Make pretty-printing GDB's LazyString work

Qt Creator failed to properly display GDB's LazyString.

The problem was that GDB's 'PlainDumper::__call__' passed a 'gdb.Type',
while 'DumperBase::putCharArrayHelper' called methods that are only
defined for the custom and more abstract 'Type' type defined in 'dumper.py'.

As described at [1], GDB's 'LazyString.type' "holds the type that is
represented by the lazy string’s type. For a lazy string this is a pointer
or array type. To resolve this to the lazy string’s character type,
use the type’s target method."

In addition, 'gdb.Type' does not have a 'size()' method, just a 'sizeof'
member, s. [2].

Since all other uses of 'DumperBase::putCharArrayHelper' are passed
a "proper" type, extract the code common to the GDB case and all others
into a separate method and directly call this one for the GDB LazyString
case.

[1] https://sourceware.org/gdb/onlinedocs/gdb/Lazy-Strings-In-Python.html#Lazy-Strings-In-Python
[2] https://sourceware.org/gdb/onlinedocs/gdb/Types-In-Python.html#Types-In-Python

Task-number: QTCREATORBUG-20939
Change-Id: I16608668c9403b6d8e509dab17eb1788586f453e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Michael Weghorn
2018-08-14 14:02:00 +02:00
parent db9837fa6c
commit ec5e70eeda
2 changed files with 10 additions and 5 deletions

View File

@@ -703,10 +703,8 @@ class DumperBase:
elided, shown = self.computeLimit(size, limit)
return elided, self.readMemory(data, shown)
def putCharArrayHelper(self, data, size, charType,
displayFormat = AutomaticFormat,
makeExpandable = True):
charSize = charType.size()
def putCharArrayValue(self, data, size, charSize,
displayFormat = AutomaticFormat):
bytelen = size * charSize
elided, shown = self.computeLimit(bytelen, self.displayStringLimit)
mem = self.readMemory(data, shown)
@@ -729,6 +727,12 @@ class DumperBase:
elided, shown = self.computeLimit(bytelen, 100000)
self.putDisplay(encodingType + ':separate', self.readMemory(data, shown))
def putCharArrayHelper(self, data, size, charType,
displayFormat = AutomaticFormat,
makeExpandable = True):
charSize = charType.size()
self.putCharArrayValue(data, size, charSize, displayFormat = displayFormat)
if makeExpandable:
self.putNumChild(size)
if self.isExpanded():

View File

@@ -145,7 +145,8 @@ class PlainDumper:
elif sys.version_info[0] <= 2 and isinstance(val, unicode):
d.putValue(val)
else: # Assuming LazyString
d.putCharArrayHelper(val.address, val.length, val.type)
d.putCharArrayValue(val.address, val.length,
val.type.target().sizeof)
d.putNumChild(len(children))
if d.isExpanded():