全部博文(685)
分类: LINUX
2014-09-05 10:42:38
本文介绍一些平时查找内核报栈时用的到的小技巧
1、 使用gdb 取得结构体中某一字段的偏移量
命令: p ((struct xxx *)0)->xxx
例:
>> gdb vmlinux
(gdb) p ((struct sk_buff*)0)->data
Cannot access memory at address 0xb4
2、 使用gdb 进行四则运算
p x+y
p x-y
p x*y
p x/y
p/x 已十六进行显示
例:
>>gdb vmlinux
(gdb) p/x 10 + 0xb
$3 = 0x15
3、 gdb 查看报栈代码位置:
l * code/sit
例:
[ 89.718952] BUG: unable to handle kernel NULL pointer dereference at 0000000c
[ 89.719129] IP: [
>> gdb network-unstrip.ko
(gdb) l* vlan_get_frame_type+0xa
0xedf5f is in vlan_get_frame_type (/xxx/network/net/bridge/br_vlan.c:45).
40
41 br_frame_t
42 vlan_get_frame_type (struct sk_buff *skb)
43 {
44 br_frame_t frame_type;
45 if (ntohs(eth_hdr(skb)->h_proto) == ETH_P_8021Q)
46 {
47 frame_type = (br_vlan_get_vid_from_frame (skb) == VLAN_NULL_VID) ?
48 PRIORITY_TAGGED : TAGGED;
49 }
objdump –dSL vlan_dev.o
5、 使用kdb 查看内存:
md $addree
例:
[1]kdb> md c5082f00
0xc5082f00 00000000 00000000 00000000 00000000 ................
0xc5082f10-0xc5082f6f zero suppressed
0xc5082f70 00000000 00000000 00000000 00000000 ................