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
qqmlenginedebugclient.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// Qt-Security score:significant
4
6#include <private/qqmldebugconnection_p.h>
7
9
21
22QPacket &operator>>(QPacket &ds, QQmlObjectData &data)
23{
24 ds >> data.url >> data.lineNumber >> data.columnNumber >> data.idString
25 >> data.objectName >> data.objectType >> data.objectId >> data.contextId
26 >> data.parentId;
27 return ds;
28}
29
39
40QPacket &operator>>(QPacket &ds, QQmlObjectProperty &data)
41{
42 qint32 type;
43 ds >> type >> data.name >> data.value >> data.valueTypeName
44 >> data.binding >> data.hasNotifySignal;
45 data.type = QQmlObjectProperty::Type(type);
46 return ds;
47}
48
49QQmlEngineDebugClient::QQmlEngineDebugClient(QQmlDebugConnection *connection) :
50 QQmlDebugClient(*new QQmlEngineDebugClientPrivate(connection))
51{
52}
53
54QQmlEngineDebugClientPrivate::QQmlEngineDebugClientPrivate(QQmlDebugConnection *connection) :
55 QQmlDebugClientPrivate (QLatin1String("QmlDebugger"), connection)
56{
57}
58
59
61 const QQmlEngineDebugPropertyReference &property, bool *success)
62{
63 qint32 id = -1;
64 *success = false;
65 if (state() == QQmlDebugClient::Enabled) {
66 id = getId();
67 QPacket ds(connection()->currentDataStreamVersion());
68 ds << QByteArray("WATCH_PROPERTY") << id << property.objectDebugId
69 << property.name.toUtf8();
70 sendMessage(ds.data());
71 *success = true;
72 }
73 return id;
74}
75
77 const QQmlEngineDebugContextReference &, const QString &, bool *success)
78{
79 *success = false;
80 qWarning("QQmlEngineDebugClient::addWatch(): Not implemented");
81 return -1;
82}
83
85 const QQmlEngineDebugObjectReference &object, const QString &expr,
86 bool *success)
87{
88 qint32 id = -1;
89 *success = false;
90 if (state() == QQmlDebugClient::Enabled) {
91 id = getId();
92 QPacket ds(connection()->currentDataStreamVersion());
93 ds << QByteArray("WATCH_EXPR_OBJECT") << id << object.debugId << expr;
94 sendMessage(ds.data());
95 *success = true;
96 }
97 return id;
98}
99
101 const QQmlEngineDebugObjectReference &object, bool *success)
102{
103 qint32 id = -1;
104 *success = false;
105 if (state() == QQmlDebugClient::Enabled) {
106 id = getId();
107 QPacket ds(connection()->currentDataStreamVersion());
108 ds << QByteArray("WATCH_OBJECT") << id << object.debugId;
109 sendMessage(ds.data());
110 *success = true;
111 }
112 return id;
113}
114
116 const QQmlEngineDebugFileReference &, bool *success)
117{
118 *success = false;
119 qWarning("QQmlEngineDebugClient::addWatch(): Not implemented");
120 return -1;
121}
122
123void QQmlEngineDebugClient::removeWatch(qint32 id, bool *success)
124{
125 *success = false;
126 if (state() == QQmlDebugClient::Enabled) {
127 QPacket ds(connection()->currentDataStreamVersion());
128 ds << QByteArray("NO_WATCH") << id;
129 sendMessage(ds.data());
130 *success = true;
131 }
132}
133
135{
136 Q_D(QQmlEngineDebugClient);
137 d->engines.clear();
138 qint32 id = -1;
139 *success = false;
140 if (state() == QQmlDebugClient::Enabled) {
141 id = getId();
142 QPacket ds(connection()->currentDataStreamVersion());
143 ds << QByteArray("LIST_ENGINES") << id;
144 sendMessage(ds.data());
145 *success = true;
146 }
147 return id;
148}
149
151 const QQmlEngineDebugEngineReference &engine, bool *success)
152{
153 Q_D(QQmlEngineDebugClient);
154 d->rootContext = QQmlEngineDebugContextReference();
155 qint32 id = -1;
156 *success = false;
157 if (state() == QQmlDebugClient::Enabled && engine.debugId != -1) {
158 id = getId();
159 QPacket ds(connection()->currentDataStreamVersion());
160 ds << QByteArray("LIST_OBJECTS") << id << engine.debugId;
161 sendMessage(ds.data());
162 *success = true;
163 }
164 return id;
165}
166
168 const QQmlEngineDebugObjectReference &object, bool *success)
169{
170 Q_D(QQmlEngineDebugClient);
171 d->object = QQmlEngineDebugObjectReference();
172 qint32 id = -1;
173 *success = false;
174 if (state() == QQmlDebugClient::Enabled && object.debugId != -1) {
175 id = getId();
176 QPacket ds(connection()->currentDataStreamVersion());
177 ds << QByteArray("FETCH_OBJECT") << id << object.debugId << false << true;
178 sendMessage(ds.data());
179 *success = true;
180 }
181 return id;
182}
183
185 const QString &file, qint32 lineNumber, qint32 columnNumber, bool *success)
186{
187 Q_D(QQmlEngineDebugClient);
188 d->objects.clear();
189 qint32 id = -1;
190 *success = false;
191 if (state() == QQmlDebugClient::Enabled) {
192 id = getId();
193 QPacket ds(connection()->currentDataStreamVersion());
194 ds << QByteArray("FETCH_OBJECTS_FOR_LOCATION") << id << file << lineNumber
195 << columnNumber << false << true;
196 sendMessage(ds.data());
197 *success = true;
198 }
199 return id;
200}
201
203 const QQmlEngineDebugObjectReference &object, bool *success)
204{
205 Q_D(QQmlEngineDebugClient);
206 d->object = QQmlEngineDebugObjectReference();
207 qint32 id = -1;
208 *success = false;
209 if (state() == QQmlDebugClient::Enabled && object.debugId != -1) {
210 id = getId();
211 QPacket ds(connection()->currentDataStreamVersion());
212 ds << QByteArray("FETCH_OBJECT") << id << object.debugId << true << true;
213 sendMessage(ds.data());
214 *success = true;
215 }
216 return id;
217}
218
220 qint32 lineNumber, qint32 columnNumber, bool *success)
221{
222 Q_D(QQmlEngineDebugClient);
223 d->objects.clear();
224 qint32 id = -1;
225 *success = false;
226 if (state() == QQmlDebugClient::Enabled) {
227 id = getId();
228 QPacket ds(connection()->currentDataStreamVersion());
229 ds << QByteArray("FETCH_OBJECTS_FOR_LOCATION") << id << file << lineNumber
230 << columnNumber << true << true;
231 sendMessage(ds.data());
232 *success = true;
233 }
234 return id;
235}
236
238 qint32 objectDebugId, const QString &expr, bool *success)
239{
240 Q_D(QQmlEngineDebugClient);
241 d->exprResult = QVariant();
242 qint32 id = -1;
243 *success = false;
244 if (state() == QQmlDebugClient::Enabled) {
245 id = getId();
246 QPacket ds(connection()->currentDataStreamVersion());
247 ds << QByteArray("EVAL_EXPRESSION") << id << objectDebugId << expr
248 << engines()[0].debugId;
249 sendMessage(ds.data());
250 *success = true;
251 }
252 return id;
253}
254
256 qint32 objectDebugId, const QString &expr, bool *success)
257{
258 Q_D(QQmlEngineDebugClient);
259 d->exprResult = QVariant();
260 qint32 id = -1;
261 *success = false;
262 if (state() == QQmlDebugClient::Enabled) {
263 id = getId();
264 QPacket ds(connection()->currentDataStreamVersion());
265 ds << QByteArray("EVAL_EXPRESSION") << id << objectDebugId << expr;
266 sendMessage(ds.data());
267 *success = true;
268 }
269 return id;
270}
271
273 qint32 objectDebugId,
274 const QString &propertyName,
275 const QVariant &bindingExpression,
276 bool isLiteralValue,
277 const QString &source, qint32 line,
278 bool *success)
279{
280 qint32 id = -1;
281 *success = false;
282 if (state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
283 id = getId();
284 QPacket ds(connection()->currentDataStreamVersion());
285 ds << QByteArray("SET_BINDING") << id << objectDebugId << propertyName
286 << bindingExpression << isLiteralValue << source << line;
287 sendMessage(ds.data());
288 *success = true;
289 }
290 return id;
291}
292
294 qint32 objectDebugId,
295 const QString &propertyName,
296 bool *success)
297{
298 qint32 id = -1;
299 *success = false;
300 if (state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
301 id = getId();
302 QPacket ds(connection()->currentDataStreamVersion());
303 ds << QByteArray("RESET_BINDING") << id << objectDebugId << propertyName;
304 sendMessage(ds.data());
305 *success = true;
306 }
307 return id;
308}
309
311 qint32 objectDebugId, const QString &methodName,
312 const QString &methodBody, bool *success)
313{
314 qint32 id = -1;
315 *success = false;
316 if (state() == QQmlDebugClient::Enabled && objectDebugId != -1) {
317 id = getId();
318 QPacket ds(connection()->currentDataStreamVersion());
319 ds << QByteArray("SET_METHOD_BODY") << id << objectDebugId
320 << methodName << methodBody;
321 sendMessage(ds.data());
322 *success = true;
323 }
324 return id;
325}
326
329 bool simple)
330{
331 QQmlObjectData data;
332 ds >> data;
333 o.debugId = data.objectId;
334 o.className = data.objectType;
335 o.idString = data.idString;
336 o.name = data.objectName;
337 o.source.url = data.url;
338 o.source.lineNumber = data.lineNumber;
339 o.source.columnNumber = data.columnNumber;
340 o.contextDebugId = data.contextId;
341
342 if (simple)
343 return;
344
345 qint32 childCount;
346 bool recur;
347 ds >> childCount >> recur;
348
349 for (qint32 ii = 0; ii < childCount; ++ii) {
350 o.children.append(QQmlEngineDebugObjectReference());
351 decode(ds, o.children.last(), !recur);
352 }
353
354 qint32 propCount;
355 ds >> propCount;
356
357 for (qint32 ii = 0; ii < propCount; ++ii) {
359 ds >> data;
360 QQmlEngineDebugPropertyReference prop;
361 prop.objectDebugId = o.debugId;
362 prop.name = data.name;
363 prop.binding = data.binding;
364 prop.hasNotifySignal = data.hasNotifySignal;
365 prop.valueTypeName = data.valueTypeName;
366 switch (data.type) {
370 {
371 prop.value = data.value;
372 break;
373 }
375 {
377 obj.name = data.value.toString();
378 obj.className = prop.valueTypeName;
379 prop.value = QVariant::fromValue(obj);
380 break;
381 }
383 break;
384 }
385 o.properties << prop;
386 }
387}
388
390 QList<QQmlEngineDebugObjectReference> &o,
391 bool simple)
392{
393 qint32 count;
394 ds >> count;
395 for (qint32 i = 0; i < count; i++) {
397 decode(ds, obj, simple);
398 o << obj;
399 }
400}
401
403{
404 Q_D(const QQmlEngineDebugClient);
405 return d->engines;
406}
407
409{
410 Q_D(const QQmlEngineDebugClient);
411 return d->rootContext;
412}
413
415{
416 Q_D(const QQmlEngineDebugClient);
417 return d->object;
418}
419
421{
422 Q_D(const QQmlEngineDebugClient);
423 return d->objects;
424}
425
427{
428 Q_D(const QQmlEngineDebugClient);
429 return d->exprResult;
430}
431
433{
434 Q_D(const QQmlEngineDebugClient);
435 return d->valid;
436}
437
440{
441 ds >> c.name >> c.debugId;
442
443 qint32 contextCount;
444 ds >> contextCount;
445
446 for (qint32 ii = 0; ii < contextCount; ++ii) {
447 c.contexts.append(QQmlEngineDebugContextReference());
448 decode(ds, c.contexts.last());
449 }
450
451 qint32 objectCount;
452 ds >> objectCount;
453
454 for (qint32 ii = 0; ii < objectCount; ++ii) {
456 decode(ds, obj, true);
457
458 obj.contextDebugId = c.debugId;
459 c.objects << obj;
460 }
461}
462
463void QQmlEngineDebugClient::messageReceived(const QByteArray &data)
464{
465 Q_D(QQmlEngineDebugClient);
466 d->valid = false;
467 QPacket ds(connection()->currentDataStreamVersion(), data);
468
469 qint32 queryId;
470 QByteArray type;
471 ds >> type >> queryId;
472
473 //qDebug() << "QQmlEngineDebugPrivate::message()" << type;
474
475 if (type == "LIST_ENGINES_R") {
476 qint32 count;
477 ds >> count;
478
479 d->engines.clear();
480 for (qint32 ii = 0; ii < count; ++ii) {
482 ds >> eng.name;
483 ds >> eng.debugId;
484 d->engines << eng;
485 }
486 } else if (type == "LIST_OBJECTS_R") {
487 if (!ds.atEnd())
488 decode(ds, d->rootContext);
489
490 } else if (type == "FETCH_OBJECT_R") {
491 if (!ds.atEnd())
492 decode(ds, d->object, false);
493
494 } else if (type == "FETCH_OBJECTS_FOR_LOCATION_R") {
495 if (!ds.atEnd())
496 decode(ds, d->objects, false);
497
498 } else if (type == "EVAL_EXPRESSION_R") {;
499 ds >> d->exprResult;
500
501 } else if (type == "WATCH_PROPERTY_R") {
502 ds >> d->valid;
503
504 } else if (type == "WATCH_OBJECT_R") {
505 ds >> d->valid;
506
507 } else if (type == "WATCH_EXPR_OBJECT_R") {
508 ds >> d->valid;
509
510 } else if (type == "UPDATE_WATCH") {
511 qint32 debugId;
512 QByteArray name;
513 QVariant value;
514 ds >> debugId >> name >> value;
515 emit valueChanged(name, value);
516 return;
517
518 } else if (type == "OBJECT_CREATED") {
519 qint32 engineId;
520 qint32 objectId;
521 qint32 parentId;
522 ds >> engineId >> objectId >> parentId;
523 emit newObject(objectId);
524 return;
525 } else if (type == "SET_BINDING_R") {
526 ds >> d->valid;
527 } else if (type == "RESET_BINDING_R") {
528 ds >> d->valid;
529 } else if (type == "SET_METHOD_BODY_R") {
530 ds >> d->valid;
531 } else if (type == "NO_WATCH_R") {
532 ds >> d->valid;
533 }
534 emit result();
535}
536
537
539{
540 Q_D(QQmlEngineDebugClient);
541 return d->nextId++;
542}
543
544QT_END_NAMESPACE
545
546#include "moc_qqmlenginedebugclient_p.cpp"
qint32 addWatch(const QQmlEngineDebugContextReference &, const QString &, bool *success)
qint32 resetBindingForObject(qint32 objectDebugId, const QString &propertyName, bool *success)
void decode(QPacket &ds, QQmlEngineDebugContextReference &)
qint32 queryObjectsForLocationRecursive(const QString &file, qint32 lineNumber, qint32 columnNumber, bool *success)
qint32 queryExpressionResultBC(qint32 objectDebugId, const QString &expr, bool *success)
QList< QQmlEngineDebugObjectReference > objects() const
qint32 addWatch(const QQmlEngineDebugFileReference &, bool *success)
qint32 queryExpressionResult(qint32 objectDebugId, const QString &expr, bool *success)
qint32 queryRootContexts(const QQmlEngineDebugEngineReference &, bool *success)
qint32 addWatch(const QQmlEngineDebugObjectReference &, const QString &, bool *success)
void removeWatch(qint32 watch, bool *success)
qint32 queryAvailableEngines(bool *success)
void decode(QPacket &ds, QList< QQmlEngineDebugObjectReference > &o, bool simple)
qint32 addWatch(const QQmlEngineDebugObjectReference &, bool *success)
qint32 setMethodBody(qint32 objectDebugId, const QString &methodName, const QString &methodBody, bool *success)
qint32 addWatch(const QQmlEngineDebugPropertyReference &, bool *success)
qint32 setBindingForObject(qint32 objectDebugId, const QString &propertyName, const QVariant &bindingExpression, bool isLiteralValue, const QString &source, qint32 line, bool *success)
qint32 queryObjectRecursive(const QQmlEngineDebugObjectReference &, bool *success)
QQmlEngineDebugContextReference rootContext() const
void messageReceived(const QByteArray &) override
QQmlEngineDebugObjectReference object() const
qint32 queryObject(const QQmlEngineDebugObjectReference &, bool *success)
QList< QQmlEngineDebugEngineReference > engines() const
qint32 queryObjectsForLocation(const QString &file, qint32 lineNumber, qint32 columnNumber, bool *success)
void decode(QPacket &ds, QQmlEngineDebugObjectReference &, bool simple)
Combined button and popup list for selecting options.
QPacket & operator>>(QPacket &ds, QQmlObjectProperty &data)
QPacket & operator>>(QPacket &ds, QQmlObjectData &data)