From patchwork Thu Oct 1 10:28:47 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Metzger X-Patchwork-Id: 145088 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B8DC4BB5913 for ; Thu, 1 Oct 2026 10:30:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B8DC4BB5913 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=aU9uN8XW X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by sourceware.org (Postfix) with ESMTPS id C27734BB590D for ; Thu, 1 Oct 2026 10:29:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C27734BB590D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C27734BB590D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790850553; cv=none; b=KAt+rGgqrIFqSBB1T+Qmn2AfdHoODXuR9oe3nuk3NftLQjfg4ZHouBY/itLL5lev7cYoH0TgB77vnf6WMfw7sCfNafwLP+t9xYepPynWj99NRpyu1jxP0TfNo1Na0n7G58WA3OHK2ZNV6Bmwk3xQhfAydOETbOBByyx2xJR8dgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790850553; c=relaxed/simple; bh=bhqee7yMcgtORE6kUMv02HRToOpMIOE1fTH21b/eecU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FpQeVvit9yqC8FYDvsa9ylGlYqley3jaPHLu5XrSNSq4xaA3r8hnPSns8EabhrEf45b/NP3yZDN4bxTFoktD82hU4tFVo4wTRSCp9CCa8lQbYewrCQ/RFMiXqgQklGOp/TO9/Ymnnlbb4aJ482gpcS9Lp3/NXA57RANEXkk4VrY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=aU9uN8XW DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C27734BB590D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790850553; x=1822386553; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=bhqee7yMcgtORE6kUMv02HRToOpMIOE1fTH21b/eecU=; b=aU9uN8XWHo0fbM/iamWIbSSEhnkCIeVgFhj1TyuJjn5Zzo+SX3uoD+Kn Jhjr4jsLz1HKGcIEkrnRYTGpKapEyC8gEm4qDT796I4gP84Lbj1oXAx4J R53xyf+2iqmLuil4+NyRnRUHmDzLKSPnsdq5WWv9XTLq5rN+JjIt2bdfL OusiQDTN93eS08lZ6KNChNCreJDVm2s0H48NJg+y4jf4NeP1xHEMmY2nG o27qBkVSvju0F4+kLOvXIQjOqB3kH10J9Vy407Dgbdjjmlr9xxOtPpsLS OHxr8C8U7GdqzEsmNxldHomY1cRKYTowfV9B3GCPOyI60JrpE+lbhiumk A==; X-CSE-ConnectionGUID: ZeN53woITymP/I/q9eOu5g== X-CSE-MsgGUID: RzZ8/LfHTQ60bBOqqIHYvA== X-IronPort-AV: E=McAfee;i="6800,10657,11921"; a="91619654" X-IronPort-AV: E=Sophos;i="6.27,134,1787036400"; d="scan'208";a="91619654" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2026 03:29:13 -0700 X-CSE-ConnectionGUID: Seo3lOHlRMiwaUiqqkVmjA== X-CSE-MsgGUID: haweTeIhQBigpPefjUWHpQ== X-ExtLoop1: 1 Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2026 03:29:11 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [RFC PATCH 8/8] gdb, infrun: only step over breakpoints that were hit Date: Thu, 1 Oct 2026 12:28:47 +0200 Message-ID: <20261001102847.576880-9-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261001102847.576880-1-markus.t.metzger@intel.com> References: <20261001102847.576880-1-markus.t.metzger@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, TXREP, T_SPF_TEMPERROR shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org When a thread hits a breakpoint, we note that this thread will need to step over the breakpoint when it is next resumed, e.g. case BPSTAT_WHAT_STOP_NOISY: infrun_debug_printf ("BPSTAT_WHAT_STOP_NOISY"); stop_print_frame = true; /* Assume the thread stopped for a breakpoint. We'll still check whether a/the breakpoint is there when the thread is next resumed. */ ecs->event_thread->stepping_over_breakpoint = 1; stop_waiting (ecs); return; in process_event_stop_test(). In addition, there is a special check whether there is a breakpoint at the current location in proceed(): if (cur_thr->stop_pc_p () && pc == cur_thr->stop_pc () && breakpoint_here_p (aspace, pc) == ordinary_breakpoint_here && execution_direction != EXEC_REVERSE) /* There is a breakpoint at the address we will resume at, step one instruction before inserting breakpoints so that we do not stop right away (and report a second hit at this breakpoint). Note, we don't do this in reverse, because we won't actually be executing the breakpoint insn anyway. We'll be (un-)executing the previous instruction. */ cur_thr->stepping_over_breakpoint = 1; This does not consider whether we actually hit the breakpoint. So, when setting $pc to a location with a breakpoint and continuing, we will skip it, but when jumping to that same location, we will hit the breakpoint. Prior to the parent patch, when stepping onto the breakpoint location in some other thread that was resumed while stepping the current thread, and then switching to that thread, we had skipped that breakpoint. There even is some special code in other locations to avoid the special handling in proceed(): /* Start the target running. Do not use -1 continuation as it would skip breakpoint right at the entry point. */ proceed (regcache_read_pc (get_thread_regcache (inferior_thread ())), GDB_SIGNAL_0); Removing this special case in proceed() makes GDB behave more consistently. It does introduce potentially undesired behavior when using the break command without arguments, though. E.g. (gdb) break (gdb) continue will now hit the newly inserted breakpoint that used to be skipped. On the other hand, any other thread at the same location would have hit the breakpoint, even though the current thread skipped it. E.g. (gdb) break (gdb) thread (gdb) continue would have hit the breakpoint (assuming no scheduler-locking). --- gdb/infcmd.c | 10 ++++++---- gdb/infrun.c | 20 +------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index d7544168362..043f5e890bf 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -654,10 +654,8 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how) prior to a proceed call. */ clear_proceed_status (0); - /* Start the target running. Do not use -1 continuation as it would skip - breakpoint right at the entry point. */ - proceed (regcache_read_pc (get_thread_regcache (inferior_thread ())), - GDB_SIGNAL_0); + /* Start the target running. */ + proceed ((CORE_ADDR) -1, GDB_SIGNAL_0); /* Since there was no error, there's no need to finish the thread states here. */ @@ -1312,6 +1310,10 @@ jump_command (const char *arg, int from_tty) gdb_printf (".\n"); } + /* Any pending step-over is cancelled by the jump. */ + thread_info *tp = inferior_thread (); + tp->stepping_over_breakpoint = 0; + clear_proceed_status (0); proceed (addr, GDB_SIGNAL_0); } diff --git a/gdb/infrun.c b/gdb/infrun.c index 44c41be1baa..2450394e3d1 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3634,7 +3634,6 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) INFRUN_SCOPED_DEBUG_ENTER_EXIT; struct gdbarch *gdbarch; - CORE_ADDR pc; /* If we're stopped at a fork/vfork, switch to either the parent or child thread as defined by the "set follow-fork-mode" command, or, if both @@ -3658,11 +3657,9 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) regcache *regcache = get_thread_regcache (cur_thr); gdbarch = regcache->arch (); - pc = regcache_read_pc_protected (regcache); /* Fill in with reasonable starting values. */ cur_thr->stepped_breakpoint = 0; - cur_thr->stepping_over_breakpoint = 0; cur_thr->stepping_over_watchpoint = 0; cur_thr->step_after_step_resume_breakpoint = 0; @@ -3677,22 +3674,7 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) if (addr == (CORE_ADDR) -1) { - const address_space *aspace = cur_thr->inf->aspace.get (); - - if (cur_thr->stop_pc_p () - && pc == cur_thr->stop_pc () - && breakpoint_here_p (aspace, pc) == ordinary_breakpoint_here - && execution_direction != EXEC_REVERSE) - /* There is a breakpoint at the address we will resume at, - step one instruction before inserting breakpoints so that - we do not stop right away (and report a second hit at this - breakpoint). - - Note, we don't do this in reverse, because we won't - actually be executing the breakpoint insn anyway. - We'll be (un-)executing the previous instruction. */ - cur_thr->stepping_over_breakpoint = 1; - else if (gdbarch_single_step_through_delay_p (gdbarch) + if (gdbarch_single_step_through_delay_p (gdbarch) && gdbarch_single_step_through_delay (gdbarch, get_current_frame ())) /* We stepped onto an instruction that needs to be stepped