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

最低0.47元/天 解锁文章
2664

被折叠的 条评论
为什么被折叠?



