gdbengine.h 13.3 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
** If you are unsure which license is appropriate for your use, please
26
** contact the sales department at http://www.qtsoftware.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
#ifndef DEBUGGER_GDBENGINE_H
#define DEBUGGER_GDBENGINE_H

33
34
#include "idebuggerengine.h"
#include "gdbmi.h"
35
#include "outputcollector.h"
36
#include "watchutils.h"
37

38
39
#include <consoleprocess.h>

con's avatar
con committed
40
41
42
43
44
45
#include <QtCore/QByteArray>
#include <QtCore/QHash>
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QProcess>
#include <QtCore/QPoint>
46
#include <QtCore/QTextCodec>
47
#include <QtCore/QTime>
con's avatar
con committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <QtCore/QVariant>

QT_BEGIN_NAMESPACE
class QAction;
class QAbstractItemModel;
class QWidget;
QT_END_NAMESPACE

namespace Debugger {
namespace Internal {

class DebuggerManager;
class IDebuggerManagerAccessForEngines;
class GdbResultRecord;
class GdbMi;

class WatchData;
class BreakpointData;

67
enum DebuggingHelperState
con's avatar
con committed
68
{
69
70
71
72
    DebuggingHelperUninitialized,
    DebuggingHelperLoadTried,
    DebuggingHelperAvailable,
    DebuggingHelperUnavailable,
con's avatar
con committed
73
74
};

hjk's avatar
hjk committed
75

con's avatar
con committed
76
77
78
79
80
81
82
83
84
class GdbEngine : public IDebuggerEngine
{
    Q_OBJECT

public:
    GdbEngine(DebuggerManager *parent);
    ~GdbEngine();

signals:
85
86
    void gdbInputAvailable(int channel, const QString &msg);
    void gdbOutputAvailable(int channel, const QString &msg);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
87
    void applicationOutputAvailable(const QString &output);
con's avatar
con committed
88
89
90
91
92
93
94
95
96
97
98
99

private:
    //
    // IDebuggerEngine implementation
    //
    void stepExec();
    void stepOutExec();
    void nextExec();
    void stepIExec();
    void nextIExec();

    void shutdown();
100
    void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos);
101
    bool startDebugger(const QSharedPointer<DebuggerStartParameters> &sp);
con's avatar
con committed
102
    void exitDebugger();
103
    void detachDebugger();
con's avatar
con committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

    void continueInferior();
    void interruptInferior();

    void runToLineExec(const QString &fileName, int lineNumber);
    void runToFunctionExec(const QString &functionName);
    void jumpToLineExec(const QString &fileName, int lineNumber);

    void activateFrame(int index);
    void selectThread(int index);

    Q_SLOT void attemptBreakpointSynchronization();

    void assignValueInDebugger(const QString &expr, const QString &value);
    void executeDebuggerCommand(const QString & command);
119
    void watchPoint(const QPoint &);
con's avatar
con committed
120
121
122

    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();
123
    virtual QList<Symbol> moduleSymbols(const QString &moduleName);
con's avatar
con committed
124

125
126
    Q_SLOT void setDebugDebuggingHelpers(const QVariant &on);
    Q_SLOT void setUseDebuggingHelpers(const QVariant &on);
127

con's avatar
con committed
128
129
130
    //
    // Own stuff
    //
131

con's avatar
con committed
132
    int currentFrame() const;
133
    //QString currentWorkingDirectory() const { return m_pwd; }
con's avatar
con committed
134
135
136

    bool supportsThreads() const;

137
138
    void initializeConnections();
    void initializeVariables();
con's avatar
con committed
139
140
141
142
143
144
    QString fullName(const QString &fileName);
    // get one usable name out of these, try full names first
    QString fullName(const QStringList &candidates);

    void handleResult(const GdbResultRecord &, int type, const QVariant &);

145
146
147
148
149
150
public: // otherwise the Qt flag macros are unhappy
    enum GdbCommandFlag {
        NoFlags = 0,
        NeedsStop = 1,
        Discardable = 2,
        RebuildModel = 4,
151
152
        WatchUpdate = Discardable|RebuildModel,
        EmbedToken = 8
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    };
    Q_DECLARE_FLAGS(GdbCommandFlags, GdbCommandFlag)
private:

    typedef void (GdbEngine::*GdbCommandCallback)(const GdbResultRecord &record, const QVariant &cookie);

    struct GdbCommand
    {
        GdbCommand() : flags(0), callback(0), callbackName(0) {}

        int flags;
        GdbCommandCallback callback;
        const char *callbackName;
        QString command;
        QVariant cookie;
168
        QTime postTime;
169
170
    };

con's avatar
con committed
171
172
173
174
    // type and cookie are sender-internal data, opaque for the "event
    // queue". resultNeeded == true increments m_pendingResults on
    // send and decrements on receipt, effectively preventing 
    // watch model updates before everything is finished.
175
    void flushCommand(GdbCommand &cmd);
176
    void postCommand(const QString &command,
177
178
179
180
                     GdbCommandFlags flags,
                     GdbCommandCallback callback = 0,
                     const char *callbackName = 0,
                     const QVariant &cookie = QVariant());
181
    void postCommand(const QString &command,
182
183
184
                     GdbCommandCallback callback = 0,
                     const char *callbackName = 0,
                     const QVariant &cookie = QVariant());
con's avatar
con committed
185
186
187
188
189
190
191
192
193

    void setTokenBarrier();

    void updateLocals();

private slots:
    void gdbProcError(QProcess::ProcessError error);
    void readGdbStandardOutput();
    void readGdbStandardError();
194
195
    void readUploadStandardOutput();
    void readUploadStandardError();
196
    void readDebugeeOutput(const QByteArray &data);
197
198
    void stubStarted();
    void stubError(const QString &msg);
199
    void uploadProcError(QProcess::ProcessError error);
con's avatar
con committed
200
201
202

private:
    int terminationIndex(const QByteArray &buffer, int &length);
203
    void handleResponse(const QByteArray &buff);
204
205
206
    void handleStart(const GdbResultRecord &response, const QVariant &);
    void handleAttach(const GdbResultRecord &, const QVariant &);
    void handleStubAttached(const GdbResultRecord &, const QVariant &);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
207
    void handleAqcuiredInferior();
208
    void handleAsyncOutput2(const GdbResultRecord &, const QVariant &cookie);
con's avatar
con committed
209
210
211
    void handleAsyncOutput2(const GdbMi &data);
    void handleAsyncOutput(const GdbMi &data);
    void handleResultRecord(const GdbResultRecord &response);
212
    void handleFileExecAndSymbols(const GdbResultRecord &response, const QVariant &);
hjk's avatar
hjk committed
213
    void handleExecContinue(const GdbResultRecord &response, const QVariant &);
214
215
216
217
218
219
220
221
222
223
224
    void handleExecRun(const GdbResultRecord &response, const QVariant &);
    void handleExecJumpToLine(const GdbResultRecord &response, const QVariant &);
    void handleExecRunToFunction(const GdbResultRecord &response, const QVariant &);
    void handleInfoShared(const GdbResultRecord &response, const QVariant &);
    void handleInfoProc(const GdbResultRecord &response, const QVariant &);
    void handleInfoThreads(const GdbResultRecord &response, const QVariant &);
    void handleShowVersion(const GdbResultRecord &response, const QVariant &);
    void handleQueryPwd(const GdbResultRecord &response, const QVariant &);
    void handleQuerySources(const GdbResultRecord &response, const QVariant &);
    void handleTargetCore(const GdbResultRecord &, const QVariant &);
    void handleExit(const GdbResultRecord &, const QVariant &);
225
226
    void handleSetTargetAsync(const GdbResultRecord &, const QVariant &);
    void handleTargetRemote(const GdbResultRecord &, const QVariant &);
227
    void handleWatchPoint(const GdbResultRecord &, const QVariant &);
hjk's avatar
hjk committed
228
    void debugMessage(const QString &msg);
229
    bool showToolTip();
con's avatar
con committed
230

231
232
    const bool m_dumperInjectionLoad;

233
234
235
236
    OutputCollector m_outputCollector;
    QTextCodec *m_outputCodec;
    QTextCodec::ConverterState m_outputCodecState;

con's avatar
con committed
237
238
239
    QByteArray m_inbuffer;

    QProcess m_gdbProc;
240
    QProcess m_uploadProc;
con's avatar
con committed
241

242
243
    Core::Utils::ConsoleProcess m_stubProc;

244
    QHash<int, GdbCommand> m_cookieForToken;
con's avatar
con committed
245
246
247
248
249
250
251
252
253
254
255
256
    QHash<int, QByteArray> m_customOutputForToken;

    QByteArray m_pendingConsoleStreamOutput;
    QByteArray m_pendingTargetStreamOutput;
    QByteArray m_pendingLogStreamOutput;

    // contains the first token number for the current round
    // of evaluation. Responses with older tokens are considers
    // out of date and discarded.
    int m_oldestAcceptableToken;

    int m_gdbVersion; // 6.8.0 is 680
hjk's avatar
hjk committed
257
    int m_gdbBuildVersion; // MAC only? 
con's avatar
con committed
258
259

    // awful hack to keep track of used files
260
261
    QMap<QString, QString> m_shortToFullName;
    QMap<QString, QString> m_fullToShortName;
con's avatar
con committed
262
263
264
265

    //
    // Breakpoint specific stuff
    //
266
    void handleBreakList(const GdbResultRecord &record, const QVariant &);
con's avatar
con committed
267
    void handleBreakList(const GdbMi &table);
268
269
270
271
272
    void handleBreakIgnore(const GdbResultRecord &record, const QVariant &cookie);
    void handleBreakInsert(const GdbResultRecord &record, const QVariant &cookie);
    void handleBreakInsert1(const GdbResultRecord &record, const QVariant &cookie);
    void handleBreakCondition(const GdbResultRecord &record, const QVariant &cookie);
    void handleBreakInfo(const GdbResultRecord &record, const QVariant &cookie);
con's avatar
con committed
273
274
275
276
277
278
279
280
281
    void extractDataFromInfoBreak(const QString &output, BreakpointData *data);
    void breakpointDataFromOutput(BreakpointData *data, const GdbMi &bkpt);
    void sendInsertBreakpoint(int index);


    //
    // Disassembler specific stuff
    //
    void handleDisassemblerList(const GdbResultRecord &record,
282
        const QVariant &cookie);
con's avatar
con committed
283
284
285
286
287
288
289
290
    void reloadDisassembler();
    QString m_address;


    //
    // Modules specific stuff
    //
    void reloadModules();
291
    void handleModulesList(const GdbResultRecord &record, const QVariant &);
con's avatar
con committed
292
293
294
295
296


    //
    // Register specific stuff
    // 
297
    Q_SLOT void reloadRegisters();
298
299
    void handleRegisterListNames(const GdbResultRecord &record, const QVariant &);
    void handleRegisterListValues(const GdbResultRecord &record, const QVariant &);
con's avatar
con committed
300

301
302
303
304
    //
    // Source file specific stuff
    // 
    void reloadSourceFiles();
con's avatar
con committed
305
306
307
308

    //
    // Stack specific stuff
    // 
309
310
311
    void handleStackListFrames(const GdbResultRecord &record, const QVariant &cookie);
    void handleStackSelectThread(const GdbResultRecord &, const QVariant &);
    void handleStackListThreads(const GdbResultRecord &record, const QVariant &cookie);
312
313
    Q_SLOT void reloadStack();
    Q_SLOT void reloadFullStack();
con's avatar
con committed
314
315
316
317
318
319
320
321
322
323
324
325
326
327


    //
    // Tooltip specific stuff
    // 
    void sendToolTipCommand(const QString &command, const QString &cookie);


    //
    // Watch specific stuff
    //
    // FIXME: BaseClass. called to improve situation for a watch item
    void updateSubItem(const WatchData &data);

328
    void updateWatchData(const WatchData &data);
hjk's avatar
hjk committed
329
    void rebuildModel();
con's avatar
con committed
330
331
332
333
334
335
336

    void insertData(const WatchData &data);
    void sendWatchParameters(const QByteArray &params0);
    void createGdbVariable(const WatchData &data);

    void maybeHandleInferiorPidChanged(const QString &pid);

337
    void tryLoadDebuggingHelpers();
338
    void tryQueryDebuggingHelpers();
339
340
341
342
    Q_SLOT void recheckDebuggingHelperAvailability();
    void runDebuggingHelper(const WatchData &data, bool dumpChildren);
    void runDirectDebuggingHelper(const WatchData &data, bool dumpChildren);
    bool hasDebuggingHelperForType(const QString &type) const;
con's avatar
con committed
343
344

    void handleVarListChildren(const GdbResultRecord &record,
345
        const QVariant &cookie);
con's avatar
con committed
346
    void handleVarCreate(const GdbResultRecord &record,
347
348
        const QVariant &cookie);
    void handleVarAssign(const GdbResultRecord &, const QVariant &);
con's avatar
con committed
349
    void handleEvaluateExpression(const GdbResultRecord &record,
350
        const QVariant &cookie);
351
352
    //void handleToolTip(const GdbResultRecord &record,
    //    const QVariant &cookie);
353
    void handleQueryDebuggingHelper(const GdbResultRecord &record, const QVariant &);
354
    void handleDebuggingHelperValue1(const GdbResultRecord &record,
355
        const QVariant &cookie);
356
    void handleDebuggingHelperValue2(const GdbResultRecord &record,
357
        const QVariant &cookie);
358
    void handleDebuggingHelperValue3(const GdbResultRecord &record,
359
        const QVariant &cookie);
360
    void handleDebuggingHelperEditValue(const GdbResultRecord &record);
361
362
363
    void handleDebuggingHelperSetup(const GdbResultRecord &record, const QVariant &);
    void handleStackListLocals(const GdbResultRecord &record, const QVariant &);
    void handleStackListArguments(const GdbResultRecord &record, const QVariant &);
con's avatar
con committed
364
365
366
    void handleVarListChildrenHelper(const GdbMi &child,
        const WatchData &parent);
    void setWatchDataType(WatchData &data, const GdbMi &mi);
hjk's avatar
hjk committed
367
    void setLocals(const QList<GdbMi> &locals);
368
369
   
    bool startModeAllowsDumpers() const;
con's avatar
con committed
370
371
372

    int m_pendingRequests;

373
    QtDumperHelper m_dumperHelper;
con's avatar
con committed
374
    
375
    DebuggingHelperState m_debuggingHelperState;
con's avatar
con committed
376
377
378
379
    QList<GdbMi> m_currentFunctionArgs;
    QString m_currentFrame;
    QMap<QString, QString> m_varToType;

380
    bool m_autoContinue;
381
    bool m_waitingForFirstBreakpointToBeHit;
382
    bool m_modulesListOutdated;
383

384
    QList<GdbCommand> m_commandsToRunOnTemporaryBreak;
385

386
387
388
    DebuggerManager * const q;
    IDebuggerManagerAccessForEngines * const qq;
    // make sure to re-initialize new members in initializeVariables();
con's avatar
con committed
389
390
391
392
393
};

} // namespace Internal
} // namespace Debugger

394
395
Q_DECLARE_OPERATORS_FOR_FLAGS(Debugger::Internal::GdbEngine::GdbCommandFlags)

con's avatar
con committed
396
#endif // DEBUGGER_GDBENGINE_H