This is the mail archive of the
mailing list for the GCC project.
- To: egcs at egcs dot cygnus dot com
- Subject: using __builtin_return_address?
- From: "Marty Leisner" <leisner at rochester dot rr dot com>
- Date: Sun, 25 Jul 1999 18:36:48 -0400
I'm using egcs 19990712 (so its new...)
I'm trying to run this subroutine:
if(count >= 10)
printf("count = %d\n", count);
p = __builtin_return_address(0);
printf("0 = %x\n", p);
p = __builtin_return_address(1);
printf("1 = %x\n", p);
p = __builtin_return_address(2);
printf("2 = %x\n", p);
p = __builtin_return_address(3);
printf("3 = %x\n", p);
I'm using linux (with redhat 6.0, glibc 2.1).
It gives me:
: leisner@soyata; ./a.out
count = 1
0 = 80484e1
1 = 40032cb3
2 = 8048371
Segmentation fault (core dumped)
(I'm looking to instrument dmalloc to work up the function chain...)
The info file says:
This function returns the return address of the current function,
or of one of its callers. The LEVEL argument is number of frames
to scan up the call stack. A value of `0' yields the return
address of the current function, a value of `1' yields the return
address of the caller of the current function, and so forth.
The LEVEL argument must be a constant integer.
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
This function should only be used with a non-zero argument for
The only thing which seems to make sense is __builtin_return_address(0).
I've written some hand-crafted code to walk back the stack before
(only for intel)...
would be very useful to accept a variable (instead of a constant).
Also, not sure why it says:
"A non-zero argument should be used"
if that's the only thing which works...
count = 0;