1*6881a400Schristos /* Low-level DWARF 2 reading code 2*6881a400Schristos 3*6881a400Schristos Copyright (C) 1994-2023 Free Software Foundation, Inc. 4*6881a400Schristos 5*6881a400Schristos Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, 6*6881a400Schristos Inc. with support from Florida State University (under contract 7*6881a400Schristos with the Ada Joint Program Office), and Silicon Graphics, Inc. 8*6881a400Schristos Initial contribution by Brent Benson, Harris Computer Systems, Inc., 9*6881a400Schristos based on Fred Fish's (Cygnus Support) implementation of DWARF 1 10*6881a400Schristos support. 11*6881a400Schristos 12*6881a400Schristos This file is part of GDB. 13*6881a400Schristos 14*6881a400Schristos This program is free software; you can redistribute it and/or modify 15*6881a400Schristos it under the terms of the GNU General Public License as published by 16*6881a400Schristos the Free Software Foundation; either version 3 of the License, or 17*6881a400Schristos (at your option) any later version. 18*6881a400Schristos 19*6881a400Schristos This program is distributed in the hope that it will be useful, 20*6881a400Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 21*6881a400Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22*6881a400Schristos GNU General Public License for more details. 23*6881a400Schristos 24*6881a400Schristos You should have received a copy of the GNU General Public License 25*6881a400Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 26*6881a400Schristos 27*6881a400Schristos #ifndef GDB_DWARF2_COMP_UNIT_H 28*6881a400Schristos #define GDB_DWARF2_COMP_UNIT_H 29*6881a400Schristos 30*6881a400Schristos #include "dwarf2/leb.h" 31*6881a400Schristos #include "gdbtypes.h" 32*6881a400Schristos 33*6881a400Schristos /* The data in a compilation unit header, after target2host 34*6881a400Schristos translation, looks like this. */ 35*6881a400Schristos struct comp_unit_head 36*6881a400Schristos { 37*6881a400Schristos unsigned int length; 38*6881a400Schristos unsigned char version; 39*6881a400Schristos unsigned char addr_size; 40*6881a400Schristos unsigned char signed_addr_p; 41*6881a400Schristos sect_offset abbrev_sect_off; 42*6881a400Schristos 43*6881a400Schristos /* Size of file offsets; either 4 or 8. */ 44*6881a400Schristos unsigned int offset_size; 45*6881a400Schristos 46*6881a400Schristos /* Size of the length field; either 4 or 12. */ 47*6881a400Schristos unsigned int initial_length_size; 48*6881a400Schristos 49*6881a400Schristos enum dwarf_unit_type unit_type; 50*6881a400Schristos 51*6881a400Schristos /* Offset to first die in this cu from the start of the cu. 52*6881a400Schristos This will be the first byte following the compilation unit header. */ 53*6881a400Schristos cu_offset first_die_cu_offset; 54*6881a400Schristos 55*6881a400Schristos /* Offset to the first byte of this compilation unit header in the 56*6881a400Schristos .debug_info section, for resolving relative reference dies. */ 57*6881a400Schristos sect_offset sect_off; 58*6881a400Schristos 59*6881a400Schristos /* For types, offset in the type's DIE of the type defined by this TU. */ 60*6881a400Schristos cu_offset type_cu_offset_in_tu; 61*6881a400Schristos 62*6881a400Schristos /* 64-bit signature of this unit. For type units, it denotes the signature of 63*6881a400Schristos the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5). 64*6881a400Schristos Also used in DWARF 5, to denote the dwo id when the unit type is 65*6881a400Schristos DW_UT_skeleton or DW_UT_split_compile. */ 66*6881a400Schristos ULONGEST signature; 67*6881a400Schristos 68*6881a400Schristos /* Return the total length of the CU described by this header. */ 69*6881a400Schristos unsigned int get_length () const 70*6881a400Schristos { 71*6881a400Schristos return initial_length_size + length; 72*6881a400Schristos } 73*6881a400Schristos 74*6881a400Schristos /* Return TRUE if OFF is within this CU. */ 75*6881a400Schristos bool offset_in_cu_p (sect_offset off) const 76*6881a400Schristos { 77*6881a400Schristos sect_offset bottom = sect_off; 78*6881a400Schristos sect_offset top = sect_off + get_length (); 79*6881a400Schristos return off >= bottom && off < top; 80*6881a400Schristos } 81*6881a400Schristos 82*6881a400Schristos /* Read an offset from the data stream. The size of the offset is 83*6881a400Schristos given by cu_header->offset_size. */ 84*6881a400Schristos LONGEST read_offset (bfd *abfd, const gdb_byte *buf, 85*6881a400Schristos unsigned int *bytes_read) const 86*6881a400Schristos { 87*6881a400Schristos LONGEST offset = ::read_offset (abfd, buf, offset_size); 88*6881a400Schristos *bytes_read = offset_size; 89*6881a400Schristos return offset; 90*6881a400Schristos } 91*6881a400Schristos 92*6881a400Schristos /* Read an address from BUF. BYTES_READ is updated. */ 93*6881a400Schristos CORE_ADDR read_address (bfd *abfd, const gdb_byte *buf, 94*6881a400Schristos unsigned int *bytes_read) const; 95*6881a400Schristos }; 96*6881a400Schristos 97*6881a400Schristos /* Expected enum dwarf_unit_type for read_comp_unit_head. */ 98*6881a400Schristos enum class rcuh_kind { COMPILE, TYPE }; 99*6881a400Schristos 100*6881a400Schristos /* Read in the comp unit header information from the debug_info at info_ptr. 101*6881a400Schristos Use rcuh_kind::COMPILE as the default type if not known by the caller. 102*6881a400Schristos NOTE: This leaves members offset, first_die_offset to be filled in 103*6881a400Schristos by the caller. */ 104*6881a400Schristos extern const gdb_byte *read_comp_unit_head 105*6881a400Schristos (struct comp_unit_head *cu_header, 106*6881a400Schristos const gdb_byte *info_ptr, 107*6881a400Schristos struct dwarf2_section_info *section, 108*6881a400Schristos rcuh_kind section_kind); 109*6881a400Schristos 110*6881a400Schristos /* Read in a CU/TU header and perform some basic error checking. 111*6881a400Schristos The contents of the header are stored in HEADER. 112*6881a400Schristos The result is a pointer to the start of the first DIE. */ 113*6881a400Schristos extern const gdb_byte *read_and_check_comp_unit_head 114*6881a400Schristos (dwarf2_per_objfile *per_objfile, 115*6881a400Schristos struct comp_unit_head *header, 116*6881a400Schristos struct dwarf2_section_info *section, 117*6881a400Schristos struct dwarf2_section_info *abbrev_section, 118*6881a400Schristos const gdb_byte *info_ptr, 119*6881a400Schristos rcuh_kind section_kind); 120*6881a400Schristos 121*6881a400Schristos #endif /* GDB_DWARF2_COMP_UNIT_H */ 122