Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
0b302171 | 3 | Copyright (C) 1994-2012 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" | |
c906108c SS |
33 | #include "symtab.h" |
34 | #include "gdbtypes.h" | |
c906108c | 35 | #include "objfiles.h" |
fa8f86ff | 36 | #include "dwarf2.h" |
c906108c SS |
37 | #include "buildsym.h" |
38 | #include "demangle.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
c906108c | 40 | #include "expression.h" |
d5166ae1 | 41 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 42 | #include "macrotab.h" |
c906108c SS |
43 | #include "language.h" |
44 | #include "complaints.h" | |
357e46e7 | 45 | #include "bcache.h" |
4c2df51b DJ |
46 | #include "dwarf2expr.h" |
47 | #include "dwarf2loc.h" | |
9219021c | 48 | #include "cp-support.h" |
72bf9492 | 49 | #include "hashtab.h" |
ae038cb0 DJ |
50 | #include "command.h" |
51 | #include "gdbcmd.h" | |
edb3359d | 52 | #include "block.h" |
ff013f42 | 53 | #include "addrmap.h" |
94af9270 KS |
54 | #include "typeprint.h" |
55 | #include "jv-lang.h" | |
ccefe4c4 | 56 | #include "psympriv.h" |
9291a0cd TT |
57 | #include "exceptions.h" |
58 | #include "gdb_stat.h" | |
96d19272 | 59 | #include "completer.h" |
34eaf542 | 60 | #include "vec.h" |
98bfdba5 | 61 | #include "c-lang.h" |
a766d390 | 62 | #include "go-lang.h" |
98bfdba5 | 63 | #include "valprint.h" |
3019eac3 | 64 | #include "gdbcore.h" /* for gnutarget */ |
156942c7 | 65 | #include "gdb/gdb-index.h" |
60d5a603 | 66 | #include <ctype.h> |
4c2df51b | 67 | |
c906108c SS |
68 | #include <fcntl.h> |
69 | #include "gdb_string.h" | |
4bdf3d34 | 70 | #include "gdb_assert.h" |
c906108c | 71 | #include <sys/types.h> |
233a11ab CS |
72 | #ifdef HAVE_ZLIB_H |
73 | #include <zlib.h> | |
74 | #endif | |
dce234bc PP |
75 | #ifdef HAVE_MMAP |
76 | #include <sys/mman.h> | |
85d9bd0e TT |
77 | #ifndef MAP_FAILED |
78 | #define MAP_FAILED ((void *) -1) | |
79 | #endif | |
dce234bc | 80 | #endif |
d8151005 | 81 | |
34eaf542 TT |
82 | typedef struct symbol *symbolp; |
83 | DEF_VEC_P (symbolp); | |
84 | ||
45cfd468 DE |
85 | /* When non-zero, print basic high level tracing messages. |
86 | This is in contrast to the low level DIE reading of dwarf2_die_debug. */ | |
87 | static int dwarf2_read_debug = 0; | |
88 | ||
d97bc12b DE |
89 | /* When non-zero, dump DIEs after they are read in. */ |
90 | static int dwarf2_die_debug = 0; | |
91 | ||
900e11f9 JK |
92 | /* When non-zero, cross-check physname against demangler. */ |
93 | static int check_physname = 0; | |
94 | ||
481860b3 GB |
95 | /* When non-zero, do not reject deprecated .gdb_index sections. */ |
96 | int use_deprecated_index_sections = 0; | |
97 | ||
dce234bc PP |
98 | static int pagesize; |
99 | ||
df8a16a1 DJ |
100 | /* When set, the file that we're processing is known to have debugging |
101 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
102 | but later versions do. */ | |
103 | ||
104 | static int processing_has_namespace_info; | |
105 | ||
6502dd73 DJ |
106 | static const struct objfile_data *dwarf2_objfile_data_key; |
107 | ||
dce234bc PP |
108 | struct dwarf2_section_info |
109 | { | |
110 | asection *asection; | |
111 | gdb_byte *buffer; | |
112 | bfd_size_type size; | |
b315ab21 TG |
113 | /* Not NULL if the section was actually mmapped. */ |
114 | void *map_addr; | |
115 | /* Page aligned size of mmapped area. */ | |
116 | bfd_size_type map_len; | |
be391dca TT |
117 | /* True if we have tried to read this section. */ |
118 | int readin; | |
dce234bc PP |
119 | }; |
120 | ||
8b70b953 TT |
121 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
122 | DEF_VEC_O (dwarf2_section_info_def); | |
123 | ||
9291a0cd TT |
124 | /* All offsets in the index are of this type. It must be |
125 | architecture-independent. */ | |
126 | typedef uint32_t offset_type; | |
127 | ||
128 | DEF_VEC_I (offset_type); | |
129 | ||
156942c7 DE |
130 | /* Ensure only legit values are used. */ |
131 | #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \ | |
132 | do { \ | |
133 | gdb_assert ((unsigned int) (value) <= 1); \ | |
134 | GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \ | |
135 | } while (0) | |
136 | ||
137 | /* Ensure only legit values are used. */ | |
138 | #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \ | |
139 | do { \ | |
140 | gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \ | |
141 | && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \ | |
142 | GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \ | |
143 | } while (0) | |
144 | ||
145 | /* Ensure we don't use more than the alloted nuber of bits for the CU. */ | |
146 | #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \ | |
147 | do { \ | |
148 | gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \ | |
149 | GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \ | |
150 | } while (0) | |
151 | ||
9291a0cd TT |
152 | /* A description of the mapped index. The file format is described in |
153 | a comment by the code that writes the index. */ | |
154 | struct mapped_index | |
155 | { | |
559a7a62 JK |
156 | /* Index data format version. */ |
157 | int version; | |
158 | ||
9291a0cd TT |
159 | /* The total length of the buffer. */ |
160 | off_t total_size; | |
b11b1f88 | 161 | |
9291a0cd TT |
162 | /* A pointer to the address table data. */ |
163 | const gdb_byte *address_table; | |
b11b1f88 | 164 | |
9291a0cd TT |
165 | /* Size of the address table data in bytes. */ |
166 | offset_type address_table_size; | |
b11b1f88 | 167 | |
3876f04e DE |
168 | /* The symbol table, implemented as a hash table. */ |
169 | const offset_type *symbol_table; | |
b11b1f88 | 170 | |
9291a0cd | 171 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 172 | offset_type symbol_table_slots; |
b11b1f88 | 173 | |
9291a0cd TT |
174 | /* A pointer to the constant pool. */ |
175 | const char *constant_pool; | |
176 | }; | |
177 | ||
95554aad TT |
178 | typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr; |
179 | DEF_VEC_P (dwarf2_per_cu_ptr); | |
180 | ||
9cdd5dbd DE |
181 | /* Collection of data recorded per objfile. |
182 | This hangs off of dwarf2_objfile_data_key. */ | |
183 | ||
6502dd73 DJ |
184 | struct dwarf2_per_objfile |
185 | { | |
dce234bc PP |
186 | struct dwarf2_section_info info; |
187 | struct dwarf2_section_info abbrev; | |
188 | struct dwarf2_section_info line; | |
dce234bc PP |
189 | struct dwarf2_section_info loc; |
190 | struct dwarf2_section_info macinfo; | |
cf2c3c16 | 191 | struct dwarf2_section_info macro; |
dce234bc PP |
192 | struct dwarf2_section_info str; |
193 | struct dwarf2_section_info ranges; | |
3019eac3 | 194 | struct dwarf2_section_info addr; |
dce234bc PP |
195 | struct dwarf2_section_info frame; |
196 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 197 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 198 | |
8b70b953 TT |
199 | VEC (dwarf2_section_info_def) *types; |
200 | ||
be391dca TT |
201 | /* Back link. */ |
202 | struct objfile *objfile; | |
203 | ||
d467dd73 | 204 | /* Table of all the compilation units. This is used to locate |
10b3939b | 205 | the target compilation unit of a particular reference. */ |
ae038cb0 DJ |
206 | struct dwarf2_per_cu_data **all_comp_units; |
207 | ||
208 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
209 | int n_comp_units; | |
210 | ||
1fd400ff | 211 | /* The number of .debug_types-related CUs. */ |
d467dd73 | 212 | int n_type_units; |
1fd400ff | 213 | |
d467dd73 DE |
214 | /* The .debug_types-related CUs (TUs). */ |
215 | struct dwarf2_per_cu_data **all_type_units; | |
1fd400ff | 216 | |
ae038cb0 DJ |
217 | /* A chain of compilation units that are currently read in, so that |
218 | they can be freed later. */ | |
219 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 220 | |
348e048f DE |
221 | /* A table mapping .debug_types signatures to its signatured_type entry. |
222 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
223 | htab_t signatured_types; | |
224 | ||
3019eac3 DE |
225 | /* A table mapping DW_AT_dwo_name values to struct dwo_file objects. |
226 | This is NULL if the table hasn't been allocated yet. */ | |
227 | htab_t dwo_files; | |
228 | ||
72dca2f5 FR |
229 | /* A flag indicating wether this objfile has a section loaded at a |
230 | VMA of 0. */ | |
231 | int has_section_at_zero; | |
9291a0cd | 232 | |
ae2de4f8 DE |
233 | /* True if we are using the mapped index, |
234 | or we are faking it for OBJF_READNOW's sake. */ | |
9291a0cd TT |
235 | unsigned char using_index; |
236 | ||
ae2de4f8 | 237 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
9291a0cd | 238 | struct mapped_index *index_table; |
98bfdba5 | 239 | |
7b9f3c50 DE |
240 | /* When using index_table, this keeps track of all quick_file_names entries. |
241 | TUs can share line table entries with CUs or other TUs, and there can be | |
242 | a lot more TUs than unique line tables, so we maintain a separate table | |
243 | of all line table entries to support the sharing. */ | |
244 | htab_t quick_file_names_table; | |
245 | ||
98bfdba5 PA |
246 | /* Set during partial symbol reading, to prevent queueing of full |
247 | symbols. */ | |
248 | int reading_partial_symbols; | |
673bfd45 | 249 | |
dee91e82 | 250 | /* Table mapping type DIEs to their struct type *. |
673bfd45 | 251 | This is NULL if not allocated yet. |
dee91e82 DE |
252 | The mapping is done via (CU/TU signature + DIE offset) -> type. */ |
253 | htab_t die_type_hash; | |
95554aad TT |
254 | |
255 | /* The CUs we recently read. */ | |
256 | VEC (dwarf2_per_cu_ptr) *just_read_cus; | |
6502dd73 DJ |
257 | }; |
258 | ||
259 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 260 | |
251d32d9 | 261 | /* Default names of the debugging sections. */ |
c906108c | 262 | |
233a11ab CS |
263 | /* Note that if the debugging section has been compressed, it might |
264 | have a name like .zdebug_info. */ | |
265 | ||
9cdd5dbd DE |
266 | static const struct dwarf2_debug_sections dwarf2_elf_names = |
267 | { | |
251d32d9 TG |
268 | { ".debug_info", ".zdebug_info" }, |
269 | { ".debug_abbrev", ".zdebug_abbrev" }, | |
270 | { ".debug_line", ".zdebug_line" }, | |
271 | { ".debug_loc", ".zdebug_loc" }, | |
272 | { ".debug_macinfo", ".zdebug_macinfo" }, | |
cf2c3c16 | 273 | { ".debug_macro", ".zdebug_macro" }, |
251d32d9 TG |
274 | { ".debug_str", ".zdebug_str" }, |
275 | { ".debug_ranges", ".zdebug_ranges" }, | |
276 | { ".debug_types", ".zdebug_types" }, | |
3019eac3 | 277 | { ".debug_addr", ".zdebug_addr" }, |
251d32d9 TG |
278 | { ".debug_frame", ".zdebug_frame" }, |
279 | { ".eh_frame", NULL }, | |
24d3216f TT |
280 | { ".gdb_index", ".zgdb_index" }, |
281 | 23 | |
251d32d9 | 282 | }; |
c906108c | 283 | |
3019eac3 DE |
284 | /* List of DWO sections. */ |
285 | ||
286 | static const struct dwo_section_names | |
287 | { | |
288 | struct dwarf2_section_names abbrev_dwo; | |
289 | struct dwarf2_section_names info_dwo; | |
290 | struct dwarf2_section_names line_dwo; | |
291 | struct dwarf2_section_names loc_dwo; | |
09262596 DE |
292 | struct dwarf2_section_names macinfo_dwo; |
293 | struct dwarf2_section_names macro_dwo; | |
3019eac3 DE |
294 | struct dwarf2_section_names str_dwo; |
295 | struct dwarf2_section_names str_offsets_dwo; | |
296 | struct dwarf2_section_names types_dwo; | |
297 | } | |
298 | dwo_section_names = | |
299 | { | |
300 | { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" }, | |
301 | { ".debug_info.dwo", ".zdebug_info.dwo" }, | |
302 | { ".debug_line.dwo", ".zdebug_line.dwo" }, | |
303 | { ".debug_loc.dwo", ".zdebug_loc.dwo" }, | |
09262596 DE |
304 | { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" }, |
305 | { ".debug_macro.dwo", ".zdebug_macro.dwo" }, | |
3019eac3 DE |
306 | { ".debug_str.dwo", ".zdebug_str.dwo" }, |
307 | { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" }, | |
308 | { ".debug_types.dwo", ".zdebug_types.dwo" }, | |
309 | }; | |
310 | ||
c906108c SS |
311 | /* local data types */ |
312 | ||
0963b4bd | 313 | /* We hold several abbreviation tables in memory at the same time. */ |
57349743 JB |
314 | #ifndef ABBREV_HASH_SIZE |
315 | #define ABBREV_HASH_SIZE 121 | |
316 | #endif | |
317 | ||
107d2387 AC |
318 | /* The data in a compilation unit header, after target2host |
319 | translation, looks like this. */ | |
c906108c | 320 | struct comp_unit_head |
a738430d | 321 | { |
c764a876 | 322 | unsigned int length; |
a738430d | 323 | short version; |
a738430d MK |
324 | unsigned char addr_size; |
325 | unsigned char signed_addr_p; | |
b64f50a1 | 326 | sect_offset abbrev_offset; |
57349743 | 327 | |
a738430d MK |
328 | /* Size of file offsets; either 4 or 8. */ |
329 | unsigned int offset_size; | |
57349743 | 330 | |
a738430d MK |
331 | /* Size of the length field; either 4 or 12. */ |
332 | unsigned int initial_length_size; | |
57349743 | 333 | |
a738430d MK |
334 | /* Offset to the first byte of this compilation unit header in the |
335 | .debug_info section, for resolving relative reference dies. */ | |
b64f50a1 | 336 | sect_offset offset; |
57349743 | 337 | |
d00adf39 DE |
338 | /* Offset to first die in this cu from the start of the cu. |
339 | This will be the first byte following the compilation unit header. */ | |
b64f50a1 | 340 | cu_offset first_die_offset; |
a738430d | 341 | }; |
c906108c | 342 | |
3da10d80 KS |
343 | /* Type used for delaying computation of method physnames. |
344 | See comments for compute_delayed_physnames. */ | |
345 | struct delayed_method_info | |
346 | { | |
347 | /* The type to which the method is attached, i.e., its parent class. */ | |
348 | struct type *type; | |
349 | ||
350 | /* The index of the method in the type's function fieldlists. */ | |
351 | int fnfield_index; | |
352 | ||
353 | /* The index of the method in the fieldlist. */ | |
354 | int index; | |
355 | ||
356 | /* The name of the DIE. */ | |
357 | const char *name; | |
358 | ||
359 | /* The DIE associated with this method. */ | |
360 | struct die_info *die; | |
361 | }; | |
362 | ||
363 | typedef struct delayed_method_info delayed_method_info; | |
364 | DEF_VEC_O (delayed_method_info); | |
365 | ||
e7c27a73 DJ |
366 | /* Internal state when decoding a particular compilation unit. */ |
367 | struct dwarf2_cu | |
368 | { | |
369 | /* The objfile containing this compilation unit. */ | |
370 | struct objfile *objfile; | |
371 | ||
d00adf39 | 372 | /* The header of the compilation unit. */ |
e7c27a73 | 373 | struct comp_unit_head header; |
e142c38c | 374 | |
d00adf39 DE |
375 | /* Base address of this compilation unit. */ |
376 | CORE_ADDR base_address; | |
377 | ||
378 | /* Non-zero if base_address has been set. */ | |
379 | int base_known; | |
380 | ||
e142c38c DJ |
381 | /* The language we are debugging. */ |
382 | enum language language; | |
383 | const struct language_defn *language_defn; | |
384 | ||
b0f35d58 DL |
385 | const char *producer; |
386 | ||
e142c38c DJ |
387 | /* The generic symbol table building routines have separate lists for |
388 | file scope symbols and all all other scopes (local scopes). So | |
389 | we need to select the right one to pass to add_symbol_to_list(). | |
390 | We do it by keeping a pointer to the correct list in list_in_scope. | |
391 | ||
392 | FIXME: The original dwarf code just treated the file scope as the | |
393 | first local scope, and all other local scopes as nested local | |
394 | scopes, and worked fine. Check to see if we really need to | |
395 | distinguish these in buildsym.c. */ | |
396 | struct pending **list_in_scope; | |
397 | ||
f3dd6933 DJ |
398 | /* DWARF abbreviation table associated with this compilation unit. */ |
399 | struct abbrev_info **dwarf2_abbrevs; | |
400 | ||
401 | /* Storage for the abbrev table. */ | |
402 | struct obstack abbrev_obstack; | |
72bf9492 | 403 | |
b64f50a1 JK |
404 | /* Hash table holding all the loaded partial DIEs |
405 | with partial_die->offset.SECT_OFF as hash. */ | |
72bf9492 DJ |
406 | htab_t partial_dies; |
407 | ||
408 | /* Storage for things with the same lifetime as this read-in compilation | |
409 | unit, including partial DIEs. */ | |
410 | struct obstack comp_unit_obstack; | |
411 | ||
ae038cb0 DJ |
412 | /* When multiple dwarf2_cu structures are living in memory, this field |
413 | chains them all together, so that they can be released efficiently. | |
414 | We will probably also want a generation counter so that most-recently-used | |
415 | compilation units are cached... */ | |
416 | struct dwarf2_per_cu_data *read_in_chain; | |
417 | ||
418 | /* Backchain to our per_cu entry if the tree has been built. */ | |
419 | struct dwarf2_per_cu_data *per_cu; | |
420 | ||
421 | /* How many compilation units ago was this CU last referenced? */ | |
422 | int last_used; | |
423 | ||
b64f50a1 JK |
424 | /* A hash table of DIE cu_offset for following references with |
425 | die_info->offset.sect_off as hash. */ | |
51545339 | 426 | htab_t die_hash; |
10b3939b DJ |
427 | |
428 | /* Full DIEs if read in. */ | |
429 | struct die_info *dies; | |
430 | ||
431 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
432 | units referenced by this one. Only set during full symbol processing; | |
433 | partial symbol tables do not have dependencies. */ | |
434 | htab_t dependencies; | |
435 | ||
cb1df416 DJ |
436 | /* Header data from the line table, during full symbol processing. */ |
437 | struct line_header *line_header; | |
438 | ||
3da10d80 KS |
439 | /* A list of methods which need to have physnames computed |
440 | after all type information has been read. */ | |
441 | VEC (delayed_method_info) *method_list; | |
442 | ||
96408a79 SA |
443 | /* To be copied to symtab->call_site_htab. */ |
444 | htab_t call_site_htab; | |
445 | ||
034e5797 DE |
446 | /* Non-NULL if this CU came from a DWO file. |
447 | There is an invariant here that is important to remember: | |
448 | Except for attributes copied from the top level DIE in the "main" | |
449 | (or "stub") file in preparation for reading the DWO file | |
450 | (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU. | |
451 | Either there isn't a DWO file (in which case this is NULL and the point | |
452 | is moot), or there is and either we're not going to read it (in which | |
453 | case this is NULL) or there is and we are reading it (in which case this | |
454 | is non-NULL). */ | |
3019eac3 DE |
455 | struct dwo_unit *dwo_unit; |
456 | ||
457 | /* The DW_AT_addr_base attribute if present, zero otherwise | |
458 | (zero is a valid value though). | |
459 | Note this value comes from the stub CU/TU's DIE. */ | |
460 | ULONGEST addr_base; | |
461 | ||
2e3cf129 DE |
462 | /* The DW_AT_ranges_base attribute if present, zero otherwise |
463 | (zero is a valid value though). | |
464 | Note this value comes from the stub CU/TU's DIE. | |
465 | Also note that the value is zero in the non-DWO case so this value can | |
466 | be used without needing to know whether DWO files are in use or not. */ | |
467 | ULONGEST ranges_base; | |
468 | ||
ae038cb0 DJ |
469 | /* Mark used when releasing cached dies. */ |
470 | unsigned int mark : 1; | |
471 | ||
8be455d7 JK |
472 | /* This CU references .debug_loc. See the symtab->locations_valid field. |
473 | This test is imperfect as there may exist optimized debug code not using | |
474 | any location list and still facing inlining issues if handled as | |
475 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
8be455d7 | 476 | unsigned int has_loclist : 1; |
ba919b58 | 477 | |
685b1105 JK |
478 | /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc. |
479 | CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC | |
480 | are valid. This information is cached because profiling CU expansion | |
481 | showed excessive time spent in producer_is_gxx_lt_4_6. */ | |
ba919b58 TT |
482 | unsigned int checked_producer : 1; |
483 | unsigned int producer_is_gxx_lt_4_6 : 1; | |
685b1105 | 484 | unsigned int producer_is_icc : 1; |
e7c27a73 DJ |
485 | }; |
486 | ||
10b3939b DJ |
487 | /* Persistent data held for a compilation unit, even when not |
488 | processing it. We put a pointer to this structure in the | |
28dee7f5 | 489 | read_symtab_private field of the psymtab. */ |
10b3939b | 490 | |
ae038cb0 DJ |
491 | struct dwarf2_per_cu_data |
492 | { | |
348e048f | 493 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 494 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
495 | - if it doesn't, GDB will fall over anyway. |
496 | NOTE: Unlike comp_unit_head.length, this length includes | |
3019eac3 DE |
497 | initial_length_size. |
498 | If the DIE refers to a DWO file, this is always of the original die, | |
499 | not the DWO file. */ | |
b64f50a1 | 500 | sect_offset offset; |
348e048f | 501 | unsigned int length : 29; |
ae038cb0 DJ |
502 | |
503 | /* Flag indicating this compilation unit will be read in before | |
504 | any of the current compilation units are processed. */ | |
c764a876 | 505 | unsigned int queued : 1; |
ae038cb0 | 506 | |
0d99eb77 DE |
507 | /* This flag will be set when reading partial DIEs if we need to load |
508 | absolutely all DIEs for this compilation unit, instead of just the ones | |
509 | we think are interesting. It gets set if we look for a DIE in the | |
5afb4e99 DJ |
510 | hash table and don't find it. */ |
511 | unsigned int load_all_dies : 1; | |
512 | ||
3019eac3 DE |
513 | /* Non-zero if this CU is from .debug_types. */ |
514 | unsigned int is_debug_types : 1; | |
515 | ||
516 | /* The section this CU/TU lives in. | |
517 | If the DIE refers to a DWO file, this is always the original die, | |
518 | not the DWO file. */ | |
519 | struct dwarf2_section_info *info_or_types_section; | |
348e048f | 520 | |
17ea53c3 JK |
521 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
522 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 523 | struct dwarf2_cu *cu; |
1c379e20 | 524 | |
9cdd5dbd DE |
525 | /* The corresponding objfile. |
526 | Normally we can get the objfile from dwarf2_per_objfile. | |
527 | However we can enter this file with just a "per_cu" handle. */ | |
9291a0cd TT |
528 | struct objfile *objfile; |
529 | ||
530 | /* When using partial symbol tables, the 'psymtab' field is active. | |
531 | Otherwise the 'quick' field is active. */ | |
532 | union | |
533 | { | |
534 | /* The partial symbol table associated with this compilation unit, | |
95554aad | 535 | or NULL for unread partial units. */ |
9291a0cd TT |
536 | struct partial_symtab *psymtab; |
537 | ||
538 | /* Data needed by the "quick" functions. */ | |
539 | struct dwarf2_per_cu_quick_data *quick; | |
540 | } v; | |
95554aad TT |
541 | |
542 | /* The CUs we import using DW_TAG_imported_unit. This is filled in | |
543 | while reading psymtabs, used to compute the psymtab dependencies, | |
544 | and then cleared. Then it is filled in again while reading full | |
545 | symbols, and only deleted when the objfile is destroyed. */ | |
546 | VEC (dwarf2_per_cu_ptr) *imported_symtabs; | |
ae038cb0 DJ |
547 | }; |
548 | ||
348e048f DE |
549 | /* Entry in the signatured_types hash table. */ |
550 | ||
551 | struct signatured_type | |
552 | { | |
3019eac3 | 553 | /* The type's signature. */ |
348e048f DE |
554 | ULONGEST signature; |
555 | ||
3019eac3 DE |
556 | /* Offset in the TU of the type's DIE, as read from the TU header. |
557 | If the definition lives in a DWO file, this value is unusable. */ | |
558 | cu_offset type_offset_in_tu; | |
559 | ||
560 | /* Offset in the section of the type's DIE. | |
561 | If the definition lives in a DWO file, this is the offset in the | |
562 | .debug_types.dwo section. | |
563 | The value is zero until the actual value is known. | |
564 | Zero is otherwise not a valid section offset. */ | |
565 | sect_offset type_offset_in_section; | |
348e048f DE |
566 | |
567 | /* The CU(/TU) of this type. */ | |
568 | struct dwarf2_per_cu_data per_cu; | |
569 | }; | |
570 | ||
3019eac3 DE |
571 | /* These sections are what may appear in a "dwo" file. */ |
572 | ||
573 | struct dwo_sections | |
574 | { | |
575 | struct dwarf2_section_info abbrev; | |
576 | struct dwarf2_section_info info; | |
577 | struct dwarf2_section_info line; | |
578 | struct dwarf2_section_info loc; | |
09262596 DE |
579 | struct dwarf2_section_info macinfo; |
580 | struct dwarf2_section_info macro; | |
3019eac3 DE |
581 | struct dwarf2_section_info str; |
582 | struct dwarf2_section_info str_offsets; | |
583 | VEC (dwarf2_section_info_def) *types; | |
584 | }; | |
585 | ||
586 | /* Common bits of DWO CUs/TUs. */ | |
587 | ||
588 | struct dwo_unit | |
589 | { | |
590 | /* Backlink to the containing struct dwo_file. */ | |
591 | struct dwo_file *dwo_file; | |
592 | ||
593 | /* The "id" that distinguishes this CU/TU. | |
594 | .debug_info calls this "dwo_id", .debug_types calls this "signature". | |
595 | Since signatures came first, we stick with it for consistency. */ | |
596 | ULONGEST signature; | |
597 | ||
598 | /* The section this CU/TU lives in, in the DWO file. */ | |
599 | struct dwarf2_section_info *info_or_types_section; | |
600 | ||
601 | /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */ | |
602 | sect_offset offset; | |
603 | unsigned int length; | |
604 | ||
605 | /* For types, offset in the type's DIE of the type defined by this TU. */ | |
606 | cu_offset type_offset_in_tu; | |
607 | }; | |
608 | ||
609 | /* Data for one DWO file. */ | |
610 | ||
611 | struct dwo_file | |
612 | { | |
613 | /* The DW_AT_GNU_dwo_name attribute. | |
614 | We don't manage space for this, it's an attribute. */ | |
615 | const char *dwo_name; | |
616 | ||
617 | /* The bfd, when the file is open. Otherwise this is NULL. */ | |
618 | bfd *dwo_bfd; | |
619 | ||
620 | /* Section info for this file. */ | |
621 | struct dwo_sections sections; | |
622 | ||
623 | /* Table of CUs in the file. | |
624 | Each element is a struct dwo_unit. */ | |
625 | htab_t cus; | |
626 | ||
627 | /* Table of TUs in the file. | |
628 | Each element is a struct dwo_unit. */ | |
629 | htab_t tus; | |
630 | }; | |
631 | ||
0963b4bd MS |
632 | /* Struct used to pass misc. parameters to read_die_and_children, et |
633 | al. which are used for both .debug_info and .debug_types dies. | |
634 | All parameters here are unchanging for the life of the call. This | |
dee91e82 | 635 | struct exists to abstract away the constant parameters of die reading. */ |
93311388 DE |
636 | |
637 | struct die_reader_specs | |
638 | { | |
dee91e82 | 639 | /* die_section->asection->owner. */ |
93311388 DE |
640 | bfd* abfd; |
641 | ||
642 | /* The CU of the DIE we are parsing. */ | |
643 | struct dwarf2_cu *cu; | |
644 | ||
3019eac3 DE |
645 | /* Non-NULL if reading a DWO file. */ |
646 | struct dwo_file *dwo_file; | |
647 | ||
dee91e82 | 648 | /* The section the die comes from. |
3019eac3 | 649 | This is either .debug_info or .debug_types, or the .dwo variants. */ |
dee91e82 DE |
650 | struct dwarf2_section_info *die_section; |
651 | ||
652 | /* die_section->buffer. */ | |
653 | gdb_byte *buffer; | |
f664829e DE |
654 | |
655 | /* The end of the buffer. */ | |
656 | const gdb_byte *buffer_end; | |
93311388 DE |
657 | }; |
658 | ||
fd820528 | 659 | /* Type of function passed to init_cutu_and_read_dies, et.al. */ |
dee91e82 DE |
660 | typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader, |
661 | gdb_byte *info_ptr, | |
662 | struct die_info *comp_unit_die, | |
663 | int has_children, | |
664 | void *data); | |
665 | ||
debd256d JB |
666 | /* The line number information for a compilation unit (found in the |
667 | .debug_line section) begins with a "statement program header", | |
668 | which contains the following information. */ | |
669 | struct line_header | |
670 | { | |
671 | unsigned int total_length; | |
672 | unsigned short version; | |
673 | unsigned int header_length; | |
674 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 675 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
676 | unsigned char default_is_stmt; |
677 | int line_base; | |
678 | unsigned char line_range; | |
679 | unsigned char opcode_base; | |
680 | ||
681 | /* standard_opcode_lengths[i] is the number of operands for the | |
682 | standard opcode whose value is i. This means that | |
683 | standard_opcode_lengths[0] is unused, and the last meaningful | |
684 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
685 | unsigned char *standard_opcode_lengths; | |
686 | ||
687 | /* The include_directories table. NOTE! These strings are not | |
688 | allocated with xmalloc; instead, they are pointers into | |
689 | debug_line_buffer. If you try to free them, `free' will get | |
690 | indigestion. */ | |
691 | unsigned int num_include_dirs, include_dirs_size; | |
692 | char **include_dirs; | |
693 | ||
694 | /* The file_names table. NOTE! These strings are not allocated | |
695 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
696 | Don't try to free them directly. */ | |
697 | unsigned int num_file_names, file_names_size; | |
698 | struct file_entry | |
c906108c | 699 | { |
debd256d JB |
700 | char *name; |
701 | unsigned int dir_index; | |
702 | unsigned int mod_time; | |
703 | unsigned int length; | |
aaa75496 | 704 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 705 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
706 | } *file_names; |
707 | ||
708 | /* The start and end of the statement program following this | |
6502dd73 | 709 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 710 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 711 | }; |
c906108c SS |
712 | |
713 | /* When we construct a partial symbol table entry we only | |
0963b4bd | 714 | need this much information. */ |
c906108c SS |
715 | struct partial_die_info |
716 | { | |
72bf9492 | 717 | /* Offset of this DIE. */ |
b64f50a1 | 718 | sect_offset offset; |
72bf9492 DJ |
719 | |
720 | /* DWARF-2 tag for this DIE. */ | |
721 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
722 | ||
72bf9492 DJ |
723 | /* Assorted flags describing the data found in this DIE. */ |
724 | unsigned int has_children : 1; | |
725 | unsigned int is_external : 1; | |
726 | unsigned int is_declaration : 1; | |
727 | unsigned int has_type : 1; | |
728 | unsigned int has_specification : 1; | |
729 | unsigned int has_pc_info : 1; | |
481860b3 | 730 | unsigned int may_be_inlined : 1; |
72bf9492 DJ |
731 | |
732 | /* Flag set if the SCOPE field of this structure has been | |
733 | computed. */ | |
734 | unsigned int scope_set : 1; | |
735 | ||
fa4028e9 JB |
736 | /* Flag set if the DIE has a byte_size attribute. */ |
737 | unsigned int has_byte_size : 1; | |
738 | ||
98bfdba5 PA |
739 | /* Flag set if any of the DIE's children are template arguments. */ |
740 | unsigned int has_template_arguments : 1; | |
741 | ||
abc72ce4 DE |
742 | /* Flag set if fixup_partial_die has been called on this die. */ |
743 | unsigned int fixup_called : 1; | |
744 | ||
72bf9492 | 745 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 746 | sometimes a default name for unnamed DIEs. */ |
c906108c | 747 | char *name; |
72bf9492 | 748 | |
abc72ce4 DE |
749 | /* The linkage name, if present. */ |
750 | const char *linkage_name; | |
751 | ||
72bf9492 DJ |
752 | /* The scope to prepend to our children. This is generally |
753 | allocated on the comp_unit_obstack, so will disappear | |
754 | when this compilation unit leaves the cache. */ | |
755 | char *scope; | |
756 | ||
95554aad TT |
757 | /* Some data associated with the partial DIE. The tag determines |
758 | which field is live. */ | |
759 | union | |
760 | { | |
761 | /* The location description associated with this DIE, if any. */ | |
762 | struct dwarf_block *locdesc; | |
763 | /* The offset of an import, for DW_TAG_imported_unit. */ | |
764 | sect_offset offset; | |
765 | } d; | |
72bf9492 DJ |
766 | |
767 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
768 | CORE_ADDR lowpc; |
769 | CORE_ADDR highpc; | |
72bf9492 | 770 | |
93311388 | 771 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 772 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
773 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
774 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
fe1b8b76 | 775 | gdb_byte *sibling; |
72bf9492 DJ |
776 | |
777 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
778 | DW_AT_specification (or DW_AT_abstract_origin or | |
779 | DW_AT_extension). */ | |
b64f50a1 | 780 | sect_offset spec_offset; |
72bf9492 DJ |
781 | |
782 | /* Pointers to this DIE's parent, first child, and next sibling, | |
783 | if any. */ | |
784 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
785 | }; |
786 | ||
0963b4bd | 787 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
788 | struct abbrev_info |
789 | { | |
790 | unsigned int number; /* number identifying abbrev */ | |
791 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
792 | unsigned short has_children; /* boolean */ |
793 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
794 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
795 | struct abbrev_info *next; /* next in chain */ | |
796 | }; | |
797 | ||
798 | struct attr_abbrev | |
799 | { | |
9d25dd43 DE |
800 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
801 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
802 | }; |
803 | ||
0963b4bd | 804 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
805 | struct attribute |
806 | { | |
9d25dd43 | 807 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
808 | ENUM_BITFIELD(dwarf_form) form : 15; |
809 | ||
810 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
811 | field should be in u.str (existing only for DW_STRING) but it is kept | |
812 | here for better struct attribute alignment. */ | |
813 | unsigned int string_is_canonical : 1; | |
814 | ||
b60c80d6 DJ |
815 | union |
816 | { | |
817 | char *str; | |
818 | struct dwarf_block *blk; | |
43bbcdc2 PH |
819 | ULONGEST unsnd; |
820 | LONGEST snd; | |
b60c80d6 | 821 | CORE_ADDR addr; |
348e048f | 822 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
823 | } |
824 | u; | |
825 | }; | |
826 | ||
0963b4bd | 827 | /* This data structure holds a complete die structure. */ |
c906108c SS |
828 | struct die_info |
829 | { | |
76815b17 DE |
830 | /* DWARF-2 tag for this DIE. */ |
831 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
832 | ||
833 | /* Number of attributes */ | |
98bfdba5 PA |
834 | unsigned char num_attrs; |
835 | ||
836 | /* True if we're presently building the full type name for the | |
837 | type derived from this DIE. */ | |
838 | unsigned char building_fullname : 1; | |
76815b17 DE |
839 | |
840 | /* Abbrev number */ | |
841 | unsigned int abbrev; | |
842 | ||
93311388 | 843 | /* Offset in .debug_info or .debug_types section. */ |
b64f50a1 | 844 | sect_offset offset; |
78ba4af6 JB |
845 | |
846 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
847 | points to this die's parent; CHILD points to the first child of | |
848 | this node; and all the children of a given node are chained | |
4950bc1c | 849 | together via their SIBLING fields. */ |
639d11d3 DC |
850 | struct die_info *child; /* Its first child, if any. */ |
851 | struct die_info *sibling; /* Its next sibling, if any. */ | |
852 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 853 | |
b60c80d6 DJ |
854 | /* An array of attributes, with NUM_ATTRS elements. There may be |
855 | zero, but it's not common and zero-sized arrays are not | |
856 | sufficiently portable C. */ | |
857 | struct attribute attrs[1]; | |
c906108c SS |
858 | }; |
859 | ||
0963b4bd | 860 | /* Get at parts of an attribute structure. */ |
c906108c SS |
861 | |
862 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 863 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
864 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
865 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
866 | #define DW_SND(attr) ((attr)->u.snd) | |
867 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 868 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c | 869 | |
0963b4bd | 870 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
871 | struct dwarf_block |
872 | { | |
873 | unsigned int size; | |
1d6edc3c JK |
874 | |
875 | /* Valid only if SIZE is not zero. */ | |
fe1b8b76 | 876 | gdb_byte *data; |
c906108c SS |
877 | }; |
878 | ||
c906108c SS |
879 | #ifndef ATTR_ALLOC_CHUNK |
880 | #define ATTR_ALLOC_CHUNK 4 | |
881 | #endif | |
882 | ||
c906108c SS |
883 | /* Allocate fields for structs, unions and enums in this size. */ |
884 | #ifndef DW_FIELD_ALLOC_CHUNK | |
885 | #define DW_FIELD_ALLOC_CHUNK 4 | |
886 | #endif | |
887 | ||
c906108c SS |
888 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
889 | but this would require a corresponding change in unpack_field_as_long | |
890 | and friends. */ | |
891 | static int bits_per_byte = 8; | |
892 | ||
893 | /* The routines that read and process dies for a C struct or C++ class | |
894 | pass lists of data member fields and lists of member function fields | |
895 | in an instance of a field_info structure, as defined below. */ | |
896 | struct field_info | |
c5aa993b | 897 | { |
0963b4bd | 898 | /* List of data member and baseclasses fields. */ |
c5aa993b JM |
899 | struct nextfield |
900 | { | |
901 | struct nextfield *next; | |
902 | int accessibility; | |
903 | int virtuality; | |
904 | struct field field; | |
905 | } | |
7d0ccb61 | 906 | *fields, *baseclasses; |
c906108c | 907 | |
7d0ccb61 | 908 | /* Number of fields (including baseclasses). */ |
c5aa993b | 909 | int nfields; |
c906108c | 910 | |
c5aa993b JM |
911 | /* Number of baseclasses. */ |
912 | int nbaseclasses; | |
c906108c | 913 | |
c5aa993b JM |
914 | /* Set if the accesibility of one of the fields is not public. */ |
915 | int non_public_fields; | |
c906108c | 916 | |
c5aa993b JM |
917 | /* Member function fields array, entries are allocated in the order they |
918 | are encountered in the object file. */ | |
919 | struct nextfnfield | |
920 | { | |
921 | struct nextfnfield *next; | |
922 | struct fn_field fnfield; | |
923 | } | |
924 | *fnfields; | |
c906108c | 925 | |
c5aa993b JM |
926 | /* Member function fieldlist array, contains name of possibly overloaded |
927 | member function, number of overloaded member functions and a pointer | |
928 | to the head of the member function field chain. */ | |
929 | struct fnfieldlist | |
930 | { | |
931 | char *name; | |
932 | int length; | |
933 | struct nextfnfield *head; | |
934 | } | |
935 | *fnfieldlists; | |
c906108c | 936 | |
c5aa993b JM |
937 | /* Number of entries in the fnfieldlists array. */ |
938 | int nfnfields; | |
98751a41 JK |
939 | |
940 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
941 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
942 | struct typedef_field_list | |
943 | { | |
944 | struct typedef_field field; | |
945 | struct typedef_field_list *next; | |
946 | } | |
947 | *typedef_field_list; | |
948 | unsigned typedef_field_list_count; | |
c5aa993b | 949 | }; |
c906108c | 950 | |
10b3939b DJ |
951 | /* One item on the queue of compilation units to read in full symbols |
952 | for. */ | |
953 | struct dwarf2_queue_item | |
954 | { | |
955 | struct dwarf2_per_cu_data *per_cu; | |
95554aad | 956 | enum language pretend_language; |
10b3939b DJ |
957 | struct dwarf2_queue_item *next; |
958 | }; | |
959 | ||
960 | /* The current queue. */ | |
961 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
962 | ||
ae038cb0 DJ |
963 | /* Loaded secondary compilation units are kept in memory until they |
964 | have not been referenced for the processing of this many | |
965 | compilation units. Set this to zero to disable caching. Cache | |
966 | sizes of up to at least twenty will improve startup time for | |
967 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
968 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
969 | static void |
970 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
971 | struct cmd_list_element *c, const char *value) | |
972 | { | |
3e43a32a MS |
973 | fprintf_filtered (file, _("The upper bound on the age of cached " |
974 | "dwarf2 compilation units is %s.\n"), | |
920d2a44 AC |
975 | value); |
976 | } | |
977 | ||
ae038cb0 | 978 | |
0963b4bd | 979 | /* Various complaints about symbol reading that don't abort the process. */ |
c906108c | 980 | |
4d3c2250 KB |
981 | static void |
982 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 983 | { |
4d3c2250 | 984 | complaint (&symfile_complaints, |
e2e0b3e5 | 985 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
986 | } |
987 | ||
25e43795 DJ |
988 | static void |
989 | dwarf2_debug_line_missing_file_complaint (void) | |
990 | { | |
991 | complaint (&symfile_complaints, | |
992 | _(".debug_line section has line data without a file")); | |
993 | } | |
994 | ||
59205f5a JB |
995 | static void |
996 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
997 | { | |
998 | complaint (&symfile_complaints, | |
3e43a32a MS |
999 | _(".debug_line section has line " |
1000 | "program sequence without an end")); | |
59205f5a JB |
1001 | } |
1002 | ||
4d3c2250 KB |
1003 | static void |
1004 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 1005 | { |
e2e0b3e5 | 1006 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
1007 | } |
1008 | ||
4d3c2250 KB |
1009 | static void |
1010 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
1011 | int arg3) | |
2e276125 | 1012 | { |
4d3c2250 | 1013 | complaint (&symfile_complaints, |
3e43a32a MS |
1014 | _("const value length mismatch for '%s', got %d, expected %d"), |
1015 | arg1, arg2, arg3); | |
4d3c2250 KB |
1016 | } |
1017 | ||
1018 | static void | |
f664829e | 1019 | dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section) |
2e276125 | 1020 | { |
4d3c2250 | 1021 | complaint (&symfile_complaints, |
f664829e DE |
1022 | _("debug info runs off end of %s section" |
1023 | " [in module %s]"), | |
1024 | section->asection->name, | |
1025 | bfd_get_filename (section->asection->owner)); | |
4d3c2250 KB |
1026 | } |
1027 | ||
1028 | static void | |
1029 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 1030 | { |
4d3c2250 | 1031 | complaint (&symfile_complaints, |
3e43a32a MS |
1032 | _("macro debug info contains a " |
1033 | "malformed macro definition:\n`%s'"), | |
4d3c2250 KB |
1034 | arg1); |
1035 | } | |
1036 | ||
1037 | static void | |
1038 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 1039 | { |
4d3c2250 | 1040 | complaint (&symfile_complaints, |
3e43a32a MS |
1041 | _("invalid attribute class or form for '%s' in '%s'"), |
1042 | arg1, arg2); | |
4d3c2250 | 1043 | } |
c906108c | 1044 | |
c906108c SS |
1045 | /* local function prototypes */ |
1046 | ||
4efb68b1 | 1047 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 1048 | |
aaa75496 JB |
1049 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
1050 | struct objfile *); | |
1051 | ||
918dd910 JK |
1052 | static void dwarf2_find_base_address (struct die_info *die, |
1053 | struct dwarf2_cu *cu); | |
1054 | ||
c67a9c90 | 1055 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 1056 | |
72bf9492 DJ |
1057 | static void scan_partial_symbols (struct partial_die_info *, |
1058 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 1059 | int, struct dwarf2_cu *); |
c906108c | 1060 | |
72bf9492 DJ |
1061 | static void add_partial_symbol (struct partial_die_info *, |
1062 | struct dwarf2_cu *); | |
63d06c5c | 1063 | |
72bf9492 DJ |
1064 | static void add_partial_namespace (struct partial_die_info *pdi, |
1065 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 1066 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 1067 | |
5d7cb8df JK |
1068 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
1069 | CORE_ADDR *highpc, int need_pc, | |
1070 | struct dwarf2_cu *cu); | |
1071 | ||
72bf9492 DJ |
1072 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
1073 | struct dwarf2_cu *cu); | |
91c24f0a | 1074 | |
bc30ff58 JB |
1075 | static void add_partial_subprogram (struct partial_die_info *pdi, |
1076 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 1077 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 1078 | |
a14ed312 | 1079 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 1080 | |
a14ed312 | 1081 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 1082 | |
dee91e82 DE |
1083 | static void dwarf2_read_abbrevs (struct dwarf2_cu *, |
1084 | struct dwarf2_section_info *); | |
c906108c | 1085 | |
f3dd6933 | 1086 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 1087 | |
6caca83c CC |
1088 | static unsigned int peek_abbrev_code (bfd *, gdb_byte *); |
1089 | ||
fe1b8b76 | 1090 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 1091 | struct dwarf2_cu *); |
72bf9492 | 1092 | |
57349743 | 1093 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 1094 | struct dwarf2_cu *); |
c906108c | 1095 | |
dee91e82 DE |
1096 | static struct partial_die_info *load_partial_dies |
1097 | (const struct die_reader_specs *, gdb_byte *, int); | |
72bf9492 | 1098 | |
dee91e82 DE |
1099 | static gdb_byte *read_partial_die (const struct die_reader_specs *, |
1100 | struct partial_die_info *, | |
1101 | struct abbrev_info *, | |
1102 | unsigned int, | |
1103 | gdb_byte *); | |
c906108c | 1104 | |
b64f50a1 | 1105 | static struct partial_die_info *find_partial_die (sect_offset, |
10b3939b | 1106 | struct dwarf2_cu *); |
72bf9492 DJ |
1107 | |
1108 | static void fixup_partial_die (struct partial_die_info *, | |
1109 | struct dwarf2_cu *); | |
1110 | ||
dee91e82 DE |
1111 | static gdb_byte *read_attribute (const struct die_reader_specs *, |
1112 | struct attribute *, struct attr_abbrev *, | |
1113 | gdb_byte *); | |
a8329558 | 1114 | |
fe1b8b76 | 1115 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 1116 | |
fe1b8b76 | 1117 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 1118 | |
fe1b8b76 | 1119 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 1120 | |
fe1b8b76 | 1121 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 1122 | |
93311388 | 1123 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 1124 | |
fe1b8b76 | 1125 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 1126 | unsigned int *); |
c906108c | 1127 | |
c764a876 DE |
1128 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
1129 | ||
1130 | static LONGEST read_checked_initial_length_and_offset | |
1131 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
1132 | unsigned int *, unsigned int *); | |
613e1657 | 1133 | |
fe1b8b76 | 1134 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
1135 | unsigned int *); |
1136 | ||
1137 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 1138 | |
fe1b8b76 | 1139 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 1140 | |
9b1c24c8 | 1141 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1142 | |
fe1b8b76 JB |
1143 | static char *read_indirect_string (bfd *, gdb_byte *, |
1144 | const struct comp_unit_head *, | |
1145 | unsigned int *); | |
4bdf3d34 | 1146 | |
12df843f | 1147 | static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1148 | |
12df843f | 1149 | static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1150 | |
3019eac3 DE |
1151 | static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, gdb_byte *, |
1152 | unsigned int *); | |
1153 | ||
1154 | static char *read_str_index (const struct die_reader_specs *reader, | |
1155 | struct dwarf2_cu *cu, ULONGEST str_index); | |
1156 | ||
e142c38c | 1157 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 1158 | |
e142c38c DJ |
1159 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
1160 | struct dwarf2_cu *); | |
c906108c | 1161 | |
348e048f DE |
1162 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
1163 | unsigned int, | |
1164 | struct dwarf2_cu *); | |
1165 | ||
05cf31d1 JB |
1166 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
1167 | struct dwarf2_cu *cu); | |
1168 | ||
e142c38c | 1169 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 1170 | |
e142c38c | 1171 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 1172 | struct dwarf2_cu **); |
63d06c5c | 1173 | |
debd256d JB |
1174 | static void free_line_header (struct line_header *lh); |
1175 | ||
aaa75496 JB |
1176 | static void add_file_name (struct line_header *, char *, unsigned int, |
1177 | unsigned int, unsigned int); | |
1178 | ||
3019eac3 DE |
1179 | static struct line_header *dwarf_decode_line_header (unsigned int offset, |
1180 | struct dwarf2_cu *cu); | |
debd256d | 1181 | |
f3f5162e DE |
1182 | static void dwarf_decode_lines (struct line_header *, const char *, |
1183 | struct dwarf2_cu *, struct partial_symtab *, | |
1184 | int); | |
c906108c | 1185 | |
72b9f47f | 1186 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 1187 | |
a14ed312 | 1188 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 1189 | struct dwarf2_cu *); |
c906108c | 1190 | |
34eaf542 TT |
1191 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
1192 | struct dwarf2_cu *, struct symbol *); | |
1193 | ||
a14ed312 | 1194 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1195 | struct dwarf2_cu *); |
c906108c | 1196 | |
98bfdba5 PA |
1197 | static void dwarf2_const_value_attr (struct attribute *attr, |
1198 | struct type *type, | |
1199 | const char *name, | |
1200 | struct obstack *obstack, | |
12df843f | 1201 | struct dwarf2_cu *cu, LONGEST *value, |
98bfdba5 PA |
1202 | gdb_byte **bytes, |
1203 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1204 | |
e7c27a73 | 1205 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1206 | |
b4ba55a1 JB |
1207 | static int need_gnat_info (struct dwarf2_cu *); |
1208 | ||
3e43a32a MS |
1209 | static struct type *die_descriptive_type (struct die_info *, |
1210 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1211 | |
1212 | static void set_descriptive_type (struct type *, struct die_info *, | |
1213 | struct dwarf2_cu *); | |
1214 | ||
e7c27a73 DJ |
1215 | static struct type *die_containing_type (struct die_info *, |
1216 | struct dwarf2_cu *); | |
c906108c | 1217 | |
673bfd45 DE |
1218 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1219 | struct dwarf2_cu *); | |
c906108c | 1220 | |
f792889a | 1221 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1222 | |
673bfd45 DE |
1223 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1224 | ||
0d5cff50 | 1225 | static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1226 | |
6e70227d | 1227 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1228 | const char *suffix, int physname, |
1229 | struct dwarf2_cu *cu); | |
63d06c5c | 1230 | |
e7c27a73 | 1231 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1232 | |
348e048f DE |
1233 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1234 | ||
e7c27a73 | 1235 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1236 | |
e7c27a73 | 1237 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1238 | |
96408a79 SA |
1239 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
1240 | ||
ff013f42 JK |
1241 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1242 | struct dwarf2_cu *, struct partial_symtab *); | |
1243 | ||
a14ed312 | 1244 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1245 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1246 | struct partial_symtab *); | |
c906108c | 1247 | |
fae299cd DC |
1248 | static void get_scope_pc_bounds (struct die_info *, |
1249 | CORE_ADDR *, CORE_ADDR *, | |
1250 | struct dwarf2_cu *); | |
1251 | ||
801e3a5b JB |
1252 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1253 | CORE_ADDR, struct dwarf2_cu *); | |
1254 | ||
a14ed312 | 1255 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1256 | struct dwarf2_cu *); |
c906108c | 1257 | |
a14ed312 | 1258 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1259 | struct type *, struct dwarf2_cu *); |
c906108c | 1260 | |
a14ed312 | 1261 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1262 | struct die_info *, struct type *, |
e7c27a73 | 1263 | struct dwarf2_cu *); |
c906108c | 1264 | |
a14ed312 | 1265 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1266 | struct type *, |
1267 | struct dwarf2_cu *); | |
c906108c | 1268 | |
134d01f1 | 1269 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1270 | |
e7c27a73 | 1271 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1272 | |
e7c27a73 | 1273 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1274 | |
5d7cb8df JK |
1275 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1276 | ||
27aa8d6a SW |
1277 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1278 | ||
f55ee35c JK |
1279 | static struct type *read_module_type (struct die_info *die, |
1280 | struct dwarf2_cu *cu); | |
1281 | ||
38d518c9 | 1282 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1283 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1284 | |
134d01f1 | 1285 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1286 | |
e7c27a73 | 1287 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1288 | |
6e70227d | 1289 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1290 | struct dwarf2_cu *); |
1291 | ||
dee91e82 | 1292 | static struct die_info *read_die_and_children (const struct die_reader_specs *, |
93311388 | 1293 | gdb_byte *info_ptr, |
fe1b8b76 | 1294 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1295 | struct die_info *parent); |
1296 | ||
dee91e82 | 1297 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *, |
93311388 | 1298 | gdb_byte *info_ptr, |
fe1b8b76 | 1299 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1300 | struct die_info *parent); |
1301 | ||
3019eac3 DE |
1302 | static gdb_byte *read_full_die_1 (const struct die_reader_specs *, |
1303 | struct die_info **, gdb_byte *, int *, int); | |
1304 | ||
dee91e82 DE |
1305 | static gdb_byte *read_full_die (const struct die_reader_specs *, |
1306 | struct die_info **, gdb_byte *, int *); | |
93311388 | 1307 | |
e7c27a73 | 1308 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1309 | |
71c25dea TT |
1310 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1311 | struct obstack *); | |
1312 | ||
e142c38c | 1313 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1314 | |
98bfdba5 PA |
1315 | static const char *dwarf2_full_name (char *name, |
1316 | struct die_info *die, | |
1317 | struct dwarf2_cu *cu); | |
1318 | ||
e142c38c | 1319 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1320 | struct dwarf2_cu **); |
9219021c | 1321 | |
f39c6ffd | 1322 | static const char *dwarf_tag_name (unsigned int); |
c906108c | 1323 | |
f39c6ffd | 1324 | static const char *dwarf_attr_name (unsigned int); |
c906108c | 1325 | |
f39c6ffd | 1326 | static const char *dwarf_form_name (unsigned int); |
c906108c | 1327 | |
a14ed312 | 1328 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1329 | |
f39c6ffd | 1330 | static const char *dwarf_type_encoding_name (unsigned int); |
c906108c | 1331 | |
f9aca02d | 1332 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1333 | |
d97bc12b DE |
1334 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1335 | ||
1336 | static void dump_die_for_error (struct die_info *); | |
1337 | ||
1338 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1339 | struct die_info *); | |
c906108c | 1340 | |
d97bc12b | 1341 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1342 | |
51545339 | 1343 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1344 | struct dwarf2_cu *); |
c906108c | 1345 | |
93311388 DE |
1346 | static int is_ref_attr (struct attribute *); |
1347 | ||
b64f50a1 | 1348 | static sect_offset dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1349 | |
43bbcdc2 | 1350 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1351 | |
348e048f DE |
1352 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1353 | struct attribute *, | |
1354 | struct dwarf2_cu **); | |
1355 | ||
10b3939b DJ |
1356 | static struct die_info *follow_die_ref (struct die_info *, |
1357 | struct attribute *, | |
f2f0e013 | 1358 | struct dwarf2_cu **); |
c906108c | 1359 | |
348e048f DE |
1360 | static struct die_info *follow_die_sig (struct die_info *, |
1361 | struct attribute *, | |
1362 | struct dwarf2_cu **); | |
1363 | ||
6c83ed52 TT |
1364 | static struct signatured_type *lookup_signatured_type_at_offset |
1365 | (struct objfile *objfile, | |
b64f50a1 | 1366 | struct dwarf2_section_info *section, sect_offset offset); |
6c83ed52 | 1367 | |
e5fe5e75 | 1368 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
348e048f | 1369 | |
52dc124a | 1370 | static void read_signatured_type (struct signatured_type *); |
348e048f | 1371 | |
c906108c SS |
1372 | /* memory allocation interface */ |
1373 | ||
7b5a2f43 | 1374 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1375 | |
f3dd6933 | 1376 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1377 | |
b60c80d6 | 1378 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1379 | |
09262596 DE |
1380 | static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int, |
1381 | char *, int); | |
2e276125 | 1382 | |
8e19ed76 PS |
1383 | static int attr_form_is_block (struct attribute *); |
1384 | ||
3690dd37 JB |
1385 | static int attr_form_is_section_offset (struct attribute *); |
1386 | ||
1387 | static int attr_form_is_constant (struct attribute *); | |
1388 | ||
8cf6f0b1 TT |
1389 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1390 | struct dwarf2_loclist_baton *baton, | |
1391 | struct attribute *attr); | |
1392 | ||
93e7bd98 DJ |
1393 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1394 | struct symbol *sym, | |
1395 | struct dwarf2_cu *cu); | |
4c2df51b | 1396 | |
dee91e82 DE |
1397 | static gdb_byte *skip_one_die (const struct die_reader_specs *reader, |
1398 | gdb_byte *info_ptr, | |
1399 | struct abbrev_info *abbrev); | |
4bb7a0a7 | 1400 | |
72bf9492 DJ |
1401 | static void free_stack_comp_unit (void *); |
1402 | ||
72bf9492 DJ |
1403 | static hashval_t partial_die_hash (const void *item); |
1404 | ||
1405 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1406 | ||
ae038cb0 | 1407 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
b64f50a1 | 1408 | (sect_offset offset, struct objfile *objfile); |
ae038cb0 | 1409 | |
9816fde3 | 1410 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
23745b47 | 1411 | struct dwarf2_per_cu_data *per_cu); |
9816fde3 JK |
1412 | |
1413 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
95554aad TT |
1414 | struct die_info *comp_unit_die, |
1415 | enum language pretend_language); | |
93311388 | 1416 | |
68dc6402 | 1417 | static void free_heap_comp_unit (void *); |
ae038cb0 DJ |
1418 | |
1419 | static void free_cached_comp_units (void *); | |
1420 | ||
1421 | static void age_cached_comp_units (void); | |
1422 | ||
dee91e82 | 1423 | static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *); |
ae038cb0 | 1424 | |
f792889a DJ |
1425 | static struct type *set_die_type (struct die_info *, struct type *, |
1426 | struct dwarf2_cu *); | |
1c379e20 | 1427 | |
ae038cb0 DJ |
1428 | static void create_all_comp_units (struct objfile *); |
1429 | ||
0e50663e | 1430 | static int create_all_type_units (struct objfile *); |
1fd400ff | 1431 | |
95554aad TT |
1432 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1433 | enum language); | |
10b3939b | 1434 | |
95554aad TT |
1435 | static void process_full_comp_unit (struct dwarf2_per_cu_data *, |
1436 | enum language); | |
10b3939b DJ |
1437 | |
1438 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1439 | struct dwarf2_per_cu_data *); | |
1440 | ||
ae038cb0 DJ |
1441 | static void dwarf2_mark (struct dwarf2_cu *); |
1442 | ||
1443 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1444 | ||
b64f50a1 | 1445 | static struct type *get_die_type_at_offset (sect_offset, |
673bfd45 DE |
1446 | struct dwarf2_per_cu_data *per_cu); |
1447 | ||
f792889a | 1448 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1449 | |
9291a0cd TT |
1450 | static void dwarf2_release_queue (void *dummy); |
1451 | ||
95554aad TT |
1452 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, |
1453 | enum language pretend_language); | |
1454 | ||
1455 | static int maybe_queue_comp_unit (struct dwarf2_cu *this_cu, | |
1456 | struct dwarf2_per_cu_data *per_cu, | |
1457 | enum language pretend_language); | |
9291a0cd | 1458 | |
a0f42c21 | 1459 | static void process_queue (void); |
9291a0cd TT |
1460 | |
1461 | static void find_file_and_directory (struct die_info *die, | |
1462 | struct dwarf2_cu *cu, | |
1463 | char **name, char **comp_dir); | |
1464 | ||
1465 | static char *file_full_name (int file, struct line_header *lh, | |
1466 | const char *comp_dir); | |
1467 | ||
fd820528 DE |
1468 | static void init_cutu_and_read_dies |
1469 | (struct dwarf2_per_cu_data *this_cu, int use_existing_cu, int keep, | |
3019eac3 DE |
1470 | die_reader_func_ftype *die_reader_func, void *data); |
1471 | ||
dee91e82 DE |
1472 | static void init_cutu_and_read_dies_simple |
1473 | (struct dwarf2_per_cu_data *this_cu, | |
1474 | die_reader_func_ftype *die_reader_func, void *data); | |
9291a0cd | 1475 | |
673bfd45 | 1476 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1477 | |
95554aad | 1478 | static void process_psymtab_comp_unit (struct dwarf2_per_cu_data *, int); |
dee91e82 | 1479 | |
3019eac3 DE |
1480 | static htab_t allocate_dwo_unit_table (struct objfile *objfile); |
1481 | ||
1482 | static struct dwo_unit *lookup_dwo_comp_unit | |
1483 | (struct dwarf2_per_cu_data *, char *, const char *, ULONGEST); | |
1484 | ||
1485 | static struct dwo_unit *lookup_dwo_type_unit | |
1486 | (struct signatured_type *, char *, const char *); | |
1487 | ||
1488 | static void free_dwo_file_cleanup (void *); | |
1489 | ||
1490 | static void munmap_section_buffer (struct dwarf2_section_info *); | |
1491 | ||
95554aad TT |
1492 | static void process_cu_includes (void); |
1493 | ||
9291a0cd TT |
1494 | #if WORDS_BIGENDIAN |
1495 | ||
1496 | /* Convert VALUE between big- and little-endian. */ | |
1497 | static offset_type | |
1498 | byte_swap (offset_type value) | |
1499 | { | |
1500 | offset_type result; | |
1501 | ||
1502 | result = (value & 0xff) << 24; | |
1503 | result |= (value & 0xff00) << 8; | |
1504 | result |= (value & 0xff0000) >> 8; | |
1505 | result |= (value & 0xff000000) >> 24; | |
1506 | return result; | |
1507 | } | |
1508 | ||
1509 | #define MAYBE_SWAP(V) byte_swap (V) | |
1510 | ||
1511 | #else | |
1512 | #define MAYBE_SWAP(V) (V) | |
1513 | #endif /* WORDS_BIGENDIAN */ | |
1514 | ||
1515 | /* The suffix for an index file. */ | |
1516 | #define INDEX_SUFFIX ".gdb-index" | |
1517 | ||
3da10d80 KS |
1518 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1519 | struct dwarf2_cu *cu); | |
1520 | ||
c906108c | 1521 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
1522 | information and return true if we have enough to do something. |
1523 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
1524 | ELF names are used. */ | |
c906108c SS |
1525 | |
1526 | int | |
251d32d9 TG |
1527 | dwarf2_has_info (struct objfile *objfile, |
1528 | const struct dwarf2_debug_sections *names) | |
c906108c | 1529 | { |
be391dca TT |
1530 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1531 | if (!dwarf2_per_objfile) | |
1532 | { | |
1533 | /* Initialize per-objfile state. */ | |
1534 | struct dwarf2_per_objfile *data | |
1535 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1536 | |
be391dca TT |
1537 | memset (data, 0, sizeof (*data)); |
1538 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1539 | dwarf2_per_objfile = data; | |
6502dd73 | 1540 | |
251d32d9 TG |
1541 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
1542 | (void *) names); | |
be391dca TT |
1543 | dwarf2_per_objfile->objfile = objfile; |
1544 | } | |
1545 | return (dwarf2_per_objfile->info.asection != NULL | |
1546 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1547 | } |
1548 | ||
251d32d9 TG |
1549 | /* When loading sections, we look either for uncompressed section or for |
1550 | compressed section names. */ | |
233a11ab CS |
1551 | |
1552 | static int | |
251d32d9 TG |
1553 | section_is_p (const char *section_name, |
1554 | const struct dwarf2_section_names *names) | |
233a11ab | 1555 | { |
251d32d9 TG |
1556 | if (names->normal != NULL |
1557 | && strcmp (section_name, names->normal) == 0) | |
1558 | return 1; | |
1559 | if (names->compressed != NULL | |
1560 | && strcmp (section_name, names->compressed) == 0) | |
1561 | return 1; | |
1562 | return 0; | |
233a11ab CS |
1563 | } |
1564 | ||
c906108c SS |
1565 | /* This function is mapped across the sections and remembers the |
1566 | offset and size of each of the debugging sections we are interested | |
1567 | in. */ | |
1568 | ||
1569 | static void | |
251d32d9 | 1570 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
c906108c | 1571 | { |
251d32d9 TG |
1572 | const struct dwarf2_debug_sections *names; |
1573 | ||
1574 | if (vnames == NULL) | |
1575 | names = &dwarf2_elf_names; | |
1576 | else | |
1577 | names = (const struct dwarf2_debug_sections *) vnames; | |
1578 | ||
1579 | if (section_is_p (sectp->name, &names->info)) | |
c906108c | 1580 | { |
dce234bc PP |
1581 | dwarf2_per_objfile->info.asection = sectp; |
1582 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1583 | } |
251d32d9 | 1584 | else if (section_is_p (sectp->name, &names->abbrev)) |
c906108c | 1585 | { |
dce234bc PP |
1586 | dwarf2_per_objfile->abbrev.asection = sectp; |
1587 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1588 | } |
251d32d9 | 1589 | else if (section_is_p (sectp->name, &names->line)) |
c906108c | 1590 | { |
dce234bc PP |
1591 | dwarf2_per_objfile->line.asection = sectp; |
1592 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1593 | } |
251d32d9 | 1594 | else if (section_is_p (sectp->name, &names->loc)) |
c906108c | 1595 | { |
dce234bc PP |
1596 | dwarf2_per_objfile->loc.asection = sectp; |
1597 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1598 | } |
251d32d9 | 1599 | else if (section_is_p (sectp->name, &names->macinfo)) |
c906108c | 1600 | { |
dce234bc PP |
1601 | dwarf2_per_objfile->macinfo.asection = sectp; |
1602 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1603 | } |
cf2c3c16 TT |
1604 | else if (section_is_p (sectp->name, &names->macro)) |
1605 | { | |
1606 | dwarf2_per_objfile->macro.asection = sectp; | |
1607 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); | |
1608 | } | |
251d32d9 | 1609 | else if (section_is_p (sectp->name, &names->str)) |
c906108c | 1610 | { |
dce234bc PP |
1611 | dwarf2_per_objfile->str.asection = sectp; |
1612 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1613 | } |
3019eac3 DE |
1614 | else if (section_is_p (sectp->name, &names->addr)) |
1615 | { | |
1616 | dwarf2_per_objfile->addr.asection = sectp; | |
1617 | dwarf2_per_objfile->addr.size = bfd_get_section_size (sectp); | |
1618 | } | |
251d32d9 | 1619 | else if (section_is_p (sectp->name, &names->frame)) |
b6af0555 | 1620 | { |
dce234bc PP |
1621 | dwarf2_per_objfile->frame.asection = sectp; |
1622 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1623 | } |
251d32d9 | 1624 | else if (section_is_p (sectp->name, &names->eh_frame)) |
b6af0555 | 1625 | { |
81b9b86e | 1626 | flagword aflag = bfd_get_section_flags (abfd, sectp); |
9a619af0 | 1627 | |
3799ccc6 EZ |
1628 | if (aflag & SEC_HAS_CONTENTS) |
1629 | { | |
dce234bc PP |
1630 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1631 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1632 | } |
b6af0555 | 1633 | } |
251d32d9 | 1634 | else if (section_is_p (sectp->name, &names->ranges)) |
af34e669 | 1635 | { |
dce234bc PP |
1636 | dwarf2_per_objfile->ranges.asection = sectp; |
1637 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1638 | } |
251d32d9 | 1639 | else if (section_is_p (sectp->name, &names->types)) |
348e048f | 1640 | { |
8b70b953 TT |
1641 | struct dwarf2_section_info type_section; |
1642 | ||
1643 | memset (&type_section, 0, sizeof (type_section)); | |
1644 | type_section.asection = sectp; | |
1645 | type_section.size = bfd_get_section_size (sectp); | |
1646 | ||
1647 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
1648 | &type_section); | |
348e048f | 1649 | } |
251d32d9 | 1650 | else if (section_is_p (sectp->name, &names->gdb_index)) |
9291a0cd TT |
1651 | { |
1652 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1653 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1654 | } | |
dce234bc | 1655 | |
72dca2f5 FR |
1656 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1657 | && bfd_section_vma (abfd, sectp) == 0) | |
1658 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1659 | } |
1660 | ||
dce234bc PP |
1661 | /* Decompress a section that was compressed using zlib. Store the |
1662 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1663 | |
1664 | static void | |
dce234bc PP |
1665 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1666 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1667 | { | |
3019eac3 | 1668 | bfd *abfd = sectp->owner; |
dce234bc PP |
1669 | #ifndef HAVE_ZLIB_H |
1670 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1671 | "is disabled in this copy of GDB"), | |
1672 | bfd_get_filename (abfd)); | |
1673 | #else | |
1674 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1675 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1676 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1677 | bfd_size_type uncompressed_size; |
1678 | gdb_byte *uncompressed_buffer; | |
1679 | z_stream strm; | |
1680 | int rc; | |
1681 | int header_size = 12; | |
1682 | ||
1683 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
3e43a32a MS |
1684 | || bfd_bread (compressed_buffer, |
1685 | compressed_size, abfd) != compressed_size) | |
dce234bc PP |
1686 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
1687 | bfd_get_filename (abfd)); | |
1688 | ||
1689 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1690 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1691 | if (compressed_size < header_size | |
1692 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1693 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1694 | bfd_get_filename (abfd)); | |
1695 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1696 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1697 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1698 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1699 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1700 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1701 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1702 | uncompressed_size += compressed_buffer[11]; | |
1703 | ||
1704 | /* It is possible the section consists of several compressed | |
1705 | buffers concatenated together, so we uncompress in a loop. */ | |
1706 | strm.zalloc = NULL; | |
1707 | strm.zfree = NULL; | |
1708 | strm.opaque = NULL; | |
1709 | strm.avail_in = compressed_size - header_size; | |
1710 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1711 | strm.avail_out = uncompressed_size; | |
1712 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1713 | uncompressed_size); | |
1714 | rc = inflateInit (&strm); | |
1715 | while (strm.avail_in > 0) | |
1716 | { | |
1717 | if (rc != Z_OK) | |
1718 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1719 | bfd_get_filename (abfd), rc); | |
1720 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1721 | + (uncompressed_size - strm.avail_out)); | |
1722 | rc = inflate (&strm, Z_FINISH); | |
1723 | if (rc != Z_STREAM_END) | |
1724 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1725 | bfd_get_filename (abfd), rc); | |
1726 | rc = inflateReset (&strm); | |
1727 | } | |
1728 | rc = inflateEnd (&strm); | |
1729 | if (rc != Z_OK | |
1730 | || strm.avail_out != 0) | |
1731 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1732 | bfd_get_filename (abfd), rc); | |
1733 | ||
affddf13 | 1734 | do_cleanups (cleanup); |
dce234bc PP |
1735 | *outbuf = uncompressed_buffer; |
1736 | *outsize = uncompressed_size; | |
1737 | #endif | |
233a11ab CS |
1738 | } |
1739 | ||
fceca515 DE |
1740 | /* A helper function that decides whether a section is empty, |
1741 | or not present. */ | |
9e0ac564 TT |
1742 | |
1743 | static int | |
1744 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1745 | { | |
1746 | return info->asection == NULL || info->size == 0; | |
1747 | } | |
1748 | ||
3019eac3 DE |
1749 | /* Read the contents of the section INFO. |
1750 | OBJFILE is the main object file, but not necessarily the file where | |
1751 | the section comes from. E.g., for DWO files INFO->asection->owner | |
1752 | is the bfd of the DWO file. | |
dce234bc | 1753 | If the section is compressed, uncompress it before returning. */ |
c906108c | 1754 | |
dce234bc PP |
1755 | static void |
1756 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1757 | { |
dce234bc | 1758 | asection *sectp = info->asection; |
3019eac3 | 1759 | bfd *abfd; |
dce234bc PP |
1760 | gdb_byte *buf, *retbuf; |
1761 | unsigned char header[4]; | |
c906108c | 1762 | |
be391dca TT |
1763 | if (info->readin) |
1764 | return; | |
dce234bc | 1765 | info->buffer = NULL; |
b315ab21 | 1766 | info->map_addr = NULL; |
be391dca | 1767 | info->readin = 1; |
188dd5d6 | 1768 | |
9e0ac564 | 1769 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1770 | return; |
c906108c | 1771 | |
3019eac3 DE |
1772 | /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */ |
1773 | abfd = sectp->owner; | |
1774 | ||
dce234bc PP |
1775 | /* Check if the file has a 4-byte header indicating compression. */ |
1776 | if (info->size > sizeof (header) | |
1777 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1778 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1779 | { | |
1780 | /* Upon decompression, update the buffer and its size. */ | |
1781 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1782 | { | |
1783 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1784 | &info->size); | |
1785 | return; | |
1786 | } | |
1787 | } | |
4bdf3d34 | 1788 | |
dce234bc PP |
1789 | #ifdef HAVE_MMAP |
1790 | if (pagesize == 0) | |
1791 | pagesize = getpagesize (); | |
2e276125 | 1792 | |
dce234bc PP |
1793 | /* Only try to mmap sections which are large enough: we don't want to |
1794 | waste space due to fragmentation. Also, only try mmap for sections | |
1795 | without relocations. */ | |
1796 | ||
1797 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1798 | { | |
b315ab21 TG |
1799 | info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ, |
1800 | MAP_PRIVATE, sectp->filepos, | |
1801 | &info->map_addr, &info->map_len); | |
dce234bc | 1802 | |
b315ab21 | 1803 | if ((caddr_t)info->buffer != MAP_FAILED) |
dce234bc | 1804 | { |
be391dca | 1805 | #if HAVE_POSIX_MADVISE |
b315ab21 | 1806 | posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED); |
be391dca | 1807 | #endif |
dce234bc PP |
1808 | return; |
1809 | } | |
1810 | } | |
1811 | #endif | |
1812 | ||
1813 | /* If we get here, we are a normal, not-compressed section. */ | |
1814 | info->buffer = buf | |
1815 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1816 | ||
1817 | /* When debugging .o files, we may need to apply relocations; see | |
1818 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1819 | We never compress sections in .o files, so we only need to | |
1820 | try this when the section is not compressed. */ | |
ac8035ab | 1821 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1822 | if (retbuf != NULL) |
1823 | { | |
1824 | info->buffer = retbuf; | |
1825 | return; | |
1826 | } | |
1827 | ||
1828 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1829 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1830 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1831 | bfd_get_filename (abfd)); | |
1832 | } | |
1833 | ||
9e0ac564 TT |
1834 | /* A helper function that returns the size of a section in a safe way. |
1835 | If you are positive that the section has been read before using the | |
1836 | size, then it is safe to refer to the dwarf2_section_info object's | |
1837 | "size" field directly. In other cases, you must call this | |
1838 | function, because for compressed sections the size field is not set | |
1839 | correctly until the section has been read. */ | |
1840 | ||
1841 | static bfd_size_type | |
1842 | dwarf2_section_size (struct objfile *objfile, | |
1843 | struct dwarf2_section_info *info) | |
1844 | { | |
1845 | if (!info->readin) | |
1846 | dwarf2_read_section (objfile, info); | |
1847 | return info->size; | |
1848 | } | |
1849 | ||
dce234bc | 1850 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1851 | SECTION_NAME. */ |
af34e669 | 1852 | |
dce234bc | 1853 | void |
3017a003 TG |
1854 | dwarf2_get_section_info (struct objfile *objfile, |
1855 | enum dwarf2_section_enum sect, | |
dce234bc PP |
1856 | asection **sectp, gdb_byte **bufp, |
1857 | bfd_size_type *sizep) | |
1858 | { | |
1859 | struct dwarf2_per_objfile *data | |
1860 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1861 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1862 | |
1863 | /* We may see an objfile without any DWARF, in which case we just | |
1864 | return nothing. */ | |
1865 | if (data == NULL) | |
1866 | { | |
1867 | *sectp = NULL; | |
1868 | *bufp = NULL; | |
1869 | *sizep = 0; | |
1870 | return; | |
1871 | } | |
3017a003 TG |
1872 | switch (sect) |
1873 | { | |
1874 | case DWARF2_DEBUG_FRAME: | |
1875 | info = &data->frame; | |
1876 | break; | |
1877 | case DWARF2_EH_FRAME: | |
1878 | info = &data->eh_frame; | |
1879 | break; | |
1880 | default: | |
1881 | gdb_assert_not_reached ("unexpected section"); | |
1882 | } | |
dce234bc | 1883 | |
9e0ac564 | 1884 | dwarf2_read_section (objfile, info); |
dce234bc PP |
1885 | |
1886 | *sectp = info->asection; | |
1887 | *bufp = info->buffer; | |
1888 | *sizep = info->size; | |
1889 | } | |
1890 | ||
9291a0cd | 1891 | \f |
7b9f3c50 DE |
1892 | /* DWARF quick_symbols_functions support. */ |
1893 | ||
1894 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
1895 | unique line tables, so we maintain a separate table of all .debug_line | |
1896 | derived entries to support the sharing. | |
1897 | All the quick functions need is the list of file names. We discard the | |
1898 | line_header when we're done and don't need to record it here. */ | |
1899 | struct quick_file_names | |
1900 | { | |
1901 | /* The offset in .debug_line of the line table. We hash on this. */ | |
1902 | unsigned int offset; | |
1903 | ||
1904 | /* The number of entries in file_names, real_names. */ | |
1905 | unsigned int num_file_names; | |
1906 | ||
1907 | /* The file names from the line table, after being run through | |
1908 | file_full_name. */ | |
1909 | const char **file_names; | |
1910 | ||
1911 | /* The file names from the line table after being run through | |
1912 | gdb_realpath. These are computed lazily. */ | |
1913 | const char **real_names; | |
1914 | }; | |
1915 | ||
1916 | /* When using the index (and thus not using psymtabs), each CU has an | |
1917 | object of this type. This is used to hold information needed by | |
1918 | the various "quick" methods. */ | |
1919 | struct dwarf2_per_cu_quick_data | |
1920 | { | |
1921 | /* The file table. This can be NULL if there was no file table | |
1922 | or it's currently not read in. | |
1923 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
1924 | struct quick_file_names *file_names; | |
1925 | ||
1926 | /* The corresponding symbol table. This is NULL if symbols for this | |
1927 | CU have not yet been read. */ | |
1928 | struct symtab *symtab; | |
1929 | ||
1930 | /* A temporary mark bit used when iterating over all CUs in | |
1931 | expand_symtabs_matching. */ | |
1932 | unsigned int mark : 1; | |
1933 | ||
1934 | /* True if we've tried to read the file table and found there isn't one. | |
1935 | There will be no point in trying to read it again next time. */ | |
1936 | unsigned int no_file_data : 1; | |
1937 | }; | |
1938 | ||
1939 | /* Hash function for a quick_file_names. */ | |
1940 | ||
1941 | static hashval_t | |
1942 | hash_file_name_entry (const void *e) | |
1943 | { | |
1944 | const struct quick_file_names *file_data = e; | |
1945 | ||
1946 | return file_data->offset; | |
1947 | } | |
1948 | ||
1949 | /* Equality function for a quick_file_names. */ | |
1950 | ||
1951 | static int | |
1952 | eq_file_name_entry (const void *a, const void *b) | |
1953 | { | |
1954 | const struct quick_file_names *ea = a; | |
1955 | const struct quick_file_names *eb = b; | |
1956 | ||
1957 | return ea->offset == eb->offset; | |
1958 | } | |
1959 | ||
1960 | /* Delete function for a quick_file_names. */ | |
1961 | ||
1962 | static void | |
1963 | delete_file_name_entry (void *e) | |
1964 | { | |
1965 | struct quick_file_names *file_data = e; | |
1966 | int i; | |
1967 | ||
1968 | for (i = 0; i < file_data->num_file_names; ++i) | |
1969 | { | |
1970 | xfree ((void*) file_data->file_names[i]); | |
1971 | if (file_data->real_names) | |
1972 | xfree ((void*) file_data->real_names[i]); | |
1973 | } | |
1974 | ||
1975 | /* The space for the struct itself lives on objfile_obstack, | |
1976 | so we don't free it here. */ | |
1977 | } | |
1978 | ||
1979 | /* Create a quick_file_names hash table. */ | |
1980 | ||
1981 | static htab_t | |
1982 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
1983 | { | |
1984 | return htab_create_alloc (nr_initial_entries, | |
1985 | hash_file_name_entry, eq_file_name_entry, | |
1986 | delete_file_name_entry, xcalloc, xfree); | |
1987 | } | |
9291a0cd | 1988 | |
918dd910 JK |
1989 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
1990 | have to be created afterwards. You should call age_cached_comp_units after | |
1991 | processing PER_CU->CU. dw2_setup must have been already called. */ | |
1992 | ||
1993 | static void | |
1994 | load_cu (struct dwarf2_per_cu_data *per_cu) | |
1995 | { | |
3019eac3 | 1996 | if (per_cu->is_debug_types) |
e5fe5e75 | 1997 | load_full_type_unit (per_cu); |
918dd910 | 1998 | else |
95554aad | 1999 | load_full_comp_unit (per_cu, language_minimal); |
918dd910 | 2000 | |
918dd910 | 2001 | gdb_assert (per_cu->cu != NULL); |
2dc860c0 DE |
2002 | |
2003 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); | |
918dd910 JK |
2004 | } |
2005 | ||
a0f42c21 | 2006 | /* Read in the symbols for PER_CU. */ |
2fdf6df6 | 2007 | |
9291a0cd | 2008 | static void |
a0f42c21 | 2009 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
2010 | { |
2011 | struct cleanup *back_to; | |
2012 | ||
2013 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
2014 | ||
95554aad TT |
2015 | if (dwarf2_per_objfile->using_index |
2016 | ? per_cu->v.quick->symtab == NULL | |
2017 | : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin)) | |
2018 | { | |
2019 | queue_comp_unit (per_cu, language_minimal); | |
2020 | load_cu (per_cu); | |
2021 | } | |
9291a0cd | 2022 | |
a0f42c21 | 2023 | process_queue (); |
9291a0cd TT |
2024 | |
2025 | /* Age the cache, releasing compilation units that have not | |
2026 | been used recently. */ | |
2027 | age_cached_comp_units (); | |
2028 | ||
2029 | do_cleanups (back_to); | |
2030 | } | |
2031 | ||
2032 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
2033 | the objfile from which this CU came. Returns the resulting symbol | |
2034 | table. */ | |
2fdf6df6 | 2035 | |
9291a0cd | 2036 | static struct symtab * |
a0f42c21 | 2037 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd | 2038 | { |
95554aad | 2039 | gdb_assert (dwarf2_per_objfile->using_index); |
9291a0cd TT |
2040 | if (!per_cu->v.quick->symtab) |
2041 | { | |
2042 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
2043 | increment_reading_symtab (); | |
a0f42c21 | 2044 | dw2_do_instantiate_symtab (per_cu); |
95554aad | 2045 | process_cu_includes (); |
9291a0cd TT |
2046 | do_cleanups (back_to); |
2047 | } | |
2048 | return per_cu->v.quick->symtab; | |
2049 | } | |
2050 | ||
1fd400ff | 2051 | /* Return the CU given its index. */ |
2fdf6df6 | 2052 | |
1fd400ff TT |
2053 | static struct dwarf2_per_cu_data * |
2054 | dw2_get_cu (int index) | |
2055 | { | |
2056 | if (index >= dwarf2_per_objfile->n_comp_units) | |
2057 | { | |
2058 | index -= dwarf2_per_objfile->n_comp_units; | |
d467dd73 | 2059 | return dwarf2_per_objfile->all_type_units[index]; |
1fd400ff TT |
2060 | } |
2061 | return dwarf2_per_objfile->all_comp_units[index]; | |
2062 | } | |
2063 | ||
9291a0cd TT |
2064 | /* A helper function that knows how to read a 64-bit value in a way |
2065 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
2066 | otherwise. */ | |
2fdf6df6 | 2067 | |
9291a0cd TT |
2068 | static int |
2069 | extract_cu_value (const char *bytes, ULONGEST *result) | |
2070 | { | |
2071 | if (sizeof (ULONGEST) < 8) | |
2072 | { | |
2073 | int i; | |
2074 | ||
2075 | /* Ignore the upper 4 bytes if they are all zero. */ | |
2076 | for (i = 0; i < 4; ++i) | |
2077 | if (bytes[i + 4] != 0) | |
2078 | return 0; | |
2079 | ||
2080 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
2081 | } | |
2082 | else | |
2083 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
2084 | return 1; | |
2085 | } | |
2086 | ||
2087 | /* Read the CU list from the mapped index, and use it to create all | |
2088 | the CU objects for this objfile. Return 0 if something went wrong, | |
2089 | 1 if everything went ok. */ | |
2fdf6df6 | 2090 | |
9291a0cd | 2091 | static int |
1fd400ff TT |
2092 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
2093 | offset_type cu_list_elements) | |
9291a0cd TT |
2094 | { |
2095 | offset_type i; | |
9291a0cd TT |
2096 | |
2097 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
2098 | dwarf2_per_objfile->all_comp_units | |
2099 | = obstack_alloc (&objfile->objfile_obstack, | |
2100 | dwarf2_per_objfile->n_comp_units | |
2101 | * sizeof (struct dwarf2_per_cu_data *)); | |
2102 | ||
2103 | for (i = 0; i < cu_list_elements; i += 2) | |
2104 | { | |
2105 | struct dwarf2_per_cu_data *the_cu; | |
2106 | ULONGEST offset, length; | |
2107 | ||
2108 | if (!extract_cu_value (cu_list, &offset) | |
2109 | || !extract_cu_value (cu_list + 8, &length)) | |
2110 | return 0; | |
2111 | cu_list += 2 * 8; | |
2112 | ||
2113 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
2114 | struct dwarf2_per_cu_data); | |
b64f50a1 | 2115 | the_cu->offset.sect_off = offset; |
9291a0cd TT |
2116 | the_cu->length = length; |
2117 | the_cu->objfile = objfile; | |
3019eac3 | 2118 | the_cu->info_or_types_section = &dwarf2_per_objfile->info; |
9291a0cd TT |
2119 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2120 | struct dwarf2_per_cu_quick_data); | |
2121 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
2122 | } | |
2123 | ||
2124 | return 1; | |
2125 | } | |
2126 | ||
1fd400ff | 2127 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 2128 | |
1fd400ff | 2129 | static int |
673bfd45 | 2130 | create_signatured_type_table_from_index (struct objfile *objfile, |
8b70b953 | 2131 | struct dwarf2_section_info *section, |
673bfd45 DE |
2132 | const gdb_byte *bytes, |
2133 | offset_type elements) | |
1fd400ff TT |
2134 | { |
2135 | offset_type i; | |
673bfd45 | 2136 | htab_t sig_types_hash; |
1fd400ff | 2137 | |
d467dd73 DE |
2138 | dwarf2_per_objfile->n_type_units = elements / 3; |
2139 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 2140 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 2141 | dwarf2_per_objfile->n_type_units |
1fd400ff TT |
2142 | * sizeof (struct dwarf2_per_cu_data *)); |
2143 | ||
673bfd45 | 2144 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
2145 | |
2146 | for (i = 0; i < elements; i += 3) | |
2147 | { | |
52dc124a DE |
2148 | struct signatured_type *sig_type; |
2149 | ULONGEST offset, type_offset_in_tu, signature; | |
1fd400ff TT |
2150 | void **slot; |
2151 | ||
2152 | if (!extract_cu_value (bytes, &offset) | |
52dc124a | 2153 | || !extract_cu_value (bytes + 8, &type_offset_in_tu)) |
1fd400ff TT |
2154 | return 0; |
2155 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
2156 | bytes += 3 * 8; | |
2157 | ||
52dc124a | 2158 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
1fd400ff | 2159 | struct signatured_type); |
52dc124a | 2160 | sig_type->signature = signature; |
3019eac3 DE |
2161 | sig_type->type_offset_in_tu.cu_off = type_offset_in_tu; |
2162 | sig_type->per_cu.is_debug_types = 1; | |
2163 | sig_type->per_cu.info_or_types_section = section; | |
52dc124a DE |
2164 | sig_type->per_cu.offset.sect_off = offset; |
2165 | sig_type->per_cu.objfile = objfile; | |
2166 | sig_type->per_cu.v.quick | |
1fd400ff TT |
2167 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2168 | struct dwarf2_per_cu_quick_data); | |
2169 | ||
52dc124a DE |
2170 | slot = htab_find_slot (sig_types_hash, sig_type, INSERT); |
2171 | *slot = sig_type; | |
1fd400ff | 2172 | |
52dc124a | 2173 | dwarf2_per_objfile->all_type_units[i / 3] = &sig_type->per_cu; |
1fd400ff TT |
2174 | } |
2175 | ||
673bfd45 | 2176 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
2177 | |
2178 | return 1; | |
2179 | } | |
2180 | ||
9291a0cd TT |
2181 | /* Read the address map data from the mapped index, and use it to |
2182 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 2183 | |
9291a0cd TT |
2184 | static void |
2185 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
2186 | { | |
2187 | const gdb_byte *iter, *end; | |
2188 | struct obstack temp_obstack; | |
2189 | struct addrmap *mutable_map; | |
2190 | struct cleanup *cleanup; | |
2191 | CORE_ADDR baseaddr; | |
2192 | ||
2193 | obstack_init (&temp_obstack); | |
2194 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
2195 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
2196 | ||
2197 | iter = index->address_table; | |
2198 | end = iter + index->address_table_size; | |
2199 | ||
2200 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2201 | ||
2202 | while (iter < end) | |
2203 | { | |
2204 | ULONGEST hi, lo, cu_index; | |
2205 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
2206 | iter += 8; | |
2207 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
2208 | iter += 8; | |
2209 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
2210 | iter += 4; | |
2211 | ||
2212 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 2213 | dw2_get_cu (cu_index)); |
9291a0cd TT |
2214 | } |
2215 | ||
2216 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
2217 | &objfile->objfile_obstack); | |
2218 | do_cleanups (cleanup); | |
2219 | } | |
2220 | ||
59d7bcaf JK |
2221 | /* The hash function for strings in the mapped index. This is the same as |
2222 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
2223 | implementation. This is necessary because the hash function is tied to the | |
2224 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
2225 | SYMBOL_HASH_NEXT. |
2226 | ||
2227 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 2228 | |
9291a0cd | 2229 | static hashval_t |
559a7a62 | 2230 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
2231 | { |
2232 | const unsigned char *str = (const unsigned char *) p; | |
2233 | hashval_t r = 0; | |
2234 | unsigned char c; | |
2235 | ||
2236 | while ((c = *str++) != 0) | |
559a7a62 JK |
2237 | { |
2238 | if (index_version >= 5) | |
2239 | c = tolower (c); | |
2240 | r = r * 67 + c - 113; | |
2241 | } | |
9291a0cd TT |
2242 | |
2243 | return r; | |
2244 | } | |
2245 | ||
2246 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
2247 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
2248 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 2249 | |
9291a0cd TT |
2250 | static int |
2251 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
2252 | offset_type **vec_out) | |
2253 | { | |
0cf03b49 JK |
2254 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2255 | offset_type hash; | |
9291a0cd | 2256 | offset_type slot, step; |
559a7a62 | 2257 | int (*cmp) (const char *, const char *); |
9291a0cd | 2258 | |
0cf03b49 JK |
2259 | if (current_language->la_language == language_cplus |
2260 | || current_language->la_language == language_java | |
2261 | || current_language->la_language == language_fortran) | |
2262 | { | |
2263 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2264 | not contain any. */ | |
2265 | const char *paren = strchr (name, '('); | |
2266 | ||
2267 | if (paren) | |
2268 | { | |
2269 | char *dup; | |
2270 | ||
2271 | dup = xmalloc (paren - name + 1); | |
2272 | memcpy (dup, name, paren - name); | |
2273 | dup[paren - name] = 0; | |
2274 | ||
2275 | make_cleanup (xfree, dup); | |
2276 | name = dup; | |
2277 | } | |
2278 | } | |
2279 | ||
559a7a62 | 2280 | /* Index version 4 did not support case insensitive searches. But the |
feea76c2 | 2281 | indices for case insensitive languages are built in lowercase, therefore |
559a7a62 JK |
2282 | simulate our NAME being searched is also lowercased. */ |
2283 | hash = mapped_index_string_hash ((index->version == 4 | |
2284 | && case_sensitivity == case_sensitive_off | |
2285 | ? 5 : index->version), | |
2286 | name); | |
2287 | ||
3876f04e DE |
2288 | slot = hash & (index->symbol_table_slots - 1); |
2289 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 2290 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
2291 | |
2292 | for (;;) | |
2293 | { | |
2294 | /* Convert a slot number to an offset into the table. */ | |
2295 | offset_type i = 2 * slot; | |
2296 | const char *str; | |
3876f04e | 2297 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2298 | { |
2299 | do_cleanups (back_to); | |
2300 | return 0; | |
2301 | } | |
9291a0cd | 2302 | |
3876f04e | 2303 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 2304 | if (!cmp (name, str)) |
9291a0cd TT |
2305 | { |
2306 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2307 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2308 | do_cleanups (back_to); |
9291a0cd TT |
2309 | return 1; |
2310 | } | |
2311 | ||
3876f04e | 2312 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2313 | } |
2314 | } | |
2315 | ||
2316 | /* Read the index file. If everything went ok, initialize the "quick" | |
2317 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2fdf6df6 | 2318 | |
9291a0cd TT |
2319 | static int |
2320 | dwarf2_read_index (struct objfile *objfile) | |
2321 | { | |
9291a0cd TT |
2322 | char *addr; |
2323 | struct mapped_index *map; | |
b3b272e1 | 2324 | offset_type *metadata; |
ac0b195c KW |
2325 | const gdb_byte *cu_list; |
2326 | const gdb_byte *types_list = NULL; | |
2327 | offset_type version, cu_list_elements; | |
2328 | offset_type types_list_elements = 0; | |
1fd400ff | 2329 | int i; |
9291a0cd | 2330 | |
9e0ac564 | 2331 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
9291a0cd | 2332 | return 0; |
82430852 JK |
2333 | |
2334 | /* Older elfutils strip versions could keep the section in the main | |
2335 | executable while splitting it for the separate debug info file. */ | |
2336 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
2337 | & SEC_HAS_CONTENTS) == 0) | |
2338 | return 0; | |
2339 | ||
9291a0cd TT |
2340 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
2341 | ||
2342 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
2343 | /* Version check. */ | |
1fd400ff | 2344 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2345 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2346 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 2347 | contained incomplete addrmap. So, it seems better to just ignore such |
481860b3 | 2348 | indices. */ |
831adc1f | 2349 | if (version < 4) |
481860b3 GB |
2350 | { |
2351 | static int warning_printed = 0; | |
2352 | if (!warning_printed) | |
2353 | { | |
2354 | warning (_("Skipping obsolete .gdb_index section in %s."), | |
2355 | objfile->name); | |
2356 | warning_printed = 1; | |
2357 | } | |
2358 | return 0; | |
2359 | } | |
2360 | /* Index version 4 uses a different hash function than index version | |
2361 | 5 and later. | |
2362 | ||
2363 | Versions earlier than 6 did not emit psymbols for inlined | |
2364 | functions. Using these files will cause GDB not to be able to | |
2365 | set breakpoints on inlined functions by name, so we ignore these | |
2366 | indices unless the --use-deprecated-index-sections command line | |
2367 | option was supplied. */ | |
2368 | if (version < 6 && !use_deprecated_index_sections) | |
2369 | { | |
2370 | static int warning_printed = 0; | |
2371 | if (!warning_printed) | |
2372 | { | |
2373 | warning (_("Skipping deprecated .gdb_index section in %s, pass " | |
2374 | "--use-deprecated-index-sections to use them anyway"), | |
2375 | objfile->name); | |
2376 | warning_printed = 1; | |
2377 | } | |
2378 | return 0; | |
2379 | } | |
2380 | /* Indexes with higher version than the one supported by GDB may be no | |
594e8718 | 2381 | longer backward compatible. */ |
156942c7 | 2382 | if (version > 7) |
594e8718 | 2383 | return 0; |
9291a0cd TT |
2384 | |
2385 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
559a7a62 | 2386 | map->version = version; |
b3b272e1 | 2387 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
2388 | |
2389 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2390 | |
2391 | i = 0; | |
2392 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
2393 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 2394 | / 8); |
1fd400ff TT |
2395 | ++i; |
2396 | ||
987d643c TT |
2397 | types_list = addr + MAYBE_SWAP (metadata[i]); |
2398 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2399 | - MAYBE_SWAP (metadata[i])) | |
2400 | / 8); | |
2401 | ++i; | |
1fd400ff TT |
2402 | |
2403 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2404 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2405 | - MAYBE_SWAP (metadata[i])); | |
2406 | ++i; | |
2407 | ||
3876f04e DE |
2408 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2409 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2410 | - MAYBE_SWAP (metadata[i])) | |
2411 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2412 | ++i; |
9291a0cd | 2413 | |
1fd400ff TT |
2414 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2415 | ||
0fefef59 DE |
2416 | /* Don't use the index if it's empty. */ |
2417 | if (map->symbol_table_slots == 0) | |
2418 | return 0; | |
2419 | ||
1fd400ff TT |
2420 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) |
2421 | return 0; | |
2422 | ||
8b70b953 TT |
2423 | if (types_list_elements) |
2424 | { | |
2425 | struct dwarf2_section_info *section; | |
2426 | ||
2427 | /* We can only handle a single .debug_types when we have an | |
2428 | index. */ | |
2429 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) | |
2430 | return 0; | |
2431 | ||
2432 | section = VEC_index (dwarf2_section_info_def, | |
2433 | dwarf2_per_objfile->types, 0); | |
2434 | ||
2435 | if (!create_signatured_type_table_from_index (objfile, section, | |
2436 | types_list, | |
2437 | types_list_elements)) | |
2438 | return 0; | |
2439 | } | |
9291a0cd TT |
2440 | |
2441 | create_addrmap_from_index (objfile, map); | |
2442 | ||
2443 | dwarf2_per_objfile->index_table = map; | |
2444 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2445 | dwarf2_per_objfile->quick_file_names_table = |
2446 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2447 | |
2448 | return 1; | |
2449 | } | |
2450 | ||
2451 | /* A helper for the "quick" functions which sets the global | |
2452 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2453 | |
9291a0cd TT |
2454 | static void |
2455 | dw2_setup (struct objfile *objfile) | |
2456 | { | |
2457 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2458 | gdb_assert (dwarf2_per_objfile); | |
2459 | } | |
2460 | ||
dee91e82 | 2461 | /* die_reader_func for dw2_get_file_names. */ |
2fdf6df6 | 2462 | |
dee91e82 DE |
2463 | static void |
2464 | dw2_get_file_names_reader (const struct die_reader_specs *reader, | |
2465 | gdb_byte *info_ptr, | |
2466 | struct die_info *comp_unit_die, | |
2467 | int has_children, | |
2468 | void *data) | |
9291a0cd | 2469 | { |
dee91e82 DE |
2470 | struct dwarf2_cu *cu = reader->cu; |
2471 | struct dwarf2_per_cu_data *this_cu = cu->per_cu; | |
2472 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
7b9f3c50 | 2473 | struct line_header *lh; |
9291a0cd | 2474 | struct attribute *attr; |
dee91e82 | 2475 | int i; |
9291a0cd | 2476 | char *name, *comp_dir; |
7b9f3c50 DE |
2477 | void **slot; |
2478 | struct quick_file_names *qfn; | |
2479 | unsigned int line_offset; | |
9291a0cd | 2480 | |
07261596 TT |
2481 | /* Our callers never want to match partial units -- instead they |
2482 | will match the enclosing full CU. */ | |
2483 | if (comp_unit_die->tag == DW_TAG_partial_unit) | |
2484 | { | |
2485 | this_cu->v.quick->no_file_data = 1; | |
2486 | return; | |
2487 | } | |
2488 | ||
7b9f3c50 DE |
2489 | lh = NULL; |
2490 | slot = NULL; | |
2491 | line_offset = 0; | |
dee91e82 DE |
2492 | |
2493 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); | |
9291a0cd TT |
2494 | if (attr) |
2495 | { | |
7b9f3c50 DE |
2496 | struct quick_file_names find_entry; |
2497 | ||
2498 | line_offset = DW_UNSND (attr); | |
2499 | ||
2500 | /* We may have already read in this line header (TU line header sharing). | |
2501 | If we have we're done. */ | |
2502 | find_entry.offset = line_offset; | |
2503 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, | |
2504 | &find_entry, INSERT); | |
2505 | if (*slot != NULL) | |
2506 | { | |
7b9f3c50 | 2507 | this_cu->v.quick->file_names = *slot; |
dee91e82 | 2508 | return; |
7b9f3c50 DE |
2509 | } |
2510 | ||
3019eac3 | 2511 | lh = dwarf_decode_line_header (line_offset, cu); |
9291a0cd TT |
2512 | } |
2513 | if (lh == NULL) | |
2514 | { | |
7b9f3c50 | 2515 | this_cu->v.quick->no_file_data = 1; |
dee91e82 | 2516 | return; |
9291a0cd TT |
2517 | } |
2518 | ||
7b9f3c50 DE |
2519 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
2520 | qfn->offset = line_offset; | |
2521 | gdb_assert (slot != NULL); | |
2522 | *slot = qfn; | |
9291a0cd | 2523 | |
dee91e82 | 2524 | find_file_and_directory (comp_unit_die, cu, &name, &comp_dir); |
9291a0cd | 2525 | |
7b9f3c50 DE |
2526 | qfn->num_file_names = lh->num_file_names; |
2527 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2528 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2529 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2530 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2531 | qfn->real_names = NULL; | |
9291a0cd | 2532 | |
7b9f3c50 | 2533 | free_line_header (lh); |
7b9f3c50 DE |
2534 | |
2535 | this_cu->v.quick->file_names = qfn; | |
dee91e82 DE |
2536 | } |
2537 | ||
2538 | /* A helper for the "quick" functions which attempts to read the line | |
2539 | table for THIS_CU. */ | |
2540 | ||
2541 | static struct quick_file_names * | |
2542 | dw2_get_file_names (struct objfile *objfile, | |
2543 | struct dwarf2_per_cu_data *this_cu) | |
2544 | { | |
2545 | if (this_cu->v.quick->file_names != NULL) | |
2546 | return this_cu->v.quick->file_names; | |
2547 | /* If we know there is no line data, no point in looking again. */ | |
2548 | if (this_cu->v.quick->no_file_data) | |
2549 | return NULL; | |
2550 | ||
3019eac3 DE |
2551 | /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute |
2552 | in the stub for CUs, there's is no need to lookup the DWO file. | |
2553 | However, that's not the case for TUs where DW_AT_stmt_list lives in the | |
2554 | DWO file. */ | |
2555 | if (this_cu->is_debug_types) | |
fd820528 | 2556 | init_cutu_and_read_dies (this_cu, 0, 0, dw2_get_file_names_reader, NULL); |
3019eac3 DE |
2557 | else |
2558 | init_cutu_and_read_dies_simple (this_cu, dw2_get_file_names_reader, NULL); | |
dee91e82 DE |
2559 | |
2560 | if (this_cu->v.quick->no_file_data) | |
2561 | return NULL; | |
2562 | return this_cu->v.quick->file_names; | |
9291a0cd TT |
2563 | } |
2564 | ||
2565 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2566 | real path for a given file name from the line table. */ |
2fdf6df6 | 2567 | |
9291a0cd | 2568 | static const char * |
7b9f3c50 DE |
2569 | dw2_get_real_path (struct objfile *objfile, |
2570 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2571 | { |
7b9f3c50 DE |
2572 | if (qfn->real_names == NULL) |
2573 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2574 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2575 | |
7b9f3c50 DE |
2576 | if (qfn->real_names[index] == NULL) |
2577 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2578 | |
7b9f3c50 | 2579 | return qfn->real_names[index]; |
9291a0cd TT |
2580 | } |
2581 | ||
2582 | static struct symtab * | |
2583 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2584 | { | |
2585 | int index; | |
ae2de4f8 | 2586 | |
9291a0cd TT |
2587 | dw2_setup (objfile); |
2588 | index = dwarf2_per_objfile->n_comp_units - 1; | |
a0f42c21 | 2589 | return dw2_instantiate_symtab (dw2_get_cu (index)); |
9291a0cd TT |
2590 | } |
2591 | ||
7b9f3c50 DE |
2592 | /* Traversal function for dw2_forget_cached_source_info. */ |
2593 | ||
2594 | static int | |
2595 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2596 | { |
7b9f3c50 | 2597 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2598 | |
7b9f3c50 | 2599 | if (file_data->real_names) |
9291a0cd | 2600 | { |
7b9f3c50 | 2601 | int i; |
9291a0cd | 2602 | |
7b9f3c50 | 2603 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2604 | { |
7b9f3c50 DE |
2605 | xfree ((void*) file_data->real_names[i]); |
2606 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
2607 | } |
2608 | } | |
7b9f3c50 DE |
2609 | |
2610 | return 1; | |
2611 | } | |
2612 | ||
2613 | static void | |
2614 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2615 | { | |
2616 | dw2_setup (objfile); | |
2617 | ||
2618 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
2619 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
2620 | } |
2621 | ||
f8eba3c6 TT |
2622 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
2623 | the symtabs and calls the iterator. */ | |
2624 | ||
2625 | static int | |
2626 | dw2_map_expand_apply (struct objfile *objfile, | |
2627 | struct dwarf2_per_cu_data *per_cu, | |
2628 | const char *name, | |
2629 | const char *full_path, const char *real_path, | |
2630 | int (*callback) (struct symtab *, void *), | |
2631 | void *data) | |
2632 | { | |
2633 | struct symtab *last_made = objfile->symtabs; | |
2634 | ||
2635 | /* Don't visit already-expanded CUs. */ | |
2636 | if (per_cu->v.quick->symtab) | |
2637 | return 0; | |
2638 | ||
2639 | /* This may expand more than one symtab, and we want to iterate over | |
2640 | all of them. */ | |
a0f42c21 | 2641 | dw2_instantiate_symtab (per_cu); |
f8eba3c6 TT |
2642 | |
2643 | return iterate_over_some_symtabs (name, full_path, real_path, callback, data, | |
2644 | objfile->symtabs, last_made); | |
2645 | } | |
2646 | ||
2647 | /* Implementation of the map_symtabs_matching_filename method. */ | |
2648 | ||
9291a0cd | 2649 | static int |
f8eba3c6 TT |
2650 | dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name, |
2651 | const char *full_path, const char *real_path, | |
2652 | int (*callback) (struct symtab *, void *), | |
2653 | void *data) | |
9291a0cd TT |
2654 | { |
2655 | int i; | |
c011a4f4 | 2656 | const char *name_basename = lbasename (name); |
4aac40c8 TT |
2657 | int name_len = strlen (name); |
2658 | int is_abs = IS_ABSOLUTE_PATH (name); | |
9291a0cd TT |
2659 | |
2660 | dw2_setup (objfile); | |
ae2de4f8 | 2661 | |
1fd400ff | 2662 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2663 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2664 | { |
2665 | int j; | |
e254ef6a | 2666 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2667 | struct quick_file_names *file_data; |
9291a0cd | 2668 | |
3d7bb9d9 | 2669 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2670 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2671 | continue; |
2672 | ||
7b9f3c50 DE |
2673 | file_data = dw2_get_file_names (objfile, per_cu); |
2674 | if (file_data == NULL) | |
9291a0cd TT |
2675 | continue; |
2676 | ||
7b9f3c50 | 2677 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2678 | { |
7b9f3c50 | 2679 | const char *this_name = file_data->file_names[j]; |
9291a0cd | 2680 | |
4aac40c8 TT |
2681 | if (FILENAME_CMP (name, this_name) == 0 |
2682 | || (!is_abs && compare_filenames_for_search (this_name, | |
2683 | name, name_len))) | |
9291a0cd | 2684 | { |
f8eba3c6 TT |
2685 | if (dw2_map_expand_apply (objfile, per_cu, |
2686 | name, full_path, real_path, | |
2687 | callback, data)) | |
2688 | return 1; | |
4aac40c8 | 2689 | } |
9291a0cd | 2690 | |
c011a4f4 DE |
2691 | /* Before we invoke realpath, which can get expensive when many |
2692 | files are involved, do a quick comparison of the basenames. */ | |
2693 | if (! basenames_may_differ | |
2694 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) | |
2695 | continue; | |
2696 | ||
9291a0cd TT |
2697 | if (full_path != NULL) |
2698 | { | |
7b9f3c50 DE |
2699 | const char *this_real_name = dw2_get_real_path (objfile, |
2700 | file_data, j); | |
9291a0cd | 2701 | |
7b9f3c50 | 2702 | if (this_real_name != NULL |
4aac40c8 TT |
2703 | && (FILENAME_CMP (full_path, this_real_name) == 0 |
2704 | || (!is_abs | |
2705 | && compare_filenames_for_search (this_real_name, | |
2706 | name, name_len)))) | |
9291a0cd | 2707 | { |
f8eba3c6 TT |
2708 | if (dw2_map_expand_apply (objfile, per_cu, |
2709 | name, full_path, real_path, | |
2710 | callback, data)) | |
2711 | return 1; | |
9291a0cd TT |
2712 | } |
2713 | } | |
2714 | ||
2715 | if (real_path != NULL) | |
2716 | { | |
7b9f3c50 DE |
2717 | const char *this_real_name = dw2_get_real_path (objfile, |
2718 | file_data, j); | |
9291a0cd | 2719 | |
7b9f3c50 | 2720 | if (this_real_name != NULL |
4aac40c8 TT |
2721 | && (FILENAME_CMP (real_path, this_real_name) == 0 |
2722 | || (!is_abs | |
2723 | && compare_filenames_for_search (this_real_name, | |
2724 | name, name_len)))) | |
9291a0cd | 2725 | { |
f8eba3c6 TT |
2726 | if (dw2_map_expand_apply (objfile, per_cu, |
2727 | name, full_path, real_path, | |
2728 | callback, data)) | |
2729 | return 1; | |
9291a0cd TT |
2730 | } |
2731 | } | |
2732 | } | |
2733 | } | |
2734 | ||
9291a0cd TT |
2735 | return 0; |
2736 | } | |
2737 | ||
2738 | static struct symtab * | |
2739 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2740 | const char *name, domain_enum domain) | |
2741 | { | |
774b6a14 | 2742 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2743 | instead. */ |
2744 | return NULL; | |
2745 | } | |
2746 | ||
2747 | /* A helper function that expands all symtabs that hold an object | |
156942c7 DE |
2748 | named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for |
2749 | symbols in block BLOCK_KIND. */ | |
2fdf6df6 | 2750 | |
9291a0cd | 2751 | static void |
156942c7 DE |
2752 | dw2_do_expand_symtabs_matching (struct objfile *objfile, |
2753 | int want_specific_block, | |
2754 | enum block_enum block_kind, | |
2755 | const char *name, domain_enum domain) | |
9291a0cd | 2756 | { |
156942c7 DE |
2757 | struct mapped_index *index; |
2758 | ||
9291a0cd TT |
2759 | dw2_setup (objfile); |
2760 | ||
156942c7 DE |
2761 | index = dwarf2_per_objfile->index_table; |
2762 | ||
ae2de4f8 | 2763 | /* index_table is NULL if OBJF_READNOW. */ |
156942c7 | 2764 | if (index) |
9291a0cd TT |
2765 | { |
2766 | offset_type *vec; | |
2767 | ||
156942c7 | 2768 | if (find_slot_in_mapped_hash (index, name, &vec)) |
9291a0cd TT |
2769 | { |
2770 | offset_type i, len = MAYBE_SWAP (*vec); | |
2771 | for (i = 0; i < len; ++i) | |
2772 | { | |
156942c7 DE |
2773 | offset_type cu_index_and_attrs = MAYBE_SWAP (vec[i + 1]); |
2774 | offset_type cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs); | |
e254ef6a | 2775 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
156942c7 DE |
2776 | int want_static = block_kind != GLOBAL_BLOCK; |
2777 | /* This value is only valid for index versions >= 7. */ | |
2778 | int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs); | |
2779 | gdb_index_symbol_kind symbol_kind = | |
2780 | GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs); | |
2781 | ||
2782 | if (want_specific_block | |
2783 | && index->version >= 7 | |
2784 | && want_static != is_static) | |
2785 | continue; | |
2786 | ||
2787 | /* Only check the symbol's kind if it has one. | |
2788 | Indices prior to version 7 don't record it. */ | |
2789 | if (index->version >= 7) | |
2790 | { | |
2791 | switch (domain) | |
2792 | { | |
2793 | case VAR_DOMAIN: | |
2794 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE | |
2795 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION | |
2796 | /* Some types are also in VAR_DOMAIN. */ | |
2797 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) | |
2798 | continue; | |
2799 | break; | |
2800 | case STRUCT_DOMAIN: | |
2801 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) | |
2802 | continue; | |
2803 | break; | |
2804 | case LABEL_DOMAIN: | |
2805 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER) | |
2806 | continue; | |
2807 | break; | |
2808 | default: | |
2809 | break; | |
2810 | } | |
2811 | } | |
1fd400ff | 2812 | |
a0f42c21 | 2813 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2814 | } |
2815 | } | |
2816 | } | |
2817 | } | |
2818 | ||
774b6a14 TT |
2819 | static void |
2820 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
8903c50d | 2821 | enum block_enum block_kind, const char *name, |
774b6a14 | 2822 | domain_enum domain) |
9291a0cd | 2823 | { |
156942c7 | 2824 | dw2_do_expand_symtabs_matching (objfile, 1, block_kind, name, domain); |
9291a0cd TT |
2825 | } |
2826 | ||
2827 | static void | |
2828 | dw2_print_stats (struct objfile *objfile) | |
2829 | { | |
2830 | int i, count; | |
2831 | ||
2832 | dw2_setup (objfile); | |
2833 | count = 0; | |
1fd400ff | 2834 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2835 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2836 | { |
e254ef6a | 2837 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2838 | |
e254ef6a | 2839 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2840 | ++count; |
2841 | } | |
2842 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2843 | } | |
2844 | ||
2845 | static void | |
2846 | dw2_dump (struct objfile *objfile) | |
2847 | { | |
2848 | /* Nothing worth printing. */ | |
2849 | } | |
2850 | ||
2851 | static void | |
2852 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2853 | struct section_offsets *delta) | |
2854 | { | |
2855 | /* There's nothing to relocate here. */ | |
2856 | } | |
2857 | ||
2858 | static void | |
2859 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2860 | const char *func_name) | |
2861 | { | |
156942c7 DE |
2862 | /* Note: It doesn't matter what we pass for block_kind here. */ |
2863 | dw2_do_expand_symtabs_matching (objfile, 0, GLOBAL_BLOCK, func_name, | |
2864 | VAR_DOMAIN); | |
9291a0cd TT |
2865 | } |
2866 | ||
2867 | static void | |
2868 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2869 | { | |
2870 | int i; | |
2871 | ||
2872 | dw2_setup (objfile); | |
1fd400ff TT |
2873 | |
2874 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 2875 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2876 | { |
e254ef6a | 2877 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2878 | |
a0f42c21 | 2879 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2880 | } |
2881 | } | |
2882 | ||
2883 | static void | |
2884 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2885 | const char *filename) | |
2886 | { | |
2887 | int i; | |
2888 | ||
2889 | dw2_setup (objfile); | |
d4637a04 DE |
2890 | |
2891 | /* We don't need to consider type units here. | |
2892 | This is only called for examining code, e.g. expand_line_sal. | |
2893 | There can be an order of magnitude (or more) more type units | |
2894 | than comp units, and we avoid them if we can. */ | |
2895 | ||
2896 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
2897 | { |
2898 | int j; | |
e254ef6a | 2899 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2900 | struct quick_file_names *file_data; |
9291a0cd | 2901 | |
3d7bb9d9 | 2902 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2903 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2904 | continue; |
2905 | ||
7b9f3c50 DE |
2906 | file_data = dw2_get_file_names (objfile, per_cu); |
2907 | if (file_data == NULL) | |
9291a0cd TT |
2908 | continue; |
2909 | ||
7b9f3c50 | 2910 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2911 | { |
7b9f3c50 | 2912 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 2913 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 2914 | { |
a0f42c21 | 2915 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2916 | break; |
2917 | } | |
2918 | } | |
2919 | } | |
2920 | } | |
2921 | ||
356d9f9d TT |
2922 | /* A helper function for dw2_find_symbol_file that finds the primary |
2923 | file name for a given CU. This is a die_reader_func. */ | |
2924 | ||
2925 | static void | |
2926 | dw2_get_primary_filename_reader (const struct die_reader_specs *reader, | |
2927 | gdb_byte *info_ptr, | |
2928 | struct die_info *comp_unit_die, | |
2929 | int has_children, | |
2930 | void *data) | |
2931 | { | |
2932 | const char **result_ptr = data; | |
2933 | struct dwarf2_cu *cu = reader->cu; | |
2934 | struct attribute *attr; | |
2935 | ||
2936 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu); | |
2937 | if (attr == NULL) | |
2938 | *result_ptr = NULL; | |
2939 | else | |
2940 | *result_ptr = DW_STRING (attr); | |
2941 | } | |
2942 | ||
dd786858 | 2943 | static const char * |
9291a0cd TT |
2944 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2945 | { | |
e254ef6a | 2946 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 2947 | offset_type *vec; |
7b9f3c50 | 2948 | struct quick_file_names *file_data; |
356d9f9d | 2949 | const char *filename; |
9291a0cd TT |
2950 | |
2951 | dw2_setup (objfile); | |
2952 | ||
ae2de4f8 | 2953 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd | 2954 | if (!dwarf2_per_objfile->index_table) |
96408a79 SA |
2955 | { |
2956 | struct symtab *s; | |
2957 | ||
d790cf0a DE |
2958 | ALL_OBJFILE_PRIMARY_SYMTABS (objfile, s) |
2959 | { | |
2960 | struct blockvector *bv = BLOCKVECTOR (s); | |
2961 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
2962 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); | |
2963 | ||
2964 | if (sym) | |
2965 | return sym->symtab->filename; | |
2966 | } | |
96408a79 SA |
2967 | return NULL; |
2968 | } | |
9291a0cd TT |
2969 | |
2970 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2971 | name, &vec)) | |
2972 | return NULL; | |
2973 | ||
2974 | /* Note that this just looks at the very first one named NAME -- but | |
2975 | actually we are looking for a function. find_main_filename | |
2976 | should be rewritten so that it doesn't require a custom hook. It | |
2977 | could just use the ordinary symbol tables. */ | |
2978 | /* vec[0] is the length, which must always be >0. */ | |
156942c7 | 2979 | per_cu = dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec[1]))); |
9291a0cd | 2980 | |
356d9f9d TT |
2981 | if (per_cu->v.quick->symtab != NULL) |
2982 | return per_cu->v.quick->symtab->filename; | |
2983 | ||
663b969e TT |
2984 | init_cutu_and_read_dies (per_cu, 0, 0, dw2_get_primary_filename_reader, |
2985 | &filename); | |
9291a0cd | 2986 | |
356d9f9d | 2987 | return filename; |
9291a0cd TT |
2988 | } |
2989 | ||
2990 | static void | |
40658b94 PH |
2991 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
2992 | struct objfile *objfile, int global, | |
2993 | int (*callback) (struct block *, | |
2994 | struct symbol *, void *), | |
2edb89d3 JK |
2995 | void *data, symbol_compare_ftype *match, |
2996 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 2997 | { |
40658b94 | 2998 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
2999 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
3000 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
3001 | } |
3002 | ||
3003 | static void | |
f8eba3c6 TT |
3004 | dw2_expand_symtabs_matching |
3005 | (struct objfile *objfile, | |
3006 | int (*file_matcher) (const char *, void *), | |
e078317b | 3007 | int (*name_matcher) (const char *, void *), |
f8eba3c6 TT |
3008 | enum search_domain kind, |
3009 | void *data) | |
9291a0cd TT |
3010 | { |
3011 | int i; | |
3012 | offset_type iter; | |
4b5246aa | 3013 | struct mapped_index *index; |
9291a0cd TT |
3014 | |
3015 | dw2_setup (objfile); | |
ae2de4f8 DE |
3016 | |
3017 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
3018 | if (!dwarf2_per_objfile->index_table) |
3019 | return; | |
4b5246aa | 3020 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 3021 | |
7b08b9eb | 3022 | if (file_matcher != NULL) |
24c79950 TT |
3023 | { |
3024 | struct cleanup *cleanup; | |
3025 | htab_t visited_found, visited_not_found; | |
3026 | ||
3027 | visited_found = htab_create_alloc (10, | |
3028 | htab_hash_pointer, htab_eq_pointer, | |
3029 | NULL, xcalloc, xfree); | |
3030 | cleanup = make_cleanup_htab_delete (visited_found); | |
3031 | visited_not_found = htab_create_alloc (10, | |
3032 | htab_hash_pointer, htab_eq_pointer, | |
3033 | NULL, xcalloc, xfree); | |
3034 | make_cleanup_htab_delete (visited_not_found); | |
3035 | ||
3036 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
3037 | + dwarf2_per_objfile->n_type_units); ++i) | |
3038 | { | |
3039 | int j; | |
3040 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
3041 | struct quick_file_names *file_data; | |
3042 | void **slot; | |
7b08b9eb | 3043 | |
24c79950 | 3044 | per_cu->v.quick->mark = 0; |
3d7bb9d9 | 3045 | |
24c79950 TT |
3046 | /* We only need to look at symtabs not already expanded. */ |
3047 | if (per_cu->v.quick->symtab) | |
3048 | continue; | |
7b08b9eb | 3049 | |
24c79950 TT |
3050 | file_data = dw2_get_file_names (objfile, per_cu); |
3051 | if (file_data == NULL) | |
3052 | continue; | |
7b08b9eb | 3053 | |
24c79950 TT |
3054 | if (htab_find (visited_not_found, file_data) != NULL) |
3055 | continue; | |
3056 | else if (htab_find (visited_found, file_data) != NULL) | |
3057 | { | |
3058 | per_cu->v.quick->mark = 1; | |
3059 | continue; | |
3060 | } | |
3061 | ||
3062 | for (j = 0; j < file_data->num_file_names; ++j) | |
3063 | { | |
3064 | if (file_matcher (file_data->file_names[j], data)) | |
3065 | { | |
3066 | per_cu->v.quick->mark = 1; | |
3067 | break; | |
3068 | } | |
3069 | } | |
3070 | ||
3071 | slot = htab_find_slot (per_cu->v.quick->mark | |
3072 | ? visited_found | |
3073 | : visited_not_found, | |
3074 | file_data, INSERT); | |
3075 | *slot = file_data; | |
3076 | } | |
3077 | ||
3078 | do_cleanups (cleanup); | |
3079 | } | |
9291a0cd | 3080 | |
3876f04e | 3081 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
3082 | { |
3083 | offset_type idx = 2 * iter; | |
3084 | const char *name; | |
3085 | offset_type *vec, vec_len, vec_idx; | |
3086 | ||
3876f04e | 3087 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
3088 | continue; |
3089 | ||
3876f04e | 3090 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd | 3091 | |
e078317b | 3092 | if (! (*name_matcher) (name, data)) |
9291a0cd TT |
3093 | continue; |
3094 | ||
3095 | /* The name was matched, now expand corresponding CUs that were | |
3096 | marked. */ | |
4b5246aa | 3097 | vec = (offset_type *) (index->constant_pool |
3876f04e | 3098 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
3099 | vec_len = MAYBE_SWAP (vec[0]); |
3100 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
3101 | { | |
e254ef6a | 3102 | struct dwarf2_per_cu_data *per_cu; |
156942c7 DE |
3103 | offset_type cu_index_and_attrs = MAYBE_SWAP (vec[vec_idx + 1]); |
3104 | gdb_index_symbol_kind symbol_kind = | |
3105 | GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs); | |
3106 | int cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs); | |
3107 | ||
3108 | /* Don't crash on bad data. */ | |
3109 | if (cu_index >= (dwarf2_per_objfile->n_comp_units | |
3110 | + dwarf2_per_objfile->n_comp_units)) | |
3111 | continue; | |
1fd400ff | 3112 | |
156942c7 DE |
3113 | /* Only check the symbol's kind if it has one. |
3114 | Indices prior to version 7 don't record it. */ | |
3115 | if (index->version >= 7) | |
3116 | { | |
3117 | switch (kind) | |
3118 | { | |
3119 | case VARIABLES_DOMAIN: | |
3120 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE) | |
3121 | continue; | |
3122 | break; | |
3123 | case FUNCTIONS_DOMAIN: | |
3124 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION) | |
3125 | continue; | |
3126 | break; | |
3127 | case TYPES_DOMAIN: | |
3128 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) | |
3129 | continue; | |
3130 | break; | |
3131 | default: | |
3132 | break; | |
3133 | } | |
3134 | } | |
3135 | ||
3136 | per_cu = dw2_get_cu (cu_index); | |
7b08b9eb | 3137 | if (file_matcher == NULL || per_cu->v.quick->mark) |
a0f42c21 | 3138 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
3139 | } |
3140 | } | |
3141 | } | |
3142 | ||
9703b513 TT |
3143 | /* A helper for dw2_find_pc_sect_symtab which finds the most specific |
3144 | symtab. */ | |
3145 | ||
3146 | static struct symtab * | |
3147 | recursively_find_pc_sect_symtab (struct symtab *symtab, CORE_ADDR pc) | |
3148 | { | |
3149 | int i; | |
3150 | ||
3151 | if (BLOCKVECTOR (symtab) != NULL | |
3152 | && blockvector_contains_pc (BLOCKVECTOR (symtab), pc)) | |
3153 | return symtab; | |
3154 | ||
a3ec0bb1 DE |
3155 | if (symtab->includes == NULL) |
3156 | return NULL; | |
3157 | ||
9703b513 TT |
3158 | for (i = 0; symtab->includes[i]; ++i) |
3159 | { | |
a3ec0bb1 | 3160 | struct symtab *s = symtab->includes[i]; |
9703b513 TT |
3161 | |
3162 | s = recursively_find_pc_sect_symtab (s, pc); | |
3163 | if (s != NULL) | |
3164 | return s; | |
3165 | } | |
3166 | ||
3167 | return NULL; | |
3168 | } | |
3169 | ||
9291a0cd TT |
3170 | static struct symtab * |
3171 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
3172 | struct minimal_symbol *msymbol, | |
3173 | CORE_ADDR pc, | |
3174 | struct obj_section *section, | |
3175 | int warn_if_readin) | |
3176 | { | |
3177 | struct dwarf2_per_cu_data *data; | |
9703b513 | 3178 | struct symtab *result; |
9291a0cd TT |
3179 | |
3180 | dw2_setup (objfile); | |
3181 | ||
3182 | if (!objfile->psymtabs_addrmap) | |
3183 | return NULL; | |
3184 | ||
3185 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
3186 | if (!data) | |
3187 | return NULL; | |
3188 | ||
3189 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 3190 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
3191 | paddress (get_objfile_arch (objfile), pc)); |
3192 | ||
9703b513 TT |
3193 | result = recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data), pc); |
3194 | gdb_assert (result != NULL); | |
3195 | return result; | |
9291a0cd TT |
3196 | } |
3197 | ||
9291a0cd | 3198 | static void |
44b13c5a | 3199 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
74e2f255 | 3200 | void *data, int need_fullname) |
9291a0cd TT |
3201 | { |
3202 | int i; | |
24c79950 TT |
3203 | struct cleanup *cleanup; |
3204 | htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer, | |
3205 | NULL, xcalloc, xfree); | |
9291a0cd | 3206 | |
24c79950 | 3207 | cleanup = make_cleanup_htab_delete (visited); |
9291a0cd | 3208 | dw2_setup (objfile); |
ae2de4f8 | 3209 | |
24c79950 TT |
3210 | /* We can ignore file names coming from already-expanded CUs. */ |
3211 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
3212 | + dwarf2_per_objfile->n_type_units); ++i) | |
3213 | { | |
3214 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
3215 | ||
3216 | if (per_cu->v.quick->symtab) | |
3217 | { | |
3218 | void **slot = htab_find_slot (visited, per_cu->v.quick->file_names, | |
3219 | INSERT); | |
3220 | ||
3221 | *slot = per_cu->v.quick->file_names; | |
3222 | } | |
3223 | } | |
3224 | ||
1fd400ff | 3225 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 3226 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
3227 | { |
3228 | int j; | |
e254ef6a | 3229 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 3230 | struct quick_file_names *file_data; |
24c79950 | 3231 | void **slot; |
9291a0cd | 3232 | |
3d7bb9d9 | 3233 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 3234 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
3235 | continue; |
3236 | ||
7b9f3c50 DE |
3237 | file_data = dw2_get_file_names (objfile, per_cu); |
3238 | if (file_data == NULL) | |
9291a0cd TT |
3239 | continue; |
3240 | ||
24c79950 TT |
3241 | slot = htab_find_slot (visited, file_data, INSERT); |
3242 | if (*slot) | |
3243 | { | |
3244 | /* Already visited. */ | |
3245 | continue; | |
3246 | } | |
3247 | *slot = file_data; | |
3248 | ||
7b9f3c50 | 3249 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 3250 | { |
74e2f255 DE |
3251 | const char *this_real_name; |
3252 | ||
3253 | if (need_fullname) | |
3254 | this_real_name = dw2_get_real_path (objfile, file_data, j); | |
3255 | else | |
3256 | this_real_name = NULL; | |
7b9f3c50 | 3257 | (*fun) (file_data->file_names[j], this_real_name, data); |
9291a0cd TT |
3258 | } |
3259 | } | |
24c79950 TT |
3260 | |
3261 | do_cleanups (cleanup); | |
9291a0cd TT |
3262 | } |
3263 | ||
3264 | static int | |
3265 | dw2_has_symbols (struct objfile *objfile) | |
3266 | { | |
3267 | return 1; | |
3268 | } | |
3269 | ||
3270 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
3271 | { | |
3272 | dw2_has_symbols, | |
3273 | dw2_find_last_source_symtab, | |
3274 | dw2_forget_cached_source_info, | |
f8eba3c6 | 3275 | dw2_map_symtabs_matching_filename, |
9291a0cd | 3276 | dw2_lookup_symbol, |
774b6a14 | 3277 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
3278 | dw2_print_stats, |
3279 | dw2_dump, | |
3280 | dw2_relocate, | |
3281 | dw2_expand_symtabs_for_function, | |
3282 | dw2_expand_all_symtabs, | |
3283 | dw2_expand_symtabs_with_filename, | |
3284 | dw2_find_symbol_file, | |
40658b94 | 3285 | dw2_map_matching_symbols, |
9291a0cd TT |
3286 | dw2_expand_symtabs_matching, |
3287 | dw2_find_pc_sect_symtab, | |
9291a0cd TT |
3288 | dw2_map_symbol_filenames |
3289 | }; | |
3290 | ||
3291 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
3292 | file will use psymtabs, or 1 if using the GNU index. */ | |
3293 | ||
3294 | int | |
3295 | dwarf2_initialize_objfile (struct objfile *objfile) | |
3296 | { | |
3297 | /* If we're about to read full symbols, don't bother with the | |
3298 | indices. In this case we also don't care if some other debug | |
3299 | format is making psymtabs, because they are all about to be | |
3300 | expanded anyway. */ | |
3301 | if ((objfile->flags & OBJF_READNOW)) | |
3302 | { | |
3303 | int i; | |
3304 | ||
3305 | dwarf2_per_objfile->using_index = 1; | |
3306 | create_all_comp_units (objfile); | |
0e50663e | 3307 | create_all_type_units (objfile); |
7b9f3c50 DE |
3308 | dwarf2_per_objfile->quick_file_names_table = |
3309 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 3310 | |
1fd400ff | 3311 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 3312 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 3313 | { |
e254ef6a | 3314 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 3315 | |
e254ef6a DE |
3316 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
3317 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
3318 | } |
3319 | ||
3320 | /* Return 1 so that gdb sees the "quick" functions. However, | |
3321 | these functions will be no-ops because we will have expanded | |
3322 | all symtabs. */ | |
3323 | return 1; | |
3324 | } | |
3325 | ||
3326 | if (dwarf2_read_index (objfile)) | |
3327 | return 1; | |
3328 | ||
9291a0cd TT |
3329 | return 0; |
3330 | } | |
3331 | ||
3332 | \f | |
3333 | ||
dce234bc PP |
3334 | /* Build a partial symbol table. */ |
3335 | ||
3336 | void | |
f29dff0a | 3337 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 3338 | { |
f29dff0a | 3339 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
3340 | { |
3341 | init_psymbol_list (objfile, 1024); | |
3342 | } | |
3343 | ||
d146bf1e | 3344 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 3345 | } |
c906108c | 3346 | |
45452591 DE |
3347 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
3348 | ||
3349 | static inline int | |
b64f50a1 | 3350 | offset_in_cu_p (const struct comp_unit_head *cu_header, sect_offset offset) |
45452591 | 3351 | { |
b64f50a1 JK |
3352 | sect_offset bottom = { cu_header->offset.sect_off }; |
3353 | sect_offset top = { (cu_header->offset.sect_off + cu_header->length | |
3354 | + cu_header->initial_length_size) }; | |
9a619af0 | 3355 | |
b64f50a1 | 3356 | return (offset.sect_off >= bottom.sect_off && offset.sect_off < top.sect_off); |
45452591 DE |
3357 | } |
3358 | ||
93311388 DE |
3359 | /* Read in the comp unit header information from the debug_info at info_ptr. |
3360 | NOTE: This leaves members offset, first_die_offset to be filled in | |
3361 | by the caller. */ | |
107d2387 | 3362 | |
fe1b8b76 | 3363 | static gdb_byte * |
107d2387 | 3364 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 3365 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
3366 | { |
3367 | int signed_addr; | |
891d2f0b | 3368 | unsigned int bytes_read; |
c764a876 DE |
3369 | |
3370 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
3371 | cu_header->initial_length_size = bytes_read; | |
3372 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 3373 | info_ptr += bytes_read; |
107d2387 AC |
3374 | cu_header->version = read_2_bytes (abfd, info_ptr); |
3375 | info_ptr += 2; | |
b64f50a1 JK |
3376 | cu_header->abbrev_offset.sect_off = read_offset (abfd, info_ptr, cu_header, |
3377 | &bytes_read); | |
613e1657 | 3378 | info_ptr += bytes_read; |
107d2387 AC |
3379 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
3380 | info_ptr += 1; | |
3381 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
3382 | if (signed_addr < 0) | |
8e65ff28 | 3383 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3384 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 3385 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 3386 | |
107d2387 AC |
3387 | return info_ptr; |
3388 | } | |
3389 | ||
9ff913ba DE |
3390 | /* Subroutine of read_and_check_comp_unit_head and |
3391 | read_and_check_type_unit_head to simplify them. | |
3392 | Perform various error checking on the header. */ | |
3393 | ||
3394 | static void | |
3395 | error_check_comp_unit_head (struct comp_unit_head *header, | |
4bdcc0c1 DE |
3396 | struct dwarf2_section_info *section, |
3397 | struct dwarf2_section_info *abbrev_section) | |
9ff913ba DE |
3398 | { |
3399 | bfd *abfd = section->asection->owner; | |
3400 | const char *filename = bfd_get_filename (abfd); | |
3401 | ||
3402 | if (header->version != 2 && header->version != 3 && header->version != 4) | |
3403 | error (_("Dwarf Error: wrong version in compilation unit header " | |
3404 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, | |
3405 | filename); | |
3406 | ||
b64f50a1 | 3407 | if (header->abbrev_offset.sect_off |
9ff913ba DE |
3408 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, |
3409 | &dwarf2_per_objfile->abbrev)) | |
3410 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " | |
3411 | "(offset 0x%lx + 6) [in module %s]"), | |
b64f50a1 | 3412 | (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off, |
9ff913ba DE |
3413 | filename); |
3414 | ||
3415 | /* Cast to unsigned long to use 64-bit arithmetic when possible to | |
3416 | avoid potential 32-bit overflow. */ | |
b64f50a1 | 3417 | if (((unsigned long) header->offset.sect_off |
9ff913ba DE |
3418 | + header->length + header->initial_length_size) |
3419 | > section->size) | |
3420 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " | |
3421 | "(offset 0x%lx + 0) [in module %s]"), | |
b64f50a1 | 3422 | (long) header->length, (long) header->offset.sect_off, |
9ff913ba DE |
3423 | filename); |
3424 | } | |
3425 | ||
3426 | /* Read in a CU/TU header and perform some basic error checking. | |
3427 | The contents of the header are stored in HEADER. | |
3428 | The result is a pointer to the start of the first DIE. */ | |
adabb602 | 3429 | |
fe1b8b76 | 3430 | static gdb_byte * |
9ff913ba DE |
3431 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
3432 | struct dwarf2_section_info *section, | |
4bdcc0c1 | 3433 | struct dwarf2_section_info *abbrev_section, |
9ff913ba DE |
3434 | gdb_byte *info_ptr, |
3435 | int is_debug_types_section) | |
72bf9492 | 3436 | { |
fe1b8b76 | 3437 | gdb_byte *beg_of_comp_unit = info_ptr; |
9ff913ba | 3438 | bfd *abfd = section->asection->owner; |
72bf9492 | 3439 | |
b64f50a1 | 3440 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
adabb602 | 3441 | |
72bf9492 DJ |
3442 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
3443 | ||
460c1c54 CC |
3444 | /* If we're reading a type unit, skip over the signature and |
3445 | type_offset fields. */ | |
b0df02fd | 3446 | if (is_debug_types_section) |
460c1c54 CC |
3447 | info_ptr += 8 /*signature*/ + header->offset_size; |
3448 | ||
b64f50a1 | 3449 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
adabb602 | 3450 | |
4bdcc0c1 | 3451 | error_check_comp_unit_head (header, section, abbrev_section); |
72bf9492 DJ |
3452 | |
3453 | return info_ptr; | |
3454 | } | |
3455 | ||
348e048f DE |
3456 | /* Read in the types comp unit header information from .debug_types entry at |
3457 | types_ptr. The result is a pointer to one past the end of the header. */ | |
3458 | ||
3459 | static gdb_byte * | |
9ff913ba DE |
3460 | read_and_check_type_unit_head (struct comp_unit_head *header, |
3461 | struct dwarf2_section_info *section, | |
4bdcc0c1 | 3462 | struct dwarf2_section_info *abbrev_section, |
9ff913ba | 3463 | gdb_byte *info_ptr, |
dee91e82 DE |
3464 | ULONGEST *signature, |
3465 | cu_offset *type_offset_in_tu) | |
348e048f | 3466 | { |
9ff913ba DE |
3467 | gdb_byte *beg_of_comp_unit = info_ptr; |
3468 | bfd *abfd = section->asection->owner; | |
348e048f | 3469 | |
b64f50a1 | 3470 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
348e048f | 3471 | |
9ff913ba | 3472 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
348e048f | 3473 | |
9ff913ba DE |
3474 | /* If we're reading a type unit, skip over the signature and |
3475 | type_offset fields. */ | |
3476 | if (signature != NULL) | |
3477 | *signature = read_8_bytes (abfd, info_ptr); | |
3478 | info_ptr += 8; | |
dee91e82 DE |
3479 | if (type_offset_in_tu != NULL) |
3480 | type_offset_in_tu->cu_off = read_offset_1 (abfd, info_ptr, | |
3481 | header->offset_size); | |
9ff913ba DE |
3482 | info_ptr += header->offset_size; |
3483 | ||
b64f50a1 | 3484 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
348e048f | 3485 | |
4bdcc0c1 | 3486 | error_check_comp_unit_head (header, section, abbrev_section); |
9ff913ba DE |
3487 | |
3488 | return info_ptr; | |
348e048f DE |
3489 | } |
3490 | ||
aaa75496 JB |
3491 | /* Allocate a new partial symtab for file named NAME and mark this new |
3492 | partial symtab as being an include of PST. */ | |
3493 | ||
3494 | static void | |
3495 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
3496 | struct objfile *objfile) | |
3497 | { | |
3498 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
3499 | ||
3500 | subpst->section_offsets = pst->section_offsets; | |
3501 | subpst->textlow = 0; | |
3502 | subpst->texthigh = 0; | |
3503 | ||
3504 | subpst->dependencies = (struct partial_symtab **) | |
3505 | obstack_alloc (&objfile->objfile_obstack, | |
3506 | sizeof (struct partial_symtab *)); | |
3507 | subpst->dependencies[0] = pst; | |
3508 | subpst->number_of_dependencies = 1; | |
3509 | ||
3510 | subpst->globals_offset = 0; | |
3511 | subpst->n_global_syms = 0; | |
3512 | subpst->statics_offset = 0; | |
3513 | subpst->n_static_syms = 0; | |
3514 | subpst->symtab = NULL; | |
3515 | subpst->read_symtab = pst->read_symtab; | |
3516 | subpst->readin = 0; | |
3517 | ||
3518 | /* No private part is necessary for include psymtabs. This property | |
3519 | can be used to differentiate between such include psymtabs and | |
10b3939b | 3520 | the regular ones. */ |
58a9656e | 3521 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
3522 | } |
3523 | ||
3524 | /* Read the Line Number Program data and extract the list of files | |
3525 | included by the source file represented by PST. Build an include | |
d85a05f0 | 3526 | partial symtab for each of these included files. */ |
aaa75496 JB |
3527 | |
3528 | static void | |
3529 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
dee91e82 DE |
3530 | struct die_info *die, |
3531 | struct partial_symtab *pst) | |
aaa75496 | 3532 | { |
d85a05f0 DJ |
3533 | struct line_header *lh = NULL; |
3534 | struct attribute *attr; | |
aaa75496 | 3535 | |
d85a05f0 DJ |
3536 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
3537 | if (attr) | |
3019eac3 | 3538 | lh = dwarf_decode_line_header (DW_UNSND (attr), cu); |
aaa75496 JB |
3539 | if (lh == NULL) |
3540 | return; /* No linetable, so no includes. */ | |
3541 | ||
c6da4cef | 3542 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
f3f5162e | 3543 | dwarf_decode_lines (lh, pst->dirname, cu, pst, 1); |
aaa75496 JB |
3544 | |
3545 | free_line_header (lh); | |
3546 | } | |
3547 | ||
348e048f | 3548 | static hashval_t |
52dc124a | 3549 | hash_signatured_type (const void *item) |
348e048f | 3550 | { |
52dc124a | 3551 | const struct signatured_type *sig_type = item; |
9a619af0 | 3552 | |
348e048f | 3553 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
52dc124a | 3554 | return sig_type->signature; |
348e048f DE |
3555 | } |
3556 | ||
3557 | static int | |
52dc124a | 3558 | eq_signatured_type (const void *item_lhs, const void *item_rhs) |
348e048f DE |
3559 | { |
3560 | const struct signatured_type *lhs = item_lhs; | |
3561 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 3562 | |
348e048f DE |
3563 | return lhs->signature == rhs->signature; |
3564 | } | |
3565 | ||
1fd400ff TT |
3566 | /* Allocate a hash table for signatured types. */ |
3567 | ||
3568 | static htab_t | |
673bfd45 | 3569 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
3570 | { |
3571 | return htab_create_alloc_ex (41, | |
52dc124a DE |
3572 | hash_signatured_type, |
3573 | eq_signatured_type, | |
1fd400ff TT |
3574 | NULL, |
3575 | &objfile->objfile_obstack, | |
3576 | hashtab_obstack_allocate, | |
3577 | dummy_obstack_deallocate); | |
3578 | } | |
3579 | ||
d467dd73 | 3580 | /* A helper function to add a signatured type CU to a table. */ |
1fd400ff TT |
3581 | |
3582 | static int | |
d467dd73 | 3583 | add_signatured_type_cu_to_table (void **slot, void *datum) |
1fd400ff TT |
3584 | { |
3585 | struct signatured_type *sigt = *slot; | |
3586 | struct dwarf2_per_cu_data ***datap = datum; | |
3587 | ||
3588 | **datap = &sigt->per_cu; | |
3589 | ++*datap; | |
3590 | ||
3591 | return 1; | |
3592 | } | |
3593 | ||
3019eac3 DE |
3594 | /* Create the hash table of all entries in the .debug_types section. |
3595 | DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise. | |
3596 | The result is a pointer to the hash table or NULL if there are | |
3597 | no types. */ | |
348e048f | 3598 | |
3019eac3 DE |
3599 | static htab_t |
3600 | create_debug_types_hash_table (struct dwo_file *dwo_file, | |
3601 | VEC (dwarf2_section_info_def) *types) | |
348e048f | 3602 | { |
3019eac3 | 3603 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
8b70b953 | 3604 | htab_t types_htab = NULL; |
8b70b953 TT |
3605 | int ix; |
3606 | struct dwarf2_section_info *section; | |
4bdcc0c1 | 3607 | struct dwarf2_section_info *abbrev_section; |
348e048f | 3608 | |
3019eac3 DE |
3609 | if (VEC_empty (dwarf2_section_info_def, types)) |
3610 | return NULL; | |
348e048f | 3611 | |
4bdcc0c1 DE |
3612 | abbrev_section = (dwo_file != NULL |
3613 | ? &dwo_file->sections.abbrev | |
3614 | : &dwarf2_per_objfile->abbrev); | |
3615 | ||
8b70b953 | 3616 | for (ix = 0; |
3019eac3 | 3617 | VEC_iterate (dwarf2_section_info_def, types, ix, section); |
8b70b953 TT |
3618 | ++ix) |
3619 | { | |
3019eac3 | 3620 | bfd *abfd; |
8b70b953 | 3621 | gdb_byte *info_ptr, *end_ptr; |
348e048f | 3622 | |
8b70b953 TT |
3623 | dwarf2_read_section (objfile, section); |
3624 | info_ptr = section->buffer; | |
348e048f | 3625 | |
8b70b953 TT |
3626 | if (info_ptr == NULL) |
3627 | continue; | |
348e048f | 3628 | |
3019eac3 DE |
3629 | /* We can't set abfd until now because the section may be empty or |
3630 | not present, in which case section->asection will be NULL. */ | |
3631 | abfd = section->asection->owner; | |
3632 | ||
8b70b953 | 3633 | if (types_htab == NULL) |
3019eac3 DE |
3634 | { |
3635 | if (dwo_file) | |
3636 | types_htab = allocate_dwo_unit_table (objfile); | |
3637 | else | |
3638 | types_htab = allocate_signatured_type_table (objfile); | |
3639 | } | |
348e048f | 3640 | |
8b70b953 | 3641 | if (dwarf2_die_debug) |
dee91e82 DE |
3642 | fprintf_unfiltered (gdb_stdlog, "Reading signatured types for %s:\n", |
3643 | bfd_get_filename (abfd)); | |
3644 | ||
3645 | /* We don't use init_cutu_and_read_dies_simple, or some such, here | |
3646 | because we don't need to read any dies: the signature is in the | |
3647 | header. */ | |
8b70b953 TT |
3648 | |
3649 | end_ptr = info_ptr + section->size; | |
3650 | while (info_ptr < end_ptr) | |
3651 | { | |
b64f50a1 | 3652 | sect_offset offset; |
3019eac3 | 3653 | cu_offset type_offset_in_tu; |
8b70b953 | 3654 | ULONGEST signature; |
52dc124a | 3655 | struct signatured_type *sig_type; |
3019eac3 | 3656 | struct dwo_unit *dwo_tu; |
8b70b953 TT |
3657 | void **slot; |
3658 | gdb_byte *ptr = info_ptr; | |
9ff913ba | 3659 | struct comp_unit_head header; |
dee91e82 | 3660 | unsigned int length; |
348e048f | 3661 | |
b64f50a1 | 3662 | offset.sect_off = ptr - section->buffer; |
348e048f | 3663 | |
8b70b953 | 3664 | /* We need to read the type's signature in order to build the hash |
9ff913ba | 3665 | table, but we don't need anything else just yet. */ |
348e048f | 3666 | |
4bdcc0c1 DE |
3667 | ptr = read_and_check_type_unit_head (&header, section, |
3668 | abbrev_section, ptr, | |
3019eac3 | 3669 | &signature, &type_offset_in_tu); |
6caca83c | 3670 | |
dee91e82 DE |
3671 | length = header.initial_length_size + header.length; |
3672 | ||
6caca83c | 3673 | /* Skip dummy type units. */ |
dee91e82 DE |
3674 | if (ptr >= info_ptr + length |
3675 | || peek_abbrev_code (abfd, ptr) == 0) | |
6caca83c | 3676 | { |
dee91e82 | 3677 | info_ptr += header.initial_length_size + header.length; |
6caca83c CC |
3678 | continue; |
3679 | } | |
8b70b953 | 3680 | |
3019eac3 DE |
3681 | if (dwo_file) |
3682 | { | |
3683 | sig_type = NULL; | |
3684 | dwo_tu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
3685 | struct dwo_unit); | |
3686 | dwo_tu->dwo_file = dwo_file; | |
3687 | dwo_tu->signature = signature; | |
3688 | dwo_tu->type_offset_in_tu = type_offset_in_tu; | |
3689 | dwo_tu->info_or_types_section = section; | |
3690 | dwo_tu->offset = offset; | |
3691 | dwo_tu->length = length; | |
3692 | } | |
3693 | else | |
3694 | { | |
3695 | /* N.B.: type_offset is not usable if this type uses a DWO file. | |
3696 | The real type_offset is in the DWO file. */ | |
3697 | dwo_tu = NULL; | |
3698 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
3699 | struct signatured_type); | |
3700 | sig_type->signature = signature; | |
3701 | sig_type->type_offset_in_tu = type_offset_in_tu; | |
3702 | sig_type->per_cu.objfile = objfile; | |
3703 | sig_type->per_cu.is_debug_types = 1; | |
3704 | sig_type->per_cu.info_or_types_section = section; | |
3705 | sig_type->per_cu.offset = offset; | |
3706 | sig_type->per_cu.length = length; | |
3707 | } | |
8b70b953 | 3708 | |
3019eac3 DE |
3709 | slot = htab_find_slot (types_htab, |
3710 | dwo_file ? (void*) dwo_tu : (void *) sig_type, | |
3711 | INSERT); | |
8b70b953 TT |
3712 | gdb_assert (slot != NULL); |
3713 | if (*slot != NULL) | |
3714 | { | |
3019eac3 DE |
3715 | sect_offset dup_offset; |
3716 | ||
3717 | if (dwo_file) | |
3718 | { | |
3719 | const struct dwo_unit *dup_tu = *slot; | |
3720 | ||
3721 | dup_offset = dup_tu->offset; | |
3722 | } | |
3723 | else | |
3724 | { | |
3725 | const struct signatured_type *dup_tu = *slot; | |
3726 | ||
3727 | dup_offset = dup_tu->per_cu.offset; | |
3728 | } | |
b3c8eb43 | 3729 | |
8b70b953 TT |
3730 | complaint (&symfile_complaints, |
3731 | _("debug type entry at offset 0x%x is duplicate to the " | |
3732 | "entry at offset 0x%x, signature 0x%s"), | |
3019eac3 | 3733 | offset.sect_off, dup_offset.sect_off, |
8b70b953 | 3734 | phex (signature, sizeof (signature))); |
8b70b953 | 3735 | } |
3019eac3 | 3736 | *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type; |
348e048f | 3737 | |
8b70b953 TT |
3738 | if (dwarf2_die_debug) |
3739 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
b64f50a1 JK |
3740 | offset.sect_off, |
3741 | phex (signature, sizeof (signature))); | |
348e048f | 3742 | |
dee91e82 | 3743 | info_ptr += length; |
8b70b953 | 3744 | } |
348e048f DE |
3745 | } |
3746 | ||
3019eac3 DE |
3747 | return types_htab; |
3748 | } | |
3749 | ||
3750 | /* Create the hash table of all entries in the .debug_types section, | |
3751 | and initialize all_type_units. | |
3752 | The result is zero if there is an error (e.g. missing .debug_types section), | |
3753 | otherwise non-zero. */ | |
3754 | ||
3755 | static int | |
3756 | create_all_type_units (struct objfile *objfile) | |
3757 | { | |
3758 | htab_t types_htab; | |
3759 | struct dwarf2_per_cu_data **iter; | |
3760 | ||
3761 | types_htab = create_debug_types_hash_table (NULL, dwarf2_per_objfile->types); | |
3762 | if (types_htab == NULL) | |
3763 | { | |
3764 | dwarf2_per_objfile->signatured_types = NULL; | |
3765 | return 0; | |
3766 | } | |
3767 | ||
348e048f DE |
3768 | dwarf2_per_objfile->signatured_types = types_htab; |
3769 | ||
d467dd73 DE |
3770 | dwarf2_per_objfile->n_type_units = htab_elements (types_htab); |
3771 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 3772 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 3773 | dwarf2_per_objfile->n_type_units |
1fd400ff | 3774 | * sizeof (struct dwarf2_per_cu_data *)); |
d467dd73 DE |
3775 | iter = &dwarf2_per_objfile->all_type_units[0]; |
3776 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); | |
3777 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] | |
3778 | == dwarf2_per_objfile->n_type_units); | |
1fd400ff | 3779 | |
348e048f DE |
3780 | return 1; |
3781 | } | |
3782 | ||
380bca97 | 3783 | /* Lookup a signature based type for DW_FORM_ref_sig8. |
e319fa28 | 3784 | Returns NULL if signature SIG is not present in the table. */ |
348e048f DE |
3785 | |
3786 | static struct signatured_type * | |
e319fa28 | 3787 | lookup_signatured_type (ULONGEST sig) |
348e048f DE |
3788 | { |
3789 | struct signatured_type find_entry, *entry; | |
3790 | ||
3791 | if (dwarf2_per_objfile->signatured_types == NULL) | |
3792 | { | |
3793 | complaint (&symfile_complaints, | |
55f1336d | 3794 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
dcc07052 | 3795 | return NULL; |
348e048f DE |
3796 | } |
3797 | ||
3798 | find_entry.signature = sig; | |
3799 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
3800 | return entry; | |
3801 | } | |
3802 | ||
d85a05f0 DJ |
3803 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
3804 | ||
3805 | static void | |
3806 | init_cu_die_reader (struct die_reader_specs *reader, | |
dee91e82 | 3807 | struct dwarf2_cu *cu, |
3019eac3 DE |
3808 | struct dwarf2_section_info *section, |
3809 | struct dwo_file *dwo_file) | |
d85a05f0 | 3810 | { |
fceca515 | 3811 | gdb_assert (section->readin && section->buffer != NULL); |
dee91e82 | 3812 | reader->abfd = section->asection->owner; |
d85a05f0 | 3813 | reader->cu = cu; |
3019eac3 | 3814 | reader->dwo_file = dwo_file; |
dee91e82 DE |
3815 | reader->die_section = section; |
3816 | reader->buffer = section->buffer; | |
f664829e | 3817 | reader->buffer_end = section->buffer + section->size; |
d85a05f0 DJ |
3818 | } |
3819 | ||
3820 | /* Find the base address of the compilation unit for range lists and | |
3821 | location lists. It will normally be specified by DW_AT_low_pc. | |
3822 | In DWARF-3 draft 4, the base address could be overridden by | |
3823 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3824 | compilation units with discontinuous ranges. */ | |
3825 | ||
3826 | static void | |
3827 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3828 | { | |
3829 | struct attribute *attr; | |
3830 | ||
3831 | cu->base_known = 0; | |
3832 | cu->base_address = 0; | |
3833 | ||
3834 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3835 | if (attr) | |
3836 | { | |
3837 | cu->base_address = DW_ADDR (attr); | |
3838 | cu->base_known = 1; | |
3839 | } | |
3840 | else | |
3841 | { | |
3842 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3843 | if (attr) | |
3844 | { | |
3845 | cu->base_address = DW_ADDR (attr); | |
3846 | cu->base_known = 1; | |
3847 | } | |
3848 | } | |
3849 | } | |
3850 | ||
fd820528 | 3851 | /* Initialize a CU (or TU) and read its DIEs. |
3019eac3 | 3852 | If the CU defers to a DWO file, read the DWO file as well. |
dee91e82 DE |
3853 | |
3854 | If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it. | |
3855 | Otherwise, a new CU is allocated with xmalloc. | |
3856 | ||
3857 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to | |
3858 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. | |
3859 | ||
3860 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
fd820528 | 3861 | linker) then DIE_READER_FUNC will not get called. */ |
aaa75496 | 3862 | |
70221824 | 3863 | static void |
fd820528 DE |
3864 | init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu, |
3865 | int use_existing_cu, int keep, | |
3866 | die_reader_func_ftype *die_reader_func, | |
3867 | void *data) | |
c906108c | 3868 | { |
dee91e82 | 3869 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
3019eac3 DE |
3870 | struct dwarf2_section_info *section = this_cu->info_or_types_section; |
3871 | bfd *abfd = section->asection->owner; | |
dee91e82 DE |
3872 | struct dwarf2_cu *cu; |
3873 | gdb_byte *begin_info_ptr, *info_ptr; | |
3874 | struct die_reader_specs reader; | |
d85a05f0 | 3875 | struct die_info *comp_unit_die; |
dee91e82 | 3876 | int has_children; |
d85a05f0 | 3877 | struct attribute *attr; |
dee91e82 DE |
3878 | struct cleanup *cleanups, *free_cu_cleanup = NULL; |
3879 | struct signatured_type *sig_type = NULL; | |
4bdcc0c1 | 3880 | struct dwarf2_section_info *abbrev_section; |
c906108c | 3881 | |
dee91e82 DE |
3882 | if (use_existing_cu) |
3883 | gdb_assert (keep); | |
23745b47 | 3884 | |
dee91e82 DE |
3885 | cleanups = make_cleanup (null_cleanup, NULL); |
3886 | ||
3887 | /* This is cheap if the section is already read in. */ | |
3888 | dwarf2_read_section (objfile, section); | |
3889 | ||
3890 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; | |
4bdcc0c1 | 3891 | abbrev_section = &dwarf2_per_objfile->abbrev; |
dee91e82 DE |
3892 | |
3893 | if (use_existing_cu && this_cu->cu != NULL) | |
3894 | { | |
3895 | cu = this_cu->cu; | |
3896 | info_ptr += cu->header.first_die_offset.cu_off; | |
3897 | } | |
3898 | else | |
3899 | { | |
3900 | /* If !use_existing_cu, this_cu->cu must be NULL. */ | |
3901 | gdb_assert (this_cu->cu == NULL); | |
3902 | ||
3903 | cu = xmalloc (sizeof (*cu)); | |
3904 | init_one_comp_unit (cu, this_cu); | |
3905 | ||
3906 | /* If an error occurs while loading, release our storage. */ | |
3907 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); | |
3908 | ||
3019eac3 | 3909 | if (this_cu->is_debug_types) |
dee91e82 DE |
3910 | { |
3911 | ULONGEST signature; | |
3912 | ||
4bdcc0c1 DE |
3913 | info_ptr = read_and_check_type_unit_head (&cu->header, section, |
3914 | abbrev_section, info_ptr, | |
dee91e82 DE |
3915 | &signature, NULL); |
3916 | ||
3917 | /* There's no way to get from PER_CU to its containing | |
3918 | struct signatured_type. | |
3919 | But we have the signature so we can use that. */ | |
3920 | sig_type = lookup_signatured_type (signature); | |
3921 | /* We've already scanned all the signatured types, | |
3922 | this must succeed. */ | |
3923 | gdb_assert (sig_type != NULL); | |
3924 | gdb_assert (&sig_type->per_cu == this_cu); | |
3925 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); | |
3926 | ||
3927 | /* LENGTH has not been set yet for type units. */ | |
3928 | this_cu->length = cu->header.length + cu->header.initial_length_size; | |
3019eac3 DE |
3929 | |
3930 | /* Establish the type offset that can be used to lookup the type. */ | |
3931 | sig_type->type_offset_in_section.sect_off = | |
3932 | this_cu->offset.sect_off + sig_type->type_offset_in_tu.cu_off; | |
dee91e82 DE |
3933 | } |
3934 | else | |
3935 | { | |
4bdcc0c1 DE |
3936 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, |
3937 | abbrev_section, | |
3938 | info_ptr, 0); | |
dee91e82 DE |
3939 | |
3940 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); | |
3941 | gdb_assert (this_cu->length | |
3942 | == cu->header.length + cu->header.initial_length_size); | |
3943 | } | |
3944 | } | |
10b3939b | 3945 | |
6caca83c | 3946 | /* Skip dummy compilation units. */ |
dee91e82 | 3947 | if (info_ptr >= begin_info_ptr + this_cu->length |
6caca83c CC |
3948 | || peek_abbrev_code (abfd, info_ptr) == 0) |
3949 | { | |
dee91e82 | 3950 | do_cleanups (cleanups); |
21b2bd31 | 3951 | return; |
6caca83c CC |
3952 | } |
3953 | ||
93311388 | 3954 | /* Read the abbrevs for this compilation unit into a table. */ |
dee91e82 DE |
3955 | if (cu->dwarf2_abbrevs == NULL) |
3956 | { | |
4bdcc0c1 | 3957 | dwarf2_read_abbrevs (cu, abbrev_section); |
dee91e82 DE |
3958 | make_cleanup (dwarf2_free_abbrev_table, cu); |
3959 | } | |
af703f96 | 3960 | |
dee91e82 | 3961 | /* Read the top level CU/TU die. */ |
3019eac3 | 3962 | init_cu_die_reader (&reader, cu, section, NULL); |
dee91e82 | 3963 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
93311388 | 3964 | |
3019eac3 DE |
3965 | /* If we have a DWO stub, process it and then read in the DWO file. |
3966 | Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains | |
3967 | a DWO CU, that this test will fail. */ | |
3968 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu); | |
3969 | if (attr) | |
3970 | { | |
3971 | char *dwo_name = DW_STRING (attr); | |
3972 | const char *comp_dir; | |
3973 | struct dwo_unit *dwo_unit; | |
3974 | ULONGEST signature; /* Or dwo_id. */ | |
3975 | struct attribute *stmt_list, *low_pc, *high_pc, *ranges; | |
3976 | int i,num_extra_attrs; | |
4bdcc0c1 | 3977 | struct dwarf2_section_info *dwo_abbrev_section; |
3019eac3 DE |
3978 | |
3979 | if (has_children) | |
3980 | error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name" | |
3981 | " has children (offset 0x%x) [in module %s]"), | |
3982 | this_cu->offset.sect_off, bfd_get_filename (abfd)); | |
3983 | ||
3984 | /* These attributes aren't processed until later: | |
3985 | DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges. | |
3986 | However, the attribute is found in the stub which we won't have later. | |
3987 | In order to not impose this complication on the rest of the code, | |
3988 | we read them here and copy them to the DWO CU/TU die. */ | |
3989 | stmt_list = low_pc = high_pc = ranges = NULL; | |
3990 | ||
3991 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the | |
3992 | DWO file. */ | |
3993 | if (! this_cu->is_debug_types) | |
3994 | stmt_list = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); | |
3995 | low_pc = dwarf2_attr (comp_unit_die, DW_AT_low_pc, cu); | |
3996 | high_pc = dwarf2_attr (comp_unit_die, DW_AT_high_pc, cu); | |
3997 | ranges = dwarf2_attr (comp_unit_die, DW_AT_ranges, cu); | |
3998 | ||
3999 | /* There should be a DW_AT_addr_base attribute here (if needed). | |
4000 | We need the value before we can process DW_FORM_GNU_addr_index. */ | |
4001 | cu->addr_base = 0; | |
3019eac3 DE |
4002 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_addr_base, cu); |
4003 | if (attr) | |
2e3cf129 DE |
4004 | cu->addr_base = DW_UNSND (attr); |
4005 | ||
4006 | /* There should be a DW_AT_ranges_base attribute here (if needed). | |
4007 | We need the value before we can process DW_AT_ranges. */ | |
4008 | cu->ranges_base = 0; | |
4009 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_ranges_base, cu); | |
4010 | if (attr) | |
4011 | cu->ranges_base = DW_UNSND (attr); | |
3019eac3 DE |
4012 | |
4013 | if (this_cu->is_debug_types) | |
4014 | { | |
4015 | gdb_assert (sig_type != NULL); | |
4016 | signature = sig_type->signature; | |
4017 | } | |
4018 | else | |
4019 | { | |
4020 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); | |
4021 | if (! attr) | |
4022 | error (_("Dwarf Error: missing dwo_id [in module %s]"), | |
4023 | dwo_name); | |
4024 | signature = DW_UNSND (attr); | |
4025 | } | |
4026 | ||
4027 | /* We may need the comp_dir in order to find the DWO file. */ | |
4028 | comp_dir = NULL; | |
4029 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu); | |
4030 | if (attr) | |
4031 | comp_dir = DW_STRING (attr); | |
4032 | ||
4033 | if (this_cu->is_debug_types) | |
4034 | dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir); | |
4035 | else | |
4036 | dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir, | |
4037 | signature); | |
4038 | ||
4039 | if (dwo_unit == NULL) | |
4040 | { | |
4041 | error (_("Dwarf Error: CU at offset 0x%x references unknown DWO" | |
4042 | " with ID %s [in module %s]"), | |
4043 | this_cu->offset.sect_off, | |
4044 | phex (signature, sizeof (signature)), | |
4045 | objfile->name); | |
4046 | } | |
4047 | ||
4048 | /* Set up for reading the DWO CU/TU. */ | |
4049 | cu->dwo_unit = dwo_unit; | |
4050 | section = dwo_unit->info_or_types_section; | |
4051 | begin_info_ptr = info_ptr = section->buffer + dwo_unit->offset.sect_off; | |
4bdcc0c1 | 4052 | dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev; |
3019eac3 DE |
4053 | init_cu_die_reader (&reader, cu, section, dwo_unit->dwo_file); |
4054 | ||
4055 | if (this_cu->is_debug_types) | |
4056 | { | |
4057 | ULONGEST signature; | |
4058 | ||
4bdcc0c1 DE |
4059 | info_ptr = read_and_check_type_unit_head (&cu->header, section, |
4060 | dwo_abbrev_section, | |
4061 | info_ptr, | |
3019eac3 DE |
4062 | &signature, NULL); |
4063 | gdb_assert (sig_type->signature == signature); | |
4064 | gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off); | |
4065 | gdb_assert (dwo_unit->length | |
4066 | == cu->header.length + cu->header.initial_length_size); | |
4067 | ||
4068 | /* Establish the type offset that can be used to lookup the type. | |
4069 | For DWO files, we don't know it until now. */ | |
4070 | sig_type->type_offset_in_section.sect_off = | |
4071 | dwo_unit->offset.sect_off + dwo_unit->type_offset_in_tu.cu_off; | |
4072 | } | |
4073 | else | |
4074 | { | |
4bdcc0c1 DE |
4075 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, |
4076 | dwo_abbrev_section, | |
4077 | info_ptr, 0); | |
3019eac3 DE |
4078 | gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off); |
4079 | gdb_assert (dwo_unit->length | |
4080 | == cu->header.length + cu->header.initial_length_size); | |
4081 | } | |
4082 | ||
4083 | /* Discard the original CU's abbrev table, and read the DWO's. */ | |
4084 | dwarf2_free_abbrev_table (cu); | |
4bdcc0c1 | 4085 | dwarf2_read_abbrevs (cu, dwo_abbrev_section); |
3019eac3 DE |
4086 | |
4087 | /* Read in the die, but leave space to copy over the attributes | |
4088 | from the stub. This has the benefit of simplifying the rest of | |
4089 | the code - all the real work is done here. */ | |
4090 | num_extra_attrs = ((stmt_list != NULL) | |
4091 | + (low_pc != NULL) | |
4092 | + (high_pc != NULL) | |
4093 | + (ranges != NULL)); | |
4094 | info_ptr = read_full_die_1 (&reader, &comp_unit_die, info_ptr, | |
4095 | &has_children, num_extra_attrs); | |
4096 | ||
4097 | /* Copy over the attributes from the stub to the DWO die. */ | |
4098 | i = comp_unit_die->num_attrs; | |
4099 | if (stmt_list != NULL) | |
4100 | comp_unit_die->attrs[i++] = *stmt_list; | |
4101 | if (low_pc != NULL) | |
4102 | comp_unit_die->attrs[i++] = *low_pc; | |
4103 | if (high_pc != NULL) | |
4104 | comp_unit_die->attrs[i++] = *high_pc; | |
4105 | if (ranges != NULL) | |
4106 | comp_unit_die->attrs[i++] = *ranges; | |
4107 | comp_unit_die->num_attrs += num_extra_attrs; | |
4108 | ||
4109 | /* Skip dummy compilation units. */ | |
4110 | if (info_ptr >= begin_info_ptr + dwo_unit->length | |
4111 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
4112 | { | |
4113 | do_cleanups (cleanups); | |
4114 | return; | |
4115 | } | |
4116 | } | |
4117 | ||
dee91e82 DE |
4118 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); |
4119 | ||
4120 | if (free_cu_cleanup != NULL) | |
348e048f | 4121 | { |
dee91e82 DE |
4122 | if (keep) |
4123 | { | |
4124 | /* We've successfully allocated this compilation unit. Let our | |
4125 | caller clean it up when finished with it. */ | |
4126 | discard_cleanups (free_cu_cleanup); | |
4127 | ||
4128 | /* We can only discard free_cu_cleanup and all subsequent cleanups. | |
4129 | So we have to manually free the abbrev table. */ | |
4130 | dwarf2_free_abbrev_table (cu); | |
4131 | ||
4132 | /* Link this CU into read_in_chain. */ | |
4133 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4134 | dwarf2_per_objfile->read_in_chain = this_cu; | |
4135 | } | |
4136 | else | |
4137 | do_cleanups (free_cu_cleanup); | |
348e048f | 4138 | } |
dee91e82 DE |
4139 | |
4140 | do_cleanups (cleanups); | |
4141 | } | |
4142 | ||
3019eac3 DE |
4143 | /* Read CU/TU THIS_CU in section SECTION, |
4144 | but do not follow DW_AT_GNU_dwo_name if present. | |
4145 | DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to | |
4146 | have already done the lookup to find the DWO file). | |
dee91e82 DE |
4147 | |
4148 | The caller is required to fill in THIS_CU->section, THIS_CU->offset, and | |
3019eac3 | 4149 | THIS_CU->is_debug_types, but nothing else. |
dee91e82 DE |
4150 | |
4151 | We fill in THIS_CU->length. | |
4152 | ||
4153 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
4154 | linker) then DIE_READER_FUNC will not get called. | |
4155 | ||
4156 | THIS_CU->cu is always freed when done. | |
3019eac3 DE |
4157 | This is done in order to not leave THIS_CU->cu in a state where we have |
4158 | to care whether it refers to the "main" CU or the DWO CU. */ | |
dee91e82 DE |
4159 | |
4160 | static void | |
4161 | init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu, | |
4162 | struct dwarf2_section_info *abbrev_section, | |
3019eac3 | 4163 | struct dwo_file *dwo_file, |
dee91e82 DE |
4164 | die_reader_func_ftype *die_reader_func, |
4165 | void *data) | |
4166 | { | |
4167 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
3019eac3 DE |
4168 | struct dwarf2_section_info *section = this_cu->info_or_types_section; |
4169 | bfd *abfd = section->asection->owner; | |
dee91e82 DE |
4170 | struct dwarf2_cu cu; |
4171 | gdb_byte *begin_info_ptr, *info_ptr; | |
4172 | struct die_reader_specs reader; | |
4173 | struct cleanup *cleanups; | |
4174 | struct die_info *comp_unit_die; | |
4175 | int has_children; | |
4176 | ||
4177 | gdb_assert (this_cu->cu == NULL); | |
4178 | ||
dee91e82 DE |
4179 | /* This is cheap if the section is already read in. */ |
4180 | dwarf2_read_section (objfile, section); | |
4181 | ||
4182 | init_one_comp_unit (&cu, this_cu); | |
4183 | ||
4184 | cleanups = make_cleanup (free_stack_comp_unit, &cu); | |
4185 | ||
4186 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; | |
4bdcc0c1 DE |
4187 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, |
4188 | abbrev_section, info_ptr, | |
3019eac3 | 4189 | this_cu->is_debug_types); |
dee91e82 DE |
4190 | |
4191 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
4192 | ||
4193 | /* Skip dummy compilation units. */ | |
4194 | if (info_ptr >= begin_info_ptr + this_cu->length | |
4195 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
c906108c | 4196 | { |
dee91e82 | 4197 | do_cleanups (cleanups); |
21b2bd31 | 4198 | return; |
93311388 | 4199 | } |
72bf9492 | 4200 | |
dee91e82 DE |
4201 | dwarf2_read_abbrevs (&cu, abbrev_section); |
4202 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
4203 | ||
3019eac3 | 4204 | init_cu_die_reader (&reader, &cu, section, dwo_file); |
dee91e82 DE |
4205 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
4206 | ||
4207 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); | |
4208 | ||
4209 | do_cleanups (cleanups); | |
4210 | } | |
4211 | ||
3019eac3 DE |
4212 | /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and |
4213 | does not lookup the specified DWO file. | |
4214 | This cannot be used to read DWO files. | |
dee91e82 DE |
4215 | |
4216 | THIS_CU->cu is always freed when done. | |
3019eac3 DE |
4217 | This is done in order to not leave THIS_CU->cu in a state where we have |
4218 | to care whether it refers to the "main" CU or the DWO CU. | |
4219 | We can revisit this if the data shows there's a performance issue. */ | |
dee91e82 DE |
4220 | |
4221 | static void | |
4222 | init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu, | |
4223 | die_reader_func_ftype *die_reader_func, | |
4224 | void *data) | |
4225 | { | |
4226 | init_cutu_and_read_dies_no_follow (this_cu, | |
4227 | &dwarf2_per_objfile->abbrev, | |
3019eac3 | 4228 | NULL, |
dee91e82 DE |
4229 | die_reader_func, data); |
4230 | } | |
4231 | ||
4232 | /* die_reader_func for process_psymtab_comp_unit. */ | |
4233 | ||
4234 | static void | |
4235 | process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, | |
4236 | gdb_byte *info_ptr, | |
4237 | struct die_info *comp_unit_die, | |
4238 | int has_children, | |
4239 | void *data) | |
4240 | { | |
4241 | struct dwarf2_cu *cu = reader->cu; | |
4242 | struct objfile *objfile = cu->objfile; | |
4243 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; | |
dee91e82 DE |
4244 | struct attribute *attr; |
4245 | CORE_ADDR baseaddr; | |
4246 | CORE_ADDR best_lowpc = 0, best_highpc = 0; | |
4247 | struct partial_symtab *pst; | |
4248 | int has_pc_info; | |
4249 | const char *filename; | |
95554aad | 4250 | int *want_partial_unit_ptr = data; |
dee91e82 | 4251 | |
95554aad TT |
4252 | if (comp_unit_die->tag == DW_TAG_partial_unit |
4253 | && (want_partial_unit_ptr == NULL | |
4254 | || !*want_partial_unit_ptr)) | |
dee91e82 DE |
4255 | return; |
4256 | ||
95554aad | 4257 | prepare_one_comp_unit (cu, comp_unit_die, language_minimal); |
dee91e82 DE |
4258 | |
4259 | cu->list_in_scope = &file_symbols; | |
c906108c | 4260 | |
93311388 | 4261 | /* Allocate a new partial symbol table structure. */ |
dee91e82 | 4262 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu); |
3e2a0cee TT |
4263 | if (attr == NULL || !DW_STRING (attr)) |
4264 | filename = ""; | |
4265 | else | |
4266 | filename = DW_STRING (attr); | |
93311388 | 4267 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
3e2a0cee | 4268 | filename, |
93311388 DE |
4269 | /* TEXTLOW and TEXTHIGH are set below. */ |
4270 | 0, | |
4271 | objfile->global_psymbols.next, | |
4272 | objfile->static_psymbols.next); | |
9750bca9 | 4273 | pst->psymtabs_addrmap_supported = 1; |
72bf9492 | 4274 | |
dee91e82 | 4275 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu); |
d85a05f0 DJ |
4276 | if (attr != NULL) |
4277 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 4278 | |
dee91e82 | 4279 | pst->read_symtab_private = per_cu; |
72bf9492 | 4280 | |
93311388 | 4281 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 4282 | |
0963b4bd | 4283 | /* Store the function that reads in the rest of the symbol table. */ |
93311388 | 4284 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
57349743 | 4285 | |
dee91e82 | 4286 | per_cu->v.psymtab = pst; |
c906108c | 4287 | |
dee91e82 | 4288 | dwarf2_find_base_address (comp_unit_die, cu); |
d85a05f0 | 4289 | |
93311388 DE |
4290 | /* Possibly set the default values of LOWPC and HIGHPC from |
4291 | `DW_AT_ranges'. */ | |
d85a05f0 | 4292 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
dee91e82 | 4293 | &best_highpc, cu, pst); |
d85a05f0 | 4294 | if (has_pc_info == 1 && best_lowpc < best_highpc) |
93311388 DE |
4295 | /* Store the contiguous range if it is not empty; it can be empty for |
4296 | CUs with no code. */ | |
4297 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
4298 | best_lowpc + baseaddr, |
4299 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
4300 | |
4301 | /* Check if comp unit has_children. | |
4302 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 4303 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 4304 | if (has_children) |
93311388 DE |
4305 | { |
4306 | struct partial_die_info *first_die; | |
4307 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 4308 | |
93311388 DE |
4309 | lowpc = ((CORE_ADDR) -1); |
4310 | highpc = ((CORE_ADDR) 0); | |
c906108c | 4311 | |
dee91e82 | 4312 | first_die = load_partial_dies (reader, info_ptr, 1); |
c906108c | 4313 | |
93311388 | 4314 | scan_partial_symbols (first_die, &lowpc, &highpc, |
dee91e82 | 4315 | ! has_pc_info, cu); |
57c22c6c | 4316 | |
93311388 DE |
4317 | /* If we didn't find a lowpc, set it to highpc to avoid |
4318 | complaints from `maint check'. */ | |
4319 | if (lowpc == ((CORE_ADDR) -1)) | |
4320 | lowpc = highpc; | |
10b3939b | 4321 | |
93311388 DE |
4322 | /* If the compilation unit didn't have an explicit address range, |
4323 | then use the information extracted from its child dies. */ | |
d85a05f0 | 4324 | if (! has_pc_info) |
93311388 | 4325 | { |
d85a05f0 DJ |
4326 | best_lowpc = lowpc; |
4327 | best_highpc = highpc; | |
93311388 DE |
4328 | } |
4329 | } | |
d85a05f0 DJ |
4330 | pst->textlow = best_lowpc + baseaddr; |
4331 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 4332 | |
93311388 DE |
4333 | pst->n_global_syms = objfile->global_psymbols.next - |
4334 | (objfile->global_psymbols.list + pst->globals_offset); | |
4335 | pst->n_static_syms = objfile->static_psymbols.next - | |
4336 | (objfile->static_psymbols.list + pst->statics_offset); | |
4337 | sort_pst_symbols (pst); | |
c906108c | 4338 | |
95554aad TT |
4339 | if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs)) |
4340 | { | |
4341 | int i; | |
4342 | int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); | |
4343 | struct dwarf2_per_cu_data *iter; | |
4344 | ||
4345 | /* Fill in 'dependencies' here; we fill in 'users' in a | |
4346 | post-pass. */ | |
4347 | pst->number_of_dependencies = len; | |
4348 | pst->dependencies = obstack_alloc (&objfile->objfile_obstack, | |
4349 | len * sizeof (struct symtab *)); | |
4350 | for (i = 0; | |
4351 | VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, | |
4352 | i, iter); | |
4353 | ++i) | |
4354 | pst->dependencies[i] = iter->v.psymtab; | |
4355 | ||
4356 | VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs); | |
4357 | } | |
4358 | ||
3019eac3 | 4359 | if (per_cu->is_debug_types) |
348e048f DE |
4360 | { |
4361 | /* It's not clear we want to do anything with stmt lists here. | |
4362 | Waiting to see what gcc ultimately does. */ | |
4363 | } | |
d85a05f0 | 4364 | else |
93311388 DE |
4365 | { |
4366 | /* Get the list of files included in the current compilation unit, | |
4367 | and build a psymtab for each of them. */ | |
dee91e82 | 4368 | dwarf2_build_include_psymtabs (cu, comp_unit_die, pst); |
93311388 | 4369 | } |
dee91e82 | 4370 | } |
ae038cb0 | 4371 | |
dee91e82 DE |
4372 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. |
4373 | Process compilation unit THIS_CU for a psymtab. */ | |
4374 | ||
4375 | static void | |
95554aad TT |
4376 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, |
4377 | int want_partial_unit) | |
dee91e82 DE |
4378 | { |
4379 | /* If this compilation unit was already read in, free the | |
4380 | cached copy in order to read it in again. This is | |
4381 | necessary because we skipped some symbols when we first | |
4382 | read in the compilation unit (see load_partial_dies). | |
4383 | This problem could be avoided, but the benefit is unclear. */ | |
4384 | if (this_cu->cu != NULL) | |
4385 | free_one_cached_comp_unit (this_cu); | |
4386 | ||
3019eac3 | 4387 | gdb_assert (! this_cu->is_debug_types); |
fd820528 | 4388 | init_cutu_and_read_dies (this_cu, 0, 0, process_psymtab_comp_unit_reader, |
95554aad | 4389 | &want_partial_unit); |
dee91e82 DE |
4390 | |
4391 | /* Age out any secondary CUs. */ | |
4392 | age_cached_comp_units (); | |
93311388 | 4393 | } |
ff013f42 | 4394 | |
348e048f DE |
4395 | /* Traversal function for htab_traverse_noresize. |
4396 | Process one .debug_types comp-unit. */ | |
4397 | ||
4398 | static int | |
dee91e82 | 4399 | process_psymtab_type_unit (void **slot, void *info) |
348e048f | 4400 | { |
dee91e82 DE |
4401 | struct signatured_type *sig_type = (struct signatured_type *) *slot; |
4402 | struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu; | |
348e048f | 4403 | |
fd820528 | 4404 | gdb_assert (per_cu->is_debug_types); |
a0f42c21 | 4405 | gdb_assert (info == NULL); |
348e048f | 4406 | |
dee91e82 DE |
4407 | /* If this compilation unit was already read in, free the |
4408 | cached copy in order to read it in again. This is | |
4409 | necessary because we skipped some symbols when we first | |
4410 | read in the compilation unit (see load_partial_dies). | |
4411 | This problem could be avoided, but the benefit is unclear. */ | |
4412 | if (per_cu->cu != NULL) | |
4413 | free_one_cached_comp_unit (per_cu); | |
4414 | ||
fd820528 DE |
4415 | init_cutu_and_read_dies (per_cu, 0, 0, process_psymtab_comp_unit_reader, |
4416 | NULL); | |
dee91e82 DE |
4417 | |
4418 | /* Age out any secondary CUs. */ | |
4419 | age_cached_comp_units (); | |
348e048f DE |
4420 | |
4421 | return 1; | |
4422 | } | |
4423 | ||
4424 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
4425 | Build partial symbol tables for the .debug_types comp-units. */ | |
4426 | ||
4427 | static void | |
4428 | build_type_psymtabs (struct objfile *objfile) | |
4429 | { | |
0e50663e | 4430 | if (! create_all_type_units (objfile)) |
348e048f DE |
4431 | return; |
4432 | ||
4433 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
dee91e82 | 4434 | process_psymtab_type_unit, NULL); |
348e048f DE |
4435 | } |
4436 | ||
60606b2c TT |
4437 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
4438 | ||
4439 | static void | |
4440 | psymtabs_addrmap_cleanup (void *o) | |
4441 | { | |
4442 | struct objfile *objfile = o; | |
ec61707d | 4443 | |
60606b2c TT |
4444 | objfile->psymtabs_addrmap = NULL; |
4445 | } | |
4446 | ||
95554aad TT |
4447 | /* Compute the 'user' field for each psymtab in OBJFILE. */ |
4448 | ||
4449 | static void | |
4450 | set_partial_user (struct objfile *objfile) | |
4451 | { | |
4452 | int i; | |
4453 | ||
4454 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
4455 | { | |
4456 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
4457 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4458 | int j; | |
4459 | ||
4460 | for (j = 0; j < pst->number_of_dependencies; ++j) | |
4461 | { | |
4462 | /* Set the 'user' field only if it is not already set. */ | |
4463 | if (pst->dependencies[j]->user == NULL) | |
4464 | pst->dependencies[j]->user = pst; | |
4465 | } | |
4466 | } | |
4467 | } | |
4468 | ||
93311388 DE |
4469 | /* Build the partial symbol table by doing a quick pass through the |
4470 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 4471 | |
93311388 | 4472 | static void |
c67a9c90 | 4473 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 4474 | { |
60606b2c TT |
4475 | struct cleanup *back_to, *addrmap_cleanup; |
4476 | struct obstack temp_obstack; | |
21b2bd31 | 4477 | int i; |
93311388 | 4478 | |
45cfd468 DE |
4479 | if (dwarf2_read_debug) |
4480 | { | |
4481 | fprintf_unfiltered (gdb_stdlog, "Building psymtabs of objfile %s ...\n", | |
4482 | objfile->name); | |
4483 | } | |
4484 | ||
98bfdba5 PA |
4485 | dwarf2_per_objfile->reading_partial_symbols = 1; |
4486 | ||
be391dca | 4487 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
91c24f0a | 4488 | |
93311388 DE |
4489 | /* Any cached compilation units will be linked by the per-objfile |
4490 | read_in_chain. Make sure to free them when we're done. */ | |
4491 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 4492 | |
348e048f DE |
4493 | build_type_psymtabs (objfile); |
4494 | ||
93311388 | 4495 | create_all_comp_units (objfile); |
c906108c | 4496 | |
60606b2c TT |
4497 | /* Create a temporary address map on a temporary obstack. We later |
4498 | copy this to the final obstack. */ | |
4499 | obstack_init (&temp_obstack); | |
4500 | make_cleanup_obstack_free (&temp_obstack); | |
4501 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
4502 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 4503 | |
21b2bd31 | 4504 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
93311388 | 4505 | { |
21b2bd31 | 4506 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
aaa75496 | 4507 | |
95554aad | 4508 | process_psymtab_comp_unit (per_cu, 0); |
c906108c | 4509 | } |
ff013f42 | 4510 | |
95554aad TT |
4511 | set_partial_user (objfile); |
4512 | ||
ff013f42 JK |
4513 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, |
4514 | &objfile->objfile_obstack); | |
60606b2c | 4515 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 4516 | |
ae038cb0 | 4517 | do_cleanups (back_to); |
45cfd468 DE |
4518 | |
4519 | if (dwarf2_read_debug) | |
4520 | fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n", | |
4521 | objfile->name); | |
ae038cb0 DJ |
4522 | } |
4523 | ||
3019eac3 | 4524 | /* die_reader_func for load_partial_comp_unit. */ |
ae038cb0 DJ |
4525 | |
4526 | static void | |
dee91e82 DE |
4527 | load_partial_comp_unit_reader (const struct die_reader_specs *reader, |
4528 | gdb_byte *info_ptr, | |
4529 | struct die_info *comp_unit_die, | |
4530 | int has_children, | |
4531 | void *data) | |
ae038cb0 | 4532 | { |
dee91e82 | 4533 | struct dwarf2_cu *cu = reader->cu; |
ae038cb0 | 4534 | |
95554aad | 4535 | prepare_one_comp_unit (cu, comp_unit_die, language_minimal); |
ae038cb0 | 4536 | |
ae038cb0 DJ |
4537 | /* Check if comp unit has_children. |
4538 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 4539 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 4540 | if (has_children) |
dee91e82 DE |
4541 | load_partial_dies (reader, info_ptr, 0); |
4542 | } | |
98bfdba5 | 4543 | |
dee91e82 DE |
4544 | /* Load the partial DIEs for a secondary CU into memory. |
4545 | This is also used when rereading a primary CU with load_all_dies. */ | |
c5b7e1cb | 4546 | |
dee91e82 DE |
4547 | static void |
4548 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) | |
4549 | { | |
fd820528 | 4550 | init_cutu_and_read_dies (this_cu, 1, 1, load_partial_comp_unit_reader, NULL); |
ae038cb0 DJ |
4551 | } |
4552 | ||
9cdd5dbd DE |
4553 | /* Create a list of all compilation units in OBJFILE. |
4554 | This is only done for -readnow and building partial symtabs. */ | |
ae038cb0 DJ |
4555 | |
4556 | static void | |
4557 | create_all_comp_units (struct objfile *objfile) | |
4558 | { | |
4559 | int n_allocated; | |
4560 | int n_comp_units; | |
4561 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
4562 | gdb_byte *info_ptr; |
4563 | ||
4564 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
4565 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
4566 | |
4567 | n_comp_units = 0; | |
4568 | n_allocated = 10; | |
4569 | all_comp_units = xmalloc (n_allocated | |
4570 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 4571 | |
3e43a32a MS |
4572 | while (info_ptr < dwarf2_per_objfile->info.buffer |
4573 | + dwarf2_per_objfile->info.size) | |
ae038cb0 | 4574 | { |
c764a876 | 4575 | unsigned int length, initial_length_size; |
ae038cb0 | 4576 | struct dwarf2_per_cu_data *this_cu; |
b64f50a1 | 4577 | sect_offset offset; |
ae038cb0 | 4578 | |
b64f50a1 | 4579 | offset.sect_off = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
4580 | |
4581 | /* Read just enough information to find out where the next | |
4582 | compilation unit is. */ | |
c764a876 DE |
4583 | length = read_initial_length (objfile->obfd, info_ptr, |
4584 | &initial_length_size); | |
ae038cb0 DJ |
4585 | |
4586 | /* Save the compilation unit for later lookup. */ | |
4587 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
4588 | sizeof (struct dwarf2_per_cu_data)); | |
4589 | memset (this_cu, 0, sizeof (*this_cu)); | |
4590 | this_cu->offset = offset; | |
c764a876 | 4591 | this_cu->length = length + initial_length_size; |
9291a0cd | 4592 | this_cu->objfile = objfile; |
3019eac3 | 4593 | this_cu->info_or_types_section = &dwarf2_per_objfile->info; |
ae038cb0 DJ |
4594 | |
4595 | if (n_comp_units == n_allocated) | |
4596 | { | |
4597 | n_allocated *= 2; | |
4598 | all_comp_units = xrealloc (all_comp_units, | |
4599 | n_allocated | |
4600 | * sizeof (struct dwarf2_per_cu_data *)); | |
4601 | } | |
4602 | all_comp_units[n_comp_units++] = this_cu; | |
4603 | ||
4604 | info_ptr = info_ptr + this_cu->length; | |
4605 | } | |
4606 | ||
4607 | dwarf2_per_objfile->all_comp_units | |
4608 | = obstack_alloc (&objfile->objfile_obstack, | |
4609 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
4610 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
4611 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
4612 | xfree (all_comp_units); | |
4613 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
4614 | } |
4615 | ||
5734ee8b DJ |
4616 | /* Process all loaded DIEs for compilation unit CU, starting at |
4617 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
4618 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
4619 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
4620 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
4621 | and record the covered ranges in the addrmap. */ | |
c906108c | 4622 | |
72bf9492 DJ |
4623 | static void |
4624 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 4625 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 4626 | { |
72bf9492 | 4627 | struct partial_die_info *pdi; |
c906108c | 4628 | |
91c24f0a DC |
4629 | /* Now, march along the PDI's, descending into ones which have |
4630 | interesting children but skipping the children of the other ones, | |
4631 | until we reach the end of the compilation unit. */ | |
c906108c | 4632 | |
72bf9492 | 4633 | pdi = first_die; |
91c24f0a | 4634 | |
72bf9492 DJ |
4635 | while (pdi != NULL) |
4636 | { | |
4637 | fixup_partial_die (pdi, cu); | |
c906108c | 4638 | |
f55ee35c | 4639 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
4640 | children, so we need to look at them. Ditto for anonymous |
4641 | enums. */ | |
933c6fe4 | 4642 | |
72bf9492 | 4643 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
95554aad TT |
4644 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type |
4645 | || pdi->tag == DW_TAG_imported_unit) | |
c906108c | 4646 | { |
72bf9492 | 4647 | switch (pdi->tag) |
c906108c SS |
4648 | { |
4649 | case DW_TAG_subprogram: | |
5734ee8b | 4650 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 4651 | break; |
72929c62 | 4652 | case DW_TAG_constant: |
c906108c SS |
4653 | case DW_TAG_variable: |
4654 | case DW_TAG_typedef: | |
91c24f0a | 4655 | case DW_TAG_union_type: |
72bf9492 | 4656 | if (!pdi->is_declaration) |
63d06c5c | 4657 | { |
72bf9492 | 4658 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
4659 | } |
4660 | break; | |
c906108c | 4661 | case DW_TAG_class_type: |
680b30c7 | 4662 | case DW_TAG_interface_type: |
c906108c | 4663 | case DW_TAG_structure_type: |
72bf9492 | 4664 | if (!pdi->is_declaration) |
c906108c | 4665 | { |
72bf9492 | 4666 | add_partial_symbol (pdi, cu); |
c906108c SS |
4667 | } |
4668 | break; | |
91c24f0a | 4669 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
4670 | if (!pdi->is_declaration) |
4671 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
4672 | break; |
4673 | case DW_TAG_base_type: | |
a02abb62 | 4674 | case DW_TAG_subrange_type: |
c906108c | 4675 | /* File scope base type definitions are added to the partial |
c5aa993b | 4676 | symbol table. */ |
72bf9492 | 4677 | add_partial_symbol (pdi, cu); |
c906108c | 4678 | break; |
d9fa45fe | 4679 | case DW_TAG_namespace: |
5734ee8b | 4680 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 4681 | break; |
5d7cb8df JK |
4682 | case DW_TAG_module: |
4683 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
4684 | break; | |
95554aad TT |
4685 | case DW_TAG_imported_unit: |
4686 | { | |
4687 | struct dwarf2_per_cu_data *per_cu; | |
4688 | ||
4689 | per_cu = dwarf2_find_containing_comp_unit (pdi->d.offset, | |
4690 | cu->objfile); | |
4691 | ||
4692 | /* Go read the partial unit, if needed. */ | |
4693 | if (per_cu->v.psymtab == NULL) | |
4694 | process_psymtab_comp_unit (per_cu, 1); | |
4695 | ||
4696 | VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, | |
4697 | per_cu); | |
4698 | } | |
4699 | break; | |
c906108c SS |
4700 | default: |
4701 | break; | |
4702 | } | |
4703 | } | |
4704 | ||
72bf9492 DJ |
4705 | /* If the die has a sibling, skip to the sibling. */ |
4706 | ||
4707 | pdi = pdi->die_sibling; | |
4708 | } | |
4709 | } | |
4710 | ||
4711 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 4712 | |
72bf9492 | 4713 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
4714 | name is concatenated with "::" and the partial DIE's name. For |
4715 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
4716 | Enumerators are an exception; they use the scope of their parent |
4717 | enumeration type, i.e. the name of the enumeration type is not | |
4718 | prepended to the enumerator. | |
91c24f0a | 4719 | |
72bf9492 DJ |
4720 | There are two complexities. One is DW_AT_specification; in this |
4721 | case "parent" means the parent of the target of the specification, | |
4722 | instead of the direct parent of the DIE. The other is compilers | |
4723 | which do not emit DW_TAG_namespace; in this case we try to guess | |
4724 | the fully qualified name of structure types from their members' | |
4725 | linkage names. This must be done using the DIE's children rather | |
4726 | than the children of any DW_AT_specification target. We only need | |
4727 | to do this for structures at the top level, i.e. if the target of | |
4728 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
4729 | have a parent. */ | |
4730 | ||
4731 | /* Compute the scope prefix associated with PDI's parent, in | |
4732 | compilation unit CU. The result will be allocated on CU's | |
4733 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
4734 | field. NULL is returned if no prefix is necessary. */ | |
4735 | static char * | |
4736 | partial_die_parent_scope (struct partial_die_info *pdi, | |
4737 | struct dwarf2_cu *cu) | |
4738 | { | |
4739 | char *grandparent_scope; | |
4740 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 4741 | |
72bf9492 DJ |
4742 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
4743 | then this means the parent of the specification DIE. */ | |
4744 | ||
4745 | real_pdi = pdi; | |
72bf9492 | 4746 | while (real_pdi->has_specification) |
10b3939b | 4747 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
4748 | |
4749 | parent = real_pdi->die_parent; | |
4750 | if (parent == NULL) | |
4751 | return NULL; | |
4752 | ||
4753 | if (parent->scope_set) | |
4754 | return parent->scope; | |
4755 | ||
4756 | fixup_partial_die (parent, cu); | |
4757 | ||
10b3939b | 4758 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 4759 | |
acebe513 UW |
4760 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
4761 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
4762 | Work around this problem here. */ | |
4763 | if (cu->language == language_cplus | |
6e70227d | 4764 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
4765 | && strcmp (parent->name, "::") == 0 |
4766 | && grandparent_scope == NULL) | |
4767 | { | |
4768 | parent->scope = NULL; | |
4769 | parent->scope_set = 1; | |
4770 | return NULL; | |
4771 | } | |
4772 | ||
9c6c53f7 SA |
4773 | if (pdi->tag == DW_TAG_enumerator) |
4774 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
4775 | parent->scope = grandparent_scope; | |
4776 | else if (parent->tag == DW_TAG_namespace | |
f55ee35c | 4777 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
4778 | || parent->tag == DW_TAG_structure_type |
4779 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 4780 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
4781 | || parent->tag == DW_TAG_union_type |
4782 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
4783 | { |
4784 | if (grandparent_scope == NULL) | |
4785 | parent->scope = parent->name; | |
4786 | else | |
3e43a32a MS |
4787 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
4788 | grandparent_scope, | |
f55ee35c | 4789 | parent->name, 0, cu); |
72bf9492 | 4790 | } |
72bf9492 DJ |
4791 | else |
4792 | { | |
4793 | /* FIXME drow/2004-04-01: What should we be doing with | |
4794 | function-local names? For partial symbols, we should probably be | |
4795 | ignoring them. */ | |
4796 | complaint (&symfile_complaints, | |
e2e0b3e5 | 4797 | _("unhandled containing DIE tag %d for DIE at %d"), |
b64f50a1 | 4798 | parent->tag, pdi->offset.sect_off); |
72bf9492 | 4799 | parent->scope = grandparent_scope; |
c906108c SS |
4800 | } |
4801 | ||
72bf9492 DJ |
4802 | parent->scope_set = 1; |
4803 | return parent->scope; | |
4804 | } | |
4805 | ||
4806 | /* Return the fully scoped name associated with PDI, from compilation unit | |
4807 | CU. The result will be allocated with malloc. */ | |
4568ecf9 | 4808 | |
72bf9492 DJ |
4809 | static char * |
4810 | partial_die_full_name (struct partial_die_info *pdi, | |
4811 | struct dwarf2_cu *cu) | |
4812 | { | |
4813 | char *parent_scope; | |
4814 | ||
98bfdba5 PA |
4815 | /* If this is a template instantiation, we can not work out the |
4816 | template arguments from partial DIEs. So, unfortunately, we have | |
4817 | to go through the full DIEs. At least any work we do building | |
4818 | types here will be reused if full symbols are loaded later. */ | |
4819 | if (pdi->has_template_arguments) | |
4820 | { | |
4821 | fixup_partial_die (pdi, cu); | |
4822 | ||
4823 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
4824 | { | |
4825 | struct die_info *die; | |
4826 | struct attribute attr; | |
4827 | struct dwarf2_cu *ref_cu = cu; | |
4828 | ||
b64f50a1 | 4829 | /* DW_FORM_ref_addr is using section offset. */ |
98bfdba5 PA |
4830 | attr.name = 0; |
4831 | attr.form = DW_FORM_ref_addr; | |
4568ecf9 | 4832 | attr.u.unsnd = pdi->offset.sect_off; |
98bfdba5 PA |
4833 | die = follow_die_ref (NULL, &attr, &ref_cu); |
4834 | ||
4835 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
4836 | } | |
4837 | } | |
4838 | ||
72bf9492 DJ |
4839 | parent_scope = partial_die_parent_scope (pdi, cu); |
4840 | if (parent_scope == NULL) | |
4841 | return NULL; | |
4842 | else | |
f55ee35c | 4843 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
4844 | } |
4845 | ||
4846 | static void | |
72bf9492 | 4847 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 4848 | { |
e7c27a73 | 4849 | struct objfile *objfile = cu->objfile; |
c906108c | 4850 | CORE_ADDR addr = 0; |
decbce07 | 4851 | char *actual_name = NULL; |
e142c38c | 4852 | CORE_ADDR baseaddr; |
72bf9492 | 4853 | int built_actual_name = 0; |
e142c38c DJ |
4854 | |
4855 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 4856 | |
94af9270 KS |
4857 | actual_name = partial_die_full_name (pdi, cu); |
4858 | if (actual_name) | |
4859 | built_actual_name = 1; | |
63d06c5c | 4860 | |
72bf9492 DJ |
4861 | if (actual_name == NULL) |
4862 | actual_name = pdi->name; | |
4863 | ||
c906108c SS |
4864 | switch (pdi->tag) |
4865 | { | |
4866 | case DW_TAG_subprogram: | |
2cfa0c8d | 4867 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 4868 | { |
2cfa0c8d JB |
4869 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
4870 | of the global scope. But in Ada, we want to be able to access | |
4871 | nested procedures globally. So all Ada subprograms are stored | |
4872 | in the global scope. */ | |
f47fb265 | 4873 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 4874 | mst_text, objfile); */ |
f47fb265 MS |
4875 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4876 | built_actual_name, | |
4877 | VAR_DOMAIN, LOC_BLOCK, | |
4878 | &objfile->global_psymbols, | |
4879 | 0, pdi->lowpc + baseaddr, | |
4880 | cu->language, objfile); | |
c906108c SS |
4881 | } |
4882 | else | |
4883 | { | |
f47fb265 | 4884 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 4885 | mst_file_text, objfile); */ |
f47fb265 MS |
4886 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4887 | built_actual_name, | |
4888 | VAR_DOMAIN, LOC_BLOCK, | |
4889 | &objfile->static_psymbols, | |
4890 | 0, pdi->lowpc + baseaddr, | |
4891 | cu->language, objfile); | |
c906108c SS |
4892 | } |
4893 | break; | |
72929c62 JB |
4894 | case DW_TAG_constant: |
4895 | { | |
4896 | struct psymbol_allocation_list *list; | |
4897 | ||
4898 | if (pdi->is_external) | |
4899 | list = &objfile->global_psymbols; | |
4900 | else | |
4901 | list = &objfile->static_psymbols; | |
f47fb265 MS |
4902 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4903 | built_actual_name, VAR_DOMAIN, LOC_STATIC, | |
4904 | list, 0, 0, cu->language, objfile); | |
72929c62 JB |
4905 | } |
4906 | break; | |
c906108c | 4907 | case DW_TAG_variable: |
95554aad TT |
4908 | if (pdi->d.locdesc) |
4909 | addr = decode_locdesc (pdi->d.locdesc, cu); | |
caac4577 | 4910 | |
95554aad | 4911 | if (pdi->d.locdesc |
caac4577 JG |
4912 | && addr == 0 |
4913 | && !dwarf2_per_objfile->has_section_at_zero) | |
4914 | { | |
4915 | /* A global or static variable may also have been stripped | |
4916 | out by the linker if unused, in which case its address | |
4917 | will be nullified; do not add such variables into partial | |
4918 | symbol table then. */ | |
4919 | } | |
4920 | else if (pdi->is_external) | |
c906108c SS |
4921 | { |
4922 | /* Global Variable. | |
4923 | Don't enter into the minimal symbol tables as there is | |
4924 | a minimal symbol table entry from the ELF symbols already. | |
4925 | Enter into partial symbol table if it has a location | |
4926 | descriptor or a type. | |
4927 | If the location descriptor is missing, new_symbol will create | |
4928 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
4929 | be determined from the minimal symbol table whenever the variable | |
4930 | is referenced. | |
4931 | The address for the partial symbol table entry is not | |
4932 | used by GDB, but it comes in handy for debugging partial symbol | |
4933 | table building. */ | |
4934 | ||
95554aad | 4935 | if (pdi->d.locdesc || pdi->has_type) |
f47fb265 MS |
4936 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4937 | built_actual_name, | |
4938 | VAR_DOMAIN, LOC_STATIC, | |
4939 | &objfile->global_psymbols, | |
4940 | 0, addr + baseaddr, | |
4941 | cu->language, objfile); | |
c906108c SS |
4942 | } |
4943 | else | |
4944 | { | |
0963b4bd | 4945 | /* Static Variable. Skip symbols without location descriptors. */ |
95554aad | 4946 | if (pdi->d.locdesc == NULL) |
decbce07 MS |
4947 | { |
4948 | if (built_actual_name) | |
4949 | xfree (actual_name); | |
4950 | return; | |
4951 | } | |
f47fb265 | 4952 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 4953 | mst_file_data, objfile); */ |
f47fb265 MS |
4954 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4955 | built_actual_name, | |
4956 | VAR_DOMAIN, LOC_STATIC, | |
4957 | &objfile->static_psymbols, | |
4958 | 0, addr + baseaddr, | |
4959 | cu->language, objfile); | |
c906108c SS |
4960 | } |
4961 | break; | |
4962 | case DW_TAG_typedef: | |
4963 | case DW_TAG_base_type: | |
a02abb62 | 4964 | case DW_TAG_subrange_type: |
38d518c9 | 4965 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4966 | built_actual_name, |
176620f1 | 4967 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 4968 | &objfile->static_psymbols, |
e142c38c | 4969 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4970 | break; |
72bf9492 DJ |
4971 | case DW_TAG_namespace: |
4972 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 4973 | built_actual_name, |
72bf9492 DJ |
4974 | VAR_DOMAIN, LOC_TYPEDEF, |
4975 | &objfile->global_psymbols, | |
4976 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
4977 | break; | |
c906108c | 4978 | case DW_TAG_class_type: |
680b30c7 | 4979 | case DW_TAG_interface_type: |
c906108c SS |
4980 | case DW_TAG_structure_type: |
4981 | case DW_TAG_union_type: | |
4982 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
4983 | /* Skip external references. The DWARF standard says in the section |
4984 | about "Structure, Union, and Class Type Entries": "An incomplete | |
4985 | structure, union or class type is represented by a structure, | |
4986 | union or class entry that does not have a byte size attribute | |
4987 | and that has a DW_AT_declaration attribute." */ | |
4988 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
4989 | { |
4990 | if (built_actual_name) | |
4991 | xfree (actual_name); | |
4992 | return; | |
4993 | } | |
fa4028e9 | 4994 | |
63d06c5c DC |
4995 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
4996 | static vs. global. */ | |
38d518c9 | 4997 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4998 | built_actual_name, |
176620f1 | 4999 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
5000 | (cu->language == language_cplus |
5001 | || cu->language == language_java) | |
63d06c5c DC |
5002 | ? &objfile->global_psymbols |
5003 | : &objfile->static_psymbols, | |
e142c38c | 5004 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 5005 | |
c906108c SS |
5006 | break; |
5007 | case DW_TAG_enumerator: | |
38d518c9 | 5008 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 5009 | built_actual_name, |
176620f1 | 5010 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
5011 | (cu->language == language_cplus |
5012 | || cu->language == language_java) | |
f6fe98ef DJ |
5013 | ? &objfile->global_psymbols |
5014 | : &objfile->static_psymbols, | |
e142c38c | 5015 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
5016 | break; |
5017 | default: | |
5018 | break; | |
5019 | } | |
5c4e30ca | 5020 | |
72bf9492 DJ |
5021 | if (built_actual_name) |
5022 | xfree (actual_name); | |
c906108c SS |
5023 | } |
5024 | ||
5c4e30ca DC |
5025 | /* Read a partial die corresponding to a namespace; also, add a symbol |
5026 | corresponding to that namespace to the symbol table. NAMESPACE is | |
5027 | the name of the enclosing namespace. */ | |
91c24f0a | 5028 | |
72bf9492 DJ |
5029 | static void |
5030 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 5031 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 5032 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 5033 | { |
72bf9492 | 5034 | /* Add a symbol for the namespace. */ |
e7c27a73 | 5035 | |
72bf9492 | 5036 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
5037 | |
5038 | /* Now scan partial symbols in that namespace. */ | |
5039 | ||
91c24f0a | 5040 | if (pdi->has_children) |
5734ee8b | 5041 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
5042 | } |
5043 | ||
5d7cb8df JK |
5044 | /* Read a partial die corresponding to a Fortran module. */ |
5045 | ||
5046 | static void | |
5047 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
5048 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
5049 | { | |
f55ee35c | 5050 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
5051 | |
5052 | if (pdi->has_children) | |
5053 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
5054 | } | |
5055 | ||
bc30ff58 JB |
5056 | /* Read a partial die corresponding to a subprogram and create a partial |
5057 | symbol for that subprogram. When the CU language allows it, this | |
5058 | routine also defines a partial symbol for each nested subprogram | |
5059 | that this subprogram contains. | |
6e70227d | 5060 | |
bc30ff58 JB |
5061 | DIE my also be a lexical block, in which case we simply search |
5062 | recursively for suprograms defined inside that lexical block. | |
5063 | Again, this is only performed when the CU language allows this | |
5064 | type of definitions. */ | |
5065 | ||
5066 | static void | |
5067 | add_partial_subprogram (struct partial_die_info *pdi, | |
5068 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 5069 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
5070 | { |
5071 | if (pdi->tag == DW_TAG_subprogram) | |
5072 | { | |
5073 | if (pdi->has_pc_info) | |
5074 | { | |
5075 | if (pdi->lowpc < *lowpc) | |
5076 | *lowpc = pdi->lowpc; | |
5077 | if (pdi->highpc > *highpc) | |
5078 | *highpc = pdi->highpc; | |
5734ee8b DJ |
5079 | if (need_pc) |
5080 | { | |
5081 | CORE_ADDR baseaddr; | |
5082 | struct objfile *objfile = cu->objfile; | |
5083 | ||
5084 | baseaddr = ANOFFSET (objfile->section_offsets, | |
5085 | SECT_OFF_TEXT (objfile)); | |
5086 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
5087 | pdi->lowpc + baseaddr, |
5088 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 5089 | cu->per_cu->v.psymtab); |
5734ee8b | 5090 | } |
481860b3 GB |
5091 | } |
5092 | ||
5093 | if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined)) | |
5094 | { | |
bc30ff58 | 5095 | if (!pdi->is_declaration) |
e8d05480 JB |
5096 | /* Ignore subprogram DIEs that do not have a name, they are |
5097 | illegal. Do not emit a complaint at this point, we will | |
5098 | do so when we convert this psymtab into a symtab. */ | |
5099 | if (pdi->name) | |
5100 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
5101 | } |
5102 | } | |
6e70227d | 5103 | |
bc30ff58 JB |
5104 | if (! pdi->has_children) |
5105 | return; | |
5106 | ||
5107 | if (cu->language == language_ada) | |
5108 | { | |
5109 | pdi = pdi->die_child; | |
5110 | while (pdi != NULL) | |
5111 | { | |
5112 | fixup_partial_die (pdi, cu); | |
5113 | if (pdi->tag == DW_TAG_subprogram | |
5114 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 5115 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
5116 | pdi = pdi->die_sibling; |
5117 | } | |
5118 | } | |
5119 | } | |
5120 | ||
91c24f0a DC |
5121 | /* Read a partial die corresponding to an enumeration type. */ |
5122 | ||
72bf9492 DJ |
5123 | static void |
5124 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
5125 | struct dwarf2_cu *cu) | |
91c24f0a | 5126 | { |
72bf9492 | 5127 | struct partial_die_info *pdi; |
91c24f0a DC |
5128 | |
5129 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
5130 | add_partial_symbol (enum_pdi, cu); |
5131 | ||
5132 | pdi = enum_pdi->die_child; | |
5133 | while (pdi) | |
91c24f0a | 5134 | { |
72bf9492 | 5135 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 5136 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 5137 | else |
72bf9492 DJ |
5138 | add_partial_symbol (pdi, cu); |
5139 | pdi = pdi->die_sibling; | |
91c24f0a | 5140 | } |
91c24f0a DC |
5141 | } |
5142 | ||
6caca83c CC |
5143 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
5144 | ||
5145 | static unsigned int | |
5146 | peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr) | |
5147 | { | |
5148 | unsigned int bytes_read; | |
5149 | ||
5150 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5151 | } | |
5152 | ||
4bb7a0a7 DJ |
5153 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
5154 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
5155 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
5156 | the initial number. */ | |
5157 | ||
5158 | static struct abbrev_info * | |
fe1b8b76 | 5159 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 5160 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
5161 | { |
5162 | bfd *abfd = cu->objfile->obfd; | |
5163 | unsigned int abbrev_number; | |
5164 | struct abbrev_info *abbrev; | |
5165 | ||
5166 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
5167 | ||
5168 | if (abbrev_number == 0) | |
5169 | return NULL; | |
5170 | ||
5171 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
5172 | if (!abbrev) | |
5173 | { | |
3e43a32a MS |
5174 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
5175 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
5176 | } |
5177 | ||
5178 | return abbrev; | |
5179 | } | |
5180 | ||
93311388 DE |
5181 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
5182 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
5183 | DIE. Any children of the skipped DIEs will also be skipped. */ |
5184 | ||
fe1b8b76 | 5185 | static gdb_byte * |
dee91e82 | 5186 | skip_children (const struct die_reader_specs *reader, gdb_byte *info_ptr) |
4bb7a0a7 | 5187 | { |
dee91e82 | 5188 | struct dwarf2_cu *cu = reader->cu; |
4bb7a0a7 DJ |
5189 | struct abbrev_info *abbrev; |
5190 | unsigned int bytes_read; | |
5191 | ||
5192 | while (1) | |
5193 | { | |
5194 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
5195 | if (abbrev == NULL) | |
5196 | return info_ptr + bytes_read; | |
5197 | else | |
dee91e82 | 5198 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
4bb7a0a7 DJ |
5199 | } |
5200 | } | |
5201 | ||
93311388 DE |
5202 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
5203 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
5204 | abbrev corresponding to that skipped uleb128 should be passed in |
5205 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
5206 | children. */ | |
5207 | ||
fe1b8b76 | 5208 | static gdb_byte * |
dee91e82 DE |
5209 | skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr, |
5210 | struct abbrev_info *abbrev) | |
4bb7a0a7 DJ |
5211 | { |
5212 | unsigned int bytes_read; | |
5213 | struct attribute attr; | |
dee91e82 DE |
5214 | bfd *abfd = reader->abfd; |
5215 | struct dwarf2_cu *cu = reader->cu; | |
5216 | gdb_byte *buffer = reader->buffer; | |
f664829e DE |
5217 | const gdb_byte *buffer_end = reader->buffer_end; |
5218 | gdb_byte *start_info_ptr = info_ptr; | |
4bb7a0a7 DJ |
5219 | unsigned int form, i; |
5220 | ||
5221 | for (i = 0; i < abbrev->num_attrs; i++) | |
5222 | { | |
5223 | /* The only abbrev we care about is DW_AT_sibling. */ | |
5224 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
5225 | { | |
dee91e82 | 5226 | read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
4bb7a0a7 | 5227 | if (attr.form == DW_FORM_ref_addr) |
3e43a32a MS |
5228 | complaint (&symfile_complaints, |
5229 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 5230 | else |
b64f50a1 | 5231 | return buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
4bb7a0a7 DJ |
5232 | } |
5233 | ||
5234 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
5235 | form = abbrev->attrs[i].form; | |
5236 | skip_attribute: | |
5237 | switch (form) | |
5238 | { | |
4bb7a0a7 | 5239 | case DW_FORM_ref_addr: |
ae411497 TT |
5240 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
5241 | and later it is offset sized. */ | |
5242 | if (cu->header.version == 2) | |
5243 | info_ptr += cu->header.addr_size; | |
5244 | else | |
5245 | info_ptr += cu->header.offset_size; | |
5246 | break; | |
5247 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
5248 | info_ptr += cu->header.addr_size; |
5249 | break; | |
5250 | case DW_FORM_data1: | |
5251 | case DW_FORM_ref1: | |
5252 | case DW_FORM_flag: | |
5253 | info_ptr += 1; | |
5254 | break; | |
2dc7f7b3 TT |
5255 | case DW_FORM_flag_present: |
5256 | break; | |
4bb7a0a7 DJ |
5257 | case DW_FORM_data2: |
5258 | case DW_FORM_ref2: | |
5259 | info_ptr += 2; | |
5260 | break; | |
5261 | case DW_FORM_data4: | |
5262 | case DW_FORM_ref4: | |
5263 | info_ptr += 4; | |
5264 | break; | |
5265 | case DW_FORM_data8: | |
5266 | case DW_FORM_ref8: | |
55f1336d | 5267 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
5268 | info_ptr += 8; |
5269 | break; | |
5270 | case DW_FORM_string: | |
9b1c24c8 | 5271 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
5272 | info_ptr += bytes_read; |
5273 | break; | |
2dc7f7b3 | 5274 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
5275 | case DW_FORM_strp: |
5276 | info_ptr += cu->header.offset_size; | |
5277 | break; | |
2dc7f7b3 | 5278 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
5279 | case DW_FORM_block: |
5280 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5281 | info_ptr += bytes_read; | |
5282 | break; | |
5283 | case DW_FORM_block1: | |
5284 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
5285 | break; | |
5286 | case DW_FORM_block2: | |
5287 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
5288 | break; | |
5289 | case DW_FORM_block4: | |
5290 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
5291 | break; | |
5292 | case DW_FORM_sdata: | |
5293 | case DW_FORM_udata: | |
5294 | case DW_FORM_ref_udata: | |
3019eac3 DE |
5295 | case DW_FORM_GNU_addr_index: |
5296 | case DW_FORM_GNU_str_index: | |
f664829e | 5297 | info_ptr = (gdb_byte *) safe_skip_leb128 (info_ptr, buffer_end); |
4bb7a0a7 DJ |
5298 | break; |
5299 | case DW_FORM_indirect: | |
5300 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5301 | info_ptr += bytes_read; | |
5302 | /* We need to continue parsing from here, so just go back to | |
5303 | the top. */ | |
5304 | goto skip_attribute; | |
5305 | ||
5306 | default: | |
3e43a32a MS |
5307 | error (_("Dwarf Error: Cannot handle %s " |
5308 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
5309 | dwarf_form_name (form), |
5310 | bfd_get_filename (abfd)); | |
5311 | } | |
5312 | } | |
5313 | ||
5314 | if (abbrev->has_children) | |
dee91e82 | 5315 | return skip_children (reader, info_ptr); |
4bb7a0a7 DJ |
5316 | else |
5317 | return info_ptr; | |
5318 | } | |
5319 | ||
93311388 | 5320 | /* Locate ORIG_PDI's sibling. |
dee91e82 | 5321 | INFO_PTR should point to the start of the next DIE after ORIG_PDI. */ |
91c24f0a | 5322 | |
fe1b8b76 | 5323 | static gdb_byte * |
dee91e82 DE |
5324 | locate_pdi_sibling (const struct die_reader_specs *reader, |
5325 | struct partial_die_info *orig_pdi, | |
5326 | gdb_byte *info_ptr) | |
91c24f0a DC |
5327 | { |
5328 | /* Do we know the sibling already? */ | |
72bf9492 | 5329 | |
91c24f0a DC |
5330 | if (orig_pdi->sibling) |
5331 | return orig_pdi->sibling; | |
5332 | ||
5333 | /* Are there any children to deal with? */ | |
5334 | ||
5335 | if (!orig_pdi->has_children) | |
5336 | return info_ptr; | |
5337 | ||
4bb7a0a7 | 5338 | /* Skip the children the long way. */ |
91c24f0a | 5339 | |
dee91e82 | 5340 | return skip_children (reader, info_ptr); |
91c24f0a DC |
5341 | } |
5342 | ||
c906108c SS |
5343 | /* Expand this partial symbol table into a full symbol table. */ |
5344 | ||
5345 | static void | |
fba45db2 | 5346 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 5347 | { |
c906108c SS |
5348 | if (pst != NULL) |
5349 | { | |
5350 | if (pst->readin) | |
5351 | { | |
3e43a32a MS |
5352 | warning (_("bug: psymtab for %s is already read in."), |
5353 | pst->filename); | |
c906108c SS |
5354 | } |
5355 | else | |
5356 | { | |
5357 | if (info_verbose) | |
5358 | { | |
3e43a32a MS |
5359 | printf_filtered (_("Reading in symbols for %s..."), |
5360 | pst->filename); | |
c906108c SS |
5361 | gdb_flush (gdb_stdout); |
5362 | } | |
5363 | ||
10b3939b DJ |
5364 | /* Restore our global data. */ |
5365 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
5366 | dwarf2_objfile_data_key); | |
5367 | ||
b2ab525c KB |
5368 | /* If this psymtab is constructed from a debug-only objfile, the |
5369 | has_section_at_zero flag will not necessarily be correct. We | |
5370 | can get the correct value for this flag by looking at the data | |
5371 | associated with the (presumably stripped) associated objfile. */ | |
5372 | if (pst->objfile->separate_debug_objfile_backlink) | |
5373 | { | |
5374 | struct dwarf2_per_objfile *dpo_backlink | |
5375 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
5376 | dwarf2_objfile_data_key); | |
9a619af0 | 5377 | |
b2ab525c KB |
5378 | dwarf2_per_objfile->has_section_at_zero |
5379 | = dpo_backlink->has_section_at_zero; | |
5380 | } | |
5381 | ||
98bfdba5 PA |
5382 | dwarf2_per_objfile->reading_partial_symbols = 0; |
5383 | ||
c906108c SS |
5384 | psymtab_to_symtab_1 (pst); |
5385 | ||
5386 | /* Finish up the debug error message. */ | |
5387 | if (info_verbose) | |
a3f17187 | 5388 | printf_filtered (_("done.\n")); |
c906108c SS |
5389 | } |
5390 | } | |
95554aad TT |
5391 | |
5392 | process_cu_includes (); | |
c906108c | 5393 | } |
9cdd5dbd DE |
5394 | \f |
5395 | /* Reading in full CUs. */ | |
c906108c | 5396 | |
10b3939b DJ |
5397 | /* Add PER_CU to the queue. */ |
5398 | ||
5399 | static void | |
95554aad TT |
5400 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, |
5401 | enum language pretend_language) | |
10b3939b DJ |
5402 | { |
5403 | struct dwarf2_queue_item *item; | |
5404 | ||
5405 | per_cu->queued = 1; | |
5406 | item = xmalloc (sizeof (*item)); | |
5407 | item->per_cu = per_cu; | |
95554aad | 5408 | item->pretend_language = pretend_language; |
10b3939b DJ |
5409 | item->next = NULL; |
5410 | ||
5411 | if (dwarf2_queue == NULL) | |
5412 | dwarf2_queue = item; | |
5413 | else | |
5414 | dwarf2_queue_tail->next = item; | |
5415 | ||
5416 | dwarf2_queue_tail = item; | |
5417 | } | |
5418 | ||
5419 | /* Process the queue. */ | |
5420 | ||
5421 | static void | |
a0f42c21 | 5422 | process_queue (void) |
10b3939b DJ |
5423 | { |
5424 | struct dwarf2_queue_item *item, *next_item; | |
5425 | ||
45cfd468 DE |
5426 | if (dwarf2_read_debug) |
5427 | { | |
5428 | fprintf_unfiltered (gdb_stdlog, | |
5429 | "Expanding one or more symtabs of objfile %s ...\n", | |
5430 | dwarf2_per_objfile->objfile->name); | |
5431 | } | |
5432 | ||
03dd20cc DJ |
5433 | /* The queue starts out with one item, but following a DIE reference |
5434 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
5435 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
5436 | { | |
9291a0cd TT |
5437 | if (dwarf2_per_objfile->using_index |
5438 | ? !item->per_cu->v.quick->symtab | |
5439 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
95554aad | 5440 | process_full_comp_unit (item->per_cu, item->pretend_language); |
10b3939b DJ |
5441 | |
5442 | item->per_cu->queued = 0; | |
5443 | next_item = item->next; | |
5444 | xfree (item); | |
5445 | } | |
5446 | ||
5447 | dwarf2_queue_tail = NULL; | |
45cfd468 DE |
5448 | |
5449 | if (dwarf2_read_debug) | |
5450 | { | |
5451 | fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n", | |
5452 | dwarf2_per_objfile->objfile->name); | |
5453 | } | |
10b3939b DJ |
5454 | } |
5455 | ||
5456 | /* Free all allocated queue entries. This function only releases anything if | |
5457 | an error was thrown; if the queue was processed then it would have been | |
5458 | freed as we went along. */ | |
5459 | ||
5460 | static void | |
5461 | dwarf2_release_queue (void *dummy) | |
5462 | { | |
5463 | struct dwarf2_queue_item *item, *last; | |
5464 | ||
5465 | item = dwarf2_queue; | |
5466 | while (item) | |
5467 | { | |
5468 | /* Anything still marked queued is likely to be in an | |
5469 | inconsistent state, so discard it. */ | |
5470 | if (item->per_cu->queued) | |
5471 | { | |
5472 | if (item->per_cu->cu != NULL) | |
dee91e82 | 5473 | free_one_cached_comp_unit (item->per_cu); |
10b3939b DJ |
5474 | item->per_cu->queued = 0; |
5475 | } | |
5476 | ||
5477 | last = item; | |
5478 | item = item->next; | |
5479 | xfree (last); | |
5480 | } | |
5481 | ||
5482 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
5483 | } | |
5484 | ||
5485 | /* Read in full symbols for PST, and anything it depends on. */ | |
5486 | ||
c906108c | 5487 | static void |
fba45db2 | 5488 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 5489 | { |
10b3939b | 5490 | struct dwarf2_per_cu_data *per_cu; |
aaa75496 JB |
5491 | int i; |
5492 | ||
95554aad TT |
5493 | if (pst->readin) |
5494 | return; | |
5495 | ||
aaa75496 | 5496 | for (i = 0; i < pst->number_of_dependencies; i++) |
95554aad TT |
5497 | if (!pst->dependencies[i]->readin |
5498 | && pst->dependencies[i]->user == NULL) | |
aaa75496 JB |
5499 | { |
5500 | /* Inform about additional files that need to be read in. */ | |
5501 | if (info_verbose) | |
5502 | { | |
a3f17187 | 5503 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
5504 | fputs_filtered (" ", gdb_stdout); |
5505 | wrap_here (""); | |
5506 | fputs_filtered ("and ", gdb_stdout); | |
5507 | wrap_here (""); | |
5508 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 5509 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
5510 | gdb_flush (gdb_stdout); |
5511 | } | |
5512 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
5513 | } | |
5514 | ||
e38df1d0 | 5515 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
5516 | |
5517 | if (per_cu == NULL) | |
aaa75496 JB |
5518 | { |
5519 | /* It's an include file, no symbols to read for it. | |
5520 | Everything is in the parent symtab. */ | |
5521 | pst->readin = 1; | |
5522 | return; | |
5523 | } | |
c906108c | 5524 | |
a0f42c21 | 5525 | dw2_do_instantiate_symtab (per_cu); |
10b3939b DJ |
5526 | } |
5527 | ||
dee91e82 DE |
5528 | /* Trivial hash function for die_info: the hash value of a DIE |
5529 | is its offset in .debug_info for this objfile. */ | |
10b3939b | 5530 | |
dee91e82 DE |
5531 | static hashval_t |
5532 | die_hash (const void *item) | |
10b3939b | 5533 | { |
dee91e82 | 5534 | const struct die_info *die = item; |
6502dd73 | 5535 | |
dee91e82 DE |
5536 | return die->offset.sect_off; |
5537 | } | |
63d06c5c | 5538 | |
dee91e82 DE |
5539 | /* Trivial comparison function for die_info structures: two DIEs |
5540 | are equal if they have the same offset. */ | |
98bfdba5 | 5541 | |
dee91e82 DE |
5542 | static int |
5543 | die_eq (const void *item_lhs, const void *item_rhs) | |
5544 | { | |
5545 | const struct die_info *die_lhs = item_lhs; | |
5546 | const struct die_info *die_rhs = item_rhs; | |
c906108c | 5547 | |
dee91e82 DE |
5548 | return die_lhs->offset.sect_off == die_rhs->offset.sect_off; |
5549 | } | |
c906108c | 5550 | |
dee91e82 DE |
5551 | /* die_reader_func for load_full_comp_unit. |
5552 | This is identical to read_signatured_type_reader, | |
5553 | but is kept separate for now. */ | |
c906108c | 5554 | |
dee91e82 DE |
5555 | static void |
5556 | load_full_comp_unit_reader (const struct die_reader_specs *reader, | |
5557 | gdb_byte *info_ptr, | |
5558 | struct die_info *comp_unit_die, | |
5559 | int has_children, | |
5560 | void *data) | |
5561 | { | |
5562 | struct dwarf2_cu *cu = reader->cu; | |
95554aad | 5563 | enum language *language_ptr = data; |
6caca83c | 5564 | |
dee91e82 DE |
5565 | gdb_assert (cu->die_hash == NULL); |
5566 | cu->die_hash = | |
5567 | htab_create_alloc_ex (cu->header.length / 12, | |
5568 | die_hash, | |
5569 | die_eq, | |
5570 | NULL, | |
5571 | &cu->comp_unit_obstack, | |
5572 | hashtab_obstack_allocate, | |
5573 | dummy_obstack_deallocate); | |
e142c38c | 5574 | |
dee91e82 DE |
5575 | if (has_children) |
5576 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
5577 | &info_ptr, comp_unit_die); | |
5578 | cu->dies = comp_unit_die; | |
5579 | /* comp_unit_die is not stored in die_hash, no need. */ | |
10b3939b DJ |
5580 | |
5581 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 5582 | all CUs needed for references have been loaded yet, and symbol |
10b3939b | 5583 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
5584 | or we won't be able to build types correctly. |
5585 | Similarly, if we do not read the producer, we can not apply | |
5586 | producer-specific interpretation. */ | |
95554aad | 5587 | prepare_one_comp_unit (cu, cu->dies, *language_ptr); |
dee91e82 | 5588 | } |
10b3939b | 5589 | |
dee91e82 | 5590 | /* Load the DIEs associated with PER_CU into memory. */ |
a6c727b2 | 5591 | |
dee91e82 | 5592 | static void |
95554aad TT |
5593 | load_full_comp_unit (struct dwarf2_per_cu_data *this_cu, |
5594 | enum language pretend_language) | |
dee91e82 | 5595 | { |
3019eac3 | 5596 | gdb_assert (! this_cu->is_debug_types); |
c5b7e1cb | 5597 | |
95554aad TT |
5598 | init_cutu_and_read_dies (this_cu, 1, 1, load_full_comp_unit_reader, |
5599 | &pretend_language); | |
10b3939b DJ |
5600 | } |
5601 | ||
3da10d80 KS |
5602 | /* Add a DIE to the delayed physname list. */ |
5603 | ||
5604 | static void | |
5605 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
5606 | const char *name, struct die_info *die, | |
5607 | struct dwarf2_cu *cu) | |
5608 | { | |
5609 | struct delayed_method_info mi; | |
5610 | mi.type = type; | |
5611 | mi.fnfield_index = fnfield_index; | |
5612 | mi.index = index; | |
5613 | mi.name = name; | |
5614 | mi.die = die; | |
5615 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
5616 | } | |
5617 | ||
5618 | /* A cleanup for freeing the delayed method list. */ | |
5619 | ||
5620 | static void | |
5621 | free_delayed_list (void *ptr) | |
5622 | { | |
5623 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
5624 | if (cu->method_list != NULL) | |
5625 | { | |
5626 | VEC_free (delayed_method_info, cu->method_list); | |
5627 | cu->method_list = NULL; | |
5628 | } | |
5629 | } | |
5630 | ||
5631 | /* Compute the physnames of any methods on the CU's method list. | |
5632 | ||
5633 | The computation of method physnames is delayed in order to avoid the | |
5634 | (bad) condition that one of the method's formal parameters is of an as yet | |
5635 | incomplete type. */ | |
5636 | ||
5637 | static void | |
5638 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
5639 | { | |
5640 | int i; | |
5641 | struct delayed_method_info *mi; | |
5642 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
5643 | { | |
1d06ead6 | 5644 | const char *physname; |
3da10d80 KS |
5645 | struct fn_fieldlist *fn_flp |
5646 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
1d06ead6 | 5647 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
3da10d80 KS |
5648 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
5649 | } | |
5650 | } | |
5651 | ||
a766d390 DE |
5652 | /* Go objects should be embedded in a DW_TAG_module DIE, |
5653 | and it's not clear if/how imported objects will appear. | |
5654 | To keep Go support simple until that's worked out, | |
5655 | go back through what we've read and create something usable. | |
5656 | We could do this while processing each DIE, and feels kinda cleaner, | |
5657 | but that way is more invasive. | |
5658 | This is to, for example, allow the user to type "p var" or "b main" | |
5659 | without having to specify the package name, and allow lookups | |
5660 | of module.object to work in contexts that use the expression | |
5661 | parser. */ | |
5662 | ||
5663 | static void | |
5664 | fixup_go_packaging (struct dwarf2_cu *cu) | |
5665 | { | |
5666 | char *package_name = NULL; | |
5667 | struct pending *list; | |
5668 | int i; | |
5669 | ||
5670 | for (list = global_symbols; list != NULL; list = list->next) | |
5671 | { | |
5672 | for (i = 0; i < list->nsyms; ++i) | |
5673 | { | |
5674 | struct symbol *sym = list->symbol[i]; | |
5675 | ||
5676 | if (SYMBOL_LANGUAGE (sym) == language_go | |
5677 | && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
5678 | { | |
5679 | char *this_package_name = go_symbol_package_name (sym); | |
5680 | ||
5681 | if (this_package_name == NULL) | |
5682 | continue; | |
5683 | if (package_name == NULL) | |
5684 | package_name = this_package_name; | |
5685 | else | |
5686 | { | |
5687 | if (strcmp (package_name, this_package_name) != 0) | |
5688 | complaint (&symfile_complaints, | |
5689 | _("Symtab %s has objects from two different Go packages: %s and %s"), | |
5690 | (sym->symtab && sym->symtab->filename | |
5691 | ? sym->symtab->filename | |
5692 | : cu->objfile->name), | |
5693 | this_package_name, package_name); | |
5694 | xfree (this_package_name); | |
5695 | } | |
5696 | } | |
5697 | } | |
5698 | } | |
5699 | ||
5700 | if (package_name != NULL) | |
5701 | { | |
5702 | struct objfile *objfile = cu->objfile; | |
5703 | struct type *type = init_type (TYPE_CODE_MODULE, 0, 0, | |
5704 | package_name, objfile); | |
5705 | struct symbol *sym; | |
5706 | ||
5707 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
5708 | ||
5709 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
5710 | SYMBOL_SET_LANGUAGE (sym, language_go); | |
5711 | SYMBOL_SET_NAMES (sym, package_name, strlen (package_name), 1, objfile); | |
5712 | /* This is not VAR_DOMAIN because we want a way to ensure a lookup of, | |
5713 | e.g., "main" finds the "main" module and not C's main(). */ | |
5714 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; | |
5715 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
5716 | SYMBOL_TYPE (sym) = type; | |
5717 | ||
5718 | add_symbol_to_list (sym, &global_symbols); | |
5719 | ||
5720 | xfree (package_name); | |
5721 | } | |
5722 | } | |
5723 | ||
95554aad TT |
5724 | static void compute_symtab_includes (struct dwarf2_per_cu_data *per_cu); |
5725 | ||
5726 | /* Return the symtab for PER_CU. This works properly regardless of | |
5727 | whether we're using the index or psymtabs. */ | |
5728 | ||
5729 | static struct symtab * | |
5730 | get_symtab (struct dwarf2_per_cu_data *per_cu) | |
5731 | { | |
5732 | return (dwarf2_per_objfile->using_index | |
5733 | ? per_cu->v.quick->symtab | |
5734 | : per_cu->v.psymtab->symtab); | |
5735 | } | |
5736 | ||
5737 | /* A helper function for computing the list of all symbol tables | |
5738 | included by PER_CU. */ | |
5739 | ||
5740 | static void | |
5741 | recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr) **result, | |
5742 | htab_t all_children, | |
5743 | struct dwarf2_per_cu_data *per_cu) | |
5744 | { | |
5745 | void **slot; | |
5746 | int ix; | |
5747 | struct dwarf2_per_cu_data *iter; | |
5748 | ||
5749 | slot = htab_find_slot (all_children, per_cu, INSERT); | |
5750 | if (*slot != NULL) | |
5751 | { | |
5752 | /* This inclusion and its children have been processed. */ | |
5753 | return; | |
5754 | } | |
5755 | ||
5756 | *slot = per_cu; | |
5757 | /* Only add a CU if it has a symbol table. */ | |
5758 | if (get_symtab (per_cu) != NULL) | |
5759 | VEC_safe_push (dwarf2_per_cu_ptr, *result, per_cu); | |
5760 | ||
5761 | for (ix = 0; | |
5762 | VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter); | |
5763 | ++ix) | |
5764 | recursively_compute_inclusions (result, all_children, iter); | |
5765 | } | |
5766 | ||
5767 | /* Compute the symtab 'includes' fields for the symtab related to | |
5768 | PER_CU. */ | |
5769 | ||
5770 | static void | |
5771 | compute_symtab_includes (struct dwarf2_per_cu_data *per_cu) | |
5772 | { | |
5773 | if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs)) | |
5774 | { | |
5775 | int ix, len; | |
5776 | struct dwarf2_per_cu_data *iter; | |
5777 | VEC (dwarf2_per_cu_ptr) *result_children = NULL; | |
5778 | htab_t all_children; | |
5779 | struct symtab *symtab = get_symtab (per_cu); | |
5780 | ||
5781 | /* If we don't have a symtab, we can just skip this case. */ | |
5782 | if (symtab == NULL) | |
5783 | return; | |
5784 | ||
5785 | all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, | |
5786 | NULL, xcalloc, xfree); | |
5787 | ||
5788 | for (ix = 0; | |
5789 | VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, | |
5790 | ix, iter); | |
5791 | ++ix) | |
5792 | recursively_compute_inclusions (&result_children, all_children, iter); | |
5793 | ||
5794 | /* Now we have a transitive closure of all the included CUs, so | |
5795 | we can convert it to a list of symtabs. */ | |
5796 | len = VEC_length (dwarf2_per_cu_ptr, result_children); | |
5797 | symtab->includes | |
5798 | = obstack_alloc (&dwarf2_per_objfile->objfile->objfile_obstack, | |
5799 | (len + 1) * sizeof (struct symtab *)); | |
5800 | for (ix = 0; | |
5801 | VEC_iterate (dwarf2_per_cu_ptr, result_children, ix, iter); | |
5802 | ++ix) | |
5803 | symtab->includes[ix] = get_symtab (iter); | |
5804 | symtab->includes[len] = NULL; | |
5805 | ||
5806 | VEC_free (dwarf2_per_cu_ptr, result_children); | |
5807 | htab_delete (all_children); | |
5808 | } | |
5809 | } | |
5810 | ||
5811 | /* Compute the 'includes' field for the symtabs of all the CUs we just | |
5812 | read. */ | |
5813 | ||
5814 | static void | |
5815 | process_cu_includes (void) | |
5816 | { | |
5817 | int ix; | |
5818 | struct dwarf2_per_cu_data *iter; | |
5819 | ||
5820 | for (ix = 0; | |
5821 | VEC_iterate (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, | |
5822 | ix, iter); | |
5823 | ++ix) | |
5824 | compute_symtab_includes (iter); | |
5825 | ||
5826 | VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus); | |
5827 | } | |
5828 | ||
9cdd5dbd | 5829 | /* Generate full symbol information for PER_CU, whose DIEs have |
10b3939b DJ |
5830 | already been loaded into memory. */ |
5831 | ||
5832 | static void | |
95554aad TT |
5833 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, |
5834 | enum language pretend_language) | |
10b3939b | 5835 | { |
10b3939b | 5836 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 5837 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
5838 | CORE_ADDR lowpc, highpc; |
5839 | struct symtab *symtab; | |
3da10d80 | 5840 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
5841 | CORE_ADDR baseaddr; |
5842 | ||
45cfd468 DE |
5843 | if (dwarf2_read_debug) |
5844 | { | |
5845 | fprintf_unfiltered (gdb_stdlog, | |
5846 | "Expanding symtab of %s at offset 0x%x\n", | |
5847 | per_cu->is_debug_types ? "TU" : "CU", | |
5848 | per_cu->offset.sect_off); | |
5849 | } | |
5850 | ||
10b3939b DJ |
5851 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
5852 | ||
10b3939b DJ |
5853 | buildsym_init (); |
5854 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 5855 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
5856 | |
5857 | cu->list_in_scope = &file_symbols; | |
c906108c | 5858 | |
95554aad TT |
5859 | cu->language = pretend_language; |
5860 | cu->language_defn = language_def (cu->language); | |
5861 | ||
c906108c | 5862 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 5863 | process_die (cu->dies, cu); |
c906108c | 5864 | |
a766d390 DE |
5865 | /* For now fudge the Go package. */ |
5866 | if (cu->language == language_go) | |
5867 | fixup_go_packaging (cu); | |
5868 | ||
3da10d80 KS |
5869 | /* Now that we have processed all the DIEs in the CU, all the types |
5870 | should be complete, and it should now be safe to compute all of the | |
5871 | physnames. */ | |
5872 | compute_delayed_physnames (cu); | |
5873 | do_cleanups (delayed_list_cleanup); | |
5874 | ||
fae299cd DC |
5875 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
5876 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
5877 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 5878 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 5879 | |
613e1657 | 5880 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c | 5881 | |
8be455d7 | 5882 | if (symtab != NULL) |
c906108c | 5883 | { |
df15bd07 | 5884 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
4632c0d0 | 5885 | |
8be455d7 JK |
5886 | /* Set symtab language to language from DW_AT_language. If the |
5887 | compilation is from a C file generated by language preprocessors, do | |
5888 | not set the language if it was already deduced by start_subfile. */ | |
5889 | if (!(cu->language == language_c && symtab->language != language_c)) | |
5890 | symtab->language = cu->language; | |
5891 | ||
5892 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
5893 | produce DW_AT_location with location lists but it can be possibly | |
ab260dad JK |
5894 | invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0 |
5895 | there were bugs in prologue debug info, fixed later in GCC-4.5 | |
5896 | by "unwind info for epilogues" patch (which is not directly related). | |
8be455d7 JK |
5897 | |
5898 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
5899 | needed, it would be wrong due to missing DW_AT_producer there. | |
5900 | ||
5901 | Still one can confuse GDB by using non-standard GCC compilation | |
5902 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
5903 | */ | |
ab260dad | 5904 | if (cu->has_loclist && gcc_4_minor >= 5) |
8be455d7 | 5905 | symtab->locations_valid = 1; |
e0d00bc7 JK |
5906 | |
5907 | if (gcc_4_minor >= 5) | |
5908 | symtab->epilogue_unwind_valid = 1; | |
96408a79 SA |
5909 | |
5910 | symtab->call_site_htab = cu->call_site_htab; | |
c906108c | 5911 | } |
9291a0cd TT |
5912 | |
5913 | if (dwarf2_per_objfile->using_index) | |
5914 | per_cu->v.quick->symtab = symtab; | |
5915 | else | |
5916 | { | |
5917 | struct partial_symtab *pst = per_cu->v.psymtab; | |
5918 | pst->symtab = symtab; | |
5919 | pst->readin = 1; | |
5920 | } | |
c906108c | 5921 | |
95554aad TT |
5922 | /* Push it for inclusion processing later. */ |
5923 | VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu); | |
5924 | ||
c906108c | 5925 | do_cleanups (back_to); |
45cfd468 DE |
5926 | |
5927 | if (dwarf2_read_debug) | |
5928 | { | |
5929 | fprintf_unfiltered (gdb_stdlog, | |
5930 | "Done expanding symtab of %s at offset 0x%x\n", | |
5931 | per_cu->is_debug_types ? "TU" : "CU", | |
5932 | per_cu->offset.sect_off); | |
5933 | } | |
c906108c SS |
5934 | } |
5935 | ||
95554aad TT |
5936 | /* Process an imported unit DIE. */ |
5937 | ||
5938 | static void | |
5939 | process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu) | |
5940 | { | |
5941 | struct attribute *attr; | |
5942 | ||
5943 | attr = dwarf2_attr (die, DW_AT_import, cu); | |
5944 | if (attr != NULL) | |
5945 | { | |
5946 | struct dwarf2_per_cu_data *per_cu; | |
5947 | struct symtab *imported_symtab; | |
5948 | sect_offset offset; | |
5949 | ||
5950 | offset = dwarf2_get_ref_die_offset (attr); | |
5951 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); | |
5952 | ||
5953 | /* Queue the unit, if needed. */ | |
5954 | if (maybe_queue_comp_unit (cu, per_cu, cu->language)) | |
5955 | load_full_comp_unit (per_cu, cu->language); | |
5956 | ||
5957 | VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs, | |
5958 | per_cu); | |
5959 | } | |
5960 | } | |
5961 | ||
c906108c SS |
5962 | /* Process a die and its children. */ |
5963 | ||
5964 | static void | |
e7c27a73 | 5965 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5966 | { |
5967 | switch (die->tag) | |
5968 | { | |
5969 | case DW_TAG_padding: | |
5970 | break; | |
5971 | case DW_TAG_compile_unit: | |
95554aad | 5972 | case DW_TAG_partial_unit: |
e7c27a73 | 5973 | read_file_scope (die, cu); |
c906108c | 5974 | break; |
348e048f DE |
5975 | case DW_TAG_type_unit: |
5976 | read_type_unit_scope (die, cu); | |
5977 | break; | |
c906108c | 5978 | case DW_TAG_subprogram: |
c906108c | 5979 | case DW_TAG_inlined_subroutine: |
edb3359d | 5980 | read_func_scope (die, cu); |
c906108c SS |
5981 | break; |
5982 | case DW_TAG_lexical_block: | |
14898363 L |
5983 | case DW_TAG_try_block: |
5984 | case DW_TAG_catch_block: | |
e7c27a73 | 5985 | read_lexical_block_scope (die, cu); |
c906108c | 5986 | break; |
96408a79 SA |
5987 | case DW_TAG_GNU_call_site: |
5988 | read_call_site_scope (die, cu); | |
5989 | break; | |
c906108c | 5990 | case DW_TAG_class_type: |
680b30c7 | 5991 | case DW_TAG_interface_type: |
c906108c SS |
5992 | case DW_TAG_structure_type: |
5993 | case DW_TAG_union_type: | |
134d01f1 | 5994 | process_structure_scope (die, cu); |
c906108c SS |
5995 | break; |
5996 | case DW_TAG_enumeration_type: | |
134d01f1 | 5997 | process_enumeration_scope (die, cu); |
c906108c | 5998 | break; |
134d01f1 | 5999 | |
f792889a DJ |
6000 | /* These dies have a type, but processing them does not create |
6001 | a symbol or recurse to process the children. Therefore we can | |
6002 | read them on-demand through read_type_die. */ | |
c906108c | 6003 | case DW_TAG_subroutine_type: |
72019c9c | 6004 | case DW_TAG_set_type: |
c906108c | 6005 | case DW_TAG_array_type: |
c906108c | 6006 | case DW_TAG_pointer_type: |
c906108c | 6007 | case DW_TAG_ptr_to_member_type: |
c906108c | 6008 | case DW_TAG_reference_type: |
c906108c | 6009 | case DW_TAG_string_type: |
c906108c | 6010 | break; |
134d01f1 | 6011 | |
c906108c | 6012 | case DW_TAG_base_type: |
a02abb62 | 6013 | case DW_TAG_subrange_type: |
cb249c71 | 6014 | case DW_TAG_typedef: |
134d01f1 DJ |
6015 | /* Add a typedef symbol for the type definition, if it has a |
6016 | DW_AT_name. */ | |
f792889a | 6017 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 6018 | break; |
c906108c | 6019 | case DW_TAG_common_block: |
e7c27a73 | 6020 | read_common_block (die, cu); |
c906108c SS |
6021 | break; |
6022 | case DW_TAG_common_inclusion: | |
6023 | break; | |
d9fa45fe | 6024 | case DW_TAG_namespace: |
63d06c5c | 6025 | processing_has_namespace_info = 1; |
e7c27a73 | 6026 | read_namespace (die, cu); |
d9fa45fe | 6027 | break; |
5d7cb8df | 6028 | case DW_TAG_module: |
f55ee35c | 6029 | processing_has_namespace_info = 1; |
5d7cb8df JK |
6030 | read_module (die, cu); |
6031 | break; | |
d9fa45fe DC |
6032 | case DW_TAG_imported_declaration: |
6033 | case DW_TAG_imported_module: | |
63d06c5c | 6034 | processing_has_namespace_info = 1; |
27aa8d6a SW |
6035 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
6036 | || cu->language != language_fortran)) | |
6037 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
6038 | dwarf_tag_name (die->tag)); | |
6039 | read_import_statement (die, cu); | |
d9fa45fe | 6040 | break; |
95554aad TT |
6041 | |
6042 | case DW_TAG_imported_unit: | |
6043 | process_imported_unit_die (die, cu); | |
6044 | break; | |
6045 | ||
c906108c | 6046 | default: |
e7c27a73 | 6047 | new_symbol (die, NULL, cu); |
c906108c SS |
6048 | break; |
6049 | } | |
6050 | } | |
6051 | ||
94af9270 KS |
6052 | /* A helper function for dwarf2_compute_name which determines whether DIE |
6053 | needs to have the name of the scope prepended to the name listed in the | |
6054 | die. */ | |
6055 | ||
6056 | static int | |
6057 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
6058 | { | |
1c809c68 TT |
6059 | struct attribute *attr; |
6060 | ||
94af9270 KS |
6061 | switch (die->tag) |
6062 | { | |
6063 | case DW_TAG_namespace: | |
6064 | case DW_TAG_typedef: | |
6065 | case DW_TAG_class_type: | |
6066 | case DW_TAG_interface_type: | |
6067 | case DW_TAG_structure_type: | |
6068 | case DW_TAG_union_type: | |
6069 | case DW_TAG_enumeration_type: | |
6070 | case DW_TAG_enumerator: | |
6071 | case DW_TAG_subprogram: | |
6072 | case DW_TAG_member: | |
6073 | return 1; | |
6074 | ||
6075 | case DW_TAG_variable: | |
c2b0a229 | 6076 | case DW_TAG_constant: |
94af9270 KS |
6077 | /* We only need to prefix "globally" visible variables. These include |
6078 | any variable marked with DW_AT_external or any variable that | |
6079 | lives in a namespace. [Variables in anonymous namespaces | |
6080 | require prefixing, but they are not DW_AT_external.] */ | |
6081 | ||
6082 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
6083 | { | |
6084 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 6085 | |
94af9270 KS |
6086 | return die_needs_namespace (die_specification (die, &spec_cu), |
6087 | spec_cu); | |
6088 | } | |
6089 | ||
1c809c68 | 6090 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
6091 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
6092 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
6093 | return 0; |
6094 | /* A variable in a lexical block of some kind does not need a | |
6095 | namespace, even though in C++ such variables may be external | |
6096 | and have a mangled name. */ | |
6097 | if (die->parent->tag == DW_TAG_lexical_block | |
6098 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
6099 | || die->parent->tag == DW_TAG_catch_block |
6100 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
6101 | return 0; |
6102 | return 1; | |
94af9270 KS |
6103 | |
6104 | default: | |
6105 | return 0; | |
6106 | } | |
6107 | } | |
6108 | ||
98bfdba5 PA |
6109 | /* Retrieve the last character from a mem_file. */ |
6110 | ||
6111 | static void | |
6112 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
6113 | { | |
6114 | char *last_char_p = (char *) object; | |
6115 | ||
6116 | if (length > 0) | |
6117 | *last_char_p = buffer[length - 1]; | |
6118 | } | |
6119 | ||
94af9270 | 6120 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
a766d390 DE |
6121 | compute the physname for the object, which include a method's: |
6122 | - formal parameters (C++/Java), | |
6123 | - receiver type (Go), | |
6124 | - return type (Java). | |
6125 | ||
6126 | The term "physname" is a bit confusing. | |
6127 | For C++, for example, it is the demangled name. | |
6128 | For Go, for example, it's the mangled name. | |
94af9270 | 6129 | |
af6b7be1 JB |
6130 | For Ada, return the DIE's linkage name rather than the fully qualified |
6131 | name. PHYSNAME is ignored.. | |
6132 | ||
94af9270 KS |
6133 | The result is allocated on the objfile_obstack and canonicalized. */ |
6134 | ||
6135 | static const char * | |
6136 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
6137 | int physname) | |
6138 | { | |
bb5ed363 DE |
6139 | struct objfile *objfile = cu->objfile; |
6140 | ||
94af9270 KS |
6141 | if (name == NULL) |
6142 | name = dwarf2_name (die, cu); | |
6143 | ||
f55ee35c JK |
6144 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
6145 | compute it by typename_concat inside GDB. */ | |
6146 | if (cu->language == language_ada | |
6147 | || (cu->language == language_fortran && physname)) | |
6148 | { | |
6149 | /* For Ada unit, we prefer the linkage name over the name, as | |
6150 | the former contains the exported name, which the user expects | |
6151 | to be able to reference. Ideally, we want the user to be able | |
6152 | to reference this entity using either natural or linkage name, | |
6153 | but we haven't started looking at this enhancement yet. */ | |
6154 | struct attribute *attr; | |
6155 | ||
6156 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
6157 | if (attr == NULL) | |
6158 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
6159 | if (attr && DW_STRING (attr)) | |
6160 | return DW_STRING (attr); | |
6161 | } | |
6162 | ||
94af9270 KS |
6163 | /* These are the only languages we know how to qualify names in. */ |
6164 | if (name != NULL | |
f55ee35c JK |
6165 | && (cu->language == language_cplus || cu->language == language_java |
6166 | || cu->language == language_fortran)) | |
94af9270 KS |
6167 | { |
6168 | if (die_needs_namespace (die, cu)) | |
6169 | { | |
6170 | long length; | |
0d5cff50 | 6171 | const char *prefix; |
94af9270 KS |
6172 | struct ui_file *buf; |
6173 | ||
6174 | prefix = determine_prefix (die, cu); | |
6175 | buf = mem_fileopen (); | |
6176 | if (*prefix != '\0') | |
6177 | { | |
f55ee35c JK |
6178 | char *prefixed_name = typename_concat (NULL, prefix, name, |
6179 | physname, cu); | |
9a619af0 | 6180 | |
94af9270 KS |
6181 | fputs_unfiltered (prefixed_name, buf); |
6182 | xfree (prefixed_name); | |
6183 | } | |
6184 | else | |
62d5b8da | 6185 | fputs_unfiltered (name, buf); |
94af9270 | 6186 | |
98bfdba5 PA |
6187 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
6188 | as children with DW_TAG_template_type_param or | |
6189 | DW_TAG_value_type_param. If the latter, add them to the name | |
6190 | here. If the name already has template parameters, then | |
6191 | skip this step; some versions of GCC emit both, and | |
6192 | it is more efficient to use the pre-computed name. | |
6193 | ||
6194 | Something to keep in mind about this process: it is very | |
6195 | unlikely, or in some cases downright impossible, to produce | |
6196 | something that will match the mangled name of a function. | |
6197 | If the definition of the function has the same debug info, | |
6198 | we should be able to match up with it anyway. But fallbacks | |
6199 | using the minimal symbol, for instance to find a method | |
6200 | implemented in a stripped copy of libstdc++, will not work. | |
6201 | If we do not have debug info for the definition, we will have to | |
6202 | match them up some other way. | |
6203 | ||
6204 | When we do name matching there is a related problem with function | |
6205 | templates; two instantiated function templates are allowed to | |
6206 | differ only by their return types, which we do not add here. */ | |
6207 | ||
6208 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
6209 | { | |
6210 | struct attribute *attr; | |
6211 | struct die_info *child; | |
6212 | int first = 1; | |
6213 | ||
6214 | die->building_fullname = 1; | |
6215 | ||
6216 | for (child = die->child; child != NULL; child = child->sibling) | |
6217 | { | |
6218 | struct type *type; | |
12df843f | 6219 | LONGEST value; |
98bfdba5 PA |
6220 | gdb_byte *bytes; |
6221 | struct dwarf2_locexpr_baton *baton; | |
6222 | struct value *v; | |
6223 | ||
6224 | if (child->tag != DW_TAG_template_type_param | |
6225 | && child->tag != DW_TAG_template_value_param) | |
6226 | continue; | |
6227 | ||
6228 | if (first) | |
6229 | { | |
6230 | fputs_unfiltered ("<", buf); | |
6231 | first = 0; | |
6232 | } | |
6233 | else | |
6234 | fputs_unfiltered (", ", buf); | |
6235 | ||
6236 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
6237 | if (attr == NULL) | |
6238 | { | |
6239 | complaint (&symfile_complaints, | |
6240 | _("template parameter missing DW_AT_type")); | |
6241 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
6242 | continue; | |
6243 | } | |
6244 | type = die_type (child, cu); | |
6245 | ||
6246 | if (child->tag == DW_TAG_template_type_param) | |
6247 | { | |
6248 | c_print_type (type, "", buf, -1, 0); | |
6249 | continue; | |
6250 | } | |
6251 | ||
6252 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
6253 | if (attr == NULL) | |
6254 | { | |
6255 | complaint (&symfile_complaints, | |
3e43a32a MS |
6256 | _("template parameter missing " |
6257 | "DW_AT_const_value")); | |
98bfdba5 PA |
6258 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
6259 | continue; | |
6260 | } | |
6261 | ||
6262 | dwarf2_const_value_attr (attr, type, name, | |
6263 | &cu->comp_unit_obstack, cu, | |
6264 | &value, &bytes, &baton); | |
6265 | ||
6266 | if (TYPE_NOSIGN (type)) | |
6267 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
6268 | changed, this can use value_print instead. */ | |
6269 | c_printchar (value, type, buf); | |
6270 | else | |
6271 | { | |
6272 | struct value_print_options opts; | |
6273 | ||
6274 | if (baton != NULL) | |
6275 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
6276 | baton->data, | |
6277 | baton->size, | |
6278 | baton->per_cu); | |
6279 | else if (bytes != NULL) | |
6280 | { | |
6281 | v = allocate_value (type); | |
6282 | memcpy (value_contents_writeable (v), bytes, | |
6283 | TYPE_LENGTH (type)); | |
6284 | } | |
6285 | else | |
6286 | v = value_from_longest (type, value); | |
6287 | ||
3e43a32a MS |
6288 | /* Specify decimal so that we do not depend on |
6289 | the radix. */ | |
98bfdba5 PA |
6290 | get_formatted_print_options (&opts, 'd'); |
6291 | opts.raw = 1; | |
6292 | value_print (v, buf, &opts); | |
6293 | release_value (v); | |
6294 | value_free (v); | |
6295 | } | |
6296 | } | |
6297 | ||
6298 | die->building_fullname = 0; | |
6299 | ||
6300 | if (!first) | |
6301 | { | |
6302 | /* Close the argument list, with a space if necessary | |
6303 | (nested templates). */ | |
6304 | char last_char = '\0'; | |
6305 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
6306 | if (last_char == '>') | |
6307 | fputs_unfiltered (" >", buf); | |
6308 | else | |
6309 | fputs_unfiltered (">", buf); | |
6310 | } | |
6311 | } | |
6312 | ||
94af9270 KS |
6313 | /* For Java and C++ methods, append formal parameter type |
6314 | information, if PHYSNAME. */ | |
6e70227d | 6315 | |
94af9270 KS |
6316 | if (physname && die->tag == DW_TAG_subprogram |
6317 | && (cu->language == language_cplus | |
6318 | || cu->language == language_java)) | |
6319 | { | |
6320 | struct type *type = read_type_die (die, cu); | |
6321 | ||
3167638f | 6322 | c_type_print_args (type, buf, 1, cu->language); |
94af9270 KS |
6323 | |
6324 | if (cu->language == language_java) | |
6325 | { | |
6326 | /* For java, we must append the return type to method | |
0963b4bd | 6327 | names. */ |
94af9270 KS |
6328 | if (die->tag == DW_TAG_subprogram) |
6329 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
6330 | 0, 0); | |
6331 | } | |
6332 | else if (cu->language == language_cplus) | |
6333 | { | |
60430eff DJ |
6334 | /* Assume that an artificial first parameter is |
6335 | "this", but do not crash if it is not. RealView | |
6336 | marks unnamed (and thus unused) parameters as | |
6337 | artificial; there is no way to differentiate | |
6338 | the two cases. */ | |
94af9270 KS |
6339 | if (TYPE_NFIELDS (type) > 0 |
6340 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 6341 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
6342 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
6343 | 0)))) | |
94af9270 KS |
6344 | fputs_unfiltered (" const", buf); |
6345 | } | |
6346 | } | |
6347 | ||
bb5ed363 | 6348 | name = ui_file_obsavestring (buf, &objfile->objfile_obstack, |
94af9270 KS |
6349 | &length); |
6350 | ui_file_delete (buf); | |
6351 | ||
6352 | if (cu->language == language_cplus) | |
6353 | { | |
6354 | char *cname | |
6355 | = dwarf2_canonicalize_name (name, cu, | |
bb5ed363 | 6356 | &objfile->objfile_obstack); |
9a619af0 | 6357 | |
94af9270 KS |
6358 | if (cname != NULL) |
6359 | name = cname; | |
6360 | } | |
6361 | } | |
6362 | } | |
6363 | ||
6364 | return name; | |
6365 | } | |
6366 | ||
0114d602 DJ |
6367 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
6368 | If scope qualifiers are appropriate they will be added. The result | |
6369 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
6370 | not have a name. NAME may either be from a previous call to |
6371 | dwarf2_name or NULL. | |
6372 | ||
0963b4bd | 6373 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
6374 | |
6375 | static const char * | |
94af9270 | 6376 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 6377 | { |
94af9270 KS |
6378 | return dwarf2_compute_name (name, die, cu, 0); |
6379 | } | |
0114d602 | 6380 | |
94af9270 KS |
6381 | /* Construct a physname for the given DIE in CU. NAME may either be |
6382 | from a previous call to dwarf2_name or NULL. The result will be | |
6383 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
6384 | name. | |
0114d602 | 6385 | |
94af9270 | 6386 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 6387 | |
94af9270 KS |
6388 | static const char * |
6389 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
6390 | { | |
bb5ed363 | 6391 | struct objfile *objfile = cu->objfile; |
900e11f9 JK |
6392 | struct attribute *attr; |
6393 | const char *retval, *mangled = NULL, *canon = NULL; | |
6394 | struct cleanup *back_to; | |
6395 | int need_copy = 1; | |
6396 | ||
6397 | /* In this case dwarf2_compute_name is just a shortcut not building anything | |
6398 | on its own. */ | |
6399 | if (!die_needs_namespace (die, cu)) | |
6400 | return dwarf2_compute_name (name, die, cu, 1); | |
6401 | ||
6402 | back_to = make_cleanup (null_cleanup, NULL); | |
6403 | ||
6404 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
6405 | if (!attr) | |
6406 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
6407 | ||
6408 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB | |
6409 | has computed. */ | |
6410 | if (attr && DW_STRING (attr)) | |
6411 | { | |
6412 | char *demangled; | |
6413 | ||
6414 | mangled = DW_STRING (attr); | |
6415 | ||
6416 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return | |
6417 | type. It is easier for GDB users to search for such functions as | |
6418 | `name(params)' than `long name(params)'. In such case the minimal | |
6419 | symbol names do not match the full symbol names but for template | |
6420 | functions there is never a need to look up their definition from their | |
6421 | declaration so the only disadvantage remains the minimal symbol | |
6422 | variant `long name(params)' does not have the proper inferior type. | |
6423 | */ | |
6424 | ||
a766d390 DE |
6425 | if (cu->language == language_go) |
6426 | { | |
6427 | /* This is a lie, but we already lie to the caller new_symbol_full. | |
6428 | new_symbol_full assumes we return the mangled name. | |
6429 | This just undoes that lie until things are cleaned up. */ | |
6430 | demangled = NULL; | |
6431 | } | |
6432 | else | |
6433 | { | |
6434 | demangled = cplus_demangle (mangled, | |
6435 | (DMGL_PARAMS | DMGL_ANSI | |
6436 | | (cu->language == language_java | |
6437 | ? DMGL_JAVA | DMGL_RET_POSTFIX | |
6438 | : DMGL_RET_DROP))); | |
6439 | } | |
900e11f9 JK |
6440 | if (demangled) |
6441 | { | |
6442 | make_cleanup (xfree, demangled); | |
6443 | canon = demangled; | |
6444 | } | |
6445 | else | |
6446 | { | |
6447 | canon = mangled; | |
6448 | need_copy = 0; | |
6449 | } | |
6450 | } | |
6451 | ||
6452 | if (canon == NULL || check_physname) | |
6453 | { | |
6454 | const char *physname = dwarf2_compute_name (name, die, cu, 1); | |
6455 | ||
6456 | if (canon != NULL && strcmp (physname, canon) != 0) | |
6457 | { | |
6458 | /* It may not mean a bug in GDB. The compiler could also | |
6459 | compute DW_AT_linkage_name incorrectly. But in such case | |
6460 | GDB would need to be bug-to-bug compatible. */ | |
6461 | ||
6462 | complaint (&symfile_complaints, | |
6463 | _("Computed physname <%s> does not match demangled <%s> " | |
6464 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), | |
b64f50a1 | 6465 | physname, canon, mangled, die->offset.sect_off, objfile->name); |
900e11f9 JK |
6466 | |
6467 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it | |
6468 | is available here - over computed PHYSNAME. It is safer | |
6469 | against both buggy GDB and buggy compilers. */ | |
6470 | ||
6471 | retval = canon; | |
6472 | } | |
6473 | else | |
6474 | { | |
6475 | retval = physname; | |
6476 | need_copy = 0; | |
6477 | } | |
6478 | } | |
6479 | else | |
6480 | retval = canon; | |
6481 | ||
6482 | if (need_copy) | |
6483 | retval = obsavestring (retval, strlen (retval), | |
bb5ed363 | 6484 | &objfile->objfile_obstack); |
900e11f9 JK |
6485 | |
6486 | do_cleanups (back_to); | |
6487 | return retval; | |
0114d602 DJ |
6488 | } |
6489 | ||
27aa8d6a SW |
6490 | /* Read the import statement specified by the given die and record it. */ |
6491 | ||
6492 | static void | |
6493 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
6494 | { | |
bb5ed363 | 6495 | struct objfile *objfile = cu->objfile; |
27aa8d6a | 6496 | struct attribute *import_attr; |
32019081 | 6497 | struct die_info *imported_die, *child_die; |
de4affc9 | 6498 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 6499 | const char *imported_name; |
794684b6 | 6500 | const char *imported_name_prefix; |
13387711 SW |
6501 | const char *canonical_name; |
6502 | const char *import_alias; | |
6503 | const char *imported_declaration = NULL; | |
794684b6 | 6504 | const char *import_prefix; |
32019081 JK |
6505 | VEC (const_char_ptr) *excludes = NULL; |
6506 | struct cleanup *cleanups; | |
13387711 SW |
6507 | |
6508 | char *temp; | |
27aa8d6a SW |
6509 | |
6510 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
6511 | if (import_attr == NULL) | |
6512 | { | |
6513 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
6514 | dwarf_tag_name (die->tag)); | |
6515 | return; | |
6516 | } | |
6517 | ||
de4affc9 CC |
6518 | imported_cu = cu; |
6519 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
6520 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
6521 | if (imported_name == NULL) |
6522 | { | |
6523 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
6524 | ||
6525 | The import in the following code: | |
6526 | namespace A | |
6527 | { | |
6528 | typedef int B; | |
6529 | } | |
6530 | ||
6531 | int main () | |
6532 | { | |
6533 | using A::B; | |
6534 | B b; | |
6535 | return b; | |
6536 | } | |
6537 | ||
6538 | ... | |
6539 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
6540 | <52> DW_AT_decl_file : 1 | |
6541 | <53> DW_AT_decl_line : 6 | |
6542 | <54> DW_AT_import : <0x75> | |
6543 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
6544 | <59> DW_AT_name : B | |
6545 | <5b> DW_AT_decl_file : 1 | |
6546 | <5c> DW_AT_decl_line : 2 | |
6547 | <5d> DW_AT_type : <0x6e> | |
6548 | ... | |
6549 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
6550 | <76> DW_AT_byte_size : 4 | |
6551 | <77> DW_AT_encoding : 5 (signed) | |
6552 | ||
6553 | imports the wrong die ( 0x75 instead of 0x58 ). | |
6554 | This case will be ignored until the gcc bug is fixed. */ | |
6555 | return; | |
6556 | } | |
6557 | ||
82856980 SW |
6558 | /* Figure out the local name after import. */ |
6559 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 6560 | |
794684b6 SW |
6561 | /* Figure out where the statement is being imported to. */ |
6562 | import_prefix = determine_prefix (die, cu); | |
6563 | ||
6564 | /* Figure out what the scope of the imported die is and prepend it | |
6565 | to the name of the imported die. */ | |
de4affc9 | 6566 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 6567 | |
f55ee35c JK |
6568 | if (imported_die->tag != DW_TAG_namespace |
6569 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 6570 | { |
13387711 SW |
6571 | imported_declaration = imported_name; |
6572 | canonical_name = imported_name_prefix; | |
794684b6 | 6573 | } |
13387711 | 6574 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 6575 | { |
13387711 SW |
6576 | temp = alloca (strlen (imported_name_prefix) |
6577 | + 2 + strlen (imported_name) + 1); | |
6578 | strcpy (temp, imported_name_prefix); | |
6579 | strcat (temp, "::"); | |
6580 | strcat (temp, imported_name); | |
6581 | canonical_name = temp; | |
794684b6 | 6582 | } |
13387711 SW |
6583 | else |
6584 | canonical_name = imported_name; | |
794684b6 | 6585 | |
32019081 JK |
6586 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
6587 | ||
6588 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) | |
6589 | for (child_die = die->child; child_die && child_die->tag; | |
6590 | child_die = sibling_die (child_die)) | |
6591 | { | |
6592 | /* DWARF-4: A Fortran use statement with a “rename list” may be | |
6593 | represented by an imported module entry with an import attribute | |
6594 | referring to the module and owned entries corresponding to those | |
6595 | entities that are renamed as part of being imported. */ | |
6596 | ||
6597 | if (child_die->tag != DW_TAG_imported_declaration) | |
6598 | { | |
6599 | complaint (&symfile_complaints, | |
6600 | _("child DW_TAG_imported_declaration expected " | |
6601 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 6602 | child_die->offset.sect_off, objfile->name); |
32019081 JK |
6603 | continue; |
6604 | } | |
6605 | ||
6606 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); | |
6607 | if (import_attr == NULL) | |
6608 | { | |
6609 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
6610 | dwarf_tag_name (child_die->tag)); | |
6611 | continue; | |
6612 | } | |
6613 | ||
6614 | imported_cu = cu; | |
6615 | imported_die = follow_die_ref_or_sig (child_die, import_attr, | |
6616 | &imported_cu); | |
6617 | imported_name = dwarf2_name (imported_die, imported_cu); | |
6618 | if (imported_name == NULL) | |
6619 | { | |
6620 | complaint (&symfile_complaints, | |
6621 | _("child DW_TAG_imported_declaration has unknown " | |
6622 | "imported name - DIE at 0x%x [in module %s]"), | |
b64f50a1 | 6623 | child_die->offset.sect_off, objfile->name); |
32019081 JK |
6624 | continue; |
6625 | } | |
6626 | ||
6627 | VEC_safe_push (const_char_ptr, excludes, imported_name); | |
6628 | ||
6629 | process_die (child_die, cu); | |
6630 | } | |
6631 | ||
c0cc3a76 SW |
6632 | cp_add_using_directive (import_prefix, |
6633 | canonical_name, | |
6634 | import_alias, | |
13387711 | 6635 | imported_declaration, |
32019081 | 6636 | excludes, |
bb5ed363 | 6637 | &objfile->objfile_obstack); |
32019081 JK |
6638 | |
6639 | do_cleanups (cleanups); | |
27aa8d6a SW |
6640 | } |
6641 | ||
ae2de4f8 DE |
6642 | /* Cleanup function for read_file_scope. */ |
6643 | ||
cb1df416 DJ |
6644 | static void |
6645 | free_cu_line_header (void *arg) | |
6646 | { | |
6647 | struct dwarf2_cu *cu = arg; | |
6648 | ||
6649 | free_line_header (cu->line_header); | |
6650 | cu->line_header = NULL; | |
6651 | } | |
6652 | ||
9291a0cd TT |
6653 | static void |
6654 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
6655 | char **name, char **comp_dir) | |
6656 | { | |
6657 | struct attribute *attr; | |
6658 | ||
6659 | *name = NULL; | |
6660 | *comp_dir = NULL; | |
6661 | ||
6662 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
6663 | is not a source language identifier. */ | |
6664 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
6665 | if (attr) | |
6666 | { | |
6667 | *name = DW_STRING (attr); | |
6668 | } | |
6669 | ||
6670 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
6671 | if (attr) | |
6672 | *comp_dir = DW_STRING (attr); | |
6673 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
6674 | { | |
6675 | *comp_dir = ldirname (*name); | |
6676 | if (*comp_dir != NULL) | |
6677 | make_cleanup (xfree, *comp_dir); | |
6678 | } | |
6679 | if (*comp_dir != NULL) | |
6680 | { | |
6681 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
6682 | directory, get rid of it. */ | |
6683 | char *cp = strchr (*comp_dir, ':'); | |
6684 | ||
6685 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
6686 | *comp_dir = cp + 1; | |
6687 | } | |
6688 | ||
6689 | if (*name == NULL) | |
6690 | *name = "<unknown>"; | |
6691 | } | |
6692 | ||
f3f5162e DE |
6693 | /* Handle DW_AT_stmt_list for a compilation unit or type unit. |
6694 | DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU. | |
6695 | COMP_DIR is the compilation directory. | |
6696 | WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */ | |
2ab95328 TT |
6697 | |
6698 | static void | |
6699 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, | |
f3f5162e | 6700 | const char *comp_dir, int want_line_info) |
2ab95328 TT |
6701 | { |
6702 | struct attribute *attr; | |
2ab95328 | 6703 | |
2ab95328 TT |
6704 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
6705 | if (attr) | |
6706 | { | |
6707 | unsigned int line_offset = DW_UNSND (attr); | |
6708 | struct line_header *line_header | |
3019eac3 | 6709 | = dwarf_decode_line_header (line_offset, cu); |
2ab95328 TT |
6710 | |
6711 | if (line_header) | |
dee91e82 DE |
6712 | { |
6713 | cu->line_header = line_header; | |
6714 | make_cleanup (free_cu_line_header, cu); | |
f3f5162e | 6715 | dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info); |
dee91e82 | 6716 | } |
2ab95328 TT |
6717 | } |
6718 | } | |
6719 | ||
95554aad | 6720 | /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */ |
ae2de4f8 | 6721 | |
c906108c | 6722 | static void |
e7c27a73 | 6723 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6724 | { |
dee91e82 | 6725 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
debd256d | 6726 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 6727 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
6728 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
6729 | struct attribute *attr; | |
e1024ff1 | 6730 | char *name = NULL; |
c906108c SS |
6731 | char *comp_dir = NULL; |
6732 | struct die_info *child_die; | |
6733 | bfd *abfd = objfile->obfd; | |
e142c38c | 6734 | CORE_ADDR baseaddr; |
6e70227d | 6735 | |
e142c38c | 6736 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 6737 | |
fae299cd | 6738 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
6739 | |
6740 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
6741 | from finish_block. */ | |
2acceee2 | 6742 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
6743 | lowpc = highpc; |
6744 | lowpc += baseaddr; | |
6745 | highpc += baseaddr; | |
6746 | ||
9291a0cd | 6747 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 6748 | |
95554aad | 6749 | prepare_one_comp_unit (cu, die, cu->language); |
303b6f5d | 6750 | |
f4b8a18d KW |
6751 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
6752 | standardised yet. As a workaround for the language detection we fall | |
6753 | back to the DW_AT_producer string. */ | |
6754 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
6755 | cu->language = language_opencl; | |
6756 | ||
3019eac3 DE |
6757 | /* Similar hack for Go. */ |
6758 | if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL) | |
6759 | set_cu_language (DW_LANG_Go, cu); | |
6760 | ||
6761 | /* We assume that we're processing GCC output. */ | |
6762 | processing_gcc_compilation = 2; | |
6763 | ||
6764 | processing_has_namespace_info = 0; | |
6765 | ||
6766 | start_symtab (name, comp_dir, lowpc); | |
6767 | record_debugformat ("DWARF 2"); | |
6768 | record_producer (cu->producer); | |
6769 | ||
6770 | /* Decode line number information if present. We do this before | |
6771 | processing child DIEs, so that the line header table is available | |
6772 | for DW_AT_decl_file. */ | |
6773 | handle_DW_AT_stmt_list (die, cu, comp_dir, 1); | |
6774 | ||
6775 | /* Process all dies in compilation unit. */ | |
6776 | if (die->child != NULL) | |
6777 | { | |
6778 | child_die = die->child; | |
6779 | while (child_die && child_die->tag) | |
6780 | { | |
6781 | process_die (child_die, cu); | |
6782 | child_die = sibling_die (child_die); | |
6783 | } | |
6784 | } | |
6785 | ||
6786 | /* Decode macro information, if present. Dwarf 2 macro information | |
6787 | refers to information in the line number info statement program | |
6788 | header, so we can only read it if we've read the header | |
6789 | successfully. */ | |
6790 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); | |
6791 | if (attr && cu->line_header) | |
6792 | { | |
6793 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) | |
6794 | complaint (&symfile_complaints, | |
6795 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); | |
6796 | ||
09262596 | 6797 | dwarf_decode_macros (cu, DW_UNSND (attr), comp_dir, 1); |
3019eac3 DE |
6798 | } |
6799 | else | |
6800 | { | |
6801 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |
6802 | if (attr && cu->line_header) | |
6803 | { | |
6804 | unsigned int macro_offset = DW_UNSND (attr); | |
6805 | ||
09262596 | 6806 | dwarf_decode_macros (cu, macro_offset, comp_dir, 0); |
3019eac3 DE |
6807 | } |
6808 | } | |
6809 | ||
6810 | do_cleanups (back_to); | |
6811 | } | |
6812 | ||
6813 | /* Process DW_TAG_type_unit. | |
6814 | For TUs we want to skip the first top level sibling if it's not the | |
6815 | actual type being defined by this TU. In this case the first top | |
6816 | level sibling is there to provide context only. */ | |
6817 | ||
6818 | static void | |
6819 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6820 | { | |
6821 | struct objfile *objfile = cu->objfile; | |
6822 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
6823 | CORE_ADDR lowpc; | |
6824 | struct attribute *attr; | |
6825 | char *name = NULL; | |
6826 | char *comp_dir = NULL; | |
6827 | struct die_info *child_die; | |
6828 | bfd *abfd = objfile->obfd; | |
6829 | ||
6830 | /* start_symtab needs a low pc, but we don't really have one. | |
6831 | Do what read_file_scope would do in the absence of such info. */ | |
6832 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6833 | ||
6834 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
6835 | is not a source language identifier. */ | |
6836 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
6837 | if (attr) | |
6838 | name = DW_STRING (attr); | |
6839 | ||
6840 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
6841 | if (attr) | |
6842 | comp_dir = DW_STRING (attr); | |
6843 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
6844 | { | |
6845 | comp_dir = ldirname (name); | |
6846 | if (comp_dir != NULL) | |
6847 | make_cleanup (xfree, comp_dir); | |
6848 | } | |
6849 | ||
6850 | if (name == NULL) | |
6851 | name = "<unknown>"; | |
6852 | ||
95554aad | 6853 | prepare_one_comp_unit (cu, die, language_minimal); |
3019eac3 DE |
6854 | |
6855 | /* We assume that we're processing GCC output. */ | |
6856 | processing_gcc_compilation = 2; | |
6857 | ||
6858 | processing_has_namespace_info = 0; | |
6859 | ||
6860 | start_symtab (name, comp_dir, lowpc); | |
6861 | record_debugformat ("DWARF 2"); | |
6862 | record_producer (cu->producer); | |
6863 | ||
6864 | /* Decode line number information if present. We do this before | |
6865 | processing child DIEs, so that the line header table is available | |
6866 | for DW_AT_decl_file. | |
6867 | We don't need the pc/line-number mapping for type units. */ | |
6868 | handle_DW_AT_stmt_list (die, cu, comp_dir, 0); | |
6869 | ||
6870 | /* Process the dies in the type unit. */ | |
6871 | if (die->child == NULL) | |
6872 | { | |
6873 | dump_die_for_error (die); | |
6874 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
6875 | bfd_get_filename (abfd)); | |
6876 | } | |
6877 | ||
6878 | child_die = die->child; | |
6879 | ||
6880 | while (child_die && child_die->tag) | |
6881 | { | |
6882 | process_die (child_die, cu); | |
6883 | ||
6884 | child_die = sibling_die (child_die); | |
6885 | } | |
6886 | ||
6887 | do_cleanups (back_to); | |
6888 | } | |
6889 | \f | |
6890 | /* DWO files. */ | |
6891 | ||
6892 | static hashval_t | |
6893 | hash_dwo_file (const void *item) | |
6894 | { | |
6895 | const struct dwo_file *dwo_file = item; | |
6896 | ||
6897 | return htab_hash_string (dwo_file->dwo_name); | |
6898 | } | |
6899 | ||
6900 | static int | |
6901 | eq_dwo_file (const void *item_lhs, const void *item_rhs) | |
6902 | { | |
6903 | const struct dwo_file *lhs = item_lhs; | |
6904 | const struct dwo_file *rhs = item_rhs; | |
6905 | ||
6906 | return strcmp (lhs->dwo_name, rhs->dwo_name) == 0; | |
6907 | } | |
6908 | ||
6909 | /* Allocate a hash table for DWO files. */ | |
6910 | ||
6911 | static htab_t | |
6912 | allocate_dwo_file_hash_table (void) | |
6913 | { | |
6914 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
6915 | ||
6916 | return htab_create_alloc_ex (41, | |
6917 | hash_dwo_file, | |
6918 | eq_dwo_file, | |
6919 | NULL, | |
6920 | &objfile->objfile_obstack, | |
6921 | hashtab_obstack_allocate, | |
6922 | dummy_obstack_deallocate); | |
6923 | } | |
6924 | ||
6925 | static hashval_t | |
6926 | hash_dwo_unit (const void *item) | |
6927 | { | |
6928 | const struct dwo_unit *dwo_unit = item; | |
6929 | ||
6930 | /* This drops the top 32 bits of the id, but is ok for a hash. */ | |
6931 | return dwo_unit->signature; | |
6932 | } | |
6933 | ||
6934 | static int | |
6935 | eq_dwo_unit (const void *item_lhs, const void *item_rhs) | |
6936 | { | |
6937 | const struct dwo_unit *lhs = item_lhs; | |
6938 | const struct dwo_unit *rhs = item_rhs; | |
6939 | ||
6940 | /* The signature is assumed to be unique within the DWO file. | |
6941 | So while object file CU dwo_id's always have the value zero, | |
6942 | that's OK, assuming each object file DWO file has only one CU, | |
6943 | and that's the rule for now. */ | |
6944 | return lhs->signature == rhs->signature; | |
6945 | } | |
6946 | ||
6947 | /* Allocate a hash table for DWO CUs,TUs. | |
6948 | There is one of these tables for each of CUs,TUs for each DWO file. */ | |
6949 | ||
6950 | static htab_t | |
6951 | allocate_dwo_unit_table (struct objfile *objfile) | |
6952 | { | |
6953 | /* Start out with a pretty small number. | |
6954 | Generally DWO files contain only one CU and maybe some TUs. */ | |
6955 | return htab_create_alloc_ex (3, | |
6956 | hash_dwo_unit, | |
6957 | eq_dwo_unit, | |
6958 | NULL, | |
6959 | &objfile->objfile_obstack, | |
6960 | hashtab_obstack_allocate, | |
6961 | dummy_obstack_deallocate); | |
6962 | } | |
6963 | ||
6964 | /* This function is mapped across the sections and remembers the offset and | |
6965 | size of each of the DWO debugging sections we are interested in. */ | |
6966 | ||
6967 | static void | |
6968 | dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_file_ptr) | |
6969 | { | |
6970 | struct dwo_file *dwo_file = dwo_file_ptr; | |
6971 | const struct dwo_section_names *names = &dwo_section_names; | |
6972 | ||
6973 | if (section_is_p (sectp->name, &names->abbrev_dwo)) | |
6974 | { | |
6975 | dwo_file->sections.abbrev.asection = sectp; | |
6976 | dwo_file->sections.abbrev.size = bfd_get_section_size (sectp); | |
6977 | } | |
6978 | else if (section_is_p (sectp->name, &names->info_dwo)) | |
6979 | { | |
6980 | dwo_file->sections.info.asection = sectp; | |
6981 | dwo_file->sections.info.size = bfd_get_section_size (sectp); | |
6982 | } | |
6983 | else if (section_is_p (sectp->name, &names->line_dwo)) | |
6984 | { | |
6985 | dwo_file->sections.line.asection = sectp; | |
6986 | dwo_file->sections.line.size = bfd_get_section_size (sectp); | |
6987 | } | |
6988 | else if (section_is_p (sectp->name, &names->loc_dwo)) | |
6989 | { | |
6990 | dwo_file->sections.loc.asection = sectp; | |
6991 | dwo_file->sections.loc.size = bfd_get_section_size (sectp); | |
6992 | } | |
09262596 DE |
6993 | else if (section_is_p (sectp->name, &names->macinfo_dwo)) |
6994 | { | |
6995 | dwo_file->sections.macinfo.asection = sectp; | |
6996 | dwo_file->sections.macinfo.size = bfd_get_section_size (sectp); | |
6997 | } | |
6998 | else if (section_is_p (sectp->name, &names->macro_dwo)) | |
6999 | { | |
7000 | dwo_file->sections.macro.asection = sectp; | |
7001 | dwo_file->sections.macro.size = bfd_get_section_size (sectp); | |
7002 | } | |
3019eac3 DE |
7003 | else if (section_is_p (sectp->name, &names->str_dwo)) |
7004 | { | |
7005 | dwo_file->sections.str.asection = sectp; | |
7006 | dwo_file->sections.str.size = bfd_get_section_size (sectp); | |
7007 | } | |
7008 | else if (section_is_p (sectp->name, &names->str_offsets_dwo)) | |
7009 | { | |
7010 | dwo_file->sections.str_offsets.asection = sectp; | |
7011 | dwo_file->sections.str_offsets.size = bfd_get_section_size (sectp); | |
7012 | } | |
7013 | else if (section_is_p (sectp->name, &names->types_dwo)) | |
7014 | { | |
7015 | struct dwarf2_section_info type_section; | |
7016 | ||
7017 | memset (&type_section, 0, sizeof (type_section)); | |
7018 | type_section.asection = sectp; | |
7019 | type_section.size = bfd_get_section_size (sectp); | |
7020 | VEC_safe_push (dwarf2_section_info_def, dwo_file->sections.types, | |
7021 | &type_section); | |
7022 | } | |
7023 | } | |
7024 | ||
7025 | /* Structure used to pass data to create_debug_info_hash_table_reader. */ | |
7026 | ||
7027 | struct create_dwo_info_table_data | |
7028 | { | |
7029 | struct dwo_file *dwo_file; | |
7030 | htab_t cu_htab; | |
7031 | }; | |
7032 | ||
7033 | /* die_reader_func for create_debug_info_hash_table. */ | |
7034 | ||
7035 | static void | |
7036 | create_debug_info_hash_table_reader (const struct die_reader_specs *reader, | |
7037 | gdb_byte *info_ptr, | |
7038 | struct die_info *comp_unit_die, | |
7039 | int has_children, | |
7040 | void *datap) | |
7041 | { | |
7042 | struct dwarf2_cu *cu = reader->cu; | |
7043 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
7044 | sect_offset offset = cu->per_cu->offset; | |
7045 | struct dwarf2_section_info *section = cu->per_cu->info_or_types_section; | |
7046 | struct create_dwo_info_table_data *data = datap; | |
7047 | struct dwo_file *dwo_file = data->dwo_file; | |
7048 | htab_t cu_htab = data->cu_htab; | |
7049 | void **slot; | |
7050 | struct attribute *attr; | |
7051 | struct dwo_unit *dwo_unit; | |
7052 | ||
7053 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); | |
7054 | if (attr == NULL) | |
7055 | { | |
7056 | error (_("Dwarf Error: debug entry at offset 0x%x is missing" | |
7057 | " its dwo_id [in module %s]"), | |
7058 | offset.sect_off, dwo_file->dwo_name); | |
7059 | return; | |
7060 | } | |
7061 | ||
7062 | dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); | |
7063 | dwo_unit->dwo_file = dwo_file; | |
7064 | dwo_unit->signature = DW_UNSND (attr); | |
7065 | dwo_unit->info_or_types_section = section; | |
7066 | dwo_unit->offset = offset; | |
7067 | dwo_unit->length = cu->per_cu->length; | |
7068 | ||
7069 | slot = htab_find_slot (cu_htab, dwo_unit, INSERT); | |
7070 | gdb_assert (slot != NULL); | |
7071 | if (*slot != NULL) | |
7072 | { | |
7073 | const struct dwo_unit *dup_dwo_unit = *slot; | |
7074 | ||
7075 | complaint (&symfile_complaints, | |
7076 | _("debug entry at offset 0x%x is duplicate to the entry at" | |
7077 | " offset 0x%x, dwo_id 0x%s [in module %s]"), | |
7078 | offset.sect_off, dup_dwo_unit->offset.sect_off, | |
7079 | phex (dwo_unit->signature, sizeof (dwo_unit->signature)), | |
7080 | dwo_file->dwo_name); | |
7081 | } | |
7082 | else | |
7083 | *slot = dwo_unit; | |
7084 | ||
7085 | if (dwarf2_die_debug) | |
7086 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, dwo_id 0x%s\n", | |
7087 | offset.sect_off, | |
7088 | phex (dwo_unit->signature, | |
7089 | sizeof (dwo_unit->signature))); | |
7090 | } | |
7091 | ||
7092 | /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */ | |
7093 | ||
7094 | static htab_t | |
7095 | create_debug_info_hash_table (struct dwo_file *dwo_file) | |
7096 | { | |
7097 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
7098 | struct dwarf2_section_info *section = &dwo_file->sections.info; | |
7099 | bfd *abfd; | |
7100 | htab_t cu_htab; | |
7101 | gdb_byte *info_ptr, *end_ptr; | |
7102 | struct create_dwo_info_table_data create_dwo_info_table_data; | |
7103 | ||
7104 | dwarf2_read_section (objfile, section); | |
7105 | info_ptr = section->buffer; | |
7106 | ||
7107 | if (info_ptr == NULL) | |
7108 | return NULL; | |
7109 | ||
7110 | /* We can't set abfd until now because the section may be empty or | |
7111 | not present, in which case section->asection will be NULL. */ | |
7112 | abfd = section->asection->owner; | |
7113 | ||
7114 | if (dwarf2_die_debug) | |
7115 | fprintf_unfiltered (gdb_stdlog, "Reading .debug_info.dwo for %s:\n", | |
7116 | bfd_get_filename (abfd)); | |
7117 | ||
7118 | cu_htab = allocate_dwo_unit_table (objfile); | |
7119 | ||
7120 | create_dwo_info_table_data.dwo_file = dwo_file; | |
7121 | create_dwo_info_table_data.cu_htab = cu_htab; | |
7122 | ||
7123 | end_ptr = info_ptr + section->size; | |
7124 | while (info_ptr < end_ptr) | |
7125 | { | |
7126 | struct dwarf2_per_cu_data per_cu; | |
7127 | ||
7128 | memset (&per_cu, 0, sizeof (per_cu)); | |
7129 | per_cu.objfile = objfile; | |
7130 | per_cu.is_debug_types = 0; | |
7131 | per_cu.offset.sect_off = info_ptr - section->buffer; | |
7132 | per_cu.info_or_types_section = section; | |
7133 | ||
7134 | init_cutu_and_read_dies_no_follow (&per_cu, | |
7135 | &dwo_file->sections.abbrev, | |
7136 | dwo_file, | |
7137 | create_debug_info_hash_table_reader, | |
7138 | &create_dwo_info_table_data); | |
7139 | ||
7140 | info_ptr += per_cu.length; | |
7141 | } | |
7142 | ||
7143 | return cu_htab; | |
7144 | } | |
7145 | ||
7146 | /* Subroutine of open_dwo_file to simplify it. | |
7147 | Open the file specified by FILE_NAME and hand it off to BFD for | |
7148 | preliminary analysis. Return a newly initialized bfd *, which | |
7149 | includes a canonicalized copy of FILE_NAME. | |
7150 | In case of trouble, return NULL. | |
7151 | NOTE: This function is derived from symfile_bfd_open. */ | |
7152 | ||
7153 | static bfd * | |
7154 | try_open_dwo_file (const char *file_name) | |
7155 | { | |
7156 | bfd *sym_bfd; | |
7157 | int desc; | |
7158 | char *absolute_name; | |
3019eac3 DE |
7159 | |
7160 | desc = openp (debug_file_directory, OPF_TRY_CWD_FIRST, file_name, | |
7161 | O_RDONLY | O_BINARY, &absolute_name); | |
7162 | if (desc < 0) | |
7163 | return NULL; | |
7164 | ||
7165 | sym_bfd = bfd_fopen (absolute_name, gnutarget, FOPEN_RB, desc); | |
7166 | if (!sym_bfd) | |
7167 | { | |
3019eac3 DE |
7168 | xfree (absolute_name); |
7169 | return NULL; | |
7170 | } | |
7171 | bfd_set_cacheable (sym_bfd, 1); | |
7172 | ||
7173 | if (!bfd_check_format (sym_bfd, bfd_object)) | |
7174 | { | |
7175 | bfd_close (sym_bfd); /* This also closes desc. */ | |
7176 | xfree (absolute_name); | |
7177 | return NULL; | |
7178 | } | |
7179 | ||
7180 | /* bfd_usrdata exists for applications and libbfd must not touch it. */ | |
7181 | gdb_assert (bfd_usrdata (sym_bfd) == NULL); | |
7182 | ||
7183 | return sym_bfd; | |
7184 | } | |
7185 | ||
7186 | /* Try to open DWO file DWO_NAME. | |
7187 | COMP_DIR is the DW_AT_comp_dir attribute. | |
7188 | The result is the bfd handle of the file. | |
7189 | If there is a problem finding or opening the file, return NULL. | |
7190 | Upon success, the canonicalized path of the file is stored in the bfd, | |
7191 | same as symfile_bfd_open. */ | |
7192 | ||
7193 | static bfd * | |
7194 | open_dwo_file (const char *dwo_name, const char *comp_dir) | |
7195 | { | |
7196 | bfd *abfd; | |
3019eac3 DE |
7197 | |
7198 | if (IS_ABSOLUTE_PATH (dwo_name)) | |
7199 | return try_open_dwo_file (dwo_name); | |
7200 | ||
7201 | /* Before trying the search path, try DWO_NAME in COMP_DIR. */ | |
7202 | ||
7203 | if (comp_dir != NULL) | |
7204 | { | |
7205 | char *path_to_try = concat (comp_dir, SLASH_STRING, dwo_name, NULL); | |
7206 | ||
7207 | /* NOTE: If comp_dir is a relative path, this will also try the | |
7208 | search path, which seems useful. */ | |
7209 | abfd = try_open_dwo_file (path_to_try); | |
7210 | xfree (path_to_try); | |
7211 | if (abfd != NULL) | |
7212 | return abfd; | |
7213 | } | |
7214 | ||
7215 | /* That didn't work, try debug-file-directory, which, despite its name, | |
7216 | is a list of paths. */ | |
7217 | ||
7218 | if (*debug_file_directory == '\0') | |
7219 | return NULL; | |
7220 | ||
7221 | return try_open_dwo_file (dwo_name); | |
7222 | } | |
7223 | ||
7224 | /* Initialize the use of the DWO file specified by DWO_NAME. */ | |
7225 | ||
7226 | static struct dwo_file * | |
7227 | init_dwo_file (const char *dwo_name, const char *comp_dir) | |
7228 | { | |
7229 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
7230 | struct dwo_file *dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
7231 | struct dwo_file); | |
7232 | bfd *abfd; | |
7233 | struct cleanup *cleanups; | |
7234 | ||
7235 | if (dwarf2_die_debug) | |
7236 | fprintf_unfiltered (gdb_stdlog, "Reading DWO file %s:\n", dwo_name); | |
7237 | ||
7238 | abfd = open_dwo_file (dwo_name, comp_dir); | |
7239 | if (abfd == NULL) | |
7240 | return NULL; | |
7241 | dwo_file->dwo_name = dwo_name; | |
7242 | dwo_file->dwo_bfd = abfd; | |
7243 | ||
7244 | cleanups = make_cleanup (free_dwo_file_cleanup, dwo_file); | |
7245 | ||
7246 | bfd_map_over_sections (abfd, dwarf2_locate_dwo_sections, dwo_file); | |
7247 | ||
7248 | dwo_file->cus = create_debug_info_hash_table (dwo_file); | |
7249 | ||
7250 | dwo_file->tus = create_debug_types_hash_table (dwo_file, | |
7251 | dwo_file->sections.types); | |
7252 | ||
7253 | discard_cleanups (cleanups); | |
7254 | ||
7255 | return dwo_file; | |
7256 | } | |
7257 | ||
7258 | /* Lookup DWO file DWO_NAME. */ | |
7259 | ||
7260 | static struct dwo_file * | |
7261 | lookup_dwo_file (char *dwo_name, const char *comp_dir) | |
7262 | { | |
7263 | struct dwo_file *dwo_file; | |
7264 | struct dwo_file find_entry; | |
7265 | void **slot; | |
7266 | ||
7267 | if (dwarf2_per_objfile->dwo_files == NULL) | |
7268 | dwarf2_per_objfile->dwo_files = allocate_dwo_file_hash_table (); | |
7269 | ||
7270 | /* Have we already seen this DWO file? */ | |
7271 | find_entry.dwo_name = dwo_name; | |
7272 | slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT); | |
7273 | ||
7274 | /* If not, read it in and build a table of the DWOs it contains. */ | |
7275 | if (*slot == NULL) | |
7276 | *slot = init_dwo_file (dwo_name, comp_dir); | |
7277 | ||
7278 | /* NOTE: This will be NULL if unable to open the file. */ | |
7279 | dwo_file = *slot; | |
7280 | ||
7281 | return dwo_file; | |
7282 | } | |
7283 | ||
7284 | /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME. | |
7285 | If non-NULL, comp_dir is the DW_AT_comp_dir attribute. | |
7286 | SIGNATURE is the "dwo_id" of the CU (for consistency we use the same | |
7287 | nomenclature as TUs). | |
1c658ad5 | 7288 | The result is a pointer to the dwo_unit object or NULL if we didn't find it |
3019eac3 DE |
7289 | (dwo_id mismatch or couldn't find the DWO file). */ |
7290 | ||
7291 | static struct dwo_unit * | |
7292 | lookup_dwo_comp_unit (struct dwarf2_per_cu_data *this_cu, | |
7293 | char *dwo_name, const char *comp_dir, | |
7294 | ULONGEST signature) | |
7295 | { | |
7296 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
7297 | struct dwo_file *dwo_file; | |
7298 | ||
7299 | dwo_file = lookup_dwo_file (dwo_name, comp_dir); | |
7300 | if (dwo_file == NULL) | |
7301 | return NULL; | |
7302 | ||
7303 | /* Look up the DWO using its signature(dwo_id). */ | |
7304 | ||
7305 | if (dwo_file->cus != NULL) | |
7306 | { | |
7307 | struct dwo_unit find_dwo_cu, *dwo_cu; | |
7308 | ||
7309 | find_dwo_cu.signature = signature; | |
7310 | dwo_cu = htab_find (dwo_file->cus, &find_dwo_cu); | |
a766d390 | 7311 | |
3019eac3 DE |
7312 | if (dwo_cu != NULL) |
7313 | return dwo_cu; | |
7314 | } | |
c906108c | 7315 | |
3019eac3 | 7316 | /* We didn't find it. This must mean a dwo_id mismatch. */ |
df8a16a1 | 7317 | |
3019eac3 DE |
7318 | complaint (&symfile_complaints, |
7319 | _("Could not find DWO CU referenced by CU at offset 0x%x" | |
7320 | " [in module %s]"), | |
7321 | this_cu->offset.sect_off, objfile->name); | |
7322 | return NULL; | |
7323 | } | |
c906108c | 7324 | |
3019eac3 DE |
7325 | /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME. |
7326 | If non-NULL, comp_dir is the DW_AT_comp_dir attribute. | |
1c658ad5 | 7327 | The result is a pointer to the dwo_unit object or NULL if we didn't find it |
3019eac3 | 7328 | (dwo_id mismatch or couldn't find the DWO file). */ |
debd256d | 7329 | |
3019eac3 DE |
7330 | static struct dwo_unit * |
7331 | lookup_dwo_type_unit (struct signatured_type *this_tu, | |
7332 | char *dwo_name, const char *comp_dir) | |
7333 | { | |
7334 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
7335 | struct dwo_file *dwo_file; | |
cb1df416 | 7336 | |
3019eac3 DE |
7337 | dwo_file = lookup_dwo_file (dwo_name, comp_dir); |
7338 | if (dwo_file == NULL) | |
7339 | return NULL; | |
cf2c3c16 | 7340 | |
3019eac3 DE |
7341 | /* Look up the DWO using its signature(dwo_id). */ |
7342 | ||
7343 | if (dwo_file->tus != NULL) | |
cf2c3c16 | 7344 | { |
3019eac3 | 7345 | struct dwo_unit find_dwo_tu, *dwo_tu; |
9a619af0 | 7346 | |
3019eac3 DE |
7347 | find_dwo_tu.signature = this_tu->signature; |
7348 | dwo_tu = htab_find (dwo_file->tus, &find_dwo_tu); | |
7349 | ||
7350 | if (dwo_tu != NULL) | |
7351 | return dwo_tu; | |
2e276125 | 7352 | } |
9cdd5dbd | 7353 | |
3019eac3 DE |
7354 | /* We didn't find it. This must mean a dwo_id mismatch. */ |
7355 | ||
7356 | complaint (&symfile_complaints, | |
7357 | _("Could not find DWO TU referenced by TU at offset 0x%x" | |
7358 | " [in module %s]"), | |
7359 | this_tu->per_cu.offset.sect_off, objfile->name); | |
7360 | return NULL; | |
5fb290d7 DJ |
7361 | } |
7362 | ||
3019eac3 DE |
7363 | /* Free all resources associated with DWO_FILE. |
7364 | Close the DWO file and munmap the sections. | |
7365 | All memory should be on the objfile obstack. */ | |
348e048f DE |
7366 | |
7367 | static void | |
3019eac3 | 7368 | free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile) |
348e048f | 7369 | { |
3019eac3 DE |
7370 | int ix; |
7371 | struct dwarf2_section_info *section; | |
348e048f | 7372 | |
3019eac3 DE |
7373 | gdb_assert (dwo_file->dwo_bfd != objfile->obfd); |
7374 | bfd_close (dwo_file->dwo_bfd); | |
348e048f | 7375 | |
3019eac3 DE |
7376 | munmap_section_buffer (&dwo_file->sections.abbrev); |
7377 | munmap_section_buffer (&dwo_file->sections.info); | |
7378 | munmap_section_buffer (&dwo_file->sections.line); | |
7379 | munmap_section_buffer (&dwo_file->sections.loc); | |
7380 | munmap_section_buffer (&dwo_file->sections.str); | |
7381 | munmap_section_buffer (&dwo_file->sections.str_offsets); | |
348e048f | 7382 | |
3019eac3 DE |
7383 | for (ix = 0; |
7384 | VEC_iterate (dwarf2_section_info_def, dwo_file->sections.types, | |
7385 | ix, section); | |
7386 | ++ix) | |
7387 | munmap_section_buffer (section); | |
348e048f | 7388 | |
3019eac3 DE |
7389 | VEC_free (dwarf2_section_info_def, dwo_file->sections.types); |
7390 | } | |
348e048f | 7391 | |
3019eac3 | 7392 | /* Wrapper for free_dwo_file for use in cleanups. */ |
348e048f | 7393 | |
3019eac3 DE |
7394 | static void |
7395 | free_dwo_file_cleanup (void *arg) | |
7396 | { | |
7397 | struct dwo_file *dwo_file = (struct dwo_file *) arg; | |
7398 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
348e048f | 7399 | |
3019eac3 DE |
7400 | free_dwo_file (dwo_file, objfile); |
7401 | } | |
348e048f | 7402 | |
3019eac3 | 7403 | /* Traversal function for free_dwo_files. */ |
2ab95328 | 7404 | |
3019eac3 DE |
7405 | static int |
7406 | free_dwo_file_from_slot (void **slot, void *info) | |
7407 | { | |
7408 | struct dwo_file *dwo_file = (struct dwo_file *) *slot; | |
7409 | struct objfile *objfile = (struct objfile *) info; | |
348e048f | 7410 | |
3019eac3 | 7411 | free_dwo_file (dwo_file, objfile); |
348e048f | 7412 | |
3019eac3 DE |
7413 | return 1; |
7414 | } | |
348e048f | 7415 | |
3019eac3 | 7416 | /* Free all resources associated with DWO_FILES. */ |
348e048f | 7417 | |
3019eac3 DE |
7418 | static void |
7419 | free_dwo_files (htab_t dwo_files, struct objfile *objfile) | |
7420 | { | |
7421 | htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile); | |
348e048f | 7422 | } |
3019eac3 DE |
7423 | \f |
7424 | /* Read in various DIEs. */ | |
348e048f | 7425 | |
d389af10 JK |
7426 | /* qsort helper for inherit_abstract_dies. */ |
7427 | ||
7428 | static int | |
7429 | unsigned_int_compar (const void *ap, const void *bp) | |
7430 | { | |
7431 | unsigned int a = *(unsigned int *) ap; | |
7432 | unsigned int b = *(unsigned int *) bp; | |
7433 | ||
7434 | return (a > b) - (b > a); | |
7435 | } | |
7436 | ||
7437 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
7438 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
7439 | already referenced by DW_AT_abstract_origin from the children of the | |
7440 | current DIE. */ | |
d389af10 JK |
7441 | |
7442 | static void | |
7443 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
7444 | { | |
7445 | struct die_info *child_die; | |
7446 | unsigned die_children_count; | |
7447 | /* CU offsets which were referenced by children of the current DIE. */ | |
b64f50a1 JK |
7448 | sect_offset *offsets; |
7449 | sect_offset *offsets_end, *offsetp; | |
d389af10 JK |
7450 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ |
7451 | struct die_info *origin_die; | |
7452 | /* Iterator of the ORIGIN_DIE children. */ | |
7453 | struct die_info *origin_child_die; | |
7454 | struct cleanup *cleanups; | |
7455 | struct attribute *attr; | |
cd02d79d PA |
7456 | struct dwarf2_cu *origin_cu; |
7457 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
7458 | |
7459 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
7460 | if (!attr) | |
7461 | return; | |
7462 | ||
cd02d79d PA |
7463 | /* Note that following die references may follow to a die in a |
7464 | different cu. */ | |
7465 | ||
7466 | origin_cu = cu; | |
7467 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
7468 | ||
7469 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
7470 | symbols in. */ | |
7471 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
7472 | origin_cu->list_in_scope = cu->list_in_scope; | |
7473 | ||
edb3359d DJ |
7474 | if (die->tag != origin_die->tag |
7475 | && !(die->tag == DW_TAG_inlined_subroutine | |
7476 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
7477 | complaint (&symfile_complaints, |
7478 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
b64f50a1 | 7479 | die->offset.sect_off, origin_die->offset.sect_off); |
d389af10 JK |
7480 | |
7481 | child_die = die->child; | |
7482 | die_children_count = 0; | |
7483 | while (child_die && child_die->tag) | |
7484 | { | |
7485 | child_die = sibling_die (child_die); | |
7486 | die_children_count++; | |
7487 | } | |
7488 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
7489 | cleanups = make_cleanup (xfree, offsets); | |
7490 | ||
7491 | offsets_end = offsets; | |
7492 | child_die = die->child; | |
7493 | while (child_die && child_die->tag) | |
7494 | { | |
c38f313d DJ |
7495 | /* For each CHILD_DIE, find the corresponding child of |
7496 | ORIGIN_DIE. If there is more than one layer of | |
7497 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
7498 | but GCC versions at least through 4.4 generate this (GCC PR | |
7499 | 40573). */ | |
7500 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 7501 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 7502 | |
c38f313d DJ |
7503 | while (1) |
7504 | { | |
cd02d79d PA |
7505 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
7506 | child_origin_cu); | |
c38f313d DJ |
7507 | if (attr == NULL) |
7508 | break; | |
cd02d79d PA |
7509 | child_origin_die = follow_die_ref (child_origin_die, attr, |
7510 | &child_origin_cu); | |
c38f313d DJ |
7511 | } |
7512 | ||
d389af10 JK |
7513 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
7514 | counterpart may exist. */ | |
c38f313d | 7515 | if (child_origin_die != child_die) |
d389af10 | 7516 | { |
edb3359d DJ |
7517 | if (child_die->tag != child_origin_die->tag |
7518 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
7519 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
7520 | complaint (&symfile_complaints, |
7521 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
b64f50a1 JK |
7522 | "different tags"), child_die->offset.sect_off, |
7523 | child_origin_die->offset.sect_off); | |
c38f313d DJ |
7524 | if (child_origin_die->parent != origin_die) |
7525 | complaint (&symfile_complaints, | |
7526 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
b64f50a1 JK |
7527 | "different parents"), child_die->offset.sect_off, |
7528 | child_origin_die->offset.sect_off); | |
c38f313d DJ |
7529 | else |
7530 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
7531 | } |
7532 | child_die = sibling_die (child_die); | |
7533 | } | |
7534 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
7535 | unsigned_int_compar); | |
7536 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
b64f50a1 | 7537 | if (offsetp[-1].sect_off == offsetp->sect_off) |
3e43a32a MS |
7538 | complaint (&symfile_complaints, |
7539 | _("Multiple children of DIE 0x%x refer " | |
7540 | "to DIE 0x%x as their abstract origin"), | |
b64f50a1 | 7541 | die->offset.sect_off, offsetp->sect_off); |
d389af10 JK |
7542 | |
7543 | offsetp = offsets; | |
7544 | origin_child_die = origin_die->child; | |
7545 | while (origin_child_die && origin_child_die->tag) | |
7546 | { | |
7547 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
b64f50a1 JK |
7548 | while (offsetp < offsets_end |
7549 | && offsetp->sect_off < origin_child_die->offset.sect_off) | |
d389af10 | 7550 | offsetp++; |
b64f50a1 JK |
7551 | if (offsetp >= offsets_end |
7552 | || offsetp->sect_off > origin_child_die->offset.sect_off) | |
d389af10 JK |
7553 | { |
7554 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 7555 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
7556 | } |
7557 | origin_child_die = sibling_die (origin_child_die); | |
7558 | } | |
cd02d79d | 7559 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
7560 | |
7561 | do_cleanups (cleanups); | |
7562 | } | |
7563 | ||
c906108c | 7564 | static void |
e7c27a73 | 7565 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7566 | { |
e7c27a73 | 7567 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 7568 | struct context_stack *new; |
c906108c SS |
7569 | CORE_ADDR lowpc; |
7570 | CORE_ADDR highpc; | |
7571 | struct die_info *child_die; | |
edb3359d | 7572 | struct attribute *attr, *call_line, *call_file; |
c906108c | 7573 | char *name; |
e142c38c | 7574 | CORE_ADDR baseaddr; |
801e3a5b | 7575 | struct block *block; |
edb3359d | 7576 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
7577 | VEC (symbolp) *template_args = NULL; |
7578 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
7579 | |
7580 | if (inlined_func) | |
7581 | { | |
7582 | /* If we do not have call site information, we can't show the | |
7583 | caller of this inlined function. That's too confusing, so | |
7584 | only use the scope for local variables. */ | |
7585 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
7586 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
7587 | if (call_line == NULL || call_file == NULL) | |
7588 | { | |
7589 | read_lexical_block_scope (die, cu); | |
7590 | return; | |
7591 | } | |
7592 | } | |
c906108c | 7593 | |
e142c38c DJ |
7594 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
7595 | ||
94af9270 | 7596 | name = dwarf2_name (die, cu); |
c906108c | 7597 | |
e8d05480 JB |
7598 | /* Ignore functions with missing or empty names. These are actually |
7599 | illegal according to the DWARF standard. */ | |
7600 | if (name == NULL) | |
7601 | { | |
7602 | complaint (&symfile_complaints, | |
b64f50a1 JK |
7603 | _("missing name for subprogram DIE at %d"), |
7604 | die->offset.sect_off); | |
e8d05480 JB |
7605 | return; |
7606 | } | |
7607 | ||
7608 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
7609 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
7610 | { | |
ae4d0c03 PM |
7611 | attr = dwarf2_attr (die, DW_AT_external, cu); |
7612 | if (!attr || !DW_UNSND (attr)) | |
7613 | complaint (&symfile_complaints, | |
3e43a32a MS |
7614 | _("cannot get low and high bounds " |
7615 | "for subprogram DIE at %d"), | |
b64f50a1 | 7616 | die->offset.sect_off); |
e8d05480 JB |
7617 | return; |
7618 | } | |
c906108c SS |
7619 | |
7620 | lowpc += baseaddr; | |
7621 | highpc += baseaddr; | |
7622 | ||
34eaf542 TT |
7623 | /* If we have any template arguments, then we must allocate a |
7624 | different sort of symbol. */ | |
7625 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
7626 | { | |
7627 | if (child_die->tag == DW_TAG_template_type_param | |
7628 | || child_die->tag == DW_TAG_template_value_param) | |
7629 | { | |
7630 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
7631 | struct template_symbol); | |
7632 | templ_func->base.is_cplus_template_function = 1; | |
7633 | break; | |
7634 | } | |
7635 | } | |
7636 | ||
c906108c | 7637 | new = push_context (0, lowpc); |
34eaf542 TT |
7638 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
7639 | (struct symbol *) templ_func); | |
4c2df51b | 7640 | |
4cecd739 DJ |
7641 | /* If there is a location expression for DW_AT_frame_base, record |
7642 | it. */ | |
e142c38c | 7643 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 7644 | if (attr) |
c034e007 AC |
7645 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
7646 | expression is being recorded directly in the function's symbol | |
7647 | and not in a separate frame-base object. I guess this hack is | |
7648 | to avoid adding some sort of frame-base adjunct/annex to the | |
7649 | function's symbol :-(. The problem with doing this is that it | |
7650 | results in a function symbol with a location expression that | |
7651 | has nothing to do with the location of the function, ouch! The | |
7652 | relationship should be: a function's symbol has-a frame base; a | |
7653 | frame-base has-a location expression. */ | |
e7c27a73 | 7654 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 7655 | |
e142c38c | 7656 | cu->list_in_scope = &local_symbols; |
c906108c | 7657 | |
639d11d3 | 7658 | if (die->child != NULL) |
c906108c | 7659 | { |
639d11d3 | 7660 | child_die = die->child; |
c906108c SS |
7661 | while (child_die && child_die->tag) |
7662 | { | |
34eaf542 TT |
7663 | if (child_die->tag == DW_TAG_template_type_param |
7664 | || child_die->tag == DW_TAG_template_value_param) | |
7665 | { | |
7666 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
7667 | ||
f1078f66 DJ |
7668 | if (arg != NULL) |
7669 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
7670 | } |
7671 | else | |
7672 | process_die (child_die, cu); | |
c906108c SS |
7673 | child_die = sibling_die (child_die); |
7674 | } | |
7675 | } | |
7676 | ||
d389af10 JK |
7677 | inherit_abstract_dies (die, cu); |
7678 | ||
4a811a97 UW |
7679 | /* If we have a DW_AT_specification, we might need to import using |
7680 | directives from the context of the specification DIE. See the | |
7681 | comment in determine_prefix. */ | |
7682 | if (cu->language == language_cplus | |
7683 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
7684 | { | |
7685 | struct dwarf2_cu *spec_cu = cu; | |
7686 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
7687 | ||
7688 | while (spec_die) | |
7689 | { | |
7690 | child_die = spec_die->child; | |
7691 | while (child_die && child_die->tag) | |
7692 | { | |
7693 | if (child_die->tag == DW_TAG_imported_module) | |
7694 | process_die (child_die, spec_cu); | |
7695 | child_die = sibling_die (child_die); | |
7696 | } | |
7697 | ||
7698 | /* In some cases, GCC generates specification DIEs that | |
7699 | themselves contain DW_AT_specification attributes. */ | |
7700 | spec_die = die_specification (spec_die, &spec_cu); | |
7701 | } | |
7702 | } | |
7703 | ||
c906108c SS |
7704 | new = pop_context (); |
7705 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
7706 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
7707 | lowpc, highpc, objfile); | |
7708 | ||
df8a16a1 | 7709 | /* For C++, set the block's scope. */ |
f55ee35c | 7710 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 7711 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 7712 | determine_prefix (die, cu), |
df8a16a1 DJ |
7713 | processing_has_namespace_info); |
7714 | ||
801e3a5b JB |
7715 | /* If we have address ranges, record them. */ |
7716 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 7717 | |
34eaf542 TT |
7718 | /* Attach template arguments to function. */ |
7719 | if (! VEC_empty (symbolp, template_args)) | |
7720 | { | |
7721 | gdb_assert (templ_func != NULL); | |
7722 | ||
7723 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
7724 | templ_func->template_arguments | |
7725 | = obstack_alloc (&objfile->objfile_obstack, | |
7726 | (templ_func->n_template_arguments | |
7727 | * sizeof (struct symbol *))); | |
7728 | memcpy (templ_func->template_arguments, | |
7729 | VEC_address (symbolp, template_args), | |
7730 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
7731 | VEC_free (symbolp, template_args); | |
7732 | } | |
7733 | ||
208d8187 JB |
7734 | /* In C++, we can have functions nested inside functions (e.g., when |
7735 | a function declares a class that has methods). This means that | |
7736 | when we finish processing a function scope, we may need to go | |
7737 | back to building a containing block's symbol lists. */ | |
7738 | local_symbols = new->locals; | |
7739 | param_symbols = new->params; | |
27aa8d6a | 7740 | using_directives = new->using_directives; |
208d8187 | 7741 | |
921e78cf JB |
7742 | /* If we've finished processing a top-level function, subsequent |
7743 | symbols go in the file symbol list. */ | |
7744 | if (outermost_context_p ()) | |
e142c38c | 7745 | cu->list_in_scope = &file_symbols; |
c906108c SS |
7746 | } |
7747 | ||
7748 | /* Process all the DIES contained within a lexical block scope. Start | |
7749 | a new scope, process the dies, and then close the scope. */ | |
7750 | ||
7751 | static void | |
e7c27a73 | 7752 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7753 | { |
e7c27a73 | 7754 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 7755 | struct context_stack *new; |
c906108c SS |
7756 | CORE_ADDR lowpc, highpc; |
7757 | struct die_info *child_die; | |
e142c38c DJ |
7758 | CORE_ADDR baseaddr; |
7759 | ||
7760 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
7761 | |
7762 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
7763 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
7764 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 7765 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 7766 | describe ranges. */ |
d85a05f0 | 7767 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
7768 | return; |
7769 | lowpc += baseaddr; | |
7770 | highpc += baseaddr; | |
7771 | ||
7772 | push_context (0, lowpc); | |
639d11d3 | 7773 | if (die->child != NULL) |
c906108c | 7774 | { |
639d11d3 | 7775 | child_die = die->child; |
c906108c SS |
7776 | while (child_die && child_die->tag) |
7777 | { | |
e7c27a73 | 7778 | process_die (child_die, cu); |
c906108c SS |
7779 | child_die = sibling_die (child_die); |
7780 | } | |
7781 | } | |
7782 | new = pop_context (); | |
7783 | ||
8540c487 | 7784 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 7785 | { |
801e3a5b JB |
7786 | struct block *block |
7787 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
7788 | highpc, objfile); | |
7789 | ||
7790 | /* Note that recording ranges after traversing children, as we | |
7791 | do here, means that recording a parent's ranges entails | |
7792 | walking across all its children's ranges as they appear in | |
7793 | the address map, which is quadratic behavior. | |
7794 | ||
7795 | It would be nicer to record the parent's ranges before | |
7796 | traversing its children, simply overriding whatever you find | |
7797 | there. But since we don't even decide whether to create a | |
7798 | block until after we've traversed its children, that's hard | |
7799 | to do. */ | |
7800 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
7801 | } |
7802 | local_symbols = new->locals; | |
27aa8d6a | 7803 | using_directives = new->using_directives; |
c906108c SS |
7804 | } |
7805 | ||
96408a79 SA |
7806 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
7807 | ||
7808 | static void | |
7809 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7810 | { | |
7811 | struct objfile *objfile = cu->objfile; | |
7812 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
7813 | CORE_ADDR pc, baseaddr; | |
7814 | struct attribute *attr; | |
7815 | struct call_site *call_site, call_site_local; | |
7816 | void **slot; | |
7817 | int nparams; | |
7818 | struct die_info *child_die; | |
7819 | ||
7820 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
7821 | ||
7822 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
7823 | if (!attr) | |
7824 | { | |
7825 | complaint (&symfile_complaints, | |
7826 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " | |
7827 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 7828 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7829 | return; |
7830 | } | |
7831 | pc = DW_ADDR (attr) + baseaddr; | |
7832 | ||
7833 | if (cu->call_site_htab == NULL) | |
7834 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, | |
7835 | NULL, &objfile->objfile_obstack, | |
7836 | hashtab_obstack_allocate, NULL); | |
7837 | call_site_local.pc = pc; | |
7838 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); | |
7839 | if (*slot != NULL) | |
7840 | { | |
7841 | complaint (&symfile_complaints, | |
7842 | _("Duplicate PC %s for DW_TAG_GNU_call_site " | |
7843 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 7844 | paddress (gdbarch, pc), die->offset.sect_off, objfile->name); |
96408a79 SA |
7845 | return; |
7846 | } | |
7847 | ||
7848 | /* Count parameters at the caller. */ | |
7849 | ||
7850 | nparams = 0; | |
7851 | for (child_die = die->child; child_die && child_die->tag; | |
7852 | child_die = sibling_die (child_die)) | |
7853 | { | |
7854 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
7855 | { | |
7856 | complaint (&symfile_complaints, | |
7857 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " | |
7858 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 7859 | child_die->tag, child_die->offset.sect_off, objfile->name); |
96408a79 SA |
7860 | continue; |
7861 | } | |
7862 | ||
7863 | nparams++; | |
7864 | } | |
7865 | ||
7866 | call_site = obstack_alloc (&objfile->objfile_obstack, | |
7867 | (sizeof (*call_site) | |
7868 | + (sizeof (*call_site->parameter) | |
7869 | * (nparams - 1)))); | |
7870 | *slot = call_site; | |
7871 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); | |
7872 | call_site->pc = pc; | |
7873 | ||
7874 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) | |
7875 | { | |
7876 | struct die_info *func_die; | |
7877 | ||
7878 | /* Skip also over DW_TAG_inlined_subroutine. */ | |
7879 | for (func_die = die->parent; | |
7880 | func_die && func_die->tag != DW_TAG_subprogram | |
7881 | && func_die->tag != DW_TAG_subroutine_type; | |
7882 | func_die = func_die->parent); | |
7883 | ||
7884 | /* DW_AT_GNU_all_call_sites is a superset | |
7885 | of DW_AT_GNU_all_tail_call_sites. */ | |
7886 | if (func_die | |
7887 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) | |
7888 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) | |
7889 | { | |
7890 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is | |
7891 | not complete. But keep CALL_SITE for look ups via call_site_htab, | |
7892 | both the initial caller containing the real return address PC and | |
7893 | the final callee containing the current PC of a chain of tail | |
7894 | calls do not need to have the tail call list complete. But any | |
7895 | function candidate for a virtual tail call frame searched via | |
7896 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be | |
7897 | determined unambiguously. */ | |
7898 | } | |
7899 | else | |
7900 | { | |
7901 | struct type *func_type = NULL; | |
7902 | ||
7903 | if (func_die) | |
7904 | func_type = get_die_type (func_die, cu); | |
7905 | if (func_type != NULL) | |
7906 | { | |
7907 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); | |
7908 | ||
7909 | /* Enlist this call site to the function. */ | |
7910 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); | |
7911 | TYPE_TAIL_CALL_LIST (func_type) = call_site; | |
7912 | } | |
7913 | else | |
7914 | complaint (&symfile_complaints, | |
7915 | _("Cannot find function owning DW_TAG_GNU_call_site " | |
7916 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 7917 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7918 | } |
7919 | } | |
7920 | ||
7921 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); | |
7922 | if (attr == NULL) | |
7923 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
7924 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); | |
7925 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) | |
7926 | /* Keep NULL DWARF_BLOCK. */; | |
7927 | else if (attr_form_is_block (attr)) | |
7928 | { | |
7929 | struct dwarf2_locexpr_baton *dlbaton; | |
7930 | ||
7931 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); | |
7932 | dlbaton->data = DW_BLOCK (attr)->data; | |
7933 | dlbaton->size = DW_BLOCK (attr)->size; | |
7934 | dlbaton->per_cu = cu->per_cu; | |
7935 | ||
7936 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); | |
7937 | } | |
7938 | else if (is_ref_attr (attr)) | |
7939 | { | |
96408a79 SA |
7940 | struct dwarf2_cu *target_cu = cu; |
7941 | struct die_info *target_die; | |
7942 | ||
7943 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); | |
7944 | gdb_assert (target_cu->objfile == objfile); | |
7945 | if (die_is_declaration (target_die, target_cu)) | |
7946 | { | |
7947 | const char *target_physname; | |
7948 | ||
7949 | target_physname = dwarf2_physname (NULL, target_die, target_cu); | |
7950 | if (target_physname == NULL) | |
7951 | complaint (&symfile_complaints, | |
7952 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
7953 | "physname, for referencing DIE 0x%x [in module %s]"), | |
b64f50a1 | 7954 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7955 | else |
7956 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); | |
7957 | } | |
7958 | else | |
7959 | { | |
7960 | CORE_ADDR lowpc; | |
7961 | ||
7962 | /* DW_AT_entry_pc should be preferred. */ | |
7963 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) | |
7964 | complaint (&symfile_complaints, | |
7965 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
7966 | "low pc, for referencing DIE 0x%x [in module %s]"), | |
b64f50a1 | 7967 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7968 | else |
7969 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); | |
7970 | } | |
7971 | } | |
7972 | else | |
7973 | complaint (&symfile_complaints, | |
7974 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " | |
7975 | "block nor reference, for DIE 0x%x [in module %s]"), | |
b64f50a1 | 7976 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7977 | |
7978 | call_site->per_cu = cu->per_cu; | |
7979 | ||
7980 | for (child_die = die->child; | |
7981 | child_die && child_die->tag; | |
7982 | child_die = sibling_die (child_die)) | |
7983 | { | |
96408a79 | 7984 | struct call_site_parameter *parameter; |
1788b2d3 | 7985 | struct attribute *loc, *origin; |
96408a79 SA |
7986 | |
7987 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
7988 | { | |
7989 | /* Already printed the complaint above. */ | |
7990 | continue; | |
7991 | } | |
7992 | ||
7993 | gdb_assert (call_site->parameter_count < nparams); | |
7994 | parameter = &call_site->parameter[call_site->parameter_count]; | |
7995 | ||
1788b2d3 JK |
7996 | /* DW_AT_location specifies the register number or DW_AT_abstract_origin |
7997 | specifies DW_TAG_formal_parameter. Value of the data assumed for the | |
7998 | register is contained in DW_AT_GNU_call_site_value. */ | |
96408a79 | 7999 | |
24c5c679 | 8000 | loc = dwarf2_attr (child_die, DW_AT_location, cu); |
1788b2d3 JK |
8001 | origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu); |
8002 | if (loc == NULL && origin != NULL && is_ref_attr (origin)) | |
8003 | { | |
8004 | sect_offset offset; | |
8005 | ||
8006 | parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET; | |
8007 | offset = dwarf2_get_ref_die_offset (origin); | |
8008 | gdb_assert (offset.sect_off >= cu->header.offset.sect_off); | |
8009 | parameter->u.param_offset.cu_off = (offset.sect_off | |
8010 | - cu->header.offset.sect_off); | |
8011 | } | |
8012 | else if (loc == NULL || origin != NULL || !attr_form_is_block (loc)) | |
96408a79 SA |
8013 | { |
8014 | complaint (&symfile_complaints, | |
8015 | _("No DW_FORM_block* DW_AT_location for " | |
8016 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 8017 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
8018 | continue; |
8019 | } | |
24c5c679 | 8020 | else |
96408a79 | 8021 | { |
24c5c679 JK |
8022 | parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg |
8023 | (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]); | |
8024 | if (parameter->u.dwarf_reg != -1) | |
8025 | parameter->kind = CALL_SITE_PARAMETER_DWARF_REG; | |
8026 | else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data, | |
8027 | &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size], | |
8028 | ¶meter->u.fb_offset)) | |
8029 | parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET; | |
8030 | else | |
8031 | { | |
8032 | complaint (&symfile_complaints, | |
8033 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " | |
8034 | "for DW_FORM_block* DW_AT_location is supported for " | |
8035 | "DW_TAG_GNU_call_site child DIE 0x%x " | |
8036 | "[in module %s]"), | |
8037 | child_die->offset.sect_off, objfile->name); | |
8038 | continue; | |
8039 | } | |
96408a79 SA |
8040 | } |
8041 | ||
8042 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); | |
8043 | if (!attr_form_is_block (attr)) | |
8044 | { | |
8045 | complaint (&symfile_complaints, | |
8046 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " | |
8047 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 8048 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
8049 | continue; |
8050 | } | |
8051 | parameter->value = DW_BLOCK (attr)->data; | |
8052 | parameter->value_size = DW_BLOCK (attr)->size; | |
8053 | ||
8054 | /* Parameters are not pre-cleared by memset above. */ | |
8055 | parameter->data_value = NULL; | |
8056 | parameter->data_value_size = 0; | |
8057 | call_site->parameter_count++; | |
8058 | ||
8059 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); | |
8060 | if (attr) | |
8061 | { | |
8062 | if (!attr_form_is_block (attr)) | |
8063 | complaint (&symfile_complaints, | |
8064 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " | |
8065 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 8066 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
8067 | else |
8068 | { | |
8069 | parameter->data_value = DW_BLOCK (attr)->data; | |
8070 | parameter->data_value_size = DW_BLOCK (attr)->size; | |
8071 | } | |
8072 | } | |
8073 | } | |
8074 | } | |
8075 | ||
43039443 | 8076 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
8077 | Return 1 if the attributes are present and valid, otherwise, return 0. |
8078 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
8079 | |
8080 | static int | |
8081 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
8082 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
8083 | struct partial_symtab *ranges_pst) | |
43039443 JK |
8084 | { |
8085 | struct objfile *objfile = cu->objfile; | |
8086 | struct comp_unit_head *cu_header = &cu->header; | |
8087 | bfd *obfd = objfile->obfd; | |
8088 | unsigned int addr_size = cu_header->addr_size; | |
8089 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
8090 | /* Base address selection entry. */ | |
8091 | CORE_ADDR base; | |
8092 | int found_base; | |
8093 | unsigned int dummy; | |
8094 | gdb_byte *buffer; | |
8095 | CORE_ADDR marker; | |
8096 | int low_set; | |
8097 | CORE_ADDR low = 0; | |
8098 | CORE_ADDR high = 0; | |
ff013f42 | 8099 | CORE_ADDR baseaddr; |
43039443 | 8100 | |
d00adf39 DE |
8101 | found_base = cu->base_known; |
8102 | base = cu->base_address; | |
43039443 | 8103 | |
be391dca | 8104 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 8105 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
8106 | { |
8107 | complaint (&symfile_complaints, | |
8108 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
8109 | offset); | |
8110 | return 0; | |
8111 | } | |
dce234bc | 8112 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
8113 | |
8114 | /* Read in the largest possible address. */ | |
8115 | marker = read_address (obfd, buffer, cu, &dummy); | |
8116 | if ((marker & mask) == mask) | |
8117 | { | |
8118 | /* If we found the largest possible address, then | |
8119 | read the base address. */ | |
8120 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
8121 | buffer += 2 * addr_size; | |
8122 | offset += 2 * addr_size; | |
8123 | found_base = 1; | |
8124 | } | |
8125 | ||
8126 | low_set = 0; | |
8127 | ||
e7030f15 | 8128 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 8129 | |
43039443 JK |
8130 | while (1) |
8131 | { | |
8132 | CORE_ADDR range_beginning, range_end; | |
8133 | ||
8134 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
8135 | buffer += addr_size; | |
8136 | range_end = read_address (obfd, buffer, cu, &dummy); | |
8137 | buffer += addr_size; | |
8138 | offset += 2 * addr_size; | |
8139 | ||
8140 | /* An end of list marker is a pair of zero addresses. */ | |
8141 | if (range_beginning == 0 && range_end == 0) | |
8142 | /* Found the end of list entry. */ | |
8143 | break; | |
8144 | ||
8145 | /* Each base address selection entry is a pair of 2 values. | |
8146 | The first is the largest possible address, the second is | |
8147 | the base address. Check for a base address here. */ | |
8148 | if ((range_beginning & mask) == mask) | |
8149 | { | |
8150 | /* If we found the largest possible address, then | |
8151 | read the base address. */ | |
8152 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
8153 | found_base = 1; | |
8154 | continue; | |
8155 | } | |
8156 | ||
8157 | if (!found_base) | |
8158 | { | |
8159 | /* We have no valid base address for the ranges | |
8160 | data. */ | |
8161 | complaint (&symfile_complaints, | |
8162 | _("Invalid .debug_ranges data (no base address)")); | |
8163 | return 0; | |
8164 | } | |
8165 | ||
9277c30c UW |
8166 | if (range_beginning > range_end) |
8167 | { | |
8168 | /* Inverted range entries are invalid. */ | |
8169 | complaint (&symfile_complaints, | |
8170 | _("Invalid .debug_ranges data (inverted range)")); | |
8171 | return 0; | |
8172 | } | |
8173 | ||
8174 | /* Empty range entries have no effect. */ | |
8175 | if (range_beginning == range_end) | |
8176 | continue; | |
8177 | ||
43039443 JK |
8178 | range_beginning += base; |
8179 | range_end += base; | |
8180 | ||
9277c30c | 8181 | if (ranges_pst != NULL) |
ff013f42 | 8182 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
8183 | range_beginning + baseaddr, |
8184 | range_end - 1 + baseaddr, | |
ff013f42 JK |
8185 | ranges_pst); |
8186 | ||
43039443 JK |
8187 | /* FIXME: This is recording everything as a low-high |
8188 | segment of consecutive addresses. We should have a | |
8189 | data structure for discontiguous block ranges | |
8190 | instead. */ | |
8191 | if (! low_set) | |
8192 | { | |
8193 | low = range_beginning; | |
8194 | high = range_end; | |
8195 | low_set = 1; | |
8196 | } | |
8197 | else | |
8198 | { | |
8199 | if (range_beginning < low) | |
8200 | low = range_beginning; | |
8201 | if (range_end > high) | |
8202 | high = range_end; | |
8203 | } | |
8204 | } | |
8205 | ||
8206 | if (! low_set) | |
8207 | /* If the first entry is an end-of-list marker, the range | |
8208 | describes an empty scope, i.e. no instructions. */ | |
8209 | return 0; | |
8210 | ||
8211 | if (low_return) | |
8212 | *low_return = low; | |
8213 | if (high_return) | |
8214 | *high_return = high; | |
8215 | return 1; | |
8216 | } | |
8217 | ||
af34e669 DJ |
8218 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
8219 | are present and valid, otherwise, return 0. Return -1 if the range is | |
8220 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
380bca97 | 8221 | |
c906108c | 8222 | static int |
af34e669 | 8223 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
8224 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
8225 | struct partial_symtab *pst) | |
c906108c SS |
8226 | { |
8227 | struct attribute *attr; | |
91da1414 | 8228 | struct attribute *attr_high; |
af34e669 DJ |
8229 | CORE_ADDR low = 0; |
8230 | CORE_ADDR high = 0; | |
8231 | int ret = 0; | |
c906108c | 8232 | |
91da1414 MW |
8233 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
8234 | if (attr_high) | |
af34e669 | 8235 | { |
e142c38c | 8236 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 | 8237 | if (attr) |
91da1414 MW |
8238 | { |
8239 | low = DW_ADDR (attr); | |
3019eac3 DE |
8240 | if (attr_high->form == DW_FORM_addr |
8241 | || attr_high->form == DW_FORM_GNU_addr_index) | |
91da1414 MW |
8242 | high = DW_ADDR (attr_high); |
8243 | else | |
8244 | high = low + DW_UNSND (attr_high); | |
8245 | } | |
af34e669 DJ |
8246 | else |
8247 | /* Found high w/o low attribute. */ | |
8248 | return 0; | |
8249 | ||
8250 | /* Found consecutive range of addresses. */ | |
8251 | ret = 1; | |
8252 | } | |
c906108c | 8253 | else |
af34e669 | 8254 | { |
e142c38c | 8255 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
8256 | if (attr != NULL) |
8257 | { | |
2e3cf129 DE |
8258 | unsigned int ranges_offset = DW_UNSND (attr) + cu->ranges_base; |
8259 | ||
af34e669 | 8260 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 8261 | .debug_ranges section. */ |
2e3cf129 | 8262 | if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst)) |
af34e669 | 8263 | return 0; |
43039443 | 8264 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
8265 | ret = -1; |
8266 | } | |
8267 | } | |
c906108c | 8268 | |
9373cf26 JK |
8269 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
8270 | if (high <= low) | |
c906108c SS |
8271 | return 0; |
8272 | ||
8273 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
8274 | eliminate duplicate copies of functions and vtables and such. | |
8275 | The linker will arbitrarily choose one and discard the others. | |
8276 | The AT_*_pc values for such functions refer to local labels in | |
8277 | these sections. If the section from that file was discarded, the | |
8278 | labels are not in the output, so the relocs get a value of 0. | |
8279 | If this is a discarded function, mark the pc bounds as invalid, | |
8280 | so that GDB will ignore it. */ | |
72dca2f5 | 8281 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
8282 | return 0; |
8283 | ||
8284 | *lowpc = low; | |
96408a79 SA |
8285 | if (highpc) |
8286 | *highpc = high; | |
af34e669 | 8287 | return ret; |
c906108c SS |
8288 | } |
8289 | ||
b084d499 JB |
8290 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
8291 | its low and high PC addresses. Do nothing if these addresses could not | |
8292 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
8293 | and HIGHPC to the high address if greater than HIGHPC. */ | |
8294 | ||
8295 | static void | |
8296 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
8297 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
8298 | struct dwarf2_cu *cu) | |
8299 | { | |
8300 | CORE_ADDR low, high; | |
8301 | struct die_info *child = die->child; | |
8302 | ||
d85a05f0 | 8303 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
8304 | { |
8305 | *lowpc = min (*lowpc, low); | |
8306 | *highpc = max (*highpc, high); | |
8307 | } | |
8308 | ||
8309 | /* If the language does not allow nested subprograms (either inside | |
8310 | subprograms or lexical blocks), we're done. */ | |
8311 | if (cu->language != language_ada) | |
8312 | return; | |
6e70227d | 8313 | |
b084d499 JB |
8314 | /* Check all the children of the given DIE. If it contains nested |
8315 | subprograms, then check their pc bounds. Likewise, we need to | |
8316 | check lexical blocks as well, as they may also contain subprogram | |
8317 | definitions. */ | |
8318 | while (child && child->tag) | |
8319 | { | |
8320 | if (child->tag == DW_TAG_subprogram | |
8321 | || child->tag == DW_TAG_lexical_block) | |
8322 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
8323 | child = sibling_die (child); | |
8324 | } | |
8325 | } | |
8326 | ||
fae299cd DC |
8327 | /* Get the low and high pc's represented by the scope DIE, and store |
8328 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
8329 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
8330 | ||
8331 | static void | |
8332 | get_scope_pc_bounds (struct die_info *die, | |
8333 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
8334 | struct dwarf2_cu *cu) | |
8335 | { | |
8336 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
8337 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
8338 | CORE_ADDR current_low, current_high; | |
8339 | ||
d85a05f0 | 8340 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
8341 | { |
8342 | best_low = current_low; | |
8343 | best_high = current_high; | |
8344 | } | |
8345 | else | |
8346 | { | |
8347 | struct die_info *child = die->child; | |
8348 | ||
8349 | while (child && child->tag) | |
8350 | { | |
8351 | switch (child->tag) { | |
8352 | case DW_TAG_subprogram: | |
b084d499 | 8353 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
8354 | break; |
8355 | case DW_TAG_namespace: | |
f55ee35c | 8356 | case DW_TAG_module: |
fae299cd DC |
8357 | /* FIXME: carlton/2004-01-16: Should we do this for |
8358 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
8359 | that current GCC's always emit the DIEs corresponding | |
8360 | to definitions of methods of classes as children of a | |
8361 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
8362 | the DIEs giving the declarations, which could be | |
8363 | anywhere). But I don't see any reason why the | |
8364 | standards says that they have to be there. */ | |
8365 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
8366 | ||
8367 | if (current_low != ((CORE_ADDR) -1)) | |
8368 | { | |
8369 | best_low = min (best_low, current_low); | |
8370 | best_high = max (best_high, current_high); | |
8371 | } | |
8372 | break; | |
8373 | default: | |
0963b4bd | 8374 | /* Ignore. */ |
fae299cd DC |
8375 | break; |
8376 | } | |
8377 | ||
8378 | child = sibling_die (child); | |
8379 | } | |
8380 | } | |
8381 | ||
8382 | *lowpc = best_low; | |
8383 | *highpc = best_high; | |
8384 | } | |
8385 | ||
801e3a5b JB |
8386 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
8387 | in DIE. */ | |
380bca97 | 8388 | |
801e3a5b JB |
8389 | static void |
8390 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
8391 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
8392 | { | |
bb5ed363 | 8393 | struct objfile *objfile = cu->objfile; |
801e3a5b | 8394 | struct attribute *attr; |
91da1414 | 8395 | struct attribute *attr_high; |
801e3a5b | 8396 | |
91da1414 MW |
8397 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
8398 | if (attr_high) | |
801e3a5b | 8399 | { |
801e3a5b JB |
8400 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
8401 | if (attr) | |
8402 | { | |
8403 | CORE_ADDR low = DW_ADDR (attr); | |
91da1414 | 8404 | CORE_ADDR high; |
3019eac3 DE |
8405 | if (attr_high->form == DW_FORM_addr |
8406 | || attr_high->form == DW_FORM_GNU_addr_index) | |
91da1414 MW |
8407 | high = DW_ADDR (attr_high); |
8408 | else | |
8409 | high = low + DW_UNSND (attr_high); | |
9a619af0 | 8410 | |
801e3a5b JB |
8411 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
8412 | } | |
8413 | } | |
8414 | ||
8415 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
8416 | if (attr) | |
8417 | { | |
bb5ed363 | 8418 | bfd *obfd = objfile->obfd; |
801e3a5b JB |
8419 | |
8420 | /* The value of the DW_AT_ranges attribute is the offset of the | |
8421 | address range list in the .debug_ranges section. */ | |
2e3cf129 | 8422 | unsigned long offset = DW_UNSND (attr) + cu->ranges_base; |
dce234bc | 8423 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
8424 | |
8425 | /* For some target architectures, but not others, the | |
8426 | read_address function sign-extends the addresses it returns. | |
8427 | To recognize base address selection entries, we need a | |
8428 | mask. */ | |
8429 | unsigned int addr_size = cu->header.addr_size; | |
8430 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
8431 | ||
8432 | /* The base address, to which the next pair is relative. Note | |
8433 | that this 'base' is a DWARF concept: most entries in a range | |
8434 | list are relative, to reduce the number of relocs against the | |
8435 | debugging information. This is separate from this function's | |
8436 | 'baseaddr' argument, which GDB uses to relocate debugging | |
8437 | information from a shared library based on the address at | |
8438 | which the library was loaded. */ | |
d00adf39 DE |
8439 | CORE_ADDR base = cu->base_address; |
8440 | int base_known = cu->base_known; | |
801e3a5b | 8441 | |
be391dca | 8442 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 8443 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
8444 | { |
8445 | complaint (&symfile_complaints, | |
8446 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
8447 | offset); | |
8448 | return; | |
8449 | } | |
8450 | ||
8451 | for (;;) | |
8452 | { | |
8453 | unsigned int bytes_read; | |
8454 | CORE_ADDR start, end; | |
8455 | ||
8456 | start = read_address (obfd, buffer, cu, &bytes_read); | |
8457 | buffer += bytes_read; | |
8458 | end = read_address (obfd, buffer, cu, &bytes_read); | |
8459 | buffer += bytes_read; | |
8460 | ||
8461 | /* Did we find the end of the range list? */ | |
8462 | if (start == 0 && end == 0) | |
8463 | break; | |
8464 | ||
8465 | /* Did we find a base address selection entry? */ | |
8466 | else if ((start & base_select_mask) == base_select_mask) | |
8467 | { | |
8468 | base = end; | |
8469 | base_known = 1; | |
8470 | } | |
8471 | ||
8472 | /* We found an ordinary address range. */ | |
8473 | else | |
8474 | { | |
8475 | if (!base_known) | |
8476 | { | |
8477 | complaint (&symfile_complaints, | |
3e43a32a MS |
8478 | _("Invalid .debug_ranges data " |
8479 | "(no base address)")); | |
801e3a5b JB |
8480 | return; |
8481 | } | |
8482 | ||
9277c30c UW |
8483 | if (start > end) |
8484 | { | |
8485 | /* Inverted range entries are invalid. */ | |
8486 | complaint (&symfile_complaints, | |
8487 | _("Invalid .debug_ranges data " | |
8488 | "(inverted range)")); | |
8489 | return; | |
8490 | } | |
8491 | ||
8492 | /* Empty range entries have no effect. */ | |
8493 | if (start == end) | |
8494 | continue; | |
8495 | ||
6e70227d DE |
8496 | record_block_range (block, |
8497 | baseaddr + base + start, | |
801e3a5b JB |
8498 | baseaddr + base + end - 1); |
8499 | } | |
8500 | } | |
8501 | } | |
8502 | } | |
8503 | ||
685b1105 JK |
8504 | /* Check whether the producer field indicates either of GCC < 4.6, or the |
8505 | Intel C/C++ compiler, and cache the result in CU. */ | |
60d5a603 | 8506 | |
685b1105 JK |
8507 | static void |
8508 | check_producer (struct dwarf2_cu *cu) | |
60d5a603 JK |
8509 | { |
8510 | const char *cs; | |
8511 | int major, minor, release; | |
8512 | ||
8513 | if (cu->producer == NULL) | |
8514 | { | |
8515 | /* For unknown compilers expect their behavior is DWARF version | |
8516 | compliant. | |
8517 | ||
8518 | GCC started to support .debug_types sections by -gdwarf-4 since | |
8519 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
8520 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
8521 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
8522 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
60d5a603 | 8523 | } |
685b1105 | 8524 | else if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) == 0) |
60d5a603 | 8525 | { |
685b1105 JK |
8526 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ |
8527 | ||
ba919b58 TT |
8528 | cs = &cu->producer[strlen ("GNU ")]; |
8529 | while (*cs && !isdigit (*cs)) | |
8530 | cs++; | |
8531 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) | |
8532 | { | |
8533 | /* Not recognized as GCC. */ | |
8534 | } | |
8535 | else | |
685b1105 JK |
8536 | cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6); |
8537 | } | |
8538 | else if (strncmp (cu->producer, "Intel(R) C", strlen ("Intel(R) C")) == 0) | |
8539 | cu->producer_is_icc = 1; | |
8540 | else | |
8541 | { | |
8542 | /* For other non-GCC compilers, expect their behavior is DWARF version | |
8543 | compliant. */ | |
60d5a603 JK |
8544 | } |
8545 | ||
ba919b58 | 8546 | cu->checked_producer = 1; |
685b1105 | 8547 | } |
ba919b58 | 8548 | |
685b1105 JK |
8549 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
8550 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
8551 | during 4.6.0 experimental. */ | |
8552 | ||
8553 | static int | |
8554 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
8555 | { | |
8556 | if (!cu->checked_producer) | |
8557 | check_producer (cu); | |
8558 | ||
8559 | return cu->producer_is_gxx_lt_4_6; | |
60d5a603 JK |
8560 | } |
8561 | ||
8562 | /* Return the default accessibility type if it is not overriden by | |
8563 | DW_AT_accessibility. */ | |
8564 | ||
8565 | static enum dwarf_access_attribute | |
8566 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
8567 | { | |
8568 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
8569 | { | |
8570 | /* The default DWARF 2 accessibility for members is public, the default | |
8571 | accessibility for inheritance is private. */ | |
8572 | ||
8573 | if (die->tag != DW_TAG_inheritance) | |
8574 | return DW_ACCESS_public; | |
8575 | else | |
8576 | return DW_ACCESS_private; | |
8577 | } | |
8578 | else | |
8579 | { | |
8580 | /* DWARF 3+ defines the default accessibility a different way. The same | |
8581 | rules apply now for DW_TAG_inheritance as for the members and it only | |
8582 | depends on the container kind. */ | |
8583 | ||
8584 | if (die->parent->tag == DW_TAG_class_type) | |
8585 | return DW_ACCESS_private; | |
8586 | else | |
8587 | return DW_ACCESS_public; | |
8588 | } | |
8589 | } | |
8590 | ||
74ac6d43 TT |
8591 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
8592 | offset. If the attribute was not found return 0, otherwise return | |
8593 | 1. If it was found but could not properly be handled, set *OFFSET | |
8594 | to 0. */ | |
8595 | ||
8596 | static int | |
8597 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
8598 | LONGEST *offset) | |
8599 | { | |
8600 | struct attribute *attr; | |
8601 | ||
8602 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
8603 | if (attr != NULL) | |
8604 | { | |
8605 | *offset = 0; | |
8606 | ||
8607 | /* Note that we do not check for a section offset first here. | |
8608 | This is because DW_AT_data_member_location is new in DWARF 4, | |
8609 | so if we see it, we can assume that a constant form is really | |
8610 | a constant and not a section offset. */ | |
8611 | if (attr_form_is_constant (attr)) | |
8612 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
8613 | else if (attr_form_is_section_offset (attr)) | |
8614 | dwarf2_complex_location_expr_complaint (); | |
8615 | else if (attr_form_is_block (attr)) | |
8616 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
8617 | else | |
8618 | dwarf2_complex_location_expr_complaint (); | |
8619 | ||
8620 | return 1; | |
8621 | } | |
8622 | ||
8623 | return 0; | |
8624 | } | |
8625 | ||
c906108c SS |
8626 | /* Add an aggregate field to the field list. */ |
8627 | ||
8628 | static void | |
107d2387 | 8629 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 8630 | struct dwarf2_cu *cu) |
6e70227d | 8631 | { |
e7c27a73 | 8632 | struct objfile *objfile = cu->objfile; |
5e2b427d | 8633 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
8634 | struct nextfield *new_field; |
8635 | struct attribute *attr; | |
8636 | struct field *fp; | |
8637 | char *fieldname = ""; | |
8638 | ||
8639 | /* Allocate a new field list entry and link it in. */ | |
8640 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 8641 | make_cleanup (xfree, new_field); |
c906108c | 8642 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
8643 | |
8644 | if (die->tag == DW_TAG_inheritance) | |
8645 | { | |
8646 | new_field->next = fip->baseclasses; | |
8647 | fip->baseclasses = new_field; | |
8648 | } | |
8649 | else | |
8650 | { | |
8651 | new_field->next = fip->fields; | |
8652 | fip->fields = new_field; | |
8653 | } | |
c906108c SS |
8654 | fip->nfields++; |
8655 | ||
e142c38c | 8656 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
8657 | if (attr) |
8658 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
8659 | else |
8660 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
8661 | if (new_field->accessibility != DW_ACCESS_public) |
8662 | fip->non_public_fields = 1; | |
60d5a603 | 8663 | |
e142c38c | 8664 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
8665 | if (attr) |
8666 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
8667 | else |
8668 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
8669 | |
8670 | fp = &new_field->field; | |
a9a9bd0f | 8671 | |
e142c38c | 8672 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 8673 | { |
74ac6d43 TT |
8674 | LONGEST offset; |
8675 | ||
a9a9bd0f | 8676 | /* Data member other than a C++ static data member. */ |
6e70227d | 8677 | |
c906108c | 8678 | /* Get type of field. */ |
e7c27a73 | 8679 | fp->type = die_type (die, cu); |
c906108c | 8680 | |
d6a843b5 | 8681 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 8682 | |
c906108c | 8683 | /* Get bit size of field (zero if none). */ |
e142c38c | 8684 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
8685 | if (attr) |
8686 | { | |
8687 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
8688 | } | |
8689 | else | |
8690 | { | |
8691 | FIELD_BITSIZE (*fp) = 0; | |
8692 | } | |
8693 | ||
8694 | /* Get bit offset of field. */ | |
74ac6d43 TT |
8695 | if (handle_data_member_location (die, cu, &offset)) |
8696 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 8697 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
8698 | if (attr) |
8699 | { | |
5e2b427d | 8700 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
8701 | { |
8702 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
8703 | additional bit offset from the MSB of the containing |
8704 | anonymous object to the MSB of the field. We don't | |
8705 | have to do anything special since we don't need to | |
8706 | know the size of the anonymous object. */ | |
f41f5e61 | 8707 | SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr)); |
c906108c SS |
8708 | } |
8709 | else | |
8710 | { | |
8711 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
8712 | MSB of the anonymous object, subtract off the number of |
8713 | bits from the MSB of the field to the MSB of the | |
8714 | object, and then subtract off the number of bits of | |
8715 | the field itself. The result is the bit offset of | |
8716 | the LSB of the field. */ | |
c906108c SS |
8717 | int anonymous_size; |
8718 | int bit_offset = DW_UNSND (attr); | |
8719 | ||
e142c38c | 8720 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8721 | if (attr) |
8722 | { | |
8723 | /* The size of the anonymous object containing | |
8724 | the bit field is explicit, so use the | |
8725 | indicated size (in bytes). */ | |
8726 | anonymous_size = DW_UNSND (attr); | |
8727 | } | |
8728 | else | |
8729 | { | |
8730 | /* The size of the anonymous object containing | |
8731 | the bit field must be inferred from the type | |
8732 | attribute of the data member containing the | |
8733 | bit field. */ | |
8734 | anonymous_size = TYPE_LENGTH (fp->type); | |
8735 | } | |
f41f5e61 PA |
8736 | SET_FIELD_BITPOS (*fp, |
8737 | (FIELD_BITPOS (*fp) | |
8738 | + anonymous_size * bits_per_byte | |
8739 | - bit_offset - FIELD_BITSIZE (*fp))); | |
c906108c SS |
8740 | } |
8741 | } | |
8742 | ||
8743 | /* Get name of field. */ | |
39cbfefa DJ |
8744 | fieldname = dwarf2_name (die, cu); |
8745 | if (fieldname == NULL) | |
8746 | fieldname = ""; | |
d8151005 DJ |
8747 | |
8748 | /* The name is already allocated along with this objfile, so we don't | |
8749 | need to duplicate it for the type. */ | |
8750 | fp->name = fieldname; | |
c906108c SS |
8751 | |
8752 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 8753 | pointer or virtual base class pointer) to private. */ |
e142c38c | 8754 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 8755 | { |
d48cc9dd | 8756 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
8757 | new_field->accessibility = DW_ACCESS_private; |
8758 | fip->non_public_fields = 1; | |
8759 | } | |
8760 | } | |
a9a9bd0f | 8761 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 8762 | { |
a9a9bd0f DC |
8763 | /* C++ static member. */ |
8764 | ||
8765 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
8766 | is a declaration, but all versions of G++ as of this writing | |
8767 | (so through at least 3.2.1) incorrectly generate | |
8768 | DW_TAG_variable tags. */ | |
6e70227d | 8769 | |
ff355380 | 8770 | const char *physname; |
c906108c | 8771 | |
a9a9bd0f | 8772 | /* Get name of field. */ |
39cbfefa DJ |
8773 | fieldname = dwarf2_name (die, cu); |
8774 | if (fieldname == NULL) | |
c906108c SS |
8775 | return; |
8776 | ||
254e6b9e | 8777 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
8778 | if (attr |
8779 | /* Only create a symbol if this is an external value. | |
8780 | new_symbol checks this and puts the value in the global symbol | |
8781 | table, which we want. If it is not external, new_symbol | |
8782 | will try to put the value in cu->list_in_scope which is wrong. */ | |
8783 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
8784 | { |
8785 | /* A static const member, not much different than an enum as far as | |
8786 | we're concerned, except that we can support more types. */ | |
8787 | new_symbol (die, NULL, cu); | |
8788 | } | |
8789 | ||
2df3850c | 8790 | /* Get physical name. */ |
ff355380 | 8791 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 8792 | |
d8151005 DJ |
8793 | /* The name is already allocated along with this objfile, so we don't |
8794 | need to duplicate it for the type. */ | |
8795 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 8796 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 8797 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
8798 | } |
8799 | else if (die->tag == DW_TAG_inheritance) | |
8800 | { | |
74ac6d43 | 8801 | LONGEST offset; |
d4b96c9a | 8802 | |
74ac6d43 TT |
8803 | /* C++ base class field. */ |
8804 | if (handle_data_member_location (die, cu, &offset)) | |
8805 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 8806 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 8807 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
8808 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
8809 | fip->nbaseclasses++; | |
8810 | } | |
8811 | } | |
8812 | ||
98751a41 JK |
8813 | /* Add a typedef defined in the scope of the FIP's class. */ |
8814 | ||
8815 | static void | |
8816 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
8817 | struct dwarf2_cu *cu) | |
6e70227d | 8818 | { |
98751a41 | 8819 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
8820 | struct typedef_field_list *new_field; |
8821 | struct attribute *attr; | |
8822 | struct typedef_field *fp; | |
8823 | char *fieldname = ""; | |
8824 | ||
8825 | /* Allocate a new field list entry and link it in. */ | |
8826 | new_field = xzalloc (sizeof (*new_field)); | |
8827 | make_cleanup (xfree, new_field); | |
8828 | ||
8829 | gdb_assert (die->tag == DW_TAG_typedef); | |
8830 | ||
8831 | fp = &new_field->field; | |
8832 | ||
8833 | /* Get name of field. */ | |
8834 | fp->name = dwarf2_name (die, cu); | |
8835 | if (fp->name == NULL) | |
8836 | return; | |
8837 | ||
8838 | fp->type = read_type_die (die, cu); | |
8839 | ||
8840 | new_field->next = fip->typedef_field_list; | |
8841 | fip->typedef_field_list = new_field; | |
8842 | fip->typedef_field_list_count++; | |
8843 | } | |
8844 | ||
c906108c SS |
8845 | /* Create the vector of fields, and attach it to the type. */ |
8846 | ||
8847 | static void | |
fba45db2 | 8848 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 8849 | struct dwarf2_cu *cu) |
c906108c SS |
8850 | { |
8851 | int nfields = fip->nfields; | |
8852 | ||
8853 | /* Record the field count, allocate space for the array of fields, | |
8854 | and create blank accessibility bitfields if necessary. */ | |
8855 | TYPE_NFIELDS (type) = nfields; | |
8856 | TYPE_FIELDS (type) = (struct field *) | |
8857 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
8858 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
8859 | ||
b4ba55a1 | 8860 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
8861 | { |
8862 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
8863 | ||
8864 | TYPE_FIELD_PRIVATE_BITS (type) = | |
8865 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
8866 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
8867 | ||
8868 | TYPE_FIELD_PROTECTED_BITS (type) = | |
8869 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
8870 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
8871 | ||
774b6a14 TT |
8872 | TYPE_FIELD_IGNORE_BITS (type) = |
8873 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
8874 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
8875 | } |
8876 | ||
8877 | /* If the type has baseclasses, allocate and clear a bit vector for | |
8878 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 8879 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
8880 | { |
8881 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 8882 | unsigned char *pointer; |
c906108c SS |
8883 | |
8884 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
8885 | pointer = TYPE_ALLOC (type, num_bytes); |
8886 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
8887 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
8888 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
8889 | } | |
8890 | ||
3e43a32a MS |
8891 | /* Copy the saved-up fields into the field vector. Start from the head of |
8892 | the list, adding to the tail of the field array, so that they end up in | |
8893 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
8894 | while (nfields-- > 0) |
8895 | { | |
7d0ccb61 DJ |
8896 | struct nextfield *fieldp; |
8897 | ||
8898 | if (fip->fields) | |
8899 | { | |
8900 | fieldp = fip->fields; | |
8901 | fip->fields = fieldp->next; | |
8902 | } | |
8903 | else | |
8904 | { | |
8905 | fieldp = fip->baseclasses; | |
8906 | fip->baseclasses = fieldp->next; | |
8907 | } | |
8908 | ||
8909 | TYPE_FIELD (type, nfields) = fieldp->field; | |
8910 | switch (fieldp->accessibility) | |
c906108c | 8911 | { |
c5aa993b | 8912 | case DW_ACCESS_private: |
b4ba55a1 JB |
8913 | if (cu->language != language_ada) |
8914 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 8915 | break; |
c906108c | 8916 | |
c5aa993b | 8917 | case DW_ACCESS_protected: |
b4ba55a1 JB |
8918 | if (cu->language != language_ada) |
8919 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 8920 | break; |
c906108c | 8921 | |
c5aa993b JM |
8922 | case DW_ACCESS_public: |
8923 | break; | |
c906108c | 8924 | |
c5aa993b JM |
8925 | default: |
8926 | /* Unknown accessibility. Complain and treat it as public. */ | |
8927 | { | |
e2e0b3e5 | 8928 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 8929 | fieldp->accessibility); |
c5aa993b JM |
8930 | } |
8931 | break; | |
c906108c SS |
8932 | } |
8933 | if (nfields < fip->nbaseclasses) | |
8934 | { | |
7d0ccb61 | 8935 | switch (fieldp->virtuality) |
c906108c | 8936 | { |
c5aa993b JM |
8937 | case DW_VIRTUALITY_virtual: |
8938 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 8939 | if (cu->language == language_ada) |
a73c6dcd | 8940 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
8941 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
8942 | break; | |
c906108c SS |
8943 | } |
8944 | } | |
c906108c SS |
8945 | } |
8946 | } | |
8947 | ||
c906108c SS |
8948 | /* Add a member function to the proper fieldlist. */ |
8949 | ||
8950 | static void | |
107d2387 | 8951 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 8952 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 8953 | { |
e7c27a73 | 8954 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8955 | struct attribute *attr; |
8956 | struct fnfieldlist *flp; | |
8957 | int i; | |
8958 | struct fn_field *fnp; | |
8959 | char *fieldname; | |
c906108c | 8960 | struct nextfnfield *new_fnfield; |
f792889a | 8961 | struct type *this_type; |
60d5a603 | 8962 | enum dwarf_access_attribute accessibility; |
c906108c | 8963 | |
b4ba55a1 | 8964 | if (cu->language == language_ada) |
a73c6dcd | 8965 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 8966 | |
2df3850c | 8967 | /* Get name of member function. */ |
39cbfefa DJ |
8968 | fieldname = dwarf2_name (die, cu); |
8969 | if (fieldname == NULL) | |
2df3850c | 8970 | return; |
c906108c | 8971 | |
c906108c SS |
8972 | /* Look up member function name in fieldlist. */ |
8973 | for (i = 0; i < fip->nfnfields; i++) | |
8974 | { | |
27bfe10e | 8975 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
8976 | break; |
8977 | } | |
8978 | ||
8979 | /* Create new list element if necessary. */ | |
8980 | if (i < fip->nfnfields) | |
8981 | flp = &fip->fnfieldlists[i]; | |
8982 | else | |
8983 | { | |
8984 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
8985 | { | |
8986 | fip->fnfieldlists = (struct fnfieldlist *) | |
8987 | xrealloc (fip->fnfieldlists, | |
8988 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 8989 | * sizeof (struct fnfieldlist)); |
c906108c | 8990 | if (fip->nfnfields == 0) |
c13c43fd | 8991 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
8992 | } |
8993 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
8994 | flp->name = fieldname; | |
8995 | flp->length = 0; | |
8996 | flp->head = NULL; | |
3da10d80 | 8997 | i = fip->nfnfields++; |
c906108c SS |
8998 | } |
8999 | ||
9000 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 9001 | entry. */ |
c906108c | 9002 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 9003 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
9004 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
9005 | new_fnfield->next = flp->head; | |
9006 | flp->head = new_fnfield; | |
9007 | flp->length++; | |
9008 | ||
9009 | /* Fill in the member function field info. */ | |
9010 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
9011 | |
9012 | /* Delay processing of the physname until later. */ | |
9013 | if (cu->language == language_cplus || cu->language == language_java) | |
9014 | { | |
9015 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
9016 | die, cu); | |
9017 | } | |
9018 | else | |
9019 | { | |
1d06ead6 | 9020 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
9021 | fnp->physname = physname ? physname : ""; |
9022 | } | |
9023 | ||
c906108c | 9024 | fnp->type = alloc_type (objfile); |
f792889a DJ |
9025 | this_type = read_type_die (die, cu); |
9026 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 9027 | { |
f792889a | 9028 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 9029 | |
f792889a | 9030 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
9031 | of the method itself (TYPE_CODE_METHOD). */ |
9032 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
9033 | TYPE_TARGET_TYPE (this_type), |
9034 | TYPE_FIELDS (this_type), | |
9035 | TYPE_NFIELDS (this_type), | |
9036 | TYPE_VARARGS (this_type)); | |
c906108c SS |
9037 | |
9038 | /* Handle static member functions. | |
c5aa993b | 9039 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
9040 | member functions. G++ helps GDB by marking the first |
9041 | parameter for non-static member functions (which is the this | |
9042 | pointer) as artificial. We obtain this information from | |
9043 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 9044 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
9045 | fnp->voffset = VOFFSET_STATIC; |
9046 | } | |
9047 | else | |
e2e0b3e5 | 9048 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 9049 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
9050 | |
9051 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 9052 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 9053 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 9054 | |
3e43a32a MS |
9055 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
9056 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
9057 | |
9058 | /* Get accessibility. */ | |
e142c38c | 9059 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 9060 | if (attr) |
60d5a603 JK |
9061 | accessibility = DW_UNSND (attr); |
9062 | else | |
9063 | accessibility = dwarf2_default_access_attribute (die, cu); | |
9064 | switch (accessibility) | |
c906108c | 9065 | { |
60d5a603 JK |
9066 | case DW_ACCESS_private: |
9067 | fnp->is_private = 1; | |
9068 | break; | |
9069 | case DW_ACCESS_protected: | |
9070 | fnp->is_protected = 1; | |
9071 | break; | |
c906108c SS |
9072 | } |
9073 | ||
b02dede2 | 9074 | /* Check for artificial methods. */ |
e142c38c | 9075 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
9076 | if (attr && DW_UNSND (attr) != 0) |
9077 | fnp->is_artificial = 1; | |
9078 | ||
0d564a31 | 9079 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
9080 | function. For older versions of GCC, this is an offset in the |
9081 | appropriate virtual table, as specified by DW_AT_containing_type. | |
9082 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
9083 | to the object address. */ |
9084 | ||
e142c38c | 9085 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 9086 | if (attr) |
8e19ed76 | 9087 | { |
aec5aa8b | 9088 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 9089 | { |
aec5aa8b TT |
9090 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
9091 | { | |
9092 | /* Old-style GCC. */ | |
9093 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
9094 | } | |
9095 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
9096 | || (DW_BLOCK (attr)->size > 1 | |
9097 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
9098 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
9099 | { | |
9100 | struct dwarf_block blk; | |
9101 | int offset; | |
9102 | ||
9103 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
9104 | ? 1 : 2); | |
9105 | blk.size = DW_BLOCK (attr)->size - offset; | |
9106 | blk.data = DW_BLOCK (attr)->data + offset; | |
9107 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
9108 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
9109 | dwarf2_complex_location_expr_complaint (); | |
9110 | else | |
9111 | fnp->voffset /= cu->header.addr_size; | |
9112 | fnp->voffset += 2; | |
9113 | } | |
9114 | else | |
9115 | dwarf2_complex_location_expr_complaint (); | |
9116 | ||
9117 | if (!fnp->fcontext) | |
9118 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
9119 | } | |
3690dd37 | 9120 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 9121 | { |
4d3c2250 | 9122 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
9123 | } |
9124 | else | |
9125 | { | |
4d3c2250 KB |
9126 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
9127 | fieldname); | |
8e19ed76 | 9128 | } |
0d564a31 | 9129 | } |
d48cc9dd DJ |
9130 | else |
9131 | { | |
9132 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
9133 | if (attr && DW_UNSND (attr)) | |
9134 | { | |
9135 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
9136 | complaint (&symfile_complaints, | |
3e43a32a MS |
9137 | _("Member function \"%s\" (offset %d) is virtual " |
9138 | "but the vtable offset is not specified"), | |
b64f50a1 | 9139 | fieldname, die->offset.sect_off); |
9655fd1a | 9140 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
9141 | TYPE_CPLUS_DYNAMIC (type) = 1; |
9142 | } | |
9143 | } | |
c906108c SS |
9144 | } |
9145 | ||
9146 | /* Create the vector of member function fields, and attach it to the type. */ | |
9147 | ||
9148 | static void | |
fba45db2 | 9149 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 9150 | struct dwarf2_cu *cu) |
c906108c SS |
9151 | { |
9152 | struct fnfieldlist *flp; | |
c906108c SS |
9153 | int i; |
9154 | ||
b4ba55a1 | 9155 | if (cu->language == language_ada) |
a73c6dcd | 9156 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 9157 | |
c906108c SS |
9158 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
9159 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
9160 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
9161 | ||
9162 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
9163 | { | |
9164 | struct nextfnfield *nfp = flp->head; | |
9165 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
9166 | int k; | |
9167 | ||
9168 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
9169 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
9170 | fn_flp->fn_fields = (struct fn_field *) | |
9171 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
9172 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 9173 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
9174 | } |
9175 | ||
9176 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
c906108c SS |
9177 | } |
9178 | ||
1168df01 JB |
9179 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
9180 | language, zero otherwise. */ | |
9181 | static int | |
9182 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
9183 | { | |
9184 | static const char vptr[] = "_vptr"; | |
987504bb | 9185 | static const char vtable[] = "vtable"; |
1168df01 | 9186 | |
987504bb JJ |
9187 | /* Look for the C++ and Java forms of the vtable. */ |
9188 | if ((cu->language == language_java | |
9189 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
9190 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
9191 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
9192 | return 1; |
9193 | ||
9194 | return 0; | |
9195 | } | |
9196 | ||
c0dd20ea | 9197 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
9198 | functions, with the ABI-specified layout. If TYPE describes |
9199 | such a structure, smash it into a member function type. | |
61049d3b DJ |
9200 | |
9201 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
9202 | This is GCC PR debug/28767. */ | |
c0dd20ea | 9203 | |
0b92b5bb TT |
9204 | static void |
9205 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 9206 | { |
0b92b5bb | 9207 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
9208 | |
9209 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
9210 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
9211 | return; | |
c0dd20ea DJ |
9212 | |
9213 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
9214 | if (TYPE_FIELD_NAME (type, 0) == NULL |
9215 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
9216 | || TYPE_FIELD_NAME (type, 1) == NULL | |
9217 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
9218 | return; | |
c0dd20ea DJ |
9219 | |
9220 | /* Find the type of the method. */ | |
0b92b5bb | 9221 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
9222 | if (pfn_type == NULL |
9223 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
9224 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 9225 | return; |
c0dd20ea DJ |
9226 | |
9227 | /* Look for the "this" argument. */ | |
9228 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
9229 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 9230 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 9231 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 9232 | return; |
c0dd20ea DJ |
9233 | |
9234 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
9235 | new_type = alloc_type (objfile); |
9236 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
9237 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
9238 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 9239 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 9240 | } |
1168df01 | 9241 | |
685b1105 JK |
9242 | /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler |
9243 | (icc). */ | |
9244 | ||
9245 | static int | |
9246 | producer_is_icc (struct dwarf2_cu *cu) | |
9247 | { | |
9248 | if (!cu->checked_producer) | |
9249 | check_producer (cu); | |
9250 | ||
9251 | return cu->producer_is_icc; | |
9252 | } | |
9253 | ||
c906108c | 9254 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
9255 | (definition) to create a type for the structure or union. Fill in |
9256 | the type's name and general properties; the members will not be | |
9257 | processed until process_structure_type. | |
c906108c | 9258 | |
c767944b DJ |
9259 | NOTE: we need to call these functions regardless of whether or not the |
9260 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
9261 | structure or union. This gets the type entered into our set of |
9262 | user defined types. | |
9263 | ||
9264 | However, if the structure is incomplete (an opaque struct/union) | |
9265 | then suppress creating a symbol table entry for it since gdb only | |
9266 | wants to find the one with the complete definition. Note that if | |
9267 | it is complete, we just call new_symbol, which does it's own | |
9268 | checking about whether the struct/union is anonymous or not (and | |
9269 | suppresses creating a symbol table entry itself). */ | |
9270 | ||
f792889a | 9271 | static struct type * |
134d01f1 | 9272 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9273 | { |
e7c27a73 | 9274 | struct objfile *objfile = cu->objfile; |
c906108c SS |
9275 | struct type *type; |
9276 | struct attribute *attr; | |
39cbfefa | 9277 | char *name; |
c906108c | 9278 | |
348e048f DE |
9279 | /* If the definition of this type lives in .debug_types, read that type. |
9280 | Don't follow DW_AT_specification though, that will take us back up | |
9281 | the chain and we want to go down. */ | |
9282 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
9283 | if (attr) | |
9284 | { | |
9285 | struct dwarf2_cu *type_cu = cu; | |
9286 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 9287 | |
348e048f DE |
9288 | /* We could just recurse on read_structure_type, but we need to call |
9289 | get_die_type to ensure only one type for this DIE is created. | |
9290 | This is important, for example, because for c++ classes we need | |
9291 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
9292 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
9293 | |
9294 | /* TYPE_CU may not be the same as CU. | |
9295 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
9296 | return set_die_type (die, type, cu); |
9297 | } | |
9298 | ||
c0dd20ea | 9299 | type = alloc_type (objfile); |
c906108c | 9300 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 9301 | |
39cbfefa DJ |
9302 | name = dwarf2_name (die, cu); |
9303 | if (name != NULL) | |
c906108c | 9304 | { |
987504bb JJ |
9305 | if (cu->language == language_cplus |
9306 | || cu->language == language_java) | |
63d06c5c | 9307 | { |
3da10d80 KS |
9308 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
9309 | ||
9310 | /* dwarf2_full_name might have already finished building the DIE's | |
9311 | type. If so, there is no need to continue. */ | |
9312 | if (get_die_type (die, cu) != NULL) | |
9313 | return get_die_type (die, cu); | |
9314 | ||
9315 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
9316 | if (die->tag == DW_TAG_structure_type |
9317 | || die->tag == DW_TAG_class_type) | |
9318 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
9319 | } |
9320 | else | |
9321 | { | |
d8151005 DJ |
9322 | /* The name is already allocated along with this objfile, so |
9323 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
9324 | TYPE_TAG_NAME (type) = (char *) name; |
9325 | if (die->tag == DW_TAG_class_type) | |
9326 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 9327 | } |
c906108c SS |
9328 | } |
9329 | ||
9330 | if (die->tag == DW_TAG_structure_type) | |
9331 | { | |
9332 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
9333 | } | |
9334 | else if (die->tag == DW_TAG_union_type) | |
9335 | { | |
9336 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
9337 | } | |
9338 | else | |
9339 | { | |
c906108c SS |
9340 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
9341 | } | |
9342 | ||
0cc2414c TT |
9343 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
9344 | TYPE_DECLARED_CLASS (type) = 1; | |
9345 | ||
e142c38c | 9346 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
9347 | if (attr) |
9348 | { | |
9349 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
9350 | } | |
9351 | else | |
9352 | { | |
9353 | TYPE_LENGTH (type) = 0; | |
9354 | } | |
9355 | ||
685b1105 JK |
9356 | if (producer_is_icc (cu)) |
9357 | { | |
9358 | /* ICC does not output the required DW_AT_declaration | |
9359 | on incomplete types, but gives them a size of zero. */ | |
9360 | } | |
9361 | else | |
9362 | TYPE_STUB_SUPPORTED (type) = 1; | |
9363 | ||
dc718098 | 9364 | if (die_is_declaration (die, cu)) |
876cecd0 | 9365 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
9366 | else if (attr == NULL && die->child == NULL |
9367 | && producer_is_realview (cu->producer)) | |
9368 | /* RealView does not output the required DW_AT_declaration | |
9369 | on incomplete types. */ | |
9370 | TYPE_STUB (type) = 1; | |
dc718098 | 9371 | |
c906108c SS |
9372 | /* We need to add the type field to the die immediately so we don't |
9373 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 9374 | type within the structure itself. */ |
1c379e20 | 9375 | set_die_type (die, type, cu); |
c906108c | 9376 | |
7e314c57 JK |
9377 | /* set_die_type should be already done. */ |
9378 | set_descriptive_type (type, die, cu); | |
9379 | ||
c767944b DJ |
9380 | return type; |
9381 | } | |
9382 | ||
9383 | /* Finish creating a structure or union type, including filling in | |
9384 | its members and creating a symbol for it. */ | |
9385 | ||
9386 | static void | |
9387 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
9388 | { | |
9389 | struct objfile *objfile = cu->objfile; | |
9390 | struct die_info *child_die = die->child; | |
9391 | struct type *type; | |
9392 | ||
9393 | type = get_die_type (die, cu); | |
9394 | if (type == NULL) | |
9395 | type = read_structure_type (die, cu); | |
9396 | ||
e142c38c | 9397 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
9398 | { |
9399 | struct field_info fi; | |
9400 | struct die_info *child_die; | |
34eaf542 | 9401 | VEC (symbolp) *template_args = NULL; |
c767944b | 9402 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
9403 | |
9404 | memset (&fi, 0, sizeof (struct field_info)); | |
9405 | ||
639d11d3 | 9406 | child_die = die->child; |
c906108c SS |
9407 | |
9408 | while (child_die && child_die->tag) | |
9409 | { | |
a9a9bd0f DC |
9410 | if (child_die->tag == DW_TAG_member |
9411 | || child_die->tag == DW_TAG_variable) | |
c906108c | 9412 | { |
a9a9bd0f DC |
9413 | /* NOTE: carlton/2002-11-05: A C++ static data member |
9414 | should be a DW_TAG_member that is a declaration, but | |
9415 | all versions of G++ as of this writing (so through at | |
9416 | least 3.2.1) incorrectly generate DW_TAG_variable | |
9417 | tags for them instead. */ | |
e7c27a73 | 9418 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 9419 | } |
8713b1b1 | 9420 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 9421 | { |
0963b4bd | 9422 | /* C++ member function. */ |
e7c27a73 | 9423 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
9424 | } |
9425 | else if (child_die->tag == DW_TAG_inheritance) | |
9426 | { | |
9427 | /* C++ base class field. */ | |
e7c27a73 | 9428 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 9429 | } |
98751a41 JK |
9430 | else if (child_die->tag == DW_TAG_typedef) |
9431 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
9432 | else if (child_die->tag == DW_TAG_template_type_param |
9433 | || child_die->tag == DW_TAG_template_value_param) | |
9434 | { | |
9435 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
9436 | ||
f1078f66 DJ |
9437 | if (arg != NULL) |
9438 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
9439 | } |
9440 | ||
c906108c SS |
9441 | child_die = sibling_die (child_die); |
9442 | } | |
9443 | ||
34eaf542 TT |
9444 | /* Attach template arguments to type. */ |
9445 | if (! VEC_empty (symbolp, template_args)) | |
9446 | { | |
9447 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
9448 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
9449 | = VEC_length (symbolp, template_args); | |
9450 | TYPE_TEMPLATE_ARGUMENTS (type) | |
9451 | = obstack_alloc (&objfile->objfile_obstack, | |
9452 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
9453 | * sizeof (struct symbol *))); | |
9454 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
9455 | VEC_address (symbolp, template_args), | |
9456 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
9457 | * sizeof (struct symbol *))); | |
9458 | VEC_free (symbolp, template_args); | |
9459 | } | |
9460 | ||
c906108c SS |
9461 | /* Attach fields and member functions to the type. */ |
9462 | if (fi.nfields) | |
e7c27a73 | 9463 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
9464 | if (fi.nfnfields) |
9465 | { | |
e7c27a73 | 9466 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 9467 | |
c5aa993b | 9468 | /* Get the type which refers to the base class (possibly this |
c906108c | 9469 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
9470 | class from the DW_AT_containing_type attribute. This use of |
9471 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 9472 | |
e142c38c | 9473 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 9474 | { |
e7c27a73 | 9475 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
9476 | |
9477 | TYPE_VPTR_BASETYPE (type) = t; | |
9478 | if (type == t) | |
9479 | { | |
c906108c SS |
9480 | int i; |
9481 | ||
9482 | /* Our own class provides vtbl ptr. */ | |
9483 | for (i = TYPE_NFIELDS (t) - 1; | |
9484 | i >= TYPE_N_BASECLASSES (t); | |
9485 | --i) | |
9486 | { | |
0d5cff50 | 9487 | const char *fieldname = TYPE_FIELD_NAME (t, i); |
c906108c | 9488 | |
1168df01 | 9489 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
9490 | { |
9491 | TYPE_VPTR_FIELDNO (type) = i; | |
9492 | break; | |
9493 | } | |
9494 | } | |
9495 | ||
9496 | /* Complain if virtual function table field not found. */ | |
9497 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 9498 | complaint (&symfile_complaints, |
3e43a32a MS |
9499 | _("virtual function table pointer " |
9500 | "not found when defining class '%s'"), | |
4d3c2250 KB |
9501 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
9502 | ""); | |
c906108c SS |
9503 | } |
9504 | else | |
9505 | { | |
9506 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
9507 | } | |
9508 | } | |
f6235d4c EZ |
9509 | else if (cu->producer |
9510 | && strncmp (cu->producer, | |
9511 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
9512 | { | |
9513 | /* The IBM XLC compiler does not provide direct indication | |
9514 | of the containing type, but the vtable pointer is | |
9515 | always named __vfp. */ | |
9516 | ||
9517 | int i; | |
9518 | ||
9519 | for (i = TYPE_NFIELDS (type) - 1; | |
9520 | i >= TYPE_N_BASECLASSES (type); | |
9521 | --i) | |
9522 | { | |
9523 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
9524 | { | |
9525 | TYPE_VPTR_FIELDNO (type) = i; | |
9526 | TYPE_VPTR_BASETYPE (type) = type; | |
9527 | break; | |
9528 | } | |
9529 | } | |
9530 | } | |
c906108c | 9531 | } |
98751a41 JK |
9532 | |
9533 | /* Copy fi.typedef_field_list linked list elements content into the | |
9534 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
9535 | if (fi.typedef_field_list) | |
9536 | { | |
9537 | int i = fi.typedef_field_list_count; | |
9538 | ||
a0d7a4ff | 9539 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
9540 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
9541 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
9542 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
9543 | ||
9544 | /* Reverse the list order to keep the debug info elements order. */ | |
9545 | while (--i >= 0) | |
9546 | { | |
9547 | struct typedef_field *dest, *src; | |
6e70227d | 9548 | |
98751a41 JK |
9549 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
9550 | src = &fi.typedef_field_list->field; | |
9551 | fi.typedef_field_list = fi.typedef_field_list->next; | |
9552 | *dest = *src; | |
9553 | } | |
9554 | } | |
c767944b DJ |
9555 | |
9556 | do_cleanups (back_to); | |
eb2a6f42 TT |
9557 | |
9558 | if (HAVE_CPLUS_STRUCT (type)) | |
9559 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; | |
c906108c | 9560 | } |
63d06c5c | 9561 | |
bb5ed363 | 9562 | quirk_gcc_member_function_pointer (type, objfile); |
0b92b5bb | 9563 | |
90aeadfc DC |
9564 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
9565 | snapshots) has been known to create a die giving a declaration | |
9566 | for a class that has, as a child, a die giving a definition for a | |
9567 | nested class. So we have to process our children even if the | |
9568 | current die is a declaration. Normally, of course, a declaration | |
9569 | won't have any children at all. */ | |
134d01f1 | 9570 | |
90aeadfc DC |
9571 | while (child_die != NULL && child_die->tag) |
9572 | { | |
9573 | if (child_die->tag == DW_TAG_member | |
9574 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
9575 | || child_die->tag == DW_TAG_inheritance |
9576 | || child_die->tag == DW_TAG_template_value_param | |
9577 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 9578 | { |
90aeadfc | 9579 | /* Do nothing. */ |
134d01f1 | 9580 | } |
90aeadfc DC |
9581 | else |
9582 | process_die (child_die, cu); | |
134d01f1 | 9583 | |
90aeadfc | 9584 | child_die = sibling_die (child_die); |
134d01f1 DJ |
9585 | } |
9586 | ||
fa4028e9 JB |
9587 | /* Do not consider external references. According to the DWARF standard, |
9588 | these DIEs are identified by the fact that they have no byte_size | |
9589 | attribute, and a declaration attribute. */ | |
9590 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
9591 | || !die_is_declaration (die, cu)) | |
c767944b | 9592 | new_symbol (die, type, cu); |
134d01f1 DJ |
9593 | } |
9594 | ||
9595 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
9596 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 9597 | |
f792889a | 9598 | static struct type * |
134d01f1 | 9599 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9600 | { |
e7c27a73 | 9601 | struct objfile *objfile = cu->objfile; |
c906108c | 9602 | struct type *type; |
c906108c | 9603 | struct attribute *attr; |
0114d602 | 9604 | const char *name; |
134d01f1 | 9605 | |
348e048f DE |
9606 | /* If the definition of this type lives in .debug_types, read that type. |
9607 | Don't follow DW_AT_specification though, that will take us back up | |
9608 | the chain and we want to go down. */ | |
9609 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
9610 | if (attr) | |
9611 | { | |
9612 | struct dwarf2_cu *type_cu = cu; | |
9613 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 9614 | |
348e048f | 9615 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
9616 | |
9617 | /* TYPE_CU may not be the same as CU. | |
9618 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
9619 | return set_die_type (die, type, cu); |
9620 | } | |
9621 | ||
c906108c SS |
9622 | type = alloc_type (objfile); |
9623 | ||
9624 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 9625 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 9626 | if (name != NULL) |
0114d602 | 9627 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 9628 | |
e142c38c | 9629 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
9630 | if (attr) |
9631 | { | |
9632 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
9633 | } | |
9634 | else | |
9635 | { | |
9636 | TYPE_LENGTH (type) = 0; | |
9637 | } | |
9638 | ||
137033e9 JB |
9639 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
9640 | declared as private in the package spec, and then defined only | |
9641 | inside the package body. Such types are known as Taft Amendment | |
9642 | Types. When another package uses such a type, an incomplete DIE | |
9643 | may be generated by the compiler. */ | |
02eb380e | 9644 | if (die_is_declaration (die, cu)) |
876cecd0 | 9645 | TYPE_STUB (type) = 1; |
02eb380e | 9646 | |
f792889a | 9647 | return set_die_type (die, type, cu); |
134d01f1 DJ |
9648 | } |
9649 | ||
9650 | /* Given a pointer to a die which begins an enumeration, process all | |
9651 | the dies that define the members of the enumeration, and create the | |
9652 | symbol for the enumeration type. | |
9653 | ||
9654 | NOTE: We reverse the order of the element list. */ | |
9655 | ||
9656 | static void | |
9657 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
9658 | { | |
f792889a | 9659 | struct type *this_type; |
134d01f1 | 9660 | |
f792889a DJ |
9661 | this_type = get_die_type (die, cu); |
9662 | if (this_type == NULL) | |
9663 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 9664 | |
639d11d3 | 9665 | if (die->child != NULL) |
c906108c | 9666 | { |
9dc481d3 DE |
9667 | struct die_info *child_die; |
9668 | struct symbol *sym; | |
9669 | struct field *fields = NULL; | |
9670 | int num_fields = 0; | |
9671 | int unsigned_enum = 1; | |
9672 | char *name; | |
cafec441 TT |
9673 | int flag_enum = 1; |
9674 | ULONGEST mask = 0; | |
9dc481d3 | 9675 | |
639d11d3 | 9676 | child_die = die->child; |
c906108c SS |
9677 | while (child_die && child_die->tag) |
9678 | { | |
9679 | if (child_die->tag != DW_TAG_enumerator) | |
9680 | { | |
e7c27a73 | 9681 | process_die (child_die, cu); |
c906108c SS |
9682 | } |
9683 | else | |
9684 | { | |
39cbfefa DJ |
9685 | name = dwarf2_name (child_die, cu); |
9686 | if (name) | |
c906108c | 9687 | { |
f792889a | 9688 | sym = new_symbol (child_die, this_type, cu); |
c906108c | 9689 | if (SYMBOL_VALUE (sym) < 0) |
cafec441 TT |
9690 | { |
9691 | unsigned_enum = 0; | |
9692 | flag_enum = 0; | |
9693 | } | |
9694 | else if ((mask & SYMBOL_VALUE (sym)) != 0) | |
9695 | flag_enum = 0; | |
9696 | else | |
9697 | mask |= SYMBOL_VALUE (sym); | |
c906108c SS |
9698 | |
9699 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
9700 | { | |
9701 | fields = (struct field *) | |
9702 | xrealloc (fields, | |
9703 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 9704 | * sizeof (struct field)); |
c906108c SS |
9705 | } |
9706 | ||
3567439c | 9707 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 9708 | FIELD_TYPE (fields[num_fields]) = NULL; |
14e75d8e | 9709 | SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
9710 | FIELD_BITSIZE (fields[num_fields]) = 0; |
9711 | ||
9712 | num_fields++; | |
9713 | } | |
9714 | } | |
9715 | ||
9716 | child_die = sibling_die (child_die); | |
9717 | } | |
9718 | ||
9719 | if (num_fields) | |
9720 | { | |
f792889a DJ |
9721 | TYPE_NFIELDS (this_type) = num_fields; |
9722 | TYPE_FIELDS (this_type) = (struct field *) | |
9723 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
9724 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 9725 | sizeof (struct field) * num_fields); |
b8c9b27d | 9726 | xfree (fields); |
c906108c SS |
9727 | } |
9728 | if (unsigned_enum) | |
876cecd0 | 9729 | TYPE_UNSIGNED (this_type) = 1; |
cafec441 TT |
9730 | if (flag_enum) |
9731 | TYPE_FLAG_ENUM (this_type) = 1; | |
c906108c | 9732 | } |
134d01f1 | 9733 | |
6c83ed52 TT |
9734 | /* If we are reading an enum from a .debug_types unit, and the enum |
9735 | is a declaration, and the enum is not the signatured type in the | |
9736 | unit, then we do not want to add a symbol for it. Adding a | |
9737 | symbol would in some cases obscure the true definition of the | |
9738 | enum, giving users an incomplete type when the definition is | |
9739 | actually available. Note that we do not want to do this for all | |
9740 | enums which are just declarations, because C++0x allows forward | |
9741 | enum declarations. */ | |
3019eac3 | 9742 | if (cu->per_cu->is_debug_types |
6c83ed52 TT |
9743 | && die_is_declaration (die, cu)) |
9744 | { | |
52dc124a | 9745 | struct signatured_type *sig_type; |
6c83ed52 | 9746 | |
52dc124a | 9747 | sig_type |
6c83ed52 | 9748 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, |
3019eac3 | 9749 | cu->per_cu->info_or_types_section, |
6c83ed52 | 9750 | cu->per_cu->offset); |
3019eac3 DE |
9751 | gdb_assert (sig_type->type_offset_in_section.sect_off != 0); |
9752 | if (sig_type->type_offset_in_section.sect_off != die->offset.sect_off) | |
6c83ed52 TT |
9753 | return; |
9754 | } | |
9755 | ||
f792889a | 9756 | new_symbol (die, this_type, cu); |
c906108c SS |
9757 | } |
9758 | ||
9759 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
9760 | the DIE's type field. For now, this only handles one dimensional | |
9761 | arrays. */ | |
9762 | ||
f792889a | 9763 | static struct type * |
e7c27a73 | 9764 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9765 | { |
e7c27a73 | 9766 | struct objfile *objfile = cu->objfile; |
c906108c | 9767 | struct die_info *child_die; |
7e314c57 | 9768 | struct type *type; |
c906108c SS |
9769 | struct type *element_type, *range_type, *index_type; |
9770 | struct type **range_types = NULL; | |
9771 | struct attribute *attr; | |
9772 | int ndim = 0; | |
9773 | struct cleanup *back_to; | |
39cbfefa | 9774 | char *name; |
c906108c | 9775 | |
e7c27a73 | 9776 | element_type = die_type (die, cu); |
c906108c | 9777 | |
7e314c57 JK |
9778 | /* The die_type call above may have already set the type for this DIE. */ |
9779 | type = get_die_type (die, cu); | |
9780 | if (type) | |
9781 | return type; | |
9782 | ||
c906108c SS |
9783 | /* Irix 6.2 native cc creates array types without children for |
9784 | arrays with unspecified length. */ | |
639d11d3 | 9785 | if (die->child == NULL) |
c906108c | 9786 | { |
46bf5051 | 9787 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 9788 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
9789 | type = create_array_type (NULL, element_type, range_type); |
9790 | return set_die_type (die, type, cu); | |
c906108c SS |
9791 | } |
9792 | ||
9793 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 9794 | child_die = die->child; |
c906108c SS |
9795 | while (child_die && child_die->tag) |
9796 | { | |
9797 | if (child_die->tag == DW_TAG_subrange_type) | |
9798 | { | |
f792889a | 9799 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 9800 | |
f792889a | 9801 | if (child_type != NULL) |
a02abb62 | 9802 | { |
0963b4bd MS |
9803 | /* The range type was succesfully read. Save it for the |
9804 | array type creation. */ | |
a02abb62 JB |
9805 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
9806 | { | |
9807 | range_types = (struct type **) | |
9808 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
9809 | * sizeof (struct type *)); | |
9810 | if (ndim == 0) | |
9811 | make_cleanup (free_current_contents, &range_types); | |
9812 | } | |
f792889a | 9813 | range_types[ndim++] = child_type; |
a02abb62 | 9814 | } |
c906108c SS |
9815 | } |
9816 | child_die = sibling_die (child_die); | |
9817 | } | |
9818 | ||
9819 | /* Dwarf2 dimensions are output from left to right, create the | |
9820 | necessary array types in backwards order. */ | |
7ca2d3a3 | 9821 | |
c906108c | 9822 | type = element_type; |
7ca2d3a3 DL |
9823 | |
9824 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
9825 | { | |
9826 | int i = 0; | |
9a619af0 | 9827 | |
7ca2d3a3 DL |
9828 | while (i < ndim) |
9829 | type = create_array_type (NULL, type, range_types[i++]); | |
9830 | } | |
9831 | else | |
9832 | { | |
9833 | while (ndim-- > 0) | |
9834 | type = create_array_type (NULL, type, range_types[ndim]); | |
9835 | } | |
c906108c | 9836 | |
f5f8a009 EZ |
9837 | /* Understand Dwarf2 support for vector types (like they occur on |
9838 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
9839 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
9840 | custom vendor extension. The main difference between a regular | |
9841 | array and the vector variant is that vectors are passed by value | |
9842 | to functions. */ | |
e142c38c | 9843 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 9844 | if (attr) |
ea37ba09 | 9845 | make_vector_type (type); |
f5f8a009 | 9846 | |
dbc98a8b KW |
9847 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
9848 | implementation may choose to implement triple vectors using this | |
9849 | attribute. */ | |
9850 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
9851 | if (attr) | |
9852 | { | |
9853 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
9854 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
9855 | else | |
3e43a32a MS |
9856 | complaint (&symfile_complaints, |
9857 | _("DW_AT_byte_size for array type smaller " | |
9858 | "than the total size of elements")); | |
dbc98a8b KW |
9859 | } |
9860 | ||
39cbfefa DJ |
9861 | name = dwarf2_name (die, cu); |
9862 | if (name) | |
9863 | TYPE_NAME (type) = name; | |
6e70227d | 9864 | |
0963b4bd | 9865 | /* Install the type in the die. */ |
7e314c57 JK |
9866 | set_die_type (die, type, cu); |
9867 | ||
9868 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
9869 | set_descriptive_type (type, die, cu); |
9870 | ||
c906108c SS |
9871 | do_cleanups (back_to); |
9872 | ||
7e314c57 | 9873 | return type; |
c906108c SS |
9874 | } |
9875 | ||
7ca2d3a3 | 9876 | static enum dwarf_array_dim_ordering |
6e70227d | 9877 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
9878 | { |
9879 | struct attribute *attr; | |
9880 | ||
9881 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
9882 | ||
9883 | if (attr) return DW_SND (attr); | |
9884 | ||
0963b4bd MS |
9885 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
9886 | opposite order to the dwarf2 specification, but data is still | |
9887 | laid out as per normal fortran. | |
7ca2d3a3 | 9888 | |
0963b4bd MS |
9889 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
9890 | version checking. */ | |
7ca2d3a3 | 9891 | |
905e0470 PM |
9892 | if (cu->language == language_fortran |
9893 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
9894 | { |
9895 | return DW_ORD_row_major; | |
9896 | } | |
9897 | ||
6e70227d | 9898 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
9899 | { |
9900 | case array_column_major: | |
9901 | return DW_ORD_col_major; | |
9902 | case array_row_major: | |
9903 | default: | |
9904 | return DW_ORD_row_major; | |
9905 | }; | |
9906 | } | |
9907 | ||
72019c9c | 9908 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 9909 | the DIE's type field. */ |
72019c9c | 9910 | |
f792889a | 9911 | static struct type * |
72019c9c GM |
9912 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
9913 | { | |
7e314c57 JK |
9914 | struct type *domain_type, *set_type; |
9915 | struct attribute *attr; | |
f792889a | 9916 | |
7e314c57 JK |
9917 | domain_type = die_type (die, cu); |
9918 | ||
9919 | /* The die_type call above may have already set the type for this DIE. */ | |
9920 | set_type = get_die_type (die, cu); | |
9921 | if (set_type) | |
9922 | return set_type; | |
9923 | ||
9924 | set_type = create_set_type (NULL, domain_type); | |
9925 | ||
9926 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
9927 | if (attr) |
9928 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 9929 | |
f792889a | 9930 | return set_die_type (die, set_type, cu); |
72019c9c | 9931 | } |
7ca2d3a3 | 9932 | |
c906108c SS |
9933 | /* First cut: install each common block member as a global variable. */ |
9934 | ||
9935 | static void | |
e7c27a73 | 9936 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
9937 | { |
9938 | struct die_info *child_die; | |
9939 | struct attribute *attr; | |
9940 | struct symbol *sym; | |
9941 | CORE_ADDR base = (CORE_ADDR) 0; | |
9942 | ||
e142c38c | 9943 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
9944 | if (attr) |
9945 | { | |
0963b4bd | 9946 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
9947 | if (attr_form_is_block (attr)) |
9948 | { | |
e7c27a73 | 9949 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 9950 | } |
3690dd37 | 9951 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 9952 | { |
4d3c2250 | 9953 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
9954 | } |
9955 | else | |
9956 | { | |
4d3c2250 KB |
9957 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
9958 | "common block member"); | |
8e19ed76 | 9959 | } |
c906108c | 9960 | } |
639d11d3 | 9961 | if (die->child != NULL) |
c906108c | 9962 | { |
639d11d3 | 9963 | child_die = die->child; |
c906108c SS |
9964 | while (child_die && child_die->tag) |
9965 | { | |
74ac6d43 TT |
9966 | LONGEST offset; |
9967 | ||
e7c27a73 | 9968 | sym = new_symbol (child_die, NULL, cu); |
e8d28ef4 TT |
9969 | if (sym != NULL |
9970 | && handle_data_member_location (child_die, cu, &offset)) | |
c906108c | 9971 | { |
74ac6d43 | 9972 | SYMBOL_VALUE_ADDRESS (sym) = base + offset; |
c906108c SS |
9973 | add_symbol_to_list (sym, &global_symbols); |
9974 | } | |
9975 | child_die = sibling_die (child_die); | |
9976 | } | |
9977 | } | |
9978 | } | |
9979 | ||
0114d602 | 9980 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 9981 | |
0114d602 DJ |
9982 | static struct type * |
9983 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 9984 | { |
e7c27a73 | 9985 | struct objfile *objfile = cu->objfile; |
0114d602 | 9986 | const char *previous_prefix, *name; |
9219021c | 9987 | int is_anonymous; |
0114d602 DJ |
9988 | struct type *type; |
9989 | ||
9990 | /* For extensions, reuse the type of the original namespace. */ | |
9991 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
9992 | { | |
9993 | struct die_info *ext_die; | |
9994 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 9995 | |
0114d602 DJ |
9996 | ext_die = dwarf2_extension (die, &ext_cu); |
9997 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
9998 | |
9999 | /* EXT_CU may not be the same as CU. | |
10000 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
10001 | return set_die_type (die, type, cu); |
10002 | } | |
9219021c | 10003 | |
e142c38c | 10004 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
10005 | |
10006 | /* Now build the name of the current namespace. */ | |
10007 | ||
0114d602 DJ |
10008 | previous_prefix = determine_prefix (die, cu); |
10009 | if (previous_prefix[0] != '\0') | |
10010 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 10011 | previous_prefix, name, 0, cu); |
0114d602 DJ |
10012 | |
10013 | /* Create the type. */ | |
10014 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
10015 | objfile); | |
10016 | TYPE_NAME (type) = (char *) name; | |
10017 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
10018 | ||
60531b24 | 10019 | return set_die_type (die, type, cu); |
0114d602 DJ |
10020 | } |
10021 | ||
10022 | /* Read a C++ namespace. */ | |
10023 | ||
10024 | static void | |
10025 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
10026 | { | |
10027 | struct objfile *objfile = cu->objfile; | |
0114d602 | 10028 | int is_anonymous; |
9219021c | 10029 | |
5c4e30ca DC |
10030 | /* Add a symbol associated to this if we haven't seen the namespace |
10031 | before. Also, add a using directive if it's an anonymous | |
10032 | namespace. */ | |
9219021c | 10033 | |
f2f0e013 | 10034 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
10035 | { |
10036 | struct type *type; | |
10037 | ||
0114d602 | 10038 | type = read_type_die (die, cu); |
e7c27a73 | 10039 | new_symbol (die, type, cu); |
5c4e30ca | 10040 | |
e8e80198 | 10041 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 10042 | if (is_anonymous) |
0114d602 DJ |
10043 | { |
10044 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 10045 | |
c0cc3a76 | 10046 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
32019081 | 10047 | NULL, NULL, &objfile->objfile_obstack); |
0114d602 | 10048 | } |
5c4e30ca | 10049 | } |
9219021c | 10050 | |
639d11d3 | 10051 | if (die->child != NULL) |
d9fa45fe | 10052 | { |
639d11d3 | 10053 | struct die_info *child_die = die->child; |
6e70227d | 10054 | |
d9fa45fe DC |
10055 | while (child_die && child_die->tag) |
10056 | { | |
e7c27a73 | 10057 | process_die (child_die, cu); |
d9fa45fe DC |
10058 | child_die = sibling_die (child_die); |
10059 | } | |
10060 | } | |
38d518c9 EZ |
10061 | } |
10062 | ||
f55ee35c JK |
10063 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
10064 | imported module. Still we need that type as local Fortran "use ... only" | |
10065 | declaration imports depend on the created type in determine_prefix. */ | |
10066 | ||
10067 | static struct type * | |
10068 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
10069 | { | |
10070 | struct objfile *objfile = cu->objfile; | |
10071 | char *module_name; | |
10072 | struct type *type; | |
10073 | ||
10074 | module_name = dwarf2_name (die, cu); | |
10075 | if (!module_name) | |
3e43a32a MS |
10076 | complaint (&symfile_complaints, |
10077 | _("DW_TAG_module has no name, offset 0x%x"), | |
b64f50a1 | 10078 | die->offset.sect_off); |
f55ee35c JK |
10079 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); |
10080 | ||
10081 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
10082 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
10083 | ||
10084 | return set_die_type (die, type, cu); | |
10085 | } | |
10086 | ||
5d7cb8df JK |
10087 | /* Read a Fortran module. */ |
10088 | ||
10089 | static void | |
10090 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
10091 | { | |
10092 | struct die_info *child_die = die->child; | |
10093 | ||
5d7cb8df JK |
10094 | while (child_die && child_die->tag) |
10095 | { | |
10096 | process_die (child_die, cu); | |
10097 | child_die = sibling_die (child_die); | |
10098 | } | |
10099 | } | |
10100 | ||
38d518c9 EZ |
10101 | /* Return the name of the namespace represented by DIE. Set |
10102 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
10103 | namespace. */ | |
10104 | ||
10105 | static const char * | |
e142c38c | 10106 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
10107 | { |
10108 | struct die_info *current_die; | |
10109 | const char *name = NULL; | |
10110 | ||
10111 | /* Loop through the extensions until we find a name. */ | |
10112 | ||
10113 | for (current_die = die; | |
10114 | current_die != NULL; | |
f2f0e013 | 10115 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 10116 | { |
e142c38c | 10117 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
10118 | if (name != NULL) |
10119 | break; | |
10120 | } | |
10121 | ||
10122 | /* Is it an anonymous namespace? */ | |
10123 | ||
10124 | *is_anonymous = (name == NULL); | |
10125 | if (*is_anonymous) | |
2b1dbab0 | 10126 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
10127 | |
10128 | return name; | |
d9fa45fe DC |
10129 | } |
10130 | ||
c906108c SS |
10131 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
10132 | the user defined type vector. */ | |
10133 | ||
f792889a | 10134 | static struct type * |
e7c27a73 | 10135 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10136 | { |
5e2b427d | 10137 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 10138 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 10139 | struct type *type; |
8b2dbe47 KB |
10140 | struct attribute *attr_byte_size; |
10141 | struct attribute *attr_address_class; | |
10142 | int byte_size, addr_class; | |
7e314c57 JK |
10143 | struct type *target_type; |
10144 | ||
10145 | target_type = die_type (die, cu); | |
c906108c | 10146 | |
7e314c57 JK |
10147 | /* The die_type call above may have already set the type for this DIE. */ |
10148 | type = get_die_type (die, cu); | |
10149 | if (type) | |
10150 | return type; | |
10151 | ||
10152 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 10153 | |
e142c38c | 10154 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
10155 | if (attr_byte_size) |
10156 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 10157 | else |
8b2dbe47 KB |
10158 | byte_size = cu_header->addr_size; |
10159 | ||
e142c38c | 10160 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
10161 | if (attr_address_class) |
10162 | addr_class = DW_UNSND (attr_address_class); | |
10163 | else | |
10164 | addr_class = DW_ADDR_none; | |
10165 | ||
10166 | /* If the pointer size or address class is different than the | |
10167 | default, create a type variant marked as such and set the | |
10168 | length accordingly. */ | |
10169 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 10170 | { |
5e2b427d | 10171 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
10172 | { |
10173 | int type_flags; | |
10174 | ||
849957d9 | 10175 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 10176 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
10177 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
10178 | == 0); | |
8b2dbe47 KB |
10179 | type = make_type_with_address_space (type, type_flags); |
10180 | } | |
10181 | else if (TYPE_LENGTH (type) != byte_size) | |
10182 | { | |
3e43a32a MS |
10183 | complaint (&symfile_complaints, |
10184 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 10185 | } |
6e70227d | 10186 | else |
9a619af0 MS |
10187 | { |
10188 | /* Should we also complain about unhandled address classes? */ | |
10189 | } | |
c906108c | 10190 | } |
8b2dbe47 KB |
10191 | |
10192 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 10193 | return set_die_type (die, type, cu); |
c906108c SS |
10194 | } |
10195 | ||
10196 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
10197 | the user defined type vector. */ | |
10198 | ||
f792889a | 10199 | static struct type * |
e7c27a73 | 10200 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
10201 | { |
10202 | struct type *type; | |
10203 | struct type *to_type; | |
10204 | struct type *domain; | |
10205 | ||
e7c27a73 DJ |
10206 | to_type = die_type (die, cu); |
10207 | domain = die_containing_type (die, cu); | |
0d5de010 | 10208 | |
7e314c57 JK |
10209 | /* The calls above may have already set the type for this DIE. */ |
10210 | type = get_die_type (die, cu); | |
10211 | if (type) | |
10212 | return type; | |
10213 | ||
0d5de010 DJ |
10214 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
10215 | type = lookup_methodptr_type (to_type); | |
10216 | else | |
10217 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 10218 | |
f792889a | 10219 | return set_die_type (die, type, cu); |
c906108c SS |
10220 | } |
10221 | ||
10222 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
10223 | the user defined type vector. */ | |
10224 | ||
f792889a | 10225 | static struct type * |
e7c27a73 | 10226 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10227 | { |
e7c27a73 | 10228 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 10229 | struct type *type, *target_type; |
c906108c SS |
10230 | struct attribute *attr; |
10231 | ||
7e314c57 JK |
10232 | target_type = die_type (die, cu); |
10233 | ||
10234 | /* The die_type call above may have already set the type for this DIE. */ | |
10235 | type = get_die_type (die, cu); | |
10236 | if (type) | |
10237 | return type; | |
10238 | ||
10239 | type = lookup_reference_type (target_type); | |
e142c38c | 10240 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
10241 | if (attr) |
10242 | { | |
10243 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
10244 | } | |
10245 | else | |
10246 | { | |
107d2387 | 10247 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 10248 | } |
f792889a | 10249 | return set_die_type (die, type, cu); |
c906108c SS |
10250 | } |
10251 | ||
f792889a | 10252 | static struct type * |
e7c27a73 | 10253 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10254 | { |
f792889a | 10255 | struct type *base_type, *cv_type; |
c906108c | 10256 | |
e7c27a73 | 10257 | base_type = die_type (die, cu); |
7e314c57 JK |
10258 | |
10259 | /* The die_type call above may have already set the type for this DIE. */ | |
10260 | cv_type = get_die_type (die, cu); | |
10261 | if (cv_type) | |
10262 | return cv_type; | |
10263 | ||
2f608a3a KW |
10264 | /* In case the const qualifier is applied to an array type, the element type |
10265 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
10266 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
10267 | { | |
10268 | struct type *el_type, *inner_array; | |
10269 | ||
10270 | base_type = copy_type (base_type); | |
10271 | inner_array = base_type; | |
10272 | ||
10273 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
10274 | { | |
10275 | TYPE_TARGET_TYPE (inner_array) = | |
10276 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
10277 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
10278 | } | |
10279 | ||
10280 | el_type = TYPE_TARGET_TYPE (inner_array); | |
10281 | TYPE_TARGET_TYPE (inner_array) = | |
10282 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
10283 | ||
10284 | return set_die_type (die, base_type, cu); | |
10285 | } | |
10286 | ||
f792889a DJ |
10287 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
10288 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
10289 | } |
10290 | ||
f792889a | 10291 | static struct type * |
e7c27a73 | 10292 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10293 | { |
f792889a | 10294 | struct type *base_type, *cv_type; |
c906108c | 10295 | |
e7c27a73 | 10296 | base_type = die_type (die, cu); |
7e314c57 JK |
10297 | |
10298 | /* The die_type call above may have already set the type for this DIE. */ | |
10299 | cv_type = get_die_type (die, cu); | |
10300 | if (cv_type) | |
10301 | return cv_type; | |
10302 | ||
f792889a DJ |
10303 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
10304 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
10305 | } |
10306 | ||
10307 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
10308 | the user defined type vector. It isn't really a user defined type, | |
10309 | but it behaves like one, with other DIE's using an AT_user_def_type | |
10310 | attribute to reference it. */ | |
10311 | ||
f792889a | 10312 | static struct type * |
e7c27a73 | 10313 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10314 | { |
e7c27a73 | 10315 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 10316 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
10317 | struct type *type, *range_type, *index_type, *char_type; |
10318 | struct attribute *attr; | |
10319 | unsigned int length; | |
10320 | ||
e142c38c | 10321 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
10322 | if (attr) |
10323 | { | |
10324 | length = DW_UNSND (attr); | |
10325 | } | |
10326 | else | |
10327 | { | |
0963b4bd | 10328 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 10329 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
10330 | if (attr) |
10331 | { | |
10332 | length = DW_UNSND (attr); | |
10333 | } | |
10334 | else | |
10335 | { | |
10336 | length = 1; | |
10337 | } | |
c906108c | 10338 | } |
6ccb9162 | 10339 | |
46bf5051 | 10340 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 10341 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
10342 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
10343 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 10344 | |
f792889a | 10345 | return set_die_type (die, type, cu); |
c906108c SS |
10346 | } |
10347 | ||
10348 | /* Handle DIES due to C code like: | |
10349 | ||
10350 | struct foo | |
c5aa993b JM |
10351 | { |
10352 | int (*funcp)(int a, long l); | |
10353 | int b; | |
10354 | }; | |
c906108c | 10355 | |
0963b4bd | 10356 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 10357 | |
f792889a | 10358 | static struct type * |
e7c27a73 | 10359 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10360 | { |
bb5ed363 | 10361 | struct objfile *objfile = cu->objfile; |
0963b4bd MS |
10362 | struct type *type; /* Type that this function returns. */ |
10363 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
10364 | struct attribute *attr; |
10365 | ||
e7c27a73 | 10366 | type = die_type (die, cu); |
7e314c57 JK |
10367 | |
10368 | /* The die_type call above may have already set the type for this DIE. */ | |
10369 | ftype = get_die_type (die, cu); | |
10370 | if (ftype) | |
10371 | return ftype; | |
10372 | ||
0c8b41f1 | 10373 | ftype = lookup_function_type (type); |
c906108c | 10374 | |
5b8101ae | 10375 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 10376 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 10377 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 10378 | || cu->language == language_cplus |
5b8101ae PM |
10379 | || cu->language == language_java |
10380 | || cu->language == language_pascal) | |
876cecd0 | 10381 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
10382 | else if (producer_is_realview (cu->producer)) |
10383 | /* RealView does not emit DW_AT_prototyped. We can not | |
10384 | distinguish prototyped and unprototyped functions; default to | |
10385 | prototyped, since that is more common in modern code (and | |
10386 | RealView warns about unprototyped functions). */ | |
10387 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 10388 | |
c055b101 CV |
10389 | /* Store the calling convention in the type if it's available in |
10390 | the subroutine die. Otherwise set the calling convention to | |
10391 | the default value DW_CC_normal. */ | |
10392 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
10393 | if (attr) |
10394 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
10395 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
10396 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
10397 | else | |
10398 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
10399 | |
10400 | /* We need to add the subroutine type to the die immediately so | |
10401 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 10402 | declared as the same subroutine type. */ |
76c10ea2 | 10403 | set_die_type (die, ftype, cu); |
6e70227d | 10404 | |
639d11d3 | 10405 | if (die->child != NULL) |
c906108c | 10406 | { |
bb5ed363 | 10407 | struct type *void_type = objfile_type (objfile)->builtin_void; |
c906108c | 10408 | struct die_info *child_die; |
8072405b | 10409 | int nparams, iparams; |
c906108c SS |
10410 | |
10411 | /* Count the number of parameters. | |
10412 | FIXME: GDB currently ignores vararg functions, but knows about | |
10413 | vararg member functions. */ | |
8072405b | 10414 | nparams = 0; |
639d11d3 | 10415 | child_die = die->child; |
c906108c SS |
10416 | while (child_die && child_die->tag) |
10417 | { | |
10418 | if (child_die->tag == DW_TAG_formal_parameter) | |
10419 | nparams++; | |
10420 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 10421 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
10422 | child_die = sibling_die (child_die); |
10423 | } | |
10424 | ||
10425 | /* Allocate storage for parameters and fill them in. */ | |
10426 | TYPE_NFIELDS (ftype) = nparams; | |
10427 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 10428 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 10429 | |
8072405b JK |
10430 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
10431 | even if we error out during the parameters reading below. */ | |
10432 | for (iparams = 0; iparams < nparams; iparams++) | |
10433 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
10434 | ||
10435 | iparams = 0; | |
639d11d3 | 10436 | child_die = die->child; |
c906108c SS |
10437 | while (child_die && child_die->tag) |
10438 | { | |
10439 | if (child_die->tag == DW_TAG_formal_parameter) | |
10440 | { | |
3ce3b1ba PA |
10441 | struct type *arg_type; |
10442 | ||
10443 | /* DWARF version 2 has no clean way to discern C++ | |
10444 | static and non-static member functions. G++ helps | |
10445 | GDB by marking the first parameter for non-static | |
10446 | member functions (which is the this pointer) as | |
10447 | artificial. We pass this information to | |
10448 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
10449 | ||
10450 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
10451 | 4.5 does not yet generate. */ | |
e142c38c | 10452 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
10453 | if (attr) |
10454 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
10455 | else | |
418835cc KS |
10456 | { |
10457 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
10458 | ||
10459 | /* GCC/43521: In java, the formal parameter | |
10460 | "this" is sometimes not marked with DW_AT_artificial. */ | |
10461 | if (cu->language == language_java) | |
10462 | { | |
10463 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 10464 | |
418835cc KS |
10465 | if (name && !strcmp (name, "this")) |
10466 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
10467 | } | |
10468 | } | |
3ce3b1ba PA |
10469 | arg_type = die_type (child_die, cu); |
10470 | ||
10471 | /* RealView does not mark THIS as const, which the testsuite | |
10472 | expects. GCC marks THIS as const in method definitions, | |
10473 | but not in the class specifications (GCC PR 43053). */ | |
10474 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
10475 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
10476 | { | |
10477 | int is_this = 0; | |
10478 | struct dwarf2_cu *arg_cu = cu; | |
10479 | const char *name = dwarf2_name (child_die, cu); | |
10480 | ||
10481 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
10482 | if (attr) | |
10483 | { | |
10484 | /* If the compiler emits this, use it. */ | |
10485 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
10486 | is_this = 1; | |
10487 | } | |
10488 | else if (name && strcmp (name, "this") == 0) | |
10489 | /* Function definitions will have the argument names. */ | |
10490 | is_this = 1; | |
10491 | else if (name == NULL && iparams == 0) | |
10492 | /* Declarations may not have the names, so like | |
10493 | elsewhere in GDB, assume an artificial first | |
10494 | argument is "this". */ | |
10495 | is_this = 1; | |
10496 | ||
10497 | if (is_this) | |
10498 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
10499 | arg_type, 0); | |
10500 | } | |
10501 | ||
10502 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
10503 | iparams++; |
10504 | } | |
10505 | child_die = sibling_die (child_die); | |
10506 | } | |
10507 | } | |
10508 | ||
76c10ea2 | 10509 | return ftype; |
c906108c SS |
10510 | } |
10511 | ||
f792889a | 10512 | static struct type * |
e7c27a73 | 10513 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10514 | { |
e7c27a73 | 10515 | struct objfile *objfile = cu->objfile; |
0114d602 | 10516 | const char *name = NULL; |
3c8e0968 | 10517 | struct type *this_type, *target_type; |
c906108c | 10518 | |
94af9270 | 10519 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 10520 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
10521 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
10522 | TYPE_NAME (this_type) = (char *) name; | |
f792889a | 10523 | set_die_type (die, this_type, cu); |
3c8e0968 DE |
10524 | target_type = die_type (die, cu); |
10525 | if (target_type != this_type) | |
10526 | TYPE_TARGET_TYPE (this_type) = target_type; | |
10527 | else | |
10528 | { | |
10529 | /* Self-referential typedefs are, it seems, not allowed by the DWARF | |
10530 | spec and cause infinite loops in GDB. */ | |
10531 | complaint (&symfile_complaints, | |
10532 | _("Self-referential DW_TAG_typedef " | |
10533 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 10534 | die->offset.sect_off, objfile->name); |
3c8e0968 DE |
10535 | TYPE_TARGET_TYPE (this_type) = NULL; |
10536 | } | |
f792889a | 10537 | return this_type; |
c906108c SS |
10538 | } |
10539 | ||
10540 | /* Find a representation of a given base type and install | |
10541 | it in the TYPE field of the die. */ | |
10542 | ||
f792889a | 10543 | static struct type * |
e7c27a73 | 10544 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10545 | { |
e7c27a73 | 10546 | struct objfile *objfile = cu->objfile; |
c906108c SS |
10547 | struct type *type; |
10548 | struct attribute *attr; | |
10549 | int encoding = 0, size = 0; | |
39cbfefa | 10550 | char *name; |
6ccb9162 UW |
10551 | enum type_code code = TYPE_CODE_INT; |
10552 | int type_flags = 0; | |
10553 | struct type *target_type = NULL; | |
c906108c | 10554 | |
e142c38c | 10555 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
10556 | if (attr) |
10557 | { | |
10558 | encoding = DW_UNSND (attr); | |
10559 | } | |
e142c38c | 10560 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
10561 | if (attr) |
10562 | { | |
10563 | size = DW_UNSND (attr); | |
10564 | } | |
39cbfefa | 10565 | name = dwarf2_name (die, cu); |
6ccb9162 | 10566 | if (!name) |
c906108c | 10567 | { |
6ccb9162 UW |
10568 | complaint (&symfile_complaints, |
10569 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 10570 | } |
6ccb9162 UW |
10571 | |
10572 | switch (encoding) | |
c906108c | 10573 | { |
6ccb9162 UW |
10574 | case DW_ATE_address: |
10575 | /* Turn DW_ATE_address into a void * pointer. */ | |
10576 | code = TYPE_CODE_PTR; | |
10577 | type_flags |= TYPE_FLAG_UNSIGNED; | |
10578 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
10579 | break; | |
10580 | case DW_ATE_boolean: | |
10581 | code = TYPE_CODE_BOOL; | |
10582 | type_flags |= TYPE_FLAG_UNSIGNED; | |
10583 | break; | |
10584 | case DW_ATE_complex_float: | |
10585 | code = TYPE_CODE_COMPLEX; | |
10586 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
10587 | break; | |
10588 | case DW_ATE_decimal_float: | |
10589 | code = TYPE_CODE_DECFLOAT; | |
10590 | break; | |
10591 | case DW_ATE_float: | |
10592 | code = TYPE_CODE_FLT; | |
10593 | break; | |
10594 | case DW_ATE_signed: | |
10595 | break; | |
10596 | case DW_ATE_unsigned: | |
10597 | type_flags |= TYPE_FLAG_UNSIGNED; | |
3b2b8fea TT |
10598 | if (cu->language == language_fortran |
10599 | && name | |
10600 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) | |
10601 | code = TYPE_CODE_CHAR; | |
6ccb9162 UW |
10602 | break; |
10603 | case DW_ATE_signed_char: | |
6e70227d | 10604 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
10605 | || cu->language == language_pascal |
10606 | || cu->language == language_fortran) | |
6ccb9162 UW |
10607 | code = TYPE_CODE_CHAR; |
10608 | break; | |
10609 | case DW_ATE_unsigned_char: | |
868a0084 | 10610 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
10611 | || cu->language == language_pascal |
10612 | || cu->language == language_fortran) | |
6ccb9162 UW |
10613 | code = TYPE_CODE_CHAR; |
10614 | type_flags |= TYPE_FLAG_UNSIGNED; | |
10615 | break; | |
75079b2b TT |
10616 | case DW_ATE_UTF: |
10617 | /* We just treat this as an integer and then recognize the | |
10618 | type by name elsewhere. */ | |
10619 | break; | |
10620 | ||
6ccb9162 UW |
10621 | default: |
10622 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
10623 | dwarf_type_encoding_name (encoding)); | |
10624 | break; | |
c906108c | 10625 | } |
6ccb9162 | 10626 | |
0114d602 DJ |
10627 | type = init_type (code, size, type_flags, NULL, objfile); |
10628 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
10629 | TYPE_TARGET_TYPE (type) = target_type; |
10630 | ||
0114d602 | 10631 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 10632 | TYPE_NOSIGN (type) = 1; |
0114d602 | 10633 | |
f792889a | 10634 | return set_die_type (die, type, cu); |
c906108c SS |
10635 | } |
10636 | ||
a02abb62 JB |
10637 | /* Read the given DW_AT_subrange DIE. */ |
10638 | ||
f792889a | 10639 | static struct type * |
a02abb62 JB |
10640 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
10641 | { | |
10642 | struct type *base_type; | |
10643 | struct type *range_type; | |
10644 | struct attribute *attr; | |
4fae6e18 JK |
10645 | LONGEST low, high; |
10646 | int low_default_is_valid; | |
39cbfefa | 10647 | char *name; |
43bbcdc2 | 10648 | LONGEST negative_mask; |
e77813c8 | 10649 | |
a02abb62 | 10650 | base_type = die_type (die, cu); |
953ac07e JK |
10651 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
10652 | check_typedef (base_type); | |
a02abb62 | 10653 | |
7e314c57 JK |
10654 | /* The die_type call above may have already set the type for this DIE. */ |
10655 | range_type = get_die_type (die, cu); | |
10656 | if (range_type) | |
10657 | return range_type; | |
10658 | ||
4fae6e18 JK |
10659 | /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow |
10660 | omitting DW_AT_lower_bound. */ | |
10661 | switch (cu->language) | |
6e70227d | 10662 | { |
4fae6e18 JK |
10663 | case language_c: |
10664 | case language_cplus: | |
10665 | low = 0; | |
10666 | low_default_is_valid = 1; | |
10667 | break; | |
10668 | case language_fortran: | |
10669 | low = 1; | |
10670 | low_default_is_valid = 1; | |
10671 | break; | |
10672 | case language_d: | |
10673 | case language_java: | |
10674 | case language_objc: | |
10675 | low = 0; | |
10676 | low_default_is_valid = (cu->header.version >= 4); | |
10677 | break; | |
10678 | case language_ada: | |
10679 | case language_m2: | |
10680 | case language_pascal: | |
a02abb62 | 10681 | low = 1; |
4fae6e18 JK |
10682 | low_default_is_valid = (cu->header.version >= 4); |
10683 | break; | |
10684 | default: | |
10685 | low = 0; | |
10686 | low_default_is_valid = 0; | |
10687 | break; | |
a02abb62 JB |
10688 | } |
10689 | ||
dd5e6932 DJ |
10690 | /* FIXME: For variable sized arrays either of these could be |
10691 | a variable rather than a constant value. We'll allow it, | |
10692 | but we don't know how to handle it. */ | |
e142c38c | 10693 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 | 10694 | if (attr) |
4fae6e18 JK |
10695 | low = dwarf2_get_attr_constant_value (attr, low); |
10696 | else if (!low_default_is_valid) | |
10697 | complaint (&symfile_complaints, _("Missing DW_AT_lower_bound " | |
10698 | "- DIE at 0x%x [in module %s]"), | |
10699 | die->offset.sect_off, cu->objfile->name); | |
a02abb62 | 10700 | |
e142c38c | 10701 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 10702 | if (attr) |
6e70227d | 10703 | { |
d48323d8 | 10704 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
a02abb62 JB |
10705 | { |
10706 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 10707 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
10708 | FIXME: GDB does not yet know how to handle dynamic |
10709 | arrays properly, treat them as arrays with unspecified | |
10710 | length for now. | |
10711 | ||
10712 | FIXME: jimb/2003-09-22: GDB does not really know | |
10713 | how to handle arrays of unspecified length | |
10714 | either; we just represent them as zero-length | |
10715 | arrays. Choose an appropriate upper bound given | |
10716 | the lower bound we've computed above. */ | |
10717 | high = low - 1; | |
10718 | } | |
10719 | else | |
10720 | high = dwarf2_get_attr_constant_value (attr, 1); | |
10721 | } | |
e77813c8 PM |
10722 | else |
10723 | { | |
10724 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
10725 | if (attr) | |
10726 | { | |
10727 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
10728 | high = low + count - 1; | |
10729 | } | |
c2ff108b JK |
10730 | else |
10731 | { | |
10732 | /* Unspecified array length. */ | |
10733 | high = low - 1; | |
10734 | } | |
e77813c8 PM |
10735 | } |
10736 | ||
10737 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
10738 | without specifying a base type. | |
10739 | In that case, the base type must be set to the type of | |
10740 | the lower bound, upper bound or count, in that order, if any of these | |
10741 | three attributes references an object that has a type. | |
10742 | If no base type is found, the Dwarf-2 specifications say that | |
10743 | a signed integer type of size equal to the size of an address should | |
10744 | be used. | |
10745 | For the following C code: `extern char gdb_int [];' | |
10746 | GCC produces an empty range DIE. | |
10747 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 10748 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
10749 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
10750 | { | |
10751 | struct objfile *objfile = cu->objfile; | |
10752 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
10753 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
10754 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
10755 | ||
10756 | /* Test "int", "long int", and "long long int" objfile types, | |
10757 | and select the first one having a size above or equal to the | |
10758 | architecture address size. */ | |
10759 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
10760 | base_type = int_type; | |
10761 | else | |
10762 | { | |
10763 | int_type = objfile_type (objfile)->builtin_long; | |
10764 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
10765 | base_type = int_type; | |
10766 | else | |
10767 | { | |
10768 | int_type = objfile_type (objfile)->builtin_long_long; | |
10769 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
10770 | base_type = int_type; | |
10771 | } | |
10772 | } | |
10773 | } | |
a02abb62 | 10774 | |
6e70227d | 10775 | negative_mask = |
43bbcdc2 PH |
10776 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
10777 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
10778 | low |= negative_mask; | |
10779 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
10780 | high |= negative_mask; | |
10781 | ||
a02abb62 JB |
10782 | range_type = create_range_type (NULL, base_type, low, high); |
10783 | ||
bbb0eef6 JK |
10784 | /* Mark arrays with dynamic length at least as an array of unspecified |
10785 | length. GDB could check the boundary but before it gets implemented at | |
10786 | least allow accessing the array elements. */ | |
d48323d8 | 10787 | if (attr && attr_form_is_block (attr)) |
bbb0eef6 JK |
10788 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
10789 | ||
c2ff108b JK |
10790 | /* Ada expects an empty array on no boundary attributes. */ |
10791 | if (attr == NULL && cu->language != language_ada) | |
10792 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
10793 | ||
39cbfefa DJ |
10794 | name = dwarf2_name (die, cu); |
10795 | if (name) | |
10796 | TYPE_NAME (range_type) = name; | |
6e70227d | 10797 | |
e142c38c | 10798 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
10799 | if (attr) |
10800 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
10801 | ||
7e314c57 JK |
10802 | set_die_type (die, range_type, cu); |
10803 | ||
10804 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
10805 | set_descriptive_type (range_type, die, cu); |
10806 | ||
7e314c57 | 10807 | return range_type; |
a02abb62 | 10808 | } |
6e70227d | 10809 | |
f792889a | 10810 | static struct type * |
81a17f79 JB |
10811 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
10812 | { | |
10813 | struct type *type; | |
81a17f79 | 10814 | |
81a17f79 JB |
10815 | /* For now, we only support the C meaning of an unspecified type: void. */ |
10816 | ||
0114d602 DJ |
10817 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
10818 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 10819 | |
f792889a | 10820 | return set_die_type (die, type, cu); |
81a17f79 | 10821 | } |
a02abb62 | 10822 | |
639d11d3 DC |
10823 | /* Read a single die and all its descendents. Set the die's sibling |
10824 | field to NULL; set other fields in the die correctly, and set all | |
10825 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
10826 | location of the info_ptr after reading all of those dies. PARENT | |
10827 | is the parent of the die in question. */ | |
10828 | ||
10829 | static struct die_info * | |
dee91e82 DE |
10830 | read_die_and_children (const struct die_reader_specs *reader, |
10831 | gdb_byte *info_ptr, | |
10832 | gdb_byte **new_info_ptr, | |
10833 | struct die_info *parent) | |
639d11d3 DC |
10834 | { |
10835 | struct die_info *die; | |
fe1b8b76 | 10836 | gdb_byte *cur_ptr; |
639d11d3 DC |
10837 | int has_children; |
10838 | ||
93311388 | 10839 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
10840 | if (die == NULL) |
10841 | { | |
10842 | *new_info_ptr = cur_ptr; | |
10843 | return NULL; | |
10844 | } | |
93311388 | 10845 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
10846 | |
10847 | if (has_children) | |
348e048f | 10848 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
10849 | else |
10850 | { | |
10851 | die->child = NULL; | |
10852 | *new_info_ptr = cur_ptr; | |
10853 | } | |
10854 | ||
10855 | die->sibling = NULL; | |
10856 | die->parent = parent; | |
10857 | return die; | |
10858 | } | |
10859 | ||
10860 | /* Read a die, all of its descendents, and all of its siblings; set | |
10861 | all of the fields of all of the dies correctly. Arguments are as | |
10862 | in read_die_and_children. */ | |
10863 | ||
10864 | static struct die_info * | |
93311388 DE |
10865 | read_die_and_siblings (const struct die_reader_specs *reader, |
10866 | gdb_byte *info_ptr, | |
fe1b8b76 | 10867 | gdb_byte **new_info_ptr, |
639d11d3 DC |
10868 | struct die_info *parent) |
10869 | { | |
10870 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 10871 | gdb_byte *cur_ptr; |
639d11d3 | 10872 | |
c906108c | 10873 | cur_ptr = info_ptr; |
639d11d3 DC |
10874 | first_die = last_sibling = NULL; |
10875 | ||
10876 | while (1) | |
c906108c | 10877 | { |
639d11d3 | 10878 | struct die_info *die |
dee91e82 | 10879 | = read_die_and_children (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 10880 | |
1d325ec1 | 10881 | if (die == NULL) |
c906108c | 10882 | { |
639d11d3 DC |
10883 | *new_info_ptr = cur_ptr; |
10884 | return first_die; | |
c906108c | 10885 | } |
1d325ec1 DJ |
10886 | |
10887 | if (!first_die) | |
10888 | first_die = die; | |
c906108c | 10889 | else |
1d325ec1 DJ |
10890 | last_sibling->sibling = die; |
10891 | ||
10892 | last_sibling = die; | |
c906108c | 10893 | } |
c906108c SS |
10894 | } |
10895 | ||
3019eac3 DE |
10896 | /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS |
10897 | attributes. | |
10898 | The caller is responsible for filling in the extra attributes | |
10899 | and updating (*DIEP)->num_attrs. | |
10900 | Set DIEP to point to a newly allocated die with its information, | |
10901 | except for its child, sibling, and parent fields. | |
10902 | Set HAS_CHILDREN to tell whether the die has children or not. */ | |
93311388 DE |
10903 | |
10904 | static gdb_byte * | |
3019eac3 DE |
10905 | read_full_die_1 (const struct die_reader_specs *reader, |
10906 | struct die_info **diep, gdb_byte *info_ptr, | |
10907 | int *has_children, int num_extra_attrs) | |
93311388 | 10908 | { |
b64f50a1 JK |
10909 | unsigned int abbrev_number, bytes_read, i; |
10910 | sect_offset offset; | |
93311388 DE |
10911 | struct abbrev_info *abbrev; |
10912 | struct die_info *die; | |
10913 | struct dwarf2_cu *cu = reader->cu; | |
10914 | bfd *abfd = reader->abfd; | |
10915 | ||
b64f50a1 | 10916 | offset.sect_off = info_ptr - reader->buffer; |
93311388 DE |
10917 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10918 | info_ptr += bytes_read; | |
10919 | if (!abbrev_number) | |
10920 | { | |
10921 | *diep = NULL; | |
10922 | *has_children = 0; | |
10923 | return info_ptr; | |
10924 | } | |
10925 | ||
10926 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
10927 | if (!abbrev) | |
348e048f DE |
10928 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
10929 | abbrev_number, | |
10930 | bfd_get_filename (abfd)); | |
10931 | ||
3019eac3 | 10932 | die = dwarf_alloc_die (cu, abbrev->num_attrs + num_extra_attrs); |
93311388 DE |
10933 | die->offset = offset; |
10934 | die->tag = abbrev->tag; | |
10935 | die->abbrev = abbrev_number; | |
10936 | ||
3019eac3 DE |
10937 | /* Make the result usable. |
10938 | The caller needs to update num_attrs after adding the extra | |
10939 | attributes. */ | |
93311388 DE |
10940 | die->num_attrs = abbrev->num_attrs; |
10941 | ||
10942 | for (i = 0; i < abbrev->num_attrs; ++i) | |
dee91e82 DE |
10943 | info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i], |
10944 | info_ptr); | |
93311388 DE |
10945 | |
10946 | *diep = die; | |
10947 | *has_children = abbrev->has_children; | |
10948 | return info_ptr; | |
10949 | } | |
10950 | ||
3019eac3 DE |
10951 | /* Read a die and all its attributes. |
10952 | Set DIEP to point to a newly allocated die with its information, | |
10953 | except for its child, sibling, and parent fields. | |
10954 | Set HAS_CHILDREN to tell whether the die has children or not. */ | |
10955 | ||
10956 | static gdb_byte * | |
10957 | read_full_die (const struct die_reader_specs *reader, | |
10958 | struct die_info **diep, gdb_byte *info_ptr, | |
10959 | int *has_children) | |
10960 | { | |
10961 | return read_full_die_1 (reader, diep, info_ptr, has_children, 0); | |
10962 | } | |
10963 | ||
c906108c SS |
10964 | /* In DWARF version 2, the description of the debugging information is |
10965 | stored in a separate .debug_abbrev section. Before we read any | |
10966 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
10967 | in a hash table. This function also sets flags in CU describing |
10968 | the data found in the abbrev table. */ | |
c906108c SS |
10969 | |
10970 | static void | |
dee91e82 DE |
10971 | dwarf2_read_abbrevs (struct dwarf2_cu *cu, |
10972 | struct dwarf2_section_info *abbrev_section) | |
10973 | ||
c906108c | 10974 | { |
dee91e82 | 10975 | bfd *abfd = abbrev_section->asection->owner; |
e7c27a73 | 10976 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 10977 | gdb_byte *abbrev_ptr; |
c906108c SS |
10978 | struct abbrev_info *cur_abbrev; |
10979 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
10980 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
10981 | struct attr_abbrev *cur_attrs; |
10982 | unsigned int allocated_attrs; | |
c906108c | 10983 | |
0963b4bd | 10984 | /* Initialize dwarf2 abbrevs. */ |
f3dd6933 DJ |
10985 | obstack_init (&cu->abbrev_obstack); |
10986 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
10987 | (ABBREV_HASH_SIZE | |
10988 | * sizeof (struct abbrev_info *))); | |
10989 | memset (cu->dwarf2_abbrevs, 0, | |
10990 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 10991 | |
dee91e82 DE |
10992 | dwarf2_read_section (cu->objfile, abbrev_section); |
10993 | abbrev_ptr = abbrev_section->buffer + cu_header->abbrev_offset.sect_off; | |
c906108c SS |
10994 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
10995 | abbrev_ptr += bytes_read; | |
10996 | ||
f3dd6933 DJ |
10997 | allocated_attrs = ATTR_ALLOC_CHUNK; |
10998 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 10999 | |
0963b4bd | 11000 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
11001 | while (abbrev_number) |
11002 | { | |
f3dd6933 | 11003 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
11004 | |
11005 | /* read in abbrev header */ | |
11006 | cur_abbrev->number = abbrev_number; | |
11007 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
11008 | abbrev_ptr += bytes_read; | |
11009 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
11010 | abbrev_ptr += 1; | |
11011 | ||
11012 | /* now read in declarations */ | |
11013 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
11014 | abbrev_ptr += bytes_read; | |
11015 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
11016 | abbrev_ptr += bytes_read; | |
11017 | while (abbrev_name) | |
11018 | { | |
f3dd6933 | 11019 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 11020 | { |
f3dd6933 DJ |
11021 | allocated_attrs += ATTR_ALLOC_CHUNK; |
11022 | cur_attrs | |
11023 | = xrealloc (cur_attrs, (allocated_attrs | |
11024 | * sizeof (struct attr_abbrev))); | |
c906108c | 11025 | } |
ae038cb0 | 11026 | |
f3dd6933 DJ |
11027 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
11028 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
11029 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
11030 | abbrev_ptr += bytes_read; | |
11031 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
11032 | abbrev_ptr += bytes_read; | |
11033 | } | |
11034 | ||
f3dd6933 DJ |
11035 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
11036 | (cur_abbrev->num_attrs | |
11037 | * sizeof (struct attr_abbrev))); | |
11038 | memcpy (cur_abbrev->attrs, cur_attrs, | |
11039 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
11040 | ||
c906108c | 11041 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
11042 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
11043 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
11044 | |
11045 | /* Get next abbreviation. | |
11046 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
11047 | always properly terminated with an abbrev number of 0. |
11048 | Exit loop if we encounter an abbreviation which we have | |
11049 | already read (which means we are about to read the abbreviations | |
11050 | for the next compile unit) or if the end of the abbreviation | |
11051 | table is reached. */ | |
dee91e82 DE |
11052 | if ((unsigned int) (abbrev_ptr - abbrev_section->buffer) |
11053 | >= abbrev_section->size) | |
c906108c SS |
11054 | break; |
11055 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
11056 | abbrev_ptr += bytes_read; | |
e7c27a73 | 11057 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
11058 | break; |
11059 | } | |
f3dd6933 DJ |
11060 | |
11061 | xfree (cur_attrs); | |
c906108c SS |
11062 | } |
11063 | ||
f3dd6933 | 11064 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 11065 | |
c906108c | 11066 | static void |
f3dd6933 | 11067 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 11068 | { |
f3dd6933 | 11069 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 11070 | |
f3dd6933 DJ |
11071 | obstack_free (&cu->abbrev_obstack, NULL); |
11072 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
11073 | } |
11074 | ||
11075 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
11076 | ||
11077 | static struct abbrev_info * | |
e7c27a73 | 11078 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
11079 | { |
11080 | unsigned int hash_number; | |
11081 | struct abbrev_info *abbrev; | |
11082 | ||
11083 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 11084 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
11085 | |
11086 | while (abbrev) | |
11087 | { | |
11088 | if (abbrev->number == number) | |
11089 | return abbrev; | |
11090 | else | |
11091 | abbrev = abbrev->next; | |
11092 | } | |
11093 | return NULL; | |
11094 | } | |
11095 | ||
72bf9492 DJ |
11096 | /* Returns nonzero if TAG represents a type that we might generate a partial |
11097 | symbol for. */ | |
11098 | ||
11099 | static int | |
11100 | is_type_tag_for_partial (int tag) | |
11101 | { | |
11102 | switch (tag) | |
11103 | { | |
11104 | #if 0 | |
11105 | /* Some types that would be reasonable to generate partial symbols for, | |
11106 | that we don't at present. */ | |
11107 | case DW_TAG_array_type: | |
11108 | case DW_TAG_file_type: | |
11109 | case DW_TAG_ptr_to_member_type: | |
11110 | case DW_TAG_set_type: | |
11111 | case DW_TAG_string_type: | |
11112 | case DW_TAG_subroutine_type: | |
11113 | #endif | |
11114 | case DW_TAG_base_type: | |
11115 | case DW_TAG_class_type: | |
680b30c7 | 11116 | case DW_TAG_interface_type: |
72bf9492 DJ |
11117 | case DW_TAG_enumeration_type: |
11118 | case DW_TAG_structure_type: | |
11119 | case DW_TAG_subrange_type: | |
11120 | case DW_TAG_typedef: | |
11121 | case DW_TAG_union_type: | |
11122 | return 1; | |
11123 | default: | |
11124 | return 0; | |
11125 | } | |
11126 | } | |
11127 | ||
11128 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
11129 | ||
11130 | static struct partial_die_info * | |
dee91e82 DE |
11131 | load_partial_dies (const struct die_reader_specs *reader, |
11132 | gdb_byte *info_ptr, int building_psymtab) | |
72bf9492 | 11133 | { |
dee91e82 | 11134 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 11135 | struct objfile *objfile = cu->objfile; |
72bf9492 DJ |
11136 | struct partial_die_info *part_die; |
11137 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
11138 | struct abbrev_info *abbrev; | |
11139 | unsigned int bytes_read; | |
5afb4e99 | 11140 | unsigned int load_all = 0; |
72bf9492 DJ |
11141 | int nesting_level = 1; |
11142 | ||
11143 | parent_die = NULL; | |
11144 | last_die = NULL; | |
11145 | ||
7adf1e79 DE |
11146 | gdb_assert (cu->per_cu != NULL); |
11147 | if (cu->per_cu->load_all_dies) | |
5afb4e99 DJ |
11148 | load_all = 1; |
11149 | ||
72bf9492 DJ |
11150 | cu->partial_dies |
11151 | = htab_create_alloc_ex (cu->header.length / 12, | |
11152 | partial_die_hash, | |
11153 | partial_die_eq, | |
11154 | NULL, | |
11155 | &cu->comp_unit_obstack, | |
11156 | hashtab_obstack_allocate, | |
11157 | dummy_obstack_deallocate); | |
11158 | ||
11159 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
11160 | sizeof (struct partial_die_info)); | |
11161 | ||
11162 | while (1) | |
11163 | { | |
11164 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
11165 | ||
11166 | /* A NULL abbrev means the end of a series of children. */ | |
11167 | if (abbrev == NULL) | |
11168 | { | |
11169 | if (--nesting_level == 0) | |
11170 | { | |
11171 | /* PART_DIE was probably the last thing allocated on the | |
11172 | comp_unit_obstack, so we could call obstack_free | |
11173 | here. We don't do that because the waste is small, | |
11174 | and will be cleaned up when we're done with this | |
11175 | compilation unit. This way, we're also more robust | |
11176 | against other users of the comp_unit_obstack. */ | |
11177 | return first_die; | |
11178 | } | |
11179 | info_ptr += bytes_read; | |
11180 | last_die = parent_die; | |
11181 | parent_die = parent_die->die_parent; | |
11182 | continue; | |
11183 | } | |
11184 | ||
98bfdba5 PA |
11185 | /* Check for template arguments. We never save these; if |
11186 | they're seen, we just mark the parent, and go on our way. */ | |
11187 | if (parent_die != NULL | |
11188 | && cu->language == language_cplus | |
11189 | && (abbrev->tag == DW_TAG_template_type_param | |
11190 | || abbrev->tag == DW_TAG_template_value_param)) | |
11191 | { | |
11192 | parent_die->has_template_arguments = 1; | |
11193 | ||
11194 | if (!load_all) | |
11195 | { | |
11196 | /* We don't need a partial DIE for the template argument. */ | |
dee91e82 | 11197 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
11198 | continue; |
11199 | } | |
11200 | } | |
11201 | ||
0d99eb77 | 11202 | /* We only recurse into c++ subprograms looking for template arguments. |
98bfdba5 PA |
11203 | Skip their other children. */ |
11204 | if (!load_all | |
11205 | && cu->language == language_cplus | |
11206 | && parent_die != NULL | |
11207 | && parent_die->tag == DW_TAG_subprogram) | |
11208 | { | |
dee91e82 | 11209 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
11210 | continue; |
11211 | } | |
11212 | ||
5afb4e99 DJ |
11213 | /* Check whether this DIE is interesting enough to save. Normally |
11214 | we would not be interested in members here, but there may be | |
11215 | later variables referencing them via DW_AT_specification (for | |
11216 | static members). */ | |
11217 | if (!load_all | |
11218 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 11219 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
11220 | && abbrev->tag != DW_TAG_enumerator |
11221 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 11222 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 11223 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 11224 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 11225 | && abbrev->tag != DW_TAG_module |
95554aad TT |
11226 | && abbrev->tag != DW_TAG_member |
11227 | && abbrev->tag != DW_TAG_imported_unit) | |
72bf9492 DJ |
11228 | { |
11229 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 11230 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
72bf9492 DJ |
11231 | continue; |
11232 | } | |
11233 | ||
dee91e82 DE |
11234 | info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read, |
11235 | info_ptr); | |
72bf9492 DJ |
11236 | |
11237 | /* This two-pass algorithm for processing partial symbols has a | |
11238 | high cost in cache pressure. Thus, handle some simple cases | |
11239 | here which cover the majority of C partial symbols. DIEs | |
11240 | which neither have specification tags in them, nor could have | |
11241 | specification tags elsewhere pointing at them, can simply be | |
11242 | processed and discarded. | |
11243 | ||
11244 | This segment is also optional; scan_partial_symbols and | |
11245 | add_partial_symbol will handle these DIEs if we chain | |
11246 | them in normally. When compilers which do not emit large | |
11247 | quantities of duplicate debug information are more common, | |
11248 | this code can probably be removed. */ | |
11249 | ||
11250 | /* Any complete simple types at the top level (pretty much all | |
11251 | of them, for a language without namespaces), can be processed | |
11252 | directly. */ | |
11253 | if (parent_die == NULL | |
11254 | && part_die->has_specification == 0 | |
11255 | && part_die->is_declaration == 0 | |
d8228535 | 11256 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
11257 | || part_die->tag == DW_TAG_base_type |
11258 | || part_die->tag == DW_TAG_subrange_type)) | |
11259 | { | |
11260 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 11261 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 11262 | VAR_DOMAIN, LOC_TYPEDEF, |
bb5ed363 DE |
11263 | &objfile->static_psymbols, |
11264 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
dee91e82 | 11265 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
11266 | continue; |
11267 | } | |
11268 | ||
d8228535 JK |
11269 | /* The exception for DW_TAG_typedef with has_children above is |
11270 | a workaround of GCC PR debug/47510. In the case of this complaint | |
11271 | type_name_no_tag_or_error will error on such types later. | |
11272 | ||
11273 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
11274 | it could not find the child DIEs referenced later, this is checked | |
11275 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
11276 | ||
11277 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
11278 | complaint (&symfile_complaints, | |
11279 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
11280 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 11281 | part_die->offset.sect_off, objfile->name); |
d8228535 | 11282 | |
72bf9492 DJ |
11283 | /* If we're at the second level, and we're an enumerator, and |
11284 | our parent has no specification (meaning possibly lives in a | |
11285 | namespace elsewhere), then we can add the partial symbol now | |
11286 | instead of queueing it. */ | |
11287 | if (part_die->tag == DW_TAG_enumerator | |
11288 | && parent_die != NULL | |
11289 | && parent_die->die_parent == NULL | |
11290 | && parent_die->tag == DW_TAG_enumeration_type | |
11291 | && parent_die->has_specification == 0) | |
11292 | { | |
11293 | if (part_die->name == NULL) | |
3e43a32a MS |
11294 | complaint (&symfile_complaints, |
11295 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 11296 | else if (building_psymtab) |
04a679b8 | 11297 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 11298 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
11299 | (cu->language == language_cplus |
11300 | || cu->language == language_java) | |
bb5ed363 DE |
11301 | ? &objfile->global_psymbols |
11302 | : &objfile->static_psymbols, | |
11303 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
72bf9492 | 11304 | |
dee91e82 | 11305 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
11306 | continue; |
11307 | } | |
11308 | ||
11309 | /* We'll save this DIE so link it in. */ | |
11310 | part_die->die_parent = parent_die; | |
11311 | part_die->die_sibling = NULL; | |
11312 | part_die->die_child = NULL; | |
11313 | ||
11314 | if (last_die && last_die == parent_die) | |
11315 | last_die->die_child = part_die; | |
11316 | else if (last_die) | |
11317 | last_die->die_sibling = part_die; | |
11318 | ||
11319 | last_die = part_die; | |
11320 | ||
11321 | if (first_die == NULL) | |
11322 | first_die = part_die; | |
11323 | ||
11324 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
11325 | find interesting need to be in the hash table, because we | |
11326 | also have the parent/sibling/child chains; only those that we | |
11327 | might refer to by offset later during partial symbol reading. | |
11328 | ||
11329 | For now this means things that might have be the target of a | |
11330 | DW_AT_specification, DW_AT_abstract_origin, or | |
11331 | DW_AT_extension. DW_AT_extension will refer only to | |
11332 | namespaces; DW_AT_abstract_origin refers to functions (and | |
11333 | many things under the function DIE, but we do not recurse | |
11334 | into function DIEs during partial symbol reading) and | |
11335 | possibly variables as well; DW_AT_specification refers to | |
11336 | declarations. Declarations ought to have the DW_AT_declaration | |
11337 | flag. It happens that GCC forgets to put it in sometimes, but | |
11338 | only for functions, not for types. | |
11339 | ||
11340 | Adding more things than necessary to the hash table is harmless | |
11341 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
11342 | wasted time in find_partial_die, when we reread the compilation |
11343 | unit with load_all_dies set. */ | |
72bf9492 | 11344 | |
5afb4e99 | 11345 | if (load_all |
72929c62 | 11346 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 11347 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
11348 | || abbrev->tag == DW_TAG_variable |
11349 | || abbrev->tag == DW_TAG_namespace | |
11350 | || part_die->is_declaration) | |
11351 | { | |
11352 | void **slot; | |
11353 | ||
11354 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
b64f50a1 | 11355 | part_die->offset.sect_off, INSERT); |
72bf9492 DJ |
11356 | *slot = part_die; |
11357 | } | |
11358 | ||
11359 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
11360 | sizeof (struct partial_die_info)); | |
11361 | ||
11362 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 11363 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
11364 | languages we have to, so that we can get at method physnames |
11365 | to infer fully qualified class names, for DW_AT_specification, | |
11366 | and for C++ template arguments. For C++, we also look one level | |
11367 | inside functions to find template arguments (if the name of the | |
11368 | function does not already contain the template arguments). | |
bc30ff58 JB |
11369 | |
11370 | For Ada, we need to scan the children of subprograms and lexical | |
11371 | blocks as well because Ada allows the definition of nested | |
11372 | entities that could be interesting for the debugger, such as | |
11373 | nested subprograms for instance. */ | |
72bf9492 | 11374 | if (last_die->has_children |
5afb4e99 DJ |
11375 | && (load_all |
11376 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 11377 | || last_die->tag == DW_TAG_module |
72bf9492 | 11378 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
11379 | || (cu->language == language_cplus |
11380 | && last_die->tag == DW_TAG_subprogram | |
11381 | && (last_die->name == NULL | |
11382 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
11383 | || (cu->language != language_c |
11384 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 11385 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 11386 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
11387 | || last_die->tag == DW_TAG_union_type)) |
11388 | || (cu->language == language_ada | |
11389 | && (last_die->tag == DW_TAG_subprogram | |
11390 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
11391 | { |
11392 | nesting_level++; | |
11393 | parent_die = last_die; | |
11394 | continue; | |
11395 | } | |
11396 | ||
11397 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 11398 | info_ptr = locate_pdi_sibling (reader, last_die, info_ptr); |
72bf9492 DJ |
11399 | |
11400 | /* Back to the top, do it again. */ | |
11401 | } | |
11402 | } | |
11403 | ||
c906108c SS |
11404 | /* Read a minimal amount of information into the minimal die structure. */ |
11405 | ||
fe1b8b76 | 11406 | static gdb_byte * |
dee91e82 DE |
11407 | read_partial_die (const struct die_reader_specs *reader, |
11408 | struct partial_die_info *part_die, | |
11409 | struct abbrev_info *abbrev, unsigned int abbrev_len, | |
11410 | gdb_byte *info_ptr) | |
c906108c | 11411 | { |
dee91e82 | 11412 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 11413 | struct objfile *objfile = cu->objfile; |
dee91e82 | 11414 | gdb_byte *buffer = reader->buffer; |
fa238c03 | 11415 | unsigned int i; |
c906108c | 11416 | struct attribute attr; |
c5aa993b | 11417 | int has_low_pc_attr = 0; |
c906108c | 11418 | int has_high_pc_attr = 0; |
91da1414 | 11419 | int high_pc_relative = 0; |
c906108c | 11420 | |
72bf9492 | 11421 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 11422 | |
b64f50a1 | 11423 | part_die->offset.sect_off = info_ptr - buffer; |
72bf9492 DJ |
11424 | |
11425 | info_ptr += abbrev_len; | |
11426 | ||
11427 | if (abbrev == NULL) | |
11428 | return info_ptr; | |
11429 | ||
c906108c SS |
11430 | part_die->tag = abbrev->tag; |
11431 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
11432 | |
11433 | for (i = 0; i < abbrev->num_attrs; ++i) | |
11434 | { | |
dee91e82 | 11435 | info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
c906108c SS |
11436 | |
11437 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 11438 | partial symbol table. */ |
c906108c SS |
11439 | switch (attr.name) |
11440 | { | |
11441 | case DW_AT_name: | |
71c25dea TT |
11442 | switch (part_die->tag) |
11443 | { | |
11444 | case DW_TAG_compile_unit: | |
95554aad | 11445 | case DW_TAG_partial_unit: |
348e048f | 11446 | case DW_TAG_type_unit: |
71c25dea TT |
11447 | /* Compilation units have a DW_AT_name that is a filename, not |
11448 | a source language identifier. */ | |
11449 | case DW_TAG_enumeration_type: | |
11450 | case DW_TAG_enumerator: | |
11451 | /* These tags always have simple identifiers already; no need | |
11452 | to canonicalize them. */ | |
11453 | part_die->name = DW_STRING (&attr); | |
11454 | break; | |
11455 | default: | |
11456 | part_die->name | |
11457 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
bb5ed363 | 11458 | &objfile->objfile_obstack); |
71c25dea TT |
11459 | break; |
11460 | } | |
c906108c | 11461 | break; |
31ef98ae | 11462 | case DW_AT_linkage_name: |
c906108c | 11463 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
11464 | /* Note that both forms of linkage name might appear. We |
11465 | assume they will be the same, and we only store the last | |
11466 | one we see. */ | |
94af9270 KS |
11467 | if (cu->language == language_ada) |
11468 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 11469 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
11470 | break; |
11471 | case DW_AT_low_pc: | |
11472 | has_low_pc_attr = 1; | |
11473 | part_die->lowpc = DW_ADDR (&attr); | |
11474 | break; | |
11475 | case DW_AT_high_pc: | |
11476 | has_high_pc_attr = 1; | |
3019eac3 DE |
11477 | if (attr.form == DW_FORM_addr |
11478 | || attr.form == DW_FORM_GNU_addr_index) | |
91da1414 MW |
11479 | part_die->highpc = DW_ADDR (&attr); |
11480 | else | |
11481 | { | |
11482 | high_pc_relative = 1; | |
11483 | part_die->highpc = DW_UNSND (&attr); | |
11484 | } | |
c906108c SS |
11485 | break; |
11486 | case DW_AT_location: | |
0963b4bd | 11487 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
11488 | if (attr_form_is_block (&attr)) |
11489 | { | |
95554aad | 11490 | part_die->d.locdesc = DW_BLOCK (&attr); |
8e19ed76 | 11491 | } |
3690dd37 | 11492 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 11493 | { |
4d3c2250 | 11494 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
11495 | } |
11496 | else | |
11497 | { | |
4d3c2250 KB |
11498 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
11499 | "partial symbol information"); | |
8e19ed76 | 11500 | } |
c906108c | 11501 | break; |
c906108c SS |
11502 | case DW_AT_external: |
11503 | part_die->is_external = DW_UNSND (&attr); | |
11504 | break; | |
11505 | case DW_AT_declaration: | |
11506 | part_die->is_declaration = DW_UNSND (&attr); | |
11507 | break; | |
11508 | case DW_AT_type: | |
11509 | part_die->has_type = 1; | |
11510 | break; | |
11511 | case DW_AT_abstract_origin: | |
11512 | case DW_AT_specification: | |
72bf9492 DJ |
11513 | case DW_AT_extension: |
11514 | part_die->has_specification = 1; | |
c764a876 | 11515 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
11516 | break; |
11517 | case DW_AT_sibling: | |
11518 | /* Ignore absolute siblings, they might point outside of | |
11519 | the current compile unit. */ | |
11520 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
11521 | complaint (&symfile_complaints, |
11522 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 11523 | else |
b64f50a1 | 11524 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
c906108c | 11525 | break; |
fa4028e9 JB |
11526 | case DW_AT_byte_size: |
11527 | part_die->has_byte_size = 1; | |
11528 | break; | |
68511cec CES |
11529 | case DW_AT_calling_convention: |
11530 | /* DWARF doesn't provide a way to identify a program's source-level | |
11531 | entry point. DW_AT_calling_convention attributes are only meant | |
11532 | to describe functions' calling conventions. | |
11533 | ||
11534 | However, because it's a necessary piece of information in | |
11535 | Fortran, and because DW_CC_program is the only piece of debugging | |
11536 | information whose definition refers to a 'main program' at all, | |
11537 | several compilers have begun marking Fortran main programs with | |
11538 | DW_CC_program --- even when those functions use the standard | |
11539 | calling conventions. | |
11540 | ||
11541 | So until DWARF specifies a way to provide this information and | |
11542 | compilers pick up the new representation, we'll support this | |
11543 | practice. */ | |
11544 | if (DW_UNSND (&attr) == DW_CC_program | |
11545 | && cu->language == language_fortran) | |
01f8c46d JK |
11546 | { |
11547 | set_main_name (part_die->name); | |
11548 | ||
11549 | /* As this DIE has a static linkage the name would be difficult | |
11550 | to look up later. */ | |
11551 | language_of_main = language_fortran; | |
11552 | } | |
68511cec | 11553 | break; |
481860b3 GB |
11554 | case DW_AT_inline: |
11555 | if (DW_UNSND (&attr) == DW_INL_inlined | |
11556 | || DW_UNSND (&attr) == DW_INL_declared_inlined) | |
11557 | part_die->may_be_inlined = 1; | |
11558 | break; | |
95554aad TT |
11559 | |
11560 | case DW_AT_import: | |
11561 | if (part_die->tag == DW_TAG_imported_unit) | |
11562 | part_die->d.offset = dwarf2_get_ref_die_offset (&attr); | |
11563 | break; | |
11564 | ||
c906108c SS |
11565 | default: |
11566 | break; | |
11567 | } | |
11568 | } | |
11569 | ||
91da1414 MW |
11570 | if (high_pc_relative) |
11571 | part_die->highpc += part_die->lowpc; | |
11572 | ||
9373cf26 JK |
11573 | if (has_low_pc_attr && has_high_pc_attr) |
11574 | { | |
11575 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
11576 | eliminate duplicate copies of functions and vtables and such. | |
11577 | The linker will arbitrarily choose one and discard the others. | |
11578 | The AT_*_pc values for such functions refer to local labels in | |
11579 | these sections. If the section from that file was discarded, the | |
11580 | labels are not in the output, so the relocs get a value of 0. | |
11581 | If this is a discarded function, mark the pc bounds as invalid, | |
11582 | so that GDB will ignore it. */ | |
11583 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
11584 | { | |
bb5ed363 | 11585 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
11586 | |
11587 | complaint (&symfile_complaints, | |
11588 | _("DW_AT_low_pc %s is zero " | |
11589 | "for DIE at 0x%x [in module %s]"), | |
11590 | paddress (gdbarch, part_die->lowpc), | |
b64f50a1 | 11591 | part_die->offset.sect_off, objfile->name); |
9373cf26 JK |
11592 | } |
11593 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
11594 | else if (part_die->lowpc >= part_die->highpc) | |
11595 | { | |
bb5ed363 | 11596 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
11597 | |
11598 | complaint (&symfile_complaints, | |
11599 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
11600 | "for DIE at 0x%x [in module %s]"), | |
11601 | paddress (gdbarch, part_die->lowpc), | |
11602 | paddress (gdbarch, part_die->highpc), | |
b64f50a1 | 11603 | part_die->offset.sect_off, objfile->name); |
9373cf26 JK |
11604 | } |
11605 | else | |
11606 | part_die->has_pc_info = 1; | |
11607 | } | |
85cbf3d3 | 11608 | |
c906108c SS |
11609 | return info_ptr; |
11610 | } | |
11611 | ||
72bf9492 DJ |
11612 | /* Find a cached partial DIE at OFFSET in CU. */ |
11613 | ||
11614 | static struct partial_die_info * | |
b64f50a1 | 11615 | find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
11616 | { |
11617 | struct partial_die_info *lookup_die = NULL; | |
11618 | struct partial_die_info part_die; | |
11619 | ||
11620 | part_die.offset = offset; | |
b64f50a1 JK |
11621 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, |
11622 | offset.sect_off); | |
72bf9492 | 11623 | |
72bf9492 DJ |
11624 | return lookup_die; |
11625 | } | |
11626 | ||
348e048f DE |
11627 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
11628 | except in the case of .debug_types DIEs which do not reference | |
11629 | outside their CU (they do however referencing other types via | |
55f1336d | 11630 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
11631 | |
11632 | static struct partial_die_info * | |
b64f50a1 | 11633 | find_partial_die (sect_offset offset, struct dwarf2_cu *cu) |
72bf9492 | 11634 | { |
bb5ed363 | 11635 | struct objfile *objfile = cu->objfile; |
5afb4e99 DJ |
11636 | struct dwarf2_per_cu_data *per_cu = NULL; |
11637 | struct partial_die_info *pd = NULL; | |
72bf9492 | 11638 | |
45452591 | 11639 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
11640 | { |
11641 | pd = find_partial_die_in_comp_unit (offset, cu); | |
11642 | if (pd != NULL) | |
11643 | return pd; | |
0d99eb77 DE |
11644 | /* We missed recording what we needed. |
11645 | Load all dies and try again. */ | |
11646 | per_cu = cu->per_cu; | |
5afb4e99 | 11647 | } |
0d99eb77 DE |
11648 | else |
11649 | { | |
11650 | /* TUs don't reference other CUs/TUs (except via type signatures). */ | |
3019eac3 | 11651 | if (cu->per_cu->is_debug_types) |
0d99eb77 DE |
11652 | { |
11653 | error (_("Dwarf Error: Type Unit at offset 0x%lx contains" | |
11654 | " external reference to offset 0x%lx [in module %s].\n"), | |
11655 | (long) cu->header.offset.sect_off, (long) offset.sect_off, | |
11656 | bfd_get_filename (objfile->obfd)); | |
11657 | } | |
11658 | per_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
72bf9492 | 11659 | |
0d99eb77 DE |
11660 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
11661 | load_partial_comp_unit (per_cu); | |
ae038cb0 | 11662 | |
0d99eb77 DE |
11663 | per_cu->cu->last_used = 0; |
11664 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
11665 | } | |
5afb4e99 | 11666 | |
dee91e82 DE |
11667 | /* If we didn't find it, and not all dies have been loaded, |
11668 | load them all and try again. */ | |
11669 | ||
5afb4e99 DJ |
11670 | if (pd == NULL && per_cu->load_all_dies == 0) |
11671 | { | |
5afb4e99 | 11672 | per_cu->load_all_dies = 1; |
fd820528 DE |
11673 | |
11674 | /* This is nasty. When we reread the DIEs, somewhere up the call chain | |
11675 | THIS_CU->cu may already be in use. So we can't just free it and | |
11676 | replace its DIEs with the ones we read in. Instead, we leave those | |
11677 | DIEs alone (which can still be in use, e.g. in scan_partial_symbols), | |
11678 | and clobber THIS_CU->cu->partial_dies with the hash table for the new | |
11679 | set. */ | |
dee91e82 | 11680 | load_partial_comp_unit (per_cu); |
5afb4e99 DJ |
11681 | |
11682 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
11683 | } | |
11684 | ||
11685 | if (pd == NULL) | |
11686 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
11687 | _("could not find partial DIE 0x%x " |
11688 | "in cache [from module %s]\n"), | |
b64f50a1 | 11689 | offset.sect_off, bfd_get_filename (objfile->obfd)); |
5afb4e99 | 11690 | return pd; |
72bf9492 DJ |
11691 | } |
11692 | ||
abc72ce4 DE |
11693 | /* See if we can figure out if the class lives in a namespace. We do |
11694 | this by looking for a member function; its demangled name will | |
11695 | contain namespace info, if there is any. */ | |
11696 | ||
11697 | static void | |
11698 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
11699 | struct dwarf2_cu *cu) | |
11700 | { | |
11701 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
11702 | what template types look like, because the demangler | |
11703 | frequently doesn't give the same name as the debug info. We | |
11704 | could fix this by only using the demangled name to get the | |
11705 | prefix (but see comment in read_structure_type). */ | |
11706 | ||
11707 | struct partial_die_info *real_pdi; | |
11708 | struct partial_die_info *child_pdi; | |
11709 | ||
11710 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
11711 | we should not do this. We'll prepend the parent's fully qualified | |
11712 | name when we create the partial symbol. */ | |
11713 | ||
11714 | real_pdi = struct_pdi; | |
11715 | while (real_pdi->has_specification) | |
11716 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |
11717 | ||
11718 | if (real_pdi->die_parent != NULL) | |
11719 | return; | |
11720 | ||
11721 | for (child_pdi = struct_pdi->die_child; | |
11722 | child_pdi != NULL; | |
11723 | child_pdi = child_pdi->die_sibling) | |
11724 | { | |
11725 | if (child_pdi->tag == DW_TAG_subprogram | |
11726 | && child_pdi->linkage_name != NULL) | |
11727 | { | |
11728 | char *actual_class_name | |
11729 | = language_class_name_from_physname (cu->language_defn, | |
11730 | child_pdi->linkage_name); | |
11731 | if (actual_class_name != NULL) | |
11732 | { | |
11733 | struct_pdi->name | |
11734 | = obsavestring (actual_class_name, | |
11735 | strlen (actual_class_name), | |
11736 | &cu->objfile->objfile_obstack); | |
11737 | xfree (actual_class_name); | |
11738 | } | |
11739 | break; | |
11740 | } | |
11741 | } | |
11742 | } | |
11743 | ||
72bf9492 DJ |
11744 | /* Adjust PART_DIE before generating a symbol for it. This function |
11745 | may set the is_external flag or change the DIE's name. */ | |
11746 | ||
11747 | static void | |
11748 | fixup_partial_die (struct partial_die_info *part_die, | |
11749 | struct dwarf2_cu *cu) | |
11750 | { | |
abc72ce4 DE |
11751 | /* Once we've fixed up a die, there's no point in doing so again. |
11752 | This also avoids a memory leak if we were to call | |
11753 | guess_partial_die_structure_name multiple times. */ | |
11754 | if (part_die->fixup_called) | |
11755 | return; | |
11756 | ||
72bf9492 DJ |
11757 | /* If we found a reference attribute and the DIE has no name, try |
11758 | to find a name in the referred to DIE. */ | |
11759 | ||
11760 | if (part_die->name == NULL && part_die->has_specification) | |
11761 | { | |
11762 | struct partial_die_info *spec_die; | |
72bf9492 | 11763 | |
10b3939b | 11764 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 11765 | |
10b3939b | 11766 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
11767 | |
11768 | if (spec_die->name) | |
11769 | { | |
11770 | part_die->name = spec_die->name; | |
11771 | ||
11772 | /* Copy DW_AT_external attribute if it is set. */ | |
11773 | if (spec_die->is_external) | |
11774 | part_die->is_external = spec_die->is_external; | |
11775 | } | |
11776 | } | |
11777 | ||
11778 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
11779 | |
11780 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 11781 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 11782 | |
abc72ce4 DE |
11783 | /* If there is no parent die to provide a namespace, and there are |
11784 | children, see if we can determine the namespace from their linkage | |
122d1940 | 11785 | name. */ |
abc72ce4 | 11786 | if (cu->language == language_cplus |
8b70b953 | 11787 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
11788 | && part_die->die_parent == NULL |
11789 | && part_die->has_children | |
11790 | && (part_die->tag == DW_TAG_class_type | |
11791 | || part_die->tag == DW_TAG_structure_type | |
11792 | || part_die->tag == DW_TAG_union_type)) | |
11793 | guess_partial_die_structure_name (part_die, cu); | |
11794 | ||
53832f31 TT |
11795 | /* GCC might emit a nameless struct or union that has a linkage |
11796 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
11797 | if (part_die->name == NULL | |
96408a79 SA |
11798 | && (part_die->tag == DW_TAG_class_type |
11799 | || part_die->tag == DW_TAG_interface_type | |
11800 | || part_die->tag == DW_TAG_structure_type | |
11801 | || part_die->tag == DW_TAG_union_type) | |
53832f31 TT |
11802 | && part_die->linkage_name != NULL) |
11803 | { | |
11804 | char *demangled; | |
11805 | ||
11806 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
11807 | if (demangled) | |
11808 | { | |
96408a79 SA |
11809 | const char *base; |
11810 | ||
11811 | /* Strip any leading namespaces/classes, keep only the base name. | |
11812 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
11813 | base = strrchr (demangled, ':'); | |
11814 | if (base && base > demangled && base[-1] == ':') | |
11815 | base++; | |
11816 | else | |
11817 | base = demangled; | |
11818 | ||
11819 | part_die->name = obsavestring (base, strlen (base), | |
53832f31 TT |
11820 | &cu->objfile->objfile_obstack); |
11821 | xfree (demangled); | |
11822 | } | |
11823 | } | |
11824 | ||
abc72ce4 | 11825 | part_die->fixup_called = 1; |
72bf9492 DJ |
11826 | } |
11827 | ||
a8329558 | 11828 | /* Read an attribute value described by an attribute form. */ |
c906108c | 11829 | |
fe1b8b76 | 11830 | static gdb_byte * |
dee91e82 DE |
11831 | read_attribute_value (const struct die_reader_specs *reader, |
11832 | struct attribute *attr, unsigned form, | |
11833 | gdb_byte *info_ptr) | |
c906108c | 11834 | { |
dee91e82 DE |
11835 | struct dwarf2_cu *cu = reader->cu; |
11836 | bfd *abfd = reader->abfd; | |
e7c27a73 | 11837 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
11838 | unsigned int bytes_read; |
11839 | struct dwarf_block *blk; | |
11840 | ||
a8329558 KW |
11841 | attr->form = form; |
11842 | switch (form) | |
c906108c | 11843 | { |
c906108c | 11844 | case DW_FORM_ref_addr: |
ae411497 | 11845 | if (cu->header.version == 2) |
4568ecf9 | 11846 | DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
ae411497 | 11847 | else |
4568ecf9 DE |
11848 | DW_UNSND (attr) = read_offset (abfd, info_ptr, |
11849 | &cu->header, &bytes_read); | |
ae411497 TT |
11850 | info_ptr += bytes_read; |
11851 | break; | |
11852 | case DW_FORM_addr: | |
e7c27a73 | 11853 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 11854 | info_ptr += bytes_read; |
c906108c SS |
11855 | break; |
11856 | case DW_FORM_block2: | |
7b5a2f43 | 11857 | blk = dwarf_alloc_block (cu); |
c906108c SS |
11858 | blk->size = read_2_bytes (abfd, info_ptr); |
11859 | info_ptr += 2; | |
11860 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
11861 | info_ptr += blk->size; | |
11862 | DW_BLOCK (attr) = blk; | |
11863 | break; | |
11864 | case DW_FORM_block4: | |
7b5a2f43 | 11865 | blk = dwarf_alloc_block (cu); |
c906108c SS |
11866 | blk->size = read_4_bytes (abfd, info_ptr); |
11867 | info_ptr += 4; | |
11868 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
11869 | info_ptr += blk->size; | |
11870 | DW_BLOCK (attr) = blk; | |
11871 | break; | |
11872 | case DW_FORM_data2: | |
11873 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
11874 | info_ptr += 2; | |
11875 | break; | |
11876 | case DW_FORM_data4: | |
11877 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
11878 | info_ptr += 4; | |
11879 | break; | |
11880 | case DW_FORM_data8: | |
11881 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
11882 | info_ptr += 8; | |
11883 | break; | |
2dc7f7b3 TT |
11884 | case DW_FORM_sec_offset: |
11885 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
11886 | info_ptr += bytes_read; | |
11887 | break; | |
c906108c | 11888 | case DW_FORM_string: |
9b1c24c8 | 11889 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 11890 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
11891 | info_ptr += bytes_read; |
11892 | break; | |
4bdf3d34 JJ |
11893 | case DW_FORM_strp: |
11894 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
11895 | &bytes_read); | |
8285870a | 11896 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
11897 | info_ptr += bytes_read; |
11898 | break; | |
2dc7f7b3 | 11899 | case DW_FORM_exprloc: |
c906108c | 11900 | case DW_FORM_block: |
7b5a2f43 | 11901 | blk = dwarf_alloc_block (cu); |
c906108c SS |
11902 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
11903 | info_ptr += bytes_read; | |
11904 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
11905 | info_ptr += blk->size; | |
11906 | DW_BLOCK (attr) = blk; | |
11907 | break; | |
11908 | case DW_FORM_block1: | |
7b5a2f43 | 11909 | blk = dwarf_alloc_block (cu); |
c906108c SS |
11910 | blk->size = read_1_byte (abfd, info_ptr); |
11911 | info_ptr += 1; | |
11912 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
11913 | info_ptr += blk->size; | |
11914 | DW_BLOCK (attr) = blk; | |
11915 | break; | |
11916 | case DW_FORM_data1: | |
11917 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
11918 | info_ptr += 1; | |
11919 | break; | |
11920 | case DW_FORM_flag: | |
11921 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
11922 | info_ptr += 1; | |
11923 | break; | |
2dc7f7b3 TT |
11924 | case DW_FORM_flag_present: |
11925 | DW_UNSND (attr) = 1; | |
11926 | break; | |
c906108c SS |
11927 | case DW_FORM_sdata: |
11928 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
11929 | info_ptr += bytes_read; | |
11930 | break; | |
11931 | case DW_FORM_udata: | |
11932 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
11933 | info_ptr += bytes_read; | |
11934 | break; | |
11935 | case DW_FORM_ref1: | |
4568ecf9 DE |
11936 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11937 | + read_1_byte (abfd, info_ptr)); | |
c906108c SS |
11938 | info_ptr += 1; |
11939 | break; | |
11940 | case DW_FORM_ref2: | |
4568ecf9 DE |
11941 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11942 | + read_2_bytes (abfd, info_ptr)); | |
c906108c SS |
11943 | info_ptr += 2; |
11944 | break; | |
11945 | case DW_FORM_ref4: | |
4568ecf9 DE |
11946 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11947 | + read_4_bytes (abfd, info_ptr)); | |
c906108c SS |
11948 | info_ptr += 4; |
11949 | break; | |
613e1657 | 11950 | case DW_FORM_ref8: |
4568ecf9 DE |
11951 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11952 | + read_8_bytes (abfd, info_ptr)); | |
613e1657 KB |
11953 | info_ptr += 8; |
11954 | break; | |
55f1336d | 11955 | case DW_FORM_ref_sig8: |
348e048f DE |
11956 | /* Convert the signature to something we can record in DW_UNSND |
11957 | for later lookup. | |
11958 | NOTE: This is NULL if the type wasn't found. */ | |
11959 | DW_SIGNATURED_TYPE (attr) = | |
e319fa28 | 11960 | lookup_signatured_type (read_8_bytes (abfd, info_ptr)); |
348e048f DE |
11961 | info_ptr += 8; |
11962 | break; | |
c906108c | 11963 | case DW_FORM_ref_udata: |
4568ecf9 DE |
11964 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11965 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
11966 | info_ptr += bytes_read; |
11967 | break; | |
c906108c | 11968 | case DW_FORM_indirect: |
a8329558 KW |
11969 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
11970 | info_ptr += bytes_read; | |
dee91e82 | 11971 | info_ptr = read_attribute_value (reader, attr, form, info_ptr); |
a8329558 | 11972 | break; |
3019eac3 DE |
11973 | case DW_FORM_GNU_addr_index: |
11974 | if (reader->dwo_file == NULL) | |
11975 | { | |
11976 | /* For now flag a hard error. | |
11977 | Later we can turn this into a complaint. */ | |
11978 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), | |
11979 | dwarf_form_name (form), | |
11980 | bfd_get_filename (abfd)); | |
11981 | } | |
11982 | DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read); | |
11983 | info_ptr += bytes_read; | |
11984 | break; | |
11985 | case DW_FORM_GNU_str_index: | |
11986 | if (reader->dwo_file == NULL) | |
11987 | { | |
11988 | /* For now flag a hard error. | |
11989 | Later we can turn this into a complaint if warranted. */ | |
11990 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), | |
11991 | dwarf_form_name (form), | |
11992 | bfd_get_filename (abfd)); | |
11993 | } | |
11994 | { | |
11995 | ULONGEST str_index = | |
11996 | read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
11997 | ||
11998 | DW_STRING (attr) = read_str_index (reader, cu, str_index); | |
11999 | DW_STRING_IS_CANONICAL (attr) = 0; | |
12000 | info_ptr += bytes_read; | |
12001 | } | |
12002 | break; | |
c906108c | 12003 | default: |
8a3fe4f8 | 12004 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
12005 | dwarf_form_name (form), |
12006 | bfd_get_filename (abfd)); | |
c906108c | 12007 | } |
28e94949 JB |
12008 | |
12009 | /* We have seen instances where the compiler tried to emit a byte | |
12010 | size attribute of -1 which ended up being encoded as an unsigned | |
12011 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
12012 | an object of this size seems pretty unlikely so we can relatively | |
12013 | safely treat these cases as if the size attribute was invalid and | |
12014 | treat them as zero by default. */ | |
12015 | if (attr->name == DW_AT_byte_size | |
12016 | && form == DW_FORM_data4 | |
12017 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
12018 | { |
12019 | complaint | |
12020 | (&symfile_complaints, | |
43bbcdc2 PH |
12021 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
12022 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
12023 | DW_UNSND (attr) = 0; |
12024 | } | |
28e94949 | 12025 | |
c906108c SS |
12026 | return info_ptr; |
12027 | } | |
12028 | ||
a8329558 KW |
12029 | /* Read an attribute described by an abbreviated attribute. */ |
12030 | ||
fe1b8b76 | 12031 | static gdb_byte * |
dee91e82 DE |
12032 | read_attribute (const struct die_reader_specs *reader, |
12033 | struct attribute *attr, struct attr_abbrev *abbrev, | |
12034 | gdb_byte *info_ptr) | |
a8329558 KW |
12035 | { |
12036 | attr->name = abbrev->name; | |
dee91e82 | 12037 | return read_attribute_value (reader, attr, abbrev->form, info_ptr); |
a8329558 KW |
12038 | } |
12039 | ||
0963b4bd | 12040 | /* Read dwarf information from a buffer. */ |
c906108c SS |
12041 | |
12042 | static unsigned int | |
fe1b8b76 | 12043 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 12044 | { |
fe1b8b76 | 12045 | return bfd_get_8 (abfd, buf); |
c906108c SS |
12046 | } |
12047 | ||
12048 | static int | |
fe1b8b76 | 12049 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 12050 | { |
fe1b8b76 | 12051 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
12052 | } |
12053 | ||
12054 | static unsigned int | |
fe1b8b76 | 12055 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 12056 | { |
fe1b8b76 | 12057 | return bfd_get_16 (abfd, buf); |
c906108c SS |
12058 | } |
12059 | ||
21ae7a4d JK |
12060 | static int |
12061 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) | |
12062 | { | |
12063 | return bfd_get_signed_16 (abfd, buf); | |
12064 | } | |
12065 | ||
c906108c | 12066 | static unsigned int |
fe1b8b76 | 12067 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 12068 | { |
fe1b8b76 | 12069 | return bfd_get_32 (abfd, buf); |
c906108c SS |
12070 | } |
12071 | ||
21ae7a4d JK |
12072 | static int |
12073 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) | |
12074 | { | |
12075 | return bfd_get_signed_32 (abfd, buf); | |
12076 | } | |
12077 | ||
93311388 | 12078 | static ULONGEST |
fe1b8b76 | 12079 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 12080 | { |
fe1b8b76 | 12081 | return bfd_get_64 (abfd, buf); |
c906108c SS |
12082 | } |
12083 | ||
12084 | static CORE_ADDR | |
fe1b8b76 | 12085 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 12086 | unsigned int *bytes_read) |
c906108c | 12087 | { |
e7c27a73 | 12088 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
12089 | CORE_ADDR retval = 0; |
12090 | ||
107d2387 | 12091 | if (cu_header->signed_addr_p) |
c906108c | 12092 | { |
107d2387 AC |
12093 | switch (cu_header->addr_size) |
12094 | { | |
12095 | case 2: | |
fe1b8b76 | 12096 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
12097 | break; |
12098 | case 4: | |
fe1b8b76 | 12099 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
12100 | break; |
12101 | case 8: | |
fe1b8b76 | 12102 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
12103 | break; |
12104 | default: | |
8e65ff28 | 12105 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 12106 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 12107 | bfd_get_filename (abfd)); |
107d2387 AC |
12108 | } |
12109 | } | |
12110 | else | |
12111 | { | |
12112 | switch (cu_header->addr_size) | |
12113 | { | |
12114 | case 2: | |
fe1b8b76 | 12115 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
12116 | break; |
12117 | case 4: | |
fe1b8b76 | 12118 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
12119 | break; |
12120 | case 8: | |
fe1b8b76 | 12121 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
12122 | break; |
12123 | default: | |
8e65ff28 | 12124 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
12125 | _("read_address: bad switch, " |
12126 | "unsigned [in module %s]"), | |
659b0389 | 12127 | bfd_get_filename (abfd)); |
107d2387 | 12128 | } |
c906108c | 12129 | } |
64367e0a | 12130 | |
107d2387 AC |
12131 | *bytes_read = cu_header->addr_size; |
12132 | return retval; | |
c906108c SS |
12133 | } |
12134 | ||
f7ef9339 | 12135 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
12136 | specification allows the initial length to take up either 4 bytes |
12137 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
12138 | bytes describe the length and all offsets will be 8 bytes in length | |
12139 | instead of 4. | |
12140 | ||
f7ef9339 KB |
12141 | An older, non-standard 64-bit format is also handled by this |
12142 | function. The older format in question stores the initial length | |
12143 | as an 8-byte quantity without an escape value. Lengths greater | |
12144 | than 2^32 aren't very common which means that the initial 4 bytes | |
12145 | is almost always zero. Since a length value of zero doesn't make | |
12146 | sense for the 32-bit format, this initial zero can be considered to | |
12147 | be an escape value which indicates the presence of the older 64-bit | |
12148 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
12149 | greater than 4GB. If it becomes necessary to handle lengths |
12150 | somewhat larger than 4GB, we could allow other small values (such | |
12151 | as the non-sensical values of 1, 2, and 3) to also be used as | |
12152 | escape values indicating the presence of the old format. | |
f7ef9339 | 12153 | |
917c78fc MK |
12154 | The value returned via bytes_read should be used to increment the |
12155 | relevant pointer after calling read_initial_length(). | |
c764a876 | 12156 | |
613e1657 KB |
12157 | [ Note: read_initial_length() and read_offset() are based on the |
12158 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 12159 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
12160 | from: |
12161 | ||
f7ef9339 | 12162 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 12163 | |
613e1657 KB |
12164 | This document is only a draft and is subject to change. (So beware.) |
12165 | ||
f7ef9339 | 12166 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
12167 | determined empirically by examining 64-bit ELF files produced by |
12168 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
12169 | |
12170 | - Kevin, July 16, 2002 | |
613e1657 KB |
12171 | ] */ |
12172 | ||
12173 | static LONGEST | |
c764a876 | 12174 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 12175 | { |
fe1b8b76 | 12176 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 12177 | |
dd373385 | 12178 | if (length == 0xffffffff) |
613e1657 | 12179 | { |
fe1b8b76 | 12180 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 12181 | *bytes_read = 12; |
613e1657 | 12182 | } |
dd373385 | 12183 | else if (length == 0) |
f7ef9339 | 12184 | { |
dd373385 | 12185 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 12186 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 12187 | *bytes_read = 8; |
f7ef9339 | 12188 | } |
613e1657 KB |
12189 | else |
12190 | { | |
12191 | *bytes_read = 4; | |
613e1657 KB |
12192 | } |
12193 | ||
c764a876 DE |
12194 | return length; |
12195 | } | |
dd373385 | 12196 | |
c764a876 DE |
12197 | /* Cover function for read_initial_length. |
12198 | Returns the length of the object at BUF, and stores the size of the | |
12199 | initial length in *BYTES_READ and stores the size that offsets will be in | |
12200 | *OFFSET_SIZE. | |
12201 | If the initial length size is not equivalent to that specified in | |
12202 | CU_HEADER then issue a complaint. | |
12203 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 12204 | |
c764a876 DE |
12205 | static LONGEST |
12206 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
12207 | const struct comp_unit_head *cu_header, | |
12208 | unsigned int *bytes_read, | |
12209 | unsigned int *offset_size) | |
12210 | { | |
12211 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
12212 | ||
12213 | gdb_assert (cu_header->initial_length_size == 4 | |
12214 | || cu_header->initial_length_size == 8 | |
12215 | || cu_header->initial_length_size == 12); | |
12216 | ||
12217 | if (cu_header->initial_length_size != *bytes_read) | |
12218 | complaint (&symfile_complaints, | |
12219 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 12220 | |
c764a876 | 12221 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 12222 | return length; |
613e1657 KB |
12223 | } |
12224 | ||
12225 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 12226 | given by cu_header->offset_size. */ |
613e1657 KB |
12227 | |
12228 | static LONGEST | |
fe1b8b76 | 12229 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 12230 | unsigned int *bytes_read) |
c764a876 DE |
12231 | { |
12232 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 12233 | |
c764a876 DE |
12234 | *bytes_read = cu_header->offset_size; |
12235 | return offset; | |
12236 | } | |
12237 | ||
12238 | /* Read an offset from the data stream. */ | |
12239 | ||
12240 | static LONGEST | |
12241 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
12242 | { |
12243 | LONGEST retval = 0; | |
12244 | ||
c764a876 | 12245 | switch (offset_size) |
613e1657 KB |
12246 | { |
12247 | case 4: | |
fe1b8b76 | 12248 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
12249 | break; |
12250 | case 8: | |
fe1b8b76 | 12251 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
12252 | break; |
12253 | default: | |
8e65ff28 | 12254 | internal_error (__FILE__, __LINE__, |
c764a876 | 12255 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 12256 | bfd_get_filename (abfd)); |
613e1657 KB |
12257 | } |
12258 | ||
917c78fc | 12259 | return retval; |
613e1657 KB |
12260 | } |
12261 | ||
fe1b8b76 JB |
12262 | static gdb_byte * |
12263 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
12264 | { |
12265 | /* If the size of a host char is 8 bits, we can return a pointer | |
12266 | to the buffer, otherwise we have to copy the data to a buffer | |
12267 | allocated on the temporary obstack. */ | |
4bdf3d34 | 12268 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 12269 | return buf; |
c906108c SS |
12270 | } |
12271 | ||
12272 | static char * | |
9b1c24c8 | 12273 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
12274 | { |
12275 | /* If the size of a host char is 8 bits, we can return a pointer | |
12276 | to the string, otherwise we have to copy the string to a buffer | |
12277 | allocated on the temporary obstack. */ | |
4bdf3d34 | 12278 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
12279 | if (*buf == '\0') |
12280 | { | |
12281 | *bytes_read_ptr = 1; | |
12282 | return NULL; | |
12283 | } | |
fe1b8b76 JB |
12284 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
12285 | return (char *) buf; | |
4bdf3d34 JJ |
12286 | } |
12287 | ||
12288 | static char * | |
cf2c3c16 | 12289 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
4bdf3d34 | 12290 | { |
be391dca | 12291 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 12292 | if (dwarf2_per_objfile->str.buffer == NULL) |
cf2c3c16 TT |
12293 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
12294 | bfd_get_filename (abfd)); | |
dce234bc | 12295 | if (str_offset >= dwarf2_per_objfile->str.size) |
cf2c3c16 TT |
12296 | error (_("DW_FORM_strp pointing outside of " |
12297 | ".debug_str section [in module %s]"), | |
12298 | bfd_get_filename (abfd)); | |
4bdf3d34 | 12299 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 12300 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 12301 | return NULL; |
dce234bc | 12302 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
12303 | } |
12304 | ||
cf2c3c16 TT |
12305 | static char * |
12306 | read_indirect_string (bfd *abfd, gdb_byte *buf, | |
12307 | const struct comp_unit_head *cu_header, | |
12308 | unsigned int *bytes_read_ptr) | |
12309 | { | |
12310 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
12311 | ||
12312 | return read_indirect_string_at_offset (abfd, str_offset); | |
12313 | } | |
12314 | ||
12df843f | 12315 | static ULONGEST |
fe1b8b76 | 12316 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 12317 | { |
12df843f | 12318 | ULONGEST result; |
ce5d95e1 | 12319 | unsigned int num_read; |
c906108c SS |
12320 | int i, shift; |
12321 | unsigned char byte; | |
12322 | ||
12323 | result = 0; | |
12324 | shift = 0; | |
12325 | num_read = 0; | |
12326 | i = 0; | |
12327 | while (1) | |
12328 | { | |
fe1b8b76 | 12329 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
12330 | buf++; |
12331 | num_read++; | |
12df843f | 12332 | result |= ((ULONGEST) (byte & 127) << shift); |
c906108c SS |
12333 | if ((byte & 128) == 0) |
12334 | { | |
12335 | break; | |
12336 | } | |
12337 | shift += 7; | |
12338 | } | |
12339 | *bytes_read_ptr = num_read; | |
12340 | return result; | |
12341 | } | |
12342 | ||
12df843f | 12343 | static LONGEST |
fe1b8b76 | 12344 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 12345 | { |
12df843f | 12346 | LONGEST result; |
77e0b926 | 12347 | int i, shift, num_read; |
c906108c SS |
12348 | unsigned char byte; |
12349 | ||
12350 | result = 0; | |
12351 | shift = 0; | |
c906108c SS |
12352 | num_read = 0; |
12353 | i = 0; | |
12354 | while (1) | |
12355 | { | |
fe1b8b76 | 12356 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
12357 | buf++; |
12358 | num_read++; | |
12df843f | 12359 | result |= ((LONGEST) (byte & 127) << shift); |
c906108c SS |
12360 | shift += 7; |
12361 | if ((byte & 128) == 0) | |
12362 | { | |
12363 | break; | |
12364 | } | |
12365 | } | |
77e0b926 | 12366 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
12df843f | 12367 | result |= -(((LONGEST) 1) << shift); |
c906108c SS |
12368 | *bytes_read_ptr = num_read; |
12369 | return result; | |
12370 | } | |
12371 | ||
3019eac3 DE |
12372 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. |
12373 | ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero. | |
12374 | ADDR_SIZE is the size of addresses from the CU header. */ | |
12375 | ||
12376 | static CORE_ADDR | |
12377 | read_addr_index_1 (unsigned int addr_index, ULONGEST addr_base, int addr_size) | |
12378 | { | |
12379 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
12380 | bfd *abfd = objfile->obfd; | |
12381 | const gdb_byte *info_ptr; | |
12382 | ||
12383 | dwarf2_read_section (objfile, &dwarf2_per_objfile->addr); | |
12384 | if (dwarf2_per_objfile->addr.buffer == NULL) | |
12385 | error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"), | |
12386 | objfile->name); | |
12387 | if (addr_base + addr_index * addr_size >= dwarf2_per_objfile->addr.size) | |
12388 | error (_("DW_FORM_addr_index pointing outside of " | |
12389 | ".debug_addr section [in module %s]"), | |
12390 | objfile->name); | |
12391 | info_ptr = (dwarf2_per_objfile->addr.buffer | |
12392 | + addr_base + addr_index * addr_size); | |
12393 | if (addr_size == 4) | |
12394 | return bfd_get_32 (abfd, info_ptr); | |
12395 | else | |
12396 | return bfd_get_64 (abfd, info_ptr); | |
12397 | } | |
12398 | ||
12399 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. */ | |
12400 | ||
12401 | static CORE_ADDR | |
12402 | read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index) | |
12403 | { | |
12404 | return read_addr_index_1 (addr_index, cu->addr_base, cu->header.addr_size); | |
12405 | } | |
12406 | ||
12407 | /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */ | |
12408 | ||
12409 | static CORE_ADDR | |
12410 | read_addr_index_from_leb128 (struct dwarf2_cu *cu, gdb_byte *info_ptr, | |
12411 | unsigned int *bytes_read) | |
12412 | { | |
12413 | bfd *abfd = cu->objfile->obfd; | |
12414 | unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
12415 | ||
12416 | return read_addr_index (cu, addr_index); | |
12417 | } | |
12418 | ||
12419 | /* Data structure to pass results from dwarf2_read_addr_index_reader | |
12420 | back to dwarf2_read_addr_index. */ | |
12421 | ||
12422 | struct dwarf2_read_addr_index_data | |
12423 | { | |
12424 | ULONGEST addr_base; | |
12425 | int addr_size; | |
12426 | }; | |
12427 | ||
12428 | /* die_reader_func for dwarf2_read_addr_index. */ | |
12429 | ||
12430 | static void | |
12431 | dwarf2_read_addr_index_reader (const struct die_reader_specs *reader, | |
12432 | gdb_byte *info_ptr, | |
12433 | struct die_info *comp_unit_die, | |
12434 | int has_children, | |
12435 | void *data) | |
12436 | { | |
12437 | struct dwarf2_cu *cu = reader->cu; | |
12438 | struct dwarf2_read_addr_index_data *aidata = | |
12439 | (struct dwarf2_read_addr_index_data *) data; | |
12440 | ||
12441 | aidata->addr_base = cu->addr_base; | |
12442 | aidata->addr_size = cu->header.addr_size; | |
12443 | } | |
12444 | ||
12445 | /* Given an index in .debug_addr, fetch the value. | |
12446 | NOTE: This can be called during dwarf expression evaluation, | |
12447 | long after the debug information has been read, and thus per_cu->cu | |
12448 | may no longer exist. */ | |
12449 | ||
12450 | CORE_ADDR | |
12451 | dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu, | |
12452 | unsigned int addr_index) | |
12453 | { | |
12454 | struct objfile *objfile = per_cu->objfile; | |
12455 | struct dwarf2_cu *cu = per_cu->cu; | |
12456 | ULONGEST addr_base; | |
12457 | int addr_size; | |
12458 | ||
12459 | /* This is intended to be called from outside this file. */ | |
12460 | dw2_setup (objfile); | |
12461 | ||
12462 | /* We need addr_base and addr_size. | |
12463 | If we don't have PER_CU->cu, we have to get it. | |
12464 | Nasty, but the alternative is storing the needed info in PER_CU, | |
12465 | which at this point doesn't seem justified: it's not clear how frequently | |
12466 | it would get used and it would increase the size of every PER_CU. | |
12467 | Entry points like dwarf2_per_cu_addr_size do a similar thing | |
12468 | so we're not in uncharted territory here. | |
12469 | Alas we need to be a bit more complicated as addr_base is contained | |
12470 | in the DIE. | |
12471 | ||
12472 | We don't need to read the entire CU(/TU). | |
12473 | We just need the header and top level die. | |
12474 | IWBN to use the aging mechanism to let us lazily later discard the CU. | |
12475 | See however init_cutu_and_read_dies_simple. */ | |
12476 | ||
12477 | if (cu != NULL) | |
12478 | { | |
12479 | addr_base = cu->addr_base; | |
12480 | addr_size = cu->header.addr_size; | |
12481 | } | |
12482 | else | |
12483 | { | |
12484 | struct dwarf2_read_addr_index_data aidata; | |
12485 | ||
12486 | init_cutu_and_read_dies_simple (per_cu, dwarf2_read_addr_index_reader, | |
12487 | &aidata); | |
12488 | addr_base = aidata.addr_base; | |
12489 | addr_size = aidata.addr_size; | |
12490 | } | |
12491 | ||
12492 | return read_addr_index_1 (addr_index, addr_base, addr_size); | |
12493 | } | |
12494 | ||
12495 | /* Given a DW_AT_str_index, fetch the string. */ | |
12496 | ||
12497 | static char * | |
12498 | read_str_index (const struct die_reader_specs *reader, | |
12499 | struct dwarf2_cu *cu, ULONGEST str_index) | |
12500 | { | |
12501 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
12502 | const char *dwo_name = objfile->name; | |
12503 | bfd *abfd = objfile->obfd; | |
12504 | struct dwo_sections *sections = &reader->dwo_file->sections; | |
12505 | gdb_byte *info_ptr; | |
12506 | ULONGEST str_offset; | |
12507 | ||
12508 | dwarf2_read_section (objfile, §ions->str); | |
12509 | dwarf2_read_section (objfile, §ions->str_offsets); | |
12510 | if (sections->str.buffer == NULL) | |
12511 | error (_("DW_FORM_str_index used without .debug_str.dwo section" | |
12512 | " in CU at offset 0x%lx [in module %s]"), | |
12513 | (long) cu->header.offset.sect_off, dwo_name); | |
12514 | if (sections->str_offsets.buffer == NULL) | |
12515 | error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section" | |
12516 | " in CU at offset 0x%lx [in module %s]"), | |
12517 | (long) cu->header.offset.sect_off, dwo_name); | |
12518 | if (str_index * cu->header.offset_size >= sections->str_offsets.size) | |
12519 | error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo" | |
12520 | " section in CU at offset 0x%lx [in module %s]"), | |
12521 | (long) cu->header.offset.sect_off, dwo_name); | |
12522 | info_ptr = (sections->str_offsets.buffer | |
12523 | + str_index * cu->header.offset_size); | |
12524 | if (cu->header.offset_size == 4) | |
12525 | str_offset = bfd_get_32 (abfd, info_ptr); | |
12526 | else | |
12527 | str_offset = bfd_get_64 (abfd, info_ptr); | |
12528 | if (str_offset >= sections->str.size) | |
12529 | error (_("Offset from DW_FORM_str_index pointing outside of" | |
12530 | " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"), | |
12531 | (long) cu->header.offset.sect_off, dwo_name); | |
12532 | return (char *) (sections->str.buffer + str_offset); | |
12533 | } | |
12534 | ||
3019eac3 DE |
12535 | /* Return the length of an LEB128 number in BUF. */ |
12536 | ||
12537 | static int | |
12538 | leb128_size (const gdb_byte *buf) | |
12539 | { | |
12540 | const gdb_byte *begin = buf; | |
12541 | gdb_byte byte; | |
12542 | ||
12543 | while (1) | |
12544 | { | |
12545 | byte = *buf++; | |
12546 | if ((byte & 128) == 0) | |
12547 | return buf - begin; | |
12548 | } | |
12549 | } | |
12550 | ||
c906108c | 12551 | static void |
e142c38c | 12552 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
12553 | { |
12554 | switch (lang) | |
12555 | { | |
12556 | case DW_LANG_C89: | |
76bee0cc | 12557 | case DW_LANG_C99: |
c906108c | 12558 | case DW_LANG_C: |
e142c38c | 12559 | cu->language = language_c; |
c906108c SS |
12560 | break; |
12561 | case DW_LANG_C_plus_plus: | |
e142c38c | 12562 | cu->language = language_cplus; |
c906108c | 12563 | break; |
6aecb9c2 JB |
12564 | case DW_LANG_D: |
12565 | cu->language = language_d; | |
12566 | break; | |
c906108c SS |
12567 | case DW_LANG_Fortran77: |
12568 | case DW_LANG_Fortran90: | |
b21b22e0 | 12569 | case DW_LANG_Fortran95: |
e142c38c | 12570 | cu->language = language_fortran; |
c906108c | 12571 | break; |
a766d390 DE |
12572 | case DW_LANG_Go: |
12573 | cu->language = language_go; | |
12574 | break; | |
c906108c | 12575 | case DW_LANG_Mips_Assembler: |
e142c38c | 12576 | cu->language = language_asm; |
c906108c | 12577 | break; |
bebd888e | 12578 | case DW_LANG_Java: |
e142c38c | 12579 | cu->language = language_java; |
bebd888e | 12580 | break; |
c906108c | 12581 | case DW_LANG_Ada83: |
8aaf0b47 | 12582 | case DW_LANG_Ada95: |
bc5f45f8 JB |
12583 | cu->language = language_ada; |
12584 | break; | |
72019c9c GM |
12585 | case DW_LANG_Modula2: |
12586 | cu->language = language_m2; | |
12587 | break; | |
fe8e67fd PM |
12588 | case DW_LANG_Pascal83: |
12589 | cu->language = language_pascal; | |
12590 | break; | |
22566fbd DJ |
12591 | case DW_LANG_ObjC: |
12592 | cu->language = language_objc; | |
12593 | break; | |
c906108c SS |
12594 | case DW_LANG_Cobol74: |
12595 | case DW_LANG_Cobol85: | |
c906108c | 12596 | default: |
e142c38c | 12597 | cu->language = language_minimal; |
c906108c SS |
12598 | break; |
12599 | } | |
e142c38c | 12600 | cu->language_defn = language_def (cu->language); |
c906108c SS |
12601 | } |
12602 | ||
12603 | /* Return the named attribute or NULL if not there. */ | |
12604 | ||
12605 | static struct attribute * | |
e142c38c | 12606 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c | 12607 | { |
a48e046c | 12608 | for (;;) |
c906108c | 12609 | { |
a48e046c TT |
12610 | unsigned int i; |
12611 | struct attribute *spec = NULL; | |
12612 | ||
12613 | for (i = 0; i < die->num_attrs; ++i) | |
12614 | { | |
12615 | if (die->attrs[i].name == name) | |
12616 | return &die->attrs[i]; | |
12617 | if (die->attrs[i].name == DW_AT_specification | |
12618 | || die->attrs[i].name == DW_AT_abstract_origin) | |
12619 | spec = &die->attrs[i]; | |
12620 | } | |
12621 | ||
12622 | if (!spec) | |
12623 | break; | |
c906108c | 12624 | |
f2f0e013 | 12625 | die = follow_die_ref (die, spec, &cu); |
f2f0e013 | 12626 | } |
c5aa993b | 12627 | |
c906108c SS |
12628 | return NULL; |
12629 | } | |
12630 | ||
348e048f DE |
12631 | /* Return the named attribute or NULL if not there, |
12632 | but do not follow DW_AT_specification, etc. | |
12633 | This is for use in contexts where we're reading .debug_types dies. | |
12634 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
12635 | back up the chain, and we want to go down. */ | |
12636 | ||
12637 | static struct attribute * | |
12638 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
12639 | struct dwarf2_cu *cu) | |
12640 | { | |
12641 | unsigned int i; | |
12642 | ||
12643 | for (i = 0; i < die->num_attrs; ++i) | |
12644 | if (die->attrs[i].name == name) | |
12645 | return &die->attrs[i]; | |
12646 | ||
12647 | return NULL; | |
12648 | } | |
12649 | ||
05cf31d1 JB |
12650 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
12651 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 12652 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
12653 | |
12654 | static int | |
12655 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
12656 | { | |
12657 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
12658 | ||
12659 | return (attr && DW_UNSND (attr)); | |
12660 | } | |
12661 | ||
3ca72b44 | 12662 | static int |
e142c38c | 12663 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 12664 | { |
05cf31d1 JB |
12665 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
12666 | which value is non-zero. However, we have to be careful with | |
12667 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
12668 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
12669 | end up accidently finding a declaration attribute that belongs | |
12670 | to a different DIE referenced by the specification attribute, | |
12671 | even though the given DIE does not have a declaration attribute. */ | |
12672 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
12673 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
12674 | } |
12675 | ||
63d06c5c | 12676 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 12677 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
12678 | containing the return value on output. If there is no |
12679 | specification, but there is an abstract origin, that is | |
12680 | returned. */ | |
63d06c5c DC |
12681 | |
12682 | static struct die_info * | |
f2f0e013 | 12683 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 12684 | { |
f2f0e013 DJ |
12685 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
12686 | *spec_cu); | |
63d06c5c | 12687 | |
edb3359d DJ |
12688 | if (spec_attr == NULL) |
12689 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
12690 | ||
63d06c5c DC |
12691 | if (spec_attr == NULL) |
12692 | return NULL; | |
12693 | else | |
f2f0e013 | 12694 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 12695 | } |
c906108c | 12696 | |
debd256d | 12697 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
12698 | refers to. |
12699 | NOTE: This is also used as a "cleanup" function. */ | |
12700 | ||
debd256d JB |
12701 | static void |
12702 | free_line_header (struct line_header *lh) | |
12703 | { | |
12704 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 12705 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
12706 | |
12707 | /* Remember that all the lh->file_names[i].name pointers are | |
12708 | pointers into debug_line_buffer, and don't need to be freed. */ | |
12709 | if (lh->file_names) | |
a8bc7b56 | 12710 | xfree (lh->file_names); |
debd256d JB |
12711 | |
12712 | /* Similarly for the include directory names. */ | |
12713 | if (lh->include_dirs) | |
a8bc7b56 | 12714 | xfree (lh->include_dirs); |
debd256d | 12715 | |
a8bc7b56 | 12716 | xfree (lh); |
debd256d JB |
12717 | } |
12718 | ||
debd256d | 12719 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 12720 | |
debd256d JB |
12721 | static void |
12722 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 12723 | { |
debd256d JB |
12724 | /* Grow the array if necessary. */ |
12725 | if (lh->include_dirs_size == 0) | |
c5aa993b | 12726 | { |
debd256d JB |
12727 | lh->include_dirs_size = 1; /* for testing */ |
12728 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
12729 | * sizeof (*lh->include_dirs)); | |
12730 | } | |
12731 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
12732 | { | |
12733 | lh->include_dirs_size *= 2; | |
12734 | lh->include_dirs = xrealloc (lh->include_dirs, | |
12735 | (lh->include_dirs_size | |
12736 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 12737 | } |
c906108c | 12738 | |
debd256d JB |
12739 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
12740 | } | |
6e70227d | 12741 | |
debd256d | 12742 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 12743 | |
debd256d JB |
12744 | static void |
12745 | add_file_name (struct line_header *lh, | |
12746 | char *name, | |
12747 | unsigned int dir_index, | |
12748 | unsigned int mod_time, | |
12749 | unsigned int length) | |
12750 | { | |
12751 | struct file_entry *fe; | |
12752 | ||
12753 | /* Grow the array if necessary. */ | |
12754 | if (lh->file_names_size == 0) | |
12755 | { | |
12756 | lh->file_names_size = 1; /* for testing */ | |
12757 | lh->file_names = xmalloc (lh->file_names_size | |
12758 | * sizeof (*lh->file_names)); | |
12759 | } | |
12760 | else if (lh->num_file_names >= lh->file_names_size) | |
12761 | { | |
12762 | lh->file_names_size *= 2; | |
12763 | lh->file_names = xrealloc (lh->file_names, | |
12764 | (lh->file_names_size | |
12765 | * sizeof (*lh->file_names))); | |
12766 | } | |
12767 | ||
12768 | fe = &lh->file_names[lh->num_file_names++]; | |
12769 | fe->name = name; | |
12770 | fe->dir_index = dir_index; | |
12771 | fe->mod_time = mod_time; | |
12772 | fe->length = length; | |
aaa75496 | 12773 | fe->included_p = 0; |
cb1df416 | 12774 | fe->symtab = NULL; |
debd256d | 12775 | } |
6e70227d | 12776 | |
debd256d | 12777 | /* Read the statement program header starting at OFFSET in |
3019eac3 | 12778 | .debug_line, or .debug_line.dwo. Return a pointer |
6502dd73 | 12779 | to a struct line_header, allocated using xmalloc. |
debd256d JB |
12780 | |
12781 | NOTE: the strings in the include directory and file name tables of | |
3019eac3 DE |
12782 | the returned object point into the dwarf line section buffer, |
12783 | and must not be freed. */ | |
ae2de4f8 | 12784 | |
debd256d | 12785 | static struct line_header * |
3019eac3 | 12786 | dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu) |
debd256d JB |
12787 | { |
12788 | struct cleanup *back_to; | |
12789 | struct line_header *lh; | |
fe1b8b76 | 12790 | gdb_byte *line_ptr; |
c764a876 | 12791 | unsigned int bytes_read, offset_size; |
debd256d JB |
12792 | int i; |
12793 | char *cur_dir, *cur_file; | |
3019eac3 DE |
12794 | struct dwarf2_section_info *section; |
12795 | bfd *abfd; | |
12796 | ||
12797 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the | |
12798 | DWO file. */ | |
12799 | if (cu->dwo_unit && cu->per_cu->is_debug_types) | |
12800 | section = &cu->dwo_unit->dwo_file->sections.line; | |
12801 | else | |
12802 | section = &dwarf2_per_objfile->line; | |
debd256d | 12803 | |
3019eac3 DE |
12804 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); |
12805 | if (section->buffer == NULL) | |
debd256d | 12806 | { |
3019eac3 DE |
12807 | if (cu->dwo_unit && cu->per_cu->is_debug_types) |
12808 | complaint (&symfile_complaints, _("missing .debug_line.dwo section")); | |
12809 | else | |
12810 | complaint (&symfile_complaints, _("missing .debug_line section")); | |
debd256d JB |
12811 | return 0; |
12812 | } | |
12813 | ||
fceca515 DE |
12814 | /* We can't do this until we know the section is non-empty. |
12815 | Only then do we know we have such a section. */ | |
12816 | abfd = section->asection->owner; | |
12817 | ||
a738430d MK |
12818 | /* Make sure that at least there's room for the total_length field. |
12819 | That could be 12 bytes long, but we're just going to fudge that. */ | |
3019eac3 | 12820 | if (offset + 4 >= section->size) |
debd256d | 12821 | { |
4d3c2250 | 12822 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
12823 | return 0; |
12824 | } | |
12825 | ||
12826 | lh = xmalloc (sizeof (*lh)); | |
12827 | memset (lh, 0, sizeof (*lh)); | |
12828 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
12829 | (void *) lh); | |
12830 | ||
3019eac3 | 12831 | line_ptr = section->buffer + offset; |
debd256d | 12832 | |
a738430d | 12833 | /* Read in the header. */ |
6e70227d | 12834 | lh->total_length = |
c764a876 DE |
12835 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
12836 | &bytes_read, &offset_size); | |
debd256d | 12837 | line_ptr += bytes_read; |
3019eac3 | 12838 | if (line_ptr + lh->total_length > (section->buffer + section->size)) |
debd256d | 12839 | { |
4d3c2250 | 12840 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
12841 | return 0; |
12842 | } | |
12843 | lh->statement_program_end = line_ptr + lh->total_length; | |
12844 | lh->version = read_2_bytes (abfd, line_ptr); | |
12845 | line_ptr += 2; | |
c764a876 DE |
12846 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
12847 | line_ptr += offset_size; | |
debd256d JB |
12848 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
12849 | line_ptr += 1; | |
2dc7f7b3 TT |
12850 | if (lh->version >= 4) |
12851 | { | |
12852 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
12853 | line_ptr += 1; | |
12854 | } | |
12855 | else | |
12856 | lh->maximum_ops_per_instruction = 1; | |
12857 | ||
12858 | if (lh->maximum_ops_per_instruction == 0) | |
12859 | { | |
12860 | lh->maximum_ops_per_instruction = 1; | |
12861 | complaint (&symfile_complaints, | |
3e43a32a MS |
12862 | _("invalid maximum_ops_per_instruction " |
12863 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
12864 | } |
12865 | ||
debd256d JB |
12866 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
12867 | line_ptr += 1; | |
12868 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
12869 | line_ptr += 1; | |
12870 | lh->line_range = read_1_byte (abfd, line_ptr); | |
12871 | line_ptr += 1; | |
12872 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
12873 | line_ptr += 1; | |
12874 | lh->standard_opcode_lengths | |
fe1b8b76 | 12875 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
12876 | |
12877 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
12878 | for (i = 1; i < lh->opcode_base; ++i) | |
12879 | { | |
12880 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
12881 | line_ptr += 1; | |
12882 | } | |
12883 | ||
a738430d | 12884 | /* Read directory table. */ |
9b1c24c8 | 12885 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
12886 | { |
12887 | line_ptr += bytes_read; | |
12888 | add_include_dir (lh, cur_dir); | |
12889 | } | |
12890 | line_ptr += bytes_read; | |
12891 | ||
a738430d | 12892 | /* Read file name table. */ |
9b1c24c8 | 12893 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
12894 | { |
12895 | unsigned int dir_index, mod_time, length; | |
12896 | ||
12897 | line_ptr += bytes_read; | |
12898 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12899 | line_ptr += bytes_read; | |
12900 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12901 | line_ptr += bytes_read; | |
12902 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12903 | line_ptr += bytes_read; | |
12904 | ||
12905 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
12906 | } | |
12907 | line_ptr += bytes_read; | |
6e70227d | 12908 | lh->statement_program_start = line_ptr; |
debd256d | 12909 | |
3019eac3 | 12910 | if (line_ptr > (section->buffer + section->size)) |
4d3c2250 | 12911 | complaint (&symfile_complaints, |
3e43a32a MS |
12912 | _("line number info header doesn't " |
12913 | "fit in `.debug_line' section")); | |
debd256d JB |
12914 | |
12915 | discard_cleanups (back_to); | |
12916 | return lh; | |
12917 | } | |
c906108c | 12918 | |
c6da4cef DE |
12919 | /* Subroutine of dwarf_decode_lines to simplify it. |
12920 | Return the file name of the psymtab for included file FILE_INDEX | |
12921 | in line header LH of PST. | |
12922 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
12923 | If space for the result is malloc'd, it will be freed by a cleanup. | |
12924 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
12925 | ||
12926 | static char * | |
12927 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
12928 | const struct partial_symtab *pst, | |
12929 | const char *comp_dir) | |
12930 | { | |
12931 | const struct file_entry fe = lh->file_names [file_index]; | |
12932 | char *include_name = fe.name; | |
12933 | char *include_name_to_compare = include_name; | |
12934 | char *dir_name = NULL; | |
72b9f47f TT |
12935 | const char *pst_filename; |
12936 | char *copied_name = NULL; | |
c6da4cef DE |
12937 | int file_is_pst; |
12938 | ||
12939 | if (fe.dir_index) | |
12940 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
12941 | ||
12942 | if (!IS_ABSOLUTE_PATH (include_name) | |
12943 | && (dir_name != NULL || comp_dir != NULL)) | |
12944 | { | |
12945 | /* Avoid creating a duplicate psymtab for PST. | |
12946 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
12947 | Before we do the comparison, however, we need to account | |
12948 | for DIR_NAME and COMP_DIR. | |
12949 | First prepend dir_name (if non-NULL). If we still don't | |
12950 | have an absolute path prepend comp_dir (if non-NULL). | |
12951 | However, the directory we record in the include-file's | |
12952 | psymtab does not contain COMP_DIR (to match the | |
12953 | corresponding symtab(s)). | |
12954 | ||
12955 | Example: | |
12956 | ||
12957 | bash$ cd /tmp | |
12958 | bash$ gcc -g ./hello.c | |
12959 | include_name = "hello.c" | |
12960 | dir_name = "." | |
12961 | DW_AT_comp_dir = comp_dir = "/tmp" | |
12962 | DW_AT_name = "./hello.c" */ | |
12963 | ||
12964 | if (dir_name != NULL) | |
12965 | { | |
12966 | include_name = concat (dir_name, SLASH_STRING, | |
12967 | include_name, (char *)NULL); | |
12968 | include_name_to_compare = include_name; | |
12969 | make_cleanup (xfree, include_name); | |
12970 | } | |
12971 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
12972 | { | |
12973 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
12974 | include_name, (char *)NULL); | |
12975 | } | |
12976 | } | |
12977 | ||
12978 | pst_filename = pst->filename; | |
12979 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
12980 | { | |
72b9f47f TT |
12981 | copied_name = concat (pst->dirname, SLASH_STRING, |
12982 | pst_filename, (char *)NULL); | |
12983 | pst_filename = copied_name; | |
c6da4cef DE |
12984 | } |
12985 | ||
1e3fad37 | 12986 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
12987 | |
12988 | if (include_name_to_compare != include_name) | |
12989 | xfree (include_name_to_compare); | |
72b9f47f TT |
12990 | if (copied_name != NULL) |
12991 | xfree (copied_name); | |
c6da4cef DE |
12992 | |
12993 | if (file_is_pst) | |
12994 | return NULL; | |
12995 | return include_name; | |
12996 | } | |
12997 | ||
c91513d8 PP |
12998 | /* Ignore this record_line request. */ |
12999 | ||
13000 | static void | |
13001 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
13002 | { | |
13003 | return; | |
13004 | } | |
13005 | ||
f3f5162e DE |
13006 | /* Subroutine of dwarf_decode_lines to simplify it. |
13007 | Process the line number information in LH. */ | |
debd256d | 13008 | |
c906108c | 13009 | static void |
f3f5162e DE |
13010 | dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, |
13011 | struct dwarf2_cu *cu, struct partial_symtab *pst) | |
c906108c | 13012 | { |
a8c50c1f | 13013 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 13014 | gdb_byte *line_end; |
a8c50c1f | 13015 | unsigned int bytes_read, extended_len; |
c906108c | 13016 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
13017 | CORE_ADDR baseaddr; |
13018 | struct objfile *objfile = cu->objfile; | |
f3f5162e | 13019 | bfd *abfd = objfile->obfd; |
fbf65064 | 13020 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 13021 | const int decode_for_pst_p = (pst != NULL); |
f3f5162e | 13022 | struct subfile *last_subfile = NULL; |
c91513d8 PP |
13023 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
13024 | = record_line; | |
e142c38c DJ |
13025 | |
13026 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 13027 | |
debd256d JB |
13028 | line_ptr = lh->statement_program_start; |
13029 | line_end = lh->statement_program_end; | |
c906108c SS |
13030 | |
13031 | /* Read the statement sequences until there's nothing left. */ | |
13032 | while (line_ptr < line_end) | |
13033 | { | |
13034 | /* state machine registers */ | |
13035 | CORE_ADDR address = 0; | |
13036 | unsigned int file = 1; | |
13037 | unsigned int line = 1; | |
13038 | unsigned int column = 0; | |
debd256d | 13039 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
13040 | int basic_block = 0; |
13041 | int end_sequence = 0; | |
fbf65064 | 13042 | CORE_ADDR addr; |
2dc7f7b3 | 13043 | unsigned char op_index = 0; |
c906108c | 13044 | |
aaa75496 | 13045 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 13046 | { |
aaa75496 | 13047 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
13048 | /* lh->include_dirs and lh->file_names are 0-based, but the |
13049 | directory and file name numbers in the statement program | |
13050 | are 1-based. */ | |
13051 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 13052 | char *dir = NULL; |
a738430d | 13053 | |
debd256d JB |
13054 | if (fe->dir_index) |
13055 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
13056 | |
13057 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
13058 | } |
13059 | ||
a738430d | 13060 | /* Decode the table. */ |
c5aa993b | 13061 | while (!end_sequence) |
c906108c SS |
13062 | { |
13063 | op_code = read_1_byte (abfd, line_ptr); | |
13064 | line_ptr += 1; | |
59205f5a JB |
13065 | if (line_ptr > line_end) |
13066 | { | |
13067 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
13068 | break; | |
13069 | } | |
9aa1fe7e | 13070 | |
debd256d | 13071 | if (op_code >= lh->opcode_base) |
6e70227d | 13072 | { |
a738430d | 13073 | /* Special operand. */ |
debd256d | 13074 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
13075 | address += (((op_index + (adj_opcode / lh->line_range)) |
13076 | / lh->maximum_ops_per_instruction) | |
13077 | * lh->minimum_instruction_length); | |
13078 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
13079 | % lh->maximum_ops_per_instruction); | |
debd256d | 13080 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 13081 | if (lh->num_file_names < file || file == 0) |
25e43795 | 13082 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
13083 | /* For now we ignore lines not starting on an |
13084 | instruction boundary. */ | |
13085 | else if (op_index == 0) | |
25e43795 DJ |
13086 | { |
13087 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 13088 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
13089 | { |
13090 | if (last_subfile != current_subfile) | |
13091 | { | |
13092 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
13093 | if (last_subfile) | |
c91513d8 | 13094 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
13095 | last_subfile = current_subfile; |
13096 | } | |
25e43795 | 13097 | /* Append row to matrix using current values. */ |
7019d805 | 13098 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 13099 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 13100 | } |
25e43795 | 13101 | } |
ca5f395d | 13102 | basic_block = 0; |
9aa1fe7e GK |
13103 | } |
13104 | else switch (op_code) | |
c906108c SS |
13105 | { |
13106 | case DW_LNS_extended_op: | |
3e43a32a MS |
13107 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
13108 | &bytes_read); | |
473b7be6 | 13109 | line_ptr += bytes_read; |
a8c50c1f | 13110 | extended_end = line_ptr + extended_len; |
c906108c SS |
13111 | extended_op = read_1_byte (abfd, line_ptr); |
13112 | line_ptr += 1; | |
13113 | switch (extended_op) | |
13114 | { | |
13115 | case DW_LNE_end_sequence: | |
c91513d8 | 13116 | p_record_line = record_line; |
c906108c | 13117 | end_sequence = 1; |
c906108c SS |
13118 | break; |
13119 | case DW_LNE_set_address: | |
e7c27a73 | 13120 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
13121 | |
13122 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
13123 | { | |
13124 | /* This line table is for a function which has been | |
13125 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
13126 | ||
13127 | long line_offset | |
13128 | = line_ptr - dwarf2_per_objfile->line.buffer; | |
13129 | ||
13130 | complaint (&symfile_complaints, | |
13131 | _(".debug_line address at offset 0x%lx is 0 " | |
13132 | "[in module %s]"), | |
bb5ed363 | 13133 | line_offset, objfile->name); |
c91513d8 PP |
13134 | p_record_line = noop_record_line; |
13135 | } | |
13136 | ||
2dc7f7b3 | 13137 | op_index = 0; |
107d2387 AC |
13138 | line_ptr += bytes_read; |
13139 | address += baseaddr; | |
c906108c SS |
13140 | break; |
13141 | case DW_LNE_define_file: | |
debd256d JB |
13142 | { |
13143 | char *cur_file; | |
13144 | unsigned int dir_index, mod_time, length; | |
6e70227d | 13145 | |
3e43a32a MS |
13146 | cur_file = read_direct_string (abfd, line_ptr, |
13147 | &bytes_read); | |
debd256d JB |
13148 | line_ptr += bytes_read; |
13149 | dir_index = | |
13150 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
13151 | line_ptr += bytes_read; | |
13152 | mod_time = | |
13153 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
13154 | line_ptr += bytes_read; | |
13155 | length = | |
13156 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
13157 | line_ptr += bytes_read; | |
13158 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
13159 | } | |
c906108c | 13160 | break; |
d0c6ba3d CC |
13161 | case DW_LNE_set_discriminator: |
13162 | /* The discriminator is not interesting to the debugger; | |
13163 | just ignore it. */ | |
13164 | line_ptr = extended_end; | |
13165 | break; | |
c906108c | 13166 | default: |
4d3c2250 | 13167 | complaint (&symfile_complaints, |
e2e0b3e5 | 13168 | _("mangled .debug_line section")); |
debd256d | 13169 | return; |
c906108c | 13170 | } |
a8c50c1f DJ |
13171 | /* Make sure that we parsed the extended op correctly. If e.g. |
13172 | we expected a different address size than the producer used, | |
13173 | we may have read the wrong number of bytes. */ | |
13174 | if (line_ptr != extended_end) | |
13175 | { | |
13176 | complaint (&symfile_complaints, | |
13177 | _("mangled .debug_line section")); | |
13178 | return; | |
13179 | } | |
c906108c SS |
13180 | break; |
13181 | case DW_LNS_copy: | |
59205f5a | 13182 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
13183 | dwarf2_debug_line_missing_file_complaint (); |
13184 | else | |
366da635 | 13185 | { |
25e43795 | 13186 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 13187 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
13188 | { |
13189 | if (last_subfile != current_subfile) | |
13190 | { | |
13191 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
13192 | if (last_subfile) | |
c91513d8 | 13193 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
13194 | last_subfile = current_subfile; |
13195 | } | |
7019d805 | 13196 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 13197 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 13198 | } |
366da635 | 13199 | } |
c906108c SS |
13200 | basic_block = 0; |
13201 | break; | |
13202 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
13203 | { |
13204 | CORE_ADDR adjust | |
13205 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
13206 | ||
13207 | address += (((op_index + adjust) | |
13208 | / lh->maximum_ops_per_instruction) | |
13209 | * lh->minimum_instruction_length); | |
13210 | op_index = ((op_index + adjust) | |
13211 | % lh->maximum_ops_per_instruction); | |
13212 | line_ptr += bytes_read; | |
13213 | } | |
c906108c SS |
13214 | break; |
13215 | case DW_LNS_advance_line: | |
13216 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
13217 | line_ptr += bytes_read; | |
13218 | break; | |
13219 | case DW_LNS_set_file: | |
debd256d | 13220 | { |
a738430d MK |
13221 | /* The arrays lh->include_dirs and lh->file_names are |
13222 | 0-based, but the directory and file name numbers in | |
13223 | the statement program are 1-based. */ | |
debd256d | 13224 | struct file_entry *fe; |
4f1520fb | 13225 | char *dir = NULL; |
a738430d | 13226 | |
debd256d JB |
13227 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
13228 | line_ptr += bytes_read; | |
59205f5a | 13229 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
13230 | dwarf2_debug_line_missing_file_complaint (); |
13231 | else | |
13232 | { | |
13233 | fe = &lh->file_names[file - 1]; | |
13234 | if (fe->dir_index) | |
13235 | dir = lh->include_dirs[fe->dir_index - 1]; | |
13236 | if (!decode_for_pst_p) | |
13237 | { | |
13238 | last_subfile = current_subfile; | |
13239 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
13240 | } | |
13241 | } | |
debd256d | 13242 | } |
c906108c SS |
13243 | break; |
13244 | case DW_LNS_set_column: | |
13245 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
13246 | line_ptr += bytes_read; | |
13247 | break; | |
13248 | case DW_LNS_negate_stmt: | |
13249 | is_stmt = (!is_stmt); | |
13250 | break; | |
13251 | case DW_LNS_set_basic_block: | |
13252 | basic_block = 1; | |
13253 | break; | |
c2c6d25f JM |
13254 | /* Add to the address register of the state machine the |
13255 | address increment value corresponding to special opcode | |
a738430d MK |
13256 | 255. I.e., this value is scaled by the minimum |
13257 | instruction length since special opcode 255 would have | |
b021a221 | 13258 | scaled the increment. */ |
c906108c | 13259 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
13260 | { |
13261 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
13262 | ||
13263 | address += (((op_index + adjust) | |
13264 | / lh->maximum_ops_per_instruction) | |
13265 | * lh->minimum_instruction_length); | |
13266 | op_index = ((op_index + adjust) | |
13267 | % lh->maximum_ops_per_instruction); | |
13268 | } | |
c906108c SS |
13269 | break; |
13270 | case DW_LNS_fixed_advance_pc: | |
13271 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 13272 | op_index = 0; |
c906108c SS |
13273 | line_ptr += 2; |
13274 | break; | |
9aa1fe7e | 13275 | default: |
a738430d MK |
13276 | { |
13277 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 13278 | int i; |
a738430d | 13279 | |
debd256d | 13280 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
13281 | { |
13282 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
13283 | line_ptr += bytes_read; | |
13284 | } | |
13285 | } | |
c906108c SS |
13286 | } |
13287 | } | |
59205f5a JB |
13288 | if (lh->num_file_names < file || file == 0) |
13289 | dwarf2_debug_line_missing_file_complaint (); | |
13290 | else | |
13291 | { | |
13292 | lh->file_names[file - 1].included_p = 1; | |
13293 | if (!decode_for_pst_p) | |
fbf65064 UW |
13294 | { |
13295 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 13296 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 13297 | } |
59205f5a | 13298 | } |
c906108c | 13299 | } |
f3f5162e DE |
13300 | } |
13301 | ||
13302 | /* Decode the Line Number Program (LNP) for the given line_header | |
13303 | structure and CU. The actual information extracted and the type | |
13304 | of structures created from the LNP depends on the value of PST. | |
13305 | ||
13306 | 1. If PST is NULL, then this procedure uses the data from the program | |
13307 | to create all necessary symbol tables, and their linetables. | |
13308 | ||
13309 | 2. If PST is not NULL, this procedure reads the program to determine | |
13310 | the list of files included by the unit represented by PST, and | |
13311 | builds all the associated partial symbol tables. | |
13312 | ||
13313 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
13314 | It is used for relative paths in the line table. | |
13315 | NOTE: When processing partial symtabs (pst != NULL), | |
13316 | comp_dir == pst->dirname. | |
13317 | ||
13318 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
13319 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
13320 | symtab we don't use it in the name of the psymtabs we create. | |
13321 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
13322 | A good testcase for this is mb-inline.exp. */ | |
13323 | ||
13324 | static void | |
13325 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, | |
13326 | struct dwarf2_cu *cu, struct partial_symtab *pst, | |
13327 | int want_line_info) | |
13328 | { | |
13329 | struct objfile *objfile = cu->objfile; | |
13330 | const int decode_for_pst_p = (pst != NULL); | |
13331 | struct subfile *first_subfile = current_subfile; | |
13332 | ||
13333 | if (want_line_info) | |
13334 | dwarf_decode_lines_1 (lh, comp_dir, cu, pst); | |
aaa75496 JB |
13335 | |
13336 | if (decode_for_pst_p) | |
13337 | { | |
13338 | int file_index; | |
13339 | ||
13340 | /* Now that we're done scanning the Line Header Program, we can | |
13341 | create the psymtab of each included file. */ | |
13342 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
13343 | if (lh->file_names[file_index].included_p == 1) | |
13344 | { | |
c6da4cef DE |
13345 | char *include_name = |
13346 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
13347 | if (include_name != NULL) | |
aaa75496 JB |
13348 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
13349 | } | |
13350 | } | |
cb1df416 DJ |
13351 | else |
13352 | { | |
13353 | /* Make sure a symtab is created for every file, even files | |
13354 | which contain only variables (i.e. no code with associated | |
13355 | line numbers). */ | |
cb1df416 | 13356 | int i; |
cb1df416 DJ |
13357 | |
13358 | for (i = 0; i < lh->num_file_names; i++) | |
13359 | { | |
13360 | char *dir = NULL; | |
f3f5162e | 13361 | struct file_entry *fe; |
9a619af0 | 13362 | |
cb1df416 DJ |
13363 | fe = &lh->file_names[i]; |
13364 | if (fe->dir_index) | |
13365 | dir = lh->include_dirs[fe->dir_index - 1]; | |
13366 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
13367 | ||
13368 | /* Skip the main file; we don't need it, and it must be | |
13369 | allocated last, so that it will show up before the | |
13370 | non-primary symtabs in the objfile's symtab list. */ | |
13371 | if (current_subfile == first_subfile) | |
13372 | continue; | |
13373 | ||
13374 | if (current_subfile->symtab == NULL) | |
13375 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
bb5ed363 | 13376 | objfile); |
cb1df416 DJ |
13377 | fe->symtab = current_subfile->symtab; |
13378 | } | |
13379 | } | |
c906108c SS |
13380 | } |
13381 | ||
13382 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
13383 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
13384 | or NULL if not known. COMP_DIR is the compilation directory for the |
13385 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
13386 | This routine tries to keep line numbers from identical absolute and |
13387 | relative file names in a common subfile. | |
13388 | ||
13389 | Using the `list' example from the GDB testsuite, which resides in | |
13390 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
13391 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
13392 | ||
c5aa993b JM |
13393 | DW_AT_name: /srcdir/list0.c |
13394 | DW_AT_comp_dir: /compdir | |
357e46e7 | 13395 | files.files[0].name: list0.h |
c5aa993b | 13396 | files.files[0].dir: /srcdir |
357e46e7 | 13397 | files.files[1].name: list0.c |
c5aa993b | 13398 | files.files[1].dir: /srcdir |
c906108c SS |
13399 | |
13400 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
13401 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
13402 | start_subfile will ensure that this happens provided that we pass the | |
13403 | concatenation of files.files[1].dir and files.files[1].name as the | |
13404 | subfile's name. */ | |
c906108c SS |
13405 | |
13406 | static void | |
3e43a32a MS |
13407 | dwarf2_start_subfile (char *filename, const char *dirname, |
13408 | const char *comp_dir) | |
c906108c | 13409 | { |
4f1520fb FR |
13410 | char *fullname; |
13411 | ||
13412 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
13413 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
13414 | second argument to start_subfile. To be consistent, we do the | |
13415 | same here. In order not to lose the line information directory, | |
13416 | we concatenate it to the filename when it makes sense. | |
13417 | Note that the Dwarf3 standard says (speaking of filenames in line | |
13418 | information): ``The directory index is ignored for file names | |
13419 | that represent full path names''. Thus ignoring dirname in the | |
13420 | `else' branch below isn't an issue. */ | |
c906108c | 13421 | |
d5166ae1 | 13422 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
13423 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
13424 | else | |
13425 | fullname = filename; | |
c906108c | 13426 | |
4f1520fb FR |
13427 | start_subfile (fullname, comp_dir); |
13428 | ||
13429 | if (fullname != filename) | |
13430 | xfree (fullname); | |
c906108c SS |
13431 | } |
13432 | ||
4c2df51b DJ |
13433 | static void |
13434 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 13435 | struct dwarf2_cu *cu) |
4c2df51b | 13436 | { |
e7c27a73 DJ |
13437 | struct objfile *objfile = cu->objfile; |
13438 | struct comp_unit_head *cu_header = &cu->header; | |
13439 | ||
4c2df51b DJ |
13440 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
13441 | code here to turn a symbol with DW_AT_external and a | |
13442 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
13443 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
13444 | with some versions of binutils) where shared libraries could have | |
13445 | relocations against symbols in their debug information - the | |
13446 | minimal symbol would have the right address, but the debug info | |
13447 | would not. It's no longer necessary, because we will explicitly | |
13448 | apply relocations when we read in the debug information now. */ | |
13449 | ||
13450 | /* A DW_AT_location attribute with no contents indicates that a | |
13451 | variable has been optimized away. */ | |
13452 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
13453 | { | |
13454 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
13455 | return; | |
13456 | } | |
13457 | ||
13458 | /* Handle one degenerate form of location expression specially, to | |
13459 | preserve GDB's previous behavior when section offsets are | |
3019eac3 DE |
13460 | specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index |
13461 | then mark this symbol as LOC_STATIC. */ | |
4c2df51b DJ |
13462 | |
13463 | if (attr_form_is_block (attr) | |
3019eac3 DE |
13464 | && ((DW_BLOCK (attr)->data[0] == DW_OP_addr |
13465 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size) | |
13466 | || (DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index | |
13467 | && (DW_BLOCK (attr)->size | |
13468 | == 1 + leb128_size (&DW_BLOCK (attr)->data[1]))))) | |
4c2df51b | 13469 | { |
891d2f0b | 13470 | unsigned int dummy; |
4c2df51b | 13471 | |
3019eac3 DE |
13472 | if (DW_BLOCK (attr)->data[0] == DW_OP_addr) |
13473 | SYMBOL_VALUE_ADDRESS (sym) = | |
13474 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); | |
13475 | else | |
13476 | SYMBOL_VALUE_ADDRESS (sym) = | |
13477 | read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy); | |
907fc202 | 13478 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
13479 | fixup_symbol_section (sym, objfile); |
13480 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
13481 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
13482 | return; |
13483 | } | |
13484 | ||
13485 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
13486 | expression evaluator, and use LOC_COMPUTED only when necessary | |
13487 | (i.e. when the value of a register or memory location is | |
13488 | referenced, or a thread-local block, etc.). Then again, it might | |
13489 | not be worthwhile. I'm assuming that it isn't unless performance | |
13490 | or memory numbers show me otherwise. */ | |
13491 | ||
e7c27a73 | 13492 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b | 13493 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8be455d7 JK |
13494 | |
13495 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) | |
13496 | cu->has_loclist = 1; | |
4c2df51b DJ |
13497 | } |
13498 | ||
c906108c SS |
13499 | /* Given a pointer to a DWARF information entry, figure out if we need |
13500 | to make a symbol table entry for it, and if so, create a new entry | |
13501 | and return a pointer to it. | |
13502 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
13503 | used the passed type. |
13504 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
13505 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
13506 | |
13507 | static struct symbol * | |
34eaf542 TT |
13508 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
13509 | struct symbol *space) | |
c906108c | 13510 | { |
e7c27a73 | 13511 | struct objfile *objfile = cu->objfile; |
c906108c SS |
13512 | struct symbol *sym = NULL; |
13513 | char *name; | |
13514 | struct attribute *attr = NULL; | |
13515 | struct attribute *attr2 = NULL; | |
e142c38c | 13516 | CORE_ADDR baseaddr; |
e37fd15a SW |
13517 | struct pending **list_to_add = NULL; |
13518 | ||
edb3359d | 13519 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
13520 | |
13521 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 13522 | |
94af9270 | 13523 | name = dwarf2_name (die, cu); |
c906108c SS |
13524 | if (name) |
13525 | { | |
94af9270 | 13526 | const char *linkagename; |
34eaf542 | 13527 | int suppress_add = 0; |
94af9270 | 13528 | |
34eaf542 TT |
13529 | if (space) |
13530 | sym = space; | |
13531 | else | |
13532 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 13533 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
13534 | |
13535 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 13536 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
13537 | linkagename = dwarf2_physname (name, die, cu); |
13538 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 13539 | |
f55ee35c JK |
13540 | /* Fortran does not have mangling standard and the mangling does differ |
13541 | between gfortran, iFort etc. */ | |
13542 | if (cu->language == language_fortran | |
b250c185 | 13543 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
13544 | symbol_set_demangled_name (&(sym->ginfo), |
13545 | (char *) dwarf2_full_name (name, die, cu), | |
13546 | NULL); | |
f55ee35c | 13547 | |
c906108c | 13548 | /* Default assumptions. |
c5aa993b | 13549 | Use the passed type or decode it from the die. */ |
176620f1 | 13550 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 13551 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
13552 | if (type != NULL) |
13553 | SYMBOL_TYPE (sym) = type; | |
13554 | else | |
e7c27a73 | 13555 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
13556 | attr = dwarf2_attr (die, |
13557 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
13558 | cu); | |
c906108c SS |
13559 | if (attr) |
13560 | { | |
13561 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
13562 | } | |
cb1df416 | 13563 | |
edb3359d DJ |
13564 | attr = dwarf2_attr (die, |
13565 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
13566 | cu); | |
cb1df416 DJ |
13567 | if (attr) |
13568 | { | |
13569 | int file_index = DW_UNSND (attr); | |
9a619af0 | 13570 | |
cb1df416 DJ |
13571 | if (cu->line_header == NULL |
13572 | || file_index > cu->line_header->num_file_names) | |
13573 | complaint (&symfile_complaints, | |
13574 | _("file index out of range")); | |
1c3d648d | 13575 | else if (file_index > 0) |
cb1df416 DJ |
13576 | { |
13577 | struct file_entry *fe; | |
9a619af0 | 13578 | |
cb1df416 DJ |
13579 | fe = &cu->line_header->file_names[file_index - 1]; |
13580 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
13581 | } | |
13582 | } | |
13583 | ||
c906108c SS |
13584 | switch (die->tag) |
13585 | { | |
13586 | case DW_TAG_label: | |
e142c38c | 13587 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
13588 | if (attr) |
13589 | { | |
13590 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
13591 | } | |
0f5238ed TT |
13592 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
13593 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 13594 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 13595 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
13596 | break; |
13597 | case DW_TAG_subprogram: | |
13598 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
13599 | finish_block. */ | |
13600 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 13601 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
13602 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
13603 | || cu->language == language_ada) | |
c906108c | 13604 | { |
2cfa0c8d JB |
13605 | /* Subprograms marked external are stored as a global symbol. |
13606 | Ada subprograms, whether marked external or not, are always | |
13607 | stored as a global symbol, because we want to be able to | |
13608 | access them globally. For instance, we want to be able | |
13609 | to break on a nested subprogram without having to | |
13610 | specify the context. */ | |
e37fd15a | 13611 | list_to_add = &global_symbols; |
c906108c SS |
13612 | } |
13613 | else | |
13614 | { | |
e37fd15a | 13615 | list_to_add = cu->list_in_scope; |
c906108c SS |
13616 | } |
13617 | break; | |
edb3359d DJ |
13618 | case DW_TAG_inlined_subroutine: |
13619 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
13620 | finish_block. */ | |
13621 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
13622 | SYMBOL_INLINED (sym) = 1; | |
481860b3 | 13623 | list_to_add = cu->list_in_scope; |
edb3359d | 13624 | break; |
34eaf542 TT |
13625 | case DW_TAG_template_value_param: |
13626 | suppress_add = 1; | |
13627 | /* Fall through. */ | |
72929c62 | 13628 | case DW_TAG_constant: |
c906108c | 13629 | case DW_TAG_variable: |
254e6b9e | 13630 | case DW_TAG_member: |
0963b4bd MS |
13631 | /* Compilation with minimal debug info may result in |
13632 | variables with missing type entries. Change the | |
13633 | misleading `void' type to something sensible. */ | |
c906108c | 13634 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 13635 | SYMBOL_TYPE (sym) |
46bf5051 | 13636 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 13637 | |
e142c38c | 13638 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
13639 | /* In the case of DW_TAG_member, we should only be called for |
13640 | static const members. */ | |
13641 | if (die->tag == DW_TAG_member) | |
13642 | { | |
3863f96c DE |
13643 | /* dwarf2_add_field uses die_is_declaration, |
13644 | so we do the same. */ | |
254e6b9e DE |
13645 | gdb_assert (die_is_declaration (die, cu)); |
13646 | gdb_assert (attr); | |
13647 | } | |
c906108c SS |
13648 | if (attr) |
13649 | { | |
e7c27a73 | 13650 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 13651 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 13652 | if (!suppress_add) |
34eaf542 TT |
13653 | { |
13654 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 13655 | list_to_add = &global_symbols; |
34eaf542 | 13656 | else |
e37fd15a | 13657 | list_to_add = cu->list_in_scope; |
34eaf542 | 13658 | } |
c906108c SS |
13659 | break; |
13660 | } | |
e142c38c | 13661 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
13662 | if (attr) |
13663 | { | |
e7c27a73 | 13664 | var_decode_location (attr, sym, cu); |
e142c38c | 13665 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
13666 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
13667 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
13668 | && !dwarf2_per_objfile->has_section_at_zero) | |
13669 | { | |
13670 | /* When a static variable is eliminated by the linker, | |
13671 | the corresponding debug information is not stripped | |
13672 | out, but the variable address is set to null; | |
13673 | do not add such variables into symbol table. */ | |
13674 | } | |
13675 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 13676 | { |
f55ee35c JK |
13677 | /* Workaround gfortran PR debug/40040 - it uses |
13678 | DW_AT_location for variables in -fPIC libraries which may | |
13679 | get overriden by other libraries/executable and get | |
13680 | a different address. Resolve it by the minimal symbol | |
13681 | which may come from inferior's executable using copy | |
13682 | relocation. Make this workaround only for gfortran as for | |
13683 | other compilers GDB cannot guess the minimal symbol | |
13684 | Fortran mangling kind. */ | |
13685 | if (cu->language == language_fortran && die->parent | |
13686 | && die->parent->tag == DW_TAG_module | |
13687 | && cu->producer | |
13688 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
13689 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
13690 | ||
1c809c68 TT |
13691 | /* A variable with DW_AT_external is never static, |
13692 | but it may be block-scoped. */ | |
13693 | list_to_add = (cu->list_in_scope == &file_symbols | |
13694 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 13695 | } |
c906108c | 13696 | else |
e37fd15a | 13697 | list_to_add = cu->list_in_scope; |
c906108c SS |
13698 | } |
13699 | else | |
13700 | { | |
13701 | /* We do not know the address of this symbol. | |
c5aa993b JM |
13702 | If it is an external symbol and we have type information |
13703 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
13704 | The address of the variable will then be determined from | |
13705 | the minimal symbol table whenever the variable is | |
13706 | referenced. */ | |
e142c38c | 13707 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 13708 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 13709 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 13710 | { |
0fe7935b DJ |
13711 | /* A variable with DW_AT_external is never static, but it |
13712 | may be block-scoped. */ | |
13713 | list_to_add = (cu->list_in_scope == &file_symbols | |
13714 | ? &global_symbols : cu->list_in_scope); | |
13715 | ||
c906108c | 13716 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 13717 | } |
442ddf59 JK |
13718 | else if (!die_is_declaration (die, cu)) |
13719 | { | |
13720 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
13721 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
13722 | if (!suppress_add) |
13723 | list_to_add = cu->list_in_scope; | |
442ddf59 | 13724 | } |
c906108c SS |
13725 | } |
13726 | break; | |
13727 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
13728 | /* If we are inside a function, mark this as an argument. If |
13729 | not, we might be looking at an argument to an inlined function | |
13730 | when we do not have enough information to show inlined frames; | |
13731 | pretend it's a local variable in that case so that the user can | |
13732 | still see it. */ | |
13733 | if (context_stack_depth > 0 | |
13734 | && context_stack[context_stack_depth - 1].name != NULL) | |
13735 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 13736 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
13737 | if (attr) |
13738 | { | |
e7c27a73 | 13739 | var_decode_location (attr, sym, cu); |
c906108c | 13740 | } |
e142c38c | 13741 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
13742 | if (attr) |
13743 | { | |
e7c27a73 | 13744 | dwarf2_const_value (attr, sym, cu); |
c906108c | 13745 | } |
f346a30d | 13746 | |
e37fd15a | 13747 | list_to_add = cu->list_in_scope; |
c906108c SS |
13748 | break; |
13749 | case DW_TAG_unspecified_parameters: | |
13750 | /* From varargs functions; gdb doesn't seem to have any | |
13751 | interest in this information, so just ignore it for now. | |
13752 | (FIXME?) */ | |
13753 | break; | |
34eaf542 TT |
13754 | case DW_TAG_template_type_param: |
13755 | suppress_add = 1; | |
13756 | /* Fall through. */ | |
c906108c | 13757 | case DW_TAG_class_type: |
680b30c7 | 13758 | case DW_TAG_interface_type: |
c906108c SS |
13759 | case DW_TAG_structure_type: |
13760 | case DW_TAG_union_type: | |
72019c9c | 13761 | case DW_TAG_set_type: |
c906108c SS |
13762 | case DW_TAG_enumeration_type: |
13763 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 13764 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 13765 | |
63d06c5c | 13766 | { |
987504bb | 13767 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
13768 | really ever be static objects: otherwise, if you try |
13769 | to, say, break of a class's method and you're in a file | |
13770 | which doesn't mention that class, it won't work unless | |
13771 | the check for all static symbols in lookup_symbol_aux | |
13772 | saves you. See the OtherFileClass tests in | |
13773 | gdb.c++/namespace.exp. */ | |
13774 | ||
e37fd15a | 13775 | if (!suppress_add) |
34eaf542 | 13776 | { |
34eaf542 TT |
13777 | list_to_add = (cu->list_in_scope == &file_symbols |
13778 | && (cu->language == language_cplus | |
13779 | || cu->language == language_java) | |
13780 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 13781 | |
64382290 TT |
13782 | /* The semantics of C++ state that "struct foo { |
13783 | ... }" also defines a typedef for "foo". A Java | |
13784 | class declaration also defines a typedef for the | |
13785 | class. */ | |
13786 | if (cu->language == language_cplus | |
13787 | || cu->language == language_java | |
13788 | || cu->language == language_ada) | |
13789 | { | |
13790 | /* The symbol's name is already allocated along | |
13791 | with this objfile, so we don't need to | |
13792 | duplicate it for the type. */ | |
13793 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
13794 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
13795 | } | |
63d06c5c DC |
13796 | } |
13797 | } | |
c906108c SS |
13798 | break; |
13799 | case DW_TAG_typedef: | |
63d06c5c DC |
13800 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
13801 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 13802 | list_to_add = cu->list_in_scope; |
63d06c5c | 13803 | break; |
c906108c | 13804 | case DW_TAG_base_type: |
a02abb62 | 13805 | case DW_TAG_subrange_type: |
c906108c | 13806 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 13807 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 13808 | list_to_add = cu->list_in_scope; |
c906108c SS |
13809 | break; |
13810 | case DW_TAG_enumerator: | |
e142c38c | 13811 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
13812 | if (attr) |
13813 | { | |
e7c27a73 | 13814 | dwarf2_const_value (attr, sym, cu); |
c906108c | 13815 | } |
63d06c5c DC |
13816 | { |
13817 | /* NOTE: carlton/2003-11-10: See comment above in the | |
13818 | DW_TAG_class_type, etc. block. */ | |
13819 | ||
e142c38c | 13820 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
13821 | && (cu->language == language_cplus |
13822 | || cu->language == language_java) | |
e142c38c | 13823 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 13824 | } |
c906108c | 13825 | break; |
5c4e30ca DC |
13826 | case DW_TAG_namespace: |
13827 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 13828 | list_to_add = &global_symbols; |
5c4e30ca | 13829 | break; |
c906108c SS |
13830 | default: |
13831 | /* Not a tag we recognize. Hopefully we aren't processing | |
13832 | trash data, but since we must specifically ignore things | |
13833 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 13834 | this point. */ |
e2e0b3e5 | 13835 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 13836 | dwarf_tag_name (die->tag)); |
c906108c SS |
13837 | break; |
13838 | } | |
df8a16a1 | 13839 | |
e37fd15a SW |
13840 | if (suppress_add) |
13841 | { | |
13842 | sym->hash_next = objfile->template_symbols; | |
13843 | objfile->template_symbols = sym; | |
13844 | list_to_add = NULL; | |
13845 | } | |
13846 | ||
13847 | if (list_to_add != NULL) | |
13848 | add_symbol_to_list (sym, list_to_add); | |
13849 | ||
df8a16a1 DJ |
13850 | /* For the benefit of old versions of GCC, check for anonymous |
13851 | namespaces based on the demangled name. */ | |
13852 | if (!processing_has_namespace_info | |
94af9270 | 13853 | && cu->language == language_cplus) |
a10964d1 | 13854 | cp_scan_for_anonymous_namespaces (sym, objfile); |
c906108c SS |
13855 | } |
13856 | return (sym); | |
13857 | } | |
13858 | ||
34eaf542 TT |
13859 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
13860 | ||
13861 | static struct symbol * | |
13862 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
13863 | { | |
13864 | return new_symbol_full (die, type, cu, NULL); | |
13865 | } | |
13866 | ||
98bfdba5 PA |
13867 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
13868 | zero-extend it as appropriate for the symbol's type. The DWARF | |
13869 | standard (v4) is not entirely clear about the meaning of using | |
13870 | DW_FORM_dataN for a constant with a signed type, where the type is | |
13871 | wider than the data. The conclusion of a discussion on the DWARF | |
13872 | list was that this is unspecified. We choose to always zero-extend | |
13873 | because that is the interpretation long in use by GCC. */ | |
c906108c | 13874 | |
98bfdba5 PA |
13875 | static gdb_byte * |
13876 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
13877 | const char *name, struct obstack *obstack, | |
12df843f | 13878 | struct dwarf2_cu *cu, LONGEST *value, int bits) |
c906108c | 13879 | { |
e7c27a73 | 13880 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
13881 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
13882 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
13883 | LONGEST l = DW_UNSND (attr); |
13884 | ||
13885 | if (bits < sizeof (*value) * 8) | |
13886 | { | |
13887 | l &= ((LONGEST) 1 << bits) - 1; | |
13888 | *value = l; | |
13889 | } | |
13890 | else if (bits == sizeof (*value) * 8) | |
13891 | *value = l; | |
13892 | else | |
13893 | { | |
13894 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
13895 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
13896 | return bytes; | |
13897 | } | |
13898 | ||
13899 | return NULL; | |
13900 | } | |
13901 | ||
13902 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
13903 | the value does not fit in *VALUE, set *BYTES - either already | |
13904 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
13905 | or, set *BATON, if we translated the constant to a location | |
13906 | expression. */ | |
13907 | ||
13908 | static void | |
13909 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
13910 | const char *name, struct obstack *obstack, | |
13911 | struct dwarf2_cu *cu, | |
12df843f | 13912 | LONGEST *value, gdb_byte **bytes, |
98bfdba5 PA |
13913 | struct dwarf2_locexpr_baton **baton) |
13914 | { | |
13915 | struct objfile *objfile = cu->objfile; | |
13916 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 13917 | struct dwarf_block *blk; |
98bfdba5 PA |
13918 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
13919 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
13920 | ||
13921 | *value = 0; | |
13922 | *bytes = NULL; | |
13923 | *baton = NULL; | |
c906108c SS |
13924 | |
13925 | switch (attr->form) | |
13926 | { | |
13927 | case DW_FORM_addr: | |
3019eac3 | 13928 | case DW_FORM_GNU_addr_index: |
ac56253d | 13929 | { |
ac56253d TT |
13930 | gdb_byte *data; |
13931 | ||
98bfdba5 PA |
13932 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
13933 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 13934 | cu_header->addr_size, |
98bfdba5 | 13935 | TYPE_LENGTH (type)); |
ac56253d TT |
13936 | /* Symbols of this form are reasonably rare, so we just |
13937 | piggyback on the existing location code rather than writing | |
13938 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
13939 | *baton = obstack_alloc (&objfile->objfile_obstack, |
13940 | sizeof (struct dwarf2_locexpr_baton)); | |
13941 | (*baton)->per_cu = cu->per_cu; | |
13942 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 13943 | |
98bfdba5 PA |
13944 | (*baton)->size = 2 + cu_header->addr_size; |
13945 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
13946 | (*baton)->data = data; | |
ac56253d TT |
13947 | |
13948 | data[0] = DW_OP_addr; | |
13949 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
13950 | byte_order, DW_ADDR (attr)); | |
13951 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 13952 | } |
c906108c | 13953 | break; |
4ac36638 | 13954 | case DW_FORM_string: |
93b5768b | 13955 | case DW_FORM_strp: |
3019eac3 | 13956 | case DW_FORM_GNU_str_index: |
98bfdba5 PA |
13957 | /* DW_STRING is already allocated on the objfile obstack, point |
13958 | directly to it. */ | |
13959 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 13960 | break; |
c906108c SS |
13961 | case DW_FORM_block1: |
13962 | case DW_FORM_block2: | |
13963 | case DW_FORM_block4: | |
13964 | case DW_FORM_block: | |
2dc7f7b3 | 13965 | case DW_FORM_exprloc: |
c906108c | 13966 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
13967 | if (TYPE_LENGTH (type) != blk->size) |
13968 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
13969 | TYPE_LENGTH (type)); | |
13970 | *bytes = blk->data; | |
c906108c | 13971 | break; |
2df3850c JM |
13972 | |
13973 | /* The DW_AT_const_value attributes are supposed to carry the | |
13974 | symbol's value "represented as it would be on the target | |
13975 | architecture." By the time we get here, it's already been | |
13976 | converted to host endianness, so we just need to sign- or | |
13977 | zero-extend it as appropriate. */ | |
13978 | case DW_FORM_data1: | |
3e43a32a MS |
13979 | *bytes = dwarf2_const_value_data (attr, type, name, |
13980 | obstack, cu, value, 8); | |
2df3850c | 13981 | break; |
c906108c | 13982 | case DW_FORM_data2: |
3e43a32a MS |
13983 | *bytes = dwarf2_const_value_data (attr, type, name, |
13984 | obstack, cu, value, 16); | |
2df3850c | 13985 | break; |
c906108c | 13986 | case DW_FORM_data4: |
3e43a32a MS |
13987 | *bytes = dwarf2_const_value_data (attr, type, name, |
13988 | obstack, cu, value, 32); | |
2df3850c | 13989 | break; |
c906108c | 13990 | case DW_FORM_data8: |
3e43a32a MS |
13991 | *bytes = dwarf2_const_value_data (attr, type, name, |
13992 | obstack, cu, value, 64); | |
2df3850c JM |
13993 | break; |
13994 | ||
c906108c | 13995 | case DW_FORM_sdata: |
98bfdba5 | 13996 | *value = DW_SND (attr); |
2df3850c JM |
13997 | break; |
13998 | ||
c906108c | 13999 | case DW_FORM_udata: |
98bfdba5 | 14000 | *value = DW_UNSND (attr); |
c906108c | 14001 | break; |
2df3850c | 14002 | |
c906108c | 14003 | default: |
4d3c2250 | 14004 | complaint (&symfile_complaints, |
e2e0b3e5 | 14005 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 14006 | dwarf_form_name (attr->form)); |
98bfdba5 | 14007 | *value = 0; |
c906108c SS |
14008 | break; |
14009 | } | |
14010 | } | |
14011 | ||
2df3850c | 14012 | |
98bfdba5 PA |
14013 | /* Copy constant value from an attribute to a symbol. */ |
14014 | ||
2df3850c | 14015 | static void |
98bfdba5 PA |
14016 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
14017 | struct dwarf2_cu *cu) | |
2df3850c | 14018 | { |
98bfdba5 PA |
14019 | struct objfile *objfile = cu->objfile; |
14020 | struct comp_unit_head *cu_header = &cu->header; | |
12df843f | 14021 | LONGEST value; |
98bfdba5 PA |
14022 | gdb_byte *bytes; |
14023 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 14024 | |
98bfdba5 PA |
14025 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
14026 | SYMBOL_PRINT_NAME (sym), | |
14027 | &objfile->objfile_obstack, cu, | |
14028 | &value, &bytes, &baton); | |
2df3850c | 14029 | |
98bfdba5 PA |
14030 | if (baton != NULL) |
14031 | { | |
14032 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
14033 | SYMBOL_LOCATION_BATON (sym) = baton; | |
14034 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
14035 | } | |
14036 | else if (bytes != NULL) | |
14037 | { | |
14038 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
14039 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
14040 | } | |
14041 | else | |
14042 | { | |
14043 | SYMBOL_VALUE (sym) = value; | |
14044 | SYMBOL_CLASS (sym) = LOC_CONST; | |
14045 | } | |
2df3850c JM |
14046 | } |
14047 | ||
c906108c SS |
14048 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
14049 | ||
14050 | static struct type * | |
e7c27a73 | 14051 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14052 | { |
c906108c | 14053 | struct attribute *type_attr; |
c906108c | 14054 | |
e142c38c | 14055 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
14056 | if (!type_attr) |
14057 | { | |
14058 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 14059 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 14060 | } |
348e048f | 14061 | |
673bfd45 | 14062 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
14063 | } |
14064 | ||
b4ba55a1 JB |
14065 | /* True iff CU's producer generates GNAT Ada auxiliary information |
14066 | that allows to find parallel types through that information instead | |
14067 | of having to do expensive parallel lookups by type name. */ | |
14068 | ||
14069 | static int | |
14070 | need_gnat_info (struct dwarf2_cu *cu) | |
14071 | { | |
14072 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
14073 | of GNAT produces this auxiliary information, without any indication | |
14074 | that it is produced. Part of enhancing the FSF version of GNAT | |
14075 | to produce that information will be to put in place an indicator | |
14076 | that we can use in order to determine whether the descriptive type | |
14077 | info is available or not. One suggestion that has been made is | |
14078 | to use a new attribute, attached to the CU die. For now, assume | |
14079 | that the descriptive type info is not available. */ | |
14080 | return 0; | |
14081 | } | |
14082 | ||
b4ba55a1 JB |
14083 | /* Return the auxiliary type of the die in question using its |
14084 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
14085 | attribute is not present. */ | |
14086 | ||
14087 | static struct type * | |
14088 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
14089 | { | |
b4ba55a1 | 14090 | struct attribute *type_attr; |
b4ba55a1 JB |
14091 | |
14092 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
14093 | if (!type_attr) | |
14094 | return NULL; | |
14095 | ||
673bfd45 | 14096 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
14097 | } |
14098 | ||
14099 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
14100 | descriptive type accordingly. */ | |
14101 | ||
14102 | static void | |
14103 | set_descriptive_type (struct type *type, struct die_info *die, | |
14104 | struct dwarf2_cu *cu) | |
14105 | { | |
14106 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
14107 | ||
14108 | if (descriptive_type) | |
14109 | { | |
14110 | ALLOCATE_GNAT_AUX_TYPE (type); | |
14111 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
14112 | } | |
14113 | } | |
14114 | ||
c906108c SS |
14115 | /* Return the containing type of the die in question using its |
14116 | DW_AT_containing_type attribute. */ | |
14117 | ||
14118 | static struct type * | |
e7c27a73 | 14119 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14120 | { |
c906108c | 14121 | struct attribute *type_attr; |
c906108c | 14122 | |
e142c38c | 14123 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
14124 | if (!type_attr) |
14125 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
14126 | "[in module %s]"), cu->objfile->name); | |
14127 | ||
673bfd45 | 14128 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
14129 | } |
14130 | ||
673bfd45 DE |
14131 | /* Look up the type of DIE in CU using its type attribute ATTR. |
14132 | If there is no type substitute an error marker. */ | |
14133 | ||
c906108c | 14134 | static struct type * |
673bfd45 DE |
14135 | lookup_die_type (struct die_info *die, struct attribute *attr, |
14136 | struct dwarf2_cu *cu) | |
c906108c | 14137 | { |
bb5ed363 | 14138 | struct objfile *objfile = cu->objfile; |
f792889a DJ |
14139 | struct type *this_type; |
14140 | ||
673bfd45 DE |
14141 | /* First see if we have it cached. */ |
14142 | ||
14143 | if (is_ref_attr (attr)) | |
14144 | { | |
b64f50a1 | 14145 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
673bfd45 DE |
14146 | |
14147 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
14148 | } | |
55f1336d | 14149 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
14150 | { |
14151 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
673bfd45 DE |
14152 | |
14153 | /* sig_type will be NULL if the signatured type is missing from | |
14154 | the debug info. */ | |
14155 | if (sig_type == NULL) | |
14156 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
14157 | "at 0x%x [in module %s]"), | |
b64f50a1 | 14158 | die->offset.sect_off, objfile->name); |
673bfd45 | 14159 | |
3019eac3 DE |
14160 | gdb_assert (sig_type->per_cu.is_debug_types); |
14161 | /* If we haven't filled in type_offset_in_section yet, then we | |
14162 | haven't read the type in yet. */ | |
14163 | this_type = NULL; | |
14164 | if (sig_type->type_offset_in_section.sect_off != 0) | |
14165 | { | |
14166 | this_type = | |
14167 | get_die_type_at_offset (sig_type->type_offset_in_section, | |
14168 | &sig_type->per_cu); | |
14169 | } | |
673bfd45 DE |
14170 | } |
14171 | else | |
14172 | { | |
14173 | dump_die_for_error (die); | |
14174 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
bb5ed363 | 14175 | dwarf_attr_name (attr->name), objfile->name); |
673bfd45 DE |
14176 | } |
14177 | ||
14178 | /* If not cached we need to read it in. */ | |
14179 | ||
14180 | if (this_type == NULL) | |
14181 | { | |
14182 | struct die_info *type_die; | |
14183 | struct dwarf2_cu *type_cu = cu; | |
14184 | ||
14185 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
3019eac3 DE |
14186 | /* If we found the type now, it's probably because the type came |
14187 | from an inter-CU reference and the type's CU got expanded before | |
14188 | ours. */ | |
14189 | this_type = get_die_type (type_die, type_cu); | |
14190 | if (this_type == NULL) | |
14191 | this_type = read_type_die_1 (type_die, type_cu); | |
673bfd45 DE |
14192 | } |
14193 | ||
14194 | /* If we still don't have a type use an error marker. */ | |
14195 | ||
14196 | if (this_type == NULL) | |
c906108c | 14197 | { |
b00fdb78 TT |
14198 | char *message, *saved; |
14199 | ||
14200 | /* read_type_die already issued a complaint. */ | |
14201 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
bb5ed363 | 14202 | objfile->name, |
b64f50a1 JK |
14203 | cu->header.offset.sect_off, |
14204 | die->offset.sect_off); | |
bb5ed363 | 14205 | saved = obstack_copy0 (&objfile->objfile_obstack, |
b00fdb78 TT |
14206 | message, strlen (message)); |
14207 | xfree (message); | |
14208 | ||
bb5ed363 | 14209 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile); |
c906108c | 14210 | } |
673bfd45 | 14211 | |
f792889a | 14212 | return this_type; |
c906108c SS |
14213 | } |
14214 | ||
673bfd45 DE |
14215 | /* Return the type in DIE, CU. |
14216 | Returns NULL for invalid types. | |
14217 | ||
14218 | This first does a lookup in the appropriate type_hash table, | |
14219 | and only reads the die in if necessary. | |
14220 | ||
14221 | NOTE: This can be called when reading in partial or full symbols. */ | |
14222 | ||
f792889a | 14223 | static struct type * |
e7c27a73 | 14224 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14225 | { |
f792889a DJ |
14226 | struct type *this_type; |
14227 | ||
14228 | this_type = get_die_type (die, cu); | |
14229 | if (this_type) | |
14230 | return this_type; | |
14231 | ||
673bfd45 DE |
14232 | return read_type_die_1 (die, cu); |
14233 | } | |
14234 | ||
14235 | /* Read the type in DIE, CU. | |
14236 | Returns NULL for invalid types. */ | |
14237 | ||
14238 | static struct type * | |
14239 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
14240 | { | |
14241 | struct type *this_type = NULL; | |
14242 | ||
c906108c SS |
14243 | switch (die->tag) |
14244 | { | |
14245 | case DW_TAG_class_type: | |
680b30c7 | 14246 | case DW_TAG_interface_type: |
c906108c SS |
14247 | case DW_TAG_structure_type: |
14248 | case DW_TAG_union_type: | |
f792889a | 14249 | this_type = read_structure_type (die, cu); |
c906108c SS |
14250 | break; |
14251 | case DW_TAG_enumeration_type: | |
f792889a | 14252 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
14253 | break; |
14254 | case DW_TAG_subprogram: | |
14255 | case DW_TAG_subroutine_type: | |
edb3359d | 14256 | case DW_TAG_inlined_subroutine: |
f792889a | 14257 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
14258 | break; |
14259 | case DW_TAG_array_type: | |
f792889a | 14260 | this_type = read_array_type (die, cu); |
c906108c | 14261 | break; |
72019c9c | 14262 | case DW_TAG_set_type: |
f792889a | 14263 | this_type = read_set_type (die, cu); |
72019c9c | 14264 | break; |
c906108c | 14265 | case DW_TAG_pointer_type: |
f792889a | 14266 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
14267 | break; |
14268 | case DW_TAG_ptr_to_member_type: | |
f792889a | 14269 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
14270 | break; |
14271 | case DW_TAG_reference_type: | |
f792889a | 14272 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
14273 | break; |
14274 | case DW_TAG_const_type: | |
f792889a | 14275 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
14276 | break; |
14277 | case DW_TAG_volatile_type: | |
f792889a | 14278 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
14279 | break; |
14280 | case DW_TAG_string_type: | |
f792889a | 14281 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
14282 | break; |
14283 | case DW_TAG_typedef: | |
f792889a | 14284 | this_type = read_typedef (die, cu); |
c906108c | 14285 | break; |
a02abb62 | 14286 | case DW_TAG_subrange_type: |
f792889a | 14287 | this_type = read_subrange_type (die, cu); |
a02abb62 | 14288 | break; |
c906108c | 14289 | case DW_TAG_base_type: |
f792889a | 14290 | this_type = read_base_type (die, cu); |
c906108c | 14291 | break; |
81a17f79 | 14292 | case DW_TAG_unspecified_type: |
f792889a | 14293 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 14294 | break; |
0114d602 DJ |
14295 | case DW_TAG_namespace: |
14296 | this_type = read_namespace_type (die, cu); | |
14297 | break; | |
f55ee35c JK |
14298 | case DW_TAG_module: |
14299 | this_type = read_module_type (die, cu); | |
14300 | break; | |
c906108c | 14301 | default: |
3e43a32a MS |
14302 | complaint (&symfile_complaints, |
14303 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 14304 | dwarf_tag_name (die->tag)); |
c906108c SS |
14305 | break; |
14306 | } | |
63d06c5c | 14307 | |
f792889a | 14308 | return this_type; |
63d06c5c DC |
14309 | } |
14310 | ||
abc72ce4 DE |
14311 | /* See if we can figure out if the class lives in a namespace. We do |
14312 | this by looking for a member function; its demangled name will | |
14313 | contain namespace info, if there is any. | |
14314 | Return the computed name or NULL. | |
14315 | Space for the result is allocated on the objfile's obstack. | |
14316 | This is the full-die version of guess_partial_die_structure_name. | |
14317 | In this case we know DIE has no useful parent. */ | |
14318 | ||
14319 | static char * | |
14320 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
14321 | { | |
14322 | struct die_info *spec_die; | |
14323 | struct dwarf2_cu *spec_cu; | |
14324 | struct die_info *child; | |
14325 | ||
14326 | spec_cu = cu; | |
14327 | spec_die = die_specification (die, &spec_cu); | |
14328 | if (spec_die != NULL) | |
14329 | { | |
14330 | die = spec_die; | |
14331 | cu = spec_cu; | |
14332 | } | |
14333 | ||
14334 | for (child = die->child; | |
14335 | child != NULL; | |
14336 | child = child->sibling) | |
14337 | { | |
14338 | if (child->tag == DW_TAG_subprogram) | |
14339 | { | |
14340 | struct attribute *attr; | |
14341 | ||
14342 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
14343 | if (attr == NULL) | |
14344 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
14345 | if (attr != NULL) | |
14346 | { | |
14347 | char *actual_name | |
14348 | = language_class_name_from_physname (cu->language_defn, | |
14349 | DW_STRING (attr)); | |
14350 | char *name = NULL; | |
14351 | ||
14352 | if (actual_name != NULL) | |
14353 | { | |
14354 | char *die_name = dwarf2_name (die, cu); | |
14355 | ||
14356 | if (die_name != NULL | |
14357 | && strcmp (die_name, actual_name) != 0) | |
14358 | { | |
14359 | /* Strip off the class name from the full name. | |
14360 | We want the prefix. */ | |
14361 | int die_name_len = strlen (die_name); | |
14362 | int actual_name_len = strlen (actual_name); | |
14363 | ||
14364 | /* Test for '::' as a sanity check. */ | |
14365 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
14366 | && actual_name[actual_name_len |
14367 | - die_name_len - 1] == ':') | |
abc72ce4 DE |
14368 | name = |
14369 | obsavestring (actual_name, | |
14370 | actual_name_len - die_name_len - 2, | |
14371 | &cu->objfile->objfile_obstack); | |
14372 | } | |
14373 | } | |
14374 | xfree (actual_name); | |
14375 | return name; | |
14376 | } | |
14377 | } | |
14378 | } | |
14379 | ||
14380 | return NULL; | |
14381 | } | |
14382 | ||
96408a79 SA |
14383 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
14384 | prefix part in such case. See | |
14385 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
14386 | ||
14387 | static char * | |
14388 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) | |
14389 | { | |
14390 | struct attribute *attr; | |
14391 | char *base; | |
14392 | ||
14393 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type | |
14394 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) | |
14395 | return NULL; | |
14396 | ||
14397 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
14398 | if (attr != NULL && DW_STRING (attr) != NULL) | |
14399 | return NULL; | |
14400 | ||
14401 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
14402 | if (attr == NULL) | |
14403 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
14404 | if (attr == NULL || DW_STRING (attr) == NULL) | |
14405 | return NULL; | |
14406 | ||
14407 | /* dwarf2_name had to be already called. */ | |
14408 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); | |
14409 | ||
14410 | /* Strip the base name, keep any leading namespaces/classes. */ | |
14411 | base = strrchr (DW_STRING (attr), ':'); | |
14412 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') | |
14413 | return ""; | |
14414 | ||
14415 | return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr), | |
14416 | &cu->objfile->objfile_obstack); | |
14417 | } | |
14418 | ||
fdde2d81 | 14419 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 14420 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 14421 | |
0114d602 DJ |
14422 | For example, if we're within the method foo() in the following |
14423 | code: | |
14424 | ||
14425 | namespace N { | |
14426 | class C { | |
14427 | void foo () { | |
14428 | } | |
14429 | }; | |
14430 | } | |
14431 | ||
14432 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 | 14433 | |
0d5cff50 | 14434 | static const char * |
e142c38c | 14435 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 14436 | { |
0114d602 DJ |
14437 | struct die_info *parent, *spec_die; |
14438 | struct dwarf2_cu *spec_cu; | |
14439 | struct type *parent_type; | |
96408a79 | 14440 | char *retval; |
63d06c5c | 14441 | |
f55ee35c JK |
14442 | if (cu->language != language_cplus && cu->language != language_java |
14443 | && cu->language != language_fortran) | |
0114d602 DJ |
14444 | return ""; |
14445 | ||
96408a79 SA |
14446 | retval = anonymous_struct_prefix (die, cu); |
14447 | if (retval) | |
14448 | return retval; | |
14449 | ||
0114d602 DJ |
14450 | /* We have to be careful in the presence of DW_AT_specification. |
14451 | For example, with GCC 3.4, given the code | |
14452 | ||
14453 | namespace N { | |
14454 | void foo() { | |
14455 | // Definition of N::foo. | |
14456 | } | |
14457 | } | |
14458 | ||
14459 | then we'll have a tree of DIEs like this: | |
14460 | ||
14461 | 1: DW_TAG_compile_unit | |
14462 | 2: DW_TAG_namespace // N | |
14463 | 3: DW_TAG_subprogram // declaration of N::foo | |
14464 | 4: DW_TAG_subprogram // definition of N::foo | |
14465 | DW_AT_specification // refers to die #3 | |
14466 | ||
14467 | Thus, when processing die #4, we have to pretend that we're in | |
14468 | the context of its DW_AT_specification, namely the contex of die | |
14469 | #3. */ | |
14470 | spec_cu = cu; | |
14471 | spec_die = die_specification (die, &spec_cu); | |
14472 | if (spec_die == NULL) | |
14473 | parent = die->parent; | |
14474 | else | |
63d06c5c | 14475 | { |
0114d602 DJ |
14476 | parent = spec_die->parent; |
14477 | cu = spec_cu; | |
63d06c5c | 14478 | } |
0114d602 DJ |
14479 | |
14480 | if (parent == NULL) | |
14481 | return ""; | |
98bfdba5 PA |
14482 | else if (parent->building_fullname) |
14483 | { | |
14484 | const char *name; | |
14485 | const char *parent_name; | |
14486 | ||
14487 | /* It has been seen on RealView 2.2 built binaries, | |
14488 | DW_TAG_template_type_param types actually _defined_ as | |
14489 | children of the parent class: | |
14490 | ||
14491 | enum E {}; | |
14492 | template class <class Enum> Class{}; | |
14493 | Class<enum E> class_e; | |
14494 | ||
14495 | 1: DW_TAG_class_type (Class) | |
14496 | 2: DW_TAG_enumeration_type (E) | |
14497 | 3: DW_TAG_enumerator (enum1:0) | |
14498 | 3: DW_TAG_enumerator (enum2:1) | |
14499 | ... | |
14500 | 2: DW_TAG_template_type_param | |
14501 | DW_AT_type DW_FORM_ref_udata (E) | |
14502 | ||
14503 | Besides being broken debug info, it can put GDB into an | |
14504 | infinite loop. Consider: | |
14505 | ||
14506 | When we're building the full name for Class<E>, we'll start | |
14507 | at Class, and go look over its template type parameters, | |
14508 | finding E. We'll then try to build the full name of E, and | |
14509 | reach here. We're now trying to build the full name of E, | |
14510 | and look over the parent DIE for containing scope. In the | |
14511 | broken case, if we followed the parent DIE of E, we'd again | |
14512 | find Class, and once again go look at its template type | |
14513 | arguments, etc., etc. Simply don't consider such parent die | |
14514 | as source-level parent of this die (it can't be, the language | |
14515 | doesn't allow it), and break the loop here. */ | |
14516 | name = dwarf2_name (die, cu); | |
14517 | parent_name = dwarf2_name (parent, cu); | |
14518 | complaint (&symfile_complaints, | |
14519 | _("template param type '%s' defined within parent '%s'"), | |
14520 | name ? name : "<unknown>", | |
14521 | parent_name ? parent_name : "<unknown>"); | |
14522 | return ""; | |
14523 | } | |
63d06c5c | 14524 | else |
0114d602 DJ |
14525 | switch (parent->tag) |
14526 | { | |
63d06c5c | 14527 | case DW_TAG_namespace: |
0114d602 | 14528 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
14529 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
14530 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
14531 | Work around this problem here. */ | |
14532 | if (cu->language == language_cplus | |
14533 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
14534 | return ""; | |
0114d602 DJ |
14535 | /* We give a name to even anonymous namespaces. */ |
14536 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 14537 | case DW_TAG_class_type: |
680b30c7 | 14538 | case DW_TAG_interface_type: |
63d06c5c | 14539 | case DW_TAG_structure_type: |
0114d602 | 14540 | case DW_TAG_union_type: |
f55ee35c | 14541 | case DW_TAG_module: |
0114d602 DJ |
14542 | parent_type = read_type_die (parent, cu); |
14543 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
14544 | return TYPE_TAG_NAME (parent_type); | |
14545 | else | |
14546 | /* An anonymous structure is only allowed non-static data | |
14547 | members; no typedefs, no member functions, et cetera. | |
14548 | So it does not need a prefix. */ | |
14549 | return ""; | |
abc72ce4 | 14550 | case DW_TAG_compile_unit: |
95554aad | 14551 | case DW_TAG_partial_unit: |
abc72ce4 DE |
14552 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ |
14553 | if (cu->language == language_cplus | |
8b70b953 | 14554 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
14555 | && die->child != NULL |
14556 | && (die->tag == DW_TAG_class_type | |
14557 | || die->tag == DW_TAG_structure_type | |
14558 | || die->tag == DW_TAG_union_type)) | |
14559 | { | |
14560 | char *name = guess_full_die_structure_name (die, cu); | |
14561 | if (name != NULL) | |
14562 | return name; | |
14563 | } | |
14564 | return ""; | |
63d06c5c | 14565 | default: |
8176b9b8 | 14566 | return determine_prefix (parent, cu); |
63d06c5c | 14567 | } |
63d06c5c DC |
14568 | } |
14569 | ||
3e43a32a MS |
14570 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
14571 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
14572 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
14573 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
14574 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 14575 | |
f55ee35c | 14576 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
14577 | |
14578 | static char * | |
f55ee35c JK |
14579 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
14580 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 14581 | { |
f55ee35c | 14582 | const char *lead = ""; |
5c315b68 | 14583 | const char *sep; |
63d06c5c | 14584 | |
3e43a32a MS |
14585 | if (suffix == NULL || suffix[0] == '\0' |
14586 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
14587 | sep = ""; |
14588 | else if (cu->language == language_java) | |
14589 | sep = "."; | |
f55ee35c JK |
14590 | else if (cu->language == language_fortran && physname) |
14591 | { | |
14592 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
14593 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
14594 | ||
14595 | lead = "__"; | |
14596 | sep = "_MOD_"; | |
14597 | } | |
987504bb JJ |
14598 | else |
14599 | sep = "::"; | |
63d06c5c | 14600 | |
6dd47d34 DE |
14601 | if (prefix == NULL) |
14602 | prefix = ""; | |
14603 | if (suffix == NULL) | |
14604 | suffix = ""; | |
14605 | ||
987504bb JJ |
14606 | if (obs == NULL) |
14607 | { | |
3e43a32a MS |
14608 | char *retval |
14609 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 14610 | |
f55ee35c JK |
14611 | strcpy (retval, lead); |
14612 | strcat (retval, prefix); | |
6dd47d34 DE |
14613 | strcat (retval, sep); |
14614 | strcat (retval, suffix); | |
63d06c5c DC |
14615 | return retval; |
14616 | } | |
987504bb JJ |
14617 | else |
14618 | { | |
14619 | /* We have an obstack. */ | |
f55ee35c | 14620 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 14621 | } |
63d06c5c DC |
14622 | } |
14623 | ||
c906108c SS |
14624 | /* Return sibling of die, NULL if no sibling. */ |
14625 | ||
f9aca02d | 14626 | static struct die_info * |
fba45db2 | 14627 | sibling_die (struct die_info *die) |
c906108c | 14628 | { |
639d11d3 | 14629 | return die->sibling; |
c906108c SS |
14630 | } |
14631 | ||
71c25dea TT |
14632 | /* Get name of a die, return NULL if not found. */ |
14633 | ||
14634 | static char * | |
14635 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
14636 | struct obstack *obstack) | |
14637 | { | |
14638 | if (name && cu->language == language_cplus) | |
14639 | { | |
14640 | char *canon_name = cp_canonicalize_string (name); | |
14641 | ||
14642 | if (canon_name != NULL) | |
14643 | { | |
14644 | if (strcmp (canon_name, name) != 0) | |
14645 | name = obsavestring (canon_name, strlen (canon_name), | |
14646 | obstack); | |
14647 | xfree (canon_name); | |
14648 | } | |
14649 | } | |
14650 | ||
14651 | return name; | |
c906108c SS |
14652 | } |
14653 | ||
9219021c DC |
14654 | /* Get name of a die, return NULL if not found. */ |
14655 | ||
14656 | static char * | |
e142c38c | 14657 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
14658 | { |
14659 | struct attribute *attr; | |
14660 | ||
e142c38c | 14661 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
14662 | if ((!attr || !DW_STRING (attr)) |
14663 | && die->tag != DW_TAG_class_type | |
14664 | && die->tag != DW_TAG_interface_type | |
14665 | && die->tag != DW_TAG_structure_type | |
14666 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
14667 | return NULL; |
14668 | ||
14669 | switch (die->tag) | |
14670 | { | |
14671 | case DW_TAG_compile_unit: | |
95554aad | 14672 | case DW_TAG_partial_unit: |
71c25dea TT |
14673 | /* Compilation units have a DW_AT_name that is a filename, not |
14674 | a source language identifier. */ | |
14675 | case DW_TAG_enumeration_type: | |
14676 | case DW_TAG_enumerator: | |
14677 | /* These tags always have simple identifiers already; no need | |
14678 | to canonicalize them. */ | |
14679 | return DW_STRING (attr); | |
907af001 | 14680 | |
418835cc KS |
14681 | case DW_TAG_subprogram: |
14682 | /* Java constructors will all be named "<init>", so return | |
14683 | the class name when we see this special case. */ | |
14684 | if (cu->language == language_java | |
14685 | && DW_STRING (attr) != NULL | |
14686 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
14687 | { | |
14688 | struct dwarf2_cu *spec_cu = cu; | |
14689 | struct die_info *spec_die; | |
14690 | ||
14691 | /* GCJ will output '<init>' for Java constructor names. | |
14692 | For this special case, return the name of the parent class. */ | |
14693 | ||
14694 | /* GCJ may output suprogram DIEs with AT_specification set. | |
14695 | If so, use the name of the specified DIE. */ | |
14696 | spec_die = die_specification (die, &spec_cu); | |
14697 | if (spec_die != NULL) | |
14698 | return dwarf2_name (spec_die, spec_cu); | |
14699 | ||
14700 | do | |
14701 | { | |
14702 | die = die->parent; | |
14703 | if (die->tag == DW_TAG_class_type) | |
14704 | return dwarf2_name (die, cu); | |
14705 | } | |
95554aad TT |
14706 | while (die->tag != DW_TAG_compile_unit |
14707 | && die->tag != DW_TAG_partial_unit); | |
418835cc | 14708 | } |
907af001 UW |
14709 | break; |
14710 | ||
14711 | case DW_TAG_class_type: | |
14712 | case DW_TAG_interface_type: | |
14713 | case DW_TAG_structure_type: | |
14714 | case DW_TAG_union_type: | |
14715 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
14716 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
14717 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
14718 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
14719 | if (attr && DW_STRING (attr) |
14720 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
14721 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 14722 | return NULL; |
53832f31 TT |
14723 | |
14724 | /* GCC might emit a nameless typedef that has a linkage name. See | |
14725 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
14726 | if (!attr || DW_STRING (attr) == NULL) | |
14727 | { | |
df5c6c50 | 14728 | char *demangled = NULL; |
53832f31 TT |
14729 | |
14730 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
14731 | if (attr == NULL) | |
14732 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
14733 | ||
14734 | if (attr == NULL || DW_STRING (attr) == NULL) | |
14735 | return NULL; | |
14736 | ||
df5c6c50 JK |
14737 | /* Avoid demangling DW_STRING (attr) the second time on a second |
14738 | call for the same DIE. */ | |
14739 | if (!DW_STRING_IS_CANONICAL (attr)) | |
14740 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
14741 | |
14742 | if (demangled) | |
14743 | { | |
96408a79 SA |
14744 | char *base; |
14745 | ||
53832f31 | 14746 | /* FIXME: we already did this for the partial symbol... */ |
96408a79 SA |
14747 | DW_STRING (attr) = obsavestring (demangled, strlen (demangled), |
14748 | &cu->objfile->objfile_obstack); | |
53832f31 TT |
14749 | DW_STRING_IS_CANONICAL (attr) = 1; |
14750 | xfree (demangled); | |
96408a79 SA |
14751 | |
14752 | /* Strip any leading namespaces/classes, keep only the base name. | |
14753 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
14754 | base = strrchr (DW_STRING (attr), ':'); | |
14755 | if (base && base > DW_STRING (attr) && base[-1] == ':') | |
14756 | return &base[1]; | |
14757 | else | |
14758 | return DW_STRING (attr); | |
53832f31 TT |
14759 | } |
14760 | } | |
907af001 UW |
14761 | break; |
14762 | ||
71c25dea | 14763 | default: |
907af001 UW |
14764 | break; |
14765 | } | |
14766 | ||
14767 | if (!DW_STRING_IS_CANONICAL (attr)) | |
14768 | { | |
14769 | DW_STRING (attr) | |
14770 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
14771 | &cu->objfile->objfile_obstack); | |
14772 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 14773 | } |
907af001 | 14774 | return DW_STRING (attr); |
9219021c DC |
14775 | } |
14776 | ||
14777 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
14778 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
14779 | containing the return value on output. */ | |
9219021c DC |
14780 | |
14781 | static struct die_info * | |
f2f0e013 | 14782 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
14783 | { |
14784 | struct attribute *attr; | |
9219021c | 14785 | |
f2f0e013 | 14786 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
14787 | if (attr == NULL) |
14788 | return NULL; | |
14789 | ||
f2f0e013 | 14790 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
14791 | } |
14792 | ||
c906108c SS |
14793 | /* Convert a DIE tag into its string name. */ |
14794 | ||
f39c6ffd | 14795 | static const char * |
aa1ee363 | 14796 | dwarf_tag_name (unsigned tag) |
c906108c | 14797 | { |
f39c6ffd TT |
14798 | const char *name = get_DW_TAG_name (tag); |
14799 | ||
14800 | if (name == NULL) | |
14801 | return "DW_TAG_<unknown>"; | |
14802 | ||
14803 | return name; | |
c906108c SS |
14804 | } |
14805 | ||
14806 | /* Convert a DWARF attribute code into its string name. */ | |
14807 | ||
f39c6ffd | 14808 | static const char * |
aa1ee363 | 14809 | dwarf_attr_name (unsigned attr) |
c906108c | 14810 | { |
f39c6ffd TT |
14811 | const char *name; |
14812 | ||
c764a876 | 14813 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
f39c6ffd TT |
14814 | if (attr == DW_AT_MIPS_fde) |
14815 | return "DW_AT_MIPS_fde"; | |
14816 | #else | |
14817 | if (attr == DW_AT_HP_block_index) | |
14818 | return "DW_AT_HP_block_index"; | |
c764a876 | 14819 | #endif |
f39c6ffd TT |
14820 | |
14821 | name = get_DW_AT_name (attr); | |
14822 | ||
14823 | if (name == NULL) | |
14824 | return "DW_AT_<unknown>"; | |
14825 | ||
14826 | return name; | |
c906108c SS |
14827 | } |
14828 | ||
14829 | /* Convert a DWARF value form code into its string name. */ | |
14830 | ||
f39c6ffd | 14831 | static const char * |
aa1ee363 | 14832 | dwarf_form_name (unsigned form) |
c906108c | 14833 | { |
f39c6ffd TT |
14834 | const char *name = get_DW_FORM_name (form); |
14835 | ||
14836 | if (name == NULL) | |
14837 | return "DW_FORM_<unknown>"; | |
14838 | ||
14839 | return name; | |
c906108c SS |
14840 | } |
14841 | ||
14842 | static char * | |
fba45db2 | 14843 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
14844 | { |
14845 | if (mybool) | |
14846 | return "TRUE"; | |
14847 | else | |
14848 | return "FALSE"; | |
14849 | } | |
14850 | ||
14851 | /* Convert a DWARF type code into its string name. */ | |
14852 | ||
f39c6ffd | 14853 | static const char * |
aa1ee363 | 14854 | dwarf_type_encoding_name (unsigned enc) |
c906108c | 14855 | { |
f39c6ffd | 14856 | const char *name = get_DW_ATE_name (enc); |
c906108c | 14857 | |
f39c6ffd TT |
14858 | if (name == NULL) |
14859 | return "DW_ATE_<unknown>"; | |
c906108c | 14860 | |
f39c6ffd | 14861 | return name; |
c906108c | 14862 | } |
c906108c | 14863 | |
f9aca02d | 14864 | static void |
d97bc12b | 14865 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
14866 | { |
14867 | unsigned int i; | |
14868 | ||
d97bc12b DE |
14869 | print_spaces (indent, f); |
14870 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
b64f50a1 | 14871 | dwarf_tag_name (die->tag), die->abbrev, die->offset.sect_off); |
d97bc12b DE |
14872 | |
14873 | if (die->parent != NULL) | |
14874 | { | |
14875 | print_spaces (indent, f); | |
14876 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
b64f50a1 | 14877 | die->parent->offset.sect_off); |
d97bc12b DE |
14878 | } |
14879 | ||
14880 | print_spaces (indent, f); | |
14881 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 14882 | dwarf_bool_name (die->child != NULL)); |
c906108c | 14883 | |
d97bc12b DE |
14884 | print_spaces (indent, f); |
14885 | fprintf_unfiltered (f, " attributes:\n"); | |
14886 | ||
c906108c SS |
14887 | for (i = 0; i < die->num_attrs; ++i) |
14888 | { | |
d97bc12b DE |
14889 | print_spaces (indent, f); |
14890 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
14891 | dwarf_attr_name (die->attrs[i].name), |
14892 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 14893 | |
c906108c SS |
14894 | switch (die->attrs[i].form) |
14895 | { | |
c906108c | 14896 | case DW_FORM_addr: |
3019eac3 | 14897 | case DW_FORM_GNU_addr_index: |
d97bc12b | 14898 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 14899 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
14900 | break; |
14901 | case DW_FORM_block2: | |
14902 | case DW_FORM_block4: | |
14903 | case DW_FORM_block: | |
14904 | case DW_FORM_block1: | |
3e43a32a MS |
14905 | fprintf_unfiltered (f, "block: size %d", |
14906 | DW_BLOCK (&die->attrs[i])->size); | |
c906108c | 14907 | break; |
2dc7f7b3 TT |
14908 | case DW_FORM_exprloc: |
14909 | fprintf_unfiltered (f, "expression: size %u", | |
14910 | DW_BLOCK (&die->attrs[i])->size); | |
14911 | break; | |
4568ecf9 DE |
14912 | case DW_FORM_ref_addr: |
14913 | fprintf_unfiltered (f, "ref address: "); | |
14914 | fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f); | |
14915 | break; | |
10b3939b DJ |
14916 | case DW_FORM_ref1: |
14917 | case DW_FORM_ref2: | |
14918 | case DW_FORM_ref4: | |
4568ecf9 DE |
14919 | case DW_FORM_ref8: |
14920 | case DW_FORM_ref_udata: | |
d97bc12b | 14921 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
4568ecf9 | 14922 | (long) (DW_UNSND (&die->attrs[i]))); |
10b3939b | 14923 | break; |
c906108c SS |
14924 | case DW_FORM_data1: |
14925 | case DW_FORM_data2: | |
14926 | case DW_FORM_data4: | |
ce5d95e1 | 14927 | case DW_FORM_data8: |
c906108c SS |
14928 | case DW_FORM_udata: |
14929 | case DW_FORM_sdata: | |
43bbcdc2 PH |
14930 | fprintf_unfiltered (f, "constant: %s", |
14931 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 14932 | break; |
2dc7f7b3 TT |
14933 | case DW_FORM_sec_offset: |
14934 | fprintf_unfiltered (f, "section offset: %s", | |
14935 | pulongest (DW_UNSND (&die->attrs[i]))); | |
14936 | break; | |
55f1336d | 14937 | case DW_FORM_ref_sig8: |
348e048f DE |
14938 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
14939 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
b64f50a1 | 14940 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset.sect_off); |
348e048f DE |
14941 | else |
14942 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
14943 | break; | |
c906108c | 14944 | case DW_FORM_string: |
4bdf3d34 | 14945 | case DW_FORM_strp: |
3019eac3 | 14946 | case DW_FORM_GNU_str_index: |
8285870a | 14947 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 14948 | DW_STRING (&die->attrs[i]) |
8285870a JK |
14949 | ? DW_STRING (&die->attrs[i]) : "", |
14950 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
14951 | break; |
14952 | case DW_FORM_flag: | |
14953 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 14954 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 14955 | else |
d97bc12b | 14956 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 14957 | break; |
2dc7f7b3 TT |
14958 | case DW_FORM_flag_present: |
14959 | fprintf_unfiltered (f, "flag: TRUE"); | |
14960 | break; | |
a8329558 | 14961 | case DW_FORM_indirect: |
0963b4bd MS |
14962 | /* The reader will have reduced the indirect form to |
14963 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
14964 | fprintf_unfiltered (f, |
14965 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 14966 | break; |
c906108c | 14967 | default: |
d97bc12b | 14968 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 14969 | die->attrs[i].form); |
d97bc12b | 14970 | break; |
c906108c | 14971 | } |
d97bc12b | 14972 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
14973 | } |
14974 | } | |
14975 | ||
f9aca02d | 14976 | static void |
d97bc12b | 14977 | dump_die_for_error (struct die_info *die) |
c906108c | 14978 | { |
d97bc12b DE |
14979 | dump_die_shallow (gdb_stderr, 0, die); |
14980 | } | |
14981 | ||
14982 | static void | |
14983 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
14984 | { | |
14985 | int indent = level * 4; | |
14986 | ||
14987 | gdb_assert (die != NULL); | |
14988 | ||
14989 | if (level >= max_level) | |
14990 | return; | |
14991 | ||
14992 | dump_die_shallow (f, indent, die); | |
14993 | ||
14994 | if (die->child != NULL) | |
c906108c | 14995 | { |
d97bc12b DE |
14996 | print_spaces (indent, f); |
14997 | fprintf_unfiltered (f, " Children:"); | |
14998 | if (level + 1 < max_level) | |
14999 | { | |
15000 | fprintf_unfiltered (f, "\n"); | |
15001 | dump_die_1 (f, level + 1, max_level, die->child); | |
15002 | } | |
15003 | else | |
15004 | { | |
3e43a32a MS |
15005 | fprintf_unfiltered (f, |
15006 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
15007 | } |
15008 | } | |
15009 | ||
15010 | if (die->sibling != NULL && level > 0) | |
15011 | { | |
15012 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
15013 | } |
15014 | } | |
15015 | ||
d97bc12b DE |
15016 | /* This is called from the pdie macro in gdbinit.in. |
15017 | It's not static so gcc will keep a copy callable from gdb. */ | |
15018 | ||
15019 | void | |
15020 | dump_die (struct die_info *die, int max_level) | |
15021 | { | |
15022 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
15023 | } | |
15024 | ||
f9aca02d | 15025 | static void |
51545339 | 15026 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 15027 | { |
51545339 | 15028 | void **slot; |
c906108c | 15029 | |
b64f50a1 JK |
15030 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset.sect_off, |
15031 | INSERT); | |
51545339 DJ |
15032 | |
15033 | *slot = die; | |
c906108c SS |
15034 | } |
15035 | ||
b64f50a1 JK |
15036 | /* DW_ADDR is always stored already as sect_offset; despite for the forms |
15037 | besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ | |
15038 | ||
93311388 DE |
15039 | static int |
15040 | is_ref_attr (struct attribute *attr) | |
c906108c | 15041 | { |
c906108c SS |
15042 | switch (attr->form) |
15043 | { | |
15044 | case DW_FORM_ref_addr: | |
c906108c SS |
15045 | case DW_FORM_ref1: |
15046 | case DW_FORM_ref2: | |
15047 | case DW_FORM_ref4: | |
613e1657 | 15048 | case DW_FORM_ref8: |
c906108c | 15049 | case DW_FORM_ref_udata: |
93311388 | 15050 | return 1; |
c906108c | 15051 | default: |
93311388 | 15052 | return 0; |
c906108c | 15053 | } |
93311388 DE |
15054 | } |
15055 | ||
b64f50a1 JK |
15056 | /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the |
15057 | required kind. */ | |
15058 | ||
15059 | static sect_offset | |
93311388 DE |
15060 | dwarf2_get_ref_die_offset (struct attribute *attr) |
15061 | { | |
4568ecf9 | 15062 | sect_offset retval = { DW_UNSND (attr) }; |
b64f50a1 | 15063 | |
93311388 | 15064 | if (is_ref_attr (attr)) |
b64f50a1 | 15065 | return retval; |
93311388 | 15066 | |
b64f50a1 | 15067 | retval.sect_off = 0; |
93311388 DE |
15068 | complaint (&symfile_complaints, |
15069 | _("unsupported die ref attribute form: '%s'"), | |
15070 | dwarf_form_name (attr->form)); | |
b64f50a1 | 15071 | return retval; |
c906108c SS |
15072 | } |
15073 | ||
43bbcdc2 PH |
15074 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
15075 | * the value held by the attribute is not constant. */ | |
a02abb62 | 15076 | |
43bbcdc2 | 15077 | static LONGEST |
a02abb62 JB |
15078 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
15079 | { | |
15080 | if (attr->form == DW_FORM_sdata) | |
15081 | return DW_SND (attr); | |
15082 | else if (attr->form == DW_FORM_udata | |
15083 | || attr->form == DW_FORM_data1 | |
15084 | || attr->form == DW_FORM_data2 | |
15085 | || attr->form == DW_FORM_data4 | |
15086 | || attr->form == DW_FORM_data8) | |
15087 | return DW_UNSND (attr); | |
15088 | else | |
15089 | { | |
3e43a32a MS |
15090 | complaint (&symfile_complaints, |
15091 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
15092 | dwarf_form_name (attr->form)); |
15093 | return default_value; | |
15094 | } | |
15095 | } | |
15096 | ||
03dd20cc | 15097 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
15098 | unit and add it to our queue. |
15099 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
15100 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 15101 | |
348e048f | 15102 | static int |
03dd20cc | 15103 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
95554aad TT |
15104 | struct dwarf2_per_cu_data *per_cu, |
15105 | enum language pretend_language) | |
03dd20cc | 15106 | { |
98bfdba5 PA |
15107 | /* We may arrive here during partial symbol reading, if we need full |
15108 | DIEs to process an unusual case (e.g. template arguments). Do | |
15109 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
15110 | if (dwarf2_per_objfile->reading_partial_symbols) | |
15111 | { | |
15112 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
15113 | return 1; | |
15114 | return 0; | |
15115 | } | |
15116 | ||
03dd20cc DJ |
15117 | /* Mark the dependence relation so that we don't flush PER_CU |
15118 | too early. */ | |
15119 | dwarf2_add_dependence (this_cu, per_cu); | |
15120 | ||
15121 | /* If it's already on the queue, we have nothing to do. */ | |
15122 | if (per_cu->queued) | |
348e048f | 15123 | return 0; |
03dd20cc DJ |
15124 | |
15125 | /* If the compilation unit is already loaded, just mark it as | |
15126 | used. */ | |
15127 | if (per_cu->cu != NULL) | |
15128 | { | |
15129 | per_cu->cu->last_used = 0; | |
348e048f | 15130 | return 0; |
03dd20cc DJ |
15131 | } |
15132 | ||
15133 | /* Add it to the queue. */ | |
95554aad | 15134 | queue_comp_unit (per_cu, pretend_language); |
348e048f DE |
15135 | |
15136 | return 1; | |
15137 | } | |
15138 | ||
15139 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
15140 | On entry *REF_CU is the CU of SRC_DIE. | |
15141 | On exit *REF_CU is the CU of the result. */ | |
15142 | ||
15143 | static struct die_info * | |
15144 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
15145 | struct dwarf2_cu **ref_cu) | |
15146 | { | |
15147 | struct die_info *die; | |
15148 | ||
15149 | if (is_ref_attr (attr)) | |
15150 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 15151 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
15152 | die = follow_die_sig (src_die, attr, ref_cu); |
15153 | else | |
15154 | { | |
15155 | dump_die_for_error (src_die); | |
15156 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
15157 | (*ref_cu)->objfile->name); | |
15158 | } | |
15159 | ||
15160 | return die; | |
03dd20cc DJ |
15161 | } |
15162 | ||
5c631832 | 15163 | /* Follow reference OFFSET. |
673bfd45 DE |
15164 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
15165 | On exit *REF_CU is the CU of the result. | |
15166 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 15167 | |
f9aca02d | 15168 | static struct die_info * |
b64f50a1 | 15169 | follow_die_offset (sect_offset offset, struct dwarf2_cu **ref_cu) |
c906108c | 15170 | { |
10b3939b | 15171 | struct die_info temp_die; |
f2f0e013 | 15172 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 15173 | |
348e048f DE |
15174 | gdb_assert (cu->per_cu != NULL); |
15175 | ||
98bfdba5 PA |
15176 | target_cu = cu; |
15177 | ||
3019eac3 | 15178 | if (cu->per_cu->is_debug_types) |
348e048f DE |
15179 | { |
15180 | /* .debug_types CUs cannot reference anything outside their CU. | |
15181 | If they need to, they have to reference a signatured type via | |
55f1336d | 15182 | DW_FORM_ref_sig8. */ |
348e048f | 15183 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 15184 | return NULL; |
348e048f DE |
15185 | } |
15186 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
15187 | { |
15188 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 15189 | |
45452591 | 15190 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
15191 | |
15192 | /* If necessary, add it to the queue and load its DIEs. */ | |
95554aad TT |
15193 | if (maybe_queue_comp_unit (cu, per_cu, cu->language)) |
15194 | load_full_comp_unit (per_cu, cu->language); | |
03dd20cc | 15195 | |
10b3939b DJ |
15196 | target_cu = per_cu->cu; |
15197 | } | |
98bfdba5 PA |
15198 | else if (cu->dies == NULL) |
15199 | { | |
15200 | /* We're loading full DIEs during partial symbol reading. */ | |
15201 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
95554aad | 15202 | load_full_comp_unit (cu->per_cu, language_minimal); |
98bfdba5 | 15203 | } |
c906108c | 15204 | |
f2f0e013 | 15205 | *ref_cu = target_cu; |
51545339 | 15206 | temp_die.offset = offset; |
b64f50a1 | 15207 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset.sect_off); |
5c631832 | 15208 | } |
10b3939b | 15209 | |
5c631832 JK |
15210 | /* Follow reference attribute ATTR of SRC_DIE. |
15211 | On entry *REF_CU is the CU of SRC_DIE. | |
15212 | On exit *REF_CU is the CU of the result. */ | |
15213 | ||
15214 | static struct die_info * | |
15215 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
15216 | struct dwarf2_cu **ref_cu) | |
15217 | { | |
b64f50a1 | 15218 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
5c631832 JK |
15219 | struct dwarf2_cu *cu = *ref_cu; |
15220 | struct die_info *die; | |
15221 | ||
15222 | die = follow_die_offset (offset, ref_cu); | |
15223 | if (!die) | |
15224 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
15225 | "at 0x%x [in module %s]"), | |
b64f50a1 | 15226 | offset.sect_off, src_die->offset.sect_off, cu->objfile->name); |
348e048f | 15227 | |
5c631832 JK |
15228 | return die; |
15229 | } | |
15230 | ||
d83e736b JK |
15231 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
15232 | Returned value is intended for DW_OP_call*. Returned | |
15233 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ | |
5c631832 JK |
15234 | |
15235 | struct dwarf2_locexpr_baton | |
b64f50a1 | 15236 | dwarf2_fetch_die_location_block (cu_offset offset_in_cu, |
8cf6f0b1 TT |
15237 | struct dwarf2_per_cu_data *per_cu, |
15238 | CORE_ADDR (*get_frame_pc) (void *baton), | |
15239 | void *baton) | |
5c631832 | 15240 | { |
b64f50a1 | 15241 | sect_offset offset = { per_cu->offset.sect_off + offset_in_cu.cu_off }; |
918dd910 | 15242 | struct dwarf2_cu *cu; |
5c631832 JK |
15243 | struct die_info *die; |
15244 | struct attribute *attr; | |
15245 | struct dwarf2_locexpr_baton retval; | |
15246 | ||
8cf6f0b1 TT |
15247 | dw2_setup (per_cu->objfile); |
15248 | ||
918dd910 JK |
15249 | if (per_cu->cu == NULL) |
15250 | load_cu (per_cu); | |
15251 | cu = per_cu->cu; | |
15252 | ||
5c631832 JK |
15253 | die = follow_die_offset (offset, &cu); |
15254 | if (!die) | |
15255 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
b64f50a1 | 15256 | offset.sect_off, per_cu->objfile->name); |
5c631832 JK |
15257 | |
15258 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
15259 | if (!attr) | |
15260 | { | |
e103e986 JK |
15261 | /* DWARF: "If there is no such attribute, then there is no effect.". |
15262 | DATA is ignored if SIZE is 0. */ | |
5c631832 | 15263 | |
e103e986 | 15264 | retval.data = NULL; |
5c631832 JK |
15265 | retval.size = 0; |
15266 | } | |
8cf6f0b1 TT |
15267 | else if (attr_form_is_section_offset (attr)) |
15268 | { | |
15269 | struct dwarf2_loclist_baton loclist_baton; | |
15270 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
15271 | size_t size; | |
15272 | ||
15273 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
15274 | ||
15275 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
15276 | &size, pc); | |
15277 | retval.size = size; | |
15278 | } | |
5c631832 JK |
15279 | else |
15280 | { | |
15281 | if (!attr_form_is_block (attr)) | |
15282 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
15283 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
b64f50a1 | 15284 | offset.sect_off, per_cu->objfile->name); |
5c631832 JK |
15285 | |
15286 | retval.data = DW_BLOCK (attr)->data; | |
15287 | retval.size = DW_BLOCK (attr)->size; | |
15288 | } | |
15289 | retval.per_cu = cu->per_cu; | |
918dd910 | 15290 | |
918dd910 JK |
15291 | age_cached_comp_units (); |
15292 | ||
5c631832 | 15293 | return retval; |
348e048f DE |
15294 | } |
15295 | ||
8a9b8146 TT |
15296 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
15297 | PER_CU. */ | |
15298 | ||
15299 | struct type * | |
b64f50a1 | 15300 | dwarf2_get_die_type (cu_offset die_offset, |
8a9b8146 TT |
15301 | struct dwarf2_per_cu_data *per_cu) |
15302 | { | |
b64f50a1 JK |
15303 | sect_offset die_offset_sect; |
15304 | ||
8a9b8146 | 15305 | dw2_setup (per_cu->objfile); |
b64f50a1 JK |
15306 | |
15307 | die_offset_sect.sect_off = per_cu->offset.sect_off + die_offset.cu_off; | |
15308 | return get_die_type_at_offset (die_offset_sect, per_cu); | |
8a9b8146 TT |
15309 | } |
15310 | ||
348e048f DE |
15311 | /* Follow the signature attribute ATTR in SRC_DIE. |
15312 | On entry *REF_CU is the CU of SRC_DIE. | |
15313 | On exit *REF_CU is the CU of the result. */ | |
15314 | ||
15315 | static struct die_info * | |
15316 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
15317 | struct dwarf2_cu **ref_cu) | |
15318 | { | |
15319 | struct objfile *objfile = (*ref_cu)->objfile; | |
15320 | struct die_info temp_die; | |
15321 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
15322 | struct dwarf2_cu *sig_cu; | |
15323 | struct die_info *die; | |
15324 | ||
15325 | /* sig_type will be NULL if the signatured type is missing from | |
15326 | the debug info. */ | |
15327 | if (sig_type == NULL) | |
15328 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
15329 | "at 0x%x [in module %s]"), | |
b64f50a1 | 15330 | src_die->offset.sect_off, objfile->name); |
348e048f DE |
15331 | |
15332 | /* If necessary, add it to the queue and load its DIEs. */ | |
15333 | ||
95554aad | 15334 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, language_minimal)) |
a0f42c21 | 15335 | read_signatured_type (sig_type); |
348e048f DE |
15336 | |
15337 | gdb_assert (sig_type->per_cu.cu != NULL); | |
15338 | ||
15339 | sig_cu = sig_type->per_cu.cu; | |
3019eac3 DE |
15340 | gdb_assert (sig_type->type_offset_in_section.sect_off != 0); |
15341 | temp_die.offset = sig_type->type_offset_in_section; | |
b64f50a1 JK |
15342 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, |
15343 | temp_die.offset.sect_off); | |
348e048f DE |
15344 | if (die) |
15345 | { | |
15346 | *ref_cu = sig_cu; | |
15347 | return die; | |
15348 | } | |
15349 | ||
3e43a32a MS |
15350 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
15351 | "from DIE at 0x%x [in module %s]"), | |
b64f50a1 | 15352 | temp_die.offset.sect_off, src_die->offset.sect_off, objfile->name); |
348e048f DE |
15353 | } |
15354 | ||
15355 | /* Given an offset of a signatured type, return its signatured_type. */ | |
15356 | ||
15357 | static struct signatured_type * | |
8b70b953 TT |
15358 | lookup_signatured_type_at_offset (struct objfile *objfile, |
15359 | struct dwarf2_section_info *section, | |
b64f50a1 | 15360 | sect_offset offset) |
348e048f | 15361 | { |
b64f50a1 | 15362 | gdb_byte *info_ptr = section->buffer + offset.sect_off; |
348e048f DE |
15363 | unsigned int length, initial_length_size; |
15364 | unsigned int sig_offset; | |
52dc124a | 15365 | struct signatured_type find_entry, *sig_type; |
348e048f DE |
15366 | |
15367 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
15368 | sig_offset = (initial_length_size | |
15369 | + 2 /*version*/ | |
15370 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
15371 | + 1 /*address_size*/); | |
15372 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
52dc124a | 15373 | sig_type = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
348e048f DE |
15374 | |
15375 | /* This is only used to lookup previously recorded types. | |
15376 | If we didn't find it, it's our bug. */ | |
52dc124a DE |
15377 | gdb_assert (sig_type != NULL); |
15378 | gdb_assert (offset.sect_off == sig_type->per_cu.offset.sect_off); | |
348e048f | 15379 | |
52dc124a | 15380 | return sig_type; |
348e048f DE |
15381 | } |
15382 | ||
e5fe5e75 | 15383 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
348e048f DE |
15384 | |
15385 | static void | |
e5fe5e75 | 15386 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
348e048f | 15387 | { |
e5fe5e75 | 15388 | struct objfile *objfile = per_cu->objfile; |
3019eac3 | 15389 | struct dwarf2_section_info *sect = per_cu->info_or_types_section; |
b64f50a1 | 15390 | sect_offset offset = per_cu->offset; |
52dc124a | 15391 | struct signatured_type *sig_type; |
348e048f | 15392 | |
8b70b953 | 15393 | dwarf2_read_section (objfile, sect); |
be391dca | 15394 | |
348e048f | 15395 | /* We have the section offset, but we need the signature to do the |
e5fe5e75 DE |
15396 | hash table lookup. */ |
15397 | /* FIXME: This is sorta unnecessary, read_signatured_type only uses | |
15398 | the signature to assert we found the right one. | |
15399 | Ok, but it's a lot of work. We should simplify things so any needed | |
15400 | assert doesn't require all this clumsiness. */ | |
52dc124a | 15401 | sig_type = lookup_signatured_type_at_offset (objfile, sect, offset); |
348e048f | 15402 | |
dee91e82 | 15403 | gdb_assert (&sig_type->per_cu == per_cu); |
52dc124a | 15404 | gdb_assert (sig_type->per_cu.cu == NULL); |
348e048f | 15405 | |
52dc124a | 15406 | read_signatured_type (sig_type); |
348e048f | 15407 | |
52dc124a | 15408 | gdb_assert (sig_type->per_cu.cu != NULL); |
348e048f DE |
15409 | } |
15410 | ||
dee91e82 DE |
15411 | /* die_reader_func for read_signatured_type. |
15412 | This is identical to load_full_comp_unit_reader, | |
15413 | but is kept separate for now. */ | |
348e048f DE |
15414 | |
15415 | static void | |
dee91e82 DE |
15416 | read_signatured_type_reader (const struct die_reader_specs *reader, |
15417 | gdb_byte *info_ptr, | |
15418 | struct die_info *comp_unit_die, | |
15419 | int has_children, | |
15420 | void *data) | |
348e048f | 15421 | { |
dee91e82 | 15422 | struct dwarf2_cu *cu = reader->cu; |
348e048f | 15423 | |
dee91e82 DE |
15424 | gdb_assert (cu->die_hash == NULL); |
15425 | cu->die_hash = | |
15426 | htab_create_alloc_ex (cu->header.length / 12, | |
15427 | die_hash, | |
15428 | die_eq, | |
15429 | NULL, | |
15430 | &cu->comp_unit_obstack, | |
15431 | hashtab_obstack_allocate, | |
15432 | dummy_obstack_deallocate); | |
348e048f | 15433 | |
dee91e82 DE |
15434 | if (has_children) |
15435 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
15436 | &info_ptr, comp_unit_die); | |
15437 | cu->dies = comp_unit_die; | |
15438 | /* comp_unit_die is not stored in die_hash, no need. */ | |
348e048f DE |
15439 | |
15440 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 15441 | all CUs needed for references have been loaded yet, and symbol |
348e048f | 15442 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
15443 | or we won't be able to build types correctly. |
15444 | Similarly, if we do not read the producer, we can not apply | |
15445 | producer-specific interpretation. */ | |
95554aad | 15446 | prepare_one_comp_unit (cu, cu->dies, language_minimal); |
dee91e82 | 15447 | } |
348e048f | 15448 | |
3019eac3 DE |
15449 | /* Read in a signatured type and build its CU and DIEs. |
15450 | If the type is a stub for the real type in a DWO file, | |
15451 | read in the real type from the DWO file as well. */ | |
dee91e82 DE |
15452 | |
15453 | static void | |
15454 | read_signatured_type (struct signatured_type *sig_type) | |
15455 | { | |
15456 | struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu; | |
348e048f | 15457 | |
3019eac3 | 15458 | gdb_assert (per_cu->is_debug_types); |
dee91e82 | 15459 | gdb_assert (per_cu->cu == NULL); |
348e048f | 15460 | |
fd820528 | 15461 | init_cutu_and_read_dies (per_cu, 0, 1, read_signatured_type_reader, NULL); |
c906108c SS |
15462 | } |
15463 | ||
c906108c SS |
15464 | /* Decode simple location descriptions. |
15465 | Given a pointer to a dwarf block that defines a location, compute | |
15466 | the location and return the value. | |
15467 | ||
4cecd739 DJ |
15468 | NOTE drow/2003-11-18: This function is called in two situations |
15469 | now: for the address of static or global variables (partial symbols | |
15470 | only) and for offsets into structures which are expected to be | |
15471 | (more or less) constant. The partial symbol case should go away, | |
15472 | and only the constant case should remain. That will let this | |
15473 | function complain more accurately. A few special modes are allowed | |
15474 | without complaint for global variables (for instance, global | |
15475 | register values and thread-local values). | |
c906108c SS |
15476 | |
15477 | A location description containing no operations indicates that the | |
4cecd739 | 15478 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
15479 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
15480 | callers will only want a very basic result and this can become a | |
21ae7a4d JK |
15481 | complaint. |
15482 | ||
15483 | Note that stack[0] is unused except as a default error return. */ | |
c906108c SS |
15484 | |
15485 | static CORE_ADDR | |
e7c27a73 | 15486 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 15487 | { |
e7c27a73 | 15488 | struct objfile *objfile = cu->objfile; |
21ae7a4d JK |
15489 | int i; |
15490 | int size = blk->size; | |
15491 | gdb_byte *data = blk->data; | |
15492 | CORE_ADDR stack[64]; | |
15493 | int stacki; | |
15494 | unsigned int bytes_read, unsnd; | |
15495 | gdb_byte op; | |
c906108c | 15496 | |
21ae7a4d JK |
15497 | i = 0; |
15498 | stacki = 0; | |
15499 | stack[stacki] = 0; | |
15500 | stack[++stacki] = 0; | |
15501 | ||
15502 | while (i < size) | |
15503 | { | |
15504 | op = data[i++]; | |
15505 | switch (op) | |
15506 | { | |
15507 | case DW_OP_lit0: | |
15508 | case DW_OP_lit1: | |
15509 | case DW_OP_lit2: | |
15510 | case DW_OP_lit3: | |
15511 | case DW_OP_lit4: | |
15512 | case DW_OP_lit5: | |
15513 | case DW_OP_lit6: | |
15514 | case DW_OP_lit7: | |
15515 | case DW_OP_lit8: | |
15516 | case DW_OP_lit9: | |
15517 | case DW_OP_lit10: | |
15518 | case DW_OP_lit11: | |
15519 | case DW_OP_lit12: | |
15520 | case DW_OP_lit13: | |
15521 | case DW_OP_lit14: | |
15522 | case DW_OP_lit15: | |
15523 | case DW_OP_lit16: | |
15524 | case DW_OP_lit17: | |
15525 | case DW_OP_lit18: | |
15526 | case DW_OP_lit19: | |
15527 | case DW_OP_lit20: | |
15528 | case DW_OP_lit21: | |
15529 | case DW_OP_lit22: | |
15530 | case DW_OP_lit23: | |
15531 | case DW_OP_lit24: | |
15532 | case DW_OP_lit25: | |
15533 | case DW_OP_lit26: | |
15534 | case DW_OP_lit27: | |
15535 | case DW_OP_lit28: | |
15536 | case DW_OP_lit29: | |
15537 | case DW_OP_lit30: | |
15538 | case DW_OP_lit31: | |
15539 | stack[++stacki] = op - DW_OP_lit0; | |
15540 | break; | |
f1bea926 | 15541 | |
21ae7a4d JK |
15542 | case DW_OP_reg0: |
15543 | case DW_OP_reg1: | |
15544 | case DW_OP_reg2: | |
15545 | case DW_OP_reg3: | |
15546 | case DW_OP_reg4: | |
15547 | case DW_OP_reg5: | |
15548 | case DW_OP_reg6: | |
15549 | case DW_OP_reg7: | |
15550 | case DW_OP_reg8: | |
15551 | case DW_OP_reg9: | |
15552 | case DW_OP_reg10: | |
15553 | case DW_OP_reg11: | |
15554 | case DW_OP_reg12: | |
15555 | case DW_OP_reg13: | |
15556 | case DW_OP_reg14: | |
15557 | case DW_OP_reg15: | |
15558 | case DW_OP_reg16: | |
15559 | case DW_OP_reg17: | |
15560 | case DW_OP_reg18: | |
15561 | case DW_OP_reg19: | |
15562 | case DW_OP_reg20: | |
15563 | case DW_OP_reg21: | |
15564 | case DW_OP_reg22: | |
15565 | case DW_OP_reg23: | |
15566 | case DW_OP_reg24: | |
15567 | case DW_OP_reg25: | |
15568 | case DW_OP_reg26: | |
15569 | case DW_OP_reg27: | |
15570 | case DW_OP_reg28: | |
15571 | case DW_OP_reg29: | |
15572 | case DW_OP_reg30: | |
15573 | case DW_OP_reg31: | |
15574 | stack[++stacki] = op - DW_OP_reg0; | |
15575 | if (i < size) | |
15576 | dwarf2_complex_location_expr_complaint (); | |
15577 | break; | |
c906108c | 15578 | |
21ae7a4d JK |
15579 | case DW_OP_regx: |
15580 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
15581 | i += bytes_read; | |
15582 | stack[++stacki] = unsnd; | |
15583 | if (i < size) | |
15584 | dwarf2_complex_location_expr_complaint (); | |
15585 | break; | |
c906108c | 15586 | |
21ae7a4d JK |
15587 | case DW_OP_addr: |
15588 | stack[++stacki] = read_address (objfile->obfd, &data[i], | |
15589 | cu, &bytes_read); | |
15590 | i += bytes_read; | |
15591 | break; | |
d53d4ac5 | 15592 | |
21ae7a4d JK |
15593 | case DW_OP_const1u: |
15594 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
15595 | i += 1; | |
15596 | break; | |
15597 | ||
15598 | case DW_OP_const1s: | |
15599 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
15600 | i += 1; | |
15601 | break; | |
15602 | ||
15603 | case DW_OP_const2u: | |
15604 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
15605 | i += 2; | |
15606 | break; | |
15607 | ||
15608 | case DW_OP_const2s: | |
15609 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
15610 | i += 2; | |
15611 | break; | |
d53d4ac5 | 15612 | |
21ae7a4d JK |
15613 | case DW_OP_const4u: |
15614 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
15615 | i += 4; | |
15616 | break; | |
15617 | ||
15618 | case DW_OP_const4s: | |
15619 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
15620 | i += 4; | |
15621 | break; | |
15622 | ||
585861ea JK |
15623 | case DW_OP_const8u: |
15624 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); | |
15625 | i += 8; | |
15626 | break; | |
15627 | ||
21ae7a4d JK |
15628 | case DW_OP_constu: |
15629 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
15630 | &bytes_read); | |
15631 | i += bytes_read; | |
15632 | break; | |
15633 | ||
15634 | case DW_OP_consts: | |
15635 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
15636 | i += bytes_read; | |
15637 | break; | |
15638 | ||
15639 | case DW_OP_dup: | |
15640 | stack[stacki + 1] = stack[stacki]; | |
15641 | stacki++; | |
15642 | break; | |
15643 | ||
15644 | case DW_OP_plus: | |
15645 | stack[stacki - 1] += stack[stacki]; | |
15646 | stacki--; | |
15647 | break; | |
15648 | ||
15649 | case DW_OP_plus_uconst: | |
15650 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), | |
15651 | &bytes_read); | |
15652 | i += bytes_read; | |
15653 | break; | |
15654 | ||
15655 | case DW_OP_minus: | |
15656 | stack[stacki - 1] -= stack[stacki]; | |
15657 | stacki--; | |
15658 | break; | |
15659 | ||
15660 | case DW_OP_deref: | |
15661 | /* If we're not the last op, then we definitely can't encode | |
15662 | this using GDB's address_class enum. This is valid for partial | |
15663 | global symbols, although the variable's address will be bogus | |
15664 | in the psymtab. */ | |
15665 | if (i < size) | |
15666 | dwarf2_complex_location_expr_complaint (); | |
15667 | break; | |
15668 | ||
15669 | case DW_OP_GNU_push_tls_address: | |
15670 | /* The top of the stack has the offset from the beginning | |
15671 | of the thread control block at which the variable is located. */ | |
15672 | /* Nothing should follow this operator, so the top of stack would | |
15673 | be returned. */ | |
15674 | /* This is valid for partial global symbols, but the variable's | |
585861ea JK |
15675 | address will be bogus in the psymtab. Make it always at least |
15676 | non-zero to not look as a variable garbage collected by linker | |
15677 | which have DW_OP_addr 0. */ | |
21ae7a4d JK |
15678 | if (i < size) |
15679 | dwarf2_complex_location_expr_complaint (); | |
585861ea | 15680 | stack[stacki]++; |
21ae7a4d JK |
15681 | break; |
15682 | ||
15683 | case DW_OP_GNU_uninit: | |
15684 | break; | |
15685 | ||
3019eac3 | 15686 | case DW_OP_GNU_addr_index: |
49f6c839 | 15687 | case DW_OP_GNU_const_index: |
3019eac3 DE |
15688 | stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i], |
15689 | &bytes_read); | |
15690 | i += bytes_read; | |
15691 | break; | |
15692 | ||
21ae7a4d JK |
15693 | default: |
15694 | { | |
f39c6ffd | 15695 | const char *name = get_DW_OP_name (op); |
21ae7a4d JK |
15696 | |
15697 | if (name) | |
15698 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
15699 | name); | |
15700 | else | |
15701 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
15702 | op); | |
15703 | } | |
15704 | ||
15705 | return (stack[stacki]); | |
d53d4ac5 | 15706 | } |
3c6e0cb3 | 15707 | |
21ae7a4d JK |
15708 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
15709 | outside of the allocated space. Also enforce minimum>0. */ | |
15710 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
15711 | { | |
15712 | complaint (&symfile_complaints, | |
15713 | _("location description stack overflow")); | |
15714 | return 0; | |
15715 | } | |
15716 | ||
15717 | if (stacki <= 0) | |
15718 | { | |
15719 | complaint (&symfile_complaints, | |
15720 | _("location description stack underflow")); | |
15721 | return 0; | |
15722 | } | |
15723 | } | |
15724 | return (stack[stacki]); | |
c906108c SS |
15725 | } |
15726 | ||
15727 | /* memory allocation interface */ | |
15728 | ||
c906108c | 15729 | static struct dwarf_block * |
7b5a2f43 | 15730 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
15731 | { |
15732 | struct dwarf_block *blk; | |
15733 | ||
15734 | blk = (struct dwarf_block *) | |
7b5a2f43 | 15735 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
15736 | return (blk); |
15737 | } | |
15738 | ||
15739 | static struct abbrev_info * | |
f3dd6933 | 15740 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
15741 | { |
15742 | struct abbrev_info *abbrev; | |
15743 | ||
f3dd6933 DJ |
15744 | abbrev = (struct abbrev_info *) |
15745 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
15746 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
15747 | return (abbrev); | |
15748 | } | |
15749 | ||
15750 | static struct die_info * | |
b60c80d6 | 15751 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
15752 | { |
15753 | struct die_info *die; | |
b60c80d6 DJ |
15754 | size_t size = sizeof (struct die_info); |
15755 | ||
15756 | if (num_attrs > 1) | |
15757 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 15758 | |
b60c80d6 | 15759 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
15760 | memset (die, 0, sizeof (struct die_info)); |
15761 | return (die); | |
15762 | } | |
2e276125 JB |
15763 | |
15764 | \f | |
15765 | /* Macro support. */ | |
15766 | ||
2e276125 JB |
15767 | /* Return the full name of file number I in *LH's file name table. |
15768 | Use COMP_DIR as the name of the current directory of the | |
15769 | compilation. The result is allocated using xmalloc; the caller is | |
15770 | responsible for freeing it. */ | |
15771 | static char * | |
15772 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
15773 | { | |
6a83a1e6 EZ |
15774 | /* Is the file number a valid index into the line header's file name |
15775 | table? Remember that file numbers start with one, not zero. */ | |
15776 | if (1 <= file && file <= lh->num_file_names) | |
15777 | { | |
15778 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 15779 | |
6a83a1e6 EZ |
15780 | if (IS_ABSOLUTE_PATH (fe->name)) |
15781 | return xstrdup (fe->name); | |
15782 | else | |
15783 | { | |
15784 | const char *dir; | |
15785 | int dir_len; | |
15786 | char *full_name; | |
15787 | ||
15788 | if (fe->dir_index) | |
15789 | dir = lh->include_dirs[fe->dir_index - 1]; | |
15790 | else | |
15791 | dir = comp_dir; | |
15792 | ||
15793 | if (dir) | |
15794 | { | |
15795 | dir_len = strlen (dir); | |
15796 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
15797 | strcpy (full_name, dir); | |
15798 | full_name[dir_len] = '/'; | |
15799 | strcpy (full_name + dir_len + 1, fe->name); | |
15800 | return full_name; | |
15801 | } | |
15802 | else | |
15803 | return xstrdup (fe->name); | |
15804 | } | |
15805 | } | |
2e276125 JB |
15806 | else |
15807 | { | |
6a83a1e6 EZ |
15808 | /* The compiler produced a bogus file number. We can at least |
15809 | record the macro definitions made in the file, even if we | |
15810 | won't be able to find the file by name. */ | |
15811 | char fake_name[80]; | |
9a619af0 | 15812 | |
6a83a1e6 | 15813 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 15814 | |
6e70227d | 15815 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
15816 | _("bad file number in macro information (%d)"), |
15817 | file); | |
2e276125 | 15818 | |
6a83a1e6 | 15819 | return xstrdup (fake_name); |
2e276125 JB |
15820 | } |
15821 | } | |
15822 | ||
15823 | ||
15824 | static struct macro_source_file * | |
15825 | macro_start_file (int file, int line, | |
15826 | struct macro_source_file *current_file, | |
15827 | const char *comp_dir, | |
15828 | struct line_header *lh, struct objfile *objfile) | |
15829 | { | |
15830 | /* The full name of this source file. */ | |
15831 | char *full_name = file_full_name (file, lh, comp_dir); | |
15832 | ||
15833 | /* We don't create a macro table for this compilation unit | |
15834 | at all until we actually get a filename. */ | |
15835 | if (! pending_macros) | |
4a146b47 | 15836 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 15837 | objfile->macro_cache); |
2e276125 JB |
15838 | |
15839 | if (! current_file) | |
abc9d0dc TT |
15840 | { |
15841 | /* If we have no current file, then this must be the start_file | |
15842 | directive for the compilation unit's main source file. */ | |
15843 | current_file = macro_set_main (pending_macros, full_name); | |
15844 | macro_define_special (pending_macros); | |
15845 | } | |
2e276125 JB |
15846 | else |
15847 | current_file = macro_include (current_file, line, full_name); | |
15848 | ||
15849 | xfree (full_name); | |
6e70227d | 15850 | |
2e276125 JB |
15851 | return current_file; |
15852 | } | |
15853 | ||
15854 | ||
15855 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
15856 | followed by a null byte. */ | |
15857 | static char * | |
15858 | copy_string (const char *buf, int len) | |
15859 | { | |
15860 | char *s = xmalloc (len + 1); | |
9a619af0 | 15861 | |
2e276125 JB |
15862 | memcpy (s, buf, len); |
15863 | s[len] = '\0'; | |
2e276125 JB |
15864 | return s; |
15865 | } | |
15866 | ||
15867 | ||
15868 | static const char * | |
15869 | consume_improper_spaces (const char *p, const char *body) | |
15870 | { | |
15871 | if (*p == ' ') | |
15872 | { | |
4d3c2250 | 15873 | complaint (&symfile_complaints, |
3e43a32a MS |
15874 | _("macro definition contains spaces " |
15875 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 15876 | body); |
2e276125 JB |
15877 | |
15878 | while (*p == ' ') | |
15879 | p++; | |
15880 | } | |
15881 | ||
15882 | return p; | |
15883 | } | |
15884 | ||
15885 | ||
15886 | static void | |
15887 | parse_macro_definition (struct macro_source_file *file, int line, | |
15888 | const char *body) | |
15889 | { | |
15890 | const char *p; | |
15891 | ||
15892 | /* The body string takes one of two forms. For object-like macro | |
15893 | definitions, it should be: | |
15894 | ||
15895 | <macro name> " " <definition> | |
15896 | ||
15897 | For function-like macro definitions, it should be: | |
15898 | ||
15899 | <macro name> "() " <definition> | |
15900 | or | |
15901 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
15902 | ||
15903 | Spaces may appear only where explicitly indicated, and in the | |
15904 | <definition>. | |
15905 | ||
15906 | The Dwarf 2 spec says that an object-like macro's name is always | |
15907 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 15908 | the space when the macro's definition is the empty string. |
2e276125 JB |
15909 | |
15910 | The Dwarf 2 spec says that there should be no spaces between the | |
15911 | formal arguments in a function-like macro's formal argument list, | |
15912 | but versions of GCC around March 2002 include spaces after the | |
15913 | commas. */ | |
15914 | ||
15915 | ||
15916 | /* Find the extent of the macro name. The macro name is terminated | |
15917 | by either a space or null character (for an object-like macro) or | |
15918 | an opening paren (for a function-like macro). */ | |
15919 | for (p = body; *p; p++) | |
15920 | if (*p == ' ' || *p == '(') | |
15921 | break; | |
15922 | ||
15923 | if (*p == ' ' || *p == '\0') | |
15924 | { | |
15925 | /* It's an object-like macro. */ | |
15926 | int name_len = p - body; | |
15927 | char *name = copy_string (body, name_len); | |
15928 | const char *replacement; | |
15929 | ||
15930 | if (*p == ' ') | |
15931 | replacement = body + name_len + 1; | |
15932 | else | |
15933 | { | |
4d3c2250 | 15934 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
15935 | replacement = body + name_len; |
15936 | } | |
6e70227d | 15937 | |
2e276125 JB |
15938 | macro_define_object (file, line, name, replacement); |
15939 | ||
15940 | xfree (name); | |
15941 | } | |
15942 | else if (*p == '(') | |
15943 | { | |
15944 | /* It's a function-like macro. */ | |
15945 | char *name = copy_string (body, p - body); | |
15946 | int argc = 0; | |
15947 | int argv_size = 1; | |
15948 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
15949 | ||
15950 | p++; | |
15951 | ||
15952 | p = consume_improper_spaces (p, body); | |
15953 | ||
15954 | /* Parse the formal argument list. */ | |
15955 | while (*p && *p != ')') | |
15956 | { | |
15957 | /* Find the extent of the current argument name. */ | |
15958 | const char *arg_start = p; | |
15959 | ||
15960 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
15961 | p++; | |
15962 | ||
15963 | if (! *p || p == arg_start) | |
4d3c2250 | 15964 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
15965 | else |
15966 | { | |
15967 | /* Make sure argv has room for the new argument. */ | |
15968 | if (argc >= argv_size) | |
15969 | { | |
15970 | argv_size *= 2; | |
15971 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
15972 | } | |
15973 | ||
15974 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
15975 | } | |
15976 | ||
15977 | p = consume_improper_spaces (p, body); | |
15978 | ||
15979 | /* Consume the comma, if present. */ | |
15980 | if (*p == ',') | |
15981 | { | |
15982 | p++; | |
15983 | ||
15984 | p = consume_improper_spaces (p, body); | |
15985 | } | |
15986 | } | |
15987 | ||
15988 | if (*p == ')') | |
15989 | { | |
15990 | p++; | |
15991 | ||
15992 | if (*p == ' ') | |
15993 | /* Perfectly formed definition, no complaints. */ | |
15994 | macro_define_function (file, line, name, | |
6e70227d | 15995 | argc, (const char **) argv, |
2e276125 JB |
15996 | p + 1); |
15997 | else if (*p == '\0') | |
15998 | { | |
15999 | /* Complain, but do define it. */ | |
4d3c2250 | 16000 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 16001 | macro_define_function (file, line, name, |
6e70227d | 16002 | argc, (const char **) argv, |
2e276125 JB |
16003 | p); |
16004 | } | |
16005 | else | |
16006 | /* Just complain. */ | |
4d3c2250 | 16007 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
16008 | } |
16009 | else | |
16010 | /* Just complain. */ | |
4d3c2250 | 16011 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
16012 | |
16013 | xfree (name); | |
16014 | { | |
16015 | int i; | |
16016 | ||
16017 | for (i = 0; i < argc; i++) | |
16018 | xfree (argv[i]); | |
16019 | } | |
16020 | xfree (argv); | |
16021 | } | |
16022 | else | |
4d3c2250 | 16023 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
16024 | } |
16025 | ||
cf2c3c16 TT |
16026 | /* Skip some bytes from BYTES according to the form given in FORM. |
16027 | Returns the new pointer. */ | |
2e276125 | 16028 | |
cf2c3c16 | 16029 | static gdb_byte * |
f664829e | 16030 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, gdb_byte *buffer_end, |
cf2c3c16 TT |
16031 | enum dwarf_form form, |
16032 | unsigned int offset_size, | |
16033 | struct dwarf2_section_info *section) | |
2e276125 | 16034 | { |
cf2c3c16 | 16035 | unsigned int bytes_read; |
2e276125 | 16036 | |
cf2c3c16 | 16037 | switch (form) |
2e276125 | 16038 | { |
cf2c3c16 TT |
16039 | case DW_FORM_data1: |
16040 | case DW_FORM_flag: | |
16041 | ++bytes; | |
16042 | break; | |
16043 | ||
16044 | case DW_FORM_data2: | |
16045 | bytes += 2; | |
16046 | break; | |
16047 | ||
16048 | case DW_FORM_data4: | |
16049 | bytes += 4; | |
16050 | break; | |
16051 | ||
16052 | case DW_FORM_data8: | |
16053 | bytes += 8; | |
16054 | break; | |
16055 | ||
16056 | case DW_FORM_string: | |
16057 | read_direct_string (abfd, bytes, &bytes_read); | |
16058 | bytes += bytes_read; | |
16059 | break; | |
16060 | ||
16061 | case DW_FORM_sec_offset: | |
16062 | case DW_FORM_strp: | |
16063 | bytes += offset_size; | |
16064 | break; | |
16065 | ||
16066 | case DW_FORM_block: | |
16067 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); | |
16068 | bytes += bytes_read; | |
16069 | break; | |
16070 | ||
16071 | case DW_FORM_block1: | |
16072 | bytes += 1 + read_1_byte (abfd, bytes); | |
16073 | break; | |
16074 | case DW_FORM_block2: | |
16075 | bytes += 2 + read_2_bytes (abfd, bytes); | |
16076 | break; | |
16077 | case DW_FORM_block4: | |
16078 | bytes += 4 + read_4_bytes (abfd, bytes); | |
16079 | break; | |
16080 | ||
16081 | case DW_FORM_sdata: | |
16082 | case DW_FORM_udata: | |
3019eac3 DE |
16083 | case DW_FORM_GNU_addr_index: |
16084 | case DW_FORM_GNU_str_index: | |
f664829e DE |
16085 | bytes = (gdb_byte *) gdb_skip_leb128 (bytes, buffer_end); |
16086 | if (bytes == NULL) | |
16087 | { | |
16088 | dwarf2_section_buffer_overflow_complaint (section); | |
16089 | return NULL; | |
16090 | } | |
cf2c3c16 TT |
16091 | break; |
16092 | ||
16093 | default: | |
16094 | { | |
16095 | complain: | |
16096 | complaint (&symfile_complaints, | |
16097 | _("invalid form 0x%x in `%s'"), | |
16098 | form, | |
16099 | section->asection->name); | |
16100 | return NULL; | |
16101 | } | |
2e276125 JB |
16102 | } |
16103 | ||
cf2c3c16 TT |
16104 | return bytes; |
16105 | } | |
757a13d0 | 16106 | |
cf2c3c16 TT |
16107 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
16108 | opcode. Returns an updated pointer to the macro data buffer; or, | |
16109 | on error, issues a complaint and returns NULL. */ | |
757a13d0 | 16110 | |
cf2c3c16 TT |
16111 | static gdb_byte * |
16112 | skip_unknown_opcode (unsigned int opcode, | |
16113 | gdb_byte **opcode_definitions, | |
f664829e | 16114 | gdb_byte *mac_ptr, gdb_byte *mac_end, |
cf2c3c16 TT |
16115 | bfd *abfd, |
16116 | unsigned int offset_size, | |
16117 | struct dwarf2_section_info *section) | |
16118 | { | |
16119 | unsigned int bytes_read, i; | |
16120 | unsigned long arg; | |
16121 | gdb_byte *defn; | |
2e276125 | 16122 | |
cf2c3c16 | 16123 | if (opcode_definitions[opcode] == NULL) |
2e276125 | 16124 | { |
cf2c3c16 TT |
16125 | complaint (&symfile_complaints, |
16126 | _("unrecognized DW_MACFINO opcode 0x%x"), | |
16127 | opcode); | |
16128 | return NULL; | |
16129 | } | |
2e276125 | 16130 | |
cf2c3c16 TT |
16131 | defn = opcode_definitions[opcode]; |
16132 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); | |
16133 | defn += bytes_read; | |
2e276125 | 16134 | |
cf2c3c16 TT |
16135 | for (i = 0; i < arg; ++i) |
16136 | { | |
f664829e DE |
16137 | mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, defn[i], offset_size, |
16138 | section); | |
cf2c3c16 TT |
16139 | if (mac_ptr == NULL) |
16140 | { | |
16141 | /* skip_form_bytes already issued the complaint. */ | |
16142 | return NULL; | |
16143 | } | |
16144 | } | |
757a13d0 | 16145 | |
cf2c3c16 TT |
16146 | return mac_ptr; |
16147 | } | |
757a13d0 | 16148 | |
cf2c3c16 TT |
16149 | /* A helper function which parses the header of a macro section. |
16150 | If the macro section is the extended (for now called "GNU") type, | |
16151 | then this updates *OFFSET_SIZE. Returns a pointer to just after | |
16152 | the header, or issues a complaint and returns NULL on error. */ | |
757a13d0 | 16153 | |
cf2c3c16 TT |
16154 | static gdb_byte * |
16155 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, | |
16156 | bfd *abfd, | |
16157 | gdb_byte *mac_ptr, | |
16158 | unsigned int *offset_size, | |
16159 | int section_is_gnu) | |
16160 | { | |
16161 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); | |
757a13d0 | 16162 | |
cf2c3c16 TT |
16163 | if (section_is_gnu) |
16164 | { | |
16165 | unsigned int version, flags; | |
757a13d0 | 16166 | |
cf2c3c16 TT |
16167 | version = read_2_bytes (abfd, mac_ptr); |
16168 | if (version != 4) | |
16169 | { | |
16170 | complaint (&symfile_complaints, | |
16171 | _("unrecognized version `%d' in .debug_macro section"), | |
16172 | version); | |
16173 | return NULL; | |
16174 | } | |
16175 | mac_ptr += 2; | |
757a13d0 | 16176 | |
cf2c3c16 TT |
16177 | flags = read_1_byte (abfd, mac_ptr); |
16178 | ++mac_ptr; | |
16179 | *offset_size = (flags & 1) ? 8 : 4; | |
757a13d0 | 16180 | |
cf2c3c16 TT |
16181 | if ((flags & 2) != 0) |
16182 | /* We don't need the line table offset. */ | |
16183 | mac_ptr += *offset_size; | |
757a13d0 | 16184 | |
cf2c3c16 TT |
16185 | /* Vendor opcode descriptions. */ |
16186 | if ((flags & 4) != 0) | |
16187 | { | |
16188 | unsigned int i, count; | |
757a13d0 | 16189 | |
cf2c3c16 TT |
16190 | count = read_1_byte (abfd, mac_ptr); |
16191 | ++mac_ptr; | |
16192 | for (i = 0; i < count; ++i) | |
16193 | { | |
16194 | unsigned int opcode, bytes_read; | |
16195 | unsigned long arg; | |
16196 | ||
16197 | opcode = read_1_byte (abfd, mac_ptr); | |
16198 | ++mac_ptr; | |
16199 | opcode_definitions[opcode] = mac_ptr; | |
16200 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16201 | mac_ptr += bytes_read; | |
16202 | mac_ptr += arg; | |
16203 | } | |
757a13d0 | 16204 | } |
cf2c3c16 | 16205 | } |
757a13d0 | 16206 | |
cf2c3c16 TT |
16207 | return mac_ptr; |
16208 | } | |
757a13d0 | 16209 | |
cf2c3c16 | 16210 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
8fc3fc34 | 16211 | including DW_MACRO_GNU_transparent_include. */ |
cf2c3c16 TT |
16212 | |
16213 | static void | |
16214 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, | |
16215 | struct macro_source_file *current_file, | |
16216 | struct line_header *lh, char *comp_dir, | |
16217 | struct dwarf2_section_info *section, | |
16218 | int section_is_gnu, | |
16219 | unsigned int offset_size, | |
8fc3fc34 TT |
16220 | struct objfile *objfile, |
16221 | htab_t include_hash) | |
cf2c3c16 TT |
16222 | { |
16223 | enum dwarf_macro_record_type macinfo_type; | |
16224 | int at_commandline; | |
16225 | gdb_byte *opcode_definitions[256]; | |
757a13d0 | 16226 | |
cf2c3c16 TT |
16227 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
16228 | &offset_size, section_is_gnu); | |
16229 | if (mac_ptr == NULL) | |
16230 | { | |
16231 | /* We already issued a complaint. */ | |
16232 | return; | |
16233 | } | |
757a13d0 JK |
16234 | |
16235 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
16236 | GDB is still reading the definitions from command line. First | |
16237 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
16238 | to create CURRENT_FILE for the main source holding also the command line | |
16239 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
16240 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
16241 | ||
16242 | at_commandline = 1; | |
16243 | ||
16244 | do | |
16245 | { | |
16246 | /* Do we at least have room for a macinfo type byte? */ | |
16247 | if (mac_ptr >= mac_end) | |
16248 | { | |
f664829e | 16249 | dwarf2_section_buffer_overflow_complaint (section); |
757a13d0 JK |
16250 | break; |
16251 | } | |
16252 | ||
16253 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
16254 | mac_ptr++; | |
16255 | ||
cf2c3c16 TT |
16256 | /* Note that we rely on the fact that the corresponding GNU and |
16257 | DWARF constants are the same. */ | |
757a13d0 JK |
16258 | switch (macinfo_type) |
16259 | { | |
16260 | /* A zero macinfo type indicates the end of the macro | |
16261 | information. */ | |
16262 | case 0: | |
16263 | break; | |
2e276125 | 16264 | |
cf2c3c16 TT |
16265 | case DW_MACRO_GNU_define: |
16266 | case DW_MACRO_GNU_undef: | |
16267 | case DW_MACRO_GNU_define_indirect: | |
16268 | case DW_MACRO_GNU_undef_indirect: | |
2e276125 | 16269 | { |
891d2f0b | 16270 | unsigned int bytes_read; |
2e276125 JB |
16271 | int line; |
16272 | char *body; | |
cf2c3c16 | 16273 | int is_define; |
2e276125 | 16274 | |
cf2c3c16 TT |
16275 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
16276 | mac_ptr += bytes_read; | |
16277 | ||
16278 | if (macinfo_type == DW_MACRO_GNU_define | |
16279 | || macinfo_type == DW_MACRO_GNU_undef) | |
16280 | { | |
16281 | body = read_direct_string (abfd, mac_ptr, &bytes_read); | |
16282 | mac_ptr += bytes_read; | |
16283 | } | |
16284 | else | |
16285 | { | |
16286 | LONGEST str_offset; | |
16287 | ||
16288 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
16289 | mac_ptr += offset_size; | |
2e276125 | 16290 | |
cf2c3c16 TT |
16291 | body = read_indirect_string_at_offset (abfd, str_offset); |
16292 | } | |
16293 | ||
16294 | is_define = (macinfo_type == DW_MACRO_GNU_define | |
16295 | || macinfo_type == DW_MACRO_GNU_define_indirect); | |
2e276125 | 16296 | if (! current_file) |
757a13d0 JK |
16297 | { |
16298 | /* DWARF violation as no main source is present. */ | |
16299 | complaint (&symfile_complaints, | |
16300 | _("debug info with no main source gives macro %s " | |
16301 | "on line %d: %s"), | |
cf2c3c16 TT |
16302 | is_define ? _("definition") : _("undefinition"), |
16303 | line, body); | |
757a13d0 JK |
16304 | break; |
16305 | } | |
3e43a32a MS |
16306 | if ((line == 0 && !at_commandline) |
16307 | || (line != 0 && at_commandline)) | |
4d3c2250 | 16308 | complaint (&symfile_complaints, |
757a13d0 JK |
16309 | _("debug info gives %s macro %s with %s line %d: %s"), |
16310 | at_commandline ? _("command-line") : _("in-file"), | |
cf2c3c16 | 16311 | is_define ? _("definition") : _("undefinition"), |
757a13d0 JK |
16312 | line == 0 ? _("zero") : _("non-zero"), line, body); |
16313 | ||
cf2c3c16 | 16314 | if (is_define) |
757a13d0 | 16315 | parse_macro_definition (current_file, line, body); |
cf2c3c16 TT |
16316 | else |
16317 | { | |
16318 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef | |
16319 | || macinfo_type == DW_MACRO_GNU_undef_indirect); | |
16320 | macro_undef (current_file, line, body); | |
16321 | } | |
2e276125 JB |
16322 | } |
16323 | break; | |
16324 | ||
cf2c3c16 | 16325 | case DW_MACRO_GNU_start_file: |
2e276125 | 16326 | { |
891d2f0b | 16327 | unsigned int bytes_read; |
2e276125 JB |
16328 | int line, file; |
16329 | ||
16330 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16331 | mac_ptr += bytes_read; | |
16332 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16333 | mac_ptr += bytes_read; | |
16334 | ||
3e43a32a MS |
16335 | if ((line == 0 && !at_commandline) |
16336 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
16337 | complaint (&symfile_complaints, |
16338 | _("debug info gives source %d included " | |
16339 | "from %s at %s line %d"), | |
16340 | file, at_commandline ? _("command-line") : _("file"), | |
16341 | line == 0 ? _("zero") : _("non-zero"), line); | |
16342 | ||
16343 | if (at_commandline) | |
16344 | { | |
cf2c3c16 TT |
16345 | /* This DW_MACRO_GNU_start_file was executed in the |
16346 | pass one. */ | |
757a13d0 JK |
16347 | at_commandline = 0; |
16348 | } | |
16349 | else | |
16350 | current_file = macro_start_file (file, line, | |
16351 | current_file, comp_dir, | |
cf2c3c16 | 16352 | lh, objfile); |
2e276125 JB |
16353 | } |
16354 | break; | |
16355 | ||
cf2c3c16 | 16356 | case DW_MACRO_GNU_end_file: |
2e276125 | 16357 | if (! current_file) |
4d3c2250 | 16358 | complaint (&symfile_complaints, |
3e43a32a MS |
16359 | _("macro debug info has an unmatched " |
16360 | "`close_file' directive")); | |
2e276125 JB |
16361 | else |
16362 | { | |
16363 | current_file = current_file->included_by; | |
16364 | if (! current_file) | |
16365 | { | |
cf2c3c16 | 16366 | enum dwarf_macro_record_type next_type; |
2e276125 JB |
16367 | |
16368 | /* GCC circa March 2002 doesn't produce the zero | |
16369 | type byte marking the end of the compilation | |
16370 | unit. Complain if it's not there, but exit no | |
16371 | matter what. */ | |
16372 | ||
16373 | /* Do we at least have room for a macinfo type byte? */ | |
16374 | if (mac_ptr >= mac_end) | |
16375 | { | |
f664829e | 16376 | dwarf2_section_buffer_overflow_complaint (section); |
2e276125 JB |
16377 | return; |
16378 | } | |
16379 | ||
16380 | /* We don't increment mac_ptr here, so this is just | |
16381 | a look-ahead. */ | |
16382 | next_type = read_1_byte (abfd, mac_ptr); | |
16383 | if (next_type != 0) | |
4d3c2250 | 16384 | complaint (&symfile_complaints, |
3e43a32a MS |
16385 | _("no terminating 0-type entry for " |
16386 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
16387 | |
16388 | return; | |
16389 | } | |
16390 | } | |
16391 | break; | |
16392 | ||
cf2c3c16 TT |
16393 | case DW_MACRO_GNU_transparent_include: |
16394 | { | |
16395 | LONGEST offset; | |
8fc3fc34 | 16396 | void **slot; |
cf2c3c16 TT |
16397 | |
16398 | offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
16399 | mac_ptr += offset_size; | |
16400 | ||
8fc3fc34 TT |
16401 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); |
16402 | if (*slot != NULL) | |
16403 | { | |
16404 | /* This has actually happened; see | |
16405 | http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */ | |
16406 | complaint (&symfile_complaints, | |
16407 | _("recursive DW_MACRO_GNU_transparent_include in " | |
16408 | ".debug_macro section")); | |
16409 | } | |
16410 | else | |
16411 | { | |
16412 | *slot = mac_ptr; | |
16413 | ||
16414 | dwarf_decode_macro_bytes (abfd, | |
16415 | section->buffer + offset, | |
16416 | mac_end, current_file, | |
16417 | lh, comp_dir, | |
16418 | section, section_is_gnu, | |
16419 | offset_size, objfile, include_hash); | |
16420 | ||
16421 | htab_remove_elt (include_hash, mac_ptr); | |
16422 | } | |
cf2c3c16 TT |
16423 | } |
16424 | break; | |
16425 | ||
2e276125 | 16426 | case DW_MACINFO_vendor_ext: |
cf2c3c16 TT |
16427 | if (!section_is_gnu) |
16428 | { | |
16429 | unsigned int bytes_read; | |
16430 | int constant; | |
2e276125 | 16431 | |
cf2c3c16 TT |
16432 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
16433 | mac_ptr += bytes_read; | |
16434 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
16435 | mac_ptr += bytes_read; | |
2e276125 | 16436 | |
cf2c3c16 TT |
16437 | /* We don't recognize any vendor extensions. */ |
16438 | break; | |
16439 | } | |
16440 | /* FALLTHROUGH */ | |
16441 | ||
16442 | default: | |
16443 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
f664829e | 16444 | mac_ptr, mac_end, abfd, offset_size, |
cf2c3c16 TT |
16445 | section); |
16446 | if (mac_ptr == NULL) | |
16447 | return; | |
16448 | break; | |
2e276125 | 16449 | } |
757a13d0 | 16450 | } while (macinfo_type != 0); |
2e276125 | 16451 | } |
8e19ed76 | 16452 | |
cf2c3c16 | 16453 | static void |
09262596 DE |
16454 | dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset, |
16455 | char *comp_dir, int section_is_gnu) | |
cf2c3c16 | 16456 | { |
bb5ed363 | 16457 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
09262596 DE |
16458 | struct line_header *lh = cu->line_header; |
16459 | bfd *abfd; | |
cf2c3c16 TT |
16460 | gdb_byte *mac_ptr, *mac_end; |
16461 | struct macro_source_file *current_file = 0; | |
16462 | enum dwarf_macro_record_type macinfo_type; | |
16463 | unsigned int offset_size = cu->header.offset_size; | |
16464 | gdb_byte *opcode_definitions[256]; | |
8fc3fc34 TT |
16465 | struct cleanup *cleanup; |
16466 | htab_t include_hash; | |
16467 | void **slot; | |
09262596 DE |
16468 | struct dwarf2_section_info *section; |
16469 | const char *section_name; | |
16470 | ||
16471 | if (cu->dwo_unit != NULL) | |
16472 | { | |
16473 | if (section_is_gnu) | |
16474 | { | |
16475 | section = &cu->dwo_unit->dwo_file->sections.macro; | |
16476 | section_name = ".debug_macro.dwo"; | |
16477 | } | |
16478 | else | |
16479 | { | |
16480 | section = &cu->dwo_unit->dwo_file->sections.macinfo; | |
16481 | section_name = ".debug_macinfo.dwo"; | |
16482 | } | |
16483 | } | |
16484 | else | |
16485 | { | |
16486 | if (section_is_gnu) | |
16487 | { | |
16488 | section = &dwarf2_per_objfile->macro; | |
16489 | section_name = ".debug_macro"; | |
16490 | } | |
16491 | else | |
16492 | { | |
16493 | section = &dwarf2_per_objfile->macinfo; | |
16494 | section_name = ".debug_macinfo"; | |
16495 | } | |
16496 | } | |
cf2c3c16 | 16497 | |
bb5ed363 | 16498 | dwarf2_read_section (objfile, section); |
cf2c3c16 TT |
16499 | if (section->buffer == NULL) |
16500 | { | |
fceca515 | 16501 | complaint (&symfile_complaints, _("missing %s section"), section_name); |
cf2c3c16 TT |
16502 | return; |
16503 | } | |
09262596 | 16504 | abfd = section->asection->owner; |
cf2c3c16 TT |
16505 | |
16506 | /* First pass: Find the name of the base filename. | |
16507 | This filename is needed in order to process all macros whose definition | |
16508 | (or undefinition) comes from the command line. These macros are defined | |
16509 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
16510 | associated to the base file. | |
16511 | ||
16512 | To determine the base file name, we scan the macro definitions until we | |
16513 | reach the first DW_MACINFO_start_file entry. We then initialize | |
16514 | CURRENT_FILE accordingly so that any macro definition found before the | |
16515 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
16516 | ||
16517 | mac_ptr = section->buffer + offset; | |
16518 | mac_end = section->buffer + section->size; | |
16519 | ||
16520 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, | |
16521 | &offset_size, section_is_gnu); | |
16522 | if (mac_ptr == NULL) | |
16523 | { | |
16524 | /* We already issued a complaint. */ | |
16525 | return; | |
16526 | } | |
16527 | ||
16528 | do | |
16529 | { | |
16530 | /* Do we at least have room for a macinfo type byte? */ | |
16531 | if (mac_ptr >= mac_end) | |
16532 | { | |
16533 | /* Complaint is printed during the second pass as GDB will probably | |
16534 | stop the first pass earlier upon finding | |
16535 | DW_MACINFO_start_file. */ | |
16536 | break; | |
16537 | } | |
16538 | ||
16539 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
16540 | mac_ptr++; | |
16541 | ||
16542 | /* Note that we rely on the fact that the corresponding GNU and | |
16543 | DWARF constants are the same. */ | |
16544 | switch (macinfo_type) | |
16545 | { | |
16546 | /* A zero macinfo type indicates the end of the macro | |
16547 | information. */ | |
16548 | case 0: | |
16549 | break; | |
16550 | ||
16551 | case DW_MACRO_GNU_define: | |
16552 | case DW_MACRO_GNU_undef: | |
16553 | /* Only skip the data by MAC_PTR. */ | |
16554 | { | |
16555 | unsigned int bytes_read; | |
16556 | ||
16557 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16558 | mac_ptr += bytes_read; | |
16559 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
16560 | mac_ptr += bytes_read; | |
16561 | } | |
16562 | break; | |
16563 | ||
16564 | case DW_MACRO_GNU_start_file: | |
16565 | { | |
16566 | unsigned int bytes_read; | |
16567 | int line, file; | |
16568 | ||
16569 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16570 | mac_ptr += bytes_read; | |
16571 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16572 | mac_ptr += bytes_read; | |
16573 | ||
16574 | current_file = macro_start_file (file, line, current_file, | |
bb5ed363 | 16575 | comp_dir, lh, objfile); |
cf2c3c16 TT |
16576 | } |
16577 | break; | |
16578 | ||
16579 | case DW_MACRO_GNU_end_file: | |
16580 | /* No data to skip by MAC_PTR. */ | |
16581 | break; | |
16582 | ||
16583 | case DW_MACRO_GNU_define_indirect: | |
16584 | case DW_MACRO_GNU_undef_indirect: | |
16585 | { | |
16586 | unsigned int bytes_read; | |
16587 | ||
16588 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16589 | mac_ptr += bytes_read; | |
16590 | mac_ptr += offset_size; | |
16591 | } | |
16592 | break; | |
16593 | ||
16594 | case DW_MACRO_GNU_transparent_include: | |
16595 | /* Note that, according to the spec, a transparent include | |
16596 | chain cannot call DW_MACRO_GNU_start_file. So, we can just | |
16597 | skip this opcode. */ | |
16598 | mac_ptr += offset_size; | |
16599 | break; | |
16600 | ||
16601 | case DW_MACINFO_vendor_ext: | |
16602 | /* Only skip the data by MAC_PTR. */ | |
16603 | if (!section_is_gnu) | |
16604 | { | |
16605 | unsigned int bytes_read; | |
16606 | ||
16607 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16608 | mac_ptr += bytes_read; | |
16609 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
16610 | mac_ptr += bytes_read; | |
16611 | } | |
16612 | /* FALLTHROUGH */ | |
16613 | ||
16614 | default: | |
16615 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
f664829e | 16616 | mac_ptr, mac_end, abfd, offset_size, |
cf2c3c16 TT |
16617 | section); |
16618 | if (mac_ptr == NULL) | |
16619 | return; | |
16620 | break; | |
16621 | } | |
16622 | } while (macinfo_type != 0 && current_file == NULL); | |
16623 | ||
16624 | /* Second pass: Process all entries. | |
16625 | ||
16626 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
16627 | command-line macro definitions/undefinitions. This flag is unset when we | |
16628 | reach the first DW_MACINFO_start_file entry. */ | |
16629 | ||
8fc3fc34 TT |
16630 | include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, |
16631 | NULL, xcalloc, xfree); | |
16632 | cleanup = make_cleanup_htab_delete (include_hash); | |
16633 | mac_ptr = section->buffer + offset; | |
16634 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); | |
16635 | *slot = mac_ptr; | |
16636 | dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end, | |
cf2c3c16 | 16637 | current_file, lh, comp_dir, section, section_is_gnu, |
8fc3fc34 TT |
16638 | offset_size, objfile, include_hash); |
16639 | do_cleanups (cleanup); | |
cf2c3c16 TT |
16640 | } |
16641 | ||
8e19ed76 | 16642 | /* Check if the attribute's form is a DW_FORM_block* |
0963b4bd | 16643 | if so return true else false. */ |
380bca97 | 16644 | |
8e19ed76 PS |
16645 | static int |
16646 | attr_form_is_block (struct attribute *attr) | |
16647 | { | |
16648 | return (attr == NULL ? 0 : | |
16649 | attr->form == DW_FORM_block1 | |
16650 | || attr->form == DW_FORM_block2 | |
16651 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
16652 | || attr->form == DW_FORM_block |
16653 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 16654 | } |
4c2df51b | 16655 | |
c6a0999f JB |
16656 | /* Return non-zero if ATTR's value is a section offset --- classes |
16657 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
16658 | You may use DW_UNSND (attr) to retrieve such offsets. | |
16659 | ||
16660 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
16661 | may have a value that belongs to more than one of these classes; it | |
16662 | would be ambiguous if we did, because we use the same forms for all | |
16663 | of them. */ | |
380bca97 | 16664 | |
3690dd37 JB |
16665 | static int |
16666 | attr_form_is_section_offset (struct attribute *attr) | |
16667 | { | |
16668 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
16669 | || attr->form == DW_FORM_data8 |
16670 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
16671 | } |
16672 | ||
3690dd37 JB |
16673 | /* Return non-zero if ATTR's value falls in the 'constant' class, or |
16674 | zero otherwise. When this function returns true, you can apply | |
16675 | dwarf2_get_attr_constant_value to it. | |
16676 | ||
16677 | However, note that for some attributes you must check | |
16678 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
16679 | and DW_FORM_data8 are members of both the constant class, and of | |
16680 | the classes that contain offsets into other debug sections | |
16681 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
16682 | that, if an attribute's can be either a constant or one of the | |
16683 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
16684 | taken as section offsets, not constants. */ | |
380bca97 | 16685 | |
3690dd37 JB |
16686 | static int |
16687 | attr_form_is_constant (struct attribute *attr) | |
16688 | { | |
16689 | switch (attr->form) | |
16690 | { | |
16691 | case DW_FORM_sdata: | |
16692 | case DW_FORM_udata: | |
16693 | case DW_FORM_data1: | |
16694 | case DW_FORM_data2: | |
16695 | case DW_FORM_data4: | |
16696 | case DW_FORM_data8: | |
16697 | return 1; | |
16698 | default: | |
16699 | return 0; | |
16700 | } | |
16701 | } | |
16702 | ||
3019eac3 DE |
16703 | /* Return the .debug_loc section to use for CU. |
16704 | For DWO files use .debug_loc.dwo. */ | |
16705 | ||
16706 | static struct dwarf2_section_info * | |
16707 | cu_debug_loc_section (struct dwarf2_cu *cu) | |
16708 | { | |
16709 | if (cu->dwo_unit) | |
16710 | return &cu->dwo_unit->dwo_file->sections.loc; | |
16711 | return &dwarf2_per_objfile->loc; | |
16712 | } | |
16713 | ||
8cf6f0b1 TT |
16714 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
16715 | ||
16716 | static void | |
16717 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
16718 | struct dwarf2_loclist_baton *baton, | |
16719 | struct attribute *attr) | |
16720 | { | |
3019eac3 DE |
16721 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
16722 | ||
16723 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); | |
8cf6f0b1 TT |
16724 | |
16725 | baton->per_cu = cu->per_cu; | |
16726 | gdb_assert (baton->per_cu); | |
16727 | /* We don't know how long the location list is, but make sure we | |
16728 | don't run off the edge of the section. */ | |
3019eac3 DE |
16729 | baton->size = section->size - DW_UNSND (attr); |
16730 | baton->data = section->buffer + DW_UNSND (attr); | |
8cf6f0b1 | 16731 | baton->base_address = cu->base_address; |
f664829e | 16732 | baton->from_dwo = cu->dwo_unit != NULL; |
8cf6f0b1 TT |
16733 | } |
16734 | ||
4c2df51b DJ |
16735 | static void |
16736 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 16737 | struct dwarf2_cu *cu) |
4c2df51b | 16738 | { |
bb5ed363 | 16739 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
3019eac3 | 16740 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
bb5ed363 | 16741 | |
3690dd37 | 16742 | if (attr_form_is_section_offset (attr) |
3019eac3 | 16743 | /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside |
99bcc461 DJ |
16744 | the section. If so, fall through to the complaint in the |
16745 | other branch. */ | |
3019eac3 | 16746 | && DW_UNSND (attr) < dwarf2_section_size (objfile, section)) |
4c2df51b | 16747 | { |
0d53c4c4 | 16748 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 16749 | |
bb5ed363 | 16750 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 16751 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 16752 | |
8cf6f0b1 | 16753 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 16754 | |
d00adf39 | 16755 | if (cu->base_known == 0) |
0d53c4c4 | 16756 | complaint (&symfile_complaints, |
3e43a32a MS |
16757 | _("Location list used without " |
16758 | "specifying the CU base address.")); | |
4c2df51b | 16759 | |
768a979c | 16760 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
16761 | SYMBOL_LOCATION_BATON (sym) = baton; |
16762 | } | |
16763 | else | |
16764 | { | |
16765 | struct dwarf2_locexpr_baton *baton; | |
16766 | ||
bb5ed363 | 16767 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 16768 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
16769 | baton->per_cu = cu->per_cu; |
16770 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
16771 | |
16772 | if (attr_form_is_block (attr)) | |
16773 | { | |
16774 | /* Note that we're just copying the block's data pointer | |
16775 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
16776 | info_buffer for SYM's objfile; right now we never release |
16777 | that buffer, but when we do clean up properly this may | |
16778 | need to change. */ | |
0d53c4c4 DJ |
16779 | baton->size = DW_BLOCK (attr)->size; |
16780 | baton->data = DW_BLOCK (attr)->data; | |
16781 | } | |
16782 | else | |
16783 | { | |
16784 | dwarf2_invalid_attrib_class_complaint ("location description", | |
16785 | SYMBOL_NATURAL_NAME (sym)); | |
16786 | baton->size = 0; | |
0d53c4c4 | 16787 | } |
6e70227d | 16788 | |
768a979c | 16789 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
16790 | SYMBOL_LOCATION_BATON (sym) = baton; |
16791 | } | |
4c2df51b | 16792 | } |
6502dd73 | 16793 | |
9aa1f1e3 TT |
16794 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
16795 | came from a separate debuginfo file, then the master objfile is | |
16796 | returned. */ | |
ae0d2f24 UW |
16797 | |
16798 | struct objfile * | |
16799 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
16800 | { | |
9291a0cd | 16801 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
16802 | |
16803 | /* Return the master objfile, so that we can report and look up the | |
16804 | correct file containing this variable. */ | |
16805 | if (objfile->separate_debug_objfile_backlink) | |
16806 | objfile = objfile->separate_debug_objfile_backlink; | |
16807 | ||
16808 | return objfile; | |
16809 | } | |
16810 | ||
96408a79 SA |
16811 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
16812 | (CU_HEADERP is unused in such case) or prepare a temporary copy at | |
16813 | CU_HEADERP first. */ | |
16814 | ||
16815 | static const struct comp_unit_head * | |
16816 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, | |
16817 | struct dwarf2_per_cu_data *per_cu) | |
16818 | { | |
96408a79 SA |
16819 | gdb_byte *info_ptr; |
16820 | ||
16821 | if (per_cu->cu) | |
16822 | return &per_cu->cu->header; | |
16823 | ||
0bc3a05c | 16824 | info_ptr = per_cu->info_or_types_section->buffer + per_cu->offset.sect_off; |
96408a79 SA |
16825 | |
16826 | memset (cu_headerp, 0, sizeof (*cu_headerp)); | |
0bc3a05c | 16827 | read_comp_unit_head (cu_headerp, info_ptr, per_cu->objfile->obfd); |
96408a79 SA |
16828 | |
16829 | return cu_headerp; | |
16830 | } | |
16831 | ||
ae0d2f24 UW |
16832 | /* Return the address size given in the compilation unit header for CU. */ |
16833 | ||
98714339 | 16834 | int |
ae0d2f24 UW |
16835 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
16836 | { | |
96408a79 SA |
16837 | struct comp_unit_head cu_header_local; |
16838 | const struct comp_unit_head *cu_headerp; | |
c471e790 | 16839 | |
96408a79 SA |
16840 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
16841 | ||
16842 | return cu_headerp->addr_size; | |
ae0d2f24 UW |
16843 | } |
16844 | ||
9eae7c52 TT |
16845 | /* Return the offset size given in the compilation unit header for CU. */ |
16846 | ||
16847 | int | |
16848 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
16849 | { | |
96408a79 SA |
16850 | struct comp_unit_head cu_header_local; |
16851 | const struct comp_unit_head *cu_headerp; | |
9c6c53f7 | 16852 | |
96408a79 SA |
16853 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
16854 | ||
16855 | return cu_headerp->offset_size; | |
16856 | } | |
16857 | ||
16858 | /* See its dwarf2loc.h declaration. */ | |
16859 | ||
16860 | int | |
16861 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) | |
16862 | { | |
16863 | struct comp_unit_head cu_header_local; | |
16864 | const struct comp_unit_head *cu_headerp; | |
16865 | ||
16866 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); | |
16867 | ||
16868 | if (cu_headerp->version == 2) | |
16869 | return cu_headerp->addr_size; | |
16870 | else | |
16871 | return cu_headerp->offset_size; | |
181cebd4 JK |
16872 | } |
16873 | ||
9aa1f1e3 TT |
16874 | /* Return the text offset of the CU. The returned offset comes from |
16875 | this CU's objfile. If this objfile came from a separate debuginfo | |
16876 | file, then the offset may be different from the corresponding | |
16877 | offset in the parent objfile. */ | |
16878 | ||
16879 | CORE_ADDR | |
16880 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
16881 | { | |
bb3fa9d0 | 16882 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
16883 | |
16884 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
16885 | } | |
16886 | ||
348e048f DE |
16887 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
16888 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
16889 | |
16890 | static struct dwarf2_per_cu_data * | |
b64f50a1 | 16891 | dwarf2_find_containing_comp_unit (sect_offset offset, |
ae038cb0 DJ |
16892 | struct objfile *objfile) |
16893 | { | |
16894 | struct dwarf2_per_cu_data *this_cu; | |
16895 | int low, high; | |
16896 | ||
ae038cb0 DJ |
16897 | low = 0; |
16898 | high = dwarf2_per_objfile->n_comp_units - 1; | |
16899 | while (high > low) | |
16900 | { | |
16901 | int mid = low + (high - low) / 2; | |
9a619af0 | 16902 | |
b64f50a1 JK |
16903 | if (dwarf2_per_objfile->all_comp_units[mid]->offset.sect_off |
16904 | >= offset.sect_off) | |
ae038cb0 DJ |
16905 | high = mid; |
16906 | else | |
16907 | low = mid + 1; | |
16908 | } | |
16909 | gdb_assert (low == high); | |
b64f50a1 JK |
16910 | if (dwarf2_per_objfile->all_comp_units[low]->offset.sect_off |
16911 | > offset.sect_off) | |
ae038cb0 | 16912 | { |
10b3939b | 16913 | if (low == 0) |
8a3fe4f8 AC |
16914 | error (_("Dwarf Error: could not find partial DIE containing " |
16915 | "offset 0x%lx [in module %s]"), | |
b64f50a1 | 16916 | (long) offset.sect_off, bfd_get_filename (objfile->obfd)); |
10b3939b | 16917 | |
b64f50a1 JK |
16918 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset.sect_off |
16919 | <= offset.sect_off); | |
ae038cb0 DJ |
16920 | return dwarf2_per_objfile->all_comp_units[low-1]; |
16921 | } | |
16922 | else | |
16923 | { | |
16924 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
16925 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
b64f50a1 JK |
16926 | && offset.sect_off >= this_cu->offset.sect_off + this_cu->length) |
16927 | error (_("invalid dwarf2 offset %u"), offset.sect_off); | |
16928 | gdb_assert (offset.sect_off < this_cu->offset.sect_off + this_cu->length); | |
ae038cb0 DJ |
16929 | return this_cu; |
16930 | } | |
16931 | } | |
16932 | ||
23745b47 | 16933 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
93311388 | 16934 | |
9816fde3 | 16935 | static void |
23745b47 | 16936 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
93311388 | 16937 | { |
9816fde3 | 16938 | memset (cu, 0, sizeof (*cu)); |
23745b47 DE |
16939 | per_cu->cu = cu; |
16940 | cu->per_cu = per_cu; | |
16941 | cu->objfile = per_cu->objfile; | |
93311388 | 16942 | obstack_init (&cu->comp_unit_obstack); |
9816fde3 JK |
16943 | } |
16944 | ||
16945 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
16946 | ||
16947 | static void | |
95554aad TT |
16948 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die, |
16949 | enum language pretend_language) | |
9816fde3 JK |
16950 | { |
16951 | struct attribute *attr; | |
16952 | ||
16953 | /* Set the language we're debugging. */ | |
16954 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
16955 | if (attr) | |
16956 | set_cu_language (DW_UNSND (attr), cu); | |
16957 | else | |
9cded63f | 16958 | { |
95554aad | 16959 | cu->language = pretend_language; |
9cded63f TT |
16960 | cu->language_defn = language_def (cu->language); |
16961 | } | |
dee91e82 DE |
16962 | |
16963 | attr = dwarf2_attr (comp_unit_die, DW_AT_producer, cu); | |
16964 | if (attr) | |
16965 | cu->producer = DW_STRING (attr); | |
93311388 DE |
16966 | } |
16967 | ||
ae038cb0 DJ |
16968 | /* Release one cached compilation unit, CU. We unlink it from the tree |
16969 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
16970 | the caller is responsible for that. |
16971 | NOTE: DATA is a void * because this function is also used as a | |
16972 | cleanup routine. */ | |
ae038cb0 DJ |
16973 | |
16974 | static void | |
68dc6402 | 16975 | free_heap_comp_unit (void *data) |
ae038cb0 DJ |
16976 | { |
16977 | struct dwarf2_cu *cu = data; | |
16978 | ||
23745b47 DE |
16979 | gdb_assert (cu->per_cu != NULL); |
16980 | cu->per_cu->cu = NULL; | |
ae038cb0 DJ |
16981 | cu->per_cu = NULL; |
16982 | ||
16983 | obstack_free (&cu->comp_unit_obstack, NULL); | |
16984 | ||
16985 | xfree (cu); | |
16986 | } | |
16987 | ||
72bf9492 | 16988 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 | 16989 | when we're finished with it. We can't free the pointer itself, but be |
dee91e82 | 16990 | sure to unlink it from the cache. Also release any associated storage. */ |
72bf9492 DJ |
16991 | |
16992 | static void | |
16993 | free_stack_comp_unit (void *data) | |
16994 | { | |
16995 | struct dwarf2_cu *cu = data; | |
16996 | ||
23745b47 DE |
16997 | gdb_assert (cu->per_cu != NULL); |
16998 | cu->per_cu->cu = NULL; | |
16999 | cu->per_cu = NULL; | |
17000 | ||
72bf9492 DJ |
17001 | obstack_free (&cu->comp_unit_obstack, NULL); |
17002 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
17003 | } |
17004 | ||
17005 | /* Free all cached compilation units. */ | |
17006 | ||
17007 | static void | |
17008 | free_cached_comp_units (void *data) | |
17009 | { | |
17010 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
17011 | ||
17012 | per_cu = dwarf2_per_objfile->read_in_chain; | |
17013 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
17014 | while (per_cu != NULL) | |
17015 | { | |
17016 | struct dwarf2_per_cu_data *next_cu; | |
17017 | ||
17018 | next_cu = per_cu->cu->read_in_chain; | |
17019 | ||
68dc6402 | 17020 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
17021 | *last_chain = next_cu; |
17022 | ||
17023 | per_cu = next_cu; | |
17024 | } | |
17025 | } | |
17026 | ||
17027 | /* Increase the age counter on each cached compilation unit, and free | |
17028 | any that are too old. */ | |
17029 | ||
17030 | static void | |
17031 | age_cached_comp_units (void) | |
17032 | { | |
17033 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
17034 | ||
17035 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
17036 | per_cu = dwarf2_per_objfile->read_in_chain; | |
17037 | while (per_cu != NULL) | |
17038 | { | |
17039 | per_cu->cu->last_used ++; | |
17040 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
17041 | dwarf2_mark (per_cu->cu); | |
17042 | per_cu = per_cu->cu->read_in_chain; | |
17043 | } | |
17044 | ||
17045 | per_cu = dwarf2_per_objfile->read_in_chain; | |
17046 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
17047 | while (per_cu != NULL) | |
17048 | { | |
17049 | struct dwarf2_per_cu_data *next_cu; | |
17050 | ||
17051 | next_cu = per_cu->cu->read_in_chain; | |
17052 | ||
17053 | if (!per_cu->cu->mark) | |
17054 | { | |
68dc6402 | 17055 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
17056 | *last_chain = next_cu; |
17057 | } | |
17058 | else | |
17059 | last_chain = &per_cu->cu->read_in_chain; | |
17060 | ||
17061 | per_cu = next_cu; | |
17062 | } | |
17063 | } | |
17064 | ||
17065 | /* Remove a single compilation unit from the cache. */ | |
17066 | ||
17067 | static void | |
dee91e82 | 17068 | free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu) |
ae038cb0 DJ |
17069 | { |
17070 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
17071 | ||
17072 | per_cu = dwarf2_per_objfile->read_in_chain; | |
17073 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
17074 | while (per_cu != NULL) | |
17075 | { | |
17076 | struct dwarf2_per_cu_data *next_cu; | |
17077 | ||
17078 | next_cu = per_cu->cu->read_in_chain; | |
17079 | ||
dee91e82 | 17080 | if (per_cu == target_per_cu) |
ae038cb0 | 17081 | { |
68dc6402 | 17082 | free_heap_comp_unit (per_cu->cu); |
dee91e82 | 17083 | per_cu->cu = NULL; |
ae038cb0 DJ |
17084 | *last_chain = next_cu; |
17085 | break; | |
17086 | } | |
17087 | else | |
17088 | last_chain = &per_cu->cu->read_in_chain; | |
17089 | ||
17090 | per_cu = next_cu; | |
17091 | } | |
17092 | } | |
17093 | ||
fe3e1990 DJ |
17094 | /* Release all extra memory associated with OBJFILE. */ |
17095 | ||
17096 | void | |
17097 | dwarf2_free_objfile (struct objfile *objfile) | |
17098 | { | |
17099 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
17100 | ||
17101 | if (dwarf2_per_objfile == NULL) | |
17102 | return; | |
17103 | ||
17104 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
17105 | free_cached_comp_units (NULL); | |
17106 | ||
7b9f3c50 DE |
17107 | if (dwarf2_per_objfile->quick_file_names_table) |
17108 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 17109 | |
fe3e1990 DJ |
17110 | /* Everything else should be on the objfile obstack. */ |
17111 | } | |
17112 | ||
dee91e82 DE |
17113 | /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer. |
17114 | We store these in a hash table separate from the DIEs, and preserve them | |
17115 | when the DIEs are flushed out of cache. | |
17116 | ||
17117 | The CU "per_cu" pointer is needed because offset alone is not enough to | |
3019eac3 DE |
17118 | uniquely identify the type. A file may have multiple .debug_types sections, |
17119 | or the type may come from a DWO file. We have to use something in | |
17120 | dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup | |
17121 | routine, get_die_type_at_offset, from outside this file, and thus won't | |
17122 | necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life | |
17123 | of the objfile. */ | |
1c379e20 | 17124 | |
dee91e82 | 17125 | struct dwarf2_per_cu_offset_and_type |
1c379e20 | 17126 | { |
dee91e82 | 17127 | const struct dwarf2_per_cu_data *per_cu; |
b64f50a1 | 17128 | sect_offset offset; |
1c379e20 DJ |
17129 | struct type *type; |
17130 | }; | |
17131 | ||
dee91e82 | 17132 | /* Hash function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
17133 | |
17134 | static hashval_t | |
dee91e82 | 17135 | per_cu_offset_and_type_hash (const void *item) |
1c379e20 | 17136 | { |
dee91e82 | 17137 | const struct dwarf2_per_cu_offset_and_type *ofs = item; |
9a619af0 | 17138 | |
dee91e82 | 17139 | return (uintptr_t) ofs->per_cu + ofs->offset.sect_off; |
1c379e20 DJ |
17140 | } |
17141 | ||
dee91e82 | 17142 | /* Equality function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
17143 | |
17144 | static int | |
dee91e82 | 17145 | per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs) |
1c379e20 | 17146 | { |
dee91e82 DE |
17147 | const struct dwarf2_per_cu_offset_and_type *ofs_lhs = item_lhs; |
17148 | const struct dwarf2_per_cu_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 17149 | |
dee91e82 DE |
17150 | return (ofs_lhs->per_cu == ofs_rhs->per_cu |
17151 | && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off); | |
1c379e20 DJ |
17152 | } |
17153 | ||
17154 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
17155 | table if necessary. For convenience, return TYPE. |
17156 | ||
17157 | The DIEs reading must have careful ordering to: | |
17158 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
17159 | reading current DIE. | |
17160 | * Not trying to dereference contents of still incompletely read in types | |
17161 | while reading in other DIEs. | |
17162 | * Enable referencing still incompletely read in types just by a pointer to | |
17163 | the type without accessing its fields. | |
17164 | ||
17165 | Therefore caller should follow these rules: | |
17166 | * Try to fetch any prerequisite types we may need to build this DIE type | |
17167 | before building the type and calling set_die_type. | |
e71ec853 | 17168 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
17169 | possible before fetching more types to complete the current type. |
17170 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 17171 | |
f792889a | 17172 | static struct type * |
1c379e20 DJ |
17173 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
17174 | { | |
dee91e82 | 17175 | struct dwarf2_per_cu_offset_and_type **slot, ofs; |
673bfd45 | 17176 | struct objfile *objfile = cu->objfile; |
1c379e20 | 17177 | |
b4ba55a1 JB |
17178 | /* For Ada types, make sure that the gnat-specific data is always |
17179 | initialized (if not already set). There are a few types where | |
17180 | we should not be doing so, because the type-specific area is | |
17181 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
17182 | where the type-specific area is used to store the floatformat). | |
17183 | But this is not a problem, because the gnat-specific information | |
17184 | is actually not needed for these types. */ | |
17185 | if (need_gnat_info (cu) | |
17186 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
17187 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
17188 | && !HAVE_GNAT_AUX_INFO (type)) | |
17189 | INIT_GNAT_SPECIFIC (type); | |
17190 | ||
dee91e82 | 17191 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 17192 | { |
dee91e82 DE |
17193 | dwarf2_per_objfile->die_type_hash = |
17194 | htab_create_alloc_ex (127, | |
17195 | per_cu_offset_and_type_hash, | |
17196 | per_cu_offset_and_type_eq, | |
17197 | NULL, | |
17198 | &objfile->objfile_obstack, | |
17199 | hashtab_obstack_allocate, | |
17200 | dummy_obstack_deallocate); | |
f792889a | 17201 | } |
1c379e20 | 17202 | |
dee91e82 | 17203 | ofs.per_cu = cu->per_cu; |
1c379e20 DJ |
17204 | ofs.offset = die->offset; |
17205 | ofs.type = type; | |
dee91e82 DE |
17206 | slot = (struct dwarf2_per_cu_offset_and_type **) |
17207 | htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT); | |
7e314c57 JK |
17208 | if (*slot) |
17209 | complaint (&symfile_complaints, | |
17210 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
b64f50a1 | 17211 | die->offset.sect_off); |
673bfd45 | 17212 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 17213 | **slot = ofs; |
f792889a | 17214 | return type; |
1c379e20 DJ |
17215 | } |
17216 | ||
380bca97 | 17217 | /* Look up the type for the die at OFFSET in the appropriate type_hash |
673bfd45 | 17218 | table, or return NULL if the die does not have a saved type. */ |
1c379e20 DJ |
17219 | |
17220 | static struct type * | |
b64f50a1 | 17221 | get_die_type_at_offset (sect_offset offset, |
673bfd45 | 17222 | struct dwarf2_per_cu_data *per_cu) |
1c379e20 | 17223 | { |
dee91e82 | 17224 | struct dwarf2_per_cu_offset_and_type *slot, ofs; |
f792889a | 17225 | |
dee91e82 | 17226 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 17227 | return NULL; |
1c379e20 | 17228 | |
dee91e82 | 17229 | ofs.per_cu = per_cu; |
673bfd45 | 17230 | ofs.offset = offset; |
dee91e82 | 17231 | slot = htab_find (dwarf2_per_objfile->die_type_hash, &ofs); |
1c379e20 DJ |
17232 | if (slot) |
17233 | return slot->type; | |
17234 | else | |
17235 | return NULL; | |
17236 | } | |
17237 | ||
673bfd45 DE |
17238 | /* Look up the type for DIE in the appropriate type_hash table, |
17239 | or return NULL if DIE does not have a saved type. */ | |
17240 | ||
17241 | static struct type * | |
17242 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
17243 | { | |
17244 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
17245 | } | |
17246 | ||
10b3939b DJ |
17247 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
17248 | ||
17249 | static void | |
17250 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
17251 | struct dwarf2_per_cu_data *ref_per_cu) | |
17252 | { | |
17253 | void **slot; | |
17254 | ||
17255 | if (cu->dependencies == NULL) | |
17256 | cu->dependencies | |
17257 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
17258 | NULL, &cu->comp_unit_obstack, | |
17259 | hashtab_obstack_allocate, | |
17260 | dummy_obstack_deallocate); | |
17261 | ||
17262 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
17263 | if (*slot == NULL) | |
17264 | *slot = ref_per_cu; | |
17265 | } | |
1c379e20 | 17266 | |
f504f079 DE |
17267 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
17268 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
17269 | cache that we must keep because we are keeping CU. */ |
17270 | ||
10b3939b DJ |
17271 | static int |
17272 | dwarf2_mark_helper (void **slot, void *data) | |
17273 | { | |
17274 | struct dwarf2_per_cu_data *per_cu; | |
17275 | ||
17276 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
d07ed419 JK |
17277 | |
17278 | /* cu->dependencies references may not yet have been ever read if QUIT aborts | |
17279 | reading of the chain. As such dependencies remain valid it is not much | |
17280 | useful to track and undo them during QUIT cleanups. */ | |
17281 | if (per_cu->cu == NULL) | |
17282 | return 1; | |
17283 | ||
10b3939b DJ |
17284 | if (per_cu->cu->mark) |
17285 | return 1; | |
17286 | per_cu->cu->mark = 1; | |
17287 | ||
17288 | if (per_cu->cu->dependencies != NULL) | |
17289 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
17290 | ||
17291 | return 1; | |
17292 | } | |
17293 | ||
f504f079 DE |
17294 | /* Set the mark field in CU and in every other compilation unit in the |
17295 | cache that we must keep because we are keeping CU. */ | |
17296 | ||
ae038cb0 DJ |
17297 | static void |
17298 | dwarf2_mark (struct dwarf2_cu *cu) | |
17299 | { | |
17300 | if (cu->mark) | |
17301 | return; | |
17302 | cu->mark = 1; | |
10b3939b DJ |
17303 | if (cu->dependencies != NULL) |
17304 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
17305 | } |
17306 | ||
17307 | static void | |
17308 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
17309 | { | |
17310 | while (per_cu) | |
17311 | { | |
17312 | per_cu->cu->mark = 0; | |
17313 | per_cu = per_cu->cu->read_in_chain; | |
17314 | } | |
72bf9492 DJ |
17315 | } |
17316 | ||
72bf9492 DJ |
17317 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
17318 | is its offset in .debug_info for this objfile. */ | |
17319 | ||
17320 | static hashval_t | |
17321 | partial_die_hash (const void *item) | |
17322 | { | |
17323 | const struct partial_die_info *part_die = item; | |
9a619af0 | 17324 | |
b64f50a1 | 17325 | return part_die->offset.sect_off; |
72bf9492 DJ |
17326 | } |
17327 | ||
17328 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
17329 | are equal if they have the same offset. */ | |
17330 | ||
17331 | static int | |
17332 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
17333 | { | |
17334 | const struct partial_die_info *part_die_lhs = item_lhs; | |
17335 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 17336 | |
b64f50a1 | 17337 | return part_die_lhs->offset.sect_off == part_die_rhs->offset.sect_off; |
72bf9492 DJ |
17338 | } |
17339 | ||
ae038cb0 DJ |
17340 | static struct cmd_list_element *set_dwarf2_cmdlist; |
17341 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
17342 | ||
17343 | static void | |
17344 | set_dwarf2_cmd (char *args, int from_tty) | |
17345 | { | |
17346 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
17347 | } | |
17348 | ||
17349 | static void | |
17350 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 17351 | { |
ae038cb0 DJ |
17352 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
17353 | } | |
17354 | ||
dce234bc PP |
17355 | /* If section described by INFO was mmapped, munmap it now. */ |
17356 | ||
17357 | static void | |
17358 | munmap_section_buffer (struct dwarf2_section_info *info) | |
17359 | { | |
b315ab21 | 17360 | if (info->map_addr != NULL) |
dce234bc PP |
17361 | { |
17362 | #ifdef HAVE_MMAP | |
b315ab21 | 17363 | int res; |
9a619af0 | 17364 | |
b315ab21 TG |
17365 | res = munmap (info->map_addr, info->map_len); |
17366 | gdb_assert (res == 0); | |
dce234bc PP |
17367 | #else |
17368 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 17369 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
17370 | #endif |
17371 | } | |
17372 | } | |
17373 | ||
17374 | /* munmap debug sections for OBJFILE, if necessary. */ | |
17375 | ||
17376 | static void | |
c1bd65d0 | 17377 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
17378 | { |
17379 | struct dwarf2_per_objfile *data = d; | |
8b70b953 TT |
17380 | int ix; |
17381 | struct dwarf2_section_info *section; | |
9a619af0 | 17382 | |
16be1145 DE |
17383 | /* This is sorted according to the order they're defined in to make it easier |
17384 | to keep in sync. */ | |
dce234bc PP |
17385 | munmap_section_buffer (&data->info); |
17386 | munmap_section_buffer (&data->abbrev); | |
17387 | munmap_section_buffer (&data->line); | |
16be1145 | 17388 | munmap_section_buffer (&data->loc); |
dce234bc | 17389 | munmap_section_buffer (&data->macinfo); |
cf2c3c16 | 17390 | munmap_section_buffer (&data->macro); |
16be1145 | 17391 | munmap_section_buffer (&data->str); |
dce234bc | 17392 | munmap_section_buffer (&data->ranges); |
3019eac3 | 17393 | munmap_section_buffer (&data->addr); |
dce234bc PP |
17394 | munmap_section_buffer (&data->frame); |
17395 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd | 17396 | munmap_section_buffer (&data->gdb_index); |
8b70b953 TT |
17397 | |
17398 | for (ix = 0; | |
17399 | VEC_iterate (dwarf2_section_info_def, data->types, ix, section); | |
17400 | ++ix) | |
17401 | munmap_section_buffer (section); | |
17402 | ||
95554aad TT |
17403 | for (ix = 0; ix < dwarf2_per_objfile->n_comp_units; ++ix) |
17404 | VEC_free (dwarf2_per_cu_ptr, | |
17405 | dwarf2_per_objfile->all_comp_units[ix]->imported_symtabs); | |
17406 | ||
8b70b953 | 17407 | VEC_free (dwarf2_section_info_def, data->types); |
3019eac3 DE |
17408 | |
17409 | if (data->dwo_files) | |
17410 | free_dwo_files (data->dwo_files, objfile); | |
9291a0cd TT |
17411 | } |
17412 | ||
17413 | \f | |
ae2de4f8 | 17414 | /* The "save gdb-index" command. */ |
9291a0cd TT |
17415 | |
17416 | /* The contents of the hash table we create when building the string | |
17417 | table. */ | |
17418 | struct strtab_entry | |
17419 | { | |
17420 | offset_type offset; | |
17421 | const char *str; | |
17422 | }; | |
17423 | ||
559a7a62 JK |
17424 | /* Hash function for a strtab_entry. |
17425 | ||
17426 | Function is used only during write_hash_table so no index format backward | |
17427 | compatibility is needed. */ | |
b89be57b | 17428 | |
9291a0cd TT |
17429 | static hashval_t |
17430 | hash_strtab_entry (const void *e) | |
17431 | { | |
17432 | const struct strtab_entry *entry = e; | |
559a7a62 | 17433 | return mapped_index_string_hash (INT_MAX, entry->str); |
9291a0cd TT |
17434 | } |
17435 | ||
17436 | /* Equality function for a strtab_entry. */ | |
b89be57b | 17437 | |
9291a0cd TT |
17438 | static int |
17439 | eq_strtab_entry (const void *a, const void *b) | |
17440 | { | |
17441 | const struct strtab_entry *ea = a; | |
17442 | const struct strtab_entry *eb = b; | |
17443 | return !strcmp (ea->str, eb->str); | |
17444 | } | |
17445 | ||
17446 | /* Create a strtab_entry hash table. */ | |
b89be57b | 17447 | |
9291a0cd TT |
17448 | static htab_t |
17449 | create_strtab (void) | |
17450 | { | |
17451 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
17452 | xfree, xcalloc, xfree); | |
17453 | } | |
17454 | ||
17455 | /* Add a string to the constant pool. Return the string's offset in | |
17456 | host order. */ | |
b89be57b | 17457 | |
9291a0cd TT |
17458 | static offset_type |
17459 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
17460 | { | |
17461 | void **slot; | |
17462 | struct strtab_entry entry; | |
17463 | struct strtab_entry *result; | |
17464 | ||
17465 | entry.str = str; | |
17466 | slot = htab_find_slot (table, &entry, INSERT); | |
17467 | if (*slot) | |
17468 | result = *slot; | |
17469 | else | |
17470 | { | |
17471 | result = XNEW (struct strtab_entry); | |
17472 | result->offset = obstack_object_size (cpool); | |
17473 | result->str = str; | |
17474 | obstack_grow_str0 (cpool, str); | |
17475 | *slot = result; | |
17476 | } | |
17477 | return result->offset; | |
17478 | } | |
17479 | ||
17480 | /* An entry in the symbol table. */ | |
17481 | struct symtab_index_entry | |
17482 | { | |
17483 | /* The name of the symbol. */ | |
17484 | const char *name; | |
17485 | /* The offset of the name in the constant pool. */ | |
17486 | offset_type index_offset; | |
17487 | /* A sorted vector of the indices of all the CUs that hold an object | |
17488 | of this name. */ | |
17489 | VEC (offset_type) *cu_indices; | |
17490 | }; | |
17491 | ||
17492 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
17493 | struct mapped_symtab | |
17494 | { | |
17495 | offset_type n_elements; | |
17496 | offset_type size; | |
17497 | struct symtab_index_entry **data; | |
17498 | }; | |
17499 | ||
17500 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 17501 | |
9291a0cd TT |
17502 | static hashval_t |
17503 | hash_symtab_entry (const void *e) | |
17504 | { | |
17505 | const struct symtab_index_entry *entry = e; | |
17506 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
17507 | sizeof (offset_type) * VEC_length (offset_type, | |
17508 | entry->cu_indices), | |
17509 | 0); | |
17510 | } | |
17511 | ||
17512 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 17513 | |
9291a0cd TT |
17514 | static int |
17515 | eq_symtab_entry (const void *a, const void *b) | |
17516 | { | |
17517 | const struct symtab_index_entry *ea = a; | |
17518 | const struct symtab_index_entry *eb = b; | |
17519 | int len = VEC_length (offset_type, ea->cu_indices); | |
17520 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
17521 | return 0; | |
17522 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
17523 | VEC_address (offset_type, eb->cu_indices), | |
17524 | sizeof (offset_type) * len); | |
17525 | } | |
17526 | ||
17527 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 17528 | |
9291a0cd TT |
17529 | static void |
17530 | delete_symtab_entry (void *p) | |
17531 | { | |
17532 | struct symtab_index_entry *entry = p; | |
17533 | VEC_free (offset_type, entry->cu_indices); | |
17534 | xfree (entry); | |
17535 | } | |
17536 | ||
17537 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 17538 | |
9291a0cd | 17539 | static htab_t |
3876f04e | 17540 | create_symbol_hash_table (void) |
9291a0cd TT |
17541 | { |
17542 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
17543 | delete_symtab_entry, xcalloc, xfree); | |
17544 | } | |
17545 | ||
17546 | /* Create a new mapped symtab object. */ | |
b89be57b | 17547 | |
9291a0cd TT |
17548 | static struct mapped_symtab * |
17549 | create_mapped_symtab (void) | |
17550 | { | |
17551 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
17552 | symtab->n_elements = 0; | |
17553 | symtab->size = 1024; | |
17554 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
17555 | return symtab; | |
17556 | } | |
17557 | ||
17558 | /* Destroy a mapped_symtab. */ | |
b89be57b | 17559 | |
9291a0cd TT |
17560 | static void |
17561 | cleanup_mapped_symtab (void *p) | |
17562 | { | |
17563 | struct mapped_symtab *symtab = p; | |
17564 | /* The contents of the array are freed when the other hash table is | |
17565 | destroyed. */ | |
17566 | xfree (symtab->data); | |
17567 | xfree (symtab); | |
17568 | } | |
17569 | ||
17570 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
559a7a62 JK |
17571 | the slot. |
17572 | ||
17573 | Function is used only during write_hash_table so no index format backward | |
17574 | compatibility is needed. */ | |
b89be57b | 17575 | |
9291a0cd TT |
17576 | static struct symtab_index_entry ** |
17577 | find_slot (struct mapped_symtab *symtab, const char *name) | |
17578 | { | |
559a7a62 | 17579 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd TT |
17580 | |
17581 | index = hash & (symtab->size - 1); | |
17582 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
17583 | ||
17584 | for (;;) | |
17585 | { | |
17586 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
17587 | return &symtab->data[index]; | |
17588 | index = (index + step) & (symtab->size - 1); | |
17589 | } | |
17590 | } | |
17591 | ||
17592 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 17593 | |
9291a0cd TT |
17594 | static void |
17595 | hash_expand (struct mapped_symtab *symtab) | |
17596 | { | |
17597 | offset_type old_size = symtab->size; | |
17598 | offset_type i; | |
17599 | struct symtab_index_entry **old_entries = symtab->data; | |
17600 | ||
17601 | symtab->size *= 2; | |
17602 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
17603 | ||
17604 | for (i = 0; i < old_size; ++i) | |
17605 | { | |
17606 | if (old_entries[i]) | |
17607 | { | |
17608 | struct symtab_index_entry **slot = find_slot (symtab, | |
17609 | old_entries[i]->name); | |
17610 | *slot = old_entries[i]; | |
17611 | } | |
17612 | } | |
17613 | ||
17614 | xfree (old_entries); | |
17615 | } | |
17616 | ||
156942c7 DE |
17617 | /* Add an entry to SYMTAB. NAME is the name of the symbol. |
17618 | CU_INDEX is the index of the CU in which the symbol appears. | |
17619 | IS_STATIC is one if the symbol is static, otherwise zero (global). */ | |
b89be57b | 17620 | |
9291a0cd TT |
17621 | static void |
17622 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
156942c7 | 17623 | int is_static, gdb_index_symbol_kind kind, |
9291a0cd TT |
17624 | offset_type cu_index) |
17625 | { | |
17626 | struct symtab_index_entry **slot; | |
156942c7 | 17627 | offset_type cu_index_and_attrs; |
9291a0cd TT |
17628 | |
17629 | ++symtab->n_elements; | |
17630 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
17631 | hash_expand (symtab); | |
17632 | ||
17633 | slot = find_slot (symtab, name); | |
17634 | if (!*slot) | |
17635 | { | |
17636 | *slot = XNEW (struct symtab_index_entry); | |
17637 | (*slot)->name = name; | |
156942c7 | 17638 | /* index_offset is set later. */ |
9291a0cd TT |
17639 | (*slot)->cu_indices = NULL; |
17640 | } | |
156942c7 DE |
17641 | |
17642 | cu_index_and_attrs = 0; | |
17643 | DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs, cu_index); | |
17644 | DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs, is_static); | |
17645 | DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs, kind); | |
17646 | ||
17647 | /* We don't want to record an index value twice as we want to avoid the | |
17648 | duplication. | |
17649 | We process all global symbols and then all static symbols | |
17650 | (which would allow us to avoid the duplication by only having to check | |
17651 | the last entry pushed), but a symbol could have multiple kinds in one CU. | |
17652 | To keep things simple we don't worry about the duplication here and | |
17653 | sort and uniqufy the list after we've processed all symbols. */ | |
17654 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index_and_attrs); | |
17655 | } | |
17656 | ||
17657 | /* qsort helper routine for uniquify_cu_indices. */ | |
17658 | ||
17659 | static int | |
17660 | offset_type_compare (const void *ap, const void *bp) | |
17661 | { | |
17662 | offset_type a = *(offset_type *) ap; | |
17663 | offset_type b = *(offset_type *) bp; | |
17664 | ||
17665 | return (a > b) - (b > a); | |
17666 | } | |
17667 | ||
17668 | /* Sort and remove duplicates of all symbols' cu_indices lists. */ | |
17669 | ||
17670 | static void | |
17671 | uniquify_cu_indices (struct mapped_symtab *symtab) | |
17672 | { | |
17673 | int i; | |
17674 | ||
17675 | for (i = 0; i < symtab->size; ++i) | |
17676 | { | |
17677 | struct symtab_index_entry *entry = symtab->data[i]; | |
17678 | ||
17679 | if (entry | |
17680 | && entry->cu_indices != NULL) | |
17681 | { | |
17682 | unsigned int next_to_insert, next_to_check; | |
17683 | offset_type last_value; | |
17684 | ||
17685 | qsort (VEC_address (offset_type, entry->cu_indices), | |
17686 | VEC_length (offset_type, entry->cu_indices), | |
17687 | sizeof (offset_type), offset_type_compare); | |
17688 | ||
17689 | last_value = VEC_index (offset_type, entry->cu_indices, 0); | |
17690 | next_to_insert = 1; | |
17691 | for (next_to_check = 1; | |
17692 | next_to_check < VEC_length (offset_type, entry->cu_indices); | |
17693 | ++next_to_check) | |
17694 | { | |
17695 | if (VEC_index (offset_type, entry->cu_indices, next_to_check) | |
17696 | != last_value) | |
17697 | { | |
17698 | last_value = VEC_index (offset_type, entry->cu_indices, | |
17699 | next_to_check); | |
17700 | VEC_replace (offset_type, entry->cu_indices, next_to_insert, | |
17701 | last_value); | |
17702 | ++next_to_insert; | |
17703 | } | |
17704 | } | |
17705 | VEC_truncate (offset_type, entry->cu_indices, next_to_insert); | |
17706 | } | |
17707 | } | |
9291a0cd TT |
17708 | } |
17709 | ||
17710 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 17711 | |
9291a0cd | 17712 | static offset_type |
3876f04e | 17713 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
17714 | struct symtab_index_entry *entry) |
17715 | { | |
17716 | void **slot; | |
17717 | ||
3876f04e | 17718 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
17719 | if (!*slot) |
17720 | { | |
17721 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
17722 | offset_type val = MAYBE_SWAP (len); | |
17723 | offset_type iter; | |
17724 | int i; | |
17725 | ||
17726 | *slot = entry; | |
17727 | entry->index_offset = obstack_object_size (cpool); | |
17728 | ||
17729 | obstack_grow (cpool, &val, sizeof (val)); | |
17730 | for (i = 0; | |
17731 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
17732 | ++i) | |
17733 | { | |
17734 | val = MAYBE_SWAP (iter); | |
17735 | obstack_grow (cpool, &val, sizeof (val)); | |
17736 | } | |
17737 | } | |
17738 | else | |
17739 | { | |
17740 | struct symtab_index_entry *old_entry = *slot; | |
17741 | entry->index_offset = old_entry->index_offset; | |
17742 | entry = old_entry; | |
17743 | } | |
17744 | return entry->index_offset; | |
17745 | } | |
17746 | ||
17747 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
17748 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 17749 | |
9291a0cd TT |
17750 | static void |
17751 | write_hash_table (struct mapped_symtab *symtab, | |
17752 | struct obstack *output, struct obstack *cpool) | |
17753 | { | |
17754 | offset_type i; | |
3876f04e | 17755 | htab_t symbol_hash_table; |
9291a0cd TT |
17756 | htab_t str_table; |
17757 | ||
3876f04e | 17758 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 17759 | str_table = create_strtab (); |
3876f04e | 17760 | |
9291a0cd TT |
17761 | /* We add all the index vectors to the constant pool first, to |
17762 | ensure alignment is ok. */ | |
17763 | for (i = 0; i < symtab->size; ++i) | |
17764 | { | |
17765 | if (symtab->data[i]) | |
3876f04e | 17766 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
17767 | } |
17768 | ||
17769 | /* Now write out the hash table. */ | |
17770 | for (i = 0; i < symtab->size; ++i) | |
17771 | { | |
17772 | offset_type str_off, vec_off; | |
17773 | ||
17774 | if (symtab->data[i]) | |
17775 | { | |
17776 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
17777 | vec_off = symtab->data[i]->index_offset; | |
17778 | } | |
17779 | else | |
17780 | { | |
17781 | /* While 0 is a valid constant pool index, it is not valid | |
17782 | to have 0 for both offsets. */ | |
17783 | str_off = 0; | |
17784 | vec_off = 0; | |
17785 | } | |
17786 | ||
17787 | str_off = MAYBE_SWAP (str_off); | |
17788 | vec_off = MAYBE_SWAP (vec_off); | |
17789 | ||
17790 | obstack_grow (output, &str_off, sizeof (str_off)); | |
17791 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
17792 | } | |
17793 | ||
17794 | htab_delete (str_table); | |
3876f04e | 17795 | htab_delete (symbol_hash_table); |
9291a0cd TT |
17796 | } |
17797 | ||
0a5429f6 DE |
17798 | /* Struct to map psymtab to CU index in the index file. */ |
17799 | struct psymtab_cu_index_map | |
17800 | { | |
17801 | struct partial_symtab *psymtab; | |
17802 | unsigned int cu_index; | |
17803 | }; | |
17804 | ||
17805 | static hashval_t | |
17806 | hash_psymtab_cu_index (const void *item) | |
17807 | { | |
17808 | const struct psymtab_cu_index_map *map = item; | |
17809 | ||
17810 | return htab_hash_pointer (map->psymtab); | |
17811 | } | |
17812 | ||
17813 | static int | |
17814 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
17815 | { | |
17816 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
17817 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
17818 | ||
17819 | return lhs->psymtab == rhs->psymtab; | |
17820 | } | |
17821 | ||
17822 | /* Helper struct for building the address table. */ | |
17823 | struct addrmap_index_data | |
17824 | { | |
17825 | struct objfile *objfile; | |
17826 | struct obstack *addr_obstack; | |
17827 | htab_t cu_index_htab; | |
17828 | ||
17829 | /* Non-zero if the previous_* fields are valid. | |
17830 | We can't write an entry until we see the next entry (since it is only then | |
17831 | that we know the end of the entry). */ | |
17832 | int previous_valid; | |
17833 | /* Index of the CU in the table of all CUs in the index file. */ | |
17834 | unsigned int previous_cu_index; | |
0963b4bd | 17835 | /* Start address of the CU. */ |
0a5429f6 DE |
17836 | CORE_ADDR previous_cu_start; |
17837 | }; | |
17838 | ||
17839 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 17840 | |
9291a0cd | 17841 | static void |
0a5429f6 DE |
17842 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
17843 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 17844 | { |
0a5429f6 | 17845 | offset_type cu_index_to_write; |
9291a0cd TT |
17846 | char addr[8]; |
17847 | CORE_ADDR baseaddr; | |
17848 | ||
17849 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
17850 | ||
0a5429f6 DE |
17851 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
17852 | obstack_grow (obstack, addr, 8); | |
17853 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
17854 | obstack_grow (obstack, addr, 8); | |
17855 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
17856 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
17857 | } | |
17858 | ||
17859 | /* Worker function for traversing an addrmap to build the address table. */ | |
17860 | ||
17861 | static int | |
17862 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
17863 | { | |
17864 | struct addrmap_index_data *data = datap; | |
17865 | struct partial_symtab *pst = obj; | |
0a5429f6 DE |
17866 | |
17867 | if (data->previous_valid) | |
17868 | add_address_entry (data->objfile, data->addr_obstack, | |
17869 | data->previous_cu_start, start_addr, | |
17870 | data->previous_cu_index); | |
17871 | ||
17872 | data->previous_cu_start = start_addr; | |
17873 | if (pst != NULL) | |
17874 | { | |
17875 | struct psymtab_cu_index_map find_map, *map; | |
17876 | find_map.psymtab = pst; | |
17877 | map = htab_find (data->cu_index_htab, &find_map); | |
17878 | gdb_assert (map != NULL); | |
17879 | data->previous_cu_index = map->cu_index; | |
17880 | data->previous_valid = 1; | |
17881 | } | |
17882 | else | |
17883 | data->previous_valid = 0; | |
17884 | ||
17885 | return 0; | |
17886 | } | |
17887 | ||
17888 | /* Write OBJFILE's address map to OBSTACK. | |
17889 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
17890 | in the index file. */ | |
17891 | ||
17892 | static void | |
17893 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
17894 | htab_t cu_index_htab) | |
17895 | { | |
17896 | struct addrmap_index_data addrmap_index_data; | |
17897 | ||
17898 | /* When writing the address table, we have to cope with the fact that | |
17899 | the addrmap iterator only provides the start of a region; we have to | |
17900 | wait until the next invocation to get the start of the next region. */ | |
17901 | ||
17902 | addrmap_index_data.objfile = objfile; | |
17903 | addrmap_index_data.addr_obstack = obstack; | |
17904 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
17905 | addrmap_index_data.previous_valid = 0; | |
17906 | ||
17907 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
17908 | &addrmap_index_data); | |
17909 | ||
17910 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
17911 | is valid, but we should still handle it. | |
17912 | The end address is recorded as the start of the next region, but that | |
17913 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
17914 | anyway. */ | |
17915 | if (addrmap_index_data.previous_valid) | |
17916 | add_address_entry (objfile, obstack, | |
17917 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
17918 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
17919 | } |
17920 | ||
156942c7 DE |
17921 | /* Return the symbol kind of PSYM. */ |
17922 | ||
17923 | static gdb_index_symbol_kind | |
17924 | symbol_kind (struct partial_symbol *psym) | |
17925 | { | |
17926 | domain_enum domain = PSYMBOL_DOMAIN (psym); | |
17927 | enum address_class aclass = PSYMBOL_CLASS (psym); | |
17928 | ||
17929 | switch (domain) | |
17930 | { | |
17931 | case VAR_DOMAIN: | |
17932 | switch (aclass) | |
17933 | { | |
17934 | case LOC_BLOCK: | |
17935 | return GDB_INDEX_SYMBOL_KIND_FUNCTION; | |
17936 | case LOC_TYPEDEF: | |
17937 | return GDB_INDEX_SYMBOL_KIND_TYPE; | |
17938 | case LOC_COMPUTED: | |
17939 | case LOC_CONST_BYTES: | |
17940 | case LOC_OPTIMIZED_OUT: | |
17941 | case LOC_STATIC: | |
17942 | return GDB_INDEX_SYMBOL_KIND_VARIABLE; | |
17943 | case LOC_CONST: | |
17944 | /* Note: It's currently impossible to recognize psyms as enum values | |
17945 | short of reading the type info. For now punt. */ | |
17946 | return GDB_INDEX_SYMBOL_KIND_VARIABLE; | |
17947 | default: | |
17948 | /* There are other LOC_FOO values that one might want to classify | |
17949 | as variables, but dwarf2read.c doesn't currently use them. */ | |
17950 | return GDB_INDEX_SYMBOL_KIND_OTHER; | |
17951 | } | |
17952 | case STRUCT_DOMAIN: | |
17953 | return GDB_INDEX_SYMBOL_KIND_TYPE; | |
17954 | default: | |
17955 | return GDB_INDEX_SYMBOL_KIND_OTHER; | |
17956 | } | |
17957 | } | |
17958 | ||
9291a0cd | 17959 | /* Add a list of partial symbols to SYMTAB. */ |
b89be57b | 17960 | |
9291a0cd TT |
17961 | static void |
17962 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 17963 | htab_t psyms_seen, |
9291a0cd TT |
17964 | struct partial_symbol **psymp, |
17965 | int count, | |
987d643c TT |
17966 | offset_type cu_index, |
17967 | int is_static) | |
9291a0cd TT |
17968 | { |
17969 | for (; count-- > 0; ++psymp) | |
17970 | { | |
156942c7 DE |
17971 | struct partial_symbol *psym = *psymp; |
17972 | void **slot; | |
987d643c | 17973 | |
156942c7 | 17974 | if (SYMBOL_LANGUAGE (psym) == language_ada) |
9291a0cd | 17975 | error (_("Ada is not currently supported by the index")); |
987d643c | 17976 | |
987d643c | 17977 | /* Only add a given psymbol once. */ |
156942c7 | 17978 | slot = htab_find_slot (psyms_seen, psym, INSERT); |
987d643c TT |
17979 | if (!*slot) |
17980 | { | |
156942c7 DE |
17981 | gdb_index_symbol_kind kind = symbol_kind (psym); |
17982 | ||
17983 | *slot = psym; | |
17984 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym), | |
17985 | is_static, kind, cu_index); | |
987d643c | 17986 | } |
9291a0cd TT |
17987 | } |
17988 | } | |
17989 | ||
17990 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
17991 | exception if there is an error. */ | |
b89be57b | 17992 | |
9291a0cd TT |
17993 | static void |
17994 | write_obstack (FILE *file, struct obstack *obstack) | |
17995 | { | |
17996 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
17997 | file) | |
17998 | != obstack_object_size (obstack)) | |
17999 | error (_("couldn't data write to file")); | |
18000 | } | |
18001 | ||
18002 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 18003 | |
9291a0cd TT |
18004 | static void |
18005 | unlink_if_set (void *p) | |
18006 | { | |
18007 | char **filename = p; | |
18008 | if (*filename) | |
18009 | unlink (*filename); | |
18010 | } | |
18011 | ||
1fd400ff TT |
18012 | /* A helper struct used when iterating over debug_types. */ |
18013 | struct signatured_type_index_data | |
18014 | { | |
18015 | struct objfile *objfile; | |
18016 | struct mapped_symtab *symtab; | |
18017 | struct obstack *types_list; | |
987d643c | 18018 | htab_t psyms_seen; |
1fd400ff TT |
18019 | int cu_index; |
18020 | }; | |
18021 | ||
18022 | /* A helper function that writes a single signatured_type to an | |
18023 | obstack. */ | |
b89be57b | 18024 | |
1fd400ff TT |
18025 | static int |
18026 | write_one_signatured_type (void **slot, void *d) | |
18027 | { | |
18028 | struct signatured_type_index_data *info = d; | |
18029 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
18030 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
18031 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
18032 | gdb_byte val[8]; |
18033 | ||
18034 | write_psymbols (info->symtab, | |
987d643c | 18035 | info->psyms_seen, |
3e43a32a MS |
18036 | info->objfile->global_psymbols.list |
18037 | + psymtab->globals_offset, | |
987d643c TT |
18038 | psymtab->n_global_syms, info->cu_index, |
18039 | 0); | |
1fd400ff | 18040 | write_psymbols (info->symtab, |
987d643c | 18041 | info->psyms_seen, |
3e43a32a MS |
18042 | info->objfile->static_psymbols.list |
18043 | + psymtab->statics_offset, | |
987d643c TT |
18044 | psymtab->n_static_syms, info->cu_index, |
18045 | 1); | |
1fd400ff | 18046 | |
b64f50a1 JK |
18047 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
18048 | entry->per_cu.offset.sect_off); | |
1fd400ff | 18049 | obstack_grow (info->types_list, val, 8); |
3019eac3 DE |
18050 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
18051 | entry->type_offset_in_tu.cu_off); | |
1fd400ff TT |
18052 | obstack_grow (info->types_list, val, 8); |
18053 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
18054 | obstack_grow (info->types_list, val, 8); | |
18055 | ||
18056 | ++info->cu_index; | |
18057 | ||
18058 | return 1; | |
18059 | } | |
18060 | ||
95554aad TT |
18061 | /* Recurse into all "included" dependencies and write their symbols as |
18062 | if they appeared in this psymtab. */ | |
18063 | ||
18064 | static void | |
18065 | recursively_write_psymbols (struct objfile *objfile, | |
18066 | struct partial_symtab *psymtab, | |
18067 | struct mapped_symtab *symtab, | |
18068 | htab_t psyms_seen, | |
18069 | offset_type cu_index) | |
18070 | { | |
18071 | int i; | |
18072 | ||
18073 | for (i = 0; i < psymtab->number_of_dependencies; ++i) | |
18074 | if (psymtab->dependencies[i]->user != NULL) | |
18075 | recursively_write_psymbols (objfile, psymtab->dependencies[i], | |
18076 | symtab, psyms_seen, cu_index); | |
18077 | ||
18078 | write_psymbols (symtab, | |
18079 | psyms_seen, | |
18080 | objfile->global_psymbols.list + psymtab->globals_offset, | |
18081 | psymtab->n_global_syms, cu_index, | |
18082 | 0); | |
18083 | write_psymbols (symtab, | |
18084 | psyms_seen, | |
18085 | objfile->static_psymbols.list + psymtab->statics_offset, | |
18086 | psymtab->n_static_syms, cu_index, | |
18087 | 1); | |
18088 | } | |
18089 | ||
9291a0cd | 18090 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 18091 | |
9291a0cd TT |
18092 | static void |
18093 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
18094 | { | |
18095 | struct cleanup *cleanup; | |
18096 | char *filename, *cleanup_filename; | |
1fd400ff TT |
18097 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
18098 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
18099 | int i; |
18100 | FILE *out_file; | |
18101 | struct mapped_symtab *symtab; | |
18102 | offset_type val, size_of_contents, total_len; | |
18103 | struct stat st; | |
987d643c | 18104 | htab_t psyms_seen; |
0a5429f6 DE |
18105 | htab_t cu_index_htab; |
18106 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd | 18107 | |
b4f2f049 | 18108 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
9291a0cd | 18109 | return; |
b4f2f049 | 18110 | |
9291a0cd TT |
18111 | if (dwarf2_per_objfile->using_index) |
18112 | error (_("Cannot use an index to create the index")); | |
18113 | ||
8b70b953 TT |
18114 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
18115 | error (_("Cannot make an index when the file has multiple .debug_types sections")); | |
18116 | ||
9291a0cd | 18117 | if (stat (objfile->name, &st) < 0) |
7e17e088 | 18118 | perror_with_name (objfile->name); |
9291a0cd TT |
18119 | |
18120 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
18121 | INDEX_SUFFIX, (char *) NULL); | |
18122 | cleanup = make_cleanup (xfree, filename); | |
18123 | ||
18124 | out_file = fopen (filename, "wb"); | |
18125 | if (!out_file) | |
18126 | error (_("Can't open `%s' for writing"), filename); | |
18127 | ||
18128 | cleanup_filename = filename; | |
18129 | make_cleanup (unlink_if_set, &cleanup_filename); | |
18130 | ||
18131 | symtab = create_mapped_symtab (); | |
18132 | make_cleanup (cleanup_mapped_symtab, symtab); | |
18133 | ||
18134 | obstack_init (&addr_obstack); | |
18135 | make_cleanup_obstack_free (&addr_obstack); | |
18136 | ||
18137 | obstack_init (&cu_list); | |
18138 | make_cleanup_obstack_free (&cu_list); | |
18139 | ||
1fd400ff TT |
18140 | obstack_init (&types_cu_list); |
18141 | make_cleanup_obstack_free (&types_cu_list); | |
18142 | ||
987d643c TT |
18143 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
18144 | NULL, xcalloc, xfree); | |
96408a79 | 18145 | make_cleanup_htab_delete (psyms_seen); |
987d643c | 18146 | |
0a5429f6 DE |
18147 | /* While we're scanning CU's create a table that maps a psymtab pointer |
18148 | (which is what addrmap records) to its index (which is what is recorded | |
18149 | in the index file). This will later be needed to write the address | |
18150 | table. */ | |
18151 | cu_index_htab = htab_create_alloc (100, | |
18152 | hash_psymtab_cu_index, | |
18153 | eq_psymtab_cu_index, | |
18154 | NULL, xcalloc, xfree); | |
96408a79 | 18155 | make_cleanup_htab_delete (cu_index_htab); |
0a5429f6 DE |
18156 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
18157 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
18158 | * dwarf2_per_objfile->n_comp_units); | |
18159 | make_cleanup (xfree, psymtab_cu_index_map); | |
18160 | ||
18161 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
18162 | work here. Also, the debug_types entries do not appear in |
18163 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
18164 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
18165 | { | |
3e43a32a MS |
18166 | struct dwarf2_per_cu_data *per_cu |
18167 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 18168 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 18169 | gdb_byte val[8]; |
0a5429f6 DE |
18170 | struct psymtab_cu_index_map *map; |
18171 | void **slot; | |
9291a0cd | 18172 | |
95554aad TT |
18173 | if (psymtab->user == NULL) |
18174 | recursively_write_psymbols (objfile, psymtab, symtab, psyms_seen, i); | |
9291a0cd | 18175 | |
0a5429f6 DE |
18176 | map = &psymtab_cu_index_map[i]; |
18177 | map->psymtab = psymtab; | |
18178 | map->cu_index = i; | |
18179 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
18180 | gdb_assert (slot != NULL); | |
18181 | gdb_assert (*slot == NULL); | |
18182 | *slot = map; | |
9291a0cd | 18183 | |
b64f50a1 JK |
18184 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
18185 | per_cu->offset.sect_off); | |
9291a0cd | 18186 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 18187 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
18188 | obstack_grow (&cu_list, val, 8); |
18189 | } | |
18190 | ||
0a5429f6 DE |
18191 | /* Dump the address map. */ |
18192 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
18193 | ||
1fd400ff TT |
18194 | /* Write out the .debug_type entries, if any. */ |
18195 | if (dwarf2_per_objfile->signatured_types) | |
18196 | { | |
18197 | struct signatured_type_index_data sig_data; | |
18198 | ||
18199 | sig_data.objfile = objfile; | |
18200 | sig_data.symtab = symtab; | |
18201 | sig_data.types_list = &types_cu_list; | |
987d643c | 18202 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
18203 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
18204 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
18205 | write_one_signatured_type, &sig_data); | |
18206 | } | |
18207 | ||
156942c7 DE |
18208 | /* Now that we've processed all symbols we can shrink their cu_indices |
18209 | lists. */ | |
18210 | uniquify_cu_indices (symtab); | |
18211 | ||
9291a0cd TT |
18212 | obstack_init (&constant_pool); |
18213 | make_cleanup_obstack_free (&constant_pool); | |
18214 | obstack_init (&symtab_obstack); | |
18215 | make_cleanup_obstack_free (&symtab_obstack); | |
18216 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
18217 | ||
18218 | obstack_init (&contents); | |
18219 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 18220 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
18221 | total_len = size_of_contents; |
18222 | ||
18223 | /* The version number. */ | |
156942c7 | 18224 | val = MAYBE_SWAP (7); |
9291a0cd TT |
18225 | obstack_grow (&contents, &val, sizeof (val)); |
18226 | ||
18227 | /* The offset of the CU list from the start of the file. */ | |
18228 | val = MAYBE_SWAP (total_len); | |
18229 | obstack_grow (&contents, &val, sizeof (val)); | |
18230 | total_len += obstack_object_size (&cu_list); | |
18231 | ||
1fd400ff TT |
18232 | /* The offset of the types CU list from the start of the file. */ |
18233 | val = MAYBE_SWAP (total_len); | |
18234 | obstack_grow (&contents, &val, sizeof (val)); | |
18235 | total_len += obstack_object_size (&types_cu_list); | |
18236 | ||
9291a0cd TT |
18237 | /* The offset of the address table from the start of the file. */ |
18238 | val = MAYBE_SWAP (total_len); | |
18239 | obstack_grow (&contents, &val, sizeof (val)); | |
18240 | total_len += obstack_object_size (&addr_obstack); | |
18241 | ||
18242 | /* The offset of the symbol table from the start of the file. */ | |
18243 | val = MAYBE_SWAP (total_len); | |
18244 | obstack_grow (&contents, &val, sizeof (val)); | |
18245 | total_len += obstack_object_size (&symtab_obstack); | |
18246 | ||
18247 | /* The offset of the constant pool from the start of the file. */ | |
18248 | val = MAYBE_SWAP (total_len); | |
18249 | obstack_grow (&contents, &val, sizeof (val)); | |
18250 | total_len += obstack_object_size (&constant_pool); | |
18251 | ||
18252 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
18253 | ||
18254 | write_obstack (out_file, &contents); | |
18255 | write_obstack (out_file, &cu_list); | |
1fd400ff | 18256 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
18257 | write_obstack (out_file, &addr_obstack); |
18258 | write_obstack (out_file, &symtab_obstack); | |
18259 | write_obstack (out_file, &constant_pool); | |
18260 | ||
18261 | fclose (out_file); | |
18262 | ||
18263 | /* We want to keep the file, so we set cleanup_filename to NULL | |
18264 | here. See unlink_if_set. */ | |
18265 | cleanup_filename = NULL; | |
18266 | ||
18267 | do_cleanups (cleanup); | |
18268 | } | |
18269 | ||
90476074 TT |
18270 | /* Implementation of the `save gdb-index' command. |
18271 | ||
18272 | Note that the file format used by this command is documented in the | |
18273 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 18274 | |
9291a0cd TT |
18275 | static void |
18276 | save_gdb_index_command (char *arg, int from_tty) | |
18277 | { | |
18278 | struct objfile *objfile; | |
18279 | ||
18280 | if (!arg || !*arg) | |
96d19272 | 18281 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
18282 | |
18283 | ALL_OBJFILES (objfile) | |
18284 | { | |
18285 | struct stat st; | |
18286 | ||
18287 | /* If the objfile does not correspond to an actual file, skip it. */ | |
18288 | if (stat (objfile->name, &st) < 0) | |
18289 | continue; | |
18290 | ||
18291 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
18292 | if (dwarf2_per_objfile) | |
18293 | { | |
18294 | volatile struct gdb_exception except; | |
18295 | ||
18296 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
18297 | { | |
18298 | write_psymtabs_to_index (objfile, arg); | |
18299 | } | |
18300 | if (except.reason < 0) | |
18301 | exception_fprintf (gdb_stderr, except, | |
18302 | _("Error while writing index for `%s': "), | |
18303 | objfile->name); | |
18304 | } | |
18305 | } | |
dce234bc PP |
18306 | } |
18307 | ||
9291a0cd TT |
18308 | \f |
18309 | ||
9eae7c52 TT |
18310 | int dwarf2_always_disassemble; |
18311 | ||
18312 | static void | |
18313 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
18314 | struct cmd_list_element *c, const char *value) | |
18315 | { | |
3e43a32a MS |
18316 | fprintf_filtered (file, |
18317 | _("Whether to always disassemble " | |
18318 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
18319 | value); |
18320 | } | |
18321 | ||
900e11f9 JK |
18322 | static void |
18323 | show_check_physname (struct ui_file *file, int from_tty, | |
18324 | struct cmd_list_element *c, const char *value) | |
18325 | { | |
18326 | fprintf_filtered (file, | |
18327 | _("Whether to check \"physname\" is %s.\n"), | |
18328 | value); | |
18329 | } | |
18330 | ||
6502dd73 DJ |
18331 | void _initialize_dwarf2_read (void); |
18332 | ||
18333 | void | |
18334 | _initialize_dwarf2_read (void) | |
18335 | { | |
96d19272 JK |
18336 | struct cmd_list_element *c; |
18337 | ||
dce234bc | 18338 | dwarf2_objfile_data_key |
c1bd65d0 | 18339 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 18340 | |
1bedd215 AC |
18341 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
18342 | Set DWARF 2 specific variables.\n\ | |
18343 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
18344 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
18345 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
18346 | ||
1bedd215 AC |
18347 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
18348 | Show DWARF 2 specific variables\n\ | |
18349 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
18350 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
18351 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
18352 | ||
18353 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
18354 | &dwarf2_max_cache_age, _("\ |
18355 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
18356 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
18357 | A higher limit means that cached compilation units will be stored\n\ | |
18358 | in memory longer, and more total memory will be used. Zero disables\n\ | |
18359 | caching, which can slow down startup."), | |
2c5b56ce | 18360 | NULL, |
920d2a44 | 18361 | show_dwarf2_max_cache_age, |
2c5b56ce | 18362 | &set_dwarf2_cmdlist, |
ae038cb0 | 18363 | &show_dwarf2_cmdlist); |
d97bc12b | 18364 | |
9eae7c52 TT |
18365 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
18366 | &dwarf2_always_disassemble, _("\ | |
18367 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
18368 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
18369 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
18370 | syntax. When disabled, expressions will be printed in a more\n\ | |
18371 | conversational style, when possible."), | |
18372 | NULL, | |
18373 | show_dwarf2_always_disassemble, | |
18374 | &set_dwarf2_cmdlist, | |
18375 | &show_dwarf2_cmdlist); | |
18376 | ||
45cfd468 DE |
18377 | add_setshow_boolean_cmd ("dwarf2-read", no_class, &dwarf2_read_debug, _("\ |
18378 | Set debugging of the dwarf2 reader."), _("\ | |
18379 | Show debugging of the dwarf2 reader."), _("\ | |
18380 | When enabled, debugging messages are printed during dwarf2 reading\n\ | |
18381 | and symtab expansion."), | |
18382 | NULL, | |
18383 | NULL, | |
18384 | &setdebuglist, &showdebuglist); | |
18385 | ||
d97bc12b DE |
18386 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
18387 | Set debugging of the dwarf2 DIE reader."), _("\ | |
18388 | Show debugging of the dwarf2 DIE reader."), _("\ | |
18389 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
18390 | The value is the maximum depth to print."), | |
18391 | NULL, | |
18392 | NULL, | |
18393 | &setdebuglist, &showdebuglist); | |
9291a0cd | 18394 | |
900e11f9 JK |
18395 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
18396 | Set cross-checking of \"physname\" code against demangler."), _("\ | |
18397 | Show cross-checking of \"physname\" code against demangler."), _("\ | |
18398 | When enabled, GDB's internal \"physname\" code is checked against\n\ | |
18399 | the demangler."), | |
18400 | NULL, show_check_physname, | |
18401 | &setdebuglist, &showdebuglist); | |
18402 | ||
96d19272 | 18403 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 18404 | _("\ |
fc1a9d6e | 18405 | Save a gdb-index file.\n\ |
11570e71 | 18406 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
18407 | &save_cmdlist); |
18408 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 18409 | } |