1 //===-- PlatformRemoteGDBServer.h ----------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef liblldb_PlatformRemoteGDBServer_h_
12 #define liblldb_PlatformRemoteGDBServer_h_
16 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
17 #include "Plugins/Process/Utility/GDBRemoteSignals.h"
18 #include "lldb/Target/Platform.h"
20 namespace lldb_private {
21 namespace platform_gdb_server {
23 class PlatformRemoteGDBServer : public Platform {
25 static void Initialize();
27 static void Terminate();
29 static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
31 static ConstString GetPluginNameStatic();
33 static const char *GetDescriptionStatic();
35 PlatformRemoteGDBServer();
37 virtual ~PlatformRemoteGDBServer();
39 //------------------------------------------------------------
40 // lldb_private::PluginInterface functions
41 //------------------------------------------------------------
42 ConstString GetPluginName() override { return GetPluginNameStatic(); }
44 uint32_t GetPluginVersion() override { return 1; }
46 //------------------------------------------------------------
47 // lldb_private::Platform functions
48 //------------------------------------------------------------
50 ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
51 const FileSpecList *module_search_paths_ptr) override;
53 bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
54 ModuleSpec &module_spec) override;
56 const char *GetDescription() override;
58 Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr,
59 FileSpec &local_file) override;
61 bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
63 uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
64 ProcessInstanceInfoList &process_infos) override;
66 Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
68 Status KillProcess(const lldb::pid_t pid) override;
70 lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
72 Target *target, // Can be NULL, if NULL create a
73 // new target, else use existing
75 Status &error) override;
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;
82 bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
84 size_t GetSoftwareBreakpointTrapOpcode(Target &target,
85 BreakpointSite *bp_site) override;
87 bool GetRemoteOSVersion() override;
89 bool GetRemoteOSBuildString(std::string &s) override;
91 bool GetRemoteOSKernelDescription(std::string &s) override;
93 // Remote Platform subclasses need to override this function
94 ArchSpec GetRemoteSystemArchitecture() override;
96 FileSpec GetRemoteWorkingDirectory() override;
98 bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override;
100 // Remote subclasses should override this and return a valid instance
101 // name if connected.
102 const char *GetHostname() override;
104 const char *GetUserName(uint32_t uid) override;
106 const char *GetGroupName(uint32_t gid) override;
108 bool IsConnected() const override;
110 Status ConnectRemote(Args &args) override;
112 Status DisconnectRemote() override;
114 Status MakeDirectory(const FileSpec &file_spec,
115 uint32_t file_permissions) override;
117 Status GetFilePermissions(const FileSpec &file_spec,
118 uint32_t &file_permissions) override;
120 Status SetFilePermissions(const FileSpec &file_spec,
121 uint32_t file_permissions) override;
123 lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
124 uint32_t mode, Status &error) override;
126 bool CloseFile(lldb::user_id_t fd, Status &error) override;
128 uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *data_ptr,
129 uint64_t len, Status &error) override;
131 uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *data,
132 uint64_t len, Status &error) override;
134 lldb::user_id_t GetFileSize(const FileSpec &file_spec) override;
136 Status PutFile(const FileSpec &source, const FileSpec &destination,
137 uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;
139 Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override;
141 bool GetFileExists(const FileSpec &file_spec) override;
143 Status Unlink(const FileSpec &path) override;
145 Status RunShellCommand(
146 const char *command, // Shouldn't be NULL
147 const FileSpec &working_dir, // Pass empty FileSpec to use the current
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
153 *command_output, // Pass NULL if you don't want the command output
154 const lldb_private::Timeout<std::micro> &timeout) override;
156 void CalculateTrapHandlerSymbolNames() override;
158 const lldb::UnixSignalsSP &GetRemoteUnixSignals() override;
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;
166 size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger,
167 lldb_private::Status &error) override;
170 GetPendingGdbServerList(std::vector<std::string> &connection_urls);
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
177 std::string m_platform_scheme;
178 std::string m_platform_hostname;
180 lldb::UnixSignalsSP m_remote_signals_sp;
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
186 // after launching the debug server.
187 virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url);
189 virtual bool KillSpawnedProcess(lldb::pid_t pid);
191 virtual std::string MakeUrl(const char *scheme, const char *hostname,
192 uint16_t port, const char *path);
195 std::string MakeGdbServerUrl(const std::string &platform_scheme,
196 const std::string &platform_hostname,
197 uint16_t port, const char *socket_name);
199 DISALLOW_COPY_AND_ASSIGN(PlatformRemoteGDBServer);
202 } // namespace platform_gdb_server
203 } // namespace lldb_private
205 #endif // liblldb_PlatformRemoteGDBServer_h_