find return address

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

find return address

1,804件の閲覧回数
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 返答(返信)

680件の閲覧回数
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 件の賞賛
返信

680件の閲覧回数
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 件の賞賛
返信

680件の閲覧回数
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 件の賞賛
返信