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

4.104.115
Last change on this file since e60a5ee was e60a5ee, checked in by Dhananjay Balan <mb.dhananjay@…>, on 07/30/13 at 03:24:35

Fix Task and state printer bugs.

  • Removed ITRON api objects in thread control
  • fixes #1
  • Property mode set to 100644
File size: 8.7 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        self.wait_info = self.task.wait_info()
157
158    def show(self, from_tty):
159        print '     Name:', self.task.name()
160        print '    State:', self.task.current_state()
161        print '  Current:', self.task.current_priority()
162        print '     Real:', self.task.real_priority()
163        print '  Preempt:', self.task.preemptible()
164        print ' T Budget:', self.task.cpu_time_budget()
165
166
167class message_queue:
168    "Print classic messege queue"
169
170    def __init__(self,id):
171        self.id = id
172        self.object = objects.information.object(self.id).dereference()
173        self.object_control = objects.control(self.object['Object'])
174        self.attr = attribute(self.object['attribute_set'], \
175            'message_queue')
176        self.wait_queue = threads.queue( \
177            self.object['message_queue']['Wait_queue'])
178
179        self.core_control = supercore.message_queue(self.object['message_queue'])
180
181    def show(self, from_tty):
182        print '     Name:', self.object_control.name()
183        print '     Attr:', self.attr.to_string()
184
185        self.core_control.show()
186
187class timer:
188    '''Print a classic timer'''
189
190    def __init__(self, id):
191        self.id = id
192        self.object = objects.information.object(self.id).dereference()
193        self.object_control = objects.control(self.object['Object'])
194        self.watchdog = watchdog.control(self.object['Ticker'])
195
196    def show(self, from_tty):
197        print '     Name:', self.object_control.name()
198        self.watchdog.show()
199
200class partition:
201    ''' Print a rtems partition '''
202
203    def __init__(self, id):
204        self.id = id
205        self.object = objects.information.object(self.id).dereference()
206        self.object_control = objects.control(self.object['Object'])
207        self.attr = attribute(self.object['attribute_set'], 'partition')
208        self.starting_addr = self.object['starting_address']
209        self.length = self.object['length']
210        self.buffer_size = self.object['buffer_size']
211        self.used_blocks = self.object['number_of_used_blocks']
212
213    def show(self, from_tty):
214        # ToDo: the printing still somewhat crude.
215        print '     Name:', self.object_control.name()
216        print '     Attr:', self.attr.to_string()
217        print '   Length:', self.length
218        print '   B Size:', self.buffer_size
219        print ' U Blocks:', self.used_blocks
220
221class region:
222    "prints a classic region"
223
224    def __init__(self,id):
225        self.id = id
226        self.object = objects.information.object(self.id).dereference()
227        self.object_control = objects.control(self.object['Object'])
228        self.attr = attribute(self.object['attribute_set'], 'region')
229        self.wait_queue = threads.queue(self.object['Wait_queue'])
230        self.heap = heaps.control(self.object['Memory'])
231
232    def show(self, from_tty):
233        print '     Name:', self.object_control.name()
234        print '     Attr:', self.attr.to_string()
235        helper.tasks_printer_routine(self.wait_queue)
236        print '   Memory:'
237        self.heap.show()
238
239class barrier:
240    '''classic barrier abstraction'''
241
242    def __init__(self,id):
243        self.id = id
244        self.object = objects.information.object(self.id).dereference()
245        self.object_control = objects.control(self.object['Object'])
246        self.attr = attribute(self.object['attribute_set'],'barrier')
247        self.core_b_control = supercore.barrier_control(self.object['Barrier'])
248
249    def show(self,from_tty):
250        print '     Name:',self.object_control.name()
251        print '     Attr:',self.attr.to_string()
252
253        if self.attr.test('barrier','barrier-auto-release'):
254            max_count = self.core_b_control.max_count()
255            print 'Aut Count:', max_count
256
257        print '  Waiting:',self.core_b_control.waiting_threads()
258        helper.tasks_printer_routine(self.core_b_control.tasks())
259
Note: See TracBrowser for help on using the repository browser.