1、ulimit -c 判斷是否開啟轉(zhuǎn)儲
為0 則沒有開啟
2、ulimit -c unlimited 設(shè)置轉(zhuǎn)儲core大小沒有限制
3、設(shè)置轉(zhuǎn)儲文件位置 echo "/var/core/%t-%e-%p-%c.core" > /proc/sys/kernel/core_pattern
4、測試程序cpu_test
1 int main(int argc, char **argv) {2 3 unsigned char * c = 0x00;4 *c = 'c';5 6 return 0;7 }
5、運(yùn)行./cpu_test 發(fā)生段錯誤、生成了core文件
1521694447-cpu_test-77274-18446744073709551615.core
1521696041-cpu_test-18423-18446744073709551615.core
1521696511-cpu_test-26547-18446744073709551615.core
1521698483-cpu_test-43924-18446744073709551615.core
6、gdb分析core文件 gdb ./cpu_test /var/core/1521698483-cpu_test-43924-18446744073709551615.core
Reading symbols from ./cpu_test...done.
[New LWP 18689]
Core was generated by `./cpu_test'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000000000040075d in main (argc=1, argv=0x7ffebf1ceb18)
at /home/karllen/projects/cpu_test/main.cpp:4
4 *c = 'c';
(gdb)
聯(lián)系客服