GDB (GNU Debugger) is a powerful command-line tool for debugging C programs. It allows you to run your program step-by-step, inspect variables, set breakpoints, and examine the call stack when errors like segmentation faults occur.

To use GDB with C:

  1. Compile your code with debugging information using the -g flag: gcc -g -Wall your_program.c -o your_program.

  2. Start GDB with your compiled executable: gdb ./your_program.

  3. Use key commands at the (gdb) prompt:

    • run or r: Start executing the program.

    • break or b: Set a breakpoint at a specific line (e.g., break 10) or function (e.g., break main).

    • list or l: Display the source code around the current line.

    • step or s: Execute the next line, stepping into function calls.

    • next or n: Execute the next line, but do not step into function calls.

    • print or p: Display the value of a variable (e.g., print x).

    • continue or c: Resume program execution until the next breakpoint.

    • backtrace or bt: Show the current call stack, which is crucial for diagnosing crashes.

    • quit or q: Exit GDB.

GDB is essential for efficiently identifying and fixing bugs in C programs, especially complex ones involving pointers or memory management.

🌐
OnlineGDB
onlinegdb.com › online_c_compiler
Online C Compiler - online editor
OnlineGDB is online IDE with c compiler. Quick and easy way to compile c program online. It supports gcc compiler for c.
🌐
Purdue University
cs.purdue.edu › homes › cs240 › resources › gdb.html
gdb howto
Sound familiar? Well, there's a cool little tool called "gdb" that can help you with this, and it's installed on pretty much every UNIX machine everywhere. It can show you the exact line that caused your program to die, which is a lot faster than putting printf's all over the place.
🌐
GitHub
gist.github.com › cqfd › 3374675
Learning c with gdb · GitHub
Let’s first make sure that `i`’s chunk of memory holds `i`’s value, 32767: ... In full, “x/1dw” tells gdb to “examine 1 (signed) decimal word”, where a word means four contiguous bytes (on my machine at least).
🌐
Medium
medium.com › havingfun › debugging-c-code-with-gdb-90adb2f3da96
Debugging C code With GDB | Having Fun | Having Fun
May 15, 2022 - Inside a function, another variation of the info command prints the arguments passed to that function: ... ... was the address of the function, removed for legibility's sake. It looks like this: 0x0000000100003f6c ... (gdb) next 5 int incremented = sum + 1; (gdb) next 6 return incremented; (gdb) info locals sum = 5 incremented = 6
🌐
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.
🌐
mingw-w64
mingw-w64.org › downloads
Pre-built Toolchains - mingw-w64
mingw-w64 GCC : compilers, linker, assembler · GDB : debugger · GNU Make : standard build tool · CMake with Ninja: build system · busybox-w32 : standard unix utilities, including sh · Vim : powerful text editor · Universal Ctags : source navigation · Ccache : compiler cache ·
Find elsewhere
🌐
Reddit
reddit.com › r/c_programming › a quick intro to gdb.
r/C_Programming on Reddit: A quick intro to gdb.
May 28, 2023 -

GDB Quick Guide

I found out I didn't need cgdb by the way, it was better to just gdb -tui on Debian. Less modem noise in the form of uninterpreted escape sequences too.

So it paid up to do gdb -help.

The guide doesn't mention watch or watch -l but it points to Debugging with GDB where you can find everything.

It is a good quick start, with a couple of examples.

🌐
Jonathan Cook
cs.nmsu.edu › ~jcook › posts › gdb-intro
C/C++: The GDB Debugger • Jonathan Cook
January 31, 2023 - GDB is the Gnu DeBugger, a tool that lets you control the execution of your C/C++ program and inspect what it is doing at runtime. On top of that, it also allows you to inspect your program after it has had a catastrophic error such as a segmentation fault. Debuggers are extremely important ...
🌐
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 ...
🌐
LogicMojo
logicmojo.com › online-gdb-compiler
Online GDB Compiler By Logicmojo
It is a highly sophisticated compiler that is extremely fast, so it loads and returns results immediately. You can also use this online code editor to perform web development languages such as HTML, CSS, JavaScript, and SQL. Latest Version of GDB Compiler is 13.1, with the GNU debugger and ...
🌐
GNU Project
sourceware.org › gdb
GDB: The GNU Project Debugger
This means printing the help text for all sub-commands, unless the prefix command is a 'show' command, in which case the value of all sub-commands is printed. Setting the documentation string (__doc__) of a gdb.Parameter sub-class to the empty string, means GDB will only display the set_doc or show_doc strings in the set/show help output.
🌐
Recurse Center
recurse.com › blog › 5-learning-c-with-gdb
Learning C with gdb - Blog - Recurse Center
August 27, 2012 - The ptype command might be my favorite command. It tells you the type of a C expression: (gdb) ptype i type = int (gdb) ptype &i type = int * (gdb) ptype main type = int (void)
🌐
Dev-cpp
dev-cpp.com
Home | Dev-C++ Official Website
Supports GCC-based compilers (Mingw, Cygwin) with full debugging capabilities using GDB.
🌐
Caltech
users.cms.caltech.edu › ~mvanier › CS11_C › misc › gdb.html
CS 11 C track: Using gdb for debugging
It’s a good habit to always use these options.) The -g option puts debugging information into the executable. Most importantly, it puts the text of the source code file into the executable so you can examine it as the program executes (we’ll see how below). Type gdb myprog (for the example above).
🌐
GNU Project
sourceware.org › gdb › current › onlinedocs › gdb
Debugging with GDB
This is the Tenth Edition, for GDB (GDB) Version 18.0.50.20260319-git. Copyright (C) 1988-2026 Free Software Foundation, Inc.
🌐
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.
🌐
LLVM
llvm.org
The LLVM Compiler Infrastructure Project
The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. Despite its name, LLVM has little to do with traditional virtual machines. The name "LLVM" itself is not an acronym; it is the full name of the project · LLVM began as a research project at the University ...
🌐
UCSD
cseweb.ucsd.edu › classes › fa09 › cse141 › tutorial_gcc_gdb.html
Tutorial of gcc and gdb
The optimization options may differ in each platform. For example, the gcc under Mac OS also supports -Os and -Oz to allow optimization for code size. ... gcc is a debugger by GNU project. Gdb can step through your source code line-by-line or even instruction by instruction.