CBMC
Loading...
Searching...
No Matches
report_traces.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Report Traces
4
5Author: Daniel Kroening, dkr@amazon.com
6
7\*******************************************************************/
8
11
12#include "report_traces.h"
13
14#include <util/console.h>
15#include <util/format_expr.h>
16#include <util/pointer_expr.h>
17
18#include <iomanip>
19
20std::optional<exprt> address_to_lvalue(exprt src)
21{
22 if(src.id() == ID_object_address)
23 return to_object_address_expr(src).object_expr();
24 else if(src.id() == ID_field_address)
25 {
28 if(compound_opt.has_value())
29 return member_exprt(
31 field_address_expr.component_name(),
32 field_address_expr.field_type());
33 else
34 return {};
35 }
36 else if(src.id() == ID_element_address)
37 {
40 if(array_opt.has_value())
41 return index_exprt(
42 *array_opt,
44 element_address_expr.element_type());
45 else
46 return {};
47 }
48 else if(src.id() == ID_annotated_pointer_constant)
49 {
50 const auto &pointer =
51 to_annotated_pointer_constant_expr(src).symbolic_pointer();
52 if(
53 pointer.id() == ID_address_of &&
54 to_address_of_expr(pointer).object().id() == ID_symbol)
55 return to_address_of_expr(pointer).object();
56 else
57 return {};
58 }
59 else
60 return {};
61}
62
64{
66 if(src_lvalue_opt.has_value())
68 else
69 return src;
70}
71
73 const std::vector<framet> &frames,
74 const propertyt &property,
75 bool verbose,
76 const namespacet &ns)
77{
78 irep_idt function_id, file;
79
80 for(auto &step : property.trace)
81 {
82 const auto &frame = frames[step.frame.index];
83
84 if(
85 frame.source_location.get_function() != function_id ||
86 frame.source_location.get_file() != file)
87 {
88 consolet::out() << consolet::faint << frame.source_location.get_file();
89 if(frame.source_location.get_function() != "")
90 consolet::out() << " function " << frame.source_location.get_function();
91 consolet::out() << consolet::reset << '\n';
92 file = frame.source_location.get_file();
93 function_id = frame.source_location.get_function();
94 }
95
96 consolet::out() << consolet::faint << std::setw(4)
97 << frame.source_location.get_line() << consolet::reset
98 << ' ';
99
100 if(step.updates.empty())
101 {
102 if(!verbose)
103 {
104 consolet::out() << "(no assignment)\n";
105 }
106 else
107 {
108 bool first = true;
109 for(auto &implication : frame.implications)
110 {
111 if(first)
112 first = false;
113 else
114 {
115 consolet::out() << std::setw(4) << ' ';
116 }
117 consolet::out() << "constraint: " << format(implication.as_expr())
118 << '\n';
119 }
120 }
121 }
122 else
123 {
124 bool first = true;
125 for(auto &update : step.updates)
126 {
127 if(first)
128 first = false;
129 else
130 {
131 consolet::out() << std::setw(4) << ' ';
132 }
133
134 // use an l-value expression for better readability, if possible
135 auto lhs_lvalue_opt = address_to_lvalue(update.address);
136 if(lhs_lvalue_opt.has_value())
138 else
139 consolet::out() << '[' << format(update.address) << ']';
140
141 // use address_of for better readability
142 auto value_with_address_of = use_address_of(update.value);
143
145 consolet::out() << '\n';
146 }
147 }
148 }
149}
150
152 const std::vector<framet> &frames,
153 const std::vector<propertyt> &properties,
154 bool verbose,
155 const namespacet &ns)
156{
157 for(auto &property : properties)
158 {
159 if(property.status == propertyt::REFUTED)
160 {
161 consolet::out() << '\n'
162 << "Trace for " << consolet::bold
163 << property.property_id() << consolet::reset << ':'
164 << '\n';
165
166 show_trace(frames, property, verbose, ns);
167 }
168 }
169}
Operator to return the address of an object.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
ait()
Definition ai.h:565
static std::ostream & out()
Definition console.h:55
static std::ostream & reset(std::ostream &)
Definition console.cpp:176
static std::ostream & faint(std::ostream &)
Definition console.cpp:160
static std::ostream & bold(std::ostream &)
Definition console.cpp:152
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:56
Array index operator.
Definition std_expr.h:1470
const irep_idt & id() const
Definition irep.h:388
Extract member of struct or union.
Definition std_expr.h:2972
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
Console.
static format_containert< T > format(const T &o)
Definition format.h:37
static exprt implication(exprt lhs, exprt rhs)
API to expression classes for Pointers.
const element_address_exprt & to_element_address_expr(const exprt &expr)
Cast an exprt to an element_address_exprt.
const annotated_pointer_constant_exprt & to_annotated_pointer_constant_expr(const exprt &expr)
Cast an exprt to an annotated_pointer_constant_exprt.
const object_address_exprt & to_object_address_expr(const exprt &expr)
Cast an exprt to an object_address_exprt.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
const field_address_exprt & to_field_address_expr(const exprt &expr)
Cast an exprt to an field_address_exprt.
void report_traces(const std::vector< framet > &frames, const std::vector< propertyt > &properties, bool verbose, const namespacet &ns)
void show_trace(const std::vector< framet > &frames, const propertyt &property, bool verbose, const namespacet &ns)
static exprt use_address_of(exprt src)
std::optional< exprt > address_to_lvalue(exprt src)
Report Traces.