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