From c07c917f276d6e055a4e6ba5be5d6b9c4d355de7 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 30 Aug 2018 15:04:03 -0600 Subject: [PATCH] Set TYPE_LENGTH on a variant part gdb represents a DW_TAG_variant_part as a union. While normally DWARF would not set the size of a DW_TAG_variant_part, gdb's representation requires the TYPE_LENGTH to be set. This patch arranges to set the TYPE_LENGTH of a variant part if it has not already been set. This fixes some Rust regressions when testing against a version of rustc that emits DW_TAG_variant_part. 2018-08-31 Tom Tromey * dwarf2read.c (dwarf2_add_field): Set the TYPE_LENGTH of the variant part type. --- gdb/ChangeLog | 5 +++++ gdb/dwarf2read.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 32c23b7..cf3171d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-08-31 Tom Tromey + + * dwarf2read.c (dwarf2_add_field): Set the TYPE_LENGTH of the + variant part type. + 2018-08-28 Alan Hayward * aarch64-linux-tdep.c (aarch64_linux_supply_sve_regset): New function. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 56113c1..b0c7d98 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -15060,6 +15060,18 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die, fp->type = get_die_type (die, cu); fp->artificial = 1; fp->name = "<>"; + + /* Normally a DW_TAG_variant_part won't have a size, but our + representation requires one, so set it to the maximum of the + child sizes. */ + if (TYPE_LENGTH (fp->type) == 0) + { + unsigned max = 0; + for (int i = 0; i < TYPE_NFIELDS (fp->type); ++i) + if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i)) > max) + max = TYPE_LENGTH (TYPE_FIELD_TYPE (fp->type, i)); + TYPE_LENGTH (fp->type) = max; + } } else gdb_assert_not_reached ("missing case in dwarf2_add_field"); -- 2.7.4