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命令查看調用堆棧