通过addr2line/GDB确定ko模块中的代码偏移

假设我们crash的bt如下:

[    9.690017] i2c_designware 20002000.i2c: controller timed out
[    9.856415] CPU: 7 PID: 372 Comm: NetworkManager Tainted: G      D W         5.10.59+2.0.0 #41
[    9.856418] Hardware name: BST A1000B FAD-A (DT)
[    9.856422] Call trace:
[    9.856435]  dump_backtrace+0x0/0x1d0
[    9.856439]  show_stack+0x18/0x28
[    9.856446]  dump_stack_lvl+0xd0/0xf8
[    9.856449]  dump_stack+0x18/0x38
[    9.856456]  mrdump_common_die+0x88/0x90
[    9.856459]  ipanic+0xa8/0xd0
[    9.856466]  atomic_notifier_call_chain+0x58/0x88
[    9.856471]  panic+0x174/0x304
[    9.856475]  die+0x25c/0x2a8
[    9.856481]  die_kernel_fault+0x64/0x78
[    9.856485]  __do_kernel_fault+0x90/0x188
[    9.856491]  do_page_fault+0x1a0/0x468
[    9.856495]  do_translation_fault+0x60/0x70
[    9.856498]  do_mem_abort+0x40/0xb0
[    9.856503]  el1_abort+0x44/0x68
[    9.856507]  el1_sync_handler+0xac/0xc8
[    9.856510]  el1_sync+0x88/0x140
[    9.856517]  skb_queue_tail+0x64/0xc0
[    9.856576]  bstgmac_open+0x960/0x11c8 [bstmac]
[    9.856584]  __dev_open+0x124/0x1b8
[    9.856588]  __dev_change_flags+0x16c/0x1c8
[    9.856592]  dev_change_flags+0x24/0x68
[    9.856598]  do_setlink+0x650/0xdb0
[    9.856602]  __rtnl_newlink+0x3fc/0x780
[    9.856606]  rtnl_newlink+0x4c/0x78
[    9.856611]  rtnetlink_rcv_msg+0x11c/0x330
[    9.856616]  netlink_rcv_skb+0x58/0x120
[    9.856620]  rtnetlink_rcv+0x18/0x28
[    9.856623]  netlink_unicast+0x1ac/0x250
[    9.856627]  netlink_sendmsg+0x1bc/0x3c0
[    9.856632]  sock_sendmsg+0x4c/0x58
[    9.856635]  ____sys_sendmsg+0x264/0x2a0
[    9.856639]  ___sys_sendmsg+0x80/0xc8
[    9.856642]  __sys_sendmsg+0x68/0xc8
[    9.856646]  __arm64_sys_sendmsg+0x24/0x30
[    9.856651]  el0_svc_common.constprop.0+0x60/0x140
[    9.856655]  do_el0_svc+0x70/0x90
[    9.856658]  el0_svc+0x14/0x20
[    9.856662]  el0_sync_handler+0xb0/0xb8
[    9.856665]  el0_sync+0x1a0/0x1c0
[    9.879659] mrdump: cpu[7] tsk:000000001c634f6c ti:000000001c634f6c

通常我们可以通过gdb + vmlinux来定位crash时候的代码的位置:

这个时候如果代码是built-in 那么可以看到具体的代码位置,但是当crash的位置在ko中时,则需要通过别的方式来确定crash的代码的位置

这里我试了2个方法来确定位置:

1.通过addr2line

aarch64-linux-gnu-addr2line -e bstmac.ko -f -C -i 0x960

2,通过gdb的方式

获取ko加载的地址位置:

具体文件在:/sys/module/bstmac/sections/.text中

在gdb中加载ko文件:

(gdb) add-symbol-file /bst/a1000b/a1000b_build/kernel-HEAD_eb4045b58/build/drivers/net/ethernet/bst/dwmac/bstmac.ko 0xffff800008b31000

此时再使用list 就可以列出来代码了:

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from build/vmlinux...done.
(gdb) 
(gdb) 
(gdb) add-symbol-file /ssd2_ext4/bst/a1000b/a1000b_build/kernel-HEAD_eb4045b58/build/drivers/net/ethernet/bst/dwmac/bstmac.ko 0xffff800008b31000
add symbol table from file "/ssd2_ext4/bst/a1000b/a1000b_build/kernel-HEAD_eb4045b58/build/drivers/net/ethernet/bst/dwmac/bstmac.ko" at
	.text_addr = 0xffff800008b31000
(y or n) y
BFD: warning: /ssd2_ext4/bst/a1000b/a1000b_build/kernel-HEAD_eb4045b58/build/drivers/net/ethernet/bst/dwmac/bstmac.ko: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0000000
Reading symbols from /ssd2_ext4/bst/a1000b/a1000b_build/kernel-HEAD_eb4045b58/build/drivers/net/ethernet/bst/dwmac/bstmac.ko...done.
(gdb) list*(bstgmac_open+0x960)
0xffff800008b3bed8 is in bstgmac_open (../drivers/net/ethernet/bst/dwmac/dwmac_main.c:3042).
3037			return;
3038	
3039		for (chan = 0; chan < BSTGMAC_RXCHAN_NUM; chan++) {
3040			index = busid * BSTGMAC_RXCHAN_NUM + chan;
3041			list = &gmac_delivery_skblist[index];
3042			for (i = 0; i < BSTGMAC_RXMEM_MAX; i++) {
3043				skb = netdev_alloc_skb_ip_align(priv->dev, size);
3044				if (unlikely(!skb))
3045					break;
3046	
(gdb)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值