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

4.104.115
Last change on this file since 086e689 was 086e689, checked in by Dhananjay Balan <mb.dhananjay@…>, on 07/17/13 at 10:30:57

Added support for classic/timers.

  • Property mode set to 100644
File size: 6.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
12import objects
13import threads
14import watchdog
15import supercore
16
17class attribute:
18    """The Classic API attribute."""
19
20    groups = {
21        'none' : [],
22        'all' : ['scope',
23                 'priority',
24                 'fpu',
25                 'semaphore-type',
26                 'semaphore-pri',
27                 'semaphore-pri-ceiling',
28                 'barrier',
29                 'task'],
30        'task' : ['scope',
31                  'priority',
32                  'fpu',
33                  'task'],
34        'semaphore' : ['scope',
35                       'priority',
36                       'semaphore-type',
37                       'semaphore-pri',
38                       'semaphore-pri-ceiling'],
39        'barrier' : ['scope',
40                     'priority',
41                     'barrier'],
42        'message_queue' : ['priority',
43                           'scope']
44        }
45
46    masks = {
47        'scope' : 0x00000002,
48        'priority' : 0x00000004,
49        'fpu' : 0x00000001,
50        'semaphore-type' : 0x00000030,
51        'semaphore-pri' : 0x00000040,
52        'semaphore-pri-ceiling' : 0x00000080,
53        'barrier' : 0x00000010,
54        'task' : 0x00008000
55        }
56
57    fields = {
58        'scope' : [(0x00000000, 'local'),
59                   (0x00000002, 'global')],
60        'priority' : [(0x00000000, 'fifo'),
61                      (0x00000004, 'pri')],
62        'fpu' : [(0x00000000, 'no-fpu'),
63                 (0x00000001, 'fpu')],
64        'semaphore-type' : [(0x00000000, 'count-sema'),
65                            (0x00000010, 'bin-sema'),
66                            (0x00000020, 'simple-bin-sema')],
67        'semaphore-pri' : [(0x00000000, 'no-inherit-pri'),
68                           (0x00000040, 'inherit-pri')],
69        'semaphore-pri-ceiling' : [(0x00000000, 'no-pri-ceiling'),
70                                   (0x00000080, 'pri-ceiling')],
71        'barrier' : [(0x00000010, 'barrier-auto-release'),
72                     (0x00000000, 'barrier-manual-release')],
73        'task' : [(0x00000000, 'app-task'),
74                  (0x00008000, 'sys-task')]
75        }
76
77    def __init__(self, attr, attrtype = 'none'):
78        if attrtype not in self.groups:
79            raise 'invalid attribute type'
80        self.attrtype = attrtype
81        self.attr = attr
82
83    #ToDo: Move this out
84    def to_string(self):
85        s = '0x%08x,' % (self.attr)
86        if self.attrtype != 'none':
87            for m in self.groups[self.attrtype]:
88                v = self.attr & self.masks[m]
89                for f in self.fields[m]:
90                    if f[0] == v:
91                        s += f[1] + ','
92                        break
93        return s[:-1]
94
95    def test(self, mask, value):
96        if self.attrtype != 'none' and \
97                mask in self.groups[self.attrtype]:
98            v = self.masks[mask] & self.attr
99            for f in self.fields[mask]:
100                if v == f[0] and value == f[1]:
101                    return True
102        return False
103
104
105class semaphore:
106    "Print a classic semaphore."
107
108    def __init__(self, id):
109        self.id = id;
110        self.object = objects.information.object(self.id).dereference()
111        self.object_control = objects.control(self.object['Object'])
112        self.attr = attribute(self.object['attribute_set'], 'semaphore')
113
114    def show(self, from_tty):
115        print '     Name:', self.object_control.name()
116        print '     Attr:', self.attr.to_string()
117        if self.attr.test('semaphore-type', 'bin-sema') or \
118                self.attr.test('semaphore-type', 'simple-bin-sema'):
119            core_mutex = self.object['Core_control']['mutex']
120            locked = core_mutex['lock'] == 0
121            if locked:
122                s = 'locked'
123            else:
124                s = 'unlocked'
125            print '     Lock:', s
126            print '  Nesting:', core_mutex['nest_count']
127            print '  Blocked:', core_mutex['blocked_count']
128            print '   Holder:',
129            holder = core_mutex['holder']
130            if holder and locked:
131                holder = threads.control(holder.dereference())
132                print holder.brief()
133            elif holder == 0 and locked:
134                print 'locked but no holder'
135            else:
136                print 'unlocked'
137            wait_queue = threads.queue(core_mutex['Wait_queue'])
138            tasks = wait_queue.tasks()
139            print '    Queue: len = %d, state = %s' % (len(tasks),
140                                                       wait_queue.state())
141            for t in range(0, len(tasks)):
142                print '      ', tasks[t].brief(), ' (%08x)' % (tasks[t].id())
143        else:
144            print 'semaphore'
145
146class task:
147    "Print a classic tasks."
148
149    def __init__(self, id):
150        self.id = id;
151        self.task = \
152            threads.control(objects.information.object(self.id).dereference())
153
154    def show(self, from_tty):
155        print '     Name:', self.task.name()
156        print '    State:', self.task.current_state()
157        print '  Current:', self.task.current_priority()
158        print '     Real:', self.task.real_priority()
159        print ' Suspends:', self.task.suspends()
160        print ' Post Ext:', self.task.post_task_switch_ext()
161        print '  Preempt:', self.task.preemptible()
162        print ' T Budget:', self.task.cpu_time_budget()
163        wait_info = self.task.wait_info()
164
165class message_queue:
166    "Print a classic messege queue"
167
168    def __init__(self,id):
169        self.id = id
170        self.object = objects.information.object(self.id).dereference()
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.CORE_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, id):
189        self.id = id
190        self.object = objects.information.object(self.id).dereference()
191        self.object_control = objects.control(self.object['Object'])
192        self.watchdog = watchdog.control(self.object['Ticker'])
193
194    def show(self, from_tty):
195        print '     Name:', self.object_control.name()
196        self.watchdog.show()
Note: See TracBrowser for help on using the repository browser.