#include <cerrno>
#include <climits>
#include <cstdlib>
#include <sys/types.h>
#ifndef _WIN32
#include <dlfcn.h>
#include <grp.h>
#include <netdb.h>
#include <pwd.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#include <mach/mach_init.h>
#include <mach/mach_port.h>
#endif
#if defined(__linux__) || defined(__FreeBSD__) || \
defined(__FreeBSD_kernel__) || defined(__APPLE__) || \
defined(__NetBSD__) || defined(__OpenBSD__) || defined(__EMSCRIPTEN__)
#if !defined(__ANDROID__)
#include <spawn.h>
#endif
#include <sys/syscall.h>
#include <sys/wait.h>
#endif
#if defined(__FreeBSD__)
#include <pthread_np.h>
#endif
#if defined(__NetBSD__)
#include <lwp.h>
#endif
#include <csignal>
#include "lldb/Host/FileAction.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/HostProcess.h"
#include "lldb/Host/MonitoringProcessLauncher.h"
#include "lldb/Host/ProcessLaunchInfo.h"
#include "lldb/Host/ProcessLauncher.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Predicate.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-private-forward.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
#if defined(_WIN32)
#include "lldb/Host/windows/ConnectionGenericFileWindows.h"
#include "lldb/Host/windows/ProcessLauncherWindows.h"
#else
#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
#endif
#if defined(__APPLE__)
#ifndef _POSIX_SPAWN_DISABLE_ASLR
#define _POSIX_SPAWN_DISABLE_ASLR …
#endif
extern "C" {
int __pthread_chdir(const char *path);
int __pthread_fchdir(int fildes);
}
#endif
usingnamespacelldb;
usingnamespacelldb_private;
#if !defined(__APPLE__)
#if !defined(_WIN32)
#include <syslog.h>
void Host::SystemLog(Severity severity, llvm::StringRef message) { … }
#else
void Host::SystemLog(Severity severity, llvm::StringRef message) {
switch (severity) {
case lldb::eSeverityInfo:
case lldb::eSeverityWarning:
llvm::outs() << message;
break;
case lldb::eSeverityError:
llvm::errs() << message;
break;
}
}
#endif
#endif
#if !defined(__APPLE__) && !defined(_WIN32)
static thread_result_t
MonitorChildProcessThreadFunction(::pid_t pid,
Host::MonitorChildProcessCallback callback);
llvm::Expected<HostThread> Host::StartMonitoringChildProcess(
const Host::MonitorChildProcessCallback &callback, lldb::pid_t pid) { … }
#ifndef __linux__
class ScopedPThreadCancelDisabler {
public:
ScopedPThreadCancelDisabler() {
int err = ::pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &m_old_state);
if (err != 0)
m_old_state = -1;
}
~ScopedPThreadCancelDisabler() {
if (m_old_state != -1)
::pthread_setcancelstate(m_old_state, 0);
}
private:
int m_old_state;
};
#endif
#ifdef __linux__
static thread_local volatile sig_atomic_t g_usr1_called;
static void SigUsr1Handler(int) { … }
#endif
static bool CheckForMonitorCancellation() { … }
static thread_result_t
MonitorChildProcessThreadFunction(::pid_t pid,
Host::MonitorChildProcessCallback callback) { … }
#endif
lldb::pid_t Host::GetCurrentProcessID() { … }
#ifndef _WIN32
lldb::thread_t Host::GetCurrentThread() { … }
const char *Host::GetSignalAsCString(int signo) { … }
#endif
#if !defined(__APPLE__)
bool Host::GetBundleDirectory(const FileSpec &file, FileSpec &bundle) { … }
bool Host::ResolveExecutableInBundle(FileSpec &file) { … }
#endif
#ifndef _WIN32
FileSpec Host::GetModuleFileSpecForHostAddress(const void *host_addr) { … }
#endif
#if !defined(__linux__)
bool Host::FindProcessThreads(const lldb::pid_t pid, TidMap &tids_to_attach) {
return false;
}
#endif
struct ShellInfo { … };
static void
MonitorShellCommand(std::shared_ptr<ShellInfo> shell_info, lldb::pid_t pid,
int signo,
int status)
{ … }
Status Host::RunShellCommand(llvm::StringRef command,
const FileSpec &working_dir, int *status_ptr,
int *signo_ptr, std::string *command_output_ptr,
const Timeout<std::micro> &timeout,
bool run_in_shell, bool hide_stderr) { … }
Status Host::RunShellCommand(llvm::StringRef shell_path,
llvm::StringRef command,
const FileSpec &working_dir, int *status_ptr,
int *signo_ptr, std::string *command_output_ptr,
const Timeout<std::micro> &timeout,
bool run_in_shell, bool hide_stderr) { … }
Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
int *status_ptr, int *signo_ptr,
std::string *command_output_ptr,
const Timeout<std::micro> &timeout,
bool run_in_shell, bool hide_stderr) { … }
Status Host::RunShellCommand(llvm::StringRef shell_path, const Args &args,
const FileSpec &working_dir, int *status_ptr,
int *signo_ptr, std::string *command_output_ptr,
const Timeout<std::micro> &timeout,
bool run_in_shell, bool hide_stderr) { … }
#if !defined(__APPLE__)
Status Host::LaunchProcess(ProcessLaunchInfo &launch_info) { … }
#endif
#ifndef _WIN32
void Host::Kill(lldb::pid_t pid, int signo) { … }
#endif
#if !defined(__APPLE__)
llvm::Error Host::OpenFileInExternalEditor(llvm::StringRef editor,
const FileSpec &file_spec,
uint32_t line_no) { … }
bool Host::IsInteractiveGraphicSession() { … }
#endif
std::unique_ptr<Connection> Host::CreateDefaultConnection(llvm::StringRef url) { … }
#if defined(LLVM_ON_UNIX)
WaitStatus WaitStatus::Decode(int wstatus) { … }
#endif
void llvm::format_provider<WaitStatus>::format(const WaitStatus &WS,
raw_ostream &OS,
StringRef Options) { … }
uint32_t Host::FindProcesses(const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) { … }
char SystemLogHandler::ID;
SystemLogHandler::SystemLogHandler() { … }
void SystemLogHandler::Emit(llvm::StringRef message) { … }