Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Utility/StringExtractorGDBRemote.h
Line
Count
Source
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"
13
#include "lldb/Utility/StringExtractor.h"
14
#include "llvm/ADT/StringRef.h"
15
16
#include <string>
17
18
#include <cstddef>
19
#include <cstdint>
20
21
class StringExtractorGDBRemote : public StringExtractor {
22
public:
23
  typedef bool (*ResponseValidatorCallback)(
24
      void *baton, const StringExtractorGDBRemote &response);
25
26
425k
  StringExtractorGDBRemote() {}
27
28
  StringExtractorGDBRemote(llvm::StringRef str)
29
480k
      : StringExtractor(str), m_validator(nullptr) {}
30
31
  StringExtractorGDBRemote(const char *cstr)
32
2
      : StringExtractor(cstr), m_validator(nullptr) {}
33
34
  bool ValidateResponse() const;
35
36
  void CopyResponseValidator(const StringExtractorGDBRemote &rhs);
37
38
  void SetResponseValidator(ResponseValidatorCallback callback, void *baton);
39
40
  void SetResponseValidatorToOKErrorNotSupported();
41
42
  void SetResponseValidatorToASCIIHexBytes();
43
44
  void SetResponseValidatorToJSON();
45
46
  enum ServerPacketType {
47
    eServerPacketType_nack = 0,
48
    eServerPacketType_ack,
49
    eServerPacketType_invalid,
50
    eServerPacketType_unimplemented,
51
    eServerPacketType_interrupt, // CTRL+c packet or "\x03"
52
    eServerPacketType_A,         // Program arguments packet
53
    eServerPacketType_qfProcessInfo,
54
    eServerPacketType_qsProcessInfo,
55
    eServerPacketType_qC,
56
    eServerPacketType_qEcho,
57
    eServerPacketType_qGroupName,
58
    eServerPacketType_qHostInfo,
59
    eServerPacketType_qLaunchGDBServer,
60
    eServerPacketType_qQueryGDBServer,
61
    eServerPacketType_qKillSpawnedProcess,
62
    eServerPacketType_qLaunchSuccess,
63
    eServerPacketType_qModuleInfo,
64
    eServerPacketType_qProcessInfoPID,
65
    eServerPacketType_qSpeedTest,
66
    eServerPacketType_qUserName,
67
    eServerPacketType_qGetWorkingDir,
68
    eServerPacketType_qFileLoadAddress,
69
    eServerPacketType_QEnvironment,
70
    eServerPacketType_QEnableErrorStrings,
71
    eServerPacketType_QLaunchArch,
72
    eServerPacketType_QSetDisableASLR,
73
    eServerPacketType_QSetDetachOnError,
74
    eServerPacketType_QSetSTDIN,
75
    eServerPacketType_QSetSTDOUT,
76
    eServerPacketType_QSetSTDERR,
77
    eServerPacketType_QSetWorkingDir,
78
    eServerPacketType_QStartNoAckMode,
79
    eServerPacketType_qPathComplete,
80
    eServerPacketType_qPlatform_shell,
81
    eServerPacketType_qPlatform_mkdir,
82
    eServerPacketType_qPlatform_chmod,
83
    eServerPacketType_vFile_open,
84
    eServerPacketType_vFile_close,
85
    eServerPacketType_vFile_pread,
86
    eServerPacketType_vFile_pwrite,
87
    eServerPacketType_vFile_size,
88
    eServerPacketType_vFile_mode,
89
    eServerPacketType_vFile_exists,
90
    eServerPacketType_vFile_md5,
91
    eServerPacketType_vFile_fstat,
92
    eServerPacketType_vFile_stat,
93
    eServerPacketType_vFile_symlink,
94
    eServerPacketType_vFile_unlink,
95
    // debug server packages
96
    eServerPacketType_QEnvironmentHexEncoded,
97
    eServerPacketType_QListThreadsInStopReply,
98
    eServerPacketType_QPassSignals,
99
    eServerPacketType_QRestoreRegisterState,
100
    eServerPacketType_QSaveRegisterState,
101
    eServerPacketType_QSetLogging,
102
    eServerPacketType_QSetMaxPacketSize,
103
    eServerPacketType_QSetMaxPayloadSize,
104
    eServerPacketType_QSetEnableAsyncProfiling,
105
    eServerPacketType_QSyncThreadState,
106
    eServerPacketType_QThreadSuffixSupported,
107
108
    eServerPacketType_jThreadsInfo,
109
    eServerPacketType_qsThreadInfo,
110
    eServerPacketType_qfThreadInfo,
111
    eServerPacketType_qGetPid,
112
    eServerPacketType_qGetProfileData,
113
    eServerPacketType_qGDBServerVersion,
114
    eServerPacketType_qMemoryRegionInfo,
115
    eServerPacketType_qMemoryRegionInfoSupported,
116
    eServerPacketType_qProcessInfo,
117
    eServerPacketType_qRcmd,
118
    eServerPacketType_qRegisterInfo,
119
    eServerPacketType_qShlibInfoAddr,
120
    eServerPacketType_qStepPacketSupported,
121
    eServerPacketType_qSupported,
122
    eServerPacketType_qSyncThreadStateSupported,
123
    eServerPacketType_qThreadExtraInfo,
124
    eServerPacketType_qThreadStopInfo,
125
    eServerPacketType_qVAttachOrWaitSupported,
126
    eServerPacketType_qWatchpointSupportInfo,
127
    eServerPacketType_qWatchpointSupportInfoSupported,
128
    eServerPacketType_qXfer,
129
130
    eServerPacketType_jSignalsInfo,
131
    eServerPacketType_jModulesInfo,
132
133
    eServerPacketType_vAttach,
134
    eServerPacketType_vAttachWait,
135
    eServerPacketType_vAttachOrWait,
136
    eServerPacketType_vAttachName,
137
    eServerPacketType_vCont,
138
    eServerPacketType_vCont_actions, // vCont?
139
    eServerPacketType_vRun,
140
141
    eServerPacketType_stop_reason, // '?'
142
143
    eServerPacketType_c,
144
    eServerPacketType_C,
145
    eServerPacketType_D,
146
    eServerPacketType_g,
147
    eServerPacketType_G,
148
    eServerPacketType_H,
149
    eServerPacketType_I, // stdin notification
150
    eServerPacketType_k,
151
    eServerPacketType_m,
152
    eServerPacketType_M,
153
    eServerPacketType_p,
154
    eServerPacketType_P,
155
    eServerPacketType_s,
156
    eServerPacketType_S,
157
    eServerPacketType_T,
158
    eServerPacketType_x,
159
    eServerPacketType_X,
160
    eServerPacketType_Z,
161
    eServerPacketType_z,
162
163
    eServerPacketType__M,
164
    eServerPacketType__m,
165
    eServerPacketType_notify, // '%' notification
166
167
    eServerPacketType_jLLDBTraceSupported,
168
    eServerPacketType_jLLDBTraceStart,
169
    eServerPacketType_jLLDBTraceStop,
170
    eServerPacketType_jLLDBTraceGetState,
171
    eServerPacketType_jLLDBTraceGetBinaryData,
172
173
    eServerPacketType_qMemTags, // read memory tags
174
    eServerPacketType_QMemTags, // write memory tags
175
176
    eServerPacketType_qLLDBSaveCore,
177
  };
178
179
  ServerPacketType GetServerPacketType() const;
180
181
  enum ResponseType { eUnsupported = 0, eAck, eNack, eError, eOK, eResponse };
182
183
  ResponseType GetResponseType() const;
184
185
  bool IsOKResponse() const;
186
187
  bool IsUnsupportedResponse() const;
188
189
  bool IsNormalResponse() const;
190
191
  bool IsErrorResponse() const;
192
193
  // Returns zero if the packet isn't a EXX packet where XX are two hex digits.
194
  // Otherwise the error encoded in XX is returned.
195
  uint8_t GetError();
196
197
  lldb_private::Status GetStatus();
198
199
  size_t GetEscapedBinaryData(std::string &str);
200
201
  static constexpr lldb::pid_t AllProcesses = UINT64_MAX;
202
  static constexpr lldb::tid_t AllThreads = UINT64_MAX;
203
204
  // Read thread-id from the packet.  If the packet is valid, returns
205
  // the pair (PID, TID), otherwise returns llvm::None.  If the packet
206
  // does not list a PID, default_pid is used.
207
  llvm::Optional<std::pair<lldb::pid_t, lldb::tid_t>>
208
  GetPidTid(lldb::pid_t default_pid);
209
210
protected:
211
  ResponseValidatorCallback m_validator = nullptr;
212
  void *m_validator_baton;
213
};
214
215
#endif // LLDB_UTILITY_STRINGEXTRACTORGDBREMOTE_H