X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3b9aa4e82a8d0d7c58d9eba082402d6e4c4e5ce7..e8f25fcf5dc630fda8569c1d063c4e19770de9eb:/misc/gdb/print.py diff --git a/misc/gdb/print.py b/misc/gdb/print.py index 46a71d0056..9ac0b8e36e 100755 --- a/misc/gdb/print.py +++ b/misc/gdb/print.py @@ -5,11 +5,16 @@ # in the future...) # Author: Vadim Zeitlin # Created: 2009-01-04 -# RCS-Id: $Id:$ +# RCS-Id: $Id$ # Copyright: (c) 2009 Vadim Zeitlin -# License: wxWindows licence +# Licence: wxWindows licence ############################################################################### +# Define wxFooPrinter class implementing (at least) to_string() method for each +# wxFoo class we want to pretty print. Then just add wxFoo to the types array +# in wxLookupFunction at the bottom of this file. + + # shamelessly stolen from std::string example class wxStringPrinter: def __init__(self, val): @@ -18,4 +23,44 @@ class wxStringPrinter: def to_string(self): return '"' + self.val['m_impl']['_M_dataplus']['_M_p'].string() + '"' -gdb.pretty_printers['^wxString$'] = wxStringPrinter + def display_hint(self): + return 'string' + +class wxXYPrinterBase: + def __init__(self, val): + self.x = val['x'] + self.y = val['y'] + +class wxPointPrinter(wxXYPrinterBase): + def to_string(self): + return '(%d, %d)' % (self.x, self.y) + +class wxSizePrinter(wxXYPrinterBase): + def to_string(self): + return '%d*%d' % (self.x, self.y) + +class wxRectPrinter(wxXYPrinterBase): + def __init__(self, val): + wxXYPrinterBase.__init__(self, val) + self.width = val['width'] + self.height = val['height'] + + def to_string(self): + return '(%d, %d) %d*%d' % (self.x, self.y, self.width, self.height) + + +# The function looking up the pretty-printer to use for the given value. +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', 'wxPoint', 'wxSize', 'wxRect'] + + for t in types: + if val.type.tag == t: + # Not sure if this is the best name to create the object of a class + # by name but at least it beats eval() + return globals()[t + 'Printer'](val) + + return None + +gdb.pretty_printers.append(wxLookupFunction)