1 //===-- SBPlatform.h --------------------------------------------*- C++ -*-===//
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 #ifndef LLDB_API_SBPLATFORM_H
10 #define LLDB_API_SBPLATFORM_H
11 
12 #include "lldb/API/SBDefines.h"
13 
14 #include <functional>
15 
16 struct PlatformConnectOptions;
17 struct PlatformShellCommand;
18 
19 namespace lldb {
20 
21 class SBLaunchInfo;
22 
23 class LLDB_API SBPlatformConnectOptions {
24 public:
25   SBPlatformConnectOptions(const char *url);
26 
27   SBPlatformConnectOptions(const SBPlatformConnectOptions &rhs);
28 
29   ~SBPlatformConnectOptions();
30 
31   SBPlatformConnectOptions &operator=(const SBPlatformConnectOptions &rhs);
32 
33   const char *GetURL();
34 
35   void SetURL(const char *url);
36 
37   bool GetRsyncEnabled();
38 
39   void EnableRsync(const char *options, const char *remote_path_prefix,
40                    bool omit_remote_hostname);
41 
42   void DisableRsync();
43 
44   const char *GetLocalCacheDirectory();
45 
46   void SetLocalCacheDirectory(const char *path);
47 
48 protected:
49   PlatformConnectOptions *m_opaque_ptr;
50 };
51 
52 class LLDB_API SBPlatformShellCommand {
53 public:
54   SBPlatformShellCommand(const char *shell_command);
55 
56   SBPlatformShellCommand(const SBPlatformShellCommand &rhs);
57 
58   SBPlatformShellCommand &operator=(const SBPlatformShellCommand &rhs);
59 
60   ~SBPlatformShellCommand();
61 
62   void Clear();
63 
64   const char *GetCommand();
65 
66   void SetCommand(const char *shell_command);
67 
68   const char *GetWorkingDirectory();
69 
70   void SetWorkingDirectory(const char *path);
71 
72   uint32_t GetTimeoutSeconds();
73 
74   void SetTimeoutSeconds(uint32_t sec);
75 
76   int GetSignal();
77 
78   int GetStatus();
79 
80   const char *GetOutput();
81 
82 protected:
83   friend class SBPlatform;
84 
85   PlatformShellCommand *m_opaque_ptr;
86 };
87 
88 class LLDB_API SBPlatform {
89 public:
90   SBPlatform();
91 
92   SBPlatform(const char *platform_name);
93 
94   SBPlatform(const SBPlatform &rhs);
95 
96   SBPlatform &operator=(const SBPlatform &rhs);
97 
98   ~SBPlatform();
99 
100   static SBPlatform GetHostPlatform();
101 
102   explicit operator bool() const;
103 
104   bool IsValid() const;
105 
106   void Clear();
107 
108   const char *GetWorkingDirectory();
109 
110   bool SetWorkingDirectory(const char *path);
111 
112   const char *GetName();
113 
114   SBError ConnectRemote(SBPlatformConnectOptions &connect_options);
115 
116   void DisconnectRemote();
117 
118   bool IsConnected();
119 
120   // The following functions will work if the platform is connected
121   const char *GetTriple();
122 
123   const char *GetHostname();
124 
125   const char *GetOSBuild();
126 
127   const char *GetOSDescription();
128 
129   uint32_t GetOSMajorVersion();
130 
131   uint32_t GetOSMinorVersion();
132 
133   uint32_t GetOSUpdateVersion();
134 
135   SBError Put(SBFileSpec &src, SBFileSpec &dst);
136 
137   SBError Get(SBFileSpec &src, SBFileSpec &dst);
138 
139   SBError Install(SBFileSpec &src, SBFileSpec &dst);
140 
141   SBError Run(SBPlatformShellCommand &shell_command);
142 
143   SBError Launch(SBLaunchInfo &launch_info);
144 
145   SBError Kill(const lldb::pid_t pid);
146 
147   SBError
148   MakeDirectory(const char *path,
149                 uint32_t file_permissions = eFilePermissionsDirectoryDefault);
150 
151   uint32_t GetFilePermissions(const char *path);
152 
153   SBError SetFilePermissions(const char *path, uint32_t file_permissions);
154 
155   SBUnixSignals GetUnixSignals() const;
156 
157   /// Return the environment variables of the remote platform connection
158   /// process.
159   ///
160   /// \return
161   ///     An lldb::SBEnvironment object which is a copy of the platform's
162   ///     environment.
163   SBEnvironment GetEnvironment();
164 
165 protected:
166   friend class SBDebugger;
167   friend class SBTarget;
168 
169   lldb::PlatformSP GetSP() const;
170 
171   void SetSP(const lldb::PlatformSP &platform_sp);
172 
173   SBError ExecuteConnected(
174       const std::function<lldb_private::Status(const lldb::PlatformSP &)>
175           &func);
176 
177   lldb::PlatformSP m_opaque_sp;
178 };
179 
180 } // namespace lldb
181 
182 #endif // LLDB_API_SBPLATFORM_H
183