You can create a breakpoint at an offset from the current stopped position with gdb breakpoint +<offset>.

You can also create a breakpoint on a specific line number using either gdb break <linenumber> (for the current source file) or gdb break <filename>:<linenumber> (for a file other than the current file).

More details in the docs.

Answer from lsowen on Stack Overflow
🌐
GNU
ftp.gnu.org › old-gnu › Manuals › gdb › html_node › gdb_28.html
Debugging with GDB - Setting breakpoints
This rule applies whether or not the breakpoint already existed when your program stopped. ... Set a breakpoint with condition cond; evaluate the expression cond each time the breakpoint is reached, and stop only if the value is nonzero--that is, if cond evaluates as true.
🌐
University of Michigan
web.eecs.umich.edu › ~sugih › pointers › gdbQS.html
gdb QuickStart
To view other lines, just type "list [linenumber]", and gdb will print out the 20 or so lines around that line. gdb remembers what lines you have seen, so if you type "list" again it will print out the next bunch of lines. Setting breakpoints A breakpoint is like a stop sign in your code -- ...
🌐
Richard Johnsonbaugh
condor.depaul.edu › glancast › 373class › docs › gdb.html
Quick Gdb Guide
Run gdb on the printch program and set the number of source lines to list at a time to 28. hawk% gdb -xdb -tui printch GNU gdb 4.17.1 Copyright 1998 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License (gdb) set listsize 28 · Breakpoints are points in your code at which gdb will stop and allow executing other gdb commands.
🌐
GNU Project
sourceware.org › gdb › current › onlinedocs › gdb.html › Set-Breaks.html
Set Breaks (Debugging with GDB)
If the encountered breakpoint has only one code location, ‘$_hit_locno’ is set to 1: Breakpoint 1, main (argc=1, argv=0x7fffffffe018) at zeoes.c:24 24 if (argc > 1) (gdb) p $_hit_bpnum $3 = 1 (gdb) p $_hit_locno $4 = 1 (gdb) The ‘$_hit_bpnum’ and ‘$_hit_locno’ variables can typically be used in a breakpoint command list.
🌐
Reddit
reddit.com › r/cpp_questions › can't set breakpoint in gdb
r/cpp_questions on Reddit: Can't set breakpoint in GDB
March 26, 2024 -

In my CMake project I have executable with Google tests.

I compile my project with flag "-g". When I try to set breakpoint in GDB on specific line of file with tests

b 392

I get error "No line 392 in the current file.". This line really exists in the target file.

What can be the cause of this problem?

🌐
Reddit
reddit.com › r/embedded › how should i add breakpoint in asm with gdb ?
r/embedded on Reddit: How should I add breakpoint in ASM with GDB ?
August 29, 2024 -

Is it possible to add breakpoint in an asm file using line number in GDB, like we can do with C files using b main.c:30 ? I know that we can add breakpoint using instruction bkpt or using the instruction address like b *0x08000000 , are there any other way to add breakpoint in asm code?

🌐
Llvm-gcc-renesas
llvm-gcc-renesas.com › question › gdb-breakpoint-set-programmatically
Can a GDB breakpoint be set programmatically? | Open Source Tools for Renesas
July 17, 2024 - Does anyone have an example of setting this up? Open Source Tools Support - Thu, Jul 18, 2024, 8:50:39 UTC ... rx-elf-gdb a.out -ex “target sim” -ex “load” -ex “br abort” -ex “run” -ex “bt” -ex “c” -ex “bt” ... After creating the executable from the source file, we launch a debug session and insert a breakpoint into the abort() function.
Find elsewhere
🌐
PyTorch Forums
discuss.pytorch.org › t › gdb-usage-setting-more-breakpoints-whilst-running › 146233
Gdb usage: setting more breakpoints whilst running - PyTorch Forums
December 15, 2021 - Following https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md#gdb-integration I am able to hit a break point. Executing import torch runs for 10s of seconds. If I Ctrl-c to stop execution; I have to re-impo…
🌐
Medium
slava-moskvin.medium.com › gdb-tutorial-for-reverse-engineers-breakpoints-modifying-memory-and-printing-its-contents-46280ac37aad
GDB Tutorial for Reverse Engineers: Breakpoints, Modifying Memory and Printing its Contents | by Path Cybersec [Slava Moskvin] | Medium
April 8, 2021 - To open a file in GDB, type gdb [filename] in the console. GDB will open and load your file. Notice, that code execution hasn’t started. That’s because there’s a separate command to start the execution, it’s called run, or r for short. ... And if we start it, our program successfully completes execution. That’s because we haven’t set any breakpoints yet.
🌐
MIT
web.mit.edu › gnu › doc › html › gdb_7.html
Debugging with GDB - Stopping and Continuing
This rule applies whether or not the breakpoint already existed when your program stopped. ... Set a breakpoint with condition cond; evaluate the expression cond each time the breakpoint is reached, and stop only if the value is nonzero--that is, if cond evaluates as true.
🌐
Apple Developer
developer.apple.com › library › archive › documentation › DeveloperTools › gdb › gdb › gdb_6.html
Debugging with gdb - Stopping and Continuing
A breakpoint range is either a single breakpoint number, like `5', or two such numbers, in increasing order, separated by a hyphen, like `5-7'. When a breakpoint range is given to a command, all breakpoint in that range are operated on. Breakpoints are set with the break command (abbreviated b).
🌐
VisualGDB
visualgdb.com › gdbreference › commands › break
GDB Command Reference - break command
When specified together with a line number, the break command will set a breakpoint at a given line inside the file.
🌐
Rust Programming Language
users.rust-lang.org › help
Debugging with gdb, setting a breakpoint in main() - help - The Rust Programming Language Forum
April 13, 2018 - So I'm trying to do some debugging with gdb and noticed that setting my breakpoint at main() seems to be ignored by the debugger, it just goes ahead and executes the whole program when I give gdb the run command. I did some research and apparently this is caused by Rust having a different main() ...
🌐
Kauffman77
kauffman77.github.io › tutorials › gdb.html
Quick Guide to gdb: The GNU Debugger
April 4, 2025 - Breakpoint 1, phase01 () at puzzlebox.c:220 # hit breakpoint again 220 int a = atoi(next_input()); (gdb) info break # show info about which breakpoints are active Num Type Disp Enb Address What 1 breakpoint keep y 0x000055555555551a in phase01 at puzzlebox.c:220 breakpoint already hit 1 time (gdb) break puzzlebox.c:225 # don't feel like stepping: set a breakpoint some lines ahead Breakpoint 2 at 0x555555555583: file puzzlebox.c, line 225.
🌐
YouTube
youtube.com › watch
GDB Debugging - GDB Quickstart : Breakpoints and Printing ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
Unknownroad
unknownroad.com › rtfm › gdbtut › gdbbreak.html
RMS's gdb Tutorial: How do I use breakpoints?
Breakpoints are a way of telling gdb that you want it to stop your program at certain lines of code. You can also have it stop when your program makes specific function calls. Once the program is stopped, you can poke around in memory and see what the values of all your variables are, examine ...
🌐
Qnx
qnx.com › developers › docs › qnxcar2 › topic › com.qnx.doc.neutrino.prog › topic › using_gdb_SettingBreakpoints.html
Setting breakpoints
QNX Neutrino OS Guides > Programmer's Guide > Using GDB > Stopping and continuing > Breakpoints, watchpoints, and exceptions · Use the break (b) command to set breakpoints.
🌐
University of Rochester
cs.rochester.edu › u › nelson › courses › csc_173 › review › gdb.html
Debugging Programs with GDB
break function-name will set a breakpoint at the start of the function. You can set multiple breakpoints. (gdb) break InitArrays Breakpoint 1 at 0x2298: file gdbprog.cc, line 10.