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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM