From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QrkoLnHBdWrskRAAWB0awg (envelope-from ) for ; Fri, 07 Aug 2026 07:28:49 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=pNEXnCVr; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id ADE2C1E09B; Fri, 07 Aug 2026 07:28:49 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A86DC1E09B for ; Fri, 07 Aug 2026 07:28:48 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 359604BAE7CD for ; Fri, 7 Aug 2026 11:28:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 359604BAE7CD Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=pNEXnCVr Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 9F5864BAE7C6 for ; Fri, 7 Aug 2026 11:28:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F5864BAE7C6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9F5864BAE7C6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786102103; cv=none; b=Tl28mSGiGjDQSdcyauo3lUM0MKWsfDNwWpDLTtplsOiY+k3Z9THGxAzBnZn9234pBDjg11sJ0C9Wl6FHFr58+OEfcuMZIKeE1+3OvhB+tEHcl8xELDChlFxcmj0JQkFSoeiF6vJ1gG1GSDr3Mw+dW10qR6O1Lb9FskOd07ZuTd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786102103; c=relaxed/simple; bh=N7j/LiWOqhiieoekC7dRWUZO5trRm2GuFIkpVHax8jE=; h=DKIM-Signature:Date:Message-Id:From:To:Subject:MIME-version; b=Y+aT7YJhGJAx7XuoUVyljhThE6kUSD0/nj9TRUl8ENM2bVoa5yp5SSKBTifzDhyYI9Jt/RQVW5u70X6pEsISxdxTCHHAGpuND1aVYD4KZRGnR2RAmmUb1jAKJUIf0kQ0QQ0C2zHA4NHb50ReiousbrsKJZZlxMdwyPEmcxAzSMQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=pNEXnCVr DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F5864BAE7C6 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wsIkR-0001VP-3R; Fri, 07 Aug 2026 07:28:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=fLJ+NPh4rB+1H0TeqftgW1lNY+ybNjgIx77kv9OfyXo=; b=pNEXnCVrHSy3iTi8mqP1 5aAcqCdBTEzX+sv65GKClNpMJG+pCcmjwO4w+AYKSf07JAWULTraSBBmdQQL0h/CIudS+ULLWowCS UkuL3rvCLWg0G5xPds/t1db+bSgv6V3qSpxiGq+ndRrcSuAylMu37dc8vUMxzr6njjajrlGIvdZJ1 +Lymm1W5pDQN6DnuxUjB2c3c8nGVRWKY+0FUmBt0+9aPl6+OKBZeuyg7jFcDbE3tO0AId/zdDt0oA wpfxqM11lmOLkev1OdnXOLnITL6J06v+wsDq8KaWvzt2PC0s8bptCWwfk07RAa0I3DDKQtfiHx8rO LTeEPNKTZ9KS9w==; Date: Fri, 07 Aug 2026 14:28:19 +0300 Message-Id: <86o6fe41bg.fsf@gnu.org> From: Eli Zaretskii To: Alexandra =?utf-8?B?SMOhamtvdsOh?= Cc: gdb-patches@sourceware.org In-Reply-To: <20260807104848.497790-1-ahajkova@redhat.com> (message from Alexandra =?utf-8?B?SMOhamtvdsOh?= on Fri, 7 Aug 2026 12:46:37 +0200) Subject: Re: [PATCH v9] gdb: Add source-tracking breakpoints feature References: <20260807104848.497790-1-ahajkova@redhat.com> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org > From: Alexandra Hájková > Cc: ahajkova@redhat.com > Date: Fri, 7 Aug 2026 12:46:37 +0200 > > When we rerun the executable after changing its source files, > GDB would re-set all previously set breakpoints. The > breakpoints set to the function names would remain at their initial > locations. But the breakpoints which used filename:line notation would > be silently shifted following the source code changes. > > To address this, GDB now optionally captures a small window of source > code lines around each breakpoint set with filename:line notation, > when it is first set. When the binary is reloaded, GDB detects the BFD > change and tries to locate the same source context in the new file, > and if successful, re-sets the breakpoint to the matched source code > line. > > The breakpoint_source structure stores captured source code lines > around a breakpoint location, along with a reference to the BFD > that was current when the source was captured. > > When source tracking is enabled (via 'set breakpoint source-tracking > enabled on'), GDB captures 3 lines of source context > (BREAKPOINT_SRC_CTX_LINES) along with the current BFD when a > breakpoint is first set. On executable reload (detected by comparing > BFDs), it searches within a 12-line window > (BREAKPOINT_SRC_CTX_LINES * BREAKPOINT_SRC_SEARCH_MULTIPLIER) for > the best match and adjusts the breakpoint location if needed. > > If source tracking is disabled after breakpoints have been tracked, > all existing source tracking information is discarded and a message > is printed. > > Tests added: > gdb.base/adjust_breakpoint.exp > gdb.base/adjust_breakpoint-missing-source.exp > gdb.base/source-tracking-inline.exp > gdb.base/test_source_tracking.exp > > adjust_breakpoint.exp covers four scenarios: > - adjust the breakpoint when lines are deleted > - adjust the breakpoint when lines are inserted > - the tracked line disappears entirely > - verify the tracking can be disabled > > adjust_breakpoint-missing-source.exp covers the edge case where source > files are unavailable, verifying GDB falls back to non-tracking breakpoints. > > source-tracking-inline.exp covers source tracking with inline functions. > > test_source_tracking.exp verifies that source context is correctly captured > when the breakpoint is on the last line of the file. > > Add maintenance command to print tracked source code. > Add documentation for the new source-tracking breakpoints feature. > > Limitations of the current implementation: > > Source tracking is not enabled for pending breakpoints that become > non-pending. When a breakpoint is created pending (e.g. with 'set > breakpoint pending on'), source context is not captured at creation > time since no symtab is available yet. When the breakpoint later > resolves to a location, re_set_default() only updates existing tracked > breakpoints and does not initiate tracking for newly resolved ones. > This could be fixed in the future by initiating source tracking in > re_set_default() when a breakpoint transitions from pending to > non-pending. > > Source tracking for ranged breakpoints is not currently supported. > Ranged breakpoints have a start and end location spec, and tracking > both independently raises questions about whether to preserve the > range length or track each end separately. For now, ranged > breakpoints will never be source-tracked. > > Reviewed-By: Eli Zaretskii > --- > > v9: > - Add test_source_tracking.exp description to commit message. > - Use plongest instead of pulongest for signed line_num. > - Use error() instead of gdb_printf for non-tracked breakpoints in > maintenance_info_source_tracking_context, matching documentation. > - Discard empty breakpoint_source with bp_source.reset() when > source capture fails. > - Replace non-ASCII em-dashes with ASCII dashes in comments. > - Move trailing comment before set_string("") to its own line. > - Fix tab indentation on warning continuation line. > - Remove trailing blank lines from test files. > - Add maintenance info source-tracking-context to NEWS. > - Generalize sliding_window_match to compare all captured context > lines instead of only the immediate neighbors, so the matching > scales with BREAKPOINT_SRC_CTX_LINES. > - Use a best-match scoring approach: for each candidate where the > breakpoint line matches, count how many context lines also match > and select the highest-scoring position. > - Require a majority of context lines to match before accepting, > reducing false positives on common lines like "return 0;". > - Update function comment and texinfo documentation to describe > the new algorithm. > > gdb/NEWS | 17 + > gdb/breakpoint.c | 486 ++++++++++++++++++ > gdb/breakpoint.h | 15 + > gdb/doc/gdb.texinfo | 44 ++ > .../gdb.base/adjust_breakpoint-2.cpp | 39 ++ > .../gdb.base/adjust_breakpoint-3.cpp | 41 ++ > .../gdb.base/adjust_breakpoint-4.cpp | 37 ++ > .../adjust_breakpoint-missing-source.exp | 55 ++ > gdb/testsuite/gdb.base/adjust_breakpoint.cpp | 40 ++ > gdb/testsuite/gdb.base/adjust_breakpoint.exp | 167 ++++++ > .../gdb.base/source-tracking-inline-1.c | 50 ++ > .../gdb.base/source-tracking-inline-2.c | 49 ++ > .../gdb.base/source-tracking-inline.exp | 80 +++ > gdb/testsuite/gdb.base/test_source_tracking.c | 18 + > .../gdb.base/test_source_tracking.exp | 42 ++ > 15 files changed, 1180 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/adjust_breakpoint-2.cpp > create mode 100644 gdb/testsuite/gdb.base/adjust_breakpoint-3.cpp > create mode 100644 gdb/testsuite/gdb.base/adjust_breakpoint-4.cpp > create mode 100644 gdb/testsuite/gdb.base/adjust_breakpoint-missing-source.exp > create mode 100644 gdb/testsuite/gdb.base/adjust_breakpoint.cpp > create mode 100644 gdb/testsuite/gdb.base/adjust_breakpoint.exp > create mode 100644 gdb/testsuite/gdb.base/source-tracking-inline-1.c > create mode 100644 gdb/testsuite/gdb.base/source-tracking-inline-2.c > create mode 100644 gdb/testsuite/gdb.base/source-tracking-inline.exp > create mode 100644 gdb/testsuite/gdb.base/test_source_tracking.c > create mode 100644 gdb/testsuite/gdb.base/test_source_tracking.exp Thanks, the documentation parts are okay. Reviewed-By: Eli Zaretskii