help running provides some hints:

There are step and next instuctions (and also nexti and stepi).

(gdb) help next
Step program, proceeding through subroutine calls.
Usage: next [N]
Unlike "step", if the current source line calls a subroutine,
this command does not enter the subroutine, but instead steps over
the call, in effect treating it as a single source line.

So we can see that step steps into subroutines, but next will step over subroutines.

The step and stepi (and the next and nexti) are distinguishing by "line" or "instruction" increments.

step -- Step program until it reaches a different source line
stepi -- Step one instruction exactly

Related is finish:

(gdb) help finish
Execute until selected stack frame returns.
Usage: finish
Upon return, the value returned is printed and put in the value history.

A lot more useful information is at https://sourceware.org/gdb/onlinedocs/gdb/Continuing-and-Stepping.html

Answer from Stephen Harris on Stack Exchange
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ gdb-step-by-step-introduction
GDB (Step by Step Introduction) - GeeksforGeeks
January 10, 2025 - (here test.c). g flag means you can see the proper names of variables and functions in your stack frames, get line numbers and see the source as you step around in the executable. -std=C99 flag implies use standard C99 to compile the code. -o flag writes the build output to an output file. ... Type the following command to start GDB with the compiled executable.
๐ŸŒ
IBM
ibm.com โ€บ docs โ€บ en โ€บ sdk-java-technology โ€บ 8
Debugging with gdb
The GNU debugger (gdb) allows you to examine the internals of another program while the program executes or retrospectively to see what a program was doing at the moment that it crashed.
Discussions

debugging - How to step-into, step-over and step-out with GDB? - Unix & Linux Stack Exchange
Read the full GDB docs. As I recall, they were quite helpful about this, when I was first learning it. Unfortunately, I haven't needed to debug any program at that level for several decades, so the actual commands seem to have gotten swapped out in my brain. So, I can't really write an answer. But, if you do figure it out from the manuals, then you can answer your own question for a bonus. ... @MAP I'll try again. I tried to use ... More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
July 24, 2016
c - How to debug using gdb? - Stack Overflow
I am trying to add a breakpoint in my program using b {line number} but I am always getting an error that says: No symbol table is loaded. Use the "file" command. What should I do? More on stackoverflow.com
๐ŸŒ stackoverflow.com
How many of you actually use GDB from the terminal?
I use it in the terminal, but unless I'm just getting a backtrace from a core dump (most common use case), I usually press Ctrl-X A to enable eXtra-Awesome mode (I don't think it's actually called eXtra-Awesome mode, but that's how I remember the keystroke). I very rarely am stepping through code with gdb though, I tend to rely on printf's or just thinking really hard more often. Edit: looked it up, it's apparently called TUI mode More on reddit.com
๐ŸŒ r/C_Programming
79
87
February 9, 2022
Using gdb debugger in an efficient way
Dear all, Iโ€™m trying to use gdb debugger to debug an error related to Segmentation fault (core dumped) Unfortunately, this message happens frequently for many different types of errors, also completely not correlated (bad pointer definition, out of memory, etc.). With gdb debugger, I get ... More on geant4-forum.web.cern.ch
๐ŸŒ geant4-forum.web.cern.ch
1
November 24, 2021
๐ŸŒ
University of Toronto
cs.toronto.edu โ€บ ~krueger โ€บ csc209h โ€บ tut โ€บ gdb_tutorial.html
gdb tutorial
In order to run crash.c with gdb, we must compile it with the -g option which tells the compiler to embed debugging information for the debugger to use.
๐ŸŒ
Baylor
cs.baylor.edu โ€บ ~donahoo โ€บ tools โ€บ gdb โ€บ tutorial.html
How to Debug Using GDB
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.
๐ŸŒ
Kauffman77
kauffman77.github.io โ€บ tutorials โ€บ gdb.html
Quick Guide to gdb: The GNU Debugger
April 4, 2025 - Reading symbols from ./puzzlebox...done. (gdb) set args input.txt # set command line arguments to the input.txt (gdb) run # run the program Starting program: puzzlebox input.txt UserID 'kauf0095' accepted: hash value = 1397510491 # program output PHASE 1: A puzzle you say?
๐ŸŒ
Brendan Gregg
brendangregg.com โ€บ blog โ€บ 2016-08-09 โ€บ gdb-example-ncurses.html
gdb Debugging Full Example (Tutorial): ncurses
August 9, 2016 - Now to set the breakpoint using b (short for break): (gdb) b *doupdate + 289 No symbol table is loaded. Use the "file" command.
Find elsewhere
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
๐ŸŒ
QEMU
qemu-project.gitlab.io โ€บ qemu โ€บ system โ€บ gdb.html
GDB usage โ€” QEMU documentation
QEMU supports working with gdb ... examine state like registers and memory, and set breakpoints and watchpoints. In order to use gdb, launch QEMU with the -s and -S options....
๐ŸŒ
GNU Project
sourceware.org โ€บ gdb โ€บ current โ€บ onlinedocs โ€บ gdb.html โ€บ Starting.html
Starting (Debugging with GDB)
If a shell is available on your target, the shell is used to pass the arguments, so that you may use normal conventions (such as wildcard expansion or variable substitution) in describing the arguments. In Unix systems, you can control which shell is used with the SHELL environment variable. If you do not define SHELL, 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).
๐ŸŒ
BetterExplained
betterexplained.com โ€บ articles โ€บ debugging-with-gdb
Debugging with GDB โ€“ BetterExplained
Youโ€™ll see a prompt (gdb) โ€“ all examples are from this prompt. ... Three ways to run โ€œa.outโ€, loaded previously. You can run it directly (r), pass arguments (r arg1 arg2), or feed in a file. You will usually set breakpoints before running. ... List help topics (help) or get help on a specific topic (h breakpoints).
๐ŸŒ
Interrupt
interrupt.memfault.com โ€บ blog โ€บ advanced-gdb
Advanced GDB Usage | Interrupt
October 20, 2020 - Thereโ€™s no better place to start learning GDB than to first learn how to search the help menus. Surprisingly, or maybe unsurprisingly, GDB has over 1500+ commands! # Count number of GDB commands in the master help list $ gdb --batch -ex 'help all' | grep '\-\-' | wc 1512 16248 117306 ยท With this in mind, the most useful command within GDB is apropos, which searches all the โ€œhelpโ€ menus of each command.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ gnu_debugger โ€บ gdb_quick_guide.htm
GDB - Quick Guide
GDB allows you to run the program up to a certain point, then stop and print out the values of certain variables at that point, or step through the program one line at a time and print out the values of each variable after executing each line. GDB uses a simple command line interface.
๐ŸŒ
The Ohio State University
u.osu.edu โ€บ cstutorials โ€บ 2018 โ€บ 09 โ€บ 28 โ€บ how-to-debug-c-program-using-gdb-in-6-simple-steps
How to Debug C Program using gdb in 6 Simple Steps
September 28, 2018 - Note: The above command creates a.out file which will be used for debugging as shown below. Launch the C debugger (gdb) as shown below. ... Places break point in the C program, where you suspect errors. While executing the program, the debugger will stop at the break point, and gives you the prompt to debug.
๐ŸŒ
Geant4 Forum
geant4-forum.web.cern.ch โ€บ recording, visualizing and persisting data
Using gdb debugger in an efficient way - Recording, Visualizing and Persisting Data - Geant4 Forum
November 24, 2021 - Dear all, Iโ€™m trying to use gdb debugger to debug an error related to Segmentation fault (core dumped) Unfortunately, this message happens frequently for many different types of errors, also completely not correlated (bad pointer definition, out of memory, etc.). With gdb debugger, I get ...
๐ŸŒ
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
This starts the gdb debugger in interactive mode and displays the default prompt, (gdb). To quit the debugging session and return to the shell prompt, run the following command at any time: ... Copy to Clipboard Copied! ... Note that you can execute any command using the scl utility, causing it to be run with the Red Hat Developer Toolset binaries used in preference to the Red Hat Enterprise Linux system equivalent.
๐ŸŒ
NVIDIA
docs.nvidia.com โ€บ cuda โ€บ cuda-gdb โ€บ index.html
1. Introduction โ€” CUDA-GDB 13.1 documentation
CUDA-GDB supports debugging C/C++ and Fortran CUDA applications. Fortran debugging support is limited to 64-bit Linux operating system. CUDA-GDB allows the user to set breakpoints, to single-step CUDA applications, and also to inspect and modify the memory and variables of any given thread running on the hardware.