This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Function, file and line information out of '_Unwind_Context' ptr


On Sun, 2004-06-27 at 06:47, Gerrit BruchhÃuser wrote:
> It would be extremly useful to have a 'Backtrace' like building function in 
> g++ (as there is in GLIBC) which does work with any platform g++ runs on. I 
> thought I could use the '_Unwind_Stack' function for this. Is there maybe an 
> other way to retreive file and line information out of the mentioned 
> structure pointer??

The glibc backtrace function is x86 specific.  It is trivial to generate
a backtrace on a CISC like the x86, but it is hard on a RISC, and it is
getting harder with newer ABIs and more agressively optimizing
compilers.

By the way, if you are using -foptimize-sibling-calls, which is the
default at -O2, then your backtraces are already broken.  This option
optimizes away stack frames when we have a sibling call, and you can't
backtrace through a stack frame that isn't there.

Similarly, if you are using function inlining, then the backtraces won't
exactly represent what the programs is doing.  This is fixable by
reading the debug info, but even gdb/addr2line doesn't have code to do
this yet.

As for Alpha, the Alpha ABI has function descriptors which can be used
to generate backtraces.  The Alpha ABI deliberately sacrifices some
performance so that backtraces can still work.  If you find an Alpha ABI
reference and read up on it, you should be able to write your own code
to do stack backtraces on the alpha.  This will be faster than using the
unwinder.

But for most common RISC targets nowadays, the only safe way to do a
backtrace is to use the unwinder, and this will be a slow process
compared to the glibc backtrace function.

If you just want function names in the backtrace, you can do this pretty
easily by reading the symbol table (e.g. the ECOFF symbol table).  If
you want line numbers also, then you have to read the debug info, and
there is no getting around the fact that this will be an even slower
process.  This is best done offline as Arnaud Charlet suggested if you
really need this.  I believe the glibc backtrace function only gives you
function names.

The LSB is a good source of documentation and references to other docs. 
We also have links to documentation on our home page under Further
Readings.  This has pointers to the C++ ABI (which includes Unwinder
info), and the Alpha ABI (function descriptors).

Try calling _Unwind_GetIP for the function address.  IP is Instruction
Pointer, which is just another name for PC Program Counter.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]