source: rtems-tools/tools/gdb/python/rtems.py @ f814c76

4.104.11
Last change on this file since f814c76 was f814c76, checked in by Dhananjay Balan <mb.dhananjay@…>, on Jul 8, 2013 at 4:12:48 PM

Messege Queue Objects
Added intial support for printing

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