__builtin_return_address

Matt Newcomb spock@telerama.com
Tue Oct 31 19:18:00 GMT 2000


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: watchtest6.tar.gz
Type: application/x-gzip
Size: 10539 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20001031/81a7b78e/attachment.bin>


More information about the Gcc-bugs mailing list