Using GCC to produce readable assembly?

后端 未结 10 2091
死守一世寂寞
死守一世寂寞 2020-11-22 06:13

I was wondering how to use GCC on my C source file to dump a mnemonic version of the machine code so I could see what my code was being compiled into. You can do this with J

10条回答
  •  爱一瞬间的悲伤
    2020-11-22 06:56

    You can use gdb for this like objdump.

    This excerpt is taken from http://sources.redhat.com/gdb/current/onlinedocs/gdb_9.html#SEC64


    Here is an example showing mixed source+assembly for Intel x86:

      (gdb) disas /m main
    Dump of assembler code for function main:
    5       {
    0x08048330 :    push   %ebp
    0x08048331 :    mov    %esp,%ebp
    0x08048333 :    sub    $0x8,%esp
    0x08048336 :    and    $0xfffffff0,%esp
    0x08048339 :    sub    $0x10,%esp
    
    6         printf ("Hello.\n");
    0x0804833c :   movl   $0x8048440,(%esp)
    0x08048343 :   call   0x8048284 
    
    7         return 0;
    8       }
    0x08048348 :   mov    $0x0,%eax
    0x0804834d :   leave
    0x0804834e :   ret
    
    End of assembler dump.
    

提交回复
热议问题