3 <title>Debugging with GDB
</title>
4 <meta http-equiv=
"Content-Type" content=
"text/html">
5 <meta name=
"description" content=
"Debugging with GDB">
6 <meta name=
"generator" content=
"makeinfo 4.3">
7 <link href=
"http://www.gnu.org/software/texinfo/" rel=
"generator-home">
12 Node:
<a name=
"Print%20Settings">Print Settings
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"Value-History.html#Value%20History">Value History
</a>,
14 Previous:
<a rel=
"previous" accesskey=
"p" href=
"Auto-Display.html#Auto%20Display">Auto Display
</a>,
15 Up:
<a rel=
"up" accesskey=
"u" href=
"Data.html#Data">Data
</a>
19 <h3 class=
"section">Print settings
</h3>
21 GDB provides the following ways to control how arrays, structures,
22 and symbols are printed.
24 <p>These settings are useful for debugging programs in any language:
27 <dt><code>set print address
</code>
28 <dd><dt><code>set print address on
</code>
29 <dd>GDB prints memory addresses showing the location of stack
30 traces, structure values, pointer values, breakpoints, and so forth,
31 even when it also displays the contents of those addresses. The default
32 is
<code>on
</code>. For example, this is what a stack frame display looks like with
33 <code>set print address on
</code>:
35 <pre class=
"smallexample"> (gdb) f
36 #
0 set_quotes (lq=
0x34c78 "<<", rq=
0x34c88 ">>")
38 530 if (lquote != def_lquote)
41 <br><dt><code>set print address off
</code>
42 <dd>Do not print addresses when displaying their contents. For example,
43 this is the same stack frame displayed with
<code>set print address off
</code>:
45 <pre class=
"smallexample"> (gdb) set print addr off
47 #
0 set_quotes (
lq=
"<<",
rq=
">>") at input.c:
530
48 530 if (lquote != def_lquote)
51 <p>You can use
<code>set print address off
</code> to eliminate all machine
52 dependent displays from the GDB interface. For example, with
53 <code>print address off
</code>, you should get the same text for backtraces on
54 all machines--whether or not they involve pointer arguments.
56 <br><dt><code>show print address
</code>
57 <dd>Show whether or not addresses are to be printed.
60 <p>When GDB prints a symbolic address, it normally prints the
61 closest earlier symbol plus an offset. If that symbol does not uniquely
62 identify the address (for example, it is a name whose scope is a single
63 source file), you may need to clarify. One way to do this is with
64 <code>info line
</code>, for example
<code>info line *
0x4537</code>. Alternately,
65 you can set GDB to print the source file and line number when
66 it prints a symbolic address:
69 <dt><code>set print symbol-filename on
</code>
70 <dd>Tell GDB to print the source file name and line number of a
71 symbol in the symbolic form of an address.
73 <br><dt><code>set print symbol-filename off
</code>
74 <dd>Do not print source file name and line number of a symbol. This is the
77 <br><dt><code>show print symbol-filename
</code>
78 <dd>Show whether or not GDB will print the source file name and
79 line number of a symbol in the symbolic form of an address.
82 <p>Another situation where it is helpful to show symbol filenames and line
83 numbers is when disassembling code; GDB shows you the line
84 number and source file that corresponds to each instruction.
86 <p>Also, you may wish to see the symbolic form only if the address being
87 printed is reasonably close to the closest earlier symbol:
90 <dt><code>set print max-symbolic-offset
</code><var>max-offset
</var><code></code>
91 <dd>Tell GDB to only display the symbolic form of an address if the
92 offset between the closest earlier symbol and the address is less than
93 <var>max-offset
</var>. The default is
0, which tells GDB
94 to always print the symbolic form of an address if any symbol precedes it.
96 <br><dt><code>show print max-symbolic-offset
</code>
97 <dd>Ask how large the maximum offset is that GDB prints in a
101 <p>If you have a pointer and you are not sure where it points, try
102 <code>set print symbol-filename on
</code>. Then you can determine the name
103 and source file location of the variable where it points, using
104 <code>p/a
</code><var>pointer
</var><code></code>. This interprets the address in symbolic form.
105 For example, here GDB shows that a variable
<code>ptt
</code> points
106 at another variable
<code>t
</code>, defined in
<code>hi2.c
</code>:
108 <pre class=
"example"> (gdb) set print symbol-filename on
110 $
4 =
0xe008 <t in hi2.c
>
114 <em>Warning:
</em> For pointers that point to a local variable,
<code>p/a
</code>
115 does not show the symbol name and filename of the referent, even with
116 the appropriate
<code>set print
</code> options turned on.
119 <p>Other settings control how different kinds of objects are printed:
122 <dt><code>set print array
</code>
123 <dd><dt><code>set print array on
</code>
124 <dd>Pretty print arrays. This format is more convenient to read,
125 but uses more space. The default is off.
127 <br><dt><code>set print array off
</code>
128 <dd>Return to compressed format for arrays.
130 <br><dt><code>show print array
</code>
131 <dd>Show whether compressed or pretty format is selected for displaying
134 <br><dt><code>set print elements
</code><var>number-of-elements
</var><code></code>
135 <dd>Set a limit on how many elements of an array GDB will print.
136 If GDB is printing a large array, it stops printing after it has
137 printed the number of elements set by the
<code>set print elements
</code> command.
138 This limit also applies to the display of strings.
139 When GDB starts, this limit is set to
200.
140 Setting
<var>number-of-elements
</var> to zero means that the printing is unlimited.
142 <br><dt><code>show print elements
</code>
143 <dd>Display the number of elements of a large array that GDB will print.
144 If the number is
0, then the printing is unlimited.
146 <br><dt><code>set print null-stop
</code>
147 <dd>Cause GDB to stop printing the characters of an array when the first
148 <small>NULL
</small> is encountered. This is useful when large arrays actually
149 contain only short strings.
152 <br><dt><code>set print pretty on
</code>
153 <dd>Cause GDB to print structures in an indented format with one member
156 <pre class=
"smallexample"> $
1 = {
166 <br><dt><code>set print pretty off
</code>
167 <dd>Cause GDB to print structures in a compact format, like this:
169 <pre class=
"smallexample"> $
1 = {next =
0x0, flags = {sweet =
1, sour =
1}, \
173 <p>This is the default format.
175 <br><dt><code>show print pretty
</code>
176 <dd>Show which format GDB is using to print structures.
178 <br><dt><code>set print sevenbit-strings on
</code>
179 <dd>Print using only seven-bit characters; if this option is set,
180 GDB displays any eight-bit characters (in strings or
181 character values) using the notation
<code>\
</code><var>nnn
</var>. This setting is
182 best if you are working in English (
<small>ASCII
</small>) and you use the
183 high-order bit of characters as a marker or
"meta" bit.
185 <br><dt><code>set print sevenbit-strings off
</code>
186 <dd>Print full eight-bit characters. This allows the use of more
187 international character sets, and is the default.
189 <br><dt><code>show print sevenbit-strings
</code>
190 <dd>Show whether or not GDB is printing only seven-bit characters.
192 <br><dt><code>set print union on
</code>
193 <dd>Tell GDB to print unions which are contained in structures. This
194 is the default setting.
196 <br><dt><code>set print union off
</code>
197 <dd>Tell GDB not to print unions which are contained in structures.
199 <br><dt><code>show print union
</code>
200 <dd>Ask GDB whether or not it will print unions which are contained in
203 <p>For example, given the declarations
205 <pre class=
"smallexample"> typedef enum {Tree, Bug} Species;
206 typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
207 typedef enum {Caterpillar, Cocoon, Butterfly}
218 struct thing foo = {Tree, {Acorn}};
221 <p>with
<code>set print union on
</code> in effect
<code>p foo
</code> would print
223 <pre class=
"smallexample"> $
1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
226 <p>and with
<code>set print union off
</code> in effect it would print
228 <pre class=
"smallexample"> $
1 = {it = Tree, form = {...}}
232 <p>These settings are of interest when debugging C
<tt>++
</tt> programs:
235 <dt><code>set print demangle
</code>
236 <dd><dt><code>set print demangle on
</code>
237 <dd>Print C
<tt>++
</tt> names in their source form rather than in the encoded
238 (
"mangled") form passed to the assembler and linker for type-safe
239 linkage. The default is on.
241 <br><dt><code>show print demangle
</code>
242 <dd>Show whether C
<tt>++
</tt> names are printed in mangled or demangled form.
244 <br><dt><code>set print asm-demangle
</code>
245 <dd><dt><code>set print asm-demangle on
</code>
246 <dd>Print C
<tt>++
</tt> names in their source form rather than their mangled form, even
247 in assembler code printouts such as instruction disassemblies.
250 <br><dt><code>show print asm-demangle
</code>
251 <dd>Show whether C
<tt>++
</tt> names in assembly listings are printed in mangled
254 <br><dt><code>set demangle-style
</code><var>style
</var><code></code>
255 <dd>Choose among several encoding schemes used by different compilers to
256 represent C
<tt>++
</tt> names. The choices for
<var>style
</var> are currently:
259 <dt><code>auto
</code>
260 <dd>Allow GDB to choose a decoding style by inspecting your program.
262 <br><dt><code>gnu
</code>
263 <dd>Decode based on the
<small>GNU
</small> C
<tt>++
</tt> compiler (
<code>g++
</code>) encoding algorithm.
266 <br><dt><code>hp
</code>
267 <dd>Decode based on the HP ANSI C
<tt>++
</tt> (
<code>aCC
</code>) encoding algorithm.
269 <br><dt><code>lucid
</code>
270 <dd>Decode based on the Lucid C
<tt>++
</tt> compiler (
<code>lcc
</code>) encoding algorithm.
272 <br><dt><code>arm
</code>
273 <dd>Decode using the algorithm in the
<cite>C
</cite><tt>++
</tt><cite> Annotated Reference Manual
</cite>.
274 <strong>Warning:
</strong> this setting alone is not sufficient to allow
275 debugging
<code>cfront
</code>-generated executables. GDB would
276 require further enhancement to permit that.
279 If you omit
<var>style
</var>, you will see a list of possible formats.
281 <br><dt><code>show demangle-style
</code>
282 <dd>Display the encoding style currently in use for decoding C
<tt>++
</tt> symbols.
284 <br><dt><code>set print object
</code>
285 <dd><dt><code>set print object on
</code>
286 <dd>When displaying a pointer to an object, identify the
<em>actual
</em>
287 (derived) type of the object rather than the
<em>declared
</em> type, using
288 the virtual function table.
290 <br><dt><code>set print object off
</code>
291 <dd>Display only the declared type of objects, without reference to the
292 virtual function table. This is the default setting.
294 <br><dt><code>show print object
</code>
295 <dd>Show whether actual, or declared, object types are displayed.
297 <br><dt><code>set print static-members
</code>
298 <dd><dt><code>set print static-members on
</code>
299 <dd>Print static members when displaying a C
<tt>++
</tt> object. The default is on.
301 <br><dt><code>set print static-members off
</code>
302 <dd>Do not print static members when displaying a C
<tt>++
</tt> object.
304 <br><dt><code>show print static-members
</code>
305 <dd>Show whether C
<tt>++
</tt> static members are printed, or not.
307 <br><dt><code>set print vtbl
</code>
308 <dd><dt><code>set print vtbl on
</code>
309 <dd>Pretty print C
<tt>++
</tt> virtual function tables. The default is off.
310 (The
<code>vtbl
</code> commands do not work on programs compiled with the HP
311 ANSI C
<tt>++
</tt> compiler (
<code>aCC
</code>).)
313 <br><dt><code>set print vtbl off
</code>
314 <dd>Do not pretty print C
<tt>++
</tt> virtual function tables.
316 <br><dt><code>show print vtbl
</code>
317 <dd>Show whether C
<tt>++
</tt> virtual function tables are pretty printed, or not.