1 | # |
---|
2 | # RTEMS Pretty Printers |
---|
3 | # Copyright 2010 Chris Johns (chrisj@rtems.org) |
---|
4 | # |
---|
5 | # $Id$ |
---|
6 | # |
---|
7 | |
---|
8 | import gdb |
---|
9 | import re |
---|
10 | |
---|
11 | import objects |
---|
12 | import threads |
---|
13 | import chains |
---|
14 | import supercore |
---|
15 | import classic |
---|
16 | |
---|
17 | |
---|
18 | class rtems(gdb.Command): |
---|
19 | """Prefix command for RTEMS.""" |
---|
20 | |
---|
21 | def __init__(self): |
---|
22 | super(rtems, self).__init__('rtems', |
---|
23 | gdb.COMMAND_STATUS, |
---|
24 | gdb.COMPLETE_NONE, |
---|
25 | True) |
---|
26 | |
---|
27 | class rtems_object(gdb.Command): |
---|
28 | """Object sub-command for RTEMS""" |
---|
29 | |
---|
30 | objects = { |
---|
31 | 'classic/semaphores': lambda obj: classic.semaphore(obj), |
---|
32 | 'classic/tasks': lambda obj: classic.task(obj), |
---|
33 | 'classic/message_queues': lambda obj: classic.message_queue(obj), |
---|
34 | 'classic/timers' : lambda obj: classic.timer(obj), |
---|
35 | 'classic/partitions' : lambda obj: classic.partition(obj), |
---|
36 | 'classic/regions' : lambda obj: classic.region(obj), |
---|
37 | 'classic/barriers' : lambda obj: classic.barrier(obj) |
---|
38 | } |
---|
39 | |
---|
40 | def __init__(self): |
---|
41 | self.__doc__ = 'Display the RTEMS object given a numeric ID \ |
---|
42 | (Or a reference to rtems_object).' |
---|
43 | super(rtems_object, self).__init__('rtems object', |
---|
44 | gdb.COMMAND_DATA, |
---|
45 | gdb.COMPLETE_SYMBOL) |
---|
46 | |
---|
47 | def invoke(self, arg, from_tty): |
---|
48 | for num in arg.split(): |
---|
49 | try: |
---|
50 | val = gdb.parse_and_eval(num) |
---|
51 | num = int(val) |
---|
52 | except: |
---|
53 | print 'error: "%s" is not a number' % (num) |
---|
54 | return |
---|
55 | id = objects.ident(num) |
---|
56 | if not id.valid(): |
---|
57 | print 'Invalid object id' |
---|
58 | return |
---|
59 | |
---|
60 | print 'API:%s Class:%s Node:%d Index:%d Id:%08X' % \ |
---|
61 | (id.api(), id._class(), id.node(), id.index(), id.value()) |
---|
62 | objectname = id.api() + '/' + id._class() |
---|
63 | |
---|
64 | obj = objects.information.object(id).dereference() |
---|
65 | if objectname in self.objects: |
---|
66 | object = self.objects[objectname](obj) |
---|
67 | object.show(from_tty) |
---|
68 | objects.information.invalidate() |
---|
69 | |
---|
70 | class rtems_index(gdb.Command): |
---|
71 | '''Print object by index''' |
---|
72 | |
---|
73 | api = 'classic' |
---|
74 | _class = '' |
---|
75 | |
---|
76 | def __init__(self,command): |
---|
77 | super(rtems_index, self).__init__( command, |
---|
78 | gdb.COMMAND_DATA, |
---|
79 | gdb.COMPLETE_NONE) |
---|
80 | |
---|
81 | def instance(self,obj): |
---|
82 | '''Returns a n instance of corresponding object, the child should extend this''' |
---|
83 | return obj |
---|
84 | |
---|
85 | def invoke(self, arg, from_tty): |
---|
86 | for val in arg.split(): |
---|
87 | try: |
---|
88 | index = int(val) |
---|
89 | except ValueError: |
---|
90 | print "error: %s is not an index" % (val) |
---|
91 | return |
---|
92 | try: |
---|
93 | obj = objects.information.object_return( self.api, |
---|
94 | self._class, |
---|
95 | index ).dereference() |
---|
96 | except IndexError: |
---|
97 | print "error: index %s is invalid" % (index) |
---|
98 | return |
---|
99 | |
---|
100 | instance = self.instance(obj) |
---|
101 | instance.show(from_tty) |
---|
102 | objects.information.invalidate() |
---|
103 | |
---|
104 | |
---|
105 | class rtems_semaphore(rtems_index): |
---|
106 | '''semaphore subcommand''' |
---|
107 | _class = 'semaphores' |
---|
108 | |
---|
109 | def __init__(self): |
---|
110 | self.__doc__ = 'Display RTEMS semaphore(s) by index(es)' |
---|
111 | super(rtems_semaphore, self).__init__('rtems semaphore') |
---|
112 | |
---|
113 | def instance(self,obj): |
---|
114 | return classic.semaphore(obj) |
---|
115 | |
---|
116 | class rtems_task(rtems_index): |
---|
117 | '''tasks subcommand for rtems''' |
---|
118 | |
---|
119 | _class = 'tasks' |
---|
120 | |
---|
121 | def __init__(self): |
---|
122 | self.__doc__ = 'Display RTEMS task(s) by index(es)' |
---|
123 | super(rtems_task,self).__init__('rtems task') |
---|
124 | |
---|
125 | def instance(self,obj): |
---|
126 | return classic.task(obj) |
---|
127 | |
---|
128 | |
---|
129 | class rtems_message_queue(rtems_index): |
---|
130 | '''Message Queue subcommand''' |
---|
131 | |
---|
132 | _class = 'message_queues' |
---|
133 | |
---|
134 | def __init__(self): |
---|
135 | self.__doc__ = 'Display RTEMS message_queue(s) by index(es)' |
---|
136 | super(rtems_message_queue,self).__init__('rtems mqueue') |
---|
137 | |
---|
138 | def instance(self,obj): |
---|
139 | return classic.message_queue(obj) |
---|
140 | |
---|
141 | class rtems_timer(rtems_index): |
---|
142 | '''Index subcommand''' |
---|
143 | |
---|
144 | _class = 'timers' |
---|
145 | |
---|
146 | def __init__(self): |
---|
147 | self.__doc__ = 'Display RTEMS timer(s) by index(es)' |
---|
148 | super(rtems_timer, self).__init__('rtems timer') |
---|
149 | |
---|
150 | def instance(self,obj): |
---|
151 | return classic.timer(obj) |
---|
152 | |
---|
153 | class rtems_partition(rtems_index): |
---|
154 | '''Partition subcommand''' |
---|
155 | |
---|
156 | _class = 'partitions' |
---|
157 | |
---|
158 | def __init__(self): |
---|
159 | self.__doc__ = 'Display RTEMS partition(s) by index(es)' |
---|
160 | super(rtems_partition, self).__init__('rtems partition') |
---|
161 | |
---|
162 | def instance(self, obj): |
---|
163 | return classic.partition(obj) |
---|
164 | |
---|
165 | class rtems_region(rtems_index): |
---|
166 | '''Region subcomamnd''' |
---|
167 | |
---|
168 | _class = 'regions' |
---|
169 | |
---|
170 | def __init__(self): |
---|
171 | self.__doc__ = 'Display RTEMS region(s) by index(es)' |
---|
172 | super(rtems_region , self).__init__('rtems regions') |
---|
173 | |
---|
174 | def instance(self, obj): |
---|
175 | return classic.region(obj) |
---|
176 | |
---|
177 | class rtems_barrier(rtems_index): |
---|
178 | '''Barrier subcommand''' |
---|
179 | |
---|
180 | _class = 'barriers' |
---|
181 | |
---|
182 | def __init__(self): |
---|
183 | self.__doc__ = 'Display RTEMS barrier(s) by index(es)' |
---|
184 | super(rtems_barrier , self).__init__('rtems barrier') |
---|
185 | |
---|
186 | def instance(self, obj): |
---|
187 | return classic.barrier(obj) |
---|
188 | |
---|
189 | class rtems_tod(gdb.Command): |
---|
190 | '''Print rtems time of day''' |
---|
191 | |
---|
192 | api = 'internal' |
---|
193 | _class = 'time' |
---|
194 | |
---|
195 | def __init__(self): |
---|
196 | self.__doc__ = 'Display RTEMS time of day' |
---|
197 | super(rtems_tod, self).__init__ \ |
---|
198 | ('rtems tod', gdb.COMMAND_STATUS,gdb.COMPLETE_NONE) |
---|
199 | |
---|
200 | def invoke(self, arg, from_tty): |
---|
201 | |
---|
202 | if arg: |
---|
203 | print "warning: commad takes no arguments!" |
---|
204 | |
---|
205 | obj = objects.information.object_return(self.api,self._class) |
---|
206 | instance = supercore.time_of_day(obj) |
---|
207 | instance.show() |
---|
208 | objects.information.invalidate() |
---|
209 | |
---|
210 | class rtems_watchdog_chain(gdb.Command): |
---|
211 | '''Print watchdog ticks chain''' |
---|
212 | |
---|
213 | api = 'internal' |
---|
214 | _class = '' |
---|
215 | |
---|
216 | def __init__(self,command): |
---|
217 | super(rtems_watchdog_chain, self).__init__ \ |
---|
218 | (command, gdb.COMMAND_DATA, gdb.COMPLETE_NONE) |
---|
219 | |
---|
220 | def invoke(self, arg, from_tty): |
---|
221 | obj = objects.information.object_return(self.api, self._class) |
---|
222 | |
---|
223 | inst = chains.control(obj) |
---|
224 | |
---|
225 | if inst.empty(): |
---|
226 | print ' error: empty chain' |
---|
227 | return |
---|
228 | |
---|
229 | nd = inst.first() |
---|
230 | while not nd.null(): |
---|
231 | wd = watchdog.control(nd.cast('Watchdog_Control')) |
---|
232 | wd.show() |
---|
233 | nd = nd.next() |
---|
234 | |
---|
235 | class rtems_wdt(rtems_watchdog_chain): |
---|
236 | |
---|
237 | _class = 'wdticks' |
---|
238 | |
---|
239 | def __init__(self): |
---|
240 | self.__doc__ = 'Display watchdog ticks chain' |
---|
241 | super(rtems_wdt, self).__init__('rtems wdticks') |
---|
242 | |
---|