Skip to content

Commit 36768b6

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 5f6e6ae commit 36768b6

File tree

6 files changed

+183
-9
lines changed

6 files changed

+183
-9
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
--
9+
^warning: ignoring

scripts/delete_failing_smt2_solver_tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ rm byte_update4/test.desc
121121
rm byte_update5/test.desc
122122
rm byte_update6/test.desc
123123
rm byte_update7/test.desc
124+
rm compact-trace/test.desc
124125
rm dynamic_size1/stack_object.desc
125126
rm dynamic_size1/test.desc
126127
rm equality_through_array1/test.desc

src/cbmc/cbmc_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
200200
options.set_option("stop-on-fail", true);
201201

202202
if(
203-
cmdline.isset("trace") || cmdline.isset("stack-trace") ||
203+
cmdline.isset("trace") || cmdline.isset("compact-trace") || cmdline.isset("stack-trace") ||
204204
cmdline.isset("stop-on-fail"))
205205
options.set_option("trace", true);
206206

src/goto-programs/goto_trace.cpp

Lines changed: 151 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,145 @@ 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+
// unsigned prev_step_nr=0;
363+
// bool first_step=true;
364+
std::size_t function_depth=0;
365+
366+
for(const auto &step : goto_trace.steps)
367+
{
368+
if(step.is_function_call())
369+
function_depth++;
370+
else if(step.is_function_return())
371+
function_depth--;
372+
373+
// hide the hidden ones
374+
if(step.hidden)
375+
continue;
376+
377+
switch(step.type)
378+
{
379+
case goto_trace_stept::typet::ASSERT:
380+
if(!step.cond_value)
381+
{
382+
out << '\n';
383+
out << messaget::red << "Violated property:" << messaget::reset << '\n';
384+
if(!step.pc->source_location.is_nil())
385+
{
386+
out << " " << state_location(step, ns) << '\n';
387+
}
388+
389+
out << " " << messaget::red << step.comment << messaget::reset << '\n';
390+
391+
if(step.pc->is_assert())
392+
out << " " << from_expr(ns, step.function, step.pc->guard) << '\n';
393+
394+
out << '\n';
395+
}
396+
break;
397+
398+
case goto_trace_stept::typet::ASSIGNMENT:
399+
if(step.assignment_type == goto_trace_stept::assignment_typet::ACTUAL_PARAMETER)
400+
break;
401+
402+
out << " ";
403+
404+
if(!step.pc->source_location.get_line().empty())
405+
{
406+
out << messaget::faint
407+
<< step.pc->source_location.get_line()
408+
<< ':' << messaget::reset << ' ';
409+
}
410+
411+
trace_value(
412+
out,
413+
ns,
414+
step.get_lhs_object(),
415+
step.full_lhs,
416+
step.full_lhs_value,
417+
options);
418+
break;
419+
420+
case goto_trace_stept::typet::FUNCTION_CALL:
421+
// downwards arrow
422+
out << "\n" << messaget::faint << u8"\u21b3" << messaget::reset << ' ';
423+
if(!step.pc->source_location.get_file().empty())
424+
{
425+
out << messaget::faint
426+
<< step.pc->source_location.get_file();
427+
428+
if(!step.pc->source_location.get_line().empty())
429+
{
430+
out << messaget::faint << ':'
431+
<< step.pc->source_location.get_line();
432+
}
433+
434+
out << messaget::reset << ' ';
435+
}
436+
437+
{
438+
// show pretty name until first '('
439+
const auto &f_symbol = ns.lookup(step.called_function);
440+
const auto display_name = id2string(f_symbol.display_name());
441+
const std::size_t open_par_pos = display_name.find('(');
442+
out << std::string(display_name, 0, open_par_pos);
443+
}
444+
445+
out << '(';
446+
447+
{
448+
bool first = true;
449+
for(auto &arg : step.function_arguments)
450+
{
451+
if(first)
452+
first = false;
453+
else
454+
out << ", ";
455+
456+
out << from_expr(ns, step.function, arg);
457+
}
458+
}
459+
out << ")\n";
460+
break;
461+
462+
case goto_trace_stept::typet::FUNCTION_RETURN:
463+
// upwards arrow
464+
out << messaget::faint << u8"\u21b5" << messaget::reset << '\n';
465+
break;
466+
467+
case goto_trace_stept::typet::ASSUME:
468+
case goto_trace_stept::typet::LOCATION:
469+
case goto_trace_stept::typet::GOTO:
470+
case goto_trace_stept::typet::DECL:
471+
case goto_trace_stept::typet::OUTPUT:
472+
case goto_trace_stept::typet::INPUT:
473+
case goto_trace_stept::typet::SPAWN:
474+
case goto_trace_stept::typet::MEMORY_BARRIER:
475+
case goto_trace_stept::typet::ATOMIC_BEGIN:
476+
case goto_trace_stept::typet::ATOMIC_END:
477+
case goto_trace_stept::typet::DEAD:
478+
break;
479+
480+
case goto_trace_stept::typet::CONSTRAINT:
481+
case goto_trace_stept::typet::SHARED_READ:
482+
case goto_trace_stept::typet::SHARED_WRITE:
483+
default:
484+
UNREACHABLE;
485+
}
486+
}
487+
}
488+
489+
351490
void show_full_goto_trace(
352491
messaget::mstreamt &out,
353492
const namespacet &ns,
@@ -419,13 +558,14 @@ void show_full_goto_trace(
419558
show_state_header(out, ns, step, step.step_nr, options);
420559
}
421560

422-
trace_value(
423-
out,
424-
ns,
425-
step.get_lhs_object(),
426-
step.full_lhs,
427-
step.full_lhs_value,
428-
options);
561+
out << " ";
562+
trace_value(
563+
out,
564+
ns,
565+
step.get_lhs_object(),
566+
step.full_lhs,
567+
step.full_lhs_value,
568+
options);
429569
}
430570
break;
431571

@@ -437,6 +577,7 @@ void show_full_goto_trace(
437577
show_state_header(out, ns, step, step.step_nr, options);
438578
}
439579

580+
out << " ";
440581
trace_value(
441582
out, ns, step.get_lhs_object(), step.full_lhs, step.full_lhs_value, options);
442583
break;
@@ -623,6 +764,8 @@ void show_goto_trace(
623764
{
624765
if(options.stack_trace)
625766
show_goto_stack_trace(out, ns, goto_trace);
767+
else if(options.compact_trace)
768+
show_compact_goto_trace(out, ns, goto_trace, options);
626769
else
627770
show_full_goto_trace(out, ns, goto_trace, options);
628771
}

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)