by alex_smart · 5y ago · 0 comments
For debugging proper, sometimes it is indeed faster to just use print statements. As with everything else, you have to use your judgement.
If you are in a situation where you would like to inspect the flow of control through a large chunk of code, debugger is the best. How many print statements are you going to write? Twenty? Hundreds? Okay the log shows that some invariant somewhere broke, but now what? How did we actually get here? Of course, at some point using the debugger makes more sense in such a scenario.
The biggest problem I have seen people have with debugger (in C++ world) is that the debug builds run much slower and it can sometime takes hours to reproduce the state you want to debug. The tip I usually give is: you don't have to have the whole project be built without optimizations. Just enable those flags for the specific components you are debugging.
Use simple gdb script, break, print vals, cont,
This allows one to debug and app's internal states without rebuilding with printf enable.
Combine the above with automated regression test system, one to debug very hard problems that might take hours/days to repro.I do that a lot. It is, for me, the best way of learning something I do not know.