Android Native crash tomestone trace转换工具stack介绍

Android 版本中自带Native trace 工具,可以批量转换tomestone。

工具路径:android/development/scripts/stack

执行stack -h,可以看到帮助信息

stack -h

  usage: /LINUX/android/development/scripts/stack [options] [FILE]

  --arch=arm|arm64|mips|mips64|x86|x86_64
       the target architecture

  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

提示我们传递标准FILE可以转换stack trace为源文件和行号。

查阅stack代码,是由python编写,核心是调用到了stack_core.ConvertTrace,在stack_core.py文件中,有兴趣和能力的可以看下具体实现。

下面以例子展示使用方法,将以下trace保存为文件aaa

13:52:09.289  3186  3186 F DEBUG   : 
13:52:09.289  3186  3186 F DEBUG   : backtrace:
13:52:09.289  3186  3186 F DEBUG   :     #00 pc 000000000001db9c  /system/lib64/libc.so (abort+112)
13:52:09.289  3186  3186 F DEBUG   :     #01 pc 0000000000020b20  /system/lib64/libc.so (__fortify_fatal(char const*, ...)+136)
13:52:09.289  3186  3186 F DEBUG   :     #02 pc 00000000000217e8  /system/lib64/libc.so (__vsprintf_chk+152)
13:52:09.289  3186  3186 F DEBUG   :     #03 pc 000000000002af60  /system/lib64/libfotmanager.so (_ZL7sprintfPcU17pass_object_size1PKcz+140)
13:52:09.289  3186  3186 F DEBUG   :     #04 pc 000000000002b6a8  /system/lib64/libfotmanager.so (FOT_Manager_Thread::fot_manager_main_thread(void*)+1556)
13:52:09.289  3186  3186 F DEBUG   :     #05 pc 0000000000069e28  /system/lib64/libc.so (__pthread_start(void*)+36)

执行stack aaa,就会打印转换结果

Searching for native crashes in abc
Reading symbols from android/out/target/product/***/symbols
Using arm64 toolchain from: android/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/

Stack Trace:
  RELADDR           FUNCTION                                                                       FILE:LINE
  000000000001db9c  abort+112                                                                      bionic/libc/bionic/abort.cpp:74
  0000000000020b20  __fortify_fatal(char const*, ...)+136                                          bionic/libc/private/bionic_fortify.h:41
  v-------------->  __check_buffer_access(char const*, char const*, unsigned long, unsigned long)  bionic/libc/private/bionic_fortify.h:77
  00000000000217e8  __vsprintf_chk+152                                                             bionic/libc/bionic/fortify.cpp:442
  000000000002af60  sprintf(char*, char const* pass_object_size1, ...)+144                         bionic/libc/include/stdio.h:322
  000000000002b6a8  FOT_Manager_Thread::fot_manager_main_thread(void*)+1548                        hardware/interfaces/fotmanager/src/fot_manager_main_thread.cc:769
  0000000000069e28  __pthread_start(void*)+36                                                      bionic/libc/bionic/pthread_create.cpp:226

可以非常清晰的看见调用流程和文件行号,使用起来比addrline2或者ndk-stack方便很多。

你可能感兴趣的:(调试,android,c++)