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
This commit is contained in:
Dhananjay Balan
2013-07-12 19:04:37 +05:30
committed by Chris Johns
parent 6e75f4ebf5
commit b061a67742
6 changed files with 30 additions and 141 deletions

View File

@@ -3,14 +3,23 @@ if __name__ == "__main__":
import sys import sys
import os.path import os.path
sys.path.append(os.path.dirname(__file__)) sys.path.append(os.path.dirname(__file__))
import supercore
import chains import chains
import rtems import rtems
import classic import classic
import objects import objects
import threads import threads
import supercore_printer
import classic_printer
# Needed to reload code inside gdb source command
reload(supercore)
reload(chains) reload(chains)
reload(rtems) reload(rtems)
reload(classic) reload(classic)
reload(objects) reload(objects)
reload(threads) reload(threads)
reload(supercore_printer)
reload(classic_printer)
print 'RTEMS GDB Support loaded' print 'RTEMS GDB Support loaded'

View File

@@ -32,6 +32,8 @@ class node:
return self.node_val.cast(nodetype) return self.node_val.cast(nodetype)
return None return None
def to_string(self):
return self.node_val['next'] + "Prev: "+self.node_val['previous']
class control: class control:
"""Manage the Chain_Control.""" """Manage the Chain_Control."""
@@ -44,4 +46,5 @@ class control:
return t return t
def last(self): def last(self):
return node(self.ctrl['first']) return node(self.ctrl['Tail']['Node'])

View File

@@ -11,6 +11,7 @@ import re
import objects import objects
import threads import threads
import supercore
class attribute: class attribute:
"""The Classic API attribute.""" """The Classic API attribute."""
@@ -98,63 +99,6 @@ class attribute:
return True return True
return False return False
class attribute_printer:
def __init__(self, attr):
self.attr = attribute(attr,'all')
def to_string(self):
return gdb.Value(self.attr.to_string())
class semaphore_printer:
"""Print a Semaphore_Control object. Print using the struct display hint
and an iterator."""
class iterator:
"""Use an iterator for each field expanded from the id so GDB output
is formatted correctly."""
def __init__(self, semaphore):
self.semaphore = semaphore
self.count = 0
def __iter__(self):
return self
def next(self):
self.count += 1
if self.count == 1:
return self.semaphore['Object']
elif self.count == 2:
attr = attribute(self.semaphore['attribute_set'],
'semaphore')
return attr.to_string()
elif self.count == 3:
return self.semaphore['Core_control']
raise StopIteration
def __init__(self, semaphore):
self.semaphore = semaphore
def to_string(self):
return ''
@staticmethod
def key(i):
if i == 0:
return 'Object'
elif i == 1:
return 'attribute_set'
elif i == 2:
return 'Core_control'
return 'bad'
def children(self):
counter = itertools.imap (self.key, itertools.count())
return itertools.izip (counter, self.iterator(self.semaphore))
def display_hint (self):
return 'struct'
class semaphore: class semaphore:
"Print a classic semaphore." "Print a classic semaphore."
@@ -225,9 +169,13 @@ class message_queue:
self.object_control = objects.control(self.object['Object']) self.object_control = objects.control(self.object['Object'])
self.attr = attribute(self.object['attribute_set'], \ self.attr = attribute(self.object['attribute_set'], \
'message_queue') 'message_queue')
self.wait_queue = threads.queue( \
self.object['message_queue']['Wait_queue'])
self.core_control = supercore.CORE_message_queue(self.object['message_queue'])
def show(self, from_tty): def show(self, from_tty):
print ' Name:', self.object_control.name() print ' Name:', self.object_control.name()
print ' Attr:', self.attr.to_string() print ' Attr:', self.attr.to_string()
self.core_control.show()

View File

@@ -247,71 +247,8 @@ class control:
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 id_printer:
"""Print an object given the ID. Print using the struct display hint and an
iterator."""
class iterator:
"""Use an iterator for each field expanded from the id so GDB output
is formatted correctly."""
def __init__(self, id):
self.id = id
self.count = 0
def __iter__(self):
return self
def next(self):
self.count += 1
if self.count == 1:
return int(self.id.value())
elif self.count == 2:
return self.id.node()
elif self.count == 3:
return self.id.api()
elif self.count == 4:
return self.id._class()
elif self.count == 5:
return self.id.index()
raise StopIteration
def __init__(self, id):
self.id = ident(id)
def to_string(self):
return ''
@staticmethod
def key(i):
if i == 0:
return 'id'
elif i == 1:
return 'node'
elif i == 2:
return 'api'
elif i == 3:
return 'class'
elif i == 4:
return 'index'
return 'bad'
def children(self):
counter = itertools.imap (self.key, itertools.count())
return itertools.izip (counter, self.iterator(self.id))
def display_hint (self):
return 'struct'
class name_printer:
"""Pretty printer for an object's name. It has to guess the type as no
information is available to help determine it."""
def __init__(self, nameval):
self.name = name(nameval)
def to_string(self):
return gdb.Value(str(self.name))
class control_printer: class control_printer:

View File

@@ -12,6 +12,10 @@ import objects
import threads import threads
import classic import classic
# ToDo: Move every printing out
import supercore_printer
import classic_printer
nesting = 0 nesting = 0
def type_from_value(val): def type_from_value(val):
@@ -50,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: objects.id_printer(val) pp_dict[re.compile('^rtems_id$')] = lambda val: supercore_printer.id_printer(val)
pp_dict[re.compile('^Objects_Id$')] = lambda val: objects.id_printer(val) pp_dict[re.compile('^Objects_Id$')] = lambda val: supercore_printer.id_printer(val)
pp_dict[re.compile('^Objects_Name$')] = lambda val: objects.name_printer(val) pp_dict[re.compile('^Objects_Name$')] = lambda val: supercore_printer.name_printer(val)
pp_dict[re.compile('^Objects_Control$')] = lambda val: objects.control_printer(val) pp_dict[re.compile('^Objects_Control$')] = lambda val: supercore_printer.control_printer(val)
pp_dict[re.compile('^States_Control$')] = lambda val: threads.state_printer(val) pp_dict[re.compile('^States_Control$')] = lambda val: supercore_printer.state_printer(val)
pp_dict[re.compile('^rtems_attribute$')] = lambda val: classic.attribute_printer(val) pp_dict[re.compile('^rtems_attribute$')] = lambda val: classic_printer.attribute_printer(val)
pp_dict[re.compile('^Semaphore_Control$')] = lambda val: classic.semaphore_printer(val) pp_dict[re.compile('^Semaphore_Control$')] = lambda val: classic_printer.semaphore_printer(val)
class rtems(gdb.Command): class rtems(gdb.Command):
"""Prefix command for RTEMS.""" """Prefix command for RTEMS."""

View File

@@ -191,17 +191,5 @@ class queue:
self.que['Queues']['Priority'][ph]))) self.que['Queues']['Priority'][ph])))
return t return t
def to_string(self):
if self.fifo():
s = 'fifo'
else:
s = 'priority'
return
class state_printer:
def __init__(self, s):
self.s = state(s)
def to_string(self):
return self.s.to_string()