2013-11-21 05:07:01 +08:00
|
|
|
//===-- SBPlatform.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBPlatform.h"
|
|
|
|
#include "lldb/API/SBError.h"
|
|
|
|
#include "lldb/API/SBFileSpec.h"
|
2015-02-05 07:19:15 +08:00
|
|
|
#include "lldb/API/SBLaunchInfo.h"
|
2015-07-14 09:09:28 +08:00
|
|
|
#include "lldb/API/SBUnixSignals.h"
|
2013-11-21 05:07:01 +08:00
|
|
|
#include "lldb/Host/File.h"
|
|
|
|
#include "lldb/Interpreter/Args.h"
|
|
|
|
#include "lldb/Target/Platform.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2017-11-14 00:16:33 +08:00
|
|
|
#include "lldb/Utility/ArchSpec.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2017-03-09 01:56:08 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
|
2015-02-05 07:19:15 +08:00
|
|
|
#include <functional>
|
|
|
|
|
2013-11-21 05:07:01 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// PlatformConnectOptions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
struct PlatformConnectOptions {
|
2016-09-07 04:57:50 +08:00
|
|
|
PlatformConnectOptions(const char *url = NULL)
|
|
|
|
: m_url(), m_rsync_options(), m_rsync_remote_path_prefix(),
|
|
|
|
m_rsync_enabled(false), m_rsync_omit_hostname_from_remote_path(false),
|
|
|
|
m_local_cache_directory() {
|
|
|
|
if (url && url[0])
|
|
|
|
m_url = url;
|
|
|
|
}
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
~PlatformConnectOptions() {}
|
|
|
|
|
|
|
|
std::string m_url;
|
|
|
|
std::string m_rsync_options;
|
|
|
|
std::string m_rsync_remote_path_prefix;
|
|
|
|
bool m_rsync_enabled;
|
|
|
|
bool m_rsync_omit_hostname_from_remote_path;
|
|
|
|
ConstString m_local_cache_directory;
|
2013-11-21 05:07:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// PlatformShellCommand
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
struct PlatformShellCommand {
|
2016-09-07 04:57:50 +08:00
|
|
|
PlatformShellCommand(const char *shell_command = NULL)
|
|
|
|
: m_command(), m_working_dir(), m_status(0), m_signo(0),
|
|
|
|
m_timeout_sec(UINT32_MAX) {
|
|
|
|
if (shell_command && shell_command[0])
|
|
|
|
m_command = shell_command;
|
|
|
|
}
|
|
|
|
|
|
|
|
~PlatformShellCommand() {}
|
|
|
|
|
|
|
|
std::string m_command;
|
|
|
|
std::string m_working_dir;
|
|
|
|
std::string m_output;
|
|
|
|
int m_status;
|
|
|
|
int m_signo;
|
|
|
|
uint32_t m_timeout_sec;
|
2013-11-21 05:07:01 +08:00
|
|
|
};
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// SBPlatformConnectOptions
|
|
|
|
//----------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
SBPlatformConnectOptions::SBPlatformConnectOptions(const char *url)
|
|
|
|
: m_opaque_ptr(new PlatformConnectOptions(url)) {}
|
|
|
|
|
|
|
|
SBPlatformConnectOptions::SBPlatformConnectOptions(
|
|
|
|
const SBPlatformConnectOptions &rhs)
|
|
|
|
: m_opaque_ptr(new PlatformConnectOptions()) {
|
|
|
|
*m_opaque_ptr = *rhs.m_opaque_ptr;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBPlatformConnectOptions::~SBPlatformConnectOptions() { delete m_opaque_ptr; }
|
|
|
|
|
|
|
|
void SBPlatformConnectOptions::operator=(const SBPlatformConnectOptions &rhs) {
|
|
|
|
*m_opaque_ptr = *rhs.m_opaque_ptr;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
const char *SBPlatformConnectOptions::GetURL() {
|
|
|
|
if (m_opaque_ptr->m_url.empty())
|
|
|
|
return NULL;
|
|
|
|
return m_opaque_ptr->m_url.c_str();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBPlatformConnectOptions::SetURL(const char *url) {
|
|
|
|
if (url && url[0])
|
|
|
|
m_opaque_ptr->m_url = url;
|
|
|
|
else
|
|
|
|
m_opaque_ptr->m_url.clear();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBPlatformConnectOptions::GetRsyncEnabled() {
|
|
|
|
return m_opaque_ptr->m_rsync_enabled;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBPlatformConnectOptions::EnableRsync(
|
|
|
|
const char *options, const char *remote_path_prefix,
|
|
|
|
bool omit_hostname_from_remote_path) {
|
|
|
|
m_opaque_ptr->m_rsync_enabled = true;
|
|
|
|
m_opaque_ptr->m_rsync_omit_hostname_from_remote_path =
|
|
|
|
omit_hostname_from_remote_path;
|
|
|
|
if (remote_path_prefix && remote_path_prefix[0])
|
|
|
|
m_opaque_ptr->m_rsync_remote_path_prefix = remote_path_prefix;
|
|
|
|
else
|
|
|
|
m_opaque_ptr->m_rsync_remote_path_prefix.clear();
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (options && options[0])
|
|
|
|
m_opaque_ptr->m_rsync_options = options;
|
|
|
|
else
|
|
|
|
m_opaque_ptr->m_rsync_options.clear();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBPlatformConnectOptions::DisableRsync() {
|
|
|
|
m_opaque_ptr->m_rsync_enabled = false;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
const char *SBPlatformConnectOptions::GetLocalCacheDirectory() {
|
|
|
|
return m_opaque_ptr->m_local_cache_directory.GetCString();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
void SBPlatformConnectOptions::SetLocalCacheDirectory(const char *path) {
|
|
|
|
if (path && path[0])
|
|
|
|
m_opaque_ptr->m_local_cache_directory.SetCString(path);
|
|
|
|
else
|
|
|
|
m_opaque_ptr->m_local_cache_directory = ConstString();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// SBPlatformShellCommand
|
|
|
|
//----------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_command)
|
|
|
|
: m_opaque_ptr(new PlatformShellCommand(shell_command)) {}
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBPlatformShellCommand::SBPlatformShellCommand(
|
|
|
|
const SBPlatformShellCommand &rhs)
|
|
|
|
: m_opaque_ptr(new PlatformShellCommand()) {
|
|
|
|
*m_opaque_ptr = *rhs.m_opaque_ptr;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBPlatformShellCommand::~SBPlatformShellCommand() { delete m_opaque_ptr; }
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBPlatformShellCommand::Clear() {
|
|
|
|
m_opaque_ptr->m_output = std::string();
|
|
|
|
m_opaque_ptr->m_status = 0;
|
|
|
|
m_opaque_ptr->m_signo = 0;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBPlatformShellCommand::GetCommand() {
|
|
|
|
if (m_opaque_ptr->m_command.empty())
|
|
|
|
return NULL;
|
|
|
|
return m_opaque_ptr->m_command.c_str();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBPlatformShellCommand::SetCommand(const char *shell_command) {
|
|
|
|
if (shell_command && shell_command[0])
|
|
|
|
m_opaque_ptr->m_command = shell_command;
|
|
|
|
else
|
|
|
|
m_opaque_ptr->m_command.clear();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBPlatformShellCommand::GetWorkingDirectory() {
|
|
|
|
if (m_opaque_ptr->m_working_dir.empty())
|
|
|
|
return NULL;
|
|
|
|
return m_opaque_ptr->m_working_dir.c_str();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBPlatformShellCommand::SetWorkingDirectory(const char *path) {
|
|
|
|
if (path && path[0])
|
|
|
|
m_opaque_ptr->m_working_dir = path;
|
|
|
|
else
|
|
|
|
m_opaque_ptr->m_working_dir.clear();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBPlatformShellCommand::GetTimeoutSeconds() {
|
|
|
|
return m_opaque_ptr->m_timeout_sec;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBPlatformShellCommand::SetTimeoutSeconds(uint32_t sec) {
|
|
|
|
m_opaque_ptr->m_timeout_sec = sec;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
int SBPlatformShellCommand::GetSignal() { return m_opaque_ptr->m_signo; }
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
int SBPlatformShellCommand::GetStatus() { return m_opaque_ptr->m_status; }
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBPlatformShellCommand::GetOutput() {
|
|
|
|
if (m_opaque_ptr->m_output.empty())
|
|
|
|
return NULL;
|
|
|
|
return m_opaque_ptr->m_output.c_str();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// SBPlatform
|
|
|
|
//----------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
SBPlatform::SBPlatform() : m_opaque_sp() {}
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBPlatform::SBPlatform(const char *platform_name) : m_opaque_sp() {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (platform_name && platform_name[0])
|
|
|
|
m_opaque_sp = Platform::Create(ConstString(platform_name), error);
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBPlatform::~SBPlatform() {}
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBPlatform::IsValid() const { return m_opaque_sp.get() != NULL; }
|
|
|
|
|
|
|
|
void SBPlatform::Clear() { m_opaque_sp.reset(); }
|
|
|
|
|
|
|
|
const char *SBPlatform::GetName() {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp)
|
|
|
|
return platform_sp->GetName().GetCString();
|
|
|
|
return NULL;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::PlatformSP SBPlatform::GetSP() const { return m_opaque_sp; }
|
|
|
|
|
|
|
|
void SBPlatform::SetSP(const lldb::PlatformSP &platform_sp) {
|
|
|
|
m_opaque_sp = platform_sp;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBPlatform::GetWorkingDirectory() {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp)
|
|
|
|
return platform_sp->GetWorkingDirectory().GetCString();
|
|
|
|
return NULL;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBPlatform::SetWorkingDirectory(const char *path) {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp) {
|
|
|
|
if (path)
|
|
|
|
platform_sp->SetWorkingDirectory(FileSpec{path, false});
|
|
|
|
else
|
|
|
|
platform_sp->SetWorkingDirectory(FileSpec{});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError SBPlatform::ConnectRemote(SBPlatformConnectOptions &connect_options) {
|
|
|
|
SBError sb_error;
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp && connect_options.GetURL()) {
|
|
|
|
Args args;
|
2016-09-20 01:54:06 +08:00
|
|
|
args.AppendArgument(
|
|
|
|
llvm::StringRef::withNullAsEmpty(connect_options.GetURL()));
|
2016-09-07 04:57:50 +08:00
|
|
|
sb_error.ref() = platform_sp->ConnectRemote(args);
|
|
|
|
} else {
|
|
|
|
sb_error.SetErrorString("invalid platform");
|
|
|
|
}
|
|
|
|
return sb_error;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBPlatform::DisconnectRemote() {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp)
|
|
|
|
platform_sp->DisconnectRemote();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBPlatform::IsConnected() {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp)
|
2018-03-14 05:06:05 +08:00
|
|
|
return platform_sp->IsConnected();
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBPlatform::GetTriple() {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp) {
|
|
|
|
ArchSpec arch(platform_sp->GetSystemArchitecture());
|
|
|
|
if (arch.IsValid()) {
|
|
|
|
// Const-ify the string so we don't need to worry about the lifetime of
|
|
|
|
// the string
|
|
|
|
return ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBPlatform::GetOSBuild() {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp) {
|
|
|
|
std::string s;
|
|
|
|
if (platform_sp->GetOSBuildString(s)) {
|
|
|
|
if (!s.empty()) {
|
|
|
|
// Const-ify the string so we don't need to worry about the lifetime of
|
|
|
|
// the string
|
|
|
|
return ConstString(s.c_str()).GetCString();
|
|
|
|
}
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBPlatform::GetOSDescription() {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp) {
|
|
|
|
std::string s;
|
|
|
|
if (platform_sp->GetOSKernelDescription(s)) {
|
|
|
|
if (!s.empty()) {
|
|
|
|
// Const-ify the string so we don't need to worry about the lifetime of
|
|
|
|
// the string
|
|
|
|
return ConstString(s.c_str()).GetCString();
|
|
|
|
}
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBPlatform::GetHostname() {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp)
|
|
|
|
return platform_sp->GetHostname();
|
|
|
|
return NULL;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBPlatform::GetOSMajorVersion() {
|
|
|
|
uint32_t major, minor, update;
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp && platform_sp->GetOSVersion(major, minor, update))
|
|
|
|
return major;
|
|
|
|
return UINT32_MAX;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBPlatform::GetOSMinorVersion() {
|
|
|
|
uint32_t major, minor, update;
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp && platform_sp->GetOSVersion(major, minor, update))
|
|
|
|
return minor;
|
|
|
|
return UINT32_MAX;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBPlatform::GetOSUpdateVersion() {
|
|
|
|
uint32_t major, minor, update;
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp && platform_sp->GetOSVersion(major, minor, update))
|
|
|
|
return update;
|
|
|
|
return UINT32_MAX;
|
|
|
|
}
|
2015-02-05 07:19:15 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
|
|
|
|
SBError sb_error;
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp) {
|
|
|
|
sb_error.ref() = platform_sp->GetFile(src.ref(), dst.ref());
|
|
|
|
} else {
|
|
|
|
sb_error.SetErrorString("invalid platform");
|
|
|
|
}
|
2015-02-05 07:19:15 +08:00
|
|
|
return sb_error;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBError SBPlatform::Put(SBFileSpec &src, SBFileSpec &dst) {
|
|
|
|
return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
|
|
|
|
if (src.Exists()) {
|
|
|
|
uint32_t permissions = src.ref().GetPermissions();
|
|
|
|
if (permissions == 0) {
|
2017-03-09 01:56:08 +08:00
|
|
|
if (llvm::sys::fs::is_directory(src.ref().GetPath()))
|
2016-09-07 04:57:50 +08:00
|
|
|
permissions = eFilePermissionsDirectoryDefault;
|
|
|
|
else
|
|
|
|
permissions = eFilePermissionsFileDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
return platform_sp->PutFile(src.ref(), dst.ref(), permissions);
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
|
|
|
|
src.ref().GetPath().c_str());
|
|
|
|
return error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError SBPlatform::Install(SBFileSpec &src, SBFileSpec &dst) {
|
|
|
|
return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
|
|
|
|
if (src.Exists())
|
|
|
|
return platform_sp->Install(src.ref(), dst.ref());
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
|
|
|
|
src.ref().GetPath().c_str());
|
|
|
|
return error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError SBPlatform::Run(SBPlatformShellCommand &shell_command) {
|
|
|
|
return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
|
|
|
|
const char *command = shell_command.GetCommand();
|
|
|
|
if (!command)
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("invalid shell command (empty)");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
const char *working_dir = shell_command.GetWorkingDirectory();
|
|
|
|
if (working_dir == NULL) {
|
|
|
|
working_dir = platform_sp->GetWorkingDirectory().GetCString();
|
|
|
|
if (working_dir)
|
|
|
|
shell_command.SetWorkingDirectory(working_dir);
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return platform_sp->RunShellCommand(
|
|
|
|
command, FileSpec{working_dir, false},
|
|
|
|
&shell_command.m_opaque_ptr->m_status,
|
|
|
|
&shell_command.m_opaque_ptr->m_signo,
|
|
|
|
&shell_command.m_opaque_ptr->m_output,
|
|
|
|
shell_command.m_opaque_ptr->m_timeout_sec);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError SBPlatform::Launch(SBLaunchInfo &launch_info) {
|
|
|
|
return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
|
Add Utility/Environment class for handling... environments
Summary:
There was some confusion in the code about how to represent process
environment. Most of the code (ab)used the Args class for this purpose,
but some of it used a more basic StringList class instead. In either
case, the fact that the underlying abstraction did not provide primitive
operations for the typical environment operations meant that even a
simple operation like checking for an environment variable value was
several lines of code.
This patch adds a separate Environment class, which is essentialy a
llvm::StringMap<std::string> in disguise. To standard StringMap
functionality, it adds a couple of new functions, which are specific to
the environment use case:
- (most important) envp conversion for passing into execve() and likes.
Instead of trying to maintain a constantly up-to-date envp view, it
provides a function which creates a envp view on demand, with the
expectation that this will be called as the very last thing before
handing the value to the system function.
- insert(StringRef KeyEqValue) - splits KeyEqValue into (key, value)
pair and inserts it into the environment map.
- compose(value_type KeyValue) - takes a map entry and converts in back
into "KEY=VALUE" representation.
With this interface most of the environment-manipulating code becomes
one-liners. The only tricky part was maintaining compatibility in
SBLaunchInfo, which expects that the environment entries are accessible
by index and that the returned const char* is backed by the launch info
object (random access into maps is hard and the map stores the entry in
a deconstructed form, so we cannot just return a .c_str() value). To
solve this, I have the SBLaunchInfo convert the environment into the
"envp" form, and use it to answer the environment queries. Extra code is
added to make sure the envp version is always in sync.
(This also improves the layering situation as Args was in the Interpreter module
whereas Environment is in Utility.)
Reviewers: zturner, davide, jingham, clayborg
Subscribers: emaste, lldb-commits, mgorny
Differential Revision: https://reviews.llvm.org/D41359
llvm-svn: 322174
2018-01-10 19:57:31 +08:00
|
|
|
ProcessLaunchInfo info = launch_info.ref();
|
|
|
|
Status error = platform_sp->LaunchProcess(info);
|
|
|
|
launch_info.set_ref(info);
|
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError SBPlatform::Kill(const lldb::pid_t pid) {
|
|
|
|
return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
|
|
|
|
return platform_sp->KillProcess(pid);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError SBPlatform::ExecuteConnected(
|
2017-05-12 12:51:55 +08:00
|
|
|
const std::function<Status(const lldb::PlatformSP &)> &func) {
|
2016-09-07 04:57:50 +08:00
|
|
|
SBError sb_error;
|
|
|
|
const auto platform_sp(GetSP());
|
|
|
|
if (platform_sp) {
|
|
|
|
if (platform_sp->IsConnected())
|
|
|
|
sb_error.ref() = func(platform_sp);
|
2013-11-21 05:07:01 +08:00
|
|
|
else
|
2016-09-07 04:57:50 +08:00
|
|
|
sb_error.SetErrorString("not connected");
|
|
|
|
} else
|
|
|
|
sb_error.SetErrorString("invalid platform");
|
|
|
|
|
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError SBPlatform::MakeDirectory(const char *path, uint32_t file_permissions) {
|
|
|
|
SBError sb_error;
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp) {
|
|
|
|
sb_error.ref() =
|
|
|
|
platform_sp->MakeDirectory(FileSpec{path, false}, file_permissions);
|
|
|
|
} else {
|
|
|
|
sb_error.SetErrorString("invalid platform");
|
|
|
|
}
|
|
|
|
return sb_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBPlatform::GetFilePermissions(const char *path) {
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp) {
|
|
|
|
uint32_t file_permissions = 0;
|
|
|
|
platform_sp->GetFilePermissions(FileSpec{path, false}, file_permissions);
|
|
|
|
return file_permissions;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBError SBPlatform::SetFilePermissions(const char *path,
|
|
|
|
uint32_t file_permissions) {
|
|
|
|
SBError sb_error;
|
|
|
|
PlatformSP platform_sp(GetSP());
|
|
|
|
if (platform_sp) {
|
|
|
|
sb_error.ref() = platform_sp->SetFilePermissions(FileSpec{path, false},
|
|
|
|
file_permissions);
|
|
|
|
} else {
|
|
|
|
sb_error.SetErrorString("invalid platform");
|
|
|
|
}
|
|
|
|
return sb_error;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBUnixSignals SBPlatform::GetUnixSignals() const {
|
|
|
|
if (auto platform_sp = GetSP())
|
|
|
|
return SBUnixSignals{platform_sp};
|
2015-07-14 09:09:28 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return {};
|
2015-07-14 09:09:28 +08:00
|
|
|
}
|