将源代码映射到目标文件

时间:2014-01-10 15:13:38

标签: c objdump

我想知道如何在源文件和目标文件之间完成此映射

void main()
{
     printf("Hello world !!\n");
}

使用目标文件:

Disassembly of section .text:

00000000 <main>:

   0:   55                      push   %ebp

   1:   89 e5                   mov    %esp,%ebp

   3:   83 e4 f0                and    $0xfffffff0,%esp

   6:   83 ec 10                sub    $0x10,%esp

   9:   b8 00 00 00 00          mov    $0x0,%eax

   e:   89 04 24                mov    %eax,(%esp)

  11:   e8 fc ff ff ff          call   12 <main+0x12>

  16:   b8 00 00 00 00          mov    $0x0,%eax

  1b:   c9                      leave  

  1c:   c3                      ret  

2 个答案:

答案 0 :(得分:1)

objdump -d ./a.out --source --line-numbers

像魅力一样!

000000000040052c <main>:
main():
/home/stdcall/temp/test.c:2
void main()
{
  40052c:   55                      push   %rbp
  40052d:   48 89 e5                mov    %rsp,%rbp
/home/stdcall/temp/test.c:3
     printf("Hello world !!\n");
  400530:   bf e4 05 40 00          mov    $0x4005e4,%edi
  400535:   e8 d6 fe ff ff          callq  400410 <puts@plt>
/home/stdcall/temp/test.c:4
}
  40053a:   5d                      pop    %rbp
  40053b:   c3                      retq   
  40053c:   0f 1f 40 00             nopl   0x0(%rax)

答案 1 :(得分:0)

尝试使用gcc hello.c -g -o hello

进行编译

选项。然后做ojbdump -S你好|少