One of the main abilities of a debugger is setting breakpoints.
GDB: The GNU Project Debugger now introduces an experimental feature
called source-tracking breakpoints that tracks the source line a breakpoint
was set to.
Introduction
Imagine you are debugging: you set breakpoints on a bunch of
source lines, inspect some values, and get ideas about how to change your
code. You edit the source and recompile, but keep your GDB session running
and type run to reload the newly compiled executable. Because you changed
the source, the breakpoint line numbers shifted. Right now, you have to
disable the existing breakpoints and set new ones.
GDB source-tracking breakpoints change this situation. When you set a
breakpoint using file:line notation, when this feature is enabled, GDB
captures a small window of the surrounding source code. When you recompile
and reload the executable, GDB adjusts any breakpoints whose lines shifted
due to source changes. This is especially helpful in ad-hoc debug sessions
where you want to keep debugging without manually resetting breakpoints
after each edit-compile cycle.
Setting a source-tracking breakpoint
To enable the source-tracking feature, run:
(gdb) set breakpoint source-tracking enabled on
Set a breakpoint using file:line notation:
(gdb) break myfile.c:42
Breakpoint 1 at 0x401234: file myfile.c, line 42.
GDB now tracks the source around this line. The info breakpoints command
shows whether a breakpoint is tracked:
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000401234 in calculate at myfile.c:42
source-tracking enabled (tracking 3 lines around line 42)
Now edit the source — say a few lines are added above the breakpoint,
shifting it from line 42 to line 45. After recompiling and reloading the
executable with run, GDB resets the breakpoint to the new line and displays:
Breakpoint 1 adjusted from line 42 to line 45.
Run info breakpoints again to confirm the new location:
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000401256 in calculate at myfile.c:45
source-tracking enabled (tracking 3 lines around line 45)
As you can see, GDB updated the breakpoint line to match the new location.
Limitations
The matching algorithm requires an exact string match of the captured source
lines. Whitespace-only changes or trivial reformatting of the tracked lines
will confuse the matcher and may cause the breakpoint not to be found.
GDB only searches within a 12-line window around the original location. If
the code shifted by more than that — for example, because a large block was
inserted above — the breakpoint will not be found. GDB will keep the
original location and print a warning:
warning: Breakpoint 1 source code not found after reload, keeping original
location.
Source context cannot be captured when a breakpoint is created pending
(e.g., with set breakpoint pending on), because no symbol table is available
yet. When the breakpoint later resolves to a location, it will not be
source-tracked.
Source tracking is not supported for ranged breakpoints (set with
break-range).
Breakpoints on inline functions that expand to multiple locations are not
source-tracked, as each location may have moved differently.
How to try this experimental feature
This feature is not yet available in a stable GDB release. There are two
ways to try it.
Install from COPR (for Fedora users)
A pre-built package is available through a COPR repository. Enable it and
install:
sudo dnf copr enable ahajkova/GDB-source-tracking-breakpoints
sudo dnf upgrade gdb
To disable the repository again after testing:
sudo dnf copr disable ahajkova/GDB-source-tracking-breakpoints
The COPR project page is at:
https://copr.fedorainfracloud.org/coprs/ahajkova/GDB-source-tracking-breakpo
ints/
Build from source
- Clone the GDB repository:
git clone git://sourceware.org/git/binutils-gdb.git
cd binutils-gdb - Download and apply the patch from the upstream mailing list:
https://sourceware.org/pipermail/gdb-patches/2026-April/226349.html - Build GDB:
mkdir build && cd build
../configure --prefix=/usr/local
make -j$(nproc) all-gdb - Run the newly built GDB:
./gdb/gdb
Conclusion
GDB source-tracking breakpoints are an experimental feature currently under
upstream review and not yet available in a stable GDB release. This link
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Set-Breaks.html
covers all available breakpoint commands. If you try this feature out and
hit any kind of unexpected behavior, feedback is very welcome — you can
follow and respond to the upstream patch discussion on the GDB mailing list
at https://sourceware.org/pipermail/gdb-patches/2026-April/226349.html


Find more information here:
Deadline: 15th May 2026

comments? additions? reactions?
As always, comment on mastodon: https://fosstodon.org/@nirik/116392979078747195