Quick Facts
- Category: Programming
- Published: 2026-05-02 02:10:11
- 10 Critical Facts About the SAP npm Credential-Stealing Attack
- Anthropic’s Mythos AI: Autonomous Hacking Tool Sparks Urgent Cybersecurity Debate
- The Designer's Guide to Humility: 10 Core Insights for a Fulfilling Career
- How to Thrive Amid the Constant Evolution of Web Design and Development
- Mastering CSS Saturation: A Complete Guide to the saturate() Filter Function
Introduction
Debugging is a critical part of software development, and setting breakpoints is one of the most fundamental debugging operations. Traditionally, when you set a breakpoint at a specific line in your source code, that breakpoint remains fixed to that line number. If you edit your source code and recompile, the line numbers shift, rendering your existing breakpoints useless. You then have to manually disable old breakpoints and set new ones—a repetitive and time-consuming process, especially during iterative development.

The GNU Project Debugger (GDB) now offers an experimental feature called source-tracking breakpoints to address this problem. In this article, we explore how this feature works, how to enable it, its benefits, and its current limitations.
How Source-Tracking Breakpoints Work
When you enable source-tracking and set a breakpoint using file:line notation, GDB captures a small window of the surrounding source code—typically three lines around the breakpoint line. This snapshot is stored alongside the breakpoint metadata. Later, when you recompile your program and reload it in GDB (via the run command), GDB searches the new executable's source code for an exact match of the captured lines. If a match is found at a different line number, GDB adjusts the breakpoint to that new location automatically.
This matching process is designed to be lightweight and focused. GDB limits its search to a 12-line window around the original breakpoint location. This ensures that the adjustment is fast and avoids false matches across unrelated code sections.
Enabling the Feature
To activate source-tracking, use the following GDB command:
(gdb) set breakpoint source-tracking enabled onOnce enabled, any new breakpoint set with the file:line syntax will automatically be tracked. You can verify the tracking status using the info breakpoints command.
Setting a Source-Tracking Breakpoint
After enabling the feature, set a breakpoint as usual:
(gdb) break myfile.c:42
Breakpoint 1 at 0x401234: file myfile.c, line 42.Displaying the breakpoints will show that source-tracking is active:
(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)Example Walkthrough
Imagine you have a file myfile.c with a function calculate. You set a breakpoint at line 42. After editing the source to add a few lines of code above the breakpoint, the original breakpoint line shifts from 42 to 45. When you recompile and run the program again in GDB, you will see:
Breakpoint 1 adjusted from line 42 to line 45.Checking the breakpoints again confirms the update:
(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)The breakpoint now points to the correct line, allowing you to continue debugging without manual intervention.

Benefits
- Reduced manual overhead: No need to disable and recreate breakpoints after each edit-compile cycle.
- Faster iteration: Especially valuable in rapid debugging sessions where you experiment with code changes.
- Greater focus: You can stay in the same GDB session and concentrate on the logical flow rather than technical bookkeeping.
Limitations and Considerations
While powerful, source-tracking breakpoints have several limitations you should be aware of:
- Exact string matching: The algorithm requires an exact match of the captured source lines. Whitespace-only changes or trivial reformatting (e.g., changing indentation) will cause the match to fail.
- Limited search window: GDB only searches within a 12-line window around the original breakpoint location. If your code shift exceeds this range—for instance, due to inserting a large block above—the breakpoint will not be found. In that case, GDB keeps the original location and issues a warning:
warning: Breakpoint 1 source code not found after reload, keeping original location. - No support for pending breakpoints: Source context cannot be captured when a breakpoint is created in pending mode (e.g., with
set breakpoint pending on), because no symbol table is available yet.
Given these limitations, use source-tracking for small-to-medium edits. For major refactoring, it may be simpler to manually reset breakpoints.
Conclusion
GDB's source-tracking breakpoints represent a valuable step forward in debugging productivity. By automatically adjusting breakpoints to match changes in your source code, they eliminate a repetitive manual task and help maintain your debugging focus. Although the feature is experimental and has restrictions, it can significantly accelerate iterative development. Try enabling it in your next debugging session to see how it streamlines your workflow.