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