[PATCH 3/4] winedbg: Prefer thread name from GetThreadDescription() in GDB proxy mode.
Eric Pouech
eric.pouech at orange.fr
Wed Mar 16 02:39:10 CDT 2022
Le 15/03/2022 à 20:05, Brendan Shanks a écrit :
> Signed-off-by: Brendan Shanks<bshanks at codeweavers.com>
> ---
> 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);
> }
it's a bit ackward to add two implementations of get_thread_description
; moreover differing in ansi/unicode but also memory allocation strategy
it would be better to only have one (esp when considering that
GetThreadDescription is only avail in W10)
IMO a single helper would be preferable
A+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20220316/a52f66f3/attachment.htm>
More information about the wine-devel
mailing list