This is the mail archive of the gdb@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Should GCC tell GDB about its optimizations?


Hi!

Stan Shebs wrote:
> I'm sure this subject has come up before, but I don't remember any
> consensus...
> 
> In the process of finishing Mac OS X, Apple has hundreds of engineers
> beating on GCC and GDB every day.  The system has literally hundreds
> of subcomponents; everything from the kernel to speech output to Hebrew
> font support (sort of like a Linux system preloaded with everything
> you can find on freshmeat :-) ).  By default, everything is built with
> optimization turned on.  While an engineer can turn off optimization
> for a specific bit of code, it's not practical to build an entire system
> with optimization turned off.  So in practice any single program consists
> of a combination of optimized and unoptimized code.
> 

We have some similar problem at Sun with ChorusOS. However, I've never
seen that mixing optimized/non optimized code was really the problem.
It was rather related to mixing debugging/non debugging code. May
be that's also the problem you are facing with (ie, compile some parts
with -g, some others without).

My understanding is that this makes debugging wrong because GDB 
is not able to find out what registers are saved in functions not compiled
with -g. I don't think this is related to optimization (also see
"Timothy J. Wood" <tjw@omnigroup.com> e-mail).


There is a notion of level of debugging info in GCC. I think it was
intended to emit only the minimal debugging info (such as frame layout
or things like that). In this case, the complete system should be built
with such minimal debugging info (frame layout). Some specific files
could be compiled with -g (full debug). 

This makes sense also for any library in general that you link with
(libc, ...). If such library is not compiled with -g, you cannot get
valid access to your local variables when you stop in some system call.
Now, if your function is compiled without optimization, gcc will not
allocate your local variables in registers, and GDB should be able
to give you good values for local variables.

This is my understanding of debugging with DWARF-2.

Anyway, it makes sense to know whether some files are compiled with
optimization or not.

	Stephane

-----------------------------------------------------------------------
         Home                               Office
E-mail: stcarrez@worldnet.fr               Stephane.Carrez@sun.com
WWW:    http://home.worldnet.fr/stcarrez   http://www.sun.com
Mail:   17, rue Foucher Lepelletier        6, avenue Gustave Eiffel
        92130 Issy Les Moulineaux          78182 Saint Quentin en Yvelines
        France

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]