source: rtems-tools/tools/gdb/python/rtems.py @ 7a415d4

4.104.115
Last change on this file since 7a415d4 was a245635, checked in by Dhananjay Balan <mb.dhananjay@…>, on 08/24/13 at 09:38:16

Add subcommand

rtems tod - prints the time of day.

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