Debugging with GDB (September 2007)

Chapter 8: Examining Data 67
a Print as an address, both absolute in hexadecimal and as an offset from the
nearest preceding symbol. You can use this format used to discover where (in
what function) an unknown address is located:
(gdb) p/a 0x54320
$3 = 0x54320 <_initialize_vx+396>
c Regard as an integer and print it as a character constant.
f Regard the bits of the value as a floating point number and print using typical
floating point syntax.
For example, to print the program counter in hex (see Section 8.10 [Registers], page 77),
type
p/x $pc
Note that no space is required before the slash; this is because command names in GDB
cannot contain a slash.
To reprint the last value in the value history with a different format, you can use the
print command with just a format and no expression. For example, p/x reprints the last
value in hex.
8.5 Examining memory
You can use the command x (for “examine”) to examine memory in any of several
formats, independent of your program data types .
x/nfu addr
x addr
x Use the x command to examine memory.
n, f, and u are all optional parameters that specify how much memory to display and how
to format it; addr is an expression giving the address where you want to start displaying
memory. If you use defaults for nfu, you need not type the slash /’. Several commands set
convenient defaults for addr.
n, the repeat count
The repeat count is a decimal integer and the default is 1. It specifies how
much memory (counting by units u) to display.
f, the display format
The display format is one of the formats used by print, s (null-terminated
string), or i (machine instruction). The default is x (hexadecimal) initially.
The default changes each time you use either x or print.
u, the unit size
The unit size is any of
b Bytes.
h Halfwords (two byte s).
w Words (four bytes). This is the initial default.