aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-08-30 15:04:03 -0600
committerTom Tromey <tom@tromey.com>2018-08-31 12:59:16 -0600
commitc8c81635739435a31860ff5f1e49743d80321f43 (patch)
tree2d78f3c2f17c11c2e8b03280ae38fb7994084a57 /gdb/dwarf2read.c
parentaef9346c25b0a0c665bce793c00797f5ab82ed37 (diff)
downloadgdb-c8c81635739435a31860ff5f1e49743d80321f43.zip
gdb-c8c81635739435a31860ff5f1e49743d80321f43.tar.gz
gdb-c8c81635739435a31860ff5f1e49743d80321f43.tar.bz2
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. gdb/ChangeLog 2018-08-31 Tom Tromey <tom@tromey.com> * dwarf2read.c (dwarf2_add_field): Set the TYPE_LENGTH of the variant part type.
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 8834d08..d66dfea 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -15169,6 +15169,18 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
fp->type = get_die_type (die, cu);
fp->artificial = 1;
fp->name = "<<variant>>";
+
+ /* 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");