const char *filename = section->get_file_name ();
bfd *abfd = section->get_bfd_owner ();
- cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
+ cu_header->set_length (read_initial_length (abfd, info_ptr, &bytes_read));
cu_header->initial_length_size = bytes_read;
cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
info_ptr += bytes_read;
/* Cast to ULONGEST to use 64-bit arithmetic when possible to
avoid potential 32-bit overflow. */
- if (((ULONGEST) header->sect_off + header->get_length ())
+ if (((ULONGEST) header->sect_off + header->get_length_with_initial ())
> section->size)
error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
"(offset %s + 0) [in module %s]"),
- header->length, sect_offset_str (header->sect_off),
+ header->get_length_without_initial (), sect_offset_str (header->sect_off),
filename);
}
translation, looks like this. */
struct comp_unit_head
{
- unsigned int length = 0;
+private:
+ unsigned int m_length = 0;
+public:
unsigned char version = 0;
unsigned char addr_size = 0;
unsigned char signed_addr_p = 0;
DW_UT_skeleton or DW_UT_split_compile. */
ULONGEST signature = 0;
- /* Return the total length of the CU described by this header. */
- unsigned int get_length () const
+ void set_length (unsigned int length)
{
- return initial_length_size + length;
+ m_length = length;
+ }
+
+ /* Return the total length of the CU described by this header, including the
+ initial length field. */
+ unsigned int get_length_with_initial () const
+ {
+ return m_length + initial_length_size;
+ }
+
+ /* Return the total length of the CU described by this header, excluding the
+ initial length field. */
+ unsigned int get_length_without_initial () const
+ {
+ return m_length;
}
/* Return TRUE if OFF is within this CU. */
bool offset_in_cu_p (sect_offset off) const
{
sect_offset bottom = sect_off;
- sect_offset top = sect_off + get_length ();
+ sect_offset top = sect_off + get_length_with_initial ();
return off >= bottom && off < top;
}
ptr = read_and_check_comp_unit_head (per_objfile, &header, section,
abbrev_section, ptr, section_kind);
- length = header.get_length ();
+ length = header.get_length_with_initial ();
/* Skip dummy type units. */
if (ptr >= info_ptr + length
gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
/* For DWOs coming from DWP files, we don't know the CU length
nor the type's offset in the TU until now. */
- dwo_unit->length = cu->header.get_length ();
+ dwo_unit->length = cu->header.get_length_with_initial ();
dwo_unit->type_offset_in_tu = cu->header.type_cu_offset_in_tu;
/* Establish the type offset that can be used to lookup the type.
gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
/* For DWOs coming from DWP files, we don't know the CU length
until now. */
- dwo_unit->length = cu->header.get_length ();
+ dwo_unit->length = cu->header.get_length_with_initial ();
}
dwo_abbrev_section->read (objfile);
/* LENGTH has not been set yet for type units if we're
using .gdb_index. */
- this_cu->set_length (cu->header.get_length ());
+ this_cu->set_length (cu->header.get_length_with_initial ());
/* Establish the type offset that can be used to lookup the type. */
sig_type->type_offset_in_section =
rcuh_kind::COMPILE);
gdb_assert (this_cu->sect_off == cu->header.sect_off);
- this_cu->set_length (cu->header.get_length ());
+ this_cu->set_length (cu->header.get_length_with_initial ());
this_cu->set_version (cu->header.version);
}
}
m_new_cu->str_offsets_base = parent_cu->str_offsets_base;
m_new_cu->addr_base = parent_cu->addr_base;
}
- this_cu->set_length (m_new_cu->header.get_length ());
+ this_cu->set_length (m_new_cu->header.get_length_with_initial ());
/* Skip dummy compilation units. */
if (info_ptr >= begin_info_ptr + this_cu->length ()
*slot = sig_ptr;
}
this_cu->sect_off = sect_off;
- this_cu->set_length (cu_header.get_length ());
+ this_cu->set_length (cu_header.get_length_with_initial ());
this_cu->is_dwz = is_dwz;
this_cu->section = section;
/* Init this asap, to avoid a data race in the set_version in
gdb_assert (cu->die_hash == NULL);
cu->die_hash =
- htab_create_alloc_ex (cu->header.length / 12,
+ htab_create_alloc_ex (cu->header.get_length_without_initial () / 12,
die_hash,
die_eq,
NULL,
{
const gdb_byte *end_ptr = (reader->buffer
+ to_underlying (reader->cu->header.sect_off)
- + reader->cu->header.get_length ());
+ + reader->cu->header.get_length_with_initial ());
while (info_ptr < end_ptr)
{
gdb_assert (cu->die_hash == NULL);
cu->die_hash =
- htab_create_alloc_ex (cu->header.length / 12,
+ htab_create_alloc_ex (cu->header.get_length_without_initial () / 12,
die_hash,
die_eq,
NULL,