This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
__builtin_return_address
- To: gcc-bugs at gcc dot gnu dot org
- Subject: __builtin_return_address
- From: Matt Newcomb <spock at telerama dot com>
- Date: 31 Oct 2000 22:18:21 -0500
- Reply-To: Matt Newcomb <spock at telerama dot com>
G'day,
It is my interpretation that if you call
__builtin_return_address with position in the call stack
higher than the top of the call stack then it should
return 0. I've been told by several people that this is
supposed to happen and have seen at least three
debugging/profiling packages that make this assumption.
This does not happen on my machine ( Linux
kong.physics.berkeley.edu 2.2.14 #16 SMP Mon Sep 18
19:03:57 PDT 2000 i686 unknown ). The command "gcc -v"
returns the following:
Reading specs from
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2
release)
A test program looks like:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
void *returnPtr;
returnPtr=__builtin_return_address(0);
fprintf(stdout,"%x\n",returnPtr);
returnPtr=__builtin_return_address(1);
fprintf(stdout,"%x\n",returnPtr);
}
On my machine, this program compiled with 'gcc
watchtest6.c -o watchtest6' when run returns:
400349cb
8048361
On an ultrasparc ( SunOS unix3.andrew.cmu.edu 5.7
Generic_106541-11 sun4u sparc SUNW,Ultra-30 ), this
program compiled with the same options returns:
10718
0
Oh, and on the sparc gcc -v returns:
Reading specs from
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs
gcc version 2.95.2 19991024 (release)
Just for consistencies sake I upgraded my version of gcc
to the same version as on the sparc ( see above ) and
the example program still outputs:
400309cb
8048361
Attached you will find a tarball with the source and the
output of gcc when run with the options:
gcc -v -savetemps watchtest6.c -o watchtest6
Thank you,
Matt
Newcomb
watchtest6.tar.gz