Destroyed Build Tests (markdown)
[dealii.wiki.git] / dot-gdbinit.md
1 ```python
2 set print pretty 1
3
4 python
5
6 import gdb
7 import itertools
8 import re
9
10 # Try to use the new-style pretty-printing if available.
11 _use_gdb_pp = True
12 try:
13     import gdb.printing
14 except ImportError:
15     _use_gdb_pp = False
16
17 class PointPrinter:
18     "Print dealii::Point"
19
20     def __init__ (self, typename, val):
21         self.typename = typename
22         self.val = val
23
24     def to_string (self):
25         return '%s' % self.val['values']
26
27
28 class TensorPrinter:
29     "Print dealii::Tensor"
30
31     def __init__ (self, typename, val):
32         self.typename = typename
33         self.val = val
34
35     def to_string (self):
36         # we could distinguish between Tensor<1,dim> and Tensor<2,dim>
37         # by asking self.val.type.template_argument(0) but unfortunately
38         # template_argument does not handle value arguments...
39         try:
40             return self.val['values']
41         except:
42             return self.val['subtensor']
43
44
45 class TriaIteratorPrinter:
46     "Print dealii::TriaIterator"
47
48     def __init__ (self, typename, val):
49         self.typename = typename
50         self.val = val
51
52     def to_string (self):
53         if re.compile('.*DoF.*').match('%s' % self.val.type.template_argument(0)):
54           return ('{\n  triangulation = %s,\n  dof_handler = %s,\n  level = %d,\n  index = %d\n}' %
55               (self.val['accessor']['tria'],
56               self.val['accessor']['dof_handler'],
57               self.val['accessor']['present_level'],
58               self.val['accessor']['present_index']))
59         else:
60           return ('{\n  triangulation = %s,\n  level = %d,\n  index = %d\n}' %
61               (self.val['accessor']['tria'],
62               self.val['accessor']['present_level'],
63               self.val['accessor']['present_index']))
64
65
66
67 class VectorPrinter:
68     "Print dealii::Vector"
69
70     class _iterator:
71         def __init__ (self, start, size):
72             self.start = start
73             self.size = size
74             self.count = 0
75
76         def __iter__(self):
77             return self
78
79         def next(self):
80             if self.count == self.size:
81                 raise StopIteration
82             count = self.count
83             self.count = self.count + 1
84             self.start = self.start + 1
85             elt = self.start.dereference()
86             return ('[%d]' % count, elt)
87
88     def __init__ (self, typename, val):
89         self.typename = typename
90         self.val = val
91
92     def children(self):
93         return self._iterator(self.val['val'],
94                               self.val['vec_size'])
95
96     def to_string_x (self):
97         return ('%s[%d] = {%s}' % (self.val.type.template_argument(0),
98                                    self.val['vec_size'],
99                    self.val['val'].dereference()))
100
101     def to_string (self):
102         return ('%s[%d]' % (self.val.type.template_argument(0),
103                             self.val['vec_size']))
104
105     def display_hint(self):
106         return 'array'
107
108
109 class QuadraturePrinter:
110     "Print dealii::Quadrature"
111
112     def __init__ (self, typename, val):
113         self.typename = typename
114         self.val = val
115
116     def to_string (self):
117         return ('{\n  points = {%s},\n  weights={%s}\n}' %
118              (self.val['quadrature_points'],
119           self.val['weights']))
120
121
122
123 # A "regular expression" printer which conforms to the
124 # "SubPrettyPrinter" protocol from gdb.printing.
125 class RxPrinter(object):
126     def __init__(self, name, function):
127         super(RxPrinter, self).__init__()
128         self.name = name
129         self.function = function
130         self.enabled = True
131
132     def invoke(self, value):
133         if not self.enabled:
134             return None
135         return self.function(self.name, value)
136
137
138 # A pretty-printer that conforms to the "PrettyPrinter" protocol from
139 # gdb.printing.  It can also be used directly as an old-style printer.
140 class Printer(object):
141     def __init__(self, name):
142         super(Printer, self).__init__()
143         self.name = name
144         self.subprinters = []
145         self.lookup = {}
146         self.enabled = True
147         self.compiled_rx = re.compile('^([a-zA-Z0-9_:]+)<.*>$')
148
149     def add(self, name, function):
150         # A small sanity check.
151         # FIXME
152         if not self.compiled_rx.match(name + '<>'):
153             raise ValueError, 'libstdc++ programming error: "%s" does not match' % name
154         printer = RxPrinter(name, function)
155         self.subprinters.append(printer)
156         self.lookup[name] = printer
157
158     @staticmethod
159     def get_basic_type(type):
160         # If it points to a reference, get the reference.
161         if type.code == gdb.TYPE_CODE_REF:
162             type = type.target ()
163
164         # Get the unqualified type, stripped of typedefs.
165         type = type.unqualified ().strip_typedefs ()
166
167         return type.tag
168
169     def __call__(self, val):
170         typename = self.get_basic_type(val.type)
171         if not typename:
172             return None
173
174         # All the types we match are template types, so we can use a
175         # dictionary.
176         match = self.compiled_rx.match(typename)
177         if not match:
178             return None
179
180         basename = match.group(1)
181         if basename in self.lookup:
182             return self.lookup[basename].invoke(val)
183
184         # Cannot find a pretty printer.  Return None.
185         return None
186
187 dealii_printer = None
188
189 def build_dealii_dictionary ():
190     global dealii_printer
191
192     dealii_printer = Printer("deal.II")
193     dealii_printer.add ('dealii::Point', PointPrinter)
194     dealii_printer.add ('dealii::Tensor', TensorPrinter)
195     dealii_printer.add ('dealii::TriaRawIterator', TriaIteratorPrinter)
196     dealii_printer.add ('dealii::TriaIterator', TriaIteratorPrinter)
197     dealii_printer.add ('dealii::TriaActiveIterator', TriaIteratorPrinter)
198     dealii_printer.add ('dealii::Vector', VectorPrinter)
199     dealii_printer.add ('dealii::Quadrature', QuadraturePrinter)
200     dealii_printer.add ('dealii::QGauss', QuadraturePrinter)
201     dealii_printer.add ('dealii::QTrapez', QuadraturePrinter)
202     dealii_printer.add ('dealii::QIterated', QuadraturePrinter)
203
204 def register_dealii_printers (obj):
205     "Register deal.II pretty-printers with objfile Obj."
206
207     global _use_gdb_pp
208     global dealii_printer
209
210     build_dealii_dictionary ()
211     if _use_gdb_pp:
212         gdb.printing.register_pretty_printer(obj, dealii_printer)
213     else:
214         if obj is None:
215             obj = gdb
216         obj.pretty_printers.append(dealii_printer)
217
218
219 register_dealii_printers (None)
220
221 end
222 ```

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.