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
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
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 dependent displays 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
When GDB prints a symbolic address, it normally prints the
closest earlier symbol plus an offset. If that symbol does not uniquely
identify the address (for example, it is a name whose scope is a single
source file), you may need to clarify. 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 line number when
it prints a symbolic address:
set print symbol-filename on
set print symbol-filename off
show print symbol-filename
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 reasonably close to the closest earlier symbol:
set print max-symbolic-offset max-offset
show print max-symbolic-offset
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' does not show the symbol name and filename of the referent, even with the appropriate
set print
options turned on.
Other settings control how different kinds of objects are printed:
set print array
set print array on
set print array off
show print array
set print elements number-of-elements
set print elements
command.
This limit also applies to the display of strings.
When GDB starts, this limit is set to 200.
Setting number-of-elements to zero means that the printing is unlimited.
show print elements
set print null-stop
set print pretty on
$1 = { next = 0x0, flags = { sweet = 1, sour = 1 }, meat = 0x54 "Pork" }
set print pretty off
$1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \ meat = 0x54 "Pork"}This is the default format.
show print pretty
set print sevenbit-strings on
\
nnn. This setting is
best if you are working in English (ASCII) and you use the
high-order bit of characters as a marker or "meta" bit.
set print sevenbit-strings off
show print sevenbit-strings
set print union on
set print union off
show print union
typedef enum {Tree, Bug} Species; typedef enum {Big_tree, Acorn, Seedling} Tree_forms; typedef enum {Caterpillar, Cocoon, Butterfly} Bug_forms; struct thing { Species it; union { Tree_forms tree; Bug_forms bug; } form; }; struct thing foo = {Tree, {Acorn}};with
set print union on
in effect `p foo' would print
$1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}and with
set print union off
in effect it would print
$1 = {it = Tree, form = {...}}
These settings are of interest when debugging C++ programs:
set print demangle
set print demangle on
show print demangle
set print asm-demangle
set print asm-demangle on
show print asm-demangle
set demangle-style style
auto
gnu
g++
) encoding algorithm.
This is the default.
hp
aCC
) encoding algorithm.
lucid
lcc
) encoding algorithm.
arm
cfront
-generated executables. GDB would
require further enhancement to permit that.
show demangle-style
set print object
set print object on
set print object off
show print object
set print static-members
set print static-members on
set print static-members off
show print static-members
set print vtbl
set print vtbl on
vtbl
commands do not work on programs compiled with the HP
ANSI C++ compiler (aCC
).)
set print vtbl off
show print vtbl
Go to the first, previous, next, last section, table of contents.