I think what you want is a function of gdb, the gnu debugger, which has a disassemble command. First, you would compile test.c with debugging flags on, like this:
gcc -Wall -g -o test test.c
or something along those lines. Then, you would run the application with gdb as an argument:
gdb test
once you are in gdb, you can use the disassemble command like this:
(gdb) break main
(gdb) disassemble main
Take this trivial program named test.cpp:
#include <iostream>
using namespace std;
int main ()
{
int a=0;
for (int b = 0; b < 11; b++){
a=b+2;
cout << a << "\n\t";
}
cout << "Hello World \n";
return 0;
}
now I will compile it, with debug flags:
g++ -Wall -g test.cpp -o test
Then you say, but j0h, this is a C question... to which I say, gdb doesn't care what language you use. you can debug and disassemble c, c++, assembly, fortran, and a variety of other things, just compile with the -g option, thats what is important.
once we load the program into gdb, and break main, we cam run disassemble:
Breakpoint 1 at 0x4007da
(gdb) disassemble main
Dump of assembler code for function main:
0x00000000004007d6 <+0>: push %rbp
0x00000000004007d7 <+1>: mov %rsp,%rbp
0x00000000004007da <+4>: sub $0x10,%rsp
0x00000000004007de <+8>: movl $0x0,-0x4(%rbp)
0x00000000004007e5 <+15>: movl $0x0,-0x8(%rbp)
0x00000000004007ec <+22>: jmp 0x400817 <main+65>
0x00000000004007ee <+24>: mov -0x8(%rbp),%eax
0x00000000004007f1 <+27>: add $0x2,%eax
0x00000000004007f4 <+30>: mov %eax,-0x4(%rbp)
0x00000000004007f7 <+33>: mov -0x4(%rbp),%eax
0x00000000004007fa <+36>: mov %eax,%esi
0x00000000004007fc <+38>: mov $0x601080,%edi
0x0000000000400801 <+43>: callq 0x400670 <_ZNSolsEi@plt>
0x0000000000400806 <+48>: mov $0x400914,%esi
0x000000000040080b <+53>: mov %rax,%rdi
---Type <return> to continue, or q <return> to quit---
Here is a tutorial:
http://www.unknownroad.com/rtfm/gdbtut/gdbadvanced.html
objdump can list the contents, but I don’t think you’ll be able to interact with your code the same way as if you use the debugger.