Mail Archives: djgpp/2000/08/17/11:30:23
"Rafał Maj" <r_maj AT poczta DOT onet DOT pl> wrote:
> Of course, it's stupid to print out every debug information.
Exactly.
[...]
> so I can define at begining of program array of names of functions, with I
> want to be debugged
> const char* classes_to_dbg_to_cerr[] = {"cMyClass"};
> const char* classes_to_dbg_to_disk_file[] = {"cGfxDriver"};
I.e. you have to recompile at least part of your program whenever you
want to debug a different class. In that case, why not use more finely
grained preprocessor methods to do more of that job?
The problem you currently face is caused by *all* debug statements
being present in the code of the program, even if they aren't
currently used (because their class isn't listed in
classes_to_debug_...). Situations like this are what conditional
compilation was invented for. You can reproduce much of it by use of
constants, in C++, but in the case at hand, the decisions will still
be made at runtime, because the compiler doesn't know at compile time
what strings are in your classes_to_debug_ array, so it cannot predict
the outcome of the find_... method.
Instead, I'ld set up a #define DEBUG_THIS_CLASS 1 in the header file
for the class, and conditionally activate DBG statements based on it.
The conditional definition of DBG could be in a separate header file.
Roughly like the method implemented in <assert.h>, and the NDEBUG
macro.
Or you could have a central 'debugflags.h' that collects such
#defines, and include that everywhere. As is, you're stuffing your
code with debug-output statements that aren't ever executed. That's a
waste of execution time and program size.
> I think, that this debugging strategy isn't so bad after all ?
It's not exceptionally bad, but not particularly good, either, IMHO.
Another question that keeps popping up in my mind, as we discuss this:
why not use a proper debugger, instead of trying to do it by hand?
printf()-style debugging is sometimes necessary, and there are some
gurus who claim that it's all the debugging you'll ever need.
It's so much easier to make sense out of variable contents and other
information like it if you can observe exactly what you want, at any
given point of execution of the program and of your analysis of the
problem. A debugger lets you do that without wading through megabytes
of debug output that turns out not to be needed most of the time, and
without having to recompile everytime your analysis has led you closer
to the problem, and you need to look at other variables to make the
next step.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -