tags:

views:

120

answers:

3

Hello,

I would like to know if there is a Linux tool that allows you to read the values of the program stack?? For instance when running the binary of a program containing the line:

foo(parameter);

the parameter would be put on the stack, and I would like to know if there is a tool to access it.

thanks.

+5  A: 

Gdb?

There are also some backtrace functions in glibc. http://www.gnu.org/s/libc/manual/html%5Fnode/Backtraces.html

smcameron
+4  A: 

Yeah, it sounds like you just want to run a debugger. If you compile your program with the -g option then you can use gdb like:

gdb myprogram

Now set a break point at your function and you can view the values of the variables in the current scope.

If you are a C beginner it is very much worth your time to learn gdb (Gnu debugger).

ssteidl
You don't need to have compiled a binary with -g. Obviously more debugging info helps, but you'll be able to see the extern (i.e. shared-linker-visible) functions on the call stack, and read the numeric values of their arguments. It's optimization that gets in the way of debugger use (especially -fomit-stack-pointer on gcc!), not really the lack of -g.
Andy Ross
+3  A: 

Since you tagged this as security, you'll probably want to read "Smashing the Stack for Fun and Profit":

http://insecure.org/stf/smashstack.html

Grandpa
great link, this was exactly what I was looking for!!
marco
Be sure to use your powers for good, not evil :)
Grandpa