diff options
author | Pavel Labath <labath@google.com> | 2017-03-17 09:51:23 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2017-03-17 09:51:23 +0000 |
commit | 225b79524de987d810f4085e6a1bf61a289e4adf (patch) | |
tree | ce526121fcde21c1dd730c01c9629b3d3a465d3e /lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp | |
parent | c7c9b75804e8cd0f25b421fc5146213dc482e95b (diff) | |
download | bcm5719-llvm-225b79524de987d810f4085e6a1bf61a289e4adf.tar.gz bcm5719-llvm-225b79524de987d810f4085e6a1bf61a289e4adf.zip |
Remove HostThreadLinux/Free/NetBSD
Summary:
These classes existed only because of the GetName() static function,
which can be moved to a more natural place anyway. I move the linux
version to NativeProcessLinux (and get rid of ProcFileReader), the
freebsd version to ProcessFreeBSD (and fix a bug where it was using the
current process ID, instead of the inferior pid), and remove the NetBSD
version (which was probably incorrect anyway, as it assumes the current
process instead of the inferior.
I also add an llgs test to that verifies thread names are read
correctly.
Reviewers: zturner, krytarowski, emaste
Subscribers: lldb-commits, mgorny
Differential Revision: https://reviews.llvm.org/D30981
llvm-svn: 298058
Diffstat (limited to 'lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp b/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp index 91a1bc989d9..6e9cc9c13b0 100644 --- a/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp +++ b/lldb/source/Plugins/Process/FreeBSD/FreeBSDThread.cpp @@ -113,9 +113,41 @@ void FreeBSDThread::SetName(const char *name) { const char *FreeBSDThread::GetName() { if (!m_thread_name_valid) { - llvm::SmallString<32> thread_name; - HostNativeThread::GetName(GetID(), thread_name); - m_thread_name = thread_name.c_str(); + m_thread_name.clear(); + int pid = GetProcess()->GetID(); + + struct kinfo_proc *kp = nullptr, *nkp; + size_t len = 0; + int error; + int ctl[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, + pid}; + + while (1) { + error = sysctl(ctl, 4, kp, &len, nullptr, 0); + if (kp == nullptr || (error != 0 && errno == ENOMEM)) { + // Add extra space in case threads are added before next call. + len += sizeof(*kp) + len / 10; + nkp = (struct kinfo_proc *)realloc(kp, len); + if (nkp == nullptr) { + free(kp); + return nullptr; + } + kp = nkp; + continue; + } + if (error != 0) + len = 0; + break; + } + + for (size_t i = 0; i < len / sizeof(*kp); i++) { + if (kp[i].ki_tid == (lwpid_t)tid) { + m_thread_name.append(kp[i].ki_tdname, + kp[i].ki_tdname + strlen(kp[i].ki_tdname)); + break; + } + } + free(kp); m_thread_name_valid = true; } |