From 5c7b7f5fca8c557b14959ca338cb2fa62aea6aa0 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Mon, 28 Feb 2011 15:53:10 +0100 Subject: Avoid asserting when computing line number for backtrace With JSC asserts enabled (QtScript built without NDEBUG defined), JSC::CodeBlock::getBytecodeIndex() would assert because we sometimes called it with an address that was not inside the range of the block's JIT code. We never caught this bug because it just so happens that even though the assert fails, the function returns a result that causes our autotests to pass. Check that the returnPC is in range and report lineNumber -1 if not; this unifies the behavior of the interpreter and JIT, even though it's not the result we want. Task-number: QTBUG-17741 Reviewed-by: Olivier Goffart --- src/script/api/qscriptcontextinfo.cpp | 10 +++++++++- tests/auto/qscriptcontext/tst_qscriptcontext.cpp | 6 ++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/script/api/qscriptcontextinfo.cpp b/src/script/api/qscriptcontextinfo.cpp index 0f9de1d..182bc4a 100644 --- a/src/script/api/qscriptcontextinfo.cpp +++ b/src/script/api/qscriptcontextinfo.cpp @@ -159,12 +159,20 @@ QScriptContextInfoPrivate::QScriptContextInfoPrivate(const QScriptContext *conte JSC::CodeBlock *codeBlock = frame->codeBlock(); if (returnPC && codeBlock && QScriptEnginePrivate::hasValidCodeBlockRegister(frame)) { #if ENABLE(JIT) - unsigned bytecodeOffset = codeBlock->getBytecodeIndex(frame, JSC::ReturnAddressPtr(returnPC)); + JSC::JITCode code = codeBlock->getJITCode(); + unsigned jitOffset = code.offsetOf(JSC::ReturnAddressPtr(returnPC).value()); + // We can only use the JIT code offset if it's smaller than the JIT size; + // otherwise calling getBytecodeIndex() is meaningless. + if (jitOffset < code.size()) { + unsigned bytecodeOffset = codeBlock->getBytecodeIndex(frame, JSC::ReturnAddressPtr(returnPC)); #else unsigned bytecodeOffset = returnPC - codeBlock->instructions().begin(); #endif bytecodeOffset--; //because returnPC is on the next instruction. We want the current one lineNumber = codeBlock->lineNumberForBytecodeOffset(const_cast(frame), bytecodeOffset); +#if ENABLE(JIT) + } +#endif } } } diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp index f4833bf..457188c 100644 --- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp +++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp @@ -981,10 +981,8 @@ void tst_QScriptContext::backtrace() QVERIFY(!eng.hasUncaughtException()); QVERIFY(ret.isArray()); QStringList slist = qscriptvalue_cast(ret); - if (!qt_script_isJITEnabled()) { - QEXPECT_FAIL("eval", "QTBUG-17842: Missing line number in backtrace when function calls eval()", Continue); - QEXPECT_FAIL("eval in member", "QTBUG-17842: Missing line number in backtrace when function calls eval()", Continue); - } + QEXPECT_FAIL("eval", "QTBUG-17842: Missing line number in backtrace when function calls eval()", Continue); + QEXPECT_FAIL("eval in member", "QTBUG-17842: Missing line number in backtrace when function calls eval()", Continue); QCOMPARE(slist, expectedbacktrace); } -- cgit v0.12