From: Tom Tromey Date: Wed, 19 Mar 2025 13:25:55 +0000 (-0600) Subject: Use correct sign for DW_AT_GNU_bias X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21b5371ef19ebf2659dfa7061c892d1ba382a9f0;p=thirdparty%2Fbinutils-gdb.git Use correct sign for DW_AT_GNU_bias 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 --- diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e29fef0f72a..8941643a1f7 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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.