Skip to content

Commit 7a4135f

Browse files
committed
Include SSA lhs and rhs in extended JSON trace
The full SSA identifiers will permit building tools that trace assigned values back to inputs.
1 parent 0e356c2 commit 7a4135f

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

regression/cbmc/trace_options_json_extended/extended.desc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ test.c
44
^EXIT=10$
55
^SIGNAL=0$
66
rawLhs
7+
"ssaLhs": "main::argc!0@1#1",
8+
"ssaRhs": "argc'#0",
79
--

src/goto-programs/goto_trace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class goto_trace_stept
118118
bool cond_value;
119119
exprt cond_expr;
120120

121+
// for assignments
122+
exprt lhs, rhs;
123+
121124
// for assert
122125
irep_idt property_id;
123126
std::string comment;
@@ -161,6 +164,8 @@ class goto_trace_stept
161164
full_lhs.make_nil();
162165
full_lhs_value.make_nil();
163166
cond_expr.make_nil();
167+
lhs.make_nil();
168+
rhs.make_nil();
164169
}
165170
};
166171

src/goto-programs/json_goto_trace.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ Author: Daniel Kroening
1414
#include "json_goto_trace.h"
1515

1616
#include <langapi/language_util.h>
17+
1718
#include <util/arith_tools.h>
1819
#include <util/config.h>
20+
#include <util/format_expr.h>
1921
#include <util/invariant.h>
2022
#include <util/simplify_expr.h>
2123

@@ -154,6 +156,19 @@ void convert_decl(
154156
step.assignment_type == goto_trace_stept::assignment_typet::ACTUAL_PARAMETER
155157
? "actual-parameter"
156158
: "variable");
159+
160+
if(trace_options.json_full_lhs)
161+
{
162+
std::ostringstream oss;
163+
oss << format(step.lhs);
164+
json_assignment["ssaLhs"] = json_stringt(oss.str());
165+
}
166+
if(trace_options.json_full_lhs && step.rhs.is_not_nil())
167+
{
168+
std::ostringstream oss;
169+
oss << format(step.rhs);
170+
json_assignment["ssaRhs"] = json_stringt(oss.str());
171+
}
157172
}
158173

159174
/// Convert an OUTPUT goto_trace step.

src/goto-symex/build_goto_trace.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,15 @@ void build_goto_trace(
407407
goto_trace_step.cond_value =
408408
decision_procedure.get(SSA_step.cond_handle).is_true();
409409
}
410+
else if(SSA_step.is_assignment())
411+
{
412+
goto_trace_step.lhs = SSA_step.ssa_lhs;
413+
goto_trace_step.rhs = SSA_step.ssa_rhs;
414+
}
415+
else if(SSA_step.is_decl())
416+
{
417+
goto_trace_step.lhs = SSA_step.ssa_lhs;
418+
}
410419

411420
if(ssa_step_it == last_step_to_keep)
412421
return;

0 commit comments

Comments
 (0)