Wednesday, April 30, 2014

How to get a core dump


If your process is segfaulting, and you aren't getting a core dump, you need to make sure the kernel will allow them. First make sure that ulimit allows core files. 


$> ulimit -a 
core file size          (blocks, -c) 0

That says that core files are not allowed. You can set that for the current session by running:

$> ulimit -c unlimited 

Though you may be better off updating editing /etc/security/limits.conf. The next thing to set is fs.suid_dumpable and kernel.core_pattern. see: http://man7.org/linux/man-pages/man5/core.5.html


$> sysctl -w fs.suid_dumpable=2
$> sysctl -w kernel.core_pattern=/tmp/core

When setting the core_pattern, make sure that directory, in this case /tmp, is writable by the user process you want a core dump from. Be careful that your start script is not overriding anything anything. I found that /etc/init.d/functions daemon function set's the -c option and you need to export DAEMON_COREFILE_LIMIT=unlimited in your start script.

Once you have a core file, you can analyze with gdb e.g. 

$> gdb /tmp/core.0231
$> bt


The backtrace may require you to install debug symbols with debug-info. To do that I had to run:

$> yum install yum-utils

Then I could run debuginfo-install e.g. 

$> debuginfo-install httpd-2.2.15-30.el6.centos.x86_64


No comments: