#endif
GenerateConsoleCtrlEvent_ftype *GenerateConsoleCtrlEvent;
+#define GetThreadDescription dyn_GetThreadDescription
+typedef HRESULT WINAPI (GetThreadDescription_ftype) (HANDLE, PWSTR *);
+static GetThreadDescription_ftype *GetThreadDescription;
+
/* Note that 'debug_events' must be locally defined in the relevant
functions. */
#define DEBUG_EVENTS(fmt, ...) \
suspended = 0;
}
+const char *
+windows_thread_info::thread_name ()
+{
+ if (GetThreadDescription != nullptr)
+ {
+ PWSTR value;
+ HRESULT result = GetThreadDescription (h, &value);
+ if (SUCCEEDED (result))
+ {
+ size_t needed = wcstombs (nullptr, value, 0);
+ if (needed != (size_t) -1)
+ {
+ name.reset ((char *) xmalloc (needed));
+ if (wcstombs (name.get (), value, needed) == (size_t) -1)
+ name.reset ();
+ }
+ LocalFree (value);
+ }
+ }
+
+ return name.get ();
+}
+
/* Return the name of the DLL referenced by H at ADDRESS. UNICODE
determines what sort of string is read from the inferior. Returns
the name of the DLL, or NULL on error. If a name is returned, it
GPA (hm, Wow64GetThreadSelectorEntry);
#endif
GPA (hm, GenerateConsoleCtrlEvent);
+ GPA (hm, GetThreadDescription);
}
/* Set variables to dummy versions of these processes if the function
OpenProcessToken = bad;
}
+ /* On some versions of Windows, this function is only available in
+ KernelBase.dll, not kernel32.dll. */
+ if (GetThreadDescription == nullptr)
+ {
+ hm = LoadLibrary (TEXT ("KernelBase.dll"));
+ if (hm)
+ GPA (hm, GetThreadDescription);
+ }
+
#undef GPA
return result;
const char *
windows_nat_target::thread_name (struct thread_info *thr)
{
- return windows_process.thread_rec (thr->ptid,
- DONT_INVALIDATE_CONTEXT)->name.get ();
+ windows_thread_info *th
+ = windows_process.thread_rec (thr->ptid,
+ DONT_INVALIDATE_CONTEXT);
+ return th->thread_name ();
}