objdump -d -l

Posted Li-Yongjun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了objdump -d -l相关的知识,希望对你有一定的参考价值。

前言

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

objdump -d -l

$ /home/liyongjun/project/board/buildroot/Vexpress_4.15/host/bin/arm-buildroot-linux-gnueabihf-objdump -d -l file.ko

file.ko:     file format elf32-littlearm


Disassembly of section .text.unlikely:

00000000 <hello_init>:
hello_init():
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:12
   0:   e92d40f0        push    r4, r5, r6, r7, lr
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:19
   4:   e3a04000        mov     r4, #0
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:17
   8:   e3000000        movw    r0, #0
   c:   e3400000        movt    r0, #0
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:12
  10:   e24dd00c        sub     sp, sp, #12
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:17
  14:   ebfffffe        bl      0 <printk>
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:19
  18:   e3a03064        mov     r3, #100        ; 0x64
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:21
  1c:   e3a02f69        mov     r2, #420        ; 0x1a4
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:19
  20:   e5843000        str     r3, [r4]
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:21
  24:   e3a01042        mov     r1, #66 ; 0x42
  28:   e3000000        movw    r0, #0
  2c:   e3400000        movt    r0, #0
  30:   ebfffffe        bl      0 <filp_open>
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:22
  34:   e3700a01        cmn     r0, #4096       ; 0x1000
  38:   9a000004        bls     50 <hello_init+0x50>
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:23
  3c:   e3000000        movw    r0, #0
  40:   e3400000        movt    r0, #0
  44:   ebfffffe        bl      0 <printk>
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:24
  48:   e3e00000        mvn     r0, #0
  4c:   ea000018        b       b4 <hello_init+0xb4>
  50:   e1a05000        mov     r5, r0
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:28
  54:   e1a0300d        mov     r3, sp
  58:   e3a02006        mov     r2, #6
  5c:   e3001000        movw    r1, #0
  60:   e3401000        movt    r1, #0
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:27
  64:   e3a06000        mov     r6, #0
  68:   e3a07000        mov     r7, #0
  6c:   e1cd60f0        strd    r6, [sp]
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:28
  70:   ebfffffe        bl      0 <kernel_write>
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:31
  74:   e3a02009        mov     r2, #9
  78:   e1a0300d        mov     r3, sp
  7c:   e1a00005        mov     r0, r5
  80:   e3001000        movw    r1, #0
  84:   e3401000        movt    r1, #0
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:30
  88:   e1cd60f0        strd    r6, [sp]
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:31
  8c:   ebfffffe        bl      0 <kernel_read>
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:32
  90:   e3001000        movw    r1, #0
  94:   e3401000        movt    r1, #0
  98:   e3000000        movw    r0, #0
  9c:   e3400000        movt    r0, #0
  a0:   ebfffffe        bl      0 <printk>
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:34
  a4:   e1a01004        mov     r1, r4
  a8:   e1a00005        mov     r0, r5
  ac:   ebfffffe        bl      0 <filp_close>
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:36
  b0:   e1a00004        mov     r0, r4
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:37
  b4:   e28dd00c        add     sp, sp, #12
  b8:   e8bd80f0        pop     r4, r5, r6, r7, pc

000000bc <cleanup_module>:
hello_exit():
/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:40
  bc:   e3000000        movw    r0, #0
  c0:   e3400000        movt    r0, #0
  c4:   eafffffe        b       0 <printk>

代码报错位置是在偏移 0x20 处

/home/liyongjun/project/board/buildroot/override/Vexpress_4.15/file/file.c:19
  20:   e5843000        str     r3, [r4]

从 objdump 显示信息可以看到,0x20 偏移处为 C 代码的第 19 行。

以上是关于objdump -d -l的主要内容,如果未能解决你的问题,请参考以下文章

objdump

在 kcachegrind 中使用不同的 objdump

readelf vs. objdump:为啥都需要

objdump

objdump命令

IBM AIX 中 objdump 的等效命令是啥