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 
18 #include "lldb/Target/Platform.h"
19 
20 namespace lldb_private {
21 namespace platform_gdb_server {
22 
24 public:
25  static void Initialize();
26 
27  static void Terminate();
28 
29  static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
30 
32 
33  static const char *GetDescriptionStatic();
34 
36 
37  ~PlatformRemoteGDBServer() override;
38 
39  // lldb_private::PluginInterface functions
41 
42  // lldb_private::Platform functions
43  Status
44  ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
45  const FileSpecList *module_search_paths_ptr) override;
46 
47  bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
48  ModuleSpec &module_spec) override;
49 
50  const char *GetDescription() override;
51 
52  Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr,
53  FileSpec &local_file) override;
54 
55  bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
56 
58  ProcessInstanceInfoList &process_infos) override;
59 
60  Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
61 
62  Status KillProcess(const lldb::pid_t pid) override;
63 
64  lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
65  Debugger &debugger, Target &target,
66  Status &error) override;
67 
68  lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,
69  Target *target, // Can be NULL, if NULL create a new
70  // target, else use existing one
71  Status &error) override;
72 
73  bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
74 
76  BreakpointSite *bp_site) override;
77 
78  bool GetRemoteOSVersion() override;
79 
80  bool GetRemoteOSBuildString(std::string &s) override;
81 
82  bool GetRemoteOSKernelDescription(std::string &s) override;
83 
84  // Remote Platform subclasses need to override this function
86 
88 
89  bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override;
90 
91  // Remote subclasses should override this and return a valid instance
92  // name if connected.
93  const char *GetHostname() override;
94 
95  UserIDResolver &GetUserIDResolver() override { return *this; }
96 
97  bool IsConnected() const override;
98 
99  Status ConnectRemote(Args &args) override;
100 
101  Status DisconnectRemote() override;
102 
103  Status MakeDirectory(const FileSpec &file_spec,
104  uint32_t file_permissions) override;
105 
106  Status GetFilePermissions(const FileSpec &file_spec,
107  uint32_t &file_permissions) override;
108 
109  Status SetFilePermissions(const FileSpec &file_spec,
110  uint32_t file_permissions) override;
111 
112  lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
113  uint32_t mode, Status &error) override;
114 
115  bool CloseFile(lldb::user_id_t fd, Status &error) override;
116 
117  uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *data_ptr,
118  uint64_t len, Status &error) override;
119 
120  uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *data,
121  uint64_t len, Status &error) override;
122 
123  lldb::user_id_t GetFileSize(const FileSpec &file_spec) override;
124 
126  bool only_dir) override;
127 
128  Status PutFile(const FileSpec &source, const FileSpec &destination,
129  uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;
130 
131  Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override;
132 
133  bool GetFileExists(const FileSpec &file_spec) override;
134 
135  Status Unlink(const FileSpec &path) override;
136 
138  llvm::StringRef shell, llvm::StringRef command,
139  const FileSpec &working_dir, // Pass empty FileSpec to use the current
140  // working directory
141  int *status_ptr, // Pass NULL if you don't want the process exit status
142  int *signo_ptr, // Pass NULL if you don't want the signal that caused the
143  // process to exit
145  *command_output, // Pass NULL if you don't want the command output
146  const lldb_private::Timeout<std::micro> &timeout) override;
147 
148  void CalculateTrapHandlerSymbolNames() override;
149 
150  const lldb::UnixSignalsSP &GetRemoteUnixSignals() override;
151 
153  lldb_private::Status &error) override;
154 
155  virtual size_t
156  GetPendingGdbServerList(std::vector<std::string> &connection_urls);
157 
158 protected:
161  std::string m_platform_description; // After we connect we can get a more
162  // complete description of what we are
163  // connected to
166 
167  lldb::UnixSignalsSP m_remote_signals_sp;
168 
169  // Launch the debug server on the remote host - caller connects to launched
170  // debug server using connect_url.
171  // Subclasses should override this method if they want to do extra actions
172  // before or
173  // after launching the debug server.
174  virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url);
175 
176  virtual bool KillSpawnedProcess(lldb::pid_t pid);
177 
178  virtual std::string MakeUrl(const char *scheme, const char *hostname,
179  uint16_t port, const char *path);
180 
181 private:
182  std::string MakeGdbServerUrl(const std::string &platform_scheme,
183  const std::string &platform_hostname,
184  uint16_t port, const char *socket_name);
185 
186  llvm::Optional<std::string> DoGetUserName(UserIDResolver::id_t uid) override;
187  llvm::Optional<std::string> DoGetGroupName(UserIDResolver::id_t uid) override;
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::process_gdb_remote::GDBRemoteCommunicationReplayServer
Dummy GDB server that replays packets from the GDB Remote Communication history.
Definition: GDBRemoteCommunicationReplayServer.h:38
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:108
lldb_private::UUID
Definition: UUID.h:23
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_gdb_client
process_gdb_remote::GDBRemoteCommunicationClient m_gdb_client
Definition: PlatformRemoteGDBServer.h:159
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:601
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:715
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::IsConnected
bool IsConnected() const override
Definition: PlatformRemoteGDBServer.cpp:284
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetHostname
const char * GetHostname() override
Definition: PlatformRemoteGDBServer.cpp:355
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::DoGetGroupName
llvm::Optional< std::string > DoGetGroupName(UserIDResolver::id_t uid) override
Definition: PlatformRemoteGDBServer.cpp:371
lldb_private::process_gdb_remote::GDBRemoteCommunicationClient
Definition: GDBRemoteCommunicationClient.h:58
lldb_private::File::OpenOptions
OpenOptions
Definition: File.h:48
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_platform_description
std::string m_platform_description
Definition: PlatformRemoteGDBServer.h:161
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::Terminate
static void Terminate()
Definition: PlatformRemoteGDBServer.cpp:55
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetFileSize
lldb::user_id_t GetFileSize(const FileSpec &file_spec) override
Definition: PlatformRemoteGDBServer.cpp:648
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::DisconnectRemote
Status DisconnectRemote() override
Definition: PlatformRemoteGDBServer.cpp:348
GDBRemoteCommunicationReplayServer.h
lldb_private::ProcessInstanceInfoMatch
Definition: ProcessInfo.h:163
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_platform_scheme
std::string m_platform_scheme
Definition: PlatformRemoteGDBServer.h:164
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::CloseFile
bool CloseFile(lldb::user_id_t fd, Status &error) override
Definition: PlatformRemoteGDBServer.cpp:643
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::Initialize
static void Initialize()
Definition: PlatformRemoteGDBServer.cpp:43
lldb_private::Args
Definition: Args.h:33
lldb_private::Target
Definition: Target.h:454
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetDescription
const char * GetDescription() override
Definition: PlatformRemoteGDBServer.cpp:85
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:669
Platform.h
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteOSBuildString
bool GetRemoteOSBuildString(std::string &s) override
Definition: PlatformRemoteGDBServer.cpp:244
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:697
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetPendingGdbServerList
virtual size_t GetPendingGdbServerList(std::vector< std::string > &connection_urls)
Definition: PlatformRemoteGDBServer.cpp:841
lldb_private::BreakpointSite
Definition: BreakpointSite.h:35
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
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:257
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::SetFilePermissions
Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) override
Definition: PlatformRemoteGDBServer.cpp:624
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::LaunchGDBServer
virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url)
Definition: PlatformRemoteGDBServer.cpp:516
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::KillSpawnedProcess
virtual bool KillSpawnedProcess(lldb::pid_t pid)
Definition: PlatformRemoteGDBServer.cpp:546
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteOSVersion
bool GetRemoteOSVersion() override
Definition: PlatformRemoteGDBServer.cpp:239
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::AutoCompleteDiskFileOrDirectory
void AutoCompleteDiskFileOrDirectory(CompletionRequest &request, bool only_dir) override
Definition: PlatformRemoteGDBServer.cpp:652
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetDescriptionStatic
static const char * GetDescriptionStatic()
Definition: PlatformRemoteGDBServer.cpp:80
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetProcessInfo
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override
Definition: PlatformRemoteGDBServer.cpp:384
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteSystemArchitecture
ArchSpec GetRemoteSystemArchitecture() override
Definition: PlatformRemoteGDBServer.cpp:253
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::CreateSymlink
Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override
Definition: PlatformRemoteGDBServer.cpp:675
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetSoftwareBreakpointTrapOpcode
size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override
Definition: PlatformRemoteGDBServer.cpp:232
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::SetRemoteWorkingDirectory
bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override
Definition: PlatformRemoteGDBServer.cpp:271
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::ConnectRemote
Status ConnectRemote(Args &args) override
Definition: PlatformRemoteGDBServer.cpp:288
lldb_private::Debugger
Definition: Debugger.h:70
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::~PlatformRemoteGDBServer
~PlatformRemoteGDBServer() override
Destructor.
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteOSKernelDescription
bool GetRemoteOSKernelDescription(std::string &s) override
Definition: PlatformRemoteGDBServer.cpp:248
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:378
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::CreateInstance
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
Definition: PlatformRemoteGDBServer.cpp:64
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:636
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetPluginNameStatic
static ConstString GetPluginNameStatic()
Definition: PlatformRemoteGDBServer.cpp:75
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::Unlink
Status Unlink(const FileSpec &path) override
Definition: PlatformRemoteGDBServer.cpp:689
lldb_private::ProcessAttachInfo
Definition: Process.h:115
lldb_private::UserIDResolver
An abstract interface for things that know how to map numeric user/group IDs into names.
Definition: UserIDResolver.h:22
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:663
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_platform_hostname
std::string m_platform_hostname
Definition: PlatformRemoteGDBServer.h:165
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetUserIDResolver
UserIDResolver & GetUserIDResolver() override
Definition: PlatformRemoteGDBServer.h:95
lldb_private::ModuleSpec
Definition: ModuleSpec.h:26
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:701
uint32_t
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetPluginName
ConstString GetPluginName() override
Definition: PlatformRemoteGDBServer.h:40
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::ResolveExecutable
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.
Definition: PlatformRemoteGDBServer.cpp:97
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:195
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::m_gdb_replay_server
process_gdb_remote::GDBRemoteCommunicationReplayServer m_gdb_replay_server
Definition: PlatformRemoteGDBServer.h:160
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
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:472
uint16_t
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetRemoteUnixSignals
const lldb::UnixSignalsSP & GetRemoteUnixSignals() override
Definition: PlatformRemoteGDBServer.cpp:719
lldb_private::Platform
Definition: Platform.h:72
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:799
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:828
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:612
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:23
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:389
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::PlatformRemoteGDBServer
PlatformRemoteGDBServer()
Default Constructor.
Definition: PlatformRemoteGDBServer.cpp:204
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:479
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:816
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::DoGetUserName
llvm::Optional< std::string > DoGetUserName(UserIDResolver::id_t uid) override
Definition: PlatformRemoteGDBServer.cpp:363
lldb_private::ProcessInstanceInfoList
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition: Host.h:30
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:657
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:550
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:167
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetModuleSpec
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) override
Definition: PlatformRemoteGDBServer.cpp:167
lldb_private::platform_gdb_server::PlatformRemoteGDBServer::GetSupportedArchitectureAtIndex
bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override
Get the platform's supported architectures in the order in which they should be searched.
Definition: PlatformRemoteGDBServer.cpp:217