mgorny created this revision. mgorny added reviewers: krytarowski, emaste, labath. Herald added a reviewer: JDevlieghere. mgorny requested review of this revision.
Remove the thread name caching code. It does not handle the possibility of thread name changing between requests, therefore breaking TestGdbRemoteThreadName. While technically we could cache the results and reset the cache on resuming process, the gain from doing that does not seem worth the effort. https://reviews.llvm.org/D90863 Files: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h lldb/test/API/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py Index: lldb/test/API/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py =================================================================== --- lldb/test/API/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py +++ lldb/test/API/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py @@ -29,7 +29,6 @@ self.assertEqual(expected_name, kv_dict.get("name")) @skipIfWindows # the test is not updated for Windows. - @expectedFailureAll(oslist=["freebsd"]) @llgs_test def test(self): """ Make sure lldb-server can retrieve inferior thread name""" Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h =================================================================== --- lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h +++ lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h @@ -74,7 +74,6 @@ using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; WatchpointIndexMap m_watchpoint_index_map; WatchpointIndexMap m_hw_break_index_map; - llvm::Optional<std::string> m_thread_name; }; typedef std::shared_ptr<NativeThreadFreeBSD> NativeThreadFreeBSDSP; Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp =================================================================== --- lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp +++ lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp @@ -149,41 +149,35 @@ } std::string NativeThreadFreeBSD::GetName() { - if (!m_thread_name) { - Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); - - std::vector<struct kinfo_proc> kp; - int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, - static_cast<int>(GetProcess().GetID())}; - - while (1) { - size_t len = kp.size() * sizeof(struct kinfo_proc); - void *ptr = len == 0 ? nullptr : kp.data(); - int error = ::sysctl(mib, 4, ptr, &len, nullptr, 0); - if (ptr == nullptr || (error != 0 && errno == ENOMEM)) { - kp.resize(len / sizeof(struct kinfo_proc)); - continue; - } - if (error != 0) { - len = 0; - LLDB_LOG(log, "tid = {0} in state {1} failed to get thread name: {2}", GetID(), - m_state, strerror(errno)); - } + Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); + + std::vector<struct kinfo_proc> kp; + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, + static_cast<int>(GetProcess().GetID())}; + + while (1) { + size_t len = kp.size() * sizeof(struct kinfo_proc); + void *ptr = len == 0 ? nullptr : kp.data(); + int error = ::sysctl(mib, 4, ptr, &len, nullptr, 0); + if (ptr == nullptr || (error != 0 && errno == ENOMEM)) { kp.resize(len / sizeof(struct kinfo_proc)); - break; + continue; } - - // empty == unknown - m_thread_name = std::string(); - for (auto& procinfo : kp) { - if (procinfo.ki_tid == (lwpid_t)GetID()) { - m_thread_name = procinfo.ki_tdname; - break; - } + if (error != 0) { + len = 0; + LLDB_LOG(log, "tid = {0} in state {1} failed to get thread name: {2}", GetID(), + m_state, strerror(errno)); } + kp.resize(len / sizeof(struct kinfo_proc)); + break; + } + + for (auto& procinfo : kp) { + if (procinfo.ki_tid == static_cast<lwpid_t>(GetID())) + return procinfo.ki_tdname; } - return m_thread_name.getValue(); + return ""; } lldb::StateType NativeThreadFreeBSD::GetState() { return m_state; }
Index: lldb/test/API/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py =================================================================== --- lldb/test/API/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py +++ lldb/test/API/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py @@ -29,7 +29,6 @@ self.assertEqual(expected_name, kv_dict.get("name")) @skipIfWindows # the test is not updated for Windows. - @expectedFailureAll(oslist=["freebsd"]) @llgs_test def test(self): """ Make sure lldb-server can retrieve inferior thread name""" Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h =================================================================== --- lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h +++ lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h @@ -74,7 +74,6 @@ using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; WatchpointIndexMap m_watchpoint_index_map; WatchpointIndexMap m_hw_break_index_map; - llvm::Optional<std::string> m_thread_name; }; typedef std::shared_ptr<NativeThreadFreeBSD> NativeThreadFreeBSDSP; Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp =================================================================== --- lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp +++ lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp @@ -149,41 +149,35 @@ } std::string NativeThreadFreeBSD::GetName() { - if (!m_thread_name) { - Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); - - std::vector<struct kinfo_proc> kp; - int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, - static_cast<int>(GetProcess().GetID())}; - - while (1) { - size_t len = kp.size() * sizeof(struct kinfo_proc); - void *ptr = len == 0 ? nullptr : kp.data(); - int error = ::sysctl(mib, 4, ptr, &len, nullptr, 0); - if (ptr == nullptr || (error != 0 && errno == ENOMEM)) { - kp.resize(len / sizeof(struct kinfo_proc)); - continue; - } - if (error != 0) { - len = 0; - LLDB_LOG(log, "tid = {0} in state {1} failed to get thread name: {2}", GetID(), - m_state, strerror(errno)); - } + Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); + + std::vector<struct kinfo_proc> kp; + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, + static_cast<int>(GetProcess().GetID())}; + + while (1) { + size_t len = kp.size() * sizeof(struct kinfo_proc); + void *ptr = len == 0 ? nullptr : kp.data(); + int error = ::sysctl(mib, 4, ptr, &len, nullptr, 0); + if (ptr == nullptr || (error != 0 && errno == ENOMEM)) { kp.resize(len / sizeof(struct kinfo_proc)); - break; + continue; } - - // empty == unknown - m_thread_name = std::string(); - for (auto& procinfo : kp) { - if (procinfo.ki_tid == (lwpid_t)GetID()) { - m_thread_name = procinfo.ki_tdname; - break; - } + if (error != 0) { + len = 0; + LLDB_LOG(log, "tid = {0} in state {1} failed to get thread name: {2}", GetID(), + m_state, strerror(errno)); } + kp.resize(len / sizeof(struct kinfo_proc)); + break; + } + + for (auto& procinfo : kp) { + if (procinfo.ki_tid == static_cast<lwpid_t>(GetID())) + return procinfo.ki_tdname; } - return m_thread_name.getValue(); + return ""; } lldb::StateType NativeThreadFreeBSD::GetState() { return m_state; }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits