[Lldb-commits] [PATCH] D90298: [lldb] [Process/FreeBSDRemote] Implement thread GetName()
Michał Górny via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 3 00:46:42 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG326d23530081: [lldb] [Process/FreeBSDRemote] Implement thread GetName() (authored by mgorny).
Herald added a project: LLDB.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90298/new/
https://reviews.llvm.org/D90298
Files:
lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h
Index: lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h
===================================================================
--- lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h
+++ lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.h
@@ -74,6 +74,7 @@
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
@@ -22,9 +22,11 @@
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/sysctl.h>
+#include <sys/user.h>
// clang-format on
#include <sstream>
+#include <vector>
using namespace lldb;
using namespace lldb_private;
@@ -146,7 +148,43 @@
m_stop_info.reason = StopReason::eStopReasonNone;
}
-std::string NativeThreadFreeBSD::GetName() { return ""; }
+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));
+ }
+ kp.resize(len / sizeof(struct kinfo_proc));
+ break;
+ }
+
+ // 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;
+ }
+ }
+ }
+
+ return m_thread_name.getValue();
+}
lldb::StateType NativeThreadFreeBSD::GetState() { return m_state; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90298.302491.patch
Type: text/x-patch
Size: 2481 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201103/aff1c0a2/attachment.bin>
More information about the lldb-commits
mailing list