@@ -11,12 +11,21 @@ Author: Peter Schrammel
11
11
12
12
#include " shadow_memory_util.h"
13
13
14
+ #include < util/arith_tools.h>
15
+ #include < util/bitvector_expr.h>
16
+ #include < util/byte_operators.h>
14
17
#include < util/c_types.h>
18
+ #include < util/format_expr.h>
15
19
#include < util/invariant.h>
20
+ #include < util/namespace.h>
16
21
#include < util/pointer_expr.h>
17
22
#include < util/ssa_expr.h>
18
23
#include < util/std_expr.h>
19
24
25
+ #include < langapi/language_util.h> // IWYU pragma: keep
26
+
27
+ // TODO: change DEBUG_SM to DEBUG_SHADOW_MEMORY (it also appears in other files)
28
+
20
29
irep_idt extract_field_name (const exprt &string_expr)
21
30
{
22
31
if (string_expr.id () == ID_typecast)
@@ -71,3 +80,122 @@ void clean_pointer_expr(exprt &expr, const typet &type)
71
80
}
72
81
POSTCONDITION (expr.type ().id () == ID_pointer);
73
82
}
83
+
84
+ void log_get_field (
85
+ const namespacet &ns,
86
+ const messaget &log,
87
+ const irep_idt &field_name,
88
+ const exprt &expr)
89
+ {
90
+ log.conditional_output (
91
+ log.debug (), [ns, field_name, expr](messaget::mstreamt &mstream) {
92
+ mstream << " Shadow memory: get_field: " << id2string (field_name)
93
+ << " for " << format (expr) << messaget::eom;
94
+ });
95
+ }
96
+
97
+ void log_value_set (
98
+ const namespacet &ns,
99
+ const messaget &log,
100
+ const std::vector<exprt> &value_set)
101
+ {
102
+ #ifdef DEBUG_SM
103
+ log.conditional_output (
104
+ log.debug (), [ns, value_set](messaget::mstreamt &mstream) {
105
+ for (const auto &e : value_set)
106
+ {
107
+ mstream << " Shadow memory: value_set: " << format (e) << messaget::eom;
108
+ }
109
+ });
110
+ #endif
111
+ }
112
+
113
+ void log_value_set_match (
114
+ const namespacet &ns,
115
+ const messaget &log,
116
+ const shadow_memory_statet::shadowed_addresst &shadowed_address,
117
+ const exprt &matched_base_address,
118
+ const value_set_dereferencet::valuet &dereference,
119
+ const exprt &expr,
120
+ const value_set_dereferencet::valuet &shadow_dereference)
121
+ {
122
+ #ifdef DEBUG_SM
123
+ log.conditional_output (
124
+ log.debug (),
125
+ [ns,
126
+ shadowed_address,
127
+ expr,
128
+ dereference,
129
+ matched_base_address,
130
+ shadow_dereference](messaget::mstreamt &mstream) {
131
+ mstream << " Shadow memory: value_set_match: " << messaget::eom;
132
+ mstream << " Shadow memory: base: " << format (shadowed_address.address )
133
+ << " <-- " << format (matched_base_address) << messaget::eom;
134
+ mstream << " Shadow memory: cell: " << format (dereference.pointer )
135
+ << " <-- " << format (expr) << messaget::eom;
136
+ mstream << " Shadow memory: shadow_ptr: "
137
+ << format (shadow_dereference.pointer ) << messaget::eom;
138
+ mstream << " Shadow memory: shadow_val: "
139
+ << format (shadow_dereference.value ) << messaget::eom;
140
+ });
141
+ #endif
142
+ }
143
+
144
+ void log_value_set_match (
145
+ const namespacet &ns,
146
+ const messaget &log,
147
+ const exprt &address,
148
+ const exprt &expr)
149
+ {
150
+ // Leave guards rename to DEBUG_SHADOW_MEMORY
151
+ #ifdef DEBUG_SM
152
+ log.conditional_output (
153
+ log.debug (), [ns, address, expr](messaget::mstreamt &mstream) {
154
+ mstream << " Shadow memory: value_set_match: " << format (address)
155
+ << " <-- " << format (expr) << messaget::eom;
156
+ });
157
+ #endif
158
+ }
159
+
160
+ void log_try_shadow_address (
161
+ const namespacet &ns,
162
+ const messaget &log,
163
+ const shadow_memory_statet::shadowed_addresst &shadowed_address)
164
+ {
165
+ #ifdef DEBUG_SM
166
+ log.conditional_output (
167
+ log.debug (), [ns, shadowed_address](messaget::mstreamt &mstream) {
168
+ mstream << " Shadow memory: trying shadowed address: "
169
+ << format (shadowed_address.address ) << messaget::eom;
170
+ });
171
+ #endif
172
+ }
173
+
174
+ void log_cond (
175
+ const namespacet &ns,
176
+ const messaget &log,
177
+ const char *cond_text,
178
+ const exprt &cond)
179
+ {
180
+ #ifdef DEBUG_SM
181
+ log.conditional_output (
182
+ log.debug (), [ns, cond_text, cond](messaget::mstreamt &mstream) {
183
+ mstream << " Shadow memory: " << cond_text << " : " << format (cond)
184
+ << messaget::eom;
185
+ });
186
+ #endif
187
+ }
188
+
189
+ static void log_are_types_incompatible (
190
+ const namespacet &ns,
191
+ const exprt &expr,
192
+ const shadow_memory_statet::shadowed_addresst &shadowed_address,
193
+ const messaget &log)
194
+ {
195
+ #ifdef DEBUG_SM
196
+ log.debug () << " Shadow memory: incompatible types "
197
+ << from_type (ns, " " , expr.type ()) << " , "
198
+ << from_type (ns, " " , shadowed_address.address .type ())
199
+ << messaget::eom;
200
+ #endif
201
+ }
0 commit comments