Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

10.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

{No value for ` <listitem>GDBN'} prints memory addresses showing the location of stack traces, structure values, pointer values, breakpoints, and so forth, even when it also 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 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

Show whether or not addresses are to be printed.

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

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 reasonably 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 earlier 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 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

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.

set print elements number-of-elements

Set a limit on how many elements of an array gdb will print. If gdb is printing a large array, it stops printing after it has printed the number of elements set by the 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

Display the number of elements of a large array that gdb will print. If the number is 0, then the printing is unlimited.

set print null-stop

Cause gdb to stop printing the characters of an array when the first null is encountered. This is useful when large arrays actually contain only short strings. The default is off.

set print pretty on

Cause gdb to print structures in an indented format with one member per line, like this:

$1 = {
  next = 0x0,
  flags = {
    sweet = 1,
    sour = 1
  },
  meat = 0x54 "Pork"
}
                                  

set print pretty off

Cause gdb to print structures in a compact format, like this:

$1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
meat = 0x54 "Pork"}
          

This is the default format.

show print pretty

Show which format gdb is using to print structures.

set print sevenbit-strings on

Print using only seven-bit characters; if this option is set, gdb displays any eight-bit characters (in strings or character values) using the notation \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

Print full eight-bit characters. This allows the use of more international character sets, and is the default.

show print sevenbit-strings

Show whether or not gdb is printing only seven-bit characters.

set print union on

Tell gdb to print unions which are contained in structures. This is the default setting.

set print union off

Tell gdb not to print unions which are contained in structures.

show print union

Ask gdb whether or not it will print unions which are contained in structures.

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 = {...}}

These settings are of interest when debugging C++ programs:

set print demangle, set print demangle on

Print C++ names in their source form rather than in the encoded ("mangled") form passed to the assembler and linker for type-safe linkage. The default is on.

show print demangle

Show whether C++ names are printed in mangled or demangled form.

set print asm-demangle, set print asm-demangle on

Print C++ names in their source form rather than their mangled form, even in assembler code printouts such as instruction disassemblies. The default is off.

show print asm-demangle

Show whether C++ names in assembly listings are printed in mangled or demangled form.

set demangle-style style

Choose among several encoding schemes used by different compilers to represent C++ names. The choices for style are currently:

auto

Allow gdb to choose a decoding style by inspecting your program.

gnu

Decode based on the gnu C++ compiler (g++) encoding algorithm. This is the default.

hp

Decode based on the HP ANSI C++ (aCC) encoding algorithm.

lucid

Decode based on the Lucid C++ compiler (lcc) encoding algorithm.

arm

Decode using the algorithm in the [C++ Annotated Reference Manual]. Warning: this setting alone is not sufficient to allow debugging cfront-generated executables. gdb would require further enhancement to permit that.

If you omit style, you will see a list of possible formats.

show demangle-style

Display the encoding style currently in use for decoding C++ symbols.

set print object, set print object on

When displaying a pointer to an object, identify the actual (derived) type of the object rather than the declared type, using the virtual function table.

set print object off

Display only the declared type of objects, without reference to the virtual function table. This is the default setting.

show print object

Show whether actual, or declared, object types are displayed.

set print static-members, set print static-members on

Print static members when displaying a C++ object. The default is on.

set print static-members off

Do not print static members when displaying a C++ object.

show print static-members

Show whether C++ static members are printed, or not.

set print vtbl, set print vtbl on

Pretty print C++ virtual function tables. The default is off. (The vtbl commands do not work on programs compiled with the HP ANSI C++ compiler (aCC).)

set print vtbl off

Do not pretty print C++ virtual function tables.

show print vtbl

Show whether C++ virtual function tables are pretty printed, or not.

 
 
  Published under the terms of the GNU General Public License Design by Interspire