@@ -429,7 +429,11 @@ exprt gdb_value_extractort::get_expr_value(
429
429
430
430
return get_pointer_value (expr, zero_expr, location);
431
431
}
432
- UNIMPLEMENTED;
432
+ else if (type.id () == ID_union_tag)
433
+ {
434
+ return get_union_value (expr, zero_expr, location);
435
+ }
436
+ UNREACHABLE;
433
437
}
434
438
435
439
exprt gdb_value_extractort::get_struct_value (
@@ -465,6 +469,39 @@ exprt gdb_value_extractort::get_struct_value(
465
469
return new_expr;
466
470
}
467
471
472
+ exprt gdb_value_extractort::get_union_value (
473
+ const exprt &expr,
474
+ const exprt &zero_expr,
475
+ const source_locationt &location)
476
+ {
477
+ PRECONDITION (zero_expr.id () == ID_union);
478
+
479
+ PRECONDITION (expr.type ().id () == ID_union_tag);
480
+ PRECONDITION (expr.type () == zero_expr.type ());
481
+
482
+ exprt new_expr (zero_expr);
483
+
484
+ const union_tag_typet &union_tag_type = to_union_tag_type (expr.type ());
485
+ const union_typet union_type = ns.follow_tag (union_tag_type);
486
+
487
+ for (size_t i = 0 ; i < new_expr.operands ().size (); ++i)
488
+ {
489
+ const union_typet::componentt &component = union_type.components ()[i];
490
+
491
+ if (component.get_is_padding ())
492
+ {
493
+ continue ;
494
+ }
495
+
496
+ exprt &operand = new_expr.operands ()[i];
497
+ member_exprt member_expr (expr, component);
498
+
499
+ operand = get_expr_value (member_expr, operand, location);
500
+ }
501
+
502
+ return new_expr;
503
+ }
504
+
468
505
void gdb_value_extractort::process_outstanding_assignments ()
469
506
{
470
507
for (const auto &pair : outstanding_assignments)
0 commit comments