2015年1月24日 星期六

[Embedded] Why no core dump after segmentation fault?

1. Follow below command to set core dump generated in embedded Linux.
$ ulimit -c 1024
$ echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern

2. Why no core dump?
  • no write access to the directory 
  • use "ls" to check
  • the program changes the working directory 
  • how to check??
  • look for the core in other places too 
  • use "sysctl -a | grep core_pattern" to check
  • disk is full 
  • use "df ." to check
  • most Unix systems do not allow a setuid process to dump core 
  • use "cat /proc/sys/fs/suid_dumpable" to check,  
  • use "echo 1 > /proc/sys/fs/suid_dumpable" to change setting 
  • ulimit is set in one shell and the program is started in a different shell or environment
  • check /proc/pid/environ for current shell
  • note that only the program executed after "ulimit -c 1024" can generate core

3. We can use "kill -ABRT  pid_of_process" to generate core manually.

4. Check /proc/pid/limits for system limit
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytesMax resident set          unlimited            unlimited            bytes
Max processes             748                  748                  processes
Max open files            1024                 1024                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       748                  748                  signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

Reference:
  1. http://stackoverflow.com/questions/15272817/segmentation-fault-no-core-dump
  2. http://www.idimmu.net/2013/06/21/enable-linux-core-dump/
  3. http://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins
  4. http://blog.csdn.net/pro_or_gram/article/details/15813879
  5. http://linuxxperts.com/enabling-core-dumps-in-embedded-systems/
  6. http://tieba.baidu.com/p/2365639005