1 //===-- PlatformRemoteGDBServer.h ----------------------------------------*- C++
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
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_SOURCE_PLUGINS_PLATFORM_GDB_SERVER_PLATFORMREMOTEGDBSERVER_H
11 #define LLDB_SOURCE_PLUGINS_PLATFORM_GDB_SERVER_PLATFORMREMOTEGDBSERVER_H
16 #include "Plugins/Process/Utility/GDBRemoteSignals.h"
17 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
18 #include "lldb/Target/Platform.h"
20 namespace lldb_private
{
21 namespace platform_gdb_server
{
23 class PlatformRemoteGDBServer
: public Platform
, private UserIDResolver
{
25 static void Initialize();
27 static void Terminate();
29 static lldb::PlatformSP
CreateInstance(bool force
, const ArchSpec
*arch
);
31 static llvm::StringRef
GetPluginNameStatic() { return "remote-gdb-server"; }
33 static llvm::StringRef
GetDescriptionStatic();
35 PlatformRemoteGDBServer();
37 ~PlatformRemoteGDBServer() override
;
39 // lldb_private::PluginInterface functions
40 llvm::StringRef
GetPluginName() override
{ return GetPluginNameStatic(); }
42 // lldb_private::Platform functions
43 bool GetModuleSpec(const FileSpec
&module_file_spec
, const ArchSpec
&arch
,
44 ModuleSpec
&module_spec
) override
;
46 llvm::StringRef
GetDescription() override
;
48 Status
GetFileWithUUID(const FileSpec
&platform_file
, const UUID
*uuid_ptr
,
49 FileSpec
&local_file
) override
;
51 bool GetProcessInfo(lldb::pid_t pid
, ProcessInstanceInfo
&proc_info
) override
;
53 uint32_t FindProcesses(const ProcessInstanceInfoMatch
&match_info
,
54 ProcessInstanceInfoList
&process_infos
) override
;
56 Status
LaunchProcess(ProcessLaunchInfo
&launch_info
) override
;
58 Status
KillProcess(const lldb::pid_t pid
) override
;
60 lldb::ProcessSP
DebugProcess(ProcessLaunchInfo
&launch_info
,
61 Debugger
&debugger
, Target
&target
,
62 Status
&error
) override
;
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
;
70 GetSupportedArchitectures(const ArchSpec
&process_host_arch
) override
{
71 return m_supported_architectures
;
74 size_t GetSoftwareBreakpointTrapOpcode(Target
&target
,
75 BreakpointSite
*bp_site
) override
;
77 bool GetRemoteOSVersion() override
;
79 std::optional
<std::string
> GetRemoteOSBuildString() override
;
81 std::optional
<std::string
> GetRemoteOSKernelDescription() override
;
83 // Remote Platform subclasses need to override this function
84 ArchSpec
GetRemoteSystemArchitecture() override
;
86 FileSpec
GetRemoteWorkingDirectory() override
;
88 bool SetRemoteWorkingDirectory(const FileSpec
&working_dir
) override
;
90 // Remote subclasses should override this and return a valid instance
92 const char *GetHostname() override
;
94 UserIDResolver
&GetUserIDResolver() override
{ return *this; }
96 bool IsConnected() const override
;
98 Status
ConnectRemote(Args
&args
) override
;
100 Status
DisconnectRemote() override
;
102 Status
MakeDirectory(const FileSpec
&file_spec
,
103 uint32_t file_permissions
) override
;
105 Status
GetFilePermissions(const FileSpec
&file_spec
,
106 uint32_t &file_permissions
) override
;
108 Status
SetFilePermissions(const FileSpec
&file_spec
,
109 uint32_t file_permissions
) override
;
111 lldb::user_id_t
OpenFile(const FileSpec
&file_spec
, File::OpenOptions flags
,
112 uint32_t mode
, Status
&error
) override
;
114 bool CloseFile(lldb::user_id_t fd
, Status
&error
) override
;
116 uint64_t ReadFile(lldb::user_id_t fd
, uint64_t offset
, void *data_ptr
,
117 uint64_t len
, Status
&error
) override
;
119 uint64_t WriteFile(lldb::user_id_t fd
, uint64_t offset
, const void *data
,
120 uint64_t len
, Status
&error
) override
;
122 lldb::user_id_t
GetFileSize(const FileSpec
&file_spec
) override
;
124 void AutoCompleteDiskFileOrDirectory(CompletionRequest
&request
,
125 bool only_dir
) override
;
127 Status
PutFile(const FileSpec
&source
, const FileSpec
&destination
,
128 uint32_t uid
= UINT32_MAX
, uint32_t gid
= UINT32_MAX
) override
;
130 Status
CreateSymlink(const FileSpec
&src
, const FileSpec
&dst
) override
;
132 bool GetFileExists(const FileSpec
&file_spec
) override
;
134 Status
Unlink(const FileSpec
&path
) override
;
136 Status
RunShellCommand(
137 llvm::StringRef shell
, llvm::StringRef command
,
138 const FileSpec
&working_dir
, // Pass empty FileSpec to use the current
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
144 *command_output
, // Pass NULL if you don't want the command output
145 const lldb_private::Timeout
<std::micro
> &timeout
) override
;
147 void CalculateTrapHandlerSymbolNames() override
;
149 llvm::ErrorOr
<llvm::MD5::MD5Result
>
150 CalculateMD5(const FileSpec
&file_spec
) override
;
152 const lldb::UnixSignalsSP
&GetRemoteUnixSignals() override
;
154 size_t ConnectToWaitingProcesses(lldb_private::Debugger
&debugger
,
155 lldb_private::Status
&error
) override
;
158 GetPendingGdbServerList(std::vector
<std::string
> &connection_urls
);
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
166 std::string m_platform_scheme
;
167 std::string m_platform_hostname
;
169 lldb::UnixSignalsSP m_remote_signals_sp
;
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
175 // after launching the debug server.
176 virtual bool LaunchGDBServer(lldb::pid_t
&pid
, std::string
&connect_url
);
178 virtual bool KillSpawnedProcess(lldb::pid_t pid
);
180 virtual std::string
MakeUrl(const char *scheme
, const char *hostname
,
181 uint16_t port
, const char *path
);
184 std::string
MakeGdbServerUrl(const std::string
&platform_scheme
,
185 const std::string
&platform_hostname
,
186 uint16_t port
, const char *socket_name
);
188 std::optional
<std::string
> DoGetUserName(UserIDResolver::id_t uid
) override
;
189 std::optional
<std::string
> DoGetGroupName(UserIDResolver::id_t uid
) override
;
191 std::vector
<ArchSpec
> m_supported_architectures
;
193 PlatformRemoteGDBServer(const PlatformRemoteGDBServer
&) = delete;
194 const PlatformRemoteGDBServer
&
195 operator=(const PlatformRemoteGDBServer
&) = delete;
198 } // namespace platform_gdb_server
199 } // namespace lldb_private
201 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_GDB_SERVER_PLATFORMREMOTEGDBSERVER_H