find return address

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

find return address

2,342 次查看
Ionut
Contributor I
Hi,
How can I find the return address from the stack (the address of the calling function) ?
 
Thanks
标签 (1)
标记 (1)
0 项奖励
回复
3 回复数

1,218 次查看
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 项奖励
回复

1,218 次查看
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 项奖励
回复

1,218 次查看
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 项奖励
回复