Debugger: Extract create value functionality

Change-Id: Ia02fa053ec2a70fcd47e8f4efdd5ea8dae735200
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2017-02-27 12:22:21 +01:00
parent c517714822
commit 90e6eb1b56
3 changed files with 40 additions and 35 deletions

View File

@@ -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, &params))) {
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)

View File

@@ -26,6 +26,7 @@
#include "pyvalue.h"
#include "extensioncontext.h"
#include "symbolgroupvalue.h"
#include <list>
@@ -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, &params))) {
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 {

View File

@@ -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);