@@ -13634,7 +13634,6 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
13634
13634
struct type *type;
13635
13635
struct attribute *attr;
13636
13636
ULONGEST encoding = 0;
13637
- int bits = 0;
13638
13637
const char *name;
13639
13638
13640
13639
attr = dwarf2_attr (die, DW_AT_encoding, cu);
@@ -13644,9 +13643,33 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
13644
13643
if (value.has_value ())
13645
13644
encoding = *value;
13646
13645
}
13646
+
13647
13647
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
13648
+ std::optional<ULONGEST> byte_size;
13649
+ if (attr != nullptr)
13650
+ byte_size = attr->unsigned_constant ();
13651
+ attr = dwarf2_attr (die, DW_AT_bit_size, cu);
13652
+ std::optional<ULONGEST> bit_size;
13648
13653
if (attr != nullptr)
13649
- bits = attr->unsigned_constant ().value_or (0) * TARGET_CHAR_BIT;
13654
+ bit_size = attr->unsigned_constant ();
13655
+
13656
+ attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
13657
+ std::optional<ULONGEST> bit_offset;
13658
+ if (attr != nullptr)
13659
+ bit_offset = attr->unsigned_constant ();
13660
+
13661
+ int bits = 0;
13662
+ if (byte_size.has_value ())
13663
+ bits = TARGET_CHAR_BIT * *byte_size;
13664
+ else if (bit_size.has_value ())
13665
+ bits = align_up (*bit_size, 8);
13666
+ else
13667
+ {
13668
+ /* No size, so arrange for an error type. */
13669
+ complaint (_("DW_TAG_base_type has neither bit- nor byte-size"));
13670
+ encoding = (ULONGEST) -1;
13671
+ }
13672
+
13650
13673
name = dwarf2_full_name (nullptr, die, cu);
13651
13674
if (!name)
13652
13675
complaint (_("DW_AT_name missing from DW_TAG_base_type"));
@@ -13792,35 +13815,21 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
13792
13815
13793
13816
type->set_endianity_is_not_default (not_default);
13794
13817
13795
- if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_INT)
13818
+ /* If both a byte size and bit size were provided, then that means
13819
+ that not every bit in the object contributes to the value. */
13820
+ if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_INT
13821
+ && byte_size.has_value ()
13822
+ && bit_size.has_value ())
13796
13823
{
13797
- attr = dwarf2_attr (die, DW_AT_bit_size, cu);
13798
- if (attr != nullptr && attr->form_is_constant ())
13824
+ /* DWARF says: If this attribute is omitted a default data bit
13825
+ offset of zero is assumed. */
13826
+ ULONGEST offset = bit_offset.value_or (0);
13827
+
13828
+ /* Only use the attributes if they make sense together. */
13829
+ if (*bit_size + offset <= 8 * type->length ())
13799
13830
{
13800
- unsigned real_bit_size = attr->unsigned_constant ().value_or (0);
13801
- if (real_bit_size >= 0 && real_bit_size <= 8 * type->length ())
13802
- {
13803
- attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
13804
- /* Only use the attributes if they make sense together. */
13805
- std::optional<ULONGEST> bit_offset;
13806
- if (attr == nullptr)
13807
- bit_offset = 0;
13808
- else if (attr->form_is_constant ())
13809
- {
13810
- bit_offset = attr->unsigned_constant ();
13811
- if (bit_offset.has_value ()
13812
- && *bit_offset + real_bit_size > 8 * type->length ())
13813
- bit_offset.reset ();
13814
- }
13815
- if (bit_offset.has_value ())
13816
- {
13817
- TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size
13818
- = real_bit_size;
13819
- if (attr != nullptr)
13820
- TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset
13821
- = *bit_offset;
13822
- }
13823
- }
13831
+ TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size = *bit_size;
13832
+ TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset = offset;
13824
13833
}
13825
13834
}
13826
13835
0 commit comments