source: rtems-tools/tools/gdb/python/classic.py @ 4dbd0db

4.104.115
Last change on this file since 4dbd0db was bd0b98d, checked in by Dhananjay Balan <mb.dhananjay@…>, on 08/26/13 at 16:42:25

Add cpu registers to task output.

  • Property mode set to 100644
File size: 8.5 KB
Line 
1#
2# RTEMS Classic API Support
3# Copyright 2010 Chris Johns (chrisj@rtems.org)
4#
5# $Id$
6#
7
8import gdb
9import itertools
10import re
11#ToDo This shouldn't be here
12import helper
13
14import objects
15import threads
16import watchdog
17import heaps
18import supercore
19import sparc
20
21class attribute:
22    """The Classic API attribute."""
23
24    groups = {
25        'none' : [],
26        'all' : ['scope',
27                 'priority',
28                 'fpu',
29                 'semaphore-type',
30                 'semaphore-pri',
31                 'semaphore-pri-ceiling',
32                 'barrier',
33                 'task'],
34        'task' : ['scope',
35                  'priority',
36                  'fpu',
37                  'task'],
38        'semaphore' : ['scope',
39                       'priority',
40                       'semaphore-type',
41                       'semaphore-pri',
42                       'semaphore-pri-ceiling'],
43        'barrier' : ['barrier'],
44        'message_queue' : ['priority',
45                           'scope'],
46        'partition' : ['scope'],
47        'region' : ['priority']
48        }
49
50    masks = {
51        'scope' : 0x00000002,
52        'priority' : 0x00000004,
53        'fpu' : 0x00000001,
54        'semaphore-type' : 0x00000030,
55        'semaphore-pri' : 0x00000040,
56        'semaphore-pri-ceiling' : 0x00000080,
57        'barrier' : 0x00000010,
58        'task' : 0x00008000
59        }
60
61    fields = {
62        'scope' : [(0x00000000, 'local'),
63                   (0x00000002, 'global')],
64        'priority' : [(0x00000000, 'fifo'),
65                      (0x00000004, 'pri')],
66        'fpu' : [(0x00000000, 'no-fpu'),
67                 (0x00000001, 'fpu')],
68        'semaphore-type' : [(0x00000000, 'count-sema'),
69                            (0x00000010, 'bin-sema'),
70                            (0x00000020, 'simple-bin-sema')],
71        'semaphore-pri' : [(0x00000000, 'no-inherit-pri'),
72                           (0x00000040, 'inherit-pri')],
73        'semaphore-pri-ceiling' : [(0x00000000, 'no-pri-ceiling'),
74                                   (0x00000080, 'pri-ceiling')],
75        'barrier' : [(0x00000010, 'barrier-auto-release'),
76                     (0x00000000, 'barrier-manual-release')],
77        'task' : [(0x00000000, 'app-task'),
78                  (0x00008000, 'sys-task')]
79        }
80
81    def __init__(self, attr, attrtype = 'none'):
82        if attrtype not in self.groups:
83            raise 'invalid attribute type'
84        self.attrtype = attrtype
85        self.attr = attr
86
87    #ToDo: Move this out
88    def to_string(self):
89        s = '0x%08x,' % (self.attr)
90        if self.attrtype != 'none':
91            for m in self.groups[self.attrtype]:
92                v = self.attr & self.masks[m]
93                for f in self.fields[m]:
94                    if f[0] == v:
95                        s += f[1] + ','
96                        break
97        return s[:-1]
98
99    def test(self, mask, value):
100        if self.attrtype != 'none' and \
101                mask in self.groups[self.attrtype]:
102            v = self.masks[mask] & self.attr
103            for f in self.fields[mask]:
104                if v == f[0] and value == f[1]:
105                    return True
106        return False
107
108
109class semaphore:
110    "Print a classic semaphore."
111
112    def __init__(self, obj):
113        self.object = obj
114        self.object_control = objects.control(self.object['Object'])
115        self.attr = attribute(self.object['attribute_set'], 'semaphore')
116
117    def show(self, from_tty):
118        print '     Name:', self.object_control.name()
119        print '     Attr:', self.attr.to_string()
120        if self.attr.test('semaphore-type', 'bin-sema') or \
121                self.attr.test('semaphore-type', 'simple-bin-sema'):
122            core_mutex = self.object['Core_control']['mutex']
123            locked = core_mutex['lock'] == 0
124            if locked:
125                s = 'locked'
126            else:
127                s = 'unlocked'
128            print '     Lock:', s
129            print '  Nesting:', core_mutex['nest_count']
130            print '  Blocked:', core_mutex['blocked_count']
131            print '   Holder:',
132            holder = core_mutex['holder']
133            if holder and locked:
134                holder = threads.control(holder.dereference())
135                print holder.brief()
136            elif holder == 0 and locked:
137                print 'locked but no holder'
138            else:
139                print 'unlocked'
140            wait_queue = threads.queue(core_mutex['Wait_queue'])
141            tasks = wait_queue.tasks()
142            print '    Queue: len = %d, state = %s' % (len(tasks),
143                                                       wait_queue.state())
144            print '    Tasks:'
145            print '    Name (c:current, r:real), (id)'
146            for t in range(0, len(tasks)):
147                print '      ', tasks[t].brief(), ' (%08x)' % (tasks[t].id())
148        else:
149            print 'semaphore'
150
151class task:
152    "Print a classic task"
153
154    def __init__(self, obj):
155        self.object = obj
156        self.task = \
157            threads.control(self.object)
158        self.wait_info = self.task.wait_info()
159        # ToDo: Insert platform dep. code here.
160        self.regs = sparc.register(self.object['Registers'])
161
162    def show(self, from_tty):
163        print '     Name:', self.task.name()
164        print '    State:', self.task.current_state()
165        print '  Current:', self.task.current_priority()
166        print '     Real:', self.task.real_priority()
167        print '  Preempt:', self.task.preemptible()
168        print ' T Budget:', self.task.cpu_time_budget()
169        print ' Regsters:'
170        self.regs.show()
171
172
173class message_queue:
174    "Print classic messege queue"
175
176    def __init__(self,obj):
177        self.object = obj
178        self.object_control = objects.control(self.object['Object'])
179        self.attr = attribute(self.object['attribute_set'], \
180            'message_queue')
181        self.wait_queue = threads.queue( \
182            self.object['message_queue']['Wait_queue'])
183
184        self.core_control = supercore.message_queue(self.object['message_queue'])
185
186    def show(self, from_tty):
187        print '     Name:', self.object_control.name()
188        print '     Attr:', self.attr.to_string()
189
190        self.core_control.show()
191
192class timer:
193    '''Print a classic timer'''
194
195    def __init__(self, obj):
196        self.object = obj
197        self.object_control = objects.control(self.object['Object'])
198        self.watchdog = watchdog.control(self.object['Ticker'])
199
200    def show(self, from_tty):
201        print '     Name:', self.object_control.name()
202        self.watchdog.show()
203
204class partition:
205    ''' Print a rtems partition '''
206
207    def __init__(self, obj):
208        self.object = obj
209        self.object_control = objects.control(self.object['Object'])
210        self.attr = attribute(self.object['attribute_set'], 'partition')
211        self.starting_addr = self.object['starting_address']
212        self.length = self.object['length']
213        self.buffer_size = self.object['buffer_size']
214        self.used_blocks = self.object['number_of_used_blocks']
215
216    def show(self, from_tty):
217        # ToDo: the printing still somewhat crude.
218        print '     Name:', self.object_control.name()
219        print '     Attr:', self.attr.to_string()
220        print '   Length:', self.length
221        print '   B Size:', self.buffer_size
222        print ' U Blocks:', self.used_blocks
223
224class region:
225    "prints a classic region"
226
227    def __init__(self,obj):
228        self.object = obj
229        self.object_control = objects.control(self.object['Object'])
230        self.attr = attribute(self.object['attribute_set'], 'region')
231        self.wait_queue = threads.queue(self.object['Wait_queue'])
232        self.heap = heaps.control(self.object['Memory'])
233
234    def show(self, from_tty):
235        print '     Name:', self.object_control.name()
236        print '     Attr:', self.attr.to_string()
237        helper.tasks_printer_routine(self.wait_queue)
238        print '   Memory:'
239        self.heap.show()
240
241class barrier:
242    '''classic barrier abstraction'''
243
244    def __init__(self,obj):
245        self.object = obj
246        self.object_control = objects.control(self.object['Object'])
247        self.attr = attribute(self.object['attribute_set'],'barrier')
248        self.core_b_control = supercore.barrier_control(self.object['Barrier'])
249
250    def show(self,from_tty):
251        print '     Name:',self.object_control.name()
252        print '     Attr:',self.attr.to_string()
253
254        if self.attr.test('barrier','barrier-auto-release'):
255            max_count = self.core_b_control.max_count()
256            print 'Aut Count:', max_count
257
258        print '  Waiting:',self.core_b_control.waiting_threads()
259        helper.tasks_printer_routine(self.core_b_control.tasks())
260
261
Note: See TracBrowser for help on using the repository browser.