From 90e6eb1b569e4d90400ddb0c4e8e6690920e3b61 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 27 Feb 2017 12:22:21 +0100 Subject: [PATCH] Debugger: Extract create value functionality Change-Id: Ia02fa053ec2a70fcd47e8f4efdd5ea8dae735200 Reviewed-by: Christian Stenger --- src/libs/qtcreatorcdbext/pycdbextmodule.cpp | 36 +------------------ src/libs/qtcreatorcdbext/pyvalue.cpp | 38 +++++++++++++++++++++ src/libs/qtcreatorcdbext/pyvalue.h | 1 + 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/libs/qtcreatorcdbext/pycdbextmodule.cpp b/src/libs/qtcreatorcdbext/pycdbextmodule.cpp index 051aad58a3e..4d16671c023 100644 --- a/src/libs/qtcreatorcdbext/pycdbextmodule.cpp +++ b/src/libs/qtcreatorcdbext/pycdbextmodule.cpp @@ -293,41 +293,7 @@ static PyObject *cdbext_createValue(PyObject *, PyObject *args) if (!type->impl) Py_RETURN_NONE; - if (debugPyCdbextModule) { - DebugPrint() << "Create Value address: 0x" << std::hex << address - << " type name: " << type->impl->name(); - } - - IDebugSymbolGroup2 *symbolGroup = CurrentSymbolGroup::get(); - if (symbolGroup == nullptr) - Py_RETURN_NONE; - - ULONG numberOfSymbols = 0; - symbolGroup->GetNumberSymbols(&numberOfSymbols); - ULONG index = 0; - for (;index < numberOfSymbols; ++index) { - ULONG64 offset; - symbolGroup->GetSymbolOffset(index, &offset); - if (offset == address) { - DEBUG_SYMBOL_PARAMETERS params; - if (SUCCEEDED(symbolGroup->GetSymbolParameters(index, 1, ¶ms))) { - if (params.TypeId == type->impl->getTypeId() && params.Module == type->impl->moduleId()) - break; - } - } - } - - if (index >= numberOfSymbols) { - ULONG index = DEBUG_ANY_ID; - const std::string name = SymbolGroupValue::pointedToSymbolName(address, type->impl->name(true)); - if (debugPyCdbextModule) - DebugPrint() << "Create Value expression: " << name; - - if (FAILED(symbolGroup->AddSymbol(name.c_str(), &index))) - Py_RETURN_NONE; - } - - return createPythonObject(PyValue(index, symbolGroup)); + return createPythonObject(PyValue::createValue(address, *(type->impl))); } static PyObject *cdbext_call(PyObject *, PyObject *args) diff --git a/src/libs/qtcreatorcdbext/pyvalue.cpp b/src/libs/qtcreatorcdbext/pyvalue.cpp index ff58b482606..9ecc57e3807 100644 --- a/src/libs/qtcreatorcdbext/pyvalue.cpp +++ b/src/libs/qtcreatorcdbext/pyvalue.cpp @@ -26,6 +26,7 @@ #include "pyvalue.h" #include "extensioncontext.h" +#include "symbolgroupvalue.h" #include @@ -263,6 +264,43 @@ PyValue PyValue::childFromIndex(int index) return PyValue(m_index + offset, m_symbolGroup); } +PyValue PyValue::createValue(ULONG64 address, const PyType &type) +{ + if (debuggingValueEnabled()) { + DebugPrint() << "Create Value address: 0x" << std::hex << address + << " type name: " << type.name(); + } + + IDebugSymbolGroup2 *symbolGroup = CurrentSymbolGroup::get(); + if (symbolGroup == nullptr) + return PyValue(); + + ULONG numberOfSymbols = 0; + symbolGroup->GetNumberSymbols(&numberOfSymbols); + ULONG index = 0; + for (;index < numberOfSymbols; ++index) { + ULONG64 offset; + symbolGroup->GetSymbolOffset(index, &offset); + if (offset == address) { + DEBUG_SYMBOL_PARAMETERS params; + if (SUCCEEDED(symbolGroup->GetSymbolParameters(index, 1, ¶ms))) { + if (params.TypeId == type.getTypeId() && params.Module == type.moduleId()) + return PyValue(index, symbolGroup); + } + } + } + + const std::string name = SymbolGroupValue::pointedToSymbolName(address, type.name(true)); + if (debuggingValueEnabled()) + DebugPrint() << "Create Value expression: " << name; + + index = DEBUG_ANY_ID; + if (FAILED(symbolGroup->AddSymbol(name.c_str(), &index))) + return PyValue(); + + return PyValue(index, symbolGroup); +} + // Python interface implementation namespace PyValueInterface { diff --git a/src/libs/qtcreatorcdbext/pyvalue.h b/src/libs/qtcreatorcdbext/pyvalue.h index d422ab8f2eb..9d2cae9443f 100644 --- a/src/libs/qtcreatorcdbext/pyvalue.h +++ b/src/libs/qtcreatorcdbext/pyvalue.h @@ -54,6 +54,7 @@ public: PyValue childFromField(const PyField &field); PyValue childFromIndex(int index); + static PyValue createValue(ULONG64 address, const PyType &type); private: static void indicesMoved(CIDebugSymbolGroup *symbolGroup, ULONG start, ULONG delta);