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
🌐
GNU Project
sourceware.org › gdb › current › onlinedocs › gdb.html › Continuing-and-Stepping.html
Continuing and Stepping (Debugging with GDB)
A typical technique for using stepping is to set a breakpoint (see Breakpoints; Watchpoints; and Catchpoints) at the beginning of the function or the section of your program where a problem is believed to lie, run your program until it stops at that breakpoint, and then step through the suspect area, examining the variables that are interesting, until you see the problem happen. ... Continue running your program until control reaches a different source line, then stop it and return control to GDB.
Discussions

Can gdb step in a root function?
Hi, I’m trying to use gdb to debug my code. In my program, I have: chain->Process(my_work_code, “”, nentries); I can’t step in this function, i.e, my_work_code, which I get using “MakeSelector()”. Do you know what I can do in oder to step in my_work_code? Thanks very much. More on root-forum.cern.ch
🌐 root-forum.cern.ch
0
May 16, 2010
Can't see the source code of my assembly program with GDB
Try adding -g to your NASM command. This worked for me: hello.s: global hello hello: lea rax, [rel .msg] ret .msg: db "hello world", 0 main.c: #include char *hello(void); int main(void) { puts(hello()); } Results: $ nasm -g -felf64 hello.s $ gcc -g3 main.c hello.o $ gdb ./a.out Reading symbols from ./a.out... gdb> b hello Breakpoint 1 at 0x1160: file hello.s, line 2. gdb> r Starting program: /tmp/a.out Breakpoint 1, hello () at hello.s:2 2 hello: lea rax, [rel .msg] gdb> list 1 global hello 2 hello: lea rax, [rel .msg] 3 ret 4 .msg: db "hello world", 0 More on reddit.com
🌐 r/asm
4
4
October 5, 2022
The only proper way to debug 16-bit code on Qemu+GDB
Hi, As many know, it is quite laborious to use Qemu to debug 16-bit code in GDB, for a number of reasons, such as GDB not correctly identifying the architecture, problems with segmented memory (which make GDB read wrong portions of memory) and etc... Instead of going the 'traditional' route of writing yet another gdb script, I tried patching Qemu's source code to deliver a more consistent state to GDB. What I managed to do: Qemu now hands GDB the physical addresses of EIP and ESP, so GDB actually knows how to read from these memory locations. Qemu delivers the correct architecture to GDB at the time of attachment, whether 16-bit real mode or 32-bit protected mode, which eliminates the need for juggling with target XML files. What I couldn't do: GDB still does not notice the 'architecture' change when the code jumps from real to protected mode and vice versa and requires the user to manually set the current architecture, via set architecture (but still eliminates the use of XMLs) Overall I'm happy with the results, the patch itself is quite small and should bring a smoother experience for those who want to debug code completely in real mode and without the need for gdb scripts. For a better experience, GDB's RSP protocol should undergo changes, such as supporting 'architecture switching' at run time. More on reddit.com
🌐 r/osdev
8
12
October 9, 2023
gdb: How to stepi right through the end of main

What do you mean by "starts stepping before main" and about stepping after the end of main?

More on reddit.com
🌐 r/AskProgramming
10
14
September 29, 2021
🌐
Stony Brook University
www3.cs.stonybrook.edu › ~ezk › cse376-s21 › handouts › gdb.pdf pdf
How to Use GDB - Stony Brook CS
February 15, 2021 - To take this class, you must come to the first (real) lecture and fill out the online survey google form · Quick Links: Course Calendar Subscribe to Class Piazza Forum News: Class Time and Location Days: Monday and Wednesday Hours: 6:05pm–7:25pm Location: Online (you've been invited to the ...
🌐
Its Linux FOSS
itslinuxfoss.com › home › how to step into, step-over, and step-out with gdb?
How to Step Into, Step-over, and Step-out With GDB? – Its Linux FOSS
March 11, 2023 - To step into, step over, and step out with GDB, use the “step”, “next”, and “finish” commands. These GDB commands quickly identify and fix bugs in the program.
🌐
University of Waterloo
ece.uwaterloo.ca › ~ece250 › Projects › Debugging › indexsu5.html
Continuing execution using ‘step’, ‘finish’, and ‘next’ commands
Once the execution is paused one a line, one can execute the current line and step into the next line using step command. If there is a function ahead, the GDB jumps into the function and executes the first line of it.
🌐
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.
Find elsewhere
🌐
CERN
root-forum.cern.ch › t › can-gdb-step-in-a-root-function › 10166
Can gdb step in a root function? - ROOT - ROOT Forum
May 16, 2010 - Hi, I'm trying to use gdb to debug my code. In my program, I have: chain->Process(my_work_code, "", nentries); I can't step in this function, i.e, my_work_code, which I get using "MakeSelector()". Do you know what I can …
🌐
Apple Developer
developer.apple.com › library › archive › documentation › DeveloperTools › gdb › gdb › gdb_6.html
Debugging with gdb - Stopping and Continuing
Continuing means resuming program execution until your program completes normally. In contrast, stepping means executing just one more "step" of your program, where "step" may mean either one line of source code, or one machine instruction (depending on what particular command you use).
🌐
University of Michigan
web.eecs.umich.edu › ~sugih › pointers › gdbQS.html
gdb QuickStart
To execute one line of code, type "step" or "s". If the line to be executed is a function call, gdb will step into that function and start executing its code one line at a time. If you want to execute the entire function with one keypress, type "next" or "n".
🌐
GNU Project
sourceware.org › gdb › current › onlinedocs › gdb.html › Reverse-Execution.html
Reverse Execution (Debugging with GDB)
GDB will perform all execution commands in reverse, until the exec-direction mode is changed to “forward”. Affected commands include step, stepi, next, nexti, continue, and finish.
🌐
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.
🌐
Kauffman77
kauffman77.github.io › tutorials › gdb.html
Quick Guide to gdb: The GNU Debugger
April 4, 2025 - If a negative number is specified, ... is following last thing printed with this command or "print". (gdb) help step step, s Step program until it reaches a different source line....
🌐
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.
🌐
GNU Project
sourceware.org › gdb › current › onlinedocs › gdb
Debugging with GDB
It starts with a command name, which is followed by arguments whose meaning depends on the command name. For example, the command step accepts an argument which is the number of times to step, as in ‘step 5’. You can also use the step command with no arguments.
🌐
AdaCore
adacore.com › blog › gem-120-gdb-scripting-part-2
Gem #120 : GDB Scripting — Part 2 | AdaCore
March 12, 2012 - When you're debugging a running process, it's often desirable to get an overall view of the process context, and do this for each step in the program. The useful process-context commands you have created so far can be called automatically each time you break when debugging your program. For this, you can use a GDB-specific macro called hook-stop.
🌐
University of Washington
courses.cs.washington.edu › courses › cse351 › 17au › sections › 04 › cse351-sec4-au17.pdf pdf
CSE 351 Section 4 – GDB and x86‐64 Assembly
4ሻ Inside of GDB, use the run command ሺrun or just rሻ to execute your program. By default, this will continue until · an error or breakpoint is encountered or your program exits. a. Command‐line arguments can be passed as additional arguments to run: ... b. To step through the program starting at main() instead, use the start command ሺstart or just staሻ:
🌐
GNU
ftp.gnu.org › old-gnu › Manuals › gdb › html_node › gdb_37.html
Debugging with GDB - Continuing and Stepping
A typical technique for using stepping is to set a breakpoint (see section Breakpoints, watchpoints, and catchpoints) at the beginning of the function or the section of your program where a problem is believed to lie, run your program until it stops at that breakpoint, and then step through the suspect area, examining the variables that are interesting, until you see the problem happen. ... Continue running your program until control reaches a different source line, then stop it and return control to GDB.
🌐
Linux Hint
linuxhint.com › step-into-over-function-gdb
How to Step Into or Over a Function in GDB – Linux Hint
You can also step into the function and work on it using the step or s command. For example, to enter the loopMe() function, we can do: ... Now that we are inside the loopMe() function, we can go through it line by line using the next command: As you can see, we run through the loop and see ...
🌐
Jakubholy
jakubholy.net › unix › gdb.html
GDB Tutorial
Provides a brief description of a GDB command or topic. Plain help lists the possible topics ... Like step, however, if the current line of the program contains a function call, it executes the function and stops at the next line.
🌐
Lyngvaer
lyngvaer.no › log › stepping-with-gdb
Stepping with gdb
[...] 0x000deadbeef in strlen () from /lib/your/libc.so.6 (gdb) # so obviously this program had a segfault, better check the backtrace (gdb) bt #0 0x00007ffff7aba646 in strlen () from /lib/your/libc.so.6 #1 0x00007ffff7aa2f72 in puts () from /lib/your/libc.so.6 #2 0x00005555555546df in main (argc=1, argv=0x7fffffffc9e8)at test.c:14 (gdb) q A debugging session is active. Inferior 1 [process 4387] will be killed. Quit anyway? (y or n) okay so, in this simple example, the problem is obvious, but the same logic applies to other larger programs. you can step through until you find a problem, or you can run it, check the backtrace, and set the breakpoint at the first function where the problem occurs.