diff options
| author | Michał Górny <mgorny@gentoo.org> | 2019-11-17 22:01:19 +0100 |
|---|---|---|
| committer | Michał Górny <mgorny@gentoo.org> | 2019-11-18 11:21:17 +0100 |
| commit | 23a766dcad47993f632ab22ab3a8f3dc977bd838 (patch) | |
| tree | e3080a4ec0d897bb2d22cea1c402304da59c5459 /lldb/source/Plugins/Process | |
| parent | e8924d6403eba06438f669e434eee11016f20a67 (diff) | |
| download | bcm5719-llvm-23a766dcad47993f632ab22ab3a8f3dc977bd838.tar.gz bcm5719-llvm-23a766dcad47993f632ab22ab3a8f3dc977bd838.zip | |
[lldb] [Process/NetBSD] Implement thread name getting
Implement thread name getting sysctl() on NetBSD. Also fix
the incorrect type in pthread_setname_np() in the relevant test.
Differential Revision: https://reviews.llvm.org/D70363
Diffstat (limited to 'lldb/source/Plugins/Process')
| -rw-r--r-- | lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp b/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp index e25975c9344..d732a72c932 100644 --- a/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp +++ b/lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp @@ -16,9 +16,15 @@ #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/RegisterValue.h" #include "lldb/Utility/State.h" +#include "llvm/Support/Errno.h" #include <sstream> +// clang-format off +#include <sys/types.h> +#include <sys/sysctl.h> +// clang-format on + using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_netbsd; @@ -105,7 +111,38 @@ void NativeThreadNetBSD::SetStepping() { m_stop_info.reason = StopReason::eStopReasonNone; } -std::string NativeThreadNetBSD::GetName() { return std::string(""); } +std::string NativeThreadNetBSD::GetName() { + Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); + + std::vector<struct kinfo_lwp> infos; + int mib[5] = {CTL_KERN, KERN_LWP, static_cast<int>(m_process.GetID()), + sizeof(struct kinfo_lwp), 0}; + size_t size; + + if (::sysctl(mib, 5, nullptr, &size, nullptr, 0) == -1 || size == 0) { + LLDB_LOG(log, "sysctl() for LWP info size failed: {0}", + llvm::sys::StrError()); + return ""; + } + + mib[4] = size / sizeof(size_t); + infos.resize(size / sizeof(struct kinfo_lwp)); + + if (sysctl(mib, 5, infos.data(), &size, NULL, 0) == -1 || size == 0) { + LLDB_LOG(log, "sysctl() for LWP info failed: {0}", llvm::sys::StrError()); + return ""; + } + + size_t nlwps = size / sizeof(struct kinfo_lwp); + for (size_t i = 0; i < nlwps; i++) { + if (static_cast<lldb::tid_t>(infos[i].l_lid) == m_tid) { + return infos[i].l_name; + } + } + + LLDB_LOG(log, "unable to find lwp {0} in LWP infos", m_tid); + return ""; +} lldb::StateType NativeThreadNetBSD::GetState() { return m_state; } |

