Debugging with GDB (September 2007)

70 Debugging with GDB
would not be displayed right now because they refer to automatic variables not
currently available.
If a display expression refers to local variables, then it does not make sense outside the
lexical context for which it was set up. Such an expression is disabled when execution enters
a context where one of its variables is not defined. For example, if you give the command
display last_char while inside a function with an argument last_char, GDB displays
this argument while your program continues to stop inside that function. When it stops
elsewhere, where there is no variable last_char, the display is disabled automatically. The
next time your program stops where last_char is meaningful, you can enable the display
expression again.
8.7 Print settings
GDB provides the following ways to control how arrays, structures, and symbols are
printed.
These settings are useful for debugging programs in any language:
set print address
set print address on
GDB prints memory addresses showing the location of stack traces, structure
values, pointer values, breakpoints, and so forth, even when it als o displays the
contents of those addresses. The default is on. For example, this is what a
stack frame display looks like with set print address on:
(gdb) f
#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
at input.c:530
530 if (lquote != def_lquote)
set print address off
Do not print addresses when displaying their contents. For example, this is the
same stack frame displayed with set print address off:
(gdb) set print addr off
(gdb) f
#0 set_quotes (lq="<<", rq=">>") at input.c:530
530 if (lquote != def_lquote)
You can use set print address off to eliminate all machine dep e ndent dis-
plays from the GDB interface. For example, with print address off, you
should get the same text for backtraces on all machines—whether or not they
involve pointer arguments.
show print address
Show whether or not addresses are to b e printed.
When GDB prints a symbolic address, it normally prints the closest previous symbol
plus an offset. If that symbol does not uniquely identify the address (for example, it is a
name whose s cope is a single source file), you may need to clarify it. One way to do this is
with info line. For example info line *0x4537’. Alternately, you can set GDB to print
the source file and the line number when it prints a symbolic address: