Skip to content

Commit 999b324

Browse files
committed
Retrace improve logging
1 parent 2a33ccc commit 999b324

File tree

1 file changed

+56
-50
lines changed

1 file changed

+56
-50
lines changed

src/goto-symex/symex_goto.cpp

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -647,68 +647,78 @@ void goto_symext::symex_goto_retrace(statet &state)
647647

648648
// goto or next depends on input trace from user
649649
bool choose_goto;
650-
bool default_choice;
651-
static int retrace_index = 0;
652-
if (retrace_index < static_cast<int>(symex_config.retrace_input.size()))
650+
static size_t retrace_index = 0;
651+
if (retrace_index < symex_config.retrace_input.size())
653652
{
654653
choose_goto = symex_config.retrace_input[retrace_index] == '1';
655-
default_choice = false;
656-
retrace_index++;
657654
}
658655
else
659656
{
660657
choose_goto = false;
661-
default_choice = true;
662658
}
659+
retrace_index++;
663660

664661
// print goto choice
665-
if(true){
666-
source_locationt cur = state.source.pc->source_location();
667-
source_locationt goto_dest = goto_target->source_location();
668-
source_locationt next_dest = next_instruction->source_location();
669-
source_locationt t_dest = choose_goto ? goto_dest : next_dest;
670-
source_locationt nt_dest = choose_goto ? next_dest : goto_dest;
671-
672-
auto cur_file = cur.get_file();
673-
if(cur_file.empty()) cur_file = "<unknown>";
674-
auto t_file = t_dest.get_file();
675-
if(t_file.empty()) t_file = "<unknown>";
676-
auto nt_file = nt_dest.get_file();
677-
if(nt_file.empty()) nt_file = "<unknown>";
678-
679-
// print nothing when files are the same
680-
if(cur_file == t_file) t_file = "";
681-
if(cur_file == nt_file) nt_file = "";
682-
683-
auto cur_line = cur.get_line();
684-
if(cur_line.empty()) cur_line = "?";
685-
auto t_line = t_dest.get_line();
686-
if(t_line.empty()) t_line = "?";
687-
auto nt_line = nt_dest.get_line();
688-
if(nt_line.empty()) nt_line = "?";
689-
690-
std::string mode = default_choice ? "Retrace* " : "Retrace ";
691-
std::string desc = choose_goto ? "1/GOTO" : "0/NEXT";
692-
693-
std::string padding_1 = std::string(abs(3-cur_line.size()), ' ');
694-
std::string padding_2 = std::string(abs(3-t_line.size()), ' ');
695-
696-
log.status() << mode << desc
697-
<< " at " << cur_file << ":" << cur_line << padding_1
698-
<< " to " << t_file << ":" << t_line << padding_2
699-
<< " (not " << nt_file << ":" << nt_line << ")"
700-
<< log.eom;
701-
}
662+
log.conditional_output(
663+
log.status(),
664+
[this, &state, &goto_target, &next_instruction, choose_goto](messaget::mstreamt &mstream) {
665+
source_locationt cur = state.source.pc->source_location();
666+
source_locationt goto_dest = goto_target->source_location();
667+
source_locationt next_dest = next_instruction->source_location();
668+
source_locationt t_dest = choose_goto ? goto_dest : next_dest;
669+
source_locationt nt_dest = choose_goto ? next_dest : goto_dest;
670+
671+
auto cur_file = cur.get_file();
672+
if(cur_file.empty()) cur_file = "<unknown>";
673+
auto t_file = t_dest.get_file();
674+
if(t_file.empty()) t_file = "<unknown>";
675+
auto nt_file = nt_dest.get_file();
676+
if(nt_file.empty()) nt_file = "<unknown>";
677+
678+
// print nothing when files are the same
679+
if(cur_file == t_file) t_file = "";
680+
if(cur_file == nt_file) nt_file = "";
681+
682+
auto cur_line = cur.get_line();
683+
if(cur_line.empty()) cur_line = "?";
684+
auto t_line = t_dest.get_line();
685+
if(t_line.empty()) t_line = "?";
686+
auto nt_line = nt_dest.get_line();
687+
if(nt_line.empty()) nt_line = "?";
688+
689+
std::string head = symex_config.retrace_input;
690+
// add 0s in case input trace was shorter
691+
head.resize(retrace_index-1, '0');
692+
std::string decision = choose_goto ? "1" : "0";
693+
694+
std::string step = choose_goto ? " goto " : " next ";
695+
696+
std::string padding_1 = cur_line.size() < 3
697+
? std::string(3-cur_line.size(), ' ')
698+
: "";
699+
std::string padding_2 = t_line.size() < 3
700+
? std::string(3-t_line.size(), ' ')
701+
: "";
702+
703+
mstream << "Retrace " << head << messaget::bold << decision << messaget::reset
704+
<< " at " << cur_file << ":" << cur_line << padding_1
705+
<< step << t_file << ":" << t_line << padding_2
706+
<< " (not " << nt_file << ":" << nt_line << ")"
707+
<< messaget::eom;
708+
});
702709

703710
// warn when not following unconditional goto
704711
if(new_guard.is_true() && !choose_goto)
705712
{
706-
log.warning() << "Retrace input \033[31minconsistent\033[0m: 0/NEXT although guard is true!"
707-
<< log.eom;
713+
log.result() << "Retrace input " << messaget::red << "inconsistent" << messaget::reset
714+
<< ": 0/next although guard is true!"
715+
<< log.eom;
708716
}
709717
else if(new_guard.is_false() && choose_goto)
710718
{
711-
log.warning() << "Retrace input inconsistent: 1/GOTO although guard is false!" << log.eom;
719+
log.result() << "Retrace input " << messaget::red << "inconsistent" << messaget::reset
720+
<< ": 1/goto although guard is false!"
721+
<< log.eom;
712722
}
713723

714724
symex_targett::sourcet original_source=state.source;
@@ -773,15 +783,11 @@ void goto_symext::symex_goto_retrace(statet &state)
773783
{
774784
symex_assume_l2(state, guard_expr);
775785
state.guard.add(guard_expr);
776-
log.debug() << "Following jump target"
777-
<< log.eom;
778786
}
779787
else
780788
{
781789
symex_assume_l2(state, boolean_negate(guard_expr));
782790
state.guard.add(boolean_negate(guard_expr));
783-
log.debug() << "Following next instruction"
784-
<< log.eom;
785791
}
786792
return;
787793
}

0 commit comments

Comments
 (0)