Debugger: Adjust cdbbridge to latest type changes

Change-Id: Ifa5edb490f12c302940d4f2101f9c297558a7cce
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2016-10-31 10:54:51 +01:00
parent 0a98e47e47
commit 89fea59099
2 changed files with 84 additions and 24 deletions

View File

@@ -91,37 +91,89 @@ class Dumper(DumperBase):
val.laddress = nativeValue.address() val.laddress = nativeValue.address()
return val return val
def fromNativeType(self, nativeType): def nativeTypeId(self, nativeType):
typeobj = self.Type(self) self.check(isinstance(nativeType, cdbext.Type))
typeobj.nativeType = nativeType name = nativeType.name()
typeobj.name = nativeType.name() if name is None or len(name) == 0:
typeobj.lbitsize = nativeType.bitsize() c = '0'
typeobj.code = nativeType.code() elif name == 'struct {...}':
return typeobj c = 's'
elif name == 'union {...}':
c = 'u'
else:
return name
typeId = c + ''.join(['{%s:%s}' % (f.name(), self.nativeTypeId(f.type())) for f in nativeType.fields()])
return typeId
def nativeTypeFields(self, nativeType): def fromNativeType(self, nativeType):
self.check(isinstance(nativeType, cdbext.Type))
code = nativeType.code()
if code == TypeCodePointer:
targetType = self.fromNativeType(nativeType.target().unqualified())
return self.createPointerType(targetType)
if code == TypeCodeArray:
nativeTargetType = nativeType.target().unqualified()
targetType = self.fromNativeType(nativeTargetType)
count = nativeType.bitsize() // nativeTargetType.bitsize()
return self.createArrayType(targetType, count)
typeId = self.nativeTypeId(nativeType)
if self.typeData.get(typeId, None) is None:
tdata = self.TypeData(self)
tdata.name = nativeType.name()
tdata.typeId = typeId
tdata.lbitsize = nativeType.bitsize()
tdata.code = code
self.registerType(typeId, tdata) # Prevent recursion in fields.
tdata.lfields = self.listFields(nativeType, self.Type(self, typeId))
tdata.templateArguments = self.listTemplateParameters(nativeType)
self.registerType(typeId, tdata) # Fix up fields and template args
return self.Type(self, typeId)
def listFields(self, nativeType, parentType):
fields = [] fields = []
for nativeField in nativeType.fields():
if not nativeType.code() == TypeCodeStruct:
return fields
nativeIndex = 0
nativeFields = nativeType.fields()
for nativeField in nativeFields:
field = self.Field(self) field = self.Field(self)
fieldType = nativeField.type().unqualified()
if fieldType is None:
fieldType = FakeVoidType('void', self)
field.ltype = self.fromNativeType(fieldType)
field.parentType = parentType
field.name = nativeField.name() field.name = nativeField.name()
field.parentType = self.fromNativeType(nativeType) field.isBaseClass = False
field.ltype = self.fromNativeType(nativeField.type())
field.lbitsize = nativeField.bitsize()
field.lbitpos = nativeField.bitpos() field.lbitpos = nativeField.bitpos()
field.lbitsize = nativeField.bitsize()
field.nativeIndex = nativeIndex
#warn("FIELD RESULT: %s" % field)
fields.append(field) fields.append(field)
nativeIndex += 1
return fields return fields
def nativeTypeUnqualified(self, nativeType): def listTemplateParameters(self, nativeType):
return self.fromNativeType(nativeType.unqualified()) targs = []
for targ in nativeType.templateArguments():
def nativeTypePointer(self, nativeType): if isinstance(targ, str):
return self.fromNativeType(nativeType.target()) if self.typeData.get(targ, None) is None:
targs.append(self.lookupType(targ))
def nativeTypeStripTypedefs(self, typeobj): else:
return self.fromNativeType(nativeType.stripTypedef()) targs.append(self.Type(self, targ))
elif isinstance(targ, int):
def nativeTypeFirstBase(self, nativeType): value = self.Value(self)
return None value.type = self.lookupType('int')
value.ldata = targ.to_bytes(4, sys.byteorder)
targs.append(value)
else:
error('CDBCRAP %s' % type(targ))
return targs
def nativeTypeEnumDisplay(self, nativeType, intval): def nativeTypeEnumDisplay(self, nativeType, intval):
# TODO: generate fake value # TODO: generate fake value
@@ -165,6 +217,14 @@ class Dumper(DumperBase):
def put(self, stuff): def put(self, stuff):
self.output += stuff self.output += stuff
def lookupType(self, typeName):
if len(typeName) == 0:
return None
if self.typeData.get(typeName, None) is None:
nativeType = self.lookupNativeType(typeName)
return None if nativeType is None else self.fromNativeType(nativeType)
return self.Type(self, typeName)
def lookupNativeType(self, name): def lookupNativeType(self, name):
if name.startswith('void'): if name.startswith('void'):
return FakeVoidType(name, self) return FakeVoidType(name, self)

View File

@@ -298,7 +298,7 @@ PyObject *type_TemplateArguments(Type *self)
childValue = Py_BuildValue("i", integer); childValue = Py_BuildValue("i", integer);
} }
catch (std::invalid_argument) { catch (std::invalid_argument) {
childValue = lookupType(innerType); childValue = Py_BuildValue("s", innerType.c_str());
} }
PyList_Append(templateArguments, childValue); PyList_Append(templateArguments, childValue);
} }