-
Notifications
You must be signed in to change notification settings - Fork 15.7k
[lldb] add support for thread names on Windows #74731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| #include "lldb/Utility/LLDBLog.h" | ||
| #include "lldb/Utility/Log.h" | ||
| #include "lldb/Utility/State.h" | ||
| #include "llvm/Support/ConvertUTF.h" | ||
|
|
||
| #include "ProcessWindows.h" | ||
| #include "ProcessWindowsLog.h" | ||
|
|
@@ -33,6 +34,9 @@ | |
| using namespace lldb; | ||
| using namespace lldb_private; | ||
|
|
||
| using GetThreadDescriptionFunctionPtr = HRESULT | ||
| WINAPI (*)(HANDLE hThread, PWSTR *ppszThreadDescription); | ||
|
|
||
| TargetThreadWindows::TargetThreadWindows(ProcessWindows &process, | ||
| const HostThread &thread) | ||
| : Thread(process, thread.GetNativeThread().GetThreadId()), | ||
|
|
@@ -175,3 +179,30 @@ Status TargetThreadWindows::DoResume() { | |
|
|
||
| return Status(); | ||
| } | ||
|
|
||
| const char *TargetThreadWindows::GetName() { | ||
| Log *log = GetLog(LLDBLog::Thread); | ||
| HMODULE hModule = ::LoadLibraryW(L"Kernel32.dll"); | ||
| if (hModule) { | ||
| auto GetThreadDescription = | ||
|
||
| reinterpret_cast<GetThreadDescriptionFunctionPtr>( | ||
| ::GetProcAddress(hModule, "GetThreadDescription")); | ||
|
||
| LLDB_LOGF(log, "GetProcAddress: %p", | ||
| reinterpret_cast<void *>(GetThreadDescription)); | ||
| if (GetThreadDescription) { | ||
|
||
| PWSTR pszThreadName; | ||
| if (SUCCEEDED(GetThreadDescription( | ||
| m_host_thread.GetNativeThread().GetSystemHandle(), | ||
| &pszThreadName))) { | ||
| LLDB_LOGF(log, "GetThreadDescription: %ls", pszThreadName); | ||
| llvm::convertUTF16ToUTF8String( | ||
| llvm::ArrayRef(reinterpret_cast<char *>(pszThreadName), | ||
| wcslen(pszThreadName) * sizeof(wchar_t)), | ||
| m_name); | ||
| ::LocalFree(pszThreadName); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return m_name.c_str(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.