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 LLDB_SOURCE_PLUGINS_PLATFORM_GDB_SERVER_PLATFORMREMOTEGDBSERVER_H
11 #define LLDB_SOURCE_PLUGINS_PLATFORM_GDB_SERVER_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 
30  static llvm::StringRef GetPluginNameStatic() { return "remote-gdb-server"; }
31 
32  static llvm::StringRef GetDescriptionStatic();
33 
35 
36  ~PlatformRemoteGDBServer() override;
37 
38  // lldb_private::PluginInterface functions
39  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
40 
41  // lldb_private::Platform functions
42  bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
43  ModuleSpec &module_spec) override;
44 
45  llvm::StringRef GetDescription() override;
46 
47  Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr,
48  FileSpec &local_file) override;
49 
50  bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
51 
53  ProcessInstanceInfoList &process_infos) override;
54 
55  Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
56 
57  Status KillProcess(const lldb::pid_t pid) override;
58 
59  lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
60  Debugger &debugger, Target &target,
61  Status &error) override;
62 
63  lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,
64  Target *target, // Can be NULL, if NULL create a new
65  // target, else use existing one
66  Status &error) override;
67 
68  std::vector<ArchSpec>
69  GetSupportedArchitectures(const ArchSpec &process_host_arch) override {
71  }
72 
74  BreakpointSite *bp_site) override;
75 
76  bool GetRemoteOSVersion() override;
77 
78  llvm::Optional<std::string> GetRemoteOSBuildString() override;
79 
80  llvm::Optional<std::string> GetRemoteOSKernelDescription() override;
81 
82  // Remote Platform subclasses need to override this function
84 
86 
87  bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override;
88 
89  // Remote subclasses should override this and return a valid instance
90  // name if connected.
91  const char *GetHostname() override;
92 
93  UserIDResolver &GetUserIDResolver() override { return *this; }
94 
95  bool IsConnected() const override;
96 
97  Status ConnectRemote(Args &args) override;
98 
99  Status DisconnectRemote() override;
100 
101  Status MakeDirectory(const FileSpec &file_spec,
102  uint32_t file_permissions) override;
103 
104  Status GetFilePermissions(const FileSpec &file_spec,
105  uint32_t &file_permissions) override;
106 
107  Status SetFilePermissions(const FileSpec &file_spec,
108  uint32_t file_permissions) override;
109 
110  lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
111  uint32_t mode, Status &error) override;
112 
113  bool CloseFile(lldb::user_id_t fd, Status &error) override;
114 
115  uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *data_ptr,
116  uint64_t len, Status &error) override;
117 
118  uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *data,
119  uint64_t len, Status &error) override;
120 
121  lldb::user_id_t GetFileSize(const FileSpec &file_spec) override;
122 
124  bool only_dir) override;
125 
126  Status PutFile(const FileSpec &source, const FileSpec &destination,
127  uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;
128 
129  Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override;
130 
131  bool GetFileExists(const FileSpec &file_spec) override;
132 
133  Status Unlink(const FileSpec &path) override;
134 
136  llvm::StringRef shell, llvm::StringRef command,
137  const FileSpec &working_dir, // Pass empty FileSpec to use the current
138  // working directory
139  int *status_ptr, // Pass NULL if you don't want the process exit status
140  int *signo_ptr, // Pass NULL if you don't want the signal that caused the
141  // process to exit
143  *command_output, // Pass NULL if you don't want the command output
144  const lldb_private::Timeout<std::micro> &timeout) override;
145 
146  void CalculateTrapHandlerSymbolNames() override;
147 
148  const lldb::UnixSignalsSP &GetRemoteUnixSignals() override;
149 
151  lldb_private::Status &error) override;
152 
153  virtual size_t
154  GetPendingGdbServerList(std::vector<std::string> &connection_urls);
155 
156 protected:
157  std::unique_ptr<process_gdb_remote::GDBRemoteCommunicationClient>
159  std::string m_platform_description; // After we connect we can get a more
160  // complete description of what we are
161  // connected to
164 
165  lldb::UnixSignalsSP m_remote_signals_sp;
166 
167  // Launch the debug server on the remote host - caller connects to launched
168  // debug server using connect_url.
169  // Subclasses should override this method if they want to do extra actions
170  // before or
171  // after launching the debug server.
172  virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url);
173 
174  virtual bool KillSpawnedProcess(lldb::pid_t pid);
175 
176  virtual std::string MakeUrl(const char *scheme, const char *hostname,
177  uint16_t port, const char *path);
178 
179 private:
180  std::string MakeGdbServerUrl(const std::string &platform_scheme,
181  const std::string &platform_hostname,
182  uint16_t port, const char *socket_name);
183 
184  llvm::Optional<std::string> DoGetUserName(UserIDResolver::id_t uid) override;
185  llvm::Optional<std::string> DoGetGroupName(UserIDResolver::id_t uid) override;
186 
187  std::vector<ArchSpec> m_supported_architectures;
188 
191  operator=(const PlatformRemoteGDBServer &) = delete;
192 };
193 
194 } // namespace platform_gdb_server
195 } // namespace lldb_private
196 
197 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_GDB_SERVER_PLATFORMREMOTEGDBSERVER_H
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetDescription
llvm::StringRef GetDescription() override
Definition: PlatformRemoteGDBServer.cpp:81
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:108
lldb_private::UUID
Definition: UUID.h:23
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_supported_architectures
std::vector< ArchSpec > m_supported_architectures
Definition: PlatformRemoteGDBServer.h:187
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::MakeDirectory
Status MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) override
Definition: PlatformRemoteGDBServer.cpp:540
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
Definition: PlatformRemoteGDBServer.cpp:684
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::IsConnected
bool IsConnected() const override
Definition: PlatformRemoteGDBServer.cpp:200
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetHostname
const char * GetHostname() override
Definition: PlatformRemoteGDBServer.cpp:282
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::DoGetGroupName
llvm::Optional< std::string > DoGetGroupName(UserIDResolver::id_t uid) override
Definition: PlatformRemoteGDBServer.cpp:299
lldb_private::File::OpenOptions
OpenOptions
Definition: File.h:49
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_platform_description
std::string m_platform_description
Definition: PlatformRemoteGDBServer.h:159
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::Terminate
static void Terminate()
Definition: PlatformRemoteGDBServer.cpp:56
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetFileSize
lldb::user_id_t GetFileSize(const FileSpec &file_spec) override
Definition: PlatformRemoteGDBServer.cpp:600
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::DisconnectRemote
Status DisconnectRemote() override
Definition: PlatformRemoteGDBServer.cpp:275
lldb_private::ProcessInstanceInfoMatch
Definition: ProcessInfo.h:163
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_platform_scheme
std::string m_platform_scheme
Definition: PlatformRemoteGDBServer.h:162
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::CloseFile
bool CloseFile(lldb::user_id_t fd, Status &error) override
Definition: PlatformRemoteGDBServer.cpp:592
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::Initialize
static void Initialize()
Definition: PlatformRemoteGDBServer.cpp:44
lldb_private::Args
Definition: Args.h:33
lldb_private::Target
Definition: Target.h:467
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_gdb_client_up
std::unique_ptr< process_gdb_remote::GDBRemoteCommunicationClient > m_gdb_client_up
Definition: PlatformRemoteGDBServer.h:158
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::PutFile
Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
Definition: PlatformRemoteGDBServer.cpp:630
Platform.h
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetFileExists
bool GetFileExists(const FileSpec &file_spec) override
Definition: PlatformRemoteGDBServer.cpp:662
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetPendingGdbServerList
virtual size_t GetPendingGdbServerList(std::vector< std::string > &connection_urls)
Definition: PlatformRemoteGDBServer.cpp:810
lldb_private::BreakpointSite
Definition: BreakpointSite.h:35
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetSupportedArchitectures
std::vector< ArchSpec > GetSupportedArchitectures(const ArchSpec &process_host_arch) override
Get the platform's supported architectures in the order in which they should be searched.
Definition: PlatformRemoteGDBServer.h:69
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::operator=
const PlatformRemoteGDBServer & operator=(const PlatformRemoteGDBServer &)=delete
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteWorkingDirectory
FileSpec GetRemoteWorkingDirectory() override
Definition: PlatformRemoteGDBServer.cpp:173
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::SetFilePermissions
Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) override
Definition: PlatformRemoteGDBServer.cpp:568
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::LaunchGDBServer
virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url)
Definition: PlatformRemoteGDBServer.cpp:452
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::KillSpawnedProcess
virtual bool KillSpawnedProcess(lldb::pid_t pid)
Definition: PlatformRemoteGDBServer.cpp:484
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteOSVersion
bool GetRemoteOSVersion() override
Definition: PlatformRemoteGDBServer.cpp:147
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::AutoCompleteDiskFileOrDirectory
void AutoCompleteDiskFileOrDirectory(CompletionRequest &request, bool only_dir) override
Definition: PlatformRemoteGDBServer.cpp:606
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetProcessInfo
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override
Definition: PlatformRemoteGDBServer.cpp:314
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteSystemArchitecture
ArchSpec GetRemoteSystemArchitecture() override
Definition: PlatformRemoteGDBServer.cpp:167
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::CreateSymlink
Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override
Definition: PlatformRemoteGDBServer.cpp:636
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteOSKernelDescription
llvm::Optional< std::string > GetRemoteOSKernelDescription() override
Definition: PlatformRemoteGDBServer.cpp:160
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetSoftwareBreakpointTrapOpcode
size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override
Definition: PlatformRemoteGDBServer.cpp:140
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::SetRemoteWorkingDirectory
bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override
Definition: PlatformRemoteGDBServer.cpp:187
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::ConnectRemote
Status ConnectRemote(Args &args) override
Definition: PlatformRemoteGDBServer.cpp:208
lldb_private::Debugger
Definition: Debugger.h:74
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteOSBuildString
llvm::Optional< std::string > GetRemoteOSBuildString() override
Definition: PlatformRemoteGDBServer.cpp:153
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::~PlatformRemoteGDBServer
~PlatformRemoteGDBServer() override
Destructor.
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::FindProcesses
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) override
Attach to an existing process by process name.
Definition: PlatformRemoteGDBServer.cpp:306
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::CreateInstance
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
Definition: PlatformRemoteGDBServer.cpp:65
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::OpenFile
lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error) override
Definition: PlatformRemoteGDBServer.cpp:583
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::Unlink
Status Unlink(const FileSpec &path) override
Definition: PlatformRemoteGDBServer.cpp:652
lldb_private::ProcessAttachInfo
Definition: Process.h:113
lldb_private::UserIDResolver
An abstract interface for things that know how to map numeric user/group IDs into names.
Definition: UserIDResolver.h:23
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::WriteFile
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *data, uint64_t len, Status &error) override
Definition: PlatformRemoteGDBServer.cpp:621
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_platform_hostname
std::string m_platform_hostname
Definition: PlatformRemoteGDBServer.h:163
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetUserIDResolver
UserIDResolver & GetUserIDResolver() override
Definition: PlatformRemoteGDBServer.h:93
lldb_private::ModuleSpec
Definition: ModuleSpec.h:27
lldb_private::Status
Definition: Status.h:44
lldb_private::Timeout< std::micro >
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::RunShellCommand
Status RunShellCommand(llvm::StringRef shell, llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const lldb_private::Timeout< std::micro > &timeout) override
Definition: PlatformRemoteGDBServer.cpp:668
uint32_t
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetFileWithUUID
Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr, FileSpec &local_file) override
Locate a file for a platform.
Definition: PlatformRemoteGDBServer.cpp:122
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetDescriptionStatic
static llvm::StringRef GetDescriptionStatic()
Definition: PlatformRemoteGDBServer.cpp:76
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:19
GDBRemoteSignals.h
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::KillProcess
Status KillProcess(const lldb::pid_t pid) override
Kill process on a platform.
Definition: PlatformRemoteGDBServer.cpp:406
uint16_t
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteUnixSignals
const lldb::UnixSignalsSP & GetRemoteUnixSignals() override
Definition: PlatformRemoteGDBServer.cpp:688
lldb_private::Platform
Definition: Platform.h:71
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::MakeGdbServerUrl
std::string MakeGdbServerUrl(const std::string &platform_scheme, const std::string &platform_hostname, uint16_t port, const char *socket_name)
Definition: PlatformRemoteGDBServer.cpp:768
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::ConnectToWaitingProcesses
size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger, lldb_private::Status &error) override
Connect to all processes waiting for a debugger to attach.
Definition: PlatformRemoteGDBServer.cpp:797
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetFilePermissions
Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) override
Definition: PlatformRemoteGDBServer.cpp:553
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::platform_gdb_server::PlatformRemoteGDBServer
Definition: PlatformRemoteGDBServer.h:22
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: PlatformRemoteGDBServer.h:30
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::LaunchProcess
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...
Definition: PlatformRemoteGDBServer.cpp:321
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::PlatformRemoteGDBServer
PlatformRemoteGDBServer()
Default Constructor.
Definition: PlatformRemoteGDBServer.cpp:131
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::DebugProcess
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...
Definition: PlatformRemoteGDBServer.cpp:413
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::MakeUrl
virtual std::string MakeUrl(const char *scheme, const char *hostname, uint16_t port, const char *path)
Definition: PlatformRemoteGDBServer.cpp:785
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::DoGetUserName
llvm::Optional< std::string > DoGetUserName(UserIDResolver::id_t uid) override
Definition: PlatformRemoteGDBServer.cpp:291
lldb_private::ProcessInstanceInfoList
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition: Host.h:31
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::ReadFile
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *data_ptr, uint64_t len, Status &error) override
Definition: PlatformRemoteGDBServer.cpp:612
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::Attach
lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, Status &error) override
Attach to an existing process using a process ID.
Definition: PlatformRemoteGDBServer.cpp:489
GDBRemoteCommunicationClient.h
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_remote_signals_sp
lldb::UnixSignalsSP m_remote_signals_sp
Definition: PlatformRemoteGDBServer.h:165
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetPluginName
llvm::StringRef GetPluginName() override
Definition: PlatformRemoteGDBServer.h:39
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetModuleSpec
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) override
Definition: PlatformRemoteGDBServer.cpp:93