July 15, 2003

Know your compiler

Every once in a while it's really useful to find out exactly what the compiler's doing to your code.

gcc -g3 -fverbose-asm -Wa,-alh main.cpp > main.lst

The -fverbose-asm lists out all the compiler flags that are turned on and dumps out some additional information about how gcc was compiled (which can be useful in tracking down those "It works on system A but not on system B" bugs).

-g3 requests that additional debugging information be generated.

-Wa,<options> passes an argument to the assembler, thus -Wa,-alh asks the assembler to create a listing file with assembly and high level source.

> main.lst pipes stdout into main.lst

main.lst now contains an annotated assembler dump of your file that can help you figure out exactly what's going on with your code.

I don't spend all day reading assembler output (even if I were so inclined, I have these deadline things that prevent me from doing so), I usually use this when I'm concerned about the performance of certain calls that might wind up in high traffic inner loops (VarArgs based functions come to mind here) or when I want to track down the behavior of a bit of code that doesn't seem to be working in a rational fashion.

Posted by matt at July 15, 2003 12:24 PM
Comments