15ffd83dbSDimitry Andric //===-- SBPlatform.cpp ----------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/API/SBPlatform.h"
100b57cec5SDimitry Andric #include "SBReproducerPrivate.h"
115ffd83dbSDimitry Andric #include "lldb/API/SBEnvironment.h"
120b57cec5SDimitry Andric #include "lldb/API/SBError.h"
130b57cec5SDimitry Andric #include "lldb/API/SBFileSpec.h"
140b57cec5SDimitry Andric #include "lldb/API/SBLaunchInfo.h"
155ffd83dbSDimitry Andric #include "lldb/API/SBPlatform.h"
160b57cec5SDimitry Andric #include "lldb/API/SBUnixSignals.h"
170b57cec5SDimitry Andric #include "lldb/Host/File.h"
180b57cec5SDimitry Andric #include "lldb/Target/Platform.h"
190b57cec5SDimitry Andric #include "lldb/Target/Target.h"
200b57cec5SDimitry Andric #include "lldb/Utility/ArchSpec.h"
210b57cec5SDimitry Andric #include "lldb/Utility/Args.h"
220b57cec5SDimitry Andric #include "lldb/Utility/Status.h"
230b57cec5SDimitry Andric
240b57cec5SDimitry Andric #include "llvm/Support/FileSystem.h"
250b57cec5SDimitry Andric
260b57cec5SDimitry Andric #include <functional>
270b57cec5SDimitry Andric
280b57cec5SDimitry Andric using namespace lldb;
290b57cec5SDimitry Andric using namespace lldb_private;
300b57cec5SDimitry Andric
310b57cec5SDimitry Andric // PlatformConnectOptions
320b57cec5SDimitry Andric struct PlatformConnectOptions {
PlatformConnectOptionsPlatformConnectOptions330b57cec5SDimitry Andric PlatformConnectOptions(const char *url = nullptr)
340b57cec5SDimitry Andric : m_url(), m_rsync_options(), m_rsync_remote_path_prefix(),
35*5f7ddb14SDimitry Andric
360b57cec5SDimitry Andric m_local_cache_directory() {
370b57cec5SDimitry Andric if (url && url[0])
380b57cec5SDimitry Andric m_url = url;
390b57cec5SDimitry Andric }
400b57cec5SDimitry Andric
415ffd83dbSDimitry Andric ~PlatformConnectOptions() = default;
420b57cec5SDimitry Andric
430b57cec5SDimitry Andric std::string m_url;
440b57cec5SDimitry Andric std::string m_rsync_options;
450b57cec5SDimitry Andric std::string m_rsync_remote_path_prefix;
46*5f7ddb14SDimitry Andric bool m_rsync_enabled = false;
47*5f7ddb14SDimitry Andric bool m_rsync_omit_hostname_from_remote_path = false;
480b57cec5SDimitry Andric ConstString m_local_cache_directory;
490b57cec5SDimitry Andric };
500b57cec5SDimitry Andric
510b57cec5SDimitry Andric // PlatformShellCommand
520b57cec5SDimitry Andric struct PlatformShellCommand {
PlatformShellCommandPlatformShellCommand53af732203SDimitry Andric PlatformShellCommand(llvm::StringRef shell_interpreter,
54af732203SDimitry Andric llvm::StringRef shell_command)
550b57cec5SDimitry Andric : m_command(), m_working_dir(), m_status(0), m_signo(0) {
56af732203SDimitry Andric if (!shell_interpreter.empty())
57af732203SDimitry Andric m_shell = shell_interpreter.str();
58af732203SDimitry Andric
59af732203SDimitry Andric if (!m_shell.empty() && !shell_command.empty())
60af732203SDimitry Andric m_command = shell_command.str();
61af732203SDimitry Andric }
62af732203SDimitry Andric
PlatformShellCommandPlatformShellCommand63af732203SDimitry Andric PlatformShellCommand(llvm::StringRef shell_command = llvm::StringRef())
64*5f7ddb14SDimitry Andric : m_shell(), m_command(), m_working_dir() {
65af732203SDimitry Andric if (!shell_command.empty())
66af732203SDimitry Andric m_command = shell_command.str();
670b57cec5SDimitry Andric }
680b57cec5SDimitry Andric
695ffd83dbSDimitry Andric ~PlatformShellCommand() = default;
700b57cec5SDimitry Andric
71af732203SDimitry Andric std::string m_shell;
720b57cec5SDimitry Andric std::string m_command;
730b57cec5SDimitry Andric std::string m_working_dir;
740b57cec5SDimitry Andric std::string m_output;
75*5f7ddb14SDimitry Andric int m_status = 0;
76*5f7ddb14SDimitry Andric int m_signo = 0;
770b57cec5SDimitry Andric Timeout<std::ratio<1>> m_timeout = llvm::None;
780b57cec5SDimitry Andric };
790b57cec5SDimitry Andric // SBPlatformConnectOptions
SBPlatformConnectOptions(const char * url)800b57cec5SDimitry Andric SBPlatformConnectOptions::SBPlatformConnectOptions(const char *url)
810b57cec5SDimitry Andric : m_opaque_ptr(new PlatformConnectOptions(url)) {
820b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBPlatformConnectOptions, (const char *), url);
830b57cec5SDimitry Andric }
840b57cec5SDimitry Andric
SBPlatformConnectOptions(const SBPlatformConnectOptions & rhs)850b57cec5SDimitry Andric SBPlatformConnectOptions::SBPlatformConnectOptions(
860b57cec5SDimitry Andric const SBPlatformConnectOptions &rhs)
870b57cec5SDimitry Andric : m_opaque_ptr(new PlatformConnectOptions()) {
880b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBPlatformConnectOptions,
890b57cec5SDimitry Andric (const lldb::SBPlatformConnectOptions &), rhs);
900b57cec5SDimitry Andric
910b57cec5SDimitry Andric *m_opaque_ptr = *rhs.m_opaque_ptr;
920b57cec5SDimitry Andric }
930b57cec5SDimitry Andric
~SBPlatformConnectOptions()940b57cec5SDimitry Andric SBPlatformConnectOptions::~SBPlatformConnectOptions() { delete m_opaque_ptr; }
950b57cec5SDimitry Andric
96af732203SDimitry Andric SBPlatformConnectOptions &
operator =(const SBPlatformConnectOptions & rhs)97af732203SDimitry Andric SBPlatformConnectOptions::operator=(const SBPlatformConnectOptions &rhs) {
980b57cec5SDimitry Andric LLDB_RECORD_METHOD(
995ffd83dbSDimitry Andric SBPlatformConnectOptions &,
1000b57cec5SDimitry Andric SBPlatformConnectOptions, operator=,(
1010b57cec5SDimitry Andric const lldb::SBPlatformConnectOptions &),
1020b57cec5SDimitry Andric rhs);
1030b57cec5SDimitry Andric
1040b57cec5SDimitry Andric *m_opaque_ptr = *rhs.m_opaque_ptr;
1055ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(*this);
1060b57cec5SDimitry Andric }
1070b57cec5SDimitry Andric
GetURL()1080b57cec5SDimitry Andric const char *SBPlatformConnectOptions::GetURL() {
1090b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformConnectOptions, GetURL);
1100b57cec5SDimitry Andric
1110b57cec5SDimitry Andric if (m_opaque_ptr->m_url.empty())
1120b57cec5SDimitry Andric return nullptr;
1130b57cec5SDimitry Andric return m_opaque_ptr->m_url.c_str();
1140b57cec5SDimitry Andric }
1150b57cec5SDimitry Andric
SetURL(const char * url)1160b57cec5SDimitry Andric void SBPlatformConnectOptions::SetURL(const char *url) {
1170b57cec5SDimitry Andric LLDB_RECORD_METHOD(void, SBPlatformConnectOptions, SetURL, (const char *),
1180b57cec5SDimitry Andric url);
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andric if (url && url[0])
1210b57cec5SDimitry Andric m_opaque_ptr->m_url = url;
1220b57cec5SDimitry Andric else
1230b57cec5SDimitry Andric m_opaque_ptr->m_url.clear();
1240b57cec5SDimitry Andric }
1250b57cec5SDimitry Andric
GetRsyncEnabled()1260b57cec5SDimitry Andric bool SBPlatformConnectOptions::GetRsyncEnabled() {
1270b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(bool, SBPlatformConnectOptions, GetRsyncEnabled);
1280b57cec5SDimitry Andric
1290b57cec5SDimitry Andric return m_opaque_ptr->m_rsync_enabled;
1300b57cec5SDimitry Andric }
1310b57cec5SDimitry Andric
EnableRsync(const char * options,const char * remote_path_prefix,bool omit_hostname_from_remote_path)1320b57cec5SDimitry Andric void SBPlatformConnectOptions::EnableRsync(
1330b57cec5SDimitry Andric const char *options, const char *remote_path_prefix,
1340b57cec5SDimitry Andric bool omit_hostname_from_remote_path) {
1350b57cec5SDimitry Andric LLDB_RECORD_METHOD(void, SBPlatformConnectOptions, EnableRsync,
1360b57cec5SDimitry Andric (const char *, const char *, bool), options,
1370b57cec5SDimitry Andric remote_path_prefix, omit_hostname_from_remote_path);
1380b57cec5SDimitry Andric
1390b57cec5SDimitry Andric m_opaque_ptr->m_rsync_enabled = true;
1400b57cec5SDimitry Andric m_opaque_ptr->m_rsync_omit_hostname_from_remote_path =
1410b57cec5SDimitry Andric omit_hostname_from_remote_path;
1420b57cec5SDimitry Andric if (remote_path_prefix && remote_path_prefix[0])
1430b57cec5SDimitry Andric m_opaque_ptr->m_rsync_remote_path_prefix = remote_path_prefix;
1440b57cec5SDimitry Andric else
1450b57cec5SDimitry Andric m_opaque_ptr->m_rsync_remote_path_prefix.clear();
1460b57cec5SDimitry Andric
1470b57cec5SDimitry Andric if (options && options[0])
1480b57cec5SDimitry Andric m_opaque_ptr->m_rsync_options = options;
1490b57cec5SDimitry Andric else
1500b57cec5SDimitry Andric m_opaque_ptr->m_rsync_options.clear();
1510b57cec5SDimitry Andric }
1520b57cec5SDimitry Andric
DisableRsync()1530b57cec5SDimitry Andric void SBPlatformConnectOptions::DisableRsync() {
1540b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatformConnectOptions, DisableRsync);
1550b57cec5SDimitry Andric
1560b57cec5SDimitry Andric m_opaque_ptr->m_rsync_enabled = false;
1570b57cec5SDimitry Andric }
1580b57cec5SDimitry Andric
GetLocalCacheDirectory()1590b57cec5SDimitry Andric const char *SBPlatformConnectOptions::GetLocalCacheDirectory() {
1600b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformConnectOptions,
1610b57cec5SDimitry Andric GetLocalCacheDirectory);
1620b57cec5SDimitry Andric
1630b57cec5SDimitry Andric return m_opaque_ptr->m_local_cache_directory.GetCString();
1640b57cec5SDimitry Andric }
1650b57cec5SDimitry Andric
SetLocalCacheDirectory(const char * path)1660b57cec5SDimitry Andric void SBPlatformConnectOptions::SetLocalCacheDirectory(const char *path) {
1670b57cec5SDimitry Andric LLDB_RECORD_METHOD(void, SBPlatformConnectOptions, SetLocalCacheDirectory,
1680b57cec5SDimitry Andric (const char *), path);
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andric if (path && path[0])
1710b57cec5SDimitry Andric m_opaque_ptr->m_local_cache_directory.SetCString(path);
1720b57cec5SDimitry Andric else
1730b57cec5SDimitry Andric m_opaque_ptr->m_local_cache_directory = ConstString();
1740b57cec5SDimitry Andric }
1750b57cec5SDimitry Andric
1760b57cec5SDimitry Andric // SBPlatformShellCommand
SBPlatformShellCommand(const char * shell_interpreter,const char * shell_command)177af732203SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_interpreter,
178af732203SDimitry Andric const char *shell_command)
179af732203SDimitry Andric : m_opaque_ptr(new PlatformShellCommand(shell_interpreter, shell_command)) {
180af732203SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand, (const char *, const char *),
181af732203SDimitry Andric shell_interpreter, shell_command);
182af732203SDimitry Andric }
183af732203SDimitry Andric
SBPlatformShellCommand(const char * shell_command)1840b57cec5SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_command)
1850b57cec5SDimitry Andric : m_opaque_ptr(new PlatformShellCommand(shell_command)) {
1860b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand, (const char *),
1870b57cec5SDimitry Andric shell_command);
1880b57cec5SDimitry Andric }
1890b57cec5SDimitry Andric
SBPlatformShellCommand(const SBPlatformShellCommand & rhs)1900b57cec5SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(
1910b57cec5SDimitry Andric const SBPlatformShellCommand &rhs)
1920b57cec5SDimitry Andric : m_opaque_ptr(new PlatformShellCommand()) {
1930b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand,
1940b57cec5SDimitry Andric (const lldb::SBPlatformShellCommand &), rhs);
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric *m_opaque_ptr = *rhs.m_opaque_ptr;
1970b57cec5SDimitry Andric }
1980b57cec5SDimitry Andric
199af732203SDimitry Andric SBPlatformShellCommand &
operator =(const SBPlatformShellCommand & rhs)200af732203SDimitry Andric SBPlatformShellCommand::operator=(const SBPlatformShellCommand &rhs) {
2015ffd83dbSDimitry Andric
2025ffd83dbSDimitry Andric LLDB_RECORD_METHOD(
2035ffd83dbSDimitry Andric SBPlatformShellCommand &,
2045ffd83dbSDimitry Andric SBPlatformShellCommand, operator=,(const lldb::SBPlatformShellCommand &),
2055ffd83dbSDimitry Andric rhs);
2065ffd83dbSDimitry Andric
2075ffd83dbSDimitry Andric *m_opaque_ptr = *rhs.m_opaque_ptr;
2085ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(*this);
2095ffd83dbSDimitry Andric }
2105ffd83dbSDimitry Andric
~SBPlatformShellCommand()2110b57cec5SDimitry Andric SBPlatformShellCommand::~SBPlatformShellCommand() { delete m_opaque_ptr; }
2120b57cec5SDimitry Andric
Clear()2130b57cec5SDimitry Andric void SBPlatformShellCommand::Clear() {
2140b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatformShellCommand, Clear);
2150b57cec5SDimitry Andric
2160b57cec5SDimitry Andric m_opaque_ptr->m_output = std::string();
2170b57cec5SDimitry Andric m_opaque_ptr->m_status = 0;
2180b57cec5SDimitry Andric m_opaque_ptr->m_signo = 0;
2190b57cec5SDimitry Andric }
2200b57cec5SDimitry Andric
GetShell()221af732203SDimitry Andric const char *SBPlatformShellCommand::GetShell() {
222af732203SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetShell);
223af732203SDimitry Andric
224af732203SDimitry Andric if (m_opaque_ptr->m_shell.empty())
225af732203SDimitry Andric return nullptr;
226af732203SDimitry Andric return m_opaque_ptr->m_shell.c_str();
227af732203SDimitry Andric }
228af732203SDimitry Andric
SetShell(const char * shell_interpreter)229af732203SDimitry Andric void SBPlatformShellCommand::SetShell(const char *shell_interpreter) {
230af732203SDimitry Andric LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetShell, (const char *),
231af732203SDimitry Andric shell_interpreter);
232af732203SDimitry Andric
233af732203SDimitry Andric if (shell_interpreter && shell_interpreter[0])
234af732203SDimitry Andric m_opaque_ptr->m_shell = shell_interpreter;
235af732203SDimitry Andric else
236af732203SDimitry Andric m_opaque_ptr->m_shell.clear();
237af732203SDimitry Andric }
238af732203SDimitry Andric
GetCommand()2390b57cec5SDimitry Andric const char *SBPlatformShellCommand::GetCommand() {
2400b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetCommand);
2410b57cec5SDimitry Andric
2420b57cec5SDimitry Andric if (m_opaque_ptr->m_command.empty())
2430b57cec5SDimitry Andric return nullptr;
2440b57cec5SDimitry Andric return m_opaque_ptr->m_command.c_str();
2450b57cec5SDimitry Andric }
2460b57cec5SDimitry Andric
SetCommand(const char * shell_command)2470b57cec5SDimitry Andric void SBPlatformShellCommand::SetCommand(const char *shell_command) {
2480b57cec5SDimitry Andric LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetCommand, (const char *),
2490b57cec5SDimitry Andric shell_command);
2500b57cec5SDimitry Andric
2510b57cec5SDimitry Andric if (shell_command && shell_command[0])
2520b57cec5SDimitry Andric m_opaque_ptr->m_command = shell_command;
2530b57cec5SDimitry Andric else
2540b57cec5SDimitry Andric m_opaque_ptr->m_command.clear();
2550b57cec5SDimitry Andric }
2560b57cec5SDimitry Andric
GetWorkingDirectory()2570b57cec5SDimitry Andric const char *SBPlatformShellCommand::GetWorkingDirectory() {
2580b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand,
2590b57cec5SDimitry Andric GetWorkingDirectory);
2600b57cec5SDimitry Andric
2610b57cec5SDimitry Andric if (m_opaque_ptr->m_working_dir.empty())
2620b57cec5SDimitry Andric return nullptr;
2630b57cec5SDimitry Andric return m_opaque_ptr->m_working_dir.c_str();
2640b57cec5SDimitry Andric }
2650b57cec5SDimitry Andric
SetWorkingDirectory(const char * path)2660b57cec5SDimitry Andric void SBPlatformShellCommand::SetWorkingDirectory(const char *path) {
2670b57cec5SDimitry Andric LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetWorkingDirectory,
2680b57cec5SDimitry Andric (const char *), path);
2690b57cec5SDimitry Andric
2700b57cec5SDimitry Andric if (path && path[0])
2710b57cec5SDimitry Andric m_opaque_ptr->m_working_dir = path;
2720b57cec5SDimitry Andric else
2730b57cec5SDimitry Andric m_opaque_ptr->m_working_dir.clear();
2740b57cec5SDimitry Andric }
2750b57cec5SDimitry Andric
GetTimeoutSeconds()2760b57cec5SDimitry Andric uint32_t SBPlatformShellCommand::GetTimeoutSeconds() {
2770b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatformShellCommand,
2780b57cec5SDimitry Andric GetTimeoutSeconds);
2790b57cec5SDimitry Andric
2800b57cec5SDimitry Andric if (m_opaque_ptr->m_timeout)
2810b57cec5SDimitry Andric return m_opaque_ptr->m_timeout->count();
2820b57cec5SDimitry Andric return UINT32_MAX;
2830b57cec5SDimitry Andric }
2840b57cec5SDimitry Andric
SetTimeoutSeconds(uint32_t sec)2850b57cec5SDimitry Andric void SBPlatformShellCommand::SetTimeoutSeconds(uint32_t sec) {
2860b57cec5SDimitry Andric LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetTimeoutSeconds,
2870b57cec5SDimitry Andric (uint32_t), sec);
2880b57cec5SDimitry Andric
2890b57cec5SDimitry Andric if (sec == UINT32_MAX)
2900b57cec5SDimitry Andric m_opaque_ptr->m_timeout = llvm::None;
2910b57cec5SDimitry Andric else
2920b57cec5SDimitry Andric m_opaque_ptr->m_timeout = std::chrono::seconds(sec);
2930b57cec5SDimitry Andric }
2940b57cec5SDimitry Andric
GetSignal()2950b57cec5SDimitry Andric int SBPlatformShellCommand::GetSignal() {
2960b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(int, SBPlatformShellCommand, GetSignal);
2970b57cec5SDimitry Andric
2980b57cec5SDimitry Andric return m_opaque_ptr->m_signo;
2990b57cec5SDimitry Andric }
3000b57cec5SDimitry Andric
GetStatus()3010b57cec5SDimitry Andric int SBPlatformShellCommand::GetStatus() {
3020b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(int, SBPlatformShellCommand, GetStatus);
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andric return m_opaque_ptr->m_status;
3050b57cec5SDimitry Andric }
3060b57cec5SDimitry Andric
GetOutput()3070b57cec5SDimitry Andric const char *SBPlatformShellCommand::GetOutput() {
3080b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetOutput);
3090b57cec5SDimitry Andric
3100b57cec5SDimitry Andric if (m_opaque_ptr->m_output.empty())
3110b57cec5SDimitry Andric return nullptr;
3120b57cec5SDimitry Andric return m_opaque_ptr->m_output.c_str();
3130b57cec5SDimitry Andric }
3140b57cec5SDimitry Andric
3150b57cec5SDimitry Andric // SBPlatform
SBPlatform()3160b57cec5SDimitry Andric SBPlatform::SBPlatform() : m_opaque_sp() {
3170b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBPlatform);
3180b57cec5SDimitry Andric }
3190b57cec5SDimitry Andric
SBPlatform(const char * platform_name)3200b57cec5SDimitry Andric SBPlatform::SBPlatform(const char *platform_name) : m_opaque_sp() {
3210b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBPlatform, (const char *), platform_name);
3220b57cec5SDimitry Andric
3230b57cec5SDimitry Andric Status error;
3240b57cec5SDimitry Andric if (platform_name && platform_name[0])
3250b57cec5SDimitry Andric m_opaque_sp = Platform::Create(ConstString(platform_name), error);
3260b57cec5SDimitry Andric }
3270b57cec5SDimitry Andric
SBPlatform(const SBPlatform & rhs)3285ffd83dbSDimitry Andric SBPlatform::SBPlatform(const SBPlatform &rhs) {
3295ffd83dbSDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBPlatform, (const lldb::SBPlatform &), rhs);
3305ffd83dbSDimitry Andric
3315ffd83dbSDimitry Andric m_opaque_sp = rhs.m_opaque_sp;
3325ffd83dbSDimitry Andric }
3335ffd83dbSDimitry Andric
operator =(const SBPlatform & rhs)3345ffd83dbSDimitry Andric SBPlatform &SBPlatform::operator=(const SBPlatform &rhs) {
3355ffd83dbSDimitry Andric LLDB_RECORD_METHOD(SBPlatform &,
3365ffd83dbSDimitry Andric SBPlatform, operator=,(const lldb::SBPlatform &), rhs);
3375ffd83dbSDimitry Andric
3385ffd83dbSDimitry Andric m_opaque_sp = rhs.m_opaque_sp;
3395ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(*this);
3405ffd83dbSDimitry Andric }
3415ffd83dbSDimitry Andric
3425ffd83dbSDimitry Andric SBPlatform::~SBPlatform() = default;
3435ffd83dbSDimitry Andric
GetHostPlatform()3445ffd83dbSDimitry Andric SBPlatform SBPlatform::GetHostPlatform() {
3455ffd83dbSDimitry Andric LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBPlatform, SBPlatform,
3465ffd83dbSDimitry Andric GetHostPlatform);
3475ffd83dbSDimitry Andric
3485ffd83dbSDimitry Andric SBPlatform host_platform;
3495ffd83dbSDimitry Andric host_platform.m_opaque_sp = Platform::GetHostPlatform();
3505ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(host_platform);
3515ffd83dbSDimitry Andric }
3520b57cec5SDimitry Andric
IsValid() const3530b57cec5SDimitry Andric bool SBPlatform::IsValid() const {
3540b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBPlatform, IsValid);
3550b57cec5SDimitry Andric return this->operator bool();
3560b57cec5SDimitry Andric }
operator bool() const3570b57cec5SDimitry Andric SBPlatform::operator bool() const {
3580b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBPlatform, operator bool);
3590b57cec5SDimitry Andric
3600b57cec5SDimitry Andric return m_opaque_sp.get() != nullptr;
3610b57cec5SDimitry Andric }
3620b57cec5SDimitry Andric
Clear()3630b57cec5SDimitry Andric void SBPlatform::Clear() {
3640b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatform, Clear);
3650b57cec5SDimitry Andric
3660b57cec5SDimitry Andric m_opaque_sp.reset();
3670b57cec5SDimitry Andric }
3680b57cec5SDimitry Andric
GetName()3690b57cec5SDimitry Andric const char *SBPlatform::GetName() {
3700b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetName);
3710b57cec5SDimitry Andric
3720b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
3730b57cec5SDimitry Andric if (platform_sp)
3740b57cec5SDimitry Andric return platform_sp->GetName().GetCString();
3750b57cec5SDimitry Andric return nullptr;
3760b57cec5SDimitry Andric }
3770b57cec5SDimitry Andric
GetSP() const3780b57cec5SDimitry Andric lldb::PlatformSP SBPlatform::GetSP() const { return m_opaque_sp; }
3790b57cec5SDimitry Andric
SetSP(const lldb::PlatformSP & platform_sp)3800b57cec5SDimitry Andric void SBPlatform::SetSP(const lldb::PlatformSP &platform_sp) {
3810b57cec5SDimitry Andric m_opaque_sp = platform_sp;
3820b57cec5SDimitry Andric }
3830b57cec5SDimitry Andric
GetWorkingDirectory()3840b57cec5SDimitry Andric const char *SBPlatform::GetWorkingDirectory() {
3850b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetWorkingDirectory);
3860b57cec5SDimitry Andric
3870b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
3880b57cec5SDimitry Andric if (platform_sp)
3890b57cec5SDimitry Andric return platform_sp->GetWorkingDirectory().GetCString();
3900b57cec5SDimitry Andric return nullptr;
3910b57cec5SDimitry Andric }
3920b57cec5SDimitry Andric
SetWorkingDirectory(const char * path)3930b57cec5SDimitry Andric bool SBPlatform::SetWorkingDirectory(const char *path) {
3940b57cec5SDimitry Andric LLDB_RECORD_METHOD(bool, SBPlatform, SetWorkingDirectory, (const char *),
3950b57cec5SDimitry Andric path);
3960b57cec5SDimitry Andric
3970b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
3980b57cec5SDimitry Andric if (platform_sp) {
3990b57cec5SDimitry Andric if (path)
4000b57cec5SDimitry Andric platform_sp->SetWorkingDirectory(FileSpec(path));
4010b57cec5SDimitry Andric else
4020b57cec5SDimitry Andric platform_sp->SetWorkingDirectory(FileSpec());
4030b57cec5SDimitry Andric return true;
4040b57cec5SDimitry Andric }
4050b57cec5SDimitry Andric return false;
4060b57cec5SDimitry Andric }
4070b57cec5SDimitry Andric
ConnectRemote(SBPlatformConnectOptions & connect_options)4080b57cec5SDimitry Andric SBError SBPlatform::ConnectRemote(SBPlatformConnectOptions &connect_options) {
4090b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, ConnectRemote,
4100b57cec5SDimitry Andric (lldb::SBPlatformConnectOptions &), connect_options);
4110b57cec5SDimitry Andric
4120b57cec5SDimitry Andric SBError sb_error;
4130b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4140b57cec5SDimitry Andric if (platform_sp && connect_options.GetURL()) {
4150b57cec5SDimitry Andric Args args;
416*5f7ddb14SDimitry Andric args.AppendArgument(connect_options.GetURL());
4170b57cec5SDimitry Andric sb_error.ref() = platform_sp->ConnectRemote(args);
4180b57cec5SDimitry Andric } else {
4190b57cec5SDimitry Andric sb_error.SetErrorString("invalid platform");
4200b57cec5SDimitry Andric }
4210b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
4220b57cec5SDimitry Andric }
4230b57cec5SDimitry Andric
DisconnectRemote()4240b57cec5SDimitry Andric void SBPlatform::DisconnectRemote() {
4250b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatform, DisconnectRemote);
4260b57cec5SDimitry Andric
4270b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4280b57cec5SDimitry Andric if (platform_sp)
4290b57cec5SDimitry Andric platform_sp->DisconnectRemote();
4300b57cec5SDimitry Andric }
4310b57cec5SDimitry Andric
IsConnected()4320b57cec5SDimitry Andric bool SBPlatform::IsConnected() {
4330b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(bool, SBPlatform, IsConnected);
4340b57cec5SDimitry Andric
4350b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4360b57cec5SDimitry Andric if (platform_sp)
4370b57cec5SDimitry Andric return platform_sp->IsConnected();
4380b57cec5SDimitry Andric return false;
4390b57cec5SDimitry Andric }
4400b57cec5SDimitry Andric
GetTriple()4410b57cec5SDimitry Andric const char *SBPlatform::GetTriple() {
4420b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetTriple);
4430b57cec5SDimitry Andric
4440b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4450b57cec5SDimitry Andric if (platform_sp) {
4460b57cec5SDimitry Andric ArchSpec arch(platform_sp->GetSystemArchitecture());
4470b57cec5SDimitry Andric if (arch.IsValid()) {
4480b57cec5SDimitry Andric // Const-ify the string so we don't need to worry about the lifetime of
4490b57cec5SDimitry Andric // the string
4500b57cec5SDimitry Andric return ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
4510b57cec5SDimitry Andric }
4520b57cec5SDimitry Andric }
4530b57cec5SDimitry Andric return nullptr;
4540b57cec5SDimitry Andric }
4550b57cec5SDimitry Andric
GetOSBuild()4560b57cec5SDimitry Andric const char *SBPlatform::GetOSBuild() {
4570b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetOSBuild);
4580b57cec5SDimitry Andric
4590b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4600b57cec5SDimitry Andric if (platform_sp) {
4610b57cec5SDimitry Andric std::string s;
4620b57cec5SDimitry Andric if (platform_sp->GetOSBuildString(s)) {
4630b57cec5SDimitry Andric if (!s.empty()) {
4640b57cec5SDimitry Andric // Const-ify the string so we don't need to worry about the lifetime of
4650b57cec5SDimitry Andric // the string
4660b57cec5SDimitry Andric return ConstString(s.c_str()).GetCString();
4670b57cec5SDimitry Andric }
4680b57cec5SDimitry Andric }
4690b57cec5SDimitry Andric }
4700b57cec5SDimitry Andric return nullptr;
4710b57cec5SDimitry Andric }
4720b57cec5SDimitry Andric
GetOSDescription()4730b57cec5SDimitry Andric const char *SBPlatform::GetOSDescription() {
4740b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetOSDescription);
4750b57cec5SDimitry Andric
4760b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4770b57cec5SDimitry Andric if (platform_sp) {
4780b57cec5SDimitry Andric std::string s;
4790b57cec5SDimitry Andric if (platform_sp->GetOSKernelDescription(s)) {
4800b57cec5SDimitry Andric if (!s.empty()) {
4810b57cec5SDimitry Andric // Const-ify the string so we don't need to worry about the lifetime of
4820b57cec5SDimitry Andric // the string
4830b57cec5SDimitry Andric return ConstString(s.c_str()).GetCString();
4840b57cec5SDimitry Andric }
4850b57cec5SDimitry Andric }
4860b57cec5SDimitry Andric }
4870b57cec5SDimitry Andric return nullptr;
4880b57cec5SDimitry Andric }
4890b57cec5SDimitry Andric
GetHostname()4900b57cec5SDimitry Andric const char *SBPlatform::GetHostname() {
4910b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetHostname);
4920b57cec5SDimitry Andric
4930b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4940b57cec5SDimitry Andric if (platform_sp)
4950b57cec5SDimitry Andric return platform_sp->GetHostname();
4960b57cec5SDimitry Andric return nullptr;
4970b57cec5SDimitry Andric }
4980b57cec5SDimitry Andric
GetOSMajorVersion()4990b57cec5SDimitry Andric uint32_t SBPlatform::GetOSMajorVersion() {
5000b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatform, GetOSMajorVersion);
5010b57cec5SDimitry Andric
5020b57cec5SDimitry Andric llvm::VersionTuple version;
5030b57cec5SDimitry Andric if (PlatformSP platform_sp = GetSP())
5040b57cec5SDimitry Andric version = platform_sp->GetOSVersion();
5050b57cec5SDimitry Andric return version.empty() ? UINT32_MAX : version.getMajor();
5060b57cec5SDimitry Andric }
5070b57cec5SDimitry Andric
GetOSMinorVersion()5080b57cec5SDimitry Andric uint32_t SBPlatform::GetOSMinorVersion() {
5090b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatform, GetOSMinorVersion);
5100b57cec5SDimitry Andric
5110b57cec5SDimitry Andric llvm::VersionTuple version;
5120b57cec5SDimitry Andric if (PlatformSP platform_sp = GetSP())
5130b57cec5SDimitry Andric version = platform_sp->GetOSVersion();
5140b57cec5SDimitry Andric return version.getMinor().getValueOr(UINT32_MAX);
5150b57cec5SDimitry Andric }
5160b57cec5SDimitry Andric
GetOSUpdateVersion()5170b57cec5SDimitry Andric uint32_t SBPlatform::GetOSUpdateVersion() {
5180b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatform, GetOSUpdateVersion);
5190b57cec5SDimitry Andric
5200b57cec5SDimitry Andric llvm::VersionTuple version;
5210b57cec5SDimitry Andric if (PlatformSP platform_sp = GetSP())
5220b57cec5SDimitry Andric version = platform_sp->GetOSVersion();
5230b57cec5SDimitry Andric return version.getSubminor().getValueOr(UINT32_MAX);
5240b57cec5SDimitry Andric }
5250b57cec5SDimitry Andric
Get(SBFileSpec & src,SBFileSpec & dst)5260b57cec5SDimitry Andric SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
5270b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Get,
5280b57cec5SDimitry Andric (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);
5290b57cec5SDimitry Andric
5300b57cec5SDimitry Andric SBError sb_error;
5310b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
5320b57cec5SDimitry Andric if (platform_sp) {
5330b57cec5SDimitry Andric sb_error.ref() = platform_sp->GetFile(src.ref(), dst.ref());
5340b57cec5SDimitry Andric } else {
5350b57cec5SDimitry Andric sb_error.SetErrorString("invalid platform");
5360b57cec5SDimitry Andric }
5370b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
5380b57cec5SDimitry Andric }
5390b57cec5SDimitry Andric
Put(SBFileSpec & src,SBFileSpec & dst)5400b57cec5SDimitry Andric SBError SBPlatform::Put(SBFileSpec &src, SBFileSpec &dst) {
5410b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Put,
5420b57cec5SDimitry Andric (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);
5430b57cec5SDimitry Andric return LLDB_RECORD_RESULT(
5440b57cec5SDimitry Andric ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
5450b57cec5SDimitry Andric if (src.Exists()) {
5460b57cec5SDimitry Andric uint32_t permissions =
5470b57cec5SDimitry Andric FileSystem::Instance().GetPermissions(src.ref());
5480b57cec5SDimitry Andric if (permissions == 0) {
5490b57cec5SDimitry Andric if (FileSystem::Instance().IsDirectory(src.ref()))
5500b57cec5SDimitry Andric permissions = eFilePermissionsDirectoryDefault;
5510b57cec5SDimitry Andric else
5520b57cec5SDimitry Andric permissions = eFilePermissionsFileDefault;
5530b57cec5SDimitry Andric }
5540b57cec5SDimitry Andric
5550b57cec5SDimitry Andric return platform_sp->PutFile(src.ref(), dst.ref(), permissions);
5560b57cec5SDimitry Andric }
5570b57cec5SDimitry Andric
5580b57cec5SDimitry Andric Status error;
5590b57cec5SDimitry Andric error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
5600b57cec5SDimitry Andric src.ref().GetPath().c_str());
5610b57cec5SDimitry Andric return error;
5620b57cec5SDimitry Andric }));
5630b57cec5SDimitry Andric }
5640b57cec5SDimitry Andric
Install(SBFileSpec & src,SBFileSpec & dst)5650b57cec5SDimitry Andric SBError SBPlatform::Install(SBFileSpec &src, SBFileSpec &dst) {
5660b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Install,
5670b57cec5SDimitry Andric (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);
5680b57cec5SDimitry Andric return LLDB_RECORD_RESULT(
5690b57cec5SDimitry Andric ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
5700b57cec5SDimitry Andric if (src.Exists())
5710b57cec5SDimitry Andric return platform_sp->Install(src.ref(), dst.ref());
5720b57cec5SDimitry Andric
5730b57cec5SDimitry Andric Status error;
5740b57cec5SDimitry Andric error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
5750b57cec5SDimitry Andric src.ref().GetPath().c_str());
5760b57cec5SDimitry Andric return error;
5770b57cec5SDimitry Andric }));
5780b57cec5SDimitry Andric }
5790b57cec5SDimitry Andric
Run(SBPlatformShellCommand & shell_command)5800b57cec5SDimitry Andric SBError SBPlatform::Run(SBPlatformShellCommand &shell_command) {
5810b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Run,
5820b57cec5SDimitry Andric (lldb::SBPlatformShellCommand &), shell_command);
583af732203SDimitry Andric return LLDB_RECORD_RESULT(
584af732203SDimitry Andric ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
5850b57cec5SDimitry Andric const char *command = shell_command.GetCommand();
5860b57cec5SDimitry Andric if (!command)
5870b57cec5SDimitry Andric return Status("invalid shell command (empty)");
5880b57cec5SDimitry Andric
5890b57cec5SDimitry Andric const char *working_dir = shell_command.GetWorkingDirectory();
5900b57cec5SDimitry Andric if (working_dir == nullptr) {
5910b57cec5SDimitry Andric working_dir = platform_sp->GetWorkingDirectory().GetCString();
5920b57cec5SDimitry Andric if (working_dir)
5930b57cec5SDimitry Andric shell_command.SetWorkingDirectory(working_dir);
5940b57cec5SDimitry Andric }
595af732203SDimitry Andric return platform_sp->RunShellCommand(
596af732203SDimitry Andric shell_command.m_opaque_ptr->m_shell, command, FileSpec(working_dir),
5970b57cec5SDimitry Andric &shell_command.m_opaque_ptr->m_status,
5980b57cec5SDimitry Andric &shell_command.m_opaque_ptr->m_signo,
5990b57cec5SDimitry Andric &shell_command.m_opaque_ptr->m_output,
6000b57cec5SDimitry Andric shell_command.m_opaque_ptr->m_timeout);
6010b57cec5SDimitry Andric }));
6020b57cec5SDimitry Andric }
6030b57cec5SDimitry Andric
Launch(SBLaunchInfo & launch_info)6040b57cec5SDimitry Andric SBError SBPlatform::Launch(SBLaunchInfo &launch_info) {
6050b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Launch, (lldb::SBLaunchInfo &),
6060b57cec5SDimitry Andric launch_info);
6070b57cec5SDimitry Andric return LLDB_RECORD_RESULT(
6080b57cec5SDimitry Andric ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
6090b57cec5SDimitry Andric ProcessLaunchInfo info = launch_info.ref();
6100b57cec5SDimitry Andric Status error = platform_sp->LaunchProcess(info);
6110b57cec5SDimitry Andric launch_info.set_ref(info);
6120b57cec5SDimitry Andric return error;
6130b57cec5SDimitry Andric }));
6140b57cec5SDimitry Andric }
6150b57cec5SDimitry Andric
Kill(const lldb::pid_t pid)6160b57cec5SDimitry Andric SBError SBPlatform::Kill(const lldb::pid_t pid) {
6170b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Kill, (const lldb::pid_t), pid);
6180b57cec5SDimitry Andric return LLDB_RECORD_RESULT(
6190b57cec5SDimitry Andric ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
6200b57cec5SDimitry Andric return platform_sp->KillProcess(pid);
6210b57cec5SDimitry Andric }));
6220b57cec5SDimitry Andric }
6230b57cec5SDimitry Andric
ExecuteConnected(const std::function<Status (const lldb::PlatformSP &)> & func)6240b57cec5SDimitry Andric SBError SBPlatform::ExecuteConnected(
6250b57cec5SDimitry Andric const std::function<Status(const lldb::PlatformSP &)> &func) {
6260b57cec5SDimitry Andric SBError sb_error;
6270b57cec5SDimitry Andric const auto platform_sp(GetSP());
6280b57cec5SDimitry Andric if (platform_sp) {
6290b57cec5SDimitry Andric if (platform_sp->IsConnected())
6300b57cec5SDimitry Andric sb_error.ref() = func(platform_sp);
6310b57cec5SDimitry Andric else
6320b57cec5SDimitry Andric sb_error.SetErrorString("not connected");
6330b57cec5SDimitry Andric } else
6340b57cec5SDimitry Andric sb_error.SetErrorString("invalid platform");
6350b57cec5SDimitry Andric
6360b57cec5SDimitry Andric return sb_error;
6370b57cec5SDimitry Andric }
6380b57cec5SDimitry Andric
MakeDirectory(const char * path,uint32_t file_permissions)6390b57cec5SDimitry Andric SBError SBPlatform::MakeDirectory(const char *path, uint32_t file_permissions) {
6400b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, MakeDirectory,
6410b57cec5SDimitry Andric (const char *, uint32_t), path, file_permissions);
6420b57cec5SDimitry Andric
6430b57cec5SDimitry Andric SBError sb_error;
6440b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
6450b57cec5SDimitry Andric if (platform_sp) {
6460b57cec5SDimitry Andric sb_error.ref() =
6470b57cec5SDimitry Andric platform_sp->MakeDirectory(FileSpec(path), file_permissions);
6480b57cec5SDimitry Andric } else {
6490b57cec5SDimitry Andric sb_error.SetErrorString("invalid platform");
6500b57cec5SDimitry Andric }
6510b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
6520b57cec5SDimitry Andric }
6530b57cec5SDimitry Andric
GetFilePermissions(const char * path)6540b57cec5SDimitry Andric uint32_t SBPlatform::GetFilePermissions(const char *path) {
6550b57cec5SDimitry Andric LLDB_RECORD_METHOD(uint32_t, SBPlatform, GetFilePermissions, (const char *),
6560b57cec5SDimitry Andric path);
6570b57cec5SDimitry Andric
6580b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
6590b57cec5SDimitry Andric if (platform_sp) {
6600b57cec5SDimitry Andric uint32_t file_permissions = 0;
6610b57cec5SDimitry Andric platform_sp->GetFilePermissions(FileSpec(path), file_permissions);
6620b57cec5SDimitry Andric return file_permissions;
6630b57cec5SDimitry Andric }
6640b57cec5SDimitry Andric return 0;
6650b57cec5SDimitry Andric }
6660b57cec5SDimitry Andric
SetFilePermissions(const char * path,uint32_t file_permissions)6670b57cec5SDimitry Andric SBError SBPlatform::SetFilePermissions(const char *path,
6680b57cec5SDimitry Andric uint32_t file_permissions) {
6690b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, SetFilePermissions,
6700b57cec5SDimitry Andric (const char *, uint32_t), path, file_permissions);
6710b57cec5SDimitry Andric
6720b57cec5SDimitry Andric SBError sb_error;
6730b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
6740b57cec5SDimitry Andric if (platform_sp) {
6750b57cec5SDimitry Andric sb_error.ref() =
6760b57cec5SDimitry Andric platform_sp->SetFilePermissions(FileSpec(path), file_permissions);
6770b57cec5SDimitry Andric } else {
6780b57cec5SDimitry Andric sb_error.SetErrorString("invalid platform");
6790b57cec5SDimitry Andric }
6800b57cec5SDimitry Andric return LLDB_RECORD_RESULT(sb_error);
6810b57cec5SDimitry Andric }
6820b57cec5SDimitry Andric
GetUnixSignals() const6830b57cec5SDimitry Andric SBUnixSignals SBPlatform::GetUnixSignals() const {
6840b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBUnixSignals, SBPlatform,
6850b57cec5SDimitry Andric GetUnixSignals);
6860b57cec5SDimitry Andric
6870b57cec5SDimitry Andric if (auto platform_sp = GetSP())
6880b57cec5SDimitry Andric return LLDB_RECORD_RESULT(SBUnixSignals{platform_sp});
6890b57cec5SDimitry Andric
6900b57cec5SDimitry Andric return LLDB_RECORD_RESULT(SBUnixSignals());
6910b57cec5SDimitry Andric }
6920b57cec5SDimitry Andric
GetEnvironment()6935ffd83dbSDimitry Andric SBEnvironment SBPlatform::GetEnvironment() {
6945ffd83dbSDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBPlatform, GetEnvironment);
6955ffd83dbSDimitry Andric PlatformSP platform_sp(GetSP());
6965ffd83dbSDimitry Andric
6975ffd83dbSDimitry Andric if (platform_sp) {
6985ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(SBEnvironment(platform_sp->GetEnvironment()));
6995ffd83dbSDimitry Andric }
7005ffd83dbSDimitry Andric
7015ffd83dbSDimitry Andric return LLDB_RECORD_RESULT(SBEnvironment());
7025ffd83dbSDimitry Andric }
7035ffd83dbSDimitry Andric
7040b57cec5SDimitry Andric namespace lldb_private {
7050b57cec5SDimitry Andric namespace repro {
7060b57cec5SDimitry Andric
RegisterMethods(Registry & R)707af732203SDimitry Andric template <> void RegisterMethods<SBPlatformConnectOptions>(Registry &R) {
7080b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBPlatformConnectOptions, (const char *));
7090b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBPlatformConnectOptions,
7100b57cec5SDimitry Andric (const lldb::SBPlatformConnectOptions &));
7110b57cec5SDimitry Andric LLDB_REGISTER_METHOD(
7125ffd83dbSDimitry Andric SBPlatformConnectOptions &,
7130b57cec5SDimitry Andric SBPlatformConnectOptions, operator=,(
7140b57cec5SDimitry Andric const lldb::SBPlatformConnectOptions &));
7150b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatformConnectOptions, GetURL, ());
716af732203SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, SetURL, (const char *));
7170b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBPlatformConnectOptions, GetRsyncEnabled, ());
7180b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, EnableRsync,
7190b57cec5SDimitry Andric (const char *, const char *, bool));
7200b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, DisableRsync, ());
7210b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatformConnectOptions,
7220b57cec5SDimitry Andric GetLocalCacheDirectory, ());
7230b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, SetLocalCacheDirectory,
7240b57cec5SDimitry Andric (const char *));
7250b57cec5SDimitry Andric }
7260b57cec5SDimitry Andric
RegisterMethods(Registry & R)727af732203SDimitry Andric template <> void RegisterMethods<SBPlatformShellCommand>(Registry &R) {
7280b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand, (const char *));
7290b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand,
7300b57cec5SDimitry Andric (const lldb::SBPlatformShellCommand &));
7315ffd83dbSDimitry Andric LLDB_REGISTER_METHOD(
7325ffd83dbSDimitry Andric SBPlatformShellCommand &,
7335ffd83dbSDimitry Andric SBPlatformShellCommand, operator=,(const lldb::SBPlatformShellCommand &));
7340b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, Clear, ());
735af732203SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetShell, ());
736af732203SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetShell, (const char *));
7370b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetCommand, ());
7380b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetCommand,
7390b57cec5SDimitry Andric (const char *));
7400b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand,
7410b57cec5SDimitry Andric GetWorkingDirectory, ());
7420b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetWorkingDirectory,
7430b57cec5SDimitry Andric (const char *));
744af732203SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBPlatformShellCommand, GetTimeoutSeconds, ());
7450b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetTimeoutSeconds,
7460b57cec5SDimitry Andric (uint32_t));
7470b57cec5SDimitry Andric LLDB_REGISTER_METHOD(int, SBPlatformShellCommand, GetSignal, ());
7480b57cec5SDimitry Andric LLDB_REGISTER_METHOD(int, SBPlatformShellCommand, GetStatus, ());
7490b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetOutput, ());
7500b57cec5SDimitry Andric }
7510b57cec5SDimitry Andric
RegisterMethods(Registry & R)752af732203SDimitry Andric template <> void RegisterMethods<SBPlatform>(Registry &R) {
7530b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBPlatform, ());
7540b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBPlatform, (const char *));
7555ffd83dbSDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBPlatform, (const lldb::SBPlatform &));
756af732203SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand,
757af732203SDimitry Andric (const char *, const char *));
7585ffd83dbSDimitry Andric LLDB_REGISTER_METHOD(SBPlatform &,
7595ffd83dbSDimitry Andric SBPlatform, operator=,(const lldb::SBPlatform &));
7600b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(bool, SBPlatform, IsValid, ());
7610b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(bool, SBPlatform, operator bool,());
7620b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatform, Clear, ());
7630b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatform, GetName, ());
7640b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatform, GetWorkingDirectory, ());
7650b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBPlatform, SetWorkingDirectory, (const char *));
7660b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, ConnectRemote,
7670b57cec5SDimitry Andric (lldb::SBPlatformConnectOptions &));
7680b57cec5SDimitry Andric LLDB_REGISTER_METHOD(void, SBPlatform, DisconnectRemote, ());
7690b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBPlatform, IsConnected, ());
7700b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatform, GetTriple, ());
7710b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatform, GetOSBuild, ());
7720b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatform, GetOSDescription, ());
7730b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBPlatform, GetHostname, ());
7740b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetOSMajorVersion, ());
7750b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetOSMinorVersion, ());
7760b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetOSUpdateVersion, ());
7770b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Get,
7780b57cec5SDimitry Andric (lldb::SBFileSpec &, lldb::SBFileSpec &));
7790b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Put,
7800b57cec5SDimitry Andric (lldb::SBFileSpec &, lldb::SBFileSpec &));
7810b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Install,
7820b57cec5SDimitry Andric (lldb::SBFileSpec &, lldb::SBFileSpec &));
7830b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Run,
7840b57cec5SDimitry Andric (lldb::SBPlatformShellCommand &));
7850b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Launch,
7860b57cec5SDimitry Andric (lldb::SBLaunchInfo &));
7870b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Kill, (const lldb::pid_t));
7880b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, MakeDirectory,
7890b57cec5SDimitry Andric (const char *, uint32_t));
7900b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetFilePermissions,
7910b57cec5SDimitry Andric (const char *));
7920b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, SetFilePermissions,
7930b57cec5SDimitry Andric (const char *, uint32_t));
7945ffd83dbSDimitry Andric LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBPlatform, GetEnvironment, ());
7950b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(lldb::SBUnixSignals, SBPlatform, GetUnixSignals,
7960b57cec5SDimitry Andric ());
7975ffd83dbSDimitry Andric LLDB_REGISTER_STATIC_METHOD(lldb::SBPlatform, SBPlatform, GetHostPlatform,
7985ffd83dbSDimitry Andric ());
7990b57cec5SDimitry Andric }
8000b57cec5SDimitry Andric
801af732203SDimitry Andric } // namespace repro
802af732203SDimitry Andric } // namespace lldb_private
803