lldbengine.h 7.07 KB
Newer Older
1
2
/****************************************************************************
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
5
6
7
8
9
10
11
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
16
17
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
27
28
29
30
31
32
33
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#ifndef DEBUGGER_LLDBENGINE
#define DEBUGGER_LLDBENGINE

34
35
36
#include <debugger/debuggerengine.h>
#include <debugger/disassembleragent.h>
#include <debugger/memoryagent.h>
37
#include <debugger/watchhandler.h>
38
#include <debugger/debuggertooltipmanager.h>
39

hjk's avatar
hjk committed
40
41
#include <utils/consoleprocess.h>

42
#include <QPointer>
43
44
#include <QProcess>
#include <QQueue>
45
#include <QMap>
46
#include <QStack>
47
48
49
50
51
52
53
54
55
#include <QVariant>


namespace Debugger {
namespace Internal {

class WatchData;
class GdbMi;

hjk's avatar
hjk committed
56
57
/* A debugger engine interfacing the LLDB debugger
 * using its Python interface.
58
59
60
61
62
63
64
65
66
 */

class LldbEngine : public DebuggerEngine
{
    Q_OBJECT

public:
    explicit LldbEngine(const DebuggerStartParameters &startParameters);
    ~LldbEngine();
67

68
69
70
71
72
73
74
75
76
private:
    // DebuggerEngine implementation
    void executeStep();
    void executeStepOut();
    void executeNext();
    void executeStepI();
    void executeNextI();

    void setupEngine();
Fawzi Mohamed's avatar
Fawzi Mohamed committed
77
    void startLldb();
78
79
80
81
    void setupInferior();
    void runEngine();
    void shutdownInferior();
    void shutdownEngine();
82
    void abortDebugger();
83
    void resetLocation();
84

85
    bool setToolTipExpression(TextEditor::TextEditorWidget *editorWidget,
hjk's avatar
hjk committed
86
        const DebuggerToolTipContext &);
87
88
89
90
91
92
93
94
95
96
97

    void continueInferior();
    void interruptInferior();

    void executeRunToLine(const ContextData &data);
    void executeRunToFunction(const QString &functionName);
    void executeJumpToLine(const ContextData &data);

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

98
99
    // This should be always the last call in a function.
    bool stateAcceptsBreakpointChanges() const;
100
    bool acceptsBreakpoint(Breakpoint bp) const;
101
102
103
    void insertBreakpoint(Breakpoint bp);
    void removeBreakpoint(Breakpoint bp);
    void changeBreakpoint(Breakpoint bp);
104
105
106
107
108
109
110
111
112

    void assignValueInDebugger(const WatchData *data,
        const QString &expr, const QVariant &value);
    void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);

    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();
    void requestModuleSymbols(const QString &moduleName);
    void reloadModules();
113
    void reloadRegisters();
114
    void reloadSourceFiles() {}
115
    void reloadFullStack();
116
    void fetchDisassembler(Internal::DisassemblerAgent *);
117
    void refreshDisassembly(const GdbMi &data);
118
119
120
121

    bool supportsThreads() const { return true; }
    bool isSynchronous() const { return true; }
    void updateWatchData(const WatchData &data, const WatchUpdateFlags &flags);
hjk's avatar
hjk committed
122
    void setRegisterValue(const QByteArray &name, const QString &value);
123
124
125
126

    void fetchMemory(Internal::MemoryAgent *, QObject *, quint64 addr, quint64 length);
    void changeMemory(Internal::MemoryAgent *, QObject *, quint64 addr, const QByteArray &data);
    void refreshMemory(const GdbMi &data);
127
128
129
130
131
132
133
134

signals:
    void outputReady(const QByteArray &data);

private:
    QString errorMessage(QProcess::ProcessError error) const;
    bool hasCapability(unsigned cap) const;

135
136
137
138
139
140
141
142
    void handleLldbFinished(int, QProcess::ExitStatus status);
    void handleLldbError(QProcess::ProcessError error);
    void readLldbStandardOutput();
    void readLldbStandardError();
    void handleResponse(const QByteArray &data);
    void updateAll();
    void updateLocals();
    void createFullBacktrace();
143
    void doUpdateLocals(UpdateParameters params);
144
145
    void handleContinuation(const GdbMi &data);

146
147
148
    void refreshAll(const GdbMi &all);
    void refreshThreads(const GdbMi &threads);
    void refreshStack(const GdbMi &stack);
149
150
151
    void refreshStackPosition(const GdbMi &position);
    void refreshStackTop(const GdbMi &position);
    void setStackPosition(int index);
152
    void refreshRegisters(const GdbMi &registers);
153
    void refreshLocals(const GdbMi &vars);
154
155
    void refreshTypeInfo(const GdbMi &typeInfo);
    void refreshState(const GdbMi &state);
156
    void refreshLocation(const GdbMi &location);
157
    void refreshModules(const GdbMi &modules);
158
    void refreshSymbols(const GdbMi &symbols);
159
    void refreshOutput(const GdbMi &output);
160
161
162
    void refreshAddedBreakpoint(const GdbMi &bkpts);
    void refreshChangedBreakpoint(const GdbMi &bkpts);
    void refreshRemovedBreakpoint(const GdbMi &bkpts);
163
    void showFullBacktrace(const GdbMi &data);
164

165
    typedef void (LldbEngine::*LldbCommandContinuation)();
166

167
168
169
170
    void handleListLocals(const QByteArray &response);
    void handleListModules(const QByteArray &response);
    void handleListSymbols(const QByteArray &response);
    void handleBreakpointsSynchronized(const QByteArray &response);
171
    void updateBreakpointData(const GdbMi &bkpt, bool added);
172
173
    void handleUpdateStack(const QByteArray &response);
    void handleUpdateThreads(const QByteArray &response);
174

175
    void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result);
Fawzi Mohamed's avatar
Fawzi Mohamed committed
176

177
178
    void handleChildren(const WatchData &data0, const GdbMi &item,
        QList<WatchData> *list);
hjk's avatar
hjk committed
179

180
    void runCommand(const DebuggerCommand &cmd);
181
    void debugLastCommand();
182
    DebuggerCommand m_lastDebuggableCommand;
183
184
185
186

    QByteArray m_inbuffer;
    QString m_scriptFileName;
    QProcess m_lldbProc;
187
    QString m_lldbCmd;
188
189
190

    // FIXME: Make generic.
    int m_lastAgentId;
hjk's avatar
hjk committed
191
    int m_lastToken;
192
    int m_continueAtNextSpontaneousStop;
193
194
195
    QMap<QPointer<DisassemblerAgent>, int> m_disassemblerAgents;
    QMap<QPointer<MemoryAgent>, int> m_memoryAgents;
    QHash<int, QPointer<QObject> > m_memoryAgentTokens;
hjk's avatar
hjk committed
196
197
198
199
200
201
202

    // Console handling.
    Q_SLOT void stubError(const QString &msg);
    Q_SLOT void stubExited();
    Q_SLOT void stubStarted();
    bool prepareCommand();
    Utils::ConsoleProcess m_stubProc;
203
204
205
206
207
208
};

} // namespace Internal
} // namespace Debugger

#endif // DEBUGGER_LLDBENGINE