🌐
University of Toronto
cs.toronto.edu › ~krueger › csc209h › tut › gdb_tutorial.html
gdb tutorial
As programmers, we all make errors. Certainly, most of us at least have tried placing "printf" statements in our code hoping to catch the errors, however, we need to know more than that. Debugger is a good tool for tracing bugs. In this tutorial, we will show you how to use gdb -- a "GNU" debugger.
🌐
Red Hat
developers.redhat.com › articles › the-gdb-developers-gnu-debugger-tutorial-part-1-getting-started-with-the-debugger
The GDB developer's GNU Debugger tutorial, Part 1: Getting started with the debugger | Red Hat Developer
February 27, 2024 - This article is the first in a series demonstrating how to use the GNU Debugger (GDB) effectively to debug applications in C and C++. If you have limited or no experience using GDB, this series will teach you how to debug your code more efficiently.
Discussions

Properly Learning GDB
A course would be overkill. Look for a cheat sheet, then use it to do some actual debugging. You'll find yourself looking up specific things and soon enough you will have explored everything. I will say, if you're on windows, I'd strongly suggest using the rad debugger (shameless self plug) by epic games / rad tools. It's on GitHub. More on reddit.com
🌐 r/C_Programming
21
46
December 10, 2024
Beej's Quick Guide to GDB

I owe beej about 80% of my sockets programming knowledge. Thanks beej.

More on reddit.com
🌐 r/programming
24
86
August 28, 2018
Protips for GDB?
I find this reference card sooooo helpful and it even taught me a few features I didn't know. https://users.ece.utexas.edu/~adnan/gdb-refcard.pdf Keep it handy :) More on reddit.com
🌐 r/cpp
34
38
September 19, 2020
Getting started with GDB
Thorough article, and better than I expected! IMHO, the examples ought to use debug level 3, as in -g3 — or if you really insist, -ggdb3. (These days the gdb part is archaic, from a time before DWARF took off.) It includes extras like macro values — really handy at times. Consider: #include int main(void) { return EXIT_SUCCESS; } With -ggdb/-g: $ cc -ggdb main.c $ gdb a.out (gdb) start Temporary breakpoint 1, main () at main.c:5 5 return EXIT_SUCCESS; (gdb) p EXIT_SUCCESS No symbol "EXIT_SUCCESS" in current context. With -g3: $ cc -g3 main.c $ gdb a.out (gdb) start Temporary breakpoint 1, main () at main.c:5 5 return EXIT_SUCCESS; (gdb) p EXIT_SUCCESS $1 = 0 If you're going to ship debug information, such as a debug symbol package in a distribution, then perhaps -g makes sense because -g3 can be quite large. Otherwise either you want no debug information (releases) or as much as possible. (Note: symbol information is distinct from debug information.) Most build systems get this trade-off wrong by default. A debugging article that doesn't at least mention sanitizers is incomplete as well. They're a game changer! Address Sanitizer does produce that backtrace on crash: $ gcc -g3 -fsanitize=address -o crash crash.c $ ./crash AddressSanitizer:DEADLYSIGNAL ================================================================= ==47141==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 ... ... #2 0x557be2160174 in do_something crash.c:6 #3 0x557be2160185 in main crash.c:11 ... And Undefined Behavior Sanitizer even explains it: $ gcc -g3 -fsanitize=undefined -o crash crash.c $ ./crash crash.c:6:5: runtime error: null pointer passed as argument 1, which is declared to never be null Either can be configured to trap in GDB just like a failed assertion: export ASAN_OPTIONS=abort_on_error=1:halt_on_error=1 export UBSAN_OPTIONS=abort_on_error=1:halt_on_error=1 Which really complements GDB. But don’t despair. There is a faster way to break out of the loop. Just set a breakpoint to line 9 which is the first line after the loop: (gdb) break step.c:9 The article also mentions tbreak, but there are two even better tools: until (u) and advance (adv). The first, given no argument, will break at a higher line number, useful for getting past loops. The second is more general, combining tbreak with continue, continuing execution until reaching the given location, which need not even be local. There is nothing wrong with printf debugging. Eh… that's something people do when they don't know any better or their tools are terrible (i.e. no/poor debugger). Perhaps it's more advanced, but dprintf is worth a mention. Want a "trace" of some value over time? Throw a dprintf on it. Log of all malloc allocations (SysV ABI)? (gdb) dprintf malloc,"malloc(%zu)\n",$rdi It could be better. It's not simple to, say, capture the output in a file, and it doesn't compose with most other GDB features, notably artificial arrays . Speaking of which, the article didn't mention those! I use them all the time. $ gdb a.out (gdb) set args --foo bar baz (gdb) start Temporary breakpoint 1, main (argc=4, argv=) at main.c:3 3 return 0; (gdb) p *argv@argc $2 = {"/tmp/a.out", "--foo", "bar", "baz"} I use commands as a workaround when dprintf isn't enough. Example: #include typedef struct { char *data; int len; } str; static str example(str s) { return s; } int main(int argc, char **argv) { for (int i = 0; i < argc; i++) { str s = {argv[i], strlen(argv[i])}; example(s); } } Then: (gdb) b example Breakpoint 1 at 0x114e: file main.c, line 10. (gdb) commands Type commands for breakpoint(s) 1, one per line. End with a line saying just "end". >silent >p *s.data@s.len >c >end (gdb) r --foo bar baz Starting program: /tmp/a.out --foo bar baz $1 = "/tmp/a.out" $2 = "--foo" $3 = "bar" $4 = "baz" [Inferior 1 (process 47950) exited normally] A little tedious to set up, but sometimes called for. More on reddit.com
🌐 r/C_Programming
12
26
January 16, 2024
🌐
University of Michigan
web.eecs.umich.edu › ~sugih › pointers › summary.html
GDB Tutorial
To start gdb, just type gdb at the unix prompt. Gdb will give you a prompt that looks like this: (gdb). From that prompt you can run your program, look at variables, etc., using the commands listed below (and others not listed).
🌐
Kauffman77
kauffman77.github.io › tutorials › gdb.html
Quick Guide to gdb: The GNU Debugger
April 4, 2025 - This tutorial is for folks in courses like the UMN's CSCI 2021 or UMD's CMSC 216 which require use of GDB to work programs and perform debugging exercises like Bryant and O'Hallarons notorious "Binary Bomb" project.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › gdb-step-by-step-introduction
GDB (Step by Step Introduction) - GeeksforGeeks
January 10, 2025 - In this article we have discussed GDB (GNU Debugger) which is a powerful tool in Linux used for debugging C programs. We have discussed some of the following steps so that we can compile your code with debugging information, run GDB, set breakpoint, examine variables, and analyze program behavior.
🌐
CTF Handbook
ctf101.org › reverse-engineering › what-is-gdb
The GNU Debugger (GDB)
Then simply execute (gdb) delete display 1 and your execution will resume without the display.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › gnu_debugger › index.htm
GNU Debugger Tutorial
GDB, short for GNU Debugger, is the most popular debugger for UNIX systems to debug C and C++ programs. This tutorial provides a brief introduction on how to use GDB commands to ensure the programs are error-free.
🌐
Dirac
dirac.org › linux › gdb
Peter's gdb Tutorial: Table Of Contents
Why Write This Tutorial? Acknowledgements And Dedication · Authorship And Copyright · About Exercises · Thank Yous · A Plug For The EFF · A Request For Help · What Is A Debugger? Why Not Use printf()? What Is GDB? Other Symbolic Debuggers · Debuggers · Front Ends ·
🌐
BetterExplained
betterexplained.com › articles › debugging-with-gdb
Debugging with GDB – BetterExplained
Sample session – Short Tutorial – Long Tutorial · gcc -g myprogram.c · Compiles myprogram.c with the debugging option (-g). You still get an a.out, but it contains debugging information that lets you use variables and function names inside GDB, rather than raw memory locations (not fun).
🌐
Medium
medium.com › @amit.kulkarni › gdb-basics-bf3407593285
GDB — Basics. Introduction to basic usage of gdb | by Amit Kulkarni | Medium
November 22, 2017 - GDB — Basics Introduction to basic usage of gdb A lot of people like reading or browsing code and given the convenience of sublime or any other IDEs/tools like cscope, the navigation is simple. The …
🌐
Carnegie Mellon University
cs.cmu.edu › ~gilpin › tutorial
gdb Tutorial
April 7, 2004 - (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/cec/s/a/agg1/.www-docs/tutorial/main Creating Node, 1 are in existence right now Creating Node, 2 are in existence right now Creating Node, 3 are in existence right now Creating Node, 4 are in existence right now The fully created list is: 4 3 2 1 Now removing elements: Creating Node, 5 are in existence right now Destroying Node, 4 are in existence right now 4 3 2 1 Breakpoint 1, LinkedList<int>::remove (this=0x40160, item_to_remove=@0xffbef014) at main.cc:52 52 Node<T
🌐
Umd
users.umiacs.umd.edu › ~tudor › courses › ENEE757 › Fall15 › misc › gdb_tutorial.html
Using GDB for Reverse Engineering
To execute a single machine instruction, use: (gdb) stepi Note that if you use 'stepi' on a callq instruction, debugger will proceed inside the called function. Also note that pressing <ENTER> re-executes the last gdb command.
🌐
Beej
beej.us › guide › bggdb
Beej's Quick Guide to GDB
June 14, 2009 - This is a very quick-and-dirty guide meant to get you started with the GNU Debugger, gdb, from the command line in a terminal. Often times gdb is run via an IDE, but many people out there shun IDEs for a variety of reasons, and this tutorial is for you!
🌐
Gdbtutorial
gdbtutorial.com
Tutorial | GDB Tutorial
GDB Tutorial is comprehensive guide to learn gdb in easy steps. This tutorial covers instroduction of gdb, how to install it and explains how to use gdb and gdb commands with example.
🌐
Unknownroad
unknownroad.com › rtfm › gdbtut › gdbtoc.html
RMS's gdb Tutorial
How do I... compile with debugging symbols? run programs with the debugger? restart a program running in the debugger? exit the debugger? get help on debugger commands · How do I... stop execution continue execution see where my program stopped? step through my code line-by-line? examine ...
🌐
Interrupt
interrupt.memfault.com › blog › advanced-gdb
Advanced GDB Usage | Interrupt
October 20, 2020 - A collection of advanced GDB tips, extensions, and .gdbinit macros to speed up your debugging experience with the GNU debugger.
🌐
GNU Project
sourceware.org › gdb › current › onlinedocs › gdb.html
Top (Debugging with GDB)
This is the Tenth Edition, of Debugging with GDB: the GNU Source-Level Debugger for GDB (GDB) Version 18.0.50.20260324-git.