Skip to content

Commit bb1bae9

Browse files
authored
Merge pull request diffblue#2184 from tautschnig/human-readable-output
Cleanup and extend user-directed output
2 parents 1a4fc92 + 6f51513 commit bb1bae9

14 files changed

+141
-22
lines changed

src/analyses/does_remove_const.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ does_remove_constt::does_remove_constt(
3131

3232
/// A naive analysis to look for casts that remove const-ness from pointers.
3333
/// \return Returns true if the program contains a const-removing cast
34-
bool does_remove_constt::operator()() const
34+
std::pair<bool, source_locationt> does_remove_constt::operator()() const
3535
{
3636
for(const goto_programt::instructiont &instruction :
3737
goto_program.instructions)
@@ -49,16 +49,16 @@ bool does_remove_constt::operator()() const
4949
// const that the lhs
5050
if(!does_type_preserve_const_correctness(&lhs_type, &rhs_type))
5151
{
52-
return true;
52+
return {true, assign.find_source_location()};
5353
}
5454

5555
if(does_expr_lose_const(assign.rhs()))
5656
{
57-
return true;
57+
return {true, assign.rhs().find_source_location()};
5858
}
5959
}
6060

61-
return false;
61+
return {false, source_locationt()};
6262
}
6363

6464
/// Search the expression tree to look for any children that have the same base

src/analyses/does_remove_const.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class does_remove_constt
2222
{
2323
public:
2424
does_remove_constt(const goto_programt &goto_program, const namespacet &ns);
25-
bool operator()() const;
25+
std::pair<bool, source_locationt> operator()() const;
2626

2727
private:
2828
bool does_expr_lose_const(const exprt &expr) const;

src/cbmc/symex_bmc.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ void symex_bmct::symex_step(
3838

3939
if(!source_location.is_nil() && last_source_location!=source_location)
4040
{
41-
log.debug() << "BMC at file " << source_location.get_file() << " line "
42-
<< source_location.get_line() << " function "
43-
<< source_location.get_function() << log.eom;
41+
log.debug() << "BMC at " << source_location.as_string()
42+
<< " (depth " << state.depth << ')' << log.eom;
4443

4544
last_source_location=source_location;
4645
}

src/goto-programs/goto_trace.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,18 @@ std::string trace_value_binary(
122122
type.id()==ID_c_enum ||
123123
type.id()==ID_c_enum_tag)
124124
{
125-
return expr.get_string(ID_value);
125+
const std::string & str = expr.get_string(ID_value);
126+
127+
std::ostringstream oss;
128+
std::string::size_type i = 0;
129+
for(const auto c : str)
130+
{
131+
oss << c;
132+
if(++i % 8 == 0 && str.size() != i)
133+
oss << ' ';
134+
}
135+
136+
return oss.str();
126137
}
127138
else if(type.id()==ID_bool)
128139
{

src/goto-programs/json_goto_trace.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void convert_decl(
8484
if(!json_location.is_null())
8585
json_assignment["sourceLocation"] = json_location;
8686

87-
std::string value_string, binary_string, type_string, full_lhs_string;
87+
std::string value_string, type_string, full_lhs_string;
8888
json_objectt full_lhs_value;
8989

9090
DATA_INVARIANT(

src/goto-programs/remove_const_function_pointers.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool remove_const_function_pointerst::try_resolve_function_call(
160160
{
161161
if(simplified_expr.type().id()==ID_code)
162162
{
163-
resolved_functions.insert(simplified_expr);
163+
resolved_functions.insert(to_symbol_expr(simplified_expr));
164164
resolved=true;
165165
}
166166
else

src/goto-programs/remove_const_function_pointers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class typecast_exprt;
3232
class remove_const_function_pointerst:public messaget
3333
{
3434
public:
35-
typedef std::unordered_set<exprt, irep_hash> functionst;
35+
typedef std::unordered_set<symbol_exprt, irep_hash> functionst;
3636
typedef std::list<exprt> expressionst;
3737
remove_const_function_pointerst(
3838
message_handlert &message_handler,

src/goto-programs/remove_function_pointers.cpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ void remove_function_pointerst::remove_function_pointer(
285285
const exprt &pointer=function.op0();
286286
remove_const_function_pointerst::functionst functions;
287287
does_remove_constt const_removal_check(goto_program, ns);
288-
if(const_removal_check())
288+
const auto does_remove_const = const_removal_check();
289+
if(does_remove_const.first)
289290
{
290-
warning() << "Cast from const to non-const pointer found, only worst case"
291+
warning().source_location = does_remove_const.second;
292+
warning() << "cast from const to non-const pointer found, only worst case"
291293
<< " function pointer removal will be done." << eom;
292294
found_functions=false;
293295
}
@@ -341,10 +343,8 @@ void remove_function_pointerst::remove_function_pointer(
341343
if(t.first=="pthread_mutex_cleanup")
342344
continue;
343345

344-
symbol_exprt expr;
345-
expr.type()=t.second;
346-
expr.set_identifier(t.first);
347-
functions.insert(expr);
346+
symbol_exprt expr(t.first, t.second);
347+
functions.insert(expr);
348348
}
349349
}
350350

@@ -430,6 +430,25 @@ void remove_function_pointerst::remove_function_pointer(
430430
statistics().source_location=target->source_location;
431431
statistics() << "replacing function pointer by "
432432
<< functions.size() << " possible targets" << eom;
433+
434+
// list the names of functions when verbosity is at debug level
435+
conditional_output(
436+
debug(),
437+
[this, &functions](mstreamt &mstream) {
438+
mstream << "targets: ";
439+
440+
bool first = true;
441+
for(const auto &function : functions)
442+
{
443+
if(!first)
444+
mstream << ", ";
445+
446+
mstream << function.get_identifier();
447+
first = false;
448+
}
449+
450+
mstream << eom;
451+
});
433452
}
434453

435454
bool remove_function_pointerst::remove_function_pointers(

src/goto-programs/xml_goto_trace.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void convert(
7676
if(xml_location.name!="")
7777
xml_assignment.new_element().swap(xml_location);
7878

79-
std::string value_string, binary_string, type_string,
79+
std::string value_string, type_string,
8080
full_lhs_string, full_lhs_value_string;
8181

8282
if(step.lhs_object_value.is_not_nil())

src/goto-symex/symex_assign.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Author: Daniel Kroening, [email protected]
1212
#include "goto_symex.h"
1313

1414
#include <util/byte_operators.h>
15-
#include <util/cprover_prefix.h>
16-
1715
#include <util/c_types.h>
16+
#include <util/cprover_prefix.h>
17+
#include <util/pointer_offset_size.h>
1818

1919
#include "goto_symex_state.h"
2020

@@ -251,6 +251,14 @@ void goto_symext::symex_assign_symbol(
251251
if(symbol.is_auxiliary)
252252
assignment_type=symex_targett::assignment_typet::HIDDEN;
253253

254+
log.conditional_output(
255+
log.debug(),
256+
[this, &ssa_lhs](messaget::mstreamt &mstream) {
257+
mstream << "Assignment to " << ssa_lhs.get_identifier()
258+
<< " [" << pointer_offset_bits(ssa_lhs.type(), ns) << " bits]"
259+
<< messaget::eom;
260+
});
261+
254262
target.assignment(
255263
tmp_guard.as_expr(),
256264
ssa_lhs,

src/goto-symex/symex_goto.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414
#include <algorithm>
1515

1616
#include <util/invariant.h>
17+
#include <util/pointer_offset_size.h>
1718
#include <util/std_expr.h>
1819

1920
#include <analyses/dirty.h>
@@ -249,6 +250,14 @@ void goto_symext::symex_goto(statet &state)
249250

250251
guardt guard;
251252

253+
log.conditional_output(
254+
log.debug(),
255+
[this, &new_lhs](messaget::mstreamt &mstream) {
256+
mstream << "Assignment to " << new_lhs.get_identifier()
257+
<< " [" << pointer_offset_bits(new_lhs.type(), ns) << " bits]"
258+
<< messaget::eom;
259+
});
260+
252261
target.assignment(
253262
guard.as_expr(),
254263
new_lhs, new_lhs, guard_symbol_expr,
@@ -473,6 +482,14 @@ void goto_symext::phi_function(
473482
dest_state.assignment(new_lhs, rhs, ns, true, true);
474483
dest_state.record_events=record_events;
475484

485+
log.conditional_output(
486+
log.debug(),
487+
[this, &new_lhs](messaget::mstreamt &mstream) {
488+
mstream << "Assignment to " << new_lhs.get_identifier()
489+
<< " [" << pointer_offset_bits(new_lhs.type(), ns) << " bits]"
490+
<< messaget::eom;
491+
});
492+
476493
target.assignment(
477494
true_exprt(),
478495
new_lhs, new_lhs, new_lhs.get_original_expr(),

src/goto-symex/symex_target_equation.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,17 @@ void symex_target_equationt::convert_assignments(
403403
for(const auto &step : SSA_steps)
404404
{
405405
if(step.is_assignment() && !step.ignore)
406+
{
407+
decision_procedure.conditional_output(
408+
decision_procedure.debug(),
409+
[&step](messaget::mstreamt &mstream) {
410+
std::ostringstream oss;
411+
step.output(oss);
412+
mstream << oss.str() << messaget::eom;
413+
});
414+
406415
decision_procedure.set_to_true(step.cond_expr);
416+
}
407417
}
408418
}
409419

@@ -443,6 +453,14 @@ void symex_target_equationt::convert_guards(
443453
step.guard_literal=const_literal(false);
444454
else
445455
{
456+
prop_conv.conditional_output(
457+
prop_conv.debug(),
458+
[&step](messaget::mstreamt &mstream) {
459+
std::ostringstream oss;
460+
step.output(oss);
461+
mstream << oss.str() << messaget::eom;
462+
});
463+
446464
try
447465
{
448466
step.guard_literal = prop_conv.convert(step.guard);
@@ -470,6 +488,14 @@ void symex_target_equationt::convert_assumptions(
470488
step.cond_literal=const_literal(true);
471489
else
472490
{
491+
prop_conv.conditional_output(
492+
prop_conv.debug(),
493+
[&step](messaget::mstreamt &mstream) {
494+
std::ostringstream oss;
495+
step.output(oss);
496+
mstream << oss.str() << messaget::eom;
497+
});
498+
473499
try
474500
{
475501
step.cond_literal = prop_conv.convert(step.cond_expr);
@@ -498,6 +524,14 @@ void symex_target_equationt::convert_goto_instructions(
498524
step.cond_literal=const_literal(true);
499525
else
500526
{
527+
prop_conv.conditional_output(
528+
prop_conv.debug(),
529+
[&step](messaget::mstreamt &mstream) {
530+
std::ostringstream oss;
531+
step.output(oss);
532+
mstream << oss.str() << messaget::eom;
533+
});
534+
501535
try
502536
{
503537
step.cond_literal = prop_conv.convert(step.cond_expr);
@@ -525,6 +559,14 @@ void symex_target_equationt::convert_constraints(
525559
{
526560
if(!step.ignore)
527561
{
562+
decision_procedure.conditional_output(
563+
decision_procedure.debug(),
564+
[&step](messaget::mstreamt &mstream) {
565+
std::ostringstream oss;
566+
step.output(oss);
567+
mstream << oss.str() << messaget::eom;
568+
});
569+
528570
try
529571
{
530572
decision_procedure.set_to_true(step.cond_expr);

src/util/message.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,21 @@ unsigned messaget::eval_verbosity(
103103

104104
return v;
105105
}
106+
107+
/// Generate output to \p mstream using \p output_generator if the configured
108+
/// verbosity is at least as high as that of \p mstream. Use whenever
109+
/// generating output involves additional computational effort that should only
110+
/// be spent when such output will actually be displayed.
111+
/// \param mstream Output message stream
112+
/// \param output_generator Function generating output
113+
void messaget::conditional_output(
114+
mstreamt &mstream,
115+
const std::function<void(mstreamt &)> &output_generator) const
116+
{
117+
if(
118+
message_handler &&
119+
message_handler->get_verbosity() >= mstream.message_level)
120+
{
121+
output_generator(mstream);
122+
}
123+
}

src/util/message.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ Author: Daniel Kroening, [email protected]
1010
#ifndef CPROVER_UTIL_MESSAGE_H
1111
#define CPROVER_UTIL_MESSAGE_H
1212

13-
#include <string>
13+
#include <functional>
1414
#include <iosfwd>
1515
#include <sstream>
16+
#include <string>
1617

1718
#include "invariant.h"
1819
#include "json.h"
@@ -333,6 +334,10 @@ class messaget
333334
return get_mstream(M_DEBUG);
334335
}
335336

337+
void conditional_output(
338+
mstreamt &mstream,
339+
const std::function<void(mstreamt &)> &output_generator) const;
340+
336341
protected:
337342
message_handlert *message_handler;
338343
mutable mstreamt mstream;

0 commit comments

Comments
 (0)