gcc build with -O0 results in corrupted -debuginfo package

Simo Sorce simo at redhat.com
Fri Apr 25 19:10:53 UTC 2014


On Fri, 2014-04-25 at 14:03 -0400, Adam Jackson wrote:
> On Fri, 2014-04-25 at 18:10 +0200, Kevin Kofler wrote:
> > Petr Spacek wrote:
> > > I'm going to reproduce and debug issue in named. Do you see any specific
> > > reason why I should use -O2 for serious debugging/development sessions?
> > 
> > IMHO, you should always debug with optimization enabled. GDB can cope quite 
> > well with it,
> 
> ha ha ha ha ha ha ha ha ha ha

Sorry I think you missed a few, I'll add my part.

HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA
HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA HA 


Kevin, have you ever debugged with -O2 ?

It's more than reasonable to want -O0.
At -O2 some code becomes really annoying to follow because gcc will
optimize away way too much of it into registers (and gdb will not print
you the values you need to see) or will make stepping a nightmare with
gdb jumping in an out of the function as it gets inlined and then some
stuff moved "out of the original function" and things like that.

I've been more than once in gdb with -O2, it is *not* pretty, nor
useful.

debug symbols at -O2 are mostly useful to get backtraces, but if you
need to really step through with gdb in some complicated, highly
optimizable code, often it does not cut it, you have to rebuild with -O0
to regain debuggability and sanity.

Simo.

-- 
Simo Sorce * Red Hat, Inc * New York



More information about the devel mailing list