source: rtems-tools/tools/gdb/python/classic.py @ 6d89e3c

4.104.115
Last change on this file since 6d89e3c was 6d89e3c, checked in by Dhananjay Balan <mb.dhananjay@…>, on 08/01/13 at 06:50:23

Refactor

  • The objects are intialized using the objects rather than the ID.
  • Property mode set to 100644
File size: 8.3 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, obj):
112        self.object = obj
113        self.object_control = objects.control(self.object['Object'])
114        self.attr = attribute(self.object['attribute_set'], 'semaphore')
115
116    def show(self, from_tty):
117        print '     Name:', self.object_control.name()
118        print '     Attr:', self.attr.to_string()
119        if self.attr.test('semaphore-type', 'bin-sema') or \
120                self.attr.test('semaphore-type', 'simple-bin-sema'):
121            core_mutex = self.object['Core_control']['mutex']
122            locked = core_mutex['lock'] == 0
123            if locked:
124                s = 'locked'
125            else:
126                s = 'unlocked'
127            print '     Lock:', s
128            print '  Nesting:', core_mutex['nest_count']
129            print '  Blocked:', core_mutex['blocked_count']
130            print '   Holder:',
131            holder = core_mutex['holder']
132            if holder and locked:
133                holder = threads.control(holder.dereference())
134                print holder.brief()
135            elif holder == 0 and locked:
136                print 'locked but no holder'
137            else:
138                print 'unlocked'
139            wait_queue = threads.queue(core_mutex['Wait_queue'])
140            tasks = wait_queue.tasks()
141            print '    Queue: len = %d, state = %s' % (len(tasks),
142                                                       wait_queue.state())
143            for t in range(0, len(tasks)):
144                print '      ', tasks[t].brief(), ' (%08x)' % (tasks[t].id())
145        else:
146            print 'semaphore'
147
148class task:
149    "Print a classic task"
150
151    def __init__(self, obj):
152        self.object = obj
153        self.task = \
154            threads.control(self.object)
155        self.wait_info = self.task.wait_info()
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 '  Preempt:', self.task.preemptible()
163        print ' T Budget:', self.task.cpu_time_budget()
164
165
166class message_queue:
167    "Print classic messege queue"
168
169    def __init__(self,obj):
170        self.object = obj
171        self.object_control = objects.control(self.object['Object'])
172        self.attr = attribute(self.object['attribute_set'], \
173            'message_queue')
174        self.wait_queue = threads.queue( \
175            self.object['message_queue']['Wait_queue'])
176
177        self.core_control = supercore.message_queue(self.object['message_queue'])
178
179    def show(self, from_tty):
180        print '     Name:', self.object_control.name()
181        print '     Attr:', self.attr.to_string()
182
183        self.core_control.show()
184
185class timer:
186    '''Print a classic timer'''
187
188    def __init__(self, obj):
189        self.object = obj
190        self.object_control = objects.control(self.object['Object'])
191        self.watchdog = watchdog.control(self.object['Ticker'])
192
193    def show(self, from_tty):
194        print '     Name:', self.object_control.name()
195        self.watchdog.show()
196
197class partition:
198    ''' Print a rtems partition '''
199
200    def __init__(self, obj):
201        self.object = obj
202        self.object_control = objects.control(self.object['Object'])
203        self.attr = attribute(self.object['attribute_set'], 'partition')
204        self.starting_addr = self.object['starting_address']
205        self.length = self.object['length']
206        self.buffer_size = self.object['buffer_size']
207        self.used_blocks = self.object['number_of_used_blocks']
208
209    def show(self, from_tty):
210        # ToDo: the printing still somewhat crude.
211        print '     Name:', self.object_control.name()
212        print '     Attr:', self.attr.to_string()
213        print '   Length:', self.length
214        print '   B Size:', self.buffer_size
215        print ' U Blocks:', self.used_blocks
216
217class region:
218    "prints a classic region"
219
220    def __init__(self,obj):
221        self.object = obj
222        self.object_control = objects.control(self.object['Object'])
223        self.attr = attribute(self.object['attribute_set'], 'region')
224        self.wait_queue = threads.queue(self.object['Wait_queue'])
225        self.heap = heaps.control(self.object['Memory'])
226
227    def show(self, from_tty):
228        print '     Name:', self.object_control.name()
229        print '     Attr:', self.attr.to_string()
230        helper.tasks_printer_routine(self.wait_queue)
231        print '   Memory:'
232        self.heap.show()
233
234class barrier:
235    '''classic barrier abstraction'''
236
237    def __init__(self,obj):
238        self.object = obj
239        self.object_control = objects.control(self.object['Object'])
240        self.attr = attribute(self.object['attribute_set'],'barrier')
241        self.core_b_control = supercore.barrier_control(self.object['Barrier'])
242
243    def show(self,from_tty):
244        print '     Name:',self.object_control.name()
245        print '     Attr:',self.attr.to_string()
246
247        if self.attr.test('barrier','barrier-auto-release'):
248            max_count = self.core_b_control.max_count()
249            print 'Aut Count:', max_count
250
251        print '  Waiting:',self.core_b_control.waiting_threads()
252        helper.tasks_printer_routine(self.core_b_control.tasks())
253
Note: See TracBrowser for help on using the repository browser.