summaryrefslogblamecommitdiffstats
path: root/tools/gdb/python/chains.py
blob: ef33ed65ebccc9cbdc9b5298ceafe312eee036e3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                               


                             


                           
                                                 


                           
                                                     






                                                

                                                                         
 






                                   

                                           

                   

                                              


                                              
#
# RTEMS Chains Support
# Copyright 2010 Chris Johns (chrisj@rtems.org)
#
# $Id$
#

import gdb

class node:
    """Manage the Chain_Node."""

    def __init__(self, node_val):
        self.node_val = node_val

    def null(self):
        if not self.node_val:
            return True
        return False

    def next(self):
        if not self.null():
            self.node_val = self.node_val['next']

    def previous(self):
        if not self.null():
            self.node_val = self.node_val['previous']

    def cast(self, typename):
        if not self.null():
            nodetype = gdb.lookup_type(typename)
            return self.node_val.cast(nodetype)
        return None

    def to_string(self):
        return self.node_val['next'] + "Prev: "+self.node_val['previous']

class control:
    """Manage the Chain_Control."""

    def __init__(self, ctrl):
        self.ctrl = ctrl

    def first(self):
        t = node(self.ctrl['Head']['Node'])
        return t

    def last(self):
        return node(self.ctrl['Tail']['Node'])

    def empty(self):
        if self.last() == self.first().next():
            return True