Skip to content

Commit a6bd2a1

Browse files
committed
Add building temporary object for pointer-to-member
Using the type from symbol table and value from gdb.
1 parent 46cc6f3 commit a6bd2a1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/memory-analyzer/analyze_symbol.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,28 @@ exprt gdb_value_extractort::get_pointer_to_member_value(
242242
return *maybe_member_expr;
243243
}
244244

245+
const auto it = values.find(memory_location);
246+
// if the structure we are pointing to does not exists we need to build a
247+
// temporary object for it: get the type from symbol table, query gdb for
248+
// value, allocate new object for it and then store into assignments
249+
if(it == values.end())
250+
{
251+
const auto symbol_expr = struct_symbol->symbol_expr();
252+
const auto zero = zero_initializer(symbol_expr.type(), location, ns);
253+
CHECK_RETURN(zero.has_value());
254+
const auto val = get_expr_value(symbol_expr, *zero, location);
255+
256+
symbol_exprt dummy("tmp", pointer_type(symbol_expr.type()));
257+
code_blockt assignments;
258+
259+
const symbol_exprt new_symbol =
260+
to_symbol_expr(allocate_objects.allocate_automatic_local_object(
261+
assignments, dummy, symbol_expr.type()));
262+
263+
add_assignment(new_symbol, val);
264+
values[memory_location] = val;
265+
}
266+
245267
const auto maybe_member_expr = get_subexpression_at_offset(
246268
struct_symbol->symbol_expr(), member_offset, expr.type().subtype(), ns);
247269
DATA_INVARIANT(

0 commit comments

Comments
 (0)