惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
F
Full Disclosure
Vercel News
Vercel News
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
H
Hacker News: Front Page
H
Heimdal Security Blog
P
Privacy International News Feed
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
L
Lohrmann on Cybersecurity
D
Docker
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
人人都是产品经理
人人都是产品经理
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
博客园 - 叶小钗
Google Online Security Blog
Google Online Security Blog
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
S
Secure Thoughts
博客园 - Franky
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
P
Palo Alto Networks Blog
Latest news
Latest news
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学

博客园 - Lunais

恢复 git stash drop 丢失的内容 Git技巧:彻底重置本地仓库与远程同步,同时保留Stash内容 信源编码和信道编码区别 Leetcode scanf 一组数据差值之和最大 5G 3gpp协议 eclipse调试配置 find查找 浮点类型(float、double)在内存中的存储 yield [基础函数]memset用法 python2处理表格文件按照规则多行输出(中文路径,print) linux系统objdump输出动态库.so文件和静态库.a中符号表 python复制删除文件&修改目录&执行bat(wins) Linux C下的正则表达式 kill eclipse C语言之表达式运算整体提升 查找函数对比:findall,search,match git本地协同
Linux backtrace()
Lunais · 2020-09-09 · via 博客园 - Lunais

https://man7.org/linux/man-pages/man3/backtrace.3.html

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdint.h>
 4 #include <stdlib.h>
 5 #include "execinfo.h"
 6 
 7 typedef uint32_t UINT32;
 8 
 9 void fun3(void)
10 {
11     void* array[10] = {0};
12     UINT32 size = 0;
13     char **strframe = NULL;
14     UINT32 i = 0, j = 0;
15 
16     size = backtrace(array, 10);
17     strframe = (char **)backtrace_symbols(array, size);
18 
19     printf("print call frame now: 0x%x\n", fun3);
20     for(i = 0; i < size; i++)
21     {
22         printf("frame %d -- %s\n", i, strframe[i]);
23     }
24 
25     if(strframe)
26     {
27         free(strframe);
28         strframe = NULL;
29     }
30 }
31 
32 void fun2(void)
33 {
34     printf("fun2 0x%x\n", fun2);
35     fun3();
36 }
37 
38 void fun1(void)
39 {
40     printf("fun1 0x%x\n", fun1);
41     fun2();
42 }
43 
44 int main(void)
45 {
46     printf("main 0x%x\n", main);
47     fun1();
48     return 0;
49 }

[xxxzte.intra@桌面]$ gcc -g -rdynamic backTrace.c

[xxx@zte.intra@桌面]$ ./a.out
main 0x4009b8
fun1 0x400998
fun2 0x400978
print call frame now: 0x4008a6
frame 0 -- ./a.out(fun3+0x4a) [0x4008f0]
frame 1 -- ./a.out(fun2+0x1d) [0x400995]
frame 2 -- ./a.out(fun1+0x1d) [0x4009b5]
frame 3 -- ./a.out(main+0x1d) [0x4009d5]
frame 4 -- /usr/lib64/libc.so.6(__libc_start_main+0xf1) [0x7f2381398401]
frame 5 -- ./a.out(_start+0x2a) [0x4007da]

[xxx@zte.intra@桌面]$ addr2line 0x4009d5 -e ./a.out -f
main
/home/xxx@zte.intra/桌面/backTrace.c:48