From 3a0bb11d730390ce9fd64932f58269cfbe8c378e Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 30 Jan 2017 11:59:58 +0100 Subject: Separate SimpleCallData and CallData SimpleCallData doesn't need any loca variables, so move it into a separate CallData Heap object. This also allows getting rid of the manual markObjects() implementation for CallContext. Change-Id: I9014eb2f815d3e2fe63a951a9d126c38e8aaa0a3 Reviewed-by: Simon Hausmann --- .../qmltooling/qmldbg_debugger/qv4datacollector.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp') diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index a4bad5618b..225a1fa27d 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -55,11 +55,11 @@ QT_BEGIN_NAMESPACE -QV4::CallContext *QV4DataCollector::findContext(int frame) +QV4::SimpleCallContext *QV4DataCollector::findContext(int frame) { QV4::ExecutionContext *ctx = engine()->currentContext; while (ctx) { - QV4::CallContext *cCtxt = ctx->asCallContext(); + QV4::SimpleCallContext *cCtxt = ctx->asSimpleCallContext(); if (cCtxt && cCtxt->d()->v4Function) { if (frame < 1) return cCtxt; @@ -71,7 +71,7 @@ QV4::CallContext *QV4DataCollector::findContext(int frame) return 0; } -QV4::Heap::CallContext *QV4DataCollector::findScope(QV4::ExecutionContext *ctxt, int scope) +QV4::Heap::SimpleCallContext *QV4DataCollector::findScope(QV4::ExecutionContext *ctxt, int scope) { if (!ctxt) return 0; @@ -81,7 +81,7 @@ QV4::Heap::CallContext *QV4DataCollector::findScope(QV4::ExecutionContext *ctxt, for (; scope > 0 && ctx; --scope) ctx = ctx->d()->outer; - return (ctx && ctx->d()) ? ctx->asCallContext()->d() : 0; + return (ctx && ctx->d()) ? ctx->asSimpleCallContext()->d() : 0; } QVector QV4DataCollector::getScopeTypes(int frame) @@ -89,7 +89,7 @@ QVector QV4DataCollector::getScopeType QVector types; QV4::Scope scope(engine()); - QV4::CallContext *sctxt = findContext(frame); + QV4::SimpleCallContext *sctxt = findContext(frame); if (!sctxt || sctxt->d()->type < QV4::Heap::ExecutionContext::Type_QmlContext) return types; @@ -310,7 +310,7 @@ QJsonObject QV4DataCollector::buildFrame(const QV4::StackFrame &stackFrame, int QV4::Scope scope(engine()); QV4::ScopedContext ctxt(scope, findContext(frameNr)); while (ctxt) { - if (QV4::CallContext *cCtxt = ctxt->asCallContext()) { + if (QV4::SimpleCallContext *cCtxt = ctxt->asSimpleCallContext()) { if (cCtxt->d()->activation) break; } @@ -318,7 +318,7 @@ QJsonObject QV4DataCollector::buildFrame(const QV4::StackFrame &stackFrame, int } if (ctxt) { - QV4::ScopedValue o(scope, ctxt->asCallContext()->d()->activation); + QV4::ScopedValue o(scope, ctxt->asSimpleCallContext()->d()->activation); frame[QLatin1String("receiver")] = toRef(collect(o)); } -- cgit v1.2.3 From b214d6cc2f96837d6502c9a3068bbd0d08b5b929 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 6 Feb 2017 10:57:04 +0100 Subject: Add an actual write barrier and centralize it in one place All stores into the Heap from C++ and Moth should now go through the write barrier. Change-Id: Iae9347754b90d68c10fade9f345842e86ec460cd Reviewed-by: Simon Hausmann --- src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp') diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index 225a1fa27d..b76cd8e65a 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -366,8 +366,8 @@ QV4DataCollector::Ref QV4DataCollector::addRef(QV4::Value value, bool deduplicat { class ExceptionStateSaver { - quint32 *hasExceptionLoc; - quint32 hadException; + quint8 *hasExceptionLoc; + quint8 hadException; public: ExceptionStateSaver(QV4::ExecutionEngine *engine) -- cgit v1.2.3 From ffe538a565e2f14ad276078891f18ec90d09be82 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 9 Mar 2017 18:53:23 +0100 Subject: QV4DebugService: Reduce unnecessary recursion and redundancy Large parts of the protocol are unnecessary. There is no reason to send a separate chunk of "handles" with almost every reply. The refs are given as part of the regular data and if the client wants to find out more, it can do further lookups. Also, it makes no sense to encode the function and script names as objects, as they are in fact not JavaScript objects. Unfortunately these cleanups require some cooperation from the client. Older clients will misbehave if we just drop the redundancy. Therefore, we introduce parameters which the client can explicitly set with the "connect" message. redundantRefs tells the service if redundant references are required, namesAsObjects tells it if script and function names have to be sent as objects/ Once we can require clients that support these options, we can drop the code that generates redundant data. Also, fix tst_qv4debugger::evaluateExpression() to actually check all the expressions evaluated, not only the first and second one. Task-number: QTBUG-42435 Change-Id: If93d2a2b9d0b8035f85dbef871bc1b03f199171d Reviewed-by: hjk Reviewed-by: Simon Hausmann --- .../qmldbg_debugger/qv4datacollector.cpp | 72 +++++++++++++++------- 1 file changed, 50 insertions(+), 22 deletions(-) (limited to 'src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp') diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index aed2759383..5d2e754057 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -118,15 +118,18 @@ int QV4DataCollector::encodeScopeType(QV4::Heap::ExecutionContext::ContextType s } } -QV4DataCollector::QV4DataCollector(QV4::ExecutionEngine *engine) : m_engine(engine) +QV4DataCollector::QV4DataCollector(QV4::ExecutionEngine *engine) + : m_engine(engine), m_namesAsObjects(true), m_redundantRefs(true) { m_values.set(engine, engine->newArrayObject()); } +// TODO: Directly call addRef() once we don't need to support redundantRefs anymore QV4DataCollector::Ref QV4DataCollector::collect(const QV4::ScopedValue &value) { Ref ref = addRef(value); - m_collectedRefs.append(ref); + if (m_redundantRefs) + m_collectedRefs.append(ref); return ref; } @@ -190,24 +193,33 @@ const QV4::Object *collectProperty(const QV4::ScopedValue &value, QV4::Execution } } -QJsonObject QV4DataCollector::lookupRef(Ref ref) +QJsonObject QV4DataCollector::lookupRef(Ref ref, bool deep) { QJsonObject dict; - if (lookupSpecialRef(ref, &dict)) - return dict; + + if (m_namesAsObjects) { + if (lookupSpecialRef(ref, &dict)) + return dict; + } + + if (m_redundantRefs) + deep = true; dict.insert(QStringLiteral("handle"), qint64(ref)); QV4::Scope scope(engine()); QV4::ScopedValue value(scope, getValue(ref)); - if (const QV4::Object *o = collectProperty(value, engine(), dict)) - dict.insert(QStringLiteral("properties"), collectProperties(o)); + const QV4::Object *object = collectProperty(value, engine(), dict); + if (deep && object) + dict.insert(QStringLiteral("properties"), collectProperties(object)); return dict; } +// TODO: Drop this method once we don't need to support namesAsObjects anymore QV4DataCollector::Ref QV4DataCollector::addFunctionRef(const QString &functionName) { + Q_ASSERT(m_namesAsObjects); Ref ref = addRef(QV4::Primitive::emptyValue(), false); QJsonObject dict; @@ -220,8 +232,10 @@ QV4DataCollector::Ref QV4DataCollector::addFunctionRef(const QString &functionNa return ref; } +// TODO: Drop this method once we don't need to support namesAsObjects anymore QV4DataCollector::Ref QV4DataCollector::addScriptRef(const QString &scriptName) { + Q_ASSERT(m_namesAsObjects); Ref ref = addRef(QV4::Primitive::emptyValue(), false); QJsonObject dict; @@ -250,6 +264,7 @@ bool QV4DataCollector::collectScope(QJsonObject *dict, int frameNr, int scopeNr) if (!ctxt) return false; + Refs collectedRefs; QV4::ScopedValue v(scope); int nFormals = ctxt->formalCount(); for (unsigned i = 0, ei = nFormals; i != ei; ++i) { @@ -258,7 +273,7 @@ bool QV4DataCollector::collectScope(QJsonObject *dict, int frameNr, int scopeNr) qName = name->string; names.append(qName); v = ctxt->argument(i); - collect(v); + collectedRefs.append(collect(v)); } for (unsigned i = 0, ei = ctxt->variableCount(); i != ei; ++i) { @@ -267,19 +282,24 @@ bool QV4DataCollector::collectScope(QJsonObject *dict, int frameNr, int scopeNr) qName = name->string; names.append(qName); v = ctxt->d()->locals[i]; - collect(v); + collectedRefs.append(collect(v)); } QV4::ScopedObject scopeObject(scope, engine()->newObject()); - Q_ASSERT(names.size() == m_collectedRefs.size()); - for (int i = 0, ei = m_collectedRefs.size(); i != ei; ++i) + Q_ASSERT(names.size() == collectedRefs.size()); + for (int i = 0, ei = collectedRefs.size(); i != ei; ++i) scopeObject->put(engine(), names.at(i), - QV4::Value::fromReturnedValue(getValue(m_collectedRefs.at(i)))); + QV4::Value::fromReturnedValue(getValue(collectedRefs.at(i)))); Ref scopeObjectRef = addRef(scopeObject); - dict->insert(QStringLiteral("ref"), qint64(scopeObjectRef)); - m_collectedRefs.append(scopeObjectRef); + if (m_redundantRefs) { + dict->insert(QStringLiteral("ref"), qint64(scopeObjectRef)); + m_collectedRefs.append(scopeObjectRef); + } else { + *dict = lookupRef(scopeObjectRef, true); + } + return true; } @@ -291,15 +311,16 @@ QJsonObject toRef(QV4DataCollector::Ref ref) { QJsonObject QV4DataCollector::buildFrame(const QV4::StackFrame &stackFrame, int frameNr) { - QV4DataCollector::Ref ref; - QJsonObject frame; frame[QLatin1String("index")] = frameNr; frame[QLatin1String("debuggerFrame")] = false; - ref = addFunctionRef(stackFrame.function); - frame[QLatin1String("func")] = toRef(ref); - ref = addScriptRef(stackFrame.source); - frame[QLatin1String("script")] = toRef(ref); + if (m_namesAsObjects) { + frame[QLatin1String("func")] = toRef(addFunctionRef(stackFrame.function)); + frame[QLatin1String("script")] = toRef(addScriptRef(stackFrame.source)); + } else { + frame[QLatin1String("func")] = stackFrame.function; + frame[QLatin1String("script")] = stackFrame.source; + } frame[QLatin1String("line")] = stackFrame.line - 1; if (stackFrame.column >= 0) frame[QLatin1String("column")] = stackFrame.column; @@ -338,15 +359,17 @@ QJsonObject QV4DataCollector::buildFrame(const QV4::StackFrame &stackFrame, int return frame; } +// TODO: Drop this method once we don't need to support redundantRefs anymore QJsonArray QV4DataCollector::flushCollectedRefs() { + Q_ASSERT(m_redundantRefs); QJsonArray refs; std::sort(m_collectedRefs.begin(), m_collectedRefs.end()); for (int i = 0, ei = m_collectedRefs.size(); i != ei; ++i) { QV4DataCollector::Ref ref = m_collectedRefs.at(i); if (i > 0 && ref == m_collectedRefs.at(i - 1)) continue; - refs.append(lookupRef(ref)); + refs.append(lookupRef(ref, true)); } m_collectedRefs.clear(); @@ -358,6 +381,8 @@ void QV4DataCollector::clear() m_values.set(engine(), engine()->newArrayObject()); m_collectedRefs.clear(); m_specialRefs.clear(); + m_namesAsObjects = true; + m_redundantRefs = true; } QV4DataCollector::Ref QV4DataCollector::addRef(QV4::Value value, bool deduplicate) @@ -401,8 +426,10 @@ QV4::ReturnedValue QV4DataCollector::getValue(Ref ref) return array->getIndexed(ref, Q_NULLPTR); } +// TODO: Drop this method once we don't need to support namesAsObjects anymore bool QV4DataCollector::lookupSpecialRef(Ref ref, QJsonObject *dict) { + Q_ASSERT(m_namesAsObjects); SpecialRefs::const_iterator it = m_specialRefs.constFind(ref); if (it == m_specialRefs.cend()) return false; @@ -440,7 +467,8 @@ QJsonObject QV4DataCollector::collectAsJson(const QString &name, const QV4::Scop if (value->isManaged() && !value->isString()) { Ref ref = addRef(value); dict.insert(QStringLiteral("ref"), qint64(ref)); - m_collectedRefs.append(ref); + if (m_redundantRefs) + m_collectedRefs.append(ref); } collectProperty(value, engine(), dict); -- cgit v1.2.3 From 7a125135e1ef592aa20a29f7aac1a6117a6b1770 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 15 Mar 2017 08:25:56 +0100 Subject: Protect CallContext member usage against word size differences Ensure the offsets we're taking from ExecutionContext members in the JIT code generator can be translated from host architecture sizes to target architecture, using assertions and a memory layout that we already have in the dev branch with commit 4de7e48ab160dacc7a09360e80264eac4945a8f4. Change-Id: I1b26ef265234b05a6e5c8688a8aad2f33cd28783 Task-number: QTBUG-58666 Reviewed-by: Lars Knoll --- src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp') diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index 5d2e754057..8075b7c067 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -95,7 +95,7 @@ QVector QV4DataCollector::getScopeType QV4::ScopedContext it(scope, sctxt); for (; it; it = it->d()->outer) - types.append(it->d()->type); + types.append(QV4::Heap::ExecutionContext::ContextType(it->d()->type)); return types; } -- cgit v1.2.3 From 1bc9e17636f5fd0a4c86cba379f0060fe894b1bb Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 17 Mar 2017 17:49:44 +0100 Subject: V4 Debugger: Encode NaN and +/-Infinity as strings JSON doesn't have numerical values for those. However, as we give the type of each item in a separate field, we can just use strings here and the result will still not clash with actual strings. Task-number: QTBUG-47880 Change-Id: I85ffa008890a8a9e6894dd3151f7dc6b527ed5e1 Reviewed-by: Simon Hausmann --- src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp') diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index 8075b7c067..b4b95f6713 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -187,10 +187,19 @@ const QV4::Object *collectProperty(const QV4::ScopedValue &value, QV4::Execution case QV4::Value::Integer_Type: dict.insert(valueKey, value->integerValue()); return 0; - default: // double - dict.insert(valueKey, value->doubleValue()); + default: {// double + const double val = value->doubleValue(); + if (qIsFinite(val)) + dict.insert(valueKey, val); + else if (qIsNaN(val)) + dict.insert(valueKey, QStringLiteral("NaN")); + else if (val < 0) + dict.insert(valueKey, QStringLiteral("-Infinity")); + else + dict.insert(valueKey, QStringLiteral("Infinity")); return 0; } + } } QJsonObject QV4DataCollector::lookupRef(Ref ref, bool deep) -- cgit v1.2.3