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
23
25
26namespace lldb_private {
27
28namespace process_gdb_remote {
29
31
35public:
36 // Constructors and Destructors
38 MainLoop &mainloop,
39 NativeProcessProtocol::Manager &process_manager);
40
41 void SetLaunchInfo(const ProcessLaunchInfo &info);
42
43 /// Launch a process with the current launch settings.
44 ///
45 /// This method supports running an lldb-gdbserver or similar
46 /// server in a situation where the startup code has been provided
47 /// with all the information for a child process to be launched.
48 ///
49 /// \return
50 /// An Status object indicating the success or failure of the
51 /// launch.
52 Status LaunchProcess() override;
53
54 /// Attach to a process.
55 ///
56 /// This method supports attaching llgs to a process accessible via the
57 /// configured Platform.
58 ///
59 /// \return
60 /// An Status object indicating the success or failure of the
61 /// attach operation.
63
64 /// Wait to attach to a process with a given name.
65 ///
66 /// This method supports waiting for the next instance of a process
67 /// with a given name and attaching llgs to that via the configured
68 /// Platform.
69 ///
70 /// \return
71 /// An Status object indicating the success or failure of the
72 /// attach operation.
73 Status AttachWaitProcess(llvm::StringRef process_name, bool include_existing);
74
75 // NativeProcessProtocol::NativeDelegate overrides
76 void InitializeDelegate(NativeProcessProtocol *process) override;
77
79 lldb::StateType state) override;
80
81 void DidExec(NativeProcessProtocol *process) override;
82
83 void
85 std::unique_ptr<NativeProcessProtocol> child_process) override;
86
87 Status InitializeConnection(std::unique_ptr<Connection> connection);
88
90 SendStructuredDataPacket(const llvm::json::Value &value);
91
93 enum class Flag {
94 vkilled = (1u << 0),
95
97 };
98
99 std::unique_ptr<NativeProcessProtocol> process_up;
101 };
102
103protected:
111 std::recursive_mutex m_debugged_process_mutex;
112 std::unordered_map<lldb::pid_t, DebuggedProcess> m_debugged_processes;
113
116
117 llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> m_xfer_buffer_map;
119 std::unordered_map<uint32_t, lldb::DataBufferSP> m_saved_registers_map;
123 bool m_non_stop = false;
125 std::deque<std::string> m_stdio_notification_queue;
126 std::deque<std::string> m_stop_notification_queue;
127
129
130 // Typically we would use a SmallVector for this data but in this context we
131 // don't know how much data we're recieving so we would have to heap allocate
132 // a lot, or have a very large stack frame. So it's a member instead.
134
135 PacketResult SendONotification(const char *buffer, uint32_t len);
136
138
140
142 lldb::tid_t tid,
143 bool force_synchronous);
144
146 lldb::StateType process_state,
147 bool force_synchronous);
148
149 void EnqueueStopReplyPackets(lldb::tid_t thread_to_skip);
150
152
154
156
158
160
162
164
166
168
170 const ResumeActionList &actions);
171
173
175
177
179
181
183
184 void AddProcessThreads(StreamGDBRemote &response,
185 NativeProcessProtocol &process, bool &had_any);
186
188
190
192
194
196
198
200
202
203 // Handles $m and $x packets.
205
209
212
214
216
218
220
222
224
226
228
230
232
234
236
238
240
242
244
246
248
250
252
254
256
258
260
262
263 PacketResult HandleNotificationAck(std::deque<std::string> &queue);
264
266
268
270
272
274
276
278
280
282
284
286
288
290
291 FileSpec FindModuleFile(const std::string &module_path,
292 const ArchSpec &arch) override;
293
294 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
295 ReadXferObject(llvm::StringRef object, llvm::StringRef annex);
296
297 static std::string XMLEncodeAttributeValue(llvm::StringRef value);
298
299 std::vector<std::string> HandleFeatures(
300 const llvm::ArrayRef<llvm::StringRef> client_features) override;
301
302 // Provide a response for successful continue action, i.e. send "OK"
303 // in non-stop mode, no response otherwise.
305
306 void AppendThreadIDToResponse(Stream &response, lldb::pid_t pid,
307 lldb::tid_t tid);
308
309private:
310 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> BuildTargetXml();
311
312 struct BreakpointOK {};
314 std::string message;
315 };
317 uint8_t error_code;
318 };
319
321 std::variant<BreakpointOK, BreakpointIllFormed, BreakpointError>;
322
323 /// Core logic for a Z (set breakpoint/watchpoint) request.
324 BreakpointResult ExecuteSetBreakpoint(llvm::StringRef packet_str);
325
326 /// Core logic for a z (remove breakpoint/watchpoint) request.
327 BreakpointResult ExecuteRemoveBreakpoint(llvm::StringRef packet_str);
328
329 /// Convert a BreakpointResult into a PacketResult, sending the appropriate
330 /// response.
332 const BreakpointResult &result);
333
335
337
339
340 uint32_t GetNextSavedRegistersID();
341
343
345
347
349
350 void SendProcessOutput();
351
353
354 void StopSTDIOForwarding();
355
356 // Call SetEnabledExtensions() with appropriate flags on the process.
358
359 // For GDBRemoteCommunicationServerLLGS only
361 delete;
364};
365
366std::string LLGSArgToURL(llvm::StringRef url_arg, bool reverse_connect);
367
368} // namespace process_gdb_remote
369} // namespace lldb_private
370
371#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)
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 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.
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)
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