source: rtems-tools/tools/gdb/python/rtems.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: 3.4 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_printer(val)
58    pp_dict[re.compile('^Objects_Id$')] = lambda val: supercore_printer.id_printer(val)
59    pp_dict[re.compile('^Objects_Name$')] = lambda val: supercore_printer.name_printer(val)
60    pp_dict[re.compile('^Objects_Control$')] = lambda val: supercore_printer.control_printer(val)
61    pp_dict[re.compile('^States_Control$')] = lambda val: supercore_printer.state_printer(val)
62    pp_dict[re.compile('^rtems_attribute$')] = lambda val: classic_printer.attribute_printer(val)
63    pp_dict[re.compile('^Semaphore_Control$')] = lambda val: classic_printer.semaphore_printer(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        }
82
83    def __init__(self):
84        self.__doc__ = 'Display the RTEMS object given a numeric ID.'
85        super(rtems_object, self).__init__('rtems object',
86                                           gdb.COMMAND_STATUS)
87
88    def invoke(self, arg, from_tty):
89        for num in arg.split():
90            try:
91                val = gdb.parse_and_eval(num)
92                num = int(val)
93            except:
94                print 'error: "%s" is not a number' % (num)
95                return
96            id = objects.ident(num)
97            if not id.valid():
98                print 'Invalid object id'
99            print 'API:%s Class:%s Node:%d Index:%d Id:%08X' % \
100                (id.api(), id._class(), id.node(), id.index(), id.value())
101            objectname = id.api() + '/' + id._class()
102            if objectname in self.objects:
103                object = self.objects[objectname](id)
104                object.show(from_tty)
105        objects.information.invalidate()
106
107#
108# Main
109#
110pp_dict = {}
111build_rtems_dict()
112gdb.pretty_printers = []
113gdb.pretty_printers.append (lookup_function)
114rtems()
115rtems_object()
Note: See TracBrowser for help on using the repository browser.