X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6df26ddbf7eb563e66bee2313e71d1c0241b351a..45416752623a6ac0df3a8f5f55c1933ff52e1dbb:/misc/gdb/print.py diff --git a/misc/gdb/print.py b/misc/gdb/print.py index 449edba1ea..40084758e3 100755 --- a/misc/gdb/print.py +++ b/misc/gdb/print.py @@ -5,15 +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. +import datetime # shamelessly stolen from std::string example class wxStringPrinter: @@ -21,11 +22,38 @@ class wxStringPrinter: self.val = val def to_string(self): - return '"' + self.val['m_impl']['_M_dataplus']['_M_p'].string() + '"' + return self.val['m_impl']['_M_dataplus']['_M_p'] def display_hint(self): return 'string' +class wxDateTimePrinter: + def __init__(self, val): + self.val = val + + def to_string(self): + # A value of type wxLongLong can't be used in Python arithmetic + # expressions directly so we need to convert it to long long first and + # then cast to int explicitly to be able to use it as a timestamp. + msec = self.val['m_time'].cast(gdb.lookup_type('long long')) + if msec == 0x8000000000000000: + return 'NONE' + sec = int(msec / 1000) + return datetime.datetime.fromtimestamp(sec).isoformat(' ') + +class wxFileNamePrinter: + def __init__(self, val): + self.val = val + + def to_string(self): + # It is simpler to just call the internal function here than to iterate + # over m_dirs array ourselves. The disadvantage of this approach is + # that it requires a live inferior process and so doesn't work when + # debugging using only a core file. If this ever becomes a serious + # problem, this should be rewritten to use m_dirs and m_name and m_ext. + return gdb.parse_and_eval('((wxFileName*)%s)->GetFullPath(0)' % + self.val.address) + class wxXYPrinterBase: def __init__(self, val): self.x = val['x'] @@ -53,7 +81,12 @@ class wxRectPrinter(wxXYPrinterBase): 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'] + types = ['wxString', + 'wxDateTime', + 'wxFileName', + 'wxPoint', + 'wxSize', + 'wxRect'] for t in types: if val.type.tag == t: