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?



Yes...!!!

I proposed something like this years ago...I almost hacked up
gcc to put this in (I think I started...)

It is incredibly useful in the real world to encapsulate what
compiler flags were used in the binary (essentially the gcc command
line with preprocessor flags).

I just compiled a trivial C program with -O3 to see..

The .s file has
  .ident  "GCC: (GNU) 2.95.2 19991024 (release)"

Is there a way for nm to decode this?  (strings can show it, 
but its pretty meaningless in the binary).

For example:
...
GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
GCC: (GNU) 2.95.2 19991024 (release)
GCC: (GNU) 2.95.2 19991024 (release)
GCC: (GNU) 2.95.2 19991024 (release)
GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
....

I don't know how to take apart elf binaries off the top
of my head, but I assume there is information someplace encoded
to match this up with specific files.

gdb doesn't have to warn, but you should be able to use a tool
to figure this out.

Marty Leisner


Stan Shebs <shebs@apple.com> writes  on Fri, 03 Mar 2000 15:58:59 PST
     > 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.
     > 
     > Ideally of course, GCC would issue lots of amazingly detailed debug 
info,
     > and GDB would use it to reconstruct and report program state just as the
     > programmer expects to see it.  But today, the result is just lame; 
hackers
     > trying to debug get lots of squirrelly behavior from GDB.  The problem 
is
     > that they don't know whether the randomness is due to bugs in the 
program,
     > or to the effect of the optimizer.  So the suggestion came up to have 
GCC
     > issue debug info stating what optimizations have been applied to a file,
     > and to have GDB report that information per-function, so that users 
could
     > lower their expectations appropriately.
     > 
     > Although my first reaction was to say "bleah", upon reflection I 
wondered
     > if I was too easily dismissing the concerns of real users of the tools.
     > This sort of thing routinely confuses users; even with years of GNU
     > experience, I still find myself being caught by surprise because I've
     > forgotten that part of the code was optimized.  A simple warning from 
the
     > debugger would have saved me some time and trouble.
     
     > If there's consensus that this would be a worthwhile addition, I'll
     > work up a specific design and publish it.
     > 
     > Stan



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