Skip to content

Commit 51af015

Browse files
Petr Bauchpetr-bauch
authored andcommitted
Add building temporary object for pointer-to-member
Using the type from symbol table and value from gdb.
1 parent b2789ea commit 51af015

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/memory-analyzer/analyze_symbol.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,29 @@ exprt gdb_value_extractort::get_pointer_to_member_value(
247247
UNREACHABLE;
248248
}
249249

250+
const auto it = values.find(memory_location);
251+
// if the structure we are pointing to does not exists we need to build a
252+
// temporary object for it: get the type from symbol table, query gdb for
253+
// value, allocate new object for it and then store into assignments
254+
if(it == values.end())
255+
{
256+
const auto symbol_expr = struct_symbol->symbol_expr();
257+
const auto zero = zero_initializer(symbol_expr.type(), location, ns);
258+
CHECK_RETURN(zero.has_value());
259+
const auto val = get_expr_value(symbol_expr, *zero, location);
260+
261+
symbol_exprt dummy(
262+
pointer_typet(symbol_expr.type(), config.ansi_c.pointer_width));
263+
code_blockt assignments;
264+
265+
const symbol_exprt new_symbol =
266+
to_symbol_expr(allocate_objects.allocate_automatic_local_object(
267+
assignments, dummy, symbol_expr.type()));
268+
269+
add_assignment(new_symbol, val);
270+
values[memory_location] = val;
271+
}
272+
250273
const auto maybe_member_expr = get_subexpression_at_offset(
251274
struct_symbol->symbol_expr(), member_offset, expr.type().subtype(), ns);
252275
DATA_INVARIANT(

0 commit comments

Comments
 (0)