1 |
578 |
markom |
This is ./gdb.info, produced by makeinfo version 4.0 from gdb.texinfo.
|
2 |
|
|
|
3 |
|
|
INFO-DIR-SECTION Programming & development tools.
|
4 |
|
|
START-INFO-DIR-ENTRY
|
5 |
|
|
* Gdb: (gdb). The GNU debugger.
|
6 |
|
|
END-INFO-DIR-ENTRY
|
7 |
|
|
|
8 |
|
|
This file documents the GNU debugger GDB.
|
9 |
|
|
|
10 |
|
|
This is the Ninth Edition, April 2001, of `Debugging with GDB: the
|
11 |
|
|
GNU Source-Level Debugger' for GDB Version 20010707.
|
12 |
|
|
|
13 |
|
|
Copyright (C)
|
14 |
|
|
1988,1989,1990,1991,1992,1993,1994,1995,1996,1998,1999,2000,2001
|
15 |
|
|
Free Software Foundation, Inc.
|
16 |
|
|
|
17 |
|
|
Permission is granted to copy, distribute and/or modify this document
|
18 |
|
|
under the terms of the GNU Free Documentation License, Version 1.1 or
|
19 |
|
|
any later version published by the Free Software Foundation; with the
|
20 |
|
|
Invariant Sections being "A Sample GDB Session" and "Free Software",
|
21 |
|
|
with the Front-Cover texts being "A GNU Manual," and with the
|
22 |
|
|
Back-Cover Texts as in (a) below.
|
23 |
|
|
|
24 |
|
|
(a) The FSF's Back-Cover Text is: "You have freedom to copy and
|
25 |
|
|
modify this GNU Manual, like GNU software. Copies published by the Free
|
26 |
|
|
Software Foundation raise funds for GNU development."
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
File: gdb.info, Node: Data, Next: Tracepoints, Prev: Source, Up: Top
|
30 |
|
|
|
31 |
|
|
Examining Data
|
32 |
|
|
**************
|
33 |
|
|
|
34 |
|
|
The usual way to examine data in your program is with the `print'
|
35 |
|
|
command (abbreviated `p'), or its synonym `inspect'. It evaluates and
|
36 |
|
|
prints the value of an expression of the language your program is
|
37 |
|
|
written in (*note Using GDB with Different Languages: Languages.).
|
38 |
|
|
|
39 |
|
|
`print EXPR'
|
40 |
|
|
`print /F EXPR'
|
41 |
|
|
EXPR is an expression (in the source language). By default the
|
42 |
|
|
value of EXPR is printed in a format appropriate to its data type;
|
43 |
|
|
you can choose a different format by specifying `/F', where F is a
|
44 |
|
|
letter specifying the format; see *Note Output formats: Output
|
45 |
|
|
Formats.
|
46 |
|
|
|
47 |
|
|
`print'
|
48 |
|
|
`print /F'
|
49 |
|
|
If you omit EXPR, GDB displays the last value again (from the
|
50 |
|
|
"value history"; *note Value history: Value History.). This
|
51 |
|
|
allows you to conveniently inspect the same value in an
|
52 |
|
|
alternative format.
|
53 |
|
|
|
54 |
|
|
A more low-level way of examining data is with the `x' command. It
|
55 |
|
|
examines data in memory at a specified address and prints it in a
|
56 |
|
|
specified format. *Note Examining memory: Memory.
|
57 |
|
|
|
58 |
|
|
If you are interested in information about types, or about how the
|
59 |
|
|
fields of a struct or a class are declared, use the `ptype EXP' command
|
60 |
|
|
rather than `print'. *Note Examining the Symbol Table: Symbols.
|
61 |
|
|
|
62 |
|
|
* Menu:
|
63 |
|
|
|
64 |
|
|
* Expressions:: Expressions
|
65 |
|
|
* Variables:: Program variables
|
66 |
|
|
* Arrays:: Artificial arrays
|
67 |
|
|
* Output Formats:: Output formats
|
68 |
|
|
* Memory:: Examining memory
|
69 |
|
|
* Auto Display:: Automatic display
|
70 |
|
|
* Print Settings:: Print settings
|
71 |
|
|
* Value History:: Value history
|
72 |
|
|
* Convenience Vars:: Convenience variables
|
73 |
|
|
* Registers:: Registers
|
74 |
|
|
* Floating Point Hardware:: Floating point hardware
|
75 |
|
|
* Memory Region Attributes:: Memory region attributes
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
File: gdb.info, Node: Expressions, Next: Variables, Up: Data
|
79 |
|
|
|
80 |
|
|
Expressions
|
81 |
|
|
===========
|
82 |
|
|
|
83 |
|
|
`print' and many other GDB commands accept an expression and compute
|
84 |
|
|
its value. Any kind of constant, variable or operator defined by the
|
85 |
|
|
programming language you are using is valid in an expression in GDB.
|
86 |
|
|
This includes conditional expressions, function calls, casts and string
|
87 |
|
|
constants. It unfortunately does not include symbols defined by
|
88 |
|
|
preprocessor `#define' commands.
|
89 |
|
|
|
90 |
|
|
GDB supports array constants in expressions input by the user. The
|
91 |
|
|
syntax is {ELEMENT, ELEMENT...}. For example, you can use the command
|
92 |
|
|
`print {1, 2, 3}' to build up an array in memory that is `malloc'ed in
|
93 |
|
|
the target program.
|
94 |
|
|
|
95 |
|
|
Because C is so widespread, most of the expressions shown in
|
96 |
|
|
examples in this manual are in C. *Note Using GDB with Different
|
97 |
|
|
Languages: Languages, for information on how to use expressions in other
|
98 |
|
|
languages.
|
99 |
|
|
|
100 |
|
|
In this section, we discuss operators that you can use in GDB
|
101 |
|
|
expressions regardless of your programming language.
|
102 |
|
|
|
103 |
|
|
Casts are supported in all languages, not just in C, because it is so
|
104 |
|
|
useful to cast a number into a pointer in order to examine a structure
|
105 |
|
|
at that address in memory.
|
106 |
|
|
|
107 |
|
|
GDB supports these operators, in addition to those common to
|
108 |
|
|
programming languages:
|
109 |
|
|
|
110 |
|
|
`@'
|
111 |
|
|
`@' is a binary operator for treating parts of memory as arrays.
|
112 |
|
|
*Note Artificial arrays: Arrays, for more information.
|
113 |
|
|
|
114 |
|
|
`::'
|
115 |
|
|
`::' allows you to specify a variable in terms of the file or
|
116 |
|
|
function where it is defined. *Note Program variables: Variables.
|
117 |
|
|
|
118 |
|
|
`{TYPE} ADDR'
|
119 |
|
|
Refers to an object of type TYPE stored at address ADDR in memory.
|
120 |
|
|
ADDR may be any expression whose value is an integer or pointer
|
121 |
|
|
(but parentheses are required around binary operators, just as in
|
122 |
|
|
a cast). This construct is allowed regardless of what kind of
|
123 |
|
|
data is normally supposed to reside at ADDR.
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
File: gdb.info, Node: Variables, Next: Arrays, Prev: Expressions, Up: Data
|
127 |
|
|
|
128 |
|
|
Program variables
|
129 |
|
|
=================
|
130 |
|
|
|
131 |
|
|
The most common kind of expression to use is the name of a variable
|
132 |
|
|
in your program.
|
133 |
|
|
|
134 |
|
|
Variables in expressions are understood in the selected stack frame
|
135 |
|
|
(*note Selecting a frame: Selection.); they must be either:
|
136 |
|
|
|
137 |
|
|
* global (or file-static)
|
138 |
|
|
|
139 |
|
|
or
|
140 |
|
|
|
141 |
|
|
* visible according to the scope rules of the programming language
|
142 |
|
|
from the point of execution in that frame
|
143 |
|
|
|
144 |
|
|
This means that in the function
|
145 |
|
|
|
146 |
|
|
foo (a)
|
147 |
|
|
int a;
|
148 |
|
|
{
|
149 |
|
|
bar (a);
|
150 |
|
|
{
|
151 |
|
|
int b = test ();
|
152 |
|
|
bar (b);
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
you can examine and use the variable `a' whenever your program is
|
157 |
|
|
executing within the function `foo', but you can only use or examine
|
158 |
|
|
the variable `b' while your program is executing inside the block where
|
159 |
|
|
`b' is declared.
|
160 |
|
|
|
161 |
|
|
There is an exception: you can refer to a variable or function whose
|
162 |
|
|
scope is a single source file even if the current execution point is not
|
163 |
|
|
in this file. But it is possible to have more than one such variable or
|
164 |
|
|
function with the same name (in different source files). If that
|
165 |
|
|
happens, referring to that name has unpredictable effects. If you wish,
|
166 |
|
|
you can specify a static variable in a particular function or file,
|
167 |
|
|
using the colon-colon notation:
|
168 |
|
|
|
169 |
|
|
FILE::VARIABLE
|
170 |
|
|
FUNCTION::VARIABLE
|
171 |
|
|
|
172 |
|
|
Here FILE or FUNCTION is the name of the context for the static
|
173 |
|
|
VARIABLE. In the case of file names, you can use quotes to make sure
|
174 |
|
|
GDB parses the file name as a single word--for example, to print a
|
175 |
|
|
global value of `x' defined in `f2.c':
|
176 |
|
|
|
177 |
|
|
(gdb) p 'f2.c'::x
|
178 |
|
|
|
179 |
|
|
This use of `::' is very rarely in conflict with the very similar
|
180 |
|
|
use of the same notation in C++. GDB also supports use of the C++
|
181 |
|
|
scope resolution operator in GDB expressions.
|
182 |
|
|
|
183 |
|
|
_Warning:_ Occasionally, a local variable may appear to have the
|
184 |
|
|
wrong value at certain points in a function--just after entry to a
|
185 |
|
|
new scope, and just before exit.
|
186 |
|
|
You may see this problem when you are stepping by machine
|
187 |
|
|
instructions. This is because, on most machines, it takes more than
|
188 |
|
|
one instruction to set up a stack frame (including local variable
|
189 |
|
|
definitions); if you are stepping by machine instructions, variables
|
190 |
|
|
may appear to have the wrong values until the stack frame is completely
|
191 |
|
|
built. On exit, it usually also takes more than one machine
|
192 |
|
|
instruction to destroy a stack frame; after you begin stepping through
|
193 |
|
|
that group of instructions, local variable definitions may be gone.
|
194 |
|
|
|
195 |
|
|
This may also happen when the compiler does significant
|
196 |
|
|
optimizations. To be sure of always seeing accurate values, turn off
|
197 |
|
|
all optimization when compiling.
|
198 |
|
|
|
199 |
|
|
Another possible effect of compiler optimizations is to optimize
|
200 |
|
|
unused variables out of existence, or assign variables to registers (as
|
201 |
|
|
opposed to memory addresses). Depending on the support for such cases
|
202 |
|
|
offered by the debug info format used by the compiler, GDB might not be
|
203 |
|
|
able to display values for such local variables. If that happens, GDB
|
204 |
|
|
will print a message like this:
|
205 |
|
|
|
206 |
|
|
No symbol "foo" in current context.
|
207 |
|
|
|
208 |
|
|
To solve such problems, either recompile without optimizations, or
|
209 |
|
|
use a different debug info format, if the compiler supports several such
|
210 |
|
|
formats. For example, GCC, the GNU C/C++ compiler usually supports the
|
211 |
|
|
`-gstabs' option. `-gstabs' produces debug info in a format that is
|
212 |
|
|
superior to formats such as COFF. You may be able to use DWARF2
|
213 |
|
|
(`-gdwarf-2'), which is also an effective form for debug info. See
|
214 |
|
|
*Note Options for Debugging Your Program or GNU CC: (gcc.info)Debugging
|
215 |
|
|
Options, for more information.
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
File: gdb.info, Node: Arrays, Next: Output Formats, Prev: Variables, Up: Data
|
219 |
|
|
|
220 |
|
|
Artificial arrays
|
221 |
|
|
=================
|
222 |
|
|
|
223 |
|
|
It is often useful to print out several successive objects of the
|
224 |
|
|
same type in memory; a section of an array, or an array of dynamically
|
225 |
|
|
determined size for which only a pointer exists in the program.
|
226 |
|
|
|
227 |
|
|
You can do this by referring to a contiguous span of memory as an
|
228 |
|
|
"artificial array", using the binary operator `@'. The left operand of
|
229 |
|
|
`@' should be the first element of the desired array and be an
|
230 |
|
|
individual object. The right operand should be the desired length of
|
231 |
|
|
the array. The result is an array value whose elements are all of the
|
232 |
|
|
type of the left argument. The first element is actually the left
|
233 |
|
|
argument; the second element comes from bytes of memory immediately
|
234 |
|
|
following those that hold the first element, and so on. Here is an
|
235 |
|
|
example. If a program says
|
236 |
|
|
|
237 |
|
|
int *array = (int *) malloc (len * sizeof (int));
|
238 |
|
|
|
239 |
|
|
you can print the contents of `array' with
|
240 |
|
|
|
241 |
|
|
p *array@len
|
242 |
|
|
|
243 |
|
|
The left operand of `@' must reside in memory. Array values made
|
244 |
|
|
with `@' in this way behave just like other arrays in terms of
|
245 |
|
|
subscripting, and are coerced to pointers when used in expressions.
|
246 |
|
|
Artificial arrays most often appear in expressions via the value history
|
247 |
|
|
(*note Value history: Value History.), after printing one out.
|
248 |
|
|
|
249 |
|
|
Another way to create an artificial array is to use a cast. This
|
250 |
|
|
re-interprets a value as if it were an array. The value need not be in
|
251 |
|
|
memory:
|
252 |
|
|
(gdb) p/x (short[2])0x12345678
|
253 |
|
|
$1 = {0x1234, 0x5678}
|
254 |
|
|
|
255 |
|
|
As a convenience, if you leave the array length out (as in
|
256 |
|
|
`(TYPE[])VALUE') GDB calculates the size to fill the value (as
|
257 |
|
|
`sizeof(VALUE)/sizeof(TYPE)':
|
258 |
|
|
(gdb) p/x (short[])0x12345678
|
259 |
|
|
$2 = {0x1234, 0x5678}
|
260 |
|
|
|
261 |
|
|
Sometimes the artificial array mechanism is not quite enough; in
|
262 |
|
|
moderately complex data structures, the elements of interest may not
|
263 |
|
|
actually be adjacent--for example, if you are interested in the values
|
264 |
|
|
of pointers in an array. One useful work-around in this situation is
|
265 |
|
|
to use a convenience variable (*note Convenience variables: Convenience
|
266 |
|
|
Vars.) as a counter in an expression that prints the first interesting
|
267 |
|
|
value, and then repeat that expression via . For instance,
|
268 |
|
|
suppose you have an array `dtab' of pointers to structures, and you are
|
269 |
|
|
interested in the values of a field `fv' in each structure. Here is an
|
270 |
|
|
example of what you might type:
|
271 |
|
|
|
272 |
|
|
set $i = 0
|
273 |
|
|
p dtab[$i++]->fv
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
...
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
File: gdb.info, Node: Output Formats, Next: Memory, Prev: Arrays, Up: Data
|
280 |
|
|
|
281 |
|
|
Output formats
|
282 |
|
|
==============
|
283 |
|
|
|
284 |
|
|
By default, GDB prints a value according to its data type. Sometimes
|
285 |
|
|
this is not what you want. For example, you might want to print a
|
286 |
|
|
number in hex, or a pointer in decimal. Or you might want to view data
|
287 |
|
|
in memory at a certain address as a character string or as an
|
288 |
|
|
instruction. To do these things, specify an "output format" when you
|
289 |
|
|
print a value.
|
290 |
|
|
|
291 |
|
|
The simplest use of output formats is to say how to print a value
|
292 |
|
|
already computed. This is done by starting the arguments of the
|
293 |
|
|
`print' command with a slash and a format letter. The format letters
|
294 |
|
|
supported are:
|
295 |
|
|
|
296 |
|
|
`x'
|
297 |
|
|
Regard the bits of the value as an integer, and print the integer
|
298 |
|
|
in hexadecimal.
|
299 |
|
|
|
300 |
|
|
`d'
|
301 |
|
|
Print as integer in signed decimal.
|
302 |
|
|
|
303 |
|
|
`u'
|
304 |
|
|
Print as integer in unsigned decimal.
|
305 |
|
|
|
306 |
|
|
`o'
|
307 |
|
|
Print as integer in octal.
|
308 |
|
|
|
309 |
|
|
`t'
|
310 |
|
|
Print as integer in binary. The letter `t' stands for "two". (1)
|
311 |
|
|
|
312 |
|
|
`a'
|
313 |
|
|
Print as an address, both absolute in hexadecimal and as an offset
|
314 |
|
|
from the nearest preceding symbol. You can use this format used
|
315 |
|
|
to discover where (in what function) an unknown address is located:
|
316 |
|
|
|
317 |
|
|
(gdb) p/a 0x54320
|
318 |
|
|
$3 = 0x54320 <_initialize_vx+396>
|
319 |
|
|
|
320 |
|
|
The command `info symbol 0x54320' yields similar results. *Note
|
321 |
|
|
info symbol: Symbols.
|
322 |
|
|
|
323 |
|
|
`c'
|
324 |
|
|
Regard as an integer and print it as a character constant.
|
325 |
|
|
|
326 |
|
|
`f'
|
327 |
|
|
Regard the bits of the value as a floating point number and print
|
328 |
|
|
using typical floating point syntax.
|
329 |
|
|
|
330 |
|
|
For example, to print the program counter in hex (*note
|
331 |
|
|
Registers::), type
|
332 |
|
|
|
333 |
|
|
p/x $pc
|
334 |
|
|
|
335 |
|
|
Note that no space is required before the slash; this is because command
|
336 |
|
|
names in GDB cannot contain a slash.
|
337 |
|
|
|
338 |
|
|
To reprint the last value in the value history with a different
|
339 |
|
|
format, you can use the `print' command with just a format and no
|
340 |
|
|
expression. For example, `p/x' reprints the last value in hex.
|
341 |
|
|
|
342 |
|
|
---------- Footnotes ----------
|
343 |
|
|
|
344 |
|
|
(1) `b' cannot be used because these format letters are also used
|
345 |
|
|
with the `x' command, where `b' stands for "byte"; see *Note Examining
|
346 |
|
|
memory: Memory.
|
347 |
|
|
|
348 |
|
|
|
349 |
|
|
File: gdb.info, Node: Memory, Next: Auto Display, Prev: Output Formats, Up: Data
|
350 |
|
|
|
351 |
|
|
Examining memory
|
352 |
|
|
================
|
353 |
|
|
|
354 |
|
|
You can use the command `x' (for "examine") to examine memory in any
|
355 |
|
|
of several formats, independently of your program's data types.
|
356 |
|
|
|
357 |
|
|
`x/NFU ADDR'
|
358 |
|
|
`x ADDR'
|
359 |
|
|
`x'
|
360 |
|
|
Use the `x' command to examine memory.
|
361 |
|
|
|
362 |
|
|
N, F, and U are all optional parameters that specify how much memory
|
363 |
|
|
to display and how to format it; ADDR is an expression giving the
|
364 |
|
|
address where you want to start displaying memory. If you use defaults
|
365 |
|
|
for NFU, you need not type the slash `/'. Several commands set
|
366 |
|
|
convenient defaults for ADDR.
|
367 |
|
|
|
368 |
|
|
N, the repeat count
|
369 |
|
|
The repeat count is a decimal integer; the default is 1. It
|
370 |
|
|
specifies how much memory (counting by units U) to display.
|
371 |
|
|
|
372 |
|
|
F, the display format
|
373 |
|
|
The display format is one of the formats used by `print', `s'
|
374 |
|
|
(null-terminated string), or `i' (machine instruction). The
|
375 |
|
|
default is `x' (hexadecimal) initially. The default changes each
|
376 |
|
|
time you use either `x' or `print'.
|
377 |
|
|
|
378 |
|
|
U, the unit size
|
379 |
|
|
The unit size is any of
|
380 |
|
|
|
381 |
|
|
`b'
|
382 |
|
|
Bytes.
|
383 |
|
|
|
384 |
|
|
`h'
|
385 |
|
|
Halfwords (two bytes).
|
386 |
|
|
|
387 |
|
|
`w'
|
388 |
|
|
Words (four bytes). This is the initial default.
|
389 |
|
|
|
390 |
|
|
`g'
|
391 |
|
|
Giant words (eight bytes).
|
392 |
|
|
|
393 |
|
|
Each time you specify a unit size with `x', that size becomes the
|
394 |
|
|
default unit the next time you use `x'. (For the `s' and `i'
|
395 |
|
|
formats, the unit size is ignored and is normally not written.)
|
396 |
|
|
|
397 |
|
|
ADDR, starting display address
|
398 |
|
|
ADDR is the address where you want GDB to begin displaying memory.
|
399 |
|
|
The expression need not have a pointer value (though it may); it
|
400 |
|
|
is always interpreted as an integer address of a byte of memory.
|
401 |
|
|
*Note Expressions: Expressions, for more information on
|
402 |
|
|
expressions. The default for ADDR is usually just after the last
|
403 |
|
|
address examined--but several other commands also set the default
|
404 |
|
|
address: `info breakpoints' (to the address of the last breakpoint
|
405 |
|
|
listed), `info line' (to the starting address of a line), and
|
406 |
|
|
`print' (if you use it to display a value from memory).
|
407 |
|
|
|
408 |
|
|
For example, `x/3uh 0x54320' is a request to display three halfwords
|
409 |
|
|
(`h') of memory, formatted as unsigned decimal integers (`u'), starting
|
410 |
|
|
at address `0x54320'. `x/4xw $sp' prints the four words (`w') of
|
411 |
|
|
memory above the stack pointer (here, `$sp'; *note Registers:
|
412 |
|
|
Registers.) in hexadecimal (`x').
|
413 |
|
|
|
414 |
|
|
Since the letters indicating unit sizes are all distinct from the
|
415 |
|
|
letters specifying output formats, you do not have to remember whether
|
416 |
|
|
unit size or format comes first; either order works. The output
|
417 |
|
|
specifications `4xw' and `4wx' mean exactly the same thing. (However,
|
418 |
|
|
the count N must come first; `wx4' does not work.)
|
419 |
|
|
|
420 |
|
|
Even though the unit size U is ignored for the formats `s' and `i',
|
421 |
|
|
you might still want to use a count N; for example, `3i' specifies that
|
422 |
|
|
you want to see three machine instructions, including any operands.
|
423 |
|
|
The command `disassemble' gives an alternative way of inspecting
|
424 |
|
|
machine instructions; see *Note Source and machine code: Machine Code.
|
425 |
|
|
|
426 |
|
|
All the defaults for the arguments to `x' are designed to make it
|
427 |
|
|
easy to continue scanning memory with minimal specifications each time
|
428 |
|
|
you use `x'. For example, after you have inspected three machine
|
429 |
|
|
instructions with `x/3i ADDR', you can inspect the next seven with just
|
430 |
|
|
`x/7'. If you use to repeat the `x' command, the repeat count N
|
431 |
|
|
is used again; the other arguments default as for successive uses of
|
432 |
|
|
`x'.
|
433 |
|
|
|
434 |
|
|
The addresses and contents printed by the `x' command are not saved
|
435 |
|
|
in the value history because there is often too much of them and they
|
436 |
|
|
would get in the way. Instead, GDB makes these values available for
|
437 |
|
|
subsequent use in expressions as values of the convenience variables
|
438 |
|
|
`$_' and `$__'. After an `x' command, the last address examined is
|
439 |
|
|
available for use in expressions in the convenience variable `$_'. The
|
440 |
|
|
contents of that address, as examined, are available in the convenience
|
441 |
|
|
variable `$__'.
|
442 |
|
|
|
443 |
|
|
If the `x' command has a repeat count, the address and contents saved
|
444 |
|
|
are from the last memory unit printed; this is not the same as the last
|
445 |
|
|
address printed if several units were printed on the last line of
|
446 |
|
|
output.
|
447 |
|
|
|
448 |
|
|
|
449 |
|
|
File: gdb.info, Node: Auto Display, Next: Print Settings, Prev: Memory, Up: Data
|
450 |
|
|
|
451 |
|
|
Automatic display
|
452 |
|
|
=================
|
453 |
|
|
|
454 |
|
|
If you find that you want to print the value of an expression
|
455 |
|
|
frequently (to see how it changes), you might want to add it to the
|
456 |
|
|
"automatic display list" so that GDB prints its value each time your
|
457 |
|
|
program stops. Each expression added to the list is given a number to
|
458 |
|
|
identify it; to remove an expression from the list, you specify that
|
459 |
|
|
number. The automatic display looks like this:
|
460 |
|
|
|
461 |
|
|
2: foo = 38
|
462 |
|
|
3: bar[5] = (struct hack *) 0x3804
|
463 |
|
|
|
464 |
|
|
This display shows item numbers, expressions and their current values.
|
465 |
|
|
As with displays you request manually using `x' or `print', you can
|
466 |
|
|
specify the output format you prefer; in fact, `display' decides
|
467 |
|
|
whether to use `print' or `x' depending on how elaborate your format
|
468 |
|
|
specification is--it uses `x' if you specify a unit size, or one of the
|
469 |
|
|
two formats (`i' and `s') that are only supported by `x'; otherwise it
|
470 |
|
|
uses `print'.
|
471 |
|
|
|
472 |
|
|
`display EXPR'
|
473 |
|
|
Add the expression EXPR to the list of expressions to display each
|
474 |
|
|
time your program stops. *Note Expressions: Expressions.
|
475 |
|
|
|
476 |
|
|
`display' does not repeat if you press again after using it.
|
477 |
|
|
|
478 |
|
|
`display/FMT EXPR'
|
479 |
|
|
For FMT specifying only a display format and not a size or count,
|
480 |
|
|
add the expression EXPR to the auto-display list but arrange to
|
481 |
|
|
display it each time in the specified format FMT. *Note Output
|
482 |
|
|
formats: Output Formats.
|
483 |
|
|
|
484 |
|
|
`display/FMT ADDR'
|
485 |
|
|
For FMT `i' or `s', or including a unit-size or a number of units,
|
486 |
|
|
add the expression ADDR as a memory address to be examined each
|
487 |
|
|
time your program stops. Examining means in effect doing `x/FMT
|
488 |
|
|
ADDR'. *Note Examining memory: Memory.
|
489 |
|
|
|
490 |
|
|
For example, `display/i $pc' can be helpful, to see the machine
|
491 |
|
|
instruction about to be executed each time execution stops (`$pc' is a
|
492 |
|
|
common name for the program counter; *note Registers: Registers.).
|
493 |
|
|
|
494 |
|
|
`undisplay DNUMS...'
|
495 |
|
|
`delete display DNUMS...'
|
496 |
|
|
Remove item numbers DNUMS from the list of expressions to display.
|
497 |
|
|
|
498 |
|
|
`undisplay' does not repeat if you press after using it.
|
499 |
|
|
(Otherwise you would just get the error `No display number ...'.)
|
500 |
|
|
|
501 |
|
|
`disable display DNUMS...'
|
502 |
|
|
Disable the display of item numbers DNUMS. A disabled display
|
503 |
|
|
item is not printed automatically, but is not forgotten. It may be
|
504 |
|
|
enabled again later.
|
505 |
|
|
|
506 |
|
|
`enable display DNUMS...'
|
507 |
|
|
Enable display of item numbers DNUMS. It becomes effective once
|
508 |
|
|
again in auto display of its expression, until you specify
|
509 |
|
|
otherwise.
|
510 |
|
|
|
511 |
|
|
`display'
|
512 |
|
|
Display the current values of the expressions on the list, just as
|
513 |
|
|
is done when your program stops.
|
514 |
|
|
|
515 |
|
|
`info display'
|
516 |
|
|
Print the list of expressions previously set up to display
|
517 |
|
|
automatically, each one with its item number, but without showing
|
518 |
|
|
the values. This includes disabled expressions, which are marked
|
519 |
|
|
as such. It also includes expressions which would not be
|
520 |
|
|
displayed right now because they refer to automatic variables not
|
521 |
|
|
currently available.
|
522 |
|
|
|
523 |
|
|
If a display expression refers to local variables, then it does not
|
524 |
|
|
make sense outside the lexical context for which it was set up. Such an
|
525 |
|
|
expression is disabled when execution enters a context where one of its
|
526 |
|
|
variables is not defined. For example, if you give the command
|
527 |
|
|
`display last_char' while inside a function with an argument
|
528 |
|
|
`last_char', GDB displays this argument while your program continues to
|
529 |
|
|
stop inside that function. When it stops elsewhere--where there is no
|
530 |
|
|
variable `last_char'--the display is disabled automatically. The next
|
531 |
|
|
time your program stops where `last_char' is meaningful, you can enable
|
532 |
|
|
the display expression once again.
|
533 |
|
|
|
534 |
|
|
|
535 |
|
|
File: gdb.info, Node: Print Settings, Next: Value History, Prev: Auto Display, Up: Data
|
536 |
|
|
|
537 |
|
|
Print settings
|
538 |
|
|
==============
|
539 |
|
|
|
540 |
|
|
GDB provides the following ways to control how arrays, structures,
|
541 |
|
|
and symbols are printed.
|
542 |
|
|
|
543 |
|
|
These settings are useful for debugging programs in any language:
|
544 |
|
|
|
545 |
|
|
`set print address'
|
546 |
|
|
`set print address on'
|
547 |
|
|
GDB prints memory addresses showing the location of stack traces,
|
548 |
|
|
structure values, pointer values, breakpoints, and so forth, even
|
549 |
|
|
when it also displays the contents of those addresses. The default
|
550 |
|
|
is `on'. For example, this is what a stack frame display looks
|
551 |
|
|
like with `set print address on':
|
552 |
|
|
|
553 |
|
|
(gdb) f
|
554 |
|
|
#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
|
555 |
|
|
at input.c:530
|
556 |
|
|
530 if (lquote != def_lquote)
|
557 |
|
|
|
558 |
|
|
`set print address off'
|
559 |
|
|
Do not print addresses when displaying their contents. For
|
560 |
|
|
example, this is the same stack frame displayed with `set print
|
561 |
|
|
address off':
|
562 |
|
|
|
563 |
|
|
(gdb) set print addr off
|
564 |
|
|
(gdb) f
|
565 |
|
|
#0 set_quotes (lq="<<", rq=">>") at input.c:530
|
566 |
|
|
530 if (lquote != def_lquote)
|
567 |
|
|
|
568 |
|
|
You can use `set print address off' to eliminate all machine
|
569 |
|
|
dependent displays from the GDB interface. For example, with
|
570 |
|
|
`print address off', you should get the same text for backtraces on
|
571 |
|
|
all machines--whether or not they involve pointer arguments.
|
572 |
|
|
|
573 |
|
|
`show print address'
|
574 |
|
|
Show whether or not addresses are to be printed.
|
575 |
|
|
|
576 |
|
|
When GDB prints a symbolic address, it normally prints the closest
|
577 |
|
|
earlier symbol plus an offset. If that symbol does not uniquely
|
578 |
|
|
identify the address (for example, it is a name whose scope is a single
|
579 |
|
|
source file), you may need to clarify. One way to do this is with
|
580 |
|
|
`info line', for example `info line *0x4537'. Alternately, you can set
|
581 |
|
|
GDB to print the source file and line number when it prints a symbolic
|
582 |
|
|
address:
|
583 |
|
|
|
584 |
|
|
`set print symbol-filename on'
|
585 |
|
|
Tell GDB to print the source file name and line number of a symbol
|
586 |
|
|
in the symbolic form of an address.
|
587 |
|
|
|
588 |
|
|
`set print symbol-filename off'
|
589 |
|
|
Do not print source file name and line number of a symbol. This
|
590 |
|
|
is the default.
|
591 |
|
|
|
592 |
|
|
`show print symbol-filename'
|
593 |
|
|
Show whether or not GDB will print the source file name and line
|
594 |
|
|
number of a symbol in the symbolic form of an address.
|
595 |
|
|
|
596 |
|
|
Another situation where it is helpful to show symbol filenames and
|
597 |
|
|
line numbers is when disassembling code; GDB shows you the line number
|
598 |
|
|
and source file that corresponds to each instruction.
|
599 |
|
|
|
600 |
|
|
Also, you may wish to see the symbolic form only if the address being
|
601 |
|
|
printed is reasonably close to the closest earlier symbol:
|
602 |
|
|
|
603 |
|
|
`set print max-symbolic-offset MAX-OFFSET'
|
604 |
|
|
Tell GDB to only display the symbolic form of an address if the
|
605 |
|
|
offset between the closest earlier symbol and the address is less
|
606 |
|
|
than MAX-OFFSET. The default is 0, which tells GDB to always
|
607 |
|
|
print the symbolic form of an address if any symbol precedes it.
|
608 |
|
|
|
609 |
|
|
`show print max-symbolic-offset'
|
610 |
|
|
Ask how large the maximum offset is that GDB prints in a symbolic
|
611 |
|
|
address.
|
612 |
|
|
|
613 |
|
|
If you have a pointer and you are not sure where it points, try `set
|
614 |
|
|
print symbol-filename on'. Then you can determine the name and source
|
615 |
|
|
file location of the variable where it points, using `p/a POINTER'.
|
616 |
|
|
This interprets the address in symbolic form. For example, here GDB
|
617 |
|
|
shows that a variable `ptt' points at another variable `t', defined in
|
618 |
|
|
`hi2.c':
|
619 |
|
|
|
620 |
|
|
(gdb) set print symbol-filename on
|
621 |
|
|
(gdb) p/a ptt
|
622 |
|
|
$4 = 0xe008
|
623 |
|
|
|
624 |
|
|
_Warning:_ For pointers that point to a local variable, `p/a' does
|
625 |
|
|
not show the symbol name and filename of the referent, even with
|
626 |
|
|
the appropriate `set print' options turned on.
|
627 |
|
|
|
628 |
|
|
Other settings control how different kinds of objects are printed:
|
629 |
|
|
|
630 |
|
|
`set print array'
|
631 |
|
|
`set print array on'
|
632 |
|
|
Pretty print arrays. This format is more convenient to read, but
|
633 |
|
|
uses more space. The default is off.
|
634 |
|
|
|
635 |
|
|
`set print array off'
|
636 |
|
|
Return to compressed format for arrays.
|
637 |
|
|
|
638 |
|
|
`show print array'
|
639 |
|
|
Show whether compressed or pretty format is selected for displaying
|
640 |
|
|
arrays.
|
641 |
|
|
|
642 |
|
|
`set print elements NUMBER-OF-ELEMENTS'
|
643 |
|
|
Set a limit on how many elements of an array GDB will print. If
|
644 |
|
|
GDB is printing a large array, it stops printing after it has
|
645 |
|
|
printed the number of elements set by the `set print elements'
|
646 |
|
|
command. This limit also applies to the display of strings. When
|
647 |
|
|
GDB starts, this limit is set to 200. Setting NUMBER-OF-ELEMENTS
|
648 |
|
|
to zero means that the printing is unlimited.
|
649 |
|
|
|
650 |
|
|
`show print elements'
|
651 |
|
|
Display the number of elements of a large array that GDB will
|
652 |
|
|
print. If the number is 0, then the printing is unlimited.
|
653 |
|
|
|
654 |
|
|
`set print null-stop'
|
655 |
|
|
Cause GDB to stop printing the characters of an array when the
|
656 |
|
|
first NULL is encountered. This is useful when large arrays
|
657 |
|
|
actually contain only short strings. The default is off.
|
658 |
|
|
|
659 |
|
|
`set print pretty on'
|
660 |
|
|
Cause GDB to print structures in an indented format with one member
|
661 |
|
|
per line, like this:
|
662 |
|
|
|
663 |
|
|
$1 = {
|
664 |
|
|
next = 0x0,
|
665 |
|
|
flags = {
|
666 |
|
|
sweet = 1,
|
667 |
|
|
sour = 1
|
668 |
|
|
},
|
669 |
|
|
meat = 0x54 "Pork"
|
670 |
|
|
}
|
671 |
|
|
|
672 |
|
|
`set print pretty off'
|
673 |
|
|
Cause GDB to print structures in a compact format, like this:
|
674 |
|
|
|
675 |
|
|
$1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
|
676 |
|
|
meat = 0x54 "Pork"}
|
677 |
|
|
|
678 |
|
|
This is the default format.
|
679 |
|
|
|
680 |
|
|
`show print pretty'
|
681 |
|
|
Show which format GDB is using to print structures.
|
682 |
|
|
|
683 |
|
|
`set print sevenbit-strings on'
|
684 |
|
|
Print using only seven-bit characters; if this option is set, GDB
|
685 |
|
|
displays any eight-bit characters (in strings or character values)
|
686 |
|
|
using the notation `\'NNN. This setting is best if you are
|
687 |
|
|
working in English (ASCII) and you use the high-order bit of
|
688 |
|
|
characters as a marker or "meta" bit.
|
689 |
|
|
|
690 |
|
|
`set print sevenbit-strings off'
|
691 |
|
|
Print full eight-bit characters. This allows the use of more
|
692 |
|
|
international character sets, and is the default.
|
693 |
|
|
|
694 |
|
|
`show print sevenbit-strings'
|
695 |
|
|
Show whether or not GDB is printing only seven-bit characters.
|
696 |
|
|
|
697 |
|
|
`set print union on'
|
698 |
|
|
Tell GDB to print unions which are contained in structures. This
|
699 |
|
|
is the default setting.
|
700 |
|
|
|
701 |
|
|
`set print union off'
|
702 |
|
|
Tell GDB not to print unions which are contained in structures.
|
703 |
|
|
|
704 |
|
|
`show print union'
|
705 |
|
|
Ask GDB whether or not it will print unions which are contained in
|
706 |
|
|
structures.
|
707 |
|
|
|
708 |
|
|
For example, given the declarations
|
709 |
|
|
|
710 |
|
|
typedef enum {Tree, Bug} Species;
|
711 |
|
|
typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
|
712 |
|
|
typedef enum {Caterpillar, Cocoon, Butterfly}
|
713 |
|
|
Bug_forms;
|
714 |
|
|
|
715 |
|
|
struct thing {
|
716 |
|
|
Species it;
|
717 |
|
|
union {
|
718 |
|
|
Tree_forms tree;
|
719 |
|
|
Bug_forms bug;
|
720 |
|
|
} form;
|
721 |
|
|
};
|
722 |
|
|
|
723 |
|
|
struct thing foo = {Tree, {Acorn}};
|
724 |
|
|
|
725 |
|
|
with `set print union on' in effect `p foo' would print
|
726 |
|
|
|
727 |
|
|
$1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
|
728 |
|
|
|
729 |
|
|
and with `set print union off' in effect it would print
|
730 |
|
|
|
731 |
|
|
$1 = {it = Tree, form = {...}}
|
732 |
|
|
|
733 |
|
|
These settings are of interest when debugging C++ programs:
|
734 |
|
|
|
735 |
|
|
`set print demangle'
|
736 |
|
|
`set print demangle on'
|
737 |
|
|
Print C++ names in their source form rather than in the encoded
|
738 |
|
|
("mangled") form passed to the assembler and linker for type-safe
|
739 |
|
|
linkage. The default is on.
|
740 |
|
|
|
741 |
|
|
`show print demangle'
|
742 |
|
|
Show whether C++ names are printed in mangled or demangled form.
|
743 |
|
|
|
744 |
|
|
`set print asm-demangle'
|
745 |
|
|
`set print asm-demangle on'
|
746 |
|
|
Print C++ names in their source form rather than their mangled
|
747 |
|
|
form, even in assembler code printouts such as instruction
|
748 |
|
|
disassemblies. The default is off.
|
749 |
|
|
|
750 |
|
|
`show print asm-demangle'
|
751 |
|
|
Show whether C++ names in assembly listings are printed in mangled
|
752 |
|
|
or demangled form.
|
753 |
|
|
|
754 |
|
|
`set demangle-style STYLE'
|
755 |
|
|
Choose among several encoding schemes used by different compilers
|
756 |
|
|
to represent C++ names. The choices for STYLE are currently:
|
757 |
|
|
|
758 |
|
|
`auto'
|
759 |
|
|
Allow GDB to choose a decoding style by inspecting your
|
760 |
|
|
program.
|
761 |
|
|
|
762 |
|
|
`gnu'
|
763 |
|
|
Decode based on the GNU C++ compiler (`g++') encoding
|
764 |
|
|
algorithm. This is the default.
|
765 |
|
|
|
766 |
|
|
`hp'
|
767 |
|
|
Decode based on the HP ANSI C++ (`aCC') encoding algorithm.
|
768 |
|
|
|
769 |
|
|
`lucid'
|
770 |
|
|
Decode based on the Lucid C++ compiler (`lcc') encoding
|
771 |
|
|
algorithm.
|
772 |
|
|
|
773 |
|
|
`arm'
|
774 |
|
|
Decode using the algorithm in the `C++ Annotated Reference
|
775 |
|
|
Manual'. *Warning:* this setting alone is not sufficient to
|
776 |
|
|
allow debugging `cfront'-generated executables. GDB would
|
777 |
|
|
require further enhancement to permit that.
|
778 |
|
|
|
779 |
|
|
If you omit STYLE, you will see a list of possible formats.
|
780 |
|
|
|
781 |
|
|
`show demangle-style'
|
782 |
|
|
Display the encoding style currently in use for decoding C++
|
783 |
|
|
symbols.
|
784 |
|
|
|
785 |
|
|
`set print object'
|
786 |
|
|
`set print object on'
|
787 |
|
|
When displaying a pointer to an object, identify the _actual_
|
788 |
|
|
(derived) type of the object rather than the _declared_ type, using
|
789 |
|
|
the virtual function table.
|
790 |
|
|
|
791 |
|
|
`set print object off'
|
792 |
|
|
Display only the declared type of objects, without reference to the
|
793 |
|
|
virtual function table. This is the default setting.
|
794 |
|
|
|
795 |
|
|
`show print object'
|
796 |
|
|
Show whether actual, or declared, object types are displayed.
|
797 |
|
|
|
798 |
|
|
`set print static-members'
|
799 |
|
|
`set print static-members on'
|
800 |
|
|
Print static members when displaying a C++ object. The default is
|
801 |
|
|
on.
|
802 |
|
|
|
803 |
|
|
`set print static-members off'
|
804 |
|
|
Do not print static members when displaying a C++ object.
|
805 |
|
|
|
806 |
|
|
`show print static-members'
|
807 |
|
|
Show whether C++ static members are printed, or not.
|
808 |
|
|
|
809 |
|
|
`set print vtbl'
|
810 |
|
|
`set print vtbl on'
|
811 |
|
|
Pretty print C++ virtual function tables. The default is off.
|
812 |
|
|
(The `vtbl' commands do not work on programs compiled with the HP
|
813 |
|
|
ANSI C++ compiler (`aCC').)
|
814 |
|
|
|
815 |
|
|
`set print vtbl off'
|
816 |
|
|
Do not pretty print C++ virtual function tables.
|
817 |
|
|
|
818 |
|
|
`show print vtbl'
|
819 |
|
|
Show whether C++ virtual function tables are pretty printed, or
|
820 |
|
|
not.
|
821 |
|
|
|
822 |
|
|
|
823 |
|
|
File: gdb.info, Node: Value History, Next: Convenience Vars, Prev: Print Settings, Up: Data
|
824 |
|
|
|
825 |
|
|
Value history
|
826 |
|
|
=============
|
827 |
|
|
|
828 |
|
|
Values printed by the `print' command are saved in the GDB "value
|
829 |
|
|
history". This allows you to refer to them in other expressions.
|
830 |
|
|
Values are kept until the symbol table is re-read or discarded (for
|
831 |
|
|
example with the `file' or `symbol-file' commands). When the symbol
|
832 |
|
|
table changes, the value history is discarded, since the values may
|
833 |
|
|
contain pointers back to the types defined in the symbol table.
|
834 |
|
|
|
835 |
|
|
The values printed are given "history numbers" by which you can
|
836 |
|
|
refer to them. These are successive integers starting with one.
|
837 |
|
|
`print' shows you the history number assigned to a value by printing
|
838 |
|
|
`$NUM = ' before the value; here NUM is the history number.
|
839 |
|
|
|
840 |
|
|
To refer to any previous value, use `$' followed by the value's
|
841 |
|
|
history number. The way `print' labels its output is designed to
|
842 |
|
|
remind you of this. Just `$' refers to the most recent value in the
|
843 |
|
|
history, and `$$' refers to the value before that. `$$N' refers to the
|
844 |
|
|
Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
|
845 |
|
|
equivalent to `$$', and `$$0' is equivalent to `$'.
|
846 |
|
|
|
847 |
|
|
For example, suppose you have just printed a pointer to a structure
|
848 |
|
|
and want to see the contents of the structure. It suffices to type
|
849 |
|
|
|
850 |
|
|
p *$
|
851 |
|
|
|
852 |
|
|
If you have a chain of structures where the component `next' points
|
853 |
|
|
to the next one, you can print the contents of the next one with this:
|
854 |
|
|
|
855 |
|
|
p *$.next
|
856 |
|
|
|
857 |
|
|
You can print successive links in the chain by repeating this
|
858 |
|
|
command--which you can do by just typing .
|
859 |
|
|
|
860 |
|
|
Note that the history records values, not expressions. If the value
|
861 |
|
|
of `x' is 4 and you type these commands:
|
862 |
|
|
|
863 |
|
|
print x
|
864 |
|
|
set x=5
|
865 |
|
|
|
866 |
|
|
then the value recorded in the value history by the `print' command
|
867 |
|
|
remains 4 even though the value of `x' has changed.
|
868 |
|
|
|
869 |
|
|
`show values'
|
870 |
|
|
Print the last ten values in the value history, with their item
|
871 |
|
|
numbers. This is like `p $$9' repeated ten times, except that
|
872 |
|
|
`show values' does not change the history.
|
873 |
|
|
|
874 |
|
|
`show values N'
|
875 |
|
|
Print ten history values centered on history item number N.
|
876 |
|
|
|
877 |
|
|
`show values +'
|
878 |
|
|
Print ten history values just after the values last printed. If
|
879 |
|
|
no more values are available, `show values +' produces no display.
|
880 |
|
|
|
881 |
|
|
Pressing to repeat `show values N' has exactly the same effect
|
882 |
|
|
as `show values +'.
|
883 |
|
|
|
884 |
|
|
|
885 |
|
|
File: gdb.info, Node: Convenience Vars, Next: Registers, Prev: Value History, Up: Data
|
886 |
|
|
|
887 |
|
|
Convenience variables
|
888 |
|
|
=====================
|
889 |
|
|
|
890 |
|
|
GDB provides "convenience variables" that you can use within GDB to
|
891 |
|
|
hold on to a value and refer to it later. These variables exist
|
892 |
|
|
entirely within GDB; they are not part of your program, and setting a
|
893 |
|
|
convenience variable has no direct effect on further execution of your
|
894 |
|
|
program. That is why you can use them freely.
|
895 |
|
|
|
896 |
|
|
Convenience variables are prefixed with `$'. Any name preceded by
|
897 |
|
|
`$' can be used for a convenience variable, unless it is one of the
|
898 |
|
|
predefined machine-specific register names (*note Registers:
|
899 |
|
|
Registers.). (Value history references, in contrast, are _numbers_
|
900 |
|
|
preceded by `$'. *Note Value history: Value History.)
|
901 |
|
|
|
902 |
|
|
You can save a value in a convenience variable with an assignment
|
903 |
|
|
expression, just as you would set a variable in your program. For
|
904 |
|
|
example:
|
905 |
|
|
|
906 |
|
|
set $foo = *object_ptr
|
907 |
|
|
|
908 |
|
|
would save in `$foo' the value contained in the object pointed to by
|
909 |
|
|
`object_ptr'.
|
910 |
|
|
|
911 |
|
|
Using a convenience variable for the first time creates it, but its
|
912 |
|
|
value is `void' until you assign a new value. You can alter the value
|
913 |
|
|
with another assignment at any time.
|
914 |
|
|
|
915 |
|
|
Convenience variables have no fixed types. You can assign a
|
916 |
|
|
convenience variable any type of value, including structures and
|
917 |
|
|
arrays, even if that variable already has a value of a different type.
|
918 |
|
|
The convenience variable, when used as an expression, has the type of
|
919 |
|
|
its current value.
|
920 |
|
|
|
921 |
|
|
`show convenience'
|
922 |
|
|
Print a list of convenience variables used so far, and their
|
923 |
|
|
values. Abbreviated `show conv'.
|
924 |
|
|
|
925 |
|
|
One of the ways to use a convenience variable is as a counter to be
|
926 |
|
|
incremented or a pointer to be advanced. For example, to print a field
|
927 |
|
|
from successive elements of an array of structures:
|
928 |
|
|
|
929 |
|
|
set $i = 0
|
930 |
|
|
print bar[$i++]->contents
|
931 |
|
|
|
932 |
|
|
Repeat that command by typing .
|
933 |
|
|
|
934 |
|
|
Some convenience variables are created automatically by GDB and given
|
935 |
|
|
values likely to be useful.
|
936 |
|
|
|
937 |
|
|
`$_'
|
938 |
|
|
The variable `$_' is automatically set by the `x' command to the
|
939 |
|
|
last address examined (*note Examining memory: Memory.). Other
|
940 |
|
|
commands which provide a default address for `x' to examine also
|
941 |
|
|
set `$_' to that address; these commands include `info line' and
|
942 |
|
|
`info breakpoint'. The type of `$_' is `void *' except when set
|
943 |
|
|
by the `x' command, in which case it is a pointer to the type of
|
944 |
|
|
`$__'.
|
945 |
|
|
|
946 |
|
|
`$__'
|
947 |
|
|
The variable `$__' is automatically set by the `x' command to the
|
948 |
|
|
value found in the last address examined. Its type is chosen to
|
949 |
|
|
match the format in which the data was printed.
|
950 |
|
|
|
951 |
|
|
`$_exitcode'
|
952 |
|
|
The variable `$_exitcode' is automatically set to the exit code
|
953 |
|
|
when the program being debugged terminates.
|
954 |
|
|
|
955 |
|
|
On HP-UX systems, if you refer to a function or variable name that
|
956 |
|
|
begins with a dollar sign, GDB searches for a user or system name
|
957 |
|
|
first, before it searches for a convenience variable.
|
958 |
|
|
|
959 |
|
|
|
960 |
|
|
File: gdb.info, Node: Registers, Next: Floating Point Hardware, Prev: Convenience Vars, Up: Data
|
961 |
|
|
|
962 |
|
|
Registers
|
963 |
|
|
=========
|
964 |
|
|
|
965 |
|
|
You can refer to machine register contents, in expressions, as
|
966 |
|
|
variables with names starting with `$'. The names of registers are
|
967 |
|
|
different for each machine; use `info registers' to see the names used
|
968 |
|
|
on your machine.
|
969 |
|
|
|
970 |
|
|
`info registers'
|
971 |
|
|
Print the names and values of all registers except floating-point
|
972 |
|
|
registers (in the selected stack frame).
|
973 |
|
|
|
974 |
|
|
`info all-registers'
|
975 |
|
|
Print the names and values of all registers, including
|
976 |
|
|
floating-point registers.
|
977 |
|
|
|
978 |
|
|
`info registers REGNAME ...'
|
979 |
|
|
Print the "relativized" value of each specified register REGNAME.
|
980 |
|
|
As discussed in detail below, register values are normally
|
981 |
|
|
relative to the selected stack frame. REGNAME may be any register
|
982 |
|
|
name valid on the machine you are using, with or without the
|
983 |
|
|
initial `$'.
|
984 |
|
|
|
985 |
|
|
GDB has four "standard" register names that are available (in
|
986 |
|
|
expressions) on most machines--whenever they do not conflict with an
|
987 |
|
|
architecture's canonical mnemonics for registers. The register names
|
988 |
|
|
`$pc' and `$sp' are used for the program counter register and the stack
|
989 |
|
|
pointer. `$fp' is used for a register that contains a pointer to the
|
990 |
|
|
current stack frame, and `$ps' is used for a register that contains the
|
991 |
|
|
processor status. For example, you could print the program counter in
|
992 |
|
|
hex with
|
993 |
|
|
|
994 |
|
|
p/x $pc
|
995 |
|
|
|
996 |
|
|
or print the instruction to be executed next with
|
997 |
|
|
|
998 |
|
|
x/i $pc
|
999 |
|
|
|
1000 |
|
|
or add four to the stack pointer(1) with
|
1001 |
|
|
|
1002 |
|
|
set $sp += 4
|
1003 |
|
|
|
1004 |
|
|
Whenever possible, these four standard register names are available
|
1005 |
|
|
on your machine even though the machine has different canonical
|
1006 |
|
|
mnemonics, so long as there is no conflict. The `info registers'
|
1007 |
|
|
command shows the canonical names. For example, on the SPARC, `info
|
1008 |
|
|
registers' displays the processor status register as `$psr' but you can
|
1009 |
|
|
also refer to it as `$ps'; and on x86-based machines `$ps' is an alias
|
1010 |
|
|
for the EFLAGS register.
|
1011 |
|
|
|
1012 |
|
|
GDB always considers the contents of an ordinary register as an
|
1013 |
|
|
integer when the register is examined in this way. Some machines have
|
1014 |
|
|
special registers which can hold nothing but floating point; these
|
1015 |
|
|
registers are considered to have floating point values. There is no way
|
1016 |
|
|
to refer to the contents of an ordinary register as floating point value
|
1017 |
|
|
(although you can _print_ it as a floating point value with `print/f
|
1018 |
|
|
$REGNAME').
|
1019 |
|
|
|
1020 |
|
|
Some registers have distinct "raw" and "virtual" data formats. This
|
1021 |
|
|
means that the data format in which the register contents are saved by
|
1022 |
|
|
the operating system is not the same one that your program normally
|
1023 |
|
|
sees. For example, the registers of the 68881 floating point
|
1024 |
|
|
coprocessor are always saved in "extended" (raw) format, but all C
|
1025 |
|
|
programs expect to work with "double" (virtual) format. In such cases,
|
1026 |
|
|
GDB normally works with the virtual format only (the format that makes
|
1027 |
|
|
sense for your program), but the `info registers' command prints the
|
1028 |
|
|
data in both formats.
|
1029 |
|
|
|
1030 |
|
|
Normally, register values are relative to the selected stack frame
|
1031 |
|
|
(*note Selecting a frame: Selection.). This means that you get the
|
1032 |
|
|
value that the register would contain if all stack frames farther in
|
1033 |
|
|
were exited and their saved registers restored. In order to see the
|
1034 |
|
|
true contents of hardware registers, you must select the innermost
|
1035 |
|
|
frame (with `frame 0').
|
1036 |
|
|
|
1037 |
|
|
However, GDB must deduce where registers are saved, from the machine
|
1038 |
|
|
code generated by your compiler. If some registers are not saved, or if
|
1039 |
|
|
GDB is unable to locate the saved registers, the selected stack frame
|
1040 |
|
|
makes no difference.
|
1041 |
|
|
|
1042 |
|
|
---------- Footnotes ----------
|
1043 |
|
|
|
1044 |
|
|
(1) This is a way of removing one word from the stack, on machines
|
1045 |
|
|
where stacks grow downward in memory (most machines, nowadays). This
|
1046 |
|
|
assumes that the innermost stack frame is selected; setting `$sp' is
|
1047 |
|
|
not allowed when other stack frames are selected. To pop entire frames
|
1048 |
|
|
off the stack, regardless of machine architecture, use `return'; see
|
1049 |
|
|
*Note Returning from a function: Returning.
|
1050 |
|
|
|
1051 |
|
|
|
1052 |
|
|
File: gdb.info, Node: Floating Point Hardware, Next: Memory Region Attributes, Prev: Registers, Up: Data
|
1053 |
|
|
|
1054 |
|
|
Floating point hardware
|
1055 |
|
|
=======================
|
1056 |
|
|
|
1057 |
|
|
Depending on the configuration, GDB may be able to give you more
|
1058 |
|
|
information about the status of the floating point hardware.
|
1059 |
|
|
|
1060 |
|
|
`info float'
|
1061 |
|
|
Display hardware-dependent information about the floating point
|
1062 |
|
|
unit. The exact contents and layout vary depending on the
|
1063 |
|
|
floating point chip. Currently, `info float' is supported on the
|
1064 |
|
|
ARM and x86 machines.
|
1065 |
|
|
|
1066 |
|
|
|
1067 |
|
|
File: gdb.info, Node: Memory Region Attributes, Prev: Floating Point Hardware, Up: Data
|
1068 |
|
|
|
1069 |
|
|
Memory Region Attributes
|
1070 |
|
|
========================
|
1071 |
|
|
|
1072 |
|
|
"Memory region attributes" allow you to describe special handling
|
1073 |
|
|
required by regions of your target's memory. GDB uses attributes to
|
1074 |
|
|
determine whether to allow certain types of memory accesses; whether to
|
1075 |
|
|
use specific width accesses; and whether to cache target memory.
|
1076 |
|
|
|
1077 |
|
|
Defined memory regions can be individually enabled and disabled.
|
1078 |
|
|
When a memory region is disabled, GDB uses the default attributes when
|
1079 |
|
|
accessing memory in that region. Similarly, if no memory regions have
|
1080 |
|
|
been defined, GDB uses the default attributes when accessing all memory.
|
1081 |
|
|
|
1082 |
|
|
When a memory region is defined, it is given a number to identify it;
|
1083 |
|
|
to enable, disable, or remove a memory region, you specify that number.
|
1084 |
|
|
|
1085 |
|
|
`mem ADDRESS1 ADDRESS1 ATTRIBUTES...'
|
1086 |
|
|
Define memory region bounded by ADDRESS1 and ADDRESS2 with
|
1087 |
|
|
attributes ATTRIBUTES....
|
1088 |
|
|
|
1089 |
|
|
`delete mem NUMS...'
|
1090 |
|
|
Remove memory region numbers NUMS.
|
1091 |
|
|
|
1092 |
|
|
`disable mem NUMS...'
|
1093 |
|
|
Disable memory region numbers NUMS. A disabled memory region is
|
1094 |
|
|
not forgotten. It may be enabled again later.
|
1095 |
|
|
|
1096 |
|
|
`enable mem NUMS...'
|
1097 |
|
|
Enable memory region numbers NUMS.
|
1098 |
|
|
|
1099 |
|
|
`info mem'
|
1100 |
|
|
Print a table of all defined memory regions, with the following
|
1101 |
|
|
columns for each region.
|
1102 |
|
|
|
1103 |
|
|
_Memory Region Number_
|
1104 |
|
|
|
1105 |
|
|
_Enabled or Disabled._
|
1106 |
|
|
Enabled memory regions are marked with `y'. Disabled memory
|
1107 |
|
|
regions are marked with `n'.
|
1108 |
|
|
|
1109 |
|
|
_Lo Address_
|
1110 |
|
|
The address defining the inclusive lower bound of the memory
|
1111 |
|
|
region.
|
1112 |
|
|
|
1113 |
|
|
_Hi Address_
|
1114 |
|
|
The address defining the exclusive upper bound of the memory
|
1115 |
|
|
region.
|
1116 |
|
|
|
1117 |
|
|
_Attributes_
|
1118 |
|
|
The list of attributes set for this memory region.
|
1119 |
|
|
|
1120 |
|
|
Attributes
|
1121 |
|
|
----------
|
1122 |
|
|
|
1123 |
|
|
Memory Access Mode
|
1124 |
|
|
..................
|
1125 |
|
|
|
1126 |
|
|
The access mode attributes set whether GDB may make read or write
|
1127 |
|
|
accesses to a memory region.
|
1128 |
|
|
|
1129 |
|
|
While these attributes prevent GDB from performing invalid memory
|
1130 |
|
|
accesses, they do nothing to prevent the target system, I/O DMA, etc.
|
1131 |
|
|
from accessing memory.
|
1132 |
|
|
|
1133 |
|
|
`ro'
|
1134 |
|
|
Memory is read only.
|
1135 |
|
|
|
1136 |
|
|
`wo'
|
1137 |
|
|
Memory is write only.
|
1138 |
|
|
|
1139 |
|
|
`rw'
|
1140 |
|
|
Memory is read/write (default).
|
1141 |
|
|
|
1142 |
|
|
Memory Access Size
|
1143 |
|
|
..................
|
1144 |
|
|
|
1145 |
|
|
The acccess size attributes tells GDB to use specific sized accesses
|
1146 |
|
|
in the memory region. Often memory mapped device registers require
|
1147 |
|
|
specific sized accesses. If no access size attribute is specified, GDB
|
1148 |
|
|
may use accesses of any size.
|
1149 |
|
|
|
1150 |
|
|
`8'
|
1151 |
|
|
Use 8 bit memory accesses.
|
1152 |
|
|
|
1153 |
|
|
`16'
|
1154 |
|
|
Use 16 bit memory accesses.
|
1155 |
|
|
|
1156 |
|
|
`32'
|
1157 |
|
|
Use 32 bit memory accesses.
|
1158 |
|
|
|
1159 |
|
|
`64'
|
1160 |
|
|
Use 64 bit memory accesses.
|
1161 |
|
|
|
1162 |
|
|
Data Cache
|
1163 |
|
|
..........
|
1164 |
|
|
|
1165 |
|
|
The data cache attributes set whether GDB will cache target memory.
|
1166 |
|
|
While this generally improves performance by reducing debug protocol
|
1167 |
|
|
overhead, it can lead to incorrect results because GDB does not know
|
1168 |
|
|
about volatile variables or memory mapped device registers.
|
1169 |
|
|
|
1170 |
|
|
`cache'
|
1171 |
|
|
Enable GDB to cache target memory.
|
1172 |
|
|
|
1173 |
|
|
`nocache (default)'
|
1174 |
|
|
Disable GDB from caching target memory.
|
1175 |
|
|
|
1176 |
|
|
|
1177 |
|
|
File: gdb.info, Node: Tracepoints, Next: Languages, Prev: Data, Up: Top
|
1178 |
|
|
|
1179 |
|
|
Tracepoints
|
1180 |
|
|
***********
|
1181 |
|
|
|
1182 |
|
|
In some applications, it is not feasible for the debugger to
|
1183 |
|
|
interrupt the program's execution long enough for the developer to learn
|
1184 |
|
|
anything helpful about its behavior. If the program's correctness
|
1185 |
|
|
depends on its real-time behavior, delays introduced by a debugger
|
1186 |
|
|
might cause the program to change its behavior drastically, or perhaps
|
1187 |
|
|
fail, even when the code itself is correct. It is useful to be able to
|
1188 |
|
|
observe the program's behavior without interrupting it.
|
1189 |
|
|
|
1190 |
|
|
Using GDB's `trace' and `collect' commands, you can specify
|
1191 |
|
|
locations in the program, called "tracepoints", and arbitrary
|
1192 |
|
|
expressions to evaluate when those tracepoints are reached. Later,
|
1193 |
|
|
using the `tfind' command, you can examine the values those expressions
|
1194 |
|
|
had when the program hit the tracepoints. The expressions may also
|
1195 |
|
|
denote objects in memory--structures or arrays, for example--whose
|
1196 |
|
|
values GDB should record; while visiting a particular tracepoint, you
|
1197 |
|
|
may inspect those objects as if they were in memory at that moment.
|
1198 |
|
|
However, because GDB records these values without interacting with you,
|
1199 |
|
|
it can do so quickly and unobtrusively, hopefully not disturbing the
|
1200 |
|
|
program's behavior.
|
1201 |
|
|
|
1202 |
|
|
The tracepoint facility is currently available only for remote
|
1203 |
|
|
targets. *Note Targets::.
|
1204 |
|
|
|
1205 |
|
|
This chapter describes the tracepoint commands and features.
|
1206 |
|
|
|
1207 |
|
|
* Menu:
|
1208 |
|
|
|
1209 |
|
|
* Set Tracepoints::
|
1210 |
|
|
* Analyze Collected Data::
|
1211 |
|
|
* Tracepoint Variables::
|
1212 |
|
|
|
1213 |
|
|
|
1214 |
|
|
File: gdb.info, Node: Set Tracepoints, Next: Analyze Collected Data, Up: Tracepoints
|
1215 |
|
|
|
1216 |
|
|
Commands to Set Tracepoints
|
1217 |
|
|
===========================
|
1218 |
|
|
|
1219 |
|
|
Before running such a "trace experiment", an arbitrary number of
|
1220 |
|
|
tracepoints can be set. Like a breakpoint (*note Set Breaks::), a
|
1221 |
|
|
tracepoint has a number assigned to it by GDB. Like with breakpoints,
|
1222 |
|
|
tracepoint numbers are successive integers starting from one. Many of
|
1223 |
|
|
the commands associated with tracepoints take the tracepoint number as
|
1224 |
|
|
their argument, to identify which tracepoint to work on.
|
1225 |
|
|
|
1226 |
|
|
For each tracepoint, you can specify, in advance, some arbitrary set
|
1227 |
|
|
of data that you want the target to collect in the trace buffer when it
|
1228 |
|
|
hits that tracepoint. The collected data can include registers, local
|
1229 |
|
|
variables, or global data. Later, you can use GDB commands to examine
|
1230 |
|
|
the values these data had at the time the tracepoint was hit.
|
1231 |
|
|
|
1232 |
|
|
This section describes commands to set tracepoints and associated
|
1233 |
|
|
conditions and actions.
|
1234 |
|
|
|
1235 |
|
|
* Menu:
|
1236 |
|
|
|
1237 |
|
|
* Create and Delete Tracepoints::
|
1238 |
|
|
* Enable and Disable Tracepoints::
|
1239 |
|
|
* Tracepoint Passcounts::
|
1240 |
|
|
* Tracepoint Actions::
|
1241 |
|
|
* Listing Tracepoints::
|
1242 |
|
|
* Starting and Stopping Trace Experiment::
|
1243 |
|
|
|
1244 |
|
|
|
1245 |
|
|
File: gdb.info, Node: Create and Delete Tracepoints, Next: Enable and Disable Tracepoints, Up: Set Tracepoints
|
1246 |
|
|
|
1247 |
|
|
Create and Delete Tracepoints
|
1248 |
|
|
-----------------------------
|
1249 |
|
|
|
1250 |
|
|
`trace'
|
1251 |
|
|
The `trace' command is very similar to the `break' command. Its
|
1252 |
|
|
argument can be a source line, a function name, or an address in
|
1253 |
|
|
the target program. *Note Set Breaks::. The `trace' command
|
1254 |
|
|
defines a tracepoint, which is a point in the target program where
|
1255 |
|
|
the debugger will briefly stop, collect some data, and then allow
|
1256 |
|
|
the program to continue. Setting a tracepoint or changing its
|
1257 |
|
|
commands doesn't take effect until the next `tstart' command;
|
1258 |
|
|
thus, you cannot change the tracepoint attributes once a trace
|
1259 |
|
|
experiment is running.
|
1260 |
|
|
|
1261 |
|
|
Here are some examples of using the `trace' command:
|
1262 |
|
|
|
1263 |
|
|
(gdb) trace foo.c:121 // a source file and line number
|
1264 |
|
|
|
1265 |
|
|
(gdb) trace +2 // 2 lines forward
|
1266 |
|
|
|
1267 |
|
|
(gdb) trace my_function // first source line of function
|
1268 |
|
|
|
1269 |
|
|
(gdb) trace *my_function // EXACT start address of function
|
1270 |
|
|
|
1271 |
|
|
(gdb) trace *0x2117c4 // an address
|
1272 |
|
|
|
1273 |
|
|
You can abbreviate `trace' as `tr'.
|
1274 |
|
|
|
1275 |
|
|
The convenience variable `$tpnum' records the tracepoint number of
|
1276 |
|
|
the most recently set tracepoint.
|
1277 |
|
|
|
1278 |
|
|
`delete tracepoint [NUM]'
|
1279 |
|
|
Permanently delete one or more tracepoints. With no argument, the
|
1280 |
|
|
default is to delete all tracepoints.
|
1281 |
|
|
|
1282 |
|
|
Examples:
|
1283 |
|
|
|
1284 |
|
|
(gdb) delete trace 1 2 3 // remove three tracepoints
|
1285 |
|
|
|
1286 |
|
|
(gdb) delete trace // remove all tracepoints
|
1287 |
|
|
|
1288 |
|
|
You can abbreviate this command as `del tr'.
|
1289 |
|
|
|
1290 |
|
|
|
1291 |
|
|
File: gdb.info, Node: Enable and Disable Tracepoints, Next: Tracepoint Passcounts, Prev: Create and Delete Tracepoints, Up: Set Tracepoints
|
1292 |
|
|
|
1293 |
|
|
Enable and Disable Tracepoints
|
1294 |
|
|
------------------------------
|
1295 |
|
|
|
1296 |
|
|
`disable tracepoint [NUM]'
|
1297 |
|
|
Disable tracepoint NUM, or all tracepoints if no argument NUM is
|
1298 |
|
|
given. A disabled tracepoint will have no effect during the next
|
1299 |
|
|
trace experiment, but it is not forgotten. You can re-enable a
|
1300 |
|
|
disabled tracepoint using the `enable tracepoint' command.
|
1301 |
|
|
|
1302 |
|
|
`enable tracepoint [NUM]'
|
1303 |
|
|
Enable tracepoint NUM, or all tracepoints. The enabled
|
1304 |
|
|
tracepoints will become effective the next time a trace experiment
|
1305 |
|
|
is run.
|
1306 |
|
|
|
1307 |
|
|
|
1308 |
|
|
File: gdb.info, Node: Tracepoint Passcounts, Next: Tracepoint Actions, Prev: Enable and Disable Tracepoints, Up: Set Tracepoints
|
1309 |
|
|
|
1310 |
|
|
Tracepoint Passcounts
|
1311 |
|
|
---------------------
|
1312 |
|
|
|
1313 |
|
|
`passcount [N [NUM]]'
|
1314 |
|
|
Set the "passcount" of a tracepoint. The passcount is a way to
|
1315 |
|
|
automatically stop a trace experiment. If a tracepoint's
|
1316 |
|
|
passcount is N, then the trace experiment will be automatically
|
1317 |
|
|
stopped on the N'th time that tracepoint is hit. If the
|
1318 |
|
|
tracepoint number NUM is not specified, the `passcount' command
|
1319 |
|
|
sets the passcount of the most recently defined tracepoint. If no
|
1320 |
|
|
passcount is given, the trace experiment will run until stopped
|
1321 |
|
|
explicitly by the user.
|
1322 |
|
|
|
1323 |
|
|
Examples:
|
1324 |
|
|
|
1325 |
|
|
(gdb) passcount 5 2 // Stop on the 5th execution of tracepoint 2
|
1326 |
|
|
|
1327 |
|
|
(gdb) passcount 12 // Stop on the 12th execution of the
|
1328 |
|
|
// most recently defined tracepoint.
|
1329 |
|
|
(gdb) trace foo
|
1330 |
|
|
(gdb) pass 3
|
1331 |
|
|
(gdb) trace bar
|
1332 |
|
|
(gdb) pass 2
|
1333 |
|
|
(gdb) trace baz
|
1334 |
|
|
(gdb) pass 1 // Stop tracing when foo has been
|
1335 |
|
|
// executed 3 times OR when bar has
|
1336 |
|
|
// been executed 2 times
|
1337 |
|
|
// OR when baz has been executed 1 time.
|
1338 |
|
|
|