source: rtems-tools/tools/gdb/python/rtems.py @ 8da0a37

4.104.115
Last change on this file since 8da0a37 was 8da0a37, checked in by Dhananjay Balan <mb.dhananjay@…>, on 08/21/13 at 13:01:01

Complete index subcommands.

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