dragonmnl
dragonmnl

Reputation: 15558

What's the meaning of the output of x/ in gdb (Linux)?

I'm debugging a C program with gdb.

(gdb) r prog_name
(gdb) break main
(gdb) x/wx $esp
(gdb) 0xbffff3d0:     0xbffff60d

I know the meaning of the first 3 commands.

What I don't understand is the meaning of last one (the output of gdb after 3rd command). Specifically, I don't understand: $esp is a register, hence I expect to find a SINGLE VALUE in the register, and as far as I know , registers don't have an address. So, supposing that 0xbffff60d is the value contained by register esp, what's ** 0xbffff3d0** ?

Thanks in advance

Upvotes: 3

Views: 8045

Answers (2)

crifan
crifan

Reputation: 14328

$esp is a register

my understanding is:

  • esp is a register
  • $esp is the stored value for register esp
    • here the stored value is 0xbffff3d0
  • so x/wx $esp == x/wx 0xbffff3d0
  • -> x/wx 0xbffff3d0 means display memory value for address 0xbffff3d0
    • the normal and expected result is what your see here:
(gdb) x/wx $esp
    0xbffff3d0:     0xbffff60d
  • that is:
    • 0xbffff3d0 is memory address
    • 0xbffff60d is value stored in address 0xbffff3d0

Appendix

Upvotes: 1

Carl Norum
Carl Norum

Reputation: 225052

Straight from gdb:

(gdb) help x
Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
  t(binary), f(float), a(address), i(instruction), c(char) and s(string),
  T(OSType), A(floating point values in hex).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.

So in your case, $esp contains 0xbffff3d0, and if you interpret that value as a pointer and dereference it, you'll get that *(uint32_t *)0xbffff3d0 is 0xbffff60d.

Upvotes: 6

Related Questions