How to Use GDB to Debug C Programs — A Hands-On Tutorial

Your C program compiles cleanly, runs without crashing — and prints the wrong answer. You could scatter printf lines through the code and recompile ten times, or you could watch the program run, line by line, inspecting any variable at any moment. That second option is GDB, the GNU Debugger, and this tutorial teaches it …