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