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

4.104.115
Last change on this file since 8e0de06 was 8e0de06, checked in by Dhananjay Balan <mb.dhananjay@…>, on 07/29/13 at 04:55:38

Add classic barrier.

  • Add support for classic barrier object.
  • Drop CORE_ from names in supercore
  • Property mode set to 100644
File size: 8.8 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
19
20class attribute:
21    """The Classic API attribute."""
22
23    groups = {
24        'none' : [],
25        'all' : ['scope',
26                 'priority',
27                 'fpu',
28                 'semaphore-type',
29                 'semaphore-pri',
30                 'semaphore-pri-ceiling',
31                 'barrier',
32                 'task'],
33        'task' : ['scope',
34                  'priority',
35                  'fpu',
36                  'task'],
37        'semaphore' : ['scope',
38                       'priority',
39                       'semaphore-type',
40                       'semaphore-pri',
41                       'semaphore-pri-ceiling'],
42        'barrier' : ['barrier'],
43        'message_queue' : ['priority',
44                           'scope'],
45        'partition' : ['scope'],
46        'region' : ['priority']
47        }
48
49    masks = {
50        'scope' : 0x00000002,
51        'priority' : 0x00000004,
52        'fpu' : 0x00000001,
53        'semaphore-type' : 0x00000030,
54        'semaphore-pri' : 0x00000040,
55        'semaphore-pri-ceiling' : 0x00000080,
56        'barrier' : 0x00000010,
57        'task' : 0x00008000
58        }
59
60    fields = {
61        'scope' : [(0x00000000, 'local'),
62                   (0x00000002, 'global')],
63        'priority' : [(0x00000000, 'fifo'),
64                      (0x00000004, 'pri')],
65        'fpu' : [(0x00000000, 'no-fpu'),
66                 (0x00000001, 'fpu')],
67        'semaphore-type' : [(0x00000000, 'count-sema'),
68                            (0x00000010, 'bin-sema'),
69                            (0x00000020, 'simple-bin-sema')],
70        'semaphore-pri' : [(0x00000000, 'no-inherit-pri'),
71                           (0x00000040, 'inherit-pri')],
72        'semaphore-pri-ceiling' : [(0x00000000, 'no-pri-ceiling'),
73                                   (0x00000080, 'pri-ceiling')],
74        'barrier' : [(0x00000010, 'barrier-auto-release'),
75                     (0x00000000, 'barrier-manual-release')],
76        'task' : [(0x00000000, 'app-task'),
77                  (0x00008000, 'sys-task')]
78        }
79
80    def __init__(self, attr, attrtype = 'none'):
81        if attrtype not in self.groups:
82            raise 'invalid attribute type'
83        self.attrtype = attrtype
84        self.attr = attr
85
86    #ToDo: Move this out
87    def to_string(self):
88        s = '0x%08x,' % (self.attr)
89        if self.attrtype != 'none':
90            for m in self.groups[self.attrtype]:
91                v = self.attr & self.masks[m]
92                for f in self.fields[m]:
93                    if f[0] == v:
94                        s += f[1] + ','
95                        break
96        return s[:-1]
97
98    def test(self, mask, value):
99        if self.attrtype != 'none' and \
100                mask in self.groups[self.attrtype]:
101            v = self.masks[mask] & self.attr
102            for f in self.fields[mask]:
103                if v == f[0] and value == f[1]:
104                    return True
105        return False
106
107
108class semaphore:
109    "Print a classic semaphore."
110
111    def __init__(self, id):
112        self.id = id;
113        self.object = objects.information.object(self.id).dereference()
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            for t in range(0, len(tasks)):
145                print '      ', tasks[t].brief(), ' (%08x)' % (tasks[t].id())
146        else:
147            print 'semaphore'
148
149class task:
150    "Print a classic task"
151
152    def __init__(self, id):
153        self.id = id;
154        self.task = \
155            threads.control(objects.information.object(self.id).dereference())
156
157    def show(self, from_tty):
158        print '     Name:', self.task.name()
159        print '    State:', self.task.current_state()
160        print '  Current:', self.task.current_priority()
161        print '     Real:', self.task.real_priority()
162        print ' Suspends:', self.task.suspends()
163        print ' Post Ext:', self.task.post_task_switch_ext()
164        print '  Preempt:', self.task.preemptible()
165        print ' T Budget:', self.task.cpu_time_budget()
166        wait_info = self.task.wait_info()
167
168class message_queue:
169    "Print classic messege queue"
170
171    def __init__(self,id):
172        self.id = id
173        self.object = objects.information.object(self.id).dereference()
174        self.object_control = objects.control(self.object['Object'])
175        self.attr = attribute(self.object['attribute_set'], \
176            'message_queue')
177        self.wait_queue = threads.queue( \
178            self.object['message_queue']['Wait_queue'])
179
180        self.core_control = supercore.message_queue(self.object['message_queue'])
181
182    def show(self, from_tty):
183        print '     Name:', self.object_control.name()
184        print '     Attr:', self.attr.to_string()
185
186        self.core_control.show()
187
188class timer:
189    '''Print a classic timer'''
190
191    def __init__(self, id):
192        self.id = id
193        self.object = objects.information.object(self.id).dereference()
194        self.object_control = objects.control(self.object['Object'])
195        self.watchdog = watchdog.control(self.object['Ticker'])
196
197    def show(self, from_tty):
198        print '     Name:', self.object_control.name()
199        self.watchdog.show()
200
201class partition:
202    ''' Print a rtems partition '''
203
204    def __init__(self, id):
205        self.id = id
206        self.object = objects.information.object(self.id).dereference()
207        self.object_control = objects.control(self.object['Object'])
208        self.attr = attribute(self.object['attribute_set'], 'partition')
209        self.starting_addr = self.object['starting_address']
210        self.length = self.object['length']
211        self.buffer_size = self.object['buffer_size']
212        self.used_blocks = self.object['number_of_used_blocks']
213
214    def show(self, from_tty):
215        # ToDo: the printing still somewhat crude.
216        print '     Name:', self.object_control.name()
217        print '     Attr:', self.attr.to_string()
218        print '   Length:', self.length
219        print '   B Size:', self.buffer_size
220        print ' U Blocks:', self.used_blocks
221
222class region:
223    "prints a classic region"
224
225    def __init__(self,id):
226        self.id = id
227        self.object = objects.information.object(self.id).dereference()
228        self.object_control = objects.control(self.object['Object'])
229        self.attr = attribute(self.object['attribute_set'], 'region')
230        self.wait_queue = threads.queue(self.object['Wait_queue'])
231        self.heap = heaps.control(self.object['Memory'])
232
233    def show(self, from_tty):
234        print '     Name:', self.object_control.name()
235        print '     Attr:', self.attr.to_string()
236        helper.tasks_printer_routine(self.wait_queue)
237        print '   Memory:'
238        self.heap.show()
239
240class barrier:
241    '''classic barrier abstraction'''
242
243    def __init__(self,id):
244        self.id = id
245        self.object = objects.information.object(self.id).dereference()
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
Note: See TracBrowser for help on using the repository browser.