(gdb) Get the value of the memory address indicated by a register

assembly, debugging, gdb, x86

Solution

The "standard" command for this is `x/cx $ebx`.

This is better than `p/x *0x804a6ac` in that you don't have to cut/paste the value of `$ebx`.

Problem

I'm working on a debugging project that requires me to look through Assembly code using GDB. One line reads `movzbl (%ebx),%eax`. I understand that this copies the least significant byte of `(%ebx)` to `%eax`, appending zeros to all the more significant bits. Now, I'm trying to use GDB to find out what value is held at `(%ebx)`. `info registers` tells me that the value at `%ebx` is `0x804a6ac`. As I understand it, to get the value at `(%ebx)`, I want the value located at address `0x804a6ac`. How do I get this value? I know that, after `movzbl (%ebx),%eax` is run, `%eax` has the value of `0x41`. Therefore, I suspect that `41` is the least significant byte of `(%ebx)`, but how can I see its entire value? I tried doing `p/x $0x804a6ac`, but I get `$13 = Value can't be converted to integer.`. Also, I tried doing `p/x %ebx`, but I get "A syntax error in expression, near `%ebx'."

Original source