Using, configuring, and extending GDB
GDB has an undeserving reputation as being complicated to use, mostly because of its old-style command-line interface. In fact, there are numerous GUI frontends for the tool, including DDD (www.gnu.org/software/ddd), CGDB (https://github.com/cgdb/cgdb), GDB dashboard (https://github.com/cyrus-and/gdb-dashboard), and gdbgui (www.gdbgui.com). However, its text-based interface (TUI) is built in, simple to use and understand, especially when debugging C code. Faulty code should be compiled by GCC with the necessary flags, and loaded into GDB:
-ggdb3 makes GCC save the maximum amount of debugging information, while -O0 switches off any optimisations that might affect that data. -std=c99 indicates that the code follows the C99 standard. GDB’s -tui flag switches on the TUI, and -q disables the printing of GDB’s licensing preamble.
Debugging to the max
The code max.c (all the code can be found on the DVD or linuxformat.com/archives) is meant to find the largest integer in an array by calling findMax():
Note the program contains a printArr() function for printing an array. Neither nor found any errors in the code (), but the program prints the wrong answer:
You’re reading a preview, subscribe to read more.
Start your free 30 days