Debugging with GDB (September 2007)

Chapter 8: Examining Data 71
set print symbol-filename on
Tell GDB to print the source file name and line number of a symbol in the
symbolic form of an address.
set print symbol-filename off
Do not print source file name and line number of a symbol. This is the default.
show print symbol-filename
Show whether or not GDB will print the source file name and line number of a
symbol in the symbolic form of an address.
Another situation where it is helpful to show symbol filenames and line numbers is when
disassembling code. GDB shows you the line number and source file that corresponds to
each instruction.
Also, you may wish to see the symbolic form only if the address being printed is reason-
ably close to the closest earlier symbol:
set print max-symbolic-offset max-offset
Tell GDB to only display the symbolic form of an address if the offset between
the closest symbol and the address is less than max-offset. The default is 0,
which tells GDB to always print the symbolic form of an address if any symbol
precedes it.
show print max-symbolic-offset
Ask how large the maximum offset is that GDB prints in a symbolic address.
If you have a pointer and you are not sure where it points, try set print
symbol-filename on’. Then you can determine the name and source file location of the
variable where it points, using p/a pointer ’. This interprets the address in symbolic
form. For example, here GDB shows that a variable ptt points at another variable t,
defined in hi2.c’:
(gdb) set print symbol-filename on
(gdb) p/a ptt
$4 = 0xe008 <t in hi2.c>
Warning: For pointers that point to a local variable, p/a do es not show the
symbol name and filename of the referent, even with the appropriate set print
options turned on.
Other settings to control how different kinds of objects are printed:
set print array
set print array on
Pretty print arrays. This format is more convenient to read, but uses more
space. The default is off .
set print array off
Return to compressed format for arrays.
show print array
Show whether compressed or pretty format is selected for displaying arrays.