[Lldb-commits] [PATCH] D70363: [lldb] [test] Fix lldb-server/thread-name test code for NetBSD
mgorny created this revision. mgorny added reviewers: krytarowski, labath. Herald added a subscriber: jfb. Fix incorrect type passed to pthread_setname_np() on NetBSD. This fixes the test to build fine but the underlying function is still not implemented. https://reviews.llvm.org/D70363 Files: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp === --- lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp +++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp @@ -9,7 +9,7 @@ #elif defined(__linux__) ::pthread_setname_np(::pthread_self(), name); #elif defined(__NetBSD__) - ::pthread_setname_np(::pthread_self(), "%s", name); + ::pthread_setname_np(::pthread_self(), "%s", static_cast(name)); #endif } Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py === --- lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py +++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py @@ -30,7 +30,7 @@ self.assertEqual(expected_name, kv_dict.get("name")) @skipIfWindows # the test is not updated for Windows. -@skipIfNetBSD # build failure due to pthread_setname_np prototype +@expectedFailureNetBSD @llgs_test def test(self): """ Make sure lldb-server can retrieve inferior thread name""" Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp === --- lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp +++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp @@ -9,7 +9,7 @@ #elif defined(__linux__) ::pthread_setname_np(::pthread_self(), name); #elif defined(__NetBSD__) - ::pthread_setname_np(::pthread_self(), "%s", name); + ::pthread_setname_np(::pthread_self(), "%s", static_cast(name)); #endif } Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py === --- lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py +++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py @@ -30,7 +30,7 @@ self.assertEqual(expected_name, kv_dict.get("name")) @skipIfWindows # the test is not updated for Windows. -@skipIfNetBSD # build failure due to pthread_setname_np prototype +@expectedFailureNetBSD @llgs_test def test(self): """ Make sure lldb-server can retrieve inferior thread name""" ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D70363: [lldb] [Process/NetBSD] Implement thread name getting
mgorny updated this revision to Diff 229730. mgorny retitled this revision from "[lldb] [test] Fix lldb-server/thread-name test code for NetBSD" to "[lldb] [Process/NetBSD] Implement thread name getting". mgorny edited the summary of this revision. mgorny added a comment. Went a bit further and implemented the missing feature. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D70363/new/ https://reviews.llvm.org/D70363 Files: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp Index: lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp === --- lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp +++ lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp @@ -19,6 +19,8 @@ #include +#include + using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_netbsd; @@ -105,7 +107,37 @@ 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 infos; + int mib[5] = {CTL_KERN, KERN_LWP, static_cast(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}", strerror(errno)); +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}", strerror(errno)); +return ""; + } + + size_t nlwps = size / sizeof(struct kinfo_lwp); + for (size_t i = 0; i < nlwps; i++) { +if (static_cast(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; } Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp === --- lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp +++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp @@ -9,7 +9,8 @@ #elif defined(__linux__) ::pthread_setname_np(::pthread_self(), name); #elif defined(__NetBSD__) - ::pthread_setname_np(::pthread_self(), "%s", name); + ::pthread_setname_np(::pthread_self(), "%s", + const_cast(static_cast(name))); #endif } Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py === --- lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py +++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py @@ -30,7 +30,6 @@ self.assertEqual(expected_name, kv_dict.get("name")) @skipIfWindows # the test is not updated for Windows. -@skipIfNetBSD # build failure due to pthread_setname_np prototype @llgs_test def test(self): """ Make sure lldb-server can retrieve inferior thread name""" Index: lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp === --- lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp +++ lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp @@ -19,6 +19,8 @@ #include +#include + using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_netbsd; @@ -105,7 +107,37 @@ 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 infos; + int mib[5] = {CTL_KERN, KERN_LWP, static_cast(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}", strerror(errno)); +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}", strerror(errno)); +return ""; + } + + size_t nlwps = size / sizeof(struct kinfo_lwp); + for (size_t i = 0; i < nlwps; i++) { +if (static_cast(infos[i].l_lid) == m_tid) { + return infos[i].l_name
[Lldb-commits] [PATCH] D70363: [lldb] [Process/NetBSD] Implement thread name getting
krytarowski added inline comments. Comment at: lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp:22 +#include + Please include before this header ``. If it works, that header is likely pulled from some indirect location. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D70363/new/ https://reviews.llvm.org/D70363 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D70363: [lldb] [Process/NetBSD] Implement thread name getting
mgorny updated this revision to Diff 229751. mgorny added a comment. Added sys/types.h. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D70363/new/ https://reviews.llvm.org/D70363 Files: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp Index: lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp === --- lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp +++ lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp @@ -19,6 +19,11 @@ #include +// clang-format off +#include +#include +// clang-format on + using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_netbsd; @@ -105,7 +110,37 @@ 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 infos; + int mib[5] = {CTL_KERN, KERN_LWP, static_cast(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}", strerror(errno)); +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}", strerror(errno)); +return ""; + } + + size_t nlwps = size / sizeof(struct kinfo_lwp); + for (size_t i = 0; i < nlwps; i++) { +if (static_cast(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; } Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp === --- lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp +++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp @@ -9,7 +9,8 @@ #elif defined(__linux__) ::pthread_setname_np(::pthread_self(), name); #elif defined(__NetBSD__) - ::pthread_setname_np(::pthread_self(), "%s", name); + ::pthread_setname_np(::pthread_self(), "%s", + const_cast(static_cast(name))); #endif } Index: lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py === --- lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py +++ lldb/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py @@ -30,7 +30,6 @@ self.assertEqual(expected_name, kv_dict.get("name")) @skipIfWindows # the test is not updated for Windows. -@skipIfNetBSD # build failure due to pthread_setname_np prototype @llgs_test def test(self): """ Make sure lldb-server can retrieve inferior thread name""" Index: lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp === --- lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp +++ lldb/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp @@ -19,6 +19,11 @@ #include +// clang-format off +#include +#include +// clang-format on + using namespace lldb; using namespace lldb_private; using namespace lldb_private::process_netbsd; @@ -105,7 +110,37 @@ 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 infos; + int mib[5] = {CTL_KERN, KERN_LWP, static_cast(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}", strerror(errno)); +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}", strerror(errno)); +return ""; + } + + size_t nlwps = size / sizeof(struct kinfo_lwp); + for (size_t i = 0; i < nlwps; i++) { +if (static_cast(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::G