@@ -384,6 +384,10 @@ exprt gdb_value_extractort::get_expr_value(
384
384
385
385
return get_pointer_value (expr, zero_expr, location);
386
386
}
387
+ else if (type.id () == ID_union_tag)
388
+ {
389
+ return get_union_value (expr, zero_expr, location);
390
+ }
387
391
UNREACHABLE;
388
392
}
389
393
@@ -420,6 +424,39 @@ exprt gdb_value_extractort::get_struct_value(
420
424
return new_expr;
421
425
}
422
426
427
+ exprt gdb_value_extractort::get_union_value (
428
+ const exprt &expr,
429
+ const exprt &zero_expr,
430
+ const source_locationt &location)
431
+ {
432
+ PRECONDITION (zero_expr.id () == ID_union);
433
+
434
+ PRECONDITION (expr.type ().id () == ID_union_tag);
435
+ PRECONDITION (expr.type () == zero_expr.type ());
436
+
437
+ exprt new_expr (zero_expr);
438
+
439
+ const union_tag_typet &union_tag_type = to_union_tag_type (expr.type ());
440
+ const union_typet union_type = ns.follow_tag (union_tag_type);
441
+
442
+ for (size_t i = 0 ; i < new_expr.operands ().size (); ++i)
443
+ {
444
+ const union_typet::componentt &component = union_type.components ()[i];
445
+
446
+ if (component.get_is_padding ())
447
+ {
448
+ continue ;
449
+ }
450
+
451
+ exprt &operand = new_expr.operands ()[i];
452
+ member_exprt member_expr (expr, component);
453
+
454
+ operand = get_expr_value (member_expr, operand, location);
455
+ }
456
+
457
+ return new_expr;
458
+ }
459
+
423
460
void gdb_value_extractort::process_outstanding_assignments ()
424
461
{
425
462
for (const auto &pair : outstanding_assignments)
0 commit comments