summaryrefslogtreecommitdiffstats
path: root/tools/gdb/python/rtems.py
blob: 534cb0d1911d9570f1dd8fc6abb7293a0642b226 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# RTEMS Tools Project (http://www.rtems.org/)
# Copyright 2010-2014 Chris Johns (chrisj@rtems.org)
# All rights reserved.
#
# This file is part of the RTEMS Tools package in 'rtems-tools'.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

#
# RTEMS Pretty Printers
#

import gdb
import re

import objects
import threads
import chains
import watchdog
import supercore
import classic


class rtems(gdb.Command):
    """Prefix command for RTEMS."""

    def __init__(self):
        super(rtems, self).__init__('rtems',
                                    gdb.COMMAND_STATUS,
                                    gdb.COMPLETE_NONE,
                                    True)

class rtems_object(gdb.Command):
    """Object sub-command for RTEMS"""

    objects = {
        'classic/semaphores':     lambda obj: classic.semaphore(obj),
        'classic/tasks':          lambda obj: classic.task(obj),
        'classic/message_queues': lambda obj: classic.message_queue(obj),
        'classic/timers' :        lambda obj: classic.timer(obj),
        'classic/partitions' :    lambda obj: classic.partition(obj),
        'classic/regions' :       lambda obj: classic.region(obj),
        'classic/barriers' :      lambda obj: classic.barrier(obj)
    }

    def __init__(self):
        self.__doc__ = 'Display the RTEMS object given a numeric ID' \
                       '(Or a reference to the object).'
        super(rtems_object, self).__init__('rtems object',
                                           gdb.COMMAND_DATA,
                                           gdb.COMPLETE_SYMBOL)

    def invoke(self, arg, from_tty):
        for num in arg.split():
            try:
                val = gdb.parse_and_eval(num)
                num = int(val)
            except:
                print 'error: "%s" is not a number' % (num)
                return
            id = objects.ident(num)
            if not id.valid():
                print 'Invalid object id'
                return

            print 'API:%s Class:%s Node:%d Index:%d Id:%08X' % \
                (id.api(), id._class(), id.node(), id.index(), id.value())
            objectname = id.api() + '/' + id._class()

            obj = objects.information.object(id).dereference()
            if objectname in self.objects:
                object = self.objects[objectname](obj)
                object.show(from_tty)
        objects.information.invalidate()

class rtems_index(gdb.Command):
    '''Print object by index'''

    api = 'classic'
    _class = ''

    def __init__(self,command):
        super(rtems_index, self).__init__( command,
                                           gdb.COMMAND_DATA,
                                           gdb.COMPLETE_NONE)

    def instance(self, obj):
        '''Returns a n instance of corresponding object, the child should extend
           this'''
        return obj

    def invoke(self, arg, from_tty):
        maximum = objects.information.maximum(self.api, self._class)
        minimum_id = objects.ident(objects.information.minimum_id(self.api, self._class))
        maximum_id = objects.ident(objects.information.minimum_id(self.api, self._class))
        args = arg.split()
        if len(args):
            for val in args:
                try:
                    index = int(val, base = 0)
                    if index < maximum:
                        if index < minimum_id.index():
                            print "error: %s is not an index (min is %d)" % (val,
                                                                             minimum_id.index())
                            return
                    else:
                        index = objects.ident(index).index()
                except ValueError:
                    print "error: %s is not an index" % (val)
                    return
                try:
                    obj = objects.information.object_return(self.api,
                                                            self._class,
                                                            index)
                except IndexError:
                    print "error: index %s is invalid" % (index)
                    return
                instance = self.instance(obj)
                instance.show(from_tty)
            objects.information.invalidate()
        else:
            print '-' * 70
            print ' %s: %d [%08x -> %08x]' % (objects.information.name(self.api, self._class),
                                             maximum, minimum_id.value(), maximum_id.value())
            for index in range(minimum_id.index(), minimum_id.index() + maximum):
                print '-' * 70
                self.invoke(str(index), from_tty)

class rtems_semaphore(rtems_index):
    '''semaphore subcommand'''
    _class = 'semaphores'

    def __init__(self):
        self.__doc__ = 'Display RTEMS semaphore(s) by index(es)'
        super(rtems_semaphore, self).__init__('rtems semaphore')

    def instance(self, obj):
        return classic.semaphore(obj)

class rtems_task(rtems_index):
    '''tasks subcommand for rtems'''

    _class = 'tasks'

    def __init__(self):
        self.__doc__ = 'Display RTEMS task(s) by index(es)'
        super(rtems_task,self).__init__('rtems task')

    def instance(self, obj):
        return classic.task(obj)

class rtems_message_queue(rtems_index):
    '''Message Queue subcommand'''

    _class = 'message_queues'

    def __init__(self):
        self.__doc__ = 'Display RTEMS message_queue(s) by index(es)'
        super(rtems_message_queue,self).__init__('rtems mqueue')

    def instance(self, obj):
        return classic.message_queue(obj)

class rtems_timer(rtems_index):
    '''Index subcommand'''

    _class = 'timers'

    def __init__(self):
        self.__doc__ = 'Display RTEMS timer(s) by index(es)'
        super(rtems_timer, self).__init__('rtems timer')

    def instance(self, obj):
        return classic.timer(obj)

class rtems_partition(rtems_index):
    '''Partition subcommand'''

    _class = 'partitions'

    def __init__(self):
        self.__doc__ = 'Display RTEMS partition(s) by index(es)'
        super(rtems_partition, self).__init__('rtems partition')

    def instance(self, obj):
        return classic.partition(obj)

class rtems_region(rtems_index):
    '''Region subcomamnd'''

    _class = 'regions'

    def __init__(self):
        self.__doc__ = 'Display RTEMS region(s) by index(es)'
        super(rtems_region , self).__init__('rtems regions')

    def instance(self, obj):
        return classic.region(obj)

class rtems_barrier(rtems_index):
    '''Barrier subcommand'''

    _class = 'barriers'

    def __init__(self):
        self.__doc__ = 'Display RTEMS barrier(s) by index(es)'
        super(rtems_barrier , self).__init__('rtems barrier')

    def instance(self, obj):
        return classic.barrier(obj)

class rtems_tod(gdb.Command):
    '''Print rtems time of day'''

    api = 'internal'
    _class = 'time'

    def __init__(self):
        self.__doc__ = 'Display RTEMS time of day'
        super(rtems_tod, self).__init__ \
                    ('rtems tod', gdb.COMMAND_STATUS,gdb.COMPLETE_NONE)

    def invoke(self, arg, from_tty):

        if arg:
            print "warning: commad takes no arguments!"

        obj = objects.information.object_return(self.api,self._class)
        instance = supercore.time_of_day(obj)
        instance.show()
        objects.information.invalidate()

class rtems_watchdog_chain(gdb.Command):
    '''Print watchdog ticks chain'''

    api = 'internal'
    _class = ''

    def __init__(self,command):
        super(rtems_watchdog_chain, self).__init__ \
                                (command, gdb.COMMAND_DATA, gdb.COMPLETE_NONE)

    def invoke(self, arg, from_tty):
        obj = objects.information.object_return(self.api, self._class)

        inst = chains.control(obj)

        if inst.empty():
            print '     error: empty chain'
            return

        nd = inst.first()
        i = 0
        while not nd.null():
            wd = watchdog.control(nd.cast('Watchdog_Control'))
            print ' #'+str(i)
            print wd.to_string()
            nd.next()
            i += 1

class rtems_wdt(rtems_watchdog_chain):

    _class = 'wdticks'

    def __init__(self):
        self.__doc__ = 'Display watchdog ticks chain'
        super(rtems_wdt, self).__init__('rtems wdticks')

class rtems_wsec(rtems_watchdog_chain):

    _class = 'wdseconds'

    def __init__(self):
        self.__doc__ = 'Display watchdog seconds chain'
        super(rtems_wsec, self).__init__('rtems wdseconds')

def create():
    return (rtems(),
            rtems_object(),
            rtems_semaphore(),
            rtems_task(),
            rtems_message_queue(),
            rtems_tod(),
            rtems_wdt(),
            rtems_wsec())