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 <optional>
14#include <string>
15
19
20namespace lldb_private {
21namespace platform_gdb_server {
22
24public:
25 static void Initialize();
26
27 static void Terminate();
28
29 static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
30
31 static llvm::StringRef GetPluginNameStatic() { return "remote-gdb-server"; }
32
33 static llvm::StringRef GetDescriptionStatic();
34
36
38
39 // lldb_private::PluginInterface functions
40 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
41
42 // lldb_private::Platform functions
43 bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
44 ModuleSpec &module_spec) override;
45
46 llvm::StringRef GetDescription() override;
47
48 Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr,
49 FileSpec &local_file) override;
50
51 bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
52
53 uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
54 ProcessInstanceInfoList &process_infos) override;
55
56 Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
57
58 Status KillProcess(const lldb::pid_t pid) override;
59
61 Debugger &debugger, Target &target,
62 Status &error) override;
63
64 lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger,
65 Target *target, // Can be NULL, if NULL create a new
66 // target, else use existing one
67 Status &error) override;
68
69 std::vector<ArchSpec>
70 GetSupportedArchitectures(const ArchSpec &process_host_arch) override {
72 }
73
75 BreakpointSite *bp_site) override;
76
77 bool GetRemoteOSVersion() override;
78
79 std::optional<std::string> GetRemoteOSBuildString() override;
80
81 std::optional<std::string> GetRemoteOSKernelDescription() override;
82
83 // Remote Platform subclasses need to override this function
85
87
88 bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override;
89
90 // Remote subclasses should override this and return a valid instance
91 // name if connected.
92 const char *GetHostname() override;
93
94 UserIDResolver &GetUserIDResolver() override { return *this; }
95
96 bool IsConnected() const override;
97
98 Status ConnectRemote(Args &args) override;
99
100 Status DisconnectRemote() override;
101
102 Status MakeDirectory(const FileSpec &file_spec,
103 uint32_t file_permissions) override;
104
105 Status GetFilePermissions(const FileSpec &file_spec,
106 uint32_t &file_permissions) override;
107
108 Status SetFilePermissions(const FileSpec &file_spec,
109 uint32_t file_permissions) override;
110
111 lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags,
112 uint32_t mode, Status &error) override;
113
114 bool CloseFile(lldb::user_id_t fd, Status &error) override;
115
116 uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *data_ptr,
117 uint64_t len, Status &error) override;
118
119 uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *data,
120 uint64_t len, Status &error) override;
121
122 lldb::user_id_t GetFileSize(const FileSpec &file_spec) override;
123
125 bool only_dir) override;
126
127 Status PutFile(const FileSpec &source, const FileSpec &destination,
128 uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;
129
130 Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override;
131
132 bool GetFileExists(const FileSpec &file_spec) override;
133
134 Status Unlink(const FileSpec &path) override;
135
137 llvm::StringRef shell, llvm::StringRef command,
138 const FileSpec &working_dir, // Pass empty FileSpec to use the current
139 // working directory
140 int *status_ptr, // Pass NULL if you don't want the process exit status
141 int *signo_ptr, // Pass NULL if you don't want the signal that caused the
142 // process to exit
143 std::string
144 *command_output, // Pass NULL if you don't want the command output
145 const lldb_private::Timeout<std::micro> &timeout) override;
146
147 void CalculateTrapHandlerSymbolNames() override;
148
149 llvm::ErrorOr<llvm::MD5::MD5Result>
150 CalculateMD5(const FileSpec &file_spec) override;
151
153
155 lldb_private::Status &error) override;
156
157 virtual size_t
158 GetPendingGdbServerList(std::vector<std::string> &connection_urls);
159
160protected:
161 std::unique_ptr<process_gdb_remote::GDBRemoteCommunicationClient>
163 std::string m_platform_description; // After we connect we can get a more
164 // complete description of what we are
165 // connected to
166 std::string m_platform_scheme;
168
170
171 // Launch the debug server on the remote host - caller connects to launched
172 // debug server using connect_url.
173 // Subclasses should override this method if they want to do extra actions
174 // before or
175 // after launching the debug server.
176 virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url);
177
178 virtual bool KillSpawnedProcess(lldb::pid_t pid);
179
180 virtual std::string MakeUrl(const char *scheme, const char *hostname,
181 uint16_t port, const char *path);
182
183private:
184 std::string MakeGdbServerUrl(const std::string &platform_scheme,
185 const std::string &platform_hostname,
186 uint16_t port, const char *socket_name);
187
188 std::optional<std::string> DoGetUserName(UserIDResolver::id_t uid) override;
189 std::optional<std::string> DoGetGroupName(UserIDResolver::id_t uid) override;
190
191 std::vector<ArchSpec> m_supported_architectures;
192
196};
197
198} // namespace platform_gdb_server
199} // namespace lldb_private
200
201#endif // LLDB_SOURCE_PLUGINS_PLATFORM_GDB_SERVER_PLATFORMREMOTEGDBSERVER_H
static llvm::raw_ostream & error(Stream &strm)
An architecture specification class.
Definition: ArchSpec.h:31
A command line argument class.
Definition: Args.h:33
Class that manages the actual breakpoint that will be inserted into the running program.
"lldb/Utility/ArgCompletionRequest.h"
A class to manage flag bits.
Definition: Debugger.h:80
A file utility class.
Definition: FileSpec.h:56
A plug-in interface definition class for debug platform that includes many platform abilities such as...
Definition: Platform.h:76
An error handling class.
Definition: Status.h:44
An abstract interface for things that know how to map numeric user/group IDs into names.
lldb::user_id_t GetFileSize(const FileSpec &file_spec) override
std::unique_ptr< process_gdb_remote::GDBRemoteCommunicationClient > m_gdb_client_up
std::optional< std::string > GetRemoteOSKernelDescription() override
Status MakeDirectory(const FileSpec &file_spec, uint32_t file_permissions) override
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) override
Attach to an existing process by process name.
virtual size_t GetPendingGdbServerList(std::vector< std::string > &connection_urls)
llvm::ErrorOr< llvm::MD5::MD5Result > CalculateMD5(const FileSpec &file_spec) override
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger, lldb_private::Status &error) override
Connect to all processes waiting for a debugger to attach.
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
virtual bool LaunchGDBServer(lldb::pid_t &pid, std::string &connect_url)
Status PutFile(const FileSpec &source, const FileSpec &destination, uint32_t uid=UINT32_MAX, uint32_t gid=UINT32_MAX) override
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *data, uint64_t len, Status &error) override
Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) override
virtual std::string MakeUrl(const char *scheme, const char *hostname, uint16_t port, const char *path)
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.
Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr, FileSpec &local_file) override
Locate a file for a platform.
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *data_ptr, uint64_t len, Status &error) override
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override
bool CloseFile(lldb::user_id_t fd, Status &error) override
std::optional< std::string > DoGetGroupName(UserIDResolver::id_t uid) override
PlatformRemoteGDBServer(const PlatformRemoteGDBServer &)=delete
Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) override
const PlatformRemoteGDBServer & operator=(const PlatformRemoteGDBServer &)=delete
bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override
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...
std::string MakeGdbServerUrl(const std::string &platform_scheme, const std::string &platform_hostname, uint16_t port, const char *socket_name)
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) override
std::optional< std::string > DoGetUserName(UserIDResolver::id_t uid) override
void AutoCompleteDiskFileOrDirectory(CompletionRequest &request, bool only_dir) override
lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error) override
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override
Status KillProcess(const lldb::pid_t pid) override
Kill process on a platform.
lldb::ProcessSP Attach(ProcessAttachInfo &attach_info, Debugger &debugger, Target *target, Status &error) override
Attach to an existing process using a process ID.
size_t GetSoftwareBreakpointTrapOpcode(Target &target, BreakpointSite *bp_site) override
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...
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition: Host.h:32
std::shared_ptr< lldb_private::UnixSignals > UnixSignalsSP
Definition: lldb-forward.h:475
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:385
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:386
uint64_t pid_t
Definition: lldb-types.h:83
uint64_t user_id_t
Definition: lldb-types.h:82