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