aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2025-02-19 08:55:23 +0100
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2025-02-19 09:15:44 +0100
commit1dd0c74551166c07ba0f26d10432ffa577453713 (patch)
treef1b7c7cc52dbf63b4cf4a7d4bd493302ff405014
parent4546dae1ff089bb4a027929f47240d5de0c370c0 (diff)
downloadbinutils-1dd0c74551166c07ba0f26d10432ffa577453713.zip
binutils-1dd0c74551166c07ba0f26d10432ffa577453713.tar.gz
binutils-1dd0c74551166c07ba0f26d10432ffa577453713.tar.bz2
gdbserver, remote: introduce "id_str" in the "qXfer:threads:read" XML
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 <eliz@gnu.org> Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Approved-By: Simon Marchi <simon.marchi@efficios.com>
-rw-r--r--gdb/NEWS8
-rw-r--r--gdb/doc/gdb.texinfo7
-rw-r--r--gdb/remote.c26
-rw-r--r--gdbserver/server.cc4
-rw-r--r--gdbserver/target.cc6
-rw-r--r--gdbserver/target.h13
6 files changed, 61 insertions, 3 deletions
diff --git a/gdb/NEWS b/gdb/NEWS
index 2931a20..f5dbf5c 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -62,6 +62,14 @@ binary-upload in qSupported reply
stub doesn't report this feature supported, then GDB will not use
the 'x' packet.
+* 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.
+
* MI changes
** The =library-unloaded event now includes the 'ranges' field, which
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 88b6c68..f8a8b13 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -48444,7 +48444,7 @@ the following structure:
@smallexample
<?xml version="1.0"?>
<threads>
- <thread id="id" core="0" name="name" handle="1a2b3c">
+ <thread id="id" core="0" name="name" id_str="Thread 12.34" handle="1a2b3c">
... description ...
</thread>
</threads>
@@ -48456,7 +48456,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 1318352..98a94fa 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1623,6 +1623,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;
@@ -4030,6 +4036,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;
@@ -4156,6 +4165,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 ());
@@ -4177,6 +4190,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 }
};
@@ -4361,6 +4375,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);
}
}
@@ -12392,7 +12407,16 @@ remote_target::pid_to_str (ptid_t ptid)
{
if (magic_null_ptid == ptid)
return "Thread <main>";
- 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;
+ }
+
+ 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 8623d94..879ea78 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1981,6 +1981,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);
@@ -2005,6 +2006,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 6db32da..a26e159 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 1a013bb..782e22c 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -475,6 +475,13 @@ public:
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 */