diff options
author | Erik Verbruggen <erik.verbruggen@me.com> | 2013-10-16 12:29:47 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-10 11:01:35 +0100 |
commit | 0910a577f4d12eea4a099c989bd58f1dee6c88db (patch) | |
tree | 53860b5debf08cef684da1eb387769dbe8ef2d42 /src/qml/jsruntime/qv4function.cpp | |
parent | 1738e4ee119bbcd20d33353e7018f04d92766639 (diff) |
Debugging with V4
Currently missing, but coming in subsequent patches:
- evaluating expressions
- evaluating breakpoint conditions
Change-Id: Ib43f2a3aaa252741ea7ce857a274480feb8741aa
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4function.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4function.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index c3d2165fb4..291d4d37d4 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -91,10 +91,11 @@ void Function::mark(ExecutionEngine *e) } namespace QV4 { +template <int field, typename SearchType> struct LineNumberMappingHelper { const quint32 *table; - int lowerBound(int begin, int end, quint32 offset) { + int lowerBound(int begin, int end, SearchType value) { int middle; int n = int(end - begin); int half; @@ -102,7 +103,7 @@ struct LineNumberMappingHelper while (n > 0) { half = n >> 1; middle = begin + half; - if (table[middle * 2] < offset) { + if (table[middle * 2 + field] < value) { begin = middle + 1; n -= half + 1; } else { @@ -111,13 +112,30 @@ struct LineNumberMappingHelper } return begin; } -}; + int upperBound(int begin, int end, SearchType value) { + int middle; + int n = int(end - begin); + int half; + while (n > 0) { + half = n >> 1; + middle = begin + half; + if (value < table[middle * 2 + field]) { + n = half; + } else { + begin = middle + 1; + n -= half + 1; + } + } + return begin; + } +}; } int Function::lineNumberForProgramCounter(qptrdiff offset) const { - LineNumberMappingHelper helper; + // Access the first field, the program counter + LineNumberMappingHelper<0, qptrdiff> helper; helper.table = compiledFunction->lineNumberMapping(); const uint count = compiledFunction->nLineNumberMappingEntries; @@ -129,4 +147,19 @@ int Function::lineNumberForProgramCounter(qptrdiff offset) const return helper.table[pos * 2 + 1]; } +qptrdiff Function::programCounterForLine(quint32 line) const +{ + // Access the second field, the line number + LineNumberMappingHelper<1, quint32> helper; + helper.table = compiledFunction->lineNumberMapping(); + const int count = static_cast<int>(compiledFunction->nLineNumberMappingEntries); + + int pos = helper.upperBound(0, count, line); + if (pos != 0 && count > 0) + --pos; + if (pos == count) + return -1; + return helper.table[pos * 2]; +} + QT_END_NAMESPACE |