From 5b0dcfec8387d53041dfc5231311492d77fd21ea Mon Sep 17 00:00:00 2001 From: Teodor Petrov Date: Wed, 15 Aug 2018 08:30:27 +0300 Subject: [PATCH] Add wxArrayString pretty printer for gdb Closes #18276. --- misc/gdb/print.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/misc/gdb/print.py b/misc/gdb/print.py index 28d47d6276..8408087ad7 100755 --- a/misc/gdb/print.py +++ b/misc/gdb/print.py @@ -14,6 +14,20 @@ # in wxLookupFunction at the bottom of this file. import datetime +import gdb +import itertools +import sys + +if sys.version_info[0] > 2: + # Python 3 + Iterator = object + + long = int +else: + # Python 2, we need to make an adaptor, so we can use Python 3 iterator implementations. + class Iterator: + def next(self): + return self.__next__() # shamelessly stolen from std::string example class wxStringPrinter: @@ -26,6 +40,41 @@ class wxStringPrinter: def display_hint(self): return 'string' +class wxArrayStringPrinter: + + class _iterator(Iterator): + def __init__ (self, firstItem, count): + self.item = firstItem + self.count = count + self.current = 0 + + def __iter__(self): + return self + + def __next__(self): + current = self.current + self.current = self.current + 1 + + if current == self.count: + raise StopIteration + elt = self.item.dereference() + self.item = self.item + 1 + return ('[%d]' % current, elt) + + def __init__(self, val): + self.val = val + + def children(self): + return self._iterator(self.val['m_pItems'], self.val['m_nCount']) + + def to_string(self): + count = self.val['m_nCount'] + capacity = self.val['m_nSize'] + return ('length %d, capacity %d' % (int (count), int (capacity))) + + def display_hint(self): + return 'array' + class wxDateTimePrinter: def __init__(self, val): self.val = val @@ -81,6 +130,7 @@ def wxLookupFunction(val): # Using a list is probably ok for so few items but consider switching to a # set (or a dict and cache class types as the keys in it?) if needed later. types = ['wxString', + 'wxArrayString', 'wxDateTime', 'wxFileName', 'wxPoint',