1 //===-- PlatformRemoteGDBServer.h ----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_PlatformRemoteGDBServer_h_
11 #define liblldb_PlatformRemoteGDBServer_h_
12 
13 // C Includes
14 // C++ Includes
15 #include <string>
16 
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/Target/Platform.h"
20 #include "../../Process/gdb-remote/GDBRemoteCommunicationClient.h"
21 #include "Plugins/Process/Utility/GDBRemoteSignals.h"
22 
23 namespace lldb_private {
24 namespace platform_gdb_server {
25 
26 class PlatformRemoteGDBServer : public Platform
27 {
28 public:
29 
30     static void
31     Initialize ();
32 
33     static void
34     Terminate ();
35 
36     static lldb::PlatformSP
37     CreateInstance (bool force, const ArchSpec *arch);
38 
39     static ConstString
40     GetPluginNameStatic();
41 
42     static const char *
43     GetDescriptionStatic();
44 
45 
46     PlatformRemoteGDBServer ();
47 
48     virtual
49     ~PlatformRemoteGDBServer();
50 
51     //------------------------------------------------------------
52     // lldb_private::PluginInterface functions
53     //------------------------------------------------------------
54     ConstString
55     GetPluginName() override
56     {
57         return GetPluginNameStatic();
58     }
59 
60     uint32_t
61     GetPluginVersion() override
62     {
63         return 1;
64     }
65 
66 
67     //------------------------------------------------------------
68     // lldb_private::Platform functions
69     //------------------------------------------------------------
70     Error
71     ResolveExecutable (const ModuleSpec &module_spec,
72                        lldb::ModuleSP &module_sp,
73                        const FileSpecList *module_search_paths_ptr) override;
74 
75     bool
76     GetModuleSpec (const FileSpec& module_file_spec,
77                    const ArchSpec& arch,
78                    ModuleSpec &module_spec) override;
79 
80     const char *
81     GetDescription () override;
82 
83     Error
84     GetFileWithUUID (const FileSpec &platform_file,
85                      const UUID *uuid_ptr,
86                      FileSpec &local_file) override;
87 
88     bool
89     GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
90 
91     uint32_t
92     FindProcesses (const ProcessInstanceInfoMatch &match_info,
93                    ProcessInstanceInfoList &process_infos) override;
94 
95     Error
96     LaunchProcess (ProcessLaunchInfo &launch_info) override;
97 
98     Error
99     KillProcess (const lldb::pid_t pid) override;
100 
101     lldb::ProcessSP
102     DebugProcess (ProcessLaunchInfo &launch_info,
103                   Debugger &debugger,
104                   Target *target,       // Can be NULL, if NULL create a new target, else use existing one
105                   Error &error) override;
106 
107     lldb::ProcessSP
108     Attach (ProcessAttachInfo &attach_info,
109             Debugger &debugger,
110             Target *target,       // Can be NULL, if NULL create a new target, else use existing one
111             Error &error) override;
112 
113     bool
114     GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch) override;
115 
116     size_t
117     GetSoftwareBreakpointTrapOpcode (Target &target, BreakpointSite *bp_site) override;
118 
119     bool
120     GetRemoteOSVersion () override;
121 
122     bool
123     GetRemoteOSBuildString (std::string &s) override;
124 
125     bool
126     GetRemoteOSKernelDescription (std::string &s) override;
127 
128     // Remote Platform subclasses need to override this function
129     ArchSpec
130     GetRemoteSystemArchitecture () override;
131 
132     FileSpec
133     GetRemoteWorkingDirectory() override;
134 
135     bool
136     SetRemoteWorkingDirectory(const FileSpec &working_dir) override;
137 
138     // Remote subclasses should override this and return a valid instance
139     // name if connected.
140     const char *
141     GetHostname () override;
142 
143     const char *
144     GetUserName (uint32_t uid) override;
145 
146     const char *
147     GetGroupName (uint32_t gid) override;
148 
149     bool
150     IsConnected () const override;
151 
152     Error
153     ConnectRemote (Args& args) override;
154 
155     Error
156     DisconnectRemote () override;
157 
158     Error
159     MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) override;
160 
161     Error
162     GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) override;
163 
164     Error
165     SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) override;
166 
167 
168     lldb::user_id_t
169     OpenFile (const FileSpec& file_spec, uint32_t flags, uint32_t mode, Error &error) override;
170 
171     bool
172     CloseFile (lldb::user_id_t fd, Error &error) override;
173 
174     uint64_t
175     ReadFile (lldb::user_id_t fd,
176               uint64_t offset,
177               void *data_ptr,
178               uint64_t len,
179               Error &error) override;
180 
181     uint64_t
182     WriteFile (lldb::user_id_t fd,
183                uint64_t offset,
184                const void* data,
185                uint64_t len,
186                Error &error) override;
187 
188     lldb::user_id_t
189     GetFileSize (const FileSpec& file_spec) override;
190 
191     Error
192     PutFile (const FileSpec& source,
193              const FileSpec& destination,
194              uint32_t uid = UINT32_MAX,
195              uint32_t gid = UINT32_MAX) override;
196 
197     Error
198     CreateSymlink(const FileSpec &src, const FileSpec &dst) override;
199 
200     bool
201     GetFileExists (const FileSpec& file_spec) override;
202 
203     Error
204     Unlink(const FileSpec &path) override;
205 
206     Error
207     RunShellCommand(const char *command,            // Shouldn't be NULL
208                     const FileSpec &working_dir,    // Pass empty FileSpec to use the current working directory
209                     int *status_ptr,                // Pass NULL if you don't want the process exit status
210                     int *signo_ptr,                 // Pass NULL if you don't want the signal that caused the process to exit
211                     std::string *command_output,    // Pass NULL if you don't want the command output
212                     uint32_t timeout_sec) override; // Timeout in seconds to wait for shell program to finish
213 
214     void
215     CalculateTrapHandlerSymbolNames () override;
216 
217     const lldb::UnixSignalsSP &
218     GetRemoteUnixSignals() override;
219 
220     lldb::ProcessSP
221     ConnectProcess (const char* connect_url,
222                     const char* plugin_name,
223                     lldb_private::Debugger &debugger,
224                     lldb_private::Target *target,
225                     lldb_private::Error &error) override;
226 
227     virtual size_t
228     GetPendingGdbServerList(std::vector<std::string>& connection_urls);
229 
230 protected:
231     process_gdb_remote::GDBRemoteCommunicationClient m_gdb_client;
232     std::string m_platform_description; // After we connect we can get a more complete description of what we are connected to
233     std::string m_platform_scheme;
234     std::string m_platform_hostname;
235 
236     lldb::UnixSignalsSP m_remote_signals_sp;
237 
238     // Launch the debug server on the remote host - caller connects to launched
239     // debug server using connect_url.
240     // Subclasses should override this method if they want to do extra actions before or
241     // after launching the debug server.
242     virtual bool
243     LaunchGDBServer (lldb::pid_t &pid, std::string &connect_url);
244 
245     virtual bool
246     KillSpawnedProcess (lldb::pid_t pid);
247 
248     virtual std::string
249     MakeUrl(const char* scheme,
250             const char* hostname,
251             uint16_t port,
252             const char* path);
253 
254 private:
255     std::string
256     MakeGdbServerUrl(const std::string &platform_scheme,
257                      const std::string &platform_hostname,
258                      uint16_t port,
259                      const char* socket_name);
260 
261     DISALLOW_COPY_AND_ASSIGN (PlatformRemoteGDBServer);
262 
263 };
264 
265 } // namespace platform_gdb_server
266 } // namespace lldb_private
267 
268 #endif  // liblldb_PlatformRemoteGDBServer_h_
269