source: rtems-tools/tools/gdb/python/objects.py @ b9ee5df

4.104.115
Last change on this file since b9ee5df was b9ee5df, checked in by Dhananjay Balan <mb.dhananjay@…>, on 07/28/13 at 09:15:58

Add region support.

Abstractions for classic/region added.

  • Property mode set to 100644
File size: 7.1 KB
Line 
1#
2# RTEMS Objects Support
3# Copyright 2010 Chris Johns (chrisj@rtems.org)
4#
5# $Id$
6#
7
8import gdb
9import itertools
10import re
11
12class infotables:
13    """Manage the object information tables."""
14
15    tables_types = {
16        'classic/tasks'          : ('Thread_Control',        '_RTEMS_tasks_Information'),
17        'classic/timers'         : ('Timer_Control',         '_Timer_Information'),
18        'classic/semaphores'     : ('Semaphore_Control',     '_Semaphore_Information'),
19        'classic/message_queues' : ('Message_queue_Control', '_Message_queue_Information'),
20        'classic/partitions'     : ('Partition_Control',     '_Partition_Information'),
21        'classic/regions'        : ('Region_Control',        '_Region_Information'),
22        'classic/ports'          : ('Port_Control',          '_Port_Information'),
23        'classic/periods'        : ('Period_Control',        '_Period_Information'),
24        'classic/extensions'     : ('Extension_Control',     '_Extension_Information'),
25        'classic/barriers'       : ('Barrier_Control',       '_Barrier_Information')
26        }
27
28    def __init__(self):
29        self.invalidate()
30
31    def invalidate(self):
32        self.tables = {}
33
34    def name(self, api, _class):
35        return api + '/' + _class
36
37    def load(self, n):
38        if n in self.tables_types:
39            if n not in self.tables:
40                self.tables[n] = gdb.parse_and_eval(self.tables_types[n][1])
41
42    def get(self, api, _class):
43        n = self.name(api, _class)
44        self.load(n)
45        if n in self.tables:
46            return self.tables[n]
47        return None
48
49    def maximum(self, api, _class):
50        n = self.name(api, _class)
51        self.load(n)
52        return int(self.tables[n]['maximum'])
53
54    def object(self, id):
55        if type(id) == gdb.Value:
56            id = ident(id)
57        if type(id) == tuple:
58            api = id[0]
59            _class = id[1]
60            index = id[2]
61        else:
62            api = id.api()
63            _class = id._class()
64            index = id.index()
65        return self.object_return(api, _class, index)
66
67    def object_return(self, api, _class, index):
68        n = self.name(api, _class)
69        self.load(n)
70        max = self.maximum(api, _class)
71        if index > max:
72            raise IndexError('object index out of range (%d)' % (max))
73        table_type = self.tables_types[n]
74        expr = '(' + table_type[0] + '*)' + \
75            table_type[1] + '.local_table[' + str(index) + ']'
76        return gdb.parse_and_eval(expr)
77
78    def is_string(self, api, _class):
79        n = self.name(api, _class)
80        self.load(n)
81        if n in self.tables:
82            if self.tables[n]['is_string']:
83                return True
84        return False
85
86#
87# Global info tables. These are global in the target.
88#
89information = infotables()
90
91class ident:
92    "An RTEMS object id with support for its bit fields."
93
94    bits = [
95        { 'index': (0, 15),
96          'node':  (0, 0),
97          'api':   (8, 10),
98          'class': (11, 15) },
99        { 'index': (0, 15),
100          'node':  (16, 23),
101          'api':   (24, 26),
102          'class': (27, 31) }
103        ]
104
105    OBJECT_16_BITS = 0
106    OBJECT_31_BITS = 1
107
108    api_labels = [
109        'none',
110        'internal',
111        'classic',
112        'posix',
113        'itron'
114        ]
115
116    class_labels = {
117        'internal' : ('threads',
118                      'mutexes'),
119        'classic' : ('none',
120                     'tasks',
121                     'timers',
122                     'semaphores',
123                     'message_queues',
124                     'partitions',
125                     'regions',
126                     'ports',
127                     'periods',
128                     'extensions',
129                     'barriers'),
130        'posix' : ('none',
131                   'threads',
132                   'keys',
133                   'interrupts',
134                   'message_queue_fds',
135                   'message_queues',
136                   'mutexes',
137                   'semaphores',
138                   'condition_variables',
139                   'timers',
140                   'barriers',
141                   'spinlocks',
142                   'rwlocks'),
143        'itron' : ('none',
144                   'tasks',
145                   'eventflags',
146                   'mailboxes',
147                   'message_buffers',
148                   'ports',
149                   'semaphores',
150                   'variable_memory_pools',
151                   'fixed_memory_pools')
152        }
153
154    def __init__(self, id):
155        if type(id) != gdb.Value and type(id) != int and type(id) != unicode:
156            raise TypeError('%s: must be gdb.Value, int, unicoded int' % (type(id)))
157        if type(id) == int:
158            id = gdb.Value(id)
159        self.id = id
160        if self.id.type.sizeof == 2:
161            self.idSize = self.OBJECT_16_BITS
162        else:
163            self.idSize = self.OBJECT_31_BITS
164
165    def get(self, field):
166        if field in self.bits[self.idSize]:
167            bits = self.bits[self.idSize][field]
168            if bits[1] > 0:
169                return (int(self.id) >> bits[0]) & ((1 << (bits[1] - bits[0] + 1)) - 1)
170        return 0
171
172    def value(self):
173        return int(self.id)
174
175    def index(self):
176        return self.get('index')
177
178    def node(self):
179        return self.get('node')
180
181    def api_val(self):
182        return self.get('api')
183
184    def class_val(self):
185        return self.get('class')
186
187    def api(self):
188        api = self.api_val()
189        if api < len(self.api_labels):
190            return self.api_labels[api]
191        return 'none'
192
193    def _class(self):
194        api = self.api()
195        if api == 'none':
196            return 'invalid'
197        _class = self.class_val()
198        if _class < len(self.class_labels[api]):
199            return self.class_labels[api][_class]
200        return 'invalid'
201
202    def valid(self):
203        return self.api() != 'none' and self._class() != 'invalid'
204
205class name:
206    """The Objects_Name can either be told what the name is or can take a
207    guess."""
208
209    def __init__(self, name, is_string = None):
210        self.name = name
211        if is_string == None:
212            self.is_string = 'auto'
213        else:
214            if is_string:
215                self.is_string = 'yes'
216            else:
217                self.is_string = 'no'
218
219    def __str__(self):
220        if self.is_string != 'yes':
221            u32 = int(self.name['name_u32'])
222            s = chr((u32 >> 24) & 0xff) + \
223                chr((u32 >> 16) & 0xff) + chr((u32 >> 8) & 0xff) + \
224                chr(u32 & 0xff)
225            for c in range(0,4):
226                if s[c] < ' ' or s[c] > '~':
227                    s = None
228                    break
229            if s:
230                return s
231        return str(self.name['name_p'].dereference())
232
233class control:
234    """The Objects_Control structure."""
235
236    def __init__(self, object):
237        self.object = object
238        self._id = ident(self.object['id'])
239
240    def node(self):
241        return self.object['Node']
242
243    def id(self):
244        return self.object['id']
245
246    def name(self):
247        is_string = information.is_string(self._id.api(), self._id._class())
248        return str(name(self.object['name'], is_string))
Note: See TracBrowser for help on using the repository browser.