Thread: using -ggdb3 and -O3 simultaneously for gcc

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    159

    using -ggdb3 and -O3 simultaneously for gcc

    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!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    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?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    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).

Popular pages Recent additions subscribe to a feed