Skip to content

Commit 8f4b316

Browse files
author
Enrico Steffinlongo
committed
Add shadow memory logging functions
Add a set of functions to shadow_memory_util.{h,cpp} that will be used for logging purposes by `shadow_memory::symex_get_field` and its subfunctions.
1 parent 1e8a703 commit 8f4b316

File tree

2 files changed

+177
-1
lines changed

2 files changed

+177
-1
lines changed

src/goto-symex/shadow_memory_util.cpp

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ Author: Peter Schrammel
1111

1212
#include "shadow_memory_util.h"
1313

14+
#include <util/arith_tools.h>
15+
#include <util/bitvector_expr.h>
16+
#include <util/byte_operators.h>
1417
#include <util/c_types.h>
18+
#include <util/format_expr.h>
1519
#include <util/invariant.h>
20+
#include <util/namespace.h>
1621
#include <util/pointer_expr.h>
1722
#include <util/ssa_expr.h>
1823
#include <util/std_expr.h>
1924

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+
2029
irep_idt extract_field_name(const exprt &string_expr)
2130
{
2231
if(string_expr.id() == ID_typecast)
@@ -71,3 +80,122 @@ void clean_pointer_expr(exprt &expr, const typet &type)
7180
}
7281
POSTCONDITION(expr.type().id() == ID_pointer);
7382
}
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+
}

src/goto-symex/shadow_memory_util.h

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Author: Peter Schrammel
1313
#define CPROVER_GOTO_SYMEX_SHADOW_MEMORY_UTIL_H
1414

1515
#include <util/irep.h>
16+
#include <util/message.h> // IWYU pragma: keep
17+
18+
#include <pointer-analysis/value_set_dereference.h>
19+
20+
#include "goto_symex_state.h" // IWYU pragma: keep
1621

1722
class exprt;
1823
class typet;
@@ -32,4 +37,47 @@ irep_idt extract_field_name(const exprt &string_expr);
3237
/// \param type The followed type of expr.
3338
void clean_pointer_expr(exprt &expr, const typet &type);
3439

35-
#endif // CPROVER_GOTO_SYMEX_SHADOW_MEMORY_STATE_H
40+
// TODO: doxygen
41+
void log_get_field(
42+
const namespacet &ns,
43+
const messaget &log,
44+
const irep_idt &field_name,
45+
const exprt &expr);
46+
47+
// TODO: doxygen
48+
void log_value_set(
49+
const namespacet &ns,
50+
const messaget &log,
51+
const std::vector<exprt> &value_set);
52+
53+
// TODO: doxygen
54+
void log_value_set_match(
55+
const namespacet &ns,
56+
const messaget &log,
57+
const shadow_memory_statet::shadowed_addresst &shadowed_address,
58+
const exprt &matched_base_address,
59+
const value_set_dereferencet::valuet &dereference,
60+
const exprt &expr,
61+
const value_set_dereferencet::valuet &shadow_dereference);
62+
63+
// TODO: doxygen
64+
void log_value_set_match(
65+
const namespacet &ns,
66+
const messaget &log,
67+
const exprt &address,
68+
const exprt &expr);
69+
70+
// TODO: doxygen
71+
void log_try_shadow_address(
72+
const namespacet &ns,
73+
const messaget &log,
74+
const shadow_memory_statet::shadowed_addresst &shadowed_address);
75+
76+
// TODO: doxygen
77+
void log_cond(
78+
const namespacet &ns,
79+
const messaget &log,
80+
const char *cond_text,
81+
const exprt &cond);
82+
83+
#endif // CPROVER_GOTO_SYMEX_SHADOW_MEMORY_UTIL_H

0 commit comments

Comments
 (0)