-/* Read in the comp unit header information from the debug_info at info_ptr.
- Use rcuh_kind::COMPILE as the default type if not known by the caller.
- NOTE: This leaves members offset, first_die_offset to be filled in
- by the caller. */
-
-static const gdb_byte *
-read_comp_unit_head (struct comp_unit_head *cu_header,
- const gdb_byte *info_ptr,
- struct dwarf2_section_info *section,
- rcuh_kind section_kind)
-{
- int signed_addr;
- unsigned int bytes_read;
- 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->initial_length_size = bytes_read;
- cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
- info_ptr += bytes_read;
- cu_header->version = read_2_bytes (abfd, info_ptr);
- if (cu_header->version < 2 || cu_header->version > 5)
- error (_("Dwarf Error: wrong version in compilation unit header "
- "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
- cu_header->version, filename);
- info_ptr += 2;
- if (cu_header->version < 5)
- switch (section_kind)
- {
- case rcuh_kind::COMPILE:
- cu_header->unit_type = DW_UT_compile;
- break;
- case rcuh_kind::TYPE:
- cu_header->unit_type = DW_UT_type;
- break;
- default:
- internal_error (__FILE__, __LINE__,
- _("read_comp_unit_head: invalid section_kind"));
- }
- else
- {
- cu_header->unit_type = static_cast<enum dwarf_unit_type>
- (read_1_byte (abfd, info_ptr));
- info_ptr += 1;
- switch (cu_header->unit_type)
- {
- case DW_UT_compile:
- case DW_UT_partial:
- case DW_UT_skeleton:
- case DW_UT_split_compile:
- if (section_kind != rcuh_kind::COMPILE)
- error (_("Dwarf Error: wrong unit_type in compilation unit header "
- "(is %s, should be %s) [in module %s]"),
- dwarf_unit_type_name (cu_header->unit_type),
- dwarf_unit_type_name (DW_UT_type), filename);
- break;
- case DW_UT_type:
- case DW_UT_split_type:
- section_kind = rcuh_kind::TYPE;
- break;
- default:
- error (_("Dwarf Error: wrong unit_type in compilation unit header "
- "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
- "[in module %s]"), cu_header->unit_type,
- dwarf_unit_type_name (DW_UT_compile),
- dwarf_unit_type_name (DW_UT_skeleton),
- dwarf_unit_type_name (DW_UT_split_compile),
- dwarf_unit_type_name (DW_UT_type),
- dwarf_unit_type_name (DW_UT_split_type), filename);
- }
-
- cu_header->addr_size = read_1_byte (abfd, info_ptr);
- info_ptr += 1;
- }
- cu_header->abbrev_sect_off = (sect_offset) read_offset (abfd, info_ptr,
- cu_header,
- &bytes_read);
- info_ptr += bytes_read;
- if (cu_header->version < 5)
- {
- cu_header->addr_size = read_1_byte (abfd, info_ptr);
- info_ptr += 1;
- }
- signed_addr = bfd_get_sign_extend_vma (abfd);
- if (signed_addr < 0)
- internal_error (__FILE__, __LINE__,
- _("read_comp_unit_head: dwarf from non elf file"));
- cu_header->signed_addr_p = signed_addr;
-
- bool header_has_signature = section_kind == rcuh_kind::TYPE
- || cu_header->unit_type == DW_UT_skeleton
- || cu_header->unit_type == DW_UT_split_compile;
-
- if (header_has_signature)
- {
- cu_header->signature = read_8_bytes (abfd, info_ptr);
- info_ptr += 8;
- }
-
- if (section_kind == rcuh_kind::TYPE)
- {
- LONGEST type_offset;
- type_offset = read_offset (abfd, info_ptr, cu_header, &bytes_read);
- info_ptr += bytes_read;
- cu_header->type_cu_offset_in_tu = (cu_offset) type_offset;
- if (to_underlying (cu_header->type_cu_offset_in_tu) != type_offset)
- error (_("Dwarf Error: Too big type_offset in compilation unit "
- "header (is %s) [in module %s]"), plongest (type_offset),
- filename);
- }
-
- return info_ptr;
-}
-