Skip to content

Commit 0af7dcc

Browse files
author
Robbert van Renesse
committed
Further improved verbose output
1 parent 0f3a86c commit 0af7dcc

File tree

1 file changed

+106
-8
lines changed

1 file changed

+106
-8
lines changed

harmony_model_checker/harmony/verbose.py

+106-8
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,36 @@ def verbose_print_trace(f, trace):
6161
print("%s"%call["method"], end="", file=f)
6262
print(file=f)
6363

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+
6474
class Verbose:
6575
def __init__(self):
6676
self.tid = None
6777
self.name = None
6878
self.start = 0
69-
self.interrupted = False
7079
self.lastmis = {}
7180
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"])
7394

7495
def print_macrostep(self, f, mas):
7596
mis = mas["microsteps"]
@@ -78,38 +99,106 @@ def print_macrostep(self, f, mas):
7899
print(file=f)
79100
print("================================================", file=f)
80101
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)
82125
print("================================================", file=f)
83-
self.interrupted = False
84126
self.lastmis = mis[0]
85127
self.start = int(self.lastmis["pc"])
86128
if "shared" in self.lastmis:
87129
self.shared = self.lastmis["shared"]
88130
lastpc = 0
89131
self.steps = ""
132+
self.contexts = mas["contexts"]
90133
for step in mis:
134+
self.step += 1
91135
print(file=f)
136+
print("Step %d:"%self.step, file=f)
92137
print(" program counter: ", step["pc"], file=f)
93-
print(" code: %s"%step["code"], file=f)
138+
print(" hvm code: %s"%step["code"], file=f)
94139
# if (int(step["npc"]) != int(step["pc"]) + 1):
95140
# print(" pc after: ", step["npc"], file=f)
96-
if self.interrupted:
141+
if "interrupt" in step:
97142
print(" interrupted: jump to interrupt handler first", file=f)
98143
else:
99144
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)
100171
# if "choose" in step:
101172
# print(" chosen value: %s"%verbose_string(step["choose"]), file=f)
102173
# if "print" in step:
103174
# print(" print value: %s"%verbose_string(step["print"]), file=f)
104175
if "shared" in step:
105176
print(" shared variables: ", end="", file=f)
106177
verbose_print_vars(f, step["shared"])
178+
self.shared = step["shared"]
107179
if "local" in step:
108180
print(" method variables: ", end="", file=f)
109181
verbose_print_vars(f, step["local"])
110182
if "trace" in step:
111183
print(" call trace: ", end="", file=f)
112184
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)
113202
if "failure" in step:
114203
print(" operation failed: %s"%step["failure"], file=f)
115204
self.lastmis = step
@@ -124,7 +213,16 @@ def run(self, outputfiles, behavior):
124213

125214
print("Issue:", top["issue"], file=output)
126215
assert isinstance(top["macrosteps"], list)
216+
self.locations = top["locations"]
127217
for mes in top["macrosteps"]:
128218
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

Comments
 (0)