W
werasm
When I write code I use a lot of:
std::cout << "TEST1\n";
...
...
<some code>
...
...
std::cout << "TEST2\n";
etc.
But is there some better way do this kind of debugging (maybe with some
preprocessor commands)?
I know that I could use the gdb debugger but often I prefer the above
procedure.
I usually write a little piece of code, test it, then integrate it.
The code is written in a way that makes it easily integrable. To
achieve
this I often use either callback functions or interfaces, depending
on circumstance. For testing I often implement the interfaces by
logging
to std::cout, yes.
After integration I test again. For this the implementation of the
interfaces
log to a low priority task (to impose as little as possible runtime
overhead).
Logging can be switched on/off remotely on a per class basis, but the
class
has to derive from something that I call a DiagnosticSubscriber. This
mechanism is quite handy when debugging multi-threaded applications.
I very rarely use the debugger nowadays. When tests fail I usually
think
about why they fail by using a pen and paper first. I have used
debuggers
in the past though. One such case I was programming in a team, and
after
I added my code, the application crashed for no apparent reason.
After
debugging I realized that the size of the image caused someone else's
stray pointer to overwrite my code (The debugger just showed me the
point
of the crash, and that there was nothing wrong with the code itself).
The culprit was not found by the debugger, though. It was found by
inspection on a mass scale.