Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qv4debugger.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
5#ifndef QV4DEBUGGER_H
6#define QV4DEBUGGER_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
20#include <private/qv4debugging_p.h>
21#include <private/qv4function_p.h>
22#include <private/qv4context_p.h>
23#include <private/qv4persistent_p.h>
24#include <private/qv4executablecompilationunit_p.h>
25#include <private/qqmlrefcount_p.h>
26
27#include <QtCore/qmutex.h>
28#include <QtCore/qwaitcondition.h>
29
31
32class QV4DebugJob;
35{
37public:
43
44 enum State {
47 };
48
57
64
65 QV4Debugger(QV4::ExecutionEngine *engine);
66
67 QV4::ExecutionEngine *engine() const;
68 const QV4DataCollector *collector() const;
70
71 void pause();
72 void resume(Speed speed);
73
74 State state() const;
75
76 void addBreakPoint(const QString &fileName, int lineNumber,
77 const QString &condition = QString());
78 void removeBreakPoint(const QString &fileName, int lineNumber);
79
80 void setBreakOnThrow(bool onoff);
81
82 void clearPauseRequest();
83
84 // used for testing
92
93 QList<QV4::StackFrame> stackTrace(int frameLimit = -1) const;
95
96 QV4::Function *getFunction() const;
97 void runInEngine(QV4DebugJob *job);
98
99 int resolvedBreakpointLine(int requestedLine);
100
101 // compile-time interface
103
104 // execution hooks
106 void leavingFunction(const QV4::ReturnedValue &retVal) override;
107 void aboutToThrow() override;
109
110 bool pauseAtNextOpportunity() const override;
111
115
116private:
117 // requires lock to be held
118 void pauseAndWait(PauseReason reason);
119 bool reallyHitTheBreakPoint(QV4::Function *function, const QString &filename, int linenr);
120 struct ExecutableLine {
121 int line;
122 int functionStart; // first line of the function or binding it belongs to
123 friend bool operator==(const ExecutableLine &a, const ExecutableLine &b)
124 {
125 return a.line == b.line && a.functionStart == b.functionStart;
126 }
127 friend bool operator<(const ExecutableLine &a, const ExecutableLine &b)
128 {
129 return a.line < b.line || (a.line == b.line && a.functionStart < b.functionStart);
130 }
131 };
132 struct ExecutableLines {
133 QList<ExecutableLine> lines; // the lines that carry code, sorted
134 QList<int> functionStarts; // sorted
135 };
136 static ExecutableLines collectExecutableLines(
137 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit);
138 static int firstLineAtOrAfter(const ExecutableLines &executable, int requestedLine);
139 const ExecutableLines &executableLines(QV4::Function *function);
140 void pruneExecutableLines();
141 void runInEngine_havingLock(QV4DebugJob *job);
142 void runJobUnpaused();
143
144 QV4::ExecutionEngine *m_engine;
145 QV4::CppStackFrame *m_currentFrame = 0;
146 QMutex m_lock;
147 QWaitCondition m_runningCondition;
148 State m_state;
149 Speed m_stepping;
150 bool m_pauseRequested;
151 bool m_haveBreakPoints;
152 bool m_breakPointsChanged = false;
153 bool m_breakOnThrow;
154
155 struct BreakPointData {
156 QString target; // as given by the client, possibly with a path
157 QString condition;
158 };
159 QHash<BreakPoint, BreakPointData> m_breakPoints;
160 struct UnitLines {
161 // Keeps another unit from reusing the address while it is cached. This is
162 // the base unit: pinning the executable unit would keep the engine from
163 // trimming it, so a reloaded ES module could come back stale. The type
164 // loader still keeps the type of a pinned unit, so units are only
165 // cached while their file has breakpoints.
166 QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit;
167 ExecutableLines lines;
168 };
169 QList<UnitLines> m_executableLines; // most recently used first
170 QV4::PersistentValue m_returnedValue;
171
172 QV4DebugJob *m_gatherSources;
173 QV4DebugJob *m_runningJob;
174 QV4DataCollector m_collector;
175 QWaitCondition m_jobIsRunning;
176};
177
178QT_END_NAMESPACE
179
180Q_DECLARE_METATYPE(QV4Debugger::PauseReason)
181Q_DECLARE_METATYPE(QV4Debugger*)
182
183#endif // QV4DEBUGGER_H
void objectCreated(QJSEngine *, QObject *) override
void engineAboutToBeAdded(QJSEngine *) override
void messageReceived(const QByteArray &) override
void engineAboutToBeRemoved(QJSEngine *) override
QQmlDebugStatesDelegate * statesDelegate()
void send(QJsonObject v4Payload)
void engineAboutToBeRemoved(QJSEngine *engine) override
QV4DebuggerAgent debuggerAgent
void messageReceived(const QByteArray &) override
void stateAboutToBeChanged(State state) override
void signalEmitted(const QString &signal) override
void sendSomethingToSomebody(const char *type, int magicNumber=1)
void engineAdded(QJSEngine *engine) override
void selectFrame(int frameNr)
void setBreakOnThrow(bool onoff)
const QList< QV4Debugger * > & debuggers()
void handleDebuggerDeleted(QObject *debugger)
bool breakOnThrow() const
int addBreakPoint(const QString &fileName, int lineNumber, bool enabled=true, const QString &condition=QString())
QList< int > breakPointIds(QV4Debugger *debugger, const QString &fileName, int lineNumber) const
void addDebugger(QV4Debugger *debugger)
void removeDebugger(QV4Debugger *debugger)
void pause(QV4Debugger *debugger) const
void removeBreakPoint(int id)
void enableBreakPoint(int id, bool onoff)
void debuggerPaused(QV4Debugger *debugger, QV4Debugger::PauseReason reason)
qsizetype executableLinesCacheSize()
void maybeBreakAtInstruction() override
QV4::Function * getFunction() const
void enteringFunction() override
void scheduleJob()
void runInEngine(QV4DebugJob *job)
QList< QV4::Heap::ExecutionContext::ContextType > getScopeTypes(int frame=0) const
int resolvedBreakpointLine(int requestedLine)
QV4DataCollector * collector()
void removeBreakPoint(const QString &fileName, int lineNumber)
QV4::ExecutionEngine * engine() const
void resume(Speed speed)
void setBreakOnThrow(bool onoff)
bool pauseAtNextOpportunity() const override
void leavingFunction(const QV4::ReturnedValue &retVal) override
State state() const
ExecutionState currentExecutionState() const
QV4::Moth::DebugInstructionPass debugInstructionPass() const override
const QV4DataCollector * collector() const
QV4Debugger(QV4::ExecutionEngine *engine)
void aboutToThrow() override
void addBreakPoint(const QString &fileName, int lineNumber, const QString &condition=QString())
void clearPauseRequest()
QList< QV4::StackFrame > stackTrace(int frameLimit=-1) const
Combined button and popup list for selecting options.
Definition qjsvalue.h:24
QDataStream & operator>>(QDataStream &, QQmlEngineDebugServiceImpl::QQmlObjectProperty &)
QDataStream & operator>>(QDataStream &, QQmlEngineDebugServiceImpl::QQmlObjectData &)