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.
From: Brendan Shanks bshanks@codeweavers.com
Signed-off-by: Brendan Shanks bshanks@codeweavers.com --- dlls/kernelbase/thread.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/dlls/kernelbase/thread.c b/dlls/kernelbase/thread.c index 6ba58cf0a67..c7c411a9e0a 100644 --- a/dlls/kernelbase/thread.c +++ b/dlls/kernelbase/thread.c @@ -37,6 +37,7 @@ #include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(thread); +WINE_DECLARE_DEBUG_CHANNEL(threadname);
/*********************************************************************** @@ -420,7 +421,10 @@ HRESULT WINAPI DECLSPEC_HOTPATCH SetThreadDescription( HANDLE thread, PCWSTR des THREAD_NAME_INFORMATION info; int length;
- TRACE( "(%p, %s)\n", thread, debugstr_w( description )); + if (thread == GetCurrentThread()) + WARN_(threadname)( "Thread renamed to %s\n", debugstr_w( description )); + else + WARN_(threadname)( "Thread handle %p renamed to %s\n", thread, debugstr_w( description ));
length = description ? lstrlenW( description ) * sizeof(WCHAR) : 0;
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 7872962bbbe..34abe905d94 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 { @@ -475,7 +476,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 034c78f6b4d..4b4edf1a878 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 { @@ -507,7 +508,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 7e77329363c..622740d91dd 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) {
Alexandre Julliard (@julliard) commented about dlls/kernelbase/thread.c:
THREAD_NAME_INFORMATION info; int length;
- TRACE( "(%p, %s)\n", thread, debugstr_w( description ));
- if (thread == GetCurrentThread())
WARN_(threadname)( "Thread renamed to %s\n", debugstr_w( description ));
- else
WARN_(threadname)( "Thread handle %p renamed to %s\n", thread, debugstr_w( description ));
Printing the handle value is not very useful, it would be nicer to get the thread id from the handle if we can.