- pretty printers moved to pretty module
 - command and subcommands get own module
This commit is contained in:
Dhananjay Balan
2013-08-20 21:47:22 +05:30
committed by Chris Johns
parent 2c25dc56ed
commit 8d035f8556
5 changed files with 86 additions and 87 deletions

View File

@@ -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'

View File

@@ -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())
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 ()

19
tools/gdb/python/main.py Normal file
View File

@@ -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()

View File

@@ -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()

View File

@@ -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()
objects.information.invalidate()