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

4.104.115
Last change on this file since a7176a8 was a7176a8, checked in by Dhananjay Balan <mb.dhananjay@…>, on 08/25/13 at 17:33:44

Add watchdog ticks command.

  • ToDo? : Fix watchdog states.
  • Property mode set to 100644
File size: 6.8 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 supercore
15import classic
16
17
18class 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
27class 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
70class 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
105class 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
116class 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
129class 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
141class 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
153class 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
165class 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
177class 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
189class 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
210class 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
235class 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
Note: See TracBrowser for help on using the repository browser.