]>
git.saurik.com Git - wxWidgets.git/blob - misc/gdb/print.py
1 ###############################################################################
2 # Name: misc/gdb/print.py
3 # Purpose: pretty-printers for wx data structures: this file is meant to
4 # be sourced from gdb using "source -p" (or, better, autoloaded
6 # Author: Vadim Zeitlin
8 # Copyright: (c) 2009 Vadim Zeitlin
9 # Licence: wxWindows licence
10 ###############################################################################
12 # Define wxFooPrinter class implementing (at least) to_string() method for each
13 # wxFoo class we want to pretty print. Then just add wxFoo to the types array
14 # in wxLookupFunction at the bottom of this file.
18 # shamelessly stolen from std::string example
19 class wxStringPrinter
:
20 def __init__(self
, val
):
24 return self
.val
['m_impl']['_M_dataplus']['_M_p']
26 def display_hint(self
):
29 class wxDateTimePrinter
:
30 def __init__(self
, val
):
34 # A value of type wxLongLong can't be used in Python arithmetic
35 # expressions directly so we need to convert it to long long first and
36 # then cast to int explicitly to be able to use it as a timestamp.
37 msec
= self
.val
['m_time'].cast(gdb
.lookup_type('long long'))
38 if msec
== 0x8000000000000000:
40 sec
= int(msec
/ 1000)
41 return datetime
.datetime
.fromtimestamp(sec
).isoformat(' ')
43 class wxFileNamePrinter
:
44 def __init__(self
, val
):
48 # It is simpler to just call the internal function here than to iterate
49 # over m_dirs array ourselves. The disadvantage of this approach is
50 # that it requires a live inferior process and so doesn't work when
51 # debugging using only a core file. If this ever becomes a serious
52 # problem, this should be rewritten to use m_dirs and m_name and m_ext.
53 return gdb
.parse_and_eval('((wxFileName*)%s)->GetFullPath(0)' %
56 class wxXYPrinterBase
:
57 def __init__(self
, val
):
61 class wxPointPrinter(wxXYPrinterBase
):
63 return '(%d, %d)' % (self
.x
, self
.y
)
65 class wxSizePrinter(wxXYPrinterBase
):
67 return '%d*%d' % (self
.x
, self
.y
)
69 class wxRectPrinter(wxXYPrinterBase
):
70 def __init__(self
, val
):
71 wxXYPrinterBase
.__init
__(self
, val
)
72 self
.width
= val
['width']
73 self
.height
= val
['height']
76 return '(%d, %d) %d*%d' % (self
.x
, self
.y
, self
.width
, self
.height
)
79 # The function looking up the pretty-printer to use for the given value.
80 def wxLookupFunction(val
):
81 # Using a list is probably ok for so few items but consider switching to a
82 # set (or a dict and cache class types as the keys in it?) if needed later.
92 # Not sure if this is the best name to create the object of a class
93 # by name but at least it beats eval()
94 return globals()[t
+ 'Printer'](val
)
98 gdb
.pretty_printers
.append(wxLookupFunction
)