source: rtems-tools/tools/gdb/python/rtems.py @ b117be8

4.104.115
Last change on this file since b117be8 was b117be8, checked in by Chris Johns <chrisj@…>, on 03/17/15 at 02:11:57

gdb/python: Update the support to a recent RTEMS.

  • Property mode set to 100644
File size: 10.0 KB
Line 
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
34import gdb
35import re
36
37import objects
38import threads
39import chains
40import watchdog
41import supercore
42import classic
43
44
45class 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
54class 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        vald = False
76        for num in arg.split():
77            try:
78                val = gdb.parse_and_eval(num)
79                num = int(val)
80            except:
81                print 'error: "%s" is not a number' % (num)
82                return True
83            id = objects.ident(num)
84            if not id.valid():
85                print 'Invalid object id'
86                return True
87
88            print 'API:%s Class:%s Node:%d Index:%d Id:%08X' % \
89                (id.api(), id._class(), id.node(), id.index(), id.value())
90            objectname = id.api() + '/' + id._class()
91
92            obj = objects.information.object(id).dereference()
93            if objectname in self.objects:
94                object = self.objects[objectname](obj)
95                valid = object.show(from_tty)
96        objects.information.invalidate()
97        return valid
98
99class rtems_index(gdb.Command):
100    '''Print object by index'''
101
102    api = 'classic'
103    _class = ''
104
105    def __init__(self,command):
106        super(rtems_index, self).__init__( command,
107                                           gdb.COMMAND_DATA,
108                                           gdb.COMPLETE_NONE)
109
110    def instance(self, obj):
111        '''Returns a n instance of corresponding object, the child should extend
112           this'''
113        return obj
114
115    def invoke(self, arg, from_tty):
116        maximum = objects.information.maximum(self.api, self._class)
117        minimum_id = objects.ident(objects.information.minimum_id(self.api, self._class))
118        maximum_id = objects.ident(objects.information.maximum_id(self.api, self._class))
119        args = arg.split()
120        valid = False
121        if len(args):
122            for val in args:
123                try:
124                    index = int(val, base = 0)
125                    if index < maximum:
126                        if index < minimum_id.index():
127                            print "error: %s is not an index (min is %d)" % (val,
128                                                                             minimum_id.index())
129                            return
130                    else:
131                        index = objects.ident(index).index()
132                except ValueError:
133                    print "error: %s is not an index" % (val)
134                    return
135                try:
136                    obj = objects.information.object_return(self.api,
137                                                            self._class,
138                                                            index)
139                except IndexError:
140                    print "error: index %s is invalid" % (index)
141                    return
142                instance = self.instance(obj)
143                valid = instance.show(from_tty)
144            objects.information.invalidate()
145        else:
146            print '-' * 70
147            print ' %s: %d [%08x -> %08x]' % (objects.information.name(self.api, self._class),
148                                             maximum, minimum_id.value(), maximum_id.value())
149            valid = True
150            for index in range(minimum_id.index(), minimum_id.index() + maximum):
151                if valid:
152                    print '-' * 70
153                valid = self.invoke(str(index), from_tty)
154        return valid
155
156class rtems_semaphore(rtems_index):
157    '''semaphore subcommand'''
158    _class = 'semaphores'
159
160    def __init__(self):
161        self.__doc__ = 'Display RTEMS semaphore(s) by index(es)'
162        super(rtems_semaphore, self).__init__('rtems semaphore')
163
164    def instance(self, obj):
165        return classic.semaphore(obj)
166
167class rtems_task(rtems_index):
168    '''tasks subcommand for rtems'''
169
170    _class = 'tasks'
171
172    def __init__(self):
173        self.__doc__ = 'Display RTEMS task(s) by index(es)'
174        super(rtems_task,self).__init__('rtems task')
175
176    def instance(self, obj):
177        return classic.task(obj)
178
179class rtems_message_queue(rtems_index):
180    '''Message Queue subcommand'''
181
182    _class = 'message_queues'
183
184    def __init__(self):
185        self.__doc__ = 'Display RTEMS message_queue(s) by index(es)'
186        super(rtems_message_queue,self).__init__('rtems mqueue')
187
188    def instance(self, obj):
189        return classic.message_queue(obj)
190
191class rtems_timer(rtems_index):
192    '''Index subcommand'''
193
194    _class = 'timers'
195
196    def __init__(self):
197        self.__doc__ = 'Display RTEMS timer(s) by index(es)'
198        super(rtems_timer, self).__init__('rtems timer')
199
200    def instance(self, obj):
201        return classic.timer(obj)
202
203class rtems_partition(rtems_index):
204    '''Partition subcommand'''
205
206    _class = 'partitions'
207
208    def __init__(self):
209        self.__doc__ = 'Display RTEMS partition(s) by index(es)'
210        super(rtems_partition, self).__init__('rtems partition')
211
212    def instance(self, obj):
213        return classic.partition(obj)
214
215class rtems_region(rtems_index):
216    '''Region subcomamnd'''
217
218    _class = 'regions'
219
220    def __init__(self):
221        self.__doc__ = 'Display RTEMS region(s) by index(es)'
222        super(rtems_region , self).__init__('rtems regions')
223
224    def instance(self, obj):
225        return classic.region(obj)
226
227class rtems_barrier(rtems_index):
228    '''Barrier subcommand'''
229
230    _class = 'barriers'
231
232    def __init__(self):
233        self.__doc__ = 'Display RTEMS barrier(s) by index(es)'
234        super(rtems_barrier , self).__init__('rtems barrier')
235
236    def instance(self, obj):
237        return classic.barrier(obj)
238
239class rtems_tod(gdb.Command):
240    '''Print rtems time of day'''
241
242    api = 'internal'
243    _class = 'time'
244
245    def __init__(self):
246        self.__doc__ = 'Display RTEMS time of day'
247        super(rtems_tod, self).__init__ \
248                    ('rtems tod', gdb.COMMAND_STATUS,gdb.COMPLETE_NONE)
249
250    def invoke(self, arg, from_tty):
251        if arg:
252            print "warning: commad takes no arguments!"
253        obj = objects.information.object_return(self.api, self._class)
254        instance = supercore.time_of_day(obj)
255        instance.show()
256        objects.information.invalidate()
257
258class rtems_watchdog_chain(gdb.Command):
259    '''Print watchdog ticks chain'''
260
261    api = 'internal'
262    _class = ''
263
264    def __init__(self,command):
265        super(rtems_watchdog_chain, self).__init__ \
266                                (command, gdb.COMMAND_DATA, gdb.COMPLETE_NONE)
267
268    def invoke(self, arg, from_tty):
269        obj = objects.information.object_return(self.api, self._class)
270
271        inst = chains.control(obj)
272
273        if inst.empty():
274            print '     error: empty chain'
275            return
276
277        nd = inst.first()
278        i = 0
279        while not nd.null():
280            wd = watchdog.control(nd.cast('Watchdog_Control'))
281            print ' #'+str(i)
282            print wd.to_string()
283            nd.next()
284            i += 1
285
286class rtems_wdt(rtems_watchdog_chain):
287
288    _class = 'wdticks'
289
290    def __init__(self):
291        self.__doc__ = 'Display watchdog ticks chain'
292        super(rtems_wdt, self).__init__('rtems wdticks')
293
294class rtems_wsec(rtems_watchdog_chain):
295
296    _class = 'wdseconds'
297
298    def __init__(self):
299        self.__doc__ = 'Display watchdog seconds chain'
300        super(rtems_wsec, self).__init__('rtems wdseconds')
301
302def create():
303    return (rtems(),
304            rtems_object(),
305            rtems_semaphore(),
306            rtems_task(),
307            rtems_message_queue(),
308            rtems_tod(),
309            rtems_wdt(),
310            rtems_wsec())
Note: See TracBrowser for help on using the repository browser.