Coredump及調試


1、查看是否打開了coredump

  1. lybxin@Inspiron:~/MyRes/miscellany/test/01_coredump$ulimit -c  #這里可以看到ulimit限制coredump的產生
  2. 0
  3. lybxin@Inspiron:~/MyRes/miscellany/test/01_coredump$ulimit -c unlimited  #取消限制
  4. lybxin@Inspiron:~/MyRes/miscellany/test/01_coredump$ulimit -c
  5. unlimited

 

2、coredump默認存儲在與程序相同的目錄里

 

3、core文件的命名規則
/proc/sys/kernel/core_uses_pid  1 表示使用procid命名,0表示不使用
/proc/sys/kernel/core_pattern 可以設置格式化的 core 文件保存位置或文件名
echo “/opt/corefile/core-%e-%p-%t” > /proc/sys/kernel/core_pattern
將會控制所產生的 core 文件會存放到 /corefile 目錄下,產生的文件名為 core- 命令名 -pid- 時間戳
以下是參數列表 :
   %p - insert pid into filename 添加 pid
   %u - insert current uid into filename 添加當前 uid
   %g - insert current gid into filename 添加當前 gid
   %s - insert signal that caused the coredump into the filename 添加導致產生 core 的信號
   %t - insert UNIX time that the coredump occurred into filename 添加 core 文件生成時的 unix 時間
   %h - insert hostname where the coredump happened into filename 添加主機名
   %e - insert coredumping executable name into filename 添加命令名

 

4、core_pattern內核解析函數

format_corename

 

 

5、Coredump調試

除了下面方法外,也可以在打開gdb后使用core-file core-xxx命令來吧core-xxx文件加載進去

  1. lybxin@Inspiron:~/MyRes/miscellany/test/04_gdbtest$gdb -core=core
  2. GNU gdb (Ubuntu7.11.1-0ubuntu1~16.04)7.11.1
  3. Copyright(C)2016FreeSoftwareFoundation,Inc.
  4. LicenseGPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  5. This is free software: you are free to change and redistribute it.
  6. There is NO WARRANTY, to the extent permitted by law.  Type"show copying"
  7. and "show warranty"for details.
  8. This GDB was configured as "x86_64-linux-gnu".
  9. Type"show configuration"for configuration details.
  10. For bug reporting instructions, please see:
  11. <http://www.gnu.org/software/gdb/bugs/>.
  12. Find the GDB manual and other documentation resources online at:
  13. <http://www.gnu.org/software/gdb/documentation/>.
  14. For help, type "help".
  15. Type"apropos word" to search for commands related to "word".
  16. [New LWP 6093]
  17. Core was generated by `./testgdb.out'.
  18. Program terminated with signal SIGSEGV, Segmentation fault.
  19. #0  0x00000000004005f4 in ?? ()
  20. (gdb) bt
  21. #0  0x00000000004005f4 in ?? ()
  22. #1  0x000000000000000a in ?? ()
  23. #2  0x0000000000000140 in ?? ()
  24. #3  0x00007fff5297f7d0 in ?? ()
  25. #4  0x0000000000000145 in ?? ()
  26. #5  0x00007fff5297f6d0 in ?? ()
  27. #6  0x000000000040065e in ?? ()
  28. #7  0x00000000004007ac in ?? ()
  29. #8  0x000000647ce2a7fa in ?? ()
  30. #9  0x0000000000000000 in ?? ()
  31. (gdb) file all.out
  32. warning: core file may not match specified executable file.
  33. Reading symbols from all.out...done.
  34. (gdb) bt
  35. #0  0x00000000004005f4 in test1 (p=320)
  36.    at /home/lybxin/MyRes/miscellany/test/04_gdbtest/testgdb.c:18
  37. #1  0x000000000040065e in test2 (offset=100)
  38.    at /home/lybxin/MyRes/miscellany/test/04_gdbtest/testgdb.c:30
  39. #2  0x00000000004006c3 in main (argc=1, argv=0x7fff5297f7d8)
  40.    at /home/lybxin/MyRes/miscellany/test/04_gdbtest/testgdb.c:46
  41. (gdb)

 

 

 






免責聲明!

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



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