| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef GDBMI_H |
| 6 | #define GDBMI_H |
| 7 | |
| 8 | #include <QMap> |
| 9 | #include <QVariantMap> |
| 10 | |
| 11 | namespace gdbmi { |
| 12 | // code is from https://github.com/martinribelotta/gdbfrontend |
| 13 | struct VariableChange { |
| 14 | QString name; |
| 15 | bool inScope; |
| 16 | bool typeChanged; |
| 17 | bool hasMore; |
| 18 | }; |
| 19 | |
| 20 | struct Variable { |
| 21 | QString name; |
| 22 | int numChild = 0; |
| 23 | QString value; |
| 24 | QString type; |
| 25 | QString threadId; |
| 26 | bool hasMore = false; |
| 27 | bool dynamic = false; |
| 28 | QString displayhint; |
| 29 | |
| 30 | bool isValid() const { return !name.isEmpty() && !value.isEmpty(); } |
| 31 | bool haveType() const { return !type.isEmpty(); } |
| 32 | bool isSimple() const { return isValid() && !haveType(); } |
| 33 | |
| 34 | static Variable parseMap(const QVariantMap &data); |
| 35 | }; |
| 36 | |
| 37 | struct Frame { |
| 38 | int level = -1; |
| 39 | QString func; |
| 40 | quint64 addr; |
| 41 | QHash<QString, QString> params; |
| 42 | QString file; |
| 43 | QString fullpath; |
| 44 | int line; |
| 45 | |
| 46 | bool isValid() const { return level != -1; } |
| 47 | |
| 48 | static Frame parseMap(const QVariantMap &data); |
| 49 | }; |
| 50 | |
| 51 | struct Breakpoint { |
| 52 | int number = -1; |
| 53 | QString type; |
| 54 | enum Disp_t { keep, del } disp; |
| 55 | bool enable; |
| 56 | quint64 addr; |
| 57 | QString func; |
| 58 | QString file; |
| 59 | QString fullname; |
| 60 | int line; |
| 61 | QList<QString> threadGroups; |
| 62 | int times; |
| 63 | QString originalLocation; |
| 64 | |
| 65 | bool isValid() const { return number != -1; } |
| 66 | |
| 67 | static Breakpoint parseMap(const QVariantMap &data); |
| 68 | }; |
| 69 | |
| 70 | struct Thread { |
| 71 | int id; |
| 72 | QString targetId; |
| 73 | QString details; |
| 74 | QString name; |
| 75 | enum State_t { Unknown, Stopped, Running } state; |
| 76 | Frame frame; |
| 77 | int core; |
| 78 | |
| 79 | static Thread parseMap(const QVariantMap &data); |
| 80 | }; |
| 81 | |
| 82 | struct AsyncContext { |
| 83 | enum class Reason { |
| 84 | Unknown, |
| 85 | breakpointHhit, // breakpoint Hit |
| 86 | watchpointTrigger, |
| 87 | readWatchpointTrigger, |
| 88 | accessWatchpointTrigger, |
| 89 | functionFinished, // StepOut |
| 90 | locationReached, |
| 91 | watchpointScope, |
| 92 | endSteppingRange, // StepIn |
| 93 | exitedSignalled, |
| 94 | exited, |
| 95 | exitedNormally, |
| 96 | signalReceived, |
| 97 | solibEvent, |
| 98 | fork, |
| 99 | vfork, |
| 100 | syscallEntry, |
| 101 | syscallReturn, |
| 102 | exec, |
| 103 | }; |
| 104 | |
| 105 | Reason reason; |
| 106 | QString threadId; |
| 107 | int core; |
| 108 | Frame frame; |
| 109 | |
| 110 | static Reason textToReason(const QString &s); |
| 111 | static QString reasonToText(Reason r); |
| 112 | }; |
| 113 | |
| 114 | struct Library { |
| 115 | QString id; |
| 116 | QString targetName; |
| 117 | QString hostName; |
| 118 | QString symbolsLoaded; |
| 119 | QString threadGroup; |
| 120 | struct Ranges { |
| 121 | QString fromRange; |
| 122 | QString toRange; |
| 123 | } ranges; |
| 124 | |
| 125 | static Library parseMap(const QVariantMap& data); |
| 126 | }; |
| 127 | |
| 128 | struct Record{ |
| 129 | enum RecordType { |
| 130 | unknown, |
| 131 | notify, |
| 132 | result, |
| 133 | console, |
| 134 | log, |
| 135 | target, |
| 136 | promt, |
| 137 | program, |
| 138 | disassemble |
| 139 | }; |
| 140 | |
| 141 | RecordType type; |
| 142 | QString message; |
| 143 | QVariant payload; |
| 144 | int token; |
| 145 | |
| 146 | Record(RecordType t, const QString& msg, const QVariant &p, int tk) { |
| 147 | type = t; |
| 148 | message= msg; |
| 149 | payload = p; |
| 150 | token = tk; |
| 151 | } |
| 152 | |
| 153 | static Record parseRecord(const QString& outputText); |
| 154 | }; |
| 155 | |
| 156 | QString escapedText(const QString& s); |
| 157 | |
| 158 | } //namespace gdbmi |
| 159 | |
| 160 | #endif // GDBMI_H |
| 161 | |