From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id rS2YNvRSqWoAgQ4AWB0awg (envelope-from ) for ; Tue, 15 Sep 2026 10:15:16 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=mZl2ms4Y; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CE6621E01F; Tue, 15 Sep 2026 10:15:16 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 30E1E1E01F for ; Tue, 15 Sep 2026 10:15:14 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E50C84B9DB4E for ; Tue, 15 Sep 2026 14:15:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E50C84B9DB4E 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=mZl2ms4Y Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by sourceware.org (Postfix) with ESMTPS id 5C43F4BA9020 for ; Tue, 15 Sep 2026 14:14:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C43F4BA9020 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 5C43F4BA9020 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789481685; cv=none; b=HRuSybEUZOgVN3uJ1vlZNt5XmehQAfOk53X5xwYMpd/TbrJKqi0G0IVJrgvHBpaou8Gnzckkocnh1mkzayMioV55sInzBFoiCKLcfauoS0rGx9QPygiTAH1C3bwaY7jlFMeWciTYwMPUC/0dnbjWCKss6eFSzHyk6R16c2v47rM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789481685; c=relaxed/simple; bh=+Hzm88Tw9q6V0lExS5Ry95ZS+gqWXq7wQJsUvRlhuOc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kGJxe89tEFEiIGxujyFTt9NpfmPI8Cv42+7mm6Z7Xm0DXqYHDdCLgl/mlP1fzE7tdN8Nmi33KHOUCmI5eq3ML8pz8fH+mfpyS6eG4sR0jQzqV53mpfNDoDaITHE5Dhde30gDwhUGWqOEULSxv0Z/eiQTY6ozZkWW+KoFvH6VaJQ= 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=mZl2ms4Y DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C43F4BA9020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1789481686; x=1821017686; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=+Hzm88Tw9q6V0lExS5Ry95ZS+gqWXq7wQJsUvRlhuOc=; b=mZl2ms4YJuKG0scihHSoqmH4UEQLL61cvYY4HiQ9hGERzzFbCYQJzJKr f1tKWSaM6QEfkWDoE8x9rl4b2zTuX4O48w3JZlMmGgcSpsKmVtjeKdHMg 235yd2KKsXcmOZJjekj5ltP4w2wir0m1qid118gw8qB3sS4m0KGC52+F/ /lrPmBnVUsfhi9ChZ1WhiIL5ZLwN6PfQ0DDkRSYJTnj/QQdSA2YiIy0fv Vr0vcb5UFYT0ohreSrUWyhYTTFONvSRpcvk8ZWyPLGRcArtz6kMRyVOMw R0iiP5eFwYbDGS6CZHE3jKv1EfqEkPmfRdihlebJDpZjTq2xZK3F+jCN5 g==; X-CSE-ConnectionGUID: kDKlI4ccQ2STwF1YAlh7/w== X-CSE-MsgGUID: B7h7kkvlTCS/G4Mf6OUq+Q== X-IronPort-AV: E=McAfee;i="6800,10657,11905"; a="89870504" X-IronPort-AV: E=Sophos;i="6.27,103,1787036400"; d="scan'208";a="89870504" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2026 07:14:44 -0700 X-CSE-ConnectionGUID: m0beVP92RNqq7BQtzXfEoA== X-CSE-MsgGUID: fSkqesfcRIC6OvYB2pY5DA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,103,1787036400"; d="scan'208";a="298072946" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2026 07:14:43 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [PATCH] gdb, infrun: do not discard a step-completed pending waitstatus Date: Tue, 15 Sep 2026 16:14:41 +0200 Message-ID: <20260915141441.2274270-1-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 Consider a scenario with two breakpoints on adjacent instructions: bp1 at 0xf00 bp2 at 0xf01 as well as two threads in all-stop-on-top-of-non-stop mode. Assume that threads A hits bp1 and we report the breakpoint hit to the user. When the user continues, we start a step-over for thread A at 0xf00. Assume that thread B now hits bp1 and we report the breakpoint hit to the user. We stop all threads to report the event. Meanwhile, the step-over of thread A completes, so we save the pending waitstatus (stop_pc=0xf01, currently_stepping=1) of thread A. When the user continues, clear_proceed_status_thread() discards the pending step completed waitstatus of thread A, and proceed() starts another step-over for thread A at 0xf01. We skip bp2 for thread A. Remove the code in clear_proceed_status_thread() that discards a step completed waitstatus and let it get handled normally. --- gdb/infrun.c | 25 ++----- gdb/testsuite/gdb.threads/adjacent-bp.c | 48 +++++++++++++ gdb/testsuite/gdb.threads/adjacent-bp.exp | 86 +++++++++++++++++++++++ 3 files changed, 139 insertions(+), 20 deletions(-) create mode 100644 gdb/testsuite/gdb.threads/adjacent-bp.c create mode 100644 gdb/testsuite/gdb.threads/adjacent-bp.exp diff --git a/gdb/infrun.c b/gdb/infrun.c index b9618fb6422..4ab9f4aaf64 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3100,28 +3100,13 @@ clear_proceed_status_thread (struct thread_info *tp) infrun_debug_printf ("%s", tp->ptid.to_string ().c_str ()); gdb_assert (tp->internal_state () != THREAD_INT_RUNNING); - /* If we're starting a new sequence, then the previous finished - single-step is no longer relevant. */ if (tp->has_pending_waitstatus ()) { - if (tp->stop_reason () == TARGET_STOPPED_BY_SINGLE_STEP) - { - infrun_debug_printf ("pending event of %s was a finished step. " - "Discarding.", - tp->ptid.to_string ().c_str ()); - - tp->set_internal_state (THREAD_INT_STOPPED); - tp->clear_pending_waitstatus (); - tp->set_stop_reason (TARGET_STOPPED_BY_NO_REASON); - } - else - { - infrun_debug_printf - ("thread %s has pending wait status %s (currently_stepping=%d).", - tp->ptid.to_string ().c_str (), - tp->pending_waitstatus ().to_string ().c_str (), - tp->control.currently_stepping); - } + infrun_debug_printf + ("thread %s has pending wait status %s (currently_stepping=%d).", + tp->ptid.to_string ().c_str (), + tp->pending_waitstatus ().to_string ().c_str (), + tp->control.currently_stepping); } /* If this signal should not be seen by program, give it zero. diff --git a/gdb/testsuite/gdb.threads/adjacent-bp.c b/gdb/testsuite/gdb.threads/adjacent-bp.c new file mode 100644 index 00000000000..e72e674f52a --- /dev/null +++ b/gdb/testsuite/gdb.threads/adjacent-bp.c @@ -0,0 +1,48 @@ +/* Copyright 2026 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include + +static pthread_barrier_t barrier; + +static void * +test (void *arg) +{ + pthread_barrier_wait (&barrier); + int a = 0; /* break here. */ + int b = 0; + int c = 0; + return arg; +} + +int +main () +{ + pthread_t th; + + alarm (500); + + pthread_barrier_init (&barrier, NULL, 2); + pthread_create (&th, NULL, test, NULL); + test (NULL); + + pthread_join (th, NULL); + pthread_barrier_destroy (&barrier); + + return 0; +} diff --git a/gdb/testsuite/gdb.threads/adjacent-bp.exp b/gdb/testsuite/gdb.threads/adjacent-bp.exp new file mode 100644 index 00000000000..9e7782c01c2 --- /dev/null +++ b/gdb/testsuite/gdb.threads/adjacent-bp.exp @@ -0,0 +1,86 @@ +# Copyright 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test that GDB does not skip a breakpoint when a step-over completes +# while another event leads to a stop. + +standard_testfile + +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + {debug pthreads}]} { + return +} + +if {![runto_main]} { + return +} + +# Find a sequence of adjacent instructions. +set bp_line [gdb_get_line_number "break here"] +set pcs {} +gdb_test_multiple "info line $bp_line" "" { + -re -wrap "starts at address ($hex).*" { + pass $gdb_test_name + + set line "\\s+($hex) \[^\r\n\]+" + gdb_test_multiple "x/3i $expect_out(1,string)" "disassemble" { + -re -wrap "$line\r\n$line\r\n$line.*" { + pass $gdb_test_name + + lappend pcs $expect_out(1,string) + lappend pcs $expect_out(2,string) + lappend pcs $expect_out(3,string) + } + -re -wrap "" { + fail $gdb_test_name + } + } + } + -re -wrap "" { + fail $gdb_test_name + } +} + +# Set breakpoints on adjacent instructions. +foreach pc $pcs { + gdb_breakpoint "\*$pc" +} + +# Continue from breakpoint to breakpoint. +set hits [dict create] +set iter 0 +gdb_test_multiple "continue" "" { + -re -wrap "hit Breakpoint.*" { + dict incr hits [get_hexadecimal_valueof "\$pc" invalid "stop $iter"] + incr iter + send_gdb "continue\n" + exp_continue + } + -re -wrap "$inferior_exited_re normally.*" { + pass "$gdb_test_name" + } +} + +# We expect all breakpoints to be hit by both threads. +foreach pc $pcs { + if {[dict exists $hits $pc]} { + gdb_assert {[dict get $hits $pc] eq 2} "breakpoint at $pc" + dict unset hits $pc + } else { + fail "breakpoint at $pc" + } +} +# And no unrelated stops. +gdb_assert {[dict size $hits] eq 0} "no extra stops" -- 2.53.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.