How to enable program to dump core on linux?

删除回忆录丶 提交于 2020-01-13 19:12:50

问题


I want the program to dump core on crash on Linux for debugging purpose. How do I enable this feature - does this require any changes in the program ?


回答1:


You can either enable it for yourself by doing:

ulimit -c unlimited

If you want this to be persistent put it in ~/.profile

Alterantively, you can enable core dumps for all users on the system put the following line in /etc/sercurity/limits.conf (at least on ubuntu):

*   0  core    -1



回答2:


Whether generate core dump or not is controlled by the shell

If you use bash.

ulimit -c unlimited



回答3:


In addition to Troy's answer you will have to add to e/etc/sysctl.conf - where and how you need to core to be generated - like this :

kernel.core_uses_pid=1
kenrel.core_pattern= /tmp/cores/core-%e-%p-%u-%g-%s-%t
fs.suid_dumpable=2



回答4:


If your program is user-mode program. Here is a brief tutorial.

Set the core file size to maximum

ulimit -c unlimited

Run your program

$ ./your_program

Segmentation fault (core dumped)

It would generate core dump file. Use gdb to analyze the core dump

gdb ./your_progrm core

You can reference How to Debug Using GDB for more information.



来源:https://stackoverflow.com/questions/13832615/how-to-enable-program-to-dump-core-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!