diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-08-29 12:35:05 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-08-29 10:42:35 +0000 |
commit | 77e0602021c74b5ec2d8bd9affff5e91bf6f5ae3 (patch) | |
tree | 2054bc9a29279db1cdcdb57e414a9532b99cd818 /src/qml/jsruntime/qv4engine.cpp | |
parent | 99d5cdad6c8580d5ef31c291b721bf6230e2502f (diff) |
Fix line number mapping to work with non increasing line numbers
The old map assumed that line numbers are always increasing, something
that isn't always true. So move to a format where we map blocks of
bytecode to a line number instead.
Change-Id: I1cd9dd1329d415122cd3d560294ef53007f879f8
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4engine.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index ce21e0f7e5..618565a806 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -796,15 +796,16 @@ QString CppStackFrame::function() const int CppStackFrame::lineNumber() const { + auto findLine = [](const CompiledData::CodeOffsetToLine &entry, uint offset) { + return entry.codeOffset < offset; + }; + const QV4::CompiledData::Function *cf = v4Function->compiledFunction; - uint offset = static_cast<uint>(instructionPointer - v4Function->codeData - 1); // -1 because the instructionPointer points to the next instruction - const quint32_le *lineNumbers = cf->lineNumberTable(); - int nLineNumbers = cf->nLineNumbers; - for (int i = 0; i < nLineNumbers; ++i) { - if (offset <= lineNumbers[i]) - return cf->location.line + i; - } - return cf->location.line + nLineNumbers; + uint offset = static_cast<uint>(instructionPointer - v4Function->codeData); + const CompiledData::CodeOffsetToLine *lineNumbers = cf->lineNumberTable(); + uint nLineNumbers = cf->nLineNumbers; + const CompiledData::CodeOffsetToLine *line = std::lower_bound(lineNumbers, lineNumbers + nLineNumbers, offset, findLine) - 1; + return line->line; } ReturnedValue CppStackFrame::thisObject() const { |