[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#165992: gcc: __builtin_return_address doesn't work properly



On Fri, Oct 25, 2002 at 10:59:29AM +0200, Martin v. Loewis wrote:
> Greg Stark <gsstark@mit.edu> writes:
> 
> > Well, that's not what my documentation from GCC 2.95 says:
> > 
> >      On some machines it may be impossible to determine the return
> >      address of any function other than the current one; in such cases,
> >      or when the top of the stack has been reached, this function will
> >      return `0'.
> 
> So you have found a bug in the 2.95 documentation. Just imagine it
> would have the same text as the 3.2 documentation.

Except that I don't know whether __builtin_frame_address can be used in
2.95.  Also, Greg, be aware that despite the comment you can't
_necessarily_ use __builtin_frame_address above frame 0.  That's just
the risk you take; thus the comment about "for debugging use only".

> > I'm puzzled why I can use __builtin_frame_address to determine if
> > the top of the stack has been reached but gcc's builtin can't do the
> > same for me. I must be missing something, how do gdb and other tools
> > happily decode stack traces all the time without crashing?
> 
> They are not very happy in doing so :-) They use lots of heuristics
> which are unavailable to __builtin_return_address.

GDB will not crash from reading memory, because it cheats and reads in
a crash-proof way :)  For i386 and PPC you can use backtrace() in
glibc.  In fact, in general it's usable; I see special support for PPC,
i386, ARM, s390, and HPPA.  And it's more reliable than your method,
too.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer



Reply to: