Add wxArrayString pretty printer for gdb

Closes #18276.
This commit is contained in:
Teodor Petrov 2018-08-15 08:30:27 +03:00 committed by Vadim Zeitlin
parent ae1fa08188
commit 5b0dcfec83

View File

@ -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',