Debugger: Work around for gdb reporting zero array sizes in some cases

Task-number: QTCREATORBUG-23998
Change-Id: I101d032705b66faf50260067f6aa604214f09298
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-05-07 09:56:52 +02:00
parent f51258a17c
commit 7a63a47ef0
2 changed files with 11 additions and 5 deletions

View File

@@ -1089,6 +1089,10 @@ class DumperBase():
return '_ZN%sE' % ''.join(map(lambda x: '%d%s' % (len(x), x),
typeName.split('::')))
def arrayItemCountFromTypeName(self, typeName, fallbackMax=1):
itemCount = typeName[typeName.find('[') + 1:typeName.find(']')]
return int(itemCount) if itemCount else fallbackMax
def putCStyleArray(self, value):
arrayType = value.type.unqualified()
innerType = arrayType.ltarget
@@ -1107,10 +1111,7 @@ class DumperBase():
# This should not happen. But it does, see QTCREATORBUG-14755.
# GDB/GCC produce sizeof == 0 for QProcess arr[3]
# And in the Nim string dumper.
s = value.type.name
itemCount = s[s.find('[') + 1:s.find(']')]
if not itemCount:
itemCount = '100'
itemCount = self.arrayItemCountFromTypeName(value.type.name, 100)
arrayByteSize = int(itemCount) * innerType.size()
n = arrayByteSize // innerType.size()

View File

@@ -341,6 +341,11 @@ class Dumper(DumperBase):
#DumperBase.warn('ARRAY')
nativeTargetType = nativeType.target().unqualified()
targetType = self.fromNativeType(nativeTargetType)
if nativeType.sizeof == 0:
# QTCREATORBUG-23998, note that nativeType.name == None here,
# whereas str(nativeType) returns sth like 'QObject [5]'
count = self.arrayItemCountFromTypeName(str(nativeType), 1)
else:
count = nativeType.sizeof // nativeTargetType.sizeof
return self.createArrayType(targetType, count)