coredump产生

来源:互联网 发布:淘宝买汽车靠谱吗 编辑:程序博客网 时间:2024/04/30 03:56

coredump

上一节分析了产生NE后生成tombstone的流程,有时候通过分析tombstone并不能解决问题,这时候我们需要coredump来分析问题,core文件会包含了程序运行时的内存,寄存器状态,堆栈指针,内存管理信息还有各种函数调用堆栈信息等,我们可以理解为是程序工作当前状态存储生成第一个文件,许多的程序出错的时候都会产生一个core文件,通过工具分析这个文件,我们可以定位到程序异常退出的时候对应的堆栈调用等信息,找出问题所在并进行及时解决。
当debuggerd处理完后,程序再次回到发生异常的环境,此时还会发生1次异常,同样的会再次发送信号(第三次)。

kernel-3.18/kernel/signal.c:

2332         */2333        current->flags |= PF_SIGNALED;23342335        if (sig_kernel_coredump(signr)) {2336            if (print_fatal_signals)2337                print_fatal_signal(ksig->info.si_signo);2338            proc_coredump_connector(current);2339            /*2340             * If it was able to dump core, this kills all2341             * other threads in the group and synchronizes with2342             * their demise.  If we lost the race with another2343             * thread getting here, it set group_exit_code2344             * first and our do_group_exit call below will use2345             * that value and ignore the one we pass it.2346             */2347            do_coredump(&ksig->info);//主要通过这个函数进行dump;2348        }

由于linker里的debuggerd_init()里注册的几个信号,默认行为都会产生coredump,MTK平台通过AEE模块来收集coredump和一些log信息并压缩在db文件里面,需要通过GAT工具才能打开db文件;

readelf -h PROCESS_COREDUMPELF Header:  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00   Class:                             ELF32  Data:                              2's complement, little endian  Version:                           1 (current)  OS/ABI:                            UNIX - System V  ABI Version:                       0  Type:                              CORE (Core file)

解压之后,文件夹里面有PROCESS_COREDUMP的文件,可以用readelf -h来查看这个文件头,CORE (Core file)就表示这个文件是core文件;

可以通过下面的方式查看core存放的位置:

@$ adb shellxxx:/ # cat /proc/sys/kernel/core_pattern|/vendor/bin/aee_core_forwarder /data/core/ %p %s UID=%u GID=%g

缺省状态:

@$ adb shellxxx:/ # cat /proc/sys/kernel/core_patterncore

coredump是抓取进程空间内的内存并保存到文件上,并不是所有内存都需要保存的,你可以通过设置/proc/$pid/coredump_filter参数过滤,只抓取部分内存。该参数是一个值,每个bit位都有对应的含义用来表示是否抓取这部分内:

bit0: 私有匿名
bit1: 共享匿名
bit2: 有底层文件的私有映射
bit3: 有底层文件共享映射
bit4: ELF头
bit5: 私有大尺寸页
bit6: 共享大尺寸页

@$ adb shell cat /proc/505/coredump_filter00000027

最后需要发生异常时候的so库文件,需要带符号表的:

out/target/product/xxx/symbols/system/vendor/lib/libcancer.soout/target/product/xxx/symbols/system/bin/cameraserver

现在就可以用GDB简单来打开coredump文件了:

@$ arm-linux-androideabi-gdb symbols/cameraserver PROCESS_COREDUMP There is NO WARRANTY, to the extent permitted by law.  Type "show copying"and "show warranty" for details.This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".For bug reporting instructions, please see:<http://source.android.com/source/report-bugs.html>...Reading symbols from /data/nishome/td/xx/symbols/cameraserver...done.Core was generated by `/system/bin/cameraserver'.Program terminated with signal 4, Illegal instruction.#0  0xe09a4988 in ?? ()

平时工作当中很少通过gdb去分析这类型的问题,所以要更深入的去理解分析这类问题还需要跟还需要更多理论知识;

0 0
原创粉丝点击