source: rtems-tools/tools/gdb/python/chains.py @ b117be8

4.104.115
Last change on this file since b117be8 was b117be8, checked in by Chris Johns <chrisj@…>, on 03/17/15 at 02:11:57

gdb/python: Update the support to a recent RTEMS.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1# RTEMS Tools Project (http://www.rtems.org/)
2# Copyright 2010-2014 Chris Johns (chrisj@rtems.org)
3# All rights reserved.
4#
5# This file is part of the RTEMS Tools package in 'rtems-tools'.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are met:
9#
10# 1. Redistributions of source code must retain the above copyright notice,
11# this list of conditions and the following disclaimer.
12#
13# 2. Redistributions in binary form must reproduce the above copyright notice,
14# this list of conditions and the following disclaimer in the documentation
15# and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28#
29
30#
31# RTEMS Chains Support
32#
33
34import gdb
35
36class node:
37    """Manage the Chain_Node."""
38
39    def __init__(self, node_val):
40        if node_val:
41            if node_val.type.code == gdb.TYPE_CODE_PTR:
42                self.reference = node_val
43                self.node_val = node_val.dereference()
44            else:
45                self.node_val = node_val
46                self.reference = node_val.address
47        else:
48            self.node_val = node_val
49
50    def __str__(self):
51        return self.to_string()
52
53    def null(self):
54        if not self.node_val:
55            return True
56        return False
57
58    def next(self):
59        if not self.null():
60            return self.node_val['next']
61
62    def previous(self):
63        if not self.null():
64            return self.node_val['previous']
65
66    def cast(self, typename):
67        if not self.null():
68            nodetype = gdb.lookup_type(typename)
69            return self.node_val.cast(nodetype)
70        return None
71
72    def to_string(self):
73        if self.null():
74            return 'NULL'
75        return 'Node:%s Next:%s Prev:%s' % (self.reference,
76                                            self.node_val['next'],
77                                            self.node_val['previous'])
78
79class control:
80    """Manage the Chain_Control."""
81
82    def __init__(self, ctrl):
83        if ctrl.type.code == gdb.TYPE_CODE_PTR:
84            self.reference = ctrl
85            self.ctrl = ctrl.dereference()
86        else:
87            self.ctrl = ctrl
88            self.reference = ctrl.address
89
90    def first(self):
91        t = node(self.ctrl['Head']['Node'])
92        return t
93
94    def tail(self):
95        return node(self.ctrl['Tail']['Node'])
96
97    def empty(self):
98        if self.tail().previous() == self.reference:
99            return True
100        return False
Note: See TracBrowser for help on using the repository browser.