From ec5e70eedadc659aeea7458e1989fded8f9bd03e Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Tue, 14 Aug 2018 14:02:00 +0200 Subject: [PATCH] Make pretty-printing GDB's LazyString work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- share/qtcreator/debugger/dumper.py | 12 ++++++++---- share/qtcreator/debugger/gdbbridge.py | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/share/qtcreator/debugger/dumper.py b/share/qtcreator/debugger/dumper.py index 4805545d246..7e461320968 100644 --- a/share/qtcreator/debugger/dumper.py +++ b/share/qtcreator/debugger/dumper.py @@ -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(): diff --git a/share/qtcreator/debugger/gdbbridge.py b/share/qtcreator/debugger/gdbbridge.py index 519afdf9826..0385caa129b 100644 --- a/share/qtcreator/debugger/gdbbridge.py +++ b/share/qtcreator/debugger/gdbbridge.py @@ -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():