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

4.104.115
Last change on this file since b117be8 was b117be8, checked in by Chris Johns <chrisj@…>, on 03/17/15 at 02:11:57

gdb/python: Update the support to a recent RTEMS.

  • Property mode set to 100644
File size: 10.9 KB
RevLine 
[3162858]1# RTEMS Tools Project (http://www.rtems.org/)
2# Copyright 2010-2014 Chris Johns (chrisj@rtems.org)
3# All rights reserved.
[56a70ae]4#
[3162858]5# This file is part of the RTEMS Tools package in 'rtems-tools'.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are met:
9#
10# 1. Redistributions of source code must retain the above copyright notice,
11# this list of conditions and the following disclaimer.
12#
13# 2. Redistributions in binary form must reproduce the above copyright notice,
14# this list of conditions and the following disclaimer in the documentation
15# and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28#
29
[56a70ae]30#
[3162858]31# RTEMS Classic API Support
[56a70ae]32#
33
34import gdb
35import itertools
36import re
[b9ee5df]37#ToDo This shouldn't be here
38import helper
[56a70ae]39
[b117be8]40import heaps
41import mutex
[56a70ae]42import objects
[b117be8]43import supercore
[56a70ae]44import threads
[086e689]45import watchdog
[56a70ae]46
47class attribute:
48    """The Classic API attribute."""
49
50    groups = {
51        'none' : [],
52        'all' : ['scope',
53                 'priority',
54                 'fpu',
55                 'semaphore-type',
56                 'semaphore-pri',
57                 'semaphore-pri-ceiling',
58                 'barrier',
59                 'task'],
60        'task' : ['scope',
61                  'priority',
62                  'fpu',
63                  'task'],
64        'semaphore' : ['scope',
65                       'priority',
66                       'semaphore-type',
67                       'semaphore-pri',
68                       'semaphore-pri-ceiling'],
[8e0de06]69        'barrier' : ['barrier'],
[f814c76]70        'message_queue' : ['priority',
[09086b4]71                           'scope'],
[b9ee5df]72        'partition' : ['scope'],
73        'region' : ['priority']
[56a70ae]74        }
75
76    masks = {
77        'scope' : 0x00000002,
78        'priority' : 0x00000004,
79        'fpu' : 0x00000001,
80        'semaphore-type' : 0x00000030,
81        'semaphore-pri' : 0x00000040,
82        'semaphore-pri-ceiling' : 0x00000080,
83        'barrier' : 0x00000010,
84        'task' : 0x00008000
85        }
86
87    fields = {
88        'scope' : [(0x00000000, 'local'),
89                   (0x00000002, 'global')],
90        'priority' : [(0x00000000, 'fifo'),
91                      (0x00000004, 'pri')],
92        'fpu' : [(0x00000000, 'no-fpu'),
93                 (0x00000001, 'fpu')],
94        'semaphore-type' : [(0x00000000, 'count-sema'),
95                            (0x00000010, 'bin-sema'),
96                            (0x00000020, 'simple-bin-sema')],
97        'semaphore-pri' : [(0x00000000, 'no-inherit-pri'),
98                           (0x00000040, 'inherit-pri')],
99        'semaphore-pri-ceiling' : [(0x00000000, 'no-pri-ceiling'),
100                                   (0x00000080, 'pri-ceiling')],
[f814c76]101        'barrier' : [(0x00000010, 'barrier-auto-release'),
[56a70ae]102                     (0x00000000, 'barrier-manual-release')],
103        'task' : [(0x00000000, 'app-task'),
104                  (0x00008000, 'sys-task')]
105        }
106
107    def __init__(self, attr, attrtype = 'none'):
108        if attrtype not in self.groups:
109            raise 'invalid attribute type'
110        self.attrtype = attrtype
111        self.attr = attr
112
[0967a1b]113    #ToDo: Move this out
[56a70ae]114    def to_string(self):
[b117be8]115        s = '(0x%08x) ' % (self.attr)
[56a70ae]116        if self.attrtype != 'none':
117            for m in self.groups[self.attrtype]:
118                v = self.attr & self.masks[m]
119                for f in self.fields[m]:
120                    if f[0] == v:
121                        s += f[1] + ','
122                        break
123        return s[:-1]
124
125    def test(self, mask, value):
126        if self.attrtype != 'none' and \
127                mask in self.groups[self.attrtype]:
128            v = self.masks[mask] & self.attr
129            for f in self.fields[mask]:
130                if v == f[0] and value == f[1]:
131                    return True
132        return False
133
134
135class semaphore:
136    "Print a classic semaphore."
137
[6d89e3c]138    def __init__(self, obj):
[b117be8]139        if obj.type.code == gdb.TYPE_CODE_PTR:
140            self.reference = obj
141            self.object = obj.dereference()
142        else:
143            self.object = obj
144            self.reference = obj.address
[56a70ae]145        self.object_control = objects.control(self.object['Object'])
146        self.attr = attribute(self.object['attribute_set'], 'semaphore')
[f814c76]147
[56a70ae]148    def show(self, from_tty):
[b117be8]149        if self.object_control.id() != 0:
150            print '     Name:', self.object_control.name()
151            print '       Id: 0x%08x (@ 0x%08x)' % (self.object_control.id(),
152                                                   self.reference)
153            print '     Attr:', self.attr.to_string()
154            if self.attr.test('semaphore-type', 'bin-sema') or \
155               self.attr.test('semaphore-type', 'simple-bin-sema'):
156                core_mutex = mutex.control(self.object['Core_control']['mutex'])
157                print '  Nesting:', core_mutex.nest_count()
158                print '   Holder:',
159                holder = core_mutex.holder()
160                if holder:
161                    print '%s (id 0x%08x)' % (holder.brief(), holder.id())
162                else:
163                    print 'no holder (unlocked)'
164                wait_queue = core_mutex.wait_queue()
165                tasks = wait_queue.tasks()
166                print '    Queue: len = %d, state = %s' % (len(tasks),
167                                                           wait_queue.state())
168                if len(tasks) > 0:
169                    print '    Tasks:'
170                    print '    Name (c:current, r:real), (id)'
171                    for t in range(0, len(tasks)):
172                        print '      ', tasks[t].brief(), ' (%08x)' % (tasks[t].id())
173                return True
174        return False
[56a70ae]175
176class task:
[8e0de06]177    "Print a classic task"
[56a70ae]178
[6d89e3c]179    def __init__(self, obj):
[3162858]180        self.reference = obj
181        self.object = obj.dereference()
182        self.task = threads.control(self.reference)
[e60a5ee]183        self.wait_info = self.task.wait_info()
[3162858]184        self.regs = self.task.registers()
185        #self.regs = sparc.register(self.object['Registers'])
[f814c76]186
[56a70ae]187    def show(self, from_tty):
[b117be8]188        if self.task.id() != 0:
189            cpu = self.task.executing()
190            if cpu == -1:
191                cpu = 'not executing'
192            print '         Id:', '0x%08x (@ 0x%08x)' % (self.task.id(),
193                                                         self.task.reference)
194            print '       Name:', self.task.name()
195            print ' Active CPU:', cpu
196            print '      State:', self.task.current_state()
197            print '    Current:', self.task.current_priority()
198            print '       Real:', self.task.real_priority()
199            print '    Preempt:', self.task.preemptible()
200            print '   T Budget:', self.task.cpu_time_budget()
201            print '       Time:', self.task.cpu_time_used()
202            print '  Resources:', self.task.resource_count()
203            print '  Regsters:'
204            for name in self.regs.names():
205                val = self.regs.get(name)
206                print '    %20s: %08x (%d)' % (name, val, val)
207            return True
208        return False
[f814c76]209
210class message_queue:
[09086b4]211    "Print classic messege queue"
[f814c76]212
[3162858]213    def __init__(self, obj):
214        self.reference = obj
215        self.object = obj.dereference()
[f814c76]216        self.object_control = objects.control(self.object['Object'])
217        self.attr = attribute(self.object['attribute_set'], \
218            'message_queue')
[b061a67]219        self.wait_queue = threads.queue( \
220            self.object['message_queue']['Wait_queue'])
221
[8e0de06]222        self.core_control = supercore.message_queue(self.object['message_queue'])
[f814c76]223
224    def show(self, from_tty):
225        print '     Name:', self.object_control.name()
226        print '     Attr:', self.attr.to_string()
[3856406]227
[086e689]228        self.core_control.show()
229
230class timer:
231    '''Print a classic timer'''
232
[6d89e3c]233    def __init__(self, obj):
[3162858]234        self.reference = obj
235        self.object = obj.dereference()
[086e689]236        self.object_control = objects.control(self.object['Object'])
237        self.watchdog = watchdog.control(self.object['Ticker'])
238
239    def show(self, from_tty):
240        print '     Name:', self.object_control.name()
[09086b4]241        self.watchdog.show()
242
243class partition:
244    ''' Print a rtems partition '''
245
[6d89e3c]246    def __init__(self, obj):
[3162858]247        self.reference = obj
248        self.object = obj.dereference()
[09086b4]249        self.object_control = objects.control(self.object['Object'])
250        self.attr = attribute(self.object['attribute_set'], 'partition')
251        self.starting_addr = self.object['starting_address']
252        self.length = self.object['length']
253        self.buffer_size = self.object['buffer_size']
254        self.used_blocks = self.object['number_of_used_blocks']
255
256    def show(self, from_tty):
257        # ToDo: the printing still somewhat crude.
258        print '     Name:', self.object_control.name()
259        print '     Attr:', self.attr.to_string()
260        print '   Length:', self.length
[b9ee5df]261        print '   B Size:', self.buffer_size
262        print ' U Blocks:', self.used_blocks
[09086b4]263
[b9ee5df]264class region:
265    "prints a classic region"
266
[3162858]267    def __init__(self, obj):
268        self.reference = obj
269        self.object = obj.dereference()
[b9ee5df]270        self.object_control = objects.control(self.object['Object'])
271        self.attr = attribute(self.object['attribute_set'], 'region')
272        self.wait_queue = threads.queue(self.object['Wait_queue'])
273        self.heap = heaps.control(self.object['Memory'])
274
275    def show(self, from_tty):
276        print '     Name:', self.object_control.name()
277        print '     Attr:', self.attr.to_string()
278        helper.tasks_printer_routine(self.wait_queue)
279        print '   Memory:'
280        self.heap.show()
[8e0de06]281
282class barrier:
283    '''classic barrier abstraction'''
284
[3162858]285    def __init__(self, obj):
286        self.reference = obj
287        self.object = obj.dereference()
[8e0de06]288        self.object_control = objects.control(self.object['Object'])
289        self.attr = attribute(self.object['attribute_set'],'barrier')
290        self.core_b_control = supercore.barrier_control(self.object['Barrier'])
291
292    def show(self,from_tty):
293        print '     Name:',self.object_control.name()
294        print '     Attr:',self.attr.to_string()
295
296        if self.attr.test('barrier','barrier-auto-release'):
297            max_count = self.core_b_control.max_count()
298            print 'Aut Count:', max_count
299
300        print '  Waiting:',self.core_b_control.waiting_threads()
301        helper.tasks_printer_routine(self.core_b_control.tasks())
Note: See TracBrowser for help on using the repository browser.