1 | # |
---|
2 | # RTEMS Supercore pretty printers for GDB |
---|
3 | # |
---|
4 | import objects |
---|
5 | import itertools |
---|
6 | |
---|
7 | class id_printer: |
---|
8 | """Print an object given the ID. Print using the struct display hint and an |
---|
9 | iterator.""" |
---|
10 | |
---|
11 | class iterator: |
---|
12 | """Use an iterator for each field expanded from the id so GDB output |
---|
13 | is formatted correctly.""" |
---|
14 | |
---|
15 | def __init__(self, id): |
---|
16 | self.id = id |
---|
17 | self.count = 0 |
---|
18 | |
---|
19 | def __iter__(self): |
---|
20 | return self |
---|
21 | |
---|
22 | def next(self): |
---|
23 | self.count += 1 |
---|
24 | if self.count == 1: |
---|
25 | return int(self.id.value()) |
---|
26 | elif self.count == 2: |
---|
27 | return self.id.node() |
---|
28 | elif self.count == 3: |
---|
29 | return self.id.api() |
---|
30 | elif self.count == 4: |
---|
31 | return self.id._class() |
---|
32 | elif self.count == 5: |
---|
33 | return self.id.index() |
---|
34 | raise StopIteration |
---|
35 | |
---|
36 | def __init__(self, id): |
---|
37 | self.id = objects.ident(id) |
---|
38 | |
---|
39 | def to_string(self): |
---|
40 | return '' |
---|
41 | |
---|
42 | @staticmethod |
---|
43 | def key(i): |
---|
44 | if i == 0: |
---|
45 | return 'id' |
---|
46 | elif i == 1: |
---|
47 | return 'node' |
---|
48 | elif i == 2: |
---|
49 | return 'api' |
---|
50 | elif i == 3: |
---|
51 | return 'class' |
---|
52 | elif i == 4: |
---|
53 | return 'index' |
---|
54 | return 'bad' |
---|
55 | |
---|
56 | def children(self): |
---|
57 | counter = itertools.imap (self.key, itertools.count()) |
---|
58 | return itertools.izip (counter, self.iterator(self.id)) |
---|
59 | |
---|
60 | def display_hint (self): |
---|
61 | return 'struct' |
---|
62 | |
---|
63 | class name_printer: |
---|
64 | """Pretty printer for an object's name. It has to guess the type as no |
---|
65 | information is available to help determine it.""" |
---|
66 | |
---|
67 | def __init__(self, nameval): |
---|
68 | self.name = objects.name(nameval) |
---|
69 | |
---|
70 | def to_string(self): |
---|
71 | return str(self.name) |
---|
72 | |
---|
73 | class control_printer: |
---|
74 | |
---|
75 | class iterator: |
---|
76 | """Use an iterator for each field expanded from the id so GDB output |
---|
77 | is formatted correctly.""" |
---|
78 | |
---|
79 | def __init__(self, object): |
---|
80 | self.object = object |
---|
81 | self.count = 0 |
---|
82 | |
---|
83 | def __iter__(self): |
---|
84 | return self |
---|
85 | |
---|
86 | def next(self): |
---|
87 | self.count += 1 |
---|
88 | if self.count == 1: |
---|
89 | return self.object.node() |
---|
90 | elif self.count == 2: |
---|
91 | return self.object.id() |
---|
92 | elif self.count == 3: |
---|
93 | return self.object.name() |
---|
94 | raise StopIteration |
---|
95 | |
---|
96 | def to_string(self): |
---|
97 | return '' |
---|
98 | |
---|
99 | def __init__(self, object): |
---|
100 | self.object = objects.control(object) |
---|
101 | |
---|
102 | @staticmethod |
---|
103 | def key(i): |
---|
104 | if i == 0: |
---|
105 | return 'Node' |
---|
106 | elif i == 1: |
---|
107 | return 'id' |
---|
108 | elif i == 2: |
---|
109 | return 'name' |
---|
110 | return 'bad' |
---|
111 | |
---|
112 | def children(self): |
---|
113 | counter = itertools.imap (self.key, itertools.count()) |
---|
114 | return itertools.izip (counter, self.iterator(self.object)) |
---|
115 | |
---|
116 | def display_hint (self): |
---|
117 | return 'struct' |
---|
118 | |
---|
119 | |
---|
120 | class state_printer: |
---|
121 | |
---|
122 | def __init__(self, state): |
---|
123 | self.state = threads.state(state) |
---|
124 | def to_string(self): |
---|
125 | return self.state.to_string() |
---|
126 | |
---|
127 | class chains_printer: |
---|
128 | |
---|
129 | def __init__(self,chain): |
---|
130 | self.chain = chains.control(chain) |
---|
131 | |
---|
132 | def to_string(self): |
---|
133 | return "First:"+str(self.chain.first())+"\n Last:"+str(self.chain.last()) |
---|
134 | |
---|
135 | class node_printer: |
---|
136 | def __init__(self, node): |
---|
137 | self.node = chains.node(node) |
---|
138 | |
---|
139 | def to_string(self): |
---|
140 | return "Node: "+str(self.node)+" Next: "+str(self.node.next())+" Prev: "+str(self.node.previous()) |
---|