@@ -338,28 +338,51 @@ exprt gdb_value_extractort::get_pointer_value(
338
338
339
339
if (!memory_location.is_null ())
340
340
{
341
- if (is_c_char_type (expr.type ().subtype ()))
341
+ // pointers-to-char can point to members as well, e.g. char[]
342
+ if (points_to_member (value))
342
343
{
343
- return get_char_pointer_value (expr, memory_location, location);
344
+ const auto target_expr =
345
+ get_pointer_to_member_value (expr, value, location);
346
+ CHECK_RETURN (target_expr.is_not_nil ());
347
+ const auto result_expr = address_of_exprt (target_expr);
348
+ CHECK_RETURN (result_expr.type () == zero_expr.type ());
349
+ return result_expr;
344
350
}
345
- else
351
+
352
+ // non-member: split for char/non-char
353
+ const auto target_expr =
354
+ is_c_char_type (expr.type ().subtype ())
355
+ ? get_char_pointer_value (expr, memory_location, location)
356
+ : get_non_char_pointer_value (expr, memory_location, location);
357
+
358
+ // postpone if we cannot resolve now
359
+ if (target_expr.is_nil ())
360
+ {
361
+ outstanding_assignments[expr] = memory_location;
362
+ return zero_expr;
363
+ }
364
+
365
+ // the pointee was (probably) dynamically allocated (but the allocation
366
+ // would not be visible in the snapshot) so we pretend it is statically
367
+ // allocated (we have the value) and return address to the first element
368
+ // of the array (instead of the array as char*)
369
+ if (target_expr.type ().id () == ID_array)
346
370
{
347
- const exprt target_expr =
348
- points_to_member (value)
349
- ? get_pointer_to_member_value (expr, value, location)
350
- : get_non_char_pointer_value (expr, memory_location, location);
351
-
352
- if (target_expr.id () == ID_nil)
353
- {
354
- outstanding_assignments[expr] = memory_location;
355
- }
356
- else
357
- {
358
- const auto result_expr = address_of_exprt (target_expr);
359
- CHECK_RETURN (result_expr.type () == zero_expr.type ());
360
- return result_expr;
361
- }
371
+ const auto result_indexed_expr = get_subexpression_at_offset (
372
+ target_expr, 0 , zero_expr.type ().subtype (), ns);
373
+ CHECK_RETURN (result_indexed_expr.has_value ());
374
+ const auto result_expr = address_of_exprt{*result_indexed_expr};
375
+ return result_expr;
362
376
}
377
+
378
+ // if the types match return right away
379
+ if (target_expr.type () == zero_expr.type ())
380
+ return target_expr;
381
+
382
+ // otherwise the address of target should type-match
383
+ const auto result_expr = address_of_exprt (target_expr);
384
+ CHECK_RETURN (result_expr.type () == zero_expr.type ());
385
+ return result_expr;
363
386
}
364
387
365
388
return zero_expr;
0 commit comments