From cda204aa34e671631bb612287432ba80c72d6a7e Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 10 Jul 2020 11:37:12 +0200 Subject: [PATCH] Cdbext: Fix fetching partial variable Avoid calling PyValue::childCount as it expands the values in front of the partial variable recursively. This outdates scopeEnd as it is fetched before the items are expanded, which again results in a too early return from that function. Fixes: QTCREATORBUG-24108 Change-Id: I0848cde88c6ff8019a4ab22ac1153598c20e563d Reviewed-by: Christian Stenger --- src/libs/qtcreatorcdbext/pycdbextmodule.cpp | 12 ++++-------- src/libs/qtcreatorcdbext/pyvalue.cpp | 7 ++++++- src/libs/qtcreatorcdbext/pyvalue.h | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libs/qtcreatorcdbext/pycdbextmodule.cpp b/src/libs/qtcreatorcdbext/pycdbextmodule.cpp index c1584587c0c..49eed21616c 100644 --- a/src/libs/qtcreatorcdbext/pycdbextmodule.cpp +++ b/src/libs/qtcreatorcdbext/pycdbextmodule.cpp @@ -220,17 +220,13 @@ static PyObject *cdbext_listOfLocals(PyObject *, PyObject *args) // -> [ Value ] ++currentPartialIname; // skip "local" part ULONG symbolGroupIndex = 0; - ULONG childEndIndex = 0; for (;symbolGroupIndex < scopeEnd; ++symbolGroupIndex) { PyValue value(symbolGroupIndex, symbolGroup); - if (childEndIndex <= symbolGroupIndex) { // do not return a child value - if (value.name() == *currentPartialIname) { - PyList_Append(locals, createPythonObject(value)); - return locals; - } - ++childEndIndex; + if (value.name() == *currentPartialIname) { + PyList_Append(locals, createPythonObject(value)); + return locals; } - childEndIndex += ULONG(value.childCount()); + symbolGroupIndex += value.currentNumberOfDescendants(); } } diff --git a/src/libs/qtcreatorcdbext/pyvalue.cpp b/src/libs/qtcreatorcdbext/pyvalue.cpp index a56cb08ba9c..c92b694bf37 100644 --- a/src/libs/qtcreatorcdbext/pyvalue.cpp +++ b/src/libs/qtcreatorcdbext/pyvalue.cpp @@ -278,13 +278,18 @@ PyValue PyValue::childFromIndex(int index) int offset = index + 1; for (ULONG childIndex = m_index + 1; childIndex < m_index + offset; ) { - const ULONG childDescendantCount = currentNumberOfDescendants(childIndex, m_symbolGroup); + const ULONG childDescendantCount = ::currentNumberOfDescendants(childIndex, m_symbolGroup); childIndex += childDescendantCount + 1; offset += childDescendantCount; } return PyValue(m_index + offset, m_symbolGroup); } +ULONG PyValue::currentNumberOfDescendants() +{ + return ::currentNumberOfDescendants(m_index, m_symbolGroup); +} + PyValue PyValue::createValue(ULONG64 address, const PyType &type) { if (debuggingValueEnabled()) { diff --git a/src/libs/qtcreatorcdbext/pyvalue.h b/src/libs/qtcreatorcdbext/pyvalue.h index fa89c730621..045658a01b3 100644 --- a/src/libs/qtcreatorcdbext/pyvalue.h +++ b/src/libs/qtcreatorcdbext/pyvalue.h @@ -55,6 +55,7 @@ public: PyValue childFromName(const std::string &name); PyValue childFromField(const PyField &field); PyValue childFromIndex(int index); + ULONG currentNumberOfDescendants(); static PyValue createValue(ULONG64 address, const PyType &type); static int tag(const std::string &typeName);