native调用栈分析

1.  addr2line命令

addr2line -h 可以查看命令使用帮助:

一般命令使用方式:addr2line -e 可执行程序文件 -f -C  address

比如下面一个调用栈打印:

01-01 08:00:08.030  2981  2981 D surfaceflinger start: #00 pc 00002875  /system/bin/surfaceflinger (main+636)
01-01 08:00:08.030  2981  2981 D surfaceflinger start: #01 pc 00088161  /system/lib/libc.so (__libc_init+48)
01-01 08:00:08.030  2981  2981 D surfaceflinger start: #02 pc 000025b7  /system/bin/surfaceflinger (_start_main+38)
01-01 08:00:08.030  2981  2981 D surfaceflinger start: #03 pc 00000306  <anonymous:f266e000> 

这是在surfaceflinger模块的启动入口:main_surfaceflinger.cpp的main方法中打印的,我们可以用addr2line命令看下第3行和第2行对应的代码行, 第3行的system/bin/surfaceflinger是一个可执行程序, 第2行的system/lib/libc.so是一个so库, Android系统源码编译后生成的带调试符号的可执行程序文件或so文件都在out/target/product/xxx/symbols目录下,为了防止addr2line命令参数过长,我们可以先进入该目录下。

第3行的地址是0x000025b7, 命令执行结果如下:

 第2行的地址是0x00088161, 命令执行结果如下:

我们可以分别看下这2个执行结果所对应的代码:

bionic/libc/arch-common/bionic/crtbegin.c

 39 __used static void _start_main(void* raw_args) {
 40   structors_array_t array;
 41   array.preinit_array = &__PREINIT_ARRAY__;
 42   array.init_array = &__INIT_ARRAY__;
 43   array.fini_array = &__FINI_ARRAY__;
 44 
 45   __libc_init(raw_args, NULL, &main, &array);
 46 }

bionic/libc/bionic/libc_init_dynamic.cpp

104 // This function is called from the executable's _start entry point
105 // (see arch-$ARCH/bionic/crtbegin_dynamic.S), which is itself
106 // called by the dynamic linker after it has loaded all shared
107 // libraries the executable depends on.
108 //
109 // Note that the dynamic linker has also run all constructors in the
110
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值