summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/freebsd
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Host/freebsd')
-rw-r--r--lldb/source/Host/freebsd/Host.cpp418
-rw-r--r--lldb/source/Host/freebsd/HostInfoFreeBSD.cpp100
-rw-r--r--lldb/source/Host/freebsd/HostThreadFreeBSD.cpp77
-rw-r--r--lldb/source/Host/freebsd/ThisThread.cpp24
4 files changed, 286 insertions, 333 deletions
diff --git a/lldb/source/Host/freebsd/Host.cpp b/lldb/source/Host/freebsd/Host.cpp
index cf53cda40b1..5b1576260f3 100644
--- a/lldb/source/Host/freebsd/Host.cpp
+++ b/lldb/source/Host/freebsd/Host.cpp
@@ -1,4 +1,5 @@
-//===-- source/Host/freebsd/Host.cpp ------------------------------*- C++ -*-===//
+//===-- source/Host/freebsd/Host.cpp ------------------------------*- C++
+//-*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -8,32 +9,32 @@
//===----------------------------------------------------------------------===//
// C Includes
-#include <stdio.h>
#include <dlfcn.h>
#include <execinfo.h>
+#include <stdio.h>
+#include <sys/proc.h>
+#include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/user.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
-#include <sys/ptrace.h>
-#include <sys/exec.h>
#include <machine/elf.h>
+#include <sys/exec.h>
+#include <sys/ptrace.h>
// C++ Includes
// Other libraries and framework includes
// Project includes
+#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Error.h"
-#include "lldb/Host/Endian.h"
-#include "lldb/Host/Host.h"
-#include "lldb/Host/HostInfo.h"
+#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StreamString.h"
-#include "lldb/Core/Log.h"
-#include "lldb/Target/Process.h"
+#include "lldb/Host/Endian.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostInfo.h"
#include "lldb/Target/Platform.h"
+#include "lldb/Target/Process.h"
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/DataExtractor.h"
@@ -43,241 +44,220 @@
#include "llvm/Support/Host.h"
extern "C" {
- extern char **environ;
+extern char **environ;
}
using namespace lldb;
using namespace lldb_private;
-size_t
-Host::GetEnvironment (StringList &env)
-{
- char *v;
- char **var = environ;
- for (; var != NULL && *var != NULL; ++var)
- {
- v = strchr(*var, (int)'-');
- if (v == NULL)
- continue;
- env.AppendString(v);
- }
- return env.GetSize();
+size_t Host::GetEnvironment(StringList &env) {
+ char *v;
+ char **var = environ;
+ for (; var != NULL && *var != NULL; ++var) {
+ v = strchr(*var, (int)'-');
+ if (v == NULL)
+ continue;
+ env.AppendString(v);
+ }
+ return env.GetSize();
}
static bool
-GetFreeBSDProcessArgs (const ProcessInstanceInfoMatch *match_info_ptr,
- ProcessInstanceInfo &process_info)
-{
- if (process_info.ProcessIDIsValid())
- {
- int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, (int)process_info.GetProcessID() };
-
- char arg_data[8192];
- size_t arg_data_size = sizeof(arg_data);
- if (::sysctl (mib, 4, arg_data, &arg_data_size , NULL, 0) == 0)
- {
- DataExtractor data (arg_data, arg_data_size, endian::InlHostByteOrder(), sizeof(void *));
- lldb::offset_t offset = 0;
- const char *cstr;
-
- cstr = data.GetCStr (&offset);
- if (cstr)
- {
- process_info.GetExecutableFile().SetFile(cstr, false);
-
- if (!(match_info_ptr == NULL ||
- NameMatches (process_info.GetExecutableFile().GetFilename().GetCString(),
- match_info_ptr->GetNameMatchType(),
- match_info_ptr->GetProcessInfo().GetName())))
- return false;
-
- Args &proc_args = process_info.GetArguments();
- while (1)
- {
- const uint8_t *p = data.PeekData(offset, 1);
- while ((p != NULL) && (*p == '\0') && offset < arg_data_size)
- {
- ++offset;
- p = data.PeekData(offset, 1);
- }
- if (p == NULL || offset >= arg_data_size)
- return true;
-
- cstr = data.GetCStr(&offset);
- if (cstr)
- proc_args.AppendArgument(cstr);
- else
- return true;
- }
- }
+GetFreeBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr,
+ ProcessInstanceInfo &process_info) {
+ if (process_info.ProcessIDIsValid()) {
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS,
+ (int)process_info.GetProcessID()};
+
+ char arg_data[8192];
+ size_t arg_data_size = sizeof(arg_data);
+ if (::sysctl(mib, 4, arg_data, &arg_data_size, NULL, 0) == 0) {
+ DataExtractor data(arg_data, arg_data_size, endian::InlHostByteOrder(),
+ sizeof(void *));
+ lldb::offset_t offset = 0;
+ const char *cstr;
+
+ cstr = data.GetCStr(&offset);
+ if (cstr) {
+ process_info.GetExecutableFile().SetFile(cstr, false);
+
+ if (!(match_info_ptr == NULL ||
+ NameMatches(
+ process_info.GetExecutableFile().GetFilename().GetCString(),
+ match_info_ptr->GetNameMatchType(),
+ match_info_ptr->GetProcessInfo().GetName())))
+ return false;
+
+ Args &proc_args = process_info.GetArguments();
+ while (1) {
+ const uint8_t *p = data.PeekData(offset, 1);
+ while ((p != NULL) && (*p == '\0') && offset < arg_data_size) {
+ ++offset;
+ p = data.PeekData(offset, 1);
+ }
+ if (p == NULL || offset >= arg_data_size)
+ return true;
+
+ cstr = data.GetCStr(&offset);
+ if (cstr)
+ proc_args.AppendArgument(cstr);
+ else
+ return true;
}
+ }
}
- return false;
+ }
+ return false;
}
-static bool
-GetFreeBSDProcessCPUType (ProcessInstanceInfo &process_info)
-{
- if (process_info.ProcessIDIsValid())
- {
- process_info.GetArchitecture() = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
- return true;
- }
- process_info.GetArchitecture().Clear();
- return false;
+static bool GetFreeBSDProcessCPUType(ProcessInstanceInfo &process_info) {
+ if (process_info.ProcessIDIsValid()) {
+ process_info.GetArchitecture() =
+ HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
+ return true;
+ }
+ process_info.GetArchitecture().Clear();
+ return false;
}
-static bool
-GetFreeBSDProcessUserAndGroup(ProcessInstanceInfo &process_info)
-{
- struct kinfo_proc proc_kinfo;
- size_t proc_kinfo_size;
-
- if (process_info.ProcessIDIsValid())
- {
- int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID,
- (int)process_info.GetProcessID() };
- proc_kinfo_size = sizeof(struct kinfo_proc);
-
- if (::sysctl (mib, 4, &proc_kinfo, &proc_kinfo_size, NULL, 0) == 0)
- {
- if (proc_kinfo_size > 0)
- {
- process_info.SetParentProcessID (proc_kinfo.ki_ppid);
- process_info.SetUserID (proc_kinfo.ki_ruid);
- process_info.SetGroupID (proc_kinfo.ki_rgid);
- process_info.SetEffectiveUserID (proc_kinfo.ki_uid);
- if (proc_kinfo.ki_ngroups > 0)
- process_info.SetEffectiveGroupID (proc_kinfo.ki_groups[0]);
- else
- process_info.SetEffectiveGroupID (UINT32_MAX);
- return true;
- }
- }
+static bool GetFreeBSDProcessUserAndGroup(ProcessInstanceInfo &process_info) {
+ struct kinfo_proc proc_kinfo;
+ size_t proc_kinfo_size;
+
+ if (process_info.ProcessIDIsValid()) {
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID,
+ (int)process_info.GetProcessID()};
+ proc_kinfo_size = sizeof(struct kinfo_proc);
+
+ if (::sysctl(mib, 4, &proc_kinfo, &proc_kinfo_size, NULL, 0) == 0) {
+ if (proc_kinfo_size > 0) {
+ process_info.SetParentProcessID(proc_kinfo.ki_ppid);
+ process_info.SetUserID(proc_kinfo.ki_ruid);
+ process_info.SetGroupID(proc_kinfo.ki_rgid);
+ process_info.SetEffectiveUserID(proc_kinfo.ki_uid);
+ if (proc_kinfo.ki_ngroups > 0)
+ process_info.SetEffectiveGroupID(proc_kinfo.ki_groups[0]);
+ else
+ process_info.SetEffectiveGroupID(UINT32_MAX);
+ return true;
+ }
}
- process_info.SetParentProcessID (LLDB_INVALID_PROCESS_ID);
- process_info.SetUserID (UINT32_MAX);
- process_info.SetGroupID (UINT32_MAX);
- process_info.SetEffectiveUserID (UINT32_MAX);
- process_info.SetEffectiveGroupID (UINT32_MAX);
- return false;
+ }
+ process_info.SetParentProcessID(LLDB_INVALID_PROCESS_ID);
+ process_info.SetUserID(UINT32_MAX);
+ process_info.SetGroupID(UINT32_MAX);
+ process_info.SetEffectiveUserID(UINT32_MAX);
+ process_info.SetEffectiveGroupID(UINT32_MAX);
+ return false;
}
-uint32_t
-Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos)
-{
- std::vector<struct kinfo_proc> kinfos;
-
- int mib[3] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
-
- size_t pid_data_size = 0;
- if (::sysctl (mib, 3, NULL, &pid_data_size, NULL, 0) != 0)
- return 0;
-
- // Add a few extra in case a few more show up
- const size_t estimated_pid_count = (pid_data_size / sizeof(struct kinfo_proc)) + 10;
-
- kinfos.resize (estimated_pid_count);
- pid_data_size = kinfos.size() * sizeof(struct kinfo_proc);
-
- if (::sysctl (mib, 3, &kinfos[0], &pid_data_size, NULL, 0) != 0)
- return 0;
-
- const size_t actual_pid_count = (pid_data_size / sizeof(struct kinfo_proc));
-
- bool all_users = match_info.GetMatchAllUsers();
- const ::pid_t our_pid = getpid();
- const uid_t our_uid = getuid();
- for (size_t i = 0; i < actual_pid_count; i++)
- {
- const struct kinfo_proc &kinfo = kinfos[i];
- const bool kinfo_user_matches = (all_users ||
- (kinfo.ki_ruid == our_uid) ||
- // Special case, if lldb is being run as root we can attach to anything.
- (our_uid == 0)
- );
-
- if (kinfo_user_matches == false || // Make sure the user is acceptable
- kinfo.ki_pid == our_pid || // Skip this process
- kinfo.ki_pid == 0 || // Skip kernel (kernel pid is zero)
- kinfo.ki_stat == SZOMB || // Zombies are bad, they like brains...
- kinfo.ki_flag & P_TRACED || // Being debugged?
- kinfo.ki_flag & P_WEXIT) // Working on exiting
- continue;
-
- // Every thread is a process in FreeBSD, but all the threads of a single process
- // have the same pid. Do not store the process info in the result list if a process
- // with given identifier is already registered there.
- bool already_registered = false;
- for (uint32_t pi = 0;
- !already_registered &&
- (const int)kinfo.ki_numthreads > 1 &&
- pi < (const uint32_t)process_infos.GetSize(); pi++)
- already_registered = (process_infos.GetProcessIDAtIndex(pi) == (uint32_t)kinfo.ki_pid);
-
- if (already_registered)
- continue;
-
- ProcessInstanceInfo process_info;
- process_info.SetProcessID (kinfo.ki_pid);
- process_info.SetParentProcessID (kinfo.ki_ppid);
- process_info.SetUserID (kinfo.ki_ruid);
- process_info.SetGroupID (kinfo.ki_rgid);
- process_info.SetEffectiveUserID (kinfo.ki_svuid);
- process_info.SetEffectiveGroupID (kinfo.ki_svgid);
-
- // Make sure our info matches before we go fetch the name and cpu type
- if (match_info.Matches (process_info) &&
- GetFreeBSDProcessArgs (&match_info, process_info))
- {
- GetFreeBSDProcessCPUType (process_info);
- if (match_info.Matches (process_info))
- process_infos.Append (process_info);
- }
+uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
+ ProcessInstanceInfoList &process_infos) {
+ std::vector<struct kinfo_proc> kinfos;
+
+ int mib[3] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
+
+ size_t pid_data_size = 0;
+ if (::sysctl(mib, 3, NULL, &pid_data_size, NULL, 0) != 0)
+ return 0;
+
+ // Add a few extra in case a few more show up
+ const size_t estimated_pid_count =
+ (pid_data_size / sizeof(struct kinfo_proc)) + 10;
+
+ kinfos.resize(estimated_pid_count);
+ pid_data_size = kinfos.size() * sizeof(struct kinfo_proc);
+
+ if (::sysctl(mib, 3, &kinfos[0], &pid_data_size, NULL, 0) != 0)
+ return 0;
+
+ const size_t actual_pid_count = (pid_data_size / sizeof(struct kinfo_proc));
+
+ bool all_users = match_info.GetMatchAllUsers();
+ const ::pid_t our_pid = getpid();
+ const uid_t our_uid = getuid();
+ for (size_t i = 0; i < actual_pid_count; i++) {
+ const struct kinfo_proc &kinfo = kinfos[i];
+ const bool kinfo_user_matches = (all_users || (kinfo.ki_ruid == our_uid) ||
+ // Special case, if lldb is being run as
+ // root we can attach to anything.
+ (our_uid == 0));
+
+ if (kinfo_user_matches == false || // Make sure the user is acceptable
+ kinfo.ki_pid == our_pid || // Skip this process
+ kinfo.ki_pid == 0 || // Skip kernel (kernel pid is zero)
+ kinfo.ki_stat == SZOMB || // Zombies are bad, they like brains...
+ kinfo.ki_flag & P_TRACED || // Being debugged?
+ kinfo.ki_flag & P_WEXIT) // Working on exiting
+ continue;
+
+ // Every thread is a process in FreeBSD, but all the threads of a single
+ // process
+ // have the same pid. Do not store the process info in the result list if a
+ // process
+ // with given identifier is already registered there.
+ bool already_registered = false;
+ for (uint32_t pi = 0;
+ !already_registered && (const int)kinfo.ki_numthreads > 1 &&
+ pi < (const uint32_t)process_infos.GetSize();
+ pi++)
+ already_registered =
+ (process_infos.GetProcessIDAtIndex(pi) == (uint32_t)kinfo.ki_pid);
+
+ if (already_registered)
+ continue;
+
+ ProcessInstanceInfo process_info;
+ process_info.SetProcessID(kinfo.ki_pid);
+ process_info.SetParentProcessID(kinfo.ki_ppid);
+ process_info.SetUserID(kinfo.ki_ruid);
+ process_info.SetGroupID(kinfo.ki_rgid);
+ process_info.SetEffectiveUserID(kinfo.ki_svuid);
+ process_info.SetEffectiveGroupID(kinfo.ki_svgid);
+
+ // Make sure our info matches before we go fetch the name and cpu type
+ if (match_info.Matches(process_info) &&
+ GetFreeBSDProcessArgs(&match_info, process_info)) {
+ GetFreeBSDProcessCPUType(process_info);
+ if (match_info.Matches(process_info))
+ process_infos.Append(process_info);
}
+ }
- return process_infos.GetSize();
+ return process_infos.GetSize();
}
-bool
-Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
-{
- process_info.SetProcessID(pid);
+bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
+ process_info.SetProcessID(pid);
- if (GetFreeBSDProcessArgs(NULL, process_info))
- {
- // should use libprocstat instead of going right into sysctl?
- GetFreeBSDProcessCPUType(process_info);
- GetFreeBSDProcessUserAndGroup(process_info);
- return true;
- }
+ if (GetFreeBSDProcessArgs(NULL, process_info)) {
+ // should use libprocstat instead of going right into sysctl?
+ GetFreeBSDProcessCPUType(process_info);
+ GetFreeBSDProcessUserAndGroup(process_info);
+ return true;
+ }
- process_info.Clear();
- return false;
+ process_info.Clear();
+ return false;
}
-lldb::DataBufferSP
-Host::GetAuxvData(lldb_private::Process *process)
-{
- int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_AUXV, 0 };
- size_t auxv_size = AT_COUNT * sizeof(Elf_Auxinfo);
- DataBufferSP buf_sp;
+lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) {
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_AUXV, 0};
+ size_t auxv_size = AT_COUNT * sizeof(Elf_Auxinfo);
+ DataBufferSP buf_sp;
- std::unique_ptr<DataBufferHeap> buf_ap(new DataBufferHeap(auxv_size, 0));
+ std::unique_ptr<DataBufferHeap> buf_ap(new DataBufferHeap(auxv_size, 0));
- mib[3] = process->GetID();
- if (::sysctl(mib, 4, buf_ap->GetBytes(), &auxv_size, NULL, 0) == 0) {
- buf_sp.reset(buf_ap.release());
- } else {
- perror("sysctl failed on auxv");
- }
+ mib[3] = process->GetID();
+ if (::sysctl(mib, 4, buf_ap->GetBytes(), &auxv_size, NULL, 0) == 0) {
+ buf_sp.reset(buf_ap.release());
+ } else {
+ perror("sysctl failed on auxv");
+ }
- return buf_sp;
+ return buf_sp;
}
-Error
-Host::ShellExpandArguments (ProcessLaunchInfo &launch_info)
-{
- return Error("unimplemented");
+Error Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
+ return Error("unimplemented");
}
-
diff --git a/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp b/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp
index d51109320c3..fb9d86678db 100644
--- a/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp
+++ b/lldb/source/Host/freebsd/HostInfoFreeBSD.cpp
@@ -11,81 +11,67 @@
#include <stdio.h>
#include <string.h>
-#include <sys/types.h>
#include <sys/sysctl.h>
+#include <sys/types.h>
#include <sys/utsname.h>
using namespace lldb_private;
-uint32_t
-HostInfoFreeBSD::GetMaxThreadNameLength()
-{
- return 16;
-}
+uint32_t HostInfoFreeBSD::GetMaxThreadNameLength() { return 16; }
-bool
-HostInfoFreeBSD::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update)
-{
- struct utsname un;
+bool HostInfoFreeBSD::GetOSVersion(uint32_t &major, uint32_t &minor,
+ uint32_t &update) {
+ struct utsname un;
- ::memset(&un, 0, sizeof(utsname));
- if (uname(&un) < 0)
- return false;
+ ::memset(&un, 0, sizeof(utsname));
+ if (uname(&un) < 0)
+ return false;
- int status = sscanf(un.release, "%u.%u", &major, &minor);
- return status == 2;
+ int status = sscanf(un.release, "%u.%u", &major, &minor);
+ return status == 2;
}
-bool
-HostInfoFreeBSD::GetOSBuildString(std::string &s)
-{
- int mib[2] = {CTL_KERN, KERN_OSREV};
- char osrev_str[12];
- uint32_t osrev = 0;
- size_t osrev_len = sizeof(osrev);
-
- if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0)
- {
- ::snprintf(osrev_str, sizeof(osrev_str), "%-8.8u", osrev);
- s.assign(osrev_str);
- return true;
- }
+bool HostInfoFreeBSD::GetOSBuildString(std::string &s) {
+ int mib[2] = {CTL_KERN, KERN_OSREV};
+ char osrev_str[12];
+ uint32_t osrev = 0;
+ size_t osrev_len = sizeof(osrev);
- s.clear();
- return false;
+ if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) {
+ ::snprintf(osrev_str, sizeof(osrev_str), "%-8.8u", osrev);
+ s.assign(osrev_str);
+ return true;
+ }
+
+ s.clear();
+ return false;
}
-bool
-HostInfoFreeBSD::GetOSKernelDescription(std::string &s)
-{
- struct utsname un;
+bool HostInfoFreeBSD::GetOSKernelDescription(std::string &s) {
+ struct utsname un;
- ::memset(&un, 0, sizeof(utsname));
- s.clear();
+ ::memset(&un, 0, sizeof(utsname));
+ s.clear();
- if (uname(&un) < 0)
- return false;
+ if (uname(&un) < 0)
+ return false;
- s.assign(un.version);
+ s.assign(un.version);
- return true;
+ return true;
}
-FileSpec
-HostInfoFreeBSD::GetProgramFileSpec()
-{
- static FileSpec g_program_filespec;
- if (!g_program_filespec)
- {
- int exe_path_mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid()};
- size_t exe_path_size;
- if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0)
- {
- char *exe_path = new char[exe_path_size];
- if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0)
- g_program_filespec.SetFile(exe_path, false);
- delete[] exe_path;
- }
+FileSpec HostInfoFreeBSD::GetProgramFileSpec() {
+ static FileSpec g_program_filespec;
+ if (!g_program_filespec) {
+ int exe_path_mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid()};
+ size_t exe_path_size;
+ if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0) {
+ char *exe_path = new char[exe_path_size];
+ if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0)
+ g_program_filespec.SetFile(exe_path, false);
+ delete[] exe_path;
}
- return g_program_filespec;
+ }
+ return g_program_filespec;
} \ No newline at end of file
diff --git a/lldb/source/Host/freebsd/HostThreadFreeBSD.cpp b/lldb/source/Host/freebsd/HostThreadFreeBSD.cpp
index a4302a9e67b..97d4d9d05b6 100644
--- a/lldb/source/Host/freebsd/HostThreadFreeBSD.cpp
+++ b/lldb/source/Host/freebsd/HostThreadFreeBSD.cpp
@@ -14,7 +14,7 @@
// C includes
#include <errno.h>
#include <pthread.h>
-#if defined (__FreeBSD__)
+#if defined(__FreeBSD__)
#include <pthread_np.h>
#endif
#include <stdlib.h>
@@ -26,54 +26,45 @@
using namespace lldb_private;
-HostThreadFreeBSD::HostThreadFreeBSD()
-{
-}
+HostThreadFreeBSD::HostThreadFreeBSD() {}
HostThreadFreeBSD::HostThreadFreeBSD(lldb::thread_t thread)
- : HostThreadPosix(thread)
-{
-}
+ : HostThreadPosix(thread) {}
-void
-HostThreadFreeBSD::GetName(lldb::tid_t tid, llvm::SmallVectorImpl<char> &name)
-{
- name.clear();
- int pid = Host::GetCurrentProcessID();
+void HostThreadFreeBSD::GetName(lldb::tid_t tid,
+ llvm::SmallVectorImpl<char> &name) {
+ name.clear();
+ int pid = Host::GetCurrentProcessID();
- 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, (int)pid};
+ 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,
+ (int)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;
- }
- kp = nkp;
- continue;
- }
- if (error != 0)
- len = 0;
- break;
+ 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;
+ }
+ 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)
- {
- name.append(kp[i].ki_tdname, kp[i].ki_tdname + strlen(kp[i].ki_tdname));
- break;
- }
+ for (size_t i = 0; i < len / sizeof(*kp); i++) {
+ if (kp[i].ki_tid == (lwpid_t)tid) {
+ name.append(kp[i].ki_tdname, kp[i].ki_tdname + strlen(kp[i].ki_tdname));
+ break;
}
- free(kp);
+ }
+ free(kp);
}
diff --git a/lldb/source/Host/freebsd/ThisThread.cpp b/lldb/source/Host/freebsd/ThisThread.cpp
index e524fd4ace3..da0f2379a87 100644
--- a/lldb/source/Host/freebsd/ThisThread.cpp
+++ b/lldb/source/Host/freebsd/ThisThread.cpp
@@ -7,33 +7,29 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/Host/HostNativeThread.h"
#include "lldb/Host/ThisThread.h"
+#include "lldb/Host/HostNativeThread.h"
#include "llvm/ADT/SmallVector.h"
#include <pthread.h>
-#if defined (__FreeBSD__)
+#if defined(__FreeBSD__)
#include <pthread_np.h>
#endif
using namespace lldb_private;
-void
-ThisThread::SetName(llvm::StringRef name)
-{
-#if defined (__FreeBSD__) // Kfreebsd does not have a simple alternative
- ::pthread_set_name_np(::pthread_self(), name.data());
+void ThisThread::SetName(llvm::StringRef name) {
+#if defined(__FreeBSD__) // Kfreebsd does not have a simple alternative
+ ::pthread_set_name_np(::pthread_self(), name.data());
#endif
}
-void
-ThisThread::GetName(llvm::SmallVectorImpl<char> &name)
-{
-#if defined (__FreeBSD__)
- HostNativeThread::GetName(::pthread_getthreadid_np(), name);
+void ThisThread::GetName(llvm::SmallVectorImpl<char> &name) {
+#if defined(__FreeBSD__)
+ HostNativeThread::GetName(::pthread_getthreadid_np(), name);
#else
-// Kfreebsd
- HostNativeThread::GetName((unsigned)pthread_self(), name);
+ // Kfreebsd
+ HostNativeThread::GetName((unsigned)pthread_self(), name);
#endif
}
OpenPOWER on IntegriCloud