Linux Format

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.

More from Linux Format

Linux Format9 min read
Create Old-school Pixel Art Images
Credit: www.gimp.org Think of retro games and you’ll probably think of the pixellated look of titles released on consoles such as the NES. Games such as Bomberman and Kid Icarus worked within the limitations of ’80s technology, yet offered hours of f
Linux Format5 min read
Vintage PC options
Having got LMDE installed on our woefully underpowered EeePC, it became apparent that the machine wasn’t going to be very useful. Except for pandering to our sense of nostalgia. According to Systemd-analyze, it took a minute to boot (as far as the lo
Linux Format1 min read
Tom’s HARDWARE
No matter if you're building a PC, buying a laptop or learning about robots, Tom’s Hardware has all the comprehensive knowledge you need. Scan & Subscribe for free! ■

Related