coredump產生

coredump

上一節分析了產生NE後生成tombstone的流程,有時候通過分析tombstone並不能解決問題,這時候我們需要coredump來分析問題,core文件會包含了程序運行時的內存,寄存器狀態,堆棧指針,內存管理信息還有各種函數調用堆棧信息等,我們可以理解爲是程序工作當前狀態存儲生成第一個文件,許多的程序出錯的時候都會產生一個core文件,通過工具分析這個文件,我們可以定位到程序異常退出的時候對應的堆棧調用等信息,找出問題所在並進行及時解決。
當debuggerd處理完後,程序再次回到發生異常的環境,此時還會發生1次異常,同樣的會再次發送信號(第三次)。

kernel-3.18/kernel/signal.c:

2332         */
2333        current->flags |= PF_SIGNALED;
2334
2335        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 all
2341             * other threads in the group and synchronizes with
2342             * their demise.  If we lost the race with another
2343             * thread getting here, it set group_exit_code
2344             * first and our do_group_exit call below will use
2345             * 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_COREDUMP
ELF 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 shell
xxx:/ # cat /proc/sys/kernel/core_pattern
|/vendor/bin/aee_core_forwarder /data/core/ %p %s UID=%u GID=%g

缺省狀態:

@$ adb shell
xxx:/ # cat /proc/sys/kernel/core_pattern
core

coredump是抓取進程空間內的內存並保存到文件上,並不是所有內存都需要保存的,你可以通過設置/proc/$pid/coredump_filter參數過濾,只抓取部分內存。該參數是一個值,每個bit位都有對應的含義用來表示是否抓取這部分內:

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

@$ adb shell cat /proc/505/coredump_filter
00000027

最後需要發生異常時候的so庫文件,需要帶符號表的:

out/target/product/xxx/symbols/system/vendor/lib/libcancer.so
out/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去分析這類型的問題,所以要更深入的去理解分析這類問題還需要跟還需要更多理論知識;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章