Android上使用tombstone定位问题的示例

菜谱

1)tombstone文件
2)对应的带symbol的可执行文件或者库文件
3)stack脚本

生成tombstone文件

如果恰好手头上没有现成的tombstone文件,可以手动创建一个。
1)在native代码中写一个空指针错误,直接崩掉就会生成tombstone文件。
2)对已有的进程发送一个signal 11(SIGSEGV)
3)tombstone文件保存在/data/tombstones/目录下。

例如:可以给system_server发一个信号,为它生成一个tombstone纪念一下。
鉴于system_server的重要性和复杂性,他的tombstone内容很丰富…
找个简单点的native程序,生成的tombstone也会简单一些。


symbol文件

在AOSP源码中,对应的目录在:

	out/target/product/${prod_name}/symbols/

${prod_name}根据你的工程信息填写。

stack脚本

stack是一个python脚本,在AOSP源码和Android NDK中都可以找到。
在AOSP中的位置:

	prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/
# stack 脚本的用法
$ stack -h
usage: stack [-h] [--arch ARCH] [--syms SYMS] [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
  --syms SYMS, --symdir SYMS
                        the symbols directory

解析tombstone文件

把symbol文件目录和对应的tombstone文件传给stack脚本,就会帮着解析出错误对应的方法名称。

$ stack --syms ${aosp_dir}/out/target/product/${prod_name}/symbols/ ~/temp/tombstones/tombstone_25
Searching for native crashes in /home/user/temp/tombstones/tombstone_25
Reading symbols from symbols/
Revision: '0'
pid: 19272, tid: 19272, name: logcat  >>> logcat <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8
    x0  000000563dd67f1d  x1  0000007ffc1de546  x2  0000007ffc1db608  x3  0000000000000030
    x4  0000000000000010  x5  b4000077403c0061  x6  2d20315b203a3231  x7  5d3237323931203e
    x8  0000000000000000  x9  0000000000000070  x10 6d75642065726f63  x11 0000000000000008
    x12 0000000000000000  x13 0a2e64656c6c6163  x14 0000007860504d22  x15 00000000fffffffe
    x16 0000007860501d80  x17 0000007861a92934  x18 00000078618b6000  x19 0000007ffc1dd990
    x20 0000007861b547f0  x21 0000007ffc1de546  x22 0000000000000054  x23 b4000076103b41c0
    x24 0000007ffc1dbee0  x25 00000078608fb000  x26 0000000000000000  x27 b4000076103b48b0
    x28 0000007ffc1dc4f0  x29 0000007ffc1dbe40
  sp  0000007ffc1db990  pc  000000563dd6edfc
Using arm64 toolchain from: /home/user/code/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/

Stack Trace:
  RELADDR           FUNCTION                             FILE:LINE
  v-------------->  getLastLine(char const*)             system/core/logcat/logcat.cpp:270
  v-------------->  getLastLogTimeString(char const*)    system/core/logcat/logcat.cpp:306
  000000000000edfc  Logcat::RotateLogs2()+192            system/core/logcat/logcat.cpp:497
  000000000000fd74  Logcat::ProcessBuffer(log_msg*)+628  system/core/logcat/logcat.cpp:637
  0000000000012d34  Logcat::Run(int, char**)+11676       system/core/logcat/logcat.cpp:1600
  00000000000134a4  main+268                             system/core/logcat/logcat.cpp:1647
  00000000000499fc  __libc_init+108                      bionic/libc/bionic/libc_init_dynamic.cpp:151

手动查看tombstone文件

有文本编辑器(vi、vs code)等直接打开tombstone文件,也可以看到很多基本的有用信息,对于自己编写的代码,很多时候打开一看就能帮助定位到问题原因。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

抓饼先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值