Debugging with GDB Manual HP WDB v6.3 (5900-2180, August 2012)
GDB reads only enough symbol data to know where to find the rest when needed; as a result, the
first prompt comes up very quickly.
1.2 Setting Display width
We now tell GDB to use a narrower display width than usual, so that examples fit in this manual.
((gdb)) set width 70
We need to see how the m4 built-in changequote works. Having looked at the source, we
know the relevant subroutine is m4_changequote, so we set a breakpoint there with the GDB
break command.
1.3 Setting Breakpoints
Here we describe how to set a breakpoint.
((gdb)) break m4 changequote
Breakpoint 1 at 0x62f4: file builtin.c, line 879.
1.4 Running the executable under GDB
Using the run command, we start m4 under GDB control. As long as the control does not reach
the m4_changequote subroutine, the program runs as usual.
((gdb)) run
Starting program: /work/Editorial/gdb/gnu/m4/m4
define(foo,0000)
foo
0000
To trigger the breakpoint, we call changequote. GDB suspends execution of m4, displaying
information about the context where it stops.
changequote(<QUOTE>,<UNQUOTE>)
Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
at builtin.c:879
879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
1.5 Stepping to the next line in the source program
Now we use the command n (next) to advance execution to the next line of the current function.
((gdb)) n
882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
: nil,
1.6 Stepping into a subroutine
The set_quotes looks like a promising subroutine. We can go into it by using the command s
(step) instead of next. step goes to the next line to be executed in any subroutine, so it steps
into set_quotes.
((gdb)) s
set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
at input.c:530
530 if (lquote != def_lquote)
1.7 Examining the Stack
The display that shows the subroutine where m4 is now suspended (and its arguments) is called a
stack frame display. It shows a summary of the stack. We can use the backtrace command
18 A Sample GDB Session