summaryrefslogtreecommitdiffstats
path: root/tools/gdb/python/classic.py
blob: 50514ffdc7ab80da06736f72651a88e2116c16b0 (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
#
# RTEMS Classic API Support
# Copyright 2010 Chris Johns (chrisj@rtems.org)
#
# $Id$
#

import gdb
import itertools
import re
#ToDo This shouldn't be here
import helper

import objects
import threads
import watchdog
import heaps
import supercore

class attribute:
    """The Classic API attribute."""

    groups = {
        'none' : [],
        'all' : ['scope',
                 'priority',
                 'fpu',
                 'semaphore-type',
                 'semaphore-pri',
                 'semaphore-pri-ceiling',
                 'barrier',
                 'task'],
        'task' : ['scope',
                  'priority',
                  'fpu',
                  'task'],
        'semaphore' : ['scope',
                       'priority',
                       'semaphore-type',
                       'semaphore-pri',
                       'semaphore-pri-ceiling'],
        'barrier' : ['barrier'],
        'message_queue' : ['priority',
                           'scope'],
        'partition' : ['scope'],
        'region' : ['priority']
        }

    masks = {
        'scope' : 0x00000002,
        'priority' : 0x00000004,
        'fpu' : 0x00000001,
        'semaphore-type' : 0x00000030,
        'semaphore-pri' : 0x00000040,
        'semaphore-pri-ceiling' : 0x00000080,
        'barrier' : 0x00000010,
        'task' : 0x00008000
        }

    fields = {
        'scope' : [(0x00000000, 'local'),
                   (0x00000002, 'global')],
        'priority' : [(0x00000000, 'fifo'),
                      (0x00000004, 'pri')],
        'fpu' : [(0x00000000, 'no-fpu'),
                 (0x00000001, 'fpu')],
        'semaphore-type' : [(0x00000000, 'count-sema'),
                            (0x00000010, 'bin-sema'),
                            (0x00000020, 'simple-bin-sema')],
        'semaphore-pri' : [(0x00000000, 'no-inherit-pri'),
                           (0x00000040, 'inherit-pri')],
        'semaphore-pri-ceiling' : [(0x00000000, 'no-pri-ceiling'),
                                   (0x00000080, 'pri-ceiling')],
        'barrier' : [(0x00000010, 'barrier-auto-release'),
                     (0x00000000, 'barrier-manual-release')],
        'task' : [(0x00000000, 'app-task'),
                  (0x00008000, 'sys-task')]
        }

    def __init__(self, attr, attrtype = 'none'):
        if attrtype not in self.groups:
            raise 'invalid attribute type'
        self.attrtype = attrtype
        self.attr = attr

    #ToDo: Move this out
    def to_string(self):
        s = '0x%08x,' % (self.attr)
        if self.attrtype != 'none':
            for m in self.groups[self.attrtype]:
                v = self.attr & self.masks[m]
                for f in self.fields[m]:
                    if f[0] == v:
                        s += f[1] + ','
                        break
        return s[:-1]

    def test(self, mask, value):
        if self.attrtype != 'none' and \
                mask in self.groups[self.attrtype]:
            v = self.masks[mask] & self.attr
            for f in self.fields[mask]:
                if v == f[0] and value == f[1]:
                    return True
        return False


class semaphore:
    "Print a classic semaphore."

    def __init__(self, id):
        self.id = id;
        self.object = objects.information.object(self.id).dereference()
        self.object_control = objects.control(self.object['Object'])
        self.attr = attribute(self.object['attribute_set'], 'semaphore')

    def show(self, from_tty):
        print '     Name:', self.object_control.name()
        print '     Attr:', self.attr.to_string()
        if self.attr.test('semaphore-type', 'bin-sema') or \
                self.attr.test('semaphore-type', 'simple-bin-sema'):
            core_mutex = self.object['Core_control']['mutex']
            locked = core_mutex['lock'] == 0
            if locked:
                s = 'locked'
            else:
                s = 'unlocked'
            print '     Lock:', s
            print '  Nesting:', core_mutex['nest_count']
            print '  Blocked:', core_mutex['blocked_count']
            print '   Holder:',
            holder = core_mutex['holder']
            if holder and locked:
                holder = threads.control(holder.dereference())
                print holder.brief()
            elif holder == 0 and locked:
                print 'locked but no holder'
            else:
                print 'unlocked'
            wait_queue = threads.queue(core_mutex['Wait_queue'])
            tasks = wait_queue.tasks()
            print '    Queue: len = %d, state = %s' % (len(tasks),
                                                       wait_queue.state())
            for t in range(0, len(tasks)):
                print '      ', tasks[t].brief(), ' (%08x)' % (tasks[t].id())
        else:
            print 'semaphore'

class task:
    "Print a classic task"

    def __init__(self, id):
        self.id = id;
        self.task = \
            threads.control(objects.information.object(self.id).dereference())
        self.wait_info = self.task.wait_info()

    def show(self, from_tty):
        print '     Name:', self.task.name()
        print '    State:', self.task.current_state()
        print '  Current:', self.task.current_priority()
        print '     Real:', self.task.real_priority()
        print '  Preempt:', self.task.preemptible()
        print ' T Budget:', self.task.cpu_time_budget()


class message_queue:
    "Print classic messege queue"

    def __init__(self,id):
        self.id = id
        self.object = objects.information.object(self.id).dereference()
        self.object_control = objects.control(self.object['Object'])
        self.attr = attribute(self.object['attribute_set'], \
            'message_queue')
        self.wait_queue = threads.queue( \
            self.object['message_queue']['Wait_queue'])

        self.core_control = supercore.message_queue(self.object['message_queue'])

    def show(self, from_tty):
        print '     Name:', self.object_control.name()
        print '     Attr:', self.attr.to_string()

        self.core_control.show()

class timer:
    '''Print a classic timer'''

    def __init__(self, id):
        self.id = id
        self.object = objects.information.object(self.id).dereference()
        self.object_control = objects.control(self.object['Object'])
        self.watchdog = watchdog.control(self.object['Ticker'])

    def show(self, from_tty):
        print '     Name:', self.object_control.name()
        self.watchdog.show()

class partition:
    ''' Print a rtems partition '''

    def __init__(self, id):
        self.id = id
        self.object = objects.information.object(self.id).dereference()
        self.object_control = objects.control(self.object['Object'])
        self.attr = attribute(self.object['attribute_set'], 'partition')
        self.starting_addr = self.object['starting_address']
        self.length = self.object['length']
        self.buffer_size = self.object['buffer_size']
        self.used_blocks = self.object['number_of_used_blocks']

    def show(self, from_tty):
        # ToDo: the printing still somewhat crude.
        print '     Name:', self.object_control.name()
        print '     Attr:', self.attr.to_string()
        print '   Length:', self.length
        print '   B Size:', self.buffer_size
        print ' U Blocks:', self.used_blocks

class region:
    "prints a classic region"

    def __init__(self,id):
        self.id = id
        self.object = objects.information.object(self.id).dereference()
        self.object_control = objects.control(self.object['Object'])
        self.attr = attribute(self.object['attribute_set'], 'region')
        self.wait_queue = threads.queue(self.object['Wait_queue'])
        self.heap = heaps.control(self.object['Memory'])

    def show(self, from_tty):
        print '     Name:', self.object_control.name()
        print '     Attr:', self.attr.to_string()
        helper.tasks_printer_routine(self.wait_queue)
        print '   Memory:'
        self.heap.show()

class barrier:
    '''classic barrier abstraction'''

    def __init__(self,id):
        self.id = id
        self.object = objects.information.object(self.id).dereference()
        self.object_control = objects.control(self.object['Object'])
        self.attr = attribute(self.object['attribute_set'],'barrier')
        self.core_b_control = supercore.barrier_control(self.object['Barrier'])

    def show(self,from_tty):
        print '     Name:',self.object_control.name()
        print '     Attr:',self.attr.to_string()

        if self.attr.test('barrier','barrier-auto-release'):
            max_count = self.core_b_control.max_count()
            print 'Aut Count:', max_count

        print '  Waiting:',self.core_b_control.waiting_threads()
        helper.tasks_printer_routine(self.core_b_control.tasks())