Supported on windows
Supported on linux
Supported on embedded
Supported on android

x command

Displays the memory contents at a given address using the specified format.

Syntax

x [Address expression]
x /[Format] [Address expression]
x /[Length][Format] [Address expression]
x

Parameters

Address expression
Specifies the memory address which contents will be displayed. This can be the address itself or any C/C++ expression evaluating to address. The expression can include registers (e.g. $eip) and pseudoregisters (e.g. $pc). If the address expression is not specified, the command will continue displaying memory contents from the address where the previous instance of this command has finished.
Format
If specified, allows overriding the output format used by the command. Valid format specifiers are:
  • o - octal
  • x - hexadecimal
  • d - decimal
  • u - unsigned decimal
  • t - binary
  • f - floating point
  • a - address
  • c - char
  • s - string
  • i - instruction

The following size modifiers are supported:

  • b - byte
  • h - halfword (16-bit value)
  • w - word (32-bit value)
  • g - giant word (64-bit value)
Length
Specifies the number of elements that will be displayed by this command.

Examples

We will demonstrate the x command using a basic program that defines a byte array on the stack:

int main()
{
    char testArray[] = "0123456789ABCDEF";
    return 0;
}

We will now use the x command to display the contents of the memory occupied by the testArray array in various formats. We will also show how to use the x command to disassemble the instructions pointed by the program counter pseudo-register ($pc).

(gdb) start
Temporary breakpoint 1 at 0x8048446: file test.cpp, line 2.
Starting program: /home/bazis/test

Temporary breakpoint 1, main () at test.cpp:2
2 {
(gdb) next
3 char testArray[] = "0123456789ABCDEF";
(gdb) next
4 return 0;
(gdb) x testArray
0xbfffef7b: 0x33323130
(gdb) x/c testArray
0xbfffef7b: 48 '0'
(gdb) x/5c testArray
0xbfffef7b: 48 '0' 49 '1' 50 '2' 51 '3' 52 '4'
(gdb) x/2c
0xbfffef80: 53 '5' 54 '6'
(gdb) x/wx testArray
0xbfffef7b: 0x33323130
(gdb) x/2hx testArray
0xbfffef7b: 0x3130 0x3332
(gdb) x/gx testArray
0xbfffef7b: 0x3736353433323130
(gdb) x/s testArray
0xbfffef7b: "0123456789ABCDEF"
(gdb) x/5bx testArray
0xbfffef7b: 0x30 0x31 0x32 0x33 0x34
(gdb) x/5i $pc
=> 0x8048477 <main()+58>: mov $0x0,%eax
0x804847c <main()+63>: mov 0x1c(%esp),%edx
0x8048480 <main()+67>: xor %gs:0x14,%edx
0x8048487 <main()+74>: je 0x804848e <main()+81>
0x8048489 <main()+76>: call 0x8048310 <__stack_chk_fail@plt>

Compatibility with VisualGDB

You can use the x command normally using the GDB Session window in Visual Studio.

See also