linux 内核 addr2line,内核调试 arm-none-linux-gnueabi-addr2line 工具使用

通过OOPS信息中PC寄存器的值可以知道出错指令的地址,通过栈回朔信息可以知道出错时的函数调用的关系,根据这两点可以很快定位错误。

修改drivers/net/ethernet/davicom/dm9000.c,在dm9000_probe函数中u32 id_val;下增加下面语句:

int *ptr =NULL;

*ptr=0xff;

编译内核下载到开发板上,内核启动会出现如类似下信息:

Unable to handle kernel NULL pointer dereference at virtual address 00000000

pgd = c0004000

[00000000] *pgd=00000000

Internal error: Oops: 805 [#1] PREEMPT SMP ARM

Modules linked in:

CPU: 1 PID: 1 Comm: swapper/0 Not tainted 3.14.0 #11

task: ee8a0000 ti: ee8a4000 task.ti: ee8a4000

PC is at dm9000_probe+0x1c/0x8f0

LR is at platform_drv_probe+0x18/0x48

pc : [] lr : [] psr: 60000153

sp : ee8a5e48 ip : 00000000 fp : 00000000

r10: c052a4fc r9 : 00000000 r8 : c0591e98

r7 : 00000000 r6 : ee97c810 r5 : ee97c800 r4 : 00000000

r3 : 000000ff r2 : 00000000 r1 : ee8a5de8 r0 : ee97c800

Flags: nZCv IRQs on FIQs off Mode SVC_32 ISA ARM Segment kernel

Control: 10c5387d Table: 4000404a DAC: 00000015

Process swapper/0 (pid: 1, stack limit = 0xee8a4240)

Stack: (0xee8a5e48 to 0xee8a6000)

5e40: ee975cf0 00000000 ee1503a8 00000001 c0561afc ee150438

5e60: 00000000 ee97c810 c0591e98 ee97c810 00000000 c0591e98 c0561afc c052a4fc

5e80: 00000000 c0247f7c c0247f64 c05d931c c0591e98 c0246668 ee97c810 c0591e98

5ea0: ee97c844 00000000 c054332c c0246804 c0591e98 c0246778 00000000 c0244fbc

5ec0: ee805478 ee9771c0 c0591e98 eeb73a00 c0590028 c0245e28 c04c3128 c0591e98

5ee0: 00000000 c0591e98 00000000 c054e2ac c059f280 c0246e1c 00000000 ee8a4000

5f00: 00000000 c00087b4 ee903b00 c05c3d50 60000153 c0571c00 60000100 c0571c00

5f20: 00000000 00000000 c0571bfc 00000000 c0505bc8 ef7fc918 00000089 c0034c6c

5f40: c04ca680 c0505338 00000006 00000006 00000000 c054e2c8 c054e2cc 00000006

5f60: c054e2ac c059f280 00000089 c052a4fc 00000000 c052ac4c 00000006 00000006

5f80: c052a4fc c003e0dc 00000000 c03b46ec 00000000 00000000 00000000 00000000

5fa0: 00000000 c03b46f4 00000000 c000e4b8 00000000 00000000 00000000 00000000

5fc0: 0000000000000000 00000000 00000000 00000000 00000000 00000000 00000000

5fe0: 00000000 00000000 00000000 00000000 00000013 00000000 ffffffff ffffffff

[] (dm9000_probe) from [] (platform_drv_probe+0x18/0x48)

[] (platform_drv_probe) from [] (driver_probe_device+0x100/0x210)

[] (driver_probe_device) from [] (__driver_attach+0x8c/0x90)

[] (__driver_attach) from [] (bus_for_each_dev+0x58/0x88)

[] (bus_for_each_dev) from [] (bus_add_driver+0xd8/0x1cc)

[] (bus_add_driver) from [] (driver_register+0x78/0xf4)

[] (driver_register) from [] (do_one_initcall+0x30/0x144)

[] (do_one_initcall) from [] (kernel_init_freeable+0xfc/0x1c8)

[] (kernel_init_freeable) from [] (kernel_init+0x8/0xe4)

错误分析:

1、第一行,说明是空指针造成的错误

Unable to handle kernel NULL pointer dereference at virtual address 00000000

2、寄存器信息主要是PC的值

PC is at dm9000_probe+0x1c/0x8f0

pc : []

方法一、错误定位

arm-none-linux-gnueabi-objdump -D vmlinux > vmlinux.dis

文件vmlinux.dis非常大打开需要一定时间

ece0fa32db8587c1533030c72b013037.png

对于大多数情况,从反汇编代码定位到C代码并不会如此容易,需要有较强的阅读汇编代码的能力。

----------------------------------------------------------------------------------------------------------

方法二、错误定位

通过addr2line去定位

arm-none-linux-gnueabi-addr2line 0xc0277cc8-e vmlinux -f

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值