Commit | Line | Data |
---|---|---|
8ae78a44 TT |
1 | /* DWARF CU data structure |
2 | ||
3 | Copyright (C) 2021 Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #ifndef GDB_DWARF2_CU_H | |
21 | #define GDB_DWARF2_CU_H | |
22 | ||
23 | #include "buildsym.h" | |
cd53fa40 | 24 | #include "dwarf2/comp-unit-head.h" |
8ae78a44 TT |
25 | #include "gdbsupport/gdb_optional.h" |
26 | ||
27 | /* Type used for delaying computation of method physnames. | |
28 | See comments for compute_delayed_physnames. */ | |
29 | struct delayed_method_info | |
30 | { | |
31 | /* The type to which the method is attached, i.e., its parent class. */ | |
32 | struct type *type; | |
33 | ||
34 | /* The index of the method in the type's function fieldlists. */ | |
35 | int fnfield_index; | |
36 | ||
37 | /* The index of the method in the fieldlist. */ | |
38 | int index; | |
39 | ||
40 | /* The name of the DIE. */ | |
41 | const char *name; | |
42 | ||
43 | /* The DIE associated with this method. */ | |
44 | struct die_info *die; | |
45 | }; | |
46 | ||
47 | /* Internal state when decoding a particular compilation unit. */ | |
48 | struct dwarf2_cu | |
49 | { | |
50 | explicit dwarf2_cu (dwarf2_per_cu_data *per_cu, | |
51 | dwarf2_per_objfile *per_objfile); | |
52 | ||
53 | DISABLE_COPY_AND_ASSIGN (dwarf2_cu); | |
54 | ||
55 | /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope. | |
56 | Create the set of symtabs used by this TU, or if this TU is sharing | |
57 | symtabs with another TU and the symtabs have already been created | |
58 | then restore those symtabs in the line header. | |
59 | We don't need the pc/line-number mapping for type units. */ | |
60 | void setup_type_unit_groups (struct die_info *die); | |
61 | ||
62 | /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the | |
63 | buildsym_compunit constructor. */ | |
64 | struct compunit_symtab *start_symtab (const char *name, | |
65 | const char *comp_dir, | |
66 | CORE_ADDR low_pc); | |
67 | ||
68 | /* Reset the builder. */ | |
69 | void reset_builder () { m_builder.reset (); } | |
70 | ||
71 | /* Return a type that is a generic pointer type, the size of which | |
72 | matches the address size given in the compilation unit header for | |
73 | this CU. */ | |
74 | struct type *addr_type () const; | |
75 | ||
76 | /* Find an integer type the same size as the address size given in | |
77 | the compilation unit header for this CU. UNSIGNED_P controls if | |
78 | the integer is unsigned or not. */ | |
79 | struct type *addr_sized_int_type (bool unsigned_p) const; | |
80 | ||
347212b8 TT |
81 | /* Mark this CU as used. */ |
82 | void mark (); | |
83 | ||
84 | /* Clear the mark on this CU. */ | |
85 | void clear_mark () | |
86 | { | |
87 | m_mark = false; | |
88 | } | |
89 | ||
90 | /* True if this CU has been marked. */ | |
91 | bool is_marked () const | |
92 | { | |
93 | return m_mark; | |
94 | } | |
95 | ||
96 | /* Add a dependence relationship from this cu to REF_PER_CU. */ | |
97 | void add_dependence (struct dwarf2_per_cu_data *ref_per_cu); | |
98 | ||
8ae78a44 TT |
99 | /* The header of the compilation unit. */ |
100 | struct comp_unit_head header {}; | |
101 | ||
102 | /* Base address of this compilation unit. */ | |
103 | gdb::optional<CORE_ADDR> base_address; | |
104 | ||
105 | /* The language we are debugging. */ | |
106 | enum language language = language_unknown; | |
107 | const struct language_defn *language_defn = nullptr; | |
108 | ||
109 | const char *producer = nullptr; | |
110 | ||
111 | private: | |
112 | /* The symtab builder for this CU. This is only non-NULL when full | |
113 | symbols are being read. */ | |
114 | std::unique_ptr<buildsym_compunit> m_builder; | |
115 | ||
347212b8 TT |
116 | /* A set of pointers to dwarf2_per_cu_data objects for compilation |
117 | units referenced by this one. Only set during full symbol processing; | |
118 | partial symbol tables do not have dependencies. */ | |
119 | htab_t m_dependencies = nullptr; | |
120 | ||
8ae78a44 TT |
121 | public: |
122 | /* The generic symbol table building routines have separate lists for | |
123 | file scope symbols and all all other scopes (local scopes). So | |
124 | we need to select the right one to pass to add_symbol_to_list(). | |
125 | We do it by keeping a pointer to the correct list in list_in_scope. | |
126 | ||
127 | FIXME: The original dwarf code just treated the file scope as the | |
128 | first local scope, and all other local scopes as nested local | |
129 | scopes, and worked fine. Check to see if we really need to | |
130 | distinguish these in buildsym.c. */ | |
131 | struct pending **list_in_scope = nullptr; | |
132 | ||
133 | /* Hash table holding all the loaded partial DIEs | |
134 | with partial_die->offset.SECT_OFF as hash. */ | |
135 | htab_t partial_dies = nullptr; | |
136 | ||
137 | /* Storage for things with the same lifetime as this read-in compilation | |
138 | unit, including partial DIEs. */ | |
139 | auto_obstack comp_unit_obstack; | |
140 | ||
141 | /* Backlink to our per_cu entry. */ | |
142 | struct dwarf2_per_cu_data *per_cu; | |
143 | ||
144 | /* The dwarf2_per_objfile that owns this. */ | |
145 | dwarf2_per_objfile *per_objfile; | |
146 | ||
147 | /* How many compilation units ago was this CU last referenced? */ | |
148 | int last_used = 0; | |
149 | ||
150 | /* A hash table of DIE cu_offset for following references with | |
151 | die_info->offset.sect_off as hash. */ | |
152 | htab_t die_hash = nullptr; | |
153 | ||
154 | /* Full DIEs if read in. */ | |
155 | struct die_info *dies = nullptr; | |
156 | ||
8ae78a44 TT |
157 | /* Header data from the line table, during full symbol processing. */ |
158 | struct line_header *line_header = nullptr; | |
159 | /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise, | |
160 | it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL, | |
161 | this is the DW_TAG_compile_unit die for this CU. We'll hold on | |
162 | to the line header as long as this DIE is being processed. See | |
163 | process_die_scope. */ | |
164 | die_info *line_header_die_owner = nullptr; | |
165 | ||
166 | /* A list of methods which need to have physnames computed | |
167 | after all type information has been read. */ | |
168 | std::vector<delayed_method_info> method_list; | |
169 | ||
170 | /* To be copied to symtab->call_site_htab. */ | |
171 | htab_t call_site_htab = nullptr; | |
172 | ||
173 | /* Non-NULL if this CU came from a DWO file. | |
174 | There is an invariant here that is important to remember: | |
175 | Except for attributes copied from the top level DIE in the "main" | |
176 | (or "stub") file in preparation for reading the DWO file | |
177 | (e.g., DW_AT_addr_base), we KISS: there is only *one* CU. | |
178 | Either there isn't a DWO file (in which case this is NULL and the point | |
179 | is moot), or there is and either we're not going to read it (in which | |
180 | case this is NULL) or there is and we are reading it (in which case this | |
181 | is non-NULL). */ | |
182 | struct dwo_unit *dwo_unit = nullptr; | |
183 | ||
184 | /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present. | |
185 | Note this value comes from the Fission stub CU/TU's DIE. */ | |
186 | gdb::optional<ULONGEST> addr_base; | |
187 | ||
188 | /* The DW_AT_GNU_ranges_base attribute, if present. | |
189 | ||
190 | This is only relevant in the context of pre-DWARF 5 split units. In this | |
191 | context, there is a .debug_ranges section in the linked executable, | |
192 | containing all the ranges data for all the compilation units. Each | |
193 | skeleton/stub unit has (if needed) a DW_AT_GNU_ranges_base attribute that | |
194 | indicates the base of its contribution to that section. The DW_AT_ranges | |
195 | attributes in the split-unit are of the form DW_FORM_sec_offset and point | |
196 | into the .debug_ranges section of the linked file. However, they are not | |
197 | "true" DW_FORM_sec_offset, because they are relative to the base of their | |
198 | compilation unit's contribution, rather than relative to the beginning of | |
199 | the section. The DW_AT_GNU_ranges_base value must be added to it to make | |
200 | it relative to the beginning of the section. | |
201 | ||
202 | Note that the value is zero when we are not in a pre-DWARF 5 split-unit | |
203 | case, so this value can be added without needing to know whether we are in | |
204 | this case or not. | |
205 | ||
206 | N.B. If a DW_AT_ranges attribute is found on the DW_TAG_compile_unit in the | |
207 | skeleton/stub, it must not have the base added, as it already points to the | |
208 | right place. And since the DW_TAG_compile_unit DIE in the split-unit can't | |
209 | have a DW_AT_ranges attribute, we can use the | |
210 | ||
211 | die->tag != DW_AT_compile_unit | |
212 | ||
213 | to determine whether the base should be added or not. */ | |
214 | ULONGEST gnu_ranges_base = 0; | |
215 | ||
216 | /* The DW_AT_rnglists_base attribute, if present. | |
217 | ||
218 | This is used when processing attributes of form DW_FORM_rnglistx in | |
219 | non-split units. Attributes of this form found in a split unit don't | |
220 | use it, as split-unit files have their own non-shared .debug_rnglists.dwo | |
221 | section. */ | |
222 | ULONGEST rnglists_base = 0; | |
223 | ||
224 | /* The DW_AT_loclists_base attribute if present. */ | |
225 | ULONGEST loclist_base = 0; | |
226 | ||
227 | /* When reading debug info generated by older versions of rustc, we | |
228 | have to rewrite some union types to be struct types with a | |
229 | variant part. This rewriting must be done after the CU is fully | |
230 | read in, because otherwise at the point of rewriting some struct | |
231 | type might not have been fully processed. So, we keep a list of | |
232 | all such types here and process them after expansion. */ | |
233 | std::vector<struct type *> rust_unions; | |
234 | ||
235 | /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO | |
236 | files, the value is implicitly zero. For DWARF 5 version DWO files, the | |
237 | value is often implicit and is the size of the header of | |
238 | .debug_str_offsets section (8 or 4, depending on the address size). */ | |
239 | gdb::optional<ULONGEST> str_offsets_base; | |
240 | ||
241 | /* Mark used when releasing cached dies. */ | |
347212b8 | 242 | bool m_mark : 1; |
8ae78a44 TT |
243 | |
244 | /* This CU references .debug_loc. See the symtab->locations_valid field. | |
245 | This test is imperfect as there may exist optimized debug code not using | |
246 | any location list and still facing inlining issues if handled as | |
247 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
248 | bool has_loclist : 1; | |
249 | ||
250 | /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true | |
251 | if all the producer_is_* fields are valid. This information is cached | |
252 | because profiling CU expansion showed excessive time spent in | |
253 | producer_is_gxx_lt_4_6. */ | |
254 | bool checked_producer : 1; | |
255 | bool producer_is_gxx_lt_4_6 : 1; | |
256 | bool producer_is_gcc_lt_4_3 : 1; | |
257 | bool producer_is_icc : 1; | |
258 | bool producer_is_icc_lt_14 : 1; | |
259 | bool producer_is_codewarrior : 1; | |
260 | ||
261 | /* When true, the file that we're processing is known to have | |
262 | debugging info for C++ namespaces. GCC 3.3.x did not produce | |
263 | this information, but later versions do. */ | |
264 | ||
265 | bool processing_has_namespace_info : 1; | |
266 | ||
6dcd1193 TV |
267 | /* This flag will be set when reading partial DIEs if we need to load |
268 | absolutely all DIEs for this compilation unit, instead of just the ones | |
269 | we think are interesting. It gets set if we look for a DIE in the | |
270 | hash table and don't find it. */ | |
271 | bool load_all_dies : 1; | |
272 | ||
8ae78a44 TT |
273 | struct partial_die_info *find_partial_die (sect_offset sect_off); |
274 | ||
8ae78a44 | 275 | /* Get the buildsym_compunit for this CU. */ |
8457e5ec | 276 | buildsym_compunit *get_builder (); |
8ae78a44 TT |
277 | }; |
278 | ||
279 | #endif /* GDB_DWARF2_CU_H */ |