source: rtems-tools/tools/gdb/python/rtems.py @ 1fcff75

4.104.115
Last change on this file since 1fcff75 was 1fcff75, checked in by Dhananjay Balan <mb.dhananjay@…>, on 08/26/13 at 15:05:57

Fix wdticks command

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