backtrace() vs. _Unwind_Backtrace()

Andrew Haley aph@redhat.com
Sat Dec 6 11:16:00 GMT 2003


Bryce McKinlay writes:
 > On Dec 5, 2003, at 11:46 PM, Andrew Haley wrote:
 > 
 > > Java uses backtrace() a lot, and _Unwind_Backtrace() is inefficient.
 > > I see no good reason to switch unless backtrace() doesn't work on a
 > > given target.
 > 
 > I disagree - backtrace() tells us nothing. All it gives us is the IP 
 > for the frame. We need more: the start address of the function, or some 
 > other way to map to the Class and _Jv_Method that the frame belongs to. 
 > To get that we need to use the unwinder anyway!

No we don't.  We only need _Unwind_FindEnclosingFunction, and that
doesn't call the unwinder.  The use of _Unwind_FindEnclosingFunction
and the DWARF unwinder are quite independent.

 > Also, backtrace() is not flexible - for most of the checks that need to 
 > be fast, we only need to look at the top 1 or 2 frames. Since 
 > _Unwind_backtrace has a callback that lets us stop walking the stack 
 > once we've got what we need, its unlikely to be any less efficient than 
 > having to allocate a buffer to store the entire stack and possibly 
 > extend it if its too small and call backtrace again.

We don't store the entire stack at the moment, only a the top few
items.

 > Further more, backtrace won't work if someone decides to compile
 > their code without frame pointers. And its not a standard POSIX
 > function to my knowledge, thus not portable at all.

As portable as _Unwind_Backtrace() ?

 > Using it is just too fragile.

We've been using backtrace() for some time now.  That hasn't proved to
bve the case.

Andrew.



More information about the Java mailing list