3 ms·
Yes, and not just for debugging. Debuggers are great for learning a new codebase. For debugging proper, sometimes it is indeed faster to just use print stateme
by alex_smart 5y ago
Yes, and not just for debugging. Debuggers are great for learning a new codebase.
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.
- deleted 5y ago[deleted]
- tluyben2 5y ago> Yes, and not just for debugging. Debuggers are great for learning a new codebase. I do that a lot. It is, for me, the best way of learning something I do not know.
- selfhoster11 5y agoIt's especially useful with unfamiliar frameworks where you don't even know where the entry point is for a particular piece of code.
- srcmap 5y agoOne gdb trick I used: 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.