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"
21
24
26
27namespace lldb_private {
28
29namespace process_gdb_remote {
30
32
36public:
37 // Constructors and Destructors
39 MainLoop &mainloop,
40 NativeProcessProtocol::Manager &process_manager);
41
42 void SetLaunchInfo(const ProcessLaunchInfo &info);
43
44 /// Launch a process with the current launch settings.
45 ///
46 /// This method supports running an lldb-gdbserver or similar
47 /// server in a situation where the startup code has been provided
48 /// with all the information for a child process to be launched.
49 ///
50 /// \return
51 /// An Status object indicating the success or failure of the
52 /// launch.
53 Status LaunchProcess() override;
54
55 /// Attach to a process.
56 ///
57 /// This method supports attaching llgs to a process accessible via the
58 /// configured Platform.
59 ///
60 /// \return
61 /// An Status object indicating the success or failure of the
62 /// attach operation.
64
65 /// Wait to attach to a process with a given name.
66 ///
67 /// This method supports waiting for the next instance of a process
68 /// with a given name and attaching llgs to that via the configured
69 /// Platform.
70 ///
71 /// \return
72 /// An Status object indicating the success or failure of the
73 /// attach operation.
74 Status AttachWaitProcess(llvm::StringRef process_name, bool include_existing);
75
76 void InstallPlugin(
77 std::unique_ptr<lldb_server::LLDBServerAcceleratorPlugin> plugin_up);
78
79 // NativeProcessProtocol::NativeDelegate overrides
80 void InitializeDelegate(NativeProcessProtocol *process) override;
81
83 lldb::StateType state) override;
84
85 void DidExec(NativeProcessProtocol *process) override;
86
87 void
89 std::unique_ptr<NativeProcessProtocol> child_process) override;
90
91 /// Forward a chunk of inferior stdout/stderr produced by the platform's
92 /// own reader. This is used on Windows.
94 llvm::StringRef data) override;
95
96 /// Drain m_pending_output_buffer and emit a `$O` packet if the debuggee
97 /// is currently in a running state. No-op otherwise.
99
100 Status InitializeConnection(std::unique_ptr<Connection> connection);
101
103 SendStructuredDataPacket(const llvm::json::Value &value);
104
106 enum class Flag {
107 vkilled = (1u << 0),
108
110 };
111
112 std::unique_ptr<NativeProcessProtocol> process_up;
114 };
115
116protected:
120 std::vector<std::unique_ptr<lldb_server::LLDBServerAcceleratorPlugin>>
126 std::recursive_mutex m_debugged_process_mutex;
127 std::unordered_map<lldb::pid_t, DebuggedProcess> m_debugged_processes;
128
131
134
135 llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> m_xfer_buffer_map;
137 std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
141 bool m_non_stop = false;
143 std::deque<std::string> m_stdio_notification_queue;
144 std::deque<std::string> m_stop_notification_queue;
145
147
148 // Typically we would use a SmallVector for this data but in this context we
149 // don't know how much data we're recieving so we would have to heap allocate
150 // a lot, or have a very large stack frame. So it's a member instead.
152
153 PacketResult SendONotification(const char *buffer, uint32_t len);
154
156
158
160 lldb::tid_t tid,
161 bool force_synchronous);
162
164 lldb::StateType process_state,
165 bool force_synchronous);
166
167 void EnqueueStopReplyPackets(lldb::tid_t thread_to_skip);
168
170
172
174
176
178
180
182
184
186
188 const ResumeActionList &actions);
189
191
193
195
197
199
201
202 void AddProcessThreads(StreamGDBRemote &response,
203 NativeProcessProtocol &process, bool &had_any);
204
206
208
210
212
214
216
218
220
221 // Handles $m and $x packets.
223
227
230
232
234
236
238
240
242
244
246
248
250
252
254
256
258
260
262
264
266
268
270
272
274
276
278
280
281 PacketResult HandleNotificationAck(std::deque<std::string> &queue);
282
284
286
288
290
292
294
296
298
301
304
306
308
310
312
314
315 FileSpec FindModuleFile(const std::string &module_path,
316 const ArchSpec &arch) override;
317
318 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
319 ReadXferObject(llvm::StringRef object, llvm::StringRef annex);
320
321 static std::string XMLEncodeAttributeValue(llvm::StringRef value);
322
323 std::vector<std::string> HandleFeatures(
324 const llvm::ArrayRef<llvm::StringRef> client_features) override;
325
326 // Provide a response for successful continue action, i.e. send "OK"
327 // in non-stop mode, no response otherwise.
329
330 void AppendThreadIDToResponse(Stream &response, lldb::pid_t pid,
331 lldb::tid_t tid);
332
333private:
334 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> BuildTargetXml();
335
336 struct BreakpointOK {};
338 std::string message;
339 };
341 uint8_t error_code;
342 };
343
345 std::variant<BreakpointOK, BreakpointIllFormed, BreakpointError>;
346
347 /// Core logic for a Z (set breakpoint/watchpoint) request.
348 BreakpointResult ExecuteSetBreakpoint(llvm::StringRef packet_str);
349
350 /// Core logic for a z (remove breakpoint/watchpoint) request.
351 BreakpointResult ExecuteRemoveBreakpoint(llvm::StringRef packet_str);
352
353 /// Convert a BreakpointResult into a PacketResult, sending the appropriate
354 /// response.
356 const BreakpointResult &result);
357
359
361
363
364 uint32_t GetNextSavedRegistersID();
365
367
369
371
373
374 void SendProcessOutput();
375
377
378 void StopSTDIOForwarding();
379
380 // Call SetEnabledExtensions() with appropriate flags on the process.
382
383 // For GDBRemoteCommunicationServerLLGS only
385 delete;
388};
389
390std::string LLGSArgToURL(llvm::StringRef url_arg, bool reverse_connect);
391
392} // namespace process_gdb_remote
393} // namespace lldb_private
394
395#endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONSERVERLLGS_H
An architecture specification class.
Definition ArchSpec.h:32
An abstract communications class.
A file utility class.
Definition FileSpec.h:57
std::unique_ptr< ReadHandle > ReadHandleUP
Extension
Extension flag constants, returned by Manager::GetSupportedExtensions() and passed to SetEnabledExten...
An error handling class.
Definition Status.h:118
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)
std::vector< std::unique_ptr< lldb_server::LLDBServerAcceleratorPlugin > > m_accelerator_plugins
GDBRemoteCommunication::PacketResult SendStructuredDataPacket(const llvm::json::Value &value)
std::variant< BreakpointOK, BreakpointIllFormed, BreakpointError > BreakpointResult
BreakpointResult ExecuteRemoveBreakpoint(llvm::StringRef packet_str)
Core logic for a z (remove breakpoint/watchpoint) request.
FileSpec FindModuleFile(const std::string &module_path, const ArchSpec &arch) override
void NewProcessOutput(NativeProcessProtocol *process, llvm::StringRef data) override
Forward a chunk of inferior stdout/stderr produced by the platform's own reader.
void NewSubprocess(NativeProcessProtocol *parent_process, std::unique_ptr< NativeProcessProtocol > child_process) override
NativeThreadProtocol * GetThreadFromSuffix(StringExtractorGDBRemote &packet)
PacketResult SendBreakpointResponse(StringExtractorGDBRemote &packet, const BreakpointResult &result)
Convert a BreakpointResult into a PacketResult, sending the appropriate response.
BreakpointResult ExecuteSetBreakpoint(llvm::StringRef packet_str)
Core logic for a Z (set breakpoint/watchpoint) request.
Status LaunchProcess() override
Launch a process with the current launch settings.
void FlushPendingProcessOutput()
Drain m_pending_output_buffer and emit a $O packet if the debuggee is currently in a running state.
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)
void InstallPlugin(std::unique_ptr< lldb_server::LLDBServerAcceleratorPlugin > plugin_up)
GDBRemoteCommunicationServerLLGS(MainLoop &mainloop, NativeProcessProtocol::Manager &process_manager)
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
std::string LLGSArgToURL(llvm::StringRef url_arg, bool reverse_connect)
A class that represents a running process on the host machine.
MainLoopPosix MainLoop
Definition MainLoop.h:20
StateType
Process and Thread States.
uint64_t pid_t
Definition lldb-types.h:83
uint64_t tid_t
Definition lldb-types.h:84