5 ms·
Thank you for posting this! As a budding C programmer, this will be very useful to me. Are there any more tools/tricks I should know to debug programs? Pitfall
by Flex247A 5y ago
Thank you for posting this!
As a budding C programmer, this will be very useful to me. Are there any more tools/tricks I should know to debug programs? Pitfalls I should avoid?
- dekken_ 5y agoyou could try use sanitizers to find problems so you don't need to debug so much ref: https://clang.llvm.org/docs/AddressSanitizer.html https://clang.llvm.org/docs/AddressSanitizer.html
- f00zz 5y agoValgrind is pretty useful: https://valgrind.org/ https://valgrind.org/
- bear8642 5y agoIndeed! Very useful for shell wrote as part of OS course last year. Compiling with debug (-g in gcc) lets valgrind report which function's allocating lost memory
- passivate 5y agoHonestly, the best tool is your own brain. The easiest way to develop that tool is through experience. In a previous role, I did a ton of system level coding in C++ [~10yrs], and no tool can match your own intuition and thinking about the problem at hand. The best way to develop this is to be mindful of what is happening as the code is executing, in terms of the CPU, the memory and any peripherals or other devices you may be using. So for e.g, be very very comfortable tracing through code in an end-end fashion and not just when it crashes. This way the code paths, intermediate variable values, and everything else is ingrained within you. Your brain will very quickly spot situations where something looks off. As you do this a bunch it will get easier and easier, and you will slowly develop an intuition for these things. If you're focusing on crash dumps and postmortems, you also need to be aware of what raw memory looks like at the bit level, understand the basics of the CPU architecture, etc. Again, the more you do this the easier it will get. With most things the big-picture view is always dark and murky when you start out. The knowledge and experience you gain will be the light that you shine to gain a clearer view. Good luck.
- Flex247A 5y agoThank you so much for.your detailed comment!