ubuntu生成core转储文件

1、ulimit -c 判断是否开启转储

为0 则没有开启

2、ulimit -c unlimited 设置转储core大小没有限制

3、设置转储文件位置 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、运行./cpu_test 发生段错误、生成了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)

posted @ 2018-03-22 14:25  karllen  阅读(1693)  评论(0编辑  收藏  举报