-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdebugmanager.h
229 lines (185 loc) · 5.83 KB
/
debugmanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#ifndef DEBUGMANAGER_H
#define DEBUGMANAGER_H
#include <QHash>
#include <QObject>
#include <functional>
namespace gdb {
struct VariableChange {
QString name;
bool inScope;
bool typeChanged;
bool hasMore;
};
struct Variable {
QString name;
int numChild = 0;
QString value;
QString type;
QString threadId;
bool hasMore = false;
bool dynamic = false;
QString displayhint;
bool isValid() const { return !name.isEmpty() && !value.isEmpty(); }
bool haveType() const { return !type.isEmpty(); }
bool isSimple() const { return isValid() && !haveType(); }
static Variable parseMap(const QVariantMap& data);
};
struct Frame {
int level = -1;
QString func;
quint64 addr;
QHash<QString, QString> params;
QString file;
QString fullpath;
int line;
bool isValid() const { return level != -1; }
static Frame parseMap(const QVariantMap& data);
};
struct Breakpoint {
int number = -1;
QString type;
enum Disp_t { keep, del } disp;
bool enable;
quint64 addr;
QString func;
QString file;
QString fullname;
int line;
QList<QString> threadGroups;
int times;
QString originalLocation;
bool isValid() const { return number != -1; }
static Breakpoint parseMap(const QVariantMap& data);
};
struct Thread {
int id;
QString targetId;
QString details;
QString name;
enum State_t { Unknown, Stopped, Running } state;
Frame frame;
int core;
static Thread parseMap(const QVariantMap& data);
};
struct AsyncContext {
enum class Reason {
Unknown,
breakpointHhit,
watchpointTrigger,
readWatchpointTrigger,
accessWatchpointTrigger,
functionFinished,
locationReached,
watchpointScope,
endSteppingRange,
exitedSignalled,
exited,
exitedNormally,
signalReceived,
solibEvent,
fork,
vfork,
syscallEntry,
syscallReturn,
exec,
} reason;
QString threadId;
int core;
Frame frame;
static Reason textToReason(const QString& s);
static QString reasonToText(Reason r);
};
}
class DebugManager : public QObject
{
Q_OBJECT
public:
enum class ResponseAction_t { Permanent, Temporal };
using ResponseHandler_t = std::function<void (const QVariant& v)>;
Q_PROPERTY(QString gdbCommand READ gdbCommand WRITE setGdbCommand)
Q_PROPERTY(bool remote READ isRemote)
Q_PROPERTY(bool gdbExecuting READ isGdbExecuting)
Q_PROPERTY(QStringList gdbArgs READ gdbArgs WRITE setGdbArgs)
Q_PROPERTY(bool inferiorRunning READ isInferiorRunning)
#ifdef Q_OS_WIN
Q_PROPERTY(QString sigintHelperCmd READ sigintHelperCmd WRITE setSigintHelperCmd)
#endif
static DebugManager *instance();
QStringList gdbArgs() const;
QString gdbCommand() const;
bool isRemote() const;
bool isGdbExecuting() const;
QList<gdb::Breakpoint> allBreakpoints() const;
QList<gdb::Breakpoint> breakpointsForFile(const QString& filePath) const;
gdb::Breakpoint breakpointById(int id) const;
gdb::Breakpoint breakpointByFileLine(const QString& path, int line) const;
#ifdef Q_OS_WIN
QString sigintHelperCmd() const;
#endif
bool isInferiorRunning() const;
public slots:
void execute();
void quit();
void command(const QString& cmd);
void commandAndResponse(const QString& cmd,
const ResponseHandler_t& handler,
ResponseAction_t action = ResponseAction_t::Temporal);
void breakRemove(int bpid);
void breakInsert(const QString& path);
void loadExecutable(const QString& file);
void launchRemote(const QString& remoteTarget);
void launchLocal();
void commandContinue();
void commandNext();
void commandStep();
void commandFinish();
void commandInterrupt();
void traceAddVariable(const QString& expr, const QString& name="-", int frame=-1);
void traceDelVariable(const QString& name);
void traceUpdateVariable(const QString& name);
void traceUpdateAll() { traceUpdateVariable("*"); }
void setGdbCommand(QString gdbCommand);
void setGdbArgs(QStringList gdbArgs);
const QMap<QString, gdb::Variable> &vatchVars() const;
#ifdef Q_OS_WIN
void setSigintHelperCmd(QString sigintHelperCmd);
#endif
signals:
void gdbProcessStarted();
void gdbProcessTerminated();
void started();
void terminated();
void gdbPromt();
void targetRemoteConnected();
void gdbError(const QString& msg);
void asyncRunning(const QString& thid);
void asyncStopped(const gdb::AsyncContext& ctx);
void updateThreads(int currentId, const QList<gdb::Thread>& threads);
void updateCurrentFrame(const gdb::Frame& frame);
void updateStackFrame(const QList<gdb::Frame>& stackFrames);
void updateLocalVariables(const QList<gdb::Variable>& variableList);
void breakpointInserted(const gdb::Breakpoint& bp);
void breakpointModified(const gdb::Breakpoint& bp);
void breakpointRemoved(const gdb::Breakpoint& bp);
void variableCreated(const gdb::Variable& v);
void variableDeleted(const gdb::Variable& v);
void variablesChanged(const QStringList& changedNames);
void result(int token, const QString& reason, const QVariant& results); // <token>^...
void streamConsole(const QString& text);
void streamTarget(const QString& text);
void streamGdb(const QString& text);
void streamDebugInternal(const QString& text);
private slots:
void processLine(const QString& line);
private:
explicit DebugManager(QObject *parent = nullptr);
virtual ~DebugManager();
struct Priv_t;
Priv_t *self;
};
Q_DECLARE_METATYPE(gdb::Variable)
Q_DECLARE_METATYPE(gdb::Frame)
Q_DECLARE_METATYPE(gdb::Breakpoint)
Q_DECLARE_METATYPE(gdb::Thread)
Q_DECLARE_METATYPE(gdb::AsyncContext)
#endif // DEBUGMANAGER_H