LLDB mainline
StringExtractorGDBRemote.h
Go to the documentation of this file.
1//===-- StringExtractorGDBRemote.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_UTILITY_STRINGEXTRACTORGDBREMOTE_H
10#define LLDB_UTILITY_STRINGEXTRACTORGDBREMOTE_H
11
12#include "lldb/Utility/Status.h"
14#include "llvm/ADT/StringRef.h"
15
16#include <optional>
17#include <string>
18
19#include <cstddef>
20#include <cstdint>
21
23public:
25 void *baton, const StringExtractorGDBRemote &response);
26
28
29 StringExtractorGDBRemote(llvm::StringRef str)
30 : StringExtractor(str), m_validator(nullptr) {}
31
32 StringExtractorGDBRemote(const char *cstr)
33 : StringExtractor(cstr), m_validator(nullptr) {}
34
35 bool ValidateResponse() const;
36
38
39 void SetResponseValidator(ResponseValidatorCallback callback, void *baton);
40
42
44
46
52 eServerPacketType_interrupt, // CTRL+c packet or "\x03"
53 eServerPacketType_A, // Program arguments packet
97 // debug server packages
109
133
135
144
146
153 eServerPacketType_I, // stdin notification
166
169 eServerPacketType_notify, // '%' notification
170
182
183 eServerPacketType_qMemTags, // read memory tags
184 eServerPacketType_QMemTags, // write memory tags
185
192 };
193
195
197
199
200 bool IsOKResponse() const;
201
202 bool IsUnsupportedResponse() const;
203
204 bool IsNormalResponse() const;
205
206 bool IsErrorResponse() const;
207
208 enum StopReplyMask : uint32_t {
209 Signal = (1u << 0), // 'T' and 'S' stop reply packets.
210 Exited = (1u << 1), // 'W' process-exit and 'w' thread-exit packets.
211 Terminated = (1u << 2), // 'X' termination packets.
212 Output = (1u << 3), // 'O' output packets; these do not imply a stop.
213 NoResumedThreads = (1u << 4), // 'N' no-resumed-threads packets.
214 Syscall = (1u << 5), // 'F' file-I/O request packets.
217 };
218
219 /// Classify packets from the stop-reply section of the GDB remote protocol.
220 /// Use ValidStop to match signal, exit, and termination replies. Other packet
221 /// classes, such as Output, can be received while the process is running.
222 bool IsStopReply(uint32_t mask = StopReplyMask::Any) const;
223
224 // Returns zero if the packet isn't a EXX packet where XX are two hex digits.
225 // Otherwise the error encoded in XX is returned.
226 uint8_t GetError();
227
229
230 size_t GetEscapedBinaryData(std::string &str);
231
234
235 // Read thread-id from the packet. If the packet is valid, returns
236 // the pair (PID, TID), otherwise returns std::nullopt. If the packet
237 // does not list a PID, default_pid is used.
238 std::optional<std::pair<lldb::pid_t, lldb::tid_t>>
239 GetPidTid(lldb::pid_t default_pid);
240
241protected:
243 void *m_validator_baton = nullptr;
244};
245
246#endif // LLDB_UTILITY_STRINGEXTRACTORGDBREMOTE_H
StringExtractorGDBRemote(const char *cstr)
void CopyResponseValidator(const StringExtractorGDBRemote &rhs)
ServerPacketType GetServerPacketType() const
StringExtractorGDBRemote()=default
static constexpr lldb::tid_t AllThreads
size_t GetEscapedBinaryData(std::string &str)
void SetResponseValidator(ResponseValidatorCallback callback, void *baton)
static constexpr lldb::pid_t AllProcesses
bool IsStopReply(uint32_t mask=StopReplyMask::Any) const
Classify packets from the stop-reply section of the GDB remote protocol.
ResponseValidatorCallback m_validator
bool(* ResponseValidatorCallback)(void *baton, const StringExtractorGDBRemote &response)
std::optional< std::pair< lldb::pid_t, lldb::tid_t > > GetPidTid(lldb::pid_t default_pid)
StringExtractorGDBRemote(llvm::StringRef str)
An error handling class.
Definition Status.h:118
#define UINT64_MAX
uint64_t pid_t
Definition lldb-types.h:84
uint64_t tid_t
Definition lldb-types.h:85