15ffd83dbSDimitry Andric //===-- SBPlatform.cpp ----------------------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "lldb/API/SBPlatform.h"
10*0b57cec5SDimitry Andric #include "SBReproducerPrivate.h"
115ffd83dbSDimitry Andric #include "lldb/API/SBEnvironment.h"
12*0b57cec5SDimitry Andric #include "lldb/API/SBError.h"
13*0b57cec5SDimitry Andric #include "lldb/API/SBFileSpec.h"
14*0b57cec5SDimitry Andric #include "lldb/API/SBLaunchInfo.h"
155ffd83dbSDimitry Andric #include "lldb/API/SBPlatform.h"
16*0b57cec5SDimitry Andric #include "lldb/API/SBUnixSignals.h"
17*0b57cec5SDimitry Andric #include "lldb/Host/File.h"
18*0b57cec5SDimitry Andric #include "lldb/Target/Platform.h"
19*0b57cec5SDimitry Andric #include "lldb/Target/Target.h"
20*0b57cec5SDimitry Andric #include "lldb/Utility/ArchSpec.h"
21*0b57cec5SDimitry Andric #include "lldb/Utility/Args.h"
22*0b57cec5SDimitry Andric #include "lldb/Utility/Status.h"
23*0b57cec5SDimitry Andric 
24*0b57cec5SDimitry Andric #include "llvm/Support/FileSystem.h"
25*0b57cec5SDimitry Andric 
26*0b57cec5SDimitry Andric #include <functional>
27*0b57cec5SDimitry Andric 
28*0b57cec5SDimitry Andric using namespace lldb;
29*0b57cec5SDimitry Andric using namespace lldb_private;
30*0b57cec5SDimitry Andric 
31*0b57cec5SDimitry Andric // PlatformConnectOptions
32*0b57cec5SDimitry Andric struct PlatformConnectOptions {
33*0b57cec5SDimitry Andric   PlatformConnectOptions(const char *url = nullptr)
34*0b57cec5SDimitry Andric       : m_url(), m_rsync_options(), m_rsync_remote_path_prefix(),
35*0b57cec5SDimitry Andric         m_rsync_enabled(false), m_rsync_omit_hostname_from_remote_path(false),
36*0b57cec5SDimitry Andric         m_local_cache_directory() {
37*0b57cec5SDimitry Andric     if (url && url[0])
38*0b57cec5SDimitry Andric       m_url = url;
39*0b57cec5SDimitry Andric   }
40*0b57cec5SDimitry Andric 
415ffd83dbSDimitry Andric   ~PlatformConnectOptions() = default;
42*0b57cec5SDimitry Andric 
43*0b57cec5SDimitry Andric   std::string m_url;
44*0b57cec5SDimitry Andric   std::string m_rsync_options;
45*0b57cec5SDimitry Andric   std::string m_rsync_remote_path_prefix;
46*0b57cec5SDimitry Andric   bool m_rsync_enabled;
47*0b57cec5SDimitry Andric   bool m_rsync_omit_hostname_from_remote_path;
48*0b57cec5SDimitry Andric   ConstString m_local_cache_directory;
49*0b57cec5SDimitry Andric };
50*0b57cec5SDimitry Andric 
51*0b57cec5SDimitry Andric // PlatformShellCommand
52*0b57cec5SDimitry Andric struct PlatformShellCommand {
53*0b57cec5SDimitry Andric   PlatformShellCommand(const char *shell_command = nullptr)
54*0b57cec5SDimitry Andric       : m_command(), m_working_dir(), m_status(0), m_signo(0) {
55*0b57cec5SDimitry Andric     if (shell_command && shell_command[0])
56*0b57cec5SDimitry Andric       m_command = shell_command;
57*0b57cec5SDimitry Andric   }
58*0b57cec5SDimitry Andric 
595ffd83dbSDimitry Andric   ~PlatformShellCommand() = default;
60*0b57cec5SDimitry Andric 
61*0b57cec5SDimitry Andric   std::string m_command;
62*0b57cec5SDimitry Andric   std::string m_working_dir;
63*0b57cec5SDimitry Andric   std::string m_output;
64*0b57cec5SDimitry Andric   int m_status;
65*0b57cec5SDimitry Andric   int m_signo;
66*0b57cec5SDimitry Andric   Timeout<std::ratio<1>> m_timeout = llvm::None;
67*0b57cec5SDimitry Andric };
68*0b57cec5SDimitry Andric // SBPlatformConnectOptions
69*0b57cec5SDimitry Andric SBPlatformConnectOptions::SBPlatformConnectOptions(const char *url)
70*0b57cec5SDimitry Andric     : m_opaque_ptr(new PlatformConnectOptions(url)) {
71*0b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBPlatformConnectOptions, (const char *), url);
72*0b57cec5SDimitry Andric }
73*0b57cec5SDimitry Andric 
74*0b57cec5SDimitry Andric SBPlatformConnectOptions::SBPlatformConnectOptions(
75*0b57cec5SDimitry Andric     const SBPlatformConnectOptions &rhs)
76*0b57cec5SDimitry Andric     : m_opaque_ptr(new PlatformConnectOptions()) {
77*0b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBPlatformConnectOptions,
78*0b57cec5SDimitry Andric                           (const lldb::SBPlatformConnectOptions &), rhs);
79*0b57cec5SDimitry Andric 
80*0b57cec5SDimitry Andric   *m_opaque_ptr = *rhs.m_opaque_ptr;
81*0b57cec5SDimitry Andric }
82*0b57cec5SDimitry Andric 
83*0b57cec5SDimitry Andric SBPlatformConnectOptions::~SBPlatformConnectOptions() { delete m_opaque_ptr; }
84*0b57cec5SDimitry Andric 
855ffd83dbSDimitry Andric SBPlatformConnectOptions &SBPlatformConnectOptions::
865ffd83dbSDimitry Andric operator=(const SBPlatformConnectOptions &rhs) {
87*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(
885ffd83dbSDimitry Andric       SBPlatformConnectOptions &,
89*0b57cec5SDimitry Andric       SBPlatformConnectOptions, operator=,(
90*0b57cec5SDimitry Andric                                     const lldb::SBPlatformConnectOptions &),
91*0b57cec5SDimitry Andric       rhs);
92*0b57cec5SDimitry Andric 
93*0b57cec5SDimitry Andric   *m_opaque_ptr = *rhs.m_opaque_ptr;
945ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(*this);
95*0b57cec5SDimitry Andric }
96*0b57cec5SDimitry Andric 
97*0b57cec5SDimitry Andric const char *SBPlatformConnectOptions::GetURL() {
98*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformConnectOptions, GetURL);
99*0b57cec5SDimitry Andric 
100*0b57cec5SDimitry Andric   if (m_opaque_ptr->m_url.empty())
101*0b57cec5SDimitry Andric     return nullptr;
102*0b57cec5SDimitry Andric   return m_opaque_ptr->m_url.c_str();
103*0b57cec5SDimitry Andric }
104*0b57cec5SDimitry Andric 
105*0b57cec5SDimitry Andric void SBPlatformConnectOptions::SetURL(const char *url) {
106*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBPlatformConnectOptions, SetURL, (const char *),
107*0b57cec5SDimitry Andric                      url);
108*0b57cec5SDimitry Andric 
109*0b57cec5SDimitry Andric   if (url && url[0])
110*0b57cec5SDimitry Andric     m_opaque_ptr->m_url = url;
111*0b57cec5SDimitry Andric   else
112*0b57cec5SDimitry Andric     m_opaque_ptr->m_url.clear();
113*0b57cec5SDimitry Andric }
114*0b57cec5SDimitry Andric 
115*0b57cec5SDimitry Andric bool SBPlatformConnectOptions::GetRsyncEnabled() {
116*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBPlatformConnectOptions, GetRsyncEnabled);
117*0b57cec5SDimitry Andric 
118*0b57cec5SDimitry Andric   return m_opaque_ptr->m_rsync_enabled;
119*0b57cec5SDimitry Andric }
120*0b57cec5SDimitry Andric 
121*0b57cec5SDimitry Andric void SBPlatformConnectOptions::EnableRsync(
122*0b57cec5SDimitry Andric     const char *options, const char *remote_path_prefix,
123*0b57cec5SDimitry Andric     bool omit_hostname_from_remote_path) {
124*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBPlatformConnectOptions, EnableRsync,
125*0b57cec5SDimitry Andric                      (const char *, const char *, bool), options,
126*0b57cec5SDimitry Andric                      remote_path_prefix, omit_hostname_from_remote_path);
127*0b57cec5SDimitry Andric 
128*0b57cec5SDimitry Andric   m_opaque_ptr->m_rsync_enabled = true;
129*0b57cec5SDimitry Andric   m_opaque_ptr->m_rsync_omit_hostname_from_remote_path =
130*0b57cec5SDimitry Andric       omit_hostname_from_remote_path;
131*0b57cec5SDimitry Andric   if (remote_path_prefix && remote_path_prefix[0])
132*0b57cec5SDimitry Andric     m_opaque_ptr->m_rsync_remote_path_prefix = remote_path_prefix;
133*0b57cec5SDimitry Andric   else
134*0b57cec5SDimitry Andric     m_opaque_ptr->m_rsync_remote_path_prefix.clear();
135*0b57cec5SDimitry Andric 
136*0b57cec5SDimitry Andric   if (options && options[0])
137*0b57cec5SDimitry Andric     m_opaque_ptr->m_rsync_options = options;
138*0b57cec5SDimitry Andric   else
139*0b57cec5SDimitry Andric     m_opaque_ptr->m_rsync_options.clear();
140*0b57cec5SDimitry Andric }
141*0b57cec5SDimitry Andric 
142*0b57cec5SDimitry Andric void SBPlatformConnectOptions::DisableRsync() {
143*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatformConnectOptions, DisableRsync);
144*0b57cec5SDimitry Andric 
145*0b57cec5SDimitry Andric   m_opaque_ptr->m_rsync_enabled = false;
146*0b57cec5SDimitry Andric }
147*0b57cec5SDimitry Andric 
148*0b57cec5SDimitry Andric const char *SBPlatformConnectOptions::GetLocalCacheDirectory() {
149*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformConnectOptions,
150*0b57cec5SDimitry Andric                              GetLocalCacheDirectory);
151*0b57cec5SDimitry Andric 
152*0b57cec5SDimitry Andric   return m_opaque_ptr->m_local_cache_directory.GetCString();
153*0b57cec5SDimitry Andric }
154*0b57cec5SDimitry Andric 
155*0b57cec5SDimitry Andric void SBPlatformConnectOptions::SetLocalCacheDirectory(const char *path) {
156*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBPlatformConnectOptions, SetLocalCacheDirectory,
157*0b57cec5SDimitry Andric                      (const char *), path);
158*0b57cec5SDimitry Andric 
159*0b57cec5SDimitry Andric   if (path && path[0])
160*0b57cec5SDimitry Andric     m_opaque_ptr->m_local_cache_directory.SetCString(path);
161*0b57cec5SDimitry Andric   else
162*0b57cec5SDimitry Andric     m_opaque_ptr->m_local_cache_directory = ConstString();
163*0b57cec5SDimitry Andric }
164*0b57cec5SDimitry Andric 
165*0b57cec5SDimitry Andric // SBPlatformShellCommand
166*0b57cec5SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(const char *shell_command)
167*0b57cec5SDimitry Andric     : m_opaque_ptr(new PlatformShellCommand(shell_command)) {
168*0b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand, (const char *),
169*0b57cec5SDimitry Andric                           shell_command);
170*0b57cec5SDimitry Andric }
171*0b57cec5SDimitry Andric 
172*0b57cec5SDimitry Andric SBPlatformShellCommand::SBPlatformShellCommand(
173*0b57cec5SDimitry Andric     const SBPlatformShellCommand &rhs)
174*0b57cec5SDimitry Andric     : m_opaque_ptr(new PlatformShellCommand()) {
175*0b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBPlatformShellCommand,
176*0b57cec5SDimitry Andric                           (const lldb::SBPlatformShellCommand &), rhs);
177*0b57cec5SDimitry Andric 
178*0b57cec5SDimitry Andric   *m_opaque_ptr = *rhs.m_opaque_ptr;
179*0b57cec5SDimitry Andric }
180*0b57cec5SDimitry Andric 
1815ffd83dbSDimitry Andric SBPlatformShellCommand &SBPlatformShellCommand::
1825ffd83dbSDimitry Andric operator=(const SBPlatformShellCommand &rhs) {
1835ffd83dbSDimitry Andric 
1845ffd83dbSDimitry Andric   LLDB_RECORD_METHOD(
1855ffd83dbSDimitry Andric       SBPlatformShellCommand &,
1865ffd83dbSDimitry Andric       SBPlatformShellCommand, operator=,(const lldb::SBPlatformShellCommand &),
1875ffd83dbSDimitry Andric       rhs);
1885ffd83dbSDimitry Andric 
1895ffd83dbSDimitry Andric   *m_opaque_ptr = *rhs.m_opaque_ptr;
1905ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(*this);
1915ffd83dbSDimitry Andric }
1925ffd83dbSDimitry Andric 
193*0b57cec5SDimitry Andric SBPlatformShellCommand::~SBPlatformShellCommand() { delete m_opaque_ptr; }
194*0b57cec5SDimitry Andric 
195*0b57cec5SDimitry Andric void SBPlatformShellCommand::Clear() {
196*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatformShellCommand, Clear);
197*0b57cec5SDimitry Andric 
198*0b57cec5SDimitry Andric   m_opaque_ptr->m_output = std::string();
199*0b57cec5SDimitry Andric   m_opaque_ptr->m_status = 0;
200*0b57cec5SDimitry Andric   m_opaque_ptr->m_signo = 0;
201*0b57cec5SDimitry Andric }
202*0b57cec5SDimitry Andric 
203*0b57cec5SDimitry Andric const char *SBPlatformShellCommand::GetCommand() {
204*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetCommand);
205*0b57cec5SDimitry Andric 
206*0b57cec5SDimitry Andric   if (m_opaque_ptr->m_command.empty())
207*0b57cec5SDimitry Andric     return nullptr;
208*0b57cec5SDimitry Andric   return m_opaque_ptr->m_command.c_str();
209*0b57cec5SDimitry Andric }
210*0b57cec5SDimitry Andric 
211*0b57cec5SDimitry Andric void SBPlatformShellCommand::SetCommand(const char *shell_command) {
212*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetCommand, (const char *),
213*0b57cec5SDimitry Andric                      shell_command);
214*0b57cec5SDimitry Andric 
215*0b57cec5SDimitry Andric   if (shell_command && shell_command[0])
216*0b57cec5SDimitry Andric     m_opaque_ptr->m_command = shell_command;
217*0b57cec5SDimitry Andric   else
218*0b57cec5SDimitry Andric     m_opaque_ptr->m_command.clear();
219*0b57cec5SDimitry Andric }
220*0b57cec5SDimitry Andric 
221*0b57cec5SDimitry Andric const char *SBPlatformShellCommand::GetWorkingDirectory() {
222*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand,
223*0b57cec5SDimitry Andric                              GetWorkingDirectory);
224*0b57cec5SDimitry Andric 
225*0b57cec5SDimitry Andric   if (m_opaque_ptr->m_working_dir.empty())
226*0b57cec5SDimitry Andric     return nullptr;
227*0b57cec5SDimitry Andric   return m_opaque_ptr->m_working_dir.c_str();
228*0b57cec5SDimitry Andric }
229*0b57cec5SDimitry Andric 
230*0b57cec5SDimitry Andric void SBPlatformShellCommand::SetWorkingDirectory(const char *path) {
231*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetWorkingDirectory,
232*0b57cec5SDimitry Andric                      (const char *), path);
233*0b57cec5SDimitry Andric 
234*0b57cec5SDimitry Andric   if (path && path[0])
235*0b57cec5SDimitry Andric     m_opaque_ptr->m_working_dir = path;
236*0b57cec5SDimitry Andric   else
237*0b57cec5SDimitry Andric     m_opaque_ptr->m_working_dir.clear();
238*0b57cec5SDimitry Andric }
239*0b57cec5SDimitry Andric 
240*0b57cec5SDimitry Andric uint32_t SBPlatformShellCommand::GetTimeoutSeconds() {
241*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatformShellCommand,
242*0b57cec5SDimitry Andric                              GetTimeoutSeconds);
243*0b57cec5SDimitry Andric 
244*0b57cec5SDimitry Andric   if (m_opaque_ptr->m_timeout)
245*0b57cec5SDimitry Andric     return m_opaque_ptr->m_timeout->count();
246*0b57cec5SDimitry Andric   return UINT32_MAX;
247*0b57cec5SDimitry Andric }
248*0b57cec5SDimitry Andric 
249*0b57cec5SDimitry Andric void SBPlatformShellCommand::SetTimeoutSeconds(uint32_t sec) {
250*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(void, SBPlatformShellCommand, SetTimeoutSeconds,
251*0b57cec5SDimitry Andric                      (uint32_t), sec);
252*0b57cec5SDimitry Andric 
253*0b57cec5SDimitry Andric   if (sec == UINT32_MAX)
254*0b57cec5SDimitry Andric     m_opaque_ptr->m_timeout = llvm::None;
255*0b57cec5SDimitry Andric   else
256*0b57cec5SDimitry Andric     m_opaque_ptr->m_timeout = std::chrono::seconds(sec);
257*0b57cec5SDimitry Andric }
258*0b57cec5SDimitry Andric 
259*0b57cec5SDimitry Andric int SBPlatformShellCommand::GetSignal() {
260*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(int, SBPlatformShellCommand, GetSignal);
261*0b57cec5SDimitry Andric 
262*0b57cec5SDimitry Andric   return m_opaque_ptr->m_signo;
263*0b57cec5SDimitry Andric }
264*0b57cec5SDimitry Andric 
265*0b57cec5SDimitry Andric int SBPlatformShellCommand::GetStatus() {
266*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(int, SBPlatformShellCommand, GetStatus);
267*0b57cec5SDimitry Andric 
268*0b57cec5SDimitry Andric   return m_opaque_ptr->m_status;
269*0b57cec5SDimitry Andric }
270*0b57cec5SDimitry Andric 
271*0b57cec5SDimitry Andric const char *SBPlatformShellCommand::GetOutput() {
272*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatformShellCommand, GetOutput);
273*0b57cec5SDimitry Andric 
274*0b57cec5SDimitry Andric   if (m_opaque_ptr->m_output.empty())
275*0b57cec5SDimitry Andric     return nullptr;
276*0b57cec5SDimitry Andric   return m_opaque_ptr->m_output.c_str();
277*0b57cec5SDimitry Andric }
278*0b57cec5SDimitry Andric 
279*0b57cec5SDimitry Andric // SBPlatform
280*0b57cec5SDimitry Andric SBPlatform::SBPlatform() : m_opaque_sp() {
281*0b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBPlatform);
282*0b57cec5SDimitry Andric }
283*0b57cec5SDimitry Andric 
284*0b57cec5SDimitry Andric SBPlatform::SBPlatform(const char *platform_name) : m_opaque_sp() {
285*0b57cec5SDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBPlatform, (const char *), platform_name);
286*0b57cec5SDimitry Andric 
287*0b57cec5SDimitry Andric   Status error;
288*0b57cec5SDimitry Andric   if (platform_name && platform_name[0])
289*0b57cec5SDimitry Andric     m_opaque_sp = Platform::Create(ConstString(platform_name), error);
290*0b57cec5SDimitry Andric }
291*0b57cec5SDimitry Andric 
2925ffd83dbSDimitry Andric SBPlatform::SBPlatform(const SBPlatform &rhs) {
2935ffd83dbSDimitry Andric   LLDB_RECORD_CONSTRUCTOR(SBPlatform, (const lldb::SBPlatform &), rhs);
2945ffd83dbSDimitry Andric 
2955ffd83dbSDimitry Andric   m_opaque_sp = rhs.m_opaque_sp;
2965ffd83dbSDimitry Andric }
2975ffd83dbSDimitry Andric 
2985ffd83dbSDimitry Andric SBPlatform &SBPlatform::operator=(const SBPlatform &rhs) {
2995ffd83dbSDimitry Andric   LLDB_RECORD_METHOD(SBPlatform &,
3005ffd83dbSDimitry Andric                      SBPlatform, operator=,(const lldb::SBPlatform &), rhs);
3015ffd83dbSDimitry Andric 
3025ffd83dbSDimitry Andric   m_opaque_sp = rhs.m_opaque_sp;
3035ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(*this);
3045ffd83dbSDimitry Andric }
3055ffd83dbSDimitry Andric 
3065ffd83dbSDimitry Andric SBPlatform::~SBPlatform() = default;
3075ffd83dbSDimitry Andric 
3085ffd83dbSDimitry Andric SBPlatform SBPlatform::GetHostPlatform() {
3095ffd83dbSDimitry Andric   LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBPlatform, SBPlatform,
3105ffd83dbSDimitry Andric                                     GetHostPlatform);
3115ffd83dbSDimitry Andric 
3125ffd83dbSDimitry Andric   SBPlatform host_platform;
3135ffd83dbSDimitry Andric   host_platform.m_opaque_sp = Platform::GetHostPlatform();
3145ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(host_platform);
3155ffd83dbSDimitry Andric }
316*0b57cec5SDimitry Andric 
317*0b57cec5SDimitry Andric bool SBPlatform::IsValid() const {
318*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBPlatform, IsValid);
319*0b57cec5SDimitry Andric   return this->operator bool();
320*0b57cec5SDimitry Andric }
321*0b57cec5SDimitry Andric SBPlatform::operator bool() const {
322*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBPlatform, operator bool);
323*0b57cec5SDimitry Andric 
324*0b57cec5SDimitry Andric   return m_opaque_sp.get() != nullptr;
325*0b57cec5SDimitry Andric }
326*0b57cec5SDimitry Andric 
327*0b57cec5SDimitry Andric void SBPlatform::Clear() {
328*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatform, Clear);
329*0b57cec5SDimitry Andric 
330*0b57cec5SDimitry Andric   m_opaque_sp.reset();
331*0b57cec5SDimitry Andric }
332*0b57cec5SDimitry Andric 
333*0b57cec5SDimitry Andric const char *SBPlatform::GetName() {
334*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetName);
335*0b57cec5SDimitry Andric 
336*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
337*0b57cec5SDimitry Andric   if (platform_sp)
338*0b57cec5SDimitry Andric     return platform_sp->GetName().GetCString();
339*0b57cec5SDimitry Andric   return nullptr;
340*0b57cec5SDimitry Andric }
341*0b57cec5SDimitry Andric 
342*0b57cec5SDimitry Andric lldb::PlatformSP SBPlatform::GetSP() const { return m_opaque_sp; }
343*0b57cec5SDimitry Andric 
344*0b57cec5SDimitry Andric void SBPlatform::SetSP(const lldb::PlatformSP &platform_sp) {
345*0b57cec5SDimitry Andric   m_opaque_sp = platform_sp;
346*0b57cec5SDimitry Andric }
347*0b57cec5SDimitry Andric 
348*0b57cec5SDimitry Andric const char *SBPlatform::GetWorkingDirectory() {
349*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetWorkingDirectory);
350*0b57cec5SDimitry Andric 
351*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
352*0b57cec5SDimitry Andric   if (platform_sp)
353*0b57cec5SDimitry Andric     return platform_sp->GetWorkingDirectory().GetCString();
354*0b57cec5SDimitry Andric   return nullptr;
355*0b57cec5SDimitry Andric }
356*0b57cec5SDimitry Andric 
357*0b57cec5SDimitry Andric bool SBPlatform::SetWorkingDirectory(const char *path) {
358*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(bool, SBPlatform, SetWorkingDirectory, (const char *),
359*0b57cec5SDimitry Andric                      path);
360*0b57cec5SDimitry Andric 
361*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
362*0b57cec5SDimitry Andric   if (platform_sp) {
363*0b57cec5SDimitry Andric     if (path)
364*0b57cec5SDimitry Andric       platform_sp->SetWorkingDirectory(FileSpec(path));
365*0b57cec5SDimitry Andric     else
366*0b57cec5SDimitry Andric       platform_sp->SetWorkingDirectory(FileSpec());
367*0b57cec5SDimitry Andric     return true;
368*0b57cec5SDimitry Andric   }
369*0b57cec5SDimitry Andric   return false;
370*0b57cec5SDimitry Andric }
371*0b57cec5SDimitry Andric 
372*0b57cec5SDimitry Andric SBError SBPlatform::ConnectRemote(SBPlatformConnectOptions &connect_options) {
373*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, ConnectRemote,
374*0b57cec5SDimitry Andric                      (lldb::SBPlatformConnectOptions &), connect_options);
375*0b57cec5SDimitry Andric 
376*0b57cec5SDimitry Andric   SBError sb_error;
377*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
378*0b57cec5SDimitry Andric   if (platform_sp && connect_options.GetURL()) {
379*0b57cec5SDimitry Andric     Args args;
380*0b57cec5SDimitry Andric     args.AppendArgument(
381*0b57cec5SDimitry Andric         llvm::StringRef::withNullAsEmpty(connect_options.GetURL()));
382*0b57cec5SDimitry Andric     sb_error.ref() = platform_sp->ConnectRemote(args);
383*0b57cec5SDimitry Andric   } else {
384*0b57cec5SDimitry Andric     sb_error.SetErrorString("invalid platform");
385*0b57cec5SDimitry Andric   }
386*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
387*0b57cec5SDimitry Andric }
388*0b57cec5SDimitry Andric 
389*0b57cec5SDimitry Andric void SBPlatform::DisconnectRemote() {
390*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(void, SBPlatform, DisconnectRemote);
391*0b57cec5SDimitry Andric 
392*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
393*0b57cec5SDimitry Andric   if (platform_sp)
394*0b57cec5SDimitry Andric     platform_sp->DisconnectRemote();
395*0b57cec5SDimitry Andric }
396*0b57cec5SDimitry Andric 
397*0b57cec5SDimitry Andric bool SBPlatform::IsConnected() {
398*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(bool, SBPlatform, IsConnected);
399*0b57cec5SDimitry Andric 
400*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
401*0b57cec5SDimitry Andric   if (platform_sp)
402*0b57cec5SDimitry Andric     return platform_sp->IsConnected();
403*0b57cec5SDimitry Andric   return false;
404*0b57cec5SDimitry Andric }
405*0b57cec5SDimitry Andric 
406*0b57cec5SDimitry Andric const char *SBPlatform::GetTriple() {
407*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetTriple);
408*0b57cec5SDimitry Andric 
409*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
410*0b57cec5SDimitry Andric   if (platform_sp) {
411*0b57cec5SDimitry Andric     ArchSpec arch(platform_sp->GetSystemArchitecture());
412*0b57cec5SDimitry Andric     if (arch.IsValid()) {
413*0b57cec5SDimitry Andric       // Const-ify the string so we don't need to worry about the lifetime of
414*0b57cec5SDimitry Andric       // the string
415*0b57cec5SDimitry Andric       return ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
416*0b57cec5SDimitry Andric     }
417*0b57cec5SDimitry Andric   }
418*0b57cec5SDimitry Andric   return nullptr;
419*0b57cec5SDimitry Andric }
420*0b57cec5SDimitry Andric 
421*0b57cec5SDimitry Andric const char *SBPlatform::GetOSBuild() {
422*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetOSBuild);
423*0b57cec5SDimitry Andric 
424*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
425*0b57cec5SDimitry Andric   if (platform_sp) {
426*0b57cec5SDimitry Andric     std::string s;
427*0b57cec5SDimitry Andric     if (platform_sp->GetOSBuildString(s)) {
428*0b57cec5SDimitry Andric       if (!s.empty()) {
429*0b57cec5SDimitry Andric         // Const-ify the string so we don't need to worry about the lifetime of
430*0b57cec5SDimitry Andric         // the string
431*0b57cec5SDimitry Andric         return ConstString(s.c_str()).GetCString();
432*0b57cec5SDimitry Andric       }
433*0b57cec5SDimitry Andric     }
434*0b57cec5SDimitry Andric   }
435*0b57cec5SDimitry Andric   return nullptr;
436*0b57cec5SDimitry Andric }
437*0b57cec5SDimitry Andric 
438*0b57cec5SDimitry Andric const char *SBPlatform::GetOSDescription() {
439*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetOSDescription);
440*0b57cec5SDimitry Andric 
441*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
442*0b57cec5SDimitry Andric   if (platform_sp) {
443*0b57cec5SDimitry Andric     std::string s;
444*0b57cec5SDimitry Andric     if (platform_sp->GetOSKernelDescription(s)) {
445*0b57cec5SDimitry Andric       if (!s.empty()) {
446*0b57cec5SDimitry Andric         // Const-ify the string so we don't need to worry about the lifetime of
447*0b57cec5SDimitry Andric         // the string
448*0b57cec5SDimitry Andric         return ConstString(s.c_str()).GetCString();
449*0b57cec5SDimitry Andric       }
450*0b57cec5SDimitry Andric     }
451*0b57cec5SDimitry Andric   }
452*0b57cec5SDimitry Andric   return nullptr;
453*0b57cec5SDimitry Andric }
454*0b57cec5SDimitry Andric 
455*0b57cec5SDimitry Andric const char *SBPlatform::GetHostname() {
456*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBPlatform, GetHostname);
457*0b57cec5SDimitry Andric 
458*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
459*0b57cec5SDimitry Andric   if (platform_sp)
460*0b57cec5SDimitry Andric     return platform_sp->GetHostname();
461*0b57cec5SDimitry Andric   return nullptr;
462*0b57cec5SDimitry Andric }
463*0b57cec5SDimitry Andric 
464*0b57cec5SDimitry Andric uint32_t SBPlatform::GetOSMajorVersion() {
465*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatform, GetOSMajorVersion);
466*0b57cec5SDimitry Andric 
467*0b57cec5SDimitry Andric   llvm::VersionTuple version;
468*0b57cec5SDimitry Andric   if (PlatformSP platform_sp = GetSP())
469*0b57cec5SDimitry Andric     version = platform_sp->GetOSVersion();
470*0b57cec5SDimitry Andric   return version.empty() ? UINT32_MAX : version.getMajor();
471*0b57cec5SDimitry Andric }
472*0b57cec5SDimitry Andric 
473*0b57cec5SDimitry Andric uint32_t SBPlatform::GetOSMinorVersion() {
474*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatform, GetOSMinorVersion);
475*0b57cec5SDimitry Andric 
476*0b57cec5SDimitry Andric   llvm::VersionTuple version;
477*0b57cec5SDimitry Andric   if (PlatformSP platform_sp = GetSP())
478*0b57cec5SDimitry Andric     version = platform_sp->GetOSVersion();
479*0b57cec5SDimitry Andric   return version.getMinor().getValueOr(UINT32_MAX);
480*0b57cec5SDimitry Andric }
481*0b57cec5SDimitry Andric 
482*0b57cec5SDimitry Andric uint32_t SBPlatform::GetOSUpdateVersion() {
483*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBPlatform, GetOSUpdateVersion);
484*0b57cec5SDimitry Andric 
485*0b57cec5SDimitry Andric   llvm::VersionTuple version;
486*0b57cec5SDimitry Andric   if (PlatformSP platform_sp = GetSP())
487*0b57cec5SDimitry Andric     version = platform_sp->GetOSVersion();
488*0b57cec5SDimitry Andric   return version.getSubminor().getValueOr(UINT32_MAX);
489*0b57cec5SDimitry Andric }
490*0b57cec5SDimitry Andric 
491*0b57cec5SDimitry Andric SBError SBPlatform::Get(SBFileSpec &src, SBFileSpec &dst) {
492*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Get,
493*0b57cec5SDimitry Andric                      (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);
494*0b57cec5SDimitry Andric 
495*0b57cec5SDimitry Andric   SBError sb_error;
496*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
497*0b57cec5SDimitry Andric   if (platform_sp) {
498*0b57cec5SDimitry Andric     sb_error.ref() = platform_sp->GetFile(src.ref(), dst.ref());
499*0b57cec5SDimitry Andric   } else {
500*0b57cec5SDimitry Andric     sb_error.SetErrorString("invalid platform");
501*0b57cec5SDimitry Andric   }
502*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
503*0b57cec5SDimitry Andric }
504*0b57cec5SDimitry Andric 
505*0b57cec5SDimitry Andric SBError SBPlatform::Put(SBFileSpec &src, SBFileSpec &dst) {
506*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Put,
507*0b57cec5SDimitry Andric                      (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);
508*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
509*0b57cec5SDimitry Andric       ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
510*0b57cec5SDimitry Andric         if (src.Exists()) {
511*0b57cec5SDimitry Andric           uint32_t permissions =
512*0b57cec5SDimitry Andric               FileSystem::Instance().GetPermissions(src.ref());
513*0b57cec5SDimitry Andric           if (permissions == 0) {
514*0b57cec5SDimitry Andric             if (FileSystem::Instance().IsDirectory(src.ref()))
515*0b57cec5SDimitry Andric               permissions = eFilePermissionsDirectoryDefault;
516*0b57cec5SDimitry Andric             else
517*0b57cec5SDimitry Andric               permissions = eFilePermissionsFileDefault;
518*0b57cec5SDimitry Andric           }
519*0b57cec5SDimitry Andric 
520*0b57cec5SDimitry Andric           return platform_sp->PutFile(src.ref(), dst.ref(), permissions);
521*0b57cec5SDimitry Andric         }
522*0b57cec5SDimitry Andric 
523*0b57cec5SDimitry Andric         Status error;
524*0b57cec5SDimitry Andric         error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
525*0b57cec5SDimitry Andric                                        src.ref().GetPath().c_str());
526*0b57cec5SDimitry Andric         return error;
527*0b57cec5SDimitry Andric       }));
528*0b57cec5SDimitry Andric }
529*0b57cec5SDimitry Andric 
530*0b57cec5SDimitry Andric SBError SBPlatform::Install(SBFileSpec &src, SBFileSpec &dst) {
531*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Install,
532*0b57cec5SDimitry Andric                      (lldb::SBFileSpec &, lldb::SBFileSpec &), src, dst);
533*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
534*0b57cec5SDimitry Andric       ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
535*0b57cec5SDimitry Andric         if (src.Exists())
536*0b57cec5SDimitry Andric           return platform_sp->Install(src.ref(), dst.ref());
537*0b57cec5SDimitry Andric 
538*0b57cec5SDimitry Andric         Status error;
539*0b57cec5SDimitry Andric         error.SetErrorStringWithFormat("'src' argument doesn't exist: '%s'",
540*0b57cec5SDimitry Andric                                        src.ref().GetPath().c_str());
541*0b57cec5SDimitry Andric         return error;
542*0b57cec5SDimitry Andric       }));
543*0b57cec5SDimitry Andric }
544*0b57cec5SDimitry Andric 
545*0b57cec5SDimitry Andric SBError SBPlatform::Run(SBPlatformShellCommand &shell_command) {
546*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Run,
547*0b57cec5SDimitry Andric                      (lldb::SBPlatformShellCommand &), shell_command);
548*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(ExecuteConnected([&](const lldb::PlatformSP
549*0b57cec5SDimitry Andric                                                      &platform_sp) {
550*0b57cec5SDimitry Andric     const char *command = shell_command.GetCommand();
551*0b57cec5SDimitry Andric     if (!command)
552*0b57cec5SDimitry Andric       return Status("invalid shell command (empty)");
553*0b57cec5SDimitry Andric 
554*0b57cec5SDimitry Andric     const char *working_dir = shell_command.GetWorkingDirectory();
555*0b57cec5SDimitry Andric     if (working_dir == nullptr) {
556*0b57cec5SDimitry Andric       working_dir = platform_sp->GetWorkingDirectory().GetCString();
557*0b57cec5SDimitry Andric       if (working_dir)
558*0b57cec5SDimitry Andric         shell_command.SetWorkingDirectory(working_dir);
559*0b57cec5SDimitry Andric     }
560*0b57cec5SDimitry Andric     return platform_sp->RunShellCommand(command, FileSpec(working_dir),
561*0b57cec5SDimitry Andric                                         &shell_command.m_opaque_ptr->m_status,
562*0b57cec5SDimitry Andric                                         &shell_command.m_opaque_ptr->m_signo,
563*0b57cec5SDimitry Andric                                         &shell_command.m_opaque_ptr->m_output,
564*0b57cec5SDimitry Andric                                         shell_command.m_opaque_ptr->m_timeout);
565*0b57cec5SDimitry Andric   }));
566*0b57cec5SDimitry Andric }
567*0b57cec5SDimitry Andric 
568*0b57cec5SDimitry Andric SBError SBPlatform::Launch(SBLaunchInfo &launch_info) {
569*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Launch, (lldb::SBLaunchInfo &),
570*0b57cec5SDimitry Andric                      launch_info);
571*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
572*0b57cec5SDimitry Andric       ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
573*0b57cec5SDimitry Andric         ProcessLaunchInfo info = launch_info.ref();
574*0b57cec5SDimitry Andric         Status error = platform_sp->LaunchProcess(info);
575*0b57cec5SDimitry Andric         launch_info.set_ref(info);
576*0b57cec5SDimitry Andric         return error;
577*0b57cec5SDimitry Andric       }));
578*0b57cec5SDimitry Andric }
579*0b57cec5SDimitry Andric 
580*0b57cec5SDimitry Andric SBError SBPlatform::Kill(const lldb::pid_t pid) {
581*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, Kill, (const lldb::pid_t), pid);
582*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(
583*0b57cec5SDimitry Andric       ExecuteConnected([&](const lldb::PlatformSP &platform_sp) {
584*0b57cec5SDimitry Andric         return platform_sp->KillProcess(pid);
585*0b57cec5SDimitry Andric       }));
586*0b57cec5SDimitry Andric }
587*0b57cec5SDimitry Andric 
588*0b57cec5SDimitry Andric SBError SBPlatform::ExecuteConnected(
589*0b57cec5SDimitry Andric     const std::function<Status(const lldb::PlatformSP &)> &func) {
590*0b57cec5SDimitry Andric   SBError sb_error;
591*0b57cec5SDimitry Andric   const auto platform_sp(GetSP());
592*0b57cec5SDimitry Andric   if (platform_sp) {
593*0b57cec5SDimitry Andric     if (platform_sp->IsConnected())
594*0b57cec5SDimitry Andric       sb_error.ref() = func(platform_sp);
595*0b57cec5SDimitry Andric     else
596*0b57cec5SDimitry Andric       sb_error.SetErrorString("not connected");
597*0b57cec5SDimitry Andric   } else
598*0b57cec5SDimitry Andric     sb_error.SetErrorString("invalid platform");
599*0b57cec5SDimitry Andric 
600*0b57cec5SDimitry Andric   return sb_error;
601*0b57cec5SDimitry Andric }
602*0b57cec5SDimitry Andric 
603*0b57cec5SDimitry Andric SBError SBPlatform::MakeDirectory(const char *path, uint32_t file_permissions) {
604*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, MakeDirectory,
605*0b57cec5SDimitry Andric                      (const char *, uint32_t), path, file_permissions);
606*0b57cec5SDimitry Andric 
607*0b57cec5SDimitry Andric   SBError sb_error;
608*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
609*0b57cec5SDimitry Andric   if (platform_sp) {
610*0b57cec5SDimitry Andric     sb_error.ref() =
611*0b57cec5SDimitry Andric         platform_sp->MakeDirectory(FileSpec(path), file_permissions);
612*0b57cec5SDimitry Andric   } else {
613*0b57cec5SDimitry Andric     sb_error.SetErrorString("invalid platform");
614*0b57cec5SDimitry Andric   }
615*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
616*0b57cec5SDimitry Andric }
617*0b57cec5SDimitry Andric 
618*0b57cec5SDimitry Andric uint32_t SBPlatform::GetFilePermissions(const char *path) {
619*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(uint32_t, SBPlatform, GetFilePermissions, (const char *),
620*0b57cec5SDimitry Andric                      path);
621*0b57cec5SDimitry Andric 
622*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
623*0b57cec5SDimitry Andric   if (platform_sp) {
624*0b57cec5SDimitry Andric     uint32_t file_permissions = 0;
625*0b57cec5SDimitry Andric     platform_sp->GetFilePermissions(FileSpec(path), file_permissions);
626*0b57cec5SDimitry Andric     return file_permissions;
627*0b57cec5SDimitry Andric   }
628*0b57cec5SDimitry Andric   return 0;
629*0b57cec5SDimitry Andric }
630*0b57cec5SDimitry Andric 
631*0b57cec5SDimitry Andric SBError SBPlatform::SetFilePermissions(const char *path,
632*0b57cec5SDimitry Andric                                        uint32_t file_permissions) {
633*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD(lldb::SBError, SBPlatform, SetFilePermissions,
634*0b57cec5SDimitry Andric                      (const char *, uint32_t), path, file_permissions);
635*0b57cec5SDimitry Andric 
636*0b57cec5SDimitry Andric   SBError sb_error;
637*0b57cec5SDimitry Andric   PlatformSP platform_sp(GetSP());
638*0b57cec5SDimitry Andric   if (platform_sp) {
639*0b57cec5SDimitry Andric     sb_error.ref() =
640*0b57cec5SDimitry Andric         platform_sp->SetFilePermissions(FileSpec(path), file_permissions);
641*0b57cec5SDimitry Andric   } else {
642*0b57cec5SDimitry Andric     sb_error.SetErrorString("invalid platform");
643*0b57cec5SDimitry Andric   }
644*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(sb_error);
645*0b57cec5SDimitry Andric }
646*0b57cec5SDimitry Andric 
647*0b57cec5SDimitry Andric SBUnixSignals SBPlatform::GetUnixSignals() const {
648*0b57cec5SDimitry Andric   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBUnixSignals, SBPlatform,
649*0b57cec5SDimitry Andric                                    GetUnixSignals);
650*0b57cec5SDimitry Andric 
651*0b57cec5SDimitry Andric   if (auto platform_sp = GetSP())
652*0b57cec5SDimitry Andric     return LLDB_RECORD_RESULT(SBUnixSignals{platform_sp});
653*0b57cec5SDimitry Andric 
654*0b57cec5SDimitry Andric   return LLDB_RECORD_RESULT(SBUnixSignals());
655*0b57cec5SDimitry Andric }
656*0b57cec5SDimitry Andric 
6575ffd83dbSDimitry Andric SBEnvironment SBPlatform::GetEnvironment() {
6585ffd83dbSDimitry Andric   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBPlatform, GetEnvironment);
6595ffd83dbSDimitry Andric   PlatformSP platform_sp(GetSP());
6605ffd83dbSDimitry Andric 
6615ffd83dbSDimitry Andric   if (platform_sp) {
6625ffd83dbSDimitry Andric     return LLDB_RECORD_RESULT(SBEnvironment(platform_sp->GetEnvironment()));
6635ffd83dbSDimitry Andric   }
6645ffd83dbSDimitry Andric 
6655ffd83dbSDimitry Andric   return LLDB_RECORD_RESULT(SBEnvironment());
6665ffd83dbSDimitry Andric }
6675ffd83dbSDimitry Andric 
668*0b57cec5SDimitry Andric namespace lldb_private {
669*0b57cec5SDimitry Andric namespace repro {
670*0b57cec5SDimitry Andric 
671*0b57cec5SDimitry Andric template <>
672*0b57cec5SDimitry Andric void RegisterMethods<SBPlatformConnectOptions>(Registry &R) {
673*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBPlatformConnectOptions, (const char *));
674*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBPlatformConnectOptions,
675*0b57cec5SDimitry Andric                             (const lldb::SBPlatformConnectOptions &));
676*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(
6775ffd83dbSDimitry Andric       SBPlatformConnectOptions &,
678*0b57cec5SDimitry Andric       SBPlatformConnectOptions, operator=,(
679*0b57cec5SDimitry Andric                                     const lldb::SBPlatformConnectOptions &));
680*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatformConnectOptions, GetURL, ());
681*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, SetURL,
682*0b57cec5SDimitry Andric                        (const char *));
683*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBPlatformConnectOptions, GetRsyncEnabled, ());
684*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, EnableRsync,
685*0b57cec5SDimitry Andric                        (const char *, const char *, bool));
686*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, DisableRsync, ());
687*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatformConnectOptions,
688*0b57cec5SDimitry Andric                        GetLocalCacheDirectory, ());
689*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatformConnectOptions, SetLocalCacheDirectory,
690*0b57cec5SDimitry Andric                        (const char *));
691*0b57cec5SDimitry Andric }
692*0b57cec5SDimitry Andric 
693*0b57cec5SDimitry Andric template <>
694*0b57cec5SDimitry Andric void RegisterMethods<SBPlatformShellCommand>(Registry &R) {
695*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand, (const char *));
696*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBPlatformShellCommand,
697*0b57cec5SDimitry Andric                             (const lldb::SBPlatformShellCommand &));
6985ffd83dbSDimitry Andric   LLDB_REGISTER_METHOD(
6995ffd83dbSDimitry Andric       SBPlatformShellCommand &,
7005ffd83dbSDimitry Andric       SBPlatformShellCommand, operator=,(const lldb::SBPlatformShellCommand &));
701*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, Clear, ());
702*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetCommand, ());
703*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetCommand,
704*0b57cec5SDimitry Andric                        (const char *));
705*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand,
706*0b57cec5SDimitry Andric                        GetWorkingDirectory, ());
707*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetWorkingDirectory,
708*0b57cec5SDimitry Andric                        (const char *));
709*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBPlatformShellCommand, GetTimeoutSeconds,
710*0b57cec5SDimitry Andric                        ());
711*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatformShellCommand, SetTimeoutSeconds,
712*0b57cec5SDimitry Andric                        (uint32_t));
713*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(int, SBPlatformShellCommand, GetSignal, ());
714*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(int, SBPlatformShellCommand, GetStatus, ());
715*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatformShellCommand, GetOutput, ());
716*0b57cec5SDimitry Andric }
717*0b57cec5SDimitry Andric 
718*0b57cec5SDimitry Andric template <>
719*0b57cec5SDimitry Andric void RegisterMethods<SBPlatform>(Registry &R) {
720*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBPlatform, ());
721*0b57cec5SDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBPlatform, (const char *));
7225ffd83dbSDimitry Andric   LLDB_REGISTER_CONSTRUCTOR(SBPlatform, (const lldb::SBPlatform &));
7235ffd83dbSDimitry Andric   LLDB_REGISTER_METHOD(SBPlatform &,
7245ffd83dbSDimitry Andric                        SBPlatform, operator=,(const lldb::SBPlatform &));
725*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBPlatform, IsValid, ());
726*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(bool, SBPlatform, operator bool, ());
727*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatform, Clear, ());
728*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatform, GetName, ());
729*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatform, GetWorkingDirectory, ());
730*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBPlatform, SetWorkingDirectory, (const char *));
731*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, ConnectRemote,
732*0b57cec5SDimitry Andric                        (lldb::SBPlatformConnectOptions &));
733*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(void, SBPlatform, DisconnectRemote, ());
734*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(bool, SBPlatform, IsConnected, ());
735*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatform, GetTriple, ());
736*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatform, GetOSBuild, ());
737*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatform, GetOSDescription, ());
738*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(const char *, SBPlatform, GetHostname, ());
739*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetOSMajorVersion, ());
740*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetOSMinorVersion, ());
741*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetOSUpdateVersion, ());
742*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Get,
743*0b57cec5SDimitry Andric                        (lldb::SBFileSpec &, lldb::SBFileSpec &));
744*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Put,
745*0b57cec5SDimitry Andric                        (lldb::SBFileSpec &, lldb::SBFileSpec &));
746*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Install,
747*0b57cec5SDimitry Andric                        (lldb::SBFileSpec &, lldb::SBFileSpec &));
748*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Run,
749*0b57cec5SDimitry Andric                        (lldb::SBPlatformShellCommand &));
750*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Launch,
751*0b57cec5SDimitry Andric                        (lldb::SBLaunchInfo &));
752*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, Kill, (const lldb::pid_t));
753*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, MakeDirectory,
754*0b57cec5SDimitry Andric                        (const char *, uint32_t));
755*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(uint32_t, SBPlatform, GetFilePermissions,
756*0b57cec5SDimitry Andric                        (const char *));
757*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBError, SBPlatform, SetFilePermissions,
758*0b57cec5SDimitry Andric                        (const char *, uint32_t));
7595ffd83dbSDimitry Andric   LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBPlatform, GetEnvironment, ());
760*0b57cec5SDimitry Andric   LLDB_REGISTER_METHOD_CONST(lldb::SBUnixSignals, SBPlatform, GetUnixSignals,
761*0b57cec5SDimitry Andric                              ());
7625ffd83dbSDimitry Andric   LLDB_REGISTER_STATIC_METHOD(lldb::SBPlatform, SBPlatform, GetHostPlatform,
7635ffd83dbSDimitry Andric                               ());
764*0b57cec5SDimitry Andric }
765*0b57cec5SDimitry Andric 
766*0b57cec5SDimitry Andric }
767*0b57cec5SDimitry Andric }
768