【48】gdb 查看core堆栈信息

1、查看系统资源设置情况
用户态程序Segmentation fault会生成core文件,如果没有生成core文件,则使用ulimit命令显示系统资源的设置,看看core文件大小设置,可以看到现在core file size是0,无法生成core文件
root@cd-106:~/pcieinject# ulimit
unlimited
root@cd-106:~/pcieinject# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 319992
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 319992
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
2、设置core file size为unlimited
root@cd-106:~/pcieinject# ulimit -c unlimited
root@cd-106:~/pcieinject# ulimit -a

core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 319992
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 319992
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

3、执行用户态程序,生成core文件
Segmentation fault (core dumped)
root@cd-106:~/pcieinject# ll
total 716
drwxr-xr-x 6 root root 4096 Jan 3 09:45 ./
drwx------ 25 root root 4096 Jan 2 21:03 …/
drwxr-xr-x 2 root root 4096 Dec 25 10:52 comlib/
-rw------- 1 root root 602112 Jan 3 09:45 core

4、解析core文件
root@cd-106:~/pcieinject# gdb pcieinject core
使用backtrace或者bt找到调用栈
(gdb) bt

参考
https://blog.csdn.net/u013283985/article/details/80620237
https://www.cnblogs.com/schips/p/10735807.html
https://baijiahao.baidu.com/s?id=1599347824327158577&wfr=spider&for=pc

发布了35 篇原创文章 · 获赞 9 · 访问量 1万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章