本文主要介绍addr2line
命令的用法。
一、命令介绍
addr2line
命令是GNU Binutils
工具集中的一种,其功能为:将指令的地址和可执行映像转换成文件名、函数名和源代码行数。
使用addr2line -h
查看该命令的使用方法,参数如下:
root@ubuntu:/home/run/code/rockchip-bsp/kernel# 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
addr2line: supported targets: elf64-x86-64 elf32-i386 elf32-iamcu elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big pe-x86-64 pe-bigobj-x86-64 pe-i386 plugin srec symbolsrec verilog tekhex binary ihex
Report bugs to <http://www.sourceware.org/bugzilla/>
二、使用方法
为了介绍addr2line
命令用法,基于RockPi 4A
单板Linux 4.4
内核,在DRM驱动中增加了一行代码(1876)。由于该行代码使用了空指针port
,在内核运行时,会出现空指针异常。
系统启动时,Linux
内核出现如下Panic
:
[ 2.292839] [drm] Initialized drm 1.1.0 20060810
[ 2.296731] [drm] Rockchip DRM driver version: v1.0.1
[ 2.297182] Unable to handle kernel NULL pointer dereference at virtual address 00000000
[ 2.297892] pgd = ffffff80094b7000
[ 2.298197] [00000000] *pgd=000000007fffe003, *pud=000000007fffe003, *pmd=0000000000000000
[ 2.298970] Internal error: Oops: 96000005 [#1] SMP
[ 2.299402] Modules linked in:
[ 2.299691] CPU: 5 PID: 1 Comm: swapper/0 Not tainted 4.4.154-00037-gdee50b698ce8-dirty #90
[ 2.300425] Hardware name: ROCK PI 4A 2 (DT)
[ 2.300801] task: ffffffc079698000 task.stack: ffffffc079694000
[ 2.301337] PC is at rockchip_drm_platform_probe+0x5c/0x2b0
[ 2.301829] LR is at rockchip_drm_platform_probe+0x48/0x2b0
[ 2.302319] pc : [<ffffff80086a1374>] lr : [<ffffff80086a1360>] pstate: 60000045
[ 2.302971] sp : ffffffc079697bb0
[ 2.303264] x29: ffffffc079697bb0 x28: ffffff800920f8f0
[ 2.303758] x27: 0000000000000007 x26: ffffff8009179288
[ 2.304251] x25: ffffff800900c000 x24: ffffff8008fc3000
[ 2.304743] x23: ffffffc07ffaf9e8 x22: ffffff8008fb3000
[ 2.305235] x21: ffffff80092fb7d0 x20: ffffffc078e90c10
[ 2.305727] x19: ffffffc078e90c10 x18: 0000000000000005
[ 2.306219] x17: 0000000000007fff x16: 0000000000000010
[ 2.306711] x15: 0000000000000000 x14: 000000000000000a
[ 2.307204] x13: ffffff80893f48db x12: 0000000000000030
[ 2.307695] x11: 0000000000000006 x10: ffffff80093f48e3
[ 2.308188] x9 : 0000000005f5e0ff x8 : 2e302e3176203a6e
[ 2.308681] x7 : 6f69737265762072 x6 : ffffff80093f4914
[ 2.309173] x5 : 00000000fffffffe x4 : ffffff8009245688
[ 2.309665] x3 : 0000004076d42000 x2 : 0000004076d42000
[ 2.310157] x1 : ffffff800925dc78 x0 : 0000000000000000
使用addr2line
命令定位空指针在代码中的位置,方法如下:
## 显示函数和代码行数
root@ubuntu:/home/run/code/rockchip-bsp/kernel# aarch64-linux-gnu-addr2line -fe vmlinux 0xffffff80086a1374
rockchip_drm_platform_probe
/home/run/code/rockchip-bsp/kernel/drivers/gpu/drm/rockchip/rockchip_drm_drv.c:1876
root@ubuntu:/home/run/code/rockchip-bsp/kernel#
## 省略路径名
root@ubuntu:/home/run/code/rockchip-bsp/kernel# aarch64-linux-gnu-addr2line -sfe vmlinux 0xffffff80086a1374
rockchip_drm_platform_probe
rockchip_drm_drv.c:1876
注:
1、使用编译单板内核映像的工具链命令(aarch64-linux-gnu-addr2line
)
2、0xffffff80086a1374对应的是PC
值。
网友评论