<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">Le 15/03/2022 à 20:05, Brendan Shanks a
      écrit :<br>
    </div>
    <blockquote type="cite"
      cite="mid:20220315190517.20629-3-bshanks@codeweavers.com">
      <pre class="moz-quote-pre" wrap="">Signed-off-by: Brendan Shanks <a class="moz-txt-link-rfc2396E" href="mailto:bshanks@codeweavers.com"><bshanks@codeweavers.com></a>
---
 programs/winedbg/gdbproxy.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c
index bcde120adeb..60c69f81d23 100644
--- a/programs/winedbg/gdbproxy.c
+++ b/programs/winedbg/gdbproxy.c
@@ -1773,11 +1773,40 @@ static enum packet_return packet_query_libraries(struct gdb_context* gdbctx)
     return packet_send_buffer;
 }
 
+static char *get_thread_description(DWORD tid)
+{
+    HANDLE h;
+    char *desc = NULL;
+    WCHAR *descW = NULL;
+    int len;
+
+    h = OpenThread(THREAD_QUERY_LIMITED_INFORMATION, FALSE, tid);
+    if (!h)
+        return NULL;
+
+    GetThreadDescription(h, &descW);
+    if (!descW)
+        goto cleanup;
+
+    len = WideCharToMultiByte(CP_ACP, 0, descW, -1, NULL, 0, NULL, NULL);
+    if (len <= 1) /* failure or empty string */
+        goto cleanup;
+
+    desc = malloc(len);
+    WideCharToMultiByte(CP_ACP, 0, descW, -1, desc, len, NULL, NULL);
+
+cleanup:
+    LocalFree(descW);
+    CloseHandle(h);
+    return desc;
+}
+
 static enum packet_return packet_query_threads(struct gdb_context* gdbctx)
 {
     struct reply_buffer* reply = &gdbctx->qxfer_buffer;
     struct dbg_process* process = gdbctx->process;
     struct dbg_thread* thread;
+    char *name;
 
     if (!process) return packet_error;
 
@@ -1791,7 +1820,12 @@ static enum packet_return packet_query_threads(struct gdb_context* gdbctx)
         reply_buffer_append_str(reply, "id=\"");
         reply_buffer_append_uinthex(reply, thread->tid, 4);
         reply_buffer_append_str(reply, "\" name=\"");
-        if (strlen(thread->name))
+        if ((name = get_thread_description(thread->tid)))
+        {
+            reply_buffer_append_str(reply, name);
+            free(name);
+        }
+        else if (strlen(thread->name))
         {
             reply_buffer_append_str(reply, thread->name);
         }
</pre>
    </blockquote>
    <p><font face="Helvetica, Arial, sans-serif">it's a bit ackward to
        add two implementations of </font>get_thread_description ;
      moreover differing in ansi/unicode but also memory allocation
      strategy</p>
    <p>it would be better to only have one (esp when considering that
      GetThreadDescription is only avail in W10)</p>
    <p>IMO a single helper would be preferable</p>
    <p>A+<br>
    </p>
  </body>
</html>