由于一直都在做android系统相关的工作,获取native crash日志文件比较方便,只要发生native crash我们直接去/data/tombstones下找就行了,然后找到当天系统的symbols文件,再配合addr2line就可以分析了。因为今天被人问了app 没有权限应该怎么获取native crash堆栈,自己也只是大概知道是通过捕获信号量的方式处理的,并没有能说得很清楚,所以花了一晚上网上各种查资料参考别人的代码先搞了一个能用的案例,有空的时候再研究一下详细过程。
一.下载代码:git clone https://gitee.com/water_p/CollectNativeCrash.git
二.编译代码:./configure && make
三.sudo make install
四.idea 导入安卓项目CollectNativeCrashTest
五.运行安卓项目CollectNativeCrashTest
六.点击crash按钮
七.日志如下:
06-30 03:22:41.521 11476-11496/com.example.pzc.collectnativecrashtest I/Adreno: PFP: 0x016ee181, ME: 0x00000000
06-30 03:22:41.526 11476-11496/com.example.pzc.collectnativecrashtest I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 1
06-30 03:22:41.527 11476-11496/com.example.pzc.collectnativecrashtest I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 1
06-30 03:22:41.527 11476-11496/com.example.pzc.collectnativecrashtest I/OpenGLRenderer: Initialized EGL, version 1.4
06-30 03:22:41.527 11476-11496/com.example.pzc.collectnativecrashtest D/OpenGLRenderer: Swap behavior 2
06-30 03:22:43.647 11476-11476/com.example.pzc.collectnativecrashtest D/dodoodla_crash: crash
06-30 03:22:43.647 11476-11476/com.example.pzc.collectnativecrashtest D/dodoodla_crrrrrash: ==========init handlers_installed==========
06-30 03:22:43.807 11476-11476/com.example.pzc.collectnativecrashtest D/dodoodla_crash: ===============crrrrash================
06-30 03:22:43.808 11476-11476/com.example.pzc.collectnativecrashtest D/dodoodla_crash: Dump path: /data/user/0/com.example.pzc.collectnativecrashtest/files/crashDump/c8d740e2-00b4-4bc4-4f604286-7f64609c.dmp
c8d740e2-00b4-4bc4-4f604286-7f64609c.dmp这个就是native crash的dump文件了
八.生成日志文件minidump_stackwalk c8d740e2-00b4-4bc4-4f604286-7f64609c.dmp > log.txt
Operating system: Android
0.0.0 Linux 4.14.83-perf-g89059ed #1 SMP PREEMPT Tue Jun 18 06:10:36 CST 2019 aarch64
CPU: arm64
8 CPUs
GPU: UNKNOWN
Crash reason: SIGSEGV /SEGV_MAPERR
Crash address: 0x0
Process uptime: not available
Thread 0 (crashed)
0 libbreakpad-core.so + 0x26648
x0 = 0x0000000000000017 x1 = 0x0000007fd65ba1c0
x2 = 0x0000000000000005 x3 = 0x0000000000000003
x4 = 0x0000000000000067 x5 = 0x0000000000000000
x6 = 0x6071625e606b636e x7 = 0x7f7f7f7f7f7f7f7f
x8 = 0x0000000000000000 x9 = 0x0000000000000001
x10 = 0x0000007fd65ba360 x11 = 0x0000000000000007
x12 = 0x0000000000000018 x13 = 0xffffffffffffffff
x14 = 0xffffffffff000000 x15 = 0xffffffffffffffff
x16 = 0x0000007c9dd3d5c8 x17 = 0x0000007c9dcc6634
x18 = 0x0000000000000010 x19 = 0x0000007cb6814c00
x20 = 0x0000000000000000 x21 = 0x0000007cb6814c00
x22 = 0x0000007fd65babe0 x23 = 0x0000007cb018f64c
x24 = 0x0000000000000004 x25 = 0x0000007d3c6eb5e0
x26 = 0x0000007cb6814ca0 x27 = 0x0000000000000001
x28 = 0x0000007fd65ba910 fp = 0x0000007fd65ba8e0
lr = 0x0000007c9dcc6690 sp = 0x0000007fd65ba8c0
pc = 0x0000007c9dcc6648
Found by: given as instruction pointer in context
1 libbreakpad-core.so + 0x2668c
fp = 0x0000007fd65ba910 lr = 0x0000007cb61083e4
sp = 0x0000007fd65ba8f0 pc = 0x0000007c9dcc6690
Found by: previous frame's frame pointer
2 libart.so + 0x5603e0
fp = 0x12e402f000000001 lr = 0x0000000300010005
sp = 0x0000007fd65ba920 pc = 0x0000007cb61083e4
Found by: previous frame's frame pointer
3 libart-compiler.so + 0x26648
sp = 0x0000007fd65ba988 pc = 0x0000007cb018f64c
Found by: stack scanning
4 libart-compiler.so + 0x26648
sp = 0x0000007fd65ba9b8 pc = 0x0000007cb018f64c
Found by: stack scanning
5 libart.so + 0x557388
sp = 0x0000007fd65ba9f0 pc = 0x0000007cb60ff38c
Found by: stack scanning
6 libart-compiler.so + 0x1baca
sp = 0x0000007fd65baa08 pc = 0x0000007cb0184ace
Found by: stack scanning
7 libart.so + 0xcfcf4
sp = 0x0000007fd65baa18 pc = 0x0000007cb5c77cf8
Found by: stack scanning
8 libart-compiler.so + 0x26648
sp = 0x0000007fd65baa28 pc = 0x0000007cb018f64c
Found by: stack scanning
9 libllvm-glnext.so + 0x3d8a4
九.symbols路径
CollectNativeCrashTest/app/build/intermediates/cmake/debug/obj/arm64-v8a
十.反汇编
pzc@pzc-ThinkPad-E480:~/giteework/CollectNativeCrash/CollectNativeCrashTest/app/build/intermediates/cmake/debug/obj/arm64-v8a$ addr2line -f -e libbreakpad-core.
so 0x26648
_Z5Crashv
/home/pzc/giteework/CollectNativeCrash/CollectNativeCrashTest/app/src/main/cpp/breakpad.cpp:45
参考自: