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