@@ -421,7 +421,11 @@ exprt gdb_value_extractort::get_expr_value(
421
421
422
422
return get_pointer_value (expr, zero_expr, location);
423
423
}
424
- UNIMPLEMENTED;
424
+ else if (type.id () == ID_union_tag)
425
+ {
426
+ return get_union_value (expr, zero_expr, location);
427
+ }
428
+ UNREACHABLE;
425
429
}
426
430
427
431
exprt gdb_value_extractort::get_struct_value (
@@ -457,6 +461,28 @@ exprt gdb_value_extractort::get_struct_value(
457
461
return new_expr;
458
462
}
459
463
464
+ exprt gdb_value_extractort::get_union_value (
465
+ const exprt &expr,
466
+ const exprt &zero_expr,
467
+ const source_locationt &location)
468
+ {
469
+ PRECONDITION (zero_expr.id () == ID_union);
470
+
471
+ PRECONDITION (expr.type ().id () == ID_union_tag);
472
+ PRECONDITION (expr.type () == zero_expr.type ());
473
+
474
+ exprt new_expr (zero_expr);
475
+
476
+ const union_tag_typet &union_tag_type = to_union_tag_type (expr.type ());
477
+ const union_typet &union_type = ns.follow_tag (union_tag_type);
478
+
479
+ CHECK_RETURN (new_expr.operands ().size () == 1 );
480
+ const union_typet::componentt &component = union_type.components ()[0 ];
481
+ auto &operand = new_expr.operands ()[0 ];
482
+ operand = get_expr_value (member_exprt{expr, component}, operand, location);
483
+ return new_expr;
484
+ }
485
+
460
486
void gdb_value_extractort::process_outstanding_assignments ()
461
487
{
462
488
for (const auto &pair : outstanding_assignments)
0 commit comments