Implement Host::GetThreadName for FreeBSD

llvm-svn: 209312
This commit is contained in:
Ed Maste 2014-05-21 18:09:55 +00:00
parent ce7a1bd038
commit a45c1600dc
1 changed files with 29 additions and 0 deletions

View File

@ -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;
}