Skip to content

Commit 85193a0

Browse files
authored
Merge pull request diffblue#1694 from NathanJPhillips/feature/add-raw-lhs-to-trace
Add raw irept dump of lhs to trace
2 parents d9122dc + a9c4e4f commit 85193a0

19 files changed

+141
-6
lines changed
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Test {
2+
public static void main(int x) {
3+
assert(x == 0);
4+
}
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--trace --json-ui --trace-json-extended
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
rawLhs
7+
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--trace --json-ui
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
--
7+
rawLhs
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
test.c
3+
--trace --json-ui --trace-json-extended
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
rawLhs
7+
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
test.c
3+
--trace --json-ui
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
--
7+
rawLhs
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <assert.h>
2+
3+
int main(int argc, char *argv[])
4+
{
5+
assert(argc == 0);
6+
}

src/cbmc/all_properties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
219219
if(g.second.status==goalt::statust::FAILURE)
220220
{
221221
jsont &json_trace=result["trace"];
222-
convert(bmc.ns, g.second.goto_trace, json_trace);
222+
convert(bmc.ns, g.second.goto_trace, json_trace, bmc.trace_options());
223223
}
224224
}
225225

src/cbmc/bmc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void bmct::error_trace()
9191
json_stringt(id2string(step.pc->source_location.get_comment()));
9292
json_result["status"]=json_stringt("failed");
9393
jsont &json_trace=json_result["trace"];
94-
convert(ns, goto_trace, json_trace);
94+
convert(ns, goto_trace, json_trace, trace_options());
9595
status() << json_result;
9696
}
9797
break;

src/cbmc/bmc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Author: Daniel Kroening, [email protected]
2525
#include <solvers/smt1/smt1_dec.h>
2626
#include <solvers/smt2/smt2_dec.h>
2727

28+
#include <goto-programs/goto_trace.h>
29+
2830
#include <goto-symex/symex_target_equation.h>
2931
#include <goto-programs/safety_checker.h>
3032
#include <goto-symex/memory_model.h>
@@ -98,6 +100,11 @@ class bmct:public safety_checkert
98100
virtual void show_vcc_plain(std::ostream &out);
99101
virtual void show_vcc_json(std::ostream &out);
100102

103+
trace_optionst trace_options()
104+
{
105+
return trace_optionst(options);
106+
}
107+
101108
virtual resultt all_properties(
102109
const goto_functionst &goto_functions,
103110
prop_convt &solver);

src/cbmc/bmc_cover.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ bool bmc_covert::operator()()
370370
if(bmc.options.get_bool_option("trace"))
371371
{
372372
jsont &json_trace=result["trace"];
373-
convert(bmc.ns, test.goto_trace, json_trace);
373+
convert(bmc.ns, test.goto_trace, json_trace, bmc.trace_options());
374374
}
375375
else
376376
{

src/cbmc/cbmc_parse_options.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
408408
options.set_option(
409409
"symex-coverage-report",
410410
cmdline.get_value("symex-coverage-report"));
411+
412+
PARSE_OPTIONS_GOTO_TRACE(cmdline, options);
411413
}
412414

413415
/// invoke main modules
@@ -1020,6 +1022,7 @@ void cbmc_parse_optionst::help()
10201022
" --xml-ui use XML-formatted output\n"
10211023
" --xml-interface bi-directional XML interface\n"
10221024
" --json-ui use JSON-formatted output\n"
1025+
HELP_GOTO_TRACE
10231026
" --verbosity # verbosity level\n"
10241027
"\n";
10251028
}

src/cbmc/cbmc_parse_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Author: Daniel Kroening, [email protected]
1818

1919
#include <analyses/goto_check.h>
2020

21+
#include <goto-programs/goto_trace.h>
22+
2123
#include "xml_interface.h"
2224

2325
class bmct;
@@ -65,6 +67,7 @@ class optionst;
6567
"(round-to-nearest)(round-to-plus-inf)(round-to-minus-inf)(round-to-zero)" \
6668
"(graphml-witness):" \
6769
"(localize-faults)(localize-faults-method):" \
70+
OPT_GOTO_TRACE \
6871
"(fixedbv)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
6972

7073
class cbmc_parse_optionst:

src/goto-programs/goto_trace.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,6 @@ void show_goto_trace(
395395
}
396396
}
397397
}
398+
399+
400+
const trace_optionst trace_optionst::default_options = trace_optionst();

src/goto-programs/goto_trace.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Date: July 2005
2525
#include <vector>
2626

2727
#include <util/namespace.h>
28+
#include <util/options.h>
2829
#include <util/ssa_expr.h>
2930

3031
#include <goto-programs/goto_program.h>
@@ -206,4 +207,33 @@ void trace_value(
206207
const exprt &full_lhs,
207208
const exprt &value);
208209

210+
211+
struct trace_optionst
212+
{
213+
bool json_full_lhs;
214+
215+
static const trace_optionst default_options;
216+
217+
explicit trace_optionst(const optionst &options)
218+
{
219+
json_full_lhs = options.get_bool_option("trace-json-extended");
220+
};
221+
222+
private:
223+
trace_optionst()
224+
{
225+
json_full_lhs = false;
226+
};
227+
};
228+
229+
#define OPT_GOTO_TRACE "(trace-json-extended)"
230+
231+
#define HELP_GOTO_TRACE \
232+
" --trace-json-extended add rawLhs property to trace\n"
233+
234+
#define PARSE_OPTIONS_GOTO_TRACE(cmdline, options) \
235+
if(cmdline.isset("trace-json-extended")) \
236+
options.set_option("trace-json-extended", true);
237+
238+
209239
#endif // CPROVER_GOTO_PROGRAMS_GOTO_TRACE_H

src/goto-programs/json_goto_trace.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening
2020
#include <util/simplify_expr.h>
2121

2222
#include <langapi/language_util.h>
23+
#include <util/json_irep.h>
2324

2425
/// Produce a json representation of a trace.
2526
/// \param ns: a namespace
@@ -29,7 +30,8 @@ Author: Daniel Kroening
2930
void convert(
3031
const namespacet &ns,
3132
const goto_tracet &goto_trace,
32-
jsont &dest)
33+
jsont &dest,
34+
trace_optionst trace_options)
3335
{
3436
json_arrayt &dest_array=dest.make_array();
3537

@@ -94,6 +96,41 @@ void convert(
9496
step.full_lhs.is_not_nil(),
9597
"full_lhs in assignment must not be nil");
9698
exprt simplified=simplify_expr(step.full_lhs, ns);
99+
100+
if(trace_options.json_full_lhs)
101+
{
102+
class comment_base_name_visitort : public expr_visitort
103+
{
104+
private:
105+
const namespacet &ns;
106+
107+
public:
108+
explicit comment_base_name_visitort(const namespacet &ns) : ns(ns)
109+
{
110+
}
111+
112+
void operator()(exprt &expr) override
113+
{
114+
if(expr.id() == ID_symbol)
115+
{
116+
const symbolt &symbol = ns.lookup(expr.get(ID_identifier));
117+
// Don't break sharing unless need to write to it
118+
const irept::named_subt &comments =
119+
static_cast<const exprt &>(expr).get_comments();
120+
if(comments.count(ID_C_base_name) != 0)
121+
INVARIANT(
122+
comments.at(ID_C_base_name).id() == symbol.base_name,
123+
"base_name comment does not match symbol's base_name");
124+
else
125+
expr.get_comments().emplace(
126+
ID_C_base_name, irept(symbol.base_name));
127+
}
128+
}
129+
};
130+
comment_base_name_visitort comment_base_name_visitor(ns);
131+
simplified.visit(comment_base_name_visitor);
132+
}
133+
97134
full_lhs_string=from_expr(ns, identifier, simplified);
98135

99136
const symbolt *symbol;
@@ -121,6 +158,12 @@ void convert(
121158

122159
json_assignment["value"]=full_lhs_value;
123160
json_assignment["lhs"]=json_stringt(full_lhs_string);
161+
if(trace_options.json_full_lhs)
162+
{
163+
// Not language specific, still mangled, fully-qualified name of lhs
164+
json_assignment["rawLhs"] =
165+
json_irept(true).convert_from_irep(simplified);
166+
}
124167
json_assignment["hidden"]=jsont::json_boolean(step.hidden);
125168
json_assignment["internal"]=jsont::json_boolean(step.internal);
126169
json_assignment["thread"]=json_numbert(std::to_string(step.thread_nr));

src/goto-programs/json_goto_trace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Date: November 2005
2121
void convert(
2222
const namespacet &,
2323
const goto_tracet &,
24-
jsont &);
24+
jsont &,
25+
trace_optionst trace_options = trace_optionst::default_options);
2526

2627
#endif // CPROVER_GOTO_PROGRAMS_JSON_GOTO_TRACE_H

src/jbmc/jbmc_parse_options.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ void jbmc_parse_optionst::get_command_line_options(optionst &options)
387387
options.set_option(
388388
"symex-coverage-report",
389389
cmdline.get_value("symex-coverage-report"));
390+
391+
PARSE_OPTIONS_GOTO_TRACE(cmdline, options);
390392
}
391393

392394
/// invoke main modules
@@ -950,6 +952,7 @@ void jbmc_parse_optionst::help()
950952
" --version show version and exit\n"
951953
" --xml-ui use XML-formatted output\n"
952954
" --json-ui use JSON-formatted output\n"
955+
HELP_GOTO_TRACE
953956
" --verbosity # verbosity level\n"
954957
"\n";
955958
}

src/jbmc/jbmc_parse_options.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Author: Daniel Kroening, [email protected]
1818

1919
#include <analyses/goto_check.h>
2020

21+
#include <goto-programs/goto_trace.h>
22+
2123
#include <java_bytecode/java_bytecode_language.h>
2224

2325
class bmct;
@@ -62,7 +64,8 @@ class optionst;
6264
"(graphml-witness):" \
6365
JAVA_BYTECODE_LANGUAGE_OPTIONS \
6466
"(java-unwind-enum-static)" \
65-
"(localize-faults)(localize-faults-method):"
67+
"(localize-faults)(localize-faults-method):" \
68+
OPT_GOTO_TRACE
6669

6770
class jbmc_parse_optionst:
6871
public parse_options_baset,

0 commit comments

Comments
 (0)