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