From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id IcpoByw2vmrsLCMAWB0awg (envelope-from ) for ; Thu, 01 Oct 2026 06:30:04 -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=nA78/YGx; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 0BB4A1E051; Thu, 01 Oct 2026 06:30:04 -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 [IPv6:2620:52:6:3111::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 70DD71E033 for ; Thu, 01 Oct 2026 06:30:01 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 597DD4BB5921 for ; Thu, 1 Oct 2026 10:30:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 597DD4BB5921 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=nA78/YGx Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by sourceware.org (Postfix) with ESMTPS id A11164BB58ED for ; Thu, 1 Oct 2026 10:29:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A11164BB58ED 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 A11164BB58ED 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=1790850548; cv=none; b=s5nOuy+rIF/6wo1rArSF6ipD9WRoMMxFS7rnP6bJR0GzjjSnGBB7/lLC6HpCX/CQ3LZePwCVNYkWFfN2Wq+N3dMFaldRv7kCG9UWTqONfhWUAhGdHlAc/ozs74nDbLQUMT0hNW1DAwtZ4U7ZWFbTBPBz/uJ0VX68mDV2M+oZTHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790850548; c=relaxed/simple; bh=UOi6952j3ZW2YOJhpUArak7q1PfQFMEsBEIyZ+9UgoQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZK2xPwB16knlB//kVjwt78VdkV1sss7HbkuQ6xR1fPf2qwvz2NVHzHWmFInf+gLgKXN/9eEExdWt0C8/danQVCLQqwdqfpX+tg2JxJP4x+S+VlypUIeQqNsd0jBf/BtJgc2+a+v2KWMwB0rWRA6vYZEczdGvXGLlXfjg31aMJAg= 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=nA78/YGx DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A11164BB58ED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790850549; x=1822386549; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=UOi6952j3ZW2YOJhpUArak7q1PfQFMEsBEIyZ+9UgoQ=; b=nA78/YGxb4qIx/0VN2zUgscRFYtCj0hbH4YQxz5MWNmm1IKZCAGmFb4g MYVwb5MZzYUTAvtNIp3jd7wAD4gqgdqCDrODzUsSos22NBYjtntlTGmdd ncvtSg20cV9+FvhgsbGMXaVSqyIhkoGdgvbRba5QDrLtbezQrxqEkGf8E i2m+yAwqqoPlfBpk3dZY4Sf2BV1dXPP+mPjA10k6HUkE2T5xaFPJRm3Zi LBe7Gopv/bggfuAfVCAkgVeL+Z8UXUzd7080aRbGMDcqrEGAnYynbdnVl VqKFoc2Q51aODWUCQZa6yl/VUVbQvmQP13SmfyD46ZrngJQO2y76D/OM6 w==; X-CSE-ConnectionGUID: /BUTX7bGS+eV/SakIyVW4Q== X-CSE-MsgGUID: sMLJGg1YQkmETvsISGKU7Q== X-IronPort-AV: E=McAfee;i="6800,10657,11921"; a="91619639" X-IronPort-AV: E=Sophos;i="6.27,134,1787036400"; d="scan'208";a="91619639" 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:07 -0700 X-CSE-ConnectionGUID: M3KbKYR0RKiA308rz31T4w== X-CSE-MsgGUID: 3glsyPACRzitOqorQwPVSQ== 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:06 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [RFC PATCH 6/8] gdb, infrun: handle stop event when selecting a thread Date: Thu, 1 Oct 2026 12:28:45 +0200 Message-ID: <20261001102847.576880-7-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 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 When debugging a multi-threaded program in all-stop mode, several threads may have reported an event at the same time. GDB picks one, switches to it, and presents it to the user. When continuing the process, the next event is picked, GDB switches to the eventing thread, and presents it to the user. And so on. For breakpoint hits that are based on a thread being at the location of a breakpoint, whether the target actually reported a breakpoint hit or not, this may be a bit confusing if we switched to a thread that is obviously at a breakoint location, but the event is still pending. Check for pending stop events when selecting a thread. Previous patches already repeat a previous stop notification when switching threads; they also handle this case. --- gdb/infrun.c | 24 ++++++++++++++++++++++++ gdb/infrun.h | 4 ++++ gdb/thread.c | 10 ++++++++++ 3 files changed, 38 insertions(+) diff --git a/gdb/infrun.c b/gdb/infrun.c index 8ba5937fa73..19eac5c5c8e 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -10624,6 +10624,30 @@ infrun_async_inferior_event_handler (gdb_client_data data) inferior_event_handler (INF_REG_EVENT); } +void handle_pending_stop (thread_info *tp) +{ + gdb_assert (tp->has_pending_waitstatus ()); + + target_waitstatus ws = tp->pending_waitstatus (); + gdb_assert (ws.kind () == TARGET_WAITKIND_STOPPED); + + /* We need breakpoints inserted for the wait. */ + SCOPE_EXIT { maybe_remove_breakpoints (); }; + insert_breakpoints (); + + ptid_t ptid = do_target_wait_1 (tp->inf, tp->ptid, &ws, TARGET_WNOHANG); + if (ptid != tp->ptid) + return; + if (ws.kind () != TARGET_WAITKIND_STOPPED) + return; + + execution_control_state ecs { tp }; + ecs.target = tp->inf->process_target (); + ecs.ws = ws; + + handle_inferior_event (&ecs); +} + #if GDB_SELF_TEST namespace selftests { diff --git a/gdb/infrun.h b/gdb/infrun.h index 7b2b882dc9a..b4d9461449b 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -438,4 +438,8 @@ extern void reinstall_readline_callback_handler_cleanup (); target_attach_no_wait targets. */ extern void set_normal_stop_state_just_attached (); +/* We selected TP with a pending stopped waitstatus. Handle it so we can + show it to the user. */ +extern void handle_pending_stop (thread_info *tp); + #endif /* GDB_INFRUN_H */ diff --git a/gdb/thread.c b/gdb/thread.c index bbcd3e61cd1..aa3f8ec783f 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -2116,6 +2116,16 @@ thread_select (const char *tidstr, thread_info *tp) /* Since the current thread may have changed, see if there is any exited thread we can now delete. */ delete_exited_threads (nullptr); + + /* Process any pending stop event that was fetched from the target when + that thread was resumed but we decided to present another thread's + event to the user. + + Now that we're selecting that thread, we'd want to show the event + right away instead of waiting until the thread is resumed again. */ + if (tp->has_pending_waitstatus () + && (tp->pending_waitstatus ().kind () == TARGET_WAITKIND_STOPPED)) + handle_pending_stop (tp); } /* Print thread and frame switch command response. */ -- 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.