Chapter 10. Examining Data
71
The addresses and contents printed by the
x
command are not saved in the value history because there
is often too much of them and they would get in the way. Instead, gdb makes these values available
for subsequent use in expressions as values of the convenience variables
$_
and
$__
. After an
x
command, the last address examined is available for use in expressions in the convenience variable
$_
. The contents of that address, as examined, are available in the convenience variable
$__
.
If the
x
command has a repeat count, the address and contents saved are from the last memory unit
printed; this is not the same as the last address printed if several units were printed on the last line of
output.
10.6. Automatic display
If you find that you want to print the value of an expression frequently (to see how it changes), you
might want to add it to the
automatic display list
so that gdb prints its value each time your program
stops. Each expression added to the list is given a number to identify it; to remove an expression from
the list, you specify that number. The automatic display looks like this:
2: foo = 38
3: bar[5] = (struct hack *) 0x3804
This display shows item numbers, expressions and their current values. As with displays you request
manually using
x
or
, you can specify the output format you prefer; in fact,
display
decides
whether to use
or
x
depending on how elaborate your format specification is--it uses
x
if you
specify a unit size, or one of the two formats (
i
and
s
) that are only supported by
x
; otherwise it uses
.
display
expr
Add the expression
expr
to the list of expressions to display each time your program stops. Refer
to Section 10.1
Expressions
.
display
does not repeat if you press [RET] again after using it.
display/
fmt expr
For
fmt
specifying only a display format and not a size or count, add the expression
expr
to the
auto-display list but arrange to display it each time in the specified format
fmt
. Refer to Section
10.4
Output formats
.
display/
fmt addr
For
fmt i
or
s
, or including a unit-size or a number of units, add the expression
addr
as a
memory address to be examined each time your program stops. Examining means in effect doing
x/
fmt addr
. Refer to Section 10.5
Examining memory
.
For example,
display/i $pc
can be helpful, to see the machine instruction about to be executed
each time execution stops (
$pc
is a common name for the program counter; (refer to Section 10.10
Registers
).
undisplay
dnums
...
delete display
dnums
...
Remove item numbers
dnums
from the list of expressions to display.
undisplay
does not repeat if you press [RET] after using it. (Otherwise you would just get the
error
No display number ...
.)
Summary of Contents for ENTERPRISE LINUX 4 - DEVELOPER TOOLS GUIDE
Page 1: ...Red Hat Enterprise Linux 4 Debugging with gdb ...
Page 12: ...2 Chapter 1 Debugging with gdb ...
Page 28: ...18 Chapter 4 Getting In and Out of gdb ...
Page 34: ...24 Chapter 5 gdb Commands ...
Page 44: ...34 Chapter 6 Running Programs Under gdb ...
Page 68: ...58 Chapter 8 Examining the Stack ...
Page 98: ...88 Chapter 10 Examining Data ...
Page 112: ...102 Chapter 12 Tracepoints ...
Page 118: ...108 Chapter 13 Debugging Programs That Use Overlays ...
Page 138: ...128 Chapter 14 Using gdb with Different Languages ...
Page 144: ...134 Chapter 15 Examining the Symbol Table ...
Page 170: ...160 Chapter 19 Debugging remote programs ...
Page 198: ...188 Chapter 21 Controlling gdb ...
Page 204: ...194 Chapter 22 Canned Sequences of Commands ...
Page 206: ...196 Chapter 23 Command Interpreters ...
Page 216: ...206 Chapter 25 Using gdb under gnu Emacs ...
Page 296: ...286 Chapter 27 gdb Annotations ...
Page 300: ...290 Chapter 28 Reporting Bugs in gdb ...
Page 322: ...312 Chapter 30 Using History Interactively ...
Page 362: ...352 Appendix D gdb Remote Serial Protocol ...
Page 380: ...370 Appendix F GNU GENERAL PUBLIC LICENSE ...
Page 386: ...376 Appendix G GNU Free Documentation License ...
Page 410: ......