用__builtin_return_address获得程序运行栈情况【转】

转自:http://blog.csdn.net/vpwork/article/details/7680102

    %pF    versatile_init+0x0/0x110
    %pf    versatile_init

 

版权声明:本文为博主原创文章,未经博主允许不得转载。
[cpp] view plain copy
#include
<stdio.h> #include <stdlib.h> #include <signal.h> #define MAX_LEVEL 4 void sigfunc(int signo) { printf("%s(0): %p\n", __func__, __builtin_return_address(0)); exit(1); } int b() { printf("%s(0): %p\n", __func__, __builtin_return_address(0)); printf("%s(1): %p\n", __func__, __builtin_return_address(1)); while(1) { sleep(1); } } int a(int temp) { temp += 1; printf("%s(0): %p\n", __func__, __builtin_return_address(0)); b(); return temp; } int main() { signal(SIGINT, sigfunc); a(123); return 0; } 执行后: a(0): 0x400675 b(0): 0x400653 b(1): 0x400675 ^Csigfunc(0): 0x30bda33140 用gdb调试: gdb e ... (gdb) l *0x400675 0x400675 is in main (e.c:37). 32 int main() 33 { 34 signal(SIGINT, sigfunc); 35 a(123); 36 37 return 0; 38 }

 

posted @ 2017-07-13 16:49  Sky&Zhang  阅读(1904)  评论(0编辑  收藏  举报