@@ -61,15 +61,36 @@ def verbose_print_trace(f, trace):
61
61
print ("%s" % call ["method" ], end = "" , file = f )
62
62
print (file = f )
63
63
64
+ def get_mode (ctx ):
65
+ mode = ctx ["mode" ]
66
+ if "atomic" in ctx and int (ctx ["atomic" ]) > 0 :
67
+ mode += " atomic"
68
+ if "readonly" in ctx and int (ctx ["readonly" ]) > 0 :
69
+ mode += " readonly"
70
+ if "interruptlevel" in ctx and int (ctx ["interruptlevel" ]) > 0 :
71
+ mode += " interrupts-disabled"
72
+ return mode
73
+
64
74
class Verbose :
65
75
def __init__ (self ):
66
76
self .tid = None
67
77
self .name = None
68
78
self .start = 0
69
- self .interrupted = False
70
79
self .lastmis = {}
71
80
self .shared = {}
72
- self .failure = ""
81
+ self .step = 0
82
+ self .stack = []
83
+ self .contexts = []
84
+ self .file = None
85
+ self .stmt = None
86
+ self .expr = None
87
+
88
+ def dump_contexts (self , f , exclude ):
89
+ for ctx in self .contexts :
90
+ if ctx ["tid" ] != exclude :
91
+ mode = get_mode (ctx )
92
+ print (" T%s: pc=%s %s " % (ctx ["tid" ], ctx ["pc" ], mode ), end = "" , file = f )
93
+ verbose_print_trace (f , ctx ["trace" ])
73
94
74
95
def print_macrostep (self , f , mas ):
75
96
mis = mas ["microsteps" ]
@@ -78,38 +99,106 @@ def print_macrostep(self, f, mas):
78
99
print (file = f )
79
100
print ("================================================" , file = f )
80
101
print ("Running thread T%s: " % mas ["tid" ], end = "" , file = f )
81
- verbose_print_trace (f , mas ["context" ]["trace" ])
102
+ ctx = mas ["context" ]
103
+ trace = ctx ["trace" ]
104
+ verbose_print_trace (f , trace )
105
+ # loc = self.locations[ctx["pc"]]
106
+ # print("file: %s"%loc["file"], file=f)
107
+ # self.file = loc["file"]
108
+ if len (trace ) > 0 :
109
+ vars = trace [- 1 ]["vars" ]
110
+ if len (vars ) > 0 :
111
+ print ("method variables:" , file = f )
112
+ for k , v in vars .items ():
113
+ print (" %s: %s" % (k , verbose_string (v )), file = f )
114
+ mode = get_mode (ctx )
115
+ print ("mode: " , mode , file = f )
116
+ self .stack = [ verbose_string (v ) for v in ctx ["stack" ] ]
117
+ print ("stack:" , self .stack , file = f )
118
+ if self .contexts != []:
119
+ print ("other threads:" , file = f )
120
+ self .dump_contexts (f , self .tid )
121
+ if len (self .shared ) != 0 :
122
+ print ("shared variables:" , file = f )
123
+ for k , v in self .shared .items ():
124
+ print (" %s: %s" % (k , verbose_string (v )), file = f )
82
125
print ("================================================" , file = f )
83
- self .interrupted = False
84
126
self .lastmis = mis [0 ]
85
127
self .start = int (self .lastmis ["pc" ])
86
128
if "shared" in self .lastmis :
87
129
self .shared = self .lastmis ["shared" ]
88
130
lastpc = 0
89
131
self .steps = ""
132
+ self .contexts = mas ["contexts" ]
90
133
for step in mis :
134
+ self .step += 1
91
135
print (file = f )
136
+ print ("Step %d:" % self .step , file = f )
92
137
print (" program counter: " , step ["pc" ], file = f )
93
- print (" code: %s" % step ["code" ], file = f )
138
+ print (" hvm code: %s" % step ["code" ], file = f )
94
139
# if (int(step["npc"]) != int(step["pc"]) + 1):
95
140
# print(" pc after: ", step["npc"], file=f)
96
- if self . interrupted :
141
+ if "interrupt" in step :
97
142
print (" interrupted: jump to interrupt handler first" , file = f )
98
143
else :
99
144
print (" explanation: %s" % step ["explain" ], file = f )
145
+ loc = self .locations [step ["pc" ]]
146
+ if loc ["file" ] != self .file :
147
+ print (" file: %s" % loc ["file" ], file = f )
148
+ self .file = loc ["file" ]
149
+ stmt = loc ["stmt" ]
150
+ if stmt != self .stmt :
151
+ print (" start statement: line=%d column=%d" % (stmt [0 ], stmt [1 ]), file = f )
152
+ print (" end statement: line=%d column=%d" % (stmt [2 ], stmt [3 ]), file = f )
153
+ self .stmt = stmt
154
+ expr = tuple (int (loc [x ]) for x in [ "line" , "column" , "endline" , "endcolumn" ])
155
+ if expr != self .expr :
156
+ spaces = 0
157
+ code = loc ["code" ]
158
+ while spaces < len (code ) and code [spaces ] == ' ' :
159
+ spaces += 1
160
+ print (" source code: %s" % code [spaces :], file = f )
161
+ if stmt [0 ] == stmt [2 ] == expr [0 ] == expr [2 ]:
162
+ for _ in range (expr [1 ] + 20 - spaces ):
163
+ print (" " , end = "" , file = f )
164
+ for _ in range (expr [3 ] - expr [1 ] + 1 ):
165
+ print ("^" , end = "" , file = f )
166
+ print (file = f )
167
+ self .expr = expr
168
+ else :
169
+ print (" start expression: line=%d column=%d" % (expr [0 ], expr [1 ]), file = f )
170
+ print (" end expression: line=%d column=%d" % (expr [2 ], expr [3 ]), file = f )
100
171
# if "choose" in step:
101
172
# print(" chosen value: %s"%verbose_string(step["choose"]), file=f)
102
173
# if "print" in step:
103
174
# print(" print value: %s"%verbose_string(step["print"]), file=f)
104
175
if "shared" in step :
105
176
print (" shared variables: " , end = "" , file = f )
106
177
verbose_print_vars (f , step ["shared" ])
178
+ self .shared = step ["shared" ]
107
179
if "local" in step :
108
180
print (" method variables: " , end = "" , file = f )
109
181
verbose_print_vars (f , step ["local" ])
110
182
if "trace" in step :
111
183
print (" call trace: " , end = "" , file = f )
112
184
verbose_print_trace (f , step ["trace" ])
185
+ if "mode" in step :
186
+ print (" new mode: %s" % step ["mode" ], file = f )
187
+ if "interruptlevel" in step :
188
+ print (" interrupt level: %s" % step ["interruptlevel" ], file = f )
189
+ stack_changed = False
190
+ if "pop" in step :
191
+ pop = int (step ["pop" ])
192
+ if pop > 0 :
193
+ stack_changed = True
194
+ self .stack = self .stack [:- int (step ["pop" ])]
195
+ if "push" in step :
196
+ push = [ verbose_string (v ) for v in step ["push" ] ]
197
+ if push != []:
198
+ stack_changed = True
199
+ self .stack += push
200
+ if stack_changed :
201
+ print (" stack: [%s]" % ", " .join (self .stack ), file = f )
113
202
if "failure" in step :
114
203
print (" operation failed: %s" % step ["failure" ], file = f )
115
204
self .lastmis = step
@@ -124,7 +213,16 @@ def run(self, outputfiles, behavior):
124
213
125
214
print ("Issue:" , top ["issue" ], file = output )
126
215
assert isinstance (top ["macrosteps" ], list )
216
+ self .locations = top ["locations" ]
127
217
for mes in top ["macrosteps" ]:
128
218
self .print_macrostep (output , mes )
129
- print (self .failure , file = output )
130
- return False
219
+
220
+ print (file = output )
221
+ print ("================================================" , file = output )
222
+ print ("Final state" , file = output )
223
+ print ("================================================" , file = output )
224
+ print ("Threads:" , file = output )
225
+ self .dump_contexts (output , None )
226
+ print ("Variables:" , file = output )
227
+ for k , v in self .shared .items ():
228
+ print (" %s: %s" % (k , verbose_string (v )), file = output )
0 commit comments