Currently, the two methods of setting thread names in Windows (SetThreadDescription() and the 0x406D1388 exception) log to different channels.
I think it would be useful for these to both log to the same +threadname channel. My thinking is that this would be similar to +debugstr, in that all messages are human-readable descriptions which would be useful for debugging crashes.
-- v2: ntdll: Use +threadname channel for SetThreadDescription(). ntdll: Use +threadname channel for thread rename exceptions.
From: Brendan Shanks bshanks@codeweavers.com
Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- dlls/ntdll/signal_arm.c | 7 ++++++- dlls/ntdll/signal_arm64.c | 7 ++++++- dlls/ntdll/signal_i386.c | 7 ++++++- dlls/ntdll/signal_x86_64.c | 8 ++++++-- 4 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/dlls/ntdll/signal_arm.c b/dlls/ntdll/signal_arm.c index c4cf557edaf..d0229d934ce 100644 --- a/dlls/ntdll/signal_arm.c +++ b/dlls/ntdll/signal_arm.c @@ -36,6 +36,7 @@ #include "winnt.h"
WINE_DEFAULT_DEBUG_CHANNEL(seh); +WINE_DECLARE_DEBUG_CHANNEL(threadname);
typedef struct _SCOPE_TABLE { @@ -476,7 +477,11 @@ NTSTATUS WINAPI KiUserExceptionDispatcher( EXCEPTION_RECORD *rec, CONTEXT *conte } else if (rec->ExceptionCode == EXCEPTION_WINE_NAME_THREAD && rec->ExceptionInformation[0] == 0x1000) { - WARN( "Thread %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], debugstr_a((char *)rec->ExceptionInformation[1]) ); + if ((DWORD)rec->ExceptionInformation[2] == -1) + WARN_(threadname)( "Thread renamed to %s\n", debugstr_a((char *)rec->ExceptionInformation[1]) ); + else + WARN_(threadname)( "Thread ID %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], + debugstr_a((char *)rec->ExceptionInformation[1]) ); } else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C) { diff --git a/dlls/ntdll/signal_arm64.c b/dlls/ntdll/signal_arm64.c index fba0da48a16..959c3ea50dc 100644 --- a/dlls/ntdll/signal_arm64.c +++ b/dlls/ntdll/signal_arm64.c @@ -38,6 +38,7 @@ #include "winnt.h"
WINE_DEFAULT_DEBUG_CHANNEL(seh); +WINE_DECLARE_DEBUG_CHANNEL(threadname);
typedef struct _SCOPE_TABLE { @@ -508,7 +509,11 @@ NTSTATUS WINAPI KiUserExceptionDispatcher( EXCEPTION_RECORD *rec, CONTEXT *conte } else if (rec->ExceptionCode == EXCEPTION_WINE_NAME_THREAD && rec->ExceptionInformation[0] == 0x1000) { - WARN( "Thread %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], debugstr_a((char *)rec->ExceptionInformation[1]) ); + if ((DWORD)rec->ExceptionInformation[2] == -1) + WARN_(threadname)( "Thread renamed to %s\n", debugstr_a((char *)rec->ExceptionInformation[1]) ); + else + WARN_(threadname)( "Thread ID %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], + debugstr_a((char *)rec->ExceptionInformation[1]) ); } else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C) { diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index 14971032ce6..f4c935ecc94 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -35,6 +35,7 @@ #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(seh); +WINE_DECLARE_DEBUG_CHANNEL(threadname);
struct x86_thread_data { @@ -194,7 +195,11 @@ NTSTATUS WINAPI dispatch_exception( EXCEPTION_RECORD *rec, CONTEXT *context ) } else if (rec->ExceptionCode == EXCEPTION_WINE_NAME_THREAD && rec->ExceptionInformation[0] == 0x1000) { - WARN( "Thread %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], debugstr_a((char *)rec->ExceptionInformation[1]) ); + if ((DWORD)rec->ExceptionInformation[2] == -1) + WARN_(threadname)( "Thread renamed to %s\n", debugstr_a((char *)rec->ExceptionInformation[1]) ); + else + WARN_(threadname)( "Thread ID %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], + debugstr_a((char *)rec->ExceptionInformation[1]) ); } else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C) { diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c index fef163ac629..9957d0c3dfa 100644 --- a/dlls/ntdll/signal_x86_64.c +++ b/dlls/ntdll/signal_x86_64.c @@ -36,6 +36,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(unwind); WINE_DECLARE_DEBUG_CHANNEL(seh); +WINE_DECLARE_DEBUG_CHANNEL(threadname);
typedef struct _SCOPE_TABLE { @@ -525,8 +526,11 @@ NTSTATUS WINAPI dispatch_exception( EXCEPTION_RECORD *rec, CONTEXT *context ) } else if (rec->ExceptionCode == EXCEPTION_WINE_NAME_THREAD && rec->ExceptionInformation[0] == 0x1000) { - WARN_(seh)( "Thread %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], - debugstr_a((char *)rec->ExceptionInformation[1]) ); + if ((DWORD)rec->ExceptionInformation[2] == -1) + WARN_(threadname)( "Thread renamed to %s\n", debugstr_a((char *)rec->ExceptionInformation[1]) ); + else + WARN_(threadname)( "Thread ID %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], + debugstr_a((char *)rec->ExceptionInformation[1]) ); } else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C) {
From: Brendan Shanks bshanks@codeweavers.com
Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- dlls/ntdll/unix/thread.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index ad47a5fce74..ca1d1293d10 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -70,6 +70,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(thread); WINE_DECLARE_DEBUG_CHANNEL(seh); +WINE_DECLARE_DEBUG_CHANNEL(threadname);
static int nb_threads = 1;
@@ -2232,11 +2233,19 @@ NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class, case ThreadNameInformation: { const THREAD_NAME_INFORMATION *info = data; + THREAD_BASIC_INFORMATION tbi;
if (length != sizeof(*info)) return STATUS_INFO_LENGTH_MISMATCH; if (!info) return STATUS_ACCESS_VIOLATION; if (info->ThreadName.Length && !info->ThreadName.Buffer) return STATUS_ACCESS_VIOLATION;
+ if (handle == GetCurrentThread()) + WARN_(threadname)( "Thread renamed to %s\n", debugstr_us(&info->ThreadName) ); + else if (!NtQueryInformationThread( handle, ThreadBasicInformation, &tbi, sizeof(tbi), NULL )) + WARN_(threadname)( "Thread ID %04x renamed to %s\n", HandleToULong( tbi.ClientId.UniqueThread ), debugstr_us(&info->ThreadName) ); + else + WARN_(threadname)( "Thread handle %p renamed to %s\n", handle, debugstr_us(&info->ThreadName) ); + SERVER_START_REQ( set_thread_info ) { req->handle = wine_server_obj_handle( handle );
On Wed Jun 29 16:24:20 2022 +0000, Brendan Shanks wrote:
changed this line in [version 2 of the diff](/wine/wine/-/merge_requests/89/diffs?diff_id=3653&start_sha=6cbfc2d8a1043bd2b7acea3ef8afd6e58afd32d0#4fedec6e09794eef4b0f628a9663c00d63528441_427_423)
Good point, it now prints the ID rather than handle if possible. I also moved the prints from kernel base to ntdll.