From 8d035f8556f5c121b709c1cd6ed223fa2b70b66c Mon Sep 17 00:00:00 2001 From: Dhananjay Balan Date: Tue, 20 Aug 2013 21:47:22 +0530 Subject: Refactor - pretty printers moved to pretty module - command and subcommands get own module --- tools/gdb/python/__init__.py | 20 +------------ tools/gdb/python/helper.py | 12 +++++++- tools/gdb/python/main.py | 19 ++++++++++++ tools/gdb/python/pretty.py | 53 ++++++++++++++++++++++++++++++++++ tools/gdb/python/rtems.py | 69 ++------------------------------------------ 5 files changed, 86 insertions(+), 87 deletions(-) create mode 100644 tools/gdb/python/main.py create mode 100644 tools/gdb/python/pretty.py diff --git a/tools/gdb/python/__init__.py b/tools/gdb/python/__init__.py index 694eb06..36d2c06 100644 --- a/tools/gdb/python/__init__.py +++ b/tools/gdb/python/__init__.py @@ -3,24 +3,6 @@ if __name__ == "__main__": import sys import os.path sys.path.append(os.path.dirname(__file__)) - import supercore - import chains - import rtems - import classic - import objects - import threads - - import supercore_printer - import classic_printer - - # Needed inorder to reload code from inside gdb - reload(supercore) - reload(chains) - reload(rtems) - reload(classic) - reload(objects) - reload(threads) - reload(supercore_printer) - reload(classic_printer) + import main print 'RTEMS GDB Support loaded' diff --git a/tools/gdb/python/helper.py b/tools/gdb/python/helper.py index c9c9a42..146ee69 100644 --- a/tools/gdb/python/helper.py +++ b/tools/gdb/python/helper.py @@ -1,8 +1,18 @@ # # RTEMS GDB support helper routins. +import gdb + def tasks_printer_routine(wait_queue): tasks = wait_queue.tasks() print ' Queue: len = %d, state = %s' % (len(tasks),wait_queue.state()) for t in range(0, len(tasks)): - print ' ', tasks[t].brief(), ' (%08x)' % (tasks[t].id()) \ No newline at end of file + print ' ', tasks[t].brief(), ' (%08x)' % (tasks[t].id()) + +def type_from_value(val): + type = val.type; + # If it points to a reference, get the reference. + if type.code == gdb.TYPE_CODE_REF: + type = type.target () + # Get the unqualified type + return type.unqualified () diff --git a/tools/gdb/python/main.py b/tools/gdb/python/main.py new file mode 100644 index 0000000..2ef475a --- /dev/null +++ b/tools/gdb/python/main.py @@ -0,0 +1,19 @@ +# +# RTEMS GDB Extensions +# +# main + +import gdb +import pretty +import rtems + +gdb.pretty_printers = [] +gdb.pretty_printers.append(pretty.lookup_function) + +# Register commands +# rtems and subcommands +rtems.rtems() +rtems.rtems_object() +rtems.rtems_semaphore() +rtems.rtems_task() +rtems.rtems_message_queue() \ No newline at end of file diff --git a/tools/gdb/python/pretty.py b/tools/gdb/python/pretty.py new file mode 100644 index 0000000..929c245 --- /dev/null +++ b/tools/gdb/python/pretty.py @@ -0,0 +1,53 @@ +# +# RTEMS pretty printers +# +import re +import helper +import objects + +import supercore_printer +import classic_printer + +pretty_printer = { + + '^rtems_id$' : supercore_printer.id, + '^Objects_Id$' : supercore_printer.id, + '^Objects_Name$' : supercore_printer.name, + '^Objects_Control$' : supercore_printer.control, + '^States_Control$' : supercore_printer.state, + '^rtems_attribute$' : classic_printer.attribute, + '^Semaphore_Control$' : classic_printer.semaphore +} + + +def build_pretty_printer (): + pp_dict = {} + + for name in pretty_printer: + pp_dict[re.compile(name)] = pretty_printer[name] + + return pp_dict + +def lookup_function (val): + "Look-up and return a pretty-printer that can print val." + + global nesting + + typename = str(helper.type_from_value(val)) + + for function in pp_dict: + if function.search (typename): + nesting += 1 + result = pp_dict[function] (val) + nesting -= 1 + if nesting == 0: + objects.information.invalidate() + return result + + # Cannot find a pretty printer. Return None. + return None + +# ToDo: properly document. +nesting = 0 + +pp_dict = build_pretty_printer() diff --git a/tools/gdb/python/rtems.py b/tools/gdb/python/rtems.py index 9ae2105..c45d72e 100644 --- a/tools/gdb/python/rtems.py +++ b/tools/gdb/python/rtems.py @@ -12,55 +12,6 @@ import objects import threads import classic -# ToDo: Move every printing out -import supercore_printer -import classic_printer - -nesting = 0 - -def type_from_value(val): - type = val.type; - # If it points to a reference, get the reference. - if type.code == gdb.TYPE_CODE_REF: - type = type.target () - # Get the unqualified type - return type.unqualified () - -def register_rtems_printers (obj): - "Register RTEMS pretty-printers with objfile Obj." - - if obj == None: - obj = gdb - - obj.pretty_printers.append (lookup_function) - -def lookup_function (val): - "Look-up and return a pretty-printer that can print val." - - global nesting - - typename = str(type_from_value(val)) - - for function in pp_dict: - if function.search (typename): - nesting += 1 - result = pp_dict[function] (val) - nesting -= 1 - if nesting == 0: - objects.information.invalidate() - return result - - # Cannot find a pretty printer. Return None. - return None - -def build_rtems_dict(): - pp_dict[re.compile('^rtems_id$')] = lambda val: supercore_printer.id(val) - pp_dict[re.compile('^Objects_Id$')] = lambda val: supercore_printer.id(val) - pp_dict[re.compile('^Objects_Name$')] = lambda val: supercore_printer.name(val) - pp_dict[re.compile('^Objects_Control$')] = lambda val: supercore_printer.control(val) - pp_dict[re.compile('^States_Control$')] = lambda val: supercore_printer.state(val) - pp_dict[re.compile('^rtems_attribute$')] = lambda val: classic_printer.attribute(val) - pp_dict[re.compile('^Semaphore_Control$')] = lambda val: classic_printer.semaphore(val) class rtems(gdb.Command): """Prefix command for RTEMS.""" @@ -157,8 +108,7 @@ class rtems_task(gdb.Command): try: index = int(val) except ValueError: - print "error: %s is not an index" % (val) - return + raise gdb.GdbError( "Value is not an integer") try: obj = objects.information.object_return(self.api, @@ -198,21 +148,6 @@ class rtems_message_queue(gdb.Command): print "error: index %s is invalid" % (index) return - print "Ahi" instance = classic.message_queue(obj) instance.show(from_tty) - objects.information.invalidate() - - -# -# Main -# -pp_dict = {} -build_rtems_dict() -gdb.pretty_printers = [] -gdb.pretty_printers.append (lookup_function) -rtems() -rtems_object() -rtems_semaphore() -rtems_task() -rtems_message_queue() \ No newline at end of file + objects.information.invalidate() \ No newline at end of file -- cgit v1.2.3