summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Maste <emaste@freebsd.org>2014-05-21 18:09:55 +0000
committerEd Maste <emaste@freebsd.org>2014-05-21 18:09:55 +0000
commita45c1600dca0d210761f2d6a0b599a7493964140 (patch)
tree927ec427227688168e1f651cc14922670bd4febd
parentce7a1bd038aa383646752cbdfd5c688952dc72d9 (diff)
downloadbcm5719-llvm-a45c1600dca0d210761f2d6a0b599a7493964140.tar.gz
bcm5719-llvm-a45c1600dca0d210761f2d6a0b599a7493964140.zip
Implement Host::GetThreadName for FreeBSD
llvm-svn: 209312
-rw-r--r--lldb/source/Host/freebsd/Host.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/lldb/source/Host/freebsd/Host.cpp b/lldb/source/Host/freebsd/Host.cpp
index d508c4e9c5c..4f6af67dbd0 100644
--- a/lldb/source/Host/freebsd/Host.cpp
+++ b/lldb/source/Host/freebsd/Host.cpp
@@ -86,7 +86,36 @@ Host::ThreadCreated (const char *thread_name)
std::string
Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid)
{
+ struct kinfo_proc *kp = nullptr;
+ size_t len = 0;
+ int error;
+ int name[4] = {
+ CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, (int)pid
+ };
+
+ while (1) {
+ error = sysctl(name, 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;
+ kp = (struct kinfo_proc *)reallocf(kp, len);
+ if (kp == nullptr)
+ return std::string();
+ continue;
+ }
+ if (error != 0)
+ len = 0;
+ break;
+ }
+
std::string thread_name;
+ for (size_t i = 0; i < len / sizeof(*kp); i++) {
+ if (kp[i].ki_tid == (int)tid) {
+ thread_name = kp[i].ki_tdname;
+ break;
+ }
+ }
+ free(kp);
return thread_name;
}
OpenPOWER on IntegriCloud