LLDB mainline
GDBRemoteCommunicationServerLLGS.h
Go to the documentation of this file.
1//===-- GDBRemoteCommunicationServerLLGS.h ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERLLGS_H
10#define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERLLGS_H
11
12#include <mutex>
13#include <unordered_map>
14#include <unordered_set>
15
17#include "lldb/Host/MainLoop.h"
20
22
24
25namespace lldb_private {
26
27namespace process_gdb_remote {
28
29class ProcessGDBRemote;
30
34public:
35 // Constructors and Destructors
37 MainLoop &mainloop,
38 const NativeProcessProtocol::Factory &process_factory);
39
40 void SetLaunchInfo(const ProcessLaunchInfo &info);
41
42 /// Launch a process with the current launch settings.
43 ///
44 /// This method supports running an lldb-gdbserver or similar
45 /// server in a situation where the startup code has been provided
46 /// with all the information for a child process to be launched.
47 ///
48 /// \return
49 /// An Status object indicating the success or failure of the
50 /// launch.
51 Status LaunchProcess() override;
52
53 /// Attach to a process.
54 ///
55 /// This method supports attaching llgs to a process accessible via the
56 /// configured Platform.
57 ///
58 /// \return
59 /// An Status object indicating the success or failure of the
60 /// attach operation.
62
63 /// Wait to attach to a process with a given name.
64 ///
65 /// This method supports waiting for the next instance of a process
66 /// with a given name and attaching llgs to that via the configured
67 /// Platform.
68 ///
69 /// \return
70 /// An Status object indicating the success or failure of the
71 /// attach operation.
72 Status AttachWaitProcess(llvm::StringRef process_name, bool include_existing);
73
74 // NativeProcessProtocol::NativeDelegate overrides
75 void InitializeDelegate(NativeProcessProtocol *process) override;
76
78 lldb::StateType state) override;
79
80 void DidExec(NativeProcessProtocol *process) override;
81
82 void
84 std::unique_ptr<NativeProcessProtocol> child_process) override;
85
86 Status InitializeConnection(std::unique_ptr<Connection> connection);
87
89 enum class Flag {
90 vkilled = (1u << 0),
91
93 };
94
95 std::unique_ptr<NativeProcessProtocol> process_up;
97 };
98
99protected:
107 std::recursive_mutex m_debugged_process_mutex;
108 std::unordered_map<lldb::pid_t, DebuggedProcess> m_debugged_processes;
109
112
113 llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> m_xfer_buffer_map;
115 std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
119 bool m_non_stop = false;
121 std::deque<std::string> m_stdio_notification_queue;
122 std::deque<std::string> m_stop_notification_queue;
123
125
126 PacketResult SendONotification(const char *buffer, uint32_t len);
127
129
131
133 lldb::tid_t tid,
134 bool force_synchronous);
135
137 lldb::StateType process_state,
138 bool force_synchronous);
139
140 void EnqueueStopReplyPackets(lldb::tid_t thread_to_skip);
141
143
145
147
149
151
153
155
157
159
161 const ResumeActionList &actions);
162
164
166
168
170
172
174
175 void AddProcessThreads(StreamGDBRemote &response,
176 NativeProcessProtocol &process, bool &had_any);
177
179
181
183
185
187
189
191
192 // Handles $m and $x packets.
194
198
201
203
205
207
209
211
213
215
217
219
221
223
225
227
229
231
233
235
237
239
241
243
245
247
249
251
252 PacketResult HandleNotificationAck(std::deque<std::string> &queue);
253
255
257
259
261
263
265
267
269
271
273
275
277
278 FileSpec FindModuleFile(const std::string &module_path,
279 const ArchSpec &arch) override;
280
281 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
282 ReadXferObject(llvm::StringRef object, llvm::StringRef annex);
283
284 static std::string XMLEncodeAttributeValue(llvm::StringRef value);
285
286 std::vector<std::string> HandleFeatures(
287 const llvm::ArrayRef<llvm::StringRef> client_features) override;
288
289 // Provide a response for successful continue action, i.e. send "OK"
290 // in non-stop mode, no response otherwise.
292
293 void AppendThreadIDToResponse(Stream &response, lldb::pid_t pid,
294 lldb::tid_t tid);
295
296private:
297 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> BuildTargetXml();
298
300
302
304
306
308
310
312
314
315 void SendProcessOutput();
316
318
319 void StopSTDIOForwarding();
320
321 // Call SetEnabledExtensions() with appropriate flags on the process.
323
324 // For GDBRemoteCommunicationServerLLGS only
326 delete;
329};
330
331std::string LLGSArgToURL(llvm::StringRef url_arg, bool reverse_connect);
332
333} // namespace process_gdb_remote
334} // namespace lldb_private
335
336#endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERLLGS_H
An architecture specification class.
Definition: ArchSpec.h:32
An abstract communications class.
Definition: Communication.h:39
A file utility class.
Definition: FileSpec.h:56
std::unique_ptr< ReadHandle > ReadHandleUP
Definition: MainLoopBase.h:44
Extension
Extension flag constants, returned by Factory::GetSupportedExtensions() and passed to SetEnabledExten...
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
GDBRemoteCommunicationServerLLGS(const GDBRemoteCommunicationServerLLGS &)=delete
void AddProcessThreads(StreamGDBRemote &response, NativeProcessProtocol &process, bool &had_any)
llvm::StringMap< std::unique_ptr< llvm::MemoryBuffer > > m_xfer_buffer_map
PacketResult SendStopReasonForState(NativeProcessProtocol &process, lldb::StateType process_state, bool force_synchronous)
FileSpec FindModuleFile(const std::string &module_path, const ArchSpec &arch) override
void NewSubprocess(NativeProcessProtocol *parent_process, std::unique_ptr< NativeProcessProtocol > child_process) override
NativeThreadProtocol * GetThreadFromSuffix(StringExtractorGDBRemote &packet)
Status LaunchProcess() override
Launch a process with the current launch settings.
Status AttachWaitProcess(llvm::StringRef process_name, bool include_existing)
Wait to attach to a process with a given name.
const GDBRemoteCommunicationServerLLGS & operator=(const GDBRemoteCommunicationServerLLGS &)=delete
PacketResult ResumeProcess(NativeProcessProtocol &process, const ResumeActionList &actions)
PacketResult SendStopReplyPacketForThread(NativeProcessProtocol &process, lldb::tid_t tid, bool force_synchronous)
void AppendThreadIDToResponse(Stream &response, lldb::pid_t pid, lldb::tid_t tid)
std::vector< std::string > HandleFeatures(const llvm::ArrayRef< llvm::StringRef > client_features) override
void ProcessStateChanged(NativeProcessProtocol *process, lldb::StateType state) override
llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > ReadXferObject(llvm::StringRef object, llvm::StringRef annex)
llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > BuildTargetXml()
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:82
std::string LLGSArgToURL(llvm::StringRef url_arg, bool reverse_connect)
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
StateType
Process and Thread States.
uint64_t pid_t
Definition: lldb-types.h:81
uint64_t tid_t
Definition: lldb-types.h:82