- logcat的崩溃信息保存到文件a.txt,崩溃信息大致如下:
--------- beginning of crash
2022-02-24 14:46:37.948 26127-26127/com.example.myapplicationndk A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 26127 (yapplicationndk), pid 26127 (yapplicationndk)
2022-02-24 14:46:37.977 26156-26156/? I/crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstone
2022-02-24 14:46:37.978 1011-1011/? I//system/bin/tombstoned: received crash request for pid 26127
2022-02-24 14:46:37.979 26156-26156/? I/crash_dump64: performing dump of process 26127 (target tid = 26127)
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: Build fingerprint: 'Xiaomi/sagit/sagit:9/PKQ1.190118.001/V11.0.5.0.PCACNXM:user/release-keys'
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: Revision: '0'
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: ABI: 'arm64'
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: pid: 26127, tid: 26127, name: yapplicationndk >>> com.example.myapplicationndk <<<
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: Cause: null pointer dereference
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: x0 0000000000000000 x1 0000000000000000 x2 0000000000000018 x3 12f2df5012e80f40
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: x4 0000000000000000 x5 12f2df5012e80f40 x6 0000007fe51246f0 x7 0000000000000000
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: x8 0101010101010101 x9 f6a917c307eaf2b7 x10 0000000000430000 x11 0000007513a6a688
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: x12 000000000000018c x13 0000007599d4c018 x14 0000007599f38000 x15 ffffffffffffffff
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: x16 00000074fa2fae98 x17 0000007594668990 x18 0000000000000000 x19 0000007514014c00
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: x20 0000000000000000 x21 0000007514014c00 x22 0000007fe5124980 x23 00000075994fc658
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: x24 0000000000000004 x25 0000007599f585e0 x26 0000007514014ca0 x27 0000000000000001
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: x28 0000007fe51246b0 x29 0000007fe51245c0
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: sp 0000007fe51245b0 lr 00000074fa2d5580 pc 00000075946689a0
2022-02-24 14:46:38.044 2261-2261/? D/EventBus: [2261, u0] send(AppTransitionFinishedEvent)
2022-02-24 14:46:38.044 1602-2118/? I/Timeline: Timeline: App_transition_stopped time:253873625
2022-02-24 14:46:38.044 2261-2261/? D/EventBus: [2261, u0] -> ForcedResizableInfoActivityController [0xf1c2522, P1] onBusEvent(AppTransitionFinishedEvent)
2022-02-24 14:46:38.044 2261-2261/? D/EventBus: [2261, u0] onBusEvent(AppTransitionFinishedEvent) duration: 12 microseconds, avg: 471
2022-02-24 14:46:38.301 26156-26156/? A/DEBUG: backtrace:
2022-02-24 14:46:38.302 26156-26156/? A/DEBUG: #00 pc 000000000001e9a0 /system/lib64/libc.so (strlen+16)
2022-02-24 14:46:38.302 26156-26156/? A/DEBUG: #01 pc 000000000000f57c /data/app/com.example.myapplicationndk-Cg5eoFht9iH5OlGlzpqwZg==/lib/arm64/libmyapplicationndk.so (std::__ndk1::char_traits<char>::length(char const*)+20)
2022-02-24 14:46:38.302 26156-26156/? A/DEBUG: #02 pc 000000000000f068 /data/app/com.example.myapplicationndk-Cg5eoFht9iH5OlGlzpqwZg==/lib/arm64/libmyapplicationndk.so (_ZNSt6__ndk112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC2IDnEEPKc+48)
2022-02-24 14:46:38.302 26156-26156/? A/DEBUG: #03 pc 000000000000efb4 /data/app/com.example.myapplicationndk-Cg5eoFht9iH5OlGlzpqwZg==/lib/arm64/libmyapplicationndk.so (Java_com_example_myapplicationndk_MainActivity_stringFromJNI+56)
2022-02-24 14:46:38.302 26156-26156/? A/DEBUG: #04 pc 00000000005667e0 /system/lib64/libart.so (art_quick_generic_jni_trampoline+144)
2022-02-24 14:46:38.302 26156-26156/? A/DEBUG: #05 pc 000000000055d788 /system/lib64/libart.so (art_quick_invoke_stub+584)
2022-02-24 14:46:38.302 26156-26156/? A/DEBUG: #06 pc 00000000000d074c /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200)
2022-02-24 14:46:38.302 26156-26156/? A/DEBUG: #07 pc 0000000000280dbc /system/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+344)
2022-02-24 14:46:38.302 26156-26156/? A/DEBUG: #08 pc 000000000027add0 /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968)
- 执行命令
ndk-stack -sym xxxxxx/app/build/intermediates/cmake/debug/obj/arm64-v8a -i a.txt
其中obj文件根据自己项目符号表选择。 打印信息包含如下内容,可以看到崩溃在native-lib.cpp:8:25 :
? arm64-v8a ndk-stack -sym /Users/shuai/tmp/MyApplicationNDK/app/build/intermediates/cmake/debug/obj/arm64-v8a -i ff.txt
********** Crash dump: **********
#03 0x000000000000efb4 /data/app/com.example.myapplicationndk-Cg5eoFht9iH5OlGlzpqwZg==/lib/arm64/libmyapplicationndk.so (Java_com_example_myapplicationndk_MainActivity_stringFromJNI+56)
Java_com_example_myapplicationndk_MainActivity_stringFromJNI
/Users/shuai/tmp/MyApplicationNDK/app/src/main/cpp/native-lib.cpp:8:25
写在最后
其实只需要这一行标识,后面加上自己关心的崩溃信息即可:
2022-02-24 14:46:37.984 26156-26156/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
? ndk-stack --help usage: ndk-stack.py [-h] -sym SYMBOL_DIR [-i INPUT]
Symbolizes Android crashes.
optional arguments: -h, --help show this help message and exit -sym SYMBOL_DIR, --sym SYMBOL_DIR directory containing unstripped .so files -i INPUT, -dump INPUT, --dump INPUT input filename
|