gdb 定位代码位置

前言

接上篇《addr2line》,本篇文章使用 gdb 来定位出错代码位置。

disassemble /m func_name

(gdb) file file.ko 
Reading symbols from file.ko...
(gdb) disassemble /m hello_init
Dump of assembler code for function hello_init:
12      {
   0x00000024 <+0>:     push    {r4, r5, r6, r7, lr}
   0x00000034 <+16>:    sub     sp, sp, #12

13              struct file *filp;

14              loff_t pos;

15              int *a = NULL;

16
17              printk("hello enter\n");
   0x0000002c <+8>:     movw    r0, #0
   0x00000030 <+12>:    movt    r0, #0
   0x00000038 <+20>:    bl      0x38 <hello_init+20>

18
19              *a = 100;
   0x00000028 <+4>:     mov     r4, #0
   0x0000003c <+24>:    mov     r3, #100        ; 0x64
   0x00000044 <+32>:    str     r3, [r4]

20
21              filp = filp_open(FILENAME, O_RDWR | O_CREAT, 0644);
   0x00000040 <+28>:    mov     r2, #420        ; 0x1a4
   0x00000048 <+36>:    mov     r1, #66 ; 0x42
   0x0000004c <+40>:    movw    r0, #0
   0x00000050 <+44>:    movt    r0, #0
   0x00000054 <+48>:    bl      0x54 <hello_init+48>

22              if (IS_ERR(filp)) {
23                      printk("create file error\n");

0x20 = 32,+32 对应第 19 行代码。

19              *a = 100;
   0x00000028 <+4>:     mov     r4, #0
   0x0000003c <+24>:    mov     r3, #100        ; 0x64
   0x00000044 <+32>:    str     r3, [r4]

打断点

(gdb) b *hello_init+0x20
Breakpoint 1 at 0x44: file /home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c, line 19.

瞬间定位到 file.c, line 19.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Li-Yongjun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值