Refactoring

- drop _printer suffix from printer classes.
This commit is contained in:
Dhananjay Balan
2013-07-13 16:31:59 +05:30
committed by Chris Johns
parent a785e254f2
commit 0967a1b679
8 changed files with 30 additions and 75 deletions

View File

@@ -13,7 +13,7 @@ if __name__ == "__main__":
import supercore_printer import supercore_printer
import classic_printer import classic_printer
# Needed to reload code inside gdb source command # Needed inorder to reload code from inside gdb
reload(supercore) reload(supercore)
reload(chains) reload(chains)
reload(rtems) reload(rtems)
@@ -22,4 +22,5 @@ if __name__ == "__main__":
reload(threads) reload(threads)
reload(supercore_printer) reload(supercore_printer)
reload(classic_printer) reload(classic_printer)
print 'RTEMS GDB Support loaded' print 'RTEMS GDB Support loaded'

View File

@@ -79,6 +79,7 @@ class attribute:
self.attrtype = attrtype self.attrtype = attrtype
self.attr = attr self.attr = attr
#ToDo: Move this out
def to_string(self): def to_string(self):
s = '0x%08x,' % (self.attr) s = '0x%08x,' % (self.attr)
if self.attrtype != 'none': if self.attrtype != 'none':

View File

@@ -2,7 +2,7 @@
# RTEMS Classic pretty printers for GDB # RTEMS Classic pretty printers for GDB
# #
class attribute_printer: class attribute:
def __init__(self, attribute): def __init__(self, attribute):
''' ToDo: Verify - usage of all ''' ''' ToDo: Verify - usage of all '''
@@ -11,8 +11,8 @@ class attribute_printer:
def to_string(self): def to_string(self):
return gdb.Value(self.attr.to_string()) return gdb.Value(self.attr.to_string())
class semaphore_printer: class semaphore:
"""WIP: Print a Semaphore_Control object. Print using the struct display hint """ToDo: Print a Semaphore_Control object. Print using the struct display hint
and an iterator. """ and an iterator. """
class iterator: class iterator:

View File

@@ -0,0 +1,8 @@
#
# RTEMS GDB support helper routins.
def tasks_printer_rotuine(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())

View File

@@ -245,53 +245,4 @@ class control:
def name(self): def name(self):
is_string = information.is_string(self._id.api(), self._id._class()) is_string = information.is_string(self._id.api(), self._id._class())
return str(name(self.object['name'], is_string)) return str(name(self.object['name'], is_string))
class control_printer:
class iterator:
"""Use an iterator for each field expanded from the id so GDB output
is formatted correctly."""
def __init__(self, object):
self.object = object
self.count = 0
def __iter__(self):
return self
def next(self):
self.count += 1
if self.count == 1:
return self.object.node()
elif self.count == 2:
return self.object.id()
elif self.count == 3:
return self.object.name()
raise StopIteration
def to_string(self):
return ''
def __init__(self, object):
self.object = control(object)
@staticmethod
def key(i):
if i == 0:
return 'Node'
elif i == 1:
return 'id'
elif i == 2:
return 'name'
return 'bad'
def children(self):
counter = itertools.imap (self.key, itertools.count())
return itertools.izip (counter, self.iterator(self.object))
def display_hint (self):
return 'struct'

View File

@@ -54,13 +54,13 @@ def lookup_function (val):
return None return None
def build_rtems_dict(): def build_rtems_dict():
pp_dict[re.compile('^rtems_id$')] = lambda val: supercore_printer.id_printer(val) pp_dict[re.compile('^rtems_id$')] = lambda val: supercore_printer.id(val)
pp_dict[re.compile('^Objects_Id$')] = lambda val: supercore_printer.id_printer(val) pp_dict[re.compile('^Objects_Id$')] = lambda val: supercore_printer.id(val)
pp_dict[re.compile('^Objects_Name$')] = lambda val: supercore_printer.name_printer(val) pp_dict[re.compile('^Objects_Name$')] = lambda val: supercore_printer.name(val)
pp_dict[re.compile('^Objects_Control$')] = lambda val: supercore_printer.control_printer(val) pp_dict[re.compile('^Objects_Control$')] = lambda val: supercore_printer.control(val)
pp_dict[re.compile('^States_Control$')] = lambda val: supercore_printer.state_printer(val) pp_dict[re.compile('^States_Control$')] = lambda val: supercore_printer.state(val)
pp_dict[re.compile('^rtems_attribute$')] = lambda val: classic_printer.attribute_printer(val) pp_dict[re.compile('^rtems_attribute$')] = lambda val: classic_printer.attribute(val)
pp_dict[re.compile('^Semaphore_Control$')] = lambda val: classic_printer.semaphore_printer(val) pp_dict[re.compile('^Semaphore_Control$')] = lambda val: classic_printer.semaphore(val)
class rtems(gdb.Command): class rtems(gdb.Command):
"""Prefix command for RTEMS.""" """Prefix command for RTEMS."""

View File

@@ -3,13 +3,7 @@
# #
import threads import threads
import helper
# ToDo: Move this to helper.
def tasks_printer_rotuine(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())
class CORE_message_queue: class CORE_message_queue:
'''Manage a Supercore message_queue''' '''Manage a Supercore message_queue'''
@@ -21,4 +15,4 @@ class CORE_message_queue:
# self.buffer # self.buffer
def show(self): def show(self):
tasks_printer_rotuine(self.wait_queue) helper.tasks_printer_rotuine(self.wait_queue)

View File

@@ -4,7 +4,7 @@
import objects import objects
import itertools import itertools
class id_printer: class id:
"""Print an object given the ID. Print using the struct display hint and an """Print an object given the ID. Print using the struct display hint and an
iterator.""" iterator."""
@@ -60,7 +60,7 @@ class id_printer:
def display_hint (self): def display_hint (self):
return 'struct' return 'struct'
class name_printer: class name:
"""Pretty printer for an object's name. It has to guess the type as no """Pretty printer for an object's name. It has to guess the type as no
information is available to help determine it.""" information is available to help determine it."""
@@ -70,7 +70,7 @@ class name_printer:
def to_string(self): def to_string(self):
return str(self.name) return str(self.name)
class control_printer: class control:
class iterator: class iterator:
"""Use an iterator for each field expanded from the id so GDB output """Use an iterator for each field expanded from the id so GDB output
@@ -117,14 +117,14 @@ class control_printer:
return 'struct' return 'struct'
class state_printer: class state:
def __init__(self, state): def __init__(self, state):
self.state = threads.state(state) self.state = threads.state(state)
def to_string(self): def to_string(self):
return self.state.to_string() return self.state.to_string()
class chains_printer: class chains:
def __init__(self,chain): def __init__(self,chain):
self.chain = chains.control(chain) self.chain = chains.control(chain)
@@ -132,7 +132,7 @@ class chains_printer:
def to_string(self): def to_string(self):
return "First:"+str(self.chain.first())+"\n Last:"+str(self.chain.last()) return "First:"+str(self.chain.first())+"\n Last:"+str(self.chain.last())
class node_printer: class node:
def __init__(self, node): def __init__(self, node):
self.node = chains.node(node) self.node = chains.node(node)