Next: Pretty Printing, Previous: Auto Display, Up: Data
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-offsetset print max-symbolic-offset unlimited
unlimited
, which tells gdb
to always print the symbolic form of an address if any symbol precedes
it. Zero is equivalent to unlimited
.
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.
You can also enable ‘/a’-like formatting all the time using ‘set print symbol on’:
set print symbol on
set print symbol off
show print symbol
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 array-indexes
set print array-indexes on
set print array-indexes off
show print array-indexes
set print elements
number-of-elementsset print elements unlimited
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 unlimited
or zero means
that the number of elements to print is unlimited.
show print elements
set print frame-arguments
valueall
scalars
...
. This is the default. Here is an example where
only scalar arguments are shown:
#1 0x08048361 in call_me (i=3, s=..., ss=0xbf8d508c, u=..., e=green) at frame-args.c:23
none
...
. In this case, the example above now becomes:
#1 0x08048361 in call_me (i=..., s=..., ss=..., u=..., e=...) at frame-args.c:23
By default, only scalar arguments are printed. This command can be used
to configure the debugger to print the value of all arguments, regardless
of their type. However, it is often advantageous to not print the value
of more complex parameters. For instance, it reduces the amount of
information printed in each frame, making the backtrace more readable.
Also, it improves performance when displaying Ada frames, because
the computation of large arguments can sometimes be CPU-intensive,
especially in large applications. Setting print frame-arguments
to scalars
(the default) or none
avoids this computation,
thus speeding up the display of each Ada frame.
show print frame-arguments
set print raw frame-arguments on
set print raw frame-arguments off
show print raw frame-arguments
set print entry-values
valueThe default value is default
(see below for its description). Older
gdb behaved as with the setting no
. Compilers not supporting
this feature will behave in the default
setting the same way as with the
no
setting.
This functionality is currently supported only by DWARF 2 debugging format and the compiler has to produce ‘DW_TAG_GNU_call_site’ tags. With gcc, you need to specify -O -g during compilation, to get this information.
The value parameter can be one of the following:
no
#0 equal (val=5) #0 different (val=6) #0 lost (val=<optimized out>) #0 born (val=10) #0 invalid (val=<optimized out>)
only
#0 equal (val@entry=5) #0 different (val@entry=5) #0 lost (val@entry=5) #0 born (val@entry=<optimized out>) #0 invalid (val@entry=<optimized out>)
preferred
#0 equal (val@entry=5) #0 different (val@entry=5) #0 lost (val@entry=5) #0 born (val=10) #0 invalid (val@entry=<optimized out>)
if-needed
#0 equal (val=5) #0 different (val=6) #0 lost (val@entry=5) #0 born (val=10) #0 invalid (val=<optimized out>)
both
#0 equal (val=5, val@entry=5) #0 different (val=6, val@entry=5) #0 lost (val=<optimized out>, val@entry=5) #0 born (val=10, val@entry=<optimized out>) #0 invalid (val=<optimized out>, val@entry=<optimized out>)
compact
<optimized out>
. If not in MI mode (see GDB/MI) and if both
values are known and identical, print the shortened
param=param@entry=VALUE
notation.
#0 equal (val=val@entry=5) #0 different (val=6, val@entry=5) #0 lost (val@entry=5) #0 born (val=10) #0 invalid (val=<optimized out>)
default
param=param@entry=VALUE
notation.
#0 equal (val=val@entry=5) #0 different (val=6, val@entry=5) #0 lost (val=<optimized out>, val@entry=5) #0 born (val=10) #0 invalid (val=<optimized out>)
For analysis messages on possible failures of frame argument values at function
entry resolution see set debug entry-values.
show print entry-values
set print repeats
number-of-repeatsset print repeats unlimited
"<repeats
n times>"
, where n is the number of
identical repetitions, instead of displaying the identical elements
themselves. Setting the threshold to unlimited
or zero will
cause all elements to be individually printed. The default threshold
is 10.
show print repeats
set print null-stop
show 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
"{...}"
instead.
show print union
For example, given the declarations
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 = {...}}
set print union
affects programs written in C-like languages
and in Pascal.
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
styleauto
gnu
g++
) encoding algorithm.
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 pascal_static-members
set print pascal_static-members on
set print pascal_static-members off
show print pascal_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