O'Reilly logo

The Art of Debugging with GDB and DDD by Peter Jay Salzman, Norman Matloff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Breakpoint Command Lists

After GDB hits a breakpoint, you'll almost always inspect a variable. If the same breakpoint gets hit repeatedly (as with a breakpoint inside a loop), you'll inspect the same variable repeatedly. Wouldn't it be nice to automate the procedure by telling GDB to automatically perform a set of commands each time it reaches a breakpoint?

In fact, you can do just this with "breakpoint command lists." We'll use GDB's printf command to illustrate command lists. You haven't been formally introduced to it yet, but printf basically works the same way in GDB as it does in C, but the parentheses are optional.

You set command lists using the commands command:

commands breakpoint-number
...
commands
...
end

where breakpoint-number is the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required