linux 下core的文件生成和调试

core文件生成及调试
1 代码
#include<stdio.h>
int main()
{
  int *p = NULL;
  *p = 0;
  return 0;
}

 

2 在当前shell执行ulimit -c unlimited
注意:该命令只在当前shell生效,其他shell会失效ulimit -c是0,生成core文件失败。


3 core文件默认在执行程序当前目录下

 

4 生成及调试core文件
gcc -o test test.c
./test
Segmentation fault (core dumped)
这里出现段错误并生成core文件了

在/corefile目录下发现core-test-31421-1476266571
开始调试
gdb ./test core-test-31421-1476266571

或 gdb -c core-test-31421-1476266571 ./test 

 

 5 执行bt命令查看调用堆栈

posted @ 2019-12-03 17:46  wjbooks  阅读(1824)  评论(0编辑  收藏  举报