From 21b5371ef19ebf2659dfa7061c892d1ba382a9f0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 19 Mar 2025 07:25:55 -0600 Subject: 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 --- gdb/dwarf2/read.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'gdb') diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e29fef0..8941643 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. -- cgit v1.1