Possible Duplicate:
How can one grab a stack trace in C?
Hi,
I would like to know how to print the contents of the current program stack (using C language).
say for eg.
call_some_function()
{
...
...
print_stack_till_now();
return something;
}
call_some_other_function()
{
...
...
print_stack_till_now();
return something;
}
main()
{
print_stack_till_now();
call_some_function();
print_stack_till_now();
call_some_other_function();
print_stack_till_now();
return 0;
}
In the prev example (may be not an example exactly :)) when I call the print_stack_till_now() function I should be able to print the current stack built till that point (including the newer function call entries, return location, their arguments etc.)
Is such a function possible in C language (even inlined assembly). Please point me to the theory (or existing code would be even better) needed to write such a function.
In gdb we can use backtrace to look at the current stack, I'm looking for something similar. Why do I need this ?... just wanted to learn.
Thank you.