-
Notifications
You must be signed in to change notification settings - Fork 277
added --compact-trace option [blocks: #3459] #3458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
int x; | ||
|
||
int bar(int bar_a) | ||
{ | ||
x = 2; | ||
x++; | ||
__CPROVER_assert(0, "assertion"); | ||
} | ||
|
||
int main() | ||
{ | ||
x = 1; | ||
bar(0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE | ||
main.c | ||
--compact-trace | ||
activate-multi-line-match | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^↳ main\.c:10 main\(\)\n 12: x=1 .*$ | ||
^↳ main.c:13 bar\(0\)\n 13: bar_a=0 .*\n 5: x=2 .*\n 6: x=3 .*$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,7 +264,7 @@ void trace_value( | |
if(lhs_object.has_value()) | ||
identifier=lhs_object->get_identifier(); | ||
|
||
out << " " << from_expr(ns, identifier, full_lhs) << '='; | ||
out << from_expr(ns, identifier, full_lhs) << '='; | ||
|
||
if(value.is_nil()) | ||
out << "(assignment removed)"; | ||
|
@@ -348,6 +348,136 @@ bool is_index_member_symbol(const exprt &src) | |
return false; | ||
} | ||
|
||
/// \brief show a compact variant of the goto trace on the console | ||
/// \param out the output stream | ||
/// \param ns the namespace | ||
/// \param goto_trace the trace to be shown | ||
/// \param options any options, e.g., numerical representation | ||
void show_compact_goto_trace( | ||
messaget::mstreamt &out, | ||
const namespacet &ns, | ||
const goto_tracet &goto_trace, | ||
const trace_optionst &options) | ||
{ | ||
std::size_t function_depth = 0; | ||
|
||
for(const auto &step : goto_trace.steps) | ||
{ | ||
if(step.is_function_call()) | ||
function_depth++; | ||
else if(step.is_function_return()) | ||
function_depth--; | ||
|
||
// hide the hidden ones | ||
if(step.hidden) | ||
continue; | ||
|
||
switch(step.type) | ||
{ | ||
case goto_trace_stept::typet::ASSERT: | ||
if(!step.cond_value) | ||
{ | ||
out << '\n'; | ||
out << messaget::red << "Violated property:" << messaget::reset << '\n'; | ||
if(!step.pc->source_location.is_nil()) | ||
out << " " << state_location(step, ns) << '\n'; | ||
|
||
out << " " << messaget::red << step.comment << messaget::reset << '\n'; | ||
|
||
if(step.pc->is_assert()) | ||
out << " " << from_expr(ns, step.function, step.pc->guard) << '\n'; | ||
|
||
out << '\n'; | ||
} | ||
break; | ||
|
||
case goto_trace_stept::typet::ASSIGNMENT: | ||
if( | ||
step.assignment_type == | ||
goto_trace_stept::assignment_typet::ACTUAL_PARAMETER) | ||
{ | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Braces, please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
} | ||
|
||
out << " "; | ||
|
||
if(!step.pc->source_location.get_line().empty()) | ||
{ | ||
out << messaget::faint << step.pc->source_location.get_line() << ':' | ||
<< messaget::reset << ' '; | ||
} | ||
|
||
trace_value( | ||
out, | ||
ns, | ||
step.get_lhs_object(), | ||
step.full_lhs, | ||
step.full_lhs_value, | ||
options); | ||
break; | ||
|
||
case goto_trace_stept::typet::FUNCTION_CALL: | ||
// downwards arrow | ||
out << '\n' << messaget::faint << u8"\u21b3" << messaget::reset << ' '; | ||
if(!step.pc->source_location.get_file().empty()) | ||
{ | ||
out << messaget::faint << step.pc->source_location.get_file(); | ||
|
||
if(!step.pc->source_location.get_line().empty()) | ||
{ | ||
out << messaget::faint << ':' << step.pc->source_location.get_line(); | ||
} | ||
|
||
out << messaget::reset << ' '; | ||
} | ||
|
||
{ | ||
// show the display name | ||
const auto &f_symbol = ns.lookup(step.called_function); | ||
out << f_symbol.display_name(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually the above comment might just add confusion: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
} | ||
|
||
out << '('; | ||
|
||
{ | ||
bool first = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can already do this:
And if the above works we should likely use it in lots of places :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The range type doesn't have a difference_type, and thus, that doesn't work. Separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
for(auto &arg : step.function_arguments) | ||
{ | ||
if(first) | ||
first = false; | ||
else | ||
out << ", "; | ||
|
||
out << from_expr(ns, step.function, arg); | ||
} | ||
} | ||
out << ")\n"; | ||
break; | ||
|
||
case goto_trace_stept::typet::FUNCTION_RETURN: | ||
// upwards arrow | ||
out << messaget::faint << u8"\u21b5" << messaget::reset << '\n'; | ||
break; | ||
|
||
case goto_trace_stept::typet::ASSUME: | ||
case goto_trace_stept::typet::LOCATION: | ||
case goto_trace_stept::typet::GOTO: | ||
case goto_trace_stept::typet::DECL: | ||
case goto_trace_stept::typet::OUTPUT: | ||
case goto_trace_stept::typet::INPUT: | ||
case goto_trace_stept::typet::SPAWN: | ||
case goto_trace_stept::typet::MEMORY_BARRIER: | ||
case goto_trace_stept::typet::ATOMIC_BEGIN: | ||
case goto_trace_stept::typet::ATOMIC_END: | ||
case goto_trace_stept::typet::DEAD: | ||
break; | ||
|
||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
UNREACHABLE; | ||
} | ||
} | ||
} | ||
|
||
void show_full_goto_trace( | ||
messaget::mstreamt &out, | ||
const namespacet &ns, | ||
|
@@ -419,13 +549,14 @@ void show_full_goto_trace( | |
show_state_header(out, ns, step, step.step_nr, options); | ||
} | ||
|
||
trace_value( | ||
out, | ||
ns, | ||
step.get_lhs_object(), | ||
step.full_lhs, | ||
step.full_lhs_value, | ||
options); | ||
out << " "; | ||
trace_value( | ||
out, | ||
ns, | ||
step.get_lhs_object(), | ||
step.full_lhs, | ||
step.full_lhs_value, | ||
options); | ||
} | ||
break; | ||
|
||
|
@@ -437,6 +568,7 @@ void show_full_goto_trace( | |
show_state_header(out, ns, step, step.step_nr, options); | ||
} | ||
|
||
out << " "; | ||
trace_value( | ||
out, ns, step.get_lhs_object(), step.full_lhs, step.full_lhs_value, options); | ||
break; | ||
|
@@ -623,6 +755,8 @@ void show_goto_trace( | |
{ | ||
if(options.stack_trace) | ||
show_goto_stack_trace(out, ns, goto_trace); | ||
else if(options.compact_trace) | ||
show_compact_goto_trace(out, ns, goto_trace, options); | ||
else | ||
show_full_goto_trace(out, ns, goto_trace, options); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add braces for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok