diff options
author | Tom Tromey <tromey@adacore.com> | 2025-03-19 14:04:43 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2025-04-24 13:25:08 -0600 |
commit | 0c03db90812b50d3db4a149f679a994fa9cbee87 (patch) | |
tree | b18cfc452e26fec72a032ddc6a6a8751bdcfea7f /gdb | |
parent | 6967933c5acf85a6c8d7322b1aff529ce86507e4 (diff) | |
download | binutils-0c03db90812b50d3db4a149f679a994fa9cbee87.zip binutils-0c03db90812b50d3db4a149f679a994fa9cbee87.tar.gz binutils-0c03db90812b50d3db4a149f679a994fa9cbee87.tar.bz2 |
Use correct sign in get_mpz
This changes dwarf2/read.c:get_mpz to use the correct sign-extension
function. Normally a rational constant uses signed values, but a
purely unsigned form also seems fine here. This adds a new
attribute::form_is_strictly_unsigned, which is more precise than
form_is_unsigned (which accepts a lot of forms that aren't really for
ordinary constants).
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32680
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/dwarf2/attribute.h | 9 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h index 460cbcf..31ff018 100644 --- a/gdb/dwarf2/attribute.h +++ b/gdb/dwarf2/attribute.h @@ -175,6 +175,15 @@ struct attribute false. */ bool form_is_strictly_signed () const; + /* Check if the attribute's form is an unsigned constant form. This + only returns true for forms that are strictly unsigned -- that + is, for a context-dependent form like DW_FORM_data1, this returns + false. */ + bool form_is_strictly_unsigned () const + { + return form == DW_FORM_udata; + } + /* Check if the attribute's form is a form that requires "reprocessing". */ bool form_requires_reprocessing () const; diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index aae74e9..c5e62dd 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -13216,10 +13216,10 @@ get_mpz (struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr) ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE, true); } - else if (attr->form_is_unsigned ()) + else if (attr->form_is_strictly_unsigned ()) *value = gdb_mpz (attr->as_unsigned ()); else - *value = gdb_mpz (attr->constant_value (1)); + *value = gdb_mpz (attr->signed_constant ().value_or (1)); } /* Assuming DIE is a rational DW_TAG_constant, read the DIE's |