Next: Value History, 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 addressset print address onon. 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 offset 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 addressWhen 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 onset print symbol-filename offshow print symbol-filenameAnother 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-offsetshow print max-symbolic-offsetIf 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 arrayset print array onset print array offshow print arrayset print array-indexesset print array-indexes onset print array-indexes offshow print array-indexesset print elements number-of-elementsset 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 elementsset print frame-arguments valueallscalars.... 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, all argument values are always printed. But this command
can be useful in several cases. For instance, it can be used to reduce
the amount of information printed in each frame, making the backtrace
more readable. Also, this command can be used to improve performance
when displaying Ada frames, because the computation of large arguments
can sometimes be CPU-intensive, especiallly in large applications.
Setting print frame-arguments to scalars or none
avoids this computation, thus speeding up the display of each Ada frame.
show print frame-argumentsset print repeats"<repeats n times>", where n is the number of
identical repetitions, instead of displaying the identical elements
themselves. Setting the threshold to zero will cause all elements to
be individually printed. The default threshold is 10.
show print repeatsset print null-stopshow print null-stopset 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 prettyset 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 offshow print sevenbit-stringsset print union onset print union off"{...}"
instead.
show print unionFor 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 demangleset print demangle onshow print demangleset print asm-demangleset print asm-demangle onshow print asm-demangleset demangle-style styleautognug++) encoding algorithm.
This is the default.
hpaCC) encoding algorithm.
lucidlcc) encoding algorithm.
armcfront-generated executables. gdb would
require further enhancement to permit that.
show demangle-styleset print objectset print object onset print object offshow print objectset print static-membersset print static-members onset print static-members offshow print static-membersset print pascal_static-membersset print pascal_static-members onset print pascal_static-members offshow print pascal_static-membersset print vtblset print vtbl onvtbl commands do not work on programs compiled with the HP
ANSI C++ compiler (aCC).)
set print vtbl offshow print vtbl