aboutsummaryrefslogtreecommitdiff
path: root/gdb/amd64-tdep.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-05-12 13:44:06 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-06-07 16:45:10 +0100
commita12a15e7c5ff9f3549dd185fa1acd5a9dddd001b (patch)
tree71278848c6d52c54c8d85799717efcb248721df9 /gdb/amd64-tdep.c
parentecac8d1c14acba1fd20b99c2481d0cab5887e3b7 (diff)
downloadfsf-binutils-gdb-a12a15e7c5ff9f3549dd185fa1acd5a9dddd001b.zip
fsf-binutils-gdb-a12a15e7c5ff9f3549dd185fa1acd5a9dddd001b.tar.gz
fsf-binutils-gdb-a12a15e7c5ff9f3549dd185fa1acd5a9dddd001b.tar.bz2
gdb: handle case where type alignment is unknown
It was spotted that if type_align returned 0 then it was possible to trigger a divide by zero exception within GDB. It turns out this will only happen in an edge case where GDB is unable to figure out the alignment of a field within a structure. The attached test generates some non-standard, probably broken, DWARF, that triggers this condition, and then fixes this issue by throwing an exception when this case occurs. gdb/ChangeLog: PR gdb/27847 * amd64-tdep.c (amd64_has_unaligned_fields): Move call to type_align, and spot case where the alignment is unknown. gdb/testsuite/ChangeLog: PR gdb/27847 * gdb.dwarf2/dw2-weird-type-len.c: New file. * gdb.dwarf2/dw2-weird-type-len.exp: New file.
Diffstat (limited to 'gdb/amd64-tdep.c')
-rw-r--r--gdb/amd64-tdep.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 91305dd..3afac3c 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -554,7 +554,6 @@ amd64_has_unaligned_fields (struct type *type)
{
struct type *subtype = check_typedef (type->field (i).type ());
int bitpos = TYPE_FIELD_BITPOS (type, i);
- int align = type_align(subtype);
/* Ignore static fields, empty fields (for example nested
empty structures), and bitfields (these are handled by
@@ -568,6 +567,10 @@ amd64_has_unaligned_fields (struct type *type)
if (bitpos % 8 != 0)
return true;
+ int align = type_align (subtype);
+ if (align == 0)
+ error (_("could not determine alignment of type"));
+
int bytepos = bitpos / 8;
if (bytepos % align != 0)
return true;