GDB Quick Reference for Most Used Commands

Andrew O

Andrew O

3 min read Tags: Linux

Table of Contents


Introduction

GDB is a powerful command line tool that can be used to debug programs written in C, C++, and other languages.

Despite its popularity, GDB can be quite intimidating for new users and especially for people just starting with C/C++. The existing guides and tutorials provide a lot of information, but they can be a bit too verbose for beginners. With this post I aim to provide a quick tutorial/reference for the most commonly used GDB commands for myself and others.

For the below commands, I also recommend to use shortcuts to optimize the workflow, e.g. use r instead of run, b instead of break, etc.

Commands

Quick list, sorted by usage

You probably don’t have all day to read the entire post, so here is a quick list of commands sorted by usage:

Detailed list

Here’s expanded list of commands with more details.

Starting the program

Note: r will start the program with the last used arguments, from the beginning. Useful if you want to restart the program with the same arguments.

Quitting GDB

Note: You can also use Ctrl + D to quit GDB

Breakpoints

Running the program

Note: continue will continue the program until the next breakpoint

Printing values

Note: sometimes it is easier to backtrace (bt) to see the values of variables at the current point

Backtrace

Listing source code

Displaying source code

Changing values

Conclusion

Hopefully this helped you get started or get a refresher on GDB. If you have any questions or suggestions, feel free to contact me. Don’t forget to drink water and take breaks while debugging!

Have a good day,

Andrew


Recent Posts

/../assets/images/posts/tmux1.png
GIF/WebP Screen Capture on Wayland(Hyprland)

An easy way to create a screen capture on Wayland(Hyprland) to WebP or gif format

Tags: Linux
Andrew O

Andrew O

3 min read
/../assets/images/posts/tgu1.png
Heavy Kettlebell Turkish Getups, part 1

Benefits, drawbacks, forearm pain

Andrew O

Andrew O

6 min read
/../assets/images/posts/pw1.png
Remote plant watering with Raspberry Pi

Remote plant watering with Raspberry Pi, 5$ water pump, and Tor network for remote access

Andrew O

Andrew O

4 min read

Leave a comment

Need help? Get 1:1 live session on a trusted platform

Contact me on Codementor to schedule a 1:1 live session to help with your project or to learn something new.