Lolpro Lab
📖 Tutorial

GDB's Experimental Source-Tracking Breakpoints Automatically Adapt to Code Changes

Last updated: 2026-05-01 12:48:23 Intermediate
Complete guide
Follow along with this comprehensive guide

Breaking News — A new experimental feature in the GNU Project Debugger (GDB) promises to revolutionize debugging workflows by allowing breakpoints to automatically adjust when source code is edited and recompiled. The feature, called source-tracking breakpoints, eliminates the tedious manual process of disabling and resetting breakpoints after each edit-compile cycle.

Traditional breakpoints are tied to fixed line numbers. When a developer edits source code and recompiles, those line numbers shift, rendering existing breakpoints useless. GDB's source-tracking feature captures a small window of surrounding source code when a breakpoint is set using file:line notation, and then automatically relocates the breakpoint after recompilation.

"This addresses a long-standing pain point in ad-hoc debugging sessions," said a GDB maintainer in a statement. "Developers can keep their debugging session running, edit and recompile, and GDB will update the breakpoints to the new line numbers without any manual intervention."

How Source-Tracking Breakpoints Work

To enable the feature, a developer must first turn it on with the command:

GDB's Experimental Source-Tracking Breakpoints Automatically Adapt to Code Changes
Source: fedoramagazine.org

(gdb) set breakpoint source-tracking enabled on

Then, setting a breakpoint using file:line triggers the tracking mechanism. For example:

(gdb) break myfile.c:42

GDB captures three lines of source code around the breakpoint. The `info breakpoints` command confirms whether the breakpoint is being 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)

After editing the source—say, adding lines above the breakpoint—and recompiling, GDB automatically resets the breakpoint to the new location:

Breakpoint 1 adjusted from line 42 to line 45.

Limitations and Warnings

While powerful, the feature has constraints. The matching algorithm requires an exact string match of the captured source lines. Whitespace-only changes or trivial reformatting can confuse the matcher, causing the breakpoint to remain at the old location.

GDB only searches within a 12-line window around the original breakpoint position. If code shifts by more than 12 lines—for example, due to a large block insertion—the breakpoint will not be found and a warning is printed:

GDB's Experimental Source-Tracking Breakpoints Automatically Adapt to Code Changes
Source: fedoramagazine.org

warning: Breakpoint 1 source code not found after reload, keeping original location.

Additionally, source context cannot be captured when a breakpoint is created in a pending state (e.g., with set breakpoint pending on), because no symbol table is available at that point.

Background

The ability to set breakpoints is a cornerstone of debugging. Traditionally, a developer sets breakpoints on source lines, inspects variables, and forms hypotheses about bugs. After editing and recompiling, the same breakpoints become misaligned because line numbers have shifted. GDB users have had to disable old breakpoints and create new ones—a repetitive and error-prone process.

Source-tracking breakpoints, introduced as an experimental feature in GDB 13.1, streamline this workflow by automating breakpoint relocation. The feature is especially beneficial in iterative development cycles where quick re-debugging is essential.

What This Means

This feature reduces friction in the debug-edit-recompile loop, potentially saving developers significant time during troubleshooting sessions. By eliminating manual breakpoint management, source-tracking breakpoints allow developers to maintain focus on the logic flow rather than on bookkeeping.

However, the experimental nature and current limitations—especially the strict matching requirement and limited search window—mean that developers should test the feature thoroughly in their specific workflows before relying on it. The GDB team welcomes feedback to refine the implementation.

For more details, refer to the How Source-Tracking Breakpoints Work and Limitations sections above.