source: rtems-tools/tools/gdb/python/rtems.py @ 09086b4

4.104.11
Last change on this file since 09086b4 was 09086b4, checked in by Dhananjay Balan <mb.dhananjay@…>, on Jul 27, 2013 at 8:41:19 AM

Support classic/partitions
Added support for partition object.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#
2# RTEMS Pretty Printers
3# Copyright 2010 Chris Johns (chrisj@rtems.org)
4#
5# $Id$
6#
7
8import gdb
9import re
10
11import objects
12import threads
13import classic
14
15# ToDo: Move every printing out
16import supercore_printer
17import classic_printer
18
19nesting = 0
20
21def type_from_value(val):
22    type = val.type;
23    # If it points to a reference, get the reference.
24    if type.code == gdb.TYPE_CODE_REF:
25        type = type.target ()
26    # Get the unqualified type
27    return type.unqualified ()
28
29def register_rtems_printers (obj):
30    "Register RTEMS pretty-printers with objfile Obj."
31
32    if obj == None:
33        obj = gdb
34
35    obj.pretty_printers.append (lookup_function)
36
37def lookup_function (val):
38    "Look-up and return a pretty-printer that can print val."
39
40    global nesting
41
42    typename = str(type_from_value(val))
43
44    for function in pp_dict:
45        if function.search (typename):
46            nesting += 1
47            result = pp_dict[function] (val)
48            nesting -= 1
49            if nesting == 0:
50                objects.information.invalidate()
51            return result
52
53    # Cannot find a pretty printer.  Return None.
54    return None
55
56def build_rtems_dict():
57    pp_dict[re.compile('^rtems_id$')]   = lambda val: supercore_printer.id(val)
58    pp_dict[re.compile('^Objects_Id$')] = lambda val: supercore_printer.id(val)
59    pp_dict[re.compile('^Objects_Name$')] = lambda val: supercore_printer.name(val)
60    pp_dict[re.compile('^Objects_Control$')] = lambda val: supercore_printer.control(val)
61    pp_dict[re.compile('^States_Control$')] = lambda val: supercore_printer.state(val)
62    pp_dict[re.compile('^rtems_attribute$')] = lambda val: classic_printer.attribute(val)
63    pp_dict[re.compile('^Semaphore_Control$')] = lambda val: classic_printer.semaphore(val)
64
65class rtems(gdb.Command):
66    """Prefix command for RTEMS."""
67
68    def __init__(self):
69        super(rtems, self).__init__('rtems',
70                                    gdb.COMMAND_STATUS,
71                                    gdb.COMPLETE_NONE,
72                                    True)
73
74class rtems_object(gdb.Command):
75    """Object sub-command for RTEMS"""
76
77    objects = {
78        'classic/semaphores': lambda id: classic.semaphore(id),
79        'classic/tasks': lambda id: classic.task(id),
80        'classic/message_queues': lambda id: classic.message_queue(id),
81        'classic/timers' : lambda id: classic.timer(id),
82        'classic/partitions' : lambda id: classic.partition(id)
83        }
84
85    def __init__(self):
86        self.__doc__ = 'Display the RTEMS object given a numeric ID.'
87        super(rtems_object, self).__init__('rtems object',
88                                           gdb.COMMAND_STATUS)
89
90    def invoke(self, arg, from_tty):
91        for num in arg.split():
92            try:
93                val = gdb.parse_and_eval(num)
94                num = int(val)
95            except:
96                print 'error: "%s" is not a number' % (num)
97                return
98            id = objects.ident(num)
99            if not id.valid():
100                print 'Invalid object id'
101            print 'API:%s Class:%s Node:%d Index:%d Id:%08X' % \
102                (id.api(), id._class(), id.node(), id.index(), id.value())
103            objectname = id.api() + '/' + id._class()
104            if objectname in self.objects:
105                object = self.objects[objectname](id)
106                object.show(from_tty)
107        objects.information.invalidate()
108
109#
110# Main
111#
112pp_dict = {}
113build_rtems_dict()
114gdb.pretty_printers = []
115gdb.pretty_printers.append (lookup_function)
116rtems()
117rtems_object()
Note: See TracBrowser for help on using the repository browser.