Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | # ========== Copyright Header Begin ========================================== |
2 | # | |
3 | # OpenSPARC T2 Processor File: SS_Break.py | |
4 | # Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
5 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
6 | # | |
7 | # The above named program is free software; you can redistribute it and/or | |
8 | # modify it under the terms of the GNU General Public | |
9 | # License version 2 as published by the Free Software Foundation. | |
10 | # | |
11 | # The above named program is distributed in the hope that it will be | |
12 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public | |
17 | # License along with this work; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | # | |
20 | # ========== Copyright Header End ============================================ | |
21 | ||
22 | break_type_name = {} | |
23 | ||
24 | class BreakPoint: | |
25 | def __init__(self,strand,vonk,breakp): | |
26 | self.__strand__ = strand | |
27 | self.__vonk__ = vonk | |
28 | self.__breakp__ = breakp | |
29 | ||
30 | def is_enabled(self): | |
31 | return self.__breakp__.enabled | |
32 | def enable(self): | |
33 | self.__strand__.break_enable(self.__breakp__.id) | |
34 | def disable(self): | |
35 | self.__strand__.break_disable(self.__breakp__.id) | |
36 | ||
37 | def __repr__(self): | |
38 | type_name = break_type_name[self.__breakp__.type] | |
39 | s = '<type='+type_name | |
40 | if type_name == 'trap': | |
41 | s += '('+str(self.__breakp__.tt)+')' | |
42 | elif (type_name == 'inst_va'): | |
43 | s += '('+str(self.__breakp__.va)+')' | |
44 | elif (type_name == 'inst_pa'): | |
45 | s += '('+str(self.__breakp__.pa)+')' | |
46 | if self.is_enabled(): | |
47 | s += ',enabled>' | |
48 | else: | |
49 | s += ',disabled>' | |
50 | return s | |
51 | ||
52 | def __str__(self): | |
53 | type_name = break_type_name[self.__breakp__.type] | |
54 | s = 'brk['+str(self.__breakp__.id)+'] '+type_name+' ' | |
55 | if type_name == 'trap' or type_name == 'all_trap': | |
56 | tt = self.__breakp__.tt | |
57 | return s+'tt='+self.__vonk__.get_trap_info(tt).name+'('+hex(tt)+')' | |
58 | elif type_name == 'red_mode': | |
59 | return s+'entered' | |
60 | return s | |
61 | ||
62 | ||
63 | class BreakIter: | |
64 | def __init__(self,strand,vonk): | |
65 | self.__strand__ = strand | |
66 | self.__vonk__ = vonk | |
67 | self.__breakp__ = strand.break_points | |
68 | ||
69 | def __iter__(self): | |
70 | return self | |
71 | ||
72 | def next(self): | |
73 | if self.__breakp__: | |
74 | breakp = self.__breakp__ | |
75 | self.__breakp__ = self.__breakp__.next | |
76 | return (breakp.id, BreakPoint(self.__strand__,self.__vonk__,breakp)) | |
77 | raise StopIteration | |
78 | ||
79 | ||
80 | class BreakDict(dict): | |
81 | def __init__(self,strand,vonk): | |
82 | dict.__init__(self) | |
83 | self.__strand__ = strand | |
84 | self.__vonk__ = vonk | |
85 | self.callback = {} | |
86 | ||
87 | break_trap_info = vonk.get_trap_info | |
88 | ||
89 | if len(break_type_name) == 0: | |
90 | for on in vonk.SS_BreakPoint.__dict__: | |
91 | if on[0:3] == 'ON_': | |
92 | break_type_name[vonk.SS_BreakPoint.__dict__[on]] = on[3:].lower() | |
93 | ||
94 | def __iter__(self): | |
95 | return BreakIter(self.__strand__,self.__vonk__) | |
96 | ||
97 | def __len__(self): | |
98 | n = 0 | |
99 | for b in self.__iter__(): | |
100 | n += 1 | |
101 | return n | |
102 | ||
103 | def __repr__(self): | |
104 | l = {} | |
105 | for id,bp in self.__iter__(): | |
106 | l[id] = bp | |
107 | return str(l) | |
108 | ||
109 | def keys(self): | |
110 | l = [] | |
111 | for id,bp in self.__iter__(): | |
112 | l.append(id) | |
113 | return l | |
114 | ||
115 | def items(self): | |
116 | l = [] | |
117 | for id,bp in self.__iter__(): | |
118 | l.append(bp) | |
119 | return l | |
120 | ||
121 | def __getitem__(self,index): | |
122 | for id,bp in self.__iter__(): | |
123 | if id == index: | |
124 | return bp | |
125 | raise IndexError | |
126 | ||
127 | def __setitem__(self,index): | |
128 | raise Exception('Breakpoint dictionary is read-only') | |
129 | ||
130 | def __delitem__(self,index): | |
131 | if self.__strand__.break_delete(index) != 0: | |
132 | raise IndexError | |
133 | del self.callback[index] | |
134 | ||
135 | def on_inst_va(self,va,callback=None): | |
136 | id = self.__strand__.break_on_inst_va(va) | |
137 | self.callback[id] = callback | |
138 | return id | |
139 | ||
140 | def on_red_mode(self,callback=None): | |
141 | id = self.__strand__.break_on_red_mode() | |
142 | self.callback[id] = callback | |
143 | return id | |
144 | ||
145 | def on_trap(self,traptype,callback=None): | |
146 | id = self.__strand__.break_on_trap(traptype) | |
147 | self.callback[id] = callback | |
148 | return id | |
149 | ||
150 | def hit_id(self): | |
151 | bp = self.__strand__.break_hit | |
152 | if bp: | |
153 | return bp.id | |
154 | else: | |
155 | return None | |
156 | ||
157 | def hit_bp(self): | |
158 | bp = self.__strand__.break_hit | |
159 | if bp: | |
160 | return BreakPoint(self.__strand__,self.__vonk__,bp) | |
161 | else: | |
162 | return None | |
163 | ||
164 | def hit(self): | |
165 | bp = self.__strand__.break_hit | |
166 | if bp: | |
167 | return bp.id,BreakPoint(self.__strand__,self.__vonk__,bp) | |
168 | else: | |
169 | return None | |
170 | ||
171 | ||
172 | ||
173 |