Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Cc: "Alexandra Hájková" <ahajkova@redhat.com>
Subject: Re: [PATCH v12] gdb: Add source-tracking breakpoints feature
Date: Sat, 19 Sep 2026 10:49:52 -0700	[thread overview]
Message-ID: <20260919104952.156363c6@f44-mesa-1> (raw)
In-Reply-To: <20260918114906.37069-1-ahajkova@redhat.com>

Hi Sasha,

I had my AI driven code review tool look for changes that you might
have missed making from earlier reviews.  It found two...

On Fri, 18 Sep 2026 13:49:06 +0200
Alexandra Hájková <ahajkova@redhat.com> wrote:

> +  std::string line;
> +  scoped_restore restore_styling = make_scoped_restore (&source_styling, false);
> +  if (!g_source_cache.get_source_lines (expanded[0].symtab,
> +					expanded[0].line,
> +					expanded[0].line, &line))
> +    {
> +      /* Source is unreadable after reload - drop tracking.  */
> +      bp_source.reset ();
> +      warning (_("could not re-capture source lines, "
> +		 "breakpoint %d no longer source tracked"),
> +	       number);
> +      return;
> +    }
> +
> +  if (line == bp_source->source_lines[bp_source->bp_line_stored])
> +    {
> +      /* Line unchanged - just refresh the capture with the new BFD.  */
> +      bp_source = std::make_unique<breakpoint_source>
> +	(breakpoint_source_capture (expanded, BREAKPOINT_SRC_CTX_LINES));
> +      return;
> +    }

Back in his review of your v11 patch, Andrew wrote:

    This call to breakpoint_source_capture could, in theory, fail, though I
    don't know why it ever would.  But still, you should handle this case
    like you do all the other breakpoint_source_capture calls:

      if (!breakpoint_source_is_tracked (b->bp_source.get ()))
	{
	  warning (_("unable to refresh source tracking for breakpoint %d, "
		     "source tracking disabled"),
		   number);
	  b->bp_source.reset ();
	}

This still needs to be done.

[...]

> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 0bb0a46738f..635509f5409 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -4661,6 +4661,27 @@ program.
>  On some systems, you can set breakpoints in shared libraries before
>  the executable is run.
>  
> +@cindex source-tracking breakpoints
> +@cindex breakpoints, automatic adjustment when source changes
> +@value{GDBN} supports @dfn{source-tracking breakpoints}, which
> +automatically adjust their location when source code changes between
> +recompilations.  When enabled with @kbd{set breakpoint source-tracking
> +enabled on}, breakpoints set by file and line number capture a small
> +window of surrounding source lines centered on the breakpoint line.
> +If the source file is modified and the executable is rebuilt,
> +@value{GDBN} searches a window of approximately 12 lines centered on the
> +breakpoint's original position for the best match.  For each candidate
> +line that matches the original breakpoint line, @value{GDBN} compares
> +all captured context lines at their corresponding offsets and scores the
> +match by how many lines agree.  The candidate with the highest score is
> +selected, provided a majority of the context lines match, reducing false
> +positives from short or repeated lines.  If no match meets the threshold,
> +@value{GDBN} issues a warning and keeps the breakpoint at its original
> +location, disabling source tracking for that breakpoint.  Note that
> +breakpoints set by function name or address are not affected by source
> +tracking.
> +@xref{Set Breaks}.
> +
>  @cindex watchpoints
>  @cindex data breakpoints
>  @cindex memory tracing
> @@ -42092,6 +42113,13 @@ Shared library events.
>  
>  @end table
>  
> +@kindex maint info source-tracking-context
> +@item maint info source-tracking-context @var{num}
> +For source-tracking breakpoints (@pxref{Breakpoints}), print the
> +tracked source code context for breakpoint @var{num}.  If breakpoint
> +@var{num} is not source tracked, or @var{num} is not a valid
> +breakpoint number, then the command gives an error.
> +
>  @kindex maint info btrace
>  @item maint info btrace
>  Pint information about raw branch tracing data.
> @@ -42960,6 +42988,22 @@ Control whether to show all non zero areas within a 1k block starting
>  at thread local base, when using the @samp{info w32 thread-information-block}
>  command.
>  
> +@kindex set breakpoint source-tracking enabled
> +@kindex show breakpoint source-tracking enabled
> +@item set breakpoint source-tracking enabled @r{[}on@r{|}off@r{]}
> +@itemx show breakpoint source-tracking enabled
> +Control whether to enable source-tracking for breakpoints set by file and
> +line number.  Use @code{on} to enable, @code{off} to disable.  When
> +enabled, @value{GDBN} captures a window of source lines around each
> +new file:line breakpoint and uses it to relocate the breakpoint if the
> +source is modified and the executable is rebuilt.  @xref{Breakpoints},
> +for a full description of the matching algorithm and its limitations.
> +The default is @code{off}.  Breakpoints set by function name or address
> +are not affected by this setting.
> +
> +If this setting is changed from @samp{on} to @samp{off}, then any
> +existing source tracking information will be discarded.
> +

In v8, Eli asked you to update the manual mentioning the preconditions
for this new feature to work.  You might just say something like this:

  Source tracking requires that source files be accessible and that the
  executable contain line-number debug information.

Kevin


      parent reply	other threads:[~2026-09-19 17:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 11:49 Alexandra Hájková
2026-09-18 14:20 ` Andrew Burgess
2026-09-19 17:49 ` Kevin Buettner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260919104952.156363c6@f44-mesa-1 \
    --to=kevinb@redhat.com \
    --cc=ahajkova@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox