Commit 93577c00 authored by Brendan Shanks's avatar Brendan Shanks Committed by Alexandre Julliard

ntdll: Add native thread renaming for exception method.

parent d3416d90
......@@ -20,6 +20,7 @@
#define __WINE_NTDLL_MISC_H
#include <stdarg.h>
#include <stdlib.h>
#include <sys/types.h>
#include "windef.h"
......@@ -61,6 +62,7 @@ extern RUNTIME_FUNCTION *lookup_function_info( ULONG_PTR pc, ULONG_PTR *base, LD
/* debug helpers */
extern LPCSTR debugstr_us( const UNICODE_STRING *str ) DECLSPEC_HIDDEN;
extern const char *debugstr_exception_code( DWORD code ) DECLSPEC_HIDDEN;
extern void set_native_thread_name( DWORD tid, const char *name ) DECLSPEC_HIDDEN;
/* init routines */
extern void version_init(void) DECLSPEC_HIDDEN;
......
......@@ -482,6 +482,8 @@ NTSTATUS WINAPI KiUserExceptionDispatcher( EXCEPTION_RECORD *rec, CONTEXT *conte
else
WARN_(threadname)( "Thread ID %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2],
debugstr_a((char *)rec->ExceptionInformation[1]) );
set_native_thread_name((DWORD)rec->ExceptionInformation[2], (char *)rec->ExceptionInformation[1]);
}
else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C)
{
......
......@@ -514,6 +514,8 @@ NTSTATUS WINAPI KiUserExceptionDispatcher( EXCEPTION_RECORD *rec, CONTEXT *conte
else
WARN_(threadname)( "Thread ID %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2],
debugstr_a((char *)rec->ExceptionInformation[1]) );
set_native_thread_name((DWORD)rec->ExceptionInformation[2], (char *)rec->ExceptionInformation[1]);
}
else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C)
{
......
......@@ -200,6 +200,8 @@ NTSTATUS WINAPI dispatch_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
else
WARN_(threadname)( "Thread ID %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2],
debugstr_a((char *)rec->ExceptionInformation[1]) );
set_native_thread_name((DWORD)rec->ExceptionInformation[2], (char *)rec->ExceptionInformation[1]);
}
else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C)
{
......
......@@ -531,6 +531,8 @@ NTSTATUS WINAPI dispatch_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
else
WARN_(threadname)( "Thread ID %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2],
debugstr_a((char *)rec->ExceptionInformation[1]) );
set_native_thread_name((DWORD)rec->ExceptionInformation[2], (char *)rec->ExceptionInformation[1]);
}
else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C)
{
......
......@@ -179,6 +179,51 @@ int __cdecl __wine_dbg_output( const char *str )
/***********************************************************************
* set_native_thread_name
*/
void set_native_thread_name( DWORD tid, const char *name )
{
THREAD_NAME_INFORMATION info;
HANDLE h = GetCurrentThread();
WCHAR nameW[64];
if (tid != -1)
{
OBJECT_ATTRIBUTES attr;
CLIENT_ID cid;
attr.Length = sizeof(attr);
attr.RootDirectory = 0;
attr.Attributes = 0;
attr.ObjectName = NULL;
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
cid.UniqueProcess = 0;
cid.UniqueThread = ULongToHandle( tid );
if (NtOpenThread( &h, THREAD_QUERY_LIMITED_INFORMATION, &attr, &cid )) return;
}
if (name)
{
mbstowcs( nameW, name, ARRAY_SIZE(nameW) );
nameW[ARRAY_SIZE(nameW) - 1] = '\0';
}
else
{
nameW[0] = '\0';
}
RtlInitUnicodeString( &info.ThreadName, nameW );
NtSetInformationThread( h, ThreadWineNativeThreadName, &info, sizeof(info) );
if (h != GetCurrentThread())
NtClose(h);
}
/***********************************************************************
* RtlExitUserThread (NTDLL.@)
*/
void WINAPI RtlExitUserThread( ULONG status )
......
......@@ -2304,6 +2304,16 @@ NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class,
return status;
}
case ThreadWineNativeThreadName:
{
const THREAD_NAME_INFORMATION *info = data;
if (length != sizeof(*info)) return STATUS_INFO_LENGTH_MISMATCH;
set_native_thread_name( handle, &info->ThreadName );
return STATUS_SUCCESS;
}
case ThreadWow64Context:
return set_thread_wow64_context( handle, data, length );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment