]>
Commit | Line | Data |
---|---|---|
4057dfde TT |
1 | /* Low-level DWARF 2 reading code |
2 | ||
213516ef | 3 | Copyright (C) 1994-2023 Free Software Foundation, Inc. |
4057dfde TT |
4 | |
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 | |
10 | support. | |
11 | ||
12 | This file is part of GDB. | |
13 | ||
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. | |
18 | ||
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. | |
23 | ||
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/>. */ | |
26 | ||
27 | #ifndef GDB_DWARF2_COMP_UNIT_H | |
28 | #define GDB_DWARF2_COMP_UNIT_H | |
29 | ||
8266302d | 30 | #include "dwarf2/leb.h" |
4057dfde TT |
31 | #include "gdbtypes.h" |
32 | ||
33 | /* The data in a compilation unit header, after target2host | |
34 | translation, looks like this. */ | |
35 | struct comp_unit_head | |
36 | { | |
d8f52a9a TV |
37 | private: |
38 | unsigned int m_length = 0; | |
39 | public: | |
4d78ce77 TT |
40 | unsigned char version = 0; |
41 | unsigned char addr_size = 0; | |
42 | unsigned char signed_addr_p = 0; | |
43 | sect_offset abbrev_sect_off {}; | |
4057dfde TT |
44 | |
45 | /* Size of file offsets; either 4 or 8. */ | |
4d78ce77 | 46 | unsigned int offset_size = 0; |
4057dfde TT |
47 | |
48 | /* Size of the length field; either 4 or 12. */ | |
4d78ce77 | 49 | unsigned int initial_length_size = 0; |
4057dfde | 50 | |
4d78ce77 | 51 | enum dwarf_unit_type unit_type {}; |
4057dfde | 52 | |
4057dfde TT |
53 | /* Offset to first die in this cu from the start of the cu. |
54 | This will be the first byte following the compilation unit header. */ | |
4d78ce77 | 55 | cu_offset first_die_cu_offset {}; |
4057dfde | 56 | |
7e7a35fb TT |
57 | /* Offset to the first byte of this compilation unit header in the |
58 | .debug_info section, for resolving relative reference dies. */ | |
4d78ce77 | 59 | sect_offset sect_off {}; |
7e7a35fb TT |
60 | |
61 | /* For types, offset in the type's DIE of the type defined by this TU. */ | |
4d78ce77 | 62 | cu_offset type_cu_offset_in_tu {}; |
4057dfde TT |
63 | |
64 | /* 64-bit signature of this unit. For type units, it denotes the signature of | |
65 | the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5). | |
66 | Also used in DWARF 5, to denote the dwo id when the unit type is | |
67 | DW_UT_skeleton or DW_UT_split_compile. */ | |
4d78ce77 | 68 | ULONGEST signature = 0; |
4057dfde | 69 | |
d8f52a9a | 70 | void set_length (unsigned int length) |
4057dfde | 71 | { |
d8f52a9a TV |
72 | m_length = length; |
73 | } | |
74 | ||
75 | /* Return the total length of the CU described by this header, including the | |
76 | initial length field. */ | |
77 | unsigned int get_length_with_initial () const | |
78 | { | |
79 | return m_length + initial_length_size; | |
80 | } | |
81 | ||
82 | /* Return the total length of the CU described by this header, excluding the | |
83 | initial length field. */ | |
84 | unsigned int get_length_without_initial () const | |
85 | { | |
86 | return m_length; | |
4057dfde TT |
87 | } |
88 | ||
89 | /* Return TRUE if OFF is within this CU. */ | |
90 | bool offset_in_cu_p (sect_offset off) const | |
91 | { | |
92 | sect_offset bottom = sect_off; | |
d8f52a9a | 93 | sect_offset top = sect_off + get_length_with_initial (); |
4057dfde TT |
94 | return off >= bottom && off < top; |
95 | } | |
8266302d TT |
96 | |
97 | /* Read an offset from the data stream. The size of the offset is | |
98 | given by cu_header->offset_size. */ | |
99 | LONGEST read_offset (bfd *abfd, const gdb_byte *buf, | |
100 | unsigned int *bytes_read) const | |
101 | { | |
102 | LONGEST offset = ::read_offset (abfd, buf, offset_size); | |
103 | *bytes_read = offset_size; | |
104 | return offset; | |
105 | } | |
c8a7a66f TT |
106 | |
107 | /* Read an address from BUF. BYTES_READ is updated. */ | |
108 | CORE_ADDR read_address (bfd *abfd, const gdb_byte *buf, | |
109 | unsigned int *bytes_read) const; | |
4057dfde TT |
110 | }; |
111 | ||
112 | /* Expected enum dwarf_unit_type for read_comp_unit_head. */ | |
113 | enum class rcuh_kind { COMPILE, TYPE }; | |
114 | ||
115 | /* Read in the comp unit header information from the debug_info at info_ptr. | |
116 | Use rcuh_kind::COMPILE as the default type if not known by the caller. | |
117 | NOTE: This leaves members offset, first_die_offset to be filled in | |
118 | by the caller. */ | |
119 | extern const gdb_byte *read_comp_unit_head | |
120 | (struct comp_unit_head *cu_header, | |
121 | const gdb_byte *info_ptr, | |
122 | struct dwarf2_section_info *section, | |
123 | rcuh_kind section_kind); | |
124 | ||
125 | /* Read in a CU/TU header and perform some basic error checking. | |
126 | The contents of the header are stored in HEADER. | |
127 | The result is a pointer to the start of the first DIE. */ | |
128 | extern const gdb_byte *read_and_check_comp_unit_head | |
976ca316 | 129 | (dwarf2_per_objfile *per_objfile, |
4057dfde TT |
130 | struct comp_unit_head *header, |
131 | struct dwarf2_section_info *section, | |
132 | struct dwarf2_section_info *abbrev_section, | |
133 | const gdb_byte *info_ptr, | |
134 | rcuh_kind section_kind); | |
135 | ||
4057dfde | 136 | #endif /* GDB_DWARF2_COMP_UNIT_H */ |