From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6ao0C3p2fGpIlCAAWB0awg (envelope-from ) for ; Wed, 12 Aug 2026 09:34:50 -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=aiaQMRuX; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 29EF01E166; Wed, 12 Aug 2026 09:34:50 -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 80BF51E033 for ; Wed, 12 Aug 2026 09:34:49 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4EB564BA7999 for ; Wed, 12 Aug 2026 13:34:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EB564BA7999 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=aiaQMRuX Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by sourceware.org (Postfix) with ESMTPS id 425F04B9700C for ; Wed, 12 Aug 2026 13:29:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 425F04B9700C 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 425F04B9700C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786541349; cv=none; b=ab/LlCaAhh8lSIDl74bPYdetjc6HODJw852JfpAH4gT+89jfgOAksiG9aii7yXn1smdvzBeIepOAMxK4VPuSLzPw5r58DEGCSVvtO1ZCShbgvLmzzzfzpLoQmv1DKPvd5/2DK61BYj5DZ/DX1Te3tE2OL4fhAGO4uQosGSUoyf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786541349; c=relaxed/simple; bh=0T/Yg9Tqe9oFCkJsa5QayiXXMQdcdsWObXdrdiI2bg0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=i7XjPQYERFQtZx8pfuAk/7NCjX3OPj65BLo35sAA11vkoHxOQj2hW1TwASp3BBpuXCK6LPwxKPHRTDeOMuuln+vNTnEzNQTNJRrvOOKrGA1ZcLl/QhsqNOnsPCQGYfx4RdH2NenPsTflTb5eiyIbEXZmxohm3Cdc6RCezUZx8OU= 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=aiaQMRuX DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 425F04B9700C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1786541349; x=1818077349; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=0T/Yg9Tqe9oFCkJsa5QayiXXMQdcdsWObXdrdiI2bg0=; b=aiaQMRuXSsDs0ppVI/z7ECKYmjCdVK6plbXml70pnM5TQon7THVTs7pj F4V+ljbLw2Hfy9T7BcLyta9lTC9lU2ikFejf2QK97mLUCUM0ewm8dbvQa LUUfyAR1fGsRaRZ/tCESgwcToodnQ0ysTksfhktsYYrsQ6jXBJcyDfrkX tK1M+a76goO9FxVHwtKx11FaJMhvtrW0aKWy3OURil2fjvVSCx28UyCp1 OSa3FfjVYWrNbYfUfXmdb3HsDLcem8uTzV2s3PwbGMIYWhJCEU29VA/6x B6P/+aAhWpqxXyf6+0sUWcip/I1HQeuG3wcH/H/q8jzwVLESfvZnfONIN g==; X-CSE-ConnectionGUID: kYtYE5X/R6+9GyNz2XVE5A== X-CSE-MsgGUID: fzErqls8Q0uErjbACMzS/Q== X-IronPort-AV: E=McAfee;i="6800,10657,11872"; a="97757824" X-IronPort-AV: E=Sophos;i="6.25,219,1779174000"; d="scan'208";a="97757824" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 06:29:08 -0700 X-CSE-ConnectionGUID: 7Jqri4uLS8qE4OaKqnDmEw== X-CSE-MsgGUID: zEQpKgY5SN2JNEVHh8xwwA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,219,1779174000"; d="scan'208";a="259817892" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 06:29:07 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [PATCH v4 19/44] gdb, gdbserver: allow setting null_ptid as general thread Date: Wed, 12 Aug 2026 15:27:39 +0200 Message-ID: <20260812132805.380163-20-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260812132805.380163-1-markus.t.metzger@intel.com> References: <20260812132805.380163-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 GPU inferior, we may not have any thread selected. As a common scenario, when adding a new inferior and attaching to GPU devices when the host process is just starting, we will have an inferior representing a GPU device but, since no work has been submitted yet, there will be no thread, so inferior_ptid == null_ptid. --- gdb/remote.c | 15 ++++++++------- gdbserver/server.cc | 17 ++++++----------- gdbserver/target.cc | 6 ++++++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 50e90ad8440..753b59a0819 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -3490,10 +3490,11 @@ remote_target::program_signals (gdb::array_view signals) } } -/* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is - MINUS_ONE_PTID, set the thread to -1, so the stub returns the - thread. If GEN is set, set the general thread, if not, then set - the step/continue thread. */ +/* If PTID is MAGIC_NULL_PTID, NULL_PTID, or ANY_THREAD_PTID don't set any + thread and let the remote stub select the thread. If PTID is + MINUS_ONE_PTID, set the thread to -1, so the stub returns the thread. + If GEN is set, set the general thread, if not, then set the + step/continue thread. */ void remote_target::set_thread (ptid_t ptid, int gen) { @@ -3507,9 +3508,9 @@ remote_target::set_thread (ptid_t ptid, int gen) *buf++ = 'H'; *buf++ = gen ? 'g' : 'c'; - if (ptid == magic_null_ptid) - xsnprintf (buf, endbuf - buf, "0"); - else if (ptid == any_thread_ptid) + if (ptid == magic_null_ptid + || ptid == null_ptid + || ptid == any_thread_ptid) xsnprintf (buf, endbuf - buf, "0"); else if (ptid == minus_one_ptid) xsnprintf (buf, endbuf - buf, "-1"); diff --git a/gdbserver/server.cc b/gdbserver/server.cc index a7e976c0f75..03a40c7a19e 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -4858,14 +4858,8 @@ process_serial_event (void) { /* The ptid represents a pid. */ thread_info *thread = find_any_thread_of_pid (thread_id.pid ()); - - if (thread == NULL) - { - write_enn (cs.own_buf); - break; - } - - thread_id = thread->id; + if (thread != nullptr) + thread_id = thread->id; } else { @@ -4885,14 +4879,15 @@ process_serial_event (void) 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) + if (thread == nullptr) thread = get_first_thread (); - thread_id = thread->id; + + if (thread != nullptr) + thread_id = thread->id; } cs.general_thread = thread_id; set_desired_thread (); - gdb_assert (current_thread != NULL); } else if (cs.own_buf[1] == 'c') cs.cont_thread = thread_id; diff --git a/gdbserver/target.cc b/gdbserver/target.cc index d97d2334344..5f0d9000254 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -34,6 +34,12 @@ bool set_desired_thread () { client_state &cs = get_client_state (); + if (cs.general_thread == null_ptid) + { + switch_to_thread (nullptr); + return false; + } + if (cs.general_thread.is_pid ()) { process_info *proc = find_process_pid (cs.general_thread.pid ()); -- 2.43.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.