]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use correct sign for DW_AT_GNU_bias
authorTom Tromey <tromey@adacore.com>
Wed, 19 Mar 2025 13:25:55 +0000 (07:25 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 24 Apr 2025 19:25:08 +0000 (13:25 -0600)
DW_AT_GNU_bias may be signed or unsigned, depending on the underlying
type.  This patch changes the DWARF reader to examine the type before
decoding the attribute.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32680

gdb/dwarf2/read.c

index e29fef0f72a819d02ac29b72c3d87823ef97f1e4..8941643a1f79e9961733191f9fe0ddba495732b6 100644 (file)
@@ -14096,8 +14096,13 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 
   LONGEST bias = 0;
   struct attribute *bias_attr = dwarf2_attr (die, DW_AT_GNU_bias, cu);
-  if (bias_attr != nullptr && bias_attr->form_is_constant ())
-    bias = bias_attr->constant_value (0);
+  if (bias_attr != nullptr)
+    {
+      if (base_type->is_unsigned ())
+       bias = (LONGEST) bias_attr->unsigned_constant ().value_or (0);
+      else
+       bias = bias_attr->signed_constant ().value_or (0);
+    }
 
   /* Normally, the DWARF producers are expected to use a signed
      constant form (Eg. DW_FORM_sdata) to express negative bounds.