Re: evaluating #defines in gdb?

From: Mark Devlin (markd@eskimo.com)
Date: 11/02/95


On Thu, 2 Nov 1995, Pink Floyd wrote:

> Why couldn't gdb get that info from the source files?  It seems to be able 
> to reproduce lines of code when you're stepping through. I presume it is
> reading the source files, and that the code is not actually stored in the
> object files...?  Seems like it would be trivial to have made gdb also read
> headers and be able to evaluate macros/defines in expressions you give it.

gdb (and other source-level debuggers) get the info about variables from 
the symbol table in the executable.  When you compile with debug info, 
one of the things the compiler does is store the file and line number of a 
variable/function so the debugger could find it easily.  Note that this 
is what the _compiler_ does, NOT the preprocessor (which deals with the 
#defines, #includes, etc before the compiler even sees them).  The 
preprocessor would need to be modified to pass the macros on to the 
compiler, which would need to be changed to deal with it.  Too much 
hassle for too little benefit.

The alternative?  If you're using an ANSI C compiler (which I'm pretty 
sure you have to be to be compiling Circle, if I remember correctly), use 
things like:
const int MAX_RACES = 6;

Some compilers will allocate memory for a variable, others will 
just insert the value just as the preprocessor does with #defines.  
However, most (if not all) debuggers will be able to evaluate 
"MAX_RACES".

Another alternative that will work (I think) is to use enums:
enum { MAX_RACES = 6 };

 - Mark
markd@eskimo.com



This archive was generated by hypermail 2b30 : 12/07/00 PST