Skip to content

Commit b62ffe9

Browse files
author
Daniel Kroening
committed
added --compact-trace option
This offers a denser way of viewing traces. The rationale is that traces are getting longer; furthermore, the new format makes it easier to spot function calls and the actual function parameters.
1 parent e754de7 commit b62ffe9

File tree

6 files changed

+178
-10
lines changed

6 files changed

+178
-10
lines changed

regression/cbmc/compact-trace/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int x;
2+
3+
int bar(int bar_a)
4+
{
5+
x = 2;
6+
x++;
7+
__CPROVER_assert(0, "assertion");
8+
}
9+
10+
int main()
11+
{
12+
x = 1;
13+
bar(0);
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--compact-trace
4+
activate-multi-line-match
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
^↳ main\.c:10 main\(\)\n 12: x=1 .*$
8+
^↳ main.c:13 bar\(0\)\n 13: bar_a=0 .*\n 5: x=2 .*\n 6: x=3 .*$
9+
--
10+
^warning: ignoring

scripts/delete_failing_smt2_solver_tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ rm byte_update6/test.desc
112112
rm byte_update7/test.desc
113113
rm byte_update8/test.desc
114114
rm byte_update9/test.desc
115+
rm compact-trace/test.desc
115116
rm dynamic_size1/stack_object.desc
116117
rm equality_through_array1/test.desc
117118
rm equality_through_array2/test.desc

src/cbmc/cbmc_parse_options.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,11 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
201201
options.set_option("stop-on-fail", true);
202202

203203
if(
204-
cmdline.isset("trace") || cmdline.isset("stack-trace") ||
205-
cmdline.isset("stop-on-fail"))
204+
cmdline.isset("trace") || cmdline.isset("compact-trace") ||
205+
cmdline.isset("stack-trace") || cmdline.isset("stop-on-fail"))
206+
{
206207
options.set_option("trace", true);
208+
}
207209

208210
if(cmdline.isset("localize-faults"))
209211
options.set_option("localize-faults", true);

src/goto-programs/goto_trace.cpp

Lines changed: 142 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void trace_value(
264264
if(lhs_object.has_value())
265265
identifier=lhs_object->get_identifier();
266266

267-
out << " " << from_expr(ns, identifier, full_lhs) << '=';
267+
out << from_expr(ns, identifier, full_lhs) << '=';
268268

269269
if(value.is_nil())
270270
out << "(assignment removed)";
@@ -348,6 +348,136 @@ bool is_index_member_symbol(const exprt &src)
348348
return false;
349349
}
350350

351+
/// \brief show a compact variant of the goto trace on the console
352+
/// \param out the output stream
353+
/// \param ns the namespace
354+
/// \param goto_trace the trace to be shown
355+
/// \param options any options, e.g., numerical representation
356+
void show_compact_goto_trace(
357+
messaget::mstreamt &out,
358+
const namespacet &ns,
359+
const goto_tracet &goto_trace,
360+
const trace_optionst &options)
361+
{
362+
std::size_t function_depth = 0;
363+
364+
for(const auto &step : goto_trace.steps)
365+
{
366+
if(step.is_function_call())
367+
function_depth++;
368+
else if(step.is_function_return())
369+
function_depth--;
370+
371+
// hide the hidden ones
372+
if(step.hidden)
373+
continue;
374+
375+
switch(step.type)
376+
{
377+
case goto_trace_stept::typet::ASSERT:
378+
if(!step.cond_value)
379+
{
380+
out << '\n';
381+
out << messaget::red << "Violated property:" << messaget::reset << '\n';
382+
if(!step.pc->source_location.is_nil())
383+
out << " " << state_location(step, ns) << '\n';
384+
385+
out << " " << messaget::red << step.comment << messaget::reset << '\n';
386+
387+
if(step.pc->is_assert())
388+
out << " " << from_expr(ns, step.function, step.pc->guard) << '\n';
389+
390+
out << '\n';
391+
}
392+
break;
393+
394+
case goto_trace_stept::typet::ASSIGNMENT:
395+
if(
396+
step.assignment_type ==
397+
goto_trace_stept::assignment_typet::ACTUAL_PARAMETER)
398+
{
399+
break;
400+
}
401+
402+
out << " ";
403+
404+
if(!step.pc->source_location.get_line().empty())
405+
{
406+
out << messaget::faint << step.pc->source_location.get_line() << ':'
407+
<< messaget::reset << ' ';
408+
}
409+
410+
trace_value(
411+
out,
412+
ns,
413+
step.get_lhs_object(),
414+
step.full_lhs,
415+
step.full_lhs_value,
416+
options);
417+
break;
418+
419+
case goto_trace_stept::typet::FUNCTION_CALL:
420+
// downwards arrow
421+
out << '\n' << messaget::faint << u8"\u21b3" << messaget::reset << ' ';
422+
if(!step.pc->source_location.get_file().empty())
423+
{
424+
out << messaget::faint << step.pc->source_location.get_file();
425+
426+
if(!step.pc->source_location.get_line().empty())
427+
{
428+
out << messaget::faint << ':' << step.pc->source_location.get_line();
429+
}
430+
431+
out << messaget::reset << ' ';
432+
}
433+
434+
{
435+
// show the display name
436+
const auto &f_symbol = ns.lookup(step.called_function);
437+
out << f_symbol.display_name();
438+
}
439+
440+
out << '(';
441+
442+
{
443+
bool first = true;
444+
for(auto &arg : step.function_arguments)
445+
{
446+
if(first)
447+
first = false;
448+
else
449+
out << ", ";
450+
451+
out << from_expr(ns, step.function, arg);
452+
}
453+
}
454+
out << ")\n";
455+
break;
456+
457+
case goto_trace_stept::typet::FUNCTION_RETURN:
458+
// upwards arrow
459+
out << messaget::faint << u8"\u21b5" << messaget::reset << '\n';
460+
break;
461+
462+
case goto_trace_stept::typet::ASSUME:
463+
case goto_trace_stept::typet::LOCATION:
464+
case goto_trace_stept::typet::GOTO:
465+
case goto_trace_stept::typet::DECL:
466+
case goto_trace_stept::typet::OUTPUT:
467+
case goto_trace_stept::typet::INPUT:
468+
case goto_trace_stept::typet::SPAWN:
469+
case goto_trace_stept::typet::MEMORY_BARRIER:
470+
case goto_trace_stept::typet::ATOMIC_BEGIN:
471+
case goto_trace_stept::typet::ATOMIC_END:
472+
case goto_trace_stept::typet::DEAD:
473+
break;
474+
475+
default:
476+
UNREACHABLE;
477+
}
478+
}
479+
}
480+
351481
void show_full_goto_trace(
352482
messaget::mstreamt &out,
353483
const namespacet &ns,
@@ -419,13 +549,14 @@ void show_full_goto_trace(
419549
show_state_header(out, ns, step, step.step_nr, options);
420550
}
421551

422-
trace_value(
423-
out,
424-
ns,
425-
step.get_lhs_object(),
426-
step.full_lhs,
427-
step.full_lhs_value,
428-
options);
552+
out << " ";
553+
trace_value(
554+
out,
555+
ns,
556+
step.get_lhs_object(),
557+
step.full_lhs,
558+
step.full_lhs_value,
559+
options);
429560
}
430561
break;
431562

@@ -437,6 +568,7 @@ void show_full_goto_trace(
437568
show_state_header(out, ns, step, step.step_nr, options);
438569
}
439570

571+
out << " ";
440572
trace_value(
441573
out, ns, step.get_lhs_object(), step.full_lhs, step.full_lhs_value, options);
442574
break;
@@ -623,6 +755,8 @@ void show_goto_trace(
623755
{
624756
if(options.stack_trace)
625757
show_goto_stack_trace(out, ns, goto_trace);
758+
else if(options.compact_trace)
759+
show_compact_goto_trace(out, ns, goto_trace, options);
626760
else
627761
show_full_goto_trace(out, ns, goto_trace, options);
628762
}

src/goto-programs/goto_trace.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct trace_optionst
200200
bool base_prefix;
201201
bool show_function_calls;
202202
bool show_code;
203+
bool compact_trace;
203204
bool stack_trace;
204205

205206
static const trace_optionst default_options;
@@ -211,6 +212,7 @@ struct trace_optionst
211212
base_prefix = hex_representation;
212213
show_function_calls = options.get_bool_option("trace-show-function-calls");
213214
show_code = options.get_bool_option("trace-show-code");
215+
compact_trace = options.get_bool_option("compact-trace");
214216
stack_trace = options.get_bool_option("stack-trace");
215217
};
216218

@@ -222,6 +224,7 @@ struct trace_optionst
222224
base_prefix = false;
223225
show_function_calls = false;
224226
show_code = false;
227+
compact_trace = false;
225228
stack_trace = false;
226229
};
227230
};
@@ -250,13 +253,15 @@ void trace_value(
250253
"(trace-show-function-calls)" \
251254
"(trace-show-code)" \
252255
"(trace-hex)" \
256+
"(compact-trace)" \
253257
"(stack-trace)"
254258

255259
#define HELP_GOTO_TRACE \
256260
" --trace-json-extended add rawLhs property to trace\n" \
257261
" --trace-show-function-calls show function calls in plain trace\n" \
258262
" --trace-show-code show original code in plain trace\n" \
259263
" --trace-hex represent plain trace values in hex\n" \
264+
" --compact-trace give a compact trace\n" \
260265
" --stack-trace give a stack trace only\n"
261266

262267
#define PARSE_OPTIONS_GOTO_TRACE(cmdline, options) \
@@ -268,6 +273,8 @@ void trace_value(
268273
options.set_option("trace-show-code", true); \
269274
if(cmdline.isset("trace-hex")) \
270275
options.set_option("trace-hex", true); \
276+
if(cmdline.isset("compact-trace")) \
277+
options.set_option("compact-trace", true); \
271278
if(cmdline.isset("stack-trace")) \
272279
options.set_option("stack-trace", true);
273280

0 commit comments

Comments
 (0)