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>
This commit is contained in:
Tankut Baris Aktemur
2025-02-19 08:55:23 +01:00
parent 4546dae1ff
commit 1dd0c74551
6 changed files with 61 additions and 3 deletions

View File

@@ -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);

View File

@@ -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)

View File

@@ -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 */