From patchwork Tue Apr 2 10:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aktemur, Tankut Baris" X-Patchwork-Id: 87921 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE84F3858294 for ; Tue, 2 Apr 2024 10:21:19 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by sourceware.org (Postfix) with ESMTPS id A73923858CDB for ; Tue, 2 Apr 2024 10:20:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A73923858CDB 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 A73923858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712053239; cv=none; b=w3AuTXWm78Z8nkiUtR/KRjJ29gfrUlDZ2UlhoK1Tl0rTtiOwh8j+/zc2WifPrMEiGGUNo7WYvG420V458AYd4W3ogSX+TFYs5codLXF466r3Zrd1NdNfiI2K343TZWrInBqNCgP/MCeJfnP8zoU0pz/peEv7zqMvTD6+WnoLypY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712053239; c=relaxed/simple; bh=QOueRp4QMNsn/c/NPWRciH21gBmYNlkvBxDlAOKa4bo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ORwTxCcuRlL5MU+mwsnDTF9uGV+ijioI0Qe8ESRozFIuxjW/Yaak1B/HonND7bqxTn+3Vo/4LJj5V1K4dG5PEBY9d0gvA0x0oh5a1c+hN2YJ/p+PatN0DOT1vLNpHz3extJgykgD8erPkKypxVyvUOs+k1LtkIkZ0CojVKvKecg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712053236; x=1743589236; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=QOueRp4QMNsn/c/NPWRciH21gBmYNlkvBxDlAOKa4bo=; b=MnTjg3ge8qZsDoxerpWkn2ghop23wj9/hgB20pC8p5/HC4ygZZ0hE9Zm wYc0Pw7a7VtEMq7x02VX2R/bz/odjf+DAaga1kG4cvh3jaLvKkZSbYSvg hGPbeBYfpDRDGAtiAOsN3CWO/EDCCHD48yiXLnKMRd1jLbH4hBU1gh6Ce OXctJuaJcLT0wSgFqvLOlKEG3FUs4kBN1/WAOnxhsZ3n1tirf/HeQigWK nwTHQycCgTZfG0U14nMh+l4cOIE1RGzR16Te7BKQoDx3CLhOUo6/i+BmW zGQJ2BDd7qHi0n/8TPAmJJx8RD6InpzI1Kv4NYHP2xFZe4cUGA9wGxhmR w==; X-CSE-ConnectionGUID: 9WVzqAuhRbGq/UL3eAtoKA== X-CSE-MsgGUID: kT/k6sqURDSivxaum3w2Cw== X-IronPort-AV: E=McAfee;i="6600,9927,11031"; a="7148754" X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="7148754" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 03:20:35 -0700 X-CSE-ConnectionGUID: K1Axb+IUTUqv7veqqeUZLA== X-CSE-MsgGUID: 5LSS7WNdSaSIAl1vHnLY/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="41169815" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 03:20:34 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH 1/2] doc: add the missing 'handle' attribute in xml Date: Tue, 2 Apr 2024 12:20:19 +0200 Message-Id: <20240402102020.2521082-1-tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=AC_FROM_MANY_DOTS, BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 The XML response to the "qXfer:threads:read" packet may include a "handle" attribute. The attribute is mentioned in the document but not shown in the sample XML structure. Add it. --- gdb/doc/gdb.texinfo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 727f9275bfb..41a368a0194 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -48081,7 +48081,7 @@ the following structure: @smallexample - + ... description ... From patchwork Tue Apr 2 10:20:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aktemur, Tankut Baris" X-Patchwork-Id: 87922 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD0863858C55 for ; Tue, 2 Apr 2024 10:21:23 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by sourceware.org (Postfix) with ESMTPS id 5D8283858404 for ; Tue, 2 Apr 2024 10:20:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D8283858404 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 5D8283858404 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712053246; cv=none; b=s9ZlZF4n4ucnPqu3okn/8y8MZVaZhQEKeVXLMmOUqpEzO+R2ajaL09S7rBOwjuL9/Z3730mysOhXCVIFCWpEoQp0PHaTheQuO8X4iuvKRsDKtFx1me3Py5/1ukofyV3aAcNpcwPD8lRjk/TLODwbGI5SUBaNf6LMD8695nixvmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712053246; c=relaxed/simple; bh=JrIpfk+P8+m2mxse3fMOwRPCVd39pxA3o9RSpbOpxM0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=lkfTjCcDjtxFPy0THYxhr7PRVOCpvORP2v+NzW/VJraS8pZopuALLvqpF5itX9fzLUtLfQcSlRE3h/2XEMGwBWuwsLANaf5d7jSpXgMomMWLJhJIhzi4pCyW58G2zMi7WshzcK2spGVB+gxEU+Qd0Ph48jRsDJn72EsVaNN0qn8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712053242; x=1743589242; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=JrIpfk+P8+m2mxse3fMOwRPCVd39pxA3o9RSpbOpxM0=; b=iZl4HFy/vVQ8wWv/dMxlJ1hk5BbroefoH6wP2y8Z0ccQ8/HRWpxhOdW5 /XVlyOnHLVbAbqNsJml9JHGUA1iB7NltFRyb0VdbUW2yNVOXV9Oay+zkH My/yn4dEm321c1uWsj8+jmI3ghS35gkhkc4VRHOmrtYVPgw4xRuXYIt/X ZTppbNHY9GyXtmn2MCIpUGw3BsKQnqgEBlvzPSrOyQPgSQC2R0gWZVSoF 2CbEUDuwLOqplQ0U9eYiVYoKevmTPA0HQWhISWe0Oczb1yHhbiSh0Sf84 BYWPZSnbo8Eswp3Eo0UFArEVwTkQU6gbUee1jn7FnC3M8xjNKqL5j3Rcj A==; X-CSE-ConnectionGUID: M+5ddvn9SQyLlBtYPNUDMw== X-CSE-MsgGUID: Lz7tXMVaR7W6dzOsCQolOw== X-IronPort-AV: E=McAfee;i="6600,9927,11031"; a="7148772" X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="7148772" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 03:20:42 -0700 X-CSE-ConnectionGUID: IJzsM9F5TW+e0Pc+pZZxng== X-CSE-MsgGUID: 7TAAaAkCQj6X6ivq/N+itw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="41169826" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 03:20:41 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH 2/2] gdbserver, remote: introduce "id_str" in the "qXfer:threads:read" XML Date: Tue, 2 Apr 2024 12:20:20 +0200 Message-Id: <20240402102020.2521082-2-tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240402102020.2521082-1-tankut.baris.aktemur@intel.com> References: <20240402102020.2521082-1-tankut.baris.aktemur@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 GDB prints the target id of a thread in various places such as the output of the "info threads" command in the "Target Id" column or when switching to a thread. A target can define what to print for a given ptid by overriding the `pid_to_str` method. The remote target is a gateway behind which one of many various targets could be running. The remote target converts a given ptid to a string in a uniform way, without consulting the low target at the server-side. In this patch we introduce a new attribute in the XML that is sent in response to the "qXfer:threads:read" RSP packet, so that a low target at the server side, if it wishes, can specify what to print as the target id of a thread. Note that the existing "name" attribute or the "extra" text provided in the XML are not sufficient for the server-side low target to achieve the goal. Those attributes, when present, are simply appended to the target id by GDB. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 9 +++++++++ gdb/doc/gdb.texinfo | 7 +++++-- gdb/remote.c | 26 +++++++++++++++++++++++++- gdbserver/server.cc | 4 ++++ gdbserver/target.cc | 6 ++++++ gdbserver/target.h | 13 +++++++++++++ 6 files changed, 62 insertions(+), 3 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index feb3a37393a..2a0b08887a1 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -192,6 +192,15 @@ QThreadOptions in qSupported QThreadOptions packet, and the qSupported response can contain the set of thread options the remote stub supports. +* Changed remote packets + +qXfer:threads:read + + The XML that is sent as a response can now include an "id_str" + attribute for a thread element. The attribute indicates what GDB + should print as the target ID of the thread, for example in the + "info threads" command or when switching to the thread. + *** Changes in GDB 14 * GDB now supports the AArch64 Scalable Matrix Extension 2 (SME2), which diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 41a368a0194..42ddd8ca8d5 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -48081,7 +48081,7 @@ the following structure: @smallexample - + ... description ... @@ -48093,7 +48093,10 @@ identifies the thread (@pxref{thread-id syntax}). The the thread was last executing on. The @samp{name} attribute, if present, specifies the human-readable name of the thread. The content of the of @samp{thread} element is interpreted as human-readable -auxiliary information. The @samp{handle} attribute, if present, +auxiliary information. The @samp{id_str} attribute, if present, +specifies what @value{GDBN} should print as the target ID of the +thread (e.g.@: in the @samp{info threads} command or when switching +to the thread). The @samp{handle} attribute, if present, is a hex encoded representation of the thread handle. diff --git a/gdb/remote.c b/gdb/remote.c index e278711df7b..e09a0c56eb3 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1537,6 +1537,12 @@ struct remote_thread_info : public private_thread_info std::string name; int core = -1; + /* The string representation for the thread's id. + + The target specifies this if they want to display the thread id + in a specific way. If empty, the default approach is used. */ + std::string id_str; + /* Thread handle, perhaps a pthread_t or thread_t value, stored as a sequence of bytes. */ gdb::byte_vector thread_handle; @@ -3951,6 +3957,9 @@ struct thread_item /* The thread's name. */ std::string name; + /* The thread's id, translated to a string for displaying. */ + std::string id_str; + /* The core the thread was running on. -1 if not known. */ int core = -1; @@ -4077,6 +4086,10 @@ start_thread (struct gdb_xml_parser *parser, if (attr != NULL) item.name = (const char *) attr->value.get (); + attr = xml_find_attribute (attributes, "id_str"); + if (attr != nullptr) + item.id_str = (const char *) attr->value.get (); + attr = xml_find_attribute (attributes, "handle"); if (attr != NULL) item.thread_handle = hex2bin ((const char *) attr->value.get ()); @@ -4098,6 +4111,7 @@ const struct gdb_xml_attribute thread_attributes[] = { { "id", GDB_XML_AF_NONE, NULL, NULL }, { "core", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL }, { "name", GDB_XML_AF_OPTIONAL, NULL, NULL }, + { "id_str", GDB_XML_AF_OPTIONAL, NULL, NULL }, { "handle", GDB_XML_AF_OPTIONAL, NULL, NULL }, { NULL, GDB_XML_AF_NONE, NULL, NULL } }; @@ -4282,6 +4296,7 @@ remote_target::update_thread_list () info->core = item.core; info->extra = std::move (item.extra); info->name = std::move (item.name); + info->id_str = std::move (item.id_str); info->thread_handle = std::move (item.thread_handle); } } @@ -12228,7 +12243,16 @@ remote_target::pid_to_str (ptid_t ptid) { if (magic_null_ptid == ptid) return "Thread
"; - else if (m_features.remote_multi_process_p ()) + + thread_info *thread = this->find_thread (ptid); + if ((thread != nullptr) && (thread->priv != nullptr)) + { + remote_thread_info *priv = get_remote_thread_info (thread); + if (!priv->id_str.empty ()) + return priv->id_str.c_str (); + } + + if (m_features.remote_multi_process_p ()) if (ptid.lwp () == 0) return normal_pid_to_str (ptid); else diff --git a/gdbserver/server.cc b/gdbserver/server.cc index c7d5cc1c1b0..018fbc04076 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1994,6 +1994,7 @@ handle_qxfer_threads_worker (thread_info *thread, std::string *buffer) int core = target_core_of_thread (ptid); char core_s[21]; const char *name = target_thread_name (ptid); + std::string id_str = target_thread_id_str (thread); int handle_len; gdb_byte *handle; bool handle_status = target_thread_handle (ptid, &handle, &handle_len); @@ -2018,6 +2019,9 @@ handle_qxfer_threads_worker (thread_info *thread, std::string *buffer) if (name != NULL) string_xml_appendf (*buffer, " name=\"%s\"", name); + if (!id_str.empty ()) + string_xml_appendf (*buffer, " id_str=\"%s\"", id_str.c_str ()); + if (handle_status) { char *handle_s = (char *) alloca (handle_len * 2 + 1); diff --git a/gdbserver/target.cc b/gdbserver/target.cc index 6db32da2e95..a26e1599975 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -807,6 +807,12 @@ process_stratum_target::thread_name (ptid_t thread) return nullptr; } +std::string +process_stratum_target::thread_id_str (thread_info *thread) +{ + return ""; +} + bool process_stratum_target::thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len) diff --git a/gdbserver/target.h b/gdbserver/target.h index 3643b9110da..a46b3fa47ff 100644 --- a/gdbserver/target.h +++ b/gdbserver/target.h @@ -475,6 +475,13 @@ class process_stratum_target caller. */ virtual const char *thread_name (ptid_t thread); + /* Return the string translation for THREAD's id. This gives the + target a chance to completely re-interpret the thread id and + present a target-specific description for displaying to the user. + Return empty if the target is fine with how an id is displayed + by default. */ + virtual std::string thread_id_str (thread_info *thread); + /* Thread ID to (numeric) thread handle: Return true on success and false for failure. Return pointer to thread handle via HANDLE and the handle's length via HANDLE_LEN. */ @@ -735,4 +742,10 @@ bool set_desired_process (); std::string target_pid_to_str (ptid_t); +static inline std::string +target_thread_id_str (thread_info *thread) +{ + return the_target->thread_id_str (thread); +} + #endif /* GDBSERVER_TARGET_H */