public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* __builtin_return_address question
@ 2002-08-21  6:35 Neal D. Becker
  2002-08-21  7:05 ` H. J. Lu
  2002-08-21  7:22 ` Andrew Haley
  0 siblings, 2 replies; 4+ messages in thread
From: Neal D. Becker @ 2002-08-21  6:35 UTC (permalink / raw)
  To: gcc

I'm trying to make a stack trace function.  Use of
__builtin_return_address looks promising, but the arg has to be a
constant expression.  Because the arg can't be a variable, I don't see
how I can traceback more than one level of the stack.  Any ideas?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: __builtin_return_address question
  2002-08-21  6:35 __builtin_return_address question Neal D. Becker
@ 2002-08-21  7:05 ` H. J. Lu
  2002-08-21  7:22 ` Andrew Haley
  1 sibling, 0 replies; 4+ messages in thread
From: H. J. Lu @ 2002-08-21  7:05 UTC (permalink / raw)
  To: Neal D. Becker; +Cc: gcc

On Wed, Aug 21, 2002 at 09:27:15AM -0400, Neal D. Becker wrote:
> I'm trying to make a stack trace function.  Use of
> __builtin_return_address looks promising, but the arg has to be a
> constant expression.  Because the arg can't be a variable, I don't see
> how I can traceback more than one level of the stack.  Any ideas?

If you use glibc, you can use <execinfo.h>.


H.J.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* __builtin_return_address question
  2002-08-21  6:35 __builtin_return_address question Neal D. Becker
  2002-08-21  7:05 ` H. J. Lu
@ 2002-08-21  7:22 ` Andrew Haley
  2002-08-21  9:05   ` Neal D. Becker
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Haley @ 2002-08-21  7:22 UTC (permalink / raw)
  To: Neal D. Becker; +Cc: gcc

Neal D. Becker writes:
 > I'm trying to make a stack trace function.  Use of
 > __builtin_return_address looks promising, but the arg has to be a
 > constant expression.  Because the arg can't be a variable, I don't see
 > how I can traceback more than one level of the stack.  Any ideas?

It depends on the architecture.  With some ABIs unwinding is trivial
pointer chasing, but with others it can be very difficult.  See
backtrace() in the glibc source.

For IA-64 see
http://sources.redhat.com/ml/libc-hacker/2002-01/msg00034.html .  This
is the way of the future...

Andrew.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: __builtin_return_address question
  2002-08-21  7:22 ` Andrew Haley
@ 2002-08-21  9:05   ` Neal D. Becker
  0 siblings, 0 replies; 4+ messages in thread
From: Neal D. Becker @ 2002-08-21  9:05 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc

>>>>> "Andrew" == Andrew Haley <aph@cambridge.redhat.com> writes:

    Andrew> Neal D. Becker writes:
    >> I'm trying to make a stack trace function.  Use of
    >> __builtin_return_address looks promising, but the arg has to be a
    >> constant expression.  Because the arg can't be a variable, I don't see
    >> how I can traceback more than one level of the stack.  Any ideas?

    Andrew> It depends on the architecture.  With some ABIs unwinding is trivial
    Andrew> pointer chasing, but with others it can be very difficult.  See
    Andrew> backtrace() in the glibc source.

Thanks for the info on backtrace.  What if I want to demangle the
result?


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-08-21  9:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-21  6:35 __builtin_return_address question Neal D. Becker
2002-08-21  7:05 ` H. J. Lu
2002-08-21  7:22 ` Andrew Haley
2002-08-21  9:05   ` Neal D. Becker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).