find return address

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

find return address

1,512 Views
Ionut
Contributor I
Hi,
How can I find the return address from the stack (the address of the calling function) ?
 
Thanks
Labels (1)
Tags (1)
0 Kudos
3 Replies

388 Views
CompilerGuru
NXP Employee
NXP Employee
For which processor?

In general, in ANSI C there is no portable way. For a specific compiler and a specific architecture, it might be possible to know something from the way functions are called. Otherwise you have to revert to assembly, probably this is the only way which really reliably works.

Why do you need the return address?
Do you need just the address of the caller or the addresses of the complete call chain (much harder)?


Daniel
0 Kudos

388 Views
Ionut
Contributor I
Sorry I've forgot to mentions it's a HCS08 MCU.
I would need only the address of the caller function, not the whole call stack.
 
0 Kudos

388 Views
CompilerGuru
NXP Employee
NXP Employee
As I said, I don't think you can do this in C. With assembly/HLI its not dificult.
In the attachment (I hope it gets attached) I coded a sample. I used the elipsis (...) calling convention to make sure the compiler passes all arguments on the stack. Otherwise the trampoline code has to make sure it does pass the arguments on properly.
What kind of arguments has your function?
Any?
What do you try to do, BTW.

Daniel
0 Kudos