Debugging Programs with gdb 405
You can delete a breakpoint at a particular line with the clearcommand followed by
the line number.You can delete a breakpoint at the start of a function by specifying the
function’s name to the clearcommand instead:
(gdb) clear 20 Remove breakpoint from line 20
Deleted breakpoint 1
(gdb) info break
Num Type Disp Enb Address What
2 breakpoint keep y 0x00001c4c in foo at p18-5.c:13
(gdb) clear foo Remove breakpoint on entry into foo
Deleted breakpoint 2
(gdb) info break
No breakpoints or watchpoints.
(gdb)
Getting a Stack Trace
Sometimes, you’ll want to know exactly where you are in terms of the hierarchy of
function calls when a program gets interrupted.This is useful information when examin-
ing a core file.You can take a look at the call stackby using the backtracecommand,
which can be abbreviated as bt.The following is an example use of Program 18.5.
(gdb) break foo
Breakpoint 1 at 0x1c4c: file p18-5.c, line 13.
(gdb) run
Starting program: /Users/stevekochan/MySrc/c/a.out
Reading symbols for shared libraries. done
Breakpoint 1, foo (x={month = 10, day = 11, year = 2004}) at p18-5.c:13
13 ++x.day;
(gdb) bt Print stack trace
#0 foo (x={month = 10, day = 11, year = 2004}) at p18-5.c:13
#1 0x00001d48 in main () at p18-5.c:31
(gdb)
When the break is taken on entry to foo,the backtracecommand is entered.The out-
put shows two functions on the call stack:fooand main. As you can see, the arguments
to the functions are also listed.Various commands (such as up,down,frame,and info
args) that are not covered here allow you to work your way around in the stack so that
you can more easily examine arguments passed to a particular function or work with its
local variables.
Calling Functions and Setting Arrays and Structures
You can use function calls in gdbexpressions as follows:
(gdb) print foo(*newdate) Call foo with date structure pointed to by newdate
$13 = {