“确定被调用的宿主问题”各种语言版大征集!
C语言版:需要尽量简单地设置编译链接选项。VC6
http://topic.csdn.net/u/20120530/05/A9E5E49E-940A-44AE-96A5-A0E7DB986C10.html
#include <stdio.h>void whocallme();void fun1() { whocallme();}void fun2() { whocallme();}void fun3() { fun1();}void whocallme() { int *_esp,i; __asm { mov eax,esp mov _esp,eax } printf("\nfun1,fun2,fun3,_esp=%08x,%08x,%08x,%08x\n",(int)fun1,(int)fun2,(int)fun3,(int)_esp); for (i=0;i<100;i++) if (_esp[i]==(int)_esp) break; if (i<100) { printf("ret addr=%08x\n",_esp[i+2]); if ((int)fun1<=_esp[i+2] && _esp[i+2]<(int)fun2) printf("fun1 callme\n"); if ((int)fun2<=_esp[i+2] && _esp[i+2]<(int)fun3) printf("fun2 callme\n"); }}void main() { fun2(); fun1();}//C:\tmp\tmp\Debug>tmp////fun1,fun2,fun3,_esp=00401000,00401020,00401040,0012fe84//ret addr=0040102e//fun2 callme////fun1,fun2,fun3,_esp=00401000,00401020,00401040,0012fe84//ret addr=0040100e//fun1 callme////C:\tmp\tmp\Debug>cd ..\release////C:\tmp\tmp\Release>tmp////fun1,fun2,fun3,_esp=00401000,0040100a,00401014,0012ff5c//ret addr=00401012//fun2 callme////fun1,fun2,fun3,_esp=00401000,0040100a,00401014,0012ff5c//ret addr=00401008//fun1 callme//