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"
10*c9157d92SDimitry Andric #include "lldb/API/SBDebugger.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"
15fe013be4SDimitry Andric #include "lldb/API/SBModuleSpec.h"
165ffd83dbSDimitry Andric #include "lldb/API/SBPlatform.h"
17*c9157d92SDimitry Andric #include "lldb/API/SBProcessInfoList.h"
18*c9157d92SDimitry Andric #include "lldb/API/SBTarget.h"
190b57cec5SDimitry Andric #include "lldb/API/SBUnixSignals.h"
200b57cec5SDimitry Andric #include "lldb/Host/File.h"
210b57cec5SDimitry Andric #include "lldb/Target/Platform.h"
220b57cec5SDimitry Andric #include "lldb/Target/Target.h"
230b57cec5SDimitry Andric #include "lldb/Utility/ArchSpec.h"
240b57cec5SDimitry Andric #include "lldb/Utility/Args.h"
2504eeddc0SDimitry Andric #include "lldb/Utility/Instrumentation.h"
260b57cec5SDimitry Andric #include "lldb/Utility/Status.h"
270b57cec5SDimitry Andric
280b57cec5SDimitry Andric #include "llvm/Support/FileSystem.h"
290b57cec5SDimitry Andric
300b57cec5SDimitry Andric #include <functional>
310b57cec5SDimitry Andric
320b57cec5SDimitry Andric using namespace lldb;
330b57cec5SDimitry Andric using namespace lldb_private;
340b57cec5SDimitry Andric
350b57cec5SDimitry Andric // PlatformConnectOptions
360b57cec5SDimitry Andric struct PlatformConnectOptions {
PlatformConnectOptionsPlatformConnectOptions3704eeddc0SDimitry Andric PlatformConnectOptions(const char *url = nullptr) {
380b57cec5SDimitry Andric if (url && url[0])
390b57cec5SDimitry Andric m_url = url;
400b57cec5SDimitry Andric }
410b57cec5SDimitry Andric
425ffd83dbSDimitry Andric ~PlatformConnectOptions() = default;
430b57cec5SDimitry Andric
440b57cec5SDimitry Andric std::string m_url;
450b57cec5SDimitry Andric std::string m_rsync_options;
460b57cec5SDimitry Andric std::string m_rsync_remote_path_prefix;
47fe6060f1SDimitry Andric bool m_rsync_enabled = false;
48fe6060f1SDimitry Andric bool m_rsync_omit_hostname_from_remote_path = false;
490b57cec5SDimitry Andric ConstString m_local_cache_directory;
500b57cec5SDimitry Andric };
510b57cec5SDimitry Andric
520b57cec5SDimitry Andric // PlatformShellCommand
530b57cec5SDimitry Andric struct PlatformShellCommand {
PlatformShellCommandPlatformShellCommand54e8d8bef9SDimitry Andric PlatformShellCommand(llvm::StringRef shell_interpreter,
5581ad6265SDimitry Andric llvm::StringRef shell_command) {
56e8d8bef9SDimitry Andric if (!shell_interpreter.empty())
57e8d8bef9SDimitry Andric m_shell = shell_interpreter.str();
58e8d8bef9SDimitry Andric
59e8d8bef9SDimitry Andric if (!m_shell.empty() && !shell_command.empty())
60e8d8bef9SDimitry Andric m_command = shell_command.str();
61e8d8bef9SDimitry Andric }
62e8d8bef9SDimitry Andric
PlatformShellCommandPlatformShellCommand6304eeddc0SDimitry Andric PlatformShellCommand(llvm::StringRef shell_command = llvm::StringRef()) {
64e8d8bef9SDimitry Andric if (!shell_command.empty())
65e8d8bef9SDimitry Andric m_command = shell_command.str();
660b57cec5SDimitry Andric }
670b57cec5SDimitry Andric
685ffd83dbSDimitry Andric ~PlatformShellCommand() = default;
690b57cec5SDimitry Andric
70e8d8bef9SDimitry Andric std::string m_shell;
710b57cec5SDimitry Andric std::string m_command;
720b57cec5SDimitry Andric std::string m_working_dir;
730b57cec5SDimitry Andric std::string m_output;
74fe6060f1SDimitry Andric int m_status = 0;
75fe6060f1SDimitry Andric int m_signo = 0;
76bdd1243dSDimitry Andric Timeout<std::ratio<1>> m_timeout = std::nullopt;
770b57cec5SDimitry Andric };
780b57cec5SDimitry Andric // SBPlatformConnectOptions
SBPlatformConnectOptions(const char * url)790b57cec5SDimitry Andric SBPlatformConnectOptions::SBPlatformConnectOptions(const char *url)
800b57cec5SDimitry Andric : m_opaque_ptr(new PlatformConnectOptions(url)) {
8104eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, url);
820b57cec5SDimitry Andric }
830b57cec5SDimitry Andric
SBPlatformConnectOptions(const SBPlatformConnectOptions & rhs)840b57cec5SDimitry Andric SBPlatformConnectOptions::SBPlatformConnectOptions(
850b57cec5SDimitry Andric const SBPlatformConnectOptions &rhs)
860b57cec5SDimitry Andric : m_opaque_ptr(new PlatformConnectOptions()) {
8704eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
880b57cec5SDimitry Andric
890b57cec5SDimitry Andric *m_opaque_ptr = *rhs.m_opaque_ptr;
900b57cec5SDimitry Andric }
910b57cec5SDimitry Andric
~SBPlatformConnectOptions()920b57cec5SDimitry Andric SBPlatformConnectOptions::~SBPlatformConnectOptions() { delete m_opaque_ptr; }
930b57cec5SDimitry Andric
94e8d8bef9SDimitry Andric SBPlatformConnectOptions &
operator =(const SBPlatformConnectOptions & rhs)95e8d8bef9SDimitry Andric SBPlatformConnectOptions::operator=(const SBPlatformConnectOptions &rhs) {
9604eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
970b57cec5SDimitry Andric
980b57cec5SDimitry Andric *m_opaque_ptr = *rhs.m_opaque_ptr;
9904eeddc0SDimitry Andric return *this;
1000b57cec5SDimitry Andric }
1010b57cec5SDimitry Andric
GetURL()1020b57cec5SDimitry Andric const char *SBPlatformConnectOptions::GetURL() {
10304eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andric if (m_opaque_ptr->m_url.empty())
1060b57cec5SDimitry Andric return nullptr;
107fe013be4SDimitry Andric return ConstString(m_opaque_ptr->m_url.c_str()).GetCString();
1080b57cec5SDimitry Andric }
1090b57cec5SDimitry Andric
SetURL(const char * url)1100b57cec5SDimitry Andric void SBPlatformConnectOptions::SetURL(const char *url) {
11104eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, url);
1120b57cec5SDimitry Andric
1130b57cec5SDimitry Andric if (url && url[0])
1140b57cec5SDimitry Andric m_opaque_ptr->m_url = url;
1150b57cec5SDimitry Andric else
1160b57cec5SDimitry Andric m_opaque_ptr->m_url.clear();
1170b57cec5SDimitry Andric }
1180b57cec5SDimitry Andric
GetRsyncEnabled()1190b57cec5SDimitry Andric bool SBPlatformConnectOptions::GetRsyncEnabled() {
12004eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
1210b57cec5SDimitry Andric
1220b57cec5SDimitry Andric return m_opaque_ptr->m_rsync_enabled;
1230b57cec5SDimitry Andric }
1240b57cec5SDimitry Andric
EnableRsync(const char * options,const char * remote_path_prefix,bool omit_hostname_from_remote_path)1250b57cec5SDimitry Andric void SBPlatformConnectOptions::EnableRsync(
1260b57cec5SDimitry Andric const char *options, const char *remote_path_prefix,
1270b57cec5SDimitry Andric bool omit_hostname_from_remote_path) {
12804eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, options, remote_path_prefix,
12904eeddc0SDimitry Andric omit_hostname_from_remote_path);
1300b57cec5SDimitry Andric
1310b57cec5SDimitry Andric m_opaque_ptr->m_rsync_enabled = true;
1320b57cec5SDimitry Andric m_opaque_ptr->m_rsync_omit_hostname_from_remote_path =
1330b57cec5SDimitry Andric omit_hostname_from_remote_path;
1340b57cec5SDimitry Andric if (remote_path_prefix && remote_path_prefix[0])
1350b57cec5SDimitry Andric m_opaque_ptr->m_rsync_remote_path_prefix = remote_path_prefix;
1360b57cec5SDimitry Andric else
1370b57cec5SDimitry Andric m_opaque_ptr->m_rsync_remote_path_prefix.clear();
1380b57cec5SDimitry Andric
1390b57cec5SDimitry Andric if (options && options[0])
1400b57cec5SDimitry Andric m_opaque_ptr->m_rsync_options = options;
1410b57cec5SDimitry Andric else
1420b57cec5SDimitry Andric m_opaque_ptr->m_rsync_options.clear();
1430b57cec5SDimitry Andric }
1440b57cec5SDimitry Andric
DisableRsync()1450b57cec5SDimitry Andric void SBPlatformConnectOptions::DisableRsync() {
14604eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andric m_opaque_ptr->m_rsync_enabled = false;
1490b57cec5SDimitry Andric }
1500b57cec5SDimitry Andric
GetLocalCacheDirectory()1510b57cec5SDimitry Andric const char *SBPlatformConnectOptions::GetLocalCacheDirectory() {
15204eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
1530b57cec5SDimitry Andric
1540b57cec5SDimitry Andric return m_opaque_ptr->m_local_cache_directory.GetCString();
1550b57cec5SDimitry Andric }
1560b57cec5SDimitry Andric
SetLocalCacheDirectory(const char * path)1570b57cec5SDimitry Andric void SBPlatformConnectOptions::SetLocalCacheDirectory(const char *path) {
15804eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, path);
1590b57cec5SDimitry Andric
1600b57cec5SDimitry Andric if (path && path[0])
1610b57cec5SDimitry Andric m_opaque_ptr->m_local_cache_directory.SetCString(path);
1620b57cec5SDimitry Andric else
1630b57cec5SDimitry Andric m_opaque_ptr->m_local_cache_directory = ConstString();
1640b57cec5SDimitry Andric }
1650b57cec5SDimitry Andric
1660b57cec5SDimitry Andric // SBPlatformShellCommand
SBPlatformShellCommand(const char * shell_interpreter,const char * shell_command)167e8d8bef9SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_interpreter,
168e8d8bef9SDimitry Andric const char *shell_command)
169e8d8bef9SDimitry Andric : m_opaque_ptr(new PlatformShellCommand(shell_interpreter, shell_command)) {
17004eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_interpreter, shell_command);
171e8d8bef9SDimitry Andric }
172e8d8bef9SDimitry Andric
SBPlatformShellCommand(const char * shell_command)1730b57cec5SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_command)
1740b57cec5SDimitry Andric : m_opaque_ptr(new PlatformShellCommand(shell_command)) {
17504eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_command);
1760b57cec5SDimitry Andric }
1770b57cec5SDimitry Andric
SBPlatformShellCommand(const SBPlatformShellCommand & rhs)1780b57cec5SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(
1790b57cec5SDimitry Andric const SBPlatformShellCommand &rhs)
1800b57cec5SDimitry Andric : m_opaque_ptr(new PlatformShellCommand()) {
18104eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
1820b57cec5SDimitry Andric
1830b57cec5SDimitry Andric *m_opaque_ptr = *rhs.m_opaque_ptr;
1840b57cec5SDimitry Andric }
1850b57cec5SDimitry Andric
186e8d8bef9SDimitry Andric SBPlatformShellCommand &
operator =(const SBPlatformShellCommand & rhs)187e8d8bef9SDimitry Andric SBPlatformShellCommand::operator=(const SBPlatformShellCommand &rhs) {
1885ffd83dbSDimitry Andric
18904eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
1905ffd83dbSDimitry Andric
1915ffd83dbSDimitry Andric *m_opaque_ptr = *rhs.m_opaque_ptr;
19204eeddc0SDimitry Andric return *this;
1935ffd83dbSDimitry Andric }
1945ffd83dbSDimitry Andric
~SBPlatformShellCommand()1950b57cec5SDimitry Andric SBPlatformShellCommand::~SBPlatformShellCommand() { delete m_opaque_ptr; }
1960b57cec5SDimitry Andric
Clear()1970b57cec5SDimitry Andric void SBPlatformShellCommand::Clear() {
19804eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andric m_opaque_ptr->m_output = std::string();
2010b57cec5SDimitry Andric m_opaque_ptr->m_status = 0;
2020b57cec5SDimitry Andric m_opaque_ptr->m_signo = 0;
2030b57cec5SDimitry Andric }
2040b57cec5SDimitry Andric
GetShell()205e8d8bef9SDimitry Andric const char *SBPlatformShellCommand::GetShell() {
20604eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
207e8d8bef9SDimitry Andric
208e8d8bef9SDimitry Andric if (m_opaque_ptr->m_shell.empty())
209e8d8bef9SDimitry Andric return nullptr;
210fe013be4SDimitry Andric return ConstString(m_opaque_ptr->m_shell.c_str()).GetCString();
211e8d8bef9SDimitry Andric }
212e8d8bef9SDimitry Andric
SetShell(const char * shell_interpreter)213e8d8bef9SDimitry Andric void SBPlatformShellCommand::SetShell(const char *shell_interpreter) {
21404eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_interpreter);
215e8d8bef9SDimitry Andric
216e8d8bef9SDimitry Andric if (shell_interpreter && shell_interpreter[0])
217e8d8bef9SDimitry Andric m_opaque_ptr->m_shell = shell_interpreter;
218e8d8bef9SDimitry Andric else
219e8d8bef9SDimitry Andric m_opaque_ptr->m_shell.clear();
220e8d8bef9SDimitry Andric }
221e8d8bef9SDimitry Andric
GetCommand()2220b57cec5SDimitry Andric const char *SBPlatformShellCommand::GetCommand() {
22304eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
2240b57cec5SDimitry Andric
2250b57cec5SDimitry Andric if (m_opaque_ptr->m_command.empty())
2260b57cec5SDimitry Andric return nullptr;
227fe013be4SDimitry Andric return ConstString(m_opaque_ptr->m_command.c_str()).GetCString();
2280b57cec5SDimitry Andric }
2290b57cec5SDimitry Andric
SetCommand(const char * shell_command)2300b57cec5SDimitry Andric void SBPlatformShellCommand::SetCommand(const char *shell_command) {
23104eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_command);
2320b57cec5SDimitry Andric
2330b57cec5SDimitry Andric if (shell_command && shell_command[0])
2340b57cec5SDimitry Andric m_opaque_ptr->m_command = shell_command;
2350b57cec5SDimitry Andric else
2360b57cec5SDimitry Andric m_opaque_ptr->m_command.clear();
2370b57cec5SDimitry Andric }
2380b57cec5SDimitry Andric
GetWorkingDirectory()2390b57cec5SDimitry Andric const char *SBPlatformShellCommand::GetWorkingDirectory() {
24004eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
2410b57cec5SDimitry Andric
2420b57cec5SDimitry Andric if (m_opaque_ptr->m_working_dir.empty())
2430b57cec5SDimitry Andric return nullptr;
244fe013be4SDimitry Andric return ConstString(m_opaque_ptr->m_working_dir.c_str()).GetCString();
2450b57cec5SDimitry Andric }
2460b57cec5SDimitry Andric
SetWorkingDirectory(const char * path)2470b57cec5SDimitry Andric void SBPlatformShellCommand::SetWorkingDirectory(const char *path) {
24804eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, path);
2490b57cec5SDimitry Andric
2500b57cec5SDimitry Andric if (path && path[0])
2510b57cec5SDimitry Andric m_opaque_ptr->m_working_dir = path;
2520b57cec5SDimitry Andric else
2530b57cec5SDimitry Andric m_opaque_ptr->m_working_dir.clear();
2540b57cec5SDimitry Andric }
2550b57cec5SDimitry Andric
GetTimeoutSeconds()2560b57cec5SDimitry Andric uint32_t SBPlatformShellCommand::GetTimeoutSeconds() {
25704eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
2580b57cec5SDimitry Andric
2590b57cec5SDimitry Andric if (m_opaque_ptr->m_timeout)
2600b57cec5SDimitry Andric return m_opaque_ptr->m_timeout->count();
2610b57cec5SDimitry Andric return UINT32_MAX;
2620b57cec5SDimitry Andric }
2630b57cec5SDimitry Andric
SetTimeoutSeconds(uint32_t sec)2640b57cec5SDimitry Andric void SBPlatformShellCommand::SetTimeoutSeconds(uint32_t sec) {
26504eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, sec);
2660b57cec5SDimitry Andric
2670b57cec5SDimitry Andric if (sec == UINT32_MAX)
268bdd1243dSDimitry Andric m_opaque_ptr->m_timeout = std::nullopt;
2690b57cec5SDimitry Andric else
2700b57cec5SDimitry Andric m_opaque_ptr->m_timeout = std::chrono::seconds(sec);
2710b57cec5SDimitry Andric }
2720b57cec5SDimitry Andric
GetSignal()2730b57cec5SDimitry Andric int SBPlatformShellCommand::GetSignal() {
27404eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
2750b57cec5SDimitry Andric
2760b57cec5SDimitry Andric return m_opaque_ptr->m_signo;
2770b57cec5SDimitry Andric }
2780b57cec5SDimitry Andric
GetStatus()2790b57cec5SDimitry Andric int SBPlatformShellCommand::GetStatus() {
28004eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
2810b57cec5SDimitry Andric
2820b57cec5SDimitry Andric return m_opaque_ptr->m_status;
2830b57cec5SDimitry Andric }
2840b57cec5SDimitry Andric
GetOutput()2850b57cec5SDimitry Andric const char *SBPlatformShellCommand::GetOutput() {
28604eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
2870b57cec5SDimitry Andric
2880b57cec5SDimitry Andric if (m_opaque_ptr->m_output.empty())
2890b57cec5SDimitry Andric return nullptr;
290fe013be4SDimitry Andric return ConstString(m_opaque_ptr->m_output.c_str()).GetCString();
2910b57cec5SDimitry Andric }
2920b57cec5SDimitry Andric
2930b57cec5SDimitry Andric // SBPlatform
SBPlatform()29404eeddc0SDimitry Andric SBPlatform::SBPlatform() { LLDB_INSTRUMENT_VA(this); }
2950b57cec5SDimitry Andric
SBPlatform(const char * platform_name)29604eeddc0SDimitry Andric SBPlatform::SBPlatform(const char *platform_name) {
29704eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, platform_name);
2980b57cec5SDimitry Andric
29981ad6265SDimitry Andric m_opaque_sp = Platform::Create(platform_name);
3000b57cec5SDimitry Andric }
3010b57cec5SDimitry Andric
SBPlatform(const SBPlatform & rhs)3025ffd83dbSDimitry Andric SBPlatform::SBPlatform(const SBPlatform &rhs) {
30304eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
3045ffd83dbSDimitry Andric
3055ffd83dbSDimitry Andric m_opaque_sp = rhs.m_opaque_sp;
3065ffd83dbSDimitry Andric }
3075ffd83dbSDimitry Andric
operator =(const SBPlatform & rhs)3085ffd83dbSDimitry Andric SBPlatform &SBPlatform::operator=(const SBPlatform &rhs) {
30904eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
3105ffd83dbSDimitry Andric
3115ffd83dbSDimitry Andric m_opaque_sp = rhs.m_opaque_sp;
31204eeddc0SDimitry Andric return *this;
3135ffd83dbSDimitry Andric }
3145ffd83dbSDimitry Andric
3155ffd83dbSDimitry Andric SBPlatform::~SBPlatform() = default;
3165ffd83dbSDimitry Andric
GetHostPlatform()3175ffd83dbSDimitry Andric SBPlatform SBPlatform::GetHostPlatform() {
31804eeddc0SDimitry Andric LLDB_INSTRUMENT();
3195ffd83dbSDimitry Andric
3205ffd83dbSDimitry Andric SBPlatform host_platform;
3215ffd83dbSDimitry Andric host_platform.m_opaque_sp = Platform::GetHostPlatform();
32204eeddc0SDimitry Andric return host_platform;
3235ffd83dbSDimitry Andric }
3240b57cec5SDimitry Andric
IsValid() const3250b57cec5SDimitry Andric bool SBPlatform::IsValid() const {
32604eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
3270b57cec5SDimitry Andric return this->operator bool();
3280b57cec5SDimitry Andric }
operator bool() const3290b57cec5SDimitry Andric SBPlatform::operator bool() const {
33004eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
3310b57cec5SDimitry Andric
3320b57cec5SDimitry Andric return m_opaque_sp.get() != nullptr;
3330b57cec5SDimitry Andric }
3340b57cec5SDimitry Andric
Clear()3350b57cec5SDimitry Andric void SBPlatform::Clear() {
33604eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
3370b57cec5SDimitry Andric
3380b57cec5SDimitry Andric m_opaque_sp.reset();
3390b57cec5SDimitry Andric }
3400b57cec5SDimitry Andric
GetName()3410b57cec5SDimitry Andric const char *SBPlatform::GetName() {
34204eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
3430b57cec5SDimitry Andric
3440b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
3450b57cec5SDimitry Andric if (platform_sp)
34681ad6265SDimitry Andric return ConstString(platform_sp->GetName()).AsCString();
3470b57cec5SDimitry Andric return nullptr;
3480b57cec5SDimitry Andric }
3490b57cec5SDimitry Andric
GetSP() const3500b57cec5SDimitry Andric lldb::PlatformSP SBPlatform::GetSP() const { return m_opaque_sp; }
3510b57cec5SDimitry Andric
SetSP(const lldb::PlatformSP & platform_sp)3520b57cec5SDimitry Andric void SBPlatform::SetSP(const lldb::PlatformSP &platform_sp) {
3530b57cec5SDimitry Andric m_opaque_sp = platform_sp;
3540b57cec5SDimitry Andric }
3550b57cec5SDimitry Andric
GetWorkingDirectory()3560b57cec5SDimitry Andric const char *SBPlatform::GetWorkingDirectory() {
35704eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
3580b57cec5SDimitry Andric
3590b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
3600b57cec5SDimitry Andric if (platform_sp)
361bdd1243dSDimitry Andric return platform_sp->GetWorkingDirectory().GetPathAsConstString().AsCString();
3620b57cec5SDimitry Andric return nullptr;
3630b57cec5SDimitry Andric }
3640b57cec5SDimitry Andric
SetWorkingDirectory(const char * path)3650b57cec5SDimitry Andric bool SBPlatform::SetWorkingDirectory(const char *path) {
36604eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, path);
3670b57cec5SDimitry Andric
3680b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
3690b57cec5SDimitry Andric if (platform_sp) {
3700b57cec5SDimitry Andric if (path)
3710b57cec5SDimitry Andric platform_sp->SetWorkingDirectory(FileSpec(path));
3720b57cec5SDimitry Andric else
3730b57cec5SDimitry Andric platform_sp->SetWorkingDirectory(FileSpec());
3740b57cec5SDimitry Andric return true;
3750b57cec5SDimitry Andric }
3760b57cec5SDimitry Andric return false;
3770b57cec5SDimitry Andric }
3780b57cec5SDimitry Andric
ConnectRemote(SBPlatformConnectOptions & connect_options)3790b57cec5SDimitry Andric SBError SBPlatform::ConnectRemote(SBPlatformConnectOptions &connect_options) {
38004eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, connect_options);
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andric SBError sb_error;
3830b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
3840b57cec5SDimitry Andric if (platform_sp && connect_options.GetURL()) {
3850b57cec5SDimitry Andric Args args;
386fe6060f1SDimitry Andric args.AppendArgument(connect_options.GetURL());
3870b57cec5SDimitry Andric sb_error.ref() = platform_sp->ConnectRemote(args);
3880b57cec5SDimitry Andric } else {
3890b57cec5SDimitry Andric sb_error.SetErrorString("invalid platform");
3900b57cec5SDimitry Andric }
39104eeddc0SDimitry Andric return sb_error;
3920b57cec5SDimitry Andric }
3930b57cec5SDimitry Andric
DisconnectRemote()3940b57cec5SDimitry Andric void SBPlatform::DisconnectRemote() {
39504eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
3960b57cec5SDimitry Andric
3970b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
3980b57cec5SDimitry Andric if (platform_sp)
3990b57cec5SDimitry Andric platform_sp->DisconnectRemote();
4000b57cec5SDimitry Andric }
4010b57cec5SDimitry Andric
IsConnected()4020b57cec5SDimitry Andric bool SBPlatform::IsConnected() {
40304eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4060b57cec5SDimitry Andric if (platform_sp)
4070b57cec5SDimitry Andric return platform_sp->IsConnected();
4080b57cec5SDimitry Andric return false;
4090b57cec5SDimitry Andric }
4100b57cec5SDimitry Andric
GetTriple()4110b57cec5SDimitry Andric const char *SBPlatform::GetTriple() {
41204eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
4130b57cec5SDimitry Andric
4140b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4150b57cec5SDimitry Andric if (platform_sp) {
4160b57cec5SDimitry Andric ArchSpec arch(platform_sp->GetSystemArchitecture());
4170b57cec5SDimitry Andric if (arch.IsValid()) {
4180b57cec5SDimitry Andric // Const-ify the string so we don't need to worry about the lifetime of
4190b57cec5SDimitry Andric // the string
4200b57cec5SDimitry Andric return ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
4210b57cec5SDimitry Andric }
4220b57cec5SDimitry Andric }
4230b57cec5SDimitry Andric return nullptr;
4240b57cec5SDimitry Andric }
4250b57cec5SDimitry Andric
GetOSBuild()4260b57cec5SDimitry Andric const char *SBPlatform::GetOSBuild() {
42704eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
4280b57cec5SDimitry Andric
4290b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4300b57cec5SDimitry Andric if (platform_sp) {
43181ad6265SDimitry Andric std::string s = platform_sp->GetOSBuildString().value_or("");
4320b57cec5SDimitry Andric if (!s.empty()) {
4330b57cec5SDimitry Andric // Const-ify the string so we don't need to worry about the lifetime of
4340b57cec5SDimitry Andric // the string
435349cc55cSDimitry Andric return ConstString(s).GetCString();
4360b57cec5SDimitry Andric }
4370b57cec5SDimitry Andric }
4380b57cec5SDimitry Andric return nullptr;
4390b57cec5SDimitry Andric }
4400b57cec5SDimitry Andric
GetOSDescription()4410b57cec5SDimitry Andric const char *SBPlatform::GetOSDescription() {
44204eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
4430b57cec5SDimitry Andric
4440b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4450b57cec5SDimitry Andric if (platform_sp) {
44681ad6265SDimitry Andric std::string s = platform_sp->GetOSKernelDescription().value_or("");
4470b57cec5SDimitry Andric if (!s.empty()) {
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(s.c_str()).GetCString();
4510b57cec5SDimitry Andric }
4520b57cec5SDimitry Andric }
4530b57cec5SDimitry Andric return nullptr;
4540b57cec5SDimitry Andric }
4550b57cec5SDimitry Andric
GetHostname()4560b57cec5SDimitry Andric const char *SBPlatform::GetHostname() {
45704eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
4580b57cec5SDimitry Andric
4590b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
4600b57cec5SDimitry Andric if (platform_sp)
461fe013be4SDimitry Andric return ConstString(platform_sp->GetHostname()).GetCString();
4620b57cec5SDimitry Andric return nullptr;
4630b57cec5SDimitry Andric }
4640b57cec5SDimitry Andric
GetOSMajorVersion()4650b57cec5SDimitry Andric uint32_t SBPlatform::GetOSMajorVersion() {
46604eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
4670b57cec5SDimitry Andric
4680b57cec5SDimitry Andric llvm::VersionTuple version;
4690b57cec5SDimitry Andric if (PlatformSP platform_sp = GetSP())
4700b57cec5SDimitry Andric version = platform_sp->GetOSVersion();
4710b57cec5SDimitry Andric return version.empty() ? UINT32_MAX : version.getMajor();
4720b57cec5SDimitry Andric }
4730b57cec5SDimitry Andric
GetOSMinorVersion()4740b57cec5SDimitry Andric uint32_t SBPlatform::GetOSMinorVersion() {
47504eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
4760b57cec5SDimitry Andric
4770b57cec5SDimitry Andric llvm::VersionTuple version;
4780b57cec5SDimitry Andric if (PlatformSP platform_sp = GetSP())
4790b57cec5SDimitry Andric version = platform_sp->GetOSVersion();
48081ad6265SDimitry Andric return version.getMinor().value_or(UINT32_MAX);
4810b57cec5SDimitry Andric }
4820b57cec5SDimitry Andric
GetOSUpdateVersion()4830b57cec5SDimitry Andric uint32_t SBPlatform::GetOSUpdateVersion() {
48404eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
4850b57cec5SDimitry Andric
4860b57cec5SDimitry Andric llvm::VersionTuple version;
4870b57cec5SDimitry Andric if (PlatformSP platform_sp = GetSP())
4880b57cec5SDimitry Andric version = platform_sp->GetOSVersion();
48981ad6265SDimitry Andric return version.getSubminor().value_or(UINT32_MAX);
4900b57cec5SDimitry Andric }
4910b57cec5SDimitry Andric
SetSDKRoot(const char * sysroot)49204eeddc0SDimitry Andric void SBPlatform::SetSDKRoot(const char *sysroot) {
49304eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, sysroot);
49404eeddc0SDimitry Andric if (PlatformSP platform_sp = GetSP())
495fe013be4SDimitry Andric platform_sp->SetSDKRootDirectory(llvm::StringRef(sysroot).str());
49604eeddc0SDimitry Andric }
49704eeddc0SDimitry Andric
Get(SBFileSpec & src,SBFileSpec & dst)4980b57cec5SDimitry Andric SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
49904eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, src, dst);
5000b57cec5SDimitry Andric
5010b57cec5SDimitry Andric SBError sb_error;
5020b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
5030b57cec5SDimitry Andric if (platform_sp) {
5040b57cec5SDimitry Andric sb_error.ref() = platform_sp->GetFile(src.ref(), dst.ref());
5050b57cec5SDimitry Andric } else {
5060b57cec5SDimitry Andric sb_error.SetErrorString("invalid platform");
5070b57cec5SDimitry Andric }
50804eeddc0SDimitry Andric return sb_error;
5090b57cec5SDimitry Andric }
5100b57cec5SDimitry Andric
Put(SBFileSpec & src,SBFileSpec & dst)5110b57cec5SDimitry Andric SBError SBPlatform::Put(SBFileSpec &src, SBFileSpec &dst) {
51204eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, src, dst);
51304eeddc0SDimitry Andric return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
5140b57cec5SDimitry Andric if (src.Exists()) {
51504eeddc0SDimitry Andric uint32_t permissions = FileSystem::Instance().GetPermissions(src.ref());
5160b57cec5SDimitry Andric if (permissions == 0) {
5170b57cec5SDimitry Andric if (FileSystem::Instance().IsDirectory(src.ref()))
5180b57cec5SDimitry Andric permissions = eFilePermissionsDirectoryDefault;
5190b57cec5SDimitry Andric else
5200b57cec5SDimitry Andric permissions = eFilePermissionsFileDefault;
5210b57cec5SDimitry Andric }
5220b57cec5SDimitry Andric
5230b57cec5SDimitry Andric return platform_sp->PutFile(src.ref(), dst.ref(), permissions);
5240b57cec5SDimitry Andric }
5250b57cec5SDimitry Andric
5260b57cec5SDimitry Andric Status error;
5270b57cec5SDimitry Andric error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
5280b57cec5SDimitry Andric src.ref().GetPath().c_str());
5290b57cec5SDimitry Andric return error;
53004eeddc0SDimitry Andric });
5310b57cec5SDimitry Andric }
5320b57cec5SDimitry Andric
Install(SBFileSpec & src,SBFileSpec & dst)5330b57cec5SDimitry Andric SBError SBPlatform::Install(SBFileSpec &src, SBFileSpec &dst) {
53404eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, src, dst);
53504eeddc0SDimitry Andric return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
5360b57cec5SDimitry Andric if (src.Exists())
5370b57cec5SDimitry Andric return platform_sp->Install(src.ref(), dst.ref());
5380b57cec5SDimitry Andric
5390b57cec5SDimitry Andric Status error;
5400b57cec5SDimitry Andric error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
5410b57cec5SDimitry Andric src.ref().GetPath().c_str());
5420b57cec5SDimitry Andric return error;
54304eeddc0SDimitry Andric });
5440b57cec5SDimitry Andric }
5450b57cec5SDimitry Andric
Run(SBPlatformShellCommand & shell_command)5460b57cec5SDimitry Andric SBError SBPlatform::Run(SBPlatformShellCommand &shell_command) {
54704eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, shell_command);
54804eeddc0SDimitry Andric return ExecuteConnected(
54904eeddc0SDimitry Andric [&](const lldb::PlatformSP &platform_sp) {
5500b57cec5SDimitry Andric const char *command = shell_command.GetCommand();
5510b57cec5SDimitry Andric if (!command)
5520b57cec5SDimitry Andric return Status("invalid shell command (empty)");
5530b57cec5SDimitry Andric
554bdd1243dSDimitry Andric if (shell_command.GetWorkingDirectory() == nullptr) {
555bdd1243dSDimitry Andric std::string platform_working_dir =
556bdd1243dSDimitry Andric platform_sp->GetWorkingDirectory().GetPath();
557bdd1243dSDimitry Andric if (!platform_working_dir.empty())
558bdd1243dSDimitry Andric shell_command.SetWorkingDirectory(platform_working_dir.c_str());
5590b57cec5SDimitry Andric }
560e8d8bef9SDimitry Andric return platform_sp->RunShellCommand(
561bdd1243dSDimitry Andric shell_command.m_opaque_ptr->m_shell, command,
562bdd1243dSDimitry Andric FileSpec(shell_command.GetWorkingDirectory()),
5630b57cec5SDimitry Andric &shell_command.m_opaque_ptr->m_status,
5640b57cec5SDimitry Andric &shell_command.m_opaque_ptr->m_signo,
5650b57cec5SDimitry Andric &shell_command.m_opaque_ptr->m_output,
5660b57cec5SDimitry Andric shell_command.m_opaque_ptr->m_timeout);
56704eeddc0SDimitry Andric });
5680b57cec5SDimitry Andric }
5690b57cec5SDimitry Andric
Launch(SBLaunchInfo & launch_info)5700b57cec5SDimitry Andric SBError SBPlatform::Launch(SBLaunchInfo &launch_info) {
57104eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, launch_info);
57204eeddc0SDimitry Andric return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
5730b57cec5SDimitry Andric ProcessLaunchInfo info = launch_info.ref();
5740b57cec5SDimitry Andric Status error = platform_sp->LaunchProcess(info);
5750b57cec5SDimitry Andric launch_info.set_ref(info);
5760b57cec5SDimitry Andric return error;
57704eeddc0SDimitry Andric });
5780b57cec5SDimitry Andric }
5790b57cec5SDimitry Andric
Attach(SBAttachInfo & attach_info,const SBDebugger & debugger,SBTarget & target,SBError & error)580*c9157d92SDimitry Andric SBProcess SBPlatform::Attach(SBAttachInfo &attach_info,
581*c9157d92SDimitry Andric const SBDebugger &debugger, SBTarget &target,
582*c9157d92SDimitry Andric SBError &error) {
583*c9157d92SDimitry Andric LLDB_INSTRUMENT_VA(this, attach_info, debugger, target, error);
584*c9157d92SDimitry Andric
585*c9157d92SDimitry Andric if (PlatformSP platform_sp = GetSP()) {
586*c9157d92SDimitry Andric if (platform_sp->IsConnected()) {
587*c9157d92SDimitry Andric ProcessAttachInfo &info = attach_info.ref();
588*c9157d92SDimitry Andric Status status;
589*c9157d92SDimitry Andric ProcessSP process_sp = platform_sp->Attach(info, debugger.ref(),
590*c9157d92SDimitry Andric target.GetSP().get(), status);
591*c9157d92SDimitry Andric error.SetError(status);
592*c9157d92SDimitry Andric return SBProcess(process_sp);
593*c9157d92SDimitry Andric }
594*c9157d92SDimitry Andric
595*c9157d92SDimitry Andric error.SetErrorString("not connected");
596*c9157d92SDimitry Andric return {};
597*c9157d92SDimitry Andric }
598*c9157d92SDimitry Andric
599*c9157d92SDimitry Andric error.SetErrorString("invalid platform");
600*c9157d92SDimitry Andric return {};
601*c9157d92SDimitry Andric }
602*c9157d92SDimitry Andric
GetAllProcesses(SBError & error)603*c9157d92SDimitry Andric SBProcessInfoList SBPlatform::GetAllProcesses(SBError &error) {
604*c9157d92SDimitry Andric if (PlatformSP platform_sp = GetSP()) {
605*c9157d92SDimitry Andric if (platform_sp->IsConnected()) {
606*c9157d92SDimitry Andric ProcessInstanceInfoList list = platform_sp->GetAllProcesses();
607*c9157d92SDimitry Andric return SBProcessInfoList(list);
608*c9157d92SDimitry Andric }
609*c9157d92SDimitry Andric error.SetErrorString("not connected");
610*c9157d92SDimitry Andric return {};
611*c9157d92SDimitry Andric }
612*c9157d92SDimitry Andric
613*c9157d92SDimitry Andric error.SetErrorString("invalid platform");
614*c9157d92SDimitry Andric return {};
615*c9157d92SDimitry Andric }
616*c9157d92SDimitry Andric
Kill(const lldb::pid_t pid)6170b57cec5SDimitry Andric SBError SBPlatform::Kill(const lldb::pid_t pid) {
61804eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, pid);
61904eeddc0SDimitry Andric return ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
6200b57cec5SDimitry Andric return platform_sp->KillProcess(pid);
62104eeddc0SDimitry 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) {
64004eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, path, file_permissions);
6410b57cec5SDimitry Andric
6420b57cec5SDimitry Andric SBError sb_error;
6430b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
6440b57cec5SDimitry Andric if (platform_sp) {
6450b57cec5SDimitry Andric sb_error.ref() =
6460b57cec5SDimitry Andric platform_sp->MakeDirectory(FileSpec(path), file_permissions);
6470b57cec5SDimitry Andric } else {
6480b57cec5SDimitry Andric sb_error.SetErrorString("invalid platform");
6490b57cec5SDimitry Andric }
65004eeddc0SDimitry Andric return sb_error;
6510b57cec5SDimitry Andric }
6520b57cec5SDimitry Andric
GetFilePermissions(const char * path)6530b57cec5SDimitry Andric uint32_t SBPlatform::GetFilePermissions(const char *path) {
65404eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, path);
6550b57cec5SDimitry Andric
6560b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
6570b57cec5SDimitry Andric if (platform_sp) {
6580b57cec5SDimitry Andric uint32_t file_permissions = 0;
6590b57cec5SDimitry Andric platform_sp->GetFilePermissions(FileSpec(path), file_permissions);
6600b57cec5SDimitry Andric return file_permissions;
6610b57cec5SDimitry Andric }
6620b57cec5SDimitry Andric return 0;
6630b57cec5SDimitry Andric }
6640b57cec5SDimitry Andric
SetFilePermissions(const char * path,uint32_t file_permissions)6650b57cec5SDimitry Andric SBError SBPlatform::SetFilePermissions(const char *path,
6660b57cec5SDimitry Andric uint32_t file_permissions) {
66704eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this, path, file_permissions);
6680b57cec5SDimitry Andric
6690b57cec5SDimitry Andric SBError sb_error;
6700b57cec5SDimitry Andric PlatformSP platform_sp(GetSP());
6710b57cec5SDimitry Andric if (platform_sp) {
6720b57cec5SDimitry Andric sb_error.ref() =
6730b57cec5SDimitry Andric platform_sp->SetFilePermissions(FileSpec(path), file_permissions);
6740b57cec5SDimitry Andric } else {
6750b57cec5SDimitry Andric sb_error.SetErrorString("invalid platform");
6760b57cec5SDimitry Andric }
67704eeddc0SDimitry Andric return sb_error;
6780b57cec5SDimitry Andric }
6790b57cec5SDimitry Andric
GetUnixSignals() const6800b57cec5SDimitry Andric SBUnixSignals SBPlatform::GetUnixSignals() const {
68104eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
6820b57cec5SDimitry Andric
6830b57cec5SDimitry Andric if (auto platform_sp = GetSP())
68404eeddc0SDimitry Andric return SBUnixSignals{platform_sp};
6850b57cec5SDimitry Andric
68604eeddc0SDimitry Andric return SBUnixSignals();
6870b57cec5SDimitry Andric }
6880b57cec5SDimitry Andric
GetEnvironment()6895ffd83dbSDimitry Andric SBEnvironment SBPlatform::GetEnvironment() {
69004eeddc0SDimitry Andric LLDB_INSTRUMENT_VA(this);
6915ffd83dbSDimitry Andric PlatformSP platform_sp(GetSP());
6925ffd83dbSDimitry Andric
6935ffd83dbSDimitry Andric if (platform_sp) {
69404eeddc0SDimitry Andric return SBEnvironment(platform_sp->GetEnvironment());
6955ffd83dbSDimitry Andric }
6965ffd83dbSDimitry Andric
69704eeddc0SDimitry Andric return SBEnvironment();
6985ffd83dbSDimitry Andric }
699fe013be4SDimitry Andric
SetLocateModuleCallback(lldb::SBPlatformLocateModuleCallback callback,void * callback_baton)700fe013be4SDimitry Andric SBError SBPlatform::SetLocateModuleCallback(
701fe013be4SDimitry Andric lldb::SBPlatformLocateModuleCallback callback, void *callback_baton) {
702fe013be4SDimitry Andric LLDB_INSTRUMENT_VA(this, callback, callback_baton);
703fe013be4SDimitry Andric PlatformSP platform_sp(GetSP());
704fe013be4SDimitry Andric if (!platform_sp)
705fe013be4SDimitry Andric return SBError("invalid platform");
706fe013be4SDimitry Andric
707fe013be4SDimitry Andric if (!callback) {
708fe013be4SDimitry Andric // Clear the callback.
709fe013be4SDimitry Andric platform_sp->SetLocateModuleCallback(nullptr);
710fe013be4SDimitry Andric return SBError();
711fe013be4SDimitry Andric }
712fe013be4SDimitry Andric
713fe013be4SDimitry Andric // Platform.h does not accept lldb::SBPlatformLocateModuleCallback directly
714fe013be4SDimitry Andric // because of the SBModuleSpec and SBFileSpec dependencies. Use a lambda to
715fe013be4SDimitry Andric // convert ModuleSpec/FileSpec <--> SBModuleSpec/SBFileSpec for the callback
716fe013be4SDimitry Andric // arguments.
717fe013be4SDimitry Andric platform_sp->SetLocateModuleCallback(
718fe013be4SDimitry Andric [callback, callback_baton](const ModuleSpec &module_spec,
719fe013be4SDimitry Andric FileSpec &module_file_spec,
720fe013be4SDimitry Andric FileSpec &symbol_file_spec) {
721fe013be4SDimitry Andric SBModuleSpec module_spec_sb(module_spec);
722fe013be4SDimitry Andric SBFileSpec module_file_spec_sb;
723fe013be4SDimitry Andric SBFileSpec symbol_file_spec_sb;
724fe013be4SDimitry Andric
725fe013be4SDimitry Andric SBError error = callback(callback_baton, module_spec_sb,
726fe013be4SDimitry Andric module_file_spec_sb, symbol_file_spec_sb);
727fe013be4SDimitry Andric
728fe013be4SDimitry Andric if (error.Success()) {
729fe013be4SDimitry Andric module_file_spec = module_file_spec_sb.ref();
730fe013be4SDimitry Andric symbol_file_spec = symbol_file_spec_sb.ref();
731fe013be4SDimitry Andric }
732fe013be4SDimitry Andric
733fe013be4SDimitry Andric return error.ref();
734fe013be4SDimitry Andric });
735fe013be4SDimitry Andric return SBError();
736fe013be4SDimitry Andric }
737