Skip to content

Commit 0c03db9

Browse files
committed
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
1 parent 6967933 commit 0c03db9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

gdb/dwarf2/attribute.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ struct attribute
175175
false. */
176176
bool form_is_strictly_signed () const;
177177

178+
/* Check if the attribute's form is an unsigned constant form. This
179+
only returns true for forms that are strictly unsigned -- that
180+
is, for a context-dependent form like DW_FORM_data1, this returns
181+
false. */
182+
bool form_is_strictly_unsigned () const
183+
{
184+
return form == DW_FORM_udata;
185+
}
186+
178187
/* Check if the attribute's form is a form that requires
179188
"reprocessing". */
180189
bool form_requires_reprocessing () const;

gdb/dwarf2/read.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13216,10 +13216,10 @@ get_mpz (struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr)
1321613216
? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE,
1321713217
true);
1321813218
}
13219-
else if (attr->form_is_unsigned ())
13219+
else if (attr->form_is_strictly_unsigned ())
1322013220
*value = gdb_mpz (attr->as_unsigned ());
1322113221
else
13222-
*value = gdb_mpz (attr->constant_value (1));
13222+
*value = gdb_mpz (attr->signed_constant ().value_or (1));
1322313223
}
1322413224

1322513225
/* Assuming DIE is a rational DW_TAG_constant, read the DIE's

0 commit comments

Comments
 (0)