Memory in GDB (x command)
You can use the EXAMINE command (abbreviated as X) to view the value in the memory address. The syntax of the X command is as follows:
X/<n/f/u> <ADDR>
N, f, and u are optional parameters.
N is a positive integer that shows the memory length, that is, the content of several addresses is displayed from the current address to the back.
F indicates the display format. See the preceding figure. If the address refers to a string, the format can be S. If location 10 is the instruction address, the format can be I.
X displays variables in hexadecimal format.
D. Display variables in decimal format.
U displays unsigned integers in hexadecimal format.
O display variables in octal format.
T display variables in binary format.
A displays variables in hexadecimal format.
C. Display variables in character format.
F. Display variables in floating point format.
U indicates the number of bytes requested from the current address. If not specified, GDB defaults to four bytes. The U parameter can be replaced by the following characters. B represents a single byte, H represents a double byte, W represents a four byte, and G represents an octal node. When we specify the byte length, GDB reads and writes the specified byte starting from the memory address specified by the memory and takes it as a value.
Bhwg
X/4bt &
--------------------------------
<ADDR> indicates a memory address.
The n/f/U parameters can be used together. For example:
Command: X/3uh 0x54320 indicates that the content is read from the memory address 0x54320, h indicates that the two bytes are used as a unit, 3 indicates three units, and the u table is displayed in hexadecimal format.
Output Format
Generally, GDB outputs the value of a variable based on the type of the variable. However, you can also customize the output format of GDB. For example, you want to output a hexadecimal integer or a binary value to view the bitwise of the integer variable. To do this, you can use the gdb data display format:
X displays variables in hexadecimal format.
D. Display variables in decimal format.
U displays unsigned integers in hexadecimal format.
O display variables in octal format.
T display variables in binary format.
A displays variables in hexadecimal format.
C. Display variables in character format.
F. Display variables in floating point format.
(GDB) p I
$21 = 101
(GDB) P/A I
$22 = 0x65
(GDB) P/C I
$23 = 101 'E'
(GDB) P/F I
$24 = 1.20.31145e-43
(GDB) P/x I
$25 = 0x65
(GDB) P/T I
$26 = 1100101