[rtems-tools commit] Refactoring

Chris Johns chrisj at rtems.org
Sun Aug 24 23:45:33 UTC 2014


Module:    rtems-tools
Branch:    master
Commit:    0967a1b679495f728781bd05318379024cadf5c5
Changeset: http://git.rtems.org/rtems-tools/commit/?id=0967a1b679495f728781bd05318379024cadf5c5

Author:    Dhananjay Balan <mb.dhananjay at gmail.com>
Date:      Sat Jul 13 16:49:59 2013 +0530

Refactoring
 - drop _printer suffix from printer classes.

---

 tools/gdb/python/__init__.py          |    3 +-
 tools/gdb/python/classic.py           |    1 +
 tools/gdb/python/classic_printer.py   |    6 ++--
 tools/gdb/python/helper.py            |    8 +++++
 tools/gdb/python/objects.py           |   51 +--------------------------------
 tools/gdb/python/rtems.py             |   14 ++++----
 tools/gdb/python/supercore.py         |   10 +-----
 tools/gdb/python/supercore_printer.py |   12 ++++----
 8 files changed, 30 insertions(+), 75 deletions(-)

diff --git a/tools/gdb/python/__init__.py b/tools/gdb/python/__init__.py
index dd55529..694eb06 100644
--- a/tools/gdb/python/__init__.py
+++ b/tools/gdb/python/__init__.py
@@ -13,7 +13,7 @@ if __name__ == "__main__":
     import supercore_printer
     import classic_printer
 
-    # Needed to reload code inside gdb source command
+    # Needed inorder to reload code from inside gdb
     reload(supercore)
     reload(chains)
     reload(rtems)
@@ -22,4 +22,5 @@ if __name__ == "__main__":
     reload(threads)
     reload(supercore_printer)
     reload(classic_printer)
+
     print 'RTEMS GDB Support loaded'
diff --git a/tools/gdb/python/classic.py b/tools/gdb/python/classic.py
index e82078d..9af11df 100644
--- a/tools/gdb/python/classic.py
+++ b/tools/gdb/python/classic.py
@@ -79,6 +79,7 @@ class attribute:
         self.attrtype = attrtype
         self.attr = attr
 
+    #ToDo: Move this out
     def to_string(self):
         s = '0x%08x,' % (self.attr)
         if self.attrtype != 'none':
diff --git a/tools/gdb/python/classic_printer.py b/tools/gdb/python/classic_printer.py
index e9d7cb8..a25d756 100644
--- a/tools/gdb/python/classic_printer.py
+++ b/tools/gdb/python/classic_printer.py
@@ -2,7 +2,7 @@
 # RTEMS Classic pretty printers for GDB
 #
 
-class attribute_printer:
+class attribute:
 
     def __init__(self, attribute):
         ''' ToDo: Verify - usage of all '''
@@ -11,8 +11,8 @@ class attribute_printer:
     def to_string(self):
         return gdb.Value(self.attr.to_string())
 
-class semaphore_printer:
-    """WIP: Print a Semaphore_Control object. Print using the struct display hint
+class semaphore:
+    """ToDo: Print a Semaphore_Control object. Print using the struct display hint
     and an iterator. """
 
     class iterator:
diff --git a/tools/gdb/python/helper.py b/tools/gdb/python/helper.py
new file mode 100644
index 0000000..ec17400
--- /dev/null
+++ b/tools/gdb/python/helper.py
@@ -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())
\ No newline at end of file
diff --git a/tools/gdb/python/objects.py b/tools/gdb/python/objects.py
index d2ba216..23ea7be 100644
--- a/tools/gdb/python/objects.py
+++ b/tools/gdb/python/objects.py
@@ -245,53 +245,4 @@ class control:
 
     def name(self):
         is_string = information.is_string(self._id.api(), self._id._class())
-        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'
+        return str(name(self.object['name'], is_string))
\ No newline at end of file
diff --git a/tools/gdb/python/rtems.py b/tools/gdb/python/rtems.py
index d530e6e..4622ced 100644
--- a/tools/gdb/python/rtems.py
+++ b/tools/gdb/python/rtems.py
@@ -54,13 +54,13 @@ def lookup_function (val):
     return None
 
 def build_rtems_dict():
-    pp_dict[re.compile('^rtems_id$')]   = lambda val: supercore_printer.id_printer(val)
-    pp_dict[re.compile('^Objects_Id$')] = lambda val: supercore_printer.id_printer(val)
-    pp_dict[re.compile('^Objects_Name$')] = lambda val: supercore_printer.name_printer(val)
-    pp_dict[re.compile('^Objects_Control$')] = lambda val: supercore_printer.control_printer(val)
-    pp_dict[re.compile('^States_Control$')] = lambda val: supercore_printer.state_printer(val)
-    pp_dict[re.compile('^rtems_attribute$')] = lambda val: classic_printer.attribute_printer(val)
-    pp_dict[re.compile('^Semaphore_Control$')] = lambda val: classic_printer.semaphore_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(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."""
diff --git a/tools/gdb/python/supercore.py b/tools/gdb/python/supercore.py
index 4378e12..7e958b1 100644
--- a/tools/gdb/python/supercore.py
+++ b/tools/gdb/python/supercore.py
@@ -3,13 +3,7 @@
 #
 
 import threads
-
-# 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())
+import helper
 
 class CORE_message_queue:
     '''Manage a Supercore message_queue'''
@@ -21,4 +15,4 @@ class CORE_message_queue:
         # self.buffer
 
     def show(self):
-        tasks_printer_rotuine(self.wait_queue)
+        helper.tasks_printer_rotuine(self.wait_queue)
diff --git a/tools/gdb/python/supercore_printer.py b/tools/gdb/python/supercore_printer.py
index cee9097..ec1d416 100644
--- a/tools/gdb/python/supercore_printer.py
+++ b/tools/gdb/python/supercore_printer.py
@@ -4,7 +4,7 @@
 import objects
 import itertools
 
-class id_printer:
+class id:
     """Print an object given the ID. Print using the struct display hint and an
     iterator."""
 
@@ -60,7 +60,7 @@ class id_printer:
     def display_hint (self):
         return 'struct'
 
-class name_printer:
+class name:
     """Pretty printer for an object's name. It has to guess the type as no
     information is available to help determine it."""
 
@@ -70,7 +70,7 @@ class name_printer:
     def to_string(self):
         return str(self.name)
 
-class control_printer:
+class control:
 
     class iterator:
         """Use an iterator for each field expanded from the id so GDB output
@@ -117,14 +117,14 @@ class control_printer:
         return 'struct'
 
 
-class state_printer:
+class state:
 
     def __init__(self, state):
         self.state = threads.state(state)
     def to_string(self):
         return self.state.to_string()
 
-class chains_printer:
+class chains:
 
     def __init__(self,chain):
         self.chain = chains.control(chain)
@@ -132,7 +132,7 @@ class chains_printer:
     def to_string(self):
         return "First:"+str(self.chain.first())+"\n Last:"+str(self.chain.last())
 
-class node_printer:
+class node:
     def __init__(self, node):
         self.node = chains.node(node)
 



More information about the vc mailing list