gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > How to see asm-code of compled cpp file?

#101492 - HotChilli - Tue Sep 05, 2006 10:42 pm

I have heard about parameters for GCC that permit to see asm-code of compiled cpp file. But what is the parameter? Or another way for see asm-code?

PS: This is nice for program optimization on cpp-coding-level. ;)

#101493 - sajiimori - Tue Sep 05, 2006 10:50 pm

The best way to see the compiler output for a module is to compile it with -S. That will produce an .s file instead of an .o file.

For disassembling an .o file, use objdump -d.

#101500 - gmiller - Wed Sep 06, 2006 12:13 am

If you use -save-temps you will get assembly output for each file and the compile will still happen. The -S will stop the compile before calling the assembler. But if you just want to look at the assembly output the -S will do the job.

#101501 - HotChilli - Wed Sep 06, 2006 12:47 am

Yeah - thanx, sajiimori and gmiller. That's work! :)

#101864 - PypeBros - Fri Sep 08, 2006 2:01 pm

sajiimori wrote:
The best way to see the compiler output for a module is to compile it with -S. That will produce an .s file instead of an .o file.

For disassembling an .o file, use objdump -d.


objdump -drS thefile.o is my favourite one. Mixing your C code with ASM output :P
_________________
SEDS: Sprite Edition on DS :: modplayer

#101887 - josath - Fri Sep 08, 2006 5:51 pm

that objdump command doesn't seem to work reliably with c++ code, the asm and code are both in the output, but it doesn't seem to be matched together: there will be a big block of source code, then a big block of asm

#101897 - sajiimori - Fri Sep 08, 2006 7:27 pm

Even with no optimization?

#101901 - josath - Fri Sep 08, 2006 7:45 pm

Here's the command that gets called during compilation:
Code:

arm-eabi-g++ -MMD -MP -MF arm9/build/main.d -g -Wall -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer -ffast-math -mthumb-interwork -Iarm9/include -Ilibnds/include -Ilibfat/nds/include -Iarm9/build -DARM9 -c arm9/source/main.cpp -o main.o
(paths truncated to make it cleaner)

Here's the output of "objdrump -drS main.o > dump.s": http://h.davr.org/dump.s

search for occurrances of 'loadSplash' (please excuse my poor coding habits :P ), and you will see there is no asm directly mixed with the code, but loadsplash occurs later in the ASM. same with the main function. however other functions have their asm mixed in fine.

This kind of output, if I can get it to work reliably could actually be quite useful -- until now, I haven't found a way that will mix the generated ASM along with the original

#101903 - sajiimori - Fri Sep 08, 2006 8:05 pm

I'm actually not sure what I'm looking at there. The macros and #ifdefs and commented-out code make it hard to tell if anything is actually going wrong.

#101974 - PypeBros - Sat Sep 09, 2006 10:05 am

josath wrote:
Here's the command that gets called during compilation:
search for occurrances of 'loadSplash' (please excuse my poor coding habits :P ), and you will see there is no asm directly mixed with the code, but loadsplash occurs later in the ASM. same with the main function. however other functions have their asm mixed in fine.


Hmm. surprising. i have to admit i mainly worked with C so far. Maybe asking for the corresponding line numbers would help ... or make sure the line numbers aren't stripped from the executable.
_________________
SEDS: Sprite Edition on DS :: modplayer

#101983 - gmiller - Sat Sep 09, 2006 2:27 pm

Sounds like you would want the debug information included in the code. Things will not match up to your code if you specify any optimizations other than '-O0' which will disable most optimization that the compiler would do after intermediate code generation. To include debug just add '-g' to the commad line to your compiler and you will get more information. Of course this does bloat the size of the generated code but if you goal is to "look" at it then this will accomplish what you want.