diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-08-04 10:03:03 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-08-04 08:59:54 +0000 |
commit | 7835060518a2280bda4ca28684b78a1481677158 (patch) | |
tree | bba6908444148a724c0f7e8f724edc204ccf7322 /src | |
parent | c0f961cd6b82a523e277f6d8778a20508b15697d (diff) |
Fix frame handling
Fix some regressions introduced by change
1ae1eaf59e0475a2dc9c5e22e53e9be19d0f2feb.
Change-Id: I24c1db78634e3beb1ab090325b60e70f788f92a7
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_debugger/qv4debugger.cpp | 4 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp | 17 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp | 44 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 21 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4enginebase_p.h | 10 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4errorobject.cpp | 9 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4global_p.h | 7 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4sequenceobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4vme_moth.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 22 |
10 files changed, 75 insertions, 65 deletions
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debugger.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4debugger.cpp index b82df9c6a9..1bd8581fbb 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4debugger.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debugger.cpp @@ -158,7 +158,7 @@ QV4Debugger::ExecutionState QV4Debugger::currentExecutionState() const { ExecutionState state; state.fileName = getFunction()->sourceFile(); - state.lineNumber = engine()->current->lineNumber; + state.lineNumber = engine()->currentStackFrame->line; return state; } @@ -203,7 +203,7 @@ void QV4Debugger::maybeBreakAtInstruction() pauseAndWait(PauseRequest); } else if (m_haveBreakPoints) { if (QV4::Function *f = getFunction()) { - const int lineNumber = engine()->current->lineNumber; + const int lineNumber = engine()->currentStackFrame->line; if (reallyHitTheBreakPoint(f->sourceFile(), lineNumber)) pauseAndWait(BreakPointHit); } diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp index 9a34d5770a..09ed9ac98c 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp @@ -79,20 +79,19 @@ void QV4DebuggerAgent::debuggerPaused(QV4Debugger *debugger, QV4Debugger::PauseR case QV4Debugger::PauseRequest: case QV4Debugger::BreakPointHit: { event.insert(QStringLiteral("event"), QStringLiteral("break")); - QVector<QV4::StackFrame> frames = debugger->stackTrace(1); - if (frames.isEmpty()) + QV4::EngineBase::StackFrame *frame = debugger->engine()->currentStackFrame; + if (!frame) break; - const QV4::StackFrame &topFrame = frames.first(); - body.insert(QStringLiteral("invocationText"), topFrame.function); - body.insert(QStringLiteral("sourceLine"), topFrame.line - 1); - if (topFrame.column > 0) - body.insert(QStringLiteral("sourceColumn"), topFrame.column); + body.insert(QStringLiteral("invocationText"), frame->function()); + body.insert(QStringLiteral("sourceLine"), frame->line - 1); + if (frame->column > 0) + body.insert(QStringLiteral("sourceColumn"), frame->column); QJsonArray breakPoints; - foreach (int breakPointId, breakPointIds(topFrame.source, topFrame.line)) + foreach (int breakPointId, breakPointIds(frame->source(), frame->line)) breakPoints.push_back(breakPointId); body.insert(QStringLiteral("breakpoints"), breakPoints); - script.insert(QStringLiteral("name"), topFrame.source); + script.insert(QStringLiteral("name"), frame->source()); } break; case QV4Debugger::Throwing: // TODO: complete this! diff --git a/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp index 59d4687615..cbf4eb1539 100644 --- a/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp +++ b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp @@ -239,7 +239,9 @@ private: bool NativeDebugger::checkCondition(const QString &expression) { - return evaluateExpression(expression).booleanValue(); + QV4::Scope scope(m_engine); + QV4::ScopedValue r(scope, evaluateExpression(expression)); + return r->booleanValue(); } QV4::ReturnedValue NativeDebugger::evaluateExpression(const QString &expression) @@ -333,25 +335,24 @@ void NativeDebugger::handleBacktrace(QJsonObject *response, const QJsonObject &a int limit = arguments.value(QLatin1String("limit")).toInt(0); QJsonArray frameArray; - QV4::ExecutionContext *executionContext = m_engine->currentContext; - for (int i = 0; i < limit && executionContext; ++i) { - if (QV4::Function *function = executionContext->getFunction()) { + QV4::EngineBase::StackFrame *f= m_engine->currentStackFrame; + for (int i = 0; i < limit && f; ++i) { + QV4::Function *function = f->v4Function; - QJsonObject frame; - frame.insert(QStringLiteral("language"), QStringLiteral("js")); - frame.insert(QStringLiteral("context"), encodeContext(executionContext)); + QJsonObject frame; + frame.insert(QStringLiteral("language"), QStringLiteral("js")); + frame.insert(QStringLiteral("context"), encodeContext(nullptr /*#### context*/)); - if (QV4::Heap::String *functionName = function->name()) - frame.insert(QStringLiteral("function"), functionName->toQString()); - frame.insert(QStringLiteral("file"), function->sourceFile()); + if (QV4::Heap::String *functionName = function->name()) + frame.insert(QStringLiteral("function"), functionName->toQString()); + frame.insert(QStringLiteral("file"), function->sourceFile()); - int line = executionContext->d()->lineNumber; - frame.insert(QStringLiteral("line"), (line < 0 ? -line : line)); + int line = f->line; + frame.insert(QStringLiteral("line"), (line < 0 ? -line : line)); - frameArray.push_back(frame); - } + frameArray.push_back(frame); - executionContext = m_engine->parentContext(executionContext); + f = f->parent; } response->insert(QStringLiteral("frames"), frameArray); @@ -621,7 +622,7 @@ void NativeDebugger::maybeBreakAtInstruction() if (m_service->m_breakHandler->m_haveBreakPoints) { if (QV4::Function *function = getFunction()) { - const int lineNumber = m_engine->current->lineNumber; + const int lineNumber = m_engine->currentStackFrame->line; if (reallyHitTheBreakPoint(function, lineNumber)) pauseAndWait(); } @@ -679,12 +680,11 @@ void NativeDebugger::pauseAndWait() event.insert(QStringLiteral("event"), QStringLiteral("break")); event.insert(QStringLiteral("language"), QStringLiteral("js")); - if (QV4::ExecutionContext *executionContext = m_engine->currentContext) { - if (QV4::Function *function = executionContext->getFunction()) { - event.insert(QStringLiteral("file"), function->sourceFile()); - int line = executionContext->d()->lineNumber; - event.insert(QStringLiteral("line"), (line < 0 ? -line : line)); - } + if (QV4::EngineBase::StackFrame *frame = m_engine->currentStackFrame) { + QV4::Function *function = frame->v4Function; + event.insert(QStringLiteral("file"), function->sourceFile()); + int line = frame->line; + event.insert(QStringLiteral("line"), (line < 0 ? -line : line)); } m_service->emitAsynchronousMessageToClient(event); diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 167e38f04a..8d0f401f58 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -804,26 +804,29 @@ QQmlContextData *ExecutionEngine::callingQmlContext() const return ctx->qml()->context->contextData(); } -QString StackFrame::source() const +QString EngineBase::StackFrame::source() const { return v4Function->sourceFile(); } -QString StackFrame::function() const +QString EngineBase::StackFrame::function() const { return v4Function->name()->toQString(); } -QVector<StackFrame> ExecutionEngine::stackTrace(int frameLimit) const +StackTrace ExecutionEngine::stackTrace(int frameLimit) const { Scope scope(const_cast<ExecutionEngine *>(this)); ScopedString name(scope); - QVector<StackFrame> stack; + StackTrace stack; StackFrame *f = currentStackFrame; while (f && frameLimit) { - StackFrame frame = *f; - frame.parent = 0; + QV4::StackFrame frame; + frame.source = f->source(); + frame.function = f->function(); + frame.line = f->line; + frame.column = f->column; stack.append(frame); --frameLimit; f = f->parent; @@ -849,9 +852,9 @@ static inline char *v4StackTrace(const ExecutionContext *context) for (int i = 0; i < stackTrace.size(); ++i) { if (i) str << ','; - const QUrl url(stackTrace.at(i).source()); + const QUrl url(stackTrace.at(i).source); const QString fileName = url.isLocalFile() ? url.toLocalFile() : url.toString(); - str << "frame={level=\"" << i << "\",func=\"" << stackTrace.at(i).function() + str << "frame={level=\"" << i << "\",func=\"" << stackTrace.at(i).function << "\",file=\"" << fileName << "\",fullname=\"" << fileName << "\",line=\"" << stackTrace.at(i).line << "\",language=\"js\"}"; } @@ -1066,7 +1069,7 @@ QQmlError ExecutionEngine::catchExceptionAsQmlError() QQmlError error; if (!trace.isEmpty()) { QV4::StackFrame frame = trace.constFirst(); - error.setUrl(QUrl(frame.source())); + error.setUrl(QUrl(frame.source)); error.setLine(frame.line); error.setColumn(frame.column); } diff --git a/src/qml/jsruntime/qv4enginebase_p.h b/src/qml/jsruntime/qv4enginebase_p.h index 55c44f33f1..cc049fb296 100644 --- a/src/qml/jsruntime/qv4enginebase_p.h +++ b/src/qml/jsruntime/qv4enginebase_p.h @@ -63,6 +63,16 @@ namespace QV4 { #pragma pack(push, 1) #endif struct EngineBase { + struct StackFrame { + StackFrame *parent; + Function *v4Function; + int line = -1; + int column = -1; + + QString source() const; + QString function() const; + }; + Heap::ExecutionContext *current = 0; StackFrame *currentStackFrame = 0; diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index 1eb2cd866d..aef4e64964 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -96,7 +96,7 @@ void Heap::ErrorObject::init(const Value &message, ErrorType t) e->d()->stackTrace = new StackTrace(scope.engine->stackTrace()); if (!e->d()->stackTrace->isEmpty()) { - setProperty(scope.engine, QV4::ErrorObject::Index_FileName, scope.engine->newString(e->d()->stackTrace->at(0).source())); + setProperty(scope.engine, QV4::ErrorObject::Index_FileName, scope.engine->newString(e->d()->stackTrace->at(0).source)); setProperty(scope.engine, QV4::ErrorObject::Index_LineNumber, Primitive::fromInt32(e->d()->stackTrace->at(0).line)); } @@ -117,13 +117,14 @@ void Heap::ErrorObject::init(const Value &message, const QString &fileName, int setProperty(scope.engine, QV4::ErrorObject::Index_Stack + QV4::Object::SetterOffset, Primitive::undefinedValue()); e->d()->stackTrace = new StackTrace(scope.engine->stackTrace()); - StackFrame frame = *scope.engine->currentStackFrame; + StackFrame frame; + frame.source = fileName; frame.line = line; frame.column = column; e->d()->stackTrace->prepend(frame); Q_ASSERT(!e->d()->stackTrace->isEmpty()); - setProperty(scope.engine, QV4::ErrorObject::Index_FileName, scope.engine->newString(e->d()->stackTrace->at(0).source())); + setProperty(scope.engine, QV4::ErrorObject::Index_FileName, scope.engine->newString(e->d()->stackTrace->at(0).source)); setProperty(scope.engine, QV4::ErrorObject::Index_LineNumber, Primitive::fromInt32(e->d()->stackTrace->at(0).line)); if (!message.isUndefined()) @@ -162,7 +163,7 @@ void ErrorObject::method_get_stack(const BuiltinFunction *, Scope &scope, CallDa if (i > 0) trace += QLatin1Char('\n'); const StackFrame &frame = This->d()->stackTrace->at(i); - trace += frame.function() + QLatin1Char('@') + frame.source(); + trace += frame.function + QLatin1Char('@') + frame.source; if (frame.line >= 0) trace += QLatin1Char(':') + QString::number(frame.line); } diff --git a/src/qml/jsruntime/qv4global_p.h b/src/qml/jsruntime/qv4global_p.h index d06ab86593..d50669a24e 100644 --- a/src/qml/jsruntime/qv4global_p.h +++ b/src/qml/jsruntime/qv4global_p.h @@ -358,13 +358,10 @@ struct PropertyAttributes }; struct Q_QML_EXPORT StackFrame { - StackFrame *parent; - Function *v4Function; + QString source; + QString function; int line = -1; int column = -1; - - QString source() const; - QString function() const; }; typedef QVector<StackFrame> StackTrace; diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index 0abe6ddd98..ec3ff0ea1d 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -66,7 +66,7 @@ static void generateWarning(QV4::ExecutionEngine *v4, const QString& description QQmlError retn; retn.setDescription(description); - QV4::StackFrame *stackFrame = v4->currentStackFrame; + QV4::EngineBase::StackFrame *stackFrame = v4->currentStackFrame; retn.setLine(stackFrame->line); retn.setUrl(QUrl(stackFrame->source())); diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index e3a9815f54..954b7d40a1 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -235,7 +235,7 @@ int qt_v4DebuggerHook(const char *json) return -NoSuchCommand; // Failure. } -Q_NEVER_INLINE static void qt_v4CheckForBreak(QV4::StackFrame *frame) +Q_NEVER_INLINE static void qt_v4CheckForBreak(QV4::EngineBase::StackFrame *frame) { if (!qt_v4IsStepping && !qt_v4Breakpoints.size()) return; @@ -446,7 +446,7 @@ QV4::ReturnedValue VME::exec(Function *function) ExecutionEngine *engine = function->internalClass->engine; - StackFrame frame; + EngineBase::StackFrame frame; frame.parent = engine->currentStackFrame; frame.v4Function = function; engine->currentStackFrame = &frame; diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 8fc048b5f3..459d9afe2a 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -1326,7 +1326,7 @@ void Heap::QQmlBindingFunction::init(const QV4::FunctionObject *originalFunction QQmlSourceLocation QQmlBindingFunction::currentLocation() const { - QV4::StackFrame *frame = engine()->currentStackFrame; + QV4::EngineBase::StackFrame *frame = engine()->currentStackFrame; return QQmlSourceLocation(frame->source(), frame->line, 0); } @@ -1475,13 +1475,13 @@ static QString jsStack(QV4::ExecutionEngine *engine) { QString stackFrame; if (frame.column >= 0) - stackFrame = QStringLiteral("%1 (%2:%3:%4)").arg(frame.function(), - frame.source(), + stackFrame = QStringLiteral("%1 (%2:%3:%4)").arg(frame.function, + frame.source, QString::number(frame.line), QString::number(frame.column)); else - stackFrame = QStringLiteral("%1 (%2:%3)").arg(frame.function(), - frame.source(), + stackFrame = QStringLiteral("%1 (%2:%3)").arg(frame.function, + frame.source, QString::number(frame.line)); if (i) @@ -1530,7 +1530,7 @@ static void writeToConsole(const BuiltinFunction *, Scope &scope, CallData *call if (!loggingCategory) loggingCategory = v4->qmlEngine() ? &qmlLoggingCategory : &jsLoggingCategory; - QV4::StackFrame *frame = v4->currentStackFrame; + QV4::EngineBase::StackFrame *frame = v4->currentStackFrame; const QByteArray baSource = frame->source().toUtf8(); const QByteArray baFunction = frame->function().toUtf8(); QMessageLogger logger(baSource.constData(), frame->line, baFunction.constData(), loggingCategory->categoryName()); @@ -1583,7 +1583,7 @@ void ConsoleObject::method_profile(const BuiltinFunction *, Scope &scope, CallDa { QV4::ExecutionEngine *v4 = scope.engine; - QV4::StackFrame *frame = v4->currentStackFrame; + QV4::EngineBase::StackFrame *frame = v4->currentStackFrame; const QByteArray baSource = frame->source().toUtf8(); const QByteArray baFunction = frame->function().toUtf8(); QMessageLogger logger(baSource.constData(), frame->line, baFunction.constData()); @@ -1602,7 +1602,7 @@ void ConsoleObject::method_profileEnd(const BuiltinFunction *, Scope &scope, Cal { QV4::ExecutionEngine *v4 = scope.engine; - QV4::StackFrame *frame = v4->currentStackFrame; + QV4::EngineBase::StackFrame *frame = v4->currentStackFrame; const QByteArray baSource = frame->source().toUtf8(); const QByteArray baFunction = frame->function().toUtf8(); QMessageLogger logger(baSource.constData(), frame->line, baFunction.constData()); @@ -1656,7 +1656,7 @@ void ConsoleObject::method_count(const BuiltinFunction *, Scope &scope, CallData QV4::ExecutionEngine *v4 = scope.engine; QV8Engine *v8engine = scope.engine->v8Engine; - QV4::StackFrame *frame = v4->currentStackFrame; + QV4::EngineBase::StackFrame *frame = v4->currentStackFrame; QString scriptName = frame->source(); @@ -1679,7 +1679,7 @@ void ConsoleObject::method_trace(const BuiltinFunction *, Scope &scope, CallData QString stack = jsStack(v4); - QV4::StackFrame *frame = v4->currentStackFrame; + QV4::EngineBase::StackFrame *frame = v4->currentStackFrame; QMessageLogger(frame->source().toUtf8().constData(), frame->line, frame->function().toUtf8().constData()) .debug("%s", qPrintable(stack)); @@ -1710,7 +1710,7 @@ void ConsoleObject::method_assert(const BuiltinFunction *, Scope &scope, CallDat QString stack = jsStack(v4); - QV4::StackFrame *frame = v4->currentStackFrame; + QV4::EngineBase::StackFrame *frame = v4->currentStackFrame; QMessageLogger(frame->source().toUtf8().constData(), frame->line, frame->function().toUtf8().constData()) .critical("%s\n%s",qPrintable(message), qPrintable(stack)); |