I know that you can find any parameters by looking at a positive offset from $ ebp using gdb
This only works for some processors and some calling conventions and by no means universally.
Assuming that you only care about x86 and that your code was compiled with pointers to frames (which used to be standard, but was no longer the default value for GCC 4.6 in option mode), local people stand out with a fixed negative offset from %ebp .
Obviously, if you can rebuild your code using debugging symbols (using -g ), then GDB can simply print its values, and you donβt have to worry about how GDB detects them.
If you cannot (for example, because the code came from a third party), you will have to carefully look at the disassembly and guess. If you guessed that some value is stored in %ebp-8 , you can check this value with GDB in the same way as you study positive offsets: (gdb) x/wx $ebp-8 .
Beware: the compiler is free to host locally in any way, so if you declare
int x, y, z;
the compiler can store x on %ebp-16 , y on %ebp-20 and z on %ebp-12 .
source share