LLDB  mainline
PlatformRemoteGDBServer.h
Go to the documentation of this file.
1 //===-- PlatformRemoteGDBServer.h ----------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_PlatformRemoteGDBServer_h_
11 #define liblldb_PlatformRemoteGDBServer_h_
12 
13 #include <string>
14 
17 #include "lldb/Target/Platform.h"
18 
19 namespace lldb_private {
20 namespace platform_gdb_server {
21 
23 public:
24  static void Initialize();
25 
26  static void Terminate();
27 
28  static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
29 
31 
32  static const char *GetDescriptionStatic();
33 
35 
36  ~PlatformRemoteGDBServer() override;
37 
38  // lldb_private::PluginInterface functions
40 
41  uint32_t GetPluginVersion() override { return 1; }
42 
43  // lldb_private::Platform functions
44  Status
45  ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
46  const FileSpecList *module_search_paths_ptr) override;
47 
48  bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
49  ModuleSpec &module_spec) override;
50 
51  const char *GetDescription() override;
52 
53  Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr,
54  FileSpec &local_file) override;
55 
56  bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
57 
59  ProcessInstanceInfoList &process_infos) override;
60 
61  Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
62 
63  Status KillProcess(const lldb::pid_t pid) override;
64 
65  lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
66  Debugger &debugger,
67  Target *target, // Can be NULL, if NULL create a
68  // new target, else use existing
69  // one
70  Status &error) override;
71 
72  lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,
73  Target *target, // Can be NULL, if NULL create a new
74  // target, else use existing one
75  Status &error) override;
76 
77  bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
78 
80  BreakpointSite *bp_site) override;
81 
82  bool GetRemoteOSVersion() override;
83 
84  bool GetRemoteOSBuildString(std::string &s) override;
85 
86  bool GetRemoteOSKernelDescription(std::string &s) override;
87 
88  // Remote Platform subclasses need to override this function
90 
92 
93  bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override;
94 
95  // Remote subclasses should override this and return a valid instance
96  // name if connected.
97  const char *GetHostname() override;
98 
99  UserIDResolver &GetUserIDResolver() override { return *this; }
100 
101  bool IsConnected() const override;
102 
103  Status ConnectRemote(Args &args) override;
104 
105  Status DisconnectRemote() override;
106 
107  Status MakeDirectory(const FileSpec &file_spec,
108  uint32_t file_permissions) override;
109 
110  Status GetFilePermissions(const FileSpec &file_spec,
111  uint32_t &file_permissions) override;
112 
113  Status SetFilePermissions(const FileSpec &file_spec,
114  uint32_t file_permissions) override;
115 
116  lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags,
117  uint32_t mode, Status &error) override;
118 
119  bool CloseFile(lldb::user_id_t fd, Status &error) override;
120 
121  uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *data_ptr,
122  uint64_t len, Status &error) override;
123 
124  uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *data,
125  uint64_t len, Status &error) override;
126 
127  lldb::user_id_t GetFileSize(const FileSpec &file_spec) override;
128 
129  Status PutFile(const FileSpec &source, const FileSpec &destination,
130  uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;
131 
132  Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override;
133 
134  bool GetFileExists(const FileSpec &file_spec) override;
135 
136  Status Unlink(const FileSpec &path) override;
137 
139  const char *command, // Shouldn't be NULL
140  const FileSpec &working_dir, // Pass empty FileSpec to use the current
141  // working directory
142  int *status_ptr, // Pass NULL if you don't want the process exit status
143  int *signo_ptr, // Pass NULL if you don't want the signal that caused the
144  // process to exit
145  std::string
146  *command_output, // Pass NULL if you don't want the command output
147  const lldb_private::Timeout<std::micro> &timeout) override;
148 
149  void CalculateTrapHandlerSymbolNames() override;
150 
151  const lldb::UnixSignalsSP &GetRemoteUnixSignals() override;
152 
153  lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url,
154  llvm::StringRef plugin_name,
155  lldb_private::Debugger &debugger,
156  lldb_private::Target *target,
157  lldb_private::Status &error) override;
158 
160  lldb_private::Status &error) override;
161 
162  virtual size_t
163  GetPendingGdbServerList(std::vector<std::string> &connection_urls);
164 
165 protected:
167  std::string m_platform_description; // After we connect we can get a more
168  // complete description of what we are
169  // connected to
170  std::string m_platform_scheme;
171  std::string m_platform_hostname;
172 
173  lldb::UnixSignalsSP m_remote_signals_sp;
174 
175  // Launch the debug server on the remote host - caller connects to launched
176  // debug server using connect_url.
177  // Subclasses should override this method if they want to do extra actions
178  // before or
179  // after launching the debug server.
180  virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url);
181 
182  virtual bool KillSpawnedProcess(lldb::pid_t pid);
183 
184  virtual std::string MakeUrl(const char *scheme, const char *hostname,
185  uint16_t port, const char *path);
186 
187 private:
188  std::string MakeGdbServerUrl(const std::string &platform_scheme,
189  const std::string &platform_hostname,
190  uint16_t port, const char *socket_name);
191 
192  llvm::Optional<std::string> DoGetUserName(UserIDResolver::id_t uid) override;
193  llvm::Optional<std::string> DoGetGroupName(UserIDResolver::id_t uid) override;
194 
195  DISALLOW_COPY_AND_ASSIGN(PlatformRemoteGDBServer);
196 };
197 
198 } // namespace platform_gdb_server
199 } // namespace lldb_private
200 
201 #endif // liblldb_PlatformRemoteGDBServer_h_
A class to manage flag bits.
Definition: Debugger.h:82
Class that manages the actual breakpoint that will be inserted into the running program.
bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override
A command line argument class.
Definition: Args.h:32
Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) override
Status KillProcess(const lldb::pid_t pid) override
Kill process on a platform.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *data_ptr, uint64_t len, Status &error) override
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
lldb::user_id_t GetFileSize(const FileSpec &file_spec) override
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *data, uint64_t len, Status &error) override
A file utility class.
Definition: FileSpec.h:55
An architecture specification class.
Definition: ArchSpec.h:32
bool CloseFile(lldb::user_id_t fd, Status &error) override
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) override
Attach to an existing process by process name.
size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override
virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url)
#define UINT32_MAX
Definition: lldb-defines.h:31
Status LaunchProcess(ProcessLaunchInfo &launch_info) override
Launch a new process on a platform, not necessarily for debugging, it could be just for running the p...
Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
uint64_t user_id_t
Definition: lldb-types.h:84
Status MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) override
Status ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr) override
Find a platform plugin for a given process.
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) override
lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags, uint32_t mode, Status &error) override
Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override
lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, Status &error) override
Attach to an existing process using a process ID.
A plug-in interface definition class for debug platform that includes many platform abilities such as...
Definition: Platform.h:67
lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Status &error) override
Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) override
An abstract interface for things that know how to map numeric user/group IDs into names...
A uniqued constant string class.
Definition: ConstString.h:38
process_gdb_remote::GDBRemoteCommunicationClient m_gdb_client
uint64_t pid_t
Definition: lldb-types.h:85
lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, Target *target, Status &error) override
Subclasses do not need to implement this function as it uses the Platform::LaunchProcess() followed b...
virtual size_t GetPendingGdbServerList(std::vector< std::string > &connection_urls)
Status RunShellCommand(const char *command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const lldb_private::Timeout< std::micro > &timeout) override
virtual std::string MakeUrl(const char *scheme, const char *hostname, uint16_t port, const char *path)
size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger, lldb_private::Status &error) override
Connect to all processes waiting for a debugger to attach.
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override
bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override
Get the platform&#39;s supported architectures in the order in which they should be searched.
Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr, FileSpec &local_file) override
Locate a file for a platform.
An error handling class.
Definition: Status.h:44