Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
28e7fd62 | 3 | Copyright (C) 1994-2013 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 KS |
55 | #include "typeprint.h" |
56 | #include "jv-lang.h" | |
ccefe4c4 | 57 | #include "psympriv.h" |
9291a0cd TT |
58 | #include "exceptions.h" |
59 | #include "gdb_stat.h" | |
96d19272 | 60 | #include "completer.h" |
34eaf542 | 61 | #include "vec.h" |
98bfdba5 | 62 | #include "c-lang.h" |
a766d390 | 63 | #include "go-lang.h" |
98bfdba5 | 64 | #include "valprint.h" |
3019eac3 | 65 | #include "gdbcore.h" /* for gnutarget */ |
156942c7 | 66 | #include "gdb/gdb-index.h" |
60d5a603 | 67 | #include <ctype.h> |
cbb099e8 | 68 | #include "gdb_bfd.h" |
4357ac6c | 69 | #include "f-lang.h" |
4c2df51b | 70 | |
c906108c SS |
71 | #include <fcntl.h> |
72 | #include "gdb_string.h" | |
4bdf3d34 | 73 | #include "gdb_assert.h" |
c906108c | 74 | #include <sys/types.h> |
d8151005 | 75 | |
34eaf542 TT |
76 | typedef struct symbol *symbolp; |
77 | DEF_VEC_P (symbolp); | |
78 | ||
45cfd468 DE |
79 | /* When non-zero, print basic high level tracing messages. |
80 | This is in contrast to the low level DIE reading of dwarf2_die_debug. */ | |
81 | static int dwarf2_read_debug = 0; | |
82 | ||
d97bc12b | 83 | /* When non-zero, dump DIEs after they are read in. */ |
ccce17b0 | 84 | static unsigned int dwarf2_die_debug = 0; |
d97bc12b | 85 | |
900e11f9 JK |
86 | /* When non-zero, cross-check physname against demangler. */ |
87 | static int check_physname = 0; | |
88 | ||
481860b3 | 89 | /* When non-zero, do not reject deprecated .gdb_index sections. */ |
e615022a | 90 | static int use_deprecated_index_sections = 0; |
481860b3 | 91 | |
df8a16a1 DJ |
92 | /* When set, the file that we're processing is known to have debugging |
93 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
94 | but later versions do. */ | |
95 | ||
96 | static int processing_has_namespace_info; | |
97 | ||
6502dd73 DJ |
98 | static const struct objfile_data *dwarf2_objfile_data_key; |
99 | ||
dce234bc PP |
100 | struct dwarf2_section_info |
101 | { | |
102 | asection *asection; | |
103 | gdb_byte *buffer; | |
104 | bfd_size_type size; | |
be391dca TT |
105 | /* True if we have tried to read this section. */ |
106 | int readin; | |
dce234bc PP |
107 | }; |
108 | ||
8b70b953 TT |
109 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
110 | DEF_VEC_O (dwarf2_section_info_def); | |
111 | ||
9291a0cd TT |
112 | /* All offsets in the index are of this type. It must be |
113 | architecture-independent. */ | |
114 | typedef uint32_t offset_type; | |
115 | ||
116 | DEF_VEC_I (offset_type); | |
117 | ||
156942c7 DE |
118 | /* Ensure only legit values are used. */ |
119 | #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \ | |
120 | do { \ | |
121 | gdb_assert ((unsigned int) (value) <= 1); \ | |
122 | GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \ | |
123 | } while (0) | |
124 | ||
125 | /* Ensure only legit values are used. */ | |
126 | #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \ | |
127 | do { \ | |
128 | gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \ | |
129 | && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \ | |
130 | GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \ | |
131 | } while (0) | |
132 | ||
133 | /* Ensure we don't use more than the alloted nuber of bits for the CU. */ | |
134 | #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \ | |
135 | do { \ | |
136 | gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \ | |
137 | GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \ | |
138 | } while (0) | |
139 | ||
9291a0cd TT |
140 | /* A description of the mapped index. The file format is described in |
141 | a comment by the code that writes the index. */ | |
142 | struct mapped_index | |
143 | { | |
559a7a62 JK |
144 | /* Index data format version. */ |
145 | int version; | |
146 | ||
9291a0cd TT |
147 | /* The total length of the buffer. */ |
148 | off_t total_size; | |
b11b1f88 | 149 | |
9291a0cd TT |
150 | /* A pointer to the address table data. */ |
151 | const gdb_byte *address_table; | |
b11b1f88 | 152 | |
9291a0cd TT |
153 | /* Size of the address table data in bytes. */ |
154 | offset_type address_table_size; | |
b11b1f88 | 155 | |
3876f04e DE |
156 | /* The symbol table, implemented as a hash table. */ |
157 | const offset_type *symbol_table; | |
b11b1f88 | 158 | |
9291a0cd | 159 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 160 | offset_type symbol_table_slots; |
b11b1f88 | 161 | |
9291a0cd TT |
162 | /* A pointer to the constant pool. */ |
163 | const char *constant_pool; | |
164 | }; | |
165 | ||
95554aad TT |
166 | typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr; |
167 | DEF_VEC_P (dwarf2_per_cu_ptr); | |
168 | ||
9cdd5dbd DE |
169 | /* Collection of data recorded per objfile. |
170 | This hangs off of dwarf2_objfile_data_key. */ | |
171 | ||
6502dd73 DJ |
172 | struct dwarf2_per_objfile |
173 | { | |
dce234bc PP |
174 | struct dwarf2_section_info info; |
175 | struct dwarf2_section_info abbrev; | |
176 | struct dwarf2_section_info line; | |
dce234bc PP |
177 | struct dwarf2_section_info loc; |
178 | struct dwarf2_section_info macinfo; | |
cf2c3c16 | 179 | struct dwarf2_section_info macro; |
dce234bc PP |
180 | struct dwarf2_section_info str; |
181 | struct dwarf2_section_info ranges; | |
3019eac3 | 182 | struct dwarf2_section_info addr; |
dce234bc PP |
183 | struct dwarf2_section_info frame; |
184 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 185 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 186 | |
8b70b953 TT |
187 | VEC (dwarf2_section_info_def) *types; |
188 | ||
be391dca TT |
189 | /* Back link. */ |
190 | struct objfile *objfile; | |
191 | ||
d467dd73 | 192 | /* Table of all the compilation units. This is used to locate |
10b3939b | 193 | the target compilation unit of a particular reference. */ |
ae038cb0 DJ |
194 | struct dwarf2_per_cu_data **all_comp_units; |
195 | ||
196 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
197 | int n_comp_units; | |
198 | ||
1fd400ff | 199 | /* The number of .debug_types-related CUs. */ |
d467dd73 | 200 | int n_type_units; |
1fd400ff | 201 | |
d467dd73 | 202 | /* The .debug_types-related CUs (TUs). */ |
b4dd5633 | 203 | struct signatured_type **all_type_units; |
1fd400ff | 204 | |
f4dc4d17 DE |
205 | /* The number of entries in all_type_unit_groups. */ |
206 | int n_type_unit_groups; | |
207 | ||
208 | /* Table of type unit groups. | |
209 | This exists to make it easy to iterate over all CUs and TU groups. */ | |
210 | struct type_unit_group **all_type_unit_groups; | |
211 | ||
212 | /* Table of struct type_unit_group objects. | |
213 | The hash key is the DW_AT_stmt_list value. */ | |
214 | htab_t type_unit_groups; | |
72dca2f5 | 215 | |
348e048f DE |
216 | /* A table mapping .debug_types signatures to its signatured_type entry. |
217 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
218 | htab_t signatured_types; | |
219 | ||
f4dc4d17 DE |
220 | /* Type unit statistics, to see how well the scaling improvements |
221 | are doing. */ | |
222 | struct tu_stats | |
223 | { | |
224 | int nr_uniq_abbrev_tables; | |
225 | int nr_symtabs; | |
226 | int nr_symtab_sharers; | |
227 | int nr_stmt_less_type_units; | |
228 | } tu_stats; | |
229 | ||
230 | /* A chain of compilation units that are currently read in, so that | |
231 | they can be freed later. */ | |
232 | struct dwarf2_per_cu_data *read_in_chain; | |
233 | ||
3019eac3 DE |
234 | /* A table mapping DW_AT_dwo_name values to struct dwo_file objects. |
235 | This is NULL if the table hasn't been allocated yet. */ | |
236 | htab_t dwo_files; | |
237 | ||
80626a55 DE |
238 | /* Non-zero if we've check for whether there is a DWP file. */ |
239 | int dwp_checked; | |
240 | ||
241 | /* The DWP file if there is one, or NULL. */ | |
242 | struct dwp_file *dwp_file; | |
243 | ||
36586728 TT |
244 | /* The shared '.dwz' file, if one exists. This is used when the |
245 | original data was compressed using 'dwz -m'. */ | |
246 | struct dwz_file *dwz_file; | |
247 | ||
72dca2f5 FR |
248 | /* A flag indicating wether this objfile has a section loaded at a |
249 | VMA of 0. */ | |
250 | int has_section_at_zero; | |
9291a0cd | 251 | |
ae2de4f8 DE |
252 | /* True if we are using the mapped index, |
253 | or we are faking it for OBJF_READNOW's sake. */ | |
9291a0cd TT |
254 | unsigned char using_index; |
255 | ||
ae2de4f8 | 256 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
9291a0cd | 257 | struct mapped_index *index_table; |
98bfdba5 | 258 | |
7b9f3c50 | 259 | /* When using index_table, this keeps track of all quick_file_names entries. |
56e64610 DE |
260 | TUs typically share line table entries with a CU, so we maintain a |
261 | separate table of all line table entries to support the sharing. | |
262 | Note that while there can be way more TUs than CUs, we've already | |
263 | sorted all the TUs into "type unit groups", grouped by their | |
264 | DW_AT_stmt_list value. Therefore the only sharing done here is with a | |
265 | CU and its associated TU group if there is one. */ | |
7b9f3c50 DE |
266 | htab_t quick_file_names_table; |
267 | ||
98bfdba5 PA |
268 | /* Set during partial symbol reading, to prevent queueing of full |
269 | symbols. */ | |
270 | int reading_partial_symbols; | |
673bfd45 | 271 | |
dee91e82 | 272 | /* Table mapping type DIEs to their struct type *. |
673bfd45 | 273 | This is NULL if not allocated yet. |
dee91e82 DE |
274 | The mapping is done via (CU/TU signature + DIE offset) -> type. */ |
275 | htab_t die_type_hash; | |
95554aad TT |
276 | |
277 | /* The CUs we recently read. */ | |
278 | VEC (dwarf2_per_cu_ptr) *just_read_cus; | |
6502dd73 DJ |
279 | }; |
280 | ||
281 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 282 | |
251d32d9 | 283 | /* Default names of the debugging sections. */ |
c906108c | 284 | |
233a11ab CS |
285 | /* Note that if the debugging section has been compressed, it might |
286 | have a name like .zdebug_info. */ | |
287 | ||
9cdd5dbd DE |
288 | static const struct dwarf2_debug_sections dwarf2_elf_names = |
289 | { | |
251d32d9 TG |
290 | { ".debug_info", ".zdebug_info" }, |
291 | { ".debug_abbrev", ".zdebug_abbrev" }, | |
292 | { ".debug_line", ".zdebug_line" }, | |
293 | { ".debug_loc", ".zdebug_loc" }, | |
294 | { ".debug_macinfo", ".zdebug_macinfo" }, | |
cf2c3c16 | 295 | { ".debug_macro", ".zdebug_macro" }, |
251d32d9 TG |
296 | { ".debug_str", ".zdebug_str" }, |
297 | { ".debug_ranges", ".zdebug_ranges" }, | |
298 | { ".debug_types", ".zdebug_types" }, | |
3019eac3 | 299 | { ".debug_addr", ".zdebug_addr" }, |
251d32d9 TG |
300 | { ".debug_frame", ".zdebug_frame" }, |
301 | { ".eh_frame", NULL }, | |
24d3216f TT |
302 | { ".gdb_index", ".zgdb_index" }, |
303 | 23 | |
251d32d9 | 304 | }; |
c906108c | 305 | |
80626a55 | 306 | /* List of DWO/DWP sections. */ |
3019eac3 | 307 | |
80626a55 | 308 | static const struct dwop_section_names |
3019eac3 DE |
309 | { |
310 | struct dwarf2_section_names abbrev_dwo; | |
311 | struct dwarf2_section_names info_dwo; | |
312 | struct dwarf2_section_names line_dwo; | |
313 | struct dwarf2_section_names loc_dwo; | |
09262596 DE |
314 | struct dwarf2_section_names macinfo_dwo; |
315 | struct dwarf2_section_names macro_dwo; | |
3019eac3 DE |
316 | struct dwarf2_section_names str_dwo; |
317 | struct dwarf2_section_names str_offsets_dwo; | |
318 | struct dwarf2_section_names types_dwo; | |
80626a55 DE |
319 | struct dwarf2_section_names cu_index; |
320 | struct dwarf2_section_names tu_index; | |
3019eac3 | 321 | } |
80626a55 | 322 | dwop_section_names = |
3019eac3 DE |
323 | { |
324 | { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" }, | |
325 | { ".debug_info.dwo", ".zdebug_info.dwo" }, | |
326 | { ".debug_line.dwo", ".zdebug_line.dwo" }, | |
327 | { ".debug_loc.dwo", ".zdebug_loc.dwo" }, | |
09262596 DE |
328 | { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" }, |
329 | { ".debug_macro.dwo", ".zdebug_macro.dwo" }, | |
3019eac3 DE |
330 | { ".debug_str.dwo", ".zdebug_str.dwo" }, |
331 | { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" }, | |
332 | { ".debug_types.dwo", ".zdebug_types.dwo" }, | |
80626a55 DE |
333 | { ".debug_cu_index", ".zdebug_cu_index" }, |
334 | { ".debug_tu_index", ".zdebug_tu_index" }, | |
3019eac3 DE |
335 | }; |
336 | ||
c906108c SS |
337 | /* local data types */ |
338 | ||
107d2387 AC |
339 | /* The data in a compilation unit header, after target2host |
340 | translation, looks like this. */ | |
c906108c | 341 | struct comp_unit_head |
a738430d | 342 | { |
c764a876 | 343 | unsigned int length; |
a738430d | 344 | short version; |
a738430d MK |
345 | unsigned char addr_size; |
346 | unsigned char signed_addr_p; | |
b64f50a1 | 347 | sect_offset abbrev_offset; |
57349743 | 348 | |
a738430d MK |
349 | /* Size of file offsets; either 4 or 8. */ |
350 | unsigned int offset_size; | |
57349743 | 351 | |
a738430d MK |
352 | /* Size of the length field; either 4 or 12. */ |
353 | unsigned int initial_length_size; | |
57349743 | 354 | |
a738430d MK |
355 | /* Offset to the first byte of this compilation unit header in the |
356 | .debug_info section, for resolving relative reference dies. */ | |
b64f50a1 | 357 | sect_offset offset; |
57349743 | 358 | |
d00adf39 DE |
359 | /* Offset to first die in this cu from the start of the cu. |
360 | This will be the first byte following the compilation unit header. */ | |
b64f50a1 | 361 | cu_offset first_die_offset; |
a738430d | 362 | }; |
c906108c | 363 | |
3da10d80 KS |
364 | /* Type used for delaying computation of method physnames. |
365 | See comments for compute_delayed_physnames. */ | |
366 | struct delayed_method_info | |
367 | { | |
368 | /* The type to which the method is attached, i.e., its parent class. */ | |
369 | struct type *type; | |
370 | ||
371 | /* The index of the method in the type's function fieldlists. */ | |
372 | int fnfield_index; | |
373 | ||
374 | /* The index of the method in the fieldlist. */ | |
375 | int index; | |
376 | ||
377 | /* The name of the DIE. */ | |
378 | const char *name; | |
379 | ||
380 | /* The DIE associated with this method. */ | |
381 | struct die_info *die; | |
382 | }; | |
383 | ||
384 | typedef struct delayed_method_info delayed_method_info; | |
385 | DEF_VEC_O (delayed_method_info); | |
386 | ||
e7c27a73 DJ |
387 | /* Internal state when decoding a particular compilation unit. */ |
388 | struct dwarf2_cu | |
389 | { | |
390 | /* The objfile containing this compilation unit. */ | |
391 | struct objfile *objfile; | |
392 | ||
d00adf39 | 393 | /* The header of the compilation unit. */ |
e7c27a73 | 394 | struct comp_unit_head header; |
e142c38c | 395 | |
d00adf39 DE |
396 | /* Base address of this compilation unit. */ |
397 | CORE_ADDR base_address; | |
398 | ||
399 | /* Non-zero if base_address has been set. */ | |
400 | int base_known; | |
401 | ||
e142c38c DJ |
402 | /* The language we are debugging. */ |
403 | enum language language; | |
404 | const struct language_defn *language_defn; | |
405 | ||
b0f35d58 DL |
406 | const char *producer; |
407 | ||
e142c38c DJ |
408 | /* The generic symbol table building routines have separate lists for |
409 | file scope symbols and all all other scopes (local scopes). So | |
410 | we need to select the right one to pass to add_symbol_to_list(). | |
411 | We do it by keeping a pointer to the correct list in list_in_scope. | |
412 | ||
413 | FIXME: The original dwarf code just treated the file scope as the | |
414 | first local scope, and all other local scopes as nested local | |
415 | scopes, and worked fine. Check to see if we really need to | |
416 | distinguish these in buildsym.c. */ | |
417 | struct pending **list_in_scope; | |
418 | ||
433df2d4 DE |
419 | /* The abbrev table for this CU. |
420 | Normally this points to the abbrev table in the objfile. | |
421 | But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */ | |
422 | struct abbrev_table *abbrev_table; | |
72bf9492 | 423 | |
b64f50a1 JK |
424 | /* Hash table holding all the loaded partial DIEs |
425 | with partial_die->offset.SECT_OFF as hash. */ | |
72bf9492 DJ |
426 | htab_t partial_dies; |
427 | ||
428 | /* Storage for things with the same lifetime as this read-in compilation | |
429 | unit, including partial DIEs. */ | |
430 | struct obstack comp_unit_obstack; | |
431 | ||
ae038cb0 DJ |
432 | /* When multiple dwarf2_cu structures are living in memory, this field |
433 | chains them all together, so that they can be released efficiently. | |
434 | We will probably also want a generation counter so that most-recently-used | |
435 | compilation units are cached... */ | |
436 | struct dwarf2_per_cu_data *read_in_chain; | |
437 | ||
438 | /* Backchain to our per_cu entry if the tree has been built. */ | |
439 | struct dwarf2_per_cu_data *per_cu; | |
440 | ||
441 | /* How many compilation units ago was this CU last referenced? */ | |
442 | int last_used; | |
443 | ||
b64f50a1 JK |
444 | /* A hash table of DIE cu_offset for following references with |
445 | die_info->offset.sect_off as hash. */ | |
51545339 | 446 | htab_t die_hash; |
10b3939b DJ |
447 | |
448 | /* Full DIEs if read in. */ | |
449 | struct die_info *dies; | |
450 | ||
451 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
452 | units referenced by this one. Only set during full symbol processing; | |
453 | partial symbol tables do not have dependencies. */ | |
454 | htab_t dependencies; | |
455 | ||
cb1df416 DJ |
456 | /* Header data from the line table, during full symbol processing. */ |
457 | struct line_header *line_header; | |
458 | ||
3da10d80 KS |
459 | /* A list of methods which need to have physnames computed |
460 | after all type information has been read. */ | |
461 | VEC (delayed_method_info) *method_list; | |
462 | ||
96408a79 SA |
463 | /* To be copied to symtab->call_site_htab. */ |
464 | htab_t call_site_htab; | |
465 | ||
034e5797 DE |
466 | /* Non-NULL if this CU came from a DWO file. |
467 | There is an invariant here that is important to remember: | |
468 | Except for attributes copied from the top level DIE in the "main" | |
469 | (or "stub") file in preparation for reading the DWO file | |
470 | (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU. | |
471 | Either there isn't a DWO file (in which case this is NULL and the point | |
472 | is moot), or there is and either we're not going to read it (in which | |
473 | case this is NULL) or there is and we are reading it (in which case this | |
474 | is non-NULL). */ | |
3019eac3 DE |
475 | struct dwo_unit *dwo_unit; |
476 | ||
477 | /* The DW_AT_addr_base attribute if present, zero otherwise | |
478 | (zero is a valid value though). | |
479 | Note this value comes from the stub CU/TU's DIE. */ | |
480 | ULONGEST addr_base; | |
481 | ||
2e3cf129 DE |
482 | /* The DW_AT_ranges_base attribute if present, zero otherwise |
483 | (zero is a valid value though). | |
484 | Note this value comes from the stub CU/TU's DIE. | |
485 | Also note that the value is zero in the non-DWO case so this value can | |
ab435259 DE |
486 | be used without needing to know whether DWO files are in use or not. |
487 | N.B. This does not apply to DW_AT_ranges appearing in | |
488 | DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever | |
489 | DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then | |
490 | DW_AT_ranges_base *would* have to be applied, and we'd have to care | |
491 | whether the DW_AT_ranges attribute came from the skeleton or DWO. */ | |
2e3cf129 DE |
492 | ULONGEST ranges_base; |
493 | ||
ae038cb0 DJ |
494 | /* Mark used when releasing cached dies. */ |
495 | unsigned int mark : 1; | |
496 | ||
8be455d7 JK |
497 | /* This CU references .debug_loc. See the symtab->locations_valid field. |
498 | This test is imperfect as there may exist optimized debug code not using | |
499 | any location list and still facing inlining issues if handled as | |
500 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
8be455d7 | 501 | unsigned int has_loclist : 1; |
ba919b58 | 502 | |
1b80a9fa JK |
503 | /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set |
504 | if all the producer_is_* fields are valid. This information is cached | |
505 | because profiling CU expansion showed excessive time spent in | |
506 | producer_is_gxx_lt_4_6. */ | |
ba919b58 TT |
507 | unsigned int checked_producer : 1; |
508 | unsigned int producer_is_gxx_lt_4_6 : 1; | |
1b80a9fa | 509 | unsigned int producer_is_gcc_lt_4_3 : 1; |
685b1105 | 510 | unsigned int producer_is_icc : 1; |
e7c27a73 DJ |
511 | }; |
512 | ||
10b3939b DJ |
513 | /* Persistent data held for a compilation unit, even when not |
514 | processing it. We put a pointer to this structure in the | |
28dee7f5 | 515 | read_symtab_private field of the psymtab. */ |
10b3939b | 516 | |
ae038cb0 DJ |
517 | struct dwarf2_per_cu_data |
518 | { | |
36586728 | 519 | /* The start offset and length of this compilation unit. |
45452591 | 520 | NOTE: Unlike comp_unit_head.length, this length includes |
3019eac3 DE |
521 | initial_length_size. |
522 | If the DIE refers to a DWO file, this is always of the original die, | |
523 | not the DWO file. */ | |
b64f50a1 | 524 | sect_offset offset; |
36586728 | 525 | unsigned int length; |
ae038cb0 DJ |
526 | |
527 | /* Flag indicating this compilation unit will be read in before | |
528 | any of the current compilation units are processed. */ | |
c764a876 | 529 | unsigned int queued : 1; |
ae038cb0 | 530 | |
0d99eb77 DE |
531 | /* This flag will be set when reading partial DIEs if we need to load |
532 | absolutely all DIEs for this compilation unit, instead of just the ones | |
533 | we think are interesting. It gets set if we look for a DIE in the | |
5afb4e99 DJ |
534 | hash table and don't find it. */ |
535 | unsigned int load_all_dies : 1; | |
536 | ||
3019eac3 DE |
537 | /* Non-zero if this CU is from .debug_types. */ |
538 | unsigned int is_debug_types : 1; | |
539 | ||
36586728 TT |
540 | /* Non-zero if this CU is from the .dwz file. */ |
541 | unsigned int is_dwz : 1; | |
542 | ||
3019eac3 DE |
543 | /* The section this CU/TU lives in. |
544 | If the DIE refers to a DWO file, this is always the original die, | |
545 | not the DWO file. */ | |
546 | struct dwarf2_section_info *info_or_types_section; | |
348e048f | 547 | |
17ea53c3 JK |
548 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
549 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 550 | struct dwarf2_cu *cu; |
1c379e20 | 551 | |
9cdd5dbd DE |
552 | /* The corresponding objfile. |
553 | Normally we can get the objfile from dwarf2_per_objfile. | |
554 | However we can enter this file with just a "per_cu" handle. */ | |
9291a0cd TT |
555 | struct objfile *objfile; |
556 | ||
557 | /* When using partial symbol tables, the 'psymtab' field is active. | |
558 | Otherwise the 'quick' field is active. */ | |
559 | union | |
560 | { | |
561 | /* The partial symbol table associated with this compilation unit, | |
95554aad | 562 | or NULL for unread partial units. */ |
9291a0cd TT |
563 | struct partial_symtab *psymtab; |
564 | ||
565 | /* Data needed by the "quick" functions. */ | |
566 | struct dwarf2_per_cu_quick_data *quick; | |
567 | } v; | |
95554aad | 568 | |
796a7ff8 DE |
569 | /* The CUs we import using DW_TAG_imported_unit. This is filled in |
570 | while reading psymtabs, used to compute the psymtab dependencies, | |
571 | and then cleared. Then it is filled in again while reading full | |
572 | symbols, and only deleted when the objfile is destroyed. | |
573 | ||
574 | This is also used to work around a difference between the way gold | |
575 | generates .gdb_index version <=7 and the way gdb does. Arguably this | |
576 | is a gold bug. For symbols coming from TUs, gold records in the index | |
577 | the CU that includes the TU instead of the TU itself. This breaks | |
578 | dw2_lookup_symbol: It assumes that if the index says symbol X lives | |
579 | in CU/TU Y, then one need only expand Y and a subsequent lookup in Y | |
580 | will find X. Alas TUs live in their own symtab, so after expanding CU Y | |
581 | we need to look in TU Z to find X. Fortunately, this is akin to | |
582 | DW_TAG_imported_unit, so we just use the same mechanism: For | |
583 | .gdb_index version <=7 this also records the TUs that the CU referred | |
584 | to. Concurrently with this change gdb was modified to emit version 8 | |
585 | indices so we only pay a price for gold generated indices. */ | |
586 | VEC (dwarf2_per_cu_ptr) *imported_symtabs; | |
587 | ||
588 | /* Type units are grouped by their DW_AT_stmt_list entry so that they | |
589 | can share them. If this is a TU, this points to the containing | |
590 | symtab. */ | |
591 | struct type_unit_group *type_unit_group; | |
ae038cb0 DJ |
592 | }; |
593 | ||
348e048f DE |
594 | /* Entry in the signatured_types hash table. */ |
595 | ||
596 | struct signatured_type | |
597 | { | |
42e7ad6c DE |
598 | /* The "per_cu" object of this type. |
599 | N.B.: This is the first member so that it's easy to convert pointers | |
600 | between them. */ | |
601 | struct dwarf2_per_cu_data per_cu; | |
602 | ||
3019eac3 | 603 | /* The type's signature. */ |
348e048f DE |
604 | ULONGEST signature; |
605 | ||
3019eac3 DE |
606 | /* Offset in the TU of the type's DIE, as read from the TU header. |
607 | If the definition lives in a DWO file, this value is unusable. */ | |
608 | cu_offset type_offset_in_tu; | |
609 | ||
610 | /* Offset in the section of the type's DIE. | |
611 | If the definition lives in a DWO file, this is the offset in the | |
612 | .debug_types.dwo section. | |
613 | The value is zero until the actual value is known. | |
614 | Zero is otherwise not a valid section offset. */ | |
615 | sect_offset type_offset_in_section; | |
348e048f DE |
616 | }; |
617 | ||
094b34ac DE |
618 | /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list. |
619 | This includes type_unit_group and quick_file_names. */ | |
620 | ||
621 | struct stmt_list_hash | |
622 | { | |
623 | /* The DWO unit this table is from or NULL if there is none. */ | |
624 | struct dwo_unit *dwo_unit; | |
625 | ||
626 | /* Offset in .debug_line or .debug_line.dwo. */ | |
627 | sect_offset line_offset; | |
628 | }; | |
629 | ||
f4dc4d17 DE |
630 | /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to |
631 | an object of this type. */ | |
632 | ||
633 | struct type_unit_group | |
634 | { | |
635 | /* dwarf2read.c's main "handle" on the symtab. | |
636 | To simplify things we create an artificial CU that "includes" all the | |
637 | type units using this stmt_list so that the rest of the code still has | |
638 | a "per_cu" handle on the symtab. | |
639 | This PER_CU is recognized by having no section. */ | |
640 | #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL) | |
094b34ac DE |
641 | struct dwarf2_per_cu_data per_cu; |
642 | ||
643 | union | |
644 | { | |
645 | /* The TUs that share this DW_AT_stmt_list entry. | |
646 | This is added to while parsing type units to build partial symtabs, | |
647 | and is deleted afterwards and not used again. */ | |
648 | VEC (dwarf2_per_cu_ptr) *tus; | |
f4dc4d17 | 649 | |
094b34ac DE |
650 | /* When reading the line table in "quick" functions, we need a real TU. |
651 | Any will do, we know they all share the same DW_AT_stmt_list entry. | |
652 | For simplicity's sake, we pick the first one. */ | |
653 | struct dwarf2_per_cu_data *first_tu; | |
654 | } t; | |
f4dc4d17 DE |
655 | |
656 | /* The primary symtab. | |
094b34ac DE |
657 | Type units in a group needn't all be defined in the same source file, |
658 | so we create an essentially anonymous symtab as the primary symtab. */ | |
f4dc4d17 DE |
659 | struct symtab *primary_symtab; |
660 | ||
094b34ac DE |
661 | /* The data used to construct the hash key. */ |
662 | struct stmt_list_hash hash; | |
f4dc4d17 DE |
663 | |
664 | /* The number of symtabs from the line header. | |
665 | The value here must match line_header.num_file_names. */ | |
666 | unsigned int num_symtabs; | |
667 | ||
668 | /* The symbol tables for this TU (obtained from the files listed in | |
669 | DW_AT_stmt_list). | |
670 | WARNING: The order of entries here must match the order of entries | |
671 | in the line header. After the first TU using this type_unit_group, the | |
672 | line header for the subsequent TUs is recreated from this. This is done | |
673 | because we need to use the same symtabs for each TU using the same | |
674 | DW_AT_stmt_list value. Also note that symtabs may be repeated here, | |
675 | there's no guarantee the line header doesn't have duplicate entries. */ | |
676 | struct symtab **symtabs; | |
677 | }; | |
678 | ||
80626a55 | 679 | /* These sections are what may appear in a DWO file. */ |
3019eac3 DE |
680 | |
681 | struct dwo_sections | |
682 | { | |
683 | struct dwarf2_section_info abbrev; | |
3019eac3 DE |
684 | struct dwarf2_section_info line; |
685 | struct dwarf2_section_info loc; | |
09262596 DE |
686 | struct dwarf2_section_info macinfo; |
687 | struct dwarf2_section_info macro; | |
3019eac3 DE |
688 | struct dwarf2_section_info str; |
689 | struct dwarf2_section_info str_offsets; | |
80626a55 DE |
690 | /* In the case of a virtual DWO file, these two are unused. */ |
691 | struct dwarf2_section_info info; | |
3019eac3 DE |
692 | VEC (dwarf2_section_info_def) *types; |
693 | }; | |
694 | ||
695 | /* Common bits of DWO CUs/TUs. */ | |
696 | ||
697 | struct dwo_unit | |
698 | { | |
699 | /* Backlink to the containing struct dwo_file. */ | |
700 | struct dwo_file *dwo_file; | |
701 | ||
702 | /* The "id" that distinguishes this CU/TU. | |
703 | .debug_info calls this "dwo_id", .debug_types calls this "signature". | |
704 | Since signatures came first, we stick with it for consistency. */ | |
705 | ULONGEST signature; | |
706 | ||
707 | /* The section this CU/TU lives in, in the DWO file. */ | |
708 | struct dwarf2_section_info *info_or_types_section; | |
709 | ||
710 | /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */ | |
711 | sect_offset offset; | |
712 | unsigned int length; | |
713 | ||
714 | /* For types, offset in the type's DIE of the type defined by this TU. */ | |
715 | cu_offset type_offset_in_tu; | |
716 | }; | |
717 | ||
80626a55 DE |
718 | /* Data for one DWO file. |
719 | This includes virtual DWO files that have been packaged into a | |
720 | DWP file. */ | |
3019eac3 DE |
721 | |
722 | struct dwo_file | |
723 | { | |
80626a55 DE |
724 | /* The DW_AT_GNU_dwo_name attribute. This is the hash key. |
725 | For virtual DWO files the name is constructed from the section offsets | |
726 | of abbrev,line,loc,str_offsets so that we combine virtual DWO files | |
727 | from related CU+TUs. */ | |
728 | const char *name; | |
3019eac3 | 729 | |
80626a55 DE |
730 | /* The bfd, when the file is open. Otherwise this is NULL. |
731 | This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */ | |
732 | bfd *dbfd; | |
3019eac3 DE |
733 | |
734 | /* Section info for this file. */ | |
735 | struct dwo_sections sections; | |
736 | ||
737 | /* Table of CUs in the file. | |
738 | Each element is a struct dwo_unit. */ | |
739 | htab_t cus; | |
740 | ||
741 | /* Table of TUs in the file. | |
742 | Each element is a struct dwo_unit. */ | |
743 | htab_t tus; | |
744 | }; | |
745 | ||
80626a55 DE |
746 | /* These sections are what may appear in a DWP file. */ |
747 | ||
748 | struct dwp_sections | |
749 | { | |
750 | struct dwarf2_section_info str; | |
751 | struct dwarf2_section_info cu_index; | |
752 | struct dwarf2_section_info tu_index; | |
753 | /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced | |
754 | by section number. We don't need to record them here. */ | |
755 | }; | |
756 | ||
757 | /* These sections are what may appear in a virtual DWO file. */ | |
758 | ||
759 | struct virtual_dwo_sections | |
760 | { | |
761 | struct dwarf2_section_info abbrev; | |
762 | struct dwarf2_section_info line; | |
763 | struct dwarf2_section_info loc; | |
764 | struct dwarf2_section_info macinfo; | |
765 | struct dwarf2_section_info macro; | |
766 | struct dwarf2_section_info str_offsets; | |
767 | /* Each DWP hash table entry records one CU or one TU. | |
768 | That is recorded here, and copied to dwo_unit.info_or_types_section. */ | |
769 | struct dwarf2_section_info info_or_types; | |
770 | }; | |
771 | ||
772 | /* Contents of DWP hash tables. */ | |
773 | ||
774 | struct dwp_hash_table | |
775 | { | |
776 | uint32_t nr_units, nr_slots; | |
777 | const gdb_byte *hash_table, *unit_table, *section_pool; | |
778 | }; | |
779 | ||
780 | /* Data for one DWP file. */ | |
781 | ||
782 | struct dwp_file | |
783 | { | |
784 | /* Name of the file. */ | |
785 | const char *name; | |
786 | ||
787 | /* The bfd, when the file is open. Otherwise this is NULL. */ | |
788 | bfd *dbfd; | |
789 | ||
790 | /* Section info for this file. */ | |
791 | struct dwp_sections sections; | |
792 | ||
793 | /* Table of CUs in the file. */ | |
794 | const struct dwp_hash_table *cus; | |
795 | ||
796 | /* Table of TUs in the file. */ | |
797 | const struct dwp_hash_table *tus; | |
798 | ||
799 | /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */ | |
800 | htab_t loaded_cutus; | |
801 | ||
802 | /* Table to map ELF section numbers to their sections. */ | |
803 | unsigned int num_sections; | |
804 | asection **elf_sections; | |
805 | }; | |
806 | ||
36586728 TT |
807 | /* This represents a '.dwz' file. */ |
808 | ||
809 | struct dwz_file | |
810 | { | |
811 | /* A dwz file can only contain a few sections. */ | |
812 | struct dwarf2_section_info abbrev; | |
813 | struct dwarf2_section_info info; | |
814 | struct dwarf2_section_info str; | |
815 | struct dwarf2_section_info line; | |
816 | struct dwarf2_section_info macro; | |
2ec9a5e0 | 817 | struct dwarf2_section_info gdb_index; |
36586728 TT |
818 | |
819 | /* The dwz's BFD. */ | |
820 | bfd *dwz_bfd; | |
821 | }; | |
822 | ||
0963b4bd MS |
823 | /* Struct used to pass misc. parameters to read_die_and_children, et |
824 | al. which are used for both .debug_info and .debug_types dies. | |
825 | All parameters here are unchanging for the life of the call. This | |
dee91e82 | 826 | struct exists to abstract away the constant parameters of die reading. */ |
93311388 DE |
827 | |
828 | struct die_reader_specs | |
829 | { | |
dee91e82 | 830 | /* die_section->asection->owner. */ |
93311388 DE |
831 | bfd* abfd; |
832 | ||
833 | /* The CU of the DIE we are parsing. */ | |
834 | struct dwarf2_cu *cu; | |
835 | ||
80626a55 | 836 | /* Non-NULL if reading a DWO file (including one packaged into a DWP). */ |
3019eac3 DE |
837 | struct dwo_file *dwo_file; |
838 | ||
dee91e82 | 839 | /* The section the die comes from. |
3019eac3 | 840 | This is either .debug_info or .debug_types, or the .dwo variants. */ |
dee91e82 DE |
841 | struct dwarf2_section_info *die_section; |
842 | ||
843 | /* die_section->buffer. */ | |
844 | gdb_byte *buffer; | |
f664829e DE |
845 | |
846 | /* The end of the buffer. */ | |
847 | const gdb_byte *buffer_end; | |
93311388 DE |
848 | }; |
849 | ||
fd820528 | 850 | /* Type of function passed to init_cutu_and_read_dies, et.al. */ |
dee91e82 DE |
851 | typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader, |
852 | gdb_byte *info_ptr, | |
853 | struct die_info *comp_unit_die, | |
854 | int has_children, | |
855 | void *data); | |
856 | ||
debd256d JB |
857 | /* The line number information for a compilation unit (found in the |
858 | .debug_line section) begins with a "statement program header", | |
859 | which contains the following information. */ | |
860 | struct line_header | |
861 | { | |
862 | unsigned int total_length; | |
863 | unsigned short version; | |
864 | unsigned int header_length; | |
865 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 866 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
867 | unsigned char default_is_stmt; |
868 | int line_base; | |
869 | unsigned char line_range; | |
870 | unsigned char opcode_base; | |
871 | ||
872 | /* standard_opcode_lengths[i] is the number of operands for the | |
873 | standard opcode whose value is i. This means that | |
874 | standard_opcode_lengths[0] is unused, and the last meaningful | |
875 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
876 | unsigned char *standard_opcode_lengths; | |
877 | ||
878 | /* The include_directories table. NOTE! These strings are not | |
879 | allocated with xmalloc; instead, they are pointers into | |
880 | debug_line_buffer. If you try to free them, `free' will get | |
881 | indigestion. */ | |
882 | unsigned int num_include_dirs, include_dirs_size; | |
883 | char **include_dirs; | |
884 | ||
885 | /* The file_names table. NOTE! These strings are not allocated | |
886 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
887 | Don't try to free them directly. */ | |
888 | unsigned int num_file_names, file_names_size; | |
889 | struct file_entry | |
c906108c | 890 | { |
debd256d JB |
891 | char *name; |
892 | unsigned int dir_index; | |
893 | unsigned int mod_time; | |
894 | unsigned int length; | |
aaa75496 | 895 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 896 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
897 | } *file_names; |
898 | ||
899 | /* The start and end of the statement program following this | |
6502dd73 | 900 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 901 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 902 | }; |
c906108c SS |
903 | |
904 | /* When we construct a partial symbol table entry we only | |
0963b4bd | 905 | need this much information. */ |
c906108c SS |
906 | struct partial_die_info |
907 | { | |
72bf9492 | 908 | /* Offset of this DIE. */ |
b64f50a1 | 909 | sect_offset offset; |
72bf9492 DJ |
910 | |
911 | /* DWARF-2 tag for this DIE. */ | |
912 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
913 | ||
72bf9492 DJ |
914 | /* Assorted flags describing the data found in this DIE. */ |
915 | unsigned int has_children : 1; | |
916 | unsigned int is_external : 1; | |
917 | unsigned int is_declaration : 1; | |
918 | unsigned int has_type : 1; | |
919 | unsigned int has_specification : 1; | |
920 | unsigned int has_pc_info : 1; | |
481860b3 | 921 | unsigned int may_be_inlined : 1; |
72bf9492 DJ |
922 | |
923 | /* Flag set if the SCOPE field of this structure has been | |
924 | computed. */ | |
925 | unsigned int scope_set : 1; | |
926 | ||
fa4028e9 JB |
927 | /* Flag set if the DIE has a byte_size attribute. */ |
928 | unsigned int has_byte_size : 1; | |
929 | ||
98bfdba5 PA |
930 | /* Flag set if any of the DIE's children are template arguments. */ |
931 | unsigned int has_template_arguments : 1; | |
932 | ||
abc72ce4 DE |
933 | /* Flag set if fixup_partial_die has been called on this die. */ |
934 | unsigned int fixup_called : 1; | |
935 | ||
36586728 TT |
936 | /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */ |
937 | unsigned int is_dwz : 1; | |
938 | ||
939 | /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */ | |
940 | unsigned int spec_is_dwz : 1; | |
941 | ||
72bf9492 | 942 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 943 | sometimes a default name for unnamed DIEs. */ |
15d034d0 | 944 | const char *name; |
72bf9492 | 945 | |
abc72ce4 DE |
946 | /* The linkage name, if present. */ |
947 | const char *linkage_name; | |
948 | ||
72bf9492 DJ |
949 | /* The scope to prepend to our children. This is generally |
950 | allocated on the comp_unit_obstack, so will disappear | |
951 | when this compilation unit leaves the cache. */ | |
15d034d0 | 952 | const char *scope; |
72bf9492 | 953 | |
95554aad TT |
954 | /* Some data associated with the partial DIE. The tag determines |
955 | which field is live. */ | |
956 | union | |
957 | { | |
958 | /* The location description associated with this DIE, if any. */ | |
959 | struct dwarf_block *locdesc; | |
960 | /* The offset of an import, for DW_TAG_imported_unit. */ | |
961 | sect_offset offset; | |
962 | } d; | |
72bf9492 DJ |
963 | |
964 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
965 | CORE_ADDR lowpc; |
966 | CORE_ADDR highpc; | |
72bf9492 | 967 | |
93311388 | 968 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 969 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
970 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
971 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
fe1b8b76 | 972 | gdb_byte *sibling; |
72bf9492 DJ |
973 | |
974 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
975 | DW_AT_specification (or DW_AT_abstract_origin or | |
976 | DW_AT_extension). */ | |
b64f50a1 | 977 | sect_offset spec_offset; |
72bf9492 DJ |
978 | |
979 | /* Pointers to this DIE's parent, first child, and next sibling, | |
980 | if any. */ | |
981 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
982 | }; |
983 | ||
0963b4bd | 984 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
985 | struct abbrev_info |
986 | { | |
987 | unsigned int number; /* number identifying abbrev */ | |
988 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
989 | unsigned short has_children; /* boolean */ |
990 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
991 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
992 | struct abbrev_info *next; /* next in chain */ | |
993 | }; | |
994 | ||
995 | struct attr_abbrev | |
996 | { | |
9d25dd43 DE |
997 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
998 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
999 | }; |
1000 | ||
433df2d4 DE |
1001 | /* Size of abbrev_table.abbrev_hash_table. */ |
1002 | #define ABBREV_HASH_SIZE 121 | |
1003 | ||
1004 | /* Top level data structure to contain an abbreviation table. */ | |
1005 | ||
1006 | struct abbrev_table | |
1007 | { | |
f4dc4d17 DE |
1008 | /* Where the abbrev table came from. |
1009 | This is used as a sanity check when the table is used. */ | |
433df2d4 DE |
1010 | sect_offset offset; |
1011 | ||
1012 | /* Storage for the abbrev table. */ | |
1013 | struct obstack abbrev_obstack; | |
1014 | ||
1015 | /* Hash table of abbrevs. | |
1016 | This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack. | |
1017 | It could be statically allocated, but the previous code didn't so we | |
1018 | don't either. */ | |
1019 | struct abbrev_info **abbrevs; | |
1020 | }; | |
1021 | ||
0963b4bd | 1022 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
1023 | struct attribute |
1024 | { | |
9d25dd43 | 1025 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
1026 | ENUM_BITFIELD(dwarf_form) form : 15; |
1027 | ||
1028 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
1029 | field should be in u.str (existing only for DW_STRING) but it is kept | |
1030 | here for better struct attribute alignment. */ | |
1031 | unsigned int string_is_canonical : 1; | |
1032 | ||
b60c80d6 DJ |
1033 | union |
1034 | { | |
15d034d0 | 1035 | const char *str; |
b60c80d6 | 1036 | struct dwarf_block *blk; |
43bbcdc2 PH |
1037 | ULONGEST unsnd; |
1038 | LONGEST snd; | |
b60c80d6 | 1039 | CORE_ADDR addr; |
348e048f | 1040 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
1041 | } |
1042 | u; | |
1043 | }; | |
1044 | ||
0963b4bd | 1045 | /* This data structure holds a complete die structure. */ |
c906108c SS |
1046 | struct die_info |
1047 | { | |
76815b17 DE |
1048 | /* DWARF-2 tag for this DIE. */ |
1049 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
1050 | ||
1051 | /* Number of attributes */ | |
98bfdba5 PA |
1052 | unsigned char num_attrs; |
1053 | ||
1054 | /* True if we're presently building the full type name for the | |
1055 | type derived from this DIE. */ | |
1056 | unsigned char building_fullname : 1; | |
76815b17 DE |
1057 | |
1058 | /* Abbrev number */ | |
1059 | unsigned int abbrev; | |
1060 | ||
93311388 | 1061 | /* Offset in .debug_info or .debug_types section. */ |
b64f50a1 | 1062 | sect_offset offset; |
78ba4af6 JB |
1063 | |
1064 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
1065 | points to this die's parent; CHILD points to the first child of | |
1066 | this node; and all the children of a given node are chained | |
4950bc1c | 1067 | together via their SIBLING fields. */ |
639d11d3 DC |
1068 | struct die_info *child; /* Its first child, if any. */ |
1069 | struct die_info *sibling; /* Its next sibling, if any. */ | |
1070 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 1071 | |
b60c80d6 DJ |
1072 | /* An array of attributes, with NUM_ATTRS elements. There may be |
1073 | zero, but it's not common and zero-sized arrays are not | |
1074 | sufficiently portable C. */ | |
1075 | struct attribute attrs[1]; | |
c906108c SS |
1076 | }; |
1077 | ||
0963b4bd | 1078 | /* Get at parts of an attribute structure. */ |
c906108c SS |
1079 | |
1080 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 1081 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
1082 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
1083 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
1084 | #define DW_SND(attr) ((attr)->u.snd) | |
1085 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 1086 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c | 1087 | |
0963b4bd | 1088 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
1089 | struct dwarf_block |
1090 | { | |
56eb65bd | 1091 | size_t size; |
1d6edc3c JK |
1092 | |
1093 | /* Valid only if SIZE is not zero. */ | |
fe1b8b76 | 1094 | gdb_byte *data; |
c906108c SS |
1095 | }; |
1096 | ||
c906108c SS |
1097 | #ifndef ATTR_ALLOC_CHUNK |
1098 | #define ATTR_ALLOC_CHUNK 4 | |
1099 | #endif | |
1100 | ||
c906108c SS |
1101 | /* Allocate fields for structs, unions and enums in this size. */ |
1102 | #ifndef DW_FIELD_ALLOC_CHUNK | |
1103 | #define DW_FIELD_ALLOC_CHUNK 4 | |
1104 | #endif | |
1105 | ||
c906108c SS |
1106 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
1107 | but this would require a corresponding change in unpack_field_as_long | |
1108 | and friends. */ | |
1109 | static int bits_per_byte = 8; | |
1110 | ||
1111 | /* The routines that read and process dies for a C struct or C++ class | |
1112 | pass lists of data member fields and lists of member function fields | |
1113 | in an instance of a field_info structure, as defined below. */ | |
1114 | struct field_info | |
c5aa993b | 1115 | { |
0963b4bd | 1116 | /* List of data member and baseclasses fields. */ |
c5aa993b JM |
1117 | struct nextfield |
1118 | { | |
1119 | struct nextfield *next; | |
1120 | int accessibility; | |
1121 | int virtuality; | |
1122 | struct field field; | |
1123 | } | |
7d0ccb61 | 1124 | *fields, *baseclasses; |
c906108c | 1125 | |
7d0ccb61 | 1126 | /* Number of fields (including baseclasses). */ |
c5aa993b | 1127 | int nfields; |
c906108c | 1128 | |
c5aa993b JM |
1129 | /* Number of baseclasses. */ |
1130 | int nbaseclasses; | |
c906108c | 1131 | |
c5aa993b JM |
1132 | /* Set if the accesibility of one of the fields is not public. */ |
1133 | int non_public_fields; | |
c906108c | 1134 | |
c5aa993b JM |
1135 | /* Member function fields array, entries are allocated in the order they |
1136 | are encountered in the object file. */ | |
1137 | struct nextfnfield | |
1138 | { | |
1139 | struct nextfnfield *next; | |
1140 | struct fn_field fnfield; | |
1141 | } | |
1142 | *fnfields; | |
c906108c | 1143 | |
c5aa993b JM |
1144 | /* Member function fieldlist array, contains name of possibly overloaded |
1145 | member function, number of overloaded member functions and a pointer | |
1146 | to the head of the member function field chain. */ | |
1147 | struct fnfieldlist | |
1148 | { | |
15d034d0 | 1149 | const char *name; |
c5aa993b JM |
1150 | int length; |
1151 | struct nextfnfield *head; | |
1152 | } | |
1153 | *fnfieldlists; | |
c906108c | 1154 | |
c5aa993b JM |
1155 | /* Number of entries in the fnfieldlists array. */ |
1156 | int nfnfields; | |
98751a41 JK |
1157 | |
1158 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
1159 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
1160 | struct typedef_field_list | |
1161 | { | |
1162 | struct typedef_field field; | |
1163 | struct typedef_field_list *next; | |
1164 | } | |
1165 | *typedef_field_list; | |
1166 | unsigned typedef_field_list_count; | |
c5aa993b | 1167 | }; |
c906108c | 1168 | |
10b3939b DJ |
1169 | /* One item on the queue of compilation units to read in full symbols |
1170 | for. */ | |
1171 | struct dwarf2_queue_item | |
1172 | { | |
1173 | struct dwarf2_per_cu_data *per_cu; | |
95554aad | 1174 | enum language pretend_language; |
10b3939b DJ |
1175 | struct dwarf2_queue_item *next; |
1176 | }; | |
1177 | ||
1178 | /* The current queue. */ | |
1179 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
1180 | ||
ae038cb0 DJ |
1181 | /* Loaded secondary compilation units are kept in memory until they |
1182 | have not been referenced for the processing of this many | |
1183 | compilation units. Set this to zero to disable caching. Cache | |
1184 | sizes of up to at least twenty will improve startup time for | |
1185 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
1186 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
1187 | static void |
1188 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
1189 | struct cmd_list_element *c, const char *value) | |
1190 | { | |
3e43a32a MS |
1191 | fprintf_filtered (file, _("The upper bound on the age of cached " |
1192 | "dwarf2 compilation units is %s.\n"), | |
920d2a44 AC |
1193 | value); |
1194 | } | |
1195 | ||
ae038cb0 | 1196 | |
0963b4bd | 1197 | /* Various complaints about symbol reading that don't abort the process. */ |
c906108c | 1198 | |
4d3c2250 KB |
1199 | static void |
1200 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 1201 | { |
4d3c2250 | 1202 | complaint (&symfile_complaints, |
e2e0b3e5 | 1203 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
1204 | } |
1205 | ||
25e43795 DJ |
1206 | static void |
1207 | dwarf2_debug_line_missing_file_complaint (void) | |
1208 | { | |
1209 | complaint (&symfile_complaints, | |
1210 | _(".debug_line section has line data without a file")); | |
1211 | } | |
1212 | ||
59205f5a JB |
1213 | static void |
1214 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
1215 | { | |
1216 | complaint (&symfile_complaints, | |
3e43a32a MS |
1217 | _(".debug_line section has line " |
1218 | "program sequence without an end")); | |
59205f5a JB |
1219 | } |
1220 | ||
4d3c2250 KB |
1221 | static void |
1222 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 1223 | { |
e2e0b3e5 | 1224 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
1225 | } |
1226 | ||
4d3c2250 KB |
1227 | static void |
1228 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
1229 | int arg3) | |
2e276125 | 1230 | { |
4d3c2250 | 1231 | complaint (&symfile_complaints, |
3e43a32a MS |
1232 | _("const value length mismatch for '%s', got %d, expected %d"), |
1233 | arg1, arg2, arg3); | |
4d3c2250 KB |
1234 | } |
1235 | ||
1236 | static void | |
f664829e | 1237 | dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section) |
2e276125 | 1238 | { |
4d3c2250 | 1239 | complaint (&symfile_complaints, |
f664829e DE |
1240 | _("debug info runs off end of %s section" |
1241 | " [in module %s]"), | |
1242 | section->asection->name, | |
1243 | bfd_get_filename (section->asection->owner)); | |
4d3c2250 KB |
1244 | } |
1245 | ||
1246 | static void | |
1247 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 1248 | { |
4d3c2250 | 1249 | complaint (&symfile_complaints, |
3e43a32a MS |
1250 | _("macro debug info contains a " |
1251 | "malformed macro definition:\n`%s'"), | |
4d3c2250 KB |
1252 | arg1); |
1253 | } | |
1254 | ||
1255 | static void | |
1256 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 1257 | { |
4d3c2250 | 1258 | complaint (&symfile_complaints, |
3e43a32a MS |
1259 | _("invalid attribute class or form for '%s' in '%s'"), |
1260 | arg1, arg2); | |
4d3c2250 | 1261 | } |
c906108c | 1262 | |
c906108c SS |
1263 | /* local function prototypes */ |
1264 | ||
4efb68b1 | 1265 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 1266 | |
aaa75496 JB |
1267 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
1268 | struct objfile *); | |
1269 | ||
918dd910 JK |
1270 | static void dwarf2_find_base_address (struct die_info *die, |
1271 | struct dwarf2_cu *cu); | |
1272 | ||
c67a9c90 | 1273 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 1274 | |
72bf9492 DJ |
1275 | static void scan_partial_symbols (struct partial_die_info *, |
1276 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 1277 | int, struct dwarf2_cu *); |
c906108c | 1278 | |
72bf9492 DJ |
1279 | static void add_partial_symbol (struct partial_die_info *, |
1280 | struct dwarf2_cu *); | |
63d06c5c | 1281 | |
72bf9492 DJ |
1282 | static void add_partial_namespace (struct partial_die_info *pdi, |
1283 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 1284 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 1285 | |
5d7cb8df JK |
1286 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
1287 | CORE_ADDR *highpc, int need_pc, | |
1288 | struct dwarf2_cu *cu); | |
1289 | ||
72bf9492 DJ |
1290 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
1291 | struct dwarf2_cu *cu); | |
91c24f0a | 1292 | |
bc30ff58 JB |
1293 | static void add_partial_subprogram (struct partial_die_info *pdi, |
1294 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 1295 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 1296 | |
257e7a09 YQ |
1297 | static void dwarf2_read_symtab (struct partial_symtab *, |
1298 | struct objfile *); | |
c906108c | 1299 | |
a14ed312 | 1300 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 1301 | |
433df2d4 DE |
1302 | static struct abbrev_info *abbrev_table_lookup_abbrev |
1303 | (const struct abbrev_table *, unsigned int); | |
1304 | ||
1305 | static struct abbrev_table *abbrev_table_read_table | |
1306 | (struct dwarf2_section_info *, sect_offset); | |
1307 | ||
1308 | static void abbrev_table_free (struct abbrev_table *); | |
1309 | ||
f4dc4d17 DE |
1310 | static void abbrev_table_free_cleanup (void *); |
1311 | ||
dee91e82 DE |
1312 | static void dwarf2_read_abbrevs (struct dwarf2_cu *, |
1313 | struct dwarf2_section_info *); | |
c906108c | 1314 | |
f3dd6933 | 1315 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 1316 | |
6caca83c CC |
1317 | static unsigned int peek_abbrev_code (bfd *, gdb_byte *); |
1318 | ||
dee91e82 DE |
1319 | static struct partial_die_info *load_partial_dies |
1320 | (const struct die_reader_specs *, gdb_byte *, int); | |
72bf9492 | 1321 | |
dee91e82 DE |
1322 | static gdb_byte *read_partial_die (const struct die_reader_specs *, |
1323 | struct partial_die_info *, | |
1324 | struct abbrev_info *, | |
1325 | unsigned int, | |
1326 | gdb_byte *); | |
c906108c | 1327 | |
36586728 | 1328 | static struct partial_die_info *find_partial_die (sect_offset, int, |
10b3939b | 1329 | struct dwarf2_cu *); |
72bf9492 DJ |
1330 | |
1331 | static void fixup_partial_die (struct partial_die_info *, | |
1332 | struct dwarf2_cu *); | |
1333 | ||
dee91e82 DE |
1334 | static gdb_byte *read_attribute (const struct die_reader_specs *, |
1335 | struct attribute *, struct attr_abbrev *, | |
1336 | gdb_byte *); | |
a8329558 | 1337 | |
a1855c1d | 1338 | static unsigned int read_1_byte (bfd *, const gdb_byte *); |
c906108c | 1339 | |
a1855c1d | 1340 | static int read_1_signed_byte (bfd *, const gdb_byte *); |
c906108c | 1341 | |
a1855c1d | 1342 | static unsigned int read_2_bytes (bfd *, const gdb_byte *); |
c906108c | 1343 | |
a1855c1d | 1344 | static unsigned int read_4_bytes (bfd *, const gdb_byte *); |
c906108c | 1345 | |
a1855c1d | 1346 | static ULONGEST read_8_bytes (bfd *, const gdb_byte *); |
c906108c | 1347 | |
fe1b8b76 | 1348 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 1349 | unsigned int *); |
c906108c | 1350 | |
c764a876 DE |
1351 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
1352 | ||
1353 | static LONGEST read_checked_initial_length_and_offset | |
1354 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
1355 | unsigned int *, unsigned int *); | |
613e1657 | 1356 | |
fe1b8b76 | 1357 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
1358 | unsigned int *); |
1359 | ||
1360 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 1361 | |
f4dc4d17 DE |
1362 | static sect_offset read_abbrev_offset (struct dwarf2_section_info *, |
1363 | sect_offset); | |
1364 | ||
fe1b8b76 | 1365 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 1366 | |
9b1c24c8 | 1367 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1368 | |
fe1b8b76 JB |
1369 | static char *read_indirect_string (bfd *, gdb_byte *, |
1370 | const struct comp_unit_head *, | |
1371 | unsigned int *); | |
4bdf3d34 | 1372 | |
36586728 TT |
1373 | static char *read_indirect_string_from_dwz (struct dwz_file *, LONGEST); |
1374 | ||
12df843f | 1375 | static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1376 | |
12df843f | 1377 | static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1378 | |
3019eac3 DE |
1379 | static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, gdb_byte *, |
1380 | unsigned int *); | |
1381 | ||
1382 | static char *read_str_index (const struct die_reader_specs *reader, | |
1383 | struct dwarf2_cu *cu, ULONGEST str_index); | |
1384 | ||
e142c38c | 1385 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 1386 | |
e142c38c DJ |
1387 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
1388 | struct dwarf2_cu *); | |
c906108c | 1389 | |
348e048f | 1390 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
45e58e77 | 1391 | unsigned int); |
348e048f | 1392 | |
05cf31d1 JB |
1393 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
1394 | struct dwarf2_cu *cu); | |
1395 | ||
e142c38c | 1396 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 1397 | |
e142c38c | 1398 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 1399 | struct dwarf2_cu **); |
63d06c5c | 1400 | |
debd256d JB |
1401 | static void free_line_header (struct line_header *lh); |
1402 | ||
aaa75496 JB |
1403 | static void add_file_name (struct line_header *, char *, unsigned int, |
1404 | unsigned int, unsigned int); | |
1405 | ||
3019eac3 DE |
1406 | static struct line_header *dwarf_decode_line_header (unsigned int offset, |
1407 | struct dwarf2_cu *cu); | |
debd256d | 1408 | |
f3f5162e DE |
1409 | static void dwarf_decode_lines (struct line_header *, const char *, |
1410 | struct dwarf2_cu *, struct partial_symtab *, | |
1411 | int); | |
c906108c | 1412 | |
72b9f47f | 1413 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 1414 | |
f4dc4d17 | 1415 | static void dwarf2_start_symtab (struct dwarf2_cu *, |
15d034d0 | 1416 | const char *, const char *, CORE_ADDR); |
f4dc4d17 | 1417 | |
a14ed312 | 1418 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 1419 | struct dwarf2_cu *); |
c906108c | 1420 | |
34eaf542 TT |
1421 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
1422 | struct dwarf2_cu *, struct symbol *); | |
1423 | ||
a14ed312 | 1424 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1425 | struct dwarf2_cu *); |
c906108c | 1426 | |
98bfdba5 PA |
1427 | static void dwarf2_const_value_attr (struct attribute *attr, |
1428 | struct type *type, | |
1429 | const char *name, | |
1430 | struct obstack *obstack, | |
12df843f | 1431 | struct dwarf2_cu *cu, LONGEST *value, |
98bfdba5 PA |
1432 | gdb_byte **bytes, |
1433 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1434 | |
e7c27a73 | 1435 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1436 | |
b4ba55a1 JB |
1437 | static int need_gnat_info (struct dwarf2_cu *); |
1438 | ||
3e43a32a MS |
1439 | static struct type *die_descriptive_type (struct die_info *, |
1440 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1441 | |
1442 | static void set_descriptive_type (struct type *, struct die_info *, | |
1443 | struct dwarf2_cu *); | |
1444 | ||
e7c27a73 DJ |
1445 | static struct type *die_containing_type (struct die_info *, |
1446 | struct dwarf2_cu *); | |
c906108c | 1447 | |
673bfd45 DE |
1448 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1449 | struct dwarf2_cu *); | |
c906108c | 1450 | |
f792889a | 1451 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1452 | |
673bfd45 DE |
1453 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1454 | ||
0d5cff50 | 1455 | static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1456 | |
6e70227d | 1457 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1458 | const char *suffix, int physname, |
1459 | struct dwarf2_cu *cu); | |
63d06c5c | 1460 | |
e7c27a73 | 1461 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1462 | |
348e048f DE |
1463 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1464 | ||
e7c27a73 | 1465 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1466 | |
e7c27a73 | 1467 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1468 | |
96408a79 SA |
1469 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
1470 | ||
ff013f42 JK |
1471 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1472 | struct dwarf2_cu *, struct partial_symtab *); | |
1473 | ||
a14ed312 | 1474 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1475 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1476 | struct partial_symtab *); | |
c906108c | 1477 | |
fae299cd DC |
1478 | static void get_scope_pc_bounds (struct die_info *, |
1479 | CORE_ADDR *, CORE_ADDR *, | |
1480 | struct dwarf2_cu *); | |
1481 | ||
801e3a5b JB |
1482 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1483 | CORE_ADDR, struct dwarf2_cu *); | |
1484 | ||
a14ed312 | 1485 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1486 | struct dwarf2_cu *); |
c906108c | 1487 | |
a14ed312 | 1488 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1489 | struct type *, struct dwarf2_cu *); |
c906108c | 1490 | |
a14ed312 | 1491 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1492 | struct die_info *, struct type *, |
e7c27a73 | 1493 | struct dwarf2_cu *); |
c906108c | 1494 | |
a14ed312 | 1495 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1496 | struct type *, |
1497 | struct dwarf2_cu *); | |
c906108c | 1498 | |
134d01f1 | 1499 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1500 | |
e7c27a73 | 1501 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1502 | |
e7c27a73 | 1503 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1504 | |
5d7cb8df JK |
1505 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1506 | ||
27aa8d6a SW |
1507 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1508 | ||
f55ee35c JK |
1509 | static struct type *read_module_type (struct die_info *die, |
1510 | struct dwarf2_cu *cu); | |
1511 | ||
38d518c9 | 1512 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1513 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1514 | |
134d01f1 | 1515 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1516 | |
e7c27a73 | 1517 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1518 | |
6e70227d | 1519 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1520 | struct dwarf2_cu *); |
1521 | ||
dee91e82 | 1522 | static struct die_info *read_die_and_children (const struct die_reader_specs *, |
93311388 | 1523 | gdb_byte *info_ptr, |
fe1b8b76 | 1524 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1525 | struct die_info *parent); |
1526 | ||
dee91e82 | 1527 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *, |
93311388 | 1528 | gdb_byte *info_ptr, |
fe1b8b76 | 1529 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1530 | struct die_info *parent); |
1531 | ||
3019eac3 DE |
1532 | static gdb_byte *read_full_die_1 (const struct die_reader_specs *, |
1533 | struct die_info **, gdb_byte *, int *, int); | |
1534 | ||
dee91e82 DE |
1535 | static gdb_byte *read_full_die (const struct die_reader_specs *, |
1536 | struct die_info **, gdb_byte *, int *); | |
93311388 | 1537 | |
e7c27a73 | 1538 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1539 | |
15d034d0 TT |
1540 | static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu *, |
1541 | struct obstack *); | |
71c25dea | 1542 | |
15d034d0 | 1543 | static const char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1544 | |
15d034d0 | 1545 | static const char *dwarf2_full_name (const char *name, |
98bfdba5 PA |
1546 | struct die_info *die, |
1547 | struct dwarf2_cu *cu); | |
1548 | ||
e142c38c | 1549 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1550 | struct dwarf2_cu **); |
9219021c | 1551 | |
f39c6ffd | 1552 | static const char *dwarf_tag_name (unsigned int); |
c906108c | 1553 | |
f39c6ffd | 1554 | static const char *dwarf_attr_name (unsigned int); |
c906108c | 1555 | |
f39c6ffd | 1556 | static const char *dwarf_form_name (unsigned int); |
c906108c | 1557 | |
a14ed312 | 1558 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1559 | |
f39c6ffd | 1560 | static const char *dwarf_type_encoding_name (unsigned int); |
c906108c | 1561 | |
f9aca02d | 1562 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1563 | |
d97bc12b DE |
1564 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1565 | ||
1566 | static void dump_die_for_error (struct die_info *); | |
1567 | ||
1568 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1569 | struct die_info *); | |
c906108c | 1570 | |
d97bc12b | 1571 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1572 | |
51545339 | 1573 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1574 | struct dwarf2_cu *); |
c906108c | 1575 | |
93311388 DE |
1576 | static int is_ref_attr (struct attribute *); |
1577 | ||
b64f50a1 | 1578 | static sect_offset dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1579 | |
43bbcdc2 | 1580 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1581 | |
348e048f DE |
1582 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1583 | struct attribute *, | |
1584 | struct dwarf2_cu **); | |
1585 | ||
10b3939b DJ |
1586 | static struct die_info *follow_die_ref (struct die_info *, |
1587 | struct attribute *, | |
f2f0e013 | 1588 | struct dwarf2_cu **); |
c906108c | 1589 | |
348e048f DE |
1590 | static struct die_info *follow_die_sig (struct die_info *, |
1591 | struct attribute *, | |
1592 | struct dwarf2_cu **); | |
1593 | ||
6c83ed52 TT |
1594 | static struct signatured_type *lookup_signatured_type_at_offset |
1595 | (struct objfile *objfile, | |
b64f50a1 | 1596 | struct dwarf2_section_info *section, sect_offset offset); |
6c83ed52 | 1597 | |
e5fe5e75 | 1598 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
348e048f | 1599 | |
52dc124a | 1600 | static void read_signatured_type (struct signatured_type *); |
348e048f | 1601 | |
f4dc4d17 | 1602 | static struct type_unit_group *get_type_unit_group |
094b34ac | 1603 | (struct dwarf2_cu *, struct attribute *); |
f4dc4d17 DE |
1604 | |
1605 | static void build_type_unit_groups (die_reader_func_ftype *, void *); | |
1606 | ||
c906108c SS |
1607 | /* memory allocation interface */ |
1608 | ||
7b5a2f43 | 1609 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1610 | |
b60c80d6 | 1611 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1612 | |
09262596 | 1613 | static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int, |
15d034d0 | 1614 | const char *, int); |
2e276125 | 1615 | |
8e19ed76 PS |
1616 | static int attr_form_is_block (struct attribute *); |
1617 | ||
3690dd37 JB |
1618 | static int attr_form_is_section_offset (struct attribute *); |
1619 | ||
1620 | static int attr_form_is_constant (struct attribute *); | |
1621 | ||
8cf6f0b1 TT |
1622 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1623 | struct dwarf2_loclist_baton *baton, | |
1624 | struct attribute *attr); | |
1625 | ||
93e7bd98 DJ |
1626 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1627 | struct symbol *sym, | |
1628 | struct dwarf2_cu *cu); | |
4c2df51b | 1629 | |
dee91e82 DE |
1630 | static gdb_byte *skip_one_die (const struct die_reader_specs *reader, |
1631 | gdb_byte *info_ptr, | |
1632 | struct abbrev_info *abbrev); | |
4bb7a0a7 | 1633 | |
72bf9492 DJ |
1634 | static void free_stack_comp_unit (void *); |
1635 | ||
72bf9492 DJ |
1636 | static hashval_t partial_die_hash (const void *item); |
1637 | ||
1638 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1639 | ||
ae038cb0 | 1640 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
36586728 | 1641 | (sect_offset offset, unsigned int offset_in_dwz, struct objfile *objfile); |
ae038cb0 | 1642 | |
9816fde3 | 1643 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
23745b47 | 1644 | struct dwarf2_per_cu_data *per_cu); |
9816fde3 JK |
1645 | |
1646 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
95554aad TT |
1647 | struct die_info *comp_unit_die, |
1648 | enum language pretend_language); | |
93311388 | 1649 | |
68dc6402 | 1650 | static void free_heap_comp_unit (void *); |
ae038cb0 DJ |
1651 | |
1652 | static void free_cached_comp_units (void *); | |
1653 | ||
1654 | static void age_cached_comp_units (void); | |
1655 | ||
dee91e82 | 1656 | static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *); |
ae038cb0 | 1657 | |
f792889a DJ |
1658 | static struct type *set_die_type (struct die_info *, struct type *, |
1659 | struct dwarf2_cu *); | |
1c379e20 | 1660 | |
ae038cb0 DJ |
1661 | static void create_all_comp_units (struct objfile *); |
1662 | ||
0e50663e | 1663 | static int create_all_type_units (struct objfile *); |
1fd400ff | 1664 | |
95554aad TT |
1665 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1666 | enum language); | |
10b3939b | 1667 | |
95554aad TT |
1668 | static void process_full_comp_unit (struct dwarf2_per_cu_data *, |
1669 | enum language); | |
10b3939b | 1670 | |
f4dc4d17 DE |
1671 | static void process_full_type_unit (struct dwarf2_per_cu_data *, |
1672 | enum language); | |
1673 | ||
10b3939b DJ |
1674 | static void dwarf2_add_dependence (struct dwarf2_cu *, |
1675 | struct dwarf2_per_cu_data *); | |
1676 | ||
ae038cb0 DJ |
1677 | static void dwarf2_mark (struct dwarf2_cu *); |
1678 | ||
1679 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1680 | ||
b64f50a1 | 1681 | static struct type *get_die_type_at_offset (sect_offset, |
673bfd45 DE |
1682 | struct dwarf2_per_cu_data *per_cu); |
1683 | ||
f792889a | 1684 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1685 | |
9291a0cd TT |
1686 | static void dwarf2_release_queue (void *dummy); |
1687 | ||
95554aad TT |
1688 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, |
1689 | enum language pretend_language); | |
1690 | ||
1691 | static int maybe_queue_comp_unit (struct dwarf2_cu *this_cu, | |
1692 | struct dwarf2_per_cu_data *per_cu, | |
1693 | enum language pretend_language); | |
9291a0cd | 1694 | |
a0f42c21 | 1695 | static void process_queue (void); |
9291a0cd TT |
1696 | |
1697 | static void find_file_and_directory (struct die_info *die, | |
1698 | struct dwarf2_cu *cu, | |
15d034d0 | 1699 | const char **name, const char **comp_dir); |
9291a0cd TT |
1700 | |
1701 | static char *file_full_name (int file, struct line_header *lh, | |
1702 | const char *comp_dir); | |
1703 | ||
36586728 TT |
1704 | static gdb_byte *read_and_check_comp_unit_head |
1705 | (struct comp_unit_head *header, | |
1706 | struct dwarf2_section_info *section, | |
1707 | struct dwarf2_section_info *abbrev_section, gdb_byte *info_ptr, | |
1708 | int is_debug_types_section); | |
1709 | ||
fd820528 | 1710 | static void init_cutu_and_read_dies |
f4dc4d17 DE |
1711 | (struct dwarf2_per_cu_data *this_cu, struct abbrev_table *abbrev_table, |
1712 | int use_existing_cu, int keep, | |
3019eac3 DE |
1713 | die_reader_func_ftype *die_reader_func, void *data); |
1714 | ||
dee91e82 DE |
1715 | static void init_cutu_and_read_dies_simple |
1716 | (struct dwarf2_per_cu_data *this_cu, | |
1717 | die_reader_func_ftype *die_reader_func, void *data); | |
9291a0cd | 1718 | |
673bfd45 | 1719 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1720 | |
3019eac3 DE |
1721 | static htab_t allocate_dwo_unit_table (struct objfile *objfile); |
1722 | ||
1723 | static struct dwo_unit *lookup_dwo_comp_unit | |
a1855c1d | 1724 | (struct dwarf2_per_cu_data *, const char *, const char *, ULONGEST); |
3019eac3 DE |
1725 | |
1726 | static struct dwo_unit *lookup_dwo_type_unit | |
a1855c1d | 1727 | (struct signatured_type *, const char *, const char *); |
3019eac3 DE |
1728 | |
1729 | static void free_dwo_file_cleanup (void *); | |
1730 | ||
95554aad TT |
1731 | static void process_cu_includes (void); |
1732 | ||
1b80a9fa JK |
1733 | static void check_producer (struct dwarf2_cu *cu); |
1734 | ||
9291a0cd TT |
1735 | #if WORDS_BIGENDIAN |
1736 | ||
1737 | /* Convert VALUE between big- and little-endian. */ | |
1738 | static offset_type | |
1739 | byte_swap (offset_type value) | |
1740 | { | |
1741 | offset_type result; | |
1742 | ||
1743 | result = (value & 0xff) << 24; | |
1744 | result |= (value & 0xff00) << 8; | |
1745 | result |= (value & 0xff0000) >> 8; | |
1746 | result |= (value & 0xff000000) >> 24; | |
1747 | return result; | |
1748 | } | |
1749 | ||
1750 | #define MAYBE_SWAP(V) byte_swap (V) | |
1751 | ||
1752 | #else | |
1753 | #define MAYBE_SWAP(V) (V) | |
1754 | #endif /* WORDS_BIGENDIAN */ | |
1755 | ||
1756 | /* The suffix for an index file. */ | |
1757 | #define INDEX_SUFFIX ".gdb-index" | |
1758 | ||
15d034d0 | 1759 | static const char *dwarf2_physname (const char *name, struct die_info *die, |
3da10d80 KS |
1760 | struct dwarf2_cu *cu); |
1761 | ||
c906108c | 1762 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
1763 | information and return true if we have enough to do something. |
1764 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
1765 | ELF names are used. */ | |
c906108c SS |
1766 | |
1767 | int | |
251d32d9 TG |
1768 | dwarf2_has_info (struct objfile *objfile, |
1769 | const struct dwarf2_debug_sections *names) | |
c906108c | 1770 | { |
be391dca TT |
1771 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1772 | if (!dwarf2_per_objfile) | |
1773 | { | |
1774 | /* Initialize per-objfile state. */ | |
1775 | struct dwarf2_per_objfile *data | |
1776 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1777 | |
be391dca TT |
1778 | memset (data, 0, sizeof (*data)); |
1779 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1780 | dwarf2_per_objfile = data; | |
6502dd73 | 1781 | |
251d32d9 TG |
1782 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
1783 | (void *) names); | |
be391dca TT |
1784 | dwarf2_per_objfile->objfile = objfile; |
1785 | } | |
1786 | return (dwarf2_per_objfile->info.asection != NULL | |
1787 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1788 | } |
1789 | ||
251d32d9 TG |
1790 | /* When loading sections, we look either for uncompressed section or for |
1791 | compressed section names. */ | |
233a11ab CS |
1792 | |
1793 | static int | |
251d32d9 TG |
1794 | section_is_p (const char *section_name, |
1795 | const struct dwarf2_section_names *names) | |
233a11ab | 1796 | { |
251d32d9 TG |
1797 | if (names->normal != NULL |
1798 | && strcmp (section_name, names->normal) == 0) | |
1799 | return 1; | |
1800 | if (names->compressed != NULL | |
1801 | && strcmp (section_name, names->compressed) == 0) | |
1802 | return 1; | |
1803 | return 0; | |
233a11ab CS |
1804 | } |
1805 | ||
c906108c SS |
1806 | /* This function is mapped across the sections and remembers the |
1807 | offset and size of each of the debugging sections we are interested | |
1808 | in. */ | |
1809 | ||
1810 | static void | |
251d32d9 | 1811 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
c906108c | 1812 | { |
251d32d9 | 1813 | const struct dwarf2_debug_sections *names; |
dc7650b8 | 1814 | flagword aflag = bfd_get_section_flags (abfd, sectp); |
251d32d9 TG |
1815 | |
1816 | if (vnames == NULL) | |
1817 | names = &dwarf2_elf_names; | |
1818 | else | |
1819 | names = (const struct dwarf2_debug_sections *) vnames; | |
1820 | ||
dc7650b8 JK |
1821 | if ((aflag & SEC_HAS_CONTENTS) == 0) |
1822 | { | |
1823 | } | |
1824 | else if (section_is_p (sectp->name, &names->info)) | |
c906108c | 1825 | { |
dce234bc PP |
1826 | dwarf2_per_objfile->info.asection = sectp; |
1827 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1828 | } |
251d32d9 | 1829 | else if (section_is_p (sectp->name, &names->abbrev)) |
c906108c | 1830 | { |
dce234bc PP |
1831 | dwarf2_per_objfile->abbrev.asection = sectp; |
1832 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1833 | } |
251d32d9 | 1834 | else if (section_is_p (sectp->name, &names->line)) |
c906108c | 1835 | { |
dce234bc PP |
1836 | dwarf2_per_objfile->line.asection = sectp; |
1837 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1838 | } |
251d32d9 | 1839 | else if (section_is_p (sectp->name, &names->loc)) |
c906108c | 1840 | { |
dce234bc PP |
1841 | dwarf2_per_objfile->loc.asection = sectp; |
1842 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1843 | } |
251d32d9 | 1844 | else if (section_is_p (sectp->name, &names->macinfo)) |
c906108c | 1845 | { |
dce234bc PP |
1846 | dwarf2_per_objfile->macinfo.asection = sectp; |
1847 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1848 | } |
cf2c3c16 TT |
1849 | else if (section_is_p (sectp->name, &names->macro)) |
1850 | { | |
1851 | dwarf2_per_objfile->macro.asection = sectp; | |
1852 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); | |
1853 | } | |
251d32d9 | 1854 | else if (section_is_p (sectp->name, &names->str)) |
c906108c | 1855 | { |
dce234bc PP |
1856 | dwarf2_per_objfile->str.asection = sectp; |
1857 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1858 | } |
3019eac3 DE |
1859 | else if (section_is_p (sectp->name, &names->addr)) |
1860 | { | |
1861 | dwarf2_per_objfile->addr.asection = sectp; | |
1862 | dwarf2_per_objfile->addr.size = bfd_get_section_size (sectp); | |
1863 | } | |
251d32d9 | 1864 | else if (section_is_p (sectp->name, &names->frame)) |
b6af0555 | 1865 | { |
dce234bc PP |
1866 | dwarf2_per_objfile->frame.asection = sectp; |
1867 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1868 | } |
251d32d9 | 1869 | else if (section_is_p (sectp->name, &names->eh_frame)) |
b6af0555 | 1870 | { |
dc7650b8 JK |
1871 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1872 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1873 | } |
251d32d9 | 1874 | else if (section_is_p (sectp->name, &names->ranges)) |
af34e669 | 1875 | { |
dce234bc PP |
1876 | dwarf2_per_objfile->ranges.asection = sectp; |
1877 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1878 | } |
251d32d9 | 1879 | else if (section_is_p (sectp->name, &names->types)) |
348e048f | 1880 | { |
8b70b953 TT |
1881 | struct dwarf2_section_info type_section; |
1882 | ||
1883 | memset (&type_section, 0, sizeof (type_section)); | |
1884 | type_section.asection = sectp; | |
1885 | type_section.size = bfd_get_section_size (sectp); | |
1886 | ||
1887 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
1888 | &type_section); | |
348e048f | 1889 | } |
251d32d9 | 1890 | else if (section_is_p (sectp->name, &names->gdb_index)) |
9291a0cd TT |
1891 | { |
1892 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1893 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1894 | } | |
dce234bc | 1895 | |
72dca2f5 FR |
1896 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1897 | && bfd_section_vma (abfd, sectp) == 0) | |
1898 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1899 | } |
1900 | ||
fceca515 DE |
1901 | /* A helper function that decides whether a section is empty, |
1902 | or not present. */ | |
9e0ac564 TT |
1903 | |
1904 | static int | |
1905 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1906 | { | |
1907 | return info->asection == NULL || info->size == 0; | |
1908 | } | |
1909 | ||
3019eac3 DE |
1910 | /* Read the contents of the section INFO. |
1911 | OBJFILE is the main object file, but not necessarily the file where | |
1912 | the section comes from. E.g., for DWO files INFO->asection->owner | |
1913 | is the bfd of the DWO file. | |
dce234bc | 1914 | If the section is compressed, uncompress it before returning. */ |
c906108c | 1915 | |
dce234bc PP |
1916 | static void |
1917 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1918 | { |
dce234bc | 1919 | asection *sectp = info->asection; |
3019eac3 | 1920 | bfd *abfd; |
dce234bc PP |
1921 | gdb_byte *buf, *retbuf; |
1922 | unsigned char header[4]; | |
c906108c | 1923 | |
be391dca TT |
1924 | if (info->readin) |
1925 | return; | |
dce234bc | 1926 | info->buffer = NULL; |
be391dca | 1927 | info->readin = 1; |
188dd5d6 | 1928 | |
9e0ac564 | 1929 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1930 | return; |
c906108c | 1931 | |
3019eac3 DE |
1932 | abfd = sectp->owner; |
1933 | ||
4bf44c1c TT |
1934 | /* If the section has relocations, we must read it ourselves. |
1935 | Otherwise we attach it to the BFD. */ | |
1936 | if ((sectp->flags & SEC_RELOC) == 0) | |
dce234bc | 1937 | { |
4bf44c1c | 1938 | const gdb_byte *bytes = gdb_bfd_map_section (sectp, &info->size); |
dce234bc | 1939 | |
4bf44c1c TT |
1940 | /* We have to cast away const here for historical reasons. |
1941 | Fixing dwarf2read to be const-correct would be quite nice. */ | |
1942 | info->buffer = (gdb_byte *) bytes; | |
1943 | return; | |
dce234bc | 1944 | } |
dce234bc | 1945 | |
4bf44c1c TT |
1946 | buf = obstack_alloc (&objfile->objfile_obstack, info->size); |
1947 | info->buffer = buf; | |
dce234bc PP |
1948 | |
1949 | /* When debugging .o files, we may need to apply relocations; see | |
1950 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1951 | We never compress sections in .o files, so we only need to | |
1952 | try this when the section is not compressed. */ | |
ac8035ab | 1953 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1954 | if (retbuf != NULL) |
1955 | { | |
1956 | info->buffer = retbuf; | |
1957 | return; | |
1958 | } | |
1959 | ||
1960 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1961 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1962 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1963 | bfd_get_filename (abfd)); | |
1964 | } | |
1965 | ||
9e0ac564 TT |
1966 | /* A helper function that returns the size of a section in a safe way. |
1967 | If you are positive that the section has been read before using the | |
1968 | size, then it is safe to refer to the dwarf2_section_info object's | |
1969 | "size" field directly. In other cases, you must call this | |
1970 | function, because for compressed sections the size field is not set | |
1971 | correctly until the section has been read. */ | |
1972 | ||
1973 | static bfd_size_type | |
1974 | dwarf2_section_size (struct objfile *objfile, | |
1975 | struct dwarf2_section_info *info) | |
1976 | { | |
1977 | if (!info->readin) | |
1978 | dwarf2_read_section (objfile, info); | |
1979 | return info->size; | |
1980 | } | |
1981 | ||
dce234bc | 1982 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1983 | SECTION_NAME. */ |
af34e669 | 1984 | |
dce234bc | 1985 | void |
3017a003 TG |
1986 | dwarf2_get_section_info (struct objfile *objfile, |
1987 | enum dwarf2_section_enum sect, | |
dce234bc PP |
1988 | asection **sectp, gdb_byte **bufp, |
1989 | bfd_size_type *sizep) | |
1990 | { | |
1991 | struct dwarf2_per_objfile *data | |
1992 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1993 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1994 | |
1995 | /* We may see an objfile without any DWARF, in which case we just | |
1996 | return nothing. */ | |
1997 | if (data == NULL) | |
1998 | { | |
1999 | *sectp = NULL; | |
2000 | *bufp = NULL; | |
2001 | *sizep = 0; | |
2002 | return; | |
2003 | } | |
3017a003 TG |
2004 | switch (sect) |
2005 | { | |
2006 | case DWARF2_DEBUG_FRAME: | |
2007 | info = &data->frame; | |
2008 | break; | |
2009 | case DWARF2_EH_FRAME: | |
2010 | info = &data->eh_frame; | |
2011 | break; | |
2012 | default: | |
2013 | gdb_assert_not_reached ("unexpected section"); | |
2014 | } | |
dce234bc | 2015 | |
9e0ac564 | 2016 | dwarf2_read_section (objfile, info); |
dce234bc PP |
2017 | |
2018 | *sectp = info->asection; | |
2019 | *bufp = info->buffer; | |
2020 | *sizep = info->size; | |
2021 | } | |
2022 | ||
36586728 TT |
2023 | /* A helper function to find the sections for a .dwz file. */ |
2024 | ||
2025 | static void | |
2026 | locate_dwz_sections (bfd *abfd, asection *sectp, void *arg) | |
2027 | { | |
2028 | struct dwz_file *dwz_file = arg; | |
2029 | ||
2030 | /* Note that we only support the standard ELF names, because .dwz | |
2031 | is ELF-only (at the time of writing). */ | |
2032 | if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev)) | |
2033 | { | |
2034 | dwz_file->abbrev.asection = sectp; | |
2035 | dwz_file->abbrev.size = bfd_get_section_size (sectp); | |
2036 | } | |
2037 | else if (section_is_p (sectp->name, &dwarf2_elf_names.info)) | |
2038 | { | |
2039 | dwz_file->info.asection = sectp; | |
2040 | dwz_file->info.size = bfd_get_section_size (sectp); | |
2041 | } | |
2042 | else if (section_is_p (sectp->name, &dwarf2_elf_names.str)) | |
2043 | { | |
2044 | dwz_file->str.asection = sectp; | |
2045 | dwz_file->str.size = bfd_get_section_size (sectp); | |
2046 | } | |
2047 | else if (section_is_p (sectp->name, &dwarf2_elf_names.line)) | |
2048 | { | |
2049 | dwz_file->line.asection = sectp; | |
2050 | dwz_file->line.size = bfd_get_section_size (sectp); | |
2051 | } | |
2052 | else if (section_is_p (sectp->name, &dwarf2_elf_names.macro)) | |
2053 | { | |
2054 | dwz_file->macro.asection = sectp; | |
2055 | dwz_file->macro.size = bfd_get_section_size (sectp); | |
2056 | } | |
2ec9a5e0 TT |
2057 | else if (section_is_p (sectp->name, &dwarf2_elf_names.gdb_index)) |
2058 | { | |
2059 | dwz_file->gdb_index.asection = sectp; | |
2060 | dwz_file->gdb_index.size = bfd_get_section_size (sectp); | |
2061 | } | |
36586728 TT |
2062 | } |
2063 | ||
2064 | /* Open the separate '.dwz' debug file, if needed. Error if the file | |
2065 | cannot be found. */ | |
2066 | ||
2067 | static struct dwz_file * | |
2068 | dwarf2_get_dwz_file (void) | |
2069 | { | |
2070 | bfd *abfd, *dwz_bfd; | |
2071 | asection *section; | |
2072 | gdb_byte *data; | |
2073 | struct cleanup *cleanup; | |
2074 | const char *filename; | |
2075 | struct dwz_file *result; | |
2076 | ||
2077 | if (dwarf2_per_objfile->dwz_file != NULL) | |
2078 | return dwarf2_per_objfile->dwz_file; | |
2079 | ||
2080 | abfd = dwarf2_per_objfile->objfile->obfd; | |
2081 | section = bfd_get_section_by_name (abfd, ".gnu_debugaltlink"); | |
2082 | if (section == NULL) | |
2083 | error (_("could not find '.gnu_debugaltlink' section")); | |
2084 | if (!bfd_malloc_and_get_section (abfd, section, &data)) | |
2085 | error (_("could not read '.gnu_debugaltlink' section: %s"), | |
2086 | bfd_errmsg (bfd_get_error ())); | |
2087 | cleanup = make_cleanup (xfree, data); | |
2088 | ||
2089 | filename = data; | |
2090 | if (!IS_ABSOLUTE_PATH (filename)) | |
2091 | { | |
2092 | char *abs = gdb_realpath (dwarf2_per_objfile->objfile->name); | |
2093 | char *rel; | |
2094 | ||
2095 | make_cleanup (xfree, abs); | |
2096 | abs = ldirname (abs); | |
2097 | make_cleanup (xfree, abs); | |
2098 | ||
2099 | rel = concat (abs, SLASH_STRING, filename, (char *) NULL); | |
2100 | make_cleanup (xfree, rel); | |
2101 | filename = rel; | |
2102 | } | |
2103 | ||
2104 | /* The format is just a NUL-terminated file name, followed by the | |
2105 | build-id. For now, though, we ignore the build-id. */ | |
2106 | dwz_bfd = gdb_bfd_open (filename, gnutarget, -1); | |
2107 | if (dwz_bfd == NULL) | |
2108 | error (_("could not read '%s': %s"), filename, | |
2109 | bfd_errmsg (bfd_get_error ())); | |
2110 | ||
2111 | if (!bfd_check_format (dwz_bfd, bfd_object)) | |
2112 | { | |
2113 | gdb_bfd_unref (dwz_bfd); | |
2114 | error (_("file '%s' was not usable: %s"), filename, | |
2115 | bfd_errmsg (bfd_get_error ())); | |
2116 | } | |
2117 | ||
2118 | result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack, | |
2119 | struct dwz_file); | |
2120 | result->dwz_bfd = dwz_bfd; | |
2121 | ||
2122 | bfd_map_over_sections (dwz_bfd, locate_dwz_sections, result); | |
2123 | ||
2124 | do_cleanups (cleanup); | |
2125 | ||
8d2cc612 | 2126 | dwarf2_per_objfile->dwz_file = result; |
36586728 TT |
2127 | return result; |
2128 | } | |
9291a0cd | 2129 | \f |
7b9f3c50 DE |
2130 | /* DWARF quick_symbols_functions support. */ |
2131 | ||
2132 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
2133 | unique line tables, so we maintain a separate table of all .debug_line | |
2134 | derived entries to support the sharing. | |
2135 | All the quick functions need is the list of file names. We discard the | |
2136 | line_header when we're done and don't need to record it here. */ | |
2137 | struct quick_file_names | |
2138 | { | |
094b34ac DE |
2139 | /* The data used to construct the hash key. */ |
2140 | struct stmt_list_hash hash; | |
7b9f3c50 DE |
2141 | |
2142 | /* The number of entries in file_names, real_names. */ | |
2143 | unsigned int num_file_names; | |
2144 | ||
2145 | /* The file names from the line table, after being run through | |
2146 | file_full_name. */ | |
2147 | const char **file_names; | |
2148 | ||
2149 | /* The file names from the line table after being run through | |
2150 | gdb_realpath. These are computed lazily. */ | |
2151 | const char **real_names; | |
2152 | }; | |
2153 | ||
2154 | /* When using the index (and thus not using psymtabs), each CU has an | |
2155 | object of this type. This is used to hold information needed by | |
2156 | the various "quick" methods. */ | |
2157 | struct dwarf2_per_cu_quick_data | |
2158 | { | |
2159 | /* The file table. This can be NULL if there was no file table | |
2160 | or it's currently not read in. | |
2161 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
2162 | struct quick_file_names *file_names; | |
2163 | ||
2164 | /* The corresponding symbol table. This is NULL if symbols for this | |
2165 | CU have not yet been read. */ | |
2166 | struct symtab *symtab; | |
2167 | ||
2168 | /* A temporary mark bit used when iterating over all CUs in | |
2169 | expand_symtabs_matching. */ | |
2170 | unsigned int mark : 1; | |
2171 | ||
2172 | /* True if we've tried to read the file table and found there isn't one. | |
2173 | There will be no point in trying to read it again next time. */ | |
2174 | unsigned int no_file_data : 1; | |
2175 | }; | |
2176 | ||
094b34ac DE |
2177 | /* Utility hash function for a stmt_list_hash. */ |
2178 | ||
2179 | static hashval_t | |
2180 | hash_stmt_list_entry (const struct stmt_list_hash *stmt_list_hash) | |
2181 | { | |
2182 | hashval_t v = 0; | |
2183 | ||
2184 | if (stmt_list_hash->dwo_unit != NULL) | |
2185 | v += (uintptr_t) stmt_list_hash->dwo_unit->dwo_file; | |
2186 | v += stmt_list_hash->line_offset.sect_off; | |
2187 | return v; | |
2188 | } | |
2189 | ||
2190 | /* Utility equality function for a stmt_list_hash. */ | |
2191 | ||
2192 | static int | |
2193 | eq_stmt_list_entry (const struct stmt_list_hash *lhs, | |
2194 | const struct stmt_list_hash *rhs) | |
2195 | { | |
2196 | if ((lhs->dwo_unit != NULL) != (rhs->dwo_unit != NULL)) | |
2197 | return 0; | |
2198 | if (lhs->dwo_unit != NULL | |
2199 | && lhs->dwo_unit->dwo_file != rhs->dwo_unit->dwo_file) | |
2200 | return 0; | |
2201 | ||
2202 | return lhs->line_offset.sect_off == rhs->line_offset.sect_off; | |
2203 | } | |
2204 | ||
7b9f3c50 DE |
2205 | /* Hash function for a quick_file_names. */ |
2206 | ||
2207 | static hashval_t | |
2208 | hash_file_name_entry (const void *e) | |
2209 | { | |
2210 | const struct quick_file_names *file_data = e; | |
2211 | ||
094b34ac | 2212 | return hash_stmt_list_entry (&file_data->hash); |
7b9f3c50 DE |
2213 | } |
2214 | ||
2215 | /* Equality function for a quick_file_names. */ | |
2216 | ||
2217 | static int | |
2218 | eq_file_name_entry (const void *a, const void *b) | |
2219 | { | |
2220 | const struct quick_file_names *ea = a; | |
2221 | const struct quick_file_names *eb = b; | |
2222 | ||
094b34ac | 2223 | return eq_stmt_list_entry (&ea->hash, &eb->hash); |
7b9f3c50 DE |
2224 | } |
2225 | ||
2226 | /* Delete function for a quick_file_names. */ | |
2227 | ||
2228 | static void | |
2229 | delete_file_name_entry (void *e) | |
2230 | { | |
2231 | struct quick_file_names *file_data = e; | |
2232 | int i; | |
2233 | ||
2234 | for (i = 0; i < file_data->num_file_names; ++i) | |
2235 | { | |
2236 | xfree ((void*) file_data->file_names[i]); | |
2237 | if (file_data->real_names) | |
2238 | xfree ((void*) file_data->real_names[i]); | |
2239 | } | |
2240 | ||
2241 | /* The space for the struct itself lives on objfile_obstack, | |
2242 | so we don't free it here. */ | |
2243 | } | |
2244 | ||
2245 | /* Create a quick_file_names hash table. */ | |
2246 | ||
2247 | static htab_t | |
2248 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
2249 | { | |
2250 | return htab_create_alloc (nr_initial_entries, | |
2251 | hash_file_name_entry, eq_file_name_entry, | |
2252 | delete_file_name_entry, xcalloc, xfree); | |
2253 | } | |
9291a0cd | 2254 | |
918dd910 JK |
2255 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
2256 | have to be created afterwards. You should call age_cached_comp_units after | |
2257 | processing PER_CU->CU. dw2_setup must have been already called. */ | |
2258 | ||
2259 | static void | |
2260 | load_cu (struct dwarf2_per_cu_data *per_cu) | |
2261 | { | |
3019eac3 | 2262 | if (per_cu->is_debug_types) |
e5fe5e75 | 2263 | load_full_type_unit (per_cu); |
918dd910 | 2264 | else |
95554aad | 2265 | load_full_comp_unit (per_cu, language_minimal); |
918dd910 | 2266 | |
918dd910 | 2267 | gdb_assert (per_cu->cu != NULL); |
2dc860c0 DE |
2268 | |
2269 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); | |
918dd910 JK |
2270 | } |
2271 | ||
a0f42c21 | 2272 | /* Read in the symbols for PER_CU. */ |
2fdf6df6 | 2273 | |
9291a0cd | 2274 | static void |
a0f42c21 | 2275 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
2276 | { |
2277 | struct cleanup *back_to; | |
2278 | ||
f4dc4d17 DE |
2279 | /* Skip type_unit_groups, reading the type units they contain |
2280 | is handled elsewhere. */ | |
2281 | if (IS_TYPE_UNIT_GROUP (per_cu)) | |
2282 | return; | |
2283 | ||
9291a0cd TT |
2284 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
2285 | ||
95554aad TT |
2286 | if (dwarf2_per_objfile->using_index |
2287 | ? per_cu->v.quick->symtab == NULL | |
2288 | : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin)) | |
2289 | { | |
2290 | queue_comp_unit (per_cu, language_minimal); | |
2291 | load_cu (per_cu); | |
2292 | } | |
9291a0cd | 2293 | |
a0f42c21 | 2294 | process_queue (); |
9291a0cd TT |
2295 | |
2296 | /* Age the cache, releasing compilation units that have not | |
2297 | been used recently. */ | |
2298 | age_cached_comp_units (); | |
2299 | ||
2300 | do_cleanups (back_to); | |
2301 | } | |
2302 | ||
2303 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
2304 | the objfile from which this CU came. Returns the resulting symbol | |
2305 | table. */ | |
2fdf6df6 | 2306 | |
9291a0cd | 2307 | static struct symtab * |
a0f42c21 | 2308 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd | 2309 | { |
95554aad | 2310 | gdb_assert (dwarf2_per_objfile->using_index); |
9291a0cd TT |
2311 | if (!per_cu->v.quick->symtab) |
2312 | { | |
2313 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
2314 | increment_reading_symtab (); | |
a0f42c21 | 2315 | dw2_do_instantiate_symtab (per_cu); |
95554aad | 2316 | process_cu_includes (); |
9291a0cd TT |
2317 | do_cleanups (back_to); |
2318 | } | |
2319 | return per_cu->v.quick->symtab; | |
2320 | } | |
2321 | ||
f4dc4d17 DE |
2322 | /* Return the CU given its index. |
2323 | ||
2324 | This is intended for loops like: | |
2325 | ||
2326 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2327 | + dwarf2_per_objfile->n_type_units); ++i) | |
2328 | { | |
2329 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2330 | ||
2331 | ...; | |
2332 | } | |
2333 | */ | |
2fdf6df6 | 2334 | |
1fd400ff TT |
2335 | static struct dwarf2_per_cu_data * |
2336 | dw2_get_cu (int index) | |
2337 | { | |
2338 | if (index >= dwarf2_per_objfile->n_comp_units) | |
2339 | { | |
f4dc4d17 | 2340 | index -= dwarf2_per_objfile->n_comp_units; |
094b34ac DE |
2341 | gdb_assert (index < dwarf2_per_objfile->n_type_units); |
2342 | return &dwarf2_per_objfile->all_type_units[index]->per_cu; | |
f4dc4d17 DE |
2343 | } |
2344 | ||
2345 | return dwarf2_per_objfile->all_comp_units[index]; | |
2346 | } | |
2347 | ||
2348 | /* Return the primary CU given its index. | |
2349 | The difference between this function and dw2_get_cu is in the handling | |
2350 | of type units (TUs). Here we return the type_unit_group object. | |
2351 | ||
2352 | This is intended for loops like: | |
2353 | ||
2354 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2355 | + dwarf2_per_objfile->n_type_unit_groups); ++i) | |
2356 | { | |
2357 | struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i); | |
2358 | ||
2359 | ...; | |
2360 | } | |
2361 | */ | |
2362 | ||
2363 | static struct dwarf2_per_cu_data * | |
2364 | dw2_get_primary_cu (int index) | |
2365 | { | |
2366 | if (index >= dwarf2_per_objfile->n_comp_units) | |
2367 | { | |
1fd400ff | 2368 | index -= dwarf2_per_objfile->n_comp_units; |
094b34ac DE |
2369 | gdb_assert (index < dwarf2_per_objfile->n_type_unit_groups); |
2370 | return &dwarf2_per_objfile->all_type_unit_groups[index]->per_cu; | |
1fd400ff | 2371 | } |
f4dc4d17 | 2372 | |
1fd400ff TT |
2373 | return dwarf2_per_objfile->all_comp_units[index]; |
2374 | } | |
2375 | ||
2ec9a5e0 TT |
2376 | /* A helper for create_cus_from_index that handles a given list of |
2377 | CUs. */ | |
2fdf6df6 | 2378 | |
74a0d9f6 | 2379 | static void |
2ec9a5e0 TT |
2380 | create_cus_from_index_list (struct objfile *objfile, |
2381 | const gdb_byte *cu_list, offset_type n_elements, | |
2382 | struct dwarf2_section_info *section, | |
2383 | int is_dwz, | |
2384 | int base_offset) | |
9291a0cd TT |
2385 | { |
2386 | offset_type i; | |
9291a0cd | 2387 | |
2ec9a5e0 | 2388 | for (i = 0; i < n_elements; i += 2) |
9291a0cd TT |
2389 | { |
2390 | struct dwarf2_per_cu_data *the_cu; | |
2391 | ULONGEST offset, length; | |
2392 | ||
74a0d9f6 JK |
2393 | gdb_static_assert (sizeof (ULONGEST) >= 8); |
2394 | offset = extract_unsigned_integer (cu_list, 8, BFD_ENDIAN_LITTLE); | |
2395 | length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE); | |
9291a0cd TT |
2396 | cu_list += 2 * 8; |
2397 | ||
2398 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
2399 | struct dwarf2_per_cu_data); | |
b64f50a1 | 2400 | the_cu->offset.sect_off = offset; |
9291a0cd TT |
2401 | the_cu->length = length; |
2402 | the_cu->objfile = objfile; | |
2ec9a5e0 | 2403 | the_cu->info_or_types_section = section; |
9291a0cd TT |
2404 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2405 | struct dwarf2_per_cu_quick_data); | |
2ec9a5e0 TT |
2406 | the_cu->is_dwz = is_dwz; |
2407 | dwarf2_per_objfile->all_comp_units[base_offset + i / 2] = the_cu; | |
9291a0cd | 2408 | } |
9291a0cd TT |
2409 | } |
2410 | ||
2ec9a5e0 | 2411 | /* Read the CU list from the mapped index, and use it to create all |
74a0d9f6 | 2412 | the CU objects for this objfile. */ |
2ec9a5e0 | 2413 | |
74a0d9f6 | 2414 | static void |
2ec9a5e0 TT |
2415 | create_cus_from_index (struct objfile *objfile, |
2416 | const gdb_byte *cu_list, offset_type cu_list_elements, | |
2417 | const gdb_byte *dwz_list, offset_type dwz_elements) | |
2418 | { | |
2419 | struct dwz_file *dwz; | |
2420 | ||
2421 | dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2; | |
2422 | dwarf2_per_objfile->all_comp_units | |
2423 | = obstack_alloc (&objfile->objfile_obstack, | |
2424 | dwarf2_per_objfile->n_comp_units | |
2425 | * sizeof (struct dwarf2_per_cu_data *)); | |
2426 | ||
74a0d9f6 JK |
2427 | create_cus_from_index_list (objfile, cu_list, cu_list_elements, |
2428 | &dwarf2_per_objfile->info, 0, 0); | |
2ec9a5e0 TT |
2429 | |
2430 | if (dwz_elements == 0) | |
74a0d9f6 | 2431 | return; |
2ec9a5e0 TT |
2432 | |
2433 | dwz = dwarf2_get_dwz_file (); | |
74a0d9f6 JK |
2434 | create_cus_from_index_list (objfile, dwz_list, dwz_elements, &dwz->info, 1, |
2435 | cu_list_elements / 2); | |
2ec9a5e0 TT |
2436 | } |
2437 | ||
1fd400ff | 2438 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 2439 | |
74a0d9f6 | 2440 | static void |
673bfd45 | 2441 | create_signatured_type_table_from_index (struct objfile *objfile, |
8b70b953 | 2442 | struct dwarf2_section_info *section, |
673bfd45 DE |
2443 | const gdb_byte *bytes, |
2444 | offset_type elements) | |
1fd400ff TT |
2445 | { |
2446 | offset_type i; | |
673bfd45 | 2447 | htab_t sig_types_hash; |
1fd400ff | 2448 | |
d467dd73 DE |
2449 | dwarf2_per_objfile->n_type_units = elements / 3; |
2450 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 2451 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 2452 | dwarf2_per_objfile->n_type_units |
b4dd5633 | 2453 | * sizeof (struct signatured_type *)); |
1fd400ff | 2454 | |
673bfd45 | 2455 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
2456 | |
2457 | for (i = 0; i < elements; i += 3) | |
2458 | { | |
52dc124a DE |
2459 | struct signatured_type *sig_type; |
2460 | ULONGEST offset, type_offset_in_tu, signature; | |
1fd400ff TT |
2461 | void **slot; |
2462 | ||
74a0d9f6 JK |
2463 | gdb_static_assert (sizeof (ULONGEST) >= 8); |
2464 | offset = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
2465 | type_offset_in_tu = extract_unsigned_integer (bytes + 8, 8, | |
2466 | BFD_ENDIAN_LITTLE); | |
1fd400ff TT |
2467 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); |
2468 | bytes += 3 * 8; | |
2469 | ||
52dc124a | 2470 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
1fd400ff | 2471 | struct signatured_type); |
52dc124a | 2472 | sig_type->signature = signature; |
3019eac3 DE |
2473 | sig_type->type_offset_in_tu.cu_off = type_offset_in_tu; |
2474 | sig_type->per_cu.is_debug_types = 1; | |
2475 | sig_type->per_cu.info_or_types_section = section; | |
52dc124a DE |
2476 | sig_type->per_cu.offset.sect_off = offset; |
2477 | sig_type->per_cu.objfile = objfile; | |
2478 | sig_type->per_cu.v.quick | |
1fd400ff TT |
2479 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2480 | struct dwarf2_per_cu_quick_data); | |
2481 | ||
52dc124a DE |
2482 | slot = htab_find_slot (sig_types_hash, sig_type, INSERT); |
2483 | *slot = sig_type; | |
1fd400ff | 2484 | |
b4dd5633 | 2485 | dwarf2_per_objfile->all_type_units[i / 3] = sig_type; |
1fd400ff TT |
2486 | } |
2487 | ||
673bfd45 | 2488 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
2489 | } |
2490 | ||
9291a0cd TT |
2491 | /* Read the address map data from the mapped index, and use it to |
2492 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 2493 | |
9291a0cd TT |
2494 | static void |
2495 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
2496 | { | |
2497 | const gdb_byte *iter, *end; | |
2498 | struct obstack temp_obstack; | |
2499 | struct addrmap *mutable_map; | |
2500 | struct cleanup *cleanup; | |
2501 | CORE_ADDR baseaddr; | |
2502 | ||
2503 | obstack_init (&temp_obstack); | |
2504 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
2505 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
2506 | ||
2507 | iter = index->address_table; | |
2508 | end = iter + index->address_table_size; | |
2509 | ||
2510 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2511 | ||
2512 | while (iter < end) | |
2513 | { | |
2514 | ULONGEST hi, lo, cu_index; | |
2515 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
2516 | iter += 8; | |
2517 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
2518 | iter += 8; | |
2519 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
2520 | iter += 4; | |
2521 | ||
2522 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 2523 | dw2_get_cu (cu_index)); |
9291a0cd TT |
2524 | } |
2525 | ||
2526 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
2527 | &objfile->objfile_obstack); | |
2528 | do_cleanups (cleanup); | |
2529 | } | |
2530 | ||
59d7bcaf JK |
2531 | /* The hash function for strings in the mapped index. This is the same as |
2532 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
2533 | implementation. This is necessary because the hash function is tied to the | |
2534 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
2535 | SYMBOL_HASH_NEXT. |
2536 | ||
2537 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 2538 | |
9291a0cd | 2539 | static hashval_t |
559a7a62 | 2540 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
2541 | { |
2542 | const unsigned char *str = (const unsigned char *) p; | |
2543 | hashval_t r = 0; | |
2544 | unsigned char c; | |
2545 | ||
2546 | while ((c = *str++) != 0) | |
559a7a62 JK |
2547 | { |
2548 | if (index_version >= 5) | |
2549 | c = tolower (c); | |
2550 | r = r * 67 + c - 113; | |
2551 | } | |
9291a0cd TT |
2552 | |
2553 | return r; | |
2554 | } | |
2555 | ||
2556 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
2557 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
2558 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 2559 | |
9291a0cd TT |
2560 | static int |
2561 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
2562 | offset_type **vec_out) | |
2563 | { | |
0cf03b49 JK |
2564 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2565 | offset_type hash; | |
9291a0cd | 2566 | offset_type slot, step; |
559a7a62 | 2567 | int (*cmp) (const char *, const char *); |
9291a0cd | 2568 | |
0cf03b49 JK |
2569 | if (current_language->la_language == language_cplus |
2570 | || current_language->la_language == language_java | |
2571 | || current_language->la_language == language_fortran) | |
2572 | { | |
2573 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2574 | not contain any. */ | |
2575 | const char *paren = strchr (name, '('); | |
2576 | ||
2577 | if (paren) | |
2578 | { | |
2579 | char *dup; | |
2580 | ||
2581 | dup = xmalloc (paren - name + 1); | |
2582 | memcpy (dup, name, paren - name); | |
2583 | dup[paren - name] = 0; | |
2584 | ||
2585 | make_cleanup (xfree, dup); | |
2586 | name = dup; | |
2587 | } | |
2588 | } | |
2589 | ||
559a7a62 | 2590 | /* Index version 4 did not support case insensitive searches. But the |
feea76c2 | 2591 | indices for case insensitive languages are built in lowercase, therefore |
559a7a62 JK |
2592 | simulate our NAME being searched is also lowercased. */ |
2593 | hash = mapped_index_string_hash ((index->version == 4 | |
2594 | && case_sensitivity == case_sensitive_off | |
2595 | ? 5 : index->version), | |
2596 | name); | |
2597 | ||
3876f04e DE |
2598 | slot = hash & (index->symbol_table_slots - 1); |
2599 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 2600 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
2601 | |
2602 | for (;;) | |
2603 | { | |
2604 | /* Convert a slot number to an offset into the table. */ | |
2605 | offset_type i = 2 * slot; | |
2606 | const char *str; | |
3876f04e | 2607 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2608 | { |
2609 | do_cleanups (back_to); | |
2610 | return 0; | |
2611 | } | |
9291a0cd | 2612 | |
3876f04e | 2613 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 2614 | if (!cmp (name, str)) |
9291a0cd TT |
2615 | { |
2616 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2617 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2618 | do_cleanups (back_to); |
9291a0cd TT |
2619 | return 1; |
2620 | } | |
2621 | ||
3876f04e | 2622 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2623 | } |
2624 | } | |
2625 | ||
2ec9a5e0 TT |
2626 | /* A helper function that reads the .gdb_index from SECTION and fills |
2627 | in MAP. FILENAME is the name of the file containing the section; | |
2628 | it is used for error reporting. DEPRECATED_OK is nonzero if it is | |
2629 | ok to use deprecated sections. | |
2630 | ||
2631 | CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are | |
2632 | out parameters that are filled in with information about the CU and | |
2633 | TU lists in the section. | |
2634 | ||
2635 | Returns 1 if all went well, 0 otherwise. */ | |
2fdf6df6 | 2636 | |
9291a0cd | 2637 | static int |
2ec9a5e0 TT |
2638 | read_index_from_section (struct objfile *objfile, |
2639 | const char *filename, | |
2640 | int deprecated_ok, | |
2641 | struct dwarf2_section_info *section, | |
2642 | struct mapped_index *map, | |
2643 | const gdb_byte **cu_list, | |
2644 | offset_type *cu_list_elements, | |
2645 | const gdb_byte **types_list, | |
2646 | offset_type *types_list_elements) | |
9291a0cd | 2647 | { |
9291a0cd | 2648 | char *addr; |
2ec9a5e0 | 2649 | offset_type version; |
b3b272e1 | 2650 | offset_type *metadata; |
1fd400ff | 2651 | int i; |
9291a0cd | 2652 | |
2ec9a5e0 | 2653 | if (dwarf2_section_empty_p (section)) |
9291a0cd | 2654 | return 0; |
82430852 JK |
2655 | |
2656 | /* Older elfutils strip versions could keep the section in the main | |
2657 | executable while splitting it for the separate debug info file. */ | |
2ec9a5e0 | 2658 | if ((bfd_get_file_flags (section->asection) & SEC_HAS_CONTENTS) == 0) |
82430852 JK |
2659 | return 0; |
2660 | ||
2ec9a5e0 | 2661 | dwarf2_read_section (objfile, section); |
9291a0cd | 2662 | |
2ec9a5e0 | 2663 | addr = section->buffer; |
9291a0cd | 2664 | /* Version check. */ |
1fd400ff | 2665 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2666 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2667 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 2668 | contained incomplete addrmap. So, it seems better to just ignore such |
481860b3 | 2669 | indices. */ |
831adc1f | 2670 | if (version < 4) |
481860b3 GB |
2671 | { |
2672 | static int warning_printed = 0; | |
2673 | if (!warning_printed) | |
2674 | { | |
2675 | warning (_("Skipping obsolete .gdb_index section in %s."), | |
2ec9a5e0 | 2676 | filename); |
481860b3 GB |
2677 | warning_printed = 1; |
2678 | } | |
2679 | return 0; | |
2680 | } | |
2681 | /* Index version 4 uses a different hash function than index version | |
2682 | 5 and later. | |
2683 | ||
2684 | Versions earlier than 6 did not emit psymbols for inlined | |
2685 | functions. Using these files will cause GDB not to be able to | |
2686 | set breakpoints on inlined functions by name, so we ignore these | |
e615022a DE |
2687 | indices unless the user has done |
2688 | "set use-deprecated-index-sections on". */ | |
2ec9a5e0 | 2689 | if (version < 6 && !deprecated_ok) |
481860b3 GB |
2690 | { |
2691 | static int warning_printed = 0; | |
2692 | if (!warning_printed) | |
2693 | { | |
e615022a DE |
2694 | warning (_("\ |
2695 | Skipping deprecated .gdb_index section in %s.\n\ | |
2696 | Do \"set use-deprecated-index-sections on\" before the file is read\n\ | |
2697 | to use the section anyway."), | |
2ec9a5e0 | 2698 | filename); |
481860b3 GB |
2699 | warning_printed = 1; |
2700 | } | |
2701 | return 0; | |
2702 | } | |
796a7ff8 DE |
2703 | /* Version 7 indices generated by gold refer to the CU for a symbol instead |
2704 | of the TU (for symbols coming from TUs). It's just a performance bug, and | |
2705 | we can't distinguish gdb-generated indices from gold-generated ones, so | |
2706 | nothing to do here. */ | |
2707 | ||
481860b3 | 2708 | /* Indexes with higher version than the one supported by GDB may be no |
594e8718 | 2709 | longer backward compatible. */ |
796a7ff8 | 2710 | if (version > 8) |
594e8718 | 2711 | return 0; |
9291a0cd | 2712 | |
559a7a62 | 2713 | map->version = version; |
2ec9a5e0 | 2714 | map->total_size = section->size; |
9291a0cd TT |
2715 | |
2716 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2717 | |
2718 | i = 0; | |
2ec9a5e0 TT |
2719 | *cu_list = addr + MAYBE_SWAP (metadata[i]); |
2720 | *cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
2721 | / 8); | |
1fd400ff TT |
2722 | ++i; |
2723 | ||
2ec9a5e0 TT |
2724 | *types_list = addr + MAYBE_SWAP (metadata[i]); |
2725 | *types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2726 | - MAYBE_SWAP (metadata[i])) | |
2727 | / 8); | |
987d643c | 2728 | ++i; |
1fd400ff TT |
2729 | |
2730 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2731 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2732 | - MAYBE_SWAP (metadata[i])); | |
2733 | ++i; | |
2734 | ||
3876f04e DE |
2735 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2736 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2737 | - MAYBE_SWAP (metadata[i])) | |
2738 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2739 | ++i; |
9291a0cd | 2740 | |
1fd400ff TT |
2741 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2742 | ||
2ec9a5e0 TT |
2743 | return 1; |
2744 | } | |
2745 | ||
2746 | ||
2747 | /* Read the index file. If everything went ok, initialize the "quick" | |
2748 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2749 | ||
2750 | static int | |
2751 | dwarf2_read_index (struct objfile *objfile) | |
2752 | { | |
2753 | struct mapped_index local_map, *map; | |
2754 | const gdb_byte *cu_list, *types_list, *dwz_list = NULL; | |
2755 | offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0; | |
2756 | ||
2757 | if (!read_index_from_section (objfile, objfile->name, | |
2758 | use_deprecated_index_sections, | |
2759 | &dwarf2_per_objfile->gdb_index, &local_map, | |
2760 | &cu_list, &cu_list_elements, | |
2761 | &types_list, &types_list_elements)) | |
2762 | return 0; | |
2763 | ||
0fefef59 | 2764 | /* Don't use the index if it's empty. */ |
2ec9a5e0 | 2765 | if (local_map.symbol_table_slots == 0) |
0fefef59 DE |
2766 | return 0; |
2767 | ||
2ec9a5e0 TT |
2768 | /* If there is a .dwz file, read it so we can get its CU list as |
2769 | well. */ | |
2770 | if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL) | |
2771 | { | |
2772 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
2773 | struct mapped_index dwz_map; | |
2774 | const gdb_byte *dwz_types_ignore; | |
2775 | offset_type dwz_types_elements_ignore; | |
2776 | ||
2777 | if (!read_index_from_section (objfile, bfd_get_filename (dwz->dwz_bfd), | |
2778 | 1, | |
2779 | &dwz->gdb_index, &dwz_map, | |
2780 | &dwz_list, &dwz_list_elements, | |
2781 | &dwz_types_ignore, | |
2782 | &dwz_types_elements_ignore)) | |
2783 | { | |
2784 | warning (_("could not read '.gdb_index' section from %s; skipping"), | |
2785 | bfd_get_filename (dwz->dwz_bfd)); | |
2786 | return 0; | |
2787 | } | |
2788 | } | |
2789 | ||
74a0d9f6 JK |
2790 | create_cus_from_index (objfile, cu_list, cu_list_elements, dwz_list, |
2791 | dwz_list_elements); | |
1fd400ff | 2792 | |
8b70b953 TT |
2793 | if (types_list_elements) |
2794 | { | |
2795 | struct dwarf2_section_info *section; | |
2796 | ||
2797 | /* We can only handle a single .debug_types when we have an | |
2798 | index. */ | |
2799 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) | |
2800 | return 0; | |
2801 | ||
2802 | section = VEC_index (dwarf2_section_info_def, | |
2803 | dwarf2_per_objfile->types, 0); | |
2804 | ||
74a0d9f6 JK |
2805 | create_signatured_type_table_from_index (objfile, section, types_list, |
2806 | types_list_elements); | |
8b70b953 | 2807 | } |
9291a0cd | 2808 | |
2ec9a5e0 TT |
2809 | create_addrmap_from_index (objfile, &local_map); |
2810 | ||
2811 | map = obstack_alloc (&objfile->objfile_obstack, sizeof (struct mapped_index)); | |
2812 | *map = local_map; | |
9291a0cd TT |
2813 | |
2814 | dwarf2_per_objfile->index_table = map; | |
2815 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2816 | dwarf2_per_objfile->quick_file_names_table = |
2817 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2818 | |
2819 | return 1; | |
2820 | } | |
2821 | ||
2822 | /* A helper for the "quick" functions which sets the global | |
2823 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2824 | |
9291a0cd TT |
2825 | static void |
2826 | dw2_setup (struct objfile *objfile) | |
2827 | { | |
2828 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2829 | gdb_assert (dwarf2_per_objfile); | |
2830 | } | |
2831 | ||
dee91e82 | 2832 | /* die_reader_func for dw2_get_file_names. */ |
2fdf6df6 | 2833 | |
dee91e82 DE |
2834 | static void |
2835 | dw2_get_file_names_reader (const struct die_reader_specs *reader, | |
2836 | gdb_byte *info_ptr, | |
2837 | struct die_info *comp_unit_die, | |
2838 | int has_children, | |
2839 | void *data) | |
9291a0cd | 2840 | { |
dee91e82 DE |
2841 | struct dwarf2_cu *cu = reader->cu; |
2842 | struct dwarf2_per_cu_data *this_cu = cu->per_cu; | |
2843 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
094b34ac | 2844 | struct dwarf2_per_cu_data *lh_cu; |
7b9f3c50 | 2845 | struct line_header *lh; |
9291a0cd | 2846 | struct attribute *attr; |
dee91e82 | 2847 | int i; |
15d034d0 | 2848 | const char *name, *comp_dir; |
7b9f3c50 DE |
2849 | void **slot; |
2850 | struct quick_file_names *qfn; | |
2851 | unsigned int line_offset; | |
9291a0cd | 2852 | |
07261596 TT |
2853 | /* Our callers never want to match partial units -- instead they |
2854 | will match the enclosing full CU. */ | |
2855 | if (comp_unit_die->tag == DW_TAG_partial_unit) | |
2856 | { | |
2857 | this_cu->v.quick->no_file_data = 1; | |
2858 | return; | |
2859 | } | |
2860 | ||
094b34ac DE |
2861 | /* If we're reading the line header for TUs, store it in the "per_cu" |
2862 | for tu_group. */ | |
2863 | if (this_cu->is_debug_types) | |
2864 | { | |
2865 | struct type_unit_group *tu_group = data; | |
2866 | ||
2867 | gdb_assert (tu_group != NULL); | |
2868 | lh_cu = &tu_group->per_cu; | |
2869 | } | |
2870 | else | |
2871 | lh_cu = this_cu; | |
2872 | ||
7b9f3c50 DE |
2873 | lh = NULL; |
2874 | slot = NULL; | |
2875 | line_offset = 0; | |
dee91e82 DE |
2876 | |
2877 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); | |
9291a0cd TT |
2878 | if (attr) |
2879 | { | |
7b9f3c50 DE |
2880 | struct quick_file_names find_entry; |
2881 | ||
2882 | line_offset = DW_UNSND (attr); | |
2883 | ||
2884 | /* We may have already read in this line header (TU line header sharing). | |
2885 | If we have we're done. */ | |
094b34ac DE |
2886 | find_entry.hash.dwo_unit = cu->dwo_unit; |
2887 | find_entry.hash.line_offset.sect_off = line_offset; | |
7b9f3c50 DE |
2888 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, |
2889 | &find_entry, INSERT); | |
2890 | if (*slot != NULL) | |
2891 | { | |
094b34ac | 2892 | lh_cu->v.quick->file_names = *slot; |
dee91e82 | 2893 | return; |
7b9f3c50 DE |
2894 | } |
2895 | ||
3019eac3 | 2896 | lh = dwarf_decode_line_header (line_offset, cu); |
9291a0cd TT |
2897 | } |
2898 | if (lh == NULL) | |
2899 | { | |
094b34ac | 2900 | lh_cu->v.quick->no_file_data = 1; |
dee91e82 | 2901 | return; |
9291a0cd TT |
2902 | } |
2903 | ||
7b9f3c50 | 2904 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
094b34ac DE |
2905 | qfn->hash.dwo_unit = cu->dwo_unit; |
2906 | qfn->hash.line_offset.sect_off = line_offset; | |
7b9f3c50 DE |
2907 | gdb_assert (slot != NULL); |
2908 | *slot = qfn; | |
9291a0cd | 2909 | |
dee91e82 | 2910 | find_file_and_directory (comp_unit_die, cu, &name, &comp_dir); |
9291a0cd | 2911 | |
7b9f3c50 DE |
2912 | qfn->num_file_names = lh->num_file_names; |
2913 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2914 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2915 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2916 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2917 | qfn->real_names = NULL; | |
9291a0cd | 2918 | |
7b9f3c50 | 2919 | free_line_header (lh); |
7b9f3c50 | 2920 | |
094b34ac | 2921 | lh_cu->v.quick->file_names = qfn; |
dee91e82 DE |
2922 | } |
2923 | ||
2924 | /* A helper for the "quick" functions which attempts to read the line | |
2925 | table for THIS_CU. */ | |
2926 | ||
2927 | static struct quick_file_names * | |
2928 | dw2_get_file_names (struct objfile *objfile, | |
2929 | struct dwarf2_per_cu_data *this_cu) | |
2930 | { | |
f4dc4d17 DE |
2931 | /* For TUs this should only be called on the parent group. */ |
2932 | if (this_cu->is_debug_types) | |
2933 | gdb_assert (IS_TYPE_UNIT_GROUP (this_cu)); | |
2934 | ||
dee91e82 DE |
2935 | if (this_cu->v.quick->file_names != NULL) |
2936 | return this_cu->v.quick->file_names; | |
2937 | /* If we know there is no line data, no point in looking again. */ | |
2938 | if (this_cu->v.quick->no_file_data) | |
2939 | return NULL; | |
2940 | ||
3019eac3 DE |
2941 | /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute |
2942 | in the stub for CUs, there's is no need to lookup the DWO file. | |
2943 | However, that's not the case for TUs where DW_AT_stmt_list lives in the | |
2944 | DWO file. */ | |
2945 | if (this_cu->is_debug_types) | |
094b34ac | 2946 | { |
796a7ff8 | 2947 | struct type_unit_group *tu_group = this_cu->type_unit_group; |
094b34ac DE |
2948 | |
2949 | init_cutu_and_read_dies (tu_group->t.first_tu, NULL, 0, 0, | |
2950 | dw2_get_file_names_reader, tu_group); | |
2951 | } | |
3019eac3 DE |
2952 | else |
2953 | init_cutu_and_read_dies_simple (this_cu, dw2_get_file_names_reader, NULL); | |
dee91e82 DE |
2954 | |
2955 | if (this_cu->v.quick->no_file_data) | |
2956 | return NULL; | |
2957 | return this_cu->v.quick->file_names; | |
9291a0cd TT |
2958 | } |
2959 | ||
2960 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2961 | real path for a given file name from the line table. */ |
2fdf6df6 | 2962 | |
9291a0cd | 2963 | static const char * |
7b9f3c50 DE |
2964 | dw2_get_real_path (struct objfile *objfile, |
2965 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2966 | { |
7b9f3c50 DE |
2967 | if (qfn->real_names == NULL) |
2968 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2969 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2970 | |
7b9f3c50 DE |
2971 | if (qfn->real_names[index] == NULL) |
2972 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2973 | |
7b9f3c50 | 2974 | return qfn->real_names[index]; |
9291a0cd TT |
2975 | } |
2976 | ||
2977 | static struct symtab * | |
2978 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2979 | { | |
2980 | int index; | |
ae2de4f8 | 2981 | |
9291a0cd TT |
2982 | dw2_setup (objfile); |
2983 | index = dwarf2_per_objfile->n_comp_units - 1; | |
a0f42c21 | 2984 | return dw2_instantiate_symtab (dw2_get_cu (index)); |
9291a0cd TT |
2985 | } |
2986 | ||
7b9f3c50 DE |
2987 | /* Traversal function for dw2_forget_cached_source_info. */ |
2988 | ||
2989 | static int | |
2990 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2991 | { |
7b9f3c50 | 2992 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2993 | |
7b9f3c50 | 2994 | if (file_data->real_names) |
9291a0cd | 2995 | { |
7b9f3c50 | 2996 | int i; |
9291a0cd | 2997 | |
7b9f3c50 | 2998 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2999 | { |
7b9f3c50 DE |
3000 | xfree ((void*) file_data->real_names[i]); |
3001 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
3002 | } |
3003 | } | |
7b9f3c50 DE |
3004 | |
3005 | return 1; | |
3006 | } | |
3007 | ||
3008 | static void | |
3009 | dw2_forget_cached_source_info (struct objfile *objfile) | |
3010 | { | |
3011 | dw2_setup (objfile); | |
3012 | ||
3013 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
3014 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
3015 | } |
3016 | ||
f8eba3c6 TT |
3017 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
3018 | the symtabs and calls the iterator. */ | |
3019 | ||
3020 | static int | |
3021 | dw2_map_expand_apply (struct objfile *objfile, | |
3022 | struct dwarf2_per_cu_data *per_cu, | |
3023 | const char *name, | |
3024 | const char *full_path, const char *real_path, | |
3025 | int (*callback) (struct symtab *, void *), | |
3026 | void *data) | |
3027 | { | |
3028 | struct symtab *last_made = objfile->symtabs; | |
3029 | ||
3030 | /* Don't visit already-expanded CUs. */ | |
3031 | if (per_cu->v.quick->symtab) | |
3032 | return 0; | |
3033 | ||
3034 | /* This may expand more than one symtab, and we want to iterate over | |
3035 | all of them. */ | |
a0f42c21 | 3036 | dw2_instantiate_symtab (per_cu); |
f8eba3c6 TT |
3037 | |
3038 | return iterate_over_some_symtabs (name, full_path, real_path, callback, data, | |
3039 | objfile->symtabs, last_made); | |
3040 | } | |
3041 | ||
3042 | /* Implementation of the map_symtabs_matching_filename method. */ | |
3043 | ||
9291a0cd | 3044 | static int |
f8eba3c6 TT |
3045 | dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name, |
3046 | const char *full_path, const char *real_path, | |
3047 | int (*callback) (struct symtab *, void *), | |
3048 | void *data) | |
9291a0cd TT |
3049 | { |
3050 | int i; | |
c011a4f4 | 3051 | const char *name_basename = lbasename (name); |
4aac40c8 | 3052 | int is_abs = IS_ABSOLUTE_PATH (name); |
9291a0cd TT |
3053 | |
3054 | dw2_setup (objfile); | |
ae2de4f8 | 3055 | |
848e3e78 DE |
3056 | /* The rule is CUs specify all the files, including those used by |
3057 | any TU, so there's no need to scan TUs here. */ | |
f4dc4d17 | 3058 | |
848e3e78 | 3059 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
9291a0cd TT |
3060 | { |
3061 | int j; | |
f4dc4d17 | 3062 | struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i); |
7b9f3c50 | 3063 | struct quick_file_names *file_data; |
9291a0cd | 3064 | |
3d7bb9d9 | 3065 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 3066 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
3067 | continue; |
3068 | ||
7b9f3c50 DE |
3069 | file_data = dw2_get_file_names (objfile, per_cu); |
3070 | if (file_data == NULL) | |
9291a0cd TT |
3071 | continue; |
3072 | ||
7b9f3c50 | 3073 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 3074 | { |
7b9f3c50 | 3075 | const char *this_name = file_data->file_names[j]; |
9291a0cd | 3076 | |
4aac40c8 | 3077 | if (FILENAME_CMP (name, this_name) == 0 |
b57a636e | 3078 | || (!is_abs && compare_filenames_for_search (this_name, name))) |
9291a0cd | 3079 | { |
f8eba3c6 TT |
3080 | if (dw2_map_expand_apply (objfile, per_cu, |
3081 | name, full_path, real_path, | |
3082 | callback, data)) | |
3083 | return 1; | |
4aac40c8 | 3084 | } |
9291a0cd | 3085 | |
c011a4f4 DE |
3086 | /* Before we invoke realpath, which can get expensive when many |
3087 | files are involved, do a quick comparison of the basenames. */ | |
3088 | if (! basenames_may_differ | |
3089 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) | |
3090 | continue; | |
3091 | ||
9291a0cd TT |
3092 | if (full_path != NULL) |
3093 | { | |
7b9f3c50 DE |
3094 | const char *this_real_name = dw2_get_real_path (objfile, |
3095 | file_data, j); | |
9291a0cd | 3096 | |
7b9f3c50 | 3097 | if (this_real_name != NULL |
4aac40c8 TT |
3098 | && (FILENAME_CMP (full_path, this_real_name) == 0 |
3099 | || (!is_abs | |
3100 | && compare_filenames_for_search (this_real_name, | |
b57a636e | 3101 | name)))) |
9291a0cd | 3102 | { |
f8eba3c6 TT |
3103 | if (dw2_map_expand_apply (objfile, per_cu, |
3104 | name, full_path, real_path, | |
3105 | callback, data)) | |
3106 | return 1; | |
9291a0cd TT |
3107 | } |
3108 | } | |
3109 | ||
3110 | if (real_path != NULL) | |
3111 | { | |
7b9f3c50 DE |
3112 | const char *this_real_name = dw2_get_real_path (objfile, |
3113 | file_data, j); | |
9291a0cd | 3114 | |
7b9f3c50 | 3115 | if (this_real_name != NULL |
4aac40c8 TT |
3116 | && (FILENAME_CMP (real_path, this_real_name) == 0 |
3117 | || (!is_abs | |
3118 | && compare_filenames_for_search (this_real_name, | |
b57a636e | 3119 | name)))) |
9291a0cd | 3120 | { |
f8eba3c6 TT |
3121 | if (dw2_map_expand_apply (objfile, per_cu, |
3122 | name, full_path, real_path, | |
3123 | callback, data)) | |
3124 | return 1; | |
9291a0cd TT |
3125 | } |
3126 | } | |
3127 | } | |
3128 | } | |
3129 | ||
9291a0cd TT |
3130 | return 0; |
3131 | } | |
3132 | ||
da51c347 DE |
3133 | /* Struct used to manage iterating over all CUs looking for a symbol. */ |
3134 | ||
3135 | struct dw2_symtab_iterator | |
9291a0cd | 3136 | { |
da51c347 DE |
3137 | /* The internalized form of .gdb_index. */ |
3138 | struct mapped_index *index; | |
3139 | /* If non-zero, only look for symbols that match BLOCK_INDEX. */ | |
3140 | int want_specific_block; | |
3141 | /* One of GLOBAL_BLOCK or STATIC_BLOCK. | |
3142 | Unused if !WANT_SPECIFIC_BLOCK. */ | |
3143 | int block_index; | |
3144 | /* The kind of symbol we're looking for. */ | |
3145 | domain_enum domain; | |
3146 | /* The list of CUs from the index entry of the symbol, | |
3147 | or NULL if not found. */ | |
3148 | offset_type *vec; | |
3149 | /* The next element in VEC to look at. */ | |
3150 | int next; | |
3151 | /* The number of elements in VEC, or zero if there is no match. */ | |
3152 | int length; | |
3153 | }; | |
9291a0cd | 3154 | |
da51c347 DE |
3155 | /* Initialize the index symtab iterator ITER. |
3156 | If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols | |
3157 | in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */ | |
2fdf6df6 | 3158 | |
9291a0cd | 3159 | static void |
da51c347 DE |
3160 | dw2_symtab_iter_init (struct dw2_symtab_iterator *iter, |
3161 | struct mapped_index *index, | |
3162 | int want_specific_block, | |
3163 | int block_index, | |
3164 | domain_enum domain, | |
3165 | const char *name) | |
3166 | { | |
3167 | iter->index = index; | |
3168 | iter->want_specific_block = want_specific_block; | |
3169 | iter->block_index = block_index; | |
3170 | iter->domain = domain; | |
3171 | iter->next = 0; | |
3172 | ||
3173 | if (find_slot_in_mapped_hash (index, name, &iter->vec)) | |
3174 | iter->length = MAYBE_SWAP (*iter->vec); | |
3175 | else | |
3176 | { | |
3177 | iter->vec = NULL; | |
3178 | iter->length = 0; | |
3179 | } | |
3180 | } | |
3181 | ||
3182 | /* Return the next matching CU or NULL if there are no more. */ | |
3183 | ||
3184 | static struct dwarf2_per_cu_data * | |
3185 | dw2_symtab_iter_next (struct dw2_symtab_iterator *iter) | |
3186 | { | |
3187 | for ( ; iter->next < iter->length; ++iter->next) | |
3188 | { | |
3189 | offset_type cu_index_and_attrs = | |
3190 | MAYBE_SWAP (iter->vec[iter->next + 1]); | |
3191 | offset_type cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs); | |
3192 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); | |
3193 | int want_static = iter->block_index != GLOBAL_BLOCK; | |
3194 | /* This value is only valid for index versions >= 7. */ | |
3195 | int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs); | |
3196 | gdb_index_symbol_kind symbol_kind = | |
3197 | GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs); | |
3198 | /* Only check the symbol attributes if they're present. | |
3199 | Indices prior to version 7 don't record them, | |
3200 | and indices >= 7 may elide them for certain symbols | |
3201 | (gold does this). */ | |
3202 | int attrs_valid = | |
3203 | (iter->index->version >= 7 | |
3204 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE); | |
3205 | ||
3206 | /* Skip if already read in. */ | |
3207 | if (per_cu->v.quick->symtab) | |
3208 | continue; | |
3209 | ||
3210 | if (attrs_valid | |
3211 | && iter->want_specific_block | |
3212 | && want_static != is_static) | |
3213 | continue; | |
3214 | ||
3215 | /* Only check the symbol's kind if it has one. */ | |
3216 | if (attrs_valid) | |
3217 | { | |
3218 | switch (iter->domain) | |
3219 | { | |
3220 | case VAR_DOMAIN: | |
3221 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE | |
3222 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION | |
3223 | /* Some types are also in VAR_DOMAIN. */ | |
3224 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) | |
3225 | continue; | |
3226 | break; | |
3227 | case STRUCT_DOMAIN: | |
3228 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) | |
3229 | continue; | |
3230 | break; | |
3231 | case LABEL_DOMAIN: | |
3232 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER) | |
3233 | continue; | |
3234 | break; | |
3235 | default: | |
3236 | break; | |
3237 | } | |
3238 | } | |
3239 | ||
3240 | ++iter->next; | |
3241 | return per_cu; | |
3242 | } | |
3243 | ||
3244 | return NULL; | |
3245 | } | |
3246 | ||
3247 | static struct symtab * | |
3248 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
3249 | const char *name, domain_enum domain) | |
9291a0cd | 3250 | { |
da51c347 | 3251 | struct symtab *stab_best = NULL; |
156942c7 DE |
3252 | struct mapped_index *index; |
3253 | ||
9291a0cd TT |
3254 | dw2_setup (objfile); |
3255 | ||
156942c7 DE |
3256 | index = dwarf2_per_objfile->index_table; |
3257 | ||
da51c347 | 3258 | /* index is NULL if OBJF_READNOW. */ |
156942c7 | 3259 | if (index) |
9291a0cd | 3260 | { |
da51c347 DE |
3261 | struct dw2_symtab_iterator iter; |
3262 | struct dwarf2_per_cu_data *per_cu; | |
3263 | ||
3264 | dw2_symtab_iter_init (&iter, index, 1, block_index, domain, name); | |
9291a0cd | 3265 | |
da51c347 | 3266 | while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL) |
9291a0cd | 3267 | { |
da51c347 DE |
3268 | struct symbol *sym = NULL; |
3269 | struct symtab *stab = dw2_instantiate_symtab (per_cu); | |
3270 | ||
3271 | /* Some caution must be observed with overloaded functions | |
3272 | and methods, since the index will not contain any overload | |
3273 | information (but NAME might contain it). */ | |
3274 | if (stab->primary) | |
9291a0cd | 3275 | { |
da51c347 DE |
3276 | struct blockvector *bv = BLOCKVECTOR (stab); |
3277 | struct block *block = BLOCKVECTOR_BLOCK (bv, block_index); | |
156942c7 | 3278 | |
da51c347 DE |
3279 | sym = lookup_block_symbol (block, name, domain); |
3280 | } | |
1fd400ff | 3281 | |
da51c347 DE |
3282 | if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0) |
3283 | { | |
3284 | if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym))) | |
3285 | return stab; | |
3286 | ||
3287 | stab_best = stab; | |
9291a0cd | 3288 | } |
da51c347 DE |
3289 | |
3290 | /* Keep looking through other CUs. */ | |
9291a0cd TT |
3291 | } |
3292 | } | |
9291a0cd | 3293 | |
da51c347 | 3294 | return stab_best; |
9291a0cd TT |
3295 | } |
3296 | ||
3297 | static void | |
3298 | dw2_print_stats (struct objfile *objfile) | |
3299 | { | |
3300 | int i, count; | |
3301 | ||
3302 | dw2_setup (objfile); | |
3303 | count = 0; | |
1fd400ff | 3304 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 3305 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 3306 | { |
e254ef6a | 3307 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 3308 | |
e254ef6a | 3309 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
3310 | ++count; |
3311 | } | |
3312 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
3313 | } | |
3314 | ||
3315 | static void | |
3316 | dw2_dump (struct objfile *objfile) | |
3317 | { | |
3318 | /* Nothing worth printing. */ | |
3319 | } | |
3320 | ||
3321 | static void | |
3322 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
3323 | struct section_offsets *delta) | |
3324 | { | |
3325 | /* There's nothing to relocate here. */ | |
3326 | } | |
3327 | ||
3328 | static void | |
3329 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
3330 | const char *func_name) | |
3331 | { | |
da51c347 DE |
3332 | struct mapped_index *index; |
3333 | ||
3334 | dw2_setup (objfile); | |
3335 | ||
3336 | index = dwarf2_per_objfile->index_table; | |
3337 | ||
3338 | /* index is NULL if OBJF_READNOW. */ | |
3339 | if (index) | |
3340 | { | |
3341 | struct dw2_symtab_iterator iter; | |
3342 | struct dwarf2_per_cu_data *per_cu; | |
3343 | ||
3344 | /* Note: It doesn't matter what we pass for block_index here. */ | |
3345 | dw2_symtab_iter_init (&iter, index, 0, GLOBAL_BLOCK, VAR_DOMAIN, | |
3346 | func_name); | |
3347 | ||
3348 | while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL) | |
3349 | dw2_instantiate_symtab (per_cu); | |
3350 | } | |
9291a0cd TT |
3351 | } |
3352 | ||
3353 | static void | |
3354 | dw2_expand_all_symtabs (struct objfile *objfile) | |
3355 | { | |
3356 | int i; | |
3357 | ||
3358 | dw2_setup (objfile); | |
1fd400ff TT |
3359 | |
3360 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 3361 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 3362 | { |
e254ef6a | 3363 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 3364 | |
a0f42c21 | 3365 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
3366 | } |
3367 | } | |
3368 | ||
3369 | static void | |
3370 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
3371 | const char *filename) | |
3372 | { | |
3373 | int i; | |
3374 | ||
3375 | dw2_setup (objfile); | |
d4637a04 DE |
3376 | |
3377 | /* We don't need to consider type units here. | |
3378 | This is only called for examining code, e.g. expand_line_sal. | |
3379 | There can be an order of magnitude (or more) more type units | |
3380 | than comp units, and we avoid them if we can. */ | |
3381 | ||
3382 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
3383 | { |
3384 | int j; | |
e254ef6a | 3385 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 3386 | struct quick_file_names *file_data; |
9291a0cd | 3387 | |
3d7bb9d9 | 3388 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 3389 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
3390 | continue; |
3391 | ||
7b9f3c50 DE |
3392 | file_data = dw2_get_file_names (objfile, per_cu); |
3393 | if (file_data == NULL) | |
9291a0cd TT |
3394 | continue; |
3395 | ||
7b9f3c50 | 3396 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 3397 | { |
7b9f3c50 | 3398 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 3399 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 3400 | { |
a0f42c21 | 3401 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
3402 | break; |
3403 | } | |
3404 | } | |
3405 | } | |
3406 | } | |
3407 | ||
356d9f9d TT |
3408 | /* A helper function for dw2_find_symbol_file that finds the primary |
3409 | file name for a given CU. This is a die_reader_func. */ | |
3410 | ||
3411 | static void | |
3412 | dw2_get_primary_filename_reader (const struct die_reader_specs *reader, | |
3413 | gdb_byte *info_ptr, | |
3414 | struct die_info *comp_unit_die, | |
3415 | int has_children, | |
3416 | void *data) | |
3417 | { | |
3418 | const char **result_ptr = data; | |
3419 | struct dwarf2_cu *cu = reader->cu; | |
3420 | struct attribute *attr; | |
3421 | ||
3422 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu); | |
3423 | if (attr == NULL) | |
3424 | *result_ptr = NULL; | |
3425 | else | |
3426 | *result_ptr = DW_STRING (attr); | |
3427 | } | |
3428 | ||
dd786858 | 3429 | static const char * |
9291a0cd TT |
3430 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
3431 | { | |
e254ef6a | 3432 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 3433 | offset_type *vec; |
356d9f9d | 3434 | const char *filename; |
9291a0cd TT |
3435 | |
3436 | dw2_setup (objfile); | |
3437 | ||
ae2de4f8 | 3438 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd | 3439 | if (!dwarf2_per_objfile->index_table) |
96408a79 SA |
3440 | { |
3441 | struct symtab *s; | |
3442 | ||
d790cf0a DE |
3443 | ALL_OBJFILE_PRIMARY_SYMTABS (objfile, s) |
3444 | { | |
3445 | struct blockvector *bv = BLOCKVECTOR (s); | |
3446 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
3447 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); | |
3448 | ||
3449 | if (sym) | |
210bbc17 | 3450 | return SYMBOL_SYMTAB (sym)->filename; |
d790cf0a | 3451 | } |
96408a79 SA |
3452 | return NULL; |
3453 | } | |
9291a0cd TT |
3454 | |
3455 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
3456 | name, &vec)) | |
3457 | return NULL; | |
3458 | ||
3459 | /* Note that this just looks at the very first one named NAME -- but | |
3460 | actually we are looking for a function. find_main_filename | |
3461 | should be rewritten so that it doesn't require a custom hook. It | |
3462 | could just use the ordinary symbol tables. */ | |
3463 | /* vec[0] is the length, which must always be >0. */ | |
156942c7 | 3464 | per_cu = dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec[1]))); |
9291a0cd | 3465 | |
356d9f9d TT |
3466 | if (per_cu->v.quick->symtab != NULL) |
3467 | return per_cu->v.quick->symtab->filename; | |
3468 | ||
f4dc4d17 DE |
3469 | init_cutu_and_read_dies (per_cu, NULL, 0, 0, |
3470 | dw2_get_primary_filename_reader, &filename); | |
9291a0cd | 3471 | |
356d9f9d | 3472 | return filename; |
9291a0cd TT |
3473 | } |
3474 | ||
3475 | static void | |
40658b94 PH |
3476 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
3477 | struct objfile *objfile, int global, | |
3478 | int (*callback) (struct block *, | |
3479 | struct symbol *, void *), | |
2edb89d3 JK |
3480 | void *data, symbol_compare_ftype *match, |
3481 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 3482 | { |
40658b94 | 3483 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
3484 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
3485 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
3486 | } |
3487 | ||
3488 | static void | |
f8eba3c6 TT |
3489 | dw2_expand_symtabs_matching |
3490 | (struct objfile *objfile, | |
3491 | int (*file_matcher) (const char *, void *), | |
e078317b | 3492 | int (*name_matcher) (const char *, void *), |
f8eba3c6 TT |
3493 | enum search_domain kind, |
3494 | void *data) | |
9291a0cd TT |
3495 | { |
3496 | int i; | |
3497 | offset_type iter; | |
4b5246aa | 3498 | struct mapped_index *index; |
9291a0cd TT |
3499 | |
3500 | dw2_setup (objfile); | |
ae2de4f8 DE |
3501 | |
3502 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
3503 | if (!dwarf2_per_objfile->index_table) |
3504 | return; | |
4b5246aa | 3505 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 3506 | |
7b08b9eb | 3507 | if (file_matcher != NULL) |
24c79950 TT |
3508 | { |
3509 | struct cleanup *cleanup; | |
3510 | htab_t visited_found, visited_not_found; | |
3511 | ||
3512 | visited_found = htab_create_alloc (10, | |
3513 | htab_hash_pointer, htab_eq_pointer, | |
3514 | NULL, xcalloc, xfree); | |
3515 | cleanup = make_cleanup_htab_delete (visited_found); | |
3516 | visited_not_found = htab_create_alloc (10, | |
3517 | htab_hash_pointer, htab_eq_pointer, | |
3518 | NULL, xcalloc, xfree); | |
3519 | make_cleanup_htab_delete (visited_not_found); | |
3520 | ||
848e3e78 DE |
3521 | /* The rule is CUs specify all the files, including those used by |
3522 | any TU, so there's no need to scan TUs here. */ | |
3523 | ||
3524 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
24c79950 TT |
3525 | { |
3526 | int j; | |
f4dc4d17 | 3527 | struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i); |
24c79950 TT |
3528 | struct quick_file_names *file_data; |
3529 | void **slot; | |
7b08b9eb | 3530 | |
24c79950 | 3531 | per_cu->v.quick->mark = 0; |
3d7bb9d9 | 3532 | |
24c79950 TT |
3533 | /* We only need to look at symtabs not already expanded. */ |
3534 | if (per_cu->v.quick->symtab) | |
3535 | continue; | |
7b08b9eb | 3536 | |
24c79950 TT |
3537 | file_data = dw2_get_file_names (objfile, per_cu); |
3538 | if (file_data == NULL) | |
3539 | continue; | |
7b08b9eb | 3540 | |
24c79950 TT |
3541 | if (htab_find (visited_not_found, file_data) != NULL) |
3542 | continue; | |
3543 | else if (htab_find (visited_found, file_data) != NULL) | |
3544 | { | |
3545 | per_cu->v.quick->mark = 1; | |
3546 | continue; | |
3547 | } | |
3548 | ||
3549 | for (j = 0; j < file_data->num_file_names; ++j) | |
3550 | { | |
3551 | if (file_matcher (file_data->file_names[j], data)) | |
3552 | { | |
3553 | per_cu->v.quick->mark = 1; | |
3554 | break; | |
3555 | } | |
3556 | } | |
3557 | ||
3558 | slot = htab_find_slot (per_cu->v.quick->mark | |
3559 | ? visited_found | |
3560 | : visited_not_found, | |
3561 | file_data, INSERT); | |
3562 | *slot = file_data; | |
3563 | } | |
3564 | ||
3565 | do_cleanups (cleanup); | |
3566 | } | |
9291a0cd | 3567 | |
3876f04e | 3568 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
3569 | { |
3570 | offset_type idx = 2 * iter; | |
3571 | const char *name; | |
3572 | offset_type *vec, vec_len, vec_idx; | |
3573 | ||
3876f04e | 3574 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
3575 | continue; |
3576 | ||
3876f04e | 3577 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd | 3578 | |
e078317b | 3579 | if (! (*name_matcher) (name, data)) |
9291a0cd TT |
3580 | continue; |
3581 | ||
3582 | /* The name was matched, now expand corresponding CUs that were | |
3583 | marked. */ | |
4b5246aa | 3584 | vec = (offset_type *) (index->constant_pool |
3876f04e | 3585 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
3586 | vec_len = MAYBE_SWAP (vec[0]); |
3587 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
3588 | { | |
e254ef6a | 3589 | struct dwarf2_per_cu_data *per_cu; |
156942c7 DE |
3590 | offset_type cu_index_and_attrs = MAYBE_SWAP (vec[vec_idx + 1]); |
3591 | gdb_index_symbol_kind symbol_kind = | |
3592 | GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs); | |
3593 | int cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs); | |
3594 | ||
3595 | /* Don't crash on bad data. */ | |
3596 | if (cu_index >= (dwarf2_per_objfile->n_comp_units | |
667e0a4b | 3597 | + dwarf2_per_objfile->n_type_units)) |
156942c7 | 3598 | continue; |
1fd400ff | 3599 | |
156942c7 DE |
3600 | /* Only check the symbol's kind if it has one. |
3601 | Indices prior to version 7 don't record it. */ | |
3602 | if (index->version >= 7) | |
3603 | { | |
3604 | switch (kind) | |
3605 | { | |
3606 | case VARIABLES_DOMAIN: | |
3607 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE) | |
3608 | continue; | |
3609 | break; | |
3610 | case FUNCTIONS_DOMAIN: | |
3611 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION) | |
3612 | continue; | |
3613 | break; | |
3614 | case TYPES_DOMAIN: | |
3615 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) | |
3616 | continue; | |
3617 | break; | |
3618 | default: | |
3619 | break; | |
3620 | } | |
3621 | } | |
3622 | ||
3623 | per_cu = dw2_get_cu (cu_index); | |
7b08b9eb | 3624 | if (file_matcher == NULL || per_cu->v.quick->mark) |
a0f42c21 | 3625 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
3626 | } |
3627 | } | |
3628 | } | |
3629 | ||
9703b513 TT |
3630 | /* A helper for dw2_find_pc_sect_symtab which finds the most specific |
3631 | symtab. */ | |
3632 | ||
3633 | static struct symtab * | |
3634 | recursively_find_pc_sect_symtab (struct symtab *symtab, CORE_ADDR pc) | |
3635 | { | |
3636 | int i; | |
3637 | ||
3638 | if (BLOCKVECTOR (symtab) != NULL | |
3639 | && blockvector_contains_pc (BLOCKVECTOR (symtab), pc)) | |
3640 | return symtab; | |
3641 | ||
a3ec0bb1 DE |
3642 | if (symtab->includes == NULL) |
3643 | return NULL; | |
3644 | ||
9703b513 TT |
3645 | for (i = 0; symtab->includes[i]; ++i) |
3646 | { | |
a3ec0bb1 | 3647 | struct symtab *s = symtab->includes[i]; |
9703b513 TT |
3648 | |
3649 | s = recursively_find_pc_sect_symtab (s, pc); | |
3650 | if (s != NULL) | |
3651 | return s; | |
3652 | } | |
3653 | ||
3654 | return NULL; | |
3655 | } | |
3656 | ||
9291a0cd TT |
3657 | static struct symtab * |
3658 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
3659 | struct minimal_symbol *msymbol, | |
3660 | CORE_ADDR pc, | |
3661 | struct obj_section *section, | |
3662 | int warn_if_readin) | |
3663 | { | |
3664 | struct dwarf2_per_cu_data *data; | |
9703b513 | 3665 | struct symtab *result; |
9291a0cd TT |
3666 | |
3667 | dw2_setup (objfile); | |
3668 | ||
3669 | if (!objfile->psymtabs_addrmap) | |
3670 | return NULL; | |
3671 | ||
3672 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
3673 | if (!data) | |
3674 | return NULL; | |
3675 | ||
3676 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 3677 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
3678 | paddress (get_objfile_arch (objfile), pc)); |
3679 | ||
9703b513 TT |
3680 | result = recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data), pc); |
3681 | gdb_assert (result != NULL); | |
3682 | return result; | |
9291a0cd TT |
3683 | } |
3684 | ||
9291a0cd | 3685 | static void |
44b13c5a | 3686 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
74e2f255 | 3687 | void *data, int need_fullname) |
9291a0cd TT |
3688 | { |
3689 | int i; | |
24c79950 TT |
3690 | struct cleanup *cleanup; |
3691 | htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer, | |
3692 | NULL, xcalloc, xfree); | |
9291a0cd | 3693 | |
24c79950 | 3694 | cleanup = make_cleanup_htab_delete (visited); |
9291a0cd | 3695 | dw2_setup (objfile); |
ae2de4f8 | 3696 | |
848e3e78 DE |
3697 | /* The rule is CUs specify all the files, including those used by |
3698 | any TU, so there's no need to scan TUs here. | |
3699 | We can ignore file names coming from already-expanded CUs. */ | |
f4dc4d17 | 3700 | |
848e3e78 | 3701 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
24c79950 TT |
3702 | { |
3703 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
3704 | ||
3705 | if (per_cu->v.quick->symtab) | |
3706 | { | |
3707 | void **slot = htab_find_slot (visited, per_cu->v.quick->file_names, | |
3708 | INSERT); | |
3709 | ||
3710 | *slot = per_cu->v.quick->file_names; | |
3711 | } | |
3712 | } | |
3713 | ||
848e3e78 | 3714 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
9291a0cd TT |
3715 | { |
3716 | int j; | |
f4dc4d17 | 3717 | struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i); |
7b9f3c50 | 3718 | struct quick_file_names *file_data; |
24c79950 | 3719 | void **slot; |
9291a0cd | 3720 | |
3d7bb9d9 | 3721 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 3722 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
3723 | continue; |
3724 | ||
7b9f3c50 DE |
3725 | file_data = dw2_get_file_names (objfile, per_cu); |
3726 | if (file_data == NULL) | |
9291a0cd TT |
3727 | continue; |
3728 | ||
24c79950 TT |
3729 | slot = htab_find_slot (visited, file_data, INSERT); |
3730 | if (*slot) | |
3731 | { | |
3732 | /* Already visited. */ | |
3733 | continue; | |
3734 | } | |
3735 | *slot = file_data; | |
3736 | ||
7b9f3c50 | 3737 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 3738 | { |
74e2f255 DE |
3739 | const char *this_real_name; |
3740 | ||
3741 | if (need_fullname) | |
3742 | this_real_name = dw2_get_real_path (objfile, file_data, j); | |
3743 | else | |
3744 | this_real_name = NULL; | |
7b9f3c50 | 3745 | (*fun) (file_data->file_names[j], this_real_name, data); |
9291a0cd TT |
3746 | } |
3747 | } | |
24c79950 TT |
3748 | |
3749 | do_cleanups (cleanup); | |
9291a0cd TT |
3750 | } |
3751 | ||
3752 | static int | |
3753 | dw2_has_symbols (struct objfile *objfile) | |
3754 | { | |
3755 | return 1; | |
3756 | } | |
3757 | ||
3758 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
3759 | { | |
3760 | dw2_has_symbols, | |
3761 | dw2_find_last_source_symtab, | |
3762 | dw2_forget_cached_source_info, | |
f8eba3c6 | 3763 | dw2_map_symtabs_matching_filename, |
9291a0cd | 3764 | dw2_lookup_symbol, |
9291a0cd TT |
3765 | dw2_print_stats, |
3766 | dw2_dump, | |
3767 | dw2_relocate, | |
3768 | dw2_expand_symtabs_for_function, | |
3769 | dw2_expand_all_symtabs, | |
3770 | dw2_expand_symtabs_with_filename, | |
3771 | dw2_find_symbol_file, | |
40658b94 | 3772 | dw2_map_matching_symbols, |
9291a0cd TT |
3773 | dw2_expand_symtabs_matching, |
3774 | dw2_find_pc_sect_symtab, | |
9291a0cd TT |
3775 | dw2_map_symbol_filenames |
3776 | }; | |
3777 | ||
3778 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
3779 | file will use psymtabs, or 1 if using the GNU index. */ | |
3780 | ||
3781 | int | |
3782 | dwarf2_initialize_objfile (struct objfile *objfile) | |
3783 | { | |
3784 | /* If we're about to read full symbols, don't bother with the | |
3785 | indices. In this case we also don't care if some other debug | |
3786 | format is making psymtabs, because they are all about to be | |
3787 | expanded anyway. */ | |
3788 | if ((objfile->flags & OBJF_READNOW)) | |
3789 | { | |
3790 | int i; | |
3791 | ||
3792 | dwarf2_per_objfile->using_index = 1; | |
3793 | create_all_comp_units (objfile); | |
0e50663e | 3794 | create_all_type_units (objfile); |
7b9f3c50 DE |
3795 | dwarf2_per_objfile->quick_file_names_table = |
3796 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 3797 | |
1fd400ff | 3798 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 3799 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 3800 | { |
e254ef6a | 3801 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 3802 | |
e254ef6a DE |
3803 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
3804 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
3805 | } |
3806 | ||
3807 | /* Return 1 so that gdb sees the "quick" functions. However, | |
3808 | these functions will be no-ops because we will have expanded | |
3809 | all symtabs. */ | |
3810 | return 1; | |
3811 | } | |
3812 | ||
3813 | if (dwarf2_read_index (objfile)) | |
3814 | return 1; | |
3815 | ||
9291a0cd TT |
3816 | return 0; |
3817 | } | |
3818 | ||
3819 | \f | |
3820 | ||
dce234bc PP |
3821 | /* Build a partial symbol table. */ |
3822 | ||
3823 | void | |
f29dff0a | 3824 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 3825 | { |
c9bf0622 TT |
3826 | volatile struct gdb_exception except; |
3827 | ||
f29dff0a | 3828 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
3829 | { |
3830 | init_psymbol_list (objfile, 1024); | |
3831 | } | |
3832 | ||
c9bf0622 TT |
3833 | TRY_CATCH (except, RETURN_MASK_ERROR) |
3834 | { | |
3835 | /* This isn't really ideal: all the data we allocate on the | |
3836 | objfile's obstack is still uselessly kept around. However, | |
3837 | freeing it seems unsafe. */ | |
3838 | struct cleanup *cleanups = make_cleanup_discard_psymtabs (objfile); | |
3839 | ||
3840 | dwarf2_build_psymtabs_hard (objfile); | |
3841 | discard_cleanups (cleanups); | |
3842 | } | |
3843 | if (except.reason < 0) | |
3844 | exception_print (gdb_stderr, except); | |
c906108c | 3845 | } |
c906108c | 3846 | |
1ce1cefd DE |
3847 | /* Return the total length of the CU described by HEADER. */ |
3848 | ||
3849 | static unsigned int | |
3850 | get_cu_length (const struct comp_unit_head *header) | |
3851 | { | |
3852 | return header->initial_length_size + header->length; | |
3853 | } | |
3854 | ||
45452591 DE |
3855 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
3856 | ||
3857 | static inline int | |
b64f50a1 | 3858 | offset_in_cu_p (const struct comp_unit_head *cu_header, sect_offset offset) |
45452591 | 3859 | { |
b64f50a1 | 3860 | sect_offset bottom = { cu_header->offset.sect_off }; |
1ce1cefd | 3861 | sect_offset top = { cu_header->offset.sect_off + get_cu_length (cu_header) }; |
9a619af0 | 3862 | |
b64f50a1 | 3863 | return (offset.sect_off >= bottom.sect_off && offset.sect_off < top.sect_off); |
45452591 DE |
3864 | } |
3865 | ||
3b80fe9b DE |
3866 | /* Find the base address of the compilation unit for range lists and |
3867 | location lists. It will normally be specified by DW_AT_low_pc. | |
3868 | In DWARF-3 draft 4, the base address could be overridden by | |
3869 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3870 | compilation units with discontinuous ranges. */ | |
3871 | ||
3872 | static void | |
3873 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3874 | { | |
3875 | struct attribute *attr; | |
3876 | ||
3877 | cu->base_known = 0; | |
3878 | cu->base_address = 0; | |
3879 | ||
3880 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3881 | if (attr) | |
3882 | { | |
3883 | cu->base_address = DW_ADDR (attr); | |
3884 | cu->base_known = 1; | |
3885 | } | |
3886 | else | |
3887 | { | |
3888 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3889 | if (attr) | |
3890 | { | |
3891 | cu->base_address = DW_ADDR (attr); | |
3892 | cu->base_known = 1; | |
3893 | } | |
3894 | } | |
3895 | } | |
3896 | ||
93311388 DE |
3897 | /* Read in the comp unit header information from the debug_info at info_ptr. |
3898 | NOTE: This leaves members offset, first_die_offset to be filled in | |
3899 | by the caller. */ | |
107d2387 | 3900 | |
fe1b8b76 | 3901 | static gdb_byte * |
107d2387 | 3902 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 3903 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
3904 | { |
3905 | int signed_addr; | |
891d2f0b | 3906 | unsigned int bytes_read; |
c764a876 DE |
3907 | |
3908 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
3909 | cu_header->initial_length_size = bytes_read; | |
3910 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 3911 | info_ptr += bytes_read; |
107d2387 AC |
3912 | cu_header->version = read_2_bytes (abfd, info_ptr); |
3913 | info_ptr += 2; | |
b64f50a1 JK |
3914 | cu_header->abbrev_offset.sect_off = read_offset (abfd, info_ptr, cu_header, |
3915 | &bytes_read); | |
613e1657 | 3916 | info_ptr += bytes_read; |
107d2387 AC |
3917 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
3918 | info_ptr += 1; | |
3919 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
3920 | if (signed_addr < 0) | |
8e65ff28 | 3921 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3922 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 3923 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 3924 | |
107d2387 AC |
3925 | return info_ptr; |
3926 | } | |
3927 | ||
36586728 TT |
3928 | /* Helper function that returns the proper abbrev section for |
3929 | THIS_CU. */ | |
3930 | ||
3931 | static struct dwarf2_section_info * | |
3932 | get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu) | |
3933 | { | |
3934 | struct dwarf2_section_info *abbrev; | |
3935 | ||
3936 | if (this_cu->is_dwz) | |
3937 | abbrev = &dwarf2_get_dwz_file ()->abbrev; | |
3938 | else | |
3939 | abbrev = &dwarf2_per_objfile->abbrev; | |
3940 | ||
3941 | return abbrev; | |
3942 | } | |
3943 | ||
9ff913ba DE |
3944 | /* Subroutine of read_and_check_comp_unit_head and |
3945 | read_and_check_type_unit_head to simplify them. | |
3946 | Perform various error checking on the header. */ | |
3947 | ||
3948 | static void | |
3949 | error_check_comp_unit_head (struct comp_unit_head *header, | |
4bdcc0c1 DE |
3950 | struct dwarf2_section_info *section, |
3951 | struct dwarf2_section_info *abbrev_section) | |
9ff913ba DE |
3952 | { |
3953 | bfd *abfd = section->asection->owner; | |
3954 | const char *filename = bfd_get_filename (abfd); | |
3955 | ||
3956 | if (header->version != 2 && header->version != 3 && header->version != 4) | |
3957 | error (_("Dwarf Error: wrong version in compilation unit header " | |
3958 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, | |
3959 | filename); | |
3960 | ||
b64f50a1 | 3961 | if (header->abbrev_offset.sect_off |
36586728 | 3962 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section)) |
9ff913ba DE |
3963 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
3964 | "(offset 0x%lx + 6) [in module %s]"), | |
b64f50a1 | 3965 | (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off, |
9ff913ba DE |
3966 | filename); |
3967 | ||
3968 | /* Cast to unsigned long to use 64-bit arithmetic when possible to | |
3969 | avoid potential 32-bit overflow. */ | |
1ce1cefd | 3970 | if (((unsigned long) header->offset.sect_off + get_cu_length (header)) |
9ff913ba DE |
3971 | > section->size) |
3972 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " | |
3973 | "(offset 0x%lx + 0) [in module %s]"), | |
b64f50a1 | 3974 | (long) header->length, (long) header->offset.sect_off, |
9ff913ba DE |
3975 | filename); |
3976 | } | |
3977 | ||
3978 | /* Read in a CU/TU header and perform some basic error checking. | |
3979 | The contents of the header are stored in HEADER. | |
3980 | The result is a pointer to the start of the first DIE. */ | |
adabb602 | 3981 | |
fe1b8b76 | 3982 | static gdb_byte * |
9ff913ba DE |
3983 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
3984 | struct dwarf2_section_info *section, | |
4bdcc0c1 | 3985 | struct dwarf2_section_info *abbrev_section, |
9ff913ba DE |
3986 | gdb_byte *info_ptr, |
3987 | int is_debug_types_section) | |
72bf9492 | 3988 | { |
fe1b8b76 | 3989 | gdb_byte *beg_of_comp_unit = info_ptr; |
9ff913ba | 3990 | bfd *abfd = section->asection->owner; |
72bf9492 | 3991 | |
b64f50a1 | 3992 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
adabb602 | 3993 | |
72bf9492 DJ |
3994 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
3995 | ||
460c1c54 CC |
3996 | /* If we're reading a type unit, skip over the signature and |
3997 | type_offset fields. */ | |
b0df02fd | 3998 | if (is_debug_types_section) |
460c1c54 CC |
3999 | info_ptr += 8 /*signature*/ + header->offset_size; |
4000 | ||
b64f50a1 | 4001 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
adabb602 | 4002 | |
4bdcc0c1 | 4003 | error_check_comp_unit_head (header, section, abbrev_section); |
72bf9492 DJ |
4004 | |
4005 | return info_ptr; | |
4006 | } | |
4007 | ||
348e048f DE |
4008 | /* Read in the types comp unit header information from .debug_types entry at |
4009 | types_ptr. The result is a pointer to one past the end of the header. */ | |
4010 | ||
4011 | static gdb_byte * | |
9ff913ba DE |
4012 | read_and_check_type_unit_head (struct comp_unit_head *header, |
4013 | struct dwarf2_section_info *section, | |
4bdcc0c1 | 4014 | struct dwarf2_section_info *abbrev_section, |
9ff913ba | 4015 | gdb_byte *info_ptr, |
dee91e82 DE |
4016 | ULONGEST *signature, |
4017 | cu_offset *type_offset_in_tu) | |
348e048f | 4018 | { |
9ff913ba DE |
4019 | gdb_byte *beg_of_comp_unit = info_ptr; |
4020 | bfd *abfd = section->asection->owner; | |
348e048f | 4021 | |
b64f50a1 | 4022 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
348e048f | 4023 | |
9ff913ba | 4024 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
348e048f | 4025 | |
9ff913ba DE |
4026 | /* If we're reading a type unit, skip over the signature and |
4027 | type_offset fields. */ | |
4028 | if (signature != NULL) | |
4029 | *signature = read_8_bytes (abfd, info_ptr); | |
4030 | info_ptr += 8; | |
dee91e82 DE |
4031 | if (type_offset_in_tu != NULL) |
4032 | type_offset_in_tu->cu_off = read_offset_1 (abfd, info_ptr, | |
4033 | header->offset_size); | |
9ff913ba DE |
4034 | info_ptr += header->offset_size; |
4035 | ||
b64f50a1 | 4036 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
348e048f | 4037 | |
4bdcc0c1 | 4038 | error_check_comp_unit_head (header, section, abbrev_section); |
9ff913ba DE |
4039 | |
4040 | return info_ptr; | |
348e048f DE |
4041 | } |
4042 | ||
f4dc4d17 DE |
4043 | /* Fetch the abbreviation table offset from a comp or type unit header. */ |
4044 | ||
4045 | static sect_offset | |
4046 | read_abbrev_offset (struct dwarf2_section_info *section, | |
4047 | sect_offset offset) | |
4048 | { | |
4049 | bfd *abfd = section->asection->owner; | |
4050 | gdb_byte *info_ptr; | |
4051 | unsigned int length, initial_length_size, offset_size; | |
4052 | sect_offset abbrev_offset; | |
4053 | ||
4054 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); | |
4055 | info_ptr = section->buffer + offset.sect_off; | |
4056 | length = read_initial_length (abfd, info_ptr, &initial_length_size); | |
4057 | offset_size = initial_length_size == 4 ? 4 : 8; | |
4058 | info_ptr += initial_length_size + 2 /*version*/; | |
4059 | abbrev_offset.sect_off = read_offset_1 (abfd, info_ptr, offset_size); | |
4060 | return abbrev_offset; | |
4061 | } | |
4062 | ||
aaa75496 JB |
4063 | /* Allocate a new partial symtab for file named NAME and mark this new |
4064 | partial symtab as being an include of PST. */ | |
4065 | ||
4066 | static void | |
4067 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
4068 | struct objfile *objfile) | |
4069 | { | |
4070 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
4071 | ||
4072 | subpst->section_offsets = pst->section_offsets; | |
4073 | subpst->textlow = 0; | |
4074 | subpst->texthigh = 0; | |
4075 | ||
4076 | subpst->dependencies = (struct partial_symtab **) | |
4077 | obstack_alloc (&objfile->objfile_obstack, | |
4078 | sizeof (struct partial_symtab *)); | |
4079 | subpst->dependencies[0] = pst; | |
4080 | subpst->number_of_dependencies = 1; | |
4081 | ||
4082 | subpst->globals_offset = 0; | |
4083 | subpst->n_global_syms = 0; | |
4084 | subpst->statics_offset = 0; | |
4085 | subpst->n_static_syms = 0; | |
4086 | subpst->symtab = NULL; | |
4087 | subpst->read_symtab = pst->read_symtab; | |
4088 | subpst->readin = 0; | |
4089 | ||
4090 | /* No private part is necessary for include psymtabs. This property | |
4091 | can be used to differentiate between such include psymtabs and | |
10b3939b | 4092 | the regular ones. */ |
58a9656e | 4093 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
4094 | } |
4095 | ||
4096 | /* Read the Line Number Program data and extract the list of files | |
4097 | included by the source file represented by PST. Build an include | |
d85a05f0 | 4098 | partial symtab for each of these included files. */ |
aaa75496 JB |
4099 | |
4100 | static void | |
4101 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
dee91e82 DE |
4102 | struct die_info *die, |
4103 | struct partial_symtab *pst) | |
aaa75496 | 4104 | { |
d85a05f0 DJ |
4105 | struct line_header *lh = NULL; |
4106 | struct attribute *attr; | |
aaa75496 | 4107 | |
d85a05f0 DJ |
4108 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
4109 | if (attr) | |
3019eac3 | 4110 | lh = dwarf_decode_line_header (DW_UNSND (attr), cu); |
aaa75496 JB |
4111 | if (lh == NULL) |
4112 | return; /* No linetable, so no includes. */ | |
4113 | ||
c6da4cef | 4114 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
f3f5162e | 4115 | dwarf_decode_lines (lh, pst->dirname, cu, pst, 1); |
aaa75496 JB |
4116 | |
4117 | free_line_header (lh); | |
4118 | } | |
4119 | ||
348e048f | 4120 | static hashval_t |
52dc124a | 4121 | hash_signatured_type (const void *item) |
348e048f | 4122 | { |
52dc124a | 4123 | const struct signatured_type *sig_type = item; |
9a619af0 | 4124 | |
348e048f | 4125 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
52dc124a | 4126 | return sig_type->signature; |
348e048f DE |
4127 | } |
4128 | ||
4129 | static int | |
52dc124a | 4130 | eq_signatured_type (const void *item_lhs, const void *item_rhs) |
348e048f DE |
4131 | { |
4132 | const struct signatured_type *lhs = item_lhs; | |
4133 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 4134 | |
348e048f DE |
4135 | return lhs->signature == rhs->signature; |
4136 | } | |
4137 | ||
1fd400ff TT |
4138 | /* Allocate a hash table for signatured types. */ |
4139 | ||
4140 | static htab_t | |
673bfd45 | 4141 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
4142 | { |
4143 | return htab_create_alloc_ex (41, | |
52dc124a DE |
4144 | hash_signatured_type, |
4145 | eq_signatured_type, | |
1fd400ff TT |
4146 | NULL, |
4147 | &objfile->objfile_obstack, | |
4148 | hashtab_obstack_allocate, | |
4149 | dummy_obstack_deallocate); | |
4150 | } | |
4151 | ||
d467dd73 | 4152 | /* A helper function to add a signatured type CU to a table. */ |
1fd400ff TT |
4153 | |
4154 | static int | |
d467dd73 | 4155 | add_signatured_type_cu_to_table (void **slot, void *datum) |
1fd400ff TT |
4156 | { |
4157 | struct signatured_type *sigt = *slot; | |
b4dd5633 | 4158 | struct signatured_type ***datap = datum; |
1fd400ff | 4159 | |
b4dd5633 | 4160 | **datap = sigt; |
1fd400ff TT |
4161 | ++*datap; |
4162 | ||
4163 | return 1; | |
4164 | } | |
4165 | ||
3019eac3 | 4166 | /* Create the hash table of all entries in the .debug_types section. |
80626a55 DE |
4167 | DWO_FILE is a pointer to the DWO file for .debug_types.dwo, |
4168 | NULL otherwise. | |
4169 | Note: This function processes DWO files only, not DWP files. | |
3019eac3 DE |
4170 | The result is a pointer to the hash table or NULL if there are |
4171 | no types. */ | |
348e048f | 4172 | |
3019eac3 DE |
4173 | static htab_t |
4174 | create_debug_types_hash_table (struct dwo_file *dwo_file, | |
4175 | VEC (dwarf2_section_info_def) *types) | |
348e048f | 4176 | { |
3019eac3 | 4177 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
8b70b953 | 4178 | htab_t types_htab = NULL; |
8b70b953 TT |
4179 | int ix; |
4180 | struct dwarf2_section_info *section; | |
4bdcc0c1 | 4181 | struct dwarf2_section_info *abbrev_section; |
348e048f | 4182 | |
3019eac3 DE |
4183 | if (VEC_empty (dwarf2_section_info_def, types)) |
4184 | return NULL; | |
348e048f | 4185 | |
4bdcc0c1 DE |
4186 | abbrev_section = (dwo_file != NULL |
4187 | ? &dwo_file->sections.abbrev | |
4188 | : &dwarf2_per_objfile->abbrev); | |
4189 | ||
09406207 DE |
4190 | if (dwarf2_read_debug) |
4191 | fprintf_unfiltered (gdb_stdlog, "Reading .debug_types%s for %s:\n", | |
4192 | dwo_file ? ".dwo" : "", | |
4193 | bfd_get_filename (abbrev_section->asection->owner)); | |
4194 | ||
8b70b953 | 4195 | for (ix = 0; |
3019eac3 | 4196 | VEC_iterate (dwarf2_section_info_def, types, ix, section); |
8b70b953 TT |
4197 | ++ix) |
4198 | { | |
3019eac3 | 4199 | bfd *abfd; |
8b70b953 | 4200 | gdb_byte *info_ptr, *end_ptr; |
36586728 | 4201 | struct dwarf2_section_info *abbrev_section; |
348e048f | 4202 | |
8b70b953 TT |
4203 | dwarf2_read_section (objfile, section); |
4204 | info_ptr = section->buffer; | |
348e048f | 4205 | |
8b70b953 TT |
4206 | if (info_ptr == NULL) |
4207 | continue; | |
348e048f | 4208 | |
3019eac3 DE |
4209 | /* We can't set abfd until now because the section may be empty or |
4210 | not present, in which case section->asection will be NULL. */ | |
4211 | abfd = section->asection->owner; | |
4212 | ||
36586728 TT |
4213 | if (dwo_file) |
4214 | abbrev_section = &dwo_file->sections.abbrev; | |
4215 | else | |
4216 | abbrev_section = &dwarf2_per_objfile->abbrev; | |
4217 | ||
8b70b953 | 4218 | if (types_htab == NULL) |
3019eac3 DE |
4219 | { |
4220 | if (dwo_file) | |
4221 | types_htab = allocate_dwo_unit_table (objfile); | |
4222 | else | |
4223 | types_htab = allocate_signatured_type_table (objfile); | |
4224 | } | |
348e048f | 4225 | |
dee91e82 DE |
4226 | /* We don't use init_cutu_and_read_dies_simple, or some such, here |
4227 | because we don't need to read any dies: the signature is in the | |
4228 | header. */ | |
8b70b953 TT |
4229 | |
4230 | end_ptr = info_ptr + section->size; | |
4231 | while (info_ptr < end_ptr) | |
4232 | { | |
b64f50a1 | 4233 | sect_offset offset; |
3019eac3 | 4234 | cu_offset type_offset_in_tu; |
8b70b953 | 4235 | ULONGEST signature; |
52dc124a | 4236 | struct signatured_type *sig_type; |
3019eac3 | 4237 | struct dwo_unit *dwo_tu; |
8b70b953 TT |
4238 | void **slot; |
4239 | gdb_byte *ptr = info_ptr; | |
9ff913ba | 4240 | struct comp_unit_head header; |
dee91e82 | 4241 | unsigned int length; |
348e048f | 4242 | |
b64f50a1 | 4243 | offset.sect_off = ptr - section->buffer; |
348e048f | 4244 | |
8b70b953 | 4245 | /* We need to read the type's signature in order to build the hash |
9ff913ba | 4246 | table, but we don't need anything else just yet. */ |
348e048f | 4247 | |
4bdcc0c1 DE |
4248 | ptr = read_and_check_type_unit_head (&header, section, |
4249 | abbrev_section, ptr, | |
3019eac3 | 4250 | &signature, &type_offset_in_tu); |
6caca83c | 4251 | |
1ce1cefd | 4252 | length = get_cu_length (&header); |
dee91e82 | 4253 | |
6caca83c | 4254 | /* Skip dummy type units. */ |
dee91e82 DE |
4255 | if (ptr >= info_ptr + length |
4256 | || peek_abbrev_code (abfd, ptr) == 0) | |
6caca83c | 4257 | { |
1ce1cefd | 4258 | info_ptr += length; |
6caca83c CC |
4259 | continue; |
4260 | } | |
8b70b953 | 4261 | |
3019eac3 DE |
4262 | if (dwo_file) |
4263 | { | |
4264 | sig_type = NULL; | |
4265 | dwo_tu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
4266 | struct dwo_unit); | |
4267 | dwo_tu->dwo_file = dwo_file; | |
4268 | dwo_tu->signature = signature; | |
4269 | dwo_tu->type_offset_in_tu = type_offset_in_tu; | |
4270 | dwo_tu->info_or_types_section = section; | |
4271 | dwo_tu->offset = offset; | |
4272 | dwo_tu->length = length; | |
4273 | } | |
4274 | else | |
4275 | { | |
4276 | /* N.B.: type_offset is not usable if this type uses a DWO file. | |
4277 | The real type_offset is in the DWO file. */ | |
4278 | dwo_tu = NULL; | |
4279 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
4280 | struct signatured_type); | |
4281 | sig_type->signature = signature; | |
4282 | sig_type->type_offset_in_tu = type_offset_in_tu; | |
4283 | sig_type->per_cu.objfile = objfile; | |
4284 | sig_type->per_cu.is_debug_types = 1; | |
4285 | sig_type->per_cu.info_or_types_section = section; | |
4286 | sig_type->per_cu.offset = offset; | |
4287 | sig_type->per_cu.length = length; | |
4288 | } | |
8b70b953 | 4289 | |
3019eac3 DE |
4290 | slot = htab_find_slot (types_htab, |
4291 | dwo_file ? (void*) dwo_tu : (void *) sig_type, | |
4292 | INSERT); | |
8b70b953 TT |
4293 | gdb_assert (slot != NULL); |
4294 | if (*slot != NULL) | |
4295 | { | |
3019eac3 DE |
4296 | sect_offset dup_offset; |
4297 | ||
4298 | if (dwo_file) | |
4299 | { | |
4300 | const struct dwo_unit *dup_tu = *slot; | |
4301 | ||
4302 | dup_offset = dup_tu->offset; | |
4303 | } | |
4304 | else | |
4305 | { | |
4306 | const struct signatured_type *dup_tu = *slot; | |
4307 | ||
4308 | dup_offset = dup_tu->per_cu.offset; | |
4309 | } | |
b3c8eb43 | 4310 | |
8b70b953 TT |
4311 | complaint (&symfile_complaints, |
4312 | _("debug type entry at offset 0x%x is duplicate to the " | |
4313 | "entry at offset 0x%x, signature 0x%s"), | |
3019eac3 | 4314 | offset.sect_off, dup_offset.sect_off, |
8b70b953 | 4315 | phex (signature, sizeof (signature))); |
8b70b953 | 4316 | } |
3019eac3 | 4317 | *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type; |
348e048f | 4318 | |
09406207 | 4319 | if (dwarf2_read_debug) |
8b70b953 | 4320 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", |
b64f50a1 JK |
4321 | offset.sect_off, |
4322 | phex (signature, sizeof (signature))); | |
348e048f | 4323 | |
dee91e82 | 4324 | info_ptr += length; |
8b70b953 | 4325 | } |
348e048f DE |
4326 | } |
4327 | ||
3019eac3 DE |
4328 | return types_htab; |
4329 | } | |
4330 | ||
4331 | /* Create the hash table of all entries in the .debug_types section, | |
4332 | and initialize all_type_units. | |
4333 | The result is zero if there is an error (e.g. missing .debug_types section), | |
4334 | otherwise non-zero. */ | |
4335 | ||
4336 | static int | |
4337 | create_all_type_units (struct objfile *objfile) | |
4338 | { | |
4339 | htab_t types_htab; | |
b4dd5633 | 4340 | struct signatured_type **iter; |
3019eac3 DE |
4341 | |
4342 | types_htab = create_debug_types_hash_table (NULL, dwarf2_per_objfile->types); | |
4343 | if (types_htab == NULL) | |
4344 | { | |
4345 | dwarf2_per_objfile->signatured_types = NULL; | |
4346 | return 0; | |
4347 | } | |
4348 | ||
348e048f DE |
4349 | dwarf2_per_objfile->signatured_types = types_htab; |
4350 | ||
d467dd73 DE |
4351 | dwarf2_per_objfile->n_type_units = htab_elements (types_htab); |
4352 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 4353 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 4354 | dwarf2_per_objfile->n_type_units |
b4dd5633 | 4355 | * sizeof (struct signatured_type *)); |
d467dd73 DE |
4356 | iter = &dwarf2_per_objfile->all_type_units[0]; |
4357 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); | |
4358 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] | |
4359 | == dwarf2_per_objfile->n_type_units); | |
1fd400ff | 4360 | |
348e048f DE |
4361 | return 1; |
4362 | } | |
4363 | ||
380bca97 | 4364 | /* Lookup a signature based type for DW_FORM_ref_sig8. |
e319fa28 | 4365 | Returns NULL if signature SIG is not present in the table. */ |
348e048f DE |
4366 | |
4367 | static struct signatured_type * | |
e319fa28 | 4368 | lookup_signatured_type (ULONGEST sig) |
348e048f DE |
4369 | { |
4370 | struct signatured_type find_entry, *entry; | |
4371 | ||
4372 | if (dwarf2_per_objfile->signatured_types == NULL) | |
4373 | { | |
4374 | complaint (&symfile_complaints, | |
55f1336d | 4375 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
dcc07052 | 4376 | return NULL; |
348e048f DE |
4377 | } |
4378 | ||
4379 | find_entry.signature = sig; | |
4380 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
4381 | return entry; | |
4382 | } | |
42e7ad6c DE |
4383 | \f |
4384 | /* Low level DIE reading support. */ | |
348e048f | 4385 | |
d85a05f0 DJ |
4386 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
4387 | ||
4388 | static void | |
4389 | init_cu_die_reader (struct die_reader_specs *reader, | |
dee91e82 | 4390 | struct dwarf2_cu *cu, |
3019eac3 DE |
4391 | struct dwarf2_section_info *section, |
4392 | struct dwo_file *dwo_file) | |
d85a05f0 | 4393 | { |
fceca515 | 4394 | gdb_assert (section->readin && section->buffer != NULL); |
dee91e82 | 4395 | reader->abfd = section->asection->owner; |
d85a05f0 | 4396 | reader->cu = cu; |
3019eac3 | 4397 | reader->dwo_file = dwo_file; |
dee91e82 DE |
4398 | reader->die_section = section; |
4399 | reader->buffer = section->buffer; | |
f664829e | 4400 | reader->buffer_end = section->buffer + section->size; |
d85a05f0 DJ |
4401 | } |
4402 | ||
fd820528 | 4403 | /* Initialize a CU (or TU) and read its DIEs. |
3019eac3 | 4404 | If the CU defers to a DWO file, read the DWO file as well. |
dee91e82 | 4405 | |
f4dc4d17 DE |
4406 | ABBREV_TABLE, if non-NULL, is the abbreviation table to use. |
4407 | Otherwise the table specified in the comp unit header is read in and used. | |
4408 | This is an optimization for when we already have the abbrev table. | |
4409 | ||
dee91e82 DE |
4410 | If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it. |
4411 | Otherwise, a new CU is allocated with xmalloc. | |
4412 | ||
4413 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to | |
4414 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. | |
4415 | ||
4416 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
fd820528 | 4417 | linker) then DIE_READER_FUNC will not get called. */ |
aaa75496 | 4418 | |
70221824 | 4419 | static void |
fd820528 | 4420 | init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu, |
f4dc4d17 | 4421 | struct abbrev_table *abbrev_table, |
fd820528 DE |
4422 | int use_existing_cu, int keep, |
4423 | die_reader_func_ftype *die_reader_func, | |
4424 | void *data) | |
c906108c | 4425 | { |
dee91e82 | 4426 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
3019eac3 DE |
4427 | struct dwarf2_section_info *section = this_cu->info_or_types_section; |
4428 | bfd *abfd = section->asection->owner; | |
dee91e82 DE |
4429 | struct dwarf2_cu *cu; |
4430 | gdb_byte *begin_info_ptr, *info_ptr; | |
4431 | struct die_reader_specs reader; | |
d85a05f0 | 4432 | struct die_info *comp_unit_die; |
dee91e82 | 4433 | int has_children; |
d85a05f0 | 4434 | struct attribute *attr; |
dee91e82 DE |
4435 | struct cleanup *cleanups, *free_cu_cleanup = NULL; |
4436 | struct signatured_type *sig_type = NULL; | |
4bdcc0c1 | 4437 | struct dwarf2_section_info *abbrev_section; |
42e7ad6c DE |
4438 | /* Non-zero if CU currently points to a DWO file and we need to |
4439 | reread it. When this happens we need to reread the skeleton die | |
4440 | before we can reread the DWO file. */ | |
4441 | int rereading_dwo_cu = 0; | |
c906108c | 4442 | |
09406207 DE |
4443 | if (dwarf2_die_debug) |
4444 | fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n", | |
4445 | this_cu->is_debug_types ? "type" : "comp", | |
4446 | this_cu->offset.sect_off); | |
4447 | ||
dee91e82 DE |
4448 | if (use_existing_cu) |
4449 | gdb_assert (keep); | |
23745b47 | 4450 | |
dee91e82 DE |
4451 | cleanups = make_cleanup (null_cleanup, NULL); |
4452 | ||
4453 | /* This is cheap if the section is already read in. */ | |
4454 | dwarf2_read_section (objfile, section); | |
4455 | ||
4456 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; | |
36586728 TT |
4457 | |
4458 | abbrev_section = get_abbrev_section_for_cu (this_cu); | |
dee91e82 DE |
4459 | |
4460 | if (use_existing_cu && this_cu->cu != NULL) | |
4461 | { | |
4462 | cu = this_cu->cu; | |
42e7ad6c DE |
4463 | |
4464 | /* If this CU is from a DWO file we need to start over, we need to | |
4465 | refetch the attributes from the skeleton CU. | |
4466 | This could be optimized by retrieving those attributes from when we | |
4467 | were here the first time: the previous comp_unit_die was stored in | |
4468 | comp_unit_obstack. But there's no data yet that we need this | |
4469 | optimization. */ | |
4470 | if (cu->dwo_unit != NULL) | |
4471 | rereading_dwo_cu = 1; | |
dee91e82 DE |
4472 | } |
4473 | else | |
4474 | { | |
4475 | /* If !use_existing_cu, this_cu->cu must be NULL. */ | |
4476 | gdb_assert (this_cu->cu == NULL); | |
4477 | ||
4478 | cu = xmalloc (sizeof (*cu)); | |
4479 | init_one_comp_unit (cu, this_cu); | |
4480 | ||
4481 | /* If an error occurs while loading, release our storage. */ | |
4482 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); | |
42e7ad6c | 4483 | } |
dee91e82 | 4484 | |
42e7ad6c DE |
4485 | if (cu->header.first_die_offset.cu_off != 0 && ! rereading_dwo_cu) |
4486 | { | |
4487 | /* We already have the header, there's no need to read it in again. */ | |
4488 | info_ptr += cu->header.first_die_offset.cu_off; | |
4489 | } | |
4490 | else | |
4491 | { | |
3019eac3 | 4492 | if (this_cu->is_debug_types) |
dee91e82 DE |
4493 | { |
4494 | ULONGEST signature; | |
42e7ad6c | 4495 | cu_offset type_offset_in_tu; |
dee91e82 | 4496 | |
4bdcc0c1 DE |
4497 | info_ptr = read_and_check_type_unit_head (&cu->header, section, |
4498 | abbrev_section, info_ptr, | |
42e7ad6c DE |
4499 | &signature, |
4500 | &type_offset_in_tu); | |
dee91e82 | 4501 | |
42e7ad6c DE |
4502 | /* Since per_cu is the first member of struct signatured_type, |
4503 | we can go from a pointer to one to a pointer to the other. */ | |
4504 | sig_type = (struct signatured_type *) this_cu; | |
4505 | gdb_assert (sig_type->signature == signature); | |
4506 | gdb_assert (sig_type->type_offset_in_tu.cu_off | |
4507 | == type_offset_in_tu.cu_off); | |
dee91e82 DE |
4508 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); |
4509 | ||
42e7ad6c DE |
4510 | /* LENGTH has not been set yet for type units if we're |
4511 | using .gdb_index. */ | |
1ce1cefd | 4512 | this_cu->length = get_cu_length (&cu->header); |
3019eac3 DE |
4513 | |
4514 | /* Establish the type offset that can be used to lookup the type. */ | |
4515 | sig_type->type_offset_in_section.sect_off = | |
4516 | this_cu->offset.sect_off + sig_type->type_offset_in_tu.cu_off; | |
dee91e82 DE |
4517 | } |
4518 | else | |
4519 | { | |
4bdcc0c1 DE |
4520 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, |
4521 | abbrev_section, | |
4522 | info_ptr, 0); | |
dee91e82 DE |
4523 | |
4524 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); | |
1ce1cefd | 4525 | gdb_assert (this_cu->length == get_cu_length (&cu->header)); |
dee91e82 DE |
4526 | } |
4527 | } | |
10b3939b | 4528 | |
6caca83c | 4529 | /* Skip dummy compilation units. */ |
dee91e82 | 4530 | if (info_ptr >= begin_info_ptr + this_cu->length |
6caca83c CC |
4531 | || peek_abbrev_code (abfd, info_ptr) == 0) |
4532 | { | |
dee91e82 | 4533 | do_cleanups (cleanups); |
21b2bd31 | 4534 | return; |
6caca83c CC |
4535 | } |
4536 | ||
433df2d4 DE |
4537 | /* If we don't have them yet, read the abbrevs for this compilation unit. |
4538 | And if we need to read them now, make sure they're freed when we're | |
42e7ad6c DE |
4539 | done. Note that it's important that if the CU had an abbrev table |
4540 | on entry we don't free it when we're done: Somewhere up the call stack | |
4541 | it may be in use. */ | |
f4dc4d17 DE |
4542 | if (abbrev_table != NULL) |
4543 | { | |
4544 | gdb_assert (cu->abbrev_table == NULL); | |
4545 | gdb_assert (cu->header.abbrev_offset.sect_off | |
4546 | == abbrev_table->offset.sect_off); | |
4547 | cu->abbrev_table = abbrev_table; | |
4548 | } | |
4549 | else if (cu->abbrev_table == NULL) | |
dee91e82 | 4550 | { |
4bdcc0c1 | 4551 | dwarf2_read_abbrevs (cu, abbrev_section); |
dee91e82 DE |
4552 | make_cleanup (dwarf2_free_abbrev_table, cu); |
4553 | } | |
42e7ad6c DE |
4554 | else if (rereading_dwo_cu) |
4555 | { | |
4556 | dwarf2_free_abbrev_table (cu); | |
4557 | dwarf2_read_abbrevs (cu, abbrev_section); | |
4558 | } | |
af703f96 | 4559 | |
dee91e82 | 4560 | /* Read the top level CU/TU die. */ |
3019eac3 | 4561 | init_cu_die_reader (&reader, cu, section, NULL); |
dee91e82 | 4562 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
93311388 | 4563 | |
3019eac3 DE |
4564 | /* If we have a DWO stub, process it and then read in the DWO file. |
4565 | Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains | |
4566 | a DWO CU, that this test will fail. */ | |
4567 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu); | |
4568 | if (attr) | |
4569 | { | |
15d034d0 | 4570 | const char *dwo_name = DW_STRING (attr); |
42e7ad6c | 4571 | const char *comp_dir_string; |
3019eac3 DE |
4572 | struct dwo_unit *dwo_unit; |
4573 | ULONGEST signature; /* Or dwo_id. */ | |
42e7ad6c | 4574 | struct attribute *comp_dir, *stmt_list, *low_pc, *high_pc, *ranges; |
3019eac3 | 4575 | int i,num_extra_attrs; |
4bdcc0c1 | 4576 | struct dwarf2_section_info *dwo_abbrev_section; |
3019eac3 DE |
4577 | |
4578 | if (has_children) | |
4579 | error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name" | |
4580 | " has children (offset 0x%x) [in module %s]"), | |
4581 | this_cu->offset.sect_off, bfd_get_filename (abfd)); | |
4582 | ||
4583 | /* These attributes aren't processed until later: | |
4584 | DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges. | |
4585 | However, the attribute is found in the stub which we won't have later. | |
4586 | In order to not impose this complication on the rest of the code, | |
4587 | we read them here and copy them to the DWO CU/TU die. */ | |
3019eac3 DE |
4588 | |
4589 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the | |
4590 | DWO file. */ | |
42e7ad6c | 4591 | stmt_list = NULL; |
3019eac3 DE |
4592 | if (! this_cu->is_debug_types) |
4593 | stmt_list = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); | |
4594 | low_pc = dwarf2_attr (comp_unit_die, DW_AT_low_pc, cu); | |
4595 | high_pc = dwarf2_attr (comp_unit_die, DW_AT_high_pc, cu); | |
4596 | ranges = dwarf2_attr (comp_unit_die, DW_AT_ranges, cu); | |
42e7ad6c | 4597 | comp_dir = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu); |
3019eac3 DE |
4598 | |
4599 | /* There should be a DW_AT_addr_base attribute here (if needed). | |
4600 | We need the value before we can process DW_FORM_GNU_addr_index. */ | |
4601 | cu->addr_base = 0; | |
3019eac3 DE |
4602 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_addr_base, cu); |
4603 | if (attr) | |
2e3cf129 DE |
4604 | cu->addr_base = DW_UNSND (attr); |
4605 | ||
4606 | /* There should be a DW_AT_ranges_base attribute here (if needed). | |
4607 | We need the value before we can process DW_AT_ranges. */ | |
4608 | cu->ranges_base = 0; | |
4609 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_ranges_base, cu); | |
4610 | if (attr) | |
4611 | cu->ranges_base = DW_UNSND (attr); | |
3019eac3 DE |
4612 | |
4613 | if (this_cu->is_debug_types) | |
4614 | { | |
4615 | gdb_assert (sig_type != NULL); | |
4616 | signature = sig_type->signature; | |
4617 | } | |
4618 | else | |
4619 | { | |
4620 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); | |
4621 | if (! attr) | |
4622 | error (_("Dwarf Error: missing dwo_id [in module %s]"), | |
4623 | dwo_name); | |
4624 | signature = DW_UNSND (attr); | |
4625 | } | |
4626 | ||
4627 | /* We may need the comp_dir in order to find the DWO file. */ | |
42e7ad6c DE |
4628 | comp_dir_string = NULL; |
4629 | if (comp_dir) | |
4630 | comp_dir_string = DW_STRING (comp_dir); | |
3019eac3 DE |
4631 | |
4632 | if (this_cu->is_debug_types) | |
42e7ad6c | 4633 | dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir_string); |
3019eac3 | 4634 | else |
42e7ad6c | 4635 | dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir_string, |
3019eac3 DE |
4636 | signature); |
4637 | ||
4638 | if (dwo_unit == NULL) | |
4639 | { | |
4640 | error (_("Dwarf Error: CU at offset 0x%x references unknown DWO" | |
4641 | " with ID %s [in module %s]"), | |
4642 | this_cu->offset.sect_off, | |
4643 | phex (signature, sizeof (signature)), | |
4644 | objfile->name); | |
4645 | } | |
4646 | ||
4647 | /* Set up for reading the DWO CU/TU. */ | |
4648 | cu->dwo_unit = dwo_unit; | |
4649 | section = dwo_unit->info_or_types_section; | |
80626a55 | 4650 | dwarf2_read_section (objfile, section); |
3019eac3 | 4651 | begin_info_ptr = info_ptr = section->buffer + dwo_unit->offset.sect_off; |
4bdcc0c1 | 4652 | dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev; |
3019eac3 DE |
4653 | init_cu_die_reader (&reader, cu, section, dwo_unit->dwo_file); |
4654 | ||
4655 | if (this_cu->is_debug_types) | |
4656 | { | |
4657 | ULONGEST signature; | |
80626a55 | 4658 | cu_offset type_offset_in_tu; |
3019eac3 | 4659 | |
4bdcc0c1 DE |
4660 | info_ptr = read_and_check_type_unit_head (&cu->header, section, |
4661 | dwo_abbrev_section, | |
4662 | info_ptr, | |
80626a55 DE |
4663 | &signature, |
4664 | &type_offset_in_tu); | |
3019eac3 DE |
4665 | gdb_assert (sig_type->signature == signature); |
4666 | gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off); | |
80626a55 DE |
4667 | /* For DWOs coming from DWP files, we don't know the CU length |
4668 | nor the type's offset in the TU until now. */ | |
4669 | dwo_unit->length = get_cu_length (&cu->header); | |
4670 | dwo_unit->type_offset_in_tu = type_offset_in_tu; | |
3019eac3 DE |
4671 | |
4672 | /* Establish the type offset that can be used to lookup the type. | |
4673 | For DWO files, we don't know it until now. */ | |
4674 | sig_type->type_offset_in_section.sect_off = | |
4675 | dwo_unit->offset.sect_off + dwo_unit->type_offset_in_tu.cu_off; | |
4676 | } | |
4677 | else | |
4678 | { | |
4bdcc0c1 DE |
4679 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, |
4680 | dwo_abbrev_section, | |
4681 | info_ptr, 0); | |
3019eac3 | 4682 | gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off); |
80626a55 DE |
4683 | /* For DWOs coming from DWP files, we don't know the CU length |
4684 | until now. */ | |
4685 | dwo_unit->length = get_cu_length (&cu->header); | |
3019eac3 DE |
4686 | } |
4687 | ||
4688 | /* Discard the original CU's abbrev table, and read the DWO's. */ | |
f4dc4d17 DE |
4689 | if (abbrev_table == NULL) |
4690 | { | |
4691 | dwarf2_free_abbrev_table (cu); | |
4692 | dwarf2_read_abbrevs (cu, dwo_abbrev_section); | |
4693 | } | |
4694 | else | |
4695 | { | |
4696 | dwarf2_read_abbrevs (cu, dwo_abbrev_section); | |
4697 | make_cleanup (dwarf2_free_abbrev_table, cu); | |
4698 | } | |
3019eac3 DE |
4699 | |
4700 | /* Read in the die, but leave space to copy over the attributes | |
4701 | from the stub. This has the benefit of simplifying the rest of | |
4702 | the code - all the real work is done here. */ | |
4703 | num_extra_attrs = ((stmt_list != NULL) | |
4704 | + (low_pc != NULL) | |
4705 | + (high_pc != NULL) | |
42e7ad6c DE |
4706 | + (ranges != NULL) |
4707 | + (comp_dir != NULL)); | |
3019eac3 DE |
4708 | info_ptr = read_full_die_1 (&reader, &comp_unit_die, info_ptr, |
4709 | &has_children, num_extra_attrs); | |
4710 | ||
4711 | /* Copy over the attributes from the stub to the DWO die. */ | |
4712 | i = comp_unit_die->num_attrs; | |
4713 | if (stmt_list != NULL) | |
4714 | comp_unit_die->attrs[i++] = *stmt_list; | |
4715 | if (low_pc != NULL) | |
4716 | comp_unit_die->attrs[i++] = *low_pc; | |
4717 | if (high_pc != NULL) | |
4718 | comp_unit_die->attrs[i++] = *high_pc; | |
4719 | if (ranges != NULL) | |
4720 | comp_unit_die->attrs[i++] = *ranges; | |
42e7ad6c DE |
4721 | if (comp_dir != NULL) |
4722 | comp_unit_die->attrs[i++] = *comp_dir; | |
3019eac3 DE |
4723 | comp_unit_die->num_attrs += num_extra_attrs; |
4724 | ||
4725 | /* Skip dummy compilation units. */ | |
4726 | if (info_ptr >= begin_info_ptr + dwo_unit->length | |
4727 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
4728 | { | |
4729 | do_cleanups (cleanups); | |
4730 | return; | |
4731 | } | |
4732 | } | |
4733 | ||
dee91e82 DE |
4734 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); |
4735 | ||
4736 | if (free_cu_cleanup != NULL) | |
348e048f | 4737 | { |
dee91e82 DE |
4738 | if (keep) |
4739 | { | |
4740 | /* We've successfully allocated this compilation unit. Let our | |
4741 | caller clean it up when finished with it. */ | |
4742 | discard_cleanups (free_cu_cleanup); | |
4743 | ||
4744 | /* We can only discard free_cu_cleanup and all subsequent cleanups. | |
4745 | So we have to manually free the abbrev table. */ | |
4746 | dwarf2_free_abbrev_table (cu); | |
4747 | ||
4748 | /* Link this CU into read_in_chain. */ | |
4749 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4750 | dwarf2_per_objfile->read_in_chain = this_cu; | |
4751 | } | |
4752 | else | |
4753 | do_cleanups (free_cu_cleanup); | |
348e048f | 4754 | } |
dee91e82 DE |
4755 | |
4756 | do_cleanups (cleanups); | |
4757 | } | |
4758 | ||
3019eac3 DE |
4759 | /* Read CU/TU THIS_CU in section SECTION, |
4760 | but do not follow DW_AT_GNU_dwo_name if present. | |
80626a55 DE |
4761 | DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed |
4762 | to have already done the lookup to find the DWO/DWP file). | |
dee91e82 DE |
4763 | |
4764 | The caller is required to fill in THIS_CU->section, THIS_CU->offset, and | |
3019eac3 | 4765 | THIS_CU->is_debug_types, but nothing else. |
dee91e82 DE |
4766 | |
4767 | We fill in THIS_CU->length. | |
4768 | ||
4769 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
4770 | linker) then DIE_READER_FUNC will not get called. | |
4771 | ||
4772 | THIS_CU->cu is always freed when done. | |
3019eac3 DE |
4773 | This is done in order to not leave THIS_CU->cu in a state where we have |
4774 | to care whether it refers to the "main" CU or the DWO CU. */ | |
dee91e82 DE |
4775 | |
4776 | static void | |
4777 | init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu, | |
4778 | struct dwarf2_section_info *abbrev_section, | |
3019eac3 | 4779 | struct dwo_file *dwo_file, |
dee91e82 DE |
4780 | die_reader_func_ftype *die_reader_func, |
4781 | void *data) | |
4782 | { | |
4783 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
3019eac3 DE |
4784 | struct dwarf2_section_info *section = this_cu->info_or_types_section; |
4785 | bfd *abfd = section->asection->owner; | |
dee91e82 DE |
4786 | struct dwarf2_cu cu; |
4787 | gdb_byte *begin_info_ptr, *info_ptr; | |
4788 | struct die_reader_specs reader; | |
4789 | struct cleanup *cleanups; | |
4790 | struct die_info *comp_unit_die; | |
4791 | int has_children; | |
4792 | ||
09406207 DE |
4793 | if (dwarf2_die_debug) |
4794 | fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n", | |
4795 | this_cu->is_debug_types ? "type" : "comp", | |
4796 | this_cu->offset.sect_off); | |
4797 | ||
dee91e82 DE |
4798 | gdb_assert (this_cu->cu == NULL); |
4799 | ||
dee91e82 DE |
4800 | /* This is cheap if the section is already read in. */ |
4801 | dwarf2_read_section (objfile, section); | |
4802 | ||
4803 | init_one_comp_unit (&cu, this_cu); | |
4804 | ||
4805 | cleanups = make_cleanup (free_stack_comp_unit, &cu); | |
4806 | ||
4807 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; | |
4bdcc0c1 DE |
4808 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, |
4809 | abbrev_section, info_ptr, | |
3019eac3 | 4810 | this_cu->is_debug_types); |
dee91e82 | 4811 | |
1ce1cefd | 4812 | this_cu->length = get_cu_length (&cu.header); |
dee91e82 DE |
4813 | |
4814 | /* Skip dummy compilation units. */ | |
4815 | if (info_ptr >= begin_info_ptr + this_cu->length | |
4816 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
c906108c | 4817 | { |
dee91e82 | 4818 | do_cleanups (cleanups); |
21b2bd31 | 4819 | return; |
93311388 | 4820 | } |
72bf9492 | 4821 | |
dee91e82 DE |
4822 | dwarf2_read_abbrevs (&cu, abbrev_section); |
4823 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
4824 | ||
3019eac3 | 4825 | init_cu_die_reader (&reader, &cu, section, dwo_file); |
dee91e82 DE |
4826 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
4827 | ||
4828 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); | |
4829 | ||
4830 | do_cleanups (cleanups); | |
4831 | } | |
4832 | ||
3019eac3 DE |
4833 | /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and |
4834 | does not lookup the specified DWO file. | |
4835 | This cannot be used to read DWO files. | |
dee91e82 DE |
4836 | |
4837 | THIS_CU->cu is always freed when done. | |
3019eac3 DE |
4838 | This is done in order to not leave THIS_CU->cu in a state where we have |
4839 | to care whether it refers to the "main" CU or the DWO CU. | |
4840 | We can revisit this if the data shows there's a performance issue. */ | |
dee91e82 DE |
4841 | |
4842 | static void | |
4843 | init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu, | |
4844 | die_reader_func_ftype *die_reader_func, | |
4845 | void *data) | |
4846 | { | |
4847 | init_cutu_and_read_dies_no_follow (this_cu, | |
36586728 | 4848 | get_abbrev_section_for_cu (this_cu), |
3019eac3 | 4849 | NULL, |
dee91e82 DE |
4850 | die_reader_func, data); |
4851 | } | |
4852 | ||
f4dc4d17 DE |
4853 | /* Create a psymtab named NAME and assign it to PER_CU. |
4854 | ||
4855 | The caller must fill in the following details: | |
4856 | dirname, textlow, texthigh. */ | |
4857 | ||
4858 | static struct partial_symtab * | |
4859 | create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name) | |
4860 | { | |
4861 | struct objfile *objfile = per_cu->objfile; | |
4862 | struct partial_symtab *pst; | |
4863 | ||
4864 | pst = start_psymtab_common (objfile, objfile->section_offsets, | |
4865 | name, 0, | |
4866 | objfile->global_psymbols.next, | |
4867 | objfile->static_psymbols.next); | |
4868 | ||
4869 | pst->psymtabs_addrmap_supported = 1; | |
4870 | ||
4871 | /* This is the glue that links PST into GDB's symbol API. */ | |
4872 | pst->read_symtab_private = per_cu; | |
257e7a09 | 4873 | pst->read_symtab = dwarf2_read_symtab; |
f4dc4d17 DE |
4874 | per_cu->v.psymtab = pst; |
4875 | ||
4876 | return pst; | |
4877 | } | |
4878 | ||
dee91e82 DE |
4879 | /* die_reader_func for process_psymtab_comp_unit. */ |
4880 | ||
4881 | static void | |
4882 | process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, | |
4883 | gdb_byte *info_ptr, | |
4884 | struct die_info *comp_unit_die, | |
4885 | int has_children, | |
4886 | void *data) | |
4887 | { | |
4888 | struct dwarf2_cu *cu = reader->cu; | |
4889 | struct objfile *objfile = cu->objfile; | |
4890 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; | |
dee91e82 DE |
4891 | struct attribute *attr; |
4892 | CORE_ADDR baseaddr; | |
4893 | CORE_ADDR best_lowpc = 0, best_highpc = 0; | |
4894 | struct partial_symtab *pst; | |
4895 | int has_pc_info; | |
4896 | const char *filename; | |
95554aad | 4897 | int *want_partial_unit_ptr = data; |
dee91e82 | 4898 | |
95554aad TT |
4899 | if (comp_unit_die->tag == DW_TAG_partial_unit |
4900 | && (want_partial_unit_ptr == NULL | |
4901 | || !*want_partial_unit_ptr)) | |
dee91e82 DE |
4902 | return; |
4903 | ||
f4dc4d17 DE |
4904 | gdb_assert (! per_cu->is_debug_types); |
4905 | ||
95554aad | 4906 | prepare_one_comp_unit (cu, comp_unit_die, language_minimal); |
dee91e82 DE |
4907 | |
4908 | cu->list_in_scope = &file_symbols; | |
c906108c | 4909 | |
93311388 | 4910 | /* Allocate a new partial symbol table structure. */ |
dee91e82 | 4911 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu); |
3e2a0cee TT |
4912 | if (attr == NULL || !DW_STRING (attr)) |
4913 | filename = ""; | |
4914 | else | |
4915 | filename = DW_STRING (attr); | |
72bf9492 | 4916 | |
f4dc4d17 DE |
4917 | pst = create_partial_symtab (per_cu, filename); |
4918 | ||
4919 | /* This must be done before calling dwarf2_build_include_psymtabs. */ | |
dee91e82 | 4920 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu); |
d85a05f0 DJ |
4921 | if (attr != NULL) |
4922 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 4923 | |
93311388 | 4924 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 4925 | |
dee91e82 | 4926 | dwarf2_find_base_address (comp_unit_die, cu); |
d85a05f0 | 4927 | |
93311388 DE |
4928 | /* Possibly set the default values of LOWPC and HIGHPC from |
4929 | `DW_AT_ranges'. */ | |
d85a05f0 | 4930 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
dee91e82 | 4931 | &best_highpc, cu, pst); |
d85a05f0 | 4932 | if (has_pc_info == 1 && best_lowpc < best_highpc) |
93311388 DE |
4933 | /* Store the contiguous range if it is not empty; it can be empty for |
4934 | CUs with no code. */ | |
4935 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
4936 | best_lowpc + baseaddr, |
4937 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
4938 | |
4939 | /* Check if comp unit has_children. | |
4940 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 4941 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 4942 | if (has_children) |
93311388 DE |
4943 | { |
4944 | struct partial_die_info *first_die; | |
4945 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 4946 | |
93311388 DE |
4947 | lowpc = ((CORE_ADDR) -1); |
4948 | highpc = ((CORE_ADDR) 0); | |
c906108c | 4949 | |
dee91e82 | 4950 | first_die = load_partial_dies (reader, info_ptr, 1); |
c906108c | 4951 | |
93311388 | 4952 | scan_partial_symbols (first_die, &lowpc, &highpc, |
dee91e82 | 4953 | ! has_pc_info, cu); |
57c22c6c | 4954 | |
93311388 DE |
4955 | /* If we didn't find a lowpc, set it to highpc to avoid |
4956 | complaints from `maint check'. */ | |
4957 | if (lowpc == ((CORE_ADDR) -1)) | |
4958 | lowpc = highpc; | |
10b3939b | 4959 | |
93311388 DE |
4960 | /* If the compilation unit didn't have an explicit address range, |
4961 | then use the information extracted from its child dies. */ | |
d85a05f0 | 4962 | if (! has_pc_info) |
93311388 | 4963 | { |
d85a05f0 DJ |
4964 | best_lowpc = lowpc; |
4965 | best_highpc = highpc; | |
93311388 DE |
4966 | } |
4967 | } | |
d85a05f0 DJ |
4968 | pst->textlow = best_lowpc + baseaddr; |
4969 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 4970 | |
93311388 DE |
4971 | pst->n_global_syms = objfile->global_psymbols.next - |
4972 | (objfile->global_psymbols.list + pst->globals_offset); | |
4973 | pst->n_static_syms = objfile->static_psymbols.next - | |
4974 | (objfile->static_psymbols.list + pst->statics_offset); | |
5c80ed9d | 4975 | sort_pst_symbols (objfile, pst); |
c906108c | 4976 | |
796a7ff8 | 4977 | if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs)) |
95554aad TT |
4978 | { |
4979 | int i; | |
796a7ff8 | 4980 | int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); |
95554aad TT |
4981 | struct dwarf2_per_cu_data *iter; |
4982 | ||
4983 | /* Fill in 'dependencies' here; we fill in 'users' in a | |
4984 | post-pass. */ | |
4985 | pst->number_of_dependencies = len; | |
4986 | pst->dependencies = obstack_alloc (&objfile->objfile_obstack, | |
4987 | len * sizeof (struct symtab *)); | |
4988 | for (i = 0; | |
796a7ff8 | 4989 | VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, |
95554aad TT |
4990 | i, iter); |
4991 | ++i) | |
4992 | pst->dependencies[i] = iter->v.psymtab; | |
4993 | ||
796a7ff8 | 4994 | VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); |
95554aad TT |
4995 | } |
4996 | ||
f4dc4d17 DE |
4997 | /* Get the list of files included in the current compilation unit, |
4998 | and build a psymtab for each of them. */ | |
4999 | dwarf2_build_include_psymtabs (cu, comp_unit_die, pst); | |
09406207 DE |
5000 | |
5001 | if (dwarf2_read_debug) | |
5002 | { | |
5003 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
5004 | ||
5005 | fprintf_unfiltered (gdb_stdlog, | |
844226d6 | 5006 | "Psymtab for %s unit @0x%x: %s - %s" |
09406207 DE |
5007 | ", %d global, %d static syms\n", |
5008 | per_cu->is_debug_types ? "type" : "comp", | |
5009 | per_cu->offset.sect_off, | |
5010 | paddress (gdbarch, pst->textlow), | |
5011 | paddress (gdbarch, pst->texthigh), | |
5012 | pst->n_global_syms, pst->n_static_syms); | |
5013 | } | |
dee91e82 | 5014 | } |
ae038cb0 | 5015 | |
dee91e82 DE |
5016 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. |
5017 | Process compilation unit THIS_CU for a psymtab. */ | |
5018 | ||
5019 | static void | |
95554aad TT |
5020 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, |
5021 | int want_partial_unit) | |
dee91e82 DE |
5022 | { |
5023 | /* If this compilation unit was already read in, free the | |
5024 | cached copy in order to read it in again. This is | |
5025 | necessary because we skipped some symbols when we first | |
5026 | read in the compilation unit (see load_partial_dies). | |
5027 | This problem could be avoided, but the benefit is unclear. */ | |
5028 | if (this_cu->cu != NULL) | |
5029 | free_one_cached_comp_unit (this_cu); | |
5030 | ||
3019eac3 | 5031 | gdb_assert (! this_cu->is_debug_types); |
f4dc4d17 DE |
5032 | init_cutu_and_read_dies (this_cu, NULL, 0, 0, |
5033 | process_psymtab_comp_unit_reader, | |
95554aad | 5034 | &want_partial_unit); |
dee91e82 DE |
5035 | |
5036 | /* Age out any secondary CUs. */ | |
5037 | age_cached_comp_units (); | |
93311388 | 5038 | } |
ff013f42 | 5039 | |
f4dc4d17 DE |
5040 | static hashval_t |
5041 | hash_type_unit_group (const void *item) | |
5042 | { | |
094b34ac | 5043 | const struct type_unit_group *tu_group = item; |
f4dc4d17 | 5044 | |
094b34ac | 5045 | return hash_stmt_list_entry (&tu_group->hash); |
f4dc4d17 | 5046 | } |
348e048f DE |
5047 | |
5048 | static int | |
f4dc4d17 | 5049 | eq_type_unit_group (const void *item_lhs, const void *item_rhs) |
348e048f | 5050 | { |
f4dc4d17 DE |
5051 | const struct type_unit_group *lhs = item_lhs; |
5052 | const struct type_unit_group *rhs = item_rhs; | |
348e048f | 5053 | |
094b34ac | 5054 | return eq_stmt_list_entry (&lhs->hash, &rhs->hash); |
f4dc4d17 | 5055 | } |
348e048f | 5056 | |
f4dc4d17 DE |
5057 | /* Allocate a hash table for type unit groups. */ |
5058 | ||
5059 | static htab_t | |
5060 | allocate_type_unit_groups_table (void) | |
5061 | { | |
5062 | return htab_create_alloc_ex (3, | |
5063 | hash_type_unit_group, | |
5064 | eq_type_unit_group, | |
5065 | NULL, | |
5066 | &dwarf2_per_objfile->objfile->objfile_obstack, | |
5067 | hashtab_obstack_allocate, | |
5068 | dummy_obstack_deallocate); | |
5069 | } | |
dee91e82 | 5070 | |
f4dc4d17 DE |
5071 | /* Type units that don't have DW_AT_stmt_list are grouped into their own |
5072 | partial symtabs. We combine several TUs per psymtab to not let the size | |
5073 | of any one psymtab grow too big. */ | |
5074 | #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31) | |
5075 | #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10 | |
dee91e82 | 5076 | |
094b34ac | 5077 | /* Helper routine for get_type_unit_group. |
f4dc4d17 DE |
5078 | Create the type_unit_group object used to hold one or more TUs. */ |
5079 | ||
5080 | static struct type_unit_group * | |
094b34ac | 5081 | create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct) |
f4dc4d17 DE |
5082 | { |
5083 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
094b34ac | 5084 | struct dwarf2_per_cu_data *per_cu; |
f4dc4d17 | 5085 | struct type_unit_group *tu_group; |
f4dc4d17 DE |
5086 | |
5087 | tu_group = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5088 | struct type_unit_group); | |
094b34ac | 5089 | per_cu = &tu_group->per_cu; |
f4dc4d17 DE |
5090 | per_cu->objfile = objfile; |
5091 | per_cu->is_debug_types = 1; | |
796a7ff8 | 5092 | per_cu->type_unit_group = tu_group; |
f4dc4d17 | 5093 | |
094b34ac DE |
5094 | if (dwarf2_per_objfile->using_index) |
5095 | { | |
5096 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5097 | struct dwarf2_per_cu_quick_data); | |
5098 | tu_group->t.first_tu = cu->per_cu; | |
5099 | } | |
5100 | else | |
5101 | { | |
5102 | unsigned int line_offset = line_offset_struct.sect_off; | |
5103 | struct partial_symtab *pst; | |
5104 | char *name; | |
5105 | ||
5106 | /* Give the symtab a useful name for debug purposes. */ | |
5107 | if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0) | |
5108 | name = xstrprintf ("<type_units_%d>", | |
5109 | (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB)); | |
5110 | else | |
5111 | name = xstrprintf ("<type_units_at_0x%x>", line_offset); | |
5112 | ||
5113 | pst = create_partial_symtab (per_cu, name); | |
5114 | pst->anonymous = 1; | |
f4dc4d17 | 5115 | |
094b34ac DE |
5116 | xfree (name); |
5117 | } | |
f4dc4d17 | 5118 | |
094b34ac DE |
5119 | tu_group->hash.dwo_unit = cu->dwo_unit; |
5120 | tu_group->hash.line_offset = line_offset_struct; | |
f4dc4d17 DE |
5121 | |
5122 | return tu_group; | |
5123 | } | |
5124 | ||
094b34ac DE |
5125 | /* Look up the type_unit_group for type unit CU, and create it if necessary. |
5126 | STMT_LIST is a DW_AT_stmt_list attribute. */ | |
f4dc4d17 DE |
5127 | |
5128 | static struct type_unit_group * | |
094b34ac | 5129 | get_type_unit_group (struct dwarf2_cu *cu, struct attribute *stmt_list) |
f4dc4d17 DE |
5130 | { |
5131 | struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats; | |
5132 | struct type_unit_group *tu_group; | |
5133 | void **slot; | |
5134 | unsigned int line_offset; | |
5135 | struct type_unit_group type_unit_group_for_lookup; | |
5136 | ||
5137 | if (dwarf2_per_objfile->type_unit_groups == NULL) | |
5138 | { | |
5139 | dwarf2_per_objfile->type_unit_groups = | |
5140 | allocate_type_unit_groups_table (); | |
5141 | } | |
5142 | ||
5143 | /* Do we need to create a new group, or can we use an existing one? */ | |
5144 | ||
5145 | if (stmt_list) | |
5146 | { | |
5147 | line_offset = DW_UNSND (stmt_list); | |
5148 | ++tu_stats->nr_symtab_sharers; | |
5149 | } | |
5150 | else | |
5151 | { | |
5152 | /* Ugh, no stmt_list. Rare, but we have to handle it. | |
5153 | We can do various things here like create one group per TU or | |
5154 | spread them over multiple groups to split up the expansion work. | |
5155 | To avoid worst case scenarios (too many groups or too large groups) | |
5156 | we, umm, group them in bunches. */ | |
5157 | line_offset = (NO_STMT_LIST_TYPE_UNIT_PSYMTAB | |
5158 | | (tu_stats->nr_stmt_less_type_units | |
5159 | / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE)); | |
5160 | ++tu_stats->nr_stmt_less_type_units; | |
5161 | } | |
5162 | ||
094b34ac DE |
5163 | type_unit_group_for_lookup.hash.dwo_unit = cu->dwo_unit; |
5164 | type_unit_group_for_lookup.hash.line_offset.sect_off = line_offset; | |
f4dc4d17 DE |
5165 | slot = htab_find_slot (dwarf2_per_objfile->type_unit_groups, |
5166 | &type_unit_group_for_lookup, INSERT); | |
5167 | if (*slot != NULL) | |
5168 | { | |
5169 | tu_group = *slot; | |
5170 | gdb_assert (tu_group != NULL); | |
5171 | } | |
5172 | else | |
5173 | { | |
5174 | sect_offset line_offset_struct; | |
5175 | ||
5176 | line_offset_struct.sect_off = line_offset; | |
094b34ac | 5177 | tu_group = create_type_unit_group (cu, line_offset_struct); |
f4dc4d17 DE |
5178 | *slot = tu_group; |
5179 | ++tu_stats->nr_symtabs; | |
5180 | } | |
5181 | ||
5182 | return tu_group; | |
5183 | } | |
5184 | ||
5185 | /* Struct used to sort TUs by their abbreviation table offset. */ | |
5186 | ||
5187 | struct tu_abbrev_offset | |
5188 | { | |
5189 | struct signatured_type *sig_type; | |
5190 | sect_offset abbrev_offset; | |
5191 | }; | |
5192 | ||
5193 | /* Helper routine for build_type_unit_groups, passed to qsort. */ | |
5194 | ||
5195 | static int | |
5196 | sort_tu_by_abbrev_offset (const void *ap, const void *bp) | |
5197 | { | |
5198 | const struct tu_abbrev_offset * const *a = ap; | |
5199 | const struct tu_abbrev_offset * const *b = bp; | |
5200 | unsigned int aoff = (*a)->abbrev_offset.sect_off; | |
5201 | unsigned int boff = (*b)->abbrev_offset.sect_off; | |
5202 | ||
5203 | return (aoff > boff) - (aoff < boff); | |
5204 | } | |
5205 | ||
5206 | /* A helper function to add a type_unit_group to a table. */ | |
5207 | ||
5208 | static int | |
5209 | add_type_unit_group_to_table (void **slot, void *datum) | |
5210 | { | |
5211 | struct type_unit_group *tu_group = *slot; | |
5212 | struct type_unit_group ***datap = datum; | |
5213 | ||
5214 | **datap = tu_group; | |
5215 | ++*datap; | |
5216 | ||
5217 | return 1; | |
5218 | } | |
5219 | ||
5220 | /* Efficiently read all the type units, calling init_cutu_and_read_dies on | |
5221 | each one passing FUNC,DATA. | |
5222 | ||
5223 | The efficiency is because we sort TUs by the abbrev table they use and | |
5224 | only read each abbrev table once. In one program there are 200K TUs | |
5225 | sharing 8K abbrev tables. | |
5226 | ||
5227 | The main purpose of this function is to support building the | |
5228 | dwarf2_per_objfile->type_unit_groups table. | |
5229 | TUs typically share the DW_AT_stmt_list of the CU they came from, so we | |
5230 | can collapse the search space by grouping them by stmt_list. | |
5231 | The savings can be significant, in the same program from above the 200K TUs | |
5232 | share 8K stmt_list tables. | |
5233 | ||
5234 | FUNC is expected to call get_type_unit_group, which will create the | |
5235 | struct type_unit_group if necessary and add it to | |
5236 | dwarf2_per_objfile->type_unit_groups. */ | |
5237 | ||
5238 | static void | |
5239 | build_type_unit_groups (die_reader_func_ftype *func, void *data) | |
5240 | { | |
5241 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
5242 | struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats; | |
5243 | struct cleanup *cleanups; | |
5244 | struct abbrev_table *abbrev_table; | |
5245 | sect_offset abbrev_offset; | |
5246 | struct tu_abbrev_offset *sorted_by_abbrev; | |
5247 | struct type_unit_group **iter; | |
5248 | int i; | |
5249 | ||
5250 | /* It's up to the caller to not call us multiple times. */ | |
5251 | gdb_assert (dwarf2_per_objfile->type_unit_groups == NULL); | |
5252 | ||
5253 | if (dwarf2_per_objfile->n_type_units == 0) | |
5254 | return; | |
5255 | ||
5256 | /* TUs typically share abbrev tables, and there can be way more TUs than | |
5257 | abbrev tables. Sort by abbrev table to reduce the number of times we | |
5258 | read each abbrev table in. | |
5259 | Alternatives are to punt or to maintain a cache of abbrev tables. | |
5260 | This is simpler and efficient enough for now. | |
5261 | ||
5262 | Later we group TUs by their DW_AT_stmt_list value (as this defines the | |
5263 | symtab to use). Typically TUs with the same abbrev offset have the same | |
5264 | stmt_list value too so in practice this should work well. | |
5265 | ||
5266 | The basic algorithm here is: | |
5267 | ||
5268 | sort TUs by abbrev table | |
5269 | for each TU with same abbrev table: | |
5270 | read abbrev table if first user | |
5271 | read TU top level DIE | |
5272 | [IWBN if DWO skeletons had DW_AT_stmt_list] | |
5273 | call FUNC */ | |
5274 | ||
5275 | if (dwarf2_read_debug) | |
5276 | fprintf_unfiltered (gdb_stdlog, "Building type unit groups ...\n"); | |
5277 | ||
5278 | /* Sort in a separate table to maintain the order of all_type_units | |
5279 | for .gdb_index: TU indices directly index all_type_units. */ | |
5280 | sorted_by_abbrev = XNEWVEC (struct tu_abbrev_offset, | |
5281 | dwarf2_per_objfile->n_type_units); | |
5282 | for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i) | |
5283 | { | |
5284 | struct signatured_type *sig_type = dwarf2_per_objfile->all_type_units[i]; | |
5285 | ||
5286 | sorted_by_abbrev[i].sig_type = sig_type; | |
5287 | sorted_by_abbrev[i].abbrev_offset = | |
5288 | read_abbrev_offset (sig_type->per_cu.info_or_types_section, | |
5289 | sig_type->per_cu.offset); | |
5290 | } | |
5291 | cleanups = make_cleanup (xfree, sorted_by_abbrev); | |
5292 | qsort (sorted_by_abbrev, dwarf2_per_objfile->n_type_units, | |
5293 | sizeof (struct tu_abbrev_offset), sort_tu_by_abbrev_offset); | |
5294 | ||
094b34ac DE |
5295 | /* Note: In the .gdb_index case, get_type_unit_group may have already been |
5296 | called any number of times, so we don't reset tu_stats here. */ | |
5297 | ||
f4dc4d17 DE |
5298 | abbrev_offset.sect_off = ~(unsigned) 0; |
5299 | abbrev_table = NULL; | |
5300 | make_cleanup (abbrev_table_free_cleanup, &abbrev_table); | |
5301 | ||
5302 | for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i) | |
5303 | { | |
5304 | const struct tu_abbrev_offset *tu = &sorted_by_abbrev[i]; | |
5305 | ||
5306 | /* Switch to the next abbrev table if necessary. */ | |
5307 | if (abbrev_table == NULL | |
5308 | || tu->abbrev_offset.sect_off != abbrev_offset.sect_off) | |
5309 | { | |
5310 | if (abbrev_table != NULL) | |
5311 | { | |
5312 | abbrev_table_free (abbrev_table); | |
5313 | /* Reset to NULL in case abbrev_table_read_table throws | |
5314 | an error: abbrev_table_free_cleanup will get called. */ | |
5315 | abbrev_table = NULL; | |
5316 | } | |
5317 | abbrev_offset = tu->abbrev_offset; | |
5318 | abbrev_table = | |
5319 | abbrev_table_read_table (&dwarf2_per_objfile->abbrev, | |
5320 | abbrev_offset); | |
5321 | ++tu_stats->nr_uniq_abbrev_tables; | |
5322 | } | |
5323 | ||
5324 | init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table, 0, 0, | |
5325 | func, data); | |
5326 | } | |
5327 | ||
5328 | /* Create a vector of pointers to primary type units to make it easy to | |
5329 | iterate over them and CUs. See dw2_get_primary_cu. */ | |
5330 | dwarf2_per_objfile->n_type_unit_groups = | |
5331 | htab_elements (dwarf2_per_objfile->type_unit_groups); | |
5332 | dwarf2_per_objfile->all_type_unit_groups = | |
5333 | obstack_alloc (&objfile->objfile_obstack, | |
5334 | dwarf2_per_objfile->n_type_unit_groups | |
5335 | * sizeof (struct type_unit_group *)); | |
5336 | iter = &dwarf2_per_objfile->all_type_unit_groups[0]; | |
5337 | htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups, | |
5338 | add_type_unit_group_to_table, &iter); | |
5339 | gdb_assert (iter - &dwarf2_per_objfile->all_type_unit_groups[0] | |
5340 | == dwarf2_per_objfile->n_type_unit_groups); | |
5341 | ||
5342 | do_cleanups (cleanups); | |
5343 | ||
5344 | if (dwarf2_read_debug) | |
5345 | { | |
5346 | fprintf_unfiltered (gdb_stdlog, "Done building type unit groups:\n"); | |
5347 | fprintf_unfiltered (gdb_stdlog, " %d TUs\n", | |
5348 | dwarf2_per_objfile->n_type_units); | |
5349 | fprintf_unfiltered (gdb_stdlog, " %d uniq abbrev tables\n", | |
5350 | tu_stats->nr_uniq_abbrev_tables); | |
5351 | fprintf_unfiltered (gdb_stdlog, " %d symtabs from stmt_list entries\n", | |
5352 | tu_stats->nr_symtabs); | |
5353 | fprintf_unfiltered (gdb_stdlog, " %d symtab sharers\n", | |
5354 | tu_stats->nr_symtab_sharers); | |
5355 | fprintf_unfiltered (gdb_stdlog, " %d type units without a stmt_list\n", | |
5356 | tu_stats->nr_stmt_less_type_units); | |
5357 | } | |
5358 | } | |
5359 | ||
5360 | /* Reader function for build_type_psymtabs. */ | |
5361 | ||
5362 | static void | |
5363 | build_type_psymtabs_reader (const struct die_reader_specs *reader, | |
5364 | gdb_byte *info_ptr, | |
5365 | struct die_info *type_unit_die, | |
5366 | int has_children, | |
5367 | void *data) | |
5368 | { | |
5369 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
5370 | struct dwarf2_cu *cu = reader->cu; | |
5371 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; | |
5372 | struct type_unit_group *tu_group; | |
5373 | struct attribute *attr; | |
5374 | struct partial_die_info *first_die; | |
5375 | CORE_ADDR lowpc, highpc; | |
5376 | struct partial_symtab *pst; | |
5377 | ||
5378 | gdb_assert (data == NULL); | |
5379 | ||
5380 | if (! has_children) | |
5381 | return; | |
5382 | ||
5383 | attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list); | |
094b34ac | 5384 | tu_group = get_type_unit_group (cu, attr); |
f4dc4d17 | 5385 | |
094b34ac | 5386 | VEC_safe_push (dwarf2_per_cu_ptr, tu_group->t.tus, per_cu); |
f4dc4d17 DE |
5387 | |
5388 | prepare_one_comp_unit (cu, type_unit_die, language_minimal); | |
5389 | cu->list_in_scope = &file_symbols; | |
5390 | pst = create_partial_symtab (per_cu, ""); | |
5391 | pst->anonymous = 1; | |
5392 | ||
5393 | first_die = load_partial_dies (reader, info_ptr, 1); | |
5394 | ||
5395 | lowpc = (CORE_ADDR) -1; | |
5396 | highpc = (CORE_ADDR) 0; | |
5397 | scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu); | |
5398 | ||
5399 | pst->n_global_syms = objfile->global_psymbols.next - | |
5400 | (objfile->global_psymbols.list + pst->globals_offset); | |
5401 | pst->n_static_syms = objfile->static_psymbols.next - | |
5402 | (objfile->static_psymbols.list + pst->statics_offset); | |
5c80ed9d | 5403 | sort_pst_symbols (objfile, pst); |
f4dc4d17 DE |
5404 | } |
5405 | ||
5406 | /* Traversal function for build_type_psymtabs. */ | |
5407 | ||
5408 | static int | |
5409 | build_type_psymtab_dependencies (void **slot, void *info) | |
5410 | { | |
5411 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
5412 | struct type_unit_group *tu_group = (struct type_unit_group *) *slot; | |
094b34ac | 5413 | struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu; |
f4dc4d17 | 5414 | struct partial_symtab *pst = per_cu->v.psymtab; |
094b34ac | 5415 | int len = VEC_length (dwarf2_per_cu_ptr, tu_group->t.tus); |
f4dc4d17 DE |
5416 | struct dwarf2_per_cu_data *iter; |
5417 | int i; | |
5418 | ||
5419 | gdb_assert (len > 0); | |
5420 | ||
5421 | pst->number_of_dependencies = len; | |
5422 | pst->dependencies = obstack_alloc (&objfile->objfile_obstack, | |
5423 | len * sizeof (struct psymtab *)); | |
5424 | for (i = 0; | |
094b34ac | 5425 | VEC_iterate (dwarf2_per_cu_ptr, tu_group->t.tus, i, iter); |
f4dc4d17 DE |
5426 | ++i) |
5427 | { | |
5428 | pst->dependencies[i] = iter->v.psymtab; | |
796a7ff8 | 5429 | iter->type_unit_group = tu_group; |
f4dc4d17 DE |
5430 | } |
5431 | ||
094b34ac | 5432 | VEC_free (dwarf2_per_cu_ptr, tu_group->t.tus); |
348e048f DE |
5433 | |
5434 | return 1; | |
5435 | } | |
5436 | ||
5437 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
5438 | Build partial symbol tables for the .debug_types comp-units. */ | |
5439 | ||
5440 | static void | |
5441 | build_type_psymtabs (struct objfile *objfile) | |
5442 | { | |
0e50663e | 5443 | if (! create_all_type_units (objfile)) |
348e048f DE |
5444 | return; |
5445 | ||
f4dc4d17 DE |
5446 | build_type_unit_groups (build_type_psymtabs_reader, NULL); |
5447 | ||
5448 | /* Now that all TUs have been processed we can fill in the dependencies. */ | |
5449 | htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups, | |
5450 | build_type_psymtab_dependencies, NULL); | |
348e048f DE |
5451 | } |
5452 | ||
60606b2c TT |
5453 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
5454 | ||
5455 | static void | |
5456 | psymtabs_addrmap_cleanup (void *o) | |
5457 | { | |
5458 | struct objfile *objfile = o; | |
ec61707d | 5459 | |
60606b2c TT |
5460 | objfile->psymtabs_addrmap = NULL; |
5461 | } | |
5462 | ||
95554aad TT |
5463 | /* Compute the 'user' field for each psymtab in OBJFILE. */ |
5464 | ||
5465 | static void | |
5466 | set_partial_user (struct objfile *objfile) | |
5467 | { | |
5468 | int i; | |
5469 | ||
5470 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
5471 | { | |
5472 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
5473 | struct partial_symtab *pst = per_cu->v.psymtab; | |
5474 | int j; | |
5475 | ||
36586728 TT |
5476 | if (pst == NULL) |
5477 | continue; | |
5478 | ||
95554aad TT |
5479 | for (j = 0; j < pst->number_of_dependencies; ++j) |
5480 | { | |
5481 | /* Set the 'user' field only if it is not already set. */ | |
5482 | if (pst->dependencies[j]->user == NULL) | |
5483 | pst->dependencies[j]->user = pst; | |
5484 | } | |
5485 | } | |
5486 | } | |
5487 | ||
93311388 DE |
5488 | /* Build the partial symbol table by doing a quick pass through the |
5489 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 5490 | |
93311388 | 5491 | static void |
c67a9c90 | 5492 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 5493 | { |
60606b2c TT |
5494 | struct cleanup *back_to, *addrmap_cleanup; |
5495 | struct obstack temp_obstack; | |
21b2bd31 | 5496 | int i; |
93311388 | 5497 | |
45cfd468 DE |
5498 | if (dwarf2_read_debug) |
5499 | { | |
5500 | fprintf_unfiltered (gdb_stdlog, "Building psymtabs of objfile %s ...\n", | |
5501 | objfile->name); | |
5502 | } | |
5503 | ||
98bfdba5 PA |
5504 | dwarf2_per_objfile->reading_partial_symbols = 1; |
5505 | ||
be391dca | 5506 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
91c24f0a | 5507 | |
93311388 DE |
5508 | /* Any cached compilation units will be linked by the per-objfile |
5509 | read_in_chain. Make sure to free them when we're done. */ | |
5510 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 5511 | |
348e048f DE |
5512 | build_type_psymtabs (objfile); |
5513 | ||
93311388 | 5514 | create_all_comp_units (objfile); |
c906108c | 5515 | |
60606b2c TT |
5516 | /* Create a temporary address map on a temporary obstack. We later |
5517 | copy this to the final obstack. */ | |
5518 | obstack_init (&temp_obstack); | |
5519 | make_cleanup_obstack_free (&temp_obstack); | |
5520 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
5521 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 5522 | |
21b2bd31 | 5523 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
93311388 | 5524 | { |
21b2bd31 | 5525 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
aaa75496 | 5526 | |
95554aad | 5527 | process_psymtab_comp_unit (per_cu, 0); |
c906108c | 5528 | } |
ff013f42 | 5529 | |
95554aad TT |
5530 | set_partial_user (objfile); |
5531 | ||
ff013f42 JK |
5532 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, |
5533 | &objfile->objfile_obstack); | |
60606b2c | 5534 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 5535 | |
ae038cb0 | 5536 | do_cleanups (back_to); |
45cfd468 DE |
5537 | |
5538 | if (dwarf2_read_debug) | |
5539 | fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n", | |
5540 | objfile->name); | |
ae038cb0 DJ |
5541 | } |
5542 | ||
3019eac3 | 5543 | /* die_reader_func for load_partial_comp_unit. */ |
ae038cb0 DJ |
5544 | |
5545 | static void | |
dee91e82 DE |
5546 | load_partial_comp_unit_reader (const struct die_reader_specs *reader, |
5547 | gdb_byte *info_ptr, | |
5548 | struct die_info *comp_unit_die, | |
5549 | int has_children, | |
5550 | void *data) | |
ae038cb0 | 5551 | { |
dee91e82 | 5552 | struct dwarf2_cu *cu = reader->cu; |
ae038cb0 | 5553 | |
95554aad | 5554 | prepare_one_comp_unit (cu, comp_unit_die, language_minimal); |
ae038cb0 | 5555 | |
ae038cb0 DJ |
5556 | /* Check if comp unit has_children. |
5557 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 5558 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 5559 | if (has_children) |
dee91e82 DE |
5560 | load_partial_dies (reader, info_ptr, 0); |
5561 | } | |
98bfdba5 | 5562 | |
dee91e82 DE |
5563 | /* Load the partial DIEs for a secondary CU into memory. |
5564 | This is also used when rereading a primary CU with load_all_dies. */ | |
c5b7e1cb | 5565 | |
dee91e82 DE |
5566 | static void |
5567 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) | |
5568 | { | |
f4dc4d17 DE |
5569 | init_cutu_and_read_dies (this_cu, NULL, 1, 1, |
5570 | load_partial_comp_unit_reader, NULL); | |
ae038cb0 DJ |
5571 | } |
5572 | ||
ae038cb0 | 5573 | static void |
36586728 TT |
5574 | read_comp_units_from_section (struct objfile *objfile, |
5575 | struct dwarf2_section_info *section, | |
5576 | unsigned int is_dwz, | |
5577 | int *n_allocated, | |
5578 | int *n_comp_units, | |
5579 | struct dwarf2_per_cu_data ***all_comp_units) | |
ae038cb0 | 5580 | { |
be391dca | 5581 | gdb_byte *info_ptr; |
36586728 | 5582 | bfd *abfd = section->asection->owner; |
be391dca | 5583 | |
36586728 | 5584 | dwarf2_read_section (objfile, section); |
ae038cb0 | 5585 | |
36586728 | 5586 | info_ptr = section->buffer; |
6e70227d | 5587 | |
36586728 | 5588 | while (info_ptr < section->buffer + section->size) |
ae038cb0 | 5589 | { |
c764a876 | 5590 | unsigned int length, initial_length_size; |
ae038cb0 | 5591 | struct dwarf2_per_cu_data *this_cu; |
b64f50a1 | 5592 | sect_offset offset; |
ae038cb0 | 5593 | |
36586728 | 5594 | offset.sect_off = info_ptr - section->buffer; |
ae038cb0 DJ |
5595 | |
5596 | /* Read just enough information to find out where the next | |
5597 | compilation unit is. */ | |
36586728 | 5598 | length = read_initial_length (abfd, info_ptr, &initial_length_size); |
ae038cb0 DJ |
5599 | |
5600 | /* Save the compilation unit for later lookup. */ | |
5601 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
5602 | sizeof (struct dwarf2_per_cu_data)); | |
5603 | memset (this_cu, 0, sizeof (*this_cu)); | |
5604 | this_cu->offset = offset; | |
c764a876 | 5605 | this_cu->length = length + initial_length_size; |
36586728 | 5606 | this_cu->is_dwz = is_dwz; |
9291a0cd | 5607 | this_cu->objfile = objfile; |
36586728 | 5608 | this_cu->info_or_types_section = section; |
ae038cb0 | 5609 | |
36586728 | 5610 | if (*n_comp_units == *n_allocated) |
ae038cb0 | 5611 | { |
36586728 TT |
5612 | *n_allocated *= 2; |
5613 | *all_comp_units = xrealloc (*all_comp_units, | |
5614 | *n_allocated | |
5615 | * sizeof (struct dwarf2_per_cu_data *)); | |
ae038cb0 | 5616 | } |
36586728 TT |
5617 | (*all_comp_units)[*n_comp_units] = this_cu; |
5618 | ++*n_comp_units; | |
ae038cb0 DJ |
5619 | |
5620 | info_ptr = info_ptr + this_cu->length; | |
5621 | } | |
36586728 TT |
5622 | } |
5623 | ||
5624 | /* Create a list of all compilation units in OBJFILE. | |
5625 | This is only done for -readnow and building partial symtabs. */ | |
5626 | ||
5627 | static void | |
5628 | create_all_comp_units (struct objfile *objfile) | |
5629 | { | |
5630 | int n_allocated; | |
5631 | int n_comp_units; | |
5632 | struct dwarf2_per_cu_data **all_comp_units; | |
5633 | ||
5634 | n_comp_units = 0; | |
5635 | n_allocated = 10; | |
5636 | all_comp_units = xmalloc (n_allocated | |
5637 | * sizeof (struct dwarf2_per_cu_data *)); | |
5638 | ||
5639 | read_comp_units_from_section (objfile, &dwarf2_per_objfile->info, 0, | |
5640 | &n_allocated, &n_comp_units, &all_comp_units); | |
5641 | ||
5642 | if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL) | |
5643 | { | |
5644 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
5645 | ||
5646 | read_comp_units_from_section (objfile, &dwz->info, 1, | |
5647 | &n_allocated, &n_comp_units, | |
5648 | &all_comp_units); | |
5649 | } | |
ae038cb0 DJ |
5650 | |
5651 | dwarf2_per_objfile->all_comp_units | |
5652 | = obstack_alloc (&objfile->objfile_obstack, | |
5653 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
5654 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
5655 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
5656 | xfree (all_comp_units); | |
5657 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
5658 | } |
5659 | ||
5734ee8b DJ |
5660 | /* Process all loaded DIEs for compilation unit CU, starting at |
5661 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
5662 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
5663 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
5664 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
5665 | and record the covered ranges in the addrmap. */ | |
c906108c | 5666 | |
72bf9492 DJ |
5667 | static void |
5668 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 5669 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 5670 | { |
72bf9492 | 5671 | struct partial_die_info *pdi; |
c906108c | 5672 | |
91c24f0a DC |
5673 | /* Now, march along the PDI's, descending into ones which have |
5674 | interesting children but skipping the children of the other ones, | |
5675 | until we reach the end of the compilation unit. */ | |
c906108c | 5676 | |
72bf9492 | 5677 | pdi = first_die; |
91c24f0a | 5678 | |
72bf9492 DJ |
5679 | while (pdi != NULL) |
5680 | { | |
5681 | fixup_partial_die (pdi, cu); | |
c906108c | 5682 | |
f55ee35c | 5683 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
5684 | children, so we need to look at them. Ditto for anonymous |
5685 | enums. */ | |
933c6fe4 | 5686 | |
72bf9492 | 5687 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
95554aad TT |
5688 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type |
5689 | || pdi->tag == DW_TAG_imported_unit) | |
c906108c | 5690 | { |
72bf9492 | 5691 | switch (pdi->tag) |
c906108c SS |
5692 | { |
5693 | case DW_TAG_subprogram: | |
5734ee8b | 5694 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 5695 | break; |
72929c62 | 5696 | case DW_TAG_constant: |
c906108c SS |
5697 | case DW_TAG_variable: |
5698 | case DW_TAG_typedef: | |
91c24f0a | 5699 | case DW_TAG_union_type: |
72bf9492 | 5700 | if (!pdi->is_declaration) |
63d06c5c | 5701 | { |
72bf9492 | 5702 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
5703 | } |
5704 | break; | |
c906108c | 5705 | case DW_TAG_class_type: |
680b30c7 | 5706 | case DW_TAG_interface_type: |
c906108c | 5707 | case DW_TAG_structure_type: |
72bf9492 | 5708 | if (!pdi->is_declaration) |
c906108c | 5709 | { |
72bf9492 | 5710 | add_partial_symbol (pdi, cu); |
c906108c SS |
5711 | } |
5712 | break; | |
91c24f0a | 5713 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
5714 | if (!pdi->is_declaration) |
5715 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
5716 | break; |
5717 | case DW_TAG_base_type: | |
a02abb62 | 5718 | case DW_TAG_subrange_type: |
c906108c | 5719 | /* File scope base type definitions are added to the partial |
c5aa993b | 5720 | symbol table. */ |
72bf9492 | 5721 | add_partial_symbol (pdi, cu); |
c906108c | 5722 | break; |
d9fa45fe | 5723 | case DW_TAG_namespace: |
5734ee8b | 5724 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 5725 | break; |
5d7cb8df JK |
5726 | case DW_TAG_module: |
5727 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
5728 | break; | |
95554aad TT |
5729 | case DW_TAG_imported_unit: |
5730 | { | |
5731 | struct dwarf2_per_cu_data *per_cu; | |
5732 | ||
f4dc4d17 DE |
5733 | /* For now we don't handle imported units in type units. */ |
5734 | if (cu->per_cu->is_debug_types) | |
5735 | { | |
5736 | error (_("Dwarf Error: DW_TAG_imported_unit is not" | |
5737 | " supported in type units [in module %s]"), | |
5738 | cu->objfile->name); | |
5739 | } | |
5740 | ||
95554aad | 5741 | per_cu = dwarf2_find_containing_comp_unit (pdi->d.offset, |
36586728 | 5742 | pdi->is_dwz, |
95554aad TT |
5743 | cu->objfile); |
5744 | ||
5745 | /* Go read the partial unit, if needed. */ | |
5746 | if (per_cu->v.psymtab == NULL) | |
5747 | process_psymtab_comp_unit (per_cu, 1); | |
5748 | ||
f4dc4d17 | 5749 | VEC_safe_push (dwarf2_per_cu_ptr, |
796a7ff8 | 5750 | cu->per_cu->imported_symtabs, per_cu); |
95554aad TT |
5751 | } |
5752 | break; | |
c906108c SS |
5753 | default: |
5754 | break; | |
5755 | } | |
5756 | } | |
5757 | ||
72bf9492 DJ |
5758 | /* If the die has a sibling, skip to the sibling. */ |
5759 | ||
5760 | pdi = pdi->die_sibling; | |
5761 | } | |
5762 | } | |
5763 | ||
5764 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 5765 | |
72bf9492 | 5766 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
5767 | name is concatenated with "::" and the partial DIE's name. For |
5768 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
5769 | Enumerators are an exception; they use the scope of their parent |
5770 | enumeration type, i.e. the name of the enumeration type is not | |
5771 | prepended to the enumerator. | |
91c24f0a | 5772 | |
72bf9492 DJ |
5773 | There are two complexities. One is DW_AT_specification; in this |
5774 | case "parent" means the parent of the target of the specification, | |
5775 | instead of the direct parent of the DIE. The other is compilers | |
5776 | which do not emit DW_TAG_namespace; in this case we try to guess | |
5777 | the fully qualified name of structure types from their members' | |
5778 | linkage names. This must be done using the DIE's children rather | |
5779 | than the children of any DW_AT_specification target. We only need | |
5780 | to do this for structures at the top level, i.e. if the target of | |
5781 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
5782 | have a parent. */ | |
5783 | ||
5784 | /* Compute the scope prefix associated with PDI's parent, in | |
5785 | compilation unit CU. The result will be allocated on CU's | |
5786 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
5787 | field. NULL is returned if no prefix is necessary. */ | |
15d034d0 | 5788 | static const char * |
72bf9492 DJ |
5789 | partial_die_parent_scope (struct partial_die_info *pdi, |
5790 | struct dwarf2_cu *cu) | |
5791 | { | |
15d034d0 | 5792 | const char *grandparent_scope; |
72bf9492 | 5793 | struct partial_die_info *parent, *real_pdi; |
91c24f0a | 5794 | |
72bf9492 DJ |
5795 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
5796 | then this means the parent of the specification DIE. */ | |
5797 | ||
5798 | real_pdi = pdi; | |
72bf9492 | 5799 | while (real_pdi->has_specification) |
36586728 TT |
5800 | real_pdi = find_partial_die (real_pdi->spec_offset, |
5801 | real_pdi->spec_is_dwz, cu); | |
72bf9492 DJ |
5802 | |
5803 | parent = real_pdi->die_parent; | |
5804 | if (parent == NULL) | |
5805 | return NULL; | |
5806 | ||
5807 | if (parent->scope_set) | |
5808 | return parent->scope; | |
5809 | ||
5810 | fixup_partial_die (parent, cu); | |
5811 | ||
10b3939b | 5812 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 5813 | |
acebe513 UW |
5814 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
5815 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
5816 | Work around this problem here. */ | |
5817 | if (cu->language == language_cplus | |
6e70227d | 5818 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
5819 | && strcmp (parent->name, "::") == 0 |
5820 | && grandparent_scope == NULL) | |
5821 | { | |
5822 | parent->scope = NULL; | |
5823 | parent->scope_set = 1; | |
5824 | return NULL; | |
5825 | } | |
5826 | ||
9c6c53f7 SA |
5827 | if (pdi->tag == DW_TAG_enumerator) |
5828 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
5829 | parent->scope = grandparent_scope; | |
5830 | else if (parent->tag == DW_TAG_namespace | |
f55ee35c | 5831 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
5832 | || parent->tag == DW_TAG_structure_type |
5833 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 5834 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
5835 | || parent->tag == DW_TAG_union_type |
5836 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
5837 | { |
5838 | if (grandparent_scope == NULL) | |
5839 | parent->scope = parent->name; | |
5840 | else | |
3e43a32a MS |
5841 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
5842 | grandparent_scope, | |
f55ee35c | 5843 | parent->name, 0, cu); |
72bf9492 | 5844 | } |
72bf9492 DJ |
5845 | else |
5846 | { | |
5847 | /* FIXME drow/2004-04-01: What should we be doing with | |
5848 | function-local names? For partial symbols, we should probably be | |
5849 | ignoring them. */ | |
5850 | complaint (&symfile_complaints, | |
e2e0b3e5 | 5851 | _("unhandled containing DIE tag %d for DIE at %d"), |
b64f50a1 | 5852 | parent->tag, pdi->offset.sect_off); |
72bf9492 | 5853 | parent->scope = grandparent_scope; |
c906108c SS |
5854 | } |
5855 | ||
72bf9492 DJ |
5856 | parent->scope_set = 1; |
5857 | return parent->scope; | |
5858 | } | |
5859 | ||
5860 | /* Return the fully scoped name associated with PDI, from compilation unit | |
5861 | CU. The result will be allocated with malloc. */ | |
4568ecf9 | 5862 | |
72bf9492 DJ |
5863 | static char * |
5864 | partial_die_full_name (struct partial_die_info *pdi, | |
5865 | struct dwarf2_cu *cu) | |
5866 | { | |
15d034d0 | 5867 | const char *parent_scope; |
72bf9492 | 5868 | |
98bfdba5 PA |
5869 | /* If this is a template instantiation, we can not work out the |
5870 | template arguments from partial DIEs. So, unfortunately, we have | |
5871 | to go through the full DIEs. At least any work we do building | |
5872 | types here will be reused if full symbols are loaded later. */ | |
5873 | if (pdi->has_template_arguments) | |
5874 | { | |
5875 | fixup_partial_die (pdi, cu); | |
5876 | ||
5877 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
5878 | { | |
5879 | struct die_info *die; | |
5880 | struct attribute attr; | |
5881 | struct dwarf2_cu *ref_cu = cu; | |
5882 | ||
b64f50a1 | 5883 | /* DW_FORM_ref_addr is using section offset. */ |
98bfdba5 PA |
5884 | attr.name = 0; |
5885 | attr.form = DW_FORM_ref_addr; | |
4568ecf9 | 5886 | attr.u.unsnd = pdi->offset.sect_off; |
98bfdba5 PA |
5887 | die = follow_die_ref (NULL, &attr, &ref_cu); |
5888 | ||
5889 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
5890 | } | |
5891 | } | |
5892 | ||
72bf9492 DJ |
5893 | parent_scope = partial_die_parent_scope (pdi, cu); |
5894 | if (parent_scope == NULL) | |
5895 | return NULL; | |
5896 | else | |
f55ee35c | 5897 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
5898 | } |
5899 | ||
5900 | static void | |
72bf9492 | 5901 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 5902 | { |
e7c27a73 | 5903 | struct objfile *objfile = cu->objfile; |
c906108c | 5904 | CORE_ADDR addr = 0; |
15d034d0 | 5905 | const char *actual_name = NULL; |
e142c38c | 5906 | CORE_ADDR baseaddr; |
15d034d0 | 5907 | char *built_actual_name; |
e142c38c DJ |
5908 | |
5909 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 5910 | |
15d034d0 TT |
5911 | built_actual_name = partial_die_full_name (pdi, cu); |
5912 | if (built_actual_name != NULL) | |
5913 | actual_name = built_actual_name; | |
63d06c5c | 5914 | |
72bf9492 DJ |
5915 | if (actual_name == NULL) |
5916 | actual_name = pdi->name; | |
5917 | ||
c906108c SS |
5918 | switch (pdi->tag) |
5919 | { | |
5920 | case DW_TAG_subprogram: | |
2cfa0c8d | 5921 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 5922 | { |
2cfa0c8d JB |
5923 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
5924 | of the global scope. But in Ada, we want to be able to access | |
5925 | nested procedures globally. So all Ada subprograms are stored | |
5926 | in the global scope. */ | |
f47fb265 | 5927 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 5928 | mst_text, objfile); */ |
f47fb265 | 5929 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 5930 | built_actual_name != NULL, |
f47fb265 MS |
5931 | VAR_DOMAIN, LOC_BLOCK, |
5932 | &objfile->global_psymbols, | |
5933 | 0, pdi->lowpc + baseaddr, | |
5934 | cu->language, objfile); | |
c906108c SS |
5935 | } |
5936 | else | |
5937 | { | |
f47fb265 | 5938 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 5939 | mst_file_text, objfile); */ |
f47fb265 | 5940 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 5941 | built_actual_name != NULL, |
f47fb265 MS |
5942 | VAR_DOMAIN, LOC_BLOCK, |
5943 | &objfile->static_psymbols, | |
5944 | 0, pdi->lowpc + baseaddr, | |
5945 | cu->language, objfile); | |
c906108c SS |
5946 | } |
5947 | break; | |
72929c62 JB |
5948 | case DW_TAG_constant: |
5949 | { | |
5950 | struct psymbol_allocation_list *list; | |
5951 | ||
5952 | if (pdi->is_external) | |
5953 | list = &objfile->global_psymbols; | |
5954 | else | |
5955 | list = &objfile->static_psymbols; | |
f47fb265 | 5956 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 5957 | built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC, |
f47fb265 | 5958 | list, 0, 0, cu->language, objfile); |
72929c62 JB |
5959 | } |
5960 | break; | |
c906108c | 5961 | case DW_TAG_variable: |
95554aad TT |
5962 | if (pdi->d.locdesc) |
5963 | addr = decode_locdesc (pdi->d.locdesc, cu); | |
caac4577 | 5964 | |
95554aad | 5965 | if (pdi->d.locdesc |
caac4577 JG |
5966 | && addr == 0 |
5967 | && !dwarf2_per_objfile->has_section_at_zero) | |
5968 | { | |
5969 | /* A global or static variable may also have been stripped | |
5970 | out by the linker if unused, in which case its address | |
5971 | will be nullified; do not add such variables into partial | |
5972 | symbol table then. */ | |
5973 | } | |
5974 | else if (pdi->is_external) | |
c906108c SS |
5975 | { |
5976 | /* Global Variable. | |
5977 | Don't enter into the minimal symbol tables as there is | |
5978 | a minimal symbol table entry from the ELF symbols already. | |
5979 | Enter into partial symbol table if it has a location | |
5980 | descriptor or a type. | |
5981 | If the location descriptor is missing, new_symbol will create | |
5982 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
5983 | be determined from the minimal symbol table whenever the variable | |
5984 | is referenced. | |
5985 | The address for the partial symbol table entry is not | |
5986 | used by GDB, but it comes in handy for debugging partial symbol | |
5987 | table building. */ | |
5988 | ||
95554aad | 5989 | if (pdi->d.locdesc || pdi->has_type) |
f47fb265 | 5990 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 5991 | built_actual_name != NULL, |
f47fb265 MS |
5992 | VAR_DOMAIN, LOC_STATIC, |
5993 | &objfile->global_psymbols, | |
5994 | 0, addr + baseaddr, | |
5995 | cu->language, objfile); | |
c906108c SS |
5996 | } |
5997 | else | |
5998 | { | |
0963b4bd | 5999 | /* Static Variable. Skip symbols without location descriptors. */ |
95554aad | 6000 | if (pdi->d.locdesc == NULL) |
decbce07 | 6001 | { |
15d034d0 | 6002 | xfree (built_actual_name); |
decbce07 MS |
6003 | return; |
6004 | } | |
f47fb265 | 6005 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 6006 | mst_file_data, objfile); */ |
f47fb265 | 6007 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 6008 | built_actual_name != NULL, |
f47fb265 MS |
6009 | VAR_DOMAIN, LOC_STATIC, |
6010 | &objfile->static_psymbols, | |
6011 | 0, addr + baseaddr, | |
6012 | cu->language, objfile); | |
c906108c SS |
6013 | } |
6014 | break; | |
6015 | case DW_TAG_typedef: | |
6016 | case DW_TAG_base_type: | |
a02abb62 | 6017 | case DW_TAG_subrange_type: |
38d518c9 | 6018 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 6019 | built_actual_name != NULL, |
176620f1 | 6020 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 6021 | &objfile->static_psymbols, |
e142c38c | 6022 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 6023 | break; |
72bf9492 DJ |
6024 | case DW_TAG_namespace: |
6025 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
15d034d0 | 6026 | built_actual_name != NULL, |
72bf9492 DJ |
6027 | VAR_DOMAIN, LOC_TYPEDEF, |
6028 | &objfile->global_psymbols, | |
6029 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
6030 | break; | |
c906108c | 6031 | case DW_TAG_class_type: |
680b30c7 | 6032 | case DW_TAG_interface_type: |
c906108c SS |
6033 | case DW_TAG_structure_type: |
6034 | case DW_TAG_union_type: | |
6035 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
6036 | /* Skip external references. The DWARF standard says in the section |
6037 | about "Structure, Union, and Class Type Entries": "An incomplete | |
6038 | structure, union or class type is represented by a structure, | |
6039 | union or class entry that does not have a byte size attribute | |
6040 | and that has a DW_AT_declaration attribute." */ | |
6041 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 | 6042 | { |
15d034d0 | 6043 | xfree (built_actual_name); |
decbce07 MS |
6044 | return; |
6045 | } | |
fa4028e9 | 6046 | |
63d06c5c DC |
6047 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
6048 | static vs. global. */ | |
38d518c9 | 6049 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 6050 | built_actual_name != NULL, |
176620f1 | 6051 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
6052 | (cu->language == language_cplus |
6053 | || cu->language == language_java) | |
63d06c5c DC |
6054 | ? &objfile->global_psymbols |
6055 | : &objfile->static_psymbols, | |
e142c38c | 6056 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 6057 | |
c906108c SS |
6058 | break; |
6059 | case DW_TAG_enumerator: | |
38d518c9 | 6060 | add_psymbol_to_list (actual_name, strlen (actual_name), |
15d034d0 | 6061 | built_actual_name != NULL, |
176620f1 | 6062 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
6063 | (cu->language == language_cplus |
6064 | || cu->language == language_java) | |
f6fe98ef DJ |
6065 | ? &objfile->global_psymbols |
6066 | : &objfile->static_psymbols, | |
e142c38c | 6067 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
6068 | break; |
6069 | default: | |
6070 | break; | |
6071 | } | |
5c4e30ca | 6072 | |
15d034d0 | 6073 | xfree (built_actual_name); |
c906108c SS |
6074 | } |
6075 | ||
5c4e30ca DC |
6076 | /* Read a partial die corresponding to a namespace; also, add a symbol |
6077 | corresponding to that namespace to the symbol table. NAMESPACE is | |
6078 | the name of the enclosing namespace. */ | |
91c24f0a | 6079 | |
72bf9492 DJ |
6080 | static void |
6081 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 6082 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 6083 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 6084 | { |
72bf9492 | 6085 | /* Add a symbol for the namespace. */ |
e7c27a73 | 6086 | |
72bf9492 | 6087 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
6088 | |
6089 | /* Now scan partial symbols in that namespace. */ | |
6090 | ||
91c24f0a | 6091 | if (pdi->has_children) |
5734ee8b | 6092 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
6093 | } |
6094 | ||
5d7cb8df JK |
6095 | /* Read a partial die corresponding to a Fortran module. */ |
6096 | ||
6097 | static void | |
6098 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
6099 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
6100 | { | |
f55ee35c | 6101 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
6102 | |
6103 | if (pdi->has_children) | |
6104 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
6105 | } | |
6106 | ||
bc30ff58 JB |
6107 | /* Read a partial die corresponding to a subprogram and create a partial |
6108 | symbol for that subprogram. When the CU language allows it, this | |
6109 | routine also defines a partial symbol for each nested subprogram | |
6110 | that this subprogram contains. | |
6e70227d | 6111 | |
bc30ff58 JB |
6112 | DIE my also be a lexical block, in which case we simply search |
6113 | recursively for suprograms defined inside that lexical block. | |
6114 | Again, this is only performed when the CU language allows this | |
6115 | type of definitions. */ | |
6116 | ||
6117 | static void | |
6118 | add_partial_subprogram (struct partial_die_info *pdi, | |
6119 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 6120 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
6121 | { |
6122 | if (pdi->tag == DW_TAG_subprogram) | |
6123 | { | |
6124 | if (pdi->has_pc_info) | |
6125 | { | |
6126 | if (pdi->lowpc < *lowpc) | |
6127 | *lowpc = pdi->lowpc; | |
6128 | if (pdi->highpc > *highpc) | |
6129 | *highpc = pdi->highpc; | |
5734ee8b DJ |
6130 | if (need_pc) |
6131 | { | |
6132 | CORE_ADDR baseaddr; | |
6133 | struct objfile *objfile = cu->objfile; | |
6134 | ||
6135 | baseaddr = ANOFFSET (objfile->section_offsets, | |
6136 | SECT_OFF_TEXT (objfile)); | |
6137 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
6138 | pdi->lowpc + baseaddr, |
6139 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 6140 | cu->per_cu->v.psymtab); |
5734ee8b | 6141 | } |
481860b3 GB |
6142 | } |
6143 | ||
6144 | if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined)) | |
6145 | { | |
bc30ff58 | 6146 | if (!pdi->is_declaration) |
e8d05480 JB |
6147 | /* Ignore subprogram DIEs that do not have a name, they are |
6148 | illegal. Do not emit a complaint at this point, we will | |
6149 | do so when we convert this psymtab into a symtab. */ | |
6150 | if (pdi->name) | |
6151 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
6152 | } |
6153 | } | |
6e70227d | 6154 | |
bc30ff58 JB |
6155 | if (! pdi->has_children) |
6156 | return; | |
6157 | ||
6158 | if (cu->language == language_ada) | |
6159 | { | |
6160 | pdi = pdi->die_child; | |
6161 | while (pdi != NULL) | |
6162 | { | |
6163 | fixup_partial_die (pdi, cu); | |
6164 | if (pdi->tag == DW_TAG_subprogram | |
6165 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 6166 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
6167 | pdi = pdi->die_sibling; |
6168 | } | |
6169 | } | |
6170 | } | |
6171 | ||
91c24f0a DC |
6172 | /* Read a partial die corresponding to an enumeration type. */ |
6173 | ||
72bf9492 DJ |
6174 | static void |
6175 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
6176 | struct dwarf2_cu *cu) | |
91c24f0a | 6177 | { |
72bf9492 | 6178 | struct partial_die_info *pdi; |
91c24f0a DC |
6179 | |
6180 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
6181 | add_partial_symbol (enum_pdi, cu); |
6182 | ||
6183 | pdi = enum_pdi->die_child; | |
6184 | while (pdi) | |
91c24f0a | 6185 | { |
72bf9492 | 6186 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 6187 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 6188 | else |
72bf9492 DJ |
6189 | add_partial_symbol (pdi, cu); |
6190 | pdi = pdi->die_sibling; | |
91c24f0a | 6191 | } |
91c24f0a DC |
6192 | } |
6193 | ||
6caca83c CC |
6194 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
6195 | ||
6196 | static unsigned int | |
6197 | peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr) | |
6198 | { | |
6199 | unsigned int bytes_read; | |
6200 | ||
6201 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6202 | } | |
6203 | ||
4bb7a0a7 DJ |
6204 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
6205 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
6206 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
6207 | the initial number. */ | |
6208 | ||
6209 | static struct abbrev_info * | |
fe1b8b76 | 6210 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 6211 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
6212 | { |
6213 | bfd *abfd = cu->objfile->obfd; | |
6214 | unsigned int abbrev_number; | |
6215 | struct abbrev_info *abbrev; | |
6216 | ||
6217 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
6218 | ||
6219 | if (abbrev_number == 0) | |
6220 | return NULL; | |
6221 | ||
433df2d4 | 6222 | abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number); |
4bb7a0a7 DJ |
6223 | if (!abbrev) |
6224 | { | |
3e43a32a MS |
6225 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
6226 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
6227 | } |
6228 | ||
6229 | return abbrev; | |
6230 | } | |
6231 | ||
93311388 DE |
6232 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
6233 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
6234 | DIE. Any children of the skipped DIEs will also be skipped. */ |
6235 | ||
fe1b8b76 | 6236 | static gdb_byte * |
dee91e82 | 6237 | skip_children (const struct die_reader_specs *reader, gdb_byte *info_ptr) |
4bb7a0a7 | 6238 | { |
dee91e82 | 6239 | struct dwarf2_cu *cu = reader->cu; |
4bb7a0a7 DJ |
6240 | struct abbrev_info *abbrev; |
6241 | unsigned int bytes_read; | |
6242 | ||
6243 | while (1) | |
6244 | { | |
6245 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
6246 | if (abbrev == NULL) | |
6247 | return info_ptr + bytes_read; | |
6248 | else | |
dee91e82 | 6249 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
4bb7a0a7 DJ |
6250 | } |
6251 | } | |
6252 | ||
93311388 DE |
6253 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
6254 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
6255 | abbrev corresponding to that skipped uleb128 should be passed in |
6256 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
6257 | children. */ | |
6258 | ||
fe1b8b76 | 6259 | static gdb_byte * |
dee91e82 DE |
6260 | skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr, |
6261 | struct abbrev_info *abbrev) | |
4bb7a0a7 DJ |
6262 | { |
6263 | unsigned int bytes_read; | |
6264 | struct attribute attr; | |
dee91e82 DE |
6265 | bfd *abfd = reader->abfd; |
6266 | struct dwarf2_cu *cu = reader->cu; | |
6267 | gdb_byte *buffer = reader->buffer; | |
f664829e DE |
6268 | const gdb_byte *buffer_end = reader->buffer_end; |
6269 | gdb_byte *start_info_ptr = info_ptr; | |
4bb7a0a7 DJ |
6270 | unsigned int form, i; |
6271 | ||
6272 | for (i = 0; i < abbrev->num_attrs; i++) | |
6273 | { | |
6274 | /* The only abbrev we care about is DW_AT_sibling. */ | |
6275 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
6276 | { | |
dee91e82 | 6277 | read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
4bb7a0a7 | 6278 | if (attr.form == DW_FORM_ref_addr) |
3e43a32a MS |
6279 | complaint (&symfile_complaints, |
6280 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 6281 | else |
b64f50a1 | 6282 | return buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
4bb7a0a7 DJ |
6283 | } |
6284 | ||
6285 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
6286 | form = abbrev->attrs[i].form; | |
6287 | skip_attribute: | |
6288 | switch (form) | |
6289 | { | |
4bb7a0a7 | 6290 | case DW_FORM_ref_addr: |
ae411497 TT |
6291 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
6292 | and later it is offset sized. */ | |
6293 | if (cu->header.version == 2) | |
6294 | info_ptr += cu->header.addr_size; | |
6295 | else | |
6296 | info_ptr += cu->header.offset_size; | |
6297 | break; | |
36586728 TT |
6298 | case DW_FORM_GNU_ref_alt: |
6299 | info_ptr += cu->header.offset_size; | |
6300 | break; | |
ae411497 | 6301 | case DW_FORM_addr: |
4bb7a0a7 DJ |
6302 | info_ptr += cu->header.addr_size; |
6303 | break; | |
6304 | case DW_FORM_data1: | |
6305 | case DW_FORM_ref1: | |
6306 | case DW_FORM_flag: | |
6307 | info_ptr += 1; | |
6308 | break; | |
2dc7f7b3 TT |
6309 | case DW_FORM_flag_present: |
6310 | break; | |
4bb7a0a7 DJ |
6311 | case DW_FORM_data2: |
6312 | case DW_FORM_ref2: | |
6313 | info_ptr += 2; | |
6314 | break; | |
6315 | case DW_FORM_data4: | |
6316 | case DW_FORM_ref4: | |
6317 | info_ptr += 4; | |
6318 | break; | |
6319 | case DW_FORM_data8: | |
6320 | case DW_FORM_ref8: | |
55f1336d | 6321 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
6322 | info_ptr += 8; |
6323 | break; | |
6324 | case DW_FORM_string: | |
9b1c24c8 | 6325 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
6326 | info_ptr += bytes_read; |
6327 | break; | |
2dc7f7b3 | 6328 | case DW_FORM_sec_offset: |
4bb7a0a7 | 6329 | case DW_FORM_strp: |
36586728 | 6330 | case DW_FORM_GNU_strp_alt: |
4bb7a0a7 DJ |
6331 | info_ptr += cu->header.offset_size; |
6332 | break; | |
2dc7f7b3 | 6333 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
6334 | case DW_FORM_block: |
6335 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6336 | info_ptr += bytes_read; | |
6337 | break; | |
6338 | case DW_FORM_block1: | |
6339 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
6340 | break; | |
6341 | case DW_FORM_block2: | |
6342 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
6343 | break; | |
6344 | case DW_FORM_block4: | |
6345 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
6346 | break; | |
6347 | case DW_FORM_sdata: | |
6348 | case DW_FORM_udata: | |
6349 | case DW_FORM_ref_udata: | |
3019eac3 DE |
6350 | case DW_FORM_GNU_addr_index: |
6351 | case DW_FORM_GNU_str_index: | |
f664829e | 6352 | info_ptr = (gdb_byte *) safe_skip_leb128 (info_ptr, buffer_end); |
4bb7a0a7 DJ |
6353 | break; |
6354 | case DW_FORM_indirect: | |
6355 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6356 | info_ptr += bytes_read; | |
6357 | /* We need to continue parsing from here, so just go back to | |
6358 | the top. */ | |
6359 | goto skip_attribute; | |
6360 | ||
6361 | default: | |
3e43a32a MS |
6362 | error (_("Dwarf Error: Cannot handle %s " |
6363 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
6364 | dwarf_form_name (form), |
6365 | bfd_get_filename (abfd)); | |
6366 | } | |
6367 | } | |
6368 | ||
6369 | if (abbrev->has_children) | |
dee91e82 | 6370 | return skip_children (reader, info_ptr); |
4bb7a0a7 DJ |
6371 | else |
6372 | return info_ptr; | |
6373 | } | |
6374 | ||
93311388 | 6375 | /* Locate ORIG_PDI's sibling. |
dee91e82 | 6376 | INFO_PTR should point to the start of the next DIE after ORIG_PDI. */ |
91c24f0a | 6377 | |
fe1b8b76 | 6378 | static gdb_byte * |
dee91e82 DE |
6379 | locate_pdi_sibling (const struct die_reader_specs *reader, |
6380 | struct partial_die_info *orig_pdi, | |
6381 | gdb_byte *info_ptr) | |
91c24f0a DC |
6382 | { |
6383 | /* Do we know the sibling already? */ | |
72bf9492 | 6384 | |
91c24f0a DC |
6385 | if (orig_pdi->sibling) |
6386 | return orig_pdi->sibling; | |
6387 | ||
6388 | /* Are there any children to deal with? */ | |
6389 | ||
6390 | if (!orig_pdi->has_children) | |
6391 | return info_ptr; | |
6392 | ||
4bb7a0a7 | 6393 | /* Skip the children the long way. */ |
91c24f0a | 6394 | |
dee91e82 | 6395 | return skip_children (reader, info_ptr); |
91c24f0a DC |
6396 | } |
6397 | ||
257e7a09 | 6398 | /* Expand this partial symbol table into a full symbol table. SELF is |
442e4d9c | 6399 | not NULL. */ |
c906108c SS |
6400 | |
6401 | static void | |
257e7a09 YQ |
6402 | dwarf2_read_symtab (struct partial_symtab *self, |
6403 | struct objfile *objfile) | |
c906108c | 6404 | { |
257e7a09 | 6405 | if (self->readin) |
c906108c | 6406 | { |
442e4d9c | 6407 | warning (_("bug: psymtab for %s is already read in."), |
257e7a09 | 6408 | self->filename); |
442e4d9c YQ |
6409 | } |
6410 | else | |
6411 | { | |
6412 | if (info_verbose) | |
c906108c | 6413 | { |
442e4d9c | 6414 | printf_filtered (_("Reading in symbols for %s..."), |
257e7a09 | 6415 | self->filename); |
442e4d9c | 6416 | gdb_flush (gdb_stdout); |
c906108c | 6417 | } |
c906108c | 6418 | |
442e4d9c YQ |
6419 | /* Restore our global data. */ |
6420 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
10b3939b | 6421 | |
442e4d9c YQ |
6422 | /* If this psymtab is constructed from a debug-only objfile, the |
6423 | has_section_at_zero flag will not necessarily be correct. We | |
6424 | can get the correct value for this flag by looking at the data | |
6425 | associated with the (presumably stripped) associated objfile. */ | |
6426 | if (objfile->separate_debug_objfile_backlink) | |
6427 | { | |
6428 | struct dwarf2_per_objfile *dpo_backlink | |
6429 | = objfile_data (objfile->separate_debug_objfile_backlink, | |
6430 | dwarf2_objfile_data_key); | |
9a619af0 | 6431 | |
442e4d9c YQ |
6432 | dwarf2_per_objfile->has_section_at_zero |
6433 | = dpo_backlink->has_section_at_zero; | |
6434 | } | |
b2ab525c | 6435 | |
442e4d9c | 6436 | dwarf2_per_objfile->reading_partial_symbols = 0; |
98bfdba5 | 6437 | |
257e7a09 | 6438 | psymtab_to_symtab_1 (self); |
c906108c | 6439 | |
442e4d9c YQ |
6440 | /* Finish up the debug error message. */ |
6441 | if (info_verbose) | |
6442 | printf_filtered (_("done.\n")); | |
c906108c | 6443 | } |
95554aad TT |
6444 | |
6445 | process_cu_includes (); | |
c906108c | 6446 | } |
9cdd5dbd DE |
6447 | \f |
6448 | /* Reading in full CUs. */ | |
c906108c | 6449 | |
10b3939b DJ |
6450 | /* Add PER_CU to the queue. */ |
6451 | ||
6452 | static void | |
95554aad TT |
6453 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, |
6454 | enum language pretend_language) | |
10b3939b DJ |
6455 | { |
6456 | struct dwarf2_queue_item *item; | |
6457 | ||
6458 | per_cu->queued = 1; | |
6459 | item = xmalloc (sizeof (*item)); | |
6460 | item->per_cu = per_cu; | |
95554aad | 6461 | item->pretend_language = pretend_language; |
10b3939b DJ |
6462 | item->next = NULL; |
6463 | ||
6464 | if (dwarf2_queue == NULL) | |
6465 | dwarf2_queue = item; | |
6466 | else | |
6467 | dwarf2_queue_tail->next = item; | |
6468 | ||
6469 | dwarf2_queue_tail = item; | |
6470 | } | |
6471 | ||
0907af0c DE |
6472 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
6473 | unit and add it to our queue. | |
6474 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
6475 | meaning either PER_CU is already queued or it is already loaded. */ | |
6476 | ||
6477 | static int | |
6478 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, | |
6479 | struct dwarf2_per_cu_data *per_cu, | |
6480 | enum language pretend_language) | |
6481 | { | |
6482 | /* We may arrive here during partial symbol reading, if we need full | |
6483 | DIEs to process an unusual case (e.g. template arguments). Do | |
6484 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
6485 | if (dwarf2_per_objfile->reading_partial_symbols) | |
6486 | { | |
6487 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
6488 | return 1; | |
6489 | return 0; | |
6490 | } | |
6491 | ||
6492 | /* Mark the dependence relation so that we don't flush PER_CU | |
6493 | too early. */ | |
6494 | dwarf2_add_dependence (this_cu, per_cu); | |
6495 | ||
6496 | /* If it's already on the queue, we have nothing to do. */ | |
6497 | if (per_cu->queued) | |
6498 | return 0; | |
6499 | ||
6500 | /* If the compilation unit is already loaded, just mark it as | |
6501 | used. */ | |
6502 | if (per_cu->cu != NULL) | |
6503 | { | |
6504 | per_cu->cu->last_used = 0; | |
6505 | return 0; | |
6506 | } | |
6507 | ||
6508 | /* Add it to the queue. */ | |
6509 | queue_comp_unit (per_cu, pretend_language); | |
6510 | ||
6511 | return 1; | |
6512 | } | |
6513 | ||
10b3939b DJ |
6514 | /* Process the queue. */ |
6515 | ||
6516 | static void | |
a0f42c21 | 6517 | process_queue (void) |
10b3939b DJ |
6518 | { |
6519 | struct dwarf2_queue_item *item, *next_item; | |
6520 | ||
45cfd468 DE |
6521 | if (dwarf2_read_debug) |
6522 | { | |
6523 | fprintf_unfiltered (gdb_stdlog, | |
6524 | "Expanding one or more symtabs of objfile %s ...\n", | |
6525 | dwarf2_per_objfile->objfile->name); | |
6526 | } | |
6527 | ||
03dd20cc DJ |
6528 | /* The queue starts out with one item, but following a DIE reference |
6529 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
6530 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
6531 | { | |
9291a0cd TT |
6532 | if (dwarf2_per_objfile->using_index |
6533 | ? !item->per_cu->v.quick->symtab | |
6534 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
f4dc4d17 DE |
6535 | { |
6536 | struct dwarf2_per_cu_data *per_cu = item->per_cu; | |
6537 | ||
6538 | if (dwarf2_read_debug) | |
6539 | { | |
6540 | fprintf_unfiltered (gdb_stdlog, | |
6541 | "Expanding symtab of %s at offset 0x%x\n", | |
6542 | per_cu->is_debug_types ? "TU" : "CU", | |
6543 | per_cu->offset.sect_off); | |
6544 | } | |
6545 | ||
6546 | if (per_cu->is_debug_types) | |
6547 | process_full_type_unit (per_cu, item->pretend_language); | |
6548 | else | |
6549 | process_full_comp_unit (per_cu, item->pretend_language); | |
6550 | ||
6551 | if (dwarf2_read_debug) | |
6552 | { | |
6553 | fprintf_unfiltered (gdb_stdlog, | |
6554 | "Done expanding %s at offset 0x%x\n", | |
6555 | per_cu->is_debug_types ? "TU" : "CU", | |
6556 | per_cu->offset.sect_off); | |
6557 | } | |
6558 | } | |
10b3939b DJ |
6559 | |
6560 | item->per_cu->queued = 0; | |
6561 | next_item = item->next; | |
6562 | xfree (item); | |
6563 | } | |
6564 | ||
6565 | dwarf2_queue_tail = NULL; | |
45cfd468 DE |
6566 | |
6567 | if (dwarf2_read_debug) | |
6568 | { | |
6569 | fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n", | |
6570 | dwarf2_per_objfile->objfile->name); | |
6571 | } | |
10b3939b DJ |
6572 | } |
6573 | ||
6574 | /* Free all allocated queue entries. This function only releases anything if | |
6575 | an error was thrown; if the queue was processed then it would have been | |
6576 | freed as we went along. */ | |
6577 | ||
6578 | static void | |
6579 | dwarf2_release_queue (void *dummy) | |
6580 | { | |
6581 | struct dwarf2_queue_item *item, *last; | |
6582 | ||
6583 | item = dwarf2_queue; | |
6584 | while (item) | |
6585 | { | |
6586 | /* Anything still marked queued is likely to be in an | |
6587 | inconsistent state, so discard it. */ | |
6588 | if (item->per_cu->queued) | |
6589 | { | |
6590 | if (item->per_cu->cu != NULL) | |
dee91e82 | 6591 | free_one_cached_comp_unit (item->per_cu); |
10b3939b DJ |
6592 | item->per_cu->queued = 0; |
6593 | } | |
6594 | ||
6595 | last = item; | |
6596 | item = item->next; | |
6597 | xfree (last); | |
6598 | } | |
6599 | ||
6600 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
6601 | } | |
6602 | ||
6603 | /* Read in full symbols for PST, and anything it depends on. */ | |
6604 | ||
c906108c | 6605 | static void |
fba45db2 | 6606 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 6607 | { |
10b3939b | 6608 | struct dwarf2_per_cu_data *per_cu; |
aaa75496 JB |
6609 | int i; |
6610 | ||
95554aad TT |
6611 | if (pst->readin) |
6612 | return; | |
6613 | ||
aaa75496 | 6614 | for (i = 0; i < pst->number_of_dependencies; i++) |
95554aad TT |
6615 | if (!pst->dependencies[i]->readin |
6616 | && pst->dependencies[i]->user == NULL) | |
aaa75496 JB |
6617 | { |
6618 | /* Inform about additional files that need to be read in. */ | |
6619 | if (info_verbose) | |
6620 | { | |
a3f17187 | 6621 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
6622 | fputs_filtered (" ", gdb_stdout); |
6623 | wrap_here (""); | |
6624 | fputs_filtered ("and ", gdb_stdout); | |
6625 | wrap_here (""); | |
6626 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 6627 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
6628 | gdb_flush (gdb_stdout); |
6629 | } | |
6630 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
6631 | } | |
6632 | ||
e38df1d0 | 6633 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
6634 | |
6635 | if (per_cu == NULL) | |
aaa75496 JB |
6636 | { |
6637 | /* It's an include file, no symbols to read for it. | |
6638 | Everything is in the parent symtab. */ | |
6639 | pst->readin = 1; | |
6640 | return; | |
6641 | } | |
c906108c | 6642 | |
a0f42c21 | 6643 | dw2_do_instantiate_symtab (per_cu); |
10b3939b DJ |
6644 | } |
6645 | ||
dee91e82 DE |
6646 | /* Trivial hash function for die_info: the hash value of a DIE |
6647 | is its offset in .debug_info for this objfile. */ | |
10b3939b | 6648 | |
dee91e82 DE |
6649 | static hashval_t |
6650 | die_hash (const void *item) | |
10b3939b | 6651 | { |
dee91e82 | 6652 | const struct die_info *die = item; |
6502dd73 | 6653 | |
dee91e82 DE |
6654 | return die->offset.sect_off; |
6655 | } | |
63d06c5c | 6656 | |
dee91e82 DE |
6657 | /* Trivial comparison function for die_info structures: two DIEs |
6658 | are equal if they have the same offset. */ | |
98bfdba5 | 6659 | |
dee91e82 DE |
6660 | static int |
6661 | die_eq (const void *item_lhs, const void *item_rhs) | |
6662 | { | |
6663 | const struct die_info *die_lhs = item_lhs; | |
6664 | const struct die_info *die_rhs = item_rhs; | |
c906108c | 6665 | |
dee91e82 DE |
6666 | return die_lhs->offset.sect_off == die_rhs->offset.sect_off; |
6667 | } | |
c906108c | 6668 | |
dee91e82 DE |
6669 | /* die_reader_func for load_full_comp_unit. |
6670 | This is identical to read_signatured_type_reader, | |
6671 | but is kept separate for now. */ | |
c906108c | 6672 | |
dee91e82 DE |
6673 | static void |
6674 | load_full_comp_unit_reader (const struct die_reader_specs *reader, | |
6675 | gdb_byte *info_ptr, | |
6676 | struct die_info *comp_unit_die, | |
6677 | int has_children, | |
6678 | void *data) | |
6679 | { | |
6680 | struct dwarf2_cu *cu = reader->cu; | |
95554aad | 6681 | enum language *language_ptr = data; |
6caca83c | 6682 | |
dee91e82 DE |
6683 | gdb_assert (cu->die_hash == NULL); |
6684 | cu->die_hash = | |
6685 | htab_create_alloc_ex (cu->header.length / 12, | |
6686 | die_hash, | |
6687 | die_eq, | |
6688 | NULL, | |
6689 | &cu->comp_unit_obstack, | |
6690 | hashtab_obstack_allocate, | |
6691 | dummy_obstack_deallocate); | |
e142c38c | 6692 | |
dee91e82 DE |
6693 | if (has_children) |
6694 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
6695 | &info_ptr, comp_unit_die); | |
6696 | cu->dies = comp_unit_die; | |
6697 | /* comp_unit_die is not stored in die_hash, no need. */ | |
10b3939b DJ |
6698 | |
6699 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 6700 | all CUs needed for references have been loaded yet, and symbol |
10b3939b | 6701 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
6702 | or we won't be able to build types correctly. |
6703 | Similarly, if we do not read the producer, we can not apply | |
6704 | producer-specific interpretation. */ | |
95554aad | 6705 | prepare_one_comp_unit (cu, cu->dies, *language_ptr); |
dee91e82 | 6706 | } |
10b3939b | 6707 | |
dee91e82 | 6708 | /* Load the DIEs associated with PER_CU into memory. */ |
a6c727b2 | 6709 | |
dee91e82 | 6710 | static void |
95554aad TT |
6711 | load_full_comp_unit (struct dwarf2_per_cu_data *this_cu, |
6712 | enum language pretend_language) | |
dee91e82 | 6713 | { |
3019eac3 | 6714 | gdb_assert (! this_cu->is_debug_types); |
c5b7e1cb | 6715 | |
f4dc4d17 DE |
6716 | init_cutu_and_read_dies (this_cu, NULL, 1, 1, |
6717 | load_full_comp_unit_reader, &pretend_language); | |
10b3939b DJ |
6718 | } |
6719 | ||
3da10d80 KS |
6720 | /* Add a DIE to the delayed physname list. */ |
6721 | ||
6722 | static void | |
6723 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
6724 | const char *name, struct die_info *die, | |
6725 | struct dwarf2_cu *cu) | |
6726 | { | |
6727 | struct delayed_method_info mi; | |
6728 | mi.type = type; | |
6729 | mi.fnfield_index = fnfield_index; | |
6730 | mi.index = index; | |
6731 | mi.name = name; | |
6732 | mi.die = die; | |
6733 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
6734 | } | |
6735 | ||
6736 | /* A cleanup for freeing the delayed method list. */ | |
6737 | ||
6738 | static void | |
6739 | free_delayed_list (void *ptr) | |
6740 | { | |
6741 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
6742 | if (cu->method_list != NULL) | |
6743 | { | |
6744 | VEC_free (delayed_method_info, cu->method_list); | |
6745 | cu->method_list = NULL; | |
6746 | } | |
6747 | } | |
6748 | ||
6749 | /* Compute the physnames of any methods on the CU's method list. | |
6750 | ||
6751 | The computation of method physnames is delayed in order to avoid the | |
6752 | (bad) condition that one of the method's formal parameters is of an as yet | |
6753 | incomplete type. */ | |
6754 | ||
6755 | static void | |
6756 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
6757 | { | |
6758 | int i; | |
6759 | struct delayed_method_info *mi; | |
6760 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
6761 | { | |
1d06ead6 | 6762 | const char *physname; |
3da10d80 KS |
6763 | struct fn_fieldlist *fn_flp |
6764 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
1d06ead6 | 6765 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
3da10d80 KS |
6766 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
6767 | } | |
6768 | } | |
6769 | ||
a766d390 DE |
6770 | /* Go objects should be embedded in a DW_TAG_module DIE, |
6771 | and it's not clear if/how imported objects will appear. | |
6772 | To keep Go support simple until that's worked out, | |
6773 | go back through what we've read and create something usable. | |
6774 | We could do this while processing each DIE, and feels kinda cleaner, | |
6775 | but that way is more invasive. | |
6776 | This is to, for example, allow the user to type "p var" or "b main" | |
6777 | without having to specify the package name, and allow lookups | |
6778 | of module.object to work in contexts that use the expression | |
6779 | parser. */ | |
6780 | ||
6781 | static void | |
6782 | fixup_go_packaging (struct dwarf2_cu *cu) | |
6783 | { | |
6784 | char *package_name = NULL; | |
6785 | struct pending *list; | |
6786 | int i; | |
6787 | ||
6788 | for (list = global_symbols; list != NULL; list = list->next) | |
6789 | { | |
6790 | for (i = 0; i < list->nsyms; ++i) | |
6791 | { | |
6792 | struct symbol *sym = list->symbol[i]; | |
6793 | ||
6794 | if (SYMBOL_LANGUAGE (sym) == language_go | |
6795 | && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
6796 | { | |
6797 | char *this_package_name = go_symbol_package_name (sym); | |
6798 | ||
6799 | if (this_package_name == NULL) | |
6800 | continue; | |
6801 | if (package_name == NULL) | |
6802 | package_name = this_package_name; | |
6803 | else | |
6804 | { | |
6805 | if (strcmp (package_name, this_package_name) != 0) | |
6806 | complaint (&symfile_complaints, | |
6807 | _("Symtab %s has objects from two different Go packages: %s and %s"), | |
210bbc17 | 6808 | (SYMBOL_SYMTAB (sym) |
210bbc17 | 6809 | ? SYMBOL_SYMTAB (sym)->filename |
a766d390 DE |
6810 | : cu->objfile->name), |
6811 | this_package_name, package_name); | |
6812 | xfree (this_package_name); | |
6813 | } | |
6814 | } | |
6815 | } | |
6816 | } | |
6817 | ||
6818 | if (package_name != NULL) | |
6819 | { | |
6820 | struct objfile *objfile = cu->objfile; | |
10f0c4bb TT |
6821 | const char *saved_package_name = obstack_copy0 (&objfile->objfile_obstack, |
6822 | package_name, | |
6823 | strlen (package_name)); | |
a766d390 | 6824 | struct type *type = init_type (TYPE_CODE_MODULE, 0, 0, |
86f62fd7 | 6825 | saved_package_name, objfile); |
a766d390 DE |
6826 | struct symbol *sym; |
6827 | ||
6828 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
6829 | ||
6830 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
6831 | SYMBOL_SET_LANGUAGE (sym, language_go); | |
86f62fd7 TT |
6832 | SYMBOL_SET_NAMES (sym, saved_package_name, |
6833 | strlen (saved_package_name), 0, objfile); | |
a766d390 DE |
6834 | /* This is not VAR_DOMAIN because we want a way to ensure a lookup of, |
6835 | e.g., "main" finds the "main" module and not C's main(). */ | |
6836 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; | |
6837 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
6838 | SYMBOL_TYPE (sym) = type; | |
6839 | ||
6840 | add_symbol_to_list (sym, &global_symbols); | |
6841 | ||
6842 | xfree (package_name); | |
6843 | } | |
6844 | } | |
6845 | ||
95554aad TT |
6846 | static void compute_symtab_includes (struct dwarf2_per_cu_data *per_cu); |
6847 | ||
6848 | /* Return the symtab for PER_CU. This works properly regardless of | |
6849 | whether we're using the index or psymtabs. */ | |
6850 | ||
6851 | static struct symtab * | |
6852 | get_symtab (struct dwarf2_per_cu_data *per_cu) | |
6853 | { | |
6854 | return (dwarf2_per_objfile->using_index | |
6855 | ? per_cu->v.quick->symtab | |
6856 | : per_cu->v.psymtab->symtab); | |
6857 | } | |
6858 | ||
6859 | /* A helper function for computing the list of all symbol tables | |
6860 | included by PER_CU. */ | |
6861 | ||
6862 | static void | |
6863 | recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr) **result, | |
6864 | htab_t all_children, | |
6865 | struct dwarf2_per_cu_data *per_cu) | |
6866 | { | |
6867 | void **slot; | |
6868 | int ix; | |
6869 | struct dwarf2_per_cu_data *iter; | |
6870 | ||
6871 | slot = htab_find_slot (all_children, per_cu, INSERT); | |
6872 | if (*slot != NULL) | |
6873 | { | |
6874 | /* This inclusion and its children have been processed. */ | |
6875 | return; | |
6876 | } | |
6877 | ||
6878 | *slot = per_cu; | |
6879 | /* Only add a CU if it has a symbol table. */ | |
6880 | if (get_symtab (per_cu) != NULL) | |
6881 | VEC_safe_push (dwarf2_per_cu_ptr, *result, per_cu); | |
6882 | ||
6883 | for (ix = 0; | |
796a7ff8 | 6884 | VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter); |
95554aad TT |
6885 | ++ix) |
6886 | recursively_compute_inclusions (result, all_children, iter); | |
6887 | } | |
6888 | ||
6889 | /* Compute the symtab 'includes' fields for the symtab related to | |
6890 | PER_CU. */ | |
6891 | ||
6892 | static void | |
6893 | compute_symtab_includes (struct dwarf2_per_cu_data *per_cu) | |
6894 | { | |
f4dc4d17 DE |
6895 | gdb_assert (! per_cu->is_debug_types); |
6896 | ||
796a7ff8 | 6897 | if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs)) |
95554aad TT |
6898 | { |
6899 | int ix, len; | |
6900 | struct dwarf2_per_cu_data *iter; | |
6901 | VEC (dwarf2_per_cu_ptr) *result_children = NULL; | |
6902 | htab_t all_children; | |
6903 | struct symtab *symtab = get_symtab (per_cu); | |
6904 | ||
6905 | /* If we don't have a symtab, we can just skip this case. */ | |
6906 | if (symtab == NULL) | |
6907 | return; | |
6908 | ||
6909 | all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, | |
6910 | NULL, xcalloc, xfree); | |
6911 | ||
6912 | for (ix = 0; | |
796a7ff8 | 6913 | VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, |
95554aad TT |
6914 | ix, iter); |
6915 | ++ix) | |
6916 | recursively_compute_inclusions (&result_children, all_children, iter); | |
6917 | ||
796a7ff8 DE |
6918 | /* Now we have a transitive closure of all the included CUs, and |
6919 | for .gdb_index version 7 the included TUs, so we can convert it | |
6920 | to a list of symtabs. */ | |
95554aad TT |
6921 | len = VEC_length (dwarf2_per_cu_ptr, result_children); |
6922 | symtab->includes | |
6923 | = obstack_alloc (&dwarf2_per_objfile->objfile->objfile_obstack, | |
6924 | (len + 1) * sizeof (struct symtab *)); | |
6925 | for (ix = 0; | |
6926 | VEC_iterate (dwarf2_per_cu_ptr, result_children, ix, iter); | |
6927 | ++ix) | |
6928 | symtab->includes[ix] = get_symtab (iter); | |
6929 | symtab->includes[len] = NULL; | |
6930 | ||
6931 | VEC_free (dwarf2_per_cu_ptr, result_children); | |
6932 | htab_delete (all_children); | |
6933 | } | |
6934 | } | |
6935 | ||
6936 | /* Compute the 'includes' field for the symtabs of all the CUs we just | |
6937 | read. */ | |
6938 | ||
6939 | static void | |
6940 | process_cu_includes (void) | |
6941 | { | |
6942 | int ix; | |
6943 | struct dwarf2_per_cu_data *iter; | |
6944 | ||
6945 | for (ix = 0; | |
6946 | VEC_iterate (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, | |
6947 | ix, iter); | |
6948 | ++ix) | |
f4dc4d17 DE |
6949 | { |
6950 | if (! iter->is_debug_types) | |
6951 | compute_symtab_includes (iter); | |
6952 | } | |
95554aad TT |
6953 | |
6954 | VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus); | |
6955 | } | |
6956 | ||
9cdd5dbd | 6957 | /* Generate full symbol information for PER_CU, whose DIEs have |
10b3939b DJ |
6958 | already been loaded into memory. */ |
6959 | ||
6960 | static void | |
95554aad TT |
6961 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, |
6962 | enum language pretend_language) | |
10b3939b | 6963 | { |
10b3939b | 6964 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 6965 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
6966 | CORE_ADDR lowpc, highpc; |
6967 | struct symtab *symtab; | |
3da10d80 | 6968 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b | 6969 | CORE_ADDR baseaddr; |
4359dff1 | 6970 | struct block *static_block; |
10b3939b DJ |
6971 | |
6972 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6973 | ||
10b3939b DJ |
6974 | buildsym_init (); |
6975 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 6976 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
6977 | |
6978 | cu->list_in_scope = &file_symbols; | |
c906108c | 6979 | |
95554aad TT |
6980 | cu->language = pretend_language; |
6981 | cu->language_defn = language_def (cu->language); | |
6982 | ||
c906108c | 6983 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 6984 | process_die (cu->dies, cu); |
c906108c | 6985 | |
a766d390 DE |
6986 | /* For now fudge the Go package. */ |
6987 | if (cu->language == language_go) | |
6988 | fixup_go_packaging (cu); | |
6989 | ||
3da10d80 KS |
6990 | /* Now that we have processed all the DIEs in the CU, all the types |
6991 | should be complete, and it should now be safe to compute all of the | |
6992 | physnames. */ | |
6993 | compute_delayed_physnames (cu); | |
6994 | do_cleanups (delayed_list_cleanup); | |
6995 | ||
fae299cd DC |
6996 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
6997 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
6998 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 6999 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 7000 | |
36586728 TT |
7001 | static_block |
7002 | = end_symtab_get_static_block (highpc + baseaddr, objfile, 0, | |
796a7ff8 | 7003 | per_cu->imported_symtabs != NULL); |
4359dff1 JK |
7004 | |
7005 | /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges. | |
7006 | Also, DW_AT_ranges may record ranges not belonging to any child DIEs | |
7007 | (such as virtual method tables). Record the ranges in STATIC_BLOCK's | |
7008 | addrmap to help ensure it has an accurate map of pc values belonging to | |
7009 | this comp unit. */ | |
7010 | dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu); | |
7011 | ||
7012 | symtab = end_symtab_from_static_block (static_block, objfile, | |
7013 | SECT_OFF_TEXT (objfile), 0); | |
c906108c | 7014 | |
8be455d7 | 7015 | if (symtab != NULL) |
c906108c | 7016 | { |
df15bd07 | 7017 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
4632c0d0 | 7018 | |
8be455d7 JK |
7019 | /* Set symtab language to language from DW_AT_language. If the |
7020 | compilation is from a C file generated by language preprocessors, do | |
7021 | not set the language if it was already deduced by start_subfile. */ | |
7022 | if (!(cu->language == language_c && symtab->language != language_c)) | |
7023 | symtab->language = cu->language; | |
7024 | ||
7025 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
7026 | produce DW_AT_location with location lists but it can be possibly | |
ab260dad JK |
7027 | invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0 |
7028 | there were bugs in prologue debug info, fixed later in GCC-4.5 | |
7029 | by "unwind info for epilogues" patch (which is not directly related). | |
8be455d7 JK |
7030 | |
7031 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
7032 | needed, it would be wrong due to missing DW_AT_producer there. | |
7033 | ||
7034 | Still one can confuse GDB by using non-standard GCC compilation | |
7035 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
7036 | */ | |
ab260dad | 7037 | if (cu->has_loclist && gcc_4_minor >= 5) |
8be455d7 | 7038 | symtab->locations_valid = 1; |
e0d00bc7 JK |
7039 | |
7040 | if (gcc_4_minor >= 5) | |
7041 | symtab->epilogue_unwind_valid = 1; | |
96408a79 SA |
7042 | |
7043 | symtab->call_site_htab = cu->call_site_htab; | |
c906108c | 7044 | } |
9291a0cd TT |
7045 | |
7046 | if (dwarf2_per_objfile->using_index) | |
7047 | per_cu->v.quick->symtab = symtab; | |
7048 | else | |
7049 | { | |
7050 | struct partial_symtab *pst = per_cu->v.psymtab; | |
7051 | pst->symtab = symtab; | |
7052 | pst->readin = 1; | |
7053 | } | |
c906108c | 7054 | |
95554aad TT |
7055 | /* Push it for inclusion processing later. */ |
7056 | VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu); | |
7057 | ||
c906108c | 7058 | do_cleanups (back_to); |
f4dc4d17 | 7059 | } |
45cfd468 | 7060 | |
f4dc4d17 DE |
7061 | /* Generate full symbol information for type unit PER_CU, whose DIEs have |
7062 | already been loaded into memory. */ | |
7063 | ||
7064 | static void | |
7065 | process_full_type_unit (struct dwarf2_per_cu_data *per_cu, | |
7066 | enum language pretend_language) | |
7067 | { | |
7068 | struct dwarf2_cu *cu = per_cu->cu; | |
7069 | struct objfile *objfile = per_cu->objfile; | |
7070 | struct symtab *symtab; | |
7071 | struct cleanup *back_to, *delayed_list_cleanup; | |
7072 | ||
7073 | buildsym_init (); | |
7074 | back_to = make_cleanup (really_free_pendings, NULL); | |
7075 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); | |
7076 | ||
7077 | cu->list_in_scope = &file_symbols; | |
7078 | ||
7079 | cu->language = pretend_language; | |
7080 | cu->language_defn = language_def (cu->language); | |
7081 | ||
7082 | /* The symbol tables are set up in read_type_unit_scope. */ | |
7083 | process_die (cu->dies, cu); | |
7084 | ||
7085 | /* For now fudge the Go package. */ | |
7086 | if (cu->language == language_go) | |
7087 | fixup_go_packaging (cu); | |
7088 | ||
7089 | /* Now that we have processed all the DIEs in the CU, all the types | |
7090 | should be complete, and it should now be safe to compute all of the | |
7091 | physnames. */ | |
7092 | compute_delayed_physnames (cu); | |
7093 | do_cleanups (delayed_list_cleanup); | |
7094 | ||
7095 | /* TUs share symbol tables. | |
7096 | If this is the first TU to use this symtab, complete the construction | |
094b34ac DE |
7097 | of it with end_expandable_symtab. Otherwise, complete the addition of |
7098 | this TU's symbols to the existing symtab. */ | |
796a7ff8 | 7099 | if (per_cu->type_unit_group->primary_symtab == NULL) |
45cfd468 | 7100 | { |
f4dc4d17 | 7101 | symtab = end_expandable_symtab (0, objfile, SECT_OFF_TEXT (objfile)); |
796a7ff8 | 7102 | per_cu->type_unit_group->primary_symtab = symtab; |
f4dc4d17 DE |
7103 | |
7104 | if (symtab != NULL) | |
7105 | { | |
7106 | /* Set symtab language to language from DW_AT_language. If the | |
7107 | compilation is from a C file generated by language preprocessors, | |
7108 | do not set the language if it was already deduced by | |
7109 | start_subfile. */ | |
7110 | if (!(cu->language == language_c && symtab->language != language_c)) | |
7111 | symtab->language = cu->language; | |
7112 | } | |
7113 | } | |
7114 | else | |
7115 | { | |
7116 | augment_type_symtab (objfile, | |
796a7ff8 DE |
7117 | per_cu->type_unit_group->primary_symtab); |
7118 | symtab = per_cu->type_unit_group->primary_symtab; | |
f4dc4d17 DE |
7119 | } |
7120 | ||
7121 | if (dwarf2_per_objfile->using_index) | |
7122 | per_cu->v.quick->symtab = symtab; | |
7123 | else | |
7124 | { | |
7125 | struct partial_symtab *pst = per_cu->v.psymtab; | |
7126 | pst->symtab = symtab; | |
7127 | pst->readin = 1; | |
45cfd468 | 7128 | } |
f4dc4d17 DE |
7129 | |
7130 | do_cleanups (back_to); | |
c906108c SS |
7131 | } |
7132 | ||
95554aad TT |
7133 | /* Process an imported unit DIE. */ |
7134 | ||
7135 | static void | |
7136 | process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu) | |
7137 | { | |
7138 | struct attribute *attr; | |
7139 | ||
f4dc4d17 DE |
7140 | /* For now we don't handle imported units in type units. */ |
7141 | if (cu->per_cu->is_debug_types) | |
7142 | { | |
7143 | error (_("Dwarf Error: DW_TAG_imported_unit is not" | |
7144 | " supported in type units [in module %s]"), | |
7145 | cu->objfile->name); | |
7146 | } | |
7147 | ||
95554aad TT |
7148 | attr = dwarf2_attr (die, DW_AT_import, cu); |
7149 | if (attr != NULL) | |
7150 | { | |
7151 | struct dwarf2_per_cu_data *per_cu; | |
7152 | struct symtab *imported_symtab; | |
7153 | sect_offset offset; | |
36586728 | 7154 | int is_dwz; |
95554aad TT |
7155 | |
7156 | offset = dwarf2_get_ref_die_offset (attr); | |
36586728 TT |
7157 | is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz); |
7158 | per_cu = dwarf2_find_containing_comp_unit (offset, is_dwz, cu->objfile); | |
95554aad TT |
7159 | |
7160 | /* Queue the unit, if needed. */ | |
7161 | if (maybe_queue_comp_unit (cu, per_cu, cu->language)) | |
7162 | load_full_comp_unit (per_cu, cu->language); | |
7163 | ||
796a7ff8 | 7164 | VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, |
95554aad TT |
7165 | per_cu); |
7166 | } | |
7167 | } | |
7168 | ||
c906108c SS |
7169 | /* Process a die and its children. */ |
7170 | ||
7171 | static void | |
e7c27a73 | 7172 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7173 | { |
7174 | switch (die->tag) | |
7175 | { | |
7176 | case DW_TAG_padding: | |
7177 | break; | |
7178 | case DW_TAG_compile_unit: | |
95554aad | 7179 | case DW_TAG_partial_unit: |
e7c27a73 | 7180 | read_file_scope (die, cu); |
c906108c | 7181 | break; |
348e048f DE |
7182 | case DW_TAG_type_unit: |
7183 | read_type_unit_scope (die, cu); | |
7184 | break; | |
c906108c | 7185 | case DW_TAG_subprogram: |
c906108c | 7186 | case DW_TAG_inlined_subroutine: |
edb3359d | 7187 | read_func_scope (die, cu); |
c906108c SS |
7188 | break; |
7189 | case DW_TAG_lexical_block: | |
14898363 L |
7190 | case DW_TAG_try_block: |
7191 | case DW_TAG_catch_block: | |
e7c27a73 | 7192 | read_lexical_block_scope (die, cu); |
c906108c | 7193 | break; |
96408a79 SA |
7194 | case DW_TAG_GNU_call_site: |
7195 | read_call_site_scope (die, cu); | |
7196 | break; | |
c906108c | 7197 | case DW_TAG_class_type: |
680b30c7 | 7198 | case DW_TAG_interface_type: |
c906108c SS |
7199 | case DW_TAG_structure_type: |
7200 | case DW_TAG_union_type: | |
134d01f1 | 7201 | process_structure_scope (die, cu); |
c906108c SS |
7202 | break; |
7203 | case DW_TAG_enumeration_type: | |
134d01f1 | 7204 | process_enumeration_scope (die, cu); |
c906108c | 7205 | break; |
134d01f1 | 7206 | |
f792889a DJ |
7207 | /* These dies have a type, but processing them does not create |
7208 | a symbol or recurse to process the children. Therefore we can | |
7209 | read them on-demand through read_type_die. */ | |
c906108c | 7210 | case DW_TAG_subroutine_type: |
72019c9c | 7211 | case DW_TAG_set_type: |
c906108c | 7212 | case DW_TAG_array_type: |
c906108c | 7213 | case DW_TAG_pointer_type: |
c906108c | 7214 | case DW_TAG_ptr_to_member_type: |
c906108c | 7215 | case DW_TAG_reference_type: |
c906108c | 7216 | case DW_TAG_string_type: |
c906108c | 7217 | break; |
134d01f1 | 7218 | |
c906108c | 7219 | case DW_TAG_base_type: |
a02abb62 | 7220 | case DW_TAG_subrange_type: |
cb249c71 | 7221 | case DW_TAG_typedef: |
134d01f1 DJ |
7222 | /* Add a typedef symbol for the type definition, if it has a |
7223 | DW_AT_name. */ | |
f792889a | 7224 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 7225 | break; |
c906108c | 7226 | case DW_TAG_common_block: |
e7c27a73 | 7227 | read_common_block (die, cu); |
c906108c SS |
7228 | break; |
7229 | case DW_TAG_common_inclusion: | |
7230 | break; | |
d9fa45fe | 7231 | case DW_TAG_namespace: |
63d06c5c | 7232 | processing_has_namespace_info = 1; |
e7c27a73 | 7233 | read_namespace (die, cu); |
d9fa45fe | 7234 | break; |
5d7cb8df | 7235 | case DW_TAG_module: |
f55ee35c | 7236 | processing_has_namespace_info = 1; |
5d7cb8df JK |
7237 | read_module (die, cu); |
7238 | break; | |
d9fa45fe DC |
7239 | case DW_TAG_imported_declaration: |
7240 | case DW_TAG_imported_module: | |
63d06c5c | 7241 | processing_has_namespace_info = 1; |
27aa8d6a SW |
7242 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
7243 | || cu->language != language_fortran)) | |
7244 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
7245 | dwarf_tag_name (die->tag)); | |
7246 | read_import_statement (die, cu); | |
d9fa45fe | 7247 | break; |
95554aad TT |
7248 | |
7249 | case DW_TAG_imported_unit: | |
7250 | process_imported_unit_die (die, cu); | |
7251 | break; | |
7252 | ||
c906108c | 7253 | default: |
e7c27a73 | 7254 | new_symbol (die, NULL, cu); |
c906108c SS |
7255 | break; |
7256 | } | |
7257 | } | |
7258 | ||
94af9270 KS |
7259 | /* A helper function for dwarf2_compute_name which determines whether DIE |
7260 | needs to have the name of the scope prepended to the name listed in the | |
7261 | die. */ | |
7262 | ||
7263 | static int | |
7264 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
7265 | { | |
1c809c68 TT |
7266 | struct attribute *attr; |
7267 | ||
94af9270 KS |
7268 | switch (die->tag) |
7269 | { | |
7270 | case DW_TAG_namespace: | |
7271 | case DW_TAG_typedef: | |
7272 | case DW_TAG_class_type: | |
7273 | case DW_TAG_interface_type: | |
7274 | case DW_TAG_structure_type: | |
7275 | case DW_TAG_union_type: | |
7276 | case DW_TAG_enumeration_type: | |
7277 | case DW_TAG_enumerator: | |
7278 | case DW_TAG_subprogram: | |
7279 | case DW_TAG_member: | |
7280 | return 1; | |
7281 | ||
7282 | case DW_TAG_variable: | |
c2b0a229 | 7283 | case DW_TAG_constant: |
94af9270 KS |
7284 | /* We only need to prefix "globally" visible variables. These include |
7285 | any variable marked with DW_AT_external or any variable that | |
7286 | lives in a namespace. [Variables in anonymous namespaces | |
7287 | require prefixing, but they are not DW_AT_external.] */ | |
7288 | ||
7289 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
7290 | { | |
7291 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 7292 | |
94af9270 KS |
7293 | return die_needs_namespace (die_specification (die, &spec_cu), |
7294 | spec_cu); | |
7295 | } | |
7296 | ||
1c809c68 | 7297 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
7298 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
7299 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
7300 | return 0; |
7301 | /* A variable in a lexical block of some kind does not need a | |
7302 | namespace, even though in C++ such variables may be external | |
7303 | and have a mangled name. */ | |
7304 | if (die->parent->tag == DW_TAG_lexical_block | |
7305 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
7306 | || die->parent->tag == DW_TAG_catch_block |
7307 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
7308 | return 0; |
7309 | return 1; | |
94af9270 KS |
7310 | |
7311 | default: | |
7312 | return 0; | |
7313 | } | |
7314 | } | |
7315 | ||
98bfdba5 PA |
7316 | /* Retrieve the last character from a mem_file. */ |
7317 | ||
7318 | static void | |
7319 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
7320 | { | |
7321 | char *last_char_p = (char *) object; | |
7322 | ||
7323 | if (length > 0) | |
7324 | *last_char_p = buffer[length - 1]; | |
7325 | } | |
7326 | ||
94af9270 | 7327 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
a766d390 DE |
7328 | compute the physname for the object, which include a method's: |
7329 | - formal parameters (C++/Java), | |
7330 | - receiver type (Go), | |
7331 | - return type (Java). | |
7332 | ||
7333 | The term "physname" is a bit confusing. | |
7334 | For C++, for example, it is the demangled name. | |
7335 | For Go, for example, it's the mangled name. | |
94af9270 | 7336 | |
af6b7be1 JB |
7337 | For Ada, return the DIE's linkage name rather than the fully qualified |
7338 | name. PHYSNAME is ignored.. | |
7339 | ||
94af9270 KS |
7340 | The result is allocated on the objfile_obstack and canonicalized. */ |
7341 | ||
7342 | static const char * | |
15d034d0 TT |
7343 | dwarf2_compute_name (const char *name, |
7344 | struct die_info *die, struct dwarf2_cu *cu, | |
94af9270 KS |
7345 | int physname) |
7346 | { | |
bb5ed363 DE |
7347 | struct objfile *objfile = cu->objfile; |
7348 | ||
94af9270 KS |
7349 | if (name == NULL) |
7350 | name = dwarf2_name (die, cu); | |
7351 | ||
f55ee35c JK |
7352 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
7353 | compute it by typename_concat inside GDB. */ | |
7354 | if (cu->language == language_ada | |
7355 | || (cu->language == language_fortran && physname)) | |
7356 | { | |
7357 | /* For Ada unit, we prefer the linkage name over the name, as | |
7358 | the former contains the exported name, which the user expects | |
7359 | to be able to reference. Ideally, we want the user to be able | |
7360 | to reference this entity using either natural or linkage name, | |
7361 | but we haven't started looking at this enhancement yet. */ | |
7362 | struct attribute *attr; | |
7363 | ||
7364 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
7365 | if (attr == NULL) | |
7366 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
7367 | if (attr && DW_STRING (attr)) | |
7368 | return DW_STRING (attr); | |
7369 | } | |
7370 | ||
94af9270 KS |
7371 | /* These are the only languages we know how to qualify names in. */ |
7372 | if (name != NULL | |
f55ee35c JK |
7373 | && (cu->language == language_cplus || cu->language == language_java |
7374 | || cu->language == language_fortran)) | |
94af9270 KS |
7375 | { |
7376 | if (die_needs_namespace (die, cu)) | |
7377 | { | |
7378 | long length; | |
0d5cff50 | 7379 | const char *prefix; |
94af9270 KS |
7380 | struct ui_file *buf; |
7381 | ||
7382 | prefix = determine_prefix (die, cu); | |
7383 | buf = mem_fileopen (); | |
7384 | if (*prefix != '\0') | |
7385 | { | |
f55ee35c JK |
7386 | char *prefixed_name = typename_concat (NULL, prefix, name, |
7387 | physname, cu); | |
9a619af0 | 7388 | |
94af9270 KS |
7389 | fputs_unfiltered (prefixed_name, buf); |
7390 | xfree (prefixed_name); | |
7391 | } | |
7392 | else | |
62d5b8da | 7393 | fputs_unfiltered (name, buf); |
94af9270 | 7394 | |
98bfdba5 PA |
7395 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
7396 | as children with DW_TAG_template_type_param or | |
7397 | DW_TAG_value_type_param. If the latter, add them to the name | |
7398 | here. If the name already has template parameters, then | |
7399 | skip this step; some versions of GCC emit both, and | |
7400 | it is more efficient to use the pre-computed name. | |
7401 | ||
7402 | Something to keep in mind about this process: it is very | |
7403 | unlikely, or in some cases downright impossible, to produce | |
7404 | something that will match the mangled name of a function. | |
7405 | If the definition of the function has the same debug info, | |
7406 | we should be able to match up with it anyway. But fallbacks | |
7407 | using the minimal symbol, for instance to find a method | |
7408 | implemented in a stripped copy of libstdc++, will not work. | |
7409 | If we do not have debug info for the definition, we will have to | |
7410 | match them up some other way. | |
7411 | ||
7412 | When we do name matching there is a related problem with function | |
7413 | templates; two instantiated function templates are allowed to | |
7414 | differ only by their return types, which we do not add here. */ | |
7415 | ||
7416 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
7417 | { | |
7418 | struct attribute *attr; | |
7419 | struct die_info *child; | |
7420 | int first = 1; | |
7421 | ||
7422 | die->building_fullname = 1; | |
7423 | ||
7424 | for (child = die->child; child != NULL; child = child->sibling) | |
7425 | { | |
7426 | struct type *type; | |
12df843f | 7427 | LONGEST value; |
98bfdba5 PA |
7428 | gdb_byte *bytes; |
7429 | struct dwarf2_locexpr_baton *baton; | |
7430 | struct value *v; | |
7431 | ||
7432 | if (child->tag != DW_TAG_template_type_param | |
7433 | && child->tag != DW_TAG_template_value_param) | |
7434 | continue; | |
7435 | ||
7436 | if (first) | |
7437 | { | |
7438 | fputs_unfiltered ("<", buf); | |
7439 | first = 0; | |
7440 | } | |
7441 | else | |
7442 | fputs_unfiltered (", ", buf); | |
7443 | ||
7444 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
7445 | if (attr == NULL) | |
7446 | { | |
7447 | complaint (&symfile_complaints, | |
7448 | _("template parameter missing DW_AT_type")); | |
7449 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
7450 | continue; | |
7451 | } | |
7452 | type = die_type (child, cu); | |
7453 | ||
7454 | if (child->tag == DW_TAG_template_type_param) | |
7455 | { | |
79d43c61 | 7456 | c_print_type (type, "", buf, -1, 0, &type_print_raw_options); |
98bfdba5 PA |
7457 | continue; |
7458 | } | |
7459 | ||
7460 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
7461 | if (attr == NULL) | |
7462 | { | |
7463 | complaint (&symfile_complaints, | |
3e43a32a MS |
7464 | _("template parameter missing " |
7465 | "DW_AT_const_value")); | |
98bfdba5 PA |
7466 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
7467 | continue; | |
7468 | } | |
7469 | ||
7470 | dwarf2_const_value_attr (attr, type, name, | |
7471 | &cu->comp_unit_obstack, cu, | |
7472 | &value, &bytes, &baton); | |
7473 | ||
7474 | if (TYPE_NOSIGN (type)) | |
7475 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
7476 | changed, this can use value_print instead. */ | |
7477 | c_printchar (value, type, buf); | |
7478 | else | |
7479 | { | |
7480 | struct value_print_options opts; | |
7481 | ||
7482 | if (baton != NULL) | |
7483 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
7484 | baton->data, | |
7485 | baton->size, | |
7486 | baton->per_cu); | |
7487 | else if (bytes != NULL) | |
7488 | { | |
7489 | v = allocate_value (type); | |
7490 | memcpy (value_contents_writeable (v), bytes, | |
7491 | TYPE_LENGTH (type)); | |
7492 | } | |
7493 | else | |
7494 | v = value_from_longest (type, value); | |
7495 | ||
3e43a32a MS |
7496 | /* Specify decimal so that we do not depend on |
7497 | the radix. */ | |
98bfdba5 PA |
7498 | get_formatted_print_options (&opts, 'd'); |
7499 | opts.raw = 1; | |
7500 | value_print (v, buf, &opts); | |
7501 | release_value (v); | |
7502 | value_free (v); | |
7503 | } | |
7504 | } | |
7505 | ||
7506 | die->building_fullname = 0; | |
7507 | ||
7508 | if (!first) | |
7509 | { | |
7510 | /* Close the argument list, with a space if necessary | |
7511 | (nested templates). */ | |
7512 | char last_char = '\0'; | |
7513 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
7514 | if (last_char == '>') | |
7515 | fputs_unfiltered (" >", buf); | |
7516 | else | |
7517 | fputs_unfiltered (">", buf); | |
7518 | } | |
7519 | } | |
7520 | ||
94af9270 KS |
7521 | /* For Java and C++ methods, append formal parameter type |
7522 | information, if PHYSNAME. */ | |
6e70227d | 7523 | |
94af9270 KS |
7524 | if (physname && die->tag == DW_TAG_subprogram |
7525 | && (cu->language == language_cplus | |
7526 | || cu->language == language_java)) | |
7527 | { | |
7528 | struct type *type = read_type_die (die, cu); | |
7529 | ||
79d43c61 TT |
7530 | c_type_print_args (type, buf, 1, cu->language, |
7531 | &type_print_raw_options); | |
94af9270 KS |
7532 | |
7533 | if (cu->language == language_java) | |
7534 | { | |
7535 | /* For java, we must append the return type to method | |
0963b4bd | 7536 | names. */ |
94af9270 KS |
7537 | if (die->tag == DW_TAG_subprogram) |
7538 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
79d43c61 | 7539 | 0, 0, &type_print_raw_options); |
94af9270 KS |
7540 | } |
7541 | else if (cu->language == language_cplus) | |
7542 | { | |
60430eff DJ |
7543 | /* Assume that an artificial first parameter is |
7544 | "this", but do not crash if it is not. RealView | |
7545 | marks unnamed (and thus unused) parameters as | |
7546 | artificial; there is no way to differentiate | |
7547 | the two cases. */ | |
94af9270 KS |
7548 | if (TYPE_NFIELDS (type) > 0 |
7549 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 7550 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
7551 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
7552 | 0)))) | |
94af9270 KS |
7553 | fputs_unfiltered (" const", buf); |
7554 | } | |
7555 | } | |
7556 | ||
bb5ed363 | 7557 | name = ui_file_obsavestring (buf, &objfile->objfile_obstack, |
94af9270 KS |
7558 | &length); |
7559 | ui_file_delete (buf); | |
7560 | ||
7561 | if (cu->language == language_cplus) | |
7562 | { | |
15d034d0 | 7563 | const char *cname |
94af9270 | 7564 | = dwarf2_canonicalize_name (name, cu, |
bb5ed363 | 7565 | &objfile->objfile_obstack); |
9a619af0 | 7566 | |
94af9270 KS |
7567 | if (cname != NULL) |
7568 | name = cname; | |
7569 | } | |
7570 | } | |
7571 | } | |
7572 | ||
7573 | return name; | |
7574 | } | |
7575 | ||
0114d602 DJ |
7576 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
7577 | If scope qualifiers are appropriate they will be added. The result | |
7578 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
7579 | not have a name. NAME may either be from a previous call to |
7580 | dwarf2_name or NULL. | |
7581 | ||
0963b4bd | 7582 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
7583 | |
7584 | static const char * | |
15d034d0 | 7585 | dwarf2_full_name (const char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 7586 | { |
94af9270 KS |
7587 | return dwarf2_compute_name (name, die, cu, 0); |
7588 | } | |
0114d602 | 7589 | |
94af9270 KS |
7590 | /* Construct a physname for the given DIE in CU. NAME may either be |
7591 | from a previous call to dwarf2_name or NULL. The result will be | |
7592 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
7593 | name. | |
0114d602 | 7594 | |
94af9270 | 7595 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 7596 | |
94af9270 | 7597 | static const char * |
15d034d0 | 7598 | dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu) |
94af9270 | 7599 | { |
bb5ed363 | 7600 | struct objfile *objfile = cu->objfile; |
900e11f9 JK |
7601 | struct attribute *attr; |
7602 | const char *retval, *mangled = NULL, *canon = NULL; | |
7603 | struct cleanup *back_to; | |
7604 | int need_copy = 1; | |
7605 | ||
7606 | /* In this case dwarf2_compute_name is just a shortcut not building anything | |
7607 | on its own. */ | |
7608 | if (!die_needs_namespace (die, cu)) | |
7609 | return dwarf2_compute_name (name, die, cu, 1); | |
7610 | ||
7611 | back_to = make_cleanup (null_cleanup, NULL); | |
7612 | ||
7613 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
7614 | if (!attr) | |
7615 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
7616 | ||
7617 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB | |
7618 | has computed. */ | |
7619 | if (attr && DW_STRING (attr)) | |
7620 | { | |
7621 | char *demangled; | |
7622 | ||
7623 | mangled = DW_STRING (attr); | |
7624 | ||
7625 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return | |
7626 | type. It is easier for GDB users to search for such functions as | |
7627 | `name(params)' than `long name(params)'. In such case the minimal | |
7628 | symbol names do not match the full symbol names but for template | |
7629 | functions there is never a need to look up their definition from their | |
7630 | declaration so the only disadvantage remains the minimal symbol | |
7631 | variant `long name(params)' does not have the proper inferior type. | |
7632 | */ | |
7633 | ||
a766d390 DE |
7634 | if (cu->language == language_go) |
7635 | { | |
7636 | /* This is a lie, but we already lie to the caller new_symbol_full. | |
7637 | new_symbol_full assumes we return the mangled name. | |
7638 | This just undoes that lie until things are cleaned up. */ | |
7639 | demangled = NULL; | |
7640 | } | |
7641 | else | |
7642 | { | |
7643 | demangled = cplus_demangle (mangled, | |
7644 | (DMGL_PARAMS | DMGL_ANSI | |
7645 | | (cu->language == language_java | |
7646 | ? DMGL_JAVA | DMGL_RET_POSTFIX | |
7647 | : DMGL_RET_DROP))); | |
7648 | } | |
900e11f9 JK |
7649 | if (demangled) |
7650 | { | |
7651 | make_cleanup (xfree, demangled); | |
7652 | canon = demangled; | |
7653 | } | |
7654 | else | |
7655 | { | |
7656 | canon = mangled; | |
7657 | need_copy = 0; | |
7658 | } | |
7659 | } | |
7660 | ||
7661 | if (canon == NULL || check_physname) | |
7662 | { | |
7663 | const char *physname = dwarf2_compute_name (name, die, cu, 1); | |
7664 | ||
7665 | if (canon != NULL && strcmp (physname, canon) != 0) | |
7666 | { | |
7667 | /* It may not mean a bug in GDB. The compiler could also | |
7668 | compute DW_AT_linkage_name incorrectly. But in such case | |
7669 | GDB would need to be bug-to-bug compatible. */ | |
7670 | ||
7671 | complaint (&symfile_complaints, | |
7672 | _("Computed physname <%s> does not match demangled <%s> " | |
7673 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), | |
b64f50a1 | 7674 | physname, canon, mangled, die->offset.sect_off, objfile->name); |
900e11f9 JK |
7675 | |
7676 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it | |
7677 | is available here - over computed PHYSNAME. It is safer | |
7678 | against both buggy GDB and buggy compilers. */ | |
7679 | ||
7680 | retval = canon; | |
7681 | } | |
7682 | else | |
7683 | { | |
7684 | retval = physname; | |
7685 | need_copy = 0; | |
7686 | } | |
7687 | } | |
7688 | else | |
7689 | retval = canon; | |
7690 | ||
7691 | if (need_copy) | |
10f0c4bb | 7692 | retval = obstack_copy0 (&objfile->objfile_obstack, retval, strlen (retval)); |
900e11f9 JK |
7693 | |
7694 | do_cleanups (back_to); | |
7695 | return retval; | |
0114d602 DJ |
7696 | } |
7697 | ||
27aa8d6a SW |
7698 | /* Read the import statement specified by the given die and record it. */ |
7699 | ||
7700 | static void | |
7701 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
7702 | { | |
bb5ed363 | 7703 | struct objfile *objfile = cu->objfile; |
27aa8d6a | 7704 | struct attribute *import_attr; |
32019081 | 7705 | struct die_info *imported_die, *child_die; |
de4affc9 | 7706 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 7707 | const char *imported_name; |
794684b6 | 7708 | const char *imported_name_prefix; |
13387711 SW |
7709 | const char *canonical_name; |
7710 | const char *import_alias; | |
7711 | const char *imported_declaration = NULL; | |
794684b6 | 7712 | const char *import_prefix; |
32019081 JK |
7713 | VEC (const_char_ptr) *excludes = NULL; |
7714 | struct cleanup *cleanups; | |
13387711 SW |
7715 | |
7716 | char *temp; | |
27aa8d6a SW |
7717 | |
7718 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
7719 | if (import_attr == NULL) | |
7720 | { | |
7721 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
7722 | dwarf_tag_name (die->tag)); | |
7723 | return; | |
7724 | } | |
7725 | ||
de4affc9 CC |
7726 | imported_cu = cu; |
7727 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
7728 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
7729 | if (imported_name == NULL) |
7730 | { | |
7731 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
7732 | ||
7733 | The import in the following code: | |
7734 | namespace A | |
7735 | { | |
7736 | typedef int B; | |
7737 | } | |
7738 | ||
7739 | int main () | |
7740 | { | |
7741 | using A::B; | |
7742 | B b; | |
7743 | return b; | |
7744 | } | |
7745 | ||
7746 | ... | |
7747 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
7748 | <52> DW_AT_decl_file : 1 | |
7749 | <53> DW_AT_decl_line : 6 | |
7750 | <54> DW_AT_import : <0x75> | |
7751 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
7752 | <59> DW_AT_name : B | |
7753 | <5b> DW_AT_decl_file : 1 | |
7754 | <5c> DW_AT_decl_line : 2 | |
7755 | <5d> DW_AT_type : <0x6e> | |
7756 | ... | |
7757 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
7758 | <76> DW_AT_byte_size : 4 | |
7759 | <77> DW_AT_encoding : 5 (signed) | |
7760 | ||
7761 | imports the wrong die ( 0x75 instead of 0x58 ). | |
7762 | This case will be ignored until the gcc bug is fixed. */ | |
7763 | return; | |
7764 | } | |
7765 | ||
82856980 SW |
7766 | /* Figure out the local name after import. */ |
7767 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 7768 | |
794684b6 SW |
7769 | /* Figure out where the statement is being imported to. */ |
7770 | import_prefix = determine_prefix (die, cu); | |
7771 | ||
7772 | /* Figure out what the scope of the imported die is and prepend it | |
7773 | to the name of the imported die. */ | |
de4affc9 | 7774 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 7775 | |
f55ee35c JK |
7776 | if (imported_die->tag != DW_TAG_namespace |
7777 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 7778 | { |
13387711 SW |
7779 | imported_declaration = imported_name; |
7780 | canonical_name = imported_name_prefix; | |
794684b6 | 7781 | } |
13387711 | 7782 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 7783 | { |
13387711 SW |
7784 | temp = alloca (strlen (imported_name_prefix) |
7785 | + 2 + strlen (imported_name) + 1); | |
7786 | strcpy (temp, imported_name_prefix); | |
7787 | strcat (temp, "::"); | |
7788 | strcat (temp, imported_name); | |
7789 | canonical_name = temp; | |
794684b6 | 7790 | } |
13387711 SW |
7791 | else |
7792 | canonical_name = imported_name; | |
794684b6 | 7793 | |
32019081 JK |
7794 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
7795 | ||
7796 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) | |
7797 | for (child_die = die->child; child_die && child_die->tag; | |
7798 | child_die = sibling_die (child_die)) | |
7799 | { | |
7800 | /* DWARF-4: A Fortran use statement with a “rename list” may be | |
7801 | represented by an imported module entry with an import attribute | |
7802 | referring to the module and owned entries corresponding to those | |
7803 | entities that are renamed as part of being imported. */ | |
7804 | ||
7805 | if (child_die->tag != DW_TAG_imported_declaration) | |
7806 | { | |
7807 | complaint (&symfile_complaints, | |
7808 | _("child DW_TAG_imported_declaration expected " | |
7809 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 7810 | child_die->offset.sect_off, objfile->name); |
32019081 JK |
7811 | continue; |
7812 | } | |
7813 | ||
7814 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); | |
7815 | if (import_attr == NULL) | |
7816 | { | |
7817 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
7818 | dwarf_tag_name (child_die->tag)); | |
7819 | continue; | |
7820 | } | |
7821 | ||
7822 | imported_cu = cu; | |
7823 | imported_die = follow_die_ref_or_sig (child_die, import_attr, | |
7824 | &imported_cu); | |
7825 | imported_name = dwarf2_name (imported_die, imported_cu); | |
7826 | if (imported_name == NULL) | |
7827 | { | |
7828 | complaint (&symfile_complaints, | |
7829 | _("child DW_TAG_imported_declaration has unknown " | |
7830 | "imported name - DIE at 0x%x [in module %s]"), | |
b64f50a1 | 7831 | child_die->offset.sect_off, objfile->name); |
32019081 JK |
7832 | continue; |
7833 | } | |
7834 | ||
7835 | VEC_safe_push (const_char_ptr, excludes, imported_name); | |
7836 | ||
7837 | process_die (child_die, cu); | |
7838 | } | |
7839 | ||
c0cc3a76 SW |
7840 | cp_add_using_directive (import_prefix, |
7841 | canonical_name, | |
7842 | import_alias, | |
13387711 | 7843 | imported_declaration, |
32019081 | 7844 | excludes, |
bb5ed363 | 7845 | &objfile->objfile_obstack); |
32019081 JK |
7846 | |
7847 | do_cleanups (cleanups); | |
27aa8d6a SW |
7848 | } |
7849 | ||
f4dc4d17 | 7850 | /* Cleanup function for handle_DW_AT_stmt_list. */ |
ae2de4f8 | 7851 | |
cb1df416 DJ |
7852 | static void |
7853 | free_cu_line_header (void *arg) | |
7854 | { | |
7855 | struct dwarf2_cu *cu = arg; | |
7856 | ||
7857 | free_line_header (cu->line_header); | |
7858 | cu->line_header = NULL; | |
7859 | } | |
7860 | ||
1b80a9fa JK |
7861 | /* Check for possibly missing DW_AT_comp_dir with relative .debug_line |
7862 | directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed | |
7863 | this, it was first present in GCC release 4.3.0. */ | |
7864 | ||
7865 | static int | |
7866 | producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu) | |
7867 | { | |
7868 | if (!cu->checked_producer) | |
7869 | check_producer (cu); | |
7870 | ||
7871 | return cu->producer_is_gcc_lt_4_3; | |
7872 | } | |
7873 | ||
9291a0cd TT |
7874 | static void |
7875 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
15d034d0 | 7876 | const char **name, const char **comp_dir) |
9291a0cd TT |
7877 | { |
7878 | struct attribute *attr; | |
7879 | ||
7880 | *name = NULL; | |
7881 | *comp_dir = NULL; | |
7882 | ||
7883 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
7884 | is not a source language identifier. */ | |
7885 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
7886 | if (attr) | |
7887 | { | |
7888 | *name = DW_STRING (attr); | |
7889 | } | |
7890 | ||
7891 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
7892 | if (attr) | |
7893 | *comp_dir = DW_STRING (attr); | |
1b80a9fa JK |
7894 | else if (producer_is_gcc_lt_4_3 (cu) && *name != NULL |
7895 | && IS_ABSOLUTE_PATH (*name)) | |
9291a0cd | 7896 | { |
15d034d0 TT |
7897 | char *d = ldirname (*name); |
7898 | ||
7899 | *comp_dir = d; | |
7900 | if (d != NULL) | |
7901 | make_cleanup (xfree, d); | |
9291a0cd TT |
7902 | } |
7903 | if (*comp_dir != NULL) | |
7904 | { | |
7905 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
7906 | directory, get rid of it. */ | |
7907 | char *cp = strchr (*comp_dir, ':'); | |
7908 | ||
7909 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
7910 | *comp_dir = cp + 1; | |
7911 | } | |
7912 | ||
7913 | if (*name == NULL) | |
7914 | *name = "<unknown>"; | |
7915 | } | |
7916 | ||
f4dc4d17 DE |
7917 | /* Handle DW_AT_stmt_list for a compilation unit. |
7918 | DIE is the DW_TAG_compile_unit die for CU. | |
f3f5162e DE |
7919 | COMP_DIR is the compilation directory. |
7920 | WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */ | |
2ab95328 TT |
7921 | |
7922 | static void | |
7923 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, | |
f4dc4d17 | 7924 | const char *comp_dir) |
2ab95328 TT |
7925 | { |
7926 | struct attribute *attr; | |
2ab95328 | 7927 | |
f4dc4d17 DE |
7928 | gdb_assert (! cu->per_cu->is_debug_types); |
7929 | ||
2ab95328 TT |
7930 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
7931 | if (attr) | |
7932 | { | |
7933 | unsigned int line_offset = DW_UNSND (attr); | |
7934 | struct line_header *line_header | |
3019eac3 | 7935 | = dwarf_decode_line_header (line_offset, cu); |
2ab95328 TT |
7936 | |
7937 | if (line_header) | |
dee91e82 DE |
7938 | { |
7939 | cu->line_header = line_header; | |
7940 | make_cleanup (free_cu_line_header, cu); | |
f4dc4d17 | 7941 | dwarf_decode_lines (line_header, comp_dir, cu, NULL, 1); |
dee91e82 | 7942 | } |
2ab95328 TT |
7943 | } |
7944 | } | |
7945 | ||
95554aad | 7946 | /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */ |
ae2de4f8 | 7947 | |
c906108c | 7948 | static void |
e7c27a73 | 7949 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7950 | { |
dee91e82 | 7951 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
debd256d | 7952 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 7953 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
7954 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
7955 | struct attribute *attr; | |
15d034d0 TT |
7956 | const char *name = NULL; |
7957 | const char *comp_dir = NULL; | |
c906108c SS |
7958 | struct die_info *child_die; |
7959 | bfd *abfd = objfile->obfd; | |
e142c38c | 7960 | CORE_ADDR baseaddr; |
6e70227d | 7961 | |
e142c38c | 7962 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 7963 | |
fae299cd | 7964 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
7965 | |
7966 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
7967 | from finish_block. */ | |
2acceee2 | 7968 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
7969 | lowpc = highpc; |
7970 | lowpc += baseaddr; | |
7971 | highpc += baseaddr; | |
7972 | ||
9291a0cd | 7973 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 7974 | |
95554aad | 7975 | prepare_one_comp_unit (cu, die, cu->language); |
303b6f5d | 7976 | |
f4b8a18d KW |
7977 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
7978 | standardised yet. As a workaround for the language detection we fall | |
7979 | back to the DW_AT_producer string. */ | |
7980 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
7981 | cu->language = language_opencl; | |
7982 | ||
3019eac3 DE |
7983 | /* Similar hack for Go. */ |
7984 | if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL) | |
7985 | set_cu_language (DW_LANG_Go, cu); | |
7986 | ||
f4dc4d17 | 7987 | dwarf2_start_symtab (cu, name, comp_dir, lowpc); |
3019eac3 DE |
7988 | |
7989 | /* Decode line number information if present. We do this before | |
7990 | processing child DIEs, so that the line header table is available | |
7991 | for DW_AT_decl_file. */ | |
f4dc4d17 | 7992 | handle_DW_AT_stmt_list (die, cu, comp_dir); |
3019eac3 DE |
7993 | |
7994 | /* Process all dies in compilation unit. */ | |
7995 | if (die->child != NULL) | |
7996 | { | |
7997 | child_die = die->child; | |
7998 | while (child_die && child_die->tag) | |
7999 | { | |
8000 | process_die (child_die, cu); | |
8001 | child_die = sibling_die (child_die); | |
8002 | } | |
8003 | } | |
8004 | ||
8005 | /* Decode macro information, if present. Dwarf 2 macro information | |
8006 | refers to information in the line number info statement program | |
8007 | header, so we can only read it if we've read the header | |
8008 | successfully. */ | |
8009 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); | |
8010 | if (attr && cu->line_header) | |
8011 | { | |
8012 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) | |
8013 | complaint (&symfile_complaints, | |
8014 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); | |
8015 | ||
09262596 | 8016 | dwarf_decode_macros (cu, DW_UNSND (attr), comp_dir, 1); |
3019eac3 DE |
8017 | } |
8018 | else | |
8019 | { | |
8020 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |
8021 | if (attr && cu->line_header) | |
8022 | { | |
8023 | unsigned int macro_offset = DW_UNSND (attr); | |
8024 | ||
09262596 | 8025 | dwarf_decode_macros (cu, macro_offset, comp_dir, 0); |
3019eac3 DE |
8026 | } |
8027 | } | |
8028 | ||
8029 | do_cleanups (back_to); | |
8030 | } | |
8031 | ||
f4dc4d17 DE |
8032 | /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope. |
8033 | Create the set of symtabs used by this TU, or if this TU is sharing | |
8034 | symtabs with another TU and the symtabs have already been created | |
8035 | then restore those symtabs in the line header. | |
8036 | We don't need the pc/line-number mapping for type units. */ | |
3019eac3 DE |
8037 | |
8038 | static void | |
f4dc4d17 | 8039 | setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu) |
3019eac3 | 8040 | { |
f4dc4d17 DE |
8041 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
8042 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; | |
8043 | struct type_unit_group *tu_group; | |
8044 | int first_time; | |
8045 | struct line_header *lh; | |
3019eac3 | 8046 | struct attribute *attr; |
f4dc4d17 | 8047 | unsigned int i, line_offset; |
3019eac3 | 8048 | |
f4dc4d17 | 8049 | gdb_assert (per_cu->is_debug_types); |
3019eac3 | 8050 | |
f4dc4d17 | 8051 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
3019eac3 | 8052 | |
f4dc4d17 DE |
8053 | /* If we're using .gdb_index (includes -readnow) then |
8054 | per_cu->s.type_unit_group may not have been set up yet. */ | |
796a7ff8 DE |
8055 | if (per_cu->type_unit_group == NULL) |
8056 | per_cu->type_unit_group = get_type_unit_group (cu, attr); | |
8057 | tu_group = per_cu->type_unit_group; | |
f4dc4d17 DE |
8058 | |
8059 | /* If we've already processed this stmt_list there's no real need to | |
8060 | do it again, we could fake it and just recreate the part we need | |
8061 | (file name,index -> symtab mapping). If data shows this optimization | |
8062 | is useful we can do it then. */ | |
8063 | first_time = tu_group->primary_symtab == NULL; | |
8064 | ||
8065 | /* We have to handle the case of both a missing DW_AT_stmt_list or bad | |
8066 | debug info. */ | |
8067 | lh = NULL; | |
8068 | if (attr != NULL) | |
3019eac3 | 8069 | { |
f4dc4d17 DE |
8070 | line_offset = DW_UNSND (attr); |
8071 | lh = dwarf_decode_line_header (line_offset, cu); | |
8072 | } | |
8073 | if (lh == NULL) | |
8074 | { | |
8075 | if (first_time) | |
8076 | dwarf2_start_symtab (cu, "", NULL, 0); | |
8077 | else | |
8078 | { | |
8079 | gdb_assert (tu_group->symtabs == NULL); | |
8080 | restart_symtab (0); | |
8081 | } | |
8082 | /* Note: The primary symtab will get allocated at the end. */ | |
8083 | return; | |
3019eac3 DE |
8084 | } |
8085 | ||
f4dc4d17 DE |
8086 | cu->line_header = lh; |
8087 | make_cleanup (free_cu_line_header, cu); | |
3019eac3 | 8088 | |
f4dc4d17 DE |
8089 | if (first_time) |
8090 | { | |
8091 | dwarf2_start_symtab (cu, "", NULL, 0); | |
3019eac3 | 8092 | |
f4dc4d17 DE |
8093 | tu_group->num_symtabs = lh->num_file_names; |
8094 | tu_group->symtabs = XNEWVEC (struct symtab *, lh->num_file_names); | |
3019eac3 | 8095 | |
f4dc4d17 DE |
8096 | for (i = 0; i < lh->num_file_names; ++i) |
8097 | { | |
8098 | char *dir = NULL; | |
8099 | struct file_entry *fe = &lh->file_names[i]; | |
3019eac3 | 8100 | |
f4dc4d17 DE |
8101 | if (fe->dir_index) |
8102 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8103 | dwarf2_start_subfile (fe->name, dir, NULL); | |
3019eac3 | 8104 | |
f4dc4d17 DE |
8105 | /* Note: We don't have to watch for the main subfile here, type units |
8106 | don't have DW_AT_name. */ | |
3019eac3 | 8107 | |
f4dc4d17 DE |
8108 | if (current_subfile->symtab == NULL) |
8109 | { | |
8110 | /* NOTE: start_subfile will recognize when it's been passed | |
8111 | a file it has already seen. So we can't assume there's a | |
8112 | simple mapping from lh->file_names to subfiles, | |
8113 | lh->file_names may contain dups. */ | |
8114 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
8115 | objfile); | |
8116 | } | |
8117 | ||
8118 | fe->symtab = current_subfile->symtab; | |
8119 | tu_group->symtabs[i] = fe->symtab; | |
8120 | } | |
8121 | } | |
8122 | else | |
3019eac3 | 8123 | { |
f4dc4d17 DE |
8124 | restart_symtab (0); |
8125 | ||
8126 | for (i = 0; i < lh->num_file_names; ++i) | |
8127 | { | |
8128 | struct file_entry *fe = &lh->file_names[i]; | |
8129 | ||
8130 | fe->symtab = tu_group->symtabs[i]; | |
8131 | } | |
3019eac3 DE |
8132 | } |
8133 | ||
f4dc4d17 DE |
8134 | /* The main symtab is allocated last. Type units don't have DW_AT_name |
8135 | so they don't have a "real" (so to speak) symtab anyway. | |
8136 | There is later code that will assign the main symtab to all symbols | |
8137 | that don't have one. We need to handle the case of a symbol with a | |
8138 | missing symtab (DW_AT_decl_file) anyway. */ | |
8139 | } | |
3019eac3 | 8140 | |
f4dc4d17 DE |
8141 | /* Process DW_TAG_type_unit. |
8142 | For TUs we want to skip the first top level sibling if it's not the | |
8143 | actual type being defined by this TU. In this case the first top | |
8144 | level sibling is there to provide context only. */ | |
3019eac3 | 8145 | |
f4dc4d17 DE |
8146 | static void |
8147 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
8148 | { | |
8149 | struct die_info *child_die; | |
3019eac3 | 8150 | |
f4dc4d17 DE |
8151 | prepare_one_comp_unit (cu, die, language_minimal); |
8152 | ||
8153 | /* Initialize (or reinitialize) the machinery for building symtabs. | |
8154 | We do this before processing child DIEs, so that the line header table | |
8155 | is available for DW_AT_decl_file. */ | |
8156 | setup_type_unit_groups (die, cu); | |
8157 | ||
8158 | if (die->child != NULL) | |
8159 | { | |
8160 | child_die = die->child; | |
8161 | while (child_die && child_die->tag) | |
8162 | { | |
8163 | process_die (child_die, cu); | |
8164 | child_die = sibling_die (child_die); | |
8165 | } | |
8166 | } | |
3019eac3 DE |
8167 | } |
8168 | \f | |
80626a55 DE |
8169 | /* DWO/DWP files. |
8170 | ||
8171 | http://gcc.gnu.org/wiki/DebugFission | |
8172 | http://gcc.gnu.org/wiki/DebugFissionDWP | |
8173 | ||
8174 | To simplify handling of both DWO files ("object" files with the DWARF info) | |
8175 | and DWP files (a file with the DWOs packaged up into one file), we treat | |
8176 | DWP files as having a collection of virtual DWO files. */ | |
3019eac3 DE |
8177 | |
8178 | static hashval_t | |
8179 | hash_dwo_file (const void *item) | |
8180 | { | |
8181 | const struct dwo_file *dwo_file = item; | |
8182 | ||
80626a55 | 8183 | return htab_hash_string (dwo_file->name); |
3019eac3 DE |
8184 | } |
8185 | ||
8186 | static int | |
8187 | eq_dwo_file (const void *item_lhs, const void *item_rhs) | |
8188 | { | |
8189 | const struct dwo_file *lhs = item_lhs; | |
8190 | const struct dwo_file *rhs = item_rhs; | |
8191 | ||
80626a55 | 8192 | return strcmp (lhs->name, rhs->name) == 0; |
3019eac3 DE |
8193 | } |
8194 | ||
8195 | /* Allocate a hash table for DWO files. */ | |
8196 | ||
8197 | static htab_t | |
8198 | allocate_dwo_file_hash_table (void) | |
8199 | { | |
8200 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
8201 | ||
8202 | return htab_create_alloc_ex (41, | |
8203 | hash_dwo_file, | |
8204 | eq_dwo_file, | |
8205 | NULL, | |
8206 | &objfile->objfile_obstack, | |
8207 | hashtab_obstack_allocate, | |
8208 | dummy_obstack_deallocate); | |
8209 | } | |
8210 | ||
80626a55 DE |
8211 | /* Lookup DWO file DWO_NAME. */ |
8212 | ||
8213 | static void ** | |
8214 | lookup_dwo_file_slot (const char *dwo_name) | |
8215 | { | |
8216 | struct dwo_file find_entry; | |
8217 | void **slot; | |
8218 | ||
8219 | if (dwarf2_per_objfile->dwo_files == NULL) | |
8220 | dwarf2_per_objfile->dwo_files = allocate_dwo_file_hash_table (); | |
8221 | ||
8222 | memset (&find_entry, 0, sizeof (find_entry)); | |
8223 | find_entry.name = dwo_name; | |
8224 | slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT); | |
8225 | ||
8226 | return slot; | |
8227 | } | |
8228 | ||
3019eac3 DE |
8229 | static hashval_t |
8230 | hash_dwo_unit (const void *item) | |
8231 | { | |
8232 | const struct dwo_unit *dwo_unit = item; | |
8233 | ||
8234 | /* This drops the top 32 bits of the id, but is ok for a hash. */ | |
8235 | return dwo_unit->signature; | |
8236 | } | |
8237 | ||
8238 | static int | |
8239 | eq_dwo_unit (const void *item_lhs, const void *item_rhs) | |
8240 | { | |
8241 | const struct dwo_unit *lhs = item_lhs; | |
8242 | const struct dwo_unit *rhs = item_rhs; | |
8243 | ||
8244 | /* The signature is assumed to be unique within the DWO file. | |
8245 | So while object file CU dwo_id's always have the value zero, | |
8246 | that's OK, assuming each object file DWO file has only one CU, | |
8247 | and that's the rule for now. */ | |
8248 | return lhs->signature == rhs->signature; | |
8249 | } | |
8250 | ||
8251 | /* Allocate a hash table for DWO CUs,TUs. | |
8252 | There is one of these tables for each of CUs,TUs for each DWO file. */ | |
8253 | ||
8254 | static htab_t | |
8255 | allocate_dwo_unit_table (struct objfile *objfile) | |
8256 | { | |
8257 | /* Start out with a pretty small number. | |
8258 | Generally DWO files contain only one CU and maybe some TUs. */ | |
8259 | return htab_create_alloc_ex (3, | |
8260 | hash_dwo_unit, | |
8261 | eq_dwo_unit, | |
8262 | NULL, | |
8263 | &objfile->objfile_obstack, | |
8264 | hashtab_obstack_allocate, | |
8265 | dummy_obstack_deallocate); | |
8266 | } | |
8267 | ||
80626a55 | 8268 | /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */ |
3019eac3 DE |
8269 | |
8270 | struct create_dwo_info_table_data | |
8271 | { | |
8272 | struct dwo_file *dwo_file; | |
8273 | htab_t cu_htab; | |
8274 | }; | |
8275 | ||
80626a55 | 8276 | /* die_reader_func for create_dwo_debug_info_hash_table. */ |
3019eac3 DE |
8277 | |
8278 | static void | |
80626a55 DE |
8279 | create_dwo_debug_info_hash_table_reader (const struct die_reader_specs *reader, |
8280 | gdb_byte *info_ptr, | |
8281 | struct die_info *comp_unit_die, | |
8282 | int has_children, | |
8283 | void *datap) | |
3019eac3 DE |
8284 | { |
8285 | struct dwarf2_cu *cu = reader->cu; | |
8286 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
8287 | sect_offset offset = cu->per_cu->offset; | |
8288 | struct dwarf2_section_info *section = cu->per_cu->info_or_types_section; | |
8289 | struct create_dwo_info_table_data *data = datap; | |
8290 | struct dwo_file *dwo_file = data->dwo_file; | |
8291 | htab_t cu_htab = data->cu_htab; | |
8292 | void **slot; | |
8293 | struct attribute *attr; | |
8294 | struct dwo_unit *dwo_unit; | |
8295 | ||
8296 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); | |
8297 | if (attr == NULL) | |
8298 | { | |
8299 | error (_("Dwarf Error: debug entry at offset 0x%x is missing" | |
8300 | " its dwo_id [in module %s]"), | |
80626a55 | 8301 | offset.sect_off, dwo_file->name); |
3019eac3 DE |
8302 | return; |
8303 | } | |
8304 | ||
8305 | dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); | |
8306 | dwo_unit->dwo_file = dwo_file; | |
8307 | dwo_unit->signature = DW_UNSND (attr); | |
8308 | dwo_unit->info_or_types_section = section; | |
8309 | dwo_unit->offset = offset; | |
8310 | dwo_unit->length = cu->per_cu->length; | |
8311 | ||
8312 | slot = htab_find_slot (cu_htab, dwo_unit, INSERT); | |
8313 | gdb_assert (slot != NULL); | |
8314 | if (*slot != NULL) | |
8315 | { | |
8316 | const struct dwo_unit *dup_dwo_unit = *slot; | |
8317 | ||
8318 | complaint (&symfile_complaints, | |
8319 | _("debug entry at offset 0x%x is duplicate to the entry at" | |
8320 | " offset 0x%x, dwo_id 0x%s [in module %s]"), | |
8321 | offset.sect_off, dup_dwo_unit->offset.sect_off, | |
8322 | phex (dwo_unit->signature, sizeof (dwo_unit->signature)), | |
80626a55 | 8323 | dwo_file->name); |
3019eac3 DE |
8324 | } |
8325 | else | |
8326 | *slot = dwo_unit; | |
8327 | ||
09406207 | 8328 | if (dwarf2_read_debug) |
3019eac3 DE |
8329 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, dwo_id 0x%s\n", |
8330 | offset.sect_off, | |
8331 | phex (dwo_unit->signature, | |
8332 | sizeof (dwo_unit->signature))); | |
8333 | } | |
8334 | ||
80626a55 DE |
8335 | /* Create a hash table to map DWO IDs to their CU entry in |
8336 | .debug_info.dwo in DWO_FILE. | |
8337 | Note: This function processes DWO files only, not DWP files. */ | |
3019eac3 DE |
8338 | |
8339 | static htab_t | |
80626a55 | 8340 | create_dwo_debug_info_hash_table (struct dwo_file *dwo_file) |
3019eac3 DE |
8341 | { |
8342 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
8343 | struct dwarf2_section_info *section = &dwo_file->sections.info; | |
8344 | bfd *abfd; | |
8345 | htab_t cu_htab; | |
8346 | gdb_byte *info_ptr, *end_ptr; | |
8347 | struct create_dwo_info_table_data create_dwo_info_table_data; | |
8348 | ||
8349 | dwarf2_read_section (objfile, section); | |
8350 | info_ptr = section->buffer; | |
8351 | ||
8352 | if (info_ptr == NULL) | |
8353 | return NULL; | |
8354 | ||
8355 | /* We can't set abfd until now because the section may be empty or | |
8356 | not present, in which case section->asection will be NULL. */ | |
8357 | abfd = section->asection->owner; | |
8358 | ||
09406207 | 8359 | if (dwarf2_read_debug) |
3019eac3 DE |
8360 | fprintf_unfiltered (gdb_stdlog, "Reading .debug_info.dwo for %s:\n", |
8361 | bfd_get_filename (abfd)); | |
8362 | ||
8363 | cu_htab = allocate_dwo_unit_table (objfile); | |
8364 | ||
8365 | create_dwo_info_table_data.dwo_file = dwo_file; | |
8366 | create_dwo_info_table_data.cu_htab = cu_htab; | |
8367 | ||
8368 | end_ptr = info_ptr + section->size; | |
8369 | while (info_ptr < end_ptr) | |
8370 | { | |
8371 | struct dwarf2_per_cu_data per_cu; | |
8372 | ||
8373 | memset (&per_cu, 0, sizeof (per_cu)); | |
8374 | per_cu.objfile = objfile; | |
8375 | per_cu.is_debug_types = 0; | |
8376 | per_cu.offset.sect_off = info_ptr - section->buffer; | |
8377 | per_cu.info_or_types_section = section; | |
8378 | ||
8379 | init_cutu_and_read_dies_no_follow (&per_cu, | |
8380 | &dwo_file->sections.abbrev, | |
8381 | dwo_file, | |
80626a55 | 8382 | create_dwo_debug_info_hash_table_reader, |
3019eac3 DE |
8383 | &create_dwo_info_table_data); |
8384 | ||
8385 | info_ptr += per_cu.length; | |
8386 | } | |
8387 | ||
8388 | return cu_htab; | |
8389 | } | |
8390 | ||
80626a55 DE |
8391 | /* DWP file .debug_{cu,tu}_index section format: |
8392 | [ref: http://gcc.gnu.org/wiki/DebugFissionDWP] | |
8393 | ||
8394 | Both index sections have the same format, and serve to map a 64-bit | |
8395 | signature to a set of section numbers. Each section begins with a header, | |
8396 | followed by a hash table of 64-bit signatures, a parallel table of 32-bit | |
8397 | indexes, and a pool of 32-bit section numbers. The index sections will be | |
8398 | aligned at 8-byte boundaries in the file. | |
8399 | ||
8400 | The index section header contains two unsigned 32-bit values (using the | |
8401 | byte order of the application binary): | |
8402 | ||
8403 | N, the number of compilation units or type units in the index | |
8404 | M, the number of slots in the hash table | |
8405 | ||
8406 | (We assume that N and M will not exceed 2^32 - 1.) | |
8407 | ||
8408 | The size of the hash table, M, must be 2^k such that 2^k > 3*N/2. | |
8409 | ||
8410 | The hash table begins at offset 8 in the section, and consists of an array | |
8411 | of M 64-bit slots. Each slot contains a 64-bit signature (using the byte | |
8412 | order of the application binary). Unused slots in the hash table are 0. | |
8413 | (We rely on the extreme unlikeliness of a signature being exactly 0.) | |
8414 | ||
8415 | The parallel table begins immediately after the hash table | |
8416 | (at offset 8 + 8 * M from the beginning of the section), and consists of an | |
8417 | array of 32-bit indexes (using the byte order of the application binary), | |
8418 | corresponding 1-1 with slots in the hash table. Each entry in the parallel | |
8419 | table contains a 32-bit index into the pool of section numbers. For unused | |
8420 | hash table slots, the corresponding entry in the parallel table will be 0. | |
8421 | ||
8422 | Given a 64-bit compilation unit signature or a type signature S, an entry | |
8423 | in the hash table is located as follows: | |
8424 | ||
8425 | 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with | |
8426 | the low-order k bits all set to 1. | |
8427 | ||
8428 | 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1). | |
8429 | ||
8430 | 3) If the hash table entry at index H matches the signature, use that | |
8431 | entry. If the hash table entry at index H is unused (all zeroes), | |
8432 | terminate the search: the signature is not present in the table. | |
8433 | ||
8434 | 4) Let H = (H + H') modulo M. Repeat at Step 3. | |
8435 | ||
8436 | Because M > N and H' and M are relatively prime, the search is guaranteed | |
8437 | to stop at an unused slot or find the match. | |
8438 | ||
8439 | The pool of section numbers begins immediately following the hash table | |
8440 | (at offset 8 + 12 * M from the beginning of the section). The pool of | |
8441 | section numbers consists of an array of 32-bit words (using the byte order | |
8442 | of the application binary). Each item in the array is indexed starting | |
8443 | from 0. The hash table entry provides the index of the first section | |
8444 | number in the set. Additional section numbers in the set follow, and the | |
8445 | set is terminated by a 0 entry (section number 0 is not used in ELF). | |
8446 | ||
8447 | In each set of section numbers, the .debug_info.dwo or .debug_types.dwo | |
8448 | section must be the first entry in the set, and the .debug_abbrev.dwo must | |
8449 | be the second entry. Other members of the set may follow in any order. */ | |
8450 | ||
8451 | /* Create a hash table to map DWO IDs to their CU/TU entry in | |
8452 | .debug_{info,types}.dwo in DWP_FILE. | |
8453 | Returns NULL if there isn't one. | |
8454 | Note: This function processes DWP files only, not DWO files. */ | |
8455 | ||
8456 | static struct dwp_hash_table * | |
8457 | create_dwp_hash_table (struct dwp_file *dwp_file, int is_debug_types) | |
8458 | { | |
8459 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
8460 | bfd *dbfd = dwp_file->dbfd; | |
8461 | char *index_ptr, *index_end; | |
8462 | struct dwarf2_section_info *index; | |
8463 | uint32_t version, nr_units, nr_slots; | |
8464 | struct dwp_hash_table *htab; | |
8465 | ||
8466 | if (is_debug_types) | |
8467 | index = &dwp_file->sections.tu_index; | |
8468 | else | |
8469 | index = &dwp_file->sections.cu_index; | |
8470 | ||
8471 | if (dwarf2_section_empty_p (index)) | |
8472 | return NULL; | |
8473 | dwarf2_read_section (objfile, index); | |
8474 | ||
8475 | index_ptr = index->buffer; | |
8476 | index_end = index_ptr + index->size; | |
8477 | ||
8478 | version = read_4_bytes (dbfd, index_ptr); | |
8479 | index_ptr += 8; /* Skip the unused word. */ | |
8480 | nr_units = read_4_bytes (dbfd, index_ptr); | |
8481 | index_ptr += 4; | |
8482 | nr_slots = read_4_bytes (dbfd, index_ptr); | |
8483 | index_ptr += 4; | |
8484 | ||
8485 | if (version != 1) | |
8486 | { | |
8487 | error (_("Dwarf Error: unsupported DWP file version (%u)" | |
8488 | " [in module %s]"), | |
8489 | version, dwp_file->name); | |
8490 | } | |
8491 | if (nr_slots != (nr_slots & -nr_slots)) | |
8492 | { | |
8493 | error (_("Dwarf Error: number of slots in DWP hash table (%u)" | |
8494 | " is not power of 2 [in module %s]"), | |
8495 | nr_slots, dwp_file->name); | |
8496 | } | |
8497 | ||
8498 | htab = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_hash_table); | |
8499 | htab->nr_units = nr_units; | |
8500 | htab->nr_slots = nr_slots; | |
8501 | htab->hash_table = index_ptr; | |
8502 | htab->unit_table = htab->hash_table + sizeof (uint64_t) * nr_slots; | |
8503 | htab->section_pool = htab->unit_table + sizeof (uint32_t) * nr_slots; | |
8504 | ||
8505 | return htab; | |
8506 | } | |
8507 | ||
8508 | /* Update SECTIONS with the data from SECTP. | |
8509 | ||
8510 | This function is like the other "locate" section routines that are | |
8511 | passed to bfd_map_over_sections, but in this context the sections to | |
8512 | read comes from the DWP hash table, not the full ELF section table. | |
8513 | ||
8514 | The result is non-zero for success, or zero if an error was found. */ | |
8515 | ||
8516 | static int | |
8517 | locate_virtual_dwo_sections (asection *sectp, | |
8518 | struct virtual_dwo_sections *sections) | |
8519 | { | |
8520 | const struct dwop_section_names *names = &dwop_section_names; | |
8521 | ||
8522 | if (section_is_p (sectp->name, &names->abbrev_dwo)) | |
8523 | { | |
8524 | /* There can be only one. */ | |
8525 | if (sections->abbrev.asection != NULL) | |
8526 | return 0; | |
8527 | sections->abbrev.asection = sectp; | |
8528 | sections->abbrev.size = bfd_get_section_size (sectp); | |
8529 | } | |
8530 | else if (section_is_p (sectp->name, &names->info_dwo) | |
8531 | || section_is_p (sectp->name, &names->types_dwo)) | |
8532 | { | |
8533 | /* There can be only one. */ | |
8534 | if (sections->info_or_types.asection != NULL) | |
8535 | return 0; | |
8536 | sections->info_or_types.asection = sectp; | |
8537 | sections->info_or_types.size = bfd_get_section_size (sectp); | |
8538 | } | |
8539 | else if (section_is_p (sectp->name, &names->line_dwo)) | |
8540 | { | |
8541 | /* There can be only one. */ | |
8542 | if (sections->line.asection != NULL) | |
8543 | return 0; | |
8544 | sections->line.asection = sectp; | |
8545 | sections->line.size = bfd_get_section_size (sectp); | |
8546 | } | |
8547 | else if (section_is_p (sectp->name, &names->loc_dwo)) | |
8548 | { | |
8549 | /* There can be only one. */ | |
8550 | if (sections->loc.asection != NULL) | |
8551 | return 0; | |
8552 | sections->loc.asection = sectp; | |
8553 | sections->loc.size = bfd_get_section_size (sectp); | |
8554 | } | |
8555 | else if (section_is_p (sectp->name, &names->macinfo_dwo)) | |
8556 | { | |
8557 | /* There can be only one. */ | |
8558 | if (sections->macinfo.asection != NULL) | |
8559 | return 0; | |
8560 | sections->macinfo.asection = sectp; | |
8561 | sections->macinfo.size = bfd_get_section_size (sectp); | |
8562 | } | |
8563 | else if (section_is_p (sectp->name, &names->macro_dwo)) | |
8564 | { | |
8565 | /* There can be only one. */ | |
8566 | if (sections->macro.asection != NULL) | |
8567 | return 0; | |
8568 | sections->macro.asection = sectp; | |
8569 | sections->macro.size = bfd_get_section_size (sectp); | |
8570 | } | |
8571 | else if (section_is_p (sectp->name, &names->str_offsets_dwo)) | |
8572 | { | |
8573 | /* There can be only one. */ | |
8574 | if (sections->str_offsets.asection != NULL) | |
8575 | return 0; | |
8576 | sections->str_offsets.asection = sectp; | |
8577 | sections->str_offsets.size = bfd_get_section_size (sectp); | |
8578 | } | |
8579 | else | |
8580 | { | |
8581 | /* No other kind of section is valid. */ | |
8582 | return 0; | |
8583 | } | |
8584 | ||
8585 | return 1; | |
8586 | } | |
8587 | ||
8588 | /* Create a dwo_unit object for the DWO with signature SIGNATURE. | |
8589 | HTAB is the hash table from the DWP file. | |
8590 | SECTION_INDEX is the index of the DWO in HTAB. */ | |
8591 | ||
8592 | static struct dwo_unit * | |
8593 | create_dwo_in_dwp (struct dwp_file *dwp_file, | |
8594 | const struct dwp_hash_table *htab, | |
8595 | uint32_t section_index, | |
8596 | ULONGEST signature, int is_debug_types) | |
8597 | { | |
8598 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
8599 | bfd *dbfd = dwp_file->dbfd; | |
8600 | const char *kind = is_debug_types ? "TU" : "CU"; | |
8601 | struct dwo_file *dwo_file; | |
8602 | struct dwo_unit *dwo_unit; | |
8603 | struct virtual_dwo_sections sections; | |
8604 | void **dwo_file_slot; | |
8605 | char *virtual_dwo_name; | |
8606 | struct dwarf2_section_info *cutu; | |
8607 | struct cleanup *cleanups; | |
8608 | int i; | |
8609 | ||
8610 | if (dwarf2_read_debug) | |
8611 | { | |
8612 | fprintf_unfiltered (gdb_stdlog, "Reading %s %u/0x%s in DWP file: %s\n", | |
8613 | kind, | |
8614 | section_index, phex (signature, sizeof (signature)), | |
8615 | dwp_file->name); | |
8616 | } | |
8617 | ||
8618 | /* Fetch the sections of this DWO. | |
8619 | Put a limit on the number of sections we look for so that bad data | |
8620 | doesn't cause us to loop forever. */ | |
8621 | ||
8622 | #define MAX_NR_DWO_SECTIONS \ | |
8623 | (1 /* .debug_info or .debug_types */ \ | |
8624 | + 1 /* .debug_abbrev */ \ | |
8625 | + 1 /* .debug_line */ \ | |
8626 | + 1 /* .debug_loc */ \ | |
8627 | + 1 /* .debug_str_offsets */ \ | |
8628 | + 1 /* .debug_macro */ \ | |
8629 | + 1 /* .debug_macinfo */ \ | |
8630 | + 1 /* trailing zero */) | |
8631 | ||
8632 | memset (§ions, 0, sizeof (sections)); | |
8633 | cleanups = make_cleanup (null_cleanup, 0); | |
8634 | ||
8635 | for (i = 0; i < MAX_NR_DWO_SECTIONS; ++i) | |
8636 | { | |
8637 | asection *sectp; | |
8638 | uint32_t section_nr = | |
8639 | read_4_bytes (dbfd, | |
8640 | htab->section_pool | |
8641 | + (section_index + i) * sizeof (uint32_t)); | |
8642 | ||
8643 | if (section_nr == 0) | |
8644 | break; | |
8645 | if (section_nr >= dwp_file->num_sections) | |
8646 | { | |
8647 | error (_("Dwarf Error: bad DWP hash table, section number too large" | |
8648 | " [in module %s]"), | |
8649 | dwp_file->name); | |
8650 | } | |
8651 | ||
8652 | sectp = dwp_file->elf_sections[section_nr]; | |
8653 | if (! locate_virtual_dwo_sections (sectp, §ions)) | |
8654 | { | |
8655 | error (_("Dwarf Error: bad DWP hash table, invalid section found" | |
8656 | " [in module %s]"), | |
8657 | dwp_file->name); | |
8658 | } | |
8659 | } | |
8660 | ||
8661 | if (i < 2 | |
8662 | || sections.info_or_types.asection == NULL | |
8663 | || sections.abbrev.asection == NULL) | |
8664 | { | |
8665 | error (_("Dwarf Error: bad DWP hash table, missing DWO sections" | |
8666 | " [in module %s]"), | |
8667 | dwp_file->name); | |
8668 | } | |
8669 | if (i == MAX_NR_DWO_SECTIONS) | |
8670 | { | |
8671 | error (_("Dwarf Error: bad DWP hash table, too many DWO sections" | |
8672 | " [in module %s]"), | |
8673 | dwp_file->name); | |
8674 | } | |
8675 | ||
8676 | /* It's easier for the rest of the code if we fake a struct dwo_file and | |
8677 | have dwo_unit "live" in that. At least for now. | |
8678 | ||
8679 | The DWP file can be made up of a random collection of CUs and TUs. | |
c766f7ec DE |
8680 | However, for each CU + set of TUs that came from the same original DWO |
8681 | file, we want to combine them back into a virtual DWO file to save space | |
80626a55 DE |
8682 | (fewer struct dwo_file objects to allocated). Remember that for really |
8683 | large apps there can be on the order of 8K CUs and 200K TUs, or more. */ | |
8684 | ||
2792b94d PM |
8685 | virtual_dwo_name = |
8686 | xstrprintf ("virtual-dwo/%d-%d-%d-%d", | |
8687 | sections.abbrev.asection ? sections.abbrev.asection->id : 0, | |
8688 | sections.line.asection ? sections.line.asection->id : 0, | |
8689 | sections.loc.asection ? sections.loc.asection->id : 0, | |
8690 | (sections.str_offsets.asection | |
8691 | ? sections.str_offsets.asection->id | |
8692 | : 0)); | |
80626a55 DE |
8693 | make_cleanup (xfree, virtual_dwo_name); |
8694 | /* Can we use an existing virtual DWO file? */ | |
8695 | dwo_file_slot = lookup_dwo_file_slot (virtual_dwo_name); | |
8696 | /* Create one if necessary. */ | |
8697 | if (*dwo_file_slot == NULL) | |
8698 | { | |
8699 | if (dwarf2_read_debug) | |
8700 | { | |
8701 | fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n", | |
8702 | virtual_dwo_name); | |
8703 | } | |
8704 | dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file); | |
8705 | dwo_file->name = obstack_copy0 (&objfile->objfile_obstack, | |
8706 | virtual_dwo_name, | |
8707 | strlen (virtual_dwo_name)); | |
8708 | dwo_file->sections.abbrev = sections.abbrev; | |
8709 | dwo_file->sections.line = sections.line; | |
8710 | dwo_file->sections.loc = sections.loc; | |
8711 | dwo_file->sections.macinfo = sections.macinfo; | |
8712 | dwo_file->sections.macro = sections.macro; | |
8713 | dwo_file->sections.str_offsets = sections.str_offsets; | |
8714 | /* The "str" section is global to the entire DWP file. */ | |
8715 | dwo_file->sections.str = dwp_file->sections.str; | |
8716 | /* The info or types section is assigned later to dwo_unit, | |
8717 | there's no need to record it in dwo_file. | |
8718 | Also, we can't simply record type sections in dwo_file because | |
8719 | we record a pointer into the vector in dwo_unit. As we collect more | |
8720 | types we'll grow the vector and eventually have to reallocate space | |
8721 | for it, invalidating all the pointers into the current copy. */ | |
8722 | *dwo_file_slot = dwo_file; | |
8723 | } | |
8724 | else | |
8725 | { | |
8726 | if (dwarf2_read_debug) | |
8727 | { | |
8728 | fprintf_unfiltered (gdb_stdlog, "Using existing virtual DWO: %s\n", | |
8729 | virtual_dwo_name); | |
8730 | } | |
8731 | dwo_file = *dwo_file_slot; | |
8732 | } | |
8733 | do_cleanups (cleanups); | |
8734 | ||
8735 | dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); | |
8736 | dwo_unit->dwo_file = dwo_file; | |
8737 | dwo_unit->signature = signature; | |
8738 | dwo_unit->info_or_types_section = | |
8739 | obstack_alloc (&objfile->objfile_obstack, | |
8740 | sizeof (struct dwarf2_section_info)); | |
8741 | *dwo_unit->info_or_types_section = sections.info_or_types; | |
8742 | /* offset, length, type_offset_in_tu are set later. */ | |
8743 | ||
8744 | return dwo_unit; | |
8745 | } | |
8746 | ||
8747 | /* Lookup the DWO with SIGNATURE in DWP_FILE. */ | |
8748 | ||
8749 | static struct dwo_unit * | |
8750 | lookup_dwo_in_dwp (struct dwp_file *dwp_file, | |
8751 | const struct dwp_hash_table *htab, | |
8752 | ULONGEST signature, int is_debug_types) | |
8753 | { | |
8754 | bfd *dbfd = dwp_file->dbfd; | |
8755 | uint32_t mask = htab->nr_slots - 1; | |
8756 | uint32_t hash = signature & mask; | |
8757 | uint32_t hash2 = ((signature >> 32) & mask) | 1; | |
8758 | unsigned int i; | |
8759 | void **slot; | |
8760 | struct dwo_unit find_dwo_cu, *dwo_cu; | |
8761 | ||
8762 | memset (&find_dwo_cu, 0, sizeof (find_dwo_cu)); | |
8763 | find_dwo_cu.signature = signature; | |
8764 | slot = htab_find_slot (dwp_file->loaded_cutus, &find_dwo_cu, INSERT); | |
8765 | ||
8766 | if (*slot != NULL) | |
8767 | return *slot; | |
8768 | ||
8769 | /* Use a for loop so that we don't loop forever on bad debug info. */ | |
8770 | for (i = 0; i < htab->nr_slots; ++i) | |
8771 | { | |
8772 | ULONGEST signature_in_table; | |
8773 | ||
8774 | signature_in_table = | |
8775 | read_8_bytes (dbfd, htab->hash_table + hash * sizeof (uint64_t)); | |
8776 | if (signature_in_table == signature) | |
8777 | { | |
8778 | uint32_t section_index = | |
8779 | read_4_bytes (dbfd, htab->unit_table + hash * sizeof (uint32_t)); | |
8780 | ||
8781 | *slot = create_dwo_in_dwp (dwp_file, htab, section_index, | |
8782 | signature, is_debug_types); | |
8783 | return *slot; | |
8784 | } | |
8785 | if (signature_in_table == 0) | |
8786 | return NULL; | |
8787 | hash = (hash + hash2) & mask; | |
8788 | } | |
8789 | ||
8790 | error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate" | |
8791 | " [in module %s]"), | |
8792 | dwp_file->name); | |
8793 | } | |
8794 | ||
8795 | /* Subroutine of open_dwop_file to simplify it. | |
3019eac3 DE |
8796 | Open the file specified by FILE_NAME and hand it off to BFD for |
8797 | preliminary analysis. Return a newly initialized bfd *, which | |
8798 | includes a canonicalized copy of FILE_NAME. | |
80626a55 | 8799 | If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file. |
3019eac3 DE |
8800 | In case of trouble, return NULL. |
8801 | NOTE: This function is derived from symfile_bfd_open. */ | |
8802 | ||
8803 | static bfd * | |
80626a55 | 8804 | try_open_dwop_file (const char *file_name, int is_dwp) |
3019eac3 DE |
8805 | { |
8806 | bfd *sym_bfd; | |
80626a55 | 8807 | int desc, flags; |
3019eac3 | 8808 | char *absolute_name; |
3019eac3 | 8809 | |
80626a55 DE |
8810 | flags = OPF_TRY_CWD_FIRST; |
8811 | if (is_dwp) | |
8812 | flags |= OPF_SEARCH_IN_PATH; | |
8813 | desc = openp (debug_file_directory, flags, file_name, | |
3019eac3 DE |
8814 | O_RDONLY | O_BINARY, &absolute_name); |
8815 | if (desc < 0) | |
8816 | return NULL; | |
8817 | ||
bb397797 | 8818 | sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc); |
3019eac3 DE |
8819 | if (!sym_bfd) |
8820 | { | |
3019eac3 DE |
8821 | xfree (absolute_name); |
8822 | return NULL; | |
8823 | } | |
a4453b7e | 8824 | xfree (absolute_name); |
3019eac3 DE |
8825 | bfd_set_cacheable (sym_bfd, 1); |
8826 | ||
8827 | if (!bfd_check_format (sym_bfd, bfd_object)) | |
8828 | { | |
cbb099e8 | 8829 | gdb_bfd_unref (sym_bfd); /* This also closes desc. */ |
3019eac3 DE |
8830 | return NULL; |
8831 | } | |
8832 | ||
3019eac3 DE |
8833 | return sym_bfd; |
8834 | } | |
8835 | ||
80626a55 | 8836 | /* Try to open DWO/DWP file FILE_NAME. |
3019eac3 | 8837 | COMP_DIR is the DW_AT_comp_dir attribute. |
80626a55 | 8838 | If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file. |
3019eac3 DE |
8839 | The result is the bfd handle of the file. |
8840 | If there is a problem finding or opening the file, return NULL. | |
8841 | Upon success, the canonicalized path of the file is stored in the bfd, | |
8842 | same as symfile_bfd_open. */ | |
8843 | ||
8844 | static bfd * | |
80626a55 | 8845 | open_dwop_file (const char *file_name, const char *comp_dir, int is_dwp) |
3019eac3 DE |
8846 | { |
8847 | bfd *abfd; | |
3019eac3 | 8848 | |
80626a55 DE |
8849 | if (IS_ABSOLUTE_PATH (file_name)) |
8850 | return try_open_dwop_file (file_name, is_dwp); | |
3019eac3 DE |
8851 | |
8852 | /* Before trying the search path, try DWO_NAME in COMP_DIR. */ | |
8853 | ||
8854 | if (comp_dir != NULL) | |
8855 | { | |
80626a55 | 8856 | char *path_to_try = concat (comp_dir, SLASH_STRING, file_name, NULL); |
3019eac3 DE |
8857 | |
8858 | /* NOTE: If comp_dir is a relative path, this will also try the | |
8859 | search path, which seems useful. */ | |
80626a55 | 8860 | abfd = try_open_dwop_file (path_to_try, is_dwp); |
3019eac3 DE |
8861 | xfree (path_to_try); |
8862 | if (abfd != NULL) | |
8863 | return abfd; | |
8864 | } | |
8865 | ||
8866 | /* That didn't work, try debug-file-directory, which, despite its name, | |
8867 | is a list of paths. */ | |
8868 | ||
8869 | if (*debug_file_directory == '\0') | |
8870 | return NULL; | |
8871 | ||
80626a55 | 8872 | return try_open_dwop_file (file_name, is_dwp); |
3019eac3 DE |
8873 | } |
8874 | ||
80626a55 DE |
8875 | /* This function is mapped across the sections and remembers the offset and |
8876 | size of each of the DWO debugging sections we are interested in. */ | |
8877 | ||
8878 | static void | |
8879 | dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr) | |
8880 | { | |
8881 | struct dwo_sections *dwo_sections = dwo_sections_ptr; | |
8882 | const struct dwop_section_names *names = &dwop_section_names; | |
8883 | ||
8884 | if (section_is_p (sectp->name, &names->abbrev_dwo)) | |
8885 | { | |
8886 | dwo_sections->abbrev.asection = sectp; | |
8887 | dwo_sections->abbrev.size = bfd_get_section_size (sectp); | |
8888 | } | |
8889 | else if (section_is_p (sectp->name, &names->info_dwo)) | |
8890 | { | |
8891 | dwo_sections->info.asection = sectp; | |
8892 | dwo_sections->info.size = bfd_get_section_size (sectp); | |
8893 | } | |
8894 | else if (section_is_p (sectp->name, &names->line_dwo)) | |
8895 | { | |
8896 | dwo_sections->line.asection = sectp; | |
8897 | dwo_sections->line.size = bfd_get_section_size (sectp); | |
8898 | } | |
8899 | else if (section_is_p (sectp->name, &names->loc_dwo)) | |
8900 | { | |
8901 | dwo_sections->loc.asection = sectp; | |
8902 | dwo_sections->loc.size = bfd_get_section_size (sectp); | |
8903 | } | |
8904 | else if (section_is_p (sectp->name, &names->macinfo_dwo)) | |
8905 | { | |
8906 | dwo_sections->macinfo.asection = sectp; | |
8907 | dwo_sections->macinfo.size = bfd_get_section_size (sectp); | |
8908 | } | |
8909 | else if (section_is_p (sectp->name, &names->macro_dwo)) | |
8910 | { | |
8911 | dwo_sections->macro.asection = sectp; | |
8912 | dwo_sections->macro.size = bfd_get_section_size (sectp); | |
8913 | } | |
8914 | else if (section_is_p (sectp->name, &names->str_dwo)) | |
8915 | { | |
8916 | dwo_sections->str.asection = sectp; | |
8917 | dwo_sections->str.size = bfd_get_section_size (sectp); | |
8918 | } | |
8919 | else if (section_is_p (sectp->name, &names->str_offsets_dwo)) | |
8920 | { | |
8921 | dwo_sections->str_offsets.asection = sectp; | |
8922 | dwo_sections->str_offsets.size = bfd_get_section_size (sectp); | |
8923 | } | |
8924 | else if (section_is_p (sectp->name, &names->types_dwo)) | |
8925 | { | |
8926 | struct dwarf2_section_info type_section; | |
8927 | ||
8928 | memset (&type_section, 0, sizeof (type_section)); | |
8929 | type_section.asection = sectp; | |
8930 | type_section.size = bfd_get_section_size (sectp); | |
8931 | VEC_safe_push (dwarf2_section_info_def, dwo_sections->types, | |
8932 | &type_section); | |
8933 | } | |
8934 | } | |
8935 | ||
8936 | /* Initialize the use of the DWO file specified by DWO_NAME. | |
8937 | The result is NULL if DWO_NAME can't be found. */ | |
3019eac3 DE |
8938 | |
8939 | static struct dwo_file * | |
80626a55 | 8940 | open_and_init_dwo_file (const char *dwo_name, const char *comp_dir) |
3019eac3 DE |
8941 | { |
8942 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
80626a55 DE |
8943 | struct dwo_file *dwo_file; |
8944 | bfd *dbfd; | |
3019eac3 DE |
8945 | struct cleanup *cleanups; |
8946 | ||
80626a55 DE |
8947 | dbfd = open_dwop_file (dwo_name, comp_dir, 0); |
8948 | if (dbfd == NULL) | |
8949 | { | |
8950 | if (dwarf2_read_debug) | |
8951 | fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name); | |
8952 | return NULL; | |
8953 | } | |
8954 | dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file); | |
8955 | dwo_file->name = obstack_copy0 (&objfile->objfile_obstack, | |
8956 | dwo_name, strlen (dwo_name)); | |
8957 | dwo_file->dbfd = dbfd; | |
3019eac3 DE |
8958 | |
8959 | cleanups = make_cleanup (free_dwo_file_cleanup, dwo_file); | |
8960 | ||
80626a55 | 8961 | bfd_map_over_sections (dbfd, dwarf2_locate_dwo_sections, &dwo_file->sections); |
3019eac3 | 8962 | |
80626a55 | 8963 | dwo_file->cus = create_dwo_debug_info_hash_table (dwo_file); |
3019eac3 DE |
8964 | |
8965 | dwo_file->tus = create_debug_types_hash_table (dwo_file, | |
8966 | dwo_file->sections.types); | |
8967 | ||
8968 | discard_cleanups (cleanups); | |
8969 | ||
80626a55 DE |
8970 | if (dwarf2_read_debug) |
8971 | fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name); | |
8972 | ||
3019eac3 DE |
8973 | return dwo_file; |
8974 | } | |
8975 | ||
80626a55 DE |
8976 | /* This function is mapped across the sections and remembers the offset and |
8977 | size of each of the DWP debugging sections we are interested in. */ | |
3019eac3 | 8978 | |
80626a55 DE |
8979 | static void |
8980 | dwarf2_locate_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_ptr) | |
3019eac3 | 8981 | { |
80626a55 DE |
8982 | struct dwp_file *dwp_file = dwp_file_ptr; |
8983 | const struct dwop_section_names *names = &dwop_section_names; | |
8984 | unsigned int elf_section_nr = elf_section_data (sectp)->this_idx; | |
3019eac3 | 8985 | |
80626a55 DE |
8986 | /* Record the ELF section number for later lookup: this is what the |
8987 | .debug_cu_index,.debug_tu_index tables use. */ | |
8988 | gdb_assert (elf_section_nr < dwp_file->num_sections); | |
8989 | dwp_file->elf_sections[elf_section_nr] = sectp; | |
3019eac3 | 8990 | |
80626a55 DE |
8991 | /* Look for specific sections that we need. */ |
8992 | if (section_is_p (sectp->name, &names->str_dwo)) | |
8993 | { | |
8994 | dwp_file->sections.str.asection = sectp; | |
8995 | dwp_file->sections.str.size = bfd_get_section_size (sectp); | |
8996 | } | |
8997 | else if (section_is_p (sectp->name, &names->cu_index)) | |
8998 | { | |
8999 | dwp_file->sections.cu_index.asection = sectp; | |
9000 | dwp_file->sections.cu_index.size = bfd_get_section_size (sectp); | |
9001 | } | |
9002 | else if (section_is_p (sectp->name, &names->tu_index)) | |
9003 | { | |
9004 | dwp_file->sections.tu_index.asection = sectp; | |
9005 | dwp_file->sections.tu_index.size = bfd_get_section_size (sectp); | |
9006 | } | |
9007 | } | |
3019eac3 | 9008 | |
80626a55 | 9009 | /* Hash function for dwp_file loaded CUs/TUs. */ |
3019eac3 | 9010 | |
80626a55 DE |
9011 | static hashval_t |
9012 | hash_dwp_loaded_cutus (const void *item) | |
9013 | { | |
9014 | const struct dwo_unit *dwo_unit = item; | |
3019eac3 | 9015 | |
80626a55 DE |
9016 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
9017 | return dwo_unit->signature; | |
3019eac3 DE |
9018 | } |
9019 | ||
80626a55 | 9020 | /* Equality function for dwp_file loaded CUs/TUs. */ |
3019eac3 | 9021 | |
80626a55 DE |
9022 | static int |
9023 | eq_dwp_loaded_cutus (const void *a, const void *b) | |
3019eac3 | 9024 | { |
80626a55 DE |
9025 | const struct dwo_unit *dua = a; |
9026 | const struct dwo_unit *dub = b; | |
3019eac3 | 9027 | |
80626a55 DE |
9028 | return dua->signature == dub->signature; |
9029 | } | |
3019eac3 | 9030 | |
80626a55 | 9031 | /* Allocate a hash table for dwp_file loaded CUs/TUs. */ |
3019eac3 | 9032 | |
80626a55 DE |
9033 | static htab_t |
9034 | allocate_dwp_loaded_cutus_table (struct objfile *objfile) | |
9035 | { | |
9036 | return htab_create_alloc_ex (3, | |
9037 | hash_dwp_loaded_cutus, | |
9038 | eq_dwp_loaded_cutus, | |
9039 | NULL, | |
9040 | &objfile->objfile_obstack, | |
9041 | hashtab_obstack_allocate, | |
9042 | dummy_obstack_deallocate); | |
9043 | } | |
3019eac3 | 9044 | |
80626a55 DE |
9045 | /* Initialize the use of the DWP file for the current objfile. |
9046 | By convention the name of the DWP file is ${objfile}.dwp. | |
9047 | The result is NULL if it can't be found. */ | |
a766d390 | 9048 | |
80626a55 DE |
9049 | static struct dwp_file * |
9050 | open_and_init_dwp_file (const char *comp_dir) | |
9051 | { | |
9052 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
9053 | struct dwp_file *dwp_file; | |
9054 | char *dwp_name; | |
9055 | bfd *dbfd; | |
9056 | struct cleanup *cleanups; | |
9057 | ||
2792b94d | 9058 | dwp_name = xstrprintf ("%s.dwp", dwarf2_per_objfile->objfile->name); |
80626a55 DE |
9059 | cleanups = make_cleanup (xfree, dwp_name); |
9060 | ||
9061 | dbfd = open_dwop_file (dwp_name, comp_dir, 1); | |
9062 | if (dbfd == NULL) | |
9063 | { | |
9064 | if (dwarf2_read_debug) | |
9065 | fprintf_unfiltered (gdb_stdlog, "DWP file not found: %s\n", dwp_name); | |
9066 | do_cleanups (cleanups); | |
9067 | return NULL; | |
3019eac3 | 9068 | } |
80626a55 DE |
9069 | dwp_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_file); |
9070 | dwp_file->name = obstack_copy0 (&objfile->objfile_obstack, | |
9071 | dwp_name, strlen (dwp_name)); | |
9072 | dwp_file->dbfd = dbfd; | |
9073 | do_cleanups (cleanups); | |
c906108c | 9074 | |
80626a55 | 9075 | cleanups = make_cleanup (free_dwo_file_cleanup, dwp_file); |
df8a16a1 | 9076 | |
80626a55 DE |
9077 | /* +1: section 0 is unused */ |
9078 | dwp_file->num_sections = bfd_count_sections (dbfd) + 1; | |
9079 | dwp_file->elf_sections = | |
9080 | OBSTACK_CALLOC (&objfile->objfile_obstack, | |
9081 | dwp_file->num_sections, asection *); | |
9082 | ||
9083 | bfd_map_over_sections (dbfd, dwarf2_locate_dwp_sections, dwp_file); | |
9084 | ||
9085 | dwp_file->cus = create_dwp_hash_table (dwp_file, 0); | |
9086 | ||
9087 | dwp_file->tus = create_dwp_hash_table (dwp_file, 1); | |
9088 | ||
9089 | dwp_file->loaded_cutus = allocate_dwp_loaded_cutus_table (objfile); | |
9090 | ||
9091 | discard_cleanups (cleanups); | |
9092 | ||
9093 | if (dwarf2_read_debug) | |
9094 | { | |
9095 | fprintf_unfiltered (gdb_stdlog, "DWP file found: %s\n", dwp_file->name); | |
9096 | fprintf_unfiltered (gdb_stdlog, | |
9097 | " %u CUs, %u TUs\n", | |
9098 | dwp_file->cus ? dwp_file->cus->nr_units : 0, | |
9099 | dwp_file->tus ? dwp_file->tus->nr_units : 0); | |
9100 | } | |
9101 | ||
9102 | return dwp_file; | |
3019eac3 | 9103 | } |
c906108c | 9104 | |
80626a55 DE |
9105 | /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit. |
9106 | Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME | |
9107 | or in the DWP file for the objfile, referenced by THIS_UNIT. | |
3019eac3 | 9108 | If non-NULL, comp_dir is the DW_AT_comp_dir attribute. |
80626a55 DE |
9109 | IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU. |
9110 | ||
9111 | This is called, for example, when wanting to read a variable with a | |
9112 | complex location. Therefore we don't want to do file i/o for every call. | |
9113 | Therefore we don't want to look for a DWO file on every call. | |
9114 | Therefore we first see if we've already seen SIGNATURE in a DWP file, | |
9115 | then we check if we've already seen DWO_NAME, and only THEN do we check | |
9116 | for a DWO file. | |
9117 | ||
1c658ad5 | 9118 | The result is a pointer to the dwo_unit object or NULL if we didn't find it |
80626a55 | 9119 | (dwo_id mismatch or couldn't find the DWO/DWP file). */ |
debd256d | 9120 | |
3019eac3 | 9121 | static struct dwo_unit * |
80626a55 DE |
9122 | lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit, |
9123 | const char *dwo_name, const char *comp_dir, | |
9124 | ULONGEST signature, int is_debug_types) | |
3019eac3 DE |
9125 | { |
9126 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
80626a55 DE |
9127 | const char *kind = is_debug_types ? "TU" : "CU"; |
9128 | void **dwo_file_slot; | |
3019eac3 | 9129 | struct dwo_file *dwo_file; |
80626a55 | 9130 | struct dwp_file *dwp_file; |
cb1df416 | 9131 | |
80626a55 | 9132 | /* Have we already read SIGNATURE from a DWP file? */ |
cf2c3c16 | 9133 | |
80626a55 DE |
9134 | if (! dwarf2_per_objfile->dwp_checked) |
9135 | { | |
9136 | dwarf2_per_objfile->dwp_file = open_and_init_dwp_file (comp_dir); | |
9137 | dwarf2_per_objfile->dwp_checked = 1; | |
9138 | } | |
9139 | dwp_file = dwarf2_per_objfile->dwp_file; | |
3019eac3 | 9140 | |
80626a55 | 9141 | if (dwp_file != NULL) |
cf2c3c16 | 9142 | { |
80626a55 DE |
9143 | const struct dwp_hash_table *dwp_htab = |
9144 | is_debug_types ? dwp_file->tus : dwp_file->cus; | |
9145 | ||
9146 | if (dwp_htab != NULL) | |
9147 | { | |
9148 | struct dwo_unit *dwo_cutu = | |
9149 | lookup_dwo_in_dwp (dwp_file, dwp_htab, signature, is_debug_types); | |
9150 | ||
9151 | if (dwo_cutu != NULL) | |
9152 | { | |
9153 | if (dwarf2_read_debug) | |
9154 | { | |
9155 | fprintf_unfiltered (gdb_stdlog, | |
9156 | "Virtual DWO %s %s found: @%s\n", | |
9157 | kind, hex_string (signature), | |
9158 | host_address_to_string (dwo_cutu)); | |
9159 | } | |
9160 | return dwo_cutu; | |
9161 | } | |
9162 | } | |
9163 | } | |
9164 | ||
9165 | /* Have we already seen DWO_NAME? */ | |
9166 | ||
9167 | dwo_file_slot = lookup_dwo_file_slot (dwo_name); | |
9168 | if (*dwo_file_slot == NULL) | |
9169 | { | |
9170 | /* Read in the file and build a table of the DWOs it contains. */ | |
9171 | *dwo_file_slot = open_and_init_dwo_file (dwo_name, comp_dir); | |
9172 | } | |
9173 | /* NOTE: This will be NULL if unable to open the file. */ | |
9174 | dwo_file = *dwo_file_slot; | |
9175 | ||
9176 | if (dwo_file != NULL) | |
9177 | { | |
9178 | htab_t htab = is_debug_types ? dwo_file->tus : dwo_file->cus; | |
9179 | ||
9180 | if (htab != NULL) | |
9181 | { | |
9182 | struct dwo_unit find_dwo_cutu, *dwo_cutu; | |
9a619af0 | 9183 | |
80626a55 DE |
9184 | memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu)); |
9185 | find_dwo_cutu.signature = signature; | |
9186 | dwo_cutu = htab_find (htab, &find_dwo_cutu); | |
3019eac3 | 9187 | |
80626a55 DE |
9188 | if (dwo_cutu != NULL) |
9189 | { | |
9190 | if (dwarf2_read_debug) | |
9191 | { | |
9192 | fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) found: @%s\n", | |
9193 | kind, dwo_name, hex_string (signature), | |
9194 | host_address_to_string (dwo_cutu)); | |
9195 | } | |
9196 | return dwo_cutu; | |
9197 | } | |
9198 | } | |
2e276125 | 9199 | } |
9cdd5dbd | 9200 | |
80626a55 DE |
9201 | /* We didn't find it. This could mean a dwo_id mismatch, or |
9202 | someone deleted the DWO/DWP file, or the search path isn't set up | |
9203 | correctly to find the file. */ | |
9204 | ||
9205 | if (dwarf2_read_debug) | |
9206 | { | |
9207 | fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) not found\n", | |
9208 | kind, dwo_name, hex_string (signature)); | |
9209 | } | |
3019eac3 DE |
9210 | |
9211 | complaint (&symfile_complaints, | |
80626a55 | 9212 | _("Could not find DWO CU referenced by CU at offset 0x%x" |
3019eac3 | 9213 | " [in module %s]"), |
80626a55 | 9214 | this_unit->offset.sect_off, objfile->name); |
3019eac3 | 9215 | return NULL; |
5fb290d7 DJ |
9216 | } |
9217 | ||
80626a55 DE |
9218 | /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU. |
9219 | See lookup_dwo_cutu_unit for details. */ | |
9220 | ||
9221 | static struct dwo_unit * | |
9222 | lookup_dwo_comp_unit (struct dwarf2_per_cu_data *this_cu, | |
9223 | const char *dwo_name, const char *comp_dir, | |
9224 | ULONGEST signature) | |
9225 | { | |
9226 | return lookup_dwo_cutu (this_cu, dwo_name, comp_dir, signature, 0); | |
9227 | } | |
9228 | ||
9229 | /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU. | |
9230 | See lookup_dwo_cutu_unit for details. */ | |
9231 | ||
9232 | static struct dwo_unit * | |
9233 | lookup_dwo_type_unit (struct signatured_type *this_tu, | |
9234 | const char *dwo_name, const char *comp_dir) | |
9235 | { | |
9236 | return lookup_dwo_cutu (&this_tu->per_cu, dwo_name, comp_dir, this_tu->signature, 1); | |
9237 | } | |
9238 | ||
3019eac3 DE |
9239 | /* Free all resources associated with DWO_FILE. |
9240 | Close the DWO file and munmap the sections. | |
9241 | All memory should be on the objfile obstack. */ | |
348e048f DE |
9242 | |
9243 | static void | |
3019eac3 | 9244 | free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile) |
348e048f | 9245 | { |
3019eac3 DE |
9246 | int ix; |
9247 | struct dwarf2_section_info *section; | |
348e048f | 9248 | |
80626a55 DE |
9249 | gdb_assert (dwo_file->dbfd != objfile->obfd); |
9250 | gdb_bfd_unref (dwo_file->dbfd); | |
348e048f | 9251 | |
3019eac3 DE |
9252 | VEC_free (dwarf2_section_info_def, dwo_file->sections.types); |
9253 | } | |
348e048f | 9254 | |
3019eac3 | 9255 | /* Wrapper for free_dwo_file for use in cleanups. */ |
348e048f | 9256 | |
3019eac3 DE |
9257 | static void |
9258 | free_dwo_file_cleanup (void *arg) | |
9259 | { | |
9260 | struct dwo_file *dwo_file = (struct dwo_file *) arg; | |
9261 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
348e048f | 9262 | |
3019eac3 DE |
9263 | free_dwo_file (dwo_file, objfile); |
9264 | } | |
348e048f | 9265 | |
3019eac3 | 9266 | /* Traversal function for free_dwo_files. */ |
2ab95328 | 9267 | |
3019eac3 DE |
9268 | static int |
9269 | free_dwo_file_from_slot (void **slot, void *info) | |
9270 | { | |
9271 | struct dwo_file *dwo_file = (struct dwo_file *) *slot; | |
9272 | struct objfile *objfile = (struct objfile *) info; | |
348e048f | 9273 | |
3019eac3 | 9274 | free_dwo_file (dwo_file, objfile); |
348e048f | 9275 | |
3019eac3 DE |
9276 | return 1; |
9277 | } | |
348e048f | 9278 | |
3019eac3 | 9279 | /* Free all resources associated with DWO_FILES. */ |
348e048f | 9280 | |
3019eac3 DE |
9281 | static void |
9282 | free_dwo_files (htab_t dwo_files, struct objfile *objfile) | |
9283 | { | |
9284 | htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile); | |
348e048f | 9285 | } |
3019eac3 DE |
9286 | \f |
9287 | /* Read in various DIEs. */ | |
348e048f | 9288 | |
d389af10 JK |
9289 | /* qsort helper for inherit_abstract_dies. */ |
9290 | ||
9291 | static int | |
9292 | unsigned_int_compar (const void *ap, const void *bp) | |
9293 | { | |
9294 | unsigned int a = *(unsigned int *) ap; | |
9295 | unsigned int b = *(unsigned int *) bp; | |
9296 | ||
9297 | return (a > b) - (b > a); | |
9298 | } | |
9299 | ||
9300 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
9301 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
9302 | already referenced by DW_AT_abstract_origin from the children of the | |
9303 | current DIE. */ | |
d389af10 JK |
9304 | |
9305 | static void | |
9306 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
9307 | { | |
9308 | struct die_info *child_die; | |
9309 | unsigned die_children_count; | |
9310 | /* CU offsets which were referenced by children of the current DIE. */ | |
b64f50a1 JK |
9311 | sect_offset *offsets; |
9312 | sect_offset *offsets_end, *offsetp; | |
d389af10 JK |
9313 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ |
9314 | struct die_info *origin_die; | |
9315 | /* Iterator of the ORIGIN_DIE children. */ | |
9316 | struct die_info *origin_child_die; | |
9317 | struct cleanup *cleanups; | |
9318 | struct attribute *attr; | |
cd02d79d PA |
9319 | struct dwarf2_cu *origin_cu; |
9320 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
9321 | |
9322 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
9323 | if (!attr) | |
9324 | return; | |
9325 | ||
cd02d79d PA |
9326 | /* Note that following die references may follow to a die in a |
9327 | different cu. */ | |
9328 | ||
9329 | origin_cu = cu; | |
9330 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
9331 | ||
9332 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
9333 | symbols in. */ | |
9334 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
9335 | origin_cu->list_in_scope = cu->list_in_scope; | |
9336 | ||
edb3359d DJ |
9337 | if (die->tag != origin_die->tag |
9338 | && !(die->tag == DW_TAG_inlined_subroutine | |
9339 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
9340 | complaint (&symfile_complaints, |
9341 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
b64f50a1 | 9342 | die->offset.sect_off, origin_die->offset.sect_off); |
d389af10 JK |
9343 | |
9344 | child_die = die->child; | |
9345 | die_children_count = 0; | |
9346 | while (child_die && child_die->tag) | |
9347 | { | |
9348 | child_die = sibling_die (child_die); | |
9349 | die_children_count++; | |
9350 | } | |
9351 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
9352 | cleanups = make_cleanup (xfree, offsets); | |
9353 | ||
9354 | offsets_end = offsets; | |
9355 | child_die = die->child; | |
9356 | while (child_die && child_die->tag) | |
9357 | { | |
c38f313d DJ |
9358 | /* For each CHILD_DIE, find the corresponding child of |
9359 | ORIGIN_DIE. If there is more than one layer of | |
9360 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
9361 | but GCC versions at least through 4.4 generate this (GCC PR | |
9362 | 40573). */ | |
9363 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 9364 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 9365 | |
c38f313d DJ |
9366 | while (1) |
9367 | { | |
cd02d79d PA |
9368 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
9369 | child_origin_cu); | |
c38f313d DJ |
9370 | if (attr == NULL) |
9371 | break; | |
cd02d79d PA |
9372 | child_origin_die = follow_die_ref (child_origin_die, attr, |
9373 | &child_origin_cu); | |
c38f313d DJ |
9374 | } |
9375 | ||
d389af10 JK |
9376 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
9377 | counterpart may exist. */ | |
c38f313d | 9378 | if (child_origin_die != child_die) |
d389af10 | 9379 | { |
edb3359d DJ |
9380 | if (child_die->tag != child_origin_die->tag |
9381 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
9382 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
9383 | complaint (&symfile_complaints, |
9384 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
b64f50a1 JK |
9385 | "different tags"), child_die->offset.sect_off, |
9386 | child_origin_die->offset.sect_off); | |
c38f313d DJ |
9387 | if (child_origin_die->parent != origin_die) |
9388 | complaint (&symfile_complaints, | |
9389 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
b64f50a1 JK |
9390 | "different parents"), child_die->offset.sect_off, |
9391 | child_origin_die->offset.sect_off); | |
c38f313d DJ |
9392 | else |
9393 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
9394 | } |
9395 | child_die = sibling_die (child_die); | |
9396 | } | |
9397 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
9398 | unsigned_int_compar); | |
9399 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
b64f50a1 | 9400 | if (offsetp[-1].sect_off == offsetp->sect_off) |
3e43a32a MS |
9401 | complaint (&symfile_complaints, |
9402 | _("Multiple children of DIE 0x%x refer " | |
9403 | "to DIE 0x%x as their abstract origin"), | |
b64f50a1 | 9404 | die->offset.sect_off, offsetp->sect_off); |
d389af10 JK |
9405 | |
9406 | offsetp = offsets; | |
9407 | origin_child_die = origin_die->child; | |
9408 | while (origin_child_die && origin_child_die->tag) | |
9409 | { | |
9410 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
b64f50a1 JK |
9411 | while (offsetp < offsets_end |
9412 | && offsetp->sect_off < origin_child_die->offset.sect_off) | |
d389af10 | 9413 | offsetp++; |
b64f50a1 JK |
9414 | if (offsetp >= offsets_end |
9415 | || offsetp->sect_off > origin_child_die->offset.sect_off) | |
d389af10 JK |
9416 | { |
9417 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 9418 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
9419 | } |
9420 | origin_child_die = sibling_die (origin_child_die); | |
9421 | } | |
cd02d79d | 9422 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
9423 | |
9424 | do_cleanups (cleanups); | |
9425 | } | |
9426 | ||
c906108c | 9427 | static void |
e7c27a73 | 9428 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9429 | { |
e7c27a73 | 9430 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 9431 | struct context_stack *new; |
c906108c SS |
9432 | CORE_ADDR lowpc; |
9433 | CORE_ADDR highpc; | |
9434 | struct die_info *child_die; | |
edb3359d | 9435 | struct attribute *attr, *call_line, *call_file; |
15d034d0 | 9436 | const char *name; |
e142c38c | 9437 | CORE_ADDR baseaddr; |
801e3a5b | 9438 | struct block *block; |
edb3359d | 9439 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
9440 | VEC (symbolp) *template_args = NULL; |
9441 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
9442 | |
9443 | if (inlined_func) | |
9444 | { | |
9445 | /* If we do not have call site information, we can't show the | |
9446 | caller of this inlined function. That's too confusing, so | |
9447 | only use the scope for local variables. */ | |
9448 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
9449 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
9450 | if (call_line == NULL || call_file == NULL) | |
9451 | { | |
9452 | read_lexical_block_scope (die, cu); | |
9453 | return; | |
9454 | } | |
9455 | } | |
c906108c | 9456 | |
e142c38c DJ |
9457 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
9458 | ||
94af9270 | 9459 | name = dwarf2_name (die, cu); |
c906108c | 9460 | |
e8d05480 JB |
9461 | /* Ignore functions with missing or empty names. These are actually |
9462 | illegal according to the DWARF standard. */ | |
9463 | if (name == NULL) | |
9464 | { | |
9465 | complaint (&symfile_complaints, | |
b64f50a1 JK |
9466 | _("missing name for subprogram DIE at %d"), |
9467 | die->offset.sect_off); | |
e8d05480 JB |
9468 | return; |
9469 | } | |
9470 | ||
9471 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
9472 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
9473 | { | |
ae4d0c03 PM |
9474 | attr = dwarf2_attr (die, DW_AT_external, cu); |
9475 | if (!attr || !DW_UNSND (attr)) | |
9476 | complaint (&symfile_complaints, | |
3e43a32a MS |
9477 | _("cannot get low and high bounds " |
9478 | "for subprogram DIE at %d"), | |
b64f50a1 | 9479 | die->offset.sect_off); |
e8d05480 JB |
9480 | return; |
9481 | } | |
c906108c SS |
9482 | |
9483 | lowpc += baseaddr; | |
9484 | highpc += baseaddr; | |
9485 | ||
34eaf542 TT |
9486 | /* If we have any template arguments, then we must allocate a |
9487 | different sort of symbol. */ | |
9488 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
9489 | { | |
9490 | if (child_die->tag == DW_TAG_template_type_param | |
9491 | || child_die->tag == DW_TAG_template_value_param) | |
9492 | { | |
9493 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
9494 | struct template_symbol); | |
9495 | templ_func->base.is_cplus_template_function = 1; | |
9496 | break; | |
9497 | } | |
9498 | } | |
9499 | ||
c906108c | 9500 | new = push_context (0, lowpc); |
34eaf542 TT |
9501 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
9502 | (struct symbol *) templ_func); | |
4c2df51b | 9503 | |
4cecd739 DJ |
9504 | /* If there is a location expression for DW_AT_frame_base, record |
9505 | it. */ | |
e142c38c | 9506 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 9507 | if (attr) |
c034e007 AC |
9508 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
9509 | expression is being recorded directly in the function's symbol | |
9510 | and not in a separate frame-base object. I guess this hack is | |
9511 | to avoid adding some sort of frame-base adjunct/annex to the | |
9512 | function's symbol :-(. The problem with doing this is that it | |
9513 | results in a function symbol with a location expression that | |
9514 | has nothing to do with the location of the function, ouch! The | |
9515 | relationship should be: a function's symbol has-a frame base; a | |
9516 | frame-base has-a location expression. */ | |
e7c27a73 | 9517 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 9518 | |
e142c38c | 9519 | cu->list_in_scope = &local_symbols; |
c906108c | 9520 | |
639d11d3 | 9521 | if (die->child != NULL) |
c906108c | 9522 | { |
639d11d3 | 9523 | child_die = die->child; |
c906108c SS |
9524 | while (child_die && child_die->tag) |
9525 | { | |
34eaf542 TT |
9526 | if (child_die->tag == DW_TAG_template_type_param |
9527 | || child_die->tag == DW_TAG_template_value_param) | |
9528 | { | |
9529 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
9530 | ||
f1078f66 DJ |
9531 | if (arg != NULL) |
9532 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
9533 | } |
9534 | else | |
9535 | process_die (child_die, cu); | |
c906108c SS |
9536 | child_die = sibling_die (child_die); |
9537 | } | |
9538 | } | |
9539 | ||
d389af10 JK |
9540 | inherit_abstract_dies (die, cu); |
9541 | ||
4a811a97 UW |
9542 | /* If we have a DW_AT_specification, we might need to import using |
9543 | directives from the context of the specification DIE. See the | |
9544 | comment in determine_prefix. */ | |
9545 | if (cu->language == language_cplus | |
9546 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
9547 | { | |
9548 | struct dwarf2_cu *spec_cu = cu; | |
9549 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
9550 | ||
9551 | while (spec_die) | |
9552 | { | |
9553 | child_die = spec_die->child; | |
9554 | while (child_die && child_die->tag) | |
9555 | { | |
9556 | if (child_die->tag == DW_TAG_imported_module) | |
9557 | process_die (child_die, spec_cu); | |
9558 | child_die = sibling_die (child_die); | |
9559 | } | |
9560 | ||
9561 | /* In some cases, GCC generates specification DIEs that | |
9562 | themselves contain DW_AT_specification attributes. */ | |
9563 | spec_die = die_specification (spec_die, &spec_cu); | |
9564 | } | |
9565 | } | |
9566 | ||
c906108c SS |
9567 | new = pop_context (); |
9568 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
9569 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
9570 | lowpc, highpc, objfile); | |
9571 | ||
df8a16a1 | 9572 | /* For C++, set the block's scope. */ |
f55ee35c | 9573 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 9574 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 9575 | determine_prefix (die, cu), |
df8a16a1 DJ |
9576 | processing_has_namespace_info); |
9577 | ||
801e3a5b JB |
9578 | /* If we have address ranges, record them. */ |
9579 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 9580 | |
34eaf542 TT |
9581 | /* Attach template arguments to function. */ |
9582 | if (! VEC_empty (symbolp, template_args)) | |
9583 | { | |
9584 | gdb_assert (templ_func != NULL); | |
9585 | ||
9586 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
9587 | templ_func->template_arguments | |
9588 | = obstack_alloc (&objfile->objfile_obstack, | |
9589 | (templ_func->n_template_arguments | |
9590 | * sizeof (struct symbol *))); | |
9591 | memcpy (templ_func->template_arguments, | |
9592 | VEC_address (symbolp, template_args), | |
9593 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
9594 | VEC_free (symbolp, template_args); | |
9595 | } | |
9596 | ||
208d8187 JB |
9597 | /* In C++, we can have functions nested inside functions (e.g., when |
9598 | a function declares a class that has methods). This means that | |
9599 | when we finish processing a function scope, we may need to go | |
9600 | back to building a containing block's symbol lists. */ | |
9601 | local_symbols = new->locals; | |
27aa8d6a | 9602 | using_directives = new->using_directives; |
208d8187 | 9603 | |
921e78cf JB |
9604 | /* If we've finished processing a top-level function, subsequent |
9605 | symbols go in the file symbol list. */ | |
9606 | if (outermost_context_p ()) | |
e142c38c | 9607 | cu->list_in_scope = &file_symbols; |
c906108c SS |
9608 | } |
9609 | ||
9610 | /* Process all the DIES contained within a lexical block scope. Start | |
9611 | a new scope, process the dies, and then close the scope. */ | |
9612 | ||
9613 | static void | |
e7c27a73 | 9614 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9615 | { |
e7c27a73 | 9616 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 9617 | struct context_stack *new; |
c906108c SS |
9618 | CORE_ADDR lowpc, highpc; |
9619 | struct die_info *child_die; | |
e142c38c DJ |
9620 | CORE_ADDR baseaddr; |
9621 | ||
9622 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
9623 | |
9624 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
9625 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
9626 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 9627 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 9628 | describe ranges. */ |
d85a05f0 | 9629 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
9630 | return; |
9631 | lowpc += baseaddr; | |
9632 | highpc += baseaddr; | |
9633 | ||
9634 | push_context (0, lowpc); | |
639d11d3 | 9635 | if (die->child != NULL) |
c906108c | 9636 | { |
639d11d3 | 9637 | child_die = die->child; |
c906108c SS |
9638 | while (child_die && child_die->tag) |
9639 | { | |
e7c27a73 | 9640 | process_die (child_die, cu); |
c906108c SS |
9641 | child_die = sibling_die (child_die); |
9642 | } | |
9643 | } | |
9644 | new = pop_context (); | |
9645 | ||
8540c487 | 9646 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 9647 | { |
801e3a5b JB |
9648 | struct block *block |
9649 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
9650 | highpc, objfile); | |
9651 | ||
9652 | /* Note that recording ranges after traversing children, as we | |
9653 | do here, means that recording a parent's ranges entails | |
9654 | walking across all its children's ranges as they appear in | |
9655 | the address map, which is quadratic behavior. | |
9656 | ||
9657 | It would be nicer to record the parent's ranges before | |
9658 | traversing its children, simply overriding whatever you find | |
9659 | there. But since we don't even decide whether to create a | |
9660 | block until after we've traversed its children, that's hard | |
9661 | to do. */ | |
9662 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
9663 | } |
9664 | local_symbols = new->locals; | |
27aa8d6a | 9665 | using_directives = new->using_directives; |
c906108c SS |
9666 | } |
9667 | ||
96408a79 SA |
9668 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
9669 | ||
9670 | static void | |
9671 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) | |
9672 | { | |
9673 | struct objfile *objfile = cu->objfile; | |
9674 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
9675 | CORE_ADDR pc, baseaddr; | |
9676 | struct attribute *attr; | |
9677 | struct call_site *call_site, call_site_local; | |
9678 | void **slot; | |
9679 | int nparams; | |
9680 | struct die_info *child_die; | |
9681 | ||
9682 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
9683 | ||
9684 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
9685 | if (!attr) | |
9686 | { | |
9687 | complaint (&symfile_complaints, | |
9688 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " | |
9689 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 9690 | die->offset.sect_off, objfile->name); |
96408a79 SA |
9691 | return; |
9692 | } | |
9693 | pc = DW_ADDR (attr) + baseaddr; | |
9694 | ||
9695 | if (cu->call_site_htab == NULL) | |
9696 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, | |
9697 | NULL, &objfile->objfile_obstack, | |
9698 | hashtab_obstack_allocate, NULL); | |
9699 | call_site_local.pc = pc; | |
9700 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); | |
9701 | if (*slot != NULL) | |
9702 | { | |
9703 | complaint (&symfile_complaints, | |
9704 | _("Duplicate PC %s for DW_TAG_GNU_call_site " | |
9705 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 9706 | paddress (gdbarch, pc), die->offset.sect_off, objfile->name); |
96408a79 SA |
9707 | return; |
9708 | } | |
9709 | ||
9710 | /* Count parameters at the caller. */ | |
9711 | ||
9712 | nparams = 0; | |
9713 | for (child_die = die->child; child_die && child_die->tag; | |
9714 | child_die = sibling_die (child_die)) | |
9715 | { | |
9716 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
9717 | { | |
9718 | complaint (&symfile_complaints, | |
9719 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " | |
9720 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 9721 | child_die->tag, child_die->offset.sect_off, objfile->name); |
96408a79 SA |
9722 | continue; |
9723 | } | |
9724 | ||
9725 | nparams++; | |
9726 | } | |
9727 | ||
9728 | call_site = obstack_alloc (&objfile->objfile_obstack, | |
9729 | (sizeof (*call_site) | |
9730 | + (sizeof (*call_site->parameter) | |
9731 | * (nparams - 1)))); | |
9732 | *slot = call_site; | |
9733 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); | |
9734 | call_site->pc = pc; | |
9735 | ||
9736 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) | |
9737 | { | |
9738 | struct die_info *func_die; | |
9739 | ||
9740 | /* Skip also over DW_TAG_inlined_subroutine. */ | |
9741 | for (func_die = die->parent; | |
9742 | func_die && func_die->tag != DW_TAG_subprogram | |
9743 | && func_die->tag != DW_TAG_subroutine_type; | |
9744 | func_die = func_die->parent); | |
9745 | ||
9746 | /* DW_AT_GNU_all_call_sites is a superset | |
9747 | of DW_AT_GNU_all_tail_call_sites. */ | |
9748 | if (func_die | |
9749 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) | |
9750 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) | |
9751 | { | |
9752 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is | |
9753 | not complete. But keep CALL_SITE for look ups via call_site_htab, | |
9754 | both the initial caller containing the real return address PC and | |
9755 | the final callee containing the current PC of a chain of tail | |
9756 | calls do not need to have the tail call list complete. But any | |
9757 | function candidate for a virtual tail call frame searched via | |
9758 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be | |
9759 | determined unambiguously. */ | |
9760 | } | |
9761 | else | |
9762 | { | |
9763 | struct type *func_type = NULL; | |
9764 | ||
9765 | if (func_die) | |
9766 | func_type = get_die_type (func_die, cu); | |
9767 | if (func_type != NULL) | |
9768 | { | |
9769 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); | |
9770 | ||
9771 | /* Enlist this call site to the function. */ | |
9772 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); | |
9773 | TYPE_TAIL_CALL_LIST (func_type) = call_site; | |
9774 | } | |
9775 | else | |
9776 | complaint (&symfile_complaints, | |
9777 | _("Cannot find function owning DW_TAG_GNU_call_site " | |
9778 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 9779 | die->offset.sect_off, objfile->name); |
96408a79 SA |
9780 | } |
9781 | } | |
9782 | ||
9783 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); | |
9784 | if (attr == NULL) | |
9785 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
9786 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); | |
9787 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) | |
9788 | /* Keep NULL DWARF_BLOCK. */; | |
9789 | else if (attr_form_is_block (attr)) | |
9790 | { | |
9791 | struct dwarf2_locexpr_baton *dlbaton; | |
9792 | ||
9793 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); | |
9794 | dlbaton->data = DW_BLOCK (attr)->data; | |
9795 | dlbaton->size = DW_BLOCK (attr)->size; | |
9796 | dlbaton->per_cu = cu->per_cu; | |
9797 | ||
9798 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); | |
9799 | } | |
9800 | else if (is_ref_attr (attr)) | |
9801 | { | |
96408a79 SA |
9802 | struct dwarf2_cu *target_cu = cu; |
9803 | struct die_info *target_die; | |
9804 | ||
9805 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); | |
9806 | gdb_assert (target_cu->objfile == objfile); | |
9807 | if (die_is_declaration (target_die, target_cu)) | |
9808 | { | |
9809 | const char *target_physname; | |
9810 | ||
9811 | target_physname = dwarf2_physname (NULL, target_die, target_cu); | |
9812 | if (target_physname == NULL) | |
9813 | complaint (&symfile_complaints, | |
9814 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
9815 | "physname, for referencing DIE 0x%x [in module %s]"), | |
b64f50a1 | 9816 | die->offset.sect_off, objfile->name); |
96408a79 SA |
9817 | else |
9818 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); | |
9819 | } | |
9820 | else | |
9821 | { | |
9822 | CORE_ADDR lowpc; | |
9823 | ||
9824 | /* DW_AT_entry_pc should be preferred. */ | |
9825 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) | |
9826 | complaint (&symfile_complaints, | |
9827 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
9828 | "low pc, for referencing DIE 0x%x [in module %s]"), | |
b64f50a1 | 9829 | die->offset.sect_off, objfile->name); |
96408a79 SA |
9830 | else |
9831 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); | |
9832 | } | |
9833 | } | |
9834 | else | |
9835 | complaint (&symfile_complaints, | |
9836 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " | |
9837 | "block nor reference, for DIE 0x%x [in module %s]"), | |
b64f50a1 | 9838 | die->offset.sect_off, objfile->name); |
96408a79 SA |
9839 | |
9840 | call_site->per_cu = cu->per_cu; | |
9841 | ||
9842 | for (child_die = die->child; | |
9843 | child_die && child_die->tag; | |
9844 | child_die = sibling_die (child_die)) | |
9845 | { | |
96408a79 | 9846 | struct call_site_parameter *parameter; |
1788b2d3 | 9847 | struct attribute *loc, *origin; |
96408a79 SA |
9848 | |
9849 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
9850 | { | |
9851 | /* Already printed the complaint above. */ | |
9852 | continue; | |
9853 | } | |
9854 | ||
9855 | gdb_assert (call_site->parameter_count < nparams); | |
9856 | parameter = &call_site->parameter[call_site->parameter_count]; | |
9857 | ||
1788b2d3 JK |
9858 | /* DW_AT_location specifies the register number or DW_AT_abstract_origin |
9859 | specifies DW_TAG_formal_parameter. Value of the data assumed for the | |
9860 | register is contained in DW_AT_GNU_call_site_value. */ | |
96408a79 | 9861 | |
24c5c679 | 9862 | loc = dwarf2_attr (child_die, DW_AT_location, cu); |
1788b2d3 JK |
9863 | origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu); |
9864 | if (loc == NULL && origin != NULL && is_ref_attr (origin)) | |
9865 | { | |
9866 | sect_offset offset; | |
9867 | ||
9868 | parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET; | |
9869 | offset = dwarf2_get_ref_die_offset (origin); | |
d76b7dbc JK |
9870 | if (!offset_in_cu_p (&cu->header, offset)) |
9871 | { | |
9872 | /* As DW_OP_GNU_parameter_ref uses CU-relative offset this | |
9873 | binding can be done only inside one CU. Such referenced DIE | |
9874 | therefore cannot be even moved to DW_TAG_partial_unit. */ | |
9875 | complaint (&symfile_complaints, | |
9876 | _("DW_AT_abstract_origin offset is not in CU for " | |
9877 | "DW_TAG_GNU_call_site child DIE 0x%x " | |
9878 | "[in module %s]"), | |
9879 | child_die->offset.sect_off, objfile->name); | |
9880 | continue; | |
9881 | } | |
1788b2d3 JK |
9882 | parameter->u.param_offset.cu_off = (offset.sect_off |
9883 | - cu->header.offset.sect_off); | |
9884 | } | |
9885 | else if (loc == NULL || origin != NULL || !attr_form_is_block (loc)) | |
96408a79 SA |
9886 | { |
9887 | complaint (&symfile_complaints, | |
9888 | _("No DW_FORM_block* DW_AT_location for " | |
9889 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 9890 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
9891 | continue; |
9892 | } | |
24c5c679 | 9893 | else |
96408a79 | 9894 | { |
24c5c679 JK |
9895 | parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg |
9896 | (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]); | |
9897 | if (parameter->u.dwarf_reg != -1) | |
9898 | parameter->kind = CALL_SITE_PARAMETER_DWARF_REG; | |
9899 | else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data, | |
9900 | &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size], | |
9901 | ¶meter->u.fb_offset)) | |
9902 | parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET; | |
9903 | else | |
9904 | { | |
9905 | complaint (&symfile_complaints, | |
9906 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " | |
9907 | "for DW_FORM_block* DW_AT_location is supported for " | |
9908 | "DW_TAG_GNU_call_site child DIE 0x%x " | |
9909 | "[in module %s]"), | |
9910 | child_die->offset.sect_off, objfile->name); | |
9911 | continue; | |
9912 | } | |
96408a79 SA |
9913 | } |
9914 | ||
9915 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); | |
9916 | if (!attr_form_is_block (attr)) | |
9917 | { | |
9918 | complaint (&symfile_complaints, | |
9919 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " | |
9920 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 9921 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
9922 | continue; |
9923 | } | |
9924 | parameter->value = DW_BLOCK (attr)->data; | |
9925 | parameter->value_size = DW_BLOCK (attr)->size; | |
9926 | ||
9927 | /* Parameters are not pre-cleared by memset above. */ | |
9928 | parameter->data_value = NULL; | |
9929 | parameter->data_value_size = 0; | |
9930 | call_site->parameter_count++; | |
9931 | ||
9932 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); | |
9933 | if (attr) | |
9934 | { | |
9935 | if (!attr_form_is_block (attr)) | |
9936 | complaint (&symfile_complaints, | |
9937 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " | |
9938 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 9939 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
9940 | else |
9941 | { | |
9942 | parameter->data_value = DW_BLOCK (attr)->data; | |
9943 | parameter->data_value_size = DW_BLOCK (attr)->size; | |
9944 | } | |
9945 | } | |
9946 | } | |
9947 | } | |
9948 | ||
43039443 | 9949 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
9950 | Return 1 if the attributes are present and valid, otherwise, return 0. |
9951 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
9952 | |
9953 | static int | |
9954 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
9955 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
9956 | struct partial_symtab *ranges_pst) | |
43039443 JK |
9957 | { |
9958 | struct objfile *objfile = cu->objfile; | |
9959 | struct comp_unit_head *cu_header = &cu->header; | |
9960 | bfd *obfd = objfile->obfd; | |
9961 | unsigned int addr_size = cu_header->addr_size; | |
9962 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
9963 | /* Base address selection entry. */ | |
9964 | CORE_ADDR base; | |
9965 | int found_base; | |
9966 | unsigned int dummy; | |
9967 | gdb_byte *buffer; | |
9968 | CORE_ADDR marker; | |
9969 | int low_set; | |
9970 | CORE_ADDR low = 0; | |
9971 | CORE_ADDR high = 0; | |
ff013f42 | 9972 | CORE_ADDR baseaddr; |
43039443 | 9973 | |
d00adf39 DE |
9974 | found_base = cu->base_known; |
9975 | base = cu->base_address; | |
43039443 | 9976 | |
be391dca | 9977 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 9978 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
9979 | { |
9980 | complaint (&symfile_complaints, | |
9981 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
9982 | offset); | |
9983 | return 0; | |
9984 | } | |
dce234bc | 9985 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
9986 | |
9987 | /* Read in the largest possible address. */ | |
9988 | marker = read_address (obfd, buffer, cu, &dummy); | |
9989 | if ((marker & mask) == mask) | |
9990 | { | |
9991 | /* If we found the largest possible address, then | |
9992 | read the base address. */ | |
9993 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
9994 | buffer += 2 * addr_size; | |
9995 | offset += 2 * addr_size; | |
9996 | found_base = 1; | |
9997 | } | |
9998 | ||
9999 | low_set = 0; | |
10000 | ||
e7030f15 | 10001 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 10002 | |
43039443 JK |
10003 | while (1) |
10004 | { | |
10005 | CORE_ADDR range_beginning, range_end; | |
10006 | ||
10007 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
10008 | buffer += addr_size; | |
10009 | range_end = read_address (obfd, buffer, cu, &dummy); | |
10010 | buffer += addr_size; | |
10011 | offset += 2 * addr_size; | |
10012 | ||
10013 | /* An end of list marker is a pair of zero addresses. */ | |
10014 | if (range_beginning == 0 && range_end == 0) | |
10015 | /* Found the end of list entry. */ | |
10016 | break; | |
10017 | ||
10018 | /* Each base address selection entry is a pair of 2 values. | |
10019 | The first is the largest possible address, the second is | |
10020 | the base address. Check for a base address here. */ | |
10021 | if ((range_beginning & mask) == mask) | |
10022 | { | |
10023 | /* If we found the largest possible address, then | |
10024 | read the base address. */ | |
10025 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
10026 | found_base = 1; | |
10027 | continue; | |
10028 | } | |
10029 | ||
10030 | if (!found_base) | |
10031 | { | |
10032 | /* We have no valid base address for the ranges | |
10033 | data. */ | |
10034 | complaint (&symfile_complaints, | |
10035 | _("Invalid .debug_ranges data (no base address)")); | |
10036 | return 0; | |
10037 | } | |
10038 | ||
9277c30c UW |
10039 | if (range_beginning > range_end) |
10040 | { | |
10041 | /* Inverted range entries are invalid. */ | |
10042 | complaint (&symfile_complaints, | |
10043 | _("Invalid .debug_ranges data (inverted range)")); | |
10044 | return 0; | |
10045 | } | |
10046 | ||
10047 | /* Empty range entries have no effect. */ | |
10048 | if (range_beginning == range_end) | |
10049 | continue; | |
10050 | ||
43039443 JK |
10051 | range_beginning += base; |
10052 | range_end += base; | |
10053 | ||
01093045 DE |
10054 | /* A not-uncommon case of bad debug info. |
10055 | Don't pollute the addrmap with bad data. */ | |
10056 | if (range_beginning + baseaddr == 0 | |
10057 | && !dwarf2_per_objfile->has_section_at_zero) | |
10058 | { | |
10059 | complaint (&symfile_complaints, | |
10060 | _(".debug_ranges entry has start address of zero" | |
10061 | " [in module %s]"), objfile->name); | |
10062 | continue; | |
10063 | } | |
10064 | ||
9277c30c | 10065 | if (ranges_pst != NULL) |
ff013f42 | 10066 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
10067 | range_beginning + baseaddr, |
10068 | range_end - 1 + baseaddr, | |
ff013f42 JK |
10069 | ranges_pst); |
10070 | ||
43039443 JK |
10071 | /* FIXME: This is recording everything as a low-high |
10072 | segment of consecutive addresses. We should have a | |
10073 | data structure for discontiguous block ranges | |
10074 | instead. */ | |
10075 | if (! low_set) | |
10076 | { | |
10077 | low = range_beginning; | |
10078 | high = range_end; | |
10079 | low_set = 1; | |
10080 | } | |
10081 | else | |
10082 | { | |
10083 | if (range_beginning < low) | |
10084 | low = range_beginning; | |
10085 | if (range_end > high) | |
10086 | high = range_end; | |
10087 | } | |
10088 | } | |
10089 | ||
10090 | if (! low_set) | |
10091 | /* If the first entry is an end-of-list marker, the range | |
10092 | describes an empty scope, i.e. no instructions. */ | |
10093 | return 0; | |
10094 | ||
10095 | if (low_return) | |
10096 | *low_return = low; | |
10097 | if (high_return) | |
10098 | *high_return = high; | |
10099 | return 1; | |
10100 | } | |
10101 | ||
af34e669 DJ |
10102 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
10103 | are present and valid, otherwise, return 0. Return -1 if the range is | |
10104 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
380bca97 | 10105 | |
c906108c | 10106 | static int |
af34e669 | 10107 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
10108 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
10109 | struct partial_symtab *pst) | |
c906108c SS |
10110 | { |
10111 | struct attribute *attr; | |
91da1414 | 10112 | struct attribute *attr_high; |
af34e669 DJ |
10113 | CORE_ADDR low = 0; |
10114 | CORE_ADDR high = 0; | |
10115 | int ret = 0; | |
c906108c | 10116 | |
91da1414 MW |
10117 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
10118 | if (attr_high) | |
af34e669 | 10119 | { |
e142c38c | 10120 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 | 10121 | if (attr) |
91da1414 MW |
10122 | { |
10123 | low = DW_ADDR (attr); | |
3019eac3 DE |
10124 | if (attr_high->form == DW_FORM_addr |
10125 | || attr_high->form == DW_FORM_GNU_addr_index) | |
91da1414 MW |
10126 | high = DW_ADDR (attr_high); |
10127 | else | |
10128 | high = low + DW_UNSND (attr_high); | |
10129 | } | |
af34e669 DJ |
10130 | else |
10131 | /* Found high w/o low attribute. */ | |
10132 | return 0; | |
10133 | ||
10134 | /* Found consecutive range of addresses. */ | |
10135 | ret = 1; | |
10136 | } | |
c906108c | 10137 | else |
af34e669 | 10138 | { |
e142c38c | 10139 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
10140 | if (attr != NULL) |
10141 | { | |
ab435259 DE |
10142 | /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton. |
10143 | We take advantage of the fact that DW_AT_ranges does not appear | |
10144 | in DW_TAG_compile_unit of DWO files. */ | |
10145 | int need_ranges_base = die->tag != DW_TAG_compile_unit; | |
10146 | unsigned int ranges_offset = (DW_UNSND (attr) | |
10147 | + (need_ranges_base | |
10148 | ? cu->ranges_base | |
10149 | : 0)); | |
2e3cf129 | 10150 | |
af34e669 | 10151 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 10152 | .debug_ranges section. */ |
2e3cf129 | 10153 | if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst)) |
af34e669 | 10154 | return 0; |
43039443 | 10155 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
10156 | ret = -1; |
10157 | } | |
10158 | } | |
c906108c | 10159 | |
9373cf26 JK |
10160 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
10161 | if (high <= low) | |
c906108c SS |
10162 | return 0; |
10163 | ||
10164 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
10165 | eliminate duplicate copies of functions and vtables and such. | |
10166 | The linker will arbitrarily choose one and discard the others. | |
10167 | The AT_*_pc values for such functions refer to local labels in | |
10168 | these sections. If the section from that file was discarded, the | |
10169 | labels are not in the output, so the relocs get a value of 0. | |
10170 | If this is a discarded function, mark the pc bounds as invalid, | |
10171 | so that GDB will ignore it. */ | |
72dca2f5 | 10172 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
10173 | return 0; |
10174 | ||
10175 | *lowpc = low; | |
96408a79 SA |
10176 | if (highpc) |
10177 | *highpc = high; | |
af34e669 | 10178 | return ret; |
c906108c SS |
10179 | } |
10180 | ||
b084d499 JB |
10181 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
10182 | its low and high PC addresses. Do nothing if these addresses could not | |
10183 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
10184 | and HIGHPC to the high address if greater than HIGHPC. */ | |
10185 | ||
10186 | static void | |
10187 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
10188 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
10189 | struct dwarf2_cu *cu) | |
10190 | { | |
10191 | CORE_ADDR low, high; | |
10192 | struct die_info *child = die->child; | |
10193 | ||
d85a05f0 | 10194 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
10195 | { |
10196 | *lowpc = min (*lowpc, low); | |
10197 | *highpc = max (*highpc, high); | |
10198 | } | |
10199 | ||
10200 | /* If the language does not allow nested subprograms (either inside | |
10201 | subprograms or lexical blocks), we're done. */ | |
10202 | if (cu->language != language_ada) | |
10203 | return; | |
6e70227d | 10204 | |
b084d499 JB |
10205 | /* Check all the children of the given DIE. If it contains nested |
10206 | subprograms, then check their pc bounds. Likewise, we need to | |
10207 | check lexical blocks as well, as they may also contain subprogram | |
10208 | definitions. */ | |
10209 | while (child && child->tag) | |
10210 | { | |
10211 | if (child->tag == DW_TAG_subprogram | |
10212 | || child->tag == DW_TAG_lexical_block) | |
10213 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
10214 | child = sibling_die (child); | |
10215 | } | |
10216 | } | |
10217 | ||
fae299cd DC |
10218 | /* Get the low and high pc's represented by the scope DIE, and store |
10219 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
10220 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
10221 | ||
10222 | static void | |
10223 | get_scope_pc_bounds (struct die_info *die, | |
10224 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
10225 | struct dwarf2_cu *cu) | |
10226 | { | |
10227 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
10228 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
10229 | CORE_ADDR current_low, current_high; | |
10230 | ||
d85a05f0 | 10231 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
10232 | { |
10233 | best_low = current_low; | |
10234 | best_high = current_high; | |
10235 | } | |
10236 | else | |
10237 | { | |
10238 | struct die_info *child = die->child; | |
10239 | ||
10240 | while (child && child->tag) | |
10241 | { | |
10242 | switch (child->tag) { | |
10243 | case DW_TAG_subprogram: | |
b084d499 | 10244 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
10245 | break; |
10246 | case DW_TAG_namespace: | |
f55ee35c | 10247 | case DW_TAG_module: |
fae299cd DC |
10248 | /* FIXME: carlton/2004-01-16: Should we do this for |
10249 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
10250 | that current GCC's always emit the DIEs corresponding | |
10251 | to definitions of methods of classes as children of a | |
10252 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
10253 | the DIEs giving the declarations, which could be | |
10254 | anywhere). But I don't see any reason why the | |
10255 | standards says that they have to be there. */ | |
10256 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
10257 | ||
10258 | if (current_low != ((CORE_ADDR) -1)) | |
10259 | { | |
10260 | best_low = min (best_low, current_low); | |
10261 | best_high = max (best_high, current_high); | |
10262 | } | |
10263 | break; | |
10264 | default: | |
0963b4bd | 10265 | /* Ignore. */ |
fae299cd DC |
10266 | break; |
10267 | } | |
10268 | ||
10269 | child = sibling_die (child); | |
10270 | } | |
10271 | } | |
10272 | ||
10273 | *lowpc = best_low; | |
10274 | *highpc = best_high; | |
10275 | } | |
10276 | ||
801e3a5b JB |
10277 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
10278 | in DIE. */ | |
380bca97 | 10279 | |
801e3a5b JB |
10280 | static void |
10281 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
10282 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
10283 | { | |
bb5ed363 | 10284 | struct objfile *objfile = cu->objfile; |
801e3a5b | 10285 | struct attribute *attr; |
91da1414 | 10286 | struct attribute *attr_high; |
801e3a5b | 10287 | |
91da1414 MW |
10288 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
10289 | if (attr_high) | |
801e3a5b | 10290 | { |
801e3a5b JB |
10291 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
10292 | if (attr) | |
10293 | { | |
10294 | CORE_ADDR low = DW_ADDR (attr); | |
91da1414 | 10295 | CORE_ADDR high; |
3019eac3 DE |
10296 | if (attr_high->form == DW_FORM_addr |
10297 | || attr_high->form == DW_FORM_GNU_addr_index) | |
91da1414 MW |
10298 | high = DW_ADDR (attr_high); |
10299 | else | |
10300 | high = low + DW_UNSND (attr_high); | |
9a619af0 | 10301 | |
801e3a5b JB |
10302 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
10303 | } | |
10304 | } | |
10305 | ||
10306 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
10307 | if (attr) | |
10308 | { | |
bb5ed363 | 10309 | bfd *obfd = objfile->obfd; |
ab435259 DE |
10310 | /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton. |
10311 | We take advantage of the fact that DW_AT_ranges does not appear | |
10312 | in DW_TAG_compile_unit of DWO files. */ | |
10313 | int need_ranges_base = die->tag != DW_TAG_compile_unit; | |
801e3a5b JB |
10314 | |
10315 | /* The value of the DW_AT_ranges attribute is the offset of the | |
10316 | address range list in the .debug_ranges section. */ | |
ab435259 DE |
10317 | unsigned long offset = (DW_UNSND (attr) |
10318 | + (need_ranges_base ? cu->ranges_base : 0)); | |
dce234bc | 10319 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
10320 | |
10321 | /* For some target architectures, but not others, the | |
10322 | read_address function sign-extends the addresses it returns. | |
10323 | To recognize base address selection entries, we need a | |
10324 | mask. */ | |
10325 | unsigned int addr_size = cu->header.addr_size; | |
10326 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
10327 | ||
10328 | /* The base address, to which the next pair is relative. Note | |
10329 | that this 'base' is a DWARF concept: most entries in a range | |
10330 | list are relative, to reduce the number of relocs against the | |
10331 | debugging information. This is separate from this function's | |
10332 | 'baseaddr' argument, which GDB uses to relocate debugging | |
10333 | information from a shared library based on the address at | |
10334 | which the library was loaded. */ | |
d00adf39 DE |
10335 | CORE_ADDR base = cu->base_address; |
10336 | int base_known = cu->base_known; | |
801e3a5b | 10337 | |
be391dca | 10338 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 10339 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
10340 | { |
10341 | complaint (&symfile_complaints, | |
10342 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
10343 | offset); | |
10344 | return; | |
10345 | } | |
10346 | ||
10347 | for (;;) | |
10348 | { | |
10349 | unsigned int bytes_read; | |
10350 | CORE_ADDR start, end; | |
10351 | ||
10352 | start = read_address (obfd, buffer, cu, &bytes_read); | |
10353 | buffer += bytes_read; | |
10354 | end = read_address (obfd, buffer, cu, &bytes_read); | |
10355 | buffer += bytes_read; | |
10356 | ||
10357 | /* Did we find the end of the range list? */ | |
10358 | if (start == 0 && end == 0) | |
10359 | break; | |
10360 | ||
10361 | /* Did we find a base address selection entry? */ | |
10362 | else if ((start & base_select_mask) == base_select_mask) | |
10363 | { | |
10364 | base = end; | |
10365 | base_known = 1; | |
10366 | } | |
10367 | ||
10368 | /* We found an ordinary address range. */ | |
10369 | else | |
10370 | { | |
10371 | if (!base_known) | |
10372 | { | |
10373 | complaint (&symfile_complaints, | |
3e43a32a MS |
10374 | _("Invalid .debug_ranges data " |
10375 | "(no base address)")); | |
801e3a5b JB |
10376 | return; |
10377 | } | |
10378 | ||
9277c30c UW |
10379 | if (start > end) |
10380 | { | |
10381 | /* Inverted range entries are invalid. */ | |
10382 | complaint (&symfile_complaints, | |
10383 | _("Invalid .debug_ranges data " | |
10384 | "(inverted range)")); | |
10385 | return; | |
10386 | } | |
10387 | ||
10388 | /* Empty range entries have no effect. */ | |
10389 | if (start == end) | |
10390 | continue; | |
10391 | ||
01093045 DE |
10392 | start += base + baseaddr; |
10393 | end += base + baseaddr; | |
10394 | ||
10395 | /* A not-uncommon case of bad debug info. | |
10396 | Don't pollute the addrmap with bad data. */ | |
10397 | if (start == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
10398 | { | |
10399 | complaint (&symfile_complaints, | |
10400 | _(".debug_ranges entry has start address of zero" | |
10401 | " [in module %s]"), objfile->name); | |
10402 | continue; | |
10403 | } | |
10404 | ||
10405 | record_block_range (block, start, end - 1); | |
801e3a5b JB |
10406 | } |
10407 | } | |
10408 | } | |
10409 | } | |
10410 | ||
685b1105 JK |
10411 | /* Check whether the producer field indicates either of GCC < 4.6, or the |
10412 | Intel C/C++ compiler, and cache the result in CU. */ | |
60d5a603 | 10413 | |
685b1105 JK |
10414 | static void |
10415 | check_producer (struct dwarf2_cu *cu) | |
60d5a603 JK |
10416 | { |
10417 | const char *cs; | |
10418 | int major, minor, release; | |
10419 | ||
10420 | if (cu->producer == NULL) | |
10421 | { | |
10422 | /* For unknown compilers expect their behavior is DWARF version | |
10423 | compliant. | |
10424 | ||
10425 | GCC started to support .debug_types sections by -gdwarf-4 since | |
10426 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
10427 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
10428 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
10429 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
60d5a603 | 10430 | } |
685b1105 | 10431 | else if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) == 0) |
60d5a603 | 10432 | { |
685b1105 JK |
10433 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ |
10434 | ||
ba919b58 TT |
10435 | cs = &cu->producer[strlen ("GNU ")]; |
10436 | while (*cs && !isdigit (*cs)) | |
10437 | cs++; | |
10438 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) | |
10439 | { | |
10440 | /* Not recognized as GCC. */ | |
10441 | } | |
10442 | else | |
1b80a9fa JK |
10443 | { |
10444 | cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6); | |
10445 | cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3); | |
10446 | } | |
685b1105 JK |
10447 | } |
10448 | else if (strncmp (cu->producer, "Intel(R) C", strlen ("Intel(R) C")) == 0) | |
10449 | cu->producer_is_icc = 1; | |
10450 | else | |
10451 | { | |
10452 | /* For other non-GCC compilers, expect their behavior is DWARF version | |
10453 | compliant. */ | |
60d5a603 JK |
10454 | } |
10455 | ||
ba919b58 | 10456 | cu->checked_producer = 1; |
685b1105 | 10457 | } |
ba919b58 | 10458 | |
685b1105 JK |
10459 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
10460 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
10461 | during 4.6.0 experimental. */ | |
10462 | ||
10463 | static int | |
10464 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
10465 | { | |
10466 | if (!cu->checked_producer) | |
10467 | check_producer (cu); | |
10468 | ||
10469 | return cu->producer_is_gxx_lt_4_6; | |
60d5a603 JK |
10470 | } |
10471 | ||
10472 | /* Return the default accessibility type if it is not overriden by | |
10473 | DW_AT_accessibility. */ | |
10474 | ||
10475 | static enum dwarf_access_attribute | |
10476 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
10477 | { | |
10478 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
10479 | { | |
10480 | /* The default DWARF 2 accessibility for members is public, the default | |
10481 | accessibility for inheritance is private. */ | |
10482 | ||
10483 | if (die->tag != DW_TAG_inheritance) | |
10484 | return DW_ACCESS_public; | |
10485 | else | |
10486 | return DW_ACCESS_private; | |
10487 | } | |
10488 | else | |
10489 | { | |
10490 | /* DWARF 3+ defines the default accessibility a different way. The same | |
10491 | rules apply now for DW_TAG_inheritance as for the members and it only | |
10492 | depends on the container kind. */ | |
10493 | ||
10494 | if (die->parent->tag == DW_TAG_class_type) | |
10495 | return DW_ACCESS_private; | |
10496 | else | |
10497 | return DW_ACCESS_public; | |
10498 | } | |
10499 | } | |
10500 | ||
74ac6d43 TT |
10501 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
10502 | offset. If the attribute was not found return 0, otherwise return | |
10503 | 1. If it was found but could not properly be handled, set *OFFSET | |
10504 | to 0. */ | |
10505 | ||
10506 | static int | |
10507 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
10508 | LONGEST *offset) | |
10509 | { | |
10510 | struct attribute *attr; | |
10511 | ||
10512 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
10513 | if (attr != NULL) | |
10514 | { | |
10515 | *offset = 0; | |
10516 | ||
10517 | /* Note that we do not check for a section offset first here. | |
10518 | This is because DW_AT_data_member_location is new in DWARF 4, | |
10519 | so if we see it, we can assume that a constant form is really | |
10520 | a constant and not a section offset. */ | |
10521 | if (attr_form_is_constant (attr)) | |
10522 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
10523 | else if (attr_form_is_section_offset (attr)) | |
10524 | dwarf2_complex_location_expr_complaint (); | |
10525 | else if (attr_form_is_block (attr)) | |
10526 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
10527 | else | |
10528 | dwarf2_complex_location_expr_complaint (); | |
10529 | ||
10530 | return 1; | |
10531 | } | |
10532 | ||
10533 | return 0; | |
10534 | } | |
10535 | ||
c906108c SS |
10536 | /* Add an aggregate field to the field list. */ |
10537 | ||
10538 | static void | |
107d2387 | 10539 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 10540 | struct dwarf2_cu *cu) |
6e70227d | 10541 | { |
e7c27a73 | 10542 | struct objfile *objfile = cu->objfile; |
5e2b427d | 10543 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
10544 | struct nextfield *new_field; |
10545 | struct attribute *attr; | |
10546 | struct field *fp; | |
15d034d0 | 10547 | const char *fieldname = ""; |
c906108c SS |
10548 | |
10549 | /* Allocate a new field list entry and link it in. */ | |
10550 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 10551 | make_cleanup (xfree, new_field); |
c906108c | 10552 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
10553 | |
10554 | if (die->tag == DW_TAG_inheritance) | |
10555 | { | |
10556 | new_field->next = fip->baseclasses; | |
10557 | fip->baseclasses = new_field; | |
10558 | } | |
10559 | else | |
10560 | { | |
10561 | new_field->next = fip->fields; | |
10562 | fip->fields = new_field; | |
10563 | } | |
c906108c SS |
10564 | fip->nfields++; |
10565 | ||
e142c38c | 10566 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
10567 | if (attr) |
10568 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
10569 | else |
10570 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
10571 | if (new_field->accessibility != DW_ACCESS_public) |
10572 | fip->non_public_fields = 1; | |
60d5a603 | 10573 | |
e142c38c | 10574 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
10575 | if (attr) |
10576 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
10577 | else |
10578 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
10579 | |
10580 | fp = &new_field->field; | |
a9a9bd0f | 10581 | |
e142c38c | 10582 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 10583 | { |
74ac6d43 TT |
10584 | LONGEST offset; |
10585 | ||
a9a9bd0f | 10586 | /* Data member other than a C++ static data member. */ |
6e70227d | 10587 | |
c906108c | 10588 | /* Get type of field. */ |
e7c27a73 | 10589 | fp->type = die_type (die, cu); |
c906108c | 10590 | |
d6a843b5 | 10591 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 10592 | |
c906108c | 10593 | /* Get bit size of field (zero if none). */ |
e142c38c | 10594 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
10595 | if (attr) |
10596 | { | |
10597 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
10598 | } | |
10599 | else | |
10600 | { | |
10601 | FIELD_BITSIZE (*fp) = 0; | |
10602 | } | |
10603 | ||
10604 | /* Get bit offset of field. */ | |
74ac6d43 TT |
10605 | if (handle_data_member_location (die, cu, &offset)) |
10606 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 10607 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
10608 | if (attr) |
10609 | { | |
5e2b427d | 10610 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
10611 | { |
10612 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
10613 | additional bit offset from the MSB of the containing |
10614 | anonymous object to the MSB of the field. We don't | |
10615 | have to do anything special since we don't need to | |
10616 | know the size of the anonymous object. */ | |
f41f5e61 | 10617 | SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr)); |
c906108c SS |
10618 | } |
10619 | else | |
10620 | { | |
10621 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
10622 | MSB of the anonymous object, subtract off the number of |
10623 | bits from the MSB of the field to the MSB of the | |
10624 | object, and then subtract off the number of bits of | |
10625 | the field itself. The result is the bit offset of | |
10626 | the LSB of the field. */ | |
c906108c SS |
10627 | int anonymous_size; |
10628 | int bit_offset = DW_UNSND (attr); | |
10629 | ||
e142c38c | 10630 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
10631 | if (attr) |
10632 | { | |
10633 | /* The size of the anonymous object containing | |
10634 | the bit field is explicit, so use the | |
10635 | indicated size (in bytes). */ | |
10636 | anonymous_size = DW_UNSND (attr); | |
10637 | } | |
10638 | else | |
10639 | { | |
10640 | /* The size of the anonymous object containing | |
10641 | the bit field must be inferred from the type | |
10642 | attribute of the data member containing the | |
10643 | bit field. */ | |
10644 | anonymous_size = TYPE_LENGTH (fp->type); | |
10645 | } | |
f41f5e61 PA |
10646 | SET_FIELD_BITPOS (*fp, |
10647 | (FIELD_BITPOS (*fp) | |
10648 | + anonymous_size * bits_per_byte | |
10649 | - bit_offset - FIELD_BITSIZE (*fp))); | |
c906108c SS |
10650 | } |
10651 | } | |
10652 | ||
10653 | /* Get name of field. */ | |
39cbfefa DJ |
10654 | fieldname = dwarf2_name (die, cu); |
10655 | if (fieldname == NULL) | |
10656 | fieldname = ""; | |
d8151005 DJ |
10657 | |
10658 | /* The name is already allocated along with this objfile, so we don't | |
10659 | need to duplicate it for the type. */ | |
10660 | fp->name = fieldname; | |
c906108c SS |
10661 | |
10662 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 10663 | pointer or virtual base class pointer) to private. */ |
e142c38c | 10664 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 10665 | { |
d48cc9dd | 10666 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
10667 | new_field->accessibility = DW_ACCESS_private; |
10668 | fip->non_public_fields = 1; | |
10669 | } | |
10670 | } | |
a9a9bd0f | 10671 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 10672 | { |
a9a9bd0f DC |
10673 | /* C++ static member. */ |
10674 | ||
10675 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
10676 | is a declaration, but all versions of G++ as of this writing | |
10677 | (so through at least 3.2.1) incorrectly generate | |
10678 | DW_TAG_variable tags. */ | |
6e70227d | 10679 | |
ff355380 | 10680 | const char *physname; |
c906108c | 10681 | |
a9a9bd0f | 10682 | /* Get name of field. */ |
39cbfefa DJ |
10683 | fieldname = dwarf2_name (die, cu); |
10684 | if (fieldname == NULL) | |
c906108c SS |
10685 | return; |
10686 | ||
254e6b9e | 10687 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
10688 | if (attr |
10689 | /* Only create a symbol if this is an external value. | |
10690 | new_symbol checks this and puts the value in the global symbol | |
10691 | table, which we want. If it is not external, new_symbol | |
10692 | will try to put the value in cu->list_in_scope which is wrong. */ | |
10693 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
10694 | { |
10695 | /* A static const member, not much different than an enum as far as | |
10696 | we're concerned, except that we can support more types. */ | |
10697 | new_symbol (die, NULL, cu); | |
10698 | } | |
10699 | ||
2df3850c | 10700 | /* Get physical name. */ |
ff355380 | 10701 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 10702 | |
d8151005 DJ |
10703 | /* The name is already allocated along with this objfile, so we don't |
10704 | need to duplicate it for the type. */ | |
10705 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 10706 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 10707 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
10708 | } |
10709 | else if (die->tag == DW_TAG_inheritance) | |
10710 | { | |
74ac6d43 | 10711 | LONGEST offset; |
d4b96c9a | 10712 | |
74ac6d43 TT |
10713 | /* C++ base class field. */ |
10714 | if (handle_data_member_location (die, cu, &offset)) | |
10715 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 10716 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 10717 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
10718 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
10719 | fip->nbaseclasses++; | |
10720 | } | |
10721 | } | |
10722 | ||
98751a41 JK |
10723 | /* Add a typedef defined in the scope of the FIP's class. */ |
10724 | ||
10725 | static void | |
10726 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
10727 | struct dwarf2_cu *cu) | |
6e70227d | 10728 | { |
98751a41 | 10729 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
10730 | struct typedef_field_list *new_field; |
10731 | struct attribute *attr; | |
10732 | struct typedef_field *fp; | |
10733 | char *fieldname = ""; | |
10734 | ||
10735 | /* Allocate a new field list entry and link it in. */ | |
10736 | new_field = xzalloc (sizeof (*new_field)); | |
10737 | make_cleanup (xfree, new_field); | |
10738 | ||
10739 | gdb_assert (die->tag == DW_TAG_typedef); | |
10740 | ||
10741 | fp = &new_field->field; | |
10742 | ||
10743 | /* Get name of field. */ | |
10744 | fp->name = dwarf2_name (die, cu); | |
10745 | if (fp->name == NULL) | |
10746 | return; | |
10747 | ||
10748 | fp->type = read_type_die (die, cu); | |
10749 | ||
10750 | new_field->next = fip->typedef_field_list; | |
10751 | fip->typedef_field_list = new_field; | |
10752 | fip->typedef_field_list_count++; | |
10753 | } | |
10754 | ||
c906108c SS |
10755 | /* Create the vector of fields, and attach it to the type. */ |
10756 | ||
10757 | static void | |
fba45db2 | 10758 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 10759 | struct dwarf2_cu *cu) |
c906108c SS |
10760 | { |
10761 | int nfields = fip->nfields; | |
10762 | ||
10763 | /* Record the field count, allocate space for the array of fields, | |
10764 | and create blank accessibility bitfields if necessary. */ | |
10765 | TYPE_NFIELDS (type) = nfields; | |
10766 | TYPE_FIELDS (type) = (struct field *) | |
10767 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
10768 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
10769 | ||
b4ba55a1 | 10770 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
10771 | { |
10772 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
10773 | ||
10774 | TYPE_FIELD_PRIVATE_BITS (type) = | |
10775 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
10776 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
10777 | ||
10778 | TYPE_FIELD_PROTECTED_BITS (type) = | |
10779 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
10780 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
10781 | ||
774b6a14 TT |
10782 | TYPE_FIELD_IGNORE_BITS (type) = |
10783 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
10784 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
10785 | } |
10786 | ||
10787 | /* If the type has baseclasses, allocate and clear a bit vector for | |
10788 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 10789 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
10790 | { |
10791 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 10792 | unsigned char *pointer; |
c906108c SS |
10793 | |
10794 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
10795 | pointer = TYPE_ALLOC (type, num_bytes); |
10796 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
10797 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
10798 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
10799 | } | |
10800 | ||
3e43a32a MS |
10801 | /* Copy the saved-up fields into the field vector. Start from the head of |
10802 | the list, adding to the tail of the field array, so that they end up in | |
10803 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
10804 | while (nfields-- > 0) |
10805 | { | |
7d0ccb61 DJ |
10806 | struct nextfield *fieldp; |
10807 | ||
10808 | if (fip->fields) | |
10809 | { | |
10810 | fieldp = fip->fields; | |
10811 | fip->fields = fieldp->next; | |
10812 | } | |
10813 | else | |
10814 | { | |
10815 | fieldp = fip->baseclasses; | |
10816 | fip->baseclasses = fieldp->next; | |
10817 | } | |
10818 | ||
10819 | TYPE_FIELD (type, nfields) = fieldp->field; | |
10820 | switch (fieldp->accessibility) | |
c906108c | 10821 | { |
c5aa993b | 10822 | case DW_ACCESS_private: |
b4ba55a1 JB |
10823 | if (cu->language != language_ada) |
10824 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 10825 | break; |
c906108c | 10826 | |
c5aa993b | 10827 | case DW_ACCESS_protected: |
b4ba55a1 JB |
10828 | if (cu->language != language_ada) |
10829 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 10830 | break; |
c906108c | 10831 | |
c5aa993b JM |
10832 | case DW_ACCESS_public: |
10833 | break; | |
c906108c | 10834 | |
c5aa993b JM |
10835 | default: |
10836 | /* Unknown accessibility. Complain and treat it as public. */ | |
10837 | { | |
e2e0b3e5 | 10838 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 10839 | fieldp->accessibility); |
c5aa993b JM |
10840 | } |
10841 | break; | |
c906108c SS |
10842 | } |
10843 | if (nfields < fip->nbaseclasses) | |
10844 | { | |
7d0ccb61 | 10845 | switch (fieldp->virtuality) |
c906108c | 10846 | { |
c5aa993b JM |
10847 | case DW_VIRTUALITY_virtual: |
10848 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 10849 | if (cu->language == language_ada) |
a73c6dcd | 10850 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
10851 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
10852 | break; | |
c906108c SS |
10853 | } |
10854 | } | |
c906108c SS |
10855 | } |
10856 | } | |
10857 | ||
7d27a96d TT |
10858 | /* Return true if this member function is a constructor, false |
10859 | otherwise. */ | |
10860 | ||
10861 | static int | |
10862 | dwarf2_is_constructor (struct die_info *die, struct dwarf2_cu *cu) | |
10863 | { | |
10864 | const char *fieldname; | |
10865 | const char *typename; | |
10866 | int len; | |
10867 | ||
10868 | if (die->parent == NULL) | |
10869 | return 0; | |
10870 | ||
10871 | if (die->parent->tag != DW_TAG_structure_type | |
10872 | && die->parent->tag != DW_TAG_union_type | |
10873 | && die->parent->tag != DW_TAG_class_type) | |
10874 | return 0; | |
10875 | ||
10876 | fieldname = dwarf2_name (die, cu); | |
10877 | typename = dwarf2_name (die->parent, cu); | |
10878 | if (fieldname == NULL || typename == NULL) | |
10879 | return 0; | |
10880 | ||
10881 | len = strlen (fieldname); | |
10882 | return (strncmp (fieldname, typename, len) == 0 | |
10883 | && (typename[len] == '\0' || typename[len] == '<')); | |
10884 | } | |
10885 | ||
c906108c SS |
10886 | /* Add a member function to the proper fieldlist. */ |
10887 | ||
10888 | static void | |
107d2387 | 10889 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 10890 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 10891 | { |
e7c27a73 | 10892 | struct objfile *objfile = cu->objfile; |
c906108c SS |
10893 | struct attribute *attr; |
10894 | struct fnfieldlist *flp; | |
10895 | int i; | |
10896 | struct fn_field *fnp; | |
15d034d0 | 10897 | const char *fieldname; |
c906108c | 10898 | struct nextfnfield *new_fnfield; |
f792889a | 10899 | struct type *this_type; |
60d5a603 | 10900 | enum dwarf_access_attribute accessibility; |
c906108c | 10901 | |
b4ba55a1 | 10902 | if (cu->language == language_ada) |
a73c6dcd | 10903 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 10904 | |
2df3850c | 10905 | /* Get name of member function. */ |
39cbfefa DJ |
10906 | fieldname = dwarf2_name (die, cu); |
10907 | if (fieldname == NULL) | |
2df3850c | 10908 | return; |
c906108c | 10909 | |
c906108c SS |
10910 | /* Look up member function name in fieldlist. */ |
10911 | for (i = 0; i < fip->nfnfields; i++) | |
10912 | { | |
27bfe10e | 10913 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
10914 | break; |
10915 | } | |
10916 | ||
10917 | /* Create new list element if necessary. */ | |
10918 | if (i < fip->nfnfields) | |
10919 | flp = &fip->fnfieldlists[i]; | |
10920 | else | |
10921 | { | |
10922 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
10923 | { | |
10924 | fip->fnfieldlists = (struct fnfieldlist *) | |
10925 | xrealloc (fip->fnfieldlists, | |
10926 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 10927 | * sizeof (struct fnfieldlist)); |
c906108c | 10928 | if (fip->nfnfields == 0) |
c13c43fd | 10929 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
10930 | } |
10931 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
10932 | flp->name = fieldname; | |
10933 | flp->length = 0; | |
10934 | flp->head = NULL; | |
3da10d80 | 10935 | i = fip->nfnfields++; |
c906108c SS |
10936 | } |
10937 | ||
10938 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 10939 | entry. */ |
c906108c | 10940 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 10941 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
10942 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
10943 | new_fnfield->next = flp->head; | |
10944 | flp->head = new_fnfield; | |
10945 | flp->length++; | |
10946 | ||
10947 | /* Fill in the member function field info. */ | |
10948 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
10949 | |
10950 | /* Delay processing of the physname until later. */ | |
10951 | if (cu->language == language_cplus || cu->language == language_java) | |
10952 | { | |
10953 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
10954 | die, cu); | |
10955 | } | |
10956 | else | |
10957 | { | |
1d06ead6 | 10958 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
10959 | fnp->physname = physname ? physname : ""; |
10960 | } | |
10961 | ||
c906108c | 10962 | fnp->type = alloc_type (objfile); |
f792889a DJ |
10963 | this_type = read_type_die (die, cu); |
10964 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 10965 | { |
f792889a | 10966 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 10967 | |
f792889a | 10968 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
10969 | of the method itself (TYPE_CODE_METHOD). */ |
10970 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
10971 | TYPE_TARGET_TYPE (this_type), |
10972 | TYPE_FIELDS (this_type), | |
10973 | TYPE_NFIELDS (this_type), | |
10974 | TYPE_VARARGS (this_type)); | |
c906108c SS |
10975 | |
10976 | /* Handle static member functions. | |
c5aa993b | 10977 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
10978 | member functions. G++ helps GDB by marking the first |
10979 | parameter for non-static member functions (which is the this | |
10980 | pointer) as artificial. We obtain this information from | |
10981 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 10982 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
10983 | fnp->voffset = VOFFSET_STATIC; |
10984 | } | |
10985 | else | |
e2e0b3e5 | 10986 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 10987 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
10988 | |
10989 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 10990 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 10991 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 10992 | |
3e43a32a MS |
10993 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
10994 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
10995 | |
10996 | /* Get accessibility. */ | |
e142c38c | 10997 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 10998 | if (attr) |
60d5a603 JK |
10999 | accessibility = DW_UNSND (attr); |
11000 | else | |
11001 | accessibility = dwarf2_default_access_attribute (die, cu); | |
11002 | switch (accessibility) | |
c906108c | 11003 | { |
60d5a603 JK |
11004 | case DW_ACCESS_private: |
11005 | fnp->is_private = 1; | |
11006 | break; | |
11007 | case DW_ACCESS_protected: | |
11008 | fnp->is_protected = 1; | |
11009 | break; | |
c906108c SS |
11010 | } |
11011 | ||
b02dede2 | 11012 | /* Check for artificial methods. */ |
e142c38c | 11013 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
11014 | if (attr && DW_UNSND (attr) != 0) |
11015 | fnp->is_artificial = 1; | |
11016 | ||
7d27a96d TT |
11017 | fnp->is_constructor = dwarf2_is_constructor (die, cu); |
11018 | ||
0d564a31 | 11019 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
11020 | function. For older versions of GCC, this is an offset in the |
11021 | appropriate virtual table, as specified by DW_AT_containing_type. | |
11022 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
11023 | to the object address. */ |
11024 | ||
e142c38c | 11025 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 11026 | if (attr) |
8e19ed76 | 11027 | { |
aec5aa8b | 11028 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 11029 | { |
aec5aa8b TT |
11030 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
11031 | { | |
11032 | /* Old-style GCC. */ | |
11033 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
11034 | } | |
11035 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
11036 | || (DW_BLOCK (attr)->size > 1 | |
11037 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
11038 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
11039 | { | |
11040 | struct dwarf_block blk; | |
11041 | int offset; | |
11042 | ||
11043 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
11044 | ? 1 : 2); | |
11045 | blk.size = DW_BLOCK (attr)->size - offset; | |
11046 | blk.data = DW_BLOCK (attr)->data + offset; | |
11047 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
11048 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
11049 | dwarf2_complex_location_expr_complaint (); | |
11050 | else | |
11051 | fnp->voffset /= cu->header.addr_size; | |
11052 | fnp->voffset += 2; | |
11053 | } | |
11054 | else | |
11055 | dwarf2_complex_location_expr_complaint (); | |
11056 | ||
11057 | if (!fnp->fcontext) | |
11058 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
11059 | } | |
3690dd37 | 11060 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 11061 | { |
4d3c2250 | 11062 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
11063 | } |
11064 | else | |
11065 | { | |
4d3c2250 KB |
11066 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
11067 | fieldname); | |
8e19ed76 | 11068 | } |
0d564a31 | 11069 | } |
d48cc9dd DJ |
11070 | else |
11071 | { | |
11072 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
11073 | if (attr && DW_UNSND (attr)) | |
11074 | { | |
11075 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
11076 | complaint (&symfile_complaints, | |
3e43a32a MS |
11077 | _("Member function \"%s\" (offset %d) is virtual " |
11078 | "but the vtable offset is not specified"), | |
b64f50a1 | 11079 | fieldname, die->offset.sect_off); |
9655fd1a | 11080 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
11081 | TYPE_CPLUS_DYNAMIC (type) = 1; |
11082 | } | |
11083 | } | |
c906108c SS |
11084 | } |
11085 | ||
11086 | /* Create the vector of member function fields, and attach it to the type. */ | |
11087 | ||
11088 | static void | |
fba45db2 | 11089 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 11090 | struct dwarf2_cu *cu) |
c906108c SS |
11091 | { |
11092 | struct fnfieldlist *flp; | |
c906108c SS |
11093 | int i; |
11094 | ||
b4ba55a1 | 11095 | if (cu->language == language_ada) |
a73c6dcd | 11096 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 11097 | |
c906108c SS |
11098 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
11099 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
11100 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
11101 | ||
11102 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
11103 | { | |
11104 | struct nextfnfield *nfp = flp->head; | |
11105 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
11106 | int k; | |
11107 | ||
11108 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
11109 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
11110 | fn_flp->fn_fields = (struct fn_field *) | |
11111 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
11112 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 11113 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
11114 | } |
11115 | ||
11116 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
c906108c SS |
11117 | } |
11118 | ||
1168df01 JB |
11119 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
11120 | language, zero otherwise. */ | |
11121 | static int | |
11122 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
11123 | { | |
11124 | static const char vptr[] = "_vptr"; | |
987504bb | 11125 | static const char vtable[] = "vtable"; |
1168df01 | 11126 | |
987504bb JJ |
11127 | /* Look for the C++ and Java forms of the vtable. */ |
11128 | if ((cu->language == language_java | |
11129 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
11130 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
11131 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
11132 | return 1; |
11133 | ||
11134 | return 0; | |
11135 | } | |
11136 | ||
c0dd20ea | 11137 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
11138 | functions, with the ABI-specified layout. If TYPE describes |
11139 | such a structure, smash it into a member function type. | |
61049d3b DJ |
11140 | |
11141 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
11142 | This is GCC PR debug/28767. */ | |
c0dd20ea | 11143 | |
0b92b5bb TT |
11144 | static void |
11145 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 11146 | { |
0b92b5bb | 11147 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
11148 | |
11149 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
11150 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
11151 | return; | |
c0dd20ea DJ |
11152 | |
11153 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
11154 | if (TYPE_FIELD_NAME (type, 0) == NULL |
11155 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
11156 | || TYPE_FIELD_NAME (type, 1) == NULL | |
11157 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
11158 | return; | |
c0dd20ea DJ |
11159 | |
11160 | /* Find the type of the method. */ | |
0b92b5bb | 11161 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
11162 | if (pfn_type == NULL |
11163 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
11164 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 11165 | return; |
c0dd20ea DJ |
11166 | |
11167 | /* Look for the "this" argument. */ | |
11168 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
11169 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 11170 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 11171 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 11172 | return; |
c0dd20ea DJ |
11173 | |
11174 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
11175 | new_type = alloc_type (objfile); |
11176 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
11177 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
11178 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 11179 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 11180 | } |
1168df01 | 11181 | |
685b1105 JK |
11182 | /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler |
11183 | (icc). */ | |
11184 | ||
11185 | static int | |
11186 | producer_is_icc (struct dwarf2_cu *cu) | |
11187 | { | |
11188 | if (!cu->checked_producer) | |
11189 | check_producer (cu); | |
11190 | ||
11191 | return cu->producer_is_icc; | |
11192 | } | |
11193 | ||
c906108c | 11194 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
11195 | (definition) to create a type for the structure or union. Fill in |
11196 | the type's name and general properties; the members will not be | |
11197 | processed until process_structure_type. | |
c906108c | 11198 | |
c767944b DJ |
11199 | NOTE: we need to call these functions regardless of whether or not the |
11200 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
11201 | structure or union. This gets the type entered into our set of |
11202 | user defined types. | |
11203 | ||
11204 | However, if the structure is incomplete (an opaque struct/union) | |
11205 | then suppress creating a symbol table entry for it since gdb only | |
11206 | wants to find the one with the complete definition. Note that if | |
11207 | it is complete, we just call new_symbol, which does it's own | |
11208 | checking about whether the struct/union is anonymous or not (and | |
11209 | suppresses creating a symbol table entry itself). */ | |
11210 | ||
f792889a | 11211 | static struct type * |
134d01f1 | 11212 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11213 | { |
e7c27a73 | 11214 | struct objfile *objfile = cu->objfile; |
c906108c SS |
11215 | struct type *type; |
11216 | struct attribute *attr; | |
15d034d0 | 11217 | const char *name; |
c906108c | 11218 | |
348e048f DE |
11219 | /* If the definition of this type lives in .debug_types, read that type. |
11220 | Don't follow DW_AT_specification though, that will take us back up | |
11221 | the chain and we want to go down. */ | |
45e58e77 | 11222 | attr = dwarf2_attr_no_follow (die, DW_AT_signature); |
348e048f DE |
11223 | if (attr) |
11224 | { | |
11225 | struct dwarf2_cu *type_cu = cu; | |
11226 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 11227 | |
348e048f DE |
11228 | /* We could just recurse on read_structure_type, but we need to call |
11229 | get_die_type to ensure only one type for this DIE is created. | |
11230 | This is important, for example, because for c++ classes we need | |
11231 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
11232 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
11233 | |
11234 | /* TYPE_CU may not be the same as CU. | |
11235 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
11236 | return set_die_type (die, type, cu); |
11237 | } | |
11238 | ||
c0dd20ea | 11239 | type = alloc_type (objfile); |
c906108c | 11240 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 11241 | |
39cbfefa DJ |
11242 | name = dwarf2_name (die, cu); |
11243 | if (name != NULL) | |
c906108c | 11244 | { |
987504bb JJ |
11245 | if (cu->language == language_cplus |
11246 | || cu->language == language_java) | |
63d06c5c | 11247 | { |
15d034d0 | 11248 | const char *full_name = dwarf2_full_name (name, die, cu); |
3da10d80 KS |
11249 | |
11250 | /* dwarf2_full_name might have already finished building the DIE's | |
11251 | type. If so, there is no need to continue. */ | |
11252 | if (get_die_type (die, cu) != NULL) | |
11253 | return get_die_type (die, cu); | |
11254 | ||
11255 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
11256 | if (die->tag == DW_TAG_structure_type |
11257 | || die->tag == DW_TAG_class_type) | |
11258 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
11259 | } |
11260 | else | |
11261 | { | |
d8151005 DJ |
11262 | /* The name is already allocated along with this objfile, so |
11263 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
11264 | TYPE_TAG_NAME (type) = (char *) name; |
11265 | if (die->tag == DW_TAG_class_type) | |
11266 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 11267 | } |
c906108c SS |
11268 | } |
11269 | ||
11270 | if (die->tag == DW_TAG_structure_type) | |
11271 | { | |
11272 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
11273 | } | |
11274 | else if (die->tag == DW_TAG_union_type) | |
11275 | { | |
11276 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
11277 | } | |
11278 | else | |
11279 | { | |
c906108c SS |
11280 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
11281 | } | |
11282 | ||
0cc2414c TT |
11283 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
11284 | TYPE_DECLARED_CLASS (type) = 1; | |
11285 | ||
e142c38c | 11286 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
11287 | if (attr) |
11288 | { | |
11289 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
11290 | } | |
11291 | else | |
11292 | { | |
11293 | TYPE_LENGTH (type) = 0; | |
11294 | } | |
11295 | ||
685b1105 JK |
11296 | if (producer_is_icc (cu)) |
11297 | { | |
11298 | /* ICC does not output the required DW_AT_declaration | |
11299 | on incomplete types, but gives them a size of zero. */ | |
11300 | } | |
11301 | else | |
11302 | TYPE_STUB_SUPPORTED (type) = 1; | |
11303 | ||
dc718098 | 11304 | if (die_is_declaration (die, cu)) |
876cecd0 | 11305 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
11306 | else if (attr == NULL && die->child == NULL |
11307 | && producer_is_realview (cu->producer)) | |
11308 | /* RealView does not output the required DW_AT_declaration | |
11309 | on incomplete types. */ | |
11310 | TYPE_STUB (type) = 1; | |
dc718098 | 11311 | |
c906108c SS |
11312 | /* We need to add the type field to the die immediately so we don't |
11313 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 11314 | type within the structure itself. */ |
1c379e20 | 11315 | set_die_type (die, type, cu); |
c906108c | 11316 | |
7e314c57 JK |
11317 | /* set_die_type should be already done. */ |
11318 | set_descriptive_type (type, die, cu); | |
11319 | ||
c767944b DJ |
11320 | return type; |
11321 | } | |
11322 | ||
11323 | /* Finish creating a structure or union type, including filling in | |
11324 | its members and creating a symbol for it. */ | |
11325 | ||
11326 | static void | |
11327 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
11328 | { | |
11329 | struct objfile *objfile = cu->objfile; | |
11330 | struct die_info *child_die = die->child; | |
11331 | struct type *type; | |
11332 | ||
11333 | type = get_die_type (die, cu); | |
11334 | if (type == NULL) | |
11335 | type = read_structure_type (die, cu); | |
11336 | ||
e142c38c | 11337 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
11338 | { |
11339 | struct field_info fi; | |
11340 | struct die_info *child_die; | |
34eaf542 | 11341 | VEC (symbolp) *template_args = NULL; |
c767944b | 11342 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
11343 | |
11344 | memset (&fi, 0, sizeof (struct field_info)); | |
11345 | ||
639d11d3 | 11346 | child_die = die->child; |
c906108c SS |
11347 | |
11348 | while (child_die && child_die->tag) | |
11349 | { | |
a9a9bd0f DC |
11350 | if (child_die->tag == DW_TAG_member |
11351 | || child_die->tag == DW_TAG_variable) | |
c906108c | 11352 | { |
a9a9bd0f DC |
11353 | /* NOTE: carlton/2002-11-05: A C++ static data member |
11354 | should be a DW_TAG_member that is a declaration, but | |
11355 | all versions of G++ as of this writing (so through at | |
11356 | least 3.2.1) incorrectly generate DW_TAG_variable | |
11357 | tags for them instead. */ | |
e7c27a73 | 11358 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 11359 | } |
8713b1b1 | 11360 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 11361 | { |
0963b4bd | 11362 | /* C++ member function. */ |
e7c27a73 | 11363 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
11364 | } |
11365 | else if (child_die->tag == DW_TAG_inheritance) | |
11366 | { | |
11367 | /* C++ base class field. */ | |
e7c27a73 | 11368 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 11369 | } |
98751a41 JK |
11370 | else if (child_die->tag == DW_TAG_typedef) |
11371 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
11372 | else if (child_die->tag == DW_TAG_template_type_param |
11373 | || child_die->tag == DW_TAG_template_value_param) | |
11374 | { | |
11375 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
11376 | ||
f1078f66 DJ |
11377 | if (arg != NULL) |
11378 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
11379 | } |
11380 | ||
c906108c SS |
11381 | child_die = sibling_die (child_die); |
11382 | } | |
11383 | ||
34eaf542 TT |
11384 | /* Attach template arguments to type. */ |
11385 | if (! VEC_empty (symbolp, template_args)) | |
11386 | { | |
11387 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
11388 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
11389 | = VEC_length (symbolp, template_args); | |
11390 | TYPE_TEMPLATE_ARGUMENTS (type) | |
11391 | = obstack_alloc (&objfile->objfile_obstack, | |
11392 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
11393 | * sizeof (struct symbol *))); | |
11394 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
11395 | VEC_address (symbolp, template_args), | |
11396 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
11397 | * sizeof (struct symbol *))); | |
11398 | VEC_free (symbolp, template_args); | |
11399 | } | |
11400 | ||
c906108c SS |
11401 | /* Attach fields and member functions to the type. */ |
11402 | if (fi.nfields) | |
e7c27a73 | 11403 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
11404 | if (fi.nfnfields) |
11405 | { | |
e7c27a73 | 11406 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 11407 | |
c5aa993b | 11408 | /* Get the type which refers to the base class (possibly this |
c906108c | 11409 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
11410 | class from the DW_AT_containing_type attribute. This use of |
11411 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 11412 | |
e142c38c | 11413 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 11414 | { |
e7c27a73 | 11415 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
11416 | |
11417 | TYPE_VPTR_BASETYPE (type) = t; | |
11418 | if (type == t) | |
11419 | { | |
c906108c SS |
11420 | int i; |
11421 | ||
11422 | /* Our own class provides vtbl ptr. */ | |
11423 | for (i = TYPE_NFIELDS (t) - 1; | |
11424 | i >= TYPE_N_BASECLASSES (t); | |
11425 | --i) | |
11426 | { | |
0d5cff50 | 11427 | const char *fieldname = TYPE_FIELD_NAME (t, i); |
c906108c | 11428 | |
1168df01 | 11429 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
11430 | { |
11431 | TYPE_VPTR_FIELDNO (type) = i; | |
11432 | break; | |
11433 | } | |
11434 | } | |
11435 | ||
11436 | /* Complain if virtual function table field not found. */ | |
11437 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 11438 | complaint (&symfile_complaints, |
3e43a32a MS |
11439 | _("virtual function table pointer " |
11440 | "not found when defining class '%s'"), | |
4d3c2250 KB |
11441 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
11442 | ""); | |
c906108c SS |
11443 | } |
11444 | else | |
11445 | { | |
11446 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
11447 | } | |
11448 | } | |
f6235d4c EZ |
11449 | else if (cu->producer |
11450 | && strncmp (cu->producer, | |
11451 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
11452 | { | |
11453 | /* The IBM XLC compiler does not provide direct indication | |
11454 | of the containing type, but the vtable pointer is | |
11455 | always named __vfp. */ | |
11456 | ||
11457 | int i; | |
11458 | ||
11459 | for (i = TYPE_NFIELDS (type) - 1; | |
11460 | i >= TYPE_N_BASECLASSES (type); | |
11461 | --i) | |
11462 | { | |
11463 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
11464 | { | |
11465 | TYPE_VPTR_FIELDNO (type) = i; | |
11466 | TYPE_VPTR_BASETYPE (type) = type; | |
11467 | break; | |
11468 | } | |
11469 | } | |
11470 | } | |
c906108c | 11471 | } |
98751a41 JK |
11472 | |
11473 | /* Copy fi.typedef_field_list linked list elements content into the | |
11474 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
11475 | if (fi.typedef_field_list) | |
11476 | { | |
11477 | int i = fi.typedef_field_list_count; | |
11478 | ||
a0d7a4ff | 11479 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
11480 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
11481 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
11482 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
11483 | ||
11484 | /* Reverse the list order to keep the debug info elements order. */ | |
11485 | while (--i >= 0) | |
11486 | { | |
11487 | struct typedef_field *dest, *src; | |
6e70227d | 11488 | |
98751a41 JK |
11489 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
11490 | src = &fi.typedef_field_list->field; | |
11491 | fi.typedef_field_list = fi.typedef_field_list->next; | |
11492 | *dest = *src; | |
11493 | } | |
11494 | } | |
c767944b DJ |
11495 | |
11496 | do_cleanups (back_to); | |
eb2a6f42 TT |
11497 | |
11498 | if (HAVE_CPLUS_STRUCT (type)) | |
11499 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; | |
c906108c | 11500 | } |
63d06c5c | 11501 | |
bb5ed363 | 11502 | quirk_gcc_member_function_pointer (type, objfile); |
0b92b5bb | 11503 | |
90aeadfc DC |
11504 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
11505 | snapshots) has been known to create a die giving a declaration | |
11506 | for a class that has, as a child, a die giving a definition for a | |
11507 | nested class. So we have to process our children even if the | |
11508 | current die is a declaration. Normally, of course, a declaration | |
11509 | won't have any children at all. */ | |
134d01f1 | 11510 | |
90aeadfc DC |
11511 | while (child_die != NULL && child_die->tag) |
11512 | { | |
11513 | if (child_die->tag == DW_TAG_member | |
11514 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
11515 | || child_die->tag == DW_TAG_inheritance |
11516 | || child_die->tag == DW_TAG_template_value_param | |
11517 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 11518 | { |
90aeadfc | 11519 | /* Do nothing. */ |
134d01f1 | 11520 | } |
90aeadfc DC |
11521 | else |
11522 | process_die (child_die, cu); | |
134d01f1 | 11523 | |
90aeadfc | 11524 | child_die = sibling_die (child_die); |
134d01f1 DJ |
11525 | } |
11526 | ||
fa4028e9 JB |
11527 | /* Do not consider external references. According to the DWARF standard, |
11528 | these DIEs are identified by the fact that they have no byte_size | |
11529 | attribute, and a declaration attribute. */ | |
11530 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
11531 | || !die_is_declaration (die, cu)) | |
c767944b | 11532 | new_symbol (die, type, cu); |
134d01f1 DJ |
11533 | } |
11534 | ||
11535 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
11536 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 11537 | |
f792889a | 11538 | static struct type * |
134d01f1 | 11539 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11540 | { |
e7c27a73 | 11541 | struct objfile *objfile = cu->objfile; |
c906108c | 11542 | struct type *type; |
c906108c | 11543 | struct attribute *attr; |
0114d602 | 11544 | const char *name; |
134d01f1 | 11545 | |
348e048f DE |
11546 | /* If the definition of this type lives in .debug_types, read that type. |
11547 | Don't follow DW_AT_specification though, that will take us back up | |
11548 | the chain and we want to go down. */ | |
45e58e77 | 11549 | attr = dwarf2_attr_no_follow (die, DW_AT_signature); |
348e048f DE |
11550 | if (attr) |
11551 | { | |
11552 | struct dwarf2_cu *type_cu = cu; | |
11553 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 11554 | |
348e048f | 11555 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
11556 | |
11557 | /* TYPE_CU may not be the same as CU. | |
11558 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
11559 | return set_die_type (die, type, cu); |
11560 | } | |
11561 | ||
c906108c SS |
11562 | type = alloc_type (objfile); |
11563 | ||
11564 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 11565 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 11566 | if (name != NULL) |
0114d602 | 11567 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 11568 | |
e142c38c | 11569 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
11570 | if (attr) |
11571 | { | |
11572 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
11573 | } | |
11574 | else | |
11575 | { | |
11576 | TYPE_LENGTH (type) = 0; | |
11577 | } | |
11578 | ||
137033e9 JB |
11579 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
11580 | declared as private in the package spec, and then defined only | |
11581 | inside the package body. Such types are known as Taft Amendment | |
11582 | Types. When another package uses such a type, an incomplete DIE | |
11583 | may be generated by the compiler. */ | |
02eb380e | 11584 | if (die_is_declaration (die, cu)) |
876cecd0 | 11585 | TYPE_STUB (type) = 1; |
02eb380e | 11586 | |
f792889a | 11587 | return set_die_type (die, type, cu); |
134d01f1 DJ |
11588 | } |
11589 | ||
11590 | /* Given a pointer to a die which begins an enumeration, process all | |
11591 | the dies that define the members of the enumeration, and create the | |
11592 | symbol for the enumeration type. | |
11593 | ||
11594 | NOTE: We reverse the order of the element list. */ | |
11595 | ||
11596 | static void | |
11597 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
11598 | { | |
f792889a | 11599 | struct type *this_type; |
134d01f1 | 11600 | |
f792889a DJ |
11601 | this_type = get_die_type (die, cu); |
11602 | if (this_type == NULL) | |
11603 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 11604 | |
639d11d3 | 11605 | if (die->child != NULL) |
c906108c | 11606 | { |
9dc481d3 DE |
11607 | struct die_info *child_die; |
11608 | struct symbol *sym; | |
11609 | struct field *fields = NULL; | |
11610 | int num_fields = 0; | |
11611 | int unsigned_enum = 1; | |
15d034d0 | 11612 | const char *name; |
cafec441 TT |
11613 | int flag_enum = 1; |
11614 | ULONGEST mask = 0; | |
9dc481d3 | 11615 | |
639d11d3 | 11616 | child_die = die->child; |
c906108c SS |
11617 | while (child_die && child_die->tag) |
11618 | { | |
11619 | if (child_die->tag != DW_TAG_enumerator) | |
11620 | { | |
e7c27a73 | 11621 | process_die (child_die, cu); |
c906108c SS |
11622 | } |
11623 | else | |
11624 | { | |
39cbfefa DJ |
11625 | name = dwarf2_name (child_die, cu); |
11626 | if (name) | |
c906108c | 11627 | { |
f792889a | 11628 | sym = new_symbol (child_die, this_type, cu); |
c906108c | 11629 | if (SYMBOL_VALUE (sym) < 0) |
cafec441 TT |
11630 | { |
11631 | unsigned_enum = 0; | |
11632 | flag_enum = 0; | |
11633 | } | |
11634 | else if ((mask & SYMBOL_VALUE (sym)) != 0) | |
11635 | flag_enum = 0; | |
11636 | else | |
11637 | mask |= SYMBOL_VALUE (sym); | |
c906108c SS |
11638 | |
11639 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
11640 | { | |
11641 | fields = (struct field *) | |
11642 | xrealloc (fields, | |
11643 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 11644 | * sizeof (struct field)); |
c906108c SS |
11645 | } |
11646 | ||
3567439c | 11647 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 11648 | FIELD_TYPE (fields[num_fields]) = NULL; |
14e75d8e | 11649 | SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
11650 | FIELD_BITSIZE (fields[num_fields]) = 0; |
11651 | ||
11652 | num_fields++; | |
11653 | } | |
11654 | } | |
11655 | ||
11656 | child_die = sibling_die (child_die); | |
11657 | } | |
11658 | ||
11659 | if (num_fields) | |
11660 | { | |
f792889a DJ |
11661 | TYPE_NFIELDS (this_type) = num_fields; |
11662 | TYPE_FIELDS (this_type) = (struct field *) | |
11663 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
11664 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 11665 | sizeof (struct field) * num_fields); |
b8c9b27d | 11666 | xfree (fields); |
c906108c SS |
11667 | } |
11668 | if (unsigned_enum) | |
876cecd0 | 11669 | TYPE_UNSIGNED (this_type) = 1; |
cafec441 TT |
11670 | if (flag_enum) |
11671 | TYPE_FLAG_ENUM (this_type) = 1; | |
c906108c | 11672 | } |
134d01f1 | 11673 | |
6c83ed52 TT |
11674 | /* If we are reading an enum from a .debug_types unit, and the enum |
11675 | is a declaration, and the enum is not the signatured type in the | |
11676 | unit, then we do not want to add a symbol for it. Adding a | |
11677 | symbol would in some cases obscure the true definition of the | |
11678 | enum, giving users an incomplete type when the definition is | |
11679 | actually available. Note that we do not want to do this for all | |
11680 | enums which are just declarations, because C++0x allows forward | |
11681 | enum declarations. */ | |
3019eac3 | 11682 | if (cu->per_cu->is_debug_types |
6c83ed52 TT |
11683 | && die_is_declaration (die, cu)) |
11684 | { | |
52dc124a | 11685 | struct signatured_type *sig_type; |
6c83ed52 | 11686 | |
52dc124a | 11687 | sig_type |
6c83ed52 | 11688 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, |
3019eac3 | 11689 | cu->per_cu->info_or_types_section, |
6c83ed52 | 11690 | cu->per_cu->offset); |
3019eac3 DE |
11691 | gdb_assert (sig_type->type_offset_in_section.sect_off != 0); |
11692 | if (sig_type->type_offset_in_section.sect_off != die->offset.sect_off) | |
6c83ed52 TT |
11693 | return; |
11694 | } | |
11695 | ||
f792889a | 11696 | new_symbol (die, this_type, cu); |
c906108c SS |
11697 | } |
11698 | ||
11699 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
11700 | the DIE's type field. For now, this only handles one dimensional | |
11701 | arrays. */ | |
11702 | ||
f792889a | 11703 | static struct type * |
e7c27a73 | 11704 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11705 | { |
e7c27a73 | 11706 | struct objfile *objfile = cu->objfile; |
c906108c | 11707 | struct die_info *child_die; |
7e314c57 | 11708 | struct type *type; |
c906108c SS |
11709 | struct type *element_type, *range_type, *index_type; |
11710 | struct type **range_types = NULL; | |
11711 | struct attribute *attr; | |
11712 | int ndim = 0; | |
11713 | struct cleanup *back_to; | |
15d034d0 | 11714 | const char *name; |
c906108c | 11715 | |
e7c27a73 | 11716 | element_type = die_type (die, cu); |
c906108c | 11717 | |
7e314c57 JK |
11718 | /* The die_type call above may have already set the type for this DIE. */ |
11719 | type = get_die_type (die, cu); | |
11720 | if (type) | |
11721 | return type; | |
11722 | ||
c906108c SS |
11723 | /* Irix 6.2 native cc creates array types without children for |
11724 | arrays with unspecified length. */ | |
639d11d3 | 11725 | if (die->child == NULL) |
c906108c | 11726 | { |
46bf5051 | 11727 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 11728 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
11729 | type = create_array_type (NULL, element_type, range_type); |
11730 | return set_die_type (die, type, cu); | |
c906108c SS |
11731 | } |
11732 | ||
11733 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 11734 | child_die = die->child; |
c906108c SS |
11735 | while (child_die && child_die->tag) |
11736 | { | |
11737 | if (child_die->tag == DW_TAG_subrange_type) | |
11738 | { | |
f792889a | 11739 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 11740 | |
f792889a | 11741 | if (child_type != NULL) |
a02abb62 | 11742 | { |
0963b4bd MS |
11743 | /* The range type was succesfully read. Save it for the |
11744 | array type creation. */ | |
a02abb62 JB |
11745 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
11746 | { | |
11747 | range_types = (struct type **) | |
11748 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
11749 | * sizeof (struct type *)); | |
11750 | if (ndim == 0) | |
11751 | make_cleanup (free_current_contents, &range_types); | |
11752 | } | |
f792889a | 11753 | range_types[ndim++] = child_type; |
a02abb62 | 11754 | } |
c906108c SS |
11755 | } |
11756 | child_die = sibling_die (child_die); | |
11757 | } | |
11758 | ||
11759 | /* Dwarf2 dimensions are output from left to right, create the | |
11760 | necessary array types in backwards order. */ | |
7ca2d3a3 | 11761 | |
c906108c | 11762 | type = element_type; |
7ca2d3a3 DL |
11763 | |
11764 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
11765 | { | |
11766 | int i = 0; | |
9a619af0 | 11767 | |
7ca2d3a3 DL |
11768 | while (i < ndim) |
11769 | type = create_array_type (NULL, type, range_types[i++]); | |
11770 | } | |
11771 | else | |
11772 | { | |
11773 | while (ndim-- > 0) | |
11774 | type = create_array_type (NULL, type, range_types[ndim]); | |
11775 | } | |
c906108c | 11776 | |
f5f8a009 EZ |
11777 | /* Understand Dwarf2 support for vector types (like they occur on |
11778 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
11779 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
11780 | custom vendor extension. The main difference between a regular | |
11781 | array and the vector variant is that vectors are passed by value | |
11782 | to functions. */ | |
e142c38c | 11783 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 11784 | if (attr) |
ea37ba09 | 11785 | make_vector_type (type); |
f5f8a009 | 11786 | |
dbc98a8b KW |
11787 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
11788 | implementation may choose to implement triple vectors using this | |
11789 | attribute. */ | |
11790 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
11791 | if (attr) | |
11792 | { | |
11793 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
11794 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
11795 | else | |
3e43a32a MS |
11796 | complaint (&symfile_complaints, |
11797 | _("DW_AT_byte_size for array type smaller " | |
11798 | "than the total size of elements")); | |
dbc98a8b KW |
11799 | } |
11800 | ||
39cbfefa DJ |
11801 | name = dwarf2_name (die, cu); |
11802 | if (name) | |
11803 | TYPE_NAME (type) = name; | |
6e70227d | 11804 | |
0963b4bd | 11805 | /* Install the type in the die. */ |
7e314c57 JK |
11806 | set_die_type (die, type, cu); |
11807 | ||
11808 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
11809 | set_descriptive_type (type, die, cu); |
11810 | ||
c906108c SS |
11811 | do_cleanups (back_to); |
11812 | ||
7e314c57 | 11813 | return type; |
c906108c SS |
11814 | } |
11815 | ||
7ca2d3a3 | 11816 | static enum dwarf_array_dim_ordering |
6e70227d | 11817 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
11818 | { |
11819 | struct attribute *attr; | |
11820 | ||
11821 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
11822 | ||
11823 | if (attr) return DW_SND (attr); | |
11824 | ||
0963b4bd MS |
11825 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
11826 | opposite order to the dwarf2 specification, but data is still | |
11827 | laid out as per normal fortran. | |
7ca2d3a3 | 11828 | |
0963b4bd MS |
11829 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
11830 | version checking. */ | |
7ca2d3a3 | 11831 | |
905e0470 PM |
11832 | if (cu->language == language_fortran |
11833 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
11834 | { |
11835 | return DW_ORD_row_major; | |
11836 | } | |
11837 | ||
6e70227d | 11838 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
11839 | { |
11840 | case array_column_major: | |
11841 | return DW_ORD_col_major; | |
11842 | case array_row_major: | |
11843 | default: | |
11844 | return DW_ORD_row_major; | |
11845 | }; | |
11846 | } | |
11847 | ||
72019c9c | 11848 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 11849 | the DIE's type field. */ |
72019c9c | 11850 | |
f792889a | 11851 | static struct type * |
72019c9c GM |
11852 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
11853 | { | |
7e314c57 JK |
11854 | struct type *domain_type, *set_type; |
11855 | struct attribute *attr; | |
f792889a | 11856 | |
7e314c57 JK |
11857 | domain_type = die_type (die, cu); |
11858 | ||
11859 | /* The die_type call above may have already set the type for this DIE. */ | |
11860 | set_type = get_die_type (die, cu); | |
11861 | if (set_type) | |
11862 | return set_type; | |
11863 | ||
11864 | set_type = create_set_type (NULL, domain_type); | |
11865 | ||
11866 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
11867 | if (attr) |
11868 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 11869 | |
f792889a | 11870 | return set_die_type (die, set_type, cu); |
72019c9c | 11871 | } |
7ca2d3a3 | 11872 | |
0971de02 TT |
11873 | /* A helper for read_common_block that creates a locexpr baton. |
11874 | SYM is the symbol which we are marking as computed. | |
11875 | COMMON_DIE is the DIE for the common block. | |
11876 | COMMON_LOC is the location expression attribute for the common | |
11877 | block itself. | |
11878 | MEMBER_LOC is the location expression attribute for the particular | |
11879 | member of the common block that we are processing. | |
11880 | CU is the CU from which the above come. */ | |
11881 | ||
11882 | static void | |
11883 | mark_common_block_symbol_computed (struct symbol *sym, | |
11884 | struct die_info *common_die, | |
11885 | struct attribute *common_loc, | |
11886 | struct attribute *member_loc, | |
11887 | struct dwarf2_cu *cu) | |
11888 | { | |
11889 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
11890 | struct dwarf2_locexpr_baton *baton; | |
11891 | gdb_byte *ptr; | |
11892 | unsigned int cu_off; | |
11893 | enum bfd_endian byte_order = gdbarch_byte_order (get_objfile_arch (objfile)); | |
11894 | LONGEST offset = 0; | |
11895 | ||
11896 | gdb_assert (common_loc && member_loc); | |
11897 | gdb_assert (attr_form_is_block (common_loc)); | |
11898 | gdb_assert (attr_form_is_block (member_loc) | |
11899 | || attr_form_is_constant (member_loc)); | |
11900 | ||
11901 | baton = obstack_alloc (&objfile->objfile_obstack, | |
11902 | sizeof (struct dwarf2_locexpr_baton)); | |
11903 | baton->per_cu = cu->per_cu; | |
11904 | gdb_assert (baton->per_cu); | |
11905 | ||
11906 | baton->size = 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */; | |
11907 | ||
11908 | if (attr_form_is_constant (member_loc)) | |
11909 | { | |
11910 | offset = dwarf2_get_attr_constant_value (member_loc, 0); | |
11911 | baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size; | |
11912 | } | |
11913 | else | |
11914 | baton->size += DW_BLOCK (member_loc)->size; | |
11915 | ||
11916 | ptr = obstack_alloc (&objfile->objfile_obstack, baton->size); | |
11917 | baton->data = ptr; | |
11918 | ||
11919 | *ptr++ = DW_OP_call4; | |
11920 | cu_off = common_die->offset.sect_off - cu->per_cu->offset.sect_off; | |
11921 | store_unsigned_integer (ptr, 4, byte_order, cu_off); | |
11922 | ptr += 4; | |
11923 | ||
11924 | if (attr_form_is_constant (member_loc)) | |
11925 | { | |
11926 | *ptr++ = DW_OP_addr; | |
11927 | store_unsigned_integer (ptr, cu->header.addr_size, byte_order, offset); | |
11928 | ptr += cu->header.addr_size; | |
11929 | } | |
11930 | else | |
11931 | { | |
11932 | /* We have to copy the data here, because DW_OP_call4 will only | |
11933 | use a DW_AT_location attribute. */ | |
11934 | memcpy (ptr, DW_BLOCK (member_loc)->data, DW_BLOCK (member_loc)->size); | |
11935 | ptr += DW_BLOCK (member_loc)->size; | |
11936 | } | |
11937 | ||
11938 | *ptr++ = DW_OP_plus; | |
11939 | gdb_assert (ptr - baton->data == baton->size); | |
11940 | ||
11941 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
11942 | SYMBOL_LOCATION_BATON (sym) = baton; | |
11943 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
11944 | } | |
11945 | ||
4357ac6c TT |
11946 | /* Create appropriate locally-scoped variables for all the |
11947 | DW_TAG_common_block entries. Also create a struct common_block | |
11948 | listing all such variables for `info common'. COMMON_BLOCK_DOMAIN | |
11949 | is used to sepate the common blocks name namespace from regular | |
11950 | variable names. */ | |
c906108c SS |
11951 | |
11952 | static void | |
e7c27a73 | 11953 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11954 | { |
0971de02 TT |
11955 | struct attribute *attr; |
11956 | ||
11957 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
11958 | if (attr) | |
11959 | { | |
11960 | /* Support the .debug_loc offsets. */ | |
11961 | if (attr_form_is_block (attr)) | |
11962 | { | |
11963 | /* Ok. */ | |
11964 | } | |
11965 | else if (attr_form_is_section_offset (attr)) | |
11966 | { | |
11967 | dwarf2_complex_location_expr_complaint (); | |
11968 | attr = NULL; | |
11969 | } | |
11970 | else | |
11971 | { | |
11972 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", | |
11973 | "common block member"); | |
11974 | attr = NULL; | |
11975 | } | |
11976 | } | |
11977 | ||
639d11d3 | 11978 | if (die->child != NULL) |
c906108c | 11979 | { |
4357ac6c TT |
11980 | struct objfile *objfile = cu->objfile; |
11981 | struct die_info *child_die; | |
11982 | size_t n_entries = 0, size; | |
11983 | struct common_block *common_block; | |
11984 | struct symbol *sym; | |
74ac6d43 | 11985 | |
4357ac6c TT |
11986 | for (child_die = die->child; |
11987 | child_die && child_die->tag; | |
11988 | child_die = sibling_die (child_die)) | |
11989 | ++n_entries; | |
11990 | ||
11991 | size = (sizeof (struct common_block) | |
11992 | + (n_entries - 1) * sizeof (struct symbol *)); | |
11993 | common_block = obstack_alloc (&objfile->objfile_obstack, size); | |
11994 | memset (common_block->contents, 0, n_entries * sizeof (struct symbol *)); | |
11995 | common_block->n_entries = 0; | |
11996 | ||
11997 | for (child_die = die->child; | |
11998 | child_die && child_die->tag; | |
11999 | child_die = sibling_die (child_die)) | |
12000 | { | |
12001 | /* Create the symbol in the DW_TAG_common_block block in the current | |
12002 | symbol scope. */ | |
e7c27a73 | 12003 | sym = new_symbol (child_die, NULL, cu); |
0971de02 TT |
12004 | if (sym != NULL) |
12005 | { | |
12006 | struct attribute *member_loc; | |
12007 | ||
12008 | common_block->contents[common_block->n_entries++] = sym; | |
12009 | ||
12010 | member_loc = dwarf2_attr (child_die, DW_AT_data_member_location, | |
12011 | cu); | |
12012 | if (member_loc) | |
12013 | { | |
12014 | /* GDB has handled this for a long time, but it is | |
12015 | not specified by DWARF. It seems to have been | |
12016 | emitted by gfortran at least as recently as: | |
12017 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */ | |
12018 | complaint (&symfile_complaints, | |
12019 | _("Variable in common block has " | |
12020 | "DW_AT_data_member_location " | |
12021 | "- DIE at 0x%x [in module %s]"), | |
12022 | child_die->offset.sect_off, cu->objfile->name); | |
12023 | ||
12024 | if (attr_form_is_section_offset (member_loc)) | |
12025 | dwarf2_complex_location_expr_complaint (); | |
12026 | else if (attr_form_is_constant (member_loc) | |
12027 | || attr_form_is_block (member_loc)) | |
12028 | { | |
12029 | if (attr) | |
12030 | mark_common_block_symbol_computed (sym, die, attr, | |
12031 | member_loc, cu); | |
12032 | } | |
12033 | else | |
12034 | dwarf2_complex_location_expr_complaint (); | |
12035 | } | |
12036 | } | |
c906108c | 12037 | } |
4357ac6c TT |
12038 | |
12039 | sym = new_symbol (die, objfile_type (objfile)->builtin_void, cu); | |
12040 | SYMBOL_VALUE_COMMON_BLOCK (sym) = common_block; | |
c906108c SS |
12041 | } |
12042 | } | |
12043 | ||
0114d602 | 12044 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 12045 | |
0114d602 DJ |
12046 | static struct type * |
12047 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 12048 | { |
e7c27a73 | 12049 | struct objfile *objfile = cu->objfile; |
0114d602 | 12050 | const char *previous_prefix, *name; |
9219021c | 12051 | int is_anonymous; |
0114d602 DJ |
12052 | struct type *type; |
12053 | ||
12054 | /* For extensions, reuse the type of the original namespace. */ | |
12055 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
12056 | { | |
12057 | struct die_info *ext_die; | |
12058 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 12059 | |
0114d602 DJ |
12060 | ext_die = dwarf2_extension (die, &ext_cu); |
12061 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
12062 | |
12063 | /* EXT_CU may not be the same as CU. | |
12064 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
12065 | return set_die_type (die, type, cu); |
12066 | } | |
9219021c | 12067 | |
e142c38c | 12068 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
12069 | |
12070 | /* Now build the name of the current namespace. */ | |
12071 | ||
0114d602 DJ |
12072 | previous_prefix = determine_prefix (die, cu); |
12073 | if (previous_prefix[0] != '\0') | |
12074 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 12075 | previous_prefix, name, 0, cu); |
0114d602 DJ |
12076 | |
12077 | /* Create the type. */ | |
12078 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
12079 | objfile); | |
12080 | TYPE_NAME (type) = (char *) name; | |
12081 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
12082 | ||
60531b24 | 12083 | return set_die_type (die, type, cu); |
0114d602 DJ |
12084 | } |
12085 | ||
12086 | /* Read a C++ namespace. */ | |
12087 | ||
12088 | static void | |
12089 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
12090 | { | |
12091 | struct objfile *objfile = cu->objfile; | |
0114d602 | 12092 | int is_anonymous; |
9219021c | 12093 | |
5c4e30ca DC |
12094 | /* Add a symbol associated to this if we haven't seen the namespace |
12095 | before. Also, add a using directive if it's an anonymous | |
12096 | namespace. */ | |
9219021c | 12097 | |
f2f0e013 | 12098 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
12099 | { |
12100 | struct type *type; | |
12101 | ||
0114d602 | 12102 | type = read_type_die (die, cu); |
e7c27a73 | 12103 | new_symbol (die, type, cu); |
5c4e30ca | 12104 | |
e8e80198 | 12105 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 12106 | if (is_anonymous) |
0114d602 DJ |
12107 | { |
12108 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 12109 | |
c0cc3a76 | 12110 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
32019081 | 12111 | NULL, NULL, &objfile->objfile_obstack); |
0114d602 | 12112 | } |
5c4e30ca | 12113 | } |
9219021c | 12114 | |
639d11d3 | 12115 | if (die->child != NULL) |
d9fa45fe | 12116 | { |
639d11d3 | 12117 | struct die_info *child_die = die->child; |
6e70227d | 12118 | |
d9fa45fe DC |
12119 | while (child_die && child_die->tag) |
12120 | { | |
e7c27a73 | 12121 | process_die (child_die, cu); |
d9fa45fe DC |
12122 | child_die = sibling_die (child_die); |
12123 | } | |
12124 | } | |
38d518c9 EZ |
12125 | } |
12126 | ||
f55ee35c JK |
12127 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
12128 | imported module. Still we need that type as local Fortran "use ... only" | |
12129 | declaration imports depend on the created type in determine_prefix. */ | |
12130 | ||
12131 | static struct type * | |
12132 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
12133 | { | |
12134 | struct objfile *objfile = cu->objfile; | |
15d034d0 | 12135 | const char *module_name; |
f55ee35c JK |
12136 | struct type *type; |
12137 | ||
12138 | module_name = dwarf2_name (die, cu); | |
12139 | if (!module_name) | |
3e43a32a MS |
12140 | complaint (&symfile_complaints, |
12141 | _("DW_TAG_module has no name, offset 0x%x"), | |
b64f50a1 | 12142 | die->offset.sect_off); |
f55ee35c JK |
12143 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); |
12144 | ||
12145 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
12146 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
12147 | ||
12148 | return set_die_type (die, type, cu); | |
12149 | } | |
12150 | ||
5d7cb8df JK |
12151 | /* Read a Fortran module. */ |
12152 | ||
12153 | static void | |
12154 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
12155 | { | |
12156 | struct die_info *child_die = die->child; | |
12157 | ||
5d7cb8df JK |
12158 | while (child_die && child_die->tag) |
12159 | { | |
12160 | process_die (child_die, cu); | |
12161 | child_die = sibling_die (child_die); | |
12162 | } | |
12163 | } | |
12164 | ||
38d518c9 EZ |
12165 | /* Return the name of the namespace represented by DIE. Set |
12166 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
12167 | namespace. */ | |
12168 | ||
12169 | static const char * | |
e142c38c | 12170 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
12171 | { |
12172 | struct die_info *current_die; | |
12173 | const char *name = NULL; | |
12174 | ||
12175 | /* Loop through the extensions until we find a name. */ | |
12176 | ||
12177 | for (current_die = die; | |
12178 | current_die != NULL; | |
f2f0e013 | 12179 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 12180 | { |
e142c38c | 12181 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
12182 | if (name != NULL) |
12183 | break; | |
12184 | } | |
12185 | ||
12186 | /* Is it an anonymous namespace? */ | |
12187 | ||
12188 | *is_anonymous = (name == NULL); | |
12189 | if (*is_anonymous) | |
2b1dbab0 | 12190 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
12191 | |
12192 | return name; | |
d9fa45fe DC |
12193 | } |
12194 | ||
c906108c SS |
12195 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
12196 | the user defined type vector. */ | |
12197 | ||
f792889a | 12198 | static struct type * |
e7c27a73 | 12199 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12200 | { |
5e2b427d | 12201 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 12202 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 12203 | struct type *type; |
8b2dbe47 KB |
12204 | struct attribute *attr_byte_size; |
12205 | struct attribute *attr_address_class; | |
12206 | int byte_size, addr_class; | |
7e314c57 JK |
12207 | struct type *target_type; |
12208 | ||
12209 | target_type = die_type (die, cu); | |
c906108c | 12210 | |
7e314c57 JK |
12211 | /* The die_type call above may have already set the type for this DIE. */ |
12212 | type = get_die_type (die, cu); | |
12213 | if (type) | |
12214 | return type; | |
12215 | ||
12216 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 12217 | |
e142c38c | 12218 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
12219 | if (attr_byte_size) |
12220 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 12221 | else |
8b2dbe47 KB |
12222 | byte_size = cu_header->addr_size; |
12223 | ||
e142c38c | 12224 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
12225 | if (attr_address_class) |
12226 | addr_class = DW_UNSND (attr_address_class); | |
12227 | else | |
12228 | addr_class = DW_ADDR_none; | |
12229 | ||
12230 | /* If the pointer size or address class is different than the | |
12231 | default, create a type variant marked as such and set the | |
12232 | length accordingly. */ | |
12233 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 12234 | { |
5e2b427d | 12235 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
12236 | { |
12237 | int type_flags; | |
12238 | ||
849957d9 | 12239 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 12240 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
12241 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
12242 | == 0); | |
8b2dbe47 KB |
12243 | type = make_type_with_address_space (type, type_flags); |
12244 | } | |
12245 | else if (TYPE_LENGTH (type) != byte_size) | |
12246 | { | |
3e43a32a MS |
12247 | complaint (&symfile_complaints, |
12248 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 12249 | } |
6e70227d | 12250 | else |
9a619af0 MS |
12251 | { |
12252 | /* Should we also complain about unhandled address classes? */ | |
12253 | } | |
c906108c | 12254 | } |
8b2dbe47 KB |
12255 | |
12256 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 12257 | return set_die_type (die, type, cu); |
c906108c SS |
12258 | } |
12259 | ||
12260 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
12261 | the user defined type vector. */ | |
12262 | ||
f792889a | 12263 | static struct type * |
e7c27a73 | 12264 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
12265 | { |
12266 | struct type *type; | |
12267 | struct type *to_type; | |
12268 | struct type *domain; | |
12269 | ||
e7c27a73 DJ |
12270 | to_type = die_type (die, cu); |
12271 | domain = die_containing_type (die, cu); | |
0d5de010 | 12272 | |
7e314c57 JK |
12273 | /* The calls above may have already set the type for this DIE. */ |
12274 | type = get_die_type (die, cu); | |
12275 | if (type) | |
12276 | return type; | |
12277 | ||
0d5de010 DJ |
12278 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
12279 | type = lookup_methodptr_type (to_type); | |
12280 | else | |
12281 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 12282 | |
f792889a | 12283 | return set_die_type (die, type, cu); |
c906108c SS |
12284 | } |
12285 | ||
12286 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
12287 | the user defined type vector. */ | |
12288 | ||
f792889a | 12289 | static struct type * |
e7c27a73 | 12290 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12291 | { |
e7c27a73 | 12292 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 12293 | struct type *type, *target_type; |
c906108c SS |
12294 | struct attribute *attr; |
12295 | ||
7e314c57 JK |
12296 | target_type = die_type (die, cu); |
12297 | ||
12298 | /* The die_type call above may have already set the type for this DIE. */ | |
12299 | type = get_die_type (die, cu); | |
12300 | if (type) | |
12301 | return type; | |
12302 | ||
12303 | type = lookup_reference_type (target_type); | |
e142c38c | 12304 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
12305 | if (attr) |
12306 | { | |
12307 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
12308 | } | |
12309 | else | |
12310 | { | |
107d2387 | 12311 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 12312 | } |
f792889a | 12313 | return set_die_type (die, type, cu); |
c906108c SS |
12314 | } |
12315 | ||
f792889a | 12316 | static struct type * |
e7c27a73 | 12317 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12318 | { |
f792889a | 12319 | struct type *base_type, *cv_type; |
c906108c | 12320 | |
e7c27a73 | 12321 | base_type = die_type (die, cu); |
7e314c57 JK |
12322 | |
12323 | /* The die_type call above may have already set the type for this DIE. */ | |
12324 | cv_type = get_die_type (die, cu); | |
12325 | if (cv_type) | |
12326 | return cv_type; | |
12327 | ||
2f608a3a KW |
12328 | /* In case the const qualifier is applied to an array type, the element type |
12329 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
12330 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
12331 | { | |
12332 | struct type *el_type, *inner_array; | |
12333 | ||
12334 | base_type = copy_type (base_type); | |
12335 | inner_array = base_type; | |
12336 | ||
12337 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
12338 | { | |
12339 | TYPE_TARGET_TYPE (inner_array) = | |
12340 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
12341 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
12342 | } | |
12343 | ||
12344 | el_type = TYPE_TARGET_TYPE (inner_array); | |
12345 | TYPE_TARGET_TYPE (inner_array) = | |
12346 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
12347 | ||
12348 | return set_die_type (die, base_type, cu); | |
12349 | } | |
12350 | ||
f792889a DJ |
12351 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
12352 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
12353 | } |
12354 | ||
f792889a | 12355 | static struct type * |
e7c27a73 | 12356 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12357 | { |
f792889a | 12358 | struct type *base_type, *cv_type; |
c906108c | 12359 | |
e7c27a73 | 12360 | base_type = die_type (die, cu); |
7e314c57 JK |
12361 | |
12362 | /* The die_type call above may have already set the type for this DIE. */ | |
12363 | cv_type = get_die_type (die, cu); | |
12364 | if (cv_type) | |
12365 | return cv_type; | |
12366 | ||
f792889a DJ |
12367 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
12368 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
12369 | } |
12370 | ||
06d66ee9 TT |
12371 | /* Handle DW_TAG_restrict_type. */ |
12372 | ||
12373 | static struct type * | |
12374 | read_tag_restrict_type (struct die_info *die, struct dwarf2_cu *cu) | |
12375 | { | |
12376 | struct type *base_type, *cv_type; | |
12377 | ||
12378 | base_type = die_type (die, cu); | |
12379 | ||
12380 | /* The die_type call above may have already set the type for this DIE. */ | |
12381 | cv_type = get_die_type (die, cu); | |
12382 | if (cv_type) | |
12383 | return cv_type; | |
12384 | ||
12385 | cv_type = make_restrict_type (base_type); | |
12386 | return set_die_type (die, cv_type, cu); | |
12387 | } | |
12388 | ||
c906108c SS |
12389 | /* Extract all information from a DW_TAG_string_type DIE and add to |
12390 | the user defined type vector. It isn't really a user defined type, | |
12391 | but it behaves like one, with other DIE's using an AT_user_def_type | |
12392 | attribute to reference it. */ | |
12393 | ||
f792889a | 12394 | static struct type * |
e7c27a73 | 12395 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12396 | { |
e7c27a73 | 12397 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 12398 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
12399 | struct type *type, *range_type, *index_type, *char_type; |
12400 | struct attribute *attr; | |
12401 | unsigned int length; | |
12402 | ||
e142c38c | 12403 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
12404 | if (attr) |
12405 | { | |
12406 | length = DW_UNSND (attr); | |
12407 | } | |
12408 | else | |
12409 | { | |
0963b4bd | 12410 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 12411 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
12412 | if (attr) |
12413 | { | |
12414 | length = DW_UNSND (attr); | |
12415 | } | |
12416 | else | |
12417 | { | |
12418 | length = 1; | |
12419 | } | |
c906108c | 12420 | } |
6ccb9162 | 12421 | |
46bf5051 | 12422 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 12423 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
12424 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
12425 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 12426 | |
f792889a | 12427 | return set_die_type (die, type, cu); |
c906108c SS |
12428 | } |
12429 | ||
12430 | /* Handle DIES due to C code like: | |
12431 | ||
12432 | struct foo | |
c5aa993b JM |
12433 | { |
12434 | int (*funcp)(int a, long l); | |
12435 | int b; | |
12436 | }; | |
c906108c | 12437 | |
0963b4bd | 12438 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 12439 | |
f792889a | 12440 | static struct type * |
e7c27a73 | 12441 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12442 | { |
bb5ed363 | 12443 | struct objfile *objfile = cu->objfile; |
0963b4bd MS |
12444 | struct type *type; /* Type that this function returns. */ |
12445 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
12446 | struct attribute *attr; |
12447 | ||
e7c27a73 | 12448 | type = die_type (die, cu); |
7e314c57 JK |
12449 | |
12450 | /* The die_type call above may have already set the type for this DIE. */ | |
12451 | ftype = get_die_type (die, cu); | |
12452 | if (ftype) | |
12453 | return ftype; | |
12454 | ||
0c8b41f1 | 12455 | ftype = lookup_function_type (type); |
c906108c | 12456 | |
5b8101ae | 12457 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 12458 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 12459 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 12460 | || cu->language == language_cplus |
5b8101ae PM |
12461 | || cu->language == language_java |
12462 | || cu->language == language_pascal) | |
876cecd0 | 12463 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
12464 | else if (producer_is_realview (cu->producer)) |
12465 | /* RealView does not emit DW_AT_prototyped. We can not | |
12466 | distinguish prototyped and unprototyped functions; default to | |
12467 | prototyped, since that is more common in modern code (and | |
12468 | RealView warns about unprototyped functions). */ | |
12469 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 12470 | |
c055b101 CV |
12471 | /* Store the calling convention in the type if it's available in |
12472 | the subroutine die. Otherwise set the calling convention to | |
12473 | the default value DW_CC_normal. */ | |
12474 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
12475 | if (attr) |
12476 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
12477 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
12478 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
12479 | else | |
12480 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
12481 | |
12482 | /* We need to add the subroutine type to the die immediately so | |
12483 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 12484 | declared as the same subroutine type. */ |
76c10ea2 | 12485 | set_die_type (die, ftype, cu); |
6e70227d | 12486 | |
639d11d3 | 12487 | if (die->child != NULL) |
c906108c | 12488 | { |
bb5ed363 | 12489 | struct type *void_type = objfile_type (objfile)->builtin_void; |
c906108c | 12490 | struct die_info *child_die; |
8072405b | 12491 | int nparams, iparams; |
c906108c SS |
12492 | |
12493 | /* Count the number of parameters. | |
12494 | FIXME: GDB currently ignores vararg functions, but knows about | |
12495 | vararg member functions. */ | |
8072405b | 12496 | nparams = 0; |
639d11d3 | 12497 | child_die = die->child; |
c906108c SS |
12498 | while (child_die && child_die->tag) |
12499 | { | |
12500 | if (child_die->tag == DW_TAG_formal_parameter) | |
12501 | nparams++; | |
12502 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 12503 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
12504 | child_die = sibling_die (child_die); |
12505 | } | |
12506 | ||
12507 | /* Allocate storage for parameters and fill them in. */ | |
12508 | TYPE_NFIELDS (ftype) = nparams; | |
12509 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 12510 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 12511 | |
8072405b JK |
12512 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
12513 | even if we error out during the parameters reading below. */ | |
12514 | for (iparams = 0; iparams < nparams; iparams++) | |
12515 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
12516 | ||
12517 | iparams = 0; | |
639d11d3 | 12518 | child_die = die->child; |
c906108c SS |
12519 | while (child_die && child_die->tag) |
12520 | { | |
12521 | if (child_die->tag == DW_TAG_formal_parameter) | |
12522 | { | |
3ce3b1ba PA |
12523 | struct type *arg_type; |
12524 | ||
12525 | /* DWARF version 2 has no clean way to discern C++ | |
12526 | static and non-static member functions. G++ helps | |
12527 | GDB by marking the first parameter for non-static | |
12528 | member functions (which is the this pointer) as | |
12529 | artificial. We pass this information to | |
12530 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
12531 | ||
12532 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
12533 | 4.5 does not yet generate. */ | |
e142c38c | 12534 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
12535 | if (attr) |
12536 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
12537 | else | |
418835cc KS |
12538 | { |
12539 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
12540 | ||
12541 | /* GCC/43521: In java, the formal parameter | |
12542 | "this" is sometimes not marked with DW_AT_artificial. */ | |
12543 | if (cu->language == language_java) | |
12544 | { | |
12545 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 12546 | |
418835cc KS |
12547 | if (name && !strcmp (name, "this")) |
12548 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
12549 | } | |
12550 | } | |
3ce3b1ba PA |
12551 | arg_type = die_type (child_die, cu); |
12552 | ||
12553 | /* RealView does not mark THIS as const, which the testsuite | |
12554 | expects. GCC marks THIS as const in method definitions, | |
12555 | but not in the class specifications (GCC PR 43053). */ | |
12556 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
12557 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
12558 | { | |
12559 | int is_this = 0; | |
12560 | struct dwarf2_cu *arg_cu = cu; | |
12561 | const char *name = dwarf2_name (child_die, cu); | |
12562 | ||
12563 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
12564 | if (attr) | |
12565 | { | |
12566 | /* If the compiler emits this, use it. */ | |
12567 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
12568 | is_this = 1; | |
12569 | } | |
12570 | else if (name && strcmp (name, "this") == 0) | |
12571 | /* Function definitions will have the argument names. */ | |
12572 | is_this = 1; | |
12573 | else if (name == NULL && iparams == 0) | |
12574 | /* Declarations may not have the names, so like | |
12575 | elsewhere in GDB, assume an artificial first | |
12576 | argument is "this". */ | |
12577 | is_this = 1; | |
12578 | ||
12579 | if (is_this) | |
12580 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
12581 | arg_type, 0); | |
12582 | } | |
12583 | ||
12584 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
12585 | iparams++; |
12586 | } | |
12587 | child_die = sibling_die (child_die); | |
12588 | } | |
12589 | } | |
12590 | ||
76c10ea2 | 12591 | return ftype; |
c906108c SS |
12592 | } |
12593 | ||
f792889a | 12594 | static struct type * |
e7c27a73 | 12595 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12596 | { |
e7c27a73 | 12597 | struct objfile *objfile = cu->objfile; |
0114d602 | 12598 | const char *name = NULL; |
3c8e0968 | 12599 | struct type *this_type, *target_type; |
c906108c | 12600 | |
94af9270 | 12601 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 12602 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
12603 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
12604 | TYPE_NAME (this_type) = (char *) name; | |
f792889a | 12605 | set_die_type (die, this_type, cu); |
3c8e0968 DE |
12606 | target_type = die_type (die, cu); |
12607 | if (target_type != this_type) | |
12608 | TYPE_TARGET_TYPE (this_type) = target_type; | |
12609 | else | |
12610 | { | |
12611 | /* Self-referential typedefs are, it seems, not allowed by the DWARF | |
12612 | spec and cause infinite loops in GDB. */ | |
12613 | complaint (&symfile_complaints, | |
12614 | _("Self-referential DW_TAG_typedef " | |
12615 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 12616 | die->offset.sect_off, objfile->name); |
3c8e0968 DE |
12617 | TYPE_TARGET_TYPE (this_type) = NULL; |
12618 | } | |
f792889a | 12619 | return this_type; |
c906108c SS |
12620 | } |
12621 | ||
12622 | /* Find a representation of a given base type and install | |
12623 | it in the TYPE field of the die. */ | |
12624 | ||
f792889a | 12625 | static struct type * |
e7c27a73 | 12626 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12627 | { |
e7c27a73 | 12628 | struct objfile *objfile = cu->objfile; |
c906108c SS |
12629 | struct type *type; |
12630 | struct attribute *attr; | |
12631 | int encoding = 0, size = 0; | |
15d034d0 | 12632 | const char *name; |
6ccb9162 UW |
12633 | enum type_code code = TYPE_CODE_INT; |
12634 | int type_flags = 0; | |
12635 | struct type *target_type = NULL; | |
c906108c | 12636 | |
e142c38c | 12637 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
12638 | if (attr) |
12639 | { | |
12640 | encoding = DW_UNSND (attr); | |
12641 | } | |
e142c38c | 12642 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
12643 | if (attr) |
12644 | { | |
12645 | size = DW_UNSND (attr); | |
12646 | } | |
39cbfefa | 12647 | name = dwarf2_name (die, cu); |
6ccb9162 | 12648 | if (!name) |
c906108c | 12649 | { |
6ccb9162 UW |
12650 | complaint (&symfile_complaints, |
12651 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 12652 | } |
6ccb9162 UW |
12653 | |
12654 | switch (encoding) | |
c906108c | 12655 | { |
6ccb9162 UW |
12656 | case DW_ATE_address: |
12657 | /* Turn DW_ATE_address into a void * pointer. */ | |
12658 | code = TYPE_CODE_PTR; | |
12659 | type_flags |= TYPE_FLAG_UNSIGNED; | |
12660 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
12661 | break; | |
12662 | case DW_ATE_boolean: | |
12663 | code = TYPE_CODE_BOOL; | |
12664 | type_flags |= TYPE_FLAG_UNSIGNED; | |
12665 | break; | |
12666 | case DW_ATE_complex_float: | |
12667 | code = TYPE_CODE_COMPLEX; | |
12668 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
12669 | break; | |
12670 | case DW_ATE_decimal_float: | |
12671 | code = TYPE_CODE_DECFLOAT; | |
12672 | break; | |
12673 | case DW_ATE_float: | |
12674 | code = TYPE_CODE_FLT; | |
12675 | break; | |
12676 | case DW_ATE_signed: | |
12677 | break; | |
12678 | case DW_ATE_unsigned: | |
12679 | type_flags |= TYPE_FLAG_UNSIGNED; | |
3b2b8fea TT |
12680 | if (cu->language == language_fortran |
12681 | && name | |
12682 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) | |
12683 | code = TYPE_CODE_CHAR; | |
6ccb9162 UW |
12684 | break; |
12685 | case DW_ATE_signed_char: | |
6e70227d | 12686 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
12687 | || cu->language == language_pascal |
12688 | || cu->language == language_fortran) | |
6ccb9162 UW |
12689 | code = TYPE_CODE_CHAR; |
12690 | break; | |
12691 | case DW_ATE_unsigned_char: | |
868a0084 | 12692 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
12693 | || cu->language == language_pascal |
12694 | || cu->language == language_fortran) | |
6ccb9162 UW |
12695 | code = TYPE_CODE_CHAR; |
12696 | type_flags |= TYPE_FLAG_UNSIGNED; | |
12697 | break; | |
75079b2b TT |
12698 | case DW_ATE_UTF: |
12699 | /* We just treat this as an integer and then recognize the | |
12700 | type by name elsewhere. */ | |
12701 | break; | |
12702 | ||
6ccb9162 UW |
12703 | default: |
12704 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
12705 | dwarf_type_encoding_name (encoding)); | |
12706 | break; | |
c906108c | 12707 | } |
6ccb9162 | 12708 | |
0114d602 DJ |
12709 | type = init_type (code, size, type_flags, NULL, objfile); |
12710 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
12711 | TYPE_TARGET_TYPE (type) = target_type; |
12712 | ||
0114d602 | 12713 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 12714 | TYPE_NOSIGN (type) = 1; |
0114d602 | 12715 | |
f792889a | 12716 | return set_die_type (die, type, cu); |
c906108c SS |
12717 | } |
12718 | ||
a02abb62 JB |
12719 | /* Read the given DW_AT_subrange DIE. */ |
12720 | ||
f792889a | 12721 | static struct type * |
a02abb62 JB |
12722 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
12723 | { | |
12724 | struct type *base_type; | |
12725 | struct type *range_type; | |
12726 | struct attribute *attr; | |
4fae6e18 JK |
12727 | LONGEST low, high; |
12728 | int low_default_is_valid; | |
15d034d0 | 12729 | const char *name; |
43bbcdc2 | 12730 | LONGEST negative_mask; |
e77813c8 | 12731 | |
a02abb62 | 12732 | base_type = die_type (die, cu); |
953ac07e JK |
12733 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
12734 | check_typedef (base_type); | |
a02abb62 | 12735 | |
7e314c57 JK |
12736 | /* The die_type call above may have already set the type for this DIE. */ |
12737 | range_type = get_die_type (die, cu); | |
12738 | if (range_type) | |
12739 | return range_type; | |
12740 | ||
4fae6e18 JK |
12741 | /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow |
12742 | omitting DW_AT_lower_bound. */ | |
12743 | switch (cu->language) | |
6e70227d | 12744 | { |
4fae6e18 JK |
12745 | case language_c: |
12746 | case language_cplus: | |
12747 | low = 0; | |
12748 | low_default_is_valid = 1; | |
12749 | break; | |
12750 | case language_fortran: | |
12751 | low = 1; | |
12752 | low_default_is_valid = 1; | |
12753 | break; | |
12754 | case language_d: | |
12755 | case language_java: | |
12756 | case language_objc: | |
12757 | low = 0; | |
12758 | low_default_is_valid = (cu->header.version >= 4); | |
12759 | break; | |
12760 | case language_ada: | |
12761 | case language_m2: | |
12762 | case language_pascal: | |
a02abb62 | 12763 | low = 1; |
4fae6e18 JK |
12764 | low_default_is_valid = (cu->header.version >= 4); |
12765 | break; | |
12766 | default: | |
12767 | low = 0; | |
12768 | low_default_is_valid = 0; | |
12769 | break; | |
a02abb62 JB |
12770 | } |
12771 | ||
dd5e6932 DJ |
12772 | /* FIXME: For variable sized arrays either of these could be |
12773 | a variable rather than a constant value. We'll allow it, | |
12774 | but we don't know how to handle it. */ | |
e142c38c | 12775 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 | 12776 | if (attr) |
4fae6e18 JK |
12777 | low = dwarf2_get_attr_constant_value (attr, low); |
12778 | else if (!low_default_is_valid) | |
12779 | complaint (&symfile_complaints, _("Missing DW_AT_lower_bound " | |
12780 | "- DIE at 0x%x [in module %s]"), | |
12781 | die->offset.sect_off, cu->objfile->name); | |
a02abb62 | 12782 | |
e142c38c | 12783 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 12784 | if (attr) |
6e70227d | 12785 | { |
d48323d8 | 12786 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
a02abb62 JB |
12787 | { |
12788 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 12789 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
12790 | FIXME: GDB does not yet know how to handle dynamic |
12791 | arrays properly, treat them as arrays with unspecified | |
12792 | length for now. | |
12793 | ||
12794 | FIXME: jimb/2003-09-22: GDB does not really know | |
12795 | how to handle arrays of unspecified length | |
12796 | either; we just represent them as zero-length | |
12797 | arrays. Choose an appropriate upper bound given | |
12798 | the lower bound we've computed above. */ | |
12799 | high = low - 1; | |
12800 | } | |
12801 | else | |
12802 | high = dwarf2_get_attr_constant_value (attr, 1); | |
12803 | } | |
e77813c8 PM |
12804 | else |
12805 | { | |
12806 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
12807 | if (attr) | |
12808 | { | |
12809 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
12810 | high = low + count - 1; | |
12811 | } | |
c2ff108b JK |
12812 | else |
12813 | { | |
12814 | /* Unspecified array length. */ | |
12815 | high = low - 1; | |
12816 | } | |
e77813c8 PM |
12817 | } |
12818 | ||
12819 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
12820 | without specifying a base type. | |
12821 | In that case, the base type must be set to the type of | |
12822 | the lower bound, upper bound or count, in that order, if any of these | |
12823 | three attributes references an object that has a type. | |
12824 | If no base type is found, the Dwarf-2 specifications say that | |
12825 | a signed integer type of size equal to the size of an address should | |
12826 | be used. | |
12827 | For the following C code: `extern char gdb_int [];' | |
12828 | GCC produces an empty range DIE. | |
12829 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 12830 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
12831 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
12832 | { | |
12833 | struct objfile *objfile = cu->objfile; | |
12834 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
12835 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
12836 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
12837 | ||
12838 | /* Test "int", "long int", and "long long int" objfile types, | |
12839 | and select the first one having a size above or equal to the | |
12840 | architecture address size. */ | |
12841 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
12842 | base_type = int_type; | |
12843 | else | |
12844 | { | |
12845 | int_type = objfile_type (objfile)->builtin_long; | |
12846 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
12847 | base_type = int_type; | |
12848 | else | |
12849 | { | |
12850 | int_type = objfile_type (objfile)->builtin_long_long; | |
12851 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
12852 | base_type = int_type; | |
12853 | } | |
12854 | } | |
12855 | } | |
a02abb62 | 12856 | |
6e70227d | 12857 | negative_mask = |
43bbcdc2 PH |
12858 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
12859 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
12860 | low |= negative_mask; | |
12861 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
12862 | high |= negative_mask; | |
12863 | ||
a02abb62 JB |
12864 | range_type = create_range_type (NULL, base_type, low, high); |
12865 | ||
bbb0eef6 JK |
12866 | /* Mark arrays with dynamic length at least as an array of unspecified |
12867 | length. GDB could check the boundary but before it gets implemented at | |
12868 | least allow accessing the array elements. */ | |
d48323d8 | 12869 | if (attr && attr_form_is_block (attr)) |
bbb0eef6 JK |
12870 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
12871 | ||
c2ff108b JK |
12872 | /* Ada expects an empty array on no boundary attributes. */ |
12873 | if (attr == NULL && cu->language != language_ada) | |
12874 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
12875 | ||
39cbfefa DJ |
12876 | name = dwarf2_name (die, cu); |
12877 | if (name) | |
12878 | TYPE_NAME (range_type) = name; | |
6e70227d | 12879 | |
e142c38c | 12880 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
12881 | if (attr) |
12882 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
12883 | ||
7e314c57 JK |
12884 | set_die_type (die, range_type, cu); |
12885 | ||
12886 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
12887 | set_descriptive_type (range_type, die, cu); |
12888 | ||
7e314c57 | 12889 | return range_type; |
a02abb62 | 12890 | } |
6e70227d | 12891 | |
f792889a | 12892 | static struct type * |
81a17f79 JB |
12893 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
12894 | { | |
12895 | struct type *type; | |
81a17f79 | 12896 | |
81a17f79 JB |
12897 | /* For now, we only support the C meaning of an unspecified type: void. */ |
12898 | ||
0114d602 DJ |
12899 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
12900 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 12901 | |
f792889a | 12902 | return set_die_type (die, type, cu); |
81a17f79 | 12903 | } |
a02abb62 | 12904 | |
639d11d3 DC |
12905 | /* Read a single die and all its descendents. Set the die's sibling |
12906 | field to NULL; set other fields in the die correctly, and set all | |
12907 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
12908 | location of the info_ptr after reading all of those dies. PARENT | |
12909 | is the parent of the die in question. */ | |
12910 | ||
12911 | static struct die_info * | |
dee91e82 DE |
12912 | read_die_and_children (const struct die_reader_specs *reader, |
12913 | gdb_byte *info_ptr, | |
12914 | gdb_byte **new_info_ptr, | |
12915 | struct die_info *parent) | |
639d11d3 DC |
12916 | { |
12917 | struct die_info *die; | |
fe1b8b76 | 12918 | gdb_byte *cur_ptr; |
639d11d3 DC |
12919 | int has_children; |
12920 | ||
93311388 | 12921 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
12922 | if (die == NULL) |
12923 | { | |
12924 | *new_info_ptr = cur_ptr; | |
12925 | return NULL; | |
12926 | } | |
93311388 | 12927 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
12928 | |
12929 | if (has_children) | |
348e048f | 12930 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
12931 | else |
12932 | { | |
12933 | die->child = NULL; | |
12934 | *new_info_ptr = cur_ptr; | |
12935 | } | |
12936 | ||
12937 | die->sibling = NULL; | |
12938 | die->parent = parent; | |
12939 | return die; | |
12940 | } | |
12941 | ||
12942 | /* Read a die, all of its descendents, and all of its siblings; set | |
12943 | all of the fields of all of the dies correctly. Arguments are as | |
12944 | in read_die_and_children. */ | |
12945 | ||
12946 | static struct die_info * | |
93311388 DE |
12947 | read_die_and_siblings (const struct die_reader_specs *reader, |
12948 | gdb_byte *info_ptr, | |
fe1b8b76 | 12949 | gdb_byte **new_info_ptr, |
639d11d3 DC |
12950 | struct die_info *parent) |
12951 | { | |
12952 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 12953 | gdb_byte *cur_ptr; |
639d11d3 | 12954 | |
c906108c | 12955 | cur_ptr = info_ptr; |
639d11d3 DC |
12956 | first_die = last_sibling = NULL; |
12957 | ||
12958 | while (1) | |
c906108c | 12959 | { |
639d11d3 | 12960 | struct die_info *die |
dee91e82 | 12961 | = read_die_and_children (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 12962 | |
1d325ec1 | 12963 | if (die == NULL) |
c906108c | 12964 | { |
639d11d3 DC |
12965 | *new_info_ptr = cur_ptr; |
12966 | return first_die; | |
c906108c | 12967 | } |
1d325ec1 DJ |
12968 | |
12969 | if (!first_die) | |
12970 | first_die = die; | |
c906108c | 12971 | else |
1d325ec1 DJ |
12972 | last_sibling->sibling = die; |
12973 | ||
12974 | last_sibling = die; | |
c906108c | 12975 | } |
c906108c SS |
12976 | } |
12977 | ||
3019eac3 DE |
12978 | /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS |
12979 | attributes. | |
12980 | The caller is responsible for filling in the extra attributes | |
12981 | and updating (*DIEP)->num_attrs. | |
12982 | Set DIEP to point to a newly allocated die with its information, | |
12983 | except for its child, sibling, and parent fields. | |
12984 | Set HAS_CHILDREN to tell whether the die has children or not. */ | |
93311388 DE |
12985 | |
12986 | static gdb_byte * | |
3019eac3 DE |
12987 | read_full_die_1 (const struct die_reader_specs *reader, |
12988 | struct die_info **diep, gdb_byte *info_ptr, | |
12989 | int *has_children, int num_extra_attrs) | |
93311388 | 12990 | { |
b64f50a1 JK |
12991 | unsigned int abbrev_number, bytes_read, i; |
12992 | sect_offset offset; | |
93311388 DE |
12993 | struct abbrev_info *abbrev; |
12994 | struct die_info *die; | |
12995 | struct dwarf2_cu *cu = reader->cu; | |
12996 | bfd *abfd = reader->abfd; | |
12997 | ||
b64f50a1 | 12998 | offset.sect_off = info_ptr - reader->buffer; |
93311388 DE |
12999 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
13000 | info_ptr += bytes_read; | |
13001 | if (!abbrev_number) | |
13002 | { | |
13003 | *diep = NULL; | |
13004 | *has_children = 0; | |
13005 | return info_ptr; | |
13006 | } | |
13007 | ||
433df2d4 | 13008 | abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number); |
93311388 | 13009 | if (!abbrev) |
348e048f DE |
13010 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
13011 | abbrev_number, | |
13012 | bfd_get_filename (abfd)); | |
13013 | ||
3019eac3 | 13014 | die = dwarf_alloc_die (cu, abbrev->num_attrs + num_extra_attrs); |
93311388 DE |
13015 | die->offset = offset; |
13016 | die->tag = abbrev->tag; | |
13017 | die->abbrev = abbrev_number; | |
13018 | ||
3019eac3 DE |
13019 | /* Make the result usable. |
13020 | The caller needs to update num_attrs after adding the extra | |
13021 | attributes. */ | |
93311388 DE |
13022 | die->num_attrs = abbrev->num_attrs; |
13023 | ||
13024 | for (i = 0; i < abbrev->num_attrs; ++i) | |
dee91e82 DE |
13025 | info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i], |
13026 | info_ptr); | |
93311388 DE |
13027 | |
13028 | *diep = die; | |
13029 | *has_children = abbrev->has_children; | |
13030 | return info_ptr; | |
13031 | } | |
13032 | ||
3019eac3 DE |
13033 | /* Read a die and all its attributes. |
13034 | Set DIEP to point to a newly allocated die with its information, | |
13035 | except for its child, sibling, and parent fields. | |
13036 | Set HAS_CHILDREN to tell whether the die has children or not. */ | |
13037 | ||
13038 | static gdb_byte * | |
13039 | read_full_die (const struct die_reader_specs *reader, | |
13040 | struct die_info **diep, gdb_byte *info_ptr, | |
13041 | int *has_children) | |
13042 | { | |
13043 | return read_full_die_1 (reader, diep, info_ptr, has_children, 0); | |
13044 | } | |
433df2d4 DE |
13045 | \f |
13046 | /* Abbreviation tables. | |
3019eac3 | 13047 | |
433df2d4 | 13048 | In DWARF version 2, the description of the debugging information is |
c906108c SS |
13049 | stored in a separate .debug_abbrev section. Before we read any |
13050 | dies from a section we read in all abbreviations and install them | |
433df2d4 DE |
13051 | in a hash table. */ |
13052 | ||
13053 | /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */ | |
13054 | ||
13055 | static struct abbrev_info * | |
13056 | abbrev_table_alloc_abbrev (struct abbrev_table *abbrev_table) | |
13057 | { | |
13058 | struct abbrev_info *abbrev; | |
13059 | ||
13060 | abbrev = (struct abbrev_info *) | |
13061 | obstack_alloc (&abbrev_table->abbrev_obstack, sizeof (struct abbrev_info)); | |
13062 | memset (abbrev, 0, sizeof (struct abbrev_info)); | |
13063 | return abbrev; | |
13064 | } | |
13065 | ||
13066 | /* Add an abbreviation to the table. */ | |
c906108c SS |
13067 | |
13068 | static void | |
433df2d4 DE |
13069 | abbrev_table_add_abbrev (struct abbrev_table *abbrev_table, |
13070 | unsigned int abbrev_number, | |
13071 | struct abbrev_info *abbrev) | |
13072 | { | |
13073 | unsigned int hash_number; | |
13074 | ||
13075 | hash_number = abbrev_number % ABBREV_HASH_SIZE; | |
13076 | abbrev->next = abbrev_table->abbrevs[hash_number]; | |
13077 | abbrev_table->abbrevs[hash_number] = abbrev; | |
13078 | } | |
dee91e82 | 13079 | |
433df2d4 DE |
13080 | /* Look up an abbrev in the table. |
13081 | Returns NULL if the abbrev is not found. */ | |
13082 | ||
13083 | static struct abbrev_info * | |
13084 | abbrev_table_lookup_abbrev (const struct abbrev_table *abbrev_table, | |
13085 | unsigned int abbrev_number) | |
c906108c | 13086 | { |
433df2d4 DE |
13087 | unsigned int hash_number; |
13088 | struct abbrev_info *abbrev; | |
13089 | ||
13090 | hash_number = abbrev_number % ABBREV_HASH_SIZE; | |
13091 | abbrev = abbrev_table->abbrevs[hash_number]; | |
13092 | ||
13093 | while (abbrev) | |
13094 | { | |
13095 | if (abbrev->number == abbrev_number) | |
13096 | return abbrev; | |
13097 | abbrev = abbrev->next; | |
13098 | } | |
13099 | return NULL; | |
13100 | } | |
13101 | ||
13102 | /* Read in an abbrev table. */ | |
13103 | ||
13104 | static struct abbrev_table * | |
13105 | abbrev_table_read_table (struct dwarf2_section_info *section, | |
13106 | sect_offset offset) | |
13107 | { | |
13108 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
13109 | bfd *abfd = section->asection->owner; | |
13110 | struct abbrev_table *abbrev_table; | |
fe1b8b76 | 13111 | gdb_byte *abbrev_ptr; |
c906108c SS |
13112 | struct abbrev_info *cur_abbrev; |
13113 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
433df2d4 | 13114 | unsigned int abbrev_form; |
f3dd6933 DJ |
13115 | struct attr_abbrev *cur_attrs; |
13116 | unsigned int allocated_attrs; | |
c906108c | 13117 | |
433df2d4 | 13118 | abbrev_table = XMALLOC (struct abbrev_table); |
f4dc4d17 | 13119 | abbrev_table->offset = offset; |
433df2d4 DE |
13120 | obstack_init (&abbrev_table->abbrev_obstack); |
13121 | abbrev_table->abbrevs = obstack_alloc (&abbrev_table->abbrev_obstack, | |
13122 | (ABBREV_HASH_SIZE | |
13123 | * sizeof (struct abbrev_info *))); | |
13124 | memset (abbrev_table->abbrevs, 0, | |
13125 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 13126 | |
433df2d4 DE |
13127 | dwarf2_read_section (objfile, section); |
13128 | abbrev_ptr = section->buffer + offset.sect_off; | |
c906108c SS |
13129 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
13130 | abbrev_ptr += bytes_read; | |
13131 | ||
f3dd6933 DJ |
13132 | allocated_attrs = ATTR_ALLOC_CHUNK; |
13133 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 13134 | |
0963b4bd | 13135 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
13136 | while (abbrev_number) |
13137 | { | |
433df2d4 | 13138 | cur_abbrev = abbrev_table_alloc_abbrev (abbrev_table); |
c906108c SS |
13139 | |
13140 | /* read in abbrev header */ | |
13141 | cur_abbrev->number = abbrev_number; | |
13142 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
13143 | abbrev_ptr += bytes_read; | |
13144 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
13145 | abbrev_ptr += 1; | |
13146 | ||
13147 | /* now read in declarations */ | |
13148 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
13149 | abbrev_ptr += bytes_read; | |
13150 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
13151 | abbrev_ptr += bytes_read; | |
13152 | while (abbrev_name) | |
13153 | { | |
f3dd6933 | 13154 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 13155 | { |
f3dd6933 DJ |
13156 | allocated_attrs += ATTR_ALLOC_CHUNK; |
13157 | cur_attrs | |
13158 | = xrealloc (cur_attrs, (allocated_attrs | |
13159 | * sizeof (struct attr_abbrev))); | |
c906108c | 13160 | } |
ae038cb0 | 13161 | |
f3dd6933 DJ |
13162 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
13163 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
13164 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
13165 | abbrev_ptr += bytes_read; | |
13166 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
13167 | abbrev_ptr += bytes_read; | |
13168 | } | |
13169 | ||
433df2d4 | 13170 | cur_abbrev->attrs = obstack_alloc (&abbrev_table->abbrev_obstack, |
f3dd6933 DJ |
13171 | (cur_abbrev->num_attrs |
13172 | * sizeof (struct attr_abbrev))); | |
13173 | memcpy (cur_abbrev->attrs, cur_attrs, | |
13174 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
13175 | ||
433df2d4 | 13176 | abbrev_table_add_abbrev (abbrev_table, abbrev_number, cur_abbrev); |
c906108c SS |
13177 | |
13178 | /* Get next abbreviation. | |
13179 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
13180 | always properly terminated with an abbrev number of 0. |
13181 | Exit loop if we encounter an abbreviation which we have | |
13182 | already read (which means we are about to read the abbreviations | |
13183 | for the next compile unit) or if the end of the abbreviation | |
13184 | table is reached. */ | |
433df2d4 | 13185 | if ((unsigned int) (abbrev_ptr - section->buffer) >= section->size) |
c906108c SS |
13186 | break; |
13187 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
13188 | abbrev_ptr += bytes_read; | |
433df2d4 | 13189 | if (abbrev_table_lookup_abbrev (abbrev_table, abbrev_number) != NULL) |
c906108c SS |
13190 | break; |
13191 | } | |
f3dd6933 DJ |
13192 | |
13193 | xfree (cur_attrs); | |
433df2d4 | 13194 | return abbrev_table; |
c906108c SS |
13195 | } |
13196 | ||
433df2d4 | 13197 | /* Free the resources held by ABBREV_TABLE. */ |
c906108c | 13198 | |
c906108c | 13199 | static void |
433df2d4 | 13200 | abbrev_table_free (struct abbrev_table *abbrev_table) |
c906108c | 13201 | { |
433df2d4 DE |
13202 | obstack_free (&abbrev_table->abbrev_obstack, NULL); |
13203 | xfree (abbrev_table); | |
c906108c SS |
13204 | } |
13205 | ||
f4dc4d17 DE |
13206 | /* Same as abbrev_table_free but as a cleanup. |
13207 | We pass in a pointer to the pointer to the table so that we can | |
13208 | set the pointer to NULL when we're done. It also simplifies | |
13209 | build_type_unit_groups. */ | |
13210 | ||
13211 | static void | |
13212 | abbrev_table_free_cleanup (void *table_ptr) | |
13213 | { | |
13214 | struct abbrev_table **abbrev_table_ptr = table_ptr; | |
13215 | ||
13216 | if (*abbrev_table_ptr != NULL) | |
13217 | abbrev_table_free (*abbrev_table_ptr); | |
13218 | *abbrev_table_ptr = NULL; | |
13219 | } | |
13220 | ||
433df2d4 DE |
13221 | /* Read the abbrev table for CU from ABBREV_SECTION. */ |
13222 | ||
13223 | static void | |
13224 | dwarf2_read_abbrevs (struct dwarf2_cu *cu, | |
13225 | struct dwarf2_section_info *abbrev_section) | |
c906108c | 13226 | { |
433df2d4 DE |
13227 | cu->abbrev_table = |
13228 | abbrev_table_read_table (abbrev_section, cu->header.abbrev_offset); | |
13229 | } | |
c906108c | 13230 | |
433df2d4 | 13231 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 13232 | |
433df2d4 DE |
13233 | static void |
13234 | dwarf2_free_abbrev_table (void *ptr_to_cu) | |
13235 | { | |
13236 | struct dwarf2_cu *cu = ptr_to_cu; | |
c906108c | 13237 | |
433df2d4 DE |
13238 | abbrev_table_free (cu->abbrev_table); |
13239 | /* Set this to NULL so that we SEGV if we try to read it later, | |
13240 | and also because free_comp_unit verifies this is NULL. */ | |
13241 | cu->abbrev_table = NULL; | |
13242 | } | |
13243 | \f | |
72bf9492 DJ |
13244 | /* Returns nonzero if TAG represents a type that we might generate a partial |
13245 | symbol for. */ | |
13246 | ||
13247 | static int | |
13248 | is_type_tag_for_partial (int tag) | |
13249 | { | |
13250 | switch (tag) | |
13251 | { | |
13252 | #if 0 | |
13253 | /* Some types that would be reasonable to generate partial symbols for, | |
13254 | that we don't at present. */ | |
13255 | case DW_TAG_array_type: | |
13256 | case DW_TAG_file_type: | |
13257 | case DW_TAG_ptr_to_member_type: | |
13258 | case DW_TAG_set_type: | |
13259 | case DW_TAG_string_type: | |
13260 | case DW_TAG_subroutine_type: | |
13261 | #endif | |
13262 | case DW_TAG_base_type: | |
13263 | case DW_TAG_class_type: | |
680b30c7 | 13264 | case DW_TAG_interface_type: |
72bf9492 DJ |
13265 | case DW_TAG_enumeration_type: |
13266 | case DW_TAG_structure_type: | |
13267 | case DW_TAG_subrange_type: | |
13268 | case DW_TAG_typedef: | |
13269 | case DW_TAG_union_type: | |
13270 | return 1; | |
13271 | default: | |
13272 | return 0; | |
13273 | } | |
13274 | } | |
13275 | ||
13276 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
13277 | ||
13278 | static struct partial_die_info * | |
dee91e82 DE |
13279 | load_partial_dies (const struct die_reader_specs *reader, |
13280 | gdb_byte *info_ptr, int building_psymtab) | |
72bf9492 | 13281 | { |
dee91e82 | 13282 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 13283 | struct objfile *objfile = cu->objfile; |
72bf9492 DJ |
13284 | struct partial_die_info *part_die; |
13285 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
13286 | struct abbrev_info *abbrev; | |
13287 | unsigned int bytes_read; | |
5afb4e99 | 13288 | unsigned int load_all = 0; |
72bf9492 DJ |
13289 | int nesting_level = 1; |
13290 | ||
13291 | parent_die = NULL; | |
13292 | last_die = NULL; | |
13293 | ||
7adf1e79 DE |
13294 | gdb_assert (cu->per_cu != NULL); |
13295 | if (cu->per_cu->load_all_dies) | |
5afb4e99 DJ |
13296 | load_all = 1; |
13297 | ||
72bf9492 DJ |
13298 | cu->partial_dies |
13299 | = htab_create_alloc_ex (cu->header.length / 12, | |
13300 | partial_die_hash, | |
13301 | partial_die_eq, | |
13302 | NULL, | |
13303 | &cu->comp_unit_obstack, | |
13304 | hashtab_obstack_allocate, | |
13305 | dummy_obstack_deallocate); | |
13306 | ||
13307 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
13308 | sizeof (struct partial_die_info)); | |
13309 | ||
13310 | while (1) | |
13311 | { | |
13312 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
13313 | ||
13314 | /* A NULL abbrev means the end of a series of children. */ | |
13315 | if (abbrev == NULL) | |
13316 | { | |
13317 | if (--nesting_level == 0) | |
13318 | { | |
13319 | /* PART_DIE was probably the last thing allocated on the | |
13320 | comp_unit_obstack, so we could call obstack_free | |
13321 | here. We don't do that because the waste is small, | |
13322 | and will be cleaned up when we're done with this | |
13323 | compilation unit. This way, we're also more robust | |
13324 | against other users of the comp_unit_obstack. */ | |
13325 | return first_die; | |
13326 | } | |
13327 | info_ptr += bytes_read; | |
13328 | last_die = parent_die; | |
13329 | parent_die = parent_die->die_parent; | |
13330 | continue; | |
13331 | } | |
13332 | ||
98bfdba5 PA |
13333 | /* Check for template arguments. We never save these; if |
13334 | they're seen, we just mark the parent, and go on our way. */ | |
13335 | if (parent_die != NULL | |
13336 | && cu->language == language_cplus | |
13337 | && (abbrev->tag == DW_TAG_template_type_param | |
13338 | || abbrev->tag == DW_TAG_template_value_param)) | |
13339 | { | |
13340 | parent_die->has_template_arguments = 1; | |
13341 | ||
13342 | if (!load_all) | |
13343 | { | |
13344 | /* We don't need a partial DIE for the template argument. */ | |
dee91e82 | 13345 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
13346 | continue; |
13347 | } | |
13348 | } | |
13349 | ||
0d99eb77 | 13350 | /* We only recurse into c++ subprograms looking for template arguments. |
98bfdba5 PA |
13351 | Skip their other children. */ |
13352 | if (!load_all | |
13353 | && cu->language == language_cplus | |
13354 | && parent_die != NULL | |
13355 | && parent_die->tag == DW_TAG_subprogram) | |
13356 | { | |
dee91e82 | 13357 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
13358 | continue; |
13359 | } | |
13360 | ||
5afb4e99 DJ |
13361 | /* Check whether this DIE is interesting enough to save. Normally |
13362 | we would not be interested in members here, but there may be | |
13363 | later variables referencing them via DW_AT_specification (for | |
13364 | static members). */ | |
13365 | if (!load_all | |
13366 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 13367 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
13368 | && abbrev->tag != DW_TAG_enumerator |
13369 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 13370 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 13371 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 13372 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 13373 | && abbrev->tag != DW_TAG_module |
95554aad TT |
13374 | && abbrev->tag != DW_TAG_member |
13375 | && abbrev->tag != DW_TAG_imported_unit) | |
72bf9492 DJ |
13376 | { |
13377 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 13378 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
72bf9492 DJ |
13379 | continue; |
13380 | } | |
13381 | ||
dee91e82 DE |
13382 | info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read, |
13383 | info_ptr); | |
72bf9492 DJ |
13384 | |
13385 | /* This two-pass algorithm for processing partial symbols has a | |
13386 | high cost in cache pressure. Thus, handle some simple cases | |
13387 | here which cover the majority of C partial symbols. DIEs | |
13388 | which neither have specification tags in them, nor could have | |
13389 | specification tags elsewhere pointing at them, can simply be | |
13390 | processed and discarded. | |
13391 | ||
13392 | This segment is also optional; scan_partial_symbols and | |
13393 | add_partial_symbol will handle these DIEs if we chain | |
13394 | them in normally. When compilers which do not emit large | |
13395 | quantities of duplicate debug information are more common, | |
13396 | this code can probably be removed. */ | |
13397 | ||
13398 | /* Any complete simple types at the top level (pretty much all | |
13399 | of them, for a language without namespaces), can be processed | |
13400 | directly. */ | |
13401 | if (parent_die == NULL | |
13402 | && part_die->has_specification == 0 | |
13403 | && part_die->is_declaration == 0 | |
d8228535 | 13404 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
13405 | || part_die->tag == DW_TAG_base_type |
13406 | || part_die->tag == DW_TAG_subrange_type)) | |
13407 | { | |
13408 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 13409 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 13410 | VAR_DOMAIN, LOC_TYPEDEF, |
bb5ed363 DE |
13411 | &objfile->static_psymbols, |
13412 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
dee91e82 | 13413 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
13414 | continue; |
13415 | } | |
13416 | ||
d8228535 JK |
13417 | /* The exception for DW_TAG_typedef with has_children above is |
13418 | a workaround of GCC PR debug/47510. In the case of this complaint | |
13419 | type_name_no_tag_or_error will error on such types later. | |
13420 | ||
13421 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
13422 | it could not find the child DIEs referenced later, this is checked | |
13423 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
13424 | ||
13425 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
13426 | complaint (&symfile_complaints, | |
13427 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
13428 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 13429 | part_die->offset.sect_off, objfile->name); |
d8228535 | 13430 | |
72bf9492 DJ |
13431 | /* If we're at the second level, and we're an enumerator, and |
13432 | our parent has no specification (meaning possibly lives in a | |
13433 | namespace elsewhere), then we can add the partial symbol now | |
13434 | instead of queueing it. */ | |
13435 | if (part_die->tag == DW_TAG_enumerator | |
13436 | && parent_die != NULL | |
13437 | && parent_die->die_parent == NULL | |
13438 | && parent_die->tag == DW_TAG_enumeration_type | |
13439 | && parent_die->has_specification == 0) | |
13440 | { | |
13441 | if (part_die->name == NULL) | |
3e43a32a MS |
13442 | complaint (&symfile_complaints, |
13443 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 13444 | else if (building_psymtab) |
04a679b8 | 13445 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 13446 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
13447 | (cu->language == language_cplus |
13448 | || cu->language == language_java) | |
bb5ed363 DE |
13449 | ? &objfile->global_psymbols |
13450 | : &objfile->static_psymbols, | |
13451 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
72bf9492 | 13452 | |
dee91e82 | 13453 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
13454 | continue; |
13455 | } | |
13456 | ||
13457 | /* We'll save this DIE so link it in. */ | |
13458 | part_die->die_parent = parent_die; | |
13459 | part_die->die_sibling = NULL; | |
13460 | part_die->die_child = NULL; | |
13461 | ||
13462 | if (last_die && last_die == parent_die) | |
13463 | last_die->die_child = part_die; | |
13464 | else if (last_die) | |
13465 | last_die->die_sibling = part_die; | |
13466 | ||
13467 | last_die = part_die; | |
13468 | ||
13469 | if (first_die == NULL) | |
13470 | first_die = part_die; | |
13471 | ||
13472 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
13473 | find interesting need to be in the hash table, because we | |
13474 | also have the parent/sibling/child chains; only those that we | |
13475 | might refer to by offset later during partial symbol reading. | |
13476 | ||
13477 | For now this means things that might have be the target of a | |
13478 | DW_AT_specification, DW_AT_abstract_origin, or | |
13479 | DW_AT_extension. DW_AT_extension will refer only to | |
13480 | namespaces; DW_AT_abstract_origin refers to functions (and | |
13481 | many things under the function DIE, but we do not recurse | |
13482 | into function DIEs during partial symbol reading) and | |
13483 | possibly variables as well; DW_AT_specification refers to | |
13484 | declarations. Declarations ought to have the DW_AT_declaration | |
13485 | flag. It happens that GCC forgets to put it in sometimes, but | |
13486 | only for functions, not for types. | |
13487 | ||
13488 | Adding more things than necessary to the hash table is harmless | |
13489 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
13490 | wasted time in find_partial_die, when we reread the compilation |
13491 | unit with load_all_dies set. */ | |
72bf9492 | 13492 | |
5afb4e99 | 13493 | if (load_all |
72929c62 | 13494 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 13495 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
13496 | || abbrev->tag == DW_TAG_variable |
13497 | || abbrev->tag == DW_TAG_namespace | |
13498 | || part_die->is_declaration) | |
13499 | { | |
13500 | void **slot; | |
13501 | ||
13502 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
b64f50a1 | 13503 | part_die->offset.sect_off, INSERT); |
72bf9492 DJ |
13504 | *slot = part_die; |
13505 | } | |
13506 | ||
13507 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
13508 | sizeof (struct partial_die_info)); | |
13509 | ||
13510 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 13511 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
13512 | languages we have to, so that we can get at method physnames |
13513 | to infer fully qualified class names, for DW_AT_specification, | |
13514 | and for C++ template arguments. For C++, we also look one level | |
13515 | inside functions to find template arguments (if the name of the | |
13516 | function does not already contain the template arguments). | |
bc30ff58 JB |
13517 | |
13518 | For Ada, we need to scan the children of subprograms and lexical | |
13519 | blocks as well because Ada allows the definition of nested | |
13520 | entities that could be interesting for the debugger, such as | |
13521 | nested subprograms for instance. */ | |
72bf9492 | 13522 | if (last_die->has_children |
5afb4e99 DJ |
13523 | && (load_all |
13524 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 13525 | || last_die->tag == DW_TAG_module |
72bf9492 | 13526 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
13527 | || (cu->language == language_cplus |
13528 | && last_die->tag == DW_TAG_subprogram | |
13529 | && (last_die->name == NULL | |
13530 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
13531 | || (cu->language != language_c |
13532 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 13533 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 13534 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
13535 | || last_die->tag == DW_TAG_union_type)) |
13536 | || (cu->language == language_ada | |
13537 | && (last_die->tag == DW_TAG_subprogram | |
13538 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
13539 | { |
13540 | nesting_level++; | |
13541 | parent_die = last_die; | |
13542 | continue; | |
13543 | } | |
13544 | ||
13545 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 13546 | info_ptr = locate_pdi_sibling (reader, last_die, info_ptr); |
72bf9492 DJ |
13547 | |
13548 | /* Back to the top, do it again. */ | |
13549 | } | |
13550 | } | |
13551 | ||
c906108c SS |
13552 | /* Read a minimal amount of information into the minimal die structure. */ |
13553 | ||
fe1b8b76 | 13554 | static gdb_byte * |
dee91e82 DE |
13555 | read_partial_die (const struct die_reader_specs *reader, |
13556 | struct partial_die_info *part_die, | |
13557 | struct abbrev_info *abbrev, unsigned int abbrev_len, | |
13558 | gdb_byte *info_ptr) | |
c906108c | 13559 | { |
dee91e82 | 13560 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 13561 | struct objfile *objfile = cu->objfile; |
dee91e82 | 13562 | gdb_byte *buffer = reader->buffer; |
fa238c03 | 13563 | unsigned int i; |
c906108c | 13564 | struct attribute attr; |
c5aa993b | 13565 | int has_low_pc_attr = 0; |
c906108c | 13566 | int has_high_pc_attr = 0; |
91da1414 | 13567 | int high_pc_relative = 0; |
c906108c | 13568 | |
72bf9492 | 13569 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 13570 | |
b64f50a1 | 13571 | part_die->offset.sect_off = info_ptr - buffer; |
72bf9492 DJ |
13572 | |
13573 | info_ptr += abbrev_len; | |
13574 | ||
13575 | if (abbrev == NULL) | |
13576 | return info_ptr; | |
13577 | ||
c906108c SS |
13578 | part_die->tag = abbrev->tag; |
13579 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
13580 | |
13581 | for (i = 0; i < abbrev->num_attrs; ++i) | |
13582 | { | |
dee91e82 | 13583 | info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
c906108c SS |
13584 | |
13585 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 13586 | partial symbol table. */ |
c906108c SS |
13587 | switch (attr.name) |
13588 | { | |
13589 | case DW_AT_name: | |
71c25dea TT |
13590 | switch (part_die->tag) |
13591 | { | |
13592 | case DW_TAG_compile_unit: | |
95554aad | 13593 | case DW_TAG_partial_unit: |
348e048f | 13594 | case DW_TAG_type_unit: |
71c25dea TT |
13595 | /* Compilation units have a DW_AT_name that is a filename, not |
13596 | a source language identifier. */ | |
13597 | case DW_TAG_enumeration_type: | |
13598 | case DW_TAG_enumerator: | |
13599 | /* These tags always have simple identifiers already; no need | |
13600 | to canonicalize them. */ | |
13601 | part_die->name = DW_STRING (&attr); | |
13602 | break; | |
13603 | default: | |
13604 | part_die->name | |
13605 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
bb5ed363 | 13606 | &objfile->objfile_obstack); |
71c25dea TT |
13607 | break; |
13608 | } | |
c906108c | 13609 | break; |
31ef98ae | 13610 | case DW_AT_linkage_name: |
c906108c | 13611 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
13612 | /* Note that both forms of linkage name might appear. We |
13613 | assume they will be the same, and we only store the last | |
13614 | one we see. */ | |
94af9270 KS |
13615 | if (cu->language == language_ada) |
13616 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 13617 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
13618 | break; |
13619 | case DW_AT_low_pc: | |
13620 | has_low_pc_attr = 1; | |
13621 | part_die->lowpc = DW_ADDR (&attr); | |
13622 | break; | |
13623 | case DW_AT_high_pc: | |
13624 | has_high_pc_attr = 1; | |
3019eac3 DE |
13625 | if (attr.form == DW_FORM_addr |
13626 | || attr.form == DW_FORM_GNU_addr_index) | |
91da1414 MW |
13627 | part_die->highpc = DW_ADDR (&attr); |
13628 | else | |
13629 | { | |
13630 | high_pc_relative = 1; | |
13631 | part_die->highpc = DW_UNSND (&attr); | |
13632 | } | |
c906108c SS |
13633 | break; |
13634 | case DW_AT_location: | |
0963b4bd | 13635 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
13636 | if (attr_form_is_block (&attr)) |
13637 | { | |
95554aad | 13638 | part_die->d.locdesc = DW_BLOCK (&attr); |
8e19ed76 | 13639 | } |
3690dd37 | 13640 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 13641 | { |
4d3c2250 | 13642 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
13643 | } |
13644 | else | |
13645 | { | |
4d3c2250 KB |
13646 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
13647 | "partial symbol information"); | |
8e19ed76 | 13648 | } |
c906108c | 13649 | break; |
c906108c SS |
13650 | case DW_AT_external: |
13651 | part_die->is_external = DW_UNSND (&attr); | |
13652 | break; | |
13653 | case DW_AT_declaration: | |
13654 | part_die->is_declaration = DW_UNSND (&attr); | |
13655 | break; | |
13656 | case DW_AT_type: | |
13657 | part_die->has_type = 1; | |
13658 | break; | |
13659 | case DW_AT_abstract_origin: | |
13660 | case DW_AT_specification: | |
72bf9492 DJ |
13661 | case DW_AT_extension: |
13662 | part_die->has_specification = 1; | |
c764a876 | 13663 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
36586728 TT |
13664 | part_die->spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt |
13665 | || cu->per_cu->is_dwz); | |
c906108c SS |
13666 | break; |
13667 | case DW_AT_sibling: | |
13668 | /* Ignore absolute siblings, they might point outside of | |
13669 | the current compile unit. */ | |
13670 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
13671 | complaint (&symfile_complaints, |
13672 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 13673 | else |
b64f50a1 | 13674 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
c906108c | 13675 | break; |
fa4028e9 JB |
13676 | case DW_AT_byte_size: |
13677 | part_die->has_byte_size = 1; | |
13678 | break; | |
68511cec CES |
13679 | case DW_AT_calling_convention: |
13680 | /* DWARF doesn't provide a way to identify a program's source-level | |
13681 | entry point. DW_AT_calling_convention attributes are only meant | |
13682 | to describe functions' calling conventions. | |
13683 | ||
13684 | However, because it's a necessary piece of information in | |
13685 | Fortran, and because DW_CC_program is the only piece of debugging | |
13686 | information whose definition refers to a 'main program' at all, | |
13687 | several compilers have begun marking Fortran main programs with | |
13688 | DW_CC_program --- even when those functions use the standard | |
13689 | calling conventions. | |
13690 | ||
13691 | So until DWARF specifies a way to provide this information and | |
13692 | compilers pick up the new representation, we'll support this | |
13693 | practice. */ | |
13694 | if (DW_UNSND (&attr) == DW_CC_program | |
13695 | && cu->language == language_fortran) | |
01f8c46d JK |
13696 | { |
13697 | set_main_name (part_die->name); | |
13698 | ||
13699 | /* As this DIE has a static linkage the name would be difficult | |
13700 | to look up later. */ | |
13701 | language_of_main = language_fortran; | |
13702 | } | |
68511cec | 13703 | break; |
481860b3 GB |
13704 | case DW_AT_inline: |
13705 | if (DW_UNSND (&attr) == DW_INL_inlined | |
13706 | || DW_UNSND (&attr) == DW_INL_declared_inlined) | |
13707 | part_die->may_be_inlined = 1; | |
13708 | break; | |
95554aad TT |
13709 | |
13710 | case DW_AT_import: | |
13711 | if (part_die->tag == DW_TAG_imported_unit) | |
36586728 TT |
13712 | { |
13713 | part_die->d.offset = dwarf2_get_ref_die_offset (&attr); | |
13714 | part_die->is_dwz = (attr.form == DW_FORM_GNU_ref_alt | |
13715 | || cu->per_cu->is_dwz); | |
13716 | } | |
95554aad TT |
13717 | break; |
13718 | ||
c906108c SS |
13719 | default: |
13720 | break; | |
13721 | } | |
13722 | } | |
13723 | ||
91da1414 MW |
13724 | if (high_pc_relative) |
13725 | part_die->highpc += part_die->lowpc; | |
13726 | ||
9373cf26 JK |
13727 | if (has_low_pc_attr && has_high_pc_attr) |
13728 | { | |
13729 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
13730 | eliminate duplicate copies of functions and vtables and such. | |
13731 | The linker will arbitrarily choose one and discard the others. | |
13732 | The AT_*_pc values for such functions refer to local labels in | |
13733 | these sections. If the section from that file was discarded, the | |
13734 | labels are not in the output, so the relocs get a value of 0. | |
13735 | If this is a discarded function, mark the pc bounds as invalid, | |
13736 | so that GDB will ignore it. */ | |
13737 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
13738 | { | |
bb5ed363 | 13739 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
13740 | |
13741 | complaint (&symfile_complaints, | |
13742 | _("DW_AT_low_pc %s is zero " | |
13743 | "for DIE at 0x%x [in module %s]"), | |
13744 | paddress (gdbarch, part_die->lowpc), | |
b64f50a1 | 13745 | part_die->offset.sect_off, objfile->name); |
9373cf26 JK |
13746 | } |
13747 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
13748 | else if (part_die->lowpc >= part_die->highpc) | |
13749 | { | |
bb5ed363 | 13750 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
13751 | |
13752 | complaint (&symfile_complaints, | |
13753 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
13754 | "for DIE at 0x%x [in module %s]"), | |
13755 | paddress (gdbarch, part_die->lowpc), | |
13756 | paddress (gdbarch, part_die->highpc), | |
b64f50a1 | 13757 | part_die->offset.sect_off, objfile->name); |
9373cf26 JK |
13758 | } |
13759 | else | |
13760 | part_die->has_pc_info = 1; | |
13761 | } | |
85cbf3d3 | 13762 | |
c906108c SS |
13763 | return info_ptr; |
13764 | } | |
13765 | ||
72bf9492 DJ |
13766 | /* Find a cached partial DIE at OFFSET in CU. */ |
13767 | ||
13768 | static struct partial_die_info * | |
b64f50a1 | 13769 | find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
13770 | { |
13771 | struct partial_die_info *lookup_die = NULL; | |
13772 | struct partial_die_info part_die; | |
13773 | ||
13774 | part_die.offset = offset; | |
b64f50a1 JK |
13775 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, |
13776 | offset.sect_off); | |
72bf9492 | 13777 | |
72bf9492 DJ |
13778 | return lookup_die; |
13779 | } | |
13780 | ||
348e048f DE |
13781 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
13782 | except in the case of .debug_types DIEs which do not reference | |
13783 | outside their CU (they do however referencing other types via | |
55f1336d | 13784 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
13785 | |
13786 | static struct partial_die_info * | |
36586728 | 13787 | find_partial_die (sect_offset offset, int offset_in_dwz, struct dwarf2_cu *cu) |
72bf9492 | 13788 | { |
bb5ed363 | 13789 | struct objfile *objfile = cu->objfile; |
5afb4e99 DJ |
13790 | struct dwarf2_per_cu_data *per_cu = NULL; |
13791 | struct partial_die_info *pd = NULL; | |
72bf9492 | 13792 | |
36586728 TT |
13793 | if (offset_in_dwz == cu->per_cu->is_dwz |
13794 | && offset_in_cu_p (&cu->header, offset)) | |
5afb4e99 DJ |
13795 | { |
13796 | pd = find_partial_die_in_comp_unit (offset, cu); | |
13797 | if (pd != NULL) | |
13798 | return pd; | |
0d99eb77 DE |
13799 | /* We missed recording what we needed. |
13800 | Load all dies and try again. */ | |
13801 | per_cu = cu->per_cu; | |
5afb4e99 | 13802 | } |
0d99eb77 DE |
13803 | else |
13804 | { | |
13805 | /* TUs don't reference other CUs/TUs (except via type signatures). */ | |
3019eac3 | 13806 | if (cu->per_cu->is_debug_types) |
0d99eb77 DE |
13807 | { |
13808 | error (_("Dwarf Error: Type Unit at offset 0x%lx contains" | |
13809 | " external reference to offset 0x%lx [in module %s].\n"), | |
13810 | (long) cu->header.offset.sect_off, (long) offset.sect_off, | |
13811 | bfd_get_filename (objfile->obfd)); | |
13812 | } | |
36586728 TT |
13813 | per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz, |
13814 | objfile); | |
72bf9492 | 13815 | |
0d99eb77 DE |
13816 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
13817 | load_partial_comp_unit (per_cu); | |
ae038cb0 | 13818 | |
0d99eb77 DE |
13819 | per_cu->cu->last_used = 0; |
13820 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
13821 | } | |
5afb4e99 | 13822 | |
dee91e82 DE |
13823 | /* If we didn't find it, and not all dies have been loaded, |
13824 | load them all and try again. */ | |
13825 | ||
5afb4e99 DJ |
13826 | if (pd == NULL && per_cu->load_all_dies == 0) |
13827 | { | |
5afb4e99 | 13828 | per_cu->load_all_dies = 1; |
fd820528 DE |
13829 | |
13830 | /* This is nasty. When we reread the DIEs, somewhere up the call chain | |
13831 | THIS_CU->cu may already be in use. So we can't just free it and | |
13832 | replace its DIEs with the ones we read in. Instead, we leave those | |
13833 | DIEs alone (which can still be in use, e.g. in scan_partial_symbols), | |
13834 | and clobber THIS_CU->cu->partial_dies with the hash table for the new | |
13835 | set. */ | |
dee91e82 | 13836 | load_partial_comp_unit (per_cu); |
5afb4e99 DJ |
13837 | |
13838 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
13839 | } | |
13840 | ||
13841 | if (pd == NULL) | |
13842 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
13843 | _("could not find partial DIE 0x%x " |
13844 | "in cache [from module %s]\n"), | |
b64f50a1 | 13845 | offset.sect_off, bfd_get_filename (objfile->obfd)); |
5afb4e99 | 13846 | return pd; |
72bf9492 DJ |
13847 | } |
13848 | ||
abc72ce4 DE |
13849 | /* See if we can figure out if the class lives in a namespace. We do |
13850 | this by looking for a member function; its demangled name will | |
13851 | contain namespace info, if there is any. */ | |
13852 | ||
13853 | static void | |
13854 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
13855 | struct dwarf2_cu *cu) | |
13856 | { | |
13857 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
13858 | what template types look like, because the demangler | |
13859 | frequently doesn't give the same name as the debug info. We | |
13860 | could fix this by only using the demangled name to get the | |
13861 | prefix (but see comment in read_structure_type). */ | |
13862 | ||
13863 | struct partial_die_info *real_pdi; | |
13864 | struct partial_die_info *child_pdi; | |
13865 | ||
13866 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
13867 | we should not do this. We'll prepend the parent's fully qualified | |
13868 | name when we create the partial symbol. */ | |
13869 | ||
13870 | real_pdi = struct_pdi; | |
13871 | while (real_pdi->has_specification) | |
36586728 TT |
13872 | real_pdi = find_partial_die (real_pdi->spec_offset, |
13873 | real_pdi->spec_is_dwz, cu); | |
abc72ce4 DE |
13874 | |
13875 | if (real_pdi->die_parent != NULL) | |
13876 | return; | |
13877 | ||
13878 | for (child_pdi = struct_pdi->die_child; | |
13879 | child_pdi != NULL; | |
13880 | child_pdi = child_pdi->die_sibling) | |
13881 | { | |
13882 | if (child_pdi->tag == DW_TAG_subprogram | |
13883 | && child_pdi->linkage_name != NULL) | |
13884 | { | |
13885 | char *actual_class_name | |
13886 | = language_class_name_from_physname (cu->language_defn, | |
13887 | child_pdi->linkage_name); | |
13888 | if (actual_class_name != NULL) | |
13889 | { | |
13890 | struct_pdi->name | |
10f0c4bb TT |
13891 | = obstack_copy0 (&cu->objfile->objfile_obstack, |
13892 | actual_class_name, | |
13893 | strlen (actual_class_name)); | |
abc72ce4 DE |
13894 | xfree (actual_class_name); |
13895 | } | |
13896 | break; | |
13897 | } | |
13898 | } | |
13899 | } | |
13900 | ||
72bf9492 DJ |
13901 | /* Adjust PART_DIE before generating a symbol for it. This function |
13902 | may set the is_external flag or change the DIE's name. */ | |
13903 | ||
13904 | static void | |
13905 | fixup_partial_die (struct partial_die_info *part_die, | |
13906 | struct dwarf2_cu *cu) | |
13907 | { | |
abc72ce4 DE |
13908 | /* Once we've fixed up a die, there's no point in doing so again. |
13909 | This also avoids a memory leak if we were to call | |
13910 | guess_partial_die_structure_name multiple times. */ | |
13911 | if (part_die->fixup_called) | |
13912 | return; | |
13913 | ||
72bf9492 DJ |
13914 | /* If we found a reference attribute and the DIE has no name, try |
13915 | to find a name in the referred to DIE. */ | |
13916 | ||
13917 | if (part_die->name == NULL && part_die->has_specification) | |
13918 | { | |
13919 | struct partial_die_info *spec_die; | |
72bf9492 | 13920 | |
36586728 TT |
13921 | spec_die = find_partial_die (part_die->spec_offset, |
13922 | part_die->spec_is_dwz, cu); | |
72bf9492 | 13923 | |
10b3939b | 13924 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
13925 | |
13926 | if (spec_die->name) | |
13927 | { | |
13928 | part_die->name = spec_die->name; | |
13929 | ||
13930 | /* Copy DW_AT_external attribute if it is set. */ | |
13931 | if (spec_die->is_external) | |
13932 | part_die->is_external = spec_die->is_external; | |
13933 | } | |
13934 | } | |
13935 | ||
13936 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
13937 | |
13938 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 13939 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 13940 | |
abc72ce4 DE |
13941 | /* If there is no parent die to provide a namespace, and there are |
13942 | children, see if we can determine the namespace from their linkage | |
122d1940 | 13943 | name. */ |
abc72ce4 | 13944 | if (cu->language == language_cplus |
8b70b953 | 13945 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
13946 | && part_die->die_parent == NULL |
13947 | && part_die->has_children | |
13948 | && (part_die->tag == DW_TAG_class_type | |
13949 | || part_die->tag == DW_TAG_structure_type | |
13950 | || part_die->tag == DW_TAG_union_type)) | |
13951 | guess_partial_die_structure_name (part_die, cu); | |
13952 | ||
53832f31 TT |
13953 | /* GCC might emit a nameless struct or union that has a linkage |
13954 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
13955 | if (part_die->name == NULL | |
96408a79 SA |
13956 | && (part_die->tag == DW_TAG_class_type |
13957 | || part_die->tag == DW_TAG_interface_type | |
13958 | || part_die->tag == DW_TAG_structure_type | |
13959 | || part_die->tag == DW_TAG_union_type) | |
53832f31 TT |
13960 | && part_die->linkage_name != NULL) |
13961 | { | |
13962 | char *demangled; | |
13963 | ||
13964 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
13965 | if (demangled) | |
13966 | { | |
96408a79 SA |
13967 | const char *base; |
13968 | ||
13969 | /* Strip any leading namespaces/classes, keep only the base name. | |
13970 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
13971 | base = strrchr (demangled, ':'); | |
13972 | if (base && base > demangled && base[-1] == ':') | |
13973 | base++; | |
13974 | else | |
13975 | base = demangled; | |
13976 | ||
10f0c4bb TT |
13977 | part_die->name = obstack_copy0 (&cu->objfile->objfile_obstack, |
13978 | base, strlen (base)); | |
53832f31 TT |
13979 | xfree (demangled); |
13980 | } | |
13981 | } | |
13982 | ||
abc72ce4 | 13983 | part_die->fixup_called = 1; |
72bf9492 DJ |
13984 | } |
13985 | ||
a8329558 | 13986 | /* Read an attribute value described by an attribute form. */ |
c906108c | 13987 | |
fe1b8b76 | 13988 | static gdb_byte * |
dee91e82 DE |
13989 | read_attribute_value (const struct die_reader_specs *reader, |
13990 | struct attribute *attr, unsigned form, | |
13991 | gdb_byte *info_ptr) | |
c906108c | 13992 | { |
dee91e82 DE |
13993 | struct dwarf2_cu *cu = reader->cu; |
13994 | bfd *abfd = reader->abfd; | |
e7c27a73 | 13995 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
13996 | unsigned int bytes_read; |
13997 | struct dwarf_block *blk; | |
13998 | ||
a8329558 KW |
13999 | attr->form = form; |
14000 | switch (form) | |
c906108c | 14001 | { |
c906108c | 14002 | case DW_FORM_ref_addr: |
ae411497 | 14003 | if (cu->header.version == 2) |
4568ecf9 | 14004 | DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
ae411497 | 14005 | else |
4568ecf9 DE |
14006 | DW_UNSND (attr) = read_offset (abfd, info_ptr, |
14007 | &cu->header, &bytes_read); | |
ae411497 TT |
14008 | info_ptr += bytes_read; |
14009 | break; | |
36586728 TT |
14010 | case DW_FORM_GNU_ref_alt: |
14011 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
14012 | info_ptr += bytes_read; | |
14013 | break; | |
ae411497 | 14014 | case DW_FORM_addr: |
e7c27a73 | 14015 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 14016 | info_ptr += bytes_read; |
c906108c SS |
14017 | break; |
14018 | case DW_FORM_block2: | |
7b5a2f43 | 14019 | blk = dwarf_alloc_block (cu); |
c906108c SS |
14020 | blk->size = read_2_bytes (abfd, info_ptr); |
14021 | info_ptr += 2; | |
14022 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
14023 | info_ptr += blk->size; | |
14024 | DW_BLOCK (attr) = blk; | |
14025 | break; | |
14026 | case DW_FORM_block4: | |
7b5a2f43 | 14027 | blk = dwarf_alloc_block (cu); |
c906108c SS |
14028 | blk->size = read_4_bytes (abfd, info_ptr); |
14029 | info_ptr += 4; | |
14030 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
14031 | info_ptr += blk->size; | |
14032 | DW_BLOCK (attr) = blk; | |
14033 | break; | |
14034 | case DW_FORM_data2: | |
14035 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
14036 | info_ptr += 2; | |
14037 | break; | |
14038 | case DW_FORM_data4: | |
14039 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
14040 | info_ptr += 4; | |
14041 | break; | |
14042 | case DW_FORM_data8: | |
14043 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
14044 | info_ptr += 8; | |
14045 | break; | |
2dc7f7b3 TT |
14046 | case DW_FORM_sec_offset: |
14047 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
14048 | info_ptr += bytes_read; | |
14049 | break; | |
c906108c | 14050 | case DW_FORM_string: |
9b1c24c8 | 14051 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 14052 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
14053 | info_ptr += bytes_read; |
14054 | break; | |
4bdf3d34 | 14055 | case DW_FORM_strp: |
36586728 TT |
14056 | if (!cu->per_cu->is_dwz) |
14057 | { | |
14058 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
14059 | &bytes_read); | |
14060 | DW_STRING_IS_CANONICAL (attr) = 0; | |
14061 | info_ptr += bytes_read; | |
14062 | break; | |
14063 | } | |
14064 | /* FALLTHROUGH */ | |
14065 | case DW_FORM_GNU_strp_alt: | |
14066 | { | |
14067 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
14068 | LONGEST str_offset = read_offset (abfd, info_ptr, cu_header, | |
14069 | &bytes_read); | |
14070 | ||
14071 | DW_STRING (attr) = read_indirect_string_from_dwz (dwz, str_offset); | |
14072 | DW_STRING_IS_CANONICAL (attr) = 0; | |
14073 | info_ptr += bytes_read; | |
14074 | } | |
4bdf3d34 | 14075 | break; |
2dc7f7b3 | 14076 | case DW_FORM_exprloc: |
c906108c | 14077 | case DW_FORM_block: |
7b5a2f43 | 14078 | blk = dwarf_alloc_block (cu); |
c906108c SS |
14079 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
14080 | info_ptr += bytes_read; | |
14081 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
14082 | info_ptr += blk->size; | |
14083 | DW_BLOCK (attr) = blk; | |
14084 | break; | |
14085 | case DW_FORM_block1: | |
7b5a2f43 | 14086 | blk = dwarf_alloc_block (cu); |
c906108c SS |
14087 | blk->size = read_1_byte (abfd, info_ptr); |
14088 | info_ptr += 1; | |
14089 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
14090 | info_ptr += blk->size; | |
14091 | DW_BLOCK (attr) = blk; | |
14092 | break; | |
14093 | case DW_FORM_data1: | |
14094 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
14095 | info_ptr += 1; | |
14096 | break; | |
14097 | case DW_FORM_flag: | |
14098 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
14099 | info_ptr += 1; | |
14100 | break; | |
2dc7f7b3 TT |
14101 | case DW_FORM_flag_present: |
14102 | DW_UNSND (attr) = 1; | |
14103 | break; | |
c906108c SS |
14104 | case DW_FORM_sdata: |
14105 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
14106 | info_ptr += bytes_read; | |
14107 | break; | |
14108 | case DW_FORM_udata: | |
14109 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
14110 | info_ptr += bytes_read; | |
14111 | break; | |
14112 | case DW_FORM_ref1: | |
4568ecf9 DE |
14113 | DW_UNSND (attr) = (cu->header.offset.sect_off |
14114 | + read_1_byte (abfd, info_ptr)); | |
c906108c SS |
14115 | info_ptr += 1; |
14116 | break; | |
14117 | case DW_FORM_ref2: | |
4568ecf9 DE |
14118 | DW_UNSND (attr) = (cu->header.offset.sect_off |
14119 | + read_2_bytes (abfd, info_ptr)); | |
c906108c SS |
14120 | info_ptr += 2; |
14121 | break; | |
14122 | case DW_FORM_ref4: | |
4568ecf9 DE |
14123 | DW_UNSND (attr) = (cu->header.offset.sect_off |
14124 | + read_4_bytes (abfd, info_ptr)); | |
c906108c SS |
14125 | info_ptr += 4; |
14126 | break; | |
613e1657 | 14127 | case DW_FORM_ref8: |
4568ecf9 DE |
14128 | DW_UNSND (attr) = (cu->header.offset.sect_off |
14129 | + read_8_bytes (abfd, info_ptr)); | |
613e1657 KB |
14130 | info_ptr += 8; |
14131 | break; | |
55f1336d | 14132 | case DW_FORM_ref_sig8: |
348e048f DE |
14133 | /* Convert the signature to something we can record in DW_UNSND |
14134 | for later lookup. | |
14135 | NOTE: This is NULL if the type wasn't found. */ | |
14136 | DW_SIGNATURED_TYPE (attr) = | |
e319fa28 | 14137 | lookup_signatured_type (read_8_bytes (abfd, info_ptr)); |
348e048f DE |
14138 | info_ptr += 8; |
14139 | break; | |
c906108c | 14140 | case DW_FORM_ref_udata: |
4568ecf9 DE |
14141 | DW_UNSND (attr) = (cu->header.offset.sect_off |
14142 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
14143 | info_ptr += bytes_read; |
14144 | break; | |
c906108c | 14145 | case DW_FORM_indirect: |
a8329558 KW |
14146 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
14147 | info_ptr += bytes_read; | |
dee91e82 | 14148 | info_ptr = read_attribute_value (reader, attr, form, info_ptr); |
a8329558 | 14149 | break; |
3019eac3 DE |
14150 | case DW_FORM_GNU_addr_index: |
14151 | if (reader->dwo_file == NULL) | |
14152 | { | |
14153 | /* For now flag a hard error. | |
14154 | Later we can turn this into a complaint. */ | |
14155 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), | |
14156 | dwarf_form_name (form), | |
14157 | bfd_get_filename (abfd)); | |
14158 | } | |
14159 | DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read); | |
14160 | info_ptr += bytes_read; | |
14161 | break; | |
14162 | case DW_FORM_GNU_str_index: | |
14163 | if (reader->dwo_file == NULL) | |
14164 | { | |
14165 | /* For now flag a hard error. | |
14166 | Later we can turn this into a complaint if warranted. */ | |
14167 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), | |
14168 | dwarf_form_name (form), | |
14169 | bfd_get_filename (abfd)); | |
14170 | } | |
14171 | { | |
14172 | ULONGEST str_index = | |
14173 | read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
14174 | ||
14175 | DW_STRING (attr) = read_str_index (reader, cu, str_index); | |
14176 | DW_STRING_IS_CANONICAL (attr) = 0; | |
14177 | info_ptr += bytes_read; | |
14178 | } | |
14179 | break; | |
c906108c | 14180 | default: |
8a3fe4f8 | 14181 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
14182 | dwarf_form_name (form), |
14183 | bfd_get_filename (abfd)); | |
c906108c | 14184 | } |
28e94949 | 14185 | |
36586728 TT |
14186 | /* Super hack. */ |
14187 | if (cu->per_cu->is_dwz && is_ref_attr (attr)) | |
14188 | attr->form = DW_FORM_GNU_ref_alt; | |
14189 | ||
28e94949 JB |
14190 | /* We have seen instances where the compiler tried to emit a byte |
14191 | size attribute of -1 which ended up being encoded as an unsigned | |
14192 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
14193 | an object of this size seems pretty unlikely so we can relatively | |
14194 | safely treat these cases as if the size attribute was invalid and | |
14195 | treat them as zero by default. */ | |
14196 | if (attr->name == DW_AT_byte_size | |
14197 | && form == DW_FORM_data4 | |
14198 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
14199 | { |
14200 | complaint | |
14201 | (&symfile_complaints, | |
43bbcdc2 PH |
14202 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
14203 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
14204 | DW_UNSND (attr) = 0; |
14205 | } | |
28e94949 | 14206 | |
c906108c SS |
14207 | return info_ptr; |
14208 | } | |
14209 | ||
a8329558 KW |
14210 | /* Read an attribute described by an abbreviated attribute. */ |
14211 | ||
fe1b8b76 | 14212 | static gdb_byte * |
dee91e82 DE |
14213 | read_attribute (const struct die_reader_specs *reader, |
14214 | struct attribute *attr, struct attr_abbrev *abbrev, | |
14215 | gdb_byte *info_ptr) | |
a8329558 KW |
14216 | { |
14217 | attr->name = abbrev->name; | |
dee91e82 | 14218 | return read_attribute_value (reader, attr, abbrev->form, info_ptr); |
a8329558 KW |
14219 | } |
14220 | ||
0963b4bd | 14221 | /* Read dwarf information from a buffer. */ |
c906108c SS |
14222 | |
14223 | static unsigned int | |
a1855c1d | 14224 | read_1_byte (bfd *abfd, const gdb_byte *buf) |
c906108c | 14225 | { |
fe1b8b76 | 14226 | return bfd_get_8 (abfd, buf); |
c906108c SS |
14227 | } |
14228 | ||
14229 | static int | |
a1855c1d | 14230 | read_1_signed_byte (bfd *abfd, const gdb_byte *buf) |
c906108c | 14231 | { |
fe1b8b76 | 14232 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
14233 | } |
14234 | ||
14235 | static unsigned int | |
a1855c1d | 14236 | read_2_bytes (bfd *abfd, const gdb_byte *buf) |
c906108c | 14237 | { |
fe1b8b76 | 14238 | return bfd_get_16 (abfd, buf); |
c906108c SS |
14239 | } |
14240 | ||
21ae7a4d | 14241 | static int |
a1855c1d | 14242 | read_2_signed_bytes (bfd *abfd, const gdb_byte *buf) |
21ae7a4d JK |
14243 | { |
14244 | return bfd_get_signed_16 (abfd, buf); | |
14245 | } | |
14246 | ||
c906108c | 14247 | static unsigned int |
a1855c1d | 14248 | read_4_bytes (bfd *abfd, const gdb_byte *buf) |
c906108c | 14249 | { |
fe1b8b76 | 14250 | return bfd_get_32 (abfd, buf); |
c906108c SS |
14251 | } |
14252 | ||
21ae7a4d | 14253 | static int |
a1855c1d | 14254 | read_4_signed_bytes (bfd *abfd, const gdb_byte *buf) |
21ae7a4d JK |
14255 | { |
14256 | return bfd_get_signed_32 (abfd, buf); | |
14257 | } | |
14258 | ||
93311388 | 14259 | static ULONGEST |
a1855c1d | 14260 | read_8_bytes (bfd *abfd, const gdb_byte *buf) |
c906108c | 14261 | { |
fe1b8b76 | 14262 | return bfd_get_64 (abfd, buf); |
c906108c SS |
14263 | } |
14264 | ||
14265 | static CORE_ADDR | |
fe1b8b76 | 14266 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 14267 | unsigned int *bytes_read) |
c906108c | 14268 | { |
e7c27a73 | 14269 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
14270 | CORE_ADDR retval = 0; |
14271 | ||
107d2387 | 14272 | if (cu_header->signed_addr_p) |
c906108c | 14273 | { |
107d2387 AC |
14274 | switch (cu_header->addr_size) |
14275 | { | |
14276 | case 2: | |
fe1b8b76 | 14277 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
14278 | break; |
14279 | case 4: | |
fe1b8b76 | 14280 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
14281 | break; |
14282 | case 8: | |
fe1b8b76 | 14283 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
14284 | break; |
14285 | default: | |
8e65ff28 | 14286 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 14287 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 14288 | bfd_get_filename (abfd)); |
107d2387 AC |
14289 | } |
14290 | } | |
14291 | else | |
14292 | { | |
14293 | switch (cu_header->addr_size) | |
14294 | { | |
14295 | case 2: | |
fe1b8b76 | 14296 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
14297 | break; |
14298 | case 4: | |
fe1b8b76 | 14299 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
14300 | break; |
14301 | case 8: | |
fe1b8b76 | 14302 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
14303 | break; |
14304 | default: | |
8e65ff28 | 14305 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
14306 | _("read_address: bad switch, " |
14307 | "unsigned [in module %s]"), | |
659b0389 | 14308 | bfd_get_filename (abfd)); |
107d2387 | 14309 | } |
c906108c | 14310 | } |
64367e0a | 14311 | |
107d2387 AC |
14312 | *bytes_read = cu_header->addr_size; |
14313 | return retval; | |
c906108c SS |
14314 | } |
14315 | ||
f7ef9339 | 14316 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
14317 | specification allows the initial length to take up either 4 bytes |
14318 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
14319 | bytes describe the length and all offsets will be 8 bytes in length | |
14320 | instead of 4. | |
14321 | ||
f7ef9339 KB |
14322 | An older, non-standard 64-bit format is also handled by this |
14323 | function. The older format in question stores the initial length | |
14324 | as an 8-byte quantity without an escape value. Lengths greater | |
14325 | than 2^32 aren't very common which means that the initial 4 bytes | |
14326 | is almost always zero. Since a length value of zero doesn't make | |
14327 | sense for the 32-bit format, this initial zero can be considered to | |
14328 | be an escape value which indicates the presence of the older 64-bit | |
14329 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
14330 | greater than 4GB. If it becomes necessary to handle lengths |
14331 | somewhat larger than 4GB, we could allow other small values (such | |
14332 | as the non-sensical values of 1, 2, and 3) to also be used as | |
14333 | escape values indicating the presence of the old format. | |
f7ef9339 | 14334 | |
917c78fc MK |
14335 | The value returned via bytes_read should be used to increment the |
14336 | relevant pointer after calling read_initial_length(). | |
c764a876 | 14337 | |
613e1657 KB |
14338 | [ Note: read_initial_length() and read_offset() are based on the |
14339 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 14340 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
14341 | from: |
14342 | ||
f7ef9339 | 14343 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 14344 | |
613e1657 KB |
14345 | This document is only a draft and is subject to change. (So beware.) |
14346 | ||
f7ef9339 | 14347 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
14348 | determined empirically by examining 64-bit ELF files produced by |
14349 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
14350 | |
14351 | - Kevin, July 16, 2002 | |
613e1657 KB |
14352 | ] */ |
14353 | ||
14354 | static LONGEST | |
c764a876 | 14355 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 14356 | { |
fe1b8b76 | 14357 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 14358 | |
dd373385 | 14359 | if (length == 0xffffffff) |
613e1657 | 14360 | { |
fe1b8b76 | 14361 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 14362 | *bytes_read = 12; |
613e1657 | 14363 | } |
dd373385 | 14364 | else if (length == 0) |
f7ef9339 | 14365 | { |
dd373385 | 14366 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 14367 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 14368 | *bytes_read = 8; |
f7ef9339 | 14369 | } |
613e1657 KB |
14370 | else |
14371 | { | |
14372 | *bytes_read = 4; | |
613e1657 KB |
14373 | } |
14374 | ||
c764a876 DE |
14375 | return length; |
14376 | } | |
dd373385 | 14377 | |
c764a876 DE |
14378 | /* Cover function for read_initial_length. |
14379 | Returns the length of the object at BUF, and stores the size of the | |
14380 | initial length in *BYTES_READ and stores the size that offsets will be in | |
14381 | *OFFSET_SIZE. | |
14382 | If the initial length size is not equivalent to that specified in | |
14383 | CU_HEADER then issue a complaint. | |
14384 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 14385 | |
c764a876 DE |
14386 | static LONGEST |
14387 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
14388 | const struct comp_unit_head *cu_header, | |
14389 | unsigned int *bytes_read, | |
14390 | unsigned int *offset_size) | |
14391 | { | |
14392 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
14393 | ||
14394 | gdb_assert (cu_header->initial_length_size == 4 | |
14395 | || cu_header->initial_length_size == 8 | |
14396 | || cu_header->initial_length_size == 12); | |
14397 | ||
14398 | if (cu_header->initial_length_size != *bytes_read) | |
14399 | complaint (&symfile_complaints, | |
14400 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 14401 | |
c764a876 | 14402 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 14403 | return length; |
613e1657 KB |
14404 | } |
14405 | ||
14406 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 14407 | given by cu_header->offset_size. */ |
613e1657 KB |
14408 | |
14409 | static LONGEST | |
fe1b8b76 | 14410 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 14411 | unsigned int *bytes_read) |
c764a876 DE |
14412 | { |
14413 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 14414 | |
c764a876 DE |
14415 | *bytes_read = cu_header->offset_size; |
14416 | return offset; | |
14417 | } | |
14418 | ||
14419 | /* Read an offset from the data stream. */ | |
14420 | ||
14421 | static LONGEST | |
14422 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
14423 | { |
14424 | LONGEST retval = 0; | |
14425 | ||
c764a876 | 14426 | switch (offset_size) |
613e1657 KB |
14427 | { |
14428 | case 4: | |
fe1b8b76 | 14429 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
14430 | break; |
14431 | case 8: | |
fe1b8b76 | 14432 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
14433 | break; |
14434 | default: | |
8e65ff28 | 14435 | internal_error (__FILE__, __LINE__, |
c764a876 | 14436 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 14437 | bfd_get_filename (abfd)); |
613e1657 KB |
14438 | } |
14439 | ||
917c78fc | 14440 | return retval; |
613e1657 KB |
14441 | } |
14442 | ||
fe1b8b76 JB |
14443 | static gdb_byte * |
14444 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
14445 | { |
14446 | /* If the size of a host char is 8 bits, we can return a pointer | |
14447 | to the buffer, otherwise we have to copy the data to a buffer | |
14448 | allocated on the temporary obstack. */ | |
4bdf3d34 | 14449 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 14450 | return buf; |
c906108c SS |
14451 | } |
14452 | ||
14453 | static char * | |
9b1c24c8 | 14454 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
14455 | { |
14456 | /* If the size of a host char is 8 bits, we can return a pointer | |
14457 | to the string, otherwise we have to copy the string to a buffer | |
14458 | allocated on the temporary obstack. */ | |
4bdf3d34 | 14459 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
14460 | if (*buf == '\0') |
14461 | { | |
14462 | *bytes_read_ptr = 1; | |
14463 | return NULL; | |
14464 | } | |
fe1b8b76 JB |
14465 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
14466 | return (char *) buf; | |
4bdf3d34 JJ |
14467 | } |
14468 | ||
14469 | static char * | |
cf2c3c16 | 14470 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
4bdf3d34 | 14471 | { |
be391dca | 14472 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 14473 | if (dwarf2_per_objfile->str.buffer == NULL) |
cf2c3c16 TT |
14474 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
14475 | bfd_get_filename (abfd)); | |
dce234bc | 14476 | if (str_offset >= dwarf2_per_objfile->str.size) |
cf2c3c16 TT |
14477 | error (_("DW_FORM_strp pointing outside of " |
14478 | ".debug_str section [in module %s]"), | |
14479 | bfd_get_filename (abfd)); | |
4bdf3d34 | 14480 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 14481 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 14482 | return NULL; |
dce234bc | 14483 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
14484 | } |
14485 | ||
36586728 TT |
14486 | /* Read a string at offset STR_OFFSET in the .debug_str section from |
14487 | the .dwz file DWZ. Throw an error if the offset is too large. If | |
14488 | the string consists of a single NUL byte, return NULL; otherwise | |
14489 | return a pointer to the string. */ | |
14490 | ||
14491 | static char * | |
14492 | read_indirect_string_from_dwz (struct dwz_file *dwz, LONGEST str_offset) | |
14493 | { | |
14494 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwz->str); | |
14495 | ||
14496 | if (dwz->str.buffer == NULL) | |
14497 | error (_("DW_FORM_GNU_strp_alt used without .debug_str " | |
14498 | "section [in module %s]"), | |
14499 | bfd_get_filename (dwz->dwz_bfd)); | |
14500 | if (str_offset >= dwz->str.size) | |
14501 | error (_("DW_FORM_GNU_strp_alt pointing outside of " | |
14502 | ".debug_str section [in module %s]"), | |
14503 | bfd_get_filename (dwz->dwz_bfd)); | |
14504 | gdb_assert (HOST_CHAR_BIT == 8); | |
14505 | if (dwz->str.buffer[str_offset] == '\0') | |
14506 | return NULL; | |
14507 | return (char *) (dwz->str.buffer + str_offset); | |
14508 | } | |
14509 | ||
cf2c3c16 TT |
14510 | static char * |
14511 | read_indirect_string (bfd *abfd, gdb_byte *buf, | |
14512 | const struct comp_unit_head *cu_header, | |
14513 | unsigned int *bytes_read_ptr) | |
14514 | { | |
14515 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
14516 | ||
14517 | return read_indirect_string_at_offset (abfd, str_offset); | |
14518 | } | |
14519 | ||
12df843f | 14520 | static ULONGEST |
fe1b8b76 | 14521 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 14522 | { |
12df843f | 14523 | ULONGEST result; |
ce5d95e1 | 14524 | unsigned int num_read; |
c906108c SS |
14525 | int i, shift; |
14526 | unsigned char byte; | |
14527 | ||
14528 | result = 0; | |
14529 | shift = 0; | |
14530 | num_read = 0; | |
14531 | i = 0; | |
14532 | while (1) | |
14533 | { | |
fe1b8b76 | 14534 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
14535 | buf++; |
14536 | num_read++; | |
12df843f | 14537 | result |= ((ULONGEST) (byte & 127) << shift); |
c906108c SS |
14538 | if ((byte & 128) == 0) |
14539 | { | |
14540 | break; | |
14541 | } | |
14542 | shift += 7; | |
14543 | } | |
14544 | *bytes_read_ptr = num_read; | |
14545 | return result; | |
14546 | } | |
14547 | ||
12df843f | 14548 | static LONGEST |
fe1b8b76 | 14549 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 14550 | { |
12df843f | 14551 | LONGEST result; |
77e0b926 | 14552 | int i, shift, num_read; |
c906108c SS |
14553 | unsigned char byte; |
14554 | ||
14555 | result = 0; | |
14556 | shift = 0; | |
c906108c SS |
14557 | num_read = 0; |
14558 | i = 0; | |
14559 | while (1) | |
14560 | { | |
fe1b8b76 | 14561 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
14562 | buf++; |
14563 | num_read++; | |
12df843f | 14564 | result |= ((LONGEST) (byte & 127) << shift); |
c906108c SS |
14565 | shift += 7; |
14566 | if ((byte & 128) == 0) | |
14567 | { | |
14568 | break; | |
14569 | } | |
14570 | } | |
77e0b926 | 14571 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
12df843f | 14572 | result |= -(((LONGEST) 1) << shift); |
c906108c SS |
14573 | *bytes_read_ptr = num_read; |
14574 | return result; | |
14575 | } | |
14576 | ||
3019eac3 DE |
14577 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. |
14578 | ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero. | |
14579 | ADDR_SIZE is the size of addresses from the CU header. */ | |
14580 | ||
14581 | static CORE_ADDR | |
14582 | read_addr_index_1 (unsigned int addr_index, ULONGEST addr_base, int addr_size) | |
14583 | { | |
14584 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
14585 | bfd *abfd = objfile->obfd; | |
14586 | const gdb_byte *info_ptr; | |
14587 | ||
14588 | dwarf2_read_section (objfile, &dwarf2_per_objfile->addr); | |
14589 | if (dwarf2_per_objfile->addr.buffer == NULL) | |
14590 | error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"), | |
14591 | objfile->name); | |
14592 | if (addr_base + addr_index * addr_size >= dwarf2_per_objfile->addr.size) | |
14593 | error (_("DW_FORM_addr_index pointing outside of " | |
14594 | ".debug_addr section [in module %s]"), | |
14595 | objfile->name); | |
14596 | info_ptr = (dwarf2_per_objfile->addr.buffer | |
14597 | + addr_base + addr_index * addr_size); | |
14598 | if (addr_size == 4) | |
14599 | return bfd_get_32 (abfd, info_ptr); | |
14600 | else | |
14601 | return bfd_get_64 (abfd, info_ptr); | |
14602 | } | |
14603 | ||
14604 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. */ | |
14605 | ||
14606 | static CORE_ADDR | |
14607 | read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index) | |
14608 | { | |
14609 | return read_addr_index_1 (addr_index, cu->addr_base, cu->header.addr_size); | |
14610 | } | |
14611 | ||
14612 | /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */ | |
14613 | ||
14614 | static CORE_ADDR | |
14615 | read_addr_index_from_leb128 (struct dwarf2_cu *cu, gdb_byte *info_ptr, | |
14616 | unsigned int *bytes_read) | |
14617 | { | |
14618 | bfd *abfd = cu->objfile->obfd; | |
14619 | unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
14620 | ||
14621 | return read_addr_index (cu, addr_index); | |
14622 | } | |
14623 | ||
14624 | /* Data structure to pass results from dwarf2_read_addr_index_reader | |
14625 | back to dwarf2_read_addr_index. */ | |
14626 | ||
14627 | struct dwarf2_read_addr_index_data | |
14628 | { | |
14629 | ULONGEST addr_base; | |
14630 | int addr_size; | |
14631 | }; | |
14632 | ||
14633 | /* die_reader_func for dwarf2_read_addr_index. */ | |
14634 | ||
14635 | static void | |
14636 | dwarf2_read_addr_index_reader (const struct die_reader_specs *reader, | |
14637 | gdb_byte *info_ptr, | |
14638 | struct die_info *comp_unit_die, | |
14639 | int has_children, | |
14640 | void *data) | |
14641 | { | |
14642 | struct dwarf2_cu *cu = reader->cu; | |
14643 | struct dwarf2_read_addr_index_data *aidata = | |
14644 | (struct dwarf2_read_addr_index_data *) data; | |
14645 | ||
14646 | aidata->addr_base = cu->addr_base; | |
14647 | aidata->addr_size = cu->header.addr_size; | |
14648 | } | |
14649 | ||
14650 | /* Given an index in .debug_addr, fetch the value. | |
14651 | NOTE: This can be called during dwarf expression evaluation, | |
14652 | long after the debug information has been read, and thus per_cu->cu | |
14653 | may no longer exist. */ | |
14654 | ||
14655 | CORE_ADDR | |
14656 | dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu, | |
14657 | unsigned int addr_index) | |
14658 | { | |
14659 | struct objfile *objfile = per_cu->objfile; | |
14660 | struct dwarf2_cu *cu = per_cu->cu; | |
14661 | ULONGEST addr_base; | |
14662 | int addr_size; | |
14663 | ||
14664 | /* This is intended to be called from outside this file. */ | |
14665 | dw2_setup (objfile); | |
14666 | ||
14667 | /* We need addr_base and addr_size. | |
14668 | If we don't have PER_CU->cu, we have to get it. | |
14669 | Nasty, but the alternative is storing the needed info in PER_CU, | |
14670 | which at this point doesn't seem justified: it's not clear how frequently | |
14671 | it would get used and it would increase the size of every PER_CU. | |
14672 | Entry points like dwarf2_per_cu_addr_size do a similar thing | |
14673 | so we're not in uncharted territory here. | |
14674 | Alas we need to be a bit more complicated as addr_base is contained | |
14675 | in the DIE. | |
14676 | ||
14677 | We don't need to read the entire CU(/TU). | |
14678 | We just need the header and top level die. | |
a1b64ce1 | 14679 | |
3019eac3 | 14680 | IWBN to use the aging mechanism to let us lazily later discard the CU. |
a1b64ce1 | 14681 | For now we skip this optimization. */ |
3019eac3 DE |
14682 | |
14683 | if (cu != NULL) | |
14684 | { | |
14685 | addr_base = cu->addr_base; | |
14686 | addr_size = cu->header.addr_size; | |
14687 | } | |
14688 | else | |
14689 | { | |
14690 | struct dwarf2_read_addr_index_data aidata; | |
14691 | ||
a1b64ce1 DE |
14692 | /* Note: We can't use init_cutu_and_read_dies_simple here, |
14693 | we need addr_base. */ | |
14694 | init_cutu_and_read_dies (per_cu, NULL, 0, 0, | |
14695 | dwarf2_read_addr_index_reader, &aidata); | |
3019eac3 DE |
14696 | addr_base = aidata.addr_base; |
14697 | addr_size = aidata.addr_size; | |
14698 | } | |
14699 | ||
14700 | return read_addr_index_1 (addr_index, addr_base, addr_size); | |
14701 | } | |
14702 | ||
14703 | /* Given a DW_AT_str_index, fetch the string. */ | |
14704 | ||
14705 | static char * | |
14706 | read_str_index (const struct die_reader_specs *reader, | |
14707 | struct dwarf2_cu *cu, ULONGEST str_index) | |
14708 | { | |
14709 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
14710 | const char *dwo_name = objfile->name; | |
14711 | bfd *abfd = objfile->obfd; | |
14712 | struct dwo_sections *sections = &reader->dwo_file->sections; | |
14713 | gdb_byte *info_ptr; | |
14714 | ULONGEST str_offset; | |
14715 | ||
14716 | dwarf2_read_section (objfile, §ions->str); | |
14717 | dwarf2_read_section (objfile, §ions->str_offsets); | |
14718 | if (sections->str.buffer == NULL) | |
14719 | error (_("DW_FORM_str_index used without .debug_str.dwo section" | |
14720 | " in CU at offset 0x%lx [in module %s]"), | |
14721 | (long) cu->header.offset.sect_off, dwo_name); | |
14722 | if (sections->str_offsets.buffer == NULL) | |
14723 | error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section" | |
14724 | " in CU at offset 0x%lx [in module %s]"), | |
14725 | (long) cu->header.offset.sect_off, dwo_name); | |
14726 | if (str_index * cu->header.offset_size >= sections->str_offsets.size) | |
14727 | error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo" | |
14728 | " section in CU at offset 0x%lx [in module %s]"), | |
14729 | (long) cu->header.offset.sect_off, dwo_name); | |
14730 | info_ptr = (sections->str_offsets.buffer | |
14731 | + str_index * cu->header.offset_size); | |
14732 | if (cu->header.offset_size == 4) | |
14733 | str_offset = bfd_get_32 (abfd, info_ptr); | |
14734 | else | |
14735 | str_offset = bfd_get_64 (abfd, info_ptr); | |
14736 | if (str_offset >= sections->str.size) | |
14737 | error (_("Offset from DW_FORM_str_index pointing outside of" | |
14738 | " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"), | |
14739 | (long) cu->header.offset.sect_off, dwo_name); | |
14740 | return (char *) (sections->str.buffer + str_offset); | |
14741 | } | |
14742 | ||
3019eac3 DE |
14743 | /* Return the length of an LEB128 number in BUF. */ |
14744 | ||
14745 | static int | |
14746 | leb128_size (const gdb_byte *buf) | |
14747 | { | |
14748 | const gdb_byte *begin = buf; | |
14749 | gdb_byte byte; | |
14750 | ||
14751 | while (1) | |
14752 | { | |
14753 | byte = *buf++; | |
14754 | if ((byte & 128) == 0) | |
14755 | return buf - begin; | |
14756 | } | |
14757 | } | |
14758 | ||
c906108c | 14759 | static void |
e142c38c | 14760 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
14761 | { |
14762 | switch (lang) | |
14763 | { | |
14764 | case DW_LANG_C89: | |
76bee0cc | 14765 | case DW_LANG_C99: |
c906108c | 14766 | case DW_LANG_C: |
e142c38c | 14767 | cu->language = language_c; |
c906108c SS |
14768 | break; |
14769 | case DW_LANG_C_plus_plus: | |
e142c38c | 14770 | cu->language = language_cplus; |
c906108c | 14771 | break; |
6aecb9c2 JB |
14772 | case DW_LANG_D: |
14773 | cu->language = language_d; | |
14774 | break; | |
c906108c SS |
14775 | case DW_LANG_Fortran77: |
14776 | case DW_LANG_Fortran90: | |
b21b22e0 | 14777 | case DW_LANG_Fortran95: |
e142c38c | 14778 | cu->language = language_fortran; |
c906108c | 14779 | break; |
a766d390 DE |
14780 | case DW_LANG_Go: |
14781 | cu->language = language_go; | |
14782 | break; | |
c906108c | 14783 | case DW_LANG_Mips_Assembler: |
e142c38c | 14784 | cu->language = language_asm; |
c906108c | 14785 | break; |
bebd888e | 14786 | case DW_LANG_Java: |
e142c38c | 14787 | cu->language = language_java; |
bebd888e | 14788 | break; |
c906108c | 14789 | case DW_LANG_Ada83: |
8aaf0b47 | 14790 | case DW_LANG_Ada95: |
bc5f45f8 JB |
14791 | cu->language = language_ada; |
14792 | break; | |
72019c9c GM |
14793 | case DW_LANG_Modula2: |
14794 | cu->language = language_m2; | |
14795 | break; | |
fe8e67fd PM |
14796 | case DW_LANG_Pascal83: |
14797 | cu->language = language_pascal; | |
14798 | break; | |
22566fbd DJ |
14799 | case DW_LANG_ObjC: |
14800 | cu->language = language_objc; | |
14801 | break; | |
c906108c SS |
14802 | case DW_LANG_Cobol74: |
14803 | case DW_LANG_Cobol85: | |
c906108c | 14804 | default: |
e142c38c | 14805 | cu->language = language_minimal; |
c906108c SS |
14806 | break; |
14807 | } | |
e142c38c | 14808 | cu->language_defn = language_def (cu->language); |
c906108c SS |
14809 | } |
14810 | ||
14811 | /* Return the named attribute or NULL if not there. */ | |
14812 | ||
14813 | static struct attribute * | |
e142c38c | 14814 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c | 14815 | { |
a48e046c | 14816 | for (;;) |
c906108c | 14817 | { |
a48e046c TT |
14818 | unsigned int i; |
14819 | struct attribute *spec = NULL; | |
14820 | ||
14821 | for (i = 0; i < die->num_attrs; ++i) | |
14822 | { | |
14823 | if (die->attrs[i].name == name) | |
14824 | return &die->attrs[i]; | |
14825 | if (die->attrs[i].name == DW_AT_specification | |
14826 | || die->attrs[i].name == DW_AT_abstract_origin) | |
14827 | spec = &die->attrs[i]; | |
14828 | } | |
14829 | ||
14830 | if (!spec) | |
14831 | break; | |
c906108c | 14832 | |
f2f0e013 | 14833 | die = follow_die_ref (die, spec, &cu); |
f2f0e013 | 14834 | } |
c5aa993b | 14835 | |
c906108c SS |
14836 | return NULL; |
14837 | } | |
14838 | ||
348e048f DE |
14839 | /* Return the named attribute or NULL if not there, |
14840 | but do not follow DW_AT_specification, etc. | |
14841 | This is for use in contexts where we're reading .debug_types dies. | |
14842 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
14843 | back up the chain, and we want to go down. */ | |
14844 | ||
14845 | static struct attribute * | |
45e58e77 | 14846 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name) |
348e048f DE |
14847 | { |
14848 | unsigned int i; | |
14849 | ||
14850 | for (i = 0; i < die->num_attrs; ++i) | |
14851 | if (die->attrs[i].name == name) | |
14852 | return &die->attrs[i]; | |
14853 | ||
14854 | return NULL; | |
14855 | } | |
14856 | ||
05cf31d1 JB |
14857 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
14858 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 14859 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
14860 | |
14861 | static int | |
14862 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
14863 | { | |
14864 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
14865 | ||
14866 | return (attr && DW_UNSND (attr)); | |
14867 | } | |
14868 | ||
3ca72b44 | 14869 | static int |
e142c38c | 14870 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 14871 | { |
05cf31d1 JB |
14872 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
14873 | which value is non-zero. However, we have to be careful with | |
14874 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
14875 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
14876 | end up accidently finding a declaration attribute that belongs | |
14877 | to a different DIE referenced by the specification attribute, | |
14878 | even though the given DIE does not have a declaration attribute. */ | |
14879 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
14880 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
14881 | } |
14882 | ||
63d06c5c | 14883 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 14884 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
14885 | containing the return value on output. If there is no |
14886 | specification, but there is an abstract origin, that is | |
14887 | returned. */ | |
63d06c5c DC |
14888 | |
14889 | static struct die_info * | |
f2f0e013 | 14890 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 14891 | { |
f2f0e013 DJ |
14892 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
14893 | *spec_cu); | |
63d06c5c | 14894 | |
edb3359d DJ |
14895 | if (spec_attr == NULL) |
14896 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
14897 | ||
63d06c5c DC |
14898 | if (spec_attr == NULL) |
14899 | return NULL; | |
14900 | else | |
f2f0e013 | 14901 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 14902 | } |
c906108c | 14903 | |
debd256d | 14904 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
14905 | refers to. |
14906 | NOTE: This is also used as a "cleanup" function. */ | |
14907 | ||
debd256d JB |
14908 | static void |
14909 | free_line_header (struct line_header *lh) | |
14910 | { | |
14911 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 14912 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
14913 | |
14914 | /* Remember that all the lh->file_names[i].name pointers are | |
14915 | pointers into debug_line_buffer, and don't need to be freed. */ | |
14916 | if (lh->file_names) | |
a8bc7b56 | 14917 | xfree (lh->file_names); |
debd256d JB |
14918 | |
14919 | /* Similarly for the include directory names. */ | |
14920 | if (lh->include_dirs) | |
a8bc7b56 | 14921 | xfree (lh->include_dirs); |
debd256d | 14922 | |
a8bc7b56 | 14923 | xfree (lh); |
debd256d JB |
14924 | } |
14925 | ||
debd256d | 14926 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 14927 | |
debd256d JB |
14928 | static void |
14929 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 14930 | { |
debd256d JB |
14931 | /* Grow the array if necessary. */ |
14932 | if (lh->include_dirs_size == 0) | |
c5aa993b | 14933 | { |
debd256d JB |
14934 | lh->include_dirs_size = 1; /* for testing */ |
14935 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
14936 | * sizeof (*lh->include_dirs)); | |
14937 | } | |
14938 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
14939 | { | |
14940 | lh->include_dirs_size *= 2; | |
14941 | lh->include_dirs = xrealloc (lh->include_dirs, | |
14942 | (lh->include_dirs_size | |
14943 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 14944 | } |
c906108c | 14945 | |
debd256d JB |
14946 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
14947 | } | |
6e70227d | 14948 | |
debd256d | 14949 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 14950 | |
debd256d JB |
14951 | static void |
14952 | add_file_name (struct line_header *lh, | |
14953 | char *name, | |
14954 | unsigned int dir_index, | |
14955 | unsigned int mod_time, | |
14956 | unsigned int length) | |
14957 | { | |
14958 | struct file_entry *fe; | |
14959 | ||
14960 | /* Grow the array if necessary. */ | |
14961 | if (lh->file_names_size == 0) | |
14962 | { | |
14963 | lh->file_names_size = 1; /* for testing */ | |
14964 | lh->file_names = xmalloc (lh->file_names_size | |
14965 | * sizeof (*lh->file_names)); | |
14966 | } | |
14967 | else if (lh->num_file_names >= lh->file_names_size) | |
14968 | { | |
14969 | lh->file_names_size *= 2; | |
14970 | lh->file_names = xrealloc (lh->file_names, | |
14971 | (lh->file_names_size | |
14972 | * sizeof (*lh->file_names))); | |
14973 | } | |
14974 | ||
14975 | fe = &lh->file_names[lh->num_file_names++]; | |
14976 | fe->name = name; | |
14977 | fe->dir_index = dir_index; | |
14978 | fe->mod_time = mod_time; | |
14979 | fe->length = length; | |
aaa75496 | 14980 | fe->included_p = 0; |
cb1df416 | 14981 | fe->symtab = NULL; |
debd256d | 14982 | } |
6e70227d | 14983 | |
36586728 TT |
14984 | /* A convenience function to find the proper .debug_line section for a |
14985 | CU. */ | |
14986 | ||
14987 | static struct dwarf2_section_info * | |
14988 | get_debug_line_section (struct dwarf2_cu *cu) | |
14989 | { | |
14990 | struct dwarf2_section_info *section; | |
14991 | ||
14992 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the | |
14993 | DWO file. */ | |
14994 | if (cu->dwo_unit && cu->per_cu->is_debug_types) | |
14995 | section = &cu->dwo_unit->dwo_file->sections.line; | |
14996 | else if (cu->per_cu->is_dwz) | |
14997 | { | |
14998 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
14999 | ||
15000 | section = &dwz->line; | |
15001 | } | |
15002 | else | |
15003 | section = &dwarf2_per_objfile->line; | |
15004 | ||
15005 | return section; | |
15006 | } | |
15007 | ||
debd256d | 15008 | /* Read the statement program header starting at OFFSET in |
3019eac3 | 15009 | .debug_line, or .debug_line.dwo. Return a pointer |
6502dd73 | 15010 | to a struct line_header, allocated using xmalloc. |
debd256d JB |
15011 | |
15012 | NOTE: the strings in the include directory and file name tables of | |
3019eac3 DE |
15013 | the returned object point into the dwarf line section buffer, |
15014 | and must not be freed. */ | |
ae2de4f8 | 15015 | |
debd256d | 15016 | static struct line_header * |
3019eac3 | 15017 | dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu) |
debd256d JB |
15018 | { |
15019 | struct cleanup *back_to; | |
15020 | struct line_header *lh; | |
fe1b8b76 | 15021 | gdb_byte *line_ptr; |
c764a876 | 15022 | unsigned int bytes_read, offset_size; |
debd256d JB |
15023 | int i; |
15024 | char *cur_dir, *cur_file; | |
3019eac3 DE |
15025 | struct dwarf2_section_info *section; |
15026 | bfd *abfd; | |
15027 | ||
36586728 | 15028 | section = get_debug_line_section (cu); |
3019eac3 DE |
15029 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); |
15030 | if (section->buffer == NULL) | |
debd256d | 15031 | { |
3019eac3 DE |
15032 | if (cu->dwo_unit && cu->per_cu->is_debug_types) |
15033 | complaint (&symfile_complaints, _("missing .debug_line.dwo section")); | |
15034 | else | |
15035 | complaint (&symfile_complaints, _("missing .debug_line section")); | |
debd256d JB |
15036 | return 0; |
15037 | } | |
15038 | ||
fceca515 DE |
15039 | /* We can't do this until we know the section is non-empty. |
15040 | Only then do we know we have such a section. */ | |
15041 | abfd = section->asection->owner; | |
15042 | ||
a738430d MK |
15043 | /* Make sure that at least there's room for the total_length field. |
15044 | That could be 12 bytes long, but we're just going to fudge that. */ | |
3019eac3 | 15045 | if (offset + 4 >= section->size) |
debd256d | 15046 | { |
4d3c2250 | 15047 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
15048 | return 0; |
15049 | } | |
15050 | ||
15051 | lh = xmalloc (sizeof (*lh)); | |
15052 | memset (lh, 0, sizeof (*lh)); | |
15053 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
15054 | (void *) lh); | |
15055 | ||
3019eac3 | 15056 | line_ptr = section->buffer + offset; |
debd256d | 15057 | |
a738430d | 15058 | /* Read in the header. */ |
6e70227d | 15059 | lh->total_length = |
c764a876 DE |
15060 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
15061 | &bytes_read, &offset_size); | |
debd256d | 15062 | line_ptr += bytes_read; |
3019eac3 | 15063 | if (line_ptr + lh->total_length > (section->buffer + section->size)) |
debd256d | 15064 | { |
4d3c2250 | 15065 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
15066 | return 0; |
15067 | } | |
15068 | lh->statement_program_end = line_ptr + lh->total_length; | |
15069 | lh->version = read_2_bytes (abfd, line_ptr); | |
15070 | line_ptr += 2; | |
c764a876 DE |
15071 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
15072 | line_ptr += offset_size; | |
debd256d JB |
15073 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
15074 | line_ptr += 1; | |
2dc7f7b3 TT |
15075 | if (lh->version >= 4) |
15076 | { | |
15077 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
15078 | line_ptr += 1; | |
15079 | } | |
15080 | else | |
15081 | lh->maximum_ops_per_instruction = 1; | |
15082 | ||
15083 | if (lh->maximum_ops_per_instruction == 0) | |
15084 | { | |
15085 | lh->maximum_ops_per_instruction = 1; | |
15086 | complaint (&symfile_complaints, | |
3e43a32a MS |
15087 | _("invalid maximum_ops_per_instruction " |
15088 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
15089 | } |
15090 | ||
debd256d JB |
15091 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
15092 | line_ptr += 1; | |
15093 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
15094 | line_ptr += 1; | |
15095 | lh->line_range = read_1_byte (abfd, line_ptr); | |
15096 | line_ptr += 1; | |
15097 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
15098 | line_ptr += 1; | |
15099 | lh->standard_opcode_lengths | |
fe1b8b76 | 15100 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
15101 | |
15102 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
15103 | for (i = 1; i < lh->opcode_base; ++i) | |
15104 | { | |
15105 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
15106 | line_ptr += 1; | |
15107 | } | |
15108 | ||
a738430d | 15109 | /* Read directory table. */ |
9b1c24c8 | 15110 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
15111 | { |
15112 | line_ptr += bytes_read; | |
15113 | add_include_dir (lh, cur_dir); | |
15114 | } | |
15115 | line_ptr += bytes_read; | |
15116 | ||
a738430d | 15117 | /* Read file name table. */ |
9b1c24c8 | 15118 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
15119 | { |
15120 | unsigned int dir_index, mod_time, length; | |
15121 | ||
15122 | line_ptr += bytes_read; | |
15123 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
15124 | line_ptr += bytes_read; | |
15125 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
15126 | line_ptr += bytes_read; | |
15127 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
15128 | line_ptr += bytes_read; | |
15129 | ||
15130 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
15131 | } | |
15132 | line_ptr += bytes_read; | |
6e70227d | 15133 | lh->statement_program_start = line_ptr; |
debd256d | 15134 | |
3019eac3 | 15135 | if (line_ptr > (section->buffer + section->size)) |
4d3c2250 | 15136 | complaint (&symfile_complaints, |
3e43a32a MS |
15137 | _("line number info header doesn't " |
15138 | "fit in `.debug_line' section")); | |
debd256d JB |
15139 | |
15140 | discard_cleanups (back_to); | |
15141 | return lh; | |
15142 | } | |
c906108c | 15143 | |
c6da4cef DE |
15144 | /* Subroutine of dwarf_decode_lines to simplify it. |
15145 | Return the file name of the psymtab for included file FILE_INDEX | |
15146 | in line header LH of PST. | |
15147 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
15148 | If space for the result is malloc'd, it will be freed by a cleanup. | |
1ed59174 JK |
15149 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. |
15150 | ||
15151 | The function creates dangling cleanup registration. */ | |
c6da4cef DE |
15152 | |
15153 | static char * | |
15154 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
15155 | const struct partial_symtab *pst, | |
15156 | const char *comp_dir) | |
15157 | { | |
15158 | const struct file_entry fe = lh->file_names [file_index]; | |
15159 | char *include_name = fe.name; | |
15160 | char *include_name_to_compare = include_name; | |
15161 | char *dir_name = NULL; | |
72b9f47f TT |
15162 | const char *pst_filename; |
15163 | char *copied_name = NULL; | |
c6da4cef DE |
15164 | int file_is_pst; |
15165 | ||
15166 | if (fe.dir_index) | |
15167 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
15168 | ||
15169 | if (!IS_ABSOLUTE_PATH (include_name) | |
15170 | && (dir_name != NULL || comp_dir != NULL)) | |
15171 | { | |
15172 | /* Avoid creating a duplicate psymtab for PST. | |
15173 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
15174 | Before we do the comparison, however, we need to account | |
15175 | for DIR_NAME and COMP_DIR. | |
15176 | First prepend dir_name (if non-NULL). If we still don't | |
15177 | have an absolute path prepend comp_dir (if non-NULL). | |
15178 | However, the directory we record in the include-file's | |
15179 | psymtab does not contain COMP_DIR (to match the | |
15180 | corresponding symtab(s)). | |
15181 | ||
15182 | Example: | |
15183 | ||
15184 | bash$ cd /tmp | |
15185 | bash$ gcc -g ./hello.c | |
15186 | include_name = "hello.c" | |
15187 | dir_name = "." | |
15188 | DW_AT_comp_dir = comp_dir = "/tmp" | |
15189 | DW_AT_name = "./hello.c" */ | |
15190 | ||
15191 | if (dir_name != NULL) | |
15192 | { | |
15193 | include_name = concat (dir_name, SLASH_STRING, | |
15194 | include_name, (char *)NULL); | |
15195 | include_name_to_compare = include_name; | |
15196 | make_cleanup (xfree, include_name); | |
15197 | } | |
15198 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
15199 | { | |
15200 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
15201 | include_name, (char *)NULL); | |
15202 | } | |
15203 | } | |
15204 | ||
15205 | pst_filename = pst->filename; | |
15206 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
15207 | { | |
72b9f47f TT |
15208 | copied_name = concat (pst->dirname, SLASH_STRING, |
15209 | pst_filename, (char *)NULL); | |
15210 | pst_filename = copied_name; | |
c6da4cef DE |
15211 | } |
15212 | ||
1e3fad37 | 15213 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
15214 | |
15215 | if (include_name_to_compare != include_name) | |
15216 | xfree (include_name_to_compare); | |
72b9f47f TT |
15217 | if (copied_name != NULL) |
15218 | xfree (copied_name); | |
c6da4cef DE |
15219 | |
15220 | if (file_is_pst) | |
15221 | return NULL; | |
15222 | return include_name; | |
15223 | } | |
15224 | ||
c91513d8 PP |
15225 | /* Ignore this record_line request. */ |
15226 | ||
15227 | static void | |
15228 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
15229 | { | |
15230 | return; | |
15231 | } | |
15232 | ||
f3f5162e DE |
15233 | /* Subroutine of dwarf_decode_lines to simplify it. |
15234 | Process the line number information in LH. */ | |
debd256d | 15235 | |
c906108c | 15236 | static void |
f3f5162e DE |
15237 | dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, |
15238 | struct dwarf2_cu *cu, struct partial_symtab *pst) | |
c906108c | 15239 | { |
a8c50c1f | 15240 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 15241 | gdb_byte *line_end; |
a8c50c1f | 15242 | unsigned int bytes_read, extended_len; |
c906108c | 15243 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
15244 | CORE_ADDR baseaddr; |
15245 | struct objfile *objfile = cu->objfile; | |
f3f5162e | 15246 | bfd *abfd = objfile->obfd; |
fbf65064 | 15247 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 15248 | const int decode_for_pst_p = (pst != NULL); |
f3f5162e | 15249 | struct subfile *last_subfile = NULL; |
c91513d8 PP |
15250 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
15251 | = record_line; | |
e142c38c DJ |
15252 | |
15253 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 15254 | |
debd256d JB |
15255 | line_ptr = lh->statement_program_start; |
15256 | line_end = lh->statement_program_end; | |
c906108c SS |
15257 | |
15258 | /* Read the statement sequences until there's nothing left. */ | |
15259 | while (line_ptr < line_end) | |
15260 | { | |
15261 | /* state machine registers */ | |
15262 | CORE_ADDR address = 0; | |
15263 | unsigned int file = 1; | |
15264 | unsigned int line = 1; | |
15265 | unsigned int column = 0; | |
debd256d | 15266 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
15267 | int basic_block = 0; |
15268 | int end_sequence = 0; | |
fbf65064 | 15269 | CORE_ADDR addr; |
2dc7f7b3 | 15270 | unsigned char op_index = 0; |
c906108c | 15271 | |
aaa75496 | 15272 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 15273 | { |
aaa75496 | 15274 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
15275 | /* lh->include_dirs and lh->file_names are 0-based, but the |
15276 | directory and file name numbers in the statement program | |
15277 | are 1-based. */ | |
15278 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 15279 | char *dir = NULL; |
a738430d | 15280 | |
debd256d JB |
15281 | if (fe->dir_index) |
15282 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
15283 | |
15284 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
15285 | } |
15286 | ||
a738430d | 15287 | /* Decode the table. */ |
c5aa993b | 15288 | while (!end_sequence) |
c906108c SS |
15289 | { |
15290 | op_code = read_1_byte (abfd, line_ptr); | |
15291 | line_ptr += 1; | |
59205f5a JB |
15292 | if (line_ptr > line_end) |
15293 | { | |
15294 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
15295 | break; | |
15296 | } | |
9aa1fe7e | 15297 | |
debd256d | 15298 | if (op_code >= lh->opcode_base) |
6e70227d | 15299 | { |
a738430d | 15300 | /* Special operand. */ |
debd256d | 15301 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
15302 | address += (((op_index + (adj_opcode / lh->line_range)) |
15303 | / lh->maximum_ops_per_instruction) | |
15304 | * lh->minimum_instruction_length); | |
15305 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
15306 | % lh->maximum_ops_per_instruction); | |
debd256d | 15307 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 15308 | if (lh->num_file_names < file || file == 0) |
25e43795 | 15309 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
15310 | /* For now we ignore lines not starting on an |
15311 | instruction boundary. */ | |
15312 | else if (op_index == 0) | |
25e43795 DJ |
15313 | { |
15314 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 15315 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
15316 | { |
15317 | if (last_subfile != current_subfile) | |
15318 | { | |
15319 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
15320 | if (last_subfile) | |
c91513d8 | 15321 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
15322 | last_subfile = current_subfile; |
15323 | } | |
25e43795 | 15324 | /* Append row to matrix using current values. */ |
7019d805 | 15325 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 15326 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 15327 | } |
25e43795 | 15328 | } |
ca5f395d | 15329 | basic_block = 0; |
9aa1fe7e GK |
15330 | } |
15331 | else switch (op_code) | |
c906108c SS |
15332 | { |
15333 | case DW_LNS_extended_op: | |
3e43a32a MS |
15334 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
15335 | &bytes_read); | |
473b7be6 | 15336 | line_ptr += bytes_read; |
a8c50c1f | 15337 | extended_end = line_ptr + extended_len; |
c906108c SS |
15338 | extended_op = read_1_byte (abfd, line_ptr); |
15339 | line_ptr += 1; | |
15340 | switch (extended_op) | |
15341 | { | |
15342 | case DW_LNE_end_sequence: | |
c91513d8 | 15343 | p_record_line = record_line; |
c906108c | 15344 | end_sequence = 1; |
c906108c SS |
15345 | break; |
15346 | case DW_LNE_set_address: | |
e7c27a73 | 15347 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
15348 | |
15349 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
15350 | { | |
15351 | /* This line table is for a function which has been | |
15352 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
15353 | ||
15354 | long line_offset | |
36586728 | 15355 | = line_ptr - get_debug_line_section (cu)->buffer; |
c91513d8 PP |
15356 | |
15357 | complaint (&symfile_complaints, | |
15358 | _(".debug_line address at offset 0x%lx is 0 " | |
15359 | "[in module %s]"), | |
bb5ed363 | 15360 | line_offset, objfile->name); |
c91513d8 PP |
15361 | p_record_line = noop_record_line; |
15362 | } | |
15363 | ||
2dc7f7b3 | 15364 | op_index = 0; |
107d2387 AC |
15365 | line_ptr += bytes_read; |
15366 | address += baseaddr; | |
c906108c SS |
15367 | break; |
15368 | case DW_LNE_define_file: | |
debd256d JB |
15369 | { |
15370 | char *cur_file; | |
15371 | unsigned int dir_index, mod_time, length; | |
6e70227d | 15372 | |
3e43a32a MS |
15373 | cur_file = read_direct_string (abfd, line_ptr, |
15374 | &bytes_read); | |
debd256d JB |
15375 | line_ptr += bytes_read; |
15376 | dir_index = | |
15377 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
15378 | line_ptr += bytes_read; | |
15379 | mod_time = | |
15380 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
15381 | line_ptr += bytes_read; | |
15382 | length = | |
15383 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
15384 | line_ptr += bytes_read; | |
15385 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
15386 | } | |
c906108c | 15387 | break; |
d0c6ba3d CC |
15388 | case DW_LNE_set_discriminator: |
15389 | /* The discriminator is not interesting to the debugger; | |
15390 | just ignore it. */ | |
15391 | line_ptr = extended_end; | |
15392 | break; | |
c906108c | 15393 | default: |
4d3c2250 | 15394 | complaint (&symfile_complaints, |
e2e0b3e5 | 15395 | _("mangled .debug_line section")); |
debd256d | 15396 | return; |
c906108c | 15397 | } |
a8c50c1f DJ |
15398 | /* Make sure that we parsed the extended op correctly. If e.g. |
15399 | we expected a different address size than the producer used, | |
15400 | we may have read the wrong number of bytes. */ | |
15401 | if (line_ptr != extended_end) | |
15402 | { | |
15403 | complaint (&symfile_complaints, | |
15404 | _("mangled .debug_line section")); | |
15405 | return; | |
15406 | } | |
c906108c SS |
15407 | break; |
15408 | case DW_LNS_copy: | |
59205f5a | 15409 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
15410 | dwarf2_debug_line_missing_file_complaint (); |
15411 | else | |
366da635 | 15412 | { |
25e43795 | 15413 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 15414 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
15415 | { |
15416 | if (last_subfile != current_subfile) | |
15417 | { | |
15418 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
15419 | if (last_subfile) | |
c91513d8 | 15420 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
15421 | last_subfile = current_subfile; |
15422 | } | |
7019d805 | 15423 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 15424 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 15425 | } |
366da635 | 15426 | } |
c906108c SS |
15427 | basic_block = 0; |
15428 | break; | |
15429 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
15430 | { |
15431 | CORE_ADDR adjust | |
15432 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
15433 | ||
15434 | address += (((op_index + adjust) | |
15435 | / lh->maximum_ops_per_instruction) | |
15436 | * lh->minimum_instruction_length); | |
15437 | op_index = ((op_index + adjust) | |
15438 | % lh->maximum_ops_per_instruction); | |
15439 | line_ptr += bytes_read; | |
15440 | } | |
c906108c SS |
15441 | break; |
15442 | case DW_LNS_advance_line: | |
15443 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
15444 | line_ptr += bytes_read; | |
15445 | break; | |
15446 | case DW_LNS_set_file: | |
debd256d | 15447 | { |
a738430d MK |
15448 | /* The arrays lh->include_dirs and lh->file_names are |
15449 | 0-based, but the directory and file name numbers in | |
15450 | the statement program are 1-based. */ | |
debd256d | 15451 | struct file_entry *fe; |
4f1520fb | 15452 | char *dir = NULL; |
a738430d | 15453 | |
debd256d JB |
15454 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
15455 | line_ptr += bytes_read; | |
59205f5a | 15456 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
15457 | dwarf2_debug_line_missing_file_complaint (); |
15458 | else | |
15459 | { | |
15460 | fe = &lh->file_names[file - 1]; | |
15461 | if (fe->dir_index) | |
15462 | dir = lh->include_dirs[fe->dir_index - 1]; | |
15463 | if (!decode_for_pst_p) | |
15464 | { | |
15465 | last_subfile = current_subfile; | |
15466 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
15467 | } | |
15468 | } | |
debd256d | 15469 | } |
c906108c SS |
15470 | break; |
15471 | case DW_LNS_set_column: | |
15472 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
15473 | line_ptr += bytes_read; | |
15474 | break; | |
15475 | case DW_LNS_negate_stmt: | |
15476 | is_stmt = (!is_stmt); | |
15477 | break; | |
15478 | case DW_LNS_set_basic_block: | |
15479 | basic_block = 1; | |
15480 | break; | |
c2c6d25f JM |
15481 | /* Add to the address register of the state machine the |
15482 | address increment value corresponding to special opcode | |
a738430d MK |
15483 | 255. I.e., this value is scaled by the minimum |
15484 | instruction length since special opcode 255 would have | |
b021a221 | 15485 | scaled the increment. */ |
c906108c | 15486 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
15487 | { |
15488 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
15489 | ||
15490 | address += (((op_index + adjust) | |
15491 | / lh->maximum_ops_per_instruction) | |
15492 | * lh->minimum_instruction_length); | |
15493 | op_index = ((op_index + adjust) | |
15494 | % lh->maximum_ops_per_instruction); | |
15495 | } | |
c906108c SS |
15496 | break; |
15497 | case DW_LNS_fixed_advance_pc: | |
15498 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 15499 | op_index = 0; |
c906108c SS |
15500 | line_ptr += 2; |
15501 | break; | |
9aa1fe7e | 15502 | default: |
a738430d MK |
15503 | { |
15504 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 15505 | int i; |
a738430d | 15506 | |
debd256d | 15507 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
15508 | { |
15509 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
15510 | line_ptr += bytes_read; | |
15511 | } | |
15512 | } | |
c906108c SS |
15513 | } |
15514 | } | |
59205f5a JB |
15515 | if (lh->num_file_names < file || file == 0) |
15516 | dwarf2_debug_line_missing_file_complaint (); | |
15517 | else | |
15518 | { | |
15519 | lh->file_names[file - 1].included_p = 1; | |
15520 | if (!decode_for_pst_p) | |
fbf65064 UW |
15521 | { |
15522 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 15523 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 15524 | } |
59205f5a | 15525 | } |
c906108c | 15526 | } |
f3f5162e DE |
15527 | } |
15528 | ||
15529 | /* Decode the Line Number Program (LNP) for the given line_header | |
15530 | structure and CU. The actual information extracted and the type | |
15531 | of structures created from the LNP depends on the value of PST. | |
15532 | ||
15533 | 1. If PST is NULL, then this procedure uses the data from the program | |
15534 | to create all necessary symbol tables, and their linetables. | |
15535 | ||
15536 | 2. If PST is not NULL, this procedure reads the program to determine | |
15537 | the list of files included by the unit represented by PST, and | |
15538 | builds all the associated partial symbol tables. | |
15539 | ||
15540 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
15541 | It is used for relative paths in the line table. | |
15542 | NOTE: When processing partial symtabs (pst != NULL), | |
15543 | comp_dir == pst->dirname. | |
15544 | ||
15545 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
15546 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
15547 | symtab we don't use it in the name of the psymtabs we create. | |
15548 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
15549 | A good testcase for this is mb-inline.exp. */ | |
15550 | ||
15551 | static void | |
15552 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, | |
15553 | struct dwarf2_cu *cu, struct partial_symtab *pst, | |
15554 | int want_line_info) | |
15555 | { | |
15556 | struct objfile *objfile = cu->objfile; | |
15557 | const int decode_for_pst_p = (pst != NULL); | |
15558 | struct subfile *first_subfile = current_subfile; | |
15559 | ||
15560 | if (want_line_info) | |
15561 | dwarf_decode_lines_1 (lh, comp_dir, cu, pst); | |
aaa75496 JB |
15562 | |
15563 | if (decode_for_pst_p) | |
15564 | { | |
15565 | int file_index; | |
15566 | ||
15567 | /* Now that we're done scanning the Line Header Program, we can | |
15568 | create the psymtab of each included file. */ | |
15569 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
15570 | if (lh->file_names[file_index].included_p == 1) | |
15571 | { | |
c6da4cef DE |
15572 | char *include_name = |
15573 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
15574 | if (include_name != NULL) | |
aaa75496 JB |
15575 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
15576 | } | |
15577 | } | |
cb1df416 DJ |
15578 | else |
15579 | { | |
15580 | /* Make sure a symtab is created for every file, even files | |
15581 | which contain only variables (i.e. no code with associated | |
15582 | line numbers). */ | |
cb1df416 | 15583 | int i; |
cb1df416 DJ |
15584 | |
15585 | for (i = 0; i < lh->num_file_names; i++) | |
15586 | { | |
15587 | char *dir = NULL; | |
f3f5162e | 15588 | struct file_entry *fe; |
9a619af0 | 15589 | |
cb1df416 DJ |
15590 | fe = &lh->file_names[i]; |
15591 | if (fe->dir_index) | |
15592 | dir = lh->include_dirs[fe->dir_index - 1]; | |
15593 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
15594 | ||
15595 | /* Skip the main file; we don't need it, and it must be | |
15596 | allocated last, so that it will show up before the | |
15597 | non-primary symtabs in the objfile's symtab list. */ | |
15598 | if (current_subfile == first_subfile) | |
15599 | continue; | |
15600 | ||
15601 | if (current_subfile->symtab == NULL) | |
15602 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
bb5ed363 | 15603 | objfile); |
cb1df416 DJ |
15604 | fe->symtab = current_subfile->symtab; |
15605 | } | |
15606 | } | |
c906108c SS |
15607 | } |
15608 | ||
15609 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
15610 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
15611 | or NULL if not known. COMP_DIR is the compilation directory for the |
15612 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
15613 | This routine tries to keep line numbers from identical absolute and |
15614 | relative file names in a common subfile. | |
15615 | ||
15616 | Using the `list' example from the GDB testsuite, which resides in | |
15617 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
15618 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
15619 | ||
c5aa993b JM |
15620 | DW_AT_name: /srcdir/list0.c |
15621 | DW_AT_comp_dir: /compdir | |
357e46e7 | 15622 | files.files[0].name: list0.h |
c5aa993b | 15623 | files.files[0].dir: /srcdir |
357e46e7 | 15624 | files.files[1].name: list0.c |
c5aa993b | 15625 | files.files[1].dir: /srcdir |
c906108c SS |
15626 | |
15627 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
15628 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
15629 | start_subfile will ensure that this happens provided that we pass the | |
15630 | concatenation of files.files[1].dir and files.files[1].name as the | |
15631 | subfile's name. */ | |
c906108c SS |
15632 | |
15633 | static void | |
3e43a32a MS |
15634 | dwarf2_start_subfile (char *filename, const char *dirname, |
15635 | const char *comp_dir) | |
c906108c | 15636 | { |
4f1520fb FR |
15637 | char *fullname; |
15638 | ||
15639 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
15640 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
15641 | second argument to start_subfile. To be consistent, we do the | |
15642 | same here. In order not to lose the line information directory, | |
15643 | we concatenate it to the filename when it makes sense. | |
15644 | Note that the Dwarf3 standard says (speaking of filenames in line | |
15645 | information): ``The directory index is ignored for file names | |
15646 | that represent full path names''. Thus ignoring dirname in the | |
15647 | `else' branch below isn't an issue. */ | |
c906108c | 15648 | |
d5166ae1 | 15649 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
15650 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
15651 | else | |
15652 | fullname = filename; | |
c906108c | 15653 | |
4f1520fb FR |
15654 | start_subfile (fullname, comp_dir); |
15655 | ||
15656 | if (fullname != filename) | |
15657 | xfree (fullname); | |
c906108c SS |
15658 | } |
15659 | ||
f4dc4d17 DE |
15660 | /* Start a symtab for DWARF. |
15661 | NAME, COMP_DIR, LOW_PC are passed to start_symtab. */ | |
15662 | ||
15663 | static void | |
15664 | dwarf2_start_symtab (struct dwarf2_cu *cu, | |
15d034d0 | 15665 | const char *name, const char *comp_dir, CORE_ADDR low_pc) |
f4dc4d17 DE |
15666 | { |
15667 | start_symtab (name, comp_dir, low_pc); | |
15668 | record_debugformat ("DWARF 2"); | |
15669 | record_producer (cu->producer); | |
15670 | ||
15671 | /* We assume that we're processing GCC output. */ | |
15672 | processing_gcc_compilation = 2; | |
15673 | ||
15674 | processing_has_namespace_info = 0; | |
15675 | } | |
15676 | ||
4c2df51b DJ |
15677 | static void |
15678 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 15679 | struct dwarf2_cu *cu) |
4c2df51b | 15680 | { |
e7c27a73 DJ |
15681 | struct objfile *objfile = cu->objfile; |
15682 | struct comp_unit_head *cu_header = &cu->header; | |
15683 | ||
4c2df51b DJ |
15684 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
15685 | code here to turn a symbol with DW_AT_external and a | |
15686 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
15687 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
15688 | with some versions of binutils) where shared libraries could have | |
15689 | relocations against symbols in their debug information - the | |
15690 | minimal symbol would have the right address, but the debug info | |
15691 | would not. It's no longer necessary, because we will explicitly | |
15692 | apply relocations when we read in the debug information now. */ | |
15693 | ||
15694 | /* A DW_AT_location attribute with no contents indicates that a | |
15695 | variable has been optimized away. */ | |
15696 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
15697 | { | |
15698 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
15699 | return; | |
15700 | } | |
15701 | ||
15702 | /* Handle one degenerate form of location expression specially, to | |
15703 | preserve GDB's previous behavior when section offsets are | |
3019eac3 DE |
15704 | specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index |
15705 | then mark this symbol as LOC_STATIC. */ | |
4c2df51b DJ |
15706 | |
15707 | if (attr_form_is_block (attr) | |
3019eac3 DE |
15708 | && ((DW_BLOCK (attr)->data[0] == DW_OP_addr |
15709 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size) | |
15710 | || (DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index | |
15711 | && (DW_BLOCK (attr)->size | |
15712 | == 1 + leb128_size (&DW_BLOCK (attr)->data[1]))))) | |
4c2df51b | 15713 | { |
891d2f0b | 15714 | unsigned int dummy; |
4c2df51b | 15715 | |
3019eac3 DE |
15716 | if (DW_BLOCK (attr)->data[0] == DW_OP_addr) |
15717 | SYMBOL_VALUE_ADDRESS (sym) = | |
15718 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); | |
15719 | else | |
15720 | SYMBOL_VALUE_ADDRESS (sym) = | |
15721 | read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy); | |
907fc202 | 15722 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
15723 | fixup_symbol_section (sym, objfile); |
15724 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
15725 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
15726 | return; |
15727 | } | |
15728 | ||
15729 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
15730 | expression evaluator, and use LOC_COMPUTED only when necessary | |
15731 | (i.e. when the value of a register or memory location is | |
15732 | referenced, or a thread-local block, etc.). Then again, it might | |
15733 | not be worthwhile. I'm assuming that it isn't unless performance | |
15734 | or memory numbers show me otherwise. */ | |
15735 | ||
e7c27a73 | 15736 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b | 15737 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8be455d7 JK |
15738 | |
15739 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) | |
15740 | cu->has_loclist = 1; | |
4c2df51b DJ |
15741 | } |
15742 | ||
c906108c SS |
15743 | /* Given a pointer to a DWARF information entry, figure out if we need |
15744 | to make a symbol table entry for it, and if so, create a new entry | |
15745 | and return a pointer to it. | |
15746 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
15747 | used the passed type. |
15748 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
15749 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
15750 | |
15751 | static struct symbol * | |
34eaf542 TT |
15752 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
15753 | struct symbol *space) | |
c906108c | 15754 | { |
e7c27a73 | 15755 | struct objfile *objfile = cu->objfile; |
c906108c | 15756 | struct symbol *sym = NULL; |
15d034d0 | 15757 | const char *name; |
c906108c SS |
15758 | struct attribute *attr = NULL; |
15759 | struct attribute *attr2 = NULL; | |
e142c38c | 15760 | CORE_ADDR baseaddr; |
e37fd15a SW |
15761 | struct pending **list_to_add = NULL; |
15762 | ||
edb3359d | 15763 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
15764 | |
15765 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 15766 | |
94af9270 | 15767 | name = dwarf2_name (die, cu); |
c906108c SS |
15768 | if (name) |
15769 | { | |
94af9270 | 15770 | const char *linkagename; |
34eaf542 | 15771 | int suppress_add = 0; |
94af9270 | 15772 | |
34eaf542 TT |
15773 | if (space) |
15774 | sym = space; | |
15775 | else | |
15776 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 15777 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
15778 | |
15779 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 15780 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
15781 | linkagename = dwarf2_physname (name, die, cu); |
15782 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 15783 | |
f55ee35c JK |
15784 | /* Fortran does not have mangling standard and the mangling does differ |
15785 | between gfortran, iFort etc. */ | |
15786 | if (cu->language == language_fortran | |
b250c185 | 15787 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d | 15788 | symbol_set_demangled_name (&(sym->ginfo), |
cfc594ee | 15789 | dwarf2_full_name (name, die, cu), |
29df156d | 15790 | NULL); |
f55ee35c | 15791 | |
c906108c | 15792 | /* Default assumptions. |
c5aa993b | 15793 | Use the passed type or decode it from the die. */ |
176620f1 | 15794 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 15795 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
15796 | if (type != NULL) |
15797 | SYMBOL_TYPE (sym) = type; | |
15798 | else | |
e7c27a73 | 15799 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
15800 | attr = dwarf2_attr (die, |
15801 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
15802 | cu); | |
c906108c SS |
15803 | if (attr) |
15804 | { | |
15805 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
15806 | } | |
cb1df416 | 15807 | |
edb3359d DJ |
15808 | attr = dwarf2_attr (die, |
15809 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
15810 | cu); | |
cb1df416 DJ |
15811 | if (attr) |
15812 | { | |
15813 | int file_index = DW_UNSND (attr); | |
9a619af0 | 15814 | |
cb1df416 DJ |
15815 | if (cu->line_header == NULL |
15816 | || file_index > cu->line_header->num_file_names) | |
15817 | complaint (&symfile_complaints, | |
15818 | _("file index out of range")); | |
1c3d648d | 15819 | else if (file_index > 0) |
cb1df416 DJ |
15820 | { |
15821 | struct file_entry *fe; | |
9a619af0 | 15822 | |
cb1df416 DJ |
15823 | fe = &cu->line_header->file_names[file_index - 1]; |
15824 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
15825 | } | |
15826 | } | |
15827 | ||
c906108c SS |
15828 | switch (die->tag) |
15829 | { | |
15830 | case DW_TAG_label: | |
e142c38c | 15831 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
15832 | if (attr) |
15833 | { | |
15834 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
15835 | } | |
0f5238ed TT |
15836 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
15837 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 15838 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 15839 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
15840 | break; |
15841 | case DW_TAG_subprogram: | |
15842 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
15843 | finish_block. */ | |
15844 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 15845 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
15846 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
15847 | || cu->language == language_ada) | |
c906108c | 15848 | { |
2cfa0c8d JB |
15849 | /* Subprograms marked external are stored as a global symbol. |
15850 | Ada subprograms, whether marked external or not, are always | |
15851 | stored as a global symbol, because we want to be able to | |
15852 | access them globally. For instance, we want to be able | |
15853 | to break on a nested subprogram without having to | |
15854 | specify the context. */ | |
e37fd15a | 15855 | list_to_add = &global_symbols; |
c906108c SS |
15856 | } |
15857 | else | |
15858 | { | |
e37fd15a | 15859 | list_to_add = cu->list_in_scope; |
c906108c SS |
15860 | } |
15861 | break; | |
edb3359d DJ |
15862 | case DW_TAG_inlined_subroutine: |
15863 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
15864 | finish_block. */ | |
15865 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
15866 | SYMBOL_INLINED (sym) = 1; | |
481860b3 | 15867 | list_to_add = cu->list_in_scope; |
edb3359d | 15868 | break; |
34eaf542 TT |
15869 | case DW_TAG_template_value_param: |
15870 | suppress_add = 1; | |
15871 | /* Fall through. */ | |
72929c62 | 15872 | case DW_TAG_constant: |
c906108c | 15873 | case DW_TAG_variable: |
254e6b9e | 15874 | case DW_TAG_member: |
0963b4bd MS |
15875 | /* Compilation with minimal debug info may result in |
15876 | variables with missing type entries. Change the | |
15877 | misleading `void' type to something sensible. */ | |
c906108c | 15878 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 15879 | SYMBOL_TYPE (sym) |
46bf5051 | 15880 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 15881 | |
e142c38c | 15882 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
15883 | /* In the case of DW_TAG_member, we should only be called for |
15884 | static const members. */ | |
15885 | if (die->tag == DW_TAG_member) | |
15886 | { | |
3863f96c DE |
15887 | /* dwarf2_add_field uses die_is_declaration, |
15888 | so we do the same. */ | |
254e6b9e DE |
15889 | gdb_assert (die_is_declaration (die, cu)); |
15890 | gdb_assert (attr); | |
15891 | } | |
c906108c SS |
15892 | if (attr) |
15893 | { | |
e7c27a73 | 15894 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 15895 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 15896 | if (!suppress_add) |
34eaf542 TT |
15897 | { |
15898 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 15899 | list_to_add = &global_symbols; |
34eaf542 | 15900 | else |
e37fd15a | 15901 | list_to_add = cu->list_in_scope; |
34eaf542 | 15902 | } |
c906108c SS |
15903 | break; |
15904 | } | |
e142c38c | 15905 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
15906 | if (attr) |
15907 | { | |
e7c27a73 | 15908 | var_decode_location (attr, sym, cu); |
e142c38c | 15909 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
4357ac6c TT |
15910 | |
15911 | /* Fortran explicitly imports any global symbols to the local | |
15912 | scope by DW_TAG_common_block. */ | |
15913 | if (cu->language == language_fortran && die->parent | |
15914 | && die->parent->tag == DW_TAG_common_block) | |
15915 | attr2 = NULL; | |
15916 | ||
caac4577 JG |
15917 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
15918 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
15919 | && !dwarf2_per_objfile->has_section_at_zero) | |
15920 | { | |
15921 | /* When a static variable is eliminated by the linker, | |
15922 | the corresponding debug information is not stripped | |
15923 | out, but the variable address is set to null; | |
15924 | do not add such variables into symbol table. */ | |
15925 | } | |
15926 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 15927 | { |
f55ee35c JK |
15928 | /* Workaround gfortran PR debug/40040 - it uses |
15929 | DW_AT_location for variables in -fPIC libraries which may | |
15930 | get overriden by other libraries/executable and get | |
15931 | a different address. Resolve it by the minimal symbol | |
15932 | which may come from inferior's executable using copy | |
15933 | relocation. Make this workaround only for gfortran as for | |
15934 | other compilers GDB cannot guess the minimal symbol | |
15935 | Fortran mangling kind. */ | |
15936 | if (cu->language == language_fortran && die->parent | |
15937 | && die->parent->tag == DW_TAG_module | |
15938 | && cu->producer | |
15939 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
15940 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
15941 | ||
1c809c68 TT |
15942 | /* A variable with DW_AT_external is never static, |
15943 | but it may be block-scoped. */ | |
15944 | list_to_add = (cu->list_in_scope == &file_symbols | |
15945 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 15946 | } |
c906108c | 15947 | else |
e37fd15a | 15948 | list_to_add = cu->list_in_scope; |
c906108c SS |
15949 | } |
15950 | else | |
15951 | { | |
15952 | /* We do not know the address of this symbol. | |
c5aa993b JM |
15953 | If it is an external symbol and we have type information |
15954 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
15955 | The address of the variable will then be determined from | |
15956 | the minimal symbol table whenever the variable is | |
15957 | referenced. */ | |
e142c38c | 15958 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
0971de02 TT |
15959 | |
15960 | /* Fortran explicitly imports any global symbols to the local | |
15961 | scope by DW_TAG_common_block. */ | |
15962 | if (cu->language == language_fortran && die->parent | |
15963 | && die->parent->tag == DW_TAG_common_block) | |
15964 | { | |
15965 | /* SYMBOL_CLASS doesn't matter here because | |
15966 | read_common_block is going to reset it. */ | |
15967 | if (!suppress_add) | |
15968 | list_to_add = cu->list_in_scope; | |
15969 | } | |
15970 | else if (attr2 && (DW_UNSND (attr2) != 0) | |
15971 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) | |
c906108c | 15972 | { |
0fe7935b DJ |
15973 | /* A variable with DW_AT_external is never static, but it |
15974 | may be block-scoped. */ | |
15975 | list_to_add = (cu->list_in_scope == &file_symbols | |
15976 | ? &global_symbols : cu->list_in_scope); | |
15977 | ||
c906108c | 15978 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 15979 | } |
442ddf59 JK |
15980 | else if (!die_is_declaration (die, cu)) |
15981 | { | |
15982 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
15983 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
15984 | if (!suppress_add) |
15985 | list_to_add = cu->list_in_scope; | |
442ddf59 | 15986 | } |
c906108c SS |
15987 | } |
15988 | break; | |
15989 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
15990 | /* If we are inside a function, mark this as an argument. If |
15991 | not, we might be looking at an argument to an inlined function | |
15992 | when we do not have enough information to show inlined frames; | |
15993 | pretend it's a local variable in that case so that the user can | |
15994 | still see it. */ | |
15995 | if (context_stack_depth > 0 | |
15996 | && context_stack[context_stack_depth - 1].name != NULL) | |
15997 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 15998 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
15999 | if (attr) |
16000 | { | |
e7c27a73 | 16001 | var_decode_location (attr, sym, cu); |
c906108c | 16002 | } |
e142c38c | 16003 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
16004 | if (attr) |
16005 | { | |
e7c27a73 | 16006 | dwarf2_const_value (attr, sym, cu); |
c906108c | 16007 | } |
f346a30d | 16008 | |
e37fd15a | 16009 | list_to_add = cu->list_in_scope; |
c906108c SS |
16010 | break; |
16011 | case DW_TAG_unspecified_parameters: | |
16012 | /* From varargs functions; gdb doesn't seem to have any | |
16013 | interest in this information, so just ignore it for now. | |
16014 | (FIXME?) */ | |
16015 | break; | |
34eaf542 TT |
16016 | case DW_TAG_template_type_param: |
16017 | suppress_add = 1; | |
16018 | /* Fall through. */ | |
c906108c | 16019 | case DW_TAG_class_type: |
680b30c7 | 16020 | case DW_TAG_interface_type: |
c906108c SS |
16021 | case DW_TAG_structure_type: |
16022 | case DW_TAG_union_type: | |
72019c9c | 16023 | case DW_TAG_set_type: |
c906108c SS |
16024 | case DW_TAG_enumeration_type: |
16025 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 16026 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 16027 | |
63d06c5c | 16028 | { |
987504bb | 16029 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
16030 | really ever be static objects: otherwise, if you try |
16031 | to, say, break of a class's method and you're in a file | |
16032 | which doesn't mention that class, it won't work unless | |
16033 | the check for all static symbols in lookup_symbol_aux | |
16034 | saves you. See the OtherFileClass tests in | |
16035 | gdb.c++/namespace.exp. */ | |
16036 | ||
e37fd15a | 16037 | if (!suppress_add) |
34eaf542 | 16038 | { |
34eaf542 TT |
16039 | list_to_add = (cu->list_in_scope == &file_symbols |
16040 | && (cu->language == language_cplus | |
16041 | || cu->language == language_java) | |
16042 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 16043 | |
64382290 TT |
16044 | /* The semantics of C++ state that "struct foo { |
16045 | ... }" also defines a typedef for "foo". A Java | |
16046 | class declaration also defines a typedef for the | |
16047 | class. */ | |
16048 | if (cu->language == language_cplus | |
16049 | || cu->language == language_java | |
16050 | || cu->language == language_ada) | |
16051 | { | |
16052 | /* The symbol's name is already allocated along | |
16053 | with this objfile, so we don't need to | |
16054 | duplicate it for the type. */ | |
16055 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
16056 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
16057 | } | |
63d06c5c DC |
16058 | } |
16059 | } | |
c906108c SS |
16060 | break; |
16061 | case DW_TAG_typedef: | |
63d06c5c DC |
16062 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
16063 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 16064 | list_to_add = cu->list_in_scope; |
63d06c5c | 16065 | break; |
c906108c | 16066 | case DW_TAG_base_type: |
a02abb62 | 16067 | case DW_TAG_subrange_type: |
c906108c | 16068 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 16069 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 16070 | list_to_add = cu->list_in_scope; |
c906108c SS |
16071 | break; |
16072 | case DW_TAG_enumerator: | |
e142c38c | 16073 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
16074 | if (attr) |
16075 | { | |
e7c27a73 | 16076 | dwarf2_const_value (attr, sym, cu); |
c906108c | 16077 | } |
63d06c5c DC |
16078 | { |
16079 | /* NOTE: carlton/2003-11-10: See comment above in the | |
16080 | DW_TAG_class_type, etc. block. */ | |
16081 | ||
e142c38c | 16082 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
16083 | && (cu->language == language_cplus |
16084 | || cu->language == language_java) | |
e142c38c | 16085 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 16086 | } |
c906108c | 16087 | break; |
5c4e30ca DC |
16088 | case DW_TAG_namespace: |
16089 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 16090 | list_to_add = &global_symbols; |
5c4e30ca | 16091 | break; |
4357ac6c | 16092 | case DW_TAG_common_block: |
5a352474 | 16093 | SYMBOL_CLASS (sym) = LOC_COMMON_BLOCK; |
4357ac6c TT |
16094 | SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN; |
16095 | add_symbol_to_list (sym, cu->list_in_scope); | |
16096 | break; | |
c906108c SS |
16097 | default: |
16098 | /* Not a tag we recognize. Hopefully we aren't processing | |
16099 | trash data, but since we must specifically ignore things | |
16100 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 16101 | this point. */ |
e2e0b3e5 | 16102 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 16103 | dwarf_tag_name (die->tag)); |
c906108c SS |
16104 | break; |
16105 | } | |
df8a16a1 | 16106 | |
e37fd15a SW |
16107 | if (suppress_add) |
16108 | { | |
16109 | sym->hash_next = objfile->template_symbols; | |
16110 | objfile->template_symbols = sym; | |
16111 | list_to_add = NULL; | |
16112 | } | |
16113 | ||
16114 | if (list_to_add != NULL) | |
16115 | add_symbol_to_list (sym, list_to_add); | |
16116 | ||
df8a16a1 DJ |
16117 | /* For the benefit of old versions of GCC, check for anonymous |
16118 | namespaces based on the demangled name. */ | |
16119 | if (!processing_has_namespace_info | |
94af9270 | 16120 | && cu->language == language_cplus) |
a10964d1 | 16121 | cp_scan_for_anonymous_namespaces (sym, objfile); |
c906108c SS |
16122 | } |
16123 | return (sym); | |
16124 | } | |
16125 | ||
34eaf542 TT |
16126 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
16127 | ||
16128 | static struct symbol * | |
16129 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
16130 | { | |
16131 | return new_symbol_full (die, type, cu, NULL); | |
16132 | } | |
16133 | ||
98bfdba5 PA |
16134 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
16135 | zero-extend it as appropriate for the symbol's type. The DWARF | |
16136 | standard (v4) is not entirely clear about the meaning of using | |
16137 | DW_FORM_dataN for a constant with a signed type, where the type is | |
16138 | wider than the data. The conclusion of a discussion on the DWARF | |
16139 | list was that this is unspecified. We choose to always zero-extend | |
16140 | because that is the interpretation long in use by GCC. */ | |
c906108c | 16141 | |
98bfdba5 PA |
16142 | static gdb_byte * |
16143 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
16144 | const char *name, struct obstack *obstack, | |
12df843f | 16145 | struct dwarf2_cu *cu, LONGEST *value, int bits) |
c906108c | 16146 | { |
e7c27a73 | 16147 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
16148 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
16149 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
16150 | LONGEST l = DW_UNSND (attr); |
16151 | ||
16152 | if (bits < sizeof (*value) * 8) | |
16153 | { | |
16154 | l &= ((LONGEST) 1 << bits) - 1; | |
16155 | *value = l; | |
16156 | } | |
16157 | else if (bits == sizeof (*value) * 8) | |
16158 | *value = l; | |
16159 | else | |
16160 | { | |
16161 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
16162 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
16163 | return bytes; | |
16164 | } | |
16165 | ||
16166 | return NULL; | |
16167 | } | |
16168 | ||
16169 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
16170 | the value does not fit in *VALUE, set *BYTES - either already | |
16171 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
16172 | or, set *BATON, if we translated the constant to a location | |
16173 | expression. */ | |
16174 | ||
16175 | static void | |
16176 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
16177 | const char *name, struct obstack *obstack, | |
16178 | struct dwarf2_cu *cu, | |
12df843f | 16179 | LONGEST *value, gdb_byte **bytes, |
98bfdba5 PA |
16180 | struct dwarf2_locexpr_baton **baton) |
16181 | { | |
16182 | struct objfile *objfile = cu->objfile; | |
16183 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 16184 | struct dwarf_block *blk; |
98bfdba5 PA |
16185 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
16186 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
16187 | ||
16188 | *value = 0; | |
16189 | *bytes = NULL; | |
16190 | *baton = NULL; | |
c906108c SS |
16191 | |
16192 | switch (attr->form) | |
16193 | { | |
16194 | case DW_FORM_addr: | |
3019eac3 | 16195 | case DW_FORM_GNU_addr_index: |
ac56253d | 16196 | { |
ac56253d TT |
16197 | gdb_byte *data; |
16198 | ||
98bfdba5 PA |
16199 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
16200 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 16201 | cu_header->addr_size, |
98bfdba5 | 16202 | TYPE_LENGTH (type)); |
ac56253d TT |
16203 | /* Symbols of this form are reasonably rare, so we just |
16204 | piggyback on the existing location code rather than writing | |
16205 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
16206 | *baton = obstack_alloc (&objfile->objfile_obstack, |
16207 | sizeof (struct dwarf2_locexpr_baton)); | |
16208 | (*baton)->per_cu = cu->per_cu; | |
16209 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 16210 | |
98bfdba5 PA |
16211 | (*baton)->size = 2 + cu_header->addr_size; |
16212 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
16213 | (*baton)->data = data; | |
ac56253d TT |
16214 | |
16215 | data[0] = DW_OP_addr; | |
16216 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
16217 | byte_order, DW_ADDR (attr)); | |
16218 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 16219 | } |
c906108c | 16220 | break; |
4ac36638 | 16221 | case DW_FORM_string: |
93b5768b | 16222 | case DW_FORM_strp: |
3019eac3 | 16223 | case DW_FORM_GNU_str_index: |
36586728 | 16224 | case DW_FORM_GNU_strp_alt: |
98bfdba5 PA |
16225 | /* DW_STRING is already allocated on the objfile obstack, point |
16226 | directly to it. */ | |
16227 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 16228 | break; |
c906108c SS |
16229 | case DW_FORM_block1: |
16230 | case DW_FORM_block2: | |
16231 | case DW_FORM_block4: | |
16232 | case DW_FORM_block: | |
2dc7f7b3 | 16233 | case DW_FORM_exprloc: |
c906108c | 16234 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
16235 | if (TYPE_LENGTH (type) != blk->size) |
16236 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
16237 | TYPE_LENGTH (type)); | |
16238 | *bytes = blk->data; | |
c906108c | 16239 | break; |
2df3850c JM |
16240 | |
16241 | /* The DW_AT_const_value attributes are supposed to carry the | |
16242 | symbol's value "represented as it would be on the target | |
16243 | architecture." By the time we get here, it's already been | |
16244 | converted to host endianness, so we just need to sign- or | |
16245 | zero-extend it as appropriate. */ | |
16246 | case DW_FORM_data1: | |
3e43a32a MS |
16247 | *bytes = dwarf2_const_value_data (attr, type, name, |
16248 | obstack, cu, value, 8); | |
2df3850c | 16249 | break; |
c906108c | 16250 | case DW_FORM_data2: |
3e43a32a MS |
16251 | *bytes = dwarf2_const_value_data (attr, type, name, |
16252 | obstack, cu, value, 16); | |
2df3850c | 16253 | break; |
c906108c | 16254 | case DW_FORM_data4: |
3e43a32a MS |
16255 | *bytes = dwarf2_const_value_data (attr, type, name, |
16256 | obstack, cu, value, 32); | |
2df3850c | 16257 | break; |
c906108c | 16258 | case DW_FORM_data8: |
3e43a32a MS |
16259 | *bytes = dwarf2_const_value_data (attr, type, name, |
16260 | obstack, cu, value, 64); | |
2df3850c JM |
16261 | break; |
16262 | ||
c906108c | 16263 | case DW_FORM_sdata: |
98bfdba5 | 16264 | *value = DW_SND (attr); |
2df3850c JM |
16265 | break; |
16266 | ||
c906108c | 16267 | case DW_FORM_udata: |
98bfdba5 | 16268 | *value = DW_UNSND (attr); |
c906108c | 16269 | break; |
2df3850c | 16270 | |
c906108c | 16271 | default: |
4d3c2250 | 16272 | complaint (&symfile_complaints, |
e2e0b3e5 | 16273 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 16274 | dwarf_form_name (attr->form)); |
98bfdba5 | 16275 | *value = 0; |
c906108c SS |
16276 | break; |
16277 | } | |
16278 | } | |
16279 | ||
2df3850c | 16280 | |
98bfdba5 PA |
16281 | /* Copy constant value from an attribute to a symbol. */ |
16282 | ||
2df3850c | 16283 | static void |
98bfdba5 PA |
16284 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
16285 | struct dwarf2_cu *cu) | |
2df3850c | 16286 | { |
98bfdba5 PA |
16287 | struct objfile *objfile = cu->objfile; |
16288 | struct comp_unit_head *cu_header = &cu->header; | |
12df843f | 16289 | LONGEST value; |
98bfdba5 PA |
16290 | gdb_byte *bytes; |
16291 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 16292 | |
98bfdba5 PA |
16293 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
16294 | SYMBOL_PRINT_NAME (sym), | |
16295 | &objfile->objfile_obstack, cu, | |
16296 | &value, &bytes, &baton); | |
2df3850c | 16297 | |
98bfdba5 PA |
16298 | if (baton != NULL) |
16299 | { | |
16300 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
16301 | SYMBOL_LOCATION_BATON (sym) = baton; | |
16302 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
16303 | } | |
16304 | else if (bytes != NULL) | |
16305 | { | |
16306 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
16307 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
16308 | } | |
16309 | else | |
16310 | { | |
16311 | SYMBOL_VALUE (sym) = value; | |
16312 | SYMBOL_CLASS (sym) = LOC_CONST; | |
16313 | } | |
2df3850c JM |
16314 | } |
16315 | ||
c906108c SS |
16316 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
16317 | ||
16318 | static struct type * | |
e7c27a73 | 16319 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 16320 | { |
c906108c | 16321 | struct attribute *type_attr; |
c906108c | 16322 | |
e142c38c | 16323 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
16324 | if (!type_attr) |
16325 | { | |
16326 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 16327 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 16328 | } |
348e048f | 16329 | |
673bfd45 | 16330 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
16331 | } |
16332 | ||
b4ba55a1 JB |
16333 | /* True iff CU's producer generates GNAT Ada auxiliary information |
16334 | that allows to find parallel types through that information instead | |
16335 | of having to do expensive parallel lookups by type name. */ | |
16336 | ||
16337 | static int | |
16338 | need_gnat_info (struct dwarf2_cu *cu) | |
16339 | { | |
16340 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
16341 | of GNAT produces this auxiliary information, without any indication | |
16342 | that it is produced. Part of enhancing the FSF version of GNAT | |
16343 | to produce that information will be to put in place an indicator | |
16344 | that we can use in order to determine whether the descriptive type | |
16345 | info is available or not. One suggestion that has been made is | |
16346 | to use a new attribute, attached to the CU die. For now, assume | |
16347 | that the descriptive type info is not available. */ | |
16348 | return 0; | |
16349 | } | |
16350 | ||
b4ba55a1 JB |
16351 | /* Return the auxiliary type of the die in question using its |
16352 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
16353 | attribute is not present. */ | |
16354 | ||
16355 | static struct type * | |
16356 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
16357 | { | |
b4ba55a1 | 16358 | struct attribute *type_attr; |
b4ba55a1 JB |
16359 | |
16360 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
16361 | if (!type_attr) | |
16362 | return NULL; | |
16363 | ||
673bfd45 | 16364 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
16365 | } |
16366 | ||
16367 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
16368 | descriptive type accordingly. */ | |
16369 | ||
16370 | static void | |
16371 | set_descriptive_type (struct type *type, struct die_info *die, | |
16372 | struct dwarf2_cu *cu) | |
16373 | { | |
16374 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
16375 | ||
16376 | if (descriptive_type) | |
16377 | { | |
16378 | ALLOCATE_GNAT_AUX_TYPE (type); | |
16379 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
16380 | } | |
16381 | } | |
16382 | ||
c906108c SS |
16383 | /* Return the containing type of the die in question using its |
16384 | DW_AT_containing_type attribute. */ | |
16385 | ||
16386 | static struct type * | |
e7c27a73 | 16387 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 16388 | { |
c906108c | 16389 | struct attribute *type_attr; |
c906108c | 16390 | |
e142c38c | 16391 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
16392 | if (!type_attr) |
16393 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
16394 | "[in module %s]"), cu->objfile->name); | |
16395 | ||
673bfd45 | 16396 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
16397 | } |
16398 | ||
673bfd45 DE |
16399 | /* Look up the type of DIE in CU using its type attribute ATTR. |
16400 | If there is no type substitute an error marker. */ | |
16401 | ||
c906108c | 16402 | static struct type * |
673bfd45 DE |
16403 | lookup_die_type (struct die_info *die, struct attribute *attr, |
16404 | struct dwarf2_cu *cu) | |
c906108c | 16405 | { |
bb5ed363 | 16406 | struct objfile *objfile = cu->objfile; |
f792889a DJ |
16407 | struct type *this_type; |
16408 | ||
673bfd45 DE |
16409 | /* First see if we have it cached. */ |
16410 | ||
36586728 TT |
16411 | if (attr->form == DW_FORM_GNU_ref_alt) |
16412 | { | |
16413 | struct dwarf2_per_cu_data *per_cu; | |
16414 | sect_offset offset = dwarf2_get_ref_die_offset (attr); | |
16415 | ||
16416 | per_cu = dwarf2_find_containing_comp_unit (offset, 1, cu->objfile); | |
16417 | this_type = get_die_type_at_offset (offset, per_cu); | |
16418 | } | |
16419 | else if (is_ref_attr (attr)) | |
673bfd45 | 16420 | { |
b64f50a1 | 16421 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
673bfd45 DE |
16422 | |
16423 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
16424 | } | |
55f1336d | 16425 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
16426 | { |
16427 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
673bfd45 DE |
16428 | |
16429 | /* sig_type will be NULL if the signatured type is missing from | |
16430 | the debug info. */ | |
16431 | if (sig_type == NULL) | |
16432 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
16433 | "at 0x%x [in module %s]"), | |
b64f50a1 | 16434 | die->offset.sect_off, objfile->name); |
673bfd45 | 16435 | |
3019eac3 DE |
16436 | gdb_assert (sig_type->per_cu.is_debug_types); |
16437 | /* If we haven't filled in type_offset_in_section yet, then we | |
16438 | haven't read the type in yet. */ | |
16439 | this_type = NULL; | |
16440 | if (sig_type->type_offset_in_section.sect_off != 0) | |
16441 | { | |
16442 | this_type = | |
16443 | get_die_type_at_offset (sig_type->type_offset_in_section, | |
16444 | &sig_type->per_cu); | |
16445 | } | |
673bfd45 DE |
16446 | } |
16447 | else | |
16448 | { | |
16449 | dump_die_for_error (die); | |
16450 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
bb5ed363 | 16451 | dwarf_attr_name (attr->name), objfile->name); |
673bfd45 DE |
16452 | } |
16453 | ||
16454 | /* If not cached we need to read it in. */ | |
16455 | ||
16456 | if (this_type == NULL) | |
16457 | { | |
16458 | struct die_info *type_die; | |
16459 | struct dwarf2_cu *type_cu = cu; | |
16460 | ||
16461 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
3019eac3 DE |
16462 | /* If we found the type now, it's probably because the type came |
16463 | from an inter-CU reference and the type's CU got expanded before | |
16464 | ours. */ | |
16465 | this_type = get_die_type (type_die, type_cu); | |
16466 | if (this_type == NULL) | |
16467 | this_type = read_type_die_1 (type_die, type_cu); | |
673bfd45 DE |
16468 | } |
16469 | ||
16470 | /* If we still don't have a type use an error marker. */ | |
16471 | ||
16472 | if (this_type == NULL) | |
c906108c | 16473 | { |
b00fdb78 TT |
16474 | char *message, *saved; |
16475 | ||
16476 | /* read_type_die already issued a complaint. */ | |
16477 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
bb5ed363 | 16478 | objfile->name, |
b64f50a1 JK |
16479 | cu->header.offset.sect_off, |
16480 | die->offset.sect_off); | |
bb5ed363 | 16481 | saved = obstack_copy0 (&objfile->objfile_obstack, |
b00fdb78 TT |
16482 | message, strlen (message)); |
16483 | xfree (message); | |
16484 | ||
bb5ed363 | 16485 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile); |
c906108c | 16486 | } |
673bfd45 | 16487 | |
f792889a | 16488 | return this_type; |
c906108c SS |
16489 | } |
16490 | ||
673bfd45 DE |
16491 | /* Return the type in DIE, CU. |
16492 | Returns NULL for invalid types. | |
16493 | ||
16494 | This first does a lookup in the appropriate type_hash table, | |
16495 | and only reads the die in if necessary. | |
16496 | ||
16497 | NOTE: This can be called when reading in partial or full symbols. */ | |
16498 | ||
f792889a | 16499 | static struct type * |
e7c27a73 | 16500 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 16501 | { |
f792889a DJ |
16502 | struct type *this_type; |
16503 | ||
16504 | this_type = get_die_type (die, cu); | |
16505 | if (this_type) | |
16506 | return this_type; | |
16507 | ||
673bfd45 DE |
16508 | return read_type_die_1 (die, cu); |
16509 | } | |
16510 | ||
16511 | /* Read the type in DIE, CU. | |
16512 | Returns NULL for invalid types. */ | |
16513 | ||
16514 | static struct type * | |
16515 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
16516 | { | |
16517 | struct type *this_type = NULL; | |
16518 | ||
c906108c SS |
16519 | switch (die->tag) |
16520 | { | |
16521 | case DW_TAG_class_type: | |
680b30c7 | 16522 | case DW_TAG_interface_type: |
c906108c SS |
16523 | case DW_TAG_structure_type: |
16524 | case DW_TAG_union_type: | |
f792889a | 16525 | this_type = read_structure_type (die, cu); |
c906108c SS |
16526 | break; |
16527 | case DW_TAG_enumeration_type: | |
f792889a | 16528 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
16529 | break; |
16530 | case DW_TAG_subprogram: | |
16531 | case DW_TAG_subroutine_type: | |
edb3359d | 16532 | case DW_TAG_inlined_subroutine: |
f792889a | 16533 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
16534 | break; |
16535 | case DW_TAG_array_type: | |
f792889a | 16536 | this_type = read_array_type (die, cu); |
c906108c | 16537 | break; |
72019c9c | 16538 | case DW_TAG_set_type: |
f792889a | 16539 | this_type = read_set_type (die, cu); |
72019c9c | 16540 | break; |
c906108c | 16541 | case DW_TAG_pointer_type: |
f792889a | 16542 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
16543 | break; |
16544 | case DW_TAG_ptr_to_member_type: | |
f792889a | 16545 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
16546 | break; |
16547 | case DW_TAG_reference_type: | |
f792889a | 16548 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
16549 | break; |
16550 | case DW_TAG_const_type: | |
f792889a | 16551 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
16552 | break; |
16553 | case DW_TAG_volatile_type: | |
f792889a | 16554 | this_type = read_tag_volatile_type (die, cu); |
c906108c | 16555 | break; |
06d66ee9 TT |
16556 | case DW_TAG_restrict_type: |
16557 | this_type = read_tag_restrict_type (die, cu); | |
16558 | break; | |
c906108c | 16559 | case DW_TAG_string_type: |
f792889a | 16560 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
16561 | break; |
16562 | case DW_TAG_typedef: | |
f792889a | 16563 | this_type = read_typedef (die, cu); |
c906108c | 16564 | break; |
a02abb62 | 16565 | case DW_TAG_subrange_type: |
f792889a | 16566 | this_type = read_subrange_type (die, cu); |
a02abb62 | 16567 | break; |
c906108c | 16568 | case DW_TAG_base_type: |
f792889a | 16569 | this_type = read_base_type (die, cu); |
c906108c | 16570 | break; |
81a17f79 | 16571 | case DW_TAG_unspecified_type: |
f792889a | 16572 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 16573 | break; |
0114d602 DJ |
16574 | case DW_TAG_namespace: |
16575 | this_type = read_namespace_type (die, cu); | |
16576 | break; | |
f55ee35c JK |
16577 | case DW_TAG_module: |
16578 | this_type = read_module_type (die, cu); | |
16579 | break; | |
c906108c | 16580 | default: |
3e43a32a MS |
16581 | complaint (&symfile_complaints, |
16582 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 16583 | dwarf_tag_name (die->tag)); |
c906108c SS |
16584 | break; |
16585 | } | |
63d06c5c | 16586 | |
f792889a | 16587 | return this_type; |
63d06c5c DC |
16588 | } |
16589 | ||
abc72ce4 DE |
16590 | /* See if we can figure out if the class lives in a namespace. We do |
16591 | this by looking for a member function; its demangled name will | |
16592 | contain namespace info, if there is any. | |
16593 | Return the computed name or NULL. | |
16594 | Space for the result is allocated on the objfile's obstack. | |
16595 | This is the full-die version of guess_partial_die_structure_name. | |
16596 | In this case we know DIE has no useful parent. */ | |
16597 | ||
16598 | static char * | |
16599 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
16600 | { | |
16601 | struct die_info *spec_die; | |
16602 | struct dwarf2_cu *spec_cu; | |
16603 | struct die_info *child; | |
16604 | ||
16605 | spec_cu = cu; | |
16606 | spec_die = die_specification (die, &spec_cu); | |
16607 | if (spec_die != NULL) | |
16608 | { | |
16609 | die = spec_die; | |
16610 | cu = spec_cu; | |
16611 | } | |
16612 | ||
16613 | for (child = die->child; | |
16614 | child != NULL; | |
16615 | child = child->sibling) | |
16616 | { | |
16617 | if (child->tag == DW_TAG_subprogram) | |
16618 | { | |
16619 | struct attribute *attr; | |
16620 | ||
16621 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
16622 | if (attr == NULL) | |
16623 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
16624 | if (attr != NULL) | |
16625 | { | |
16626 | char *actual_name | |
16627 | = language_class_name_from_physname (cu->language_defn, | |
16628 | DW_STRING (attr)); | |
16629 | char *name = NULL; | |
16630 | ||
16631 | if (actual_name != NULL) | |
16632 | { | |
15d034d0 | 16633 | const char *die_name = dwarf2_name (die, cu); |
abc72ce4 DE |
16634 | |
16635 | if (die_name != NULL | |
16636 | && strcmp (die_name, actual_name) != 0) | |
16637 | { | |
16638 | /* Strip off the class name from the full name. | |
16639 | We want the prefix. */ | |
16640 | int die_name_len = strlen (die_name); | |
16641 | int actual_name_len = strlen (actual_name); | |
16642 | ||
16643 | /* Test for '::' as a sanity check. */ | |
16644 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
16645 | && actual_name[actual_name_len |
16646 | - die_name_len - 1] == ':') | |
abc72ce4 | 16647 | name = |
10f0c4bb TT |
16648 | obstack_copy0 (&cu->objfile->objfile_obstack, |
16649 | actual_name, | |
16650 | actual_name_len - die_name_len - 2); | |
abc72ce4 DE |
16651 | } |
16652 | } | |
16653 | xfree (actual_name); | |
16654 | return name; | |
16655 | } | |
16656 | } | |
16657 | } | |
16658 | ||
16659 | return NULL; | |
16660 | } | |
16661 | ||
96408a79 SA |
16662 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
16663 | prefix part in such case. See | |
16664 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
16665 | ||
16666 | static char * | |
16667 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) | |
16668 | { | |
16669 | struct attribute *attr; | |
16670 | char *base; | |
16671 | ||
16672 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type | |
16673 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) | |
16674 | return NULL; | |
16675 | ||
16676 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
16677 | if (attr != NULL && DW_STRING (attr) != NULL) | |
16678 | return NULL; | |
16679 | ||
16680 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
16681 | if (attr == NULL) | |
16682 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
16683 | if (attr == NULL || DW_STRING (attr) == NULL) | |
16684 | return NULL; | |
16685 | ||
16686 | /* dwarf2_name had to be already called. */ | |
16687 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); | |
16688 | ||
16689 | /* Strip the base name, keep any leading namespaces/classes. */ | |
16690 | base = strrchr (DW_STRING (attr), ':'); | |
16691 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') | |
16692 | return ""; | |
16693 | ||
10f0c4bb TT |
16694 | return obstack_copy0 (&cu->objfile->objfile_obstack, |
16695 | DW_STRING (attr), &base[-1] - DW_STRING (attr)); | |
96408a79 SA |
16696 | } |
16697 | ||
fdde2d81 | 16698 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 16699 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 16700 | |
0114d602 DJ |
16701 | For example, if we're within the method foo() in the following |
16702 | code: | |
16703 | ||
16704 | namespace N { | |
16705 | class C { | |
16706 | void foo () { | |
16707 | } | |
16708 | }; | |
16709 | } | |
16710 | ||
16711 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 | 16712 | |
0d5cff50 | 16713 | static const char * |
e142c38c | 16714 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 16715 | { |
0114d602 DJ |
16716 | struct die_info *parent, *spec_die; |
16717 | struct dwarf2_cu *spec_cu; | |
16718 | struct type *parent_type; | |
96408a79 | 16719 | char *retval; |
63d06c5c | 16720 | |
f55ee35c JK |
16721 | if (cu->language != language_cplus && cu->language != language_java |
16722 | && cu->language != language_fortran) | |
0114d602 DJ |
16723 | return ""; |
16724 | ||
96408a79 SA |
16725 | retval = anonymous_struct_prefix (die, cu); |
16726 | if (retval) | |
16727 | return retval; | |
16728 | ||
0114d602 DJ |
16729 | /* We have to be careful in the presence of DW_AT_specification. |
16730 | For example, with GCC 3.4, given the code | |
16731 | ||
16732 | namespace N { | |
16733 | void foo() { | |
16734 | // Definition of N::foo. | |
16735 | } | |
16736 | } | |
16737 | ||
16738 | then we'll have a tree of DIEs like this: | |
16739 | ||
16740 | 1: DW_TAG_compile_unit | |
16741 | 2: DW_TAG_namespace // N | |
16742 | 3: DW_TAG_subprogram // declaration of N::foo | |
16743 | 4: DW_TAG_subprogram // definition of N::foo | |
16744 | DW_AT_specification // refers to die #3 | |
16745 | ||
16746 | Thus, when processing die #4, we have to pretend that we're in | |
16747 | the context of its DW_AT_specification, namely the contex of die | |
16748 | #3. */ | |
16749 | spec_cu = cu; | |
16750 | spec_die = die_specification (die, &spec_cu); | |
16751 | if (spec_die == NULL) | |
16752 | parent = die->parent; | |
16753 | else | |
63d06c5c | 16754 | { |
0114d602 DJ |
16755 | parent = spec_die->parent; |
16756 | cu = spec_cu; | |
63d06c5c | 16757 | } |
0114d602 DJ |
16758 | |
16759 | if (parent == NULL) | |
16760 | return ""; | |
98bfdba5 PA |
16761 | else if (parent->building_fullname) |
16762 | { | |
16763 | const char *name; | |
16764 | const char *parent_name; | |
16765 | ||
16766 | /* It has been seen on RealView 2.2 built binaries, | |
16767 | DW_TAG_template_type_param types actually _defined_ as | |
16768 | children of the parent class: | |
16769 | ||
16770 | enum E {}; | |
16771 | template class <class Enum> Class{}; | |
16772 | Class<enum E> class_e; | |
16773 | ||
16774 | 1: DW_TAG_class_type (Class) | |
16775 | 2: DW_TAG_enumeration_type (E) | |
16776 | 3: DW_TAG_enumerator (enum1:0) | |
16777 | 3: DW_TAG_enumerator (enum2:1) | |
16778 | ... | |
16779 | 2: DW_TAG_template_type_param | |
16780 | DW_AT_type DW_FORM_ref_udata (E) | |
16781 | ||
16782 | Besides being broken debug info, it can put GDB into an | |
16783 | infinite loop. Consider: | |
16784 | ||
16785 | When we're building the full name for Class<E>, we'll start | |
16786 | at Class, and go look over its template type parameters, | |
16787 | finding E. We'll then try to build the full name of E, and | |
16788 | reach here. We're now trying to build the full name of E, | |
16789 | and look over the parent DIE for containing scope. In the | |
16790 | broken case, if we followed the parent DIE of E, we'd again | |
16791 | find Class, and once again go look at its template type | |
16792 | arguments, etc., etc. Simply don't consider such parent die | |
16793 | as source-level parent of this die (it can't be, the language | |
16794 | doesn't allow it), and break the loop here. */ | |
16795 | name = dwarf2_name (die, cu); | |
16796 | parent_name = dwarf2_name (parent, cu); | |
16797 | complaint (&symfile_complaints, | |
16798 | _("template param type '%s' defined within parent '%s'"), | |
16799 | name ? name : "<unknown>", | |
16800 | parent_name ? parent_name : "<unknown>"); | |
16801 | return ""; | |
16802 | } | |
63d06c5c | 16803 | else |
0114d602 DJ |
16804 | switch (parent->tag) |
16805 | { | |
63d06c5c | 16806 | case DW_TAG_namespace: |
0114d602 | 16807 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
16808 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
16809 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
16810 | Work around this problem here. */ | |
16811 | if (cu->language == language_cplus | |
16812 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
16813 | return ""; | |
0114d602 DJ |
16814 | /* We give a name to even anonymous namespaces. */ |
16815 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 16816 | case DW_TAG_class_type: |
680b30c7 | 16817 | case DW_TAG_interface_type: |
63d06c5c | 16818 | case DW_TAG_structure_type: |
0114d602 | 16819 | case DW_TAG_union_type: |
f55ee35c | 16820 | case DW_TAG_module: |
0114d602 DJ |
16821 | parent_type = read_type_die (parent, cu); |
16822 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
16823 | return TYPE_TAG_NAME (parent_type); | |
16824 | else | |
16825 | /* An anonymous structure is only allowed non-static data | |
16826 | members; no typedefs, no member functions, et cetera. | |
16827 | So it does not need a prefix. */ | |
16828 | return ""; | |
abc72ce4 | 16829 | case DW_TAG_compile_unit: |
95554aad | 16830 | case DW_TAG_partial_unit: |
abc72ce4 DE |
16831 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ |
16832 | if (cu->language == language_cplus | |
8b70b953 | 16833 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
16834 | && die->child != NULL |
16835 | && (die->tag == DW_TAG_class_type | |
16836 | || die->tag == DW_TAG_structure_type | |
16837 | || die->tag == DW_TAG_union_type)) | |
16838 | { | |
16839 | char *name = guess_full_die_structure_name (die, cu); | |
16840 | if (name != NULL) | |
16841 | return name; | |
16842 | } | |
16843 | return ""; | |
63d06c5c | 16844 | default: |
8176b9b8 | 16845 | return determine_prefix (parent, cu); |
63d06c5c | 16846 | } |
63d06c5c DC |
16847 | } |
16848 | ||
3e43a32a MS |
16849 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
16850 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
16851 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
16852 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
16853 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 16854 | |
f55ee35c | 16855 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
16856 | |
16857 | static char * | |
f55ee35c JK |
16858 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
16859 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 16860 | { |
f55ee35c | 16861 | const char *lead = ""; |
5c315b68 | 16862 | const char *sep; |
63d06c5c | 16863 | |
3e43a32a MS |
16864 | if (suffix == NULL || suffix[0] == '\0' |
16865 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
16866 | sep = ""; |
16867 | else if (cu->language == language_java) | |
16868 | sep = "."; | |
f55ee35c JK |
16869 | else if (cu->language == language_fortran && physname) |
16870 | { | |
16871 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
16872 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
16873 | ||
16874 | lead = "__"; | |
16875 | sep = "_MOD_"; | |
16876 | } | |
987504bb JJ |
16877 | else |
16878 | sep = "::"; | |
63d06c5c | 16879 | |
6dd47d34 DE |
16880 | if (prefix == NULL) |
16881 | prefix = ""; | |
16882 | if (suffix == NULL) | |
16883 | suffix = ""; | |
16884 | ||
987504bb JJ |
16885 | if (obs == NULL) |
16886 | { | |
3e43a32a MS |
16887 | char *retval |
16888 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 16889 | |
f55ee35c JK |
16890 | strcpy (retval, lead); |
16891 | strcat (retval, prefix); | |
6dd47d34 DE |
16892 | strcat (retval, sep); |
16893 | strcat (retval, suffix); | |
63d06c5c DC |
16894 | return retval; |
16895 | } | |
987504bb JJ |
16896 | else |
16897 | { | |
16898 | /* We have an obstack. */ | |
f55ee35c | 16899 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 16900 | } |
63d06c5c DC |
16901 | } |
16902 | ||
c906108c SS |
16903 | /* Return sibling of die, NULL if no sibling. */ |
16904 | ||
f9aca02d | 16905 | static struct die_info * |
fba45db2 | 16906 | sibling_die (struct die_info *die) |
c906108c | 16907 | { |
639d11d3 | 16908 | return die->sibling; |
c906108c SS |
16909 | } |
16910 | ||
71c25dea TT |
16911 | /* Get name of a die, return NULL if not found. */ |
16912 | ||
15d034d0 TT |
16913 | static const char * |
16914 | dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu, | |
71c25dea TT |
16915 | struct obstack *obstack) |
16916 | { | |
16917 | if (name && cu->language == language_cplus) | |
16918 | { | |
16919 | char *canon_name = cp_canonicalize_string (name); | |
16920 | ||
16921 | if (canon_name != NULL) | |
16922 | { | |
16923 | if (strcmp (canon_name, name) != 0) | |
10f0c4bb | 16924 | name = obstack_copy0 (obstack, canon_name, strlen (canon_name)); |
71c25dea TT |
16925 | xfree (canon_name); |
16926 | } | |
16927 | } | |
16928 | ||
16929 | return name; | |
c906108c SS |
16930 | } |
16931 | ||
9219021c DC |
16932 | /* Get name of a die, return NULL if not found. */ |
16933 | ||
15d034d0 | 16934 | static const char * |
e142c38c | 16935 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
16936 | { |
16937 | struct attribute *attr; | |
16938 | ||
e142c38c | 16939 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
16940 | if ((!attr || !DW_STRING (attr)) |
16941 | && die->tag != DW_TAG_class_type | |
16942 | && die->tag != DW_TAG_interface_type | |
16943 | && die->tag != DW_TAG_structure_type | |
16944 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
16945 | return NULL; |
16946 | ||
16947 | switch (die->tag) | |
16948 | { | |
16949 | case DW_TAG_compile_unit: | |
95554aad | 16950 | case DW_TAG_partial_unit: |
71c25dea TT |
16951 | /* Compilation units have a DW_AT_name that is a filename, not |
16952 | a source language identifier. */ | |
16953 | case DW_TAG_enumeration_type: | |
16954 | case DW_TAG_enumerator: | |
16955 | /* These tags always have simple identifiers already; no need | |
16956 | to canonicalize them. */ | |
16957 | return DW_STRING (attr); | |
907af001 | 16958 | |
418835cc KS |
16959 | case DW_TAG_subprogram: |
16960 | /* Java constructors will all be named "<init>", so return | |
16961 | the class name when we see this special case. */ | |
16962 | if (cu->language == language_java | |
16963 | && DW_STRING (attr) != NULL | |
16964 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
16965 | { | |
16966 | struct dwarf2_cu *spec_cu = cu; | |
16967 | struct die_info *spec_die; | |
16968 | ||
16969 | /* GCJ will output '<init>' for Java constructor names. | |
16970 | For this special case, return the name of the parent class. */ | |
16971 | ||
16972 | /* GCJ may output suprogram DIEs with AT_specification set. | |
16973 | If so, use the name of the specified DIE. */ | |
16974 | spec_die = die_specification (die, &spec_cu); | |
16975 | if (spec_die != NULL) | |
16976 | return dwarf2_name (spec_die, spec_cu); | |
16977 | ||
16978 | do | |
16979 | { | |
16980 | die = die->parent; | |
16981 | if (die->tag == DW_TAG_class_type) | |
16982 | return dwarf2_name (die, cu); | |
16983 | } | |
95554aad TT |
16984 | while (die->tag != DW_TAG_compile_unit |
16985 | && die->tag != DW_TAG_partial_unit); | |
418835cc | 16986 | } |
907af001 UW |
16987 | break; |
16988 | ||
16989 | case DW_TAG_class_type: | |
16990 | case DW_TAG_interface_type: | |
16991 | case DW_TAG_structure_type: | |
16992 | case DW_TAG_union_type: | |
16993 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
16994 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
16995 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
16996 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
16997 | if (attr && DW_STRING (attr) |
16998 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
16999 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 17000 | return NULL; |
53832f31 TT |
17001 | |
17002 | /* GCC might emit a nameless typedef that has a linkage name. See | |
17003 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
17004 | if (!attr || DW_STRING (attr) == NULL) | |
17005 | { | |
df5c6c50 | 17006 | char *demangled = NULL; |
53832f31 TT |
17007 | |
17008 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
17009 | if (attr == NULL) | |
17010 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
17011 | ||
17012 | if (attr == NULL || DW_STRING (attr) == NULL) | |
17013 | return NULL; | |
17014 | ||
df5c6c50 JK |
17015 | /* Avoid demangling DW_STRING (attr) the second time on a second |
17016 | call for the same DIE. */ | |
17017 | if (!DW_STRING_IS_CANONICAL (attr)) | |
17018 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
17019 | |
17020 | if (demangled) | |
17021 | { | |
96408a79 SA |
17022 | char *base; |
17023 | ||
53832f31 | 17024 | /* FIXME: we already did this for the partial symbol... */ |
10f0c4bb TT |
17025 | DW_STRING (attr) = obstack_copy0 (&cu->objfile->objfile_obstack, |
17026 | demangled, strlen (demangled)); | |
53832f31 TT |
17027 | DW_STRING_IS_CANONICAL (attr) = 1; |
17028 | xfree (demangled); | |
96408a79 SA |
17029 | |
17030 | /* Strip any leading namespaces/classes, keep only the base name. | |
17031 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
17032 | base = strrchr (DW_STRING (attr), ':'); | |
17033 | if (base && base > DW_STRING (attr) && base[-1] == ':') | |
17034 | return &base[1]; | |
17035 | else | |
17036 | return DW_STRING (attr); | |
53832f31 TT |
17037 | } |
17038 | } | |
907af001 UW |
17039 | break; |
17040 | ||
71c25dea | 17041 | default: |
907af001 UW |
17042 | break; |
17043 | } | |
17044 | ||
17045 | if (!DW_STRING_IS_CANONICAL (attr)) | |
17046 | { | |
17047 | DW_STRING (attr) | |
17048 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
17049 | &cu->objfile->objfile_obstack); | |
17050 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 17051 | } |
907af001 | 17052 | return DW_STRING (attr); |
9219021c DC |
17053 | } |
17054 | ||
17055 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
17056 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
17057 | containing the return value on output. */ | |
9219021c DC |
17058 | |
17059 | static struct die_info * | |
f2f0e013 | 17060 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
17061 | { |
17062 | struct attribute *attr; | |
9219021c | 17063 | |
f2f0e013 | 17064 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
17065 | if (attr == NULL) |
17066 | return NULL; | |
17067 | ||
f2f0e013 | 17068 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
17069 | } |
17070 | ||
c906108c SS |
17071 | /* Convert a DIE tag into its string name. */ |
17072 | ||
f39c6ffd | 17073 | static const char * |
aa1ee363 | 17074 | dwarf_tag_name (unsigned tag) |
c906108c | 17075 | { |
f39c6ffd TT |
17076 | const char *name = get_DW_TAG_name (tag); |
17077 | ||
17078 | if (name == NULL) | |
17079 | return "DW_TAG_<unknown>"; | |
17080 | ||
17081 | return name; | |
c906108c SS |
17082 | } |
17083 | ||
17084 | /* Convert a DWARF attribute code into its string name. */ | |
17085 | ||
f39c6ffd | 17086 | static const char * |
aa1ee363 | 17087 | dwarf_attr_name (unsigned attr) |
c906108c | 17088 | { |
f39c6ffd TT |
17089 | const char *name; |
17090 | ||
c764a876 | 17091 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
f39c6ffd TT |
17092 | if (attr == DW_AT_MIPS_fde) |
17093 | return "DW_AT_MIPS_fde"; | |
17094 | #else | |
17095 | if (attr == DW_AT_HP_block_index) | |
17096 | return "DW_AT_HP_block_index"; | |
c764a876 | 17097 | #endif |
f39c6ffd TT |
17098 | |
17099 | name = get_DW_AT_name (attr); | |
17100 | ||
17101 | if (name == NULL) | |
17102 | return "DW_AT_<unknown>"; | |
17103 | ||
17104 | return name; | |
c906108c SS |
17105 | } |
17106 | ||
17107 | /* Convert a DWARF value form code into its string name. */ | |
17108 | ||
f39c6ffd | 17109 | static const char * |
aa1ee363 | 17110 | dwarf_form_name (unsigned form) |
c906108c | 17111 | { |
f39c6ffd TT |
17112 | const char *name = get_DW_FORM_name (form); |
17113 | ||
17114 | if (name == NULL) | |
17115 | return "DW_FORM_<unknown>"; | |
17116 | ||
17117 | return name; | |
c906108c SS |
17118 | } |
17119 | ||
17120 | static char * | |
fba45db2 | 17121 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
17122 | { |
17123 | if (mybool) | |
17124 | return "TRUE"; | |
17125 | else | |
17126 | return "FALSE"; | |
17127 | } | |
17128 | ||
17129 | /* Convert a DWARF type code into its string name. */ | |
17130 | ||
f39c6ffd | 17131 | static const char * |
aa1ee363 | 17132 | dwarf_type_encoding_name (unsigned enc) |
c906108c | 17133 | { |
f39c6ffd | 17134 | const char *name = get_DW_ATE_name (enc); |
c906108c | 17135 | |
f39c6ffd TT |
17136 | if (name == NULL) |
17137 | return "DW_ATE_<unknown>"; | |
c906108c | 17138 | |
f39c6ffd | 17139 | return name; |
c906108c | 17140 | } |
c906108c | 17141 | |
f9aca02d | 17142 | static void |
d97bc12b | 17143 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
17144 | { |
17145 | unsigned int i; | |
17146 | ||
d97bc12b DE |
17147 | print_spaces (indent, f); |
17148 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
b64f50a1 | 17149 | dwarf_tag_name (die->tag), die->abbrev, die->offset.sect_off); |
d97bc12b DE |
17150 | |
17151 | if (die->parent != NULL) | |
17152 | { | |
17153 | print_spaces (indent, f); | |
17154 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
b64f50a1 | 17155 | die->parent->offset.sect_off); |
d97bc12b DE |
17156 | } |
17157 | ||
17158 | print_spaces (indent, f); | |
17159 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 17160 | dwarf_bool_name (die->child != NULL)); |
c906108c | 17161 | |
d97bc12b DE |
17162 | print_spaces (indent, f); |
17163 | fprintf_unfiltered (f, " attributes:\n"); | |
17164 | ||
c906108c SS |
17165 | for (i = 0; i < die->num_attrs; ++i) |
17166 | { | |
d97bc12b DE |
17167 | print_spaces (indent, f); |
17168 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
17169 | dwarf_attr_name (die->attrs[i].name), |
17170 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 17171 | |
c906108c SS |
17172 | switch (die->attrs[i].form) |
17173 | { | |
c906108c | 17174 | case DW_FORM_addr: |
3019eac3 | 17175 | case DW_FORM_GNU_addr_index: |
d97bc12b | 17176 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 17177 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
17178 | break; |
17179 | case DW_FORM_block2: | |
17180 | case DW_FORM_block4: | |
17181 | case DW_FORM_block: | |
17182 | case DW_FORM_block1: | |
56eb65bd SP |
17183 | fprintf_unfiltered (f, "block: size %s", |
17184 | pulongest (DW_BLOCK (&die->attrs[i])->size)); | |
c906108c | 17185 | break; |
2dc7f7b3 | 17186 | case DW_FORM_exprloc: |
56eb65bd SP |
17187 | fprintf_unfiltered (f, "expression: size %s", |
17188 | pulongest (DW_BLOCK (&die->attrs[i])->size)); | |
2dc7f7b3 | 17189 | break; |
4568ecf9 DE |
17190 | case DW_FORM_ref_addr: |
17191 | fprintf_unfiltered (f, "ref address: "); | |
17192 | fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f); | |
17193 | break; | |
36586728 TT |
17194 | case DW_FORM_GNU_ref_alt: |
17195 | fprintf_unfiltered (f, "alt ref address: "); | |
17196 | fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f); | |
17197 | break; | |
10b3939b DJ |
17198 | case DW_FORM_ref1: |
17199 | case DW_FORM_ref2: | |
17200 | case DW_FORM_ref4: | |
4568ecf9 DE |
17201 | case DW_FORM_ref8: |
17202 | case DW_FORM_ref_udata: | |
d97bc12b | 17203 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
4568ecf9 | 17204 | (long) (DW_UNSND (&die->attrs[i]))); |
10b3939b | 17205 | break; |
c906108c SS |
17206 | case DW_FORM_data1: |
17207 | case DW_FORM_data2: | |
17208 | case DW_FORM_data4: | |
ce5d95e1 | 17209 | case DW_FORM_data8: |
c906108c SS |
17210 | case DW_FORM_udata: |
17211 | case DW_FORM_sdata: | |
43bbcdc2 PH |
17212 | fprintf_unfiltered (f, "constant: %s", |
17213 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 17214 | break; |
2dc7f7b3 TT |
17215 | case DW_FORM_sec_offset: |
17216 | fprintf_unfiltered (f, "section offset: %s", | |
17217 | pulongest (DW_UNSND (&die->attrs[i]))); | |
17218 | break; | |
55f1336d | 17219 | case DW_FORM_ref_sig8: |
348e048f DE |
17220 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
17221 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
b64f50a1 | 17222 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset.sect_off); |
348e048f DE |
17223 | else |
17224 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
17225 | break; | |
c906108c | 17226 | case DW_FORM_string: |
4bdf3d34 | 17227 | case DW_FORM_strp: |
3019eac3 | 17228 | case DW_FORM_GNU_str_index: |
36586728 | 17229 | case DW_FORM_GNU_strp_alt: |
8285870a | 17230 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 17231 | DW_STRING (&die->attrs[i]) |
8285870a JK |
17232 | ? DW_STRING (&die->attrs[i]) : "", |
17233 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
17234 | break; |
17235 | case DW_FORM_flag: | |
17236 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 17237 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 17238 | else |
d97bc12b | 17239 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 17240 | break; |
2dc7f7b3 TT |
17241 | case DW_FORM_flag_present: |
17242 | fprintf_unfiltered (f, "flag: TRUE"); | |
17243 | break; | |
a8329558 | 17244 | case DW_FORM_indirect: |
0963b4bd MS |
17245 | /* The reader will have reduced the indirect form to |
17246 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
17247 | fprintf_unfiltered (f, |
17248 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 17249 | break; |
c906108c | 17250 | default: |
d97bc12b | 17251 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 17252 | die->attrs[i].form); |
d97bc12b | 17253 | break; |
c906108c | 17254 | } |
d97bc12b | 17255 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
17256 | } |
17257 | } | |
17258 | ||
f9aca02d | 17259 | static void |
d97bc12b | 17260 | dump_die_for_error (struct die_info *die) |
c906108c | 17261 | { |
d97bc12b DE |
17262 | dump_die_shallow (gdb_stderr, 0, die); |
17263 | } | |
17264 | ||
17265 | static void | |
17266 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
17267 | { | |
17268 | int indent = level * 4; | |
17269 | ||
17270 | gdb_assert (die != NULL); | |
17271 | ||
17272 | if (level >= max_level) | |
17273 | return; | |
17274 | ||
17275 | dump_die_shallow (f, indent, die); | |
17276 | ||
17277 | if (die->child != NULL) | |
c906108c | 17278 | { |
d97bc12b DE |
17279 | print_spaces (indent, f); |
17280 | fprintf_unfiltered (f, " Children:"); | |
17281 | if (level + 1 < max_level) | |
17282 | { | |
17283 | fprintf_unfiltered (f, "\n"); | |
17284 | dump_die_1 (f, level + 1, max_level, die->child); | |
17285 | } | |
17286 | else | |
17287 | { | |
3e43a32a MS |
17288 | fprintf_unfiltered (f, |
17289 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
17290 | } |
17291 | } | |
17292 | ||
17293 | if (die->sibling != NULL && level > 0) | |
17294 | { | |
17295 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
17296 | } |
17297 | } | |
17298 | ||
d97bc12b DE |
17299 | /* This is called from the pdie macro in gdbinit.in. |
17300 | It's not static so gcc will keep a copy callable from gdb. */ | |
17301 | ||
17302 | void | |
17303 | dump_die (struct die_info *die, int max_level) | |
17304 | { | |
17305 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
17306 | } | |
17307 | ||
f9aca02d | 17308 | static void |
51545339 | 17309 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 17310 | { |
51545339 | 17311 | void **slot; |
c906108c | 17312 | |
b64f50a1 JK |
17313 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset.sect_off, |
17314 | INSERT); | |
51545339 DJ |
17315 | |
17316 | *slot = die; | |
c906108c SS |
17317 | } |
17318 | ||
b64f50a1 JK |
17319 | /* DW_ADDR is always stored already as sect_offset; despite for the forms |
17320 | besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ | |
17321 | ||
93311388 DE |
17322 | static int |
17323 | is_ref_attr (struct attribute *attr) | |
c906108c | 17324 | { |
c906108c SS |
17325 | switch (attr->form) |
17326 | { | |
17327 | case DW_FORM_ref_addr: | |
c906108c SS |
17328 | case DW_FORM_ref1: |
17329 | case DW_FORM_ref2: | |
17330 | case DW_FORM_ref4: | |
613e1657 | 17331 | case DW_FORM_ref8: |
c906108c | 17332 | case DW_FORM_ref_udata: |
36586728 | 17333 | case DW_FORM_GNU_ref_alt: |
93311388 | 17334 | return 1; |
c906108c | 17335 | default: |
93311388 | 17336 | return 0; |
c906108c | 17337 | } |
93311388 DE |
17338 | } |
17339 | ||
b64f50a1 JK |
17340 | /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the |
17341 | required kind. */ | |
17342 | ||
17343 | static sect_offset | |
93311388 DE |
17344 | dwarf2_get_ref_die_offset (struct attribute *attr) |
17345 | { | |
4568ecf9 | 17346 | sect_offset retval = { DW_UNSND (attr) }; |
b64f50a1 | 17347 | |
93311388 | 17348 | if (is_ref_attr (attr)) |
b64f50a1 | 17349 | return retval; |
93311388 | 17350 | |
b64f50a1 | 17351 | retval.sect_off = 0; |
93311388 DE |
17352 | complaint (&symfile_complaints, |
17353 | _("unsupported die ref attribute form: '%s'"), | |
17354 | dwarf_form_name (attr->form)); | |
b64f50a1 | 17355 | return retval; |
c906108c SS |
17356 | } |
17357 | ||
43bbcdc2 PH |
17358 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
17359 | * the value held by the attribute is not constant. */ | |
a02abb62 | 17360 | |
43bbcdc2 | 17361 | static LONGEST |
a02abb62 JB |
17362 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
17363 | { | |
17364 | if (attr->form == DW_FORM_sdata) | |
17365 | return DW_SND (attr); | |
17366 | else if (attr->form == DW_FORM_udata | |
17367 | || attr->form == DW_FORM_data1 | |
17368 | || attr->form == DW_FORM_data2 | |
17369 | || attr->form == DW_FORM_data4 | |
17370 | || attr->form == DW_FORM_data8) | |
17371 | return DW_UNSND (attr); | |
17372 | else | |
17373 | { | |
3e43a32a MS |
17374 | complaint (&symfile_complaints, |
17375 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
17376 | dwarf_form_name (attr->form)); |
17377 | return default_value; | |
17378 | } | |
17379 | } | |
17380 | ||
348e048f DE |
17381 | /* Follow reference or signature attribute ATTR of SRC_DIE. |
17382 | On entry *REF_CU is the CU of SRC_DIE. | |
17383 | On exit *REF_CU is the CU of the result. */ | |
17384 | ||
17385 | static struct die_info * | |
17386 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
17387 | struct dwarf2_cu **ref_cu) | |
17388 | { | |
17389 | struct die_info *die; | |
17390 | ||
17391 | if (is_ref_attr (attr)) | |
17392 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 17393 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
17394 | die = follow_die_sig (src_die, attr, ref_cu); |
17395 | else | |
17396 | { | |
17397 | dump_die_for_error (src_die); | |
17398 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
17399 | (*ref_cu)->objfile->name); | |
17400 | } | |
17401 | ||
17402 | return die; | |
03dd20cc DJ |
17403 | } |
17404 | ||
5c631832 | 17405 | /* Follow reference OFFSET. |
673bfd45 DE |
17406 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
17407 | On exit *REF_CU is the CU of the result. | |
17408 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 17409 | |
f9aca02d | 17410 | static struct die_info * |
36586728 TT |
17411 | follow_die_offset (sect_offset offset, int offset_in_dwz, |
17412 | struct dwarf2_cu **ref_cu) | |
c906108c | 17413 | { |
10b3939b | 17414 | struct die_info temp_die; |
f2f0e013 | 17415 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 17416 | |
348e048f DE |
17417 | gdb_assert (cu->per_cu != NULL); |
17418 | ||
98bfdba5 PA |
17419 | target_cu = cu; |
17420 | ||
3019eac3 | 17421 | if (cu->per_cu->is_debug_types) |
348e048f DE |
17422 | { |
17423 | /* .debug_types CUs cannot reference anything outside their CU. | |
17424 | If they need to, they have to reference a signatured type via | |
55f1336d | 17425 | DW_FORM_ref_sig8. */ |
348e048f | 17426 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 17427 | return NULL; |
348e048f | 17428 | } |
36586728 TT |
17429 | else if (offset_in_dwz != cu->per_cu->is_dwz |
17430 | || ! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
17431 | { |
17432 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 17433 | |
36586728 TT |
17434 | per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz, |
17435 | cu->objfile); | |
03dd20cc DJ |
17436 | |
17437 | /* If necessary, add it to the queue and load its DIEs. */ | |
95554aad TT |
17438 | if (maybe_queue_comp_unit (cu, per_cu, cu->language)) |
17439 | load_full_comp_unit (per_cu, cu->language); | |
03dd20cc | 17440 | |
10b3939b DJ |
17441 | target_cu = per_cu->cu; |
17442 | } | |
98bfdba5 PA |
17443 | else if (cu->dies == NULL) |
17444 | { | |
17445 | /* We're loading full DIEs during partial symbol reading. */ | |
17446 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
95554aad | 17447 | load_full_comp_unit (cu->per_cu, language_minimal); |
98bfdba5 | 17448 | } |
c906108c | 17449 | |
f2f0e013 | 17450 | *ref_cu = target_cu; |
51545339 | 17451 | temp_die.offset = offset; |
b64f50a1 | 17452 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset.sect_off); |
5c631832 | 17453 | } |
10b3939b | 17454 | |
5c631832 JK |
17455 | /* Follow reference attribute ATTR of SRC_DIE. |
17456 | On entry *REF_CU is the CU of SRC_DIE. | |
17457 | On exit *REF_CU is the CU of the result. */ | |
17458 | ||
17459 | static struct die_info * | |
17460 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
17461 | struct dwarf2_cu **ref_cu) | |
17462 | { | |
b64f50a1 | 17463 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
5c631832 JK |
17464 | struct dwarf2_cu *cu = *ref_cu; |
17465 | struct die_info *die; | |
17466 | ||
36586728 TT |
17467 | die = follow_die_offset (offset, |
17468 | (attr->form == DW_FORM_GNU_ref_alt | |
17469 | || cu->per_cu->is_dwz), | |
17470 | ref_cu); | |
5c631832 JK |
17471 | if (!die) |
17472 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
17473 | "at 0x%x [in module %s]"), | |
b64f50a1 | 17474 | offset.sect_off, src_die->offset.sect_off, cu->objfile->name); |
348e048f | 17475 | |
5c631832 JK |
17476 | return die; |
17477 | } | |
17478 | ||
d83e736b JK |
17479 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
17480 | Returned value is intended for DW_OP_call*. Returned | |
17481 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ | |
5c631832 JK |
17482 | |
17483 | struct dwarf2_locexpr_baton | |
8b9737bf TT |
17484 | dwarf2_fetch_die_loc_sect_off (sect_offset offset, |
17485 | struct dwarf2_per_cu_data *per_cu, | |
17486 | CORE_ADDR (*get_frame_pc) (void *baton), | |
17487 | void *baton) | |
5c631832 | 17488 | { |
918dd910 | 17489 | struct dwarf2_cu *cu; |
5c631832 JK |
17490 | struct die_info *die; |
17491 | struct attribute *attr; | |
17492 | struct dwarf2_locexpr_baton retval; | |
17493 | ||
8cf6f0b1 TT |
17494 | dw2_setup (per_cu->objfile); |
17495 | ||
918dd910 JK |
17496 | if (per_cu->cu == NULL) |
17497 | load_cu (per_cu); | |
17498 | cu = per_cu->cu; | |
17499 | ||
36586728 | 17500 | die = follow_die_offset (offset, per_cu->is_dwz, &cu); |
5c631832 JK |
17501 | if (!die) |
17502 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
b64f50a1 | 17503 | offset.sect_off, per_cu->objfile->name); |
5c631832 JK |
17504 | |
17505 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
17506 | if (!attr) | |
17507 | { | |
e103e986 JK |
17508 | /* DWARF: "If there is no such attribute, then there is no effect.". |
17509 | DATA is ignored if SIZE is 0. */ | |
5c631832 | 17510 | |
e103e986 | 17511 | retval.data = NULL; |
5c631832 JK |
17512 | retval.size = 0; |
17513 | } | |
8cf6f0b1 TT |
17514 | else if (attr_form_is_section_offset (attr)) |
17515 | { | |
17516 | struct dwarf2_loclist_baton loclist_baton; | |
17517 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
17518 | size_t size; | |
17519 | ||
17520 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
17521 | ||
17522 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
17523 | &size, pc); | |
17524 | retval.size = size; | |
17525 | } | |
5c631832 JK |
17526 | else |
17527 | { | |
17528 | if (!attr_form_is_block (attr)) | |
17529 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
17530 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
b64f50a1 | 17531 | offset.sect_off, per_cu->objfile->name); |
5c631832 JK |
17532 | |
17533 | retval.data = DW_BLOCK (attr)->data; | |
17534 | retval.size = DW_BLOCK (attr)->size; | |
17535 | } | |
17536 | retval.per_cu = cu->per_cu; | |
918dd910 | 17537 | |
918dd910 JK |
17538 | age_cached_comp_units (); |
17539 | ||
5c631832 | 17540 | return retval; |
348e048f DE |
17541 | } |
17542 | ||
8b9737bf TT |
17543 | /* Like dwarf2_fetch_die_loc_sect_off, but take a CU |
17544 | offset. */ | |
17545 | ||
17546 | struct dwarf2_locexpr_baton | |
17547 | dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu, | |
17548 | struct dwarf2_per_cu_data *per_cu, | |
17549 | CORE_ADDR (*get_frame_pc) (void *baton), | |
17550 | void *baton) | |
17551 | { | |
17552 | sect_offset offset = { per_cu->offset.sect_off + offset_in_cu.cu_off }; | |
17553 | ||
17554 | return dwarf2_fetch_die_loc_sect_off (offset, per_cu, get_frame_pc, baton); | |
17555 | } | |
17556 | ||
8a9b8146 TT |
17557 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
17558 | PER_CU. */ | |
17559 | ||
17560 | struct type * | |
b64f50a1 | 17561 | dwarf2_get_die_type (cu_offset die_offset, |
8a9b8146 TT |
17562 | struct dwarf2_per_cu_data *per_cu) |
17563 | { | |
b64f50a1 JK |
17564 | sect_offset die_offset_sect; |
17565 | ||
8a9b8146 | 17566 | dw2_setup (per_cu->objfile); |
b64f50a1 JK |
17567 | |
17568 | die_offset_sect.sect_off = per_cu->offset.sect_off + die_offset.cu_off; | |
17569 | return get_die_type_at_offset (die_offset_sect, per_cu); | |
8a9b8146 TT |
17570 | } |
17571 | ||
348e048f DE |
17572 | /* Follow the signature attribute ATTR in SRC_DIE. |
17573 | On entry *REF_CU is the CU of SRC_DIE. | |
17574 | On exit *REF_CU is the CU of the result. */ | |
17575 | ||
17576 | static struct die_info * | |
17577 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
17578 | struct dwarf2_cu **ref_cu) | |
17579 | { | |
17580 | struct objfile *objfile = (*ref_cu)->objfile; | |
17581 | struct die_info temp_die; | |
17582 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
17583 | struct dwarf2_cu *sig_cu; | |
17584 | struct die_info *die; | |
17585 | ||
17586 | /* sig_type will be NULL if the signatured type is missing from | |
17587 | the debug info. */ | |
17588 | if (sig_type == NULL) | |
17589 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
17590 | "at 0x%x [in module %s]"), | |
b64f50a1 | 17591 | src_die->offset.sect_off, objfile->name); |
348e048f DE |
17592 | |
17593 | /* If necessary, add it to the queue and load its DIEs. */ | |
17594 | ||
95554aad | 17595 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, language_minimal)) |
a0f42c21 | 17596 | read_signatured_type (sig_type); |
348e048f DE |
17597 | |
17598 | gdb_assert (sig_type->per_cu.cu != NULL); | |
17599 | ||
17600 | sig_cu = sig_type->per_cu.cu; | |
3019eac3 DE |
17601 | gdb_assert (sig_type->type_offset_in_section.sect_off != 0); |
17602 | temp_die.offset = sig_type->type_offset_in_section; | |
b64f50a1 JK |
17603 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, |
17604 | temp_die.offset.sect_off); | |
348e048f DE |
17605 | if (die) |
17606 | { | |
796a7ff8 DE |
17607 | /* For .gdb_index version 7 keep track of included TUs. |
17608 | http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */ | |
17609 | if (dwarf2_per_objfile->index_table != NULL | |
17610 | && dwarf2_per_objfile->index_table->version <= 7) | |
17611 | { | |
17612 | VEC_safe_push (dwarf2_per_cu_ptr, | |
17613 | (*ref_cu)->per_cu->imported_symtabs, | |
17614 | sig_cu->per_cu); | |
17615 | } | |
17616 | ||
348e048f DE |
17617 | *ref_cu = sig_cu; |
17618 | return die; | |
17619 | } | |
17620 | ||
3e43a32a MS |
17621 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
17622 | "from DIE at 0x%x [in module %s]"), | |
b64f50a1 | 17623 | temp_die.offset.sect_off, src_die->offset.sect_off, objfile->name); |
348e048f DE |
17624 | } |
17625 | ||
17626 | /* Given an offset of a signatured type, return its signatured_type. */ | |
17627 | ||
17628 | static struct signatured_type * | |
8b70b953 TT |
17629 | lookup_signatured_type_at_offset (struct objfile *objfile, |
17630 | struct dwarf2_section_info *section, | |
b64f50a1 | 17631 | sect_offset offset) |
348e048f | 17632 | { |
b64f50a1 | 17633 | gdb_byte *info_ptr = section->buffer + offset.sect_off; |
348e048f DE |
17634 | unsigned int length, initial_length_size; |
17635 | unsigned int sig_offset; | |
52dc124a | 17636 | struct signatured_type find_entry, *sig_type; |
348e048f DE |
17637 | |
17638 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
17639 | sig_offset = (initial_length_size | |
17640 | + 2 /*version*/ | |
17641 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
17642 | + 1 /*address_size*/); | |
17643 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
52dc124a | 17644 | sig_type = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
348e048f DE |
17645 | |
17646 | /* This is only used to lookup previously recorded types. | |
17647 | If we didn't find it, it's our bug. */ | |
52dc124a DE |
17648 | gdb_assert (sig_type != NULL); |
17649 | gdb_assert (offset.sect_off == sig_type->per_cu.offset.sect_off); | |
348e048f | 17650 | |
52dc124a | 17651 | return sig_type; |
348e048f DE |
17652 | } |
17653 | ||
e5fe5e75 | 17654 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
348e048f DE |
17655 | |
17656 | static void | |
e5fe5e75 | 17657 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
348e048f | 17658 | { |
52dc124a | 17659 | struct signatured_type *sig_type; |
348e048f | 17660 | |
f4dc4d17 DE |
17661 | /* Caller is responsible for ensuring type_unit_groups don't get here. */ |
17662 | gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu)); | |
17663 | ||
6721b2ec DE |
17664 | /* We have the per_cu, but we need the signatured_type. |
17665 | Fortunately this is an easy translation. */ | |
17666 | gdb_assert (per_cu->is_debug_types); | |
17667 | sig_type = (struct signatured_type *) per_cu; | |
348e048f | 17668 | |
6721b2ec | 17669 | gdb_assert (per_cu->cu == NULL); |
348e048f | 17670 | |
52dc124a | 17671 | read_signatured_type (sig_type); |
348e048f | 17672 | |
6721b2ec | 17673 | gdb_assert (per_cu->cu != NULL); |
348e048f DE |
17674 | } |
17675 | ||
dee91e82 DE |
17676 | /* die_reader_func for read_signatured_type. |
17677 | This is identical to load_full_comp_unit_reader, | |
17678 | but is kept separate for now. */ | |
348e048f DE |
17679 | |
17680 | static void | |
dee91e82 DE |
17681 | read_signatured_type_reader (const struct die_reader_specs *reader, |
17682 | gdb_byte *info_ptr, | |
17683 | struct die_info *comp_unit_die, | |
17684 | int has_children, | |
17685 | void *data) | |
348e048f | 17686 | { |
dee91e82 | 17687 | struct dwarf2_cu *cu = reader->cu; |
348e048f | 17688 | |
dee91e82 DE |
17689 | gdb_assert (cu->die_hash == NULL); |
17690 | cu->die_hash = | |
17691 | htab_create_alloc_ex (cu->header.length / 12, | |
17692 | die_hash, | |
17693 | die_eq, | |
17694 | NULL, | |
17695 | &cu->comp_unit_obstack, | |
17696 | hashtab_obstack_allocate, | |
17697 | dummy_obstack_deallocate); | |
348e048f | 17698 | |
dee91e82 DE |
17699 | if (has_children) |
17700 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
17701 | &info_ptr, comp_unit_die); | |
17702 | cu->dies = comp_unit_die; | |
17703 | /* comp_unit_die is not stored in die_hash, no need. */ | |
348e048f DE |
17704 | |
17705 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 17706 | all CUs needed for references have been loaded yet, and symbol |
348e048f | 17707 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
17708 | or we won't be able to build types correctly. |
17709 | Similarly, if we do not read the producer, we can not apply | |
17710 | producer-specific interpretation. */ | |
95554aad | 17711 | prepare_one_comp_unit (cu, cu->dies, language_minimal); |
dee91e82 | 17712 | } |
348e048f | 17713 | |
3019eac3 DE |
17714 | /* Read in a signatured type and build its CU and DIEs. |
17715 | If the type is a stub for the real type in a DWO file, | |
17716 | read in the real type from the DWO file as well. */ | |
dee91e82 DE |
17717 | |
17718 | static void | |
17719 | read_signatured_type (struct signatured_type *sig_type) | |
17720 | { | |
17721 | struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu; | |
348e048f | 17722 | |
3019eac3 | 17723 | gdb_assert (per_cu->is_debug_types); |
dee91e82 | 17724 | gdb_assert (per_cu->cu == NULL); |
348e048f | 17725 | |
f4dc4d17 DE |
17726 | init_cutu_and_read_dies (per_cu, NULL, 0, 1, |
17727 | read_signatured_type_reader, NULL); | |
c906108c SS |
17728 | } |
17729 | ||
c906108c SS |
17730 | /* Decode simple location descriptions. |
17731 | Given a pointer to a dwarf block that defines a location, compute | |
17732 | the location and return the value. | |
17733 | ||
4cecd739 DJ |
17734 | NOTE drow/2003-11-18: This function is called in two situations |
17735 | now: for the address of static or global variables (partial symbols | |
17736 | only) and for offsets into structures which are expected to be | |
17737 | (more or less) constant. The partial symbol case should go away, | |
17738 | and only the constant case should remain. That will let this | |
17739 | function complain more accurately. A few special modes are allowed | |
17740 | without complaint for global variables (for instance, global | |
17741 | register values and thread-local values). | |
c906108c SS |
17742 | |
17743 | A location description containing no operations indicates that the | |
4cecd739 | 17744 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
17745 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
17746 | callers will only want a very basic result and this can become a | |
21ae7a4d JK |
17747 | complaint. |
17748 | ||
17749 | Note that stack[0] is unused except as a default error return. */ | |
c906108c SS |
17750 | |
17751 | static CORE_ADDR | |
e7c27a73 | 17752 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 17753 | { |
e7c27a73 | 17754 | struct objfile *objfile = cu->objfile; |
56eb65bd SP |
17755 | size_t i; |
17756 | size_t size = blk->size; | |
21ae7a4d JK |
17757 | gdb_byte *data = blk->data; |
17758 | CORE_ADDR stack[64]; | |
17759 | int stacki; | |
17760 | unsigned int bytes_read, unsnd; | |
17761 | gdb_byte op; | |
c906108c | 17762 | |
21ae7a4d JK |
17763 | i = 0; |
17764 | stacki = 0; | |
17765 | stack[stacki] = 0; | |
17766 | stack[++stacki] = 0; | |
17767 | ||
17768 | while (i < size) | |
17769 | { | |
17770 | op = data[i++]; | |
17771 | switch (op) | |
17772 | { | |
17773 | case DW_OP_lit0: | |
17774 | case DW_OP_lit1: | |
17775 | case DW_OP_lit2: | |
17776 | case DW_OP_lit3: | |
17777 | case DW_OP_lit4: | |
17778 | case DW_OP_lit5: | |
17779 | case DW_OP_lit6: | |
17780 | case DW_OP_lit7: | |
17781 | case DW_OP_lit8: | |
17782 | case DW_OP_lit9: | |
17783 | case DW_OP_lit10: | |
17784 | case DW_OP_lit11: | |
17785 | case DW_OP_lit12: | |
17786 | case DW_OP_lit13: | |
17787 | case DW_OP_lit14: | |
17788 | case DW_OP_lit15: | |
17789 | case DW_OP_lit16: | |
17790 | case DW_OP_lit17: | |
17791 | case DW_OP_lit18: | |
17792 | case DW_OP_lit19: | |
17793 | case DW_OP_lit20: | |
17794 | case DW_OP_lit21: | |
17795 | case DW_OP_lit22: | |
17796 | case DW_OP_lit23: | |
17797 | case DW_OP_lit24: | |
17798 | case DW_OP_lit25: | |
17799 | case DW_OP_lit26: | |
17800 | case DW_OP_lit27: | |
17801 | case DW_OP_lit28: | |
17802 | case DW_OP_lit29: | |
17803 | case DW_OP_lit30: | |
17804 | case DW_OP_lit31: | |
17805 | stack[++stacki] = op - DW_OP_lit0; | |
17806 | break; | |
f1bea926 | 17807 | |
21ae7a4d JK |
17808 | case DW_OP_reg0: |
17809 | case DW_OP_reg1: | |
17810 | case DW_OP_reg2: | |
17811 | case DW_OP_reg3: | |
17812 | case DW_OP_reg4: | |
17813 | case DW_OP_reg5: | |
17814 | case DW_OP_reg6: | |
17815 | case DW_OP_reg7: | |
17816 | case DW_OP_reg8: | |
17817 | case DW_OP_reg9: | |
17818 | case DW_OP_reg10: | |
17819 | case DW_OP_reg11: | |
17820 | case DW_OP_reg12: | |
17821 | case DW_OP_reg13: | |
17822 | case DW_OP_reg14: | |
17823 | case DW_OP_reg15: | |
17824 | case DW_OP_reg16: | |
17825 | case DW_OP_reg17: | |
17826 | case DW_OP_reg18: | |
17827 | case DW_OP_reg19: | |
17828 | case DW_OP_reg20: | |
17829 | case DW_OP_reg21: | |
17830 | case DW_OP_reg22: | |
17831 | case DW_OP_reg23: | |
17832 | case DW_OP_reg24: | |
17833 | case DW_OP_reg25: | |
17834 | case DW_OP_reg26: | |
17835 | case DW_OP_reg27: | |
17836 | case DW_OP_reg28: | |
17837 | case DW_OP_reg29: | |
17838 | case DW_OP_reg30: | |
17839 | case DW_OP_reg31: | |
17840 | stack[++stacki] = op - DW_OP_reg0; | |
17841 | if (i < size) | |
17842 | dwarf2_complex_location_expr_complaint (); | |
17843 | break; | |
c906108c | 17844 | |
21ae7a4d JK |
17845 | case DW_OP_regx: |
17846 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
17847 | i += bytes_read; | |
17848 | stack[++stacki] = unsnd; | |
17849 | if (i < size) | |
17850 | dwarf2_complex_location_expr_complaint (); | |
17851 | break; | |
c906108c | 17852 | |
21ae7a4d JK |
17853 | case DW_OP_addr: |
17854 | stack[++stacki] = read_address (objfile->obfd, &data[i], | |
17855 | cu, &bytes_read); | |
17856 | i += bytes_read; | |
17857 | break; | |
d53d4ac5 | 17858 | |
21ae7a4d JK |
17859 | case DW_OP_const1u: |
17860 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
17861 | i += 1; | |
17862 | break; | |
17863 | ||
17864 | case DW_OP_const1s: | |
17865 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
17866 | i += 1; | |
17867 | break; | |
17868 | ||
17869 | case DW_OP_const2u: | |
17870 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
17871 | i += 2; | |
17872 | break; | |
17873 | ||
17874 | case DW_OP_const2s: | |
17875 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
17876 | i += 2; | |
17877 | break; | |
d53d4ac5 | 17878 | |
21ae7a4d JK |
17879 | case DW_OP_const4u: |
17880 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
17881 | i += 4; | |
17882 | break; | |
17883 | ||
17884 | case DW_OP_const4s: | |
17885 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
17886 | i += 4; | |
17887 | break; | |
17888 | ||
585861ea JK |
17889 | case DW_OP_const8u: |
17890 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); | |
17891 | i += 8; | |
17892 | break; | |
17893 | ||
21ae7a4d JK |
17894 | case DW_OP_constu: |
17895 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
17896 | &bytes_read); | |
17897 | i += bytes_read; | |
17898 | break; | |
17899 | ||
17900 | case DW_OP_consts: | |
17901 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
17902 | i += bytes_read; | |
17903 | break; | |
17904 | ||
17905 | case DW_OP_dup: | |
17906 | stack[stacki + 1] = stack[stacki]; | |
17907 | stacki++; | |
17908 | break; | |
17909 | ||
17910 | case DW_OP_plus: | |
17911 | stack[stacki - 1] += stack[stacki]; | |
17912 | stacki--; | |
17913 | break; | |
17914 | ||
17915 | case DW_OP_plus_uconst: | |
17916 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), | |
17917 | &bytes_read); | |
17918 | i += bytes_read; | |
17919 | break; | |
17920 | ||
17921 | case DW_OP_minus: | |
17922 | stack[stacki - 1] -= stack[stacki]; | |
17923 | stacki--; | |
17924 | break; | |
17925 | ||
17926 | case DW_OP_deref: | |
17927 | /* If we're not the last op, then we definitely can't encode | |
17928 | this using GDB's address_class enum. This is valid for partial | |
17929 | global symbols, although the variable's address will be bogus | |
17930 | in the psymtab. */ | |
17931 | if (i < size) | |
17932 | dwarf2_complex_location_expr_complaint (); | |
17933 | break; | |
17934 | ||
17935 | case DW_OP_GNU_push_tls_address: | |
17936 | /* The top of the stack has the offset from the beginning | |
17937 | of the thread control block at which the variable is located. */ | |
17938 | /* Nothing should follow this operator, so the top of stack would | |
17939 | be returned. */ | |
17940 | /* This is valid for partial global symbols, but the variable's | |
585861ea JK |
17941 | address will be bogus in the psymtab. Make it always at least |
17942 | non-zero to not look as a variable garbage collected by linker | |
17943 | which have DW_OP_addr 0. */ | |
21ae7a4d JK |
17944 | if (i < size) |
17945 | dwarf2_complex_location_expr_complaint (); | |
585861ea | 17946 | stack[stacki]++; |
21ae7a4d JK |
17947 | break; |
17948 | ||
17949 | case DW_OP_GNU_uninit: | |
17950 | break; | |
17951 | ||
3019eac3 | 17952 | case DW_OP_GNU_addr_index: |
49f6c839 | 17953 | case DW_OP_GNU_const_index: |
3019eac3 DE |
17954 | stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i], |
17955 | &bytes_read); | |
17956 | i += bytes_read; | |
17957 | break; | |
17958 | ||
21ae7a4d JK |
17959 | default: |
17960 | { | |
f39c6ffd | 17961 | const char *name = get_DW_OP_name (op); |
21ae7a4d JK |
17962 | |
17963 | if (name) | |
17964 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
17965 | name); | |
17966 | else | |
17967 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
17968 | op); | |
17969 | } | |
17970 | ||
17971 | return (stack[stacki]); | |
d53d4ac5 | 17972 | } |
3c6e0cb3 | 17973 | |
21ae7a4d JK |
17974 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
17975 | outside of the allocated space. Also enforce minimum>0. */ | |
17976 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
17977 | { | |
17978 | complaint (&symfile_complaints, | |
17979 | _("location description stack overflow")); | |
17980 | return 0; | |
17981 | } | |
17982 | ||
17983 | if (stacki <= 0) | |
17984 | { | |
17985 | complaint (&symfile_complaints, | |
17986 | _("location description stack underflow")); | |
17987 | return 0; | |
17988 | } | |
17989 | } | |
17990 | return (stack[stacki]); | |
c906108c SS |
17991 | } |
17992 | ||
17993 | /* memory allocation interface */ | |
17994 | ||
c906108c | 17995 | static struct dwarf_block * |
7b5a2f43 | 17996 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
17997 | { |
17998 | struct dwarf_block *blk; | |
17999 | ||
18000 | blk = (struct dwarf_block *) | |
7b5a2f43 | 18001 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
18002 | return (blk); |
18003 | } | |
18004 | ||
c906108c | 18005 | static struct die_info * |
b60c80d6 | 18006 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
18007 | { |
18008 | struct die_info *die; | |
b60c80d6 DJ |
18009 | size_t size = sizeof (struct die_info); |
18010 | ||
18011 | if (num_attrs > 1) | |
18012 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 18013 | |
b60c80d6 | 18014 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
18015 | memset (die, 0, sizeof (struct die_info)); |
18016 | return (die); | |
18017 | } | |
2e276125 JB |
18018 | |
18019 | \f | |
18020 | /* Macro support. */ | |
18021 | ||
2e276125 JB |
18022 | /* Return the full name of file number I in *LH's file name table. |
18023 | Use COMP_DIR as the name of the current directory of the | |
18024 | compilation. The result is allocated using xmalloc; the caller is | |
18025 | responsible for freeing it. */ | |
18026 | static char * | |
18027 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
18028 | { | |
6a83a1e6 EZ |
18029 | /* Is the file number a valid index into the line header's file name |
18030 | table? Remember that file numbers start with one, not zero. */ | |
18031 | if (1 <= file && file <= lh->num_file_names) | |
18032 | { | |
18033 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 18034 | |
6a83a1e6 EZ |
18035 | if (IS_ABSOLUTE_PATH (fe->name)) |
18036 | return xstrdup (fe->name); | |
18037 | else | |
18038 | { | |
18039 | const char *dir; | |
18040 | int dir_len; | |
18041 | char *full_name; | |
18042 | ||
18043 | if (fe->dir_index) | |
18044 | dir = lh->include_dirs[fe->dir_index - 1]; | |
18045 | else | |
18046 | dir = comp_dir; | |
18047 | ||
18048 | if (dir) | |
18049 | { | |
18050 | dir_len = strlen (dir); | |
18051 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
18052 | strcpy (full_name, dir); | |
18053 | full_name[dir_len] = '/'; | |
18054 | strcpy (full_name + dir_len + 1, fe->name); | |
18055 | return full_name; | |
18056 | } | |
18057 | else | |
18058 | return xstrdup (fe->name); | |
18059 | } | |
18060 | } | |
2e276125 JB |
18061 | else |
18062 | { | |
6a83a1e6 EZ |
18063 | /* The compiler produced a bogus file number. We can at least |
18064 | record the macro definitions made in the file, even if we | |
18065 | won't be able to find the file by name. */ | |
18066 | char fake_name[80]; | |
9a619af0 | 18067 | |
8c042590 PM |
18068 | xsnprintf (fake_name, sizeof (fake_name), |
18069 | "<bad macro file number %d>", file); | |
2e276125 | 18070 | |
6e70227d | 18071 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
18072 | _("bad file number in macro information (%d)"), |
18073 | file); | |
2e276125 | 18074 | |
6a83a1e6 | 18075 | return xstrdup (fake_name); |
2e276125 JB |
18076 | } |
18077 | } | |
18078 | ||
18079 | ||
18080 | static struct macro_source_file * | |
18081 | macro_start_file (int file, int line, | |
18082 | struct macro_source_file *current_file, | |
18083 | const char *comp_dir, | |
18084 | struct line_header *lh, struct objfile *objfile) | |
18085 | { | |
18086 | /* The full name of this source file. */ | |
18087 | char *full_name = file_full_name (file, lh, comp_dir); | |
18088 | ||
18089 | /* We don't create a macro table for this compilation unit | |
18090 | at all until we actually get a filename. */ | |
18091 | if (! pending_macros) | |
6532ff36 TT |
18092 | pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack, |
18093 | objfile->per_bfd->macro_cache); | |
2e276125 JB |
18094 | |
18095 | if (! current_file) | |
abc9d0dc TT |
18096 | { |
18097 | /* If we have no current file, then this must be the start_file | |
18098 | directive for the compilation unit's main source file. */ | |
18099 | current_file = macro_set_main (pending_macros, full_name); | |
18100 | macro_define_special (pending_macros); | |
18101 | } | |
2e276125 JB |
18102 | else |
18103 | current_file = macro_include (current_file, line, full_name); | |
18104 | ||
18105 | xfree (full_name); | |
6e70227d | 18106 | |
2e276125 JB |
18107 | return current_file; |
18108 | } | |
18109 | ||
18110 | ||
18111 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
18112 | followed by a null byte. */ | |
18113 | static char * | |
18114 | copy_string (const char *buf, int len) | |
18115 | { | |
18116 | char *s = xmalloc (len + 1); | |
9a619af0 | 18117 | |
2e276125 JB |
18118 | memcpy (s, buf, len); |
18119 | s[len] = '\0'; | |
2e276125 JB |
18120 | return s; |
18121 | } | |
18122 | ||
18123 | ||
18124 | static const char * | |
18125 | consume_improper_spaces (const char *p, const char *body) | |
18126 | { | |
18127 | if (*p == ' ') | |
18128 | { | |
4d3c2250 | 18129 | complaint (&symfile_complaints, |
3e43a32a MS |
18130 | _("macro definition contains spaces " |
18131 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 18132 | body); |
2e276125 JB |
18133 | |
18134 | while (*p == ' ') | |
18135 | p++; | |
18136 | } | |
18137 | ||
18138 | return p; | |
18139 | } | |
18140 | ||
18141 | ||
18142 | static void | |
18143 | parse_macro_definition (struct macro_source_file *file, int line, | |
18144 | const char *body) | |
18145 | { | |
18146 | const char *p; | |
18147 | ||
18148 | /* The body string takes one of two forms. For object-like macro | |
18149 | definitions, it should be: | |
18150 | ||
18151 | <macro name> " " <definition> | |
18152 | ||
18153 | For function-like macro definitions, it should be: | |
18154 | ||
18155 | <macro name> "() " <definition> | |
18156 | or | |
18157 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
18158 | ||
18159 | Spaces may appear only where explicitly indicated, and in the | |
18160 | <definition>. | |
18161 | ||
18162 | The Dwarf 2 spec says that an object-like macro's name is always | |
18163 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 18164 | the space when the macro's definition is the empty string. |
2e276125 JB |
18165 | |
18166 | The Dwarf 2 spec says that there should be no spaces between the | |
18167 | formal arguments in a function-like macro's formal argument list, | |
18168 | but versions of GCC around March 2002 include spaces after the | |
18169 | commas. */ | |
18170 | ||
18171 | ||
18172 | /* Find the extent of the macro name. The macro name is terminated | |
18173 | by either a space or null character (for an object-like macro) or | |
18174 | an opening paren (for a function-like macro). */ | |
18175 | for (p = body; *p; p++) | |
18176 | if (*p == ' ' || *p == '(') | |
18177 | break; | |
18178 | ||
18179 | if (*p == ' ' || *p == '\0') | |
18180 | { | |
18181 | /* It's an object-like macro. */ | |
18182 | int name_len = p - body; | |
18183 | char *name = copy_string (body, name_len); | |
18184 | const char *replacement; | |
18185 | ||
18186 | if (*p == ' ') | |
18187 | replacement = body + name_len + 1; | |
18188 | else | |
18189 | { | |
4d3c2250 | 18190 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
18191 | replacement = body + name_len; |
18192 | } | |
6e70227d | 18193 | |
2e276125 JB |
18194 | macro_define_object (file, line, name, replacement); |
18195 | ||
18196 | xfree (name); | |
18197 | } | |
18198 | else if (*p == '(') | |
18199 | { | |
18200 | /* It's a function-like macro. */ | |
18201 | char *name = copy_string (body, p - body); | |
18202 | int argc = 0; | |
18203 | int argv_size = 1; | |
18204 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
18205 | ||
18206 | p++; | |
18207 | ||
18208 | p = consume_improper_spaces (p, body); | |
18209 | ||
18210 | /* Parse the formal argument list. */ | |
18211 | while (*p && *p != ')') | |
18212 | { | |
18213 | /* Find the extent of the current argument name. */ | |
18214 | const char *arg_start = p; | |
18215 | ||
18216 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
18217 | p++; | |
18218 | ||
18219 | if (! *p || p == arg_start) | |
4d3c2250 | 18220 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
18221 | else |
18222 | { | |
18223 | /* Make sure argv has room for the new argument. */ | |
18224 | if (argc >= argv_size) | |
18225 | { | |
18226 | argv_size *= 2; | |
18227 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
18228 | } | |
18229 | ||
18230 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
18231 | } | |
18232 | ||
18233 | p = consume_improper_spaces (p, body); | |
18234 | ||
18235 | /* Consume the comma, if present. */ | |
18236 | if (*p == ',') | |
18237 | { | |
18238 | p++; | |
18239 | ||
18240 | p = consume_improper_spaces (p, body); | |
18241 | } | |
18242 | } | |
18243 | ||
18244 | if (*p == ')') | |
18245 | { | |
18246 | p++; | |
18247 | ||
18248 | if (*p == ' ') | |
18249 | /* Perfectly formed definition, no complaints. */ | |
18250 | macro_define_function (file, line, name, | |
6e70227d | 18251 | argc, (const char **) argv, |
2e276125 JB |
18252 | p + 1); |
18253 | else if (*p == '\0') | |
18254 | { | |
18255 | /* Complain, but do define it. */ | |
4d3c2250 | 18256 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 18257 | macro_define_function (file, line, name, |
6e70227d | 18258 | argc, (const char **) argv, |
2e276125 JB |
18259 | p); |
18260 | } | |
18261 | else | |
18262 | /* Just complain. */ | |
4d3c2250 | 18263 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
18264 | } |
18265 | else | |
18266 | /* Just complain. */ | |
4d3c2250 | 18267 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
18268 | |
18269 | xfree (name); | |
18270 | { | |
18271 | int i; | |
18272 | ||
18273 | for (i = 0; i < argc; i++) | |
18274 | xfree (argv[i]); | |
18275 | } | |
18276 | xfree (argv); | |
18277 | } | |
18278 | else | |
4d3c2250 | 18279 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
18280 | } |
18281 | ||
cf2c3c16 TT |
18282 | /* Skip some bytes from BYTES according to the form given in FORM. |
18283 | Returns the new pointer. */ | |
2e276125 | 18284 | |
cf2c3c16 | 18285 | static gdb_byte * |
f664829e | 18286 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, gdb_byte *buffer_end, |
cf2c3c16 TT |
18287 | enum dwarf_form form, |
18288 | unsigned int offset_size, | |
18289 | struct dwarf2_section_info *section) | |
2e276125 | 18290 | { |
cf2c3c16 | 18291 | unsigned int bytes_read; |
2e276125 | 18292 | |
cf2c3c16 | 18293 | switch (form) |
2e276125 | 18294 | { |
cf2c3c16 TT |
18295 | case DW_FORM_data1: |
18296 | case DW_FORM_flag: | |
18297 | ++bytes; | |
18298 | break; | |
18299 | ||
18300 | case DW_FORM_data2: | |
18301 | bytes += 2; | |
18302 | break; | |
18303 | ||
18304 | case DW_FORM_data4: | |
18305 | bytes += 4; | |
18306 | break; | |
18307 | ||
18308 | case DW_FORM_data8: | |
18309 | bytes += 8; | |
18310 | break; | |
18311 | ||
18312 | case DW_FORM_string: | |
18313 | read_direct_string (abfd, bytes, &bytes_read); | |
18314 | bytes += bytes_read; | |
18315 | break; | |
18316 | ||
18317 | case DW_FORM_sec_offset: | |
18318 | case DW_FORM_strp: | |
36586728 | 18319 | case DW_FORM_GNU_strp_alt: |
cf2c3c16 TT |
18320 | bytes += offset_size; |
18321 | break; | |
18322 | ||
18323 | case DW_FORM_block: | |
18324 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); | |
18325 | bytes += bytes_read; | |
18326 | break; | |
18327 | ||
18328 | case DW_FORM_block1: | |
18329 | bytes += 1 + read_1_byte (abfd, bytes); | |
18330 | break; | |
18331 | case DW_FORM_block2: | |
18332 | bytes += 2 + read_2_bytes (abfd, bytes); | |
18333 | break; | |
18334 | case DW_FORM_block4: | |
18335 | bytes += 4 + read_4_bytes (abfd, bytes); | |
18336 | break; | |
18337 | ||
18338 | case DW_FORM_sdata: | |
18339 | case DW_FORM_udata: | |
3019eac3 DE |
18340 | case DW_FORM_GNU_addr_index: |
18341 | case DW_FORM_GNU_str_index: | |
f664829e DE |
18342 | bytes = (gdb_byte *) gdb_skip_leb128 (bytes, buffer_end); |
18343 | if (bytes == NULL) | |
18344 | { | |
18345 | dwarf2_section_buffer_overflow_complaint (section); | |
18346 | return NULL; | |
18347 | } | |
cf2c3c16 TT |
18348 | break; |
18349 | ||
18350 | default: | |
18351 | { | |
18352 | complain: | |
18353 | complaint (&symfile_complaints, | |
18354 | _("invalid form 0x%x in `%s'"), | |
18355 | form, | |
18356 | section->asection->name); | |
18357 | return NULL; | |
18358 | } | |
2e276125 JB |
18359 | } |
18360 | ||
cf2c3c16 TT |
18361 | return bytes; |
18362 | } | |
757a13d0 | 18363 | |
cf2c3c16 TT |
18364 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
18365 | opcode. Returns an updated pointer to the macro data buffer; or, | |
18366 | on error, issues a complaint and returns NULL. */ | |
757a13d0 | 18367 | |
cf2c3c16 TT |
18368 | static gdb_byte * |
18369 | skip_unknown_opcode (unsigned int opcode, | |
18370 | gdb_byte **opcode_definitions, | |
f664829e | 18371 | gdb_byte *mac_ptr, gdb_byte *mac_end, |
cf2c3c16 TT |
18372 | bfd *abfd, |
18373 | unsigned int offset_size, | |
18374 | struct dwarf2_section_info *section) | |
18375 | { | |
18376 | unsigned int bytes_read, i; | |
18377 | unsigned long arg; | |
18378 | gdb_byte *defn; | |
2e276125 | 18379 | |
cf2c3c16 | 18380 | if (opcode_definitions[opcode] == NULL) |
2e276125 | 18381 | { |
cf2c3c16 TT |
18382 | complaint (&symfile_complaints, |
18383 | _("unrecognized DW_MACFINO opcode 0x%x"), | |
18384 | opcode); | |
18385 | return NULL; | |
18386 | } | |
2e276125 | 18387 | |
cf2c3c16 TT |
18388 | defn = opcode_definitions[opcode]; |
18389 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); | |
18390 | defn += bytes_read; | |
2e276125 | 18391 | |
cf2c3c16 TT |
18392 | for (i = 0; i < arg; ++i) |
18393 | { | |
f664829e DE |
18394 | mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, defn[i], offset_size, |
18395 | section); | |
cf2c3c16 TT |
18396 | if (mac_ptr == NULL) |
18397 | { | |
18398 | /* skip_form_bytes already issued the complaint. */ | |
18399 | return NULL; | |
18400 | } | |
18401 | } | |
757a13d0 | 18402 | |
cf2c3c16 TT |
18403 | return mac_ptr; |
18404 | } | |
757a13d0 | 18405 | |
cf2c3c16 TT |
18406 | /* A helper function which parses the header of a macro section. |
18407 | If the macro section is the extended (for now called "GNU") type, | |
18408 | then this updates *OFFSET_SIZE. Returns a pointer to just after | |
18409 | the header, or issues a complaint and returns NULL on error. */ | |
757a13d0 | 18410 | |
cf2c3c16 TT |
18411 | static gdb_byte * |
18412 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, | |
18413 | bfd *abfd, | |
18414 | gdb_byte *mac_ptr, | |
18415 | unsigned int *offset_size, | |
18416 | int section_is_gnu) | |
18417 | { | |
18418 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); | |
757a13d0 | 18419 | |
cf2c3c16 TT |
18420 | if (section_is_gnu) |
18421 | { | |
18422 | unsigned int version, flags; | |
757a13d0 | 18423 | |
cf2c3c16 TT |
18424 | version = read_2_bytes (abfd, mac_ptr); |
18425 | if (version != 4) | |
18426 | { | |
18427 | complaint (&symfile_complaints, | |
18428 | _("unrecognized version `%d' in .debug_macro section"), | |
18429 | version); | |
18430 | return NULL; | |
18431 | } | |
18432 | mac_ptr += 2; | |
757a13d0 | 18433 | |
cf2c3c16 TT |
18434 | flags = read_1_byte (abfd, mac_ptr); |
18435 | ++mac_ptr; | |
18436 | *offset_size = (flags & 1) ? 8 : 4; | |
757a13d0 | 18437 | |
cf2c3c16 TT |
18438 | if ((flags & 2) != 0) |
18439 | /* We don't need the line table offset. */ | |
18440 | mac_ptr += *offset_size; | |
757a13d0 | 18441 | |
cf2c3c16 TT |
18442 | /* Vendor opcode descriptions. */ |
18443 | if ((flags & 4) != 0) | |
18444 | { | |
18445 | unsigned int i, count; | |
757a13d0 | 18446 | |
cf2c3c16 TT |
18447 | count = read_1_byte (abfd, mac_ptr); |
18448 | ++mac_ptr; | |
18449 | for (i = 0; i < count; ++i) | |
18450 | { | |
18451 | unsigned int opcode, bytes_read; | |
18452 | unsigned long arg; | |
18453 | ||
18454 | opcode = read_1_byte (abfd, mac_ptr); | |
18455 | ++mac_ptr; | |
18456 | opcode_definitions[opcode] = mac_ptr; | |
18457 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
18458 | mac_ptr += bytes_read; | |
18459 | mac_ptr += arg; | |
18460 | } | |
757a13d0 | 18461 | } |
cf2c3c16 | 18462 | } |
757a13d0 | 18463 | |
cf2c3c16 TT |
18464 | return mac_ptr; |
18465 | } | |
757a13d0 | 18466 | |
cf2c3c16 | 18467 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
8fc3fc34 | 18468 | including DW_MACRO_GNU_transparent_include. */ |
cf2c3c16 TT |
18469 | |
18470 | static void | |
18471 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, | |
18472 | struct macro_source_file *current_file, | |
15d034d0 | 18473 | struct line_header *lh, const char *comp_dir, |
cf2c3c16 | 18474 | struct dwarf2_section_info *section, |
36586728 | 18475 | int section_is_gnu, int section_is_dwz, |
cf2c3c16 | 18476 | unsigned int offset_size, |
8fc3fc34 TT |
18477 | struct objfile *objfile, |
18478 | htab_t include_hash) | |
cf2c3c16 TT |
18479 | { |
18480 | enum dwarf_macro_record_type macinfo_type; | |
18481 | int at_commandline; | |
18482 | gdb_byte *opcode_definitions[256]; | |
757a13d0 | 18483 | |
cf2c3c16 TT |
18484 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
18485 | &offset_size, section_is_gnu); | |
18486 | if (mac_ptr == NULL) | |
18487 | { | |
18488 | /* We already issued a complaint. */ | |
18489 | return; | |
18490 | } | |
757a13d0 JK |
18491 | |
18492 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
18493 | GDB is still reading the definitions from command line. First | |
18494 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
18495 | to create CURRENT_FILE for the main source holding also the command line | |
18496 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
18497 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
18498 | ||
18499 | at_commandline = 1; | |
18500 | ||
18501 | do | |
18502 | { | |
18503 | /* Do we at least have room for a macinfo type byte? */ | |
18504 | if (mac_ptr >= mac_end) | |
18505 | { | |
f664829e | 18506 | dwarf2_section_buffer_overflow_complaint (section); |
757a13d0 JK |
18507 | break; |
18508 | } | |
18509 | ||
18510 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
18511 | mac_ptr++; | |
18512 | ||
cf2c3c16 TT |
18513 | /* Note that we rely on the fact that the corresponding GNU and |
18514 | DWARF constants are the same. */ | |
757a13d0 JK |
18515 | switch (macinfo_type) |
18516 | { | |
18517 | /* A zero macinfo type indicates the end of the macro | |
18518 | information. */ | |
18519 | case 0: | |
18520 | break; | |
2e276125 | 18521 | |
cf2c3c16 TT |
18522 | case DW_MACRO_GNU_define: |
18523 | case DW_MACRO_GNU_undef: | |
18524 | case DW_MACRO_GNU_define_indirect: | |
18525 | case DW_MACRO_GNU_undef_indirect: | |
36586728 TT |
18526 | case DW_MACRO_GNU_define_indirect_alt: |
18527 | case DW_MACRO_GNU_undef_indirect_alt: | |
2e276125 | 18528 | { |
891d2f0b | 18529 | unsigned int bytes_read; |
2e276125 JB |
18530 | int line; |
18531 | char *body; | |
cf2c3c16 | 18532 | int is_define; |
2e276125 | 18533 | |
cf2c3c16 TT |
18534 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
18535 | mac_ptr += bytes_read; | |
18536 | ||
18537 | if (macinfo_type == DW_MACRO_GNU_define | |
18538 | || macinfo_type == DW_MACRO_GNU_undef) | |
18539 | { | |
18540 | body = read_direct_string (abfd, mac_ptr, &bytes_read); | |
18541 | mac_ptr += bytes_read; | |
18542 | } | |
18543 | else | |
18544 | { | |
18545 | LONGEST str_offset; | |
18546 | ||
18547 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
18548 | mac_ptr += offset_size; | |
2e276125 | 18549 | |
36586728 | 18550 | if (macinfo_type == DW_MACRO_GNU_define_indirect_alt |
f7a35f02 TT |
18551 | || macinfo_type == DW_MACRO_GNU_undef_indirect_alt |
18552 | || section_is_dwz) | |
36586728 TT |
18553 | { |
18554 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
18555 | ||
18556 | body = read_indirect_string_from_dwz (dwz, str_offset); | |
18557 | } | |
18558 | else | |
18559 | body = read_indirect_string_at_offset (abfd, str_offset); | |
cf2c3c16 TT |
18560 | } |
18561 | ||
18562 | is_define = (macinfo_type == DW_MACRO_GNU_define | |
36586728 TT |
18563 | || macinfo_type == DW_MACRO_GNU_define_indirect |
18564 | || macinfo_type == DW_MACRO_GNU_define_indirect_alt); | |
2e276125 | 18565 | if (! current_file) |
757a13d0 JK |
18566 | { |
18567 | /* DWARF violation as no main source is present. */ | |
18568 | complaint (&symfile_complaints, | |
18569 | _("debug info with no main source gives macro %s " | |
18570 | "on line %d: %s"), | |
cf2c3c16 TT |
18571 | is_define ? _("definition") : _("undefinition"), |
18572 | line, body); | |
757a13d0 JK |
18573 | break; |
18574 | } | |
3e43a32a MS |
18575 | if ((line == 0 && !at_commandline) |
18576 | || (line != 0 && at_commandline)) | |
4d3c2250 | 18577 | complaint (&symfile_complaints, |
757a13d0 JK |
18578 | _("debug info gives %s macro %s with %s line %d: %s"), |
18579 | at_commandline ? _("command-line") : _("in-file"), | |
cf2c3c16 | 18580 | is_define ? _("definition") : _("undefinition"), |
757a13d0 JK |
18581 | line == 0 ? _("zero") : _("non-zero"), line, body); |
18582 | ||
cf2c3c16 | 18583 | if (is_define) |
757a13d0 | 18584 | parse_macro_definition (current_file, line, body); |
cf2c3c16 TT |
18585 | else |
18586 | { | |
18587 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef | |
36586728 TT |
18588 | || macinfo_type == DW_MACRO_GNU_undef_indirect |
18589 | || macinfo_type == DW_MACRO_GNU_undef_indirect_alt); | |
cf2c3c16 TT |
18590 | macro_undef (current_file, line, body); |
18591 | } | |
2e276125 JB |
18592 | } |
18593 | break; | |
18594 | ||
cf2c3c16 | 18595 | case DW_MACRO_GNU_start_file: |
2e276125 | 18596 | { |
891d2f0b | 18597 | unsigned int bytes_read; |
2e276125 JB |
18598 | int line, file; |
18599 | ||
18600 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
18601 | mac_ptr += bytes_read; | |
18602 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
18603 | mac_ptr += bytes_read; | |
18604 | ||
3e43a32a MS |
18605 | if ((line == 0 && !at_commandline) |
18606 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
18607 | complaint (&symfile_complaints, |
18608 | _("debug info gives source %d included " | |
18609 | "from %s at %s line %d"), | |
18610 | file, at_commandline ? _("command-line") : _("file"), | |
18611 | line == 0 ? _("zero") : _("non-zero"), line); | |
18612 | ||
18613 | if (at_commandline) | |
18614 | { | |
cf2c3c16 TT |
18615 | /* This DW_MACRO_GNU_start_file was executed in the |
18616 | pass one. */ | |
757a13d0 JK |
18617 | at_commandline = 0; |
18618 | } | |
18619 | else | |
18620 | current_file = macro_start_file (file, line, | |
18621 | current_file, comp_dir, | |
cf2c3c16 | 18622 | lh, objfile); |
2e276125 JB |
18623 | } |
18624 | break; | |
18625 | ||
cf2c3c16 | 18626 | case DW_MACRO_GNU_end_file: |
2e276125 | 18627 | if (! current_file) |
4d3c2250 | 18628 | complaint (&symfile_complaints, |
3e43a32a MS |
18629 | _("macro debug info has an unmatched " |
18630 | "`close_file' directive")); | |
2e276125 JB |
18631 | else |
18632 | { | |
18633 | current_file = current_file->included_by; | |
18634 | if (! current_file) | |
18635 | { | |
cf2c3c16 | 18636 | enum dwarf_macro_record_type next_type; |
2e276125 JB |
18637 | |
18638 | /* GCC circa March 2002 doesn't produce the zero | |
18639 | type byte marking the end of the compilation | |
18640 | unit. Complain if it's not there, but exit no | |
18641 | matter what. */ | |
18642 | ||
18643 | /* Do we at least have room for a macinfo type byte? */ | |
18644 | if (mac_ptr >= mac_end) | |
18645 | { | |
f664829e | 18646 | dwarf2_section_buffer_overflow_complaint (section); |
2e276125 JB |
18647 | return; |
18648 | } | |
18649 | ||
18650 | /* We don't increment mac_ptr here, so this is just | |
18651 | a look-ahead. */ | |
18652 | next_type = read_1_byte (abfd, mac_ptr); | |
18653 | if (next_type != 0) | |
4d3c2250 | 18654 | complaint (&symfile_complaints, |
3e43a32a MS |
18655 | _("no terminating 0-type entry for " |
18656 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
18657 | |
18658 | return; | |
18659 | } | |
18660 | } | |
18661 | break; | |
18662 | ||
cf2c3c16 | 18663 | case DW_MACRO_GNU_transparent_include: |
36586728 | 18664 | case DW_MACRO_GNU_transparent_include_alt: |
cf2c3c16 TT |
18665 | { |
18666 | LONGEST offset; | |
8fc3fc34 | 18667 | void **slot; |
a036ba48 TT |
18668 | bfd *include_bfd = abfd; |
18669 | struct dwarf2_section_info *include_section = section; | |
18670 | struct dwarf2_section_info alt_section; | |
18671 | gdb_byte *include_mac_end = mac_end; | |
18672 | int is_dwz = section_is_dwz; | |
18673 | gdb_byte *new_mac_ptr; | |
cf2c3c16 TT |
18674 | |
18675 | offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
18676 | mac_ptr += offset_size; | |
18677 | ||
a036ba48 TT |
18678 | if (macinfo_type == DW_MACRO_GNU_transparent_include_alt) |
18679 | { | |
18680 | struct dwz_file *dwz = dwarf2_get_dwz_file (); | |
18681 | ||
18682 | dwarf2_read_section (dwarf2_per_objfile->objfile, | |
18683 | &dwz->macro); | |
18684 | ||
18685 | include_bfd = dwz->macro.asection->owner; | |
18686 | include_section = &dwz->macro; | |
18687 | include_mac_end = dwz->macro.buffer + dwz->macro.size; | |
18688 | is_dwz = 1; | |
18689 | } | |
18690 | ||
18691 | new_mac_ptr = include_section->buffer + offset; | |
18692 | slot = htab_find_slot (include_hash, new_mac_ptr, INSERT); | |
18693 | ||
8fc3fc34 TT |
18694 | if (*slot != NULL) |
18695 | { | |
18696 | /* This has actually happened; see | |
18697 | http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */ | |
18698 | complaint (&symfile_complaints, | |
18699 | _("recursive DW_MACRO_GNU_transparent_include in " | |
18700 | ".debug_macro section")); | |
18701 | } | |
18702 | else | |
18703 | { | |
a036ba48 | 18704 | *slot = new_mac_ptr; |
36586728 | 18705 | |
a036ba48 | 18706 | dwarf_decode_macro_bytes (include_bfd, new_mac_ptr, |
36586728 | 18707 | include_mac_end, current_file, |
8fc3fc34 | 18708 | lh, comp_dir, |
36586728 | 18709 | section, section_is_gnu, is_dwz, |
8fc3fc34 TT |
18710 | offset_size, objfile, include_hash); |
18711 | ||
a036ba48 | 18712 | htab_remove_elt (include_hash, new_mac_ptr); |
8fc3fc34 | 18713 | } |
cf2c3c16 TT |
18714 | } |
18715 | break; | |
18716 | ||
2e276125 | 18717 | case DW_MACINFO_vendor_ext: |
cf2c3c16 TT |
18718 | if (!section_is_gnu) |
18719 | { | |
18720 | unsigned int bytes_read; | |
18721 | int constant; | |
2e276125 | 18722 | |
cf2c3c16 TT |
18723 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
18724 | mac_ptr += bytes_read; | |
18725 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
18726 | mac_ptr += bytes_read; | |
2e276125 | 18727 | |
cf2c3c16 TT |
18728 | /* We don't recognize any vendor extensions. */ |
18729 | break; | |
18730 | } | |
18731 | /* FALLTHROUGH */ | |
18732 | ||
18733 | default: | |
18734 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
f664829e | 18735 | mac_ptr, mac_end, abfd, offset_size, |
cf2c3c16 TT |
18736 | section); |
18737 | if (mac_ptr == NULL) | |
18738 | return; | |
18739 | break; | |
2e276125 | 18740 | } |
757a13d0 | 18741 | } while (macinfo_type != 0); |
2e276125 | 18742 | } |
8e19ed76 | 18743 | |
cf2c3c16 | 18744 | static void |
09262596 | 18745 | dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset, |
15d034d0 | 18746 | const char *comp_dir, int section_is_gnu) |
cf2c3c16 | 18747 | { |
bb5ed363 | 18748 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
09262596 DE |
18749 | struct line_header *lh = cu->line_header; |
18750 | bfd *abfd; | |
cf2c3c16 TT |
18751 | gdb_byte *mac_ptr, *mac_end; |
18752 | struct macro_source_file *current_file = 0; | |
18753 | enum dwarf_macro_record_type macinfo_type; | |
18754 | unsigned int offset_size = cu->header.offset_size; | |
18755 | gdb_byte *opcode_definitions[256]; | |
8fc3fc34 TT |
18756 | struct cleanup *cleanup; |
18757 | htab_t include_hash; | |
18758 | void **slot; | |
09262596 DE |
18759 | struct dwarf2_section_info *section; |
18760 | const char *section_name; | |
18761 | ||
18762 | if (cu->dwo_unit != NULL) | |
18763 | { | |
18764 | if (section_is_gnu) | |
18765 | { | |
18766 | section = &cu->dwo_unit->dwo_file->sections.macro; | |
18767 | section_name = ".debug_macro.dwo"; | |
18768 | } | |
18769 | else | |
18770 | { | |
18771 | section = &cu->dwo_unit->dwo_file->sections.macinfo; | |
18772 | section_name = ".debug_macinfo.dwo"; | |
18773 | } | |
18774 | } | |
18775 | else | |
18776 | { | |
18777 | if (section_is_gnu) | |
18778 | { | |
18779 | section = &dwarf2_per_objfile->macro; | |
18780 | section_name = ".debug_macro"; | |
18781 | } | |
18782 | else | |
18783 | { | |
18784 | section = &dwarf2_per_objfile->macinfo; | |
18785 | section_name = ".debug_macinfo"; | |
18786 | } | |
18787 | } | |
cf2c3c16 | 18788 | |
bb5ed363 | 18789 | dwarf2_read_section (objfile, section); |
cf2c3c16 TT |
18790 | if (section->buffer == NULL) |
18791 | { | |
fceca515 | 18792 | complaint (&symfile_complaints, _("missing %s section"), section_name); |
cf2c3c16 TT |
18793 | return; |
18794 | } | |
09262596 | 18795 | abfd = section->asection->owner; |
cf2c3c16 TT |
18796 | |
18797 | /* First pass: Find the name of the base filename. | |
18798 | This filename is needed in order to process all macros whose definition | |
18799 | (or undefinition) comes from the command line. These macros are defined | |
18800 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
18801 | associated to the base file. | |
18802 | ||
18803 | To determine the base file name, we scan the macro definitions until we | |
18804 | reach the first DW_MACINFO_start_file entry. We then initialize | |
18805 | CURRENT_FILE accordingly so that any macro definition found before the | |
18806 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
18807 | ||
18808 | mac_ptr = section->buffer + offset; | |
18809 | mac_end = section->buffer + section->size; | |
18810 | ||
18811 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, | |
18812 | &offset_size, section_is_gnu); | |
18813 | if (mac_ptr == NULL) | |
18814 | { | |
18815 | /* We already issued a complaint. */ | |
18816 | return; | |
18817 | } | |
18818 | ||
18819 | do | |
18820 | { | |
18821 | /* Do we at least have room for a macinfo type byte? */ | |
18822 | if (mac_ptr >= mac_end) | |
18823 | { | |
18824 | /* Complaint is printed during the second pass as GDB will probably | |
18825 | stop the first pass earlier upon finding | |
18826 | DW_MACINFO_start_file. */ | |
18827 | break; | |
18828 | } | |
18829 | ||
18830 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
18831 | mac_ptr++; | |
18832 | ||
18833 | /* Note that we rely on the fact that the corresponding GNU and | |
18834 | DWARF constants are the same. */ | |
18835 | switch (macinfo_type) | |
18836 | { | |
18837 | /* A zero macinfo type indicates the end of the macro | |
18838 | information. */ | |
18839 | case 0: | |
18840 | break; | |
18841 | ||
18842 | case DW_MACRO_GNU_define: | |
18843 | case DW_MACRO_GNU_undef: | |
18844 | /* Only skip the data by MAC_PTR. */ | |
18845 | { | |
18846 | unsigned int bytes_read; | |
18847 | ||
18848 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
18849 | mac_ptr += bytes_read; | |
18850 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
18851 | mac_ptr += bytes_read; | |
18852 | } | |
18853 | break; | |
18854 | ||
18855 | case DW_MACRO_GNU_start_file: | |
18856 | { | |
18857 | unsigned int bytes_read; | |
18858 | int line, file; | |
18859 | ||
18860 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
18861 | mac_ptr += bytes_read; | |
18862 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
18863 | mac_ptr += bytes_read; | |
18864 | ||
18865 | current_file = macro_start_file (file, line, current_file, | |
bb5ed363 | 18866 | comp_dir, lh, objfile); |
cf2c3c16 TT |
18867 | } |
18868 | break; | |
18869 | ||
18870 | case DW_MACRO_GNU_end_file: | |
18871 | /* No data to skip by MAC_PTR. */ | |
18872 | break; | |
18873 | ||
18874 | case DW_MACRO_GNU_define_indirect: | |
18875 | case DW_MACRO_GNU_undef_indirect: | |
f7a35f02 TT |
18876 | case DW_MACRO_GNU_define_indirect_alt: |
18877 | case DW_MACRO_GNU_undef_indirect_alt: | |
cf2c3c16 TT |
18878 | { |
18879 | unsigned int bytes_read; | |
18880 | ||
18881 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
18882 | mac_ptr += bytes_read; | |
18883 | mac_ptr += offset_size; | |
18884 | } | |
18885 | break; | |
18886 | ||
18887 | case DW_MACRO_GNU_transparent_include: | |
f7a35f02 | 18888 | case DW_MACRO_GNU_transparent_include_alt: |
cf2c3c16 TT |
18889 | /* Note that, according to the spec, a transparent include |
18890 | chain cannot call DW_MACRO_GNU_start_file. So, we can just | |
18891 | skip this opcode. */ | |
18892 | mac_ptr += offset_size; | |
18893 | break; | |
18894 | ||
18895 | case DW_MACINFO_vendor_ext: | |
18896 | /* Only skip the data by MAC_PTR. */ | |
18897 | if (!section_is_gnu) | |
18898 | { | |
18899 | unsigned int bytes_read; | |
18900 | ||
18901 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
18902 | mac_ptr += bytes_read; | |
18903 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
18904 | mac_ptr += bytes_read; | |
18905 | } | |
18906 | /* FALLTHROUGH */ | |
18907 | ||
18908 | default: | |
18909 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
f664829e | 18910 | mac_ptr, mac_end, abfd, offset_size, |
cf2c3c16 TT |
18911 | section); |
18912 | if (mac_ptr == NULL) | |
18913 | return; | |
18914 | break; | |
18915 | } | |
18916 | } while (macinfo_type != 0 && current_file == NULL); | |
18917 | ||
18918 | /* Second pass: Process all entries. | |
18919 | ||
18920 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
18921 | command-line macro definitions/undefinitions. This flag is unset when we | |
18922 | reach the first DW_MACINFO_start_file entry. */ | |
18923 | ||
8fc3fc34 TT |
18924 | include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, |
18925 | NULL, xcalloc, xfree); | |
18926 | cleanup = make_cleanup_htab_delete (include_hash); | |
18927 | mac_ptr = section->buffer + offset; | |
18928 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); | |
18929 | *slot = mac_ptr; | |
18930 | dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end, | |
36586728 TT |
18931 | current_file, lh, comp_dir, section, |
18932 | section_is_gnu, 0, | |
8fc3fc34 TT |
18933 | offset_size, objfile, include_hash); |
18934 | do_cleanups (cleanup); | |
cf2c3c16 TT |
18935 | } |
18936 | ||
8e19ed76 | 18937 | /* Check if the attribute's form is a DW_FORM_block* |
0963b4bd | 18938 | if so return true else false. */ |
380bca97 | 18939 | |
8e19ed76 PS |
18940 | static int |
18941 | attr_form_is_block (struct attribute *attr) | |
18942 | { | |
18943 | return (attr == NULL ? 0 : | |
18944 | attr->form == DW_FORM_block1 | |
18945 | || attr->form == DW_FORM_block2 | |
18946 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
18947 | || attr->form == DW_FORM_block |
18948 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 18949 | } |
4c2df51b | 18950 | |
c6a0999f JB |
18951 | /* Return non-zero if ATTR's value is a section offset --- classes |
18952 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
18953 | You may use DW_UNSND (attr) to retrieve such offsets. | |
18954 | ||
18955 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
18956 | may have a value that belongs to more than one of these classes; it | |
18957 | would be ambiguous if we did, because we use the same forms for all | |
18958 | of them. */ | |
380bca97 | 18959 | |
3690dd37 JB |
18960 | static int |
18961 | attr_form_is_section_offset (struct attribute *attr) | |
18962 | { | |
18963 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
18964 | || attr->form == DW_FORM_data8 |
18965 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
18966 | } |
18967 | ||
3690dd37 JB |
18968 | /* Return non-zero if ATTR's value falls in the 'constant' class, or |
18969 | zero otherwise. When this function returns true, you can apply | |
18970 | dwarf2_get_attr_constant_value to it. | |
18971 | ||
18972 | However, note that for some attributes you must check | |
18973 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
18974 | and DW_FORM_data8 are members of both the constant class, and of | |
18975 | the classes that contain offsets into other debug sections | |
18976 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
18977 | that, if an attribute's can be either a constant or one of the | |
18978 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
18979 | taken as section offsets, not constants. */ | |
380bca97 | 18980 | |
3690dd37 JB |
18981 | static int |
18982 | attr_form_is_constant (struct attribute *attr) | |
18983 | { | |
18984 | switch (attr->form) | |
18985 | { | |
18986 | case DW_FORM_sdata: | |
18987 | case DW_FORM_udata: | |
18988 | case DW_FORM_data1: | |
18989 | case DW_FORM_data2: | |
18990 | case DW_FORM_data4: | |
18991 | case DW_FORM_data8: | |
18992 | return 1; | |
18993 | default: | |
18994 | return 0; | |
18995 | } | |
18996 | } | |
18997 | ||
3019eac3 DE |
18998 | /* Return the .debug_loc section to use for CU. |
18999 | For DWO files use .debug_loc.dwo. */ | |
19000 | ||
19001 | static struct dwarf2_section_info * | |
19002 | cu_debug_loc_section (struct dwarf2_cu *cu) | |
19003 | { | |
19004 | if (cu->dwo_unit) | |
19005 | return &cu->dwo_unit->dwo_file->sections.loc; | |
19006 | return &dwarf2_per_objfile->loc; | |
19007 | } | |
19008 | ||
8cf6f0b1 TT |
19009 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
19010 | ||
19011 | static void | |
19012 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
19013 | struct dwarf2_loclist_baton *baton, | |
19014 | struct attribute *attr) | |
19015 | { | |
3019eac3 DE |
19016 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
19017 | ||
19018 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); | |
8cf6f0b1 TT |
19019 | |
19020 | baton->per_cu = cu->per_cu; | |
19021 | gdb_assert (baton->per_cu); | |
19022 | /* We don't know how long the location list is, but make sure we | |
19023 | don't run off the edge of the section. */ | |
3019eac3 DE |
19024 | baton->size = section->size - DW_UNSND (attr); |
19025 | baton->data = section->buffer + DW_UNSND (attr); | |
8cf6f0b1 | 19026 | baton->base_address = cu->base_address; |
f664829e | 19027 | baton->from_dwo = cu->dwo_unit != NULL; |
8cf6f0b1 TT |
19028 | } |
19029 | ||
4c2df51b DJ |
19030 | static void |
19031 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 19032 | struct dwarf2_cu *cu) |
4c2df51b | 19033 | { |
bb5ed363 | 19034 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
3019eac3 | 19035 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
bb5ed363 | 19036 | |
3690dd37 | 19037 | if (attr_form_is_section_offset (attr) |
3019eac3 | 19038 | /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside |
99bcc461 DJ |
19039 | the section. If so, fall through to the complaint in the |
19040 | other branch. */ | |
3019eac3 | 19041 | && DW_UNSND (attr) < dwarf2_section_size (objfile, section)) |
4c2df51b | 19042 | { |
0d53c4c4 | 19043 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 19044 | |
bb5ed363 | 19045 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 19046 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 19047 | |
8cf6f0b1 | 19048 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 19049 | |
d00adf39 | 19050 | if (cu->base_known == 0) |
0d53c4c4 | 19051 | complaint (&symfile_complaints, |
3e43a32a MS |
19052 | _("Location list used without " |
19053 | "specifying the CU base address.")); | |
4c2df51b | 19054 | |
768a979c | 19055 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
19056 | SYMBOL_LOCATION_BATON (sym) = baton; |
19057 | } | |
19058 | else | |
19059 | { | |
19060 | struct dwarf2_locexpr_baton *baton; | |
19061 | ||
bb5ed363 | 19062 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 19063 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
19064 | baton->per_cu = cu->per_cu; |
19065 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
19066 | |
19067 | if (attr_form_is_block (attr)) | |
19068 | { | |
19069 | /* Note that we're just copying the block's data pointer | |
19070 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
19071 | info_buffer for SYM's objfile; right now we never release |
19072 | that buffer, but when we do clean up properly this may | |
19073 | need to change. */ | |
0d53c4c4 DJ |
19074 | baton->size = DW_BLOCK (attr)->size; |
19075 | baton->data = DW_BLOCK (attr)->data; | |
19076 | } | |
19077 | else | |
19078 | { | |
19079 | dwarf2_invalid_attrib_class_complaint ("location description", | |
19080 | SYMBOL_NATURAL_NAME (sym)); | |
19081 | baton->size = 0; | |
0d53c4c4 | 19082 | } |
6e70227d | 19083 | |
768a979c | 19084 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
19085 | SYMBOL_LOCATION_BATON (sym) = baton; |
19086 | } | |
4c2df51b | 19087 | } |
6502dd73 | 19088 | |
9aa1f1e3 TT |
19089 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
19090 | came from a separate debuginfo file, then the master objfile is | |
19091 | returned. */ | |
ae0d2f24 UW |
19092 | |
19093 | struct objfile * | |
19094 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
19095 | { | |
9291a0cd | 19096 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
19097 | |
19098 | /* Return the master objfile, so that we can report and look up the | |
19099 | correct file containing this variable. */ | |
19100 | if (objfile->separate_debug_objfile_backlink) | |
19101 | objfile = objfile->separate_debug_objfile_backlink; | |
19102 | ||
19103 | return objfile; | |
19104 | } | |
19105 | ||
96408a79 SA |
19106 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
19107 | (CU_HEADERP is unused in such case) or prepare a temporary copy at | |
19108 | CU_HEADERP first. */ | |
19109 | ||
19110 | static const struct comp_unit_head * | |
19111 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, | |
19112 | struct dwarf2_per_cu_data *per_cu) | |
19113 | { | |
96408a79 SA |
19114 | gdb_byte *info_ptr; |
19115 | ||
19116 | if (per_cu->cu) | |
19117 | return &per_cu->cu->header; | |
19118 | ||
0bc3a05c | 19119 | info_ptr = per_cu->info_or_types_section->buffer + per_cu->offset.sect_off; |
96408a79 SA |
19120 | |
19121 | memset (cu_headerp, 0, sizeof (*cu_headerp)); | |
0bc3a05c | 19122 | read_comp_unit_head (cu_headerp, info_ptr, per_cu->objfile->obfd); |
96408a79 SA |
19123 | |
19124 | return cu_headerp; | |
19125 | } | |
19126 | ||
ae0d2f24 UW |
19127 | /* Return the address size given in the compilation unit header for CU. */ |
19128 | ||
98714339 | 19129 | int |
ae0d2f24 UW |
19130 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
19131 | { | |
96408a79 SA |
19132 | struct comp_unit_head cu_header_local; |
19133 | const struct comp_unit_head *cu_headerp; | |
c471e790 | 19134 | |
96408a79 SA |
19135 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
19136 | ||
19137 | return cu_headerp->addr_size; | |
ae0d2f24 UW |
19138 | } |
19139 | ||
9eae7c52 TT |
19140 | /* Return the offset size given in the compilation unit header for CU. */ |
19141 | ||
19142 | int | |
19143 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
19144 | { | |
96408a79 SA |
19145 | struct comp_unit_head cu_header_local; |
19146 | const struct comp_unit_head *cu_headerp; | |
9c6c53f7 | 19147 | |
96408a79 SA |
19148 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
19149 | ||
19150 | return cu_headerp->offset_size; | |
19151 | } | |
19152 | ||
19153 | /* See its dwarf2loc.h declaration. */ | |
19154 | ||
19155 | int | |
19156 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) | |
19157 | { | |
19158 | struct comp_unit_head cu_header_local; | |
19159 | const struct comp_unit_head *cu_headerp; | |
19160 | ||
19161 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); | |
19162 | ||
19163 | if (cu_headerp->version == 2) | |
19164 | return cu_headerp->addr_size; | |
19165 | else | |
19166 | return cu_headerp->offset_size; | |
181cebd4 JK |
19167 | } |
19168 | ||
9aa1f1e3 TT |
19169 | /* Return the text offset of the CU. The returned offset comes from |
19170 | this CU's objfile. If this objfile came from a separate debuginfo | |
19171 | file, then the offset may be different from the corresponding | |
19172 | offset in the parent objfile. */ | |
19173 | ||
19174 | CORE_ADDR | |
19175 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
19176 | { | |
bb3fa9d0 | 19177 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
19178 | |
19179 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
19180 | } | |
19181 | ||
348e048f DE |
19182 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
19183 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
19184 | |
19185 | static struct dwarf2_per_cu_data * | |
b64f50a1 | 19186 | dwarf2_find_containing_comp_unit (sect_offset offset, |
36586728 | 19187 | unsigned int offset_in_dwz, |
ae038cb0 DJ |
19188 | struct objfile *objfile) |
19189 | { | |
19190 | struct dwarf2_per_cu_data *this_cu; | |
19191 | int low, high; | |
36586728 | 19192 | const sect_offset *cu_off; |
ae038cb0 | 19193 | |
ae038cb0 DJ |
19194 | low = 0; |
19195 | high = dwarf2_per_objfile->n_comp_units - 1; | |
19196 | while (high > low) | |
19197 | { | |
36586728 | 19198 | struct dwarf2_per_cu_data *mid_cu; |
ae038cb0 | 19199 | int mid = low + (high - low) / 2; |
9a619af0 | 19200 | |
36586728 TT |
19201 | mid_cu = dwarf2_per_objfile->all_comp_units[mid]; |
19202 | cu_off = &mid_cu->offset; | |
19203 | if (mid_cu->is_dwz > offset_in_dwz | |
19204 | || (mid_cu->is_dwz == offset_in_dwz | |
19205 | && cu_off->sect_off >= offset.sect_off)) | |
ae038cb0 DJ |
19206 | high = mid; |
19207 | else | |
19208 | low = mid + 1; | |
19209 | } | |
19210 | gdb_assert (low == high); | |
36586728 TT |
19211 | this_cu = dwarf2_per_objfile->all_comp_units[low]; |
19212 | cu_off = &this_cu->offset; | |
19213 | if (this_cu->is_dwz != offset_in_dwz || cu_off->sect_off > offset.sect_off) | |
ae038cb0 | 19214 | { |
36586728 | 19215 | if (low == 0 || this_cu->is_dwz != offset_in_dwz) |
8a3fe4f8 AC |
19216 | error (_("Dwarf Error: could not find partial DIE containing " |
19217 | "offset 0x%lx [in module %s]"), | |
b64f50a1 | 19218 | (long) offset.sect_off, bfd_get_filename (objfile->obfd)); |
10b3939b | 19219 | |
b64f50a1 JK |
19220 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset.sect_off |
19221 | <= offset.sect_off); | |
ae038cb0 DJ |
19222 | return dwarf2_per_objfile->all_comp_units[low-1]; |
19223 | } | |
19224 | else | |
19225 | { | |
19226 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
19227 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
b64f50a1 JK |
19228 | && offset.sect_off >= this_cu->offset.sect_off + this_cu->length) |
19229 | error (_("invalid dwarf2 offset %u"), offset.sect_off); | |
19230 | gdb_assert (offset.sect_off < this_cu->offset.sect_off + this_cu->length); | |
ae038cb0 DJ |
19231 | return this_cu; |
19232 | } | |
19233 | } | |
19234 | ||
23745b47 | 19235 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
93311388 | 19236 | |
9816fde3 | 19237 | static void |
23745b47 | 19238 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
93311388 | 19239 | { |
9816fde3 | 19240 | memset (cu, 0, sizeof (*cu)); |
23745b47 DE |
19241 | per_cu->cu = cu; |
19242 | cu->per_cu = per_cu; | |
19243 | cu->objfile = per_cu->objfile; | |
93311388 | 19244 | obstack_init (&cu->comp_unit_obstack); |
9816fde3 JK |
19245 | } |
19246 | ||
19247 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
19248 | ||
19249 | static void | |
95554aad TT |
19250 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die, |
19251 | enum language pretend_language) | |
9816fde3 JK |
19252 | { |
19253 | struct attribute *attr; | |
19254 | ||
19255 | /* Set the language we're debugging. */ | |
19256 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
19257 | if (attr) | |
19258 | set_cu_language (DW_UNSND (attr), cu); | |
19259 | else | |
9cded63f | 19260 | { |
95554aad | 19261 | cu->language = pretend_language; |
9cded63f TT |
19262 | cu->language_defn = language_def (cu->language); |
19263 | } | |
dee91e82 DE |
19264 | |
19265 | attr = dwarf2_attr (comp_unit_die, DW_AT_producer, cu); | |
19266 | if (attr) | |
19267 | cu->producer = DW_STRING (attr); | |
93311388 DE |
19268 | } |
19269 | ||
ae038cb0 DJ |
19270 | /* Release one cached compilation unit, CU. We unlink it from the tree |
19271 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
19272 | the caller is responsible for that. |
19273 | NOTE: DATA is a void * because this function is also used as a | |
19274 | cleanup routine. */ | |
ae038cb0 DJ |
19275 | |
19276 | static void | |
68dc6402 | 19277 | free_heap_comp_unit (void *data) |
ae038cb0 DJ |
19278 | { |
19279 | struct dwarf2_cu *cu = data; | |
19280 | ||
23745b47 DE |
19281 | gdb_assert (cu->per_cu != NULL); |
19282 | cu->per_cu->cu = NULL; | |
ae038cb0 DJ |
19283 | cu->per_cu = NULL; |
19284 | ||
19285 | obstack_free (&cu->comp_unit_obstack, NULL); | |
19286 | ||
19287 | xfree (cu); | |
19288 | } | |
19289 | ||
72bf9492 | 19290 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 | 19291 | when we're finished with it. We can't free the pointer itself, but be |
dee91e82 | 19292 | sure to unlink it from the cache. Also release any associated storage. */ |
72bf9492 DJ |
19293 | |
19294 | static void | |
19295 | free_stack_comp_unit (void *data) | |
19296 | { | |
19297 | struct dwarf2_cu *cu = data; | |
19298 | ||
23745b47 DE |
19299 | gdb_assert (cu->per_cu != NULL); |
19300 | cu->per_cu->cu = NULL; | |
19301 | cu->per_cu = NULL; | |
19302 | ||
72bf9492 DJ |
19303 | obstack_free (&cu->comp_unit_obstack, NULL); |
19304 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
19305 | } |
19306 | ||
19307 | /* Free all cached compilation units. */ | |
19308 | ||
19309 | static void | |
19310 | free_cached_comp_units (void *data) | |
19311 | { | |
19312 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
19313 | ||
19314 | per_cu = dwarf2_per_objfile->read_in_chain; | |
19315 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
19316 | while (per_cu != NULL) | |
19317 | { | |
19318 | struct dwarf2_per_cu_data *next_cu; | |
19319 | ||
19320 | next_cu = per_cu->cu->read_in_chain; | |
19321 | ||
68dc6402 | 19322 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
19323 | *last_chain = next_cu; |
19324 | ||
19325 | per_cu = next_cu; | |
19326 | } | |
19327 | } | |
19328 | ||
19329 | /* Increase the age counter on each cached compilation unit, and free | |
19330 | any that are too old. */ | |
19331 | ||
19332 | static void | |
19333 | age_cached_comp_units (void) | |
19334 | { | |
19335 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
19336 | ||
19337 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
19338 | per_cu = dwarf2_per_objfile->read_in_chain; | |
19339 | while (per_cu != NULL) | |
19340 | { | |
19341 | per_cu->cu->last_used ++; | |
19342 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
19343 | dwarf2_mark (per_cu->cu); | |
19344 | per_cu = per_cu->cu->read_in_chain; | |
19345 | } | |
19346 | ||
19347 | per_cu = dwarf2_per_objfile->read_in_chain; | |
19348 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
19349 | while (per_cu != NULL) | |
19350 | { | |
19351 | struct dwarf2_per_cu_data *next_cu; | |
19352 | ||
19353 | next_cu = per_cu->cu->read_in_chain; | |
19354 | ||
19355 | if (!per_cu->cu->mark) | |
19356 | { | |
68dc6402 | 19357 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
19358 | *last_chain = next_cu; |
19359 | } | |
19360 | else | |
19361 | last_chain = &per_cu->cu->read_in_chain; | |
19362 | ||
19363 | per_cu = next_cu; | |
19364 | } | |
19365 | } | |
19366 | ||
19367 | /* Remove a single compilation unit from the cache. */ | |
19368 | ||
19369 | static void | |
dee91e82 | 19370 | free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu) |
ae038cb0 DJ |
19371 | { |
19372 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
19373 | ||
19374 | per_cu = dwarf2_per_objfile->read_in_chain; | |
19375 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
19376 | while (per_cu != NULL) | |
19377 | { | |
19378 | struct dwarf2_per_cu_data *next_cu; | |
19379 | ||
19380 | next_cu = per_cu->cu->read_in_chain; | |
19381 | ||
dee91e82 | 19382 | if (per_cu == target_per_cu) |
ae038cb0 | 19383 | { |
68dc6402 | 19384 | free_heap_comp_unit (per_cu->cu); |
dee91e82 | 19385 | per_cu->cu = NULL; |
ae038cb0 DJ |
19386 | *last_chain = next_cu; |
19387 | break; | |
19388 | } | |
19389 | else | |
19390 | last_chain = &per_cu->cu->read_in_chain; | |
19391 | ||
19392 | per_cu = next_cu; | |
19393 | } | |
19394 | } | |
19395 | ||
fe3e1990 DJ |
19396 | /* Release all extra memory associated with OBJFILE. */ |
19397 | ||
19398 | void | |
19399 | dwarf2_free_objfile (struct objfile *objfile) | |
19400 | { | |
19401 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
19402 | ||
19403 | if (dwarf2_per_objfile == NULL) | |
19404 | return; | |
19405 | ||
19406 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
19407 | free_cached_comp_units (NULL); | |
19408 | ||
7b9f3c50 DE |
19409 | if (dwarf2_per_objfile->quick_file_names_table) |
19410 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 19411 | |
fe3e1990 DJ |
19412 | /* Everything else should be on the objfile obstack. */ |
19413 | } | |
19414 | ||
dee91e82 DE |
19415 | /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer. |
19416 | We store these in a hash table separate from the DIEs, and preserve them | |
19417 | when the DIEs are flushed out of cache. | |
19418 | ||
19419 | The CU "per_cu" pointer is needed because offset alone is not enough to | |
3019eac3 DE |
19420 | uniquely identify the type. A file may have multiple .debug_types sections, |
19421 | or the type may come from a DWO file. We have to use something in | |
19422 | dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup | |
19423 | routine, get_die_type_at_offset, from outside this file, and thus won't | |
19424 | necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life | |
19425 | of the objfile. */ | |
1c379e20 | 19426 | |
dee91e82 | 19427 | struct dwarf2_per_cu_offset_and_type |
1c379e20 | 19428 | { |
dee91e82 | 19429 | const struct dwarf2_per_cu_data *per_cu; |
b64f50a1 | 19430 | sect_offset offset; |
1c379e20 DJ |
19431 | struct type *type; |
19432 | }; | |
19433 | ||
dee91e82 | 19434 | /* Hash function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
19435 | |
19436 | static hashval_t | |
dee91e82 | 19437 | per_cu_offset_and_type_hash (const void *item) |
1c379e20 | 19438 | { |
dee91e82 | 19439 | const struct dwarf2_per_cu_offset_and_type *ofs = item; |
9a619af0 | 19440 | |
dee91e82 | 19441 | return (uintptr_t) ofs->per_cu + ofs->offset.sect_off; |
1c379e20 DJ |
19442 | } |
19443 | ||
dee91e82 | 19444 | /* Equality function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
19445 | |
19446 | static int | |
dee91e82 | 19447 | per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs) |
1c379e20 | 19448 | { |
dee91e82 DE |
19449 | const struct dwarf2_per_cu_offset_and_type *ofs_lhs = item_lhs; |
19450 | const struct dwarf2_per_cu_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 19451 | |
dee91e82 DE |
19452 | return (ofs_lhs->per_cu == ofs_rhs->per_cu |
19453 | && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off); | |
1c379e20 DJ |
19454 | } |
19455 | ||
19456 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
19457 | table if necessary. For convenience, return TYPE. |
19458 | ||
19459 | The DIEs reading must have careful ordering to: | |
19460 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
19461 | reading current DIE. | |
19462 | * Not trying to dereference contents of still incompletely read in types | |
19463 | while reading in other DIEs. | |
19464 | * Enable referencing still incompletely read in types just by a pointer to | |
19465 | the type without accessing its fields. | |
19466 | ||
19467 | Therefore caller should follow these rules: | |
19468 | * Try to fetch any prerequisite types we may need to build this DIE type | |
19469 | before building the type and calling set_die_type. | |
e71ec853 | 19470 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
19471 | possible before fetching more types to complete the current type. |
19472 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 19473 | |
f792889a | 19474 | static struct type * |
1c379e20 DJ |
19475 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
19476 | { | |
dee91e82 | 19477 | struct dwarf2_per_cu_offset_and_type **slot, ofs; |
673bfd45 | 19478 | struct objfile *objfile = cu->objfile; |
1c379e20 | 19479 | |
b4ba55a1 JB |
19480 | /* For Ada types, make sure that the gnat-specific data is always |
19481 | initialized (if not already set). There are a few types where | |
19482 | we should not be doing so, because the type-specific area is | |
19483 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
19484 | where the type-specific area is used to store the floatformat). | |
19485 | But this is not a problem, because the gnat-specific information | |
19486 | is actually not needed for these types. */ | |
19487 | if (need_gnat_info (cu) | |
19488 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
19489 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
19490 | && !HAVE_GNAT_AUX_INFO (type)) | |
19491 | INIT_GNAT_SPECIFIC (type); | |
19492 | ||
dee91e82 | 19493 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 19494 | { |
dee91e82 DE |
19495 | dwarf2_per_objfile->die_type_hash = |
19496 | htab_create_alloc_ex (127, | |
19497 | per_cu_offset_and_type_hash, | |
19498 | per_cu_offset_and_type_eq, | |
19499 | NULL, | |
19500 | &objfile->objfile_obstack, | |
19501 | hashtab_obstack_allocate, | |
19502 | dummy_obstack_deallocate); | |
f792889a | 19503 | } |
1c379e20 | 19504 | |
dee91e82 | 19505 | ofs.per_cu = cu->per_cu; |
1c379e20 DJ |
19506 | ofs.offset = die->offset; |
19507 | ofs.type = type; | |
dee91e82 DE |
19508 | slot = (struct dwarf2_per_cu_offset_and_type **) |
19509 | htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT); | |
7e314c57 JK |
19510 | if (*slot) |
19511 | complaint (&symfile_complaints, | |
19512 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
b64f50a1 | 19513 | die->offset.sect_off); |
673bfd45 | 19514 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 19515 | **slot = ofs; |
f792889a | 19516 | return type; |
1c379e20 DJ |
19517 | } |
19518 | ||
380bca97 | 19519 | /* Look up the type for the die at OFFSET in the appropriate type_hash |
673bfd45 | 19520 | table, or return NULL if the die does not have a saved type. */ |
1c379e20 DJ |
19521 | |
19522 | static struct type * | |
b64f50a1 | 19523 | get_die_type_at_offset (sect_offset offset, |
673bfd45 | 19524 | struct dwarf2_per_cu_data *per_cu) |
1c379e20 | 19525 | { |
dee91e82 | 19526 | struct dwarf2_per_cu_offset_and_type *slot, ofs; |
f792889a | 19527 | |
dee91e82 | 19528 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 19529 | return NULL; |
1c379e20 | 19530 | |
dee91e82 | 19531 | ofs.per_cu = per_cu; |
673bfd45 | 19532 | ofs.offset = offset; |
dee91e82 | 19533 | slot = htab_find (dwarf2_per_objfile->die_type_hash, &ofs); |
1c379e20 DJ |
19534 | if (slot) |
19535 | return slot->type; | |
19536 | else | |
19537 | return NULL; | |
19538 | } | |
19539 | ||
673bfd45 DE |
19540 | /* Look up the type for DIE in the appropriate type_hash table, |
19541 | or return NULL if DIE does not have a saved type. */ | |
19542 | ||
19543 | static struct type * | |
19544 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
19545 | { | |
19546 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
19547 | } | |
19548 | ||
10b3939b DJ |
19549 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
19550 | ||
19551 | static void | |
19552 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
19553 | struct dwarf2_per_cu_data *ref_per_cu) | |
19554 | { | |
19555 | void **slot; | |
19556 | ||
19557 | if (cu->dependencies == NULL) | |
19558 | cu->dependencies | |
19559 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
19560 | NULL, &cu->comp_unit_obstack, | |
19561 | hashtab_obstack_allocate, | |
19562 | dummy_obstack_deallocate); | |
19563 | ||
19564 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
19565 | if (*slot == NULL) | |
19566 | *slot = ref_per_cu; | |
19567 | } | |
1c379e20 | 19568 | |
f504f079 DE |
19569 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
19570 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
19571 | cache that we must keep because we are keeping CU. */ |
19572 | ||
10b3939b DJ |
19573 | static int |
19574 | dwarf2_mark_helper (void **slot, void *data) | |
19575 | { | |
19576 | struct dwarf2_per_cu_data *per_cu; | |
19577 | ||
19578 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
d07ed419 JK |
19579 | |
19580 | /* cu->dependencies references may not yet have been ever read if QUIT aborts | |
19581 | reading of the chain. As such dependencies remain valid it is not much | |
19582 | useful to track and undo them during QUIT cleanups. */ | |
19583 | if (per_cu->cu == NULL) | |
19584 | return 1; | |
19585 | ||
10b3939b DJ |
19586 | if (per_cu->cu->mark) |
19587 | return 1; | |
19588 | per_cu->cu->mark = 1; | |
19589 | ||
19590 | if (per_cu->cu->dependencies != NULL) | |
19591 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
19592 | ||
19593 | return 1; | |
19594 | } | |
19595 | ||
f504f079 DE |
19596 | /* Set the mark field in CU and in every other compilation unit in the |
19597 | cache that we must keep because we are keeping CU. */ | |
19598 | ||
ae038cb0 DJ |
19599 | static void |
19600 | dwarf2_mark (struct dwarf2_cu *cu) | |
19601 | { | |
19602 | if (cu->mark) | |
19603 | return; | |
19604 | cu->mark = 1; | |
10b3939b DJ |
19605 | if (cu->dependencies != NULL) |
19606 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
19607 | } |
19608 | ||
19609 | static void | |
19610 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
19611 | { | |
19612 | while (per_cu) | |
19613 | { | |
19614 | per_cu->cu->mark = 0; | |
19615 | per_cu = per_cu->cu->read_in_chain; | |
19616 | } | |
72bf9492 DJ |
19617 | } |
19618 | ||
72bf9492 DJ |
19619 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
19620 | is its offset in .debug_info for this objfile. */ | |
19621 | ||
19622 | static hashval_t | |
19623 | partial_die_hash (const void *item) | |
19624 | { | |
19625 | const struct partial_die_info *part_die = item; | |
9a619af0 | 19626 | |
b64f50a1 | 19627 | return part_die->offset.sect_off; |
72bf9492 DJ |
19628 | } |
19629 | ||
19630 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
19631 | are equal if they have the same offset. */ | |
19632 | ||
19633 | static int | |
19634 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
19635 | { | |
19636 | const struct partial_die_info *part_die_lhs = item_lhs; | |
19637 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 19638 | |
b64f50a1 | 19639 | return part_die_lhs->offset.sect_off == part_die_rhs->offset.sect_off; |
72bf9492 DJ |
19640 | } |
19641 | ||
ae038cb0 DJ |
19642 | static struct cmd_list_element *set_dwarf2_cmdlist; |
19643 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
19644 | ||
19645 | static void | |
19646 | set_dwarf2_cmd (char *args, int from_tty) | |
19647 | { | |
19648 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
19649 | } | |
19650 | ||
19651 | static void | |
19652 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 19653 | { |
ae038cb0 DJ |
19654 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
19655 | } | |
19656 | ||
4bf44c1c | 19657 | /* Free data associated with OBJFILE, if necessary. */ |
dce234bc PP |
19658 | |
19659 | static void | |
c1bd65d0 | 19660 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
19661 | { |
19662 | struct dwarf2_per_objfile *data = d; | |
8b70b953 | 19663 | int ix; |
8b70b953 | 19664 | |
95554aad TT |
19665 | for (ix = 0; ix < dwarf2_per_objfile->n_comp_units; ++ix) |
19666 | VEC_free (dwarf2_per_cu_ptr, | |
796a7ff8 DE |
19667 | dwarf2_per_objfile->all_comp_units[ix]->imported_symtabs); |
19668 | ||
19669 | for (ix = 0; ix < dwarf2_per_objfile->n_type_units; ++ix) | |
19670 | VEC_free (dwarf2_per_cu_ptr, | |
19671 | dwarf2_per_objfile->all_type_units[ix]->per_cu.imported_symtabs); | |
95554aad | 19672 | |
8b70b953 | 19673 | VEC_free (dwarf2_section_info_def, data->types); |
3019eac3 DE |
19674 | |
19675 | if (data->dwo_files) | |
19676 | free_dwo_files (data->dwo_files, objfile); | |
36586728 TT |
19677 | |
19678 | if (data->dwz_file && data->dwz_file->dwz_bfd) | |
19679 | gdb_bfd_unref (data->dwz_file->dwz_bfd); | |
9291a0cd TT |
19680 | } |
19681 | ||
19682 | \f | |
ae2de4f8 | 19683 | /* The "save gdb-index" command. */ |
9291a0cd TT |
19684 | |
19685 | /* The contents of the hash table we create when building the string | |
19686 | table. */ | |
19687 | struct strtab_entry | |
19688 | { | |
19689 | offset_type offset; | |
19690 | const char *str; | |
19691 | }; | |
19692 | ||
559a7a62 JK |
19693 | /* Hash function for a strtab_entry. |
19694 | ||
19695 | Function is used only during write_hash_table so no index format backward | |
19696 | compatibility is needed. */ | |
b89be57b | 19697 | |
9291a0cd TT |
19698 | static hashval_t |
19699 | hash_strtab_entry (const void *e) | |
19700 | { | |
19701 | const struct strtab_entry *entry = e; | |
559a7a62 | 19702 | return mapped_index_string_hash (INT_MAX, entry->str); |
9291a0cd TT |
19703 | } |
19704 | ||
19705 | /* Equality function for a strtab_entry. */ | |
b89be57b | 19706 | |
9291a0cd TT |
19707 | static int |
19708 | eq_strtab_entry (const void *a, const void *b) | |
19709 | { | |
19710 | const struct strtab_entry *ea = a; | |
19711 | const struct strtab_entry *eb = b; | |
19712 | return !strcmp (ea->str, eb->str); | |
19713 | } | |
19714 | ||
19715 | /* Create a strtab_entry hash table. */ | |
b89be57b | 19716 | |
9291a0cd TT |
19717 | static htab_t |
19718 | create_strtab (void) | |
19719 | { | |
19720 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
19721 | xfree, xcalloc, xfree); | |
19722 | } | |
19723 | ||
19724 | /* Add a string to the constant pool. Return the string's offset in | |
19725 | host order. */ | |
b89be57b | 19726 | |
9291a0cd TT |
19727 | static offset_type |
19728 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
19729 | { | |
19730 | void **slot; | |
19731 | struct strtab_entry entry; | |
19732 | struct strtab_entry *result; | |
19733 | ||
19734 | entry.str = str; | |
19735 | slot = htab_find_slot (table, &entry, INSERT); | |
19736 | if (*slot) | |
19737 | result = *slot; | |
19738 | else | |
19739 | { | |
19740 | result = XNEW (struct strtab_entry); | |
19741 | result->offset = obstack_object_size (cpool); | |
19742 | result->str = str; | |
19743 | obstack_grow_str0 (cpool, str); | |
19744 | *slot = result; | |
19745 | } | |
19746 | return result->offset; | |
19747 | } | |
19748 | ||
19749 | /* An entry in the symbol table. */ | |
19750 | struct symtab_index_entry | |
19751 | { | |
19752 | /* The name of the symbol. */ | |
19753 | const char *name; | |
19754 | /* The offset of the name in the constant pool. */ | |
19755 | offset_type index_offset; | |
19756 | /* A sorted vector of the indices of all the CUs that hold an object | |
19757 | of this name. */ | |
19758 | VEC (offset_type) *cu_indices; | |
19759 | }; | |
19760 | ||
19761 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
19762 | struct mapped_symtab | |
19763 | { | |
19764 | offset_type n_elements; | |
19765 | offset_type size; | |
19766 | struct symtab_index_entry **data; | |
19767 | }; | |
19768 | ||
19769 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 19770 | |
9291a0cd TT |
19771 | static hashval_t |
19772 | hash_symtab_entry (const void *e) | |
19773 | { | |
19774 | const struct symtab_index_entry *entry = e; | |
19775 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
19776 | sizeof (offset_type) * VEC_length (offset_type, | |
19777 | entry->cu_indices), | |
19778 | 0); | |
19779 | } | |
19780 | ||
19781 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 19782 | |
9291a0cd TT |
19783 | static int |
19784 | eq_symtab_entry (const void *a, const void *b) | |
19785 | { | |
19786 | const struct symtab_index_entry *ea = a; | |
19787 | const struct symtab_index_entry *eb = b; | |
19788 | int len = VEC_length (offset_type, ea->cu_indices); | |
19789 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
19790 | return 0; | |
19791 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
19792 | VEC_address (offset_type, eb->cu_indices), | |
19793 | sizeof (offset_type) * len); | |
19794 | } | |
19795 | ||
19796 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 19797 | |
9291a0cd TT |
19798 | static void |
19799 | delete_symtab_entry (void *p) | |
19800 | { | |
19801 | struct symtab_index_entry *entry = p; | |
19802 | VEC_free (offset_type, entry->cu_indices); | |
19803 | xfree (entry); | |
19804 | } | |
19805 | ||
19806 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 19807 | |
9291a0cd | 19808 | static htab_t |
3876f04e | 19809 | create_symbol_hash_table (void) |
9291a0cd TT |
19810 | { |
19811 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
19812 | delete_symtab_entry, xcalloc, xfree); | |
19813 | } | |
19814 | ||
19815 | /* Create a new mapped symtab object. */ | |
b89be57b | 19816 | |
9291a0cd TT |
19817 | static struct mapped_symtab * |
19818 | create_mapped_symtab (void) | |
19819 | { | |
19820 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
19821 | symtab->n_elements = 0; | |
19822 | symtab->size = 1024; | |
19823 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
19824 | return symtab; | |
19825 | } | |
19826 | ||
19827 | /* Destroy a mapped_symtab. */ | |
b89be57b | 19828 | |
9291a0cd TT |
19829 | static void |
19830 | cleanup_mapped_symtab (void *p) | |
19831 | { | |
19832 | struct mapped_symtab *symtab = p; | |
19833 | /* The contents of the array are freed when the other hash table is | |
19834 | destroyed. */ | |
19835 | xfree (symtab->data); | |
19836 | xfree (symtab); | |
19837 | } | |
19838 | ||
19839 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
559a7a62 JK |
19840 | the slot. |
19841 | ||
19842 | Function is used only during write_hash_table so no index format backward | |
19843 | compatibility is needed. */ | |
b89be57b | 19844 | |
9291a0cd TT |
19845 | static struct symtab_index_entry ** |
19846 | find_slot (struct mapped_symtab *symtab, const char *name) | |
19847 | { | |
559a7a62 | 19848 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd TT |
19849 | |
19850 | index = hash & (symtab->size - 1); | |
19851 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
19852 | ||
19853 | for (;;) | |
19854 | { | |
19855 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
19856 | return &symtab->data[index]; | |
19857 | index = (index + step) & (symtab->size - 1); | |
19858 | } | |
19859 | } | |
19860 | ||
19861 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 19862 | |
9291a0cd TT |
19863 | static void |
19864 | hash_expand (struct mapped_symtab *symtab) | |
19865 | { | |
19866 | offset_type old_size = symtab->size; | |
19867 | offset_type i; | |
19868 | struct symtab_index_entry **old_entries = symtab->data; | |
19869 | ||
19870 | symtab->size *= 2; | |
19871 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
19872 | ||
19873 | for (i = 0; i < old_size; ++i) | |
19874 | { | |
19875 | if (old_entries[i]) | |
19876 | { | |
19877 | struct symtab_index_entry **slot = find_slot (symtab, | |
19878 | old_entries[i]->name); | |
19879 | *slot = old_entries[i]; | |
19880 | } | |
19881 | } | |
19882 | ||
19883 | xfree (old_entries); | |
19884 | } | |
19885 | ||
156942c7 DE |
19886 | /* Add an entry to SYMTAB. NAME is the name of the symbol. |
19887 | CU_INDEX is the index of the CU in which the symbol appears. | |
19888 | IS_STATIC is one if the symbol is static, otherwise zero (global). */ | |
b89be57b | 19889 | |
9291a0cd TT |
19890 | static void |
19891 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
156942c7 | 19892 | int is_static, gdb_index_symbol_kind kind, |
9291a0cd TT |
19893 | offset_type cu_index) |
19894 | { | |
19895 | struct symtab_index_entry **slot; | |
156942c7 | 19896 | offset_type cu_index_and_attrs; |
9291a0cd TT |
19897 | |
19898 | ++symtab->n_elements; | |
19899 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
19900 | hash_expand (symtab); | |
19901 | ||
19902 | slot = find_slot (symtab, name); | |
19903 | if (!*slot) | |
19904 | { | |
19905 | *slot = XNEW (struct symtab_index_entry); | |
19906 | (*slot)->name = name; | |
156942c7 | 19907 | /* index_offset is set later. */ |
9291a0cd TT |
19908 | (*slot)->cu_indices = NULL; |
19909 | } | |
156942c7 DE |
19910 | |
19911 | cu_index_and_attrs = 0; | |
19912 | DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs, cu_index); | |
19913 | DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs, is_static); | |
19914 | DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs, kind); | |
19915 | ||
19916 | /* We don't want to record an index value twice as we want to avoid the | |
19917 | duplication. | |
19918 | We process all global symbols and then all static symbols | |
19919 | (which would allow us to avoid the duplication by only having to check | |
19920 | the last entry pushed), but a symbol could have multiple kinds in one CU. | |
19921 | To keep things simple we don't worry about the duplication here and | |
19922 | sort and uniqufy the list after we've processed all symbols. */ | |
19923 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index_and_attrs); | |
19924 | } | |
19925 | ||
19926 | /* qsort helper routine for uniquify_cu_indices. */ | |
19927 | ||
19928 | static int | |
19929 | offset_type_compare (const void *ap, const void *bp) | |
19930 | { | |
19931 | offset_type a = *(offset_type *) ap; | |
19932 | offset_type b = *(offset_type *) bp; | |
19933 | ||
19934 | return (a > b) - (b > a); | |
19935 | } | |
19936 | ||
19937 | /* Sort and remove duplicates of all symbols' cu_indices lists. */ | |
19938 | ||
19939 | static void | |
19940 | uniquify_cu_indices (struct mapped_symtab *symtab) | |
19941 | { | |
19942 | int i; | |
19943 | ||
19944 | for (i = 0; i < symtab->size; ++i) | |
19945 | { | |
19946 | struct symtab_index_entry *entry = symtab->data[i]; | |
19947 | ||
19948 | if (entry | |
19949 | && entry->cu_indices != NULL) | |
19950 | { | |
19951 | unsigned int next_to_insert, next_to_check; | |
19952 | offset_type last_value; | |
19953 | ||
19954 | qsort (VEC_address (offset_type, entry->cu_indices), | |
19955 | VEC_length (offset_type, entry->cu_indices), | |
19956 | sizeof (offset_type), offset_type_compare); | |
19957 | ||
19958 | last_value = VEC_index (offset_type, entry->cu_indices, 0); | |
19959 | next_to_insert = 1; | |
19960 | for (next_to_check = 1; | |
19961 | next_to_check < VEC_length (offset_type, entry->cu_indices); | |
19962 | ++next_to_check) | |
19963 | { | |
19964 | if (VEC_index (offset_type, entry->cu_indices, next_to_check) | |
19965 | != last_value) | |
19966 | { | |
19967 | last_value = VEC_index (offset_type, entry->cu_indices, | |
19968 | next_to_check); | |
19969 | VEC_replace (offset_type, entry->cu_indices, next_to_insert, | |
19970 | last_value); | |
19971 | ++next_to_insert; | |
19972 | } | |
19973 | } | |
19974 | VEC_truncate (offset_type, entry->cu_indices, next_to_insert); | |
19975 | } | |
19976 | } | |
9291a0cd TT |
19977 | } |
19978 | ||
19979 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 19980 | |
9291a0cd | 19981 | static offset_type |
3876f04e | 19982 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
19983 | struct symtab_index_entry *entry) |
19984 | { | |
19985 | void **slot; | |
19986 | ||
3876f04e | 19987 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
19988 | if (!*slot) |
19989 | { | |
19990 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
19991 | offset_type val = MAYBE_SWAP (len); | |
19992 | offset_type iter; | |
19993 | int i; | |
19994 | ||
19995 | *slot = entry; | |
19996 | entry->index_offset = obstack_object_size (cpool); | |
19997 | ||
19998 | obstack_grow (cpool, &val, sizeof (val)); | |
19999 | for (i = 0; | |
20000 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
20001 | ++i) | |
20002 | { | |
20003 | val = MAYBE_SWAP (iter); | |
20004 | obstack_grow (cpool, &val, sizeof (val)); | |
20005 | } | |
20006 | } | |
20007 | else | |
20008 | { | |
20009 | struct symtab_index_entry *old_entry = *slot; | |
20010 | entry->index_offset = old_entry->index_offset; | |
20011 | entry = old_entry; | |
20012 | } | |
20013 | return entry->index_offset; | |
20014 | } | |
20015 | ||
20016 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
20017 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 20018 | |
9291a0cd TT |
20019 | static void |
20020 | write_hash_table (struct mapped_symtab *symtab, | |
20021 | struct obstack *output, struct obstack *cpool) | |
20022 | { | |
20023 | offset_type i; | |
3876f04e | 20024 | htab_t symbol_hash_table; |
9291a0cd TT |
20025 | htab_t str_table; |
20026 | ||
3876f04e | 20027 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 20028 | str_table = create_strtab (); |
3876f04e | 20029 | |
9291a0cd TT |
20030 | /* We add all the index vectors to the constant pool first, to |
20031 | ensure alignment is ok. */ | |
20032 | for (i = 0; i < symtab->size; ++i) | |
20033 | { | |
20034 | if (symtab->data[i]) | |
3876f04e | 20035 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
20036 | } |
20037 | ||
20038 | /* Now write out the hash table. */ | |
20039 | for (i = 0; i < symtab->size; ++i) | |
20040 | { | |
20041 | offset_type str_off, vec_off; | |
20042 | ||
20043 | if (symtab->data[i]) | |
20044 | { | |
20045 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
20046 | vec_off = symtab->data[i]->index_offset; | |
20047 | } | |
20048 | else | |
20049 | { | |
20050 | /* While 0 is a valid constant pool index, it is not valid | |
20051 | to have 0 for both offsets. */ | |
20052 | str_off = 0; | |
20053 | vec_off = 0; | |
20054 | } | |
20055 | ||
20056 | str_off = MAYBE_SWAP (str_off); | |
20057 | vec_off = MAYBE_SWAP (vec_off); | |
20058 | ||
20059 | obstack_grow (output, &str_off, sizeof (str_off)); | |
20060 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
20061 | } | |
20062 | ||
20063 | htab_delete (str_table); | |
3876f04e | 20064 | htab_delete (symbol_hash_table); |
9291a0cd TT |
20065 | } |
20066 | ||
0a5429f6 DE |
20067 | /* Struct to map psymtab to CU index in the index file. */ |
20068 | struct psymtab_cu_index_map | |
20069 | { | |
20070 | struct partial_symtab *psymtab; | |
20071 | unsigned int cu_index; | |
20072 | }; | |
20073 | ||
20074 | static hashval_t | |
20075 | hash_psymtab_cu_index (const void *item) | |
20076 | { | |
20077 | const struct psymtab_cu_index_map *map = item; | |
20078 | ||
20079 | return htab_hash_pointer (map->psymtab); | |
20080 | } | |
20081 | ||
20082 | static int | |
20083 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
20084 | { | |
20085 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
20086 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
20087 | ||
20088 | return lhs->psymtab == rhs->psymtab; | |
20089 | } | |
20090 | ||
20091 | /* Helper struct for building the address table. */ | |
20092 | struct addrmap_index_data | |
20093 | { | |
20094 | struct objfile *objfile; | |
20095 | struct obstack *addr_obstack; | |
20096 | htab_t cu_index_htab; | |
20097 | ||
20098 | /* Non-zero if the previous_* fields are valid. | |
20099 | We can't write an entry until we see the next entry (since it is only then | |
20100 | that we know the end of the entry). */ | |
20101 | int previous_valid; | |
20102 | /* Index of the CU in the table of all CUs in the index file. */ | |
20103 | unsigned int previous_cu_index; | |
0963b4bd | 20104 | /* Start address of the CU. */ |
0a5429f6 DE |
20105 | CORE_ADDR previous_cu_start; |
20106 | }; | |
20107 | ||
20108 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 20109 | |
9291a0cd | 20110 | static void |
0a5429f6 DE |
20111 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
20112 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 20113 | { |
0a5429f6 | 20114 | offset_type cu_index_to_write; |
9291a0cd TT |
20115 | char addr[8]; |
20116 | CORE_ADDR baseaddr; | |
20117 | ||
20118 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
20119 | ||
0a5429f6 DE |
20120 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
20121 | obstack_grow (obstack, addr, 8); | |
20122 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
20123 | obstack_grow (obstack, addr, 8); | |
20124 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
20125 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
20126 | } | |
20127 | ||
20128 | /* Worker function for traversing an addrmap to build the address table. */ | |
20129 | ||
20130 | static int | |
20131 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
20132 | { | |
20133 | struct addrmap_index_data *data = datap; | |
20134 | struct partial_symtab *pst = obj; | |
0a5429f6 DE |
20135 | |
20136 | if (data->previous_valid) | |
20137 | add_address_entry (data->objfile, data->addr_obstack, | |
20138 | data->previous_cu_start, start_addr, | |
20139 | data->previous_cu_index); | |
20140 | ||
20141 | data->previous_cu_start = start_addr; | |
20142 | if (pst != NULL) | |
20143 | { | |
20144 | struct psymtab_cu_index_map find_map, *map; | |
20145 | find_map.psymtab = pst; | |
20146 | map = htab_find (data->cu_index_htab, &find_map); | |
20147 | gdb_assert (map != NULL); | |
20148 | data->previous_cu_index = map->cu_index; | |
20149 | data->previous_valid = 1; | |
20150 | } | |
20151 | else | |
20152 | data->previous_valid = 0; | |
20153 | ||
20154 | return 0; | |
20155 | } | |
20156 | ||
20157 | /* Write OBJFILE's address map to OBSTACK. | |
20158 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
20159 | in the index file. */ | |
20160 | ||
20161 | static void | |
20162 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
20163 | htab_t cu_index_htab) | |
20164 | { | |
20165 | struct addrmap_index_data addrmap_index_data; | |
20166 | ||
20167 | /* When writing the address table, we have to cope with the fact that | |
20168 | the addrmap iterator only provides the start of a region; we have to | |
20169 | wait until the next invocation to get the start of the next region. */ | |
20170 | ||
20171 | addrmap_index_data.objfile = objfile; | |
20172 | addrmap_index_data.addr_obstack = obstack; | |
20173 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
20174 | addrmap_index_data.previous_valid = 0; | |
20175 | ||
20176 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
20177 | &addrmap_index_data); | |
20178 | ||
20179 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
20180 | is valid, but we should still handle it. | |
20181 | The end address is recorded as the start of the next region, but that | |
20182 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
20183 | anyway. */ | |
20184 | if (addrmap_index_data.previous_valid) | |
20185 | add_address_entry (objfile, obstack, | |
20186 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
20187 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
20188 | } |
20189 | ||
156942c7 DE |
20190 | /* Return the symbol kind of PSYM. */ |
20191 | ||
20192 | static gdb_index_symbol_kind | |
20193 | symbol_kind (struct partial_symbol *psym) | |
20194 | { | |
20195 | domain_enum domain = PSYMBOL_DOMAIN (psym); | |
20196 | enum address_class aclass = PSYMBOL_CLASS (psym); | |
20197 | ||
20198 | switch (domain) | |
20199 | { | |
20200 | case VAR_DOMAIN: | |
20201 | switch (aclass) | |
20202 | { | |
20203 | case LOC_BLOCK: | |
20204 | return GDB_INDEX_SYMBOL_KIND_FUNCTION; | |
20205 | case LOC_TYPEDEF: | |
20206 | return GDB_INDEX_SYMBOL_KIND_TYPE; | |
20207 | case LOC_COMPUTED: | |
20208 | case LOC_CONST_BYTES: | |
20209 | case LOC_OPTIMIZED_OUT: | |
20210 | case LOC_STATIC: | |
20211 | return GDB_INDEX_SYMBOL_KIND_VARIABLE; | |
20212 | case LOC_CONST: | |
20213 | /* Note: It's currently impossible to recognize psyms as enum values | |
20214 | short of reading the type info. For now punt. */ | |
20215 | return GDB_INDEX_SYMBOL_KIND_VARIABLE; | |
20216 | default: | |
20217 | /* There are other LOC_FOO values that one might want to classify | |
20218 | as variables, but dwarf2read.c doesn't currently use them. */ | |
20219 | return GDB_INDEX_SYMBOL_KIND_OTHER; | |
20220 | } | |
20221 | case STRUCT_DOMAIN: | |
20222 | return GDB_INDEX_SYMBOL_KIND_TYPE; | |
20223 | default: | |
20224 | return GDB_INDEX_SYMBOL_KIND_OTHER; | |
20225 | } | |
20226 | } | |
20227 | ||
9291a0cd | 20228 | /* Add a list of partial symbols to SYMTAB. */ |
b89be57b | 20229 | |
9291a0cd TT |
20230 | static void |
20231 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 20232 | htab_t psyms_seen, |
9291a0cd TT |
20233 | struct partial_symbol **psymp, |
20234 | int count, | |
987d643c TT |
20235 | offset_type cu_index, |
20236 | int is_static) | |
9291a0cd TT |
20237 | { |
20238 | for (; count-- > 0; ++psymp) | |
20239 | { | |
156942c7 DE |
20240 | struct partial_symbol *psym = *psymp; |
20241 | void **slot; | |
987d643c | 20242 | |
156942c7 | 20243 | if (SYMBOL_LANGUAGE (psym) == language_ada) |
9291a0cd | 20244 | error (_("Ada is not currently supported by the index")); |
987d643c | 20245 | |
987d643c | 20246 | /* Only add a given psymbol once. */ |
156942c7 | 20247 | slot = htab_find_slot (psyms_seen, psym, INSERT); |
987d643c TT |
20248 | if (!*slot) |
20249 | { | |
156942c7 DE |
20250 | gdb_index_symbol_kind kind = symbol_kind (psym); |
20251 | ||
20252 | *slot = psym; | |
20253 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym), | |
20254 | is_static, kind, cu_index); | |
987d643c | 20255 | } |
9291a0cd TT |
20256 | } |
20257 | } | |
20258 | ||
20259 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
20260 | exception if there is an error. */ | |
b89be57b | 20261 | |
9291a0cd TT |
20262 | static void |
20263 | write_obstack (FILE *file, struct obstack *obstack) | |
20264 | { | |
20265 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
20266 | file) | |
20267 | != obstack_object_size (obstack)) | |
20268 | error (_("couldn't data write to file")); | |
20269 | } | |
20270 | ||
20271 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 20272 | |
9291a0cd TT |
20273 | static void |
20274 | unlink_if_set (void *p) | |
20275 | { | |
20276 | char **filename = p; | |
20277 | if (*filename) | |
20278 | unlink (*filename); | |
20279 | } | |
20280 | ||
1fd400ff TT |
20281 | /* A helper struct used when iterating over debug_types. */ |
20282 | struct signatured_type_index_data | |
20283 | { | |
20284 | struct objfile *objfile; | |
20285 | struct mapped_symtab *symtab; | |
20286 | struct obstack *types_list; | |
987d643c | 20287 | htab_t psyms_seen; |
1fd400ff TT |
20288 | int cu_index; |
20289 | }; | |
20290 | ||
20291 | /* A helper function that writes a single signatured_type to an | |
20292 | obstack. */ | |
b89be57b | 20293 | |
1fd400ff TT |
20294 | static int |
20295 | write_one_signatured_type (void **slot, void *d) | |
20296 | { | |
20297 | struct signatured_type_index_data *info = d; | |
20298 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
20299 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
20300 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
20301 | gdb_byte val[8]; |
20302 | ||
20303 | write_psymbols (info->symtab, | |
987d643c | 20304 | info->psyms_seen, |
3e43a32a MS |
20305 | info->objfile->global_psymbols.list |
20306 | + psymtab->globals_offset, | |
987d643c TT |
20307 | psymtab->n_global_syms, info->cu_index, |
20308 | 0); | |
1fd400ff | 20309 | write_psymbols (info->symtab, |
987d643c | 20310 | info->psyms_seen, |
3e43a32a MS |
20311 | info->objfile->static_psymbols.list |
20312 | + psymtab->statics_offset, | |
987d643c TT |
20313 | psymtab->n_static_syms, info->cu_index, |
20314 | 1); | |
1fd400ff | 20315 | |
b64f50a1 JK |
20316 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
20317 | entry->per_cu.offset.sect_off); | |
1fd400ff | 20318 | obstack_grow (info->types_list, val, 8); |
3019eac3 DE |
20319 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
20320 | entry->type_offset_in_tu.cu_off); | |
1fd400ff TT |
20321 | obstack_grow (info->types_list, val, 8); |
20322 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
20323 | obstack_grow (info->types_list, val, 8); | |
20324 | ||
20325 | ++info->cu_index; | |
20326 | ||
20327 | return 1; | |
20328 | } | |
20329 | ||
95554aad TT |
20330 | /* Recurse into all "included" dependencies and write their symbols as |
20331 | if they appeared in this psymtab. */ | |
20332 | ||
20333 | static void | |
20334 | recursively_write_psymbols (struct objfile *objfile, | |
20335 | struct partial_symtab *psymtab, | |
20336 | struct mapped_symtab *symtab, | |
20337 | htab_t psyms_seen, | |
20338 | offset_type cu_index) | |
20339 | { | |
20340 | int i; | |
20341 | ||
20342 | for (i = 0; i < psymtab->number_of_dependencies; ++i) | |
20343 | if (psymtab->dependencies[i]->user != NULL) | |
20344 | recursively_write_psymbols (objfile, psymtab->dependencies[i], | |
20345 | symtab, psyms_seen, cu_index); | |
20346 | ||
20347 | write_psymbols (symtab, | |
20348 | psyms_seen, | |
20349 | objfile->global_psymbols.list + psymtab->globals_offset, | |
20350 | psymtab->n_global_syms, cu_index, | |
20351 | 0); | |
20352 | write_psymbols (symtab, | |
20353 | psyms_seen, | |
20354 | objfile->static_psymbols.list + psymtab->statics_offset, | |
20355 | psymtab->n_static_syms, cu_index, | |
20356 | 1); | |
20357 | } | |
20358 | ||
9291a0cd | 20359 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 20360 | |
9291a0cd TT |
20361 | static void |
20362 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
20363 | { | |
20364 | struct cleanup *cleanup; | |
20365 | char *filename, *cleanup_filename; | |
1fd400ff TT |
20366 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
20367 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
20368 | int i; |
20369 | FILE *out_file; | |
20370 | struct mapped_symtab *symtab; | |
20371 | offset_type val, size_of_contents, total_len; | |
20372 | struct stat st; | |
987d643c | 20373 | htab_t psyms_seen; |
0a5429f6 DE |
20374 | htab_t cu_index_htab; |
20375 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd | 20376 | |
b4f2f049 | 20377 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
9291a0cd | 20378 | return; |
b4f2f049 | 20379 | |
9291a0cd TT |
20380 | if (dwarf2_per_objfile->using_index) |
20381 | error (_("Cannot use an index to create the index")); | |
20382 | ||
8b70b953 TT |
20383 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
20384 | error (_("Cannot make an index when the file has multiple .debug_types sections")); | |
20385 | ||
9291a0cd | 20386 | if (stat (objfile->name, &st) < 0) |
7e17e088 | 20387 | perror_with_name (objfile->name); |
9291a0cd TT |
20388 | |
20389 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
20390 | INDEX_SUFFIX, (char *) NULL); | |
20391 | cleanup = make_cleanup (xfree, filename); | |
20392 | ||
20393 | out_file = fopen (filename, "wb"); | |
20394 | if (!out_file) | |
20395 | error (_("Can't open `%s' for writing"), filename); | |
20396 | ||
20397 | cleanup_filename = filename; | |
20398 | make_cleanup (unlink_if_set, &cleanup_filename); | |
20399 | ||
20400 | symtab = create_mapped_symtab (); | |
20401 | make_cleanup (cleanup_mapped_symtab, symtab); | |
20402 | ||
20403 | obstack_init (&addr_obstack); | |
20404 | make_cleanup_obstack_free (&addr_obstack); | |
20405 | ||
20406 | obstack_init (&cu_list); | |
20407 | make_cleanup_obstack_free (&cu_list); | |
20408 | ||
1fd400ff TT |
20409 | obstack_init (&types_cu_list); |
20410 | make_cleanup_obstack_free (&types_cu_list); | |
20411 | ||
987d643c TT |
20412 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
20413 | NULL, xcalloc, xfree); | |
96408a79 | 20414 | make_cleanup_htab_delete (psyms_seen); |
987d643c | 20415 | |
0a5429f6 DE |
20416 | /* While we're scanning CU's create a table that maps a psymtab pointer |
20417 | (which is what addrmap records) to its index (which is what is recorded | |
20418 | in the index file). This will later be needed to write the address | |
20419 | table. */ | |
20420 | cu_index_htab = htab_create_alloc (100, | |
20421 | hash_psymtab_cu_index, | |
20422 | eq_psymtab_cu_index, | |
20423 | NULL, xcalloc, xfree); | |
96408a79 | 20424 | make_cleanup_htab_delete (cu_index_htab); |
0a5429f6 DE |
20425 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
20426 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
20427 | * dwarf2_per_objfile->n_comp_units); | |
20428 | make_cleanup (xfree, psymtab_cu_index_map); | |
20429 | ||
20430 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
20431 | work here. Also, the debug_types entries do not appear in |
20432 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
20433 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
20434 | { | |
3e43a32a MS |
20435 | struct dwarf2_per_cu_data *per_cu |
20436 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 20437 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 20438 | gdb_byte val[8]; |
0a5429f6 DE |
20439 | struct psymtab_cu_index_map *map; |
20440 | void **slot; | |
9291a0cd | 20441 | |
95554aad TT |
20442 | if (psymtab->user == NULL) |
20443 | recursively_write_psymbols (objfile, psymtab, symtab, psyms_seen, i); | |
9291a0cd | 20444 | |
0a5429f6 DE |
20445 | map = &psymtab_cu_index_map[i]; |
20446 | map->psymtab = psymtab; | |
20447 | map->cu_index = i; | |
20448 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
20449 | gdb_assert (slot != NULL); | |
20450 | gdb_assert (*slot == NULL); | |
20451 | *slot = map; | |
9291a0cd | 20452 | |
b64f50a1 JK |
20453 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
20454 | per_cu->offset.sect_off); | |
9291a0cd | 20455 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 20456 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
20457 | obstack_grow (&cu_list, val, 8); |
20458 | } | |
20459 | ||
0a5429f6 DE |
20460 | /* Dump the address map. */ |
20461 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
20462 | ||
1fd400ff TT |
20463 | /* Write out the .debug_type entries, if any. */ |
20464 | if (dwarf2_per_objfile->signatured_types) | |
20465 | { | |
20466 | struct signatured_type_index_data sig_data; | |
20467 | ||
20468 | sig_data.objfile = objfile; | |
20469 | sig_data.symtab = symtab; | |
20470 | sig_data.types_list = &types_cu_list; | |
987d643c | 20471 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
20472 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
20473 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
20474 | write_one_signatured_type, &sig_data); | |
20475 | } | |
20476 | ||
156942c7 DE |
20477 | /* Now that we've processed all symbols we can shrink their cu_indices |
20478 | lists. */ | |
20479 | uniquify_cu_indices (symtab); | |
20480 | ||
9291a0cd TT |
20481 | obstack_init (&constant_pool); |
20482 | make_cleanup_obstack_free (&constant_pool); | |
20483 | obstack_init (&symtab_obstack); | |
20484 | make_cleanup_obstack_free (&symtab_obstack); | |
20485 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
20486 | ||
20487 | obstack_init (&contents); | |
20488 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 20489 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
20490 | total_len = size_of_contents; |
20491 | ||
20492 | /* The version number. */ | |
796a7ff8 | 20493 | val = MAYBE_SWAP (8); |
9291a0cd TT |
20494 | obstack_grow (&contents, &val, sizeof (val)); |
20495 | ||
20496 | /* The offset of the CU list from the start of the file. */ | |
20497 | val = MAYBE_SWAP (total_len); | |
20498 | obstack_grow (&contents, &val, sizeof (val)); | |
20499 | total_len += obstack_object_size (&cu_list); | |
20500 | ||
1fd400ff TT |
20501 | /* The offset of the types CU list from the start of the file. */ |
20502 | val = MAYBE_SWAP (total_len); | |
20503 | obstack_grow (&contents, &val, sizeof (val)); | |
20504 | total_len += obstack_object_size (&types_cu_list); | |
20505 | ||
9291a0cd TT |
20506 | /* The offset of the address table from the start of the file. */ |
20507 | val = MAYBE_SWAP (total_len); | |
20508 | obstack_grow (&contents, &val, sizeof (val)); | |
20509 | total_len += obstack_object_size (&addr_obstack); | |
20510 | ||
20511 | /* The offset of the symbol table from the start of the file. */ | |
20512 | val = MAYBE_SWAP (total_len); | |
20513 | obstack_grow (&contents, &val, sizeof (val)); | |
20514 | total_len += obstack_object_size (&symtab_obstack); | |
20515 | ||
20516 | /* The offset of the constant pool from the start of the file. */ | |
20517 | val = MAYBE_SWAP (total_len); | |
20518 | obstack_grow (&contents, &val, sizeof (val)); | |
20519 | total_len += obstack_object_size (&constant_pool); | |
20520 | ||
20521 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
20522 | ||
20523 | write_obstack (out_file, &contents); | |
20524 | write_obstack (out_file, &cu_list); | |
1fd400ff | 20525 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
20526 | write_obstack (out_file, &addr_obstack); |
20527 | write_obstack (out_file, &symtab_obstack); | |
20528 | write_obstack (out_file, &constant_pool); | |
20529 | ||
20530 | fclose (out_file); | |
20531 | ||
20532 | /* We want to keep the file, so we set cleanup_filename to NULL | |
20533 | here. See unlink_if_set. */ | |
20534 | cleanup_filename = NULL; | |
20535 | ||
20536 | do_cleanups (cleanup); | |
20537 | } | |
20538 | ||
90476074 TT |
20539 | /* Implementation of the `save gdb-index' command. |
20540 | ||
20541 | Note that the file format used by this command is documented in the | |
20542 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 20543 | |
9291a0cd TT |
20544 | static void |
20545 | save_gdb_index_command (char *arg, int from_tty) | |
20546 | { | |
20547 | struct objfile *objfile; | |
20548 | ||
20549 | if (!arg || !*arg) | |
96d19272 | 20550 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
20551 | |
20552 | ALL_OBJFILES (objfile) | |
20553 | { | |
20554 | struct stat st; | |
20555 | ||
20556 | /* If the objfile does not correspond to an actual file, skip it. */ | |
20557 | if (stat (objfile->name, &st) < 0) | |
20558 | continue; | |
20559 | ||
20560 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
20561 | if (dwarf2_per_objfile) | |
20562 | { | |
20563 | volatile struct gdb_exception except; | |
20564 | ||
20565 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
20566 | { | |
20567 | write_psymtabs_to_index (objfile, arg); | |
20568 | } | |
20569 | if (except.reason < 0) | |
20570 | exception_fprintf (gdb_stderr, except, | |
20571 | _("Error while writing index for `%s': "), | |
20572 | objfile->name); | |
20573 | } | |
20574 | } | |
dce234bc PP |
20575 | } |
20576 | ||
9291a0cd TT |
20577 | \f |
20578 | ||
9eae7c52 TT |
20579 | int dwarf2_always_disassemble; |
20580 | ||
20581 | static void | |
20582 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
20583 | struct cmd_list_element *c, const char *value) | |
20584 | { | |
3e43a32a MS |
20585 | fprintf_filtered (file, |
20586 | _("Whether to always disassemble " | |
20587 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
20588 | value); |
20589 | } | |
20590 | ||
900e11f9 JK |
20591 | static void |
20592 | show_check_physname (struct ui_file *file, int from_tty, | |
20593 | struct cmd_list_element *c, const char *value) | |
20594 | { | |
20595 | fprintf_filtered (file, | |
20596 | _("Whether to check \"physname\" is %s.\n"), | |
20597 | value); | |
20598 | } | |
20599 | ||
6502dd73 DJ |
20600 | void _initialize_dwarf2_read (void); |
20601 | ||
20602 | void | |
20603 | _initialize_dwarf2_read (void) | |
20604 | { | |
96d19272 JK |
20605 | struct cmd_list_element *c; |
20606 | ||
dce234bc | 20607 | dwarf2_objfile_data_key |
c1bd65d0 | 20608 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 20609 | |
1bedd215 AC |
20610 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
20611 | Set DWARF 2 specific variables.\n\ | |
20612 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
20613 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
20614 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
20615 | ||
1bedd215 AC |
20616 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
20617 | Show DWARF 2 specific variables\n\ | |
20618 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
20619 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
20620 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
20621 | ||
20622 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
20623 | &dwarf2_max_cache_age, _("\ |
20624 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
20625 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
20626 | A higher limit means that cached compilation units will be stored\n\ | |
20627 | in memory longer, and more total memory will be used. Zero disables\n\ | |
20628 | caching, which can slow down startup."), | |
2c5b56ce | 20629 | NULL, |
920d2a44 | 20630 | show_dwarf2_max_cache_age, |
2c5b56ce | 20631 | &set_dwarf2_cmdlist, |
ae038cb0 | 20632 | &show_dwarf2_cmdlist); |
d97bc12b | 20633 | |
9eae7c52 TT |
20634 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
20635 | &dwarf2_always_disassemble, _("\ | |
20636 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
20637 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
20638 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
20639 | syntax. When disabled, expressions will be printed in a more\n\ | |
20640 | conversational style, when possible."), | |
20641 | NULL, | |
20642 | show_dwarf2_always_disassemble, | |
20643 | &set_dwarf2_cmdlist, | |
20644 | &show_dwarf2_cmdlist); | |
20645 | ||
45cfd468 DE |
20646 | add_setshow_boolean_cmd ("dwarf2-read", no_class, &dwarf2_read_debug, _("\ |
20647 | Set debugging of the dwarf2 reader."), _("\ | |
20648 | Show debugging of the dwarf2 reader."), _("\ | |
20649 | When enabled, debugging messages are printed during dwarf2 reading\n\ | |
20650 | and symtab expansion."), | |
20651 | NULL, | |
20652 | NULL, | |
20653 | &setdebuglist, &showdebuglist); | |
20654 | ||
ccce17b0 | 20655 | add_setshow_zuinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
d97bc12b DE |
20656 | Set debugging of the dwarf2 DIE reader."), _("\ |
20657 | Show debugging of the dwarf2 DIE reader."), _("\ | |
20658 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
20659 | The value is the maximum depth to print."), | |
ccce17b0 YQ |
20660 | NULL, |
20661 | NULL, | |
20662 | &setdebuglist, &showdebuglist); | |
9291a0cd | 20663 | |
900e11f9 JK |
20664 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
20665 | Set cross-checking of \"physname\" code against demangler."), _("\ | |
20666 | Show cross-checking of \"physname\" code against demangler."), _("\ | |
20667 | When enabled, GDB's internal \"physname\" code is checked against\n\ | |
20668 | the demangler."), | |
20669 | NULL, show_check_physname, | |
20670 | &setdebuglist, &showdebuglist); | |
20671 | ||
e615022a DE |
20672 | add_setshow_boolean_cmd ("use-deprecated-index-sections", |
20673 | no_class, &use_deprecated_index_sections, _("\ | |
20674 | Set whether to use deprecated gdb_index sections."), _("\ | |
20675 | Show whether to use deprecated gdb_index sections."), _("\ | |
20676 | When enabled, deprecated .gdb_index sections are used anyway.\n\ | |
20677 | Normally they are ignored either because of a missing feature or\n\ | |
20678 | performance issue.\n\ | |
20679 | Warning: This option must be enabled before gdb reads the file."), | |
20680 | NULL, | |
20681 | NULL, | |
20682 | &setlist, &showlist); | |
20683 | ||
96d19272 | 20684 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 20685 | _("\ |
fc1a9d6e | 20686 | Save a gdb-index file.\n\ |
11570e71 | 20687 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
20688 | &save_cmdlist); |
20689 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 20690 | } |