Hi,
I was wondering what is the purpose of using -ggdb3 and -O3 simultaneously for gcc? One is for debug and the other is for optimization. Is this to debug the optimized code? Can anyone point me to some reference explaining this well? Thanks!
Printable View
Hi,
I was wondering what is the purpose of using -ggdb3 and -O3 simultaneously for gcc? One is for debug and the other is for optimization. Is this to debug the optimized code? Can anyone point me to some reference explaining this well? Thanks!
> Is this to debug the optimized code?
But only if you're crazy or desperate.
With -O0, the code does what you said on a line by line basis. Step to next line does what it says, and all the variables you have are correct.
-O3
- dead code has gone
- variables which are entirely in registers are gone
- constant code and common sub-expressions get moved around
- etc etc
All of which make debugging a wild ride.
It beats single-stepping the assembler, but you need your wits about you to separate optimiser induced hallucinations from the real bugs.
It's just one of those things you have to experience really ;)
Pick some fairly simple and familiar code and give it a go.
Actually I got this "-ggdb3 -O3" from a Makefile written by an experienced programmer. That's why it so confuses me. As I always use -ggdb3 to debug and then -O3 to generate release, what could "-ggdb3 -O3" be possibly for?
Aside from making the binary a tad bigger, it doesn't hurt. It makes post-mortem debugging possible on a production build I guess (the program crashes with a memory dump, and the user can send the memory dump back to the developer for analysis).