[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Finding address of where a function called from
From: |
Dmitry K. |
Subject: |
Re: [avr-gcc-list] Finding address of where a function called from |
Date: |
Fri, 30 Jan 2004 09:04:25 +1000 |
User-agent: |
KMail/1.5 |
29 Jan 2004 14:51 Tom Harris wrote:
> Greetings,
>
> For logging purposes I would like the called function to be able to find
> out where it was called _from_. What I have done in the past is to take the
> address of a dummy variable on the stack, add a bit to it and hope that the
> result is the address of the stack with the return in it. Sort of the code
> below (which is off the top of my head and probably doesn't even compile):
>
> #define FIDDLE_FACTOR 4
> void foo() {
> char dummy;
>
> uint16_t* whereCalled = *((uint16_t*)(&dummy) + FIDDLE_FACTOR);
>
> ...
> }
>
> The problem is that as the number of stack reserved for the use of foo()
> changes, so does the size of FIDDLE_FACTOR. Is there a more portable way of
> determining this?
>
> TomH
It is sad. Function `__builtin_return_address' does not work in avr-gcc.
It takes contents of a top of a stack, without consideration his use.
Gcc for i86, pdp-11: all works correctly.
Example:
extern void foo (char *);
extern void *p;
void foo1 (void)
{
char s[10];
foo(s);
p= __builtin_return_address(0);
}
Result:
...
rcall foo
ldd r24,Y+1 ??? must: Y+1+10
ldd r25,Y+2
sts (p)+1,r25
sts p,r24
/* epilogue: frame size=10 */
adiw r28,10
...