After compiling a C program, you get a .o file. I know it's a file consisting of '0's and '1's and if formed after successful compilation of a program. But I want to see what is in the file!
you've got a couple of choices here.
Firstly (and easiest) is to use something that decodes the file to show you what it is. objdump on linux does this.
gcc -c test.c
gives you test.o
objdump -D test.o
will decode the file and show you what's in it on standard output (so pipe it to less or similar)
Objdump output shows you the unlinked object file. The addresses aren't valid and have to be fixed up by the linker.
the format is
first a line number
then some number of bytes that are the cpu instruction, these are shown in hexadecimal.eg 14 means 00010100
next comes the instruction that these byes represent
0: 14 00 adc $0x0,%al
so above we have line 0 of the function - it's unlinked) 14 00 - these are the bytes they mean add with carry 0 to the al register storing the result in al
Another alternative is to use a hex editor and try and work out what 14 00 means without any assistance.
Good luck.
You can use hexdump
command from the terminal to display the content.
Syntax : $ hexdump <filename>.o
It will show you the content in hexadecimal
form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With