Debugging

There are many ways to go about debugging, from printing out messages to the screen, to using a debugger, or just thinking about what the program is doing and making an educated guess as to what the problem is.

5 stages of debugging

Bugs

Before a bug can be fixed, the source of the bug must be located. For example, with segmentation faults, it is useful to know on which line of code the segmentation fault is occurring. Once the line of code in question has been found, it is useful to know about the values in that method, who called the method, and why (specifically) the error is occurring. Using a debugger makes finding this type of information very simple.

  • gdb is the debugger for multiple programming languages on Linux. If you installed geany-plugins with geany (a lightweight IDE), you can perhaps activate gdb debug in menu → tools → plugin manager and mark the debugger checkbox (this is not true for all distros). Documentation can be found on the GNU Project website.
  • An alternative is ddd, it is easier to use, and with GUI.
  • When using dynamic memory allocation, valgrind may come in handy.