This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

using __builtin_return_address?

I'm using egcs 19990712 (so its new...)

I'm trying to run this subroutine:
        int i;
        void *p;

        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:
`__builtin_return_address (LEVEL)'
     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
     return `0'.

     This function should only be used with a non-zero argument for
     debugging purposes.

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)...

	core dumps
	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;

Marty Leisner

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]