Chapter 10.
Examining Data
The usual way to examine data in your program is with the
command (abbreviated
p
), or its
synonym
inspect
. It evaluates and prints the value of an expression of the language your program is
written in (refer to Chapter 14
Using gdb with Different Languages
).
expr
print /
f expr
expr
is an expression (in the source language). By default the value of
expr
is printed in a
format appropriate to its data type; you can choose a different format by specifying
/
f
, where
f
is a letter specifying the format; refer to Section 10.4
Output formats
.
print
print /
f
If you omit
expr
, gdb displays the last value again (from the
value history
; (refer to Section 10.8
Value history
). This allows you to conveniently inspect the same value in an alternative format.
A more low-level way of examining data is with the
x
command. It examines data in memory at a
specified address and prints it in a specified format. Refer to Section 10.5
Examining memory
.
If you are interested in information about types, or about how the fields of a struct or a class are
declared, use the
ptype
exp
command rather than
. Refer to Chapter 15
Examining the Symbol
Table
.
10.1. Expressions
and many other gdb commands accept an expression and compute its value. Any kind of
constant, variable or operator defined by the programming language you are using is valid in an
expression in gdb. This includes conditional expressions, function calls, casts, and string constants. It
also includes preprocessor macros, if you compiled your program to include this information; refer to
Section 6.1
Compiling for debugging
.
gdb supports array constants in expressions input by the user. The syntax is {
element
,
element
. . . }.
For example, you can use the command
print {1, 2, 3}
to build up an array in memory that is
malloc
ed in the target program.
Because C is so widespread, most of the expressions shown in examples in this manual are in C. Refer
to Chapter 14
Using gdb with Different Languages
, for information on how to use expressions in other
languages.
In this section, we discuss operators that you can use in gdb expressions regardless of your program-
ming language.
Casts are supported in all languages, not just in C, because it is so useful to cast a number into a
pointer in order to examine a structure at that address in memory.
gdb supports these operators, in addition to those common to programming languages:
@
@
is a binary operator for treating parts of memory as arrays. Refer to Section 10.3
Artificial
arrays
, for more information.
Summary of Contents for ENTERPRISE LINUX 3 - SECURITY GUIDE
Page 1: ...Red Hat Enterprise Linux 3 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: ......