1 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
2 | # Copyright 2010-2015 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 Mutex Support |
---|
32 | # |
---|
33 | |
---|
34 | import gdb |
---|
35 | |
---|
36 | import objects |
---|
37 | import percpu |
---|
38 | import threads |
---|
39 | |
---|
40 | class attributes: |
---|
41 | CORE_MUTEX_NESTING_ACQUIRES = 0 |
---|
42 | CORE_MUTEX_NESTING_IS_ERROR = 1 |
---|
43 | CORE_MUTEX_NESTING_BLOCKS = 2 |
---|
44 | |
---|
45 | CORE_MUTEX_DISCIPLINES_FIFO = 0 |
---|
46 | CORE_MUTEX_DISCIPLINES_PRIORITY = 1 |
---|
47 | CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT = 2 |
---|
48 | CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING = 3 |
---|
49 | |
---|
50 | def __init__(self, attr): |
---|
51 | self.attr = attr |
---|
52 | |
---|
53 | def lock_nesting_behaviour(self): |
---|
54 | return self.attr['lock_nesting_behaviour'] |
---|
55 | |
---|
56 | def only_owner_release(self): |
---|
57 | return self.attr['only_owner_release'] |
---|
58 | |
---|
59 | def discipline(self): |
---|
60 | return self.attr['discipline'] |
---|
61 | |
---|
62 | def priority_ceiling(self): |
---|
63 | return self.attr['priority_ceiling'] |
---|
64 | |
---|
65 | def brief(self): |
---|
66 | s = '' |
---|
67 | if self.lock_nesting_behaviour() == CORE_MUTEX_NESTING_ACQUIRES: |
---|
68 | s += 'lck-nest-acquire' |
---|
69 | elif self.lock_nesting_behaviour() == CORE_MUTEX_NESTING_IS_ERROR: |
---|
70 | s += 'lck-nest-acquire' |
---|
71 | elif self.lock_nesting_behaviour() == CORE_MUTEX_NESTING_BLOCKS: |
---|
72 | s += 'lck-nest-blocks' |
---|
73 | else: |
---|
74 | s += 'lck-nest-bad' |
---|
75 | if self.only_owner_release(): |
---|
76 | s += ',owner-release' |
---|
77 | else: |
---|
78 | s += ',any-release' |
---|
79 | if self.discipline() == CORE_MUTEX_DISCIPLINES_FIFO: |
---|
80 | s += ',fifo' |
---|
81 | elif self.discipline() == CORE_MUTEX_DISCIPLINES_PRIORITY: |
---|
82 | s += ',pri' |
---|
83 | elif self.discipline() == CORE_MUTEX_DISCIPLINES_INHERIT: |
---|
84 | s += ',inherit' |
---|
85 | elif self.discipline() == CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING: |
---|
86 | s += ',pri-celling' |
---|
87 | else: |
---|
88 | s += ',dis-bad' |
---|
89 | return s |
---|
90 | |
---|
91 | class control(): |
---|
92 | ''' |
---|
93 | CORE_mutex_Control has the following fields: |
---|
94 | Wait_queue Thread_queue_Control |
---|
95 | Attributes CORE_mutex_attributes |
---|
96 | nest_count uint32_t |
---|
97 | *holder Thread_control |
---|
98 | queue CORE_mutex_order_list X |
---|
99 | |
---|
100 | where 'X' means the field is condition and may no exist. |
---|
101 | ''' |
---|
102 | |
---|
103 | def __init__(self, ctrl): |
---|
104 | if ctrl.type.code == gdb.TYPE_CODE_PTR: |
---|
105 | self.reference = ctrl |
---|
106 | self.ctrl = ctrl.dereference() |
---|
107 | else: |
---|
108 | self.ctrl = ctrl |
---|
109 | self.reference = ctrl.address |
---|
110 | self.attr = attributes(ctrl['Attributes']) |
---|
111 | |
---|
112 | def wait_queue(self): |
---|
113 | return threads.queue(self.ctrl['Wait_queue']) |
---|
114 | |
---|
115 | def attributes(self): |
---|
116 | return self.attr |
---|
117 | |
---|
118 | def nest_count(self): |
---|
119 | return self.ctrl['nest_count'] |
---|
120 | |
---|
121 | def holder(self): |
---|
122 | h = self.ctrl['holder'] |
---|
123 | if h: |
---|
124 | return threads.control(h) |
---|
125 | return None |
---|
126 | |
---|
127 | def brief(self): |
---|
128 | return "nests:%d, %s" % (self.ctrl['nest_count'], self.attr.brief()) |
---|