CBMC
goto_symex_fault_localizer.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Fault Localization for Goto Symex
4 
5 Author: Peter Schrammel
6 
7 \*******************************************************************/
8 
11 
13 
14 #include <util/ui_message.h>
15 
17 
19 
21  const optionst &options,
22  ui_message_handlert &ui_message_handler,
23  const symex_target_equationt &equation,
25  : options(options),
26  ui_message_handler(ui_message_handler),
27  equation(equation),
28  solver(solver)
29 {
30 }
31 
33 operator()(const irep_idt &failed_property_id)
34 {
35  fault_location_infot fault_location;
36  localization_pointst localization_points;
37  const auto &failed_step =
38  collect_guards(failed_property_id, localization_points, fault_location);
39 
40  if(!localization_points.empty())
41  {
43  log.status() << "Localizing fault" << messaget::eom;
44 
45  // pick localization method
46  // if(options.get_option("localize-faults-method")=="TBD")
47  localize_linear(failed_step, localization_points);
48  }
49 
50  return fault_location;
51 }
52 
54  const irep_idt &failed_property_id,
55  localization_pointst &localization_points,
56  fault_location_infot &fault_location)
57 {
58  for(const auto &step : equation.SSA_steps)
59  {
60  if(
61  step.is_assignment() &&
62  step.assignment_type == symex_targett::assignment_typet::STATE &&
63  !step.ignore)
64  {
65  exprt l = solver.handle(step.guard_handle);
66  if(!l.is_constant())
67  {
68  auto emplace_result = fault_location.scores.emplace(step.source.pc, 0);
69  localization_points.emplace(l, emplace_result.first);
70  }
71  }
72 
73  // reached failed assertion?
74  if(step.is_assert() && step.get_property_id() == failed_property_id)
75  return step;
76  }
78 }
79 
81  const SSA_stept &failed_step,
82  const localization_pointst &localization_points,
83  const localization_points_valuet &value)
84 {
85  PRECONDITION(value.size() == localization_points.size());
86  std::vector<exprt> assumptions;
87  localization_points_valuet::const_iterator v_it = value.begin();
88  for(const auto &l : localization_points)
89  {
90  if(v_it->is_true())
91  assumptions.push_back(l.first);
92  else if(v_it->is_false())
93  assumptions.push_back(solver.handle(not_exprt(l.first)));
94  ++v_it;
95  }
96 
97  // lock the failed assertion
98  assumptions.push_back(solver.handle(not_exprt(failed_step.cond_handle)));
99 
100  solver.push(assumptions);
101 
103 }
104 
106  const localization_pointst &localization_points)
107 {
108  for(auto &l : localization_points)
109  {
110  auto &score = l.second->second;
111  if(solver.get(l.first).is_true())
112  {
113  score++;
114  }
115  else if(solver.get(l.first).is_false() && score > 0)
116  {
117  score--;
118  }
119  }
120 }
121 
123  const SSA_stept &failed_step,
124  const localization_pointst &localization_points)
125 {
126  localization_points_valuet v(localization_points.size(), tvt::unknown());
127 
128  for(std::size_t i = 0; i < v.size(); ++i)
129  {
130  v[i] = tvt(tvt::tv_enumt::TV_TRUE);
131  if(!check(failed_step, localization_points, v))
132  update_scores(localization_points);
133 
135  if(!check(failed_step, localization_points, v))
136  update_scores(localization_points);
137 
138  v[i] = tvt::unknown();
139  }
140 
141  // clear assumptions
142  solver.pop();
143 }
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
decision_proceduret::get
virtual exprt get(const exprt &expr) const =0
Return expr with variables replaced by values from satisfying assignment if available.
UNREACHABLE
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:503
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
goto_symex_fault_localizert::collect_guards
const SSA_stept & collect_guards(const irep_idt &failed_property_id, localization_pointst &localization_points, fault_location_infot &fault_location)
Collects the guards as localization_points up to failed_property_id and initializes fault_location_in...
Definition: goto_symex_fault_localizer.cpp:53
goto_symex_fault_localizert::update_scores
void update_scores(const localization_pointst &)
Definition: goto_symex_fault_localizer.cpp:105
symex_target_equation.h
SSA_stept::cond_handle
exprt cond_handle
Definition: ssa_step.h:150
ui_message_handlert
Definition: ui_message.h:21
optionst
Definition: options.h:22
SSA_stept
Single SSA step in the equation.
Definition: ssa_step.h:46
stack_decision_proceduret::push
virtual void push(const std::vector< exprt > &assumptions)=0
Pushes a new context on the stack that consists of the given (possibly empty vector of) assumptions.
messaget::status
mstreamt & status() const
Definition: message.h:414
goto_symex_fault_localizert::localization_pointst
std::map< exprt, fault_location_infot::score_mapt::iterator > localization_pointst
A localization point is a goto instruction that is potentially at fault.
Definition: goto_symex_fault_localizer.h:44
exprt
Base class for all expressions.
Definition: expr.h:55
fault_location_infot
Definition: fault_localization_provider.h:22
goto_symex_fault_localizert::localization_points_valuet
std::vector< tvt > localization_points_valuet
Definition: goto_symex_fault_localizer.h:55
messaget::eom
static eomt eom
Definition: message.h:297
exprt::is_true
bool is_true() const
Return whether the expression is a constant representing true.
Definition: expr.cpp:34
stack_decision_proceduret
Definition: stack_decision_procedure.h:57
goto_symex_fault_localizert::equation
const symex_target_equationt & equation
Definition: goto_symex_fault_localizer.h:39
exprt::is_false
bool is_false() const
Return whether the expression is a constant representing false.
Definition: expr.cpp:43
symex_targett::assignment_typet::STATE
@ STATE
decision_proceduret::resultt::D_SATISFIABLE
@ D_SATISFIABLE
stack_decision_procedure.h
tvt::tv_enumt::TV_TRUE
@ TV_TRUE
goto_symex_fault_localizert::operator()
fault_location_infot operator()(const irep_idt &failed_property_id)
Definition: goto_symex_fault_localizer.cpp:33
fault_location_infot::scores
score_mapt scores
Definition: fault_localization_provider.h:25
goto_symex_fault_localizert::check
bool check(const SSA_stept &failed_step, const localization_pointst &, const localization_points_valuet &)
Definition: goto_symex_fault_localizer.cpp:80
PRECONDITION
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
goto_symex_fault_localizert::solver
stack_decision_proceduret & solver
Definition: goto_symex_fault_localizer.h:40
goto_symex_fault_localizert::localize_linear
void localize_linear(const SSA_stept &failed_step, const localization_pointst &)
Definition: goto_symex_fault_localizer.cpp:122
tvt::unknown
static tvt unknown()
Definition: threeval.h:33
decision_proceduret::handle
virtual exprt handle(const exprt &expr)=0
Generate a handle, which is an expression that has the same value as the argument in any model that i...
tvt
Definition: threeval.h:19
symex_target_equationt
Inheriting the interface of symex_targett this class represents the SSA form of the input program as ...
Definition: symex_target_equation.h:33
symex_target_equationt::SSA_steps
SSA_stepst SSA_steps
Definition: symex_target_equation.h:250
solver
int solver(std::istream &in)
Definition: smt2_solver.cpp:407
exprt::is_constant
bool is_constant() const
Return whether the expression is a constant.
Definition: expr.cpp:27
goto_symex_fault_localizer.h
stack_decision_proceduret::pop
virtual void pop()=0
Pop whatever is on top of the stack.
tvt::tv_enumt::TV_FALSE
@ TV_FALSE
goto_symex_fault_localizert::ui_message_handler
ui_message_handlert & ui_message_handler
Definition: goto_symex_fault_localizer.h:38
goto_symex_fault_localizert::goto_symex_fault_localizert
goto_symex_fault_localizert(const optionst &options, ui_message_handlert &ui_message_handler, const symex_target_equationt &equation, stack_decision_proceduret &solver)
Definition: goto_symex_fault_localizer.cpp:20
ui_message.h
not_exprt
Boolean negation.
Definition: std_expr.h:2277