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 Format1 min read
Ultimate Desktop Upgrade!
LXF316 will be on sale Tuesday 28th May 2024 Word processors that can help craft that novel you’ve always been talking about and organise large projects. Revive the old roleplaying system for a digital age as we recreate our own play-by-mail gaming
Linux Format3 min read
Original Prusa XL
The wait for a bigger 3D printer from Prusa Research has ended, and it certainly overdelivered. Instead of simply upsizing its classic i3 design, Prusa chose to create a completely new Core XY tool changer with a 360x360 mm build plate. The machine c
Linux Format5 min read
Some Ansible Advice For Around The Home!
Of late, this writer has been busy creating new virtual hosts for different things and decided that it would be an ideal time to get stuck into Ansible. Things have evolved in system management since Bash. Ansible is a great way to deploy software c

Related