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;
108
109 bool pauseAtNextOpportunity() const override;
110
114
115private:
116 // requires lock to be held
117 void pauseAndWait(PauseReason reason);
118 bool reallyHitTheBreakPoint(QV4::Function *function, const QString &filename, int linenr);
119 struct ExecutableLine {
120 int line;
121 int functionStart; // first line of the function or binding it belongs to
122 friend bool operator==(const ExecutableLine &a, const ExecutableLine &b)
123 {
124 return a.line == b.line && a.functionStart == b.functionStart;
125 }
126 friend bool operator<(const ExecutableLine &a, const ExecutableLine &b)
127 {
128 return a.line < b.line || (a.line == b.line && a.functionStart < b.functionStart);
129 }
130 };
131 struct ExecutableLines {
132 QList<ExecutableLine> lines; // the lines that carry code, sorted
133 QList<int> functionStarts; // sorted
134 };
135 static ExecutableLines collectExecutableLines(
136 const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit);
137 static int firstLineAtOrAfter(const ExecutableLines &executable, int requestedLine);
138 const ExecutableLines &executableLines(QV4::Function *function);
139 void pruneExecutableLines();
140 void runInEngine_havingLock(QV4DebugJob *job);
141 void runJobUnpaused();
142
143 QV4::ExecutionEngine *m_engine;
144 QV4::CppStackFrame *m_currentFrame = 0;
145 QMutex m_lock;
146 QWaitCondition m_runningCondition;
147 State m_state;
148 Speed m_stepping;
149 bool m_pauseRequested;
150 bool m_haveBreakPoints;
151 bool m_breakPointsChanged = false;
152 bool m_breakOnThrow;
153
154 struct BreakPointData {
155 QString target; // as given by the client, possibly with a path
156 QString condition;
157 };
158 QHash<BreakPoint, BreakPointData> m_breakPoints;
159 struct UnitLines {
160 // Keeps another unit from reusing the address while it is cached. This is
161 // the base unit: pinning the executable unit would keep the engine from
162 // trimming it, so a reloaded ES module could come back stale. The type
163 // loader still keeps the type of a pinned unit, so units are only
164 // cached while their file has breakpoints.
165 QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit;
166 ExecutableLines lines;
167 };
168 QList<UnitLines> m_executableLines; // most recently used first
169 QV4::PersistentValue m_returnedValue;
170
171 QV4DebugJob *m_gatherSources;
172 QV4DebugJob *m_runningJob;
173 QV4DataCollector m_collector;
174 QWaitCondition m_jobIsRunning;
175};
176
177QT_END_NAMESPACE
178
179Q_DECLARE_METATYPE(QV4Debugger::PauseReason)
180Q_DECLARE_METATYPE(QV4Debugger*)
181
182#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
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 &)