i am using ptrace to get information related to Callstack on Linux. i can retrieve Spack Pointer to my stack using register returned by ptarces. but using this stack pointer how can i retrieve information related to Function name and signature of current call stack?
are there any Linux APIs to traverse this callstack?
please 开发者_开发百科help.. i am looking for it from last few days...
thanks in advance Sandeep
The first thing you need to get is a list of code addresses - that of the currently executing function, and the return addresses going back up the call chain.
On x86, the %eip
register will contain a memory address within the code of the currently-executing function. The %ebp
register will point at the location on the stack where the previous value of %ebp
is stored, followed by the return value. You need to follow that chain of %ebp
values, recording the return addresses as you go.
You then need to read the DWARF debugging information in the binary file you're debugging to resolve code addresses back to function names.
Note that backtraces can only be done reliably if the code is compiled with frame pointers.
I strongly suggest using libunwind in this case. It provides a good API for traversal of call-stack. It depends on presence of .eh_frame header in the object file.It can be used both in local and remote(your use case) contexts. Stack unwinding does not depend on DWARF information or debug builds.
精彩评论