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

4.104.115
Last change on this file since a785e25 was b061a67, checked in by Dhananjay Balan <mb.dhananjay@…>, on 07/12/13 at 13:34:37

Heavy refactoring + Improved mesege queu printing.

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