How do I deference the address (examine memory) stored at label in GDB?

0

How do I deference the address (examine memory) stored at label in GDB?

I've produced the example below, where I try to examine the memory address stored as a doubleword value at label file_handle. In this case, the address is 0, but in general, it could be arbitrary. Each attempt makes x examine address 0x401004, and not 0x00 as anticipated.

I know I could just copy paste the address and give it to x as argument, but I'm used to using the * operator to deference values stored in registers, e.g., x *$eax.

How can I use the same technique to deference to address stored at label without copy-pasting it?

    (gdb) x &file_handle
    0x401004 <file_handle>: 0x00000000
    (gdb) x *&file_handle
    0x401004 <file_handle>: 0x00000000
    (gdb) x *(&file_handle +0x00)
    0x401004 <file_handle>: 0x00000000
debugging
gdb
nasm
asked on Stack Overflow Oct 30, 2016 by Shuzheng • edited Nov 1, 2016 by Shift_Left

1 Answer

0

Let's assume we have a program:

section .data
file_handle db "some"
...

Via x &file_handle we examine memory by an address of file_handle.

0x601038 <file_handle>: 0x656d6f73

If we wanna examine memory by where the content of file_handle points to we can try:

x *file_handle

But we got an error: 'file_handle' has unknown type; cast it to its declared type

So, after casting to char (because we're dealing with db):

x *(char *)file_handle
answered on Stack Overflow Jan 26, 2019 by funnydman • edited Jan 26, 2019 by funnydman

User contributions licensed under CC BY-SA 3.0