Skip to content

Commit cfc1954

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 03957cd commit cfc1954

File tree

5 files changed

+181
-10
lines changed

5 files changed

+181
-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 5: x=2 .*\n 6: x=3 .*$
9+
--
10+
^warning: ignoring

src/cbmc/cbmc_parse_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ 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") ||
204-
cmdline.isset("stop-on-fail"))
203+
cmdline.isset("trace") || cmdline.isset("compact-trace") ||
204+
cmdline.isset("stack-trace") || cmdline.isset("stop-on-fail"))
205205
options.set_option("trace", true);
206206

207207
if(cmdline.isset("localize-faults"))

src/goto-programs/goto_trace.cpp

Lines changed: 148 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,142 @@ 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+
{
384+
out << " " << state_location(step, ns) << '\n';
385+
}
386+
387+
out << " " << messaget::red << step.comment << messaget::reset << '\n';
388+
389+
if(step.pc->is_assert())
390+
out << " " << from_expr(ns, step.function, step.pc->guard) << '\n';
391+
392+
out << '\n';
393+
}
394+
break;
395+
396+
case goto_trace_stept::typet::ASSIGNMENT:
397+
if(
398+
step.assignment_type ==
399+
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 << 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 pretty name until first '(' to cut off
436+
// decorated identifiers, e.g., func(int, int)
437+
const auto &f_symbol = ns.lookup(step.called_function);
438+
const auto display_name = id2string(f_symbol.display_name());
439+
const std::size_t open_par_pos = display_name.find('(');
440+
out << std::string(display_name, 0, open_par_pos);
441+
}
442+
443+
out << '(';
444+
445+
{
446+
bool first = true;
447+
for(auto &arg : step.function_arguments)
448+
{
449+
if(first)
450+
first = false;
451+
else
452+
out << ", ";
453+
454+
out << from_expr(ns, step.function, arg);
455+
}
456+
}
457+
out << ")\n";
458+
break;
459+
460+
case goto_trace_stept::typet::FUNCTION_RETURN:
461+
// upwards arrow
462+
out << messaget::faint << u8"\u21b5" << messaget::reset << '\n';
463+
break;
464+
465+
case goto_trace_stept::typet::ASSUME:
466+
case goto_trace_stept::typet::LOCATION:
467+
case goto_trace_stept::typet::GOTO:
468+
case goto_trace_stept::typet::DECL:
469+
case goto_trace_stept::typet::OUTPUT:
470+
case goto_trace_stept::typet::INPUT:
471+
case goto_trace_stept::typet::SPAWN:
472+
case goto_trace_stept::typet::MEMORY_BARRIER:
473+
case goto_trace_stept::typet::ATOMIC_BEGIN:
474+
case goto_trace_stept::typet::ATOMIC_END:
475+
case goto_trace_stept::typet::DEAD:
476+
break;
477+
478+
case goto_trace_stept::typet::CONSTRAINT:
479+
case goto_trace_stept::typet::SHARED_READ:
480+
case goto_trace_stept::typet::SHARED_WRITE:
481+
default:
482+
UNREACHABLE;
483+
}
484+
}
485+
}
486+
351487
void show_full_goto_trace(
352488
messaget::mstreamt &out,
353489
const namespacet &ns,
@@ -419,13 +555,14 @@ void show_full_goto_trace(
419555
show_state_header(out, ns, step, step.step_nr, options);
420556
}
421557

422-
trace_value(
423-
out,
424-
ns,
425-
step.get_lhs_object(),
426-
step.full_lhs,
427-
step.full_lhs_value,
428-
options);
558+
out << " ";
559+
trace_value(
560+
out,
561+
ns,
562+
step.get_lhs_object(),
563+
step.full_lhs,
564+
step.full_lhs_value,
565+
options);
429566
}
430567
break;
431568

@@ -437,6 +574,7 @@ void show_full_goto_trace(
437574
show_state_header(out, ns, step, step.step_nr, options);
438575
}
439576

577+
out << " ";
440578
trace_value(
441579
out, ns, step.get_lhs_object(), step.full_lhs, step.full_lhs_value, options);
442580
break;
@@ -623,6 +761,8 @@ void show_goto_trace(
623761
{
624762
if(options.stack_trace)
625763
show_goto_stack_trace(out, ns, goto_trace);
764+
else if(options.compact_trace)
765+
show_compact_goto_trace(out, ns, goto_trace, options);
626766
else
627767
show_full_goto_trace(out, ns, goto_trace, options);
628768
}

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)