🌐
University of Michigan
web.eecs.umich.edu › ~sugih › pointers › summary.html
GDB Tutorial
So, if your program is in a source file called memsim.c and you want to put the executable in the file memsim, then you would compile with the following command: ... To start gdb, just type gdb at the unix prompt. Gdb will give you a prompt that looks like this: (gdb).
🌐
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.
🌐
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.
🌐
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.
🌐
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.

🌐
Baylor
cs.baylor.edu › ~donahoo › tools › gdb › tutorial.html
How to Debug Using GDB
Watching changes We can step through the program and examine the values using the print command. (gdb) n 9 for (int j = 0; j <= number; j++) { (gdb) n 10 fact = fact * j; (gdb) n 9 for (int j = 0; j <= number; j++) { (gdb) print fact $2 = 0 (gdb) n 13 return fact; (gdb) quit The print command (abbreviated p) reveals that the value of fact never changes.
🌐
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.
🌐
Cprogramming.com
cprogramming.com › gdbtutorial.html
Tutorials - An Introduction to GDB - Cprogramming.com
How to begin Get the book · C tutorial C++ tutorial Game programming Graphics programming Algorithms More tutorials
Find elsewhere
🌐
YouTube
youtube.com › low level
GDB is REALLY easy! Find Bugs in Your Code with Only A Few Commands - YouTube
Join me and learn how to debug a program written in C using GDB. In this video, we go over how to compile a program written in C so that GDB can present it, ...
Published   April 17, 2021
Views   230K
🌐
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).
🌐
University of Chicago
classes.cs.uchicago.edu › archive › 2017 › winter › 51081-1 › LabFAQ › lab2 › gdb.html
Debugging "C" And "C++" Programs Using "gdb"
Specifying a specific line of code ... this tutorial). Specifying a function name, to break every time it is being called: break main this will set a break point right when starting the program (as the function "main" gets executed automatically on the beginning of any C or C++ program). ... Starting program: /usr/home/choo/work/c-on-unix/debug_me warning: Unable to find dynamic linker breakpoint function. warning: GDB will be unable ...
🌐
Swarthmore College
cs.swarthmore.edu › ~newhall › unixhelp › howto_gdb.php
gdb (and ddd) guide
Getting Started with gdb C and C++ programs compiled with the GNU compiler and the -g option can be debugged using GNU's debugger gdb (actually, you can use gdb on code that is not compiled with -g, but unless you like trying to figure out how assembly code sequences map to your source code ...
🌐
Carnegie Mellon University
cs.cmu.edu › ~gilpin › tutorial
gdb Tutorial
This tutorial was originally written for CS 342 at Washington University. It is still maintained by Andrew Gilpin. This tutorial is written to help a programmer who is new to the Unix environment to get started with using the gdb debugger. This tutorial assumes you already know how to program ...
🌐
Suchprogramming
suchprogramming.com › debugging-with-gdb-part-1
Such Programming - Debugging C Programs with GDB – Part 1
Looking at this listing, I think a good place to pause and look around would be at the printf() call within my for loop. To have GDB stop here I’ll use the break command and I’ll give it the argument 10 to indicate I’d like to set a breakpoint at line 10.
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
🌐
UCSD
cseweb.ucsd.edu › classes › fa09 › cse141 › tutorial_gcc_gdb.html
Tutorial of gcc and gdb
You may also watch the value of any variable at run-time. In additon, it also helps to identify the place and the reason making the program crash. All program to be debugged in gdb must be compiled by gcc with the option "-g" turning on.
🌐
Stanford University
web.stanford.edu › class › cs107 › resources › gdb
CS107 GDB and Debugging
This page will list the basic gdb commands you will need to use as you progress through CS107. However, it takes practice to become proficient in using the tool, and gdb is a large program that has a tremendous number of features.
🌐
HowtoForge
howtoforge.com › home › how to debug c programs in linux using gdb
How to Debug C Programs in Linux using gdb
Firstly, to successfully use debuggers like GDB, you have to compile your program so that the compiler also produces debugging information that debuggers require. For example, in case of the gcc compiler, which we'll be using to compile the ...