• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stddef.h>
19 #include <stdint.h>
20 
21 class StringExtractorGDBRemote : public StringExtractor {
22 public:
23   typedef bool (*ResponseValidatorCallback)(
24       void *baton, const StringExtractorGDBRemote &response);
25 
StringExtractorGDBRemote()26   StringExtractorGDBRemote() : StringExtractor(), m_validator(nullptr) {}
27 
StringExtractorGDBRemote(llvm::StringRef str)28   StringExtractorGDBRemote(llvm::StringRef str)
29       : StringExtractor(str), m_validator(nullptr) {}
30 
StringExtractorGDBRemote(const char * cstr)31   StringExtractorGDBRemote(const char *cstr)
32       : 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_stat,
92     eServerPacketType_vFile_symlink,
93     eServerPacketType_vFile_unlink,
94     // debug server packages
95     eServerPacketType_QEnvironmentHexEncoded,
96     eServerPacketType_QListThreadsInStopReply,
97     eServerPacketType_QPassSignals,
98     eServerPacketType_QRestoreRegisterState,
99     eServerPacketType_QSaveRegisterState,
100     eServerPacketType_QSetLogging,
101     eServerPacketType_QSetMaxPacketSize,
102     eServerPacketType_QSetMaxPayloadSize,
103     eServerPacketType_QSetEnableAsyncProfiling,
104     eServerPacketType_QSyncThreadState,
105     eServerPacketType_QThreadSuffixSupported,
106 
107     eServerPacketType_jThreadsInfo,
108     eServerPacketType_qsThreadInfo,
109     eServerPacketType_qfThreadInfo,
110     eServerPacketType_qGetPid,
111     eServerPacketType_qGetProfileData,
112     eServerPacketType_qGDBServerVersion,
113     eServerPacketType_qMemoryRegionInfo,
114     eServerPacketType_qMemoryRegionInfoSupported,
115     eServerPacketType_qProcessInfo,
116     eServerPacketType_qRcmd,
117     eServerPacketType_qRegisterInfo,
118     eServerPacketType_qShlibInfoAddr,
119     eServerPacketType_qStepPacketSupported,
120     eServerPacketType_qSupported,
121     eServerPacketType_qSyncThreadStateSupported,
122     eServerPacketType_qThreadExtraInfo,
123     eServerPacketType_qThreadStopInfo,
124     eServerPacketType_qVAttachOrWaitSupported,
125     eServerPacketType_qWatchpointSupportInfo,
126     eServerPacketType_qWatchpointSupportInfoSupported,
127     eServerPacketType_qXfer,
128 
129     eServerPacketType_jSignalsInfo,
130     eServerPacketType_jModulesInfo,
131 
132     eServerPacketType_vAttach,
133     eServerPacketType_vAttachWait,
134     eServerPacketType_vAttachOrWait,
135     eServerPacketType_vAttachName,
136     eServerPacketType_vCont,
137     eServerPacketType_vCont_actions, // vCont?
138 
139     eServerPacketType_stop_reason, // '?'
140 
141     eServerPacketType_c,
142     eServerPacketType_C,
143     eServerPacketType_D,
144     eServerPacketType_g,
145     eServerPacketType_G,
146     eServerPacketType_H,
147     eServerPacketType_I, // stdin notification
148     eServerPacketType_k,
149     eServerPacketType_m,
150     eServerPacketType_M,
151     eServerPacketType_p,
152     eServerPacketType_P,
153     eServerPacketType_s,
154     eServerPacketType_S,
155     eServerPacketType_T,
156     eServerPacketType_x,
157     eServerPacketType_X,
158     eServerPacketType_Z,
159     eServerPacketType_z,
160 
161     eServerPacketType__M,
162     eServerPacketType__m,
163     eServerPacketType_notify, // '%' notification
164 
165     eServerPacketType_jTraceStart,      // deprecated
166     eServerPacketType_jTraceBufferRead, // deprecated
167     eServerPacketType_jTraceMetaRead,   // deprecated
168     eServerPacketType_jTraceStop,       // deprecated
169     eServerPacketType_jTraceConfigRead, // deprecated
170 
171     eServerPacketType_jLLDBTraceSupportedType,
172   };
173 
174   ServerPacketType GetServerPacketType() const;
175 
176   enum ResponseType { eUnsupported = 0, eAck, eNack, eError, eOK, eResponse };
177 
178   ResponseType GetResponseType() const;
179 
180   bool IsOKResponse() const;
181 
182   bool IsUnsupportedResponse() const;
183 
184   bool IsNormalResponse() const;
185 
186   bool IsErrorResponse() const;
187 
188   // Returns zero if the packet isn't a EXX packet where XX are two hex digits.
189   // Otherwise the error encoded in XX is returned.
190   uint8_t GetError();
191 
192   lldb_private::Status GetStatus();
193 
194   size_t GetEscapedBinaryData(std::string &str);
195 
196 protected:
197   ResponseValidatorCallback m_validator;
198   void *m_validator_baton;
199 };
200 
201 #endif // LLDB_UTILITY_STRINGEXTRACTORGDBREMOTE_H
202