Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
61baf725 | 3 | Copyright (C) 1994-2017 Free Software Foundation, Inc. |
c906108c SS |
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 | |
7ce59000 | 10 | support. |
c906108c | 11 | |
c5aa993b | 12 | This file is part of GDB. |
c906108c | 13 | |
c5aa993b JM |
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 | |
a9762ec7 JB |
16 | the Free Software Foundation; either version 3 of the License, or |
17 | (at your option) any later version. | |
c906108c | 18 | |
a9762ec7 JB |
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. | |
c906108c | 23 | |
c5aa993b | 24 | You should have received a copy of the GNU General Public License |
a9762ec7 | 25 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 26 | |
21b2bd31 DE |
27 | /* FIXME: Various die-reading functions need to be more careful with |
28 | reading off the end of the section. | |
29 | E.g., load_partial_dies, read_partial_die. */ | |
30 | ||
c906108c SS |
31 | #include "defs.h" |
32 | #include "bfd.h" | |
80626a55 | 33 | #include "elf-bfd.h" |
c906108c SS |
34 | #include "symtab.h" |
35 | #include "gdbtypes.h" | |
c906108c | 36 | #include "objfiles.h" |
fa8f86ff | 37 | #include "dwarf2.h" |
c906108c SS |
38 | #include "buildsym.h" |
39 | #include "demangle.h" | |
50f182aa | 40 | #include "gdb-demangle.h" |
c906108c | 41 | #include "expression.h" |
d5166ae1 | 42 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 43 | #include "macrotab.h" |
c906108c SS |
44 | #include "language.h" |
45 | #include "complaints.h" | |
357e46e7 | 46 | #include "bcache.h" |
4c2df51b DJ |
47 | #include "dwarf2expr.h" |
48 | #include "dwarf2loc.h" | |
9219021c | 49 | #include "cp-support.h" |
72bf9492 | 50 | #include "hashtab.h" |
ae038cb0 DJ |
51 | #include "command.h" |
52 | #include "gdbcmd.h" | |
edb3359d | 53 | #include "block.h" |
ff013f42 | 54 | #include "addrmap.h" |
94af9270 | 55 | #include "typeprint.h" |
ccefe4c4 | 56 | #include "psympriv.h" |
53ce3c39 | 57 | #include <sys/stat.h> |
96d19272 | 58 | #include "completer.h" |
34eaf542 | 59 | #include "vec.h" |
98bfdba5 | 60 | #include "c-lang.h" |
a766d390 | 61 | #include "go-lang.h" |
98bfdba5 | 62 | #include "valprint.h" |
3019eac3 | 63 | #include "gdbcore.h" /* for gnutarget */ |
156942c7 | 64 | #include "gdb/gdb-index.h" |
60d5a603 | 65 | #include <ctype.h> |
cbb099e8 | 66 | #include "gdb_bfd.h" |
4357ac6c | 67 | #include "f-lang.h" |
05cba821 | 68 | #include "source.h" |
614c279d | 69 | #include "filestuff.h" |
dc294be5 | 70 | #include "build-id.h" |
22cee43f | 71 | #include "namespace.h" |
bef155c3 | 72 | #include "common/gdb_unlinker.h" |
14bc53a8 | 73 | #include "common/function-view.h" |
ecfb656c PA |
74 | #include "common/gdb_optional.h" |
75 | #include "common/underlying.h" | |
d5722aa2 | 76 | #include "common/byte-vector.h" |
bbf2f4df | 77 | #include "filename-seen-cache.h" |
c906108c | 78 | #include <fcntl.h> |
c906108c | 79 | #include <sys/types.h> |
325fac50 | 80 | #include <algorithm> |
bc8f2430 JK |
81 | #include <unordered_set> |
82 | #include <unordered_map> | |
d8151005 | 83 | |
34eaf542 TT |
84 | typedef struct symbol *symbolp; |
85 | DEF_VEC_P (symbolp); | |
86 | ||
73be47f5 DE |
87 | /* When == 1, print basic high level tracing messages. |
88 | When > 1, be more verbose. | |
b4f54984 DE |
89 | This is in contrast to the low level DIE reading of dwarf_die_debug. */ |
90 | static unsigned int dwarf_read_debug = 0; | |
45cfd468 | 91 | |
d97bc12b | 92 | /* When non-zero, dump DIEs after they are read in. */ |
b4f54984 | 93 | static unsigned int dwarf_die_debug = 0; |
d97bc12b | 94 | |
27e0867f DE |
95 | /* When non-zero, dump line number entries as they are read in. */ |
96 | static unsigned int dwarf_line_debug = 0; | |
97 | ||
900e11f9 JK |
98 | /* When non-zero, cross-check physname against demangler. */ |
99 | static int check_physname = 0; | |
100 | ||
481860b3 | 101 | /* When non-zero, do not reject deprecated .gdb_index sections. */ |
e615022a | 102 | static int use_deprecated_index_sections = 0; |
481860b3 | 103 | |
6502dd73 DJ |
104 | static const struct objfile_data *dwarf2_objfile_data_key; |
105 | ||
f1e6e072 TT |
106 | /* The "aclass" indices for various kinds of computed DWARF symbols. */ |
107 | ||
108 | static int dwarf2_locexpr_index; | |
109 | static int dwarf2_loclist_index; | |
110 | static int dwarf2_locexpr_block_index; | |
111 | static int dwarf2_loclist_block_index; | |
112 | ||
73869dc2 DE |
113 | /* A descriptor for dwarf sections. |
114 | ||
115 | S.ASECTION, SIZE are typically initialized when the objfile is first | |
116 | scanned. BUFFER, READIN are filled in later when the section is read. | |
117 | If the section contained compressed data then SIZE is updated to record | |
118 | the uncompressed size of the section. | |
119 | ||
120 | DWP file format V2 introduces a wrinkle that is easiest to handle by | |
121 | creating the concept of virtual sections contained within a real section. | |
122 | In DWP V2 the sections of the input DWO files are concatenated together | |
123 | into one section, but section offsets are kept relative to the original | |
124 | input section. | |
125 | If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to | |
126 | the real section this "virtual" section is contained in, and BUFFER,SIZE | |
127 | describe the virtual section. */ | |
128 | ||
dce234bc PP |
129 | struct dwarf2_section_info |
130 | { | |
73869dc2 DE |
131 | union |
132 | { | |
e5aa3347 | 133 | /* If this is a real section, the bfd section. */ |
049412e3 | 134 | asection *section; |
73869dc2 | 135 | /* If this is a virtual section, pointer to the containing ("real") |
e5aa3347 | 136 | section. */ |
73869dc2 DE |
137 | struct dwarf2_section_info *containing_section; |
138 | } s; | |
19ac8c2e | 139 | /* Pointer to section data, only valid if readin. */ |
d521ce57 | 140 | const gdb_byte *buffer; |
73869dc2 | 141 | /* The size of the section, real or virtual. */ |
dce234bc | 142 | bfd_size_type size; |
73869dc2 DE |
143 | /* If this is a virtual section, the offset in the real section. |
144 | Only valid if is_virtual. */ | |
145 | bfd_size_type virtual_offset; | |
be391dca | 146 | /* True if we have tried to read this section. */ |
73869dc2 DE |
147 | char readin; |
148 | /* True if this is a virtual section, False otherwise. | |
049412e3 | 149 | This specifies which of s.section and s.containing_section to use. */ |
73869dc2 | 150 | char is_virtual; |
dce234bc PP |
151 | }; |
152 | ||
8b70b953 TT |
153 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
154 | DEF_VEC_O (dwarf2_section_info_def); | |
155 | ||
9291a0cd TT |
156 | /* All offsets in the index are of this type. It must be |
157 | architecture-independent. */ | |
158 | typedef uint32_t offset_type; | |
159 | ||
160 | DEF_VEC_I (offset_type); | |
161 | ||
156942c7 DE |
162 | /* Ensure only legit values are used. */ |
163 | #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \ | |
164 | do { \ | |
165 | gdb_assert ((unsigned int) (value) <= 1); \ | |
166 | GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \ | |
167 | } while (0) | |
168 | ||
169 | /* Ensure only legit values are used. */ | |
170 | #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \ | |
171 | do { \ | |
172 | gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \ | |
173 | && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \ | |
174 | GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \ | |
175 | } while (0) | |
176 | ||
177 | /* Ensure we don't use more than the alloted nuber of bits for the CU. */ | |
178 | #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \ | |
179 | do { \ | |
180 | gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \ | |
181 | GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \ | |
182 | } while (0) | |
183 | ||
9291a0cd TT |
184 | /* A description of the mapped index. The file format is described in |
185 | a comment by the code that writes the index. */ | |
186 | struct mapped_index | |
187 | { | |
559a7a62 JK |
188 | /* Index data format version. */ |
189 | int version; | |
190 | ||
9291a0cd TT |
191 | /* The total length of the buffer. */ |
192 | off_t total_size; | |
b11b1f88 | 193 | |
9291a0cd TT |
194 | /* A pointer to the address table data. */ |
195 | const gdb_byte *address_table; | |
b11b1f88 | 196 | |
9291a0cd TT |
197 | /* Size of the address table data in bytes. */ |
198 | offset_type address_table_size; | |
b11b1f88 | 199 | |
3876f04e DE |
200 | /* The symbol table, implemented as a hash table. */ |
201 | const offset_type *symbol_table; | |
b11b1f88 | 202 | |
9291a0cd | 203 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 204 | offset_type symbol_table_slots; |
b11b1f88 | 205 | |
9291a0cd TT |
206 | /* A pointer to the constant pool. */ |
207 | const char *constant_pool; | |
208 | }; | |
209 | ||
95554aad TT |
210 | typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr; |
211 | DEF_VEC_P (dwarf2_per_cu_ptr); | |
212 | ||
52059ffd TT |
213 | struct tu_stats |
214 | { | |
215 | int nr_uniq_abbrev_tables; | |
216 | int nr_symtabs; | |
217 | int nr_symtab_sharers; | |
218 | int nr_stmt_less_type_units; | |
219 | int nr_all_type_units_reallocs; | |
220 | }; | |
221 | ||
9cdd5dbd DE |
222 | /* Collection of data recorded per objfile. |
223 | This hangs off of dwarf2_objfile_data_key. */ | |
224 | ||
6502dd73 DJ |
225 | struct dwarf2_per_objfile |
226 | { | |
330cdd98 PA |
227 | /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the |
228 | dwarf2 section names, or is NULL if the standard ELF names are | |
229 | used. */ | |
230 | dwarf2_per_objfile (struct objfile *objfile, | |
231 | const dwarf2_debug_sections *names); | |
ae038cb0 | 232 | |
330cdd98 PA |
233 | ~dwarf2_per_objfile (); |
234 | ||
235 | /* Disable copy. */ | |
236 | dwarf2_per_objfile (const dwarf2_per_objfile &) = delete; | |
237 | void operator= (const dwarf2_per_objfile &) = delete; | |
238 | ||
239 | /* Free all cached compilation units. */ | |
240 | void free_cached_comp_units (); | |
241 | private: | |
242 | /* This function is mapped across the sections and remembers the | |
243 | offset and size of each of the debugging sections we are | |
244 | interested in. */ | |
245 | void locate_sections (bfd *abfd, asection *sectp, | |
246 | const dwarf2_debug_sections &names); | |
247 | ||
248 | public: | |
249 | dwarf2_section_info info {}; | |
250 | dwarf2_section_info abbrev {}; | |
251 | dwarf2_section_info line {}; | |
252 | dwarf2_section_info loc {}; | |
253 | dwarf2_section_info loclists {}; | |
254 | dwarf2_section_info macinfo {}; | |
255 | dwarf2_section_info macro {}; | |
256 | dwarf2_section_info str {}; | |
257 | dwarf2_section_info line_str {}; | |
258 | dwarf2_section_info ranges {}; | |
259 | dwarf2_section_info rnglists {}; | |
260 | dwarf2_section_info addr {}; | |
261 | dwarf2_section_info frame {}; | |
262 | dwarf2_section_info eh_frame {}; | |
263 | dwarf2_section_info gdb_index {}; | |
264 | ||
265 | VEC (dwarf2_section_info_def) *types = NULL; | |
8b70b953 | 266 | |
be391dca | 267 | /* Back link. */ |
330cdd98 | 268 | struct objfile *objfile = NULL; |
be391dca | 269 | |
d467dd73 | 270 | /* Table of all the compilation units. This is used to locate |
10b3939b | 271 | the target compilation unit of a particular reference. */ |
330cdd98 | 272 | struct dwarf2_per_cu_data **all_comp_units = NULL; |
ae038cb0 DJ |
273 | |
274 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
330cdd98 | 275 | int n_comp_units = 0; |
ae038cb0 | 276 | |
1fd400ff | 277 | /* The number of .debug_types-related CUs. */ |
330cdd98 | 278 | int n_type_units = 0; |
1fd400ff | 279 | |
6aa5f3a6 DE |
280 | /* The number of elements allocated in all_type_units. |
281 | If there are skeleton-less TUs, we add them to all_type_units lazily. */ | |
330cdd98 | 282 | int n_allocated_type_units = 0; |
6aa5f3a6 | 283 | |
a2ce51a0 DE |
284 | /* The .debug_types-related CUs (TUs). |
285 | This is stored in malloc space because we may realloc it. */ | |
330cdd98 | 286 | struct signatured_type **all_type_units = NULL; |
1fd400ff | 287 | |
f4dc4d17 DE |
288 | /* Table of struct type_unit_group objects. |
289 | The hash key is the DW_AT_stmt_list value. */ | |
330cdd98 | 290 | htab_t type_unit_groups {}; |
72dca2f5 | 291 | |
348e048f DE |
292 | /* A table mapping .debug_types signatures to its signatured_type entry. |
293 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
330cdd98 | 294 | htab_t signatured_types {}; |
348e048f | 295 | |
f4dc4d17 DE |
296 | /* Type unit statistics, to see how well the scaling improvements |
297 | are doing. */ | |
330cdd98 | 298 | struct tu_stats tu_stats {}; |
f4dc4d17 DE |
299 | |
300 | /* A chain of compilation units that are currently read in, so that | |
301 | they can be freed later. */ | |
330cdd98 | 302 | dwarf2_per_cu_data *read_in_chain = NULL; |
f4dc4d17 | 303 | |
3019eac3 DE |
304 | /* A table mapping DW_AT_dwo_name values to struct dwo_file objects. |
305 | This is NULL if the table hasn't been allocated yet. */ | |
330cdd98 | 306 | htab_t dwo_files {}; |
3019eac3 | 307 | |
330cdd98 PA |
308 | /* True if we've checked for whether there is a DWP file. */ |
309 | bool dwp_checked = false; | |
80626a55 DE |
310 | |
311 | /* The DWP file if there is one, or NULL. */ | |
330cdd98 | 312 | struct dwp_file *dwp_file = NULL; |
80626a55 | 313 | |
36586728 TT |
314 | /* The shared '.dwz' file, if one exists. This is used when the |
315 | original data was compressed using 'dwz -m'. */ | |
330cdd98 | 316 | struct dwz_file *dwz_file = NULL; |
36586728 | 317 | |
330cdd98 | 318 | /* A flag indicating whether this objfile has a section loaded at a |
72dca2f5 | 319 | VMA of 0. */ |
330cdd98 | 320 | bool has_section_at_zero = false; |
9291a0cd | 321 | |
ae2de4f8 DE |
322 | /* True if we are using the mapped index, |
323 | or we are faking it for OBJF_READNOW's sake. */ | |
330cdd98 | 324 | bool using_index = false; |
9291a0cd | 325 | |
ae2de4f8 | 326 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
330cdd98 | 327 | mapped_index *index_table = NULL; |
98bfdba5 | 328 | |
7b9f3c50 | 329 | /* When using index_table, this keeps track of all quick_file_names entries. |
56e64610 DE |
330 | TUs typically share line table entries with a CU, so we maintain a |
331 | separate table of all line table entries to support the sharing. | |
332 | Note that while there can be way more TUs than CUs, we've already | |
333 | sorted all the TUs into "type unit groups", grouped by their | |
334 | DW_AT_stmt_list value. Therefore the only sharing done here is with a | |
335 | CU and its associated TU group if there is one. */ | |
330cdd98 | 336 | htab_t quick_file_names_table {}; |
7b9f3c50 | 337 | |
98bfdba5 PA |
338 | /* Set during partial symbol reading, to prevent queueing of full |
339 | symbols. */ | |
330cdd98 | 340 | bool reading_partial_symbols = false; |
673bfd45 | 341 | |
dee91e82 | 342 | /* Table mapping type DIEs to their struct type *. |
673bfd45 | 343 | This is NULL if not allocated yet. |
02142a6c | 344 | The mapping is done via (CU/TU + DIE offset) -> type. */ |
330cdd98 | 345 | htab_t die_type_hash {}; |
95554aad TT |
346 | |
347 | /* The CUs we recently read. */ | |
330cdd98 | 348 | VEC (dwarf2_per_cu_ptr) *just_read_cus = NULL; |
527f3840 JK |
349 | |
350 | /* Table containing line_header indexed by offset and offset_in_dwz. */ | |
330cdd98 | 351 | htab_t line_header_hash {}; |
bbf2f4df PA |
352 | |
353 | /* Table containing all filenames. This is an optional because the | |
354 | table is lazily constructed on first access. */ | |
355 | gdb::optional<filename_seen_cache> filenames_cache; | |
6502dd73 DJ |
356 | }; |
357 | ||
358 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 359 | |
251d32d9 | 360 | /* Default names of the debugging sections. */ |
c906108c | 361 | |
233a11ab CS |
362 | /* Note that if the debugging section has been compressed, it might |
363 | have a name like .zdebug_info. */ | |
364 | ||
9cdd5dbd DE |
365 | static const struct dwarf2_debug_sections dwarf2_elf_names = |
366 | { | |
251d32d9 TG |
367 | { ".debug_info", ".zdebug_info" }, |
368 | { ".debug_abbrev", ".zdebug_abbrev" }, | |
369 | { ".debug_line", ".zdebug_line" }, | |
370 | { ".debug_loc", ".zdebug_loc" }, | |
43988095 | 371 | { ".debug_loclists", ".zdebug_loclists" }, |
251d32d9 | 372 | { ".debug_macinfo", ".zdebug_macinfo" }, |
cf2c3c16 | 373 | { ".debug_macro", ".zdebug_macro" }, |
251d32d9 | 374 | { ".debug_str", ".zdebug_str" }, |
43988095 | 375 | { ".debug_line_str", ".zdebug_line_str" }, |
251d32d9 | 376 | { ".debug_ranges", ".zdebug_ranges" }, |
43988095 | 377 | { ".debug_rnglists", ".zdebug_rnglists" }, |
251d32d9 | 378 | { ".debug_types", ".zdebug_types" }, |
3019eac3 | 379 | { ".debug_addr", ".zdebug_addr" }, |
251d32d9 TG |
380 | { ".debug_frame", ".zdebug_frame" }, |
381 | { ".eh_frame", NULL }, | |
24d3216f TT |
382 | { ".gdb_index", ".zgdb_index" }, |
383 | 23 | |
251d32d9 | 384 | }; |
c906108c | 385 | |
80626a55 | 386 | /* List of DWO/DWP sections. */ |
3019eac3 | 387 | |
80626a55 | 388 | static const struct dwop_section_names |
3019eac3 DE |
389 | { |
390 | struct dwarf2_section_names abbrev_dwo; | |
391 | struct dwarf2_section_names info_dwo; | |
392 | struct dwarf2_section_names line_dwo; | |
393 | struct dwarf2_section_names loc_dwo; | |
43988095 | 394 | struct dwarf2_section_names loclists_dwo; |
09262596 DE |
395 | struct dwarf2_section_names macinfo_dwo; |
396 | struct dwarf2_section_names macro_dwo; | |
3019eac3 DE |
397 | struct dwarf2_section_names str_dwo; |
398 | struct dwarf2_section_names str_offsets_dwo; | |
399 | struct dwarf2_section_names types_dwo; | |
80626a55 DE |
400 | struct dwarf2_section_names cu_index; |
401 | struct dwarf2_section_names tu_index; | |
3019eac3 | 402 | } |
80626a55 | 403 | dwop_section_names = |
3019eac3 DE |
404 | { |
405 | { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" }, | |
406 | { ".debug_info.dwo", ".zdebug_info.dwo" }, | |
407 | { ".debug_line.dwo", ".zdebug_line.dwo" }, | |
408 | { ".debug_loc.dwo", ".zdebug_loc.dwo" }, | |
43988095 | 409 | { ".debug_loclists.dwo", ".zdebug_loclists.dwo" }, |
09262596 DE |
410 | { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" }, |
411 | { ".debug_macro.dwo", ".zdebug_macro.dwo" }, | |
3019eac3 DE |
412 | { ".debug_str.dwo", ".zdebug_str.dwo" }, |
413 | { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" }, | |
414 | { ".debug_types.dwo", ".zdebug_types.dwo" }, | |
80626a55 DE |
415 | { ".debug_cu_index", ".zdebug_cu_index" }, |
416 | { ".debug_tu_index", ".zdebug_tu_index" }, | |
3019eac3 DE |
417 | }; |
418 | ||
c906108c SS |
419 | /* local data types */ |
420 | ||
107d2387 AC |
421 | /* The data in a compilation unit header, after target2host |
422 | translation, looks like this. */ | |
c906108c | 423 | struct comp_unit_head |
a738430d | 424 | { |
c764a876 | 425 | unsigned int length; |
a738430d | 426 | short version; |
a738430d MK |
427 | unsigned char addr_size; |
428 | unsigned char signed_addr_p; | |
9c541725 | 429 | sect_offset abbrev_sect_off; |
57349743 | 430 | |
a738430d MK |
431 | /* Size of file offsets; either 4 or 8. */ |
432 | unsigned int offset_size; | |
57349743 | 433 | |
a738430d MK |
434 | /* Size of the length field; either 4 or 12. */ |
435 | unsigned int initial_length_size; | |
57349743 | 436 | |
43988095 JK |
437 | enum dwarf_unit_type unit_type; |
438 | ||
a738430d MK |
439 | /* Offset to the first byte of this compilation unit header in the |
440 | .debug_info section, for resolving relative reference dies. */ | |
9c541725 | 441 | sect_offset sect_off; |
57349743 | 442 | |
d00adf39 DE |
443 | /* Offset to first die in this cu from the start of the cu. |
444 | This will be the first byte following the compilation unit header. */ | |
9c541725 | 445 | cu_offset first_die_cu_offset; |
43988095 JK |
446 | |
447 | /* 64-bit signature of this type unit - it is valid only for | |
448 | UNIT_TYPE DW_UT_type. */ | |
449 | ULONGEST signature; | |
450 | ||
451 | /* For types, offset in the type's DIE of the type defined by this TU. */ | |
9c541725 | 452 | cu_offset type_cu_offset_in_tu; |
a738430d | 453 | }; |
c906108c | 454 | |
3da10d80 KS |
455 | /* Type used for delaying computation of method physnames. |
456 | See comments for compute_delayed_physnames. */ | |
457 | struct delayed_method_info | |
458 | { | |
459 | /* The type to which the method is attached, i.e., its parent class. */ | |
460 | struct type *type; | |
461 | ||
462 | /* The index of the method in the type's function fieldlists. */ | |
463 | int fnfield_index; | |
464 | ||
465 | /* The index of the method in the fieldlist. */ | |
466 | int index; | |
467 | ||
468 | /* The name of the DIE. */ | |
469 | const char *name; | |
470 | ||
471 | /* The DIE associated with this method. */ | |
472 | struct die_info *die; | |
473 | }; | |
474 | ||
475 | typedef struct delayed_method_info delayed_method_info; | |
476 | DEF_VEC_O (delayed_method_info); | |
477 | ||
e7c27a73 DJ |
478 | /* Internal state when decoding a particular compilation unit. */ |
479 | struct dwarf2_cu | |
480 | { | |
481 | /* The objfile containing this compilation unit. */ | |
482 | struct objfile *objfile; | |
483 | ||
d00adf39 | 484 | /* The header of the compilation unit. */ |
e7c27a73 | 485 | struct comp_unit_head header; |
e142c38c | 486 | |
d00adf39 DE |
487 | /* Base address of this compilation unit. */ |
488 | CORE_ADDR base_address; | |
489 | ||
490 | /* Non-zero if base_address has been set. */ | |
491 | int base_known; | |
492 | ||
e142c38c DJ |
493 | /* The language we are debugging. */ |
494 | enum language language; | |
495 | const struct language_defn *language_defn; | |
496 | ||
b0f35d58 DL |
497 | const char *producer; |
498 | ||
e142c38c DJ |
499 | /* The generic symbol table building routines have separate lists for |
500 | file scope symbols and all all other scopes (local scopes). So | |
501 | we need to select the right one to pass to add_symbol_to_list(). | |
502 | We do it by keeping a pointer to the correct list in list_in_scope. | |
503 | ||
504 | FIXME: The original dwarf code just treated the file scope as the | |
505 | first local scope, and all other local scopes as nested local | |
506 | scopes, and worked fine. Check to see if we really need to | |
507 | distinguish these in buildsym.c. */ | |
508 | struct pending **list_in_scope; | |
509 | ||
433df2d4 DE |
510 | /* The abbrev table for this CU. |
511 | Normally this points to the abbrev table in the objfile. | |
512 | But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */ | |
513 | struct abbrev_table *abbrev_table; | |
72bf9492 | 514 | |
b64f50a1 JK |
515 | /* Hash table holding all the loaded partial DIEs |
516 | with partial_die->offset.SECT_OFF as hash. */ | |
72bf9492 DJ |
517 | htab_t partial_dies; |
518 | ||
519 | /* Storage for things with the same lifetime as this read-in compilation | |
520 | unit, including partial DIEs. */ | |
521 | struct obstack comp_unit_obstack; | |
522 | ||
ae038cb0 DJ |
523 | /* When multiple dwarf2_cu structures are living in memory, this field |
524 | chains them all together, so that they can be released efficiently. | |
525 | We will probably also want a generation counter so that most-recently-used | |
526 | compilation units are cached... */ | |
527 | struct dwarf2_per_cu_data *read_in_chain; | |
528 | ||
69d751e3 | 529 | /* Backlink to our per_cu entry. */ |
ae038cb0 DJ |
530 | struct dwarf2_per_cu_data *per_cu; |
531 | ||
532 | /* How many compilation units ago was this CU last referenced? */ | |
533 | int last_used; | |
534 | ||
b64f50a1 JK |
535 | /* A hash table of DIE cu_offset for following references with |
536 | die_info->offset.sect_off as hash. */ | |
51545339 | 537 | htab_t die_hash; |
10b3939b DJ |
538 | |
539 | /* Full DIEs if read in. */ | |
540 | struct die_info *dies; | |
541 | ||
542 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
543 | units referenced by this one. Only set during full symbol processing; | |
544 | partial symbol tables do not have dependencies. */ | |
545 | htab_t dependencies; | |
546 | ||
cb1df416 DJ |
547 | /* Header data from the line table, during full symbol processing. */ |
548 | struct line_header *line_header; | |
549 | ||
3da10d80 KS |
550 | /* A list of methods which need to have physnames computed |
551 | after all type information has been read. */ | |
552 | VEC (delayed_method_info) *method_list; | |
553 | ||
96408a79 SA |
554 | /* To be copied to symtab->call_site_htab. */ |
555 | htab_t call_site_htab; | |
556 | ||
034e5797 DE |
557 | /* Non-NULL if this CU came from a DWO file. |
558 | There is an invariant here that is important to remember: | |
559 | Except for attributes copied from the top level DIE in the "main" | |
560 | (or "stub") file in preparation for reading the DWO file | |
561 | (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU. | |
562 | Either there isn't a DWO file (in which case this is NULL and the point | |
563 | is moot), or there is and either we're not going to read it (in which | |
564 | case this is NULL) or there is and we are reading it (in which case this | |
565 | is non-NULL). */ | |
3019eac3 DE |
566 | struct dwo_unit *dwo_unit; |
567 | ||
568 | /* The DW_AT_addr_base attribute if present, zero otherwise | |
569 | (zero is a valid value though). | |
1dbab08b | 570 | Note this value comes from the Fission stub CU/TU's DIE. */ |
3019eac3 DE |
571 | ULONGEST addr_base; |
572 | ||
2e3cf129 DE |
573 | /* The DW_AT_ranges_base attribute if present, zero otherwise |
574 | (zero is a valid value though). | |
1dbab08b | 575 | Note this value comes from the Fission stub CU/TU's DIE. |
2e3cf129 | 576 | Also note that the value is zero in the non-DWO case so this value can |
ab435259 DE |
577 | be used without needing to know whether DWO files are in use or not. |
578 | N.B. This does not apply to DW_AT_ranges appearing in | |
579 | DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever | |
580 | DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then | |
581 | DW_AT_ranges_base *would* have to be applied, and we'd have to care | |
582 | whether the DW_AT_ranges attribute came from the skeleton or DWO. */ | |
2e3cf129 DE |
583 | ULONGEST ranges_base; |
584 | ||
ae038cb0 DJ |
585 | /* Mark used when releasing cached dies. */ |
586 | unsigned int mark : 1; | |
587 | ||
8be455d7 JK |
588 | /* This CU references .debug_loc. See the symtab->locations_valid field. |
589 | This test is imperfect as there may exist optimized debug code not using | |
590 | any location list and still facing inlining issues if handled as | |
591 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
8be455d7 | 592 | unsigned int has_loclist : 1; |
ba919b58 | 593 | |
1b80a9fa JK |
594 | /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set |
595 | if all the producer_is_* fields are valid. This information is cached | |
596 | because profiling CU expansion showed excessive time spent in | |
597 | producer_is_gxx_lt_4_6. */ | |
ba919b58 TT |
598 | unsigned int checked_producer : 1; |
599 | unsigned int producer_is_gxx_lt_4_6 : 1; | |
1b80a9fa | 600 | unsigned int producer_is_gcc_lt_4_3 : 1; |
685b1105 | 601 | unsigned int producer_is_icc : 1; |
4d4ec4e5 TT |
602 | |
603 | /* When set, the file that we're processing is known to have | |
604 | debugging info for C++ namespaces. GCC 3.3.x did not produce | |
605 | this information, but later versions do. */ | |
606 | ||
607 | unsigned int processing_has_namespace_info : 1; | |
e7c27a73 DJ |
608 | }; |
609 | ||
10b3939b DJ |
610 | /* Persistent data held for a compilation unit, even when not |
611 | processing it. We put a pointer to this structure in the | |
28dee7f5 | 612 | read_symtab_private field of the psymtab. */ |
10b3939b | 613 | |
ae038cb0 DJ |
614 | struct dwarf2_per_cu_data |
615 | { | |
36586728 | 616 | /* The start offset and length of this compilation unit. |
45452591 | 617 | NOTE: Unlike comp_unit_head.length, this length includes |
3019eac3 DE |
618 | initial_length_size. |
619 | If the DIE refers to a DWO file, this is always of the original die, | |
620 | not the DWO file. */ | |
9c541725 | 621 | sect_offset sect_off; |
36586728 | 622 | unsigned int length; |
ae038cb0 | 623 | |
43988095 JK |
624 | /* DWARF standard version this data has been read from (such as 4 or 5). */ |
625 | short dwarf_version; | |
626 | ||
ae038cb0 DJ |
627 | /* Flag indicating this compilation unit will be read in before |
628 | any of the current compilation units are processed. */ | |
c764a876 | 629 | unsigned int queued : 1; |
ae038cb0 | 630 | |
0d99eb77 DE |
631 | /* This flag will be set when reading partial DIEs if we need to load |
632 | absolutely all DIEs for this compilation unit, instead of just the ones | |
633 | we think are interesting. It gets set if we look for a DIE in the | |
5afb4e99 DJ |
634 | hash table and don't find it. */ |
635 | unsigned int load_all_dies : 1; | |
636 | ||
0186c6a7 DE |
637 | /* Non-zero if this CU is from .debug_types. |
638 | Struct dwarf2_per_cu_data is contained in struct signatured_type iff | |
639 | this is non-zero. */ | |
3019eac3 DE |
640 | unsigned int is_debug_types : 1; |
641 | ||
36586728 TT |
642 | /* Non-zero if this CU is from the .dwz file. */ |
643 | unsigned int is_dwz : 1; | |
644 | ||
a2ce51a0 DE |
645 | /* Non-zero if reading a TU directly from a DWO file, bypassing the stub. |
646 | This flag is only valid if is_debug_types is true. | |
647 | We can't read a CU directly from a DWO file: There are required | |
648 | attributes in the stub. */ | |
649 | unsigned int reading_dwo_directly : 1; | |
650 | ||
7ee85ab1 DE |
651 | /* Non-zero if the TU has been read. |
652 | This is used to assist the "Stay in DWO Optimization" for Fission: | |
653 | When reading a DWO, it's faster to read TUs from the DWO instead of | |
654 | fetching them from random other DWOs (due to comdat folding). | |
655 | If the TU has already been read, the optimization is unnecessary | |
656 | (and unwise - we don't want to change where gdb thinks the TU lives | |
657 | "midflight"). | |
658 | This flag is only valid if is_debug_types is true. */ | |
659 | unsigned int tu_read : 1; | |
660 | ||
3019eac3 DE |
661 | /* The section this CU/TU lives in. |
662 | If the DIE refers to a DWO file, this is always the original die, | |
663 | not the DWO file. */ | |
8a0459fd | 664 | struct dwarf2_section_info *section; |
348e048f | 665 | |
17ea53c3 | 666 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
cc12ce38 DE |
667 | of the CU cache it gets reset to NULL again. This is left as NULL for |
668 | dummy CUs (a CU header, but nothing else). */ | |
ae038cb0 | 669 | struct dwarf2_cu *cu; |
1c379e20 | 670 | |
9cdd5dbd DE |
671 | /* The corresponding objfile. |
672 | Normally we can get the objfile from dwarf2_per_objfile. | |
673 | However we can enter this file with just a "per_cu" handle. */ | |
9291a0cd TT |
674 | struct objfile *objfile; |
675 | ||
fffbe6a8 YQ |
676 | /* When dwarf2_per_objfile->using_index is true, the 'quick' field |
677 | is active. Otherwise, the 'psymtab' field is active. */ | |
9291a0cd TT |
678 | union |
679 | { | |
680 | /* The partial symbol table associated with this compilation unit, | |
95554aad | 681 | or NULL for unread partial units. */ |
9291a0cd TT |
682 | struct partial_symtab *psymtab; |
683 | ||
684 | /* Data needed by the "quick" functions. */ | |
685 | struct dwarf2_per_cu_quick_data *quick; | |
686 | } v; | |
95554aad | 687 | |
796a7ff8 DE |
688 | /* The CUs we import using DW_TAG_imported_unit. This is filled in |
689 | while reading psymtabs, used to compute the psymtab dependencies, | |
690 | and then cleared. Then it is filled in again while reading full | |
691 | symbols, and only deleted when the objfile is destroyed. | |
692 | ||
693 | This is also used to work around a difference between the way gold | |
694 | generates .gdb_index version <=7 and the way gdb does. Arguably this | |
695 | is a gold bug. For symbols coming from TUs, gold records in the index | |
696 | the CU that includes the TU instead of the TU itself. This breaks | |
697 | dw2_lookup_symbol: It assumes that if the index says symbol X lives | |
698 | in CU/TU Y, then one need only expand Y and a subsequent lookup in Y | |
699 | will find X. Alas TUs live in their own symtab, so after expanding CU Y | |
700 | we need to look in TU Z to find X. Fortunately, this is akin to | |
701 | DW_TAG_imported_unit, so we just use the same mechanism: For | |
702 | .gdb_index version <=7 this also records the TUs that the CU referred | |
703 | to. Concurrently with this change gdb was modified to emit version 8 | |
69d751e3 DE |
704 | indices so we only pay a price for gold generated indices. |
705 | http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */ | |
796a7ff8 | 706 | VEC (dwarf2_per_cu_ptr) *imported_symtabs; |
ae038cb0 DJ |
707 | }; |
708 | ||
348e048f DE |
709 | /* Entry in the signatured_types hash table. */ |
710 | ||
711 | struct signatured_type | |
712 | { | |
42e7ad6c | 713 | /* The "per_cu" object of this type. |
ac9ec31b | 714 | This struct is used iff per_cu.is_debug_types. |
42e7ad6c DE |
715 | N.B.: This is the first member so that it's easy to convert pointers |
716 | between them. */ | |
717 | struct dwarf2_per_cu_data per_cu; | |
718 | ||
3019eac3 | 719 | /* The type's signature. */ |
348e048f DE |
720 | ULONGEST signature; |
721 | ||
3019eac3 | 722 | /* Offset in the TU of the type's DIE, as read from the TU header. |
c88ee1f0 DE |
723 | If this TU is a DWO stub and the definition lives in a DWO file |
724 | (specified by DW_AT_GNU_dwo_name), this value is unusable. */ | |
3019eac3 DE |
725 | cu_offset type_offset_in_tu; |
726 | ||
727 | /* Offset in the section of the type's DIE. | |
728 | If the definition lives in a DWO file, this is the offset in the | |
729 | .debug_types.dwo section. | |
730 | The value is zero until the actual value is known. | |
731 | Zero is otherwise not a valid section offset. */ | |
732 | sect_offset type_offset_in_section; | |
0186c6a7 DE |
733 | |
734 | /* Type units are grouped by their DW_AT_stmt_list entry so that they | |
735 | can share them. This points to the containing symtab. */ | |
736 | struct type_unit_group *type_unit_group; | |
ac9ec31b DE |
737 | |
738 | /* The type. | |
739 | The first time we encounter this type we fully read it in and install it | |
740 | in the symbol tables. Subsequent times we only need the type. */ | |
741 | struct type *type; | |
a2ce51a0 DE |
742 | |
743 | /* Containing DWO unit. | |
744 | This field is valid iff per_cu.reading_dwo_directly. */ | |
745 | struct dwo_unit *dwo_unit; | |
348e048f DE |
746 | }; |
747 | ||
0186c6a7 DE |
748 | typedef struct signatured_type *sig_type_ptr; |
749 | DEF_VEC_P (sig_type_ptr); | |
750 | ||
094b34ac DE |
751 | /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list. |
752 | This includes type_unit_group and quick_file_names. */ | |
753 | ||
754 | struct stmt_list_hash | |
755 | { | |
756 | /* The DWO unit this table is from or NULL if there is none. */ | |
757 | struct dwo_unit *dwo_unit; | |
758 | ||
759 | /* Offset in .debug_line or .debug_line.dwo. */ | |
9c541725 | 760 | sect_offset line_sect_off; |
094b34ac DE |
761 | }; |
762 | ||
f4dc4d17 DE |
763 | /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to |
764 | an object of this type. */ | |
765 | ||
766 | struct type_unit_group | |
767 | { | |
0186c6a7 | 768 | /* dwarf2read.c's main "handle" on a TU symtab. |
f4dc4d17 DE |
769 | To simplify things we create an artificial CU that "includes" all the |
770 | type units using this stmt_list so that the rest of the code still has | |
771 | a "per_cu" handle on the symtab. | |
772 | This PER_CU is recognized by having no section. */ | |
8a0459fd | 773 | #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL) |
094b34ac DE |
774 | struct dwarf2_per_cu_data per_cu; |
775 | ||
0186c6a7 DE |
776 | /* The TUs that share this DW_AT_stmt_list entry. |
777 | This is added to while parsing type units to build partial symtabs, | |
778 | and is deleted afterwards and not used again. */ | |
779 | VEC (sig_type_ptr) *tus; | |
f4dc4d17 | 780 | |
43f3e411 | 781 | /* The compunit symtab. |
094b34ac | 782 | Type units in a group needn't all be defined in the same source file, |
43f3e411 DE |
783 | so we create an essentially anonymous symtab as the compunit symtab. */ |
784 | struct compunit_symtab *compunit_symtab; | |
f4dc4d17 | 785 | |
094b34ac DE |
786 | /* The data used to construct the hash key. */ |
787 | struct stmt_list_hash hash; | |
f4dc4d17 DE |
788 | |
789 | /* The number of symtabs from the line header. | |
790 | The value here must match line_header.num_file_names. */ | |
791 | unsigned int num_symtabs; | |
792 | ||
793 | /* The symbol tables for this TU (obtained from the files listed in | |
794 | DW_AT_stmt_list). | |
795 | WARNING: The order of entries here must match the order of entries | |
796 | in the line header. After the first TU using this type_unit_group, the | |
797 | line header for the subsequent TUs is recreated from this. This is done | |
798 | because we need to use the same symtabs for each TU using the same | |
799 | DW_AT_stmt_list value. Also note that symtabs may be repeated here, | |
800 | there's no guarantee the line header doesn't have duplicate entries. */ | |
801 | struct symtab **symtabs; | |
802 | }; | |
803 | ||
73869dc2 | 804 | /* These sections are what may appear in a (real or virtual) DWO file. */ |
3019eac3 DE |
805 | |
806 | struct dwo_sections | |
807 | { | |
808 | struct dwarf2_section_info abbrev; | |
3019eac3 DE |
809 | struct dwarf2_section_info line; |
810 | struct dwarf2_section_info loc; | |
43988095 | 811 | struct dwarf2_section_info loclists; |
09262596 DE |
812 | struct dwarf2_section_info macinfo; |
813 | struct dwarf2_section_info macro; | |
3019eac3 DE |
814 | struct dwarf2_section_info str; |
815 | struct dwarf2_section_info str_offsets; | |
80626a55 DE |
816 | /* In the case of a virtual DWO file, these two are unused. */ |
817 | struct dwarf2_section_info info; | |
3019eac3 DE |
818 | VEC (dwarf2_section_info_def) *types; |
819 | }; | |
820 | ||
c88ee1f0 | 821 | /* CUs/TUs in DWP/DWO files. */ |
3019eac3 DE |
822 | |
823 | struct dwo_unit | |
824 | { | |
825 | /* Backlink to the containing struct dwo_file. */ | |
826 | struct dwo_file *dwo_file; | |
827 | ||
828 | /* The "id" that distinguishes this CU/TU. | |
829 | .debug_info calls this "dwo_id", .debug_types calls this "signature". | |
830 | Since signatures came first, we stick with it for consistency. */ | |
831 | ULONGEST signature; | |
832 | ||
833 | /* The section this CU/TU lives in, in the DWO file. */ | |
8a0459fd | 834 | struct dwarf2_section_info *section; |
3019eac3 | 835 | |
9c541725 PA |
836 | /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */ |
837 | sect_offset sect_off; | |
3019eac3 DE |
838 | unsigned int length; |
839 | ||
840 | /* For types, offset in the type's DIE of the type defined by this TU. */ | |
841 | cu_offset type_offset_in_tu; | |
842 | }; | |
843 | ||
73869dc2 DE |
844 | /* include/dwarf2.h defines the DWP section codes. |
845 | It defines a max value but it doesn't define a min value, which we | |
846 | use for error checking, so provide one. */ | |
847 | ||
848 | enum dwp_v2_section_ids | |
849 | { | |
850 | DW_SECT_MIN = 1 | |
851 | }; | |
852 | ||
80626a55 | 853 | /* Data for one DWO file. |
57d63ce2 DE |
854 | |
855 | This includes virtual DWO files (a virtual DWO file is a DWO file as it | |
856 | appears in a DWP file). DWP files don't really have DWO files per se - | |
857 | comdat folding of types "loses" the DWO file they came from, and from | |
858 | a high level view DWP files appear to contain a mass of random types. | |
859 | However, to maintain consistency with the non-DWP case we pretend DWP | |
860 | files contain virtual DWO files, and we assign each TU with one virtual | |
861 | DWO file (generally based on the line and abbrev section offsets - | |
862 | a heuristic that seems to work in practice). */ | |
3019eac3 DE |
863 | |
864 | struct dwo_file | |
865 | { | |
0ac5b59e | 866 | /* The DW_AT_GNU_dwo_name attribute. |
80626a55 DE |
867 | For virtual DWO files the name is constructed from the section offsets |
868 | of abbrev,line,loc,str_offsets so that we combine virtual DWO files | |
869 | from related CU+TUs. */ | |
0ac5b59e DE |
870 | const char *dwo_name; |
871 | ||
872 | /* The DW_AT_comp_dir attribute. */ | |
873 | const char *comp_dir; | |
3019eac3 | 874 | |
80626a55 DE |
875 | /* The bfd, when the file is open. Otherwise this is NULL. |
876 | This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */ | |
877 | bfd *dbfd; | |
3019eac3 | 878 | |
73869dc2 DE |
879 | /* The sections that make up this DWO file. |
880 | Remember that for virtual DWO files in DWP V2, these are virtual | |
881 | sections (for lack of a better name). */ | |
3019eac3 DE |
882 | struct dwo_sections sections; |
883 | ||
33c5cd75 DB |
884 | /* The CUs in the file. |
885 | Each element is a struct dwo_unit. Multiple CUs per DWO are supported as | |
886 | an extension to handle LLVM's Link Time Optimization output (where | |
887 | multiple source files may be compiled into a single object/dwo pair). */ | |
888 | htab_t cus; | |
3019eac3 DE |
889 | |
890 | /* Table of TUs in the file. | |
891 | Each element is a struct dwo_unit. */ | |
892 | htab_t tus; | |
893 | }; | |
894 | ||
80626a55 DE |
895 | /* These sections are what may appear in a DWP file. */ |
896 | ||
897 | struct dwp_sections | |
898 | { | |
73869dc2 | 899 | /* These are used by both DWP version 1 and 2. */ |
80626a55 DE |
900 | struct dwarf2_section_info str; |
901 | struct dwarf2_section_info cu_index; | |
902 | struct dwarf2_section_info tu_index; | |
73869dc2 DE |
903 | |
904 | /* These are only used by DWP version 2 files. | |
905 | In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other | |
906 | sections are referenced by section number, and are not recorded here. | |
907 | In DWP version 2 there is at most one copy of all these sections, each | |
908 | section being (effectively) comprised of the concatenation of all of the | |
909 | individual sections that exist in the version 1 format. | |
910 | To keep the code simple we treat each of these concatenated pieces as a | |
911 | section itself (a virtual section?). */ | |
912 | struct dwarf2_section_info abbrev; | |
913 | struct dwarf2_section_info info; | |
914 | struct dwarf2_section_info line; | |
915 | struct dwarf2_section_info loc; | |
916 | struct dwarf2_section_info macinfo; | |
917 | struct dwarf2_section_info macro; | |
918 | struct dwarf2_section_info str_offsets; | |
919 | struct dwarf2_section_info types; | |
80626a55 DE |
920 | }; |
921 | ||
73869dc2 DE |
922 | /* These sections are what may appear in a virtual DWO file in DWP version 1. |
923 | A virtual DWO file is a DWO file as it appears in a DWP file. */ | |
80626a55 | 924 | |
73869dc2 | 925 | struct virtual_v1_dwo_sections |
80626a55 DE |
926 | { |
927 | struct dwarf2_section_info abbrev; | |
928 | struct dwarf2_section_info line; | |
929 | struct dwarf2_section_info loc; | |
930 | struct dwarf2_section_info macinfo; | |
931 | struct dwarf2_section_info macro; | |
932 | struct dwarf2_section_info str_offsets; | |
933 | /* Each DWP hash table entry records one CU or one TU. | |
8a0459fd | 934 | That is recorded here, and copied to dwo_unit.section. */ |
80626a55 DE |
935 | struct dwarf2_section_info info_or_types; |
936 | }; | |
937 | ||
73869dc2 DE |
938 | /* Similar to virtual_v1_dwo_sections, but for DWP version 2. |
939 | In version 2, the sections of the DWO files are concatenated together | |
940 | and stored in one section of that name. Thus each ELF section contains | |
941 | several "virtual" sections. */ | |
942 | ||
943 | struct virtual_v2_dwo_sections | |
944 | { | |
945 | bfd_size_type abbrev_offset; | |
946 | bfd_size_type abbrev_size; | |
947 | ||
948 | bfd_size_type line_offset; | |
949 | bfd_size_type line_size; | |
950 | ||
951 | bfd_size_type loc_offset; | |
952 | bfd_size_type loc_size; | |
953 | ||
954 | bfd_size_type macinfo_offset; | |
955 | bfd_size_type macinfo_size; | |
956 | ||
957 | bfd_size_type macro_offset; | |
958 | bfd_size_type macro_size; | |
959 | ||
960 | bfd_size_type str_offsets_offset; | |
961 | bfd_size_type str_offsets_size; | |
962 | ||
963 | /* Each DWP hash table entry records one CU or one TU. | |
964 | That is recorded here, and copied to dwo_unit.section. */ | |
965 | bfd_size_type info_or_types_offset; | |
966 | bfd_size_type info_or_types_size; | |
967 | }; | |
968 | ||
80626a55 DE |
969 | /* Contents of DWP hash tables. */ |
970 | ||
971 | struct dwp_hash_table | |
972 | { | |
73869dc2 | 973 | uint32_t version, nr_columns; |
80626a55 | 974 | uint32_t nr_units, nr_slots; |
73869dc2 DE |
975 | const gdb_byte *hash_table, *unit_table; |
976 | union | |
977 | { | |
978 | struct | |
979 | { | |
980 | const gdb_byte *indices; | |
981 | } v1; | |
982 | struct | |
983 | { | |
984 | /* This is indexed by column number and gives the id of the section | |
985 | in that column. */ | |
986 | #define MAX_NR_V2_DWO_SECTIONS \ | |
987 | (1 /* .debug_info or .debug_types */ \ | |
988 | + 1 /* .debug_abbrev */ \ | |
989 | + 1 /* .debug_line */ \ | |
990 | + 1 /* .debug_loc */ \ | |
991 | + 1 /* .debug_str_offsets */ \ | |
992 | + 1 /* .debug_macro or .debug_macinfo */) | |
993 | int section_ids[MAX_NR_V2_DWO_SECTIONS]; | |
994 | const gdb_byte *offsets; | |
995 | const gdb_byte *sizes; | |
996 | } v2; | |
997 | } section_pool; | |
80626a55 DE |
998 | }; |
999 | ||
1000 | /* Data for one DWP file. */ | |
1001 | ||
1002 | struct dwp_file | |
1003 | { | |
1004 | /* Name of the file. */ | |
1005 | const char *name; | |
1006 | ||
73869dc2 DE |
1007 | /* File format version. */ |
1008 | int version; | |
1009 | ||
93417882 | 1010 | /* The bfd. */ |
80626a55 DE |
1011 | bfd *dbfd; |
1012 | ||
1013 | /* Section info for this file. */ | |
1014 | struct dwp_sections sections; | |
1015 | ||
57d63ce2 | 1016 | /* Table of CUs in the file. */ |
80626a55 DE |
1017 | const struct dwp_hash_table *cus; |
1018 | ||
1019 | /* Table of TUs in the file. */ | |
1020 | const struct dwp_hash_table *tus; | |
1021 | ||
19ac8c2e DE |
1022 | /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */ |
1023 | htab_t loaded_cus; | |
1024 | htab_t loaded_tus; | |
80626a55 | 1025 | |
73869dc2 DE |
1026 | /* Table to map ELF section numbers to their sections. |
1027 | This is only needed for the DWP V1 file format. */ | |
80626a55 DE |
1028 | unsigned int num_sections; |
1029 | asection **elf_sections; | |
1030 | }; | |
1031 | ||
36586728 TT |
1032 | /* This represents a '.dwz' file. */ |
1033 | ||
1034 | struct dwz_file | |
1035 | { | |
1036 | /* A dwz file can only contain a few sections. */ | |
1037 | struct dwarf2_section_info abbrev; | |
1038 | struct dwarf2_section_info info; | |
1039 | struct dwarf2_section_info str; | |
1040 | struct dwarf2_section_info line; | |
1041 | struct dwarf2_section_info macro; | |
2ec9a5e0 | 1042 | struct dwarf2_section_info gdb_index; |
36586728 TT |
1043 | |
1044 | /* The dwz's BFD. */ | |
1045 | bfd *dwz_bfd; | |
1046 | }; | |
1047 | ||
0963b4bd MS |
1048 | /* Struct used to pass misc. parameters to read_die_and_children, et |
1049 | al. which are used for both .debug_info and .debug_types dies. | |
1050 | All parameters here are unchanging for the life of the call. This | |
dee91e82 | 1051 | struct exists to abstract away the constant parameters of die reading. */ |
93311388 DE |
1052 | |
1053 | struct die_reader_specs | |
1054 | { | |
a32a8923 | 1055 | /* The bfd of die_section. */ |
93311388 DE |
1056 | bfd* abfd; |
1057 | ||
1058 | /* The CU of the DIE we are parsing. */ | |
1059 | struct dwarf2_cu *cu; | |
1060 | ||
80626a55 | 1061 | /* Non-NULL if reading a DWO file (including one packaged into a DWP). */ |
3019eac3 DE |
1062 | struct dwo_file *dwo_file; |
1063 | ||
dee91e82 | 1064 | /* The section the die comes from. |
3019eac3 | 1065 | This is either .debug_info or .debug_types, or the .dwo variants. */ |
dee91e82 DE |
1066 | struct dwarf2_section_info *die_section; |
1067 | ||
1068 | /* die_section->buffer. */ | |
d521ce57 | 1069 | const gdb_byte *buffer; |
f664829e DE |
1070 | |
1071 | /* The end of the buffer. */ | |
1072 | const gdb_byte *buffer_end; | |
a2ce51a0 DE |
1073 | |
1074 | /* The value of the DW_AT_comp_dir attribute. */ | |
1075 | const char *comp_dir; | |
93311388 DE |
1076 | }; |
1077 | ||
fd820528 | 1078 | /* Type of function passed to init_cutu_and_read_dies, et.al. */ |
dee91e82 | 1079 | typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader, |
d521ce57 | 1080 | const gdb_byte *info_ptr, |
dee91e82 DE |
1081 | struct die_info *comp_unit_die, |
1082 | int has_children, | |
1083 | void *data); | |
1084 | ||
ecfb656c PA |
1085 | /* A 1-based directory index. This is a strong typedef to prevent |
1086 | accidentally using a directory index as a 0-based index into an | |
1087 | array/vector. */ | |
1088 | enum class dir_index : unsigned int {}; | |
1089 | ||
1090 | /* Likewise, a 1-based file name index. */ | |
1091 | enum class file_name_index : unsigned int {}; | |
1092 | ||
52059ffd TT |
1093 | struct file_entry |
1094 | { | |
fff8551c PA |
1095 | file_entry () = default; |
1096 | ||
ecfb656c | 1097 | file_entry (const char *name_, dir_index d_index_, |
fff8551c PA |
1098 | unsigned int mod_time_, unsigned int length_) |
1099 | : name (name_), | |
ecfb656c | 1100 | d_index (d_index_), |
fff8551c PA |
1101 | mod_time (mod_time_), |
1102 | length (length_) | |
1103 | {} | |
1104 | ||
ecfb656c PA |
1105 | /* Return the include directory at D_INDEX stored in LH. Returns |
1106 | NULL if D_INDEX is out of bounds. */ | |
8c43009f PA |
1107 | const char *include_dir (const line_header *lh) const; |
1108 | ||
fff8551c PA |
1109 | /* The file name. Note this is an observing pointer. The memory is |
1110 | owned by debug_line_buffer. */ | |
1111 | const char *name {}; | |
1112 | ||
8c43009f | 1113 | /* The directory index (1-based). */ |
ecfb656c | 1114 | dir_index d_index {}; |
fff8551c PA |
1115 | |
1116 | unsigned int mod_time {}; | |
1117 | ||
1118 | unsigned int length {}; | |
1119 | ||
1120 | /* True if referenced by the Line Number Program. */ | |
1121 | bool included_p {}; | |
1122 | ||
83769d0b | 1123 | /* The associated symbol table, if any. */ |
fff8551c | 1124 | struct symtab *symtab {}; |
52059ffd TT |
1125 | }; |
1126 | ||
debd256d JB |
1127 | /* The line number information for a compilation unit (found in the |
1128 | .debug_line section) begins with a "statement program header", | |
1129 | which contains the following information. */ | |
1130 | struct line_header | |
1131 | { | |
fff8551c PA |
1132 | line_header () |
1133 | : offset_in_dwz {} | |
1134 | {} | |
1135 | ||
1136 | /* Add an entry to the include directory table. */ | |
1137 | void add_include_dir (const char *include_dir); | |
1138 | ||
1139 | /* Add an entry to the file name table. */ | |
ecfb656c | 1140 | void add_file_name (const char *name, dir_index d_index, |
fff8551c PA |
1141 | unsigned int mod_time, unsigned int length); |
1142 | ||
ecfb656c | 1143 | /* Return the include dir at INDEX (1-based). Returns NULL if INDEX |
8c43009f | 1144 | is out of bounds. */ |
ecfb656c | 1145 | const char *include_dir_at (dir_index index) const |
8c43009f | 1146 | { |
ecfb656c PA |
1147 | /* Convert directory index number (1-based) to vector index |
1148 | (0-based). */ | |
1149 | size_t vec_index = to_underlying (index) - 1; | |
1150 | ||
1151 | if (vec_index >= include_dirs.size ()) | |
8c43009f | 1152 | return NULL; |
ecfb656c | 1153 | return include_dirs[vec_index]; |
8c43009f PA |
1154 | } |
1155 | ||
ecfb656c | 1156 | /* Return the file name at INDEX (1-based). Returns NULL if INDEX |
8c43009f | 1157 | is out of bounds. */ |
ecfb656c | 1158 | file_entry *file_name_at (file_name_index index) |
8c43009f | 1159 | { |
ecfb656c PA |
1160 | /* Convert file name index number (1-based) to vector index |
1161 | (0-based). */ | |
1162 | size_t vec_index = to_underlying (index) - 1; | |
1163 | ||
1164 | if (vec_index >= file_names.size ()) | |
fff8551c | 1165 | return NULL; |
ecfb656c | 1166 | return &file_names[vec_index]; |
fff8551c PA |
1167 | } |
1168 | ||
1169 | /* Const version of the above. */ | |
1170 | const file_entry *file_name_at (unsigned int index) const | |
1171 | { | |
1172 | if (index >= file_names.size ()) | |
8c43009f PA |
1173 | return NULL; |
1174 | return &file_names[index]; | |
1175 | } | |
1176 | ||
527f3840 | 1177 | /* Offset of line number information in .debug_line section. */ |
9c541725 | 1178 | sect_offset sect_off {}; |
527f3840 JK |
1179 | |
1180 | /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */ | |
fff8551c PA |
1181 | unsigned offset_in_dwz : 1; /* Can't initialize bitfields in-class. */ |
1182 | ||
1183 | unsigned int total_length {}; | |
1184 | unsigned short version {}; | |
1185 | unsigned int header_length {}; | |
1186 | unsigned char minimum_instruction_length {}; | |
1187 | unsigned char maximum_ops_per_instruction {}; | |
1188 | unsigned char default_is_stmt {}; | |
1189 | int line_base {}; | |
1190 | unsigned char line_range {}; | |
1191 | unsigned char opcode_base {}; | |
debd256d JB |
1192 | |
1193 | /* standard_opcode_lengths[i] is the number of operands for the | |
1194 | standard opcode whose value is i. This means that | |
1195 | standard_opcode_lengths[0] is unused, and the last meaningful | |
1196 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
fff8551c | 1197 | std::unique_ptr<unsigned char[]> standard_opcode_lengths; |
debd256d | 1198 | |
fff8551c PA |
1199 | /* The include_directories table. Note these are observing |
1200 | pointers. The memory is owned by debug_line_buffer. */ | |
1201 | std::vector<const char *> include_dirs; | |
debd256d | 1202 | |
fff8551c PA |
1203 | /* The file_names table. */ |
1204 | std::vector<file_entry> file_names; | |
debd256d JB |
1205 | |
1206 | /* The start and end of the statement program following this | |
6502dd73 | 1207 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fff8551c | 1208 | const gdb_byte *statement_program_start {}, *statement_program_end {}; |
debd256d | 1209 | }; |
c906108c | 1210 | |
fff8551c PA |
1211 | typedef std::unique_ptr<line_header> line_header_up; |
1212 | ||
8c43009f PA |
1213 | const char * |
1214 | file_entry::include_dir (const line_header *lh) const | |
1215 | { | |
ecfb656c | 1216 | return lh->include_dir_at (d_index); |
8c43009f PA |
1217 | } |
1218 | ||
c906108c | 1219 | /* When we construct a partial symbol table entry we only |
0963b4bd | 1220 | need this much information. */ |
c906108c SS |
1221 | struct partial_die_info |
1222 | { | |
72bf9492 | 1223 | /* Offset of this DIE. */ |
9c541725 | 1224 | sect_offset sect_off; |
72bf9492 DJ |
1225 | |
1226 | /* DWARF-2 tag for this DIE. */ | |
1227 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
1228 | ||
72bf9492 DJ |
1229 | /* Assorted flags describing the data found in this DIE. */ |
1230 | unsigned int has_children : 1; | |
1231 | unsigned int is_external : 1; | |
1232 | unsigned int is_declaration : 1; | |
1233 | unsigned int has_type : 1; | |
1234 | unsigned int has_specification : 1; | |
1235 | unsigned int has_pc_info : 1; | |
481860b3 | 1236 | unsigned int may_be_inlined : 1; |
72bf9492 | 1237 | |
0c1b455e TT |
1238 | /* This DIE has been marked DW_AT_main_subprogram. */ |
1239 | unsigned int main_subprogram : 1; | |
1240 | ||
72bf9492 DJ |
1241 | /* Flag set if the SCOPE field of this structure has been |
1242 | computed. */ | |
1243 | unsigned int scope_set : 1; | |
1244 | ||
fa4028e9 JB |
1245 | /* Flag set if the DIE has a byte_size attribute. */ |
1246 | unsigned int has_byte_size : 1; | |
1247 | ||
ff908ebf AW |
1248 | /* Flag set if the DIE has a DW_AT_const_value attribute. */ |
1249 | unsigned int has_const_value : 1; | |
1250 | ||
98bfdba5 PA |
1251 | /* Flag set if any of the DIE's children are template arguments. */ |
1252 | unsigned int has_template_arguments : 1; | |
1253 | ||
abc72ce4 DE |
1254 | /* Flag set if fixup_partial_die has been called on this die. */ |
1255 | unsigned int fixup_called : 1; | |
1256 | ||
36586728 TT |
1257 | /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */ |
1258 | unsigned int is_dwz : 1; | |
1259 | ||
1260 | /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */ | |
1261 | unsigned int spec_is_dwz : 1; | |
1262 | ||
72bf9492 | 1263 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 1264 | sometimes a default name for unnamed DIEs. */ |
15d034d0 | 1265 | const char *name; |
72bf9492 | 1266 | |
abc72ce4 DE |
1267 | /* The linkage name, if present. */ |
1268 | const char *linkage_name; | |
1269 | ||
72bf9492 DJ |
1270 | /* The scope to prepend to our children. This is generally |
1271 | allocated on the comp_unit_obstack, so will disappear | |
1272 | when this compilation unit leaves the cache. */ | |
15d034d0 | 1273 | const char *scope; |
72bf9492 | 1274 | |
95554aad TT |
1275 | /* Some data associated with the partial DIE. The tag determines |
1276 | which field is live. */ | |
1277 | union | |
1278 | { | |
1279 | /* The location description associated with this DIE, if any. */ | |
1280 | struct dwarf_block *locdesc; | |
1281 | /* The offset of an import, for DW_TAG_imported_unit. */ | |
9c541725 | 1282 | sect_offset sect_off; |
95554aad | 1283 | } d; |
72bf9492 DJ |
1284 | |
1285 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
1286 | CORE_ADDR lowpc; |
1287 | CORE_ADDR highpc; | |
72bf9492 | 1288 | |
93311388 | 1289 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 1290 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
1291 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
1292 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
d521ce57 | 1293 | const gdb_byte *sibling; |
72bf9492 DJ |
1294 | |
1295 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
1296 | DW_AT_specification (or DW_AT_abstract_origin or | |
1297 | DW_AT_extension). */ | |
b64f50a1 | 1298 | sect_offset spec_offset; |
72bf9492 DJ |
1299 | |
1300 | /* Pointers to this DIE's parent, first child, and next sibling, | |
1301 | if any. */ | |
1302 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
1303 | }; |
1304 | ||
0963b4bd | 1305 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
1306 | struct abbrev_info |
1307 | { | |
1308 | unsigned int number; /* number identifying abbrev */ | |
1309 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
1310 | unsigned short has_children; /* boolean */ |
1311 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
1312 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
1313 | struct abbrev_info *next; /* next in chain */ | |
1314 | }; | |
1315 | ||
1316 | struct attr_abbrev | |
1317 | { | |
9d25dd43 DE |
1318 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
1319 | ENUM_BITFIELD(dwarf_form) form : 16; | |
43988095 JK |
1320 | |
1321 | /* It is valid only if FORM is DW_FORM_implicit_const. */ | |
1322 | LONGEST implicit_const; | |
c906108c SS |
1323 | }; |
1324 | ||
433df2d4 DE |
1325 | /* Size of abbrev_table.abbrev_hash_table. */ |
1326 | #define ABBREV_HASH_SIZE 121 | |
1327 | ||
1328 | /* Top level data structure to contain an abbreviation table. */ | |
1329 | ||
1330 | struct abbrev_table | |
1331 | { | |
f4dc4d17 DE |
1332 | /* Where the abbrev table came from. |
1333 | This is used as a sanity check when the table is used. */ | |
9c541725 | 1334 | sect_offset sect_off; |
433df2d4 DE |
1335 | |
1336 | /* Storage for the abbrev table. */ | |
1337 | struct obstack abbrev_obstack; | |
1338 | ||
1339 | /* Hash table of abbrevs. | |
1340 | This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack. | |
1341 | It could be statically allocated, but the previous code didn't so we | |
1342 | don't either. */ | |
1343 | struct abbrev_info **abbrevs; | |
1344 | }; | |
1345 | ||
0963b4bd | 1346 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
1347 | struct attribute |
1348 | { | |
9d25dd43 | 1349 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
1350 | ENUM_BITFIELD(dwarf_form) form : 15; |
1351 | ||
1352 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
1353 | field should be in u.str (existing only for DW_STRING) but it is kept | |
1354 | here for better struct attribute alignment. */ | |
1355 | unsigned int string_is_canonical : 1; | |
1356 | ||
b60c80d6 DJ |
1357 | union |
1358 | { | |
15d034d0 | 1359 | const char *str; |
b60c80d6 | 1360 | struct dwarf_block *blk; |
43bbcdc2 PH |
1361 | ULONGEST unsnd; |
1362 | LONGEST snd; | |
b60c80d6 | 1363 | CORE_ADDR addr; |
ac9ec31b | 1364 | ULONGEST signature; |
b60c80d6 DJ |
1365 | } |
1366 | u; | |
1367 | }; | |
1368 | ||
0963b4bd | 1369 | /* This data structure holds a complete die structure. */ |
c906108c SS |
1370 | struct die_info |
1371 | { | |
76815b17 DE |
1372 | /* DWARF-2 tag for this DIE. */ |
1373 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
1374 | ||
1375 | /* Number of attributes */ | |
98bfdba5 PA |
1376 | unsigned char num_attrs; |
1377 | ||
1378 | /* True if we're presently building the full type name for the | |
1379 | type derived from this DIE. */ | |
1380 | unsigned char building_fullname : 1; | |
76815b17 | 1381 | |
adde2bff DE |
1382 | /* True if this die is in process. PR 16581. */ |
1383 | unsigned char in_process : 1; | |
1384 | ||
76815b17 DE |
1385 | /* Abbrev number */ |
1386 | unsigned int abbrev; | |
1387 | ||
93311388 | 1388 | /* Offset in .debug_info or .debug_types section. */ |
9c541725 | 1389 | sect_offset sect_off; |
78ba4af6 JB |
1390 | |
1391 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
1392 | points to this die's parent; CHILD points to the first child of | |
1393 | this node; and all the children of a given node are chained | |
4950bc1c | 1394 | together via their SIBLING fields. */ |
639d11d3 DC |
1395 | struct die_info *child; /* Its first child, if any. */ |
1396 | struct die_info *sibling; /* Its next sibling, if any. */ | |
1397 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 1398 | |
b60c80d6 DJ |
1399 | /* An array of attributes, with NUM_ATTRS elements. There may be |
1400 | zero, but it's not common and zero-sized arrays are not | |
1401 | sufficiently portable C. */ | |
1402 | struct attribute attrs[1]; | |
c906108c SS |
1403 | }; |
1404 | ||
0963b4bd | 1405 | /* Get at parts of an attribute structure. */ |
c906108c SS |
1406 | |
1407 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 1408 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
1409 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
1410 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
1411 | #define DW_SND(attr) ((attr)->u.snd) | |
1412 | #define DW_ADDR(attr) ((attr)->u.addr) | |
ac9ec31b | 1413 | #define DW_SIGNATURE(attr) ((attr)->u.signature) |
c906108c | 1414 | |
0963b4bd | 1415 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
1416 | struct dwarf_block |
1417 | { | |
56eb65bd | 1418 | size_t size; |
1d6edc3c JK |
1419 | |
1420 | /* Valid only if SIZE is not zero. */ | |
d521ce57 | 1421 | const gdb_byte *data; |
c906108c SS |
1422 | }; |
1423 | ||
c906108c SS |
1424 | #ifndef ATTR_ALLOC_CHUNK |
1425 | #define ATTR_ALLOC_CHUNK 4 | |
1426 | #endif | |
1427 | ||
c906108c SS |
1428 | /* Allocate fields for structs, unions and enums in this size. */ |
1429 | #ifndef DW_FIELD_ALLOC_CHUNK | |
1430 | #define DW_FIELD_ALLOC_CHUNK 4 | |
1431 | #endif | |
1432 | ||
c906108c SS |
1433 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
1434 | but this would require a corresponding change in unpack_field_as_long | |
1435 | and friends. */ | |
1436 | static int bits_per_byte = 8; | |
1437 | ||
52059ffd TT |
1438 | struct nextfield |
1439 | { | |
1440 | struct nextfield *next; | |
1441 | int accessibility; | |
1442 | int virtuality; | |
1443 | struct field field; | |
1444 | }; | |
1445 | ||
1446 | struct nextfnfield | |
1447 | { | |
1448 | struct nextfnfield *next; | |
1449 | struct fn_field fnfield; | |
1450 | }; | |
1451 | ||
1452 | struct fnfieldlist | |
1453 | { | |
1454 | const char *name; | |
1455 | int length; | |
1456 | struct nextfnfield *head; | |
1457 | }; | |
1458 | ||
1459 | struct typedef_field_list | |
1460 | { | |
1461 | struct typedef_field field; | |
1462 | struct typedef_field_list *next; | |
1463 | }; | |
1464 | ||
c906108c SS |
1465 | /* The routines that read and process dies for a C struct or C++ class |
1466 | pass lists of data member fields and lists of member function fields | |
1467 | in an instance of a field_info structure, as defined below. */ | |
1468 | struct field_info | |
c5aa993b | 1469 | { |
0963b4bd | 1470 | /* List of data member and baseclasses fields. */ |
52059ffd | 1471 | struct nextfield *fields, *baseclasses; |
c906108c | 1472 | |
7d0ccb61 | 1473 | /* Number of fields (including baseclasses). */ |
c5aa993b | 1474 | int nfields; |
c906108c | 1475 | |
c5aa993b JM |
1476 | /* Number of baseclasses. */ |
1477 | int nbaseclasses; | |
c906108c | 1478 | |
c5aa993b JM |
1479 | /* Set if the accesibility of one of the fields is not public. */ |
1480 | int non_public_fields; | |
c906108c | 1481 | |
c5aa993b JM |
1482 | /* Member function fields array, entries are allocated in the order they |
1483 | are encountered in the object file. */ | |
52059ffd | 1484 | struct nextfnfield *fnfields; |
c906108c | 1485 | |
c5aa993b JM |
1486 | /* Member function fieldlist array, contains name of possibly overloaded |
1487 | member function, number of overloaded member functions and a pointer | |
1488 | to the head of the member function field chain. */ | |
52059ffd | 1489 | struct fnfieldlist *fnfieldlists; |
c906108c | 1490 | |
c5aa993b JM |
1491 | /* Number of entries in the fnfieldlists array. */ |
1492 | int nfnfields; | |
98751a41 JK |
1493 | |
1494 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
1495 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
52059ffd | 1496 | struct typedef_field_list *typedef_field_list; |
98751a41 | 1497 | unsigned typedef_field_list_count; |
c5aa993b | 1498 | }; |
c906108c | 1499 | |
10b3939b DJ |
1500 | /* One item on the queue of compilation units to read in full symbols |
1501 | for. */ | |
1502 | struct dwarf2_queue_item | |
1503 | { | |
1504 | struct dwarf2_per_cu_data *per_cu; | |
95554aad | 1505 | enum language pretend_language; |
10b3939b DJ |
1506 | struct dwarf2_queue_item *next; |
1507 | }; | |
1508 | ||
1509 | /* The current queue. */ | |
1510 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
1511 | ||
ae038cb0 DJ |
1512 | /* Loaded secondary compilation units are kept in memory until they |
1513 | have not been referenced for the processing of this many | |
1514 | compilation units. Set this to zero to disable caching. Cache | |
1515 | sizes of up to at least twenty will improve startup time for | |
1516 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
b4f54984 | 1517 | static int dwarf_max_cache_age = 5; |
920d2a44 | 1518 | static void |
b4f54984 DE |
1519 | show_dwarf_max_cache_age (struct ui_file *file, int from_tty, |
1520 | struct cmd_list_element *c, const char *value) | |
920d2a44 | 1521 | { |
3e43a32a | 1522 | fprintf_filtered (file, _("The upper bound on the age of cached " |
b4f54984 | 1523 | "DWARF compilation units is %s.\n"), |
920d2a44 AC |
1524 | value); |
1525 | } | |
4390d890 | 1526 | \f |
c906108c SS |
1527 | /* local function prototypes */ |
1528 | ||
a32a8923 DE |
1529 | static const char *get_section_name (const struct dwarf2_section_info *); |
1530 | ||
1531 | static const char *get_section_file_name (const struct dwarf2_section_info *); | |
1532 | ||
918dd910 JK |
1533 | static void dwarf2_find_base_address (struct die_info *die, |
1534 | struct dwarf2_cu *cu); | |
1535 | ||
0018ea6f DE |
1536 | static struct partial_symtab *create_partial_symtab |
1537 | (struct dwarf2_per_cu_data *per_cu, const char *name); | |
1538 | ||
c67a9c90 | 1539 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 1540 | |
72bf9492 DJ |
1541 | static void scan_partial_symbols (struct partial_die_info *, |
1542 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 1543 | int, struct dwarf2_cu *); |
c906108c | 1544 | |
72bf9492 DJ |
1545 | static void add_partial_symbol (struct partial_die_info *, |
1546 | struct dwarf2_cu *); | |
63d06c5c | 1547 | |
72bf9492 DJ |
1548 | static void add_partial_namespace (struct partial_die_info *pdi, |
1549 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
cdc07690 | 1550 | int set_addrmap, struct dwarf2_cu *cu); |
63d06c5c | 1551 | |
5d7cb8df | 1552 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
cdc07690 | 1553 | CORE_ADDR *highpc, int set_addrmap, |
5d7cb8df JK |
1554 | struct dwarf2_cu *cu); |
1555 | ||
72bf9492 DJ |
1556 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
1557 | struct dwarf2_cu *cu); | |
91c24f0a | 1558 | |
bc30ff58 JB |
1559 | static void add_partial_subprogram (struct partial_die_info *pdi, |
1560 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 1561 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 1562 | |
257e7a09 YQ |
1563 | static void dwarf2_read_symtab (struct partial_symtab *, |
1564 | struct objfile *); | |
c906108c | 1565 | |
a14ed312 | 1566 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 1567 | |
433df2d4 DE |
1568 | static struct abbrev_info *abbrev_table_lookup_abbrev |
1569 | (const struct abbrev_table *, unsigned int); | |
1570 | ||
1571 | static struct abbrev_table *abbrev_table_read_table | |
1572 | (struct dwarf2_section_info *, sect_offset); | |
1573 | ||
1574 | static void abbrev_table_free (struct abbrev_table *); | |
1575 | ||
f4dc4d17 DE |
1576 | static void abbrev_table_free_cleanup (void *); |
1577 | ||
dee91e82 DE |
1578 | static void dwarf2_read_abbrevs (struct dwarf2_cu *, |
1579 | struct dwarf2_section_info *); | |
c906108c | 1580 | |
f3dd6933 | 1581 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 1582 | |
d521ce57 | 1583 | static unsigned int peek_abbrev_code (bfd *, const gdb_byte *); |
6caca83c | 1584 | |
dee91e82 | 1585 | static struct partial_die_info *load_partial_dies |
d521ce57 | 1586 | (const struct die_reader_specs *, const gdb_byte *, int); |
72bf9492 | 1587 | |
d521ce57 TT |
1588 | static const gdb_byte *read_partial_die (const struct die_reader_specs *, |
1589 | struct partial_die_info *, | |
1590 | struct abbrev_info *, | |
1591 | unsigned int, | |
1592 | const gdb_byte *); | |
c906108c | 1593 | |
36586728 | 1594 | static struct partial_die_info *find_partial_die (sect_offset, int, |
10b3939b | 1595 | struct dwarf2_cu *); |
72bf9492 DJ |
1596 | |
1597 | static void fixup_partial_die (struct partial_die_info *, | |
1598 | struct dwarf2_cu *); | |
1599 | ||
d521ce57 TT |
1600 | static const gdb_byte *read_attribute (const struct die_reader_specs *, |
1601 | struct attribute *, struct attr_abbrev *, | |
1602 | const gdb_byte *); | |
a8329558 | 1603 | |
a1855c1d | 1604 | static unsigned int read_1_byte (bfd *, const gdb_byte *); |
c906108c | 1605 | |
a1855c1d | 1606 | static int read_1_signed_byte (bfd *, const gdb_byte *); |
c906108c | 1607 | |
a1855c1d | 1608 | static unsigned int read_2_bytes (bfd *, const gdb_byte *); |
c906108c | 1609 | |
a1855c1d | 1610 | static unsigned int read_4_bytes (bfd *, const gdb_byte *); |
c906108c | 1611 | |
a1855c1d | 1612 | static ULONGEST read_8_bytes (bfd *, const gdb_byte *); |
c906108c | 1613 | |
d521ce57 | 1614 | static CORE_ADDR read_address (bfd *, const gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 1615 | unsigned int *); |
c906108c | 1616 | |
d521ce57 | 1617 | static LONGEST read_initial_length (bfd *, const gdb_byte *, unsigned int *); |
c764a876 DE |
1618 | |
1619 | static LONGEST read_checked_initial_length_and_offset | |
d521ce57 | 1620 | (bfd *, const gdb_byte *, const struct comp_unit_head *, |
c764a876 | 1621 | unsigned int *, unsigned int *); |
613e1657 | 1622 | |
d521ce57 TT |
1623 | static LONGEST read_offset (bfd *, const gdb_byte *, |
1624 | const struct comp_unit_head *, | |
c764a876 DE |
1625 | unsigned int *); |
1626 | ||
d521ce57 | 1627 | static LONGEST read_offset_1 (bfd *, const gdb_byte *, unsigned int); |
613e1657 | 1628 | |
f4dc4d17 DE |
1629 | static sect_offset read_abbrev_offset (struct dwarf2_section_info *, |
1630 | sect_offset); | |
1631 | ||
d521ce57 | 1632 | static const gdb_byte *read_n_bytes (bfd *, const gdb_byte *, unsigned int); |
c906108c | 1633 | |
d521ce57 | 1634 | static const char *read_direct_string (bfd *, const gdb_byte *, unsigned int *); |
c906108c | 1635 | |
d521ce57 TT |
1636 | static const char *read_indirect_string (bfd *, const gdb_byte *, |
1637 | const struct comp_unit_head *, | |
1638 | unsigned int *); | |
4bdf3d34 | 1639 | |
43988095 JK |
1640 | static const char *read_indirect_line_string (bfd *, const gdb_byte *, |
1641 | const struct comp_unit_head *, | |
1642 | unsigned int *); | |
36586728 | 1643 | |
43988095 | 1644 | static const char *read_indirect_string_from_dwz (struct dwz_file *, LONGEST); |
c906108c | 1645 | |
d521ce57 | 1646 | static LONGEST read_signed_leb128 (bfd *, const gdb_byte *, unsigned int *); |
c906108c | 1647 | |
d521ce57 TT |
1648 | static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, |
1649 | const gdb_byte *, | |
3019eac3 DE |
1650 | unsigned int *); |
1651 | ||
d521ce57 | 1652 | static const char *read_str_index (const struct die_reader_specs *reader, |
342587c4 | 1653 | ULONGEST str_index); |
3019eac3 | 1654 | |
e142c38c | 1655 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 1656 | |
e142c38c DJ |
1657 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
1658 | struct dwarf2_cu *); | |
c906108c | 1659 | |
348e048f | 1660 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
45e58e77 | 1661 | unsigned int); |
348e048f | 1662 | |
7d45c7c3 KB |
1663 | static const char *dwarf2_string_attr (struct die_info *die, unsigned int name, |
1664 | struct dwarf2_cu *cu); | |
1665 | ||
05cf31d1 JB |
1666 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
1667 | struct dwarf2_cu *cu); | |
1668 | ||
e142c38c | 1669 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 1670 | |
e142c38c | 1671 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 1672 | struct dwarf2_cu **); |
63d06c5c | 1673 | |
9c541725 | 1674 | static line_header_up dwarf_decode_line_header (sect_offset sect_off, |
fff8551c | 1675 | struct dwarf2_cu *cu); |
debd256d | 1676 | |
f3f5162e | 1677 | static void dwarf_decode_lines (struct line_header *, const char *, |
c3b7b696 | 1678 | struct dwarf2_cu *, struct partial_symtab *, |
527f3840 | 1679 | CORE_ADDR, int decode_mapping); |
c906108c | 1680 | |
4d663531 | 1681 | static void dwarf2_start_subfile (const char *, const char *); |
c906108c | 1682 | |
43f3e411 DE |
1683 | static struct compunit_symtab *dwarf2_start_symtab (struct dwarf2_cu *, |
1684 | const char *, const char *, | |
1685 | CORE_ADDR); | |
f4dc4d17 | 1686 | |
a14ed312 | 1687 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 1688 | struct dwarf2_cu *); |
c906108c | 1689 | |
34eaf542 TT |
1690 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
1691 | struct dwarf2_cu *, struct symbol *); | |
1692 | ||
ff39bb5e | 1693 | static void dwarf2_const_value (const struct attribute *, struct symbol *, |
e7c27a73 | 1694 | struct dwarf2_cu *); |
c906108c | 1695 | |
ff39bb5e | 1696 | static void dwarf2_const_value_attr (const struct attribute *attr, |
98bfdba5 PA |
1697 | struct type *type, |
1698 | const char *name, | |
1699 | struct obstack *obstack, | |
12df843f | 1700 | struct dwarf2_cu *cu, LONGEST *value, |
d521ce57 | 1701 | const gdb_byte **bytes, |
98bfdba5 | 1702 | struct dwarf2_locexpr_baton **baton); |
2df3850c | 1703 | |
e7c27a73 | 1704 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1705 | |
b4ba55a1 JB |
1706 | static int need_gnat_info (struct dwarf2_cu *); |
1707 | ||
3e43a32a MS |
1708 | static struct type *die_descriptive_type (struct die_info *, |
1709 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1710 | |
1711 | static void set_descriptive_type (struct type *, struct die_info *, | |
1712 | struct dwarf2_cu *); | |
1713 | ||
e7c27a73 DJ |
1714 | static struct type *die_containing_type (struct die_info *, |
1715 | struct dwarf2_cu *); | |
c906108c | 1716 | |
ff39bb5e | 1717 | static struct type *lookup_die_type (struct die_info *, const struct attribute *, |
673bfd45 | 1718 | struct dwarf2_cu *); |
c906108c | 1719 | |
f792889a | 1720 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1721 | |
673bfd45 DE |
1722 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1723 | ||
0d5cff50 | 1724 | static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1725 | |
6e70227d | 1726 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1727 | const char *suffix, int physname, |
1728 | struct dwarf2_cu *cu); | |
63d06c5c | 1729 | |
e7c27a73 | 1730 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1731 | |
348e048f DE |
1732 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1733 | ||
e7c27a73 | 1734 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1735 | |
e7c27a73 | 1736 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1737 | |
96408a79 SA |
1738 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
1739 | ||
ff013f42 JK |
1740 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1741 | struct dwarf2_cu *, struct partial_symtab *); | |
1742 | ||
3a2b436a | 1743 | /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return |
e385593e | 1744 | values. Keep the items ordered with increasing constraints compliance. */ |
3a2b436a JK |
1745 | enum pc_bounds_kind |
1746 | { | |
e385593e | 1747 | /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */ |
3a2b436a JK |
1748 | PC_BOUNDS_NOT_PRESENT, |
1749 | ||
e385593e JK |
1750 | /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges |
1751 | were present but they do not form a valid range of PC addresses. */ | |
1752 | PC_BOUNDS_INVALID, | |
1753 | ||
3a2b436a JK |
1754 | /* Discontiguous range was found - that is DW_AT_ranges was found. */ |
1755 | PC_BOUNDS_RANGES, | |
1756 | ||
1757 | /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */ | |
1758 | PC_BOUNDS_HIGH_LOW, | |
1759 | }; | |
1760 | ||
1761 | static enum pc_bounds_kind dwarf2_get_pc_bounds (struct die_info *, | |
1762 | CORE_ADDR *, CORE_ADDR *, | |
1763 | struct dwarf2_cu *, | |
1764 | struct partial_symtab *); | |
c906108c | 1765 | |
fae299cd DC |
1766 | static void get_scope_pc_bounds (struct die_info *, |
1767 | CORE_ADDR *, CORE_ADDR *, | |
1768 | struct dwarf2_cu *); | |
1769 | ||
801e3a5b JB |
1770 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1771 | CORE_ADDR, struct dwarf2_cu *); | |
1772 | ||
a14ed312 | 1773 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1774 | struct dwarf2_cu *); |
c906108c | 1775 | |
a14ed312 | 1776 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1777 | struct type *, struct dwarf2_cu *); |
c906108c | 1778 | |
a14ed312 | 1779 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1780 | struct die_info *, struct type *, |
e7c27a73 | 1781 | struct dwarf2_cu *); |
c906108c | 1782 | |
a14ed312 | 1783 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1784 | struct type *, |
1785 | struct dwarf2_cu *); | |
c906108c | 1786 | |
134d01f1 | 1787 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1788 | |
e7c27a73 | 1789 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1790 | |
e7c27a73 | 1791 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1792 | |
5d7cb8df JK |
1793 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1794 | ||
22cee43f PMR |
1795 | static struct using_direct **using_directives (enum language); |
1796 | ||
27aa8d6a SW |
1797 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1798 | ||
74921315 KS |
1799 | static int read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu); |
1800 | ||
f55ee35c JK |
1801 | static struct type *read_module_type (struct die_info *die, |
1802 | struct dwarf2_cu *cu); | |
1803 | ||
38d518c9 | 1804 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1805 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1806 | |
134d01f1 | 1807 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1808 | |
e7c27a73 | 1809 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1810 | |
6e70227d | 1811 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1812 | struct dwarf2_cu *); |
1813 | ||
bf6af496 | 1814 | static struct die_info *read_die_and_siblings_1 |
d521ce57 | 1815 | (const struct die_reader_specs *, const gdb_byte *, const gdb_byte **, |
bf6af496 | 1816 | struct die_info *); |
639d11d3 | 1817 | |
dee91e82 | 1818 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *, |
d521ce57 TT |
1819 | const gdb_byte *info_ptr, |
1820 | const gdb_byte **new_info_ptr, | |
639d11d3 DC |
1821 | struct die_info *parent); |
1822 | ||
d521ce57 TT |
1823 | static const gdb_byte *read_full_die_1 (const struct die_reader_specs *, |
1824 | struct die_info **, const gdb_byte *, | |
1825 | int *, int); | |
3019eac3 | 1826 | |
d521ce57 TT |
1827 | static const gdb_byte *read_full_die (const struct die_reader_specs *, |
1828 | struct die_info **, const gdb_byte *, | |
1829 | int *); | |
93311388 | 1830 | |
e7c27a73 | 1831 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1832 | |
15d034d0 TT |
1833 | static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu *, |
1834 | struct obstack *); | |
71c25dea | 1835 | |
15d034d0 | 1836 | static const char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1837 | |
15d034d0 | 1838 | static const char *dwarf2_full_name (const char *name, |
98bfdba5 PA |
1839 | struct die_info *die, |
1840 | struct dwarf2_cu *cu); | |
1841 | ||
ca69b9e6 DE |
1842 | static const char *dwarf2_physname (const char *name, struct die_info *die, |
1843 | struct dwarf2_cu *cu); | |
1844 | ||
e142c38c | 1845 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1846 | struct dwarf2_cu **); |
9219021c | 1847 | |
f39c6ffd | 1848 | static const char *dwarf_tag_name (unsigned int); |
c906108c | 1849 | |
f39c6ffd | 1850 | static const char *dwarf_attr_name (unsigned int); |
c906108c | 1851 | |
f39c6ffd | 1852 | static const char *dwarf_form_name (unsigned int); |
c906108c | 1853 | |
a121b7c1 | 1854 | static const char *dwarf_bool_name (unsigned int); |
c906108c | 1855 | |
f39c6ffd | 1856 | static const char *dwarf_type_encoding_name (unsigned int); |
c906108c | 1857 | |
f9aca02d | 1858 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1859 | |
d97bc12b DE |
1860 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1861 | ||
1862 | static void dump_die_for_error (struct die_info *); | |
1863 | ||
1864 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1865 | struct die_info *); | |
c906108c | 1866 | |
d97bc12b | 1867 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1868 | |
51545339 | 1869 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1870 | struct dwarf2_cu *); |
c906108c | 1871 | |
ff39bb5e | 1872 | static sect_offset dwarf2_get_ref_die_offset (const struct attribute *); |
c906108c | 1873 | |
ff39bb5e | 1874 | static LONGEST dwarf2_get_attr_constant_value (const struct attribute *, int); |
a02abb62 | 1875 | |
348e048f | 1876 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
ff39bb5e | 1877 | const struct attribute *, |
348e048f DE |
1878 | struct dwarf2_cu **); |
1879 | ||
10b3939b | 1880 | static struct die_info *follow_die_ref (struct die_info *, |
ff39bb5e | 1881 | const struct attribute *, |
f2f0e013 | 1882 | struct dwarf2_cu **); |
c906108c | 1883 | |
348e048f | 1884 | static struct die_info *follow_die_sig (struct die_info *, |
ff39bb5e | 1885 | const struct attribute *, |
348e048f DE |
1886 | struct dwarf2_cu **); |
1887 | ||
ac9ec31b DE |
1888 | static struct type *get_signatured_type (struct die_info *, ULONGEST, |
1889 | struct dwarf2_cu *); | |
1890 | ||
1891 | static struct type *get_DW_AT_signature_type (struct die_info *, | |
ff39bb5e | 1892 | const struct attribute *, |
ac9ec31b DE |
1893 | struct dwarf2_cu *); |
1894 | ||
e5fe5e75 | 1895 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
348e048f | 1896 | |
52dc124a | 1897 | static void read_signatured_type (struct signatured_type *); |
348e048f | 1898 | |
63e43d3a PMR |
1899 | static int attr_to_dynamic_prop (const struct attribute *attr, |
1900 | struct die_info *die, struct dwarf2_cu *cu, | |
1901 | struct dynamic_prop *prop); | |
1902 | ||
c906108c SS |
1903 | /* memory allocation interface */ |
1904 | ||
7b5a2f43 | 1905 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1906 | |
b60c80d6 | 1907 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1908 | |
43f3e411 | 1909 | static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int, int); |
2e276125 | 1910 | |
6e5a29e1 | 1911 | static int attr_form_is_block (const struct attribute *); |
8e19ed76 | 1912 | |
6e5a29e1 | 1913 | static int attr_form_is_section_offset (const struct attribute *); |
3690dd37 | 1914 | |
6e5a29e1 | 1915 | static int attr_form_is_constant (const struct attribute *); |
3690dd37 | 1916 | |
6e5a29e1 | 1917 | static int attr_form_is_ref (const struct attribute *); |
7771576e | 1918 | |
8cf6f0b1 TT |
1919 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1920 | struct dwarf2_loclist_baton *baton, | |
ff39bb5e | 1921 | const struct attribute *attr); |
8cf6f0b1 | 1922 | |
ff39bb5e | 1923 | static void dwarf2_symbol_mark_computed (const struct attribute *attr, |
93e7bd98 | 1924 | struct symbol *sym, |
f1e6e072 TT |
1925 | struct dwarf2_cu *cu, |
1926 | int is_block); | |
4c2df51b | 1927 | |
d521ce57 TT |
1928 | static const gdb_byte *skip_one_die (const struct die_reader_specs *reader, |
1929 | const gdb_byte *info_ptr, | |
1930 | struct abbrev_info *abbrev); | |
4bb7a0a7 | 1931 | |
72bf9492 DJ |
1932 | static void free_stack_comp_unit (void *); |
1933 | ||
72bf9492 DJ |
1934 | static hashval_t partial_die_hash (const void *item); |
1935 | ||
1936 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1937 | ||
ae038cb0 | 1938 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
9c541725 | 1939 | (sect_offset sect_off, unsigned int offset_in_dwz, struct objfile *objfile); |
ae038cb0 | 1940 | |
9816fde3 | 1941 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
23745b47 | 1942 | struct dwarf2_per_cu_data *per_cu); |
9816fde3 JK |
1943 | |
1944 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
95554aad TT |
1945 | struct die_info *comp_unit_die, |
1946 | enum language pretend_language); | |
93311388 | 1947 | |
68dc6402 | 1948 | static void free_heap_comp_unit (void *); |
ae038cb0 DJ |
1949 | |
1950 | static void free_cached_comp_units (void *); | |
1951 | ||
1952 | static void age_cached_comp_units (void); | |
1953 | ||
dee91e82 | 1954 | static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *); |
ae038cb0 | 1955 | |
f792889a DJ |
1956 | static struct type *set_die_type (struct die_info *, struct type *, |
1957 | struct dwarf2_cu *); | |
1c379e20 | 1958 | |
ae038cb0 DJ |
1959 | static void create_all_comp_units (struct objfile *); |
1960 | ||
0e50663e | 1961 | static int create_all_type_units (struct objfile *); |
1fd400ff | 1962 | |
95554aad TT |
1963 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1964 | enum language); | |
10b3939b | 1965 | |
95554aad TT |
1966 | static void process_full_comp_unit (struct dwarf2_per_cu_data *, |
1967 | enum language); | |
10b3939b | 1968 | |
f4dc4d17 DE |
1969 | static void process_full_type_unit (struct dwarf2_per_cu_data *, |
1970 | enum language); | |
1971 | ||
10b3939b DJ |
1972 | static void dwarf2_add_dependence (struct dwarf2_cu *, |
1973 | struct dwarf2_per_cu_data *); | |
1974 | ||
ae038cb0 DJ |
1975 | static void dwarf2_mark (struct dwarf2_cu *); |
1976 | ||
1977 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1978 | ||
b64f50a1 | 1979 | static struct type *get_die_type_at_offset (sect_offset, |
ac9ec31b | 1980 | struct dwarf2_per_cu_data *); |
673bfd45 | 1981 | |
f792889a | 1982 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1983 | |
9291a0cd TT |
1984 | static void dwarf2_release_queue (void *dummy); |
1985 | ||
95554aad TT |
1986 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, |
1987 | enum language pretend_language); | |
1988 | ||
a0f42c21 | 1989 | static void process_queue (void); |
9291a0cd | 1990 | |
d721ba37 PA |
1991 | /* The return type of find_file_and_directory. Note, the enclosed |
1992 | string pointers are only valid while this object is valid. */ | |
1993 | ||
1994 | struct file_and_directory | |
1995 | { | |
1996 | /* The filename. This is never NULL. */ | |
1997 | const char *name; | |
1998 | ||
1999 | /* The compilation directory. NULL if not known. If we needed to | |
2000 | compute a new string, this points to COMP_DIR_STORAGE, otherwise, | |
2001 | points directly to the DW_AT_comp_dir string attribute owned by | |
2002 | the obstack that owns the DIE. */ | |
2003 | const char *comp_dir; | |
2004 | ||
2005 | /* If we needed to build a new string for comp_dir, this is what | |
2006 | owns the storage. */ | |
2007 | std::string comp_dir_storage; | |
2008 | }; | |
2009 | ||
2010 | static file_and_directory find_file_and_directory (struct die_info *die, | |
2011 | struct dwarf2_cu *cu); | |
9291a0cd TT |
2012 | |
2013 | static char *file_full_name (int file, struct line_header *lh, | |
2014 | const char *comp_dir); | |
2015 | ||
43988095 JK |
2016 | /* Expected enum dwarf_unit_type for read_comp_unit_head. */ |
2017 | enum class rcuh_kind { COMPILE, TYPE }; | |
2018 | ||
d521ce57 | 2019 | static const gdb_byte *read_and_check_comp_unit_head |
36586728 TT |
2020 | (struct comp_unit_head *header, |
2021 | struct dwarf2_section_info *section, | |
d521ce57 | 2022 | struct dwarf2_section_info *abbrev_section, const gdb_byte *info_ptr, |
43988095 | 2023 | rcuh_kind section_kind); |
36586728 | 2024 | |
fd820528 | 2025 | static void init_cutu_and_read_dies |
f4dc4d17 DE |
2026 | (struct dwarf2_per_cu_data *this_cu, struct abbrev_table *abbrev_table, |
2027 | int use_existing_cu, int keep, | |
3019eac3 DE |
2028 | die_reader_func_ftype *die_reader_func, void *data); |
2029 | ||
dee91e82 DE |
2030 | static void init_cutu_and_read_dies_simple |
2031 | (struct dwarf2_per_cu_data *this_cu, | |
2032 | die_reader_func_ftype *die_reader_func, void *data); | |
9291a0cd | 2033 | |
673bfd45 | 2034 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 2035 | |
3019eac3 DE |
2036 | static htab_t allocate_dwo_unit_table (struct objfile *objfile); |
2037 | ||
57d63ce2 DE |
2038 | static struct dwo_unit *lookup_dwo_unit_in_dwp |
2039 | (struct dwp_file *dwp_file, const char *comp_dir, | |
2040 | ULONGEST signature, int is_debug_types); | |
a2ce51a0 DE |
2041 | |
2042 | static struct dwp_file *get_dwp_file (void); | |
2043 | ||
3019eac3 | 2044 | static struct dwo_unit *lookup_dwo_comp_unit |
a1855c1d | 2045 | (struct dwarf2_per_cu_data *, const char *, const char *, ULONGEST); |
3019eac3 DE |
2046 | |
2047 | static struct dwo_unit *lookup_dwo_type_unit | |
a1855c1d | 2048 | (struct signatured_type *, const char *, const char *); |
3019eac3 | 2049 | |
89e63ee4 DE |
2050 | static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *); |
2051 | ||
3019eac3 DE |
2052 | static void free_dwo_file_cleanup (void *); |
2053 | ||
95554aad TT |
2054 | static void process_cu_includes (void); |
2055 | ||
1b80a9fa | 2056 | static void check_producer (struct dwarf2_cu *cu); |
527f3840 JK |
2057 | |
2058 | static void free_line_header_voidp (void *arg); | |
4390d890 DE |
2059 | \f |
2060 | /* Various complaints about symbol reading that don't abort the process. */ | |
2061 | ||
2062 | static void | |
2063 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2064 | { | |
2065 | complaint (&symfile_complaints, | |
2066 | _("statement list doesn't fit in .debug_line section")); | |
2067 | } | |
2068 | ||
2069 | static void | |
2070 | dwarf2_debug_line_missing_file_complaint (void) | |
2071 | { | |
2072 | complaint (&symfile_complaints, | |
2073 | _(".debug_line section has line data without a file")); | |
2074 | } | |
2075 | ||
2076 | static void | |
2077 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
2078 | { | |
2079 | complaint (&symfile_complaints, | |
2080 | _(".debug_line section has line " | |
2081 | "program sequence without an end")); | |
2082 | } | |
2083 | ||
2084 | static void | |
2085 | dwarf2_complex_location_expr_complaint (void) | |
2086 | { | |
2087 | complaint (&symfile_complaints, _("location expression too complex")); | |
2088 | } | |
2089 | ||
2090 | static void | |
2091 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
2092 | int arg3) | |
2093 | { | |
2094 | complaint (&symfile_complaints, | |
2095 | _("const value length mismatch for '%s', got %d, expected %d"), | |
2096 | arg1, arg2, arg3); | |
2097 | } | |
2098 | ||
2099 | static void | |
2100 | dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section) | |
2101 | { | |
2102 | complaint (&symfile_complaints, | |
2103 | _("debug info runs off end of %s section" | |
2104 | " [in module %s]"), | |
a32a8923 DE |
2105 | get_section_name (section), |
2106 | get_section_file_name (section)); | |
4390d890 | 2107 | } |
1b80a9fa | 2108 | |
4390d890 DE |
2109 | static void |
2110 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
2111 | { | |
2112 | complaint (&symfile_complaints, | |
2113 | _("macro debug info contains a " | |
2114 | "malformed macro definition:\n`%s'"), | |
2115 | arg1); | |
2116 | } | |
2117 | ||
2118 | static void | |
2119 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
2120 | { | |
2121 | complaint (&symfile_complaints, | |
2122 | _("invalid attribute class or form for '%s' in '%s'"), | |
2123 | arg1, arg2); | |
2124 | } | |
527f3840 JK |
2125 | |
2126 | /* Hash function for line_header_hash. */ | |
2127 | ||
2128 | static hashval_t | |
2129 | line_header_hash (const struct line_header *ofs) | |
2130 | { | |
9c541725 | 2131 | return to_underlying (ofs->sect_off) ^ ofs->offset_in_dwz; |
527f3840 JK |
2132 | } |
2133 | ||
2134 | /* Hash function for htab_create_alloc_ex for line_header_hash. */ | |
2135 | ||
2136 | static hashval_t | |
2137 | line_header_hash_voidp (const void *item) | |
2138 | { | |
9a3c8263 | 2139 | const struct line_header *ofs = (const struct line_header *) item; |
527f3840 JK |
2140 | |
2141 | return line_header_hash (ofs); | |
2142 | } | |
2143 | ||
2144 | /* Equality function for line_header_hash. */ | |
2145 | ||
2146 | static int | |
2147 | line_header_eq_voidp (const void *item_lhs, const void *item_rhs) | |
2148 | { | |
9a3c8263 SM |
2149 | const struct line_header *ofs_lhs = (const struct line_header *) item_lhs; |
2150 | const struct line_header *ofs_rhs = (const struct line_header *) item_rhs; | |
527f3840 | 2151 | |
9c541725 | 2152 | return (ofs_lhs->sect_off == ofs_rhs->sect_off |
527f3840 JK |
2153 | && ofs_lhs->offset_in_dwz == ofs_rhs->offset_in_dwz); |
2154 | } | |
2155 | ||
4390d890 | 2156 | \f |
9291a0cd TT |
2157 | #if WORDS_BIGENDIAN |
2158 | ||
2159 | /* Convert VALUE between big- and little-endian. */ | |
2160 | static offset_type | |
2161 | byte_swap (offset_type value) | |
2162 | { | |
2163 | offset_type result; | |
2164 | ||
2165 | result = (value & 0xff) << 24; | |
2166 | result |= (value & 0xff00) << 8; | |
2167 | result |= (value & 0xff0000) >> 8; | |
2168 | result |= (value & 0xff000000) >> 24; | |
2169 | return result; | |
2170 | } | |
2171 | ||
2172 | #define MAYBE_SWAP(V) byte_swap (V) | |
2173 | ||
2174 | #else | |
bc8f2430 | 2175 | #define MAYBE_SWAP(V) static_cast<offset_type> (V) |
9291a0cd TT |
2176 | #endif /* WORDS_BIGENDIAN */ |
2177 | ||
31aa7e4e JB |
2178 | /* Read the given attribute value as an address, taking the attribute's |
2179 | form into account. */ | |
2180 | ||
2181 | static CORE_ADDR | |
2182 | attr_value_as_address (struct attribute *attr) | |
2183 | { | |
2184 | CORE_ADDR addr; | |
2185 | ||
2186 | if (attr->form != DW_FORM_addr && attr->form != DW_FORM_GNU_addr_index) | |
2187 | { | |
2188 | /* Aside from a few clearly defined exceptions, attributes that | |
2189 | contain an address must always be in DW_FORM_addr form. | |
2190 | Unfortunately, some compilers happen to be violating this | |
2191 | requirement by encoding addresses using other forms, such | |
2192 | as DW_FORM_data4 for example. For those broken compilers, | |
2193 | we try to do our best, without any guarantee of success, | |
2194 | to interpret the address correctly. It would also be nice | |
2195 | to generate a complaint, but that would require us to maintain | |
2196 | a list of legitimate cases where a non-address form is allowed, | |
2197 | as well as update callers to pass in at least the CU's DWARF | |
2198 | version. This is more overhead than what we're willing to | |
2199 | expand for a pretty rare case. */ | |
2200 | addr = DW_UNSND (attr); | |
2201 | } | |
2202 | else | |
2203 | addr = DW_ADDR (attr); | |
2204 | ||
2205 | return addr; | |
2206 | } | |
2207 | ||
9291a0cd TT |
2208 | /* The suffix for an index file. */ |
2209 | #define INDEX_SUFFIX ".gdb-index" | |
2210 | ||
330cdd98 PA |
2211 | /* See declaration. */ |
2212 | ||
2213 | dwarf2_per_objfile::dwarf2_per_objfile (struct objfile *objfile_, | |
2214 | const dwarf2_debug_sections *names) | |
2215 | : objfile (objfile_) | |
2216 | { | |
2217 | if (names == NULL) | |
2218 | names = &dwarf2_elf_names; | |
2219 | ||
2220 | bfd *obfd = objfile->obfd; | |
2221 | ||
2222 | for (asection *sec = obfd->sections; sec != NULL; sec = sec->next) | |
2223 | locate_sections (obfd, sec, *names); | |
2224 | } | |
2225 | ||
2226 | dwarf2_per_objfile::~dwarf2_per_objfile () | |
2227 | { | |
2228 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
2229 | free_cached_comp_units (); | |
2230 | ||
2231 | if (quick_file_names_table) | |
2232 | htab_delete (quick_file_names_table); | |
2233 | ||
2234 | if (line_header_hash) | |
2235 | htab_delete (line_header_hash); | |
2236 | ||
2237 | /* Everything else should be on the objfile obstack. */ | |
2238 | } | |
2239 | ||
2240 | /* See declaration. */ | |
2241 | ||
2242 | void | |
2243 | dwarf2_per_objfile::free_cached_comp_units () | |
2244 | { | |
2245 | dwarf2_per_cu_data *per_cu = read_in_chain; | |
2246 | dwarf2_per_cu_data **last_chain = &read_in_chain; | |
2247 | while (per_cu != NULL) | |
2248 | { | |
2249 | dwarf2_per_cu_data *next_cu = per_cu->cu->read_in_chain; | |
2250 | ||
2251 | free_heap_comp_unit (per_cu->cu); | |
2252 | *last_chain = next_cu; | |
2253 | per_cu = next_cu; | |
2254 | } | |
2255 | } | |
2256 | ||
c906108c | 2257 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
2258 | information and return true if we have enough to do something. |
2259 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
2260 | ELF names are used. */ | |
c906108c SS |
2261 | |
2262 | int | |
251d32d9 TG |
2263 | dwarf2_has_info (struct objfile *objfile, |
2264 | const struct dwarf2_debug_sections *names) | |
c906108c | 2265 | { |
9a3c8263 SM |
2266 | dwarf2_per_objfile = ((struct dwarf2_per_objfile *) |
2267 | objfile_data (objfile, dwarf2_objfile_data_key)); | |
be391dca TT |
2268 | if (!dwarf2_per_objfile) |
2269 | { | |
2270 | /* Initialize per-objfile state. */ | |
2271 | struct dwarf2_per_objfile *data | |
8d749320 | 2272 | = XOBNEW (&objfile->objfile_obstack, struct dwarf2_per_objfile); |
9a619af0 | 2273 | |
330cdd98 PA |
2274 | dwarf2_per_objfile = new (data) struct dwarf2_per_objfile (objfile, names); |
2275 | set_objfile_data (objfile, dwarf2_objfile_data_key, dwarf2_per_objfile); | |
be391dca | 2276 | } |
73869dc2 | 2277 | return (!dwarf2_per_objfile->info.is_virtual |
049412e3 | 2278 | && dwarf2_per_objfile->info.s.section != NULL |
73869dc2 | 2279 | && !dwarf2_per_objfile->abbrev.is_virtual |
049412e3 | 2280 | && dwarf2_per_objfile->abbrev.s.section != NULL); |
73869dc2 DE |
2281 | } |
2282 | ||
2283 | /* Return the containing section of virtual section SECTION. */ | |
2284 | ||
2285 | static struct dwarf2_section_info * | |
2286 | get_containing_section (const struct dwarf2_section_info *section) | |
2287 | { | |
2288 | gdb_assert (section->is_virtual); | |
2289 | return section->s.containing_section; | |
c906108c SS |
2290 | } |
2291 | ||
a32a8923 DE |
2292 | /* Return the bfd owner of SECTION. */ |
2293 | ||
2294 | static struct bfd * | |
2295 | get_section_bfd_owner (const struct dwarf2_section_info *section) | |
2296 | { | |
73869dc2 DE |
2297 | if (section->is_virtual) |
2298 | { | |
2299 | section = get_containing_section (section); | |
2300 | gdb_assert (!section->is_virtual); | |
2301 | } | |
049412e3 | 2302 | return section->s.section->owner; |
a32a8923 DE |
2303 | } |
2304 | ||
2305 | /* Return the bfd section of SECTION. | |
2306 | Returns NULL if the section is not present. */ | |
2307 | ||
2308 | static asection * | |
2309 | get_section_bfd_section (const struct dwarf2_section_info *section) | |
2310 | { | |
73869dc2 DE |
2311 | if (section->is_virtual) |
2312 | { | |
2313 | section = get_containing_section (section); | |
2314 | gdb_assert (!section->is_virtual); | |
2315 | } | |
049412e3 | 2316 | return section->s.section; |
a32a8923 DE |
2317 | } |
2318 | ||
2319 | /* Return the name of SECTION. */ | |
2320 | ||
2321 | static const char * | |
2322 | get_section_name (const struct dwarf2_section_info *section) | |
2323 | { | |
2324 | asection *sectp = get_section_bfd_section (section); | |
2325 | ||
2326 | gdb_assert (sectp != NULL); | |
2327 | return bfd_section_name (get_section_bfd_owner (section), sectp); | |
2328 | } | |
2329 | ||
2330 | /* Return the name of the file SECTION is in. */ | |
2331 | ||
2332 | static const char * | |
2333 | get_section_file_name (const struct dwarf2_section_info *section) | |
2334 | { | |
2335 | bfd *abfd = get_section_bfd_owner (section); | |
2336 | ||
2337 | return bfd_get_filename (abfd); | |
2338 | } | |
2339 | ||
2340 | /* Return the id of SECTION. | |
2341 | Returns 0 if SECTION doesn't exist. */ | |
2342 | ||
2343 | static int | |
2344 | get_section_id (const struct dwarf2_section_info *section) | |
2345 | { | |
2346 | asection *sectp = get_section_bfd_section (section); | |
2347 | ||
2348 | if (sectp == NULL) | |
2349 | return 0; | |
2350 | return sectp->id; | |
2351 | } | |
2352 | ||
2353 | /* Return the flags of SECTION. | |
73869dc2 | 2354 | SECTION (or containing section if this is a virtual section) must exist. */ |
a32a8923 DE |
2355 | |
2356 | static int | |
2357 | get_section_flags (const struct dwarf2_section_info *section) | |
2358 | { | |
2359 | asection *sectp = get_section_bfd_section (section); | |
2360 | ||
2361 | gdb_assert (sectp != NULL); | |
2362 | return bfd_get_section_flags (sectp->owner, sectp); | |
2363 | } | |
2364 | ||
251d32d9 TG |
2365 | /* When loading sections, we look either for uncompressed section or for |
2366 | compressed section names. */ | |
233a11ab CS |
2367 | |
2368 | static int | |
251d32d9 TG |
2369 | section_is_p (const char *section_name, |
2370 | const struct dwarf2_section_names *names) | |
233a11ab | 2371 | { |
251d32d9 TG |
2372 | if (names->normal != NULL |
2373 | && strcmp (section_name, names->normal) == 0) | |
2374 | return 1; | |
2375 | if (names->compressed != NULL | |
2376 | && strcmp (section_name, names->compressed) == 0) | |
2377 | return 1; | |
2378 | return 0; | |
233a11ab CS |
2379 | } |
2380 | ||
330cdd98 | 2381 | /* See declaration. */ |
c906108c | 2382 | |
330cdd98 PA |
2383 | void |
2384 | dwarf2_per_objfile::locate_sections (bfd *abfd, asection *sectp, | |
2385 | const dwarf2_debug_sections &names) | |
c906108c | 2386 | { |
dc7650b8 | 2387 | flagword aflag = bfd_get_section_flags (abfd, sectp); |
251d32d9 | 2388 | |
dc7650b8 JK |
2389 | if ((aflag & SEC_HAS_CONTENTS) == 0) |
2390 | { | |
2391 | } | |
330cdd98 | 2392 | else if (section_is_p (sectp->name, &names.info)) |
c906108c | 2393 | { |
330cdd98 PA |
2394 | this->info.s.section = sectp; |
2395 | this->info.size = bfd_get_section_size (sectp); | |
c906108c | 2396 | } |
330cdd98 | 2397 | else if (section_is_p (sectp->name, &names.abbrev)) |
c906108c | 2398 | { |
330cdd98 PA |
2399 | this->abbrev.s.section = sectp; |
2400 | this->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 2401 | } |
330cdd98 | 2402 | else if (section_is_p (sectp->name, &names.line)) |
c906108c | 2403 | { |
330cdd98 PA |
2404 | this->line.s.section = sectp; |
2405 | this->line.size = bfd_get_section_size (sectp); | |
c906108c | 2406 | } |
330cdd98 | 2407 | else if (section_is_p (sectp->name, &names.loc)) |
c906108c | 2408 | { |
330cdd98 PA |
2409 | this->loc.s.section = sectp; |
2410 | this->loc.size = bfd_get_section_size (sectp); | |
c906108c | 2411 | } |
330cdd98 | 2412 | else if (section_is_p (sectp->name, &names.loclists)) |
43988095 | 2413 | { |
330cdd98 PA |
2414 | this->loclists.s.section = sectp; |
2415 | this->loclists.size = bfd_get_section_size (sectp); | |
43988095 | 2416 | } |
330cdd98 | 2417 | else if (section_is_p (sectp->name, &names.macinfo)) |
c906108c | 2418 | { |
330cdd98 PA |
2419 | this->macinfo.s.section = sectp; |
2420 | this->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 2421 | } |
330cdd98 | 2422 | else if (section_is_p (sectp->name, &names.macro)) |
cf2c3c16 | 2423 | { |
330cdd98 PA |
2424 | this->macro.s.section = sectp; |
2425 | this->macro.size = bfd_get_section_size (sectp); | |
cf2c3c16 | 2426 | } |
330cdd98 | 2427 | else if (section_is_p (sectp->name, &names.str)) |
c906108c | 2428 | { |
330cdd98 PA |
2429 | this->str.s.section = sectp; |
2430 | this->str.size = bfd_get_section_size (sectp); | |
c906108c | 2431 | } |
330cdd98 | 2432 | else if (section_is_p (sectp->name, &names.line_str)) |
43988095 | 2433 | { |
330cdd98 PA |
2434 | this->line_str.s.section = sectp; |
2435 | this->line_str.size = bfd_get_section_size (sectp); | |
43988095 | 2436 | } |
330cdd98 | 2437 | else if (section_is_p (sectp->name, &names.addr)) |
3019eac3 | 2438 | { |
330cdd98 PA |
2439 | this->addr.s.section = sectp; |
2440 | this->addr.size = bfd_get_section_size (sectp); | |
3019eac3 | 2441 | } |
330cdd98 | 2442 | else if (section_is_p (sectp->name, &names.frame)) |
b6af0555 | 2443 | { |
330cdd98 PA |
2444 | this->frame.s.section = sectp; |
2445 | this->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 2446 | } |
330cdd98 | 2447 | else if (section_is_p (sectp->name, &names.eh_frame)) |
b6af0555 | 2448 | { |
330cdd98 PA |
2449 | this->eh_frame.s.section = sectp; |
2450 | this->eh_frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 2451 | } |
330cdd98 | 2452 | else if (section_is_p (sectp->name, &names.ranges)) |
af34e669 | 2453 | { |
330cdd98 PA |
2454 | this->ranges.s.section = sectp; |
2455 | this->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 2456 | } |
330cdd98 | 2457 | else if (section_is_p (sectp->name, &names.rnglists)) |
43988095 | 2458 | { |
330cdd98 PA |
2459 | this->rnglists.s.section = sectp; |
2460 | this->rnglists.size = bfd_get_section_size (sectp); | |
43988095 | 2461 | } |
330cdd98 | 2462 | else if (section_is_p (sectp->name, &names.types)) |
348e048f | 2463 | { |
8b70b953 TT |
2464 | struct dwarf2_section_info type_section; |
2465 | ||
2466 | memset (&type_section, 0, sizeof (type_section)); | |
049412e3 | 2467 | type_section.s.section = sectp; |
8b70b953 TT |
2468 | type_section.size = bfd_get_section_size (sectp); |
2469 | ||
330cdd98 | 2470 | VEC_safe_push (dwarf2_section_info_def, this->types, |
8b70b953 | 2471 | &type_section); |
348e048f | 2472 | } |
330cdd98 | 2473 | else if (section_is_p (sectp->name, &names.gdb_index)) |
9291a0cd | 2474 | { |
330cdd98 PA |
2475 | this->gdb_index.s.section = sectp; |
2476 | this->gdb_index.size = bfd_get_section_size (sectp); | |
9291a0cd | 2477 | } |
dce234bc | 2478 | |
b4e1fd61 | 2479 | if ((bfd_get_section_flags (abfd, sectp) & (SEC_LOAD | SEC_ALLOC)) |
72dca2f5 | 2480 | && bfd_section_vma (abfd, sectp) == 0) |
330cdd98 | 2481 | this->has_section_at_zero = true; |
c906108c SS |
2482 | } |
2483 | ||
fceca515 DE |
2484 | /* A helper function that decides whether a section is empty, |
2485 | or not present. */ | |
9e0ac564 TT |
2486 | |
2487 | static int | |
19ac8c2e | 2488 | dwarf2_section_empty_p (const struct dwarf2_section_info *section) |
9e0ac564 | 2489 | { |
73869dc2 DE |
2490 | if (section->is_virtual) |
2491 | return section->size == 0; | |
049412e3 | 2492 | return section->s.section == NULL || section->size == 0; |
9e0ac564 TT |
2493 | } |
2494 | ||
3019eac3 DE |
2495 | /* Read the contents of the section INFO. |
2496 | OBJFILE is the main object file, but not necessarily the file where | |
a32a8923 DE |
2497 | the section comes from. E.g., for DWO files the bfd of INFO is the bfd |
2498 | of the DWO file. | |
dce234bc | 2499 | If the section is compressed, uncompress it before returning. */ |
c906108c | 2500 | |
dce234bc PP |
2501 | static void |
2502 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 2503 | { |
a32a8923 | 2504 | asection *sectp; |
3019eac3 | 2505 | bfd *abfd; |
dce234bc | 2506 | gdb_byte *buf, *retbuf; |
c906108c | 2507 | |
be391dca TT |
2508 | if (info->readin) |
2509 | return; | |
dce234bc | 2510 | info->buffer = NULL; |
be391dca | 2511 | info->readin = 1; |
188dd5d6 | 2512 | |
9e0ac564 | 2513 | if (dwarf2_section_empty_p (info)) |
dce234bc | 2514 | return; |
c906108c | 2515 | |
a32a8923 | 2516 | sectp = get_section_bfd_section (info); |
3019eac3 | 2517 | |
73869dc2 DE |
2518 | /* If this is a virtual section we need to read in the real one first. */ |
2519 | if (info->is_virtual) | |
2520 | { | |
2521 | struct dwarf2_section_info *containing_section = | |
2522 | get_containing_section (info); | |
2523 | ||
2524 | gdb_assert (sectp != NULL); | |
2525 | if ((sectp->flags & SEC_RELOC) != 0) | |
2526 | { | |
2527 | error (_("Dwarf Error: DWP format V2 with relocations is not" | |
2528 | " supported in section %s [in module %s]"), | |
2529 | get_section_name (info), get_section_file_name (info)); | |
2530 | } | |
2531 | dwarf2_read_section (objfile, containing_section); | |
2532 | /* Other code should have already caught virtual sections that don't | |
2533 | fit. */ | |
2534 | gdb_assert (info->virtual_offset + info->size | |
2535 | <= containing_section->size); | |
2536 | /* If the real section is empty or there was a problem reading the | |
2537 | section we shouldn't get here. */ | |
2538 | gdb_assert (containing_section->buffer != NULL); | |
2539 | info->buffer = containing_section->buffer + info->virtual_offset; | |
2540 | return; | |
2541 | } | |
2542 | ||
4bf44c1c TT |
2543 | /* If the section has relocations, we must read it ourselves. |
2544 | Otherwise we attach it to the BFD. */ | |
2545 | if ((sectp->flags & SEC_RELOC) == 0) | |
dce234bc | 2546 | { |
d521ce57 | 2547 | info->buffer = gdb_bfd_map_section (sectp, &info->size); |
4bf44c1c | 2548 | return; |
dce234bc | 2549 | } |
dce234bc | 2550 | |
224c3ddb | 2551 | buf = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, info->size); |
4bf44c1c | 2552 | info->buffer = buf; |
dce234bc PP |
2553 | |
2554 | /* When debugging .o files, we may need to apply relocations; see | |
2555 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
2556 | We never compress sections in .o files, so we only need to | |
2557 | try this when the section is not compressed. */ | |
ac8035ab | 2558 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
2559 | if (retbuf != NULL) |
2560 | { | |
2561 | info->buffer = retbuf; | |
2562 | return; | |
2563 | } | |
2564 | ||
a32a8923 DE |
2565 | abfd = get_section_bfd_owner (info); |
2566 | gdb_assert (abfd != NULL); | |
2567 | ||
dce234bc PP |
2568 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
2569 | || bfd_bread (buf, info->size, abfd) != info->size) | |
19ac8c2e DE |
2570 | { |
2571 | error (_("Dwarf Error: Can't read DWARF data" | |
2572 | " in section %s [in module %s]"), | |
2573 | bfd_section_name (abfd, sectp), bfd_get_filename (abfd)); | |
2574 | } | |
dce234bc PP |
2575 | } |
2576 | ||
9e0ac564 TT |
2577 | /* A helper function that returns the size of a section in a safe way. |
2578 | If you are positive that the section has been read before using the | |
2579 | size, then it is safe to refer to the dwarf2_section_info object's | |
2580 | "size" field directly. In other cases, you must call this | |
2581 | function, because for compressed sections the size field is not set | |
2582 | correctly until the section has been read. */ | |
2583 | ||
2584 | static bfd_size_type | |
2585 | dwarf2_section_size (struct objfile *objfile, | |
2586 | struct dwarf2_section_info *info) | |
2587 | { | |
2588 | if (!info->readin) | |
2589 | dwarf2_read_section (objfile, info); | |
2590 | return info->size; | |
2591 | } | |
2592 | ||
dce234bc | 2593 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 2594 | SECTION_NAME. */ |
af34e669 | 2595 | |
dce234bc | 2596 | void |
3017a003 TG |
2597 | dwarf2_get_section_info (struct objfile *objfile, |
2598 | enum dwarf2_section_enum sect, | |
d521ce57 | 2599 | asection **sectp, const gdb_byte **bufp, |
dce234bc PP |
2600 | bfd_size_type *sizep) |
2601 | { | |
2602 | struct dwarf2_per_objfile *data | |
9a3c8263 SM |
2603 | = (struct dwarf2_per_objfile *) objfile_data (objfile, |
2604 | dwarf2_objfile_data_key); | |
dce234bc | 2605 | struct dwarf2_section_info *info; |
a3b2a86b TT |
2606 | |
2607 | /* We may see an objfile without any DWARF, in which case we just | |
2608 | return nothing. */ | |
2609 | if (data == NULL) | |
2610 | { | |
2611 | *sectp = NULL; | |
2612 | *bufp = NULL; | |
2613 | *sizep = 0; | |
2614 | return; | |
2615 | } | |
3017a003 TG |
2616 | switch (sect) |
2617 | { | |
2618 | case DWARF2_DEBUG_FRAME: | |
2619 | info = &data->frame; | |
2620 | break; | |
2621 | case DWARF2_EH_FRAME: | |
2622 | info = &data->eh_frame; | |
2623 | break; | |
2624 | default: | |
2625 | gdb_assert_not_reached ("unexpected section"); | |
2626 | } | |
dce234bc | 2627 | |
9e0ac564 | 2628 | dwarf2_read_section (objfile, info); |
dce234bc | 2629 | |
a32a8923 | 2630 | *sectp = get_section_bfd_section (info); |
dce234bc PP |
2631 | *bufp = info->buffer; |
2632 | *sizep = info->size; | |
2633 | } | |
2634 | ||
36586728 TT |
2635 | /* A helper function to find the sections for a .dwz file. */ |
2636 | ||
2637 | static void | |
2638 | locate_dwz_sections (bfd *abfd, asection *sectp, void *arg) | |
2639 | { | |
9a3c8263 | 2640 | struct dwz_file *dwz_file = (struct dwz_file *) arg; |
36586728 TT |
2641 | |
2642 | /* Note that we only support the standard ELF names, because .dwz | |
2643 | is ELF-only (at the time of writing). */ | |
2644 | if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev)) | |
2645 | { | |
049412e3 | 2646 | dwz_file->abbrev.s.section = sectp; |
36586728 TT |
2647 | dwz_file->abbrev.size = bfd_get_section_size (sectp); |
2648 | } | |
2649 | else if (section_is_p (sectp->name, &dwarf2_elf_names.info)) | |
2650 | { | |
049412e3 | 2651 | dwz_file->info.s.section = sectp; |
36586728 TT |
2652 | dwz_file->info.size = bfd_get_section_size (sectp); |
2653 | } | |
2654 | else if (section_is_p (sectp->name, &dwarf2_elf_names.str)) | |
2655 | { | |
049412e3 | 2656 | dwz_file->str.s.section = sectp; |
36586728 TT |
2657 | dwz_file->str.size = bfd_get_section_size (sectp); |
2658 | } | |
2659 | else if (section_is_p (sectp->name, &dwarf2_elf_names.line)) | |
2660 | { | |
049412e3 | 2661 | dwz_file->line.s.section = sectp; |
36586728 TT |
2662 | dwz_file->line.size = bfd_get_section_size (sectp); |
2663 | } | |
2664 | else if (section_is_p (sectp->name, &dwarf2_elf_names.macro)) | |
2665 | { | |
049412e3 | 2666 | dwz_file->macro.s.section = sectp; |
36586728 TT |
2667 | dwz_file->macro.size = bfd_get_section_size (sectp); |
2668 | } | |
2ec9a5e0 TT |
2669 | else if (section_is_p (sectp->name, &dwarf2_elf_names.gdb_index)) |
2670 | { | |
049412e3 | 2671 | dwz_file->gdb_index.s.section = sectp; |
2ec9a5e0 TT |
2672 | dwz_file->gdb_index.size = bfd_get_section_size (sectp); |
2673 | } | |
36586728 TT |
2674 | } |
2675 | ||
4db1a1dc TT |
2676 | /* Open the separate '.dwz' debug file, if needed. Return NULL if |
2677 | there is no .gnu_debugaltlink section in the file. Error if there | |
2678 | is such a section but the file cannot be found. */ | |
36586728 TT |
2679 | |
2680 | static struct dwz_file * | |
2681 | dwarf2_get_dwz_file (void) | |
2682 | { | |
4db1a1dc | 2683 | char *data; |
36586728 TT |
2684 | struct cleanup *cleanup; |
2685 | const char *filename; | |
2686 | struct dwz_file *result; | |
acd13123 | 2687 | bfd_size_type buildid_len_arg; |
dc294be5 TT |
2688 | size_t buildid_len; |
2689 | bfd_byte *buildid; | |
36586728 TT |
2690 | |
2691 | if (dwarf2_per_objfile->dwz_file != NULL) | |
2692 | return dwarf2_per_objfile->dwz_file; | |
2693 | ||
4db1a1dc TT |
2694 | bfd_set_error (bfd_error_no_error); |
2695 | data = bfd_get_alt_debug_link_info (dwarf2_per_objfile->objfile->obfd, | |
acd13123 | 2696 | &buildid_len_arg, &buildid); |
4db1a1dc TT |
2697 | if (data == NULL) |
2698 | { | |
2699 | if (bfd_get_error () == bfd_error_no_error) | |
2700 | return NULL; | |
2701 | error (_("could not read '.gnu_debugaltlink' section: %s"), | |
2702 | bfd_errmsg (bfd_get_error ())); | |
2703 | } | |
36586728 | 2704 | cleanup = make_cleanup (xfree, data); |
dc294be5 | 2705 | make_cleanup (xfree, buildid); |
36586728 | 2706 | |
acd13123 TT |
2707 | buildid_len = (size_t) buildid_len_arg; |
2708 | ||
f9d83a0b | 2709 | filename = (const char *) data; |
d721ba37 PA |
2710 | |
2711 | std::string abs_storage; | |
36586728 TT |
2712 | if (!IS_ABSOLUTE_PATH (filename)) |
2713 | { | |
4262abfb | 2714 | char *abs = gdb_realpath (objfile_name (dwarf2_per_objfile->objfile)); |
36586728 TT |
2715 | |
2716 | make_cleanup (xfree, abs); | |
d721ba37 PA |
2717 | abs_storage = ldirname (abs) + SLASH_STRING + filename; |
2718 | filename = abs_storage.c_str (); | |
36586728 TT |
2719 | } |
2720 | ||
dc294be5 TT |
2721 | /* First try the file name given in the section. If that doesn't |
2722 | work, try to use the build-id instead. */ | |
192b62ce | 2723 | gdb_bfd_ref_ptr dwz_bfd (gdb_bfd_open (filename, gnutarget, -1)); |
dc294be5 | 2724 | if (dwz_bfd != NULL) |
36586728 | 2725 | { |
192b62ce TT |
2726 | if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid)) |
2727 | dwz_bfd.release (); | |
36586728 TT |
2728 | } |
2729 | ||
dc294be5 TT |
2730 | if (dwz_bfd == NULL) |
2731 | dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid); | |
2732 | ||
2733 | if (dwz_bfd == NULL) | |
2734 | error (_("could not find '.gnu_debugaltlink' file for %s"), | |
2735 | objfile_name (dwarf2_per_objfile->objfile)); | |
2736 | ||
36586728 TT |
2737 | result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack, |
2738 | struct dwz_file); | |
192b62ce | 2739 | result->dwz_bfd = dwz_bfd.release (); |
36586728 | 2740 | |
192b62ce | 2741 | bfd_map_over_sections (result->dwz_bfd, locate_dwz_sections, result); |
36586728 TT |
2742 | |
2743 | do_cleanups (cleanup); | |
2744 | ||
192b62ce | 2745 | gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, result->dwz_bfd); |
8d2cc612 | 2746 | dwarf2_per_objfile->dwz_file = result; |
36586728 TT |
2747 | return result; |
2748 | } | |
9291a0cd | 2749 | \f |
7b9f3c50 DE |
2750 | /* DWARF quick_symbols_functions support. */ |
2751 | ||
2752 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
2753 | unique line tables, so we maintain a separate table of all .debug_line | |
2754 | derived entries to support the sharing. | |
2755 | All the quick functions need is the list of file names. We discard the | |
2756 | line_header when we're done and don't need to record it here. */ | |
2757 | struct quick_file_names | |
2758 | { | |
094b34ac DE |
2759 | /* The data used to construct the hash key. */ |
2760 | struct stmt_list_hash hash; | |
7b9f3c50 DE |
2761 | |
2762 | /* The number of entries in file_names, real_names. */ | |
2763 | unsigned int num_file_names; | |
2764 | ||
2765 | /* The file names from the line table, after being run through | |
2766 | file_full_name. */ | |
2767 | const char **file_names; | |
2768 | ||
2769 | /* The file names from the line table after being run through | |
2770 | gdb_realpath. These are computed lazily. */ | |
2771 | const char **real_names; | |
2772 | }; | |
2773 | ||
2774 | /* When using the index (and thus not using psymtabs), each CU has an | |
2775 | object of this type. This is used to hold information needed by | |
2776 | the various "quick" methods. */ | |
2777 | struct dwarf2_per_cu_quick_data | |
2778 | { | |
2779 | /* The file table. This can be NULL if there was no file table | |
2780 | or it's currently not read in. | |
2781 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
2782 | struct quick_file_names *file_names; | |
2783 | ||
2784 | /* The corresponding symbol table. This is NULL if symbols for this | |
2785 | CU have not yet been read. */ | |
43f3e411 | 2786 | struct compunit_symtab *compunit_symtab; |
7b9f3c50 DE |
2787 | |
2788 | /* A temporary mark bit used when iterating over all CUs in | |
2789 | expand_symtabs_matching. */ | |
2790 | unsigned int mark : 1; | |
2791 | ||
2792 | /* True if we've tried to read the file table and found there isn't one. | |
2793 | There will be no point in trying to read it again next time. */ | |
2794 | unsigned int no_file_data : 1; | |
2795 | }; | |
2796 | ||
094b34ac DE |
2797 | /* Utility hash function for a stmt_list_hash. */ |
2798 | ||
2799 | static hashval_t | |
2800 | hash_stmt_list_entry (const struct stmt_list_hash *stmt_list_hash) | |
2801 | { | |
2802 | hashval_t v = 0; | |
2803 | ||
2804 | if (stmt_list_hash->dwo_unit != NULL) | |
2805 | v += (uintptr_t) stmt_list_hash->dwo_unit->dwo_file; | |
9c541725 | 2806 | v += to_underlying (stmt_list_hash->line_sect_off); |
094b34ac DE |
2807 | return v; |
2808 | } | |
2809 | ||
2810 | /* Utility equality function for a stmt_list_hash. */ | |
2811 | ||
2812 | static int | |
2813 | eq_stmt_list_entry (const struct stmt_list_hash *lhs, | |
2814 | const struct stmt_list_hash *rhs) | |
2815 | { | |
2816 | if ((lhs->dwo_unit != NULL) != (rhs->dwo_unit != NULL)) | |
2817 | return 0; | |
2818 | if (lhs->dwo_unit != NULL | |
2819 | && lhs->dwo_unit->dwo_file != rhs->dwo_unit->dwo_file) | |
2820 | return 0; | |
2821 | ||
9c541725 | 2822 | return lhs->line_sect_off == rhs->line_sect_off; |
094b34ac DE |
2823 | } |
2824 | ||
7b9f3c50 DE |
2825 | /* Hash function for a quick_file_names. */ |
2826 | ||
2827 | static hashval_t | |
2828 | hash_file_name_entry (const void *e) | |
2829 | { | |
9a3c8263 SM |
2830 | const struct quick_file_names *file_data |
2831 | = (const struct quick_file_names *) e; | |
7b9f3c50 | 2832 | |
094b34ac | 2833 | return hash_stmt_list_entry (&file_data->hash); |
7b9f3c50 DE |
2834 | } |
2835 | ||
2836 | /* Equality function for a quick_file_names. */ | |
2837 | ||
2838 | static int | |
2839 | eq_file_name_entry (const void *a, const void *b) | |
2840 | { | |
9a3c8263 SM |
2841 | const struct quick_file_names *ea = (const struct quick_file_names *) a; |
2842 | const struct quick_file_names *eb = (const struct quick_file_names *) b; | |
7b9f3c50 | 2843 | |
094b34ac | 2844 | return eq_stmt_list_entry (&ea->hash, &eb->hash); |
7b9f3c50 DE |
2845 | } |
2846 | ||
2847 | /* Delete function for a quick_file_names. */ | |
2848 | ||
2849 | static void | |
2850 | delete_file_name_entry (void *e) | |
2851 | { | |
9a3c8263 | 2852 | struct quick_file_names *file_data = (struct quick_file_names *) e; |
7b9f3c50 DE |
2853 | int i; |
2854 | ||
2855 | for (i = 0; i < file_data->num_file_names; ++i) | |
2856 | { | |
2857 | xfree ((void*) file_data->file_names[i]); | |
2858 | if (file_data->real_names) | |
2859 | xfree ((void*) file_data->real_names[i]); | |
2860 | } | |
2861 | ||
2862 | /* The space for the struct itself lives on objfile_obstack, | |
2863 | so we don't free it here. */ | |
2864 | } | |
2865 | ||
2866 | /* Create a quick_file_names hash table. */ | |
2867 | ||
2868 | static htab_t | |
2869 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
2870 | { | |
2871 | return htab_create_alloc (nr_initial_entries, | |
2872 | hash_file_name_entry, eq_file_name_entry, | |
2873 | delete_file_name_entry, xcalloc, xfree); | |
2874 | } | |
9291a0cd | 2875 | |
918dd910 JK |
2876 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
2877 | have to be created afterwards. You should call age_cached_comp_units after | |
2878 | processing PER_CU->CU. dw2_setup must have been already called. */ | |
2879 | ||
2880 | static void | |
2881 | load_cu (struct dwarf2_per_cu_data *per_cu) | |
2882 | { | |
3019eac3 | 2883 | if (per_cu->is_debug_types) |
e5fe5e75 | 2884 | load_full_type_unit (per_cu); |
918dd910 | 2885 | else |
95554aad | 2886 | load_full_comp_unit (per_cu, language_minimal); |
918dd910 | 2887 | |
cc12ce38 DE |
2888 | if (per_cu->cu == NULL) |
2889 | return; /* Dummy CU. */ | |
2dc860c0 DE |
2890 | |
2891 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); | |
918dd910 JK |
2892 | } |
2893 | ||
a0f42c21 | 2894 | /* Read in the symbols for PER_CU. */ |
2fdf6df6 | 2895 | |
9291a0cd | 2896 | static void |
a0f42c21 | 2897 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
2898 | { |
2899 | struct cleanup *back_to; | |
2900 | ||
f4dc4d17 DE |
2901 | /* Skip type_unit_groups, reading the type units they contain |
2902 | is handled elsewhere. */ | |
2903 | if (IS_TYPE_UNIT_GROUP (per_cu)) | |
2904 | return; | |
2905 | ||
9291a0cd TT |
2906 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
2907 | ||
95554aad | 2908 | if (dwarf2_per_objfile->using_index |
43f3e411 | 2909 | ? per_cu->v.quick->compunit_symtab == NULL |
95554aad TT |
2910 | : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin)) |
2911 | { | |
2912 | queue_comp_unit (per_cu, language_minimal); | |
2913 | load_cu (per_cu); | |
89e63ee4 DE |
2914 | |
2915 | /* If we just loaded a CU from a DWO, and we're working with an index | |
2916 | that may badly handle TUs, load all the TUs in that DWO as well. | |
2917 | http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */ | |
2918 | if (!per_cu->is_debug_types | |
cc12ce38 | 2919 | && per_cu->cu != NULL |
89e63ee4 DE |
2920 | && per_cu->cu->dwo_unit != NULL |
2921 | && dwarf2_per_objfile->index_table != NULL | |
2922 | && dwarf2_per_objfile->index_table->version <= 7 | |
2923 | /* DWP files aren't supported yet. */ | |
2924 | && get_dwp_file () == NULL) | |
2925 | queue_and_load_all_dwo_tus (per_cu); | |
95554aad | 2926 | } |
9291a0cd | 2927 | |
a0f42c21 | 2928 | process_queue (); |
9291a0cd TT |
2929 | |
2930 | /* Age the cache, releasing compilation units that have not | |
2931 | been used recently. */ | |
2932 | age_cached_comp_units (); | |
2933 | ||
2934 | do_cleanups (back_to); | |
2935 | } | |
2936 | ||
2937 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
2938 | the objfile from which this CU came. Returns the resulting symbol | |
2939 | table. */ | |
2fdf6df6 | 2940 | |
43f3e411 | 2941 | static struct compunit_symtab * |
a0f42c21 | 2942 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd | 2943 | { |
95554aad | 2944 | gdb_assert (dwarf2_per_objfile->using_index); |
43f3e411 | 2945 | if (!per_cu->v.quick->compunit_symtab) |
9291a0cd TT |
2946 | { |
2947 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
c83dd867 | 2948 | scoped_restore decrementer = increment_reading_symtab (); |
a0f42c21 | 2949 | dw2_do_instantiate_symtab (per_cu); |
95554aad | 2950 | process_cu_includes (); |
9291a0cd TT |
2951 | do_cleanups (back_to); |
2952 | } | |
f194fefb | 2953 | |
43f3e411 | 2954 | return per_cu->v.quick->compunit_symtab; |
9291a0cd TT |
2955 | } |
2956 | ||
8832e7e3 | 2957 | /* Return the CU/TU given its index. |
f4dc4d17 DE |
2958 | |
2959 | This is intended for loops like: | |
2960 | ||
2961 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2962 | + dwarf2_per_objfile->n_type_units); ++i) | |
2963 | { | |
8832e7e3 | 2964 | struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i); |
f4dc4d17 DE |
2965 | |
2966 | ...; | |
2967 | } | |
2968 | */ | |
2fdf6df6 | 2969 | |
1fd400ff | 2970 | static struct dwarf2_per_cu_data * |
8832e7e3 | 2971 | dw2_get_cutu (int index) |
1fd400ff TT |
2972 | { |
2973 | if (index >= dwarf2_per_objfile->n_comp_units) | |
2974 | { | |
f4dc4d17 | 2975 | index -= dwarf2_per_objfile->n_comp_units; |
094b34ac DE |
2976 | gdb_assert (index < dwarf2_per_objfile->n_type_units); |
2977 | return &dwarf2_per_objfile->all_type_units[index]->per_cu; | |
f4dc4d17 DE |
2978 | } |
2979 | ||
2980 | return dwarf2_per_objfile->all_comp_units[index]; | |
2981 | } | |
2982 | ||
8832e7e3 DE |
2983 | /* Return the CU given its index. |
2984 | This differs from dw2_get_cutu in that it's for when you know INDEX | |
2985 | refers to a CU. */ | |
f4dc4d17 DE |
2986 | |
2987 | static struct dwarf2_per_cu_data * | |
8832e7e3 | 2988 | dw2_get_cu (int index) |
f4dc4d17 | 2989 | { |
8832e7e3 | 2990 | gdb_assert (index >= 0 && index < dwarf2_per_objfile->n_comp_units); |
f4dc4d17 | 2991 | |
1fd400ff TT |
2992 | return dwarf2_per_objfile->all_comp_units[index]; |
2993 | } | |
2994 | ||
2ec9a5e0 TT |
2995 | /* A helper for create_cus_from_index that handles a given list of |
2996 | CUs. */ | |
2fdf6df6 | 2997 | |
74a0d9f6 | 2998 | static void |
2ec9a5e0 TT |
2999 | create_cus_from_index_list (struct objfile *objfile, |
3000 | const gdb_byte *cu_list, offset_type n_elements, | |
3001 | struct dwarf2_section_info *section, | |
3002 | int is_dwz, | |
3003 | int base_offset) | |
9291a0cd TT |
3004 | { |
3005 | offset_type i; | |
9291a0cd | 3006 | |
2ec9a5e0 | 3007 | for (i = 0; i < n_elements; i += 2) |
9291a0cd | 3008 | { |
74a0d9f6 | 3009 | gdb_static_assert (sizeof (ULONGEST) >= 8); |
9c541725 PA |
3010 | |
3011 | sect_offset sect_off | |
3012 | = (sect_offset) extract_unsigned_integer (cu_list, 8, BFD_ENDIAN_LITTLE); | |
3013 | ULONGEST length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE); | |
9291a0cd TT |
3014 | cu_list += 2 * 8; |
3015 | ||
9c541725 PA |
3016 | dwarf2_per_cu_data *the_cu |
3017 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
3018 | struct dwarf2_per_cu_data); | |
3019 | the_cu->sect_off = sect_off; | |
9291a0cd TT |
3020 | the_cu->length = length; |
3021 | the_cu->objfile = objfile; | |
8a0459fd | 3022 | the_cu->section = section; |
9291a0cd TT |
3023 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
3024 | struct dwarf2_per_cu_quick_data); | |
2ec9a5e0 TT |
3025 | the_cu->is_dwz = is_dwz; |
3026 | dwarf2_per_objfile->all_comp_units[base_offset + i / 2] = the_cu; | |
9291a0cd | 3027 | } |
9291a0cd TT |
3028 | } |
3029 | ||
2ec9a5e0 | 3030 | /* Read the CU list from the mapped index, and use it to create all |
74a0d9f6 | 3031 | the CU objects for this objfile. */ |
2ec9a5e0 | 3032 | |
74a0d9f6 | 3033 | static void |
2ec9a5e0 TT |
3034 | create_cus_from_index (struct objfile *objfile, |
3035 | const gdb_byte *cu_list, offset_type cu_list_elements, | |
3036 | const gdb_byte *dwz_list, offset_type dwz_elements) | |
3037 | { | |
3038 | struct dwz_file *dwz; | |
3039 | ||
3040 | dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2; | |
8d749320 SM |
3041 | dwarf2_per_objfile->all_comp_units = |
3042 | XOBNEWVEC (&objfile->objfile_obstack, struct dwarf2_per_cu_data *, | |
3043 | dwarf2_per_objfile->n_comp_units); | |
2ec9a5e0 | 3044 | |
74a0d9f6 JK |
3045 | create_cus_from_index_list (objfile, cu_list, cu_list_elements, |
3046 | &dwarf2_per_objfile->info, 0, 0); | |
2ec9a5e0 TT |
3047 | |
3048 | if (dwz_elements == 0) | |
74a0d9f6 | 3049 | return; |
2ec9a5e0 TT |
3050 | |
3051 | dwz = dwarf2_get_dwz_file (); | |
74a0d9f6 JK |
3052 | create_cus_from_index_list (objfile, dwz_list, dwz_elements, &dwz->info, 1, |
3053 | cu_list_elements / 2); | |
2ec9a5e0 TT |
3054 | } |
3055 | ||
1fd400ff | 3056 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 3057 | |
74a0d9f6 | 3058 | static void |
673bfd45 | 3059 | create_signatured_type_table_from_index (struct objfile *objfile, |
8b70b953 | 3060 | struct dwarf2_section_info *section, |
673bfd45 DE |
3061 | const gdb_byte *bytes, |
3062 | offset_type elements) | |
1fd400ff TT |
3063 | { |
3064 | offset_type i; | |
673bfd45 | 3065 | htab_t sig_types_hash; |
1fd400ff | 3066 | |
6aa5f3a6 DE |
3067 | dwarf2_per_objfile->n_type_units |
3068 | = dwarf2_per_objfile->n_allocated_type_units | |
3069 | = elements / 3; | |
8d749320 SM |
3070 | dwarf2_per_objfile->all_type_units = |
3071 | XNEWVEC (struct signatured_type *, dwarf2_per_objfile->n_type_units); | |
1fd400ff | 3072 | |
673bfd45 | 3073 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
3074 | |
3075 | for (i = 0; i < elements; i += 3) | |
3076 | { | |
52dc124a | 3077 | struct signatured_type *sig_type; |
9c541725 | 3078 | ULONGEST signature; |
1fd400ff | 3079 | void **slot; |
9c541725 | 3080 | cu_offset type_offset_in_tu; |
1fd400ff | 3081 | |
74a0d9f6 | 3082 | gdb_static_assert (sizeof (ULONGEST) >= 8); |
9c541725 PA |
3083 | sect_offset sect_off |
3084 | = (sect_offset) extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
3085 | type_offset_in_tu | |
3086 | = (cu_offset) extract_unsigned_integer (bytes + 8, 8, | |
3087 | BFD_ENDIAN_LITTLE); | |
1fd400ff TT |
3088 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); |
3089 | bytes += 3 * 8; | |
3090 | ||
52dc124a | 3091 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
1fd400ff | 3092 | struct signatured_type); |
52dc124a | 3093 | sig_type->signature = signature; |
9c541725 | 3094 | sig_type->type_offset_in_tu = type_offset_in_tu; |
3019eac3 | 3095 | sig_type->per_cu.is_debug_types = 1; |
8a0459fd | 3096 | sig_type->per_cu.section = section; |
9c541725 | 3097 | sig_type->per_cu.sect_off = sect_off; |
52dc124a DE |
3098 | sig_type->per_cu.objfile = objfile; |
3099 | sig_type->per_cu.v.quick | |
1fd400ff TT |
3100 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
3101 | struct dwarf2_per_cu_quick_data); | |
3102 | ||
52dc124a DE |
3103 | slot = htab_find_slot (sig_types_hash, sig_type, INSERT); |
3104 | *slot = sig_type; | |
1fd400ff | 3105 | |
b4dd5633 | 3106 | dwarf2_per_objfile->all_type_units[i / 3] = sig_type; |
1fd400ff TT |
3107 | } |
3108 | ||
673bfd45 | 3109 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
3110 | } |
3111 | ||
9291a0cd TT |
3112 | /* Read the address map data from the mapped index, and use it to |
3113 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 3114 | |
9291a0cd TT |
3115 | static void |
3116 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
3117 | { | |
3e29f34a | 3118 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9291a0cd | 3119 | const gdb_byte *iter, *end; |
9291a0cd | 3120 | struct addrmap *mutable_map; |
9291a0cd TT |
3121 | CORE_ADDR baseaddr; |
3122 | ||
8268c778 PA |
3123 | auto_obstack temp_obstack; |
3124 | ||
9291a0cd TT |
3125 | mutable_map = addrmap_create_mutable (&temp_obstack); |
3126 | ||
3127 | iter = index->address_table; | |
3128 | end = iter + index->address_table_size; | |
3129 | ||
3130 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3131 | ||
3132 | while (iter < end) | |
3133 | { | |
3134 | ULONGEST hi, lo, cu_index; | |
3135 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
3136 | iter += 8; | |
3137 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
3138 | iter += 8; | |
3139 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
3140 | iter += 4; | |
f652bce2 | 3141 | |
24a55014 | 3142 | if (lo > hi) |
f652bce2 | 3143 | { |
24a55014 DE |
3144 | complaint (&symfile_complaints, |
3145 | _(".gdb_index address table has invalid range (%s - %s)"), | |
c0cd8254 | 3146 | hex_string (lo), hex_string (hi)); |
24a55014 | 3147 | continue; |
f652bce2 | 3148 | } |
24a55014 DE |
3149 | |
3150 | if (cu_index >= dwarf2_per_objfile->n_comp_units) | |
f652bce2 DE |
3151 | { |
3152 | complaint (&symfile_complaints, | |
3153 | _(".gdb_index address table has invalid CU number %u"), | |
3154 | (unsigned) cu_index); | |
24a55014 | 3155 | continue; |
f652bce2 | 3156 | } |
24a55014 | 3157 | |
3e29f34a MR |
3158 | lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr); |
3159 | hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr); | |
3160 | addrmap_set_empty (mutable_map, lo, hi - 1, dw2_get_cutu (cu_index)); | |
9291a0cd TT |
3161 | } |
3162 | ||
3163 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
3164 | &objfile->objfile_obstack); | |
9291a0cd TT |
3165 | } |
3166 | ||
59d7bcaf JK |
3167 | /* The hash function for strings in the mapped index. This is the same as |
3168 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
3169 | implementation. This is necessary because the hash function is tied to the | |
3170 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
3171 | SYMBOL_HASH_NEXT. |
3172 | ||
3173 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 3174 | |
9291a0cd | 3175 | static hashval_t |
559a7a62 | 3176 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
3177 | { |
3178 | const unsigned char *str = (const unsigned char *) p; | |
3179 | hashval_t r = 0; | |
3180 | unsigned char c; | |
3181 | ||
3182 | while ((c = *str++) != 0) | |
559a7a62 JK |
3183 | { |
3184 | if (index_version >= 5) | |
3185 | c = tolower (c); | |
3186 | r = r * 67 + c - 113; | |
3187 | } | |
9291a0cd TT |
3188 | |
3189 | return r; | |
3190 | } | |
3191 | ||
3192 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
3193 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
3194 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 3195 | |
9291a0cd TT |
3196 | static int |
3197 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
3198 | offset_type **vec_out) | |
3199 | { | |
0cf03b49 JK |
3200 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
3201 | offset_type hash; | |
9291a0cd | 3202 | offset_type slot, step; |
559a7a62 | 3203 | int (*cmp) (const char *, const char *); |
9291a0cd | 3204 | |
0cf03b49 | 3205 | if (current_language->la_language == language_cplus |
45280282 IB |
3206 | || current_language->la_language == language_fortran |
3207 | || current_language->la_language == language_d) | |
0cf03b49 JK |
3208 | { |
3209 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
3210 | not contain any. */ | |
a8719064 | 3211 | |
72998fb3 | 3212 | if (strchr (name, '(') != NULL) |
0cf03b49 | 3213 | { |
72998fb3 | 3214 | char *without_params = cp_remove_params (name); |
0cf03b49 | 3215 | |
72998fb3 DE |
3216 | if (without_params != NULL) |
3217 | { | |
3218 | make_cleanup (xfree, without_params); | |
3219 | name = without_params; | |
3220 | } | |
0cf03b49 JK |
3221 | } |
3222 | } | |
3223 | ||
559a7a62 | 3224 | /* Index version 4 did not support case insensitive searches. But the |
feea76c2 | 3225 | indices for case insensitive languages are built in lowercase, therefore |
559a7a62 JK |
3226 | simulate our NAME being searched is also lowercased. */ |
3227 | hash = mapped_index_string_hash ((index->version == 4 | |
3228 | && case_sensitivity == case_sensitive_off | |
3229 | ? 5 : index->version), | |
3230 | name); | |
3231 | ||
3876f04e DE |
3232 | slot = hash & (index->symbol_table_slots - 1); |
3233 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 3234 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
3235 | |
3236 | for (;;) | |
3237 | { | |
3238 | /* Convert a slot number to an offset into the table. */ | |
3239 | offset_type i = 2 * slot; | |
3240 | const char *str; | |
3876f04e | 3241 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
3242 | { |
3243 | do_cleanups (back_to); | |
3244 | return 0; | |
3245 | } | |
9291a0cd | 3246 | |
3876f04e | 3247 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 3248 | if (!cmp (name, str)) |
9291a0cd TT |
3249 | { |
3250 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 3251 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 3252 | do_cleanups (back_to); |
9291a0cd TT |
3253 | return 1; |
3254 | } | |
3255 | ||
3876f04e | 3256 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
3257 | } |
3258 | } | |
3259 | ||
2ec9a5e0 TT |
3260 | /* A helper function that reads the .gdb_index from SECTION and fills |
3261 | in MAP. FILENAME is the name of the file containing the section; | |
3262 | it is used for error reporting. DEPRECATED_OK is nonzero if it is | |
3263 | ok to use deprecated sections. | |
3264 | ||
3265 | CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are | |
3266 | out parameters that are filled in with information about the CU and | |
3267 | TU lists in the section. | |
3268 | ||
3269 | Returns 1 if all went well, 0 otherwise. */ | |
2fdf6df6 | 3270 | |
9291a0cd | 3271 | static int |
2ec9a5e0 TT |
3272 | read_index_from_section (struct objfile *objfile, |
3273 | const char *filename, | |
3274 | int deprecated_ok, | |
3275 | struct dwarf2_section_info *section, | |
3276 | struct mapped_index *map, | |
3277 | const gdb_byte **cu_list, | |
3278 | offset_type *cu_list_elements, | |
3279 | const gdb_byte **types_list, | |
3280 | offset_type *types_list_elements) | |
9291a0cd | 3281 | { |
948f8e3d | 3282 | const gdb_byte *addr; |
2ec9a5e0 | 3283 | offset_type version; |
b3b272e1 | 3284 | offset_type *metadata; |
1fd400ff | 3285 | int i; |
9291a0cd | 3286 | |
2ec9a5e0 | 3287 | if (dwarf2_section_empty_p (section)) |
9291a0cd | 3288 | return 0; |
82430852 JK |
3289 | |
3290 | /* Older elfutils strip versions could keep the section in the main | |
3291 | executable while splitting it for the separate debug info file. */ | |
a32a8923 | 3292 | if ((get_section_flags (section) & SEC_HAS_CONTENTS) == 0) |
82430852 JK |
3293 | return 0; |
3294 | ||
2ec9a5e0 | 3295 | dwarf2_read_section (objfile, section); |
9291a0cd | 3296 | |
2ec9a5e0 | 3297 | addr = section->buffer; |
9291a0cd | 3298 | /* Version check. */ |
1fd400ff | 3299 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 3300 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 3301 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 3302 | contained incomplete addrmap. So, it seems better to just ignore such |
481860b3 | 3303 | indices. */ |
831adc1f | 3304 | if (version < 4) |
481860b3 GB |
3305 | { |
3306 | static int warning_printed = 0; | |
3307 | if (!warning_printed) | |
3308 | { | |
3309 | warning (_("Skipping obsolete .gdb_index section in %s."), | |
2ec9a5e0 | 3310 | filename); |
481860b3 GB |
3311 | warning_printed = 1; |
3312 | } | |
3313 | return 0; | |
3314 | } | |
3315 | /* Index version 4 uses a different hash function than index version | |
3316 | 5 and later. | |
3317 | ||
3318 | Versions earlier than 6 did not emit psymbols for inlined | |
3319 | functions. Using these files will cause GDB not to be able to | |
3320 | set breakpoints on inlined functions by name, so we ignore these | |
e615022a DE |
3321 | indices unless the user has done |
3322 | "set use-deprecated-index-sections on". */ | |
2ec9a5e0 | 3323 | if (version < 6 && !deprecated_ok) |
481860b3 GB |
3324 | { |
3325 | static int warning_printed = 0; | |
3326 | if (!warning_printed) | |
3327 | { | |
e615022a DE |
3328 | warning (_("\ |
3329 | Skipping deprecated .gdb_index section in %s.\n\ | |
3330 | Do \"set use-deprecated-index-sections on\" before the file is read\n\ | |
3331 | to use the section anyway."), | |
2ec9a5e0 | 3332 | filename); |
481860b3 GB |
3333 | warning_printed = 1; |
3334 | } | |
3335 | return 0; | |
3336 | } | |
796a7ff8 | 3337 | /* Version 7 indices generated by gold refer to the CU for a symbol instead |
8943b874 DE |
3338 | of the TU (for symbols coming from TUs), |
3339 | http://sourceware.org/bugzilla/show_bug.cgi?id=15021. | |
3340 | Plus gold-generated indices can have duplicate entries for global symbols, | |
3341 | http://sourceware.org/bugzilla/show_bug.cgi?id=15646. | |
3342 | These are just performance bugs, and we can't distinguish gdb-generated | |
3343 | indices from gold-generated ones, so issue no warning here. */ | |
796a7ff8 | 3344 | |
481860b3 | 3345 | /* Indexes with higher version than the one supported by GDB may be no |
594e8718 | 3346 | longer backward compatible. */ |
796a7ff8 | 3347 | if (version > 8) |
594e8718 | 3348 | return 0; |
9291a0cd | 3349 | |
559a7a62 | 3350 | map->version = version; |
2ec9a5e0 | 3351 | map->total_size = section->size; |
9291a0cd TT |
3352 | |
3353 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
3354 | |
3355 | i = 0; | |
2ec9a5e0 TT |
3356 | *cu_list = addr + MAYBE_SWAP (metadata[i]); |
3357 | *cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
3358 | / 8); | |
1fd400ff TT |
3359 | ++i; |
3360 | ||
2ec9a5e0 TT |
3361 | *types_list = addr + MAYBE_SWAP (metadata[i]); |
3362 | *types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
3363 | - MAYBE_SWAP (metadata[i])) | |
3364 | / 8); | |
987d643c | 3365 | ++i; |
1fd400ff TT |
3366 | |
3367 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
3368 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
3369 | - MAYBE_SWAP (metadata[i])); | |
3370 | ++i; | |
3371 | ||
3876f04e DE |
3372 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
3373 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
3374 | - MAYBE_SWAP (metadata[i])) | |
3375 | / (2 * sizeof (offset_type))); | |
1fd400ff | 3376 | ++i; |
9291a0cd | 3377 | |
f9d83a0b | 3378 | map->constant_pool = (char *) (addr + MAYBE_SWAP (metadata[i])); |
1fd400ff | 3379 | |
2ec9a5e0 TT |
3380 | return 1; |
3381 | } | |
3382 | ||
3383 | ||
3384 | /* Read the index file. If everything went ok, initialize the "quick" | |
3385 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
3386 | ||
3387 | static int | |
3388 | dwarf2_read_index (struct objfile *objfile) | |
3389 | { | |
3390 | struct mapped_index local_map, *map; | |
3391 | const gdb_byte *cu_list, *types_list, *dwz_list = NULL; | |
3392 | offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0; | |
4db1a1dc | 3393 | struct dwz_file *dwz; |
2ec9a5e0 | 3394 | |
4262abfb | 3395 | if (!read_index_from_section (objfile, objfile_name (objfile), |
2ec9a5e0 TT |
3396 | use_deprecated_index_sections, |
3397 | &dwarf2_per_objfile->gdb_index, &local_map, | |
3398 | &cu_list, &cu_list_elements, | |
3399 | &types_list, &types_list_elements)) | |
3400 | return 0; | |
3401 | ||
0fefef59 | 3402 | /* Don't use the index if it's empty. */ |
2ec9a5e0 | 3403 | if (local_map.symbol_table_slots == 0) |
0fefef59 DE |
3404 | return 0; |
3405 | ||
2ec9a5e0 TT |
3406 | /* If there is a .dwz file, read it so we can get its CU list as |
3407 | well. */ | |
4db1a1dc TT |
3408 | dwz = dwarf2_get_dwz_file (); |
3409 | if (dwz != NULL) | |
2ec9a5e0 | 3410 | { |
2ec9a5e0 TT |
3411 | struct mapped_index dwz_map; |
3412 | const gdb_byte *dwz_types_ignore; | |
3413 | offset_type dwz_types_elements_ignore; | |
3414 | ||
3415 | if (!read_index_from_section (objfile, bfd_get_filename (dwz->dwz_bfd), | |
3416 | 1, | |
3417 | &dwz->gdb_index, &dwz_map, | |
3418 | &dwz_list, &dwz_list_elements, | |
3419 | &dwz_types_ignore, | |
3420 | &dwz_types_elements_ignore)) | |
3421 | { | |
3422 | warning (_("could not read '.gdb_index' section from %s; skipping"), | |
3423 | bfd_get_filename (dwz->dwz_bfd)); | |
3424 | return 0; | |
3425 | } | |
3426 | } | |
3427 | ||
74a0d9f6 JK |
3428 | create_cus_from_index (objfile, cu_list, cu_list_elements, dwz_list, |
3429 | dwz_list_elements); | |
1fd400ff | 3430 | |
8b70b953 TT |
3431 | if (types_list_elements) |
3432 | { | |
3433 | struct dwarf2_section_info *section; | |
3434 | ||
3435 | /* We can only handle a single .debug_types when we have an | |
3436 | index. */ | |
3437 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) | |
3438 | return 0; | |
3439 | ||
3440 | section = VEC_index (dwarf2_section_info_def, | |
3441 | dwarf2_per_objfile->types, 0); | |
3442 | ||
74a0d9f6 JK |
3443 | create_signatured_type_table_from_index (objfile, section, types_list, |
3444 | types_list_elements); | |
8b70b953 | 3445 | } |
9291a0cd | 3446 | |
2ec9a5e0 TT |
3447 | create_addrmap_from_index (objfile, &local_map); |
3448 | ||
8d749320 | 3449 | map = XOBNEW (&objfile->objfile_obstack, struct mapped_index); |
2ec9a5e0 | 3450 | *map = local_map; |
9291a0cd TT |
3451 | |
3452 | dwarf2_per_objfile->index_table = map; | |
3453 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
3454 | dwarf2_per_objfile->quick_file_names_table = |
3455 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
3456 | |
3457 | return 1; | |
3458 | } | |
3459 | ||
3460 | /* A helper for the "quick" functions which sets the global | |
3461 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 3462 | |
9291a0cd TT |
3463 | static void |
3464 | dw2_setup (struct objfile *objfile) | |
3465 | { | |
9a3c8263 SM |
3466 | dwarf2_per_objfile = ((struct dwarf2_per_objfile *) |
3467 | objfile_data (objfile, dwarf2_objfile_data_key)); | |
9291a0cd TT |
3468 | gdb_assert (dwarf2_per_objfile); |
3469 | } | |
3470 | ||
dee91e82 | 3471 | /* die_reader_func for dw2_get_file_names. */ |
2fdf6df6 | 3472 | |
dee91e82 DE |
3473 | static void |
3474 | dw2_get_file_names_reader (const struct die_reader_specs *reader, | |
d521ce57 | 3475 | const gdb_byte *info_ptr, |
dee91e82 DE |
3476 | struct die_info *comp_unit_die, |
3477 | int has_children, | |
3478 | void *data) | |
9291a0cd | 3479 | { |
dee91e82 DE |
3480 | struct dwarf2_cu *cu = reader->cu; |
3481 | struct dwarf2_per_cu_data *this_cu = cu->per_cu; | |
3482 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
094b34ac | 3483 | struct dwarf2_per_cu_data *lh_cu; |
9291a0cd | 3484 | struct attribute *attr; |
dee91e82 | 3485 | int i; |
7b9f3c50 DE |
3486 | void **slot; |
3487 | struct quick_file_names *qfn; | |
9291a0cd | 3488 | |
0186c6a7 DE |
3489 | gdb_assert (! this_cu->is_debug_types); |
3490 | ||
07261596 TT |
3491 | /* Our callers never want to match partial units -- instead they |
3492 | will match the enclosing full CU. */ | |
3493 | if (comp_unit_die->tag == DW_TAG_partial_unit) | |
3494 | { | |
3495 | this_cu->v.quick->no_file_data = 1; | |
3496 | return; | |
3497 | } | |
3498 | ||
0186c6a7 | 3499 | lh_cu = this_cu; |
7b9f3c50 | 3500 | slot = NULL; |
dee91e82 | 3501 | |
fff8551c | 3502 | line_header_up lh; |
9c541725 | 3503 | sect_offset line_offset {}; |
fff8551c | 3504 | |
dee91e82 | 3505 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); |
9291a0cd TT |
3506 | if (attr) |
3507 | { | |
7b9f3c50 DE |
3508 | struct quick_file_names find_entry; |
3509 | ||
9c541725 | 3510 | line_offset = (sect_offset) DW_UNSND (attr); |
7b9f3c50 DE |
3511 | |
3512 | /* We may have already read in this line header (TU line header sharing). | |
3513 | If we have we're done. */ | |
094b34ac | 3514 | find_entry.hash.dwo_unit = cu->dwo_unit; |
9c541725 | 3515 | find_entry.hash.line_sect_off = line_offset; |
7b9f3c50 DE |
3516 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, |
3517 | &find_entry, INSERT); | |
3518 | if (*slot != NULL) | |
3519 | { | |
9a3c8263 | 3520 | lh_cu->v.quick->file_names = (struct quick_file_names *) *slot; |
dee91e82 | 3521 | return; |
7b9f3c50 DE |
3522 | } |
3523 | ||
3019eac3 | 3524 | lh = dwarf_decode_line_header (line_offset, cu); |
9291a0cd TT |
3525 | } |
3526 | if (lh == NULL) | |
3527 | { | |
094b34ac | 3528 | lh_cu->v.quick->no_file_data = 1; |
dee91e82 | 3529 | return; |
9291a0cd TT |
3530 | } |
3531 | ||
8d749320 | 3532 | qfn = XOBNEW (&objfile->objfile_obstack, struct quick_file_names); |
094b34ac | 3533 | qfn->hash.dwo_unit = cu->dwo_unit; |
9c541725 | 3534 | qfn->hash.line_sect_off = line_offset; |
7b9f3c50 DE |
3535 | gdb_assert (slot != NULL); |
3536 | *slot = qfn; | |
9291a0cd | 3537 | |
d721ba37 | 3538 | file_and_directory fnd = find_file_and_directory (comp_unit_die, cu); |
9291a0cd | 3539 | |
fff8551c | 3540 | qfn->num_file_names = lh->file_names.size (); |
8d749320 | 3541 | qfn->file_names = |
fff8551c PA |
3542 | XOBNEWVEC (&objfile->objfile_obstack, const char *, lh->file_names.size ()); |
3543 | for (i = 0; i < lh->file_names.size (); ++i) | |
3544 | qfn->file_names[i] = file_full_name (i + 1, lh.get (), fnd.comp_dir); | |
7b9f3c50 | 3545 | qfn->real_names = NULL; |
9291a0cd | 3546 | |
094b34ac | 3547 | lh_cu->v.quick->file_names = qfn; |
dee91e82 DE |
3548 | } |
3549 | ||
3550 | /* A helper for the "quick" functions which attempts to read the line | |
3551 | table for THIS_CU. */ | |
3552 | ||
3553 | static struct quick_file_names * | |
e4a48d9d | 3554 | dw2_get_file_names (struct dwarf2_per_cu_data *this_cu) |
dee91e82 | 3555 | { |
0186c6a7 DE |
3556 | /* This should never be called for TUs. */ |
3557 | gdb_assert (! this_cu->is_debug_types); | |
3558 | /* Nor type unit groups. */ | |
3559 | gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu)); | |
f4dc4d17 | 3560 | |
dee91e82 DE |
3561 | if (this_cu->v.quick->file_names != NULL) |
3562 | return this_cu->v.quick->file_names; | |
3563 | /* If we know there is no line data, no point in looking again. */ | |
3564 | if (this_cu->v.quick->no_file_data) | |
3565 | return NULL; | |
3566 | ||
0186c6a7 | 3567 | init_cutu_and_read_dies_simple (this_cu, dw2_get_file_names_reader, NULL); |
dee91e82 DE |
3568 | |
3569 | if (this_cu->v.quick->no_file_data) | |
3570 | return NULL; | |
3571 | return this_cu->v.quick->file_names; | |
9291a0cd TT |
3572 | } |
3573 | ||
3574 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 3575 | real path for a given file name from the line table. */ |
2fdf6df6 | 3576 | |
9291a0cd | 3577 | static const char * |
7b9f3c50 DE |
3578 | dw2_get_real_path (struct objfile *objfile, |
3579 | struct quick_file_names *qfn, int index) | |
9291a0cd | 3580 | { |
7b9f3c50 DE |
3581 | if (qfn->real_names == NULL) |
3582 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
26f2dc30 | 3583 | qfn->num_file_names, const char *); |
9291a0cd | 3584 | |
7b9f3c50 DE |
3585 | if (qfn->real_names[index] == NULL) |
3586 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 3587 | |
7b9f3c50 | 3588 | return qfn->real_names[index]; |
9291a0cd TT |
3589 | } |
3590 | ||
3591 | static struct symtab * | |
3592 | dw2_find_last_source_symtab (struct objfile *objfile) | |
3593 | { | |
43f3e411 | 3594 | struct compunit_symtab *cust; |
9291a0cd | 3595 | int index; |
ae2de4f8 | 3596 | |
9291a0cd TT |
3597 | dw2_setup (objfile); |
3598 | index = dwarf2_per_objfile->n_comp_units - 1; | |
43f3e411 DE |
3599 | cust = dw2_instantiate_symtab (dw2_get_cutu (index)); |
3600 | if (cust == NULL) | |
3601 | return NULL; | |
3602 | return compunit_primary_filetab (cust); | |
9291a0cd TT |
3603 | } |
3604 | ||
7b9f3c50 DE |
3605 | /* Traversal function for dw2_forget_cached_source_info. */ |
3606 | ||
3607 | static int | |
3608 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 3609 | { |
7b9f3c50 | 3610 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 3611 | |
7b9f3c50 | 3612 | if (file_data->real_names) |
9291a0cd | 3613 | { |
7b9f3c50 | 3614 | int i; |
9291a0cd | 3615 | |
7b9f3c50 | 3616 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 3617 | { |
7b9f3c50 DE |
3618 | xfree ((void*) file_data->real_names[i]); |
3619 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
3620 | } |
3621 | } | |
7b9f3c50 DE |
3622 | |
3623 | return 1; | |
3624 | } | |
3625 | ||
3626 | static void | |
3627 | dw2_forget_cached_source_info (struct objfile *objfile) | |
3628 | { | |
3629 | dw2_setup (objfile); | |
3630 | ||
3631 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
3632 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
3633 | } |
3634 | ||
f8eba3c6 TT |
3635 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
3636 | the symtabs and calls the iterator. */ | |
3637 | ||
3638 | static int | |
3639 | dw2_map_expand_apply (struct objfile *objfile, | |
3640 | struct dwarf2_per_cu_data *per_cu, | |
f5b95b50 | 3641 | const char *name, const char *real_path, |
14bc53a8 | 3642 | gdb::function_view<bool (symtab *)> callback) |
f8eba3c6 | 3643 | { |
43f3e411 | 3644 | struct compunit_symtab *last_made = objfile->compunit_symtabs; |
f8eba3c6 TT |
3645 | |
3646 | /* Don't visit already-expanded CUs. */ | |
43f3e411 | 3647 | if (per_cu->v.quick->compunit_symtab) |
f8eba3c6 TT |
3648 | return 0; |
3649 | ||
3650 | /* This may expand more than one symtab, and we want to iterate over | |
3651 | all of them. */ | |
a0f42c21 | 3652 | dw2_instantiate_symtab (per_cu); |
f8eba3c6 | 3653 | |
14bc53a8 PA |
3654 | return iterate_over_some_symtabs (name, real_path, objfile->compunit_symtabs, |
3655 | last_made, callback); | |
f8eba3c6 TT |
3656 | } |
3657 | ||
3658 | /* Implementation of the map_symtabs_matching_filename method. */ | |
3659 | ||
14bc53a8 PA |
3660 | static bool |
3661 | dw2_map_symtabs_matching_filename | |
3662 | (struct objfile *objfile, const char *name, const char *real_path, | |
3663 | gdb::function_view<bool (symtab *)> callback) | |
9291a0cd TT |
3664 | { |
3665 | int i; | |
c011a4f4 | 3666 | const char *name_basename = lbasename (name); |
9291a0cd TT |
3667 | |
3668 | dw2_setup (objfile); | |
ae2de4f8 | 3669 | |
848e3e78 DE |
3670 | /* The rule is CUs specify all the files, including those used by |
3671 | any TU, so there's no need to scan TUs here. */ | |
f4dc4d17 | 3672 | |
848e3e78 | 3673 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
9291a0cd TT |
3674 | { |
3675 | int j; | |
8832e7e3 | 3676 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 3677 | struct quick_file_names *file_data; |
9291a0cd | 3678 | |
3d7bb9d9 | 3679 | /* We only need to look at symtabs not already expanded. */ |
43f3e411 | 3680 | if (per_cu->v.quick->compunit_symtab) |
9291a0cd TT |
3681 | continue; |
3682 | ||
e4a48d9d | 3683 | file_data = dw2_get_file_names (per_cu); |
7b9f3c50 | 3684 | if (file_data == NULL) |
9291a0cd TT |
3685 | continue; |
3686 | ||
7b9f3c50 | 3687 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 3688 | { |
7b9f3c50 | 3689 | const char *this_name = file_data->file_names[j]; |
da235a7c | 3690 | const char *this_real_name; |
9291a0cd | 3691 | |
af529f8f | 3692 | if (compare_filenames_for_search (this_name, name)) |
9291a0cd | 3693 | { |
f5b95b50 | 3694 | if (dw2_map_expand_apply (objfile, per_cu, name, real_path, |
14bc53a8 PA |
3695 | callback)) |
3696 | return true; | |
288e77a7 | 3697 | continue; |
4aac40c8 | 3698 | } |
9291a0cd | 3699 | |
c011a4f4 DE |
3700 | /* Before we invoke realpath, which can get expensive when many |
3701 | files are involved, do a quick comparison of the basenames. */ | |
3702 | if (! basenames_may_differ | |
3703 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) | |
3704 | continue; | |
3705 | ||
da235a7c JK |
3706 | this_real_name = dw2_get_real_path (objfile, file_data, j); |
3707 | if (compare_filenames_for_search (this_real_name, name)) | |
9291a0cd | 3708 | { |
da235a7c | 3709 | if (dw2_map_expand_apply (objfile, per_cu, name, real_path, |
14bc53a8 PA |
3710 | callback)) |
3711 | return true; | |
288e77a7 | 3712 | continue; |
da235a7c | 3713 | } |
9291a0cd | 3714 | |
da235a7c JK |
3715 | if (real_path != NULL) |
3716 | { | |
af529f8f JK |
3717 | gdb_assert (IS_ABSOLUTE_PATH (real_path)); |
3718 | gdb_assert (IS_ABSOLUTE_PATH (name)); | |
7b9f3c50 | 3719 | if (this_real_name != NULL |
af529f8f | 3720 | && FILENAME_CMP (real_path, this_real_name) == 0) |
9291a0cd | 3721 | { |
f5b95b50 | 3722 | if (dw2_map_expand_apply (objfile, per_cu, name, real_path, |
14bc53a8 PA |
3723 | callback)) |
3724 | return true; | |
288e77a7 | 3725 | continue; |
9291a0cd TT |
3726 | } |
3727 | } | |
3728 | } | |
3729 | } | |
3730 | ||
14bc53a8 | 3731 | return false; |
9291a0cd TT |
3732 | } |
3733 | ||
da51c347 DE |
3734 | /* Struct used to manage iterating over all CUs looking for a symbol. */ |
3735 | ||
3736 | struct dw2_symtab_iterator | |
9291a0cd | 3737 | { |
da51c347 DE |
3738 | /* The internalized form of .gdb_index. */ |
3739 | struct mapped_index *index; | |
3740 | /* If non-zero, only look for symbols that match BLOCK_INDEX. */ | |
3741 | int want_specific_block; | |
3742 | /* One of GLOBAL_BLOCK or STATIC_BLOCK. | |
3743 | Unused if !WANT_SPECIFIC_BLOCK. */ | |
3744 | int block_index; | |
3745 | /* The kind of symbol we're looking for. */ | |
3746 | domain_enum domain; | |
3747 | /* The list of CUs from the index entry of the symbol, | |
3748 | or NULL if not found. */ | |
3749 | offset_type *vec; | |
3750 | /* The next element in VEC to look at. */ | |
3751 | int next; | |
3752 | /* The number of elements in VEC, or zero if there is no match. */ | |
3753 | int length; | |
8943b874 DE |
3754 | /* Have we seen a global version of the symbol? |
3755 | If so we can ignore all further global instances. | |
3756 | This is to work around gold/15646, inefficient gold-generated | |
3757 | indices. */ | |
3758 | int global_seen; | |
da51c347 | 3759 | }; |
9291a0cd | 3760 | |
da51c347 DE |
3761 | /* Initialize the index symtab iterator ITER. |
3762 | If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols | |
3763 | in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */ | |
2fdf6df6 | 3764 | |
9291a0cd | 3765 | static void |
da51c347 DE |
3766 | dw2_symtab_iter_init (struct dw2_symtab_iterator *iter, |
3767 | struct mapped_index *index, | |
3768 | int want_specific_block, | |
3769 | int block_index, | |
3770 | domain_enum domain, | |
3771 | const char *name) | |
3772 | { | |
3773 | iter->index = index; | |
3774 | iter->want_specific_block = want_specific_block; | |
3775 | iter->block_index = block_index; | |
3776 | iter->domain = domain; | |
3777 | iter->next = 0; | |
8943b874 | 3778 | iter->global_seen = 0; |
da51c347 DE |
3779 | |
3780 | if (find_slot_in_mapped_hash (index, name, &iter->vec)) | |
3781 | iter->length = MAYBE_SWAP (*iter->vec); | |
3782 | else | |
3783 | { | |
3784 | iter->vec = NULL; | |
3785 | iter->length = 0; | |
3786 | } | |
3787 | } | |
3788 | ||
3789 | /* Return the next matching CU or NULL if there are no more. */ | |
3790 | ||
3791 | static struct dwarf2_per_cu_data * | |
3792 | dw2_symtab_iter_next (struct dw2_symtab_iterator *iter) | |
3793 | { | |
3794 | for ( ; iter->next < iter->length; ++iter->next) | |
3795 | { | |
3796 | offset_type cu_index_and_attrs = | |
3797 | MAYBE_SWAP (iter->vec[iter->next + 1]); | |
3798 | offset_type cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs); | |
3190f0c6 | 3799 | struct dwarf2_per_cu_data *per_cu; |
da51c347 DE |
3800 | int want_static = iter->block_index != GLOBAL_BLOCK; |
3801 | /* This value is only valid for index versions >= 7. */ | |
3802 | int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs); | |
3803 | gdb_index_symbol_kind symbol_kind = | |
3804 | GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs); | |
3805 | /* Only check the symbol attributes if they're present. | |
3806 | Indices prior to version 7 don't record them, | |
3807 | and indices >= 7 may elide them for certain symbols | |
3808 | (gold does this). */ | |
3809 | int attrs_valid = | |
3810 | (iter->index->version >= 7 | |
3811 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE); | |
3812 | ||
3190f0c6 DE |
3813 | /* Don't crash on bad data. */ |
3814 | if (cu_index >= (dwarf2_per_objfile->n_comp_units | |
3815 | + dwarf2_per_objfile->n_type_units)) | |
3816 | { | |
3817 | complaint (&symfile_complaints, | |
3818 | _(".gdb_index entry has bad CU index" | |
4262abfb JK |
3819 | " [in module %s]"), |
3820 | objfile_name (dwarf2_per_objfile->objfile)); | |
3190f0c6 DE |
3821 | continue; |
3822 | } | |
3823 | ||
8832e7e3 | 3824 | per_cu = dw2_get_cutu (cu_index); |
3190f0c6 | 3825 | |
da51c347 | 3826 | /* Skip if already read in. */ |
43f3e411 | 3827 | if (per_cu->v.quick->compunit_symtab) |
da51c347 DE |
3828 | continue; |
3829 | ||
8943b874 DE |
3830 | /* Check static vs global. */ |
3831 | if (attrs_valid) | |
3832 | { | |
3833 | if (iter->want_specific_block | |
3834 | && want_static != is_static) | |
3835 | continue; | |
3836 | /* Work around gold/15646. */ | |
3837 | if (!is_static && iter->global_seen) | |
3838 | continue; | |
3839 | if (!is_static) | |
3840 | iter->global_seen = 1; | |
3841 | } | |
da51c347 DE |
3842 | |
3843 | /* Only check the symbol's kind if it has one. */ | |
3844 | if (attrs_valid) | |
3845 | { | |
3846 | switch (iter->domain) | |
3847 | { | |
3848 | case VAR_DOMAIN: | |
3849 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE | |
3850 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION | |
3851 | /* Some types are also in VAR_DOMAIN. */ | |
3852 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) | |
3853 | continue; | |
3854 | break; | |
3855 | case STRUCT_DOMAIN: | |
3856 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) | |
3857 | continue; | |
3858 | break; | |
3859 | case LABEL_DOMAIN: | |
3860 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER) | |
3861 | continue; | |
3862 | break; | |
3863 | default: | |
3864 | break; | |
3865 | } | |
3866 | } | |
3867 | ||
3868 | ++iter->next; | |
3869 | return per_cu; | |
3870 | } | |
3871 | ||
3872 | return NULL; | |
3873 | } | |
3874 | ||
43f3e411 | 3875 | static struct compunit_symtab * |
da51c347 DE |
3876 | dw2_lookup_symbol (struct objfile *objfile, int block_index, |
3877 | const char *name, domain_enum domain) | |
9291a0cd | 3878 | { |
43f3e411 | 3879 | struct compunit_symtab *stab_best = NULL; |
156942c7 DE |
3880 | struct mapped_index *index; |
3881 | ||
9291a0cd TT |
3882 | dw2_setup (objfile); |
3883 | ||
156942c7 DE |
3884 | index = dwarf2_per_objfile->index_table; |
3885 | ||
da51c347 | 3886 | /* index is NULL if OBJF_READNOW. */ |
156942c7 | 3887 | if (index) |
9291a0cd | 3888 | { |
da51c347 DE |
3889 | struct dw2_symtab_iterator iter; |
3890 | struct dwarf2_per_cu_data *per_cu; | |
3891 | ||
3892 | dw2_symtab_iter_init (&iter, index, 1, block_index, domain, name); | |
9291a0cd | 3893 | |
da51c347 | 3894 | while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL) |
9291a0cd | 3895 | { |
b2e2f908 | 3896 | struct symbol *sym, *with_opaque = NULL; |
43f3e411 DE |
3897 | struct compunit_symtab *stab = dw2_instantiate_symtab (per_cu); |
3898 | const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab); | |
f194fefb | 3899 | struct block *block = BLOCKVECTOR_BLOCK (bv, block_index); |
da51c347 | 3900 | |
b2e2f908 DE |
3901 | sym = block_find_symbol (block, name, domain, |
3902 | block_find_non_opaque_type_preferred, | |
3903 | &with_opaque); | |
3904 | ||
da51c347 DE |
3905 | /* Some caution must be observed with overloaded functions |
3906 | and methods, since the index will not contain any overload | |
3907 | information (but NAME might contain it). */ | |
da51c347 | 3908 | |
b2e2f908 | 3909 | if (sym != NULL |
a778f165 | 3910 | && SYMBOL_MATCHES_SEARCH_NAME (sym, name)) |
b2e2f908 DE |
3911 | return stab; |
3912 | if (with_opaque != NULL | |
a778f165 | 3913 | && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, name)) |
b2e2f908 | 3914 | stab_best = stab; |
da51c347 DE |
3915 | |
3916 | /* Keep looking through other CUs. */ | |
9291a0cd TT |
3917 | } |
3918 | } | |
9291a0cd | 3919 | |
da51c347 | 3920 | return stab_best; |
9291a0cd TT |
3921 | } |
3922 | ||
3923 | static void | |
3924 | dw2_print_stats (struct objfile *objfile) | |
3925 | { | |
e4a48d9d | 3926 | int i, total, count; |
9291a0cd TT |
3927 | |
3928 | dw2_setup (objfile); | |
e4a48d9d | 3929 | total = dwarf2_per_objfile->n_comp_units + dwarf2_per_objfile->n_type_units; |
9291a0cd | 3930 | count = 0; |
e4a48d9d | 3931 | for (i = 0; i < total; ++i) |
9291a0cd | 3932 | { |
8832e7e3 | 3933 | struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i); |
9291a0cd | 3934 | |
43f3e411 | 3935 | if (!per_cu->v.quick->compunit_symtab) |
9291a0cd TT |
3936 | ++count; |
3937 | } | |
e4a48d9d | 3938 | printf_filtered (_(" Number of read CUs: %d\n"), total - count); |
9291a0cd TT |
3939 | printf_filtered (_(" Number of unread CUs: %d\n"), count); |
3940 | } | |
3941 | ||
779bd270 DE |
3942 | /* This dumps minimal information about the index. |
3943 | It is called via "mt print objfiles". | |
3944 | One use is to verify .gdb_index has been loaded by the | |
3945 | gdb.dwarf2/gdb-index.exp testcase. */ | |
3946 | ||
9291a0cd TT |
3947 | static void |
3948 | dw2_dump (struct objfile *objfile) | |
3949 | { | |
779bd270 DE |
3950 | dw2_setup (objfile); |
3951 | gdb_assert (dwarf2_per_objfile->using_index); | |
3952 | printf_filtered (".gdb_index:"); | |
3953 | if (dwarf2_per_objfile->index_table != NULL) | |
3954 | { | |
3955 | printf_filtered (" version %d\n", | |
3956 | dwarf2_per_objfile->index_table->version); | |
3957 | } | |
3958 | else | |
3959 | printf_filtered (" faked for \"readnow\"\n"); | |
3960 | printf_filtered ("\n"); | |
9291a0cd TT |
3961 | } |
3962 | ||
3963 | static void | |
3189cb12 DE |
3964 | dw2_relocate (struct objfile *objfile, |
3965 | const struct section_offsets *new_offsets, | |
3966 | const struct section_offsets *delta) | |
9291a0cd TT |
3967 | { |
3968 | /* There's nothing to relocate here. */ | |
3969 | } | |
3970 | ||
3971 | static void | |
3972 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
3973 | const char *func_name) | |
3974 | { | |
da51c347 DE |
3975 | struct mapped_index *index; |
3976 | ||
3977 | dw2_setup (objfile); | |
3978 | ||
3979 | index = dwarf2_per_objfile->index_table; | |
3980 | ||
3981 | /* index is NULL if OBJF_READNOW. */ | |
3982 | if (index) | |
3983 | { | |
3984 | struct dw2_symtab_iterator iter; | |
3985 | struct dwarf2_per_cu_data *per_cu; | |
3986 | ||
3987 | /* Note: It doesn't matter what we pass for block_index here. */ | |
3988 | dw2_symtab_iter_init (&iter, index, 0, GLOBAL_BLOCK, VAR_DOMAIN, | |
3989 | func_name); | |
3990 | ||
3991 | while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL) | |
3992 | dw2_instantiate_symtab (per_cu); | |
3993 | } | |
9291a0cd TT |
3994 | } |
3995 | ||
3996 | static void | |
3997 | dw2_expand_all_symtabs (struct objfile *objfile) | |
3998 | { | |
3999 | int i; | |
4000 | ||
4001 | dw2_setup (objfile); | |
1fd400ff TT |
4002 | |
4003 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 4004 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 4005 | { |
8832e7e3 | 4006 | struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i); |
9291a0cd | 4007 | |
a0f42c21 | 4008 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
4009 | } |
4010 | } | |
4011 | ||
4012 | static void | |
652a8996 JK |
4013 | dw2_expand_symtabs_with_fullname (struct objfile *objfile, |
4014 | const char *fullname) | |
9291a0cd TT |
4015 | { |
4016 | int i; | |
4017 | ||
4018 | dw2_setup (objfile); | |
d4637a04 DE |
4019 | |
4020 | /* We don't need to consider type units here. | |
4021 | This is only called for examining code, e.g. expand_line_sal. | |
4022 | There can be an order of magnitude (or more) more type units | |
4023 | than comp units, and we avoid them if we can. */ | |
4024 | ||
4025 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
4026 | { |
4027 | int j; | |
8832e7e3 | 4028 | struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i); |
7b9f3c50 | 4029 | struct quick_file_names *file_data; |
9291a0cd | 4030 | |
3d7bb9d9 | 4031 | /* We only need to look at symtabs not already expanded. */ |
43f3e411 | 4032 | if (per_cu->v.quick->compunit_symtab) |
9291a0cd TT |
4033 | continue; |
4034 | ||
e4a48d9d | 4035 | file_data = dw2_get_file_names (per_cu); |
7b9f3c50 | 4036 | if (file_data == NULL) |
9291a0cd TT |
4037 | continue; |
4038 | ||
7b9f3c50 | 4039 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 4040 | { |
652a8996 JK |
4041 | const char *this_fullname = file_data->file_names[j]; |
4042 | ||
4043 | if (filename_cmp (this_fullname, fullname) == 0) | |
9291a0cd | 4044 | { |
a0f42c21 | 4045 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
4046 | break; |
4047 | } | |
4048 | } | |
4049 | } | |
4050 | } | |
4051 | ||
9291a0cd | 4052 | static void |
ade7ed9e | 4053 | dw2_map_matching_symbols (struct objfile *objfile, |
fe978cb0 | 4054 | const char * name, domain_enum domain, |
ade7ed9e | 4055 | int global, |
40658b94 PH |
4056 | int (*callback) (struct block *, |
4057 | struct symbol *, void *), | |
2edb89d3 JK |
4058 | void *data, symbol_compare_ftype *match, |
4059 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 4060 | { |
40658b94 | 4061 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
4062 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
4063 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
4064 | } |
4065 | ||
4066 | static void | |
f8eba3c6 TT |
4067 | dw2_expand_symtabs_matching |
4068 | (struct objfile *objfile, | |
14bc53a8 PA |
4069 | gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher, |
4070 | gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher, | |
4071 | gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify, | |
4072 | enum search_domain kind) | |
9291a0cd TT |
4073 | { |
4074 | int i; | |
4075 | offset_type iter; | |
4b5246aa | 4076 | struct mapped_index *index; |
9291a0cd TT |
4077 | |
4078 | dw2_setup (objfile); | |
ae2de4f8 DE |
4079 | |
4080 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
4081 | if (!dwarf2_per_objfile->index_table) |
4082 | return; | |
4b5246aa | 4083 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 4084 | |
7b08b9eb | 4085 | if (file_matcher != NULL) |
24c79950 | 4086 | { |
fc4007c9 TT |
4087 | htab_up visited_found (htab_create_alloc (10, htab_hash_pointer, |
4088 | htab_eq_pointer, | |
4089 | NULL, xcalloc, xfree)); | |
4090 | htab_up visited_not_found (htab_create_alloc (10, htab_hash_pointer, | |
4091 | htab_eq_pointer, | |
4092 | NULL, xcalloc, xfree)); | |
24c79950 | 4093 | |
848e3e78 DE |
4094 | /* The rule is CUs specify all the files, including those used by |
4095 | any TU, so there's no need to scan TUs here. */ | |
4096 | ||
4097 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
24c79950 TT |
4098 | { |
4099 | int j; | |
8832e7e3 | 4100 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
24c79950 TT |
4101 | struct quick_file_names *file_data; |
4102 | void **slot; | |
7b08b9eb | 4103 | |
61d96d7e DE |
4104 | QUIT; |
4105 | ||
24c79950 | 4106 | per_cu->v.quick->mark = 0; |
3d7bb9d9 | 4107 | |
24c79950 | 4108 | /* We only need to look at symtabs not already expanded. */ |
43f3e411 | 4109 | if (per_cu->v.quick->compunit_symtab) |
24c79950 | 4110 | continue; |
7b08b9eb | 4111 | |
e4a48d9d | 4112 | file_data = dw2_get_file_names (per_cu); |
24c79950 TT |
4113 | if (file_data == NULL) |
4114 | continue; | |
7b08b9eb | 4115 | |
fc4007c9 | 4116 | if (htab_find (visited_not_found.get (), file_data) != NULL) |
24c79950 | 4117 | continue; |
fc4007c9 | 4118 | else if (htab_find (visited_found.get (), file_data) != NULL) |
24c79950 TT |
4119 | { |
4120 | per_cu->v.quick->mark = 1; | |
4121 | continue; | |
4122 | } | |
4123 | ||
4124 | for (j = 0; j < file_data->num_file_names; ++j) | |
4125 | { | |
da235a7c JK |
4126 | const char *this_real_name; |
4127 | ||
14bc53a8 | 4128 | if (file_matcher (file_data->file_names[j], false)) |
24c79950 TT |
4129 | { |
4130 | per_cu->v.quick->mark = 1; | |
4131 | break; | |
4132 | } | |
da235a7c JK |
4133 | |
4134 | /* Before we invoke realpath, which can get expensive when many | |
4135 | files are involved, do a quick comparison of the basenames. */ | |
4136 | if (!basenames_may_differ | |
4137 | && !file_matcher (lbasename (file_data->file_names[j]), | |
14bc53a8 | 4138 | true)) |
da235a7c JK |
4139 | continue; |
4140 | ||
4141 | this_real_name = dw2_get_real_path (objfile, file_data, j); | |
14bc53a8 | 4142 | if (file_matcher (this_real_name, false)) |
da235a7c JK |
4143 | { |
4144 | per_cu->v.quick->mark = 1; | |
4145 | break; | |
4146 | } | |
24c79950 TT |
4147 | } |
4148 | ||
4149 | slot = htab_find_slot (per_cu->v.quick->mark | |
fc4007c9 TT |
4150 | ? visited_found.get () |
4151 | : visited_not_found.get (), | |
24c79950 TT |
4152 | file_data, INSERT); |
4153 | *slot = file_data; | |
4154 | } | |
24c79950 | 4155 | } |
9291a0cd | 4156 | |
3876f04e | 4157 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
4158 | { |
4159 | offset_type idx = 2 * iter; | |
4160 | const char *name; | |
4161 | offset_type *vec, vec_len, vec_idx; | |
8943b874 | 4162 | int global_seen = 0; |
9291a0cd | 4163 | |
61d96d7e DE |
4164 | QUIT; |
4165 | ||
3876f04e | 4166 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
4167 | continue; |
4168 | ||
3876f04e | 4169 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd | 4170 | |
14bc53a8 | 4171 | if (!symbol_matcher (name)) |
9291a0cd TT |
4172 | continue; |
4173 | ||
4174 | /* The name was matched, now expand corresponding CUs that were | |
4175 | marked. */ | |
4b5246aa | 4176 | vec = (offset_type *) (index->constant_pool |
3876f04e | 4177 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
4178 | vec_len = MAYBE_SWAP (vec[0]); |
4179 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
4180 | { | |
e254ef6a | 4181 | struct dwarf2_per_cu_data *per_cu; |
156942c7 | 4182 | offset_type cu_index_and_attrs = MAYBE_SWAP (vec[vec_idx + 1]); |
8943b874 DE |
4183 | /* This value is only valid for index versions >= 7. */ |
4184 | int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs); | |
156942c7 DE |
4185 | gdb_index_symbol_kind symbol_kind = |
4186 | GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs); | |
4187 | int cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs); | |
3190f0c6 DE |
4188 | /* Only check the symbol attributes if they're present. |
4189 | Indices prior to version 7 don't record them, | |
4190 | and indices >= 7 may elide them for certain symbols | |
4191 | (gold does this). */ | |
4192 | int attrs_valid = | |
4193 | (index->version >= 7 | |
4194 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE); | |
4195 | ||
8943b874 DE |
4196 | /* Work around gold/15646. */ |
4197 | if (attrs_valid) | |
4198 | { | |
4199 | if (!is_static && global_seen) | |
4200 | continue; | |
4201 | if (!is_static) | |
4202 | global_seen = 1; | |
4203 | } | |
4204 | ||
3190f0c6 DE |
4205 | /* Only check the symbol's kind if it has one. */ |
4206 | if (attrs_valid) | |
156942c7 DE |
4207 | { |
4208 | switch (kind) | |
4209 | { | |
4210 | case VARIABLES_DOMAIN: | |
4211 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE) | |
4212 | continue; | |
4213 | break; | |
4214 | case FUNCTIONS_DOMAIN: | |
4215 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION) | |
4216 | continue; | |
4217 | break; | |
4218 | case TYPES_DOMAIN: | |
4219 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) | |
4220 | continue; | |
4221 | break; | |
4222 | default: | |
4223 | break; | |
4224 | } | |
4225 | } | |
4226 | ||
3190f0c6 DE |
4227 | /* Don't crash on bad data. */ |
4228 | if (cu_index >= (dwarf2_per_objfile->n_comp_units | |
4229 | + dwarf2_per_objfile->n_type_units)) | |
4230 | { | |
4231 | complaint (&symfile_complaints, | |
4232 | _(".gdb_index entry has bad CU index" | |
4262abfb | 4233 | " [in module %s]"), objfile_name (objfile)); |
3190f0c6 DE |
4234 | continue; |
4235 | } | |
4236 | ||
8832e7e3 | 4237 | per_cu = dw2_get_cutu (cu_index); |
7b08b9eb | 4238 | if (file_matcher == NULL || per_cu->v.quick->mark) |
276d885b GB |
4239 | { |
4240 | int symtab_was_null = | |
4241 | (per_cu->v.quick->compunit_symtab == NULL); | |
4242 | ||
4243 | dw2_instantiate_symtab (per_cu); | |
4244 | ||
4245 | if (expansion_notify != NULL | |
4246 | && symtab_was_null | |
4247 | && per_cu->v.quick->compunit_symtab != NULL) | |
4248 | { | |
14bc53a8 | 4249 | expansion_notify (per_cu->v.quick->compunit_symtab); |
276d885b GB |
4250 | } |
4251 | } | |
9291a0cd TT |
4252 | } |
4253 | } | |
4254 | } | |
4255 | ||
43f3e411 | 4256 | /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific |
9703b513 TT |
4257 | symtab. */ |
4258 | ||
43f3e411 DE |
4259 | static struct compunit_symtab * |
4260 | recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust, | |
4261 | CORE_ADDR pc) | |
9703b513 TT |
4262 | { |
4263 | int i; | |
4264 | ||
43f3e411 DE |
4265 | if (COMPUNIT_BLOCKVECTOR (cust) != NULL |
4266 | && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust), pc)) | |
4267 | return cust; | |
9703b513 | 4268 | |
43f3e411 | 4269 | if (cust->includes == NULL) |
a3ec0bb1 DE |
4270 | return NULL; |
4271 | ||
43f3e411 | 4272 | for (i = 0; cust->includes[i]; ++i) |
9703b513 | 4273 | { |
43f3e411 | 4274 | struct compunit_symtab *s = cust->includes[i]; |
9703b513 | 4275 | |
43f3e411 | 4276 | s = recursively_find_pc_sect_compunit_symtab (s, pc); |
9703b513 TT |
4277 | if (s != NULL) |
4278 | return s; | |
4279 | } | |
4280 | ||
4281 | return NULL; | |
4282 | } | |
4283 | ||
43f3e411 DE |
4284 | static struct compunit_symtab * |
4285 | dw2_find_pc_sect_compunit_symtab (struct objfile *objfile, | |
4286 | struct bound_minimal_symbol msymbol, | |
4287 | CORE_ADDR pc, | |
4288 | struct obj_section *section, | |
4289 | int warn_if_readin) | |
9291a0cd TT |
4290 | { |
4291 | struct dwarf2_per_cu_data *data; | |
43f3e411 | 4292 | struct compunit_symtab *result; |
9291a0cd TT |
4293 | |
4294 | dw2_setup (objfile); | |
4295 | ||
4296 | if (!objfile->psymtabs_addrmap) | |
4297 | return NULL; | |
4298 | ||
9a3c8263 SM |
4299 | data = (struct dwarf2_per_cu_data *) addrmap_find (objfile->psymtabs_addrmap, |
4300 | pc); | |
9291a0cd TT |
4301 | if (!data) |
4302 | return NULL; | |
4303 | ||
43f3e411 | 4304 | if (warn_if_readin && data->v.quick->compunit_symtab) |
abebb8b0 | 4305 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
4306 | paddress (get_objfile_arch (objfile), pc)); |
4307 | ||
43f3e411 DE |
4308 | result |
4309 | = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data), | |
4310 | pc); | |
9703b513 TT |
4311 | gdb_assert (result != NULL); |
4312 | return result; | |
9291a0cd TT |
4313 | } |
4314 | ||
9291a0cd | 4315 | static void |
44b13c5a | 4316 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
74e2f255 | 4317 | void *data, int need_fullname) |
9291a0cd | 4318 | { |
9291a0cd | 4319 | dw2_setup (objfile); |
ae2de4f8 | 4320 | |
bbf2f4df | 4321 | if (!dwarf2_per_objfile->filenames_cache) |
24c79950 | 4322 | { |
bbf2f4df | 4323 | dwarf2_per_objfile->filenames_cache.emplace (); |
24c79950 | 4324 | |
bbf2f4df PA |
4325 | htab_up visited (htab_create_alloc (10, |
4326 | htab_hash_pointer, htab_eq_pointer, | |
4327 | NULL, xcalloc, xfree)); | |
24c79950 | 4328 | |
bbf2f4df PA |
4329 | /* The rule is CUs specify all the files, including those used |
4330 | by any TU, so there's no need to scan TUs here. We can | |
4331 | ignore file names coming from already-expanded CUs. */ | |
24c79950 | 4332 | |
bbf2f4df PA |
4333 | for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
4334 | { | |
4335 | struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i); | |
9291a0cd | 4336 | |
bbf2f4df PA |
4337 | if (per_cu->v.quick->compunit_symtab) |
4338 | { | |
4339 | void **slot = htab_find_slot (visited.get (), | |
4340 | per_cu->v.quick->file_names, | |
4341 | INSERT); | |
9291a0cd | 4342 | |
bbf2f4df PA |
4343 | *slot = per_cu->v.quick->file_names; |
4344 | } | |
24c79950 | 4345 | } |
24c79950 | 4346 | |
bbf2f4df | 4347 | for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
9291a0cd | 4348 | { |
bbf2f4df PA |
4349 | int j; |
4350 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
4351 | struct quick_file_names *file_data; | |
4352 | void **slot; | |
4353 | ||
4354 | /* We only need to look at symtabs not already expanded. */ | |
4355 | if (per_cu->v.quick->compunit_symtab) | |
4356 | continue; | |
74e2f255 | 4357 | |
bbf2f4df PA |
4358 | file_data = dw2_get_file_names (per_cu); |
4359 | if (file_data == NULL) | |
4360 | continue; | |
4361 | ||
4362 | slot = htab_find_slot (visited.get (), file_data, INSERT); | |
4363 | if (*slot) | |
4364 | { | |
4365 | /* Already visited. */ | |
4366 | continue; | |
4367 | } | |
4368 | *slot = file_data; | |
4369 | ||
4370 | for (int j = 0; j < file_data->num_file_names; ++j) | |
4371 | { | |
4372 | const char *filename = file_data->file_names[j]; | |
4373 | dwarf2_per_objfile->filenames_cache->seen (filename); | |
4374 | } | |
9291a0cd TT |
4375 | } |
4376 | } | |
bbf2f4df PA |
4377 | |
4378 | dwarf2_per_objfile->filenames_cache->traverse ([&] (const char *filename) | |
4379 | { | |
4380 | const char *this_real_name; | |
4381 | ||
4382 | if (need_fullname) | |
4383 | this_real_name = gdb_realpath (filename); | |
4384 | else | |
4385 | this_real_name = NULL; | |
4386 | (*fun) (filename, this_real_name, data); | |
4387 | }); | |
9291a0cd TT |
4388 | } |
4389 | ||
4390 | static int | |
4391 | dw2_has_symbols (struct objfile *objfile) | |
4392 | { | |
4393 | return 1; | |
4394 | } | |
4395 | ||
4396 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
4397 | { | |
4398 | dw2_has_symbols, | |
4399 | dw2_find_last_source_symtab, | |
4400 | dw2_forget_cached_source_info, | |
f8eba3c6 | 4401 | dw2_map_symtabs_matching_filename, |
9291a0cd | 4402 | dw2_lookup_symbol, |
9291a0cd TT |
4403 | dw2_print_stats, |
4404 | dw2_dump, | |
4405 | dw2_relocate, | |
4406 | dw2_expand_symtabs_for_function, | |
4407 | dw2_expand_all_symtabs, | |
652a8996 | 4408 | dw2_expand_symtabs_with_fullname, |
40658b94 | 4409 | dw2_map_matching_symbols, |
9291a0cd | 4410 | dw2_expand_symtabs_matching, |
43f3e411 | 4411 | dw2_find_pc_sect_compunit_symtab, |
9291a0cd TT |
4412 | dw2_map_symbol_filenames |
4413 | }; | |
4414 | ||
4415 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
4416 | file will use psymtabs, or 1 if using the GNU index. */ | |
4417 | ||
4418 | int | |
4419 | dwarf2_initialize_objfile (struct objfile *objfile) | |
4420 | { | |
4421 | /* If we're about to read full symbols, don't bother with the | |
4422 | indices. In this case we also don't care if some other debug | |
4423 | format is making psymtabs, because they are all about to be | |
4424 | expanded anyway. */ | |
4425 | if ((objfile->flags & OBJF_READNOW)) | |
4426 | { | |
4427 | int i; | |
4428 | ||
4429 | dwarf2_per_objfile->using_index = 1; | |
4430 | create_all_comp_units (objfile); | |
0e50663e | 4431 | create_all_type_units (objfile); |
7b9f3c50 DE |
4432 | dwarf2_per_objfile->quick_file_names_table = |
4433 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 4434 | |
1fd400ff | 4435 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 4436 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 4437 | { |
8832e7e3 | 4438 | struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i); |
9291a0cd | 4439 | |
e254ef6a DE |
4440 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
4441 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
4442 | } |
4443 | ||
4444 | /* Return 1 so that gdb sees the "quick" functions. However, | |
4445 | these functions will be no-ops because we will have expanded | |
4446 | all symtabs. */ | |
4447 | return 1; | |
4448 | } | |
4449 | ||
4450 | if (dwarf2_read_index (objfile)) | |
4451 | return 1; | |
4452 | ||
9291a0cd TT |
4453 | return 0; |
4454 | } | |
4455 | ||
4456 | \f | |
4457 | ||
dce234bc PP |
4458 | /* Build a partial symbol table. */ |
4459 | ||
4460 | void | |
f29dff0a | 4461 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 4462 | { |
c9bf0622 | 4463 | |
f29dff0a | 4464 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
4465 | { |
4466 | init_psymbol_list (objfile, 1024); | |
4467 | } | |
4468 | ||
492d29ea | 4469 | TRY |
c9bf0622 TT |
4470 | { |
4471 | /* This isn't really ideal: all the data we allocate on the | |
4472 | objfile's obstack is still uselessly kept around. However, | |
4473 | freeing it seems unsafe. */ | |
906768f9 | 4474 | psymtab_discarder psymtabs (objfile); |
c9bf0622 | 4475 | dwarf2_build_psymtabs_hard (objfile); |
906768f9 | 4476 | psymtabs.keep (); |
c9bf0622 | 4477 | } |
492d29ea PA |
4478 | CATCH (except, RETURN_MASK_ERROR) |
4479 | { | |
4480 | exception_print (gdb_stderr, except); | |
4481 | } | |
4482 | END_CATCH | |
c906108c | 4483 | } |
c906108c | 4484 | |
1ce1cefd DE |
4485 | /* Return the total length of the CU described by HEADER. */ |
4486 | ||
4487 | static unsigned int | |
4488 | get_cu_length (const struct comp_unit_head *header) | |
4489 | { | |
4490 | return header->initial_length_size + header->length; | |
4491 | } | |
4492 | ||
9c541725 | 4493 | /* Return TRUE if SECT_OFF is within CU_HEADER. */ |
45452591 | 4494 | |
9c541725 PA |
4495 | static inline bool |
4496 | offset_in_cu_p (const comp_unit_head *cu_header, sect_offset sect_off) | |
45452591 | 4497 | { |
9c541725 PA |
4498 | sect_offset bottom = cu_header->sect_off; |
4499 | sect_offset top = cu_header->sect_off + get_cu_length (cu_header); | |
9a619af0 | 4500 | |
9c541725 | 4501 | return sect_off >= bottom && sect_off < top; |
45452591 DE |
4502 | } |
4503 | ||
3b80fe9b DE |
4504 | /* Find the base address of the compilation unit for range lists and |
4505 | location lists. It will normally be specified by DW_AT_low_pc. | |
4506 | In DWARF-3 draft 4, the base address could be overridden by | |
4507 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
4508 | compilation units with discontinuous ranges. */ | |
4509 | ||
4510 | static void | |
4511 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
4512 | { | |
4513 | struct attribute *attr; | |
4514 | ||
4515 | cu->base_known = 0; | |
4516 | cu->base_address = 0; | |
4517 | ||
4518 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
4519 | if (attr) | |
4520 | { | |
31aa7e4e | 4521 | cu->base_address = attr_value_as_address (attr); |
3b80fe9b DE |
4522 | cu->base_known = 1; |
4523 | } | |
4524 | else | |
4525 | { | |
4526 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
4527 | if (attr) | |
4528 | { | |
31aa7e4e | 4529 | cu->base_address = attr_value_as_address (attr); |
3b80fe9b DE |
4530 | cu->base_known = 1; |
4531 | } | |
4532 | } | |
4533 | } | |
4534 | ||
93311388 | 4535 | /* Read in the comp unit header information from the debug_info at info_ptr. |
43988095 | 4536 | Use rcuh_kind::COMPILE as the default type if not known by the caller. |
93311388 DE |
4537 | NOTE: This leaves members offset, first_die_offset to be filled in |
4538 | by the caller. */ | |
107d2387 | 4539 | |
d521ce57 | 4540 | static const gdb_byte * |
107d2387 | 4541 | read_comp_unit_head (struct comp_unit_head *cu_header, |
43988095 JK |
4542 | const gdb_byte *info_ptr, |
4543 | struct dwarf2_section_info *section, | |
4544 | rcuh_kind section_kind) | |
107d2387 AC |
4545 | { |
4546 | int signed_addr; | |
891d2f0b | 4547 | unsigned int bytes_read; |
43988095 JK |
4548 | const char *filename = get_section_file_name (section); |
4549 | bfd *abfd = get_section_bfd_owner (section); | |
c764a876 DE |
4550 | |
4551 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
4552 | cu_header->initial_length_size = bytes_read; | |
4553 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 4554 | info_ptr += bytes_read; |
107d2387 AC |
4555 | cu_header->version = read_2_bytes (abfd, info_ptr); |
4556 | info_ptr += 2; | |
43988095 JK |
4557 | if (cu_header->version < 5) |
4558 | switch (section_kind) | |
4559 | { | |
4560 | case rcuh_kind::COMPILE: | |
4561 | cu_header->unit_type = DW_UT_compile; | |
4562 | break; | |
4563 | case rcuh_kind::TYPE: | |
4564 | cu_header->unit_type = DW_UT_type; | |
4565 | break; | |
4566 | default: | |
4567 | internal_error (__FILE__, __LINE__, | |
4568 | _("read_comp_unit_head: invalid section_kind")); | |
4569 | } | |
4570 | else | |
4571 | { | |
4572 | cu_header->unit_type = static_cast<enum dwarf_unit_type> | |
4573 | (read_1_byte (abfd, info_ptr)); | |
4574 | info_ptr += 1; | |
4575 | switch (cu_header->unit_type) | |
4576 | { | |
4577 | case DW_UT_compile: | |
4578 | if (section_kind != rcuh_kind::COMPILE) | |
4579 | error (_("Dwarf Error: wrong unit_type in compilation unit header " | |
4580 | "(is DW_UT_compile, should be DW_UT_type) [in module %s]"), | |
4581 | filename); | |
4582 | break; | |
4583 | case DW_UT_type: | |
4584 | section_kind = rcuh_kind::TYPE; | |
4585 | break; | |
4586 | default: | |
4587 | error (_("Dwarf Error: wrong unit_type in compilation unit header " | |
4588 | "(is %d, should be %d or %d) [in module %s]"), | |
4589 | cu_header->unit_type, DW_UT_compile, DW_UT_type, filename); | |
4590 | } | |
4591 | ||
4592 | cu_header->addr_size = read_1_byte (abfd, info_ptr); | |
4593 | info_ptr += 1; | |
4594 | } | |
9c541725 PA |
4595 | cu_header->abbrev_sect_off = (sect_offset) read_offset (abfd, info_ptr, |
4596 | cu_header, | |
4597 | &bytes_read); | |
613e1657 | 4598 | info_ptr += bytes_read; |
43988095 JK |
4599 | if (cu_header->version < 5) |
4600 | { | |
4601 | cu_header->addr_size = read_1_byte (abfd, info_ptr); | |
4602 | info_ptr += 1; | |
4603 | } | |
107d2387 AC |
4604 | signed_addr = bfd_get_sign_extend_vma (abfd); |
4605 | if (signed_addr < 0) | |
8e65ff28 | 4606 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4607 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 4608 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 4609 | |
43988095 JK |
4610 | if (section_kind == rcuh_kind::TYPE) |
4611 | { | |
4612 | LONGEST type_offset; | |
4613 | ||
4614 | cu_header->signature = read_8_bytes (abfd, info_ptr); | |
4615 | info_ptr += 8; | |
4616 | ||
4617 | type_offset = read_offset (abfd, info_ptr, cu_header, &bytes_read); | |
4618 | info_ptr += bytes_read; | |
9c541725 PA |
4619 | cu_header->type_cu_offset_in_tu = (cu_offset) type_offset; |
4620 | if (to_underlying (cu_header->type_cu_offset_in_tu) != type_offset) | |
43988095 JK |
4621 | error (_("Dwarf Error: Too big type_offset in compilation unit " |
4622 | "header (is %s) [in module %s]"), plongest (type_offset), | |
4623 | filename); | |
4624 | } | |
4625 | ||
107d2387 AC |
4626 | return info_ptr; |
4627 | } | |
4628 | ||
36586728 TT |
4629 | /* Helper function that returns the proper abbrev section for |
4630 | THIS_CU. */ | |
4631 | ||
4632 | static struct dwarf2_section_info * | |
4633 | get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu) | |
4634 | { | |
4635 | struct dwarf2_section_info *abbrev; | |
4636 | ||
4637 | if (this_cu->is_dwz) | |
4638 | abbrev = &dwarf2_get_dwz_file ()->abbrev; | |
4639 | else | |
4640 | abbrev = &dwarf2_per_objfile->abbrev; | |
4641 | ||
4642 | return abbrev; | |
4643 | } | |
4644 | ||
9ff913ba DE |
4645 | /* Subroutine of read_and_check_comp_unit_head and |
4646 | read_and_check_type_unit_head to simplify them. | |
4647 | Perform various error checking on the header. */ | |
4648 | ||
4649 | static void | |
4650 | error_check_comp_unit_head (struct comp_unit_head *header, | |
4bdcc0c1 DE |
4651 | struct dwarf2_section_info *section, |
4652 | struct dwarf2_section_info *abbrev_section) | |
9ff913ba | 4653 | { |
a32a8923 | 4654 | const char *filename = get_section_file_name (section); |
9ff913ba | 4655 | |
43988095 | 4656 | if (header->version < 2 || header->version > 5) |
9ff913ba | 4657 | error (_("Dwarf Error: wrong version in compilation unit header " |
43988095 | 4658 | "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header->version, |
9ff913ba DE |
4659 | filename); |
4660 | ||
9c541725 | 4661 | if (to_underlying (header->abbrev_sect_off) |
36586728 | 4662 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section)) |
9c541725 PA |
4663 | error (_("Dwarf Error: bad offset (0x%x) in compilation unit header " |
4664 | "(offset 0x%x + 6) [in module %s]"), | |
4665 | to_underlying (header->abbrev_sect_off), | |
4666 | to_underlying (header->sect_off), | |
9ff913ba DE |
4667 | filename); |
4668 | ||
9c541725 | 4669 | /* Cast to ULONGEST to use 64-bit arithmetic when possible to |
9ff913ba | 4670 | avoid potential 32-bit overflow. */ |
9c541725 | 4671 | if (((ULONGEST) header->sect_off + get_cu_length (header)) |
9ff913ba | 4672 | > section->size) |
9c541725 PA |
4673 | error (_("Dwarf Error: bad length (0x%x) in compilation unit header " |
4674 | "(offset 0x%x + 0) [in module %s]"), | |
4675 | header->length, to_underlying (header->sect_off), | |
9ff913ba DE |
4676 | filename); |
4677 | } | |
4678 | ||
4679 | /* Read in a CU/TU header and perform some basic error checking. | |
4680 | The contents of the header are stored in HEADER. | |
4681 | The result is a pointer to the start of the first DIE. */ | |
adabb602 | 4682 | |
d521ce57 | 4683 | static const gdb_byte * |
9ff913ba DE |
4684 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
4685 | struct dwarf2_section_info *section, | |
4bdcc0c1 | 4686 | struct dwarf2_section_info *abbrev_section, |
d521ce57 | 4687 | const gdb_byte *info_ptr, |
43988095 | 4688 | rcuh_kind section_kind) |
72bf9492 | 4689 | { |
d521ce57 | 4690 | const gdb_byte *beg_of_comp_unit = info_ptr; |
a32a8923 | 4691 | bfd *abfd = get_section_bfd_owner (section); |
72bf9492 | 4692 | |
9c541725 | 4693 | header->sect_off = (sect_offset) (beg_of_comp_unit - section->buffer); |
adabb602 | 4694 | |
43988095 | 4695 | info_ptr = read_comp_unit_head (header, info_ptr, section, section_kind); |
9ff913ba | 4696 | |
9c541725 | 4697 | header->first_die_cu_offset = (cu_offset) (info_ptr - beg_of_comp_unit); |
348e048f | 4698 | |
4bdcc0c1 | 4699 | error_check_comp_unit_head (header, section, abbrev_section); |
9ff913ba DE |
4700 | |
4701 | return info_ptr; | |
348e048f DE |
4702 | } |
4703 | ||
f4dc4d17 DE |
4704 | /* Fetch the abbreviation table offset from a comp or type unit header. */ |
4705 | ||
4706 | static sect_offset | |
4707 | read_abbrev_offset (struct dwarf2_section_info *section, | |
9c541725 | 4708 | sect_offset sect_off) |
f4dc4d17 | 4709 | { |
a32a8923 | 4710 | bfd *abfd = get_section_bfd_owner (section); |
d521ce57 | 4711 | const gdb_byte *info_ptr; |
ac298888 | 4712 | unsigned int initial_length_size, offset_size; |
43988095 | 4713 | uint16_t version; |
f4dc4d17 DE |
4714 | |
4715 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); | |
9c541725 | 4716 | info_ptr = section->buffer + to_underlying (sect_off); |
ac298888 | 4717 | read_initial_length (abfd, info_ptr, &initial_length_size); |
f4dc4d17 | 4718 | offset_size = initial_length_size == 4 ? 4 : 8; |
43988095 JK |
4719 | info_ptr += initial_length_size; |
4720 | ||
4721 | version = read_2_bytes (abfd, info_ptr); | |
4722 | info_ptr += 2; | |
4723 | if (version >= 5) | |
4724 | { | |
4725 | /* Skip unit type and address size. */ | |
4726 | info_ptr += 2; | |
4727 | } | |
4728 | ||
9c541725 | 4729 | return (sect_offset) read_offset_1 (abfd, info_ptr, offset_size); |
f4dc4d17 DE |
4730 | } |
4731 | ||
aaa75496 JB |
4732 | /* Allocate a new partial symtab for file named NAME and mark this new |
4733 | partial symtab as being an include of PST. */ | |
4734 | ||
4735 | static void | |
d521ce57 | 4736 | dwarf2_create_include_psymtab (const char *name, struct partial_symtab *pst, |
aaa75496 JB |
4737 | struct objfile *objfile) |
4738 | { | |
4739 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
4740 | ||
fbd9ab74 JK |
4741 | if (!IS_ABSOLUTE_PATH (subpst->filename)) |
4742 | { | |
4743 | /* It shares objfile->objfile_obstack. */ | |
4744 | subpst->dirname = pst->dirname; | |
4745 | } | |
4746 | ||
aaa75496 JB |
4747 | subpst->textlow = 0; |
4748 | subpst->texthigh = 0; | |
4749 | ||
8d749320 SM |
4750 | subpst->dependencies |
4751 | = XOBNEW (&objfile->objfile_obstack, struct partial_symtab *); | |
aaa75496 JB |
4752 | subpst->dependencies[0] = pst; |
4753 | subpst->number_of_dependencies = 1; | |
4754 | ||
4755 | subpst->globals_offset = 0; | |
4756 | subpst->n_global_syms = 0; | |
4757 | subpst->statics_offset = 0; | |
4758 | subpst->n_static_syms = 0; | |
43f3e411 | 4759 | subpst->compunit_symtab = NULL; |
aaa75496 JB |
4760 | subpst->read_symtab = pst->read_symtab; |
4761 | subpst->readin = 0; | |
4762 | ||
4763 | /* No private part is necessary for include psymtabs. This property | |
4764 | can be used to differentiate between such include psymtabs and | |
10b3939b | 4765 | the regular ones. */ |
58a9656e | 4766 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
4767 | } |
4768 | ||
4769 | /* Read the Line Number Program data and extract the list of files | |
4770 | included by the source file represented by PST. Build an include | |
d85a05f0 | 4771 | partial symtab for each of these included files. */ |
aaa75496 JB |
4772 | |
4773 | static void | |
4774 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
dee91e82 DE |
4775 | struct die_info *die, |
4776 | struct partial_symtab *pst) | |
aaa75496 | 4777 | { |
fff8551c | 4778 | line_header_up lh; |
d85a05f0 | 4779 | struct attribute *attr; |
aaa75496 | 4780 | |
d85a05f0 DJ |
4781 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
4782 | if (attr) | |
9c541725 | 4783 | lh = dwarf_decode_line_header ((sect_offset) DW_UNSND (attr), cu); |
aaa75496 JB |
4784 | if (lh == NULL) |
4785 | return; /* No linetable, so no includes. */ | |
4786 | ||
c6da4cef | 4787 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
fff8551c | 4788 | dwarf_decode_lines (lh.get (), pst->dirname, cu, pst, pst->textlow, 1); |
aaa75496 JB |
4789 | } |
4790 | ||
348e048f | 4791 | static hashval_t |
52dc124a | 4792 | hash_signatured_type (const void *item) |
348e048f | 4793 | { |
9a3c8263 SM |
4794 | const struct signatured_type *sig_type |
4795 | = (const struct signatured_type *) item; | |
9a619af0 | 4796 | |
348e048f | 4797 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
52dc124a | 4798 | return sig_type->signature; |
348e048f DE |
4799 | } |
4800 | ||
4801 | static int | |
52dc124a | 4802 | eq_signatured_type (const void *item_lhs, const void *item_rhs) |
348e048f | 4803 | { |
9a3c8263 SM |
4804 | const struct signatured_type *lhs = (const struct signatured_type *) item_lhs; |
4805 | const struct signatured_type *rhs = (const struct signatured_type *) item_rhs; | |
9a619af0 | 4806 | |
348e048f DE |
4807 | return lhs->signature == rhs->signature; |
4808 | } | |
4809 | ||
1fd400ff TT |
4810 | /* Allocate a hash table for signatured types. */ |
4811 | ||
4812 | static htab_t | |
673bfd45 | 4813 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
4814 | { |
4815 | return htab_create_alloc_ex (41, | |
52dc124a DE |
4816 | hash_signatured_type, |
4817 | eq_signatured_type, | |
1fd400ff TT |
4818 | NULL, |
4819 | &objfile->objfile_obstack, | |
4820 | hashtab_obstack_allocate, | |
4821 | dummy_obstack_deallocate); | |
4822 | } | |
4823 | ||
d467dd73 | 4824 | /* A helper function to add a signatured type CU to a table. */ |
1fd400ff TT |
4825 | |
4826 | static int | |
d467dd73 | 4827 | add_signatured_type_cu_to_table (void **slot, void *datum) |
1fd400ff | 4828 | { |
9a3c8263 SM |
4829 | struct signatured_type *sigt = (struct signatured_type *) *slot; |
4830 | struct signatured_type ***datap = (struct signatured_type ***) datum; | |
1fd400ff | 4831 | |
b4dd5633 | 4832 | **datap = sigt; |
1fd400ff TT |
4833 | ++*datap; |
4834 | ||
4835 | return 1; | |
4836 | } | |
4837 | ||
78d4d2c5 | 4838 | /* A helper for create_debug_types_hash_table. Read types from SECTION |
43988095 JK |
4839 | and fill them into TYPES_HTAB. It will process only type units, |
4840 | therefore DW_UT_type. */ | |
c88ee1f0 | 4841 | |
78d4d2c5 JK |
4842 | static void |
4843 | create_debug_type_hash_table (struct dwo_file *dwo_file, | |
43988095 JK |
4844 | dwarf2_section_info *section, htab_t &types_htab, |
4845 | rcuh_kind section_kind) | |
348e048f | 4846 | { |
3019eac3 | 4847 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
4bdcc0c1 | 4848 | struct dwarf2_section_info *abbrev_section; |
78d4d2c5 JK |
4849 | bfd *abfd; |
4850 | const gdb_byte *info_ptr, *end_ptr; | |
348e048f | 4851 | |
4bdcc0c1 DE |
4852 | abbrev_section = (dwo_file != NULL |
4853 | ? &dwo_file->sections.abbrev | |
4854 | : &dwarf2_per_objfile->abbrev); | |
4855 | ||
b4f54984 | 4856 | if (dwarf_read_debug) |
43988095 JK |
4857 | fprintf_unfiltered (gdb_stdlog, "Reading %s for %s:\n", |
4858 | get_section_name (section), | |
a32a8923 | 4859 | get_section_file_name (abbrev_section)); |
09406207 | 4860 | |
78d4d2c5 JK |
4861 | dwarf2_read_section (objfile, section); |
4862 | info_ptr = section->buffer; | |
348e048f | 4863 | |
78d4d2c5 JK |
4864 | if (info_ptr == NULL) |
4865 | return; | |
348e048f | 4866 | |
78d4d2c5 JK |
4867 | /* We can't set abfd until now because the section may be empty or |
4868 | not present, in which case the bfd is unknown. */ | |
4869 | abfd = get_section_bfd_owner (section); | |
348e048f | 4870 | |
78d4d2c5 JK |
4871 | /* We don't use init_cutu_and_read_dies_simple, or some such, here |
4872 | because we don't need to read any dies: the signature is in the | |
4873 | header. */ | |
3019eac3 | 4874 | |
78d4d2c5 JK |
4875 | end_ptr = info_ptr + section->size; |
4876 | while (info_ptr < end_ptr) | |
4877 | { | |
78d4d2c5 JK |
4878 | struct signatured_type *sig_type; |
4879 | struct dwo_unit *dwo_tu; | |
4880 | void **slot; | |
4881 | const gdb_byte *ptr = info_ptr; | |
4882 | struct comp_unit_head header; | |
4883 | unsigned int length; | |
8b70b953 | 4884 | |
9c541725 | 4885 | sect_offset sect_off = (sect_offset) (ptr - section->buffer); |
348e048f | 4886 | |
a49dd8dd JK |
4887 | /* Initialize it due to a false compiler warning. */ |
4888 | header.signature = -1; | |
9c541725 | 4889 | header.type_cu_offset_in_tu = (cu_offset) -1; |
a49dd8dd | 4890 | |
78d4d2c5 JK |
4891 | /* We need to read the type's signature in order to build the hash |
4892 | table, but we don't need anything else just yet. */ | |
348e048f | 4893 | |
43988095 JK |
4894 | ptr = read_and_check_comp_unit_head (&header, section, |
4895 | abbrev_section, ptr, section_kind); | |
348e048f | 4896 | |
78d4d2c5 | 4897 | length = get_cu_length (&header); |
6caca83c | 4898 | |
78d4d2c5 JK |
4899 | /* Skip dummy type units. */ |
4900 | if (ptr >= info_ptr + length | |
43988095 JK |
4901 | || peek_abbrev_code (abfd, ptr) == 0 |
4902 | || header.unit_type != DW_UT_type) | |
78d4d2c5 JK |
4903 | { |
4904 | info_ptr += length; | |
4905 | continue; | |
4906 | } | |
dee91e82 | 4907 | |
78d4d2c5 JK |
4908 | if (types_htab == NULL) |
4909 | { | |
4910 | if (dwo_file) | |
4911 | types_htab = allocate_dwo_unit_table (objfile); | |
4912 | else | |
4913 | types_htab = allocate_signatured_type_table (objfile); | |
4914 | } | |
8b70b953 | 4915 | |
78d4d2c5 JK |
4916 | if (dwo_file) |
4917 | { | |
4918 | sig_type = NULL; | |
4919 | dwo_tu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
4920 | struct dwo_unit); | |
4921 | dwo_tu->dwo_file = dwo_file; | |
43988095 | 4922 | dwo_tu->signature = header.signature; |
9c541725 | 4923 | dwo_tu->type_offset_in_tu = header.type_cu_offset_in_tu; |
78d4d2c5 | 4924 | dwo_tu->section = section; |
9c541725 | 4925 | dwo_tu->sect_off = sect_off; |
78d4d2c5 JK |
4926 | dwo_tu->length = length; |
4927 | } | |
4928 | else | |
4929 | { | |
4930 | /* N.B.: type_offset is not usable if this type uses a DWO file. | |
4931 | The real type_offset is in the DWO file. */ | |
4932 | dwo_tu = NULL; | |
4933 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
4934 | struct signatured_type); | |
43988095 | 4935 | sig_type->signature = header.signature; |
9c541725 | 4936 | sig_type->type_offset_in_tu = header.type_cu_offset_in_tu; |
78d4d2c5 JK |
4937 | sig_type->per_cu.objfile = objfile; |
4938 | sig_type->per_cu.is_debug_types = 1; | |
4939 | sig_type->per_cu.section = section; | |
9c541725 | 4940 | sig_type->per_cu.sect_off = sect_off; |
78d4d2c5 JK |
4941 | sig_type->per_cu.length = length; |
4942 | } | |
4943 | ||
4944 | slot = htab_find_slot (types_htab, | |
4945 | dwo_file ? (void*) dwo_tu : (void *) sig_type, | |
4946 | INSERT); | |
4947 | gdb_assert (slot != NULL); | |
4948 | if (*slot != NULL) | |
4949 | { | |
9c541725 | 4950 | sect_offset dup_sect_off; |
0349ea22 | 4951 | |
3019eac3 DE |
4952 | if (dwo_file) |
4953 | { | |
78d4d2c5 JK |
4954 | const struct dwo_unit *dup_tu |
4955 | = (const struct dwo_unit *) *slot; | |
4956 | ||
9c541725 | 4957 | dup_sect_off = dup_tu->sect_off; |
3019eac3 DE |
4958 | } |
4959 | else | |
4960 | { | |
78d4d2c5 JK |
4961 | const struct signatured_type *dup_tu |
4962 | = (const struct signatured_type *) *slot; | |
4963 | ||
9c541725 | 4964 | dup_sect_off = dup_tu->per_cu.sect_off; |
3019eac3 | 4965 | } |
8b70b953 | 4966 | |
78d4d2c5 JK |
4967 | complaint (&symfile_complaints, |
4968 | _("debug type entry at offset 0x%x is duplicate to" | |
4969 | " the entry at offset 0x%x, signature %s"), | |
9c541725 | 4970 | to_underlying (sect_off), to_underlying (dup_sect_off), |
43988095 | 4971 | hex_string (header.signature)); |
78d4d2c5 JK |
4972 | } |
4973 | *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type; | |
3019eac3 | 4974 | |
78d4d2c5 JK |
4975 | if (dwarf_read_debug > 1) |
4976 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature %s\n", | |
9c541725 | 4977 | to_underlying (sect_off), |
43988095 | 4978 | hex_string (header.signature)); |
3019eac3 | 4979 | |
78d4d2c5 JK |
4980 | info_ptr += length; |
4981 | } | |
4982 | } | |
3019eac3 | 4983 | |
78d4d2c5 JK |
4984 | /* Create the hash table of all entries in the .debug_types |
4985 | (or .debug_types.dwo) section(s). | |
4986 | If reading a DWO file, then DWO_FILE is a pointer to the DWO file object, | |
4987 | otherwise it is NULL. | |
b3c8eb43 | 4988 | |
78d4d2c5 | 4989 | The result is a pointer to the hash table or NULL if there are no types. |
348e048f | 4990 | |
78d4d2c5 | 4991 | Note: This function processes DWO files only, not DWP files. */ |
348e048f | 4992 | |
78d4d2c5 JK |
4993 | static void |
4994 | create_debug_types_hash_table (struct dwo_file *dwo_file, | |
4995 | VEC (dwarf2_section_info_def) *types, | |
4996 | htab_t &types_htab) | |
4997 | { | |
4998 | int ix; | |
4999 | struct dwarf2_section_info *section; | |
5000 | ||
5001 | if (VEC_empty (dwarf2_section_info_def, types)) | |
5002 | return; | |
348e048f | 5003 | |
78d4d2c5 JK |
5004 | for (ix = 0; |
5005 | VEC_iterate (dwarf2_section_info_def, types, ix, section); | |
5006 | ++ix) | |
43988095 JK |
5007 | create_debug_type_hash_table (dwo_file, section, types_htab, |
5008 | rcuh_kind::TYPE); | |
3019eac3 DE |
5009 | } |
5010 | ||
5011 | /* Create the hash table of all entries in the .debug_types section, | |
5012 | and initialize all_type_units. | |
5013 | The result is zero if there is an error (e.g. missing .debug_types section), | |
5014 | otherwise non-zero. */ | |
5015 | ||
5016 | static int | |
5017 | create_all_type_units (struct objfile *objfile) | |
5018 | { | |
78d4d2c5 | 5019 | htab_t types_htab = NULL; |
b4dd5633 | 5020 | struct signatured_type **iter; |
3019eac3 | 5021 | |
43988095 JK |
5022 | create_debug_type_hash_table (NULL, &dwarf2_per_objfile->info, types_htab, |
5023 | rcuh_kind::COMPILE); | |
78d4d2c5 | 5024 | create_debug_types_hash_table (NULL, dwarf2_per_objfile->types, types_htab); |
3019eac3 DE |
5025 | if (types_htab == NULL) |
5026 | { | |
5027 | dwarf2_per_objfile->signatured_types = NULL; | |
5028 | return 0; | |
5029 | } | |
5030 | ||
348e048f DE |
5031 | dwarf2_per_objfile->signatured_types = types_htab; |
5032 | ||
6aa5f3a6 DE |
5033 | dwarf2_per_objfile->n_type_units |
5034 | = dwarf2_per_objfile->n_allocated_type_units | |
5035 | = htab_elements (types_htab); | |
8d749320 SM |
5036 | dwarf2_per_objfile->all_type_units = |
5037 | XNEWVEC (struct signatured_type *, dwarf2_per_objfile->n_type_units); | |
d467dd73 DE |
5038 | iter = &dwarf2_per_objfile->all_type_units[0]; |
5039 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); | |
5040 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] | |
5041 | == dwarf2_per_objfile->n_type_units); | |
1fd400ff | 5042 | |
348e048f DE |
5043 | return 1; |
5044 | } | |
5045 | ||
6aa5f3a6 DE |
5046 | /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types. |
5047 | If SLOT is non-NULL, it is the entry to use in the hash table. | |
5048 | Otherwise we find one. */ | |
5049 | ||
5050 | static struct signatured_type * | |
5051 | add_type_unit (ULONGEST sig, void **slot) | |
5052 | { | |
5053 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
5054 | int n_type_units = dwarf2_per_objfile->n_type_units; | |
5055 | struct signatured_type *sig_type; | |
5056 | ||
5057 | gdb_assert (n_type_units <= dwarf2_per_objfile->n_allocated_type_units); | |
5058 | ++n_type_units; | |
5059 | if (n_type_units > dwarf2_per_objfile->n_allocated_type_units) | |
5060 | { | |
5061 | if (dwarf2_per_objfile->n_allocated_type_units == 0) | |
5062 | dwarf2_per_objfile->n_allocated_type_units = 1; | |
5063 | dwarf2_per_objfile->n_allocated_type_units *= 2; | |
5064 | dwarf2_per_objfile->all_type_units | |
224c3ddb SM |
5065 | = XRESIZEVEC (struct signatured_type *, |
5066 | dwarf2_per_objfile->all_type_units, | |
5067 | dwarf2_per_objfile->n_allocated_type_units); | |
6aa5f3a6 DE |
5068 | ++dwarf2_per_objfile->tu_stats.nr_all_type_units_reallocs; |
5069 | } | |
5070 | dwarf2_per_objfile->n_type_units = n_type_units; | |
5071 | ||
5072 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5073 | struct signatured_type); | |
5074 | dwarf2_per_objfile->all_type_units[n_type_units - 1] = sig_type; | |
5075 | sig_type->signature = sig; | |
5076 | sig_type->per_cu.is_debug_types = 1; | |
5077 | if (dwarf2_per_objfile->using_index) | |
5078 | { | |
5079 | sig_type->per_cu.v.quick = | |
5080 | OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5081 | struct dwarf2_per_cu_quick_data); | |
5082 | } | |
5083 | ||
5084 | if (slot == NULL) | |
5085 | { | |
5086 | slot = htab_find_slot (dwarf2_per_objfile->signatured_types, | |
5087 | sig_type, INSERT); | |
5088 | } | |
5089 | gdb_assert (*slot == NULL); | |
5090 | *slot = sig_type; | |
5091 | /* The rest of sig_type must be filled in by the caller. */ | |
5092 | return sig_type; | |
5093 | } | |
5094 | ||
a2ce51a0 DE |
5095 | /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type. |
5096 | Fill in SIG_ENTRY with DWO_ENTRY. */ | |
5097 | ||
5098 | static void | |
5099 | fill_in_sig_entry_from_dwo_entry (struct objfile *objfile, | |
5100 | struct signatured_type *sig_entry, | |
5101 | struct dwo_unit *dwo_entry) | |
5102 | { | |
7ee85ab1 | 5103 | /* Make sure we're not clobbering something we don't expect to. */ |
a2ce51a0 DE |
5104 | gdb_assert (! sig_entry->per_cu.queued); |
5105 | gdb_assert (sig_entry->per_cu.cu == NULL); | |
6aa5f3a6 DE |
5106 | if (dwarf2_per_objfile->using_index) |
5107 | { | |
5108 | gdb_assert (sig_entry->per_cu.v.quick != NULL); | |
43f3e411 | 5109 | gdb_assert (sig_entry->per_cu.v.quick->compunit_symtab == NULL); |
6aa5f3a6 DE |
5110 | } |
5111 | else | |
5112 | gdb_assert (sig_entry->per_cu.v.psymtab == NULL); | |
a2ce51a0 | 5113 | gdb_assert (sig_entry->signature == dwo_entry->signature); |
9c541725 | 5114 | gdb_assert (to_underlying (sig_entry->type_offset_in_section) == 0); |
a2ce51a0 | 5115 | gdb_assert (sig_entry->type_unit_group == NULL); |
7ee85ab1 DE |
5116 | gdb_assert (sig_entry->dwo_unit == NULL); |
5117 | ||
5118 | sig_entry->per_cu.section = dwo_entry->section; | |
9c541725 | 5119 | sig_entry->per_cu.sect_off = dwo_entry->sect_off; |
7ee85ab1 DE |
5120 | sig_entry->per_cu.length = dwo_entry->length; |
5121 | sig_entry->per_cu.reading_dwo_directly = 1; | |
5122 | sig_entry->per_cu.objfile = objfile; | |
a2ce51a0 DE |
5123 | sig_entry->type_offset_in_tu = dwo_entry->type_offset_in_tu; |
5124 | sig_entry->dwo_unit = dwo_entry; | |
5125 | } | |
5126 | ||
5127 | /* Subroutine of lookup_signatured_type. | |
7ee85ab1 DE |
5128 | If we haven't read the TU yet, create the signatured_type data structure |
5129 | for a TU to be read in directly from a DWO file, bypassing the stub. | |
5130 | This is the "Stay in DWO Optimization": When there is no DWP file and we're | |
5131 | using .gdb_index, then when reading a CU we want to stay in the DWO file | |
5132 | containing that CU. Otherwise we could end up reading several other DWO | |
5133 | files (due to comdat folding) to process the transitive closure of all the | |
5134 | mentioned TUs, and that can be slow. The current DWO file will have every | |
5135 | type signature that it needs. | |
a2ce51a0 DE |
5136 | We only do this for .gdb_index because in the psymtab case we already have |
5137 | to read all the DWOs to build the type unit groups. */ | |
5138 | ||
5139 | static struct signatured_type * | |
5140 | lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) | |
5141 | { | |
5142 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
5143 | struct dwo_file *dwo_file; | |
5144 | struct dwo_unit find_dwo_entry, *dwo_entry; | |
5145 | struct signatured_type find_sig_entry, *sig_entry; | |
6aa5f3a6 | 5146 | void **slot; |
a2ce51a0 DE |
5147 | |
5148 | gdb_assert (cu->dwo_unit && dwarf2_per_objfile->using_index); | |
5149 | ||
6aa5f3a6 DE |
5150 | /* If TU skeletons have been removed then we may not have read in any |
5151 | TUs yet. */ | |
5152 | if (dwarf2_per_objfile->signatured_types == NULL) | |
5153 | { | |
5154 | dwarf2_per_objfile->signatured_types | |
5155 | = allocate_signatured_type_table (objfile); | |
5156 | } | |
a2ce51a0 DE |
5157 | |
5158 | /* We only ever need to read in one copy of a signatured type. | |
6aa5f3a6 DE |
5159 | Use the global signatured_types array to do our own comdat-folding |
5160 | of types. If this is the first time we're reading this TU, and | |
5161 | the TU has an entry in .gdb_index, replace the recorded data from | |
5162 | .gdb_index with this TU. */ | |
a2ce51a0 | 5163 | |
a2ce51a0 | 5164 | find_sig_entry.signature = sig; |
6aa5f3a6 DE |
5165 | slot = htab_find_slot (dwarf2_per_objfile->signatured_types, |
5166 | &find_sig_entry, INSERT); | |
9a3c8263 | 5167 | sig_entry = (struct signatured_type *) *slot; |
7ee85ab1 DE |
5168 | |
5169 | /* We can get here with the TU already read, *or* in the process of being | |
6aa5f3a6 DE |
5170 | read. Don't reassign the global entry to point to this DWO if that's |
5171 | the case. Also note that if the TU is already being read, it may not | |
5172 | have come from a DWO, the program may be a mix of Fission-compiled | |
5173 | code and non-Fission-compiled code. */ | |
5174 | ||
5175 | /* Have we already tried to read this TU? | |
5176 | Note: sig_entry can be NULL if the skeleton TU was removed (thus it | |
5177 | needn't exist in the global table yet). */ | |
5178 | if (sig_entry != NULL && sig_entry->per_cu.tu_read) | |
a2ce51a0 DE |
5179 | return sig_entry; |
5180 | ||
6aa5f3a6 DE |
5181 | /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the |
5182 | dwo_unit of the TU itself. */ | |
5183 | dwo_file = cu->dwo_unit->dwo_file; | |
5184 | ||
a2ce51a0 DE |
5185 | /* Ok, this is the first time we're reading this TU. */ |
5186 | if (dwo_file->tus == NULL) | |
5187 | return NULL; | |
5188 | find_dwo_entry.signature = sig; | |
9a3c8263 | 5189 | dwo_entry = (struct dwo_unit *) htab_find (dwo_file->tus, &find_dwo_entry); |
a2ce51a0 DE |
5190 | if (dwo_entry == NULL) |
5191 | return NULL; | |
5192 | ||
6aa5f3a6 DE |
5193 | /* If the global table doesn't have an entry for this TU, add one. */ |
5194 | if (sig_entry == NULL) | |
5195 | sig_entry = add_type_unit (sig, slot); | |
5196 | ||
a2ce51a0 | 5197 | fill_in_sig_entry_from_dwo_entry (objfile, sig_entry, dwo_entry); |
89e63ee4 | 5198 | sig_entry->per_cu.tu_read = 1; |
a2ce51a0 DE |
5199 | return sig_entry; |
5200 | } | |
5201 | ||
a2ce51a0 DE |
5202 | /* Subroutine of lookup_signatured_type. |
5203 | Look up the type for signature SIG, and if we can't find SIG in .gdb_index | |
6aa5f3a6 DE |
5204 | then try the DWP file. If the TU stub (skeleton) has been removed then |
5205 | it won't be in .gdb_index. */ | |
a2ce51a0 DE |
5206 | |
5207 | static struct signatured_type * | |
5208 | lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) | |
5209 | { | |
5210 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
5211 | struct dwp_file *dwp_file = get_dwp_file (); | |
5212 | struct dwo_unit *dwo_entry; | |
5213 | struct signatured_type find_sig_entry, *sig_entry; | |
6aa5f3a6 | 5214 | void **slot; |
a2ce51a0 DE |
5215 | |
5216 | gdb_assert (cu->dwo_unit && dwarf2_per_objfile->using_index); | |
5217 | gdb_assert (dwp_file != NULL); | |
5218 | ||
6aa5f3a6 DE |
5219 | /* If TU skeletons have been removed then we may not have read in any |
5220 | TUs yet. */ | |
5221 | if (dwarf2_per_objfile->signatured_types == NULL) | |
a2ce51a0 | 5222 | { |
6aa5f3a6 DE |
5223 | dwarf2_per_objfile->signatured_types |
5224 | = allocate_signatured_type_table (objfile); | |
a2ce51a0 DE |
5225 | } |
5226 | ||
6aa5f3a6 DE |
5227 | find_sig_entry.signature = sig; |
5228 | slot = htab_find_slot (dwarf2_per_objfile->signatured_types, | |
5229 | &find_sig_entry, INSERT); | |
9a3c8263 | 5230 | sig_entry = (struct signatured_type *) *slot; |
6aa5f3a6 DE |
5231 | |
5232 | /* Have we already tried to read this TU? | |
5233 | Note: sig_entry can be NULL if the skeleton TU was removed (thus it | |
5234 | needn't exist in the global table yet). */ | |
5235 | if (sig_entry != NULL) | |
5236 | return sig_entry; | |
5237 | ||
a2ce51a0 DE |
5238 | if (dwp_file->tus == NULL) |
5239 | return NULL; | |
57d63ce2 DE |
5240 | dwo_entry = lookup_dwo_unit_in_dwp (dwp_file, NULL, |
5241 | sig, 1 /* is_debug_types */); | |
a2ce51a0 DE |
5242 | if (dwo_entry == NULL) |
5243 | return NULL; | |
5244 | ||
6aa5f3a6 | 5245 | sig_entry = add_type_unit (sig, slot); |
a2ce51a0 DE |
5246 | fill_in_sig_entry_from_dwo_entry (objfile, sig_entry, dwo_entry); |
5247 | ||
a2ce51a0 DE |
5248 | return sig_entry; |
5249 | } | |
5250 | ||
380bca97 | 5251 | /* Lookup a signature based type for DW_FORM_ref_sig8. |
5a8b3f62 DE |
5252 | Returns NULL if signature SIG is not present in the table. |
5253 | It is up to the caller to complain about this. */ | |
348e048f DE |
5254 | |
5255 | static struct signatured_type * | |
a2ce51a0 | 5256 | lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) |
348e048f | 5257 | { |
a2ce51a0 DE |
5258 | if (cu->dwo_unit |
5259 | && dwarf2_per_objfile->using_index) | |
5260 | { | |
5261 | /* We're in a DWO/DWP file, and we're using .gdb_index. | |
5262 | These cases require special processing. */ | |
5263 | if (get_dwp_file () == NULL) | |
5264 | return lookup_dwo_signatured_type (cu, sig); | |
5265 | else | |
5266 | return lookup_dwp_signatured_type (cu, sig); | |
5267 | } | |
5268 | else | |
5269 | { | |
5270 | struct signatured_type find_entry, *entry; | |
348e048f | 5271 | |
a2ce51a0 DE |
5272 | if (dwarf2_per_objfile->signatured_types == NULL) |
5273 | return NULL; | |
5274 | find_entry.signature = sig; | |
9a3c8263 SM |
5275 | entry = ((struct signatured_type *) |
5276 | htab_find (dwarf2_per_objfile->signatured_types, &find_entry)); | |
a2ce51a0 DE |
5277 | return entry; |
5278 | } | |
348e048f | 5279 | } |
42e7ad6c DE |
5280 | \f |
5281 | /* Low level DIE reading support. */ | |
348e048f | 5282 | |
d85a05f0 DJ |
5283 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
5284 | ||
5285 | static void | |
5286 | init_cu_die_reader (struct die_reader_specs *reader, | |
dee91e82 | 5287 | struct dwarf2_cu *cu, |
3019eac3 DE |
5288 | struct dwarf2_section_info *section, |
5289 | struct dwo_file *dwo_file) | |
d85a05f0 | 5290 | { |
fceca515 | 5291 | gdb_assert (section->readin && section->buffer != NULL); |
a32a8923 | 5292 | reader->abfd = get_section_bfd_owner (section); |
d85a05f0 | 5293 | reader->cu = cu; |
3019eac3 | 5294 | reader->dwo_file = dwo_file; |
dee91e82 DE |
5295 | reader->die_section = section; |
5296 | reader->buffer = section->buffer; | |
f664829e | 5297 | reader->buffer_end = section->buffer + section->size; |
a2ce51a0 | 5298 | reader->comp_dir = NULL; |
d85a05f0 DJ |
5299 | } |
5300 | ||
b0c7bfa9 DE |
5301 | /* Subroutine of init_cutu_and_read_dies to simplify it. |
5302 | Read in the rest of a CU/TU top level DIE from DWO_UNIT. | |
5303 | There's just a lot of work to do, and init_cutu_and_read_dies is big enough | |
5304 | already. | |
5305 | ||
5306 | STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes | |
5307 | from it to the DIE in the DWO. If NULL we are skipping the stub. | |
a2ce51a0 DE |
5308 | STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly |
5309 | from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir | |
c54a1dd8 DE |
5310 | attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and |
5311 | STUB_COMP_DIR may be non-NULL. | |
b0c7bfa9 DE |
5312 | *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN |
5313 | are filled in with the info of the DIE from the DWO file. | |
5314 | ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies | |
5315 | provided an abbrev table to use. | |
5316 | The result is non-zero if a valid (non-dummy) DIE was found. */ | |
5317 | ||
5318 | static int | |
5319 | read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu, | |
5320 | struct dwo_unit *dwo_unit, | |
5321 | int abbrev_table_provided, | |
5322 | struct die_info *stub_comp_unit_die, | |
a2ce51a0 | 5323 | const char *stub_comp_dir, |
b0c7bfa9 | 5324 | struct die_reader_specs *result_reader, |
d521ce57 | 5325 | const gdb_byte **result_info_ptr, |
b0c7bfa9 DE |
5326 | struct die_info **result_comp_unit_die, |
5327 | int *result_has_children) | |
5328 | { | |
5329 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
5330 | struct dwarf2_cu *cu = this_cu->cu; | |
5331 | struct dwarf2_section_info *section; | |
5332 | bfd *abfd; | |
d521ce57 | 5333 | const gdb_byte *begin_info_ptr, *info_ptr; |
b0c7bfa9 DE |
5334 | ULONGEST signature; /* Or dwo_id. */ |
5335 | struct attribute *comp_dir, *stmt_list, *low_pc, *high_pc, *ranges; | |
5336 | int i,num_extra_attrs; | |
5337 | struct dwarf2_section_info *dwo_abbrev_section; | |
5338 | struct attribute *attr; | |
5339 | struct die_info *comp_unit_die; | |
5340 | ||
b0aeadb3 DE |
5341 | /* At most one of these may be provided. */ |
5342 | gdb_assert ((stub_comp_unit_die != NULL) + (stub_comp_dir != NULL) <= 1); | |
a2ce51a0 | 5343 | |
b0c7bfa9 DE |
5344 | /* These attributes aren't processed until later: |
5345 | DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges. | |
0d60c288 DE |
5346 | DW_AT_comp_dir is used now, to find the DWO file, but it is also |
5347 | referenced later. However, these attributes are found in the stub | |
5348 | which we won't have later. In order to not impose this complication | |
5349 | on the rest of the code, we read them here and copy them to the | |
5350 | DWO CU/TU die. */ | |
b0c7bfa9 DE |
5351 | |
5352 | stmt_list = NULL; | |
5353 | low_pc = NULL; | |
5354 | high_pc = NULL; | |
5355 | ranges = NULL; | |
5356 | comp_dir = NULL; | |
5357 | ||
5358 | if (stub_comp_unit_die != NULL) | |
5359 | { | |
5360 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the | |
5361 | DWO file. */ | |
5362 | if (! this_cu->is_debug_types) | |
5363 | stmt_list = dwarf2_attr (stub_comp_unit_die, DW_AT_stmt_list, cu); | |
5364 | low_pc = dwarf2_attr (stub_comp_unit_die, DW_AT_low_pc, cu); | |
5365 | high_pc = dwarf2_attr (stub_comp_unit_die, DW_AT_high_pc, cu); | |
5366 | ranges = dwarf2_attr (stub_comp_unit_die, DW_AT_ranges, cu); | |
5367 | comp_dir = dwarf2_attr (stub_comp_unit_die, DW_AT_comp_dir, cu); | |
5368 | ||
5369 | /* There should be a DW_AT_addr_base attribute here (if needed). | |
5370 | We need the value before we can process DW_FORM_GNU_addr_index. */ | |
5371 | cu->addr_base = 0; | |
5372 | attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_addr_base, cu); | |
5373 | if (attr) | |
5374 | cu->addr_base = DW_UNSND (attr); | |
5375 | ||
5376 | /* There should be a DW_AT_ranges_base attribute here (if needed). | |
5377 | We need the value before we can process DW_AT_ranges. */ | |
5378 | cu->ranges_base = 0; | |
5379 | attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_ranges_base, cu); | |
5380 | if (attr) | |
5381 | cu->ranges_base = DW_UNSND (attr); | |
5382 | } | |
a2ce51a0 DE |
5383 | else if (stub_comp_dir != NULL) |
5384 | { | |
5385 | /* Reconstruct the comp_dir attribute to simplify the code below. */ | |
8d749320 | 5386 | comp_dir = XOBNEW (&cu->comp_unit_obstack, struct attribute); |
a2ce51a0 DE |
5387 | comp_dir->name = DW_AT_comp_dir; |
5388 | comp_dir->form = DW_FORM_string; | |
5389 | DW_STRING_IS_CANONICAL (comp_dir) = 0; | |
5390 | DW_STRING (comp_dir) = stub_comp_dir; | |
5391 | } | |
b0c7bfa9 DE |
5392 | |
5393 | /* Set up for reading the DWO CU/TU. */ | |
5394 | cu->dwo_unit = dwo_unit; | |
5395 | section = dwo_unit->section; | |
5396 | dwarf2_read_section (objfile, section); | |
a32a8923 | 5397 | abfd = get_section_bfd_owner (section); |
9c541725 PA |
5398 | begin_info_ptr = info_ptr = (section->buffer |
5399 | + to_underlying (dwo_unit->sect_off)); | |
b0c7bfa9 DE |
5400 | dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev; |
5401 | init_cu_die_reader (result_reader, cu, section, dwo_unit->dwo_file); | |
5402 | ||
5403 | if (this_cu->is_debug_types) | |
5404 | { | |
b0c7bfa9 DE |
5405 | struct signatured_type *sig_type = (struct signatured_type *) this_cu; |
5406 | ||
43988095 | 5407 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, |
b0c7bfa9 | 5408 | dwo_abbrev_section, |
43988095 | 5409 | info_ptr, rcuh_kind::TYPE); |
a2ce51a0 | 5410 | /* This is not an assert because it can be caused by bad debug info. */ |
43988095 | 5411 | if (sig_type->signature != cu->header.signature) |
a2ce51a0 DE |
5412 | { |
5413 | error (_("Dwarf Error: signature mismatch %s vs %s while reading" | |
5414 | " TU at offset 0x%x [in module %s]"), | |
5415 | hex_string (sig_type->signature), | |
43988095 | 5416 | hex_string (cu->header.signature), |
9c541725 | 5417 | to_underlying (dwo_unit->sect_off), |
a2ce51a0 DE |
5418 | bfd_get_filename (abfd)); |
5419 | } | |
9c541725 | 5420 | gdb_assert (dwo_unit->sect_off == cu->header.sect_off); |
b0c7bfa9 DE |
5421 | /* For DWOs coming from DWP files, we don't know the CU length |
5422 | nor the type's offset in the TU until now. */ | |
5423 | dwo_unit->length = get_cu_length (&cu->header); | |
9c541725 | 5424 | dwo_unit->type_offset_in_tu = cu->header.type_cu_offset_in_tu; |
b0c7bfa9 DE |
5425 | |
5426 | /* Establish the type offset that can be used to lookup the type. | |
5427 | For DWO files, we don't know it until now. */ | |
9c541725 PA |
5428 | sig_type->type_offset_in_section |
5429 | = dwo_unit->sect_off + to_underlying (dwo_unit->type_offset_in_tu); | |
b0c7bfa9 DE |
5430 | } |
5431 | else | |
5432 | { | |
5433 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, | |
5434 | dwo_abbrev_section, | |
43988095 | 5435 | info_ptr, rcuh_kind::COMPILE); |
9c541725 | 5436 | gdb_assert (dwo_unit->sect_off == cu->header.sect_off); |
b0c7bfa9 DE |
5437 | /* For DWOs coming from DWP files, we don't know the CU length |
5438 | until now. */ | |
5439 | dwo_unit->length = get_cu_length (&cu->header); | |
5440 | } | |
5441 | ||
02142a6c DE |
5442 | /* Replace the CU's original abbrev table with the DWO's. |
5443 | Reminder: We can't read the abbrev table until we've read the header. */ | |
b0c7bfa9 DE |
5444 | if (abbrev_table_provided) |
5445 | { | |
5446 | /* Don't free the provided abbrev table, the caller of | |
5447 | init_cutu_and_read_dies owns it. */ | |
5448 | dwarf2_read_abbrevs (cu, dwo_abbrev_section); | |
02142a6c | 5449 | /* Ensure the DWO abbrev table gets freed. */ |
b0c7bfa9 DE |
5450 | make_cleanup (dwarf2_free_abbrev_table, cu); |
5451 | } | |
5452 | else | |
5453 | { | |
5454 | dwarf2_free_abbrev_table (cu); | |
5455 | dwarf2_read_abbrevs (cu, dwo_abbrev_section); | |
02142a6c | 5456 | /* Leave any existing abbrev table cleanup as is. */ |
b0c7bfa9 DE |
5457 | } |
5458 | ||
5459 | /* Read in the die, but leave space to copy over the attributes | |
5460 | from the stub. This has the benefit of simplifying the rest of | |
5461 | the code - all the work to maintain the illusion of a single | |
5462 | DW_TAG_{compile,type}_unit DIE is done here. */ | |
5463 | num_extra_attrs = ((stmt_list != NULL) | |
5464 | + (low_pc != NULL) | |
5465 | + (high_pc != NULL) | |
5466 | + (ranges != NULL) | |
5467 | + (comp_dir != NULL)); | |
5468 | info_ptr = read_full_die_1 (result_reader, result_comp_unit_die, info_ptr, | |
5469 | result_has_children, num_extra_attrs); | |
5470 | ||
5471 | /* Copy over the attributes from the stub to the DIE we just read in. */ | |
5472 | comp_unit_die = *result_comp_unit_die; | |
5473 | i = comp_unit_die->num_attrs; | |
5474 | if (stmt_list != NULL) | |
5475 | comp_unit_die->attrs[i++] = *stmt_list; | |
5476 | if (low_pc != NULL) | |
5477 | comp_unit_die->attrs[i++] = *low_pc; | |
5478 | if (high_pc != NULL) | |
5479 | comp_unit_die->attrs[i++] = *high_pc; | |
5480 | if (ranges != NULL) | |
5481 | comp_unit_die->attrs[i++] = *ranges; | |
5482 | if (comp_dir != NULL) | |
5483 | comp_unit_die->attrs[i++] = *comp_dir; | |
5484 | comp_unit_die->num_attrs += num_extra_attrs; | |
5485 | ||
b4f54984 | 5486 | if (dwarf_die_debug) |
bf6af496 DE |
5487 | { |
5488 | fprintf_unfiltered (gdb_stdlog, | |
5489 | "Read die from %s@0x%x of %s:\n", | |
a32a8923 | 5490 | get_section_name (section), |
bf6af496 DE |
5491 | (unsigned) (begin_info_ptr - section->buffer), |
5492 | bfd_get_filename (abfd)); | |
b4f54984 | 5493 | dump_die (comp_unit_die, dwarf_die_debug); |
bf6af496 DE |
5494 | } |
5495 | ||
a2ce51a0 DE |
5496 | /* Save the comp_dir attribute. If there is no DWP file then we'll read |
5497 | TUs by skipping the stub and going directly to the entry in the DWO file. | |
5498 | However, skipping the stub means we won't get DW_AT_comp_dir, so we have | |
5499 | to get it via circuitous means. Blech. */ | |
5500 | if (comp_dir != NULL) | |
5501 | result_reader->comp_dir = DW_STRING (comp_dir); | |
5502 | ||
b0c7bfa9 DE |
5503 | /* Skip dummy compilation units. */ |
5504 | if (info_ptr >= begin_info_ptr + dwo_unit->length | |
5505 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
5506 | return 0; | |
5507 | ||
5508 | *result_info_ptr = info_ptr; | |
5509 | return 1; | |
5510 | } | |
5511 | ||
5512 | /* Subroutine of init_cutu_and_read_dies to simplify it. | |
5513 | Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU. | |
6a506a2d | 5514 | Returns NULL if the specified DWO unit cannot be found. */ |
b0c7bfa9 DE |
5515 | |
5516 | static struct dwo_unit * | |
5517 | lookup_dwo_unit (struct dwarf2_per_cu_data *this_cu, | |
5518 | struct die_info *comp_unit_die) | |
5519 | { | |
5520 | struct dwarf2_cu *cu = this_cu->cu; | |
5521 | struct attribute *attr; | |
5522 | ULONGEST signature; | |
5523 | struct dwo_unit *dwo_unit; | |
5524 | const char *comp_dir, *dwo_name; | |
5525 | ||
a2ce51a0 DE |
5526 | gdb_assert (cu != NULL); |
5527 | ||
b0c7bfa9 | 5528 | /* Yeah, we look dwo_name up again, but it simplifies the code. */ |
7d45c7c3 KB |
5529 | dwo_name = dwarf2_string_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu); |
5530 | comp_dir = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu); | |
b0c7bfa9 DE |
5531 | |
5532 | if (this_cu->is_debug_types) | |
5533 | { | |
5534 | struct signatured_type *sig_type; | |
5535 | ||
5536 | /* Since this_cu is the first member of struct signatured_type, | |
5537 | we can go from a pointer to one to a pointer to the other. */ | |
5538 | sig_type = (struct signatured_type *) this_cu; | |
5539 | signature = sig_type->signature; | |
5540 | dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir); | |
5541 | } | |
5542 | else | |
5543 | { | |
5544 | struct attribute *attr; | |
5545 | ||
5546 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); | |
5547 | if (! attr) | |
5548 | error (_("Dwarf Error: missing dwo_id for dwo_name %s" | |
5549 | " [in module %s]"), | |
4262abfb | 5550 | dwo_name, objfile_name (this_cu->objfile)); |
b0c7bfa9 DE |
5551 | signature = DW_UNSND (attr); |
5552 | dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir, | |
5553 | signature); | |
5554 | } | |
5555 | ||
b0c7bfa9 DE |
5556 | return dwo_unit; |
5557 | } | |
5558 | ||
a2ce51a0 | 5559 | /* Subroutine of init_cutu_and_read_dies to simplify it. |
6aa5f3a6 DE |
5560 | See it for a description of the parameters. |
5561 | Read a TU directly from a DWO file, bypassing the stub. | |
5562 | ||
5563 | Note: This function could be a little bit simpler if we shared cleanups | |
5564 | with our caller, init_cutu_and_read_dies. That's generally a fragile thing | |
5565 | to do, so we keep this function self-contained. Or we could move this | |
5566 | into our caller, but it's complex enough already. */ | |
a2ce51a0 DE |
5567 | |
5568 | static void | |
6aa5f3a6 DE |
5569 | init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu, |
5570 | int use_existing_cu, int keep, | |
a2ce51a0 DE |
5571 | die_reader_func_ftype *die_reader_func, |
5572 | void *data) | |
5573 | { | |
5574 | struct dwarf2_cu *cu; | |
5575 | struct signatured_type *sig_type; | |
6aa5f3a6 | 5576 | struct cleanup *cleanups, *free_cu_cleanup = NULL; |
a2ce51a0 DE |
5577 | struct die_reader_specs reader; |
5578 | const gdb_byte *info_ptr; | |
5579 | struct die_info *comp_unit_die; | |
5580 | int has_children; | |
5581 | ||
5582 | /* Verify we can do the following downcast, and that we have the | |
5583 | data we need. */ | |
5584 | gdb_assert (this_cu->is_debug_types && this_cu->reading_dwo_directly); | |
5585 | sig_type = (struct signatured_type *) this_cu; | |
5586 | gdb_assert (sig_type->dwo_unit != NULL); | |
5587 | ||
5588 | cleanups = make_cleanup (null_cleanup, NULL); | |
5589 | ||
6aa5f3a6 DE |
5590 | if (use_existing_cu && this_cu->cu != NULL) |
5591 | { | |
5592 | gdb_assert (this_cu->cu->dwo_unit == sig_type->dwo_unit); | |
5593 | cu = this_cu->cu; | |
5594 | /* There's no need to do the rereading_dwo_cu handling that | |
5595 | init_cutu_and_read_dies does since we don't read the stub. */ | |
5596 | } | |
5597 | else | |
5598 | { | |
5599 | /* If !use_existing_cu, this_cu->cu must be NULL. */ | |
5600 | gdb_assert (this_cu->cu == NULL); | |
8d749320 | 5601 | cu = XNEW (struct dwarf2_cu); |
6aa5f3a6 DE |
5602 | init_one_comp_unit (cu, this_cu); |
5603 | /* If an error occurs while loading, release our storage. */ | |
5604 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); | |
5605 | } | |
5606 | ||
5607 | /* A future optimization, if needed, would be to use an existing | |
5608 | abbrev table. When reading DWOs with skeletonless TUs, all the TUs | |
5609 | could share abbrev tables. */ | |
a2ce51a0 DE |
5610 | |
5611 | if (read_cutu_die_from_dwo (this_cu, sig_type->dwo_unit, | |
5612 | 0 /* abbrev_table_provided */, | |
5613 | NULL /* stub_comp_unit_die */, | |
5614 | sig_type->dwo_unit->dwo_file->comp_dir, | |
5615 | &reader, &info_ptr, | |
5616 | &comp_unit_die, &has_children) == 0) | |
5617 | { | |
5618 | /* Dummy die. */ | |
5619 | do_cleanups (cleanups); | |
5620 | return; | |
5621 | } | |
5622 | ||
5623 | /* All the "real" work is done here. */ | |
5624 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); | |
5625 | ||
6aa5f3a6 | 5626 | /* This duplicates the code in init_cutu_and_read_dies, |
a2ce51a0 DE |
5627 | but the alternative is making the latter more complex. |
5628 | This function is only for the special case of using DWO files directly: | |
5629 | no point in overly complicating the general case just to handle this. */ | |
6aa5f3a6 | 5630 | if (free_cu_cleanup != NULL) |
a2ce51a0 | 5631 | { |
6aa5f3a6 DE |
5632 | if (keep) |
5633 | { | |
5634 | /* We've successfully allocated this compilation unit. Let our | |
5635 | caller clean it up when finished with it. */ | |
5636 | discard_cleanups (free_cu_cleanup); | |
a2ce51a0 | 5637 | |
6aa5f3a6 DE |
5638 | /* We can only discard free_cu_cleanup and all subsequent cleanups. |
5639 | So we have to manually free the abbrev table. */ | |
5640 | dwarf2_free_abbrev_table (cu); | |
a2ce51a0 | 5641 | |
6aa5f3a6 DE |
5642 | /* Link this CU into read_in_chain. */ |
5643 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
5644 | dwarf2_per_objfile->read_in_chain = this_cu; | |
5645 | } | |
5646 | else | |
5647 | do_cleanups (free_cu_cleanup); | |
a2ce51a0 | 5648 | } |
a2ce51a0 DE |
5649 | |
5650 | do_cleanups (cleanups); | |
5651 | } | |
5652 | ||
fd820528 | 5653 | /* Initialize a CU (or TU) and read its DIEs. |
3019eac3 | 5654 | If the CU defers to a DWO file, read the DWO file as well. |
dee91e82 | 5655 | |
f4dc4d17 DE |
5656 | ABBREV_TABLE, if non-NULL, is the abbreviation table to use. |
5657 | Otherwise the table specified in the comp unit header is read in and used. | |
5658 | This is an optimization for when we already have the abbrev table. | |
5659 | ||
dee91e82 DE |
5660 | If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it. |
5661 | Otherwise, a new CU is allocated with xmalloc. | |
5662 | ||
5663 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to | |
5664 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. | |
5665 | ||
5666 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
fd820528 | 5667 | linker) then DIE_READER_FUNC will not get called. */ |
aaa75496 | 5668 | |
70221824 | 5669 | static void |
fd820528 | 5670 | init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu, |
f4dc4d17 | 5671 | struct abbrev_table *abbrev_table, |
fd820528 DE |
5672 | int use_existing_cu, int keep, |
5673 | die_reader_func_ftype *die_reader_func, | |
5674 | void *data) | |
c906108c | 5675 | { |
dee91e82 | 5676 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
8a0459fd | 5677 | struct dwarf2_section_info *section = this_cu->section; |
a32a8923 | 5678 | bfd *abfd = get_section_bfd_owner (section); |
dee91e82 | 5679 | struct dwarf2_cu *cu; |
d521ce57 | 5680 | const gdb_byte *begin_info_ptr, *info_ptr; |
dee91e82 | 5681 | struct die_reader_specs reader; |
d85a05f0 | 5682 | struct die_info *comp_unit_die; |
dee91e82 | 5683 | int has_children; |
d85a05f0 | 5684 | struct attribute *attr; |
365156ad | 5685 | struct cleanup *cleanups, *free_cu_cleanup = NULL; |
dee91e82 | 5686 | struct signatured_type *sig_type = NULL; |
4bdcc0c1 | 5687 | struct dwarf2_section_info *abbrev_section; |
42e7ad6c DE |
5688 | /* Non-zero if CU currently points to a DWO file and we need to |
5689 | reread it. When this happens we need to reread the skeleton die | |
a2ce51a0 | 5690 | before we can reread the DWO file (this only applies to CUs, not TUs). */ |
42e7ad6c | 5691 | int rereading_dwo_cu = 0; |
c906108c | 5692 | |
b4f54984 | 5693 | if (dwarf_die_debug) |
09406207 DE |
5694 | fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n", |
5695 | this_cu->is_debug_types ? "type" : "comp", | |
9c541725 | 5696 | to_underlying (this_cu->sect_off)); |
09406207 | 5697 | |
dee91e82 DE |
5698 | if (use_existing_cu) |
5699 | gdb_assert (keep); | |
23745b47 | 5700 | |
a2ce51a0 DE |
5701 | /* If we're reading a TU directly from a DWO file, including a virtual DWO |
5702 | file (instead of going through the stub), short-circuit all of this. */ | |
5703 | if (this_cu->reading_dwo_directly) | |
5704 | { | |
5705 | /* Narrow down the scope of possibilities to have to understand. */ | |
5706 | gdb_assert (this_cu->is_debug_types); | |
5707 | gdb_assert (abbrev_table == NULL); | |
6aa5f3a6 DE |
5708 | init_tu_and_read_dwo_dies (this_cu, use_existing_cu, keep, |
5709 | die_reader_func, data); | |
a2ce51a0 DE |
5710 | return; |
5711 | } | |
5712 | ||
dee91e82 DE |
5713 | cleanups = make_cleanup (null_cleanup, NULL); |
5714 | ||
5715 | /* This is cheap if the section is already read in. */ | |
5716 | dwarf2_read_section (objfile, section); | |
5717 | ||
9c541725 | 5718 | begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off); |
36586728 TT |
5719 | |
5720 | abbrev_section = get_abbrev_section_for_cu (this_cu); | |
dee91e82 DE |
5721 | |
5722 | if (use_existing_cu && this_cu->cu != NULL) | |
5723 | { | |
5724 | cu = this_cu->cu; | |
42e7ad6c DE |
5725 | /* If this CU is from a DWO file we need to start over, we need to |
5726 | refetch the attributes from the skeleton CU. | |
5727 | This could be optimized by retrieving those attributes from when we | |
5728 | were here the first time: the previous comp_unit_die was stored in | |
5729 | comp_unit_obstack. But there's no data yet that we need this | |
5730 | optimization. */ | |
5731 | if (cu->dwo_unit != NULL) | |
5732 | rereading_dwo_cu = 1; | |
dee91e82 DE |
5733 | } |
5734 | else | |
5735 | { | |
5736 | /* If !use_existing_cu, this_cu->cu must be NULL. */ | |
5737 | gdb_assert (this_cu->cu == NULL); | |
8d749320 | 5738 | cu = XNEW (struct dwarf2_cu); |
dee91e82 | 5739 | init_one_comp_unit (cu, this_cu); |
dee91e82 | 5740 | /* If an error occurs while loading, release our storage. */ |
365156ad | 5741 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
42e7ad6c | 5742 | } |
dee91e82 | 5743 | |
b0c7bfa9 | 5744 | /* Get the header. */ |
9c541725 | 5745 | if (to_underlying (cu->header.first_die_cu_offset) != 0 && !rereading_dwo_cu) |
42e7ad6c DE |
5746 | { |
5747 | /* We already have the header, there's no need to read it in again. */ | |
9c541725 | 5748 | info_ptr += to_underlying (cu->header.first_die_cu_offset); |
42e7ad6c DE |
5749 | } |
5750 | else | |
5751 | { | |
3019eac3 | 5752 | if (this_cu->is_debug_types) |
dee91e82 | 5753 | { |
43988095 | 5754 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, |
4bdcc0c1 | 5755 | abbrev_section, info_ptr, |
43988095 | 5756 | rcuh_kind::TYPE); |
dee91e82 | 5757 | |
42e7ad6c DE |
5758 | /* Since per_cu is the first member of struct signatured_type, |
5759 | we can go from a pointer to one to a pointer to the other. */ | |
5760 | sig_type = (struct signatured_type *) this_cu; | |
43988095 | 5761 | gdb_assert (sig_type->signature == cu->header.signature); |
9c541725 PA |
5762 | gdb_assert (sig_type->type_offset_in_tu |
5763 | == cu->header.type_cu_offset_in_tu); | |
5764 | gdb_assert (this_cu->sect_off == cu->header.sect_off); | |
dee91e82 | 5765 | |
42e7ad6c DE |
5766 | /* LENGTH has not been set yet for type units if we're |
5767 | using .gdb_index. */ | |
1ce1cefd | 5768 | this_cu->length = get_cu_length (&cu->header); |
3019eac3 DE |
5769 | |
5770 | /* Establish the type offset that can be used to lookup the type. */ | |
9c541725 PA |
5771 | sig_type->type_offset_in_section = |
5772 | this_cu->sect_off + to_underlying (sig_type->type_offset_in_tu); | |
43988095 JK |
5773 | |
5774 | this_cu->dwarf_version = cu->header.version; | |
dee91e82 DE |
5775 | } |
5776 | else | |
5777 | { | |
4bdcc0c1 DE |
5778 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, |
5779 | abbrev_section, | |
43988095 JK |
5780 | info_ptr, |
5781 | rcuh_kind::COMPILE); | |
dee91e82 | 5782 | |
9c541725 | 5783 | gdb_assert (this_cu->sect_off == cu->header.sect_off); |
1ce1cefd | 5784 | gdb_assert (this_cu->length == get_cu_length (&cu->header)); |
43988095 | 5785 | this_cu->dwarf_version = cu->header.version; |
dee91e82 DE |
5786 | } |
5787 | } | |
10b3939b | 5788 | |
6caca83c | 5789 | /* Skip dummy compilation units. */ |
dee91e82 | 5790 | if (info_ptr >= begin_info_ptr + this_cu->length |
6caca83c CC |
5791 | || peek_abbrev_code (abfd, info_ptr) == 0) |
5792 | { | |
dee91e82 | 5793 | do_cleanups (cleanups); |
21b2bd31 | 5794 | return; |
6caca83c CC |
5795 | } |
5796 | ||
433df2d4 DE |
5797 | /* If we don't have them yet, read the abbrevs for this compilation unit. |
5798 | And if we need to read them now, make sure they're freed when we're | |
42e7ad6c DE |
5799 | done. Note that it's important that if the CU had an abbrev table |
5800 | on entry we don't free it when we're done: Somewhere up the call stack | |
5801 | it may be in use. */ | |
f4dc4d17 DE |
5802 | if (abbrev_table != NULL) |
5803 | { | |
5804 | gdb_assert (cu->abbrev_table == NULL); | |
9c541725 | 5805 | gdb_assert (cu->header.abbrev_sect_off == abbrev_table->sect_off); |
f4dc4d17 DE |
5806 | cu->abbrev_table = abbrev_table; |
5807 | } | |
5808 | else if (cu->abbrev_table == NULL) | |
dee91e82 | 5809 | { |
4bdcc0c1 | 5810 | dwarf2_read_abbrevs (cu, abbrev_section); |
dee91e82 DE |
5811 | make_cleanup (dwarf2_free_abbrev_table, cu); |
5812 | } | |
42e7ad6c DE |
5813 | else if (rereading_dwo_cu) |
5814 | { | |
5815 | dwarf2_free_abbrev_table (cu); | |
5816 | dwarf2_read_abbrevs (cu, abbrev_section); | |
5817 | } | |
af703f96 | 5818 | |
dee91e82 | 5819 | /* Read the top level CU/TU die. */ |
3019eac3 | 5820 | init_cu_die_reader (&reader, cu, section, NULL); |
dee91e82 | 5821 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
93311388 | 5822 | |
b0c7bfa9 DE |
5823 | /* If we are in a DWO stub, process it and then read in the "real" CU/TU |
5824 | from the DWO file. | |
5825 | Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a | |
5826 | DWO CU, that this test will fail (the attribute will not be present). */ | |
3019eac3 DE |
5827 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu); |
5828 | if (attr) | |
5829 | { | |
3019eac3 | 5830 | struct dwo_unit *dwo_unit; |
b0c7bfa9 | 5831 | struct die_info *dwo_comp_unit_die; |
3019eac3 DE |
5832 | |
5833 | if (has_children) | |
6a506a2d DE |
5834 | { |
5835 | complaint (&symfile_complaints, | |
5836 | _("compilation unit with DW_AT_GNU_dwo_name" | |
5837 | " has children (offset 0x%x) [in module %s]"), | |
9c541725 | 5838 | to_underlying (this_cu->sect_off), bfd_get_filename (abfd)); |
6a506a2d | 5839 | } |
b0c7bfa9 | 5840 | dwo_unit = lookup_dwo_unit (this_cu, comp_unit_die); |
6a506a2d | 5841 | if (dwo_unit != NULL) |
3019eac3 | 5842 | { |
6a506a2d DE |
5843 | if (read_cutu_die_from_dwo (this_cu, dwo_unit, |
5844 | abbrev_table != NULL, | |
a2ce51a0 | 5845 | comp_unit_die, NULL, |
6a506a2d DE |
5846 | &reader, &info_ptr, |
5847 | &dwo_comp_unit_die, &has_children) == 0) | |
5848 | { | |
5849 | /* Dummy die. */ | |
5850 | do_cleanups (cleanups); | |
5851 | return; | |
5852 | } | |
5853 | comp_unit_die = dwo_comp_unit_die; | |
5854 | } | |
5855 | else | |
5856 | { | |
5857 | /* Yikes, we couldn't find the rest of the DIE, we only have | |
5858 | the stub. A complaint has already been logged. There's | |
5859 | not much more we can do except pass on the stub DIE to | |
5860 | die_reader_func. We don't want to throw an error on bad | |
5861 | debug info. */ | |
3019eac3 DE |
5862 | } |
5863 | } | |
5864 | ||
b0c7bfa9 | 5865 | /* All of the above is setup for this call. Yikes. */ |
dee91e82 DE |
5866 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); |
5867 | ||
b0c7bfa9 | 5868 | /* Done, clean up. */ |
365156ad | 5869 | if (free_cu_cleanup != NULL) |
348e048f | 5870 | { |
365156ad TT |
5871 | if (keep) |
5872 | { | |
5873 | /* We've successfully allocated this compilation unit. Let our | |
5874 | caller clean it up when finished with it. */ | |
5875 | discard_cleanups (free_cu_cleanup); | |
dee91e82 | 5876 | |
365156ad TT |
5877 | /* We can only discard free_cu_cleanup and all subsequent cleanups. |
5878 | So we have to manually free the abbrev table. */ | |
5879 | dwarf2_free_abbrev_table (cu); | |
dee91e82 | 5880 | |
365156ad TT |
5881 | /* Link this CU into read_in_chain. */ |
5882 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
5883 | dwarf2_per_objfile->read_in_chain = this_cu; | |
5884 | } | |
5885 | else | |
5886 | do_cleanups (free_cu_cleanup); | |
348e048f | 5887 | } |
365156ad TT |
5888 | |
5889 | do_cleanups (cleanups); | |
dee91e82 DE |
5890 | } |
5891 | ||
33e80786 DE |
5892 | /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present. |
5893 | DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed | |
5894 | to have already done the lookup to find the DWO file). | |
dee91e82 DE |
5895 | |
5896 | The caller is required to fill in THIS_CU->section, THIS_CU->offset, and | |
3019eac3 | 5897 | THIS_CU->is_debug_types, but nothing else. |
dee91e82 DE |
5898 | |
5899 | We fill in THIS_CU->length. | |
5900 | ||
5901 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
5902 | linker) then DIE_READER_FUNC will not get called. | |
5903 | ||
5904 | THIS_CU->cu is always freed when done. | |
3019eac3 DE |
5905 | This is done in order to not leave THIS_CU->cu in a state where we have |
5906 | to care whether it refers to the "main" CU or the DWO CU. */ | |
dee91e82 DE |
5907 | |
5908 | static void | |
5909 | init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu, | |
3019eac3 | 5910 | struct dwo_file *dwo_file, |
dee91e82 DE |
5911 | die_reader_func_ftype *die_reader_func, |
5912 | void *data) | |
5913 | { | |
5914 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
8a0459fd | 5915 | struct dwarf2_section_info *section = this_cu->section; |
a32a8923 | 5916 | bfd *abfd = get_section_bfd_owner (section); |
33e80786 | 5917 | struct dwarf2_section_info *abbrev_section; |
dee91e82 | 5918 | struct dwarf2_cu cu; |
d521ce57 | 5919 | const gdb_byte *begin_info_ptr, *info_ptr; |
dee91e82 DE |
5920 | struct die_reader_specs reader; |
5921 | struct cleanup *cleanups; | |
5922 | struct die_info *comp_unit_die; | |
5923 | int has_children; | |
5924 | ||
b4f54984 | 5925 | if (dwarf_die_debug) |
09406207 DE |
5926 | fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n", |
5927 | this_cu->is_debug_types ? "type" : "comp", | |
9c541725 | 5928 | to_underlying (this_cu->sect_off)); |
09406207 | 5929 | |
dee91e82 DE |
5930 | gdb_assert (this_cu->cu == NULL); |
5931 | ||
33e80786 DE |
5932 | abbrev_section = (dwo_file != NULL |
5933 | ? &dwo_file->sections.abbrev | |
5934 | : get_abbrev_section_for_cu (this_cu)); | |
5935 | ||
dee91e82 DE |
5936 | /* This is cheap if the section is already read in. */ |
5937 | dwarf2_read_section (objfile, section); | |
5938 | ||
5939 | init_one_comp_unit (&cu, this_cu); | |
5940 | ||
5941 | cleanups = make_cleanup (free_stack_comp_unit, &cu); | |
5942 | ||
9c541725 | 5943 | begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off); |
4bdcc0c1 DE |
5944 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, |
5945 | abbrev_section, info_ptr, | |
43988095 JK |
5946 | (this_cu->is_debug_types |
5947 | ? rcuh_kind::TYPE | |
5948 | : rcuh_kind::COMPILE)); | |
dee91e82 | 5949 | |
1ce1cefd | 5950 | this_cu->length = get_cu_length (&cu.header); |
dee91e82 DE |
5951 | |
5952 | /* Skip dummy compilation units. */ | |
5953 | if (info_ptr >= begin_info_ptr + this_cu->length | |
5954 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
c906108c | 5955 | { |
dee91e82 | 5956 | do_cleanups (cleanups); |
21b2bd31 | 5957 | return; |
93311388 | 5958 | } |
72bf9492 | 5959 | |
dee91e82 DE |
5960 | dwarf2_read_abbrevs (&cu, abbrev_section); |
5961 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
5962 | ||
3019eac3 | 5963 | init_cu_die_reader (&reader, &cu, section, dwo_file); |
dee91e82 DE |
5964 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
5965 | ||
5966 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); | |
5967 | ||
5968 | do_cleanups (cleanups); | |
5969 | } | |
5970 | ||
3019eac3 DE |
5971 | /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and |
5972 | does not lookup the specified DWO file. | |
5973 | This cannot be used to read DWO files. | |
dee91e82 DE |
5974 | |
5975 | THIS_CU->cu is always freed when done. | |
3019eac3 DE |
5976 | This is done in order to not leave THIS_CU->cu in a state where we have |
5977 | to care whether it refers to the "main" CU or the DWO CU. | |
5978 | We can revisit this if the data shows there's a performance issue. */ | |
dee91e82 DE |
5979 | |
5980 | static void | |
5981 | init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu, | |
5982 | die_reader_func_ftype *die_reader_func, | |
5983 | void *data) | |
5984 | { | |
33e80786 | 5985 | init_cutu_and_read_dies_no_follow (this_cu, NULL, die_reader_func, data); |
dee91e82 | 5986 | } |
0018ea6f DE |
5987 | \f |
5988 | /* Type Unit Groups. | |
dee91e82 | 5989 | |
0018ea6f DE |
5990 | Type Unit Groups are a way to collapse the set of all TUs (type units) into |
5991 | a more manageable set. The grouping is done by DW_AT_stmt_list entry | |
5992 | so that all types coming from the same compilation (.o file) are grouped | |
5993 | together. A future step could be to put the types in the same symtab as | |
5994 | the CU the types ultimately came from. */ | |
ff013f42 | 5995 | |
f4dc4d17 DE |
5996 | static hashval_t |
5997 | hash_type_unit_group (const void *item) | |
5998 | { | |
9a3c8263 SM |
5999 | const struct type_unit_group *tu_group |
6000 | = (const struct type_unit_group *) item; | |
f4dc4d17 | 6001 | |
094b34ac | 6002 | return hash_stmt_list_entry (&tu_group->hash); |
f4dc4d17 | 6003 | } |
348e048f DE |
6004 | |
6005 | static int | |
f4dc4d17 | 6006 | eq_type_unit_group (const void *item_lhs, const void *item_rhs) |
348e048f | 6007 | { |
9a3c8263 SM |
6008 | const struct type_unit_group *lhs = (const struct type_unit_group *) item_lhs; |
6009 | const struct type_unit_group *rhs = (const struct type_unit_group *) item_rhs; | |
348e048f | 6010 | |
094b34ac | 6011 | return eq_stmt_list_entry (&lhs->hash, &rhs->hash); |
f4dc4d17 | 6012 | } |
348e048f | 6013 | |
f4dc4d17 DE |
6014 | /* Allocate a hash table for type unit groups. */ |
6015 | ||
6016 | static htab_t | |
6017 | allocate_type_unit_groups_table (void) | |
6018 | { | |
6019 | return htab_create_alloc_ex (3, | |
6020 | hash_type_unit_group, | |
6021 | eq_type_unit_group, | |
6022 | NULL, | |
6023 | &dwarf2_per_objfile->objfile->objfile_obstack, | |
6024 | hashtab_obstack_allocate, | |
6025 | dummy_obstack_deallocate); | |
6026 | } | |
dee91e82 | 6027 | |
f4dc4d17 DE |
6028 | /* Type units that don't have DW_AT_stmt_list are grouped into their own |
6029 | partial symtabs. We combine several TUs per psymtab to not let the size | |
6030 | of any one psymtab grow too big. */ | |
6031 | #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31) | |
6032 | #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10 | |
dee91e82 | 6033 | |
094b34ac | 6034 | /* Helper routine for get_type_unit_group. |
f4dc4d17 DE |
6035 | Create the type_unit_group object used to hold one or more TUs. */ |
6036 | ||
6037 | static struct type_unit_group * | |
094b34ac | 6038 | create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct) |
f4dc4d17 DE |
6039 | { |
6040 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
094b34ac | 6041 | struct dwarf2_per_cu_data *per_cu; |
f4dc4d17 | 6042 | struct type_unit_group *tu_group; |
f4dc4d17 DE |
6043 | |
6044 | tu_group = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
6045 | struct type_unit_group); | |
094b34ac | 6046 | per_cu = &tu_group->per_cu; |
f4dc4d17 | 6047 | per_cu->objfile = objfile; |
f4dc4d17 | 6048 | |
094b34ac DE |
6049 | if (dwarf2_per_objfile->using_index) |
6050 | { | |
6051 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
6052 | struct dwarf2_per_cu_quick_data); | |
094b34ac DE |
6053 | } |
6054 | else | |
6055 | { | |
9c541725 | 6056 | unsigned int line_offset = to_underlying (line_offset_struct); |
094b34ac DE |
6057 | struct partial_symtab *pst; |
6058 | char *name; | |
6059 | ||
6060 | /* Give the symtab a useful name for debug purposes. */ | |
6061 | if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0) | |
6062 | name = xstrprintf ("<type_units_%d>", | |
6063 | (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB)); | |
6064 | else | |
6065 | name = xstrprintf ("<type_units_at_0x%x>", line_offset); | |
6066 | ||
6067 | pst = create_partial_symtab (per_cu, name); | |
6068 | pst->anonymous = 1; | |
f4dc4d17 | 6069 | |
094b34ac DE |
6070 | xfree (name); |
6071 | } | |
f4dc4d17 | 6072 | |
094b34ac | 6073 | tu_group->hash.dwo_unit = cu->dwo_unit; |
9c541725 | 6074 | tu_group->hash.line_sect_off = line_offset_struct; |
f4dc4d17 DE |
6075 | |
6076 | return tu_group; | |
6077 | } | |
6078 | ||
094b34ac DE |
6079 | /* Look up the type_unit_group for type unit CU, and create it if necessary. |
6080 | STMT_LIST is a DW_AT_stmt_list attribute. */ | |
f4dc4d17 DE |
6081 | |
6082 | static struct type_unit_group * | |
ff39bb5e | 6083 | get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list) |
f4dc4d17 DE |
6084 | { |
6085 | struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats; | |
6086 | struct type_unit_group *tu_group; | |
6087 | void **slot; | |
6088 | unsigned int line_offset; | |
6089 | struct type_unit_group type_unit_group_for_lookup; | |
6090 | ||
6091 | if (dwarf2_per_objfile->type_unit_groups == NULL) | |
6092 | { | |
6093 | dwarf2_per_objfile->type_unit_groups = | |
6094 | allocate_type_unit_groups_table (); | |
6095 | } | |
6096 | ||
6097 | /* Do we need to create a new group, or can we use an existing one? */ | |
6098 | ||
6099 | if (stmt_list) | |
6100 | { | |
6101 | line_offset = DW_UNSND (stmt_list); | |
6102 | ++tu_stats->nr_symtab_sharers; | |
6103 | } | |
6104 | else | |
6105 | { | |
6106 | /* Ugh, no stmt_list. Rare, but we have to handle it. | |
6107 | We can do various things here like create one group per TU or | |
6108 | spread them over multiple groups to split up the expansion work. | |
6109 | To avoid worst case scenarios (too many groups or too large groups) | |
6110 | we, umm, group them in bunches. */ | |
6111 | line_offset = (NO_STMT_LIST_TYPE_UNIT_PSYMTAB | |
6112 | | (tu_stats->nr_stmt_less_type_units | |
6113 | / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE)); | |
6114 | ++tu_stats->nr_stmt_less_type_units; | |
6115 | } | |
6116 | ||
094b34ac | 6117 | type_unit_group_for_lookup.hash.dwo_unit = cu->dwo_unit; |
9c541725 | 6118 | type_unit_group_for_lookup.hash.line_sect_off = (sect_offset) line_offset; |
f4dc4d17 DE |
6119 | slot = htab_find_slot (dwarf2_per_objfile->type_unit_groups, |
6120 | &type_unit_group_for_lookup, INSERT); | |
6121 | if (*slot != NULL) | |
6122 | { | |
9a3c8263 | 6123 | tu_group = (struct type_unit_group *) *slot; |
f4dc4d17 DE |
6124 | gdb_assert (tu_group != NULL); |
6125 | } | |
6126 | else | |
6127 | { | |
9c541725 | 6128 | sect_offset line_offset_struct = (sect_offset) line_offset; |
094b34ac | 6129 | tu_group = create_type_unit_group (cu, line_offset_struct); |
f4dc4d17 DE |
6130 | *slot = tu_group; |
6131 | ++tu_stats->nr_symtabs; | |
6132 | } | |
6133 | ||
6134 | return tu_group; | |
6135 | } | |
0018ea6f DE |
6136 | \f |
6137 | /* Partial symbol tables. */ | |
6138 | ||
6139 | /* Create a psymtab named NAME and assign it to PER_CU. | |
6140 | ||
6141 | The caller must fill in the following details: | |
6142 | dirname, textlow, texthigh. */ | |
6143 | ||
6144 | static struct partial_symtab * | |
6145 | create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name) | |
6146 | { | |
6147 | struct objfile *objfile = per_cu->objfile; | |
6148 | struct partial_symtab *pst; | |
6149 | ||
18a94d75 | 6150 | pst = start_psymtab_common (objfile, name, 0, |
0018ea6f DE |
6151 | objfile->global_psymbols.next, |
6152 | objfile->static_psymbols.next); | |
6153 | ||
6154 | pst->psymtabs_addrmap_supported = 1; | |
6155 | ||
6156 | /* This is the glue that links PST into GDB's symbol API. */ | |
6157 | pst->read_symtab_private = per_cu; | |
6158 | pst->read_symtab = dwarf2_read_symtab; | |
6159 | per_cu->v.psymtab = pst; | |
6160 | ||
6161 | return pst; | |
6162 | } | |
6163 | ||
b93601f3 TT |
6164 | /* The DATA object passed to process_psymtab_comp_unit_reader has this |
6165 | type. */ | |
6166 | ||
6167 | struct process_psymtab_comp_unit_data | |
6168 | { | |
6169 | /* True if we are reading a DW_TAG_partial_unit. */ | |
6170 | ||
6171 | int want_partial_unit; | |
6172 | ||
6173 | /* The "pretend" language that is used if the CU doesn't declare a | |
6174 | language. */ | |
6175 | ||
6176 | enum language pretend_language; | |
6177 | }; | |
6178 | ||
0018ea6f DE |
6179 | /* die_reader_func for process_psymtab_comp_unit. */ |
6180 | ||
6181 | static void | |
6182 | process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, | |
d521ce57 | 6183 | const gdb_byte *info_ptr, |
0018ea6f DE |
6184 | struct die_info *comp_unit_die, |
6185 | int has_children, | |
6186 | void *data) | |
6187 | { | |
6188 | struct dwarf2_cu *cu = reader->cu; | |
6189 | struct objfile *objfile = cu->objfile; | |
3e29f34a | 6190 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
0018ea6f | 6191 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; |
0018ea6f DE |
6192 | CORE_ADDR baseaddr; |
6193 | CORE_ADDR best_lowpc = 0, best_highpc = 0; | |
6194 | struct partial_symtab *pst; | |
3a2b436a | 6195 | enum pc_bounds_kind cu_bounds_kind; |
0018ea6f | 6196 | const char *filename; |
9a3c8263 SM |
6197 | struct process_psymtab_comp_unit_data *info |
6198 | = (struct process_psymtab_comp_unit_data *) data; | |
0018ea6f | 6199 | |
b93601f3 | 6200 | if (comp_unit_die->tag == DW_TAG_partial_unit && !info->want_partial_unit) |
0018ea6f DE |
6201 | return; |
6202 | ||
6203 | gdb_assert (! per_cu->is_debug_types); | |
6204 | ||
b93601f3 | 6205 | prepare_one_comp_unit (cu, comp_unit_die, info->pretend_language); |
0018ea6f DE |
6206 | |
6207 | cu->list_in_scope = &file_symbols; | |
6208 | ||
6209 | /* Allocate a new partial symbol table structure. */ | |
7d45c7c3 KB |
6210 | filename = dwarf2_string_attr (comp_unit_die, DW_AT_name, cu); |
6211 | if (filename == NULL) | |
0018ea6f | 6212 | filename = ""; |
0018ea6f DE |
6213 | |
6214 | pst = create_partial_symtab (per_cu, filename); | |
6215 | ||
6216 | /* This must be done before calling dwarf2_build_include_psymtabs. */ | |
7d45c7c3 | 6217 | pst->dirname = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu); |
0018ea6f DE |
6218 | |
6219 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6220 | ||
6221 | dwarf2_find_base_address (comp_unit_die, cu); | |
6222 | ||
6223 | /* Possibly set the default values of LOWPC and HIGHPC from | |
6224 | `DW_AT_ranges'. */ | |
3a2b436a JK |
6225 | cu_bounds_kind = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
6226 | &best_highpc, cu, pst); | |
6227 | if (cu_bounds_kind == PC_BOUNDS_HIGH_LOW && best_lowpc < best_highpc) | |
0018ea6f DE |
6228 | /* Store the contiguous range if it is not empty; it can be empty for |
6229 | CUs with no code. */ | |
6230 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
3e29f34a MR |
6231 | gdbarch_adjust_dwarf2_addr (gdbarch, |
6232 | best_lowpc + baseaddr), | |
6233 | gdbarch_adjust_dwarf2_addr (gdbarch, | |
6234 | best_highpc + baseaddr) - 1, | |
6235 | pst); | |
0018ea6f DE |
6236 | |
6237 | /* Check if comp unit has_children. | |
6238 | If so, read the rest of the partial symbols from this comp unit. | |
6239 | If not, there's no more debug_info for this comp unit. */ | |
6240 | if (has_children) | |
6241 | { | |
6242 | struct partial_die_info *first_die; | |
6243 | CORE_ADDR lowpc, highpc; | |
6244 | ||
6245 | lowpc = ((CORE_ADDR) -1); | |
6246 | highpc = ((CORE_ADDR) 0); | |
6247 | ||
6248 | first_die = load_partial_dies (reader, info_ptr, 1); | |
6249 | ||
6250 | scan_partial_symbols (first_die, &lowpc, &highpc, | |
e385593e | 6251 | cu_bounds_kind <= PC_BOUNDS_INVALID, cu); |
0018ea6f DE |
6252 | |
6253 | /* If we didn't find a lowpc, set it to highpc to avoid | |
6254 | complaints from `maint check'. */ | |
6255 | if (lowpc == ((CORE_ADDR) -1)) | |
6256 | lowpc = highpc; | |
6257 | ||
6258 | /* If the compilation unit didn't have an explicit address range, | |
6259 | then use the information extracted from its child dies. */ | |
e385593e | 6260 | if (cu_bounds_kind <= PC_BOUNDS_INVALID) |
0018ea6f DE |
6261 | { |
6262 | best_lowpc = lowpc; | |
6263 | best_highpc = highpc; | |
6264 | } | |
6265 | } | |
3e29f34a MR |
6266 | pst->textlow = gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr); |
6267 | pst->texthigh = gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr); | |
0018ea6f | 6268 | |
8763cede | 6269 | end_psymtab_common (objfile, pst); |
0018ea6f DE |
6270 | |
6271 | if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs)) | |
6272 | { | |
6273 | int i; | |
6274 | int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); | |
6275 | struct dwarf2_per_cu_data *iter; | |
6276 | ||
6277 | /* Fill in 'dependencies' here; we fill in 'users' in a | |
6278 | post-pass. */ | |
6279 | pst->number_of_dependencies = len; | |
8d749320 SM |
6280 | pst->dependencies = |
6281 | XOBNEWVEC (&objfile->objfile_obstack, struct partial_symtab *, len); | |
0018ea6f DE |
6282 | for (i = 0; |
6283 | VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, | |
6284 | i, iter); | |
6285 | ++i) | |
6286 | pst->dependencies[i] = iter->v.psymtab; | |
6287 | ||
6288 | VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); | |
6289 | } | |
6290 | ||
6291 | /* Get the list of files included in the current compilation unit, | |
6292 | and build a psymtab for each of them. */ | |
6293 | dwarf2_build_include_psymtabs (cu, comp_unit_die, pst); | |
6294 | ||
b4f54984 | 6295 | if (dwarf_read_debug) |
0018ea6f DE |
6296 | { |
6297 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
6298 | ||
6299 | fprintf_unfiltered (gdb_stdlog, | |
6300 | "Psymtab for %s unit @0x%x: %s - %s" | |
6301 | ", %d global, %d static syms\n", | |
6302 | per_cu->is_debug_types ? "type" : "comp", | |
9c541725 | 6303 | to_underlying (per_cu->sect_off), |
0018ea6f DE |
6304 | paddress (gdbarch, pst->textlow), |
6305 | paddress (gdbarch, pst->texthigh), | |
6306 | pst->n_global_syms, pst->n_static_syms); | |
6307 | } | |
6308 | } | |
6309 | ||
6310 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
6311 | Process compilation unit THIS_CU for a psymtab. */ | |
6312 | ||
6313 | static void | |
6314 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, | |
b93601f3 TT |
6315 | int want_partial_unit, |
6316 | enum language pretend_language) | |
0018ea6f | 6317 | { |
b93601f3 TT |
6318 | struct process_psymtab_comp_unit_data info; |
6319 | ||
0018ea6f DE |
6320 | /* If this compilation unit was already read in, free the |
6321 | cached copy in order to read it in again. This is | |
6322 | necessary because we skipped some symbols when we first | |
6323 | read in the compilation unit (see load_partial_dies). | |
6324 | This problem could be avoided, but the benefit is unclear. */ | |
6325 | if (this_cu->cu != NULL) | |
6326 | free_one_cached_comp_unit (this_cu); | |
6327 | ||
6328 | gdb_assert (! this_cu->is_debug_types); | |
b93601f3 TT |
6329 | info.want_partial_unit = want_partial_unit; |
6330 | info.pretend_language = pretend_language; | |
0018ea6f DE |
6331 | init_cutu_and_read_dies (this_cu, NULL, 0, 0, |
6332 | process_psymtab_comp_unit_reader, | |
b93601f3 | 6333 | &info); |
0018ea6f DE |
6334 | |
6335 | /* Age out any secondary CUs. */ | |
6336 | age_cached_comp_units (); | |
6337 | } | |
f4dc4d17 DE |
6338 | |
6339 | /* Reader function for build_type_psymtabs. */ | |
6340 | ||
6341 | static void | |
6342 | build_type_psymtabs_reader (const struct die_reader_specs *reader, | |
d521ce57 | 6343 | const gdb_byte *info_ptr, |
f4dc4d17 DE |
6344 | struct die_info *type_unit_die, |
6345 | int has_children, | |
6346 | void *data) | |
6347 | { | |
6348 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
6349 | struct dwarf2_cu *cu = reader->cu; | |
6350 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; | |
0186c6a7 | 6351 | struct signatured_type *sig_type; |
f4dc4d17 DE |
6352 | struct type_unit_group *tu_group; |
6353 | struct attribute *attr; | |
6354 | struct partial_die_info *first_die; | |
6355 | CORE_ADDR lowpc, highpc; | |
6356 | struct partial_symtab *pst; | |
6357 | ||
6358 | gdb_assert (data == NULL); | |
0186c6a7 DE |
6359 | gdb_assert (per_cu->is_debug_types); |
6360 | sig_type = (struct signatured_type *) per_cu; | |
f4dc4d17 DE |
6361 | |
6362 | if (! has_children) | |
6363 | return; | |
6364 | ||
6365 | attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list); | |
094b34ac | 6366 | tu_group = get_type_unit_group (cu, attr); |
f4dc4d17 | 6367 | |
0186c6a7 | 6368 | VEC_safe_push (sig_type_ptr, tu_group->tus, sig_type); |
f4dc4d17 DE |
6369 | |
6370 | prepare_one_comp_unit (cu, type_unit_die, language_minimal); | |
6371 | cu->list_in_scope = &file_symbols; | |
6372 | pst = create_partial_symtab (per_cu, ""); | |
6373 | pst->anonymous = 1; | |
6374 | ||
6375 | first_die = load_partial_dies (reader, info_ptr, 1); | |
6376 | ||
6377 | lowpc = (CORE_ADDR) -1; | |
6378 | highpc = (CORE_ADDR) 0; | |
6379 | scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu); | |
6380 | ||
8763cede | 6381 | end_psymtab_common (objfile, pst); |
f4dc4d17 DE |
6382 | } |
6383 | ||
73051182 DE |
6384 | /* Struct used to sort TUs by their abbreviation table offset. */ |
6385 | ||
6386 | struct tu_abbrev_offset | |
6387 | { | |
6388 | struct signatured_type *sig_type; | |
6389 | sect_offset abbrev_offset; | |
6390 | }; | |
6391 | ||
6392 | /* Helper routine for build_type_psymtabs_1, passed to qsort. */ | |
6393 | ||
6394 | static int | |
6395 | sort_tu_by_abbrev_offset (const void *ap, const void *bp) | |
6396 | { | |
9a3c8263 SM |
6397 | const struct tu_abbrev_offset * const *a |
6398 | = (const struct tu_abbrev_offset * const*) ap; | |
6399 | const struct tu_abbrev_offset * const *b | |
6400 | = (const struct tu_abbrev_offset * const*) bp; | |
9c541725 PA |
6401 | sect_offset aoff = (*a)->abbrev_offset; |
6402 | sect_offset boff = (*b)->abbrev_offset; | |
73051182 DE |
6403 | |
6404 | return (aoff > boff) - (aoff < boff); | |
6405 | } | |
6406 | ||
6407 | /* Efficiently read all the type units. | |
6408 | This does the bulk of the work for build_type_psymtabs. | |
6409 | ||
6410 | The efficiency is because we sort TUs by the abbrev table they use and | |
6411 | only read each abbrev table once. In one program there are 200K TUs | |
6412 | sharing 8K abbrev tables. | |
6413 | ||
6414 | The main purpose of this function is to support building the | |
6415 | dwarf2_per_objfile->type_unit_groups table. | |
6416 | TUs typically share the DW_AT_stmt_list of the CU they came from, so we | |
6417 | can collapse the search space by grouping them by stmt_list. | |
6418 | The savings can be significant, in the same program from above the 200K TUs | |
6419 | share 8K stmt_list tables. | |
6420 | ||
6421 | FUNC is expected to call get_type_unit_group, which will create the | |
6422 | struct type_unit_group if necessary and add it to | |
6423 | dwarf2_per_objfile->type_unit_groups. */ | |
6424 | ||
6425 | static void | |
6426 | build_type_psymtabs_1 (void) | |
6427 | { | |
73051182 DE |
6428 | struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats; |
6429 | struct cleanup *cleanups; | |
6430 | struct abbrev_table *abbrev_table; | |
6431 | sect_offset abbrev_offset; | |
6432 | struct tu_abbrev_offset *sorted_by_abbrev; | |
73051182 DE |
6433 | int i; |
6434 | ||
6435 | /* It's up to the caller to not call us multiple times. */ | |
6436 | gdb_assert (dwarf2_per_objfile->type_unit_groups == NULL); | |
6437 | ||
6438 | if (dwarf2_per_objfile->n_type_units == 0) | |
6439 | return; | |
6440 | ||
6441 | /* TUs typically share abbrev tables, and there can be way more TUs than | |
6442 | abbrev tables. Sort by abbrev table to reduce the number of times we | |
6443 | read each abbrev table in. | |
6444 | Alternatives are to punt or to maintain a cache of abbrev tables. | |
6445 | This is simpler and efficient enough for now. | |
6446 | ||
6447 | Later we group TUs by their DW_AT_stmt_list value (as this defines the | |
6448 | symtab to use). Typically TUs with the same abbrev offset have the same | |
6449 | stmt_list value too so in practice this should work well. | |
6450 | ||
6451 | The basic algorithm here is: | |
6452 | ||
6453 | sort TUs by abbrev table | |
6454 | for each TU with same abbrev table: | |
6455 | read abbrev table if first user | |
6456 | read TU top level DIE | |
6457 | [IWBN if DWO skeletons had DW_AT_stmt_list] | |
6458 | call FUNC */ | |
6459 | ||
b4f54984 | 6460 | if (dwarf_read_debug) |
73051182 DE |
6461 | fprintf_unfiltered (gdb_stdlog, "Building type unit groups ...\n"); |
6462 | ||
6463 | /* Sort in a separate table to maintain the order of all_type_units | |
6464 | for .gdb_index: TU indices directly index all_type_units. */ | |
6465 | sorted_by_abbrev = XNEWVEC (struct tu_abbrev_offset, | |
6466 | dwarf2_per_objfile->n_type_units); | |
6467 | for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i) | |
6468 | { | |
6469 | struct signatured_type *sig_type = dwarf2_per_objfile->all_type_units[i]; | |
6470 | ||
6471 | sorted_by_abbrev[i].sig_type = sig_type; | |
6472 | sorted_by_abbrev[i].abbrev_offset = | |
6473 | read_abbrev_offset (sig_type->per_cu.section, | |
9c541725 | 6474 | sig_type->per_cu.sect_off); |
73051182 DE |
6475 | } |
6476 | cleanups = make_cleanup (xfree, sorted_by_abbrev); | |
6477 | qsort (sorted_by_abbrev, dwarf2_per_objfile->n_type_units, | |
6478 | sizeof (struct tu_abbrev_offset), sort_tu_by_abbrev_offset); | |
6479 | ||
9c541725 | 6480 | abbrev_offset = (sect_offset) ~(unsigned) 0; |
73051182 DE |
6481 | abbrev_table = NULL; |
6482 | make_cleanup (abbrev_table_free_cleanup, &abbrev_table); | |
6483 | ||
6484 | for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i) | |
6485 | { | |
6486 | const struct tu_abbrev_offset *tu = &sorted_by_abbrev[i]; | |
6487 | ||
6488 | /* Switch to the next abbrev table if necessary. */ | |
6489 | if (abbrev_table == NULL | |
9c541725 | 6490 | || tu->abbrev_offset != abbrev_offset) |
73051182 DE |
6491 | { |
6492 | if (abbrev_table != NULL) | |
6493 | { | |
6494 | abbrev_table_free (abbrev_table); | |
6495 | /* Reset to NULL in case abbrev_table_read_table throws | |
6496 | an error: abbrev_table_free_cleanup will get called. */ | |
6497 | abbrev_table = NULL; | |
6498 | } | |
6499 | abbrev_offset = tu->abbrev_offset; | |
6500 | abbrev_table = | |
6501 | abbrev_table_read_table (&dwarf2_per_objfile->abbrev, | |
6502 | abbrev_offset); | |
6503 | ++tu_stats->nr_uniq_abbrev_tables; | |
6504 | } | |
6505 | ||
6506 | init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table, 0, 0, | |
6507 | build_type_psymtabs_reader, NULL); | |
6508 | } | |
6509 | ||
73051182 | 6510 | do_cleanups (cleanups); |
6aa5f3a6 | 6511 | } |
73051182 | 6512 | |
6aa5f3a6 DE |
6513 | /* Print collected type unit statistics. */ |
6514 | ||
6515 | static void | |
6516 | print_tu_stats (void) | |
6517 | { | |
6518 | struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats; | |
6519 | ||
6520 | fprintf_unfiltered (gdb_stdlog, "Type unit statistics:\n"); | |
6521 | fprintf_unfiltered (gdb_stdlog, " %d TUs\n", | |
6522 | dwarf2_per_objfile->n_type_units); | |
6523 | fprintf_unfiltered (gdb_stdlog, " %d uniq abbrev tables\n", | |
6524 | tu_stats->nr_uniq_abbrev_tables); | |
6525 | fprintf_unfiltered (gdb_stdlog, " %d symtabs from stmt_list entries\n", | |
6526 | tu_stats->nr_symtabs); | |
6527 | fprintf_unfiltered (gdb_stdlog, " %d symtab sharers\n", | |
6528 | tu_stats->nr_symtab_sharers); | |
6529 | fprintf_unfiltered (gdb_stdlog, " %d type units without a stmt_list\n", | |
6530 | tu_stats->nr_stmt_less_type_units); | |
6531 | fprintf_unfiltered (gdb_stdlog, " %d all_type_units reallocs\n", | |
6532 | tu_stats->nr_all_type_units_reallocs); | |
73051182 DE |
6533 | } |
6534 | ||
f4dc4d17 DE |
6535 | /* Traversal function for build_type_psymtabs. */ |
6536 | ||
6537 | static int | |
6538 | build_type_psymtab_dependencies (void **slot, void *info) | |
6539 | { | |
6540 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
6541 | struct type_unit_group *tu_group = (struct type_unit_group *) *slot; | |
094b34ac | 6542 | struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu; |
f4dc4d17 | 6543 | struct partial_symtab *pst = per_cu->v.psymtab; |
0186c6a7 DE |
6544 | int len = VEC_length (sig_type_ptr, tu_group->tus); |
6545 | struct signatured_type *iter; | |
f4dc4d17 DE |
6546 | int i; |
6547 | ||
6548 | gdb_assert (len > 0); | |
0186c6a7 | 6549 | gdb_assert (IS_TYPE_UNIT_GROUP (per_cu)); |
f4dc4d17 DE |
6550 | |
6551 | pst->number_of_dependencies = len; | |
8d749320 SM |
6552 | pst->dependencies = |
6553 | XOBNEWVEC (&objfile->objfile_obstack, struct partial_symtab *, len); | |
f4dc4d17 | 6554 | for (i = 0; |
0186c6a7 | 6555 | VEC_iterate (sig_type_ptr, tu_group->tus, i, iter); |
f4dc4d17 DE |
6556 | ++i) |
6557 | { | |
0186c6a7 DE |
6558 | gdb_assert (iter->per_cu.is_debug_types); |
6559 | pst->dependencies[i] = iter->per_cu.v.psymtab; | |
796a7ff8 | 6560 | iter->type_unit_group = tu_group; |
f4dc4d17 DE |
6561 | } |
6562 | ||
0186c6a7 | 6563 | VEC_free (sig_type_ptr, tu_group->tus); |
348e048f DE |
6564 | |
6565 | return 1; | |
6566 | } | |
6567 | ||
6568 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
6569 | Build partial symbol tables for the .debug_types comp-units. */ | |
6570 | ||
6571 | static void | |
6572 | build_type_psymtabs (struct objfile *objfile) | |
6573 | { | |
0e50663e | 6574 | if (! create_all_type_units (objfile)) |
348e048f DE |
6575 | return; |
6576 | ||
73051182 | 6577 | build_type_psymtabs_1 (); |
6aa5f3a6 | 6578 | } |
f4dc4d17 | 6579 | |
6aa5f3a6 DE |
6580 | /* Traversal function for process_skeletonless_type_unit. |
6581 | Read a TU in a DWO file and build partial symbols for it. */ | |
6582 | ||
6583 | static int | |
6584 | process_skeletonless_type_unit (void **slot, void *info) | |
6585 | { | |
6586 | struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot; | |
9a3c8263 | 6587 | struct objfile *objfile = (struct objfile *) info; |
6aa5f3a6 DE |
6588 | struct signatured_type find_entry, *entry; |
6589 | ||
6590 | /* If this TU doesn't exist in the global table, add it and read it in. */ | |
6591 | ||
6592 | if (dwarf2_per_objfile->signatured_types == NULL) | |
6593 | { | |
6594 | dwarf2_per_objfile->signatured_types | |
6595 | = allocate_signatured_type_table (objfile); | |
6596 | } | |
6597 | ||
6598 | find_entry.signature = dwo_unit->signature; | |
6599 | slot = htab_find_slot (dwarf2_per_objfile->signatured_types, &find_entry, | |
6600 | INSERT); | |
6601 | /* If we've already seen this type there's nothing to do. What's happening | |
6602 | is we're doing our own version of comdat-folding here. */ | |
6603 | if (*slot != NULL) | |
6604 | return 1; | |
6605 | ||
6606 | /* This does the job that create_all_type_units would have done for | |
6607 | this TU. */ | |
6608 | entry = add_type_unit (dwo_unit->signature, slot); | |
6609 | fill_in_sig_entry_from_dwo_entry (objfile, entry, dwo_unit); | |
6610 | *slot = entry; | |
6611 | ||
6612 | /* This does the job that build_type_psymtabs_1 would have done. */ | |
6613 | init_cutu_and_read_dies (&entry->per_cu, NULL, 0, 0, | |
6614 | build_type_psymtabs_reader, NULL); | |
6615 | ||
6616 | return 1; | |
6617 | } | |
6618 | ||
6619 | /* Traversal function for process_skeletonless_type_units. */ | |
6620 | ||
6621 | static int | |
6622 | process_dwo_file_for_skeletonless_type_units (void **slot, void *info) | |
6623 | { | |
6624 | struct dwo_file *dwo_file = (struct dwo_file *) *slot; | |
6625 | ||
6626 | if (dwo_file->tus != NULL) | |
6627 | { | |
6628 | htab_traverse_noresize (dwo_file->tus, | |
6629 | process_skeletonless_type_unit, info); | |
6630 | } | |
6631 | ||
6632 | return 1; | |
6633 | } | |
6634 | ||
6635 | /* Scan all TUs of DWO files, verifying we've processed them. | |
6636 | This is needed in case a TU was emitted without its skeleton. | |
6637 | Note: This can't be done until we know what all the DWO files are. */ | |
6638 | ||
6639 | static void | |
6640 | process_skeletonless_type_units (struct objfile *objfile) | |
6641 | { | |
6642 | /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */ | |
6643 | if (get_dwp_file () == NULL | |
6644 | && dwarf2_per_objfile->dwo_files != NULL) | |
6645 | { | |
6646 | htab_traverse_noresize (dwarf2_per_objfile->dwo_files, | |
6647 | process_dwo_file_for_skeletonless_type_units, | |
6648 | objfile); | |
6649 | } | |
348e048f DE |
6650 | } |
6651 | ||
60606b2c TT |
6652 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
6653 | ||
6654 | static void | |
6655 | psymtabs_addrmap_cleanup (void *o) | |
6656 | { | |
9a3c8263 | 6657 | struct objfile *objfile = (struct objfile *) o; |
ec61707d | 6658 | |
60606b2c TT |
6659 | objfile->psymtabs_addrmap = NULL; |
6660 | } | |
6661 | ||
95554aad TT |
6662 | /* Compute the 'user' field for each psymtab in OBJFILE. */ |
6663 | ||
6664 | static void | |
6665 | set_partial_user (struct objfile *objfile) | |
6666 | { | |
6667 | int i; | |
6668 | ||
6669 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
6670 | { | |
8832e7e3 | 6671 | struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i); |
95554aad TT |
6672 | struct partial_symtab *pst = per_cu->v.psymtab; |
6673 | int j; | |
6674 | ||
36586728 TT |
6675 | if (pst == NULL) |
6676 | continue; | |
6677 | ||
95554aad TT |
6678 | for (j = 0; j < pst->number_of_dependencies; ++j) |
6679 | { | |
6680 | /* Set the 'user' field only if it is not already set. */ | |
6681 | if (pst->dependencies[j]->user == NULL) | |
6682 | pst->dependencies[j]->user = pst; | |
6683 | } | |
6684 | } | |
6685 | } | |
6686 | ||
93311388 DE |
6687 | /* Build the partial symbol table by doing a quick pass through the |
6688 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 6689 | |
93311388 | 6690 | static void |
c67a9c90 | 6691 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 6692 | { |
60606b2c | 6693 | struct cleanup *back_to, *addrmap_cleanup; |
21b2bd31 | 6694 | int i; |
93311388 | 6695 | |
b4f54984 | 6696 | if (dwarf_read_debug) |
45cfd468 DE |
6697 | { |
6698 | fprintf_unfiltered (gdb_stdlog, "Building psymtabs of objfile %s ...\n", | |
4262abfb | 6699 | objfile_name (objfile)); |
45cfd468 DE |
6700 | } |
6701 | ||
98bfdba5 PA |
6702 | dwarf2_per_objfile->reading_partial_symbols = 1; |
6703 | ||
be391dca | 6704 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
91c24f0a | 6705 | |
93311388 DE |
6706 | /* Any cached compilation units will be linked by the per-objfile |
6707 | read_in_chain. Make sure to free them when we're done. */ | |
6708 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 6709 | |
348e048f DE |
6710 | build_type_psymtabs (objfile); |
6711 | ||
93311388 | 6712 | create_all_comp_units (objfile); |
c906108c | 6713 | |
60606b2c TT |
6714 | /* Create a temporary address map on a temporary obstack. We later |
6715 | copy this to the final obstack. */ | |
8268c778 | 6716 | auto_obstack temp_obstack; |
60606b2c TT |
6717 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); |
6718 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 6719 | |
21b2bd31 | 6720 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
93311388 | 6721 | { |
8832e7e3 | 6722 | struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i); |
aaa75496 | 6723 | |
b93601f3 | 6724 | process_psymtab_comp_unit (per_cu, 0, language_minimal); |
c906108c | 6725 | } |
ff013f42 | 6726 | |
6aa5f3a6 DE |
6727 | /* This has to wait until we read the CUs, we need the list of DWOs. */ |
6728 | process_skeletonless_type_units (objfile); | |
6729 | ||
6730 | /* Now that all TUs have been processed we can fill in the dependencies. */ | |
6731 | if (dwarf2_per_objfile->type_unit_groups != NULL) | |
6732 | { | |
6733 | htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups, | |
6734 | build_type_psymtab_dependencies, NULL); | |
6735 | } | |
6736 | ||
b4f54984 | 6737 | if (dwarf_read_debug) |
6aa5f3a6 DE |
6738 | print_tu_stats (); |
6739 | ||
95554aad TT |
6740 | set_partial_user (objfile); |
6741 | ||
ff013f42 JK |
6742 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, |
6743 | &objfile->objfile_obstack); | |
60606b2c | 6744 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 6745 | |
ae038cb0 | 6746 | do_cleanups (back_to); |
45cfd468 | 6747 | |
b4f54984 | 6748 | if (dwarf_read_debug) |
45cfd468 | 6749 | fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n", |
4262abfb | 6750 | objfile_name (objfile)); |
ae038cb0 DJ |
6751 | } |
6752 | ||
3019eac3 | 6753 | /* die_reader_func for load_partial_comp_unit. */ |
ae038cb0 DJ |
6754 | |
6755 | static void | |
dee91e82 | 6756 | load_partial_comp_unit_reader (const struct die_reader_specs *reader, |
d521ce57 | 6757 | const gdb_byte *info_ptr, |
dee91e82 DE |
6758 | struct die_info *comp_unit_die, |
6759 | int has_children, | |
6760 | void *data) | |
ae038cb0 | 6761 | { |
dee91e82 | 6762 | struct dwarf2_cu *cu = reader->cu; |
ae038cb0 | 6763 | |
95554aad | 6764 | prepare_one_comp_unit (cu, comp_unit_die, language_minimal); |
ae038cb0 | 6765 | |
ae038cb0 DJ |
6766 | /* Check if comp unit has_children. |
6767 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 6768 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 6769 | if (has_children) |
dee91e82 DE |
6770 | load_partial_dies (reader, info_ptr, 0); |
6771 | } | |
98bfdba5 | 6772 | |
dee91e82 DE |
6773 | /* Load the partial DIEs for a secondary CU into memory. |
6774 | This is also used when rereading a primary CU with load_all_dies. */ | |
c5b7e1cb | 6775 | |
dee91e82 DE |
6776 | static void |
6777 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) | |
6778 | { | |
f4dc4d17 DE |
6779 | init_cutu_and_read_dies (this_cu, NULL, 1, 1, |
6780 | load_partial_comp_unit_reader, NULL); | |
ae038cb0 DJ |
6781 | } |
6782 | ||
ae038cb0 | 6783 | static void |
36586728 TT |
6784 | read_comp_units_from_section (struct objfile *objfile, |
6785 | struct dwarf2_section_info *section, | |
6786 | unsigned int is_dwz, | |
6787 | int *n_allocated, | |
6788 | int *n_comp_units, | |
6789 | struct dwarf2_per_cu_data ***all_comp_units) | |
ae038cb0 | 6790 | { |
d521ce57 | 6791 | const gdb_byte *info_ptr; |
a32a8923 | 6792 | bfd *abfd = get_section_bfd_owner (section); |
be391dca | 6793 | |
b4f54984 | 6794 | if (dwarf_read_debug) |
bf6af496 | 6795 | fprintf_unfiltered (gdb_stdlog, "Reading %s for %s\n", |
a32a8923 DE |
6796 | get_section_name (section), |
6797 | get_section_file_name (section)); | |
bf6af496 | 6798 | |
36586728 | 6799 | dwarf2_read_section (objfile, section); |
ae038cb0 | 6800 | |
36586728 | 6801 | info_ptr = section->buffer; |
6e70227d | 6802 | |
36586728 | 6803 | while (info_ptr < section->buffer + section->size) |
ae038cb0 | 6804 | { |
c764a876 | 6805 | unsigned int length, initial_length_size; |
ae038cb0 | 6806 | struct dwarf2_per_cu_data *this_cu; |
ae038cb0 | 6807 | |
9c541725 | 6808 | sect_offset sect_off = (sect_offset) (info_ptr - section->buffer); |
ae038cb0 DJ |
6809 | |
6810 | /* Read just enough information to find out where the next | |
6811 | compilation unit is. */ | |
36586728 | 6812 | length = read_initial_length (abfd, info_ptr, &initial_length_size); |
ae038cb0 DJ |
6813 | |
6814 | /* Save the compilation unit for later lookup. */ | |
8d749320 | 6815 | this_cu = XOBNEW (&objfile->objfile_obstack, struct dwarf2_per_cu_data); |
ae038cb0 | 6816 | memset (this_cu, 0, sizeof (*this_cu)); |
9c541725 | 6817 | this_cu->sect_off = sect_off; |
c764a876 | 6818 | this_cu->length = length + initial_length_size; |
36586728 | 6819 | this_cu->is_dwz = is_dwz; |
9291a0cd | 6820 | this_cu->objfile = objfile; |
8a0459fd | 6821 | this_cu->section = section; |
ae038cb0 | 6822 | |
36586728 | 6823 | if (*n_comp_units == *n_allocated) |
ae038cb0 | 6824 | { |
36586728 | 6825 | *n_allocated *= 2; |
224c3ddb SM |
6826 | *all_comp_units = XRESIZEVEC (struct dwarf2_per_cu_data *, |
6827 | *all_comp_units, *n_allocated); | |
ae038cb0 | 6828 | } |
36586728 TT |
6829 | (*all_comp_units)[*n_comp_units] = this_cu; |
6830 | ++*n_comp_units; | |
ae038cb0 DJ |
6831 | |
6832 | info_ptr = info_ptr + this_cu->length; | |
6833 | } | |
36586728 TT |
6834 | } |
6835 | ||
6836 | /* Create a list of all compilation units in OBJFILE. | |
6837 | This is only done for -readnow and building partial symtabs. */ | |
6838 | ||
6839 | static void | |
6840 | create_all_comp_units (struct objfile *objfile) | |
6841 | { | |
6842 | int n_allocated; | |
6843 | int n_comp_units; | |
6844 | struct dwarf2_per_cu_data **all_comp_units; | |
4db1a1dc | 6845 | struct dwz_file *dwz; |
36586728 TT |
6846 | |
6847 | n_comp_units = 0; | |
6848 | n_allocated = 10; | |
8d749320 | 6849 | all_comp_units = XNEWVEC (struct dwarf2_per_cu_data *, n_allocated); |
36586728 TT |
6850 | |
6851 | read_comp_units_from_section (objfile, &dwarf2_per_objfile->info, 0, | |
6852 | &n_allocated, &n_comp_units, &all_comp_units); | |
6853 | ||
4db1a1dc TT |
6854 | dwz = dwarf2_get_dwz_file (); |
6855 | if (dwz != NULL) | |
6856 | read_comp_units_from_section (objfile, &dwz->info, 1, | |
6857 | &n_allocated, &n_comp_units, | |
6858 | &all_comp_units); | |
ae038cb0 | 6859 | |
8d749320 SM |
6860 | dwarf2_per_objfile->all_comp_units = XOBNEWVEC (&objfile->objfile_obstack, |
6861 | struct dwarf2_per_cu_data *, | |
6862 | n_comp_units); | |
ae038cb0 DJ |
6863 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, |
6864 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
6865 | xfree (all_comp_units); | |
6866 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
6867 | } |
6868 | ||
5734ee8b | 6869 | /* Process all loaded DIEs for compilation unit CU, starting at |
cdc07690 | 6870 | FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation |
5734ee8b | 6871 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or |
cdc07690 YQ |
6872 | DW_AT_ranges). See the comments of add_partial_subprogram on how |
6873 | SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */ | |
c906108c | 6874 | |
72bf9492 DJ |
6875 | static void |
6876 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
cdc07690 YQ |
6877 | CORE_ADDR *highpc, int set_addrmap, |
6878 | struct dwarf2_cu *cu) | |
c906108c | 6879 | { |
72bf9492 | 6880 | struct partial_die_info *pdi; |
c906108c | 6881 | |
91c24f0a DC |
6882 | /* Now, march along the PDI's, descending into ones which have |
6883 | interesting children but skipping the children of the other ones, | |
6884 | until we reach the end of the compilation unit. */ | |
c906108c | 6885 | |
72bf9492 | 6886 | pdi = first_die; |
91c24f0a | 6887 | |
72bf9492 DJ |
6888 | while (pdi != NULL) |
6889 | { | |
6890 | fixup_partial_die (pdi, cu); | |
c906108c | 6891 | |
f55ee35c | 6892 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
6893 | children, so we need to look at them. Ditto for anonymous |
6894 | enums. */ | |
933c6fe4 | 6895 | |
72bf9492 | 6896 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
95554aad TT |
6897 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type |
6898 | || pdi->tag == DW_TAG_imported_unit) | |
c906108c | 6899 | { |
72bf9492 | 6900 | switch (pdi->tag) |
c906108c SS |
6901 | { |
6902 | case DW_TAG_subprogram: | |
cdc07690 | 6903 | add_partial_subprogram (pdi, lowpc, highpc, set_addrmap, cu); |
c906108c | 6904 | break; |
72929c62 | 6905 | case DW_TAG_constant: |
c906108c SS |
6906 | case DW_TAG_variable: |
6907 | case DW_TAG_typedef: | |
91c24f0a | 6908 | case DW_TAG_union_type: |
72bf9492 | 6909 | if (!pdi->is_declaration) |
63d06c5c | 6910 | { |
72bf9492 | 6911 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
6912 | } |
6913 | break; | |
c906108c | 6914 | case DW_TAG_class_type: |
680b30c7 | 6915 | case DW_TAG_interface_type: |
c906108c | 6916 | case DW_TAG_structure_type: |
72bf9492 | 6917 | if (!pdi->is_declaration) |
c906108c | 6918 | { |
72bf9492 | 6919 | add_partial_symbol (pdi, cu); |
c906108c | 6920 | } |
e98c9e7c TT |
6921 | if (cu->language == language_rust && pdi->has_children) |
6922 | scan_partial_symbols (pdi->die_child, lowpc, highpc, | |
6923 | set_addrmap, cu); | |
c906108c | 6924 | break; |
91c24f0a | 6925 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
6926 | if (!pdi->is_declaration) |
6927 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
6928 | break; |
6929 | case DW_TAG_base_type: | |
a02abb62 | 6930 | case DW_TAG_subrange_type: |
c906108c | 6931 | /* File scope base type definitions are added to the partial |
c5aa993b | 6932 | symbol table. */ |
72bf9492 | 6933 | add_partial_symbol (pdi, cu); |
c906108c | 6934 | break; |
d9fa45fe | 6935 | case DW_TAG_namespace: |
cdc07690 | 6936 | add_partial_namespace (pdi, lowpc, highpc, set_addrmap, cu); |
91c24f0a | 6937 | break; |
5d7cb8df | 6938 | case DW_TAG_module: |
cdc07690 | 6939 | add_partial_module (pdi, lowpc, highpc, set_addrmap, cu); |
5d7cb8df | 6940 | break; |
95554aad TT |
6941 | case DW_TAG_imported_unit: |
6942 | { | |
6943 | struct dwarf2_per_cu_data *per_cu; | |
6944 | ||
f4dc4d17 DE |
6945 | /* For now we don't handle imported units in type units. */ |
6946 | if (cu->per_cu->is_debug_types) | |
6947 | { | |
6948 | error (_("Dwarf Error: DW_TAG_imported_unit is not" | |
6949 | " supported in type units [in module %s]"), | |
4262abfb | 6950 | objfile_name (cu->objfile)); |
f4dc4d17 DE |
6951 | } |
6952 | ||
9c541725 | 6953 | per_cu = dwarf2_find_containing_comp_unit (pdi->d.sect_off, |
36586728 | 6954 | pdi->is_dwz, |
95554aad TT |
6955 | cu->objfile); |
6956 | ||
6957 | /* Go read the partial unit, if needed. */ | |
6958 | if (per_cu->v.psymtab == NULL) | |
b93601f3 | 6959 | process_psymtab_comp_unit (per_cu, 1, cu->language); |
95554aad | 6960 | |
f4dc4d17 | 6961 | VEC_safe_push (dwarf2_per_cu_ptr, |
796a7ff8 | 6962 | cu->per_cu->imported_symtabs, per_cu); |
95554aad TT |
6963 | } |
6964 | break; | |
74921315 KS |
6965 | case DW_TAG_imported_declaration: |
6966 | add_partial_symbol (pdi, cu); | |
6967 | break; | |
c906108c SS |
6968 | default: |
6969 | break; | |
6970 | } | |
6971 | } | |
6972 | ||
72bf9492 DJ |
6973 | /* If the die has a sibling, skip to the sibling. */ |
6974 | ||
6975 | pdi = pdi->die_sibling; | |
6976 | } | |
6977 | } | |
6978 | ||
6979 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 6980 | |
72bf9492 | 6981 | Normally, this is simple. For C++, the parent DIE's fully scoped |
9c37b5ae | 6982 | name is concatenated with "::" and the partial DIE's name. |
72bf9492 DJ |
6983 | Enumerators are an exception; they use the scope of their parent |
6984 | enumeration type, i.e. the name of the enumeration type is not | |
6985 | prepended to the enumerator. | |
91c24f0a | 6986 | |
72bf9492 DJ |
6987 | There are two complexities. One is DW_AT_specification; in this |
6988 | case "parent" means the parent of the target of the specification, | |
6989 | instead of the direct parent of the DIE. The other is compilers | |
6990 | which do not emit DW_TAG_namespace; in this case we try to guess | |
6991 | the fully qualified name of structure types from their members' | |
6992 | linkage names. This must be done using the DIE's children rather | |
6993 | than the children of any DW_AT_specification target. We only need | |
6994 | to do this for structures at the top level, i.e. if the target of | |
6995 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
6996 | have a parent. */ | |
6997 | ||
6998 | /* Compute the scope prefix associated with PDI's parent, in | |
6999 | compilation unit CU. The result will be allocated on CU's | |
7000 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
7001 | field. NULL is returned if no prefix is necessary. */ | |
15d034d0 | 7002 | static const char * |
72bf9492 DJ |
7003 | partial_die_parent_scope (struct partial_die_info *pdi, |
7004 | struct dwarf2_cu *cu) | |
7005 | { | |
15d034d0 | 7006 | const char *grandparent_scope; |
72bf9492 | 7007 | struct partial_die_info *parent, *real_pdi; |
91c24f0a | 7008 | |
72bf9492 DJ |
7009 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
7010 | then this means the parent of the specification DIE. */ | |
7011 | ||
7012 | real_pdi = pdi; | |
72bf9492 | 7013 | while (real_pdi->has_specification) |
36586728 TT |
7014 | real_pdi = find_partial_die (real_pdi->spec_offset, |
7015 | real_pdi->spec_is_dwz, cu); | |
72bf9492 DJ |
7016 | |
7017 | parent = real_pdi->die_parent; | |
7018 | if (parent == NULL) | |
7019 | return NULL; | |
7020 | ||
7021 | if (parent->scope_set) | |
7022 | return parent->scope; | |
7023 | ||
7024 | fixup_partial_die (parent, cu); | |
7025 | ||
10b3939b | 7026 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 7027 | |
acebe513 UW |
7028 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
7029 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
7030 | Work around this problem here. */ | |
7031 | if (cu->language == language_cplus | |
6e70227d | 7032 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
7033 | && strcmp (parent->name, "::") == 0 |
7034 | && grandparent_scope == NULL) | |
7035 | { | |
7036 | parent->scope = NULL; | |
7037 | parent->scope_set = 1; | |
7038 | return NULL; | |
7039 | } | |
7040 | ||
9c6c53f7 SA |
7041 | if (pdi->tag == DW_TAG_enumerator) |
7042 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
7043 | parent->scope = grandparent_scope; | |
7044 | else if (parent->tag == DW_TAG_namespace | |
f55ee35c | 7045 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
7046 | || parent->tag == DW_TAG_structure_type |
7047 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 7048 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
7049 | || parent->tag == DW_TAG_union_type |
7050 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
7051 | { |
7052 | if (grandparent_scope == NULL) | |
7053 | parent->scope = parent->name; | |
7054 | else | |
3e43a32a MS |
7055 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
7056 | grandparent_scope, | |
f55ee35c | 7057 | parent->name, 0, cu); |
72bf9492 | 7058 | } |
72bf9492 DJ |
7059 | else |
7060 | { | |
7061 | /* FIXME drow/2004-04-01: What should we be doing with | |
7062 | function-local names? For partial symbols, we should probably be | |
7063 | ignoring them. */ | |
7064 | complaint (&symfile_complaints, | |
e2e0b3e5 | 7065 | _("unhandled containing DIE tag %d for DIE at %d"), |
9c541725 | 7066 | parent->tag, to_underlying (pdi->sect_off)); |
72bf9492 | 7067 | parent->scope = grandparent_scope; |
c906108c SS |
7068 | } |
7069 | ||
72bf9492 DJ |
7070 | parent->scope_set = 1; |
7071 | return parent->scope; | |
7072 | } | |
7073 | ||
7074 | /* Return the fully scoped name associated with PDI, from compilation unit | |
7075 | CU. The result will be allocated with malloc. */ | |
4568ecf9 | 7076 | |
72bf9492 DJ |
7077 | static char * |
7078 | partial_die_full_name (struct partial_die_info *pdi, | |
7079 | struct dwarf2_cu *cu) | |
7080 | { | |
15d034d0 | 7081 | const char *parent_scope; |
72bf9492 | 7082 | |
98bfdba5 PA |
7083 | /* If this is a template instantiation, we can not work out the |
7084 | template arguments from partial DIEs. So, unfortunately, we have | |
7085 | to go through the full DIEs. At least any work we do building | |
7086 | types here will be reused if full symbols are loaded later. */ | |
7087 | if (pdi->has_template_arguments) | |
7088 | { | |
7089 | fixup_partial_die (pdi, cu); | |
7090 | ||
7091 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
7092 | { | |
7093 | struct die_info *die; | |
7094 | struct attribute attr; | |
7095 | struct dwarf2_cu *ref_cu = cu; | |
7096 | ||
b64f50a1 | 7097 | /* DW_FORM_ref_addr is using section offset. */ |
b4069958 | 7098 | attr.name = (enum dwarf_attribute) 0; |
98bfdba5 | 7099 | attr.form = DW_FORM_ref_addr; |
9c541725 | 7100 | attr.u.unsnd = to_underlying (pdi->sect_off); |
98bfdba5 PA |
7101 | die = follow_die_ref (NULL, &attr, &ref_cu); |
7102 | ||
7103 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
7104 | } | |
7105 | } | |
7106 | ||
72bf9492 DJ |
7107 | parent_scope = partial_die_parent_scope (pdi, cu); |
7108 | if (parent_scope == NULL) | |
7109 | return NULL; | |
7110 | else | |
f55ee35c | 7111 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
7112 | } |
7113 | ||
7114 | static void | |
72bf9492 | 7115 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 7116 | { |
e7c27a73 | 7117 | struct objfile *objfile = cu->objfile; |
3e29f34a | 7118 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c | 7119 | CORE_ADDR addr = 0; |
15d034d0 | 7120 | const char *actual_name = NULL; |
e142c38c | 7121 | CORE_ADDR baseaddr; |
15d034d0 | 7122 | char *built_actual_name; |
e142c38c DJ |
7123 | |
7124 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7125 | |
15d034d0 TT |
7126 | built_actual_name = partial_die_full_name (pdi, cu); |
7127 | if (built_actual_name != NULL) | |
7128 | actual_name = built_actual_name; | |
63d06c5c | 7129 | |
72bf9492 DJ |
7130 | if (actual_name == NULL) |
7131 | actual_name = pdi->name; | |
7132 | ||
c906108c SS |
7133 | switch (pdi->tag) |
7134 | { | |
7135 | case DW_TAG_subprogram: | |
3e29f34a | 7136 | addr = gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr); |
2cfa0c8d | 7137 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 7138 | { |
2cfa0c8d JB |
7139 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
7140 | of the global scope. But in Ada, we want to be able to access | |
7141 | nested procedures globally. So all Ada subprograms are stored | |
7142 | in the global scope. */ | |
f47fb265 | 7143 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 7144 | built_actual_name != NULL, |
f47fb265 MS |
7145 | VAR_DOMAIN, LOC_BLOCK, |
7146 | &objfile->global_psymbols, | |
1762568f | 7147 | addr, cu->language, objfile); |
c906108c SS |
7148 | } |
7149 | else | |
7150 | { | |
f47fb265 | 7151 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 7152 | built_actual_name != NULL, |
f47fb265 MS |
7153 | VAR_DOMAIN, LOC_BLOCK, |
7154 | &objfile->static_psymbols, | |
1762568f | 7155 | addr, cu->language, objfile); |
c906108c | 7156 | } |
0c1b455e TT |
7157 | |
7158 | if (pdi->main_subprogram && actual_name != NULL) | |
7159 | set_objfile_main_name (objfile, actual_name, cu->language); | |
c906108c | 7160 | break; |
72929c62 JB |
7161 | case DW_TAG_constant: |
7162 | { | |
7163 | struct psymbol_allocation_list *list; | |
7164 | ||
7165 | if (pdi->is_external) | |
7166 | list = &objfile->global_psymbols; | |
7167 | else | |
7168 | list = &objfile->static_psymbols; | |
f47fb265 | 7169 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 7170 | built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC, |
1762568f | 7171 | list, 0, cu->language, objfile); |
72929c62 JB |
7172 | } |
7173 | break; | |
c906108c | 7174 | case DW_TAG_variable: |
95554aad TT |
7175 | if (pdi->d.locdesc) |
7176 | addr = decode_locdesc (pdi->d.locdesc, cu); | |
caac4577 | 7177 | |
95554aad | 7178 | if (pdi->d.locdesc |
caac4577 JG |
7179 | && addr == 0 |
7180 | && !dwarf2_per_objfile->has_section_at_zero) | |
7181 | { | |
7182 | /* A global or static variable may also have been stripped | |
7183 | out by the linker if unused, in which case its address | |
7184 | will be nullified; do not add such variables into partial | |
7185 | symbol table then. */ | |
7186 | } | |
7187 | else if (pdi->is_external) | |
c906108c SS |
7188 | { |
7189 | /* Global Variable. | |
7190 | Don't enter into the minimal symbol tables as there is | |
7191 | a minimal symbol table entry from the ELF symbols already. | |
7192 | Enter into partial symbol table if it has a location | |
7193 | descriptor or a type. | |
7194 | If the location descriptor is missing, new_symbol will create | |
7195 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
7196 | be determined from the minimal symbol table whenever the variable | |
7197 | is referenced. | |
7198 | The address for the partial symbol table entry is not | |
7199 | used by GDB, but it comes in handy for debugging partial symbol | |
7200 | table building. */ | |
7201 | ||
95554aad | 7202 | if (pdi->d.locdesc || pdi->has_type) |
f47fb265 | 7203 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 7204 | built_actual_name != NULL, |
f47fb265 MS |
7205 | VAR_DOMAIN, LOC_STATIC, |
7206 | &objfile->global_psymbols, | |
1762568f | 7207 | addr + baseaddr, |
f47fb265 | 7208 | cu->language, objfile); |
c906108c SS |
7209 | } |
7210 | else | |
7211 | { | |
ff908ebf AW |
7212 | int has_loc = pdi->d.locdesc != NULL; |
7213 | ||
7214 | /* Static Variable. Skip symbols whose value we cannot know (those | |
7215 | without location descriptors or constant values). */ | |
7216 | if (!has_loc && !pdi->has_const_value) | |
decbce07 | 7217 | { |
15d034d0 | 7218 | xfree (built_actual_name); |
decbce07 MS |
7219 | return; |
7220 | } | |
ff908ebf | 7221 | |
f47fb265 | 7222 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 7223 | built_actual_name != NULL, |
f47fb265 MS |
7224 | VAR_DOMAIN, LOC_STATIC, |
7225 | &objfile->static_psymbols, | |
ff908ebf | 7226 | has_loc ? addr + baseaddr : (CORE_ADDR) 0, |
f47fb265 | 7227 | cu->language, objfile); |
c906108c SS |
7228 | } |
7229 | break; | |
7230 | case DW_TAG_typedef: | |
7231 | case DW_TAG_base_type: | |
a02abb62 | 7232 | case DW_TAG_subrange_type: |
38d518c9 | 7233 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 7234 | built_actual_name != NULL, |
176620f1 | 7235 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 7236 | &objfile->static_psymbols, |
1762568f | 7237 | 0, cu->language, objfile); |
c906108c | 7238 | break; |
74921315 | 7239 | case DW_TAG_imported_declaration: |
72bf9492 DJ |
7240 | case DW_TAG_namespace: |
7241 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
15d034d0 | 7242 | built_actual_name != NULL, |
72bf9492 DJ |
7243 | VAR_DOMAIN, LOC_TYPEDEF, |
7244 | &objfile->global_psymbols, | |
1762568f | 7245 | 0, cu->language, objfile); |
72bf9492 | 7246 | break; |
530e8392 KB |
7247 | case DW_TAG_module: |
7248 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
7249 | built_actual_name != NULL, | |
7250 | MODULE_DOMAIN, LOC_TYPEDEF, | |
7251 | &objfile->global_psymbols, | |
1762568f | 7252 | 0, cu->language, objfile); |
530e8392 | 7253 | break; |
c906108c | 7254 | case DW_TAG_class_type: |
680b30c7 | 7255 | case DW_TAG_interface_type: |
c906108c SS |
7256 | case DW_TAG_structure_type: |
7257 | case DW_TAG_union_type: | |
7258 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
7259 | /* Skip external references. The DWARF standard says in the section |
7260 | about "Structure, Union, and Class Type Entries": "An incomplete | |
7261 | structure, union or class type is represented by a structure, | |
7262 | union or class entry that does not have a byte size attribute | |
7263 | and that has a DW_AT_declaration attribute." */ | |
7264 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 | 7265 | { |
15d034d0 | 7266 | xfree (built_actual_name); |
decbce07 MS |
7267 | return; |
7268 | } | |
fa4028e9 | 7269 | |
63d06c5c DC |
7270 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
7271 | static vs. global. */ | |
38d518c9 | 7272 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 7273 | built_actual_name != NULL, |
176620f1 | 7274 | STRUCT_DOMAIN, LOC_TYPEDEF, |
9c37b5ae | 7275 | cu->language == language_cplus |
63d06c5c DC |
7276 | ? &objfile->global_psymbols |
7277 | : &objfile->static_psymbols, | |
1762568f | 7278 | 0, cu->language, objfile); |
c906108c | 7279 | |
c906108c SS |
7280 | break; |
7281 | case DW_TAG_enumerator: | |
38d518c9 | 7282 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 7283 | built_actual_name != NULL, |
176620f1 | 7284 | VAR_DOMAIN, LOC_CONST, |
9c37b5ae | 7285 | cu->language == language_cplus |
f6fe98ef DJ |
7286 | ? &objfile->global_psymbols |
7287 | : &objfile->static_psymbols, | |
1762568f | 7288 | 0, cu->language, objfile); |
c906108c SS |
7289 | break; |
7290 | default: | |
7291 | break; | |
7292 | } | |
5c4e30ca | 7293 | |
15d034d0 | 7294 | xfree (built_actual_name); |
c906108c SS |
7295 | } |
7296 | ||
5c4e30ca DC |
7297 | /* Read a partial die corresponding to a namespace; also, add a symbol |
7298 | corresponding to that namespace to the symbol table. NAMESPACE is | |
7299 | the name of the enclosing namespace. */ | |
91c24f0a | 7300 | |
72bf9492 DJ |
7301 | static void |
7302 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 7303 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
cdc07690 | 7304 | int set_addrmap, struct dwarf2_cu *cu) |
91c24f0a | 7305 | { |
72bf9492 | 7306 | /* Add a symbol for the namespace. */ |
e7c27a73 | 7307 | |
72bf9492 | 7308 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
7309 | |
7310 | /* Now scan partial symbols in that namespace. */ | |
7311 | ||
91c24f0a | 7312 | if (pdi->has_children) |
cdc07690 | 7313 | scan_partial_symbols (pdi->die_child, lowpc, highpc, set_addrmap, cu); |
91c24f0a DC |
7314 | } |
7315 | ||
5d7cb8df JK |
7316 | /* Read a partial die corresponding to a Fortran module. */ |
7317 | ||
7318 | static void | |
7319 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
cdc07690 | 7320 | CORE_ADDR *highpc, int set_addrmap, struct dwarf2_cu *cu) |
5d7cb8df | 7321 | { |
530e8392 KB |
7322 | /* Add a symbol for the namespace. */ |
7323 | ||
7324 | add_partial_symbol (pdi, cu); | |
7325 | ||
f55ee35c | 7326 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
7327 | |
7328 | if (pdi->has_children) | |
cdc07690 | 7329 | scan_partial_symbols (pdi->die_child, lowpc, highpc, set_addrmap, cu); |
5d7cb8df JK |
7330 | } |
7331 | ||
bc30ff58 JB |
7332 | /* Read a partial die corresponding to a subprogram and create a partial |
7333 | symbol for that subprogram. When the CU language allows it, this | |
7334 | routine also defines a partial symbol for each nested subprogram | |
cdc07690 | 7335 | that this subprogram contains. If SET_ADDRMAP is true, record the |
428fc5fc YQ |
7336 | covered ranges in the addrmap. Set *LOWPC and *HIGHPC to the lowest |
7337 | and highest PC values found in PDI. | |
6e70227d | 7338 | |
cdc07690 YQ |
7339 | PDI may also be a lexical block, in which case we simply search |
7340 | recursively for subprograms defined inside that lexical block. | |
bc30ff58 JB |
7341 | Again, this is only performed when the CU language allows this |
7342 | type of definitions. */ | |
7343 | ||
7344 | static void | |
7345 | add_partial_subprogram (struct partial_die_info *pdi, | |
7346 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
cdc07690 | 7347 | int set_addrmap, struct dwarf2_cu *cu) |
bc30ff58 JB |
7348 | { |
7349 | if (pdi->tag == DW_TAG_subprogram) | |
7350 | { | |
7351 | if (pdi->has_pc_info) | |
7352 | { | |
7353 | if (pdi->lowpc < *lowpc) | |
7354 | *lowpc = pdi->lowpc; | |
7355 | if (pdi->highpc > *highpc) | |
7356 | *highpc = pdi->highpc; | |
cdc07690 | 7357 | if (set_addrmap) |
5734ee8b | 7358 | { |
5734ee8b | 7359 | struct objfile *objfile = cu->objfile; |
3e29f34a MR |
7360 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
7361 | CORE_ADDR baseaddr; | |
7362 | CORE_ADDR highpc; | |
7363 | CORE_ADDR lowpc; | |
5734ee8b DJ |
7364 | |
7365 | baseaddr = ANOFFSET (objfile->section_offsets, | |
7366 | SECT_OFF_TEXT (objfile)); | |
3e29f34a MR |
7367 | lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, |
7368 | pdi->lowpc + baseaddr); | |
7369 | highpc = gdbarch_adjust_dwarf2_addr (gdbarch, | |
7370 | pdi->highpc + baseaddr); | |
7371 | addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1, | |
9291a0cd | 7372 | cu->per_cu->v.psymtab); |
5734ee8b | 7373 | } |
481860b3 GB |
7374 | } |
7375 | ||
7376 | if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined)) | |
7377 | { | |
bc30ff58 | 7378 | if (!pdi->is_declaration) |
e8d05480 JB |
7379 | /* Ignore subprogram DIEs that do not have a name, they are |
7380 | illegal. Do not emit a complaint at this point, we will | |
7381 | do so when we convert this psymtab into a symtab. */ | |
7382 | if (pdi->name) | |
7383 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
7384 | } |
7385 | } | |
6e70227d | 7386 | |
bc30ff58 JB |
7387 | if (! pdi->has_children) |
7388 | return; | |
7389 | ||
7390 | if (cu->language == language_ada) | |
7391 | { | |
7392 | pdi = pdi->die_child; | |
7393 | while (pdi != NULL) | |
7394 | { | |
7395 | fixup_partial_die (pdi, cu); | |
7396 | if (pdi->tag == DW_TAG_subprogram | |
7397 | || pdi->tag == DW_TAG_lexical_block) | |
cdc07690 | 7398 | add_partial_subprogram (pdi, lowpc, highpc, set_addrmap, cu); |
bc30ff58 JB |
7399 | pdi = pdi->die_sibling; |
7400 | } | |
7401 | } | |
7402 | } | |
7403 | ||
91c24f0a DC |
7404 | /* Read a partial die corresponding to an enumeration type. */ |
7405 | ||
72bf9492 DJ |
7406 | static void |
7407 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
7408 | struct dwarf2_cu *cu) | |
91c24f0a | 7409 | { |
72bf9492 | 7410 | struct partial_die_info *pdi; |
91c24f0a DC |
7411 | |
7412 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
7413 | add_partial_symbol (enum_pdi, cu); |
7414 | ||
7415 | pdi = enum_pdi->die_child; | |
7416 | while (pdi) | |
91c24f0a | 7417 | { |
72bf9492 | 7418 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 7419 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 7420 | else |
72bf9492 DJ |
7421 | add_partial_symbol (pdi, cu); |
7422 | pdi = pdi->die_sibling; | |
91c24f0a | 7423 | } |
91c24f0a DC |
7424 | } |
7425 | ||
6caca83c CC |
7426 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
7427 | ||
7428 | static unsigned int | |
d521ce57 | 7429 | peek_abbrev_code (bfd *abfd, const gdb_byte *info_ptr) |
6caca83c CC |
7430 | { |
7431 | unsigned int bytes_read; | |
7432 | ||
7433 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
7434 | } | |
7435 | ||
4bb7a0a7 DJ |
7436 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
7437 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
7438 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
7439 | the initial number. */ | |
7440 | ||
7441 | static struct abbrev_info * | |
d521ce57 | 7442 | peek_die_abbrev (const gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 7443 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
7444 | { |
7445 | bfd *abfd = cu->objfile->obfd; | |
7446 | unsigned int abbrev_number; | |
7447 | struct abbrev_info *abbrev; | |
7448 | ||
7449 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
7450 | ||
7451 | if (abbrev_number == 0) | |
7452 | return NULL; | |
7453 | ||
433df2d4 | 7454 | abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number); |
4bb7a0a7 DJ |
7455 | if (!abbrev) |
7456 | { | |
422b9917 DE |
7457 | error (_("Dwarf Error: Could not find abbrev number %d in %s" |
7458 | " at offset 0x%x [in module %s]"), | |
7459 | abbrev_number, cu->per_cu->is_debug_types ? "TU" : "CU", | |
9c541725 | 7460 | to_underlying (cu->header.sect_off), bfd_get_filename (abfd)); |
4bb7a0a7 DJ |
7461 | } |
7462 | ||
7463 | return abbrev; | |
7464 | } | |
7465 | ||
93311388 DE |
7466 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
7467 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
7468 | DIE. Any children of the skipped DIEs will also be skipped. */ |
7469 | ||
d521ce57 TT |
7470 | static const gdb_byte * |
7471 | skip_children (const struct die_reader_specs *reader, const gdb_byte *info_ptr) | |
4bb7a0a7 | 7472 | { |
dee91e82 | 7473 | struct dwarf2_cu *cu = reader->cu; |
4bb7a0a7 DJ |
7474 | struct abbrev_info *abbrev; |
7475 | unsigned int bytes_read; | |
7476 | ||
7477 | while (1) | |
7478 | { | |
7479 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
7480 | if (abbrev == NULL) | |
7481 | return info_ptr + bytes_read; | |
7482 | else | |
dee91e82 | 7483 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
4bb7a0a7 DJ |
7484 | } |
7485 | } | |
7486 | ||
93311388 DE |
7487 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
7488 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
7489 | abbrev corresponding to that skipped uleb128 should be passed in |
7490 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
7491 | children. */ | |
7492 | ||
d521ce57 TT |
7493 | static const gdb_byte * |
7494 | skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr, | |
dee91e82 | 7495 | struct abbrev_info *abbrev) |
4bb7a0a7 DJ |
7496 | { |
7497 | unsigned int bytes_read; | |
7498 | struct attribute attr; | |
dee91e82 DE |
7499 | bfd *abfd = reader->abfd; |
7500 | struct dwarf2_cu *cu = reader->cu; | |
d521ce57 | 7501 | const gdb_byte *buffer = reader->buffer; |
f664829e | 7502 | const gdb_byte *buffer_end = reader->buffer_end; |
4bb7a0a7 DJ |
7503 | unsigned int form, i; |
7504 | ||
7505 | for (i = 0; i < abbrev->num_attrs; i++) | |
7506 | { | |
7507 | /* The only abbrev we care about is DW_AT_sibling. */ | |
7508 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
7509 | { | |
dee91e82 | 7510 | read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
4bb7a0a7 | 7511 | if (attr.form == DW_FORM_ref_addr) |
3e43a32a MS |
7512 | complaint (&symfile_complaints, |
7513 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 7514 | else |
b9502d3f | 7515 | { |
9c541725 PA |
7516 | sect_offset off = dwarf2_get_ref_die_offset (&attr); |
7517 | const gdb_byte *sibling_ptr = buffer + to_underlying (off); | |
b9502d3f WN |
7518 | |
7519 | if (sibling_ptr < info_ptr) | |
7520 | complaint (&symfile_complaints, | |
7521 | _("DW_AT_sibling points backwards")); | |
22869d73 KS |
7522 | else if (sibling_ptr > reader->buffer_end) |
7523 | dwarf2_section_buffer_overflow_complaint (reader->die_section); | |
b9502d3f WN |
7524 | else |
7525 | return sibling_ptr; | |
7526 | } | |
4bb7a0a7 DJ |
7527 | } |
7528 | ||
7529 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
7530 | form = abbrev->attrs[i].form; | |
7531 | skip_attribute: | |
7532 | switch (form) | |
7533 | { | |
4bb7a0a7 | 7534 | case DW_FORM_ref_addr: |
ae411497 TT |
7535 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
7536 | and later it is offset sized. */ | |
7537 | if (cu->header.version == 2) | |
7538 | info_ptr += cu->header.addr_size; | |
7539 | else | |
7540 | info_ptr += cu->header.offset_size; | |
7541 | break; | |
36586728 TT |
7542 | case DW_FORM_GNU_ref_alt: |
7543 | info_ptr += cu->header.offset_size; | |
7544 | break; | |
ae411497 | 7545 | case DW_FORM_addr: |
4bb7a0a7 DJ |
7546 | info_ptr += cu->header.addr_size; |
7547 | break; | |
7548 | case DW_FORM_data1: | |
7549 | case DW_FORM_ref1: | |
7550 | case DW_FORM_flag: | |
7551 | info_ptr += 1; | |
7552 | break; | |
2dc7f7b3 | 7553 | case DW_FORM_flag_present: |
43988095 | 7554 | case DW_FORM_implicit_const: |
2dc7f7b3 | 7555 | break; |
4bb7a0a7 DJ |
7556 | case DW_FORM_data2: |
7557 | case DW_FORM_ref2: | |
7558 | info_ptr += 2; | |
7559 | break; | |
7560 | case DW_FORM_data4: | |
7561 | case DW_FORM_ref4: | |
7562 | info_ptr += 4; | |
7563 | break; | |
7564 | case DW_FORM_data8: | |
7565 | case DW_FORM_ref8: | |
55f1336d | 7566 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
7567 | info_ptr += 8; |
7568 | break; | |
0224619f JK |
7569 | case DW_FORM_data16: |
7570 | info_ptr += 16; | |
7571 | break; | |
4bb7a0a7 | 7572 | case DW_FORM_string: |
9b1c24c8 | 7573 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
7574 | info_ptr += bytes_read; |
7575 | break; | |
2dc7f7b3 | 7576 | case DW_FORM_sec_offset: |
4bb7a0a7 | 7577 | case DW_FORM_strp: |
36586728 | 7578 | case DW_FORM_GNU_strp_alt: |
4bb7a0a7 DJ |
7579 | info_ptr += cu->header.offset_size; |
7580 | break; | |
2dc7f7b3 | 7581 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
7582 | case DW_FORM_block: |
7583 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
7584 | info_ptr += bytes_read; | |
7585 | break; | |
7586 | case DW_FORM_block1: | |
7587 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
7588 | break; | |
7589 | case DW_FORM_block2: | |
7590 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
7591 | break; | |
7592 | case DW_FORM_block4: | |
7593 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
7594 | break; | |
7595 | case DW_FORM_sdata: | |
7596 | case DW_FORM_udata: | |
7597 | case DW_FORM_ref_udata: | |
3019eac3 DE |
7598 | case DW_FORM_GNU_addr_index: |
7599 | case DW_FORM_GNU_str_index: | |
d521ce57 | 7600 | info_ptr = safe_skip_leb128 (info_ptr, buffer_end); |
4bb7a0a7 DJ |
7601 | break; |
7602 | case DW_FORM_indirect: | |
7603 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
7604 | info_ptr += bytes_read; | |
7605 | /* We need to continue parsing from here, so just go back to | |
7606 | the top. */ | |
7607 | goto skip_attribute; | |
7608 | ||
7609 | default: | |
3e43a32a MS |
7610 | error (_("Dwarf Error: Cannot handle %s " |
7611 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
7612 | dwarf_form_name (form), |
7613 | bfd_get_filename (abfd)); | |
7614 | } | |
7615 | } | |
7616 | ||
7617 | if (abbrev->has_children) | |
dee91e82 | 7618 | return skip_children (reader, info_ptr); |
4bb7a0a7 DJ |
7619 | else |
7620 | return info_ptr; | |
7621 | } | |
7622 | ||
93311388 | 7623 | /* Locate ORIG_PDI's sibling. |
dee91e82 | 7624 | INFO_PTR should point to the start of the next DIE after ORIG_PDI. */ |
91c24f0a | 7625 | |
d521ce57 | 7626 | static const gdb_byte * |
dee91e82 DE |
7627 | locate_pdi_sibling (const struct die_reader_specs *reader, |
7628 | struct partial_die_info *orig_pdi, | |
d521ce57 | 7629 | const gdb_byte *info_ptr) |
91c24f0a DC |
7630 | { |
7631 | /* Do we know the sibling already? */ | |
72bf9492 | 7632 | |
91c24f0a DC |
7633 | if (orig_pdi->sibling) |
7634 | return orig_pdi->sibling; | |
7635 | ||
7636 | /* Are there any children to deal with? */ | |
7637 | ||
7638 | if (!orig_pdi->has_children) | |
7639 | return info_ptr; | |
7640 | ||
4bb7a0a7 | 7641 | /* Skip the children the long way. */ |
91c24f0a | 7642 | |
dee91e82 | 7643 | return skip_children (reader, info_ptr); |
91c24f0a DC |
7644 | } |
7645 | ||
257e7a09 | 7646 | /* Expand this partial symbol table into a full symbol table. SELF is |
442e4d9c | 7647 | not NULL. */ |
c906108c SS |
7648 | |
7649 | static void | |
257e7a09 YQ |
7650 | dwarf2_read_symtab (struct partial_symtab *self, |
7651 | struct objfile *objfile) | |
c906108c | 7652 | { |
257e7a09 | 7653 | if (self->readin) |
c906108c | 7654 | { |
442e4d9c | 7655 | warning (_("bug: psymtab for %s is already read in."), |
257e7a09 | 7656 | self->filename); |
442e4d9c YQ |
7657 | } |
7658 | else | |
7659 | { | |
7660 | if (info_verbose) | |
c906108c | 7661 | { |
442e4d9c | 7662 | printf_filtered (_("Reading in symbols for %s..."), |
257e7a09 | 7663 | self->filename); |
442e4d9c | 7664 | gdb_flush (gdb_stdout); |
c906108c | 7665 | } |
c906108c | 7666 | |
442e4d9c | 7667 | /* Restore our global data. */ |
9a3c8263 SM |
7668 | dwarf2_per_objfile |
7669 | = (struct dwarf2_per_objfile *) objfile_data (objfile, | |
7670 | dwarf2_objfile_data_key); | |
10b3939b | 7671 | |
442e4d9c YQ |
7672 | /* If this psymtab is constructed from a debug-only objfile, the |
7673 | has_section_at_zero flag will not necessarily be correct. We | |
7674 | can get the correct value for this flag by looking at the data | |
7675 | associated with the (presumably stripped) associated objfile. */ | |
7676 | if (objfile->separate_debug_objfile_backlink) | |
7677 | { | |
7678 | struct dwarf2_per_objfile *dpo_backlink | |
9a3c8263 SM |
7679 | = ((struct dwarf2_per_objfile *) |
7680 | objfile_data (objfile->separate_debug_objfile_backlink, | |
7681 | dwarf2_objfile_data_key)); | |
9a619af0 | 7682 | |
442e4d9c YQ |
7683 | dwarf2_per_objfile->has_section_at_zero |
7684 | = dpo_backlink->has_section_at_zero; | |
7685 | } | |
b2ab525c | 7686 | |
442e4d9c | 7687 | dwarf2_per_objfile->reading_partial_symbols = 0; |
98bfdba5 | 7688 | |
257e7a09 | 7689 | psymtab_to_symtab_1 (self); |
c906108c | 7690 | |
442e4d9c YQ |
7691 | /* Finish up the debug error message. */ |
7692 | if (info_verbose) | |
7693 | printf_filtered (_("done.\n")); | |
c906108c | 7694 | } |
95554aad TT |
7695 | |
7696 | process_cu_includes (); | |
c906108c | 7697 | } |
9cdd5dbd DE |
7698 | \f |
7699 | /* Reading in full CUs. */ | |
c906108c | 7700 | |
10b3939b DJ |
7701 | /* Add PER_CU to the queue. */ |
7702 | ||
7703 | static void | |
95554aad TT |
7704 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, |
7705 | enum language pretend_language) | |
10b3939b DJ |
7706 | { |
7707 | struct dwarf2_queue_item *item; | |
7708 | ||
7709 | per_cu->queued = 1; | |
8d749320 | 7710 | item = XNEW (struct dwarf2_queue_item); |
10b3939b | 7711 | item->per_cu = per_cu; |
95554aad | 7712 | item->pretend_language = pretend_language; |
10b3939b DJ |
7713 | item->next = NULL; |
7714 | ||
7715 | if (dwarf2_queue == NULL) | |
7716 | dwarf2_queue = item; | |
7717 | else | |
7718 | dwarf2_queue_tail->next = item; | |
7719 | ||
7720 | dwarf2_queue_tail = item; | |
7721 | } | |
7722 | ||
89e63ee4 DE |
7723 | /* If PER_CU is not yet queued, add it to the queue. |
7724 | If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a | |
7725 | dependency. | |
0907af0c | 7726 | The result is non-zero if PER_CU was queued, otherwise the result is zero |
69d751e3 DE |
7727 | meaning either PER_CU is already queued or it is already loaded. |
7728 | ||
7729 | N.B. There is an invariant here that if a CU is queued then it is loaded. | |
7730 | The caller is required to load PER_CU if we return non-zero. */ | |
0907af0c DE |
7731 | |
7732 | static int | |
89e63ee4 | 7733 | maybe_queue_comp_unit (struct dwarf2_cu *dependent_cu, |
0907af0c DE |
7734 | struct dwarf2_per_cu_data *per_cu, |
7735 | enum language pretend_language) | |
7736 | { | |
7737 | /* We may arrive here during partial symbol reading, if we need full | |
7738 | DIEs to process an unusual case (e.g. template arguments). Do | |
7739 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
7740 | if (dwarf2_per_objfile->reading_partial_symbols) | |
7741 | { | |
7742 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
7743 | return 1; | |
7744 | return 0; | |
7745 | } | |
7746 | ||
7747 | /* Mark the dependence relation so that we don't flush PER_CU | |
7748 | too early. */ | |
89e63ee4 DE |
7749 | if (dependent_cu != NULL) |
7750 | dwarf2_add_dependence (dependent_cu, per_cu); | |
0907af0c DE |
7751 | |
7752 | /* If it's already on the queue, we have nothing to do. */ | |
7753 | if (per_cu->queued) | |
7754 | return 0; | |
7755 | ||
7756 | /* If the compilation unit is already loaded, just mark it as | |
7757 | used. */ | |
7758 | if (per_cu->cu != NULL) | |
7759 | { | |
7760 | per_cu->cu->last_used = 0; | |
7761 | return 0; | |
7762 | } | |
7763 | ||
7764 | /* Add it to the queue. */ | |
7765 | queue_comp_unit (per_cu, pretend_language); | |
7766 | ||
7767 | return 1; | |
7768 | } | |
7769 | ||
10b3939b DJ |
7770 | /* Process the queue. */ |
7771 | ||
7772 | static void | |
a0f42c21 | 7773 | process_queue (void) |
10b3939b DJ |
7774 | { |
7775 | struct dwarf2_queue_item *item, *next_item; | |
7776 | ||
b4f54984 | 7777 | if (dwarf_read_debug) |
45cfd468 DE |
7778 | { |
7779 | fprintf_unfiltered (gdb_stdlog, | |
7780 | "Expanding one or more symtabs of objfile %s ...\n", | |
4262abfb | 7781 | objfile_name (dwarf2_per_objfile->objfile)); |
45cfd468 DE |
7782 | } |
7783 | ||
03dd20cc DJ |
7784 | /* The queue starts out with one item, but following a DIE reference |
7785 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
7786 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
7787 | { | |
cc12ce38 DE |
7788 | if ((dwarf2_per_objfile->using_index |
7789 | ? !item->per_cu->v.quick->compunit_symtab | |
7790 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
7791 | /* Skip dummy CUs. */ | |
7792 | && item->per_cu->cu != NULL) | |
f4dc4d17 DE |
7793 | { |
7794 | struct dwarf2_per_cu_data *per_cu = item->per_cu; | |
73be47f5 | 7795 | unsigned int debug_print_threshold; |
247f5c4f | 7796 | char buf[100]; |
f4dc4d17 | 7797 | |
247f5c4f | 7798 | if (per_cu->is_debug_types) |
f4dc4d17 | 7799 | { |
247f5c4f DE |
7800 | struct signatured_type *sig_type = |
7801 | (struct signatured_type *) per_cu; | |
7802 | ||
7803 | sprintf (buf, "TU %s at offset 0x%x", | |
73be47f5 | 7804 | hex_string (sig_type->signature), |
9c541725 | 7805 | to_underlying (per_cu->sect_off)); |
73be47f5 DE |
7806 | /* There can be 100s of TUs. |
7807 | Only print them in verbose mode. */ | |
7808 | debug_print_threshold = 2; | |
f4dc4d17 | 7809 | } |
247f5c4f | 7810 | else |
73be47f5 | 7811 | { |
9c541725 PA |
7812 | sprintf (buf, "CU at offset 0x%x", |
7813 | to_underlying (per_cu->sect_off)); | |
73be47f5 DE |
7814 | debug_print_threshold = 1; |
7815 | } | |
247f5c4f | 7816 | |
b4f54984 | 7817 | if (dwarf_read_debug >= debug_print_threshold) |
247f5c4f | 7818 | fprintf_unfiltered (gdb_stdlog, "Expanding symtab of %s\n", buf); |
f4dc4d17 DE |
7819 | |
7820 | if (per_cu->is_debug_types) | |
7821 | process_full_type_unit (per_cu, item->pretend_language); | |
7822 | else | |
7823 | process_full_comp_unit (per_cu, item->pretend_language); | |
7824 | ||
b4f54984 | 7825 | if (dwarf_read_debug >= debug_print_threshold) |
247f5c4f | 7826 | fprintf_unfiltered (gdb_stdlog, "Done expanding %s\n", buf); |
f4dc4d17 | 7827 | } |
10b3939b DJ |
7828 | |
7829 | item->per_cu->queued = 0; | |
7830 | next_item = item->next; | |
7831 | xfree (item); | |
7832 | } | |
7833 | ||
7834 | dwarf2_queue_tail = NULL; | |
45cfd468 | 7835 | |
b4f54984 | 7836 | if (dwarf_read_debug) |
45cfd468 DE |
7837 | { |
7838 | fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n", | |
4262abfb | 7839 | objfile_name (dwarf2_per_objfile->objfile)); |
45cfd468 | 7840 | } |
10b3939b DJ |
7841 | } |
7842 | ||
7843 | /* Free all allocated queue entries. This function only releases anything if | |
7844 | an error was thrown; if the queue was processed then it would have been | |
7845 | freed as we went along. */ | |
7846 | ||
7847 | static void | |
7848 | dwarf2_release_queue (void *dummy) | |
7849 | { | |
7850 | struct dwarf2_queue_item *item, *last; | |
7851 | ||
7852 | item = dwarf2_queue; | |
7853 | while (item) | |
7854 | { | |
7855 | /* Anything still marked queued is likely to be in an | |
7856 | inconsistent state, so discard it. */ | |
7857 | if (item->per_cu->queued) | |
7858 | { | |
7859 | if (item->per_cu->cu != NULL) | |
dee91e82 | 7860 | free_one_cached_comp_unit (item->per_cu); |
10b3939b DJ |
7861 | item->per_cu->queued = 0; |
7862 | } | |
7863 | ||
7864 | last = item; | |
7865 | item = item->next; | |
7866 | xfree (last); | |
7867 | } | |
7868 | ||
7869 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
7870 | } | |
7871 | ||
7872 | /* Read in full symbols for PST, and anything it depends on. */ | |
7873 | ||
c906108c | 7874 | static void |
fba45db2 | 7875 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 7876 | { |
10b3939b | 7877 | struct dwarf2_per_cu_data *per_cu; |
aaa75496 JB |
7878 | int i; |
7879 | ||
95554aad TT |
7880 | if (pst->readin) |
7881 | return; | |
7882 | ||
aaa75496 | 7883 | for (i = 0; i < pst->number_of_dependencies; i++) |
95554aad TT |
7884 | if (!pst->dependencies[i]->readin |
7885 | && pst->dependencies[i]->user == NULL) | |
aaa75496 JB |
7886 | { |
7887 | /* Inform about additional files that need to be read in. */ | |
7888 | if (info_verbose) | |
7889 | { | |
a3f17187 | 7890 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
7891 | fputs_filtered (" ", gdb_stdout); |
7892 | wrap_here (""); | |
7893 | fputs_filtered ("and ", gdb_stdout); | |
7894 | wrap_here (""); | |
7895 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 7896 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
7897 | gdb_flush (gdb_stdout); |
7898 | } | |
7899 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
7900 | } | |
7901 | ||
9a3c8263 | 7902 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
10b3939b DJ |
7903 | |
7904 | if (per_cu == NULL) | |
aaa75496 JB |
7905 | { |
7906 | /* It's an include file, no symbols to read for it. | |
7907 | Everything is in the parent symtab. */ | |
7908 | pst->readin = 1; | |
7909 | return; | |
7910 | } | |
c906108c | 7911 | |
a0f42c21 | 7912 | dw2_do_instantiate_symtab (per_cu); |
10b3939b DJ |
7913 | } |
7914 | ||
dee91e82 DE |
7915 | /* Trivial hash function for die_info: the hash value of a DIE |
7916 | is its offset in .debug_info for this objfile. */ | |
10b3939b | 7917 | |
dee91e82 DE |
7918 | static hashval_t |
7919 | die_hash (const void *item) | |
10b3939b | 7920 | { |
9a3c8263 | 7921 | const struct die_info *die = (const struct die_info *) item; |
6502dd73 | 7922 | |
9c541725 | 7923 | return to_underlying (die->sect_off); |
dee91e82 | 7924 | } |
63d06c5c | 7925 | |
dee91e82 DE |
7926 | /* Trivial comparison function for die_info structures: two DIEs |
7927 | are equal if they have the same offset. */ | |
98bfdba5 | 7928 | |
dee91e82 DE |
7929 | static int |
7930 | die_eq (const void *item_lhs, const void *item_rhs) | |
7931 | { | |
9a3c8263 SM |
7932 | const struct die_info *die_lhs = (const struct die_info *) item_lhs; |
7933 | const struct die_info *die_rhs = (const struct die_info *) item_rhs; | |
c906108c | 7934 | |
9c541725 | 7935 | return die_lhs->sect_off == die_rhs->sect_off; |
dee91e82 | 7936 | } |
c906108c | 7937 | |
dee91e82 DE |
7938 | /* die_reader_func for load_full_comp_unit. |
7939 | This is identical to read_signatured_type_reader, | |
7940 | but is kept separate for now. */ | |
c906108c | 7941 | |
dee91e82 DE |
7942 | static void |
7943 | load_full_comp_unit_reader (const struct die_reader_specs *reader, | |
d521ce57 | 7944 | const gdb_byte *info_ptr, |
dee91e82 DE |
7945 | struct die_info *comp_unit_die, |
7946 | int has_children, | |
7947 | void *data) | |
7948 | { | |
7949 | struct dwarf2_cu *cu = reader->cu; | |
9a3c8263 | 7950 | enum language *language_ptr = (enum language *) data; |
6caca83c | 7951 | |
dee91e82 DE |
7952 | gdb_assert (cu->die_hash == NULL); |
7953 | cu->die_hash = | |
7954 | htab_create_alloc_ex (cu->header.length / 12, | |
7955 | die_hash, | |
7956 | die_eq, | |
7957 | NULL, | |
7958 | &cu->comp_unit_obstack, | |
7959 | hashtab_obstack_allocate, | |
7960 | dummy_obstack_deallocate); | |
e142c38c | 7961 | |
dee91e82 DE |
7962 | if (has_children) |
7963 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
7964 | &info_ptr, comp_unit_die); | |
7965 | cu->dies = comp_unit_die; | |
7966 | /* comp_unit_die is not stored in die_hash, no need. */ | |
10b3939b DJ |
7967 | |
7968 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 7969 | all CUs needed for references have been loaded yet, and symbol |
10b3939b | 7970 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
7971 | or we won't be able to build types correctly. |
7972 | Similarly, if we do not read the producer, we can not apply | |
7973 | producer-specific interpretation. */ | |
95554aad | 7974 | prepare_one_comp_unit (cu, cu->dies, *language_ptr); |
dee91e82 | 7975 | } |
10b3939b | 7976 | |
dee91e82 | 7977 | /* Load the DIEs associated with PER_CU into memory. */ |
a6c727b2 | 7978 | |
dee91e82 | 7979 | static void |
95554aad TT |
7980 | load_full_comp_unit (struct dwarf2_per_cu_data *this_cu, |
7981 | enum language pretend_language) | |
dee91e82 | 7982 | { |
3019eac3 | 7983 | gdb_assert (! this_cu->is_debug_types); |
c5b7e1cb | 7984 | |
f4dc4d17 DE |
7985 | init_cutu_and_read_dies (this_cu, NULL, 1, 1, |
7986 | load_full_comp_unit_reader, &pretend_language); | |
10b3939b DJ |
7987 | } |
7988 | ||
3da10d80 KS |
7989 | /* Add a DIE to the delayed physname list. */ |
7990 | ||
7991 | static void | |
7992 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
7993 | const char *name, struct die_info *die, | |
7994 | struct dwarf2_cu *cu) | |
7995 | { | |
7996 | struct delayed_method_info mi; | |
7997 | mi.type = type; | |
7998 | mi.fnfield_index = fnfield_index; | |
7999 | mi.index = index; | |
8000 | mi.name = name; | |
8001 | mi.die = die; | |
8002 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
8003 | } | |
8004 | ||
8005 | /* A cleanup for freeing the delayed method list. */ | |
8006 | ||
8007 | static void | |
8008 | free_delayed_list (void *ptr) | |
8009 | { | |
8010 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
8011 | if (cu->method_list != NULL) | |
8012 | { | |
8013 | VEC_free (delayed_method_info, cu->method_list); | |
8014 | cu->method_list = NULL; | |
8015 | } | |
8016 | } | |
8017 | ||
8018 | /* Compute the physnames of any methods on the CU's method list. | |
8019 | ||
8020 | The computation of method physnames is delayed in order to avoid the | |
8021 | (bad) condition that one of the method's formal parameters is of an as yet | |
8022 | incomplete type. */ | |
8023 | ||
8024 | static void | |
8025 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
8026 | { | |
8027 | int i; | |
8028 | struct delayed_method_info *mi; | |
8029 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
8030 | { | |
1d06ead6 | 8031 | const char *physname; |
3da10d80 KS |
8032 | struct fn_fieldlist *fn_flp |
8033 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
7d455152 | 8034 | physname = dwarf2_physname (mi->name, mi->die, cu); |
005e54bb DE |
8035 | TYPE_FN_FIELD_PHYSNAME (fn_flp->fn_fields, mi->index) |
8036 | = physname ? physname : ""; | |
3da10d80 KS |
8037 | } |
8038 | } | |
8039 | ||
a766d390 DE |
8040 | /* Go objects should be embedded in a DW_TAG_module DIE, |
8041 | and it's not clear if/how imported objects will appear. | |
8042 | To keep Go support simple until that's worked out, | |
8043 | go back through what we've read and create something usable. | |
8044 | We could do this while processing each DIE, and feels kinda cleaner, | |
8045 | but that way is more invasive. | |
8046 | This is to, for example, allow the user to type "p var" or "b main" | |
8047 | without having to specify the package name, and allow lookups | |
8048 | of module.object to work in contexts that use the expression | |
8049 | parser. */ | |
8050 | ||
8051 | static void | |
8052 | fixup_go_packaging (struct dwarf2_cu *cu) | |
8053 | { | |
8054 | char *package_name = NULL; | |
8055 | struct pending *list; | |
8056 | int i; | |
8057 | ||
8058 | for (list = global_symbols; list != NULL; list = list->next) | |
8059 | { | |
8060 | for (i = 0; i < list->nsyms; ++i) | |
8061 | { | |
8062 | struct symbol *sym = list->symbol[i]; | |
8063 | ||
8064 | if (SYMBOL_LANGUAGE (sym) == language_go | |
8065 | && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
8066 | { | |
8067 | char *this_package_name = go_symbol_package_name (sym); | |
8068 | ||
8069 | if (this_package_name == NULL) | |
8070 | continue; | |
8071 | if (package_name == NULL) | |
8072 | package_name = this_package_name; | |
8073 | else | |
8074 | { | |
8075 | if (strcmp (package_name, this_package_name) != 0) | |
8076 | complaint (&symfile_complaints, | |
8077 | _("Symtab %s has objects from two different Go packages: %s and %s"), | |
08be3fe3 DE |
8078 | (symbol_symtab (sym) != NULL |
8079 | ? symtab_to_filename_for_display | |
8080 | (symbol_symtab (sym)) | |
4262abfb | 8081 | : objfile_name (cu->objfile)), |
a766d390 DE |
8082 | this_package_name, package_name); |
8083 | xfree (this_package_name); | |
8084 | } | |
8085 | } | |
8086 | } | |
8087 | } | |
8088 | ||
8089 | if (package_name != NULL) | |
8090 | { | |
8091 | struct objfile *objfile = cu->objfile; | |
34a68019 | 8092 | const char *saved_package_name |
224c3ddb SM |
8093 | = (const char *) obstack_copy0 (&objfile->per_bfd->storage_obstack, |
8094 | package_name, | |
8095 | strlen (package_name)); | |
19f392bc UW |
8096 | struct type *type = init_type (objfile, TYPE_CODE_MODULE, 0, |
8097 | saved_package_name); | |
a766d390 DE |
8098 | struct symbol *sym; |
8099 | ||
8100 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8101 | ||
e623cf5d | 8102 | sym = allocate_symbol (objfile); |
f85f34ed | 8103 | SYMBOL_SET_LANGUAGE (sym, language_go, &objfile->objfile_obstack); |
86f62fd7 TT |
8104 | SYMBOL_SET_NAMES (sym, saved_package_name, |
8105 | strlen (saved_package_name), 0, objfile); | |
a766d390 DE |
8106 | /* This is not VAR_DOMAIN because we want a way to ensure a lookup of, |
8107 | e.g., "main" finds the "main" module and not C's main(). */ | |
8108 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; | |
f1e6e072 | 8109 | SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF; |
a766d390 DE |
8110 | SYMBOL_TYPE (sym) = type; |
8111 | ||
8112 | add_symbol_to_list (sym, &global_symbols); | |
8113 | ||
8114 | xfree (package_name); | |
8115 | } | |
8116 | } | |
8117 | ||
95554aad TT |
8118 | /* Return the symtab for PER_CU. This works properly regardless of |
8119 | whether we're using the index or psymtabs. */ | |
8120 | ||
43f3e411 DE |
8121 | static struct compunit_symtab * |
8122 | get_compunit_symtab (struct dwarf2_per_cu_data *per_cu) | |
95554aad TT |
8123 | { |
8124 | return (dwarf2_per_objfile->using_index | |
43f3e411 DE |
8125 | ? per_cu->v.quick->compunit_symtab |
8126 | : per_cu->v.psymtab->compunit_symtab); | |
95554aad TT |
8127 | } |
8128 | ||
8129 | /* A helper function for computing the list of all symbol tables | |
8130 | included by PER_CU. */ | |
8131 | ||
8132 | static void | |
43f3e411 | 8133 | recursively_compute_inclusions (VEC (compunit_symtab_ptr) **result, |
ec94af83 | 8134 | htab_t all_children, htab_t all_type_symtabs, |
f9125b6c | 8135 | struct dwarf2_per_cu_data *per_cu, |
43f3e411 | 8136 | struct compunit_symtab *immediate_parent) |
95554aad TT |
8137 | { |
8138 | void **slot; | |
8139 | int ix; | |
43f3e411 | 8140 | struct compunit_symtab *cust; |
95554aad TT |
8141 | struct dwarf2_per_cu_data *iter; |
8142 | ||
8143 | slot = htab_find_slot (all_children, per_cu, INSERT); | |
8144 | if (*slot != NULL) | |
8145 | { | |
8146 | /* This inclusion and its children have been processed. */ | |
8147 | return; | |
8148 | } | |
8149 | ||
8150 | *slot = per_cu; | |
8151 | /* Only add a CU if it has a symbol table. */ | |
43f3e411 DE |
8152 | cust = get_compunit_symtab (per_cu); |
8153 | if (cust != NULL) | |
ec94af83 DE |
8154 | { |
8155 | /* If this is a type unit only add its symbol table if we haven't | |
8156 | seen it yet (type unit per_cu's can share symtabs). */ | |
8157 | if (per_cu->is_debug_types) | |
8158 | { | |
43f3e411 | 8159 | slot = htab_find_slot (all_type_symtabs, cust, INSERT); |
ec94af83 DE |
8160 | if (*slot == NULL) |
8161 | { | |
43f3e411 DE |
8162 | *slot = cust; |
8163 | VEC_safe_push (compunit_symtab_ptr, *result, cust); | |
8164 | if (cust->user == NULL) | |
8165 | cust->user = immediate_parent; | |
ec94af83 DE |
8166 | } |
8167 | } | |
8168 | else | |
f9125b6c | 8169 | { |
43f3e411 DE |
8170 | VEC_safe_push (compunit_symtab_ptr, *result, cust); |
8171 | if (cust->user == NULL) | |
8172 | cust->user = immediate_parent; | |
f9125b6c | 8173 | } |
ec94af83 | 8174 | } |
95554aad TT |
8175 | |
8176 | for (ix = 0; | |
796a7ff8 | 8177 | VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter); |
95554aad | 8178 | ++ix) |
ec94af83 DE |
8179 | { |
8180 | recursively_compute_inclusions (result, all_children, | |
43f3e411 | 8181 | all_type_symtabs, iter, cust); |
ec94af83 | 8182 | } |
95554aad TT |
8183 | } |
8184 | ||
43f3e411 | 8185 | /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of |
95554aad TT |
8186 | PER_CU. */ |
8187 | ||
8188 | static void | |
43f3e411 | 8189 | compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu) |
95554aad | 8190 | { |
f4dc4d17 DE |
8191 | gdb_assert (! per_cu->is_debug_types); |
8192 | ||
796a7ff8 | 8193 | if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs)) |
95554aad TT |
8194 | { |
8195 | int ix, len; | |
ec94af83 | 8196 | struct dwarf2_per_cu_data *per_cu_iter; |
43f3e411 DE |
8197 | struct compunit_symtab *compunit_symtab_iter; |
8198 | VEC (compunit_symtab_ptr) *result_symtabs = NULL; | |
ec94af83 | 8199 | htab_t all_children, all_type_symtabs; |
43f3e411 | 8200 | struct compunit_symtab *cust = get_compunit_symtab (per_cu); |
95554aad TT |
8201 | |
8202 | /* If we don't have a symtab, we can just skip this case. */ | |
43f3e411 | 8203 | if (cust == NULL) |
95554aad TT |
8204 | return; |
8205 | ||
8206 | all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, | |
8207 | NULL, xcalloc, xfree); | |
ec94af83 DE |
8208 | all_type_symtabs = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, |
8209 | NULL, xcalloc, xfree); | |
95554aad TT |
8210 | |
8211 | for (ix = 0; | |
796a7ff8 | 8212 | VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, |
ec94af83 | 8213 | ix, per_cu_iter); |
95554aad | 8214 | ++ix) |
ec94af83 DE |
8215 | { |
8216 | recursively_compute_inclusions (&result_symtabs, all_children, | |
f9125b6c | 8217 | all_type_symtabs, per_cu_iter, |
43f3e411 | 8218 | cust); |
ec94af83 | 8219 | } |
95554aad | 8220 | |
ec94af83 | 8221 | /* Now we have a transitive closure of all the included symtabs. */ |
43f3e411 DE |
8222 | len = VEC_length (compunit_symtab_ptr, result_symtabs); |
8223 | cust->includes | |
8d749320 SM |
8224 | = XOBNEWVEC (&dwarf2_per_objfile->objfile->objfile_obstack, |
8225 | struct compunit_symtab *, len + 1); | |
95554aad | 8226 | for (ix = 0; |
43f3e411 DE |
8227 | VEC_iterate (compunit_symtab_ptr, result_symtabs, ix, |
8228 | compunit_symtab_iter); | |
95554aad | 8229 | ++ix) |
43f3e411 DE |
8230 | cust->includes[ix] = compunit_symtab_iter; |
8231 | cust->includes[len] = NULL; | |
95554aad | 8232 | |
43f3e411 | 8233 | VEC_free (compunit_symtab_ptr, result_symtabs); |
95554aad | 8234 | htab_delete (all_children); |
ec94af83 | 8235 | htab_delete (all_type_symtabs); |
95554aad TT |
8236 | } |
8237 | } | |
8238 | ||
8239 | /* Compute the 'includes' field for the symtabs of all the CUs we just | |
8240 | read. */ | |
8241 | ||
8242 | static void | |
8243 | process_cu_includes (void) | |
8244 | { | |
8245 | int ix; | |
8246 | struct dwarf2_per_cu_data *iter; | |
8247 | ||
8248 | for (ix = 0; | |
8249 | VEC_iterate (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, | |
8250 | ix, iter); | |
8251 | ++ix) | |
f4dc4d17 DE |
8252 | { |
8253 | if (! iter->is_debug_types) | |
43f3e411 | 8254 | compute_compunit_symtab_includes (iter); |
f4dc4d17 | 8255 | } |
95554aad TT |
8256 | |
8257 | VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus); | |
8258 | } | |
8259 | ||
9cdd5dbd | 8260 | /* Generate full symbol information for PER_CU, whose DIEs have |
10b3939b DJ |
8261 | already been loaded into memory. */ |
8262 | ||
8263 | static void | |
95554aad TT |
8264 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, |
8265 | enum language pretend_language) | |
10b3939b | 8266 | { |
10b3939b | 8267 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 8268 | struct objfile *objfile = per_cu->objfile; |
3e29f34a | 8269 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
10b3939b | 8270 | CORE_ADDR lowpc, highpc; |
43f3e411 | 8271 | struct compunit_symtab *cust; |
3da10d80 | 8272 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b | 8273 | CORE_ADDR baseaddr; |
4359dff1 | 8274 | struct block *static_block; |
3e29f34a | 8275 | CORE_ADDR addr; |
10b3939b DJ |
8276 | |
8277 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
8278 | ||
10b3939b DJ |
8279 | buildsym_init (); |
8280 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 8281 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
8282 | |
8283 | cu->list_in_scope = &file_symbols; | |
c906108c | 8284 | |
95554aad TT |
8285 | cu->language = pretend_language; |
8286 | cu->language_defn = language_def (cu->language); | |
8287 | ||
c906108c | 8288 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 8289 | process_die (cu->dies, cu); |
c906108c | 8290 | |
a766d390 DE |
8291 | /* For now fudge the Go package. */ |
8292 | if (cu->language == language_go) | |
8293 | fixup_go_packaging (cu); | |
8294 | ||
3da10d80 KS |
8295 | /* Now that we have processed all the DIEs in the CU, all the types |
8296 | should be complete, and it should now be safe to compute all of the | |
8297 | physnames. */ | |
8298 | compute_delayed_physnames (cu); | |
8299 | do_cleanups (delayed_list_cleanup); | |
8300 | ||
fae299cd DC |
8301 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
8302 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
8303 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 8304 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 8305 | |
3e29f34a MR |
8306 | addr = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr); |
8307 | static_block = end_symtab_get_static_block (addr, 0, 1); | |
4359dff1 JK |
8308 | |
8309 | /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges. | |
8310 | Also, DW_AT_ranges may record ranges not belonging to any child DIEs | |
8311 | (such as virtual method tables). Record the ranges in STATIC_BLOCK's | |
8312 | addrmap to help ensure it has an accurate map of pc values belonging to | |
8313 | this comp unit. */ | |
8314 | dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu); | |
8315 | ||
43f3e411 DE |
8316 | cust = end_symtab_from_static_block (static_block, |
8317 | SECT_OFF_TEXT (objfile), 0); | |
c906108c | 8318 | |
43f3e411 | 8319 | if (cust != NULL) |
c906108c | 8320 | { |
df15bd07 | 8321 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
4632c0d0 | 8322 | |
8be455d7 JK |
8323 | /* Set symtab language to language from DW_AT_language. If the |
8324 | compilation is from a C file generated by language preprocessors, do | |
8325 | not set the language if it was already deduced by start_subfile. */ | |
43f3e411 | 8326 | if (!(cu->language == language_c |
40e3ad0e | 8327 | && COMPUNIT_FILETABS (cust)->language != language_unknown)) |
43f3e411 | 8328 | COMPUNIT_FILETABS (cust)->language = cu->language; |
8be455d7 JK |
8329 | |
8330 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
8331 | produce DW_AT_location with location lists but it can be possibly | |
ab260dad JK |
8332 | invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0 |
8333 | there were bugs in prologue debug info, fixed later in GCC-4.5 | |
8334 | by "unwind info for epilogues" patch (which is not directly related). | |
8be455d7 JK |
8335 | |
8336 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
8337 | needed, it would be wrong due to missing DW_AT_producer there. | |
8338 | ||
8339 | Still one can confuse GDB by using non-standard GCC compilation | |
8340 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
8341 | */ | |
ab260dad | 8342 | if (cu->has_loclist && gcc_4_minor >= 5) |
43f3e411 | 8343 | cust->locations_valid = 1; |
e0d00bc7 JK |
8344 | |
8345 | if (gcc_4_minor >= 5) | |
43f3e411 | 8346 | cust->epilogue_unwind_valid = 1; |
96408a79 | 8347 | |
43f3e411 | 8348 | cust->call_site_htab = cu->call_site_htab; |
c906108c | 8349 | } |
9291a0cd TT |
8350 | |
8351 | if (dwarf2_per_objfile->using_index) | |
43f3e411 | 8352 | per_cu->v.quick->compunit_symtab = cust; |
9291a0cd TT |
8353 | else |
8354 | { | |
8355 | struct partial_symtab *pst = per_cu->v.psymtab; | |
43f3e411 | 8356 | pst->compunit_symtab = cust; |
9291a0cd TT |
8357 | pst->readin = 1; |
8358 | } | |
c906108c | 8359 | |
95554aad TT |
8360 | /* Push it for inclusion processing later. */ |
8361 | VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu); | |
8362 | ||
c906108c | 8363 | do_cleanups (back_to); |
f4dc4d17 | 8364 | } |
45cfd468 | 8365 | |
f4dc4d17 DE |
8366 | /* Generate full symbol information for type unit PER_CU, whose DIEs have |
8367 | already been loaded into memory. */ | |
8368 | ||
8369 | static void | |
8370 | process_full_type_unit (struct dwarf2_per_cu_data *per_cu, | |
8371 | enum language pretend_language) | |
8372 | { | |
8373 | struct dwarf2_cu *cu = per_cu->cu; | |
8374 | struct objfile *objfile = per_cu->objfile; | |
43f3e411 | 8375 | struct compunit_symtab *cust; |
f4dc4d17 | 8376 | struct cleanup *back_to, *delayed_list_cleanup; |
0186c6a7 DE |
8377 | struct signatured_type *sig_type; |
8378 | ||
8379 | gdb_assert (per_cu->is_debug_types); | |
8380 | sig_type = (struct signatured_type *) per_cu; | |
f4dc4d17 DE |
8381 | |
8382 | buildsym_init (); | |
8383 | back_to = make_cleanup (really_free_pendings, NULL); | |
8384 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); | |
8385 | ||
8386 | cu->list_in_scope = &file_symbols; | |
8387 | ||
8388 | cu->language = pretend_language; | |
8389 | cu->language_defn = language_def (cu->language); | |
8390 | ||
8391 | /* The symbol tables are set up in read_type_unit_scope. */ | |
8392 | process_die (cu->dies, cu); | |
8393 | ||
8394 | /* For now fudge the Go package. */ | |
8395 | if (cu->language == language_go) | |
8396 | fixup_go_packaging (cu); | |
8397 | ||
8398 | /* Now that we have processed all the DIEs in the CU, all the types | |
8399 | should be complete, and it should now be safe to compute all of the | |
8400 | physnames. */ | |
8401 | compute_delayed_physnames (cu); | |
8402 | do_cleanups (delayed_list_cleanup); | |
8403 | ||
8404 | /* TUs share symbol tables. | |
8405 | If this is the first TU to use this symtab, complete the construction | |
094b34ac DE |
8406 | of it with end_expandable_symtab. Otherwise, complete the addition of |
8407 | this TU's symbols to the existing symtab. */ | |
43f3e411 | 8408 | if (sig_type->type_unit_group->compunit_symtab == NULL) |
45cfd468 | 8409 | { |
43f3e411 DE |
8410 | cust = end_expandable_symtab (0, SECT_OFF_TEXT (objfile)); |
8411 | sig_type->type_unit_group->compunit_symtab = cust; | |
f4dc4d17 | 8412 | |
43f3e411 | 8413 | if (cust != NULL) |
f4dc4d17 DE |
8414 | { |
8415 | /* Set symtab language to language from DW_AT_language. If the | |
8416 | compilation is from a C file generated by language preprocessors, | |
8417 | do not set the language if it was already deduced by | |
8418 | start_subfile. */ | |
43f3e411 DE |
8419 | if (!(cu->language == language_c |
8420 | && COMPUNIT_FILETABS (cust)->language != language_c)) | |
8421 | COMPUNIT_FILETABS (cust)->language = cu->language; | |
f4dc4d17 DE |
8422 | } |
8423 | } | |
8424 | else | |
8425 | { | |
0ab9ce85 | 8426 | augment_type_symtab (); |
43f3e411 | 8427 | cust = sig_type->type_unit_group->compunit_symtab; |
f4dc4d17 DE |
8428 | } |
8429 | ||
8430 | if (dwarf2_per_objfile->using_index) | |
43f3e411 | 8431 | per_cu->v.quick->compunit_symtab = cust; |
f4dc4d17 DE |
8432 | else |
8433 | { | |
8434 | struct partial_symtab *pst = per_cu->v.psymtab; | |
43f3e411 | 8435 | pst->compunit_symtab = cust; |
f4dc4d17 | 8436 | pst->readin = 1; |
45cfd468 | 8437 | } |
f4dc4d17 DE |
8438 | |
8439 | do_cleanups (back_to); | |
c906108c SS |
8440 | } |
8441 | ||
95554aad TT |
8442 | /* Process an imported unit DIE. */ |
8443 | ||
8444 | static void | |
8445 | process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu) | |
8446 | { | |
8447 | struct attribute *attr; | |
8448 | ||
f4dc4d17 DE |
8449 | /* For now we don't handle imported units in type units. */ |
8450 | if (cu->per_cu->is_debug_types) | |
8451 | { | |
8452 | error (_("Dwarf Error: DW_TAG_imported_unit is not" | |
8453 | " supported in type units [in module %s]"), | |
4262abfb | 8454 | objfile_name (cu->objfile)); |
f4dc4d17 DE |
8455 | } |
8456 | ||
95554aad TT |
8457 | attr = dwarf2_attr (die, DW_AT_import, cu); |
8458 | if (attr != NULL) | |
8459 | { | |
9c541725 PA |
8460 | sect_offset sect_off = dwarf2_get_ref_die_offset (attr); |
8461 | bool is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz); | |
8462 | dwarf2_per_cu_data *per_cu | |
8463 | = dwarf2_find_containing_comp_unit (sect_off, is_dwz, cu->objfile); | |
95554aad | 8464 | |
69d751e3 | 8465 | /* If necessary, add it to the queue and load its DIEs. */ |
95554aad TT |
8466 | if (maybe_queue_comp_unit (cu, per_cu, cu->language)) |
8467 | load_full_comp_unit (per_cu, cu->language); | |
8468 | ||
796a7ff8 | 8469 | VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, |
95554aad TT |
8470 | per_cu); |
8471 | } | |
8472 | } | |
8473 | ||
adde2bff DE |
8474 | /* Reset the in_process bit of a die. */ |
8475 | ||
8476 | static void | |
8477 | reset_die_in_process (void *arg) | |
8478 | { | |
9a3c8263 | 8479 | struct die_info *die = (struct die_info *) arg; |
8c3cb9fa | 8480 | |
adde2bff DE |
8481 | die->in_process = 0; |
8482 | } | |
8483 | ||
c906108c SS |
8484 | /* Process a die and its children. */ |
8485 | ||
8486 | static void | |
e7c27a73 | 8487 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8488 | { |
adde2bff DE |
8489 | struct cleanup *in_process; |
8490 | ||
8491 | /* We should only be processing those not already in process. */ | |
8492 | gdb_assert (!die->in_process); | |
8493 | ||
8494 | die->in_process = 1; | |
8495 | in_process = make_cleanup (reset_die_in_process,die); | |
8496 | ||
c906108c SS |
8497 | switch (die->tag) |
8498 | { | |
8499 | case DW_TAG_padding: | |
8500 | break; | |
8501 | case DW_TAG_compile_unit: | |
95554aad | 8502 | case DW_TAG_partial_unit: |
e7c27a73 | 8503 | read_file_scope (die, cu); |
c906108c | 8504 | break; |
348e048f DE |
8505 | case DW_TAG_type_unit: |
8506 | read_type_unit_scope (die, cu); | |
8507 | break; | |
c906108c | 8508 | case DW_TAG_subprogram: |
c906108c | 8509 | case DW_TAG_inlined_subroutine: |
edb3359d | 8510 | read_func_scope (die, cu); |
c906108c SS |
8511 | break; |
8512 | case DW_TAG_lexical_block: | |
14898363 L |
8513 | case DW_TAG_try_block: |
8514 | case DW_TAG_catch_block: | |
e7c27a73 | 8515 | read_lexical_block_scope (die, cu); |
c906108c | 8516 | break; |
216f72a1 | 8517 | case DW_TAG_call_site: |
96408a79 SA |
8518 | case DW_TAG_GNU_call_site: |
8519 | read_call_site_scope (die, cu); | |
8520 | break; | |
c906108c | 8521 | case DW_TAG_class_type: |
680b30c7 | 8522 | case DW_TAG_interface_type: |
c906108c SS |
8523 | case DW_TAG_structure_type: |
8524 | case DW_TAG_union_type: | |
134d01f1 | 8525 | process_structure_scope (die, cu); |
c906108c SS |
8526 | break; |
8527 | case DW_TAG_enumeration_type: | |
134d01f1 | 8528 | process_enumeration_scope (die, cu); |
c906108c | 8529 | break; |
134d01f1 | 8530 | |
f792889a DJ |
8531 | /* These dies have a type, but processing them does not create |
8532 | a symbol or recurse to process the children. Therefore we can | |
8533 | read them on-demand through read_type_die. */ | |
c906108c | 8534 | case DW_TAG_subroutine_type: |
72019c9c | 8535 | case DW_TAG_set_type: |
c906108c | 8536 | case DW_TAG_array_type: |
c906108c | 8537 | case DW_TAG_pointer_type: |
c906108c | 8538 | case DW_TAG_ptr_to_member_type: |
c906108c | 8539 | case DW_TAG_reference_type: |
4297a3f0 | 8540 | case DW_TAG_rvalue_reference_type: |
c906108c | 8541 | case DW_TAG_string_type: |
c906108c | 8542 | break; |
134d01f1 | 8543 | |
c906108c | 8544 | case DW_TAG_base_type: |
a02abb62 | 8545 | case DW_TAG_subrange_type: |
cb249c71 | 8546 | case DW_TAG_typedef: |
134d01f1 DJ |
8547 | /* Add a typedef symbol for the type definition, if it has a |
8548 | DW_AT_name. */ | |
f792889a | 8549 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 8550 | break; |
c906108c | 8551 | case DW_TAG_common_block: |
e7c27a73 | 8552 | read_common_block (die, cu); |
c906108c SS |
8553 | break; |
8554 | case DW_TAG_common_inclusion: | |
8555 | break; | |
d9fa45fe | 8556 | case DW_TAG_namespace: |
4d4ec4e5 | 8557 | cu->processing_has_namespace_info = 1; |
e7c27a73 | 8558 | read_namespace (die, cu); |
d9fa45fe | 8559 | break; |
5d7cb8df | 8560 | case DW_TAG_module: |
4d4ec4e5 | 8561 | cu->processing_has_namespace_info = 1; |
5d7cb8df JK |
8562 | read_module (die, cu); |
8563 | break; | |
d9fa45fe | 8564 | case DW_TAG_imported_declaration: |
74921315 KS |
8565 | cu->processing_has_namespace_info = 1; |
8566 | if (read_namespace_alias (die, cu)) | |
8567 | break; | |
8568 | /* The declaration is not a global namespace alias: fall through. */ | |
d9fa45fe | 8569 | case DW_TAG_imported_module: |
4d4ec4e5 | 8570 | cu->processing_has_namespace_info = 1; |
27aa8d6a SW |
8571 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
8572 | || cu->language != language_fortran)) | |
8573 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
8574 | dwarf_tag_name (die->tag)); | |
8575 | read_import_statement (die, cu); | |
d9fa45fe | 8576 | break; |
95554aad TT |
8577 | |
8578 | case DW_TAG_imported_unit: | |
8579 | process_imported_unit_die (die, cu); | |
8580 | break; | |
8581 | ||
c906108c | 8582 | default: |
e7c27a73 | 8583 | new_symbol (die, NULL, cu); |
c906108c SS |
8584 | break; |
8585 | } | |
adde2bff DE |
8586 | |
8587 | do_cleanups (in_process); | |
c906108c | 8588 | } |
ca69b9e6 DE |
8589 | \f |
8590 | /* DWARF name computation. */ | |
c906108c | 8591 | |
94af9270 KS |
8592 | /* A helper function for dwarf2_compute_name which determines whether DIE |
8593 | needs to have the name of the scope prepended to the name listed in the | |
8594 | die. */ | |
8595 | ||
8596 | static int | |
8597 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
8598 | { | |
1c809c68 TT |
8599 | struct attribute *attr; |
8600 | ||
94af9270 KS |
8601 | switch (die->tag) |
8602 | { | |
8603 | case DW_TAG_namespace: | |
8604 | case DW_TAG_typedef: | |
8605 | case DW_TAG_class_type: | |
8606 | case DW_TAG_interface_type: | |
8607 | case DW_TAG_structure_type: | |
8608 | case DW_TAG_union_type: | |
8609 | case DW_TAG_enumeration_type: | |
8610 | case DW_TAG_enumerator: | |
8611 | case DW_TAG_subprogram: | |
08a76f8a | 8612 | case DW_TAG_inlined_subroutine: |
94af9270 | 8613 | case DW_TAG_member: |
74921315 | 8614 | case DW_TAG_imported_declaration: |
94af9270 KS |
8615 | return 1; |
8616 | ||
8617 | case DW_TAG_variable: | |
c2b0a229 | 8618 | case DW_TAG_constant: |
94af9270 KS |
8619 | /* We only need to prefix "globally" visible variables. These include |
8620 | any variable marked with DW_AT_external or any variable that | |
8621 | lives in a namespace. [Variables in anonymous namespaces | |
8622 | require prefixing, but they are not DW_AT_external.] */ | |
8623 | ||
8624 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
8625 | { | |
8626 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 8627 | |
94af9270 KS |
8628 | return die_needs_namespace (die_specification (die, &spec_cu), |
8629 | spec_cu); | |
8630 | } | |
8631 | ||
1c809c68 | 8632 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
8633 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
8634 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
8635 | return 0; |
8636 | /* A variable in a lexical block of some kind does not need a | |
8637 | namespace, even though in C++ such variables may be external | |
8638 | and have a mangled name. */ | |
8639 | if (die->parent->tag == DW_TAG_lexical_block | |
8640 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
8641 | || die->parent->tag == DW_TAG_catch_block |
8642 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
8643 | return 0; |
8644 | return 1; | |
94af9270 KS |
8645 | |
8646 | default: | |
8647 | return 0; | |
8648 | } | |
8649 | } | |
8650 | ||
8651 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, | |
a766d390 | 8652 | compute the physname for the object, which include a method's: |
9c37b5ae | 8653 | - formal parameters (C++), |
a766d390 | 8654 | - receiver type (Go), |
a766d390 DE |
8655 | |
8656 | The term "physname" is a bit confusing. | |
8657 | For C++, for example, it is the demangled name. | |
8658 | For Go, for example, it's the mangled name. | |
94af9270 | 8659 | |
af6b7be1 JB |
8660 | For Ada, return the DIE's linkage name rather than the fully qualified |
8661 | name. PHYSNAME is ignored.. | |
8662 | ||
94af9270 KS |
8663 | The result is allocated on the objfile_obstack and canonicalized. */ |
8664 | ||
8665 | static const char * | |
15d034d0 TT |
8666 | dwarf2_compute_name (const char *name, |
8667 | struct die_info *die, struct dwarf2_cu *cu, | |
94af9270 KS |
8668 | int physname) |
8669 | { | |
bb5ed363 DE |
8670 | struct objfile *objfile = cu->objfile; |
8671 | ||
94af9270 KS |
8672 | if (name == NULL) |
8673 | name = dwarf2_name (die, cu); | |
8674 | ||
2ee7123e DE |
8675 | /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present |
8676 | but otherwise compute it by typename_concat inside GDB. | |
8677 | FIXME: Actually this is not really true, or at least not always true. | |
8678 | It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle | |
8679 | Fortran names because there is no mangling standard. So new_symbol_full | |
8680 | will set the demangled name to the result of dwarf2_full_name, and it is | |
8681 | the demangled name that GDB uses if it exists. */ | |
f55ee35c JK |
8682 | if (cu->language == language_ada |
8683 | || (cu->language == language_fortran && physname)) | |
8684 | { | |
8685 | /* For Ada unit, we prefer the linkage name over the name, as | |
8686 | the former contains the exported name, which the user expects | |
8687 | to be able to reference. Ideally, we want the user to be able | |
8688 | to reference this entity using either natural or linkage name, | |
8689 | but we haven't started looking at this enhancement yet. */ | |
2ee7123e | 8690 | const char *linkage_name; |
f55ee35c | 8691 | |
2ee7123e DE |
8692 | linkage_name = dwarf2_string_attr (die, DW_AT_linkage_name, cu); |
8693 | if (linkage_name == NULL) | |
8694 | linkage_name = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); | |
8695 | if (linkage_name != NULL) | |
8696 | return linkage_name; | |
f55ee35c JK |
8697 | } |
8698 | ||
94af9270 KS |
8699 | /* These are the only languages we know how to qualify names in. */ |
8700 | if (name != NULL | |
9c37b5ae | 8701 | && (cu->language == language_cplus |
c44af4eb TT |
8702 | || cu->language == language_fortran || cu->language == language_d |
8703 | || cu->language == language_rust)) | |
94af9270 KS |
8704 | { |
8705 | if (die_needs_namespace (die, cu)) | |
8706 | { | |
8707 | long length; | |
0d5cff50 | 8708 | const char *prefix; |
34a68019 | 8709 | const char *canonical_name = NULL; |
94af9270 | 8710 | |
d7e74731 PA |
8711 | string_file buf; |
8712 | ||
94af9270 | 8713 | prefix = determine_prefix (die, cu); |
94af9270 KS |
8714 | if (*prefix != '\0') |
8715 | { | |
f55ee35c JK |
8716 | char *prefixed_name = typename_concat (NULL, prefix, name, |
8717 | physname, cu); | |
9a619af0 | 8718 | |
d7e74731 | 8719 | buf.puts (prefixed_name); |
94af9270 KS |
8720 | xfree (prefixed_name); |
8721 | } | |
8722 | else | |
d7e74731 | 8723 | buf.puts (name); |
94af9270 | 8724 | |
98bfdba5 PA |
8725 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
8726 | as children with DW_TAG_template_type_param or | |
8727 | DW_TAG_value_type_param. If the latter, add them to the name | |
8728 | here. If the name already has template parameters, then | |
8729 | skip this step; some versions of GCC emit both, and | |
8730 | it is more efficient to use the pre-computed name. | |
8731 | ||
8732 | Something to keep in mind about this process: it is very | |
8733 | unlikely, or in some cases downright impossible, to produce | |
8734 | something that will match the mangled name of a function. | |
8735 | If the definition of the function has the same debug info, | |
8736 | we should be able to match up with it anyway. But fallbacks | |
8737 | using the minimal symbol, for instance to find a method | |
8738 | implemented in a stripped copy of libstdc++, will not work. | |
8739 | If we do not have debug info for the definition, we will have to | |
8740 | match them up some other way. | |
8741 | ||
8742 | When we do name matching there is a related problem with function | |
8743 | templates; two instantiated function templates are allowed to | |
8744 | differ only by their return types, which we do not add here. */ | |
8745 | ||
8746 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
8747 | { | |
8748 | struct attribute *attr; | |
8749 | struct die_info *child; | |
8750 | int first = 1; | |
8751 | ||
8752 | die->building_fullname = 1; | |
8753 | ||
8754 | for (child = die->child; child != NULL; child = child->sibling) | |
8755 | { | |
8756 | struct type *type; | |
12df843f | 8757 | LONGEST value; |
d521ce57 | 8758 | const gdb_byte *bytes; |
98bfdba5 PA |
8759 | struct dwarf2_locexpr_baton *baton; |
8760 | struct value *v; | |
8761 | ||
8762 | if (child->tag != DW_TAG_template_type_param | |
8763 | && child->tag != DW_TAG_template_value_param) | |
8764 | continue; | |
8765 | ||
8766 | if (first) | |
8767 | { | |
d7e74731 | 8768 | buf.puts ("<"); |
98bfdba5 PA |
8769 | first = 0; |
8770 | } | |
8771 | else | |
d7e74731 | 8772 | buf.puts (", "); |
98bfdba5 PA |
8773 | |
8774 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
8775 | if (attr == NULL) | |
8776 | { | |
8777 | complaint (&symfile_complaints, | |
8778 | _("template parameter missing DW_AT_type")); | |
d7e74731 | 8779 | buf.puts ("UNKNOWN_TYPE"); |
98bfdba5 PA |
8780 | continue; |
8781 | } | |
8782 | type = die_type (child, cu); | |
8783 | ||
8784 | if (child->tag == DW_TAG_template_type_param) | |
8785 | { | |
d7e74731 | 8786 | c_print_type (type, "", &buf, -1, 0, &type_print_raw_options); |
98bfdba5 PA |
8787 | continue; |
8788 | } | |
8789 | ||
8790 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
8791 | if (attr == NULL) | |
8792 | { | |
8793 | complaint (&symfile_complaints, | |
3e43a32a MS |
8794 | _("template parameter missing " |
8795 | "DW_AT_const_value")); | |
d7e74731 | 8796 | buf.puts ("UNKNOWN_VALUE"); |
98bfdba5 PA |
8797 | continue; |
8798 | } | |
8799 | ||
8800 | dwarf2_const_value_attr (attr, type, name, | |
8801 | &cu->comp_unit_obstack, cu, | |
8802 | &value, &bytes, &baton); | |
8803 | ||
8804 | if (TYPE_NOSIGN (type)) | |
8805 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
8806 | changed, this can use value_print instead. */ | |
d7e74731 | 8807 | c_printchar (value, type, &buf); |
98bfdba5 PA |
8808 | else |
8809 | { | |
8810 | struct value_print_options opts; | |
8811 | ||
8812 | if (baton != NULL) | |
8813 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
8814 | baton->data, | |
8815 | baton->size, | |
8816 | baton->per_cu); | |
8817 | else if (bytes != NULL) | |
8818 | { | |
8819 | v = allocate_value (type); | |
8820 | memcpy (value_contents_writeable (v), bytes, | |
8821 | TYPE_LENGTH (type)); | |
8822 | } | |
8823 | else | |
8824 | v = value_from_longest (type, value); | |
8825 | ||
3e43a32a MS |
8826 | /* Specify decimal so that we do not depend on |
8827 | the radix. */ | |
98bfdba5 PA |
8828 | get_formatted_print_options (&opts, 'd'); |
8829 | opts.raw = 1; | |
d7e74731 | 8830 | value_print (v, &buf, &opts); |
98bfdba5 PA |
8831 | release_value (v); |
8832 | value_free (v); | |
8833 | } | |
8834 | } | |
8835 | ||
8836 | die->building_fullname = 0; | |
8837 | ||
8838 | if (!first) | |
8839 | { | |
8840 | /* Close the argument list, with a space if necessary | |
8841 | (nested templates). */ | |
d7e74731 PA |
8842 | if (!buf.empty () && buf.string ().back () == '>') |
8843 | buf.puts (" >"); | |
98bfdba5 | 8844 | else |
d7e74731 | 8845 | buf.puts (">"); |
98bfdba5 PA |
8846 | } |
8847 | } | |
8848 | ||
9c37b5ae | 8849 | /* For C++ methods, append formal parameter type |
94af9270 | 8850 | information, if PHYSNAME. */ |
6e70227d | 8851 | |
94af9270 | 8852 | if (physname && die->tag == DW_TAG_subprogram |
9c37b5ae | 8853 | && cu->language == language_cplus) |
94af9270 KS |
8854 | { |
8855 | struct type *type = read_type_die (die, cu); | |
8856 | ||
d7e74731 | 8857 | c_type_print_args (type, &buf, 1, cu->language, |
79d43c61 | 8858 | &type_print_raw_options); |
94af9270 | 8859 | |
9c37b5ae | 8860 | if (cu->language == language_cplus) |
94af9270 | 8861 | { |
60430eff DJ |
8862 | /* Assume that an artificial first parameter is |
8863 | "this", but do not crash if it is not. RealView | |
8864 | marks unnamed (and thus unused) parameters as | |
8865 | artificial; there is no way to differentiate | |
8866 | the two cases. */ | |
94af9270 KS |
8867 | if (TYPE_NFIELDS (type) > 0 |
8868 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 8869 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
8870 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
8871 | 0)))) | |
d7e74731 | 8872 | buf.puts (" const"); |
94af9270 KS |
8873 | } |
8874 | } | |
8875 | ||
d7e74731 | 8876 | const std::string &intermediate_name = buf.string (); |
94af9270 KS |
8877 | |
8878 | if (cu->language == language_cplus) | |
34a68019 | 8879 | canonical_name |
322a8516 | 8880 | = dwarf2_canonicalize_name (intermediate_name.c_str (), cu, |
34a68019 TT |
8881 | &objfile->per_bfd->storage_obstack); |
8882 | ||
8883 | /* If we only computed INTERMEDIATE_NAME, or if | |
8884 | INTERMEDIATE_NAME is already canonical, then we need to | |
8885 | copy it to the appropriate obstack. */ | |
322a8516 | 8886 | if (canonical_name == NULL || canonical_name == intermediate_name.c_str ()) |
224c3ddb SM |
8887 | name = ((const char *) |
8888 | obstack_copy0 (&objfile->per_bfd->storage_obstack, | |
322a8516 PA |
8889 | intermediate_name.c_str (), |
8890 | intermediate_name.length ())); | |
34a68019 TT |
8891 | else |
8892 | name = canonical_name; | |
94af9270 KS |
8893 | } |
8894 | } | |
8895 | ||
8896 | return name; | |
8897 | } | |
8898 | ||
0114d602 DJ |
8899 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
8900 | If scope qualifiers are appropriate they will be added. The result | |
34a68019 | 8901 | will be allocated on the storage_obstack, or NULL if the DIE does |
94af9270 KS |
8902 | not have a name. NAME may either be from a previous call to |
8903 | dwarf2_name or NULL. | |
8904 | ||
9c37b5ae | 8905 | The output string will be canonicalized (if C++). */ |
0114d602 DJ |
8906 | |
8907 | static const char * | |
15d034d0 | 8908 | dwarf2_full_name (const char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 8909 | { |
94af9270 KS |
8910 | return dwarf2_compute_name (name, die, cu, 0); |
8911 | } | |
0114d602 | 8912 | |
94af9270 KS |
8913 | /* Construct a physname for the given DIE in CU. NAME may either be |
8914 | from a previous call to dwarf2_name or NULL. The result will be | |
8915 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
8916 | name. | |
0114d602 | 8917 | |
9c37b5ae | 8918 | The output string will be canonicalized (if C++). */ |
0114d602 | 8919 | |
94af9270 | 8920 | static const char * |
15d034d0 | 8921 | dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu) |
94af9270 | 8922 | { |
bb5ed363 | 8923 | struct objfile *objfile = cu->objfile; |
900e11f9 JK |
8924 | const char *retval, *mangled = NULL, *canon = NULL; |
8925 | struct cleanup *back_to; | |
8926 | int need_copy = 1; | |
8927 | ||
8928 | /* In this case dwarf2_compute_name is just a shortcut not building anything | |
8929 | on its own. */ | |
8930 | if (!die_needs_namespace (die, cu)) | |
8931 | return dwarf2_compute_name (name, die, cu, 1); | |
8932 | ||
8933 | back_to = make_cleanup (null_cleanup, NULL); | |
8934 | ||
7d45c7c3 KB |
8935 | mangled = dwarf2_string_attr (die, DW_AT_linkage_name, cu); |
8936 | if (mangled == NULL) | |
8937 | mangled = dwarf2_string_attr (die, DW_AT_MIPS_linkage_name, cu); | |
900e11f9 | 8938 | |
e98c9e7c TT |
8939 | /* rustc emits invalid values for DW_AT_linkage_name. Ignore these. |
8940 | See https://github.com/rust-lang/rust/issues/32925. */ | |
8941 | if (cu->language == language_rust && mangled != NULL | |
8942 | && strchr (mangled, '{') != NULL) | |
8943 | mangled = NULL; | |
8944 | ||
900e11f9 JK |
8945 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB |
8946 | has computed. */ | |
7d45c7c3 | 8947 | if (mangled != NULL) |
900e11f9 JK |
8948 | { |
8949 | char *demangled; | |
8950 | ||
900e11f9 JK |
8951 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return |
8952 | type. It is easier for GDB users to search for such functions as | |
8953 | `name(params)' than `long name(params)'. In such case the minimal | |
8954 | symbol names do not match the full symbol names but for template | |
8955 | functions there is never a need to look up their definition from their | |
8956 | declaration so the only disadvantage remains the minimal symbol | |
8957 | variant `long name(params)' does not have the proper inferior type. | |
8958 | */ | |
8959 | ||
a766d390 DE |
8960 | if (cu->language == language_go) |
8961 | { | |
8962 | /* This is a lie, but we already lie to the caller new_symbol_full. | |
8963 | new_symbol_full assumes we return the mangled name. | |
8964 | This just undoes that lie until things are cleaned up. */ | |
8965 | demangled = NULL; | |
8966 | } | |
8967 | else | |
8968 | { | |
8de20a37 | 8969 | demangled = gdb_demangle (mangled, |
9c37b5ae | 8970 | (DMGL_PARAMS | DMGL_ANSI | DMGL_RET_DROP)); |
a766d390 | 8971 | } |
900e11f9 JK |
8972 | if (demangled) |
8973 | { | |
8974 | make_cleanup (xfree, demangled); | |
8975 | canon = demangled; | |
8976 | } | |
8977 | else | |
8978 | { | |
8979 | canon = mangled; | |
8980 | need_copy = 0; | |
8981 | } | |
8982 | } | |
8983 | ||
8984 | if (canon == NULL || check_physname) | |
8985 | { | |
8986 | const char *physname = dwarf2_compute_name (name, die, cu, 1); | |
8987 | ||
8988 | if (canon != NULL && strcmp (physname, canon) != 0) | |
8989 | { | |
8990 | /* It may not mean a bug in GDB. The compiler could also | |
8991 | compute DW_AT_linkage_name incorrectly. But in such case | |
8992 | GDB would need to be bug-to-bug compatible. */ | |
8993 | ||
8994 | complaint (&symfile_complaints, | |
8995 | _("Computed physname <%s> does not match demangled <%s> " | |
8996 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), | |
9c541725 | 8997 | physname, canon, mangled, to_underlying (die->sect_off), |
4262abfb | 8998 | objfile_name (objfile)); |
900e11f9 JK |
8999 | |
9000 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it | |
9001 | is available here - over computed PHYSNAME. It is safer | |
9002 | against both buggy GDB and buggy compilers. */ | |
9003 | ||
9004 | retval = canon; | |
9005 | } | |
9006 | else | |
9007 | { | |
9008 | retval = physname; | |
9009 | need_copy = 0; | |
9010 | } | |
9011 | } | |
9012 | else | |
9013 | retval = canon; | |
9014 | ||
9015 | if (need_copy) | |
224c3ddb SM |
9016 | retval = ((const char *) |
9017 | obstack_copy0 (&objfile->per_bfd->storage_obstack, | |
9018 | retval, strlen (retval))); | |
900e11f9 JK |
9019 | |
9020 | do_cleanups (back_to); | |
9021 | return retval; | |
0114d602 DJ |
9022 | } |
9023 | ||
74921315 KS |
9024 | /* Inspect DIE in CU for a namespace alias. If one exists, record |
9025 | a new symbol for it. | |
9026 | ||
9027 | Returns 1 if a namespace alias was recorded, 0 otherwise. */ | |
9028 | ||
9029 | static int | |
9030 | read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu) | |
9031 | { | |
9032 | struct attribute *attr; | |
9033 | ||
9034 | /* If the die does not have a name, this is not a namespace | |
9035 | alias. */ | |
9036 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
9037 | if (attr != NULL) | |
9038 | { | |
9039 | int num; | |
9040 | struct die_info *d = die; | |
9041 | struct dwarf2_cu *imported_cu = cu; | |
9042 | ||
9043 | /* If the compiler has nested DW_AT_imported_declaration DIEs, | |
9044 | keep inspecting DIEs until we hit the underlying import. */ | |
9045 | #define MAX_NESTED_IMPORTED_DECLARATIONS 100 | |
9046 | for (num = 0; num < MAX_NESTED_IMPORTED_DECLARATIONS; ++num) | |
9047 | { | |
9048 | attr = dwarf2_attr (d, DW_AT_import, cu); | |
9049 | if (attr == NULL) | |
9050 | break; | |
9051 | ||
9052 | d = follow_die_ref (d, attr, &imported_cu); | |
9053 | if (d->tag != DW_TAG_imported_declaration) | |
9054 | break; | |
9055 | } | |
9056 | ||
9057 | if (num == MAX_NESTED_IMPORTED_DECLARATIONS) | |
9058 | { | |
9059 | complaint (&symfile_complaints, | |
9060 | _("DIE at 0x%x has too many recursively imported " | |
9c541725 | 9061 | "declarations"), to_underlying (d->sect_off)); |
74921315 KS |
9062 | return 0; |
9063 | } | |
9064 | ||
9065 | if (attr != NULL) | |
9066 | { | |
9067 | struct type *type; | |
9c541725 | 9068 | sect_offset sect_off = dwarf2_get_ref_die_offset (attr); |
74921315 | 9069 | |
9c541725 | 9070 | type = get_die_type_at_offset (sect_off, cu->per_cu); |
74921315 KS |
9071 | if (type != NULL && TYPE_CODE (type) == TYPE_CODE_NAMESPACE) |
9072 | { | |
9073 | /* This declaration is a global namespace alias. Add | |
9074 | a symbol for it whose type is the aliased namespace. */ | |
9075 | new_symbol (die, type, cu); | |
9076 | return 1; | |
9077 | } | |
9078 | } | |
9079 | } | |
9080 | ||
9081 | return 0; | |
9082 | } | |
9083 | ||
22cee43f PMR |
9084 | /* Return the using directives repository (global or local?) to use in the |
9085 | current context for LANGUAGE. | |
9086 | ||
9087 | For Ada, imported declarations can materialize renamings, which *may* be | |
9088 | global. However it is impossible (for now?) in DWARF to distinguish | |
9089 | "external" imported declarations and "static" ones. As all imported | |
9090 | declarations seem to be static in all other languages, make them all CU-wide | |
9091 | global only in Ada. */ | |
9092 | ||
9093 | static struct using_direct ** | |
9094 | using_directives (enum language language) | |
9095 | { | |
9096 | if (language == language_ada && context_stack_depth == 0) | |
9097 | return &global_using_directives; | |
9098 | else | |
9099 | return &local_using_directives; | |
9100 | } | |
9101 | ||
27aa8d6a SW |
9102 | /* Read the import statement specified by the given die and record it. */ |
9103 | ||
9104 | static void | |
9105 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
9106 | { | |
bb5ed363 | 9107 | struct objfile *objfile = cu->objfile; |
27aa8d6a | 9108 | struct attribute *import_attr; |
32019081 | 9109 | struct die_info *imported_die, *child_die; |
de4affc9 | 9110 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 9111 | const char *imported_name; |
794684b6 | 9112 | const char *imported_name_prefix; |
13387711 SW |
9113 | const char *canonical_name; |
9114 | const char *import_alias; | |
9115 | const char *imported_declaration = NULL; | |
794684b6 | 9116 | const char *import_prefix; |
32019081 JK |
9117 | VEC (const_char_ptr) *excludes = NULL; |
9118 | struct cleanup *cleanups; | |
13387711 | 9119 | |
27aa8d6a SW |
9120 | import_attr = dwarf2_attr (die, DW_AT_import, cu); |
9121 | if (import_attr == NULL) | |
9122 | { | |
9123 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
9124 | dwarf_tag_name (die->tag)); | |
9125 | return; | |
9126 | } | |
9127 | ||
de4affc9 CC |
9128 | imported_cu = cu; |
9129 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
9130 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
9131 | if (imported_name == NULL) |
9132 | { | |
9133 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
9134 | ||
9135 | The import in the following code: | |
9136 | namespace A | |
9137 | { | |
9138 | typedef int B; | |
9139 | } | |
9140 | ||
9141 | int main () | |
9142 | { | |
9143 | using A::B; | |
9144 | B b; | |
9145 | return b; | |
9146 | } | |
9147 | ||
9148 | ... | |
9149 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
9150 | <52> DW_AT_decl_file : 1 | |
9151 | <53> DW_AT_decl_line : 6 | |
9152 | <54> DW_AT_import : <0x75> | |
9153 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
9154 | <59> DW_AT_name : B | |
9155 | <5b> DW_AT_decl_file : 1 | |
9156 | <5c> DW_AT_decl_line : 2 | |
9157 | <5d> DW_AT_type : <0x6e> | |
9158 | ... | |
9159 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
9160 | <76> DW_AT_byte_size : 4 | |
9161 | <77> DW_AT_encoding : 5 (signed) | |
9162 | ||
9163 | imports the wrong die ( 0x75 instead of 0x58 ). | |
9164 | This case will be ignored until the gcc bug is fixed. */ | |
9165 | return; | |
9166 | } | |
9167 | ||
82856980 SW |
9168 | /* Figure out the local name after import. */ |
9169 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 9170 | |
794684b6 SW |
9171 | /* Figure out where the statement is being imported to. */ |
9172 | import_prefix = determine_prefix (die, cu); | |
9173 | ||
9174 | /* Figure out what the scope of the imported die is and prepend it | |
9175 | to the name of the imported die. */ | |
de4affc9 | 9176 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 9177 | |
f55ee35c JK |
9178 | if (imported_die->tag != DW_TAG_namespace |
9179 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 9180 | { |
13387711 SW |
9181 | imported_declaration = imported_name; |
9182 | canonical_name = imported_name_prefix; | |
794684b6 | 9183 | } |
13387711 | 9184 | else if (strlen (imported_name_prefix) > 0) |
12aaed36 | 9185 | canonical_name = obconcat (&objfile->objfile_obstack, |
45280282 IB |
9186 | imported_name_prefix, |
9187 | (cu->language == language_d ? "." : "::"), | |
9188 | imported_name, (char *) NULL); | |
13387711 SW |
9189 | else |
9190 | canonical_name = imported_name; | |
794684b6 | 9191 | |
32019081 JK |
9192 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
9193 | ||
9194 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) | |
9195 | for (child_die = die->child; child_die && child_die->tag; | |
9196 | child_die = sibling_die (child_die)) | |
9197 | { | |
9198 | /* DWARF-4: A Fortran use statement with a “rename list” may be | |
9199 | represented by an imported module entry with an import attribute | |
9200 | referring to the module and owned entries corresponding to those | |
9201 | entities that are renamed as part of being imported. */ | |
9202 | ||
9203 | if (child_die->tag != DW_TAG_imported_declaration) | |
9204 | { | |
9205 | complaint (&symfile_complaints, | |
9206 | _("child DW_TAG_imported_declaration expected " | |
9207 | "- DIE at 0x%x [in module %s]"), | |
9c541725 | 9208 | to_underlying (child_die->sect_off), objfile_name (objfile)); |
32019081 JK |
9209 | continue; |
9210 | } | |
9211 | ||
9212 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); | |
9213 | if (import_attr == NULL) | |
9214 | { | |
9215 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
9216 | dwarf_tag_name (child_die->tag)); | |
9217 | continue; | |
9218 | } | |
9219 | ||
9220 | imported_cu = cu; | |
9221 | imported_die = follow_die_ref_or_sig (child_die, import_attr, | |
9222 | &imported_cu); | |
9223 | imported_name = dwarf2_name (imported_die, imported_cu); | |
9224 | if (imported_name == NULL) | |
9225 | { | |
9226 | complaint (&symfile_complaints, | |
9227 | _("child DW_TAG_imported_declaration has unknown " | |
9228 | "imported name - DIE at 0x%x [in module %s]"), | |
9c541725 | 9229 | to_underlying (child_die->sect_off), objfile_name (objfile)); |
32019081 JK |
9230 | continue; |
9231 | } | |
9232 | ||
9233 | VEC_safe_push (const_char_ptr, excludes, imported_name); | |
9234 | ||
9235 | process_die (child_die, cu); | |
9236 | } | |
9237 | ||
22cee43f PMR |
9238 | add_using_directive (using_directives (cu->language), |
9239 | import_prefix, | |
9240 | canonical_name, | |
9241 | import_alias, | |
9242 | imported_declaration, | |
9243 | excludes, | |
9244 | 0, | |
9245 | &objfile->objfile_obstack); | |
32019081 JK |
9246 | |
9247 | do_cleanups (cleanups); | |
27aa8d6a SW |
9248 | } |
9249 | ||
1b80a9fa JK |
9250 | /* Check for possibly missing DW_AT_comp_dir with relative .debug_line |
9251 | directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed | |
9252 | this, it was first present in GCC release 4.3.0. */ | |
9253 | ||
9254 | static int | |
9255 | producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu) | |
9256 | { | |
9257 | if (!cu->checked_producer) | |
9258 | check_producer (cu); | |
9259 | ||
9260 | return cu->producer_is_gcc_lt_4_3; | |
9261 | } | |
9262 | ||
d721ba37 PA |
9263 | static file_and_directory |
9264 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) | |
9291a0cd | 9265 | { |
d721ba37 PA |
9266 | file_and_directory res; |
9267 | ||
9291a0cd TT |
9268 | /* Find the filename. Do not use dwarf2_name here, since the filename |
9269 | is not a source language identifier. */ | |
d721ba37 PA |
9270 | res.name = dwarf2_string_attr (die, DW_AT_name, cu); |
9271 | res.comp_dir = dwarf2_string_attr (die, DW_AT_comp_dir, cu); | |
9291a0cd | 9272 | |
d721ba37 PA |
9273 | if (res.comp_dir == NULL |
9274 | && producer_is_gcc_lt_4_3 (cu) && res.name != NULL | |
9275 | && IS_ABSOLUTE_PATH (res.name)) | |
9291a0cd | 9276 | { |
d721ba37 PA |
9277 | res.comp_dir_storage = ldirname (res.name); |
9278 | if (!res.comp_dir_storage.empty ()) | |
9279 | res.comp_dir = res.comp_dir_storage.c_str (); | |
9291a0cd | 9280 | } |
d721ba37 | 9281 | if (res.comp_dir != NULL) |
9291a0cd TT |
9282 | { |
9283 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
9284 | directory, get rid of it. */ | |
d721ba37 | 9285 | const char *cp = strchr (res.comp_dir, ':'); |
9291a0cd | 9286 | |
d721ba37 PA |
9287 | if (cp && cp != res.comp_dir && cp[-1] == '.' && cp[1] == '/') |
9288 | res.comp_dir = cp + 1; | |
9291a0cd TT |
9289 | } |
9290 | ||
d721ba37 PA |
9291 | if (res.name == NULL) |
9292 | res.name = "<unknown>"; | |
9293 | ||
9294 | return res; | |
9291a0cd TT |
9295 | } |
9296 | ||
f4dc4d17 DE |
9297 | /* Handle DW_AT_stmt_list for a compilation unit. |
9298 | DIE is the DW_TAG_compile_unit die for CU. | |
c3b7b696 YQ |
9299 | COMP_DIR is the compilation directory. LOWPC is passed to |
9300 | dwarf_decode_lines. See dwarf_decode_lines comments about it. */ | |
2ab95328 TT |
9301 | |
9302 | static void | |
9303 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, | |
c3b7b696 | 9304 | const char *comp_dir, CORE_ADDR lowpc) /* ARI: editCase function */ |
2ab95328 | 9305 | { |
527f3840 | 9306 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
2ab95328 | 9307 | struct attribute *attr; |
527f3840 JK |
9308 | struct line_header line_header_local; |
9309 | hashval_t line_header_local_hash; | |
9310 | unsigned u; | |
9311 | void **slot; | |
9312 | int decode_mapping; | |
2ab95328 | 9313 | |
f4dc4d17 DE |
9314 | gdb_assert (! cu->per_cu->is_debug_types); |
9315 | ||
2ab95328 | 9316 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
527f3840 JK |
9317 | if (attr == NULL) |
9318 | return; | |
9319 | ||
9c541725 | 9320 | sect_offset line_offset = (sect_offset) DW_UNSND (attr); |
527f3840 JK |
9321 | |
9322 | /* The line header hash table is only created if needed (it exists to | |
9323 | prevent redundant reading of the line table for partial_units). | |
9324 | If we're given a partial_unit, we'll need it. If we're given a | |
9325 | compile_unit, then use the line header hash table if it's already | |
9326 | created, but don't create one just yet. */ | |
9327 | ||
9328 | if (dwarf2_per_objfile->line_header_hash == NULL | |
9329 | && die->tag == DW_TAG_partial_unit) | |
2ab95328 | 9330 | { |
527f3840 JK |
9331 | dwarf2_per_objfile->line_header_hash |
9332 | = htab_create_alloc_ex (127, line_header_hash_voidp, | |
9333 | line_header_eq_voidp, | |
9334 | free_line_header_voidp, | |
9335 | &objfile->objfile_obstack, | |
9336 | hashtab_obstack_allocate, | |
9337 | dummy_obstack_deallocate); | |
9338 | } | |
2ab95328 | 9339 | |
9c541725 | 9340 | line_header_local.sect_off = line_offset; |
527f3840 JK |
9341 | line_header_local.offset_in_dwz = cu->per_cu->is_dwz; |
9342 | line_header_local_hash = line_header_hash (&line_header_local); | |
9343 | if (dwarf2_per_objfile->line_header_hash != NULL) | |
9344 | { | |
9345 | slot = htab_find_slot_with_hash (dwarf2_per_objfile->line_header_hash, | |
9346 | &line_header_local, | |
9347 | line_header_local_hash, NO_INSERT); | |
9348 | ||
9349 | /* For DW_TAG_compile_unit we need info like symtab::linetable which | |
9350 | is not present in *SLOT (since if there is something in *SLOT then | |
9351 | it will be for a partial_unit). */ | |
9352 | if (die->tag == DW_TAG_partial_unit && slot != NULL) | |
dee91e82 | 9353 | { |
527f3840 | 9354 | gdb_assert (*slot != NULL); |
9a3c8263 | 9355 | cu->line_header = (struct line_header *) *slot; |
527f3840 | 9356 | return; |
dee91e82 | 9357 | } |
2ab95328 | 9358 | } |
527f3840 JK |
9359 | |
9360 | /* dwarf_decode_line_header does not yet provide sufficient information. | |
9361 | We always have to call also dwarf_decode_lines for it. */ | |
fff8551c PA |
9362 | line_header_up lh = dwarf_decode_line_header (line_offset, cu); |
9363 | if (lh == NULL) | |
527f3840 | 9364 | return; |
fff8551c | 9365 | cu->line_header = lh.get (); |
527f3840 JK |
9366 | |
9367 | if (dwarf2_per_objfile->line_header_hash == NULL) | |
9368 | slot = NULL; | |
9369 | else | |
9370 | { | |
9371 | slot = htab_find_slot_with_hash (dwarf2_per_objfile->line_header_hash, | |
9372 | &line_header_local, | |
9373 | line_header_local_hash, INSERT); | |
9374 | gdb_assert (slot != NULL); | |
9375 | } | |
9376 | if (slot != NULL && *slot == NULL) | |
9377 | { | |
9378 | /* This newly decoded line number information unit will be owned | |
9379 | by line_header_hash hash table. */ | |
9380 | *slot = cu->line_header; | |
9381 | } | |
9382 | else | |
9383 | { | |
9384 | /* We cannot free any current entry in (*slot) as that struct line_header | |
9385 | may be already used by multiple CUs. Create only temporary decoded | |
9386 | line_header for this CU - it may happen at most once for each line | |
9387 | number information unit. And if we're not using line_header_hash | |
9388 | then this is what we want as well. */ | |
9389 | gdb_assert (die->tag != DW_TAG_partial_unit); | |
527f3840 JK |
9390 | } |
9391 | decode_mapping = (die->tag != DW_TAG_partial_unit); | |
9392 | dwarf_decode_lines (cu->line_header, comp_dir, cu, NULL, lowpc, | |
9393 | decode_mapping); | |
fff8551c PA |
9394 | |
9395 | lh.release (); | |
2ab95328 TT |
9396 | } |
9397 | ||
95554aad | 9398 | /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */ |
ae2de4f8 | 9399 | |
c906108c | 9400 | static void |
e7c27a73 | 9401 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9402 | { |
dee91e82 | 9403 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
3e29f34a | 9404 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
2acceee2 | 9405 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
9406 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
9407 | struct attribute *attr; | |
c906108c | 9408 | struct die_info *child_die; |
e142c38c | 9409 | CORE_ADDR baseaddr; |
6e70227d | 9410 | |
e142c38c | 9411 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 9412 | |
fae299cd | 9413 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
9414 | |
9415 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
9416 | from finish_block. */ | |
2acceee2 | 9417 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c | 9418 | lowpc = highpc; |
3e29f34a | 9419 | lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr); |
c906108c | 9420 | |
d721ba37 | 9421 | file_and_directory fnd = find_file_and_directory (die, cu); |
e1024ff1 | 9422 | |
95554aad | 9423 | prepare_one_comp_unit (cu, die, cu->language); |
303b6f5d | 9424 | |
f4b8a18d KW |
9425 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
9426 | standardised yet. As a workaround for the language detection we fall | |
9427 | back to the DW_AT_producer string. */ | |
9428 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
9429 | cu->language = language_opencl; | |
9430 | ||
3019eac3 DE |
9431 | /* Similar hack for Go. */ |
9432 | if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL) | |
9433 | set_cu_language (DW_LANG_Go, cu); | |
9434 | ||
d721ba37 | 9435 | dwarf2_start_symtab (cu, fnd.name, fnd.comp_dir, lowpc); |
3019eac3 DE |
9436 | |
9437 | /* Decode line number information if present. We do this before | |
9438 | processing child DIEs, so that the line header table is available | |
9439 | for DW_AT_decl_file. */ | |
d721ba37 | 9440 | handle_DW_AT_stmt_list (die, cu, fnd.comp_dir, lowpc); |
3019eac3 DE |
9441 | |
9442 | /* Process all dies in compilation unit. */ | |
9443 | if (die->child != NULL) | |
9444 | { | |
9445 | child_die = die->child; | |
9446 | while (child_die && child_die->tag) | |
9447 | { | |
9448 | process_die (child_die, cu); | |
9449 | child_die = sibling_die (child_die); | |
9450 | } | |
9451 | } | |
9452 | ||
9453 | /* Decode macro information, if present. Dwarf 2 macro information | |
9454 | refers to information in the line number info statement program | |
9455 | header, so we can only read it if we've read the header | |
9456 | successfully. */ | |
0af92d60 JK |
9457 | attr = dwarf2_attr (die, DW_AT_macros, cu); |
9458 | if (attr == NULL) | |
9459 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); | |
3019eac3 DE |
9460 | if (attr && cu->line_header) |
9461 | { | |
9462 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) | |
9463 | complaint (&symfile_complaints, | |
0af92d60 | 9464 | _("CU refers to both DW_AT_macros and DW_AT_macro_info")); |
3019eac3 | 9465 | |
43f3e411 | 9466 | dwarf_decode_macros (cu, DW_UNSND (attr), 1); |
3019eac3 DE |
9467 | } |
9468 | else | |
9469 | { | |
9470 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |
9471 | if (attr && cu->line_header) | |
9472 | { | |
9473 | unsigned int macro_offset = DW_UNSND (attr); | |
9474 | ||
43f3e411 | 9475 | dwarf_decode_macros (cu, macro_offset, 0); |
3019eac3 DE |
9476 | } |
9477 | } | |
3019eac3 DE |
9478 | } |
9479 | ||
f4dc4d17 DE |
9480 | /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope. |
9481 | Create the set of symtabs used by this TU, or if this TU is sharing | |
9482 | symtabs with another TU and the symtabs have already been created | |
9483 | then restore those symtabs in the line header. | |
9484 | We don't need the pc/line-number mapping for type units. */ | |
3019eac3 DE |
9485 | |
9486 | static void | |
f4dc4d17 | 9487 | setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu) |
3019eac3 | 9488 | { |
f4dc4d17 DE |
9489 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; |
9490 | struct type_unit_group *tu_group; | |
9491 | int first_time; | |
3019eac3 | 9492 | struct attribute *attr; |
9c541725 | 9493 | unsigned int i; |
0186c6a7 | 9494 | struct signatured_type *sig_type; |
3019eac3 | 9495 | |
f4dc4d17 | 9496 | gdb_assert (per_cu->is_debug_types); |
0186c6a7 | 9497 | sig_type = (struct signatured_type *) per_cu; |
3019eac3 | 9498 | |
f4dc4d17 | 9499 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
3019eac3 | 9500 | |
f4dc4d17 | 9501 | /* If we're using .gdb_index (includes -readnow) then |
74e04d1c | 9502 | per_cu->type_unit_group may not have been set up yet. */ |
0186c6a7 DE |
9503 | if (sig_type->type_unit_group == NULL) |
9504 | sig_type->type_unit_group = get_type_unit_group (cu, attr); | |
9505 | tu_group = sig_type->type_unit_group; | |
f4dc4d17 DE |
9506 | |
9507 | /* If we've already processed this stmt_list there's no real need to | |
9508 | do it again, we could fake it and just recreate the part we need | |
9509 | (file name,index -> symtab mapping). If data shows this optimization | |
9510 | is useful we can do it then. */ | |
43f3e411 | 9511 | first_time = tu_group->compunit_symtab == NULL; |
f4dc4d17 DE |
9512 | |
9513 | /* We have to handle the case of both a missing DW_AT_stmt_list or bad | |
9514 | debug info. */ | |
fff8551c | 9515 | line_header_up lh; |
f4dc4d17 | 9516 | if (attr != NULL) |
3019eac3 | 9517 | { |
9c541725 | 9518 | sect_offset line_offset = (sect_offset) DW_UNSND (attr); |
f4dc4d17 DE |
9519 | lh = dwarf_decode_line_header (line_offset, cu); |
9520 | } | |
9521 | if (lh == NULL) | |
9522 | { | |
9523 | if (first_time) | |
9524 | dwarf2_start_symtab (cu, "", NULL, 0); | |
9525 | else | |
9526 | { | |
9527 | gdb_assert (tu_group->symtabs == NULL); | |
0ab9ce85 | 9528 | restart_symtab (tu_group->compunit_symtab, "", 0); |
f4dc4d17 | 9529 | } |
f4dc4d17 | 9530 | return; |
3019eac3 DE |
9531 | } |
9532 | ||
fff8551c | 9533 | cu->line_header = lh.get (); |
3019eac3 | 9534 | |
f4dc4d17 DE |
9535 | if (first_time) |
9536 | { | |
43f3e411 | 9537 | struct compunit_symtab *cust = dwarf2_start_symtab (cu, "", NULL, 0); |
3019eac3 | 9538 | |
1fd60fc0 DE |
9539 | /* Note: We don't assign tu_group->compunit_symtab yet because we're |
9540 | still initializing it, and our caller (a few levels up) | |
9541 | process_full_type_unit still needs to know if this is the first | |
9542 | time. */ | |
9543 | ||
fff8551c PA |
9544 | tu_group->num_symtabs = lh->file_names.size (); |
9545 | tu_group->symtabs = XNEWVEC (struct symtab *, lh->file_names.size ()); | |
3019eac3 | 9546 | |
fff8551c | 9547 | for (i = 0; i < lh->file_names.size (); ++i) |
f4dc4d17 | 9548 | { |
8c43009f | 9549 | file_entry &fe = lh->file_names[i]; |
3019eac3 | 9550 | |
fff8551c | 9551 | dwarf2_start_subfile (fe.name, fe.include_dir (lh.get ())); |
3019eac3 | 9552 | |
f4dc4d17 DE |
9553 | if (current_subfile->symtab == NULL) |
9554 | { | |
9555 | /* NOTE: start_subfile will recognize when it's been passed | |
9556 | a file it has already seen. So we can't assume there's a | |
43f3e411 | 9557 | simple mapping from lh->file_names to subfiles, plus |
f4dc4d17 | 9558 | lh->file_names may contain dups. */ |
43f3e411 DE |
9559 | current_subfile->symtab |
9560 | = allocate_symtab (cust, current_subfile->name); | |
f4dc4d17 DE |
9561 | } |
9562 | ||
8c43009f PA |
9563 | fe.symtab = current_subfile->symtab; |
9564 | tu_group->symtabs[i] = fe.symtab; | |
f4dc4d17 DE |
9565 | } |
9566 | } | |
9567 | else | |
3019eac3 | 9568 | { |
0ab9ce85 | 9569 | restart_symtab (tu_group->compunit_symtab, "", 0); |
f4dc4d17 | 9570 | |
fff8551c | 9571 | for (i = 0; i < lh->file_names.size (); ++i) |
f4dc4d17 DE |
9572 | { |
9573 | struct file_entry *fe = &lh->file_names[i]; | |
9574 | ||
9575 | fe->symtab = tu_group->symtabs[i]; | |
9576 | } | |
3019eac3 DE |
9577 | } |
9578 | ||
fff8551c PA |
9579 | lh.release (); |
9580 | ||
f4dc4d17 DE |
9581 | /* The main symtab is allocated last. Type units don't have DW_AT_name |
9582 | so they don't have a "real" (so to speak) symtab anyway. | |
9583 | There is later code that will assign the main symtab to all symbols | |
9584 | that don't have one. We need to handle the case of a symbol with a | |
9585 | missing symtab (DW_AT_decl_file) anyway. */ | |
9586 | } | |
3019eac3 | 9587 | |
f4dc4d17 DE |
9588 | /* Process DW_TAG_type_unit. |
9589 | For TUs we want to skip the first top level sibling if it's not the | |
9590 | actual type being defined by this TU. In this case the first top | |
9591 | level sibling is there to provide context only. */ | |
3019eac3 | 9592 | |
f4dc4d17 DE |
9593 | static void |
9594 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
9595 | { | |
9596 | struct die_info *child_die; | |
3019eac3 | 9597 | |
f4dc4d17 DE |
9598 | prepare_one_comp_unit (cu, die, language_minimal); |
9599 | ||
9600 | /* Initialize (or reinitialize) the machinery for building symtabs. | |
9601 | We do this before processing child DIEs, so that the line header table | |
9602 | is available for DW_AT_decl_file. */ | |
9603 | setup_type_unit_groups (die, cu); | |
9604 | ||
9605 | if (die->child != NULL) | |
9606 | { | |
9607 | child_die = die->child; | |
9608 | while (child_die && child_die->tag) | |
9609 | { | |
9610 | process_die (child_die, cu); | |
9611 | child_die = sibling_die (child_die); | |
9612 | } | |
9613 | } | |
3019eac3 DE |
9614 | } |
9615 | \f | |
80626a55 DE |
9616 | /* DWO/DWP files. |
9617 | ||
9618 | http://gcc.gnu.org/wiki/DebugFission | |
9619 | http://gcc.gnu.org/wiki/DebugFissionDWP | |
9620 | ||
9621 | To simplify handling of both DWO files ("object" files with the DWARF info) | |
9622 | and DWP files (a file with the DWOs packaged up into one file), we treat | |
9623 | DWP files as having a collection of virtual DWO files. */ | |
3019eac3 DE |
9624 | |
9625 | static hashval_t | |
9626 | hash_dwo_file (const void *item) | |
9627 | { | |
9a3c8263 | 9628 | const struct dwo_file *dwo_file = (const struct dwo_file *) item; |
a2ce51a0 | 9629 | hashval_t hash; |
3019eac3 | 9630 | |
a2ce51a0 DE |
9631 | hash = htab_hash_string (dwo_file->dwo_name); |
9632 | if (dwo_file->comp_dir != NULL) | |
9633 | hash += htab_hash_string (dwo_file->comp_dir); | |
9634 | return hash; | |
3019eac3 DE |
9635 | } |
9636 | ||
9637 | static int | |
9638 | eq_dwo_file (const void *item_lhs, const void *item_rhs) | |
9639 | { | |
9a3c8263 SM |
9640 | const struct dwo_file *lhs = (const struct dwo_file *) item_lhs; |
9641 | const struct dwo_file *rhs = (const struct dwo_file *) item_rhs; | |
3019eac3 | 9642 | |
a2ce51a0 DE |
9643 | if (strcmp (lhs->dwo_name, rhs->dwo_name) != 0) |
9644 | return 0; | |
9645 | if (lhs->comp_dir == NULL || rhs->comp_dir == NULL) | |
9646 | return lhs->comp_dir == rhs->comp_dir; | |
9647 | return strcmp (lhs->comp_dir, rhs->comp_dir) == 0; | |
3019eac3 DE |
9648 | } |
9649 | ||
9650 | /* Allocate a hash table for DWO files. */ | |
9651 | ||
9652 | static htab_t | |
9653 | allocate_dwo_file_hash_table (void) | |
9654 | { | |
9655 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
9656 | ||
9657 | return htab_create_alloc_ex (41, | |
9658 | hash_dwo_file, | |
9659 | eq_dwo_file, | |
9660 | NULL, | |
9661 | &objfile->objfile_obstack, | |
9662 | hashtab_obstack_allocate, | |
9663 | dummy_obstack_deallocate); | |
9664 | } | |
9665 | ||
80626a55 DE |
9666 | /* Lookup DWO file DWO_NAME. */ |
9667 | ||
9668 | static void ** | |
0ac5b59e | 9669 | lookup_dwo_file_slot (const char *dwo_name, const char *comp_dir) |
80626a55 DE |
9670 | { |
9671 | struct dwo_file find_entry; | |
9672 | void **slot; | |
9673 | ||
9674 | if (dwarf2_per_objfile->dwo_files == NULL) | |
9675 | dwarf2_per_objfile->dwo_files = allocate_dwo_file_hash_table (); | |
9676 | ||
9677 | memset (&find_entry, 0, sizeof (find_entry)); | |
0ac5b59e DE |
9678 | find_entry.dwo_name = dwo_name; |
9679 | find_entry.comp_dir = comp_dir; | |
80626a55 DE |
9680 | slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT); |
9681 | ||
9682 | return slot; | |
9683 | } | |
9684 | ||
3019eac3 DE |
9685 | static hashval_t |
9686 | hash_dwo_unit (const void *item) | |
9687 | { | |
9a3c8263 | 9688 | const struct dwo_unit *dwo_unit = (const struct dwo_unit *) item; |
3019eac3 DE |
9689 | |
9690 | /* This drops the top 32 bits of the id, but is ok for a hash. */ | |
9691 | return dwo_unit->signature; | |
9692 | } | |
9693 | ||
9694 | static int | |
9695 | eq_dwo_unit (const void *item_lhs, const void *item_rhs) | |
9696 | { | |
9a3c8263 SM |
9697 | const struct dwo_unit *lhs = (const struct dwo_unit *) item_lhs; |
9698 | const struct dwo_unit *rhs = (const struct dwo_unit *) item_rhs; | |
3019eac3 DE |
9699 | |
9700 | /* The signature is assumed to be unique within the DWO file. | |
9701 | So while object file CU dwo_id's always have the value zero, | |
9702 | that's OK, assuming each object file DWO file has only one CU, | |
9703 | and that's the rule for now. */ | |
9704 | return lhs->signature == rhs->signature; | |
9705 | } | |
9706 | ||
9707 | /* Allocate a hash table for DWO CUs,TUs. | |
9708 | There is one of these tables for each of CUs,TUs for each DWO file. */ | |
9709 | ||
9710 | static htab_t | |
9711 | allocate_dwo_unit_table (struct objfile *objfile) | |
9712 | { | |
9713 | /* Start out with a pretty small number. | |
9714 | Generally DWO files contain only one CU and maybe some TUs. */ | |
9715 | return htab_create_alloc_ex (3, | |
9716 | hash_dwo_unit, | |
9717 | eq_dwo_unit, | |
9718 | NULL, | |
9719 | &objfile->objfile_obstack, | |
9720 | hashtab_obstack_allocate, | |
9721 | dummy_obstack_deallocate); | |
9722 | } | |
9723 | ||
80626a55 | 9724 | /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */ |
3019eac3 | 9725 | |
19c3d4c9 | 9726 | struct create_dwo_cu_data |
3019eac3 DE |
9727 | { |
9728 | struct dwo_file *dwo_file; | |
19c3d4c9 | 9729 | struct dwo_unit dwo_unit; |
3019eac3 DE |
9730 | }; |
9731 | ||
19c3d4c9 | 9732 | /* die_reader_func for create_dwo_cu. */ |
3019eac3 DE |
9733 | |
9734 | static void | |
19c3d4c9 DE |
9735 | create_dwo_cu_reader (const struct die_reader_specs *reader, |
9736 | const gdb_byte *info_ptr, | |
9737 | struct die_info *comp_unit_die, | |
9738 | int has_children, | |
9739 | void *datap) | |
3019eac3 DE |
9740 | { |
9741 | struct dwarf2_cu *cu = reader->cu; | |
9c541725 | 9742 | sect_offset sect_off = cu->per_cu->sect_off; |
8a0459fd | 9743 | struct dwarf2_section_info *section = cu->per_cu->section; |
9a3c8263 | 9744 | struct create_dwo_cu_data *data = (struct create_dwo_cu_data *) datap; |
3019eac3 | 9745 | struct dwo_file *dwo_file = data->dwo_file; |
19c3d4c9 | 9746 | struct dwo_unit *dwo_unit = &data->dwo_unit; |
3019eac3 | 9747 | struct attribute *attr; |
3019eac3 DE |
9748 | |
9749 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); | |
9750 | if (attr == NULL) | |
9751 | { | |
19c3d4c9 DE |
9752 | complaint (&symfile_complaints, |
9753 | _("Dwarf Error: debug entry at offset 0x%x is missing" | |
9754 | " its dwo_id [in module %s]"), | |
9c541725 | 9755 | to_underlying (sect_off), dwo_file->dwo_name); |
3019eac3 DE |
9756 | return; |
9757 | } | |
9758 | ||
3019eac3 DE |
9759 | dwo_unit->dwo_file = dwo_file; |
9760 | dwo_unit->signature = DW_UNSND (attr); | |
8a0459fd | 9761 | dwo_unit->section = section; |
9c541725 | 9762 | dwo_unit->sect_off = sect_off; |
3019eac3 DE |
9763 | dwo_unit->length = cu->per_cu->length; |
9764 | ||
b4f54984 | 9765 | if (dwarf_read_debug) |
4031ecc5 | 9766 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, dwo_id %s\n", |
9c541725 PA |
9767 | to_underlying (sect_off), |
9768 | hex_string (dwo_unit->signature)); | |
3019eac3 DE |
9769 | } |
9770 | ||
33c5cd75 | 9771 | /* Create the dwo_units for the CUs in a DWO_FILE. |
19c3d4c9 | 9772 | Note: This function processes DWO files only, not DWP files. */ |
3019eac3 | 9773 | |
33c5cd75 DB |
9774 | static void |
9775 | create_cus_hash_table (struct dwo_file &dwo_file, dwarf2_section_info §ion, | |
9776 | htab_t &cus_htab) | |
3019eac3 DE |
9777 | { |
9778 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
33c5cd75 | 9779 | const struct dwarf2_section_info *abbrev_section = &dwo_file.sections.abbrev; |
d521ce57 | 9780 | const gdb_byte *info_ptr, *end_ptr; |
3019eac3 | 9781 | |
33c5cd75 DB |
9782 | dwarf2_read_section (objfile, §ion); |
9783 | info_ptr = section.buffer; | |
3019eac3 DE |
9784 | |
9785 | if (info_ptr == NULL) | |
33c5cd75 | 9786 | return; |
3019eac3 | 9787 | |
b4f54984 | 9788 | if (dwarf_read_debug) |
19c3d4c9 DE |
9789 | { |
9790 | fprintf_unfiltered (gdb_stdlog, "Reading %s for %s:\n", | |
33c5cd75 DB |
9791 | get_section_name (§ion), |
9792 | get_section_file_name (§ion)); | |
19c3d4c9 | 9793 | } |
3019eac3 | 9794 | |
33c5cd75 | 9795 | end_ptr = info_ptr + section.size; |
3019eac3 DE |
9796 | while (info_ptr < end_ptr) |
9797 | { | |
9798 | struct dwarf2_per_cu_data per_cu; | |
33c5cd75 DB |
9799 | struct create_dwo_cu_data create_dwo_cu_data; |
9800 | struct dwo_unit *dwo_unit; | |
9801 | void **slot; | |
9802 | sect_offset sect_off = (sect_offset) (info_ptr - section.buffer); | |
3019eac3 | 9803 | |
19c3d4c9 DE |
9804 | memset (&create_dwo_cu_data.dwo_unit, 0, |
9805 | sizeof (create_dwo_cu_data.dwo_unit)); | |
3019eac3 DE |
9806 | memset (&per_cu, 0, sizeof (per_cu)); |
9807 | per_cu.objfile = objfile; | |
9808 | per_cu.is_debug_types = 0; | |
33c5cd75 DB |
9809 | per_cu.sect_off = sect_offset (info_ptr - section.buffer); |
9810 | per_cu.section = §ion; | |
c5ed0576 | 9811 | create_dwo_cu_data.dwo_file = &dwo_file; |
33c5cd75 DB |
9812 | |
9813 | init_cutu_and_read_dies_no_follow ( | |
9814 | &per_cu, &dwo_file, create_dwo_cu_reader, &create_dwo_cu_data); | |
9815 | info_ptr += per_cu.length; | |
9816 | ||
9817 | // If the unit could not be parsed, skip it. | |
9818 | if (create_dwo_cu_data.dwo_unit.dwo_file == NULL) | |
9819 | continue; | |
3019eac3 | 9820 | |
33c5cd75 DB |
9821 | if (cus_htab == NULL) |
9822 | cus_htab = allocate_dwo_unit_table (objfile); | |
19c3d4c9 | 9823 | |
33c5cd75 DB |
9824 | dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); |
9825 | *dwo_unit = create_dwo_cu_data.dwo_unit; | |
9826 | slot = htab_find_slot (cus_htab, dwo_unit, INSERT); | |
9827 | gdb_assert (slot != NULL); | |
9828 | if (*slot != NULL) | |
19c3d4c9 | 9829 | { |
33c5cd75 DB |
9830 | const struct dwo_unit *dup_cu = (const struct dwo_unit *)*slot; |
9831 | sect_offset dup_sect_off = dup_cu->sect_off; | |
19c3d4c9 | 9832 | |
33c5cd75 DB |
9833 | complaint (&symfile_complaints, |
9834 | _("debug cu entry at offset 0x%x is duplicate to" | |
9835 | " the entry at offset 0x%x, signature %s"), | |
9836 | to_underlying (sect_off), to_underlying (dup_sect_off), | |
9837 | hex_string (dwo_unit->signature)); | |
19c3d4c9 | 9838 | } |
33c5cd75 | 9839 | *slot = (void *)dwo_unit; |
3019eac3 | 9840 | } |
3019eac3 DE |
9841 | } |
9842 | ||
80626a55 DE |
9843 | /* DWP file .debug_{cu,tu}_index section format: |
9844 | [ref: http://gcc.gnu.org/wiki/DebugFissionDWP] | |
9845 | ||
d2415c6c DE |
9846 | DWP Version 1: |
9847 | ||
80626a55 DE |
9848 | Both index sections have the same format, and serve to map a 64-bit |
9849 | signature to a set of section numbers. Each section begins with a header, | |
9850 | followed by a hash table of 64-bit signatures, a parallel table of 32-bit | |
9851 | indexes, and a pool of 32-bit section numbers. The index sections will be | |
9852 | aligned at 8-byte boundaries in the file. | |
9853 | ||
d2415c6c DE |
9854 | The index section header consists of: |
9855 | ||
9856 | V, 32 bit version number | |
9857 | -, 32 bits unused | |
9858 | N, 32 bit number of compilation units or type units in the index | |
9859 | M, 32 bit number of slots in the hash table | |
80626a55 | 9860 | |
d2415c6c | 9861 | Numbers are recorded using the byte order of the application binary. |
80626a55 | 9862 | |
d2415c6c DE |
9863 | The hash table begins at offset 16 in the section, and consists of an array |
9864 | of M 64-bit slots. Each slot contains a 64-bit signature (using the byte | |
9865 | order of the application binary). Unused slots in the hash table are 0. | |
9866 | (We rely on the extreme unlikeliness of a signature being exactly 0.) | |
80626a55 | 9867 | |
d2415c6c DE |
9868 | The parallel table begins immediately after the hash table |
9869 | (at offset 16 + 8 * M from the beginning of the section), and consists of an | |
9870 | array of 32-bit indexes (using the byte order of the application binary), | |
9871 | corresponding 1-1 with slots in the hash table. Each entry in the parallel | |
9872 | table contains a 32-bit index into the pool of section numbers. For unused | |
9873 | hash table slots, the corresponding entry in the parallel table will be 0. | |
80626a55 | 9874 | |
73869dc2 DE |
9875 | The pool of section numbers begins immediately following the hash table |
9876 | (at offset 16 + 12 * M from the beginning of the section). The pool of | |
9877 | section numbers consists of an array of 32-bit words (using the byte order | |
9878 | of the application binary). Each item in the array is indexed starting | |
9879 | from 0. The hash table entry provides the index of the first section | |
9880 | number in the set. Additional section numbers in the set follow, and the | |
9881 | set is terminated by a 0 entry (section number 0 is not used in ELF). | |
9882 | ||
9883 | In each set of section numbers, the .debug_info.dwo or .debug_types.dwo | |
9884 | section must be the first entry in the set, and the .debug_abbrev.dwo must | |
9885 | be the second entry. Other members of the set may follow in any order. | |
9886 | ||
9887 | --- | |
9888 | ||
9889 | DWP Version 2: | |
9890 | ||
9891 | DWP Version 2 combines all the .debug_info, etc. sections into one, | |
9892 | and the entries in the index tables are now offsets into these sections. | |
9893 | CU offsets begin at 0. TU offsets begin at the size of the .debug_info | |
9894 | section. | |
9895 | ||
9896 | Index Section Contents: | |
9897 | Header | |
9898 | Hash Table of Signatures dwp_hash_table.hash_table | |
9899 | Parallel Table of Indices dwp_hash_table.unit_table | |
9900 | Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets} | |
9901 | Table of Section Sizes dwp_hash_table.v2.sizes | |
9902 | ||
9903 | The index section header consists of: | |
9904 | ||
9905 | V, 32 bit version number | |
9906 | L, 32 bit number of columns in the table of section offsets | |
9907 | N, 32 bit number of compilation units or type units in the index | |
9908 | M, 32 bit number of slots in the hash table | |
9909 | ||
9910 | Numbers are recorded using the byte order of the application binary. | |
9911 | ||
9912 | The hash table has the same format as version 1. | |
9913 | The parallel table of indices has the same format as version 1, | |
9914 | except that the entries are origin-1 indices into the table of sections | |
9915 | offsets and the table of section sizes. | |
9916 | ||
9917 | The table of offsets begins immediately following the parallel table | |
9918 | (at offset 16 + 12 * M from the beginning of the section). The table is | |
9919 | a two-dimensional array of 32-bit words (using the byte order of the | |
9920 | application binary), with L columns and N+1 rows, in row-major order. | |
9921 | Each row in the array is indexed starting from 0. The first row provides | |
9922 | a key to the remaining rows: each column in this row provides an identifier | |
9923 | for a debug section, and the offsets in the same column of subsequent rows | |
9924 | refer to that section. The section identifiers are: | |
9925 | ||
9926 | DW_SECT_INFO 1 .debug_info.dwo | |
9927 | DW_SECT_TYPES 2 .debug_types.dwo | |
9928 | DW_SECT_ABBREV 3 .debug_abbrev.dwo | |
9929 | DW_SECT_LINE 4 .debug_line.dwo | |
9930 | DW_SECT_LOC 5 .debug_loc.dwo | |
9931 | DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo | |
9932 | DW_SECT_MACINFO 7 .debug_macinfo.dwo | |
9933 | DW_SECT_MACRO 8 .debug_macro.dwo | |
9934 | ||
9935 | The offsets provided by the CU and TU index sections are the base offsets | |
9936 | for the contributions made by each CU or TU to the corresponding section | |
9937 | in the package file. Each CU and TU header contains an abbrev_offset | |
9938 | field, used to find the abbreviations table for that CU or TU within the | |
9939 | contribution to the .debug_abbrev.dwo section for that CU or TU, and should | |
9940 | be interpreted as relative to the base offset given in the index section. | |
9941 | Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes | |
9942 | should be interpreted as relative to the base offset for .debug_line.dwo, | |
9943 | and offsets into other debug sections obtained from DWARF attributes should | |
9944 | also be interpreted as relative to the corresponding base offset. | |
9945 | ||
9946 | The table of sizes begins immediately following the table of offsets. | |
9947 | Like the table of offsets, it is a two-dimensional array of 32-bit words, | |
9948 | with L columns and N rows, in row-major order. Each row in the array is | |
9949 | indexed starting from 1 (row 0 is shared by the two tables). | |
9950 | ||
9951 | --- | |
9952 | ||
9953 | Hash table lookup is handled the same in version 1 and 2: | |
9954 | ||
9955 | We assume that N and M will not exceed 2^32 - 1. | |
9956 | The size of the hash table, M, must be 2^k such that 2^k > 3*N/2. | |
9957 | ||
d2415c6c DE |
9958 | Given a 64-bit compilation unit signature or a type signature S, an entry |
9959 | in the hash table is located as follows: | |
80626a55 | 9960 | |
d2415c6c DE |
9961 | 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with |
9962 | the low-order k bits all set to 1. | |
80626a55 | 9963 | |
d2415c6c | 9964 | 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1). |
80626a55 | 9965 | |
d2415c6c DE |
9966 | 3) If the hash table entry at index H matches the signature, use that |
9967 | entry. If the hash table entry at index H is unused (all zeroes), | |
9968 | terminate the search: the signature is not present in the table. | |
80626a55 | 9969 | |
d2415c6c | 9970 | 4) Let H = (H + H') modulo M. Repeat at Step 3. |
80626a55 | 9971 | |
d2415c6c | 9972 | Because M > N and H' and M are relatively prime, the search is guaranteed |
73869dc2 | 9973 | to stop at an unused slot or find the match. */ |
80626a55 DE |
9974 | |
9975 | /* Create a hash table to map DWO IDs to their CU/TU entry in | |
9976 | .debug_{info,types}.dwo in DWP_FILE. | |
9977 | Returns NULL if there isn't one. | |
9978 | Note: This function processes DWP files only, not DWO files. */ | |
9979 | ||
9980 | static struct dwp_hash_table * | |
9981 | create_dwp_hash_table (struct dwp_file *dwp_file, int is_debug_types) | |
9982 | { | |
9983 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
9984 | bfd *dbfd = dwp_file->dbfd; | |
948f8e3d | 9985 | const gdb_byte *index_ptr, *index_end; |
80626a55 | 9986 | struct dwarf2_section_info *index; |
73869dc2 | 9987 | uint32_t version, nr_columns, nr_units, nr_slots; |
80626a55 DE |
9988 | struct dwp_hash_table *htab; |
9989 | ||
9990 | if (is_debug_types) | |
9991 | index = &dwp_file->sections.tu_index; | |
9992 | else | |
9993 | index = &dwp_file->sections.cu_index; | |
9994 | ||
9995 | if (dwarf2_section_empty_p (index)) | |
9996 | return NULL; | |
9997 | dwarf2_read_section (objfile, index); | |
9998 | ||
9999 | index_ptr = index->buffer; | |
10000 | index_end = index_ptr + index->size; | |
10001 | ||
10002 | version = read_4_bytes (dbfd, index_ptr); | |
73869dc2 DE |
10003 | index_ptr += 4; |
10004 | if (version == 2) | |
10005 | nr_columns = read_4_bytes (dbfd, index_ptr); | |
10006 | else | |
10007 | nr_columns = 0; | |
10008 | index_ptr += 4; | |
80626a55 DE |
10009 | nr_units = read_4_bytes (dbfd, index_ptr); |
10010 | index_ptr += 4; | |
10011 | nr_slots = read_4_bytes (dbfd, index_ptr); | |
10012 | index_ptr += 4; | |
10013 | ||
73869dc2 | 10014 | if (version != 1 && version != 2) |
80626a55 | 10015 | { |
21aa081e | 10016 | error (_("Dwarf Error: unsupported DWP file version (%s)" |
80626a55 | 10017 | " [in module %s]"), |
21aa081e | 10018 | pulongest (version), dwp_file->name); |
80626a55 DE |
10019 | } |
10020 | if (nr_slots != (nr_slots & -nr_slots)) | |
10021 | { | |
21aa081e | 10022 | error (_("Dwarf Error: number of slots in DWP hash table (%s)" |
80626a55 | 10023 | " is not power of 2 [in module %s]"), |
21aa081e | 10024 | pulongest (nr_slots), dwp_file->name); |
80626a55 DE |
10025 | } |
10026 | ||
10027 | htab = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_hash_table); | |
73869dc2 DE |
10028 | htab->version = version; |
10029 | htab->nr_columns = nr_columns; | |
80626a55 DE |
10030 | htab->nr_units = nr_units; |
10031 | htab->nr_slots = nr_slots; | |
10032 | htab->hash_table = index_ptr; | |
10033 | htab->unit_table = htab->hash_table + sizeof (uint64_t) * nr_slots; | |
73869dc2 DE |
10034 | |
10035 | /* Exit early if the table is empty. */ | |
10036 | if (nr_slots == 0 || nr_units == 0 | |
10037 | || (version == 2 && nr_columns == 0)) | |
10038 | { | |
10039 | /* All must be zero. */ | |
10040 | if (nr_slots != 0 || nr_units != 0 | |
10041 | || (version == 2 && nr_columns != 0)) | |
10042 | { | |
10043 | complaint (&symfile_complaints, | |
10044 | _("Empty DWP but nr_slots,nr_units,nr_columns not" | |
10045 | " all zero [in modules %s]"), | |
10046 | dwp_file->name); | |
10047 | } | |
10048 | return htab; | |
10049 | } | |
10050 | ||
10051 | if (version == 1) | |
10052 | { | |
10053 | htab->section_pool.v1.indices = | |
10054 | htab->unit_table + sizeof (uint32_t) * nr_slots; | |
10055 | /* It's harder to decide whether the section is too small in v1. | |
10056 | V1 is deprecated anyway so we punt. */ | |
10057 | } | |
10058 | else | |
10059 | { | |
10060 | const gdb_byte *ids_ptr = htab->unit_table + sizeof (uint32_t) * nr_slots; | |
10061 | int *ids = htab->section_pool.v2.section_ids; | |
10062 | /* Reverse map for error checking. */ | |
10063 | int ids_seen[DW_SECT_MAX + 1]; | |
10064 | int i; | |
10065 | ||
10066 | if (nr_columns < 2) | |
10067 | { | |
10068 | error (_("Dwarf Error: bad DWP hash table, too few columns" | |
10069 | " in section table [in module %s]"), | |
10070 | dwp_file->name); | |
10071 | } | |
10072 | if (nr_columns > MAX_NR_V2_DWO_SECTIONS) | |
10073 | { | |
10074 | error (_("Dwarf Error: bad DWP hash table, too many columns" | |
10075 | " in section table [in module %s]"), | |
10076 | dwp_file->name); | |
10077 | } | |
10078 | memset (ids, 255, (DW_SECT_MAX + 1) * sizeof (int32_t)); | |
10079 | memset (ids_seen, 255, (DW_SECT_MAX + 1) * sizeof (int32_t)); | |
10080 | for (i = 0; i < nr_columns; ++i) | |
10081 | { | |
10082 | int id = read_4_bytes (dbfd, ids_ptr + i * sizeof (uint32_t)); | |
10083 | ||
10084 | if (id < DW_SECT_MIN || id > DW_SECT_MAX) | |
10085 | { | |
10086 | error (_("Dwarf Error: bad DWP hash table, bad section id %d" | |
10087 | " in section table [in module %s]"), | |
10088 | id, dwp_file->name); | |
10089 | } | |
10090 | if (ids_seen[id] != -1) | |
10091 | { | |
10092 | error (_("Dwarf Error: bad DWP hash table, duplicate section" | |
10093 | " id %d in section table [in module %s]"), | |
10094 | id, dwp_file->name); | |
10095 | } | |
10096 | ids_seen[id] = i; | |
10097 | ids[i] = id; | |
10098 | } | |
10099 | /* Must have exactly one info or types section. */ | |
10100 | if (((ids_seen[DW_SECT_INFO] != -1) | |
10101 | + (ids_seen[DW_SECT_TYPES] != -1)) | |
10102 | != 1) | |
10103 | { | |
10104 | error (_("Dwarf Error: bad DWP hash table, missing/duplicate" | |
10105 | " DWO info/types section [in module %s]"), | |
10106 | dwp_file->name); | |
10107 | } | |
10108 | /* Must have an abbrev section. */ | |
10109 | if (ids_seen[DW_SECT_ABBREV] == -1) | |
10110 | { | |
10111 | error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev" | |
10112 | " section [in module %s]"), | |
10113 | dwp_file->name); | |
10114 | } | |
10115 | htab->section_pool.v2.offsets = ids_ptr + sizeof (uint32_t) * nr_columns; | |
10116 | htab->section_pool.v2.sizes = | |
10117 | htab->section_pool.v2.offsets + (sizeof (uint32_t) | |
10118 | * nr_units * nr_columns); | |
10119 | if ((htab->section_pool.v2.sizes + (sizeof (uint32_t) | |
10120 | * nr_units * nr_columns)) | |
10121 | > index_end) | |
10122 | { | |
10123 | error (_("Dwarf Error: DWP index section is corrupt (too small)" | |
10124 | " [in module %s]"), | |
10125 | dwp_file->name); | |
10126 | } | |
10127 | } | |
80626a55 DE |
10128 | |
10129 | return htab; | |
10130 | } | |
10131 | ||
10132 | /* Update SECTIONS with the data from SECTP. | |
10133 | ||
10134 | This function is like the other "locate" section routines that are | |
10135 | passed to bfd_map_over_sections, but in this context the sections to | |
73869dc2 | 10136 | read comes from the DWP V1 hash table, not the full ELF section table. |
80626a55 DE |
10137 | |
10138 | The result is non-zero for success, or zero if an error was found. */ | |
10139 | ||
10140 | static int | |
73869dc2 DE |
10141 | locate_v1_virtual_dwo_sections (asection *sectp, |
10142 | struct virtual_v1_dwo_sections *sections) | |
80626a55 DE |
10143 | { |
10144 | const struct dwop_section_names *names = &dwop_section_names; | |
10145 | ||
10146 | if (section_is_p (sectp->name, &names->abbrev_dwo)) | |
10147 | { | |
10148 | /* There can be only one. */ | |
049412e3 | 10149 | if (sections->abbrev.s.section != NULL) |
80626a55 | 10150 | return 0; |
049412e3 | 10151 | sections->abbrev.s.section = sectp; |
80626a55 DE |
10152 | sections->abbrev.size = bfd_get_section_size (sectp); |
10153 | } | |
10154 | else if (section_is_p (sectp->name, &names->info_dwo) | |
10155 | || section_is_p (sectp->name, &names->types_dwo)) | |
10156 | { | |
10157 | /* There can be only one. */ | |
049412e3 | 10158 | if (sections->info_or_types.s.section != NULL) |
80626a55 | 10159 | return 0; |
049412e3 | 10160 | sections->info_or_types.s.section = sectp; |
80626a55 DE |
10161 | sections->info_or_types.size = bfd_get_section_size (sectp); |
10162 | } | |
10163 | else if (section_is_p (sectp->name, &names->line_dwo)) | |
10164 | { | |
10165 | /* There can be only one. */ | |
049412e3 | 10166 | if (sections->line.s.section != NULL) |
80626a55 | 10167 | return 0; |
049412e3 | 10168 | sections->line.s.section = sectp; |
80626a55 DE |
10169 | sections->line.size = bfd_get_section_size (sectp); |
10170 | } | |
10171 | else if (section_is_p (sectp->name, &names->loc_dwo)) | |
10172 | { | |
10173 | /* There can be only one. */ | |
049412e3 | 10174 | if (sections->loc.s.section != NULL) |
80626a55 | 10175 | return 0; |
049412e3 | 10176 | sections->loc.s.section = sectp; |
80626a55 DE |
10177 | sections->loc.size = bfd_get_section_size (sectp); |
10178 | } | |
10179 | else if (section_is_p (sectp->name, &names->macinfo_dwo)) | |
10180 | { | |
10181 | /* There can be only one. */ | |
049412e3 | 10182 | if (sections->macinfo.s.section != NULL) |
80626a55 | 10183 | return 0; |
049412e3 | 10184 | sections->macinfo.s.section = sectp; |
80626a55 DE |
10185 | sections->macinfo.size = bfd_get_section_size (sectp); |
10186 | } | |
10187 | else if (section_is_p (sectp->name, &names->macro_dwo)) | |
10188 | { | |
10189 | /* There can be only one. */ | |
049412e3 | 10190 | if (sections->macro.s.section != NULL) |
80626a55 | 10191 | return 0; |
049412e3 | 10192 | sections->macro.s.section = sectp; |
80626a55 DE |
10193 | sections->macro.size = bfd_get_section_size (sectp); |
10194 | } | |
10195 | else if (section_is_p (sectp->name, &names->str_offsets_dwo)) | |
10196 | { | |
10197 | /* There can be only one. */ | |
049412e3 | 10198 | if (sections->str_offsets.s.section != NULL) |
80626a55 | 10199 | return 0; |
049412e3 | 10200 | sections->str_offsets.s.section = sectp; |
80626a55 DE |
10201 | sections->str_offsets.size = bfd_get_section_size (sectp); |
10202 | } | |
10203 | else | |
10204 | { | |
10205 | /* No other kind of section is valid. */ | |
10206 | return 0; | |
10207 | } | |
10208 | ||
10209 | return 1; | |
10210 | } | |
10211 | ||
73869dc2 DE |
10212 | /* Create a dwo_unit object for the DWO unit with signature SIGNATURE. |
10213 | UNIT_INDEX is the index of the DWO unit in the DWP hash table. | |
10214 | COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU. | |
10215 | This is for DWP version 1 files. */ | |
80626a55 DE |
10216 | |
10217 | static struct dwo_unit * | |
73869dc2 DE |
10218 | create_dwo_unit_in_dwp_v1 (struct dwp_file *dwp_file, |
10219 | uint32_t unit_index, | |
10220 | const char *comp_dir, | |
10221 | ULONGEST signature, int is_debug_types) | |
80626a55 DE |
10222 | { |
10223 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
73869dc2 DE |
10224 | const struct dwp_hash_table *dwp_htab = |
10225 | is_debug_types ? dwp_file->tus : dwp_file->cus; | |
80626a55 DE |
10226 | bfd *dbfd = dwp_file->dbfd; |
10227 | const char *kind = is_debug_types ? "TU" : "CU"; | |
10228 | struct dwo_file *dwo_file; | |
10229 | struct dwo_unit *dwo_unit; | |
73869dc2 | 10230 | struct virtual_v1_dwo_sections sections; |
80626a55 DE |
10231 | void **dwo_file_slot; |
10232 | char *virtual_dwo_name; | |
80626a55 DE |
10233 | struct cleanup *cleanups; |
10234 | int i; | |
10235 | ||
73869dc2 DE |
10236 | gdb_assert (dwp_file->version == 1); |
10237 | ||
b4f54984 | 10238 | if (dwarf_read_debug) |
80626a55 | 10239 | { |
73869dc2 | 10240 | fprintf_unfiltered (gdb_stdlog, "Reading %s %s/%s in DWP V1 file: %s\n", |
80626a55 | 10241 | kind, |
73869dc2 | 10242 | pulongest (unit_index), hex_string (signature), |
80626a55 DE |
10243 | dwp_file->name); |
10244 | } | |
10245 | ||
19ac8c2e | 10246 | /* Fetch the sections of this DWO unit. |
80626a55 DE |
10247 | Put a limit on the number of sections we look for so that bad data |
10248 | doesn't cause us to loop forever. */ | |
10249 | ||
73869dc2 | 10250 | #define MAX_NR_V1_DWO_SECTIONS \ |
80626a55 DE |
10251 | (1 /* .debug_info or .debug_types */ \ |
10252 | + 1 /* .debug_abbrev */ \ | |
10253 | + 1 /* .debug_line */ \ | |
10254 | + 1 /* .debug_loc */ \ | |
10255 | + 1 /* .debug_str_offsets */ \ | |
19ac8c2e | 10256 | + 1 /* .debug_macro or .debug_macinfo */ \ |
80626a55 DE |
10257 | + 1 /* trailing zero */) |
10258 | ||
10259 | memset (§ions, 0, sizeof (sections)); | |
10260 | cleanups = make_cleanup (null_cleanup, 0); | |
10261 | ||
73869dc2 | 10262 | for (i = 0; i < MAX_NR_V1_DWO_SECTIONS; ++i) |
80626a55 DE |
10263 | { |
10264 | asection *sectp; | |
10265 | uint32_t section_nr = | |
10266 | read_4_bytes (dbfd, | |
73869dc2 DE |
10267 | dwp_htab->section_pool.v1.indices |
10268 | + (unit_index + i) * sizeof (uint32_t)); | |
80626a55 DE |
10269 | |
10270 | if (section_nr == 0) | |
10271 | break; | |
10272 | if (section_nr >= dwp_file->num_sections) | |
10273 | { | |
10274 | error (_("Dwarf Error: bad DWP hash table, section number too large" | |
10275 | " [in module %s]"), | |
10276 | dwp_file->name); | |
10277 | } | |
10278 | ||
10279 | sectp = dwp_file->elf_sections[section_nr]; | |
73869dc2 | 10280 | if (! locate_v1_virtual_dwo_sections (sectp, §ions)) |
80626a55 DE |
10281 | { |
10282 | error (_("Dwarf Error: bad DWP hash table, invalid section found" | |
10283 | " [in module %s]"), | |
10284 | dwp_file->name); | |
10285 | } | |
10286 | } | |
10287 | ||
10288 | if (i < 2 | |
a32a8923 DE |
10289 | || dwarf2_section_empty_p (§ions.info_or_types) |
10290 | || dwarf2_section_empty_p (§ions.abbrev)) | |
80626a55 DE |
10291 | { |
10292 | error (_("Dwarf Error: bad DWP hash table, missing DWO sections" | |
10293 | " [in module %s]"), | |
10294 | dwp_file->name); | |
10295 | } | |
73869dc2 | 10296 | if (i == MAX_NR_V1_DWO_SECTIONS) |
80626a55 DE |
10297 | { |
10298 | error (_("Dwarf Error: bad DWP hash table, too many DWO sections" | |
10299 | " [in module %s]"), | |
10300 | dwp_file->name); | |
10301 | } | |
10302 | ||
10303 | /* It's easier for the rest of the code if we fake a struct dwo_file and | |
10304 | have dwo_unit "live" in that. At least for now. | |
10305 | ||
10306 | The DWP file can be made up of a random collection of CUs and TUs. | |
c766f7ec | 10307 | However, for each CU + set of TUs that came from the same original DWO |
57d63ce2 DE |
10308 | file, we can combine them back into a virtual DWO file to save space |
10309 | (fewer struct dwo_file objects to allocate). Remember that for really | |
80626a55 DE |
10310 | large apps there can be on the order of 8K CUs and 200K TUs, or more. */ |
10311 | ||
2792b94d PM |
10312 | virtual_dwo_name = |
10313 | xstrprintf ("virtual-dwo/%d-%d-%d-%d", | |
a32a8923 DE |
10314 | get_section_id (§ions.abbrev), |
10315 | get_section_id (§ions.line), | |
10316 | get_section_id (§ions.loc), | |
10317 | get_section_id (§ions.str_offsets)); | |
80626a55 DE |
10318 | make_cleanup (xfree, virtual_dwo_name); |
10319 | /* Can we use an existing virtual DWO file? */ | |
0ac5b59e | 10320 | dwo_file_slot = lookup_dwo_file_slot (virtual_dwo_name, comp_dir); |
80626a55 DE |
10321 | /* Create one if necessary. */ |
10322 | if (*dwo_file_slot == NULL) | |
10323 | { | |
b4f54984 | 10324 | if (dwarf_read_debug) |
80626a55 DE |
10325 | { |
10326 | fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n", | |
10327 | virtual_dwo_name); | |
10328 | } | |
10329 | dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file); | |
224c3ddb SM |
10330 | dwo_file->dwo_name |
10331 | = (const char *) obstack_copy0 (&objfile->objfile_obstack, | |
10332 | virtual_dwo_name, | |
10333 | strlen (virtual_dwo_name)); | |
0ac5b59e | 10334 | dwo_file->comp_dir = comp_dir; |
80626a55 DE |
10335 | dwo_file->sections.abbrev = sections.abbrev; |
10336 | dwo_file->sections.line = sections.line; | |
10337 | dwo_file->sections.loc = sections.loc; | |
10338 | dwo_file->sections.macinfo = sections.macinfo; | |
10339 | dwo_file->sections.macro = sections.macro; | |
10340 | dwo_file->sections.str_offsets = sections.str_offsets; | |
10341 | /* The "str" section is global to the entire DWP file. */ | |
10342 | dwo_file->sections.str = dwp_file->sections.str; | |
57d63ce2 | 10343 | /* The info or types section is assigned below to dwo_unit, |
80626a55 DE |
10344 | there's no need to record it in dwo_file. |
10345 | Also, we can't simply record type sections in dwo_file because | |
10346 | we record a pointer into the vector in dwo_unit. As we collect more | |
10347 | types we'll grow the vector and eventually have to reallocate space | |
57d63ce2 DE |
10348 | for it, invalidating all copies of pointers into the previous |
10349 | contents. */ | |
80626a55 DE |
10350 | *dwo_file_slot = dwo_file; |
10351 | } | |
10352 | else | |
10353 | { | |
b4f54984 | 10354 | if (dwarf_read_debug) |
80626a55 DE |
10355 | { |
10356 | fprintf_unfiltered (gdb_stdlog, "Using existing virtual DWO: %s\n", | |
10357 | virtual_dwo_name); | |
10358 | } | |
9a3c8263 | 10359 | dwo_file = (struct dwo_file *) *dwo_file_slot; |
80626a55 DE |
10360 | } |
10361 | do_cleanups (cleanups); | |
10362 | ||
10363 | dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); | |
10364 | dwo_unit->dwo_file = dwo_file; | |
10365 | dwo_unit->signature = signature; | |
8d749320 SM |
10366 | dwo_unit->section = |
10367 | XOBNEW (&objfile->objfile_obstack, struct dwarf2_section_info); | |
8a0459fd | 10368 | *dwo_unit->section = sections.info_or_types; |
57d63ce2 | 10369 | /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */ |
80626a55 DE |
10370 | |
10371 | return dwo_unit; | |
10372 | } | |
10373 | ||
73869dc2 DE |
10374 | /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it. |
10375 | Given a pointer to the containing section SECTION, and OFFSET,SIZE of the | |
10376 | piece within that section used by a TU/CU, return a virtual section | |
10377 | of just that piece. */ | |
10378 | ||
10379 | static struct dwarf2_section_info | |
10380 | create_dwp_v2_section (struct dwarf2_section_info *section, | |
10381 | bfd_size_type offset, bfd_size_type size) | |
10382 | { | |
10383 | struct dwarf2_section_info result; | |
10384 | asection *sectp; | |
10385 | ||
10386 | gdb_assert (section != NULL); | |
10387 | gdb_assert (!section->is_virtual); | |
10388 | ||
10389 | memset (&result, 0, sizeof (result)); | |
10390 | result.s.containing_section = section; | |
10391 | result.is_virtual = 1; | |
10392 | ||
10393 | if (size == 0) | |
10394 | return result; | |
10395 | ||
10396 | sectp = get_section_bfd_section (section); | |
10397 | ||
10398 | /* Flag an error if the piece denoted by OFFSET,SIZE is outside the | |
10399 | bounds of the real section. This is a pretty-rare event, so just | |
10400 | flag an error (easier) instead of a warning and trying to cope. */ | |
10401 | if (sectp == NULL | |
10402 | || offset + size > bfd_get_section_size (sectp)) | |
10403 | { | |
10404 | bfd *abfd = sectp->owner; | |
10405 | ||
10406 | error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit" | |
10407 | " in section %s [in module %s]"), | |
10408 | sectp ? bfd_section_name (abfd, sectp) : "<unknown>", | |
10409 | objfile_name (dwarf2_per_objfile->objfile)); | |
10410 | } | |
10411 | ||
10412 | result.virtual_offset = offset; | |
10413 | result.size = size; | |
10414 | return result; | |
10415 | } | |
10416 | ||
10417 | /* Create a dwo_unit object for the DWO unit with signature SIGNATURE. | |
10418 | UNIT_INDEX is the index of the DWO unit in the DWP hash table. | |
10419 | COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU. | |
10420 | This is for DWP version 2 files. */ | |
10421 | ||
10422 | static struct dwo_unit * | |
10423 | create_dwo_unit_in_dwp_v2 (struct dwp_file *dwp_file, | |
10424 | uint32_t unit_index, | |
10425 | const char *comp_dir, | |
10426 | ULONGEST signature, int is_debug_types) | |
10427 | { | |
10428 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
10429 | const struct dwp_hash_table *dwp_htab = | |
10430 | is_debug_types ? dwp_file->tus : dwp_file->cus; | |
10431 | bfd *dbfd = dwp_file->dbfd; | |
10432 | const char *kind = is_debug_types ? "TU" : "CU"; | |
10433 | struct dwo_file *dwo_file; | |
10434 | struct dwo_unit *dwo_unit; | |
10435 | struct virtual_v2_dwo_sections sections; | |
10436 | void **dwo_file_slot; | |
10437 | char *virtual_dwo_name; | |
73869dc2 DE |
10438 | struct cleanup *cleanups; |
10439 | int i; | |
10440 | ||
10441 | gdb_assert (dwp_file->version == 2); | |
10442 | ||
b4f54984 | 10443 | if (dwarf_read_debug) |
73869dc2 DE |
10444 | { |
10445 | fprintf_unfiltered (gdb_stdlog, "Reading %s %s/%s in DWP V2 file: %s\n", | |
10446 | kind, | |
10447 | pulongest (unit_index), hex_string (signature), | |
10448 | dwp_file->name); | |
10449 | } | |
10450 | ||
10451 | /* Fetch the section offsets of this DWO unit. */ | |
10452 | ||
10453 | memset (§ions, 0, sizeof (sections)); | |
10454 | cleanups = make_cleanup (null_cleanup, 0); | |
10455 | ||
10456 | for (i = 0; i < dwp_htab->nr_columns; ++i) | |
10457 | { | |
10458 | uint32_t offset = read_4_bytes (dbfd, | |
10459 | dwp_htab->section_pool.v2.offsets | |
10460 | + (((unit_index - 1) * dwp_htab->nr_columns | |
10461 | + i) | |
10462 | * sizeof (uint32_t))); | |
10463 | uint32_t size = read_4_bytes (dbfd, | |
10464 | dwp_htab->section_pool.v2.sizes | |
10465 | + (((unit_index - 1) * dwp_htab->nr_columns | |
10466 | + i) | |
10467 | * sizeof (uint32_t))); | |
10468 | ||
10469 | switch (dwp_htab->section_pool.v2.section_ids[i]) | |
10470 | { | |
10471 | case DW_SECT_INFO: | |
10472 | case DW_SECT_TYPES: | |
10473 | sections.info_or_types_offset = offset; | |
10474 | sections.info_or_types_size = size; | |
10475 | break; | |
10476 | case DW_SECT_ABBREV: | |
10477 | sections.abbrev_offset = offset; | |
10478 | sections.abbrev_size = size; | |
10479 | break; | |
10480 | case DW_SECT_LINE: | |
10481 | sections.line_offset = offset; | |
10482 | sections.line_size = size; | |
10483 | break; | |
10484 | case DW_SECT_LOC: | |
10485 | sections.loc_offset = offset; | |
10486 | sections.loc_size = size; | |
10487 | break; | |
10488 | case DW_SECT_STR_OFFSETS: | |
10489 | sections.str_offsets_offset = offset; | |
10490 | sections.str_offsets_size = size; | |
10491 | break; | |
10492 | case DW_SECT_MACINFO: | |
10493 | sections.macinfo_offset = offset; | |
10494 | sections.macinfo_size = size; | |
10495 | break; | |
10496 | case DW_SECT_MACRO: | |
10497 | sections.macro_offset = offset; | |
10498 | sections.macro_size = size; | |
10499 | break; | |
10500 | } | |
10501 | } | |
10502 | ||
10503 | /* It's easier for the rest of the code if we fake a struct dwo_file and | |
10504 | have dwo_unit "live" in that. At least for now. | |
10505 | ||
10506 | The DWP file can be made up of a random collection of CUs and TUs. | |
10507 | However, for each CU + set of TUs that came from the same original DWO | |
10508 | file, we can combine them back into a virtual DWO file to save space | |
10509 | (fewer struct dwo_file objects to allocate). Remember that for really | |
10510 | large apps there can be on the order of 8K CUs and 200K TUs, or more. */ | |
10511 | ||
10512 | virtual_dwo_name = | |
10513 | xstrprintf ("virtual-dwo/%ld-%ld-%ld-%ld", | |
10514 | (long) (sections.abbrev_size ? sections.abbrev_offset : 0), | |
10515 | (long) (sections.line_size ? sections.line_offset : 0), | |
10516 | (long) (sections.loc_size ? sections.loc_offset : 0), | |
10517 | (long) (sections.str_offsets_size | |
10518 | ? sections.str_offsets_offset : 0)); | |
10519 | make_cleanup (xfree, virtual_dwo_name); | |
10520 | /* Can we use an existing virtual DWO file? */ | |
10521 | dwo_file_slot = lookup_dwo_file_slot (virtual_dwo_name, comp_dir); | |
10522 | /* Create one if necessary. */ | |
10523 | if (*dwo_file_slot == NULL) | |
10524 | { | |
b4f54984 | 10525 | if (dwarf_read_debug) |
73869dc2 DE |
10526 | { |
10527 | fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n", | |
10528 | virtual_dwo_name); | |
10529 | } | |
10530 | dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file); | |
224c3ddb SM |
10531 | dwo_file->dwo_name |
10532 | = (const char *) obstack_copy0 (&objfile->objfile_obstack, | |
10533 | virtual_dwo_name, | |
10534 | strlen (virtual_dwo_name)); | |
73869dc2 DE |
10535 | dwo_file->comp_dir = comp_dir; |
10536 | dwo_file->sections.abbrev = | |
10537 | create_dwp_v2_section (&dwp_file->sections.abbrev, | |
10538 | sections.abbrev_offset, sections.abbrev_size); | |
10539 | dwo_file->sections.line = | |
10540 | create_dwp_v2_section (&dwp_file->sections.line, | |
10541 | sections.line_offset, sections.line_size); | |
10542 | dwo_file->sections.loc = | |
10543 | create_dwp_v2_section (&dwp_file->sections.loc, | |
10544 | sections.loc_offset, sections.loc_size); | |
10545 | dwo_file->sections.macinfo = | |
10546 | create_dwp_v2_section (&dwp_file->sections.macinfo, | |
10547 | sections.macinfo_offset, sections.macinfo_size); | |
10548 | dwo_file->sections.macro = | |
10549 | create_dwp_v2_section (&dwp_file->sections.macro, | |
10550 | sections.macro_offset, sections.macro_size); | |
10551 | dwo_file->sections.str_offsets = | |
10552 | create_dwp_v2_section (&dwp_file->sections.str_offsets, | |
10553 | sections.str_offsets_offset, | |
10554 | sections.str_offsets_size); | |
10555 | /* The "str" section is global to the entire DWP file. */ | |
10556 | dwo_file->sections.str = dwp_file->sections.str; | |
10557 | /* The info or types section is assigned below to dwo_unit, | |
10558 | there's no need to record it in dwo_file. | |
10559 | Also, we can't simply record type sections in dwo_file because | |
10560 | we record a pointer into the vector in dwo_unit. As we collect more | |
10561 | types we'll grow the vector and eventually have to reallocate space | |
10562 | for it, invalidating all copies of pointers into the previous | |
10563 | contents. */ | |
10564 | *dwo_file_slot = dwo_file; | |
10565 | } | |
10566 | else | |
10567 | { | |
b4f54984 | 10568 | if (dwarf_read_debug) |
73869dc2 DE |
10569 | { |
10570 | fprintf_unfiltered (gdb_stdlog, "Using existing virtual DWO: %s\n", | |
10571 | virtual_dwo_name); | |
10572 | } | |
9a3c8263 | 10573 | dwo_file = (struct dwo_file *) *dwo_file_slot; |
73869dc2 DE |
10574 | } |
10575 | do_cleanups (cleanups); | |
10576 | ||
10577 | dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); | |
10578 | dwo_unit->dwo_file = dwo_file; | |
10579 | dwo_unit->signature = signature; | |
8d749320 SM |
10580 | dwo_unit->section = |
10581 | XOBNEW (&objfile->objfile_obstack, struct dwarf2_section_info); | |
73869dc2 DE |
10582 | *dwo_unit->section = create_dwp_v2_section (is_debug_types |
10583 | ? &dwp_file->sections.types | |
10584 | : &dwp_file->sections.info, | |
10585 | sections.info_or_types_offset, | |
10586 | sections.info_or_types_size); | |
10587 | /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */ | |
10588 | ||
10589 | return dwo_unit; | |
10590 | } | |
10591 | ||
57d63ce2 DE |
10592 | /* Lookup the DWO unit with SIGNATURE in DWP_FILE. |
10593 | Returns NULL if the signature isn't found. */ | |
80626a55 DE |
10594 | |
10595 | static struct dwo_unit * | |
57d63ce2 DE |
10596 | lookup_dwo_unit_in_dwp (struct dwp_file *dwp_file, const char *comp_dir, |
10597 | ULONGEST signature, int is_debug_types) | |
80626a55 | 10598 | { |
57d63ce2 DE |
10599 | const struct dwp_hash_table *dwp_htab = |
10600 | is_debug_types ? dwp_file->tus : dwp_file->cus; | |
80626a55 | 10601 | bfd *dbfd = dwp_file->dbfd; |
57d63ce2 | 10602 | uint32_t mask = dwp_htab->nr_slots - 1; |
80626a55 DE |
10603 | uint32_t hash = signature & mask; |
10604 | uint32_t hash2 = ((signature >> 32) & mask) | 1; | |
10605 | unsigned int i; | |
10606 | void **slot; | |
870f88f7 | 10607 | struct dwo_unit find_dwo_cu; |
80626a55 DE |
10608 | |
10609 | memset (&find_dwo_cu, 0, sizeof (find_dwo_cu)); | |
10610 | find_dwo_cu.signature = signature; | |
19ac8c2e DE |
10611 | slot = htab_find_slot (is_debug_types |
10612 | ? dwp_file->loaded_tus | |
10613 | : dwp_file->loaded_cus, | |
10614 | &find_dwo_cu, INSERT); | |
80626a55 DE |
10615 | |
10616 | if (*slot != NULL) | |
9a3c8263 | 10617 | return (struct dwo_unit *) *slot; |
80626a55 DE |
10618 | |
10619 | /* Use a for loop so that we don't loop forever on bad debug info. */ | |
57d63ce2 | 10620 | for (i = 0; i < dwp_htab->nr_slots; ++i) |
80626a55 DE |
10621 | { |
10622 | ULONGEST signature_in_table; | |
10623 | ||
10624 | signature_in_table = | |
57d63ce2 | 10625 | read_8_bytes (dbfd, dwp_htab->hash_table + hash * sizeof (uint64_t)); |
80626a55 DE |
10626 | if (signature_in_table == signature) |
10627 | { | |
57d63ce2 DE |
10628 | uint32_t unit_index = |
10629 | read_4_bytes (dbfd, | |
10630 | dwp_htab->unit_table + hash * sizeof (uint32_t)); | |
80626a55 | 10631 | |
73869dc2 DE |
10632 | if (dwp_file->version == 1) |
10633 | { | |
10634 | *slot = create_dwo_unit_in_dwp_v1 (dwp_file, unit_index, | |
10635 | comp_dir, signature, | |
10636 | is_debug_types); | |
10637 | } | |
10638 | else | |
10639 | { | |
10640 | *slot = create_dwo_unit_in_dwp_v2 (dwp_file, unit_index, | |
10641 | comp_dir, signature, | |
10642 | is_debug_types); | |
10643 | } | |
9a3c8263 | 10644 | return (struct dwo_unit *) *slot; |
80626a55 DE |
10645 | } |
10646 | if (signature_in_table == 0) | |
10647 | return NULL; | |
10648 | hash = (hash + hash2) & mask; | |
10649 | } | |
10650 | ||
10651 | error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate" | |
10652 | " [in module %s]"), | |
10653 | dwp_file->name); | |
10654 | } | |
10655 | ||
ab5088bf | 10656 | /* Subroutine of open_dwo_file,open_dwp_file to simplify them. |
3019eac3 DE |
10657 | Open the file specified by FILE_NAME and hand it off to BFD for |
10658 | preliminary analysis. Return a newly initialized bfd *, which | |
10659 | includes a canonicalized copy of FILE_NAME. | |
80626a55 | 10660 | If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file. |
6ac97d4c DE |
10661 | SEARCH_CWD is true if the current directory is to be searched. |
10662 | It will be searched before debug-file-directory. | |
13aaf454 DE |
10663 | If successful, the file is added to the bfd include table of the |
10664 | objfile's bfd (see gdb_bfd_record_inclusion). | |
6ac97d4c | 10665 | If unable to find/open the file, return NULL. |
3019eac3 DE |
10666 | NOTE: This function is derived from symfile_bfd_open. */ |
10667 | ||
192b62ce | 10668 | static gdb_bfd_ref_ptr |
6ac97d4c | 10669 | try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd) |
3019eac3 | 10670 | { |
80626a55 | 10671 | int desc, flags; |
3019eac3 | 10672 | char *absolute_name; |
9c02c129 DE |
10673 | /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if |
10674 | FILE_NAME contains a '/'. So we can't use it. Instead prepend "." | |
10675 | to debug_file_directory. */ | |
10676 | char *search_path; | |
10677 | static const char dirname_separator_string[] = { DIRNAME_SEPARATOR, '\0' }; | |
10678 | ||
6ac97d4c DE |
10679 | if (search_cwd) |
10680 | { | |
10681 | if (*debug_file_directory != '\0') | |
10682 | search_path = concat (".", dirname_separator_string, | |
b36cec19 | 10683 | debug_file_directory, (char *) NULL); |
6ac97d4c DE |
10684 | else |
10685 | search_path = xstrdup ("."); | |
10686 | } | |
9c02c129 | 10687 | else |
6ac97d4c | 10688 | search_path = xstrdup (debug_file_directory); |
3019eac3 | 10689 | |
492c0ab7 | 10690 | flags = OPF_RETURN_REALPATH; |
80626a55 DE |
10691 | if (is_dwp) |
10692 | flags |= OPF_SEARCH_IN_PATH; | |
9c02c129 | 10693 | desc = openp (search_path, flags, file_name, |
3019eac3 | 10694 | O_RDONLY | O_BINARY, &absolute_name); |
9c02c129 | 10695 | xfree (search_path); |
3019eac3 DE |
10696 | if (desc < 0) |
10697 | return NULL; | |
10698 | ||
192b62ce | 10699 | gdb_bfd_ref_ptr sym_bfd (gdb_bfd_open (absolute_name, gnutarget, desc)); |
a4453b7e | 10700 | xfree (absolute_name); |
9c02c129 DE |
10701 | if (sym_bfd == NULL) |
10702 | return NULL; | |
192b62ce | 10703 | bfd_set_cacheable (sym_bfd.get (), 1); |
3019eac3 | 10704 | |
192b62ce TT |
10705 | if (!bfd_check_format (sym_bfd.get (), bfd_object)) |
10706 | return NULL; | |
3019eac3 | 10707 | |
13aaf454 DE |
10708 | /* Success. Record the bfd as having been included by the objfile's bfd. |
10709 | This is important because things like demangled_names_hash lives in the | |
10710 | objfile's per_bfd space and may have references to things like symbol | |
10711 | names that live in the DWO/DWP file's per_bfd space. PR 16426. */ | |
192b62ce | 10712 | gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, sym_bfd.get ()); |
13aaf454 | 10713 | |
3019eac3 DE |
10714 | return sym_bfd; |
10715 | } | |
10716 | ||
ab5088bf | 10717 | /* Try to open DWO file FILE_NAME. |
3019eac3 DE |
10718 | COMP_DIR is the DW_AT_comp_dir attribute. |
10719 | The result is the bfd handle of the file. | |
10720 | If there is a problem finding or opening the file, return NULL. | |
10721 | Upon success, the canonicalized path of the file is stored in the bfd, | |
10722 | same as symfile_bfd_open. */ | |
10723 | ||
192b62ce | 10724 | static gdb_bfd_ref_ptr |
ab5088bf | 10725 | open_dwo_file (const char *file_name, const char *comp_dir) |
3019eac3 | 10726 | { |
80626a55 | 10727 | if (IS_ABSOLUTE_PATH (file_name)) |
6ac97d4c | 10728 | return try_open_dwop_file (file_name, 0 /*is_dwp*/, 0 /*search_cwd*/); |
3019eac3 DE |
10729 | |
10730 | /* Before trying the search path, try DWO_NAME in COMP_DIR. */ | |
10731 | ||
10732 | if (comp_dir != NULL) | |
10733 | { | |
b36cec19 PA |
10734 | char *path_to_try = concat (comp_dir, SLASH_STRING, |
10735 | file_name, (char *) NULL); | |
3019eac3 DE |
10736 | |
10737 | /* NOTE: If comp_dir is a relative path, this will also try the | |
10738 | search path, which seems useful. */ | |
192b62ce TT |
10739 | gdb_bfd_ref_ptr abfd (try_open_dwop_file (path_to_try, 0 /*is_dwp*/, |
10740 | 1 /*search_cwd*/)); | |
3019eac3 DE |
10741 | xfree (path_to_try); |
10742 | if (abfd != NULL) | |
10743 | return abfd; | |
10744 | } | |
10745 | ||
10746 | /* That didn't work, try debug-file-directory, which, despite its name, | |
10747 | is a list of paths. */ | |
10748 | ||
10749 | if (*debug_file_directory == '\0') | |
10750 | return NULL; | |
10751 | ||
6ac97d4c | 10752 | return try_open_dwop_file (file_name, 0 /*is_dwp*/, 1 /*search_cwd*/); |
3019eac3 DE |
10753 | } |
10754 | ||
80626a55 DE |
10755 | /* This function is mapped across the sections and remembers the offset and |
10756 | size of each of the DWO debugging sections we are interested in. */ | |
10757 | ||
10758 | static void | |
10759 | dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr) | |
10760 | { | |
9a3c8263 | 10761 | struct dwo_sections *dwo_sections = (struct dwo_sections *) dwo_sections_ptr; |
80626a55 DE |
10762 | const struct dwop_section_names *names = &dwop_section_names; |
10763 | ||
10764 | if (section_is_p (sectp->name, &names->abbrev_dwo)) | |
10765 | { | |
049412e3 | 10766 | dwo_sections->abbrev.s.section = sectp; |
80626a55 DE |
10767 | dwo_sections->abbrev.size = bfd_get_section_size (sectp); |
10768 | } | |
10769 | else if (section_is_p (sectp->name, &names->info_dwo)) | |
10770 | { | |
049412e3 | 10771 | dwo_sections->info.s.section = sectp; |
80626a55 DE |
10772 | dwo_sections->info.size = bfd_get_section_size (sectp); |
10773 | } | |
10774 | else if (section_is_p (sectp->name, &names->line_dwo)) | |
10775 | { | |
049412e3 | 10776 | dwo_sections->line.s.section = sectp; |
80626a55 DE |
10777 | dwo_sections->line.size = bfd_get_section_size (sectp); |
10778 | } | |
10779 | else if (section_is_p (sectp->name, &names->loc_dwo)) | |
10780 | { | |
049412e3 | 10781 | dwo_sections->loc.s.section = sectp; |
80626a55 DE |
10782 | dwo_sections->loc.size = bfd_get_section_size (sectp); |
10783 | } | |
10784 | else if (section_is_p (sectp->name, &names->macinfo_dwo)) | |
10785 | { | |
049412e3 | 10786 | dwo_sections->macinfo.s.section = sectp; |
80626a55 DE |
10787 | dwo_sections->macinfo.size = bfd_get_section_size (sectp); |
10788 | } | |
10789 | else if (section_is_p (sectp->name, &names->macro_dwo)) | |
10790 | { | |
049412e3 | 10791 | dwo_sections->macro.s.section = sectp; |
80626a55 DE |
10792 | dwo_sections->macro.size = bfd_get_section_size (sectp); |
10793 | } | |
10794 | else if (section_is_p (sectp->name, &names->str_dwo)) | |
10795 | { | |
049412e3 | 10796 | dwo_sections->str.s.section = sectp; |
80626a55 DE |
10797 | dwo_sections->str.size = bfd_get_section_size (sectp); |
10798 | } | |
10799 | else if (section_is_p (sectp->name, &names->str_offsets_dwo)) | |
10800 | { | |
049412e3 | 10801 | dwo_sections->str_offsets.s.section = sectp; |
80626a55 DE |
10802 | dwo_sections->str_offsets.size = bfd_get_section_size (sectp); |
10803 | } | |
10804 | else if (section_is_p (sectp->name, &names->types_dwo)) | |
10805 | { | |
10806 | struct dwarf2_section_info type_section; | |
10807 | ||
10808 | memset (&type_section, 0, sizeof (type_section)); | |
049412e3 | 10809 | type_section.s.section = sectp; |
80626a55 DE |
10810 | type_section.size = bfd_get_section_size (sectp); |
10811 | VEC_safe_push (dwarf2_section_info_def, dwo_sections->types, | |
10812 | &type_section); | |
10813 | } | |
10814 | } | |
10815 | ||
ab5088bf | 10816 | /* Initialize the use of the DWO file specified by DWO_NAME and referenced |
19c3d4c9 | 10817 | by PER_CU. This is for the non-DWP case. |
80626a55 | 10818 | The result is NULL if DWO_NAME can't be found. */ |
3019eac3 DE |
10819 | |
10820 | static struct dwo_file * | |
0ac5b59e DE |
10821 | open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu, |
10822 | const char *dwo_name, const char *comp_dir) | |
3019eac3 DE |
10823 | { |
10824 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
80626a55 | 10825 | struct dwo_file *dwo_file; |
3019eac3 DE |
10826 | struct cleanup *cleanups; |
10827 | ||
192b62ce | 10828 | gdb_bfd_ref_ptr dbfd (open_dwo_file (dwo_name, comp_dir)); |
80626a55 DE |
10829 | if (dbfd == NULL) |
10830 | { | |
b4f54984 | 10831 | if (dwarf_read_debug) |
80626a55 DE |
10832 | fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name); |
10833 | return NULL; | |
10834 | } | |
10835 | dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file); | |
0ac5b59e DE |
10836 | dwo_file->dwo_name = dwo_name; |
10837 | dwo_file->comp_dir = comp_dir; | |
192b62ce | 10838 | dwo_file->dbfd = dbfd.release (); |
3019eac3 DE |
10839 | |
10840 | cleanups = make_cleanup (free_dwo_file_cleanup, dwo_file); | |
10841 | ||
192b62ce TT |
10842 | bfd_map_over_sections (dwo_file->dbfd, dwarf2_locate_dwo_sections, |
10843 | &dwo_file->sections); | |
3019eac3 | 10844 | |
33c5cd75 | 10845 | create_cus_hash_table (*dwo_file, dwo_file->sections.info, dwo_file->cus); |
3019eac3 | 10846 | |
78d4d2c5 JK |
10847 | create_debug_types_hash_table (dwo_file, dwo_file->sections.types, |
10848 | dwo_file->tus); | |
3019eac3 DE |
10849 | |
10850 | discard_cleanups (cleanups); | |
10851 | ||
b4f54984 | 10852 | if (dwarf_read_debug) |
80626a55 DE |
10853 | fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name); |
10854 | ||
3019eac3 DE |
10855 | return dwo_file; |
10856 | } | |
10857 | ||
80626a55 | 10858 | /* This function is mapped across the sections and remembers the offset and |
73869dc2 DE |
10859 | size of each of the DWP debugging sections common to version 1 and 2 that |
10860 | we are interested in. */ | |
3019eac3 | 10861 | |
80626a55 | 10862 | static void |
73869dc2 DE |
10863 | dwarf2_locate_common_dwp_sections (bfd *abfd, asection *sectp, |
10864 | void *dwp_file_ptr) | |
3019eac3 | 10865 | { |
9a3c8263 | 10866 | struct dwp_file *dwp_file = (struct dwp_file *) dwp_file_ptr; |
80626a55 DE |
10867 | const struct dwop_section_names *names = &dwop_section_names; |
10868 | unsigned int elf_section_nr = elf_section_data (sectp)->this_idx; | |
3019eac3 | 10869 | |
80626a55 | 10870 | /* Record the ELF section number for later lookup: this is what the |
73869dc2 | 10871 | .debug_cu_index,.debug_tu_index tables use in DWP V1. */ |
80626a55 DE |
10872 | gdb_assert (elf_section_nr < dwp_file->num_sections); |
10873 | dwp_file->elf_sections[elf_section_nr] = sectp; | |
3019eac3 | 10874 | |
80626a55 DE |
10875 | /* Look for specific sections that we need. */ |
10876 | if (section_is_p (sectp->name, &names->str_dwo)) | |
10877 | { | |
049412e3 | 10878 | dwp_file->sections.str.s.section = sectp; |
80626a55 DE |
10879 | dwp_file->sections.str.size = bfd_get_section_size (sectp); |
10880 | } | |
10881 | else if (section_is_p (sectp->name, &names->cu_index)) | |
10882 | { | |
049412e3 | 10883 | dwp_file->sections.cu_index.s.section = sectp; |
80626a55 DE |
10884 | dwp_file->sections.cu_index.size = bfd_get_section_size (sectp); |
10885 | } | |
10886 | else if (section_is_p (sectp->name, &names->tu_index)) | |
10887 | { | |
049412e3 | 10888 | dwp_file->sections.tu_index.s.section = sectp; |
80626a55 DE |
10889 | dwp_file->sections.tu_index.size = bfd_get_section_size (sectp); |
10890 | } | |
10891 | } | |
3019eac3 | 10892 | |
73869dc2 DE |
10893 | /* This function is mapped across the sections and remembers the offset and |
10894 | size of each of the DWP version 2 debugging sections that we are interested | |
10895 | in. This is split into a separate function because we don't know if we | |
10896 | have version 1 or 2 until we parse the cu_index/tu_index sections. */ | |
10897 | ||
10898 | static void | |
10899 | dwarf2_locate_v2_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_ptr) | |
10900 | { | |
9a3c8263 | 10901 | struct dwp_file *dwp_file = (struct dwp_file *) dwp_file_ptr; |
73869dc2 DE |
10902 | const struct dwop_section_names *names = &dwop_section_names; |
10903 | unsigned int elf_section_nr = elf_section_data (sectp)->this_idx; | |
10904 | ||
10905 | /* Record the ELF section number for later lookup: this is what the | |
10906 | .debug_cu_index,.debug_tu_index tables use in DWP V1. */ | |
10907 | gdb_assert (elf_section_nr < dwp_file->num_sections); | |
10908 | dwp_file->elf_sections[elf_section_nr] = sectp; | |
10909 | ||
10910 | /* Look for specific sections that we need. */ | |
10911 | if (section_is_p (sectp->name, &names->abbrev_dwo)) | |
10912 | { | |
049412e3 | 10913 | dwp_file->sections.abbrev.s.section = sectp; |
73869dc2 DE |
10914 | dwp_file->sections.abbrev.size = bfd_get_section_size (sectp); |
10915 | } | |
10916 | else if (section_is_p (sectp->name, &names->info_dwo)) | |
10917 | { | |
049412e3 | 10918 | dwp_file->sections.info.s.section = sectp; |
73869dc2 DE |
10919 | dwp_file->sections.info.size = bfd_get_section_size (sectp); |
10920 | } | |
10921 | else if (section_is_p (sectp->name, &names->line_dwo)) | |
10922 | { | |
049412e3 | 10923 | dwp_file->sections.line.s.section = sectp; |
73869dc2 DE |
10924 | dwp_file->sections.line.size = bfd_get_section_size (sectp); |
10925 | } | |
10926 | else if (section_is_p (sectp->name, &names->loc_dwo)) | |
10927 | { | |
049412e3 | 10928 | dwp_file->sections.loc.s.section = sectp; |
73869dc2 DE |
10929 | dwp_file->sections.loc.size = bfd_get_section_size (sectp); |
10930 | } | |
10931 | else if (section_is_p (sectp->name, &names->macinfo_dwo)) | |
10932 | { | |
049412e3 | 10933 | dwp_file->sections.macinfo.s.section = sectp; |
73869dc2 DE |
10934 | dwp_file->sections.macinfo.size = bfd_get_section_size (sectp); |
10935 | } | |
10936 | else if (section_is_p (sectp->name, &names->macro_dwo)) | |
10937 | { | |
049412e3 | 10938 | dwp_file->sections.macro.s.section = sectp; |
73869dc2 DE |
10939 | dwp_file->sections.macro.size = bfd_get_section_size (sectp); |
10940 | } | |
10941 | else if (section_is_p (sectp->name, &names->str_offsets_dwo)) | |
10942 | { | |
049412e3 | 10943 | dwp_file->sections.str_offsets.s.section = sectp; |
73869dc2 DE |
10944 | dwp_file->sections.str_offsets.size = bfd_get_section_size (sectp); |
10945 | } | |
10946 | else if (section_is_p (sectp->name, &names->types_dwo)) | |
10947 | { | |
049412e3 | 10948 | dwp_file->sections.types.s.section = sectp; |
73869dc2 DE |
10949 | dwp_file->sections.types.size = bfd_get_section_size (sectp); |
10950 | } | |
10951 | } | |
10952 | ||
80626a55 | 10953 | /* Hash function for dwp_file loaded CUs/TUs. */ |
3019eac3 | 10954 | |
80626a55 DE |
10955 | static hashval_t |
10956 | hash_dwp_loaded_cutus (const void *item) | |
10957 | { | |
9a3c8263 | 10958 | const struct dwo_unit *dwo_unit = (const struct dwo_unit *) item; |
3019eac3 | 10959 | |
80626a55 DE |
10960 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
10961 | return dwo_unit->signature; | |
3019eac3 DE |
10962 | } |
10963 | ||
80626a55 | 10964 | /* Equality function for dwp_file loaded CUs/TUs. */ |
3019eac3 | 10965 | |
80626a55 DE |
10966 | static int |
10967 | eq_dwp_loaded_cutus (const void *a, const void *b) | |
3019eac3 | 10968 | { |
9a3c8263 SM |
10969 | const struct dwo_unit *dua = (const struct dwo_unit *) a; |
10970 | const struct dwo_unit *dub = (const struct dwo_unit *) b; | |
3019eac3 | 10971 | |
80626a55 DE |
10972 | return dua->signature == dub->signature; |
10973 | } | |
3019eac3 | 10974 | |
80626a55 | 10975 | /* Allocate a hash table for dwp_file loaded CUs/TUs. */ |
3019eac3 | 10976 | |
80626a55 DE |
10977 | static htab_t |
10978 | allocate_dwp_loaded_cutus_table (struct objfile *objfile) | |
10979 | { | |
10980 | return htab_create_alloc_ex (3, | |
10981 | hash_dwp_loaded_cutus, | |
10982 | eq_dwp_loaded_cutus, | |
10983 | NULL, | |
10984 | &objfile->objfile_obstack, | |
10985 | hashtab_obstack_allocate, | |
10986 | dummy_obstack_deallocate); | |
10987 | } | |
3019eac3 | 10988 | |
ab5088bf DE |
10989 | /* Try to open DWP file FILE_NAME. |
10990 | The result is the bfd handle of the file. | |
10991 | If there is a problem finding or opening the file, return NULL. | |
10992 | Upon success, the canonicalized path of the file is stored in the bfd, | |
10993 | same as symfile_bfd_open. */ | |
10994 | ||
192b62ce | 10995 | static gdb_bfd_ref_ptr |
ab5088bf DE |
10996 | open_dwp_file (const char *file_name) |
10997 | { | |
192b62ce TT |
10998 | gdb_bfd_ref_ptr abfd (try_open_dwop_file (file_name, 1 /*is_dwp*/, |
10999 | 1 /*search_cwd*/)); | |
6ac97d4c DE |
11000 | if (abfd != NULL) |
11001 | return abfd; | |
11002 | ||
11003 | /* Work around upstream bug 15652. | |
11004 | http://sourceware.org/bugzilla/show_bug.cgi?id=15652 | |
11005 | [Whether that's a "bug" is debatable, but it is getting in our way.] | |
11006 | We have no real idea where the dwp file is, because gdb's realpath-ing | |
11007 | of the executable's path may have discarded the needed info. | |
11008 | [IWBN if the dwp file name was recorded in the executable, akin to | |
11009 | .gnu_debuglink, but that doesn't exist yet.] | |
11010 | Strip the directory from FILE_NAME and search again. */ | |
11011 | if (*debug_file_directory != '\0') | |
11012 | { | |
11013 | /* Don't implicitly search the current directory here. | |
11014 | If the user wants to search "." to handle this case, | |
11015 | it must be added to debug-file-directory. */ | |
11016 | return try_open_dwop_file (lbasename (file_name), 1 /*is_dwp*/, | |
11017 | 0 /*search_cwd*/); | |
11018 | } | |
11019 | ||
11020 | return NULL; | |
ab5088bf DE |
11021 | } |
11022 | ||
80626a55 DE |
11023 | /* Initialize the use of the DWP file for the current objfile. |
11024 | By convention the name of the DWP file is ${objfile}.dwp. | |
11025 | The result is NULL if it can't be found. */ | |
a766d390 | 11026 | |
80626a55 | 11027 | static struct dwp_file * |
ab5088bf | 11028 | open_and_init_dwp_file (void) |
80626a55 DE |
11029 | { |
11030 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
11031 | struct dwp_file *dwp_file; | |
80626a55 | 11032 | |
82bf32bc JK |
11033 | /* Try to find first .dwp for the binary file before any symbolic links |
11034 | resolving. */ | |
6c447423 DE |
11035 | |
11036 | /* If the objfile is a debug file, find the name of the real binary | |
11037 | file and get the name of dwp file from there. */ | |
d721ba37 | 11038 | std::string dwp_name; |
6c447423 DE |
11039 | if (objfile->separate_debug_objfile_backlink != NULL) |
11040 | { | |
11041 | struct objfile *backlink = objfile->separate_debug_objfile_backlink; | |
11042 | const char *backlink_basename = lbasename (backlink->original_name); | |
6c447423 | 11043 | |
d721ba37 | 11044 | dwp_name = ldirname (objfile->original_name) + SLASH_STRING + backlink_basename; |
6c447423 DE |
11045 | } |
11046 | else | |
d721ba37 PA |
11047 | dwp_name = objfile->original_name; |
11048 | ||
11049 | dwp_name += ".dwp"; | |
80626a55 | 11050 | |
d721ba37 | 11051 | gdb_bfd_ref_ptr dbfd (open_dwp_file (dwp_name.c_str ())); |
82bf32bc JK |
11052 | if (dbfd == NULL |
11053 | && strcmp (objfile->original_name, objfile_name (objfile)) != 0) | |
11054 | { | |
11055 | /* Try to find .dwp for the binary file after gdb_realpath resolving. */ | |
d721ba37 PA |
11056 | dwp_name = objfile_name (objfile); |
11057 | dwp_name += ".dwp"; | |
11058 | dbfd = open_dwp_file (dwp_name.c_str ()); | |
82bf32bc JK |
11059 | } |
11060 | ||
80626a55 DE |
11061 | if (dbfd == NULL) |
11062 | { | |
b4f54984 | 11063 | if (dwarf_read_debug) |
d721ba37 | 11064 | fprintf_unfiltered (gdb_stdlog, "DWP file not found: %s\n", dwp_name.c_str ()); |
80626a55 | 11065 | return NULL; |
3019eac3 | 11066 | } |
80626a55 | 11067 | dwp_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_file); |
192b62ce TT |
11068 | dwp_file->name = bfd_get_filename (dbfd.get ()); |
11069 | dwp_file->dbfd = dbfd.release (); | |
c906108c | 11070 | |
80626a55 | 11071 | /* +1: section 0 is unused */ |
192b62ce | 11072 | dwp_file->num_sections = bfd_count_sections (dwp_file->dbfd) + 1; |
80626a55 DE |
11073 | dwp_file->elf_sections = |
11074 | OBSTACK_CALLOC (&objfile->objfile_obstack, | |
11075 | dwp_file->num_sections, asection *); | |
11076 | ||
192b62ce TT |
11077 | bfd_map_over_sections (dwp_file->dbfd, dwarf2_locate_common_dwp_sections, |
11078 | dwp_file); | |
80626a55 DE |
11079 | |
11080 | dwp_file->cus = create_dwp_hash_table (dwp_file, 0); | |
11081 | ||
11082 | dwp_file->tus = create_dwp_hash_table (dwp_file, 1); | |
11083 | ||
73869dc2 DE |
11084 | /* The DWP file version is stored in the hash table. Oh well. */ |
11085 | if (dwp_file->cus->version != dwp_file->tus->version) | |
11086 | { | |
11087 | /* Technically speaking, we should try to limp along, but this is | |
fbcbc3fd | 11088 | pretty bizarre. We use pulongest here because that's the established |
4d65956b | 11089 | portability solution (e.g, we cannot use %u for uint32_t). */ |
fbcbc3fd DE |
11090 | error (_("Dwarf Error: DWP file CU version %s doesn't match" |
11091 | " TU version %s [in DWP file %s]"), | |
11092 | pulongest (dwp_file->cus->version), | |
d721ba37 | 11093 | pulongest (dwp_file->tus->version), dwp_name.c_str ()); |
73869dc2 DE |
11094 | } |
11095 | dwp_file->version = dwp_file->cus->version; | |
11096 | ||
11097 | if (dwp_file->version == 2) | |
192b62ce TT |
11098 | bfd_map_over_sections (dwp_file->dbfd, dwarf2_locate_v2_dwp_sections, |
11099 | dwp_file); | |
73869dc2 | 11100 | |
19ac8c2e DE |
11101 | dwp_file->loaded_cus = allocate_dwp_loaded_cutus_table (objfile); |
11102 | dwp_file->loaded_tus = allocate_dwp_loaded_cutus_table (objfile); | |
80626a55 | 11103 | |
b4f54984 | 11104 | if (dwarf_read_debug) |
80626a55 DE |
11105 | { |
11106 | fprintf_unfiltered (gdb_stdlog, "DWP file found: %s\n", dwp_file->name); | |
11107 | fprintf_unfiltered (gdb_stdlog, | |
21aa081e PA |
11108 | " %s CUs, %s TUs\n", |
11109 | pulongest (dwp_file->cus ? dwp_file->cus->nr_units : 0), | |
11110 | pulongest (dwp_file->tus ? dwp_file->tus->nr_units : 0)); | |
80626a55 DE |
11111 | } |
11112 | ||
11113 | return dwp_file; | |
3019eac3 | 11114 | } |
c906108c | 11115 | |
ab5088bf DE |
11116 | /* Wrapper around open_and_init_dwp_file, only open it once. */ |
11117 | ||
11118 | static struct dwp_file * | |
11119 | get_dwp_file (void) | |
11120 | { | |
11121 | if (! dwarf2_per_objfile->dwp_checked) | |
11122 | { | |
11123 | dwarf2_per_objfile->dwp_file = open_and_init_dwp_file (); | |
11124 | dwarf2_per_objfile->dwp_checked = 1; | |
11125 | } | |
11126 | return dwarf2_per_objfile->dwp_file; | |
11127 | } | |
11128 | ||
80626a55 DE |
11129 | /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit. |
11130 | Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME | |
11131 | or in the DWP file for the objfile, referenced by THIS_UNIT. | |
3019eac3 | 11132 | If non-NULL, comp_dir is the DW_AT_comp_dir attribute. |
80626a55 DE |
11133 | IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU. |
11134 | ||
11135 | This is called, for example, when wanting to read a variable with a | |
11136 | complex location. Therefore we don't want to do file i/o for every call. | |
11137 | Therefore we don't want to look for a DWO file on every call. | |
11138 | Therefore we first see if we've already seen SIGNATURE in a DWP file, | |
11139 | then we check if we've already seen DWO_NAME, and only THEN do we check | |
11140 | for a DWO file. | |
11141 | ||
1c658ad5 | 11142 | The result is a pointer to the dwo_unit object or NULL if we didn't find it |
80626a55 | 11143 | (dwo_id mismatch or couldn't find the DWO/DWP file). */ |
debd256d | 11144 | |
3019eac3 | 11145 | static struct dwo_unit * |
80626a55 DE |
11146 | lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit, |
11147 | const char *dwo_name, const char *comp_dir, | |
11148 | ULONGEST signature, int is_debug_types) | |
3019eac3 DE |
11149 | { |
11150 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
80626a55 DE |
11151 | const char *kind = is_debug_types ? "TU" : "CU"; |
11152 | void **dwo_file_slot; | |
3019eac3 | 11153 | struct dwo_file *dwo_file; |
80626a55 | 11154 | struct dwp_file *dwp_file; |
cb1df416 | 11155 | |
6a506a2d DE |
11156 | /* First see if there's a DWP file. |
11157 | If we have a DWP file but didn't find the DWO inside it, don't | |
11158 | look for the original DWO file. It makes gdb behave differently | |
11159 | depending on whether one is debugging in the build tree. */ | |
cf2c3c16 | 11160 | |
ab5088bf | 11161 | dwp_file = get_dwp_file (); |
80626a55 | 11162 | if (dwp_file != NULL) |
cf2c3c16 | 11163 | { |
80626a55 DE |
11164 | const struct dwp_hash_table *dwp_htab = |
11165 | is_debug_types ? dwp_file->tus : dwp_file->cus; | |
11166 | ||
11167 | if (dwp_htab != NULL) | |
11168 | { | |
11169 | struct dwo_unit *dwo_cutu = | |
57d63ce2 DE |
11170 | lookup_dwo_unit_in_dwp (dwp_file, comp_dir, |
11171 | signature, is_debug_types); | |
80626a55 DE |
11172 | |
11173 | if (dwo_cutu != NULL) | |
11174 | { | |
b4f54984 | 11175 | if (dwarf_read_debug) |
80626a55 DE |
11176 | { |
11177 | fprintf_unfiltered (gdb_stdlog, | |
11178 | "Virtual DWO %s %s found: @%s\n", | |
11179 | kind, hex_string (signature), | |
11180 | host_address_to_string (dwo_cutu)); | |
11181 | } | |
11182 | return dwo_cutu; | |
11183 | } | |
11184 | } | |
11185 | } | |
6a506a2d | 11186 | else |
80626a55 | 11187 | { |
6a506a2d | 11188 | /* No DWP file, look for the DWO file. */ |
80626a55 | 11189 | |
6a506a2d DE |
11190 | dwo_file_slot = lookup_dwo_file_slot (dwo_name, comp_dir); |
11191 | if (*dwo_file_slot == NULL) | |
80626a55 | 11192 | { |
6a506a2d DE |
11193 | /* Read in the file and build a table of the CUs/TUs it contains. */ |
11194 | *dwo_file_slot = open_and_init_dwo_file (this_unit, dwo_name, comp_dir); | |
19c3d4c9 | 11195 | } |
6a506a2d | 11196 | /* NOTE: This will be NULL if unable to open the file. */ |
9a3c8263 | 11197 | dwo_file = (struct dwo_file *) *dwo_file_slot; |
3019eac3 | 11198 | |
6a506a2d | 11199 | if (dwo_file != NULL) |
19c3d4c9 | 11200 | { |
6a506a2d DE |
11201 | struct dwo_unit *dwo_cutu = NULL; |
11202 | ||
11203 | if (is_debug_types && dwo_file->tus) | |
11204 | { | |
11205 | struct dwo_unit find_dwo_cutu; | |
11206 | ||
11207 | memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu)); | |
11208 | find_dwo_cutu.signature = signature; | |
9a3c8263 SM |
11209 | dwo_cutu |
11210 | = (struct dwo_unit *) htab_find (dwo_file->tus, &find_dwo_cutu); | |
6a506a2d | 11211 | } |
33c5cd75 | 11212 | else if (!is_debug_types && dwo_file->cus) |
80626a55 | 11213 | { |
33c5cd75 DB |
11214 | struct dwo_unit find_dwo_cutu; |
11215 | ||
11216 | memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu)); | |
11217 | find_dwo_cutu.signature = signature; | |
11218 | dwo_cutu = (struct dwo_unit *)htab_find (dwo_file->cus, | |
11219 | &find_dwo_cutu); | |
6a506a2d DE |
11220 | } |
11221 | ||
11222 | if (dwo_cutu != NULL) | |
11223 | { | |
b4f54984 | 11224 | if (dwarf_read_debug) |
6a506a2d DE |
11225 | { |
11226 | fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) found: @%s\n", | |
11227 | kind, dwo_name, hex_string (signature), | |
11228 | host_address_to_string (dwo_cutu)); | |
11229 | } | |
11230 | return dwo_cutu; | |
80626a55 DE |
11231 | } |
11232 | } | |
2e276125 | 11233 | } |
9cdd5dbd | 11234 | |
80626a55 DE |
11235 | /* We didn't find it. This could mean a dwo_id mismatch, or |
11236 | someone deleted the DWO/DWP file, or the search path isn't set up | |
11237 | correctly to find the file. */ | |
11238 | ||
b4f54984 | 11239 | if (dwarf_read_debug) |
80626a55 DE |
11240 | { |
11241 | fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) not found\n", | |
11242 | kind, dwo_name, hex_string (signature)); | |
11243 | } | |
3019eac3 | 11244 | |
6656a72d DE |
11245 | /* This is a warning and not a complaint because it can be caused by |
11246 | pilot error (e.g., user accidentally deleting the DWO). */ | |
43942612 DE |
11247 | { |
11248 | /* Print the name of the DWP file if we looked there, helps the user | |
11249 | better diagnose the problem. */ | |
11250 | char *dwp_text = NULL; | |
11251 | struct cleanup *cleanups; | |
11252 | ||
11253 | if (dwp_file != NULL) | |
11254 | dwp_text = xstrprintf (" [in DWP file %s]", lbasename (dwp_file->name)); | |
11255 | cleanups = make_cleanup (xfree, dwp_text); | |
11256 | ||
11257 | warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x" | |
11258 | " [in module %s]"), | |
11259 | kind, dwo_name, hex_string (signature), | |
11260 | dwp_text != NULL ? dwp_text : "", | |
11261 | this_unit->is_debug_types ? "TU" : "CU", | |
9c541725 | 11262 | to_underlying (this_unit->sect_off), objfile_name (objfile)); |
43942612 DE |
11263 | |
11264 | do_cleanups (cleanups); | |
11265 | } | |
3019eac3 | 11266 | return NULL; |
5fb290d7 DJ |
11267 | } |
11268 | ||
80626a55 DE |
11269 | /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU. |
11270 | See lookup_dwo_cutu_unit for details. */ | |
11271 | ||
11272 | static struct dwo_unit * | |
11273 | lookup_dwo_comp_unit (struct dwarf2_per_cu_data *this_cu, | |
11274 | const char *dwo_name, const char *comp_dir, | |
11275 | ULONGEST signature) | |
11276 | { | |
11277 | return lookup_dwo_cutu (this_cu, dwo_name, comp_dir, signature, 0); | |
11278 | } | |
11279 | ||
11280 | /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU. | |
11281 | See lookup_dwo_cutu_unit for details. */ | |
11282 | ||
11283 | static struct dwo_unit * | |
11284 | lookup_dwo_type_unit (struct signatured_type *this_tu, | |
11285 | const char *dwo_name, const char *comp_dir) | |
11286 | { | |
11287 | return lookup_dwo_cutu (&this_tu->per_cu, dwo_name, comp_dir, this_tu->signature, 1); | |
11288 | } | |
11289 | ||
89e63ee4 DE |
11290 | /* Traversal function for queue_and_load_all_dwo_tus. */ |
11291 | ||
11292 | static int | |
11293 | queue_and_load_dwo_tu (void **slot, void *info) | |
11294 | { | |
11295 | struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot; | |
11296 | struct dwarf2_per_cu_data *per_cu = (struct dwarf2_per_cu_data *) info; | |
11297 | ULONGEST signature = dwo_unit->signature; | |
11298 | struct signatured_type *sig_type = | |
11299 | lookup_dwo_signatured_type (per_cu->cu, signature); | |
11300 | ||
11301 | if (sig_type != NULL) | |
11302 | { | |
11303 | struct dwarf2_per_cu_data *sig_cu = &sig_type->per_cu; | |
11304 | ||
11305 | /* We pass NULL for DEPENDENT_CU because we don't yet know if there's | |
11306 | a real dependency of PER_CU on SIG_TYPE. That is detected later | |
11307 | while processing PER_CU. */ | |
11308 | if (maybe_queue_comp_unit (NULL, sig_cu, per_cu->cu->language)) | |
11309 | load_full_type_unit (sig_cu); | |
11310 | VEC_safe_push (dwarf2_per_cu_ptr, per_cu->imported_symtabs, sig_cu); | |
11311 | } | |
11312 | ||
11313 | return 1; | |
11314 | } | |
11315 | ||
11316 | /* Queue all TUs contained in the DWO of PER_CU to be read in. | |
11317 | The DWO may have the only definition of the type, though it may not be | |
11318 | referenced anywhere in PER_CU. Thus we have to load *all* its TUs. | |
11319 | http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */ | |
11320 | ||
11321 | static void | |
11322 | queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *per_cu) | |
11323 | { | |
11324 | struct dwo_unit *dwo_unit; | |
11325 | struct dwo_file *dwo_file; | |
11326 | ||
11327 | gdb_assert (!per_cu->is_debug_types); | |
11328 | gdb_assert (get_dwp_file () == NULL); | |
11329 | gdb_assert (per_cu->cu != NULL); | |
11330 | ||
11331 | dwo_unit = per_cu->cu->dwo_unit; | |
11332 | gdb_assert (dwo_unit != NULL); | |
11333 | ||
11334 | dwo_file = dwo_unit->dwo_file; | |
11335 | if (dwo_file->tus != NULL) | |
11336 | htab_traverse_noresize (dwo_file->tus, queue_and_load_dwo_tu, per_cu); | |
11337 | } | |
11338 | ||
3019eac3 DE |
11339 | /* Free all resources associated with DWO_FILE. |
11340 | Close the DWO file and munmap the sections. | |
11341 | All memory should be on the objfile obstack. */ | |
348e048f DE |
11342 | |
11343 | static void | |
3019eac3 | 11344 | free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile) |
348e048f | 11345 | { |
348e048f | 11346 | |
5c6fa7ab | 11347 | /* Note: dbfd is NULL for virtual DWO files. */ |
80626a55 | 11348 | gdb_bfd_unref (dwo_file->dbfd); |
348e048f | 11349 | |
3019eac3 DE |
11350 | VEC_free (dwarf2_section_info_def, dwo_file->sections.types); |
11351 | } | |
348e048f | 11352 | |
3019eac3 | 11353 | /* Wrapper for free_dwo_file for use in cleanups. */ |
348e048f | 11354 | |
3019eac3 DE |
11355 | static void |
11356 | free_dwo_file_cleanup (void *arg) | |
11357 | { | |
11358 | struct dwo_file *dwo_file = (struct dwo_file *) arg; | |
11359 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
348e048f | 11360 | |
3019eac3 DE |
11361 | free_dwo_file (dwo_file, objfile); |
11362 | } | |
348e048f | 11363 | |
3019eac3 | 11364 | /* Traversal function for free_dwo_files. */ |
2ab95328 | 11365 | |
3019eac3 DE |
11366 | static int |
11367 | free_dwo_file_from_slot (void **slot, void *info) | |
11368 | { | |
11369 | struct dwo_file *dwo_file = (struct dwo_file *) *slot; | |
11370 | struct objfile *objfile = (struct objfile *) info; | |
348e048f | 11371 | |
3019eac3 | 11372 | free_dwo_file (dwo_file, objfile); |
348e048f | 11373 | |
3019eac3 DE |
11374 | return 1; |
11375 | } | |
348e048f | 11376 | |
3019eac3 | 11377 | /* Free all resources associated with DWO_FILES. */ |
348e048f | 11378 | |
3019eac3 DE |
11379 | static void |
11380 | free_dwo_files (htab_t dwo_files, struct objfile *objfile) | |
11381 | { | |
11382 | htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile); | |
348e048f | 11383 | } |
3019eac3 DE |
11384 | \f |
11385 | /* Read in various DIEs. */ | |
348e048f | 11386 | |
d389af10 JK |
11387 | /* qsort helper for inherit_abstract_dies. */ |
11388 | ||
11389 | static int | |
11390 | unsigned_int_compar (const void *ap, const void *bp) | |
11391 | { | |
11392 | unsigned int a = *(unsigned int *) ap; | |
11393 | unsigned int b = *(unsigned int *) bp; | |
11394 | ||
11395 | return (a > b) - (b > a); | |
11396 | } | |
11397 | ||
11398 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
11399 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
11400 | already referenced by DW_AT_abstract_origin from the children of the | |
11401 | current DIE. */ | |
d389af10 JK |
11402 | |
11403 | static void | |
11404 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
11405 | { | |
11406 | struct die_info *child_die; | |
11407 | unsigned die_children_count; | |
11408 | /* CU offsets which were referenced by children of the current DIE. */ | |
b64f50a1 JK |
11409 | sect_offset *offsets; |
11410 | sect_offset *offsets_end, *offsetp; | |
d389af10 JK |
11411 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ |
11412 | struct die_info *origin_die; | |
11413 | /* Iterator of the ORIGIN_DIE children. */ | |
11414 | struct die_info *origin_child_die; | |
11415 | struct cleanup *cleanups; | |
11416 | struct attribute *attr; | |
cd02d79d PA |
11417 | struct dwarf2_cu *origin_cu; |
11418 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
11419 | |
11420 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
11421 | if (!attr) | |
11422 | return; | |
11423 | ||
cd02d79d PA |
11424 | /* Note that following die references may follow to a die in a |
11425 | different cu. */ | |
11426 | ||
11427 | origin_cu = cu; | |
11428 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
11429 | ||
11430 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
11431 | symbols in. */ | |
11432 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
11433 | origin_cu->list_in_scope = cu->list_in_scope; | |
11434 | ||
edb3359d DJ |
11435 | if (die->tag != origin_die->tag |
11436 | && !(die->tag == DW_TAG_inlined_subroutine | |
11437 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
11438 | complaint (&symfile_complaints, |
11439 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
9c541725 PA |
11440 | to_underlying (die->sect_off), |
11441 | to_underlying (origin_die->sect_off)); | |
d389af10 JK |
11442 | |
11443 | child_die = die->child; | |
11444 | die_children_count = 0; | |
11445 | while (child_die && child_die->tag) | |
11446 | { | |
11447 | child_die = sibling_die (child_die); | |
11448 | die_children_count++; | |
11449 | } | |
8d749320 | 11450 | offsets = XNEWVEC (sect_offset, die_children_count); |
d389af10 JK |
11451 | cleanups = make_cleanup (xfree, offsets); |
11452 | ||
11453 | offsets_end = offsets; | |
3ea89b92 PMR |
11454 | for (child_die = die->child; |
11455 | child_die && child_die->tag; | |
11456 | child_die = sibling_die (child_die)) | |
11457 | { | |
11458 | struct die_info *child_origin_die; | |
11459 | struct dwarf2_cu *child_origin_cu; | |
11460 | ||
11461 | /* We are trying to process concrete instance entries: | |
216f72a1 | 11462 | DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but |
3ea89b92 PMR |
11463 | it's not relevant to our analysis here. i.e. detecting DIEs that are |
11464 | present in the abstract instance but not referenced in the concrete | |
11465 | one. */ | |
216f72a1 JK |
11466 | if (child_die->tag == DW_TAG_call_site |
11467 | || child_die->tag == DW_TAG_GNU_call_site) | |
3ea89b92 PMR |
11468 | continue; |
11469 | ||
c38f313d DJ |
11470 | /* For each CHILD_DIE, find the corresponding child of |
11471 | ORIGIN_DIE. If there is more than one layer of | |
11472 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
11473 | but GCC versions at least through 4.4 generate this (GCC PR | |
11474 | 40573). */ | |
3ea89b92 PMR |
11475 | child_origin_die = child_die; |
11476 | child_origin_cu = cu; | |
c38f313d DJ |
11477 | while (1) |
11478 | { | |
cd02d79d PA |
11479 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
11480 | child_origin_cu); | |
c38f313d DJ |
11481 | if (attr == NULL) |
11482 | break; | |
cd02d79d PA |
11483 | child_origin_die = follow_die_ref (child_origin_die, attr, |
11484 | &child_origin_cu); | |
c38f313d DJ |
11485 | } |
11486 | ||
d389af10 JK |
11487 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
11488 | counterpart may exist. */ | |
c38f313d | 11489 | if (child_origin_die != child_die) |
d389af10 | 11490 | { |
edb3359d DJ |
11491 | if (child_die->tag != child_origin_die->tag |
11492 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
11493 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
11494 | complaint (&symfile_complaints, |
11495 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
9c541725 PA |
11496 | "different tags"), |
11497 | to_underlying (child_die->sect_off), | |
11498 | to_underlying (child_origin_die->sect_off)); | |
c38f313d DJ |
11499 | if (child_origin_die->parent != origin_die) |
11500 | complaint (&symfile_complaints, | |
11501 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
9c541725 PA |
11502 | "different parents"), |
11503 | to_underlying (child_die->sect_off), | |
11504 | to_underlying (child_origin_die->sect_off)); | |
c38f313d | 11505 | else |
9c541725 | 11506 | *offsets_end++ = child_origin_die->sect_off; |
d389af10 | 11507 | } |
d389af10 JK |
11508 | } |
11509 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
11510 | unsigned_int_compar); | |
11511 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
9c541725 | 11512 | if (offsetp[-1] == *offsetp) |
3e43a32a MS |
11513 | complaint (&symfile_complaints, |
11514 | _("Multiple children of DIE 0x%x refer " | |
11515 | "to DIE 0x%x as their abstract origin"), | |
9c541725 | 11516 | to_underlying (die->sect_off), to_underlying (*offsetp)); |
d389af10 JK |
11517 | |
11518 | offsetp = offsets; | |
11519 | origin_child_die = origin_die->child; | |
11520 | while (origin_child_die && origin_child_die->tag) | |
11521 | { | |
11522 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
b64f50a1 | 11523 | while (offsetp < offsets_end |
9c541725 | 11524 | && *offsetp < origin_child_die->sect_off) |
d389af10 | 11525 | offsetp++; |
b64f50a1 | 11526 | if (offsetp >= offsets_end |
9c541725 | 11527 | || *offsetp > origin_child_die->sect_off) |
d389af10 | 11528 | { |
adde2bff DE |
11529 | /* Found that ORIGIN_CHILD_DIE is really not referenced. |
11530 | Check whether we're already processing ORIGIN_CHILD_DIE. | |
11531 | This can happen with mutually referenced abstract_origins. | |
11532 | PR 16581. */ | |
11533 | if (!origin_child_die->in_process) | |
11534 | process_die (origin_child_die, origin_cu); | |
d389af10 JK |
11535 | } |
11536 | origin_child_die = sibling_die (origin_child_die); | |
11537 | } | |
cd02d79d | 11538 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
11539 | |
11540 | do_cleanups (cleanups); | |
11541 | } | |
11542 | ||
c906108c | 11543 | static void |
e7c27a73 | 11544 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11545 | { |
e7c27a73 | 11546 | struct objfile *objfile = cu->objfile; |
3e29f34a | 11547 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
fe978cb0 | 11548 | struct context_stack *newobj; |
c906108c SS |
11549 | CORE_ADDR lowpc; |
11550 | CORE_ADDR highpc; | |
11551 | struct die_info *child_die; | |
edb3359d | 11552 | struct attribute *attr, *call_line, *call_file; |
15d034d0 | 11553 | const char *name; |
e142c38c | 11554 | CORE_ADDR baseaddr; |
801e3a5b | 11555 | struct block *block; |
edb3359d | 11556 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
11557 | VEC (symbolp) *template_args = NULL; |
11558 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
11559 | |
11560 | if (inlined_func) | |
11561 | { | |
11562 | /* If we do not have call site information, we can't show the | |
11563 | caller of this inlined function. That's too confusing, so | |
11564 | only use the scope for local variables. */ | |
11565 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
11566 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
11567 | if (call_line == NULL || call_file == NULL) | |
11568 | { | |
11569 | read_lexical_block_scope (die, cu); | |
11570 | return; | |
11571 | } | |
11572 | } | |
c906108c | 11573 | |
e142c38c DJ |
11574 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
11575 | ||
94af9270 | 11576 | name = dwarf2_name (die, cu); |
c906108c | 11577 | |
e8d05480 JB |
11578 | /* Ignore functions with missing or empty names. These are actually |
11579 | illegal according to the DWARF standard. */ | |
11580 | if (name == NULL) | |
11581 | { | |
11582 | complaint (&symfile_complaints, | |
b64f50a1 | 11583 | _("missing name for subprogram DIE at %d"), |
9c541725 | 11584 | to_underlying (die->sect_off)); |
e8d05480 JB |
11585 | return; |
11586 | } | |
11587 | ||
11588 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
3a2b436a | 11589 | if (dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL) |
e385593e | 11590 | <= PC_BOUNDS_INVALID) |
e8d05480 | 11591 | { |
ae4d0c03 PM |
11592 | attr = dwarf2_attr (die, DW_AT_external, cu); |
11593 | if (!attr || !DW_UNSND (attr)) | |
11594 | complaint (&symfile_complaints, | |
3e43a32a MS |
11595 | _("cannot get low and high bounds " |
11596 | "for subprogram DIE at %d"), | |
9c541725 | 11597 | to_underlying (die->sect_off)); |
e8d05480 JB |
11598 | return; |
11599 | } | |
c906108c | 11600 | |
3e29f34a MR |
11601 | lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr); |
11602 | highpc = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr); | |
c906108c | 11603 | |
34eaf542 TT |
11604 | /* If we have any template arguments, then we must allocate a |
11605 | different sort of symbol. */ | |
11606 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
11607 | { | |
11608 | if (child_die->tag == DW_TAG_template_type_param | |
11609 | || child_die->tag == DW_TAG_template_value_param) | |
11610 | { | |
e623cf5d | 11611 | templ_func = allocate_template_symbol (objfile); |
34eaf542 TT |
11612 | templ_func->base.is_cplus_template_function = 1; |
11613 | break; | |
11614 | } | |
11615 | } | |
11616 | ||
fe978cb0 PA |
11617 | newobj = push_context (0, lowpc); |
11618 | newobj->name = new_symbol_full (die, read_type_die (die, cu), cu, | |
34eaf542 | 11619 | (struct symbol *) templ_func); |
4c2df51b | 11620 | |
4cecd739 DJ |
11621 | /* If there is a location expression for DW_AT_frame_base, record |
11622 | it. */ | |
e142c38c | 11623 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 11624 | if (attr) |
fe978cb0 | 11625 | dwarf2_symbol_mark_computed (attr, newobj->name, cu, 1); |
4c2df51b | 11626 | |
63e43d3a PMR |
11627 | /* If there is a location for the static link, record it. */ |
11628 | newobj->static_link = NULL; | |
11629 | attr = dwarf2_attr (die, DW_AT_static_link, cu); | |
11630 | if (attr) | |
11631 | { | |
224c3ddb SM |
11632 | newobj->static_link |
11633 | = XOBNEW (&objfile->objfile_obstack, struct dynamic_prop); | |
63e43d3a PMR |
11634 | attr_to_dynamic_prop (attr, die, cu, newobj->static_link); |
11635 | } | |
11636 | ||
e142c38c | 11637 | cu->list_in_scope = &local_symbols; |
c906108c | 11638 | |
639d11d3 | 11639 | if (die->child != NULL) |
c906108c | 11640 | { |
639d11d3 | 11641 | child_die = die->child; |
c906108c SS |
11642 | while (child_die && child_die->tag) |
11643 | { | |
34eaf542 TT |
11644 | if (child_die->tag == DW_TAG_template_type_param |
11645 | || child_die->tag == DW_TAG_template_value_param) | |
11646 | { | |
11647 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
11648 | ||
f1078f66 DJ |
11649 | if (arg != NULL) |
11650 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
11651 | } |
11652 | else | |
11653 | process_die (child_die, cu); | |
c906108c SS |
11654 | child_die = sibling_die (child_die); |
11655 | } | |
11656 | } | |
11657 | ||
d389af10 JK |
11658 | inherit_abstract_dies (die, cu); |
11659 | ||
4a811a97 UW |
11660 | /* If we have a DW_AT_specification, we might need to import using |
11661 | directives from the context of the specification DIE. See the | |
11662 | comment in determine_prefix. */ | |
11663 | if (cu->language == language_cplus | |
11664 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
11665 | { | |
11666 | struct dwarf2_cu *spec_cu = cu; | |
11667 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
11668 | ||
11669 | while (spec_die) | |
11670 | { | |
11671 | child_die = spec_die->child; | |
11672 | while (child_die && child_die->tag) | |
11673 | { | |
11674 | if (child_die->tag == DW_TAG_imported_module) | |
11675 | process_die (child_die, spec_cu); | |
11676 | child_die = sibling_die (child_die); | |
11677 | } | |
11678 | ||
11679 | /* In some cases, GCC generates specification DIEs that | |
11680 | themselves contain DW_AT_specification attributes. */ | |
11681 | spec_die = die_specification (spec_die, &spec_cu); | |
11682 | } | |
11683 | } | |
11684 | ||
fe978cb0 | 11685 | newobj = pop_context (); |
c906108c | 11686 | /* Make a block for the local symbols within. */ |
fe978cb0 | 11687 | block = finish_block (newobj->name, &local_symbols, newobj->old_blocks, |
63e43d3a | 11688 | newobj->static_link, lowpc, highpc); |
801e3a5b | 11689 | |
df8a16a1 | 11690 | /* For C++, set the block's scope. */ |
45280282 IB |
11691 | if ((cu->language == language_cplus |
11692 | || cu->language == language_fortran | |
c44af4eb TT |
11693 | || cu->language == language_d |
11694 | || cu->language == language_rust) | |
4d4ec4e5 | 11695 | && cu->processing_has_namespace_info) |
195a3f6c TT |
11696 | block_set_scope (block, determine_prefix (die, cu), |
11697 | &objfile->objfile_obstack); | |
df8a16a1 | 11698 | |
801e3a5b JB |
11699 | /* If we have address ranges, record them. */ |
11700 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 11701 | |
fe978cb0 | 11702 | gdbarch_make_symbol_special (gdbarch, newobj->name, objfile); |
3e29f34a | 11703 | |
34eaf542 TT |
11704 | /* Attach template arguments to function. */ |
11705 | if (! VEC_empty (symbolp, template_args)) | |
11706 | { | |
11707 | gdb_assert (templ_func != NULL); | |
11708 | ||
11709 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
11710 | templ_func->template_arguments | |
8d749320 SM |
11711 | = XOBNEWVEC (&objfile->objfile_obstack, struct symbol *, |
11712 | templ_func->n_template_arguments); | |
34eaf542 TT |
11713 | memcpy (templ_func->template_arguments, |
11714 | VEC_address (symbolp, template_args), | |
11715 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
11716 | VEC_free (symbolp, template_args); | |
11717 | } | |
11718 | ||
208d8187 JB |
11719 | /* In C++, we can have functions nested inside functions (e.g., when |
11720 | a function declares a class that has methods). This means that | |
11721 | when we finish processing a function scope, we may need to go | |
11722 | back to building a containing block's symbol lists. */ | |
fe978cb0 | 11723 | local_symbols = newobj->locals; |
22cee43f | 11724 | local_using_directives = newobj->local_using_directives; |
208d8187 | 11725 | |
921e78cf JB |
11726 | /* If we've finished processing a top-level function, subsequent |
11727 | symbols go in the file symbol list. */ | |
11728 | if (outermost_context_p ()) | |
e142c38c | 11729 | cu->list_in_scope = &file_symbols; |
c906108c SS |
11730 | } |
11731 | ||
11732 | /* Process all the DIES contained within a lexical block scope. Start | |
11733 | a new scope, process the dies, and then close the scope. */ | |
11734 | ||
11735 | static void | |
e7c27a73 | 11736 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11737 | { |
e7c27a73 | 11738 | struct objfile *objfile = cu->objfile; |
3e29f34a | 11739 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
fe978cb0 | 11740 | struct context_stack *newobj; |
c906108c SS |
11741 | CORE_ADDR lowpc, highpc; |
11742 | struct die_info *child_die; | |
e142c38c DJ |
11743 | CORE_ADDR baseaddr; |
11744 | ||
11745 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
11746 | |
11747 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
11748 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
11749 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 11750 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 11751 | describe ranges. */ |
e385593e JK |
11752 | switch (dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
11753 | { | |
11754 | case PC_BOUNDS_NOT_PRESENT: | |
11755 | /* DW_TAG_lexical_block has no attributes, process its children as if | |
11756 | there was no wrapping by that DW_TAG_lexical_block. | |
11757 | GCC does no longer produces such DWARF since GCC r224161. */ | |
11758 | for (child_die = die->child; | |
11759 | child_die != NULL && child_die->tag; | |
11760 | child_die = sibling_die (child_die)) | |
11761 | process_die (child_die, cu); | |
11762 | return; | |
11763 | case PC_BOUNDS_INVALID: | |
11764 | return; | |
11765 | } | |
3e29f34a MR |
11766 | lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr); |
11767 | highpc = gdbarch_adjust_dwarf2_addr (gdbarch, highpc + baseaddr); | |
c906108c SS |
11768 | |
11769 | push_context (0, lowpc); | |
639d11d3 | 11770 | if (die->child != NULL) |
c906108c | 11771 | { |
639d11d3 | 11772 | child_die = die->child; |
c906108c SS |
11773 | while (child_die && child_die->tag) |
11774 | { | |
e7c27a73 | 11775 | process_die (child_die, cu); |
c906108c SS |
11776 | child_die = sibling_die (child_die); |
11777 | } | |
11778 | } | |
3ea89b92 | 11779 | inherit_abstract_dies (die, cu); |
fe978cb0 | 11780 | newobj = pop_context (); |
c906108c | 11781 | |
22cee43f | 11782 | if (local_symbols != NULL || local_using_directives != NULL) |
c906108c | 11783 | { |
801e3a5b | 11784 | struct block *block |
63e43d3a | 11785 | = finish_block (0, &local_symbols, newobj->old_blocks, NULL, |
fe978cb0 | 11786 | newobj->start_addr, highpc); |
801e3a5b JB |
11787 | |
11788 | /* Note that recording ranges after traversing children, as we | |
11789 | do here, means that recording a parent's ranges entails | |
11790 | walking across all its children's ranges as they appear in | |
11791 | the address map, which is quadratic behavior. | |
11792 | ||
11793 | It would be nicer to record the parent's ranges before | |
11794 | traversing its children, simply overriding whatever you find | |
11795 | there. But since we don't even decide whether to create a | |
11796 | block until after we've traversed its children, that's hard | |
11797 | to do. */ | |
11798 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c | 11799 | } |
fe978cb0 | 11800 | local_symbols = newobj->locals; |
22cee43f | 11801 | local_using_directives = newobj->local_using_directives; |
c906108c SS |
11802 | } |
11803 | ||
216f72a1 | 11804 | /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */ |
96408a79 SA |
11805 | |
11806 | static void | |
11807 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) | |
11808 | { | |
11809 | struct objfile *objfile = cu->objfile; | |
11810 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
11811 | CORE_ADDR pc, baseaddr; | |
11812 | struct attribute *attr; | |
11813 | struct call_site *call_site, call_site_local; | |
11814 | void **slot; | |
11815 | int nparams; | |
11816 | struct die_info *child_die; | |
11817 | ||
11818 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
11819 | ||
216f72a1 JK |
11820 | attr = dwarf2_attr (die, DW_AT_call_return_pc, cu); |
11821 | if (attr == NULL) | |
11822 | { | |
11823 | /* This was a pre-DWARF-5 GNU extension alias | |
11824 | for DW_AT_call_return_pc. */ | |
11825 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
11826 | } | |
96408a79 SA |
11827 | if (!attr) |
11828 | { | |
11829 | complaint (&symfile_complaints, | |
216f72a1 | 11830 | _("missing DW_AT_call_return_pc for DW_TAG_call_site " |
96408a79 | 11831 | "DIE 0x%x [in module %s]"), |
9c541725 | 11832 | to_underlying (die->sect_off), objfile_name (objfile)); |
96408a79 SA |
11833 | return; |
11834 | } | |
31aa7e4e | 11835 | pc = attr_value_as_address (attr) + baseaddr; |
3e29f34a | 11836 | pc = gdbarch_adjust_dwarf2_addr (gdbarch, pc); |
96408a79 SA |
11837 | |
11838 | if (cu->call_site_htab == NULL) | |
11839 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, | |
11840 | NULL, &objfile->objfile_obstack, | |
11841 | hashtab_obstack_allocate, NULL); | |
11842 | call_site_local.pc = pc; | |
11843 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); | |
11844 | if (*slot != NULL) | |
11845 | { | |
11846 | complaint (&symfile_complaints, | |
216f72a1 | 11847 | _("Duplicate PC %s for DW_TAG_call_site " |
96408a79 | 11848 | "DIE 0x%x [in module %s]"), |
9c541725 | 11849 | paddress (gdbarch, pc), to_underlying (die->sect_off), |
4262abfb | 11850 | objfile_name (objfile)); |
96408a79 SA |
11851 | return; |
11852 | } | |
11853 | ||
11854 | /* Count parameters at the caller. */ | |
11855 | ||
11856 | nparams = 0; | |
11857 | for (child_die = die->child; child_die && child_die->tag; | |
11858 | child_die = sibling_die (child_die)) | |
11859 | { | |
216f72a1 JK |
11860 | if (child_die->tag != DW_TAG_call_site_parameter |
11861 | && child_die->tag != DW_TAG_GNU_call_site_parameter) | |
96408a79 SA |
11862 | { |
11863 | complaint (&symfile_complaints, | |
216f72a1 JK |
11864 | _("Tag %d is not DW_TAG_call_site_parameter in " |
11865 | "DW_TAG_call_site child DIE 0x%x [in module %s]"), | |
9c541725 | 11866 | child_die->tag, to_underlying (child_die->sect_off), |
4262abfb | 11867 | objfile_name (objfile)); |
96408a79 SA |
11868 | continue; |
11869 | } | |
11870 | ||
11871 | nparams++; | |
11872 | } | |
11873 | ||
224c3ddb SM |
11874 | call_site |
11875 | = ((struct call_site *) | |
11876 | obstack_alloc (&objfile->objfile_obstack, | |
11877 | sizeof (*call_site) | |
11878 | + (sizeof (*call_site->parameter) * (nparams - 1)))); | |
96408a79 SA |
11879 | *slot = call_site; |
11880 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); | |
11881 | call_site->pc = pc; | |
11882 | ||
216f72a1 JK |
11883 | if (dwarf2_flag_true_p (die, DW_AT_call_tail_call, cu) |
11884 | || dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) | |
96408a79 SA |
11885 | { |
11886 | struct die_info *func_die; | |
11887 | ||
11888 | /* Skip also over DW_TAG_inlined_subroutine. */ | |
11889 | for (func_die = die->parent; | |
11890 | func_die && func_die->tag != DW_TAG_subprogram | |
11891 | && func_die->tag != DW_TAG_subroutine_type; | |
11892 | func_die = func_die->parent); | |
11893 | ||
216f72a1 JK |
11894 | /* DW_AT_call_all_calls is a superset |
11895 | of DW_AT_call_all_tail_calls. */ | |
96408a79 | 11896 | if (func_die |
216f72a1 | 11897 | && !dwarf2_flag_true_p (func_die, DW_AT_call_all_calls, cu) |
96408a79 | 11898 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) |
216f72a1 | 11899 | && !dwarf2_flag_true_p (func_die, DW_AT_call_all_tail_calls, cu) |
96408a79 SA |
11900 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) |
11901 | { | |
11902 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is | |
11903 | not complete. But keep CALL_SITE for look ups via call_site_htab, | |
11904 | both the initial caller containing the real return address PC and | |
11905 | the final callee containing the current PC of a chain of tail | |
11906 | calls do not need to have the tail call list complete. But any | |
11907 | function candidate for a virtual tail call frame searched via | |
11908 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be | |
11909 | determined unambiguously. */ | |
11910 | } | |
11911 | else | |
11912 | { | |
11913 | struct type *func_type = NULL; | |
11914 | ||
11915 | if (func_die) | |
11916 | func_type = get_die_type (func_die, cu); | |
11917 | if (func_type != NULL) | |
11918 | { | |
11919 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); | |
11920 | ||
11921 | /* Enlist this call site to the function. */ | |
11922 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); | |
11923 | TYPE_TAIL_CALL_LIST (func_type) = call_site; | |
11924 | } | |
11925 | else | |
11926 | complaint (&symfile_complaints, | |
216f72a1 | 11927 | _("Cannot find function owning DW_TAG_call_site " |
96408a79 | 11928 | "DIE 0x%x [in module %s]"), |
9c541725 | 11929 | to_underlying (die->sect_off), objfile_name (objfile)); |
96408a79 SA |
11930 | } |
11931 | } | |
11932 | ||
216f72a1 JK |
11933 | attr = dwarf2_attr (die, DW_AT_call_target, cu); |
11934 | if (attr == NULL) | |
11935 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); | |
11936 | if (attr == NULL) | |
11937 | attr = dwarf2_attr (die, DW_AT_call_origin, cu); | |
96408a79 | 11938 | if (attr == NULL) |
216f72a1 JK |
11939 | { |
11940 | /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */ | |
11941 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
11942 | } | |
96408a79 SA |
11943 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); |
11944 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) | |
11945 | /* Keep NULL DWARF_BLOCK. */; | |
11946 | else if (attr_form_is_block (attr)) | |
11947 | { | |
11948 | struct dwarf2_locexpr_baton *dlbaton; | |
11949 | ||
8d749320 | 11950 | dlbaton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton); |
96408a79 SA |
11951 | dlbaton->data = DW_BLOCK (attr)->data; |
11952 | dlbaton->size = DW_BLOCK (attr)->size; | |
11953 | dlbaton->per_cu = cu->per_cu; | |
11954 | ||
11955 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); | |
11956 | } | |
7771576e | 11957 | else if (attr_form_is_ref (attr)) |
96408a79 | 11958 | { |
96408a79 SA |
11959 | struct dwarf2_cu *target_cu = cu; |
11960 | struct die_info *target_die; | |
11961 | ||
ac9ec31b | 11962 | target_die = follow_die_ref (die, attr, &target_cu); |
96408a79 SA |
11963 | gdb_assert (target_cu->objfile == objfile); |
11964 | if (die_is_declaration (target_die, target_cu)) | |
11965 | { | |
7d45c7c3 | 11966 | const char *target_physname; |
9112db09 JK |
11967 | |
11968 | /* Prefer the mangled name; otherwise compute the demangled one. */ | |
7d45c7c3 KB |
11969 | target_physname = dwarf2_string_attr (target_die, |
11970 | DW_AT_linkage_name, | |
11971 | target_cu); | |
11972 | if (target_physname == NULL) | |
11973 | target_physname = dwarf2_string_attr (target_die, | |
11974 | DW_AT_MIPS_linkage_name, | |
11975 | target_cu); | |
11976 | if (target_physname == NULL) | |
9112db09 | 11977 | target_physname = dwarf2_physname (NULL, target_die, target_cu); |
96408a79 SA |
11978 | if (target_physname == NULL) |
11979 | complaint (&symfile_complaints, | |
216f72a1 | 11980 | _("DW_AT_call_target target DIE has invalid " |
96408a79 | 11981 | "physname, for referencing DIE 0x%x [in module %s]"), |
9c541725 | 11982 | to_underlying (die->sect_off), objfile_name (objfile)); |
96408a79 | 11983 | else |
7d455152 | 11984 | SET_FIELD_PHYSNAME (call_site->target, target_physname); |
96408a79 SA |
11985 | } |
11986 | else | |
11987 | { | |
11988 | CORE_ADDR lowpc; | |
11989 | ||
11990 | /* DW_AT_entry_pc should be preferred. */ | |
3a2b436a | 11991 | if (dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL) |
e385593e | 11992 | <= PC_BOUNDS_INVALID) |
96408a79 | 11993 | complaint (&symfile_complaints, |
216f72a1 | 11994 | _("DW_AT_call_target target DIE has invalid " |
96408a79 | 11995 | "low pc, for referencing DIE 0x%x [in module %s]"), |
9c541725 | 11996 | to_underlying (die->sect_off), objfile_name (objfile)); |
96408a79 | 11997 | else |
3e29f34a MR |
11998 | { |
11999 | lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr); | |
12000 | SET_FIELD_PHYSADDR (call_site->target, lowpc); | |
12001 | } | |
96408a79 SA |
12002 | } |
12003 | } | |
12004 | else | |
12005 | complaint (&symfile_complaints, | |
216f72a1 | 12006 | _("DW_TAG_call_site DW_AT_call_target is neither " |
96408a79 | 12007 | "block nor reference, for DIE 0x%x [in module %s]"), |
9c541725 | 12008 | to_underlying (die->sect_off), objfile_name (objfile)); |
96408a79 SA |
12009 | |
12010 | call_site->per_cu = cu->per_cu; | |
12011 | ||
12012 | for (child_die = die->child; | |
12013 | child_die && child_die->tag; | |
12014 | child_die = sibling_die (child_die)) | |
12015 | { | |
96408a79 | 12016 | struct call_site_parameter *parameter; |
1788b2d3 | 12017 | struct attribute *loc, *origin; |
96408a79 | 12018 | |
216f72a1 JK |
12019 | if (child_die->tag != DW_TAG_call_site_parameter |
12020 | && child_die->tag != DW_TAG_GNU_call_site_parameter) | |
96408a79 SA |
12021 | { |
12022 | /* Already printed the complaint above. */ | |
12023 | continue; | |
12024 | } | |
12025 | ||
12026 | gdb_assert (call_site->parameter_count < nparams); | |
12027 | parameter = &call_site->parameter[call_site->parameter_count]; | |
12028 | ||
1788b2d3 JK |
12029 | /* DW_AT_location specifies the register number or DW_AT_abstract_origin |
12030 | specifies DW_TAG_formal_parameter. Value of the data assumed for the | |
216f72a1 | 12031 | register is contained in DW_AT_call_value. */ |
96408a79 | 12032 | |
24c5c679 | 12033 | loc = dwarf2_attr (child_die, DW_AT_location, cu); |
216f72a1 JK |
12034 | origin = dwarf2_attr (child_die, DW_AT_call_parameter, cu); |
12035 | if (origin == NULL) | |
12036 | { | |
12037 | /* This was a pre-DWARF-5 GNU extension alias | |
12038 | for DW_AT_call_parameter. */ | |
12039 | origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu); | |
12040 | } | |
7771576e | 12041 | if (loc == NULL && origin != NULL && attr_form_is_ref (origin)) |
1788b2d3 | 12042 | { |
1788b2d3 | 12043 | parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET; |
9c541725 PA |
12044 | |
12045 | sect_offset sect_off | |
12046 | = (sect_offset) dwarf2_get_ref_die_offset (origin); | |
12047 | if (!offset_in_cu_p (&cu->header, sect_off)) | |
d76b7dbc JK |
12048 | { |
12049 | /* As DW_OP_GNU_parameter_ref uses CU-relative offset this | |
12050 | binding can be done only inside one CU. Such referenced DIE | |
12051 | therefore cannot be even moved to DW_TAG_partial_unit. */ | |
12052 | complaint (&symfile_complaints, | |
216f72a1 JK |
12053 | _("DW_AT_call_parameter offset is not in CU for " |
12054 | "DW_TAG_call_site child DIE 0x%x [in module %s]"), | |
9c541725 PA |
12055 | to_underlying (child_die->sect_off), |
12056 | objfile_name (objfile)); | |
d76b7dbc JK |
12057 | continue; |
12058 | } | |
9c541725 PA |
12059 | parameter->u.param_cu_off |
12060 | = (cu_offset) (sect_off - cu->header.sect_off); | |
1788b2d3 JK |
12061 | } |
12062 | else if (loc == NULL || origin != NULL || !attr_form_is_block (loc)) | |
96408a79 SA |
12063 | { |
12064 | complaint (&symfile_complaints, | |
12065 | _("No DW_FORM_block* DW_AT_location for " | |
216f72a1 | 12066 | "DW_TAG_call_site child DIE 0x%x [in module %s]"), |
9c541725 | 12067 | to_underlying (child_die->sect_off), objfile_name (objfile)); |
96408a79 SA |
12068 | continue; |
12069 | } | |
24c5c679 | 12070 | else |
96408a79 | 12071 | { |
24c5c679 JK |
12072 | parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg |
12073 | (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]); | |
12074 | if (parameter->u.dwarf_reg != -1) | |
12075 | parameter->kind = CALL_SITE_PARAMETER_DWARF_REG; | |
12076 | else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data, | |
12077 | &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size], | |
12078 | ¶meter->u.fb_offset)) | |
12079 | parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET; | |
12080 | else | |
12081 | { | |
12082 | complaint (&symfile_complaints, | |
12083 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " | |
12084 | "for DW_FORM_block* DW_AT_location is supported for " | |
216f72a1 | 12085 | "DW_TAG_call_site child DIE 0x%x " |
24c5c679 | 12086 | "[in module %s]"), |
9c541725 PA |
12087 | to_underlying (child_die->sect_off), |
12088 | objfile_name (objfile)); | |
24c5c679 JK |
12089 | continue; |
12090 | } | |
96408a79 SA |
12091 | } |
12092 | ||
216f72a1 JK |
12093 | attr = dwarf2_attr (child_die, DW_AT_call_value, cu); |
12094 | if (attr == NULL) | |
12095 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); | |
96408a79 SA |
12096 | if (!attr_form_is_block (attr)) |
12097 | { | |
12098 | complaint (&symfile_complaints, | |
216f72a1 JK |
12099 | _("No DW_FORM_block* DW_AT_call_value for " |
12100 | "DW_TAG_call_site child DIE 0x%x [in module %s]"), | |
9c541725 PA |
12101 | to_underlying (child_die->sect_off), |
12102 | objfile_name (objfile)); | |
96408a79 SA |
12103 | continue; |
12104 | } | |
12105 | parameter->value = DW_BLOCK (attr)->data; | |
12106 | parameter->value_size = DW_BLOCK (attr)->size; | |
12107 | ||
12108 | /* Parameters are not pre-cleared by memset above. */ | |
12109 | parameter->data_value = NULL; | |
12110 | parameter->data_value_size = 0; | |
12111 | call_site->parameter_count++; | |
12112 | ||
216f72a1 JK |
12113 | attr = dwarf2_attr (child_die, DW_AT_call_data_value, cu); |
12114 | if (attr == NULL) | |
12115 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); | |
96408a79 SA |
12116 | if (attr) |
12117 | { | |
12118 | if (!attr_form_is_block (attr)) | |
12119 | complaint (&symfile_complaints, | |
216f72a1 JK |
12120 | _("No DW_FORM_block* DW_AT_call_data_value for " |
12121 | "DW_TAG_call_site child DIE 0x%x [in module %s]"), | |
9c541725 PA |
12122 | to_underlying (child_die->sect_off), |
12123 | objfile_name (objfile)); | |
96408a79 SA |
12124 | else |
12125 | { | |
12126 | parameter->data_value = DW_BLOCK (attr)->data; | |
12127 | parameter->data_value_size = DW_BLOCK (attr)->size; | |
12128 | } | |
12129 | } | |
12130 | } | |
12131 | } | |
12132 | ||
43988095 JK |
12133 | /* Call CALLBACK from DW_AT_ranges attribute value OFFSET |
12134 | reading .debug_rnglists. | |
12135 | Callback's type should be: | |
12136 | void (CORE_ADDR range_beginning, CORE_ADDR range_end) | |
12137 | Return true if the attributes are present and valid, otherwise, | |
12138 | return false. */ | |
12139 | ||
12140 | template <typename Callback> | |
12141 | static bool | |
12142 | dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu, | |
12143 | Callback &&callback) | |
12144 | { | |
12145 | struct objfile *objfile = cu->objfile; | |
12146 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
12147 | struct comp_unit_head *cu_header = &cu->header; | |
12148 | bfd *obfd = objfile->obfd; | |
12149 | unsigned int addr_size = cu_header->addr_size; | |
12150 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
12151 | /* Base address selection entry. */ | |
12152 | CORE_ADDR base; | |
12153 | int found_base; | |
12154 | unsigned int dummy; | |
12155 | const gdb_byte *buffer; | |
12156 | CORE_ADDR low = 0; | |
12157 | CORE_ADDR high = 0; | |
12158 | CORE_ADDR baseaddr; | |
12159 | bool overflow = false; | |
12160 | ||
12161 | found_base = cu->base_known; | |
12162 | base = cu->base_address; | |
12163 | ||
12164 | dwarf2_read_section (objfile, &dwarf2_per_objfile->rnglists); | |
12165 | if (offset >= dwarf2_per_objfile->rnglists.size) | |
12166 | { | |
12167 | complaint (&symfile_complaints, | |
12168 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
12169 | offset); | |
12170 | return false; | |
12171 | } | |
12172 | buffer = dwarf2_per_objfile->rnglists.buffer + offset; | |
12173 | ||
12174 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
12175 | ||
12176 | while (1) | |
12177 | { | |
7814882a JK |
12178 | /* Initialize it due to a false compiler warning. */ |
12179 | CORE_ADDR range_beginning = 0, range_end = 0; | |
43988095 JK |
12180 | const gdb_byte *buf_end = (dwarf2_per_objfile->rnglists.buffer |
12181 | + dwarf2_per_objfile->rnglists.size); | |
12182 | unsigned int bytes_read; | |
12183 | ||
12184 | if (buffer == buf_end) | |
12185 | { | |
12186 | overflow = true; | |
12187 | break; | |
12188 | } | |
12189 | const auto rlet = static_cast<enum dwarf_range_list_entry>(*buffer++); | |
12190 | switch (rlet) | |
12191 | { | |
12192 | case DW_RLE_end_of_list: | |
12193 | break; | |
12194 | case DW_RLE_base_address: | |
12195 | if (buffer + cu->header.addr_size > buf_end) | |
12196 | { | |
12197 | overflow = true; | |
12198 | break; | |
12199 | } | |
12200 | base = read_address (obfd, buffer, cu, &bytes_read); | |
12201 | found_base = 1; | |
12202 | buffer += bytes_read; | |
12203 | break; | |
12204 | case DW_RLE_start_length: | |
12205 | if (buffer + cu->header.addr_size > buf_end) | |
12206 | { | |
12207 | overflow = true; | |
12208 | break; | |
12209 | } | |
12210 | range_beginning = read_address (obfd, buffer, cu, &bytes_read); | |
12211 | buffer += bytes_read; | |
12212 | range_end = (range_beginning | |
12213 | + read_unsigned_leb128 (obfd, buffer, &bytes_read)); | |
12214 | buffer += bytes_read; | |
12215 | if (buffer > buf_end) | |
12216 | { | |
12217 | overflow = true; | |
12218 | break; | |
12219 | } | |
12220 | break; | |
12221 | case DW_RLE_offset_pair: | |
12222 | range_beginning = read_unsigned_leb128 (obfd, buffer, &bytes_read); | |
12223 | buffer += bytes_read; | |
12224 | if (buffer > buf_end) | |
12225 | { | |
12226 | overflow = true; | |
12227 | break; | |
12228 | } | |
12229 | range_end = read_unsigned_leb128 (obfd, buffer, &bytes_read); | |
12230 | buffer += bytes_read; | |
12231 | if (buffer > buf_end) | |
12232 | { | |
12233 | overflow = true; | |
12234 | break; | |
12235 | } | |
12236 | break; | |
12237 | case DW_RLE_start_end: | |
12238 | if (buffer + 2 * cu->header.addr_size > buf_end) | |
12239 | { | |
12240 | overflow = true; | |
12241 | break; | |
12242 | } | |
12243 | range_beginning = read_address (obfd, buffer, cu, &bytes_read); | |
12244 | buffer += bytes_read; | |
12245 | range_end = read_address (obfd, buffer, cu, &bytes_read); | |
12246 | buffer += bytes_read; | |
12247 | break; | |
12248 | default: | |
12249 | complaint (&symfile_complaints, | |
12250 | _("Invalid .debug_rnglists data (no base address)")); | |
12251 | return false; | |
12252 | } | |
12253 | if (rlet == DW_RLE_end_of_list || overflow) | |
12254 | break; | |
12255 | if (rlet == DW_RLE_base_address) | |
12256 | continue; | |
12257 | ||
12258 | if (!found_base) | |
12259 | { | |
12260 | /* We have no valid base address for the ranges | |
12261 | data. */ | |
12262 | complaint (&symfile_complaints, | |
12263 | _("Invalid .debug_rnglists data (no base address)")); | |
12264 | return false; | |
12265 | } | |
12266 | ||
12267 | if (range_beginning > range_end) | |
12268 | { | |
12269 | /* Inverted range entries are invalid. */ | |
12270 | complaint (&symfile_complaints, | |
12271 | _("Invalid .debug_rnglists data (inverted range)")); | |
12272 | return false; | |
12273 | } | |
12274 | ||
12275 | /* Empty range entries have no effect. */ | |
12276 | if (range_beginning == range_end) | |
12277 | continue; | |
12278 | ||
12279 | range_beginning += base; | |
12280 | range_end += base; | |
12281 | ||
12282 | /* A not-uncommon case of bad debug info. | |
12283 | Don't pollute the addrmap with bad data. */ | |
12284 | if (range_beginning + baseaddr == 0 | |
12285 | && !dwarf2_per_objfile->has_section_at_zero) | |
12286 | { | |
12287 | complaint (&symfile_complaints, | |
12288 | _(".debug_rnglists entry has start address of zero" | |
12289 | " [in module %s]"), objfile_name (objfile)); | |
12290 | continue; | |
12291 | } | |
12292 | ||
12293 | callback (range_beginning, range_end); | |
12294 | } | |
12295 | ||
12296 | if (overflow) | |
12297 | { | |
12298 | complaint (&symfile_complaints, | |
12299 | _("Offset %d is not terminated " | |
12300 | "for DW_AT_ranges attribute"), | |
12301 | offset); | |
12302 | return false; | |
12303 | } | |
12304 | ||
12305 | return true; | |
12306 | } | |
12307 | ||
12308 | /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges. | |
12309 | Callback's type should be: | |
12310 | void (CORE_ADDR range_beginning, CORE_ADDR range_end) | |
5f46c5a5 | 12311 | Return 1 if the attributes are present and valid, otherwise, return 0. */ |
43039443 | 12312 | |
43988095 | 12313 | template <typename Callback> |
43039443 | 12314 | static int |
5f46c5a5 | 12315 | dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, |
43988095 | 12316 | Callback &&callback) |
43039443 JK |
12317 | { |
12318 | struct objfile *objfile = cu->objfile; | |
3e29f34a | 12319 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
43039443 JK |
12320 | struct comp_unit_head *cu_header = &cu->header; |
12321 | bfd *obfd = objfile->obfd; | |
12322 | unsigned int addr_size = cu_header->addr_size; | |
12323 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
12324 | /* Base address selection entry. */ | |
12325 | CORE_ADDR base; | |
12326 | int found_base; | |
12327 | unsigned int dummy; | |
d521ce57 | 12328 | const gdb_byte *buffer; |
ff013f42 | 12329 | CORE_ADDR baseaddr; |
43039443 | 12330 | |
43988095 JK |
12331 | if (cu_header->version >= 5) |
12332 | return dwarf2_rnglists_process (offset, cu, callback); | |
12333 | ||
d00adf39 DE |
12334 | found_base = cu->base_known; |
12335 | base = cu->base_address; | |
43039443 | 12336 | |
be391dca | 12337 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 12338 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
12339 | { |
12340 | complaint (&symfile_complaints, | |
12341 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
12342 | offset); | |
12343 | return 0; | |
12344 | } | |
dce234bc | 12345 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 | 12346 | |
e7030f15 | 12347 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 12348 | |
43039443 JK |
12349 | while (1) |
12350 | { | |
12351 | CORE_ADDR range_beginning, range_end; | |
12352 | ||
12353 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
12354 | buffer += addr_size; | |
12355 | range_end = read_address (obfd, buffer, cu, &dummy); | |
12356 | buffer += addr_size; | |
12357 | offset += 2 * addr_size; | |
12358 | ||
12359 | /* An end of list marker is a pair of zero addresses. */ | |
12360 | if (range_beginning == 0 && range_end == 0) | |
12361 | /* Found the end of list entry. */ | |
12362 | break; | |
12363 | ||
12364 | /* Each base address selection entry is a pair of 2 values. | |
12365 | The first is the largest possible address, the second is | |
12366 | the base address. Check for a base address here. */ | |
12367 | if ((range_beginning & mask) == mask) | |
12368 | { | |
28d2bfb9 AB |
12369 | /* If we found the largest possible address, then we already |
12370 | have the base address in range_end. */ | |
12371 | base = range_end; | |
43039443 JK |
12372 | found_base = 1; |
12373 | continue; | |
12374 | } | |
12375 | ||
12376 | if (!found_base) | |
12377 | { | |
12378 | /* We have no valid base address for the ranges | |
12379 | data. */ | |
12380 | complaint (&symfile_complaints, | |
12381 | _("Invalid .debug_ranges data (no base address)")); | |
12382 | return 0; | |
12383 | } | |
12384 | ||
9277c30c UW |
12385 | if (range_beginning > range_end) |
12386 | { | |
12387 | /* Inverted range entries are invalid. */ | |
12388 | complaint (&symfile_complaints, | |
12389 | _("Invalid .debug_ranges data (inverted range)")); | |
12390 | return 0; | |
12391 | } | |
12392 | ||
12393 | /* Empty range entries have no effect. */ | |
12394 | if (range_beginning == range_end) | |
12395 | continue; | |
12396 | ||
43039443 JK |
12397 | range_beginning += base; |
12398 | range_end += base; | |
12399 | ||
01093045 DE |
12400 | /* A not-uncommon case of bad debug info. |
12401 | Don't pollute the addrmap with bad data. */ | |
12402 | if (range_beginning + baseaddr == 0 | |
12403 | && !dwarf2_per_objfile->has_section_at_zero) | |
12404 | { | |
12405 | complaint (&symfile_complaints, | |
12406 | _(".debug_ranges entry has start address of zero" | |
4262abfb | 12407 | " [in module %s]"), objfile_name (objfile)); |
01093045 DE |
12408 | continue; |
12409 | } | |
12410 | ||
5f46c5a5 JK |
12411 | callback (range_beginning, range_end); |
12412 | } | |
12413 | ||
12414 | return 1; | |
12415 | } | |
12416 | ||
12417 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. | |
12418 | Return 1 if the attributes are present and valid, otherwise, return 0. | |
12419 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
12420 | ||
12421 | static int | |
12422 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
12423 | CORE_ADDR *high_return, struct dwarf2_cu *cu, | |
12424 | struct partial_symtab *ranges_pst) | |
12425 | { | |
12426 | struct objfile *objfile = cu->objfile; | |
12427 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
12428 | const CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets, | |
12429 | SECT_OFF_TEXT (objfile)); | |
12430 | int low_set = 0; | |
12431 | CORE_ADDR low = 0; | |
12432 | CORE_ADDR high = 0; | |
12433 | int retval; | |
12434 | ||
12435 | retval = dwarf2_ranges_process (offset, cu, | |
12436 | [&] (CORE_ADDR range_beginning, CORE_ADDR range_end) | |
12437 | { | |
9277c30c | 12438 | if (ranges_pst != NULL) |
3e29f34a MR |
12439 | { |
12440 | CORE_ADDR lowpc; | |
12441 | CORE_ADDR highpc; | |
12442 | ||
12443 | lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, | |
12444 | range_beginning + baseaddr); | |
12445 | highpc = gdbarch_adjust_dwarf2_addr (gdbarch, | |
12446 | range_end + baseaddr); | |
12447 | addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1, | |
12448 | ranges_pst); | |
12449 | } | |
ff013f42 | 12450 | |
43039443 JK |
12451 | /* FIXME: This is recording everything as a low-high |
12452 | segment of consecutive addresses. We should have a | |
12453 | data structure for discontiguous block ranges | |
12454 | instead. */ | |
12455 | if (! low_set) | |
12456 | { | |
12457 | low = range_beginning; | |
12458 | high = range_end; | |
12459 | low_set = 1; | |
12460 | } | |
12461 | else | |
12462 | { | |
12463 | if (range_beginning < low) | |
12464 | low = range_beginning; | |
12465 | if (range_end > high) | |
12466 | high = range_end; | |
12467 | } | |
5f46c5a5 JK |
12468 | }); |
12469 | if (!retval) | |
12470 | return 0; | |
43039443 JK |
12471 | |
12472 | if (! low_set) | |
12473 | /* If the first entry is an end-of-list marker, the range | |
12474 | describes an empty scope, i.e. no instructions. */ | |
12475 | return 0; | |
12476 | ||
12477 | if (low_return) | |
12478 | *low_return = low; | |
12479 | if (high_return) | |
12480 | *high_return = high; | |
12481 | return 1; | |
12482 | } | |
12483 | ||
3a2b436a JK |
12484 | /* Get low and high pc attributes from a die. See enum pc_bounds_kind |
12485 | definition for the return value. *LOWPC and *HIGHPC are set iff | |
e385593e | 12486 | neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */ |
380bca97 | 12487 | |
3a2b436a | 12488 | static enum pc_bounds_kind |
af34e669 | 12489 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
12490 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
12491 | struct partial_symtab *pst) | |
c906108c SS |
12492 | { |
12493 | struct attribute *attr; | |
91da1414 | 12494 | struct attribute *attr_high; |
af34e669 DJ |
12495 | CORE_ADDR low = 0; |
12496 | CORE_ADDR high = 0; | |
e385593e | 12497 | enum pc_bounds_kind ret; |
c906108c | 12498 | |
91da1414 MW |
12499 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
12500 | if (attr_high) | |
af34e669 | 12501 | { |
e142c38c | 12502 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 | 12503 | if (attr) |
91da1414 | 12504 | { |
31aa7e4e JB |
12505 | low = attr_value_as_address (attr); |
12506 | high = attr_value_as_address (attr_high); | |
12507 | if (cu->header.version >= 4 && attr_form_is_constant (attr_high)) | |
12508 | high += low; | |
91da1414 | 12509 | } |
af34e669 DJ |
12510 | else |
12511 | /* Found high w/o low attribute. */ | |
e385593e | 12512 | return PC_BOUNDS_INVALID; |
af34e669 DJ |
12513 | |
12514 | /* Found consecutive range of addresses. */ | |
3a2b436a | 12515 | ret = PC_BOUNDS_HIGH_LOW; |
af34e669 | 12516 | } |
c906108c | 12517 | else |
af34e669 | 12518 | { |
e142c38c | 12519 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
12520 | if (attr != NULL) |
12521 | { | |
ab435259 DE |
12522 | /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton. |
12523 | We take advantage of the fact that DW_AT_ranges does not appear | |
12524 | in DW_TAG_compile_unit of DWO files. */ | |
12525 | int need_ranges_base = die->tag != DW_TAG_compile_unit; | |
12526 | unsigned int ranges_offset = (DW_UNSND (attr) | |
12527 | + (need_ranges_base | |
12528 | ? cu->ranges_base | |
12529 | : 0)); | |
2e3cf129 | 12530 | |
af34e669 | 12531 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 12532 | .debug_ranges section. */ |
2e3cf129 | 12533 | if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst)) |
e385593e | 12534 | return PC_BOUNDS_INVALID; |
43039443 | 12535 | /* Found discontinuous range of addresses. */ |
3a2b436a | 12536 | ret = PC_BOUNDS_RANGES; |
af34e669 | 12537 | } |
e385593e JK |
12538 | else |
12539 | return PC_BOUNDS_NOT_PRESENT; | |
af34e669 | 12540 | } |
c906108c | 12541 | |
9373cf26 JK |
12542 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
12543 | if (high <= low) | |
e385593e | 12544 | return PC_BOUNDS_INVALID; |
c906108c SS |
12545 | |
12546 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
12547 | eliminate duplicate copies of functions and vtables and such. | |
12548 | The linker will arbitrarily choose one and discard the others. | |
12549 | The AT_*_pc values for such functions refer to local labels in | |
12550 | these sections. If the section from that file was discarded, the | |
12551 | labels are not in the output, so the relocs get a value of 0. | |
12552 | If this is a discarded function, mark the pc bounds as invalid, | |
12553 | so that GDB will ignore it. */ | |
72dca2f5 | 12554 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
e385593e | 12555 | return PC_BOUNDS_INVALID; |
c906108c SS |
12556 | |
12557 | *lowpc = low; | |
96408a79 SA |
12558 | if (highpc) |
12559 | *highpc = high; | |
af34e669 | 12560 | return ret; |
c906108c SS |
12561 | } |
12562 | ||
b084d499 JB |
12563 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
12564 | its low and high PC addresses. Do nothing if these addresses could not | |
12565 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
12566 | and HIGHPC to the high address if greater than HIGHPC. */ | |
12567 | ||
12568 | static void | |
12569 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
12570 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
12571 | struct dwarf2_cu *cu) | |
12572 | { | |
12573 | CORE_ADDR low, high; | |
12574 | struct die_info *child = die->child; | |
12575 | ||
e385593e | 12576 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL) >= PC_BOUNDS_RANGES) |
b084d499 | 12577 | { |
325fac50 PA |
12578 | *lowpc = std::min (*lowpc, low); |
12579 | *highpc = std::max (*highpc, high); | |
b084d499 JB |
12580 | } |
12581 | ||
12582 | /* If the language does not allow nested subprograms (either inside | |
12583 | subprograms or lexical blocks), we're done. */ | |
12584 | if (cu->language != language_ada) | |
12585 | return; | |
6e70227d | 12586 | |
b084d499 JB |
12587 | /* Check all the children of the given DIE. If it contains nested |
12588 | subprograms, then check their pc bounds. Likewise, we need to | |
12589 | check lexical blocks as well, as they may also contain subprogram | |
12590 | definitions. */ | |
12591 | while (child && child->tag) | |
12592 | { | |
12593 | if (child->tag == DW_TAG_subprogram | |
12594 | || child->tag == DW_TAG_lexical_block) | |
12595 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
12596 | child = sibling_die (child); | |
12597 | } | |
12598 | } | |
12599 | ||
fae299cd DC |
12600 | /* Get the low and high pc's represented by the scope DIE, and store |
12601 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
12602 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
12603 | ||
12604 | static void | |
12605 | get_scope_pc_bounds (struct die_info *die, | |
12606 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
12607 | struct dwarf2_cu *cu) | |
12608 | { | |
12609 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
12610 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
12611 | CORE_ADDR current_low, current_high; | |
12612 | ||
3a2b436a | 12613 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL) |
e385593e | 12614 | >= PC_BOUNDS_RANGES) |
fae299cd DC |
12615 | { |
12616 | best_low = current_low; | |
12617 | best_high = current_high; | |
12618 | } | |
12619 | else | |
12620 | { | |
12621 | struct die_info *child = die->child; | |
12622 | ||
12623 | while (child && child->tag) | |
12624 | { | |
12625 | switch (child->tag) { | |
12626 | case DW_TAG_subprogram: | |
b084d499 | 12627 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
12628 | break; |
12629 | case DW_TAG_namespace: | |
f55ee35c | 12630 | case DW_TAG_module: |
fae299cd DC |
12631 | /* FIXME: carlton/2004-01-16: Should we do this for |
12632 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
12633 | that current GCC's always emit the DIEs corresponding | |
12634 | to definitions of methods of classes as children of a | |
12635 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
12636 | the DIEs giving the declarations, which could be | |
12637 | anywhere). But I don't see any reason why the | |
12638 | standards says that they have to be there. */ | |
12639 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
12640 | ||
12641 | if (current_low != ((CORE_ADDR) -1)) | |
12642 | { | |
325fac50 PA |
12643 | best_low = std::min (best_low, current_low); |
12644 | best_high = std::max (best_high, current_high); | |
fae299cd DC |
12645 | } |
12646 | break; | |
12647 | default: | |
0963b4bd | 12648 | /* Ignore. */ |
fae299cd DC |
12649 | break; |
12650 | } | |
12651 | ||
12652 | child = sibling_die (child); | |
12653 | } | |
12654 | } | |
12655 | ||
12656 | *lowpc = best_low; | |
12657 | *highpc = best_high; | |
12658 | } | |
12659 | ||
801e3a5b JB |
12660 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
12661 | in DIE. */ | |
380bca97 | 12662 | |
801e3a5b JB |
12663 | static void |
12664 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
12665 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
12666 | { | |
bb5ed363 | 12667 | struct objfile *objfile = cu->objfile; |
3e29f34a | 12668 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
801e3a5b | 12669 | struct attribute *attr; |
91da1414 | 12670 | struct attribute *attr_high; |
801e3a5b | 12671 | |
91da1414 MW |
12672 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
12673 | if (attr_high) | |
801e3a5b | 12674 | { |
801e3a5b JB |
12675 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
12676 | if (attr) | |
12677 | { | |
31aa7e4e JB |
12678 | CORE_ADDR low = attr_value_as_address (attr); |
12679 | CORE_ADDR high = attr_value_as_address (attr_high); | |
12680 | ||
12681 | if (cu->header.version >= 4 && attr_form_is_constant (attr_high)) | |
12682 | high += low; | |
9a619af0 | 12683 | |
3e29f34a MR |
12684 | low = gdbarch_adjust_dwarf2_addr (gdbarch, low + baseaddr); |
12685 | high = gdbarch_adjust_dwarf2_addr (gdbarch, high + baseaddr); | |
12686 | record_block_range (block, low, high - 1); | |
801e3a5b JB |
12687 | } |
12688 | } | |
12689 | ||
12690 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
12691 | if (attr) | |
12692 | { | |
bb5ed363 | 12693 | bfd *obfd = objfile->obfd; |
ab435259 DE |
12694 | /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton. |
12695 | We take advantage of the fact that DW_AT_ranges does not appear | |
12696 | in DW_TAG_compile_unit of DWO files. */ | |
12697 | int need_ranges_base = die->tag != DW_TAG_compile_unit; | |
801e3a5b JB |
12698 | |
12699 | /* The value of the DW_AT_ranges attribute is the offset of the | |
12700 | address range list in the .debug_ranges section. */ | |
ab435259 DE |
12701 | unsigned long offset = (DW_UNSND (attr) |
12702 | + (need_ranges_base ? cu->ranges_base : 0)); | |
d62bfeaf | 12703 | const gdb_byte *buffer; |
801e3a5b JB |
12704 | |
12705 | /* For some target architectures, but not others, the | |
12706 | read_address function sign-extends the addresses it returns. | |
12707 | To recognize base address selection entries, we need a | |
12708 | mask. */ | |
12709 | unsigned int addr_size = cu->header.addr_size; | |
12710 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
12711 | ||
12712 | /* The base address, to which the next pair is relative. Note | |
12713 | that this 'base' is a DWARF concept: most entries in a range | |
12714 | list are relative, to reduce the number of relocs against the | |
12715 | debugging information. This is separate from this function's | |
12716 | 'baseaddr' argument, which GDB uses to relocate debugging | |
12717 | information from a shared library based on the address at | |
12718 | which the library was loaded. */ | |
d00adf39 DE |
12719 | CORE_ADDR base = cu->base_address; |
12720 | int base_known = cu->base_known; | |
801e3a5b | 12721 | |
5f46c5a5 JK |
12722 | dwarf2_ranges_process (offset, cu, |
12723 | [&] (CORE_ADDR start, CORE_ADDR end) | |
12724 | { | |
58fdfd2c JK |
12725 | start += baseaddr; |
12726 | end += baseaddr; | |
5f46c5a5 JK |
12727 | start = gdbarch_adjust_dwarf2_addr (gdbarch, start); |
12728 | end = gdbarch_adjust_dwarf2_addr (gdbarch, end); | |
12729 | record_block_range (block, start, end - 1); | |
12730 | }); | |
801e3a5b JB |
12731 | } |
12732 | } | |
12733 | ||
685b1105 JK |
12734 | /* Check whether the producer field indicates either of GCC < 4.6, or the |
12735 | Intel C/C++ compiler, and cache the result in CU. */ | |
60d5a603 | 12736 | |
685b1105 JK |
12737 | static void |
12738 | check_producer (struct dwarf2_cu *cu) | |
60d5a603 | 12739 | { |
38360086 | 12740 | int major, minor; |
60d5a603 JK |
12741 | |
12742 | if (cu->producer == NULL) | |
12743 | { | |
12744 | /* For unknown compilers expect their behavior is DWARF version | |
12745 | compliant. | |
12746 | ||
12747 | GCC started to support .debug_types sections by -gdwarf-4 since | |
12748 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
12749 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
12750 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
12751 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
60d5a603 | 12752 | } |
b1ffba5a | 12753 | else if (producer_is_gcc (cu->producer, &major, &minor)) |
60d5a603 | 12754 | { |
38360086 MW |
12755 | cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6); |
12756 | cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3); | |
685b1105 | 12757 | } |
61012eef | 12758 | else if (startswith (cu->producer, "Intel(R) C")) |
685b1105 JK |
12759 | cu->producer_is_icc = 1; |
12760 | else | |
12761 | { | |
12762 | /* For other non-GCC compilers, expect their behavior is DWARF version | |
12763 | compliant. */ | |
60d5a603 JK |
12764 | } |
12765 | ||
ba919b58 | 12766 | cu->checked_producer = 1; |
685b1105 | 12767 | } |
ba919b58 | 12768 | |
685b1105 JK |
12769 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
12770 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
12771 | during 4.6.0 experimental. */ | |
12772 | ||
12773 | static int | |
12774 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
12775 | { | |
12776 | if (!cu->checked_producer) | |
12777 | check_producer (cu); | |
12778 | ||
12779 | return cu->producer_is_gxx_lt_4_6; | |
60d5a603 JK |
12780 | } |
12781 | ||
12782 | /* Return the default accessibility type if it is not overriden by | |
12783 | DW_AT_accessibility. */ | |
12784 | ||
12785 | static enum dwarf_access_attribute | |
12786 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
12787 | { | |
12788 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
12789 | { | |
12790 | /* The default DWARF 2 accessibility for members is public, the default | |
12791 | accessibility for inheritance is private. */ | |
12792 | ||
12793 | if (die->tag != DW_TAG_inheritance) | |
12794 | return DW_ACCESS_public; | |
12795 | else | |
12796 | return DW_ACCESS_private; | |
12797 | } | |
12798 | else | |
12799 | { | |
12800 | /* DWARF 3+ defines the default accessibility a different way. The same | |
12801 | rules apply now for DW_TAG_inheritance as for the members and it only | |
12802 | depends on the container kind. */ | |
12803 | ||
12804 | if (die->parent->tag == DW_TAG_class_type) | |
12805 | return DW_ACCESS_private; | |
12806 | else | |
12807 | return DW_ACCESS_public; | |
12808 | } | |
12809 | } | |
12810 | ||
74ac6d43 TT |
12811 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
12812 | offset. If the attribute was not found return 0, otherwise return | |
12813 | 1. If it was found but could not properly be handled, set *OFFSET | |
12814 | to 0. */ | |
12815 | ||
12816 | static int | |
12817 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
12818 | LONGEST *offset) | |
12819 | { | |
12820 | struct attribute *attr; | |
12821 | ||
12822 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
12823 | if (attr != NULL) | |
12824 | { | |
12825 | *offset = 0; | |
12826 | ||
12827 | /* Note that we do not check for a section offset first here. | |
12828 | This is because DW_AT_data_member_location is new in DWARF 4, | |
12829 | so if we see it, we can assume that a constant form is really | |
12830 | a constant and not a section offset. */ | |
12831 | if (attr_form_is_constant (attr)) | |
12832 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
12833 | else if (attr_form_is_section_offset (attr)) | |
12834 | dwarf2_complex_location_expr_complaint (); | |
12835 | else if (attr_form_is_block (attr)) | |
12836 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
12837 | else | |
12838 | dwarf2_complex_location_expr_complaint (); | |
12839 | ||
12840 | return 1; | |
12841 | } | |
12842 | ||
12843 | return 0; | |
12844 | } | |
12845 | ||
c906108c SS |
12846 | /* Add an aggregate field to the field list. */ |
12847 | ||
12848 | static void | |
107d2387 | 12849 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 12850 | struct dwarf2_cu *cu) |
6e70227d | 12851 | { |
e7c27a73 | 12852 | struct objfile *objfile = cu->objfile; |
5e2b427d | 12853 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
12854 | struct nextfield *new_field; |
12855 | struct attribute *attr; | |
12856 | struct field *fp; | |
15d034d0 | 12857 | const char *fieldname = ""; |
c906108c SS |
12858 | |
12859 | /* Allocate a new field list entry and link it in. */ | |
8d749320 | 12860 | new_field = XNEW (struct nextfield); |
b8c9b27d | 12861 | make_cleanup (xfree, new_field); |
c906108c | 12862 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
12863 | |
12864 | if (die->tag == DW_TAG_inheritance) | |
12865 | { | |
12866 | new_field->next = fip->baseclasses; | |
12867 | fip->baseclasses = new_field; | |
12868 | } | |
12869 | else | |
12870 | { | |
12871 | new_field->next = fip->fields; | |
12872 | fip->fields = new_field; | |
12873 | } | |
c906108c SS |
12874 | fip->nfields++; |
12875 | ||
e142c38c | 12876 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
12877 | if (attr) |
12878 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
12879 | else |
12880 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
12881 | if (new_field->accessibility != DW_ACCESS_public) |
12882 | fip->non_public_fields = 1; | |
60d5a603 | 12883 | |
e142c38c | 12884 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
12885 | if (attr) |
12886 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
12887 | else |
12888 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
12889 | |
12890 | fp = &new_field->field; | |
a9a9bd0f | 12891 | |
e142c38c | 12892 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 12893 | { |
74ac6d43 TT |
12894 | LONGEST offset; |
12895 | ||
a9a9bd0f | 12896 | /* Data member other than a C++ static data member. */ |
6e70227d | 12897 | |
c906108c | 12898 | /* Get type of field. */ |
e7c27a73 | 12899 | fp->type = die_type (die, cu); |
c906108c | 12900 | |
d6a843b5 | 12901 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 12902 | |
c906108c | 12903 | /* Get bit size of field (zero if none). */ |
e142c38c | 12904 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
12905 | if (attr) |
12906 | { | |
12907 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
12908 | } | |
12909 | else | |
12910 | { | |
12911 | FIELD_BITSIZE (*fp) = 0; | |
12912 | } | |
12913 | ||
12914 | /* Get bit offset of field. */ | |
74ac6d43 TT |
12915 | if (handle_data_member_location (die, cu, &offset)) |
12916 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 12917 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
12918 | if (attr) |
12919 | { | |
5e2b427d | 12920 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
12921 | { |
12922 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
12923 | additional bit offset from the MSB of the containing |
12924 | anonymous object to the MSB of the field. We don't | |
12925 | have to do anything special since we don't need to | |
12926 | know the size of the anonymous object. */ | |
f41f5e61 | 12927 | SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr)); |
c906108c SS |
12928 | } |
12929 | else | |
12930 | { | |
12931 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
12932 | MSB of the anonymous object, subtract off the number of |
12933 | bits from the MSB of the field to the MSB of the | |
12934 | object, and then subtract off the number of bits of | |
12935 | the field itself. The result is the bit offset of | |
12936 | the LSB of the field. */ | |
c906108c SS |
12937 | int anonymous_size; |
12938 | int bit_offset = DW_UNSND (attr); | |
12939 | ||
e142c38c | 12940 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
12941 | if (attr) |
12942 | { | |
12943 | /* The size of the anonymous object containing | |
12944 | the bit field is explicit, so use the | |
12945 | indicated size (in bytes). */ | |
12946 | anonymous_size = DW_UNSND (attr); | |
12947 | } | |
12948 | else | |
12949 | { | |
12950 | /* The size of the anonymous object containing | |
12951 | the bit field must be inferred from the type | |
12952 | attribute of the data member containing the | |
12953 | bit field. */ | |
12954 | anonymous_size = TYPE_LENGTH (fp->type); | |
12955 | } | |
f41f5e61 PA |
12956 | SET_FIELD_BITPOS (*fp, |
12957 | (FIELD_BITPOS (*fp) | |
12958 | + anonymous_size * bits_per_byte | |
12959 | - bit_offset - FIELD_BITSIZE (*fp))); | |
c906108c SS |
12960 | } |
12961 | } | |
da5b30da AA |
12962 | attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu); |
12963 | if (attr != NULL) | |
12964 | SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp) | |
12965 | + dwarf2_get_attr_constant_value (attr, 0))); | |
c906108c SS |
12966 | |
12967 | /* Get name of field. */ | |
39cbfefa DJ |
12968 | fieldname = dwarf2_name (die, cu); |
12969 | if (fieldname == NULL) | |
12970 | fieldname = ""; | |
d8151005 DJ |
12971 | |
12972 | /* The name is already allocated along with this objfile, so we don't | |
12973 | need to duplicate it for the type. */ | |
12974 | fp->name = fieldname; | |
c906108c SS |
12975 | |
12976 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 12977 | pointer or virtual base class pointer) to private. */ |
e142c38c | 12978 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 12979 | { |
d48cc9dd | 12980 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
12981 | new_field->accessibility = DW_ACCESS_private; |
12982 | fip->non_public_fields = 1; | |
12983 | } | |
12984 | } | |
a9a9bd0f | 12985 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 12986 | { |
a9a9bd0f DC |
12987 | /* C++ static member. */ |
12988 | ||
12989 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
12990 | is a declaration, but all versions of G++ as of this writing | |
12991 | (so through at least 3.2.1) incorrectly generate | |
12992 | DW_TAG_variable tags. */ | |
6e70227d | 12993 | |
ff355380 | 12994 | const char *physname; |
c906108c | 12995 | |
a9a9bd0f | 12996 | /* Get name of field. */ |
39cbfefa DJ |
12997 | fieldname = dwarf2_name (die, cu); |
12998 | if (fieldname == NULL) | |
c906108c SS |
12999 | return; |
13000 | ||
254e6b9e | 13001 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
13002 | if (attr |
13003 | /* Only create a symbol if this is an external value. | |
13004 | new_symbol checks this and puts the value in the global symbol | |
13005 | table, which we want. If it is not external, new_symbol | |
13006 | will try to put the value in cu->list_in_scope which is wrong. */ | |
13007 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
13008 | { |
13009 | /* A static const member, not much different than an enum as far as | |
13010 | we're concerned, except that we can support more types. */ | |
13011 | new_symbol (die, NULL, cu); | |
13012 | } | |
13013 | ||
2df3850c | 13014 | /* Get physical name. */ |
ff355380 | 13015 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 13016 | |
d8151005 DJ |
13017 | /* The name is already allocated along with this objfile, so we don't |
13018 | need to duplicate it for the type. */ | |
13019 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 13020 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 13021 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
13022 | } |
13023 | else if (die->tag == DW_TAG_inheritance) | |
13024 | { | |
74ac6d43 | 13025 | LONGEST offset; |
d4b96c9a | 13026 | |
74ac6d43 TT |
13027 | /* C++ base class field. */ |
13028 | if (handle_data_member_location (die, cu, &offset)) | |
13029 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 13030 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 13031 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
13032 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
13033 | fip->nbaseclasses++; | |
13034 | } | |
13035 | } | |
13036 | ||
98751a41 JK |
13037 | /* Add a typedef defined in the scope of the FIP's class. */ |
13038 | ||
13039 | static void | |
13040 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
13041 | struct dwarf2_cu *cu) | |
6e70227d | 13042 | { |
98751a41 | 13043 | struct typedef_field_list *new_field; |
98751a41 | 13044 | struct typedef_field *fp; |
98751a41 JK |
13045 | |
13046 | /* Allocate a new field list entry and link it in. */ | |
8d749320 | 13047 | new_field = XCNEW (struct typedef_field_list); |
98751a41 JK |
13048 | make_cleanup (xfree, new_field); |
13049 | ||
13050 | gdb_assert (die->tag == DW_TAG_typedef); | |
13051 | ||
13052 | fp = &new_field->field; | |
13053 | ||
13054 | /* Get name of field. */ | |
13055 | fp->name = dwarf2_name (die, cu); | |
13056 | if (fp->name == NULL) | |
13057 | return; | |
13058 | ||
13059 | fp->type = read_type_die (die, cu); | |
13060 | ||
13061 | new_field->next = fip->typedef_field_list; | |
13062 | fip->typedef_field_list = new_field; | |
13063 | fip->typedef_field_list_count++; | |
13064 | } | |
13065 | ||
c906108c SS |
13066 | /* Create the vector of fields, and attach it to the type. */ |
13067 | ||
13068 | static void | |
fba45db2 | 13069 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 13070 | struct dwarf2_cu *cu) |
c906108c SS |
13071 | { |
13072 | int nfields = fip->nfields; | |
13073 | ||
13074 | /* Record the field count, allocate space for the array of fields, | |
13075 | and create blank accessibility bitfields if necessary. */ | |
13076 | TYPE_NFIELDS (type) = nfields; | |
13077 | TYPE_FIELDS (type) = (struct field *) | |
13078 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
13079 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
13080 | ||
b4ba55a1 | 13081 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
13082 | { |
13083 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
13084 | ||
13085 | TYPE_FIELD_PRIVATE_BITS (type) = | |
13086 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
13087 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
13088 | ||
13089 | TYPE_FIELD_PROTECTED_BITS (type) = | |
13090 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
13091 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
13092 | ||
774b6a14 TT |
13093 | TYPE_FIELD_IGNORE_BITS (type) = |
13094 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
13095 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
13096 | } |
13097 | ||
13098 | /* If the type has baseclasses, allocate and clear a bit vector for | |
13099 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 13100 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
13101 | { |
13102 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 13103 | unsigned char *pointer; |
c906108c SS |
13104 | |
13105 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
224c3ddb | 13106 | pointer = (unsigned char *) TYPE_ALLOC (type, num_bytes); |
fe1b8b76 | 13107 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; |
c906108c SS |
13108 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
13109 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
13110 | } | |
13111 | ||
3e43a32a MS |
13112 | /* Copy the saved-up fields into the field vector. Start from the head of |
13113 | the list, adding to the tail of the field array, so that they end up in | |
13114 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
13115 | while (nfields-- > 0) |
13116 | { | |
7d0ccb61 DJ |
13117 | struct nextfield *fieldp; |
13118 | ||
13119 | if (fip->fields) | |
13120 | { | |
13121 | fieldp = fip->fields; | |
13122 | fip->fields = fieldp->next; | |
13123 | } | |
13124 | else | |
13125 | { | |
13126 | fieldp = fip->baseclasses; | |
13127 | fip->baseclasses = fieldp->next; | |
13128 | } | |
13129 | ||
13130 | TYPE_FIELD (type, nfields) = fieldp->field; | |
13131 | switch (fieldp->accessibility) | |
c906108c | 13132 | { |
c5aa993b | 13133 | case DW_ACCESS_private: |
b4ba55a1 JB |
13134 | if (cu->language != language_ada) |
13135 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 13136 | break; |
c906108c | 13137 | |
c5aa993b | 13138 | case DW_ACCESS_protected: |
b4ba55a1 JB |
13139 | if (cu->language != language_ada) |
13140 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 13141 | break; |
c906108c | 13142 | |
c5aa993b JM |
13143 | case DW_ACCESS_public: |
13144 | break; | |
c906108c | 13145 | |
c5aa993b JM |
13146 | default: |
13147 | /* Unknown accessibility. Complain and treat it as public. */ | |
13148 | { | |
e2e0b3e5 | 13149 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 13150 | fieldp->accessibility); |
c5aa993b JM |
13151 | } |
13152 | break; | |
c906108c SS |
13153 | } |
13154 | if (nfields < fip->nbaseclasses) | |
13155 | { | |
7d0ccb61 | 13156 | switch (fieldp->virtuality) |
c906108c | 13157 | { |
c5aa993b JM |
13158 | case DW_VIRTUALITY_virtual: |
13159 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 13160 | if (cu->language == language_ada) |
a73c6dcd | 13161 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
13162 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
13163 | break; | |
c906108c SS |
13164 | } |
13165 | } | |
c906108c SS |
13166 | } |
13167 | } | |
13168 | ||
7d27a96d TT |
13169 | /* Return true if this member function is a constructor, false |
13170 | otherwise. */ | |
13171 | ||
13172 | static int | |
13173 | dwarf2_is_constructor (struct die_info *die, struct dwarf2_cu *cu) | |
13174 | { | |
13175 | const char *fieldname; | |
fe978cb0 | 13176 | const char *type_name; |
7d27a96d TT |
13177 | int len; |
13178 | ||
13179 | if (die->parent == NULL) | |
13180 | return 0; | |
13181 | ||
13182 | if (die->parent->tag != DW_TAG_structure_type | |
13183 | && die->parent->tag != DW_TAG_union_type | |
13184 | && die->parent->tag != DW_TAG_class_type) | |
13185 | return 0; | |
13186 | ||
13187 | fieldname = dwarf2_name (die, cu); | |
fe978cb0 PA |
13188 | type_name = dwarf2_name (die->parent, cu); |
13189 | if (fieldname == NULL || type_name == NULL) | |
7d27a96d TT |
13190 | return 0; |
13191 | ||
13192 | len = strlen (fieldname); | |
fe978cb0 PA |
13193 | return (strncmp (fieldname, type_name, len) == 0 |
13194 | && (type_name[len] == '\0' || type_name[len] == '<')); | |
7d27a96d TT |
13195 | } |
13196 | ||
c906108c SS |
13197 | /* Add a member function to the proper fieldlist. */ |
13198 | ||
13199 | static void | |
107d2387 | 13200 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 13201 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 13202 | { |
e7c27a73 | 13203 | struct objfile *objfile = cu->objfile; |
c906108c SS |
13204 | struct attribute *attr; |
13205 | struct fnfieldlist *flp; | |
13206 | int i; | |
13207 | struct fn_field *fnp; | |
15d034d0 | 13208 | const char *fieldname; |
c906108c | 13209 | struct nextfnfield *new_fnfield; |
f792889a | 13210 | struct type *this_type; |
60d5a603 | 13211 | enum dwarf_access_attribute accessibility; |
c906108c | 13212 | |
b4ba55a1 | 13213 | if (cu->language == language_ada) |
a73c6dcd | 13214 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 13215 | |
2df3850c | 13216 | /* Get name of member function. */ |
39cbfefa DJ |
13217 | fieldname = dwarf2_name (die, cu); |
13218 | if (fieldname == NULL) | |
2df3850c | 13219 | return; |
c906108c | 13220 | |
c906108c SS |
13221 | /* Look up member function name in fieldlist. */ |
13222 | for (i = 0; i < fip->nfnfields; i++) | |
13223 | { | |
27bfe10e | 13224 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
13225 | break; |
13226 | } | |
13227 | ||
13228 | /* Create new list element if necessary. */ | |
13229 | if (i < fip->nfnfields) | |
13230 | flp = &fip->fnfieldlists[i]; | |
13231 | else | |
13232 | { | |
13233 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
13234 | { | |
13235 | fip->fnfieldlists = (struct fnfieldlist *) | |
13236 | xrealloc (fip->fnfieldlists, | |
13237 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 13238 | * sizeof (struct fnfieldlist)); |
c906108c | 13239 | if (fip->nfnfields == 0) |
c13c43fd | 13240 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
13241 | } |
13242 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
13243 | flp->name = fieldname; | |
13244 | flp->length = 0; | |
13245 | flp->head = NULL; | |
3da10d80 | 13246 | i = fip->nfnfields++; |
c906108c SS |
13247 | } |
13248 | ||
13249 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 13250 | entry. */ |
8d749320 | 13251 | new_fnfield = XNEW (struct nextfnfield); |
b8c9b27d | 13252 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
13253 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
13254 | new_fnfield->next = flp->head; | |
13255 | flp->head = new_fnfield; | |
13256 | flp->length++; | |
13257 | ||
13258 | /* Fill in the member function field info. */ | |
13259 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
13260 | |
13261 | /* Delay processing of the physname until later. */ | |
9c37b5ae | 13262 | if (cu->language == language_cplus) |
3da10d80 KS |
13263 | { |
13264 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
13265 | die, cu); | |
13266 | } | |
13267 | else | |
13268 | { | |
1d06ead6 | 13269 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
13270 | fnp->physname = physname ? physname : ""; |
13271 | } | |
13272 | ||
c906108c | 13273 | fnp->type = alloc_type (objfile); |
f792889a DJ |
13274 | this_type = read_type_die (die, cu); |
13275 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 13276 | { |
f792889a | 13277 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 13278 | |
f792889a | 13279 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
13280 | of the method itself (TYPE_CODE_METHOD). */ |
13281 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
13282 | TYPE_TARGET_TYPE (this_type), |
13283 | TYPE_FIELDS (this_type), | |
13284 | TYPE_NFIELDS (this_type), | |
13285 | TYPE_VARARGS (this_type)); | |
c906108c SS |
13286 | |
13287 | /* Handle static member functions. | |
c5aa993b | 13288 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
13289 | member functions. G++ helps GDB by marking the first |
13290 | parameter for non-static member functions (which is the this | |
13291 | pointer) as artificial. We obtain this information from | |
13292 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 13293 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
13294 | fnp->voffset = VOFFSET_STATIC; |
13295 | } | |
13296 | else | |
e2e0b3e5 | 13297 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 13298 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
13299 | |
13300 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 13301 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 13302 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 13303 | |
3e43a32a MS |
13304 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
13305 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
13306 | |
13307 | /* Get accessibility. */ | |
e142c38c | 13308 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 13309 | if (attr) |
aead7601 | 13310 | accessibility = (enum dwarf_access_attribute) DW_UNSND (attr); |
60d5a603 JK |
13311 | else |
13312 | accessibility = dwarf2_default_access_attribute (die, cu); | |
13313 | switch (accessibility) | |
c906108c | 13314 | { |
60d5a603 JK |
13315 | case DW_ACCESS_private: |
13316 | fnp->is_private = 1; | |
13317 | break; | |
13318 | case DW_ACCESS_protected: | |
13319 | fnp->is_protected = 1; | |
13320 | break; | |
c906108c SS |
13321 | } |
13322 | ||
b02dede2 | 13323 | /* Check for artificial methods. */ |
e142c38c | 13324 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
13325 | if (attr && DW_UNSND (attr) != 0) |
13326 | fnp->is_artificial = 1; | |
13327 | ||
7d27a96d TT |
13328 | fnp->is_constructor = dwarf2_is_constructor (die, cu); |
13329 | ||
0d564a31 | 13330 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
13331 | function. For older versions of GCC, this is an offset in the |
13332 | appropriate virtual table, as specified by DW_AT_containing_type. | |
13333 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
13334 | to the object address. */ |
13335 | ||
e142c38c | 13336 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 13337 | if (attr) |
8e19ed76 | 13338 | { |
aec5aa8b | 13339 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 13340 | { |
aec5aa8b TT |
13341 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
13342 | { | |
13343 | /* Old-style GCC. */ | |
13344 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
13345 | } | |
13346 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
13347 | || (DW_BLOCK (attr)->size > 1 | |
13348 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
13349 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
13350 | { | |
aec5aa8b TT |
13351 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); |
13352 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
13353 | dwarf2_complex_location_expr_complaint (); | |
13354 | else | |
13355 | fnp->voffset /= cu->header.addr_size; | |
13356 | fnp->voffset += 2; | |
13357 | } | |
13358 | else | |
13359 | dwarf2_complex_location_expr_complaint (); | |
13360 | ||
13361 | if (!fnp->fcontext) | |
7e993ebf KS |
13362 | { |
13363 | /* If there is no `this' field and no DW_AT_containing_type, | |
13364 | we cannot actually find a base class context for the | |
13365 | vtable! */ | |
13366 | if (TYPE_NFIELDS (this_type) == 0 | |
13367 | || !TYPE_FIELD_ARTIFICIAL (this_type, 0)) | |
13368 | { | |
13369 | complaint (&symfile_complaints, | |
13370 | _("cannot determine context for virtual member " | |
13371 | "function \"%s\" (offset %d)"), | |
9c541725 | 13372 | fieldname, to_underlying (die->sect_off)); |
7e993ebf KS |
13373 | } |
13374 | else | |
13375 | { | |
13376 | fnp->fcontext | |
13377 | = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
13378 | } | |
13379 | } | |
aec5aa8b | 13380 | } |
3690dd37 | 13381 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 13382 | { |
4d3c2250 | 13383 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
13384 | } |
13385 | else | |
13386 | { | |
4d3c2250 KB |
13387 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
13388 | fieldname); | |
8e19ed76 | 13389 | } |
0d564a31 | 13390 | } |
d48cc9dd DJ |
13391 | else |
13392 | { | |
13393 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
13394 | if (attr && DW_UNSND (attr)) | |
13395 | { | |
13396 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
13397 | complaint (&symfile_complaints, | |
3e43a32a MS |
13398 | _("Member function \"%s\" (offset %d) is virtual " |
13399 | "but the vtable offset is not specified"), | |
9c541725 | 13400 | fieldname, to_underlying (die->sect_off)); |
9655fd1a | 13401 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
13402 | TYPE_CPLUS_DYNAMIC (type) = 1; |
13403 | } | |
13404 | } | |
c906108c SS |
13405 | } |
13406 | ||
13407 | /* Create the vector of member function fields, and attach it to the type. */ | |
13408 | ||
13409 | static void | |
fba45db2 | 13410 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 13411 | struct dwarf2_cu *cu) |
c906108c SS |
13412 | { |
13413 | struct fnfieldlist *flp; | |
c906108c SS |
13414 | int i; |
13415 | ||
b4ba55a1 | 13416 | if (cu->language == language_ada) |
a73c6dcd | 13417 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 13418 | |
c906108c SS |
13419 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
13420 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
13421 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
13422 | ||
13423 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
13424 | { | |
13425 | struct nextfnfield *nfp = flp->head; | |
13426 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
13427 | int k; | |
13428 | ||
13429 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
13430 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
13431 | fn_flp->fn_fields = (struct fn_field *) | |
13432 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
13433 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 13434 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
13435 | } |
13436 | ||
13437 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
c906108c SS |
13438 | } |
13439 | ||
1168df01 JB |
13440 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
13441 | language, zero otherwise. */ | |
13442 | static int | |
13443 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
13444 | { | |
13445 | static const char vptr[] = "_vptr"; | |
987504bb | 13446 | static const char vtable[] = "vtable"; |
1168df01 | 13447 | |
9c37b5ae TT |
13448 | /* Look for the C++ form of the vtable. */ |
13449 | if (startswith (name, vptr) && is_cplus_marker (name[sizeof (vptr) - 1])) | |
1168df01 JB |
13450 | return 1; |
13451 | ||
13452 | return 0; | |
13453 | } | |
13454 | ||
c0dd20ea | 13455 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
13456 | functions, with the ABI-specified layout. If TYPE describes |
13457 | such a structure, smash it into a member function type. | |
61049d3b DJ |
13458 | |
13459 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
13460 | This is GCC PR debug/28767. */ | |
c0dd20ea | 13461 | |
0b92b5bb TT |
13462 | static void |
13463 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 13464 | { |
09e2d7c7 | 13465 | struct type *pfn_type, *self_type, *new_type; |
c0dd20ea DJ |
13466 | |
13467 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
13468 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
13469 | return; | |
c0dd20ea DJ |
13470 | |
13471 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
13472 | if (TYPE_FIELD_NAME (type, 0) == NULL |
13473 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
13474 | || TYPE_FIELD_NAME (type, 1) == NULL | |
13475 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
13476 | return; | |
c0dd20ea DJ |
13477 | |
13478 | /* Find the type of the method. */ | |
0b92b5bb | 13479 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
13480 | if (pfn_type == NULL |
13481 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
13482 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 13483 | return; |
c0dd20ea DJ |
13484 | |
13485 | /* Look for the "this" argument. */ | |
13486 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
13487 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 13488 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 13489 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 13490 | return; |
c0dd20ea | 13491 | |
09e2d7c7 | 13492 | self_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); |
0b92b5bb | 13493 | new_type = alloc_type (objfile); |
09e2d7c7 | 13494 | smash_to_method_type (new_type, self_type, TYPE_TARGET_TYPE (pfn_type), |
c0dd20ea DJ |
13495 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
13496 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 13497 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 13498 | } |
1168df01 | 13499 | |
685b1105 JK |
13500 | /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler |
13501 | (icc). */ | |
13502 | ||
13503 | static int | |
13504 | producer_is_icc (struct dwarf2_cu *cu) | |
13505 | { | |
13506 | if (!cu->checked_producer) | |
13507 | check_producer (cu); | |
13508 | ||
13509 | return cu->producer_is_icc; | |
13510 | } | |
13511 | ||
c906108c | 13512 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
13513 | (definition) to create a type for the structure or union. Fill in |
13514 | the type's name and general properties; the members will not be | |
83655187 DE |
13515 | processed until process_structure_scope. A symbol table entry for |
13516 | the type will also not be done until process_structure_scope (assuming | |
13517 | the type has a name). | |
c906108c | 13518 | |
c767944b DJ |
13519 | NOTE: we need to call these functions regardless of whether or not the |
13520 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c | 13521 | structure or union. This gets the type entered into our set of |
83655187 | 13522 | user defined types. */ |
c906108c | 13523 | |
f792889a | 13524 | static struct type * |
134d01f1 | 13525 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13526 | { |
e7c27a73 | 13527 | struct objfile *objfile = cu->objfile; |
c906108c SS |
13528 | struct type *type; |
13529 | struct attribute *attr; | |
15d034d0 | 13530 | const char *name; |
c906108c | 13531 | |
348e048f DE |
13532 | /* If the definition of this type lives in .debug_types, read that type. |
13533 | Don't follow DW_AT_specification though, that will take us back up | |
13534 | the chain and we want to go down. */ | |
45e58e77 | 13535 | attr = dwarf2_attr_no_follow (die, DW_AT_signature); |
348e048f DE |
13536 | if (attr) |
13537 | { | |
ac9ec31b | 13538 | type = get_DW_AT_signature_type (die, attr, cu); |
9dc481d3 | 13539 | |
ac9ec31b | 13540 | /* The type's CU may not be the same as CU. |
02142a6c | 13541 | Ensure TYPE is recorded with CU in die_type_hash. */ |
348e048f DE |
13542 | return set_die_type (die, type, cu); |
13543 | } | |
13544 | ||
c0dd20ea | 13545 | type = alloc_type (objfile); |
c906108c | 13546 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 13547 | |
39cbfefa DJ |
13548 | name = dwarf2_name (die, cu); |
13549 | if (name != NULL) | |
c906108c | 13550 | { |
987504bb | 13551 | if (cu->language == language_cplus |
c44af4eb TT |
13552 | || cu->language == language_d |
13553 | || cu->language == language_rust) | |
63d06c5c | 13554 | { |
15d034d0 | 13555 | const char *full_name = dwarf2_full_name (name, die, cu); |
3da10d80 KS |
13556 | |
13557 | /* dwarf2_full_name might have already finished building the DIE's | |
13558 | type. If so, there is no need to continue. */ | |
13559 | if (get_die_type (die, cu) != NULL) | |
13560 | return get_die_type (die, cu); | |
13561 | ||
13562 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
13563 | if (die->tag == DW_TAG_structure_type |
13564 | || die->tag == DW_TAG_class_type) | |
13565 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
13566 | } |
13567 | else | |
13568 | { | |
d8151005 DJ |
13569 | /* The name is already allocated along with this objfile, so |
13570 | we don't need to duplicate it for the type. */ | |
7d455152 | 13571 | TYPE_TAG_NAME (type) = name; |
94af9270 KS |
13572 | if (die->tag == DW_TAG_class_type) |
13573 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 13574 | } |
c906108c SS |
13575 | } |
13576 | ||
13577 | if (die->tag == DW_TAG_structure_type) | |
13578 | { | |
13579 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
13580 | } | |
13581 | else if (die->tag == DW_TAG_union_type) | |
13582 | { | |
13583 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
13584 | } | |
13585 | else | |
13586 | { | |
4753d33b | 13587 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
c906108c SS |
13588 | } |
13589 | ||
0cc2414c TT |
13590 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
13591 | TYPE_DECLARED_CLASS (type) = 1; | |
13592 | ||
e142c38c | 13593 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
13594 | if (attr) |
13595 | { | |
155bfbd3 JB |
13596 | if (attr_form_is_constant (attr)) |
13597 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
13598 | else | |
13599 | { | |
13600 | /* For the moment, dynamic type sizes are not supported | |
13601 | by GDB's struct type. The actual size is determined | |
13602 | on-demand when resolving the type of a given object, | |
13603 | so set the type's length to zero for now. Otherwise, | |
13604 | we record an expression as the length, and that expression | |
13605 | could lead to a very large value, which could eventually | |
13606 | lead to us trying to allocate that much memory when creating | |
13607 | a value of that type. */ | |
13608 | TYPE_LENGTH (type) = 0; | |
13609 | } | |
c906108c SS |
13610 | } |
13611 | else | |
13612 | { | |
13613 | TYPE_LENGTH (type) = 0; | |
13614 | } | |
13615 | ||
422b1cb0 | 13616 | if (producer_is_icc (cu) && (TYPE_LENGTH (type) == 0)) |
685b1105 JK |
13617 | { |
13618 | /* ICC does not output the required DW_AT_declaration | |
13619 | on incomplete types, but gives them a size of zero. */ | |
422b1cb0 | 13620 | TYPE_STUB (type) = 1; |
685b1105 JK |
13621 | } |
13622 | else | |
13623 | TYPE_STUB_SUPPORTED (type) = 1; | |
13624 | ||
dc718098 | 13625 | if (die_is_declaration (die, cu)) |
876cecd0 | 13626 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
13627 | else if (attr == NULL && die->child == NULL |
13628 | && producer_is_realview (cu->producer)) | |
13629 | /* RealView does not output the required DW_AT_declaration | |
13630 | on incomplete types. */ | |
13631 | TYPE_STUB (type) = 1; | |
dc718098 | 13632 | |
c906108c SS |
13633 | /* We need to add the type field to the die immediately so we don't |
13634 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 13635 | type within the structure itself. */ |
1c379e20 | 13636 | set_die_type (die, type, cu); |
c906108c | 13637 | |
7e314c57 JK |
13638 | /* set_die_type should be already done. */ |
13639 | set_descriptive_type (type, die, cu); | |
13640 | ||
c767944b DJ |
13641 | return type; |
13642 | } | |
13643 | ||
13644 | /* Finish creating a structure or union type, including filling in | |
13645 | its members and creating a symbol for it. */ | |
13646 | ||
13647 | static void | |
13648 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
13649 | { | |
13650 | struct objfile *objfile = cu->objfile; | |
ca040673 | 13651 | struct die_info *child_die; |
c767944b DJ |
13652 | struct type *type; |
13653 | ||
13654 | type = get_die_type (die, cu); | |
13655 | if (type == NULL) | |
13656 | type = read_structure_type (die, cu); | |
13657 | ||
e142c38c | 13658 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
13659 | { |
13660 | struct field_info fi; | |
34eaf542 | 13661 | VEC (symbolp) *template_args = NULL; |
c767944b | 13662 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
13663 | |
13664 | memset (&fi, 0, sizeof (struct field_info)); | |
13665 | ||
639d11d3 | 13666 | child_die = die->child; |
c906108c SS |
13667 | |
13668 | while (child_die && child_die->tag) | |
13669 | { | |
a9a9bd0f DC |
13670 | if (child_die->tag == DW_TAG_member |
13671 | || child_die->tag == DW_TAG_variable) | |
c906108c | 13672 | { |
a9a9bd0f DC |
13673 | /* NOTE: carlton/2002-11-05: A C++ static data member |
13674 | should be a DW_TAG_member that is a declaration, but | |
13675 | all versions of G++ as of this writing (so through at | |
13676 | least 3.2.1) incorrectly generate DW_TAG_variable | |
13677 | tags for them instead. */ | |
e7c27a73 | 13678 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 13679 | } |
8713b1b1 | 13680 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 13681 | { |
e98c9e7c TT |
13682 | /* Rust doesn't have member functions in the C++ sense. |
13683 | However, it does emit ordinary functions as children | |
13684 | of a struct DIE. */ | |
13685 | if (cu->language == language_rust) | |
13686 | read_func_scope (child_die, cu); | |
13687 | else | |
13688 | { | |
13689 | /* C++ member function. */ | |
13690 | dwarf2_add_member_fn (&fi, child_die, type, cu); | |
13691 | } | |
c906108c SS |
13692 | } |
13693 | else if (child_die->tag == DW_TAG_inheritance) | |
13694 | { | |
13695 | /* C++ base class field. */ | |
e7c27a73 | 13696 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 13697 | } |
98751a41 JK |
13698 | else if (child_die->tag == DW_TAG_typedef) |
13699 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
13700 | else if (child_die->tag == DW_TAG_template_type_param |
13701 | || child_die->tag == DW_TAG_template_value_param) | |
13702 | { | |
13703 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
13704 | ||
f1078f66 DJ |
13705 | if (arg != NULL) |
13706 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
13707 | } |
13708 | ||
c906108c SS |
13709 | child_die = sibling_die (child_die); |
13710 | } | |
13711 | ||
34eaf542 TT |
13712 | /* Attach template arguments to type. */ |
13713 | if (! VEC_empty (symbolp, template_args)) | |
13714 | { | |
13715 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
13716 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
13717 | = VEC_length (symbolp, template_args); | |
13718 | TYPE_TEMPLATE_ARGUMENTS (type) | |
8d749320 SM |
13719 | = XOBNEWVEC (&objfile->objfile_obstack, |
13720 | struct symbol *, | |
13721 | TYPE_N_TEMPLATE_ARGUMENTS (type)); | |
34eaf542 TT |
13722 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), |
13723 | VEC_address (symbolp, template_args), | |
13724 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
13725 | * sizeof (struct symbol *))); | |
13726 | VEC_free (symbolp, template_args); | |
13727 | } | |
13728 | ||
c906108c SS |
13729 | /* Attach fields and member functions to the type. */ |
13730 | if (fi.nfields) | |
e7c27a73 | 13731 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
13732 | if (fi.nfnfields) |
13733 | { | |
e7c27a73 | 13734 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 13735 | |
c5aa993b | 13736 | /* Get the type which refers to the base class (possibly this |
c906108c | 13737 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
13738 | class from the DW_AT_containing_type attribute. This use of |
13739 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 13740 | |
e142c38c | 13741 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 13742 | { |
e7c27a73 | 13743 | struct type *t = die_containing_type (die, cu); |
c906108c | 13744 | |
ae6ae975 | 13745 | set_type_vptr_basetype (type, t); |
c906108c SS |
13746 | if (type == t) |
13747 | { | |
c906108c SS |
13748 | int i; |
13749 | ||
13750 | /* Our own class provides vtbl ptr. */ | |
13751 | for (i = TYPE_NFIELDS (t) - 1; | |
13752 | i >= TYPE_N_BASECLASSES (t); | |
13753 | --i) | |
13754 | { | |
0d5cff50 | 13755 | const char *fieldname = TYPE_FIELD_NAME (t, i); |
c906108c | 13756 | |
1168df01 | 13757 | if (is_vtable_name (fieldname, cu)) |
c906108c | 13758 | { |
ae6ae975 | 13759 | set_type_vptr_fieldno (type, i); |
c906108c SS |
13760 | break; |
13761 | } | |
13762 | } | |
13763 | ||
13764 | /* Complain if virtual function table field not found. */ | |
13765 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 13766 | complaint (&symfile_complaints, |
3e43a32a MS |
13767 | _("virtual function table pointer " |
13768 | "not found when defining class '%s'"), | |
4d3c2250 KB |
13769 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
13770 | ""); | |
c906108c SS |
13771 | } |
13772 | else | |
13773 | { | |
ae6ae975 | 13774 | set_type_vptr_fieldno (type, TYPE_VPTR_FIELDNO (t)); |
c906108c SS |
13775 | } |
13776 | } | |
f6235d4c | 13777 | else if (cu->producer |
61012eef | 13778 | && startswith (cu->producer, "IBM(R) XL C/C++ Advanced Edition")) |
f6235d4c EZ |
13779 | { |
13780 | /* The IBM XLC compiler does not provide direct indication | |
13781 | of the containing type, but the vtable pointer is | |
13782 | always named __vfp. */ | |
13783 | ||
13784 | int i; | |
13785 | ||
13786 | for (i = TYPE_NFIELDS (type) - 1; | |
13787 | i >= TYPE_N_BASECLASSES (type); | |
13788 | --i) | |
13789 | { | |
13790 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
13791 | { | |
ae6ae975 DE |
13792 | set_type_vptr_fieldno (type, i); |
13793 | set_type_vptr_basetype (type, type); | |
f6235d4c EZ |
13794 | break; |
13795 | } | |
13796 | } | |
13797 | } | |
c906108c | 13798 | } |
98751a41 JK |
13799 | |
13800 | /* Copy fi.typedef_field_list linked list elements content into the | |
13801 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
13802 | if (fi.typedef_field_list) | |
13803 | { | |
13804 | int i = fi.typedef_field_list_count; | |
13805 | ||
a0d7a4ff | 13806 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 | 13807 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
224c3ddb SM |
13808 | = ((struct typedef_field *) |
13809 | TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i)); | |
98751a41 JK |
13810 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; |
13811 | ||
13812 | /* Reverse the list order to keep the debug info elements order. */ | |
13813 | while (--i >= 0) | |
13814 | { | |
13815 | struct typedef_field *dest, *src; | |
6e70227d | 13816 | |
98751a41 JK |
13817 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
13818 | src = &fi.typedef_field_list->field; | |
13819 | fi.typedef_field_list = fi.typedef_field_list->next; | |
13820 | *dest = *src; | |
13821 | } | |
13822 | } | |
c767944b DJ |
13823 | |
13824 | do_cleanups (back_to); | |
c906108c | 13825 | } |
63d06c5c | 13826 | |
bb5ed363 | 13827 | quirk_gcc_member_function_pointer (type, objfile); |
0b92b5bb | 13828 | |
90aeadfc DC |
13829 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
13830 | snapshots) has been known to create a die giving a declaration | |
13831 | for a class that has, as a child, a die giving a definition for a | |
13832 | nested class. So we have to process our children even if the | |
13833 | current die is a declaration. Normally, of course, a declaration | |
13834 | won't have any children at all. */ | |
134d01f1 | 13835 | |
ca040673 DE |
13836 | child_die = die->child; |
13837 | ||
90aeadfc DC |
13838 | while (child_die != NULL && child_die->tag) |
13839 | { | |
13840 | if (child_die->tag == DW_TAG_member | |
13841 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
13842 | || child_die->tag == DW_TAG_inheritance |
13843 | || child_die->tag == DW_TAG_template_value_param | |
13844 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 13845 | { |
90aeadfc | 13846 | /* Do nothing. */ |
134d01f1 | 13847 | } |
90aeadfc DC |
13848 | else |
13849 | process_die (child_die, cu); | |
134d01f1 | 13850 | |
90aeadfc | 13851 | child_die = sibling_die (child_die); |
134d01f1 DJ |
13852 | } |
13853 | ||
fa4028e9 JB |
13854 | /* Do not consider external references. According to the DWARF standard, |
13855 | these DIEs are identified by the fact that they have no byte_size | |
13856 | attribute, and a declaration attribute. */ | |
13857 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
13858 | || !die_is_declaration (die, cu)) | |
c767944b | 13859 | new_symbol (die, type, cu); |
134d01f1 DJ |
13860 | } |
13861 | ||
55426c9d JB |
13862 | /* Assuming DIE is an enumeration type, and TYPE is its associated type, |
13863 | update TYPE using some information only available in DIE's children. */ | |
13864 | ||
13865 | static void | |
13866 | update_enumeration_type_from_children (struct die_info *die, | |
13867 | struct type *type, | |
13868 | struct dwarf2_cu *cu) | |
13869 | { | |
60f7655a | 13870 | struct die_info *child_die; |
55426c9d JB |
13871 | int unsigned_enum = 1; |
13872 | int flag_enum = 1; | |
13873 | ULONGEST mask = 0; | |
55426c9d | 13874 | |
8268c778 | 13875 | auto_obstack obstack; |
55426c9d | 13876 | |
60f7655a DE |
13877 | for (child_die = die->child; |
13878 | child_die != NULL && child_die->tag; | |
13879 | child_die = sibling_die (child_die)) | |
55426c9d JB |
13880 | { |
13881 | struct attribute *attr; | |
13882 | LONGEST value; | |
13883 | const gdb_byte *bytes; | |
13884 | struct dwarf2_locexpr_baton *baton; | |
13885 | const char *name; | |
60f7655a | 13886 | |
55426c9d JB |
13887 | if (child_die->tag != DW_TAG_enumerator) |
13888 | continue; | |
13889 | ||
13890 | attr = dwarf2_attr (child_die, DW_AT_const_value, cu); | |
13891 | if (attr == NULL) | |
13892 | continue; | |
13893 | ||
13894 | name = dwarf2_name (child_die, cu); | |
13895 | if (name == NULL) | |
13896 | name = "<anonymous enumerator>"; | |
13897 | ||
13898 | dwarf2_const_value_attr (attr, type, name, &obstack, cu, | |
13899 | &value, &bytes, &baton); | |
13900 | if (value < 0) | |
13901 | { | |
13902 | unsigned_enum = 0; | |
13903 | flag_enum = 0; | |
13904 | } | |
13905 | else if ((mask & value) != 0) | |
13906 | flag_enum = 0; | |
13907 | else | |
13908 | mask |= value; | |
13909 | ||
13910 | /* If we already know that the enum type is neither unsigned, nor | |
13911 | a flag type, no need to look at the rest of the enumerates. */ | |
13912 | if (!unsigned_enum && !flag_enum) | |
13913 | break; | |
55426c9d JB |
13914 | } |
13915 | ||
13916 | if (unsigned_enum) | |
13917 | TYPE_UNSIGNED (type) = 1; | |
13918 | if (flag_enum) | |
13919 | TYPE_FLAG_ENUM (type) = 1; | |
55426c9d JB |
13920 | } |
13921 | ||
134d01f1 DJ |
13922 | /* Given a DW_AT_enumeration_type die, set its type. We do not |
13923 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 13924 | |
f792889a | 13925 | static struct type * |
134d01f1 | 13926 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13927 | { |
e7c27a73 | 13928 | struct objfile *objfile = cu->objfile; |
c906108c | 13929 | struct type *type; |
c906108c | 13930 | struct attribute *attr; |
0114d602 | 13931 | const char *name; |
134d01f1 | 13932 | |
348e048f DE |
13933 | /* If the definition of this type lives in .debug_types, read that type. |
13934 | Don't follow DW_AT_specification though, that will take us back up | |
13935 | the chain and we want to go down. */ | |
45e58e77 | 13936 | attr = dwarf2_attr_no_follow (die, DW_AT_signature); |
348e048f DE |
13937 | if (attr) |
13938 | { | |
ac9ec31b | 13939 | type = get_DW_AT_signature_type (die, attr, cu); |
9dc481d3 | 13940 | |
ac9ec31b | 13941 | /* The type's CU may not be the same as CU. |
02142a6c | 13942 | Ensure TYPE is recorded with CU in die_type_hash. */ |
348e048f DE |
13943 | return set_die_type (die, type, cu); |
13944 | } | |
13945 | ||
c906108c SS |
13946 | type = alloc_type (objfile); |
13947 | ||
13948 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 13949 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 13950 | if (name != NULL) |
7d455152 | 13951 | TYPE_TAG_NAME (type) = name; |
c906108c | 13952 | |
0626fc76 TT |
13953 | attr = dwarf2_attr (die, DW_AT_type, cu); |
13954 | if (attr != NULL) | |
13955 | { | |
13956 | struct type *underlying_type = die_type (die, cu); | |
13957 | ||
13958 | TYPE_TARGET_TYPE (type) = underlying_type; | |
13959 | } | |
13960 | ||
e142c38c | 13961 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
13962 | if (attr) |
13963 | { | |
13964 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
13965 | } | |
13966 | else | |
13967 | { | |
13968 | TYPE_LENGTH (type) = 0; | |
13969 | } | |
13970 | ||
137033e9 JB |
13971 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
13972 | declared as private in the package spec, and then defined only | |
13973 | inside the package body. Such types are known as Taft Amendment | |
13974 | Types. When another package uses such a type, an incomplete DIE | |
13975 | may be generated by the compiler. */ | |
02eb380e | 13976 | if (die_is_declaration (die, cu)) |
876cecd0 | 13977 | TYPE_STUB (type) = 1; |
02eb380e | 13978 | |
0626fc76 TT |
13979 | /* Finish the creation of this type by using the enum's children. |
13980 | We must call this even when the underlying type has been provided | |
13981 | so that we can determine if we're looking at a "flag" enum. */ | |
55426c9d JB |
13982 | update_enumeration_type_from_children (die, type, cu); |
13983 | ||
0626fc76 TT |
13984 | /* If this type has an underlying type that is not a stub, then we |
13985 | may use its attributes. We always use the "unsigned" attribute | |
13986 | in this situation, because ordinarily we guess whether the type | |
13987 | is unsigned -- but the guess can be wrong and the underlying type | |
13988 | can tell us the reality. However, we defer to a local size | |
13989 | attribute if one exists, because this lets the compiler override | |
13990 | the underlying type if needed. */ | |
13991 | if (TYPE_TARGET_TYPE (type) != NULL && !TYPE_STUB (TYPE_TARGET_TYPE (type))) | |
13992 | { | |
13993 | TYPE_UNSIGNED (type) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)); | |
13994 | if (TYPE_LENGTH (type) == 0) | |
13995 | TYPE_LENGTH (type) = TYPE_LENGTH (TYPE_TARGET_TYPE (type)); | |
13996 | } | |
13997 | ||
3d567982 TT |
13998 | TYPE_DECLARED_CLASS (type) = dwarf2_flag_true_p (die, DW_AT_enum_class, cu); |
13999 | ||
f792889a | 14000 | return set_die_type (die, type, cu); |
134d01f1 DJ |
14001 | } |
14002 | ||
14003 | /* Given a pointer to a die which begins an enumeration, process all | |
14004 | the dies that define the members of the enumeration, and create the | |
14005 | symbol for the enumeration type. | |
14006 | ||
14007 | NOTE: We reverse the order of the element list. */ | |
14008 | ||
14009 | static void | |
14010 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
14011 | { | |
f792889a | 14012 | struct type *this_type; |
134d01f1 | 14013 | |
f792889a DJ |
14014 | this_type = get_die_type (die, cu); |
14015 | if (this_type == NULL) | |
14016 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 14017 | |
639d11d3 | 14018 | if (die->child != NULL) |
c906108c | 14019 | { |
9dc481d3 DE |
14020 | struct die_info *child_die; |
14021 | struct symbol *sym; | |
14022 | struct field *fields = NULL; | |
14023 | int num_fields = 0; | |
15d034d0 | 14024 | const char *name; |
9dc481d3 | 14025 | |
639d11d3 | 14026 | child_die = die->child; |
c906108c SS |
14027 | while (child_die && child_die->tag) |
14028 | { | |
14029 | if (child_die->tag != DW_TAG_enumerator) | |
14030 | { | |
e7c27a73 | 14031 | process_die (child_die, cu); |
c906108c SS |
14032 | } |
14033 | else | |
14034 | { | |
39cbfefa DJ |
14035 | name = dwarf2_name (child_die, cu); |
14036 | if (name) | |
c906108c | 14037 | { |
f792889a | 14038 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
14039 | |
14040 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
14041 | { | |
14042 | fields = (struct field *) | |
14043 | xrealloc (fields, | |
14044 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 14045 | * sizeof (struct field)); |
c906108c SS |
14046 | } |
14047 | ||
3567439c | 14048 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 14049 | FIELD_TYPE (fields[num_fields]) = NULL; |
14e75d8e | 14050 | SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
14051 | FIELD_BITSIZE (fields[num_fields]) = 0; |
14052 | ||
14053 | num_fields++; | |
14054 | } | |
14055 | } | |
14056 | ||
14057 | child_die = sibling_die (child_die); | |
14058 | } | |
14059 | ||
14060 | if (num_fields) | |
14061 | { | |
f792889a DJ |
14062 | TYPE_NFIELDS (this_type) = num_fields; |
14063 | TYPE_FIELDS (this_type) = (struct field *) | |
14064 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
14065 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 14066 | sizeof (struct field) * num_fields); |
b8c9b27d | 14067 | xfree (fields); |
c906108c | 14068 | } |
c906108c | 14069 | } |
134d01f1 | 14070 | |
6c83ed52 TT |
14071 | /* If we are reading an enum from a .debug_types unit, and the enum |
14072 | is a declaration, and the enum is not the signatured type in the | |
14073 | unit, then we do not want to add a symbol for it. Adding a | |
14074 | symbol would in some cases obscure the true definition of the | |
14075 | enum, giving users an incomplete type when the definition is | |
14076 | actually available. Note that we do not want to do this for all | |
14077 | enums which are just declarations, because C++0x allows forward | |
14078 | enum declarations. */ | |
3019eac3 | 14079 | if (cu->per_cu->is_debug_types |
6c83ed52 TT |
14080 | && die_is_declaration (die, cu)) |
14081 | { | |
52dc124a | 14082 | struct signatured_type *sig_type; |
6c83ed52 | 14083 | |
c0f78cd4 | 14084 | sig_type = (struct signatured_type *) cu->per_cu; |
9c541725 PA |
14085 | gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0); |
14086 | if (sig_type->type_offset_in_section != die->sect_off) | |
6c83ed52 TT |
14087 | return; |
14088 | } | |
14089 | ||
f792889a | 14090 | new_symbol (die, this_type, cu); |
c906108c SS |
14091 | } |
14092 | ||
14093 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
14094 | the DIE's type field. For now, this only handles one dimensional | |
14095 | arrays. */ | |
14096 | ||
f792889a | 14097 | static struct type * |
e7c27a73 | 14098 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14099 | { |
e7c27a73 | 14100 | struct objfile *objfile = cu->objfile; |
c906108c | 14101 | struct die_info *child_die; |
7e314c57 | 14102 | struct type *type; |
c906108c SS |
14103 | struct type *element_type, *range_type, *index_type; |
14104 | struct type **range_types = NULL; | |
14105 | struct attribute *attr; | |
14106 | int ndim = 0; | |
14107 | struct cleanup *back_to; | |
15d034d0 | 14108 | const char *name; |
dc53a7ad | 14109 | unsigned int bit_stride = 0; |
c906108c | 14110 | |
e7c27a73 | 14111 | element_type = die_type (die, cu); |
c906108c | 14112 | |
7e314c57 JK |
14113 | /* The die_type call above may have already set the type for this DIE. */ |
14114 | type = get_die_type (die, cu); | |
14115 | if (type) | |
14116 | return type; | |
14117 | ||
dc53a7ad JB |
14118 | attr = dwarf2_attr (die, DW_AT_byte_stride, cu); |
14119 | if (attr != NULL) | |
14120 | bit_stride = DW_UNSND (attr) * 8; | |
14121 | ||
14122 | attr = dwarf2_attr (die, DW_AT_bit_stride, cu); | |
14123 | if (attr != NULL) | |
14124 | bit_stride = DW_UNSND (attr); | |
14125 | ||
c906108c SS |
14126 | /* Irix 6.2 native cc creates array types without children for |
14127 | arrays with unspecified length. */ | |
639d11d3 | 14128 | if (die->child == NULL) |
c906108c | 14129 | { |
46bf5051 | 14130 | index_type = objfile_type (objfile)->builtin_int; |
0c9c3474 | 14131 | range_type = create_static_range_type (NULL, index_type, 0, -1); |
dc53a7ad JB |
14132 | type = create_array_type_with_stride (NULL, element_type, range_type, |
14133 | bit_stride); | |
f792889a | 14134 | return set_die_type (die, type, cu); |
c906108c SS |
14135 | } |
14136 | ||
14137 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 14138 | child_die = die->child; |
c906108c SS |
14139 | while (child_die && child_die->tag) |
14140 | { | |
14141 | if (child_die->tag == DW_TAG_subrange_type) | |
14142 | { | |
f792889a | 14143 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 14144 | |
f792889a | 14145 | if (child_type != NULL) |
a02abb62 | 14146 | { |
0963b4bd MS |
14147 | /* The range type was succesfully read. Save it for the |
14148 | array type creation. */ | |
a02abb62 JB |
14149 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
14150 | { | |
14151 | range_types = (struct type **) | |
14152 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
14153 | * sizeof (struct type *)); | |
14154 | if (ndim == 0) | |
14155 | make_cleanup (free_current_contents, &range_types); | |
14156 | } | |
f792889a | 14157 | range_types[ndim++] = child_type; |
a02abb62 | 14158 | } |
c906108c SS |
14159 | } |
14160 | child_die = sibling_die (child_die); | |
14161 | } | |
14162 | ||
14163 | /* Dwarf2 dimensions are output from left to right, create the | |
14164 | necessary array types in backwards order. */ | |
7ca2d3a3 | 14165 | |
c906108c | 14166 | type = element_type; |
7ca2d3a3 DL |
14167 | |
14168 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
14169 | { | |
14170 | int i = 0; | |
9a619af0 | 14171 | |
7ca2d3a3 | 14172 | while (i < ndim) |
dc53a7ad JB |
14173 | type = create_array_type_with_stride (NULL, type, range_types[i++], |
14174 | bit_stride); | |
7ca2d3a3 DL |
14175 | } |
14176 | else | |
14177 | { | |
14178 | while (ndim-- > 0) | |
dc53a7ad JB |
14179 | type = create_array_type_with_stride (NULL, type, range_types[ndim], |
14180 | bit_stride); | |
7ca2d3a3 | 14181 | } |
c906108c | 14182 | |
f5f8a009 EZ |
14183 | /* Understand Dwarf2 support for vector types (like they occur on |
14184 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
14185 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
14186 | custom vendor extension. The main difference between a regular | |
14187 | array and the vector variant is that vectors are passed by value | |
14188 | to functions. */ | |
e142c38c | 14189 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 14190 | if (attr) |
ea37ba09 | 14191 | make_vector_type (type); |
f5f8a009 | 14192 | |
dbc98a8b KW |
14193 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
14194 | implementation may choose to implement triple vectors using this | |
14195 | attribute. */ | |
14196 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
14197 | if (attr) | |
14198 | { | |
14199 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
14200 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
14201 | else | |
3e43a32a MS |
14202 | complaint (&symfile_complaints, |
14203 | _("DW_AT_byte_size for array type smaller " | |
14204 | "than the total size of elements")); | |
dbc98a8b KW |
14205 | } |
14206 | ||
39cbfefa DJ |
14207 | name = dwarf2_name (die, cu); |
14208 | if (name) | |
14209 | TYPE_NAME (type) = name; | |
6e70227d | 14210 | |
0963b4bd | 14211 | /* Install the type in the die. */ |
7e314c57 JK |
14212 | set_die_type (die, type, cu); |
14213 | ||
14214 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
14215 | set_descriptive_type (type, die, cu); |
14216 | ||
c906108c SS |
14217 | do_cleanups (back_to); |
14218 | ||
7e314c57 | 14219 | return type; |
c906108c SS |
14220 | } |
14221 | ||
7ca2d3a3 | 14222 | static enum dwarf_array_dim_ordering |
6e70227d | 14223 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
14224 | { |
14225 | struct attribute *attr; | |
14226 | ||
14227 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
14228 | ||
aead7601 SM |
14229 | if (attr) |
14230 | return (enum dwarf_array_dim_ordering) DW_SND (attr); | |
7ca2d3a3 | 14231 | |
0963b4bd MS |
14232 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
14233 | opposite order to the dwarf2 specification, but data is still | |
14234 | laid out as per normal fortran. | |
7ca2d3a3 | 14235 | |
0963b4bd MS |
14236 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
14237 | version checking. */ | |
7ca2d3a3 | 14238 | |
905e0470 PM |
14239 | if (cu->language == language_fortran |
14240 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
14241 | { |
14242 | return DW_ORD_row_major; | |
14243 | } | |
14244 | ||
6e70227d | 14245 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
14246 | { |
14247 | case array_column_major: | |
14248 | return DW_ORD_col_major; | |
14249 | case array_row_major: | |
14250 | default: | |
14251 | return DW_ORD_row_major; | |
14252 | }; | |
14253 | } | |
14254 | ||
72019c9c | 14255 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 14256 | the DIE's type field. */ |
72019c9c | 14257 | |
f792889a | 14258 | static struct type * |
72019c9c GM |
14259 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
14260 | { | |
7e314c57 JK |
14261 | struct type *domain_type, *set_type; |
14262 | struct attribute *attr; | |
f792889a | 14263 | |
7e314c57 JK |
14264 | domain_type = die_type (die, cu); |
14265 | ||
14266 | /* The die_type call above may have already set the type for this DIE. */ | |
14267 | set_type = get_die_type (die, cu); | |
14268 | if (set_type) | |
14269 | return set_type; | |
14270 | ||
14271 | set_type = create_set_type (NULL, domain_type); | |
14272 | ||
14273 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
14274 | if (attr) |
14275 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 14276 | |
f792889a | 14277 | return set_die_type (die, set_type, cu); |
72019c9c | 14278 | } |
7ca2d3a3 | 14279 | |
0971de02 TT |
14280 | /* A helper for read_common_block that creates a locexpr baton. |
14281 | SYM is the symbol which we are marking as computed. | |
14282 | COMMON_DIE is the DIE for the common block. | |
14283 | COMMON_LOC is the location expression attribute for the common | |
14284 | block itself. | |
14285 | MEMBER_LOC is the location expression attribute for the particular | |
14286 | member of the common block that we are processing. | |
14287 | CU is the CU from which the above come. */ | |
14288 | ||
14289 | static void | |
14290 | mark_common_block_symbol_computed (struct symbol *sym, | |
14291 | struct die_info *common_die, | |
14292 | struct attribute *common_loc, | |
14293 | struct attribute *member_loc, | |
14294 | struct dwarf2_cu *cu) | |
14295 | { | |
14296 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
14297 | struct dwarf2_locexpr_baton *baton; | |
14298 | gdb_byte *ptr; | |
14299 | unsigned int cu_off; | |
14300 | enum bfd_endian byte_order = gdbarch_byte_order (get_objfile_arch (objfile)); | |
14301 | LONGEST offset = 0; | |
14302 | ||
14303 | gdb_assert (common_loc && member_loc); | |
14304 | gdb_assert (attr_form_is_block (common_loc)); | |
14305 | gdb_assert (attr_form_is_block (member_loc) | |
14306 | || attr_form_is_constant (member_loc)); | |
14307 | ||
8d749320 | 14308 | baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton); |
0971de02 TT |
14309 | baton->per_cu = cu->per_cu; |
14310 | gdb_assert (baton->per_cu); | |
14311 | ||
14312 | baton->size = 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */; | |
14313 | ||
14314 | if (attr_form_is_constant (member_loc)) | |
14315 | { | |
14316 | offset = dwarf2_get_attr_constant_value (member_loc, 0); | |
14317 | baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size; | |
14318 | } | |
14319 | else | |
14320 | baton->size += DW_BLOCK (member_loc)->size; | |
14321 | ||
224c3ddb | 14322 | ptr = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, baton->size); |
0971de02 TT |
14323 | baton->data = ptr; |
14324 | ||
14325 | *ptr++ = DW_OP_call4; | |
9c541725 | 14326 | cu_off = common_die->sect_off - cu->per_cu->sect_off; |
0971de02 TT |
14327 | store_unsigned_integer (ptr, 4, byte_order, cu_off); |
14328 | ptr += 4; | |
14329 | ||
14330 | if (attr_form_is_constant (member_loc)) | |
14331 | { | |
14332 | *ptr++ = DW_OP_addr; | |
14333 | store_unsigned_integer (ptr, cu->header.addr_size, byte_order, offset); | |
14334 | ptr += cu->header.addr_size; | |
14335 | } | |
14336 | else | |
14337 | { | |
14338 | /* We have to copy the data here, because DW_OP_call4 will only | |
14339 | use a DW_AT_location attribute. */ | |
14340 | memcpy (ptr, DW_BLOCK (member_loc)->data, DW_BLOCK (member_loc)->size); | |
14341 | ptr += DW_BLOCK (member_loc)->size; | |
14342 | } | |
14343 | ||
14344 | *ptr++ = DW_OP_plus; | |
14345 | gdb_assert (ptr - baton->data == baton->size); | |
14346 | ||
0971de02 | 14347 | SYMBOL_LOCATION_BATON (sym) = baton; |
f1e6e072 | 14348 | SYMBOL_ACLASS_INDEX (sym) = dwarf2_locexpr_index; |
0971de02 TT |
14349 | } |
14350 | ||
4357ac6c TT |
14351 | /* Create appropriate locally-scoped variables for all the |
14352 | DW_TAG_common_block entries. Also create a struct common_block | |
14353 | listing all such variables for `info common'. COMMON_BLOCK_DOMAIN | |
14354 | is used to sepate the common blocks name namespace from regular | |
14355 | variable names. */ | |
c906108c SS |
14356 | |
14357 | static void | |
e7c27a73 | 14358 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14359 | { |
0971de02 TT |
14360 | struct attribute *attr; |
14361 | ||
14362 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
14363 | if (attr) | |
14364 | { | |
14365 | /* Support the .debug_loc offsets. */ | |
14366 | if (attr_form_is_block (attr)) | |
14367 | { | |
14368 | /* Ok. */ | |
14369 | } | |
14370 | else if (attr_form_is_section_offset (attr)) | |
14371 | { | |
14372 | dwarf2_complex_location_expr_complaint (); | |
14373 | attr = NULL; | |
14374 | } | |
14375 | else | |
14376 | { | |
14377 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", | |
14378 | "common block member"); | |
14379 | attr = NULL; | |
14380 | } | |
14381 | } | |
14382 | ||
639d11d3 | 14383 | if (die->child != NULL) |
c906108c | 14384 | { |
4357ac6c TT |
14385 | struct objfile *objfile = cu->objfile; |
14386 | struct die_info *child_die; | |
14387 | size_t n_entries = 0, size; | |
14388 | struct common_block *common_block; | |
14389 | struct symbol *sym; | |
74ac6d43 | 14390 | |
4357ac6c TT |
14391 | for (child_die = die->child; |
14392 | child_die && child_die->tag; | |
14393 | child_die = sibling_die (child_die)) | |
14394 | ++n_entries; | |
14395 | ||
14396 | size = (sizeof (struct common_block) | |
14397 | + (n_entries - 1) * sizeof (struct symbol *)); | |
224c3ddb SM |
14398 | common_block |
14399 | = (struct common_block *) obstack_alloc (&objfile->objfile_obstack, | |
14400 | size); | |
4357ac6c TT |
14401 | memset (common_block->contents, 0, n_entries * sizeof (struct symbol *)); |
14402 | common_block->n_entries = 0; | |
14403 | ||
14404 | for (child_die = die->child; | |
14405 | child_die && child_die->tag; | |
14406 | child_die = sibling_die (child_die)) | |
14407 | { | |
14408 | /* Create the symbol in the DW_TAG_common_block block in the current | |
14409 | symbol scope. */ | |
e7c27a73 | 14410 | sym = new_symbol (child_die, NULL, cu); |
0971de02 TT |
14411 | if (sym != NULL) |
14412 | { | |
14413 | struct attribute *member_loc; | |
14414 | ||
14415 | common_block->contents[common_block->n_entries++] = sym; | |
14416 | ||
14417 | member_loc = dwarf2_attr (child_die, DW_AT_data_member_location, | |
14418 | cu); | |
14419 | if (member_loc) | |
14420 | { | |
14421 | /* GDB has handled this for a long time, but it is | |
14422 | not specified by DWARF. It seems to have been | |
14423 | emitted by gfortran at least as recently as: | |
14424 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */ | |
14425 | complaint (&symfile_complaints, | |
14426 | _("Variable in common block has " | |
14427 | "DW_AT_data_member_location " | |
14428 | "- DIE at 0x%x [in module %s]"), | |
9c541725 | 14429 | to_underlying (child_die->sect_off), |
4262abfb | 14430 | objfile_name (cu->objfile)); |
0971de02 TT |
14431 | |
14432 | if (attr_form_is_section_offset (member_loc)) | |
14433 | dwarf2_complex_location_expr_complaint (); | |
14434 | else if (attr_form_is_constant (member_loc) | |
14435 | || attr_form_is_block (member_loc)) | |
14436 | { | |
14437 | if (attr) | |
14438 | mark_common_block_symbol_computed (sym, die, attr, | |
14439 | member_loc, cu); | |
14440 | } | |
14441 | else | |
14442 | dwarf2_complex_location_expr_complaint (); | |
14443 | } | |
14444 | } | |
c906108c | 14445 | } |
4357ac6c TT |
14446 | |
14447 | sym = new_symbol (die, objfile_type (objfile)->builtin_void, cu); | |
14448 | SYMBOL_VALUE_COMMON_BLOCK (sym) = common_block; | |
c906108c SS |
14449 | } |
14450 | } | |
14451 | ||
0114d602 | 14452 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 14453 | |
0114d602 DJ |
14454 | static struct type * |
14455 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 14456 | { |
e7c27a73 | 14457 | struct objfile *objfile = cu->objfile; |
0114d602 | 14458 | const char *previous_prefix, *name; |
9219021c | 14459 | int is_anonymous; |
0114d602 DJ |
14460 | struct type *type; |
14461 | ||
14462 | /* For extensions, reuse the type of the original namespace. */ | |
14463 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
14464 | { | |
14465 | struct die_info *ext_die; | |
14466 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 14467 | |
0114d602 DJ |
14468 | ext_die = dwarf2_extension (die, &ext_cu); |
14469 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
14470 | |
14471 | /* EXT_CU may not be the same as CU. | |
02142a6c | 14472 | Ensure TYPE is recorded with CU in die_type_hash. */ |
0114d602 DJ |
14473 | return set_die_type (die, type, cu); |
14474 | } | |
9219021c | 14475 | |
e142c38c | 14476 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
14477 | |
14478 | /* Now build the name of the current namespace. */ | |
14479 | ||
0114d602 DJ |
14480 | previous_prefix = determine_prefix (die, cu); |
14481 | if (previous_prefix[0] != '\0') | |
14482 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 14483 | previous_prefix, name, 0, cu); |
0114d602 DJ |
14484 | |
14485 | /* Create the type. */ | |
19f392bc | 14486 | type = init_type (objfile, TYPE_CODE_NAMESPACE, 0, name); |
0114d602 DJ |
14487 | TYPE_TAG_NAME (type) = TYPE_NAME (type); |
14488 | ||
60531b24 | 14489 | return set_die_type (die, type, cu); |
0114d602 DJ |
14490 | } |
14491 | ||
22cee43f | 14492 | /* Read a namespace scope. */ |
0114d602 DJ |
14493 | |
14494 | static void | |
14495 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
14496 | { | |
14497 | struct objfile *objfile = cu->objfile; | |
0114d602 | 14498 | int is_anonymous; |
9219021c | 14499 | |
5c4e30ca DC |
14500 | /* Add a symbol associated to this if we haven't seen the namespace |
14501 | before. Also, add a using directive if it's an anonymous | |
14502 | namespace. */ | |
9219021c | 14503 | |
f2f0e013 | 14504 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
14505 | { |
14506 | struct type *type; | |
14507 | ||
0114d602 | 14508 | type = read_type_die (die, cu); |
e7c27a73 | 14509 | new_symbol (die, type, cu); |
5c4e30ca | 14510 | |
e8e80198 | 14511 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 14512 | if (is_anonymous) |
0114d602 DJ |
14513 | { |
14514 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 14515 | |
22cee43f PMR |
14516 | add_using_directive (using_directives (cu->language), |
14517 | previous_prefix, TYPE_NAME (type), NULL, | |
14518 | NULL, NULL, 0, &objfile->objfile_obstack); | |
0114d602 | 14519 | } |
5c4e30ca | 14520 | } |
9219021c | 14521 | |
639d11d3 | 14522 | if (die->child != NULL) |
d9fa45fe | 14523 | { |
639d11d3 | 14524 | struct die_info *child_die = die->child; |
6e70227d | 14525 | |
d9fa45fe DC |
14526 | while (child_die && child_die->tag) |
14527 | { | |
e7c27a73 | 14528 | process_die (child_die, cu); |
d9fa45fe DC |
14529 | child_die = sibling_die (child_die); |
14530 | } | |
14531 | } | |
38d518c9 EZ |
14532 | } |
14533 | ||
f55ee35c JK |
14534 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
14535 | imported module. Still we need that type as local Fortran "use ... only" | |
14536 | declaration imports depend on the created type in determine_prefix. */ | |
14537 | ||
14538 | static struct type * | |
14539 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
14540 | { | |
14541 | struct objfile *objfile = cu->objfile; | |
15d034d0 | 14542 | const char *module_name; |
f55ee35c JK |
14543 | struct type *type; |
14544 | ||
14545 | module_name = dwarf2_name (die, cu); | |
14546 | if (!module_name) | |
3e43a32a MS |
14547 | complaint (&symfile_complaints, |
14548 | _("DW_TAG_module has no name, offset 0x%x"), | |
9c541725 | 14549 | to_underlying (die->sect_off)); |
19f392bc | 14550 | type = init_type (objfile, TYPE_CODE_MODULE, 0, module_name); |
f55ee35c JK |
14551 | |
14552 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
14553 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
14554 | ||
14555 | return set_die_type (die, type, cu); | |
14556 | } | |
14557 | ||
5d7cb8df JK |
14558 | /* Read a Fortran module. */ |
14559 | ||
14560 | static void | |
14561 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
14562 | { | |
14563 | struct die_info *child_die = die->child; | |
530e8392 KB |
14564 | struct type *type; |
14565 | ||
14566 | type = read_type_die (die, cu); | |
14567 | new_symbol (die, type, cu); | |
5d7cb8df | 14568 | |
5d7cb8df JK |
14569 | while (child_die && child_die->tag) |
14570 | { | |
14571 | process_die (child_die, cu); | |
14572 | child_die = sibling_die (child_die); | |
14573 | } | |
14574 | } | |
14575 | ||
38d518c9 EZ |
14576 | /* Return the name of the namespace represented by DIE. Set |
14577 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
14578 | namespace. */ | |
14579 | ||
14580 | static const char * | |
e142c38c | 14581 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
14582 | { |
14583 | struct die_info *current_die; | |
14584 | const char *name = NULL; | |
14585 | ||
14586 | /* Loop through the extensions until we find a name. */ | |
14587 | ||
14588 | for (current_die = die; | |
14589 | current_die != NULL; | |
f2f0e013 | 14590 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 14591 | { |
96553a0c DE |
14592 | /* We don't use dwarf2_name here so that we can detect the absence |
14593 | of a name -> anonymous namespace. */ | |
7d45c7c3 | 14594 | name = dwarf2_string_attr (die, DW_AT_name, cu); |
96553a0c | 14595 | |
38d518c9 EZ |
14596 | if (name != NULL) |
14597 | break; | |
14598 | } | |
14599 | ||
14600 | /* Is it an anonymous namespace? */ | |
14601 | ||
14602 | *is_anonymous = (name == NULL); | |
14603 | if (*is_anonymous) | |
2b1dbab0 | 14604 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
14605 | |
14606 | return name; | |
d9fa45fe DC |
14607 | } |
14608 | ||
c906108c SS |
14609 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
14610 | the user defined type vector. */ | |
14611 | ||
f792889a | 14612 | static struct type * |
e7c27a73 | 14613 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14614 | { |
5e2b427d | 14615 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 14616 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 14617 | struct type *type; |
8b2dbe47 KB |
14618 | struct attribute *attr_byte_size; |
14619 | struct attribute *attr_address_class; | |
14620 | int byte_size, addr_class; | |
7e314c57 JK |
14621 | struct type *target_type; |
14622 | ||
14623 | target_type = die_type (die, cu); | |
c906108c | 14624 | |
7e314c57 JK |
14625 | /* The die_type call above may have already set the type for this DIE. */ |
14626 | type = get_die_type (die, cu); | |
14627 | if (type) | |
14628 | return type; | |
14629 | ||
14630 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 14631 | |
e142c38c | 14632 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
14633 | if (attr_byte_size) |
14634 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 14635 | else |
8b2dbe47 KB |
14636 | byte_size = cu_header->addr_size; |
14637 | ||
e142c38c | 14638 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
14639 | if (attr_address_class) |
14640 | addr_class = DW_UNSND (attr_address_class); | |
14641 | else | |
14642 | addr_class = DW_ADDR_none; | |
14643 | ||
14644 | /* If the pointer size or address class is different than the | |
14645 | default, create a type variant marked as such and set the | |
14646 | length accordingly. */ | |
14647 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 14648 | { |
5e2b427d | 14649 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
14650 | { |
14651 | int type_flags; | |
14652 | ||
849957d9 | 14653 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 14654 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
14655 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
14656 | == 0); | |
8b2dbe47 KB |
14657 | type = make_type_with_address_space (type, type_flags); |
14658 | } | |
14659 | else if (TYPE_LENGTH (type) != byte_size) | |
14660 | { | |
3e43a32a MS |
14661 | complaint (&symfile_complaints, |
14662 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 14663 | } |
6e70227d | 14664 | else |
9a619af0 MS |
14665 | { |
14666 | /* Should we also complain about unhandled address classes? */ | |
14667 | } | |
c906108c | 14668 | } |
8b2dbe47 KB |
14669 | |
14670 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 14671 | return set_die_type (die, type, cu); |
c906108c SS |
14672 | } |
14673 | ||
14674 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
14675 | the user defined type vector. */ | |
14676 | ||
f792889a | 14677 | static struct type * |
e7c27a73 | 14678 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
14679 | { |
14680 | struct type *type; | |
14681 | struct type *to_type; | |
14682 | struct type *domain; | |
14683 | ||
e7c27a73 DJ |
14684 | to_type = die_type (die, cu); |
14685 | domain = die_containing_type (die, cu); | |
0d5de010 | 14686 | |
7e314c57 JK |
14687 | /* The calls above may have already set the type for this DIE. */ |
14688 | type = get_die_type (die, cu); | |
14689 | if (type) | |
14690 | return type; | |
14691 | ||
0d5de010 DJ |
14692 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
14693 | type = lookup_methodptr_type (to_type); | |
7078baeb TT |
14694 | else if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_FUNC) |
14695 | { | |
14696 | struct type *new_type = alloc_type (cu->objfile); | |
14697 | ||
14698 | smash_to_method_type (new_type, domain, TYPE_TARGET_TYPE (to_type), | |
14699 | TYPE_FIELDS (to_type), TYPE_NFIELDS (to_type), | |
14700 | TYPE_VARARGS (to_type)); | |
14701 | type = lookup_methodptr_type (new_type); | |
14702 | } | |
0d5de010 DJ |
14703 | else |
14704 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 14705 | |
f792889a | 14706 | return set_die_type (die, type, cu); |
c906108c SS |
14707 | } |
14708 | ||
4297a3f0 | 14709 | /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to |
c906108c SS |
14710 | the user defined type vector. */ |
14711 | ||
f792889a | 14712 | static struct type * |
4297a3f0 AV |
14713 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu, |
14714 | enum type_code refcode) | |
c906108c | 14715 | { |
e7c27a73 | 14716 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 14717 | struct type *type, *target_type; |
c906108c SS |
14718 | struct attribute *attr; |
14719 | ||
4297a3f0 AV |
14720 | gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF); |
14721 | ||
7e314c57 JK |
14722 | target_type = die_type (die, cu); |
14723 | ||
14724 | /* The die_type call above may have already set the type for this DIE. */ | |
14725 | type = get_die_type (die, cu); | |
14726 | if (type) | |
14727 | return type; | |
14728 | ||
4297a3f0 | 14729 | type = lookup_reference_type (target_type, refcode); |
e142c38c | 14730 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
14731 | if (attr) |
14732 | { | |
14733 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
14734 | } | |
14735 | else | |
14736 | { | |
107d2387 | 14737 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 14738 | } |
f792889a | 14739 | return set_die_type (die, type, cu); |
c906108c SS |
14740 | } |
14741 | ||
cf363f18 MW |
14742 | /* Add the given cv-qualifiers to the element type of the array. GCC |
14743 | outputs DWARF type qualifiers that apply to an array, not the | |
14744 | element type. But GDB relies on the array element type to carry | |
14745 | the cv-qualifiers. This mimics section 6.7.3 of the C99 | |
14746 | specification. */ | |
14747 | ||
14748 | static struct type * | |
14749 | add_array_cv_type (struct die_info *die, struct dwarf2_cu *cu, | |
14750 | struct type *base_type, int cnst, int voltl) | |
14751 | { | |
14752 | struct type *el_type, *inner_array; | |
14753 | ||
14754 | base_type = copy_type (base_type); | |
14755 | inner_array = base_type; | |
14756 | ||
14757 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
14758 | { | |
14759 | TYPE_TARGET_TYPE (inner_array) = | |
14760 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
14761 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
14762 | } | |
14763 | ||
14764 | el_type = TYPE_TARGET_TYPE (inner_array); | |
14765 | cnst |= TYPE_CONST (el_type); | |
14766 | voltl |= TYPE_VOLATILE (el_type); | |
14767 | TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, NULL); | |
14768 | ||
14769 | return set_die_type (die, base_type, cu); | |
14770 | } | |
14771 | ||
f792889a | 14772 | static struct type * |
e7c27a73 | 14773 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14774 | { |
f792889a | 14775 | struct type *base_type, *cv_type; |
c906108c | 14776 | |
e7c27a73 | 14777 | base_type = die_type (die, cu); |
7e314c57 JK |
14778 | |
14779 | /* The die_type call above may have already set the type for this DIE. */ | |
14780 | cv_type = get_die_type (die, cu); | |
14781 | if (cv_type) | |
14782 | return cv_type; | |
14783 | ||
2f608a3a KW |
14784 | /* In case the const qualifier is applied to an array type, the element type |
14785 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
14786 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
cf363f18 | 14787 | return add_array_cv_type (die, cu, base_type, 1, 0); |
2f608a3a | 14788 | |
f792889a DJ |
14789 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
14790 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
14791 | } |
14792 | ||
f792889a | 14793 | static struct type * |
e7c27a73 | 14794 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14795 | { |
f792889a | 14796 | struct type *base_type, *cv_type; |
c906108c | 14797 | |
e7c27a73 | 14798 | base_type = die_type (die, cu); |
7e314c57 JK |
14799 | |
14800 | /* The die_type call above may have already set the type for this DIE. */ | |
14801 | cv_type = get_die_type (die, cu); | |
14802 | if (cv_type) | |
14803 | return cv_type; | |
14804 | ||
cf363f18 MW |
14805 | /* In case the volatile qualifier is applied to an array type, the |
14806 | element type is so qualified, not the array type (section 6.7.3 | |
14807 | of C99). */ | |
14808 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
14809 | return add_array_cv_type (die, cu, base_type, 0, 1); | |
14810 | ||
f792889a DJ |
14811 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
14812 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
14813 | } |
14814 | ||
06d66ee9 TT |
14815 | /* Handle DW_TAG_restrict_type. */ |
14816 | ||
14817 | static struct type * | |
14818 | read_tag_restrict_type (struct die_info *die, struct dwarf2_cu *cu) | |
14819 | { | |
14820 | struct type *base_type, *cv_type; | |
14821 | ||
14822 | base_type = die_type (die, cu); | |
14823 | ||
14824 | /* The die_type call above may have already set the type for this DIE. */ | |
14825 | cv_type = get_die_type (die, cu); | |
14826 | if (cv_type) | |
14827 | return cv_type; | |
14828 | ||
14829 | cv_type = make_restrict_type (base_type); | |
14830 | return set_die_type (die, cv_type, cu); | |
14831 | } | |
14832 | ||
a2c2acaf MW |
14833 | /* Handle DW_TAG_atomic_type. */ |
14834 | ||
14835 | static struct type * | |
14836 | read_tag_atomic_type (struct die_info *die, struct dwarf2_cu *cu) | |
14837 | { | |
14838 | struct type *base_type, *cv_type; | |
14839 | ||
14840 | base_type = die_type (die, cu); | |
14841 | ||
14842 | /* The die_type call above may have already set the type for this DIE. */ | |
14843 | cv_type = get_die_type (die, cu); | |
14844 | if (cv_type) | |
14845 | return cv_type; | |
14846 | ||
14847 | cv_type = make_atomic_type (base_type); | |
14848 | return set_die_type (die, cv_type, cu); | |
14849 | } | |
14850 | ||
c906108c SS |
14851 | /* Extract all information from a DW_TAG_string_type DIE and add to |
14852 | the user defined type vector. It isn't really a user defined type, | |
14853 | but it behaves like one, with other DIE's using an AT_user_def_type | |
14854 | attribute to reference it. */ | |
14855 | ||
f792889a | 14856 | static struct type * |
e7c27a73 | 14857 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14858 | { |
e7c27a73 | 14859 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 14860 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
14861 | struct type *type, *range_type, *index_type, *char_type; |
14862 | struct attribute *attr; | |
14863 | unsigned int length; | |
14864 | ||
e142c38c | 14865 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
14866 | if (attr) |
14867 | { | |
14868 | length = DW_UNSND (attr); | |
14869 | } | |
14870 | else | |
14871 | { | |
0963b4bd | 14872 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 14873 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
14874 | if (attr) |
14875 | { | |
14876 | length = DW_UNSND (attr); | |
14877 | } | |
14878 | else | |
14879 | { | |
14880 | length = 1; | |
14881 | } | |
c906108c | 14882 | } |
6ccb9162 | 14883 | |
46bf5051 | 14884 | index_type = objfile_type (objfile)->builtin_int; |
0c9c3474 | 14885 | range_type = create_static_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
14886 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
14887 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 14888 | |
f792889a | 14889 | return set_die_type (die, type, cu); |
c906108c SS |
14890 | } |
14891 | ||
4d804846 JB |
14892 | /* Assuming that DIE corresponds to a function, returns nonzero |
14893 | if the function is prototyped. */ | |
14894 | ||
14895 | static int | |
14896 | prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu) | |
14897 | { | |
14898 | struct attribute *attr; | |
14899 | ||
14900 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); | |
14901 | if (attr && (DW_UNSND (attr) != 0)) | |
14902 | return 1; | |
14903 | ||
14904 | /* The DWARF standard implies that the DW_AT_prototyped attribute | |
14905 | is only meaninful for C, but the concept also extends to other | |
14906 | languages that allow unprototyped functions (Eg: Objective C). | |
14907 | For all other languages, assume that functions are always | |
14908 | prototyped. */ | |
14909 | if (cu->language != language_c | |
14910 | && cu->language != language_objc | |
14911 | && cu->language != language_opencl) | |
14912 | return 1; | |
14913 | ||
14914 | /* RealView does not emit DW_AT_prototyped. We can not distinguish | |
14915 | prototyped and unprototyped functions; default to prototyped, | |
14916 | since that is more common in modern code (and RealView warns | |
14917 | about unprototyped functions). */ | |
14918 | if (producer_is_realview (cu->producer)) | |
14919 | return 1; | |
14920 | ||
14921 | return 0; | |
14922 | } | |
14923 | ||
c906108c SS |
14924 | /* Handle DIES due to C code like: |
14925 | ||
14926 | struct foo | |
c5aa993b JM |
14927 | { |
14928 | int (*funcp)(int a, long l); | |
14929 | int b; | |
14930 | }; | |
c906108c | 14931 | |
0963b4bd | 14932 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 14933 | |
f792889a | 14934 | static struct type * |
e7c27a73 | 14935 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14936 | { |
bb5ed363 | 14937 | struct objfile *objfile = cu->objfile; |
0963b4bd MS |
14938 | struct type *type; /* Type that this function returns. */ |
14939 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
14940 | struct attribute *attr; |
14941 | ||
e7c27a73 | 14942 | type = die_type (die, cu); |
7e314c57 JK |
14943 | |
14944 | /* The die_type call above may have already set the type for this DIE. */ | |
14945 | ftype = get_die_type (die, cu); | |
14946 | if (ftype) | |
14947 | return ftype; | |
14948 | ||
0c8b41f1 | 14949 | ftype = lookup_function_type (type); |
c906108c | 14950 | |
4d804846 | 14951 | if (prototyped_function_p (die, cu)) |
a6c727b2 | 14952 | TYPE_PROTOTYPED (ftype) = 1; |
c906108c | 14953 | |
c055b101 CV |
14954 | /* Store the calling convention in the type if it's available in |
14955 | the subroutine die. Otherwise set the calling convention to | |
14956 | the default value DW_CC_normal. */ | |
14957 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
14958 | if (attr) |
14959 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
14960 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
14961 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
14962 | else | |
14963 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 | 14964 | |
743649fd MW |
14965 | /* Record whether the function returns normally to its caller or not |
14966 | if the DWARF producer set that information. */ | |
14967 | attr = dwarf2_attr (die, DW_AT_noreturn, cu); | |
14968 | if (attr && (DW_UNSND (attr) != 0)) | |
14969 | TYPE_NO_RETURN (ftype) = 1; | |
14970 | ||
76c10ea2 GM |
14971 | /* We need to add the subroutine type to the die immediately so |
14972 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 14973 | declared as the same subroutine type. */ |
76c10ea2 | 14974 | set_die_type (die, ftype, cu); |
6e70227d | 14975 | |
639d11d3 | 14976 | if (die->child != NULL) |
c906108c | 14977 | { |
bb5ed363 | 14978 | struct type *void_type = objfile_type (objfile)->builtin_void; |
c906108c | 14979 | struct die_info *child_die; |
8072405b | 14980 | int nparams, iparams; |
c906108c SS |
14981 | |
14982 | /* Count the number of parameters. | |
14983 | FIXME: GDB currently ignores vararg functions, but knows about | |
14984 | vararg member functions. */ | |
8072405b | 14985 | nparams = 0; |
639d11d3 | 14986 | child_die = die->child; |
c906108c SS |
14987 | while (child_die && child_die->tag) |
14988 | { | |
14989 | if (child_die->tag == DW_TAG_formal_parameter) | |
14990 | nparams++; | |
14991 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 14992 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
14993 | child_die = sibling_die (child_die); |
14994 | } | |
14995 | ||
14996 | /* Allocate storage for parameters and fill them in. */ | |
14997 | TYPE_NFIELDS (ftype) = nparams; | |
14998 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 14999 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 15000 | |
8072405b JK |
15001 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
15002 | even if we error out during the parameters reading below. */ | |
15003 | for (iparams = 0; iparams < nparams; iparams++) | |
15004 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
15005 | ||
15006 | iparams = 0; | |
639d11d3 | 15007 | child_die = die->child; |
c906108c SS |
15008 | while (child_die && child_die->tag) |
15009 | { | |
15010 | if (child_die->tag == DW_TAG_formal_parameter) | |
15011 | { | |
3ce3b1ba PA |
15012 | struct type *arg_type; |
15013 | ||
15014 | /* DWARF version 2 has no clean way to discern C++ | |
15015 | static and non-static member functions. G++ helps | |
15016 | GDB by marking the first parameter for non-static | |
15017 | member functions (which is the this pointer) as | |
15018 | artificial. We pass this information to | |
15019 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
15020 | ||
15021 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
15022 | 4.5 does not yet generate. */ | |
e142c38c | 15023 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
15024 | if (attr) |
15025 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
15026 | else | |
9c37b5ae | 15027 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; |
3ce3b1ba PA |
15028 | arg_type = die_type (child_die, cu); |
15029 | ||
15030 | /* RealView does not mark THIS as const, which the testsuite | |
15031 | expects. GCC marks THIS as const in method definitions, | |
15032 | but not in the class specifications (GCC PR 43053). */ | |
15033 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
15034 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
15035 | { | |
15036 | int is_this = 0; | |
15037 | struct dwarf2_cu *arg_cu = cu; | |
15038 | const char *name = dwarf2_name (child_die, cu); | |
15039 | ||
15040 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
15041 | if (attr) | |
15042 | { | |
15043 | /* If the compiler emits this, use it. */ | |
15044 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
15045 | is_this = 1; | |
15046 | } | |
15047 | else if (name && strcmp (name, "this") == 0) | |
15048 | /* Function definitions will have the argument names. */ | |
15049 | is_this = 1; | |
15050 | else if (name == NULL && iparams == 0) | |
15051 | /* Declarations may not have the names, so like | |
15052 | elsewhere in GDB, assume an artificial first | |
15053 | argument is "this". */ | |
15054 | is_this = 1; | |
15055 | ||
15056 | if (is_this) | |
15057 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
15058 | arg_type, 0); | |
15059 | } | |
15060 | ||
15061 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
15062 | iparams++; |
15063 | } | |
15064 | child_die = sibling_die (child_die); | |
15065 | } | |
15066 | } | |
15067 | ||
76c10ea2 | 15068 | return ftype; |
c906108c SS |
15069 | } |
15070 | ||
f792889a | 15071 | static struct type * |
e7c27a73 | 15072 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 15073 | { |
e7c27a73 | 15074 | struct objfile *objfile = cu->objfile; |
0114d602 | 15075 | const char *name = NULL; |
3c8e0968 | 15076 | struct type *this_type, *target_type; |
c906108c | 15077 | |
94af9270 | 15078 | name = dwarf2_full_name (NULL, die, cu); |
19f392bc UW |
15079 | this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, name); |
15080 | TYPE_TARGET_STUB (this_type) = 1; | |
f792889a | 15081 | set_die_type (die, this_type, cu); |
3c8e0968 DE |
15082 | target_type = die_type (die, cu); |
15083 | if (target_type != this_type) | |
15084 | TYPE_TARGET_TYPE (this_type) = target_type; | |
15085 | else | |
15086 | { | |
15087 | /* Self-referential typedefs are, it seems, not allowed by the DWARF | |
15088 | spec and cause infinite loops in GDB. */ | |
15089 | complaint (&symfile_complaints, | |
15090 | _("Self-referential DW_TAG_typedef " | |
15091 | "- DIE at 0x%x [in module %s]"), | |
9c541725 | 15092 | to_underlying (die->sect_off), objfile_name (objfile)); |
3c8e0968 DE |
15093 | TYPE_TARGET_TYPE (this_type) = NULL; |
15094 | } | |
f792889a | 15095 | return this_type; |
c906108c SS |
15096 | } |
15097 | ||
9b790ce7 UW |
15098 | /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT |
15099 | (which may be different from NAME) to the architecture back-end to allow | |
15100 | it to guess the correct format if necessary. */ | |
15101 | ||
15102 | static struct type * | |
15103 | dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name, | |
15104 | const char *name_hint) | |
15105 | { | |
15106 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
15107 | const struct floatformat **format; | |
15108 | struct type *type; | |
15109 | ||
15110 | format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits); | |
15111 | if (format) | |
15112 | type = init_float_type (objfile, bits, name, format); | |
15113 | else | |
15114 | type = init_type (objfile, TYPE_CODE_ERROR, bits / TARGET_CHAR_BIT, name); | |
15115 | ||
15116 | return type; | |
15117 | } | |
15118 | ||
c906108c SS |
15119 | /* Find a representation of a given base type and install |
15120 | it in the TYPE field of the die. */ | |
15121 | ||
f792889a | 15122 | static struct type * |
e7c27a73 | 15123 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 15124 | { |
e7c27a73 | 15125 | struct objfile *objfile = cu->objfile; |
c906108c SS |
15126 | struct type *type; |
15127 | struct attribute *attr; | |
19f392bc | 15128 | int encoding = 0, bits = 0; |
15d034d0 | 15129 | const char *name; |
c906108c | 15130 | |
e142c38c | 15131 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
15132 | if (attr) |
15133 | { | |
15134 | encoding = DW_UNSND (attr); | |
15135 | } | |
e142c38c | 15136 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
15137 | if (attr) |
15138 | { | |
19f392bc | 15139 | bits = DW_UNSND (attr) * TARGET_CHAR_BIT; |
c906108c | 15140 | } |
39cbfefa | 15141 | name = dwarf2_name (die, cu); |
6ccb9162 | 15142 | if (!name) |
c906108c | 15143 | { |
6ccb9162 UW |
15144 | complaint (&symfile_complaints, |
15145 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 15146 | } |
6ccb9162 UW |
15147 | |
15148 | switch (encoding) | |
c906108c | 15149 | { |
6ccb9162 UW |
15150 | case DW_ATE_address: |
15151 | /* Turn DW_ATE_address into a void * pointer. */ | |
19f392bc UW |
15152 | type = init_type (objfile, TYPE_CODE_VOID, 1, NULL); |
15153 | type = init_pointer_type (objfile, bits, name, type); | |
6ccb9162 UW |
15154 | break; |
15155 | case DW_ATE_boolean: | |
19f392bc | 15156 | type = init_boolean_type (objfile, bits, 1, name); |
6ccb9162 UW |
15157 | break; |
15158 | case DW_ATE_complex_float: | |
9b790ce7 | 15159 | type = dwarf2_init_float_type (objfile, bits / 2, NULL, name); |
19f392bc | 15160 | type = init_complex_type (objfile, name, type); |
6ccb9162 UW |
15161 | break; |
15162 | case DW_ATE_decimal_float: | |
19f392bc | 15163 | type = init_decfloat_type (objfile, bits, name); |
6ccb9162 UW |
15164 | break; |
15165 | case DW_ATE_float: | |
9b790ce7 | 15166 | type = dwarf2_init_float_type (objfile, bits, name, name); |
6ccb9162 UW |
15167 | break; |
15168 | case DW_ATE_signed: | |
19f392bc | 15169 | type = init_integer_type (objfile, bits, 0, name); |
6ccb9162 UW |
15170 | break; |
15171 | case DW_ATE_unsigned: | |
3b2b8fea TT |
15172 | if (cu->language == language_fortran |
15173 | && name | |
61012eef | 15174 | && startswith (name, "character(")) |
19f392bc UW |
15175 | type = init_character_type (objfile, bits, 1, name); |
15176 | else | |
15177 | type = init_integer_type (objfile, bits, 1, name); | |
6ccb9162 UW |
15178 | break; |
15179 | case DW_ATE_signed_char: | |
6e70227d | 15180 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
15181 | || cu->language == language_pascal |
15182 | || cu->language == language_fortran) | |
19f392bc UW |
15183 | type = init_character_type (objfile, bits, 0, name); |
15184 | else | |
15185 | type = init_integer_type (objfile, bits, 0, name); | |
6ccb9162 UW |
15186 | break; |
15187 | case DW_ATE_unsigned_char: | |
868a0084 | 15188 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea | 15189 | || cu->language == language_pascal |
c44af4eb TT |
15190 | || cu->language == language_fortran |
15191 | || cu->language == language_rust) | |
19f392bc UW |
15192 | type = init_character_type (objfile, bits, 1, name); |
15193 | else | |
15194 | type = init_integer_type (objfile, bits, 1, name); | |
6ccb9162 | 15195 | break; |
75079b2b | 15196 | case DW_ATE_UTF: |
53e710ac PA |
15197 | { |
15198 | gdbarch *arch = get_objfile_arch (objfile); | |
15199 | ||
15200 | if (bits == 16) | |
15201 | type = builtin_type (arch)->builtin_char16; | |
15202 | else if (bits == 32) | |
15203 | type = builtin_type (arch)->builtin_char32; | |
15204 | else | |
15205 | { | |
15206 | complaint (&symfile_complaints, | |
15207 | _("unsupported DW_ATE_UTF bit size: '%d'"), | |
15208 | bits); | |
15209 | type = init_integer_type (objfile, bits, 1, name); | |
15210 | } | |
15211 | return set_die_type (die, type, cu); | |
15212 | } | |
75079b2b TT |
15213 | break; |
15214 | ||
6ccb9162 UW |
15215 | default: |
15216 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
15217 | dwarf_type_encoding_name (encoding)); | |
19f392bc UW |
15218 | type = init_type (objfile, TYPE_CODE_ERROR, |
15219 | bits / TARGET_CHAR_BIT, name); | |
6ccb9162 | 15220 | break; |
c906108c | 15221 | } |
6ccb9162 | 15222 | |
0114d602 | 15223 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 15224 | TYPE_NOSIGN (type) = 1; |
0114d602 | 15225 | |
f792889a | 15226 | return set_die_type (die, type, cu); |
c906108c SS |
15227 | } |
15228 | ||
80180f79 SA |
15229 | /* Parse dwarf attribute if it's a block, reference or constant and put the |
15230 | resulting value of the attribute into struct bound_prop. | |
15231 | Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */ | |
15232 | ||
15233 | static int | |
15234 | attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, | |
15235 | struct dwarf2_cu *cu, struct dynamic_prop *prop) | |
15236 | { | |
15237 | struct dwarf2_property_baton *baton; | |
15238 | struct obstack *obstack = &cu->objfile->objfile_obstack; | |
15239 | ||
15240 | if (attr == NULL || prop == NULL) | |
15241 | return 0; | |
15242 | ||
15243 | if (attr_form_is_block (attr)) | |
15244 | { | |
8d749320 | 15245 | baton = XOBNEW (obstack, struct dwarf2_property_baton); |
80180f79 SA |
15246 | baton->referenced_type = NULL; |
15247 | baton->locexpr.per_cu = cu->per_cu; | |
15248 | baton->locexpr.size = DW_BLOCK (attr)->size; | |
15249 | baton->locexpr.data = DW_BLOCK (attr)->data; | |
15250 | prop->data.baton = baton; | |
15251 | prop->kind = PROP_LOCEXPR; | |
15252 | gdb_assert (prop->data.baton != NULL); | |
15253 | } | |
15254 | else if (attr_form_is_ref (attr)) | |
15255 | { | |
15256 | struct dwarf2_cu *target_cu = cu; | |
15257 | struct die_info *target_die; | |
15258 | struct attribute *target_attr; | |
15259 | ||
15260 | target_die = follow_die_ref (die, attr, &target_cu); | |
15261 | target_attr = dwarf2_attr (target_die, DW_AT_location, target_cu); | |
df25ebbd JB |
15262 | if (target_attr == NULL) |
15263 | target_attr = dwarf2_attr (target_die, DW_AT_data_member_location, | |
15264 | target_cu); | |
80180f79 SA |
15265 | if (target_attr == NULL) |
15266 | return 0; | |
15267 | ||
df25ebbd | 15268 | switch (target_attr->name) |
80180f79 | 15269 | { |
df25ebbd JB |
15270 | case DW_AT_location: |
15271 | if (attr_form_is_section_offset (target_attr)) | |
15272 | { | |
8d749320 | 15273 | baton = XOBNEW (obstack, struct dwarf2_property_baton); |
df25ebbd JB |
15274 | baton->referenced_type = die_type (target_die, target_cu); |
15275 | fill_in_loclist_baton (cu, &baton->loclist, target_attr); | |
15276 | prop->data.baton = baton; | |
15277 | prop->kind = PROP_LOCLIST; | |
15278 | gdb_assert (prop->data.baton != NULL); | |
15279 | } | |
15280 | else if (attr_form_is_block (target_attr)) | |
15281 | { | |
8d749320 | 15282 | baton = XOBNEW (obstack, struct dwarf2_property_baton); |
df25ebbd JB |
15283 | baton->referenced_type = die_type (target_die, target_cu); |
15284 | baton->locexpr.per_cu = cu->per_cu; | |
15285 | baton->locexpr.size = DW_BLOCK (target_attr)->size; | |
15286 | baton->locexpr.data = DW_BLOCK (target_attr)->data; | |
15287 | prop->data.baton = baton; | |
15288 | prop->kind = PROP_LOCEXPR; | |
15289 | gdb_assert (prop->data.baton != NULL); | |
15290 | } | |
15291 | else | |
15292 | { | |
15293 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", | |
15294 | "dynamic property"); | |
15295 | return 0; | |
15296 | } | |
15297 | break; | |
15298 | case DW_AT_data_member_location: | |
15299 | { | |
15300 | LONGEST offset; | |
15301 | ||
15302 | if (!handle_data_member_location (target_die, target_cu, | |
15303 | &offset)) | |
15304 | return 0; | |
15305 | ||
8d749320 | 15306 | baton = XOBNEW (obstack, struct dwarf2_property_baton); |
6ad395a7 JB |
15307 | baton->referenced_type = read_type_die (target_die->parent, |
15308 | target_cu); | |
df25ebbd JB |
15309 | baton->offset_info.offset = offset; |
15310 | baton->offset_info.type = die_type (target_die, target_cu); | |
15311 | prop->data.baton = baton; | |
15312 | prop->kind = PROP_ADDR_OFFSET; | |
15313 | break; | |
15314 | } | |
80180f79 SA |
15315 | } |
15316 | } | |
15317 | else if (attr_form_is_constant (attr)) | |
15318 | { | |
15319 | prop->data.const_val = dwarf2_get_attr_constant_value (attr, 0); | |
15320 | prop->kind = PROP_CONST; | |
15321 | } | |
15322 | else | |
15323 | { | |
15324 | dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form), | |
15325 | dwarf2_name (die, cu)); | |
15326 | return 0; | |
15327 | } | |
15328 | ||
15329 | return 1; | |
15330 | } | |
15331 | ||
a02abb62 JB |
15332 | /* Read the given DW_AT_subrange DIE. */ |
15333 | ||
f792889a | 15334 | static struct type * |
a02abb62 JB |
15335 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
15336 | { | |
4c9ad8c2 | 15337 | struct type *base_type, *orig_base_type; |
a02abb62 JB |
15338 | struct type *range_type; |
15339 | struct attribute *attr; | |
729efb13 | 15340 | struct dynamic_prop low, high; |
4fae6e18 | 15341 | int low_default_is_valid; |
c451ebe5 | 15342 | int high_bound_is_count = 0; |
15d034d0 | 15343 | const char *name; |
43bbcdc2 | 15344 | LONGEST negative_mask; |
e77813c8 | 15345 | |
4c9ad8c2 TT |
15346 | orig_base_type = die_type (die, cu); |
15347 | /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED, | |
15348 | whereas the real type might be. So, we use ORIG_BASE_TYPE when | |
15349 | creating the range type, but we use the result of check_typedef | |
15350 | when examining properties of the type. */ | |
15351 | base_type = check_typedef (orig_base_type); | |
a02abb62 | 15352 | |
7e314c57 JK |
15353 | /* The die_type call above may have already set the type for this DIE. */ |
15354 | range_type = get_die_type (die, cu); | |
15355 | if (range_type) | |
15356 | return range_type; | |
15357 | ||
729efb13 SA |
15358 | low.kind = PROP_CONST; |
15359 | high.kind = PROP_CONST; | |
15360 | high.data.const_val = 0; | |
15361 | ||
4fae6e18 JK |
15362 | /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow |
15363 | omitting DW_AT_lower_bound. */ | |
15364 | switch (cu->language) | |
6e70227d | 15365 | { |
4fae6e18 JK |
15366 | case language_c: |
15367 | case language_cplus: | |
729efb13 | 15368 | low.data.const_val = 0; |
4fae6e18 JK |
15369 | low_default_is_valid = 1; |
15370 | break; | |
15371 | case language_fortran: | |
729efb13 | 15372 | low.data.const_val = 1; |
4fae6e18 JK |
15373 | low_default_is_valid = 1; |
15374 | break; | |
15375 | case language_d: | |
4fae6e18 | 15376 | case language_objc: |
c44af4eb | 15377 | case language_rust: |
729efb13 | 15378 | low.data.const_val = 0; |
4fae6e18 JK |
15379 | low_default_is_valid = (cu->header.version >= 4); |
15380 | break; | |
15381 | case language_ada: | |
15382 | case language_m2: | |
15383 | case language_pascal: | |
729efb13 | 15384 | low.data.const_val = 1; |
4fae6e18 JK |
15385 | low_default_is_valid = (cu->header.version >= 4); |
15386 | break; | |
15387 | default: | |
729efb13 | 15388 | low.data.const_val = 0; |
4fae6e18 JK |
15389 | low_default_is_valid = 0; |
15390 | break; | |
a02abb62 JB |
15391 | } |
15392 | ||
e142c38c | 15393 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 | 15394 | if (attr) |
11c1ba78 | 15395 | attr_to_dynamic_prop (attr, die, cu, &low); |
4fae6e18 JK |
15396 | else if (!low_default_is_valid) |
15397 | complaint (&symfile_complaints, _("Missing DW_AT_lower_bound " | |
15398 | "- DIE at 0x%x [in module %s]"), | |
9c541725 | 15399 | to_underlying (die->sect_off), objfile_name (cu->objfile)); |
a02abb62 | 15400 | |
e142c38c | 15401 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
80180f79 | 15402 | if (!attr_to_dynamic_prop (attr, die, cu, &high)) |
e77813c8 PM |
15403 | { |
15404 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
c451ebe5 | 15405 | if (attr_to_dynamic_prop (attr, die, cu, &high)) |
6b662e19 | 15406 | { |
c451ebe5 SA |
15407 | /* If bounds are constant do the final calculation here. */ |
15408 | if (low.kind == PROP_CONST && high.kind == PROP_CONST) | |
15409 | high.data.const_val = low.data.const_val + high.data.const_val - 1; | |
15410 | else | |
15411 | high_bound_is_count = 1; | |
c2ff108b | 15412 | } |
e77813c8 PM |
15413 | } |
15414 | ||
15415 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
15416 | without specifying a base type. | |
15417 | In that case, the base type must be set to the type of | |
15418 | the lower bound, upper bound or count, in that order, if any of these | |
15419 | three attributes references an object that has a type. | |
15420 | If no base type is found, the Dwarf-2 specifications say that | |
15421 | a signed integer type of size equal to the size of an address should | |
15422 | be used. | |
15423 | For the following C code: `extern char gdb_int [];' | |
15424 | GCC produces an empty range DIE. | |
15425 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 15426 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
15427 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
15428 | { | |
15429 | struct objfile *objfile = cu->objfile; | |
15430 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
15431 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
15432 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
15433 | ||
15434 | /* Test "int", "long int", and "long long int" objfile types, | |
15435 | and select the first one having a size above or equal to the | |
15436 | architecture address size. */ | |
15437 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
15438 | base_type = int_type; | |
15439 | else | |
15440 | { | |
15441 | int_type = objfile_type (objfile)->builtin_long; | |
15442 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
15443 | base_type = int_type; | |
15444 | else | |
15445 | { | |
15446 | int_type = objfile_type (objfile)->builtin_long_long; | |
15447 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
15448 | base_type = int_type; | |
15449 | } | |
15450 | } | |
15451 | } | |
a02abb62 | 15452 | |
dbb9c2b1 JB |
15453 | /* Normally, the DWARF producers are expected to use a signed |
15454 | constant form (Eg. DW_FORM_sdata) to express negative bounds. | |
15455 | But this is unfortunately not always the case, as witnessed | |
15456 | with GCC, for instance, where the ambiguous DW_FORM_dataN form | |
15457 | is used instead. To work around that ambiguity, we treat | |
15458 | the bounds as signed, and thus sign-extend their values, when | |
15459 | the base type is signed. */ | |
6e70227d | 15460 | negative_mask = |
66c6502d | 15461 | -((LONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1)); |
729efb13 SA |
15462 | if (low.kind == PROP_CONST |
15463 | && !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask)) | |
15464 | low.data.const_val |= negative_mask; | |
15465 | if (high.kind == PROP_CONST | |
15466 | && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask)) | |
15467 | high.data.const_val |= negative_mask; | |
43bbcdc2 | 15468 | |
729efb13 | 15469 | range_type = create_range_type (NULL, orig_base_type, &low, &high); |
a02abb62 | 15470 | |
c451ebe5 SA |
15471 | if (high_bound_is_count) |
15472 | TYPE_RANGE_DATA (range_type)->flag_upper_bound_is_count = 1; | |
15473 | ||
c2ff108b JK |
15474 | /* Ada expects an empty array on no boundary attributes. */ |
15475 | if (attr == NULL && cu->language != language_ada) | |
729efb13 | 15476 | TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED; |
c2ff108b | 15477 | |
39cbfefa DJ |
15478 | name = dwarf2_name (die, cu); |
15479 | if (name) | |
15480 | TYPE_NAME (range_type) = name; | |
6e70227d | 15481 | |
e142c38c | 15482 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
15483 | if (attr) |
15484 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
15485 | ||
7e314c57 JK |
15486 | set_die_type (die, range_type, cu); |
15487 | ||
15488 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
15489 | set_descriptive_type (range_type, die, cu); |
15490 | ||
7e314c57 | 15491 | return range_type; |
a02abb62 | 15492 | } |
6e70227d | 15493 | |
f792889a | 15494 | static struct type * |
81a17f79 JB |
15495 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
15496 | { | |
15497 | struct type *type; | |
81a17f79 | 15498 | |
81a17f79 JB |
15499 | /* For now, we only support the C meaning of an unspecified type: void. */ |
15500 | ||
19f392bc | 15501 | type = init_type (cu->objfile, TYPE_CODE_VOID, 0, NULL); |
0114d602 | 15502 | TYPE_NAME (type) = dwarf2_name (die, cu); |
81a17f79 | 15503 | |
f792889a | 15504 | return set_die_type (die, type, cu); |
81a17f79 | 15505 | } |
a02abb62 | 15506 | |
639d11d3 DC |
15507 | /* Read a single die and all its descendents. Set the die's sibling |
15508 | field to NULL; set other fields in the die correctly, and set all | |
15509 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
15510 | location of the info_ptr after reading all of those dies. PARENT | |
15511 | is the parent of the die in question. */ | |
15512 | ||
15513 | static struct die_info * | |
dee91e82 | 15514 | read_die_and_children (const struct die_reader_specs *reader, |
d521ce57 TT |
15515 | const gdb_byte *info_ptr, |
15516 | const gdb_byte **new_info_ptr, | |
dee91e82 | 15517 | struct die_info *parent) |
639d11d3 DC |
15518 | { |
15519 | struct die_info *die; | |
d521ce57 | 15520 | const gdb_byte *cur_ptr; |
639d11d3 DC |
15521 | int has_children; |
15522 | ||
bf6af496 | 15523 | cur_ptr = read_full_die_1 (reader, &die, info_ptr, &has_children, 0); |
1d325ec1 DJ |
15524 | if (die == NULL) |
15525 | { | |
15526 | *new_info_ptr = cur_ptr; | |
15527 | return NULL; | |
15528 | } | |
93311388 | 15529 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
15530 | |
15531 | if (has_children) | |
bf6af496 | 15532 | die->child = read_die_and_siblings_1 (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
15533 | else |
15534 | { | |
15535 | die->child = NULL; | |
15536 | *new_info_ptr = cur_ptr; | |
15537 | } | |
15538 | ||
15539 | die->sibling = NULL; | |
15540 | die->parent = parent; | |
15541 | return die; | |
15542 | } | |
15543 | ||
15544 | /* Read a die, all of its descendents, and all of its siblings; set | |
15545 | all of the fields of all of the dies correctly. Arguments are as | |
15546 | in read_die_and_children. */ | |
15547 | ||
15548 | static struct die_info * | |
bf6af496 | 15549 | read_die_and_siblings_1 (const struct die_reader_specs *reader, |
d521ce57 TT |
15550 | const gdb_byte *info_ptr, |
15551 | const gdb_byte **new_info_ptr, | |
bf6af496 | 15552 | struct die_info *parent) |
639d11d3 DC |
15553 | { |
15554 | struct die_info *first_die, *last_sibling; | |
d521ce57 | 15555 | const gdb_byte *cur_ptr; |
639d11d3 | 15556 | |
c906108c | 15557 | cur_ptr = info_ptr; |
639d11d3 DC |
15558 | first_die = last_sibling = NULL; |
15559 | ||
15560 | while (1) | |
c906108c | 15561 | { |
639d11d3 | 15562 | struct die_info *die |
dee91e82 | 15563 | = read_die_and_children (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 15564 | |
1d325ec1 | 15565 | if (die == NULL) |
c906108c | 15566 | { |
639d11d3 DC |
15567 | *new_info_ptr = cur_ptr; |
15568 | return first_die; | |
c906108c | 15569 | } |
1d325ec1 DJ |
15570 | |
15571 | if (!first_die) | |
15572 | first_die = die; | |
c906108c | 15573 | else |
1d325ec1 DJ |
15574 | last_sibling->sibling = die; |
15575 | ||
15576 | last_sibling = die; | |
c906108c | 15577 | } |
c906108c SS |
15578 | } |
15579 | ||
bf6af496 DE |
15580 | /* Read a die, all of its descendents, and all of its siblings; set |
15581 | all of the fields of all of the dies correctly. Arguments are as | |
15582 | in read_die_and_children. | |
15583 | This the main entry point for reading a DIE and all its children. */ | |
15584 | ||
15585 | static struct die_info * | |
15586 | read_die_and_siblings (const struct die_reader_specs *reader, | |
d521ce57 TT |
15587 | const gdb_byte *info_ptr, |
15588 | const gdb_byte **new_info_ptr, | |
bf6af496 DE |
15589 | struct die_info *parent) |
15590 | { | |
15591 | struct die_info *die = read_die_and_siblings_1 (reader, info_ptr, | |
15592 | new_info_ptr, parent); | |
15593 | ||
b4f54984 | 15594 | if (dwarf_die_debug) |
bf6af496 DE |
15595 | { |
15596 | fprintf_unfiltered (gdb_stdlog, | |
15597 | "Read die from %s@0x%x of %s:\n", | |
a32a8923 | 15598 | get_section_name (reader->die_section), |
bf6af496 DE |
15599 | (unsigned) (info_ptr - reader->die_section->buffer), |
15600 | bfd_get_filename (reader->abfd)); | |
b4f54984 | 15601 | dump_die (die, dwarf_die_debug); |
bf6af496 DE |
15602 | } |
15603 | ||
15604 | return die; | |
15605 | } | |
15606 | ||
3019eac3 DE |
15607 | /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS |
15608 | attributes. | |
15609 | The caller is responsible for filling in the extra attributes | |
15610 | and updating (*DIEP)->num_attrs. | |
15611 | Set DIEP to point to a newly allocated die with its information, | |
15612 | except for its child, sibling, and parent fields. | |
15613 | Set HAS_CHILDREN to tell whether the die has children or not. */ | |
93311388 | 15614 | |
d521ce57 | 15615 | static const gdb_byte * |
3019eac3 | 15616 | read_full_die_1 (const struct die_reader_specs *reader, |
d521ce57 | 15617 | struct die_info **diep, const gdb_byte *info_ptr, |
3019eac3 | 15618 | int *has_children, int num_extra_attrs) |
93311388 | 15619 | { |
b64f50a1 | 15620 | unsigned int abbrev_number, bytes_read, i; |
93311388 DE |
15621 | struct abbrev_info *abbrev; |
15622 | struct die_info *die; | |
15623 | struct dwarf2_cu *cu = reader->cu; | |
15624 | bfd *abfd = reader->abfd; | |
15625 | ||
9c541725 | 15626 | sect_offset sect_off = (sect_offset) (info_ptr - reader->buffer); |
93311388 DE |
15627 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
15628 | info_ptr += bytes_read; | |
15629 | if (!abbrev_number) | |
15630 | { | |
15631 | *diep = NULL; | |
15632 | *has_children = 0; | |
15633 | return info_ptr; | |
15634 | } | |
15635 | ||
433df2d4 | 15636 | abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number); |
93311388 | 15637 | if (!abbrev) |
348e048f DE |
15638 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
15639 | abbrev_number, | |
15640 | bfd_get_filename (abfd)); | |
15641 | ||
3019eac3 | 15642 | die = dwarf_alloc_die (cu, abbrev->num_attrs + num_extra_attrs); |
9c541725 | 15643 | die->sect_off = sect_off; |
93311388 DE |
15644 | die->tag = abbrev->tag; |
15645 | die->abbrev = abbrev_number; | |
15646 | ||
3019eac3 DE |
15647 | /* Make the result usable. |
15648 | The caller needs to update num_attrs after adding the extra | |
15649 | attributes. */ | |
93311388 DE |
15650 | die->num_attrs = abbrev->num_attrs; |
15651 | ||
15652 | for (i = 0; i < abbrev->num_attrs; ++i) | |
dee91e82 DE |
15653 | info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i], |
15654 | info_ptr); | |
93311388 DE |
15655 | |
15656 | *diep = die; | |
15657 | *has_children = abbrev->has_children; | |
15658 | return info_ptr; | |
15659 | } | |
15660 | ||
3019eac3 DE |
15661 | /* Read a die and all its attributes. |
15662 | Set DIEP to point to a newly allocated die with its information, | |
15663 | except for its child, sibling, and parent fields. | |
15664 | Set HAS_CHILDREN to tell whether the die has children or not. */ | |
15665 | ||
d521ce57 | 15666 | static const gdb_byte * |
3019eac3 | 15667 | read_full_die (const struct die_reader_specs *reader, |
d521ce57 | 15668 | struct die_info **diep, const gdb_byte *info_ptr, |
3019eac3 DE |
15669 | int *has_children) |
15670 | { | |
d521ce57 | 15671 | const gdb_byte *result; |
bf6af496 DE |
15672 | |
15673 | result = read_full_die_1 (reader, diep, info_ptr, has_children, 0); | |
15674 | ||
b4f54984 | 15675 | if (dwarf_die_debug) |
bf6af496 DE |
15676 | { |
15677 | fprintf_unfiltered (gdb_stdlog, | |
15678 | "Read die from %s@0x%x of %s:\n", | |
a32a8923 | 15679 | get_section_name (reader->die_section), |
bf6af496 DE |
15680 | (unsigned) (info_ptr - reader->die_section->buffer), |
15681 | bfd_get_filename (reader->abfd)); | |
b4f54984 | 15682 | dump_die (*diep, dwarf_die_debug); |
bf6af496 DE |
15683 | } |
15684 | ||
15685 | return result; | |
3019eac3 | 15686 | } |
433df2d4 DE |
15687 | \f |
15688 | /* Abbreviation tables. | |
3019eac3 | 15689 | |
433df2d4 | 15690 | In DWARF version 2, the description of the debugging information is |
c906108c SS |
15691 | stored in a separate .debug_abbrev section. Before we read any |
15692 | dies from a section we read in all abbreviations and install them | |
433df2d4 DE |
15693 | in a hash table. */ |
15694 | ||
15695 | /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */ | |
15696 | ||
15697 | static struct abbrev_info * | |
15698 | abbrev_table_alloc_abbrev (struct abbrev_table *abbrev_table) | |
15699 | { | |
15700 | struct abbrev_info *abbrev; | |
15701 | ||
8d749320 | 15702 | abbrev = XOBNEW (&abbrev_table->abbrev_obstack, struct abbrev_info); |
433df2d4 | 15703 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
8d749320 | 15704 | |
433df2d4 DE |
15705 | return abbrev; |
15706 | } | |
15707 | ||
15708 | /* Add an abbreviation to the table. */ | |
c906108c SS |
15709 | |
15710 | static void | |
433df2d4 DE |
15711 | abbrev_table_add_abbrev (struct abbrev_table *abbrev_table, |
15712 | unsigned int abbrev_number, | |
15713 | struct abbrev_info *abbrev) | |
15714 | { | |
15715 | unsigned int hash_number; | |
15716 | ||
15717 | hash_number = abbrev_number % ABBREV_HASH_SIZE; | |
15718 | abbrev->next = abbrev_table->abbrevs[hash_number]; | |
15719 | abbrev_table->abbrevs[hash_number] = abbrev; | |
15720 | } | |
dee91e82 | 15721 | |
433df2d4 DE |
15722 | /* Look up an abbrev in the table. |
15723 | Returns NULL if the abbrev is not found. */ | |
15724 | ||
15725 | static struct abbrev_info * | |
15726 | abbrev_table_lookup_abbrev (const struct abbrev_table *abbrev_table, | |
15727 | unsigned int abbrev_number) | |
c906108c | 15728 | { |
433df2d4 DE |
15729 | unsigned int hash_number; |
15730 | struct abbrev_info *abbrev; | |
15731 | ||
15732 | hash_number = abbrev_number % ABBREV_HASH_SIZE; | |
15733 | abbrev = abbrev_table->abbrevs[hash_number]; | |
15734 | ||
15735 | while (abbrev) | |
15736 | { | |
15737 | if (abbrev->number == abbrev_number) | |
15738 | return abbrev; | |
15739 | abbrev = abbrev->next; | |
15740 | } | |
15741 | return NULL; | |
15742 | } | |
15743 | ||
15744 | /* Read in an abbrev table. */ | |
15745 | ||
15746 | static struct abbrev_table * | |
15747 | abbrev_table_read_table (struct dwarf2_section_info *section, | |
9c541725 | 15748 | sect_offset sect_off) |
433df2d4 DE |
15749 | { |
15750 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
a32a8923 | 15751 | bfd *abfd = get_section_bfd_owner (section); |
433df2d4 | 15752 | struct abbrev_table *abbrev_table; |
d521ce57 | 15753 | const gdb_byte *abbrev_ptr; |
c906108c SS |
15754 | struct abbrev_info *cur_abbrev; |
15755 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
433df2d4 | 15756 | unsigned int abbrev_form; |
f3dd6933 DJ |
15757 | struct attr_abbrev *cur_attrs; |
15758 | unsigned int allocated_attrs; | |
c906108c | 15759 | |
70ba0933 | 15760 | abbrev_table = XNEW (struct abbrev_table); |
9c541725 | 15761 | abbrev_table->sect_off = sect_off; |
433df2d4 | 15762 | obstack_init (&abbrev_table->abbrev_obstack); |
8d749320 SM |
15763 | abbrev_table->abbrevs = |
15764 | XOBNEWVEC (&abbrev_table->abbrev_obstack, struct abbrev_info *, | |
15765 | ABBREV_HASH_SIZE); | |
433df2d4 DE |
15766 | memset (abbrev_table->abbrevs, 0, |
15767 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 15768 | |
433df2d4 | 15769 | dwarf2_read_section (objfile, section); |
9c541725 | 15770 | abbrev_ptr = section->buffer + to_underlying (sect_off); |
c906108c SS |
15771 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
15772 | abbrev_ptr += bytes_read; | |
15773 | ||
f3dd6933 | 15774 | allocated_attrs = ATTR_ALLOC_CHUNK; |
8d749320 | 15775 | cur_attrs = XNEWVEC (struct attr_abbrev, allocated_attrs); |
6e70227d | 15776 | |
0963b4bd | 15777 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
15778 | while (abbrev_number) |
15779 | { | |
433df2d4 | 15780 | cur_abbrev = abbrev_table_alloc_abbrev (abbrev_table); |
c906108c SS |
15781 | |
15782 | /* read in abbrev header */ | |
15783 | cur_abbrev->number = abbrev_number; | |
aead7601 SM |
15784 | cur_abbrev->tag |
15785 | = (enum dwarf_tag) read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
c906108c SS |
15786 | abbrev_ptr += bytes_read; |
15787 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
15788 | abbrev_ptr += 1; | |
15789 | ||
15790 | /* now read in declarations */ | |
22d2f3ab | 15791 | for (;;) |
c906108c | 15792 | { |
43988095 JK |
15793 | LONGEST implicit_const; |
15794 | ||
22d2f3ab JK |
15795 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
15796 | abbrev_ptr += bytes_read; | |
15797 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
15798 | abbrev_ptr += bytes_read; | |
43988095 JK |
15799 | if (abbrev_form == DW_FORM_implicit_const) |
15800 | { | |
15801 | implicit_const = read_signed_leb128 (abfd, abbrev_ptr, | |
15802 | &bytes_read); | |
15803 | abbrev_ptr += bytes_read; | |
15804 | } | |
15805 | else | |
15806 | { | |
15807 | /* Initialize it due to a false compiler warning. */ | |
15808 | implicit_const = -1; | |
15809 | } | |
22d2f3ab JK |
15810 | |
15811 | if (abbrev_name == 0) | |
15812 | break; | |
15813 | ||
f3dd6933 | 15814 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 15815 | { |
f3dd6933 DJ |
15816 | allocated_attrs += ATTR_ALLOC_CHUNK; |
15817 | cur_attrs | |
224c3ddb | 15818 | = XRESIZEVEC (struct attr_abbrev, cur_attrs, allocated_attrs); |
c906108c | 15819 | } |
ae038cb0 | 15820 | |
aead7601 SM |
15821 | cur_attrs[cur_abbrev->num_attrs].name |
15822 | = (enum dwarf_attribute) abbrev_name; | |
22d2f3ab | 15823 | cur_attrs[cur_abbrev->num_attrs].form |
aead7601 | 15824 | = (enum dwarf_form) abbrev_form; |
43988095 | 15825 | cur_attrs[cur_abbrev->num_attrs].implicit_const = implicit_const; |
22d2f3ab | 15826 | ++cur_abbrev->num_attrs; |
c906108c SS |
15827 | } |
15828 | ||
8d749320 SM |
15829 | cur_abbrev->attrs = |
15830 | XOBNEWVEC (&abbrev_table->abbrev_obstack, struct attr_abbrev, | |
15831 | cur_abbrev->num_attrs); | |
f3dd6933 DJ |
15832 | memcpy (cur_abbrev->attrs, cur_attrs, |
15833 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
15834 | ||
433df2d4 | 15835 | abbrev_table_add_abbrev (abbrev_table, abbrev_number, cur_abbrev); |
c906108c SS |
15836 | |
15837 | /* Get next abbreviation. | |
15838 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
15839 | always properly terminated with an abbrev number of 0. |
15840 | Exit loop if we encounter an abbreviation which we have | |
15841 | already read (which means we are about to read the abbreviations | |
15842 | for the next compile unit) or if the end of the abbreviation | |
15843 | table is reached. */ | |
433df2d4 | 15844 | if ((unsigned int) (abbrev_ptr - section->buffer) >= section->size) |
c906108c SS |
15845 | break; |
15846 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
15847 | abbrev_ptr += bytes_read; | |
433df2d4 | 15848 | if (abbrev_table_lookup_abbrev (abbrev_table, abbrev_number) != NULL) |
c906108c SS |
15849 | break; |
15850 | } | |
f3dd6933 DJ |
15851 | |
15852 | xfree (cur_attrs); | |
433df2d4 | 15853 | return abbrev_table; |
c906108c SS |
15854 | } |
15855 | ||
433df2d4 | 15856 | /* Free the resources held by ABBREV_TABLE. */ |
c906108c | 15857 | |
c906108c | 15858 | static void |
433df2d4 | 15859 | abbrev_table_free (struct abbrev_table *abbrev_table) |
c906108c | 15860 | { |
433df2d4 DE |
15861 | obstack_free (&abbrev_table->abbrev_obstack, NULL); |
15862 | xfree (abbrev_table); | |
c906108c SS |
15863 | } |
15864 | ||
f4dc4d17 DE |
15865 | /* Same as abbrev_table_free but as a cleanup. |
15866 | We pass in a pointer to the pointer to the table so that we can | |
15867 | set the pointer to NULL when we're done. It also simplifies | |
73051182 | 15868 | build_type_psymtabs_1. */ |
f4dc4d17 DE |
15869 | |
15870 | static void | |
15871 | abbrev_table_free_cleanup (void *table_ptr) | |
15872 | { | |
9a3c8263 | 15873 | struct abbrev_table **abbrev_table_ptr = (struct abbrev_table **) table_ptr; |
f4dc4d17 DE |
15874 | |
15875 | if (*abbrev_table_ptr != NULL) | |
15876 | abbrev_table_free (*abbrev_table_ptr); | |
15877 | *abbrev_table_ptr = NULL; | |
15878 | } | |
15879 | ||
433df2d4 DE |
15880 | /* Read the abbrev table for CU from ABBREV_SECTION. */ |
15881 | ||
15882 | static void | |
15883 | dwarf2_read_abbrevs (struct dwarf2_cu *cu, | |
15884 | struct dwarf2_section_info *abbrev_section) | |
c906108c | 15885 | { |
433df2d4 | 15886 | cu->abbrev_table = |
9c541725 | 15887 | abbrev_table_read_table (abbrev_section, cu->header.abbrev_sect_off); |
433df2d4 | 15888 | } |
c906108c | 15889 | |
433df2d4 | 15890 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 15891 | |
433df2d4 DE |
15892 | static void |
15893 | dwarf2_free_abbrev_table (void *ptr_to_cu) | |
15894 | { | |
9a3c8263 | 15895 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr_to_cu; |
c906108c | 15896 | |
a2ce51a0 DE |
15897 | if (cu->abbrev_table != NULL) |
15898 | abbrev_table_free (cu->abbrev_table); | |
433df2d4 DE |
15899 | /* Set this to NULL so that we SEGV if we try to read it later, |
15900 | and also because free_comp_unit verifies this is NULL. */ | |
15901 | cu->abbrev_table = NULL; | |
15902 | } | |
15903 | \f | |
72bf9492 DJ |
15904 | /* Returns nonzero if TAG represents a type that we might generate a partial |
15905 | symbol for. */ | |
15906 | ||
15907 | static int | |
15908 | is_type_tag_for_partial (int tag) | |
15909 | { | |
15910 | switch (tag) | |
15911 | { | |
15912 | #if 0 | |
15913 | /* Some types that would be reasonable to generate partial symbols for, | |
15914 | that we don't at present. */ | |
15915 | case DW_TAG_array_type: | |
15916 | case DW_TAG_file_type: | |
15917 | case DW_TAG_ptr_to_member_type: | |
15918 | case DW_TAG_set_type: | |
15919 | case DW_TAG_string_type: | |
15920 | case DW_TAG_subroutine_type: | |
15921 | #endif | |
15922 | case DW_TAG_base_type: | |
15923 | case DW_TAG_class_type: | |
680b30c7 | 15924 | case DW_TAG_interface_type: |
72bf9492 DJ |
15925 | case DW_TAG_enumeration_type: |
15926 | case DW_TAG_structure_type: | |
15927 | case DW_TAG_subrange_type: | |
15928 | case DW_TAG_typedef: | |
15929 | case DW_TAG_union_type: | |
15930 | return 1; | |
15931 | default: | |
15932 | return 0; | |
15933 | } | |
15934 | } | |
15935 | ||
15936 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
15937 | ||
15938 | static struct partial_die_info * | |
dee91e82 | 15939 | load_partial_dies (const struct die_reader_specs *reader, |
d521ce57 | 15940 | const gdb_byte *info_ptr, int building_psymtab) |
72bf9492 | 15941 | { |
dee91e82 | 15942 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 15943 | struct objfile *objfile = cu->objfile; |
72bf9492 DJ |
15944 | struct partial_die_info *part_die; |
15945 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
15946 | struct abbrev_info *abbrev; | |
15947 | unsigned int bytes_read; | |
5afb4e99 | 15948 | unsigned int load_all = 0; |
72bf9492 DJ |
15949 | int nesting_level = 1; |
15950 | ||
15951 | parent_die = NULL; | |
15952 | last_die = NULL; | |
15953 | ||
7adf1e79 DE |
15954 | gdb_assert (cu->per_cu != NULL); |
15955 | if (cu->per_cu->load_all_dies) | |
5afb4e99 DJ |
15956 | load_all = 1; |
15957 | ||
72bf9492 DJ |
15958 | cu->partial_dies |
15959 | = htab_create_alloc_ex (cu->header.length / 12, | |
15960 | partial_die_hash, | |
15961 | partial_die_eq, | |
15962 | NULL, | |
15963 | &cu->comp_unit_obstack, | |
15964 | hashtab_obstack_allocate, | |
15965 | dummy_obstack_deallocate); | |
15966 | ||
8d749320 | 15967 | part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info); |
72bf9492 DJ |
15968 | |
15969 | while (1) | |
15970 | { | |
15971 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
15972 | ||
15973 | /* A NULL abbrev means the end of a series of children. */ | |
15974 | if (abbrev == NULL) | |
15975 | { | |
15976 | if (--nesting_level == 0) | |
15977 | { | |
15978 | /* PART_DIE was probably the last thing allocated on the | |
15979 | comp_unit_obstack, so we could call obstack_free | |
15980 | here. We don't do that because the waste is small, | |
15981 | and will be cleaned up when we're done with this | |
15982 | compilation unit. This way, we're also more robust | |
15983 | against other users of the comp_unit_obstack. */ | |
15984 | return first_die; | |
15985 | } | |
15986 | info_ptr += bytes_read; | |
15987 | last_die = parent_die; | |
15988 | parent_die = parent_die->die_parent; | |
15989 | continue; | |
15990 | } | |
15991 | ||
98bfdba5 PA |
15992 | /* Check for template arguments. We never save these; if |
15993 | they're seen, we just mark the parent, and go on our way. */ | |
15994 | if (parent_die != NULL | |
15995 | && cu->language == language_cplus | |
15996 | && (abbrev->tag == DW_TAG_template_type_param | |
15997 | || abbrev->tag == DW_TAG_template_value_param)) | |
15998 | { | |
15999 | parent_die->has_template_arguments = 1; | |
16000 | ||
16001 | if (!load_all) | |
16002 | { | |
16003 | /* We don't need a partial DIE for the template argument. */ | |
dee91e82 | 16004 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
16005 | continue; |
16006 | } | |
16007 | } | |
16008 | ||
0d99eb77 | 16009 | /* We only recurse into c++ subprograms looking for template arguments. |
98bfdba5 PA |
16010 | Skip their other children. */ |
16011 | if (!load_all | |
16012 | && cu->language == language_cplus | |
16013 | && parent_die != NULL | |
16014 | && parent_die->tag == DW_TAG_subprogram) | |
16015 | { | |
dee91e82 | 16016 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
16017 | continue; |
16018 | } | |
16019 | ||
5afb4e99 DJ |
16020 | /* Check whether this DIE is interesting enough to save. Normally |
16021 | we would not be interested in members here, but there may be | |
16022 | later variables referencing them via DW_AT_specification (for | |
16023 | static members). */ | |
16024 | if (!load_all | |
16025 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 16026 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
16027 | && abbrev->tag != DW_TAG_enumerator |
16028 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 16029 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 16030 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 16031 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 16032 | && abbrev->tag != DW_TAG_module |
95554aad | 16033 | && abbrev->tag != DW_TAG_member |
74921315 KS |
16034 | && abbrev->tag != DW_TAG_imported_unit |
16035 | && abbrev->tag != DW_TAG_imported_declaration) | |
72bf9492 DJ |
16036 | { |
16037 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 16038 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
72bf9492 DJ |
16039 | continue; |
16040 | } | |
16041 | ||
dee91e82 DE |
16042 | info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read, |
16043 | info_ptr); | |
72bf9492 DJ |
16044 | |
16045 | /* This two-pass algorithm for processing partial symbols has a | |
16046 | high cost in cache pressure. Thus, handle some simple cases | |
16047 | here which cover the majority of C partial symbols. DIEs | |
16048 | which neither have specification tags in them, nor could have | |
16049 | specification tags elsewhere pointing at them, can simply be | |
16050 | processed and discarded. | |
16051 | ||
16052 | This segment is also optional; scan_partial_symbols and | |
16053 | add_partial_symbol will handle these DIEs if we chain | |
16054 | them in normally. When compilers which do not emit large | |
16055 | quantities of duplicate debug information are more common, | |
16056 | this code can probably be removed. */ | |
16057 | ||
16058 | /* Any complete simple types at the top level (pretty much all | |
16059 | of them, for a language without namespaces), can be processed | |
16060 | directly. */ | |
16061 | if (parent_die == NULL | |
16062 | && part_die->has_specification == 0 | |
16063 | && part_die->is_declaration == 0 | |
d8228535 | 16064 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
16065 | || part_die->tag == DW_TAG_base_type |
16066 | || part_die->tag == DW_TAG_subrange_type)) | |
16067 | { | |
16068 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 16069 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 16070 | VAR_DOMAIN, LOC_TYPEDEF, |
bb5ed363 | 16071 | &objfile->static_psymbols, |
1762568f | 16072 | 0, cu->language, objfile); |
dee91e82 | 16073 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
16074 | continue; |
16075 | } | |
16076 | ||
d8228535 JK |
16077 | /* The exception for DW_TAG_typedef with has_children above is |
16078 | a workaround of GCC PR debug/47510. In the case of this complaint | |
16079 | type_name_no_tag_or_error will error on such types later. | |
16080 | ||
16081 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
16082 | it could not find the child DIEs referenced later, this is checked | |
16083 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
16084 | ||
16085 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
16086 | complaint (&symfile_complaints, | |
16087 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
16088 | "- DIE at 0x%x [in module %s]"), | |
9c541725 | 16089 | to_underlying (part_die->sect_off), objfile_name (objfile)); |
d8228535 | 16090 | |
72bf9492 DJ |
16091 | /* If we're at the second level, and we're an enumerator, and |
16092 | our parent has no specification (meaning possibly lives in a | |
16093 | namespace elsewhere), then we can add the partial symbol now | |
16094 | instead of queueing it. */ | |
16095 | if (part_die->tag == DW_TAG_enumerator | |
16096 | && parent_die != NULL | |
16097 | && parent_die->die_parent == NULL | |
16098 | && parent_die->tag == DW_TAG_enumeration_type | |
16099 | && parent_die->has_specification == 0) | |
16100 | { | |
16101 | if (part_die->name == NULL) | |
3e43a32a MS |
16102 | complaint (&symfile_complaints, |
16103 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 16104 | else if (building_psymtab) |
04a679b8 | 16105 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 16106 | VAR_DOMAIN, LOC_CONST, |
9c37b5ae | 16107 | cu->language == language_cplus |
bb5ed363 DE |
16108 | ? &objfile->global_psymbols |
16109 | : &objfile->static_psymbols, | |
1762568f | 16110 | 0, cu->language, objfile); |
72bf9492 | 16111 | |
dee91e82 | 16112 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
16113 | continue; |
16114 | } | |
16115 | ||
16116 | /* We'll save this DIE so link it in. */ | |
16117 | part_die->die_parent = parent_die; | |
16118 | part_die->die_sibling = NULL; | |
16119 | part_die->die_child = NULL; | |
16120 | ||
16121 | if (last_die && last_die == parent_die) | |
16122 | last_die->die_child = part_die; | |
16123 | else if (last_die) | |
16124 | last_die->die_sibling = part_die; | |
16125 | ||
16126 | last_die = part_die; | |
16127 | ||
16128 | if (first_die == NULL) | |
16129 | first_die = part_die; | |
16130 | ||
16131 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
16132 | find interesting need to be in the hash table, because we | |
16133 | also have the parent/sibling/child chains; only those that we | |
16134 | might refer to by offset later during partial symbol reading. | |
16135 | ||
16136 | For now this means things that might have be the target of a | |
16137 | DW_AT_specification, DW_AT_abstract_origin, or | |
16138 | DW_AT_extension. DW_AT_extension will refer only to | |
16139 | namespaces; DW_AT_abstract_origin refers to functions (and | |
16140 | many things under the function DIE, but we do not recurse | |
16141 | into function DIEs during partial symbol reading) and | |
16142 | possibly variables as well; DW_AT_specification refers to | |
16143 | declarations. Declarations ought to have the DW_AT_declaration | |
16144 | flag. It happens that GCC forgets to put it in sometimes, but | |
16145 | only for functions, not for types. | |
16146 | ||
16147 | Adding more things than necessary to the hash table is harmless | |
16148 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
16149 | wasted time in find_partial_die, when we reread the compilation |
16150 | unit with load_all_dies set. */ | |
72bf9492 | 16151 | |
5afb4e99 | 16152 | if (load_all |
72929c62 | 16153 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 16154 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
16155 | || abbrev->tag == DW_TAG_variable |
16156 | || abbrev->tag == DW_TAG_namespace | |
16157 | || part_die->is_declaration) | |
16158 | { | |
16159 | void **slot; | |
16160 | ||
16161 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
9c541725 PA |
16162 | to_underlying (part_die->sect_off), |
16163 | INSERT); | |
72bf9492 DJ |
16164 | *slot = part_die; |
16165 | } | |
16166 | ||
8d749320 | 16167 | part_die = XOBNEW (&cu->comp_unit_obstack, struct partial_die_info); |
72bf9492 DJ |
16168 | |
16169 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 16170 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
16171 | languages we have to, so that we can get at method physnames |
16172 | to infer fully qualified class names, for DW_AT_specification, | |
16173 | and for C++ template arguments. For C++, we also look one level | |
16174 | inside functions to find template arguments (if the name of the | |
16175 | function does not already contain the template arguments). | |
bc30ff58 JB |
16176 | |
16177 | For Ada, we need to scan the children of subprograms and lexical | |
16178 | blocks as well because Ada allows the definition of nested | |
16179 | entities that could be interesting for the debugger, such as | |
16180 | nested subprograms for instance. */ | |
72bf9492 | 16181 | if (last_die->has_children |
5afb4e99 DJ |
16182 | && (load_all |
16183 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 16184 | || last_die->tag == DW_TAG_module |
72bf9492 | 16185 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
16186 | || (cu->language == language_cplus |
16187 | && last_die->tag == DW_TAG_subprogram | |
16188 | && (last_die->name == NULL | |
16189 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
16190 | || (cu->language != language_c |
16191 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 16192 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 16193 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
16194 | || last_die->tag == DW_TAG_union_type)) |
16195 | || (cu->language == language_ada | |
16196 | && (last_die->tag == DW_TAG_subprogram | |
16197 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
16198 | { |
16199 | nesting_level++; | |
16200 | parent_die = last_die; | |
16201 | continue; | |
16202 | } | |
16203 | ||
16204 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 16205 | info_ptr = locate_pdi_sibling (reader, last_die, info_ptr); |
72bf9492 DJ |
16206 | |
16207 | /* Back to the top, do it again. */ | |
16208 | } | |
16209 | } | |
16210 | ||
c906108c SS |
16211 | /* Read a minimal amount of information into the minimal die structure. */ |
16212 | ||
d521ce57 | 16213 | static const gdb_byte * |
dee91e82 DE |
16214 | read_partial_die (const struct die_reader_specs *reader, |
16215 | struct partial_die_info *part_die, | |
16216 | struct abbrev_info *abbrev, unsigned int abbrev_len, | |
d521ce57 | 16217 | const gdb_byte *info_ptr) |
c906108c | 16218 | { |
dee91e82 | 16219 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 16220 | struct objfile *objfile = cu->objfile; |
d521ce57 | 16221 | const gdb_byte *buffer = reader->buffer; |
fa238c03 | 16222 | unsigned int i; |
c906108c | 16223 | struct attribute attr; |
c5aa993b | 16224 | int has_low_pc_attr = 0; |
c906108c | 16225 | int has_high_pc_attr = 0; |
91da1414 | 16226 | int high_pc_relative = 0; |
c906108c | 16227 | |
72bf9492 | 16228 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 16229 | |
9c541725 | 16230 | part_die->sect_off = (sect_offset) (info_ptr - buffer); |
72bf9492 DJ |
16231 | |
16232 | info_ptr += abbrev_len; | |
16233 | ||
16234 | if (abbrev == NULL) | |
16235 | return info_ptr; | |
16236 | ||
c906108c SS |
16237 | part_die->tag = abbrev->tag; |
16238 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
16239 | |
16240 | for (i = 0; i < abbrev->num_attrs; ++i) | |
16241 | { | |
dee91e82 | 16242 | info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
c906108c SS |
16243 | |
16244 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 16245 | partial symbol table. */ |
c906108c SS |
16246 | switch (attr.name) |
16247 | { | |
16248 | case DW_AT_name: | |
71c25dea TT |
16249 | switch (part_die->tag) |
16250 | { | |
16251 | case DW_TAG_compile_unit: | |
95554aad | 16252 | case DW_TAG_partial_unit: |
348e048f | 16253 | case DW_TAG_type_unit: |
71c25dea TT |
16254 | /* Compilation units have a DW_AT_name that is a filename, not |
16255 | a source language identifier. */ | |
16256 | case DW_TAG_enumeration_type: | |
16257 | case DW_TAG_enumerator: | |
16258 | /* These tags always have simple identifiers already; no need | |
16259 | to canonicalize them. */ | |
16260 | part_die->name = DW_STRING (&attr); | |
16261 | break; | |
16262 | default: | |
16263 | part_die->name | |
16264 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
34a68019 | 16265 | &objfile->per_bfd->storage_obstack); |
71c25dea TT |
16266 | break; |
16267 | } | |
c906108c | 16268 | break; |
31ef98ae | 16269 | case DW_AT_linkage_name: |
c906108c | 16270 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
16271 | /* Note that both forms of linkage name might appear. We |
16272 | assume they will be the same, and we only store the last | |
16273 | one we see. */ | |
94af9270 KS |
16274 | if (cu->language == language_ada) |
16275 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 16276 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
16277 | break; |
16278 | case DW_AT_low_pc: | |
16279 | has_low_pc_attr = 1; | |
31aa7e4e | 16280 | part_die->lowpc = attr_value_as_address (&attr); |
c906108c SS |
16281 | break; |
16282 | case DW_AT_high_pc: | |
16283 | has_high_pc_attr = 1; | |
31aa7e4e JB |
16284 | part_die->highpc = attr_value_as_address (&attr); |
16285 | if (cu->header.version >= 4 && attr_form_is_constant (&attr)) | |
16286 | high_pc_relative = 1; | |
c906108c SS |
16287 | break; |
16288 | case DW_AT_location: | |
0963b4bd | 16289 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
16290 | if (attr_form_is_block (&attr)) |
16291 | { | |
95554aad | 16292 | part_die->d.locdesc = DW_BLOCK (&attr); |
8e19ed76 | 16293 | } |
3690dd37 | 16294 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 16295 | { |
4d3c2250 | 16296 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
16297 | } |
16298 | else | |
16299 | { | |
4d3c2250 KB |
16300 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
16301 | "partial symbol information"); | |
8e19ed76 | 16302 | } |
c906108c | 16303 | break; |
c906108c SS |
16304 | case DW_AT_external: |
16305 | part_die->is_external = DW_UNSND (&attr); | |
16306 | break; | |
16307 | case DW_AT_declaration: | |
16308 | part_die->is_declaration = DW_UNSND (&attr); | |
16309 | break; | |
16310 | case DW_AT_type: | |
16311 | part_die->has_type = 1; | |
16312 | break; | |
16313 | case DW_AT_abstract_origin: | |
16314 | case DW_AT_specification: | |
72bf9492 DJ |
16315 | case DW_AT_extension: |
16316 | part_die->has_specification = 1; | |
c764a876 | 16317 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
36586728 TT |
16318 | part_die->spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt |
16319 | || cu->per_cu->is_dwz); | |
c906108c SS |
16320 | break; |
16321 | case DW_AT_sibling: | |
16322 | /* Ignore absolute siblings, they might point outside of | |
16323 | the current compile unit. */ | |
16324 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
16325 | complaint (&symfile_complaints, |
16326 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 16327 | else |
b9502d3f | 16328 | { |
9c541725 PA |
16329 | sect_offset off = dwarf2_get_ref_die_offset (&attr); |
16330 | const gdb_byte *sibling_ptr = buffer + to_underlying (off); | |
b9502d3f WN |
16331 | |
16332 | if (sibling_ptr < info_ptr) | |
16333 | complaint (&symfile_complaints, | |
16334 | _("DW_AT_sibling points backwards")); | |
22869d73 KS |
16335 | else if (sibling_ptr > reader->buffer_end) |
16336 | dwarf2_section_buffer_overflow_complaint (reader->die_section); | |
b9502d3f WN |
16337 | else |
16338 | part_die->sibling = sibling_ptr; | |
16339 | } | |
c906108c | 16340 | break; |
fa4028e9 JB |
16341 | case DW_AT_byte_size: |
16342 | part_die->has_byte_size = 1; | |
16343 | break; | |
ff908ebf AW |
16344 | case DW_AT_const_value: |
16345 | part_die->has_const_value = 1; | |
16346 | break; | |
68511cec CES |
16347 | case DW_AT_calling_convention: |
16348 | /* DWARF doesn't provide a way to identify a program's source-level | |
16349 | entry point. DW_AT_calling_convention attributes are only meant | |
16350 | to describe functions' calling conventions. | |
16351 | ||
16352 | However, because it's a necessary piece of information in | |
0c1b455e TT |
16353 | Fortran, and before DWARF 4 DW_CC_program was the only |
16354 | piece of debugging information whose definition refers to | |
16355 | a 'main program' at all, several compilers marked Fortran | |
16356 | main programs with DW_CC_program --- even when those | |
16357 | functions use the standard calling conventions. | |
16358 | ||
16359 | Although DWARF now specifies a way to provide this | |
16360 | information, we support this practice for backward | |
16361 | compatibility. */ | |
68511cec | 16362 | if (DW_UNSND (&attr) == DW_CC_program |
0c1b455e TT |
16363 | && cu->language == language_fortran) |
16364 | part_die->main_subprogram = 1; | |
68511cec | 16365 | break; |
481860b3 GB |
16366 | case DW_AT_inline: |
16367 | if (DW_UNSND (&attr) == DW_INL_inlined | |
16368 | || DW_UNSND (&attr) == DW_INL_declared_inlined) | |
16369 | part_die->may_be_inlined = 1; | |
16370 | break; | |
95554aad TT |
16371 | |
16372 | case DW_AT_import: | |
16373 | if (part_die->tag == DW_TAG_imported_unit) | |
36586728 | 16374 | { |
9c541725 | 16375 | part_die->d.sect_off = dwarf2_get_ref_die_offset (&attr); |
36586728 TT |
16376 | part_die->is_dwz = (attr.form == DW_FORM_GNU_ref_alt |
16377 | || cu->per_cu->is_dwz); | |
16378 | } | |
95554aad TT |
16379 | break; |
16380 | ||
0c1b455e TT |
16381 | case DW_AT_main_subprogram: |
16382 | part_die->main_subprogram = DW_UNSND (&attr); | |
16383 | break; | |
16384 | ||
c906108c SS |
16385 | default: |
16386 | break; | |
16387 | } | |
16388 | } | |
16389 | ||
91da1414 MW |
16390 | if (high_pc_relative) |
16391 | part_die->highpc += part_die->lowpc; | |
16392 | ||
9373cf26 JK |
16393 | if (has_low_pc_attr && has_high_pc_attr) |
16394 | { | |
16395 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
16396 | eliminate duplicate copies of functions and vtables and such. | |
16397 | The linker will arbitrarily choose one and discard the others. | |
16398 | The AT_*_pc values for such functions refer to local labels in | |
16399 | these sections. If the section from that file was discarded, the | |
16400 | labels are not in the output, so the relocs get a value of 0. | |
16401 | If this is a discarded function, mark the pc bounds as invalid, | |
16402 | so that GDB will ignore it. */ | |
16403 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
16404 | { | |
bb5ed363 | 16405 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
16406 | |
16407 | complaint (&symfile_complaints, | |
16408 | _("DW_AT_low_pc %s is zero " | |
16409 | "for DIE at 0x%x [in module %s]"), | |
16410 | paddress (gdbarch, part_die->lowpc), | |
9c541725 | 16411 | to_underlying (part_die->sect_off), objfile_name (objfile)); |
9373cf26 JK |
16412 | } |
16413 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
16414 | else if (part_die->lowpc >= part_die->highpc) | |
16415 | { | |
bb5ed363 | 16416 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
16417 | |
16418 | complaint (&symfile_complaints, | |
16419 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
16420 | "for DIE at 0x%x [in module %s]"), | |
16421 | paddress (gdbarch, part_die->lowpc), | |
16422 | paddress (gdbarch, part_die->highpc), | |
9c541725 PA |
16423 | to_underlying (part_die->sect_off), |
16424 | objfile_name (objfile)); | |
9373cf26 JK |
16425 | } |
16426 | else | |
16427 | part_die->has_pc_info = 1; | |
16428 | } | |
85cbf3d3 | 16429 | |
c906108c SS |
16430 | return info_ptr; |
16431 | } | |
16432 | ||
72bf9492 DJ |
16433 | /* Find a cached partial DIE at OFFSET in CU. */ |
16434 | ||
16435 | static struct partial_die_info * | |
9c541725 | 16436 | find_partial_die_in_comp_unit (sect_offset sect_off, struct dwarf2_cu *cu) |
72bf9492 DJ |
16437 | { |
16438 | struct partial_die_info *lookup_die = NULL; | |
16439 | struct partial_die_info part_die; | |
16440 | ||
9c541725 | 16441 | part_die.sect_off = sect_off; |
9a3c8263 SM |
16442 | lookup_die = ((struct partial_die_info *) |
16443 | htab_find_with_hash (cu->partial_dies, &part_die, | |
9c541725 | 16444 | to_underlying (sect_off))); |
72bf9492 | 16445 | |
72bf9492 DJ |
16446 | return lookup_die; |
16447 | } | |
16448 | ||
348e048f DE |
16449 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
16450 | except in the case of .debug_types DIEs which do not reference | |
16451 | outside their CU (they do however referencing other types via | |
55f1336d | 16452 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
16453 | |
16454 | static struct partial_die_info * | |
9c541725 | 16455 | find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu) |
72bf9492 | 16456 | { |
bb5ed363 | 16457 | struct objfile *objfile = cu->objfile; |
5afb4e99 DJ |
16458 | struct dwarf2_per_cu_data *per_cu = NULL; |
16459 | struct partial_die_info *pd = NULL; | |
72bf9492 | 16460 | |
36586728 | 16461 | if (offset_in_dwz == cu->per_cu->is_dwz |
9c541725 | 16462 | && offset_in_cu_p (&cu->header, sect_off)) |
5afb4e99 | 16463 | { |
9c541725 | 16464 | pd = find_partial_die_in_comp_unit (sect_off, cu); |
5afb4e99 DJ |
16465 | if (pd != NULL) |
16466 | return pd; | |
0d99eb77 DE |
16467 | /* We missed recording what we needed. |
16468 | Load all dies and try again. */ | |
16469 | per_cu = cu->per_cu; | |
5afb4e99 | 16470 | } |
0d99eb77 DE |
16471 | else |
16472 | { | |
16473 | /* TUs don't reference other CUs/TUs (except via type signatures). */ | |
3019eac3 | 16474 | if (cu->per_cu->is_debug_types) |
0d99eb77 | 16475 | { |
9c541725 PA |
16476 | error (_("Dwarf Error: Type Unit at offset 0x%x contains" |
16477 | " external reference to offset 0x%x [in module %s].\n"), | |
16478 | to_underlying (cu->header.sect_off), to_underlying (sect_off), | |
0d99eb77 DE |
16479 | bfd_get_filename (objfile->obfd)); |
16480 | } | |
9c541725 | 16481 | per_cu = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz, |
36586728 | 16482 | objfile); |
72bf9492 | 16483 | |
0d99eb77 DE |
16484 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
16485 | load_partial_comp_unit (per_cu); | |
ae038cb0 | 16486 | |
0d99eb77 | 16487 | per_cu->cu->last_used = 0; |
9c541725 | 16488 | pd = find_partial_die_in_comp_unit (sect_off, per_cu->cu); |
0d99eb77 | 16489 | } |
5afb4e99 | 16490 | |
dee91e82 DE |
16491 | /* If we didn't find it, and not all dies have been loaded, |
16492 | load them all and try again. */ | |
16493 | ||
5afb4e99 DJ |
16494 | if (pd == NULL && per_cu->load_all_dies == 0) |
16495 | { | |
5afb4e99 | 16496 | per_cu->load_all_dies = 1; |
fd820528 DE |
16497 | |
16498 | /* This is nasty. When we reread the DIEs, somewhere up the call chain | |
16499 | THIS_CU->cu may already be in use. So we can't just free it and | |
16500 | replace its DIEs with the ones we read in. Instead, we leave those | |
16501 | DIEs alone (which can still be in use, e.g. in scan_partial_symbols), | |
16502 | and clobber THIS_CU->cu->partial_dies with the hash table for the new | |
16503 | set. */ | |
dee91e82 | 16504 | load_partial_comp_unit (per_cu); |
5afb4e99 | 16505 | |
9c541725 | 16506 | pd = find_partial_die_in_comp_unit (sect_off, per_cu->cu); |
5afb4e99 DJ |
16507 | } |
16508 | ||
16509 | if (pd == NULL) | |
16510 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
16511 | _("could not find partial DIE 0x%x " |
16512 | "in cache [from module %s]\n"), | |
9c541725 | 16513 | to_underlying (sect_off), bfd_get_filename (objfile->obfd)); |
5afb4e99 | 16514 | return pd; |
72bf9492 DJ |
16515 | } |
16516 | ||
abc72ce4 DE |
16517 | /* See if we can figure out if the class lives in a namespace. We do |
16518 | this by looking for a member function; its demangled name will | |
16519 | contain namespace info, if there is any. */ | |
16520 | ||
16521 | static void | |
16522 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
16523 | struct dwarf2_cu *cu) | |
16524 | { | |
16525 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
16526 | what template types look like, because the demangler | |
16527 | frequently doesn't give the same name as the debug info. We | |
16528 | could fix this by only using the demangled name to get the | |
16529 | prefix (but see comment in read_structure_type). */ | |
16530 | ||
16531 | struct partial_die_info *real_pdi; | |
16532 | struct partial_die_info *child_pdi; | |
16533 | ||
16534 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
16535 | we should not do this. We'll prepend the parent's fully qualified | |
16536 | name when we create the partial symbol. */ | |
16537 | ||
16538 | real_pdi = struct_pdi; | |
16539 | while (real_pdi->has_specification) | |
36586728 TT |
16540 | real_pdi = find_partial_die (real_pdi->spec_offset, |
16541 | real_pdi->spec_is_dwz, cu); | |
abc72ce4 DE |
16542 | |
16543 | if (real_pdi->die_parent != NULL) | |
16544 | return; | |
16545 | ||
16546 | for (child_pdi = struct_pdi->die_child; | |
16547 | child_pdi != NULL; | |
16548 | child_pdi = child_pdi->die_sibling) | |
16549 | { | |
16550 | if (child_pdi->tag == DW_TAG_subprogram | |
16551 | && child_pdi->linkage_name != NULL) | |
16552 | { | |
16553 | char *actual_class_name | |
16554 | = language_class_name_from_physname (cu->language_defn, | |
16555 | child_pdi->linkage_name); | |
16556 | if (actual_class_name != NULL) | |
16557 | { | |
16558 | struct_pdi->name | |
224c3ddb SM |
16559 | = ((const char *) |
16560 | obstack_copy0 (&cu->objfile->per_bfd->storage_obstack, | |
16561 | actual_class_name, | |
16562 | strlen (actual_class_name))); | |
abc72ce4 DE |
16563 | xfree (actual_class_name); |
16564 | } | |
16565 | break; | |
16566 | } | |
16567 | } | |
16568 | } | |
16569 | ||
72bf9492 DJ |
16570 | /* Adjust PART_DIE before generating a symbol for it. This function |
16571 | may set the is_external flag or change the DIE's name. */ | |
16572 | ||
16573 | static void | |
16574 | fixup_partial_die (struct partial_die_info *part_die, | |
16575 | struct dwarf2_cu *cu) | |
16576 | { | |
abc72ce4 DE |
16577 | /* Once we've fixed up a die, there's no point in doing so again. |
16578 | This also avoids a memory leak if we were to call | |
16579 | guess_partial_die_structure_name multiple times. */ | |
16580 | if (part_die->fixup_called) | |
16581 | return; | |
16582 | ||
72bf9492 DJ |
16583 | /* If we found a reference attribute and the DIE has no name, try |
16584 | to find a name in the referred to DIE. */ | |
16585 | ||
16586 | if (part_die->name == NULL && part_die->has_specification) | |
16587 | { | |
16588 | struct partial_die_info *spec_die; | |
72bf9492 | 16589 | |
36586728 TT |
16590 | spec_die = find_partial_die (part_die->spec_offset, |
16591 | part_die->spec_is_dwz, cu); | |
72bf9492 | 16592 | |
10b3939b | 16593 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
16594 | |
16595 | if (spec_die->name) | |
16596 | { | |
16597 | part_die->name = spec_die->name; | |
16598 | ||
16599 | /* Copy DW_AT_external attribute if it is set. */ | |
16600 | if (spec_die->is_external) | |
16601 | part_die->is_external = spec_die->is_external; | |
16602 | } | |
16603 | } | |
16604 | ||
16605 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
16606 | |
16607 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 16608 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 16609 | |
abc72ce4 DE |
16610 | /* If there is no parent die to provide a namespace, and there are |
16611 | children, see if we can determine the namespace from their linkage | |
122d1940 | 16612 | name. */ |
abc72ce4 | 16613 | if (cu->language == language_cplus |
8b70b953 | 16614 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
16615 | && part_die->die_parent == NULL |
16616 | && part_die->has_children | |
16617 | && (part_die->tag == DW_TAG_class_type | |
16618 | || part_die->tag == DW_TAG_structure_type | |
16619 | || part_die->tag == DW_TAG_union_type)) | |
16620 | guess_partial_die_structure_name (part_die, cu); | |
16621 | ||
53832f31 TT |
16622 | /* GCC might emit a nameless struct or union that has a linkage |
16623 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
16624 | if (part_die->name == NULL | |
96408a79 SA |
16625 | && (part_die->tag == DW_TAG_class_type |
16626 | || part_die->tag == DW_TAG_interface_type | |
16627 | || part_die->tag == DW_TAG_structure_type | |
16628 | || part_die->tag == DW_TAG_union_type) | |
53832f31 TT |
16629 | && part_die->linkage_name != NULL) |
16630 | { | |
16631 | char *demangled; | |
16632 | ||
8de20a37 | 16633 | demangled = gdb_demangle (part_die->linkage_name, DMGL_TYPES); |
53832f31 TT |
16634 | if (demangled) |
16635 | { | |
96408a79 SA |
16636 | const char *base; |
16637 | ||
16638 | /* Strip any leading namespaces/classes, keep only the base name. | |
16639 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
16640 | base = strrchr (demangled, ':'); | |
16641 | if (base && base > demangled && base[-1] == ':') | |
16642 | base++; | |
16643 | else | |
16644 | base = demangled; | |
16645 | ||
34a68019 | 16646 | part_die->name |
224c3ddb SM |
16647 | = ((const char *) |
16648 | obstack_copy0 (&cu->objfile->per_bfd->storage_obstack, | |
16649 | base, strlen (base))); | |
53832f31 TT |
16650 | xfree (demangled); |
16651 | } | |
16652 | } | |
16653 | ||
abc72ce4 | 16654 | part_die->fixup_called = 1; |
72bf9492 DJ |
16655 | } |
16656 | ||
a8329558 | 16657 | /* Read an attribute value described by an attribute form. */ |
c906108c | 16658 | |
d521ce57 | 16659 | static const gdb_byte * |
dee91e82 DE |
16660 | read_attribute_value (const struct die_reader_specs *reader, |
16661 | struct attribute *attr, unsigned form, | |
43988095 | 16662 | LONGEST implicit_const, const gdb_byte *info_ptr) |
c906108c | 16663 | { |
dee91e82 | 16664 | struct dwarf2_cu *cu = reader->cu; |
3e29f34a MR |
16665 | struct objfile *objfile = cu->objfile; |
16666 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
dee91e82 | 16667 | bfd *abfd = reader->abfd; |
e7c27a73 | 16668 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
16669 | unsigned int bytes_read; |
16670 | struct dwarf_block *blk; | |
16671 | ||
aead7601 | 16672 | attr->form = (enum dwarf_form) form; |
a8329558 | 16673 | switch (form) |
c906108c | 16674 | { |
c906108c | 16675 | case DW_FORM_ref_addr: |
ae411497 | 16676 | if (cu->header.version == 2) |
4568ecf9 | 16677 | DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
ae411497 | 16678 | else |
4568ecf9 DE |
16679 | DW_UNSND (attr) = read_offset (abfd, info_ptr, |
16680 | &cu->header, &bytes_read); | |
ae411497 TT |
16681 | info_ptr += bytes_read; |
16682 | break; | |
36586728 TT |
16683 | case DW_FORM_GNU_ref_alt: |
16684 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
16685 | info_ptr += bytes_read; | |
16686 | break; | |
ae411497 | 16687 | case DW_FORM_addr: |
e7c27a73 | 16688 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
3e29f34a | 16689 | DW_ADDR (attr) = gdbarch_adjust_dwarf2_addr (gdbarch, DW_ADDR (attr)); |
107d2387 | 16690 | info_ptr += bytes_read; |
c906108c SS |
16691 | break; |
16692 | case DW_FORM_block2: | |
7b5a2f43 | 16693 | blk = dwarf_alloc_block (cu); |
c906108c SS |
16694 | blk->size = read_2_bytes (abfd, info_ptr); |
16695 | info_ptr += 2; | |
16696 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
16697 | info_ptr += blk->size; | |
16698 | DW_BLOCK (attr) = blk; | |
16699 | break; | |
16700 | case DW_FORM_block4: | |
7b5a2f43 | 16701 | blk = dwarf_alloc_block (cu); |
c906108c SS |
16702 | blk->size = read_4_bytes (abfd, info_ptr); |
16703 | info_ptr += 4; | |
16704 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
16705 | info_ptr += blk->size; | |
16706 | DW_BLOCK (attr) = blk; | |
16707 | break; | |
16708 | case DW_FORM_data2: | |
16709 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
16710 | info_ptr += 2; | |
16711 | break; | |
16712 | case DW_FORM_data4: | |
16713 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
16714 | info_ptr += 4; | |
16715 | break; | |
16716 | case DW_FORM_data8: | |
16717 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
16718 | info_ptr += 8; | |
16719 | break; | |
0224619f JK |
16720 | case DW_FORM_data16: |
16721 | blk = dwarf_alloc_block (cu); | |
16722 | blk->size = 16; | |
16723 | blk->data = read_n_bytes (abfd, info_ptr, 16); | |
16724 | info_ptr += 16; | |
16725 | DW_BLOCK (attr) = blk; | |
16726 | break; | |
2dc7f7b3 TT |
16727 | case DW_FORM_sec_offset: |
16728 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
16729 | info_ptr += bytes_read; | |
16730 | break; | |
c906108c | 16731 | case DW_FORM_string: |
9b1c24c8 | 16732 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 16733 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
16734 | info_ptr += bytes_read; |
16735 | break; | |
4bdf3d34 | 16736 | case DW_FORM_strp: |
36586728 TT |
16737 | if (!cu->per_cu->is_dwz) |
16738 | { | |
16739 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
16740 | &bytes_read); | |
16741 | DW_STRING_IS_CANONICAL (attr) = 0; | |
16742 | info_ptr += bytes_read; | |
16743 | break; | |
16744 | } | |
16745 | /* FALLTHROUGH */ | |
43988095 JK |
16746 | case DW_FORM_line_strp: |
16747 | if (!cu->per_cu->is_dwz) | |
16748 | { | |
16749 | DW_STRING (attr) = read_indirect_line_string (abfd, info_ptr, | |
16750 | cu_header, &bytes_read); | |
16751 | DW_STRING_IS_CANONICAL (attr) = 0; | |
16752 | info_ptr += bytes_read; | |
16753 | break; | |
16754 | } | |
16755 | /* FALLTHROUGH */ | |
36586728 TT |
16756 | case DW_FORM_GNU_strp_alt: |
16757 | { | |
16758 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
16759 | LONGEST str_offset = read_offset (abfd, info_ptr, cu_header, | |
16760 | &bytes_read); | |
16761 | ||
16762 | DW_STRING (attr) = read_indirect_string_from_dwz (dwz, str_offset); | |
16763 | DW_STRING_IS_CANONICAL (attr) = 0; | |
16764 | info_ptr += bytes_read; | |
16765 | } | |
4bdf3d34 | 16766 | break; |
2dc7f7b3 | 16767 | case DW_FORM_exprloc: |
c906108c | 16768 | case DW_FORM_block: |
7b5a2f43 | 16769 | blk = dwarf_alloc_block (cu); |
c906108c SS |
16770 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
16771 | info_ptr += bytes_read; | |
16772 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
16773 | info_ptr += blk->size; | |
16774 | DW_BLOCK (attr) = blk; | |
16775 | break; | |
16776 | case DW_FORM_block1: | |
7b5a2f43 | 16777 | blk = dwarf_alloc_block (cu); |
c906108c SS |
16778 | blk->size = read_1_byte (abfd, info_ptr); |
16779 | info_ptr += 1; | |
16780 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
16781 | info_ptr += blk->size; | |
16782 | DW_BLOCK (attr) = blk; | |
16783 | break; | |
16784 | case DW_FORM_data1: | |
16785 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
16786 | info_ptr += 1; | |
16787 | break; | |
16788 | case DW_FORM_flag: | |
16789 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
16790 | info_ptr += 1; | |
16791 | break; | |
2dc7f7b3 TT |
16792 | case DW_FORM_flag_present: |
16793 | DW_UNSND (attr) = 1; | |
16794 | break; | |
c906108c SS |
16795 | case DW_FORM_sdata: |
16796 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
16797 | info_ptr += bytes_read; | |
16798 | break; | |
16799 | case DW_FORM_udata: | |
16800 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
16801 | info_ptr += bytes_read; | |
16802 | break; | |
16803 | case DW_FORM_ref1: | |
9c541725 | 16804 | DW_UNSND (attr) = (to_underlying (cu->header.sect_off) |
4568ecf9 | 16805 | + read_1_byte (abfd, info_ptr)); |
c906108c SS |
16806 | info_ptr += 1; |
16807 | break; | |
16808 | case DW_FORM_ref2: | |
9c541725 | 16809 | DW_UNSND (attr) = (to_underlying (cu->header.sect_off) |
4568ecf9 | 16810 | + read_2_bytes (abfd, info_ptr)); |
c906108c SS |
16811 | info_ptr += 2; |
16812 | break; | |
16813 | case DW_FORM_ref4: | |
9c541725 | 16814 | DW_UNSND (attr) = (to_underlying (cu->header.sect_off) |
4568ecf9 | 16815 | + read_4_bytes (abfd, info_ptr)); |
c906108c SS |
16816 | info_ptr += 4; |
16817 | break; | |
613e1657 | 16818 | case DW_FORM_ref8: |
9c541725 | 16819 | DW_UNSND (attr) = (to_underlying (cu->header.sect_off) |
4568ecf9 | 16820 | + read_8_bytes (abfd, info_ptr)); |
613e1657 KB |
16821 | info_ptr += 8; |
16822 | break; | |
55f1336d | 16823 | case DW_FORM_ref_sig8: |
ac9ec31b | 16824 | DW_SIGNATURE (attr) = read_8_bytes (abfd, info_ptr); |
348e048f DE |
16825 | info_ptr += 8; |
16826 | break; | |
c906108c | 16827 | case DW_FORM_ref_udata: |
9c541725 | 16828 | DW_UNSND (attr) = (to_underlying (cu->header.sect_off) |
4568ecf9 | 16829 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); |
c906108c SS |
16830 | info_ptr += bytes_read; |
16831 | break; | |
c906108c | 16832 | case DW_FORM_indirect: |
a8329558 KW |
16833 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
16834 | info_ptr += bytes_read; | |
43988095 JK |
16835 | if (form == DW_FORM_implicit_const) |
16836 | { | |
16837 | implicit_const = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
16838 | info_ptr += bytes_read; | |
16839 | } | |
16840 | info_ptr = read_attribute_value (reader, attr, form, implicit_const, | |
16841 | info_ptr); | |
16842 | break; | |
16843 | case DW_FORM_implicit_const: | |
16844 | DW_SND (attr) = implicit_const; | |
a8329558 | 16845 | break; |
3019eac3 DE |
16846 | case DW_FORM_GNU_addr_index: |
16847 | if (reader->dwo_file == NULL) | |
16848 | { | |
16849 | /* For now flag a hard error. | |
16850 | Later we can turn this into a complaint. */ | |
16851 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), | |
16852 | dwarf_form_name (form), | |
16853 | bfd_get_filename (abfd)); | |
16854 | } | |
16855 | DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read); | |
16856 | info_ptr += bytes_read; | |
16857 | break; | |
16858 | case DW_FORM_GNU_str_index: | |
16859 | if (reader->dwo_file == NULL) | |
16860 | { | |
16861 | /* For now flag a hard error. | |
16862 | Later we can turn this into a complaint if warranted. */ | |
16863 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), | |
16864 | dwarf_form_name (form), | |
16865 | bfd_get_filename (abfd)); | |
16866 | } | |
16867 | { | |
16868 | ULONGEST str_index = | |
16869 | read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
16870 | ||
342587c4 | 16871 | DW_STRING (attr) = read_str_index (reader, str_index); |
3019eac3 DE |
16872 | DW_STRING_IS_CANONICAL (attr) = 0; |
16873 | info_ptr += bytes_read; | |
16874 | } | |
16875 | break; | |
c906108c | 16876 | default: |
8a3fe4f8 | 16877 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
16878 | dwarf_form_name (form), |
16879 | bfd_get_filename (abfd)); | |
c906108c | 16880 | } |
28e94949 | 16881 | |
36586728 | 16882 | /* Super hack. */ |
7771576e | 16883 | if (cu->per_cu->is_dwz && attr_form_is_ref (attr)) |
36586728 TT |
16884 | attr->form = DW_FORM_GNU_ref_alt; |
16885 | ||
28e94949 JB |
16886 | /* We have seen instances where the compiler tried to emit a byte |
16887 | size attribute of -1 which ended up being encoded as an unsigned | |
16888 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
16889 | an object of this size seems pretty unlikely so we can relatively | |
16890 | safely treat these cases as if the size attribute was invalid and | |
16891 | treat them as zero by default. */ | |
16892 | if (attr->name == DW_AT_byte_size | |
16893 | && form == DW_FORM_data4 | |
16894 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
16895 | { |
16896 | complaint | |
16897 | (&symfile_complaints, | |
43bbcdc2 PH |
16898 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
16899 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
16900 | DW_UNSND (attr) = 0; |
16901 | } | |
28e94949 | 16902 | |
c906108c SS |
16903 | return info_ptr; |
16904 | } | |
16905 | ||
a8329558 KW |
16906 | /* Read an attribute described by an abbreviated attribute. */ |
16907 | ||
d521ce57 | 16908 | static const gdb_byte * |
dee91e82 DE |
16909 | read_attribute (const struct die_reader_specs *reader, |
16910 | struct attribute *attr, struct attr_abbrev *abbrev, | |
d521ce57 | 16911 | const gdb_byte *info_ptr) |
a8329558 KW |
16912 | { |
16913 | attr->name = abbrev->name; | |
43988095 JK |
16914 | return read_attribute_value (reader, attr, abbrev->form, |
16915 | abbrev->implicit_const, info_ptr); | |
a8329558 KW |
16916 | } |
16917 | ||
0963b4bd | 16918 | /* Read dwarf information from a buffer. */ |
c906108c SS |
16919 | |
16920 | static unsigned int | |
a1855c1d | 16921 | read_1_byte (bfd *abfd, const gdb_byte *buf) |
c906108c | 16922 | { |
fe1b8b76 | 16923 | return bfd_get_8 (abfd, buf); |
c906108c SS |
16924 | } |
16925 | ||
16926 | static int | |
a1855c1d | 16927 | read_1_signed_byte (bfd *abfd, const gdb_byte *buf) |
c906108c | 16928 | { |
fe1b8b76 | 16929 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
16930 | } |
16931 | ||
16932 | static unsigned int | |
a1855c1d | 16933 | read_2_bytes (bfd *abfd, const gdb_byte *buf) |
c906108c | 16934 | { |
fe1b8b76 | 16935 | return bfd_get_16 (abfd, buf); |
c906108c SS |
16936 | } |
16937 | ||
21ae7a4d | 16938 | static int |
a1855c1d | 16939 | read_2_signed_bytes (bfd *abfd, const gdb_byte *buf) |
21ae7a4d JK |
16940 | { |
16941 | return bfd_get_signed_16 (abfd, buf); | |
16942 | } | |
16943 | ||
c906108c | 16944 | static unsigned int |
a1855c1d | 16945 | read_4_bytes (bfd *abfd, const gdb_byte *buf) |
c906108c | 16946 | { |
fe1b8b76 | 16947 | return bfd_get_32 (abfd, buf); |
c906108c SS |
16948 | } |
16949 | ||
21ae7a4d | 16950 | static int |
a1855c1d | 16951 | read_4_signed_bytes (bfd *abfd, const gdb_byte *buf) |
21ae7a4d JK |
16952 | { |
16953 | return bfd_get_signed_32 (abfd, buf); | |
16954 | } | |
16955 | ||
93311388 | 16956 | static ULONGEST |
a1855c1d | 16957 | read_8_bytes (bfd *abfd, const gdb_byte *buf) |
c906108c | 16958 | { |
fe1b8b76 | 16959 | return bfd_get_64 (abfd, buf); |
c906108c SS |
16960 | } |
16961 | ||
16962 | static CORE_ADDR | |
d521ce57 | 16963 | read_address (bfd *abfd, const gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 16964 | unsigned int *bytes_read) |
c906108c | 16965 | { |
e7c27a73 | 16966 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
16967 | CORE_ADDR retval = 0; |
16968 | ||
107d2387 | 16969 | if (cu_header->signed_addr_p) |
c906108c | 16970 | { |
107d2387 AC |
16971 | switch (cu_header->addr_size) |
16972 | { | |
16973 | case 2: | |
fe1b8b76 | 16974 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
16975 | break; |
16976 | case 4: | |
fe1b8b76 | 16977 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
16978 | break; |
16979 | case 8: | |
fe1b8b76 | 16980 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
16981 | break; |
16982 | default: | |
8e65ff28 | 16983 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 16984 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 16985 | bfd_get_filename (abfd)); |
107d2387 AC |
16986 | } |
16987 | } | |
16988 | else | |
16989 | { | |
16990 | switch (cu_header->addr_size) | |
16991 | { | |
16992 | case 2: | |
fe1b8b76 | 16993 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
16994 | break; |
16995 | case 4: | |
fe1b8b76 | 16996 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
16997 | break; |
16998 | case 8: | |
fe1b8b76 | 16999 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
17000 | break; |
17001 | default: | |
8e65ff28 | 17002 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
17003 | _("read_address: bad switch, " |
17004 | "unsigned [in module %s]"), | |
659b0389 | 17005 | bfd_get_filename (abfd)); |
107d2387 | 17006 | } |
c906108c | 17007 | } |
64367e0a | 17008 | |
107d2387 AC |
17009 | *bytes_read = cu_header->addr_size; |
17010 | return retval; | |
c906108c SS |
17011 | } |
17012 | ||
f7ef9339 | 17013 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
17014 | specification allows the initial length to take up either 4 bytes |
17015 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
17016 | bytes describe the length and all offsets will be 8 bytes in length | |
17017 | instead of 4. | |
17018 | ||
f7ef9339 KB |
17019 | An older, non-standard 64-bit format is also handled by this |
17020 | function. The older format in question stores the initial length | |
17021 | as an 8-byte quantity without an escape value. Lengths greater | |
17022 | than 2^32 aren't very common which means that the initial 4 bytes | |
17023 | is almost always zero. Since a length value of zero doesn't make | |
17024 | sense for the 32-bit format, this initial zero can be considered to | |
17025 | be an escape value which indicates the presence of the older 64-bit | |
17026 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
17027 | greater than 4GB. If it becomes necessary to handle lengths |
17028 | somewhat larger than 4GB, we could allow other small values (such | |
17029 | as the non-sensical values of 1, 2, and 3) to also be used as | |
17030 | escape values indicating the presence of the old format. | |
f7ef9339 | 17031 | |
917c78fc MK |
17032 | The value returned via bytes_read should be used to increment the |
17033 | relevant pointer after calling read_initial_length(). | |
c764a876 | 17034 | |
613e1657 KB |
17035 | [ Note: read_initial_length() and read_offset() are based on the |
17036 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 17037 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
17038 | from: |
17039 | ||
f7ef9339 | 17040 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 17041 | |
613e1657 KB |
17042 | This document is only a draft and is subject to change. (So beware.) |
17043 | ||
f7ef9339 | 17044 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
17045 | determined empirically by examining 64-bit ELF files produced by |
17046 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
17047 | |
17048 | - Kevin, July 16, 2002 | |
613e1657 KB |
17049 | ] */ |
17050 | ||
17051 | static LONGEST | |
d521ce57 | 17052 | read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 17053 | { |
fe1b8b76 | 17054 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 17055 | |
dd373385 | 17056 | if (length == 0xffffffff) |
613e1657 | 17057 | { |
fe1b8b76 | 17058 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 17059 | *bytes_read = 12; |
613e1657 | 17060 | } |
dd373385 | 17061 | else if (length == 0) |
f7ef9339 | 17062 | { |
dd373385 | 17063 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 17064 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 17065 | *bytes_read = 8; |
f7ef9339 | 17066 | } |
613e1657 KB |
17067 | else |
17068 | { | |
17069 | *bytes_read = 4; | |
613e1657 KB |
17070 | } |
17071 | ||
c764a876 DE |
17072 | return length; |
17073 | } | |
dd373385 | 17074 | |
c764a876 DE |
17075 | /* Cover function for read_initial_length. |
17076 | Returns the length of the object at BUF, and stores the size of the | |
17077 | initial length in *BYTES_READ and stores the size that offsets will be in | |
17078 | *OFFSET_SIZE. | |
17079 | If the initial length size is not equivalent to that specified in | |
17080 | CU_HEADER then issue a complaint. | |
17081 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 17082 | |
c764a876 | 17083 | static LONGEST |
d521ce57 | 17084 | read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf, |
c764a876 DE |
17085 | const struct comp_unit_head *cu_header, |
17086 | unsigned int *bytes_read, | |
17087 | unsigned int *offset_size) | |
17088 | { | |
17089 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
17090 | ||
17091 | gdb_assert (cu_header->initial_length_size == 4 | |
17092 | || cu_header->initial_length_size == 8 | |
17093 | || cu_header->initial_length_size == 12); | |
17094 | ||
17095 | if (cu_header->initial_length_size != *bytes_read) | |
17096 | complaint (&symfile_complaints, | |
17097 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 17098 | |
c764a876 | 17099 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 17100 | return length; |
613e1657 KB |
17101 | } |
17102 | ||
17103 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 17104 | given by cu_header->offset_size. */ |
613e1657 KB |
17105 | |
17106 | static LONGEST | |
d521ce57 TT |
17107 | read_offset (bfd *abfd, const gdb_byte *buf, |
17108 | const struct comp_unit_head *cu_header, | |
891d2f0b | 17109 | unsigned int *bytes_read) |
c764a876 DE |
17110 | { |
17111 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 17112 | |
c764a876 DE |
17113 | *bytes_read = cu_header->offset_size; |
17114 | return offset; | |
17115 | } | |
17116 | ||
17117 | /* Read an offset from the data stream. */ | |
17118 | ||
17119 | static LONGEST | |
d521ce57 | 17120 | read_offset_1 (bfd *abfd, const gdb_byte *buf, unsigned int offset_size) |
613e1657 KB |
17121 | { |
17122 | LONGEST retval = 0; | |
17123 | ||
c764a876 | 17124 | switch (offset_size) |
613e1657 KB |
17125 | { |
17126 | case 4: | |
fe1b8b76 | 17127 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
17128 | break; |
17129 | case 8: | |
fe1b8b76 | 17130 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
17131 | break; |
17132 | default: | |
8e65ff28 | 17133 | internal_error (__FILE__, __LINE__, |
c764a876 | 17134 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 17135 | bfd_get_filename (abfd)); |
613e1657 KB |
17136 | } |
17137 | ||
917c78fc | 17138 | return retval; |
613e1657 KB |
17139 | } |
17140 | ||
d521ce57 TT |
17141 | static const gdb_byte * |
17142 | read_n_bytes (bfd *abfd, const gdb_byte *buf, unsigned int size) | |
c906108c SS |
17143 | { |
17144 | /* If the size of a host char is 8 bits, we can return a pointer | |
17145 | to the buffer, otherwise we have to copy the data to a buffer | |
17146 | allocated on the temporary obstack. */ | |
4bdf3d34 | 17147 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 17148 | return buf; |
c906108c SS |
17149 | } |
17150 | ||
d521ce57 TT |
17151 | static const char * |
17152 | read_direct_string (bfd *abfd, const gdb_byte *buf, | |
17153 | unsigned int *bytes_read_ptr) | |
c906108c SS |
17154 | { |
17155 | /* If the size of a host char is 8 bits, we can return a pointer | |
17156 | to the string, otherwise we have to copy the string to a buffer | |
17157 | allocated on the temporary obstack. */ | |
4bdf3d34 | 17158 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
17159 | if (*buf == '\0') |
17160 | { | |
17161 | *bytes_read_ptr = 1; | |
17162 | return NULL; | |
17163 | } | |
d521ce57 TT |
17164 | *bytes_read_ptr = strlen ((const char *) buf) + 1; |
17165 | return (const char *) buf; | |
4bdf3d34 JJ |
17166 | } |
17167 | ||
43988095 JK |
17168 | /* Return pointer to string at section SECT offset STR_OFFSET with error |
17169 | reporting strings FORM_NAME and SECT_NAME. */ | |
17170 | ||
d521ce57 | 17171 | static const char * |
43988095 JK |
17172 | read_indirect_string_at_offset_from (bfd *abfd, LONGEST str_offset, |
17173 | struct dwarf2_section_info *sect, | |
17174 | const char *form_name, | |
17175 | const char *sect_name) | |
17176 | { | |
17177 | dwarf2_read_section (dwarf2_per_objfile->objfile, sect); | |
17178 | if (sect->buffer == NULL) | |
17179 | error (_("%s used without %s section [in module %s]"), | |
17180 | form_name, sect_name, bfd_get_filename (abfd)); | |
17181 | if (str_offset >= sect->size) | |
17182 | error (_("%s pointing outside of %s section [in module %s]"), | |
17183 | form_name, sect_name, bfd_get_filename (abfd)); | |
4bdf3d34 | 17184 | gdb_assert (HOST_CHAR_BIT == 8); |
43988095 | 17185 | if (sect->buffer[str_offset] == '\0') |
4bdf3d34 | 17186 | return NULL; |
43988095 JK |
17187 | return (const char *) (sect->buffer + str_offset); |
17188 | } | |
17189 | ||
17190 | /* Return pointer to string at .debug_str offset STR_OFFSET. */ | |
17191 | ||
17192 | static const char * | |
17193 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) | |
17194 | { | |
17195 | return read_indirect_string_at_offset_from (abfd, str_offset, | |
17196 | &dwarf2_per_objfile->str, | |
17197 | "DW_FORM_strp", ".debug_str"); | |
17198 | } | |
17199 | ||
17200 | /* Return pointer to string at .debug_line_str offset STR_OFFSET. */ | |
17201 | ||
17202 | static const char * | |
17203 | read_indirect_line_string_at_offset (bfd *abfd, LONGEST str_offset) | |
17204 | { | |
17205 | return read_indirect_string_at_offset_from (abfd, str_offset, | |
17206 | &dwarf2_per_objfile->line_str, | |
17207 | "DW_FORM_line_strp", | |
17208 | ".debug_line_str"); | |
c906108c SS |
17209 | } |
17210 | ||
36586728 TT |
17211 | /* Read a string at offset STR_OFFSET in the .debug_str section from |
17212 | the .dwz file DWZ. Throw an error if the offset is too large. If | |
17213 | the string consists of a single NUL byte, return NULL; otherwise | |
17214 | return a pointer to the string. */ | |
17215 | ||
d521ce57 | 17216 | static const char * |
36586728 TT |
17217 | read_indirect_string_from_dwz (struct dwz_file *dwz, LONGEST str_offset) |
17218 | { | |
17219 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwz->str); | |
17220 | ||
17221 | if (dwz->str.buffer == NULL) | |
17222 | error (_("DW_FORM_GNU_strp_alt used without .debug_str " | |
17223 | "section [in module %s]"), | |
17224 | bfd_get_filename (dwz->dwz_bfd)); | |
17225 | if (str_offset >= dwz->str.size) | |
17226 | error (_("DW_FORM_GNU_strp_alt pointing outside of " | |
17227 | ".debug_str section [in module %s]"), | |
17228 | bfd_get_filename (dwz->dwz_bfd)); | |
17229 | gdb_assert (HOST_CHAR_BIT == 8); | |
17230 | if (dwz->str.buffer[str_offset] == '\0') | |
17231 | return NULL; | |
d521ce57 | 17232 | return (const char *) (dwz->str.buffer + str_offset); |
36586728 TT |
17233 | } |
17234 | ||
43988095 JK |
17235 | /* Return pointer to string at .debug_str offset as read from BUF. |
17236 | BUF is assumed to be in a compilation unit described by CU_HEADER. | |
17237 | Return *BYTES_READ_PTR count of bytes read from BUF. */ | |
17238 | ||
d521ce57 TT |
17239 | static const char * |
17240 | read_indirect_string (bfd *abfd, const gdb_byte *buf, | |
cf2c3c16 TT |
17241 | const struct comp_unit_head *cu_header, |
17242 | unsigned int *bytes_read_ptr) | |
17243 | { | |
17244 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
17245 | ||
17246 | return read_indirect_string_at_offset (abfd, str_offset); | |
17247 | } | |
17248 | ||
43988095 JK |
17249 | /* Return pointer to string at .debug_line_str offset as read from BUF. |
17250 | BUF is assumed to be in a compilation unit described by CU_HEADER. | |
17251 | Return *BYTES_READ_PTR count of bytes read from BUF. */ | |
17252 | ||
17253 | static const char * | |
17254 | read_indirect_line_string (bfd *abfd, const gdb_byte *buf, | |
17255 | const struct comp_unit_head *cu_header, | |
17256 | unsigned int *bytes_read_ptr) | |
17257 | { | |
17258 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
17259 | ||
17260 | return read_indirect_line_string_at_offset (abfd, str_offset); | |
17261 | } | |
17262 | ||
17263 | ULONGEST | |
d521ce57 | 17264 | read_unsigned_leb128 (bfd *abfd, const gdb_byte *buf, |
43988095 | 17265 | unsigned int *bytes_read_ptr) |
c906108c | 17266 | { |
12df843f | 17267 | ULONGEST result; |
ce5d95e1 | 17268 | unsigned int num_read; |
870f88f7 | 17269 | int shift; |
c906108c SS |
17270 | unsigned char byte; |
17271 | ||
17272 | result = 0; | |
17273 | shift = 0; | |
17274 | num_read = 0; | |
c906108c SS |
17275 | while (1) |
17276 | { | |
fe1b8b76 | 17277 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
17278 | buf++; |
17279 | num_read++; | |
12df843f | 17280 | result |= ((ULONGEST) (byte & 127) << shift); |
c906108c SS |
17281 | if ((byte & 128) == 0) |
17282 | { | |
17283 | break; | |
17284 | } | |
17285 | shift += 7; | |
17286 | } | |
17287 | *bytes_read_ptr = num_read; | |
17288 | return result; | |
17289 | } | |
17290 | ||
12df843f | 17291 | static LONGEST |
d521ce57 TT |
17292 | read_signed_leb128 (bfd *abfd, const gdb_byte *buf, |
17293 | unsigned int *bytes_read_ptr) | |
c906108c | 17294 | { |
12df843f | 17295 | LONGEST result; |
870f88f7 | 17296 | int shift, num_read; |
c906108c SS |
17297 | unsigned char byte; |
17298 | ||
17299 | result = 0; | |
17300 | shift = 0; | |
c906108c | 17301 | num_read = 0; |
c906108c SS |
17302 | while (1) |
17303 | { | |
fe1b8b76 | 17304 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
17305 | buf++; |
17306 | num_read++; | |
12df843f | 17307 | result |= ((LONGEST) (byte & 127) << shift); |
c906108c SS |
17308 | shift += 7; |
17309 | if ((byte & 128) == 0) | |
17310 | { | |
17311 | break; | |
17312 | } | |
17313 | } | |
77e0b926 | 17314 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
12df843f | 17315 | result |= -(((LONGEST) 1) << shift); |
c906108c SS |
17316 | *bytes_read_ptr = num_read; |
17317 | return result; | |
17318 | } | |
17319 | ||
3019eac3 DE |
17320 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. |
17321 | ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero. | |
17322 | ADDR_SIZE is the size of addresses from the CU header. */ | |
17323 | ||
17324 | static CORE_ADDR | |
17325 | read_addr_index_1 (unsigned int addr_index, ULONGEST addr_base, int addr_size) | |
17326 | { | |
17327 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
17328 | bfd *abfd = objfile->obfd; | |
17329 | const gdb_byte *info_ptr; | |
17330 | ||
17331 | dwarf2_read_section (objfile, &dwarf2_per_objfile->addr); | |
17332 | if (dwarf2_per_objfile->addr.buffer == NULL) | |
17333 | error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"), | |
4262abfb | 17334 | objfile_name (objfile)); |
3019eac3 DE |
17335 | if (addr_base + addr_index * addr_size >= dwarf2_per_objfile->addr.size) |
17336 | error (_("DW_FORM_addr_index pointing outside of " | |
17337 | ".debug_addr section [in module %s]"), | |
4262abfb | 17338 | objfile_name (objfile)); |
3019eac3 DE |
17339 | info_ptr = (dwarf2_per_objfile->addr.buffer |
17340 | + addr_base + addr_index * addr_size); | |
17341 | if (addr_size == 4) | |
17342 | return bfd_get_32 (abfd, info_ptr); | |
17343 | else | |
17344 | return bfd_get_64 (abfd, info_ptr); | |
17345 | } | |
17346 | ||
17347 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. */ | |
17348 | ||
17349 | static CORE_ADDR | |
17350 | read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index) | |
17351 | { | |
17352 | return read_addr_index_1 (addr_index, cu->addr_base, cu->header.addr_size); | |
17353 | } | |
17354 | ||
17355 | /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */ | |
17356 | ||
17357 | static CORE_ADDR | |
d521ce57 | 17358 | read_addr_index_from_leb128 (struct dwarf2_cu *cu, const gdb_byte *info_ptr, |
3019eac3 DE |
17359 | unsigned int *bytes_read) |
17360 | { | |
17361 | bfd *abfd = cu->objfile->obfd; | |
17362 | unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
17363 | ||
17364 | return read_addr_index (cu, addr_index); | |
17365 | } | |
17366 | ||
17367 | /* Data structure to pass results from dwarf2_read_addr_index_reader | |
17368 | back to dwarf2_read_addr_index. */ | |
17369 | ||
17370 | struct dwarf2_read_addr_index_data | |
17371 | { | |
17372 | ULONGEST addr_base; | |
17373 | int addr_size; | |
17374 | }; | |
17375 | ||
17376 | /* die_reader_func for dwarf2_read_addr_index. */ | |
17377 | ||
17378 | static void | |
17379 | dwarf2_read_addr_index_reader (const struct die_reader_specs *reader, | |
d521ce57 | 17380 | const gdb_byte *info_ptr, |
3019eac3 DE |
17381 | struct die_info *comp_unit_die, |
17382 | int has_children, | |
17383 | void *data) | |
17384 | { | |
17385 | struct dwarf2_cu *cu = reader->cu; | |
17386 | struct dwarf2_read_addr_index_data *aidata = | |
17387 | (struct dwarf2_read_addr_index_data *) data; | |
17388 | ||
17389 | aidata->addr_base = cu->addr_base; | |
17390 | aidata->addr_size = cu->header.addr_size; | |
17391 | } | |
17392 | ||
17393 | /* Given an index in .debug_addr, fetch the value. | |
17394 | NOTE: This can be called during dwarf expression evaluation, | |
17395 | long after the debug information has been read, and thus per_cu->cu | |
17396 | may no longer exist. */ | |
17397 | ||
17398 | CORE_ADDR | |
17399 | dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu, | |
17400 | unsigned int addr_index) | |
17401 | { | |
17402 | struct objfile *objfile = per_cu->objfile; | |
17403 | struct dwarf2_cu *cu = per_cu->cu; | |
17404 | ULONGEST addr_base; | |
17405 | int addr_size; | |
17406 | ||
17407 | /* This is intended to be called from outside this file. */ | |
17408 | dw2_setup (objfile); | |
17409 | ||
17410 | /* We need addr_base and addr_size. | |
17411 | If we don't have PER_CU->cu, we have to get it. | |
17412 | Nasty, but the alternative is storing the needed info in PER_CU, | |
17413 | which at this point doesn't seem justified: it's not clear how frequently | |
17414 | it would get used and it would increase the size of every PER_CU. | |
17415 | Entry points like dwarf2_per_cu_addr_size do a similar thing | |
17416 | so we're not in uncharted territory here. | |
17417 | Alas we need to be a bit more complicated as addr_base is contained | |
17418 | in the DIE. | |
17419 | ||
17420 | We don't need to read the entire CU(/TU). | |
17421 | We just need the header and top level die. | |
a1b64ce1 | 17422 | |
3019eac3 | 17423 | IWBN to use the aging mechanism to let us lazily later discard the CU. |
a1b64ce1 | 17424 | For now we skip this optimization. */ |
3019eac3 DE |
17425 | |
17426 | if (cu != NULL) | |
17427 | { | |
17428 | addr_base = cu->addr_base; | |
17429 | addr_size = cu->header.addr_size; | |
17430 | } | |
17431 | else | |
17432 | { | |
17433 | struct dwarf2_read_addr_index_data aidata; | |
17434 | ||
a1b64ce1 DE |
17435 | /* Note: We can't use init_cutu_and_read_dies_simple here, |
17436 | we need addr_base. */ | |
17437 | init_cutu_and_read_dies (per_cu, NULL, 0, 0, | |
17438 | dwarf2_read_addr_index_reader, &aidata); | |
3019eac3 DE |
17439 | addr_base = aidata.addr_base; |
17440 | addr_size = aidata.addr_size; | |
17441 | } | |
17442 | ||
17443 | return read_addr_index_1 (addr_index, addr_base, addr_size); | |
17444 | } | |
17445 | ||
57d63ce2 DE |
17446 | /* Given a DW_FORM_GNU_str_index, fetch the string. |
17447 | This is only used by the Fission support. */ | |
3019eac3 | 17448 | |
d521ce57 | 17449 | static const char * |
342587c4 | 17450 | read_str_index (const struct die_reader_specs *reader, ULONGEST str_index) |
3019eac3 DE |
17451 | { |
17452 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
c5164cbc | 17453 | const char *objf_name = objfile_name (objfile); |
3019eac3 | 17454 | bfd *abfd = objfile->obfd; |
342587c4 | 17455 | struct dwarf2_cu *cu = reader->cu; |
73869dc2 DE |
17456 | struct dwarf2_section_info *str_section = &reader->dwo_file->sections.str; |
17457 | struct dwarf2_section_info *str_offsets_section = | |
17458 | &reader->dwo_file->sections.str_offsets; | |
d521ce57 | 17459 | const gdb_byte *info_ptr; |
3019eac3 | 17460 | ULONGEST str_offset; |
57d63ce2 | 17461 | static const char form_name[] = "DW_FORM_GNU_str_index"; |
3019eac3 | 17462 | |
73869dc2 DE |
17463 | dwarf2_read_section (objfile, str_section); |
17464 | dwarf2_read_section (objfile, str_offsets_section); | |
17465 | if (str_section->buffer == NULL) | |
57d63ce2 | 17466 | error (_("%s used without .debug_str.dwo section" |
9c541725 PA |
17467 | " in CU at offset 0x%x [in module %s]"), |
17468 | form_name, to_underlying (cu->header.sect_off), objf_name); | |
73869dc2 | 17469 | if (str_offsets_section->buffer == NULL) |
57d63ce2 | 17470 | error (_("%s used without .debug_str_offsets.dwo section" |
9c541725 PA |
17471 | " in CU at offset 0x%x [in module %s]"), |
17472 | form_name, to_underlying (cu->header.sect_off), objf_name); | |
73869dc2 | 17473 | if (str_index * cu->header.offset_size >= str_offsets_section->size) |
57d63ce2 | 17474 | error (_("%s pointing outside of .debug_str_offsets.dwo" |
9c541725 PA |
17475 | " section in CU at offset 0x%x [in module %s]"), |
17476 | form_name, to_underlying (cu->header.sect_off), objf_name); | |
73869dc2 | 17477 | info_ptr = (str_offsets_section->buffer |
3019eac3 DE |
17478 | + str_index * cu->header.offset_size); |
17479 | if (cu->header.offset_size == 4) | |
17480 | str_offset = bfd_get_32 (abfd, info_ptr); | |
17481 | else | |
17482 | str_offset = bfd_get_64 (abfd, info_ptr); | |
73869dc2 | 17483 | if (str_offset >= str_section->size) |
57d63ce2 | 17484 | error (_("Offset from %s pointing outside of" |
9c541725 PA |
17485 | " .debug_str.dwo section in CU at offset 0x%x [in module %s]"), |
17486 | form_name, to_underlying (cu->header.sect_off), objf_name); | |
73869dc2 | 17487 | return (const char *) (str_section->buffer + str_offset); |
3019eac3 DE |
17488 | } |
17489 | ||
3019eac3 DE |
17490 | /* Return the length of an LEB128 number in BUF. */ |
17491 | ||
17492 | static int | |
17493 | leb128_size (const gdb_byte *buf) | |
17494 | { | |
17495 | const gdb_byte *begin = buf; | |
17496 | gdb_byte byte; | |
17497 | ||
17498 | while (1) | |
17499 | { | |
17500 | byte = *buf++; | |
17501 | if ((byte & 128) == 0) | |
17502 | return buf - begin; | |
17503 | } | |
17504 | } | |
17505 | ||
c906108c | 17506 | static void |
e142c38c | 17507 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
17508 | { |
17509 | switch (lang) | |
17510 | { | |
17511 | case DW_LANG_C89: | |
76bee0cc | 17512 | case DW_LANG_C99: |
0cfd832f | 17513 | case DW_LANG_C11: |
c906108c | 17514 | case DW_LANG_C: |
d1be3247 | 17515 | case DW_LANG_UPC: |
e142c38c | 17516 | cu->language = language_c; |
c906108c | 17517 | break; |
9c37b5ae | 17518 | case DW_LANG_Java: |
c906108c | 17519 | case DW_LANG_C_plus_plus: |
0cfd832f MW |
17520 | case DW_LANG_C_plus_plus_11: |
17521 | case DW_LANG_C_plus_plus_14: | |
e142c38c | 17522 | cu->language = language_cplus; |
c906108c | 17523 | break; |
6aecb9c2 JB |
17524 | case DW_LANG_D: |
17525 | cu->language = language_d; | |
17526 | break; | |
c906108c SS |
17527 | case DW_LANG_Fortran77: |
17528 | case DW_LANG_Fortran90: | |
b21b22e0 | 17529 | case DW_LANG_Fortran95: |
f7de9aab MW |
17530 | case DW_LANG_Fortran03: |
17531 | case DW_LANG_Fortran08: | |
e142c38c | 17532 | cu->language = language_fortran; |
c906108c | 17533 | break; |
a766d390 DE |
17534 | case DW_LANG_Go: |
17535 | cu->language = language_go; | |
17536 | break; | |
c906108c | 17537 | case DW_LANG_Mips_Assembler: |
e142c38c | 17538 | cu->language = language_asm; |
c906108c SS |
17539 | break; |
17540 | case DW_LANG_Ada83: | |
8aaf0b47 | 17541 | case DW_LANG_Ada95: |
bc5f45f8 JB |
17542 | cu->language = language_ada; |
17543 | break; | |
72019c9c GM |
17544 | case DW_LANG_Modula2: |
17545 | cu->language = language_m2; | |
17546 | break; | |
fe8e67fd PM |
17547 | case DW_LANG_Pascal83: |
17548 | cu->language = language_pascal; | |
17549 | break; | |
22566fbd DJ |
17550 | case DW_LANG_ObjC: |
17551 | cu->language = language_objc; | |
17552 | break; | |
c44af4eb TT |
17553 | case DW_LANG_Rust: |
17554 | case DW_LANG_Rust_old: | |
17555 | cu->language = language_rust; | |
17556 | break; | |
c906108c SS |
17557 | case DW_LANG_Cobol74: |
17558 | case DW_LANG_Cobol85: | |
c906108c | 17559 | default: |
e142c38c | 17560 | cu->language = language_minimal; |
c906108c SS |
17561 | break; |
17562 | } | |
e142c38c | 17563 | cu->language_defn = language_def (cu->language); |
c906108c SS |
17564 | } |
17565 | ||
17566 | /* Return the named attribute or NULL if not there. */ | |
17567 | ||
17568 | static struct attribute * | |
e142c38c | 17569 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c | 17570 | { |
a48e046c | 17571 | for (;;) |
c906108c | 17572 | { |
a48e046c TT |
17573 | unsigned int i; |
17574 | struct attribute *spec = NULL; | |
17575 | ||
17576 | for (i = 0; i < die->num_attrs; ++i) | |
17577 | { | |
17578 | if (die->attrs[i].name == name) | |
17579 | return &die->attrs[i]; | |
17580 | if (die->attrs[i].name == DW_AT_specification | |
17581 | || die->attrs[i].name == DW_AT_abstract_origin) | |
17582 | spec = &die->attrs[i]; | |
17583 | } | |
17584 | ||
17585 | if (!spec) | |
17586 | break; | |
c906108c | 17587 | |
f2f0e013 | 17588 | die = follow_die_ref (die, spec, &cu); |
f2f0e013 | 17589 | } |
c5aa993b | 17590 | |
c906108c SS |
17591 | return NULL; |
17592 | } | |
17593 | ||
348e048f DE |
17594 | /* Return the named attribute or NULL if not there, |
17595 | but do not follow DW_AT_specification, etc. | |
17596 | This is for use in contexts where we're reading .debug_types dies. | |
17597 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
17598 | back up the chain, and we want to go down. */ | |
17599 | ||
17600 | static struct attribute * | |
45e58e77 | 17601 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name) |
348e048f DE |
17602 | { |
17603 | unsigned int i; | |
17604 | ||
17605 | for (i = 0; i < die->num_attrs; ++i) | |
17606 | if (die->attrs[i].name == name) | |
17607 | return &die->attrs[i]; | |
17608 | ||
17609 | return NULL; | |
17610 | } | |
17611 | ||
7d45c7c3 KB |
17612 | /* Return the string associated with a string-typed attribute, or NULL if it |
17613 | is either not found or is of an incorrect type. */ | |
17614 | ||
17615 | static const char * | |
17616 | dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) | |
17617 | { | |
17618 | struct attribute *attr; | |
17619 | const char *str = NULL; | |
17620 | ||
17621 | attr = dwarf2_attr (die, name, cu); | |
17622 | ||
17623 | if (attr != NULL) | |
17624 | { | |
43988095 | 17625 | if (attr->form == DW_FORM_strp || attr->form == DW_FORM_line_strp |
16eb6b2d LS |
17626 | || attr->form == DW_FORM_string || DW_FORM_GNU_str_index |
17627 | || attr->form == DW_FORM_GNU_strp_alt) | |
7d45c7c3 KB |
17628 | str = DW_STRING (attr); |
17629 | else | |
17630 | complaint (&symfile_complaints, | |
17631 | _("string type expected for attribute %s for " | |
17632 | "DIE at 0x%x in module %s"), | |
9c541725 | 17633 | dwarf_attr_name (name), to_underlying (die->sect_off), |
7d45c7c3 KB |
17634 | objfile_name (cu->objfile)); |
17635 | } | |
17636 | ||
17637 | return str; | |
17638 | } | |
17639 | ||
05cf31d1 JB |
17640 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
17641 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 17642 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
17643 | |
17644 | static int | |
17645 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
17646 | { | |
17647 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
17648 | ||
17649 | return (attr && DW_UNSND (attr)); | |
17650 | } | |
17651 | ||
3ca72b44 | 17652 | static int |
e142c38c | 17653 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 17654 | { |
05cf31d1 JB |
17655 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
17656 | which value is non-zero. However, we have to be careful with | |
17657 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
17658 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
17659 | end up accidently finding a declaration attribute that belongs | |
17660 | to a different DIE referenced by the specification attribute, | |
17661 | even though the given DIE does not have a declaration attribute. */ | |
17662 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
17663 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
17664 | } |
17665 | ||
63d06c5c | 17666 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 17667 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
17668 | containing the return value on output. If there is no |
17669 | specification, but there is an abstract origin, that is | |
17670 | returned. */ | |
63d06c5c DC |
17671 | |
17672 | static struct die_info * | |
f2f0e013 | 17673 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 17674 | { |
f2f0e013 DJ |
17675 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
17676 | *spec_cu); | |
63d06c5c | 17677 | |
edb3359d DJ |
17678 | if (spec_attr == NULL) |
17679 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
17680 | ||
63d06c5c DC |
17681 | if (spec_attr == NULL) |
17682 | return NULL; | |
17683 | else | |
f2f0e013 | 17684 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 17685 | } |
c906108c | 17686 | |
527f3840 JK |
17687 | /* Stub for free_line_header to match void * callback types. */ |
17688 | ||
17689 | static void | |
17690 | free_line_header_voidp (void *arg) | |
17691 | { | |
9a3c8263 | 17692 | struct line_header *lh = (struct line_header *) arg; |
527f3840 | 17693 | |
fff8551c | 17694 | delete lh; |
527f3840 JK |
17695 | } |
17696 | ||
fff8551c PA |
17697 | void |
17698 | line_header::add_include_dir (const char *include_dir) | |
c906108c | 17699 | { |
27e0867f | 17700 | if (dwarf_line_debug >= 2) |
fff8551c PA |
17701 | fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n", |
17702 | include_dirs.size () + 1, include_dir); | |
27e0867f | 17703 | |
fff8551c | 17704 | include_dirs.push_back (include_dir); |
debd256d | 17705 | } |
6e70227d | 17706 | |
fff8551c PA |
17707 | void |
17708 | line_header::add_file_name (const char *name, | |
ecfb656c | 17709 | dir_index d_index, |
fff8551c PA |
17710 | unsigned int mod_time, |
17711 | unsigned int length) | |
debd256d | 17712 | { |
27e0867f DE |
17713 | if (dwarf_line_debug >= 2) |
17714 | fprintf_unfiltered (gdb_stdlog, "Adding file %u: %s\n", | |
fff8551c | 17715 | (unsigned) file_names.size () + 1, name); |
27e0867f | 17716 | |
ecfb656c | 17717 | file_names.emplace_back (name, d_index, mod_time, length); |
debd256d | 17718 | } |
6e70227d | 17719 | |
83769d0b | 17720 | /* A convenience function to find the proper .debug_line section for a CU. */ |
36586728 TT |
17721 | |
17722 | static struct dwarf2_section_info * | |
17723 | get_debug_line_section (struct dwarf2_cu *cu) | |
17724 | { | |
17725 | struct dwarf2_section_info *section; | |
17726 | ||
17727 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the | |
17728 | DWO file. */ | |
17729 | if (cu->dwo_unit && cu->per_cu->is_debug_types) | |
17730 | section = &cu->dwo_unit->dwo_file->sections.line; | |
17731 | else if (cu->per_cu->is_dwz) | |
17732 | { | |
17733 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
17734 | ||
17735 | section = &dwz->line; | |
17736 | } | |
17737 | else | |
17738 | section = &dwarf2_per_objfile->line; | |
17739 | ||
17740 | return section; | |
17741 | } | |
17742 | ||
43988095 JK |
17743 | /* Read directory or file name entry format, starting with byte of |
17744 | format count entries, ULEB128 pairs of entry formats, ULEB128 of | |
17745 | entries count and the entries themselves in the described entry | |
17746 | format. */ | |
17747 | ||
17748 | static void | |
17749 | read_formatted_entries (bfd *abfd, const gdb_byte **bufp, | |
17750 | struct line_header *lh, | |
17751 | const struct comp_unit_head *cu_header, | |
17752 | void (*callback) (struct line_header *lh, | |
17753 | const char *name, | |
ecfb656c | 17754 | dir_index d_index, |
43988095 JK |
17755 | unsigned int mod_time, |
17756 | unsigned int length)) | |
17757 | { | |
17758 | gdb_byte format_count, formati; | |
17759 | ULONGEST data_count, datai; | |
17760 | const gdb_byte *buf = *bufp; | |
17761 | const gdb_byte *format_header_data; | |
17762 | int i; | |
17763 | unsigned int bytes_read; | |
17764 | ||
17765 | format_count = read_1_byte (abfd, buf); | |
17766 | buf += 1; | |
17767 | format_header_data = buf; | |
17768 | for (formati = 0; formati < format_count; formati++) | |
17769 | { | |
17770 | read_unsigned_leb128 (abfd, buf, &bytes_read); | |
17771 | buf += bytes_read; | |
17772 | read_unsigned_leb128 (abfd, buf, &bytes_read); | |
17773 | buf += bytes_read; | |
17774 | } | |
17775 | ||
17776 | data_count = read_unsigned_leb128 (abfd, buf, &bytes_read); | |
17777 | buf += bytes_read; | |
17778 | for (datai = 0; datai < data_count; datai++) | |
17779 | { | |
17780 | const gdb_byte *format = format_header_data; | |
17781 | struct file_entry fe; | |
17782 | ||
43988095 JK |
17783 | for (formati = 0; formati < format_count; formati++) |
17784 | { | |
ecfb656c | 17785 | ULONGEST content_type = read_unsigned_leb128 (abfd, format, &bytes_read); |
43988095 | 17786 | format += bytes_read; |
43988095 | 17787 | |
ecfb656c | 17788 | ULONGEST form = read_unsigned_leb128 (abfd, format, &bytes_read); |
43988095 | 17789 | format += bytes_read; |
ecfb656c PA |
17790 | |
17791 | gdb::optional<const char *> string; | |
17792 | gdb::optional<unsigned int> uint; | |
17793 | ||
43988095 JK |
17794 | switch (form) |
17795 | { | |
17796 | case DW_FORM_string: | |
ecfb656c | 17797 | string.emplace (read_direct_string (abfd, buf, &bytes_read)); |
43988095 JK |
17798 | buf += bytes_read; |
17799 | break; | |
17800 | ||
17801 | case DW_FORM_line_strp: | |
ecfb656c PA |
17802 | string.emplace (read_indirect_line_string (abfd, buf, |
17803 | cu_header, | |
17804 | &bytes_read)); | |
43988095 JK |
17805 | buf += bytes_read; |
17806 | break; | |
17807 | ||
17808 | case DW_FORM_data1: | |
ecfb656c | 17809 | uint.emplace (read_1_byte (abfd, buf)); |
43988095 JK |
17810 | buf += 1; |
17811 | break; | |
17812 | ||
17813 | case DW_FORM_data2: | |
ecfb656c | 17814 | uint.emplace (read_2_bytes (abfd, buf)); |
43988095 JK |
17815 | buf += 2; |
17816 | break; | |
17817 | ||
17818 | case DW_FORM_data4: | |
ecfb656c | 17819 | uint.emplace (read_4_bytes (abfd, buf)); |
43988095 JK |
17820 | buf += 4; |
17821 | break; | |
17822 | ||
17823 | case DW_FORM_data8: | |
ecfb656c | 17824 | uint.emplace (read_8_bytes (abfd, buf)); |
43988095 JK |
17825 | buf += 8; |
17826 | break; | |
17827 | ||
17828 | case DW_FORM_udata: | |
ecfb656c | 17829 | uint.emplace (read_unsigned_leb128 (abfd, buf, &bytes_read)); |
43988095 JK |
17830 | buf += bytes_read; |
17831 | break; | |
17832 | ||
17833 | case DW_FORM_block: | |
17834 | /* It is valid only for DW_LNCT_timestamp which is ignored by | |
17835 | current GDB. */ | |
17836 | break; | |
17837 | } | |
ecfb656c PA |
17838 | |
17839 | switch (content_type) | |
17840 | { | |
17841 | case DW_LNCT_path: | |
17842 | if (string.has_value ()) | |
17843 | fe.name = *string; | |
17844 | break; | |
17845 | case DW_LNCT_directory_index: | |
17846 | if (uint.has_value ()) | |
17847 | fe.d_index = (dir_index) *uint; | |
17848 | break; | |
17849 | case DW_LNCT_timestamp: | |
17850 | if (uint.has_value ()) | |
17851 | fe.mod_time = *uint; | |
17852 | break; | |
17853 | case DW_LNCT_size: | |
17854 | if (uint.has_value ()) | |
17855 | fe.length = *uint; | |
17856 | break; | |
17857 | case DW_LNCT_MD5: | |
17858 | break; | |
17859 | default: | |
17860 | complaint (&symfile_complaints, | |
17861 | _("Unknown format content type %s"), | |
17862 | pulongest (content_type)); | |
17863 | } | |
43988095 JK |
17864 | } |
17865 | ||
ecfb656c | 17866 | callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length); |
43988095 JK |
17867 | } |
17868 | ||
17869 | *bufp = buf; | |
17870 | } | |
17871 | ||
debd256d | 17872 | /* Read the statement program header starting at OFFSET in |
3019eac3 | 17873 | .debug_line, or .debug_line.dwo. Return a pointer |
6502dd73 | 17874 | to a struct line_header, allocated using xmalloc. |
cd366ee8 DE |
17875 | Returns NULL if there is a problem reading the header, e.g., if it |
17876 | has a version we don't understand. | |
debd256d JB |
17877 | |
17878 | NOTE: the strings in the include directory and file name tables of | |
3019eac3 DE |
17879 | the returned object point into the dwarf line section buffer, |
17880 | and must not be freed. */ | |
ae2de4f8 | 17881 | |
fff8551c | 17882 | static line_header_up |
9c541725 | 17883 | dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu) |
debd256d | 17884 | { |
d521ce57 | 17885 | const gdb_byte *line_ptr; |
c764a876 | 17886 | unsigned int bytes_read, offset_size; |
debd256d | 17887 | int i; |
d521ce57 | 17888 | const char *cur_dir, *cur_file; |
3019eac3 DE |
17889 | struct dwarf2_section_info *section; |
17890 | bfd *abfd; | |
17891 | ||
36586728 | 17892 | section = get_debug_line_section (cu); |
3019eac3 DE |
17893 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); |
17894 | if (section->buffer == NULL) | |
debd256d | 17895 | { |
3019eac3 DE |
17896 | if (cu->dwo_unit && cu->per_cu->is_debug_types) |
17897 | complaint (&symfile_complaints, _("missing .debug_line.dwo section")); | |
17898 | else | |
17899 | complaint (&symfile_complaints, _("missing .debug_line section")); | |
debd256d JB |
17900 | return 0; |
17901 | } | |
17902 | ||
fceca515 DE |
17903 | /* We can't do this until we know the section is non-empty. |
17904 | Only then do we know we have such a section. */ | |
a32a8923 | 17905 | abfd = get_section_bfd_owner (section); |
fceca515 | 17906 | |
a738430d MK |
17907 | /* Make sure that at least there's room for the total_length field. |
17908 | That could be 12 bytes long, but we're just going to fudge that. */ | |
9c541725 | 17909 | if (to_underlying (sect_off) + 4 >= section->size) |
debd256d | 17910 | { |
4d3c2250 | 17911 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
17912 | return 0; |
17913 | } | |
17914 | ||
fff8551c | 17915 | line_header_up lh (new line_header ()); |
debd256d | 17916 | |
9c541725 | 17917 | lh->sect_off = sect_off; |
527f3840 JK |
17918 | lh->offset_in_dwz = cu->per_cu->is_dwz; |
17919 | ||
9c541725 | 17920 | line_ptr = section->buffer + to_underlying (sect_off); |
debd256d | 17921 | |
a738430d | 17922 | /* Read in the header. */ |
6e70227d | 17923 | lh->total_length = |
c764a876 DE |
17924 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
17925 | &bytes_read, &offset_size); | |
debd256d | 17926 | line_ptr += bytes_read; |
3019eac3 | 17927 | if (line_ptr + lh->total_length > (section->buffer + section->size)) |
debd256d | 17928 | { |
4d3c2250 | 17929 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
17930 | return 0; |
17931 | } | |
17932 | lh->statement_program_end = line_ptr + lh->total_length; | |
17933 | lh->version = read_2_bytes (abfd, line_ptr); | |
17934 | line_ptr += 2; | |
43988095 | 17935 | if (lh->version > 5) |
cd366ee8 DE |
17936 | { |
17937 | /* This is a version we don't understand. The format could have | |
17938 | changed in ways we don't handle properly so just punt. */ | |
17939 | complaint (&symfile_complaints, | |
17940 | _("unsupported version in .debug_line section")); | |
17941 | return NULL; | |
17942 | } | |
43988095 JK |
17943 | if (lh->version >= 5) |
17944 | { | |
17945 | gdb_byte segment_selector_size; | |
17946 | ||
17947 | /* Skip address size. */ | |
17948 | read_1_byte (abfd, line_ptr); | |
17949 | line_ptr += 1; | |
17950 | ||
17951 | segment_selector_size = read_1_byte (abfd, line_ptr); | |
17952 | line_ptr += 1; | |
17953 | if (segment_selector_size != 0) | |
17954 | { | |
17955 | complaint (&symfile_complaints, | |
17956 | _("unsupported segment selector size %u " | |
17957 | "in .debug_line section"), | |
17958 | segment_selector_size); | |
17959 | return NULL; | |
17960 | } | |
17961 | } | |
c764a876 DE |
17962 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
17963 | line_ptr += offset_size; | |
debd256d JB |
17964 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
17965 | line_ptr += 1; | |
2dc7f7b3 TT |
17966 | if (lh->version >= 4) |
17967 | { | |
17968 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
17969 | line_ptr += 1; | |
17970 | } | |
17971 | else | |
17972 | lh->maximum_ops_per_instruction = 1; | |
17973 | ||
17974 | if (lh->maximum_ops_per_instruction == 0) | |
17975 | { | |
17976 | lh->maximum_ops_per_instruction = 1; | |
17977 | complaint (&symfile_complaints, | |
3e43a32a MS |
17978 | _("invalid maximum_ops_per_instruction " |
17979 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
17980 | } |
17981 | ||
debd256d JB |
17982 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
17983 | line_ptr += 1; | |
17984 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
17985 | line_ptr += 1; | |
17986 | lh->line_range = read_1_byte (abfd, line_ptr); | |
17987 | line_ptr += 1; | |
17988 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
17989 | line_ptr += 1; | |
fff8551c | 17990 | lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_base]); |
debd256d JB |
17991 | |
17992 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
17993 | for (i = 1; i < lh->opcode_base; ++i) | |
17994 | { | |
17995 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
17996 | line_ptr += 1; | |
17997 | } | |
17998 | ||
43988095 | 17999 | if (lh->version >= 5) |
debd256d | 18000 | { |
43988095 | 18001 | /* Read directory table. */ |
fff8551c PA |
18002 | read_formatted_entries (abfd, &line_ptr, lh.get (), &cu->header, |
18003 | [] (struct line_header *lh, const char *name, | |
ecfb656c | 18004 | dir_index d_index, unsigned int mod_time, |
fff8551c PA |
18005 | unsigned int length) |
18006 | { | |
18007 | lh->add_include_dir (name); | |
18008 | }); | |
debd256d | 18009 | |
43988095 | 18010 | /* Read file name table. */ |
fff8551c PA |
18011 | read_formatted_entries (abfd, &line_ptr, lh.get (), &cu->header, |
18012 | [] (struct line_header *lh, const char *name, | |
ecfb656c | 18013 | dir_index d_index, unsigned int mod_time, |
fff8551c PA |
18014 | unsigned int length) |
18015 | { | |
ecfb656c | 18016 | lh->add_file_name (name, d_index, mod_time, length); |
fff8551c | 18017 | }); |
43988095 JK |
18018 | } |
18019 | else | |
debd256d | 18020 | { |
43988095 JK |
18021 | /* Read directory table. */ |
18022 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) | |
18023 | { | |
18024 | line_ptr += bytes_read; | |
fff8551c | 18025 | lh->add_include_dir (cur_dir); |
43988095 | 18026 | } |
debd256d JB |
18027 | line_ptr += bytes_read; |
18028 | ||
43988095 JK |
18029 | /* Read file name table. */ |
18030 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) | |
18031 | { | |
ecfb656c PA |
18032 | unsigned int mod_time, length; |
18033 | dir_index d_index; | |
43988095 JK |
18034 | |
18035 | line_ptr += bytes_read; | |
ecfb656c | 18036 | d_index = (dir_index) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
43988095 JK |
18037 | line_ptr += bytes_read; |
18038 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
18039 | line_ptr += bytes_read; | |
18040 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
18041 | line_ptr += bytes_read; | |
18042 | ||
ecfb656c | 18043 | lh->add_file_name (cur_file, d_index, mod_time, length); |
43988095 JK |
18044 | } |
18045 | line_ptr += bytes_read; | |
debd256d | 18046 | } |
6e70227d | 18047 | lh->statement_program_start = line_ptr; |
debd256d | 18048 | |
3019eac3 | 18049 | if (line_ptr > (section->buffer + section->size)) |
4d3c2250 | 18050 | complaint (&symfile_complaints, |
3e43a32a MS |
18051 | _("line number info header doesn't " |
18052 | "fit in `.debug_line' section")); | |
debd256d | 18053 | |
debd256d JB |
18054 | return lh; |
18055 | } | |
c906108c | 18056 | |
c6da4cef DE |
18057 | /* Subroutine of dwarf_decode_lines to simplify it. |
18058 | Return the file name of the psymtab for included file FILE_INDEX | |
18059 | in line header LH of PST. | |
18060 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
18061 | If space for the result is malloc'd, it will be freed by a cleanup. | |
1ed59174 JK |
18062 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. |
18063 | ||
18064 | The function creates dangling cleanup registration. */ | |
c6da4cef | 18065 | |
d521ce57 | 18066 | static const char * |
c6da4cef DE |
18067 | psymtab_include_file_name (const struct line_header *lh, int file_index, |
18068 | const struct partial_symtab *pst, | |
18069 | const char *comp_dir) | |
18070 | { | |
8c43009f | 18071 | const file_entry &fe = lh->file_names[file_index]; |
d521ce57 TT |
18072 | const char *include_name = fe.name; |
18073 | const char *include_name_to_compare = include_name; | |
72b9f47f TT |
18074 | const char *pst_filename; |
18075 | char *copied_name = NULL; | |
c6da4cef DE |
18076 | int file_is_pst; |
18077 | ||
8c43009f | 18078 | const char *dir_name = fe.include_dir (lh); |
c6da4cef DE |
18079 | |
18080 | if (!IS_ABSOLUTE_PATH (include_name) | |
18081 | && (dir_name != NULL || comp_dir != NULL)) | |
18082 | { | |
18083 | /* Avoid creating a duplicate psymtab for PST. | |
18084 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
18085 | Before we do the comparison, however, we need to account | |
18086 | for DIR_NAME and COMP_DIR. | |
18087 | First prepend dir_name (if non-NULL). If we still don't | |
18088 | have an absolute path prepend comp_dir (if non-NULL). | |
18089 | However, the directory we record in the include-file's | |
18090 | psymtab does not contain COMP_DIR (to match the | |
18091 | corresponding symtab(s)). | |
18092 | ||
18093 | Example: | |
18094 | ||
18095 | bash$ cd /tmp | |
18096 | bash$ gcc -g ./hello.c | |
18097 | include_name = "hello.c" | |
18098 | dir_name = "." | |
18099 | DW_AT_comp_dir = comp_dir = "/tmp" | |
5f52445b YQ |
18100 | DW_AT_name = "./hello.c" |
18101 | ||
18102 | */ | |
c6da4cef DE |
18103 | |
18104 | if (dir_name != NULL) | |
18105 | { | |
d521ce57 TT |
18106 | char *tem = concat (dir_name, SLASH_STRING, |
18107 | include_name, (char *)NULL); | |
18108 | ||
18109 | make_cleanup (xfree, tem); | |
18110 | include_name = tem; | |
c6da4cef | 18111 | include_name_to_compare = include_name; |
c6da4cef DE |
18112 | } |
18113 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
18114 | { | |
d521ce57 TT |
18115 | char *tem = concat (comp_dir, SLASH_STRING, |
18116 | include_name, (char *)NULL); | |
18117 | ||
18118 | make_cleanup (xfree, tem); | |
18119 | include_name_to_compare = tem; | |
c6da4cef DE |
18120 | } |
18121 | } | |
18122 | ||
18123 | pst_filename = pst->filename; | |
18124 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
18125 | { | |
72b9f47f TT |
18126 | copied_name = concat (pst->dirname, SLASH_STRING, |
18127 | pst_filename, (char *)NULL); | |
18128 | pst_filename = copied_name; | |
c6da4cef DE |
18129 | } |
18130 | ||
1e3fad37 | 18131 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef | 18132 | |
72b9f47f TT |
18133 | if (copied_name != NULL) |
18134 | xfree (copied_name); | |
c6da4cef DE |
18135 | |
18136 | if (file_is_pst) | |
18137 | return NULL; | |
18138 | return include_name; | |
18139 | } | |
18140 | ||
d9b3de22 DE |
18141 | /* State machine to track the state of the line number program. */ |
18142 | ||
6f77053d | 18143 | class lnp_state_machine |
d9b3de22 | 18144 | { |
6f77053d PA |
18145 | public: |
18146 | /* Initialize a machine state for the start of a line number | |
18147 | program. */ | |
18148 | lnp_state_machine (gdbarch *arch, line_header *lh, bool record_lines_p); | |
18149 | ||
8c43009f PA |
18150 | file_entry *current_file () |
18151 | { | |
18152 | /* lh->file_names is 0-based, but the file name numbers in the | |
18153 | statement program are 1-based. */ | |
6f77053d PA |
18154 | return m_line_header->file_name_at (m_file); |
18155 | } | |
18156 | ||
18157 | /* Record the line in the state machine. END_SEQUENCE is true if | |
18158 | we're processing the end of a sequence. */ | |
18159 | void record_line (bool end_sequence); | |
18160 | ||
18161 | /* Check address and if invalid nop-out the rest of the lines in this | |
18162 | sequence. */ | |
18163 | void check_line_address (struct dwarf2_cu *cu, | |
18164 | const gdb_byte *line_ptr, | |
18165 | CORE_ADDR lowpc, CORE_ADDR address); | |
18166 | ||
18167 | void handle_set_discriminator (unsigned int discriminator) | |
18168 | { | |
18169 | m_discriminator = discriminator; | |
18170 | m_line_has_non_zero_discriminator |= discriminator != 0; | |
18171 | } | |
18172 | ||
18173 | /* Handle DW_LNE_set_address. */ | |
18174 | void handle_set_address (CORE_ADDR baseaddr, CORE_ADDR address) | |
18175 | { | |
18176 | m_op_index = 0; | |
18177 | address += baseaddr; | |
18178 | m_address = gdbarch_adjust_dwarf2_line (m_gdbarch, address, false); | |
18179 | } | |
18180 | ||
18181 | /* Handle DW_LNS_advance_pc. */ | |
18182 | void handle_advance_pc (CORE_ADDR adjust); | |
18183 | ||
18184 | /* Handle a special opcode. */ | |
18185 | void handle_special_opcode (unsigned char op_code); | |
18186 | ||
18187 | /* Handle DW_LNS_advance_line. */ | |
18188 | void handle_advance_line (int line_delta) | |
18189 | { | |
18190 | advance_line (line_delta); | |
18191 | } | |
18192 | ||
18193 | /* Handle DW_LNS_set_file. */ | |
18194 | void handle_set_file (file_name_index file); | |
18195 | ||
18196 | /* Handle DW_LNS_negate_stmt. */ | |
18197 | void handle_negate_stmt () | |
18198 | { | |
18199 | m_is_stmt = !m_is_stmt; | |
18200 | } | |
18201 | ||
18202 | /* Handle DW_LNS_const_add_pc. */ | |
18203 | void handle_const_add_pc (); | |
18204 | ||
18205 | /* Handle DW_LNS_fixed_advance_pc. */ | |
18206 | void handle_fixed_advance_pc (CORE_ADDR addr_adj) | |
18207 | { | |
18208 | m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true); | |
18209 | m_op_index = 0; | |
18210 | } | |
18211 | ||
18212 | /* Handle DW_LNS_copy. */ | |
18213 | void handle_copy () | |
18214 | { | |
18215 | record_line (false); | |
18216 | m_discriminator = 0; | |
18217 | } | |
18218 | ||
18219 | /* Handle DW_LNE_end_sequence. */ | |
18220 | void handle_end_sequence () | |
18221 | { | |
18222 | m_record_line_callback = ::record_line; | |
18223 | } | |
18224 | ||
18225 | private: | |
18226 | /* Advance the line by LINE_DELTA. */ | |
18227 | void advance_line (int line_delta) | |
18228 | { | |
18229 | m_line += line_delta; | |
18230 | ||
18231 | if (line_delta != 0) | |
18232 | m_line_has_non_zero_discriminator = m_discriminator != 0; | |
8c43009f PA |
18233 | } |
18234 | ||
6f77053d PA |
18235 | gdbarch *m_gdbarch; |
18236 | ||
18237 | /* True if we're recording lines. | |
18238 | Otherwise we're building partial symtabs and are just interested in | |
18239 | finding include files mentioned by the line number program. */ | |
18240 | bool m_record_lines_p; | |
18241 | ||
8c43009f | 18242 | /* The line number header. */ |
6f77053d | 18243 | line_header *m_line_header; |
8c43009f | 18244 | |
6f77053d PA |
18245 | /* These are part of the standard DWARF line number state machine, |
18246 | and initialized according to the DWARF spec. */ | |
d9b3de22 | 18247 | |
6f77053d | 18248 | unsigned char m_op_index = 0; |
8c43009f | 18249 | /* The line table index (1-based) of the current file. */ |
6f77053d PA |
18250 | file_name_index m_file = (file_name_index) 1; |
18251 | unsigned int m_line = 1; | |
18252 | ||
18253 | /* These are initialized in the constructor. */ | |
18254 | ||
18255 | CORE_ADDR m_address; | |
18256 | bool m_is_stmt; | |
18257 | unsigned int m_discriminator; | |
d9b3de22 DE |
18258 | |
18259 | /* Additional bits of state we need to track. */ | |
18260 | ||
18261 | /* The last file that we called dwarf2_start_subfile for. | |
18262 | This is only used for TLLs. */ | |
6f77053d | 18263 | unsigned int m_last_file = 0; |
d9b3de22 | 18264 | /* The last file a line number was recorded for. */ |
6f77053d | 18265 | struct subfile *m_last_subfile = NULL; |
d9b3de22 DE |
18266 | |
18267 | /* The function to call to record a line. */ | |
6f77053d | 18268 | record_line_ftype *m_record_line_callback = NULL; |
d9b3de22 DE |
18269 | |
18270 | /* The last line number that was recorded, used to coalesce | |
18271 | consecutive entries for the same line. This can happen, for | |
18272 | example, when discriminators are present. PR 17276. */ | |
6f77053d PA |
18273 | unsigned int m_last_line = 0; |
18274 | bool m_line_has_non_zero_discriminator = false; | |
8c43009f | 18275 | }; |
d9b3de22 | 18276 | |
6f77053d PA |
18277 | void |
18278 | lnp_state_machine::handle_advance_pc (CORE_ADDR adjust) | |
18279 | { | |
18280 | CORE_ADDR addr_adj = (((m_op_index + adjust) | |
18281 | / m_line_header->maximum_ops_per_instruction) | |
18282 | * m_line_header->minimum_instruction_length); | |
18283 | m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true); | |
18284 | m_op_index = ((m_op_index + adjust) | |
18285 | % m_line_header->maximum_ops_per_instruction); | |
18286 | } | |
d9b3de22 | 18287 | |
6f77053d PA |
18288 | void |
18289 | lnp_state_machine::handle_special_opcode (unsigned char op_code) | |
d9b3de22 | 18290 | { |
6f77053d PA |
18291 | unsigned char adj_opcode = op_code - m_line_header->opcode_base; |
18292 | CORE_ADDR addr_adj = (((m_op_index | |
18293 | + (adj_opcode / m_line_header->line_range)) | |
18294 | / m_line_header->maximum_ops_per_instruction) | |
18295 | * m_line_header->minimum_instruction_length); | |
18296 | m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true); | |
18297 | m_op_index = ((m_op_index + (adj_opcode / m_line_header->line_range)) | |
18298 | % m_line_header->maximum_ops_per_instruction); | |
d9b3de22 | 18299 | |
6f77053d PA |
18300 | int line_delta = (m_line_header->line_base |
18301 | + (adj_opcode % m_line_header->line_range)); | |
18302 | advance_line (line_delta); | |
18303 | record_line (false); | |
18304 | m_discriminator = 0; | |
18305 | } | |
d9b3de22 | 18306 | |
6f77053d PA |
18307 | void |
18308 | lnp_state_machine::handle_set_file (file_name_index file) | |
18309 | { | |
18310 | m_file = file; | |
18311 | ||
18312 | const file_entry *fe = current_file (); | |
18313 | if (fe == NULL) | |
18314 | dwarf2_debug_line_missing_file_complaint (); | |
18315 | else if (m_record_lines_p) | |
18316 | { | |
18317 | const char *dir = fe->include_dir (m_line_header); | |
18318 | ||
18319 | m_last_subfile = current_subfile; | |
18320 | m_line_has_non_zero_discriminator = m_discriminator != 0; | |
18321 | dwarf2_start_subfile (fe->name, dir); | |
18322 | } | |
18323 | } | |
18324 | ||
18325 | void | |
18326 | lnp_state_machine::handle_const_add_pc () | |
18327 | { | |
18328 | CORE_ADDR adjust | |
18329 | = (255 - m_line_header->opcode_base) / m_line_header->line_range; | |
18330 | ||
18331 | CORE_ADDR addr_adj | |
18332 | = (((m_op_index + adjust) | |
18333 | / m_line_header->maximum_ops_per_instruction) | |
18334 | * m_line_header->minimum_instruction_length); | |
18335 | ||
18336 | m_address += gdbarch_adjust_dwarf2_line (m_gdbarch, addr_adj, true); | |
18337 | m_op_index = ((m_op_index + adjust) | |
18338 | % m_line_header->maximum_ops_per_instruction); | |
18339 | } | |
d9b3de22 | 18340 | |
c91513d8 PP |
18341 | /* Ignore this record_line request. */ |
18342 | ||
18343 | static void | |
18344 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
18345 | { | |
18346 | return; | |
18347 | } | |
18348 | ||
a05a36a5 DE |
18349 | /* Return non-zero if we should add LINE to the line number table. |
18350 | LINE is the line to add, LAST_LINE is the last line that was added, | |
18351 | LAST_SUBFILE is the subfile for LAST_LINE. | |
18352 | LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever | |
18353 | had a non-zero discriminator. | |
18354 | ||
18355 | We have to be careful in the presence of discriminators. | |
18356 | E.g., for this line: | |
18357 | ||
18358 | for (i = 0; i < 100000; i++); | |
18359 | ||
18360 | clang can emit four line number entries for that one line, | |
18361 | each with a different discriminator. | |
18362 | See gdb.dwarf2/dw2-single-line-discriminators.exp for an example. | |
18363 | ||
18364 | However, we want gdb to coalesce all four entries into one. | |
18365 | Otherwise the user could stepi into the middle of the line and | |
18366 | gdb would get confused about whether the pc really was in the | |
18367 | middle of the line. | |
18368 | ||
18369 | Things are further complicated by the fact that two consecutive | |
18370 | line number entries for the same line is a heuristic used by gcc | |
18371 | to denote the end of the prologue. So we can't just discard duplicate | |
18372 | entries, we have to be selective about it. The heuristic we use is | |
18373 | that we only collapse consecutive entries for the same line if at least | |
18374 | one of those entries has a non-zero discriminator. PR 17276. | |
18375 | ||
18376 | Note: Addresses in the line number state machine can never go backwards | |
18377 | within one sequence, thus this coalescing is ok. */ | |
18378 | ||
18379 | static int | |
18380 | dwarf_record_line_p (unsigned int line, unsigned int last_line, | |
18381 | int line_has_non_zero_discriminator, | |
18382 | struct subfile *last_subfile) | |
18383 | { | |
18384 | if (current_subfile != last_subfile) | |
18385 | return 1; | |
18386 | if (line != last_line) | |
18387 | return 1; | |
18388 | /* Same line for the same file that we've seen already. | |
18389 | As a last check, for pr 17276, only record the line if the line | |
18390 | has never had a non-zero discriminator. */ | |
18391 | if (!line_has_non_zero_discriminator) | |
18392 | return 1; | |
18393 | return 0; | |
18394 | } | |
18395 | ||
252a6764 DE |
18396 | /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS |
18397 | in the line table of subfile SUBFILE. */ | |
18398 | ||
18399 | static void | |
d9b3de22 DE |
18400 | dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile, |
18401 | unsigned int line, CORE_ADDR address, | |
18402 | record_line_ftype p_record_line) | |
252a6764 DE |
18403 | { |
18404 | CORE_ADDR addr = gdbarch_addr_bits_remove (gdbarch, address); | |
18405 | ||
27e0867f DE |
18406 | if (dwarf_line_debug) |
18407 | { | |
18408 | fprintf_unfiltered (gdb_stdlog, | |
18409 | "Recording line %u, file %s, address %s\n", | |
18410 | line, lbasename (subfile->name), | |
18411 | paddress (gdbarch, address)); | |
18412 | } | |
18413 | ||
d5962de5 | 18414 | (*p_record_line) (subfile, line, addr); |
252a6764 DE |
18415 | } |
18416 | ||
18417 | /* Subroutine of dwarf_decode_lines_1 to simplify it. | |
18418 | Mark the end of a set of line number records. | |
d9b3de22 | 18419 | The arguments are the same as for dwarf_record_line_1. |
252a6764 DE |
18420 | If SUBFILE is NULL the request is ignored. */ |
18421 | ||
18422 | static void | |
18423 | dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile, | |
18424 | CORE_ADDR address, record_line_ftype p_record_line) | |
18425 | { | |
27e0867f DE |
18426 | if (subfile == NULL) |
18427 | return; | |
18428 | ||
18429 | if (dwarf_line_debug) | |
18430 | { | |
18431 | fprintf_unfiltered (gdb_stdlog, | |
18432 | "Finishing current line, file %s, address %s\n", | |
18433 | lbasename (subfile->name), | |
18434 | paddress (gdbarch, address)); | |
18435 | } | |
18436 | ||
d9b3de22 DE |
18437 | dwarf_record_line_1 (gdbarch, subfile, 0, address, p_record_line); |
18438 | } | |
18439 | ||
6f77053d PA |
18440 | void |
18441 | lnp_state_machine::record_line (bool end_sequence) | |
d9b3de22 | 18442 | { |
d9b3de22 DE |
18443 | if (dwarf_line_debug) |
18444 | { | |
18445 | fprintf_unfiltered (gdb_stdlog, | |
18446 | "Processing actual line %u: file %u," | |
18447 | " address %s, is_stmt %u, discrim %u\n", | |
6f77053d PA |
18448 | m_line, to_underlying (m_file), |
18449 | paddress (m_gdbarch, m_address), | |
18450 | m_is_stmt, m_discriminator); | |
d9b3de22 DE |
18451 | } |
18452 | ||
6f77053d | 18453 | file_entry *fe = current_file (); |
8c43009f PA |
18454 | |
18455 | if (fe == NULL) | |
d9b3de22 DE |
18456 | dwarf2_debug_line_missing_file_complaint (); |
18457 | /* For now we ignore lines not starting on an instruction boundary. | |
18458 | But not when processing end_sequence for compatibility with the | |
18459 | previous version of the code. */ | |
6f77053d | 18460 | else if (m_op_index == 0 || end_sequence) |
d9b3de22 | 18461 | { |
8c43009f | 18462 | fe->included_p = 1; |
6f77053d | 18463 | if (m_record_lines_p && m_is_stmt) |
d9b3de22 | 18464 | { |
6f77053d | 18465 | if (m_last_subfile != current_subfile || end_sequence) |
d9b3de22 | 18466 | { |
6f77053d PA |
18467 | dwarf_finish_line (m_gdbarch, m_last_subfile, |
18468 | m_address, m_record_line_callback); | |
d9b3de22 DE |
18469 | } |
18470 | ||
18471 | if (!end_sequence) | |
18472 | { | |
6f77053d PA |
18473 | if (dwarf_record_line_p (m_line, m_last_line, |
18474 | m_line_has_non_zero_discriminator, | |
18475 | m_last_subfile)) | |
d9b3de22 | 18476 | { |
6f77053d PA |
18477 | dwarf_record_line_1 (m_gdbarch, current_subfile, |
18478 | m_line, m_address, | |
18479 | m_record_line_callback); | |
d9b3de22 | 18480 | } |
6f77053d PA |
18481 | m_last_subfile = current_subfile; |
18482 | m_last_line = m_line; | |
d9b3de22 DE |
18483 | } |
18484 | } | |
18485 | } | |
18486 | } | |
18487 | ||
6f77053d PA |
18488 | lnp_state_machine::lnp_state_machine (gdbarch *arch, line_header *lh, |
18489 | bool record_lines_p) | |
d9b3de22 | 18490 | { |
6f77053d PA |
18491 | m_gdbarch = arch; |
18492 | m_record_lines_p = record_lines_p; | |
18493 | m_line_header = lh; | |
d9b3de22 | 18494 | |
6f77053d | 18495 | m_record_line_callback = ::record_line; |
d9b3de22 | 18496 | |
d9b3de22 DE |
18497 | /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there |
18498 | was a line entry for it so that the backend has a chance to adjust it | |
18499 | and also record it in case it needs it. This is currently used by MIPS | |
18500 | code, cf. `mips_adjust_dwarf2_line'. */ | |
6f77053d PA |
18501 | m_address = gdbarch_adjust_dwarf2_line (arch, 0, 0); |
18502 | m_is_stmt = lh->default_is_stmt; | |
18503 | m_discriminator = 0; | |
252a6764 DE |
18504 | } |
18505 | ||
6f77053d PA |
18506 | void |
18507 | lnp_state_machine::check_line_address (struct dwarf2_cu *cu, | |
18508 | const gdb_byte *line_ptr, | |
18509 | CORE_ADDR lowpc, CORE_ADDR address) | |
924c2928 DE |
18510 | { |
18511 | /* If address < lowpc then it's not a usable value, it's outside the | |
18512 | pc range of the CU. However, we restrict the test to only address | |
18513 | values of zero to preserve GDB's previous behaviour which is to | |
18514 | handle the specific case of a function being GC'd by the linker. */ | |
18515 | ||
18516 | if (address == 0 && address < lowpc) | |
18517 | { | |
18518 | /* This line table is for a function which has been | |
18519 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
18520 | ||
18521 | struct objfile *objfile = cu->objfile; | |
18522 | long line_offset = line_ptr - get_debug_line_section (cu)->buffer; | |
18523 | ||
18524 | complaint (&symfile_complaints, | |
18525 | _(".debug_line address at offset 0x%lx is 0 [in module %s]"), | |
18526 | line_offset, objfile_name (objfile)); | |
6f77053d PA |
18527 | m_record_line_callback = noop_record_line; |
18528 | /* Note: record_line_callback is left as noop_record_line until | |
18529 | we see DW_LNE_end_sequence. */ | |
924c2928 DE |
18530 | } |
18531 | } | |
18532 | ||
f3f5162e | 18533 | /* Subroutine of dwarf_decode_lines to simplify it. |
d9b3de22 DE |
18534 | Process the line number information in LH. |
18535 | If DECODE_FOR_PST_P is non-zero, all we do is process the line number | |
18536 | program in order to set included_p for every referenced header. */ | |
debd256d | 18537 | |
c906108c | 18538 | static void |
43f3e411 DE |
18539 | dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu, |
18540 | const int decode_for_pst_p, CORE_ADDR lowpc) | |
c906108c | 18541 | { |
d521ce57 TT |
18542 | const gdb_byte *line_ptr, *extended_end; |
18543 | const gdb_byte *line_end; | |
a8c50c1f | 18544 | unsigned int bytes_read, extended_len; |
699ca60a | 18545 | unsigned char op_code, extended_op; |
e142c38c DJ |
18546 | CORE_ADDR baseaddr; |
18547 | struct objfile *objfile = cu->objfile; | |
f3f5162e | 18548 | bfd *abfd = objfile->obfd; |
fbf65064 | 18549 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
6f77053d PA |
18550 | /* True if we're recording line info (as opposed to building partial |
18551 | symtabs and just interested in finding include files mentioned by | |
18552 | the line number program). */ | |
18553 | bool record_lines_p = !decode_for_pst_p; | |
e142c38c DJ |
18554 | |
18555 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 18556 | |
debd256d JB |
18557 | line_ptr = lh->statement_program_start; |
18558 | line_end = lh->statement_program_end; | |
c906108c SS |
18559 | |
18560 | /* Read the statement sequences until there's nothing left. */ | |
18561 | while (line_ptr < line_end) | |
18562 | { | |
6f77053d PA |
18563 | /* The DWARF line number program state machine. Reset the state |
18564 | machine at the start of each sequence. */ | |
18565 | lnp_state_machine state_machine (gdbarch, lh, record_lines_p); | |
18566 | bool end_sequence = false; | |
d9b3de22 | 18567 | |
8c43009f | 18568 | if (record_lines_p) |
c906108c | 18569 | { |
8c43009f PA |
18570 | /* Start a subfile for the current file of the state |
18571 | machine. */ | |
18572 | const file_entry *fe = state_machine.current_file (); | |
18573 | ||
18574 | if (fe != NULL) | |
18575 | dwarf2_start_subfile (fe->name, fe->include_dir (lh)); | |
c906108c SS |
18576 | } |
18577 | ||
a738430d | 18578 | /* Decode the table. */ |
d9b3de22 | 18579 | while (line_ptr < line_end && !end_sequence) |
c906108c SS |
18580 | { |
18581 | op_code = read_1_byte (abfd, line_ptr); | |
18582 | line_ptr += 1; | |
9aa1fe7e | 18583 | |
debd256d | 18584 | if (op_code >= lh->opcode_base) |
6e70227d | 18585 | { |
8e07a239 | 18586 | /* Special opcode. */ |
6f77053d | 18587 | state_machine.handle_special_opcode (op_code); |
9aa1fe7e GK |
18588 | } |
18589 | else switch (op_code) | |
c906108c SS |
18590 | { |
18591 | case DW_LNS_extended_op: | |
3e43a32a MS |
18592 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
18593 | &bytes_read); | |
473b7be6 | 18594 | line_ptr += bytes_read; |
a8c50c1f | 18595 | extended_end = line_ptr + extended_len; |
c906108c SS |
18596 | extended_op = read_1_byte (abfd, line_ptr); |
18597 | line_ptr += 1; | |
18598 | switch (extended_op) | |
18599 | { | |
18600 | case DW_LNE_end_sequence: | |
6f77053d PA |
18601 | state_machine.handle_end_sequence (); |
18602 | end_sequence = true; | |
c906108c SS |
18603 | break; |
18604 | case DW_LNE_set_address: | |
d9b3de22 DE |
18605 | { |
18606 | CORE_ADDR address | |
18607 | = read_address (abfd, line_ptr, cu, &bytes_read); | |
d9b3de22 | 18608 | line_ptr += bytes_read; |
6f77053d PA |
18609 | |
18610 | state_machine.check_line_address (cu, line_ptr, | |
18611 | lowpc, address); | |
18612 | state_machine.handle_set_address (baseaddr, address); | |
d9b3de22 | 18613 | } |
c906108c SS |
18614 | break; |
18615 | case DW_LNE_define_file: | |
debd256d | 18616 | { |
d521ce57 | 18617 | const char *cur_file; |
ecfb656c PA |
18618 | unsigned int mod_time, length; |
18619 | dir_index dindex; | |
6e70227d | 18620 | |
3e43a32a MS |
18621 | cur_file = read_direct_string (abfd, line_ptr, |
18622 | &bytes_read); | |
debd256d | 18623 | line_ptr += bytes_read; |
ecfb656c | 18624 | dindex = (dir_index) |
debd256d JB |
18625 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
18626 | line_ptr += bytes_read; | |
18627 | mod_time = | |
18628 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
18629 | line_ptr += bytes_read; | |
18630 | length = | |
18631 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
18632 | line_ptr += bytes_read; | |
ecfb656c | 18633 | lh->add_file_name (cur_file, dindex, mod_time, length); |
debd256d | 18634 | } |
c906108c | 18635 | break; |
d0c6ba3d | 18636 | case DW_LNE_set_discriminator: |
6f77053d PA |
18637 | { |
18638 | /* The discriminator is not interesting to the | |
18639 | debugger; just ignore it. We still need to | |
18640 | check its value though: | |
18641 | if there are consecutive entries for the same | |
18642 | (non-prologue) line we want to coalesce them. | |
18643 | PR 17276. */ | |
18644 | unsigned int discr | |
18645 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
18646 | line_ptr += bytes_read; | |
18647 | ||
18648 | state_machine.handle_set_discriminator (discr); | |
18649 | } | |
d0c6ba3d | 18650 | break; |
c906108c | 18651 | default: |
4d3c2250 | 18652 | complaint (&symfile_complaints, |
e2e0b3e5 | 18653 | _("mangled .debug_line section")); |
debd256d | 18654 | return; |
c906108c | 18655 | } |
a8c50c1f DJ |
18656 | /* Make sure that we parsed the extended op correctly. If e.g. |
18657 | we expected a different address size than the producer used, | |
18658 | we may have read the wrong number of bytes. */ | |
18659 | if (line_ptr != extended_end) | |
18660 | { | |
18661 | complaint (&symfile_complaints, | |
18662 | _("mangled .debug_line section")); | |
18663 | return; | |
18664 | } | |
c906108c SS |
18665 | break; |
18666 | case DW_LNS_copy: | |
6f77053d | 18667 | state_machine.handle_copy (); |
c906108c SS |
18668 | break; |
18669 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
18670 | { |
18671 | CORE_ADDR adjust | |
18672 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
2dc7f7b3 | 18673 | line_ptr += bytes_read; |
6f77053d PA |
18674 | |
18675 | state_machine.handle_advance_pc (adjust); | |
2dc7f7b3 | 18676 | } |
c906108c SS |
18677 | break; |
18678 | case DW_LNS_advance_line: | |
a05a36a5 DE |
18679 | { |
18680 | int line_delta | |
18681 | = read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
a05a36a5 | 18682 | line_ptr += bytes_read; |
6f77053d PA |
18683 | |
18684 | state_machine.handle_advance_line (line_delta); | |
a05a36a5 | 18685 | } |
c906108c SS |
18686 | break; |
18687 | case DW_LNS_set_file: | |
d9b3de22 | 18688 | { |
6f77053d | 18689 | file_name_index file |
ecfb656c PA |
18690 | = (file_name_index) read_unsigned_leb128 (abfd, line_ptr, |
18691 | &bytes_read); | |
d9b3de22 | 18692 | line_ptr += bytes_read; |
8c43009f | 18693 | |
6f77053d | 18694 | state_machine.handle_set_file (file); |
d9b3de22 | 18695 | } |
c906108c SS |
18696 | break; |
18697 | case DW_LNS_set_column: | |
0ad93d4f | 18698 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
c906108c SS |
18699 | line_ptr += bytes_read; |
18700 | break; | |
18701 | case DW_LNS_negate_stmt: | |
6f77053d | 18702 | state_machine.handle_negate_stmt (); |
c906108c SS |
18703 | break; |
18704 | case DW_LNS_set_basic_block: | |
c906108c | 18705 | break; |
c2c6d25f JM |
18706 | /* Add to the address register of the state machine the |
18707 | address increment value corresponding to special opcode | |
a738430d MK |
18708 | 255. I.e., this value is scaled by the minimum |
18709 | instruction length since special opcode 255 would have | |
b021a221 | 18710 | scaled the increment. */ |
c906108c | 18711 | case DW_LNS_const_add_pc: |
6f77053d | 18712 | state_machine.handle_const_add_pc (); |
c906108c SS |
18713 | break; |
18714 | case DW_LNS_fixed_advance_pc: | |
3e29f34a | 18715 | { |
6f77053d | 18716 | CORE_ADDR addr_adj = read_2_bytes (abfd, line_ptr); |
3e29f34a | 18717 | line_ptr += 2; |
6f77053d PA |
18718 | |
18719 | state_machine.handle_fixed_advance_pc (addr_adj); | |
3e29f34a | 18720 | } |
c906108c | 18721 | break; |
9aa1fe7e | 18722 | default: |
a738430d MK |
18723 | { |
18724 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 18725 | int i; |
a738430d | 18726 | |
debd256d | 18727 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
18728 | { |
18729 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
18730 | line_ptr += bytes_read; | |
18731 | } | |
18732 | } | |
c906108c SS |
18733 | } |
18734 | } | |
d9b3de22 DE |
18735 | |
18736 | if (!end_sequence) | |
18737 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
18738 | ||
18739 | /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer, | |
18740 | in which case we still finish recording the last line). */ | |
6f77053d | 18741 | state_machine.record_line (true); |
c906108c | 18742 | } |
f3f5162e DE |
18743 | } |
18744 | ||
18745 | /* Decode the Line Number Program (LNP) for the given line_header | |
18746 | structure and CU. The actual information extracted and the type | |
18747 | of structures created from the LNP depends on the value of PST. | |
18748 | ||
18749 | 1. If PST is NULL, then this procedure uses the data from the program | |
18750 | to create all necessary symbol tables, and their linetables. | |
18751 | ||
18752 | 2. If PST is not NULL, this procedure reads the program to determine | |
18753 | the list of files included by the unit represented by PST, and | |
18754 | builds all the associated partial symbol tables. | |
18755 | ||
18756 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
18757 | It is used for relative paths in the line table. | |
18758 | NOTE: When processing partial symtabs (pst != NULL), | |
18759 | comp_dir == pst->dirname. | |
18760 | ||
18761 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
18762 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
18763 | symtab we don't use it in the name of the psymtabs we create. | |
18764 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
c3b7b696 YQ |
18765 | A good testcase for this is mb-inline.exp. |
18766 | ||
527f3840 JK |
18767 | LOWPC is the lowest address in CU (or 0 if not known). |
18768 | ||
18769 | Boolean DECODE_MAPPING specifies we need to fully decode .debug_line | |
18770 | for its PC<->lines mapping information. Otherwise only the filename | |
18771 | table is read in. */ | |
f3f5162e DE |
18772 | |
18773 | static void | |
18774 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, | |
c3b7b696 | 18775 | struct dwarf2_cu *cu, struct partial_symtab *pst, |
527f3840 | 18776 | CORE_ADDR lowpc, int decode_mapping) |
f3f5162e DE |
18777 | { |
18778 | struct objfile *objfile = cu->objfile; | |
18779 | const int decode_for_pst_p = (pst != NULL); | |
f3f5162e | 18780 | |
527f3840 JK |
18781 | if (decode_mapping) |
18782 | dwarf_decode_lines_1 (lh, cu, decode_for_pst_p, lowpc); | |
aaa75496 JB |
18783 | |
18784 | if (decode_for_pst_p) | |
18785 | { | |
18786 | int file_index; | |
18787 | ||
18788 | /* Now that we're done scanning the Line Header Program, we can | |
18789 | create the psymtab of each included file. */ | |
fff8551c | 18790 | for (file_index = 0; file_index < lh->file_names.size (); file_index++) |
aaa75496 JB |
18791 | if (lh->file_names[file_index].included_p == 1) |
18792 | { | |
d521ce57 | 18793 | const char *include_name = |
c6da4cef DE |
18794 | psymtab_include_file_name (lh, file_index, pst, comp_dir); |
18795 | if (include_name != NULL) | |
aaa75496 JB |
18796 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
18797 | } | |
18798 | } | |
cb1df416 DJ |
18799 | else |
18800 | { | |
18801 | /* Make sure a symtab is created for every file, even files | |
18802 | which contain only variables (i.e. no code with associated | |
18803 | line numbers). */ | |
43f3e411 | 18804 | struct compunit_symtab *cust = buildsym_compunit_symtab (); |
cb1df416 | 18805 | int i; |
cb1df416 | 18806 | |
fff8551c | 18807 | for (i = 0; i < lh->file_names.size (); i++) |
cb1df416 | 18808 | { |
8c43009f | 18809 | file_entry &fe = lh->file_names[i]; |
9a619af0 | 18810 | |
8c43009f | 18811 | dwarf2_start_subfile (fe.name, fe.include_dir (lh)); |
cb1df416 | 18812 | |
cb1df416 | 18813 | if (current_subfile->symtab == NULL) |
43f3e411 DE |
18814 | { |
18815 | current_subfile->symtab | |
18816 | = allocate_symtab (cust, current_subfile->name); | |
18817 | } | |
8c43009f | 18818 | fe.symtab = current_subfile->symtab; |
cb1df416 DJ |
18819 | } |
18820 | } | |
c906108c SS |
18821 | } |
18822 | ||
18823 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
18824 | DIRNAME the name of the source directory which contains FILENAME | |
4d663531 | 18825 | or NULL if not known. |
c906108c SS |
18826 | This routine tries to keep line numbers from identical absolute and |
18827 | relative file names in a common subfile. | |
18828 | ||
18829 | Using the `list' example from the GDB testsuite, which resides in | |
18830 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
18831 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
18832 | ||
c5aa993b | 18833 | DW_AT_name: /srcdir/list0.c |
4d663531 | 18834 | DW_AT_comp_dir: /compdir |
357e46e7 | 18835 | files.files[0].name: list0.h |
c5aa993b | 18836 | files.files[0].dir: /srcdir |
357e46e7 | 18837 | files.files[1].name: list0.c |
c5aa993b | 18838 | files.files[1].dir: /srcdir |
c906108c SS |
18839 | |
18840 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
18841 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
18842 | start_subfile will ensure that this happens provided that we pass the | |
18843 | concatenation of files.files[1].dir and files.files[1].name as the | |
18844 | subfile's name. */ | |
c906108c SS |
18845 | |
18846 | static void | |
4d663531 | 18847 | dwarf2_start_subfile (const char *filename, const char *dirname) |
c906108c | 18848 | { |
d521ce57 | 18849 | char *copy = NULL; |
4f1520fb | 18850 | |
4d663531 | 18851 | /* In order not to lose the line information directory, |
4f1520fb FR |
18852 | we concatenate it to the filename when it makes sense. |
18853 | Note that the Dwarf3 standard says (speaking of filenames in line | |
18854 | information): ``The directory index is ignored for file names | |
18855 | that represent full path names''. Thus ignoring dirname in the | |
18856 | `else' branch below isn't an issue. */ | |
c906108c | 18857 | |
d5166ae1 | 18858 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
d521ce57 TT |
18859 | { |
18860 | copy = concat (dirname, SLASH_STRING, filename, (char *)NULL); | |
18861 | filename = copy; | |
18862 | } | |
c906108c | 18863 | |
4d663531 | 18864 | start_subfile (filename); |
4f1520fb | 18865 | |
d521ce57 TT |
18866 | if (copy != NULL) |
18867 | xfree (copy); | |
c906108c SS |
18868 | } |
18869 | ||
f4dc4d17 DE |
18870 | /* Start a symtab for DWARF. |
18871 | NAME, COMP_DIR, LOW_PC are passed to start_symtab. */ | |
18872 | ||
43f3e411 | 18873 | static struct compunit_symtab * |
f4dc4d17 | 18874 | dwarf2_start_symtab (struct dwarf2_cu *cu, |
15d034d0 | 18875 | const char *name, const char *comp_dir, CORE_ADDR low_pc) |
f4dc4d17 | 18876 | { |
43f3e411 DE |
18877 | struct compunit_symtab *cust |
18878 | = start_symtab (cu->objfile, name, comp_dir, low_pc); | |
18879 | ||
f4dc4d17 DE |
18880 | record_debugformat ("DWARF 2"); |
18881 | record_producer (cu->producer); | |
18882 | ||
18883 | /* We assume that we're processing GCC output. */ | |
18884 | processing_gcc_compilation = 2; | |
18885 | ||
4d4ec4e5 | 18886 | cu->processing_has_namespace_info = 0; |
43f3e411 DE |
18887 | |
18888 | return cust; | |
f4dc4d17 DE |
18889 | } |
18890 | ||
4c2df51b DJ |
18891 | static void |
18892 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 18893 | struct dwarf2_cu *cu) |
4c2df51b | 18894 | { |
e7c27a73 DJ |
18895 | struct objfile *objfile = cu->objfile; |
18896 | struct comp_unit_head *cu_header = &cu->header; | |
18897 | ||
4c2df51b DJ |
18898 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
18899 | code here to turn a symbol with DW_AT_external and a | |
18900 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
18901 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
18902 | with some versions of binutils) where shared libraries could have | |
18903 | relocations against symbols in their debug information - the | |
18904 | minimal symbol would have the right address, but the debug info | |
18905 | would not. It's no longer necessary, because we will explicitly | |
18906 | apply relocations when we read in the debug information now. */ | |
18907 | ||
18908 | /* A DW_AT_location attribute with no contents indicates that a | |
18909 | variable has been optimized away. */ | |
18910 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
18911 | { | |
f1e6e072 | 18912 | SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT; |
4c2df51b DJ |
18913 | return; |
18914 | } | |
18915 | ||
18916 | /* Handle one degenerate form of location expression specially, to | |
18917 | preserve GDB's previous behavior when section offsets are | |
3019eac3 DE |
18918 | specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index |
18919 | then mark this symbol as LOC_STATIC. */ | |
4c2df51b DJ |
18920 | |
18921 | if (attr_form_is_block (attr) | |
3019eac3 DE |
18922 | && ((DW_BLOCK (attr)->data[0] == DW_OP_addr |
18923 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size) | |
18924 | || (DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index | |
18925 | && (DW_BLOCK (attr)->size | |
18926 | == 1 + leb128_size (&DW_BLOCK (attr)->data[1]))))) | |
4c2df51b | 18927 | { |
891d2f0b | 18928 | unsigned int dummy; |
4c2df51b | 18929 | |
3019eac3 DE |
18930 | if (DW_BLOCK (attr)->data[0] == DW_OP_addr) |
18931 | SYMBOL_VALUE_ADDRESS (sym) = | |
18932 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); | |
18933 | else | |
18934 | SYMBOL_VALUE_ADDRESS (sym) = | |
18935 | read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy); | |
f1e6e072 | 18936 | SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC; |
4c2df51b DJ |
18937 | fixup_symbol_section (sym, objfile); |
18938 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
18939 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
18940 | return; |
18941 | } | |
18942 | ||
18943 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
18944 | expression evaluator, and use LOC_COMPUTED only when necessary | |
18945 | (i.e. when the value of a register or memory location is | |
18946 | referenced, or a thread-local block, etc.). Then again, it might | |
18947 | not be worthwhile. I'm assuming that it isn't unless performance | |
18948 | or memory numbers show me otherwise. */ | |
18949 | ||
f1e6e072 | 18950 | dwarf2_symbol_mark_computed (attr, sym, cu, 0); |
8be455d7 | 18951 | |
f1e6e072 | 18952 | if (SYMBOL_COMPUTED_OPS (sym)->location_has_loclist) |
8be455d7 | 18953 | cu->has_loclist = 1; |
4c2df51b DJ |
18954 | } |
18955 | ||
c906108c SS |
18956 | /* Given a pointer to a DWARF information entry, figure out if we need |
18957 | to make a symbol table entry for it, and if so, create a new entry | |
18958 | and return a pointer to it. | |
18959 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
18960 | used the passed type. |
18961 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
18962 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
18963 | |
18964 | static struct symbol * | |
34eaf542 TT |
18965 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
18966 | struct symbol *space) | |
c906108c | 18967 | { |
e7c27a73 | 18968 | struct objfile *objfile = cu->objfile; |
3e29f34a | 18969 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c | 18970 | struct symbol *sym = NULL; |
15d034d0 | 18971 | const char *name; |
c906108c SS |
18972 | struct attribute *attr = NULL; |
18973 | struct attribute *attr2 = NULL; | |
e142c38c | 18974 | CORE_ADDR baseaddr; |
e37fd15a SW |
18975 | struct pending **list_to_add = NULL; |
18976 | ||
edb3359d | 18977 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
18978 | |
18979 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 18980 | |
94af9270 | 18981 | name = dwarf2_name (die, cu); |
c906108c SS |
18982 | if (name) |
18983 | { | |
94af9270 | 18984 | const char *linkagename; |
34eaf542 | 18985 | int suppress_add = 0; |
94af9270 | 18986 | |
34eaf542 TT |
18987 | if (space) |
18988 | sym = space; | |
18989 | else | |
e623cf5d | 18990 | sym = allocate_symbol (objfile); |
c906108c | 18991 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
18992 | |
18993 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
f85f34ed | 18994 | SYMBOL_SET_LANGUAGE (sym, cu->language, &objfile->objfile_obstack); |
94af9270 KS |
18995 | linkagename = dwarf2_physname (name, die, cu); |
18996 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 18997 | |
f55ee35c JK |
18998 | /* Fortran does not have mangling standard and the mangling does differ |
18999 | between gfortran, iFort etc. */ | |
19000 | if (cu->language == language_fortran | |
b250c185 | 19001 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d | 19002 | symbol_set_demangled_name (&(sym->ginfo), |
cfc594ee | 19003 | dwarf2_full_name (name, die, cu), |
29df156d | 19004 | NULL); |
f55ee35c | 19005 | |
c906108c | 19006 | /* Default assumptions. |
c5aa993b | 19007 | Use the passed type or decode it from the die. */ |
176620f1 | 19008 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
f1e6e072 | 19009 | SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
19010 | if (type != NULL) |
19011 | SYMBOL_TYPE (sym) = type; | |
19012 | else | |
e7c27a73 | 19013 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
19014 | attr = dwarf2_attr (die, |
19015 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
19016 | cu); | |
c906108c SS |
19017 | if (attr) |
19018 | { | |
19019 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
19020 | } | |
cb1df416 | 19021 | |
edb3359d DJ |
19022 | attr = dwarf2_attr (die, |
19023 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
19024 | cu); | |
cb1df416 DJ |
19025 | if (attr) |
19026 | { | |
ecfb656c | 19027 | file_name_index file_index = (file_name_index) DW_UNSND (attr); |
8c43009f | 19028 | struct file_entry *fe; |
9a619af0 | 19029 | |
ecfb656c PA |
19030 | if (cu->line_header != NULL) |
19031 | fe = cu->line_header->file_name_at (file_index); | |
8c43009f PA |
19032 | else |
19033 | fe = NULL; | |
19034 | ||
19035 | if (fe == NULL) | |
cb1df416 DJ |
19036 | complaint (&symfile_complaints, |
19037 | _("file index out of range")); | |
8c43009f PA |
19038 | else |
19039 | symbol_set_symtab (sym, fe->symtab); | |
cb1df416 DJ |
19040 | } |
19041 | ||
c906108c SS |
19042 | switch (die->tag) |
19043 | { | |
19044 | case DW_TAG_label: | |
e142c38c | 19045 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c | 19046 | if (attr) |
3e29f34a MR |
19047 | { |
19048 | CORE_ADDR addr; | |
19049 | ||
19050 | addr = attr_value_as_address (attr); | |
19051 | addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr); | |
19052 | SYMBOL_VALUE_ADDRESS (sym) = addr; | |
19053 | } | |
0f5238ed TT |
19054 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
19055 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
f1e6e072 | 19056 | SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL; |
0f5238ed | 19057 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
19058 | break; |
19059 | case DW_TAG_subprogram: | |
19060 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
19061 | finish_block. */ | |
f1e6e072 | 19062 | SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK; |
e142c38c | 19063 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
19064 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
19065 | || cu->language == language_ada) | |
c906108c | 19066 | { |
2cfa0c8d JB |
19067 | /* Subprograms marked external are stored as a global symbol. |
19068 | Ada subprograms, whether marked external or not, are always | |
19069 | stored as a global symbol, because we want to be able to | |
19070 | access them globally. For instance, we want to be able | |
19071 | to break on a nested subprogram without having to | |
19072 | specify the context. */ | |
e37fd15a | 19073 | list_to_add = &global_symbols; |
c906108c SS |
19074 | } |
19075 | else | |
19076 | { | |
e37fd15a | 19077 | list_to_add = cu->list_in_scope; |
c906108c SS |
19078 | } |
19079 | break; | |
edb3359d DJ |
19080 | case DW_TAG_inlined_subroutine: |
19081 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
19082 | finish_block. */ | |
f1e6e072 | 19083 | SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK; |
edb3359d | 19084 | SYMBOL_INLINED (sym) = 1; |
481860b3 | 19085 | list_to_add = cu->list_in_scope; |
edb3359d | 19086 | break; |
34eaf542 TT |
19087 | case DW_TAG_template_value_param: |
19088 | suppress_add = 1; | |
19089 | /* Fall through. */ | |
72929c62 | 19090 | case DW_TAG_constant: |
c906108c | 19091 | case DW_TAG_variable: |
254e6b9e | 19092 | case DW_TAG_member: |
0963b4bd MS |
19093 | /* Compilation with minimal debug info may result in |
19094 | variables with missing type entries. Change the | |
19095 | misleading `void' type to something sensible. */ | |
c906108c | 19096 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 19097 | SYMBOL_TYPE (sym) |
46bf5051 | 19098 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 19099 | |
e142c38c | 19100 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
19101 | /* In the case of DW_TAG_member, we should only be called for |
19102 | static const members. */ | |
19103 | if (die->tag == DW_TAG_member) | |
19104 | { | |
3863f96c DE |
19105 | /* dwarf2_add_field uses die_is_declaration, |
19106 | so we do the same. */ | |
254e6b9e DE |
19107 | gdb_assert (die_is_declaration (die, cu)); |
19108 | gdb_assert (attr); | |
19109 | } | |
c906108c SS |
19110 | if (attr) |
19111 | { | |
e7c27a73 | 19112 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 19113 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 19114 | if (!suppress_add) |
34eaf542 TT |
19115 | { |
19116 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 19117 | list_to_add = &global_symbols; |
34eaf542 | 19118 | else |
e37fd15a | 19119 | list_to_add = cu->list_in_scope; |
34eaf542 | 19120 | } |
c906108c SS |
19121 | break; |
19122 | } | |
e142c38c | 19123 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
19124 | if (attr) |
19125 | { | |
e7c27a73 | 19126 | var_decode_location (attr, sym, cu); |
e142c38c | 19127 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
4357ac6c TT |
19128 | |
19129 | /* Fortran explicitly imports any global symbols to the local | |
19130 | scope by DW_TAG_common_block. */ | |
19131 | if (cu->language == language_fortran && die->parent | |
19132 | && die->parent->tag == DW_TAG_common_block) | |
19133 | attr2 = NULL; | |
19134 | ||
caac4577 JG |
19135 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
19136 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
19137 | && !dwarf2_per_objfile->has_section_at_zero) | |
19138 | { | |
19139 | /* When a static variable is eliminated by the linker, | |
19140 | the corresponding debug information is not stripped | |
19141 | out, but the variable address is set to null; | |
19142 | do not add such variables into symbol table. */ | |
19143 | } | |
19144 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 19145 | { |
f55ee35c JK |
19146 | /* Workaround gfortran PR debug/40040 - it uses |
19147 | DW_AT_location for variables in -fPIC libraries which may | |
19148 | get overriden by other libraries/executable and get | |
19149 | a different address. Resolve it by the minimal symbol | |
19150 | which may come from inferior's executable using copy | |
19151 | relocation. Make this workaround only for gfortran as for | |
19152 | other compilers GDB cannot guess the minimal symbol | |
19153 | Fortran mangling kind. */ | |
19154 | if (cu->language == language_fortran && die->parent | |
19155 | && die->parent->tag == DW_TAG_module | |
19156 | && cu->producer | |
28586665 | 19157 | && startswith (cu->producer, "GNU Fortran")) |
f1e6e072 | 19158 | SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED; |
f55ee35c | 19159 | |
1c809c68 TT |
19160 | /* A variable with DW_AT_external is never static, |
19161 | but it may be block-scoped. */ | |
19162 | list_to_add = (cu->list_in_scope == &file_symbols | |
19163 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 19164 | } |
c906108c | 19165 | else |
e37fd15a | 19166 | list_to_add = cu->list_in_scope; |
c906108c SS |
19167 | } |
19168 | else | |
19169 | { | |
19170 | /* We do not know the address of this symbol. | |
c5aa993b JM |
19171 | If it is an external symbol and we have type information |
19172 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
19173 | The address of the variable will then be determined from | |
19174 | the minimal symbol table whenever the variable is | |
19175 | referenced. */ | |
e142c38c | 19176 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
0971de02 TT |
19177 | |
19178 | /* Fortran explicitly imports any global symbols to the local | |
19179 | scope by DW_TAG_common_block. */ | |
19180 | if (cu->language == language_fortran && die->parent | |
19181 | && die->parent->tag == DW_TAG_common_block) | |
19182 | { | |
19183 | /* SYMBOL_CLASS doesn't matter here because | |
19184 | read_common_block is going to reset it. */ | |
19185 | if (!suppress_add) | |
19186 | list_to_add = cu->list_in_scope; | |
19187 | } | |
19188 | else if (attr2 && (DW_UNSND (attr2) != 0) | |
19189 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) | |
c906108c | 19190 | { |
0fe7935b DJ |
19191 | /* A variable with DW_AT_external is never static, but it |
19192 | may be block-scoped. */ | |
19193 | list_to_add = (cu->list_in_scope == &file_symbols | |
19194 | ? &global_symbols : cu->list_in_scope); | |
19195 | ||
f1e6e072 | 19196 | SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED; |
c906108c | 19197 | } |
442ddf59 JK |
19198 | else if (!die_is_declaration (die, cu)) |
19199 | { | |
19200 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
19201 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
19202 | if (!suppress_add) |
19203 | list_to_add = cu->list_in_scope; | |
442ddf59 | 19204 | } |
c906108c SS |
19205 | } |
19206 | break; | |
19207 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
19208 | /* If we are inside a function, mark this as an argument. If |
19209 | not, we might be looking at an argument to an inlined function | |
19210 | when we do not have enough information to show inlined frames; | |
19211 | pretend it's a local variable in that case so that the user can | |
19212 | still see it. */ | |
19213 | if (context_stack_depth > 0 | |
19214 | && context_stack[context_stack_depth - 1].name != NULL) | |
19215 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 19216 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
19217 | if (attr) |
19218 | { | |
e7c27a73 | 19219 | var_decode_location (attr, sym, cu); |
c906108c | 19220 | } |
e142c38c | 19221 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
19222 | if (attr) |
19223 | { | |
e7c27a73 | 19224 | dwarf2_const_value (attr, sym, cu); |
c906108c | 19225 | } |
f346a30d | 19226 | |
e37fd15a | 19227 | list_to_add = cu->list_in_scope; |
c906108c SS |
19228 | break; |
19229 | case DW_TAG_unspecified_parameters: | |
19230 | /* From varargs functions; gdb doesn't seem to have any | |
19231 | interest in this information, so just ignore it for now. | |
19232 | (FIXME?) */ | |
19233 | break; | |
34eaf542 TT |
19234 | case DW_TAG_template_type_param: |
19235 | suppress_add = 1; | |
19236 | /* Fall through. */ | |
c906108c | 19237 | case DW_TAG_class_type: |
680b30c7 | 19238 | case DW_TAG_interface_type: |
c906108c SS |
19239 | case DW_TAG_structure_type: |
19240 | case DW_TAG_union_type: | |
72019c9c | 19241 | case DW_TAG_set_type: |
c906108c | 19242 | case DW_TAG_enumeration_type: |
f1e6e072 | 19243 | SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF; |
176620f1 | 19244 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 19245 | |
63d06c5c | 19246 | { |
9c37b5ae | 19247 | /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't |
63d06c5c DC |
19248 | really ever be static objects: otherwise, if you try |
19249 | to, say, break of a class's method and you're in a file | |
19250 | which doesn't mention that class, it won't work unless | |
19251 | the check for all static symbols in lookup_symbol_aux | |
19252 | saves you. See the OtherFileClass tests in | |
19253 | gdb.c++/namespace.exp. */ | |
19254 | ||
e37fd15a | 19255 | if (!suppress_add) |
34eaf542 | 19256 | { |
34eaf542 | 19257 | list_to_add = (cu->list_in_scope == &file_symbols |
9c37b5ae | 19258 | && cu->language == language_cplus |
34eaf542 | 19259 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 19260 | |
64382290 | 19261 | /* The semantics of C++ state that "struct foo { |
9c37b5ae | 19262 | ... }" also defines a typedef for "foo". */ |
64382290 | 19263 | if (cu->language == language_cplus |
45280282 | 19264 | || cu->language == language_ada |
c44af4eb TT |
19265 | || cu->language == language_d |
19266 | || cu->language == language_rust) | |
64382290 TT |
19267 | { |
19268 | /* The symbol's name is already allocated along | |
19269 | with this objfile, so we don't need to | |
19270 | duplicate it for the type. */ | |
19271 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
19272 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
19273 | } | |
63d06c5c DC |
19274 | } |
19275 | } | |
c906108c SS |
19276 | break; |
19277 | case DW_TAG_typedef: | |
f1e6e072 | 19278 | SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF; |
63d06c5c | 19279 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 19280 | list_to_add = cu->list_in_scope; |
63d06c5c | 19281 | break; |
c906108c | 19282 | case DW_TAG_base_type: |
a02abb62 | 19283 | case DW_TAG_subrange_type: |
f1e6e072 | 19284 | SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF; |
176620f1 | 19285 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 19286 | list_to_add = cu->list_in_scope; |
c906108c SS |
19287 | break; |
19288 | case DW_TAG_enumerator: | |
e142c38c | 19289 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
19290 | if (attr) |
19291 | { | |
e7c27a73 | 19292 | dwarf2_const_value (attr, sym, cu); |
c906108c | 19293 | } |
63d06c5c DC |
19294 | { |
19295 | /* NOTE: carlton/2003-11-10: See comment above in the | |
19296 | DW_TAG_class_type, etc. block. */ | |
19297 | ||
e142c38c | 19298 | list_to_add = (cu->list_in_scope == &file_symbols |
9c37b5ae | 19299 | && cu->language == language_cplus |
e142c38c | 19300 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 19301 | } |
c906108c | 19302 | break; |
74921315 | 19303 | case DW_TAG_imported_declaration: |
5c4e30ca | 19304 | case DW_TAG_namespace: |
f1e6e072 | 19305 | SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF; |
e37fd15a | 19306 | list_to_add = &global_symbols; |
5c4e30ca | 19307 | break; |
530e8392 KB |
19308 | case DW_TAG_module: |
19309 | SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF; | |
19310 | SYMBOL_DOMAIN (sym) = MODULE_DOMAIN; | |
19311 | list_to_add = &global_symbols; | |
19312 | break; | |
4357ac6c | 19313 | case DW_TAG_common_block: |
f1e6e072 | 19314 | SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK; |
4357ac6c TT |
19315 | SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN; |
19316 | add_symbol_to_list (sym, cu->list_in_scope); | |
19317 | break; | |
c906108c SS |
19318 | default: |
19319 | /* Not a tag we recognize. Hopefully we aren't processing | |
19320 | trash data, but since we must specifically ignore things | |
19321 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 19322 | this point. */ |
e2e0b3e5 | 19323 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 19324 | dwarf_tag_name (die->tag)); |
c906108c SS |
19325 | break; |
19326 | } | |
df8a16a1 | 19327 | |
e37fd15a SW |
19328 | if (suppress_add) |
19329 | { | |
19330 | sym->hash_next = objfile->template_symbols; | |
19331 | objfile->template_symbols = sym; | |
19332 | list_to_add = NULL; | |
19333 | } | |
19334 | ||
19335 | if (list_to_add != NULL) | |
19336 | add_symbol_to_list (sym, list_to_add); | |
19337 | ||
df8a16a1 DJ |
19338 | /* For the benefit of old versions of GCC, check for anonymous |
19339 | namespaces based on the demangled name. */ | |
4d4ec4e5 | 19340 | if (!cu->processing_has_namespace_info |
94af9270 | 19341 | && cu->language == language_cplus) |
a10964d1 | 19342 | cp_scan_for_anonymous_namespaces (sym, objfile); |
c906108c SS |
19343 | } |
19344 | return (sym); | |
19345 | } | |
19346 | ||
34eaf542 TT |
19347 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
19348 | ||
19349 | static struct symbol * | |
19350 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
19351 | { | |
19352 | return new_symbol_full (die, type, cu, NULL); | |
19353 | } | |
19354 | ||
98bfdba5 PA |
19355 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
19356 | zero-extend it as appropriate for the symbol's type. The DWARF | |
19357 | standard (v4) is not entirely clear about the meaning of using | |
19358 | DW_FORM_dataN for a constant with a signed type, where the type is | |
19359 | wider than the data. The conclusion of a discussion on the DWARF | |
19360 | list was that this is unspecified. We choose to always zero-extend | |
19361 | because that is the interpretation long in use by GCC. */ | |
c906108c | 19362 | |
98bfdba5 | 19363 | static gdb_byte * |
ff39bb5e | 19364 | dwarf2_const_value_data (const struct attribute *attr, struct obstack *obstack, |
12df843f | 19365 | struct dwarf2_cu *cu, LONGEST *value, int bits) |
c906108c | 19366 | { |
e7c27a73 | 19367 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
19368 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
19369 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
19370 | LONGEST l = DW_UNSND (attr); |
19371 | ||
19372 | if (bits < sizeof (*value) * 8) | |
19373 | { | |
19374 | l &= ((LONGEST) 1 << bits) - 1; | |
19375 | *value = l; | |
19376 | } | |
19377 | else if (bits == sizeof (*value) * 8) | |
19378 | *value = l; | |
19379 | else | |
19380 | { | |
224c3ddb | 19381 | gdb_byte *bytes = (gdb_byte *) obstack_alloc (obstack, bits / 8); |
98bfdba5 PA |
19382 | store_unsigned_integer (bytes, bits / 8, byte_order, l); |
19383 | return bytes; | |
19384 | } | |
19385 | ||
19386 | return NULL; | |
19387 | } | |
19388 | ||
19389 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
19390 | the value does not fit in *VALUE, set *BYTES - either already | |
19391 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
19392 | or, set *BATON, if we translated the constant to a location | |
19393 | expression. */ | |
19394 | ||
19395 | static void | |
ff39bb5e | 19396 | dwarf2_const_value_attr (const struct attribute *attr, struct type *type, |
98bfdba5 PA |
19397 | const char *name, struct obstack *obstack, |
19398 | struct dwarf2_cu *cu, | |
d521ce57 | 19399 | LONGEST *value, const gdb_byte **bytes, |
98bfdba5 PA |
19400 | struct dwarf2_locexpr_baton **baton) |
19401 | { | |
19402 | struct objfile *objfile = cu->objfile; | |
19403 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 19404 | struct dwarf_block *blk; |
98bfdba5 PA |
19405 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
19406 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
19407 | ||
19408 | *value = 0; | |
19409 | *bytes = NULL; | |
19410 | *baton = NULL; | |
c906108c SS |
19411 | |
19412 | switch (attr->form) | |
19413 | { | |
19414 | case DW_FORM_addr: | |
3019eac3 | 19415 | case DW_FORM_GNU_addr_index: |
ac56253d | 19416 | { |
ac56253d TT |
19417 | gdb_byte *data; |
19418 | ||
98bfdba5 PA |
19419 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
19420 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 19421 | cu_header->addr_size, |
98bfdba5 | 19422 | TYPE_LENGTH (type)); |
ac56253d TT |
19423 | /* Symbols of this form are reasonably rare, so we just |
19424 | piggyback on the existing location code rather than writing | |
19425 | a new implementation of symbol_computed_ops. */ | |
8d749320 | 19426 | *baton = XOBNEW (obstack, struct dwarf2_locexpr_baton); |
98bfdba5 PA |
19427 | (*baton)->per_cu = cu->per_cu; |
19428 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 19429 | |
98bfdba5 | 19430 | (*baton)->size = 2 + cu_header->addr_size; |
224c3ddb | 19431 | data = (gdb_byte *) obstack_alloc (obstack, (*baton)->size); |
98bfdba5 | 19432 | (*baton)->data = data; |
ac56253d TT |
19433 | |
19434 | data[0] = DW_OP_addr; | |
19435 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
19436 | byte_order, DW_ADDR (attr)); | |
19437 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 19438 | } |
c906108c | 19439 | break; |
4ac36638 | 19440 | case DW_FORM_string: |
93b5768b | 19441 | case DW_FORM_strp: |
3019eac3 | 19442 | case DW_FORM_GNU_str_index: |
36586728 | 19443 | case DW_FORM_GNU_strp_alt: |
98bfdba5 PA |
19444 | /* DW_STRING is already allocated on the objfile obstack, point |
19445 | directly to it. */ | |
d521ce57 | 19446 | *bytes = (const gdb_byte *) DW_STRING (attr); |
93b5768b | 19447 | break; |
c906108c SS |
19448 | case DW_FORM_block1: |
19449 | case DW_FORM_block2: | |
19450 | case DW_FORM_block4: | |
19451 | case DW_FORM_block: | |
2dc7f7b3 | 19452 | case DW_FORM_exprloc: |
0224619f | 19453 | case DW_FORM_data16: |
c906108c | 19454 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
19455 | if (TYPE_LENGTH (type) != blk->size) |
19456 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
19457 | TYPE_LENGTH (type)); | |
19458 | *bytes = blk->data; | |
c906108c | 19459 | break; |
2df3850c JM |
19460 | |
19461 | /* The DW_AT_const_value attributes are supposed to carry the | |
19462 | symbol's value "represented as it would be on the target | |
19463 | architecture." By the time we get here, it's already been | |
19464 | converted to host endianness, so we just need to sign- or | |
19465 | zero-extend it as appropriate. */ | |
19466 | case DW_FORM_data1: | |
3aef2284 | 19467 | *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 8); |
2df3850c | 19468 | break; |
c906108c | 19469 | case DW_FORM_data2: |
3aef2284 | 19470 | *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 16); |
2df3850c | 19471 | break; |
c906108c | 19472 | case DW_FORM_data4: |
3aef2284 | 19473 | *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 32); |
2df3850c | 19474 | break; |
c906108c | 19475 | case DW_FORM_data8: |
3aef2284 | 19476 | *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 64); |
2df3850c JM |
19477 | break; |
19478 | ||
c906108c | 19479 | case DW_FORM_sdata: |
98bfdba5 | 19480 | *value = DW_SND (attr); |
2df3850c JM |
19481 | break; |
19482 | ||
c906108c | 19483 | case DW_FORM_udata: |
98bfdba5 | 19484 | *value = DW_UNSND (attr); |
c906108c | 19485 | break; |
2df3850c | 19486 | |
c906108c | 19487 | default: |
4d3c2250 | 19488 | complaint (&symfile_complaints, |
e2e0b3e5 | 19489 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 19490 | dwarf_form_name (attr->form)); |
98bfdba5 | 19491 | *value = 0; |
c906108c SS |
19492 | break; |
19493 | } | |
19494 | } | |
19495 | ||
2df3850c | 19496 | |
98bfdba5 PA |
19497 | /* Copy constant value from an attribute to a symbol. */ |
19498 | ||
2df3850c | 19499 | static void |
ff39bb5e | 19500 | dwarf2_const_value (const struct attribute *attr, struct symbol *sym, |
98bfdba5 | 19501 | struct dwarf2_cu *cu) |
2df3850c | 19502 | { |
98bfdba5 | 19503 | struct objfile *objfile = cu->objfile; |
12df843f | 19504 | LONGEST value; |
d521ce57 | 19505 | const gdb_byte *bytes; |
98bfdba5 | 19506 | struct dwarf2_locexpr_baton *baton; |
2df3850c | 19507 | |
98bfdba5 PA |
19508 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
19509 | SYMBOL_PRINT_NAME (sym), | |
19510 | &objfile->objfile_obstack, cu, | |
19511 | &value, &bytes, &baton); | |
2df3850c | 19512 | |
98bfdba5 PA |
19513 | if (baton != NULL) |
19514 | { | |
98bfdba5 | 19515 | SYMBOL_LOCATION_BATON (sym) = baton; |
f1e6e072 | 19516 | SYMBOL_ACLASS_INDEX (sym) = dwarf2_locexpr_index; |
98bfdba5 PA |
19517 | } |
19518 | else if (bytes != NULL) | |
19519 | { | |
19520 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
f1e6e072 | 19521 | SYMBOL_ACLASS_INDEX (sym) = LOC_CONST_BYTES; |
98bfdba5 PA |
19522 | } |
19523 | else | |
19524 | { | |
19525 | SYMBOL_VALUE (sym) = value; | |
f1e6e072 | 19526 | SYMBOL_ACLASS_INDEX (sym) = LOC_CONST; |
98bfdba5 | 19527 | } |
2df3850c JM |
19528 | } |
19529 | ||
c906108c SS |
19530 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
19531 | ||
19532 | static struct type * | |
e7c27a73 | 19533 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 19534 | { |
c906108c | 19535 | struct attribute *type_attr; |
c906108c | 19536 | |
e142c38c | 19537 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
19538 | if (!type_attr) |
19539 | { | |
19540 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 19541 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 19542 | } |
348e048f | 19543 | |
673bfd45 | 19544 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
19545 | } |
19546 | ||
b4ba55a1 JB |
19547 | /* True iff CU's producer generates GNAT Ada auxiliary information |
19548 | that allows to find parallel types through that information instead | |
19549 | of having to do expensive parallel lookups by type name. */ | |
19550 | ||
19551 | static int | |
19552 | need_gnat_info (struct dwarf2_cu *cu) | |
19553 | { | |
19554 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
19555 | of GNAT produces this auxiliary information, without any indication | |
19556 | that it is produced. Part of enhancing the FSF version of GNAT | |
19557 | to produce that information will be to put in place an indicator | |
19558 | that we can use in order to determine whether the descriptive type | |
19559 | info is available or not. One suggestion that has been made is | |
19560 | to use a new attribute, attached to the CU die. For now, assume | |
19561 | that the descriptive type info is not available. */ | |
19562 | return 0; | |
19563 | } | |
19564 | ||
b4ba55a1 JB |
19565 | /* Return the auxiliary type of the die in question using its |
19566 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
19567 | attribute is not present. */ | |
19568 | ||
19569 | static struct type * | |
19570 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
19571 | { | |
b4ba55a1 | 19572 | struct attribute *type_attr; |
b4ba55a1 JB |
19573 | |
19574 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
19575 | if (!type_attr) | |
19576 | return NULL; | |
19577 | ||
673bfd45 | 19578 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
19579 | } |
19580 | ||
19581 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
19582 | descriptive type accordingly. */ | |
19583 | ||
19584 | static void | |
19585 | set_descriptive_type (struct type *type, struct die_info *die, | |
19586 | struct dwarf2_cu *cu) | |
19587 | { | |
19588 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
19589 | ||
19590 | if (descriptive_type) | |
19591 | { | |
19592 | ALLOCATE_GNAT_AUX_TYPE (type); | |
19593 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
19594 | } | |
19595 | } | |
19596 | ||
c906108c SS |
19597 | /* Return the containing type of the die in question using its |
19598 | DW_AT_containing_type attribute. */ | |
19599 | ||
19600 | static struct type * | |
e7c27a73 | 19601 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 19602 | { |
c906108c | 19603 | struct attribute *type_attr; |
c906108c | 19604 | |
e142c38c | 19605 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
19606 | if (!type_attr) |
19607 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
4262abfb | 19608 | "[in module %s]"), objfile_name (cu->objfile)); |
33ac96f0 | 19609 | |
673bfd45 | 19610 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
19611 | } |
19612 | ||
ac9ec31b DE |
19613 | /* Return an error marker type to use for the ill formed type in DIE/CU. */ |
19614 | ||
19615 | static struct type * | |
19616 | build_error_marker_type (struct dwarf2_cu *cu, struct die_info *die) | |
19617 | { | |
19618 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
19619 | char *message, *saved; | |
19620 | ||
19621 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
4262abfb | 19622 | objfile_name (objfile), |
9c541725 PA |
19623 | to_underlying (cu->header.sect_off), |
19624 | to_underlying (die->sect_off)); | |
224c3ddb SM |
19625 | saved = (char *) obstack_copy0 (&objfile->objfile_obstack, |
19626 | message, strlen (message)); | |
ac9ec31b DE |
19627 | xfree (message); |
19628 | ||
19f392bc | 19629 | return init_type (objfile, TYPE_CODE_ERROR, 0, saved); |
ac9ec31b DE |
19630 | } |
19631 | ||
673bfd45 | 19632 | /* Look up the type of DIE in CU using its type attribute ATTR. |
ac9ec31b DE |
19633 | ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type, |
19634 | DW_AT_containing_type. | |
673bfd45 DE |
19635 | If there is no type substitute an error marker. */ |
19636 | ||
c906108c | 19637 | static struct type * |
ff39bb5e | 19638 | lookup_die_type (struct die_info *die, const struct attribute *attr, |
673bfd45 | 19639 | struct dwarf2_cu *cu) |
c906108c | 19640 | { |
bb5ed363 | 19641 | struct objfile *objfile = cu->objfile; |
f792889a DJ |
19642 | struct type *this_type; |
19643 | ||
ac9ec31b DE |
19644 | gdb_assert (attr->name == DW_AT_type |
19645 | || attr->name == DW_AT_GNAT_descriptive_type | |
19646 | || attr->name == DW_AT_containing_type); | |
19647 | ||
673bfd45 DE |
19648 | /* First see if we have it cached. */ |
19649 | ||
36586728 TT |
19650 | if (attr->form == DW_FORM_GNU_ref_alt) |
19651 | { | |
19652 | struct dwarf2_per_cu_data *per_cu; | |
9c541725 | 19653 | sect_offset sect_off = dwarf2_get_ref_die_offset (attr); |
36586728 | 19654 | |
9c541725 PA |
19655 | per_cu = dwarf2_find_containing_comp_unit (sect_off, 1, cu->objfile); |
19656 | this_type = get_die_type_at_offset (sect_off, per_cu); | |
36586728 | 19657 | } |
7771576e | 19658 | else if (attr_form_is_ref (attr)) |
673bfd45 | 19659 | { |
9c541725 | 19660 | sect_offset sect_off = dwarf2_get_ref_die_offset (attr); |
673bfd45 | 19661 | |
9c541725 | 19662 | this_type = get_die_type_at_offset (sect_off, cu->per_cu); |
673bfd45 | 19663 | } |
55f1336d | 19664 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 | 19665 | { |
ac9ec31b | 19666 | ULONGEST signature = DW_SIGNATURE (attr); |
673bfd45 | 19667 | |
ac9ec31b | 19668 | return get_signatured_type (die, signature, cu); |
673bfd45 DE |
19669 | } |
19670 | else | |
19671 | { | |
ac9ec31b DE |
19672 | complaint (&symfile_complaints, |
19673 | _("Dwarf Error: Bad type attribute %s in DIE" | |
19674 | " at 0x%x [in module %s]"), | |
9c541725 | 19675 | dwarf_attr_name (attr->name), to_underlying (die->sect_off), |
4262abfb | 19676 | objfile_name (objfile)); |
ac9ec31b | 19677 | return build_error_marker_type (cu, die); |
673bfd45 DE |
19678 | } |
19679 | ||
19680 | /* If not cached we need to read it in. */ | |
19681 | ||
19682 | if (this_type == NULL) | |
19683 | { | |
ac9ec31b | 19684 | struct die_info *type_die = NULL; |
673bfd45 DE |
19685 | struct dwarf2_cu *type_cu = cu; |
19686 | ||
7771576e | 19687 | if (attr_form_is_ref (attr)) |
ac9ec31b DE |
19688 | type_die = follow_die_ref (die, attr, &type_cu); |
19689 | if (type_die == NULL) | |
19690 | return build_error_marker_type (cu, die); | |
19691 | /* If we find the type now, it's probably because the type came | |
3019eac3 DE |
19692 | from an inter-CU reference and the type's CU got expanded before |
19693 | ours. */ | |
ac9ec31b | 19694 | this_type = read_type_die (type_die, type_cu); |
673bfd45 DE |
19695 | } |
19696 | ||
19697 | /* If we still don't have a type use an error marker. */ | |
19698 | ||
19699 | if (this_type == NULL) | |
ac9ec31b | 19700 | return build_error_marker_type (cu, die); |
673bfd45 | 19701 | |
f792889a | 19702 | return this_type; |
c906108c SS |
19703 | } |
19704 | ||
673bfd45 DE |
19705 | /* Return the type in DIE, CU. |
19706 | Returns NULL for invalid types. | |
19707 | ||
02142a6c | 19708 | This first does a lookup in die_type_hash, |
673bfd45 DE |
19709 | and only reads the die in if necessary. |
19710 | ||
19711 | NOTE: This can be called when reading in partial or full symbols. */ | |
19712 | ||
f792889a | 19713 | static struct type * |
e7c27a73 | 19714 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 19715 | { |
f792889a DJ |
19716 | struct type *this_type; |
19717 | ||
19718 | this_type = get_die_type (die, cu); | |
19719 | if (this_type) | |
19720 | return this_type; | |
19721 | ||
673bfd45 DE |
19722 | return read_type_die_1 (die, cu); |
19723 | } | |
19724 | ||
19725 | /* Read the type in DIE, CU. | |
19726 | Returns NULL for invalid types. */ | |
19727 | ||
19728 | static struct type * | |
19729 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
19730 | { | |
19731 | struct type *this_type = NULL; | |
19732 | ||
c906108c SS |
19733 | switch (die->tag) |
19734 | { | |
19735 | case DW_TAG_class_type: | |
680b30c7 | 19736 | case DW_TAG_interface_type: |
c906108c SS |
19737 | case DW_TAG_structure_type: |
19738 | case DW_TAG_union_type: | |
f792889a | 19739 | this_type = read_structure_type (die, cu); |
c906108c SS |
19740 | break; |
19741 | case DW_TAG_enumeration_type: | |
f792889a | 19742 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
19743 | break; |
19744 | case DW_TAG_subprogram: | |
19745 | case DW_TAG_subroutine_type: | |
edb3359d | 19746 | case DW_TAG_inlined_subroutine: |
f792889a | 19747 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
19748 | break; |
19749 | case DW_TAG_array_type: | |
f792889a | 19750 | this_type = read_array_type (die, cu); |
c906108c | 19751 | break; |
72019c9c | 19752 | case DW_TAG_set_type: |
f792889a | 19753 | this_type = read_set_type (die, cu); |
72019c9c | 19754 | break; |
c906108c | 19755 | case DW_TAG_pointer_type: |
f792889a | 19756 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
19757 | break; |
19758 | case DW_TAG_ptr_to_member_type: | |
f792889a | 19759 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
19760 | break; |
19761 | case DW_TAG_reference_type: | |
4297a3f0 AV |
19762 | this_type = read_tag_reference_type (die, cu, TYPE_CODE_REF); |
19763 | break; | |
19764 | case DW_TAG_rvalue_reference_type: | |
19765 | this_type = read_tag_reference_type (die, cu, TYPE_CODE_RVALUE_REF); | |
c906108c SS |
19766 | break; |
19767 | case DW_TAG_const_type: | |
f792889a | 19768 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
19769 | break; |
19770 | case DW_TAG_volatile_type: | |
f792889a | 19771 | this_type = read_tag_volatile_type (die, cu); |
c906108c | 19772 | break; |
06d66ee9 TT |
19773 | case DW_TAG_restrict_type: |
19774 | this_type = read_tag_restrict_type (die, cu); | |
19775 | break; | |
c906108c | 19776 | case DW_TAG_string_type: |
f792889a | 19777 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
19778 | break; |
19779 | case DW_TAG_typedef: | |
f792889a | 19780 | this_type = read_typedef (die, cu); |
c906108c | 19781 | break; |
a02abb62 | 19782 | case DW_TAG_subrange_type: |
f792889a | 19783 | this_type = read_subrange_type (die, cu); |
a02abb62 | 19784 | break; |
c906108c | 19785 | case DW_TAG_base_type: |
f792889a | 19786 | this_type = read_base_type (die, cu); |
c906108c | 19787 | break; |
81a17f79 | 19788 | case DW_TAG_unspecified_type: |
f792889a | 19789 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 19790 | break; |
0114d602 DJ |
19791 | case DW_TAG_namespace: |
19792 | this_type = read_namespace_type (die, cu); | |
19793 | break; | |
f55ee35c JK |
19794 | case DW_TAG_module: |
19795 | this_type = read_module_type (die, cu); | |
19796 | break; | |
a2c2acaf MW |
19797 | case DW_TAG_atomic_type: |
19798 | this_type = read_tag_atomic_type (die, cu); | |
19799 | break; | |
c906108c | 19800 | default: |
3e43a32a MS |
19801 | complaint (&symfile_complaints, |
19802 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 19803 | dwarf_tag_name (die->tag)); |
c906108c SS |
19804 | break; |
19805 | } | |
63d06c5c | 19806 | |
f792889a | 19807 | return this_type; |
63d06c5c DC |
19808 | } |
19809 | ||
abc72ce4 DE |
19810 | /* See if we can figure out if the class lives in a namespace. We do |
19811 | this by looking for a member function; its demangled name will | |
19812 | contain namespace info, if there is any. | |
19813 | Return the computed name or NULL. | |
19814 | Space for the result is allocated on the objfile's obstack. | |
19815 | This is the full-die version of guess_partial_die_structure_name. | |
19816 | In this case we know DIE has no useful parent. */ | |
19817 | ||
19818 | static char * | |
19819 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
19820 | { | |
19821 | struct die_info *spec_die; | |
19822 | struct dwarf2_cu *spec_cu; | |
19823 | struct die_info *child; | |
19824 | ||
19825 | spec_cu = cu; | |
19826 | spec_die = die_specification (die, &spec_cu); | |
19827 | if (spec_die != NULL) | |
19828 | { | |
19829 | die = spec_die; | |
19830 | cu = spec_cu; | |
19831 | } | |
19832 | ||
19833 | for (child = die->child; | |
19834 | child != NULL; | |
19835 | child = child->sibling) | |
19836 | { | |
19837 | if (child->tag == DW_TAG_subprogram) | |
19838 | { | |
7d45c7c3 | 19839 | const char *linkage_name; |
abc72ce4 | 19840 | |
7d45c7c3 KB |
19841 | linkage_name = dwarf2_string_attr (child, DW_AT_linkage_name, cu); |
19842 | if (linkage_name == NULL) | |
19843 | linkage_name = dwarf2_string_attr (child, DW_AT_MIPS_linkage_name, | |
19844 | cu); | |
19845 | if (linkage_name != NULL) | |
abc72ce4 DE |
19846 | { |
19847 | char *actual_name | |
19848 | = language_class_name_from_physname (cu->language_defn, | |
7d45c7c3 | 19849 | linkage_name); |
abc72ce4 DE |
19850 | char *name = NULL; |
19851 | ||
19852 | if (actual_name != NULL) | |
19853 | { | |
15d034d0 | 19854 | const char *die_name = dwarf2_name (die, cu); |
abc72ce4 DE |
19855 | |
19856 | if (die_name != NULL | |
19857 | && strcmp (die_name, actual_name) != 0) | |
19858 | { | |
19859 | /* Strip off the class name from the full name. | |
19860 | We want the prefix. */ | |
19861 | int die_name_len = strlen (die_name); | |
19862 | int actual_name_len = strlen (actual_name); | |
19863 | ||
19864 | /* Test for '::' as a sanity check. */ | |
19865 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
19866 | && actual_name[actual_name_len |
19867 | - die_name_len - 1] == ':') | |
224c3ddb SM |
19868 | name = (char *) obstack_copy0 ( |
19869 | &cu->objfile->per_bfd->storage_obstack, | |
19870 | actual_name, actual_name_len - die_name_len - 2); | |
abc72ce4 DE |
19871 | } |
19872 | } | |
19873 | xfree (actual_name); | |
19874 | return name; | |
19875 | } | |
19876 | } | |
19877 | } | |
19878 | ||
19879 | return NULL; | |
19880 | } | |
19881 | ||
96408a79 SA |
19882 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
19883 | prefix part in such case. See | |
19884 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
19885 | ||
a121b7c1 | 19886 | static const char * |
96408a79 SA |
19887 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) |
19888 | { | |
19889 | struct attribute *attr; | |
e6a959d6 | 19890 | const char *base; |
96408a79 SA |
19891 | |
19892 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type | |
19893 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) | |
19894 | return NULL; | |
19895 | ||
7d45c7c3 | 19896 | if (dwarf2_string_attr (die, DW_AT_name, cu) != NULL) |
96408a79 SA |
19897 | return NULL; |
19898 | ||
19899 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
19900 | if (attr == NULL) | |
19901 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
19902 | if (attr == NULL || DW_STRING (attr) == NULL) | |
19903 | return NULL; | |
19904 | ||
19905 | /* dwarf2_name had to be already called. */ | |
19906 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); | |
19907 | ||
19908 | /* Strip the base name, keep any leading namespaces/classes. */ | |
19909 | base = strrchr (DW_STRING (attr), ':'); | |
19910 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') | |
19911 | return ""; | |
19912 | ||
224c3ddb SM |
19913 | return (char *) obstack_copy0 (&cu->objfile->per_bfd->storage_obstack, |
19914 | DW_STRING (attr), | |
19915 | &base[-1] - DW_STRING (attr)); | |
96408a79 SA |
19916 | } |
19917 | ||
fdde2d81 | 19918 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 19919 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 19920 | |
0114d602 DJ |
19921 | For example, if we're within the method foo() in the following |
19922 | code: | |
19923 | ||
19924 | namespace N { | |
19925 | class C { | |
19926 | void foo () { | |
19927 | } | |
19928 | }; | |
19929 | } | |
19930 | ||
19931 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 | 19932 | |
0d5cff50 | 19933 | static const char * |
e142c38c | 19934 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 19935 | { |
0114d602 DJ |
19936 | struct die_info *parent, *spec_die; |
19937 | struct dwarf2_cu *spec_cu; | |
19938 | struct type *parent_type; | |
a121b7c1 | 19939 | const char *retval; |
63d06c5c | 19940 | |
9c37b5ae | 19941 | if (cu->language != language_cplus |
c44af4eb TT |
19942 | && cu->language != language_fortran && cu->language != language_d |
19943 | && cu->language != language_rust) | |
0114d602 DJ |
19944 | return ""; |
19945 | ||
96408a79 SA |
19946 | retval = anonymous_struct_prefix (die, cu); |
19947 | if (retval) | |
19948 | return retval; | |
19949 | ||
0114d602 DJ |
19950 | /* We have to be careful in the presence of DW_AT_specification. |
19951 | For example, with GCC 3.4, given the code | |
19952 | ||
19953 | namespace N { | |
19954 | void foo() { | |
19955 | // Definition of N::foo. | |
19956 | } | |
19957 | } | |
19958 | ||
19959 | then we'll have a tree of DIEs like this: | |
19960 | ||
19961 | 1: DW_TAG_compile_unit | |
19962 | 2: DW_TAG_namespace // N | |
19963 | 3: DW_TAG_subprogram // declaration of N::foo | |
19964 | 4: DW_TAG_subprogram // definition of N::foo | |
19965 | DW_AT_specification // refers to die #3 | |
19966 | ||
19967 | Thus, when processing die #4, we have to pretend that we're in | |
19968 | the context of its DW_AT_specification, namely the contex of die | |
19969 | #3. */ | |
19970 | spec_cu = cu; | |
19971 | spec_die = die_specification (die, &spec_cu); | |
19972 | if (spec_die == NULL) | |
19973 | parent = die->parent; | |
19974 | else | |
63d06c5c | 19975 | { |
0114d602 DJ |
19976 | parent = spec_die->parent; |
19977 | cu = spec_cu; | |
63d06c5c | 19978 | } |
0114d602 DJ |
19979 | |
19980 | if (parent == NULL) | |
19981 | return ""; | |
98bfdba5 PA |
19982 | else if (parent->building_fullname) |
19983 | { | |
19984 | const char *name; | |
19985 | const char *parent_name; | |
19986 | ||
19987 | /* It has been seen on RealView 2.2 built binaries, | |
19988 | DW_TAG_template_type_param types actually _defined_ as | |
19989 | children of the parent class: | |
19990 | ||
19991 | enum E {}; | |
19992 | template class <class Enum> Class{}; | |
19993 | Class<enum E> class_e; | |
19994 | ||
19995 | 1: DW_TAG_class_type (Class) | |
19996 | 2: DW_TAG_enumeration_type (E) | |
19997 | 3: DW_TAG_enumerator (enum1:0) | |
19998 | 3: DW_TAG_enumerator (enum2:1) | |
19999 | ... | |
20000 | 2: DW_TAG_template_type_param | |
20001 | DW_AT_type DW_FORM_ref_udata (E) | |
20002 | ||
20003 | Besides being broken debug info, it can put GDB into an | |
20004 | infinite loop. Consider: | |
20005 | ||
20006 | When we're building the full name for Class<E>, we'll start | |
20007 | at Class, and go look over its template type parameters, | |
20008 | finding E. We'll then try to build the full name of E, and | |
20009 | reach here. We're now trying to build the full name of E, | |
20010 | and look over the parent DIE for containing scope. In the | |
20011 | broken case, if we followed the parent DIE of E, we'd again | |
20012 | find Class, and once again go look at its template type | |
20013 | arguments, etc., etc. Simply don't consider such parent die | |
20014 | as source-level parent of this die (it can't be, the language | |
20015 | doesn't allow it), and break the loop here. */ | |
20016 | name = dwarf2_name (die, cu); | |
20017 | parent_name = dwarf2_name (parent, cu); | |
20018 | complaint (&symfile_complaints, | |
20019 | _("template param type '%s' defined within parent '%s'"), | |
20020 | name ? name : "<unknown>", | |
20021 | parent_name ? parent_name : "<unknown>"); | |
20022 | return ""; | |
20023 | } | |
63d06c5c | 20024 | else |
0114d602 DJ |
20025 | switch (parent->tag) |
20026 | { | |
63d06c5c | 20027 | case DW_TAG_namespace: |
0114d602 | 20028 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
20029 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
20030 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
20031 | Work around this problem here. */ | |
20032 | if (cu->language == language_cplus | |
20033 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
20034 | return ""; | |
0114d602 DJ |
20035 | /* We give a name to even anonymous namespaces. */ |
20036 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 20037 | case DW_TAG_class_type: |
680b30c7 | 20038 | case DW_TAG_interface_type: |
63d06c5c | 20039 | case DW_TAG_structure_type: |
0114d602 | 20040 | case DW_TAG_union_type: |
f55ee35c | 20041 | case DW_TAG_module: |
0114d602 DJ |
20042 | parent_type = read_type_die (parent, cu); |
20043 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
20044 | return TYPE_TAG_NAME (parent_type); | |
20045 | else | |
20046 | /* An anonymous structure is only allowed non-static data | |
20047 | members; no typedefs, no member functions, et cetera. | |
20048 | So it does not need a prefix. */ | |
20049 | return ""; | |
abc72ce4 | 20050 | case DW_TAG_compile_unit: |
95554aad | 20051 | case DW_TAG_partial_unit: |
abc72ce4 DE |
20052 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ |
20053 | if (cu->language == language_cplus | |
8b70b953 | 20054 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
20055 | && die->child != NULL |
20056 | && (die->tag == DW_TAG_class_type | |
20057 | || die->tag == DW_TAG_structure_type | |
20058 | || die->tag == DW_TAG_union_type)) | |
20059 | { | |
20060 | char *name = guess_full_die_structure_name (die, cu); | |
20061 | if (name != NULL) | |
20062 | return name; | |
20063 | } | |
20064 | return ""; | |
3d567982 TT |
20065 | case DW_TAG_enumeration_type: |
20066 | parent_type = read_type_die (parent, cu); | |
20067 | if (TYPE_DECLARED_CLASS (parent_type)) | |
20068 | { | |
20069 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
20070 | return TYPE_TAG_NAME (parent_type); | |
20071 | return ""; | |
20072 | } | |
20073 | /* Fall through. */ | |
63d06c5c | 20074 | default: |
8176b9b8 | 20075 | return determine_prefix (parent, cu); |
63d06c5c | 20076 | } |
63d06c5c DC |
20077 | } |
20078 | ||
3e43a32a MS |
20079 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
20080 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
20081 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
20082 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
20083 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 20084 | |
f55ee35c | 20085 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
20086 | |
20087 | static char * | |
f55ee35c JK |
20088 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
20089 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 20090 | { |
f55ee35c | 20091 | const char *lead = ""; |
5c315b68 | 20092 | const char *sep; |
63d06c5c | 20093 | |
3e43a32a MS |
20094 | if (suffix == NULL || suffix[0] == '\0' |
20095 | || prefix == NULL || prefix[0] == '\0') | |
987504bb | 20096 | sep = ""; |
45280282 IB |
20097 | else if (cu->language == language_d) |
20098 | { | |
20099 | /* For D, the 'main' function could be defined in any module, but it | |
20100 | should never be prefixed. */ | |
20101 | if (strcmp (suffix, "D main") == 0) | |
20102 | { | |
20103 | prefix = ""; | |
20104 | sep = ""; | |
20105 | } | |
20106 | else | |
20107 | sep = "."; | |
20108 | } | |
f55ee35c JK |
20109 | else if (cu->language == language_fortran && physname) |
20110 | { | |
20111 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
20112 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
20113 | ||
20114 | lead = "__"; | |
20115 | sep = "_MOD_"; | |
20116 | } | |
987504bb JJ |
20117 | else |
20118 | sep = "::"; | |
63d06c5c | 20119 | |
6dd47d34 DE |
20120 | if (prefix == NULL) |
20121 | prefix = ""; | |
20122 | if (suffix == NULL) | |
20123 | suffix = ""; | |
20124 | ||
987504bb JJ |
20125 | if (obs == NULL) |
20126 | { | |
3e43a32a | 20127 | char *retval |
224c3ddb SM |
20128 | = ((char *) |
20129 | xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1)); | |
9a619af0 | 20130 | |
f55ee35c JK |
20131 | strcpy (retval, lead); |
20132 | strcat (retval, prefix); | |
6dd47d34 DE |
20133 | strcat (retval, sep); |
20134 | strcat (retval, suffix); | |
63d06c5c DC |
20135 | return retval; |
20136 | } | |
987504bb JJ |
20137 | else |
20138 | { | |
20139 | /* We have an obstack. */ | |
f55ee35c | 20140 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 20141 | } |
63d06c5c DC |
20142 | } |
20143 | ||
c906108c SS |
20144 | /* Return sibling of die, NULL if no sibling. */ |
20145 | ||
f9aca02d | 20146 | static struct die_info * |
fba45db2 | 20147 | sibling_die (struct die_info *die) |
c906108c | 20148 | { |
639d11d3 | 20149 | return die->sibling; |
c906108c SS |
20150 | } |
20151 | ||
71c25dea TT |
20152 | /* Get name of a die, return NULL if not found. */ |
20153 | ||
15d034d0 TT |
20154 | static const char * |
20155 | dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu, | |
71c25dea TT |
20156 | struct obstack *obstack) |
20157 | { | |
20158 | if (name && cu->language == language_cplus) | |
20159 | { | |
2f408ecb | 20160 | std::string canon_name = cp_canonicalize_string (name); |
71c25dea | 20161 | |
2f408ecb | 20162 | if (!canon_name.empty ()) |
71c25dea | 20163 | { |
2f408ecb PA |
20164 | if (canon_name != name) |
20165 | name = (const char *) obstack_copy0 (obstack, | |
20166 | canon_name.c_str (), | |
20167 | canon_name.length ()); | |
71c25dea TT |
20168 | } |
20169 | } | |
20170 | ||
20171 | return name; | |
c906108c SS |
20172 | } |
20173 | ||
96553a0c DE |
20174 | /* Get name of a die, return NULL if not found. |
20175 | Anonymous namespaces are converted to their magic string. */ | |
9219021c | 20176 | |
15d034d0 | 20177 | static const char * |
e142c38c | 20178 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
20179 | { |
20180 | struct attribute *attr; | |
20181 | ||
e142c38c | 20182 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 | 20183 | if ((!attr || !DW_STRING (attr)) |
96553a0c | 20184 | && die->tag != DW_TAG_namespace |
53832f31 TT |
20185 | && die->tag != DW_TAG_class_type |
20186 | && die->tag != DW_TAG_interface_type | |
20187 | && die->tag != DW_TAG_structure_type | |
20188 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
20189 | return NULL; |
20190 | ||
20191 | switch (die->tag) | |
20192 | { | |
20193 | case DW_TAG_compile_unit: | |
95554aad | 20194 | case DW_TAG_partial_unit: |
71c25dea TT |
20195 | /* Compilation units have a DW_AT_name that is a filename, not |
20196 | a source language identifier. */ | |
20197 | case DW_TAG_enumeration_type: | |
20198 | case DW_TAG_enumerator: | |
20199 | /* These tags always have simple identifiers already; no need | |
20200 | to canonicalize them. */ | |
20201 | return DW_STRING (attr); | |
907af001 | 20202 | |
96553a0c DE |
20203 | case DW_TAG_namespace: |
20204 | if (attr != NULL && DW_STRING (attr) != NULL) | |
20205 | return DW_STRING (attr); | |
20206 | return CP_ANONYMOUS_NAMESPACE_STR; | |
20207 | ||
907af001 UW |
20208 | case DW_TAG_class_type: |
20209 | case DW_TAG_interface_type: | |
20210 | case DW_TAG_structure_type: | |
20211 | case DW_TAG_union_type: | |
20212 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
20213 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
20214 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
20215 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 | 20216 | if (attr && DW_STRING (attr) |
61012eef GB |
20217 | && (startswith (DW_STRING (attr), "._") |
20218 | || startswith (DW_STRING (attr), "<anonymous"))) | |
907af001 | 20219 | return NULL; |
53832f31 TT |
20220 | |
20221 | /* GCC might emit a nameless typedef that has a linkage name. See | |
20222 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
20223 | if (!attr || DW_STRING (attr) == NULL) | |
20224 | { | |
df5c6c50 | 20225 | char *demangled = NULL; |
53832f31 TT |
20226 | |
20227 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
20228 | if (attr == NULL) | |
20229 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
20230 | ||
20231 | if (attr == NULL || DW_STRING (attr) == NULL) | |
20232 | return NULL; | |
20233 | ||
df5c6c50 JK |
20234 | /* Avoid demangling DW_STRING (attr) the second time on a second |
20235 | call for the same DIE. */ | |
20236 | if (!DW_STRING_IS_CANONICAL (attr)) | |
8de20a37 | 20237 | demangled = gdb_demangle (DW_STRING (attr), DMGL_TYPES); |
53832f31 TT |
20238 | |
20239 | if (demangled) | |
20240 | { | |
e6a959d6 | 20241 | const char *base; |
96408a79 | 20242 | |
53832f31 | 20243 | /* FIXME: we already did this for the partial symbol... */ |
34a68019 | 20244 | DW_STRING (attr) |
224c3ddb SM |
20245 | = ((const char *) |
20246 | obstack_copy0 (&cu->objfile->per_bfd->storage_obstack, | |
20247 | demangled, strlen (demangled))); | |
53832f31 TT |
20248 | DW_STRING_IS_CANONICAL (attr) = 1; |
20249 | xfree (demangled); | |
96408a79 SA |
20250 | |
20251 | /* Strip any leading namespaces/classes, keep only the base name. | |
20252 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
20253 | base = strrchr (DW_STRING (attr), ':'); | |
20254 | if (base && base > DW_STRING (attr) && base[-1] == ':') | |
20255 | return &base[1]; | |
20256 | else | |
20257 | return DW_STRING (attr); | |
53832f31 TT |
20258 | } |
20259 | } | |
907af001 UW |
20260 | break; |
20261 | ||
71c25dea | 20262 | default: |
907af001 UW |
20263 | break; |
20264 | } | |
20265 | ||
20266 | if (!DW_STRING_IS_CANONICAL (attr)) | |
20267 | { | |
20268 | DW_STRING (attr) | |
20269 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
34a68019 | 20270 | &cu->objfile->per_bfd->storage_obstack); |
907af001 | 20271 | DW_STRING_IS_CANONICAL (attr) = 1; |
71c25dea | 20272 | } |
907af001 | 20273 | return DW_STRING (attr); |
9219021c DC |
20274 | } |
20275 | ||
20276 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
20277 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
20278 | containing the return value on output. */ | |
9219021c DC |
20279 | |
20280 | static struct die_info * | |
f2f0e013 | 20281 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
20282 | { |
20283 | struct attribute *attr; | |
9219021c | 20284 | |
f2f0e013 | 20285 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
20286 | if (attr == NULL) |
20287 | return NULL; | |
20288 | ||
f2f0e013 | 20289 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
20290 | } |
20291 | ||
c906108c SS |
20292 | /* Convert a DIE tag into its string name. */ |
20293 | ||
f39c6ffd | 20294 | static const char * |
aa1ee363 | 20295 | dwarf_tag_name (unsigned tag) |
c906108c | 20296 | { |
f39c6ffd TT |
20297 | const char *name = get_DW_TAG_name (tag); |
20298 | ||
20299 | if (name == NULL) | |
20300 | return "DW_TAG_<unknown>"; | |
20301 | ||
20302 | return name; | |
c906108c SS |
20303 | } |
20304 | ||
20305 | /* Convert a DWARF attribute code into its string name. */ | |
20306 | ||
f39c6ffd | 20307 | static const char * |
aa1ee363 | 20308 | dwarf_attr_name (unsigned attr) |
c906108c | 20309 | { |
f39c6ffd TT |
20310 | const char *name; |
20311 | ||
c764a876 | 20312 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
f39c6ffd TT |
20313 | if (attr == DW_AT_MIPS_fde) |
20314 | return "DW_AT_MIPS_fde"; | |
20315 | #else | |
20316 | if (attr == DW_AT_HP_block_index) | |
20317 | return "DW_AT_HP_block_index"; | |
c764a876 | 20318 | #endif |
f39c6ffd TT |
20319 | |
20320 | name = get_DW_AT_name (attr); | |
20321 | ||
20322 | if (name == NULL) | |
20323 | return "DW_AT_<unknown>"; | |
20324 | ||
20325 | return name; | |
c906108c SS |
20326 | } |
20327 | ||
20328 | /* Convert a DWARF value form code into its string name. */ | |
20329 | ||
f39c6ffd | 20330 | static const char * |
aa1ee363 | 20331 | dwarf_form_name (unsigned form) |
c906108c | 20332 | { |
f39c6ffd TT |
20333 | const char *name = get_DW_FORM_name (form); |
20334 | ||
20335 | if (name == NULL) | |
20336 | return "DW_FORM_<unknown>"; | |
20337 | ||
20338 | return name; | |
c906108c SS |
20339 | } |
20340 | ||
a121b7c1 | 20341 | static const char * |
fba45db2 | 20342 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
20343 | { |
20344 | if (mybool) | |
20345 | return "TRUE"; | |
20346 | else | |
20347 | return "FALSE"; | |
20348 | } | |
20349 | ||
20350 | /* Convert a DWARF type code into its string name. */ | |
20351 | ||
f39c6ffd | 20352 | static const char * |
aa1ee363 | 20353 | dwarf_type_encoding_name (unsigned enc) |
c906108c | 20354 | { |
f39c6ffd | 20355 | const char *name = get_DW_ATE_name (enc); |
c906108c | 20356 | |
f39c6ffd TT |
20357 | if (name == NULL) |
20358 | return "DW_ATE_<unknown>"; | |
c906108c | 20359 | |
f39c6ffd | 20360 | return name; |
c906108c | 20361 | } |
c906108c | 20362 | |
f9aca02d | 20363 | static void |
d97bc12b | 20364 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
20365 | { |
20366 | unsigned int i; | |
20367 | ||
d97bc12b DE |
20368 | print_spaces (indent, f); |
20369 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
9c541725 PA |
20370 | dwarf_tag_name (die->tag), die->abbrev, |
20371 | to_underlying (die->sect_off)); | |
d97bc12b DE |
20372 | |
20373 | if (die->parent != NULL) | |
20374 | { | |
20375 | print_spaces (indent, f); | |
20376 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
9c541725 | 20377 | to_underlying (die->parent->sect_off)); |
d97bc12b DE |
20378 | } |
20379 | ||
20380 | print_spaces (indent, f); | |
20381 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 20382 | dwarf_bool_name (die->child != NULL)); |
c906108c | 20383 | |
d97bc12b DE |
20384 | print_spaces (indent, f); |
20385 | fprintf_unfiltered (f, " attributes:\n"); | |
20386 | ||
c906108c SS |
20387 | for (i = 0; i < die->num_attrs; ++i) |
20388 | { | |
d97bc12b DE |
20389 | print_spaces (indent, f); |
20390 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
20391 | dwarf_attr_name (die->attrs[i].name), |
20392 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 20393 | |
c906108c SS |
20394 | switch (die->attrs[i].form) |
20395 | { | |
c906108c | 20396 | case DW_FORM_addr: |
3019eac3 | 20397 | case DW_FORM_GNU_addr_index: |
d97bc12b | 20398 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 20399 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
20400 | break; |
20401 | case DW_FORM_block2: | |
20402 | case DW_FORM_block4: | |
20403 | case DW_FORM_block: | |
20404 | case DW_FORM_block1: | |
56eb65bd SP |
20405 | fprintf_unfiltered (f, "block: size %s", |
20406 | pulongest (DW_BLOCK (&die->attrs[i])->size)); | |
c906108c | 20407 | break; |
2dc7f7b3 | 20408 | case DW_FORM_exprloc: |
56eb65bd SP |
20409 | fprintf_unfiltered (f, "expression: size %s", |
20410 | pulongest (DW_BLOCK (&die->attrs[i])->size)); | |
2dc7f7b3 | 20411 | break; |
0224619f JK |
20412 | case DW_FORM_data16: |
20413 | fprintf_unfiltered (f, "constant of 16 bytes"); | |
20414 | break; | |
4568ecf9 DE |
20415 | case DW_FORM_ref_addr: |
20416 | fprintf_unfiltered (f, "ref address: "); | |
20417 | fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f); | |
20418 | break; | |
36586728 TT |
20419 | case DW_FORM_GNU_ref_alt: |
20420 | fprintf_unfiltered (f, "alt ref address: "); | |
20421 | fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f); | |
20422 | break; | |
10b3939b DJ |
20423 | case DW_FORM_ref1: |
20424 | case DW_FORM_ref2: | |
20425 | case DW_FORM_ref4: | |
4568ecf9 DE |
20426 | case DW_FORM_ref8: |
20427 | case DW_FORM_ref_udata: | |
d97bc12b | 20428 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
4568ecf9 | 20429 | (long) (DW_UNSND (&die->attrs[i]))); |
10b3939b | 20430 | break; |
c906108c SS |
20431 | case DW_FORM_data1: |
20432 | case DW_FORM_data2: | |
20433 | case DW_FORM_data4: | |
ce5d95e1 | 20434 | case DW_FORM_data8: |
c906108c SS |
20435 | case DW_FORM_udata: |
20436 | case DW_FORM_sdata: | |
43bbcdc2 PH |
20437 | fprintf_unfiltered (f, "constant: %s", |
20438 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 20439 | break; |
2dc7f7b3 TT |
20440 | case DW_FORM_sec_offset: |
20441 | fprintf_unfiltered (f, "section offset: %s", | |
20442 | pulongest (DW_UNSND (&die->attrs[i]))); | |
20443 | break; | |
55f1336d | 20444 | case DW_FORM_ref_sig8: |
ac9ec31b DE |
20445 | fprintf_unfiltered (f, "signature: %s", |
20446 | hex_string (DW_SIGNATURE (&die->attrs[i]))); | |
348e048f | 20447 | break; |
c906108c | 20448 | case DW_FORM_string: |
4bdf3d34 | 20449 | case DW_FORM_strp: |
43988095 | 20450 | case DW_FORM_line_strp: |
3019eac3 | 20451 | case DW_FORM_GNU_str_index: |
36586728 | 20452 | case DW_FORM_GNU_strp_alt: |
8285870a | 20453 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 20454 | DW_STRING (&die->attrs[i]) |
8285870a JK |
20455 | ? DW_STRING (&die->attrs[i]) : "", |
20456 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
20457 | break; |
20458 | case DW_FORM_flag: | |
20459 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 20460 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 20461 | else |
d97bc12b | 20462 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 20463 | break; |
2dc7f7b3 TT |
20464 | case DW_FORM_flag_present: |
20465 | fprintf_unfiltered (f, "flag: TRUE"); | |
20466 | break; | |
a8329558 | 20467 | case DW_FORM_indirect: |
0963b4bd MS |
20468 | /* The reader will have reduced the indirect form to |
20469 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
20470 | fprintf_unfiltered (f, |
20471 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 20472 | break; |
c906108c | 20473 | default: |
d97bc12b | 20474 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 20475 | die->attrs[i].form); |
d97bc12b | 20476 | break; |
c906108c | 20477 | } |
d97bc12b | 20478 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
20479 | } |
20480 | } | |
20481 | ||
f9aca02d | 20482 | static void |
d97bc12b | 20483 | dump_die_for_error (struct die_info *die) |
c906108c | 20484 | { |
d97bc12b DE |
20485 | dump_die_shallow (gdb_stderr, 0, die); |
20486 | } | |
20487 | ||
20488 | static void | |
20489 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
20490 | { | |
20491 | int indent = level * 4; | |
20492 | ||
20493 | gdb_assert (die != NULL); | |
20494 | ||
20495 | if (level >= max_level) | |
20496 | return; | |
20497 | ||
20498 | dump_die_shallow (f, indent, die); | |
20499 | ||
20500 | if (die->child != NULL) | |
c906108c | 20501 | { |
d97bc12b DE |
20502 | print_spaces (indent, f); |
20503 | fprintf_unfiltered (f, " Children:"); | |
20504 | if (level + 1 < max_level) | |
20505 | { | |
20506 | fprintf_unfiltered (f, "\n"); | |
20507 | dump_die_1 (f, level + 1, max_level, die->child); | |
20508 | } | |
20509 | else | |
20510 | { | |
3e43a32a MS |
20511 | fprintf_unfiltered (f, |
20512 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
20513 | } |
20514 | } | |
20515 | ||
20516 | if (die->sibling != NULL && level > 0) | |
20517 | { | |
20518 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
20519 | } |
20520 | } | |
20521 | ||
d97bc12b DE |
20522 | /* This is called from the pdie macro in gdbinit.in. |
20523 | It's not static so gcc will keep a copy callable from gdb. */ | |
20524 | ||
20525 | void | |
20526 | dump_die (struct die_info *die, int max_level) | |
20527 | { | |
20528 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
20529 | } | |
20530 | ||
f9aca02d | 20531 | static void |
51545339 | 20532 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 20533 | { |
51545339 | 20534 | void **slot; |
c906108c | 20535 | |
9c541725 PA |
20536 | slot = htab_find_slot_with_hash (cu->die_hash, die, |
20537 | to_underlying (die->sect_off), | |
b64f50a1 | 20538 | INSERT); |
51545339 DJ |
20539 | |
20540 | *slot = die; | |
c906108c SS |
20541 | } |
20542 | ||
b64f50a1 JK |
20543 | /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the |
20544 | required kind. */ | |
20545 | ||
20546 | static sect_offset | |
ff39bb5e | 20547 | dwarf2_get_ref_die_offset (const struct attribute *attr) |
93311388 | 20548 | { |
7771576e | 20549 | if (attr_form_is_ref (attr)) |
9c541725 | 20550 | return (sect_offset) DW_UNSND (attr); |
93311388 DE |
20551 | |
20552 | complaint (&symfile_complaints, | |
20553 | _("unsupported die ref attribute form: '%s'"), | |
20554 | dwarf_form_name (attr->form)); | |
9c541725 | 20555 | return {}; |
c906108c SS |
20556 | } |
20557 | ||
43bbcdc2 PH |
20558 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
20559 | * the value held by the attribute is not constant. */ | |
a02abb62 | 20560 | |
43bbcdc2 | 20561 | static LONGEST |
ff39bb5e | 20562 | dwarf2_get_attr_constant_value (const struct attribute *attr, int default_value) |
a02abb62 JB |
20563 | { |
20564 | if (attr->form == DW_FORM_sdata) | |
20565 | return DW_SND (attr); | |
20566 | else if (attr->form == DW_FORM_udata | |
20567 | || attr->form == DW_FORM_data1 | |
20568 | || attr->form == DW_FORM_data2 | |
20569 | || attr->form == DW_FORM_data4 | |
20570 | || attr->form == DW_FORM_data8) | |
20571 | return DW_UNSND (attr); | |
20572 | else | |
20573 | { | |
0224619f | 20574 | /* For DW_FORM_data16 see attr_form_is_constant. */ |
3e43a32a MS |
20575 | complaint (&symfile_complaints, |
20576 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
20577 | dwarf_form_name (attr->form)); |
20578 | return default_value; | |
20579 | } | |
20580 | } | |
20581 | ||
348e048f DE |
20582 | /* Follow reference or signature attribute ATTR of SRC_DIE. |
20583 | On entry *REF_CU is the CU of SRC_DIE. | |
20584 | On exit *REF_CU is the CU of the result. */ | |
20585 | ||
20586 | static struct die_info * | |
ff39bb5e | 20587 | follow_die_ref_or_sig (struct die_info *src_die, const struct attribute *attr, |
348e048f DE |
20588 | struct dwarf2_cu **ref_cu) |
20589 | { | |
20590 | struct die_info *die; | |
20591 | ||
7771576e | 20592 | if (attr_form_is_ref (attr)) |
348e048f | 20593 | die = follow_die_ref (src_die, attr, ref_cu); |
55f1336d | 20594 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
20595 | die = follow_die_sig (src_die, attr, ref_cu); |
20596 | else | |
20597 | { | |
20598 | dump_die_for_error (src_die); | |
20599 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
4262abfb | 20600 | objfile_name ((*ref_cu)->objfile)); |
348e048f DE |
20601 | } |
20602 | ||
20603 | return die; | |
03dd20cc DJ |
20604 | } |
20605 | ||
5c631832 | 20606 | /* Follow reference OFFSET. |
673bfd45 DE |
20607 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
20608 | On exit *REF_CU is the CU of the result. | |
20609 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 20610 | |
f9aca02d | 20611 | static struct die_info * |
9c541725 | 20612 | follow_die_offset (sect_offset sect_off, int offset_in_dwz, |
36586728 | 20613 | struct dwarf2_cu **ref_cu) |
c906108c | 20614 | { |
10b3939b | 20615 | struct die_info temp_die; |
f2f0e013 | 20616 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 20617 | |
348e048f DE |
20618 | gdb_assert (cu->per_cu != NULL); |
20619 | ||
98bfdba5 PA |
20620 | target_cu = cu; |
20621 | ||
3019eac3 | 20622 | if (cu->per_cu->is_debug_types) |
348e048f DE |
20623 | { |
20624 | /* .debug_types CUs cannot reference anything outside their CU. | |
20625 | If they need to, they have to reference a signatured type via | |
55f1336d | 20626 | DW_FORM_ref_sig8. */ |
9c541725 | 20627 | if (!offset_in_cu_p (&cu->header, sect_off)) |
5c631832 | 20628 | return NULL; |
348e048f | 20629 | } |
36586728 | 20630 | else if (offset_in_dwz != cu->per_cu->is_dwz |
9c541725 | 20631 | || !offset_in_cu_p (&cu->header, sect_off)) |
10b3939b DJ |
20632 | { |
20633 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 20634 | |
9c541725 | 20635 | per_cu = dwarf2_find_containing_comp_unit (sect_off, offset_in_dwz, |
36586728 | 20636 | cu->objfile); |
03dd20cc DJ |
20637 | |
20638 | /* If necessary, add it to the queue and load its DIEs. */ | |
95554aad TT |
20639 | if (maybe_queue_comp_unit (cu, per_cu, cu->language)) |
20640 | load_full_comp_unit (per_cu, cu->language); | |
03dd20cc | 20641 | |
10b3939b DJ |
20642 | target_cu = per_cu->cu; |
20643 | } | |
98bfdba5 PA |
20644 | else if (cu->dies == NULL) |
20645 | { | |
20646 | /* We're loading full DIEs during partial symbol reading. */ | |
20647 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
95554aad | 20648 | load_full_comp_unit (cu->per_cu, language_minimal); |
98bfdba5 | 20649 | } |
c906108c | 20650 | |
f2f0e013 | 20651 | *ref_cu = target_cu; |
9c541725 | 20652 | temp_die.sect_off = sect_off; |
9a3c8263 | 20653 | return (struct die_info *) htab_find_with_hash (target_cu->die_hash, |
9c541725 PA |
20654 | &temp_die, |
20655 | to_underlying (sect_off)); | |
5c631832 | 20656 | } |
10b3939b | 20657 | |
5c631832 JK |
20658 | /* Follow reference attribute ATTR of SRC_DIE. |
20659 | On entry *REF_CU is the CU of SRC_DIE. | |
20660 | On exit *REF_CU is the CU of the result. */ | |
20661 | ||
20662 | static struct die_info * | |
ff39bb5e | 20663 | follow_die_ref (struct die_info *src_die, const struct attribute *attr, |
5c631832 JK |
20664 | struct dwarf2_cu **ref_cu) |
20665 | { | |
9c541725 | 20666 | sect_offset sect_off = dwarf2_get_ref_die_offset (attr); |
5c631832 JK |
20667 | struct dwarf2_cu *cu = *ref_cu; |
20668 | struct die_info *die; | |
20669 | ||
9c541725 | 20670 | die = follow_die_offset (sect_off, |
36586728 TT |
20671 | (attr->form == DW_FORM_GNU_ref_alt |
20672 | || cu->per_cu->is_dwz), | |
20673 | ref_cu); | |
5c631832 JK |
20674 | if (!die) |
20675 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
20676 | "at 0x%x [in module %s]"), | |
9c541725 | 20677 | to_underlying (sect_off), to_underlying (src_die->sect_off), |
4262abfb | 20678 | objfile_name (cu->objfile)); |
348e048f | 20679 | |
5c631832 JK |
20680 | return die; |
20681 | } | |
20682 | ||
9c541725 | 20683 | /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU. |
d83e736b JK |
20684 | Returned value is intended for DW_OP_call*. Returned |
20685 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ | |
5c631832 JK |
20686 | |
20687 | struct dwarf2_locexpr_baton | |
9c541725 | 20688 | dwarf2_fetch_die_loc_sect_off (sect_offset sect_off, |
8b9737bf TT |
20689 | struct dwarf2_per_cu_data *per_cu, |
20690 | CORE_ADDR (*get_frame_pc) (void *baton), | |
20691 | void *baton) | |
5c631832 | 20692 | { |
918dd910 | 20693 | struct dwarf2_cu *cu; |
5c631832 JK |
20694 | struct die_info *die; |
20695 | struct attribute *attr; | |
20696 | struct dwarf2_locexpr_baton retval; | |
20697 | ||
8cf6f0b1 TT |
20698 | dw2_setup (per_cu->objfile); |
20699 | ||
918dd910 JK |
20700 | if (per_cu->cu == NULL) |
20701 | load_cu (per_cu); | |
20702 | cu = per_cu->cu; | |
cc12ce38 DE |
20703 | if (cu == NULL) |
20704 | { | |
20705 | /* We shouldn't get here for a dummy CU, but don't crash on the user. | |
20706 | Instead just throw an error, not much else we can do. */ | |
20707 | error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"), | |
9c541725 | 20708 | to_underlying (sect_off), objfile_name (per_cu->objfile)); |
cc12ce38 | 20709 | } |
918dd910 | 20710 | |
9c541725 | 20711 | die = follow_die_offset (sect_off, per_cu->is_dwz, &cu); |
5c631832 JK |
20712 | if (!die) |
20713 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
9c541725 | 20714 | to_underlying (sect_off), objfile_name (per_cu->objfile)); |
5c631832 JK |
20715 | |
20716 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
20717 | if (!attr) | |
20718 | { | |
e103e986 JK |
20719 | /* DWARF: "If there is no such attribute, then there is no effect.". |
20720 | DATA is ignored if SIZE is 0. */ | |
5c631832 | 20721 | |
e103e986 | 20722 | retval.data = NULL; |
5c631832 JK |
20723 | retval.size = 0; |
20724 | } | |
8cf6f0b1 TT |
20725 | else if (attr_form_is_section_offset (attr)) |
20726 | { | |
20727 | struct dwarf2_loclist_baton loclist_baton; | |
20728 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
20729 | size_t size; | |
20730 | ||
20731 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
20732 | ||
20733 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
20734 | &size, pc); | |
20735 | retval.size = size; | |
20736 | } | |
5c631832 JK |
20737 | else |
20738 | { | |
20739 | if (!attr_form_is_block (attr)) | |
20740 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
20741 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
9c541725 | 20742 | to_underlying (sect_off), objfile_name (per_cu->objfile)); |
5c631832 JK |
20743 | |
20744 | retval.data = DW_BLOCK (attr)->data; | |
20745 | retval.size = DW_BLOCK (attr)->size; | |
20746 | } | |
20747 | retval.per_cu = cu->per_cu; | |
918dd910 | 20748 | |
918dd910 JK |
20749 | age_cached_comp_units (); |
20750 | ||
5c631832 | 20751 | return retval; |
348e048f DE |
20752 | } |
20753 | ||
8b9737bf TT |
20754 | /* Like dwarf2_fetch_die_loc_sect_off, but take a CU |
20755 | offset. */ | |
20756 | ||
20757 | struct dwarf2_locexpr_baton | |
20758 | dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu, | |
20759 | struct dwarf2_per_cu_data *per_cu, | |
20760 | CORE_ADDR (*get_frame_pc) (void *baton), | |
20761 | void *baton) | |
20762 | { | |
9c541725 | 20763 | sect_offset sect_off = per_cu->sect_off + to_underlying (offset_in_cu); |
8b9737bf | 20764 | |
9c541725 | 20765 | return dwarf2_fetch_die_loc_sect_off (sect_off, per_cu, get_frame_pc, baton); |
8b9737bf TT |
20766 | } |
20767 | ||
b6807d98 TT |
20768 | /* Write a constant of a given type as target-ordered bytes into |
20769 | OBSTACK. */ | |
20770 | ||
20771 | static const gdb_byte * | |
20772 | write_constant_as_bytes (struct obstack *obstack, | |
20773 | enum bfd_endian byte_order, | |
20774 | struct type *type, | |
20775 | ULONGEST value, | |
20776 | LONGEST *len) | |
20777 | { | |
20778 | gdb_byte *result; | |
20779 | ||
20780 | *len = TYPE_LENGTH (type); | |
224c3ddb | 20781 | result = (gdb_byte *) obstack_alloc (obstack, *len); |
b6807d98 TT |
20782 | store_unsigned_integer (result, *len, byte_order, value); |
20783 | ||
20784 | return result; | |
20785 | } | |
20786 | ||
20787 | /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a | |
20788 | pointer to the constant bytes and set LEN to the length of the | |
20789 | data. If memory is needed, allocate it on OBSTACK. If the DIE | |
20790 | does not have a DW_AT_const_value, return NULL. */ | |
20791 | ||
20792 | const gdb_byte * | |
9c541725 | 20793 | dwarf2_fetch_constant_bytes (sect_offset sect_off, |
b6807d98 TT |
20794 | struct dwarf2_per_cu_data *per_cu, |
20795 | struct obstack *obstack, | |
20796 | LONGEST *len) | |
20797 | { | |
20798 | struct dwarf2_cu *cu; | |
20799 | struct die_info *die; | |
20800 | struct attribute *attr; | |
20801 | const gdb_byte *result = NULL; | |
20802 | struct type *type; | |
20803 | LONGEST value; | |
20804 | enum bfd_endian byte_order; | |
20805 | ||
20806 | dw2_setup (per_cu->objfile); | |
20807 | ||
20808 | if (per_cu->cu == NULL) | |
20809 | load_cu (per_cu); | |
20810 | cu = per_cu->cu; | |
cc12ce38 DE |
20811 | if (cu == NULL) |
20812 | { | |
20813 | /* We shouldn't get here for a dummy CU, but don't crash on the user. | |
20814 | Instead just throw an error, not much else we can do. */ | |
20815 | error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"), | |
9c541725 | 20816 | to_underlying (sect_off), objfile_name (per_cu->objfile)); |
cc12ce38 | 20817 | } |
b6807d98 | 20818 | |
9c541725 | 20819 | die = follow_die_offset (sect_off, per_cu->is_dwz, &cu); |
b6807d98 TT |
20820 | if (!die) |
20821 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
9c541725 | 20822 | to_underlying (sect_off), objfile_name (per_cu->objfile)); |
b6807d98 TT |
20823 | |
20824 | ||
20825 | attr = dwarf2_attr (die, DW_AT_const_value, cu); | |
20826 | if (attr == NULL) | |
20827 | return NULL; | |
20828 | ||
20829 | byte_order = (bfd_big_endian (per_cu->objfile->obfd) | |
20830 | ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
20831 | ||
20832 | switch (attr->form) | |
20833 | { | |
20834 | case DW_FORM_addr: | |
20835 | case DW_FORM_GNU_addr_index: | |
20836 | { | |
20837 | gdb_byte *tem; | |
20838 | ||
20839 | *len = cu->header.addr_size; | |
224c3ddb | 20840 | tem = (gdb_byte *) obstack_alloc (obstack, *len); |
b6807d98 TT |
20841 | store_unsigned_integer (tem, *len, byte_order, DW_ADDR (attr)); |
20842 | result = tem; | |
20843 | } | |
20844 | break; | |
20845 | case DW_FORM_string: | |
20846 | case DW_FORM_strp: | |
20847 | case DW_FORM_GNU_str_index: | |
20848 | case DW_FORM_GNU_strp_alt: | |
20849 | /* DW_STRING is already allocated on the objfile obstack, point | |
20850 | directly to it. */ | |
20851 | result = (const gdb_byte *) DW_STRING (attr); | |
20852 | *len = strlen (DW_STRING (attr)); | |
20853 | break; | |
20854 | case DW_FORM_block1: | |
20855 | case DW_FORM_block2: | |
20856 | case DW_FORM_block4: | |
20857 | case DW_FORM_block: | |
20858 | case DW_FORM_exprloc: | |
0224619f | 20859 | case DW_FORM_data16: |
b6807d98 TT |
20860 | result = DW_BLOCK (attr)->data; |
20861 | *len = DW_BLOCK (attr)->size; | |
20862 | break; | |
20863 | ||
20864 | /* The DW_AT_const_value attributes are supposed to carry the | |
20865 | symbol's value "represented as it would be on the target | |
20866 | architecture." By the time we get here, it's already been | |
20867 | converted to host endianness, so we just need to sign- or | |
20868 | zero-extend it as appropriate. */ | |
20869 | case DW_FORM_data1: | |
20870 | type = die_type (die, cu); | |
20871 | result = dwarf2_const_value_data (attr, obstack, cu, &value, 8); | |
20872 | if (result == NULL) | |
20873 | result = write_constant_as_bytes (obstack, byte_order, | |
20874 | type, value, len); | |
20875 | break; | |
20876 | case DW_FORM_data2: | |
20877 | type = die_type (die, cu); | |
20878 | result = dwarf2_const_value_data (attr, obstack, cu, &value, 16); | |
20879 | if (result == NULL) | |
20880 | result = write_constant_as_bytes (obstack, byte_order, | |
20881 | type, value, len); | |
20882 | break; | |
20883 | case DW_FORM_data4: | |
20884 | type = die_type (die, cu); | |
20885 | result = dwarf2_const_value_data (attr, obstack, cu, &value, 32); | |
20886 | if (result == NULL) | |
20887 | result = write_constant_as_bytes (obstack, byte_order, | |
20888 | type, value, len); | |
20889 | break; | |
20890 | case DW_FORM_data8: | |
20891 | type = die_type (die, cu); | |
20892 | result = dwarf2_const_value_data (attr, obstack, cu, &value, 64); | |
20893 | if (result == NULL) | |
20894 | result = write_constant_as_bytes (obstack, byte_order, | |
20895 | type, value, len); | |
20896 | break; | |
20897 | ||
20898 | case DW_FORM_sdata: | |
20899 | type = die_type (die, cu); | |
20900 | result = write_constant_as_bytes (obstack, byte_order, | |
20901 | type, DW_SND (attr), len); | |
20902 | break; | |
20903 | ||
20904 | case DW_FORM_udata: | |
20905 | type = die_type (die, cu); | |
20906 | result = write_constant_as_bytes (obstack, byte_order, | |
20907 | type, DW_UNSND (attr), len); | |
20908 | break; | |
20909 | ||
20910 | default: | |
20911 | complaint (&symfile_complaints, | |
20912 | _("unsupported const value attribute form: '%s'"), | |
20913 | dwarf_form_name (attr->form)); | |
20914 | break; | |
20915 | } | |
20916 | ||
20917 | return result; | |
20918 | } | |
20919 | ||
7942e96e AA |
20920 | /* Return the type of the die at OFFSET in PER_CU. Return NULL if no |
20921 | valid type for this die is found. */ | |
20922 | ||
20923 | struct type * | |
9c541725 | 20924 | dwarf2_fetch_die_type_sect_off (sect_offset sect_off, |
7942e96e AA |
20925 | struct dwarf2_per_cu_data *per_cu) |
20926 | { | |
20927 | struct dwarf2_cu *cu; | |
20928 | struct die_info *die; | |
20929 | ||
20930 | dw2_setup (per_cu->objfile); | |
20931 | ||
20932 | if (per_cu->cu == NULL) | |
20933 | load_cu (per_cu); | |
20934 | cu = per_cu->cu; | |
20935 | if (!cu) | |
20936 | return NULL; | |
20937 | ||
9c541725 | 20938 | die = follow_die_offset (sect_off, per_cu->is_dwz, &cu); |
7942e96e AA |
20939 | if (!die) |
20940 | return NULL; | |
20941 | ||
20942 | return die_type (die, cu); | |
20943 | } | |
20944 | ||
8a9b8146 TT |
20945 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
20946 | PER_CU. */ | |
20947 | ||
20948 | struct type * | |
b64f50a1 | 20949 | dwarf2_get_die_type (cu_offset die_offset, |
8a9b8146 TT |
20950 | struct dwarf2_per_cu_data *per_cu) |
20951 | { | |
8a9b8146 | 20952 | dw2_setup (per_cu->objfile); |
b64f50a1 | 20953 | |
9c541725 | 20954 | sect_offset die_offset_sect = per_cu->sect_off + to_underlying (die_offset); |
b64f50a1 | 20955 | return get_die_type_at_offset (die_offset_sect, per_cu); |
8a9b8146 TT |
20956 | } |
20957 | ||
ac9ec31b | 20958 | /* Follow type unit SIG_TYPE referenced by SRC_DIE. |
348e048f | 20959 | On entry *REF_CU is the CU of SRC_DIE. |
ac9ec31b DE |
20960 | On exit *REF_CU is the CU of the result. |
20961 | Returns NULL if the referenced DIE isn't found. */ | |
348e048f DE |
20962 | |
20963 | static struct die_info * | |
ac9ec31b DE |
20964 | follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, |
20965 | struct dwarf2_cu **ref_cu) | |
348e048f | 20966 | { |
348e048f | 20967 | struct die_info temp_die; |
348e048f DE |
20968 | struct dwarf2_cu *sig_cu; |
20969 | struct die_info *die; | |
20970 | ||
ac9ec31b DE |
20971 | /* While it might be nice to assert sig_type->type == NULL here, |
20972 | we can get here for DW_AT_imported_declaration where we need | |
20973 | the DIE not the type. */ | |
348e048f DE |
20974 | |
20975 | /* If necessary, add it to the queue and load its DIEs. */ | |
20976 | ||
95554aad | 20977 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, language_minimal)) |
a0f42c21 | 20978 | read_signatured_type (sig_type); |
348e048f | 20979 | |
348e048f | 20980 | sig_cu = sig_type->per_cu.cu; |
69d751e3 | 20981 | gdb_assert (sig_cu != NULL); |
9c541725 PA |
20982 | gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0); |
20983 | temp_die.sect_off = sig_type->type_offset_in_section; | |
9a3c8263 | 20984 | die = (struct die_info *) htab_find_with_hash (sig_cu->die_hash, &temp_die, |
9c541725 | 20985 | to_underlying (temp_die.sect_off)); |
348e048f DE |
20986 | if (die) |
20987 | { | |
796a7ff8 DE |
20988 | /* For .gdb_index version 7 keep track of included TUs. |
20989 | http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */ | |
20990 | if (dwarf2_per_objfile->index_table != NULL | |
20991 | && dwarf2_per_objfile->index_table->version <= 7) | |
20992 | { | |
20993 | VEC_safe_push (dwarf2_per_cu_ptr, | |
20994 | (*ref_cu)->per_cu->imported_symtabs, | |
20995 | sig_cu->per_cu); | |
20996 | } | |
20997 | ||
348e048f DE |
20998 | *ref_cu = sig_cu; |
20999 | return die; | |
21000 | } | |
21001 | ||
ac9ec31b DE |
21002 | return NULL; |
21003 | } | |
21004 | ||
21005 | /* Follow signatured type referenced by ATTR in SRC_DIE. | |
21006 | On entry *REF_CU is the CU of SRC_DIE. | |
21007 | On exit *REF_CU is the CU of the result. | |
21008 | The result is the DIE of the type. | |
21009 | If the referenced type cannot be found an error is thrown. */ | |
21010 | ||
21011 | static struct die_info * | |
ff39bb5e | 21012 | follow_die_sig (struct die_info *src_die, const struct attribute *attr, |
ac9ec31b DE |
21013 | struct dwarf2_cu **ref_cu) |
21014 | { | |
21015 | ULONGEST signature = DW_SIGNATURE (attr); | |
21016 | struct signatured_type *sig_type; | |
21017 | struct die_info *die; | |
21018 | ||
21019 | gdb_assert (attr->form == DW_FORM_ref_sig8); | |
21020 | ||
a2ce51a0 | 21021 | sig_type = lookup_signatured_type (*ref_cu, signature); |
ac9ec31b DE |
21022 | /* sig_type will be NULL if the signatured type is missing from |
21023 | the debug info. */ | |
21024 | if (sig_type == NULL) | |
21025 | { | |
21026 | error (_("Dwarf Error: Cannot find signatured DIE %s referenced" | |
21027 | " from DIE at 0x%x [in module %s]"), | |
9c541725 | 21028 | hex_string (signature), to_underlying (src_die->sect_off), |
4262abfb | 21029 | objfile_name ((*ref_cu)->objfile)); |
ac9ec31b DE |
21030 | } |
21031 | ||
21032 | die = follow_die_sig_1 (src_die, sig_type, ref_cu); | |
21033 | if (die == NULL) | |
21034 | { | |
21035 | dump_die_for_error (src_die); | |
21036 | error (_("Dwarf Error: Problem reading signatured DIE %s referenced" | |
21037 | " from DIE at 0x%x [in module %s]"), | |
9c541725 | 21038 | hex_string (signature), to_underlying (src_die->sect_off), |
4262abfb | 21039 | objfile_name ((*ref_cu)->objfile)); |
ac9ec31b DE |
21040 | } |
21041 | ||
21042 | return die; | |
21043 | } | |
21044 | ||
21045 | /* Get the type specified by SIGNATURE referenced in DIE/CU, | |
21046 | reading in and processing the type unit if necessary. */ | |
21047 | ||
21048 | static struct type * | |
21049 | get_signatured_type (struct die_info *die, ULONGEST signature, | |
21050 | struct dwarf2_cu *cu) | |
21051 | { | |
21052 | struct signatured_type *sig_type; | |
21053 | struct dwarf2_cu *type_cu; | |
21054 | struct die_info *type_die; | |
21055 | struct type *type; | |
21056 | ||
a2ce51a0 | 21057 | sig_type = lookup_signatured_type (cu, signature); |
ac9ec31b DE |
21058 | /* sig_type will be NULL if the signatured type is missing from |
21059 | the debug info. */ | |
21060 | if (sig_type == NULL) | |
21061 | { | |
21062 | complaint (&symfile_complaints, | |
21063 | _("Dwarf Error: Cannot find signatured DIE %s referenced" | |
21064 | " from DIE at 0x%x [in module %s]"), | |
9c541725 | 21065 | hex_string (signature), to_underlying (die->sect_off), |
4262abfb | 21066 | objfile_name (dwarf2_per_objfile->objfile)); |
ac9ec31b DE |
21067 | return build_error_marker_type (cu, die); |
21068 | } | |
21069 | ||
21070 | /* If we already know the type we're done. */ | |
21071 | if (sig_type->type != NULL) | |
21072 | return sig_type->type; | |
21073 | ||
21074 | type_cu = cu; | |
21075 | type_die = follow_die_sig_1 (die, sig_type, &type_cu); | |
21076 | if (type_die != NULL) | |
21077 | { | |
21078 | /* N.B. We need to call get_die_type to ensure only one type for this DIE | |
21079 | is created. This is important, for example, because for c++ classes | |
21080 | we need TYPE_NAME set which is only done by new_symbol. Blech. */ | |
21081 | type = read_type_die (type_die, type_cu); | |
21082 | if (type == NULL) | |
21083 | { | |
21084 | complaint (&symfile_complaints, | |
21085 | _("Dwarf Error: Cannot build signatured type %s" | |
21086 | " referenced from DIE at 0x%x [in module %s]"), | |
9c541725 | 21087 | hex_string (signature), to_underlying (die->sect_off), |
4262abfb | 21088 | objfile_name (dwarf2_per_objfile->objfile)); |
ac9ec31b DE |
21089 | type = build_error_marker_type (cu, die); |
21090 | } | |
21091 | } | |
21092 | else | |
21093 | { | |
21094 | complaint (&symfile_complaints, | |
21095 | _("Dwarf Error: Problem reading signatured DIE %s referenced" | |
21096 | " from DIE at 0x%x [in module %s]"), | |
9c541725 | 21097 | hex_string (signature), to_underlying (die->sect_off), |
4262abfb | 21098 | objfile_name (dwarf2_per_objfile->objfile)); |
ac9ec31b DE |
21099 | type = build_error_marker_type (cu, die); |
21100 | } | |
21101 | sig_type->type = type; | |
21102 | ||
21103 | return type; | |
21104 | } | |
21105 | ||
21106 | /* Get the type specified by the DW_AT_signature ATTR in DIE/CU, | |
21107 | reading in and processing the type unit if necessary. */ | |
21108 | ||
21109 | static struct type * | |
ff39bb5e | 21110 | get_DW_AT_signature_type (struct die_info *die, const struct attribute *attr, |
b385a60d | 21111 | struct dwarf2_cu *cu) /* ARI: editCase function */ |
ac9ec31b DE |
21112 | { |
21113 | /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */ | |
7771576e | 21114 | if (attr_form_is_ref (attr)) |
ac9ec31b DE |
21115 | { |
21116 | struct dwarf2_cu *type_cu = cu; | |
21117 | struct die_info *type_die = follow_die_ref (die, attr, &type_cu); | |
21118 | ||
21119 | return read_type_die (type_die, type_cu); | |
21120 | } | |
21121 | else if (attr->form == DW_FORM_ref_sig8) | |
21122 | { | |
21123 | return get_signatured_type (die, DW_SIGNATURE (attr), cu); | |
21124 | } | |
21125 | else | |
21126 | { | |
21127 | complaint (&symfile_complaints, | |
21128 | _("Dwarf Error: DW_AT_signature has bad form %s in DIE" | |
21129 | " at 0x%x [in module %s]"), | |
9c541725 | 21130 | dwarf_form_name (attr->form), to_underlying (die->sect_off), |
4262abfb | 21131 | objfile_name (dwarf2_per_objfile->objfile)); |
ac9ec31b DE |
21132 | return build_error_marker_type (cu, die); |
21133 | } | |
348e048f DE |
21134 | } |
21135 | ||
e5fe5e75 | 21136 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
348e048f DE |
21137 | |
21138 | static void | |
e5fe5e75 | 21139 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
348e048f | 21140 | { |
52dc124a | 21141 | struct signatured_type *sig_type; |
348e048f | 21142 | |
f4dc4d17 DE |
21143 | /* Caller is responsible for ensuring type_unit_groups don't get here. */ |
21144 | gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu)); | |
21145 | ||
6721b2ec DE |
21146 | /* We have the per_cu, but we need the signatured_type. |
21147 | Fortunately this is an easy translation. */ | |
21148 | gdb_assert (per_cu->is_debug_types); | |
21149 | sig_type = (struct signatured_type *) per_cu; | |
348e048f | 21150 | |
6721b2ec | 21151 | gdb_assert (per_cu->cu == NULL); |
348e048f | 21152 | |
52dc124a | 21153 | read_signatured_type (sig_type); |
348e048f | 21154 | |
6721b2ec | 21155 | gdb_assert (per_cu->cu != NULL); |
348e048f DE |
21156 | } |
21157 | ||
dee91e82 DE |
21158 | /* die_reader_func for read_signatured_type. |
21159 | This is identical to load_full_comp_unit_reader, | |
21160 | but is kept separate for now. */ | |
348e048f DE |
21161 | |
21162 | static void | |
dee91e82 | 21163 | read_signatured_type_reader (const struct die_reader_specs *reader, |
d521ce57 | 21164 | const gdb_byte *info_ptr, |
dee91e82 DE |
21165 | struct die_info *comp_unit_die, |
21166 | int has_children, | |
21167 | void *data) | |
348e048f | 21168 | { |
dee91e82 | 21169 | struct dwarf2_cu *cu = reader->cu; |
348e048f | 21170 | |
dee91e82 DE |
21171 | gdb_assert (cu->die_hash == NULL); |
21172 | cu->die_hash = | |
21173 | htab_create_alloc_ex (cu->header.length / 12, | |
21174 | die_hash, | |
21175 | die_eq, | |
21176 | NULL, | |
21177 | &cu->comp_unit_obstack, | |
21178 | hashtab_obstack_allocate, | |
21179 | dummy_obstack_deallocate); | |
348e048f | 21180 | |
dee91e82 DE |
21181 | if (has_children) |
21182 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
21183 | &info_ptr, comp_unit_die); | |
21184 | cu->dies = comp_unit_die; | |
21185 | /* comp_unit_die is not stored in die_hash, no need. */ | |
348e048f DE |
21186 | |
21187 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 21188 | all CUs needed for references have been loaded yet, and symbol |
348e048f | 21189 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
21190 | or we won't be able to build types correctly. |
21191 | Similarly, if we do not read the producer, we can not apply | |
21192 | producer-specific interpretation. */ | |
95554aad | 21193 | prepare_one_comp_unit (cu, cu->dies, language_minimal); |
dee91e82 | 21194 | } |
348e048f | 21195 | |
3019eac3 DE |
21196 | /* Read in a signatured type and build its CU and DIEs. |
21197 | If the type is a stub for the real type in a DWO file, | |
21198 | read in the real type from the DWO file as well. */ | |
dee91e82 DE |
21199 | |
21200 | static void | |
21201 | read_signatured_type (struct signatured_type *sig_type) | |
21202 | { | |
21203 | struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu; | |
348e048f | 21204 | |
3019eac3 | 21205 | gdb_assert (per_cu->is_debug_types); |
dee91e82 | 21206 | gdb_assert (per_cu->cu == NULL); |
348e048f | 21207 | |
f4dc4d17 DE |
21208 | init_cutu_and_read_dies (per_cu, NULL, 0, 1, |
21209 | read_signatured_type_reader, NULL); | |
7ee85ab1 | 21210 | sig_type->per_cu.tu_read = 1; |
c906108c SS |
21211 | } |
21212 | ||
c906108c SS |
21213 | /* Decode simple location descriptions. |
21214 | Given a pointer to a dwarf block that defines a location, compute | |
21215 | the location and return the value. | |
21216 | ||
4cecd739 DJ |
21217 | NOTE drow/2003-11-18: This function is called in two situations |
21218 | now: for the address of static or global variables (partial symbols | |
21219 | only) and for offsets into structures which are expected to be | |
21220 | (more or less) constant. The partial symbol case should go away, | |
21221 | and only the constant case should remain. That will let this | |
21222 | function complain more accurately. A few special modes are allowed | |
21223 | without complaint for global variables (for instance, global | |
21224 | register values and thread-local values). | |
c906108c SS |
21225 | |
21226 | A location description containing no operations indicates that the | |
4cecd739 | 21227 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
21228 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
21229 | callers will only want a very basic result and this can become a | |
21ae7a4d JK |
21230 | complaint. |
21231 | ||
21232 | Note that stack[0] is unused except as a default error return. */ | |
c906108c SS |
21233 | |
21234 | static CORE_ADDR | |
e7c27a73 | 21235 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 21236 | { |
e7c27a73 | 21237 | struct objfile *objfile = cu->objfile; |
56eb65bd SP |
21238 | size_t i; |
21239 | size_t size = blk->size; | |
d521ce57 | 21240 | const gdb_byte *data = blk->data; |
21ae7a4d JK |
21241 | CORE_ADDR stack[64]; |
21242 | int stacki; | |
21243 | unsigned int bytes_read, unsnd; | |
21244 | gdb_byte op; | |
c906108c | 21245 | |
21ae7a4d JK |
21246 | i = 0; |
21247 | stacki = 0; | |
21248 | stack[stacki] = 0; | |
21249 | stack[++stacki] = 0; | |
21250 | ||
21251 | while (i < size) | |
21252 | { | |
21253 | op = data[i++]; | |
21254 | switch (op) | |
21255 | { | |
21256 | case DW_OP_lit0: | |
21257 | case DW_OP_lit1: | |
21258 | case DW_OP_lit2: | |
21259 | case DW_OP_lit3: | |
21260 | case DW_OP_lit4: | |
21261 | case DW_OP_lit5: | |
21262 | case DW_OP_lit6: | |
21263 | case DW_OP_lit7: | |
21264 | case DW_OP_lit8: | |
21265 | case DW_OP_lit9: | |
21266 | case DW_OP_lit10: | |
21267 | case DW_OP_lit11: | |
21268 | case DW_OP_lit12: | |
21269 | case DW_OP_lit13: | |
21270 | case DW_OP_lit14: | |
21271 | case DW_OP_lit15: | |
21272 | case DW_OP_lit16: | |
21273 | case DW_OP_lit17: | |
21274 | case DW_OP_lit18: | |
21275 | case DW_OP_lit19: | |
21276 | case DW_OP_lit20: | |
21277 | case DW_OP_lit21: | |
21278 | case DW_OP_lit22: | |
21279 | case DW_OP_lit23: | |
21280 | case DW_OP_lit24: | |
21281 | case DW_OP_lit25: | |
21282 | case DW_OP_lit26: | |
21283 | case DW_OP_lit27: | |
21284 | case DW_OP_lit28: | |
21285 | case DW_OP_lit29: | |
21286 | case DW_OP_lit30: | |
21287 | case DW_OP_lit31: | |
21288 | stack[++stacki] = op - DW_OP_lit0; | |
21289 | break; | |
f1bea926 | 21290 | |
21ae7a4d JK |
21291 | case DW_OP_reg0: |
21292 | case DW_OP_reg1: | |
21293 | case DW_OP_reg2: | |
21294 | case DW_OP_reg3: | |
21295 | case DW_OP_reg4: | |
21296 | case DW_OP_reg5: | |
21297 | case DW_OP_reg6: | |
21298 | case DW_OP_reg7: | |
21299 | case DW_OP_reg8: | |
21300 | case DW_OP_reg9: | |
21301 | case DW_OP_reg10: | |
21302 | case DW_OP_reg11: | |
21303 | case DW_OP_reg12: | |
21304 | case DW_OP_reg13: | |
21305 | case DW_OP_reg14: | |
21306 | case DW_OP_reg15: | |
21307 | case DW_OP_reg16: | |
21308 | case DW_OP_reg17: | |
21309 | case DW_OP_reg18: | |
21310 | case DW_OP_reg19: | |
21311 | case DW_OP_reg20: | |
21312 | case DW_OP_reg21: | |
21313 | case DW_OP_reg22: | |
21314 | case DW_OP_reg23: | |
21315 | case DW_OP_reg24: | |
21316 | case DW_OP_reg25: | |
21317 | case DW_OP_reg26: | |
21318 | case DW_OP_reg27: | |
21319 | case DW_OP_reg28: | |
21320 | case DW_OP_reg29: | |
21321 | case DW_OP_reg30: | |
21322 | case DW_OP_reg31: | |
21323 | stack[++stacki] = op - DW_OP_reg0; | |
21324 | if (i < size) | |
21325 | dwarf2_complex_location_expr_complaint (); | |
21326 | break; | |
c906108c | 21327 | |
21ae7a4d JK |
21328 | case DW_OP_regx: |
21329 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
21330 | i += bytes_read; | |
21331 | stack[++stacki] = unsnd; | |
21332 | if (i < size) | |
21333 | dwarf2_complex_location_expr_complaint (); | |
21334 | break; | |
c906108c | 21335 | |
21ae7a4d JK |
21336 | case DW_OP_addr: |
21337 | stack[++stacki] = read_address (objfile->obfd, &data[i], | |
21338 | cu, &bytes_read); | |
21339 | i += bytes_read; | |
21340 | break; | |
d53d4ac5 | 21341 | |
21ae7a4d JK |
21342 | case DW_OP_const1u: |
21343 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
21344 | i += 1; | |
21345 | break; | |
21346 | ||
21347 | case DW_OP_const1s: | |
21348 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
21349 | i += 1; | |
21350 | break; | |
21351 | ||
21352 | case DW_OP_const2u: | |
21353 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
21354 | i += 2; | |
21355 | break; | |
21356 | ||
21357 | case DW_OP_const2s: | |
21358 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
21359 | i += 2; | |
21360 | break; | |
d53d4ac5 | 21361 | |
21ae7a4d JK |
21362 | case DW_OP_const4u: |
21363 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
21364 | i += 4; | |
21365 | break; | |
21366 | ||
21367 | case DW_OP_const4s: | |
21368 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
21369 | i += 4; | |
21370 | break; | |
21371 | ||
585861ea JK |
21372 | case DW_OP_const8u: |
21373 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); | |
21374 | i += 8; | |
21375 | break; | |
21376 | ||
21ae7a4d JK |
21377 | case DW_OP_constu: |
21378 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
21379 | &bytes_read); | |
21380 | i += bytes_read; | |
21381 | break; | |
21382 | ||
21383 | case DW_OP_consts: | |
21384 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
21385 | i += bytes_read; | |
21386 | break; | |
21387 | ||
21388 | case DW_OP_dup: | |
21389 | stack[stacki + 1] = stack[stacki]; | |
21390 | stacki++; | |
21391 | break; | |
21392 | ||
21393 | case DW_OP_plus: | |
21394 | stack[stacki - 1] += stack[stacki]; | |
21395 | stacki--; | |
21396 | break; | |
21397 | ||
21398 | case DW_OP_plus_uconst: | |
21399 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), | |
21400 | &bytes_read); | |
21401 | i += bytes_read; | |
21402 | break; | |
21403 | ||
21404 | case DW_OP_minus: | |
21405 | stack[stacki - 1] -= stack[stacki]; | |
21406 | stacki--; | |
21407 | break; | |
21408 | ||
21409 | case DW_OP_deref: | |
21410 | /* If we're not the last op, then we definitely can't encode | |
21411 | this using GDB's address_class enum. This is valid for partial | |
21412 | global symbols, although the variable's address will be bogus | |
21413 | in the psymtab. */ | |
21414 | if (i < size) | |
21415 | dwarf2_complex_location_expr_complaint (); | |
21416 | break; | |
21417 | ||
21418 | case DW_OP_GNU_push_tls_address: | |
4aa4e28b | 21419 | case DW_OP_form_tls_address: |
21ae7a4d JK |
21420 | /* The top of the stack has the offset from the beginning |
21421 | of the thread control block at which the variable is located. */ | |
21422 | /* Nothing should follow this operator, so the top of stack would | |
21423 | be returned. */ | |
21424 | /* This is valid for partial global symbols, but the variable's | |
585861ea JK |
21425 | address will be bogus in the psymtab. Make it always at least |
21426 | non-zero to not look as a variable garbage collected by linker | |
21427 | which have DW_OP_addr 0. */ | |
21ae7a4d JK |
21428 | if (i < size) |
21429 | dwarf2_complex_location_expr_complaint (); | |
585861ea | 21430 | stack[stacki]++; |
21ae7a4d JK |
21431 | break; |
21432 | ||
21433 | case DW_OP_GNU_uninit: | |
21434 | break; | |
21435 | ||
3019eac3 | 21436 | case DW_OP_GNU_addr_index: |
49f6c839 | 21437 | case DW_OP_GNU_const_index: |
3019eac3 DE |
21438 | stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i], |
21439 | &bytes_read); | |
21440 | i += bytes_read; | |
21441 | break; | |
21442 | ||
21ae7a4d JK |
21443 | default: |
21444 | { | |
f39c6ffd | 21445 | const char *name = get_DW_OP_name (op); |
21ae7a4d JK |
21446 | |
21447 | if (name) | |
21448 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
21449 | name); | |
21450 | else | |
21451 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
21452 | op); | |
21453 | } | |
21454 | ||
21455 | return (stack[stacki]); | |
d53d4ac5 | 21456 | } |
3c6e0cb3 | 21457 | |
21ae7a4d JK |
21458 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
21459 | outside of the allocated space. Also enforce minimum>0. */ | |
21460 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
21461 | { | |
21462 | complaint (&symfile_complaints, | |
21463 | _("location description stack overflow")); | |
21464 | return 0; | |
21465 | } | |
21466 | ||
21467 | if (stacki <= 0) | |
21468 | { | |
21469 | complaint (&symfile_complaints, | |
21470 | _("location description stack underflow")); | |
21471 | return 0; | |
21472 | } | |
21473 | } | |
21474 | return (stack[stacki]); | |
c906108c SS |
21475 | } |
21476 | ||
21477 | /* memory allocation interface */ | |
21478 | ||
c906108c | 21479 | static struct dwarf_block * |
7b5a2f43 | 21480 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c | 21481 | { |
8d749320 | 21482 | return XOBNEW (&cu->comp_unit_obstack, struct dwarf_block); |
c906108c SS |
21483 | } |
21484 | ||
c906108c | 21485 | static struct die_info * |
b60c80d6 | 21486 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
21487 | { |
21488 | struct die_info *die; | |
b60c80d6 DJ |
21489 | size_t size = sizeof (struct die_info); |
21490 | ||
21491 | if (num_attrs > 1) | |
21492 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 21493 | |
b60c80d6 | 21494 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
21495 | memset (die, 0, sizeof (struct die_info)); |
21496 | return (die); | |
21497 | } | |
2e276125 JB |
21498 | |
21499 | \f | |
21500 | /* Macro support. */ | |
21501 | ||
233d95b5 JK |
21502 | /* Return file name relative to the compilation directory of file number I in |
21503 | *LH's file name table. The result is allocated using xmalloc; the caller is | |
2e276125 | 21504 | responsible for freeing it. */ |
233d95b5 | 21505 | |
2e276125 | 21506 | static char * |
233d95b5 | 21507 | file_file_name (int file, struct line_header *lh) |
2e276125 | 21508 | { |
6a83a1e6 EZ |
21509 | /* Is the file number a valid index into the line header's file name |
21510 | table? Remember that file numbers start with one, not zero. */ | |
fff8551c | 21511 | if (1 <= file && file <= lh->file_names.size ()) |
6a83a1e6 | 21512 | { |
8c43009f | 21513 | const file_entry &fe = lh->file_names[file - 1]; |
6e70227d | 21514 | |
8c43009f PA |
21515 | if (!IS_ABSOLUTE_PATH (fe.name)) |
21516 | { | |
21517 | const char *dir = fe.include_dir (lh); | |
21518 | if (dir != NULL) | |
21519 | return concat (dir, SLASH_STRING, fe.name, (char *) NULL); | |
21520 | } | |
21521 | return xstrdup (fe.name); | |
6a83a1e6 | 21522 | } |
2e276125 JB |
21523 | else |
21524 | { | |
6a83a1e6 EZ |
21525 | /* The compiler produced a bogus file number. We can at least |
21526 | record the macro definitions made in the file, even if we | |
21527 | won't be able to find the file by name. */ | |
21528 | char fake_name[80]; | |
9a619af0 | 21529 | |
8c042590 PM |
21530 | xsnprintf (fake_name, sizeof (fake_name), |
21531 | "<bad macro file number %d>", file); | |
2e276125 | 21532 | |
6e70227d | 21533 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
21534 | _("bad file number in macro information (%d)"), |
21535 | file); | |
2e276125 | 21536 | |
6a83a1e6 | 21537 | return xstrdup (fake_name); |
2e276125 JB |
21538 | } |
21539 | } | |
21540 | ||
233d95b5 JK |
21541 | /* Return the full name of file number I in *LH's file name table. |
21542 | Use COMP_DIR as the name of the current directory of the | |
21543 | compilation. The result is allocated using xmalloc; the caller is | |
21544 | responsible for freeing it. */ | |
21545 | static char * | |
21546 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
21547 | { | |
21548 | /* Is the file number a valid index into the line header's file name | |
21549 | table? Remember that file numbers start with one, not zero. */ | |
fff8551c | 21550 | if (1 <= file && file <= lh->file_names.size ()) |
233d95b5 JK |
21551 | { |
21552 | char *relative = file_file_name (file, lh); | |
21553 | ||
21554 | if (IS_ABSOLUTE_PATH (relative) || comp_dir == NULL) | |
21555 | return relative; | |
b36cec19 PA |
21556 | return reconcat (relative, comp_dir, SLASH_STRING, |
21557 | relative, (char *) NULL); | |
233d95b5 JK |
21558 | } |
21559 | else | |
21560 | return file_file_name (file, lh); | |
21561 | } | |
21562 | ||
2e276125 JB |
21563 | |
21564 | static struct macro_source_file * | |
21565 | macro_start_file (int file, int line, | |
21566 | struct macro_source_file *current_file, | |
43f3e411 | 21567 | struct line_header *lh) |
2e276125 | 21568 | { |
233d95b5 JK |
21569 | /* File name relative to the compilation directory of this source file. */ |
21570 | char *file_name = file_file_name (file, lh); | |
2e276125 | 21571 | |
2e276125 | 21572 | if (! current_file) |
abc9d0dc | 21573 | { |
fc474241 DE |
21574 | /* Note: We don't create a macro table for this compilation unit |
21575 | at all until we actually get a filename. */ | |
43f3e411 | 21576 | struct macro_table *macro_table = get_macro_table (); |
fc474241 | 21577 | |
abc9d0dc TT |
21578 | /* If we have no current file, then this must be the start_file |
21579 | directive for the compilation unit's main source file. */ | |
fc474241 DE |
21580 | current_file = macro_set_main (macro_table, file_name); |
21581 | macro_define_special (macro_table); | |
abc9d0dc | 21582 | } |
2e276125 | 21583 | else |
233d95b5 | 21584 | current_file = macro_include (current_file, line, file_name); |
2e276125 | 21585 | |
233d95b5 | 21586 | xfree (file_name); |
6e70227d | 21587 | |
2e276125 JB |
21588 | return current_file; |
21589 | } | |
21590 | ||
21591 | ||
21592 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
21593 | followed by a null byte. */ | |
21594 | static char * | |
21595 | copy_string (const char *buf, int len) | |
21596 | { | |
224c3ddb | 21597 | char *s = (char *) xmalloc (len + 1); |
9a619af0 | 21598 | |
2e276125 JB |
21599 | memcpy (s, buf, len); |
21600 | s[len] = '\0'; | |
2e276125 JB |
21601 | return s; |
21602 | } | |
21603 | ||
21604 | ||
21605 | static const char * | |
21606 | consume_improper_spaces (const char *p, const char *body) | |
21607 | { | |
21608 | if (*p == ' ') | |
21609 | { | |
4d3c2250 | 21610 | complaint (&symfile_complaints, |
3e43a32a MS |
21611 | _("macro definition contains spaces " |
21612 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 21613 | body); |
2e276125 JB |
21614 | |
21615 | while (*p == ' ') | |
21616 | p++; | |
21617 | } | |
21618 | ||
21619 | return p; | |
21620 | } | |
21621 | ||
21622 | ||
21623 | static void | |
21624 | parse_macro_definition (struct macro_source_file *file, int line, | |
21625 | const char *body) | |
21626 | { | |
21627 | const char *p; | |
21628 | ||
21629 | /* The body string takes one of two forms. For object-like macro | |
21630 | definitions, it should be: | |
21631 | ||
21632 | <macro name> " " <definition> | |
21633 | ||
21634 | For function-like macro definitions, it should be: | |
21635 | ||
21636 | <macro name> "() " <definition> | |
21637 | or | |
21638 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
21639 | ||
21640 | Spaces may appear only where explicitly indicated, and in the | |
21641 | <definition>. | |
21642 | ||
21643 | The Dwarf 2 spec says that an object-like macro's name is always | |
21644 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 21645 | the space when the macro's definition is the empty string. |
2e276125 JB |
21646 | |
21647 | The Dwarf 2 spec says that there should be no spaces between the | |
21648 | formal arguments in a function-like macro's formal argument list, | |
21649 | but versions of GCC around March 2002 include spaces after the | |
21650 | commas. */ | |
21651 | ||
21652 | ||
21653 | /* Find the extent of the macro name. The macro name is terminated | |
21654 | by either a space or null character (for an object-like macro) or | |
21655 | an opening paren (for a function-like macro). */ | |
21656 | for (p = body; *p; p++) | |
21657 | if (*p == ' ' || *p == '(') | |
21658 | break; | |
21659 | ||
21660 | if (*p == ' ' || *p == '\0') | |
21661 | { | |
21662 | /* It's an object-like macro. */ | |
21663 | int name_len = p - body; | |
21664 | char *name = copy_string (body, name_len); | |
21665 | const char *replacement; | |
21666 | ||
21667 | if (*p == ' ') | |
21668 | replacement = body + name_len + 1; | |
21669 | else | |
21670 | { | |
4d3c2250 | 21671 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
21672 | replacement = body + name_len; |
21673 | } | |
6e70227d | 21674 | |
2e276125 JB |
21675 | macro_define_object (file, line, name, replacement); |
21676 | ||
21677 | xfree (name); | |
21678 | } | |
21679 | else if (*p == '(') | |
21680 | { | |
21681 | /* It's a function-like macro. */ | |
21682 | char *name = copy_string (body, p - body); | |
21683 | int argc = 0; | |
21684 | int argv_size = 1; | |
8d749320 | 21685 | char **argv = XNEWVEC (char *, argv_size); |
2e276125 JB |
21686 | |
21687 | p++; | |
21688 | ||
21689 | p = consume_improper_spaces (p, body); | |
21690 | ||
21691 | /* Parse the formal argument list. */ | |
21692 | while (*p && *p != ')') | |
21693 | { | |
21694 | /* Find the extent of the current argument name. */ | |
21695 | const char *arg_start = p; | |
21696 | ||
21697 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
21698 | p++; | |
21699 | ||
21700 | if (! *p || p == arg_start) | |
4d3c2250 | 21701 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
21702 | else |
21703 | { | |
21704 | /* Make sure argv has room for the new argument. */ | |
21705 | if (argc >= argv_size) | |
21706 | { | |
21707 | argv_size *= 2; | |
224c3ddb | 21708 | argv = XRESIZEVEC (char *, argv, argv_size); |
2e276125 JB |
21709 | } |
21710 | ||
21711 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
21712 | } | |
21713 | ||
21714 | p = consume_improper_spaces (p, body); | |
21715 | ||
21716 | /* Consume the comma, if present. */ | |
21717 | if (*p == ',') | |
21718 | { | |
21719 | p++; | |
21720 | ||
21721 | p = consume_improper_spaces (p, body); | |
21722 | } | |
21723 | } | |
21724 | ||
21725 | if (*p == ')') | |
21726 | { | |
21727 | p++; | |
21728 | ||
21729 | if (*p == ' ') | |
21730 | /* Perfectly formed definition, no complaints. */ | |
21731 | macro_define_function (file, line, name, | |
6e70227d | 21732 | argc, (const char **) argv, |
2e276125 JB |
21733 | p + 1); |
21734 | else if (*p == '\0') | |
21735 | { | |
21736 | /* Complain, but do define it. */ | |
4d3c2250 | 21737 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 21738 | macro_define_function (file, line, name, |
6e70227d | 21739 | argc, (const char **) argv, |
2e276125 JB |
21740 | p); |
21741 | } | |
21742 | else | |
21743 | /* Just complain. */ | |
4d3c2250 | 21744 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
21745 | } |
21746 | else | |
21747 | /* Just complain. */ | |
4d3c2250 | 21748 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
21749 | |
21750 | xfree (name); | |
21751 | { | |
21752 | int i; | |
21753 | ||
21754 | for (i = 0; i < argc; i++) | |
21755 | xfree (argv[i]); | |
21756 | } | |
21757 | xfree (argv); | |
21758 | } | |
21759 | else | |
4d3c2250 | 21760 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
21761 | } |
21762 | ||
cf2c3c16 TT |
21763 | /* Skip some bytes from BYTES according to the form given in FORM. |
21764 | Returns the new pointer. */ | |
2e276125 | 21765 | |
d521ce57 TT |
21766 | static const gdb_byte * |
21767 | skip_form_bytes (bfd *abfd, const gdb_byte *bytes, const gdb_byte *buffer_end, | |
cf2c3c16 TT |
21768 | enum dwarf_form form, |
21769 | unsigned int offset_size, | |
21770 | struct dwarf2_section_info *section) | |
2e276125 | 21771 | { |
cf2c3c16 | 21772 | unsigned int bytes_read; |
2e276125 | 21773 | |
cf2c3c16 | 21774 | switch (form) |
2e276125 | 21775 | { |
cf2c3c16 TT |
21776 | case DW_FORM_data1: |
21777 | case DW_FORM_flag: | |
21778 | ++bytes; | |
21779 | break; | |
21780 | ||
21781 | case DW_FORM_data2: | |
21782 | bytes += 2; | |
21783 | break; | |
21784 | ||
21785 | case DW_FORM_data4: | |
21786 | bytes += 4; | |
21787 | break; | |
21788 | ||
21789 | case DW_FORM_data8: | |
21790 | bytes += 8; | |
21791 | break; | |
21792 | ||
0224619f JK |
21793 | case DW_FORM_data16: |
21794 | bytes += 16; | |
21795 | break; | |
21796 | ||
cf2c3c16 TT |
21797 | case DW_FORM_string: |
21798 | read_direct_string (abfd, bytes, &bytes_read); | |
21799 | bytes += bytes_read; | |
21800 | break; | |
21801 | ||
21802 | case DW_FORM_sec_offset: | |
21803 | case DW_FORM_strp: | |
36586728 | 21804 | case DW_FORM_GNU_strp_alt: |
cf2c3c16 TT |
21805 | bytes += offset_size; |
21806 | break; | |
21807 | ||
21808 | case DW_FORM_block: | |
21809 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); | |
21810 | bytes += bytes_read; | |
21811 | break; | |
21812 | ||
21813 | case DW_FORM_block1: | |
21814 | bytes += 1 + read_1_byte (abfd, bytes); | |
21815 | break; | |
21816 | case DW_FORM_block2: | |
21817 | bytes += 2 + read_2_bytes (abfd, bytes); | |
21818 | break; | |
21819 | case DW_FORM_block4: | |
21820 | bytes += 4 + read_4_bytes (abfd, bytes); | |
21821 | break; | |
21822 | ||
21823 | case DW_FORM_sdata: | |
21824 | case DW_FORM_udata: | |
3019eac3 DE |
21825 | case DW_FORM_GNU_addr_index: |
21826 | case DW_FORM_GNU_str_index: | |
d521ce57 | 21827 | bytes = gdb_skip_leb128 (bytes, buffer_end); |
f664829e DE |
21828 | if (bytes == NULL) |
21829 | { | |
21830 | dwarf2_section_buffer_overflow_complaint (section); | |
21831 | return NULL; | |
21832 | } | |
cf2c3c16 TT |
21833 | break; |
21834 | ||
21835 | default: | |
21836 | { | |
21837 | complain: | |
21838 | complaint (&symfile_complaints, | |
21839 | _("invalid form 0x%x in `%s'"), | |
a32a8923 | 21840 | form, get_section_name (section)); |
cf2c3c16 TT |
21841 | return NULL; |
21842 | } | |
2e276125 JB |
21843 | } |
21844 | ||
cf2c3c16 TT |
21845 | return bytes; |
21846 | } | |
757a13d0 | 21847 | |
cf2c3c16 TT |
21848 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
21849 | opcode. Returns an updated pointer to the macro data buffer; or, | |
21850 | on error, issues a complaint and returns NULL. */ | |
757a13d0 | 21851 | |
d521ce57 | 21852 | static const gdb_byte * |
cf2c3c16 | 21853 | skip_unknown_opcode (unsigned int opcode, |
d521ce57 TT |
21854 | const gdb_byte **opcode_definitions, |
21855 | const gdb_byte *mac_ptr, const gdb_byte *mac_end, | |
cf2c3c16 TT |
21856 | bfd *abfd, |
21857 | unsigned int offset_size, | |
21858 | struct dwarf2_section_info *section) | |
21859 | { | |
21860 | unsigned int bytes_read, i; | |
21861 | unsigned long arg; | |
d521ce57 | 21862 | const gdb_byte *defn; |
2e276125 | 21863 | |
cf2c3c16 | 21864 | if (opcode_definitions[opcode] == NULL) |
2e276125 | 21865 | { |
cf2c3c16 TT |
21866 | complaint (&symfile_complaints, |
21867 | _("unrecognized DW_MACFINO opcode 0x%x"), | |
21868 | opcode); | |
21869 | return NULL; | |
21870 | } | |
2e276125 | 21871 | |
cf2c3c16 TT |
21872 | defn = opcode_definitions[opcode]; |
21873 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); | |
21874 | defn += bytes_read; | |
2e276125 | 21875 | |
cf2c3c16 TT |
21876 | for (i = 0; i < arg; ++i) |
21877 | { | |
aead7601 SM |
21878 | mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, |
21879 | (enum dwarf_form) defn[i], offset_size, | |
f664829e | 21880 | section); |
cf2c3c16 TT |
21881 | if (mac_ptr == NULL) |
21882 | { | |
21883 | /* skip_form_bytes already issued the complaint. */ | |
21884 | return NULL; | |
21885 | } | |
21886 | } | |
757a13d0 | 21887 | |
cf2c3c16 TT |
21888 | return mac_ptr; |
21889 | } | |
757a13d0 | 21890 | |
cf2c3c16 TT |
21891 | /* A helper function which parses the header of a macro section. |
21892 | If the macro section is the extended (for now called "GNU") type, | |
21893 | then this updates *OFFSET_SIZE. Returns a pointer to just after | |
21894 | the header, or issues a complaint and returns NULL on error. */ | |
757a13d0 | 21895 | |
d521ce57 TT |
21896 | static const gdb_byte * |
21897 | dwarf_parse_macro_header (const gdb_byte **opcode_definitions, | |
cf2c3c16 | 21898 | bfd *abfd, |
d521ce57 | 21899 | const gdb_byte *mac_ptr, |
cf2c3c16 TT |
21900 | unsigned int *offset_size, |
21901 | int section_is_gnu) | |
21902 | { | |
21903 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); | |
757a13d0 | 21904 | |
cf2c3c16 TT |
21905 | if (section_is_gnu) |
21906 | { | |
21907 | unsigned int version, flags; | |
757a13d0 | 21908 | |
cf2c3c16 | 21909 | version = read_2_bytes (abfd, mac_ptr); |
0af92d60 | 21910 | if (version != 4 && version != 5) |
cf2c3c16 TT |
21911 | { |
21912 | complaint (&symfile_complaints, | |
21913 | _("unrecognized version `%d' in .debug_macro section"), | |
21914 | version); | |
21915 | return NULL; | |
21916 | } | |
21917 | mac_ptr += 2; | |
757a13d0 | 21918 | |
cf2c3c16 TT |
21919 | flags = read_1_byte (abfd, mac_ptr); |
21920 | ++mac_ptr; | |
21921 | *offset_size = (flags & 1) ? 8 : 4; | |
757a13d0 | 21922 | |
cf2c3c16 TT |
21923 | if ((flags & 2) != 0) |
21924 | /* We don't need the line table offset. */ | |
21925 | mac_ptr += *offset_size; | |
757a13d0 | 21926 | |
cf2c3c16 TT |
21927 | /* Vendor opcode descriptions. */ |
21928 | if ((flags & 4) != 0) | |
21929 | { | |
21930 | unsigned int i, count; | |
757a13d0 | 21931 | |
cf2c3c16 TT |
21932 | count = read_1_byte (abfd, mac_ptr); |
21933 | ++mac_ptr; | |
21934 | for (i = 0; i < count; ++i) | |
21935 | { | |
21936 | unsigned int opcode, bytes_read; | |
21937 | unsigned long arg; | |
21938 | ||
21939 | opcode = read_1_byte (abfd, mac_ptr); | |
21940 | ++mac_ptr; | |
21941 | opcode_definitions[opcode] = mac_ptr; | |
21942 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
21943 | mac_ptr += bytes_read; | |
21944 | mac_ptr += arg; | |
21945 | } | |
757a13d0 | 21946 | } |
cf2c3c16 | 21947 | } |
757a13d0 | 21948 | |
cf2c3c16 TT |
21949 | return mac_ptr; |
21950 | } | |
757a13d0 | 21951 | |
cf2c3c16 | 21952 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
0af92d60 | 21953 | including DW_MACRO_import. */ |
cf2c3c16 TT |
21954 | |
21955 | static void | |
d521ce57 TT |
21956 | dwarf_decode_macro_bytes (bfd *abfd, |
21957 | const gdb_byte *mac_ptr, const gdb_byte *mac_end, | |
cf2c3c16 | 21958 | struct macro_source_file *current_file, |
43f3e411 | 21959 | struct line_header *lh, |
cf2c3c16 | 21960 | struct dwarf2_section_info *section, |
36586728 | 21961 | int section_is_gnu, int section_is_dwz, |
cf2c3c16 | 21962 | unsigned int offset_size, |
8fc3fc34 | 21963 | htab_t include_hash) |
cf2c3c16 | 21964 | { |
4d663531 | 21965 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
cf2c3c16 TT |
21966 | enum dwarf_macro_record_type macinfo_type; |
21967 | int at_commandline; | |
d521ce57 | 21968 | const gdb_byte *opcode_definitions[256]; |
757a13d0 | 21969 | |
cf2c3c16 TT |
21970 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
21971 | &offset_size, section_is_gnu); | |
21972 | if (mac_ptr == NULL) | |
21973 | { | |
21974 | /* We already issued a complaint. */ | |
21975 | return; | |
21976 | } | |
757a13d0 JK |
21977 | |
21978 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
21979 | GDB is still reading the definitions from command line. First | |
21980 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
21981 | to create CURRENT_FILE for the main source holding also the command line | |
21982 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
21983 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
21984 | ||
21985 | at_commandline = 1; | |
21986 | ||
21987 | do | |
21988 | { | |
21989 | /* Do we at least have room for a macinfo type byte? */ | |
21990 | if (mac_ptr >= mac_end) | |
21991 | { | |
f664829e | 21992 | dwarf2_section_buffer_overflow_complaint (section); |
757a13d0 JK |
21993 | break; |
21994 | } | |
21995 | ||
aead7601 | 21996 | macinfo_type = (enum dwarf_macro_record_type) read_1_byte (abfd, mac_ptr); |
757a13d0 JK |
21997 | mac_ptr++; |
21998 | ||
cf2c3c16 TT |
21999 | /* Note that we rely on the fact that the corresponding GNU and |
22000 | DWARF constants are the same. */ | |
757a13d0 JK |
22001 | switch (macinfo_type) |
22002 | { | |
22003 | /* A zero macinfo type indicates the end of the macro | |
22004 | information. */ | |
22005 | case 0: | |
22006 | break; | |
2e276125 | 22007 | |
0af92d60 JK |
22008 | case DW_MACRO_define: |
22009 | case DW_MACRO_undef: | |
22010 | case DW_MACRO_define_strp: | |
22011 | case DW_MACRO_undef_strp: | |
22012 | case DW_MACRO_define_sup: | |
22013 | case DW_MACRO_undef_sup: | |
2e276125 | 22014 | { |
891d2f0b | 22015 | unsigned int bytes_read; |
2e276125 | 22016 | int line; |
d521ce57 | 22017 | const char *body; |
cf2c3c16 | 22018 | int is_define; |
2e276125 | 22019 | |
cf2c3c16 TT |
22020 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
22021 | mac_ptr += bytes_read; | |
22022 | ||
0af92d60 JK |
22023 | if (macinfo_type == DW_MACRO_define |
22024 | || macinfo_type == DW_MACRO_undef) | |
cf2c3c16 TT |
22025 | { |
22026 | body = read_direct_string (abfd, mac_ptr, &bytes_read); | |
22027 | mac_ptr += bytes_read; | |
22028 | } | |
22029 | else | |
22030 | { | |
22031 | LONGEST str_offset; | |
22032 | ||
22033 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
22034 | mac_ptr += offset_size; | |
2e276125 | 22035 | |
0af92d60 JK |
22036 | if (macinfo_type == DW_MACRO_define_sup |
22037 | || macinfo_type == DW_MACRO_undef_sup | |
f7a35f02 | 22038 | || section_is_dwz) |
36586728 TT |
22039 | { |
22040 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
22041 | ||
22042 | body = read_indirect_string_from_dwz (dwz, str_offset); | |
22043 | } | |
22044 | else | |
22045 | body = read_indirect_string_at_offset (abfd, str_offset); | |
cf2c3c16 TT |
22046 | } |
22047 | ||
0af92d60 JK |
22048 | is_define = (macinfo_type == DW_MACRO_define |
22049 | || macinfo_type == DW_MACRO_define_strp | |
22050 | || macinfo_type == DW_MACRO_define_sup); | |
2e276125 | 22051 | if (! current_file) |
757a13d0 JK |
22052 | { |
22053 | /* DWARF violation as no main source is present. */ | |
22054 | complaint (&symfile_complaints, | |
22055 | _("debug info with no main source gives macro %s " | |
22056 | "on line %d: %s"), | |
cf2c3c16 TT |
22057 | is_define ? _("definition") : _("undefinition"), |
22058 | line, body); | |
757a13d0 JK |
22059 | break; |
22060 | } | |
3e43a32a MS |
22061 | if ((line == 0 && !at_commandline) |
22062 | || (line != 0 && at_commandline)) | |
4d3c2250 | 22063 | complaint (&symfile_complaints, |
757a13d0 JK |
22064 | _("debug info gives %s macro %s with %s line %d: %s"), |
22065 | at_commandline ? _("command-line") : _("in-file"), | |
cf2c3c16 | 22066 | is_define ? _("definition") : _("undefinition"), |
757a13d0 JK |
22067 | line == 0 ? _("zero") : _("non-zero"), line, body); |
22068 | ||
cf2c3c16 | 22069 | if (is_define) |
757a13d0 | 22070 | parse_macro_definition (current_file, line, body); |
cf2c3c16 TT |
22071 | else |
22072 | { | |
0af92d60 JK |
22073 | gdb_assert (macinfo_type == DW_MACRO_undef |
22074 | || macinfo_type == DW_MACRO_undef_strp | |
22075 | || macinfo_type == DW_MACRO_undef_sup); | |
cf2c3c16 TT |
22076 | macro_undef (current_file, line, body); |
22077 | } | |
2e276125 JB |
22078 | } |
22079 | break; | |
22080 | ||
0af92d60 | 22081 | case DW_MACRO_start_file: |
2e276125 | 22082 | { |
891d2f0b | 22083 | unsigned int bytes_read; |
2e276125 JB |
22084 | int line, file; |
22085 | ||
22086 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
22087 | mac_ptr += bytes_read; | |
22088 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
22089 | mac_ptr += bytes_read; | |
22090 | ||
3e43a32a MS |
22091 | if ((line == 0 && !at_commandline) |
22092 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
22093 | complaint (&symfile_complaints, |
22094 | _("debug info gives source %d included " | |
22095 | "from %s at %s line %d"), | |
22096 | file, at_commandline ? _("command-line") : _("file"), | |
22097 | line == 0 ? _("zero") : _("non-zero"), line); | |
22098 | ||
22099 | if (at_commandline) | |
22100 | { | |
0af92d60 | 22101 | /* This DW_MACRO_start_file was executed in the |
cf2c3c16 | 22102 | pass one. */ |
757a13d0 JK |
22103 | at_commandline = 0; |
22104 | } | |
22105 | else | |
43f3e411 | 22106 | current_file = macro_start_file (file, line, current_file, lh); |
2e276125 JB |
22107 | } |
22108 | break; | |
22109 | ||
0af92d60 | 22110 | case DW_MACRO_end_file: |
2e276125 | 22111 | if (! current_file) |
4d3c2250 | 22112 | complaint (&symfile_complaints, |
3e43a32a MS |
22113 | _("macro debug info has an unmatched " |
22114 | "`close_file' directive")); | |
2e276125 JB |
22115 | else |
22116 | { | |
22117 | current_file = current_file->included_by; | |
22118 | if (! current_file) | |
22119 | { | |
cf2c3c16 | 22120 | enum dwarf_macro_record_type next_type; |
2e276125 JB |
22121 | |
22122 | /* GCC circa March 2002 doesn't produce the zero | |
22123 | type byte marking the end of the compilation | |
22124 | unit. Complain if it's not there, but exit no | |
22125 | matter what. */ | |
22126 | ||
22127 | /* Do we at least have room for a macinfo type byte? */ | |
22128 | if (mac_ptr >= mac_end) | |
22129 | { | |
f664829e | 22130 | dwarf2_section_buffer_overflow_complaint (section); |
2e276125 JB |
22131 | return; |
22132 | } | |
22133 | ||
22134 | /* We don't increment mac_ptr here, so this is just | |
22135 | a look-ahead. */ | |
aead7601 SM |
22136 | next_type |
22137 | = (enum dwarf_macro_record_type) read_1_byte (abfd, | |
22138 | mac_ptr); | |
2e276125 | 22139 | if (next_type != 0) |
4d3c2250 | 22140 | complaint (&symfile_complaints, |
3e43a32a MS |
22141 | _("no terminating 0-type entry for " |
22142 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
22143 | |
22144 | return; | |
22145 | } | |
22146 | } | |
22147 | break; | |
22148 | ||
0af92d60 JK |
22149 | case DW_MACRO_import: |
22150 | case DW_MACRO_import_sup: | |
cf2c3c16 TT |
22151 | { |
22152 | LONGEST offset; | |
8fc3fc34 | 22153 | void **slot; |
a036ba48 TT |
22154 | bfd *include_bfd = abfd; |
22155 | struct dwarf2_section_info *include_section = section; | |
d521ce57 | 22156 | const gdb_byte *include_mac_end = mac_end; |
a036ba48 | 22157 | int is_dwz = section_is_dwz; |
d521ce57 | 22158 | const gdb_byte *new_mac_ptr; |
cf2c3c16 TT |
22159 | |
22160 | offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
22161 | mac_ptr += offset_size; | |
22162 | ||
0af92d60 | 22163 | if (macinfo_type == DW_MACRO_import_sup) |
a036ba48 TT |
22164 | { |
22165 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
22166 | ||
4d663531 | 22167 | dwarf2_read_section (objfile, &dwz->macro); |
a036ba48 | 22168 | |
a036ba48 | 22169 | include_section = &dwz->macro; |
a32a8923 | 22170 | include_bfd = get_section_bfd_owner (include_section); |
a036ba48 TT |
22171 | include_mac_end = dwz->macro.buffer + dwz->macro.size; |
22172 | is_dwz = 1; | |
22173 | } | |
22174 | ||
22175 | new_mac_ptr = include_section->buffer + offset; | |
22176 | slot = htab_find_slot (include_hash, new_mac_ptr, INSERT); | |
22177 | ||
8fc3fc34 TT |
22178 | if (*slot != NULL) |
22179 | { | |
22180 | /* This has actually happened; see | |
22181 | http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */ | |
22182 | complaint (&symfile_complaints, | |
0af92d60 | 22183 | _("recursive DW_MACRO_import in " |
8fc3fc34 TT |
22184 | ".debug_macro section")); |
22185 | } | |
22186 | else | |
22187 | { | |
d521ce57 | 22188 | *slot = (void *) new_mac_ptr; |
36586728 | 22189 | |
a036ba48 | 22190 | dwarf_decode_macro_bytes (include_bfd, new_mac_ptr, |
43f3e411 | 22191 | include_mac_end, current_file, lh, |
36586728 | 22192 | section, section_is_gnu, is_dwz, |
4d663531 | 22193 | offset_size, include_hash); |
8fc3fc34 | 22194 | |
d521ce57 | 22195 | htab_remove_elt (include_hash, (void *) new_mac_ptr); |
8fc3fc34 | 22196 | } |
cf2c3c16 TT |
22197 | } |
22198 | break; | |
22199 | ||
2e276125 | 22200 | case DW_MACINFO_vendor_ext: |
cf2c3c16 TT |
22201 | if (!section_is_gnu) |
22202 | { | |
22203 | unsigned int bytes_read; | |
2e276125 | 22204 | |
ac298888 TT |
22205 | /* This reads the constant, but since we don't recognize |
22206 | any vendor extensions, we ignore it. */ | |
22207 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
cf2c3c16 TT |
22208 | mac_ptr += bytes_read; |
22209 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
22210 | mac_ptr += bytes_read; | |
2e276125 | 22211 | |
cf2c3c16 TT |
22212 | /* We don't recognize any vendor extensions. */ |
22213 | break; | |
22214 | } | |
22215 | /* FALLTHROUGH */ | |
22216 | ||
22217 | default: | |
22218 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
f664829e | 22219 | mac_ptr, mac_end, abfd, offset_size, |
cf2c3c16 TT |
22220 | section); |
22221 | if (mac_ptr == NULL) | |
22222 | return; | |
22223 | break; | |
2e276125 | 22224 | } |
757a13d0 | 22225 | } while (macinfo_type != 0); |
2e276125 | 22226 | } |
8e19ed76 | 22227 | |
cf2c3c16 | 22228 | static void |
09262596 | 22229 | dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset, |
43f3e411 | 22230 | int section_is_gnu) |
cf2c3c16 | 22231 | { |
bb5ed363 | 22232 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
09262596 DE |
22233 | struct line_header *lh = cu->line_header; |
22234 | bfd *abfd; | |
d521ce57 | 22235 | const gdb_byte *mac_ptr, *mac_end; |
cf2c3c16 TT |
22236 | struct macro_source_file *current_file = 0; |
22237 | enum dwarf_macro_record_type macinfo_type; | |
22238 | unsigned int offset_size = cu->header.offset_size; | |
d521ce57 | 22239 | const gdb_byte *opcode_definitions[256]; |
8fc3fc34 | 22240 | struct cleanup *cleanup; |
8fc3fc34 | 22241 | void **slot; |
09262596 DE |
22242 | struct dwarf2_section_info *section; |
22243 | const char *section_name; | |
22244 | ||
22245 | if (cu->dwo_unit != NULL) | |
22246 | { | |
22247 | if (section_is_gnu) | |
22248 | { | |
22249 | section = &cu->dwo_unit->dwo_file->sections.macro; | |
22250 | section_name = ".debug_macro.dwo"; | |
22251 | } | |
22252 | else | |
22253 | { | |
22254 | section = &cu->dwo_unit->dwo_file->sections.macinfo; | |
22255 | section_name = ".debug_macinfo.dwo"; | |
22256 | } | |
22257 | } | |
22258 | else | |
22259 | { | |
22260 | if (section_is_gnu) | |
22261 | { | |
22262 | section = &dwarf2_per_objfile->macro; | |
22263 | section_name = ".debug_macro"; | |
22264 | } | |
22265 | else | |
22266 | { | |
22267 | section = &dwarf2_per_objfile->macinfo; | |
22268 | section_name = ".debug_macinfo"; | |
22269 | } | |
22270 | } | |
cf2c3c16 | 22271 | |
bb5ed363 | 22272 | dwarf2_read_section (objfile, section); |
cf2c3c16 TT |
22273 | if (section->buffer == NULL) |
22274 | { | |
fceca515 | 22275 | complaint (&symfile_complaints, _("missing %s section"), section_name); |
cf2c3c16 TT |
22276 | return; |
22277 | } | |
a32a8923 | 22278 | abfd = get_section_bfd_owner (section); |
cf2c3c16 TT |
22279 | |
22280 | /* First pass: Find the name of the base filename. | |
22281 | This filename is needed in order to process all macros whose definition | |
22282 | (or undefinition) comes from the command line. These macros are defined | |
22283 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
22284 | associated to the base file. | |
22285 | ||
22286 | To determine the base file name, we scan the macro definitions until we | |
22287 | reach the first DW_MACINFO_start_file entry. We then initialize | |
22288 | CURRENT_FILE accordingly so that any macro definition found before the | |
22289 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
22290 | ||
22291 | mac_ptr = section->buffer + offset; | |
22292 | mac_end = section->buffer + section->size; | |
22293 | ||
22294 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, | |
22295 | &offset_size, section_is_gnu); | |
22296 | if (mac_ptr == NULL) | |
22297 | { | |
22298 | /* We already issued a complaint. */ | |
22299 | return; | |
22300 | } | |
22301 | ||
22302 | do | |
22303 | { | |
22304 | /* Do we at least have room for a macinfo type byte? */ | |
22305 | if (mac_ptr >= mac_end) | |
22306 | { | |
22307 | /* Complaint is printed during the second pass as GDB will probably | |
22308 | stop the first pass earlier upon finding | |
22309 | DW_MACINFO_start_file. */ | |
22310 | break; | |
22311 | } | |
22312 | ||
aead7601 | 22313 | macinfo_type = (enum dwarf_macro_record_type) read_1_byte (abfd, mac_ptr); |
cf2c3c16 TT |
22314 | mac_ptr++; |
22315 | ||
22316 | /* Note that we rely on the fact that the corresponding GNU and | |
22317 | DWARF constants are the same. */ | |
22318 | switch (macinfo_type) | |
22319 | { | |
22320 | /* A zero macinfo type indicates the end of the macro | |
22321 | information. */ | |
22322 | case 0: | |
22323 | break; | |
22324 | ||
0af92d60 JK |
22325 | case DW_MACRO_define: |
22326 | case DW_MACRO_undef: | |
cf2c3c16 TT |
22327 | /* Only skip the data by MAC_PTR. */ |
22328 | { | |
22329 | unsigned int bytes_read; | |
22330 | ||
22331 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
22332 | mac_ptr += bytes_read; | |
22333 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
22334 | mac_ptr += bytes_read; | |
22335 | } | |
22336 | break; | |
22337 | ||
0af92d60 | 22338 | case DW_MACRO_start_file: |
cf2c3c16 TT |
22339 | { |
22340 | unsigned int bytes_read; | |
22341 | int line, file; | |
22342 | ||
22343 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
22344 | mac_ptr += bytes_read; | |
22345 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
22346 | mac_ptr += bytes_read; | |
22347 | ||
43f3e411 | 22348 | current_file = macro_start_file (file, line, current_file, lh); |
cf2c3c16 TT |
22349 | } |
22350 | break; | |
22351 | ||
0af92d60 | 22352 | case DW_MACRO_end_file: |
cf2c3c16 TT |
22353 | /* No data to skip by MAC_PTR. */ |
22354 | break; | |
22355 | ||
0af92d60 JK |
22356 | case DW_MACRO_define_strp: |
22357 | case DW_MACRO_undef_strp: | |
22358 | case DW_MACRO_define_sup: | |
22359 | case DW_MACRO_undef_sup: | |
cf2c3c16 TT |
22360 | { |
22361 | unsigned int bytes_read; | |
22362 | ||
22363 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
22364 | mac_ptr += bytes_read; | |
22365 | mac_ptr += offset_size; | |
22366 | } | |
22367 | break; | |
22368 | ||
0af92d60 JK |
22369 | case DW_MACRO_import: |
22370 | case DW_MACRO_import_sup: | |
cf2c3c16 | 22371 | /* Note that, according to the spec, a transparent include |
0af92d60 | 22372 | chain cannot call DW_MACRO_start_file. So, we can just |
cf2c3c16 TT |
22373 | skip this opcode. */ |
22374 | mac_ptr += offset_size; | |
22375 | break; | |
22376 | ||
22377 | case DW_MACINFO_vendor_ext: | |
22378 | /* Only skip the data by MAC_PTR. */ | |
22379 | if (!section_is_gnu) | |
22380 | { | |
22381 | unsigned int bytes_read; | |
22382 | ||
22383 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
22384 | mac_ptr += bytes_read; | |
22385 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
22386 | mac_ptr += bytes_read; | |
22387 | } | |
22388 | /* FALLTHROUGH */ | |
22389 | ||
22390 | default: | |
22391 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
f664829e | 22392 | mac_ptr, mac_end, abfd, offset_size, |
cf2c3c16 TT |
22393 | section); |
22394 | if (mac_ptr == NULL) | |
22395 | return; | |
22396 | break; | |
22397 | } | |
22398 | } while (macinfo_type != 0 && current_file == NULL); | |
22399 | ||
22400 | /* Second pass: Process all entries. | |
22401 | ||
22402 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
22403 | command-line macro definitions/undefinitions. This flag is unset when we | |
22404 | reach the first DW_MACINFO_start_file entry. */ | |
22405 | ||
fc4007c9 TT |
22406 | htab_up include_hash (htab_create_alloc (1, htab_hash_pointer, |
22407 | htab_eq_pointer, | |
22408 | NULL, xcalloc, xfree)); | |
8fc3fc34 | 22409 | mac_ptr = section->buffer + offset; |
fc4007c9 | 22410 | slot = htab_find_slot (include_hash.get (), mac_ptr, INSERT); |
d521ce57 | 22411 | *slot = (void *) mac_ptr; |
8fc3fc34 | 22412 | dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end, |
43f3e411 | 22413 | current_file, lh, section, |
fc4007c9 TT |
22414 | section_is_gnu, 0, offset_size, |
22415 | include_hash.get ()); | |
cf2c3c16 TT |
22416 | } |
22417 | ||
8e19ed76 | 22418 | /* Check if the attribute's form is a DW_FORM_block* |
0963b4bd | 22419 | if so return true else false. */ |
380bca97 | 22420 | |
8e19ed76 | 22421 | static int |
6e5a29e1 | 22422 | attr_form_is_block (const struct attribute *attr) |
8e19ed76 PS |
22423 | { |
22424 | return (attr == NULL ? 0 : | |
22425 | attr->form == DW_FORM_block1 | |
22426 | || attr->form == DW_FORM_block2 | |
22427 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
22428 | || attr->form == DW_FORM_block |
22429 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 22430 | } |
4c2df51b | 22431 | |
c6a0999f JB |
22432 | /* Return non-zero if ATTR's value is a section offset --- classes |
22433 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
22434 | You may use DW_UNSND (attr) to retrieve such offsets. | |
22435 | ||
22436 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
22437 | may have a value that belongs to more than one of these classes; it | |
22438 | would be ambiguous if we did, because we use the same forms for all | |
22439 | of them. */ | |
380bca97 | 22440 | |
3690dd37 | 22441 | static int |
6e5a29e1 | 22442 | attr_form_is_section_offset (const struct attribute *attr) |
3690dd37 JB |
22443 | { |
22444 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
22445 | || attr->form == DW_FORM_data8 |
22446 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
22447 | } |
22448 | ||
3690dd37 JB |
22449 | /* Return non-zero if ATTR's value falls in the 'constant' class, or |
22450 | zero otherwise. When this function returns true, you can apply | |
22451 | dwarf2_get_attr_constant_value to it. | |
22452 | ||
22453 | However, note that for some attributes you must check | |
22454 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
22455 | and DW_FORM_data8 are members of both the constant class, and of | |
22456 | the classes that contain offsets into other debug sections | |
22457 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
22458 | that, if an attribute's can be either a constant or one of the | |
22459 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
0224619f JK |
22460 | taken as section offsets, not constants. |
22461 | ||
22462 | DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value | |
22463 | cannot handle that. */ | |
380bca97 | 22464 | |
3690dd37 | 22465 | static int |
6e5a29e1 | 22466 | attr_form_is_constant (const struct attribute *attr) |
3690dd37 JB |
22467 | { |
22468 | switch (attr->form) | |
22469 | { | |
22470 | case DW_FORM_sdata: | |
22471 | case DW_FORM_udata: | |
22472 | case DW_FORM_data1: | |
22473 | case DW_FORM_data2: | |
22474 | case DW_FORM_data4: | |
22475 | case DW_FORM_data8: | |
22476 | return 1; | |
22477 | default: | |
22478 | return 0; | |
22479 | } | |
22480 | } | |
22481 | ||
7771576e SA |
22482 | |
22483 | /* DW_ADDR is always stored already as sect_offset; despite for the forms | |
22484 | besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ | |
22485 | ||
22486 | static int | |
6e5a29e1 | 22487 | attr_form_is_ref (const struct attribute *attr) |
7771576e SA |
22488 | { |
22489 | switch (attr->form) | |
22490 | { | |
22491 | case DW_FORM_ref_addr: | |
22492 | case DW_FORM_ref1: | |
22493 | case DW_FORM_ref2: | |
22494 | case DW_FORM_ref4: | |
22495 | case DW_FORM_ref8: | |
22496 | case DW_FORM_ref_udata: | |
22497 | case DW_FORM_GNU_ref_alt: | |
22498 | return 1; | |
22499 | default: | |
22500 | return 0; | |
22501 | } | |
22502 | } | |
22503 | ||
3019eac3 DE |
22504 | /* Return the .debug_loc section to use for CU. |
22505 | For DWO files use .debug_loc.dwo. */ | |
22506 | ||
22507 | static struct dwarf2_section_info * | |
22508 | cu_debug_loc_section (struct dwarf2_cu *cu) | |
22509 | { | |
22510 | if (cu->dwo_unit) | |
43988095 JK |
22511 | { |
22512 | struct dwo_sections *sections = &cu->dwo_unit->dwo_file->sections; | |
22513 | ||
22514 | return cu->header.version >= 5 ? §ions->loclists : §ions->loc; | |
22515 | } | |
22516 | return (cu->header.version >= 5 ? &dwarf2_per_objfile->loclists | |
22517 | : &dwarf2_per_objfile->loc); | |
3019eac3 DE |
22518 | } |
22519 | ||
8cf6f0b1 TT |
22520 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
22521 | ||
22522 | static void | |
22523 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
22524 | struct dwarf2_loclist_baton *baton, | |
ff39bb5e | 22525 | const struct attribute *attr) |
8cf6f0b1 | 22526 | { |
3019eac3 DE |
22527 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
22528 | ||
22529 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); | |
8cf6f0b1 TT |
22530 | |
22531 | baton->per_cu = cu->per_cu; | |
22532 | gdb_assert (baton->per_cu); | |
22533 | /* We don't know how long the location list is, but make sure we | |
22534 | don't run off the edge of the section. */ | |
3019eac3 DE |
22535 | baton->size = section->size - DW_UNSND (attr); |
22536 | baton->data = section->buffer + DW_UNSND (attr); | |
8cf6f0b1 | 22537 | baton->base_address = cu->base_address; |
f664829e | 22538 | baton->from_dwo = cu->dwo_unit != NULL; |
8cf6f0b1 TT |
22539 | } |
22540 | ||
4c2df51b | 22541 | static void |
ff39bb5e | 22542 | dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym, |
f1e6e072 | 22543 | struct dwarf2_cu *cu, int is_block) |
4c2df51b | 22544 | { |
bb5ed363 | 22545 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
3019eac3 | 22546 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
bb5ed363 | 22547 | |
3690dd37 | 22548 | if (attr_form_is_section_offset (attr) |
3019eac3 | 22549 | /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside |
99bcc461 DJ |
22550 | the section. If so, fall through to the complaint in the |
22551 | other branch. */ | |
3019eac3 | 22552 | && DW_UNSND (attr) < dwarf2_section_size (objfile, section)) |
4c2df51b | 22553 | { |
0d53c4c4 | 22554 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 22555 | |
8d749320 | 22556 | baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_loclist_baton); |
4c2df51b | 22557 | |
8cf6f0b1 | 22558 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 22559 | |
d00adf39 | 22560 | if (cu->base_known == 0) |
0d53c4c4 | 22561 | complaint (&symfile_complaints, |
3e43a32a MS |
22562 | _("Location list used without " |
22563 | "specifying the CU base address.")); | |
4c2df51b | 22564 | |
f1e6e072 TT |
22565 | SYMBOL_ACLASS_INDEX (sym) = (is_block |
22566 | ? dwarf2_loclist_block_index | |
22567 | : dwarf2_loclist_index); | |
0d53c4c4 DJ |
22568 | SYMBOL_LOCATION_BATON (sym) = baton; |
22569 | } | |
22570 | else | |
22571 | { | |
22572 | struct dwarf2_locexpr_baton *baton; | |
22573 | ||
8d749320 | 22574 | baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton); |
ae0d2f24 UW |
22575 | baton->per_cu = cu->per_cu; |
22576 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
22577 | |
22578 | if (attr_form_is_block (attr)) | |
22579 | { | |
22580 | /* Note that we're just copying the block's data pointer | |
22581 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
22582 | info_buffer for SYM's objfile; right now we never release |
22583 | that buffer, but when we do clean up properly this may | |
22584 | need to change. */ | |
0d53c4c4 DJ |
22585 | baton->size = DW_BLOCK (attr)->size; |
22586 | baton->data = DW_BLOCK (attr)->data; | |
22587 | } | |
22588 | else | |
22589 | { | |
22590 | dwarf2_invalid_attrib_class_complaint ("location description", | |
22591 | SYMBOL_NATURAL_NAME (sym)); | |
22592 | baton->size = 0; | |
0d53c4c4 | 22593 | } |
6e70227d | 22594 | |
f1e6e072 TT |
22595 | SYMBOL_ACLASS_INDEX (sym) = (is_block |
22596 | ? dwarf2_locexpr_block_index | |
22597 | : dwarf2_locexpr_index); | |
0d53c4c4 DJ |
22598 | SYMBOL_LOCATION_BATON (sym) = baton; |
22599 | } | |
4c2df51b | 22600 | } |
6502dd73 | 22601 | |
9aa1f1e3 TT |
22602 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
22603 | came from a separate debuginfo file, then the master objfile is | |
22604 | returned. */ | |
ae0d2f24 UW |
22605 | |
22606 | struct objfile * | |
22607 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
22608 | { | |
9291a0cd | 22609 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
22610 | |
22611 | /* Return the master objfile, so that we can report and look up the | |
22612 | correct file containing this variable. */ | |
22613 | if (objfile->separate_debug_objfile_backlink) | |
22614 | objfile = objfile->separate_debug_objfile_backlink; | |
22615 | ||
22616 | return objfile; | |
22617 | } | |
22618 | ||
96408a79 SA |
22619 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
22620 | (CU_HEADERP is unused in such case) or prepare a temporary copy at | |
22621 | CU_HEADERP first. */ | |
22622 | ||
22623 | static const struct comp_unit_head * | |
22624 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, | |
22625 | struct dwarf2_per_cu_data *per_cu) | |
22626 | { | |
d521ce57 | 22627 | const gdb_byte *info_ptr; |
96408a79 SA |
22628 | |
22629 | if (per_cu->cu) | |
22630 | return &per_cu->cu->header; | |
22631 | ||
9c541725 | 22632 | info_ptr = per_cu->section->buffer + to_underlying (per_cu->sect_off); |
96408a79 SA |
22633 | |
22634 | memset (cu_headerp, 0, sizeof (*cu_headerp)); | |
43988095 JK |
22635 | read_comp_unit_head (cu_headerp, info_ptr, per_cu->section, |
22636 | rcuh_kind::COMPILE); | |
96408a79 SA |
22637 | |
22638 | return cu_headerp; | |
22639 | } | |
22640 | ||
ae0d2f24 UW |
22641 | /* Return the address size given in the compilation unit header for CU. */ |
22642 | ||
98714339 | 22643 | int |
ae0d2f24 UW |
22644 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
22645 | { | |
96408a79 SA |
22646 | struct comp_unit_head cu_header_local; |
22647 | const struct comp_unit_head *cu_headerp; | |
c471e790 | 22648 | |
96408a79 SA |
22649 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
22650 | ||
22651 | return cu_headerp->addr_size; | |
ae0d2f24 UW |
22652 | } |
22653 | ||
9eae7c52 TT |
22654 | /* Return the offset size given in the compilation unit header for CU. */ |
22655 | ||
22656 | int | |
22657 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
22658 | { | |
96408a79 SA |
22659 | struct comp_unit_head cu_header_local; |
22660 | const struct comp_unit_head *cu_headerp; | |
9c6c53f7 | 22661 | |
96408a79 SA |
22662 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
22663 | ||
22664 | return cu_headerp->offset_size; | |
22665 | } | |
22666 | ||
22667 | /* See its dwarf2loc.h declaration. */ | |
22668 | ||
22669 | int | |
22670 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) | |
22671 | { | |
22672 | struct comp_unit_head cu_header_local; | |
22673 | const struct comp_unit_head *cu_headerp; | |
22674 | ||
22675 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); | |
22676 | ||
22677 | if (cu_headerp->version == 2) | |
22678 | return cu_headerp->addr_size; | |
22679 | else | |
22680 | return cu_headerp->offset_size; | |
181cebd4 JK |
22681 | } |
22682 | ||
9aa1f1e3 TT |
22683 | /* Return the text offset of the CU. The returned offset comes from |
22684 | this CU's objfile. If this objfile came from a separate debuginfo | |
22685 | file, then the offset may be different from the corresponding | |
22686 | offset in the parent objfile. */ | |
22687 | ||
22688 | CORE_ADDR | |
22689 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
22690 | { | |
bb3fa9d0 | 22691 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
22692 | |
22693 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
22694 | } | |
22695 | ||
43988095 JK |
22696 | /* Return DWARF version number of PER_CU. */ |
22697 | ||
22698 | short | |
22699 | dwarf2_version (struct dwarf2_per_cu_data *per_cu) | |
22700 | { | |
22701 | return per_cu->dwarf_version; | |
22702 | } | |
22703 | ||
348e048f DE |
22704 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
22705 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
22706 | |
22707 | static struct dwarf2_per_cu_data * | |
9c541725 | 22708 | dwarf2_find_containing_comp_unit (sect_offset sect_off, |
36586728 | 22709 | unsigned int offset_in_dwz, |
ae038cb0 DJ |
22710 | struct objfile *objfile) |
22711 | { | |
22712 | struct dwarf2_per_cu_data *this_cu; | |
22713 | int low, high; | |
36586728 | 22714 | const sect_offset *cu_off; |
ae038cb0 | 22715 | |
ae038cb0 DJ |
22716 | low = 0; |
22717 | high = dwarf2_per_objfile->n_comp_units - 1; | |
22718 | while (high > low) | |
22719 | { | |
36586728 | 22720 | struct dwarf2_per_cu_data *mid_cu; |
ae038cb0 | 22721 | int mid = low + (high - low) / 2; |
9a619af0 | 22722 | |
36586728 | 22723 | mid_cu = dwarf2_per_objfile->all_comp_units[mid]; |
9c541725 | 22724 | cu_off = &mid_cu->sect_off; |
36586728 | 22725 | if (mid_cu->is_dwz > offset_in_dwz |
9c541725 | 22726 | || (mid_cu->is_dwz == offset_in_dwz && *cu_off >= sect_off)) |
ae038cb0 DJ |
22727 | high = mid; |
22728 | else | |
22729 | low = mid + 1; | |
22730 | } | |
22731 | gdb_assert (low == high); | |
36586728 | 22732 | this_cu = dwarf2_per_objfile->all_comp_units[low]; |
9c541725 PA |
22733 | cu_off = &this_cu->sect_off; |
22734 | if (this_cu->is_dwz != offset_in_dwz || *cu_off > sect_off) | |
ae038cb0 | 22735 | { |
36586728 | 22736 | if (low == 0 || this_cu->is_dwz != offset_in_dwz) |
8a3fe4f8 | 22737 | error (_("Dwarf Error: could not find partial DIE containing " |
9c541725 PA |
22738 | "offset 0x%x [in module %s]"), |
22739 | to_underlying (sect_off), bfd_get_filename (objfile->obfd)); | |
10b3939b | 22740 | |
9c541725 PA |
22741 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->sect_off |
22742 | <= sect_off); | |
ae038cb0 DJ |
22743 | return dwarf2_per_objfile->all_comp_units[low-1]; |
22744 | } | |
22745 | else | |
22746 | { | |
22747 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
22748 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
9c541725 PA |
22749 | && sect_off >= this_cu->sect_off + this_cu->length) |
22750 | error (_("invalid dwarf2 offset %u"), to_underlying (sect_off)); | |
22751 | gdb_assert (sect_off < this_cu->sect_off + this_cu->length); | |
ae038cb0 DJ |
22752 | return this_cu; |
22753 | } | |
22754 | } | |
22755 | ||
23745b47 | 22756 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
93311388 | 22757 | |
9816fde3 | 22758 | static void |
23745b47 | 22759 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
93311388 | 22760 | { |
9816fde3 | 22761 | memset (cu, 0, sizeof (*cu)); |
23745b47 DE |
22762 | per_cu->cu = cu; |
22763 | cu->per_cu = per_cu; | |
22764 | cu->objfile = per_cu->objfile; | |
93311388 | 22765 | obstack_init (&cu->comp_unit_obstack); |
9816fde3 JK |
22766 | } |
22767 | ||
22768 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
22769 | ||
22770 | static void | |
95554aad TT |
22771 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die, |
22772 | enum language pretend_language) | |
9816fde3 JK |
22773 | { |
22774 | struct attribute *attr; | |
22775 | ||
22776 | /* Set the language we're debugging. */ | |
22777 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
22778 | if (attr) | |
22779 | set_cu_language (DW_UNSND (attr), cu); | |
22780 | else | |
9cded63f | 22781 | { |
95554aad | 22782 | cu->language = pretend_language; |
9cded63f TT |
22783 | cu->language_defn = language_def (cu->language); |
22784 | } | |
dee91e82 | 22785 | |
7d45c7c3 | 22786 | cu->producer = dwarf2_string_attr (comp_unit_die, DW_AT_producer, cu); |
93311388 DE |
22787 | } |
22788 | ||
ae038cb0 DJ |
22789 | /* Release one cached compilation unit, CU. We unlink it from the tree |
22790 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
22791 | the caller is responsible for that. |
22792 | NOTE: DATA is a void * because this function is also used as a | |
22793 | cleanup routine. */ | |
ae038cb0 DJ |
22794 | |
22795 | static void | |
68dc6402 | 22796 | free_heap_comp_unit (void *data) |
ae038cb0 | 22797 | { |
9a3c8263 | 22798 | struct dwarf2_cu *cu = (struct dwarf2_cu *) data; |
ae038cb0 | 22799 | |
23745b47 DE |
22800 | gdb_assert (cu->per_cu != NULL); |
22801 | cu->per_cu->cu = NULL; | |
ae038cb0 DJ |
22802 | cu->per_cu = NULL; |
22803 | ||
22804 | obstack_free (&cu->comp_unit_obstack, NULL); | |
22805 | ||
22806 | xfree (cu); | |
22807 | } | |
22808 | ||
72bf9492 | 22809 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 | 22810 | when we're finished with it. We can't free the pointer itself, but be |
dee91e82 | 22811 | sure to unlink it from the cache. Also release any associated storage. */ |
72bf9492 DJ |
22812 | |
22813 | static void | |
22814 | free_stack_comp_unit (void *data) | |
22815 | { | |
9a3c8263 | 22816 | struct dwarf2_cu *cu = (struct dwarf2_cu *) data; |
72bf9492 | 22817 | |
23745b47 DE |
22818 | gdb_assert (cu->per_cu != NULL); |
22819 | cu->per_cu->cu = NULL; | |
22820 | cu->per_cu = NULL; | |
22821 | ||
72bf9492 DJ |
22822 | obstack_free (&cu->comp_unit_obstack, NULL); |
22823 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
22824 | } |
22825 | ||
22826 | /* Free all cached compilation units. */ | |
22827 | ||
22828 | static void | |
22829 | free_cached_comp_units (void *data) | |
22830 | { | |
330cdd98 | 22831 | dwarf2_per_objfile->free_cached_comp_units (); |
ae038cb0 DJ |
22832 | } |
22833 | ||
22834 | /* Increase the age counter on each cached compilation unit, and free | |
22835 | any that are too old. */ | |
22836 | ||
22837 | static void | |
22838 | age_cached_comp_units (void) | |
22839 | { | |
22840 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
22841 | ||
22842 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
22843 | per_cu = dwarf2_per_objfile->read_in_chain; | |
22844 | while (per_cu != NULL) | |
22845 | { | |
22846 | per_cu->cu->last_used ++; | |
b4f54984 | 22847 | if (per_cu->cu->last_used <= dwarf_max_cache_age) |
ae038cb0 DJ |
22848 | dwarf2_mark (per_cu->cu); |
22849 | per_cu = per_cu->cu->read_in_chain; | |
22850 | } | |
22851 | ||
22852 | per_cu = dwarf2_per_objfile->read_in_chain; | |
22853 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
22854 | while (per_cu != NULL) | |
22855 | { | |
22856 | struct dwarf2_per_cu_data *next_cu; | |
22857 | ||
22858 | next_cu = per_cu->cu->read_in_chain; | |
22859 | ||
22860 | if (!per_cu->cu->mark) | |
22861 | { | |
68dc6402 | 22862 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
22863 | *last_chain = next_cu; |
22864 | } | |
22865 | else | |
22866 | last_chain = &per_cu->cu->read_in_chain; | |
22867 | ||
22868 | per_cu = next_cu; | |
22869 | } | |
22870 | } | |
22871 | ||
22872 | /* Remove a single compilation unit from the cache. */ | |
22873 | ||
22874 | static void | |
dee91e82 | 22875 | free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu) |
ae038cb0 DJ |
22876 | { |
22877 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
22878 | ||
22879 | per_cu = dwarf2_per_objfile->read_in_chain; | |
22880 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
22881 | while (per_cu != NULL) | |
22882 | { | |
22883 | struct dwarf2_per_cu_data *next_cu; | |
22884 | ||
22885 | next_cu = per_cu->cu->read_in_chain; | |
22886 | ||
dee91e82 | 22887 | if (per_cu == target_per_cu) |
ae038cb0 | 22888 | { |
68dc6402 | 22889 | free_heap_comp_unit (per_cu->cu); |
dee91e82 | 22890 | per_cu->cu = NULL; |
ae038cb0 DJ |
22891 | *last_chain = next_cu; |
22892 | break; | |
22893 | } | |
22894 | else | |
22895 | last_chain = &per_cu->cu->read_in_chain; | |
22896 | ||
22897 | per_cu = next_cu; | |
22898 | } | |
22899 | } | |
22900 | ||
fe3e1990 DJ |
22901 | /* Release all extra memory associated with OBJFILE. */ |
22902 | ||
22903 | void | |
22904 | dwarf2_free_objfile (struct objfile *objfile) | |
22905 | { | |
9a3c8263 SM |
22906 | dwarf2_per_objfile |
22907 | = (struct dwarf2_per_objfile *) objfile_data (objfile, | |
22908 | dwarf2_objfile_data_key); | |
fe3e1990 DJ |
22909 | |
22910 | if (dwarf2_per_objfile == NULL) | |
22911 | return; | |
22912 | ||
330cdd98 | 22913 | dwarf2_per_objfile->~dwarf2_per_objfile (); |
fe3e1990 DJ |
22914 | } |
22915 | ||
dee91e82 DE |
22916 | /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer. |
22917 | We store these in a hash table separate from the DIEs, and preserve them | |
22918 | when the DIEs are flushed out of cache. | |
22919 | ||
22920 | The CU "per_cu" pointer is needed because offset alone is not enough to | |
3019eac3 | 22921 | uniquely identify the type. A file may have multiple .debug_types sections, |
c88ee1f0 DE |
22922 | or the type may come from a DWO file. Furthermore, while it's more logical |
22923 | to use per_cu->section+offset, with Fission the section with the data is in | |
22924 | the DWO file but we don't know that section at the point we need it. | |
22925 | We have to use something in dwarf2_per_cu_data (or the pointer to it) | |
22926 | because we can enter the lookup routine, get_die_type_at_offset, from | |
22927 | outside this file, and thus won't necessarily have PER_CU->cu. | |
22928 | Fortunately, PER_CU is stable for the life of the objfile. */ | |
1c379e20 | 22929 | |
dee91e82 | 22930 | struct dwarf2_per_cu_offset_and_type |
1c379e20 | 22931 | { |
dee91e82 | 22932 | const struct dwarf2_per_cu_data *per_cu; |
9c541725 | 22933 | sect_offset sect_off; |
1c379e20 DJ |
22934 | struct type *type; |
22935 | }; | |
22936 | ||
dee91e82 | 22937 | /* Hash function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
22938 | |
22939 | static hashval_t | |
dee91e82 | 22940 | per_cu_offset_and_type_hash (const void *item) |
1c379e20 | 22941 | { |
9a3c8263 SM |
22942 | const struct dwarf2_per_cu_offset_and_type *ofs |
22943 | = (const struct dwarf2_per_cu_offset_and_type *) item; | |
9a619af0 | 22944 | |
9c541725 | 22945 | return (uintptr_t) ofs->per_cu + to_underlying (ofs->sect_off); |
1c379e20 DJ |
22946 | } |
22947 | ||
dee91e82 | 22948 | /* Equality function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
22949 | |
22950 | static int | |
dee91e82 | 22951 | per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs) |
1c379e20 | 22952 | { |
9a3c8263 SM |
22953 | const struct dwarf2_per_cu_offset_and_type *ofs_lhs |
22954 | = (const struct dwarf2_per_cu_offset_and_type *) item_lhs; | |
22955 | const struct dwarf2_per_cu_offset_and_type *ofs_rhs | |
22956 | = (const struct dwarf2_per_cu_offset_and_type *) item_rhs; | |
9a619af0 | 22957 | |
dee91e82 | 22958 | return (ofs_lhs->per_cu == ofs_rhs->per_cu |
9c541725 | 22959 | && ofs_lhs->sect_off == ofs_rhs->sect_off); |
1c379e20 DJ |
22960 | } |
22961 | ||
22962 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
22963 | table if necessary. For convenience, return TYPE. |
22964 | ||
22965 | The DIEs reading must have careful ordering to: | |
22966 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
22967 | reading current DIE. | |
22968 | * Not trying to dereference contents of still incompletely read in types | |
22969 | while reading in other DIEs. | |
22970 | * Enable referencing still incompletely read in types just by a pointer to | |
22971 | the type without accessing its fields. | |
22972 | ||
22973 | Therefore caller should follow these rules: | |
22974 | * Try to fetch any prerequisite types we may need to build this DIE type | |
22975 | before building the type and calling set_die_type. | |
e71ec853 | 22976 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
22977 | possible before fetching more types to complete the current type. |
22978 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 22979 | |
f792889a | 22980 | static struct type * |
1c379e20 DJ |
22981 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
22982 | { | |
dee91e82 | 22983 | struct dwarf2_per_cu_offset_and_type **slot, ofs; |
673bfd45 | 22984 | struct objfile *objfile = cu->objfile; |
3cdcd0ce JB |
22985 | struct attribute *attr; |
22986 | struct dynamic_prop prop; | |
1c379e20 | 22987 | |
b4ba55a1 JB |
22988 | /* For Ada types, make sure that the gnat-specific data is always |
22989 | initialized (if not already set). There are a few types where | |
22990 | we should not be doing so, because the type-specific area is | |
22991 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
22992 | where the type-specific area is used to store the floatformat). | |
22993 | But this is not a problem, because the gnat-specific information | |
22994 | is actually not needed for these types. */ | |
22995 | if (need_gnat_info (cu) | |
22996 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
22997 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
09e2d7c7 DE |
22998 | && TYPE_CODE (type) != TYPE_CODE_METHODPTR |
22999 | && TYPE_CODE (type) != TYPE_CODE_MEMBERPTR | |
23000 | && TYPE_CODE (type) != TYPE_CODE_METHOD | |
b4ba55a1 JB |
23001 | && !HAVE_GNAT_AUX_INFO (type)) |
23002 | INIT_GNAT_SPECIFIC (type); | |
23003 | ||
3f2f83dd KB |
23004 | /* Read DW_AT_allocated and set in type. */ |
23005 | attr = dwarf2_attr (die, DW_AT_allocated, cu); | |
23006 | if (attr_form_is_block (attr)) | |
23007 | { | |
23008 | if (attr_to_dynamic_prop (attr, die, cu, &prop)) | |
23009 | add_dyn_prop (DYN_PROP_ALLOCATED, prop, type, objfile); | |
23010 | } | |
23011 | else if (attr != NULL) | |
23012 | { | |
23013 | complaint (&symfile_complaints, | |
9c541725 PA |
23014 | _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"), |
23015 | (attr != NULL ? dwarf_form_name (attr->form) : "n/a"), | |
23016 | to_underlying (die->sect_off)); | |
3f2f83dd KB |
23017 | } |
23018 | ||
23019 | /* Read DW_AT_associated and set in type. */ | |
23020 | attr = dwarf2_attr (die, DW_AT_associated, cu); | |
23021 | if (attr_form_is_block (attr)) | |
23022 | { | |
23023 | if (attr_to_dynamic_prop (attr, die, cu, &prop)) | |
23024 | add_dyn_prop (DYN_PROP_ASSOCIATED, prop, type, objfile); | |
23025 | } | |
23026 | else if (attr != NULL) | |
23027 | { | |
23028 | complaint (&symfile_complaints, | |
9c541725 PA |
23029 | _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"), |
23030 | (attr != NULL ? dwarf_form_name (attr->form) : "n/a"), | |
23031 | to_underlying (die->sect_off)); | |
3f2f83dd KB |
23032 | } |
23033 | ||
3cdcd0ce JB |
23034 | /* Read DW_AT_data_location and set in type. */ |
23035 | attr = dwarf2_attr (die, DW_AT_data_location, cu); | |
23036 | if (attr_to_dynamic_prop (attr, die, cu, &prop)) | |
93a8e227 | 23037 | add_dyn_prop (DYN_PROP_DATA_LOCATION, prop, type, objfile); |
3cdcd0ce | 23038 | |
dee91e82 | 23039 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 23040 | { |
dee91e82 DE |
23041 | dwarf2_per_objfile->die_type_hash = |
23042 | htab_create_alloc_ex (127, | |
23043 | per_cu_offset_and_type_hash, | |
23044 | per_cu_offset_and_type_eq, | |
23045 | NULL, | |
23046 | &objfile->objfile_obstack, | |
23047 | hashtab_obstack_allocate, | |
23048 | dummy_obstack_deallocate); | |
f792889a | 23049 | } |
1c379e20 | 23050 | |
dee91e82 | 23051 | ofs.per_cu = cu->per_cu; |
9c541725 | 23052 | ofs.sect_off = die->sect_off; |
1c379e20 | 23053 | ofs.type = type; |
dee91e82 DE |
23054 | slot = (struct dwarf2_per_cu_offset_and_type **) |
23055 | htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT); | |
7e314c57 JK |
23056 | if (*slot) |
23057 | complaint (&symfile_complaints, | |
23058 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
9c541725 | 23059 | to_underlying (die->sect_off)); |
8d749320 SM |
23060 | *slot = XOBNEW (&objfile->objfile_obstack, |
23061 | struct dwarf2_per_cu_offset_and_type); | |
1c379e20 | 23062 | **slot = ofs; |
f792889a | 23063 | return type; |
1c379e20 DJ |
23064 | } |
23065 | ||
9c541725 | 23066 | /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash, |
02142a6c | 23067 | or return NULL if the die does not have a saved type. */ |
1c379e20 DJ |
23068 | |
23069 | static struct type * | |
9c541725 | 23070 | get_die_type_at_offset (sect_offset sect_off, |
673bfd45 | 23071 | struct dwarf2_per_cu_data *per_cu) |
1c379e20 | 23072 | { |
dee91e82 | 23073 | struct dwarf2_per_cu_offset_and_type *slot, ofs; |
f792889a | 23074 | |
dee91e82 | 23075 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 23076 | return NULL; |
1c379e20 | 23077 | |
dee91e82 | 23078 | ofs.per_cu = per_cu; |
9c541725 | 23079 | ofs.sect_off = sect_off; |
9a3c8263 SM |
23080 | slot = ((struct dwarf2_per_cu_offset_and_type *) |
23081 | htab_find (dwarf2_per_objfile->die_type_hash, &ofs)); | |
1c379e20 DJ |
23082 | if (slot) |
23083 | return slot->type; | |
23084 | else | |
23085 | return NULL; | |
23086 | } | |
23087 | ||
02142a6c | 23088 | /* Look up the type for DIE in CU in die_type_hash, |
673bfd45 DE |
23089 | or return NULL if DIE does not have a saved type. */ |
23090 | ||
23091 | static struct type * | |
23092 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
23093 | { | |
9c541725 | 23094 | return get_die_type_at_offset (die->sect_off, cu->per_cu); |
673bfd45 DE |
23095 | } |
23096 | ||
10b3939b DJ |
23097 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
23098 | ||
23099 | static void | |
23100 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
23101 | struct dwarf2_per_cu_data *ref_per_cu) | |
23102 | { | |
23103 | void **slot; | |
23104 | ||
23105 | if (cu->dependencies == NULL) | |
23106 | cu->dependencies | |
23107 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
23108 | NULL, &cu->comp_unit_obstack, | |
23109 | hashtab_obstack_allocate, | |
23110 | dummy_obstack_deallocate); | |
23111 | ||
23112 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
23113 | if (*slot == NULL) | |
23114 | *slot = ref_per_cu; | |
23115 | } | |
1c379e20 | 23116 | |
f504f079 DE |
23117 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
23118 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
23119 | cache that we must keep because we are keeping CU. */ |
23120 | ||
10b3939b DJ |
23121 | static int |
23122 | dwarf2_mark_helper (void **slot, void *data) | |
23123 | { | |
23124 | struct dwarf2_per_cu_data *per_cu; | |
23125 | ||
23126 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
d07ed419 JK |
23127 | |
23128 | /* cu->dependencies references may not yet have been ever read if QUIT aborts | |
23129 | reading of the chain. As such dependencies remain valid it is not much | |
23130 | useful to track and undo them during QUIT cleanups. */ | |
23131 | if (per_cu->cu == NULL) | |
23132 | return 1; | |
23133 | ||
10b3939b DJ |
23134 | if (per_cu->cu->mark) |
23135 | return 1; | |
23136 | per_cu->cu->mark = 1; | |
23137 | ||
23138 | if (per_cu->cu->dependencies != NULL) | |
23139 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
23140 | ||
23141 | return 1; | |
23142 | } | |
23143 | ||
f504f079 DE |
23144 | /* Set the mark field in CU and in every other compilation unit in the |
23145 | cache that we must keep because we are keeping CU. */ | |
23146 | ||
ae038cb0 DJ |
23147 | static void |
23148 | dwarf2_mark (struct dwarf2_cu *cu) | |
23149 | { | |
23150 | if (cu->mark) | |
23151 | return; | |
23152 | cu->mark = 1; | |
10b3939b DJ |
23153 | if (cu->dependencies != NULL) |
23154 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
23155 | } |
23156 | ||
23157 | static void | |
23158 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
23159 | { | |
23160 | while (per_cu) | |
23161 | { | |
23162 | per_cu->cu->mark = 0; | |
23163 | per_cu = per_cu->cu->read_in_chain; | |
23164 | } | |
72bf9492 DJ |
23165 | } |
23166 | ||
72bf9492 DJ |
23167 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
23168 | is its offset in .debug_info for this objfile. */ | |
23169 | ||
23170 | static hashval_t | |
23171 | partial_die_hash (const void *item) | |
23172 | { | |
9a3c8263 SM |
23173 | const struct partial_die_info *part_die |
23174 | = (const struct partial_die_info *) item; | |
9a619af0 | 23175 | |
9c541725 | 23176 | return to_underlying (part_die->sect_off); |
72bf9492 DJ |
23177 | } |
23178 | ||
23179 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
23180 | are equal if they have the same offset. */ | |
23181 | ||
23182 | static int | |
23183 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
23184 | { | |
9a3c8263 SM |
23185 | const struct partial_die_info *part_die_lhs |
23186 | = (const struct partial_die_info *) item_lhs; | |
23187 | const struct partial_die_info *part_die_rhs | |
23188 | = (const struct partial_die_info *) item_rhs; | |
9a619af0 | 23189 | |
9c541725 | 23190 | return part_die_lhs->sect_off == part_die_rhs->sect_off; |
72bf9492 DJ |
23191 | } |
23192 | ||
b4f54984 DE |
23193 | static struct cmd_list_element *set_dwarf_cmdlist; |
23194 | static struct cmd_list_element *show_dwarf_cmdlist; | |
ae038cb0 DJ |
23195 | |
23196 | static void | |
b4f54984 | 23197 | set_dwarf_cmd (char *args, int from_tty) |
ae038cb0 | 23198 | { |
b4f54984 | 23199 | help_list (set_dwarf_cmdlist, "maintenance set dwarf ", all_commands, |
635c7e8a | 23200 | gdb_stdout); |
ae038cb0 DJ |
23201 | } |
23202 | ||
23203 | static void | |
b4f54984 | 23204 | show_dwarf_cmd (char *args, int from_tty) |
6e70227d | 23205 | { |
b4f54984 | 23206 | cmd_show_list (show_dwarf_cmdlist, from_tty, ""); |
ae038cb0 DJ |
23207 | } |
23208 | ||
4bf44c1c | 23209 | /* Free data associated with OBJFILE, if necessary. */ |
dce234bc PP |
23210 | |
23211 | static void | |
c1bd65d0 | 23212 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc | 23213 | { |
9a3c8263 | 23214 | struct dwarf2_per_objfile *data = (struct dwarf2_per_objfile *) d; |
8b70b953 | 23215 | int ix; |
8b70b953 | 23216 | |
626f2d1c TT |
23217 | /* Make sure we don't accidentally use dwarf2_per_objfile while |
23218 | cleaning up. */ | |
23219 | dwarf2_per_objfile = NULL; | |
23220 | ||
59b0c7c1 JB |
23221 | for (ix = 0; ix < data->n_comp_units; ++ix) |
23222 | VEC_free (dwarf2_per_cu_ptr, data->all_comp_units[ix]->imported_symtabs); | |
796a7ff8 | 23223 | |
59b0c7c1 | 23224 | for (ix = 0; ix < data->n_type_units; ++ix) |
796a7ff8 | 23225 | VEC_free (dwarf2_per_cu_ptr, |
59b0c7c1 JB |
23226 | data->all_type_units[ix]->per_cu.imported_symtabs); |
23227 | xfree (data->all_type_units); | |
95554aad | 23228 | |
8b70b953 | 23229 | VEC_free (dwarf2_section_info_def, data->types); |
3019eac3 DE |
23230 | |
23231 | if (data->dwo_files) | |
23232 | free_dwo_files (data->dwo_files, objfile); | |
5c6fa7ab DE |
23233 | if (data->dwp_file) |
23234 | gdb_bfd_unref (data->dwp_file->dbfd); | |
36586728 TT |
23235 | |
23236 | if (data->dwz_file && data->dwz_file->dwz_bfd) | |
23237 | gdb_bfd_unref (data->dwz_file->dwz_bfd); | |
9291a0cd TT |
23238 | } |
23239 | ||
23240 | \f | |
ae2de4f8 | 23241 | /* The "save gdb-index" command. */ |
9291a0cd | 23242 | |
bc8f2430 JK |
23243 | /* In-memory buffer to prepare data to be written later to a file. */ |
23244 | class data_buf | |
9291a0cd | 23245 | { |
bc8f2430 | 23246 | public: |
bc8f2430 JK |
23247 | /* Copy DATA to the end of the buffer. */ |
23248 | template<typename T> | |
23249 | void append_data (const T &data) | |
23250 | { | |
23251 | std::copy (reinterpret_cast<const gdb_byte *> (&data), | |
23252 | reinterpret_cast<const gdb_byte *> (&data + 1), | |
c2f134ac | 23253 | grow (sizeof (data))); |
bc8f2430 | 23254 | } |
b89be57b | 23255 | |
c2f134ac PA |
23256 | /* Copy CSTR (a zero-terminated string) to the end of buffer. The |
23257 | terminating zero is appended too. */ | |
bc8f2430 JK |
23258 | void append_cstr0 (const char *cstr) |
23259 | { | |
23260 | const size_t size = strlen (cstr) + 1; | |
c2f134ac PA |
23261 | std::copy (cstr, cstr + size, grow (size)); |
23262 | } | |
23263 | ||
23264 | /* Accept a host-format integer in VAL and append it to the buffer | |
23265 | as a target-format integer which is LEN bytes long. */ | |
23266 | void append_uint (size_t len, bfd_endian byte_order, ULONGEST val) | |
23267 | { | |
23268 | ::store_unsigned_integer (grow (len), len, byte_order, val); | |
bc8f2430 | 23269 | } |
9291a0cd | 23270 | |
bc8f2430 JK |
23271 | /* Return the size of the buffer. */ |
23272 | size_t size () const | |
23273 | { | |
23274 | return m_vec.size (); | |
23275 | } | |
23276 | ||
23277 | /* Write the buffer to FILE. */ | |
23278 | void file_write (FILE *file) const | |
23279 | { | |
a81e6d4d PA |
23280 | if (::fwrite (m_vec.data (), 1, m_vec.size (), file) != m_vec.size ()) |
23281 | error (_("couldn't write data to file")); | |
bc8f2430 JK |
23282 | } |
23283 | ||
23284 | private: | |
c2f134ac PA |
23285 | /* Grow SIZE bytes at the end of the buffer. Returns a pointer to |
23286 | the start of the new block. */ | |
23287 | gdb_byte *grow (size_t size) | |
23288 | { | |
23289 | m_vec.resize (m_vec.size () + size); | |
23290 | return &*m_vec.end () - size; | |
23291 | } | |
23292 | ||
d5722aa2 | 23293 | gdb::byte_vector m_vec; |
bc8f2430 | 23294 | }; |
9291a0cd TT |
23295 | |
23296 | /* An entry in the symbol table. */ | |
23297 | struct symtab_index_entry | |
23298 | { | |
23299 | /* The name of the symbol. */ | |
23300 | const char *name; | |
23301 | /* The offset of the name in the constant pool. */ | |
23302 | offset_type index_offset; | |
23303 | /* A sorted vector of the indices of all the CUs that hold an object | |
23304 | of this name. */ | |
bc8f2430 | 23305 | std::vector<offset_type> cu_indices; |
9291a0cd TT |
23306 | }; |
23307 | ||
23308 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
23309 | struct mapped_symtab | |
23310 | { | |
bc8f2430 JK |
23311 | mapped_symtab () |
23312 | { | |
23313 | data.resize (1024); | |
23314 | } | |
b89be57b | 23315 | |
bc8f2430 | 23316 | offset_type n_elements = 0; |
4b76cda9 | 23317 | std::vector<symtab_index_entry> data; |
bc8f2430 | 23318 | }; |
9291a0cd | 23319 | |
bc8f2430 | 23320 | /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to |
559a7a62 JK |
23321 | the slot. |
23322 | ||
23323 | Function is used only during write_hash_table so no index format backward | |
23324 | compatibility is needed. */ | |
b89be57b | 23325 | |
4b76cda9 | 23326 | static symtab_index_entry & |
9291a0cd TT |
23327 | find_slot (struct mapped_symtab *symtab, const char *name) |
23328 | { | |
559a7a62 | 23329 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd | 23330 | |
bc8f2430 JK |
23331 | index = hash & (symtab->data.size () - 1); |
23332 | step = ((hash * 17) & (symtab->data.size () - 1)) | 1; | |
9291a0cd TT |
23333 | |
23334 | for (;;) | |
23335 | { | |
4b76cda9 PA |
23336 | if (symtab->data[index].name == NULL |
23337 | || strcmp (name, symtab->data[index].name) == 0) | |
bc8f2430 JK |
23338 | return symtab->data[index]; |
23339 | index = (index + step) & (symtab->data.size () - 1); | |
9291a0cd TT |
23340 | } |
23341 | } | |
23342 | ||
23343 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 23344 | |
9291a0cd TT |
23345 | static void |
23346 | hash_expand (struct mapped_symtab *symtab) | |
23347 | { | |
bc8f2430 | 23348 | auto old_entries = std::move (symtab->data); |
9291a0cd | 23349 | |
bc8f2430 JK |
23350 | symtab->data.clear (); |
23351 | symtab->data.resize (old_entries.size () * 2); | |
9291a0cd | 23352 | |
bc8f2430 | 23353 | for (auto &it : old_entries) |
4b76cda9 | 23354 | if (it.name != NULL) |
bc8f2430 | 23355 | { |
4b76cda9 | 23356 | auto &ref = find_slot (symtab, it.name); |
bc8f2430 JK |
23357 | ref = std::move (it); |
23358 | } | |
9291a0cd TT |
23359 | } |
23360 | ||
156942c7 DE |
23361 | /* Add an entry to SYMTAB. NAME is the name of the symbol. |
23362 | CU_INDEX is the index of the CU in which the symbol appears. | |
23363 | IS_STATIC is one if the symbol is static, otherwise zero (global). */ | |
b89be57b | 23364 | |
9291a0cd TT |
23365 | static void |
23366 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
156942c7 | 23367 | int is_static, gdb_index_symbol_kind kind, |
9291a0cd TT |
23368 | offset_type cu_index) |
23369 | { | |
156942c7 | 23370 | offset_type cu_index_and_attrs; |
9291a0cd TT |
23371 | |
23372 | ++symtab->n_elements; | |
bc8f2430 | 23373 | if (4 * symtab->n_elements / 3 >= symtab->data.size ()) |
9291a0cd TT |
23374 | hash_expand (symtab); |
23375 | ||
4b76cda9 PA |
23376 | symtab_index_entry &slot = find_slot (symtab, name); |
23377 | if (slot.name == NULL) | |
9291a0cd | 23378 | { |
4b76cda9 | 23379 | slot.name = name; |
156942c7 | 23380 | /* index_offset is set later. */ |
9291a0cd | 23381 | } |
156942c7 DE |
23382 | |
23383 | cu_index_and_attrs = 0; | |
23384 | DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs, cu_index); | |
23385 | DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs, is_static); | |
23386 | DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs, kind); | |
23387 | ||
23388 | /* We don't want to record an index value twice as we want to avoid the | |
23389 | duplication. | |
23390 | We process all global symbols and then all static symbols | |
23391 | (which would allow us to avoid the duplication by only having to check | |
23392 | the last entry pushed), but a symbol could have multiple kinds in one CU. | |
23393 | To keep things simple we don't worry about the duplication here and | |
23394 | sort and uniqufy the list after we've processed all symbols. */ | |
4b76cda9 | 23395 | slot.cu_indices.push_back (cu_index_and_attrs); |
156942c7 DE |
23396 | } |
23397 | ||
23398 | /* Sort and remove duplicates of all symbols' cu_indices lists. */ | |
23399 | ||
23400 | static void | |
23401 | uniquify_cu_indices (struct mapped_symtab *symtab) | |
23402 | { | |
4b76cda9 | 23403 | for (auto &entry : symtab->data) |
156942c7 | 23404 | { |
4b76cda9 | 23405 | if (entry.name != NULL && !entry.cu_indices.empty ()) |
156942c7 | 23406 | { |
4b76cda9 | 23407 | auto &cu_indices = entry.cu_indices; |
6fd931f2 PA |
23408 | std::sort (cu_indices.begin (), cu_indices.end ()); |
23409 | auto from = std::unique (cu_indices.begin (), cu_indices.end ()); | |
23410 | cu_indices.erase (from, cu_indices.end ()); | |
156942c7 DE |
23411 | } |
23412 | } | |
9291a0cd TT |
23413 | } |
23414 | ||
bc8f2430 JK |
23415 | /* A form of 'const char *' suitable for container keys. Only the |
23416 | pointer is stored. The strings themselves are compared, not the | |
23417 | pointers. */ | |
23418 | class c_str_view | |
9291a0cd | 23419 | { |
bc8f2430 JK |
23420 | public: |
23421 | c_str_view (const char *cstr) | |
23422 | : m_cstr (cstr) | |
23423 | {} | |
9291a0cd | 23424 | |
bc8f2430 JK |
23425 | bool operator== (const c_str_view &other) const |
23426 | { | |
23427 | return strcmp (m_cstr, other.m_cstr) == 0; | |
23428 | } | |
9291a0cd | 23429 | |
bc8f2430 JK |
23430 | private: |
23431 | friend class c_str_view_hasher; | |
23432 | const char *const m_cstr; | |
23433 | }; | |
9291a0cd | 23434 | |
bc8f2430 JK |
23435 | /* A std::unordered_map::hasher for c_str_view that uses the right |
23436 | hash function for strings in a mapped index. */ | |
23437 | class c_str_view_hasher | |
23438 | { | |
23439 | public: | |
23440 | size_t operator () (const c_str_view &x) const | |
23441 | { | |
23442 | return mapped_index_string_hash (INT_MAX, x.m_cstr); | |
23443 | } | |
23444 | }; | |
b89be57b | 23445 | |
bc8f2430 JK |
23446 | /* A std::unordered_map::hasher for std::vector<>. */ |
23447 | template<typename T> | |
23448 | class vector_hasher | |
9291a0cd | 23449 | { |
bc8f2430 JK |
23450 | public: |
23451 | size_t operator () (const std::vector<T> &key) const | |
23452 | { | |
23453 | return iterative_hash (key.data (), | |
23454 | sizeof (key.front ()) * key.size (), 0); | |
23455 | } | |
23456 | }; | |
9291a0cd | 23457 | |
bc8f2430 JK |
23458 | /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with |
23459 | constant pool entries going into the data buffer CPOOL. */ | |
3876f04e | 23460 | |
bc8f2430 JK |
23461 | static void |
23462 | write_hash_table (mapped_symtab *symtab, data_buf &output, data_buf &cpool) | |
23463 | { | |
23464 | { | |
23465 | /* Elements are sorted vectors of the indices of all the CUs that | |
23466 | hold an object of this name. */ | |
23467 | std::unordered_map<std::vector<offset_type>, offset_type, | |
23468 | vector_hasher<offset_type>> | |
23469 | symbol_hash_table; | |
23470 | ||
23471 | /* We add all the index vectors to the constant pool first, to | |
23472 | ensure alignment is ok. */ | |
4b76cda9 | 23473 | for (symtab_index_entry &entry : symtab->data) |
bc8f2430 | 23474 | { |
4b76cda9 | 23475 | if (entry.name == NULL) |
bc8f2430 | 23476 | continue; |
4b76cda9 | 23477 | gdb_assert (entry.index_offset == 0); |
70a1152b PA |
23478 | |
23479 | /* Finding before inserting is faster than always trying to | |
23480 | insert, because inserting always allocates a node, does the | |
23481 | lookup, and then destroys the new node if another node | |
23482 | already had the same key. C++17 try_emplace will avoid | |
23483 | this. */ | |
23484 | const auto found | |
4b76cda9 | 23485 | = symbol_hash_table.find (entry.cu_indices); |
70a1152b PA |
23486 | if (found != symbol_hash_table.end ()) |
23487 | { | |
4b76cda9 | 23488 | entry.index_offset = found->second; |
70a1152b PA |
23489 | continue; |
23490 | } | |
23491 | ||
4b76cda9 PA |
23492 | symbol_hash_table.emplace (entry.cu_indices, cpool.size ()); |
23493 | entry.index_offset = cpool.size (); | |
23494 | cpool.append_data (MAYBE_SWAP (entry.cu_indices.size ())); | |
23495 | for (const auto index : entry.cu_indices) | |
23496 | cpool.append_data (MAYBE_SWAP (index)); | |
bc8f2430 JK |
23497 | } |
23498 | } | |
9291a0cd TT |
23499 | |
23500 | /* Now write out the hash table. */ | |
bc8f2430 | 23501 | std::unordered_map<c_str_view, offset_type, c_str_view_hasher> str_table; |
4b76cda9 | 23502 | for (const auto &entry : symtab->data) |
9291a0cd TT |
23503 | { |
23504 | offset_type str_off, vec_off; | |
23505 | ||
4b76cda9 | 23506 | if (entry.name != NULL) |
9291a0cd | 23507 | { |
4b76cda9 | 23508 | const auto insertpair = str_table.emplace (entry.name, cpool.size ()); |
bc8f2430 | 23509 | if (insertpair.second) |
4b76cda9 | 23510 | cpool.append_cstr0 (entry.name); |
bc8f2430 | 23511 | str_off = insertpair.first->second; |
4b76cda9 | 23512 | vec_off = entry.index_offset; |
9291a0cd TT |
23513 | } |
23514 | else | |
23515 | { | |
23516 | /* While 0 is a valid constant pool index, it is not valid | |
23517 | to have 0 for both offsets. */ | |
23518 | str_off = 0; | |
23519 | vec_off = 0; | |
23520 | } | |
23521 | ||
bc8f2430 JK |
23522 | output.append_data (MAYBE_SWAP (str_off)); |
23523 | output.append_data (MAYBE_SWAP (vec_off)); | |
9291a0cd | 23524 | } |
9291a0cd TT |
23525 | } |
23526 | ||
bc8f2430 | 23527 | typedef std::unordered_map<partial_symtab *, unsigned int> psym_index_map; |
0a5429f6 DE |
23528 | |
23529 | /* Helper struct for building the address table. */ | |
23530 | struct addrmap_index_data | |
23531 | { | |
bc8f2430 JK |
23532 | addrmap_index_data (data_buf &addr_vec_, psym_index_map &cu_index_htab_) |
23533 | : addr_vec (addr_vec_), cu_index_htab (cu_index_htab_) | |
23534 | {} | |
23535 | ||
0a5429f6 | 23536 | struct objfile *objfile; |
bc8f2430 JK |
23537 | data_buf &addr_vec; |
23538 | psym_index_map &cu_index_htab; | |
0a5429f6 DE |
23539 | |
23540 | /* Non-zero if the previous_* fields are valid. | |
23541 | We can't write an entry until we see the next entry (since it is only then | |
23542 | that we know the end of the entry). */ | |
23543 | int previous_valid; | |
23544 | /* Index of the CU in the table of all CUs in the index file. */ | |
23545 | unsigned int previous_cu_index; | |
0963b4bd | 23546 | /* Start address of the CU. */ |
0a5429f6 DE |
23547 | CORE_ADDR previous_cu_start; |
23548 | }; | |
23549 | ||
bc8f2430 | 23550 | /* Write an address entry to ADDR_VEC. */ |
b89be57b | 23551 | |
9291a0cd | 23552 | static void |
bc8f2430 | 23553 | add_address_entry (struct objfile *objfile, data_buf &addr_vec, |
0a5429f6 | 23554 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) |
9291a0cd | 23555 | { |
9291a0cd TT |
23556 | CORE_ADDR baseaddr; |
23557 | ||
23558 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
23559 | ||
c2f134ac PA |
23560 | addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, start - baseaddr); |
23561 | addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
bc8f2430 | 23562 | addr_vec.append_data (MAYBE_SWAP (cu_index)); |
0a5429f6 DE |
23563 | } |
23564 | ||
23565 | /* Worker function for traversing an addrmap to build the address table. */ | |
23566 | ||
23567 | static int | |
23568 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
23569 | { | |
9a3c8263 SM |
23570 | struct addrmap_index_data *data = (struct addrmap_index_data *) datap; |
23571 | struct partial_symtab *pst = (struct partial_symtab *) obj; | |
0a5429f6 DE |
23572 | |
23573 | if (data->previous_valid) | |
bc8f2430 | 23574 | add_address_entry (data->objfile, data->addr_vec, |
0a5429f6 DE |
23575 | data->previous_cu_start, start_addr, |
23576 | data->previous_cu_index); | |
23577 | ||
23578 | data->previous_cu_start = start_addr; | |
23579 | if (pst != NULL) | |
23580 | { | |
bc8f2430 JK |
23581 | const auto it = data->cu_index_htab.find (pst); |
23582 | gdb_assert (it != data->cu_index_htab.cend ()); | |
23583 | data->previous_cu_index = it->second; | |
0a5429f6 DE |
23584 | data->previous_valid = 1; |
23585 | } | |
23586 | else | |
bc8f2430 | 23587 | data->previous_valid = 0; |
0a5429f6 DE |
23588 | |
23589 | return 0; | |
23590 | } | |
23591 | ||
bc8f2430 | 23592 | /* Write OBJFILE's address map to ADDR_VEC. |
0a5429f6 DE |
23593 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices |
23594 | in the index file. */ | |
23595 | ||
23596 | static void | |
bc8f2430 JK |
23597 | write_address_map (struct objfile *objfile, data_buf &addr_vec, |
23598 | psym_index_map &cu_index_htab) | |
0a5429f6 | 23599 | { |
bc8f2430 | 23600 | struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab); |
0a5429f6 DE |
23601 | |
23602 | /* When writing the address table, we have to cope with the fact that | |
23603 | the addrmap iterator only provides the start of a region; we have to | |
23604 | wait until the next invocation to get the start of the next region. */ | |
23605 | ||
23606 | addrmap_index_data.objfile = objfile; | |
0a5429f6 DE |
23607 | addrmap_index_data.previous_valid = 0; |
23608 | ||
23609 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
23610 | &addrmap_index_data); | |
23611 | ||
23612 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
23613 | is valid, but we should still handle it. | |
23614 | The end address is recorded as the start of the next region, but that | |
23615 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
23616 | anyway. */ | |
23617 | if (addrmap_index_data.previous_valid) | |
bc8f2430 | 23618 | add_address_entry (objfile, addr_vec, |
0a5429f6 DE |
23619 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, |
23620 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
23621 | } |
23622 | ||
156942c7 DE |
23623 | /* Return the symbol kind of PSYM. */ |
23624 | ||
23625 | static gdb_index_symbol_kind | |
23626 | symbol_kind (struct partial_symbol *psym) | |
23627 | { | |
23628 | domain_enum domain = PSYMBOL_DOMAIN (psym); | |
23629 | enum address_class aclass = PSYMBOL_CLASS (psym); | |
23630 | ||
23631 | switch (domain) | |
23632 | { | |
23633 | case VAR_DOMAIN: | |
23634 | switch (aclass) | |
23635 | { | |
23636 | case LOC_BLOCK: | |
23637 | return GDB_INDEX_SYMBOL_KIND_FUNCTION; | |
23638 | case LOC_TYPEDEF: | |
23639 | return GDB_INDEX_SYMBOL_KIND_TYPE; | |
23640 | case LOC_COMPUTED: | |
23641 | case LOC_CONST_BYTES: | |
23642 | case LOC_OPTIMIZED_OUT: | |
23643 | case LOC_STATIC: | |
23644 | return GDB_INDEX_SYMBOL_KIND_VARIABLE; | |
23645 | case LOC_CONST: | |
23646 | /* Note: It's currently impossible to recognize psyms as enum values | |
23647 | short of reading the type info. For now punt. */ | |
23648 | return GDB_INDEX_SYMBOL_KIND_VARIABLE; | |
23649 | default: | |
23650 | /* There are other LOC_FOO values that one might want to classify | |
23651 | as variables, but dwarf2read.c doesn't currently use them. */ | |
23652 | return GDB_INDEX_SYMBOL_KIND_OTHER; | |
23653 | } | |
23654 | case STRUCT_DOMAIN: | |
23655 | return GDB_INDEX_SYMBOL_KIND_TYPE; | |
23656 | default: | |
23657 | return GDB_INDEX_SYMBOL_KIND_OTHER; | |
23658 | } | |
23659 | } | |
23660 | ||
9291a0cd | 23661 | /* Add a list of partial symbols to SYMTAB. */ |
b89be57b | 23662 | |
9291a0cd TT |
23663 | static void |
23664 | write_psymbols (struct mapped_symtab *symtab, | |
bc8f2430 | 23665 | std::unordered_set<partial_symbol *> &psyms_seen, |
9291a0cd TT |
23666 | struct partial_symbol **psymp, |
23667 | int count, | |
987d643c TT |
23668 | offset_type cu_index, |
23669 | int is_static) | |
9291a0cd TT |
23670 | { |
23671 | for (; count-- > 0; ++psymp) | |
23672 | { | |
156942c7 | 23673 | struct partial_symbol *psym = *psymp; |
987d643c | 23674 | |
156942c7 | 23675 | if (SYMBOL_LANGUAGE (psym) == language_ada) |
9291a0cd | 23676 | error (_("Ada is not currently supported by the index")); |
987d643c | 23677 | |
987d643c | 23678 | /* Only add a given psymbol once. */ |
bc8f2430 | 23679 | if (psyms_seen.insert (psym).second) |
987d643c | 23680 | { |
156942c7 DE |
23681 | gdb_index_symbol_kind kind = symbol_kind (psym); |
23682 | ||
156942c7 DE |
23683 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym), |
23684 | is_static, kind, cu_index); | |
987d643c | 23685 | } |
9291a0cd TT |
23686 | } |
23687 | } | |
23688 | ||
1fd400ff TT |
23689 | /* A helper struct used when iterating over debug_types. */ |
23690 | struct signatured_type_index_data | |
23691 | { | |
bc8f2430 JK |
23692 | signatured_type_index_data (data_buf &types_list_, |
23693 | std::unordered_set<partial_symbol *> &psyms_seen_) | |
23694 | : types_list (types_list_), psyms_seen (psyms_seen_) | |
23695 | {} | |
23696 | ||
1fd400ff TT |
23697 | struct objfile *objfile; |
23698 | struct mapped_symtab *symtab; | |
bc8f2430 JK |
23699 | data_buf &types_list; |
23700 | std::unordered_set<partial_symbol *> &psyms_seen; | |
1fd400ff TT |
23701 | int cu_index; |
23702 | }; | |
23703 | ||
23704 | /* A helper function that writes a single signatured_type to an | |
23705 | obstack. */ | |
b89be57b | 23706 | |
1fd400ff TT |
23707 | static int |
23708 | write_one_signatured_type (void **slot, void *d) | |
23709 | { | |
9a3c8263 SM |
23710 | struct signatured_type_index_data *info |
23711 | = (struct signatured_type_index_data *) d; | |
1fd400ff | 23712 | struct signatured_type *entry = (struct signatured_type *) *slot; |
0186c6a7 | 23713 | struct partial_symtab *psymtab = entry->per_cu.v.psymtab; |
1fd400ff TT |
23714 | |
23715 | write_psymbols (info->symtab, | |
987d643c | 23716 | info->psyms_seen, |
3e43a32a MS |
23717 | info->objfile->global_psymbols.list |
23718 | + psymtab->globals_offset, | |
987d643c TT |
23719 | psymtab->n_global_syms, info->cu_index, |
23720 | 0); | |
1fd400ff | 23721 | write_psymbols (info->symtab, |
987d643c | 23722 | info->psyms_seen, |
3e43a32a MS |
23723 | info->objfile->static_psymbols.list |
23724 | + psymtab->statics_offset, | |
987d643c TT |
23725 | psymtab->n_static_syms, info->cu_index, |
23726 | 1); | |
1fd400ff | 23727 | |
c2f134ac PA |
23728 | info->types_list.append_uint (8, BFD_ENDIAN_LITTLE, |
23729 | to_underlying (entry->per_cu.sect_off)); | |
23730 | info->types_list.append_uint (8, BFD_ENDIAN_LITTLE, | |
23731 | to_underlying (entry->type_offset_in_tu)); | |
23732 | info->types_list.append_uint (8, BFD_ENDIAN_LITTLE, entry->signature); | |
1fd400ff TT |
23733 | |
23734 | ++info->cu_index; | |
23735 | ||
23736 | return 1; | |
23737 | } | |
23738 | ||
e8f8bcb3 PA |
23739 | /* Recurse into all "included" dependencies and count their symbols as |
23740 | if they appeared in this psymtab. */ | |
23741 | ||
23742 | static void | |
23743 | recursively_count_psymbols (struct partial_symtab *psymtab, | |
23744 | size_t &psyms_seen) | |
23745 | { | |
23746 | for (int i = 0; i < psymtab->number_of_dependencies; ++i) | |
23747 | if (psymtab->dependencies[i]->user != NULL) | |
23748 | recursively_count_psymbols (psymtab->dependencies[i], | |
23749 | psyms_seen); | |
23750 | ||
23751 | psyms_seen += psymtab->n_global_syms; | |
23752 | psyms_seen += psymtab->n_static_syms; | |
23753 | } | |
23754 | ||
95554aad TT |
23755 | /* Recurse into all "included" dependencies and write their symbols as |
23756 | if they appeared in this psymtab. */ | |
23757 | ||
23758 | static void | |
23759 | recursively_write_psymbols (struct objfile *objfile, | |
23760 | struct partial_symtab *psymtab, | |
23761 | struct mapped_symtab *symtab, | |
bc8f2430 | 23762 | std::unordered_set<partial_symbol *> &psyms_seen, |
95554aad TT |
23763 | offset_type cu_index) |
23764 | { | |
23765 | int i; | |
23766 | ||
23767 | for (i = 0; i < psymtab->number_of_dependencies; ++i) | |
23768 | if (psymtab->dependencies[i]->user != NULL) | |
23769 | recursively_write_psymbols (objfile, psymtab->dependencies[i], | |
23770 | symtab, psyms_seen, cu_index); | |
23771 | ||
23772 | write_psymbols (symtab, | |
23773 | psyms_seen, | |
23774 | objfile->global_psymbols.list + psymtab->globals_offset, | |
23775 | psymtab->n_global_syms, cu_index, | |
23776 | 0); | |
23777 | write_psymbols (symtab, | |
23778 | psyms_seen, | |
23779 | objfile->static_psymbols.list + psymtab->statics_offset, | |
23780 | psymtab->n_static_syms, cu_index, | |
23781 | 1); | |
23782 | } | |
23783 | ||
9291a0cd | 23784 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 23785 | |
9291a0cd TT |
23786 | static void |
23787 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
23788 | { | |
9291a0cd TT |
23789 | if (dwarf2_per_objfile->using_index) |
23790 | error (_("Cannot use an index to create the index")); | |
23791 | ||
8b70b953 TT |
23792 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
23793 | error (_("Cannot make an index when the file has multiple .debug_types sections")); | |
23794 | ||
260b681b DE |
23795 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
23796 | return; | |
23797 | ||
bc8f2430 | 23798 | struct stat st; |
4262abfb JK |
23799 | if (stat (objfile_name (objfile), &st) < 0) |
23800 | perror_with_name (objfile_name (objfile)); | |
9291a0cd | 23801 | |
bc8f2430 JK |
23802 | std::string filename (std::string (dir) + SLASH_STRING |
23803 | + lbasename (objfile_name (objfile)) + INDEX_SUFFIX); | |
9291a0cd | 23804 | |
d419f42d | 23805 | FILE *out_file = gdb_fopen_cloexec (filename.c_str (), "wb").release (); |
9291a0cd | 23806 | if (!out_file) |
bc8f2430 | 23807 | error (_("Can't open `%s' for writing"), filename.c_str ()); |
9291a0cd | 23808 | |
16b7a719 PA |
23809 | /* Order matters here; we want FILE to be closed before FILENAME is |
23810 | unlinked, because on MS-Windows one cannot delete a file that is | |
23811 | still open. (Don't call anything here that might throw until | |
23812 | file_closer is created.) */ | |
bc8f2430 | 23813 | gdb::unlinker unlink_file (filename.c_str ()); |
d419f42d | 23814 | gdb_file_up close_out_file (out_file); |
9291a0cd | 23815 | |
bc8f2430 JK |
23816 | mapped_symtab symtab; |
23817 | data_buf cu_list; | |
987d643c | 23818 | |
0a5429f6 DE |
23819 | /* While we're scanning CU's create a table that maps a psymtab pointer |
23820 | (which is what addrmap records) to its index (which is what is recorded | |
23821 | in the index file). This will later be needed to write the address | |
23822 | table. */ | |
bc8f2430 JK |
23823 | psym_index_map cu_index_htab; |
23824 | cu_index_htab.reserve (dwarf2_per_objfile->n_comp_units); | |
0a5429f6 DE |
23825 | |
23826 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
23827 | work here. Also, the debug_types entries do not appear in |
23828 | all_comp_units, but only in their own hash table. */ | |
e8f8bcb3 PA |
23829 | |
23830 | /* The psyms_seen set is potentially going to be largish (~40k | |
23831 | elements when indexing a -g3 build of GDB itself). Estimate the | |
23832 | number of elements in order to avoid too many rehashes, which | |
23833 | require rebuilding buckets and thus many trips to | |
23834 | malloc/free. */ | |
23835 | size_t psyms_count = 0; | |
23836 | for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
23837 | { | |
23838 | struct dwarf2_per_cu_data *per_cu | |
23839 | = dwarf2_per_objfile->all_comp_units[i]; | |
23840 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
23841 | ||
23842 | if (psymtab != NULL && psymtab->user == NULL) | |
23843 | recursively_count_psymbols (psymtab, psyms_count); | |
23844 | } | |
23845 | /* Generating an index for gdb itself shows a ratio of | |
23846 | TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */ | |
23847 | std::unordered_set<partial_symbol *> psyms_seen (psyms_count / 4); | |
bc8f2430 | 23848 | for (int i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
9291a0cd | 23849 | { |
3e43a32a MS |
23850 | struct dwarf2_per_cu_data *per_cu |
23851 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 23852 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 23853 | |
92fac807 JK |
23854 | /* CU of a shared file from 'dwz -m' may be unused by this main file. |
23855 | It may be referenced from a local scope but in such case it does not | |
23856 | need to be present in .gdb_index. */ | |
23857 | if (psymtab == NULL) | |
23858 | continue; | |
23859 | ||
95554aad | 23860 | if (psymtab->user == NULL) |
bc8f2430 JK |
23861 | recursively_write_psymbols (objfile, psymtab, &symtab, |
23862 | psyms_seen, i); | |
9291a0cd | 23863 | |
bc8f2430 JK |
23864 | const auto insertpair = cu_index_htab.emplace (psymtab, i); |
23865 | gdb_assert (insertpair.second); | |
9291a0cd | 23866 | |
c2f134ac PA |
23867 | cu_list.append_uint (8, BFD_ENDIAN_LITTLE, |
23868 | to_underlying (per_cu->sect_off)); | |
23869 | cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length); | |
9291a0cd TT |
23870 | } |
23871 | ||
0a5429f6 | 23872 | /* Dump the address map. */ |
bc8f2430 JK |
23873 | data_buf addr_vec; |
23874 | write_address_map (objfile, addr_vec, cu_index_htab); | |
0a5429f6 | 23875 | |
1fd400ff | 23876 | /* Write out the .debug_type entries, if any. */ |
bc8f2430 | 23877 | data_buf types_cu_list; |
1fd400ff TT |
23878 | if (dwarf2_per_objfile->signatured_types) |
23879 | { | |
bc8f2430 JK |
23880 | signatured_type_index_data sig_data (types_cu_list, |
23881 | psyms_seen); | |
1fd400ff TT |
23882 | |
23883 | sig_data.objfile = objfile; | |
bc8f2430 | 23884 | sig_data.symtab = &symtab; |
1fd400ff TT |
23885 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
23886 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
23887 | write_one_signatured_type, &sig_data); | |
23888 | } | |
23889 | ||
156942c7 DE |
23890 | /* Now that we've processed all symbols we can shrink their cu_indices |
23891 | lists. */ | |
bc8f2430 | 23892 | uniquify_cu_indices (&symtab); |
156942c7 | 23893 | |
bc8f2430 JK |
23894 | data_buf symtab_vec, constant_pool; |
23895 | write_hash_table (&symtab, symtab_vec, constant_pool); | |
9291a0cd | 23896 | |
bc8f2430 JK |
23897 | data_buf contents; |
23898 | const offset_type size_of_contents = 6 * sizeof (offset_type); | |
23899 | offset_type total_len = size_of_contents; | |
9291a0cd TT |
23900 | |
23901 | /* The version number. */ | |
bc8f2430 | 23902 | contents.append_data (MAYBE_SWAP (8)); |
9291a0cd TT |
23903 | |
23904 | /* The offset of the CU list from the start of the file. */ | |
bc8f2430 JK |
23905 | contents.append_data (MAYBE_SWAP (total_len)); |
23906 | total_len += cu_list.size (); | |
9291a0cd | 23907 | |
1fd400ff | 23908 | /* The offset of the types CU list from the start of the file. */ |
bc8f2430 JK |
23909 | contents.append_data (MAYBE_SWAP (total_len)); |
23910 | total_len += types_cu_list.size (); | |
1fd400ff | 23911 | |
9291a0cd | 23912 | /* The offset of the address table from the start of the file. */ |
bc8f2430 JK |
23913 | contents.append_data (MAYBE_SWAP (total_len)); |
23914 | total_len += addr_vec.size (); | |
9291a0cd TT |
23915 | |
23916 | /* The offset of the symbol table from the start of the file. */ | |
bc8f2430 JK |
23917 | contents.append_data (MAYBE_SWAP (total_len)); |
23918 | total_len += symtab_vec.size (); | |
9291a0cd TT |
23919 | |
23920 | /* The offset of the constant pool from the start of the file. */ | |
bc8f2430 JK |
23921 | contents.append_data (MAYBE_SWAP (total_len)); |
23922 | total_len += constant_pool.size (); | |
9291a0cd | 23923 | |
bc8f2430 | 23924 | gdb_assert (contents.size () == size_of_contents); |
9291a0cd | 23925 | |
bc8f2430 JK |
23926 | contents.file_write (out_file); |
23927 | cu_list.file_write (out_file); | |
23928 | types_cu_list.file_write (out_file); | |
23929 | addr_vec.file_write (out_file); | |
23930 | symtab_vec.file_write (out_file); | |
23931 | constant_pool.file_write (out_file); | |
9291a0cd | 23932 | |
bef155c3 TT |
23933 | /* We want to keep the file. */ |
23934 | unlink_file.keep (); | |
9291a0cd TT |
23935 | } |
23936 | ||
90476074 TT |
23937 | /* Implementation of the `save gdb-index' command. |
23938 | ||
23939 | Note that the file format used by this command is documented in the | |
23940 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 23941 | |
9291a0cd TT |
23942 | static void |
23943 | save_gdb_index_command (char *arg, int from_tty) | |
23944 | { | |
23945 | struct objfile *objfile; | |
23946 | ||
23947 | if (!arg || !*arg) | |
96d19272 | 23948 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
23949 | |
23950 | ALL_OBJFILES (objfile) | |
23951 | { | |
23952 | struct stat st; | |
23953 | ||
23954 | /* If the objfile does not correspond to an actual file, skip it. */ | |
4262abfb | 23955 | if (stat (objfile_name (objfile), &st) < 0) |
9291a0cd TT |
23956 | continue; |
23957 | ||
9a3c8263 SM |
23958 | dwarf2_per_objfile |
23959 | = (struct dwarf2_per_objfile *) objfile_data (objfile, | |
23960 | dwarf2_objfile_data_key); | |
9291a0cd TT |
23961 | if (dwarf2_per_objfile) |
23962 | { | |
9291a0cd | 23963 | |
492d29ea | 23964 | TRY |
9291a0cd TT |
23965 | { |
23966 | write_psymtabs_to_index (objfile, arg); | |
23967 | } | |
492d29ea PA |
23968 | CATCH (except, RETURN_MASK_ERROR) |
23969 | { | |
23970 | exception_fprintf (gdb_stderr, except, | |
23971 | _("Error while writing index for `%s': "), | |
23972 | objfile_name (objfile)); | |
23973 | } | |
23974 | END_CATCH | |
9291a0cd TT |
23975 | } |
23976 | } | |
dce234bc PP |
23977 | } |
23978 | ||
9291a0cd TT |
23979 | \f |
23980 | ||
b4f54984 | 23981 | int dwarf_always_disassemble; |
9eae7c52 TT |
23982 | |
23983 | static void | |
b4f54984 DE |
23984 | show_dwarf_always_disassemble (struct ui_file *file, int from_tty, |
23985 | struct cmd_list_element *c, const char *value) | |
9eae7c52 | 23986 | { |
3e43a32a MS |
23987 | fprintf_filtered (file, |
23988 | _("Whether to always disassemble " | |
23989 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
23990 | value); |
23991 | } | |
23992 | ||
900e11f9 JK |
23993 | static void |
23994 | show_check_physname (struct ui_file *file, int from_tty, | |
23995 | struct cmd_list_element *c, const char *value) | |
23996 | { | |
23997 | fprintf_filtered (file, | |
23998 | _("Whether to check \"physname\" is %s.\n"), | |
23999 | value); | |
24000 | } | |
24001 | ||
6502dd73 DJ |
24002 | void _initialize_dwarf2_read (void); |
24003 | ||
24004 | void | |
24005 | _initialize_dwarf2_read (void) | |
24006 | { | |
96d19272 JK |
24007 | struct cmd_list_element *c; |
24008 | ||
dce234bc | 24009 | dwarf2_objfile_data_key |
c1bd65d0 | 24010 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 24011 | |
b4f54984 DE |
24012 | add_prefix_cmd ("dwarf", class_maintenance, set_dwarf_cmd, _("\ |
24013 | Set DWARF specific variables.\n\ | |
24014 | Configure DWARF variables such as the cache size"), | |
24015 | &set_dwarf_cmdlist, "maintenance set dwarf ", | |
ae038cb0 DJ |
24016 | 0/*allow-unknown*/, &maintenance_set_cmdlist); |
24017 | ||
b4f54984 DE |
24018 | add_prefix_cmd ("dwarf", class_maintenance, show_dwarf_cmd, _("\ |
24019 | Show DWARF specific variables\n\ | |
24020 | Show DWARF variables such as the cache size"), | |
24021 | &show_dwarf_cmdlist, "maintenance show dwarf ", | |
ae038cb0 DJ |
24022 | 0/*allow-unknown*/, &maintenance_show_cmdlist); |
24023 | ||
24024 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
b4f54984 DE |
24025 | &dwarf_max_cache_age, _("\ |
24026 | Set the upper bound on the age of cached DWARF compilation units."), _("\ | |
24027 | Show the upper bound on the age of cached DWARF compilation units."), _("\ | |
7915a72c AC |
24028 | A higher limit means that cached compilation units will be stored\n\ |
24029 | in memory longer, and more total memory will be used. Zero disables\n\ | |
24030 | caching, which can slow down startup."), | |
2c5b56ce | 24031 | NULL, |
b4f54984 DE |
24032 | show_dwarf_max_cache_age, |
24033 | &set_dwarf_cmdlist, | |
24034 | &show_dwarf_cmdlist); | |
d97bc12b | 24035 | |
9eae7c52 | 24036 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
b4f54984 | 24037 | &dwarf_always_disassemble, _("\ |
9eae7c52 TT |
24038 | Set whether `info address' always disassembles DWARF expressions."), _("\ |
24039 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
24040 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
24041 | syntax. When disabled, expressions will be printed in a more\n\ | |
24042 | conversational style, when possible."), | |
24043 | NULL, | |
b4f54984 DE |
24044 | show_dwarf_always_disassemble, |
24045 | &set_dwarf_cmdlist, | |
24046 | &show_dwarf_cmdlist); | |
24047 | ||
24048 | add_setshow_zuinteger_cmd ("dwarf-read", no_class, &dwarf_read_debug, _("\ | |
24049 | Set debugging of the DWARF reader."), _("\ | |
24050 | Show debugging of the DWARF reader."), _("\ | |
24051 | When enabled (non-zero), debugging messages are printed during DWARF\n\ | |
73be47f5 DE |
24052 | reading and symtab expansion. A value of 1 (one) provides basic\n\ |
24053 | information. A value greater than 1 provides more verbose information."), | |
45cfd468 DE |
24054 | NULL, |
24055 | NULL, | |
24056 | &setdebuglist, &showdebuglist); | |
24057 | ||
b4f54984 DE |
24058 | add_setshow_zuinteger_cmd ("dwarf-die", no_class, &dwarf_die_debug, _("\ |
24059 | Set debugging of the DWARF DIE reader."), _("\ | |
24060 | Show debugging of the DWARF DIE reader."), _("\ | |
d97bc12b DE |
24061 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ |
24062 | The value is the maximum depth to print."), | |
ccce17b0 YQ |
24063 | NULL, |
24064 | NULL, | |
24065 | &setdebuglist, &showdebuglist); | |
9291a0cd | 24066 | |
27e0867f DE |
24067 | add_setshow_zuinteger_cmd ("dwarf-line", no_class, &dwarf_line_debug, _("\ |
24068 | Set debugging of the dwarf line reader."), _("\ | |
24069 | Show debugging of the dwarf line reader."), _("\ | |
24070 | When enabled (non-zero), line number entries are dumped as they are read in.\n\ | |
24071 | A value of 1 (one) provides basic information.\n\ | |
24072 | A value greater than 1 provides more verbose information."), | |
24073 | NULL, | |
24074 | NULL, | |
24075 | &setdebuglist, &showdebuglist); | |
24076 | ||
900e11f9 JK |
24077 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
24078 | Set cross-checking of \"physname\" code against demangler."), _("\ | |
24079 | Show cross-checking of \"physname\" code against demangler."), _("\ | |
24080 | When enabled, GDB's internal \"physname\" code is checked against\n\ | |
24081 | the demangler."), | |
24082 | NULL, show_check_physname, | |
24083 | &setdebuglist, &showdebuglist); | |
24084 | ||
e615022a DE |
24085 | add_setshow_boolean_cmd ("use-deprecated-index-sections", |
24086 | no_class, &use_deprecated_index_sections, _("\ | |
24087 | Set whether to use deprecated gdb_index sections."), _("\ | |
24088 | Show whether to use deprecated gdb_index sections."), _("\ | |
24089 | When enabled, deprecated .gdb_index sections are used anyway.\n\ | |
24090 | Normally they are ignored either because of a missing feature or\n\ | |
24091 | performance issue.\n\ | |
24092 | Warning: This option must be enabled before gdb reads the file."), | |
24093 | NULL, | |
24094 | NULL, | |
24095 | &setlist, &showlist); | |
24096 | ||
96d19272 | 24097 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 24098 | _("\ |
fc1a9d6e | 24099 | Save a gdb-index file.\n\ |
11570e71 | 24100 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
24101 | &save_cmdlist); |
24102 | set_cmd_completer (c, filename_completer); | |
f1e6e072 TT |
24103 | |
24104 | dwarf2_locexpr_index = register_symbol_computed_impl (LOC_COMPUTED, | |
24105 | &dwarf2_locexpr_funcs); | |
24106 | dwarf2_loclist_index = register_symbol_computed_impl (LOC_COMPUTED, | |
24107 | &dwarf2_loclist_funcs); | |
24108 | ||
24109 | dwarf2_locexpr_block_index = register_symbol_block_impl (LOC_BLOCK, | |
24110 | &dwarf2_block_frame_base_locexpr_funcs); | |
24111 | dwarf2_loclist_block_index = register_symbol_block_impl (LOC_BLOCK, | |
24112 | &dwarf2_block_frame_base_loclist_funcs); | |
6502dd73 | 24113 | } |