1.Addr2line 简介和安装
Addr2line 是一个用于将程序计数器(PC)地址转换为源代码文件名和行号的工具。它通常用于调试程序时查找特定地址对应的源代码位置。Addr2line 通常与调试符号文件(.debug文件)一起使用,以便能够正确地解析地址到源代码的映射关系。Addr2line 是 GNU binutils 工具集的一部分。
$yum install binutils
Last metadata expiration check: 1:28:21 ago on Sun 18 Feb 2024 10:00:14 AM CST.
Package binutils-2.34-18.oe1.aarch64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
2.Addr2line 使用
$addr2line -h
Usage: addr2line [option(s)] [addr(s)]
Convert addresses into line number/file name pairs.
If no addresses are specified on the command line, they will be read from stdin
The options are:
@<file> Read options from <file>
-a --addresses Show addresses
-b --target=<bfdname> Set the binary file format
-e --exe=<executable> Set the input file name (default is a.out)
-i --inlines Unwind inlined functions
-j --section=<name> Read section-relative offsets instead of addresses
-p --pretty-print Make the output easier to read for humans
-s --basenames Strip directory names
-f --functions Show function names
-C --demangle[=style] Demangle function names
-R --recurse-limit Enable a limit on recursion whilst demangling. [Default]
-r --no-recurse-limit Disable a limit on recursion whilst demangling
-h --help Display this information
-v --version Display the program's version
#code dump的内容如下所示:
Stack: [0x0000ffe9e4bb0000,0x0000ffe9e4db0000], sp=0x0000ffe9e4daa090, free space=2024k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [ld-linux-aarch64.so.1+0x1addc]
C [ld-linux-aarch64.so.1+0x6dfc]
C [ld-linux-aarch64.so.1+0x2120]
C [libc.so.6+0x12bda4] _dl_catch_exception+0x74
C [ld-linux-aarch64.so.1+0x2684]
C [ld-linux-aarch64.so.1+0xae18]
C [libc.so.6+0x12bda4] _dl_catch_exception+0x74
C [ld-linux-aarch64.so.1+0xa5e4]
C [libc.so.6+0x12bda4] _dl_catch_exception+0x74
C [ld-linux-aarch64.so.1+0xa9b8]
C [libc.so.6+0x7b344]
C [libc.so.6+0x12bda4] _dl_catch_exception+0x74
C [libc.so.6+0x12be70] _dl_catch_error+0x40
C [libc.so.6+0x7ae20]
C [libc.so.6+0x7b418] dlopen+0x88
V [libjvm.so+0x9fdf70] os::dll_load(char const*, char*, int)+0x50
V [libjvm.so+0x7c47b0] JVM_LoadLibrary+0x90
C [libjava.so+0x10850] Java_java_lang_ClassLoader_00024NativeLibrary_load+0x140
j java.lang.ClassLoader$NativeLibrary.load(Ljava/lang/String;Z)V+0
j java.lang.ClassLoader.loadLibrary0(Ljava/lang/Class;Ljava/io/File;)Z+328
j java.lang.ClassLoader.loadLibrary(Ljava/lang/Class;Ljava/lang/String;Z)V+48
j java.lang.Runtime.load0(Ljava/lang/Class;Ljava/lang/String;)V+57
j java.lang.System.load(Ljava/lang/String;)V+7
...省略
$addr2line -e /usr/lib64/libc.so.6 0x7b418 -f -a -C
0x000000000007b418
dlopen
:
【参考】
Linux调试工具 | Addr2line