1 | # |
---|
2 | # RTEMS Pretty Printers |
---|
3 | # Copyright 2010 Chris Johns (chrisj@rtems.org) |
---|
4 | # |
---|
5 | # $Id$ |
---|
6 | # |
---|
7 | |
---|
8 | import gdb |
---|
9 | import re |
---|
10 | |
---|
11 | import objects |
---|
12 | import threads |
---|
13 | import classic |
---|
14 | |
---|
15 | # ToDo: Move every printing out |
---|
16 | import supercore_printer |
---|
17 | import classic_printer |
---|
18 | |
---|
19 | nesting = 0 |
---|
20 | |
---|
21 | def 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 | |
---|
29 | def 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 | |
---|
37 | def 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 | |
---|
56 | def 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 | |
---|
65 | class 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 | |
---|
74 | class 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 | # |
---|
110 | pp_dict = {} |
---|
111 | build_rtems_dict() |
---|
112 | gdb.pretty_printers = [] |
---|
113 | gdb.pretty_printers.append (lookup_function) |
---|
114 | rtems() |
---|
115 | rtems_object() |
---|