1

Saying that I have an executable binary file, which comes from the compilation of some C code and its name is a.out.

As we know, we can disassemble it with the command objdump -d a.out. Here is an example:

00000000004006b6 <main>:
  4006b6:       55                      push   %rbp
  4006b7:       48 89 e5                mov    %rsp,%rbp
  4006ba:       89 7d ec                mov    %edi,-0x14(%rbp)
  4006bd:       48 89 75 e0             mov    %rsi,-0x20(%rbp)
  4006c1:       c7 45 f4 01 00 00 00    movl   $0x1,-0xc(%rbp)
  4006c8:       c7 45 f8 02 00 00 00    movl   $0x2,-0x8(%rbp)
  4006cf:       8b 55 f4                mov    -0xc(%rbp),%edx
  4006d2:       8b 45 f8                mov    -0x8(%rbp),%eax
  4006d5:       01 d0                   add    %edx,%eax
  4006d7:       89 45 fc                mov    %eax,-0x4(%rbp)
  ...
  ...

Now I want to know if we can list the C code corresponding to the disassembly, meaning that something as below:

4006c1:       c7 45 f4 01 00 00 00    movl   $0x1,-0xc(%rbp)  // int i = 1;
4006c8:       c7 45 f8 02 00 00 00    movl   $0x2,-0x8(%rbp)  // int j = 2;

In a word, I know that movl $0x2,-0x8(%rbp) is to assign the integer 2 to a variable, but as you see this is not very clear, I'm thinking if there are some way to translate movl $0x2,-0x8(%rbp) into int j = 2 automatically and immediately, it would be very helpful.

Yves
  • 11,597
  • 17
  • 83
  • 180
  • 1
    `objdump -dS` interleaves disassembly with source lines. In un-optimized code it's pretty straightforward. – Peter Cordes Jan 20 '20 at 10:20
  • @PeterCordes yea.... this is what I need. lol – Yves Jan 20 '20 at 10:21
  • Note if you optimize then there isnt a one to chunk relationship between the compiled language and assembly, its whatever the compiler comes up with. In general there isnt an expectation to have a one line of C to asm blob, so it can be more confusing than useful. – old_timer Jan 20 '20 at 19:58

0 Answers0