[56a70ae] | 1 | # |
---|
| 2 | # RTEMS Classic API Support |
---|
| 3 | # Copyright 2010 Chris Johns (chrisj@rtems.org) |
---|
| 4 | # |
---|
| 5 | # $Id$ |
---|
| 6 | # |
---|
| 7 | |
---|
| 8 | import gdb |
---|
| 9 | import itertools |
---|
| 10 | import re |
---|
| 11 | |
---|
| 12 | import objects |
---|
| 13 | import threads |
---|
| 14 | |
---|
| 15 | class attribute: |
---|
| 16 | """The Classic API attribute.""" |
---|
| 17 | |
---|
| 18 | groups = { |
---|
| 19 | 'none' : [], |
---|
| 20 | 'all' : ['scope', |
---|
| 21 | 'priority', |
---|
| 22 | 'fpu', |
---|
| 23 | 'semaphore-type', |
---|
| 24 | 'semaphore-pri', |
---|
| 25 | 'semaphore-pri-ceiling', |
---|
| 26 | 'barrier', |
---|
| 27 | 'task'], |
---|
| 28 | 'task' : ['scope', |
---|
| 29 | 'priority', |
---|
| 30 | 'fpu', |
---|
| 31 | 'task'], |
---|
| 32 | 'semaphore' : ['scope', |
---|
| 33 | 'priority', |
---|
| 34 | 'semaphore-type', |
---|
| 35 | 'semaphore-pri', |
---|
| 36 | 'semaphore-pri-ceiling'], |
---|
| 37 | 'barrier' : ['scope', |
---|
| 38 | 'priority', |
---|
[f814c76] | 39 | 'barrier'], |
---|
| 40 | 'message_queue' : ['priority', |
---|
| 41 | 'scope'] |
---|
[56a70ae] | 42 | } |
---|
| 43 | |
---|
| 44 | masks = { |
---|
| 45 | 'scope' : 0x00000002, |
---|
| 46 | 'priority' : 0x00000004, |
---|
| 47 | 'fpu' : 0x00000001, |
---|
| 48 | 'semaphore-type' : 0x00000030, |
---|
| 49 | 'semaphore-pri' : 0x00000040, |
---|
| 50 | 'semaphore-pri-ceiling' : 0x00000080, |
---|
| 51 | 'barrier' : 0x00000010, |
---|
| 52 | 'task' : 0x00008000 |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | fields = { |
---|
| 56 | 'scope' : [(0x00000000, 'local'), |
---|
| 57 | (0x00000002, 'global')], |
---|
| 58 | 'priority' : [(0x00000000, 'fifo'), |
---|
| 59 | (0x00000004, 'pri')], |
---|
| 60 | 'fpu' : [(0x00000000, 'no-fpu'), |
---|
| 61 | (0x00000001, 'fpu')], |
---|
| 62 | 'semaphore-type' : [(0x00000000, 'count-sema'), |
---|
| 63 | (0x00000010, 'bin-sema'), |
---|
| 64 | (0x00000020, 'simple-bin-sema')], |
---|
| 65 | 'semaphore-pri' : [(0x00000000, 'no-inherit-pri'), |
---|
| 66 | (0x00000040, 'inherit-pri')], |
---|
| 67 | 'semaphore-pri-ceiling' : [(0x00000000, 'no-pri-ceiling'), |
---|
| 68 | (0x00000080, 'pri-ceiling')], |
---|
[f814c76] | 69 | 'barrier' : [(0x00000010, 'barrier-auto-release'), |
---|
[56a70ae] | 70 | (0x00000000, 'barrier-manual-release')], |
---|
| 71 | 'task' : [(0x00000000, 'app-task'), |
---|
| 72 | (0x00008000, 'sys-task')] |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | def __init__(self, attr, attrtype = 'none'): |
---|
| 76 | if attrtype not in self.groups: |
---|
| 77 | raise 'invalid attribute type' |
---|
| 78 | self.attrtype = attrtype |
---|
| 79 | self.attr = attr |
---|
| 80 | |
---|
| 81 | def to_string(self): |
---|
| 82 | s = '0x%08x,' % (self.attr) |
---|
| 83 | if self.attrtype != 'none': |
---|
| 84 | for m in self.groups[self.attrtype]: |
---|
| 85 | v = self.attr & self.masks[m] |
---|
| 86 | for f in self.fields[m]: |
---|
| 87 | if f[0] == v: |
---|
| 88 | s += f[1] + ',' |
---|
| 89 | break |
---|
| 90 | return s[:-1] |
---|
| 91 | |
---|
| 92 | def test(self, mask, value): |
---|
| 93 | if self.attrtype != 'none' and \ |
---|
| 94 | mask in self.groups[self.attrtype]: |
---|
| 95 | v = self.masks[mask] & self.attr |
---|
| 96 | for f in self.fields[mask]: |
---|
| 97 | if v == f[0] and value == f[1]: |
---|
| 98 | return True |
---|
| 99 | return False |
---|
| 100 | |
---|
| 101 | class attribute_printer: |
---|
[f814c76] | 102 | |
---|
[56a70ae] | 103 | def __init__(self, attr): |
---|
[3856406] | 104 | self.attr = attribute(attr,'all') |
---|
[56a70ae] | 105 | |
---|
| 106 | def to_string(self): |
---|
| 107 | return gdb.Value(self.attr.to_string()) |
---|
| 108 | |
---|
| 109 | class semaphore_printer: |
---|
| 110 | """Print a Semaphore_Control object. Print using the struct display hint |
---|
| 111 | and an iterator.""" |
---|
| 112 | |
---|
| 113 | class iterator: |
---|
| 114 | """Use an iterator for each field expanded from the id so GDB output |
---|
| 115 | is formatted correctly.""" |
---|
| 116 | |
---|
| 117 | def __init__(self, semaphore): |
---|
| 118 | self.semaphore = semaphore |
---|
| 119 | self.count = 0 |
---|
| 120 | |
---|
| 121 | def __iter__(self): |
---|
| 122 | return self |
---|
| 123 | |
---|
| 124 | def next(self): |
---|
| 125 | self.count += 1 |
---|
| 126 | if self.count == 1: |
---|
| 127 | return self.semaphore['Object'] |
---|
| 128 | elif self.count == 2: |
---|
[f814c76] | 129 | attr = attribute(self.semaphore['attribute_set'], |
---|
[56a70ae] | 130 | 'semaphore') |
---|
| 131 | return attr.to_string() |
---|
| 132 | elif self.count == 3: |
---|
| 133 | return self.semaphore['Core_control'] |
---|
| 134 | raise StopIteration |
---|
| 135 | |
---|
| 136 | def __init__(self, semaphore): |
---|
| 137 | self.semaphore = semaphore |
---|
| 138 | |
---|
| 139 | def to_string(self): |
---|
| 140 | return '' |
---|
| 141 | |
---|
| 142 | @staticmethod |
---|
| 143 | def key(i): |
---|
| 144 | if i == 0: |
---|
| 145 | return 'Object' |
---|
| 146 | elif i == 1: |
---|
| 147 | return 'attribute_set' |
---|
| 148 | elif i == 2: |
---|
| 149 | return 'Core_control' |
---|
| 150 | return 'bad' |
---|
| 151 | |
---|
| 152 | def children(self): |
---|
| 153 | counter = itertools.imap (self.key, itertools.count()) |
---|
| 154 | return itertools.izip (counter, self.iterator(self.semaphore)) |
---|
| 155 | |
---|
| 156 | def display_hint (self): |
---|
| 157 | return 'struct' |
---|
| 158 | |
---|
| 159 | class semaphore: |
---|
| 160 | "Print a classic semaphore." |
---|
| 161 | |
---|
| 162 | def __init__(self, id): |
---|
| 163 | self.id = id; |
---|
| 164 | self.object = objects.information.object(self.id).dereference() |
---|
| 165 | self.object_control = objects.control(self.object['Object']) |
---|
| 166 | self.attr = attribute(self.object['attribute_set'], 'semaphore') |
---|
[f814c76] | 167 | |
---|
[56a70ae] | 168 | def show(self, from_tty): |
---|
| 169 | print ' Name:', self.object_control.name() |
---|
| 170 | print ' Attr:', self.attr.to_string() |
---|
| 171 | if self.attr.test('semaphore-type', 'bin-sema') or \ |
---|
| 172 | self.attr.test('semaphore-type', 'simple-bin-sema'): |
---|
| 173 | core_mutex = self.object['Core_control']['mutex'] |
---|
| 174 | locked = core_mutex['lock'] == 0 |
---|
| 175 | if locked: |
---|
| 176 | s = 'locked' |
---|
| 177 | else: |
---|
| 178 | s = 'unlocked' |
---|
| 179 | print ' Lock:', s |
---|
| 180 | print ' Nesting:', core_mutex['nest_count'] |
---|
| 181 | print ' Blocked:', core_mutex['blocked_count'] |
---|
| 182 | print ' Holder:', |
---|
| 183 | holder = core_mutex['holder'] |
---|
| 184 | if holder and locked: |
---|
| 185 | holder = threads.control(holder.dereference()) |
---|
| 186 | print holder.brief() |
---|
| 187 | elif holder == 0 and locked: |
---|
| 188 | print 'locked but no holder' |
---|
| 189 | else: |
---|
| 190 | print 'unlocked' |
---|
| 191 | wait_queue = threads.queue(core_mutex['Wait_queue']) |
---|
| 192 | tasks = wait_queue.tasks() |
---|
| 193 | print ' Queue: len = %d, state = %s' % (len(tasks), |
---|
| 194 | wait_queue.state()) |
---|
| 195 | for t in range(0, len(tasks)): |
---|
| 196 | print ' ', tasks[t].brief(), ' (%08x)' % (tasks[t].id()) |
---|
| 197 | else: |
---|
| 198 | print 'semaphore' |
---|
| 199 | |
---|
| 200 | class task: |
---|
| 201 | "Print a classic tasks." |
---|
| 202 | |
---|
| 203 | def __init__(self, id): |
---|
| 204 | self.id = id; |
---|
| 205 | self.task = \ |
---|
| 206 | threads.control(objects.information.object(self.id).dereference()) |
---|
[f814c76] | 207 | |
---|
[56a70ae] | 208 | def show(self, from_tty): |
---|
| 209 | print ' Name:', self.task.name() |
---|
| 210 | print ' State:', self.task.current_state() |
---|
| 211 | print ' Current:', self.task.current_priority() |
---|
| 212 | print ' Real:', self.task.real_priority() |
---|
| 213 | print ' Suspends:', self.task.suspends() |
---|
| 214 | print ' Post Ext:', self.task.post_task_switch_ext() |
---|
| 215 | print ' Preempt:', self.task.preemptible() |
---|
| 216 | print ' T Budget:', self.task.cpu_time_budget() |
---|
| 217 | wait_info = self.task.wait_info() |
---|
[f814c76] | 218 | |
---|
| 219 | class message_queue: |
---|
| 220 | "Print a classic messege queue" |
---|
| 221 | |
---|
| 222 | def __init__(self,id): |
---|
| 223 | self.id = id |
---|
| 224 | self.object = objects.information.object(self.id).dereference() |
---|
| 225 | self.object_control = objects.control(self.object['Object']) |
---|
| 226 | self.attr = attribute(self.object['attribute_set'], \ |
---|
| 227 | 'message_queue') |
---|
| 228 | |
---|
| 229 | def show(self, from_tty): |
---|
| 230 | print ' Name:', self.object_control.name() |
---|
| 231 | print ' Attr:', self.attr.to_string() |
---|
[3856406] | 232 | |
---|
| 233 | |
---|