当前位置:网站首页>使用addr2line分析Native Crash
使用addr2line分析Native Crash
2022-06-09 21:55:00 【雪月清】
在Android NDK开发中,Native层的崩溃信息不像Java层的崩溃堆栈那样可以直接看到出现问题的函数名和行数
如上图所示的Native Crash例子,我们需要一些NDK提供的工具将函数地址解析为具体的函数名和行数才能进一步分析问题。
常用的地址转换工具有addr2line、ndk-stack等,个人比较喜欢addr2line,所以接下来介绍下该工具的基本使用方式
addr2line简介
使用-h参数查看工具的可选参数配置
日常使用过程中,只需要关注-C -f -e三个参数即可
// -C: Demangle函数名
// -f: 显示函数名
// -e: 带符号表的so路径这里展开说说-C这个参数,我们知道C/C++语言在编译以后,函数的名字会被编译器修改为编译器内部识别的名字,该名字在链接的时候被用到。将C++源代码转换为C++ ABI标识符的过程称为mangle,相反的过程称为demangle
以Linux下的g++为例,每个方法都以_Z开头,比如_Z3foov就是函数foo(),v表示参数类型为void。从foo()转换为_Z3foov的过程被称为mangle,_Z3foov转换为foo()的过程被称为demangle。
其中NDK中的aarch64-linux-android-c++fil(和addr2line同一个目录)是专门用来支持Demangle的
addr2line使用示例
新建一个带C++的Android Studio工程,主动创造一个native crash
启动app后如预期崩溃
抓到崩溃信息后,根据ABI找到相对应的addr2line工具和带符号表的so文件。
我们主要关注backtrace后面的信息,同时带"pc"和"/data"的行基本就是app相关的崩溃行了
除了最后一个是被strip了符号的so,前三个so文件都是可以的
终端中使用addr2line转换地址
aarch64-linux-android-addr2lin -C -f -e ${SO_PATH} ${Address} ${Address} ...解析结果
定位到具体的函数名和行数后就可以进一步排查问题了
Crash堆栈解析脚本
日常工作或者学习中还是使用一个python脚本来解析带crash堆栈的文件比较方便
#!/usr/bin/python
import sys
import re
import os
ADDR2LINE_PATH ='your tool abs path'
if len(sys.argv) >= 3:
SO_PATH = sys.argv[1]
FILE_PATH = sys.argv[2]
CMD_BASE = ADDR2LINE_PATH + ' -C -f -e ' + SO_PATH + ' '
with open(FILE_PATH, 'r') as f:
for line in f:
crash = re.search('#[0-9]+ +pc +([0-9A-Fa-f]+) +/data', line)
if crash is not None:
addr = crash.groups(1)[0]
cmd = CMD_BASE + addr
res = os.popen(cmd).read()
print(res)使用效果
~~END~~
边栏推荐
- The little schemer Chinese version
- Learn how to parse SQL from kernel code
- Wenxin Ernie 3.0 blessing! Small samples can also achieve 99% effect of full data!
- Erc20 protocol API interface specification
- 第四范式陈雨强:企业智能决策的下一代技术「强化学习 + 环境学习」
- 【图像重建】基于正则化的图像超分辨重建附matlab代码
- Pi of C language test question 162
- Oracle paging
- Digital integrated management system of double prevention system in chemical enterprises
- ERC20协议API接口规范
猜你喜欢

Intelligent prevention and control of safety production risk at construction site in flood season

Digital integrated management system of double prevention system in chemical enterprises

【图像重建】基于正则化的图像超分辨重建附matlab代码

Digital supervision of construction sites and the wisdom of scientific warfare

Cookies and session workflows

C语言试题164之求定积分

10个常见触发IO瓶颈的高频业务场景

2022年最系统的自动化测试,测试开发面试题,10k以下不建议看

2022 safety production month activity starts safety production and epidemic prevention and control

St link V2 Download: internal command error & error: flash download failed - target DLL has been canceled
随机推荐
Wenxin Ernie 3.0 blessing! Small samples can also achieve 99% effect of full data!
函数对象(仿函数)
Unity code binding button function
MySQL的集合运算
邦纳光电开关SM912LVQD
Aquanee will land in gate and bitmart in the near future, providing a good opportunity for low-level layout
The Little Schemer 中文版
第四范式陈雨强:企业智能决策的下一代技术「强化学习 + 环境学习」
2022 safety production month activity starts safety production and epidemic prevention and control
C语言试题168之获取矩阵的最大值及其下标
sparksql源码系列 | 一文搞懂Show create table 执行原理
【图像分割】基于各向异性热扩散方程的图像分割附matlab代码
ffmpeg加opencv的人脸采集并做出识别的实战项目!
【轴承故障分解】基于 ITD实现轴承故障信号分解含Matlab源码
TL,你是如何管理项目风险的?
中金证券开户怎么样?安全吗?开户
化工企业双重预防体系数字化综合管理系统
【翻译论文】A Progressive Morphological Filter for Removing Nonground Measurements From Airborne LIDAR Dat
Digital engineering construction enterprises carry out "safety production month" activities in this way
Collection operation of MySQL