在Linux上生成Core Dump文件的配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dayancn/article/details/50963822

Linux生成core dump的做法


一、 内核必须打开选项 CONFIG_ELF_CORE;


二、配置每个进程的RLIMIT_CORE资源为RLIM_INFINITY。方法有二:

1. 在busybox的init/init.c源文件定义了宏CORE_ENABLE_FLAG_FILE,

#define CORE_ENABLE_FLAG_FILE "/.init_enable_core"

如果根目录中存在此文件,那么run会自动设core dump文件大小设为不限。

 #if ENABLE_FEATURE_INIT_COREDUMPS                                                                               
         {                                                                                                       
                 struct stat sb;                                                                                 
                 if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {                                                    
                         struct rlimit limit;                                                                    
                                                                                                                 
                         limit.rlim_cur = RLIM_INFINITY;                                                         
                         limit.rlim_max = RLIM_INFINITY;                                                         
                         setrlimit(RLIMIT_CORE, &limit);                                                         
                 }                                                                                               
         }                                                                                                       
 #endif

2. 使用ulimit命令,unlimited可以一个适当的数值。请参数man ulimit。

# ulimit -c unlimited


三、core_pattern设置

因为可执行文件的目录可能没有写入权限,因为可以修改这个文件,如:

# echo "/tmp/cores/core" > /proc/sys/kernel/core_pattern

详解,请参考Documentation/sysctl/kernel.txt中core_pattern部分。


四、在PC上执行调试

# gdb-host ./app ./core.xxxx

# arm-gdb-host ./app ./core.xxxx

# mips-gdb-host ./app ./core.xxxx


展开阅读全文

没有更多推荐了,返回首页