Programming in C

(Barry) #1

404 Chapter 18 Debugging Programs


i = 3
(gdb) break foo Put a breakpoint at the start of foo
Breakpoint 2 at 0x1c98: file p18-5.c, line 13.
(gdb) continue Continue execution
Continuing.

Breakpoint 2, foo (x={month = 10, day = 11, year = 2004}) at p18-5.c:13
13 ++x.day; 0x8e in foo:25: {
(gdb) print today Display value of today
No symbol "today" in current context
(gdb) print main::today Display value of today from main
$11 = {
month = 10,
day = 11,
year = 2004
}
(gdb) step
15 return x;
(gdb) print x.day
$12 = 12
(gdb) continue
Continuing.
Program exited normally.
(gdb)

Note one feature of gdb: After a breakpoint is reached or after single stepping, it lists the
line that will be executed next when you resume execution of your program, and not
the last executed line.That’s why arraywas still not initialized the first time it was dis-
played. Single stepping one line caused it to be initialized. Also note that declarations that
initialize automatic variables are considered executable lines (they actually do cause the
compiler to produce executable code).

Listing and Deleting Breakpoints
Once set, breakpoints remain in a program until gdbexits or until you delete them.You
can see all the breakpoints that you have set by using the info breakcommand, as
follows:
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x00001c9c in main at p18-5.c:20
2 breakpoint keep y 0x00001c4c in foo at p18-5.c:13

Program 18.5 Continued
Free download pdf