[Bug gdb/34426] New: [gdb] DW_AT_bit_size-only base types lose their exact bit width
firmiana402 at gmail dot com via Gdb-prs <[email protected]>
| Newsgroups | gmane.comp.gdb.bugs.discuss |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://sourceware.org/bugzilla/show_bug.cgi?id=34426
Bug ID: 34426
Summary: [gdb] DW_AT_bit_size-only base types lose their exact
bit width
Product: gdb
Version: HEAD
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: gdb
Assignee: unassigned at sourceware dot org
Reporter: firmiana402 at gmail dot com
Target Milestone: ---
GDB loses the exact width of integer base types whose sole size
attribute is DW_AT_bit_size and whose width is not a multiple of 8.
It records the byte-rounded storage width as the logical width.
DWARF v5 Section 5.1 states:
"A base type entry has a DW_AT_byte_size attribute or a
DW_AT_bit_size attribute whose integer constant value (see
Section 2.21 on page 56) is the amount of storage needed to hold
a value of the type."
This permits DW_AT_bit_size as the sole size attribute. Therefore,
this is a valid 31-bit integer type:
DW_TAG_base_type
DW_AT_encoding DW_ATE_signed
DW_AT_bit_size 31
In gdb/dwarf2/read.c, read_base_type does not preserve that exact
width when DW_AT_byte_size is absent. It first computes:
if (byte_size.has_value ())
bits = TARGET_CHAR_BIT * *byte_size;
else if (bit_size.has_value ())
bits = align_up (*bit_size, 8);
For this type, bits becomes 32 and is passed to init_integer_type. In
gdb/gdbtypes.c, that function records the same rounded value as the
logical bit size:
t = alloc.new_type (TYPE_CODE_INT, bit, name);
...
TYPE_MAIN_TYPE (t)->type_specific.int_stuff.bit_size = bit;
The type therefore has both a 4-byte storage size and a 32-bit logical
width. Later in read_base_type, the original DW_AT_bit_size is
restored only when DW_AT_byte_size is also present:
if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_INT
&& byte_size.has_value ()
&& bit_size.has_value ())
{
...
type->main_type->type_specific.int_stuff.bit_size = *bit_size;
}
Because the valid type above has no DW_AT_byte_size, this block is
skipped and the logical width remains 32 instead of 31.
This might be an implementation/specification mismatch in read_base_type.
--
You are receiving this mail because:
You are on the CC list for the bug.