๐ŸŒ
GNU Project
sourceware.org โ€บ gdb
GDB: The GNU Project Debugger
GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed.
HomePage
Please wait a moment while we ensure the security of your connection ยท Protected by Anubis From Techaro. Made with โค๏ธ in ๐Ÿ‡จ๐Ÿ‡ฆ
Memory (Debugging with GDB)
Within GDB and this document, the term addressable memory unit (or memory unit for short) is used when explicitly referring to a chunk of data of that size. The word byte is used to refer to a chunk of data of 8 bits, regardless of the addressable memory unit size of the target. For most systems, addressable memory unit is a synonym of byte. When you are debugging ...
๐ŸŒ
GNU
gnu.org โ€บ software โ€บ gdb โ€บ gdb.html
GDB: The GNU Project Debugger
GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed.

source-level debugger

GNU_gdb_12.1_screenshot.png
The GNU Debugger (GDB) is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, Assembly, C, C++, D, Fortran, Haskell, Go, Objective-C, OpenCL C, โ€ฆ Wikipedia
Factsheet
Developer GNU Project
Initial release 1986; 39 years ago (1986)
Stable release 16.3
/ 20 April 2025
Factsheet
Developer GNU Project
Initial release 1986; 39 years ago (1986)
Stable release 16.3
/ 20 April 2025
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ GNU_Debugger
GNU Debugger - Wikipedia
1 month ago - The GNU Debugger (GDB) is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, Assembly, C, C++, D, Fortran, Haskell, Go, Objective-C, OpenCL C, Modula-2, Pascal, Rust, and partially others.
๐ŸŒ
Opensource.com
opensource.com โ€บ article โ€บ 21 โ€บ 3 โ€บ debug-code-gdb
Learn to debug code with the GNU Debugger | Opensource.com
The GNU Debugger, more commonly known by its command, gdb, is an interactive console to help you step through source code, analyze what gets executed, and essentially reverse-engineer what's going wrong in a buggy application.
๐ŸŒ
Kauffman77
kauffman77.github.io โ€บ tutorials โ€บ gdb.html
Quick Guide to gdb: The GNU Debugger
In a terminal, run gdb with a "text user interface" >> make puzzlebox gcc -Wall -g -c puzzlebox.c gcc -Wall -g -o puzzlebox puzzlebox.o # Note the -g option while compiling which adds debugging symbols for # the debugger: very useful # Start gdb with the text user interface on program puzzlebox >> gdb -tui ./puzzlebox
๐ŸŒ
OnlineGDB
onlinegdb.com
GDB online Debugger | Compiler - Code, Compile, Run, Debug online C, C++
Online GDB is online compiler and debugger for C/C++. You can compile, run and debug code with gdb online. Using gcc/g++ as compiler and gdb as debugger. Currently C and C++ languages are supported.
๐ŸŒ
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.
๐ŸŒ
Baylor
cs.baylor.edu โ€บ ~donahoo โ€บ tools โ€บ gdb โ€บ tutorial.html
How to Debug Using GDB
By taking a closer look at the values printed above, we realize that we are computing fact=fact * j where fact has been initialized to 0; fact should have been initialized to 1. We quit GDB with the quit command. Next we need to change the following line: int fact = 1; Recompile the code and run it, you will get the expected output. This program causes a core dump due to a segmentation fault. We will try to trace the reason for this core dump. Download the program, from here. 1. Compile the program using the following command. ... 3. The core dump generates a file called corewhich can be used for debugging.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ gdb-step-by-step-introduction
GDB (Step by Step Introduction) - GeeksforGeeks
January 10, 2025 - GDB stands for GNU Project Debugger and is a powerful debugging tool for C (along with other languages like C++). It helps you to poke around inside your C programs while they are executing and also allows you to see what exactly happens when ...
๐ŸŒ
GNU Project
sourceware.org โ€บ gdb โ€บ current โ€บ onlinedocs โ€บ gdb
Debugging with GDB
Fred was a long-standing contributor to GDB and to Free software in general. We will miss him. ... The purpose of a debugger such as GDB is to allow you to see what is going on โ€œinsideโ€ another program while it executesโ€”or what another program was doing at the moment it crashed.
๐ŸŒ
Red Hat
docs.redhat.com โ€บ en โ€บ documentation โ€บ red_hat_developer_toolset โ€บ 12 โ€บ html โ€บ user_guide โ€บ chap-gdb
Chapter 8. GNU Debugger (GDB) | User Guide | Red Hat Developer Toolset | 12 | Red Hat Documentation
It allows you to inspect memory within the code being debugged, control the execution state of the code, detect the execution of particular sections of code, and much more. Red Hat Developer Toolset is distributed with GDB 11.2.
Top answer
1 of 5
33

Here is a quick start tutorial for gdb:

/* test.c  */
/* Sample program to debug.  */
#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char **argv) 
{
  if (argc != 3)
    return 1;
  int a = atoi (argv[1]);
  int b = atoi (argv[2]);
  int c = a + b;
  printf ("%d\n", c);
  return 0;
}

Compile with the -g3 option. g3 includes extra information, such as all the macro definitions present in the program.

gcc -g3 -o test test.c

Load the executable, which now contain the debugging symbols, into gdb:

gdb --annotate=3 test.exe 

Now you should find yourself at the gdb prompt. There you can issue commands to gdb. Say you like to place a breakpoint at line 11 and step through the execution, printing the values of the local variables - the following commands sequences will help you do this:

(gdb) break test.c:11
Breakpoint 1 at 0x401329: file test.c, line 11.
(gdb) set args 10 20
(gdb) run
Starting program: c:\Documents and Settings\VMathew\Desktop/test.exe 10 20
[New thread 3824.0x8e8]

Breakpoint 1, main (argc=3, argv=0x3d5a90) at test.c:11
(gdb) n
(gdb) print a
$1 = 10
(gdb) n
(gdb) print b
$2 = 20
(gdb) n
(gdb) print c
$3 = 30
(gdb) c
Continuing.
30

Program exited normally.
(gdb) 

In short, the following commands are all you need to get started using gdb:

break file:lineno - sets a breakpoint in the file at lineno.
set args - sets the command line arguments.
run - executes the debugged program with the given command line arguments.
next (n) and step (s) - step program and step program until it 
                        reaches a different source line, respectively. 
print - prints a local variable
bt -  print backtrace of all stack frames
c - continue execution.

Type help at the (gdb) prompt to get a list and description of all valid commands.

2 of 5
7

Start gdb with the executable as a parameter, so that it knows which program you want to debug:

gdb ./myprogram

Then you should be able to set breakpoints. For example:

b myfile.cpp:25
b some_function
๐ŸŒ
Florida State University
cs.fsu.edu โ€บ ~myers โ€บ cop3330 โ€บ debug โ€บ debugger.html
How to use the GDB debugger - basics
Most installations of the GNU c++ compiler (g++) also include the GNU debugger, GDB. This page is meant to be a guide to doing some basic debugging with GDB.
๐ŸŒ
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).
๐ŸŒ
Stanford University
web.stanford.edu โ€บ class โ€บ cs107 โ€บ resources โ€บ gdb
CS107 GDB and Debugging
In CS106A and CS106B, you may have used a graphical debugger; these debuggers were built into the program you used to write your code, and allowed you to set breakpoints, step through your code, and see variable values, among other features. In CS107, the debugger we are using is a separate program from your text editor, called gdb (the "GNU Debugger").
๐ŸŒ
Sternum IoT
sternumiot.com โ€บ home โ€บ learn gdb debugger: key features and tutorial
Learn GDB Debugger: Key Features and Tutorial
May 29, 2024 - GDB (GNU Project Debugger) is a free and open-source debugger used for debugging various programming languages, including C, C++, Ada, Fortran, and others.
๐ŸŒ
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.
๐ŸŒ
Brendan Gregg
brendangregg.com โ€บ blog โ€บ 2016-08-09 โ€บ gdb-example-ncurses.html
gdb Debugging Full Example (Tutorial): ncurses
I'm a little frustrated with finding "gdb examples" online that show the commands but not their output. gdb is the GNU Debugger, the standard debugger on Linux. I was reminded of the lack of example output when watching the Give me 15 minutes and I'll change your view of GDB talk by Greg Law ...
๐ŸŒ
BitDegree
bitdegree.org โ€บ learn โ€บ gdb-debugger
Tutorial on How to Use the GDB Debugger Easily
October 14, 2019 - This tutorial introduces the GDB debugger for checking the way C++ programs work. Learn to find bugs and solve quickly by analyzing code with GDB debugger.