Over your window
You think I’m confused,
I’m waiting ...
To complete my current ruse.
Wire, “I Am the Fly”
This chapter will cover tools for debugging, testing, and documenting your writing—the essentials to take your writing from a potentially useful set of scripts to something you and others can rely on.
Because C gives you the freedom to do idiotic things with memory, debugging means both the quotidian problem of checking logic (with GDB) and the more technical problem of checking for memory misallocations and leaks (with Valgrind). On the documentation side, this chapter covers one tool at the interface level (Doxygen) and another that helps you document and develop every step of the program (CWEB).
The chapter also gives a quick introduction to the test harness, which will allow you to quickly write lots of tests for your code, and offers some considerations about error reporting and handling input or user errors.
The first tip about the debugger is simple and brief:
Use a debugger, always.
Some of you will find this to be not much of a tip, because who possibly wouldn’t use a debugger? Here in the second edition of the book, I can tell you that one of the most common requests regarding the first edition was a more extensive introduction to the debugger, which was entirely new to many readers.
Some people worry that bugs typically come from broad errors of understanding, while the debugger only gives information ...