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"
19#include "lldb/Utility/Locked.h"
22
25
27
28namespace lldb_private {
29
30namespace process_gdb_remote {
31
33
37public:
38 // Constructors and Destructors
40 MainLoop &mainloop,
41 NativeProcessProtocol::Manager &process_manager);
42
43 void SetLaunchInfo(const ProcessLaunchInfo &info);
44
45 /// Launch a process with the current launch settings.
46 ///
47 /// This method supports running an lldb-gdbserver or similar
48 /// server in a situation where the startup code has been provided
49 /// with all the information for a child process to be launched.
50 ///
51 /// \return
52 /// An Status object indicating the success or failure of the
53 /// launch.
54 Status LaunchProcess() override;
55
56 /// Attach to a process.
57 ///
58 /// This method supports attaching llgs to a process accessible via the
59 /// configured Platform.
60 ///
61 /// \return
62 /// An Status object indicating the success or failure of the
63 /// attach operation.
65
66 /// Wait to attach to a process with a given name.
67 ///
68 /// This method supports waiting for the next instance of a process
69 /// with a given name and attaching llgs to that via the configured
70 /// Platform.
71 ///
72 /// \return
73 /// An Status object indicating the success or failure of the
74 /// attach operation.
75 Status AttachWaitProcess(llvm::StringRef process_name, bool include_existing);
76
77 void InstallPlugin(
78 std::unique_ptr<lldb_server::LLDBServerAcceleratorPlugin> plugin_up);
79
80 // NativeProcessProtocol::NativeDelegate overrides
81 void InitializeDelegate(NativeProcessProtocol *process) override;
82
84 lldb::StateType state) override;
85
86 void DidExec(NativeProcessProtocol *process) override;
87
88 void
90 std::unique_ptr<NativeProcessProtocol> child_process) override;
91
92 /// Forward a chunk of inferior stdout/stderr produced by the platform's
93 /// own reader. This is used on Windows.
95 llvm::StringRef data) override;
96
97 /// Drain m_pending_output_buffer and emit a `$O` packet if the debuggee
98 /// is currently in a running state. No-op otherwise.
100
101 Status InitializeConnection(std::unique_ptr<Connection> connection);
102
104 SendStructuredDataPacket(const llvm::json::Value &value);
105
107 enum class Flag {
108 vkilled = (1u << 0),
109
111 };
112
113 std::unique_ptr<NativeProcessProtocol> process_up;
115 };
116
117protected:
121 std::vector<std::unique_ptr<lldb_server::LLDBServerAcceleratorPlugin>>
127 std::recursive_mutex m_debugged_process_mutex;
128 std::unordered_map<lldb::pid_t, DebuggedProcess> m_debugged_processes;
129
132
135
136 llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> m_xfer_buffer_map;
137
139 std::unordered_map<uint32_t, lldb::DataBufferSP> map;
140 uint32_t next_id = 1;
141 };
143
147 bool m_non_stop = false;
149 std::deque<std::string> m_stdio_notification_queue;
150 std::deque<std::string> m_stop_notification_queue;
151
153
154 // Typically we would use a SmallVector for this data but in this context we
155 // don't know how much data we're recieving so we would have to heap allocate
156 // a lot, or have a very large stack frame. So it's a member instead.
158
159 PacketResult SendONotification(const char *buffer, uint32_t len);
160
162
164
166 lldb::tid_t tid,
167 bool force_synchronous);
168
170 lldb::StateType process_state,
171 bool force_synchronous);
172
173 void EnqueueStopReplyPackets(lldb::tid_t thread_to_skip);
174
176
178
180
182
184
186
188
190
192
194 const ResumeActionList &actions);
195
197
199
201
203
205
207
208 void AddProcessThreads(StreamGDBRemote &response,
209 NativeProcessProtocol &process, bool &had_any);
210
212
214
216
218
220
222
224
226
227 // Handles $m and $x packets.
229
233
236
238
240
242
244
246
248
250
252
254
256
258
260
262
264
266
268
270
272
274
276
278
280
282
284
286
288
289 PacketResult HandleNotificationAck(std::deque<std::string> &queue);
290
292
294
296
298
300
302
304
306
309
312
315
317
319
321
323
325
326 FileSpec FindModuleFile(const std::string &module_path,
327 const ArchSpec &arch) override;
328
329 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
330 ReadXferObject(llvm::StringRef object, llvm::StringRef annex);
331
332 static std::string XMLEncodeAttributeValue(llvm::StringRef value);
333
334 std::vector<std::string> HandleFeatures(
335 const llvm::ArrayRef<llvm::StringRef> client_features) override;
336
337 // Provide a response for successful continue action, i.e. send "OK"
338 // in non-stop mode, no response otherwise.
340
341 void AppendThreadIDToResponse(Stream &response, lldb::pid_t pid,
342 lldb::tid_t tid);
343
344private:
345 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> BuildTargetXml();
346
347 struct BreakpointOK {};
349 std::string message;
350 };
352 uint8_t error_code;
353 };
354
356 std::variant<BreakpointOK, BreakpointIllFormed, BreakpointError>;
357
358 /// Core logic for a Z (set breakpoint/watchpoint) request.
359 BreakpointResult ExecuteSetBreakpoint(llvm::StringRef packet_str);
360
361 /// Core logic for a z (remove breakpoint/watchpoint) request.
362 BreakpointResult ExecuteRemoveBreakpoint(llvm::StringRef packet_str);
363
364 /// Convert a BreakpointResult into a PacketResult, sending the appropriate
365 /// response.
367 const BreakpointResult &result);
368
370
372
374
375 uint32_t GetNextSavedRegistersID();
376
378
380
382
384
385 void SendProcessOutput();
386
388
389 void StopSTDIOForwarding();
390
391 // Call SetEnabledExtensions() with appropriate flags on the process.
393
394 // For GDBRemoteCommunicationServerLLGS only
396 delete;
399};
400
401std::string LLGSArgToURL(llvm::StringRef url_arg, bool reverse_connect);
402
403} // namespace process_gdb_remote
404} // namespace lldb_private
405
406#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:56
Bundles a value of type T with the Mutex that guards it.
Definition Locked.h:178
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)
PacketResult Handle_jAcceleratorPluginGetDynamicLoaderLibraryInfo(StringExtractorGDBRemote &packet)
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:84
uint64_t tid_t
Definition lldb-types.h:85