aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-01-25 08:13:51 -0700
committerTom Tromey <tromey@adacore.com>2021-01-25 08:13:51 -0700
commita625a8c9eb4b5ae67dc3a6f34ef3c03520ab090d (patch)
treeadc8a58898928e011b02bdffccf46bbd60a44a10 /gdb/dwarf2
parent191849105b95e5ac3a3173547fd77f7b1fc3b283 (diff)
downloadfsf-binutils-gdb-a625a8c9eb4b5ae67dc3a6f34ef3c03520ab090d.zip
fsf-binutils-gdb-a625a8c9eb4b5ae67dc3a6f34ef3c03520ab090d.tar.gz
fsf-binutils-gdb-a625a8c9eb4b5ae67dc3a6f34ef3c03520ab090d.tar.bz2
Fix fixed-point regression with recent GCC
A recent version of GCC changed how fixed-point types are described. For example, a denominator in one test case now looks like: GNU_denominator (exprloc) [ 0] implicit_value: 16 byte block: 00 00 b8 9d 0d 69 55 a0 01 00 00 00 00 00 00 00 ... the difference being that this now uses exprloc and emits a DW_OP_implicit_value for the 16-byte block. (DWARF 5 still uses DW_FORM_data16.) This change was made here: https://gcc.gnu.org/pipermail/gcc-patches/2020-December/560897.html This patch updates gdb to handle this situation. Note that, before GCC 11, this test would not give the same answer. Earlier versions of GCC fell back to GNAT encodings for this case. gdb/ChangeLog 2021-01-25 Tom Tromey <tromey@adacore.com> * dwarf2/read.c (get_mpz): New function. (get_dwarf2_rational_constant): Use it. gdb/testsuite/ChangeLog 2021-01-25 Tom Tromey <tromey@adacore.com> * gdb.ada/fixed_points.exp: Add regression test. * gdb.ada/fixed_points/fixed_points.adb (FP5_Var): New variable. * gdb.ada/fixed_points/pck.adb (Delta5, FP5_Type): New.
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r--gdb/dwarf2/read.c61
1 files changed, 42 insertions, 19 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 309ff83..ae95c65 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18228,6 +18228,46 @@ read_typedef (struct die_info *die, struct dwarf2_cu *cu)
return this_type;
}
+/* Helper for get_dwarf2_rational_constant that computes the value of
+ a given gmp_mpz given an attribute. */
+
+static void
+get_mpz (struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr)
+{
+ /* GCC will sometimes emit a 16-byte constant value as a DWARF
+ location expression that pushes an implicit value. */
+ if (attr->form == DW_FORM_exprloc)
+ {
+ dwarf_block *blk = attr->as_block ();
+ if (blk->size > 0 && blk->data[0] == DW_OP_implicit_value)
+ {
+ uint64_t len;
+ const gdb_byte *ptr = safe_read_uleb128 (blk->data + 1,
+ blk->data + blk->size,
+ &len);
+ if (ptr - blk->data + len <= blk->size)
+ {
+ mpz_import (value->val, len,
+ bfd_big_endian (cu->per_objfile->objfile->obfd) ? 1 : -1,
+ 1, 0, 0, ptr);
+ return;
+ }
+ }
+
+ /* On failure set it to 1. */
+ *value = gdb_mpz (1);
+ }
+ else if (attr->form_is_block ())
+ {
+ dwarf_block *blk = attr->as_block ();
+ mpz_import (value->val, blk->size,
+ bfd_big_endian (cu->per_objfile->objfile->obfd) ? 1 : -1,
+ 1, 0, 0, blk->data);
+ }
+ else
+ *value = gdb_mpz (attr->constant_value (1));
+}
+
/* Assuming DIE is a rational DW_TAG_constant, read the DIE's
numerator and denominator into NUMERATOR and DENOMINATOR (resp).
@@ -18254,25 +18294,8 @@ get_dwarf2_rational_constant (struct die_info *die, struct dwarf2_cu *cu,
if (num_attr == nullptr || denom_attr == nullptr)
return;
- if (num_attr->form_is_block ())
- {
- dwarf_block *blk = num_attr->as_block ();
- mpz_import (numerator->val, blk->size,
- bfd_big_endian (cu->per_objfile->objfile->obfd) ? 1 : -1,
- 1, 0, 0, blk->data);
- }
- else
- *numerator = gdb_mpz (num_attr->constant_value (1));
-
- if (denom_attr->form_is_block ())
- {
- dwarf_block *blk = denom_attr->as_block ();
- mpz_import (denominator->val, blk->size,
- bfd_big_endian (cu->per_objfile->objfile->obfd) ? 1 : -1,
- 1, 0, 0, blk->data);
- }
- else
- *denominator = gdb_mpz (denom_attr->constant_value (1));
+ get_mpz (cu, numerator, num_attr);
+ get_mpz (cu, denominator, denom_attr);
}
/* Same as get_dwarf2_rational_constant, but extracting an unsigned