Android系统coredump

1.打开内核coredump功能

Android系统的linux内核有可能没有打开coredump功能,可以通过查看android系统是否存在/proc/sys/kernel/core_patten配置项来确定,如果没有该配置项,那么需要重新配置内核,并且重新编译,并将其替换掉目标android系统内核(具体更新方试需要根据不同的硬件而定)。下面为coredump内核配置项的具体位置:

make menuconfig 
 Userspace binary formats-->
   [*] Enable core dump support

开启该选项,系统就支持程序的coredump功能,保存退出,重新编译内核,并下载到目标系统中就可了。重启后,在文件系统中应该就可看到/proc/sys/kernel/core_pattern配置项了。

2.配置coredump的存储位置

将core文件存储位置写入到/proc/sys/kernel/core_pattern即可,但/proc为内存文件系统,系统重启后,该配置会失效,所以对于android系统可以将配置该文件的命令写入到init.rc中,例如:


setrlimit 4  -1 -1      

mkdir /data/coredump 0777 system system

write /proc/sys/kernel/core_pattern  /data/coredump/core.%e.%p

下面是关于core_pattern的介绍:

core_pattern:
core_pattern is used to specify a core dumpfile pattern name.
. max length 128 characters; default value is "core"
. core_pattern is used as a pattern template for the output filename;
  certain string patterns (beginning with '%') are substituted with
  their actual values.
. backward compatibility with core_uses_pid:
    If core_pattern does not include "%p" (default does not)
    and core_uses_pid is set, then .PID will be appended to
    the filename.
. corename format specifiers:
    %  '%' is dropped
    %%  output one '%' 
    %p  pid 
    %u  uid 
    %g  gid 
    %d  dump mode, matches PR_SET_DUMPABLE and                                                                                                                                                              
        /proc/sys/fs/suid_dumpable
    %s  signal number
    %t  UNIX time of dump
    %h  hostname
    %e  executable filename (may be shortened)
    %E  executable path
    % both are dropped

你可能感兴趣的:(Linux,embedded,development)