Android Native crash tomestone trace tools¶
工具目录¶
源代码下有批量转换 Native trace 工具 development/scripts。
前提¶
- python版本要大于3.6
- 必须lunch target
介绍¶
执行命令 ./development/scripts/stack -h 查看帮助
usage: stack [-h] [--arch ARCH] [--symbols-dir SYMBOLS_DIR | --symbols-zip SYMBOLS_ZIP] [-v] [FILE]
Parse and symbolize crashes
positional arguments:
FILE should contain a stack trace in it somewhere the tool will find that and re-print it with source files and line numbers. If you don't pass FILE, or if file is -, it reads from stdin.
optional arguments:
-h, --help show this help message and exit
--arch ARCH the target architecture
--symbols-dir SYMBOLS_DIR, --syms SYMBOLS_DIR, --symdir SYMBOLS_DIR
the symbols directory
--symbols-zip SYMBOLS_ZIP
the symbols.zip file from a build
-v, --verbose include function parameters
常用到的就是 --symbols-dir 指定symbols目录。
将以下trace保存为文件crash.txt。
07-10 14:43:05.333 5628 5628 F DEBUG : backtrace:
07-10 14:43:05.333 5628 5628 F DEBUG : #00 pc 0000000000054f50 /apex/com.android.runtime/lib64/bionic/libc.so (__strlen_aarch64+16) (BuildId: bed176195375c12bbf636f129939f1e0)
07-10 14:43:05.333 5628 5628 F DEBUG : #01 pc 0000000000087eec /apex/com.android.runtime/lib64/bionic/libc.so (__strcpy_chk+36) (BuildId: bed176195375c12bbf636f129939f1e0)
07-10 14:43:05.334 5628 5628 F DEBUG : #02 pc 00000000000a280c /system/lib64/libinputflinger.so (android::inputdispatcher::InputDispatcher::findTouchedWindowTargetsLocked(long, android::inputdispatcher::MotionEntry const&, bool*, android::os::InputEventInjectionResult&)+1456) (BuildId: 2fcc309ec38481b32c1e81dc0b7ecc64)
07-10 14:43:05.334 5628 5628 F DEBUG : #03 pc 000000000009cebc /system/lib64/libinputflinger.so (android::inputdispatcher::InputDispatcher::dispatchMotionLocked(long, std::__1::shared_ptr<android::inputdispatcher::MotionEntry>, android::inputdispatcher::InputDispatcher::DropReason*, long*)+280) (BuildId: 2fcc309ec38481b32c1e81dc0b7ecc64)
07-10 14:43:05.334 5628 5628 F DEBUG : #04 pc 0000000000099dcc /system/lib64/libinputflinger.so (android::inputdispatcher::InputDispatcher::dispatchOnceInnerLocked(long*)+2056) (BuildId: 2fcc309ec38481b32c1e81dc0b7ecc64)
07-10 14:43:05.334 5628 5628 F DEBUG : #05 pc 0000000000099098 /system/lib64/libinputflinger.so (android::inputdispatcher::InputDispatcher::dispatchOnce()+92) (BuildId: 2fcc309ec38481b32c1e81dc0b7ecc64)
07-10 14:43:05.334 5628 5628 F DEBUG : #06 pc 000000000000aed0 /system/lib64/libinputflinger_base.so (android::(anonymous namespace)::InputThreadImpl::threadLoop()+28) (BuildId: bd72f4f9ad9381770dd946bc3c6438bc)
07-10 14:43:05.334 5628 5628 F DEBUG : #07 pc 00000000000142f8 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+288) (BuildId: 2e18a478e616c2b0c1d5cd6c93f03877)
07-10 14:43:05.334 5628 5628 F DEBUG : #08 pc 00000000000ebcb0 /system/lib64/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+144) (BuildId: 8ade5e301ae1a90d6a5fd890c586f86b)
07-10 14:43:05.334 5628 5628 F DEBUG : #09 pc 00000000000c34f8 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+208) (BuildId: bed176195375c12bbf636f129939f1e0)
07-10 14:43:05.334 5628 5628 F DEBUG : #10 pc 000000000005ccb0 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+68) (BuildId: bed176195375c12bbf636f129939f1e0)
执行:./development/scripts/stack --symbols-dir out/target/product/qssi_64/symbols/ crash.txt
可以非常清晰的看见调用流程和文件行号,使用起来比addrline2方便很多。
Searching for native crashes in trace.log
Reading symbols from out/target/product/qssi_64/symbols/
Stack Trace:
RELADDR FUNCTION FILE:LINE
0000000000054f50 __strlen_aarch64+16 external/arm-optimized-routines/string/aarch64/strlen.S:84
0000000000087eec __strcpy_chk+36 bionic/libc/bionic/fortify.cpp:487
v--------------> strcpy bionic/libc/include/bits/fortify/string.h:99
v--------------> android::inputdispatcher::::uidToName frameworks/native/services/inputflinger/dispatcher/InputDispatcher.cpp:618
00000000000a280c android::inputdispatcher::InputDispatcher::findTouchedWindowTargetsLocked+1456 frameworks/native/services/inputflinger/dispatcher/InputDispatcher.cpp:2427 (discriminator 2)
000000000009cebc android::inputdispatcher::InputDispatcher::dispatchMotionLocked+280 frameworks/native/services/inputflinger/dispatcher/InputDispatcher.cpp:1949 (discriminator 2)
0000000000099dcc android::inputdispatcher::InputDispatcher::dispatchOnceInnerLocked+2056 frameworks/native/services/inputflinger/dispatcher/InputDispatcher.cpp:1132 (discriminator 2)
0000000000099098 android::inputdispatcher::InputDispatcher::dispatchOnce()+92 frameworks/native/services/inputflinger/dispatcher/InputDispatcher.cpp:842
v--------------> std::__1::__function::__value_func<void ()>::operator()() external/libcxx/include/functional:1799
v--------------> std::__1::function<void ()>::operator()() external/libcxx/include/functional:2347
000000000000aed0 android::::InputThreadImpl::threadLoop()+28 frameworks/native/services/inputflinger/InputThread.cpp:35
00000000000142f8 android::Thread::_threadLoop+288 system/core/libutils/Threads.cpp:0
00000000000ebcb0 android::AndroidRuntime::javaThreadShell+144 frameworks/base/core/jni/AndroidRuntime.cpp:1412
00000000000c34f8 __pthread_start+208 bionic/libc/bionic/pthread_create.cpp:382
000000000005ccb0 __start_thread+68 bionic/libc/bionic/clone.cpp:53