1 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
2 | # Copyright 2010-2014 Chris Johns (chrisj@rtems.org) |
---|
3 | # All rights reserved. |
---|
4 | # |
---|
5 | # This file is part of the RTEMS Tools package in 'rtems-tools'. |
---|
6 | # |
---|
7 | # Redistribution and use in source and binary forms, with or without |
---|
8 | # modification, are permitted provided that the following conditions are met: |
---|
9 | # |
---|
10 | # 1. Redistributions of source code must retain the above copyright notice, |
---|
11 | # this list of conditions and the following disclaimer. |
---|
12 | # |
---|
13 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
14 | # this list of conditions and the following disclaimer in the documentation |
---|
15 | # and/or other materials provided with the distribution. |
---|
16 | # |
---|
17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
21 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
22 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
25 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
26 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
27 | # POSSIBILITY OF SUCH DAMAGE. |
---|
28 | # |
---|
29 | |
---|
30 | # |
---|
31 | # RTEMS Pretty Printers |
---|
32 | # |
---|
33 | |
---|
34 | import gdb |
---|
35 | import re |
---|
36 | |
---|
37 | import objects |
---|
38 | import threads |
---|
39 | import chains |
---|
40 | import watchdog |
---|
41 | import supercore |
---|
42 | import classic |
---|
43 | |
---|
44 | |
---|
45 | class rtems(gdb.Command): |
---|
46 | """Prefix command for RTEMS.""" |
---|
47 | |
---|
48 | def __init__(self): |
---|
49 | super(rtems, self).__init__('rtems', |
---|
50 | gdb.COMMAND_STATUS, |
---|
51 | gdb.COMPLETE_NONE, |
---|
52 | True) |
---|
53 | |
---|
54 | class rtems_object(gdb.Command): |
---|
55 | """Object sub-command for RTEMS""" |
---|
56 | |
---|
57 | objects = { |
---|
58 | 'classic/semaphores': lambda obj: classic.semaphore(obj), |
---|
59 | 'classic/tasks': lambda obj: classic.task(obj), |
---|
60 | 'classic/message_queues': lambda obj: classic.message_queue(obj), |
---|
61 | 'classic/timers' : lambda obj: classic.timer(obj), |
---|
62 | 'classic/partitions' : lambda obj: classic.partition(obj), |
---|
63 | 'classic/regions' : lambda obj: classic.region(obj), |
---|
64 | 'classic/barriers' : lambda obj: classic.barrier(obj) |
---|
65 | } |
---|
66 | |
---|
67 | def __init__(self): |
---|
68 | self.__doc__ = 'Display the RTEMS object given a numeric ID' \ |
---|
69 | '(Or a reference to the object).' |
---|
70 | super(rtems_object, self).__init__('rtems object', |
---|
71 | gdb.COMMAND_DATA, |
---|
72 | gdb.COMPLETE_SYMBOL) |
---|
73 | |
---|
74 | def invoke(self, arg, from_tty): |
---|
75 | for num in arg.split(): |
---|
76 | try: |
---|
77 | val = gdb.parse_and_eval(num) |
---|
78 | num = int(val) |
---|
79 | except: |
---|
80 | print 'error: "%s" is not a number' % (num) |
---|
81 | return |
---|
82 | id = objects.ident(num) |
---|
83 | if not id.valid(): |
---|
84 | print 'Invalid object id' |
---|
85 | return |
---|
86 | |
---|
87 | print 'API:%s Class:%s Node:%d Index:%d Id:%08X' % \ |
---|
88 | (id.api(), id._class(), id.node(), id.index(), id.value()) |
---|
89 | objectname = id.api() + '/' + id._class() |
---|
90 | |
---|
91 | obj = objects.information.object(id).dereference() |
---|
92 | if objectname in self.objects: |
---|
93 | object = self.objects[objectname](obj) |
---|
94 | object.show(from_tty) |
---|
95 | objects.information.invalidate() |
---|
96 | |
---|
97 | class rtems_index(gdb.Command): |
---|
98 | '''Print object by index''' |
---|
99 | |
---|
100 | api = 'classic' |
---|
101 | _class = '' |
---|
102 | |
---|
103 | def __init__(self,command): |
---|
104 | super(rtems_index, self).__init__( command, |
---|
105 | gdb.COMMAND_DATA, |
---|
106 | gdb.COMPLETE_NONE) |
---|
107 | |
---|
108 | def instance(self, obj): |
---|
109 | '''Returns a n instance of corresponding object, the child should extend |
---|
110 | this''' |
---|
111 | return obj |
---|
112 | |
---|
113 | def invoke(self, arg, from_tty): |
---|
114 | maximum = objects.information.maximum(self.api, self._class) |
---|
115 | minimum_id = objects.ident(objects.information.minimum_id(self.api, self._class)) |
---|
116 | maximum_id = objects.ident(objects.information.minimum_id(self.api, self._class)) |
---|
117 | args = arg.split() |
---|
118 | if len(args): |
---|
119 | for val in args: |
---|
120 | try: |
---|
121 | index = int(val, base = 0) |
---|
122 | if index < maximum: |
---|
123 | if index < minimum_id.index(): |
---|
124 | print "error: %s is not an index (min is %d)" % (val, |
---|
125 | minimum_id.index()) |
---|
126 | return |
---|
127 | else: |
---|
128 | index = objects.ident(index).index() |
---|
129 | except ValueError: |
---|
130 | print "error: %s is not an index" % (val) |
---|
131 | return |
---|
132 | try: |
---|
133 | obj = objects.information.object_return(self.api, |
---|
134 | self._class, |
---|
135 | index) |
---|
136 | except IndexError: |
---|
137 | print "error: index %s is invalid" % (index) |
---|
138 | return |
---|
139 | instance = self.instance(obj) |
---|
140 | instance.show(from_tty) |
---|
141 | objects.information.invalidate() |
---|
142 | else: |
---|
143 | print '-' * 70 |
---|
144 | print ' %s: %d [%08x -> %08x]' % (objects.information.name(self.api, self._class), |
---|
145 | maximum, minimum_id.value(), maximum_id.value()) |
---|
146 | for index in range(minimum_id.index(), minimum_id.index() + maximum): |
---|
147 | print '-' * 70 |
---|
148 | self.invoke(str(index), from_tty) |
---|
149 | |
---|
150 | class rtems_semaphore(rtems_index): |
---|
151 | '''semaphore subcommand''' |
---|
152 | _class = 'semaphores' |
---|
153 | |
---|
154 | def __init__(self): |
---|
155 | self.__doc__ = 'Display RTEMS semaphore(s) by index(es)' |
---|
156 | super(rtems_semaphore, self).__init__('rtems semaphore') |
---|
157 | |
---|
158 | def instance(self, obj): |
---|
159 | return classic.semaphore(obj) |
---|
160 | |
---|
161 | class rtems_task(rtems_index): |
---|
162 | '''tasks subcommand for rtems''' |
---|
163 | |
---|
164 | _class = 'tasks' |
---|
165 | |
---|
166 | def __init__(self): |
---|
167 | self.__doc__ = 'Display RTEMS task(s) by index(es)' |
---|
168 | super(rtems_task,self).__init__('rtems task') |
---|
169 | |
---|
170 | def instance(self, obj): |
---|
171 | return classic.task(obj) |
---|
172 | |
---|
173 | class rtems_message_queue(rtems_index): |
---|
174 | '''Message Queue subcommand''' |
---|
175 | |
---|
176 | _class = 'message_queues' |
---|
177 | |
---|
178 | def __init__(self): |
---|
179 | self.__doc__ = 'Display RTEMS message_queue(s) by index(es)' |
---|
180 | super(rtems_message_queue,self).__init__('rtems mqueue') |
---|
181 | |
---|
182 | def instance(self, obj): |
---|
183 | return classic.message_queue(obj) |
---|
184 | |
---|
185 | class rtems_timer(rtems_index): |
---|
186 | '''Index subcommand''' |
---|
187 | |
---|
188 | _class = 'timers' |
---|
189 | |
---|
190 | def __init__(self): |
---|
191 | self.__doc__ = 'Display RTEMS timer(s) by index(es)' |
---|
192 | super(rtems_timer, self).__init__('rtems timer') |
---|
193 | |
---|
194 | def instance(self, obj): |
---|
195 | return classic.timer(obj) |
---|
196 | |
---|
197 | class rtems_partition(rtems_index): |
---|
198 | '''Partition subcommand''' |
---|
199 | |
---|
200 | _class = 'partitions' |
---|
201 | |
---|
202 | def __init__(self): |
---|
203 | self.__doc__ = 'Display RTEMS partition(s) by index(es)' |
---|
204 | super(rtems_partition, self).__init__('rtems partition') |
---|
205 | |
---|
206 | def instance(self, obj): |
---|
207 | return classic.partition(obj) |
---|
208 | |
---|
209 | class rtems_region(rtems_index): |
---|
210 | '''Region subcomamnd''' |
---|
211 | |
---|
212 | _class = 'regions' |
---|
213 | |
---|
214 | def __init__(self): |
---|
215 | self.__doc__ = 'Display RTEMS region(s) by index(es)' |
---|
216 | super(rtems_region , self).__init__('rtems regions') |
---|
217 | |
---|
218 | def instance(self, obj): |
---|
219 | return classic.region(obj) |
---|
220 | |
---|
221 | class rtems_barrier(rtems_index): |
---|
222 | '''Barrier subcommand''' |
---|
223 | |
---|
224 | _class = 'barriers' |
---|
225 | |
---|
226 | def __init__(self): |
---|
227 | self.__doc__ = 'Display RTEMS barrier(s) by index(es)' |
---|
228 | super(rtems_barrier , self).__init__('rtems barrier') |
---|
229 | |
---|
230 | def instance(self, obj): |
---|
231 | return classic.barrier(obj) |
---|
232 | |
---|
233 | class rtems_tod(gdb.Command): |
---|
234 | '''Print rtems time of day''' |
---|
235 | |
---|
236 | api = 'internal' |
---|
237 | _class = 'time' |
---|
238 | |
---|
239 | def __init__(self): |
---|
240 | self.__doc__ = 'Display RTEMS time of day' |
---|
241 | super(rtems_tod, self).__init__ \ |
---|
242 | ('rtems tod', gdb.COMMAND_STATUS,gdb.COMPLETE_NONE) |
---|
243 | |
---|
244 | def invoke(self, arg, from_tty): |
---|
245 | |
---|
246 | if arg: |
---|
247 | print "warning: commad takes no arguments!" |
---|
248 | |
---|
249 | obj = objects.information.object_return(self.api,self._class) |
---|
250 | instance = supercore.time_of_day(obj) |
---|
251 | instance.show() |
---|
252 | objects.information.invalidate() |
---|
253 | |
---|
254 | class rtems_watchdog_chain(gdb.Command): |
---|
255 | '''Print watchdog ticks chain''' |
---|
256 | |
---|
257 | api = 'internal' |
---|
258 | _class = '' |
---|
259 | |
---|
260 | def __init__(self,command): |
---|
261 | super(rtems_watchdog_chain, self).__init__ \ |
---|
262 | (command, gdb.COMMAND_DATA, gdb.COMPLETE_NONE) |
---|
263 | |
---|
264 | def invoke(self, arg, from_tty): |
---|
265 | obj = objects.information.object_return(self.api, self._class) |
---|
266 | |
---|
267 | inst = chains.control(obj) |
---|
268 | |
---|
269 | if inst.empty(): |
---|
270 | print ' error: empty chain' |
---|
271 | return |
---|
272 | |
---|
273 | nd = inst.first() |
---|
274 | i = 0 |
---|
275 | while not nd.null(): |
---|
276 | wd = watchdog.control(nd.cast('Watchdog_Control')) |
---|
277 | print ' #'+str(i) |
---|
278 | print wd.to_string() |
---|
279 | nd.next() |
---|
280 | i += 1 |
---|
281 | |
---|
282 | class rtems_wdt(rtems_watchdog_chain): |
---|
283 | |
---|
284 | _class = 'wdticks' |
---|
285 | |
---|
286 | def __init__(self): |
---|
287 | self.__doc__ = 'Display watchdog ticks chain' |
---|
288 | super(rtems_wdt, self).__init__('rtems wdticks') |
---|
289 | |
---|
290 | class rtems_wsec(rtems_watchdog_chain): |
---|
291 | |
---|
292 | _class = 'wdseconds' |
---|
293 | |
---|
294 | def __init__(self): |
---|
295 | self.__doc__ = 'Display watchdog seconds chain' |
---|
296 | super(rtems_wsec, self).__init__('rtems wdseconds') |
---|
297 | |
---|
298 | def create(): |
---|
299 | return (rtems(), |
---|
300 | rtems_object(), |
---|
301 | rtems_semaphore(), |
---|
302 | rtems_task(), |
---|
303 | rtems_message_queue(), |
---|
304 | rtems_tod(), |
---|
305 | rtems_wdt(), |
---|
306 | rtems_wsec()) |
---|