Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qv4debuggeragent.cpp
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
4#include "qv4debuggeragent.h"
5#include "qv4debugservice.h"
6#include "qv4datacollector.h"
7
8#include <QtCore/qjsonobject.h>
9#include <QtCore/qjsonarray.h>
10
12
14{
15 for (QV4Debugger *debugger : m_debuggers) {
16 if (debugger->state() == QV4Debugger::Paused)
17 return debugger;
18 }
19 return nullptr;
20}
21
23{
24 // "running" means none of the engines are paused.
25 return pausedDebugger() == nullptr;
26}
27
29{
30 Q_UNUSED(reason);
31
32 debugger->collector()->clear();
33
34 QJsonObject event, body, script;
35 event.insert(QStringLiteral("type"), QStringLiteral("event"));
36
37 switch (reason) {
41 event.insert(QStringLiteral("event"), QStringLiteral("break"));
42 QV4::CppStackFrame *frame = debugger->engine()->currentStackFrame;
43 if (!frame)
44 break;
45
46 body.insert(QStringLiteral("invocationText"), frame->function());
47 body.insert(QStringLiteral("sourceLine"), qAbs(frame->lineNumber()) - 1);
48// if (frame->column > 0)
49// body.insert(QStringLiteral("sourceColumn"), frame->column);
50 QJsonArray breakPoints;
51 foreach (int breakPointId, breakPointIds(frame->source(), frame->lineNumber()))
52 breakPoints.push_back(breakPointId);
53 body.insert(QStringLiteral("breakpoints"), breakPoints);
54 script.insert(QStringLiteral("name"), frame->source());
55 } break;
57 // TODO: complete this!
58 event.insert(QStringLiteral("event"), QStringLiteral("exception"));
59 break;
60 }
61
62 if (!script.isEmpty())
63 body.insert(QStringLiteral("script"), script);
64 if (!body.isEmpty())
65 event.insert(QStringLiteral("body"), body);
66 m_debugService->send(event);
67}
68
70{
71 Q_ASSERT(!m_debuggers.contains(debugger));
72 m_debuggers << debugger;
73
74 debugger->setBreakOnThrow(m_breakOnThrow);
75
76 for (const BreakPoint &breakPoint : std::as_const(m_breakPoints))
77 if (breakPoint.enabled)
78 debugger->addBreakPoint(breakPoint.fileName, breakPoint.lineNr, breakPoint.condition);
79
83}
84
86{
87 m_debuggers.removeAll(debugger);
90}
91
93{
94 return m_debuggers;
95}
96
98{
99 m_debuggers.removeAll(static_cast<QV4Debugger *>(debugger));
100}
101
103{
104 debugger->pause();
105}
106
108{
109 for (QV4Debugger *debugger : m_debuggers)
111}
112
114{
115 for (QV4Debugger *debugger : m_debuggers)
116 if (debugger->state() == QV4Debugger::Paused)
118}
119
121{
122 if (enabled) {
123 for (QV4Debugger *debugger : std::as_const(m_debuggers))
124 debugger->addBreakPoint(fileName, lineNumber, condition);
125 }
126
127 const int id = ++m_lastBreakPointId;
128 m_breakPoints.insert(id, BreakPoint(fileName, lineNumber, enabled, condition));
129 return id;
130}
131
133{
134 BreakPoint breakPoint = m_breakPoints.value(id);
135 if (!breakPoint.isValid())
136 return;
137
138 m_breakPoints.remove(id);
139
140 if (breakPoint.enabled)
141 for (QV4Debugger *debugger : std::as_const(m_debuggers))
142 debugger->removeBreakPoint(breakPoint.fileName, breakPoint.lineNr);
143}
144
146{
147 for (auto it = m_breakPoints.keyBegin(), end = m_breakPoints.keyEnd(); it != end; ++it)
149}
150
152{
153 BreakPoint &breakPoint = m_breakPoints[id];
154 if (!breakPoint.isValid() || breakPoint.enabled == onoff)
155 return;
156 breakPoint.enabled = onoff;
157
158 for (QV4Debugger *debugger : std::as_const(m_debuggers)) {
159 if (onoff)
160 debugger->addBreakPoint(breakPoint.fileName, breakPoint.lineNr, breakPoint.condition);
161 else
162 debugger->removeBreakPoint(breakPoint.fileName, breakPoint.lineNr);
163 }
164}
165
167{
169
170 for (QHash<int, BreakPoint>::const_iterator i = m_breakPoints.begin(), ei = m_breakPoints.end(); i != ei; ++i)
171 if (i->lineNr == lineNumber && fileName.endsWith(i->fileName))
172 ids.push_back(i.key());
173
174 return ids;
175}
176
178{
179 if (onoff != m_breakOnThrow) {
180 m_breakOnThrow = onoff;
181 for (QV4Debugger *debugger : std::as_const(m_debuggers))
182 debugger->setBreakOnThrow(onoff);
183 }
184}
185
187{
188 for (QV4Debugger *debugger : std::as_const(m_debuggers))
189 debugger->clearPauseRequest();
190}
191
193
194#include "moc_qv4debuggeragent.cpp"
\inmodule QtCore
Definition qhash.h:1135
key_iterator keyEnd() const noexcept
Definition qhash.h:1211
bool remove(const Key &key)
Removes the item that has the key from the hash.
Definition qhash.h:956
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
Definition qhash.h:1202
key_iterator keyBegin() const noexcept
Definition qhash.h:1210
T value(const Key &key) const noexcept
Definition qhash.h:1044
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
Definition qhash.h:1206
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1283
\inmodule QtCore\reentrant
Definition qjsonarray.h:18
void push_back(const QJsonValue &t)
This function is provided for STL compatibility.
Definition qjsonarray.h:206
\inmodule QtCore\reentrant
Definition qjsonobject.h:20
iterator insert(const QString &key, const QJsonValue &value)
Inserts a new item with the key key and a value of value.
bool isEmpty() const
Returns true if the object is empty.
Definition qlist.h:74
qsizetype removeAll(const AT &t)
Definition qlist.h:575
\inmodule QtCore
Definition qobject.h:90
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
void send(QJsonObject v4Payload)
void setBreakOnThrow(bool onoff)
QV4Debugger * pausedDebugger() const
const QList< QV4Debugger * > & debuggers()
QList< int > breakPointIds(const QString &fileName, int lineNumber) const
void handleDebuggerDeleted(QObject *debugger)
int addBreakPoint(const QString &fileName, int lineNumber, bool enabled=true, const QString &condition=QString())
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)
void debuggerPaused(QV4Debugger *self, QV4Debugger::PauseReason reason)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
@ QueuedConnection
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
GLenum condition
GLuint GLuint end
GLenum GLenum GLsizei const GLuint * ids
GLenum GLuint id
[7]
GLenum GLenum GLsizei const GLuint GLboolean enabled
struct _cl_event * event
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
static DebuggerProgram debugger
#define Q_UNUSED(x)
myObject disconnect()
[26]
QFrame frame
[0]
bool contains(const AT &t) const noexcept
Definition qlist.h:44