Programming in C

(Barry) #1

408 Chapter 18 Debugging Programs


Alternatively, you can specify a command, such as one from the previous list:
(gdb_ help break
Set breakpoint at specified line or function.
Argument may be line number, function name, or "*" and an address.
If line number is specified, break at start of code for that line.
If function is specified, break at start of code for that function.
If an address is specified, break at that exact address.
With no arg, uses current execution address of selected stack frame.
This is useful for breaking on return to a stack frame.

Multiple breakpoints at one place are permitted, and useful if conditional.

break ... if <cond> sets condition <cond> on the breakpoint as it is created.

Do "help breakpoints" for info on other commands dealing with breakpoints.
(gdb)
So, you can see that you have a lot of help information built right in to the gdbdebug-
ger. Be sure to take advantage of it!

Odds and Ends


Many other features are available with gdb that can’t be covered here for space reasons.
These include the ability to
n Set temporary breakpoints that are automatically removed when they are reached.
n Enable and disable breakpoints without having to clear them.
n Dump memory locations in a specified format.
n Set a watchpoint that allows for your program’s execution to be stopped whenever
the value of a specified expression changes (for example, when a variable changes
its value).
n Specify a list of values to be displayed whenever the program stops.
n Set your own “convenience variables” by name.

Ta b le 18.1 lists the gdbcommands covered in this chapter. A leading bold character for a
command name shows how the command can be abbreviated.
Free download pdf