Debugging with GDB (September 2007)

Chapter 8: Examining Data 73
set print union off
Tell GDB not to print unions which are contained in structures.
show print union
Ask GDB whether or not it w ill 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 de-
mangled form.
set demangle-style style
Choose among several encoding schemes used by different compilers to represent
C++ names.
On HP-UX, WDB automatically chooses the appropriate style.
The choices for style currently supported are:
auto Allow GDB to choose a decoding style by inspecting your program.