From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8JlpOcqwkWivPgQAWB0awg (envelope-from ) for ; Tue, 05 Aug 2025 03:20:42 -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=TF85Mm7K; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E6CF61E102; Tue, 5 Aug 2025 03:20:42 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-10.1 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, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 6F5381E089 for ; Tue, 5 Aug 2025 03:20:42 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 047073858CD9 for ; Tue, 5 Aug 2025 07:20:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 047073858CD9 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=TF85Mm7K Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by sourceware.org (Postfix) with ESMTPS id 558FA3858D37 for ; Tue, 5 Aug 2025 07:19:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 558FA3858D37 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 558FA3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1754378361; cv=none; b=Z/o7QxIqjaksCdDzF0NlPxtC5RCVIRCPSXOkN9i6YOsKYhPhnbmYpQbaXmIKZenmfswGHXs5ppQTzbtjaNTmzt2k2xuDtzkmTZYmGQcttDs9vGiCSVrdXPL2/FsaS6CDOk+mcc/GK2KRSb9b53N8QrKvfNtUgq0ppMEt9aShG1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1754378361; c=relaxed/simple; bh=R9n3tNjJePo8gv/0GPuAmJAa93QryuKQM7k6njZQK3g=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=FA01Yiq43KJ1u/ayIctdM1X6ft8M5IZJw9Tau5L1wk7cTV521/q0ejnPre/Eeeft+oUOhvGBHdYVk2Fbv/S5omzTX7DoEWNjR2aNxkKzrNm06/f08NxzqVhjmQ4tI+R7g+wAKGVgqjRcV61wEd5S3ztInymRHi2/jWtvP7fVXEA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 558FA3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1754378361; x=1785914361; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R9n3tNjJePo8gv/0GPuAmJAa93QryuKQM7k6njZQK3g=; b=TF85Mm7KxmmrGgQeMqqVwG3lsSP6LhZ1syg8wQkuNX+BbEK8iAu+u9QU 769UyGmujWt6jI5p5Ok83/6Y+7qQgwWz96qx4x+cMWvEib1JhbTCKcfTT WDBbH8qg5aRua4NmOl+uHxa9ipU2LrmRNIr+HeTKIX+dFWOgW5xiIza3/ 0E3OcZol+5mAojrDkAqqgXZMuT4r7Jh1iODSvqpl8Jk0v+HAwGlCz8xzJ ZUcyhrqiWcHrviTXfbs2Rc0W+PBBJtTK9htcfx/jzDqpBbcwaHmgfwAVL AkuCll8b5fpZpfKj/9j34eCSKbgOQEIxF2G+ffI4zMKl63FN+CqfLuiWh A==; X-CSE-ConnectionGUID: Z60TKvZLS2WbJLnNlD79WQ== X-CSE-MsgGUID: IWkwU+gsRHy4LQcepJbOzQ== X-IronPort-AV: E=McAfee;i="6800,10657,11512"; a="68031318" X-IronPort-AV: E=Sophos;i="6.17,265,1747724400"; d="scan'208";a="68031318" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2025 00:19:20 -0700 X-CSE-ConnectionGUID: 1GHrr18zR7ytGt8rbillCg== X-CSE-MsgGUID: FoLhpvKYRwGXmBrn2apQGQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,265,1747724400"; d="scan'208";a="164305259" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2025 00:19:19 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Cc: Thiago Jung Bauermann Subject: [PATCH 2/2] gdb, remote: fix set_thread () in start_remote () Date: Tue, 5 Aug 2025 07:19:14 +0000 Message-Id: <20250805071914.3832823-2-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250805071914.3832823-1-markus.t.metzger@intel.com> References: <20250805071914.3832823-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 remote_target::start_remote_1 () calls set_continue_thread (minus_one_ptid) with the intent to /* Let the stub know that we want it to return the thread. */ set_continue_thread (minus_one_ptid); I interpret it such that it expects a later get_current_thread () to return the thread selected by the target: /* We have thread information; select the thread the target says should be current. If we're reconnecting to a multi-threaded program, this will ideally be the thread that last reported an event before GDB disconnected. */ ptid_t curr_thread = get_current_thread (wait_status); This results in the packet sequence Hc-1, qC. Hc simply sets cont_thread: else if (cs.own_buf[1] == 'c') cs.cont_thread = thread_id; write_ok (cs.own_buf); and qC returns the general thread. This doesn't match. It also has some special treatment for null_ptid and minus_one_ptid: if (cs.general_thread != null_ptid && cs.general_thread != minus_one_ptid) ptid = cs.general_thread; else { init_thread_iter (); ptid = thread_iter->id; } Similarly, Hg has some special treatment for null_ptid: if (cs.own_buf[1] == 'g') { if (thread_id == null_ptid) { /* GDB is telling us to choose any thread. Check if the currently selected thread is still valid. If it is not, select the first available. */ thread_info *thread = find_thread_ptid (cs.general_thread); if (thread == NULL) thread = get_first_thread (); thread_id = thread->id; } cs.general_thread = thread_id; The comment at Hg matches the intent of GDB for sending Hc-1. Change the set_thread () call in remote_target::start_remote_1 () to set_general_thread (any_thread_ptid); This results in GDB sending Hg0 and gdbserver preserving the currently selected thread that is later returned in response to qC. CC: Thiago Jung Bauermann --- gdb/remote.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/remote.c b/gdb/remote.c index 6208a90f94a..9b76578bd80 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -5293,7 +5293,7 @@ remote_target::start_remote_1 (int from_tty, int extended_p) target_update_thread_list (); /* Let the stub know that we want it to return the thread. */ - set_continue_thread (minus_one_ptid); + set_general_thread (any_thread_ptid); if (thread_count (this) == 0) { -- 2.34.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928