Assembly x86 Programming Debugging (GDB): How to print out data through advancing indexing

0

I am wondering how do I print out data through advanced indexing in GDB? For example, say I want to print out the value at 8(%ebp) to get the first parameter passed into a function. How would I do that? The following command does not seem to work:

p (int)8 ($esp)

I always get this segmentation fault error:

Program received signal SIGSEGV, Segmentation fault. 0x00000008 in ?? () The program being debugged was signaled while in a function called from GDB. GDB remains in the frame where the signal was received. To change this behavior use "set unwindonsignal on". Evaluation of the expression containing the function (at 0x0x8) will be abandoned. When the function is done executing, GDB will silently stop.

c
assembly
x86
gdb
embedded
asked on Stack Overflow Nov 28, 2020 by Adam Lee • edited Nov 28, 2020 by Adam Lee

1 Answer

0

I think 8($esp) tries to call 8 as a function, with %esp as the arg. (But absolute address 8 is not in a valid executable page). Remember that GDB uses GDB's C-like syntax, not AT&T assembly addressing-mode syntax.

Register + offset is hardly "advanced indexing", but regardless, it's easy enough to translate to a GDB expression:

x  $esp + 8

The x command examines memory at that address. Use help x to see options for formatting and how many elements to display. p would print the address, unless you cast it to a pointer and dereference it like p *(int*)(8 + $esp)

answered on Stack Overflow Nov 28, 2020 by Peter Cordes

User contributions licensed under CC BY-SA 3.0