Debugger: Add helper function for value creation

Change-Id: Ibdf496e5d6f6772d5c9fd831b8c66823c7ba8e72
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2016-11-03 15:32:27 +01:00
parent 4411f91139
commit df35444e8d
3 changed files with 21 additions and 38 deletions

View File

@@ -74,14 +74,8 @@ static PyObject *cdbext_listOfLocals(PyObject *, PyObject *) // -> [ Value ]
const auto children = sg->root()->children();
auto locals = PyList_New(0);
for (AbstractSymbolGroupNode *abstractChild : children) {
Value *childValue = PyObject_New(Value, value_pytype());
if (childValue != NULL) {
if (SymbolGroupNode* child = abstractChild->asSymbolGroupNode()) {
childValue->m_index = child->index();
childValue->m_symbolGroup = sg->debugSymbolGroup();
}
}
PyList_Append(locals, reinterpret_cast<PyObject*>(childValue));
if (SymbolGroupNode* child = abstractChild->asSymbolGroupNode())
PyList_Append(locals, createValue(child->index(), sg->debugSymbolGroup()));
}
return locals;

View File

@@ -125,23 +125,18 @@ PyObject *value_Dereference(Value *self)
char *name = getTypeName(params.Module, params.TypeId);
Value *ret = self;
PyObject *ret = reinterpret_cast<PyObject*>(self);
if (endsWith(std::string(name), "*")) {
if (numberOfChildren(self) > 0 && expandValue(self)) {
ULONG symbolCount = 0;
self->m_symbolGroup->GetNumberSymbols(&symbolCount);
if (symbolCount > self->m_index + 1) {
ret = PyObject_New(Value, value_pytype());
if (ret != NULL) {
ret->m_index = self->m_index + 1;
ret->m_symbolGroup = self->m_symbolGroup;
}
}
if (symbolCount > self->m_index + 1)
ret = createValue(self->m_index + 1, self->m_symbolGroup);
}
}
delete[] name;
return reinterpret_cast<PyObject*>(ret);
return ret;
}
PyObject *value_HasChildren(Value *self)
@@ -187,14 +182,8 @@ PyObject *value_ChildFromName(Value *self, PyObject *args)
Py_RETURN_NONE;
for (ULONG childIndex = self->m_index + 1 ; childIndex <= self->m_index + childCount; ++childIndex) {
if (getSymbolName(self->m_symbolGroup, childIndex) == name) {
Value *childValue = PyObject_New(Value, value_pytype());
if (childValue != NULL) {
childValue->m_index = childIndex;
childValue->m_symbolGroup = self->m_symbolGroup;
}
return reinterpret_cast<PyObject*>(childValue);
}
if (getSymbolName(self->m_symbolGroup, childIndex) == name)
return createValue(childIndex, self->m_symbolGroup);
}
Py_RETURN_NONE;
@@ -241,12 +230,7 @@ PyObject *value_ChildFromField(Value *self, PyObject *args)
if (FAILED(self->m_symbolGroup->AddSymbol(name.c_str(), &index)))
Py_RETURN_NONE;
Value *childValue = PyObject_New(Value, value_pytype());
if (childValue != NULL) {
childValue->m_index = index;
childValue->m_symbolGroup = self->m_symbolGroup;
}
return reinterpret_cast<PyObject*>(childValue);
return createValue(index, self->m_symbolGroup);
}
PyObject *value_ChildFromIndex(Value *self, PyObject *args)
@@ -264,13 +248,7 @@ PyObject *value_ChildFromIndex(Value *self, PyObject *args)
if (childCount <= index || !expandValue(self))
Py_RETURN_NONE;
Value *childValue = PyObject_New(Value, value_pytype());
if (childValue != NULL) {
childValue->m_index = self->m_index + index + 1;
childValue->m_symbolGroup = self->m_symbolGroup;
}
return reinterpret_cast<PyObject*>(childValue);
return createValue(self->m_index + index + 1, self->m_symbolGroup);
}
void value_Dealloc(Value *)
@@ -290,6 +268,16 @@ void initValue(Value *value)
value->m_symbolGroup = nullptr;
}
PyObject *createValue(ULONG index, CIDebugSymbolGroup *symbolGroup)
{
Value *value = PyObject_New(Value, value_pytype());
if (value != NULL) {
value->m_index = index;
value->m_symbolGroup = symbolGroup;
}
return reinterpret_cast<PyObject*>(value);
}
static PyMethodDef valueMethods[] = {
{"name", PyCFunction(value_Name), METH_NOARGS,
"Name of this thing or None"},

View File

@@ -40,3 +40,4 @@ struct Value
PyTypeObject *value_pytype();
void initValue(Value *value);
PyObject *createValue(ULONG index, CIDebugSymbolGroup *symbolGroup);