diff options
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/gdbtypes.c | 14 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 12 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/vla-datatypes.c | 28 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/vla-datatypes.exp | 6 |
5 files changed, 60 insertions, 6 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e009aab..e006943 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-06-11 Keith Seitz <keiths@redhat.com> + + PR gdb/21356 + * gdbtypes.c (resolve_dynamic_union, resolve_dynamic_struct): + Resolve typedefs for type length calculations. + 2020-06-10 Tom de Vries <tdevries@suse.de> PR ada/24713 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index b5a1310..cdf88a4 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2264,8 +2264,10 @@ resolve_dynamic_union (struct type *type, t = resolve_dynamic_type_internal (resolved_type->field (i).type (), addr_stack, 0); resolved_type->field (i).set_type (t); - if (TYPE_LENGTH (t) > max_len) - max_len = TYPE_LENGTH (t); + + struct type *real_type = check_typedef (t); + if (TYPE_LENGTH (real_type) > max_len) + max_len = TYPE_LENGTH (real_type); } TYPE_LENGTH (resolved_type) = max_len; @@ -2521,8 +2523,12 @@ resolve_dynamic_struct (struct type *type, if (TYPE_FIELD_BITSIZE (resolved_type, i) != 0) new_bit_length += TYPE_FIELD_BITSIZE (resolved_type, i); else - new_bit_length += (TYPE_LENGTH (resolved_type->field (i).type ()) - * TARGET_CHAR_BIT); + { + struct type *real_type + = check_typedef (resolved_type->field (i).type ()); + + new_bit_length += (TYPE_LENGTH (real_type) * TARGET_CHAR_BIT); + } /* Normally, we would use the position and size of the last field to determine the size of the enclosing structure. But GCC seems diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e0fece6..7ff7de2 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2020-06-11 Keith Seitz <keiths@redhat.com> + + PR gdb/21356 + * gdb.base/vla-datatypes.c (vla_factory): Add typedef for struct + vla_struct. + Add new struct vla_typedef and union vla_typedef_union and + corresponding instantiation objects. + Initialize new objects. + * gdb.base/vla-datatypes.exp: Add tests for vla_typedef_struct_object + and vla_typedef_union_object. + Fixup type for vla_struct_object. + 2020-06-11 Tom de Vries <tdevries@suse.de> * lib/gdb.exp (with_override): New proc, factored out of ... diff --git a/gdb/testsuite/gdb.base/vla-datatypes.c b/gdb/testsuite/gdb.base/vla-datatypes.c index ecdcf43..682319f 100644 --- a/gdb/testsuite/gdb.base/vla-datatypes.c +++ b/gdb/testsuite/gdb.base/vla-datatypes.c @@ -50,7 +50,10 @@ vla_factory (int n) { int something; int vla_field[n]; - } vla_struct_object; + }; + /* Define a typedef for a VLA structure. */ + typedef struct vla_struct vla_struct_typedef; + vla_struct_typedef vla_struct_object; struct inner_vla_struct { @@ -59,14 +62,33 @@ vla_factory (int n) int after; } inner_vla_struct_object; + /* Define a structure which uses a typedef for the VLA field + to make sure that GDB creates the proper type for this field, + preventing a possible assertion failure (see gdb/21356). */ + struct vla_struct_typedef_struct_member + { + int something; + vla_struct_typedef vla_object; + } vla_struct_typedef_struct_member_object; + union vla_union { int vla_field[n]; } vla_union_object; + /* Like vla_struct_typedef_struct_member but a union type. */ + union vla_struct_typedef_union_member + { + int something; + vla_struct_typedef vla_object; + } vla_struct_typedef_union_member_object; + vla_struct_object.something = n; inner_vla_struct_object.something = n; inner_vla_struct_object.after = n; + vla_struct_typedef_struct_member_object.something = n * 2; + vla_struct_typedef_struct_member_object.vla_object.something = n * 3; + vla_struct_typedef_union_member_object.vla_object.something = n + 1; for (i = 0; i < n; i++) { int_vla[i] = i*2; @@ -85,6 +107,10 @@ vla_factory (int n) vla_struct_object.vla_field[i] = i*2; vla_union_object.vla_field[i] = i*2; inner_vla_struct_object.vla_field[i] = i*2; + vla_struct_typedef_struct_member_object.vla_object.vla_field[i] + = i * 3; + vla_struct_typedef_union_member_object.vla_object.vla_field[i] + = i * 3 - 1; } size_t int_size = sizeof(int_vla); /* vlas_filled */ diff --git a/gdb/testsuite/gdb.base/vla-datatypes.exp b/gdb/testsuite/gdb.base/vla-datatypes.exp index fbc2c97..e8d8457 100644 --- a/gdb/testsuite/gdb.base/vla-datatypes.exp +++ b/gdb/testsuite/gdb.base/vla-datatypes.exp @@ -45,6 +45,10 @@ gdb_test "print vla_struct_object" \ "\\\{something = 5, vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}" gdb_test "print vla_union_object" \ "\\\{vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}" +gdb_test "print vla_struct_typedef_struct_member_object" \ + "\\\{something = 10, vla_object = \\\{something = 15, vla_field = \\\{0, 3, 6, 9, 12\\\}\\\}\\\}" +gdb_test "print vla_struct_typedef_union_member_object" \ + "\\\{something = 6, vla_object = \\\{something = 6, vla_field = \\\{-1, 2, 5, 8, 11\\\}\\\}\\\}" # Check whatis of VLA's. gdb_test "whatis int_vla" "type = int \\\[5\\\]" @@ -61,7 +65,7 @@ gdb_test "whatis unsigned_short_vla" \ gdb_test "whatis unsigned_char_vla" "type = unsigned char \\\[5\\\]" gdb_test "whatis foo_vla" "type = struct foo \\\[5\\\]" gdb_test "whatis bar_vla" "type = BAR \\\[5\\\]" -gdb_test "whatis vla_struct_object" "type = struct vla_struct" +gdb_test "whatis vla_struct_object" "type = vla_struct_typedef" gdb_test "whatis vla_union_object" "type = union vla_union" # Check ptype of VLA's. |