File indexing completed on 2024-05-12 05:51:06
0001 /* 0002 SPDX-FileCopyrightText: 2022 Héctor Mesa Jiménez <wmj.py@gmx.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include <QHash> 0009 #include <QJsonValue> 0010 #include <QList> 0011 #include <QString> 0012 #include <optional> 0013 #include <utility> 0014 0015 class QJsonObject; 0016 0017 namespace dap 0018 { 0019 struct Message { 0020 /** 0021 * @brief id unique identifier for the message 0022 */ 0023 int id; 0024 /** 0025 * @brief format A format string for the message. 0026 * 0027 * Embedded variables have the form '{name}'. If variable 0028 * name starts with an underscore character, the variable 0029 * does not contain user data (PII) and can be safely used for 0030 * telemetry purposes. 0031 */ 0032 QString format; 0033 /** 0034 * @brief variables An object used as a dictionary for looking 0035 * up the variables in the format string. 0036 */ 0037 std::optional<QHash<QString, QString>> variables; 0038 /** 0039 * @brief sendTelemetry If true send telemetry 0040 */ 0041 std::optional<bool> sendTelemetry; 0042 /** 0043 * @brief showUser If true show user 0044 */ 0045 std::optional<bool> showUser; 0046 /** 0047 * @brief showUser An optional url where additional information 0048 * about this message can be found. 0049 */ 0050 std::optional<QString> url; 0051 /** 0052 * @brief urlLabel An optional label that is presented to the user as the UI 0053 * for opening the url. 0054 */ 0055 std::optional<QString> urlLabel; 0056 0057 Message() = default; 0058 Message(const QJsonObject &body); 0059 }; 0060 0061 struct Response { 0062 int request_seq; 0063 bool success; 0064 QString command; 0065 QString message; 0066 QJsonValue body; 0067 std::optional<Message> errorBody; 0068 0069 Response() = default; 0070 Response(const QJsonObject &msg); 0071 0072 bool isCancelled() const; 0073 }; 0074 0075 struct ProcessInfo { 0076 /** 0077 * @brief name the logical name of the process 0078 * 0079 * This is usually the full path to process's executable file. 0080 */ 0081 QString name; 0082 /** 0083 * @brief systemProcessId the system process id of the debugged process 0084 * 0085 * This property will be missing for non-system processes. 0086 */ 0087 std::optional<int> systemProcessId; 0088 /** 0089 * @brief isLocalProcess if true, the process is running on the same computer as DA 0090 */ 0091 std::optional<bool> isLocalProcess; 0092 /** 0093 * @brief startMethod describes how the debug engine started debugging this process. 0094 */ 0095 std::optional<QString> startMethod; 0096 /** 0097 * @brief pointerSize the sized of a pointer or address for this process, in bits. 0098 * 0099 * This value may be used by clients when formatting addresses for display. 0100 */ 0101 std::optional<int> pointerSize; 0102 0103 ProcessInfo() = default; 0104 ProcessInfo(const QJsonObject &body); 0105 }; 0106 0107 struct Checksum { 0108 QString checksum; 0109 QString algorithm; 0110 0111 Checksum() = default; 0112 Checksum(const QJsonObject &body); 0113 0114 QJsonObject toJson() const; 0115 }; 0116 0117 struct Source { 0118 QString name; 0119 QString path; 0120 std::optional<int> sourceReference; 0121 std::optional<QString> presentationHint; 0122 QString origin; 0123 QList<Source> sources; 0124 QJsonValue adapterData; 0125 QList<Checksum> checksums; 0126 0127 QString unifiedId() const; 0128 static QString getUnifiedId(const QString &path, std::optional<int> sourceReference); 0129 0130 Source() = default; 0131 Source(const QJsonObject &body); 0132 Source(const QString &path); 0133 0134 QJsonObject toJson() const; 0135 }; 0136 0137 struct SourceContent { 0138 QString content; 0139 std::optional<QString> mimeType; 0140 0141 SourceContent() = default; 0142 SourceContent(const QJsonObject &body); 0143 SourceContent(const QString &path); 0144 }; 0145 0146 struct SourceBreakpoint { 0147 int line; 0148 std::optional<int> column; 0149 /** 0150 * An optional expression for conditional breakpoints. 0151 * It is only honored by a debug adapter if the capability 0152 * 'supportsConditionalBreakpoints' is true. 0153 */ 0154 std::optional<QString> condition; 0155 /** 0156 * An optional expression that controls how many hits of the breakpoint are 0157 * ignored. 0158 * The backend is expected to interpret the expression as needed. 0159 * The attribute is only honored by a debug adapter if the capability 0160 * 'supportsHitConditionalBreakpoints' is true. 0161 */ 0162 std::optional<QString> hitCondition; 0163 /** 0164 * If this attribute exists and is non-empty, the backend must not 'break' 0165 * (stop) 0166 * but log the message instead. Expressions within {} are interpolated. 0167 * The attribute is only honored by a debug adapter if the capability 0168 * 'supportsLogPoints' is true. 0169 */ 0170 std::optional<QString> logMessage; 0171 0172 SourceBreakpoint() = default; 0173 SourceBreakpoint(const QJsonObject &body); 0174 SourceBreakpoint(const int line); 0175 0176 QJsonObject toJson() const; 0177 }; 0178 0179 struct Breakpoint { 0180 /** 0181 * An optional identifier for the breakpoint. It is needed if breakpoint 0182 * events are used to update or remove breakpoints. 0183 */ 0184 std::optional<int> id; 0185 /** 0186 * If true breakpoint could be set (but not necessarily at the desired 0187 * location). 0188 */ 0189 bool verified; 0190 /** 0191 * An optional message about the state of the breakpoint. 0192 * This is shown to the user and can be used to explain why a breakpoint could 0193 * not be verified. 0194 */ 0195 std::optional<QString> message; 0196 std::optional<Source> source; 0197 /** 0198 * The start line of the actual range covered by the breakpoint. 0199 */ 0200 std::optional<int> line; 0201 std::optional<int> column; 0202 std::optional<int> endLine; 0203 std::optional<int> endColumn; 0204 /** 0205 * An optional memory reference to where the breakpoint is set. 0206 */ 0207 std::optional<QString> instructionReference; 0208 /** 0209 * An optional offset from the instruction reference. 0210 * This can be negative. 0211 */ 0212 std::optional<int> offset; 0213 0214 Breakpoint() = default; 0215 Breakpoint(const QJsonObject &body); 0216 Breakpoint(const int line); 0217 }; 0218 0219 class Output 0220 { 0221 Q_GADGET 0222 public: 0223 enum class Category { Console, Important, Stdout, Stderr, Telemetry, Unknown }; 0224 0225 Q_ENUM(Category) 0226 0227 enum class Group { 0228 Start, 0229 StartCollapsed, 0230 End, 0231 }; 0232 0233 Category category; 0234 QString output; 0235 std::optional<Group> group; 0236 std::optional<int> variablesReference; 0237 std::optional<Source> source; 0238 std::optional<int> line; 0239 std::optional<int> column; 0240 QJsonValue data; 0241 0242 Output() = default; 0243 Output(const QJsonObject &body); 0244 Output(const QString &output, const Category &category); 0245 0246 bool isSpecialOutput() const; 0247 }; 0248 0249 struct Capabilities { 0250 bool supportsConfigurationDoneRequest; 0251 bool supportsFunctionBreakpoints; 0252 bool supportsConditionalBreakpoints; 0253 bool supportsHitConditionalBreakpoints; 0254 bool supportsLogPoints; 0255 bool supportsModulesRequest; 0256 bool supportsTerminateRequest; 0257 bool supportTerminateDebuggee; 0258 bool supportsGotoTargetsRequest; 0259 0260 Capabilities() = default; 0261 Capabilities(const QJsonObject &body); 0262 }; 0263 0264 struct ThreadEvent { 0265 QString reason; 0266 int threadId; 0267 0268 ThreadEvent() = default; 0269 ThreadEvent(const QJsonObject &body); 0270 }; 0271 0272 struct Module { 0273 std::optional<int> id_int; 0274 std::optional<QString> id_str; 0275 QString name; 0276 std::optional<QString> path; 0277 std::optional<bool> isOptimized; 0278 std::optional<bool> isUserCode; 0279 std::optional<QString> version; 0280 std::optional<QString> symbolStatus; 0281 std::optional<QString> symbolFilePath; 0282 std::optional<QString> dateTimeStamp; 0283 std::optional<QString> addressRange; 0284 0285 Module() = default; 0286 Module(const QJsonObject &body); 0287 }; 0288 0289 struct ModulesInfo { 0290 QList<Module> modules; 0291 std::optional<int> totalModules; 0292 0293 ModulesInfo() = default; 0294 ModulesInfo(const QJsonObject &body); 0295 }; 0296 0297 struct ModuleEvent { 0298 QString reason; 0299 Module module; 0300 0301 ModuleEvent() = default; 0302 ModuleEvent(const QJsonObject &body); 0303 }; 0304 0305 struct StoppedEvent { 0306 QString reason; 0307 std::optional<QString> description; 0308 /** 0309 * @brief threadId The thread which was stopped. 0310 */ 0311 std::optional<int> threadId; 0312 /** 0313 * @brief preserverFocusHint A value of true hints to the frontend that 0314 * this event should not change the focus 0315 */ 0316 std::optional<bool> preserveFocusHint; 0317 /** 0318 * @brief text Additional information. 0319 */ 0320 std::optional<QString> text; 0321 /** 0322 * @brief allThreadsStopped if true, a DA can announce 0323 * that all threads have stopped. 0324 * - The client should use this information to enable that all threads can be 0325 * expanded to access their stacktraces. 0326 * - If the attribute is missing or false, only the thread with the given threadId 0327 * can be expanded. 0328 */ 0329 std::optional<bool> allThreadsStopped; 0330 /** 0331 * @brief hitBreakpointsIds ids of the breakpoints that triggered the event 0332 */ 0333 std::optional<QList<int>> hitBreakpointsIds; 0334 0335 StoppedEvent() = default; 0336 StoppedEvent(const QJsonObject &body); 0337 }; 0338 0339 struct ContinuedEvent { 0340 int threadId; 0341 /** 0342 * If 'allThreadsContinued' is true, a debug adapter can announce that all 0343 * threads have continued. 0344 */ 0345 std::optional<bool> allThreadsContinued; 0346 0347 ContinuedEvent() = default; 0348 ContinuedEvent(int threadId, bool allThreadsContinued); 0349 ContinuedEvent(const QJsonObject &body); 0350 }; 0351 0352 struct BreakpointEvent { 0353 QString reason; 0354 Breakpoint breakpoint; 0355 0356 BreakpointEvent() = default; 0357 BreakpointEvent(const QJsonObject &body); 0358 }; 0359 0360 struct Thread { 0361 int id; 0362 QString name; 0363 0364 Thread() = default; 0365 Thread(const QJsonObject &body); 0366 explicit Thread(const int id); 0367 0368 static QList<Thread> parseList(const QJsonArray &threads); 0369 }; 0370 0371 struct StackFrame { 0372 int id; 0373 QString name; 0374 std::optional<Source> source; 0375 int line; 0376 int column; 0377 std::optional<int> endLine; 0378 std::optional<int> endColumn; 0379 std::optional<bool> canRestart; 0380 std::optional<QString> instructionPointerReference; 0381 std::optional<int> moduleId_int; 0382 std::optional<QString> moduleId_str; 0383 std::optional<QString> presentationHint; 0384 0385 StackFrame() = default; 0386 StackFrame(const QJsonObject &body); 0387 }; 0388 0389 struct StackTraceInfo { 0390 QList<StackFrame> stackFrames; 0391 std::optional<int> totalFrames; 0392 0393 StackTraceInfo() = default; 0394 StackTraceInfo(const QJsonObject &body); 0395 }; 0396 0397 struct Scope { 0398 QString name; 0399 std::optional<QString> presentationHint; 0400 int variablesReference; 0401 std::optional<int> namedVariables; 0402 std::optional<int> indexedVariables; 0403 std::optional<bool> expensive; 0404 std::optional<Source> source; 0405 std::optional<int> line; 0406 std::optional<int> column; 0407 std::optional<int> endLine; 0408 std::optional<int> endColumn; 0409 0410 Scope() = default; 0411 Scope(const QJsonObject &body); 0412 Scope(int variablesReference, QString name); 0413 0414 static QList<Scope> parseList(const QJsonArray &scopes); 0415 }; 0416 0417 struct Variable { 0418 enum Type { Indexed = 1, Named = 2, Both = 3 }; 0419 0420 QString name; 0421 QString value; 0422 std::optional<QString> type; 0423 /** 0424 * @brief evaluateName Optional evaluatable name of tihs variable which can be 0425 * passed to the EvaluateRequest to fetch the variable's value 0426 */ 0427 std::optional<QString> evaluateName; 0428 /** 0429 * @brief variablesReference if > 0, its children can be retrieved by VariablesRequest 0430 */ 0431 int variablesReference; 0432 /** 0433 * @brief namedVariables number of named child variables 0434 */ 0435 std::optional<int> namedVariables; 0436 /** 0437 * @brief indexedVariables number of indexed child variables 0438 */ 0439 std::optional<int> indexedVariables; 0440 /** 0441 * @brief memoryReference optional memory reference for the variable if the 0442 * variable represents executable code, such as a function pointer. 0443 * Requires 'supportsMemoryReferences' 0444 */ 0445 std::optional<QString> memoryReference; 0446 0447 /** 0448 * the value has changed since the last time 0449 */ 0450 std::optional<bool> valueChanged; 0451 0452 Variable() = default; 0453 Variable(const QJsonObject &body); 0454 Variable(const QString &name, const QString &value, const int reference = 0); 0455 0456 static QList<Variable> parseList(const QJsonArray &variables); 0457 }; 0458 0459 struct EvaluateInfo { 0460 QString result; 0461 std::optional<QString> type; 0462 int variablesReference; 0463 std::optional<int> namedVariables; 0464 std::optional<int> indexedVariables; 0465 std::optional<QString> memoryReference; 0466 0467 EvaluateInfo(); 0468 EvaluateInfo(const QJsonObject &body); 0469 }; 0470 0471 struct GotoTarget { 0472 int id; 0473 QString label; 0474 int line; 0475 std::optional<int> column; 0476 std::optional<int> endLine; 0477 std::optional<int> endColumn; 0478 std::optional<QString> instructionPointerReference; 0479 0480 GotoTarget() = default; 0481 GotoTarget(const QJsonObject &body); 0482 0483 static QList<GotoTarget> parseList(const QJsonArray &variables); 0484 }; 0485 0486 }