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 */ |
60d5a603 | 65 | #include <ctype.h> |
4c2df51b | 66 | |
c906108c SS |
67 | #include <fcntl.h> |
68 | #include "gdb_string.h" | |
4bdf3d34 | 69 | #include "gdb_assert.h" |
c906108c | 70 | #include <sys/types.h> |
233a11ab CS |
71 | #ifdef HAVE_ZLIB_H |
72 | #include <zlib.h> | |
73 | #endif | |
dce234bc PP |
74 | #ifdef HAVE_MMAP |
75 | #include <sys/mman.h> | |
85d9bd0e TT |
76 | #ifndef MAP_FAILED |
77 | #define MAP_FAILED ((void *) -1) | |
78 | #endif | |
dce234bc | 79 | #endif |
d8151005 | 80 | |
34eaf542 TT |
81 | typedef struct symbol *symbolp; |
82 | DEF_VEC_P (symbolp); | |
83 | ||
d97bc12b DE |
84 | /* When non-zero, dump DIEs after they are read in. */ |
85 | static int dwarf2_die_debug = 0; | |
86 | ||
900e11f9 JK |
87 | /* When non-zero, cross-check physname against demangler. */ |
88 | static int check_physname = 0; | |
89 | ||
481860b3 GB |
90 | /* When non-zero, do not reject deprecated .gdb_index sections. */ |
91 | int use_deprecated_index_sections = 0; | |
92 | ||
dce234bc PP |
93 | static int pagesize; |
94 | ||
df8a16a1 DJ |
95 | /* When set, the file that we're processing is known to have debugging |
96 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
97 | but later versions do. */ | |
98 | ||
99 | static int processing_has_namespace_info; | |
100 | ||
6502dd73 DJ |
101 | static const struct objfile_data *dwarf2_objfile_data_key; |
102 | ||
dce234bc PP |
103 | struct dwarf2_section_info |
104 | { | |
105 | asection *asection; | |
106 | gdb_byte *buffer; | |
107 | bfd_size_type size; | |
b315ab21 TG |
108 | /* Not NULL if the section was actually mmapped. */ |
109 | void *map_addr; | |
110 | /* Page aligned size of mmapped area. */ | |
111 | bfd_size_type map_len; | |
be391dca TT |
112 | /* True if we have tried to read this section. */ |
113 | int readin; | |
dce234bc PP |
114 | }; |
115 | ||
8b70b953 TT |
116 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
117 | DEF_VEC_O (dwarf2_section_info_def); | |
118 | ||
9291a0cd TT |
119 | /* All offsets in the index are of this type. It must be |
120 | architecture-independent. */ | |
121 | typedef uint32_t offset_type; | |
122 | ||
123 | DEF_VEC_I (offset_type); | |
124 | ||
125 | /* A description of the mapped index. The file format is described in | |
126 | a comment by the code that writes the index. */ | |
127 | struct mapped_index | |
128 | { | |
559a7a62 JK |
129 | /* Index data format version. */ |
130 | int version; | |
131 | ||
9291a0cd TT |
132 | /* The total length of the buffer. */ |
133 | off_t total_size; | |
b11b1f88 | 134 | |
9291a0cd TT |
135 | /* A pointer to the address table data. */ |
136 | const gdb_byte *address_table; | |
b11b1f88 | 137 | |
9291a0cd TT |
138 | /* Size of the address table data in bytes. */ |
139 | offset_type address_table_size; | |
b11b1f88 | 140 | |
3876f04e DE |
141 | /* The symbol table, implemented as a hash table. */ |
142 | const offset_type *symbol_table; | |
b11b1f88 | 143 | |
9291a0cd | 144 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 145 | offset_type symbol_table_slots; |
b11b1f88 | 146 | |
9291a0cd TT |
147 | /* A pointer to the constant pool. */ |
148 | const char *constant_pool; | |
149 | }; | |
150 | ||
9cdd5dbd DE |
151 | /* Collection of data recorded per objfile. |
152 | This hangs off of dwarf2_objfile_data_key. */ | |
153 | ||
6502dd73 DJ |
154 | struct dwarf2_per_objfile |
155 | { | |
dce234bc PP |
156 | struct dwarf2_section_info info; |
157 | struct dwarf2_section_info abbrev; | |
158 | struct dwarf2_section_info line; | |
dce234bc PP |
159 | struct dwarf2_section_info loc; |
160 | struct dwarf2_section_info macinfo; | |
cf2c3c16 | 161 | struct dwarf2_section_info macro; |
dce234bc PP |
162 | struct dwarf2_section_info str; |
163 | struct dwarf2_section_info ranges; | |
3019eac3 | 164 | struct dwarf2_section_info addr; |
dce234bc PP |
165 | struct dwarf2_section_info frame; |
166 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 167 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 168 | |
8b70b953 TT |
169 | VEC (dwarf2_section_info_def) *types; |
170 | ||
be391dca TT |
171 | /* Back link. */ |
172 | struct objfile *objfile; | |
173 | ||
d467dd73 | 174 | /* Table of all the compilation units. This is used to locate |
10b3939b | 175 | the target compilation unit of a particular reference. */ |
ae038cb0 DJ |
176 | struct dwarf2_per_cu_data **all_comp_units; |
177 | ||
178 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
179 | int n_comp_units; | |
180 | ||
1fd400ff | 181 | /* The number of .debug_types-related CUs. */ |
d467dd73 | 182 | int n_type_units; |
1fd400ff | 183 | |
d467dd73 DE |
184 | /* The .debug_types-related CUs (TUs). */ |
185 | struct dwarf2_per_cu_data **all_type_units; | |
1fd400ff | 186 | |
ae038cb0 DJ |
187 | /* A chain of compilation units that are currently read in, so that |
188 | they can be freed later. */ | |
189 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 190 | |
348e048f DE |
191 | /* A table mapping .debug_types signatures to its signatured_type entry. |
192 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
193 | htab_t signatured_types; | |
194 | ||
3019eac3 DE |
195 | /* A table mapping DW_AT_dwo_name values to struct dwo_file objects. |
196 | This is NULL if the table hasn't been allocated yet. */ | |
197 | htab_t dwo_files; | |
198 | ||
72dca2f5 FR |
199 | /* A flag indicating wether this objfile has a section loaded at a |
200 | VMA of 0. */ | |
201 | int has_section_at_zero; | |
9291a0cd | 202 | |
ae2de4f8 DE |
203 | /* True if we are using the mapped index, |
204 | or we are faking it for OBJF_READNOW's sake. */ | |
9291a0cd TT |
205 | unsigned char using_index; |
206 | ||
ae2de4f8 | 207 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
9291a0cd | 208 | struct mapped_index *index_table; |
98bfdba5 | 209 | |
7b9f3c50 DE |
210 | /* When using index_table, this keeps track of all quick_file_names entries. |
211 | TUs can share line table entries with CUs or other TUs, and there can be | |
212 | a lot more TUs than unique line tables, so we maintain a separate table | |
213 | of all line table entries to support the sharing. */ | |
214 | htab_t quick_file_names_table; | |
215 | ||
98bfdba5 PA |
216 | /* Set during partial symbol reading, to prevent queueing of full |
217 | symbols. */ | |
218 | int reading_partial_symbols; | |
673bfd45 | 219 | |
dee91e82 | 220 | /* Table mapping type DIEs to their struct type *. |
673bfd45 | 221 | This is NULL if not allocated yet. |
dee91e82 DE |
222 | The mapping is done via (CU/TU signature + DIE offset) -> type. */ |
223 | htab_t die_type_hash; | |
6502dd73 DJ |
224 | }; |
225 | ||
226 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 227 | |
251d32d9 | 228 | /* Default names of the debugging sections. */ |
c906108c | 229 | |
233a11ab CS |
230 | /* Note that if the debugging section has been compressed, it might |
231 | have a name like .zdebug_info. */ | |
232 | ||
9cdd5dbd DE |
233 | static const struct dwarf2_debug_sections dwarf2_elf_names = |
234 | { | |
251d32d9 TG |
235 | { ".debug_info", ".zdebug_info" }, |
236 | { ".debug_abbrev", ".zdebug_abbrev" }, | |
237 | { ".debug_line", ".zdebug_line" }, | |
238 | { ".debug_loc", ".zdebug_loc" }, | |
239 | { ".debug_macinfo", ".zdebug_macinfo" }, | |
cf2c3c16 | 240 | { ".debug_macro", ".zdebug_macro" }, |
251d32d9 TG |
241 | { ".debug_str", ".zdebug_str" }, |
242 | { ".debug_ranges", ".zdebug_ranges" }, | |
243 | { ".debug_types", ".zdebug_types" }, | |
3019eac3 | 244 | { ".debug_addr", ".zdebug_addr" }, |
251d32d9 TG |
245 | { ".debug_frame", ".zdebug_frame" }, |
246 | { ".eh_frame", NULL }, | |
24d3216f TT |
247 | { ".gdb_index", ".zgdb_index" }, |
248 | 23 | |
251d32d9 | 249 | }; |
c906108c | 250 | |
3019eac3 DE |
251 | /* List of DWO sections. */ |
252 | ||
253 | static const struct dwo_section_names | |
254 | { | |
255 | struct dwarf2_section_names abbrev_dwo; | |
256 | struct dwarf2_section_names info_dwo; | |
257 | struct dwarf2_section_names line_dwo; | |
258 | struct dwarf2_section_names loc_dwo; | |
259 | struct dwarf2_section_names str_dwo; | |
260 | struct dwarf2_section_names str_offsets_dwo; | |
261 | struct dwarf2_section_names types_dwo; | |
262 | } | |
263 | dwo_section_names = | |
264 | { | |
265 | { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" }, | |
266 | { ".debug_info.dwo", ".zdebug_info.dwo" }, | |
267 | { ".debug_line.dwo", ".zdebug_line.dwo" }, | |
268 | { ".debug_loc.dwo", ".zdebug_loc.dwo" }, | |
269 | { ".debug_str.dwo", ".zdebug_str.dwo" }, | |
270 | { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" }, | |
271 | { ".debug_types.dwo", ".zdebug_types.dwo" }, | |
272 | }; | |
273 | ||
c906108c SS |
274 | /* local data types */ |
275 | ||
0963b4bd | 276 | /* We hold several abbreviation tables in memory at the same time. */ |
57349743 JB |
277 | #ifndef ABBREV_HASH_SIZE |
278 | #define ABBREV_HASH_SIZE 121 | |
279 | #endif | |
280 | ||
107d2387 AC |
281 | /* The data in a compilation unit header, after target2host |
282 | translation, looks like this. */ | |
c906108c | 283 | struct comp_unit_head |
a738430d | 284 | { |
c764a876 | 285 | unsigned int length; |
a738430d | 286 | short version; |
a738430d MK |
287 | unsigned char addr_size; |
288 | unsigned char signed_addr_p; | |
b64f50a1 | 289 | sect_offset abbrev_offset; |
57349743 | 290 | |
a738430d MK |
291 | /* Size of file offsets; either 4 or 8. */ |
292 | unsigned int offset_size; | |
57349743 | 293 | |
a738430d MK |
294 | /* Size of the length field; either 4 or 12. */ |
295 | unsigned int initial_length_size; | |
57349743 | 296 | |
a738430d MK |
297 | /* Offset to the first byte of this compilation unit header in the |
298 | .debug_info section, for resolving relative reference dies. */ | |
b64f50a1 | 299 | sect_offset offset; |
57349743 | 300 | |
d00adf39 DE |
301 | /* Offset to first die in this cu from the start of the cu. |
302 | This will be the first byte following the compilation unit header. */ | |
b64f50a1 | 303 | cu_offset first_die_offset; |
a738430d | 304 | }; |
c906108c | 305 | |
3da10d80 KS |
306 | /* Type used for delaying computation of method physnames. |
307 | See comments for compute_delayed_physnames. */ | |
308 | struct delayed_method_info | |
309 | { | |
310 | /* The type to which the method is attached, i.e., its parent class. */ | |
311 | struct type *type; | |
312 | ||
313 | /* The index of the method in the type's function fieldlists. */ | |
314 | int fnfield_index; | |
315 | ||
316 | /* The index of the method in the fieldlist. */ | |
317 | int index; | |
318 | ||
319 | /* The name of the DIE. */ | |
320 | const char *name; | |
321 | ||
322 | /* The DIE associated with this method. */ | |
323 | struct die_info *die; | |
324 | }; | |
325 | ||
326 | typedef struct delayed_method_info delayed_method_info; | |
327 | DEF_VEC_O (delayed_method_info); | |
328 | ||
e7c27a73 DJ |
329 | /* Internal state when decoding a particular compilation unit. */ |
330 | struct dwarf2_cu | |
331 | { | |
332 | /* The objfile containing this compilation unit. */ | |
333 | struct objfile *objfile; | |
334 | ||
d00adf39 | 335 | /* The header of the compilation unit. */ |
e7c27a73 | 336 | struct comp_unit_head header; |
e142c38c | 337 | |
d00adf39 DE |
338 | /* Base address of this compilation unit. */ |
339 | CORE_ADDR base_address; | |
340 | ||
341 | /* Non-zero if base_address has been set. */ | |
342 | int base_known; | |
343 | ||
e142c38c DJ |
344 | /* The language we are debugging. */ |
345 | enum language language; | |
346 | const struct language_defn *language_defn; | |
347 | ||
b0f35d58 DL |
348 | const char *producer; |
349 | ||
e142c38c DJ |
350 | /* The generic symbol table building routines have separate lists for |
351 | file scope symbols and all all other scopes (local scopes). So | |
352 | we need to select the right one to pass to add_symbol_to_list(). | |
353 | We do it by keeping a pointer to the correct list in list_in_scope. | |
354 | ||
355 | FIXME: The original dwarf code just treated the file scope as the | |
356 | first local scope, and all other local scopes as nested local | |
357 | scopes, and worked fine. Check to see if we really need to | |
358 | distinguish these in buildsym.c. */ | |
359 | struct pending **list_in_scope; | |
360 | ||
f3dd6933 DJ |
361 | /* DWARF abbreviation table associated with this compilation unit. */ |
362 | struct abbrev_info **dwarf2_abbrevs; | |
363 | ||
364 | /* Storage for the abbrev table. */ | |
365 | struct obstack abbrev_obstack; | |
72bf9492 | 366 | |
b64f50a1 JK |
367 | /* Hash table holding all the loaded partial DIEs |
368 | with partial_die->offset.SECT_OFF as hash. */ | |
72bf9492 DJ |
369 | htab_t partial_dies; |
370 | ||
371 | /* Storage for things with the same lifetime as this read-in compilation | |
372 | unit, including partial DIEs. */ | |
373 | struct obstack comp_unit_obstack; | |
374 | ||
ae038cb0 DJ |
375 | /* When multiple dwarf2_cu structures are living in memory, this field |
376 | chains them all together, so that they can be released efficiently. | |
377 | We will probably also want a generation counter so that most-recently-used | |
378 | compilation units are cached... */ | |
379 | struct dwarf2_per_cu_data *read_in_chain; | |
380 | ||
381 | /* Backchain to our per_cu entry if the tree has been built. */ | |
382 | struct dwarf2_per_cu_data *per_cu; | |
383 | ||
384 | /* How many compilation units ago was this CU last referenced? */ | |
385 | int last_used; | |
386 | ||
b64f50a1 JK |
387 | /* A hash table of DIE cu_offset for following references with |
388 | die_info->offset.sect_off as hash. */ | |
51545339 | 389 | htab_t die_hash; |
10b3939b DJ |
390 | |
391 | /* Full DIEs if read in. */ | |
392 | struct die_info *dies; | |
393 | ||
394 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
395 | units referenced by this one. Only set during full symbol processing; | |
396 | partial symbol tables do not have dependencies. */ | |
397 | htab_t dependencies; | |
398 | ||
cb1df416 DJ |
399 | /* Header data from the line table, during full symbol processing. */ |
400 | struct line_header *line_header; | |
401 | ||
3da10d80 KS |
402 | /* A list of methods which need to have physnames computed |
403 | after all type information has been read. */ | |
404 | VEC (delayed_method_info) *method_list; | |
405 | ||
96408a79 SA |
406 | /* To be copied to symtab->call_site_htab. */ |
407 | htab_t call_site_htab; | |
408 | ||
3019eac3 DE |
409 | /* Non-NULL if this CU came from a DWO file. */ |
410 | struct dwo_unit *dwo_unit; | |
411 | ||
412 | /* The DW_AT_addr_base attribute if present, zero otherwise | |
413 | (zero is a valid value though). | |
414 | Note this value comes from the stub CU/TU's DIE. */ | |
415 | ULONGEST addr_base; | |
416 | ||
ae038cb0 DJ |
417 | /* Mark used when releasing cached dies. */ |
418 | unsigned int mark : 1; | |
419 | ||
8be455d7 JK |
420 | /* This CU references .debug_loc. See the symtab->locations_valid field. |
421 | This test is imperfect as there may exist optimized debug code not using | |
422 | any location list and still facing inlining issues if handled as | |
423 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
8be455d7 | 424 | unsigned int has_loclist : 1; |
ba919b58 TT |
425 | |
426 | /* These cache the results of producer_is_gxx_lt_4_6. | |
427 | CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This | |
428 | information is cached because profiling CU expansion showed | |
429 | excessive time spent in producer_is_gxx_lt_4_6. */ | |
430 | unsigned int checked_producer : 1; | |
431 | unsigned int producer_is_gxx_lt_4_6 : 1; | |
3019eac3 DE |
432 | |
433 | /* Non-zero if DW_AT_addr_base was found. | |
434 | Used when processing DWO files. */ | |
435 | unsigned int have_addr_base : 1; | |
e7c27a73 DJ |
436 | }; |
437 | ||
10b3939b DJ |
438 | /* Persistent data held for a compilation unit, even when not |
439 | processing it. We put a pointer to this structure in the | |
28dee7f5 | 440 | read_symtab_private field of the psymtab. */ |
10b3939b | 441 | |
ae038cb0 DJ |
442 | struct dwarf2_per_cu_data |
443 | { | |
348e048f | 444 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 445 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
446 | - if it doesn't, GDB will fall over anyway. |
447 | NOTE: Unlike comp_unit_head.length, this length includes | |
3019eac3 DE |
448 | initial_length_size. |
449 | If the DIE refers to a DWO file, this is always of the original die, | |
450 | not the DWO file. */ | |
b64f50a1 | 451 | sect_offset offset; |
348e048f | 452 | unsigned int length : 29; |
ae038cb0 DJ |
453 | |
454 | /* Flag indicating this compilation unit will be read in before | |
455 | any of the current compilation units are processed. */ | |
c764a876 | 456 | unsigned int queued : 1; |
ae038cb0 | 457 | |
0d99eb77 DE |
458 | /* This flag will be set when reading partial DIEs if we need to load |
459 | absolutely all DIEs for this compilation unit, instead of just the ones | |
460 | we think are interesting. It gets set if we look for a DIE in the | |
5afb4e99 DJ |
461 | hash table and don't find it. */ |
462 | unsigned int load_all_dies : 1; | |
463 | ||
3019eac3 DE |
464 | /* Non-zero if this CU is from .debug_types. */ |
465 | unsigned int is_debug_types : 1; | |
466 | ||
467 | /* The section this CU/TU lives in. | |
468 | If the DIE refers to a DWO file, this is always the original die, | |
469 | not the DWO file. */ | |
470 | struct dwarf2_section_info *info_or_types_section; | |
348e048f | 471 | |
17ea53c3 JK |
472 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
473 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 474 | struct dwarf2_cu *cu; |
1c379e20 | 475 | |
9cdd5dbd DE |
476 | /* The corresponding objfile. |
477 | Normally we can get the objfile from dwarf2_per_objfile. | |
478 | However we can enter this file with just a "per_cu" handle. */ | |
9291a0cd TT |
479 | struct objfile *objfile; |
480 | ||
481 | /* When using partial symbol tables, the 'psymtab' field is active. | |
482 | Otherwise the 'quick' field is active. */ | |
483 | union | |
484 | { | |
485 | /* The partial symbol table associated with this compilation unit, | |
486 | or NULL for partial units (which do not have an associated | |
487 | symtab). */ | |
488 | struct partial_symtab *psymtab; | |
489 | ||
490 | /* Data needed by the "quick" functions. */ | |
491 | struct dwarf2_per_cu_quick_data *quick; | |
492 | } v; | |
ae038cb0 DJ |
493 | }; |
494 | ||
348e048f DE |
495 | /* Entry in the signatured_types hash table. */ |
496 | ||
497 | struct signatured_type | |
498 | { | |
3019eac3 | 499 | /* The type's signature. */ |
348e048f DE |
500 | ULONGEST signature; |
501 | ||
3019eac3 DE |
502 | /* Offset in the TU of the type's DIE, as read from the TU header. |
503 | If the definition lives in a DWO file, this value is unusable. */ | |
504 | cu_offset type_offset_in_tu; | |
505 | ||
506 | /* Offset in the section of the type's DIE. | |
507 | If the definition lives in a DWO file, this is the offset in the | |
508 | .debug_types.dwo section. | |
509 | The value is zero until the actual value is known. | |
510 | Zero is otherwise not a valid section offset. */ | |
511 | sect_offset type_offset_in_section; | |
348e048f DE |
512 | |
513 | /* The CU(/TU) of this type. */ | |
514 | struct dwarf2_per_cu_data per_cu; | |
515 | }; | |
516 | ||
3019eac3 DE |
517 | /* These sections are what may appear in a "dwo" file. */ |
518 | ||
519 | struct dwo_sections | |
520 | { | |
521 | struct dwarf2_section_info abbrev; | |
522 | struct dwarf2_section_info info; | |
523 | struct dwarf2_section_info line; | |
524 | struct dwarf2_section_info loc; | |
525 | struct dwarf2_section_info str; | |
526 | struct dwarf2_section_info str_offsets; | |
527 | VEC (dwarf2_section_info_def) *types; | |
528 | }; | |
529 | ||
530 | /* Common bits of DWO CUs/TUs. */ | |
531 | ||
532 | struct dwo_unit | |
533 | { | |
534 | /* Backlink to the containing struct dwo_file. */ | |
535 | struct dwo_file *dwo_file; | |
536 | ||
537 | /* The "id" that distinguishes this CU/TU. | |
538 | .debug_info calls this "dwo_id", .debug_types calls this "signature". | |
539 | Since signatures came first, we stick with it for consistency. */ | |
540 | ULONGEST signature; | |
541 | ||
542 | /* The section this CU/TU lives in, in the DWO file. */ | |
543 | struct dwarf2_section_info *info_or_types_section; | |
544 | ||
545 | /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */ | |
546 | sect_offset offset; | |
547 | unsigned int length; | |
548 | ||
549 | /* For types, offset in the type's DIE of the type defined by this TU. */ | |
550 | cu_offset type_offset_in_tu; | |
551 | }; | |
552 | ||
553 | /* Data for one DWO file. */ | |
554 | ||
555 | struct dwo_file | |
556 | { | |
557 | /* The DW_AT_GNU_dwo_name attribute. | |
558 | We don't manage space for this, it's an attribute. */ | |
559 | const char *dwo_name; | |
560 | ||
561 | /* The bfd, when the file is open. Otherwise this is NULL. */ | |
562 | bfd *dwo_bfd; | |
563 | ||
564 | /* Section info for this file. */ | |
565 | struct dwo_sections sections; | |
566 | ||
567 | /* Table of CUs in the file. | |
568 | Each element is a struct dwo_unit. */ | |
569 | htab_t cus; | |
570 | ||
571 | /* Table of TUs in the file. | |
572 | Each element is a struct dwo_unit. */ | |
573 | htab_t tus; | |
574 | }; | |
575 | ||
0963b4bd MS |
576 | /* Struct used to pass misc. parameters to read_die_and_children, et |
577 | al. which are used for both .debug_info and .debug_types dies. | |
578 | All parameters here are unchanging for the life of the call. This | |
dee91e82 | 579 | struct exists to abstract away the constant parameters of die reading. */ |
93311388 DE |
580 | |
581 | struct die_reader_specs | |
582 | { | |
dee91e82 | 583 | /* die_section->asection->owner. */ |
93311388 DE |
584 | bfd* abfd; |
585 | ||
586 | /* The CU of the DIE we are parsing. */ | |
587 | struct dwarf2_cu *cu; | |
588 | ||
3019eac3 DE |
589 | /* Non-NULL if reading a DWO file. */ |
590 | struct dwo_file *dwo_file; | |
591 | ||
dee91e82 | 592 | /* The section the die comes from. |
3019eac3 | 593 | This is either .debug_info or .debug_types, or the .dwo variants. */ |
dee91e82 DE |
594 | struct dwarf2_section_info *die_section; |
595 | ||
596 | /* die_section->buffer. */ | |
597 | gdb_byte *buffer; | |
93311388 DE |
598 | }; |
599 | ||
dee91e82 DE |
600 | /* Type of function passed to init_cu_and_read_dies, et.al. */ |
601 | typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader, | |
602 | gdb_byte *info_ptr, | |
603 | struct die_info *comp_unit_die, | |
604 | int has_children, | |
605 | void *data); | |
606 | ||
debd256d JB |
607 | /* The line number information for a compilation unit (found in the |
608 | .debug_line section) begins with a "statement program header", | |
609 | which contains the following information. */ | |
610 | struct line_header | |
611 | { | |
612 | unsigned int total_length; | |
613 | unsigned short version; | |
614 | unsigned int header_length; | |
615 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 616 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
617 | unsigned char default_is_stmt; |
618 | int line_base; | |
619 | unsigned char line_range; | |
620 | unsigned char opcode_base; | |
621 | ||
622 | /* standard_opcode_lengths[i] is the number of operands for the | |
623 | standard opcode whose value is i. This means that | |
624 | standard_opcode_lengths[0] is unused, and the last meaningful | |
625 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
626 | unsigned char *standard_opcode_lengths; | |
627 | ||
628 | /* The include_directories table. NOTE! These strings are not | |
629 | allocated with xmalloc; instead, they are pointers into | |
630 | debug_line_buffer. If you try to free them, `free' will get | |
631 | indigestion. */ | |
632 | unsigned int num_include_dirs, include_dirs_size; | |
633 | char **include_dirs; | |
634 | ||
635 | /* The file_names table. NOTE! These strings are not allocated | |
636 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
637 | Don't try to free them directly. */ | |
638 | unsigned int num_file_names, file_names_size; | |
639 | struct file_entry | |
c906108c | 640 | { |
debd256d JB |
641 | char *name; |
642 | unsigned int dir_index; | |
643 | unsigned int mod_time; | |
644 | unsigned int length; | |
aaa75496 | 645 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 646 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
647 | } *file_names; |
648 | ||
649 | /* The start and end of the statement program following this | |
6502dd73 | 650 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 651 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 652 | }; |
c906108c SS |
653 | |
654 | /* When we construct a partial symbol table entry we only | |
0963b4bd | 655 | need this much information. */ |
c906108c SS |
656 | struct partial_die_info |
657 | { | |
72bf9492 | 658 | /* Offset of this DIE. */ |
b64f50a1 | 659 | sect_offset offset; |
72bf9492 DJ |
660 | |
661 | /* DWARF-2 tag for this DIE. */ | |
662 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
663 | ||
72bf9492 DJ |
664 | /* Assorted flags describing the data found in this DIE. */ |
665 | unsigned int has_children : 1; | |
666 | unsigned int is_external : 1; | |
667 | unsigned int is_declaration : 1; | |
668 | unsigned int has_type : 1; | |
669 | unsigned int has_specification : 1; | |
670 | unsigned int has_pc_info : 1; | |
481860b3 | 671 | unsigned int may_be_inlined : 1; |
72bf9492 DJ |
672 | |
673 | /* Flag set if the SCOPE field of this structure has been | |
674 | computed. */ | |
675 | unsigned int scope_set : 1; | |
676 | ||
fa4028e9 JB |
677 | /* Flag set if the DIE has a byte_size attribute. */ |
678 | unsigned int has_byte_size : 1; | |
679 | ||
98bfdba5 PA |
680 | /* Flag set if any of the DIE's children are template arguments. */ |
681 | unsigned int has_template_arguments : 1; | |
682 | ||
abc72ce4 DE |
683 | /* Flag set if fixup_partial_die has been called on this die. */ |
684 | unsigned int fixup_called : 1; | |
685 | ||
72bf9492 | 686 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 687 | sometimes a default name for unnamed DIEs. */ |
c906108c | 688 | char *name; |
72bf9492 | 689 | |
abc72ce4 DE |
690 | /* The linkage name, if present. */ |
691 | const char *linkage_name; | |
692 | ||
72bf9492 DJ |
693 | /* The scope to prepend to our children. This is generally |
694 | allocated on the comp_unit_obstack, so will disappear | |
695 | when this compilation unit leaves the cache. */ | |
696 | char *scope; | |
697 | ||
698 | /* The location description associated with this DIE, if any. */ | |
699 | struct dwarf_block *locdesc; | |
700 | ||
701 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
702 | CORE_ADDR lowpc; |
703 | CORE_ADDR highpc; | |
72bf9492 | 704 | |
93311388 | 705 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 706 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
707 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
708 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
fe1b8b76 | 709 | gdb_byte *sibling; |
72bf9492 DJ |
710 | |
711 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
712 | DW_AT_specification (or DW_AT_abstract_origin or | |
713 | DW_AT_extension). */ | |
b64f50a1 | 714 | sect_offset spec_offset; |
72bf9492 DJ |
715 | |
716 | /* Pointers to this DIE's parent, first child, and next sibling, | |
717 | if any. */ | |
718 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
719 | }; |
720 | ||
0963b4bd | 721 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
722 | struct abbrev_info |
723 | { | |
724 | unsigned int number; /* number identifying abbrev */ | |
725 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
726 | unsigned short has_children; /* boolean */ |
727 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
728 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
729 | struct abbrev_info *next; /* next in chain */ | |
730 | }; | |
731 | ||
732 | struct attr_abbrev | |
733 | { | |
9d25dd43 DE |
734 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
735 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
736 | }; |
737 | ||
0963b4bd | 738 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
739 | struct attribute |
740 | { | |
9d25dd43 | 741 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
742 | ENUM_BITFIELD(dwarf_form) form : 15; |
743 | ||
744 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
745 | field should be in u.str (existing only for DW_STRING) but it is kept | |
746 | here for better struct attribute alignment. */ | |
747 | unsigned int string_is_canonical : 1; | |
748 | ||
b60c80d6 DJ |
749 | union |
750 | { | |
751 | char *str; | |
752 | struct dwarf_block *blk; | |
43bbcdc2 PH |
753 | ULONGEST unsnd; |
754 | LONGEST snd; | |
b60c80d6 | 755 | CORE_ADDR addr; |
348e048f | 756 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
757 | } |
758 | u; | |
759 | }; | |
760 | ||
0963b4bd | 761 | /* This data structure holds a complete die structure. */ |
c906108c SS |
762 | struct die_info |
763 | { | |
76815b17 DE |
764 | /* DWARF-2 tag for this DIE. */ |
765 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
766 | ||
767 | /* Number of attributes */ | |
98bfdba5 PA |
768 | unsigned char num_attrs; |
769 | ||
770 | /* True if we're presently building the full type name for the | |
771 | type derived from this DIE. */ | |
772 | unsigned char building_fullname : 1; | |
76815b17 DE |
773 | |
774 | /* Abbrev number */ | |
775 | unsigned int abbrev; | |
776 | ||
93311388 | 777 | /* Offset in .debug_info or .debug_types section. */ |
b64f50a1 | 778 | sect_offset offset; |
78ba4af6 JB |
779 | |
780 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
781 | points to this die's parent; CHILD points to the first child of | |
782 | this node; and all the children of a given node are chained | |
4950bc1c | 783 | together via their SIBLING fields. */ |
639d11d3 DC |
784 | struct die_info *child; /* Its first child, if any. */ |
785 | struct die_info *sibling; /* Its next sibling, if any. */ | |
786 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 787 | |
b60c80d6 DJ |
788 | /* An array of attributes, with NUM_ATTRS elements. There may be |
789 | zero, but it's not common and zero-sized arrays are not | |
790 | sufficiently portable C. */ | |
791 | struct attribute attrs[1]; | |
c906108c SS |
792 | }; |
793 | ||
0963b4bd | 794 | /* Get at parts of an attribute structure. */ |
c906108c SS |
795 | |
796 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 797 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
798 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
799 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
800 | #define DW_SND(attr) ((attr)->u.snd) | |
801 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 802 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c | 803 | |
0963b4bd | 804 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
805 | struct dwarf_block |
806 | { | |
807 | unsigned int size; | |
1d6edc3c JK |
808 | |
809 | /* Valid only if SIZE is not zero. */ | |
fe1b8b76 | 810 | gdb_byte *data; |
c906108c SS |
811 | }; |
812 | ||
c906108c SS |
813 | #ifndef ATTR_ALLOC_CHUNK |
814 | #define ATTR_ALLOC_CHUNK 4 | |
815 | #endif | |
816 | ||
c906108c SS |
817 | /* Allocate fields for structs, unions and enums in this size. */ |
818 | #ifndef DW_FIELD_ALLOC_CHUNK | |
819 | #define DW_FIELD_ALLOC_CHUNK 4 | |
820 | #endif | |
821 | ||
c906108c SS |
822 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
823 | but this would require a corresponding change in unpack_field_as_long | |
824 | and friends. */ | |
825 | static int bits_per_byte = 8; | |
826 | ||
827 | /* The routines that read and process dies for a C struct or C++ class | |
828 | pass lists of data member fields and lists of member function fields | |
829 | in an instance of a field_info structure, as defined below. */ | |
830 | struct field_info | |
c5aa993b | 831 | { |
0963b4bd | 832 | /* List of data member and baseclasses fields. */ |
c5aa993b JM |
833 | struct nextfield |
834 | { | |
835 | struct nextfield *next; | |
836 | int accessibility; | |
837 | int virtuality; | |
838 | struct field field; | |
839 | } | |
7d0ccb61 | 840 | *fields, *baseclasses; |
c906108c | 841 | |
7d0ccb61 | 842 | /* Number of fields (including baseclasses). */ |
c5aa993b | 843 | int nfields; |
c906108c | 844 | |
c5aa993b JM |
845 | /* Number of baseclasses. */ |
846 | int nbaseclasses; | |
c906108c | 847 | |
c5aa993b JM |
848 | /* Set if the accesibility of one of the fields is not public. */ |
849 | int non_public_fields; | |
c906108c | 850 | |
c5aa993b JM |
851 | /* Member function fields array, entries are allocated in the order they |
852 | are encountered in the object file. */ | |
853 | struct nextfnfield | |
854 | { | |
855 | struct nextfnfield *next; | |
856 | struct fn_field fnfield; | |
857 | } | |
858 | *fnfields; | |
c906108c | 859 | |
c5aa993b JM |
860 | /* Member function fieldlist array, contains name of possibly overloaded |
861 | member function, number of overloaded member functions and a pointer | |
862 | to the head of the member function field chain. */ | |
863 | struct fnfieldlist | |
864 | { | |
865 | char *name; | |
866 | int length; | |
867 | struct nextfnfield *head; | |
868 | } | |
869 | *fnfieldlists; | |
c906108c | 870 | |
c5aa993b JM |
871 | /* Number of entries in the fnfieldlists array. */ |
872 | int nfnfields; | |
98751a41 JK |
873 | |
874 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
875 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
876 | struct typedef_field_list | |
877 | { | |
878 | struct typedef_field field; | |
879 | struct typedef_field_list *next; | |
880 | } | |
881 | *typedef_field_list; | |
882 | unsigned typedef_field_list_count; | |
c5aa993b | 883 | }; |
c906108c | 884 | |
10b3939b DJ |
885 | /* One item on the queue of compilation units to read in full symbols |
886 | for. */ | |
887 | struct dwarf2_queue_item | |
888 | { | |
889 | struct dwarf2_per_cu_data *per_cu; | |
890 | struct dwarf2_queue_item *next; | |
891 | }; | |
892 | ||
893 | /* The current queue. */ | |
894 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
895 | ||
ae038cb0 DJ |
896 | /* Loaded secondary compilation units are kept in memory until they |
897 | have not been referenced for the processing of this many | |
898 | compilation units. Set this to zero to disable caching. Cache | |
899 | sizes of up to at least twenty will improve startup time for | |
900 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
901 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
902 | static void |
903 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
904 | struct cmd_list_element *c, const char *value) | |
905 | { | |
3e43a32a MS |
906 | fprintf_filtered (file, _("The upper bound on the age of cached " |
907 | "dwarf2 compilation units is %s.\n"), | |
920d2a44 AC |
908 | value); |
909 | } | |
910 | ||
ae038cb0 | 911 | |
0963b4bd | 912 | /* Various complaints about symbol reading that don't abort the process. */ |
c906108c | 913 | |
4d3c2250 KB |
914 | static void |
915 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 916 | { |
4d3c2250 | 917 | complaint (&symfile_complaints, |
e2e0b3e5 | 918 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
919 | } |
920 | ||
25e43795 DJ |
921 | static void |
922 | dwarf2_debug_line_missing_file_complaint (void) | |
923 | { | |
924 | complaint (&symfile_complaints, | |
925 | _(".debug_line section has line data without a file")); | |
926 | } | |
927 | ||
59205f5a JB |
928 | static void |
929 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
930 | { | |
931 | complaint (&symfile_complaints, | |
3e43a32a MS |
932 | _(".debug_line section has line " |
933 | "program sequence without an end")); | |
59205f5a JB |
934 | } |
935 | ||
4d3c2250 KB |
936 | static void |
937 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 938 | { |
e2e0b3e5 | 939 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
940 | } |
941 | ||
4d3c2250 KB |
942 | static void |
943 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
944 | int arg3) | |
2e276125 | 945 | { |
4d3c2250 | 946 | complaint (&symfile_complaints, |
3e43a32a MS |
947 | _("const value length mismatch for '%s', got %d, expected %d"), |
948 | arg1, arg2, arg3); | |
4d3c2250 KB |
949 | } |
950 | ||
951 | static void | |
cf2c3c16 | 952 | dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section) |
2e276125 | 953 | { |
4d3c2250 | 954 | complaint (&symfile_complaints, |
cf2c3c16 TT |
955 | _("macro info runs off end of `%s' section"), |
956 | section->asection->name); | |
4d3c2250 KB |
957 | } |
958 | ||
959 | static void | |
960 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 961 | { |
4d3c2250 | 962 | complaint (&symfile_complaints, |
3e43a32a MS |
963 | _("macro debug info contains a " |
964 | "malformed macro definition:\n`%s'"), | |
4d3c2250 KB |
965 | arg1); |
966 | } | |
967 | ||
968 | static void | |
969 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 970 | { |
4d3c2250 | 971 | complaint (&symfile_complaints, |
3e43a32a MS |
972 | _("invalid attribute class or form for '%s' in '%s'"), |
973 | arg1, arg2); | |
4d3c2250 | 974 | } |
c906108c | 975 | |
c906108c SS |
976 | /* local function prototypes */ |
977 | ||
4efb68b1 | 978 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 979 | |
aaa75496 JB |
980 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
981 | struct objfile *); | |
982 | ||
918dd910 JK |
983 | static void dwarf2_find_base_address (struct die_info *die, |
984 | struct dwarf2_cu *cu); | |
985 | ||
c67a9c90 | 986 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 987 | |
72bf9492 DJ |
988 | static void scan_partial_symbols (struct partial_die_info *, |
989 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 990 | int, struct dwarf2_cu *); |
c906108c | 991 | |
72bf9492 DJ |
992 | static void add_partial_symbol (struct partial_die_info *, |
993 | struct dwarf2_cu *); | |
63d06c5c | 994 | |
72bf9492 DJ |
995 | static void add_partial_namespace (struct partial_die_info *pdi, |
996 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 997 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 998 | |
5d7cb8df JK |
999 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
1000 | CORE_ADDR *highpc, int need_pc, | |
1001 | struct dwarf2_cu *cu); | |
1002 | ||
72bf9492 DJ |
1003 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
1004 | struct dwarf2_cu *cu); | |
91c24f0a | 1005 | |
bc30ff58 JB |
1006 | static void add_partial_subprogram (struct partial_die_info *pdi, |
1007 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 1008 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 1009 | |
a14ed312 | 1010 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 1011 | |
a14ed312 | 1012 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 1013 | |
dee91e82 DE |
1014 | static void dwarf2_read_abbrevs (struct dwarf2_cu *, |
1015 | struct dwarf2_section_info *); | |
c906108c | 1016 | |
f3dd6933 | 1017 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 1018 | |
6caca83c CC |
1019 | static unsigned int peek_abbrev_code (bfd *, gdb_byte *); |
1020 | ||
fe1b8b76 | 1021 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 1022 | struct dwarf2_cu *); |
72bf9492 | 1023 | |
57349743 | 1024 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 1025 | struct dwarf2_cu *); |
c906108c | 1026 | |
dee91e82 DE |
1027 | static struct partial_die_info *load_partial_dies |
1028 | (const struct die_reader_specs *, gdb_byte *, int); | |
72bf9492 | 1029 | |
dee91e82 DE |
1030 | static gdb_byte *read_partial_die (const struct die_reader_specs *, |
1031 | struct partial_die_info *, | |
1032 | struct abbrev_info *, | |
1033 | unsigned int, | |
1034 | gdb_byte *); | |
c906108c | 1035 | |
b64f50a1 | 1036 | static struct partial_die_info *find_partial_die (sect_offset, |
10b3939b | 1037 | struct dwarf2_cu *); |
72bf9492 DJ |
1038 | |
1039 | static void fixup_partial_die (struct partial_die_info *, | |
1040 | struct dwarf2_cu *); | |
1041 | ||
dee91e82 DE |
1042 | static gdb_byte *read_attribute (const struct die_reader_specs *, |
1043 | struct attribute *, struct attr_abbrev *, | |
1044 | gdb_byte *); | |
a8329558 | 1045 | |
fe1b8b76 | 1046 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 1047 | |
fe1b8b76 | 1048 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 1049 | |
fe1b8b76 | 1050 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 1051 | |
fe1b8b76 | 1052 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 1053 | |
93311388 | 1054 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 1055 | |
fe1b8b76 | 1056 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 1057 | unsigned int *); |
c906108c | 1058 | |
c764a876 DE |
1059 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
1060 | ||
1061 | static LONGEST read_checked_initial_length_and_offset | |
1062 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
1063 | unsigned int *, unsigned int *); | |
613e1657 | 1064 | |
fe1b8b76 | 1065 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
1066 | unsigned int *); |
1067 | ||
1068 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 1069 | |
fe1b8b76 | 1070 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 1071 | |
9b1c24c8 | 1072 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1073 | |
fe1b8b76 JB |
1074 | static char *read_indirect_string (bfd *, gdb_byte *, |
1075 | const struct comp_unit_head *, | |
1076 | unsigned int *); | |
4bdf3d34 | 1077 | |
12df843f | 1078 | static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1079 | |
12df843f | 1080 | static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 1081 | |
3019eac3 DE |
1082 | static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, gdb_byte *, |
1083 | unsigned int *); | |
1084 | ||
1085 | static char *read_str_index (const struct die_reader_specs *reader, | |
1086 | struct dwarf2_cu *cu, ULONGEST str_index); | |
1087 | ||
fe1b8b76 | 1088 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 1089 | |
e142c38c | 1090 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 1091 | |
e142c38c DJ |
1092 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
1093 | struct dwarf2_cu *); | |
c906108c | 1094 | |
348e048f DE |
1095 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
1096 | unsigned int, | |
1097 | struct dwarf2_cu *); | |
1098 | ||
05cf31d1 JB |
1099 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
1100 | struct dwarf2_cu *cu); | |
1101 | ||
e142c38c | 1102 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 1103 | |
e142c38c | 1104 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 1105 | struct dwarf2_cu **); |
63d06c5c | 1106 | |
debd256d JB |
1107 | static void free_line_header (struct line_header *lh); |
1108 | ||
aaa75496 JB |
1109 | static void add_file_name (struct line_header *, char *, unsigned int, |
1110 | unsigned int, unsigned int); | |
1111 | ||
3019eac3 DE |
1112 | static struct line_header *dwarf_decode_line_header (unsigned int offset, |
1113 | struct dwarf2_cu *cu); | |
debd256d | 1114 | |
f3f5162e DE |
1115 | static void dwarf_decode_lines (struct line_header *, const char *, |
1116 | struct dwarf2_cu *, struct partial_symtab *, | |
1117 | int); | |
c906108c | 1118 | |
72b9f47f | 1119 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 1120 | |
a14ed312 | 1121 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 1122 | struct dwarf2_cu *); |
c906108c | 1123 | |
34eaf542 TT |
1124 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
1125 | struct dwarf2_cu *, struct symbol *); | |
1126 | ||
a14ed312 | 1127 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1128 | struct dwarf2_cu *); |
c906108c | 1129 | |
98bfdba5 PA |
1130 | static void dwarf2_const_value_attr (struct attribute *attr, |
1131 | struct type *type, | |
1132 | const char *name, | |
1133 | struct obstack *obstack, | |
12df843f | 1134 | struct dwarf2_cu *cu, LONGEST *value, |
98bfdba5 PA |
1135 | gdb_byte **bytes, |
1136 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1137 | |
e7c27a73 | 1138 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1139 | |
b4ba55a1 JB |
1140 | static int need_gnat_info (struct dwarf2_cu *); |
1141 | ||
3e43a32a MS |
1142 | static struct type *die_descriptive_type (struct die_info *, |
1143 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1144 | |
1145 | static void set_descriptive_type (struct type *, struct die_info *, | |
1146 | struct dwarf2_cu *); | |
1147 | ||
e7c27a73 DJ |
1148 | static struct type *die_containing_type (struct die_info *, |
1149 | struct dwarf2_cu *); | |
c906108c | 1150 | |
673bfd45 DE |
1151 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1152 | struct dwarf2_cu *); | |
c906108c | 1153 | |
f792889a | 1154 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1155 | |
673bfd45 DE |
1156 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1157 | ||
0d5cff50 | 1158 | static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1159 | |
6e70227d | 1160 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1161 | const char *suffix, int physname, |
1162 | struct dwarf2_cu *cu); | |
63d06c5c | 1163 | |
e7c27a73 | 1164 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1165 | |
348e048f DE |
1166 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1167 | ||
e7c27a73 | 1168 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1169 | |
e7c27a73 | 1170 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1171 | |
96408a79 SA |
1172 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
1173 | ||
ff013f42 JK |
1174 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1175 | struct dwarf2_cu *, struct partial_symtab *); | |
1176 | ||
a14ed312 | 1177 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1178 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1179 | struct partial_symtab *); | |
c906108c | 1180 | |
fae299cd DC |
1181 | static void get_scope_pc_bounds (struct die_info *, |
1182 | CORE_ADDR *, CORE_ADDR *, | |
1183 | struct dwarf2_cu *); | |
1184 | ||
801e3a5b JB |
1185 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1186 | CORE_ADDR, struct dwarf2_cu *); | |
1187 | ||
a14ed312 | 1188 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1189 | struct dwarf2_cu *); |
c906108c | 1190 | |
a14ed312 | 1191 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1192 | struct type *, struct dwarf2_cu *); |
c906108c | 1193 | |
a14ed312 | 1194 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1195 | struct die_info *, struct type *, |
e7c27a73 | 1196 | struct dwarf2_cu *); |
c906108c | 1197 | |
a14ed312 | 1198 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1199 | struct type *, |
1200 | struct dwarf2_cu *); | |
c906108c | 1201 | |
134d01f1 | 1202 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1203 | |
e7c27a73 | 1204 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1205 | |
e7c27a73 | 1206 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1207 | |
5d7cb8df JK |
1208 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1209 | ||
27aa8d6a SW |
1210 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1211 | ||
f55ee35c JK |
1212 | static struct type *read_module_type (struct die_info *die, |
1213 | struct dwarf2_cu *cu); | |
1214 | ||
38d518c9 | 1215 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1216 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1217 | |
134d01f1 | 1218 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1219 | |
e7c27a73 | 1220 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1221 | |
6e70227d | 1222 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1223 | struct dwarf2_cu *); |
1224 | ||
dee91e82 | 1225 | static struct die_info *read_die_and_children (const struct die_reader_specs *, |
93311388 | 1226 | gdb_byte *info_ptr, |
fe1b8b76 | 1227 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1228 | struct die_info *parent); |
1229 | ||
dee91e82 | 1230 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *, |
93311388 | 1231 | gdb_byte *info_ptr, |
fe1b8b76 | 1232 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1233 | struct die_info *parent); |
1234 | ||
3019eac3 DE |
1235 | static gdb_byte *read_full_die_1 (const struct die_reader_specs *, |
1236 | struct die_info **, gdb_byte *, int *, int); | |
1237 | ||
dee91e82 DE |
1238 | static gdb_byte *read_full_die (const struct die_reader_specs *, |
1239 | struct die_info **, gdb_byte *, int *); | |
93311388 | 1240 | |
e7c27a73 | 1241 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1242 | |
71c25dea TT |
1243 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1244 | struct obstack *); | |
1245 | ||
e142c38c | 1246 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1247 | |
98bfdba5 PA |
1248 | static const char *dwarf2_full_name (char *name, |
1249 | struct die_info *die, | |
1250 | struct dwarf2_cu *cu); | |
1251 | ||
e142c38c | 1252 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1253 | struct dwarf2_cu **); |
9219021c | 1254 | |
a14ed312 | 1255 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1256 | |
a14ed312 | 1257 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1258 | |
a14ed312 | 1259 | static char *dwarf_form_name (unsigned int); |
c906108c | 1260 | |
a14ed312 | 1261 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1262 | |
a14ed312 | 1263 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1264 | |
1265 | #if 0 | |
a14ed312 | 1266 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1267 | #endif |
1268 | ||
f9aca02d | 1269 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1270 | |
d97bc12b DE |
1271 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1272 | ||
1273 | static void dump_die_for_error (struct die_info *); | |
1274 | ||
1275 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1276 | struct die_info *); | |
c906108c | 1277 | |
d97bc12b | 1278 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1279 | |
51545339 | 1280 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1281 | struct dwarf2_cu *); |
c906108c | 1282 | |
93311388 DE |
1283 | static int is_ref_attr (struct attribute *); |
1284 | ||
b64f50a1 | 1285 | static sect_offset dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1286 | |
43bbcdc2 | 1287 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1288 | |
348e048f DE |
1289 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1290 | struct attribute *, | |
1291 | struct dwarf2_cu **); | |
1292 | ||
10b3939b DJ |
1293 | static struct die_info *follow_die_ref (struct die_info *, |
1294 | struct attribute *, | |
f2f0e013 | 1295 | struct dwarf2_cu **); |
c906108c | 1296 | |
348e048f DE |
1297 | static struct die_info *follow_die_sig (struct die_info *, |
1298 | struct attribute *, | |
1299 | struct dwarf2_cu **); | |
1300 | ||
6c83ed52 TT |
1301 | static struct signatured_type *lookup_signatured_type_at_offset |
1302 | (struct objfile *objfile, | |
b64f50a1 | 1303 | struct dwarf2_section_info *section, sect_offset offset); |
6c83ed52 | 1304 | |
e5fe5e75 | 1305 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
348e048f | 1306 | |
52dc124a | 1307 | static void read_signatured_type (struct signatured_type *); |
348e048f | 1308 | |
c906108c SS |
1309 | /* memory allocation interface */ |
1310 | ||
7b5a2f43 | 1311 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1312 | |
f3dd6933 | 1313 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1314 | |
b60c80d6 | 1315 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1316 | |
2e276125 | 1317 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
cf2c3c16 TT |
1318 | char *, bfd *, struct dwarf2_cu *, |
1319 | struct dwarf2_section_info *, | |
1320 | int); | |
2e276125 | 1321 | |
8e19ed76 PS |
1322 | static int attr_form_is_block (struct attribute *); |
1323 | ||
3690dd37 JB |
1324 | static int attr_form_is_section_offset (struct attribute *); |
1325 | ||
1326 | static int attr_form_is_constant (struct attribute *); | |
1327 | ||
8cf6f0b1 TT |
1328 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1329 | struct dwarf2_loclist_baton *baton, | |
1330 | struct attribute *attr); | |
1331 | ||
93e7bd98 DJ |
1332 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1333 | struct symbol *sym, | |
1334 | struct dwarf2_cu *cu); | |
4c2df51b | 1335 | |
dee91e82 DE |
1336 | static gdb_byte *skip_one_die (const struct die_reader_specs *reader, |
1337 | gdb_byte *info_ptr, | |
1338 | struct abbrev_info *abbrev); | |
4bb7a0a7 | 1339 | |
72bf9492 DJ |
1340 | static void free_stack_comp_unit (void *); |
1341 | ||
72bf9492 DJ |
1342 | static hashval_t partial_die_hash (const void *item); |
1343 | ||
1344 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1345 | ||
ae038cb0 | 1346 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
b64f50a1 | 1347 | (sect_offset offset, struct objfile *objfile); |
ae038cb0 | 1348 | |
9816fde3 | 1349 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
23745b47 | 1350 | struct dwarf2_per_cu_data *per_cu); |
9816fde3 JK |
1351 | |
1352 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
1353 | struct die_info *comp_unit_die); | |
93311388 | 1354 | |
68dc6402 | 1355 | static void free_heap_comp_unit (void *); |
ae038cb0 DJ |
1356 | |
1357 | static void free_cached_comp_units (void *); | |
1358 | ||
1359 | static void age_cached_comp_units (void); | |
1360 | ||
dee91e82 | 1361 | static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *); |
ae038cb0 | 1362 | |
f792889a DJ |
1363 | static struct type *set_die_type (struct die_info *, struct type *, |
1364 | struct dwarf2_cu *); | |
1c379e20 | 1365 | |
ae038cb0 DJ |
1366 | static void create_all_comp_units (struct objfile *); |
1367 | ||
0e50663e | 1368 | static int create_all_type_units (struct objfile *); |
1fd400ff | 1369 | |
a0f42c21 | 1370 | static void load_full_comp_unit (struct dwarf2_per_cu_data *); |
10b3939b DJ |
1371 | |
1372 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1373 | ||
1374 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1375 | struct dwarf2_per_cu_data *); | |
1376 | ||
ae038cb0 DJ |
1377 | static void dwarf2_mark (struct dwarf2_cu *); |
1378 | ||
1379 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1380 | ||
b64f50a1 | 1381 | static struct type *get_die_type_at_offset (sect_offset, |
673bfd45 DE |
1382 | struct dwarf2_per_cu_data *per_cu); |
1383 | ||
f792889a | 1384 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1385 | |
9291a0cd TT |
1386 | static void dwarf2_release_queue (void *dummy); |
1387 | ||
a0f42c21 | 1388 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu); |
9291a0cd | 1389 | |
a0f42c21 | 1390 | static void process_queue (void); |
9291a0cd TT |
1391 | |
1392 | static void find_file_and_directory (struct die_info *die, | |
1393 | struct dwarf2_cu *cu, | |
1394 | char **name, char **comp_dir); | |
1395 | ||
1396 | static char *file_full_name (int file, struct line_header *lh, | |
1397 | const char *comp_dir); | |
1398 | ||
9ff913ba DE |
1399 | static gdb_byte *read_and_check_comp_unit_head |
1400 | (struct comp_unit_head *header, | |
1401 | struct dwarf2_section_info *section, gdb_byte *info_ptr, | |
1402 | int is_debug_types_section); | |
9291a0cd | 1403 | |
3019eac3 DE |
1404 | static void init_tu_and_read_dies |
1405 | (struct dwarf2_per_cu_data *this_cu, int keep, | |
1406 | die_reader_func_ftype *die_reader_func, void *data); | |
1407 | ||
dee91e82 DE |
1408 | static void init_cutu_and_read_dies_simple |
1409 | (struct dwarf2_per_cu_data *this_cu, | |
1410 | die_reader_func_ftype *die_reader_func, void *data); | |
9291a0cd | 1411 | |
673bfd45 | 1412 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1413 | |
dee91e82 DE |
1414 | static void process_psymtab_comp_unit (struct dwarf2_per_cu_data *); |
1415 | ||
3019eac3 DE |
1416 | static htab_t allocate_dwo_unit_table (struct objfile *objfile); |
1417 | ||
1418 | static struct dwo_unit *lookup_dwo_comp_unit | |
1419 | (struct dwarf2_per_cu_data *, char *, const char *, ULONGEST); | |
1420 | ||
1421 | static struct dwo_unit *lookup_dwo_type_unit | |
1422 | (struct signatured_type *, char *, const char *); | |
1423 | ||
1424 | static void free_dwo_file_cleanup (void *); | |
1425 | ||
1426 | static void munmap_section_buffer (struct dwarf2_section_info *); | |
1427 | ||
9291a0cd TT |
1428 | #if WORDS_BIGENDIAN |
1429 | ||
1430 | /* Convert VALUE between big- and little-endian. */ | |
1431 | static offset_type | |
1432 | byte_swap (offset_type value) | |
1433 | { | |
1434 | offset_type result; | |
1435 | ||
1436 | result = (value & 0xff) << 24; | |
1437 | result |= (value & 0xff00) << 8; | |
1438 | result |= (value & 0xff0000) >> 8; | |
1439 | result |= (value & 0xff000000) >> 24; | |
1440 | return result; | |
1441 | } | |
1442 | ||
1443 | #define MAYBE_SWAP(V) byte_swap (V) | |
1444 | ||
1445 | #else | |
1446 | #define MAYBE_SWAP(V) (V) | |
1447 | #endif /* WORDS_BIGENDIAN */ | |
1448 | ||
1449 | /* The suffix for an index file. */ | |
1450 | #define INDEX_SUFFIX ".gdb-index" | |
1451 | ||
3da10d80 KS |
1452 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1453 | struct dwarf2_cu *cu); | |
1454 | ||
c906108c | 1455 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
1456 | information and return true if we have enough to do something. |
1457 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
1458 | ELF names are used. */ | |
c906108c SS |
1459 | |
1460 | int | |
251d32d9 TG |
1461 | dwarf2_has_info (struct objfile *objfile, |
1462 | const struct dwarf2_debug_sections *names) | |
c906108c | 1463 | { |
be391dca TT |
1464 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1465 | if (!dwarf2_per_objfile) | |
1466 | { | |
1467 | /* Initialize per-objfile state. */ | |
1468 | struct dwarf2_per_objfile *data | |
1469 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1470 | |
be391dca TT |
1471 | memset (data, 0, sizeof (*data)); |
1472 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1473 | dwarf2_per_objfile = data; | |
6502dd73 | 1474 | |
251d32d9 TG |
1475 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
1476 | (void *) names); | |
be391dca TT |
1477 | dwarf2_per_objfile->objfile = objfile; |
1478 | } | |
1479 | return (dwarf2_per_objfile->info.asection != NULL | |
1480 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1481 | } |
1482 | ||
251d32d9 TG |
1483 | /* When loading sections, we look either for uncompressed section or for |
1484 | compressed section names. */ | |
233a11ab CS |
1485 | |
1486 | static int | |
251d32d9 TG |
1487 | section_is_p (const char *section_name, |
1488 | const struct dwarf2_section_names *names) | |
233a11ab | 1489 | { |
251d32d9 TG |
1490 | if (names->normal != NULL |
1491 | && strcmp (section_name, names->normal) == 0) | |
1492 | return 1; | |
1493 | if (names->compressed != NULL | |
1494 | && strcmp (section_name, names->compressed) == 0) | |
1495 | return 1; | |
1496 | return 0; | |
233a11ab CS |
1497 | } |
1498 | ||
c906108c SS |
1499 | /* This function is mapped across the sections and remembers the |
1500 | offset and size of each of the debugging sections we are interested | |
1501 | in. */ | |
1502 | ||
1503 | static void | |
251d32d9 | 1504 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
c906108c | 1505 | { |
251d32d9 TG |
1506 | const struct dwarf2_debug_sections *names; |
1507 | ||
1508 | if (vnames == NULL) | |
1509 | names = &dwarf2_elf_names; | |
1510 | else | |
1511 | names = (const struct dwarf2_debug_sections *) vnames; | |
1512 | ||
1513 | if (section_is_p (sectp->name, &names->info)) | |
c906108c | 1514 | { |
dce234bc PP |
1515 | dwarf2_per_objfile->info.asection = sectp; |
1516 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1517 | } |
251d32d9 | 1518 | else if (section_is_p (sectp->name, &names->abbrev)) |
c906108c | 1519 | { |
dce234bc PP |
1520 | dwarf2_per_objfile->abbrev.asection = sectp; |
1521 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1522 | } |
251d32d9 | 1523 | else if (section_is_p (sectp->name, &names->line)) |
c906108c | 1524 | { |
dce234bc PP |
1525 | dwarf2_per_objfile->line.asection = sectp; |
1526 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1527 | } |
251d32d9 | 1528 | else if (section_is_p (sectp->name, &names->loc)) |
c906108c | 1529 | { |
dce234bc PP |
1530 | dwarf2_per_objfile->loc.asection = sectp; |
1531 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1532 | } |
251d32d9 | 1533 | else if (section_is_p (sectp->name, &names->macinfo)) |
c906108c | 1534 | { |
dce234bc PP |
1535 | dwarf2_per_objfile->macinfo.asection = sectp; |
1536 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1537 | } |
cf2c3c16 TT |
1538 | else if (section_is_p (sectp->name, &names->macro)) |
1539 | { | |
1540 | dwarf2_per_objfile->macro.asection = sectp; | |
1541 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); | |
1542 | } | |
251d32d9 | 1543 | else if (section_is_p (sectp->name, &names->str)) |
c906108c | 1544 | { |
dce234bc PP |
1545 | dwarf2_per_objfile->str.asection = sectp; |
1546 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1547 | } |
3019eac3 DE |
1548 | else if (section_is_p (sectp->name, &names->addr)) |
1549 | { | |
1550 | dwarf2_per_objfile->addr.asection = sectp; | |
1551 | dwarf2_per_objfile->addr.size = bfd_get_section_size (sectp); | |
1552 | } | |
251d32d9 | 1553 | else if (section_is_p (sectp->name, &names->frame)) |
b6af0555 | 1554 | { |
dce234bc PP |
1555 | dwarf2_per_objfile->frame.asection = sectp; |
1556 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1557 | } |
251d32d9 | 1558 | else if (section_is_p (sectp->name, &names->eh_frame)) |
b6af0555 | 1559 | { |
3799ccc6 | 1560 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1561 | |
3799ccc6 EZ |
1562 | if (aflag & SEC_HAS_CONTENTS) |
1563 | { | |
dce234bc PP |
1564 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1565 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1566 | } |
b6af0555 | 1567 | } |
251d32d9 | 1568 | else if (section_is_p (sectp->name, &names->ranges)) |
af34e669 | 1569 | { |
dce234bc PP |
1570 | dwarf2_per_objfile->ranges.asection = sectp; |
1571 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1572 | } |
251d32d9 | 1573 | else if (section_is_p (sectp->name, &names->types)) |
348e048f | 1574 | { |
8b70b953 TT |
1575 | struct dwarf2_section_info type_section; |
1576 | ||
1577 | memset (&type_section, 0, sizeof (type_section)); | |
1578 | type_section.asection = sectp; | |
1579 | type_section.size = bfd_get_section_size (sectp); | |
1580 | ||
1581 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
1582 | &type_section); | |
348e048f | 1583 | } |
251d32d9 | 1584 | else if (section_is_p (sectp->name, &names->gdb_index)) |
9291a0cd TT |
1585 | { |
1586 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1587 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1588 | } | |
dce234bc | 1589 | |
72dca2f5 FR |
1590 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1591 | && bfd_section_vma (abfd, sectp) == 0) | |
1592 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1593 | } |
1594 | ||
dce234bc PP |
1595 | /* Decompress a section that was compressed using zlib. Store the |
1596 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1597 | |
1598 | static void | |
dce234bc PP |
1599 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1600 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1601 | { | |
3019eac3 | 1602 | bfd *abfd = sectp->owner; |
dce234bc PP |
1603 | #ifndef HAVE_ZLIB_H |
1604 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1605 | "is disabled in this copy of GDB"), | |
1606 | bfd_get_filename (abfd)); | |
1607 | #else | |
1608 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1609 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1610 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1611 | bfd_size_type uncompressed_size; |
1612 | gdb_byte *uncompressed_buffer; | |
1613 | z_stream strm; | |
1614 | int rc; | |
1615 | int header_size = 12; | |
1616 | ||
1617 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
3e43a32a MS |
1618 | || bfd_bread (compressed_buffer, |
1619 | compressed_size, abfd) != compressed_size) | |
dce234bc PP |
1620 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
1621 | bfd_get_filename (abfd)); | |
1622 | ||
1623 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1624 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1625 | if (compressed_size < header_size | |
1626 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1627 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1628 | bfd_get_filename (abfd)); | |
1629 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1630 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1631 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1632 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1633 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1634 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1635 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1636 | uncompressed_size += compressed_buffer[11]; | |
1637 | ||
1638 | /* It is possible the section consists of several compressed | |
1639 | buffers concatenated together, so we uncompress in a loop. */ | |
1640 | strm.zalloc = NULL; | |
1641 | strm.zfree = NULL; | |
1642 | strm.opaque = NULL; | |
1643 | strm.avail_in = compressed_size - header_size; | |
1644 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1645 | strm.avail_out = uncompressed_size; | |
1646 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1647 | uncompressed_size); | |
1648 | rc = inflateInit (&strm); | |
1649 | while (strm.avail_in > 0) | |
1650 | { | |
1651 | if (rc != Z_OK) | |
1652 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1653 | bfd_get_filename (abfd), rc); | |
1654 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1655 | + (uncompressed_size - strm.avail_out)); | |
1656 | rc = inflate (&strm, Z_FINISH); | |
1657 | if (rc != Z_STREAM_END) | |
1658 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1659 | bfd_get_filename (abfd), rc); | |
1660 | rc = inflateReset (&strm); | |
1661 | } | |
1662 | rc = inflateEnd (&strm); | |
1663 | if (rc != Z_OK | |
1664 | || strm.avail_out != 0) | |
1665 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1666 | bfd_get_filename (abfd), rc); | |
1667 | ||
affddf13 | 1668 | do_cleanups (cleanup); |
dce234bc PP |
1669 | *outbuf = uncompressed_buffer; |
1670 | *outsize = uncompressed_size; | |
1671 | #endif | |
233a11ab CS |
1672 | } |
1673 | ||
9e0ac564 TT |
1674 | /* A helper function that decides whether a section is empty. */ |
1675 | ||
1676 | static int | |
1677 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1678 | { | |
1679 | return info->asection == NULL || info->size == 0; | |
1680 | } | |
1681 | ||
3019eac3 DE |
1682 | /* Read the contents of the section INFO. |
1683 | OBJFILE is the main object file, but not necessarily the file where | |
1684 | the section comes from. E.g., for DWO files INFO->asection->owner | |
1685 | is the bfd of the DWO file. | |
dce234bc | 1686 | If the section is compressed, uncompress it before returning. */ |
c906108c | 1687 | |
dce234bc PP |
1688 | static void |
1689 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1690 | { |
dce234bc | 1691 | asection *sectp = info->asection; |
3019eac3 | 1692 | bfd *abfd; |
dce234bc PP |
1693 | gdb_byte *buf, *retbuf; |
1694 | unsigned char header[4]; | |
c906108c | 1695 | |
be391dca TT |
1696 | if (info->readin) |
1697 | return; | |
dce234bc | 1698 | info->buffer = NULL; |
b315ab21 | 1699 | info->map_addr = NULL; |
be391dca | 1700 | info->readin = 1; |
188dd5d6 | 1701 | |
9e0ac564 | 1702 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1703 | return; |
c906108c | 1704 | |
3019eac3 DE |
1705 | /* Note that ABFD may not be from OBJFILE, e.g. a DWO section. */ |
1706 | abfd = sectp->owner; | |
1707 | ||
dce234bc PP |
1708 | /* Check if the file has a 4-byte header indicating compression. */ |
1709 | if (info->size > sizeof (header) | |
1710 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1711 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1712 | { | |
1713 | /* Upon decompression, update the buffer and its size. */ | |
1714 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1715 | { | |
1716 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1717 | &info->size); | |
1718 | return; | |
1719 | } | |
1720 | } | |
4bdf3d34 | 1721 | |
dce234bc PP |
1722 | #ifdef HAVE_MMAP |
1723 | if (pagesize == 0) | |
1724 | pagesize = getpagesize (); | |
2e276125 | 1725 | |
dce234bc PP |
1726 | /* Only try to mmap sections which are large enough: we don't want to |
1727 | waste space due to fragmentation. Also, only try mmap for sections | |
1728 | without relocations. */ | |
1729 | ||
1730 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1731 | { | |
b315ab21 TG |
1732 | info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ, |
1733 | MAP_PRIVATE, sectp->filepos, | |
1734 | &info->map_addr, &info->map_len); | |
dce234bc | 1735 | |
b315ab21 | 1736 | if ((caddr_t)info->buffer != MAP_FAILED) |
dce234bc | 1737 | { |
be391dca | 1738 | #if HAVE_POSIX_MADVISE |
b315ab21 | 1739 | posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED); |
be391dca | 1740 | #endif |
dce234bc PP |
1741 | return; |
1742 | } | |
1743 | } | |
1744 | #endif | |
1745 | ||
1746 | /* If we get here, we are a normal, not-compressed section. */ | |
1747 | info->buffer = buf | |
1748 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1749 | ||
1750 | /* When debugging .o files, we may need to apply relocations; see | |
1751 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1752 | We never compress sections in .o files, so we only need to | |
1753 | try this when the section is not compressed. */ | |
ac8035ab | 1754 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1755 | if (retbuf != NULL) |
1756 | { | |
1757 | info->buffer = retbuf; | |
1758 | return; | |
1759 | } | |
1760 | ||
1761 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1762 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1763 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1764 | bfd_get_filename (abfd)); | |
1765 | } | |
1766 | ||
9e0ac564 TT |
1767 | /* A helper function that returns the size of a section in a safe way. |
1768 | If you are positive that the section has been read before using the | |
1769 | size, then it is safe to refer to the dwarf2_section_info object's | |
1770 | "size" field directly. In other cases, you must call this | |
1771 | function, because for compressed sections the size field is not set | |
1772 | correctly until the section has been read. */ | |
1773 | ||
1774 | static bfd_size_type | |
1775 | dwarf2_section_size (struct objfile *objfile, | |
1776 | struct dwarf2_section_info *info) | |
1777 | { | |
1778 | if (!info->readin) | |
1779 | dwarf2_read_section (objfile, info); | |
1780 | return info->size; | |
1781 | } | |
1782 | ||
dce234bc | 1783 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1784 | SECTION_NAME. */ |
af34e669 | 1785 | |
dce234bc | 1786 | void |
3017a003 TG |
1787 | dwarf2_get_section_info (struct objfile *objfile, |
1788 | enum dwarf2_section_enum sect, | |
dce234bc PP |
1789 | asection **sectp, gdb_byte **bufp, |
1790 | bfd_size_type *sizep) | |
1791 | { | |
1792 | struct dwarf2_per_objfile *data | |
1793 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1794 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1795 | |
1796 | /* We may see an objfile without any DWARF, in which case we just | |
1797 | return nothing. */ | |
1798 | if (data == NULL) | |
1799 | { | |
1800 | *sectp = NULL; | |
1801 | *bufp = NULL; | |
1802 | *sizep = 0; | |
1803 | return; | |
1804 | } | |
3017a003 TG |
1805 | switch (sect) |
1806 | { | |
1807 | case DWARF2_DEBUG_FRAME: | |
1808 | info = &data->frame; | |
1809 | break; | |
1810 | case DWARF2_EH_FRAME: | |
1811 | info = &data->eh_frame; | |
1812 | break; | |
1813 | default: | |
1814 | gdb_assert_not_reached ("unexpected section"); | |
1815 | } | |
dce234bc | 1816 | |
9e0ac564 | 1817 | dwarf2_read_section (objfile, info); |
dce234bc PP |
1818 | |
1819 | *sectp = info->asection; | |
1820 | *bufp = info->buffer; | |
1821 | *sizep = info->size; | |
1822 | } | |
1823 | ||
9291a0cd | 1824 | \f |
7b9f3c50 DE |
1825 | /* DWARF quick_symbols_functions support. */ |
1826 | ||
1827 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
1828 | unique line tables, so we maintain a separate table of all .debug_line | |
1829 | derived entries to support the sharing. | |
1830 | All the quick functions need is the list of file names. We discard the | |
1831 | line_header when we're done and don't need to record it here. */ | |
1832 | struct quick_file_names | |
1833 | { | |
1834 | /* The offset in .debug_line of the line table. We hash on this. */ | |
1835 | unsigned int offset; | |
1836 | ||
1837 | /* The number of entries in file_names, real_names. */ | |
1838 | unsigned int num_file_names; | |
1839 | ||
1840 | /* The file names from the line table, after being run through | |
1841 | file_full_name. */ | |
1842 | const char **file_names; | |
1843 | ||
1844 | /* The file names from the line table after being run through | |
1845 | gdb_realpath. These are computed lazily. */ | |
1846 | const char **real_names; | |
1847 | }; | |
1848 | ||
1849 | /* When using the index (and thus not using psymtabs), each CU has an | |
1850 | object of this type. This is used to hold information needed by | |
1851 | the various "quick" methods. */ | |
1852 | struct dwarf2_per_cu_quick_data | |
1853 | { | |
1854 | /* The file table. This can be NULL if there was no file table | |
1855 | or it's currently not read in. | |
1856 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
1857 | struct quick_file_names *file_names; | |
1858 | ||
1859 | /* The corresponding symbol table. This is NULL if symbols for this | |
1860 | CU have not yet been read. */ | |
1861 | struct symtab *symtab; | |
1862 | ||
1863 | /* A temporary mark bit used when iterating over all CUs in | |
1864 | expand_symtabs_matching. */ | |
1865 | unsigned int mark : 1; | |
1866 | ||
1867 | /* True if we've tried to read the file table and found there isn't one. | |
1868 | There will be no point in trying to read it again next time. */ | |
1869 | unsigned int no_file_data : 1; | |
1870 | }; | |
1871 | ||
1872 | /* Hash function for a quick_file_names. */ | |
1873 | ||
1874 | static hashval_t | |
1875 | hash_file_name_entry (const void *e) | |
1876 | { | |
1877 | const struct quick_file_names *file_data = e; | |
1878 | ||
1879 | return file_data->offset; | |
1880 | } | |
1881 | ||
1882 | /* Equality function for a quick_file_names. */ | |
1883 | ||
1884 | static int | |
1885 | eq_file_name_entry (const void *a, const void *b) | |
1886 | { | |
1887 | const struct quick_file_names *ea = a; | |
1888 | const struct quick_file_names *eb = b; | |
1889 | ||
1890 | return ea->offset == eb->offset; | |
1891 | } | |
1892 | ||
1893 | /* Delete function for a quick_file_names. */ | |
1894 | ||
1895 | static void | |
1896 | delete_file_name_entry (void *e) | |
1897 | { | |
1898 | struct quick_file_names *file_data = e; | |
1899 | int i; | |
1900 | ||
1901 | for (i = 0; i < file_data->num_file_names; ++i) | |
1902 | { | |
1903 | xfree ((void*) file_data->file_names[i]); | |
1904 | if (file_data->real_names) | |
1905 | xfree ((void*) file_data->real_names[i]); | |
1906 | } | |
1907 | ||
1908 | /* The space for the struct itself lives on objfile_obstack, | |
1909 | so we don't free it here. */ | |
1910 | } | |
1911 | ||
1912 | /* Create a quick_file_names hash table. */ | |
1913 | ||
1914 | static htab_t | |
1915 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
1916 | { | |
1917 | return htab_create_alloc (nr_initial_entries, | |
1918 | hash_file_name_entry, eq_file_name_entry, | |
1919 | delete_file_name_entry, xcalloc, xfree); | |
1920 | } | |
9291a0cd | 1921 | |
918dd910 JK |
1922 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
1923 | have to be created afterwards. You should call age_cached_comp_units after | |
1924 | processing PER_CU->CU. dw2_setup must have been already called. */ | |
1925 | ||
1926 | static void | |
1927 | load_cu (struct dwarf2_per_cu_data *per_cu) | |
1928 | { | |
3019eac3 | 1929 | if (per_cu->is_debug_types) |
e5fe5e75 | 1930 | load_full_type_unit (per_cu); |
918dd910 | 1931 | else |
a0f42c21 | 1932 | load_full_comp_unit (per_cu); |
918dd910 | 1933 | |
918dd910 | 1934 | gdb_assert (per_cu->cu != NULL); |
2dc860c0 DE |
1935 | |
1936 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); | |
918dd910 JK |
1937 | } |
1938 | ||
a0f42c21 | 1939 | /* Read in the symbols for PER_CU. */ |
2fdf6df6 | 1940 | |
9291a0cd | 1941 | static void |
a0f42c21 | 1942 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1943 | { |
1944 | struct cleanup *back_to; | |
1945 | ||
1946 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1947 | ||
a0f42c21 | 1948 | queue_comp_unit (per_cu); |
9291a0cd | 1949 | |
918dd910 | 1950 | load_cu (per_cu); |
9291a0cd | 1951 | |
a0f42c21 | 1952 | process_queue (); |
9291a0cd TT |
1953 | |
1954 | /* Age the cache, releasing compilation units that have not | |
1955 | been used recently. */ | |
1956 | age_cached_comp_units (); | |
1957 | ||
1958 | do_cleanups (back_to); | |
1959 | } | |
1960 | ||
1961 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1962 | the objfile from which this CU came. Returns the resulting symbol | |
1963 | table. */ | |
2fdf6df6 | 1964 | |
9291a0cd | 1965 | static struct symtab * |
a0f42c21 | 1966 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1967 | { |
1968 | if (!per_cu->v.quick->symtab) | |
1969 | { | |
1970 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1971 | increment_reading_symtab (); | |
a0f42c21 | 1972 | dw2_do_instantiate_symtab (per_cu); |
9291a0cd TT |
1973 | do_cleanups (back_to); |
1974 | } | |
1975 | return per_cu->v.quick->symtab; | |
1976 | } | |
1977 | ||
1fd400ff | 1978 | /* Return the CU given its index. */ |
2fdf6df6 | 1979 | |
1fd400ff TT |
1980 | static struct dwarf2_per_cu_data * |
1981 | dw2_get_cu (int index) | |
1982 | { | |
1983 | if (index >= dwarf2_per_objfile->n_comp_units) | |
1984 | { | |
1985 | index -= dwarf2_per_objfile->n_comp_units; | |
d467dd73 | 1986 | return dwarf2_per_objfile->all_type_units[index]; |
1fd400ff TT |
1987 | } |
1988 | return dwarf2_per_objfile->all_comp_units[index]; | |
1989 | } | |
1990 | ||
9291a0cd TT |
1991 | /* A helper function that knows how to read a 64-bit value in a way |
1992 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1993 | otherwise. */ | |
2fdf6df6 | 1994 | |
9291a0cd TT |
1995 | static int |
1996 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1997 | { | |
1998 | if (sizeof (ULONGEST) < 8) | |
1999 | { | |
2000 | int i; | |
2001 | ||
2002 | /* Ignore the upper 4 bytes if they are all zero. */ | |
2003 | for (i = 0; i < 4; ++i) | |
2004 | if (bytes[i + 4] != 0) | |
2005 | return 0; | |
2006 | ||
2007 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
2008 | } | |
2009 | else | |
2010 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
2011 | return 1; | |
2012 | } | |
2013 | ||
2014 | /* Read the CU list from the mapped index, and use it to create all | |
2015 | the CU objects for this objfile. Return 0 if something went wrong, | |
2016 | 1 if everything went ok. */ | |
2fdf6df6 | 2017 | |
9291a0cd | 2018 | static int |
1fd400ff TT |
2019 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
2020 | offset_type cu_list_elements) | |
9291a0cd TT |
2021 | { |
2022 | offset_type i; | |
9291a0cd TT |
2023 | |
2024 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
2025 | dwarf2_per_objfile->all_comp_units | |
2026 | = obstack_alloc (&objfile->objfile_obstack, | |
2027 | dwarf2_per_objfile->n_comp_units | |
2028 | * sizeof (struct dwarf2_per_cu_data *)); | |
2029 | ||
2030 | for (i = 0; i < cu_list_elements; i += 2) | |
2031 | { | |
2032 | struct dwarf2_per_cu_data *the_cu; | |
2033 | ULONGEST offset, length; | |
2034 | ||
2035 | if (!extract_cu_value (cu_list, &offset) | |
2036 | || !extract_cu_value (cu_list + 8, &length)) | |
2037 | return 0; | |
2038 | cu_list += 2 * 8; | |
2039 | ||
2040 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
2041 | struct dwarf2_per_cu_data); | |
b64f50a1 | 2042 | the_cu->offset.sect_off = offset; |
9291a0cd TT |
2043 | the_cu->length = length; |
2044 | the_cu->objfile = objfile; | |
3019eac3 | 2045 | the_cu->info_or_types_section = &dwarf2_per_objfile->info; |
9291a0cd TT |
2046 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2047 | struct dwarf2_per_cu_quick_data); | |
2048 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
2049 | } | |
2050 | ||
2051 | return 1; | |
2052 | } | |
2053 | ||
1fd400ff | 2054 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 2055 | |
1fd400ff | 2056 | static int |
673bfd45 | 2057 | create_signatured_type_table_from_index (struct objfile *objfile, |
8b70b953 | 2058 | struct dwarf2_section_info *section, |
673bfd45 DE |
2059 | const gdb_byte *bytes, |
2060 | offset_type elements) | |
1fd400ff TT |
2061 | { |
2062 | offset_type i; | |
673bfd45 | 2063 | htab_t sig_types_hash; |
1fd400ff | 2064 | |
d467dd73 DE |
2065 | dwarf2_per_objfile->n_type_units = elements / 3; |
2066 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 2067 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 2068 | dwarf2_per_objfile->n_type_units |
1fd400ff TT |
2069 | * sizeof (struct dwarf2_per_cu_data *)); |
2070 | ||
673bfd45 | 2071 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
2072 | |
2073 | for (i = 0; i < elements; i += 3) | |
2074 | { | |
52dc124a DE |
2075 | struct signatured_type *sig_type; |
2076 | ULONGEST offset, type_offset_in_tu, signature; | |
1fd400ff TT |
2077 | void **slot; |
2078 | ||
2079 | if (!extract_cu_value (bytes, &offset) | |
52dc124a | 2080 | || !extract_cu_value (bytes + 8, &type_offset_in_tu)) |
1fd400ff TT |
2081 | return 0; |
2082 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
2083 | bytes += 3 * 8; | |
2084 | ||
52dc124a | 2085 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
1fd400ff | 2086 | struct signatured_type); |
52dc124a | 2087 | sig_type->signature = signature; |
3019eac3 DE |
2088 | sig_type->type_offset_in_tu.cu_off = type_offset_in_tu; |
2089 | sig_type->per_cu.is_debug_types = 1; | |
2090 | sig_type->per_cu.info_or_types_section = section; | |
52dc124a DE |
2091 | sig_type->per_cu.offset.sect_off = offset; |
2092 | sig_type->per_cu.objfile = objfile; | |
2093 | sig_type->per_cu.v.quick | |
1fd400ff TT |
2094 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2095 | struct dwarf2_per_cu_quick_data); | |
2096 | ||
52dc124a DE |
2097 | slot = htab_find_slot (sig_types_hash, sig_type, INSERT); |
2098 | *slot = sig_type; | |
1fd400ff | 2099 | |
52dc124a | 2100 | dwarf2_per_objfile->all_type_units[i / 3] = &sig_type->per_cu; |
1fd400ff TT |
2101 | } |
2102 | ||
673bfd45 | 2103 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
2104 | |
2105 | return 1; | |
2106 | } | |
2107 | ||
9291a0cd TT |
2108 | /* Read the address map data from the mapped index, and use it to |
2109 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 2110 | |
9291a0cd TT |
2111 | static void |
2112 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
2113 | { | |
2114 | const gdb_byte *iter, *end; | |
2115 | struct obstack temp_obstack; | |
2116 | struct addrmap *mutable_map; | |
2117 | struct cleanup *cleanup; | |
2118 | CORE_ADDR baseaddr; | |
2119 | ||
2120 | obstack_init (&temp_obstack); | |
2121 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
2122 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
2123 | ||
2124 | iter = index->address_table; | |
2125 | end = iter + index->address_table_size; | |
2126 | ||
2127 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2128 | ||
2129 | while (iter < end) | |
2130 | { | |
2131 | ULONGEST hi, lo, cu_index; | |
2132 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
2133 | iter += 8; | |
2134 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
2135 | iter += 8; | |
2136 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
2137 | iter += 4; | |
2138 | ||
2139 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 2140 | dw2_get_cu (cu_index)); |
9291a0cd TT |
2141 | } |
2142 | ||
2143 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
2144 | &objfile->objfile_obstack); | |
2145 | do_cleanups (cleanup); | |
2146 | } | |
2147 | ||
59d7bcaf JK |
2148 | /* The hash function for strings in the mapped index. This is the same as |
2149 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
2150 | implementation. This is necessary because the hash function is tied to the | |
2151 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
2152 | SYMBOL_HASH_NEXT. |
2153 | ||
2154 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 2155 | |
9291a0cd | 2156 | static hashval_t |
559a7a62 | 2157 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
2158 | { |
2159 | const unsigned char *str = (const unsigned char *) p; | |
2160 | hashval_t r = 0; | |
2161 | unsigned char c; | |
2162 | ||
2163 | while ((c = *str++) != 0) | |
559a7a62 JK |
2164 | { |
2165 | if (index_version >= 5) | |
2166 | c = tolower (c); | |
2167 | r = r * 67 + c - 113; | |
2168 | } | |
9291a0cd TT |
2169 | |
2170 | return r; | |
2171 | } | |
2172 | ||
2173 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
2174 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
2175 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 2176 | |
9291a0cd TT |
2177 | static int |
2178 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
2179 | offset_type **vec_out) | |
2180 | { | |
0cf03b49 JK |
2181 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2182 | offset_type hash; | |
9291a0cd | 2183 | offset_type slot, step; |
559a7a62 | 2184 | int (*cmp) (const char *, const char *); |
9291a0cd | 2185 | |
0cf03b49 JK |
2186 | if (current_language->la_language == language_cplus |
2187 | || current_language->la_language == language_java | |
2188 | || current_language->la_language == language_fortran) | |
2189 | { | |
2190 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2191 | not contain any. */ | |
2192 | const char *paren = strchr (name, '('); | |
2193 | ||
2194 | if (paren) | |
2195 | { | |
2196 | char *dup; | |
2197 | ||
2198 | dup = xmalloc (paren - name + 1); | |
2199 | memcpy (dup, name, paren - name); | |
2200 | dup[paren - name] = 0; | |
2201 | ||
2202 | make_cleanup (xfree, dup); | |
2203 | name = dup; | |
2204 | } | |
2205 | } | |
2206 | ||
559a7a62 | 2207 | /* Index version 4 did not support case insensitive searches. But the |
feea76c2 | 2208 | indices for case insensitive languages are built in lowercase, therefore |
559a7a62 JK |
2209 | simulate our NAME being searched is also lowercased. */ |
2210 | hash = mapped_index_string_hash ((index->version == 4 | |
2211 | && case_sensitivity == case_sensitive_off | |
2212 | ? 5 : index->version), | |
2213 | name); | |
2214 | ||
3876f04e DE |
2215 | slot = hash & (index->symbol_table_slots - 1); |
2216 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 2217 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
2218 | |
2219 | for (;;) | |
2220 | { | |
2221 | /* Convert a slot number to an offset into the table. */ | |
2222 | offset_type i = 2 * slot; | |
2223 | const char *str; | |
3876f04e | 2224 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2225 | { |
2226 | do_cleanups (back_to); | |
2227 | return 0; | |
2228 | } | |
9291a0cd | 2229 | |
3876f04e | 2230 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 2231 | if (!cmp (name, str)) |
9291a0cd TT |
2232 | { |
2233 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2234 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2235 | do_cleanups (back_to); |
9291a0cd TT |
2236 | return 1; |
2237 | } | |
2238 | ||
3876f04e | 2239 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2240 | } |
2241 | } | |
2242 | ||
2243 | /* Read the index file. If everything went ok, initialize the "quick" | |
2244 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2fdf6df6 | 2245 | |
9291a0cd TT |
2246 | static int |
2247 | dwarf2_read_index (struct objfile *objfile) | |
2248 | { | |
9291a0cd TT |
2249 | char *addr; |
2250 | struct mapped_index *map; | |
b3b272e1 | 2251 | offset_type *metadata; |
ac0b195c KW |
2252 | const gdb_byte *cu_list; |
2253 | const gdb_byte *types_list = NULL; | |
2254 | offset_type version, cu_list_elements; | |
2255 | offset_type types_list_elements = 0; | |
1fd400ff | 2256 | int i; |
9291a0cd | 2257 | |
9e0ac564 | 2258 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
9291a0cd | 2259 | return 0; |
82430852 JK |
2260 | |
2261 | /* Older elfutils strip versions could keep the section in the main | |
2262 | executable while splitting it for the separate debug info file. */ | |
2263 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
2264 | & SEC_HAS_CONTENTS) == 0) | |
2265 | return 0; | |
2266 | ||
9291a0cd TT |
2267 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
2268 | ||
2269 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
2270 | /* Version check. */ | |
1fd400ff | 2271 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2272 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2273 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 2274 | contained incomplete addrmap. So, it seems better to just ignore such |
481860b3 | 2275 | indices. */ |
831adc1f | 2276 | if (version < 4) |
481860b3 GB |
2277 | { |
2278 | static int warning_printed = 0; | |
2279 | if (!warning_printed) | |
2280 | { | |
2281 | warning (_("Skipping obsolete .gdb_index section in %s."), | |
2282 | objfile->name); | |
2283 | warning_printed = 1; | |
2284 | } | |
2285 | return 0; | |
2286 | } | |
2287 | /* Index version 4 uses a different hash function than index version | |
2288 | 5 and later. | |
2289 | ||
2290 | Versions earlier than 6 did not emit psymbols for inlined | |
2291 | functions. Using these files will cause GDB not to be able to | |
2292 | set breakpoints on inlined functions by name, so we ignore these | |
2293 | indices unless the --use-deprecated-index-sections command line | |
2294 | option was supplied. */ | |
2295 | if (version < 6 && !use_deprecated_index_sections) | |
2296 | { | |
2297 | static int warning_printed = 0; | |
2298 | if (!warning_printed) | |
2299 | { | |
2300 | warning (_("Skipping deprecated .gdb_index section in %s, pass " | |
2301 | "--use-deprecated-index-sections to use them anyway"), | |
2302 | objfile->name); | |
2303 | warning_printed = 1; | |
2304 | } | |
2305 | return 0; | |
2306 | } | |
2307 | /* Indexes with higher version than the one supported by GDB may be no | |
594e8718 | 2308 | longer backward compatible. */ |
481860b3 | 2309 | if (version > 6) |
594e8718 | 2310 | return 0; |
9291a0cd TT |
2311 | |
2312 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
559a7a62 | 2313 | map->version = version; |
b3b272e1 | 2314 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
2315 | |
2316 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2317 | |
2318 | i = 0; | |
2319 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
2320 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 2321 | / 8); |
1fd400ff TT |
2322 | ++i; |
2323 | ||
987d643c TT |
2324 | types_list = addr + MAYBE_SWAP (metadata[i]); |
2325 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2326 | - MAYBE_SWAP (metadata[i])) | |
2327 | / 8); | |
2328 | ++i; | |
1fd400ff TT |
2329 | |
2330 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2331 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2332 | - MAYBE_SWAP (metadata[i])); | |
2333 | ++i; | |
2334 | ||
3876f04e DE |
2335 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2336 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2337 | - MAYBE_SWAP (metadata[i])) | |
2338 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2339 | ++i; |
9291a0cd | 2340 | |
1fd400ff TT |
2341 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2342 | ||
0fefef59 DE |
2343 | /* Don't use the index if it's empty. */ |
2344 | if (map->symbol_table_slots == 0) | |
2345 | return 0; | |
2346 | ||
1fd400ff TT |
2347 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) |
2348 | return 0; | |
2349 | ||
8b70b953 TT |
2350 | if (types_list_elements) |
2351 | { | |
2352 | struct dwarf2_section_info *section; | |
2353 | ||
2354 | /* We can only handle a single .debug_types when we have an | |
2355 | index. */ | |
2356 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) | |
2357 | return 0; | |
2358 | ||
2359 | section = VEC_index (dwarf2_section_info_def, | |
2360 | dwarf2_per_objfile->types, 0); | |
2361 | ||
2362 | if (!create_signatured_type_table_from_index (objfile, section, | |
2363 | types_list, | |
2364 | types_list_elements)) | |
2365 | return 0; | |
2366 | } | |
9291a0cd TT |
2367 | |
2368 | create_addrmap_from_index (objfile, map); | |
2369 | ||
2370 | dwarf2_per_objfile->index_table = map; | |
2371 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2372 | dwarf2_per_objfile->quick_file_names_table = |
2373 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2374 | |
2375 | return 1; | |
2376 | } | |
2377 | ||
2378 | /* A helper for the "quick" functions which sets the global | |
2379 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2380 | |
9291a0cd TT |
2381 | static void |
2382 | dw2_setup (struct objfile *objfile) | |
2383 | { | |
2384 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2385 | gdb_assert (dwarf2_per_objfile); | |
2386 | } | |
2387 | ||
dee91e82 | 2388 | /* die_reader_func for dw2_get_file_names. */ |
2fdf6df6 | 2389 | |
dee91e82 DE |
2390 | static void |
2391 | dw2_get_file_names_reader (const struct die_reader_specs *reader, | |
2392 | gdb_byte *info_ptr, | |
2393 | struct die_info *comp_unit_die, | |
2394 | int has_children, | |
2395 | void *data) | |
9291a0cd | 2396 | { |
dee91e82 DE |
2397 | struct dwarf2_cu *cu = reader->cu; |
2398 | struct dwarf2_per_cu_data *this_cu = cu->per_cu; | |
2399 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
7b9f3c50 | 2400 | struct line_header *lh; |
9291a0cd | 2401 | struct attribute *attr; |
dee91e82 | 2402 | int i; |
9ff913ba | 2403 | unsigned int bytes_read; |
9291a0cd | 2404 | char *name, *comp_dir; |
7b9f3c50 DE |
2405 | void **slot; |
2406 | struct quick_file_names *qfn; | |
2407 | unsigned int line_offset; | |
9291a0cd | 2408 | |
7b9f3c50 DE |
2409 | lh = NULL; |
2410 | slot = NULL; | |
2411 | line_offset = 0; | |
dee91e82 DE |
2412 | |
2413 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); | |
9291a0cd TT |
2414 | if (attr) |
2415 | { | |
7b9f3c50 DE |
2416 | struct quick_file_names find_entry; |
2417 | ||
2418 | line_offset = DW_UNSND (attr); | |
2419 | ||
2420 | /* We may have already read in this line header (TU line header sharing). | |
2421 | If we have we're done. */ | |
2422 | find_entry.offset = line_offset; | |
2423 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, | |
2424 | &find_entry, INSERT); | |
2425 | if (*slot != NULL) | |
2426 | { | |
7b9f3c50 | 2427 | this_cu->v.quick->file_names = *slot; |
dee91e82 | 2428 | return; |
7b9f3c50 DE |
2429 | } |
2430 | ||
3019eac3 | 2431 | lh = dwarf_decode_line_header (line_offset, cu); |
9291a0cd TT |
2432 | } |
2433 | if (lh == NULL) | |
2434 | { | |
7b9f3c50 | 2435 | this_cu->v.quick->no_file_data = 1; |
dee91e82 | 2436 | return; |
9291a0cd TT |
2437 | } |
2438 | ||
7b9f3c50 DE |
2439 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
2440 | qfn->offset = line_offset; | |
2441 | gdb_assert (slot != NULL); | |
2442 | *slot = qfn; | |
9291a0cd | 2443 | |
dee91e82 | 2444 | find_file_and_directory (comp_unit_die, cu, &name, &comp_dir); |
9291a0cd | 2445 | |
7b9f3c50 DE |
2446 | qfn->num_file_names = lh->num_file_names; |
2447 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2448 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2449 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2450 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2451 | qfn->real_names = NULL; | |
9291a0cd | 2452 | |
7b9f3c50 | 2453 | free_line_header (lh); |
7b9f3c50 DE |
2454 | |
2455 | this_cu->v.quick->file_names = qfn; | |
dee91e82 DE |
2456 | } |
2457 | ||
2458 | /* A helper for the "quick" functions which attempts to read the line | |
2459 | table for THIS_CU. */ | |
2460 | ||
2461 | static struct quick_file_names * | |
2462 | dw2_get_file_names (struct objfile *objfile, | |
2463 | struct dwarf2_per_cu_data *this_cu) | |
2464 | { | |
2465 | if (this_cu->v.quick->file_names != NULL) | |
2466 | return this_cu->v.quick->file_names; | |
2467 | /* If we know there is no line data, no point in looking again. */ | |
2468 | if (this_cu->v.quick->no_file_data) | |
2469 | return NULL; | |
2470 | ||
3019eac3 DE |
2471 | /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute |
2472 | in the stub for CUs, there's is no need to lookup the DWO file. | |
2473 | However, that's not the case for TUs where DW_AT_stmt_list lives in the | |
2474 | DWO file. */ | |
2475 | if (this_cu->is_debug_types) | |
2476 | init_tu_and_read_dies (this_cu, 0, dw2_get_file_names_reader, NULL); | |
2477 | else | |
2478 | init_cutu_and_read_dies_simple (this_cu, dw2_get_file_names_reader, NULL); | |
dee91e82 DE |
2479 | |
2480 | if (this_cu->v.quick->no_file_data) | |
2481 | return NULL; | |
2482 | return this_cu->v.quick->file_names; | |
9291a0cd TT |
2483 | } |
2484 | ||
2485 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2486 | real path for a given file name from the line table. */ |
2fdf6df6 | 2487 | |
9291a0cd | 2488 | static const char * |
7b9f3c50 DE |
2489 | dw2_get_real_path (struct objfile *objfile, |
2490 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2491 | { |
7b9f3c50 DE |
2492 | if (qfn->real_names == NULL) |
2493 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2494 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2495 | |
7b9f3c50 DE |
2496 | if (qfn->real_names[index] == NULL) |
2497 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2498 | |
7b9f3c50 | 2499 | return qfn->real_names[index]; |
9291a0cd TT |
2500 | } |
2501 | ||
2502 | static struct symtab * | |
2503 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2504 | { | |
2505 | int index; | |
ae2de4f8 | 2506 | |
9291a0cd TT |
2507 | dw2_setup (objfile); |
2508 | index = dwarf2_per_objfile->n_comp_units - 1; | |
a0f42c21 | 2509 | return dw2_instantiate_symtab (dw2_get_cu (index)); |
9291a0cd TT |
2510 | } |
2511 | ||
7b9f3c50 DE |
2512 | /* Traversal function for dw2_forget_cached_source_info. */ |
2513 | ||
2514 | static int | |
2515 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2516 | { |
7b9f3c50 | 2517 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2518 | |
7b9f3c50 | 2519 | if (file_data->real_names) |
9291a0cd | 2520 | { |
7b9f3c50 | 2521 | int i; |
9291a0cd | 2522 | |
7b9f3c50 | 2523 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2524 | { |
7b9f3c50 DE |
2525 | xfree ((void*) file_data->real_names[i]); |
2526 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
2527 | } |
2528 | } | |
7b9f3c50 DE |
2529 | |
2530 | return 1; | |
2531 | } | |
2532 | ||
2533 | static void | |
2534 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2535 | { | |
2536 | dw2_setup (objfile); | |
2537 | ||
2538 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
2539 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
2540 | } |
2541 | ||
f8eba3c6 TT |
2542 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
2543 | the symtabs and calls the iterator. */ | |
2544 | ||
2545 | static int | |
2546 | dw2_map_expand_apply (struct objfile *objfile, | |
2547 | struct dwarf2_per_cu_data *per_cu, | |
2548 | const char *name, | |
2549 | const char *full_path, const char *real_path, | |
2550 | int (*callback) (struct symtab *, void *), | |
2551 | void *data) | |
2552 | { | |
2553 | struct symtab *last_made = objfile->symtabs; | |
2554 | ||
2555 | /* Don't visit already-expanded CUs. */ | |
2556 | if (per_cu->v.quick->symtab) | |
2557 | return 0; | |
2558 | ||
2559 | /* This may expand more than one symtab, and we want to iterate over | |
2560 | all of them. */ | |
a0f42c21 | 2561 | dw2_instantiate_symtab (per_cu); |
f8eba3c6 TT |
2562 | |
2563 | return iterate_over_some_symtabs (name, full_path, real_path, callback, data, | |
2564 | objfile->symtabs, last_made); | |
2565 | } | |
2566 | ||
2567 | /* Implementation of the map_symtabs_matching_filename method. */ | |
2568 | ||
9291a0cd | 2569 | static int |
f8eba3c6 TT |
2570 | dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name, |
2571 | const char *full_path, const char *real_path, | |
2572 | int (*callback) (struct symtab *, void *), | |
2573 | void *data) | |
9291a0cd TT |
2574 | { |
2575 | int i; | |
c011a4f4 | 2576 | const char *name_basename = lbasename (name); |
4aac40c8 TT |
2577 | int name_len = strlen (name); |
2578 | int is_abs = IS_ABSOLUTE_PATH (name); | |
9291a0cd TT |
2579 | |
2580 | dw2_setup (objfile); | |
ae2de4f8 | 2581 | |
1fd400ff | 2582 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2583 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2584 | { |
2585 | int j; | |
e254ef6a | 2586 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2587 | struct quick_file_names *file_data; |
9291a0cd | 2588 | |
3d7bb9d9 | 2589 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2590 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2591 | continue; |
2592 | ||
7b9f3c50 DE |
2593 | file_data = dw2_get_file_names (objfile, per_cu); |
2594 | if (file_data == NULL) | |
9291a0cd TT |
2595 | continue; |
2596 | ||
7b9f3c50 | 2597 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2598 | { |
7b9f3c50 | 2599 | const char *this_name = file_data->file_names[j]; |
9291a0cd | 2600 | |
4aac40c8 TT |
2601 | if (FILENAME_CMP (name, this_name) == 0 |
2602 | || (!is_abs && compare_filenames_for_search (this_name, | |
2603 | name, name_len))) | |
9291a0cd | 2604 | { |
f8eba3c6 TT |
2605 | if (dw2_map_expand_apply (objfile, per_cu, |
2606 | name, full_path, real_path, | |
2607 | callback, data)) | |
2608 | return 1; | |
4aac40c8 | 2609 | } |
9291a0cd | 2610 | |
c011a4f4 DE |
2611 | /* Before we invoke realpath, which can get expensive when many |
2612 | files are involved, do a quick comparison of the basenames. */ | |
2613 | if (! basenames_may_differ | |
2614 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) | |
2615 | continue; | |
2616 | ||
9291a0cd TT |
2617 | if (full_path != NULL) |
2618 | { | |
7b9f3c50 DE |
2619 | const char *this_real_name = dw2_get_real_path (objfile, |
2620 | file_data, j); | |
9291a0cd | 2621 | |
7b9f3c50 | 2622 | if (this_real_name != NULL |
4aac40c8 TT |
2623 | && (FILENAME_CMP (full_path, this_real_name) == 0 |
2624 | || (!is_abs | |
2625 | && compare_filenames_for_search (this_real_name, | |
2626 | name, name_len)))) | |
9291a0cd | 2627 | { |
f8eba3c6 TT |
2628 | if (dw2_map_expand_apply (objfile, per_cu, |
2629 | name, full_path, real_path, | |
2630 | callback, data)) | |
2631 | return 1; | |
9291a0cd TT |
2632 | } |
2633 | } | |
2634 | ||
2635 | if (real_path != NULL) | |
2636 | { | |
7b9f3c50 DE |
2637 | const char *this_real_name = dw2_get_real_path (objfile, |
2638 | file_data, j); | |
9291a0cd | 2639 | |
7b9f3c50 | 2640 | if (this_real_name != NULL |
4aac40c8 TT |
2641 | && (FILENAME_CMP (real_path, this_real_name) == 0 |
2642 | || (!is_abs | |
2643 | && compare_filenames_for_search (this_real_name, | |
2644 | name, name_len)))) | |
9291a0cd | 2645 | { |
f8eba3c6 TT |
2646 | if (dw2_map_expand_apply (objfile, per_cu, |
2647 | name, full_path, real_path, | |
2648 | callback, data)) | |
2649 | return 1; | |
9291a0cd TT |
2650 | } |
2651 | } | |
2652 | } | |
2653 | } | |
2654 | ||
9291a0cd TT |
2655 | return 0; |
2656 | } | |
2657 | ||
2658 | static struct symtab * | |
2659 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2660 | const char *name, domain_enum domain) | |
2661 | { | |
774b6a14 | 2662 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2663 | instead. */ |
2664 | return NULL; | |
2665 | } | |
2666 | ||
2667 | /* A helper function that expands all symtabs that hold an object | |
2668 | named NAME. */ | |
2fdf6df6 | 2669 | |
9291a0cd TT |
2670 | static void |
2671 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2672 | { | |
2673 | dw2_setup (objfile); | |
2674 | ||
ae2de4f8 | 2675 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2676 | if (dwarf2_per_objfile->index_table) |
2677 | { | |
2678 | offset_type *vec; | |
2679 | ||
2680 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2681 | name, &vec)) | |
2682 | { | |
2683 | offset_type i, len = MAYBE_SWAP (*vec); | |
2684 | for (i = 0; i < len; ++i) | |
2685 | { | |
2686 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2687 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2688 | |
a0f42c21 | 2689 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2690 | } |
2691 | } | |
2692 | } | |
2693 | } | |
2694 | ||
774b6a14 TT |
2695 | static void |
2696 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
8903c50d | 2697 | enum block_enum block_kind, const char *name, |
774b6a14 | 2698 | domain_enum domain) |
9291a0cd | 2699 | { |
774b6a14 | 2700 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2701 | } |
2702 | ||
2703 | static void | |
2704 | dw2_print_stats (struct objfile *objfile) | |
2705 | { | |
2706 | int i, count; | |
2707 | ||
2708 | dw2_setup (objfile); | |
2709 | count = 0; | |
1fd400ff | 2710 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2711 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2712 | { |
e254ef6a | 2713 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2714 | |
e254ef6a | 2715 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2716 | ++count; |
2717 | } | |
2718 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2719 | } | |
2720 | ||
2721 | static void | |
2722 | dw2_dump (struct objfile *objfile) | |
2723 | { | |
2724 | /* Nothing worth printing. */ | |
2725 | } | |
2726 | ||
2727 | static void | |
2728 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2729 | struct section_offsets *delta) | |
2730 | { | |
2731 | /* There's nothing to relocate here. */ | |
2732 | } | |
2733 | ||
2734 | static void | |
2735 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2736 | const char *func_name) | |
2737 | { | |
2738 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2739 | } | |
2740 | ||
2741 | static void | |
2742 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2743 | { | |
2744 | int i; | |
2745 | ||
2746 | dw2_setup (objfile); | |
1fd400ff TT |
2747 | |
2748 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 2749 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2750 | { |
e254ef6a | 2751 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2752 | |
a0f42c21 | 2753 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2754 | } |
2755 | } | |
2756 | ||
2757 | static void | |
2758 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2759 | const char *filename) | |
2760 | { | |
2761 | int i; | |
2762 | ||
2763 | dw2_setup (objfile); | |
d4637a04 DE |
2764 | |
2765 | /* We don't need to consider type units here. | |
2766 | This is only called for examining code, e.g. expand_line_sal. | |
2767 | There can be an order of magnitude (or more) more type units | |
2768 | than comp units, and we avoid them if we can. */ | |
2769 | ||
2770 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
2771 | { |
2772 | int j; | |
e254ef6a | 2773 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2774 | struct quick_file_names *file_data; |
9291a0cd | 2775 | |
3d7bb9d9 | 2776 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2777 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2778 | continue; |
2779 | ||
7b9f3c50 DE |
2780 | file_data = dw2_get_file_names (objfile, per_cu); |
2781 | if (file_data == NULL) | |
9291a0cd TT |
2782 | continue; |
2783 | ||
7b9f3c50 | 2784 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2785 | { |
7b9f3c50 | 2786 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 2787 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 2788 | { |
a0f42c21 | 2789 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2790 | break; |
2791 | } | |
2792 | } | |
2793 | } | |
2794 | } | |
2795 | ||
dd786858 | 2796 | static const char * |
9291a0cd TT |
2797 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2798 | { | |
e254ef6a | 2799 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 2800 | offset_type *vec; |
7b9f3c50 | 2801 | struct quick_file_names *file_data; |
9291a0cd TT |
2802 | |
2803 | dw2_setup (objfile); | |
2804 | ||
ae2de4f8 | 2805 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd | 2806 | if (!dwarf2_per_objfile->index_table) |
96408a79 SA |
2807 | { |
2808 | struct symtab *s; | |
2809 | ||
2810 | ALL_OBJFILE_SYMTABS (objfile, s) | |
2811 | if (s->primary) | |
2812 | { | |
2813 | struct blockvector *bv = BLOCKVECTOR (s); | |
2814 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
2815 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); | |
2816 | ||
2817 | if (sym) | |
2818 | return sym->symtab->filename; | |
2819 | } | |
2820 | return NULL; | |
2821 | } | |
9291a0cd TT |
2822 | |
2823 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2824 | name, &vec)) | |
2825 | return NULL; | |
2826 | ||
2827 | /* Note that this just looks at the very first one named NAME -- but | |
2828 | actually we are looking for a function. find_main_filename | |
2829 | should be rewritten so that it doesn't require a custom hook. It | |
2830 | could just use the ordinary symbol tables. */ | |
2831 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2832 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2833 | |
7b9f3c50 DE |
2834 | file_data = dw2_get_file_names (objfile, per_cu); |
2835 | if (file_data == NULL) | |
9291a0cd TT |
2836 | return NULL; |
2837 | ||
7b9f3c50 | 2838 | return file_data->file_names[file_data->num_file_names - 1]; |
9291a0cd TT |
2839 | } |
2840 | ||
2841 | static void | |
40658b94 PH |
2842 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
2843 | struct objfile *objfile, int global, | |
2844 | int (*callback) (struct block *, | |
2845 | struct symbol *, void *), | |
2edb89d3 JK |
2846 | void *data, symbol_compare_ftype *match, |
2847 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 2848 | { |
40658b94 | 2849 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
2850 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
2851 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
2852 | } |
2853 | ||
2854 | static void | |
f8eba3c6 TT |
2855 | dw2_expand_symtabs_matching |
2856 | (struct objfile *objfile, | |
2857 | int (*file_matcher) (const char *, void *), | |
e078317b | 2858 | int (*name_matcher) (const char *, void *), |
f8eba3c6 TT |
2859 | enum search_domain kind, |
2860 | void *data) | |
9291a0cd TT |
2861 | { |
2862 | int i; | |
2863 | offset_type iter; | |
4b5246aa | 2864 | struct mapped_index *index; |
9291a0cd TT |
2865 | |
2866 | dw2_setup (objfile); | |
ae2de4f8 DE |
2867 | |
2868 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
2869 | if (!dwarf2_per_objfile->index_table) |
2870 | return; | |
4b5246aa | 2871 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 2872 | |
7b08b9eb | 2873 | if (file_matcher != NULL) |
24c79950 TT |
2874 | { |
2875 | struct cleanup *cleanup; | |
2876 | htab_t visited_found, visited_not_found; | |
2877 | ||
2878 | visited_found = htab_create_alloc (10, | |
2879 | htab_hash_pointer, htab_eq_pointer, | |
2880 | NULL, xcalloc, xfree); | |
2881 | cleanup = make_cleanup_htab_delete (visited_found); | |
2882 | visited_not_found = htab_create_alloc (10, | |
2883 | htab_hash_pointer, htab_eq_pointer, | |
2884 | NULL, xcalloc, xfree); | |
2885 | make_cleanup_htab_delete (visited_not_found); | |
2886 | ||
2887 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2888 | + dwarf2_per_objfile->n_type_units); ++i) | |
2889 | { | |
2890 | int j; | |
2891 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2892 | struct quick_file_names *file_data; | |
2893 | void **slot; | |
7b08b9eb | 2894 | |
24c79950 | 2895 | per_cu->v.quick->mark = 0; |
3d7bb9d9 | 2896 | |
24c79950 TT |
2897 | /* We only need to look at symtabs not already expanded. */ |
2898 | if (per_cu->v.quick->symtab) | |
2899 | continue; | |
7b08b9eb | 2900 | |
24c79950 TT |
2901 | file_data = dw2_get_file_names (objfile, per_cu); |
2902 | if (file_data == NULL) | |
2903 | continue; | |
7b08b9eb | 2904 | |
24c79950 TT |
2905 | if (htab_find (visited_not_found, file_data) != NULL) |
2906 | continue; | |
2907 | else if (htab_find (visited_found, file_data) != NULL) | |
2908 | { | |
2909 | per_cu->v.quick->mark = 1; | |
2910 | continue; | |
2911 | } | |
2912 | ||
2913 | for (j = 0; j < file_data->num_file_names; ++j) | |
2914 | { | |
2915 | if (file_matcher (file_data->file_names[j], data)) | |
2916 | { | |
2917 | per_cu->v.quick->mark = 1; | |
2918 | break; | |
2919 | } | |
2920 | } | |
2921 | ||
2922 | slot = htab_find_slot (per_cu->v.quick->mark | |
2923 | ? visited_found | |
2924 | : visited_not_found, | |
2925 | file_data, INSERT); | |
2926 | *slot = file_data; | |
2927 | } | |
2928 | ||
2929 | do_cleanups (cleanup); | |
2930 | } | |
9291a0cd | 2931 | |
3876f04e | 2932 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
2933 | { |
2934 | offset_type idx = 2 * iter; | |
2935 | const char *name; | |
2936 | offset_type *vec, vec_len, vec_idx; | |
2937 | ||
3876f04e | 2938 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
2939 | continue; |
2940 | ||
3876f04e | 2941 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd | 2942 | |
e078317b | 2943 | if (! (*name_matcher) (name, data)) |
9291a0cd TT |
2944 | continue; |
2945 | ||
2946 | /* The name was matched, now expand corresponding CUs that were | |
2947 | marked. */ | |
4b5246aa | 2948 | vec = (offset_type *) (index->constant_pool |
3876f04e | 2949 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
2950 | vec_len = MAYBE_SWAP (vec[0]); |
2951 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2952 | { | |
e254ef6a | 2953 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2954 | |
e254ef6a | 2955 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
7b08b9eb | 2956 | if (file_matcher == NULL || per_cu->v.quick->mark) |
a0f42c21 | 2957 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2958 | } |
2959 | } | |
2960 | } | |
2961 | ||
2962 | static struct symtab * | |
2963 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2964 | struct minimal_symbol *msymbol, | |
2965 | CORE_ADDR pc, | |
2966 | struct obj_section *section, | |
2967 | int warn_if_readin) | |
2968 | { | |
2969 | struct dwarf2_per_cu_data *data; | |
2970 | ||
2971 | dw2_setup (objfile); | |
2972 | ||
2973 | if (!objfile->psymtabs_addrmap) | |
2974 | return NULL; | |
2975 | ||
2976 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2977 | if (!data) | |
2978 | return NULL; | |
2979 | ||
2980 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2981 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2982 | paddress (get_objfile_arch (objfile), pc)); |
2983 | ||
a0f42c21 | 2984 | return dw2_instantiate_symtab (data); |
9291a0cd TT |
2985 | } |
2986 | ||
9291a0cd | 2987 | static void |
44b13c5a | 2988 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
74e2f255 | 2989 | void *data, int need_fullname) |
9291a0cd TT |
2990 | { |
2991 | int i; | |
24c79950 TT |
2992 | struct cleanup *cleanup; |
2993 | htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer, | |
2994 | NULL, xcalloc, xfree); | |
9291a0cd | 2995 | |
24c79950 | 2996 | cleanup = make_cleanup_htab_delete (visited); |
9291a0cd | 2997 | dw2_setup (objfile); |
ae2de4f8 | 2998 | |
24c79950 TT |
2999 | /* We can ignore file names coming from already-expanded CUs. */ |
3000 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
3001 | + dwarf2_per_objfile->n_type_units); ++i) | |
3002 | { | |
3003 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
3004 | ||
3005 | if (per_cu->v.quick->symtab) | |
3006 | { | |
3007 | void **slot = htab_find_slot (visited, per_cu->v.quick->file_names, | |
3008 | INSERT); | |
3009 | ||
3010 | *slot = per_cu->v.quick->file_names; | |
3011 | } | |
3012 | } | |
3013 | ||
1fd400ff | 3014 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 3015 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
3016 | { |
3017 | int j; | |
e254ef6a | 3018 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 3019 | struct quick_file_names *file_data; |
24c79950 | 3020 | void **slot; |
9291a0cd | 3021 | |
3d7bb9d9 | 3022 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 3023 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
3024 | continue; |
3025 | ||
7b9f3c50 DE |
3026 | file_data = dw2_get_file_names (objfile, per_cu); |
3027 | if (file_data == NULL) | |
9291a0cd TT |
3028 | continue; |
3029 | ||
24c79950 TT |
3030 | slot = htab_find_slot (visited, file_data, INSERT); |
3031 | if (*slot) | |
3032 | { | |
3033 | /* Already visited. */ | |
3034 | continue; | |
3035 | } | |
3036 | *slot = file_data; | |
3037 | ||
7b9f3c50 | 3038 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 3039 | { |
74e2f255 DE |
3040 | const char *this_real_name; |
3041 | ||
3042 | if (need_fullname) | |
3043 | this_real_name = dw2_get_real_path (objfile, file_data, j); | |
3044 | else | |
3045 | this_real_name = NULL; | |
7b9f3c50 | 3046 | (*fun) (file_data->file_names[j], this_real_name, data); |
9291a0cd TT |
3047 | } |
3048 | } | |
24c79950 TT |
3049 | |
3050 | do_cleanups (cleanup); | |
9291a0cd TT |
3051 | } |
3052 | ||
3053 | static int | |
3054 | dw2_has_symbols (struct objfile *objfile) | |
3055 | { | |
3056 | return 1; | |
3057 | } | |
3058 | ||
3059 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
3060 | { | |
3061 | dw2_has_symbols, | |
3062 | dw2_find_last_source_symtab, | |
3063 | dw2_forget_cached_source_info, | |
f8eba3c6 | 3064 | dw2_map_symtabs_matching_filename, |
9291a0cd | 3065 | dw2_lookup_symbol, |
774b6a14 | 3066 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
3067 | dw2_print_stats, |
3068 | dw2_dump, | |
3069 | dw2_relocate, | |
3070 | dw2_expand_symtabs_for_function, | |
3071 | dw2_expand_all_symtabs, | |
3072 | dw2_expand_symtabs_with_filename, | |
3073 | dw2_find_symbol_file, | |
40658b94 | 3074 | dw2_map_matching_symbols, |
9291a0cd TT |
3075 | dw2_expand_symtabs_matching, |
3076 | dw2_find_pc_sect_symtab, | |
9291a0cd TT |
3077 | dw2_map_symbol_filenames |
3078 | }; | |
3079 | ||
3080 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
3081 | file will use psymtabs, or 1 if using the GNU index. */ | |
3082 | ||
3083 | int | |
3084 | dwarf2_initialize_objfile (struct objfile *objfile) | |
3085 | { | |
3086 | /* If we're about to read full symbols, don't bother with the | |
3087 | indices. In this case we also don't care if some other debug | |
3088 | format is making psymtabs, because they are all about to be | |
3089 | expanded anyway. */ | |
3090 | if ((objfile->flags & OBJF_READNOW)) | |
3091 | { | |
3092 | int i; | |
3093 | ||
3094 | dwarf2_per_objfile->using_index = 1; | |
3095 | create_all_comp_units (objfile); | |
0e50663e | 3096 | create_all_type_units (objfile); |
7b9f3c50 DE |
3097 | dwarf2_per_objfile->quick_file_names_table = |
3098 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 3099 | |
1fd400ff | 3100 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 3101 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 3102 | { |
e254ef6a | 3103 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 3104 | |
e254ef6a DE |
3105 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
3106 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
3107 | } |
3108 | ||
3109 | /* Return 1 so that gdb sees the "quick" functions. However, | |
3110 | these functions will be no-ops because we will have expanded | |
3111 | all symtabs. */ | |
3112 | return 1; | |
3113 | } | |
3114 | ||
3115 | if (dwarf2_read_index (objfile)) | |
3116 | return 1; | |
3117 | ||
9291a0cd TT |
3118 | return 0; |
3119 | } | |
3120 | ||
3121 | \f | |
3122 | ||
dce234bc PP |
3123 | /* Build a partial symbol table. */ |
3124 | ||
3125 | void | |
f29dff0a | 3126 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 3127 | { |
f29dff0a | 3128 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
3129 | { |
3130 | init_psymbol_list (objfile, 1024); | |
3131 | } | |
3132 | ||
d146bf1e | 3133 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 3134 | } |
c906108c | 3135 | |
45452591 DE |
3136 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
3137 | ||
3138 | static inline int | |
b64f50a1 | 3139 | offset_in_cu_p (const struct comp_unit_head *cu_header, sect_offset offset) |
45452591 | 3140 | { |
b64f50a1 JK |
3141 | sect_offset bottom = { cu_header->offset.sect_off }; |
3142 | sect_offset top = { (cu_header->offset.sect_off + cu_header->length | |
3143 | + cu_header->initial_length_size) }; | |
9a619af0 | 3144 | |
b64f50a1 | 3145 | return (offset.sect_off >= bottom.sect_off && offset.sect_off < top.sect_off); |
45452591 DE |
3146 | } |
3147 | ||
93311388 DE |
3148 | /* Read in the comp unit header information from the debug_info at info_ptr. |
3149 | NOTE: This leaves members offset, first_die_offset to be filled in | |
3150 | by the caller. */ | |
107d2387 | 3151 | |
fe1b8b76 | 3152 | static gdb_byte * |
107d2387 | 3153 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 3154 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
3155 | { |
3156 | int signed_addr; | |
891d2f0b | 3157 | unsigned int bytes_read; |
c764a876 DE |
3158 | |
3159 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
3160 | cu_header->initial_length_size = bytes_read; | |
3161 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 3162 | info_ptr += bytes_read; |
107d2387 AC |
3163 | cu_header->version = read_2_bytes (abfd, info_ptr); |
3164 | info_ptr += 2; | |
b64f50a1 JK |
3165 | cu_header->abbrev_offset.sect_off = read_offset (abfd, info_ptr, cu_header, |
3166 | &bytes_read); | |
613e1657 | 3167 | info_ptr += bytes_read; |
107d2387 AC |
3168 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
3169 | info_ptr += 1; | |
3170 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
3171 | if (signed_addr < 0) | |
8e65ff28 | 3172 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3173 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 3174 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 3175 | |
107d2387 AC |
3176 | return info_ptr; |
3177 | } | |
3178 | ||
9ff913ba DE |
3179 | /* Subroutine of read_and_check_comp_unit_head and |
3180 | read_and_check_type_unit_head to simplify them. | |
3181 | Perform various error checking on the header. */ | |
3182 | ||
3183 | static void | |
3184 | error_check_comp_unit_head (struct comp_unit_head *header, | |
3185 | struct dwarf2_section_info *section) | |
3186 | { | |
3187 | bfd *abfd = section->asection->owner; | |
3188 | const char *filename = bfd_get_filename (abfd); | |
3189 | ||
3190 | if (header->version != 2 && header->version != 3 && header->version != 4) | |
3191 | error (_("Dwarf Error: wrong version in compilation unit header " | |
3192 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, | |
3193 | filename); | |
3194 | ||
b64f50a1 | 3195 | if (header->abbrev_offset.sect_off |
9ff913ba DE |
3196 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, |
3197 | &dwarf2_per_objfile->abbrev)) | |
3198 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " | |
3199 | "(offset 0x%lx + 6) [in module %s]"), | |
b64f50a1 | 3200 | (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off, |
9ff913ba DE |
3201 | filename); |
3202 | ||
3203 | /* Cast to unsigned long to use 64-bit arithmetic when possible to | |
3204 | avoid potential 32-bit overflow. */ | |
b64f50a1 | 3205 | if (((unsigned long) header->offset.sect_off |
9ff913ba DE |
3206 | + header->length + header->initial_length_size) |
3207 | > section->size) | |
3208 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " | |
3209 | "(offset 0x%lx + 0) [in module %s]"), | |
b64f50a1 | 3210 | (long) header->length, (long) header->offset.sect_off, |
9ff913ba DE |
3211 | filename); |
3212 | } | |
3213 | ||
3214 | /* Read in a CU/TU header and perform some basic error checking. | |
3215 | The contents of the header are stored in HEADER. | |
3216 | The result is a pointer to the start of the first DIE. */ | |
adabb602 | 3217 | |
fe1b8b76 | 3218 | static gdb_byte * |
9ff913ba DE |
3219 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
3220 | struct dwarf2_section_info *section, | |
3221 | gdb_byte *info_ptr, | |
3222 | int is_debug_types_section) | |
72bf9492 | 3223 | { |
fe1b8b76 | 3224 | gdb_byte *beg_of_comp_unit = info_ptr; |
9ff913ba | 3225 | bfd *abfd = section->asection->owner; |
72bf9492 | 3226 | |
b64f50a1 | 3227 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
adabb602 | 3228 | |
72bf9492 DJ |
3229 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
3230 | ||
460c1c54 CC |
3231 | /* If we're reading a type unit, skip over the signature and |
3232 | type_offset fields. */ | |
b0df02fd | 3233 | if (is_debug_types_section) |
460c1c54 CC |
3234 | info_ptr += 8 /*signature*/ + header->offset_size; |
3235 | ||
b64f50a1 | 3236 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
adabb602 | 3237 | |
9ff913ba | 3238 | error_check_comp_unit_head (header, section); |
72bf9492 DJ |
3239 | |
3240 | return info_ptr; | |
3241 | } | |
3242 | ||
348e048f DE |
3243 | /* Read in the types comp unit header information from .debug_types entry at |
3244 | types_ptr. The result is a pointer to one past the end of the header. */ | |
3245 | ||
3246 | static gdb_byte * | |
9ff913ba DE |
3247 | read_and_check_type_unit_head (struct comp_unit_head *header, |
3248 | struct dwarf2_section_info *section, | |
3249 | gdb_byte *info_ptr, | |
dee91e82 DE |
3250 | ULONGEST *signature, |
3251 | cu_offset *type_offset_in_tu) | |
348e048f | 3252 | { |
9ff913ba DE |
3253 | gdb_byte *beg_of_comp_unit = info_ptr; |
3254 | bfd *abfd = section->asection->owner; | |
348e048f | 3255 | |
b64f50a1 | 3256 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
348e048f | 3257 | |
9ff913ba | 3258 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
348e048f | 3259 | |
9ff913ba DE |
3260 | /* If we're reading a type unit, skip over the signature and |
3261 | type_offset fields. */ | |
3262 | if (signature != NULL) | |
3263 | *signature = read_8_bytes (abfd, info_ptr); | |
3264 | info_ptr += 8; | |
dee91e82 DE |
3265 | if (type_offset_in_tu != NULL) |
3266 | type_offset_in_tu->cu_off = read_offset_1 (abfd, info_ptr, | |
3267 | header->offset_size); | |
9ff913ba DE |
3268 | info_ptr += header->offset_size; |
3269 | ||
b64f50a1 | 3270 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
348e048f | 3271 | |
9ff913ba DE |
3272 | error_check_comp_unit_head (header, section); |
3273 | ||
3274 | return info_ptr; | |
348e048f DE |
3275 | } |
3276 | ||
aaa75496 JB |
3277 | /* Allocate a new partial symtab for file named NAME and mark this new |
3278 | partial symtab as being an include of PST. */ | |
3279 | ||
3280 | static void | |
3281 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
3282 | struct objfile *objfile) | |
3283 | { | |
3284 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
3285 | ||
3286 | subpst->section_offsets = pst->section_offsets; | |
3287 | subpst->textlow = 0; | |
3288 | subpst->texthigh = 0; | |
3289 | ||
3290 | subpst->dependencies = (struct partial_symtab **) | |
3291 | obstack_alloc (&objfile->objfile_obstack, | |
3292 | sizeof (struct partial_symtab *)); | |
3293 | subpst->dependencies[0] = pst; | |
3294 | subpst->number_of_dependencies = 1; | |
3295 | ||
3296 | subpst->globals_offset = 0; | |
3297 | subpst->n_global_syms = 0; | |
3298 | subpst->statics_offset = 0; | |
3299 | subpst->n_static_syms = 0; | |
3300 | subpst->symtab = NULL; | |
3301 | subpst->read_symtab = pst->read_symtab; | |
3302 | subpst->readin = 0; | |
3303 | ||
3304 | /* No private part is necessary for include psymtabs. This property | |
3305 | can be used to differentiate between such include psymtabs and | |
10b3939b | 3306 | the regular ones. */ |
58a9656e | 3307 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
3308 | } |
3309 | ||
3310 | /* Read the Line Number Program data and extract the list of files | |
3311 | included by the source file represented by PST. Build an include | |
d85a05f0 | 3312 | partial symtab for each of these included files. */ |
aaa75496 JB |
3313 | |
3314 | static void | |
3315 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
dee91e82 DE |
3316 | struct die_info *die, |
3317 | struct partial_symtab *pst) | |
aaa75496 | 3318 | { |
d85a05f0 DJ |
3319 | struct line_header *lh = NULL; |
3320 | struct attribute *attr; | |
aaa75496 | 3321 | |
d85a05f0 DJ |
3322 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
3323 | if (attr) | |
3019eac3 | 3324 | lh = dwarf_decode_line_header (DW_UNSND (attr), cu); |
aaa75496 JB |
3325 | if (lh == NULL) |
3326 | return; /* No linetable, so no includes. */ | |
3327 | ||
c6da4cef | 3328 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
f3f5162e | 3329 | dwarf_decode_lines (lh, pst->dirname, cu, pst, 1); |
aaa75496 JB |
3330 | |
3331 | free_line_header (lh); | |
3332 | } | |
3333 | ||
348e048f | 3334 | static hashval_t |
52dc124a | 3335 | hash_signatured_type (const void *item) |
348e048f | 3336 | { |
52dc124a | 3337 | const struct signatured_type *sig_type = item; |
9a619af0 | 3338 | |
348e048f | 3339 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
52dc124a | 3340 | return sig_type->signature; |
348e048f DE |
3341 | } |
3342 | ||
3343 | static int | |
52dc124a | 3344 | eq_signatured_type (const void *item_lhs, const void *item_rhs) |
348e048f DE |
3345 | { |
3346 | const struct signatured_type *lhs = item_lhs; | |
3347 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 3348 | |
348e048f DE |
3349 | return lhs->signature == rhs->signature; |
3350 | } | |
3351 | ||
1fd400ff TT |
3352 | /* Allocate a hash table for signatured types. */ |
3353 | ||
3354 | static htab_t | |
673bfd45 | 3355 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
3356 | { |
3357 | return htab_create_alloc_ex (41, | |
52dc124a DE |
3358 | hash_signatured_type, |
3359 | eq_signatured_type, | |
1fd400ff TT |
3360 | NULL, |
3361 | &objfile->objfile_obstack, | |
3362 | hashtab_obstack_allocate, | |
3363 | dummy_obstack_deallocate); | |
3364 | } | |
3365 | ||
d467dd73 | 3366 | /* A helper function to add a signatured type CU to a table. */ |
1fd400ff TT |
3367 | |
3368 | static int | |
d467dd73 | 3369 | add_signatured_type_cu_to_table (void **slot, void *datum) |
1fd400ff TT |
3370 | { |
3371 | struct signatured_type *sigt = *slot; | |
3372 | struct dwarf2_per_cu_data ***datap = datum; | |
3373 | ||
3374 | **datap = &sigt->per_cu; | |
3375 | ++*datap; | |
3376 | ||
3377 | return 1; | |
3378 | } | |
3379 | ||
3019eac3 DE |
3380 | /* Create the hash table of all entries in the .debug_types section. |
3381 | DWO_FILE is a pointer to the DWO file for .debug_types.dwo, NULL otherwise. | |
3382 | The result is a pointer to the hash table or NULL if there are | |
3383 | no types. */ | |
348e048f | 3384 | |
3019eac3 DE |
3385 | static htab_t |
3386 | create_debug_types_hash_table (struct dwo_file *dwo_file, | |
3387 | VEC (dwarf2_section_info_def) *types) | |
348e048f | 3388 | { |
3019eac3 | 3389 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
8b70b953 | 3390 | htab_t types_htab = NULL; |
8b70b953 TT |
3391 | int ix; |
3392 | struct dwarf2_section_info *section; | |
348e048f | 3393 | |
3019eac3 DE |
3394 | if (VEC_empty (dwarf2_section_info_def, types)) |
3395 | return NULL; | |
348e048f | 3396 | |
8b70b953 | 3397 | for (ix = 0; |
3019eac3 | 3398 | VEC_iterate (dwarf2_section_info_def, types, ix, section); |
8b70b953 TT |
3399 | ++ix) |
3400 | { | |
3019eac3 | 3401 | bfd *abfd; |
8b70b953 | 3402 | gdb_byte *info_ptr, *end_ptr; |
348e048f | 3403 | |
8b70b953 TT |
3404 | dwarf2_read_section (objfile, section); |
3405 | info_ptr = section->buffer; | |
348e048f | 3406 | |
8b70b953 TT |
3407 | if (info_ptr == NULL) |
3408 | continue; | |
348e048f | 3409 | |
3019eac3 DE |
3410 | /* We can't set abfd until now because the section may be empty or |
3411 | not present, in which case section->asection will be NULL. */ | |
3412 | abfd = section->asection->owner; | |
3413 | ||
8b70b953 | 3414 | if (types_htab == NULL) |
3019eac3 DE |
3415 | { |
3416 | if (dwo_file) | |
3417 | types_htab = allocate_dwo_unit_table (objfile); | |
3418 | else | |
3419 | types_htab = allocate_signatured_type_table (objfile); | |
3420 | } | |
348e048f | 3421 | |
8b70b953 | 3422 | if (dwarf2_die_debug) |
dee91e82 DE |
3423 | fprintf_unfiltered (gdb_stdlog, "Reading signatured types for %s:\n", |
3424 | bfd_get_filename (abfd)); | |
3425 | ||
3426 | /* We don't use init_cutu_and_read_dies_simple, or some such, here | |
3427 | because we don't need to read any dies: the signature is in the | |
3428 | header. */ | |
8b70b953 TT |
3429 | |
3430 | end_ptr = info_ptr + section->size; | |
3431 | while (info_ptr < end_ptr) | |
3432 | { | |
b64f50a1 | 3433 | sect_offset offset; |
3019eac3 | 3434 | cu_offset type_offset_in_tu; |
8b70b953 | 3435 | ULONGEST signature; |
52dc124a | 3436 | struct signatured_type *sig_type; |
3019eac3 | 3437 | struct dwo_unit *dwo_tu; |
8b70b953 TT |
3438 | void **slot; |
3439 | gdb_byte *ptr = info_ptr; | |
9ff913ba | 3440 | struct comp_unit_head header; |
dee91e82 | 3441 | unsigned int length; |
348e048f | 3442 | |
b64f50a1 | 3443 | offset.sect_off = ptr - section->buffer; |
348e048f | 3444 | |
8b70b953 | 3445 | /* We need to read the type's signature in order to build the hash |
9ff913ba | 3446 | table, but we don't need anything else just yet. */ |
348e048f | 3447 | |
9ff913ba | 3448 | ptr = read_and_check_type_unit_head (&header, section, ptr, |
3019eac3 | 3449 | &signature, &type_offset_in_tu); |
6caca83c | 3450 | |
dee91e82 DE |
3451 | length = header.initial_length_size + header.length; |
3452 | ||
6caca83c | 3453 | /* Skip dummy type units. */ |
dee91e82 DE |
3454 | if (ptr >= info_ptr + length |
3455 | || peek_abbrev_code (abfd, ptr) == 0) | |
6caca83c | 3456 | { |
dee91e82 | 3457 | info_ptr += header.initial_length_size + header.length; |
6caca83c CC |
3458 | continue; |
3459 | } | |
8b70b953 | 3460 | |
3019eac3 DE |
3461 | if (dwo_file) |
3462 | { | |
3463 | sig_type = NULL; | |
3464 | dwo_tu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
3465 | struct dwo_unit); | |
3466 | dwo_tu->dwo_file = dwo_file; | |
3467 | dwo_tu->signature = signature; | |
3468 | dwo_tu->type_offset_in_tu = type_offset_in_tu; | |
3469 | dwo_tu->info_or_types_section = section; | |
3470 | dwo_tu->offset = offset; | |
3471 | dwo_tu->length = length; | |
3472 | } | |
3473 | else | |
3474 | { | |
3475 | /* N.B.: type_offset is not usable if this type uses a DWO file. | |
3476 | The real type_offset is in the DWO file. */ | |
3477 | dwo_tu = NULL; | |
3478 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
3479 | struct signatured_type); | |
3480 | sig_type->signature = signature; | |
3481 | sig_type->type_offset_in_tu = type_offset_in_tu; | |
3482 | sig_type->per_cu.objfile = objfile; | |
3483 | sig_type->per_cu.is_debug_types = 1; | |
3484 | sig_type->per_cu.info_or_types_section = section; | |
3485 | sig_type->per_cu.offset = offset; | |
3486 | sig_type->per_cu.length = length; | |
3487 | } | |
8b70b953 | 3488 | |
3019eac3 DE |
3489 | slot = htab_find_slot (types_htab, |
3490 | dwo_file ? (void*) dwo_tu : (void *) sig_type, | |
3491 | INSERT); | |
8b70b953 TT |
3492 | gdb_assert (slot != NULL); |
3493 | if (*slot != NULL) | |
3494 | { | |
3019eac3 DE |
3495 | sect_offset dup_offset; |
3496 | ||
3497 | if (dwo_file) | |
3498 | { | |
3499 | const struct dwo_unit *dup_tu = *slot; | |
3500 | ||
3501 | dup_offset = dup_tu->offset; | |
3502 | } | |
3503 | else | |
3504 | { | |
3505 | const struct signatured_type *dup_tu = *slot; | |
3506 | ||
3507 | dup_offset = dup_tu->per_cu.offset; | |
3508 | } | |
b3c8eb43 | 3509 | |
8b70b953 TT |
3510 | complaint (&symfile_complaints, |
3511 | _("debug type entry at offset 0x%x is duplicate to the " | |
3512 | "entry at offset 0x%x, signature 0x%s"), | |
3019eac3 | 3513 | offset.sect_off, dup_offset.sect_off, |
8b70b953 | 3514 | phex (signature, sizeof (signature))); |
8b70b953 | 3515 | } |
3019eac3 | 3516 | *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type; |
348e048f | 3517 | |
8b70b953 TT |
3518 | if (dwarf2_die_debug) |
3519 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
b64f50a1 JK |
3520 | offset.sect_off, |
3521 | phex (signature, sizeof (signature))); | |
348e048f | 3522 | |
dee91e82 | 3523 | info_ptr += length; |
8b70b953 | 3524 | } |
348e048f DE |
3525 | } |
3526 | ||
3019eac3 DE |
3527 | return types_htab; |
3528 | } | |
3529 | ||
3530 | /* Create the hash table of all entries in the .debug_types section, | |
3531 | and initialize all_type_units. | |
3532 | The result is zero if there is an error (e.g. missing .debug_types section), | |
3533 | otherwise non-zero. */ | |
3534 | ||
3535 | static int | |
3536 | create_all_type_units (struct objfile *objfile) | |
3537 | { | |
3538 | htab_t types_htab; | |
3539 | struct dwarf2_per_cu_data **iter; | |
3540 | ||
3541 | types_htab = create_debug_types_hash_table (NULL, dwarf2_per_objfile->types); | |
3542 | if (types_htab == NULL) | |
3543 | { | |
3544 | dwarf2_per_objfile->signatured_types = NULL; | |
3545 | return 0; | |
3546 | } | |
3547 | ||
348e048f DE |
3548 | dwarf2_per_objfile->signatured_types = types_htab; |
3549 | ||
d467dd73 DE |
3550 | dwarf2_per_objfile->n_type_units = htab_elements (types_htab); |
3551 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 3552 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 3553 | dwarf2_per_objfile->n_type_units |
1fd400ff | 3554 | * sizeof (struct dwarf2_per_cu_data *)); |
d467dd73 DE |
3555 | iter = &dwarf2_per_objfile->all_type_units[0]; |
3556 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); | |
3557 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] | |
3558 | == dwarf2_per_objfile->n_type_units); | |
1fd400ff | 3559 | |
348e048f DE |
3560 | return 1; |
3561 | } | |
3562 | ||
380bca97 | 3563 | /* Lookup a signature based type for DW_FORM_ref_sig8. |
e319fa28 | 3564 | Returns NULL if signature SIG is not present in the table. */ |
348e048f DE |
3565 | |
3566 | static struct signatured_type * | |
e319fa28 | 3567 | lookup_signatured_type (ULONGEST sig) |
348e048f DE |
3568 | { |
3569 | struct signatured_type find_entry, *entry; | |
3570 | ||
3571 | if (dwarf2_per_objfile->signatured_types == NULL) | |
3572 | { | |
3573 | complaint (&symfile_complaints, | |
55f1336d | 3574 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
dcc07052 | 3575 | return NULL; |
348e048f DE |
3576 | } |
3577 | ||
3578 | find_entry.signature = sig; | |
3579 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
3580 | return entry; | |
3581 | } | |
3582 | ||
d85a05f0 DJ |
3583 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
3584 | ||
3585 | static void | |
3586 | init_cu_die_reader (struct die_reader_specs *reader, | |
dee91e82 | 3587 | struct dwarf2_cu *cu, |
3019eac3 DE |
3588 | struct dwarf2_section_info *section, |
3589 | struct dwo_file *dwo_file) | |
d85a05f0 | 3590 | { |
dee91e82 DE |
3591 | gdb_assert (section->readin); |
3592 | reader->abfd = section->asection->owner; | |
d85a05f0 | 3593 | reader->cu = cu; |
3019eac3 | 3594 | reader->dwo_file = dwo_file; |
dee91e82 DE |
3595 | reader->die_section = section; |
3596 | reader->buffer = section->buffer; | |
d85a05f0 DJ |
3597 | } |
3598 | ||
3599 | /* Find the base address of the compilation unit for range lists and | |
3600 | location lists. It will normally be specified by DW_AT_low_pc. | |
3601 | In DWARF-3 draft 4, the base address could be overridden by | |
3602 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3603 | compilation units with discontinuous ranges. */ | |
3604 | ||
3605 | static void | |
3606 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3607 | { | |
3608 | struct attribute *attr; | |
3609 | ||
3610 | cu->base_known = 0; | |
3611 | cu->base_address = 0; | |
3612 | ||
3613 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3614 | if (attr) | |
3615 | { | |
3616 | cu->base_address = DW_ADDR (attr); | |
3617 | cu->base_known = 1; | |
3618 | } | |
3619 | else | |
3620 | { | |
3621 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3622 | if (attr) | |
3623 | { | |
3624 | cu->base_address = DW_ADDR (attr); | |
3625 | cu->base_known = 1; | |
3626 | } | |
3627 | } | |
3628 | } | |
3629 | ||
dee91e82 DE |
3630 | /* Subroutine of init_{cu,tu}_and_read_dies. |
3631 | Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s). | |
3019eac3 | 3632 | If the CU defers to a DWO file, read the DWO file as well. |
dee91e82 DE |
3633 | |
3634 | If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it. | |
3635 | Otherwise, a new CU is allocated with xmalloc. | |
3636 | ||
3637 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to | |
3638 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. | |
3639 | ||
3640 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
3641 | linker) then DIE_READER_FUNC will not get called. | |
3642 | ||
3643 | FIXME: As an implementation detail between our callers and us, | |
3644 | USE_EXISTING_CU and KEEP are OK. But bubbling them up into their callers | |
3645 | isn't as clean as I'd like. Having more callers with good names | |
3646 | may be the way to go. */ | |
aaa75496 | 3647 | |
70221824 | 3648 | static void |
dee91e82 DE |
3649 | init_and_read_dies_worker (struct dwarf2_per_cu_data *this_cu, |
3650 | int use_existing_cu, int keep, | |
3651 | die_reader_func_ftype *die_reader_func, | |
3652 | void *data) | |
c906108c | 3653 | { |
dee91e82 | 3654 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
3019eac3 DE |
3655 | struct dwarf2_section_info *section = this_cu->info_or_types_section; |
3656 | bfd *abfd = section->asection->owner; | |
dee91e82 DE |
3657 | struct dwarf2_cu *cu; |
3658 | gdb_byte *begin_info_ptr, *info_ptr; | |
3659 | struct die_reader_specs reader; | |
d85a05f0 | 3660 | struct die_info *comp_unit_die; |
dee91e82 | 3661 | int has_children; |
d85a05f0 | 3662 | struct attribute *attr; |
dee91e82 DE |
3663 | struct cleanup *cleanups, *free_cu_cleanup = NULL; |
3664 | struct signatured_type *sig_type = NULL; | |
c906108c | 3665 | |
dee91e82 DE |
3666 | if (use_existing_cu) |
3667 | gdb_assert (keep); | |
3019eac3 | 3668 | if (this_cu->is_debug_types) |
dee91e82 | 3669 | gdb_assert (! use_existing_cu); |
23745b47 | 3670 | |
dee91e82 DE |
3671 | cleanups = make_cleanup (null_cleanup, NULL); |
3672 | ||
3673 | /* This is cheap if the section is already read in. */ | |
3674 | dwarf2_read_section (objfile, section); | |
3675 | ||
3676 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; | |
3677 | ||
3678 | if (use_existing_cu && this_cu->cu != NULL) | |
3679 | { | |
3680 | cu = this_cu->cu; | |
3681 | info_ptr += cu->header.first_die_offset.cu_off; | |
3682 | } | |
3683 | else | |
3684 | { | |
3685 | /* If !use_existing_cu, this_cu->cu must be NULL. */ | |
3686 | gdb_assert (this_cu->cu == NULL); | |
3687 | ||
3688 | cu = xmalloc (sizeof (*cu)); | |
3689 | init_one_comp_unit (cu, this_cu); | |
3690 | ||
3691 | /* If an error occurs while loading, release our storage. */ | |
3692 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); | |
3693 | ||
3019eac3 | 3694 | if (this_cu->is_debug_types) |
dee91e82 DE |
3695 | { |
3696 | ULONGEST signature; | |
3697 | ||
3698 | info_ptr = read_and_check_type_unit_head (&cu->header, | |
3699 | section, info_ptr, | |
3700 | &signature, NULL); | |
3701 | ||
3702 | /* There's no way to get from PER_CU to its containing | |
3703 | struct signatured_type. | |
3704 | But we have the signature so we can use that. */ | |
3705 | sig_type = lookup_signatured_type (signature); | |
3706 | /* We've already scanned all the signatured types, | |
3707 | this must succeed. */ | |
3708 | gdb_assert (sig_type != NULL); | |
3709 | gdb_assert (&sig_type->per_cu == this_cu); | |
3710 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); | |
3711 | ||
3712 | /* LENGTH has not been set yet for type units. */ | |
3713 | this_cu->length = cu->header.length + cu->header.initial_length_size; | |
3019eac3 DE |
3714 | |
3715 | /* Establish the type offset that can be used to lookup the type. */ | |
3716 | sig_type->type_offset_in_section.sect_off = | |
3717 | this_cu->offset.sect_off + sig_type->type_offset_in_tu.cu_off; | |
dee91e82 DE |
3718 | } |
3719 | else | |
3720 | { | |
3721 | info_ptr = read_and_check_comp_unit_head (&cu->header, | |
3722 | section, info_ptr, 0); | |
3723 | ||
3724 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); | |
3725 | gdb_assert (this_cu->length | |
3726 | == cu->header.length + cu->header.initial_length_size); | |
3727 | } | |
3728 | } | |
10b3939b | 3729 | |
6caca83c | 3730 | /* Skip dummy compilation units. */ |
dee91e82 | 3731 | if (info_ptr >= begin_info_ptr + this_cu->length |
6caca83c CC |
3732 | || peek_abbrev_code (abfd, info_ptr) == 0) |
3733 | { | |
dee91e82 | 3734 | do_cleanups (cleanups); |
21b2bd31 | 3735 | return; |
6caca83c CC |
3736 | } |
3737 | ||
93311388 | 3738 | /* Read the abbrevs for this compilation unit into a table. */ |
dee91e82 DE |
3739 | if (cu->dwarf2_abbrevs == NULL) |
3740 | { | |
3741 | dwarf2_read_abbrevs (cu, &dwarf2_per_objfile->abbrev); | |
3742 | make_cleanup (dwarf2_free_abbrev_table, cu); | |
3743 | } | |
af703f96 | 3744 | |
dee91e82 | 3745 | /* Read the top level CU/TU die. */ |
3019eac3 | 3746 | init_cu_die_reader (&reader, cu, section, NULL); |
dee91e82 | 3747 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
93311388 | 3748 | |
3019eac3 DE |
3749 | /* If we have a DWO stub, process it and then read in the DWO file. |
3750 | Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains | |
3751 | a DWO CU, that this test will fail. */ | |
3752 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu); | |
3753 | if (attr) | |
3754 | { | |
3755 | char *dwo_name = DW_STRING (attr); | |
3756 | const char *comp_dir; | |
3757 | struct dwo_unit *dwo_unit; | |
3758 | ULONGEST signature; /* Or dwo_id. */ | |
3759 | struct attribute *stmt_list, *low_pc, *high_pc, *ranges; | |
3760 | int i,num_extra_attrs; | |
3761 | ||
3762 | if (has_children) | |
3763 | error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name" | |
3764 | " has children (offset 0x%x) [in module %s]"), | |
3765 | this_cu->offset.sect_off, bfd_get_filename (abfd)); | |
3766 | ||
3767 | /* These attributes aren't processed until later: | |
3768 | DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges. | |
3769 | However, the attribute is found in the stub which we won't have later. | |
3770 | In order to not impose this complication on the rest of the code, | |
3771 | we read them here and copy them to the DWO CU/TU die. */ | |
3772 | stmt_list = low_pc = high_pc = ranges = NULL; | |
3773 | ||
3774 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the | |
3775 | DWO file. */ | |
3776 | if (! this_cu->is_debug_types) | |
3777 | stmt_list = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); | |
3778 | low_pc = dwarf2_attr (comp_unit_die, DW_AT_low_pc, cu); | |
3779 | high_pc = dwarf2_attr (comp_unit_die, DW_AT_high_pc, cu); | |
3780 | ranges = dwarf2_attr (comp_unit_die, DW_AT_ranges, cu); | |
3781 | ||
3782 | /* There should be a DW_AT_addr_base attribute here (if needed). | |
3783 | We need the value before we can process DW_FORM_GNU_addr_index. */ | |
3784 | cu->addr_base = 0; | |
3785 | cu->have_addr_base = 0; | |
3786 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_addr_base, cu); | |
3787 | if (attr) | |
3788 | { | |
3789 | cu->addr_base = DW_UNSND (attr); | |
3790 | cu->have_addr_base = 1; | |
3791 | } | |
3792 | ||
3793 | if (this_cu->is_debug_types) | |
3794 | { | |
3795 | gdb_assert (sig_type != NULL); | |
3796 | signature = sig_type->signature; | |
3797 | } | |
3798 | else | |
3799 | { | |
3800 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); | |
3801 | if (! attr) | |
3802 | error (_("Dwarf Error: missing dwo_id [in module %s]"), | |
3803 | dwo_name); | |
3804 | signature = DW_UNSND (attr); | |
3805 | } | |
3806 | ||
3807 | /* We may need the comp_dir in order to find the DWO file. */ | |
3808 | comp_dir = NULL; | |
3809 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu); | |
3810 | if (attr) | |
3811 | comp_dir = DW_STRING (attr); | |
3812 | ||
3813 | if (this_cu->is_debug_types) | |
3814 | dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir); | |
3815 | else | |
3816 | dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir, | |
3817 | signature); | |
3818 | ||
3819 | if (dwo_unit == NULL) | |
3820 | { | |
3821 | error (_("Dwarf Error: CU at offset 0x%x references unknown DWO" | |
3822 | " with ID %s [in module %s]"), | |
3823 | this_cu->offset.sect_off, | |
3824 | phex (signature, sizeof (signature)), | |
3825 | objfile->name); | |
3826 | } | |
3827 | ||
3828 | /* Set up for reading the DWO CU/TU. */ | |
3829 | cu->dwo_unit = dwo_unit; | |
3830 | section = dwo_unit->info_or_types_section; | |
3831 | begin_info_ptr = info_ptr = section->buffer + dwo_unit->offset.sect_off; | |
3832 | init_cu_die_reader (&reader, cu, section, dwo_unit->dwo_file); | |
3833 | ||
3834 | if (this_cu->is_debug_types) | |
3835 | { | |
3836 | ULONGEST signature; | |
3837 | ||
3838 | info_ptr = read_and_check_type_unit_head (&cu->header, | |
3839 | section, info_ptr, | |
3840 | &signature, NULL); | |
3841 | gdb_assert (sig_type->signature == signature); | |
3842 | gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off); | |
3843 | gdb_assert (dwo_unit->length | |
3844 | == cu->header.length + cu->header.initial_length_size); | |
3845 | ||
3846 | /* Establish the type offset that can be used to lookup the type. | |
3847 | For DWO files, we don't know it until now. */ | |
3848 | sig_type->type_offset_in_section.sect_off = | |
3849 | dwo_unit->offset.sect_off + dwo_unit->type_offset_in_tu.cu_off; | |
3850 | } | |
3851 | else | |
3852 | { | |
3853 | info_ptr = read_and_check_comp_unit_head (&cu->header, | |
3854 | section, info_ptr, 0); | |
3855 | gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off); | |
3856 | gdb_assert (dwo_unit->length | |
3857 | == cu->header.length + cu->header.initial_length_size); | |
3858 | } | |
3859 | ||
3860 | /* Discard the original CU's abbrev table, and read the DWO's. */ | |
3861 | dwarf2_free_abbrev_table (cu); | |
3862 | dwarf2_read_abbrevs (cu, &dwo_unit->dwo_file->sections.abbrev); | |
3863 | ||
3864 | /* Read in the die, but leave space to copy over the attributes | |
3865 | from the stub. This has the benefit of simplifying the rest of | |
3866 | the code - all the real work is done here. */ | |
3867 | num_extra_attrs = ((stmt_list != NULL) | |
3868 | + (low_pc != NULL) | |
3869 | + (high_pc != NULL) | |
3870 | + (ranges != NULL)); | |
3871 | info_ptr = read_full_die_1 (&reader, &comp_unit_die, info_ptr, | |
3872 | &has_children, num_extra_attrs); | |
3873 | ||
3874 | /* Copy over the attributes from the stub to the DWO die. */ | |
3875 | i = comp_unit_die->num_attrs; | |
3876 | if (stmt_list != NULL) | |
3877 | comp_unit_die->attrs[i++] = *stmt_list; | |
3878 | if (low_pc != NULL) | |
3879 | comp_unit_die->attrs[i++] = *low_pc; | |
3880 | if (high_pc != NULL) | |
3881 | comp_unit_die->attrs[i++] = *high_pc; | |
3882 | if (ranges != NULL) | |
3883 | comp_unit_die->attrs[i++] = *ranges; | |
3884 | comp_unit_die->num_attrs += num_extra_attrs; | |
3885 | ||
3886 | /* Skip dummy compilation units. */ | |
3887 | if (info_ptr >= begin_info_ptr + dwo_unit->length | |
3888 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
3889 | { | |
3890 | do_cleanups (cleanups); | |
3891 | return; | |
3892 | } | |
3893 | } | |
3894 | ||
dee91e82 DE |
3895 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); |
3896 | ||
3897 | if (free_cu_cleanup != NULL) | |
348e048f | 3898 | { |
dee91e82 DE |
3899 | if (keep) |
3900 | { | |
3901 | /* We've successfully allocated this compilation unit. Let our | |
3902 | caller clean it up when finished with it. */ | |
3903 | discard_cleanups (free_cu_cleanup); | |
3904 | ||
3905 | /* We can only discard free_cu_cleanup and all subsequent cleanups. | |
3906 | So we have to manually free the abbrev table. */ | |
3907 | dwarf2_free_abbrev_table (cu); | |
3908 | ||
3909 | /* Link this CU into read_in_chain. */ | |
3910 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3911 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3912 | } | |
3913 | else | |
3914 | do_cleanups (free_cu_cleanup); | |
348e048f | 3915 | } |
dee91e82 DE |
3916 | |
3917 | do_cleanups (cleanups); | |
3918 | } | |
3919 | ||
3920 | /* Main entry point for reading a CU. | |
3921 | Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s). | |
3019eac3 | 3922 | If the CU defers to a DWO file, read the DWO file as well. |
dee91e82 DE |
3923 | |
3924 | If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it. | |
3925 | Otherwise, a new CU is allocated with xmalloc. | |
3926 | ||
3927 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to | |
3928 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. */ | |
3929 | ||
3930 | static void | |
3931 | init_cu_and_read_dies (struct dwarf2_per_cu_data *this_cu, | |
3932 | int use_existing_cu, int keep, | |
3933 | die_reader_func_ftype *die_reader_func, | |
3934 | void *data) | |
3935 | { | |
3936 | init_and_read_dies_worker (this_cu, use_existing_cu, keep, | |
3937 | die_reader_func, data); | |
3938 | } | |
3939 | ||
3940 | /* Main entry point for reading a TU. | |
3941 | Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s). | |
3019eac3 | 3942 | If the TU defers to a DWO file, read the DWO file as well. |
dee91e82 DE |
3943 | |
3944 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to | |
3945 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. */ | |
3946 | ||
3947 | static void | |
3948 | init_tu_and_read_dies (struct dwarf2_per_cu_data *this_cu, | |
3949 | int keep, | |
3950 | die_reader_func_ftype *die_reader_func, | |
3951 | void *data) | |
3952 | { | |
3019eac3 | 3953 | gdb_assert (this_cu->is_debug_types); |
dee91e82 DE |
3954 | init_and_read_dies_worker (this_cu, 0, keep, die_reader_func, data); |
3955 | } | |
3956 | ||
3019eac3 DE |
3957 | /* Read CU/TU THIS_CU in section SECTION, |
3958 | but do not follow DW_AT_GNU_dwo_name if present. | |
3959 | DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed to | |
3960 | have already done the lookup to find the DWO file). | |
dee91e82 DE |
3961 | |
3962 | The caller is required to fill in THIS_CU->section, THIS_CU->offset, and | |
3019eac3 | 3963 | THIS_CU->is_debug_types, but nothing else. |
dee91e82 DE |
3964 | |
3965 | We fill in THIS_CU->length. | |
3966 | ||
3967 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
3968 | linker) then DIE_READER_FUNC will not get called. | |
3969 | ||
3970 | THIS_CU->cu is always freed when done. | |
3019eac3 DE |
3971 | This is done in order to not leave THIS_CU->cu in a state where we have |
3972 | to care whether it refers to the "main" CU or the DWO CU. */ | |
dee91e82 DE |
3973 | |
3974 | static void | |
3975 | init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu, | |
3976 | struct dwarf2_section_info *abbrev_section, | |
3019eac3 | 3977 | struct dwo_file *dwo_file, |
dee91e82 DE |
3978 | die_reader_func_ftype *die_reader_func, |
3979 | void *data) | |
3980 | { | |
3981 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
3019eac3 DE |
3982 | struct dwarf2_section_info *section = this_cu->info_or_types_section; |
3983 | bfd *abfd = section->asection->owner; | |
dee91e82 DE |
3984 | struct dwarf2_cu cu; |
3985 | gdb_byte *begin_info_ptr, *info_ptr; | |
3986 | struct die_reader_specs reader; | |
3987 | struct cleanup *cleanups; | |
3988 | struct die_info *comp_unit_die; | |
3989 | int has_children; | |
3990 | ||
3991 | gdb_assert (this_cu->cu == NULL); | |
3992 | ||
dee91e82 DE |
3993 | /* This is cheap if the section is already read in. */ |
3994 | dwarf2_read_section (objfile, section); | |
3995 | ||
3996 | init_one_comp_unit (&cu, this_cu); | |
3997 | ||
3998 | cleanups = make_cleanup (free_stack_comp_unit, &cu); | |
3999 | ||
4000 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; | |
4001 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr, | |
3019eac3 | 4002 | this_cu->is_debug_types); |
dee91e82 DE |
4003 | |
4004 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
4005 | ||
4006 | /* Skip dummy compilation units. */ | |
4007 | if (info_ptr >= begin_info_ptr + this_cu->length | |
4008 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
c906108c | 4009 | { |
dee91e82 | 4010 | do_cleanups (cleanups); |
21b2bd31 | 4011 | return; |
93311388 | 4012 | } |
72bf9492 | 4013 | |
dee91e82 DE |
4014 | dwarf2_read_abbrevs (&cu, abbrev_section); |
4015 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
4016 | ||
3019eac3 | 4017 | init_cu_die_reader (&reader, &cu, section, dwo_file); |
dee91e82 DE |
4018 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
4019 | ||
4020 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); | |
4021 | ||
4022 | do_cleanups (cleanups); | |
4023 | } | |
4024 | ||
3019eac3 DE |
4025 | /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and |
4026 | does not lookup the specified DWO file. | |
4027 | This cannot be used to read DWO files. | |
dee91e82 DE |
4028 | |
4029 | THIS_CU->cu is always freed when done. | |
3019eac3 DE |
4030 | This is done in order to not leave THIS_CU->cu in a state where we have |
4031 | to care whether it refers to the "main" CU or the DWO CU. | |
4032 | We can revisit this if the data shows there's a performance issue. */ | |
dee91e82 DE |
4033 | |
4034 | static void | |
4035 | init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu, | |
4036 | die_reader_func_ftype *die_reader_func, | |
4037 | void *data) | |
4038 | { | |
4039 | init_cutu_and_read_dies_no_follow (this_cu, | |
4040 | &dwarf2_per_objfile->abbrev, | |
3019eac3 | 4041 | NULL, |
dee91e82 DE |
4042 | die_reader_func, data); |
4043 | } | |
4044 | ||
4045 | /* die_reader_func for process_psymtab_comp_unit. */ | |
4046 | ||
4047 | static void | |
4048 | process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, | |
4049 | gdb_byte *info_ptr, | |
4050 | struct die_info *comp_unit_die, | |
4051 | int has_children, | |
4052 | void *data) | |
4053 | { | |
4054 | struct dwarf2_cu *cu = reader->cu; | |
4055 | struct objfile *objfile = cu->objfile; | |
4056 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; | |
4057 | bfd *abfd = objfile->obfd; | |
4058 | struct attribute *attr; | |
4059 | CORE_ADDR baseaddr; | |
4060 | CORE_ADDR best_lowpc = 0, best_highpc = 0; | |
4061 | struct partial_symtab *pst; | |
4062 | int has_pc_info; | |
4063 | const char *filename; | |
4064 | ||
4065 | if (comp_unit_die->tag == DW_TAG_partial_unit) | |
4066 | return; | |
4067 | ||
4068 | prepare_one_comp_unit (cu, comp_unit_die); | |
4069 | ||
4070 | cu->list_in_scope = &file_symbols; | |
c906108c | 4071 | |
93311388 | 4072 | /* Allocate a new partial symbol table structure. */ |
dee91e82 | 4073 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu); |
3e2a0cee TT |
4074 | if (attr == NULL || !DW_STRING (attr)) |
4075 | filename = ""; | |
4076 | else | |
4077 | filename = DW_STRING (attr); | |
93311388 | 4078 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
3e2a0cee | 4079 | filename, |
93311388 DE |
4080 | /* TEXTLOW and TEXTHIGH are set below. */ |
4081 | 0, | |
4082 | objfile->global_psymbols.next, | |
4083 | objfile->static_psymbols.next); | |
9750bca9 | 4084 | pst->psymtabs_addrmap_supported = 1; |
72bf9492 | 4085 | |
dee91e82 | 4086 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu); |
d85a05f0 DJ |
4087 | if (attr != NULL) |
4088 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 4089 | |
dee91e82 | 4090 | pst->read_symtab_private = per_cu; |
72bf9492 | 4091 | |
93311388 | 4092 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 4093 | |
0963b4bd | 4094 | /* Store the function that reads in the rest of the symbol table. */ |
93311388 | 4095 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
57349743 | 4096 | |
dee91e82 | 4097 | per_cu->v.psymtab = pst; |
c906108c | 4098 | |
dee91e82 | 4099 | dwarf2_find_base_address (comp_unit_die, cu); |
d85a05f0 | 4100 | |
93311388 DE |
4101 | /* Possibly set the default values of LOWPC and HIGHPC from |
4102 | `DW_AT_ranges'. */ | |
d85a05f0 | 4103 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
dee91e82 | 4104 | &best_highpc, cu, pst); |
d85a05f0 | 4105 | if (has_pc_info == 1 && best_lowpc < best_highpc) |
93311388 DE |
4106 | /* Store the contiguous range if it is not empty; it can be empty for |
4107 | CUs with no code. */ | |
4108 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
4109 | best_lowpc + baseaddr, |
4110 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
4111 | |
4112 | /* Check if comp unit has_children. | |
4113 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 4114 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 4115 | if (has_children) |
93311388 DE |
4116 | { |
4117 | struct partial_die_info *first_die; | |
4118 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 4119 | |
93311388 DE |
4120 | lowpc = ((CORE_ADDR) -1); |
4121 | highpc = ((CORE_ADDR) 0); | |
c906108c | 4122 | |
dee91e82 | 4123 | first_die = load_partial_dies (reader, info_ptr, 1); |
c906108c | 4124 | |
93311388 | 4125 | scan_partial_symbols (first_die, &lowpc, &highpc, |
dee91e82 | 4126 | ! has_pc_info, cu); |
57c22c6c | 4127 | |
93311388 DE |
4128 | /* If we didn't find a lowpc, set it to highpc to avoid |
4129 | complaints from `maint check'. */ | |
4130 | if (lowpc == ((CORE_ADDR) -1)) | |
4131 | lowpc = highpc; | |
10b3939b | 4132 | |
93311388 DE |
4133 | /* If the compilation unit didn't have an explicit address range, |
4134 | then use the information extracted from its child dies. */ | |
d85a05f0 | 4135 | if (! has_pc_info) |
93311388 | 4136 | { |
d85a05f0 DJ |
4137 | best_lowpc = lowpc; |
4138 | best_highpc = highpc; | |
93311388 DE |
4139 | } |
4140 | } | |
d85a05f0 DJ |
4141 | pst->textlow = best_lowpc + baseaddr; |
4142 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 4143 | |
93311388 DE |
4144 | pst->n_global_syms = objfile->global_psymbols.next - |
4145 | (objfile->global_psymbols.list + pst->globals_offset); | |
4146 | pst->n_static_syms = objfile->static_psymbols.next - | |
4147 | (objfile->static_psymbols.list + pst->statics_offset); | |
4148 | sort_pst_symbols (pst); | |
c906108c | 4149 | |
3019eac3 | 4150 | if (per_cu->is_debug_types) |
348e048f DE |
4151 | { |
4152 | /* It's not clear we want to do anything with stmt lists here. | |
4153 | Waiting to see what gcc ultimately does. */ | |
4154 | } | |
d85a05f0 | 4155 | else |
93311388 DE |
4156 | { |
4157 | /* Get the list of files included in the current compilation unit, | |
4158 | and build a psymtab for each of them. */ | |
dee91e82 | 4159 | dwarf2_build_include_psymtabs (cu, comp_unit_die, pst); |
93311388 | 4160 | } |
dee91e82 | 4161 | } |
ae038cb0 | 4162 | |
dee91e82 DE |
4163 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. |
4164 | Process compilation unit THIS_CU for a psymtab. */ | |
4165 | ||
4166 | static void | |
4167 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu) | |
4168 | { | |
4169 | /* If this compilation unit was already read in, free the | |
4170 | cached copy in order to read it in again. This is | |
4171 | necessary because we skipped some symbols when we first | |
4172 | read in the compilation unit (see load_partial_dies). | |
4173 | This problem could be avoided, but the benefit is unclear. */ | |
4174 | if (this_cu->cu != NULL) | |
4175 | free_one_cached_comp_unit (this_cu); | |
4176 | ||
3019eac3 | 4177 | gdb_assert (! this_cu->is_debug_types); |
dee91e82 DE |
4178 | init_cu_and_read_dies (this_cu, 0, 0, process_psymtab_comp_unit_reader, |
4179 | NULL); | |
4180 | ||
4181 | /* Age out any secondary CUs. */ | |
4182 | age_cached_comp_units (); | |
93311388 | 4183 | } |
ff013f42 | 4184 | |
348e048f DE |
4185 | /* Traversal function for htab_traverse_noresize. |
4186 | Process one .debug_types comp-unit. */ | |
4187 | ||
4188 | static int | |
dee91e82 | 4189 | process_psymtab_type_unit (void **slot, void *info) |
348e048f | 4190 | { |
dee91e82 DE |
4191 | struct signatured_type *sig_type = (struct signatured_type *) *slot; |
4192 | struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu; | |
348e048f | 4193 | |
a0f42c21 | 4194 | gdb_assert (info == NULL); |
348e048f | 4195 | |
dee91e82 DE |
4196 | /* If this compilation unit was already read in, free the |
4197 | cached copy in order to read it in again. This is | |
4198 | necessary because we skipped some symbols when we first | |
4199 | read in the compilation unit (see load_partial_dies). | |
4200 | This problem could be avoided, but the benefit is unclear. */ | |
4201 | if (per_cu->cu != NULL) | |
4202 | free_one_cached_comp_unit (per_cu); | |
4203 | ||
3019eac3 | 4204 | gdb_assert (per_cu->is_debug_types); |
dee91e82 DE |
4205 | init_tu_and_read_dies (per_cu, 0, process_psymtab_comp_unit_reader, NULL); |
4206 | ||
4207 | /* Age out any secondary CUs. */ | |
4208 | age_cached_comp_units (); | |
348e048f DE |
4209 | |
4210 | return 1; | |
4211 | } | |
4212 | ||
4213 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
4214 | Build partial symbol tables for the .debug_types comp-units. */ | |
4215 | ||
4216 | static void | |
4217 | build_type_psymtabs (struct objfile *objfile) | |
4218 | { | |
0e50663e | 4219 | if (! create_all_type_units (objfile)) |
348e048f DE |
4220 | return; |
4221 | ||
4222 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
dee91e82 | 4223 | process_psymtab_type_unit, NULL); |
348e048f DE |
4224 | } |
4225 | ||
60606b2c TT |
4226 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
4227 | ||
4228 | static void | |
4229 | psymtabs_addrmap_cleanup (void *o) | |
4230 | { | |
4231 | struct objfile *objfile = o; | |
ec61707d | 4232 | |
60606b2c TT |
4233 | objfile->psymtabs_addrmap = NULL; |
4234 | } | |
4235 | ||
93311388 DE |
4236 | /* Build the partial symbol table by doing a quick pass through the |
4237 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 4238 | |
93311388 | 4239 | static void |
c67a9c90 | 4240 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 4241 | { |
60606b2c TT |
4242 | struct cleanup *back_to, *addrmap_cleanup; |
4243 | struct obstack temp_obstack; | |
21b2bd31 | 4244 | int i; |
93311388 | 4245 | |
98bfdba5 PA |
4246 | dwarf2_per_objfile->reading_partial_symbols = 1; |
4247 | ||
be391dca | 4248 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
91c24f0a | 4249 | |
93311388 DE |
4250 | /* Any cached compilation units will be linked by the per-objfile |
4251 | read_in_chain. Make sure to free them when we're done. */ | |
4252 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 4253 | |
348e048f DE |
4254 | build_type_psymtabs (objfile); |
4255 | ||
93311388 | 4256 | create_all_comp_units (objfile); |
c906108c | 4257 | |
60606b2c TT |
4258 | /* Create a temporary address map on a temporary obstack. We later |
4259 | copy this to the final obstack. */ | |
4260 | obstack_init (&temp_obstack); | |
4261 | make_cleanup_obstack_free (&temp_obstack); | |
4262 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
4263 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 4264 | |
21b2bd31 | 4265 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
93311388 | 4266 | { |
21b2bd31 | 4267 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
aaa75496 | 4268 | |
dee91e82 | 4269 | process_psymtab_comp_unit (per_cu); |
c906108c | 4270 | } |
ff013f42 JK |
4271 | |
4272 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
4273 | &objfile->objfile_obstack); | |
60606b2c | 4274 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 4275 | |
ae038cb0 DJ |
4276 | do_cleanups (back_to); |
4277 | } | |
4278 | ||
3019eac3 | 4279 | /* die_reader_func for load_partial_comp_unit. */ |
ae038cb0 DJ |
4280 | |
4281 | static void | |
dee91e82 DE |
4282 | load_partial_comp_unit_reader (const struct die_reader_specs *reader, |
4283 | gdb_byte *info_ptr, | |
4284 | struct die_info *comp_unit_die, | |
4285 | int has_children, | |
4286 | void *data) | |
ae038cb0 | 4287 | { |
dee91e82 | 4288 | struct dwarf2_cu *cu = reader->cu; |
ae038cb0 | 4289 | |
9816fde3 | 4290 | prepare_one_comp_unit (cu, comp_unit_die); |
ae038cb0 | 4291 | |
ae038cb0 DJ |
4292 | /* Check if comp unit has_children. |
4293 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 4294 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 4295 | if (has_children) |
dee91e82 DE |
4296 | load_partial_dies (reader, info_ptr, 0); |
4297 | } | |
98bfdba5 | 4298 | |
dee91e82 DE |
4299 | /* Load the partial DIEs for a secondary CU into memory. |
4300 | This is also used when rereading a primary CU with load_all_dies. */ | |
c5b7e1cb | 4301 | |
dee91e82 DE |
4302 | static void |
4303 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) | |
4304 | { | |
3019eac3 | 4305 | if (this_cu->is_debug_types) |
dee91e82 DE |
4306 | init_tu_and_read_dies (this_cu, 1, load_partial_comp_unit_reader, NULL); |
4307 | else | |
4308 | init_cu_and_read_dies (this_cu, 0, 1, load_partial_comp_unit_reader, NULL); | |
ae038cb0 DJ |
4309 | } |
4310 | ||
9cdd5dbd DE |
4311 | /* Create a list of all compilation units in OBJFILE. |
4312 | This is only done for -readnow and building partial symtabs. */ | |
ae038cb0 DJ |
4313 | |
4314 | static void | |
4315 | create_all_comp_units (struct objfile *objfile) | |
4316 | { | |
4317 | int n_allocated; | |
4318 | int n_comp_units; | |
4319 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
4320 | gdb_byte *info_ptr; |
4321 | ||
4322 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
4323 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
4324 | |
4325 | n_comp_units = 0; | |
4326 | n_allocated = 10; | |
4327 | all_comp_units = xmalloc (n_allocated | |
4328 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 4329 | |
3e43a32a MS |
4330 | while (info_ptr < dwarf2_per_objfile->info.buffer |
4331 | + dwarf2_per_objfile->info.size) | |
ae038cb0 | 4332 | { |
c764a876 | 4333 | unsigned int length, initial_length_size; |
ae038cb0 | 4334 | struct dwarf2_per_cu_data *this_cu; |
b64f50a1 | 4335 | sect_offset offset; |
ae038cb0 | 4336 | |
b64f50a1 | 4337 | offset.sect_off = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
4338 | |
4339 | /* Read just enough information to find out where the next | |
4340 | compilation unit is. */ | |
c764a876 DE |
4341 | length = read_initial_length (objfile->obfd, info_ptr, |
4342 | &initial_length_size); | |
ae038cb0 DJ |
4343 | |
4344 | /* Save the compilation unit for later lookup. */ | |
4345 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
4346 | sizeof (struct dwarf2_per_cu_data)); | |
4347 | memset (this_cu, 0, sizeof (*this_cu)); | |
4348 | this_cu->offset = offset; | |
c764a876 | 4349 | this_cu->length = length + initial_length_size; |
9291a0cd | 4350 | this_cu->objfile = objfile; |
3019eac3 | 4351 | this_cu->info_or_types_section = &dwarf2_per_objfile->info; |
ae038cb0 DJ |
4352 | |
4353 | if (n_comp_units == n_allocated) | |
4354 | { | |
4355 | n_allocated *= 2; | |
4356 | all_comp_units = xrealloc (all_comp_units, | |
4357 | n_allocated | |
4358 | * sizeof (struct dwarf2_per_cu_data *)); | |
4359 | } | |
4360 | all_comp_units[n_comp_units++] = this_cu; | |
4361 | ||
4362 | info_ptr = info_ptr + this_cu->length; | |
4363 | } | |
4364 | ||
4365 | dwarf2_per_objfile->all_comp_units | |
4366 | = obstack_alloc (&objfile->objfile_obstack, | |
4367 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
4368 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
4369 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
4370 | xfree (all_comp_units); | |
4371 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
4372 | } |
4373 | ||
5734ee8b DJ |
4374 | /* Process all loaded DIEs for compilation unit CU, starting at |
4375 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
4376 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
4377 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
4378 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
4379 | and record the covered ranges in the addrmap. */ | |
c906108c | 4380 | |
72bf9492 DJ |
4381 | static void |
4382 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 4383 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 4384 | { |
72bf9492 | 4385 | struct partial_die_info *pdi; |
c906108c | 4386 | |
91c24f0a DC |
4387 | /* Now, march along the PDI's, descending into ones which have |
4388 | interesting children but skipping the children of the other ones, | |
4389 | until we reach the end of the compilation unit. */ | |
c906108c | 4390 | |
72bf9492 | 4391 | pdi = first_die; |
91c24f0a | 4392 | |
72bf9492 DJ |
4393 | while (pdi != NULL) |
4394 | { | |
4395 | fixup_partial_die (pdi, cu); | |
c906108c | 4396 | |
f55ee35c | 4397 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
4398 | children, so we need to look at them. Ditto for anonymous |
4399 | enums. */ | |
933c6fe4 | 4400 | |
72bf9492 | 4401 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 4402 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 4403 | { |
72bf9492 | 4404 | switch (pdi->tag) |
c906108c SS |
4405 | { |
4406 | case DW_TAG_subprogram: | |
5734ee8b | 4407 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 4408 | break; |
72929c62 | 4409 | case DW_TAG_constant: |
c906108c SS |
4410 | case DW_TAG_variable: |
4411 | case DW_TAG_typedef: | |
91c24f0a | 4412 | case DW_TAG_union_type: |
72bf9492 | 4413 | if (!pdi->is_declaration) |
63d06c5c | 4414 | { |
72bf9492 | 4415 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
4416 | } |
4417 | break; | |
c906108c | 4418 | case DW_TAG_class_type: |
680b30c7 | 4419 | case DW_TAG_interface_type: |
c906108c | 4420 | case DW_TAG_structure_type: |
72bf9492 | 4421 | if (!pdi->is_declaration) |
c906108c | 4422 | { |
72bf9492 | 4423 | add_partial_symbol (pdi, cu); |
c906108c SS |
4424 | } |
4425 | break; | |
91c24f0a | 4426 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
4427 | if (!pdi->is_declaration) |
4428 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
4429 | break; |
4430 | case DW_TAG_base_type: | |
a02abb62 | 4431 | case DW_TAG_subrange_type: |
c906108c | 4432 | /* File scope base type definitions are added to the partial |
c5aa993b | 4433 | symbol table. */ |
72bf9492 | 4434 | add_partial_symbol (pdi, cu); |
c906108c | 4435 | break; |
d9fa45fe | 4436 | case DW_TAG_namespace: |
5734ee8b | 4437 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 4438 | break; |
5d7cb8df JK |
4439 | case DW_TAG_module: |
4440 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
4441 | break; | |
c906108c SS |
4442 | default: |
4443 | break; | |
4444 | } | |
4445 | } | |
4446 | ||
72bf9492 DJ |
4447 | /* If the die has a sibling, skip to the sibling. */ |
4448 | ||
4449 | pdi = pdi->die_sibling; | |
4450 | } | |
4451 | } | |
4452 | ||
4453 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 4454 | |
72bf9492 | 4455 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
4456 | name is concatenated with "::" and the partial DIE's name. For |
4457 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
4458 | Enumerators are an exception; they use the scope of their parent |
4459 | enumeration type, i.e. the name of the enumeration type is not | |
4460 | prepended to the enumerator. | |
91c24f0a | 4461 | |
72bf9492 DJ |
4462 | There are two complexities. One is DW_AT_specification; in this |
4463 | case "parent" means the parent of the target of the specification, | |
4464 | instead of the direct parent of the DIE. The other is compilers | |
4465 | which do not emit DW_TAG_namespace; in this case we try to guess | |
4466 | the fully qualified name of structure types from their members' | |
4467 | linkage names. This must be done using the DIE's children rather | |
4468 | than the children of any DW_AT_specification target. We only need | |
4469 | to do this for structures at the top level, i.e. if the target of | |
4470 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
4471 | have a parent. */ | |
4472 | ||
4473 | /* Compute the scope prefix associated with PDI's parent, in | |
4474 | compilation unit CU. The result will be allocated on CU's | |
4475 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
4476 | field. NULL is returned if no prefix is necessary. */ | |
4477 | static char * | |
4478 | partial_die_parent_scope (struct partial_die_info *pdi, | |
4479 | struct dwarf2_cu *cu) | |
4480 | { | |
4481 | char *grandparent_scope; | |
4482 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 4483 | |
72bf9492 DJ |
4484 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
4485 | then this means the parent of the specification DIE. */ | |
4486 | ||
4487 | real_pdi = pdi; | |
72bf9492 | 4488 | while (real_pdi->has_specification) |
10b3939b | 4489 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
4490 | |
4491 | parent = real_pdi->die_parent; | |
4492 | if (parent == NULL) | |
4493 | return NULL; | |
4494 | ||
4495 | if (parent->scope_set) | |
4496 | return parent->scope; | |
4497 | ||
4498 | fixup_partial_die (parent, cu); | |
4499 | ||
10b3939b | 4500 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 4501 | |
acebe513 UW |
4502 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
4503 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
4504 | Work around this problem here. */ | |
4505 | if (cu->language == language_cplus | |
6e70227d | 4506 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
4507 | && strcmp (parent->name, "::") == 0 |
4508 | && grandparent_scope == NULL) | |
4509 | { | |
4510 | parent->scope = NULL; | |
4511 | parent->scope_set = 1; | |
4512 | return NULL; | |
4513 | } | |
4514 | ||
9c6c53f7 SA |
4515 | if (pdi->tag == DW_TAG_enumerator) |
4516 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
4517 | parent->scope = grandparent_scope; | |
4518 | else if (parent->tag == DW_TAG_namespace | |
f55ee35c | 4519 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
4520 | || parent->tag == DW_TAG_structure_type |
4521 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 4522 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
4523 | || parent->tag == DW_TAG_union_type |
4524 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
4525 | { |
4526 | if (grandparent_scope == NULL) | |
4527 | parent->scope = parent->name; | |
4528 | else | |
3e43a32a MS |
4529 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
4530 | grandparent_scope, | |
f55ee35c | 4531 | parent->name, 0, cu); |
72bf9492 | 4532 | } |
72bf9492 DJ |
4533 | else |
4534 | { | |
4535 | /* FIXME drow/2004-04-01: What should we be doing with | |
4536 | function-local names? For partial symbols, we should probably be | |
4537 | ignoring them. */ | |
4538 | complaint (&symfile_complaints, | |
e2e0b3e5 | 4539 | _("unhandled containing DIE tag %d for DIE at %d"), |
b64f50a1 | 4540 | parent->tag, pdi->offset.sect_off); |
72bf9492 | 4541 | parent->scope = grandparent_scope; |
c906108c SS |
4542 | } |
4543 | ||
72bf9492 DJ |
4544 | parent->scope_set = 1; |
4545 | return parent->scope; | |
4546 | } | |
4547 | ||
4548 | /* Return the fully scoped name associated with PDI, from compilation unit | |
4549 | CU. The result will be allocated with malloc. */ | |
4568ecf9 | 4550 | |
72bf9492 DJ |
4551 | static char * |
4552 | partial_die_full_name (struct partial_die_info *pdi, | |
4553 | struct dwarf2_cu *cu) | |
4554 | { | |
4555 | char *parent_scope; | |
4556 | ||
98bfdba5 PA |
4557 | /* If this is a template instantiation, we can not work out the |
4558 | template arguments from partial DIEs. So, unfortunately, we have | |
4559 | to go through the full DIEs. At least any work we do building | |
4560 | types here will be reused if full symbols are loaded later. */ | |
4561 | if (pdi->has_template_arguments) | |
4562 | { | |
4563 | fixup_partial_die (pdi, cu); | |
4564 | ||
4565 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
4566 | { | |
4567 | struct die_info *die; | |
4568 | struct attribute attr; | |
4569 | struct dwarf2_cu *ref_cu = cu; | |
4570 | ||
b64f50a1 | 4571 | /* DW_FORM_ref_addr is using section offset. */ |
98bfdba5 PA |
4572 | attr.name = 0; |
4573 | attr.form = DW_FORM_ref_addr; | |
4568ecf9 | 4574 | attr.u.unsnd = pdi->offset.sect_off; |
98bfdba5 PA |
4575 | die = follow_die_ref (NULL, &attr, &ref_cu); |
4576 | ||
4577 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
4578 | } | |
4579 | } | |
4580 | ||
72bf9492 DJ |
4581 | parent_scope = partial_die_parent_scope (pdi, cu); |
4582 | if (parent_scope == NULL) | |
4583 | return NULL; | |
4584 | else | |
f55ee35c | 4585 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
4586 | } |
4587 | ||
4588 | static void | |
72bf9492 | 4589 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 4590 | { |
e7c27a73 | 4591 | struct objfile *objfile = cu->objfile; |
c906108c | 4592 | CORE_ADDR addr = 0; |
decbce07 | 4593 | char *actual_name = NULL; |
e142c38c | 4594 | CORE_ADDR baseaddr; |
72bf9492 | 4595 | int built_actual_name = 0; |
e142c38c DJ |
4596 | |
4597 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 4598 | |
94af9270 KS |
4599 | actual_name = partial_die_full_name (pdi, cu); |
4600 | if (actual_name) | |
4601 | built_actual_name = 1; | |
63d06c5c | 4602 | |
72bf9492 DJ |
4603 | if (actual_name == NULL) |
4604 | actual_name = pdi->name; | |
4605 | ||
c906108c SS |
4606 | switch (pdi->tag) |
4607 | { | |
4608 | case DW_TAG_subprogram: | |
2cfa0c8d | 4609 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 4610 | { |
2cfa0c8d JB |
4611 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
4612 | of the global scope. But in Ada, we want to be able to access | |
4613 | nested procedures globally. So all Ada subprograms are stored | |
4614 | in the global scope. */ | |
f47fb265 | 4615 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 4616 | mst_text, objfile); */ |
f47fb265 MS |
4617 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4618 | built_actual_name, | |
4619 | VAR_DOMAIN, LOC_BLOCK, | |
4620 | &objfile->global_psymbols, | |
4621 | 0, pdi->lowpc + baseaddr, | |
4622 | cu->language, objfile); | |
c906108c SS |
4623 | } |
4624 | else | |
4625 | { | |
f47fb265 | 4626 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 4627 | mst_file_text, objfile); */ |
f47fb265 MS |
4628 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4629 | built_actual_name, | |
4630 | VAR_DOMAIN, LOC_BLOCK, | |
4631 | &objfile->static_psymbols, | |
4632 | 0, pdi->lowpc + baseaddr, | |
4633 | cu->language, objfile); | |
c906108c SS |
4634 | } |
4635 | break; | |
72929c62 JB |
4636 | case DW_TAG_constant: |
4637 | { | |
4638 | struct psymbol_allocation_list *list; | |
4639 | ||
4640 | if (pdi->is_external) | |
4641 | list = &objfile->global_psymbols; | |
4642 | else | |
4643 | list = &objfile->static_psymbols; | |
f47fb265 MS |
4644 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4645 | built_actual_name, VAR_DOMAIN, LOC_STATIC, | |
4646 | list, 0, 0, cu->language, objfile); | |
72929c62 JB |
4647 | } |
4648 | break; | |
c906108c | 4649 | case DW_TAG_variable: |
caac4577 JG |
4650 | if (pdi->locdesc) |
4651 | addr = decode_locdesc (pdi->locdesc, cu); | |
4652 | ||
4653 | if (pdi->locdesc | |
4654 | && addr == 0 | |
4655 | && !dwarf2_per_objfile->has_section_at_zero) | |
4656 | { | |
4657 | /* A global or static variable may also have been stripped | |
4658 | out by the linker if unused, in which case its address | |
4659 | will be nullified; do not add such variables into partial | |
4660 | symbol table then. */ | |
4661 | } | |
4662 | else if (pdi->is_external) | |
c906108c SS |
4663 | { |
4664 | /* Global Variable. | |
4665 | Don't enter into the minimal symbol tables as there is | |
4666 | a minimal symbol table entry from the ELF symbols already. | |
4667 | Enter into partial symbol table if it has a location | |
4668 | descriptor or a type. | |
4669 | If the location descriptor is missing, new_symbol will create | |
4670 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
4671 | be determined from the minimal symbol table whenever the variable | |
4672 | is referenced. | |
4673 | The address for the partial symbol table entry is not | |
4674 | used by GDB, but it comes in handy for debugging partial symbol | |
4675 | table building. */ | |
4676 | ||
c906108c | 4677 | if (pdi->locdesc || pdi->has_type) |
f47fb265 MS |
4678 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4679 | built_actual_name, | |
4680 | VAR_DOMAIN, LOC_STATIC, | |
4681 | &objfile->global_psymbols, | |
4682 | 0, addr + baseaddr, | |
4683 | cu->language, objfile); | |
c906108c SS |
4684 | } |
4685 | else | |
4686 | { | |
0963b4bd | 4687 | /* Static Variable. Skip symbols without location descriptors. */ |
c906108c | 4688 | if (pdi->locdesc == NULL) |
decbce07 MS |
4689 | { |
4690 | if (built_actual_name) | |
4691 | xfree (actual_name); | |
4692 | return; | |
4693 | } | |
f47fb265 | 4694 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 4695 | mst_file_data, objfile); */ |
f47fb265 MS |
4696 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4697 | built_actual_name, | |
4698 | VAR_DOMAIN, LOC_STATIC, | |
4699 | &objfile->static_psymbols, | |
4700 | 0, addr + baseaddr, | |
4701 | cu->language, objfile); | |
c906108c SS |
4702 | } |
4703 | break; | |
4704 | case DW_TAG_typedef: | |
4705 | case DW_TAG_base_type: | |
a02abb62 | 4706 | case DW_TAG_subrange_type: |
38d518c9 | 4707 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4708 | built_actual_name, |
176620f1 | 4709 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 4710 | &objfile->static_psymbols, |
e142c38c | 4711 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4712 | break; |
72bf9492 DJ |
4713 | case DW_TAG_namespace: |
4714 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 4715 | built_actual_name, |
72bf9492 DJ |
4716 | VAR_DOMAIN, LOC_TYPEDEF, |
4717 | &objfile->global_psymbols, | |
4718 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
4719 | break; | |
c906108c | 4720 | case DW_TAG_class_type: |
680b30c7 | 4721 | case DW_TAG_interface_type: |
c906108c SS |
4722 | case DW_TAG_structure_type: |
4723 | case DW_TAG_union_type: | |
4724 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
4725 | /* Skip external references. The DWARF standard says in the section |
4726 | about "Structure, Union, and Class Type Entries": "An incomplete | |
4727 | structure, union or class type is represented by a structure, | |
4728 | union or class entry that does not have a byte size attribute | |
4729 | and that has a DW_AT_declaration attribute." */ | |
4730 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
4731 | { |
4732 | if (built_actual_name) | |
4733 | xfree (actual_name); | |
4734 | return; | |
4735 | } | |
fa4028e9 | 4736 | |
63d06c5c DC |
4737 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
4738 | static vs. global. */ | |
38d518c9 | 4739 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4740 | built_actual_name, |
176620f1 | 4741 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
4742 | (cu->language == language_cplus |
4743 | || cu->language == language_java) | |
63d06c5c DC |
4744 | ? &objfile->global_psymbols |
4745 | : &objfile->static_psymbols, | |
e142c38c | 4746 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4747 | |
c906108c SS |
4748 | break; |
4749 | case DW_TAG_enumerator: | |
38d518c9 | 4750 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4751 | built_actual_name, |
176620f1 | 4752 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
4753 | (cu->language == language_cplus |
4754 | || cu->language == language_java) | |
f6fe98ef DJ |
4755 | ? &objfile->global_psymbols |
4756 | : &objfile->static_psymbols, | |
e142c38c | 4757 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
4758 | break; |
4759 | default: | |
4760 | break; | |
4761 | } | |
5c4e30ca | 4762 | |
72bf9492 DJ |
4763 | if (built_actual_name) |
4764 | xfree (actual_name); | |
c906108c SS |
4765 | } |
4766 | ||
5c4e30ca DC |
4767 | /* Read a partial die corresponding to a namespace; also, add a symbol |
4768 | corresponding to that namespace to the symbol table. NAMESPACE is | |
4769 | the name of the enclosing namespace. */ | |
91c24f0a | 4770 | |
72bf9492 DJ |
4771 | static void |
4772 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 4773 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 4774 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 4775 | { |
72bf9492 | 4776 | /* Add a symbol for the namespace. */ |
e7c27a73 | 4777 | |
72bf9492 | 4778 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
4779 | |
4780 | /* Now scan partial symbols in that namespace. */ | |
4781 | ||
91c24f0a | 4782 | if (pdi->has_children) |
5734ee8b | 4783 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
4784 | } |
4785 | ||
5d7cb8df JK |
4786 | /* Read a partial die corresponding to a Fortran module. */ |
4787 | ||
4788 | static void | |
4789 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
4790 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
4791 | { | |
f55ee35c | 4792 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
4793 | |
4794 | if (pdi->has_children) | |
4795 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
4796 | } | |
4797 | ||
bc30ff58 JB |
4798 | /* Read a partial die corresponding to a subprogram and create a partial |
4799 | symbol for that subprogram. When the CU language allows it, this | |
4800 | routine also defines a partial symbol for each nested subprogram | |
4801 | that this subprogram contains. | |
6e70227d | 4802 | |
bc30ff58 JB |
4803 | DIE my also be a lexical block, in which case we simply search |
4804 | recursively for suprograms defined inside that lexical block. | |
4805 | Again, this is only performed when the CU language allows this | |
4806 | type of definitions. */ | |
4807 | ||
4808 | static void | |
4809 | add_partial_subprogram (struct partial_die_info *pdi, | |
4810 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 4811 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
4812 | { |
4813 | if (pdi->tag == DW_TAG_subprogram) | |
4814 | { | |
4815 | if (pdi->has_pc_info) | |
4816 | { | |
4817 | if (pdi->lowpc < *lowpc) | |
4818 | *lowpc = pdi->lowpc; | |
4819 | if (pdi->highpc > *highpc) | |
4820 | *highpc = pdi->highpc; | |
5734ee8b DJ |
4821 | if (need_pc) |
4822 | { | |
4823 | CORE_ADDR baseaddr; | |
4824 | struct objfile *objfile = cu->objfile; | |
4825 | ||
4826 | baseaddr = ANOFFSET (objfile->section_offsets, | |
4827 | SECT_OFF_TEXT (objfile)); | |
4828 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
4829 | pdi->lowpc + baseaddr, |
4830 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 4831 | cu->per_cu->v.psymtab); |
5734ee8b | 4832 | } |
481860b3 GB |
4833 | } |
4834 | ||
4835 | if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined)) | |
4836 | { | |
bc30ff58 | 4837 | if (!pdi->is_declaration) |
e8d05480 JB |
4838 | /* Ignore subprogram DIEs that do not have a name, they are |
4839 | illegal. Do not emit a complaint at this point, we will | |
4840 | do so when we convert this psymtab into a symtab. */ | |
4841 | if (pdi->name) | |
4842 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
4843 | } |
4844 | } | |
6e70227d | 4845 | |
bc30ff58 JB |
4846 | if (! pdi->has_children) |
4847 | return; | |
4848 | ||
4849 | if (cu->language == language_ada) | |
4850 | { | |
4851 | pdi = pdi->die_child; | |
4852 | while (pdi != NULL) | |
4853 | { | |
4854 | fixup_partial_die (pdi, cu); | |
4855 | if (pdi->tag == DW_TAG_subprogram | |
4856 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 4857 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
4858 | pdi = pdi->die_sibling; |
4859 | } | |
4860 | } | |
4861 | } | |
4862 | ||
91c24f0a DC |
4863 | /* Read a partial die corresponding to an enumeration type. */ |
4864 | ||
72bf9492 DJ |
4865 | static void |
4866 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
4867 | struct dwarf2_cu *cu) | |
91c24f0a | 4868 | { |
72bf9492 | 4869 | struct partial_die_info *pdi; |
91c24f0a DC |
4870 | |
4871 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
4872 | add_partial_symbol (enum_pdi, cu); |
4873 | ||
4874 | pdi = enum_pdi->die_child; | |
4875 | while (pdi) | |
91c24f0a | 4876 | { |
72bf9492 | 4877 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 4878 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 4879 | else |
72bf9492 DJ |
4880 | add_partial_symbol (pdi, cu); |
4881 | pdi = pdi->die_sibling; | |
91c24f0a | 4882 | } |
91c24f0a DC |
4883 | } |
4884 | ||
6caca83c CC |
4885 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
4886 | ||
4887 | static unsigned int | |
4888 | peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr) | |
4889 | { | |
4890 | unsigned int bytes_read; | |
4891 | ||
4892 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4893 | } | |
4894 | ||
4bb7a0a7 DJ |
4895 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
4896 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
4897 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
4898 | the initial number. */ | |
4899 | ||
4900 | static struct abbrev_info * | |
fe1b8b76 | 4901 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 4902 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4903 | { |
4904 | bfd *abfd = cu->objfile->obfd; | |
4905 | unsigned int abbrev_number; | |
4906 | struct abbrev_info *abbrev; | |
4907 | ||
4908 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
4909 | ||
4910 | if (abbrev_number == 0) | |
4911 | return NULL; | |
4912 | ||
4913 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
4914 | if (!abbrev) | |
4915 | { | |
3e43a32a MS |
4916 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
4917 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
4918 | } |
4919 | ||
4920 | return abbrev; | |
4921 | } | |
4922 | ||
93311388 DE |
4923 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4924 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
4925 | DIE. Any children of the skipped DIEs will also be skipped. */ |
4926 | ||
fe1b8b76 | 4927 | static gdb_byte * |
dee91e82 | 4928 | skip_children (const struct die_reader_specs *reader, gdb_byte *info_ptr) |
4bb7a0a7 | 4929 | { |
dee91e82 | 4930 | struct dwarf2_cu *cu = reader->cu; |
4bb7a0a7 DJ |
4931 | struct abbrev_info *abbrev; |
4932 | unsigned int bytes_read; | |
4933 | ||
4934 | while (1) | |
4935 | { | |
4936 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4937 | if (abbrev == NULL) | |
4938 | return info_ptr + bytes_read; | |
4939 | else | |
dee91e82 | 4940 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
4bb7a0a7 DJ |
4941 | } |
4942 | } | |
4943 | ||
93311388 DE |
4944 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4945 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4946 | abbrev corresponding to that skipped uleb128 should be passed in |
4947 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4948 | children. */ | |
4949 | ||
fe1b8b76 | 4950 | static gdb_byte * |
dee91e82 DE |
4951 | skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr, |
4952 | struct abbrev_info *abbrev) | |
4bb7a0a7 DJ |
4953 | { |
4954 | unsigned int bytes_read; | |
4955 | struct attribute attr; | |
dee91e82 DE |
4956 | bfd *abfd = reader->abfd; |
4957 | struct dwarf2_cu *cu = reader->cu; | |
4958 | gdb_byte *buffer = reader->buffer; | |
4bb7a0a7 DJ |
4959 | unsigned int form, i; |
4960 | ||
4961 | for (i = 0; i < abbrev->num_attrs; i++) | |
4962 | { | |
4963 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4964 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4965 | { | |
dee91e82 | 4966 | read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
4bb7a0a7 | 4967 | if (attr.form == DW_FORM_ref_addr) |
3e43a32a MS |
4968 | complaint (&symfile_complaints, |
4969 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 4970 | else |
b64f50a1 | 4971 | return buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
4bb7a0a7 DJ |
4972 | } |
4973 | ||
4974 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4975 | form = abbrev->attrs[i].form; | |
4976 | skip_attribute: | |
4977 | switch (form) | |
4978 | { | |
4bb7a0a7 | 4979 | case DW_FORM_ref_addr: |
ae411497 TT |
4980 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4981 | and later it is offset sized. */ | |
4982 | if (cu->header.version == 2) | |
4983 | info_ptr += cu->header.addr_size; | |
4984 | else | |
4985 | info_ptr += cu->header.offset_size; | |
4986 | break; | |
4987 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4988 | info_ptr += cu->header.addr_size; |
4989 | break; | |
4990 | case DW_FORM_data1: | |
4991 | case DW_FORM_ref1: | |
4992 | case DW_FORM_flag: | |
4993 | info_ptr += 1; | |
4994 | break; | |
2dc7f7b3 TT |
4995 | case DW_FORM_flag_present: |
4996 | break; | |
4bb7a0a7 DJ |
4997 | case DW_FORM_data2: |
4998 | case DW_FORM_ref2: | |
4999 | info_ptr += 2; | |
5000 | break; | |
5001 | case DW_FORM_data4: | |
5002 | case DW_FORM_ref4: | |
5003 | info_ptr += 4; | |
5004 | break; | |
5005 | case DW_FORM_data8: | |
5006 | case DW_FORM_ref8: | |
55f1336d | 5007 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
5008 | info_ptr += 8; |
5009 | break; | |
5010 | case DW_FORM_string: | |
9b1c24c8 | 5011 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
5012 | info_ptr += bytes_read; |
5013 | break; | |
2dc7f7b3 | 5014 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
5015 | case DW_FORM_strp: |
5016 | info_ptr += cu->header.offset_size; | |
5017 | break; | |
2dc7f7b3 | 5018 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
5019 | case DW_FORM_block: |
5020 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5021 | info_ptr += bytes_read; | |
5022 | break; | |
5023 | case DW_FORM_block1: | |
5024 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
5025 | break; | |
5026 | case DW_FORM_block2: | |
5027 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
5028 | break; | |
5029 | case DW_FORM_block4: | |
5030 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
5031 | break; | |
5032 | case DW_FORM_sdata: | |
5033 | case DW_FORM_udata: | |
5034 | case DW_FORM_ref_udata: | |
3019eac3 DE |
5035 | case DW_FORM_GNU_addr_index: |
5036 | case DW_FORM_GNU_str_index: | |
4bb7a0a7 DJ |
5037 | info_ptr = skip_leb128 (abfd, info_ptr); |
5038 | break; | |
5039 | case DW_FORM_indirect: | |
5040 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5041 | info_ptr += bytes_read; | |
5042 | /* We need to continue parsing from here, so just go back to | |
5043 | the top. */ | |
5044 | goto skip_attribute; | |
5045 | ||
5046 | default: | |
3e43a32a MS |
5047 | error (_("Dwarf Error: Cannot handle %s " |
5048 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
5049 | dwarf_form_name (form), |
5050 | bfd_get_filename (abfd)); | |
5051 | } | |
5052 | } | |
5053 | ||
5054 | if (abbrev->has_children) | |
dee91e82 | 5055 | return skip_children (reader, info_ptr); |
4bb7a0a7 DJ |
5056 | else |
5057 | return info_ptr; | |
5058 | } | |
5059 | ||
93311388 | 5060 | /* Locate ORIG_PDI's sibling. |
dee91e82 | 5061 | INFO_PTR should point to the start of the next DIE after ORIG_PDI. */ |
91c24f0a | 5062 | |
fe1b8b76 | 5063 | static gdb_byte * |
dee91e82 DE |
5064 | locate_pdi_sibling (const struct die_reader_specs *reader, |
5065 | struct partial_die_info *orig_pdi, | |
5066 | gdb_byte *info_ptr) | |
91c24f0a DC |
5067 | { |
5068 | /* Do we know the sibling already? */ | |
72bf9492 | 5069 | |
91c24f0a DC |
5070 | if (orig_pdi->sibling) |
5071 | return orig_pdi->sibling; | |
5072 | ||
5073 | /* Are there any children to deal with? */ | |
5074 | ||
5075 | if (!orig_pdi->has_children) | |
5076 | return info_ptr; | |
5077 | ||
4bb7a0a7 | 5078 | /* Skip the children the long way. */ |
91c24f0a | 5079 | |
dee91e82 | 5080 | return skip_children (reader, info_ptr); |
91c24f0a DC |
5081 | } |
5082 | ||
c906108c SS |
5083 | /* Expand this partial symbol table into a full symbol table. */ |
5084 | ||
5085 | static void | |
fba45db2 | 5086 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 5087 | { |
c906108c SS |
5088 | if (pst != NULL) |
5089 | { | |
5090 | if (pst->readin) | |
5091 | { | |
3e43a32a MS |
5092 | warning (_("bug: psymtab for %s is already read in."), |
5093 | pst->filename); | |
c906108c SS |
5094 | } |
5095 | else | |
5096 | { | |
5097 | if (info_verbose) | |
5098 | { | |
3e43a32a MS |
5099 | printf_filtered (_("Reading in symbols for %s..."), |
5100 | pst->filename); | |
c906108c SS |
5101 | gdb_flush (gdb_stdout); |
5102 | } | |
5103 | ||
10b3939b DJ |
5104 | /* Restore our global data. */ |
5105 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
5106 | dwarf2_objfile_data_key); | |
5107 | ||
b2ab525c KB |
5108 | /* If this psymtab is constructed from a debug-only objfile, the |
5109 | has_section_at_zero flag will not necessarily be correct. We | |
5110 | can get the correct value for this flag by looking at the data | |
5111 | associated with the (presumably stripped) associated objfile. */ | |
5112 | if (pst->objfile->separate_debug_objfile_backlink) | |
5113 | { | |
5114 | struct dwarf2_per_objfile *dpo_backlink | |
5115 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
5116 | dwarf2_objfile_data_key); | |
9a619af0 | 5117 | |
b2ab525c KB |
5118 | dwarf2_per_objfile->has_section_at_zero |
5119 | = dpo_backlink->has_section_at_zero; | |
5120 | } | |
5121 | ||
98bfdba5 PA |
5122 | dwarf2_per_objfile->reading_partial_symbols = 0; |
5123 | ||
c906108c SS |
5124 | psymtab_to_symtab_1 (pst); |
5125 | ||
5126 | /* Finish up the debug error message. */ | |
5127 | if (info_verbose) | |
a3f17187 | 5128 | printf_filtered (_("done.\n")); |
c906108c SS |
5129 | } |
5130 | } | |
5131 | } | |
9cdd5dbd DE |
5132 | \f |
5133 | /* Reading in full CUs. */ | |
c906108c | 5134 | |
10b3939b DJ |
5135 | /* Add PER_CU to the queue. */ |
5136 | ||
5137 | static void | |
a0f42c21 | 5138 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) |
10b3939b DJ |
5139 | { |
5140 | struct dwarf2_queue_item *item; | |
5141 | ||
5142 | per_cu->queued = 1; | |
5143 | item = xmalloc (sizeof (*item)); | |
5144 | item->per_cu = per_cu; | |
5145 | item->next = NULL; | |
5146 | ||
5147 | if (dwarf2_queue == NULL) | |
5148 | dwarf2_queue = item; | |
5149 | else | |
5150 | dwarf2_queue_tail->next = item; | |
5151 | ||
5152 | dwarf2_queue_tail = item; | |
5153 | } | |
5154 | ||
5155 | /* Process the queue. */ | |
5156 | ||
5157 | static void | |
a0f42c21 | 5158 | process_queue (void) |
10b3939b DJ |
5159 | { |
5160 | struct dwarf2_queue_item *item, *next_item; | |
5161 | ||
03dd20cc DJ |
5162 | /* The queue starts out with one item, but following a DIE reference |
5163 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
5164 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
5165 | { | |
9291a0cd TT |
5166 | if (dwarf2_per_objfile->using_index |
5167 | ? !item->per_cu->v.quick->symtab | |
5168 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
5169 | process_full_comp_unit (item->per_cu); |
5170 | ||
5171 | item->per_cu->queued = 0; | |
5172 | next_item = item->next; | |
5173 | xfree (item); | |
5174 | } | |
5175 | ||
5176 | dwarf2_queue_tail = NULL; | |
5177 | } | |
5178 | ||
5179 | /* Free all allocated queue entries. This function only releases anything if | |
5180 | an error was thrown; if the queue was processed then it would have been | |
5181 | freed as we went along. */ | |
5182 | ||
5183 | static void | |
5184 | dwarf2_release_queue (void *dummy) | |
5185 | { | |
5186 | struct dwarf2_queue_item *item, *last; | |
5187 | ||
5188 | item = dwarf2_queue; | |
5189 | while (item) | |
5190 | { | |
5191 | /* Anything still marked queued is likely to be in an | |
5192 | inconsistent state, so discard it. */ | |
5193 | if (item->per_cu->queued) | |
5194 | { | |
5195 | if (item->per_cu->cu != NULL) | |
dee91e82 | 5196 | free_one_cached_comp_unit (item->per_cu); |
10b3939b DJ |
5197 | item->per_cu->queued = 0; |
5198 | } | |
5199 | ||
5200 | last = item; | |
5201 | item = item->next; | |
5202 | xfree (last); | |
5203 | } | |
5204 | ||
5205 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
5206 | } | |
5207 | ||
5208 | /* Read in full symbols for PST, and anything it depends on. */ | |
5209 | ||
c906108c | 5210 | static void |
fba45db2 | 5211 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 5212 | { |
10b3939b | 5213 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 5214 | struct cleanup *back_to; |
aaa75496 JB |
5215 | int i; |
5216 | ||
5217 | for (i = 0; i < pst->number_of_dependencies; i++) | |
5218 | if (!pst->dependencies[i]->readin) | |
5219 | { | |
5220 | /* Inform about additional files that need to be read in. */ | |
5221 | if (info_verbose) | |
5222 | { | |
a3f17187 | 5223 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
5224 | fputs_filtered (" ", gdb_stdout); |
5225 | wrap_here (""); | |
5226 | fputs_filtered ("and ", gdb_stdout); | |
5227 | wrap_here (""); | |
5228 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 5229 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
5230 | gdb_flush (gdb_stdout); |
5231 | } | |
5232 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
5233 | } | |
5234 | ||
e38df1d0 | 5235 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
5236 | |
5237 | if (per_cu == NULL) | |
aaa75496 JB |
5238 | { |
5239 | /* It's an include file, no symbols to read for it. | |
5240 | Everything is in the parent symtab. */ | |
5241 | pst->readin = 1; | |
5242 | return; | |
5243 | } | |
c906108c | 5244 | |
a0f42c21 | 5245 | dw2_do_instantiate_symtab (per_cu); |
10b3939b DJ |
5246 | } |
5247 | ||
dee91e82 DE |
5248 | /* Trivial hash function for die_info: the hash value of a DIE |
5249 | is its offset in .debug_info for this objfile. */ | |
10b3939b | 5250 | |
dee91e82 DE |
5251 | static hashval_t |
5252 | die_hash (const void *item) | |
10b3939b | 5253 | { |
dee91e82 | 5254 | const struct die_info *die = item; |
6502dd73 | 5255 | |
dee91e82 DE |
5256 | return die->offset.sect_off; |
5257 | } | |
63d06c5c | 5258 | |
dee91e82 DE |
5259 | /* Trivial comparison function for die_info structures: two DIEs |
5260 | are equal if they have the same offset. */ | |
98bfdba5 | 5261 | |
dee91e82 DE |
5262 | static int |
5263 | die_eq (const void *item_lhs, const void *item_rhs) | |
5264 | { | |
5265 | const struct die_info *die_lhs = item_lhs; | |
5266 | const struct die_info *die_rhs = item_rhs; | |
c906108c | 5267 | |
dee91e82 DE |
5268 | return die_lhs->offset.sect_off == die_rhs->offset.sect_off; |
5269 | } | |
c906108c | 5270 | |
dee91e82 DE |
5271 | /* die_reader_func for load_full_comp_unit. |
5272 | This is identical to read_signatured_type_reader, | |
5273 | but is kept separate for now. */ | |
c906108c | 5274 | |
dee91e82 DE |
5275 | static void |
5276 | load_full_comp_unit_reader (const struct die_reader_specs *reader, | |
5277 | gdb_byte *info_ptr, | |
5278 | struct die_info *comp_unit_die, | |
5279 | int has_children, | |
5280 | void *data) | |
5281 | { | |
5282 | struct dwarf2_cu *cu = reader->cu; | |
5283 | struct attribute *attr; | |
6caca83c | 5284 | |
dee91e82 DE |
5285 | gdb_assert (cu->die_hash == NULL); |
5286 | cu->die_hash = | |
5287 | htab_create_alloc_ex (cu->header.length / 12, | |
5288 | die_hash, | |
5289 | die_eq, | |
5290 | NULL, | |
5291 | &cu->comp_unit_obstack, | |
5292 | hashtab_obstack_allocate, | |
5293 | dummy_obstack_deallocate); | |
e142c38c | 5294 | |
dee91e82 DE |
5295 | if (has_children) |
5296 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
5297 | &info_ptr, comp_unit_die); | |
5298 | cu->dies = comp_unit_die; | |
5299 | /* comp_unit_die is not stored in die_hash, no need. */ | |
10b3939b DJ |
5300 | |
5301 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 5302 | all CUs needed for references have been loaded yet, and symbol |
10b3939b | 5303 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
5304 | or we won't be able to build types correctly. |
5305 | Similarly, if we do not read the producer, we can not apply | |
5306 | producer-specific interpretation. */ | |
9816fde3 | 5307 | prepare_one_comp_unit (cu, cu->dies); |
dee91e82 | 5308 | } |
10b3939b | 5309 | |
dee91e82 | 5310 | /* Load the DIEs associated with PER_CU into memory. */ |
a6c727b2 | 5311 | |
dee91e82 DE |
5312 | static void |
5313 | load_full_comp_unit (struct dwarf2_per_cu_data *this_cu) | |
5314 | { | |
3019eac3 | 5315 | gdb_assert (! this_cu->is_debug_types); |
c5b7e1cb | 5316 | |
dee91e82 | 5317 | init_cu_and_read_dies (this_cu, 1, 1, load_full_comp_unit_reader, NULL); |
10b3939b DJ |
5318 | } |
5319 | ||
3da10d80 KS |
5320 | /* Add a DIE to the delayed physname list. */ |
5321 | ||
5322 | static void | |
5323 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
5324 | const char *name, struct die_info *die, | |
5325 | struct dwarf2_cu *cu) | |
5326 | { | |
5327 | struct delayed_method_info mi; | |
5328 | mi.type = type; | |
5329 | mi.fnfield_index = fnfield_index; | |
5330 | mi.index = index; | |
5331 | mi.name = name; | |
5332 | mi.die = die; | |
5333 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
5334 | } | |
5335 | ||
5336 | /* A cleanup for freeing the delayed method list. */ | |
5337 | ||
5338 | static void | |
5339 | free_delayed_list (void *ptr) | |
5340 | { | |
5341 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
5342 | if (cu->method_list != NULL) | |
5343 | { | |
5344 | VEC_free (delayed_method_info, cu->method_list); | |
5345 | cu->method_list = NULL; | |
5346 | } | |
5347 | } | |
5348 | ||
5349 | /* Compute the physnames of any methods on the CU's method list. | |
5350 | ||
5351 | The computation of method physnames is delayed in order to avoid the | |
5352 | (bad) condition that one of the method's formal parameters is of an as yet | |
5353 | incomplete type. */ | |
5354 | ||
5355 | static void | |
5356 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
5357 | { | |
5358 | int i; | |
5359 | struct delayed_method_info *mi; | |
5360 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
5361 | { | |
1d06ead6 | 5362 | const char *physname; |
3da10d80 KS |
5363 | struct fn_fieldlist *fn_flp |
5364 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
1d06ead6 | 5365 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
3da10d80 KS |
5366 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
5367 | } | |
5368 | } | |
5369 | ||
a766d390 DE |
5370 | /* Go objects should be embedded in a DW_TAG_module DIE, |
5371 | and it's not clear if/how imported objects will appear. | |
5372 | To keep Go support simple until that's worked out, | |
5373 | go back through what we've read and create something usable. | |
5374 | We could do this while processing each DIE, and feels kinda cleaner, | |
5375 | but that way is more invasive. | |
5376 | This is to, for example, allow the user to type "p var" or "b main" | |
5377 | without having to specify the package name, and allow lookups | |
5378 | of module.object to work in contexts that use the expression | |
5379 | parser. */ | |
5380 | ||
5381 | static void | |
5382 | fixup_go_packaging (struct dwarf2_cu *cu) | |
5383 | { | |
5384 | char *package_name = NULL; | |
5385 | struct pending *list; | |
5386 | int i; | |
5387 | ||
5388 | for (list = global_symbols; list != NULL; list = list->next) | |
5389 | { | |
5390 | for (i = 0; i < list->nsyms; ++i) | |
5391 | { | |
5392 | struct symbol *sym = list->symbol[i]; | |
5393 | ||
5394 | if (SYMBOL_LANGUAGE (sym) == language_go | |
5395 | && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
5396 | { | |
5397 | char *this_package_name = go_symbol_package_name (sym); | |
5398 | ||
5399 | if (this_package_name == NULL) | |
5400 | continue; | |
5401 | if (package_name == NULL) | |
5402 | package_name = this_package_name; | |
5403 | else | |
5404 | { | |
5405 | if (strcmp (package_name, this_package_name) != 0) | |
5406 | complaint (&symfile_complaints, | |
5407 | _("Symtab %s has objects from two different Go packages: %s and %s"), | |
5408 | (sym->symtab && sym->symtab->filename | |
5409 | ? sym->symtab->filename | |
5410 | : cu->objfile->name), | |
5411 | this_package_name, package_name); | |
5412 | xfree (this_package_name); | |
5413 | } | |
5414 | } | |
5415 | } | |
5416 | } | |
5417 | ||
5418 | if (package_name != NULL) | |
5419 | { | |
5420 | struct objfile *objfile = cu->objfile; | |
5421 | struct type *type = init_type (TYPE_CODE_MODULE, 0, 0, | |
5422 | package_name, objfile); | |
5423 | struct symbol *sym; | |
5424 | ||
5425 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
5426 | ||
5427 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
5428 | SYMBOL_SET_LANGUAGE (sym, language_go); | |
5429 | SYMBOL_SET_NAMES (sym, package_name, strlen (package_name), 1, objfile); | |
5430 | /* This is not VAR_DOMAIN because we want a way to ensure a lookup of, | |
5431 | e.g., "main" finds the "main" module and not C's main(). */ | |
5432 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; | |
5433 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
5434 | SYMBOL_TYPE (sym) = type; | |
5435 | ||
5436 | add_symbol_to_list (sym, &global_symbols); | |
5437 | ||
5438 | xfree (package_name); | |
5439 | } | |
5440 | } | |
5441 | ||
9cdd5dbd | 5442 | /* Generate full symbol information for PER_CU, whose DIEs have |
10b3939b DJ |
5443 | already been loaded into memory. */ |
5444 | ||
5445 | static void | |
5446 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
5447 | { | |
10b3939b | 5448 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 5449 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
5450 | CORE_ADDR lowpc, highpc; |
5451 | struct symtab *symtab; | |
3da10d80 | 5452 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
5453 | CORE_ADDR baseaddr; |
5454 | ||
5455 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5456 | ||
10b3939b DJ |
5457 | buildsym_init (); |
5458 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 5459 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
5460 | |
5461 | cu->list_in_scope = &file_symbols; | |
c906108c SS |
5462 | |
5463 | /* Do line number decoding in read_file_scope () */ | |
10b3939b | 5464 | process_die (cu->dies, cu); |
c906108c | 5465 | |
a766d390 DE |
5466 | /* For now fudge the Go package. */ |
5467 | if (cu->language == language_go) | |
5468 | fixup_go_packaging (cu); | |
5469 | ||
3da10d80 KS |
5470 | /* Now that we have processed all the DIEs in the CU, all the types |
5471 | should be complete, and it should now be safe to compute all of the | |
5472 | physnames. */ | |
5473 | compute_delayed_physnames (cu); | |
5474 | do_cleanups (delayed_list_cleanup); | |
5475 | ||
fae299cd DC |
5476 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
5477 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
5478 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 5479 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 5480 | |
613e1657 | 5481 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c | 5482 | |
8be455d7 | 5483 | if (symtab != NULL) |
c906108c | 5484 | { |
df15bd07 | 5485 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
4632c0d0 | 5486 | |
8be455d7 JK |
5487 | /* Set symtab language to language from DW_AT_language. If the |
5488 | compilation is from a C file generated by language preprocessors, do | |
5489 | not set the language if it was already deduced by start_subfile. */ | |
5490 | if (!(cu->language == language_c && symtab->language != language_c)) | |
5491 | symtab->language = cu->language; | |
5492 | ||
5493 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
5494 | produce DW_AT_location with location lists but it can be possibly | |
ab260dad JK |
5495 | invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0 |
5496 | there were bugs in prologue debug info, fixed later in GCC-4.5 | |
5497 | by "unwind info for epilogues" patch (which is not directly related). | |
8be455d7 JK |
5498 | |
5499 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
5500 | needed, it would be wrong due to missing DW_AT_producer there. | |
5501 | ||
5502 | Still one can confuse GDB by using non-standard GCC compilation | |
5503 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
5504 | */ | |
ab260dad | 5505 | if (cu->has_loclist && gcc_4_minor >= 5) |
8be455d7 | 5506 | symtab->locations_valid = 1; |
e0d00bc7 JK |
5507 | |
5508 | if (gcc_4_minor >= 5) | |
5509 | symtab->epilogue_unwind_valid = 1; | |
96408a79 SA |
5510 | |
5511 | symtab->call_site_htab = cu->call_site_htab; | |
c906108c | 5512 | } |
9291a0cd TT |
5513 | |
5514 | if (dwarf2_per_objfile->using_index) | |
5515 | per_cu->v.quick->symtab = symtab; | |
5516 | else | |
5517 | { | |
5518 | struct partial_symtab *pst = per_cu->v.psymtab; | |
5519 | pst->symtab = symtab; | |
5520 | pst->readin = 1; | |
5521 | } | |
c906108c SS |
5522 | |
5523 | do_cleanups (back_to); | |
5524 | } | |
5525 | ||
5526 | /* Process a die and its children. */ | |
5527 | ||
5528 | static void | |
e7c27a73 | 5529 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5530 | { |
5531 | switch (die->tag) | |
5532 | { | |
5533 | case DW_TAG_padding: | |
5534 | break; | |
5535 | case DW_TAG_compile_unit: | |
e7c27a73 | 5536 | read_file_scope (die, cu); |
c906108c | 5537 | break; |
348e048f DE |
5538 | case DW_TAG_type_unit: |
5539 | read_type_unit_scope (die, cu); | |
5540 | break; | |
c906108c | 5541 | case DW_TAG_subprogram: |
c906108c | 5542 | case DW_TAG_inlined_subroutine: |
edb3359d | 5543 | read_func_scope (die, cu); |
c906108c SS |
5544 | break; |
5545 | case DW_TAG_lexical_block: | |
14898363 L |
5546 | case DW_TAG_try_block: |
5547 | case DW_TAG_catch_block: | |
e7c27a73 | 5548 | read_lexical_block_scope (die, cu); |
c906108c | 5549 | break; |
96408a79 SA |
5550 | case DW_TAG_GNU_call_site: |
5551 | read_call_site_scope (die, cu); | |
5552 | break; | |
c906108c | 5553 | case DW_TAG_class_type: |
680b30c7 | 5554 | case DW_TAG_interface_type: |
c906108c SS |
5555 | case DW_TAG_structure_type: |
5556 | case DW_TAG_union_type: | |
134d01f1 | 5557 | process_structure_scope (die, cu); |
c906108c SS |
5558 | break; |
5559 | case DW_TAG_enumeration_type: | |
134d01f1 | 5560 | process_enumeration_scope (die, cu); |
c906108c | 5561 | break; |
134d01f1 | 5562 | |
f792889a DJ |
5563 | /* These dies have a type, but processing them does not create |
5564 | a symbol or recurse to process the children. Therefore we can | |
5565 | read them on-demand through read_type_die. */ | |
c906108c | 5566 | case DW_TAG_subroutine_type: |
72019c9c | 5567 | case DW_TAG_set_type: |
c906108c | 5568 | case DW_TAG_array_type: |
c906108c | 5569 | case DW_TAG_pointer_type: |
c906108c | 5570 | case DW_TAG_ptr_to_member_type: |
c906108c | 5571 | case DW_TAG_reference_type: |
c906108c | 5572 | case DW_TAG_string_type: |
c906108c | 5573 | break; |
134d01f1 | 5574 | |
c906108c | 5575 | case DW_TAG_base_type: |
a02abb62 | 5576 | case DW_TAG_subrange_type: |
cb249c71 | 5577 | case DW_TAG_typedef: |
134d01f1 DJ |
5578 | /* Add a typedef symbol for the type definition, if it has a |
5579 | DW_AT_name. */ | |
f792889a | 5580 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 5581 | break; |
c906108c | 5582 | case DW_TAG_common_block: |
e7c27a73 | 5583 | read_common_block (die, cu); |
c906108c SS |
5584 | break; |
5585 | case DW_TAG_common_inclusion: | |
5586 | break; | |
d9fa45fe | 5587 | case DW_TAG_namespace: |
63d06c5c | 5588 | processing_has_namespace_info = 1; |
e7c27a73 | 5589 | read_namespace (die, cu); |
d9fa45fe | 5590 | break; |
5d7cb8df | 5591 | case DW_TAG_module: |
f55ee35c | 5592 | processing_has_namespace_info = 1; |
5d7cb8df JK |
5593 | read_module (die, cu); |
5594 | break; | |
d9fa45fe DC |
5595 | case DW_TAG_imported_declaration: |
5596 | case DW_TAG_imported_module: | |
63d06c5c | 5597 | processing_has_namespace_info = 1; |
27aa8d6a SW |
5598 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
5599 | || cu->language != language_fortran)) | |
5600 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
5601 | dwarf_tag_name (die->tag)); | |
5602 | read_import_statement (die, cu); | |
d9fa45fe | 5603 | break; |
c906108c | 5604 | default: |
e7c27a73 | 5605 | new_symbol (die, NULL, cu); |
c906108c SS |
5606 | break; |
5607 | } | |
5608 | } | |
5609 | ||
94af9270 KS |
5610 | /* A helper function for dwarf2_compute_name which determines whether DIE |
5611 | needs to have the name of the scope prepended to the name listed in the | |
5612 | die. */ | |
5613 | ||
5614 | static int | |
5615 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
5616 | { | |
1c809c68 TT |
5617 | struct attribute *attr; |
5618 | ||
94af9270 KS |
5619 | switch (die->tag) |
5620 | { | |
5621 | case DW_TAG_namespace: | |
5622 | case DW_TAG_typedef: | |
5623 | case DW_TAG_class_type: | |
5624 | case DW_TAG_interface_type: | |
5625 | case DW_TAG_structure_type: | |
5626 | case DW_TAG_union_type: | |
5627 | case DW_TAG_enumeration_type: | |
5628 | case DW_TAG_enumerator: | |
5629 | case DW_TAG_subprogram: | |
5630 | case DW_TAG_member: | |
5631 | return 1; | |
5632 | ||
5633 | case DW_TAG_variable: | |
c2b0a229 | 5634 | case DW_TAG_constant: |
94af9270 KS |
5635 | /* We only need to prefix "globally" visible variables. These include |
5636 | any variable marked with DW_AT_external or any variable that | |
5637 | lives in a namespace. [Variables in anonymous namespaces | |
5638 | require prefixing, but they are not DW_AT_external.] */ | |
5639 | ||
5640 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
5641 | { | |
5642 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 5643 | |
94af9270 KS |
5644 | return die_needs_namespace (die_specification (die, &spec_cu), |
5645 | spec_cu); | |
5646 | } | |
5647 | ||
1c809c68 | 5648 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
5649 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
5650 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
5651 | return 0; |
5652 | /* A variable in a lexical block of some kind does not need a | |
5653 | namespace, even though in C++ such variables may be external | |
5654 | and have a mangled name. */ | |
5655 | if (die->parent->tag == DW_TAG_lexical_block | |
5656 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
5657 | || die->parent->tag == DW_TAG_catch_block |
5658 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
5659 | return 0; |
5660 | return 1; | |
94af9270 KS |
5661 | |
5662 | default: | |
5663 | return 0; | |
5664 | } | |
5665 | } | |
5666 | ||
98bfdba5 PA |
5667 | /* Retrieve the last character from a mem_file. */ |
5668 | ||
5669 | static void | |
5670 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
5671 | { | |
5672 | char *last_char_p = (char *) object; | |
5673 | ||
5674 | if (length > 0) | |
5675 | *last_char_p = buffer[length - 1]; | |
5676 | } | |
5677 | ||
94af9270 | 5678 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
a766d390 DE |
5679 | compute the physname for the object, which include a method's: |
5680 | - formal parameters (C++/Java), | |
5681 | - receiver type (Go), | |
5682 | - return type (Java). | |
5683 | ||
5684 | The term "physname" is a bit confusing. | |
5685 | For C++, for example, it is the demangled name. | |
5686 | For Go, for example, it's the mangled name. | |
94af9270 | 5687 | |
af6b7be1 JB |
5688 | For Ada, return the DIE's linkage name rather than the fully qualified |
5689 | name. PHYSNAME is ignored.. | |
5690 | ||
94af9270 KS |
5691 | The result is allocated on the objfile_obstack and canonicalized. */ |
5692 | ||
5693 | static const char * | |
5694 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
5695 | int physname) | |
5696 | { | |
bb5ed363 DE |
5697 | struct objfile *objfile = cu->objfile; |
5698 | ||
94af9270 KS |
5699 | if (name == NULL) |
5700 | name = dwarf2_name (die, cu); | |
5701 | ||
f55ee35c JK |
5702 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
5703 | compute it by typename_concat inside GDB. */ | |
5704 | if (cu->language == language_ada | |
5705 | || (cu->language == language_fortran && physname)) | |
5706 | { | |
5707 | /* For Ada unit, we prefer the linkage name over the name, as | |
5708 | the former contains the exported name, which the user expects | |
5709 | to be able to reference. Ideally, we want the user to be able | |
5710 | to reference this entity using either natural or linkage name, | |
5711 | but we haven't started looking at this enhancement yet. */ | |
5712 | struct attribute *attr; | |
5713 | ||
5714 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5715 | if (attr == NULL) | |
5716 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5717 | if (attr && DW_STRING (attr)) | |
5718 | return DW_STRING (attr); | |
5719 | } | |
5720 | ||
94af9270 KS |
5721 | /* These are the only languages we know how to qualify names in. */ |
5722 | if (name != NULL | |
f55ee35c JK |
5723 | && (cu->language == language_cplus || cu->language == language_java |
5724 | || cu->language == language_fortran)) | |
94af9270 KS |
5725 | { |
5726 | if (die_needs_namespace (die, cu)) | |
5727 | { | |
5728 | long length; | |
0d5cff50 | 5729 | const char *prefix; |
94af9270 KS |
5730 | struct ui_file *buf; |
5731 | ||
5732 | prefix = determine_prefix (die, cu); | |
5733 | buf = mem_fileopen (); | |
5734 | if (*prefix != '\0') | |
5735 | { | |
f55ee35c JK |
5736 | char *prefixed_name = typename_concat (NULL, prefix, name, |
5737 | physname, cu); | |
9a619af0 | 5738 | |
94af9270 KS |
5739 | fputs_unfiltered (prefixed_name, buf); |
5740 | xfree (prefixed_name); | |
5741 | } | |
5742 | else | |
62d5b8da | 5743 | fputs_unfiltered (name, buf); |
94af9270 | 5744 | |
98bfdba5 PA |
5745 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
5746 | as children with DW_TAG_template_type_param or | |
5747 | DW_TAG_value_type_param. If the latter, add them to the name | |
5748 | here. If the name already has template parameters, then | |
5749 | skip this step; some versions of GCC emit both, and | |
5750 | it is more efficient to use the pre-computed name. | |
5751 | ||
5752 | Something to keep in mind about this process: it is very | |
5753 | unlikely, or in some cases downright impossible, to produce | |
5754 | something that will match the mangled name of a function. | |
5755 | If the definition of the function has the same debug info, | |
5756 | we should be able to match up with it anyway. But fallbacks | |
5757 | using the minimal symbol, for instance to find a method | |
5758 | implemented in a stripped copy of libstdc++, will not work. | |
5759 | If we do not have debug info for the definition, we will have to | |
5760 | match them up some other way. | |
5761 | ||
5762 | When we do name matching there is a related problem with function | |
5763 | templates; two instantiated function templates are allowed to | |
5764 | differ only by their return types, which we do not add here. */ | |
5765 | ||
5766 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
5767 | { | |
5768 | struct attribute *attr; | |
5769 | struct die_info *child; | |
5770 | int first = 1; | |
5771 | ||
5772 | die->building_fullname = 1; | |
5773 | ||
5774 | for (child = die->child; child != NULL; child = child->sibling) | |
5775 | { | |
5776 | struct type *type; | |
12df843f | 5777 | LONGEST value; |
98bfdba5 PA |
5778 | gdb_byte *bytes; |
5779 | struct dwarf2_locexpr_baton *baton; | |
5780 | struct value *v; | |
5781 | ||
5782 | if (child->tag != DW_TAG_template_type_param | |
5783 | && child->tag != DW_TAG_template_value_param) | |
5784 | continue; | |
5785 | ||
5786 | if (first) | |
5787 | { | |
5788 | fputs_unfiltered ("<", buf); | |
5789 | first = 0; | |
5790 | } | |
5791 | else | |
5792 | fputs_unfiltered (", ", buf); | |
5793 | ||
5794 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
5795 | if (attr == NULL) | |
5796 | { | |
5797 | complaint (&symfile_complaints, | |
5798 | _("template parameter missing DW_AT_type")); | |
5799 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
5800 | continue; | |
5801 | } | |
5802 | type = die_type (child, cu); | |
5803 | ||
5804 | if (child->tag == DW_TAG_template_type_param) | |
5805 | { | |
5806 | c_print_type (type, "", buf, -1, 0); | |
5807 | continue; | |
5808 | } | |
5809 | ||
5810 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
5811 | if (attr == NULL) | |
5812 | { | |
5813 | complaint (&symfile_complaints, | |
3e43a32a MS |
5814 | _("template parameter missing " |
5815 | "DW_AT_const_value")); | |
98bfdba5 PA |
5816 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
5817 | continue; | |
5818 | } | |
5819 | ||
5820 | dwarf2_const_value_attr (attr, type, name, | |
5821 | &cu->comp_unit_obstack, cu, | |
5822 | &value, &bytes, &baton); | |
5823 | ||
5824 | if (TYPE_NOSIGN (type)) | |
5825 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
5826 | changed, this can use value_print instead. */ | |
5827 | c_printchar (value, type, buf); | |
5828 | else | |
5829 | { | |
5830 | struct value_print_options opts; | |
5831 | ||
5832 | if (baton != NULL) | |
5833 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
5834 | baton->data, | |
5835 | baton->size, | |
5836 | baton->per_cu); | |
5837 | else if (bytes != NULL) | |
5838 | { | |
5839 | v = allocate_value (type); | |
5840 | memcpy (value_contents_writeable (v), bytes, | |
5841 | TYPE_LENGTH (type)); | |
5842 | } | |
5843 | else | |
5844 | v = value_from_longest (type, value); | |
5845 | ||
3e43a32a MS |
5846 | /* Specify decimal so that we do not depend on |
5847 | the radix. */ | |
98bfdba5 PA |
5848 | get_formatted_print_options (&opts, 'd'); |
5849 | opts.raw = 1; | |
5850 | value_print (v, buf, &opts); | |
5851 | release_value (v); | |
5852 | value_free (v); | |
5853 | } | |
5854 | } | |
5855 | ||
5856 | die->building_fullname = 0; | |
5857 | ||
5858 | if (!first) | |
5859 | { | |
5860 | /* Close the argument list, with a space if necessary | |
5861 | (nested templates). */ | |
5862 | char last_char = '\0'; | |
5863 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
5864 | if (last_char == '>') | |
5865 | fputs_unfiltered (" >", buf); | |
5866 | else | |
5867 | fputs_unfiltered (">", buf); | |
5868 | } | |
5869 | } | |
5870 | ||
94af9270 KS |
5871 | /* For Java and C++ methods, append formal parameter type |
5872 | information, if PHYSNAME. */ | |
6e70227d | 5873 | |
94af9270 KS |
5874 | if (physname && die->tag == DW_TAG_subprogram |
5875 | && (cu->language == language_cplus | |
5876 | || cu->language == language_java)) | |
5877 | { | |
5878 | struct type *type = read_type_die (die, cu); | |
5879 | ||
3167638f | 5880 | c_type_print_args (type, buf, 1, cu->language); |
94af9270 KS |
5881 | |
5882 | if (cu->language == language_java) | |
5883 | { | |
5884 | /* For java, we must append the return type to method | |
0963b4bd | 5885 | names. */ |
94af9270 KS |
5886 | if (die->tag == DW_TAG_subprogram) |
5887 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
5888 | 0, 0); | |
5889 | } | |
5890 | else if (cu->language == language_cplus) | |
5891 | { | |
60430eff DJ |
5892 | /* Assume that an artificial first parameter is |
5893 | "this", but do not crash if it is not. RealView | |
5894 | marks unnamed (and thus unused) parameters as | |
5895 | artificial; there is no way to differentiate | |
5896 | the two cases. */ | |
94af9270 KS |
5897 | if (TYPE_NFIELDS (type) > 0 |
5898 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 5899 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
5900 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
5901 | 0)))) | |
94af9270 KS |
5902 | fputs_unfiltered (" const", buf); |
5903 | } | |
5904 | } | |
5905 | ||
bb5ed363 | 5906 | name = ui_file_obsavestring (buf, &objfile->objfile_obstack, |
94af9270 KS |
5907 | &length); |
5908 | ui_file_delete (buf); | |
5909 | ||
5910 | if (cu->language == language_cplus) | |
5911 | { | |
5912 | char *cname | |
5913 | = dwarf2_canonicalize_name (name, cu, | |
bb5ed363 | 5914 | &objfile->objfile_obstack); |
9a619af0 | 5915 | |
94af9270 KS |
5916 | if (cname != NULL) |
5917 | name = cname; | |
5918 | } | |
5919 | } | |
5920 | } | |
5921 | ||
5922 | return name; | |
5923 | } | |
5924 | ||
0114d602 DJ |
5925 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
5926 | If scope qualifiers are appropriate they will be added. The result | |
5927 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
5928 | not have a name. NAME may either be from a previous call to |
5929 | dwarf2_name or NULL. | |
5930 | ||
0963b4bd | 5931 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
5932 | |
5933 | static const char * | |
94af9270 | 5934 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 5935 | { |
94af9270 KS |
5936 | return dwarf2_compute_name (name, die, cu, 0); |
5937 | } | |
0114d602 | 5938 | |
94af9270 KS |
5939 | /* Construct a physname for the given DIE in CU. NAME may either be |
5940 | from a previous call to dwarf2_name or NULL. The result will be | |
5941 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
5942 | name. | |
0114d602 | 5943 | |
94af9270 | 5944 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 5945 | |
94af9270 KS |
5946 | static const char * |
5947 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
5948 | { | |
bb5ed363 | 5949 | struct objfile *objfile = cu->objfile; |
900e11f9 JK |
5950 | struct attribute *attr; |
5951 | const char *retval, *mangled = NULL, *canon = NULL; | |
5952 | struct cleanup *back_to; | |
5953 | int need_copy = 1; | |
5954 | ||
5955 | /* In this case dwarf2_compute_name is just a shortcut not building anything | |
5956 | on its own. */ | |
5957 | if (!die_needs_namespace (die, cu)) | |
5958 | return dwarf2_compute_name (name, die, cu, 1); | |
5959 | ||
5960 | back_to = make_cleanup (null_cleanup, NULL); | |
5961 | ||
5962 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5963 | if (!attr) | |
5964 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5965 | ||
5966 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB | |
5967 | has computed. */ | |
5968 | if (attr && DW_STRING (attr)) | |
5969 | { | |
5970 | char *demangled; | |
5971 | ||
5972 | mangled = DW_STRING (attr); | |
5973 | ||
5974 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return | |
5975 | type. It is easier for GDB users to search for such functions as | |
5976 | `name(params)' than `long name(params)'. In such case the minimal | |
5977 | symbol names do not match the full symbol names but for template | |
5978 | functions there is never a need to look up their definition from their | |
5979 | declaration so the only disadvantage remains the minimal symbol | |
5980 | variant `long name(params)' does not have the proper inferior type. | |
5981 | */ | |
5982 | ||
a766d390 DE |
5983 | if (cu->language == language_go) |
5984 | { | |
5985 | /* This is a lie, but we already lie to the caller new_symbol_full. | |
5986 | new_symbol_full assumes we return the mangled name. | |
5987 | This just undoes that lie until things are cleaned up. */ | |
5988 | demangled = NULL; | |
5989 | } | |
5990 | else | |
5991 | { | |
5992 | demangled = cplus_demangle (mangled, | |
5993 | (DMGL_PARAMS | DMGL_ANSI | |
5994 | | (cu->language == language_java | |
5995 | ? DMGL_JAVA | DMGL_RET_POSTFIX | |
5996 | : DMGL_RET_DROP))); | |
5997 | } | |
900e11f9 JK |
5998 | if (demangled) |
5999 | { | |
6000 | make_cleanup (xfree, demangled); | |
6001 | canon = demangled; | |
6002 | } | |
6003 | else | |
6004 | { | |
6005 | canon = mangled; | |
6006 | need_copy = 0; | |
6007 | } | |
6008 | } | |
6009 | ||
6010 | if (canon == NULL || check_physname) | |
6011 | { | |
6012 | const char *physname = dwarf2_compute_name (name, die, cu, 1); | |
6013 | ||
6014 | if (canon != NULL && strcmp (physname, canon) != 0) | |
6015 | { | |
6016 | /* It may not mean a bug in GDB. The compiler could also | |
6017 | compute DW_AT_linkage_name incorrectly. But in such case | |
6018 | GDB would need to be bug-to-bug compatible. */ | |
6019 | ||
6020 | complaint (&symfile_complaints, | |
6021 | _("Computed physname <%s> does not match demangled <%s> " | |
6022 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), | |
b64f50a1 | 6023 | physname, canon, mangled, die->offset.sect_off, objfile->name); |
900e11f9 JK |
6024 | |
6025 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it | |
6026 | is available here - over computed PHYSNAME. It is safer | |
6027 | against both buggy GDB and buggy compilers. */ | |
6028 | ||
6029 | retval = canon; | |
6030 | } | |
6031 | else | |
6032 | { | |
6033 | retval = physname; | |
6034 | need_copy = 0; | |
6035 | } | |
6036 | } | |
6037 | else | |
6038 | retval = canon; | |
6039 | ||
6040 | if (need_copy) | |
6041 | retval = obsavestring (retval, strlen (retval), | |
bb5ed363 | 6042 | &objfile->objfile_obstack); |
900e11f9 JK |
6043 | |
6044 | do_cleanups (back_to); | |
6045 | return retval; | |
0114d602 DJ |
6046 | } |
6047 | ||
27aa8d6a SW |
6048 | /* Read the import statement specified by the given die and record it. */ |
6049 | ||
6050 | static void | |
6051 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
6052 | { | |
bb5ed363 | 6053 | struct objfile *objfile = cu->objfile; |
27aa8d6a | 6054 | struct attribute *import_attr; |
32019081 | 6055 | struct die_info *imported_die, *child_die; |
de4affc9 | 6056 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 6057 | const char *imported_name; |
794684b6 | 6058 | const char *imported_name_prefix; |
13387711 SW |
6059 | const char *canonical_name; |
6060 | const char *import_alias; | |
6061 | const char *imported_declaration = NULL; | |
794684b6 | 6062 | const char *import_prefix; |
32019081 JK |
6063 | VEC (const_char_ptr) *excludes = NULL; |
6064 | struct cleanup *cleanups; | |
13387711 SW |
6065 | |
6066 | char *temp; | |
27aa8d6a SW |
6067 | |
6068 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
6069 | if (import_attr == NULL) | |
6070 | { | |
6071 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
6072 | dwarf_tag_name (die->tag)); | |
6073 | return; | |
6074 | } | |
6075 | ||
de4affc9 CC |
6076 | imported_cu = cu; |
6077 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
6078 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
6079 | if (imported_name == NULL) |
6080 | { | |
6081 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
6082 | ||
6083 | The import in the following code: | |
6084 | namespace A | |
6085 | { | |
6086 | typedef int B; | |
6087 | } | |
6088 | ||
6089 | int main () | |
6090 | { | |
6091 | using A::B; | |
6092 | B b; | |
6093 | return b; | |
6094 | } | |
6095 | ||
6096 | ... | |
6097 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
6098 | <52> DW_AT_decl_file : 1 | |
6099 | <53> DW_AT_decl_line : 6 | |
6100 | <54> DW_AT_import : <0x75> | |
6101 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
6102 | <59> DW_AT_name : B | |
6103 | <5b> DW_AT_decl_file : 1 | |
6104 | <5c> DW_AT_decl_line : 2 | |
6105 | <5d> DW_AT_type : <0x6e> | |
6106 | ... | |
6107 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
6108 | <76> DW_AT_byte_size : 4 | |
6109 | <77> DW_AT_encoding : 5 (signed) | |
6110 | ||
6111 | imports the wrong die ( 0x75 instead of 0x58 ). | |
6112 | This case will be ignored until the gcc bug is fixed. */ | |
6113 | return; | |
6114 | } | |
6115 | ||
82856980 SW |
6116 | /* Figure out the local name after import. */ |
6117 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 6118 | |
794684b6 SW |
6119 | /* Figure out where the statement is being imported to. */ |
6120 | import_prefix = determine_prefix (die, cu); | |
6121 | ||
6122 | /* Figure out what the scope of the imported die is and prepend it | |
6123 | to the name of the imported die. */ | |
de4affc9 | 6124 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 6125 | |
f55ee35c JK |
6126 | if (imported_die->tag != DW_TAG_namespace |
6127 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 6128 | { |
13387711 SW |
6129 | imported_declaration = imported_name; |
6130 | canonical_name = imported_name_prefix; | |
794684b6 | 6131 | } |
13387711 | 6132 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 6133 | { |
13387711 SW |
6134 | temp = alloca (strlen (imported_name_prefix) |
6135 | + 2 + strlen (imported_name) + 1); | |
6136 | strcpy (temp, imported_name_prefix); | |
6137 | strcat (temp, "::"); | |
6138 | strcat (temp, imported_name); | |
6139 | canonical_name = temp; | |
794684b6 | 6140 | } |
13387711 SW |
6141 | else |
6142 | canonical_name = imported_name; | |
794684b6 | 6143 | |
32019081 JK |
6144 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
6145 | ||
6146 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) | |
6147 | for (child_die = die->child; child_die && child_die->tag; | |
6148 | child_die = sibling_die (child_die)) | |
6149 | { | |
6150 | /* DWARF-4: A Fortran use statement with a “rename list” may be | |
6151 | represented by an imported module entry with an import attribute | |
6152 | referring to the module and owned entries corresponding to those | |
6153 | entities that are renamed as part of being imported. */ | |
6154 | ||
6155 | if (child_die->tag != DW_TAG_imported_declaration) | |
6156 | { | |
6157 | complaint (&symfile_complaints, | |
6158 | _("child DW_TAG_imported_declaration expected " | |
6159 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 6160 | child_die->offset.sect_off, objfile->name); |
32019081 JK |
6161 | continue; |
6162 | } | |
6163 | ||
6164 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); | |
6165 | if (import_attr == NULL) | |
6166 | { | |
6167 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
6168 | dwarf_tag_name (child_die->tag)); | |
6169 | continue; | |
6170 | } | |
6171 | ||
6172 | imported_cu = cu; | |
6173 | imported_die = follow_die_ref_or_sig (child_die, import_attr, | |
6174 | &imported_cu); | |
6175 | imported_name = dwarf2_name (imported_die, imported_cu); | |
6176 | if (imported_name == NULL) | |
6177 | { | |
6178 | complaint (&symfile_complaints, | |
6179 | _("child DW_TAG_imported_declaration has unknown " | |
6180 | "imported name - DIE at 0x%x [in module %s]"), | |
b64f50a1 | 6181 | child_die->offset.sect_off, objfile->name); |
32019081 JK |
6182 | continue; |
6183 | } | |
6184 | ||
6185 | VEC_safe_push (const_char_ptr, excludes, imported_name); | |
6186 | ||
6187 | process_die (child_die, cu); | |
6188 | } | |
6189 | ||
c0cc3a76 SW |
6190 | cp_add_using_directive (import_prefix, |
6191 | canonical_name, | |
6192 | import_alias, | |
13387711 | 6193 | imported_declaration, |
32019081 | 6194 | excludes, |
bb5ed363 | 6195 | &objfile->objfile_obstack); |
32019081 JK |
6196 | |
6197 | do_cleanups (cleanups); | |
27aa8d6a SW |
6198 | } |
6199 | ||
ae2de4f8 DE |
6200 | /* Cleanup function for read_file_scope. */ |
6201 | ||
cb1df416 DJ |
6202 | static void |
6203 | free_cu_line_header (void *arg) | |
6204 | { | |
6205 | struct dwarf2_cu *cu = arg; | |
6206 | ||
6207 | free_line_header (cu->line_header); | |
6208 | cu->line_header = NULL; | |
6209 | } | |
6210 | ||
9291a0cd TT |
6211 | static void |
6212 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
6213 | char **name, char **comp_dir) | |
6214 | { | |
6215 | struct attribute *attr; | |
6216 | ||
6217 | *name = NULL; | |
6218 | *comp_dir = NULL; | |
6219 | ||
6220 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
6221 | is not a source language identifier. */ | |
6222 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
6223 | if (attr) | |
6224 | { | |
6225 | *name = DW_STRING (attr); | |
6226 | } | |
6227 | ||
6228 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
6229 | if (attr) | |
6230 | *comp_dir = DW_STRING (attr); | |
6231 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
6232 | { | |
6233 | *comp_dir = ldirname (*name); | |
6234 | if (*comp_dir != NULL) | |
6235 | make_cleanup (xfree, *comp_dir); | |
6236 | } | |
6237 | if (*comp_dir != NULL) | |
6238 | { | |
6239 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
6240 | directory, get rid of it. */ | |
6241 | char *cp = strchr (*comp_dir, ':'); | |
6242 | ||
6243 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
6244 | *comp_dir = cp + 1; | |
6245 | } | |
6246 | ||
6247 | if (*name == NULL) | |
6248 | *name = "<unknown>"; | |
6249 | } | |
6250 | ||
f3f5162e DE |
6251 | /* Handle DW_AT_stmt_list for a compilation unit or type unit. |
6252 | DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU. | |
6253 | COMP_DIR is the compilation directory. | |
6254 | WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */ | |
2ab95328 TT |
6255 | |
6256 | static void | |
6257 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, | |
f3f5162e | 6258 | const char *comp_dir, int want_line_info) |
2ab95328 TT |
6259 | { |
6260 | struct attribute *attr; | |
2ab95328 | 6261 | |
2ab95328 TT |
6262 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
6263 | if (attr) | |
6264 | { | |
6265 | unsigned int line_offset = DW_UNSND (attr); | |
6266 | struct line_header *line_header | |
3019eac3 | 6267 | = dwarf_decode_line_header (line_offset, cu); |
2ab95328 TT |
6268 | |
6269 | if (line_header) | |
dee91e82 DE |
6270 | { |
6271 | cu->line_header = line_header; | |
6272 | make_cleanup (free_cu_line_header, cu); | |
f3f5162e | 6273 | dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info); |
dee91e82 | 6274 | } |
2ab95328 TT |
6275 | } |
6276 | } | |
6277 | ||
ae2de4f8 DE |
6278 | /* Process DW_TAG_compile_unit. */ |
6279 | ||
c906108c | 6280 | static void |
e7c27a73 | 6281 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6282 | { |
dee91e82 | 6283 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
debd256d | 6284 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 6285 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
6286 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
6287 | struct attribute *attr; | |
e1024ff1 | 6288 | char *name = NULL; |
c906108c SS |
6289 | char *comp_dir = NULL; |
6290 | struct die_info *child_die; | |
6291 | bfd *abfd = objfile->obfd; | |
e142c38c | 6292 | CORE_ADDR baseaddr; |
6e70227d | 6293 | |
e142c38c | 6294 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 6295 | |
fae299cd | 6296 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
6297 | |
6298 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
6299 | from finish_block. */ | |
2acceee2 | 6300 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
6301 | lowpc = highpc; |
6302 | lowpc += baseaddr; | |
6303 | highpc += baseaddr; | |
6304 | ||
9291a0cd | 6305 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 6306 | |
dee91e82 | 6307 | prepare_one_comp_unit (cu, die); |
303b6f5d | 6308 | |
f4b8a18d KW |
6309 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
6310 | standardised yet. As a workaround for the language detection we fall | |
6311 | back to the DW_AT_producer string. */ | |
6312 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
6313 | cu->language = language_opencl; | |
6314 | ||
3019eac3 DE |
6315 | /* Similar hack for Go. */ |
6316 | if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL) | |
6317 | set_cu_language (DW_LANG_Go, cu); | |
6318 | ||
6319 | /* We assume that we're processing GCC output. */ | |
6320 | processing_gcc_compilation = 2; | |
6321 | ||
6322 | processing_has_namespace_info = 0; | |
6323 | ||
6324 | start_symtab (name, comp_dir, lowpc); | |
6325 | record_debugformat ("DWARF 2"); | |
6326 | record_producer (cu->producer); | |
6327 | ||
6328 | /* Decode line number information if present. We do this before | |
6329 | processing child DIEs, so that the line header table is available | |
6330 | for DW_AT_decl_file. */ | |
6331 | handle_DW_AT_stmt_list (die, cu, comp_dir, 1); | |
6332 | ||
6333 | /* Process all dies in compilation unit. */ | |
6334 | if (die->child != NULL) | |
6335 | { | |
6336 | child_die = die->child; | |
6337 | while (child_die && child_die->tag) | |
6338 | { | |
6339 | process_die (child_die, cu); | |
6340 | child_die = sibling_die (child_die); | |
6341 | } | |
6342 | } | |
6343 | ||
6344 | /* Decode macro information, if present. Dwarf 2 macro information | |
6345 | refers to information in the line number info statement program | |
6346 | header, so we can only read it if we've read the header | |
6347 | successfully. */ | |
6348 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); | |
6349 | if (attr && cu->line_header) | |
6350 | { | |
6351 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) | |
6352 | complaint (&symfile_complaints, | |
6353 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); | |
6354 | ||
6355 | dwarf_decode_macros (cu->line_header, DW_UNSND (attr), | |
6356 | comp_dir, abfd, cu, | |
6357 | &dwarf2_per_objfile->macro, 1); | |
6358 | } | |
6359 | else | |
6360 | { | |
6361 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |
6362 | if (attr && cu->line_header) | |
6363 | { | |
6364 | unsigned int macro_offset = DW_UNSND (attr); | |
6365 | ||
6366 | dwarf_decode_macros (cu->line_header, macro_offset, | |
6367 | comp_dir, abfd, cu, | |
6368 | &dwarf2_per_objfile->macinfo, 0); | |
6369 | } | |
6370 | } | |
6371 | ||
6372 | do_cleanups (back_to); | |
6373 | } | |
6374 | ||
6375 | /* Process DW_TAG_type_unit. | |
6376 | For TUs we want to skip the first top level sibling if it's not the | |
6377 | actual type being defined by this TU. In this case the first top | |
6378 | level sibling is there to provide context only. */ | |
6379 | ||
6380 | static void | |
6381 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6382 | { | |
6383 | struct objfile *objfile = cu->objfile; | |
6384 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
6385 | CORE_ADDR lowpc; | |
6386 | struct attribute *attr; | |
6387 | char *name = NULL; | |
6388 | char *comp_dir = NULL; | |
6389 | struct die_info *child_die; | |
6390 | bfd *abfd = objfile->obfd; | |
6391 | ||
6392 | /* start_symtab needs a low pc, but we don't really have one. | |
6393 | Do what read_file_scope would do in the absence of such info. */ | |
6394 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6395 | ||
6396 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
6397 | is not a source language identifier. */ | |
6398 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
6399 | if (attr) | |
6400 | name = DW_STRING (attr); | |
6401 | ||
6402 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
6403 | if (attr) | |
6404 | comp_dir = DW_STRING (attr); | |
6405 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
6406 | { | |
6407 | comp_dir = ldirname (name); | |
6408 | if (comp_dir != NULL) | |
6409 | make_cleanup (xfree, comp_dir); | |
6410 | } | |
6411 | ||
6412 | if (name == NULL) | |
6413 | name = "<unknown>"; | |
6414 | ||
6415 | prepare_one_comp_unit (cu, die); | |
6416 | ||
6417 | /* We assume that we're processing GCC output. */ | |
6418 | processing_gcc_compilation = 2; | |
6419 | ||
6420 | processing_has_namespace_info = 0; | |
6421 | ||
6422 | start_symtab (name, comp_dir, lowpc); | |
6423 | record_debugformat ("DWARF 2"); | |
6424 | record_producer (cu->producer); | |
6425 | ||
6426 | /* Decode line number information if present. We do this before | |
6427 | processing child DIEs, so that the line header table is available | |
6428 | for DW_AT_decl_file. | |
6429 | We don't need the pc/line-number mapping for type units. */ | |
6430 | handle_DW_AT_stmt_list (die, cu, comp_dir, 0); | |
6431 | ||
6432 | /* Process the dies in the type unit. */ | |
6433 | if (die->child == NULL) | |
6434 | { | |
6435 | dump_die_for_error (die); | |
6436 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
6437 | bfd_get_filename (abfd)); | |
6438 | } | |
6439 | ||
6440 | child_die = die->child; | |
6441 | ||
6442 | while (child_die && child_die->tag) | |
6443 | { | |
6444 | process_die (child_die, cu); | |
6445 | ||
6446 | child_die = sibling_die (child_die); | |
6447 | } | |
6448 | ||
6449 | do_cleanups (back_to); | |
6450 | } | |
6451 | \f | |
6452 | /* DWO files. */ | |
6453 | ||
6454 | static hashval_t | |
6455 | hash_dwo_file (const void *item) | |
6456 | { | |
6457 | const struct dwo_file *dwo_file = item; | |
6458 | ||
6459 | return htab_hash_string (dwo_file->dwo_name); | |
6460 | } | |
6461 | ||
6462 | static int | |
6463 | eq_dwo_file (const void *item_lhs, const void *item_rhs) | |
6464 | { | |
6465 | const struct dwo_file *lhs = item_lhs; | |
6466 | const struct dwo_file *rhs = item_rhs; | |
6467 | ||
6468 | return strcmp (lhs->dwo_name, rhs->dwo_name) == 0; | |
6469 | } | |
6470 | ||
6471 | /* Allocate a hash table for DWO files. */ | |
6472 | ||
6473 | static htab_t | |
6474 | allocate_dwo_file_hash_table (void) | |
6475 | { | |
6476 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
6477 | ||
6478 | return htab_create_alloc_ex (41, | |
6479 | hash_dwo_file, | |
6480 | eq_dwo_file, | |
6481 | NULL, | |
6482 | &objfile->objfile_obstack, | |
6483 | hashtab_obstack_allocate, | |
6484 | dummy_obstack_deallocate); | |
6485 | } | |
6486 | ||
6487 | static hashval_t | |
6488 | hash_dwo_unit (const void *item) | |
6489 | { | |
6490 | const struct dwo_unit *dwo_unit = item; | |
6491 | ||
6492 | /* This drops the top 32 bits of the id, but is ok for a hash. */ | |
6493 | return dwo_unit->signature; | |
6494 | } | |
6495 | ||
6496 | static int | |
6497 | eq_dwo_unit (const void *item_lhs, const void *item_rhs) | |
6498 | { | |
6499 | const struct dwo_unit *lhs = item_lhs; | |
6500 | const struct dwo_unit *rhs = item_rhs; | |
6501 | ||
6502 | /* The signature is assumed to be unique within the DWO file. | |
6503 | So while object file CU dwo_id's always have the value zero, | |
6504 | that's OK, assuming each object file DWO file has only one CU, | |
6505 | and that's the rule for now. */ | |
6506 | return lhs->signature == rhs->signature; | |
6507 | } | |
6508 | ||
6509 | /* Allocate a hash table for DWO CUs,TUs. | |
6510 | There is one of these tables for each of CUs,TUs for each DWO file. */ | |
6511 | ||
6512 | static htab_t | |
6513 | allocate_dwo_unit_table (struct objfile *objfile) | |
6514 | { | |
6515 | /* Start out with a pretty small number. | |
6516 | Generally DWO files contain only one CU and maybe some TUs. */ | |
6517 | return htab_create_alloc_ex (3, | |
6518 | hash_dwo_unit, | |
6519 | eq_dwo_unit, | |
6520 | NULL, | |
6521 | &objfile->objfile_obstack, | |
6522 | hashtab_obstack_allocate, | |
6523 | dummy_obstack_deallocate); | |
6524 | } | |
6525 | ||
6526 | /* This function is mapped across the sections and remembers the offset and | |
6527 | size of each of the DWO debugging sections we are interested in. */ | |
6528 | ||
6529 | static void | |
6530 | dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_file_ptr) | |
6531 | { | |
6532 | struct dwo_file *dwo_file = dwo_file_ptr; | |
6533 | const struct dwo_section_names *names = &dwo_section_names; | |
6534 | ||
6535 | if (section_is_p (sectp->name, &names->abbrev_dwo)) | |
6536 | { | |
6537 | dwo_file->sections.abbrev.asection = sectp; | |
6538 | dwo_file->sections.abbrev.size = bfd_get_section_size (sectp); | |
6539 | } | |
6540 | else if (section_is_p (sectp->name, &names->info_dwo)) | |
6541 | { | |
6542 | dwo_file->sections.info.asection = sectp; | |
6543 | dwo_file->sections.info.size = bfd_get_section_size (sectp); | |
6544 | } | |
6545 | else if (section_is_p (sectp->name, &names->line_dwo)) | |
6546 | { | |
6547 | dwo_file->sections.line.asection = sectp; | |
6548 | dwo_file->sections.line.size = bfd_get_section_size (sectp); | |
6549 | } | |
6550 | else if (section_is_p (sectp->name, &names->loc_dwo)) | |
6551 | { | |
6552 | dwo_file->sections.loc.asection = sectp; | |
6553 | dwo_file->sections.loc.size = bfd_get_section_size (sectp); | |
6554 | } | |
6555 | else if (section_is_p (sectp->name, &names->str_dwo)) | |
6556 | { | |
6557 | dwo_file->sections.str.asection = sectp; | |
6558 | dwo_file->sections.str.size = bfd_get_section_size (sectp); | |
6559 | } | |
6560 | else if (section_is_p (sectp->name, &names->str_offsets_dwo)) | |
6561 | { | |
6562 | dwo_file->sections.str_offsets.asection = sectp; | |
6563 | dwo_file->sections.str_offsets.size = bfd_get_section_size (sectp); | |
6564 | } | |
6565 | else if (section_is_p (sectp->name, &names->types_dwo)) | |
6566 | { | |
6567 | struct dwarf2_section_info type_section; | |
6568 | ||
6569 | memset (&type_section, 0, sizeof (type_section)); | |
6570 | type_section.asection = sectp; | |
6571 | type_section.size = bfd_get_section_size (sectp); | |
6572 | VEC_safe_push (dwarf2_section_info_def, dwo_file->sections.types, | |
6573 | &type_section); | |
6574 | } | |
6575 | } | |
6576 | ||
6577 | /* Structure used to pass data to create_debug_info_hash_table_reader. */ | |
6578 | ||
6579 | struct create_dwo_info_table_data | |
6580 | { | |
6581 | struct dwo_file *dwo_file; | |
6582 | htab_t cu_htab; | |
6583 | }; | |
6584 | ||
6585 | /* die_reader_func for create_debug_info_hash_table. */ | |
6586 | ||
6587 | static void | |
6588 | create_debug_info_hash_table_reader (const struct die_reader_specs *reader, | |
6589 | gdb_byte *info_ptr, | |
6590 | struct die_info *comp_unit_die, | |
6591 | int has_children, | |
6592 | void *datap) | |
6593 | { | |
6594 | struct dwarf2_cu *cu = reader->cu; | |
6595 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
6596 | sect_offset offset = cu->per_cu->offset; | |
6597 | struct dwarf2_section_info *section = cu->per_cu->info_or_types_section; | |
6598 | struct create_dwo_info_table_data *data = datap; | |
6599 | struct dwo_file *dwo_file = data->dwo_file; | |
6600 | htab_t cu_htab = data->cu_htab; | |
6601 | void **slot; | |
6602 | struct attribute *attr; | |
6603 | struct dwo_unit *dwo_unit; | |
6604 | ||
6605 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); | |
6606 | if (attr == NULL) | |
6607 | { | |
6608 | error (_("Dwarf Error: debug entry at offset 0x%x is missing" | |
6609 | " its dwo_id [in module %s]"), | |
6610 | offset.sect_off, dwo_file->dwo_name); | |
6611 | return; | |
6612 | } | |
6613 | ||
6614 | dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); | |
6615 | dwo_unit->dwo_file = dwo_file; | |
6616 | dwo_unit->signature = DW_UNSND (attr); | |
6617 | dwo_unit->info_or_types_section = section; | |
6618 | dwo_unit->offset = offset; | |
6619 | dwo_unit->length = cu->per_cu->length; | |
6620 | ||
6621 | slot = htab_find_slot (cu_htab, dwo_unit, INSERT); | |
6622 | gdb_assert (slot != NULL); | |
6623 | if (*slot != NULL) | |
6624 | { | |
6625 | const struct dwo_unit *dup_dwo_unit = *slot; | |
6626 | ||
6627 | complaint (&symfile_complaints, | |
6628 | _("debug entry at offset 0x%x is duplicate to the entry at" | |
6629 | " offset 0x%x, dwo_id 0x%s [in module %s]"), | |
6630 | offset.sect_off, dup_dwo_unit->offset.sect_off, | |
6631 | phex (dwo_unit->signature, sizeof (dwo_unit->signature)), | |
6632 | dwo_file->dwo_name); | |
6633 | } | |
6634 | else | |
6635 | *slot = dwo_unit; | |
6636 | ||
6637 | if (dwarf2_die_debug) | |
6638 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, dwo_id 0x%s\n", | |
6639 | offset.sect_off, | |
6640 | phex (dwo_unit->signature, | |
6641 | sizeof (dwo_unit->signature))); | |
6642 | } | |
6643 | ||
6644 | /* Create a hash table to map DWO IDs to their CU entry in .debug_info.dwo. */ | |
6645 | ||
6646 | static htab_t | |
6647 | create_debug_info_hash_table (struct dwo_file *dwo_file) | |
6648 | { | |
6649 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
6650 | struct dwarf2_section_info *section = &dwo_file->sections.info; | |
6651 | bfd *abfd; | |
6652 | htab_t cu_htab; | |
6653 | gdb_byte *info_ptr, *end_ptr; | |
6654 | struct create_dwo_info_table_data create_dwo_info_table_data; | |
6655 | ||
6656 | dwarf2_read_section (objfile, section); | |
6657 | info_ptr = section->buffer; | |
6658 | ||
6659 | if (info_ptr == NULL) | |
6660 | return NULL; | |
6661 | ||
6662 | /* We can't set abfd until now because the section may be empty or | |
6663 | not present, in which case section->asection will be NULL. */ | |
6664 | abfd = section->asection->owner; | |
6665 | ||
6666 | if (dwarf2_die_debug) | |
6667 | fprintf_unfiltered (gdb_stdlog, "Reading .debug_info.dwo for %s:\n", | |
6668 | bfd_get_filename (abfd)); | |
6669 | ||
6670 | cu_htab = allocate_dwo_unit_table (objfile); | |
6671 | ||
6672 | create_dwo_info_table_data.dwo_file = dwo_file; | |
6673 | create_dwo_info_table_data.cu_htab = cu_htab; | |
6674 | ||
6675 | end_ptr = info_ptr + section->size; | |
6676 | while (info_ptr < end_ptr) | |
6677 | { | |
6678 | struct dwarf2_per_cu_data per_cu; | |
6679 | ||
6680 | memset (&per_cu, 0, sizeof (per_cu)); | |
6681 | per_cu.objfile = objfile; | |
6682 | per_cu.is_debug_types = 0; | |
6683 | per_cu.offset.sect_off = info_ptr - section->buffer; | |
6684 | per_cu.info_or_types_section = section; | |
6685 | ||
6686 | init_cutu_and_read_dies_no_follow (&per_cu, | |
6687 | &dwo_file->sections.abbrev, | |
6688 | dwo_file, | |
6689 | create_debug_info_hash_table_reader, | |
6690 | &create_dwo_info_table_data); | |
6691 | ||
6692 | info_ptr += per_cu.length; | |
6693 | } | |
6694 | ||
6695 | return cu_htab; | |
6696 | } | |
6697 | ||
6698 | /* Subroutine of open_dwo_file to simplify it. | |
6699 | Open the file specified by FILE_NAME and hand it off to BFD for | |
6700 | preliminary analysis. Return a newly initialized bfd *, which | |
6701 | includes a canonicalized copy of FILE_NAME. | |
6702 | In case of trouble, return NULL. | |
6703 | NOTE: This function is derived from symfile_bfd_open. */ | |
6704 | ||
6705 | static bfd * | |
6706 | try_open_dwo_file (const char *file_name) | |
6707 | { | |
6708 | bfd *sym_bfd; | |
6709 | int desc; | |
6710 | char *absolute_name; | |
6711 | char *name; | |
6712 | ||
6713 | desc = openp (debug_file_directory, OPF_TRY_CWD_FIRST, file_name, | |
6714 | O_RDONLY | O_BINARY, &absolute_name); | |
6715 | if (desc < 0) | |
6716 | return NULL; | |
6717 | ||
6718 | sym_bfd = bfd_fopen (absolute_name, gnutarget, FOPEN_RB, desc); | |
6719 | if (!sym_bfd) | |
6720 | { | |
6721 | close (desc); | |
6722 | xfree (absolute_name); | |
6723 | return NULL; | |
6724 | } | |
6725 | bfd_set_cacheable (sym_bfd, 1); | |
6726 | ||
6727 | if (!bfd_check_format (sym_bfd, bfd_object)) | |
6728 | { | |
6729 | bfd_close (sym_bfd); /* This also closes desc. */ | |
6730 | xfree (absolute_name); | |
6731 | return NULL; | |
6732 | } | |
6733 | ||
6734 | /* bfd_usrdata exists for applications and libbfd must not touch it. */ | |
6735 | gdb_assert (bfd_usrdata (sym_bfd) == NULL); | |
6736 | ||
6737 | return sym_bfd; | |
6738 | } | |
6739 | ||
6740 | /* Try to open DWO file DWO_NAME. | |
6741 | COMP_DIR is the DW_AT_comp_dir attribute. | |
6742 | The result is the bfd handle of the file. | |
6743 | If there is a problem finding or opening the file, return NULL. | |
6744 | Upon success, the canonicalized path of the file is stored in the bfd, | |
6745 | same as symfile_bfd_open. */ | |
6746 | ||
6747 | static bfd * | |
6748 | open_dwo_file (const char *dwo_name, const char *comp_dir) | |
6749 | { | |
6750 | bfd *abfd; | |
6751 | char *path_to_try, *debug_dir; | |
6752 | ||
6753 | if (IS_ABSOLUTE_PATH (dwo_name)) | |
6754 | return try_open_dwo_file (dwo_name); | |
6755 | ||
6756 | /* Before trying the search path, try DWO_NAME in COMP_DIR. */ | |
6757 | ||
6758 | if (comp_dir != NULL) | |
6759 | { | |
6760 | char *path_to_try = concat (comp_dir, SLASH_STRING, dwo_name, NULL); | |
6761 | ||
6762 | /* NOTE: If comp_dir is a relative path, this will also try the | |
6763 | search path, which seems useful. */ | |
6764 | abfd = try_open_dwo_file (path_to_try); | |
6765 | xfree (path_to_try); | |
6766 | if (abfd != NULL) | |
6767 | return abfd; | |
6768 | } | |
6769 | ||
6770 | /* That didn't work, try debug-file-directory, which, despite its name, | |
6771 | is a list of paths. */ | |
6772 | ||
6773 | if (*debug_file_directory == '\0') | |
6774 | return NULL; | |
6775 | ||
6776 | return try_open_dwo_file (dwo_name); | |
6777 | } | |
6778 | ||
6779 | /* Initialize the use of the DWO file specified by DWO_NAME. */ | |
6780 | ||
6781 | static struct dwo_file * | |
6782 | init_dwo_file (const char *dwo_name, const char *comp_dir) | |
6783 | { | |
6784 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
6785 | struct dwo_file *dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
6786 | struct dwo_file); | |
6787 | bfd *abfd; | |
6788 | struct cleanup *cleanups; | |
6789 | ||
6790 | if (dwarf2_die_debug) | |
6791 | fprintf_unfiltered (gdb_stdlog, "Reading DWO file %s:\n", dwo_name); | |
6792 | ||
6793 | abfd = open_dwo_file (dwo_name, comp_dir); | |
6794 | if (abfd == NULL) | |
6795 | return NULL; | |
6796 | dwo_file->dwo_name = dwo_name; | |
6797 | dwo_file->dwo_bfd = abfd; | |
6798 | ||
6799 | cleanups = make_cleanup (free_dwo_file_cleanup, dwo_file); | |
6800 | ||
6801 | bfd_map_over_sections (abfd, dwarf2_locate_dwo_sections, dwo_file); | |
6802 | ||
6803 | dwo_file->cus = create_debug_info_hash_table (dwo_file); | |
6804 | ||
6805 | dwo_file->tus = create_debug_types_hash_table (dwo_file, | |
6806 | dwo_file->sections.types); | |
6807 | ||
6808 | discard_cleanups (cleanups); | |
6809 | ||
6810 | return dwo_file; | |
6811 | } | |
6812 | ||
6813 | /* Lookup DWO file DWO_NAME. */ | |
6814 | ||
6815 | static struct dwo_file * | |
6816 | lookup_dwo_file (char *dwo_name, const char *comp_dir) | |
6817 | { | |
6818 | struct dwo_file *dwo_file; | |
6819 | struct dwo_file find_entry; | |
6820 | void **slot; | |
6821 | ||
6822 | if (dwarf2_per_objfile->dwo_files == NULL) | |
6823 | dwarf2_per_objfile->dwo_files = allocate_dwo_file_hash_table (); | |
6824 | ||
6825 | /* Have we already seen this DWO file? */ | |
6826 | find_entry.dwo_name = dwo_name; | |
6827 | slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT); | |
6828 | ||
6829 | /* If not, read it in and build a table of the DWOs it contains. */ | |
6830 | if (*slot == NULL) | |
6831 | *slot = init_dwo_file (dwo_name, comp_dir); | |
6832 | ||
6833 | /* NOTE: This will be NULL if unable to open the file. */ | |
6834 | dwo_file = *slot; | |
6835 | ||
6836 | return dwo_file; | |
6837 | } | |
6838 | ||
6839 | /* Lookup the DWO CU referenced from THIS_CU in DWO file DWO_NAME. | |
6840 | If non-NULL, comp_dir is the DW_AT_comp_dir attribute. | |
6841 | SIGNATURE is the "dwo_id" of the CU (for consistency we use the same | |
6842 | nomenclature as TUs). | |
6843 | The result is the DWO CU or NULL if we didn't find it | |
6844 | (dwo_id mismatch or couldn't find the DWO file). */ | |
6845 | ||
6846 | static struct dwo_unit * | |
6847 | lookup_dwo_comp_unit (struct dwarf2_per_cu_data *this_cu, | |
6848 | char *dwo_name, const char *comp_dir, | |
6849 | ULONGEST signature) | |
6850 | { | |
6851 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
6852 | struct dwo_file *dwo_file; | |
6853 | ||
6854 | dwo_file = lookup_dwo_file (dwo_name, comp_dir); | |
6855 | if (dwo_file == NULL) | |
6856 | return NULL; | |
6857 | ||
6858 | /* Look up the DWO using its signature(dwo_id). */ | |
6859 | ||
6860 | if (dwo_file->cus != NULL) | |
6861 | { | |
6862 | struct dwo_unit find_dwo_cu, *dwo_cu; | |
6863 | ||
6864 | find_dwo_cu.signature = signature; | |
6865 | dwo_cu = htab_find (dwo_file->cus, &find_dwo_cu); | |
a766d390 | 6866 | |
3019eac3 DE |
6867 | if (dwo_cu != NULL) |
6868 | return dwo_cu; | |
6869 | } | |
c906108c | 6870 | |
3019eac3 | 6871 | /* We didn't find it. This must mean a dwo_id mismatch. */ |
df8a16a1 | 6872 | |
3019eac3 DE |
6873 | complaint (&symfile_complaints, |
6874 | _("Could not find DWO CU referenced by CU at offset 0x%x" | |
6875 | " [in module %s]"), | |
6876 | this_cu->offset.sect_off, objfile->name); | |
6877 | return NULL; | |
6878 | } | |
c906108c | 6879 | |
3019eac3 DE |
6880 | /* Lookup the DWO TU referenced from THIS_TU in DWO file DWO_NAME. |
6881 | If non-NULL, comp_dir is the DW_AT_comp_dir attribute. | |
6882 | The result is the DWO CU or NULL if we didn't find it | |
6883 | (dwo_id mismatch or couldn't find the DWO file). */ | |
debd256d | 6884 | |
3019eac3 DE |
6885 | static struct dwo_unit * |
6886 | lookup_dwo_type_unit (struct signatured_type *this_tu, | |
6887 | char *dwo_name, const char *comp_dir) | |
6888 | { | |
6889 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
6890 | struct dwo_file *dwo_file; | |
6891 | struct dwo_unit find_dwo_tu, *dwo_tu; | |
cb1df416 | 6892 | |
3019eac3 DE |
6893 | dwo_file = lookup_dwo_file (dwo_name, comp_dir); |
6894 | if (dwo_file == NULL) | |
6895 | return NULL; | |
cf2c3c16 | 6896 | |
3019eac3 DE |
6897 | /* Look up the DWO using its signature(dwo_id). */ |
6898 | ||
6899 | if (dwo_file->tus != NULL) | |
cf2c3c16 | 6900 | { |
3019eac3 | 6901 | struct dwo_unit find_dwo_tu, *dwo_tu; |
9a619af0 | 6902 | |
3019eac3 DE |
6903 | find_dwo_tu.signature = this_tu->signature; |
6904 | dwo_tu = htab_find (dwo_file->tus, &find_dwo_tu); | |
6905 | ||
6906 | if (dwo_tu != NULL) | |
6907 | return dwo_tu; | |
2e276125 | 6908 | } |
9cdd5dbd | 6909 | |
3019eac3 DE |
6910 | /* We didn't find it. This must mean a dwo_id mismatch. */ |
6911 | ||
6912 | complaint (&symfile_complaints, | |
6913 | _("Could not find DWO TU referenced by TU at offset 0x%x" | |
6914 | " [in module %s]"), | |
6915 | this_tu->per_cu.offset.sect_off, objfile->name); | |
6916 | return NULL; | |
5fb290d7 DJ |
6917 | } |
6918 | ||
3019eac3 DE |
6919 | /* Free all resources associated with DWO_FILE. |
6920 | Close the DWO file and munmap the sections. | |
6921 | All memory should be on the objfile obstack. */ | |
348e048f DE |
6922 | |
6923 | static void | |
3019eac3 | 6924 | free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile) |
348e048f | 6925 | { |
3019eac3 DE |
6926 | int ix; |
6927 | struct dwarf2_section_info *section; | |
348e048f | 6928 | |
3019eac3 DE |
6929 | gdb_assert (dwo_file->dwo_bfd != objfile->obfd); |
6930 | bfd_close (dwo_file->dwo_bfd); | |
348e048f | 6931 | |
3019eac3 DE |
6932 | munmap_section_buffer (&dwo_file->sections.abbrev); |
6933 | munmap_section_buffer (&dwo_file->sections.info); | |
6934 | munmap_section_buffer (&dwo_file->sections.line); | |
6935 | munmap_section_buffer (&dwo_file->sections.loc); | |
6936 | munmap_section_buffer (&dwo_file->sections.str); | |
6937 | munmap_section_buffer (&dwo_file->sections.str_offsets); | |
348e048f | 6938 | |
3019eac3 DE |
6939 | for (ix = 0; |
6940 | VEC_iterate (dwarf2_section_info_def, dwo_file->sections.types, | |
6941 | ix, section); | |
6942 | ++ix) | |
6943 | munmap_section_buffer (section); | |
348e048f | 6944 | |
3019eac3 DE |
6945 | VEC_free (dwarf2_section_info_def, dwo_file->sections.types); |
6946 | } | |
348e048f | 6947 | |
3019eac3 | 6948 | /* Wrapper for free_dwo_file for use in cleanups. */ |
348e048f | 6949 | |
3019eac3 DE |
6950 | static void |
6951 | free_dwo_file_cleanup (void *arg) | |
6952 | { | |
6953 | struct dwo_file *dwo_file = (struct dwo_file *) arg; | |
6954 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
348e048f | 6955 | |
3019eac3 DE |
6956 | free_dwo_file (dwo_file, objfile); |
6957 | } | |
348e048f | 6958 | |
3019eac3 | 6959 | /* Traversal function for free_dwo_files. */ |
2ab95328 | 6960 | |
3019eac3 DE |
6961 | static int |
6962 | free_dwo_file_from_slot (void **slot, void *info) | |
6963 | { | |
6964 | struct dwo_file *dwo_file = (struct dwo_file *) *slot; | |
6965 | struct objfile *objfile = (struct objfile *) info; | |
348e048f | 6966 | |
3019eac3 | 6967 | free_dwo_file (dwo_file, objfile); |
348e048f | 6968 | |
3019eac3 DE |
6969 | return 1; |
6970 | } | |
348e048f | 6971 | |
3019eac3 | 6972 | /* Free all resources associated with DWO_FILES. */ |
348e048f | 6973 | |
3019eac3 DE |
6974 | static void |
6975 | free_dwo_files (htab_t dwo_files, struct objfile *objfile) | |
6976 | { | |
6977 | htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile); | |
348e048f | 6978 | } |
3019eac3 DE |
6979 | \f |
6980 | /* Read in various DIEs. */ | |
348e048f | 6981 | |
d389af10 JK |
6982 | /* qsort helper for inherit_abstract_dies. */ |
6983 | ||
6984 | static int | |
6985 | unsigned_int_compar (const void *ap, const void *bp) | |
6986 | { | |
6987 | unsigned int a = *(unsigned int *) ap; | |
6988 | unsigned int b = *(unsigned int *) bp; | |
6989 | ||
6990 | return (a > b) - (b > a); | |
6991 | } | |
6992 | ||
6993 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
6994 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
6995 | already referenced by DW_AT_abstract_origin from the children of the | |
6996 | current DIE. */ | |
d389af10 JK |
6997 | |
6998 | static void | |
6999 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
7000 | { | |
7001 | struct die_info *child_die; | |
7002 | unsigned die_children_count; | |
7003 | /* CU offsets which were referenced by children of the current DIE. */ | |
b64f50a1 JK |
7004 | sect_offset *offsets; |
7005 | sect_offset *offsets_end, *offsetp; | |
d389af10 JK |
7006 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ |
7007 | struct die_info *origin_die; | |
7008 | /* Iterator of the ORIGIN_DIE children. */ | |
7009 | struct die_info *origin_child_die; | |
7010 | struct cleanup *cleanups; | |
7011 | struct attribute *attr; | |
cd02d79d PA |
7012 | struct dwarf2_cu *origin_cu; |
7013 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
7014 | |
7015 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
7016 | if (!attr) | |
7017 | return; | |
7018 | ||
cd02d79d PA |
7019 | /* Note that following die references may follow to a die in a |
7020 | different cu. */ | |
7021 | ||
7022 | origin_cu = cu; | |
7023 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
7024 | ||
7025 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
7026 | symbols in. */ | |
7027 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
7028 | origin_cu->list_in_scope = cu->list_in_scope; | |
7029 | ||
edb3359d DJ |
7030 | if (die->tag != origin_die->tag |
7031 | && !(die->tag == DW_TAG_inlined_subroutine | |
7032 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
7033 | complaint (&symfile_complaints, |
7034 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
b64f50a1 | 7035 | die->offset.sect_off, origin_die->offset.sect_off); |
d389af10 JK |
7036 | |
7037 | child_die = die->child; | |
7038 | die_children_count = 0; | |
7039 | while (child_die && child_die->tag) | |
7040 | { | |
7041 | child_die = sibling_die (child_die); | |
7042 | die_children_count++; | |
7043 | } | |
7044 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
7045 | cleanups = make_cleanup (xfree, offsets); | |
7046 | ||
7047 | offsets_end = offsets; | |
7048 | child_die = die->child; | |
7049 | while (child_die && child_die->tag) | |
7050 | { | |
c38f313d DJ |
7051 | /* For each CHILD_DIE, find the corresponding child of |
7052 | ORIGIN_DIE. If there is more than one layer of | |
7053 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
7054 | but GCC versions at least through 4.4 generate this (GCC PR | |
7055 | 40573). */ | |
7056 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 7057 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 7058 | |
c38f313d DJ |
7059 | while (1) |
7060 | { | |
cd02d79d PA |
7061 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
7062 | child_origin_cu); | |
c38f313d DJ |
7063 | if (attr == NULL) |
7064 | break; | |
cd02d79d PA |
7065 | child_origin_die = follow_die_ref (child_origin_die, attr, |
7066 | &child_origin_cu); | |
c38f313d DJ |
7067 | } |
7068 | ||
d389af10 JK |
7069 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
7070 | counterpart may exist. */ | |
c38f313d | 7071 | if (child_origin_die != child_die) |
d389af10 | 7072 | { |
edb3359d DJ |
7073 | if (child_die->tag != child_origin_die->tag |
7074 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
7075 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
7076 | complaint (&symfile_complaints, |
7077 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
b64f50a1 JK |
7078 | "different tags"), child_die->offset.sect_off, |
7079 | child_origin_die->offset.sect_off); | |
c38f313d DJ |
7080 | if (child_origin_die->parent != origin_die) |
7081 | complaint (&symfile_complaints, | |
7082 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
b64f50a1 JK |
7083 | "different parents"), child_die->offset.sect_off, |
7084 | child_origin_die->offset.sect_off); | |
c38f313d DJ |
7085 | else |
7086 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
7087 | } |
7088 | child_die = sibling_die (child_die); | |
7089 | } | |
7090 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
7091 | unsigned_int_compar); | |
7092 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
b64f50a1 | 7093 | if (offsetp[-1].sect_off == offsetp->sect_off) |
3e43a32a MS |
7094 | complaint (&symfile_complaints, |
7095 | _("Multiple children of DIE 0x%x refer " | |
7096 | "to DIE 0x%x as their abstract origin"), | |
b64f50a1 | 7097 | die->offset.sect_off, offsetp->sect_off); |
d389af10 JK |
7098 | |
7099 | offsetp = offsets; | |
7100 | origin_child_die = origin_die->child; | |
7101 | while (origin_child_die && origin_child_die->tag) | |
7102 | { | |
7103 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
b64f50a1 JK |
7104 | while (offsetp < offsets_end |
7105 | && offsetp->sect_off < origin_child_die->offset.sect_off) | |
d389af10 | 7106 | offsetp++; |
b64f50a1 JK |
7107 | if (offsetp >= offsets_end |
7108 | || offsetp->sect_off > origin_child_die->offset.sect_off) | |
d389af10 JK |
7109 | { |
7110 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 7111 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
7112 | } |
7113 | origin_child_die = sibling_die (origin_child_die); | |
7114 | } | |
cd02d79d | 7115 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
7116 | |
7117 | do_cleanups (cleanups); | |
7118 | } | |
7119 | ||
c906108c | 7120 | static void |
e7c27a73 | 7121 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7122 | { |
e7c27a73 | 7123 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 7124 | struct context_stack *new; |
c906108c SS |
7125 | CORE_ADDR lowpc; |
7126 | CORE_ADDR highpc; | |
7127 | struct die_info *child_die; | |
edb3359d | 7128 | struct attribute *attr, *call_line, *call_file; |
c906108c | 7129 | char *name; |
e142c38c | 7130 | CORE_ADDR baseaddr; |
801e3a5b | 7131 | struct block *block; |
edb3359d | 7132 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
7133 | VEC (symbolp) *template_args = NULL; |
7134 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
7135 | |
7136 | if (inlined_func) | |
7137 | { | |
7138 | /* If we do not have call site information, we can't show the | |
7139 | caller of this inlined function. That's too confusing, so | |
7140 | only use the scope for local variables. */ | |
7141 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
7142 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
7143 | if (call_line == NULL || call_file == NULL) | |
7144 | { | |
7145 | read_lexical_block_scope (die, cu); | |
7146 | return; | |
7147 | } | |
7148 | } | |
c906108c | 7149 | |
e142c38c DJ |
7150 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
7151 | ||
94af9270 | 7152 | name = dwarf2_name (die, cu); |
c906108c | 7153 | |
e8d05480 JB |
7154 | /* Ignore functions with missing or empty names. These are actually |
7155 | illegal according to the DWARF standard. */ | |
7156 | if (name == NULL) | |
7157 | { | |
7158 | complaint (&symfile_complaints, | |
b64f50a1 JK |
7159 | _("missing name for subprogram DIE at %d"), |
7160 | die->offset.sect_off); | |
e8d05480 JB |
7161 | return; |
7162 | } | |
7163 | ||
7164 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
7165 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
7166 | { | |
ae4d0c03 PM |
7167 | attr = dwarf2_attr (die, DW_AT_external, cu); |
7168 | if (!attr || !DW_UNSND (attr)) | |
7169 | complaint (&symfile_complaints, | |
3e43a32a MS |
7170 | _("cannot get low and high bounds " |
7171 | "for subprogram DIE at %d"), | |
b64f50a1 | 7172 | die->offset.sect_off); |
e8d05480 JB |
7173 | return; |
7174 | } | |
c906108c SS |
7175 | |
7176 | lowpc += baseaddr; | |
7177 | highpc += baseaddr; | |
7178 | ||
34eaf542 TT |
7179 | /* If we have any template arguments, then we must allocate a |
7180 | different sort of symbol. */ | |
7181 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
7182 | { | |
7183 | if (child_die->tag == DW_TAG_template_type_param | |
7184 | || child_die->tag == DW_TAG_template_value_param) | |
7185 | { | |
7186 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
7187 | struct template_symbol); | |
7188 | templ_func->base.is_cplus_template_function = 1; | |
7189 | break; | |
7190 | } | |
7191 | } | |
7192 | ||
c906108c | 7193 | new = push_context (0, lowpc); |
34eaf542 TT |
7194 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
7195 | (struct symbol *) templ_func); | |
4c2df51b | 7196 | |
4cecd739 DJ |
7197 | /* If there is a location expression for DW_AT_frame_base, record |
7198 | it. */ | |
e142c38c | 7199 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 7200 | if (attr) |
c034e007 AC |
7201 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
7202 | expression is being recorded directly in the function's symbol | |
7203 | and not in a separate frame-base object. I guess this hack is | |
7204 | to avoid adding some sort of frame-base adjunct/annex to the | |
7205 | function's symbol :-(. The problem with doing this is that it | |
7206 | results in a function symbol with a location expression that | |
7207 | has nothing to do with the location of the function, ouch! The | |
7208 | relationship should be: a function's symbol has-a frame base; a | |
7209 | frame-base has-a location expression. */ | |
e7c27a73 | 7210 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 7211 | |
e142c38c | 7212 | cu->list_in_scope = &local_symbols; |
c906108c | 7213 | |
639d11d3 | 7214 | if (die->child != NULL) |
c906108c | 7215 | { |
639d11d3 | 7216 | child_die = die->child; |
c906108c SS |
7217 | while (child_die && child_die->tag) |
7218 | { | |
34eaf542 TT |
7219 | if (child_die->tag == DW_TAG_template_type_param |
7220 | || child_die->tag == DW_TAG_template_value_param) | |
7221 | { | |
7222 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
7223 | ||
f1078f66 DJ |
7224 | if (arg != NULL) |
7225 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
7226 | } |
7227 | else | |
7228 | process_die (child_die, cu); | |
c906108c SS |
7229 | child_die = sibling_die (child_die); |
7230 | } | |
7231 | } | |
7232 | ||
d389af10 JK |
7233 | inherit_abstract_dies (die, cu); |
7234 | ||
4a811a97 UW |
7235 | /* If we have a DW_AT_specification, we might need to import using |
7236 | directives from the context of the specification DIE. See the | |
7237 | comment in determine_prefix. */ | |
7238 | if (cu->language == language_cplus | |
7239 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
7240 | { | |
7241 | struct dwarf2_cu *spec_cu = cu; | |
7242 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
7243 | ||
7244 | while (spec_die) | |
7245 | { | |
7246 | child_die = spec_die->child; | |
7247 | while (child_die && child_die->tag) | |
7248 | { | |
7249 | if (child_die->tag == DW_TAG_imported_module) | |
7250 | process_die (child_die, spec_cu); | |
7251 | child_die = sibling_die (child_die); | |
7252 | } | |
7253 | ||
7254 | /* In some cases, GCC generates specification DIEs that | |
7255 | themselves contain DW_AT_specification attributes. */ | |
7256 | spec_die = die_specification (spec_die, &spec_cu); | |
7257 | } | |
7258 | } | |
7259 | ||
c906108c SS |
7260 | new = pop_context (); |
7261 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
7262 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
7263 | lowpc, highpc, objfile); | |
7264 | ||
df8a16a1 | 7265 | /* For C++, set the block's scope. */ |
f55ee35c | 7266 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 7267 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 7268 | determine_prefix (die, cu), |
df8a16a1 DJ |
7269 | processing_has_namespace_info); |
7270 | ||
801e3a5b JB |
7271 | /* If we have address ranges, record them. */ |
7272 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 7273 | |
34eaf542 TT |
7274 | /* Attach template arguments to function. */ |
7275 | if (! VEC_empty (symbolp, template_args)) | |
7276 | { | |
7277 | gdb_assert (templ_func != NULL); | |
7278 | ||
7279 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
7280 | templ_func->template_arguments | |
7281 | = obstack_alloc (&objfile->objfile_obstack, | |
7282 | (templ_func->n_template_arguments | |
7283 | * sizeof (struct symbol *))); | |
7284 | memcpy (templ_func->template_arguments, | |
7285 | VEC_address (symbolp, template_args), | |
7286 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
7287 | VEC_free (symbolp, template_args); | |
7288 | } | |
7289 | ||
208d8187 JB |
7290 | /* In C++, we can have functions nested inside functions (e.g., when |
7291 | a function declares a class that has methods). This means that | |
7292 | when we finish processing a function scope, we may need to go | |
7293 | back to building a containing block's symbol lists. */ | |
7294 | local_symbols = new->locals; | |
7295 | param_symbols = new->params; | |
27aa8d6a | 7296 | using_directives = new->using_directives; |
208d8187 | 7297 | |
921e78cf JB |
7298 | /* If we've finished processing a top-level function, subsequent |
7299 | symbols go in the file symbol list. */ | |
7300 | if (outermost_context_p ()) | |
e142c38c | 7301 | cu->list_in_scope = &file_symbols; |
c906108c SS |
7302 | } |
7303 | ||
7304 | /* Process all the DIES contained within a lexical block scope. Start | |
7305 | a new scope, process the dies, and then close the scope. */ | |
7306 | ||
7307 | static void | |
e7c27a73 | 7308 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7309 | { |
e7c27a73 | 7310 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 7311 | struct context_stack *new; |
c906108c SS |
7312 | CORE_ADDR lowpc, highpc; |
7313 | struct die_info *child_die; | |
e142c38c DJ |
7314 | CORE_ADDR baseaddr; |
7315 | ||
7316 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
7317 | |
7318 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
7319 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
7320 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 7321 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 7322 | describe ranges. */ |
d85a05f0 | 7323 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
7324 | return; |
7325 | lowpc += baseaddr; | |
7326 | highpc += baseaddr; | |
7327 | ||
7328 | push_context (0, lowpc); | |
639d11d3 | 7329 | if (die->child != NULL) |
c906108c | 7330 | { |
639d11d3 | 7331 | child_die = die->child; |
c906108c SS |
7332 | while (child_die && child_die->tag) |
7333 | { | |
e7c27a73 | 7334 | process_die (child_die, cu); |
c906108c SS |
7335 | child_die = sibling_die (child_die); |
7336 | } | |
7337 | } | |
7338 | new = pop_context (); | |
7339 | ||
8540c487 | 7340 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 7341 | { |
801e3a5b JB |
7342 | struct block *block |
7343 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
7344 | highpc, objfile); | |
7345 | ||
7346 | /* Note that recording ranges after traversing children, as we | |
7347 | do here, means that recording a parent's ranges entails | |
7348 | walking across all its children's ranges as they appear in | |
7349 | the address map, which is quadratic behavior. | |
7350 | ||
7351 | It would be nicer to record the parent's ranges before | |
7352 | traversing its children, simply overriding whatever you find | |
7353 | there. But since we don't even decide whether to create a | |
7354 | block until after we've traversed its children, that's hard | |
7355 | to do. */ | |
7356 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
7357 | } |
7358 | local_symbols = new->locals; | |
27aa8d6a | 7359 | using_directives = new->using_directives; |
c906108c SS |
7360 | } |
7361 | ||
96408a79 SA |
7362 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
7363 | ||
7364 | static void | |
7365 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7366 | { | |
7367 | struct objfile *objfile = cu->objfile; | |
7368 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
7369 | CORE_ADDR pc, baseaddr; | |
7370 | struct attribute *attr; | |
7371 | struct call_site *call_site, call_site_local; | |
7372 | void **slot; | |
7373 | int nparams; | |
7374 | struct die_info *child_die; | |
7375 | ||
7376 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
7377 | ||
7378 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
7379 | if (!attr) | |
7380 | { | |
7381 | complaint (&symfile_complaints, | |
7382 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " | |
7383 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 7384 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7385 | return; |
7386 | } | |
7387 | pc = DW_ADDR (attr) + baseaddr; | |
7388 | ||
7389 | if (cu->call_site_htab == NULL) | |
7390 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, | |
7391 | NULL, &objfile->objfile_obstack, | |
7392 | hashtab_obstack_allocate, NULL); | |
7393 | call_site_local.pc = pc; | |
7394 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); | |
7395 | if (*slot != NULL) | |
7396 | { | |
7397 | complaint (&symfile_complaints, | |
7398 | _("Duplicate PC %s for DW_TAG_GNU_call_site " | |
7399 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 7400 | paddress (gdbarch, pc), die->offset.sect_off, objfile->name); |
96408a79 SA |
7401 | return; |
7402 | } | |
7403 | ||
7404 | /* Count parameters at the caller. */ | |
7405 | ||
7406 | nparams = 0; | |
7407 | for (child_die = die->child; child_die && child_die->tag; | |
7408 | child_die = sibling_die (child_die)) | |
7409 | { | |
7410 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
7411 | { | |
7412 | complaint (&symfile_complaints, | |
7413 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " | |
7414 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 7415 | child_die->tag, child_die->offset.sect_off, objfile->name); |
96408a79 SA |
7416 | continue; |
7417 | } | |
7418 | ||
7419 | nparams++; | |
7420 | } | |
7421 | ||
7422 | call_site = obstack_alloc (&objfile->objfile_obstack, | |
7423 | (sizeof (*call_site) | |
7424 | + (sizeof (*call_site->parameter) | |
7425 | * (nparams - 1)))); | |
7426 | *slot = call_site; | |
7427 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); | |
7428 | call_site->pc = pc; | |
7429 | ||
7430 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) | |
7431 | { | |
7432 | struct die_info *func_die; | |
7433 | ||
7434 | /* Skip also over DW_TAG_inlined_subroutine. */ | |
7435 | for (func_die = die->parent; | |
7436 | func_die && func_die->tag != DW_TAG_subprogram | |
7437 | && func_die->tag != DW_TAG_subroutine_type; | |
7438 | func_die = func_die->parent); | |
7439 | ||
7440 | /* DW_AT_GNU_all_call_sites is a superset | |
7441 | of DW_AT_GNU_all_tail_call_sites. */ | |
7442 | if (func_die | |
7443 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) | |
7444 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) | |
7445 | { | |
7446 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is | |
7447 | not complete. But keep CALL_SITE for look ups via call_site_htab, | |
7448 | both the initial caller containing the real return address PC and | |
7449 | the final callee containing the current PC of a chain of tail | |
7450 | calls do not need to have the tail call list complete. But any | |
7451 | function candidate for a virtual tail call frame searched via | |
7452 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be | |
7453 | determined unambiguously. */ | |
7454 | } | |
7455 | else | |
7456 | { | |
7457 | struct type *func_type = NULL; | |
7458 | ||
7459 | if (func_die) | |
7460 | func_type = get_die_type (func_die, cu); | |
7461 | if (func_type != NULL) | |
7462 | { | |
7463 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); | |
7464 | ||
7465 | /* Enlist this call site to the function. */ | |
7466 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); | |
7467 | TYPE_TAIL_CALL_LIST (func_type) = call_site; | |
7468 | } | |
7469 | else | |
7470 | complaint (&symfile_complaints, | |
7471 | _("Cannot find function owning DW_TAG_GNU_call_site " | |
7472 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 7473 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7474 | } |
7475 | } | |
7476 | ||
7477 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); | |
7478 | if (attr == NULL) | |
7479 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
7480 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); | |
7481 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) | |
7482 | /* Keep NULL DWARF_BLOCK. */; | |
7483 | else if (attr_form_is_block (attr)) | |
7484 | { | |
7485 | struct dwarf2_locexpr_baton *dlbaton; | |
7486 | ||
7487 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); | |
7488 | dlbaton->data = DW_BLOCK (attr)->data; | |
7489 | dlbaton->size = DW_BLOCK (attr)->size; | |
7490 | dlbaton->per_cu = cu->per_cu; | |
7491 | ||
7492 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); | |
7493 | } | |
7494 | else if (is_ref_attr (attr)) | |
7495 | { | |
96408a79 SA |
7496 | struct dwarf2_cu *target_cu = cu; |
7497 | struct die_info *target_die; | |
7498 | ||
7499 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); | |
7500 | gdb_assert (target_cu->objfile == objfile); | |
7501 | if (die_is_declaration (target_die, target_cu)) | |
7502 | { | |
7503 | const char *target_physname; | |
7504 | ||
7505 | target_physname = dwarf2_physname (NULL, target_die, target_cu); | |
7506 | if (target_physname == NULL) | |
7507 | complaint (&symfile_complaints, | |
7508 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
7509 | "physname, for referencing DIE 0x%x [in module %s]"), | |
b64f50a1 | 7510 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7511 | else |
7512 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); | |
7513 | } | |
7514 | else | |
7515 | { | |
7516 | CORE_ADDR lowpc; | |
7517 | ||
7518 | /* DW_AT_entry_pc should be preferred. */ | |
7519 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) | |
7520 | complaint (&symfile_complaints, | |
7521 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
7522 | "low pc, for referencing DIE 0x%x [in module %s]"), | |
b64f50a1 | 7523 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7524 | else |
7525 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); | |
7526 | } | |
7527 | } | |
7528 | else | |
7529 | complaint (&symfile_complaints, | |
7530 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " | |
7531 | "block nor reference, for DIE 0x%x [in module %s]"), | |
b64f50a1 | 7532 | die->offset.sect_off, objfile->name); |
96408a79 SA |
7533 | |
7534 | call_site->per_cu = cu->per_cu; | |
7535 | ||
7536 | for (child_die = die->child; | |
7537 | child_die && child_die->tag; | |
7538 | child_die = sibling_die (child_die)) | |
7539 | { | |
7540 | struct dwarf2_locexpr_baton *dlbaton; | |
7541 | struct call_site_parameter *parameter; | |
7542 | ||
7543 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
7544 | { | |
7545 | /* Already printed the complaint above. */ | |
7546 | continue; | |
7547 | } | |
7548 | ||
7549 | gdb_assert (call_site->parameter_count < nparams); | |
7550 | parameter = &call_site->parameter[call_site->parameter_count]; | |
7551 | ||
7552 | /* DW_AT_location specifies the register number. Value of the data | |
7553 | assumed for the register is contained in DW_AT_GNU_call_site_value. */ | |
7554 | ||
7555 | attr = dwarf2_attr (child_die, DW_AT_location, cu); | |
7556 | if (!attr || !attr_form_is_block (attr)) | |
7557 | { | |
7558 | complaint (&symfile_complaints, | |
7559 | _("No DW_FORM_block* DW_AT_location for " | |
7560 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 7561 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
7562 | continue; |
7563 | } | |
7564 | parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data, | |
7565 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]); | |
7566 | if (parameter->dwarf_reg == -1 | |
7567 | && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data, | |
7568 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size], | |
7569 | ¶meter->fb_offset)) | |
7570 | { | |
7571 | complaint (&symfile_complaints, | |
7572 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " | |
7573 | "for DW_FORM_block* DW_AT_location for " | |
7574 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 7575 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
7576 | continue; |
7577 | } | |
7578 | ||
7579 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); | |
7580 | if (!attr_form_is_block (attr)) | |
7581 | { | |
7582 | complaint (&symfile_complaints, | |
7583 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " | |
7584 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 7585 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
7586 | continue; |
7587 | } | |
7588 | parameter->value = DW_BLOCK (attr)->data; | |
7589 | parameter->value_size = DW_BLOCK (attr)->size; | |
7590 | ||
7591 | /* Parameters are not pre-cleared by memset above. */ | |
7592 | parameter->data_value = NULL; | |
7593 | parameter->data_value_size = 0; | |
7594 | call_site->parameter_count++; | |
7595 | ||
7596 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); | |
7597 | if (attr) | |
7598 | { | |
7599 | if (!attr_form_is_block (attr)) | |
7600 | complaint (&symfile_complaints, | |
7601 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " | |
7602 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 7603 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
7604 | else |
7605 | { | |
7606 | parameter->data_value = DW_BLOCK (attr)->data; | |
7607 | parameter->data_value_size = DW_BLOCK (attr)->size; | |
7608 | } | |
7609 | } | |
7610 | } | |
7611 | } | |
7612 | ||
43039443 | 7613 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
7614 | Return 1 if the attributes are present and valid, otherwise, return 0. |
7615 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
7616 | |
7617 | static int | |
7618 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
7619 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
7620 | struct partial_symtab *ranges_pst) | |
43039443 JK |
7621 | { |
7622 | struct objfile *objfile = cu->objfile; | |
7623 | struct comp_unit_head *cu_header = &cu->header; | |
7624 | bfd *obfd = objfile->obfd; | |
7625 | unsigned int addr_size = cu_header->addr_size; | |
7626 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
7627 | /* Base address selection entry. */ | |
7628 | CORE_ADDR base; | |
7629 | int found_base; | |
7630 | unsigned int dummy; | |
7631 | gdb_byte *buffer; | |
7632 | CORE_ADDR marker; | |
7633 | int low_set; | |
7634 | CORE_ADDR low = 0; | |
7635 | CORE_ADDR high = 0; | |
ff013f42 | 7636 | CORE_ADDR baseaddr; |
43039443 | 7637 | |
d00adf39 DE |
7638 | found_base = cu->base_known; |
7639 | base = cu->base_address; | |
43039443 | 7640 | |
be391dca | 7641 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 7642 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
7643 | { |
7644 | complaint (&symfile_complaints, | |
7645 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
7646 | offset); | |
7647 | return 0; | |
7648 | } | |
dce234bc | 7649 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
7650 | |
7651 | /* Read in the largest possible address. */ | |
7652 | marker = read_address (obfd, buffer, cu, &dummy); | |
7653 | if ((marker & mask) == mask) | |
7654 | { | |
7655 | /* If we found the largest possible address, then | |
7656 | read the base address. */ | |
7657 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
7658 | buffer += 2 * addr_size; | |
7659 | offset += 2 * addr_size; | |
7660 | found_base = 1; | |
7661 | } | |
7662 | ||
7663 | low_set = 0; | |
7664 | ||
e7030f15 | 7665 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 7666 | |
43039443 JK |
7667 | while (1) |
7668 | { | |
7669 | CORE_ADDR range_beginning, range_end; | |
7670 | ||
7671 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
7672 | buffer += addr_size; | |
7673 | range_end = read_address (obfd, buffer, cu, &dummy); | |
7674 | buffer += addr_size; | |
7675 | offset += 2 * addr_size; | |
7676 | ||
7677 | /* An end of list marker is a pair of zero addresses. */ | |
7678 | if (range_beginning == 0 && range_end == 0) | |
7679 | /* Found the end of list entry. */ | |
7680 | break; | |
7681 | ||
7682 | /* Each base address selection entry is a pair of 2 values. | |
7683 | The first is the largest possible address, the second is | |
7684 | the base address. Check for a base address here. */ | |
7685 | if ((range_beginning & mask) == mask) | |
7686 | { | |
7687 | /* If we found the largest possible address, then | |
7688 | read the base address. */ | |
7689 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
7690 | found_base = 1; | |
7691 | continue; | |
7692 | } | |
7693 | ||
7694 | if (!found_base) | |
7695 | { | |
7696 | /* We have no valid base address for the ranges | |
7697 | data. */ | |
7698 | complaint (&symfile_complaints, | |
7699 | _("Invalid .debug_ranges data (no base address)")); | |
7700 | return 0; | |
7701 | } | |
7702 | ||
9277c30c UW |
7703 | if (range_beginning > range_end) |
7704 | { | |
7705 | /* Inverted range entries are invalid. */ | |
7706 | complaint (&symfile_complaints, | |
7707 | _("Invalid .debug_ranges data (inverted range)")); | |
7708 | return 0; | |
7709 | } | |
7710 | ||
7711 | /* Empty range entries have no effect. */ | |
7712 | if (range_beginning == range_end) | |
7713 | continue; | |
7714 | ||
43039443 JK |
7715 | range_beginning += base; |
7716 | range_end += base; | |
7717 | ||
9277c30c | 7718 | if (ranges_pst != NULL) |
ff013f42 | 7719 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
7720 | range_beginning + baseaddr, |
7721 | range_end - 1 + baseaddr, | |
ff013f42 JK |
7722 | ranges_pst); |
7723 | ||
43039443 JK |
7724 | /* FIXME: This is recording everything as a low-high |
7725 | segment of consecutive addresses. We should have a | |
7726 | data structure for discontiguous block ranges | |
7727 | instead. */ | |
7728 | if (! low_set) | |
7729 | { | |
7730 | low = range_beginning; | |
7731 | high = range_end; | |
7732 | low_set = 1; | |
7733 | } | |
7734 | else | |
7735 | { | |
7736 | if (range_beginning < low) | |
7737 | low = range_beginning; | |
7738 | if (range_end > high) | |
7739 | high = range_end; | |
7740 | } | |
7741 | } | |
7742 | ||
7743 | if (! low_set) | |
7744 | /* If the first entry is an end-of-list marker, the range | |
7745 | describes an empty scope, i.e. no instructions. */ | |
7746 | return 0; | |
7747 | ||
7748 | if (low_return) | |
7749 | *low_return = low; | |
7750 | if (high_return) | |
7751 | *high_return = high; | |
7752 | return 1; | |
7753 | } | |
7754 | ||
af34e669 DJ |
7755 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
7756 | are present and valid, otherwise, return 0. Return -1 if the range is | |
7757 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
380bca97 | 7758 | |
c906108c | 7759 | static int |
af34e669 | 7760 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
7761 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
7762 | struct partial_symtab *pst) | |
c906108c SS |
7763 | { |
7764 | struct attribute *attr; | |
91da1414 | 7765 | struct attribute *attr_high; |
af34e669 DJ |
7766 | CORE_ADDR low = 0; |
7767 | CORE_ADDR high = 0; | |
7768 | int ret = 0; | |
c906108c | 7769 | |
91da1414 MW |
7770 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
7771 | if (attr_high) | |
af34e669 | 7772 | { |
e142c38c | 7773 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 | 7774 | if (attr) |
91da1414 MW |
7775 | { |
7776 | low = DW_ADDR (attr); | |
3019eac3 DE |
7777 | if (attr_high->form == DW_FORM_addr |
7778 | || attr_high->form == DW_FORM_GNU_addr_index) | |
91da1414 MW |
7779 | high = DW_ADDR (attr_high); |
7780 | else | |
7781 | high = low + DW_UNSND (attr_high); | |
7782 | } | |
af34e669 DJ |
7783 | else |
7784 | /* Found high w/o low attribute. */ | |
7785 | return 0; | |
7786 | ||
7787 | /* Found consecutive range of addresses. */ | |
7788 | ret = 1; | |
7789 | } | |
c906108c | 7790 | else |
af34e669 | 7791 | { |
e142c38c | 7792 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
7793 | if (attr != NULL) |
7794 | { | |
af34e669 | 7795 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 7796 | .debug_ranges section. */ |
d85a05f0 | 7797 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 7798 | return 0; |
43039443 | 7799 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
7800 | ret = -1; |
7801 | } | |
7802 | } | |
c906108c | 7803 | |
9373cf26 JK |
7804 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
7805 | if (high <= low) | |
c906108c SS |
7806 | return 0; |
7807 | ||
7808 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
7809 | eliminate duplicate copies of functions and vtables and such. | |
7810 | The linker will arbitrarily choose one and discard the others. | |
7811 | The AT_*_pc values for such functions refer to local labels in | |
7812 | these sections. If the section from that file was discarded, the | |
7813 | labels are not in the output, so the relocs get a value of 0. | |
7814 | If this is a discarded function, mark the pc bounds as invalid, | |
7815 | so that GDB will ignore it. */ | |
72dca2f5 | 7816 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
7817 | return 0; |
7818 | ||
7819 | *lowpc = low; | |
96408a79 SA |
7820 | if (highpc) |
7821 | *highpc = high; | |
af34e669 | 7822 | return ret; |
c906108c SS |
7823 | } |
7824 | ||
b084d499 JB |
7825 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
7826 | its low and high PC addresses. Do nothing if these addresses could not | |
7827 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
7828 | and HIGHPC to the high address if greater than HIGHPC. */ | |
7829 | ||
7830 | static void | |
7831 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
7832 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
7833 | struct dwarf2_cu *cu) | |
7834 | { | |
7835 | CORE_ADDR low, high; | |
7836 | struct die_info *child = die->child; | |
7837 | ||
d85a05f0 | 7838 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
7839 | { |
7840 | *lowpc = min (*lowpc, low); | |
7841 | *highpc = max (*highpc, high); | |
7842 | } | |
7843 | ||
7844 | /* If the language does not allow nested subprograms (either inside | |
7845 | subprograms or lexical blocks), we're done. */ | |
7846 | if (cu->language != language_ada) | |
7847 | return; | |
6e70227d | 7848 | |
b084d499 JB |
7849 | /* Check all the children of the given DIE. If it contains nested |
7850 | subprograms, then check their pc bounds. Likewise, we need to | |
7851 | check lexical blocks as well, as they may also contain subprogram | |
7852 | definitions. */ | |
7853 | while (child && child->tag) | |
7854 | { | |
7855 | if (child->tag == DW_TAG_subprogram | |
7856 | || child->tag == DW_TAG_lexical_block) | |
7857 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
7858 | child = sibling_die (child); | |
7859 | } | |
7860 | } | |
7861 | ||
fae299cd DC |
7862 | /* Get the low and high pc's represented by the scope DIE, and store |
7863 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
7864 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
7865 | ||
7866 | static void | |
7867 | get_scope_pc_bounds (struct die_info *die, | |
7868 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
7869 | struct dwarf2_cu *cu) | |
7870 | { | |
7871 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
7872 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
7873 | CORE_ADDR current_low, current_high; | |
7874 | ||
d85a05f0 | 7875 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
7876 | { |
7877 | best_low = current_low; | |
7878 | best_high = current_high; | |
7879 | } | |
7880 | else | |
7881 | { | |
7882 | struct die_info *child = die->child; | |
7883 | ||
7884 | while (child && child->tag) | |
7885 | { | |
7886 | switch (child->tag) { | |
7887 | case DW_TAG_subprogram: | |
b084d499 | 7888 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
7889 | break; |
7890 | case DW_TAG_namespace: | |
f55ee35c | 7891 | case DW_TAG_module: |
fae299cd DC |
7892 | /* FIXME: carlton/2004-01-16: Should we do this for |
7893 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
7894 | that current GCC's always emit the DIEs corresponding | |
7895 | to definitions of methods of classes as children of a | |
7896 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
7897 | the DIEs giving the declarations, which could be | |
7898 | anywhere). But I don't see any reason why the | |
7899 | standards says that they have to be there. */ | |
7900 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
7901 | ||
7902 | if (current_low != ((CORE_ADDR) -1)) | |
7903 | { | |
7904 | best_low = min (best_low, current_low); | |
7905 | best_high = max (best_high, current_high); | |
7906 | } | |
7907 | break; | |
7908 | default: | |
0963b4bd | 7909 | /* Ignore. */ |
fae299cd DC |
7910 | break; |
7911 | } | |
7912 | ||
7913 | child = sibling_die (child); | |
7914 | } | |
7915 | } | |
7916 | ||
7917 | *lowpc = best_low; | |
7918 | *highpc = best_high; | |
7919 | } | |
7920 | ||
801e3a5b JB |
7921 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
7922 | in DIE. */ | |
380bca97 | 7923 | |
801e3a5b JB |
7924 | static void |
7925 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
7926 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
7927 | { | |
bb5ed363 | 7928 | struct objfile *objfile = cu->objfile; |
801e3a5b | 7929 | struct attribute *attr; |
91da1414 | 7930 | struct attribute *attr_high; |
801e3a5b | 7931 | |
91da1414 MW |
7932 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
7933 | if (attr_high) | |
801e3a5b | 7934 | { |
801e3a5b JB |
7935 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
7936 | if (attr) | |
7937 | { | |
7938 | CORE_ADDR low = DW_ADDR (attr); | |
91da1414 | 7939 | CORE_ADDR high; |
3019eac3 DE |
7940 | if (attr_high->form == DW_FORM_addr |
7941 | || attr_high->form == DW_FORM_GNU_addr_index) | |
91da1414 MW |
7942 | high = DW_ADDR (attr_high); |
7943 | else | |
7944 | high = low + DW_UNSND (attr_high); | |
9a619af0 | 7945 | |
801e3a5b JB |
7946 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
7947 | } | |
7948 | } | |
7949 | ||
7950 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
7951 | if (attr) | |
7952 | { | |
bb5ed363 | 7953 | bfd *obfd = objfile->obfd; |
801e3a5b JB |
7954 | |
7955 | /* The value of the DW_AT_ranges attribute is the offset of the | |
7956 | address range list in the .debug_ranges section. */ | |
7957 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 7958 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
7959 | |
7960 | /* For some target architectures, but not others, the | |
7961 | read_address function sign-extends the addresses it returns. | |
7962 | To recognize base address selection entries, we need a | |
7963 | mask. */ | |
7964 | unsigned int addr_size = cu->header.addr_size; | |
7965 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
7966 | ||
7967 | /* The base address, to which the next pair is relative. Note | |
7968 | that this 'base' is a DWARF concept: most entries in a range | |
7969 | list are relative, to reduce the number of relocs against the | |
7970 | debugging information. This is separate from this function's | |
7971 | 'baseaddr' argument, which GDB uses to relocate debugging | |
7972 | information from a shared library based on the address at | |
7973 | which the library was loaded. */ | |
d00adf39 DE |
7974 | CORE_ADDR base = cu->base_address; |
7975 | int base_known = cu->base_known; | |
801e3a5b | 7976 | |
be391dca | 7977 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 7978 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
7979 | { |
7980 | complaint (&symfile_complaints, | |
7981 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
7982 | offset); | |
7983 | return; | |
7984 | } | |
7985 | ||
7986 | for (;;) | |
7987 | { | |
7988 | unsigned int bytes_read; | |
7989 | CORE_ADDR start, end; | |
7990 | ||
7991 | start = read_address (obfd, buffer, cu, &bytes_read); | |
7992 | buffer += bytes_read; | |
7993 | end = read_address (obfd, buffer, cu, &bytes_read); | |
7994 | buffer += bytes_read; | |
7995 | ||
7996 | /* Did we find the end of the range list? */ | |
7997 | if (start == 0 && end == 0) | |
7998 | break; | |
7999 | ||
8000 | /* Did we find a base address selection entry? */ | |
8001 | else if ((start & base_select_mask) == base_select_mask) | |
8002 | { | |
8003 | base = end; | |
8004 | base_known = 1; | |
8005 | } | |
8006 | ||
8007 | /* We found an ordinary address range. */ | |
8008 | else | |
8009 | { | |
8010 | if (!base_known) | |
8011 | { | |
8012 | complaint (&symfile_complaints, | |
3e43a32a MS |
8013 | _("Invalid .debug_ranges data " |
8014 | "(no base address)")); | |
801e3a5b JB |
8015 | return; |
8016 | } | |
8017 | ||
9277c30c UW |
8018 | if (start > end) |
8019 | { | |
8020 | /* Inverted range entries are invalid. */ | |
8021 | complaint (&symfile_complaints, | |
8022 | _("Invalid .debug_ranges data " | |
8023 | "(inverted range)")); | |
8024 | return; | |
8025 | } | |
8026 | ||
8027 | /* Empty range entries have no effect. */ | |
8028 | if (start == end) | |
8029 | continue; | |
8030 | ||
6e70227d DE |
8031 | record_block_range (block, |
8032 | baseaddr + base + start, | |
801e3a5b JB |
8033 | baseaddr + base + end - 1); |
8034 | } | |
8035 | } | |
8036 | } | |
8037 | } | |
8038 | ||
60d5a603 JK |
8039 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
8040 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
8041 | during 4.6.0 experimental. */ | |
8042 | ||
8043 | static int | |
8044 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
8045 | { | |
8046 | const char *cs; | |
8047 | int major, minor, release; | |
ba919b58 | 8048 | int result = 0; |
60d5a603 JK |
8049 | |
8050 | if (cu->producer == NULL) | |
8051 | { | |
8052 | /* For unknown compilers expect their behavior is DWARF version | |
8053 | compliant. | |
8054 | ||
8055 | GCC started to support .debug_types sections by -gdwarf-4 since | |
8056 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
8057 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
8058 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
8059 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
8060 | ||
8061 | return 0; | |
8062 | } | |
8063 | ||
ba919b58 TT |
8064 | if (cu->checked_producer) |
8065 | return cu->producer_is_gxx_lt_4_6; | |
8066 | ||
60d5a603 JK |
8067 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ |
8068 | ||
8069 | if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) | |
8070 | { | |
8071 | /* For non-GCC compilers expect their behavior is DWARF version | |
8072 | compliant. */ | |
60d5a603 | 8073 | } |
ba919b58 | 8074 | else |
60d5a603 | 8075 | { |
ba919b58 TT |
8076 | cs = &cu->producer[strlen ("GNU ")]; |
8077 | while (*cs && !isdigit (*cs)) | |
8078 | cs++; | |
8079 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) | |
8080 | { | |
8081 | /* Not recognized as GCC. */ | |
8082 | } | |
8083 | else | |
8084 | result = major < 4 || (major == 4 && minor < 6); | |
60d5a603 JK |
8085 | } |
8086 | ||
ba919b58 TT |
8087 | cu->checked_producer = 1; |
8088 | cu->producer_is_gxx_lt_4_6 = result; | |
8089 | ||
8090 | return result; | |
60d5a603 JK |
8091 | } |
8092 | ||
8093 | /* Return the default accessibility type if it is not overriden by | |
8094 | DW_AT_accessibility. */ | |
8095 | ||
8096 | static enum dwarf_access_attribute | |
8097 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
8098 | { | |
8099 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
8100 | { | |
8101 | /* The default DWARF 2 accessibility for members is public, the default | |
8102 | accessibility for inheritance is private. */ | |
8103 | ||
8104 | if (die->tag != DW_TAG_inheritance) | |
8105 | return DW_ACCESS_public; | |
8106 | else | |
8107 | return DW_ACCESS_private; | |
8108 | } | |
8109 | else | |
8110 | { | |
8111 | /* DWARF 3+ defines the default accessibility a different way. The same | |
8112 | rules apply now for DW_TAG_inheritance as for the members and it only | |
8113 | depends on the container kind. */ | |
8114 | ||
8115 | if (die->parent->tag == DW_TAG_class_type) | |
8116 | return DW_ACCESS_private; | |
8117 | else | |
8118 | return DW_ACCESS_public; | |
8119 | } | |
8120 | } | |
8121 | ||
74ac6d43 TT |
8122 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
8123 | offset. If the attribute was not found return 0, otherwise return | |
8124 | 1. If it was found but could not properly be handled, set *OFFSET | |
8125 | to 0. */ | |
8126 | ||
8127 | static int | |
8128 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
8129 | LONGEST *offset) | |
8130 | { | |
8131 | struct attribute *attr; | |
8132 | ||
8133 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
8134 | if (attr != NULL) | |
8135 | { | |
8136 | *offset = 0; | |
8137 | ||
8138 | /* Note that we do not check for a section offset first here. | |
8139 | This is because DW_AT_data_member_location is new in DWARF 4, | |
8140 | so if we see it, we can assume that a constant form is really | |
8141 | a constant and not a section offset. */ | |
8142 | if (attr_form_is_constant (attr)) | |
8143 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
8144 | else if (attr_form_is_section_offset (attr)) | |
8145 | dwarf2_complex_location_expr_complaint (); | |
8146 | else if (attr_form_is_block (attr)) | |
8147 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
8148 | else | |
8149 | dwarf2_complex_location_expr_complaint (); | |
8150 | ||
8151 | return 1; | |
8152 | } | |
8153 | ||
8154 | return 0; | |
8155 | } | |
8156 | ||
c906108c SS |
8157 | /* Add an aggregate field to the field list. */ |
8158 | ||
8159 | static void | |
107d2387 | 8160 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 8161 | struct dwarf2_cu *cu) |
6e70227d | 8162 | { |
e7c27a73 | 8163 | struct objfile *objfile = cu->objfile; |
5e2b427d | 8164 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
8165 | struct nextfield *new_field; |
8166 | struct attribute *attr; | |
8167 | struct field *fp; | |
8168 | char *fieldname = ""; | |
8169 | ||
8170 | /* Allocate a new field list entry and link it in. */ | |
8171 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 8172 | make_cleanup (xfree, new_field); |
c906108c | 8173 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
8174 | |
8175 | if (die->tag == DW_TAG_inheritance) | |
8176 | { | |
8177 | new_field->next = fip->baseclasses; | |
8178 | fip->baseclasses = new_field; | |
8179 | } | |
8180 | else | |
8181 | { | |
8182 | new_field->next = fip->fields; | |
8183 | fip->fields = new_field; | |
8184 | } | |
c906108c SS |
8185 | fip->nfields++; |
8186 | ||
e142c38c | 8187 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
8188 | if (attr) |
8189 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
8190 | else |
8191 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
8192 | if (new_field->accessibility != DW_ACCESS_public) |
8193 | fip->non_public_fields = 1; | |
60d5a603 | 8194 | |
e142c38c | 8195 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
8196 | if (attr) |
8197 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
8198 | else |
8199 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
8200 | |
8201 | fp = &new_field->field; | |
a9a9bd0f | 8202 | |
e142c38c | 8203 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 8204 | { |
74ac6d43 TT |
8205 | LONGEST offset; |
8206 | ||
a9a9bd0f | 8207 | /* Data member other than a C++ static data member. */ |
6e70227d | 8208 | |
c906108c | 8209 | /* Get type of field. */ |
e7c27a73 | 8210 | fp->type = die_type (die, cu); |
c906108c | 8211 | |
d6a843b5 | 8212 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 8213 | |
c906108c | 8214 | /* Get bit size of field (zero if none). */ |
e142c38c | 8215 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
8216 | if (attr) |
8217 | { | |
8218 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
8219 | } | |
8220 | else | |
8221 | { | |
8222 | FIELD_BITSIZE (*fp) = 0; | |
8223 | } | |
8224 | ||
8225 | /* Get bit offset of field. */ | |
74ac6d43 TT |
8226 | if (handle_data_member_location (die, cu, &offset)) |
8227 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 8228 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
8229 | if (attr) |
8230 | { | |
5e2b427d | 8231 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
8232 | { |
8233 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
8234 | additional bit offset from the MSB of the containing |
8235 | anonymous object to the MSB of the field. We don't | |
8236 | have to do anything special since we don't need to | |
8237 | know the size of the anonymous object. */ | |
f41f5e61 | 8238 | SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr)); |
c906108c SS |
8239 | } |
8240 | else | |
8241 | { | |
8242 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
8243 | MSB of the anonymous object, subtract off the number of |
8244 | bits from the MSB of the field to the MSB of the | |
8245 | object, and then subtract off the number of bits of | |
8246 | the field itself. The result is the bit offset of | |
8247 | the LSB of the field. */ | |
c906108c SS |
8248 | int anonymous_size; |
8249 | int bit_offset = DW_UNSND (attr); | |
8250 | ||
e142c38c | 8251 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8252 | if (attr) |
8253 | { | |
8254 | /* The size of the anonymous object containing | |
8255 | the bit field is explicit, so use the | |
8256 | indicated size (in bytes). */ | |
8257 | anonymous_size = DW_UNSND (attr); | |
8258 | } | |
8259 | else | |
8260 | { | |
8261 | /* The size of the anonymous object containing | |
8262 | the bit field must be inferred from the type | |
8263 | attribute of the data member containing the | |
8264 | bit field. */ | |
8265 | anonymous_size = TYPE_LENGTH (fp->type); | |
8266 | } | |
f41f5e61 PA |
8267 | SET_FIELD_BITPOS (*fp, |
8268 | (FIELD_BITPOS (*fp) | |
8269 | + anonymous_size * bits_per_byte | |
8270 | - bit_offset - FIELD_BITSIZE (*fp))); | |
c906108c SS |
8271 | } |
8272 | } | |
8273 | ||
8274 | /* Get name of field. */ | |
39cbfefa DJ |
8275 | fieldname = dwarf2_name (die, cu); |
8276 | if (fieldname == NULL) | |
8277 | fieldname = ""; | |
d8151005 DJ |
8278 | |
8279 | /* The name is already allocated along with this objfile, so we don't | |
8280 | need to duplicate it for the type. */ | |
8281 | fp->name = fieldname; | |
c906108c SS |
8282 | |
8283 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 8284 | pointer or virtual base class pointer) to private. */ |
e142c38c | 8285 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 8286 | { |
d48cc9dd | 8287 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
8288 | new_field->accessibility = DW_ACCESS_private; |
8289 | fip->non_public_fields = 1; | |
8290 | } | |
8291 | } | |
a9a9bd0f | 8292 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 8293 | { |
a9a9bd0f DC |
8294 | /* C++ static member. */ |
8295 | ||
8296 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
8297 | is a declaration, but all versions of G++ as of this writing | |
8298 | (so through at least 3.2.1) incorrectly generate | |
8299 | DW_TAG_variable tags. */ | |
6e70227d | 8300 | |
ff355380 | 8301 | const char *physname; |
c906108c | 8302 | |
a9a9bd0f | 8303 | /* Get name of field. */ |
39cbfefa DJ |
8304 | fieldname = dwarf2_name (die, cu); |
8305 | if (fieldname == NULL) | |
c906108c SS |
8306 | return; |
8307 | ||
254e6b9e | 8308 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
8309 | if (attr |
8310 | /* Only create a symbol if this is an external value. | |
8311 | new_symbol checks this and puts the value in the global symbol | |
8312 | table, which we want. If it is not external, new_symbol | |
8313 | will try to put the value in cu->list_in_scope which is wrong. */ | |
8314 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
8315 | { |
8316 | /* A static const member, not much different than an enum as far as | |
8317 | we're concerned, except that we can support more types. */ | |
8318 | new_symbol (die, NULL, cu); | |
8319 | } | |
8320 | ||
2df3850c | 8321 | /* Get physical name. */ |
ff355380 | 8322 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 8323 | |
d8151005 DJ |
8324 | /* The name is already allocated along with this objfile, so we don't |
8325 | need to duplicate it for the type. */ | |
8326 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 8327 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 8328 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
8329 | } |
8330 | else if (die->tag == DW_TAG_inheritance) | |
8331 | { | |
74ac6d43 | 8332 | LONGEST offset; |
d4b96c9a | 8333 | |
74ac6d43 TT |
8334 | /* C++ base class field. */ |
8335 | if (handle_data_member_location (die, cu, &offset)) | |
8336 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 8337 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 8338 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
8339 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
8340 | fip->nbaseclasses++; | |
8341 | } | |
8342 | } | |
8343 | ||
98751a41 JK |
8344 | /* Add a typedef defined in the scope of the FIP's class. */ |
8345 | ||
8346 | static void | |
8347 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
8348 | struct dwarf2_cu *cu) | |
6e70227d | 8349 | { |
98751a41 | 8350 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
8351 | struct typedef_field_list *new_field; |
8352 | struct attribute *attr; | |
8353 | struct typedef_field *fp; | |
8354 | char *fieldname = ""; | |
8355 | ||
8356 | /* Allocate a new field list entry and link it in. */ | |
8357 | new_field = xzalloc (sizeof (*new_field)); | |
8358 | make_cleanup (xfree, new_field); | |
8359 | ||
8360 | gdb_assert (die->tag == DW_TAG_typedef); | |
8361 | ||
8362 | fp = &new_field->field; | |
8363 | ||
8364 | /* Get name of field. */ | |
8365 | fp->name = dwarf2_name (die, cu); | |
8366 | if (fp->name == NULL) | |
8367 | return; | |
8368 | ||
8369 | fp->type = read_type_die (die, cu); | |
8370 | ||
8371 | new_field->next = fip->typedef_field_list; | |
8372 | fip->typedef_field_list = new_field; | |
8373 | fip->typedef_field_list_count++; | |
8374 | } | |
8375 | ||
c906108c SS |
8376 | /* Create the vector of fields, and attach it to the type. */ |
8377 | ||
8378 | static void | |
fba45db2 | 8379 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 8380 | struct dwarf2_cu *cu) |
c906108c SS |
8381 | { |
8382 | int nfields = fip->nfields; | |
8383 | ||
8384 | /* Record the field count, allocate space for the array of fields, | |
8385 | and create blank accessibility bitfields if necessary. */ | |
8386 | TYPE_NFIELDS (type) = nfields; | |
8387 | TYPE_FIELDS (type) = (struct field *) | |
8388 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
8389 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
8390 | ||
b4ba55a1 | 8391 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
8392 | { |
8393 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
8394 | ||
8395 | TYPE_FIELD_PRIVATE_BITS (type) = | |
8396 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
8397 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
8398 | ||
8399 | TYPE_FIELD_PROTECTED_BITS (type) = | |
8400 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
8401 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
8402 | ||
774b6a14 TT |
8403 | TYPE_FIELD_IGNORE_BITS (type) = |
8404 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
8405 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
8406 | } |
8407 | ||
8408 | /* If the type has baseclasses, allocate and clear a bit vector for | |
8409 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 8410 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
8411 | { |
8412 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 8413 | unsigned char *pointer; |
c906108c SS |
8414 | |
8415 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
8416 | pointer = TYPE_ALLOC (type, num_bytes); |
8417 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
8418 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
8419 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
8420 | } | |
8421 | ||
3e43a32a MS |
8422 | /* Copy the saved-up fields into the field vector. Start from the head of |
8423 | the list, adding to the tail of the field array, so that they end up in | |
8424 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
8425 | while (nfields-- > 0) |
8426 | { | |
7d0ccb61 DJ |
8427 | struct nextfield *fieldp; |
8428 | ||
8429 | if (fip->fields) | |
8430 | { | |
8431 | fieldp = fip->fields; | |
8432 | fip->fields = fieldp->next; | |
8433 | } | |
8434 | else | |
8435 | { | |
8436 | fieldp = fip->baseclasses; | |
8437 | fip->baseclasses = fieldp->next; | |
8438 | } | |
8439 | ||
8440 | TYPE_FIELD (type, nfields) = fieldp->field; | |
8441 | switch (fieldp->accessibility) | |
c906108c | 8442 | { |
c5aa993b | 8443 | case DW_ACCESS_private: |
b4ba55a1 JB |
8444 | if (cu->language != language_ada) |
8445 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 8446 | break; |
c906108c | 8447 | |
c5aa993b | 8448 | case DW_ACCESS_protected: |
b4ba55a1 JB |
8449 | if (cu->language != language_ada) |
8450 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 8451 | break; |
c906108c | 8452 | |
c5aa993b JM |
8453 | case DW_ACCESS_public: |
8454 | break; | |
c906108c | 8455 | |
c5aa993b JM |
8456 | default: |
8457 | /* Unknown accessibility. Complain and treat it as public. */ | |
8458 | { | |
e2e0b3e5 | 8459 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 8460 | fieldp->accessibility); |
c5aa993b JM |
8461 | } |
8462 | break; | |
c906108c SS |
8463 | } |
8464 | if (nfields < fip->nbaseclasses) | |
8465 | { | |
7d0ccb61 | 8466 | switch (fieldp->virtuality) |
c906108c | 8467 | { |
c5aa993b JM |
8468 | case DW_VIRTUALITY_virtual: |
8469 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 8470 | if (cu->language == language_ada) |
a73c6dcd | 8471 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
8472 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
8473 | break; | |
c906108c SS |
8474 | } |
8475 | } | |
c906108c SS |
8476 | } |
8477 | } | |
8478 | ||
c906108c SS |
8479 | /* Add a member function to the proper fieldlist. */ |
8480 | ||
8481 | static void | |
107d2387 | 8482 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 8483 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 8484 | { |
e7c27a73 | 8485 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8486 | struct attribute *attr; |
8487 | struct fnfieldlist *flp; | |
8488 | int i; | |
8489 | struct fn_field *fnp; | |
8490 | char *fieldname; | |
c906108c | 8491 | struct nextfnfield *new_fnfield; |
f792889a | 8492 | struct type *this_type; |
60d5a603 | 8493 | enum dwarf_access_attribute accessibility; |
c906108c | 8494 | |
b4ba55a1 | 8495 | if (cu->language == language_ada) |
a73c6dcd | 8496 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 8497 | |
2df3850c | 8498 | /* Get name of member function. */ |
39cbfefa DJ |
8499 | fieldname = dwarf2_name (die, cu); |
8500 | if (fieldname == NULL) | |
2df3850c | 8501 | return; |
c906108c | 8502 | |
c906108c SS |
8503 | /* Look up member function name in fieldlist. */ |
8504 | for (i = 0; i < fip->nfnfields; i++) | |
8505 | { | |
27bfe10e | 8506 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
8507 | break; |
8508 | } | |
8509 | ||
8510 | /* Create new list element if necessary. */ | |
8511 | if (i < fip->nfnfields) | |
8512 | flp = &fip->fnfieldlists[i]; | |
8513 | else | |
8514 | { | |
8515 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
8516 | { | |
8517 | fip->fnfieldlists = (struct fnfieldlist *) | |
8518 | xrealloc (fip->fnfieldlists, | |
8519 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 8520 | * sizeof (struct fnfieldlist)); |
c906108c | 8521 | if (fip->nfnfields == 0) |
c13c43fd | 8522 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
8523 | } |
8524 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
8525 | flp->name = fieldname; | |
8526 | flp->length = 0; | |
8527 | flp->head = NULL; | |
3da10d80 | 8528 | i = fip->nfnfields++; |
c906108c SS |
8529 | } |
8530 | ||
8531 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 8532 | entry. */ |
c906108c | 8533 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 8534 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
8535 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
8536 | new_fnfield->next = flp->head; | |
8537 | flp->head = new_fnfield; | |
8538 | flp->length++; | |
8539 | ||
8540 | /* Fill in the member function field info. */ | |
8541 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
8542 | |
8543 | /* Delay processing of the physname until later. */ | |
8544 | if (cu->language == language_cplus || cu->language == language_java) | |
8545 | { | |
8546 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
8547 | die, cu); | |
8548 | } | |
8549 | else | |
8550 | { | |
1d06ead6 | 8551 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
8552 | fnp->physname = physname ? physname : ""; |
8553 | } | |
8554 | ||
c906108c | 8555 | fnp->type = alloc_type (objfile); |
f792889a DJ |
8556 | this_type = read_type_die (die, cu); |
8557 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 8558 | { |
f792889a | 8559 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 8560 | |
f792889a | 8561 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
8562 | of the method itself (TYPE_CODE_METHOD). */ |
8563 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
8564 | TYPE_TARGET_TYPE (this_type), |
8565 | TYPE_FIELDS (this_type), | |
8566 | TYPE_NFIELDS (this_type), | |
8567 | TYPE_VARARGS (this_type)); | |
c906108c SS |
8568 | |
8569 | /* Handle static member functions. | |
c5aa993b | 8570 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
8571 | member functions. G++ helps GDB by marking the first |
8572 | parameter for non-static member functions (which is the this | |
8573 | pointer) as artificial. We obtain this information from | |
8574 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 8575 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
8576 | fnp->voffset = VOFFSET_STATIC; |
8577 | } | |
8578 | else | |
e2e0b3e5 | 8579 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 8580 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
8581 | |
8582 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 8583 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 8584 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 8585 | |
3e43a32a MS |
8586 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
8587 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
8588 | |
8589 | /* Get accessibility. */ | |
e142c38c | 8590 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 8591 | if (attr) |
60d5a603 JK |
8592 | accessibility = DW_UNSND (attr); |
8593 | else | |
8594 | accessibility = dwarf2_default_access_attribute (die, cu); | |
8595 | switch (accessibility) | |
c906108c | 8596 | { |
60d5a603 JK |
8597 | case DW_ACCESS_private: |
8598 | fnp->is_private = 1; | |
8599 | break; | |
8600 | case DW_ACCESS_protected: | |
8601 | fnp->is_protected = 1; | |
8602 | break; | |
c906108c SS |
8603 | } |
8604 | ||
b02dede2 | 8605 | /* Check for artificial methods. */ |
e142c38c | 8606 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
8607 | if (attr && DW_UNSND (attr) != 0) |
8608 | fnp->is_artificial = 1; | |
8609 | ||
0d564a31 | 8610 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
8611 | function. For older versions of GCC, this is an offset in the |
8612 | appropriate virtual table, as specified by DW_AT_containing_type. | |
8613 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
8614 | to the object address. */ |
8615 | ||
e142c38c | 8616 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 8617 | if (attr) |
8e19ed76 | 8618 | { |
aec5aa8b | 8619 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 8620 | { |
aec5aa8b TT |
8621 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
8622 | { | |
8623 | /* Old-style GCC. */ | |
8624 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
8625 | } | |
8626 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
8627 | || (DW_BLOCK (attr)->size > 1 | |
8628 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
8629 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
8630 | { | |
8631 | struct dwarf_block blk; | |
8632 | int offset; | |
8633 | ||
8634 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
8635 | ? 1 : 2); | |
8636 | blk.size = DW_BLOCK (attr)->size - offset; | |
8637 | blk.data = DW_BLOCK (attr)->data + offset; | |
8638 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
8639 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
8640 | dwarf2_complex_location_expr_complaint (); | |
8641 | else | |
8642 | fnp->voffset /= cu->header.addr_size; | |
8643 | fnp->voffset += 2; | |
8644 | } | |
8645 | else | |
8646 | dwarf2_complex_location_expr_complaint (); | |
8647 | ||
8648 | if (!fnp->fcontext) | |
8649 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
8650 | } | |
3690dd37 | 8651 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 8652 | { |
4d3c2250 | 8653 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8654 | } |
8655 | else | |
8656 | { | |
4d3c2250 KB |
8657 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
8658 | fieldname); | |
8e19ed76 | 8659 | } |
0d564a31 | 8660 | } |
d48cc9dd DJ |
8661 | else |
8662 | { | |
8663 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
8664 | if (attr && DW_UNSND (attr)) | |
8665 | { | |
8666 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
8667 | complaint (&symfile_complaints, | |
3e43a32a MS |
8668 | _("Member function \"%s\" (offset %d) is virtual " |
8669 | "but the vtable offset is not specified"), | |
b64f50a1 | 8670 | fieldname, die->offset.sect_off); |
9655fd1a | 8671 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
8672 | TYPE_CPLUS_DYNAMIC (type) = 1; |
8673 | } | |
8674 | } | |
c906108c SS |
8675 | } |
8676 | ||
8677 | /* Create the vector of member function fields, and attach it to the type. */ | |
8678 | ||
8679 | static void | |
fba45db2 | 8680 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 8681 | struct dwarf2_cu *cu) |
c906108c SS |
8682 | { |
8683 | struct fnfieldlist *flp; | |
c906108c SS |
8684 | int i; |
8685 | ||
b4ba55a1 | 8686 | if (cu->language == language_ada) |
a73c6dcd | 8687 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 8688 | |
c906108c SS |
8689 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
8690 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
8691 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
8692 | ||
8693 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
8694 | { | |
8695 | struct nextfnfield *nfp = flp->head; | |
8696 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
8697 | int k; | |
8698 | ||
8699 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
8700 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
8701 | fn_flp->fn_fields = (struct fn_field *) | |
8702 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
8703 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 8704 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
8705 | } |
8706 | ||
8707 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
c906108c SS |
8708 | } |
8709 | ||
1168df01 JB |
8710 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
8711 | language, zero otherwise. */ | |
8712 | static int | |
8713 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
8714 | { | |
8715 | static const char vptr[] = "_vptr"; | |
987504bb | 8716 | static const char vtable[] = "vtable"; |
1168df01 | 8717 | |
987504bb JJ |
8718 | /* Look for the C++ and Java forms of the vtable. */ |
8719 | if ((cu->language == language_java | |
8720 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
8721 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
8722 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
8723 | return 1; |
8724 | ||
8725 | return 0; | |
8726 | } | |
8727 | ||
c0dd20ea | 8728 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
8729 | functions, with the ABI-specified layout. If TYPE describes |
8730 | such a structure, smash it into a member function type. | |
61049d3b DJ |
8731 | |
8732 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
8733 | This is GCC PR debug/28767. */ | |
c0dd20ea | 8734 | |
0b92b5bb TT |
8735 | static void |
8736 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 8737 | { |
0b92b5bb | 8738 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
8739 | |
8740 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
8741 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
8742 | return; | |
c0dd20ea DJ |
8743 | |
8744 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
8745 | if (TYPE_FIELD_NAME (type, 0) == NULL |
8746 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
8747 | || TYPE_FIELD_NAME (type, 1) == NULL | |
8748 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
8749 | return; | |
c0dd20ea DJ |
8750 | |
8751 | /* Find the type of the method. */ | |
0b92b5bb | 8752 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
8753 | if (pfn_type == NULL |
8754 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
8755 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 8756 | return; |
c0dd20ea DJ |
8757 | |
8758 | /* Look for the "this" argument. */ | |
8759 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
8760 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 8761 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 8762 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 8763 | return; |
c0dd20ea DJ |
8764 | |
8765 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
8766 | new_type = alloc_type (objfile); |
8767 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
8768 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
8769 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 8770 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 8771 | } |
1168df01 | 8772 | |
c906108c | 8773 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
8774 | (definition) to create a type for the structure or union. Fill in |
8775 | the type's name and general properties; the members will not be | |
8776 | processed until process_structure_type. | |
c906108c | 8777 | |
c767944b DJ |
8778 | NOTE: we need to call these functions regardless of whether or not the |
8779 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
8780 | structure or union. This gets the type entered into our set of |
8781 | user defined types. | |
8782 | ||
8783 | However, if the structure is incomplete (an opaque struct/union) | |
8784 | then suppress creating a symbol table entry for it since gdb only | |
8785 | wants to find the one with the complete definition. Note that if | |
8786 | it is complete, we just call new_symbol, which does it's own | |
8787 | checking about whether the struct/union is anonymous or not (and | |
8788 | suppresses creating a symbol table entry itself). */ | |
8789 | ||
f792889a | 8790 | static struct type * |
134d01f1 | 8791 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8792 | { |
e7c27a73 | 8793 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8794 | struct type *type; |
8795 | struct attribute *attr; | |
39cbfefa | 8796 | char *name; |
c906108c | 8797 | |
348e048f DE |
8798 | /* If the definition of this type lives in .debug_types, read that type. |
8799 | Don't follow DW_AT_specification though, that will take us back up | |
8800 | the chain and we want to go down. */ | |
8801 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
8802 | if (attr) | |
8803 | { | |
8804 | struct dwarf2_cu *type_cu = cu; | |
8805 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 8806 | |
348e048f DE |
8807 | /* We could just recurse on read_structure_type, but we need to call |
8808 | get_die_type to ensure only one type for this DIE is created. | |
8809 | This is important, for example, because for c++ classes we need | |
8810 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
8811 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
8812 | |
8813 | /* TYPE_CU may not be the same as CU. | |
8814 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
8815 | return set_die_type (die, type, cu); |
8816 | } | |
8817 | ||
c0dd20ea | 8818 | type = alloc_type (objfile); |
c906108c | 8819 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 8820 | |
39cbfefa DJ |
8821 | name = dwarf2_name (die, cu); |
8822 | if (name != NULL) | |
c906108c | 8823 | { |
987504bb JJ |
8824 | if (cu->language == language_cplus |
8825 | || cu->language == language_java) | |
63d06c5c | 8826 | { |
3da10d80 KS |
8827 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
8828 | ||
8829 | /* dwarf2_full_name might have already finished building the DIE's | |
8830 | type. If so, there is no need to continue. */ | |
8831 | if (get_die_type (die, cu) != NULL) | |
8832 | return get_die_type (die, cu); | |
8833 | ||
8834 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
8835 | if (die->tag == DW_TAG_structure_type |
8836 | || die->tag == DW_TAG_class_type) | |
8837 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
8838 | } |
8839 | else | |
8840 | { | |
d8151005 DJ |
8841 | /* The name is already allocated along with this objfile, so |
8842 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
8843 | TYPE_TAG_NAME (type) = (char *) name; |
8844 | if (die->tag == DW_TAG_class_type) | |
8845 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 8846 | } |
c906108c SS |
8847 | } |
8848 | ||
8849 | if (die->tag == DW_TAG_structure_type) | |
8850 | { | |
8851 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
8852 | } | |
8853 | else if (die->tag == DW_TAG_union_type) | |
8854 | { | |
8855 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
8856 | } | |
8857 | else | |
8858 | { | |
c906108c SS |
8859 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
8860 | } | |
8861 | ||
0cc2414c TT |
8862 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
8863 | TYPE_DECLARED_CLASS (type) = 1; | |
8864 | ||
e142c38c | 8865 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8866 | if (attr) |
8867 | { | |
8868 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8869 | } | |
8870 | else | |
8871 | { | |
8872 | TYPE_LENGTH (type) = 0; | |
8873 | } | |
8874 | ||
876cecd0 | 8875 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 8876 | if (die_is_declaration (die, cu)) |
876cecd0 | 8877 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
8878 | else if (attr == NULL && die->child == NULL |
8879 | && producer_is_realview (cu->producer)) | |
8880 | /* RealView does not output the required DW_AT_declaration | |
8881 | on incomplete types. */ | |
8882 | TYPE_STUB (type) = 1; | |
dc718098 | 8883 | |
c906108c SS |
8884 | /* We need to add the type field to the die immediately so we don't |
8885 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 8886 | type within the structure itself. */ |
1c379e20 | 8887 | set_die_type (die, type, cu); |
c906108c | 8888 | |
7e314c57 JK |
8889 | /* set_die_type should be already done. */ |
8890 | set_descriptive_type (type, die, cu); | |
8891 | ||
c767944b DJ |
8892 | return type; |
8893 | } | |
8894 | ||
8895 | /* Finish creating a structure or union type, including filling in | |
8896 | its members and creating a symbol for it. */ | |
8897 | ||
8898 | static void | |
8899 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
8900 | { | |
8901 | struct objfile *objfile = cu->objfile; | |
8902 | struct die_info *child_die = die->child; | |
8903 | struct type *type; | |
8904 | ||
8905 | type = get_die_type (die, cu); | |
8906 | if (type == NULL) | |
8907 | type = read_structure_type (die, cu); | |
8908 | ||
e142c38c | 8909 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
8910 | { |
8911 | struct field_info fi; | |
8912 | struct die_info *child_die; | |
34eaf542 | 8913 | VEC (symbolp) *template_args = NULL; |
c767944b | 8914 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
8915 | |
8916 | memset (&fi, 0, sizeof (struct field_info)); | |
8917 | ||
639d11d3 | 8918 | child_die = die->child; |
c906108c SS |
8919 | |
8920 | while (child_die && child_die->tag) | |
8921 | { | |
a9a9bd0f DC |
8922 | if (child_die->tag == DW_TAG_member |
8923 | || child_die->tag == DW_TAG_variable) | |
c906108c | 8924 | { |
a9a9bd0f DC |
8925 | /* NOTE: carlton/2002-11-05: A C++ static data member |
8926 | should be a DW_TAG_member that is a declaration, but | |
8927 | all versions of G++ as of this writing (so through at | |
8928 | least 3.2.1) incorrectly generate DW_TAG_variable | |
8929 | tags for them instead. */ | |
e7c27a73 | 8930 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 8931 | } |
8713b1b1 | 8932 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 8933 | { |
0963b4bd | 8934 | /* C++ member function. */ |
e7c27a73 | 8935 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
8936 | } |
8937 | else if (child_die->tag == DW_TAG_inheritance) | |
8938 | { | |
8939 | /* C++ base class field. */ | |
e7c27a73 | 8940 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 8941 | } |
98751a41 JK |
8942 | else if (child_die->tag == DW_TAG_typedef) |
8943 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
8944 | else if (child_die->tag == DW_TAG_template_type_param |
8945 | || child_die->tag == DW_TAG_template_value_param) | |
8946 | { | |
8947 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
8948 | ||
f1078f66 DJ |
8949 | if (arg != NULL) |
8950 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
8951 | } |
8952 | ||
c906108c SS |
8953 | child_die = sibling_die (child_die); |
8954 | } | |
8955 | ||
34eaf542 TT |
8956 | /* Attach template arguments to type. */ |
8957 | if (! VEC_empty (symbolp, template_args)) | |
8958 | { | |
8959 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
8960 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
8961 | = VEC_length (symbolp, template_args); | |
8962 | TYPE_TEMPLATE_ARGUMENTS (type) | |
8963 | = obstack_alloc (&objfile->objfile_obstack, | |
8964 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
8965 | * sizeof (struct symbol *))); | |
8966 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
8967 | VEC_address (symbolp, template_args), | |
8968 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
8969 | * sizeof (struct symbol *))); | |
8970 | VEC_free (symbolp, template_args); | |
8971 | } | |
8972 | ||
c906108c SS |
8973 | /* Attach fields and member functions to the type. */ |
8974 | if (fi.nfields) | |
e7c27a73 | 8975 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
8976 | if (fi.nfnfields) |
8977 | { | |
e7c27a73 | 8978 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 8979 | |
c5aa993b | 8980 | /* Get the type which refers to the base class (possibly this |
c906108c | 8981 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
8982 | class from the DW_AT_containing_type attribute. This use of |
8983 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 8984 | |
e142c38c | 8985 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 8986 | { |
e7c27a73 | 8987 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
8988 | |
8989 | TYPE_VPTR_BASETYPE (type) = t; | |
8990 | if (type == t) | |
8991 | { | |
c906108c SS |
8992 | int i; |
8993 | ||
8994 | /* Our own class provides vtbl ptr. */ | |
8995 | for (i = TYPE_NFIELDS (t) - 1; | |
8996 | i >= TYPE_N_BASECLASSES (t); | |
8997 | --i) | |
8998 | { | |
0d5cff50 | 8999 | const char *fieldname = TYPE_FIELD_NAME (t, i); |
c906108c | 9000 | |
1168df01 | 9001 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
9002 | { |
9003 | TYPE_VPTR_FIELDNO (type) = i; | |
9004 | break; | |
9005 | } | |
9006 | } | |
9007 | ||
9008 | /* Complain if virtual function table field not found. */ | |
9009 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 9010 | complaint (&symfile_complaints, |
3e43a32a MS |
9011 | _("virtual function table pointer " |
9012 | "not found when defining class '%s'"), | |
4d3c2250 KB |
9013 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
9014 | ""); | |
c906108c SS |
9015 | } |
9016 | else | |
9017 | { | |
9018 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
9019 | } | |
9020 | } | |
f6235d4c EZ |
9021 | else if (cu->producer |
9022 | && strncmp (cu->producer, | |
9023 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
9024 | { | |
9025 | /* The IBM XLC compiler does not provide direct indication | |
9026 | of the containing type, but the vtable pointer is | |
9027 | always named __vfp. */ | |
9028 | ||
9029 | int i; | |
9030 | ||
9031 | for (i = TYPE_NFIELDS (type) - 1; | |
9032 | i >= TYPE_N_BASECLASSES (type); | |
9033 | --i) | |
9034 | { | |
9035 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
9036 | { | |
9037 | TYPE_VPTR_FIELDNO (type) = i; | |
9038 | TYPE_VPTR_BASETYPE (type) = type; | |
9039 | break; | |
9040 | } | |
9041 | } | |
9042 | } | |
c906108c | 9043 | } |
98751a41 JK |
9044 | |
9045 | /* Copy fi.typedef_field_list linked list elements content into the | |
9046 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
9047 | if (fi.typedef_field_list) | |
9048 | { | |
9049 | int i = fi.typedef_field_list_count; | |
9050 | ||
a0d7a4ff | 9051 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
9052 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
9053 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
9054 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
9055 | ||
9056 | /* Reverse the list order to keep the debug info elements order. */ | |
9057 | while (--i >= 0) | |
9058 | { | |
9059 | struct typedef_field *dest, *src; | |
6e70227d | 9060 | |
98751a41 JK |
9061 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
9062 | src = &fi.typedef_field_list->field; | |
9063 | fi.typedef_field_list = fi.typedef_field_list->next; | |
9064 | *dest = *src; | |
9065 | } | |
9066 | } | |
c767944b DJ |
9067 | |
9068 | do_cleanups (back_to); | |
eb2a6f42 TT |
9069 | |
9070 | if (HAVE_CPLUS_STRUCT (type)) | |
9071 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; | |
c906108c | 9072 | } |
63d06c5c | 9073 | |
bb5ed363 | 9074 | quirk_gcc_member_function_pointer (type, objfile); |
0b92b5bb | 9075 | |
90aeadfc DC |
9076 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
9077 | snapshots) has been known to create a die giving a declaration | |
9078 | for a class that has, as a child, a die giving a definition for a | |
9079 | nested class. So we have to process our children even if the | |
9080 | current die is a declaration. Normally, of course, a declaration | |
9081 | won't have any children at all. */ | |
134d01f1 | 9082 | |
90aeadfc DC |
9083 | while (child_die != NULL && child_die->tag) |
9084 | { | |
9085 | if (child_die->tag == DW_TAG_member | |
9086 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
9087 | || child_die->tag == DW_TAG_inheritance |
9088 | || child_die->tag == DW_TAG_template_value_param | |
9089 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 9090 | { |
90aeadfc | 9091 | /* Do nothing. */ |
134d01f1 | 9092 | } |
90aeadfc DC |
9093 | else |
9094 | process_die (child_die, cu); | |
134d01f1 | 9095 | |
90aeadfc | 9096 | child_die = sibling_die (child_die); |
134d01f1 DJ |
9097 | } |
9098 | ||
fa4028e9 JB |
9099 | /* Do not consider external references. According to the DWARF standard, |
9100 | these DIEs are identified by the fact that they have no byte_size | |
9101 | attribute, and a declaration attribute. */ | |
9102 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
9103 | || !die_is_declaration (die, cu)) | |
c767944b | 9104 | new_symbol (die, type, cu); |
134d01f1 DJ |
9105 | } |
9106 | ||
9107 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
9108 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 9109 | |
f792889a | 9110 | static struct type * |
134d01f1 | 9111 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9112 | { |
e7c27a73 | 9113 | struct objfile *objfile = cu->objfile; |
c906108c | 9114 | struct type *type; |
c906108c | 9115 | struct attribute *attr; |
0114d602 | 9116 | const char *name; |
134d01f1 | 9117 | |
348e048f DE |
9118 | /* If the definition of this type lives in .debug_types, read that type. |
9119 | Don't follow DW_AT_specification though, that will take us back up | |
9120 | the chain and we want to go down. */ | |
9121 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
9122 | if (attr) | |
9123 | { | |
9124 | struct dwarf2_cu *type_cu = cu; | |
9125 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 9126 | |
348e048f | 9127 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
9128 | |
9129 | /* TYPE_CU may not be the same as CU. | |
9130 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
9131 | return set_die_type (die, type, cu); |
9132 | } | |
9133 | ||
c906108c SS |
9134 | type = alloc_type (objfile); |
9135 | ||
9136 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 9137 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 9138 | if (name != NULL) |
0114d602 | 9139 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 9140 | |
e142c38c | 9141 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
9142 | if (attr) |
9143 | { | |
9144 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
9145 | } | |
9146 | else | |
9147 | { | |
9148 | TYPE_LENGTH (type) = 0; | |
9149 | } | |
9150 | ||
137033e9 JB |
9151 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
9152 | declared as private in the package spec, and then defined only | |
9153 | inside the package body. Such types are known as Taft Amendment | |
9154 | Types. When another package uses such a type, an incomplete DIE | |
9155 | may be generated by the compiler. */ | |
02eb380e | 9156 | if (die_is_declaration (die, cu)) |
876cecd0 | 9157 | TYPE_STUB (type) = 1; |
02eb380e | 9158 | |
f792889a | 9159 | return set_die_type (die, type, cu); |
134d01f1 DJ |
9160 | } |
9161 | ||
9162 | /* Given a pointer to a die which begins an enumeration, process all | |
9163 | the dies that define the members of the enumeration, and create the | |
9164 | symbol for the enumeration type. | |
9165 | ||
9166 | NOTE: We reverse the order of the element list. */ | |
9167 | ||
9168 | static void | |
9169 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
9170 | { | |
f792889a | 9171 | struct type *this_type; |
134d01f1 | 9172 | |
f792889a DJ |
9173 | this_type = get_die_type (die, cu); |
9174 | if (this_type == NULL) | |
9175 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 9176 | |
639d11d3 | 9177 | if (die->child != NULL) |
c906108c | 9178 | { |
9dc481d3 DE |
9179 | struct die_info *child_die; |
9180 | struct symbol *sym; | |
9181 | struct field *fields = NULL; | |
9182 | int num_fields = 0; | |
9183 | int unsigned_enum = 1; | |
9184 | char *name; | |
cafec441 TT |
9185 | int flag_enum = 1; |
9186 | ULONGEST mask = 0; | |
9dc481d3 | 9187 | |
639d11d3 | 9188 | child_die = die->child; |
c906108c SS |
9189 | while (child_die && child_die->tag) |
9190 | { | |
9191 | if (child_die->tag != DW_TAG_enumerator) | |
9192 | { | |
e7c27a73 | 9193 | process_die (child_die, cu); |
c906108c SS |
9194 | } |
9195 | else | |
9196 | { | |
39cbfefa DJ |
9197 | name = dwarf2_name (child_die, cu); |
9198 | if (name) | |
c906108c | 9199 | { |
f792889a | 9200 | sym = new_symbol (child_die, this_type, cu); |
c906108c | 9201 | if (SYMBOL_VALUE (sym) < 0) |
cafec441 TT |
9202 | { |
9203 | unsigned_enum = 0; | |
9204 | flag_enum = 0; | |
9205 | } | |
9206 | else if ((mask & SYMBOL_VALUE (sym)) != 0) | |
9207 | flag_enum = 0; | |
9208 | else | |
9209 | mask |= SYMBOL_VALUE (sym); | |
c906108c SS |
9210 | |
9211 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
9212 | { | |
9213 | fields = (struct field *) | |
9214 | xrealloc (fields, | |
9215 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 9216 | * sizeof (struct field)); |
c906108c SS |
9217 | } |
9218 | ||
3567439c | 9219 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 9220 | FIELD_TYPE (fields[num_fields]) = NULL; |
14e75d8e | 9221 | SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
9222 | FIELD_BITSIZE (fields[num_fields]) = 0; |
9223 | ||
9224 | num_fields++; | |
9225 | } | |
9226 | } | |
9227 | ||
9228 | child_die = sibling_die (child_die); | |
9229 | } | |
9230 | ||
9231 | if (num_fields) | |
9232 | { | |
f792889a DJ |
9233 | TYPE_NFIELDS (this_type) = num_fields; |
9234 | TYPE_FIELDS (this_type) = (struct field *) | |
9235 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
9236 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 9237 | sizeof (struct field) * num_fields); |
b8c9b27d | 9238 | xfree (fields); |
c906108c SS |
9239 | } |
9240 | if (unsigned_enum) | |
876cecd0 | 9241 | TYPE_UNSIGNED (this_type) = 1; |
cafec441 TT |
9242 | if (flag_enum) |
9243 | TYPE_FLAG_ENUM (this_type) = 1; | |
c906108c | 9244 | } |
134d01f1 | 9245 | |
6c83ed52 TT |
9246 | /* If we are reading an enum from a .debug_types unit, and the enum |
9247 | is a declaration, and the enum is not the signatured type in the | |
9248 | unit, then we do not want to add a symbol for it. Adding a | |
9249 | symbol would in some cases obscure the true definition of the | |
9250 | enum, giving users an incomplete type when the definition is | |
9251 | actually available. Note that we do not want to do this for all | |
9252 | enums which are just declarations, because C++0x allows forward | |
9253 | enum declarations. */ | |
3019eac3 | 9254 | if (cu->per_cu->is_debug_types |
6c83ed52 TT |
9255 | && die_is_declaration (die, cu)) |
9256 | { | |
52dc124a | 9257 | struct signatured_type *sig_type; |
6c83ed52 | 9258 | |
52dc124a | 9259 | sig_type |
6c83ed52 | 9260 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, |
3019eac3 | 9261 | cu->per_cu->info_or_types_section, |
6c83ed52 | 9262 | cu->per_cu->offset); |
3019eac3 DE |
9263 | gdb_assert (sig_type->type_offset_in_section.sect_off != 0); |
9264 | if (sig_type->type_offset_in_section.sect_off != die->offset.sect_off) | |
6c83ed52 TT |
9265 | return; |
9266 | } | |
9267 | ||
f792889a | 9268 | new_symbol (die, this_type, cu); |
c906108c SS |
9269 | } |
9270 | ||
9271 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
9272 | the DIE's type field. For now, this only handles one dimensional | |
9273 | arrays. */ | |
9274 | ||
f792889a | 9275 | static struct type * |
e7c27a73 | 9276 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9277 | { |
e7c27a73 | 9278 | struct objfile *objfile = cu->objfile; |
c906108c | 9279 | struct die_info *child_die; |
7e314c57 | 9280 | struct type *type; |
c906108c SS |
9281 | struct type *element_type, *range_type, *index_type; |
9282 | struct type **range_types = NULL; | |
9283 | struct attribute *attr; | |
9284 | int ndim = 0; | |
9285 | struct cleanup *back_to; | |
39cbfefa | 9286 | char *name; |
c906108c | 9287 | |
e7c27a73 | 9288 | element_type = die_type (die, cu); |
c906108c | 9289 | |
7e314c57 JK |
9290 | /* The die_type call above may have already set the type for this DIE. */ |
9291 | type = get_die_type (die, cu); | |
9292 | if (type) | |
9293 | return type; | |
9294 | ||
c906108c SS |
9295 | /* Irix 6.2 native cc creates array types without children for |
9296 | arrays with unspecified length. */ | |
639d11d3 | 9297 | if (die->child == NULL) |
c906108c | 9298 | { |
46bf5051 | 9299 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 9300 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
9301 | type = create_array_type (NULL, element_type, range_type); |
9302 | return set_die_type (die, type, cu); | |
c906108c SS |
9303 | } |
9304 | ||
9305 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 9306 | child_die = die->child; |
c906108c SS |
9307 | while (child_die && child_die->tag) |
9308 | { | |
9309 | if (child_die->tag == DW_TAG_subrange_type) | |
9310 | { | |
f792889a | 9311 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 9312 | |
f792889a | 9313 | if (child_type != NULL) |
a02abb62 | 9314 | { |
0963b4bd MS |
9315 | /* The range type was succesfully read. Save it for the |
9316 | array type creation. */ | |
a02abb62 JB |
9317 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
9318 | { | |
9319 | range_types = (struct type **) | |
9320 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
9321 | * sizeof (struct type *)); | |
9322 | if (ndim == 0) | |
9323 | make_cleanup (free_current_contents, &range_types); | |
9324 | } | |
f792889a | 9325 | range_types[ndim++] = child_type; |
a02abb62 | 9326 | } |
c906108c SS |
9327 | } |
9328 | child_die = sibling_die (child_die); | |
9329 | } | |
9330 | ||
9331 | /* Dwarf2 dimensions are output from left to right, create the | |
9332 | necessary array types in backwards order. */ | |
7ca2d3a3 | 9333 | |
c906108c | 9334 | type = element_type; |
7ca2d3a3 DL |
9335 | |
9336 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
9337 | { | |
9338 | int i = 0; | |
9a619af0 | 9339 | |
7ca2d3a3 DL |
9340 | while (i < ndim) |
9341 | type = create_array_type (NULL, type, range_types[i++]); | |
9342 | } | |
9343 | else | |
9344 | { | |
9345 | while (ndim-- > 0) | |
9346 | type = create_array_type (NULL, type, range_types[ndim]); | |
9347 | } | |
c906108c | 9348 | |
f5f8a009 EZ |
9349 | /* Understand Dwarf2 support for vector types (like they occur on |
9350 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
9351 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
9352 | custom vendor extension. The main difference between a regular | |
9353 | array and the vector variant is that vectors are passed by value | |
9354 | to functions. */ | |
e142c38c | 9355 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 9356 | if (attr) |
ea37ba09 | 9357 | make_vector_type (type); |
f5f8a009 | 9358 | |
dbc98a8b KW |
9359 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
9360 | implementation may choose to implement triple vectors using this | |
9361 | attribute. */ | |
9362 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
9363 | if (attr) | |
9364 | { | |
9365 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
9366 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
9367 | else | |
3e43a32a MS |
9368 | complaint (&symfile_complaints, |
9369 | _("DW_AT_byte_size for array type smaller " | |
9370 | "than the total size of elements")); | |
dbc98a8b KW |
9371 | } |
9372 | ||
39cbfefa DJ |
9373 | name = dwarf2_name (die, cu); |
9374 | if (name) | |
9375 | TYPE_NAME (type) = name; | |
6e70227d | 9376 | |
0963b4bd | 9377 | /* Install the type in the die. */ |
7e314c57 JK |
9378 | set_die_type (die, type, cu); |
9379 | ||
9380 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
9381 | set_descriptive_type (type, die, cu); |
9382 | ||
c906108c SS |
9383 | do_cleanups (back_to); |
9384 | ||
7e314c57 | 9385 | return type; |
c906108c SS |
9386 | } |
9387 | ||
7ca2d3a3 | 9388 | static enum dwarf_array_dim_ordering |
6e70227d | 9389 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
9390 | { |
9391 | struct attribute *attr; | |
9392 | ||
9393 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
9394 | ||
9395 | if (attr) return DW_SND (attr); | |
9396 | ||
0963b4bd MS |
9397 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
9398 | opposite order to the dwarf2 specification, but data is still | |
9399 | laid out as per normal fortran. | |
7ca2d3a3 | 9400 | |
0963b4bd MS |
9401 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
9402 | version checking. */ | |
7ca2d3a3 | 9403 | |
905e0470 PM |
9404 | if (cu->language == language_fortran |
9405 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
9406 | { |
9407 | return DW_ORD_row_major; | |
9408 | } | |
9409 | ||
6e70227d | 9410 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
9411 | { |
9412 | case array_column_major: | |
9413 | return DW_ORD_col_major; | |
9414 | case array_row_major: | |
9415 | default: | |
9416 | return DW_ORD_row_major; | |
9417 | }; | |
9418 | } | |
9419 | ||
72019c9c | 9420 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 9421 | the DIE's type field. */ |
72019c9c | 9422 | |
f792889a | 9423 | static struct type * |
72019c9c GM |
9424 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
9425 | { | |
7e314c57 JK |
9426 | struct type *domain_type, *set_type; |
9427 | struct attribute *attr; | |
f792889a | 9428 | |
7e314c57 JK |
9429 | domain_type = die_type (die, cu); |
9430 | ||
9431 | /* The die_type call above may have already set the type for this DIE. */ | |
9432 | set_type = get_die_type (die, cu); | |
9433 | if (set_type) | |
9434 | return set_type; | |
9435 | ||
9436 | set_type = create_set_type (NULL, domain_type); | |
9437 | ||
9438 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
9439 | if (attr) |
9440 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 9441 | |
f792889a | 9442 | return set_die_type (die, set_type, cu); |
72019c9c | 9443 | } |
7ca2d3a3 | 9444 | |
c906108c SS |
9445 | /* First cut: install each common block member as a global variable. */ |
9446 | ||
9447 | static void | |
e7c27a73 | 9448 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
9449 | { |
9450 | struct die_info *child_die; | |
9451 | struct attribute *attr; | |
9452 | struct symbol *sym; | |
9453 | CORE_ADDR base = (CORE_ADDR) 0; | |
9454 | ||
e142c38c | 9455 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
9456 | if (attr) |
9457 | { | |
0963b4bd | 9458 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
9459 | if (attr_form_is_block (attr)) |
9460 | { | |
e7c27a73 | 9461 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 9462 | } |
3690dd37 | 9463 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 9464 | { |
4d3c2250 | 9465 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
9466 | } |
9467 | else | |
9468 | { | |
4d3c2250 KB |
9469 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
9470 | "common block member"); | |
8e19ed76 | 9471 | } |
c906108c | 9472 | } |
639d11d3 | 9473 | if (die->child != NULL) |
c906108c | 9474 | { |
639d11d3 | 9475 | child_die = die->child; |
c906108c SS |
9476 | while (child_die && child_die->tag) |
9477 | { | |
74ac6d43 TT |
9478 | LONGEST offset; |
9479 | ||
e7c27a73 | 9480 | sym = new_symbol (child_die, NULL, cu); |
e8d28ef4 TT |
9481 | if (sym != NULL |
9482 | && handle_data_member_location (child_die, cu, &offset)) | |
c906108c | 9483 | { |
74ac6d43 | 9484 | SYMBOL_VALUE_ADDRESS (sym) = base + offset; |
c906108c SS |
9485 | add_symbol_to_list (sym, &global_symbols); |
9486 | } | |
9487 | child_die = sibling_die (child_die); | |
9488 | } | |
9489 | } | |
9490 | } | |
9491 | ||
0114d602 | 9492 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 9493 | |
0114d602 DJ |
9494 | static struct type * |
9495 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 9496 | { |
e7c27a73 | 9497 | struct objfile *objfile = cu->objfile; |
0114d602 | 9498 | const char *previous_prefix, *name; |
9219021c | 9499 | int is_anonymous; |
0114d602 DJ |
9500 | struct type *type; |
9501 | ||
9502 | /* For extensions, reuse the type of the original namespace. */ | |
9503 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
9504 | { | |
9505 | struct die_info *ext_die; | |
9506 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 9507 | |
0114d602 DJ |
9508 | ext_die = dwarf2_extension (die, &ext_cu); |
9509 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
9510 | |
9511 | /* EXT_CU may not be the same as CU. | |
9512 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
9513 | return set_die_type (die, type, cu); |
9514 | } | |
9219021c | 9515 | |
e142c38c | 9516 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
9517 | |
9518 | /* Now build the name of the current namespace. */ | |
9519 | ||
0114d602 DJ |
9520 | previous_prefix = determine_prefix (die, cu); |
9521 | if (previous_prefix[0] != '\0') | |
9522 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 9523 | previous_prefix, name, 0, cu); |
0114d602 DJ |
9524 | |
9525 | /* Create the type. */ | |
9526 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
9527 | objfile); | |
9528 | TYPE_NAME (type) = (char *) name; | |
9529 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
9530 | ||
60531b24 | 9531 | return set_die_type (die, type, cu); |
0114d602 DJ |
9532 | } |
9533 | ||
9534 | /* Read a C++ namespace. */ | |
9535 | ||
9536 | static void | |
9537 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
9538 | { | |
9539 | struct objfile *objfile = cu->objfile; | |
0114d602 | 9540 | int is_anonymous; |
9219021c | 9541 | |
5c4e30ca DC |
9542 | /* Add a symbol associated to this if we haven't seen the namespace |
9543 | before. Also, add a using directive if it's an anonymous | |
9544 | namespace. */ | |
9219021c | 9545 | |
f2f0e013 | 9546 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
9547 | { |
9548 | struct type *type; | |
9549 | ||
0114d602 | 9550 | type = read_type_die (die, cu); |
e7c27a73 | 9551 | new_symbol (die, type, cu); |
5c4e30ca | 9552 | |
e8e80198 | 9553 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 9554 | if (is_anonymous) |
0114d602 DJ |
9555 | { |
9556 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 9557 | |
c0cc3a76 | 9558 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
32019081 | 9559 | NULL, NULL, &objfile->objfile_obstack); |
0114d602 | 9560 | } |
5c4e30ca | 9561 | } |
9219021c | 9562 | |
639d11d3 | 9563 | if (die->child != NULL) |
d9fa45fe | 9564 | { |
639d11d3 | 9565 | struct die_info *child_die = die->child; |
6e70227d | 9566 | |
d9fa45fe DC |
9567 | while (child_die && child_die->tag) |
9568 | { | |
e7c27a73 | 9569 | process_die (child_die, cu); |
d9fa45fe DC |
9570 | child_die = sibling_die (child_die); |
9571 | } | |
9572 | } | |
38d518c9 EZ |
9573 | } |
9574 | ||
f55ee35c JK |
9575 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
9576 | imported module. Still we need that type as local Fortran "use ... only" | |
9577 | declaration imports depend on the created type in determine_prefix. */ | |
9578 | ||
9579 | static struct type * | |
9580 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
9581 | { | |
9582 | struct objfile *objfile = cu->objfile; | |
9583 | char *module_name; | |
9584 | struct type *type; | |
9585 | ||
9586 | module_name = dwarf2_name (die, cu); | |
9587 | if (!module_name) | |
3e43a32a MS |
9588 | complaint (&symfile_complaints, |
9589 | _("DW_TAG_module has no name, offset 0x%x"), | |
b64f50a1 | 9590 | die->offset.sect_off); |
f55ee35c JK |
9591 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); |
9592 | ||
9593 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
9594 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
9595 | ||
9596 | return set_die_type (die, type, cu); | |
9597 | } | |
9598 | ||
5d7cb8df JK |
9599 | /* Read a Fortran module. */ |
9600 | ||
9601 | static void | |
9602 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
9603 | { | |
9604 | struct die_info *child_die = die->child; | |
9605 | ||
5d7cb8df JK |
9606 | while (child_die && child_die->tag) |
9607 | { | |
9608 | process_die (child_die, cu); | |
9609 | child_die = sibling_die (child_die); | |
9610 | } | |
9611 | } | |
9612 | ||
38d518c9 EZ |
9613 | /* Return the name of the namespace represented by DIE. Set |
9614 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
9615 | namespace. */ | |
9616 | ||
9617 | static const char * | |
e142c38c | 9618 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
9619 | { |
9620 | struct die_info *current_die; | |
9621 | const char *name = NULL; | |
9622 | ||
9623 | /* Loop through the extensions until we find a name. */ | |
9624 | ||
9625 | for (current_die = die; | |
9626 | current_die != NULL; | |
f2f0e013 | 9627 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 9628 | { |
e142c38c | 9629 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
9630 | if (name != NULL) |
9631 | break; | |
9632 | } | |
9633 | ||
9634 | /* Is it an anonymous namespace? */ | |
9635 | ||
9636 | *is_anonymous = (name == NULL); | |
9637 | if (*is_anonymous) | |
2b1dbab0 | 9638 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
9639 | |
9640 | return name; | |
d9fa45fe DC |
9641 | } |
9642 | ||
c906108c SS |
9643 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
9644 | the user defined type vector. */ | |
9645 | ||
f792889a | 9646 | static struct type * |
e7c27a73 | 9647 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9648 | { |
5e2b427d | 9649 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 9650 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 9651 | struct type *type; |
8b2dbe47 KB |
9652 | struct attribute *attr_byte_size; |
9653 | struct attribute *attr_address_class; | |
9654 | int byte_size, addr_class; | |
7e314c57 JK |
9655 | struct type *target_type; |
9656 | ||
9657 | target_type = die_type (die, cu); | |
c906108c | 9658 | |
7e314c57 JK |
9659 | /* The die_type call above may have already set the type for this DIE. */ |
9660 | type = get_die_type (die, cu); | |
9661 | if (type) | |
9662 | return type; | |
9663 | ||
9664 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 9665 | |
e142c38c | 9666 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
9667 | if (attr_byte_size) |
9668 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 9669 | else |
8b2dbe47 KB |
9670 | byte_size = cu_header->addr_size; |
9671 | ||
e142c38c | 9672 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
9673 | if (attr_address_class) |
9674 | addr_class = DW_UNSND (attr_address_class); | |
9675 | else | |
9676 | addr_class = DW_ADDR_none; | |
9677 | ||
9678 | /* If the pointer size or address class is different than the | |
9679 | default, create a type variant marked as such and set the | |
9680 | length accordingly. */ | |
9681 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 9682 | { |
5e2b427d | 9683 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
9684 | { |
9685 | int type_flags; | |
9686 | ||
849957d9 | 9687 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 9688 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
9689 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
9690 | == 0); | |
8b2dbe47 KB |
9691 | type = make_type_with_address_space (type, type_flags); |
9692 | } | |
9693 | else if (TYPE_LENGTH (type) != byte_size) | |
9694 | { | |
3e43a32a MS |
9695 | complaint (&symfile_complaints, |
9696 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 9697 | } |
6e70227d | 9698 | else |
9a619af0 MS |
9699 | { |
9700 | /* Should we also complain about unhandled address classes? */ | |
9701 | } | |
c906108c | 9702 | } |
8b2dbe47 KB |
9703 | |
9704 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 9705 | return set_die_type (die, type, cu); |
c906108c SS |
9706 | } |
9707 | ||
9708 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
9709 | the user defined type vector. */ | |
9710 | ||
f792889a | 9711 | static struct type * |
e7c27a73 | 9712 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
9713 | { |
9714 | struct type *type; | |
9715 | struct type *to_type; | |
9716 | struct type *domain; | |
9717 | ||
e7c27a73 DJ |
9718 | to_type = die_type (die, cu); |
9719 | domain = die_containing_type (die, cu); | |
0d5de010 | 9720 | |
7e314c57 JK |
9721 | /* The calls above may have already set the type for this DIE. */ |
9722 | type = get_die_type (die, cu); | |
9723 | if (type) | |
9724 | return type; | |
9725 | ||
0d5de010 DJ |
9726 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
9727 | type = lookup_methodptr_type (to_type); | |
9728 | else | |
9729 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 9730 | |
f792889a | 9731 | return set_die_type (die, type, cu); |
c906108c SS |
9732 | } |
9733 | ||
9734 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
9735 | the user defined type vector. */ | |
9736 | ||
f792889a | 9737 | static struct type * |
e7c27a73 | 9738 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9739 | { |
e7c27a73 | 9740 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 9741 | struct type *type, *target_type; |
c906108c SS |
9742 | struct attribute *attr; |
9743 | ||
7e314c57 JK |
9744 | target_type = die_type (die, cu); |
9745 | ||
9746 | /* The die_type call above may have already set the type for this DIE. */ | |
9747 | type = get_die_type (die, cu); | |
9748 | if (type) | |
9749 | return type; | |
9750 | ||
9751 | type = lookup_reference_type (target_type); | |
e142c38c | 9752 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
9753 | if (attr) |
9754 | { | |
9755 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
9756 | } | |
9757 | else | |
9758 | { | |
107d2387 | 9759 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 9760 | } |
f792889a | 9761 | return set_die_type (die, type, cu); |
c906108c SS |
9762 | } |
9763 | ||
f792889a | 9764 | static struct type * |
e7c27a73 | 9765 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9766 | { |
f792889a | 9767 | struct type *base_type, *cv_type; |
c906108c | 9768 | |
e7c27a73 | 9769 | base_type = die_type (die, cu); |
7e314c57 JK |
9770 | |
9771 | /* The die_type call above may have already set the type for this DIE. */ | |
9772 | cv_type = get_die_type (die, cu); | |
9773 | if (cv_type) | |
9774 | return cv_type; | |
9775 | ||
2f608a3a KW |
9776 | /* In case the const qualifier is applied to an array type, the element type |
9777 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
9778 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
9779 | { | |
9780 | struct type *el_type, *inner_array; | |
9781 | ||
9782 | base_type = copy_type (base_type); | |
9783 | inner_array = base_type; | |
9784 | ||
9785 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
9786 | { | |
9787 | TYPE_TARGET_TYPE (inner_array) = | |
9788 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
9789 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
9790 | } | |
9791 | ||
9792 | el_type = TYPE_TARGET_TYPE (inner_array); | |
9793 | TYPE_TARGET_TYPE (inner_array) = | |
9794 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
9795 | ||
9796 | return set_die_type (die, base_type, cu); | |
9797 | } | |
9798 | ||
f792889a DJ |
9799 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
9800 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
9801 | } |
9802 | ||
f792889a | 9803 | static struct type * |
e7c27a73 | 9804 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9805 | { |
f792889a | 9806 | struct type *base_type, *cv_type; |
c906108c | 9807 | |
e7c27a73 | 9808 | base_type = die_type (die, cu); |
7e314c57 JK |
9809 | |
9810 | /* The die_type call above may have already set the type for this DIE. */ | |
9811 | cv_type = get_die_type (die, cu); | |
9812 | if (cv_type) | |
9813 | return cv_type; | |
9814 | ||
f792889a DJ |
9815 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
9816 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
9817 | } |
9818 | ||
9819 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
9820 | the user defined type vector. It isn't really a user defined type, | |
9821 | but it behaves like one, with other DIE's using an AT_user_def_type | |
9822 | attribute to reference it. */ | |
9823 | ||
f792889a | 9824 | static struct type * |
e7c27a73 | 9825 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9826 | { |
e7c27a73 | 9827 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 9828 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
9829 | struct type *type, *range_type, *index_type, *char_type; |
9830 | struct attribute *attr; | |
9831 | unsigned int length; | |
9832 | ||
e142c38c | 9833 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
9834 | if (attr) |
9835 | { | |
9836 | length = DW_UNSND (attr); | |
9837 | } | |
9838 | else | |
9839 | { | |
0963b4bd | 9840 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 9841 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
9842 | if (attr) |
9843 | { | |
9844 | length = DW_UNSND (attr); | |
9845 | } | |
9846 | else | |
9847 | { | |
9848 | length = 1; | |
9849 | } | |
c906108c | 9850 | } |
6ccb9162 | 9851 | |
46bf5051 | 9852 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 9853 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
9854 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
9855 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 9856 | |
f792889a | 9857 | return set_die_type (die, type, cu); |
c906108c SS |
9858 | } |
9859 | ||
9860 | /* Handle DIES due to C code like: | |
9861 | ||
9862 | struct foo | |
c5aa993b JM |
9863 | { |
9864 | int (*funcp)(int a, long l); | |
9865 | int b; | |
9866 | }; | |
c906108c | 9867 | |
0963b4bd | 9868 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 9869 | |
f792889a | 9870 | static struct type * |
e7c27a73 | 9871 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9872 | { |
bb5ed363 | 9873 | struct objfile *objfile = cu->objfile; |
0963b4bd MS |
9874 | struct type *type; /* Type that this function returns. */ |
9875 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
9876 | struct attribute *attr; |
9877 | ||
e7c27a73 | 9878 | type = die_type (die, cu); |
7e314c57 JK |
9879 | |
9880 | /* The die_type call above may have already set the type for this DIE. */ | |
9881 | ftype = get_die_type (die, cu); | |
9882 | if (ftype) | |
9883 | return ftype; | |
9884 | ||
0c8b41f1 | 9885 | ftype = lookup_function_type (type); |
c906108c | 9886 | |
5b8101ae | 9887 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 9888 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 9889 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 9890 | || cu->language == language_cplus |
5b8101ae PM |
9891 | || cu->language == language_java |
9892 | || cu->language == language_pascal) | |
876cecd0 | 9893 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
9894 | else if (producer_is_realview (cu->producer)) |
9895 | /* RealView does not emit DW_AT_prototyped. We can not | |
9896 | distinguish prototyped and unprototyped functions; default to | |
9897 | prototyped, since that is more common in modern code (and | |
9898 | RealView warns about unprototyped functions). */ | |
9899 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 9900 | |
c055b101 CV |
9901 | /* Store the calling convention in the type if it's available in |
9902 | the subroutine die. Otherwise set the calling convention to | |
9903 | the default value DW_CC_normal. */ | |
9904 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
9905 | if (attr) |
9906 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
9907 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
9908 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
9909 | else | |
9910 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
9911 | |
9912 | /* We need to add the subroutine type to the die immediately so | |
9913 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 9914 | declared as the same subroutine type. */ |
76c10ea2 | 9915 | set_die_type (die, ftype, cu); |
6e70227d | 9916 | |
639d11d3 | 9917 | if (die->child != NULL) |
c906108c | 9918 | { |
bb5ed363 | 9919 | struct type *void_type = objfile_type (objfile)->builtin_void; |
c906108c | 9920 | struct die_info *child_die; |
8072405b | 9921 | int nparams, iparams; |
c906108c SS |
9922 | |
9923 | /* Count the number of parameters. | |
9924 | FIXME: GDB currently ignores vararg functions, but knows about | |
9925 | vararg member functions. */ | |
8072405b | 9926 | nparams = 0; |
639d11d3 | 9927 | child_die = die->child; |
c906108c SS |
9928 | while (child_die && child_die->tag) |
9929 | { | |
9930 | if (child_die->tag == DW_TAG_formal_parameter) | |
9931 | nparams++; | |
9932 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 9933 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
9934 | child_die = sibling_die (child_die); |
9935 | } | |
9936 | ||
9937 | /* Allocate storage for parameters and fill them in. */ | |
9938 | TYPE_NFIELDS (ftype) = nparams; | |
9939 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 9940 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 9941 | |
8072405b JK |
9942 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
9943 | even if we error out during the parameters reading below. */ | |
9944 | for (iparams = 0; iparams < nparams; iparams++) | |
9945 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
9946 | ||
9947 | iparams = 0; | |
639d11d3 | 9948 | child_die = die->child; |
c906108c SS |
9949 | while (child_die && child_die->tag) |
9950 | { | |
9951 | if (child_die->tag == DW_TAG_formal_parameter) | |
9952 | { | |
3ce3b1ba PA |
9953 | struct type *arg_type; |
9954 | ||
9955 | /* DWARF version 2 has no clean way to discern C++ | |
9956 | static and non-static member functions. G++ helps | |
9957 | GDB by marking the first parameter for non-static | |
9958 | member functions (which is the this pointer) as | |
9959 | artificial. We pass this information to | |
9960 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
9961 | ||
9962 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
9963 | 4.5 does not yet generate. */ | |
e142c38c | 9964 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
9965 | if (attr) |
9966 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
9967 | else | |
418835cc KS |
9968 | { |
9969 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
9970 | ||
9971 | /* GCC/43521: In java, the formal parameter | |
9972 | "this" is sometimes not marked with DW_AT_artificial. */ | |
9973 | if (cu->language == language_java) | |
9974 | { | |
9975 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 9976 | |
418835cc KS |
9977 | if (name && !strcmp (name, "this")) |
9978 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
9979 | } | |
9980 | } | |
3ce3b1ba PA |
9981 | arg_type = die_type (child_die, cu); |
9982 | ||
9983 | /* RealView does not mark THIS as const, which the testsuite | |
9984 | expects. GCC marks THIS as const in method definitions, | |
9985 | but not in the class specifications (GCC PR 43053). */ | |
9986 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
9987 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
9988 | { | |
9989 | int is_this = 0; | |
9990 | struct dwarf2_cu *arg_cu = cu; | |
9991 | const char *name = dwarf2_name (child_die, cu); | |
9992 | ||
9993 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
9994 | if (attr) | |
9995 | { | |
9996 | /* If the compiler emits this, use it. */ | |
9997 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
9998 | is_this = 1; | |
9999 | } | |
10000 | else if (name && strcmp (name, "this") == 0) | |
10001 | /* Function definitions will have the argument names. */ | |
10002 | is_this = 1; | |
10003 | else if (name == NULL && iparams == 0) | |
10004 | /* Declarations may not have the names, so like | |
10005 | elsewhere in GDB, assume an artificial first | |
10006 | argument is "this". */ | |
10007 | is_this = 1; | |
10008 | ||
10009 | if (is_this) | |
10010 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
10011 | arg_type, 0); | |
10012 | } | |
10013 | ||
10014 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
10015 | iparams++; |
10016 | } | |
10017 | child_die = sibling_die (child_die); | |
10018 | } | |
10019 | } | |
10020 | ||
76c10ea2 | 10021 | return ftype; |
c906108c SS |
10022 | } |
10023 | ||
f792889a | 10024 | static struct type * |
e7c27a73 | 10025 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10026 | { |
e7c27a73 | 10027 | struct objfile *objfile = cu->objfile; |
0114d602 | 10028 | const char *name = NULL; |
3c8e0968 | 10029 | struct type *this_type, *target_type; |
c906108c | 10030 | |
94af9270 | 10031 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 10032 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
10033 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
10034 | TYPE_NAME (this_type) = (char *) name; | |
f792889a | 10035 | set_die_type (die, this_type, cu); |
3c8e0968 DE |
10036 | target_type = die_type (die, cu); |
10037 | if (target_type != this_type) | |
10038 | TYPE_TARGET_TYPE (this_type) = target_type; | |
10039 | else | |
10040 | { | |
10041 | /* Self-referential typedefs are, it seems, not allowed by the DWARF | |
10042 | spec and cause infinite loops in GDB. */ | |
10043 | complaint (&symfile_complaints, | |
10044 | _("Self-referential DW_TAG_typedef " | |
10045 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 10046 | die->offset.sect_off, objfile->name); |
3c8e0968 DE |
10047 | TYPE_TARGET_TYPE (this_type) = NULL; |
10048 | } | |
f792889a | 10049 | return this_type; |
c906108c SS |
10050 | } |
10051 | ||
10052 | /* Find a representation of a given base type and install | |
10053 | it in the TYPE field of the die. */ | |
10054 | ||
f792889a | 10055 | static struct type * |
e7c27a73 | 10056 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10057 | { |
e7c27a73 | 10058 | struct objfile *objfile = cu->objfile; |
c906108c SS |
10059 | struct type *type; |
10060 | struct attribute *attr; | |
10061 | int encoding = 0, size = 0; | |
39cbfefa | 10062 | char *name; |
6ccb9162 UW |
10063 | enum type_code code = TYPE_CODE_INT; |
10064 | int type_flags = 0; | |
10065 | struct type *target_type = NULL; | |
c906108c | 10066 | |
e142c38c | 10067 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
10068 | if (attr) |
10069 | { | |
10070 | encoding = DW_UNSND (attr); | |
10071 | } | |
e142c38c | 10072 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
10073 | if (attr) |
10074 | { | |
10075 | size = DW_UNSND (attr); | |
10076 | } | |
39cbfefa | 10077 | name = dwarf2_name (die, cu); |
6ccb9162 | 10078 | if (!name) |
c906108c | 10079 | { |
6ccb9162 UW |
10080 | complaint (&symfile_complaints, |
10081 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 10082 | } |
6ccb9162 UW |
10083 | |
10084 | switch (encoding) | |
c906108c | 10085 | { |
6ccb9162 UW |
10086 | case DW_ATE_address: |
10087 | /* Turn DW_ATE_address into a void * pointer. */ | |
10088 | code = TYPE_CODE_PTR; | |
10089 | type_flags |= TYPE_FLAG_UNSIGNED; | |
10090 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
10091 | break; | |
10092 | case DW_ATE_boolean: | |
10093 | code = TYPE_CODE_BOOL; | |
10094 | type_flags |= TYPE_FLAG_UNSIGNED; | |
10095 | break; | |
10096 | case DW_ATE_complex_float: | |
10097 | code = TYPE_CODE_COMPLEX; | |
10098 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
10099 | break; | |
10100 | case DW_ATE_decimal_float: | |
10101 | code = TYPE_CODE_DECFLOAT; | |
10102 | break; | |
10103 | case DW_ATE_float: | |
10104 | code = TYPE_CODE_FLT; | |
10105 | break; | |
10106 | case DW_ATE_signed: | |
10107 | break; | |
10108 | case DW_ATE_unsigned: | |
10109 | type_flags |= TYPE_FLAG_UNSIGNED; | |
3b2b8fea TT |
10110 | if (cu->language == language_fortran |
10111 | && name | |
10112 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) | |
10113 | code = TYPE_CODE_CHAR; | |
6ccb9162 UW |
10114 | break; |
10115 | case DW_ATE_signed_char: | |
6e70227d | 10116 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
10117 | || cu->language == language_pascal |
10118 | || cu->language == language_fortran) | |
6ccb9162 UW |
10119 | code = TYPE_CODE_CHAR; |
10120 | break; | |
10121 | case DW_ATE_unsigned_char: | |
868a0084 | 10122 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
10123 | || cu->language == language_pascal |
10124 | || cu->language == language_fortran) | |
6ccb9162 UW |
10125 | code = TYPE_CODE_CHAR; |
10126 | type_flags |= TYPE_FLAG_UNSIGNED; | |
10127 | break; | |
75079b2b TT |
10128 | case DW_ATE_UTF: |
10129 | /* We just treat this as an integer and then recognize the | |
10130 | type by name elsewhere. */ | |
10131 | break; | |
10132 | ||
6ccb9162 UW |
10133 | default: |
10134 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
10135 | dwarf_type_encoding_name (encoding)); | |
10136 | break; | |
c906108c | 10137 | } |
6ccb9162 | 10138 | |
0114d602 DJ |
10139 | type = init_type (code, size, type_flags, NULL, objfile); |
10140 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
10141 | TYPE_TARGET_TYPE (type) = target_type; |
10142 | ||
0114d602 | 10143 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 10144 | TYPE_NOSIGN (type) = 1; |
0114d602 | 10145 | |
f792889a | 10146 | return set_die_type (die, type, cu); |
c906108c SS |
10147 | } |
10148 | ||
a02abb62 JB |
10149 | /* Read the given DW_AT_subrange DIE. */ |
10150 | ||
f792889a | 10151 | static struct type * |
a02abb62 JB |
10152 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
10153 | { | |
10154 | struct type *base_type; | |
10155 | struct type *range_type; | |
10156 | struct attribute *attr; | |
4fae6e18 JK |
10157 | LONGEST low, high; |
10158 | int low_default_is_valid; | |
39cbfefa | 10159 | char *name; |
43bbcdc2 | 10160 | LONGEST negative_mask; |
e77813c8 | 10161 | |
a02abb62 | 10162 | base_type = die_type (die, cu); |
953ac07e JK |
10163 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
10164 | check_typedef (base_type); | |
a02abb62 | 10165 | |
7e314c57 JK |
10166 | /* The die_type call above may have already set the type for this DIE. */ |
10167 | range_type = get_die_type (die, cu); | |
10168 | if (range_type) | |
10169 | return range_type; | |
10170 | ||
4fae6e18 JK |
10171 | /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow |
10172 | omitting DW_AT_lower_bound. */ | |
10173 | switch (cu->language) | |
6e70227d | 10174 | { |
4fae6e18 JK |
10175 | case language_c: |
10176 | case language_cplus: | |
10177 | low = 0; | |
10178 | low_default_is_valid = 1; | |
10179 | break; | |
10180 | case language_fortran: | |
10181 | low = 1; | |
10182 | low_default_is_valid = 1; | |
10183 | break; | |
10184 | case language_d: | |
10185 | case language_java: | |
10186 | case language_objc: | |
10187 | low = 0; | |
10188 | low_default_is_valid = (cu->header.version >= 4); | |
10189 | break; | |
10190 | case language_ada: | |
10191 | case language_m2: | |
10192 | case language_pascal: | |
a02abb62 | 10193 | low = 1; |
4fae6e18 JK |
10194 | low_default_is_valid = (cu->header.version >= 4); |
10195 | break; | |
10196 | default: | |
10197 | low = 0; | |
10198 | low_default_is_valid = 0; | |
10199 | break; | |
a02abb62 JB |
10200 | } |
10201 | ||
dd5e6932 DJ |
10202 | /* FIXME: For variable sized arrays either of these could be |
10203 | a variable rather than a constant value. We'll allow it, | |
10204 | but we don't know how to handle it. */ | |
e142c38c | 10205 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 | 10206 | if (attr) |
4fae6e18 JK |
10207 | low = dwarf2_get_attr_constant_value (attr, low); |
10208 | else if (!low_default_is_valid) | |
10209 | complaint (&symfile_complaints, _("Missing DW_AT_lower_bound " | |
10210 | "- DIE at 0x%x [in module %s]"), | |
10211 | die->offset.sect_off, cu->objfile->name); | |
a02abb62 | 10212 | |
e142c38c | 10213 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 10214 | if (attr) |
6e70227d | 10215 | { |
d48323d8 | 10216 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
a02abb62 JB |
10217 | { |
10218 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 10219 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
10220 | FIXME: GDB does not yet know how to handle dynamic |
10221 | arrays properly, treat them as arrays with unspecified | |
10222 | length for now. | |
10223 | ||
10224 | FIXME: jimb/2003-09-22: GDB does not really know | |
10225 | how to handle arrays of unspecified length | |
10226 | either; we just represent them as zero-length | |
10227 | arrays. Choose an appropriate upper bound given | |
10228 | the lower bound we've computed above. */ | |
10229 | high = low - 1; | |
10230 | } | |
10231 | else | |
10232 | high = dwarf2_get_attr_constant_value (attr, 1); | |
10233 | } | |
e77813c8 PM |
10234 | else |
10235 | { | |
10236 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
10237 | if (attr) | |
10238 | { | |
10239 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
10240 | high = low + count - 1; | |
10241 | } | |
c2ff108b JK |
10242 | else |
10243 | { | |
10244 | /* Unspecified array length. */ | |
10245 | high = low - 1; | |
10246 | } | |
e77813c8 PM |
10247 | } |
10248 | ||
10249 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
10250 | without specifying a base type. | |
10251 | In that case, the base type must be set to the type of | |
10252 | the lower bound, upper bound or count, in that order, if any of these | |
10253 | three attributes references an object that has a type. | |
10254 | If no base type is found, the Dwarf-2 specifications say that | |
10255 | a signed integer type of size equal to the size of an address should | |
10256 | be used. | |
10257 | For the following C code: `extern char gdb_int [];' | |
10258 | GCC produces an empty range DIE. | |
10259 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 10260 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
10261 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
10262 | { | |
10263 | struct objfile *objfile = cu->objfile; | |
10264 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
10265 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
10266 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
10267 | ||
10268 | /* Test "int", "long int", and "long long int" objfile types, | |
10269 | and select the first one having a size above or equal to the | |
10270 | architecture address size. */ | |
10271 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
10272 | base_type = int_type; | |
10273 | else | |
10274 | { | |
10275 | int_type = objfile_type (objfile)->builtin_long; | |
10276 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
10277 | base_type = int_type; | |
10278 | else | |
10279 | { | |
10280 | int_type = objfile_type (objfile)->builtin_long_long; | |
10281 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
10282 | base_type = int_type; | |
10283 | } | |
10284 | } | |
10285 | } | |
a02abb62 | 10286 | |
6e70227d | 10287 | negative_mask = |
43bbcdc2 PH |
10288 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
10289 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
10290 | low |= negative_mask; | |
10291 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
10292 | high |= negative_mask; | |
10293 | ||
a02abb62 JB |
10294 | range_type = create_range_type (NULL, base_type, low, high); |
10295 | ||
bbb0eef6 JK |
10296 | /* Mark arrays with dynamic length at least as an array of unspecified |
10297 | length. GDB could check the boundary but before it gets implemented at | |
10298 | least allow accessing the array elements. */ | |
d48323d8 | 10299 | if (attr && attr_form_is_block (attr)) |
bbb0eef6 JK |
10300 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
10301 | ||
c2ff108b JK |
10302 | /* Ada expects an empty array on no boundary attributes. */ |
10303 | if (attr == NULL && cu->language != language_ada) | |
10304 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
10305 | ||
39cbfefa DJ |
10306 | name = dwarf2_name (die, cu); |
10307 | if (name) | |
10308 | TYPE_NAME (range_type) = name; | |
6e70227d | 10309 | |
e142c38c | 10310 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
10311 | if (attr) |
10312 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
10313 | ||
7e314c57 JK |
10314 | set_die_type (die, range_type, cu); |
10315 | ||
10316 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
10317 | set_descriptive_type (range_type, die, cu); |
10318 | ||
7e314c57 | 10319 | return range_type; |
a02abb62 | 10320 | } |
6e70227d | 10321 | |
f792889a | 10322 | static struct type * |
81a17f79 JB |
10323 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
10324 | { | |
10325 | struct type *type; | |
81a17f79 | 10326 | |
81a17f79 JB |
10327 | /* For now, we only support the C meaning of an unspecified type: void. */ |
10328 | ||
0114d602 DJ |
10329 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
10330 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 10331 | |
f792889a | 10332 | return set_die_type (die, type, cu); |
81a17f79 | 10333 | } |
a02abb62 | 10334 | |
639d11d3 DC |
10335 | /* Read a single die and all its descendents. Set the die's sibling |
10336 | field to NULL; set other fields in the die correctly, and set all | |
10337 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
10338 | location of the info_ptr after reading all of those dies. PARENT | |
10339 | is the parent of the die in question. */ | |
10340 | ||
10341 | static struct die_info * | |
dee91e82 DE |
10342 | read_die_and_children (const struct die_reader_specs *reader, |
10343 | gdb_byte *info_ptr, | |
10344 | gdb_byte **new_info_ptr, | |
10345 | struct die_info *parent) | |
639d11d3 DC |
10346 | { |
10347 | struct die_info *die; | |
fe1b8b76 | 10348 | gdb_byte *cur_ptr; |
639d11d3 DC |
10349 | int has_children; |
10350 | ||
93311388 | 10351 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
10352 | if (die == NULL) |
10353 | { | |
10354 | *new_info_ptr = cur_ptr; | |
10355 | return NULL; | |
10356 | } | |
93311388 | 10357 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
10358 | |
10359 | if (has_children) | |
348e048f | 10360 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
10361 | else |
10362 | { | |
10363 | die->child = NULL; | |
10364 | *new_info_ptr = cur_ptr; | |
10365 | } | |
10366 | ||
10367 | die->sibling = NULL; | |
10368 | die->parent = parent; | |
10369 | return die; | |
10370 | } | |
10371 | ||
10372 | /* Read a die, all of its descendents, and all of its siblings; set | |
10373 | all of the fields of all of the dies correctly. Arguments are as | |
10374 | in read_die_and_children. */ | |
10375 | ||
10376 | static struct die_info * | |
93311388 DE |
10377 | read_die_and_siblings (const struct die_reader_specs *reader, |
10378 | gdb_byte *info_ptr, | |
fe1b8b76 | 10379 | gdb_byte **new_info_ptr, |
639d11d3 DC |
10380 | struct die_info *parent) |
10381 | { | |
10382 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 10383 | gdb_byte *cur_ptr; |
639d11d3 | 10384 | |
c906108c | 10385 | cur_ptr = info_ptr; |
639d11d3 DC |
10386 | first_die = last_sibling = NULL; |
10387 | ||
10388 | while (1) | |
c906108c | 10389 | { |
639d11d3 | 10390 | struct die_info *die |
dee91e82 | 10391 | = read_die_and_children (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 10392 | |
1d325ec1 | 10393 | if (die == NULL) |
c906108c | 10394 | { |
639d11d3 DC |
10395 | *new_info_ptr = cur_ptr; |
10396 | return first_die; | |
c906108c | 10397 | } |
1d325ec1 DJ |
10398 | |
10399 | if (!first_die) | |
10400 | first_die = die; | |
c906108c | 10401 | else |
1d325ec1 DJ |
10402 | last_sibling->sibling = die; |
10403 | ||
10404 | last_sibling = die; | |
c906108c | 10405 | } |
c906108c SS |
10406 | } |
10407 | ||
3019eac3 DE |
10408 | /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS |
10409 | attributes. | |
10410 | The caller is responsible for filling in the extra attributes | |
10411 | and updating (*DIEP)->num_attrs. | |
10412 | Set DIEP to point to a newly allocated die with its information, | |
10413 | except for its child, sibling, and parent fields. | |
10414 | Set HAS_CHILDREN to tell whether the die has children or not. */ | |
93311388 DE |
10415 | |
10416 | static gdb_byte * | |
3019eac3 DE |
10417 | read_full_die_1 (const struct die_reader_specs *reader, |
10418 | struct die_info **diep, gdb_byte *info_ptr, | |
10419 | int *has_children, int num_extra_attrs) | |
93311388 | 10420 | { |
b64f50a1 JK |
10421 | unsigned int abbrev_number, bytes_read, i; |
10422 | sect_offset offset; | |
93311388 DE |
10423 | struct abbrev_info *abbrev; |
10424 | struct die_info *die; | |
10425 | struct dwarf2_cu *cu = reader->cu; | |
10426 | bfd *abfd = reader->abfd; | |
10427 | ||
b64f50a1 | 10428 | offset.sect_off = info_ptr - reader->buffer; |
93311388 DE |
10429 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10430 | info_ptr += bytes_read; | |
10431 | if (!abbrev_number) | |
10432 | { | |
10433 | *diep = NULL; | |
10434 | *has_children = 0; | |
10435 | return info_ptr; | |
10436 | } | |
10437 | ||
10438 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
10439 | if (!abbrev) | |
348e048f DE |
10440 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
10441 | abbrev_number, | |
10442 | bfd_get_filename (abfd)); | |
10443 | ||
3019eac3 | 10444 | die = dwarf_alloc_die (cu, abbrev->num_attrs + num_extra_attrs); |
93311388 DE |
10445 | die->offset = offset; |
10446 | die->tag = abbrev->tag; | |
10447 | die->abbrev = abbrev_number; | |
10448 | ||
3019eac3 DE |
10449 | /* Make the result usable. |
10450 | The caller needs to update num_attrs after adding the extra | |
10451 | attributes. */ | |
93311388 DE |
10452 | die->num_attrs = abbrev->num_attrs; |
10453 | ||
10454 | for (i = 0; i < abbrev->num_attrs; ++i) | |
dee91e82 DE |
10455 | info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i], |
10456 | info_ptr); | |
93311388 DE |
10457 | |
10458 | *diep = die; | |
10459 | *has_children = abbrev->has_children; | |
10460 | return info_ptr; | |
10461 | } | |
10462 | ||
3019eac3 DE |
10463 | /* Read a die and all its attributes. |
10464 | Set DIEP to point to a newly allocated die with its information, | |
10465 | except for its child, sibling, and parent fields. | |
10466 | Set HAS_CHILDREN to tell whether the die has children or not. */ | |
10467 | ||
10468 | static gdb_byte * | |
10469 | read_full_die (const struct die_reader_specs *reader, | |
10470 | struct die_info **diep, gdb_byte *info_ptr, | |
10471 | int *has_children) | |
10472 | { | |
10473 | return read_full_die_1 (reader, diep, info_ptr, has_children, 0); | |
10474 | } | |
10475 | ||
c906108c SS |
10476 | /* In DWARF version 2, the description of the debugging information is |
10477 | stored in a separate .debug_abbrev section. Before we read any | |
10478 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
10479 | in a hash table. This function also sets flags in CU describing |
10480 | the data found in the abbrev table. */ | |
c906108c SS |
10481 | |
10482 | static void | |
dee91e82 DE |
10483 | dwarf2_read_abbrevs (struct dwarf2_cu *cu, |
10484 | struct dwarf2_section_info *abbrev_section) | |
10485 | ||
c906108c | 10486 | { |
dee91e82 | 10487 | bfd *abfd = abbrev_section->asection->owner; |
e7c27a73 | 10488 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 10489 | gdb_byte *abbrev_ptr; |
c906108c SS |
10490 | struct abbrev_info *cur_abbrev; |
10491 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
10492 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
10493 | struct attr_abbrev *cur_attrs; |
10494 | unsigned int allocated_attrs; | |
c906108c | 10495 | |
0963b4bd | 10496 | /* Initialize dwarf2 abbrevs. */ |
f3dd6933 DJ |
10497 | obstack_init (&cu->abbrev_obstack); |
10498 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
10499 | (ABBREV_HASH_SIZE | |
10500 | * sizeof (struct abbrev_info *))); | |
10501 | memset (cu->dwarf2_abbrevs, 0, | |
10502 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 10503 | |
dee91e82 DE |
10504 | dwarf2_read_section (cu->objfile, abbrev_section); |
10505 | abbrev_ptr = abbrev_section->buffer + cu_header->abbrev_offset.sect_off; | |
c906108c SS |
10506 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
10507 | abbrev_ptr += bytes_read; | |
10508 | ||
f3dd6933 DJ |
10509 | allocated_attrs = ATTR_ALLOC_CHUNK; |
10510 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 10511 | |
0963b4bd | 10512 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
10513 | while (abbrev_number) |
10514 | { | |
f3dd6933 | 10515 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
10516 | |
10517 | /* read in abbrev header */ | |
10518 | cur_abbrev->number = abbrev_number; | |
10519 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
10520 | abbrev_ptr += bytes_read; | |
10521 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
10522 | abbrev_ptr += 1; | |
10523 | ||
10524 | /* now read in declarations */ | |
10525 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
10526 | abbrev_ptr += bytes_read; | |
10527 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
10528 | abbrev_ptr += bytes_read; | |
10529 | while (abbrev_name) | |
10530 | { | |
f3dd6933 | 10531 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 10532 | { |
f3dd6933 DJ |
10533 | allocated_attrs += ATTR_ALLOC_CHUNK; |
10534 | cur_attrs | |
10535 | = xrealloc (cur_attrs, (allocated_attrs | |
10536 | * sizeof (struct attr_abbrev))); | |
c906108c | 10537 | } |
ae038cb0 | 10538 | |
f3dd6933 DJ |
10539 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
10540 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
10541 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
10542 | abbrev_ptr += bytes_read; | |
10543 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
10544 | abbrev_ptr += bytes_read; | |
10545 | } | |
10546 | ||
f3dd6933 DJ |
10547 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
10548 | (cur_abbrev->num_attrs | |
10549 | * sizeof (struct attr_abbrev))); | |
10550 | memcpy (cur_abbrev->attrs, cur_attrs, | |
10551 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
10552 | ||
c906108c | 10553 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
10554 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
10555 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
10556 | |
10557 | /* Get next abbreviation. | |
10558 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
10559 | always properly terminated with an abbrev number of 0. |
10560 | Exit loop if we encounter an abbreviation which we have | |
10561 | already read (which means we are about to read the abbreviations | |
10562 | for the next compile unit) or if the end of the abbreviation | |
10563 | table is reached. */ | |
dee91e82 DE |
10564 | if ((unsigned int) (abbrev_ptr - abbrev_section->buffer) |
10565 | >= abbrev_section->size) | |
c906108c SS |
10566 | break; |
10567 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
10568 | abbrev_ptr += bytes_read; | |
e7c27a73 | 10569 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
10570 | break; |
10571 | } | |
f3dd6933 DJ |
10572 | |
10573 | xfree (cur_attrs); | |
c906108c SS |
10574 | } |
10575 | ||
f3dd6933 | 10576 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 10577 | |
c906108c | 10578 | static void |
f3dd6933 | 10579 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 10580 | { |
f3dd6933 | 10581 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 10582 | |
f3dd6933 DJ |
10583 | obstack_free (&cu->abbrev_obstack, NULL); |
10584 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
10585 | } |
10586 | ||
10587 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
10588 | ||
10589 | static struct abbrev_info * | |
e7c27a73 | 10590 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
10591 | { |
10592 | unsigned int hash_number; | |
10593 | struct abbrev_info *abbrev; | |
10594 | ||
10595 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 10596 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
10597 | |
10598 | while (abbrev) | |
10599 | { | |
10600 | if (abbrev->number == number) | |
10601 | return abbrev; | |
10602 | else | |
10603 | abbrev = abbrev->next; | |
10604 | } | |
10605 | return NULL; | |
10606 | } | |
10607 | ||
72bf9492 DJ |
10608 | /* Returns nonzero if TAG represents a type that we might generate a partial |
10609 | symbol for. */ | |
10610 | ||
10611 | static int | |
10612 | is_type_tag_for_partial (int tag) | |
10613 | { | |
10614 | switch (tag) | |
10615 | { | |
10616 | #if 0 | |
10617 | /* Some types that would be reasonable to generate partial symbols for, | |
10618 | that we don't at present. */ | |
10619 | case DW_TAG_array_type: | |
10620 | case DW_TAG_file_type: | |
10621 | case DW_TAG_ptr_to_member_type: | |
10622 | case DW_TAG_set_type: | |
10623 | case DW_TAG_string_type: | |
10624 | case DW_TAG_subroutine_type: | |
10625 | #endif | |
10626 | case DW_TAG_base_type: | |
10627 | case DW_TAG_class_type: | |
680b30c7 | 10628 | case DW_TAG_interface_type: |
72bf9492 DJ |
10629 | case DW_TAG_enumeration_type: |
10630 | case DW_TAG_structure_type: | |
10631 | case DW_TAG_subrange_type: | |
10632 | case DW_TAG_typedef: | |
10633 | case DW_TAG_union_type: | |
10634 | return 1; | |
10635 | default: | |
10636 | return 0; | |
10637 | } | |
10638 | } | |
10639 | ||
10640 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
10641 | ||
10642 | static struct partial_die_info * | |
dee91e82 DE |
10643 | load_partial_dies (const struct die_reader_specs *reader, |
10644 | gdb_byte *info_ptr, int building_psymtab) | |
72bf9492 | 10645 | { |
dee91e82 | 10646 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 10647 | struct objfile *objfile = cu->objfile; |
72bf9492 DJ |
10648 | struct partial_die_info *part_die; |
10649 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
10650 | struct abbrev_info *abbrev; | |
10651 | unsigned int bytes_read; | |
5afb4e99 | 10652 | unsigned int load_all = 0; |
72bf9492 DJ |
10653 | int nesting_level = 1; |
10654 | ||
10655 | parent_die = NULL; | |
10656 | last_die = NULL; | |
10657 | ||
7adf1e79 DE |
10658 | gdb_assert (cu->per_cu != NULL); |
10659 | if (cu->per_cu->load_all_dies) | |
5afb4e99 DJ |
10660 | load_all = 1; |
10661 | ||
72bf9492 DJ |
10662 | cu->partial_dies |
10663 | = htab_create_alloc_ex (cu->header.length / 12, | |
10664 | partial_die_hash, | |
10665 | partial_die_eq, | |
10666 | NULL, | |
10667 | &cu->comp_unit_obstack, | |
10668 | hashtab_obstack_allocate, | |
10669 | dummy_obstack_deallocate); | |
10670 | ||
10671 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
10672 | sizeof (struct partial_die_info)); | |
10673 | ||
10674 | while (1) | |
10675 | { | |
10676 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
10677 | ||
10678 | /* A NULL abbrev means the end of a series of children. */ | |
10679 | if (abbrev == NULL) | |
10680 | { | |
10681 | if (--nesting_level == 0) | |
10682 | { | |
10683 | /* PART_DIE was probably the last thing allocated on the | |
10684 | comp_unit_obstack, so we could call obstack_free | |
10685 | here. We don't do that because the waste is small, | |
10686 | and will be cleaned up when we're done with this | |
10687 | compilation unit. This way, we're also more robust | |
10688 | against other users of the comp_unit_obstack. */ | |
10689 | return first_die; | |
10690 | } | |
10691 | info_ptr += bytes_read; | |
10692 | last_die = parent_die; | |
10693 | parent_die = parent_die->die_parent; | |
10694 | continue; | |
10695 | } | |
10696 | ||
98bfdba5 PA |
10697 | /* Check for template arguments. We never save these; if |
10698 | they're seen, we just mark the parent, and go on our way. */ | |
10699 | if (parent_die != NULL | |
10700 | && cu->language == language_cplus | |
10701 | && (abbrev->tag == DW_TAG_template_type_param | |
10702 | || abbrev->tag == DW_TAG_template_value_param)) | |
10703 | { | |
10704 | parent_die->has_template_arguments = 1; | |
10705 | ||
10706 | if (!load_all) | |
10707 | { | |
10708 | /* We don't need a partial DIE for the template argument. */ | |
dee91e82 | 10709 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
10710 | continue; |
10711 | } | |
10712 | } | |
10713 | ||
0d99eb77 | 10714 | /* We only recurse into c++ subprograms looking for template arguments. |
98bfdba5 PA |
10715 | Skip their other children. */ |
10716 | if (!load_all | |
10717 | && cu->language == language_cplus | |
10718 | && parent_die != NULL | |
10719 | && parent_die->tag == DW_TAG_subprogram) | |
10720 | { | |
dee91e82 | 10721 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
10722 | continue; |
10723 | } | |
10724 | ||
5afb4e99 DJ |
10725 | /* Check whether this DIE is interesting enough to save. Normally |
10726 | we would not be interested in members here, but there may be | |
10727 | later variables referencing them via DW_AT_specification (for | |
10728 | static members). */ | |
10729 | if (!load_all | |
10730 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 10731 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
10732 | && abbrev->tag != DW_TAG_enumerator |
10733 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 10734 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 10735 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 10736 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 10737 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 10738 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
10739 | { |
10740 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 10741 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
72bf9492 DJ |
10742 | continue; |
10743 | } | |
10744 | ||
dee91e82 DE |
10745 | info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read, |
10746 | info_ptr); | |
72bf9492 DJ |
10747 | |
10748 | /* This two-pass algorithm for processing partial symbols has a | |
10749 | high cost in cache pressure. Thus, handle some simple cases | |
10750 | here which cover the majority of C partial symbols. DIEs | |
10751 | which neither have specification tags in them, nor could have | |
10752 | specification tags elsewhere pointing at them, can simply be | |
10753 | processed and discarded. | |
10754 | ||
10755 | This segment is also optional; scan_partial_symbols and | |
10756 | add_partial_symbol will handle these DIEs if we chain | |
10757 | them in normally. When compilers which do not emit large | |
10758 | quantities of duplicate debug information are more common, | |
10759 | this code can probably be removed. */ | |
10760 | ||
10761 | /* Any complete simple types at the top level (pretty much all | |
10762 | of them, for a language without namespaces), can be processed | |
10763 | directly. */ | |
10764 | if (parent_die == NULL | |
10765 | && part_die->has_specification == 0 | |
10766 | && part_die->is_declaration == 0 | |
d8228535 | 10767 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
10768 | || part_die->tag == DW_TAG_base_type |
10769 | || part_die->tag == DW_TAG_subrange_type)) | |
10770 | { | |
10771 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 10772 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 10773 | VAR_DOMAIN, LOC_TYPEDEF, |
bb5ed363 DE |
10774 | &objfile->static_psymbols, |
10775 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
dee91e82 | 10776 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
10777 | continue; |
10778 | } | |
10779 | ||
d8228535 JK |
10780 | /* The exception for DW_TAG_typedef with has_children above is |
10781 | a workaround of GCC PR debug/47510. In the case of this complaint | |
10782 | type_name_no_tag_or_error will error on such types later. | |
10783 | ||
10784 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
10785 | it could not find the child DIEs referenced later, this is checked | |
10786 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
10787 | ||
10788 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
10789 | complaint (&symfile_complaints, | |
10790 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
10791 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 10792 | part_die->offset.sect_off, objfile->name); |
d8228535 | 10793 | |
72bf9492 DJ |
10794 | /* If we're at the second level, and we're an enumerator, and |
10795 | our parent has no specification (meaning possibly lives in a | |
10796 | namespace elsewhere), then we can add the partial symbol now | |
10797 | instead of queueing it. */ | |
10798 | if (part_die->tag == DW_TAG_enumerator | |
10799 | && parent_die != NULL | |
10800 | && parent_die->die_parent == NULL | |
10801 | && parent_die->tag == DW_TAG_enumeration_type | |
10802 | && parent_die->has_specification == 0) | |
10803 | { | |
10804 | if (part_die->name == NULL) | |
3e43a32a MS |
10805 | complaint (&symfile_complaints, |
10806 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 10807 | else if (building_psymtab) |
04a679b8 | 10808 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 10809 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
10810 | (cu->language == language_cplus |
10811 | || cu->language == language_java) | |
bb5ed363 DE |
10812 | ? &objfile->global_psymbols |
10813 | : &objfile->static_psymbols, | |
10814 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
72bf9492 | 10815 | |
dee91e82 | 10816 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
10817 | continue; |
10818 | } | |
10819 | ||
10820 | /* We'll save this DIE so link it in. */ | |
10821 | part_die->die_parent = parent_die; | |
10822 | part_die->die_sibling = NULL; | |
10823 | part_die->die_child = NULL; | |
10824 | ||
10825 | if (last_die && last_die == parent_die) | |
10826 | last_die->die_child = part_die; | |
10827 | else if (last_die) | |
10828 | last_die->die_sibling = part_die; | |
10829 | ||
10830 | last_die = part_die; | |
10831 | ||
10832 | if (first_die == NULL) | |
10833 | first_die = part_die; | |
10834 | ||
10835 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
10836 | find interesting need to be in the hash table, because we | |
10837 | also have the parent/sibling/child chains; only those that we | |
10838 | might refer to by offset later during partial symbol reading. | |
10839 | ||
10840 | For now this means things that might have be the target of a | |
10841 | DW_AT_specification, DW_AT_abstract_origin, or | |
10842 | DW_AT_extension. DW_AT_extension will refer only to | |
10843 | namespaces; DW_AT_abstract_origin refers to functions (and | |
10844 | many things under the function DIE, but we do not recurse | |
10845 | into function DIEs during partial symbol reading) and | |
10846 | possibly variables as well; DW_AT_specification refers to | |
10847 | declarations. Declarations ought to have the DW_AT_declaration | |
10848 | flag. It happens that GCC forgets to put it in sometimes, but | |
10849 | only for functions, not for types. | |
10850 | ||
10851 | Adding more things than necessary to the hash table is harmless | |
10852 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
10853 | wasted time in find_partial_die, when we reread the compilation |
10854 | unit with load_all_dies set. */ | |
72bf9492 | 10855 | |
5afb4e99 | 10856 | if (load_all |
72929c62 | 10857 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 10858 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
10859 | || abbrev->tag == DW_TAG_variable |
10860 | || abbrev->tag == DW_TAG_namespace | |
10861 | || part_die->is_declaration) | |
10862 | { | |
10863 | void **slot; | |
10864 | ||
10865 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
b64f50a1 | 10866 | part_die->offset.sect_off, INSERT); |
72bf9492 DJ |
10867 | *slot = part_die; |
10868 | } | |
10869 | ||
10870 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
10871 | sizeof (struct partial_die_info)); | |
10872 | ||
10873 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 10874 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
10875 | languages we have to, so that we can get at method physnames |
10876 | to infer fully qualified class names, for DW_AT_specification, | |
10877 | and for C++ template arguments. For C++, we also look one level | |
10878 | inside functions to find template arguments (if the name of the | |
10879 | function does not already contain the template arguments). | |
bc30ff58 JB |
10880 | |
10881 | For Ada, we need to scan the children of subprograms and lexical | |
10882 | blocks as well because Ada allows the definition of nested | |
10883 | entities that could be interesting for the debugger, such as | |
10884 | nested subprograms for instance. */ | |
72bf9492 | 10885 | if (last_die->has_children |
5afb4e99 DJ |
10886 | && (load_all |
10887 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 10888 | || last_die->tag == DW_TAG_module |
72bf9492 | 10889 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
10890 | || (cu->language == language_cplus |
10891 | && last_die->tag == DW_TAG_subprogram | |
10892 | && (last_die->name == NULL | |
10893 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
10894 | || (cu->language != language_c |
10895 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 10896 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 10897 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
10898 | || last_die->tag == DW_TAG_union_type)) |
10899 | || (cu->language == language_ada | |
10900 | && (last_die->tag == DW_TAG_subprogram | |
10901 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
10902 | { |
10903 | nesting_level++; | |
10904 | parent_die = last_die; | |
10905 | continue; | |
10906 | } | |
10907 | ||
10908 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 10909 | info_ptr = locate_pdi_sibling (reader, last_die, info_ptr); |
72bf9492 DJ |
10910 | |
10911 | /* Back to the top, do it again. */ | |
10912 | } | |
10913 | } | |
10914 | ||
c906108c SS |
10915 | /* Read a minimal amount of information into the minimal die structure. */ |
10916 | ||
fe1b8b76 | 10917 | static gdb_byte * |
dee91e82 DE |
10918 | read_partial_die (const struct die_reader_specs *reader, |
10919 | struct partial_die_info *part_die, | |
10920 | struct abbrev_info *abbrev, unsigned int abbrev_len, | |
10921 | gdb_byte *info_ptr) | |
c906108c | 10922 | { |
dee91e82 | 10923 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 10924 | struct objfile *objfile = cu->objfile; |
dee91e82 | 10925 | gdb_byte *buffer = reader->buffer; |
fa238c03 | 10926 | unsigned int i; |
c906108c | 10927 | struct attribute attr; |
c5aa993b | 10928 | int has_low_pc_attr = 0; |
c906108c | 10929 | int has_high_pc_attr = 0; |
91da1414 | 10930 | int high_pc_relative = 0; |
c906108c | 10931 | |
72bf9492 | 10932 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 10933 | |
b64f50a1 | 10934 | part_die->offset.sect_off = info_ptr - buffer; |
72bf9492 DJ |
10935 | |
10936 | info_ptr += abbrev_len; | |
10937 | ||
10938 | if (abbrev == NULL) | |
10939 | return info_ptr; | |
10940 | ||
c906108c SS |
10941 | part_die->tag = abbrev->tag; |
10942 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
10943 | |
10944 | for (i = 0; i < abbrev->num_attrs; ++i) | |
10945 | { | |
dee91e82 | 10946 | info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
c906108c SS |
10947 | |
10948 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 10949 | partial symbol table. */ |
c906108c SS |
10950 | switch (attr.name) |
10951 | { | |
10952 | case DW_AT_name: | |
71c25dea TT |
10953 | switch (part_die->tag) |
10954 | { | |
10955 | case DW_TAG_compile_unit: | |
348e048f | 10956 | case DW_TAG_type_unit: |
71c25dea TT |
10957 | /* Compilation units have a DW_AT_name that is a filename, not |
10958 | a source language identifier. */ | |
10959 | case DW_TAG_enumeration_type: | |
10960 | case DW_TAG_enumerator: | |
10961 | /* These tags always have simple identifiers already; no need | |
10962 | to canonicalize them. */ | |
10963 | part_die->name = DW_STRING (&attr); | |
10964 | break; | |
10965 | default: | |
10966 | part_die->name | |
10967 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
bb5ed363 | 10968 | &objfile->objfile_obstack); |
71c25dea TT |
10969 | break; |
10970 | } | |
c906108c | 10971 | break; |
31ef98ae | 10972 | case DW_AT_linkage_name: |
c906108c | 10973 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
10974 | /* Note that both forms of linkage name might appear. We |
10975 | assume they will be the same, and we only store the last | |
10976 | one we see. */ | |
94af9270 KS |
10977 | if (cu->language == language_ada) |
10978 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 10979 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
10980 | break; |
10981 | case DW_AT_low_pc: | |
10982 | has_low_pc_attr = 1; | |
10983 | part_die->lowpc = DW_ADDR (&attr); | |
10984 | break; | |
10985 | case DW_AT_high_pc: | |
10986 | has_high_pc_attr = 1; | |
3019eac3 DE |
10987 | if (attr.form == DW_FORM_addr |
10988 | || attr.form == DW_FORM_GNU_addr_index) | |
91da1414 MW |
10989 | part_die->highpc = DW_ADDR (&attr); |
10990 | else | |
10991 | { | |
10992 | high_pc_relative = 1; | |
10993 | part_die->highpc = DW_UNSND (&attr); | |
10994 | } | |
c906108c SS |
10995 | break; |
10996 | case DW_AT_location: | |
0963b4bd | 10997 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
10998 | if (attr_form_is_block (&attr)) |
10999 | { | |
11000 | part_die->locdesc = DW_BLOCK (&attr); | |
11001 | } | |
3690dd37 | 11002 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 11003 | { |
4d3c2250 | 11004 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
11005 | } |
11006 | else | |
11007 | { | |
4d3c2250 KB |
11008 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
11009 | "partial symbol information"); | |
8e19ed76 | 11010 | } |
c906108c | 11011 | break; |
c906108c SS |
11012 | case DW_AT_external: |
11013 | part_die->is_external = DW_UNSND (&attr); | |
11014 | break; | |
11015 | case DW_AT_declaration: | |
11016 | part_die->is_declaration = DW_UNSND (&attr); | |
11017 | break; | |
11018 | case DW_AT_type: | |
11019 | part_die->has_type = 1; | |
11020 | break; | |
11021 | case DW_AT_abstract_origin: | |
11022 | case DW_AT_specification: | |
72bf9492 DJ |
11023 | case DW_AT_extension: |
11024 | part_die->has_specification = 1; | |
c764a876 | 11025 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
11026 | break; |
11027 | case DW_AT_sibling: | |
11028 | /* Ignore absolute siblings, they might point outside of | |
11029 | the current compile unit. */ | |
11030 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
11031 | complaint (&symfile_complaints, |
11032 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 11033 | else |
b64f50a1 | 11034 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
c906108c | 11035 | break; |
fa4028e9 JB |
11036 | case DW_AT_byte_size: |
11037 | part_die->has_byte_size = 1; | |
11038 | break; | |
68511cec CES |
11039 | case DW_AT_calling_convention: |
11040 | /* DWARF doesn't provide a way to identify a program's source-level | |
11041 | entry point. DW_AT_calling_convention attributes are only meant | |
11042 | to describe functions' calling conventions. | |
11043 | ||
11044 | However, because it's a necessary piece of information in | |
11045 | Fortran, and because DW_CC_program is the only piece of debugging | |
11046 | information whose definition refers to a 'main program' at all, | |
11047 | several compilers have begun marking Fortran main programs with | |
11048 | DW_CC_program --- even when those functions use the standard | |
11049 | calling conventions. | |
11050 | ||
11051 | So until DWARF specifies a way to provide this information and | |
11052 | compilers pick up the new representation, we'll support this | |
11053 | practice. */ | |
11054 | if (DW_UNSND (&attr) == DW_CC_program | |
11055 | && cu->language == language_fortran) | |
01f8c46d JK |
11056 | { |
11057 | set_main_name (part_die->name); | |
11058 | ||
11059 | /* As this DIE has a static linkage the name would be difficult | |
11060 | to look up later. */ | |
11061 | language_of_main = language_fortran; | |
11062 | } | |
68511cec | 11063 | break; |
481860b3 GB |
11064 | case DW_AT_inline: |
11065 | if (DW_UNSND (&attr) == DW_INL_inlined | |
11066 | || DW_UNSND (&attr) == DW_INL_declared_inlined) | |
11067 | part_die->may_be_inlined = 1; | |
11068 | break; | |
c906108c SS |
11069 | default: |
11070 | break; | |
11071 | } | |
11072 | } | |
11073 | ||
91da1414 MW |
11074 | if (high_pc_relative) |
11075 | part_die->highpc += part_die->lowpc; | |
11076 | ||
9373cf26 JK |
11077 | if (has_low_pc_attr && has_high_pc_attr) |
11078 | { | |
11079 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
11080 | eliminate duplicate copies of functions and vtables and such. | |
11081 | The linker will arbitrarily choose one and discard the others. | |
11082 | The AT_*_pc values for such functions refer to local labels in | |
11083 | these sections. If the section from that file was discarded, the | |
11084 | labels are not in the output, so the relocs get a value of 0. | |
11085 | If this is a discarded function, mark the pc bounds as invalid, | |
11086 | so that GDB will ignore it. */ | |
11087 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
11088 | { | |
bb5ed363 | 11089 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
11090 | |
11091 | complaint (&symfile_complaints, | |
11092 | _("DW_AT_low_pc %s is zero " | |
11093 | "for DIE at 0x%x [in module %s]"), | |
11094 | paddress (gdbarch, part_die->lowpc), | |
b64f50a1 | 11095 | part_die->offset.sect_off, objfile->name); |
9373cf26 JK |
11096 | } |
11097 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
11098 | else if (part_die->lowpc >= part_die->highpc) | |
11099 | { | |
bb5ed363 | 11100 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
11101 | |
11102 | complaint (&symfile_complaints, | |
11103 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
11104 | "for DIE at 0x%x [in module %s]"), | |
11105 | paddress (gdbarch, part_die->lowpc), | |
11106 | paddress (gdbarch, part_die->highpc), | |
b64f50a1 | 11107 | part_die->offset.sect_off, objfile->name); |
9373cf26 JK |
11108 | } |
11109 | else | |
11110 | part_die->has_pc_info = 1; | |
11111 | } | |
85cbf3d3 | 11112 | |
c906108c SS |
11113 | return info_ptr; |
11114 | } | |
11115 | ||
72bf9492 DJ |
11116 | /* Find a cached partial DIE at OFFSET in CU. */ |
11117 | ||
11118 | static struct partial_die_info * | |
b64f50a1 | 11119 | find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
11120 | { |
11121 | struct partial_die_info *lookup_die = NULL; | |
11122 | struct partial_die_info part_die; | |
11123 | ||
11124 | part_die.offset = offset; | |
b64f50a1 JK |
11125 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, |
11126 | offset.sect_off); | |
72bf9492 | 11127 | |
72bf9492 DJ |
11128 | return lookup_die; |
11129 | } | |
11130 | ||
348e048f DE |
11131 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
11132 | except in the case of .debug_types DIEs which do not reference | |
11133 | outside their CU (they do however referencing other types via | |
55f1336d | 11134 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
11135 | |
11136 | static struct partial_die_info * | |
b64f50a1 | 11137 | find_partial_die (sect_offset offset, struct dwarf2_cu *cu) |
72bf9492 | 11138 | { |
bb5ed363 | 11139 | struct objfile *objfile = cu->objfile; |
5afb4e99 DJ |
11140 | struct dwarf2_per_cu_data *per_cu = NULL; |
11141 | struct partial_die_info *pd = NULL; | |
72bf9492 | 11142 | |
45452591 | 11143 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
11144 | { |
11145 | pd = find_partial_die_in_comp_unit (offset, cu); | |
11146 | if (pd != NULL) | |
11147 | return pd; | |
0d99eb77 DE |
11148 | /* We missed recording what we needed. |
11149 | Load all dies and try again. */ | |
11150 | per_cu = cu->per_cu; | |
5afb4e99 | 11151 | } |
0d99eb77 DE |
11152 | else |
11153 | { | |
11154 | /* TUs don't reference other CUs/TUs (except via type signatures). */ | |
3019eac3 | 11155 | if (cu->per_cu->is_debug_types) |
0d99eb77 DE |
11156 | { |
11157 | error (_("Dwarf Error: Type Unit at offset 0x%lx contains" | |
11158 | " external reference to offset 0x%lx [in module %s].\n"), | |
11159 | (long) cu->header.offset.sect_off, (long) offset.sect_off, | |
11160 | bfd_get_filename (objfile->obfd)); | |
11161 | } | |
11162 | per_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
72bf9492 | 11163 | |
0d99eb77 DE |
11164 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
11165 | load_partial_comp_unit (per_cu); | |
ae038cb0 | 11166 | |
0d99eb77 DE |
11167 | per_cu->cu->last_used = 0; |
11168 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
11169 | } | |
5afb4e99 | 11170 | |
dee91e82 DE |
11171 | /* If we didn't find it, and not all dies have been loaded, |
11172 | load them all and try again. */ | |
11173 | ||
5afb4e99 DJ |
11174 | if (pd == NULL && per_cu->load_all_dies == 0) |
11175 | { | |
dee91e82 DE |
11176 | /* FIXME: The testsuite doesn't trigger this code path. |
11177 | http://sourceware.org/bugzilla/show_bug.cgi?id=13961 */ | |
5afb4e99 | 11178 | |
dee91e82 | 11179 | free_one_cached_comp_unit (per_cu); |
5afb4e99 | 11180 | per_cu->load_all_dies = 1; |
dee91e82 | 11181 | load_partial_comp_unit (per_cu); |
5afb4e99 DJ |
11182 | |
11183 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
11184 | } | |
11185 | ||
11186 | if (pd == NULL) | |
11187 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
11188 | _("could not find partial DIE 0x%x " |
11189 | "in cache [from module %s]\n"), | |
b64f50a1 | 11190 | offset.sect_off, bfd_get_filename (objfile->obfd)); |
5afb4e99 | 11191 | return pd; |
72bf9492 DJ |
11192 | } |
11193 | ||
abc72ce4 DE |
11194 | /* See if we can figure out if the class lives in a namespace. We do |
11195 | this by looking for a member function; its demangled name will | |
11196 | contain namespace info, if there is any. */ | |
11197 | ||
11198 | static void | |
11199 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
11200 | struct dwarf2_cu *cu) | |
11201 | { | |
11202 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
11203 | what template types look like, because the demangler | |
11204 | frequently doesn't give the same name as the debug info. We | |
11205 | could fix this by only using the demangled name to get the | |
11206 | prefix (but see comment in read_structure_type). */ | |
11207 | ||
11208 | struct partial_die_info *real_pdi; | |
11209 | struct partial_die_info *child_pdi; | |
11210 | ||
11211 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
11212 | we should not do this. We'll prepend the parent's fully qualified | |
11213 | name when we create the partial symbol. */ | |
11214 | ||
11215 | real_pdi = struct_pdi; | |
11216 | while (real_pdi->has_specification) | |
11217 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |
11218 | ||
11219 | if (real_pdi->die_parent != NULL) | |
11220 | return; | |
11221 | ||
11222 | for (child_pdi = struct_pdi->die_child; | |
11223 | child_pdi != NULL; | |
11224 | child_pdi = child_pdi->die_sibling) | |
11225 | { | |
11226 | if (child_pdi->tag == DW_TAG_subprogram | |
11227 | && child_pdi->linkage_name != NULL) | |
11228 | { | |
11229 | char *actual_class_name | |
11230 | = language_class_name_from_physname (cu->language_defn, | |
11231 | child_pdi->linkage_name); | |
11232 | if (actual_class_name != NULL) | |
11233 | { | |
11234 | struct_pdi->name | |
11235 | = obsavestring (actual_class_name, | |
11236 | strlen (actual_class_name), | |
11237 | &cu->objfile->objfile_obstack); | |
11238 | xfree (actual_class_name); | |
11239 | } | |
11240 | break; | |
11241 | } | |
11242 | } | |
11243 | } | |
11244 | ||
72bf9492 DJ |
11245 | /* Adjust PART_DIE before generating a symbol for it. This function |
11246 | may set the is_external flag or change the DIE's name. */ | |
11247 | ||
11248 | static void | |
11249 | fixup_partial_die (struct partial_die_info *part_die, | |
11250 | struct dwarf2_cu *cu) | |
11251 | { | |
abc72ce4 DE |
11252 | /* Once we've fixed up a die, there's no point in doing so again. |
11253 | This also avoids a memory leak if we were to call | |
11254 | guess_partial_die_structure_name multiple times. */ | |
11255 | if (part_die->fixup_called) | |
11256 | return; | |
11257 | ||
72bf9492 DJ |
11258 | /* If we found a reference attribute and the DIE has no name, try |
11259 | to find a name in the referred to DIE. */ | |
11260 | ||
11261 | if (part_die->name == NULL && part_die->has_specification) | |
11262 | { | |
11263 | struct partial_die_info *spec_die; | |
72bf9492 | 11264 | |
10b3939b | 11265 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 11266 | |
10b3939b | 11267 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
11268 | |
11269 | if (spec_die->name) | |
11270 | { | |
11271 | part_die->name = spec_die->name; | |
11272 | ||
11273 | /* Copy DW_AT_external attribute if it is set. */ | |
11274 | if (spec_die->is_external) | |
11275 | part_die->is_external = spec_die->is_external; | |
11276 | } | |
11277 | } | |
11278 | ||
11279 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
11280 | |
11281 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 11282 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 11283 | |
abc72ce4 DE |
11284 | /* If there is no parent die to provide a namespace, and there are |
11285 | children, see if we can determine the namespace from their linkage | |
122d1940 | 11286 | name. */ |
abc72ce4 | 11287 | if (cu->language == language_cplus |
8b70b953 | 11288 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
11289 | && part_die->die_parent == NULL |
11290 | && part_die->has_children | |
11291 | && (part_die->tag == DW_TAG_class_type | |
11292 | || part_die->tag == DW_TAG_structure_type | |
11293 | || part_die->tag == DW_TAG_union_type)) | |
11294 | guess_partial_die_structure_name (part_die, cu); | |
11295 | ||
53832f31 TT |
11296 | /* GCC might emit a nameless struct or union that has a linkage |
11297 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
11298 | if (part_die->name == NULL | |
96408a79 SA |
11299 | && (part_die->tag == DW_TAG_class_type |
11300 | || part_die->tag == DW_TAG_interface_type | |
11301 | || part_die->tag == DW_TAG_structure_type | |
11302 | || part_die->tag == DW_TAG_union_type) | |
53832f31 TT |
11303 | && part_die->linkage_name != NULL) |
11304 | { | |
11305 | char *demangled; | |
11306 | ||
11307 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
11308 | if (demangled) | |
11309 | { | |
96408a79 SA |
11310 | const char *base; |
11311 | ||
11312 | /* Strip any leading namespaces/classes, keep only the base name. | |
11313 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
11314 | base = strrchr (demangled, ':'); | |
11315 | if (base && base > demangled && base[-1] == ':') | |
11316 | base++; | |
11317 | else | |
11318 | base = demangled; | |
11319 | ||
11320 | part_die->name = obsavestring (base, strlen (base), | |
53832f31 TT |
11321 | &cu->objfile->objfile_obstack); |
11322 | xfree (demangled); | |
11323 | } | |
11324 | } | |
11325 | ||
abc72ce4 | 11326 | part_die->fixup_called = 1; |
72bf9492 DJ |
11327 | } |
11328 | ||
a8329558 | 11329 | /* Read an attribute value described by an attribute form. */ |
c906108c | 11330 | |
fe1b8b76 | 11331 | static gdb_byte * |
dee91e82 DE |
11332 | read_attribute_value (const struct die_reader_specs *reader, |
11333 | struct attribute *attr, unsigned form, | |
11334 | gdb_byte *info_ptr) | |
c906108c | 11335 | { |
dee91e82 DE |
11336 | struct dwarf2_cu *cu = reader->cu; |
11337 | bfd *abfd = reader->abfd; | |
e7c27a73 | 11338 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
11339 | unsigned int bytes_read; |
11340 | struct dwarf_block *blk; | |
11341 | ||
a8329558 KW |
11342 | attr->form = form; |
11343 | switch (form) | |
c906108c | 11344 | { |
c906108c | 11345 | case DW_FORM_ref_addr: |
ae411497 | 11346 | if (cu->header.version == 2) |
4568ecf9 | 11347 | DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
ae411497 | 11348 | else |
4568ecf9 DE |
11349 | DW_UNSND (attr) = read_offset (abfd, info_ptr, |
11350 | &cu->header, &bytes_read); | |
ae411497 TT |
11351 | info_ptr += bytes_read; |
11352 | break; | |
11353 | case DW_FORM_addr: | |
e7c27a73 | 11354 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 11355 | info_ptr += bytes_read; |
c906108c SS |
11356 | break; |
11357 | case DW_FORM_block2: | |
7b5a2f43 | 11358 | blk = dwarf_alloc_block (cu); |
c906108c SS |
11359 | blk->size = read_2_bytes (abfd, info_ptr); |
11360 | info_ptr += 2; | |
11361 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
11362 | info_ptr += blk->size; | |
11363 | DW_BLOCK (attr) = blk; | |
11364 | break; | |
11365 | case DW_FORM_block4: | |
7b5a2f43 | 11366 | blk = dwarf_alloc_block (cu); |
c906108c SS |
11367 | blk->size = read_4_bytes (abfd, info_ptr); |
11368 | info_ptr += 4; | |
11369 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
11370 | info_ptr += blk->size; | |
11371 | DW_BLOCK (attr) = blk; | |
11372 | break; | |
11373 | case DW_FORM_data2: | |
11374 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
11375 | info_ptr += 2; | |
11376 | break; | |
11377 | case DW_FORM_data4: | |
11378 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
11379 | info_ptr += 4; | |
11380 | break; | |
11381 | case DW_FORM_data8: | |
11382 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
11383 | info_ptr += 8; | |
11384 | break; | |
2dc7f7b3 TT |
11385 | case DW_FORM_sec_offset: |
11386 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
11387 | info_ptr += bytes_read; | |
11388 | break; | |
c906108c | 11389 | case DW_FORM_string: |
9b1c24c8 | 11390 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 11391 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
11392 | info_ptr += bytes_read; |
11393 | break; | |
4bdf3d34 JJ |
11394 | case DW_FORM_strp: |
11395 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
11396 | &bytes_read); | |
8285870a | 11397 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
11398 | info_ptr += bytes_read; |
11399 | break; | |
2dc7f7b3 | 11400 | case DW_FORM_exprloc: |
c906108c | 11401 | case DW_FORM_block: |
7b5a2f43 | 11402 | blk = dwarf_alloc_block (cu); |
c906108c SS |
11403 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
11404 | info_ptr += bytes_read; | |
11405 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
11406 | info_ptr += blk->size; | |
11407 | DW_BLOCK (attr) = blk; | |
11408 | break; | |
11409 | case DW_FORM_block1: | |
7b5a2f43 | 11410 | blk = dwarf_alloc_block (cu); |
c906108c SS |
11411 | blk->size = read_1_byte (abfd, info_ptr); |
11412 | info_ptr += 1; | |
11413 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
11414 | info_ptr += blk->size; | |
11415 | DW_BLOCK (attr) = blk; | |
11416 | break; | |
11417 | case DW_FORM_data1: | |
11418 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
11419 | info_ptr += 1; | |
11420 | break; | |
11421 | case DW_FORM_flag: | |
11422 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
11423 | info_ptr += 1; | |
11424 | break; | |
2dc7f7b3 TT |
11425 | case DW_FORM_flag_present: |
11426 | DW_UNSND (attr) = 1; | |
11427 | break; | |
c906108c SS |
11428 | case DW_FORM_sdata: |
11429 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
11430 | info_ptr += bytes_read; | |
11431 | break; | |
11432 | case DW_FORM_udata: | |
11433 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
11434 | info_ptr += bytes_read; | |
11435 | break; | |
11436 | case DW_FORM_ref1: | |
4568ecf9 DE |
11437 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11438 | + read_1_byte (abfd, info_ptr)); | |
c906108c SS |
11439 | info_ptr += 1; |
11440 | break; | |
11441 | case DW_FORM_ref2: | |
4568ecf9 DE |
11442 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11443 | + read_2_bytes (abfd, info_ptr)); | |
c906108c SS |
11444 | info_ptr += 2; |
11445 | break; | |
11446 | case DW_FORM_ref4: | |
4568ecf9 DE |
11447 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11448 | + read_4_bytes (abfd, info_ptr)); | |
c906108c SS |
11449 | info_ptr += 4; |
11450 | break; | |
613e1657 | 11451 | case DW_FORM_ref8: |
4568ecf9 DE |
11452 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11453 | + read_8_bytes (abfd, info_ptr)); | |
613e1657 KB |
11454 | info_ptr += 8; |
11455 | break; | |
55f1336d | 11456 | case DW_FORM_ref_sig8: |
348e048f DE |
11457 | /* Convert the signature to something we can record in DW_UNSND |
11458 | for later lookup. | |
11459 | NOTE: This is NULL if the type wasn't found. */ | |
11460 | DW_SIGNATURED_TYPE (attr) = | |
e319fa28 | 11461 | lookup_signatured_type (read_8_bytes (abfd, info_ptr)); |
348e048f DE |
11462 | info_ptr += 8; |
11463 | break; | |
c906108c | 11464 | case DW_FORM_ref_udata: |
4568ecf9 DE |
11465 | DW_UNSND (attr) = (cu->header.offset.sect_off |
11466 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
11467 | info_ptr += bytes_read; |
11468 | break; | |
c906108c | 11469 | case DW_FORM_indirect: |
a8329558 KW |
11470 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
11471 | info_ptr += bytes_read; | |
dee91e82 | 11472 | info_ptr = read_attribute_value (reader, attr, form, info_ptr); |
a8329558 | 11473 | break; |
3019eac3 DE |
11474 | case DW_FORM_GNU_addr_index: |
11475 | if (reader->dwo_file == NULL) | |
11476 | { | |
11477 | /* For now flag a hard error. | |
11478 | Later we can turn this into a complaint. */ | |
11479 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), | |
11480 | dwarf_form_name (form), | |
11481 | bfd_get_filename (abfd)); | |
11482 | } | |
11483 | DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read); | |
11484 | info_ptr += bytes_read; | |
11485 | break; | |
11486 | case DW_FORM_GNU_str_index: | |
11487 | if (reader->dwo_file == NULL) | |
11488 | { | |
11489 | /* For now flag a hard error. | |
11490 | Later we can turn this into a complaint if warranted. */ | |
11491 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), | |
11492 | dwarf_form_name (form), | |
11493 | bfd_get_filename (abfd)); | |
11494 | } | |
11495 | { | |
11496 | ULONGEST str_index = | |
11497 | read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
11498 | ||
11499 | DW_STRING (attr) = read_str_index (reader, cu, str_index); | |
11500 | DW_STRING_IS_CANONICAL (attr) = 0; | |
11501 | info_ptr += bytes_read; | |
11502 | } | |
11503 | break; | |
c906108c | 11504 | default: |
8a3fe4f8 | 11505 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
11506 | dwarf_form_name (form), |
11507 | bfd_get_filename (abfd)); | |
c906108c | 11508 | } |
28e94949 JB |
11509 | |
11510 | /* We have seen instances where the compiler tried to emit a byte | |
11511 | size attribute of -1 which ended up being encoded as an unsigned | |
11512 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
11513 | an object of this size seems pretty unlikely so we can relatively | |
11514 | safely treat these cases as if the size attribute was invalid and | |
11515 | treat them as zero by default. */ | |
11516 | if (attr->name == DW_AT_byte_size | |
11517 | && form == DW_FORM_data4 | |
11518 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
11519 | { |
11520 | complaint | |
11521 | (&symfile_complaints, | |
43bbcdc2 PH |
11522 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
11523 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
11524 | DW_UNSND (attr) = 0; |
11525 | } | |
28e94949 | 11526 | |
c906108c SS |
11527 | return info_ptr; |
11528 | } | |
11529 | ||
a8329558 KW |
11530 | /* Read an attribute described by an abbreviated attribute. */ |
11531 | ||
fe1b8b76 | 11532 | static gdb_byte * |
dee91e82 DE |
11533 | read_attribute (const struct die_reader_specs *reader, |
11534 | struct attribute *attr, struct attr_abbrev *abbrev, | |
11535 | gdb_byte *info_ptr) | |
a8329558 KW |
11536 | { |
11537 | attr->name = abbrev->name; | |
dee91e82 | 11538 | return read_attribute_value (reader, attr, abbrev->form, info_ptr); |
a8329558 KW |
11539 | } |
11540 | ||
0963b4bd | 11541 | /* Read dwarf information from a buffer. */ |
c906108c SS |
11542 | |
11543 | static unsigned int | |
fe1b8b76 | 11544 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 11545 | { |
fe1b8b76 | 11546 | return bfd_get_8 (abfd, buf); |
c906108c SS |
11547 | } |
11548 | ||
11549 | static int | |
fe1b8b76 | 11550 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 11551 | { |
fe1b8b76 | 11552 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
11553 | } |
11554 | ||
11555 | static unsigned int | |
fe1b8b76 | 11556 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 11557 | { |
fe1b8b76 | 11558 | return bfd_get_16 (abfd, buf); |
c906108c SS |
11559 | } |
11560 | ||
21ae7a4d JK |
11561 | static int |
11562 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) | |
11563 | { | |
11564 | return bfd_get_signed_16 (abfd, buf); | |
11565 | } | |
11566 | ||
c906108c | 11567 | static unsigned int |
fe1b8b76 | 11568 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 11569 | { |
fe1b8b76 | 11570 | return bfd_get_32 (abfd, buf); |
c906108c SS |
11571 | } |
11572 | ||
21ae7a4d JK |
11573 | static int |
11574 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) | |
11575 | { | |
11576 | return bfd_get_signed_32 (abfd, buf); | |
11577 | } | |
11578 | ||
93311388 | 11579 | static ULONGEST |
fe1b8b76 | 11580 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 11581 | { |
fe1b8b76 | 11582 | return bfd_get_64 (abfd, buf); |
c906108c SS |
11583 | } |
11584 | ||
11585 | static CORE_ADDR | |
fe1b8b76 | 11586 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 11587 | unsigned int *bytes_read) |
c906108c | 11588 | { |
e7c27a73 | 11589 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
11590 | CORE_ADDR retval = 0; |
11591 | ||
107d2387 | 11592 | if (cu_header->signed_addr_p) |
c906108c | 11593 | { |
107d2387 AC |
11594 | switch (cu_header->addr_size) |
11595 | { | |
11596 | case 2: | |
fe1b8b76 | 11597 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
11598 | break; |
11599 | case 4: | |
fe1b8b76 | 11600 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
11601 | break; |
11602 | case 8: | |
fe1b8b76 | 11603 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
11604 | break; |
11605 | default: | |
8e65ff28 | 11606 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 11607 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 11608 | bfd_get_filename (abfd)); |
107d2387 AC |
11609 | } |
11610 | } | |
11611 | else | |
11612 | { | |
11613 | switch (cu_header->addr_size) | |
11614 | { | |
11615 | case 2: | |
fe1b8b76 | 11616 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
11617 | break; |
11618 | case 4: | |
fe1b8b76 | 11619 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
11620 | break; |
11621 | case 8: | |
fe1b8b76 | 11622 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
11623 | break; |
11624 | default: | |
8e65ff28 | 11625 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
11626 | _("read_address: bad switch, " |
11627 | "unsigned [in module %s]"), | |
659b0389 | 11628 | bfd_get_filename (abfd)); |
107d2387 | 11629 | } |
c906108c | 11630 | } |
64367e0a | 11631 | |
107d2387 AC |
11632 | *bytes_read = cu_header->addr_size; |
11633 | return retval; | |
c906108c SS |
11634 | } |
11635 | ||
f7ef9339 | 11636 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
11637 | specification allows the initial length to take up either 4 bytes |
11638 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
11639 | bytes describe the length and all offsets will be 8 bytes in length | |
11640 | instead of 4. | |
11641 | ||
f7ef9339 KB |
11642 | An older, non-standard 64-bit format is also handled by this |
11643 | function. The older format in question stores the initial length | |
11644 | as an 8-byte quantity without an escape value. Lengths greater | |
11645 | than 2^32 aren't very common which means that the initial 4 bytes | |
11646 | is almost always zero. Since a length value of zero doesn't make | |
11647 | sense for the 32-bit format, this initial zero can be considered to | |
11648 | be an escape value which indicates the presence of the older 64-bit | |
11649 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
11650 | greater than 4GB. If it becomes necessary to handle lengths |
11651 | somewhat larger than 4GB, we could allow other small values (such | |
11652 | as the non-sensical values of 1, 2, and 3) to also be used as | |
11653 | escape values indicating the presence of the old format. | |
f7ef9339 | 11654 | |
917c78fc MK |
11655 | The value returned via bytes_read should be used to increment the |
11656 | relevant pointer after calling read_initial_length(). | |
c764a876 | 11657 | |
613e1657 KB |
11658 | [ Note: read_initial_length() and read_offset() are based on the |
11659 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 11660 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
11661 | from: |
11662 | ||
f7ef9339 | 11663 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 11664 | |
613e1657 KB |
11665 | This document is only a draft and is subject to change. (So beware.) |
11666 | ||
f7ef9339 | 11667 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
11668 | determined empirically by examining 64-bit ELF files produced by |
11669 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
11670 | |
11671 | - Kevin, July 16, 2002 | |
613e1657 KB |
11672 | ] */ |
11673 | ||
11674 | static LONGEST | |
c764a876 | 11675 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 11676 | { |
fe1b8b76 | 11677 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 11678 | |
dd373385 | 11679 | if (length == 0xffffffff) |
613e1657 | 11680 | { |
fe1b8b76 | 11681 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 11682 | *bytes_read = 12; |
613e1657 | 11683 | } |
dd373385 | 11684 | else if (length == 0) |
f7ef9339 | 11685 | { |
dd373385 | 11686 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 11687 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 11688 | *bytes_read = 8; |
f7ef9339 | 11689 | } |
613e1657 KB |
11690 | else |
11691 | { | |
11692 | *bytes_read = 4; | |
613e1657 KB |
11693 | } |
11694 | ||
c764a876 DE |
11695 | return length; |
11696 | } | |
dd373385 | 11697 | |
c764a876 DE |
11698 | /* Cover function for read_initial_length. |
11699 | Returns the length of the object at BUF, and stores the size of the | |
11700 | initial length in *BYTES_READ and stores the size that offsets will be in | |
11701 | *OFFSET_SIZE. | |
11702 | If the initial length size is not equivalent to that specified in | |
11703 | CU_HEADER then issue a complaint. | |
11704 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 11705 | |
c764a876 DE |
11706 | static LONGEST |
11707 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
11708 | const struct comp_unit_head *cu_header, | |
11709 | unsigned int *bytes_read, | |
11710 | unsigned int *offset_size) | |
11711 | { | |
11712 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
11713 | ||
11714 | gdb_assert (cu_header->initial_length_size == 4 | |
11715 | || cu_header->initial_length_size == 8 | |
11716 | || cu_header->initial_length_size == 12); | |
11717 | ||
11718 | if (cu_header->initial_length_size != *bytes_read) | |
11719 | complaint (&symfile_complaints, | |
11720 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 11721 | |
c764a876 | 11722 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 11723 | return length; |
613e1657 KB |
11724 | } |
11725 | ||
11726 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 11727 | given by cu_header->offset_size. */ |
613e1657 KB |
11728 | |
11729 | static LONGEST | |
fe1b8b76 | 11730 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 11731 | unsigned int *bytes_read) |
c764a876 DE |
11732 | { |
11733 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 11734 | |
c764a876 DE |
11735 | *bytes_read = cu_header->offset_size; |
11736 | return offset; | |
11737 | } | |
11738 | ||
11739 | /* Read an offset from the data stream. */ | |
11740 | ||
11741 | static LONGEST | |
11742 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
11743 | { |
11744 | LONGEST retval = 0; | |
11745 | ||
c764a876 | 11746 | switch (offset_size) |
613e1657 KB |
11747 | { |
11748 | case 4: | |
fe1b8b76 | 11749 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
11750 | break; |
11751 | case 8: | |
fe1b8b76 | 11752 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
11753 | break; |
11754 | default: | |
8e65ff28 | 11755 | internal_error (__FILE__, __LINE__, |
c764a876 | 11756 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 11757 | bfd_get_filename (abfd)); |
613e1657 KB |
11758 | } |
11759 | ||
917c78fc | 11760 | return retval; |
613e1657 KB |
11761 | } |
11762 | ||
fe1b8b76 JB |
11763 | static gdb_byte * |
11764 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
11765 | { |
11766 | /* If the size of a host char is 8 bits, we can return a pointer | |
11767 | to the buffer, otherwise we have to copy the data to a buffer | |
11768 | allocated on the temporary obstack. */ | |
4bdf3d34 | 11769 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 11770 | return buf; |
c906108c SS |
11771 | } |
11772 | ||
11773 | static char * | |
9b1c24c8 | 11774 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
11775 | { |
11776 | /* If the size of a host char is 8 bits, we can return a pointer | |
11777 | to the string, otherwise we have to copy the string to a buffer | |
11778 | allocated on the temporary obstack. */ | |
4bdf3d34 | 11779 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
11780 | if (*buf == '\0') |
11781 | { | |
11782 | *bytes_read_ptr = 1; | |
11783 | return NULL; | |
11784 | } | |
fe1b8b76 JB |
11785 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
11786 | return (char *) buf; | |
4bdf3d34 JJ |
11787 | } |
11788 | ||
11789 | static char * | |
cf2c3c16 | 11790 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
4bdf3d34 | 11791 | { |
be391dca | 11792 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 11793 | if (dwarf2_per_objfile->str.buffer == NULL) |
cf2c3c16 TT |
11794 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
11795 | bfd_get_filename (abfd)); | |
dce234bc | 11796 | if (str_offset >= dwarf2_per_objfile->str.size) |
cf2c3c16 TT |
11797 | error (_("DW_FORM_strp pointing outside of " |
11798 | ".debug_str section [in module %s]"), | |
11799 | bfd_get_filename (abfd)); | |
4bdf3d34 | 11800 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 11801 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 11802 | return NULL; |
dce234bc | 11803 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
11804 | } |
11805 | ||
cf2c3c16 TT |
11806 | static char * |
11807 | read_indirect_string (bfd *abfd, gdb_byte *buf, | |
11808 | const struct comp_unit_head *cu_header, | |
11809 | unsigned int *bytes_read_ptr) | |
11810 | { | |
11811 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
11812 | ||
11813 | return read_indirect_string_at_offset (abfd, str_offset); | |
11814 | } | |
11815 | ||
12df843f | 11816 | static ULONGEST |
fe1b8b76 | 11817 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 11818 | { |
12df843f | 11819 | ULONGEST result; |
ce5d95e1 | 11820 | unsigned int num_read; |
c906108c SS |
11821 | int i, shift; |
11822 | unsigned char byte; | |
11823 | ||
11824 | result = 0; | |
11825 | shift = 0; | |
11826 | num_read = 0; | |
11827 | i = 0; | |
11828 | while (1) | |
11829 | { | |
fe1b8b76 | 11830 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
11831 | buf++; |
11832 | num_read++; | |
12df843f | 11833 | result |= ((ULONGEST) (byte & 127) << shift); |
c906108c SS |
11834 | if ((byte & 128) == 0) |
11835 | { | |
11836 | break; | |
11837 | } | |
11838 | shift += 7; | |
11839 | } | |
11840 | *bytes_read_ptr = num_read; | |
11841 | return result; | |
11842 | } | |
11843 | ||
12df843f | 11844 | static LONGEST |
fe1b8b76 | 11845 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 11846 | { |
12df843f | 11847 | LONGEST result; |
77e0b926 | 11848 | int i, shift, num_read; |
c906108c SS |
11849 | unsigned char byte; |
11850 | ||
11851 | result = 0; | |
11852 | shift = 0; | |
c906108c SS |
11853 | num_read = 0; |
11854 | i = 0; | |
11855 | while (1) | |
11856 | { | |
fe1b8b76 | 11857 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
11858 | buf++; |
11859 | num_read++; | |
12df843f | 11860 | result |= ((LONGEST) (byte & 127) << shift); |
c906108c SS |
11861 | shift += 7; |
11862 | if ((byte & 128) == 0) | |
11863 | { | |
11864 | break; | |
11865 | } | |
11866 | } | |
77e0b926 | 11867 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
12df843f | 11868 | result |= -(((LONGEST) 1) << shift); |
c906108c SS |
11869 | *bytes_read_ptr = num_read; |
11870 | return result; | |
11871 | } | |
11872 | ||
3019eac3 DE |
11873 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. |
11874 | ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero. | |
11875 | ADDR_SIZE is the size of addresses from the CU header. */ | |
11876 | ||
11877 | static CORE_ADDR | |
11878 | read_addr_index_1 (unsigned int addr_index, ULONGEST addr_base, int addr_size) | |
11879 | { | |
11880 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
11881 | bfd *abfd = objfile->obfd; | |
11882 | const gdb_byte *info_ptr; | |
11883 | ||
11884 | dwarf2_read_section (objfile, &dwarf2_per_objfile->addr); | |
11885 | if (dwarf2_per_objfile->addr.buffer == NULL) | |
11886 | error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"), | |
11887 | objfile->name); | |
11888 | if (addr_base + addr_index * addr_size >= dwarf2_per_objfile->addr.size) | |
11889 | error (_("DW_FORM_addr_index pointing outside of " | |
11890 | ".debug_addr section [in module %s]"), | |
11891 | objfile->name); | |
11892 | info_ptr = (dwarf2_per_objfile->addr.buffer | |
11893 | + addr_base + addr_index * addr_size); | |
11894 | if (addr_size == 4) | |
11895 | return bfd_get_32 (abfd, info_ptr); | |
11896 | else | |
11897 | return bfd_get_64 (abfd, info_ptr); | |
11898 | } | |
11899 | ||
11900 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. */ | |
11901 | ||
11902 | static CORE_ADDR | |
11903 | read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index) | |
11904 | { | |
11905 | return read_addr_index_1 (addr_index, cu->addr_base, cu->header.addr_size); | |
11906 | } | |
11907 | ||
11908 | /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */ | |
11909 | ||
11910 | static CORE_ADDR | |
11911 | read_addr_index_from_leb128 (struct dwarf2_cu *cu, gdb_byte *info_ptr, | |
11912 | unsigned int *bytes_read) | |
11913 | { | |
11914 | bfd *abfd = cu->objfile->obfd; | |
11915 | unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
11916 | ||
11917 | return read_addr_index (cu, addr_index); | |
11918 | } | |
11919 | ||
11920 | /* Data structure to pass results from dwarf2_read_addr_index_reader | |
11921 | back to dwarf2_read_addr_index. */ | |
11922 | ||
11923 | struct dwarf2_read_addr_index_data | |
11924 | { | |
11925 | ULONGEST addr_base; | |
11926 | int addr_size; | |
11927 | }; | |
11928 | ||
11929 | /* die_reader_func for dwarf2_read_addr_index. */ | |
11930 | ||
11931 | static void | |
11932 | dwarf2_read_addr_index_reader (const struct die_reader_specs *reader, | |
11933 | gdb_byte *info_ptr, | |
11934 | struct die_info *comp_unit_die, | |
11935 | int has_children, | |
11936 | void *data) | |
11937 | { | |
11938 | struct dwarf2_cu *cu = reader->cu; | |
11939 | struct dwarf2_read_addr_index_data *aidata = | |
11940 | (struct dwarf2_read_addr_index_data *) data; | |
11941 | ||
11942 | aidata->addr_base = cu->addr_base; | |
11943 | aidata->addr_size = cu->header.addr_size; | |
11944 | } | |
11945 | ||
11946 | /* Given an index in .debug_addr, fetch the value. | |
11947 | NOTE: This can be called during dwarf expression evaluation, | |
11948 | long after the debug information has been read, and thus per_cu->cu | |
11949 | may no longer exist. */ | |
11950 | ||
11951 | CORE_ADDR | |
11952 | dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu, | |
11953 | unsigned int addr_index) | |
11954 | { | |
11955 | struct objfile *objfile = per_cu->objfile; | |
11956 | struct dwarf2_cu *cu = per_cu->cu; | |
11957 | ULONGEST addr_base; | |
11958 | int addr_size; | |
11959 | ||
11960 | /* This is intended to be called from outside this file. */ | |
11961 | dw2_setup (objfile); | |
11962 | ||
11963 | /* We need addr_base and addr_size. | |
11964 | If we don't have PER_CU->cu, we have to get it. | |
11965 | Nasty, but the alternative is storing the needed info in PER_CU, | |
11966 | which at this point doesn't seem justified: it's not clear how frequently | |
11967 | it would get used and it would increase the size of every PER_CU. | |
11968 | Entry points like dwarf2_per_cu_addr_size do a similar thing | |
11969 | so we're not in uncharted territory here. | |
11970 | Alas we need to be a bit more complicated as addr_base is contained | |
11971 | in the DIE. | |
11972 | ||
11973 | We don't need to read the entire CU(/TU). | |
11974 | We just need the header and top level die. | |
11975 | IWBN to use the aging mechanism to let us lazily later discard the CU. | |
11976 | See however init_cutu_and_read_dies_simple. */ | |
11977 | ||
11978 | if (cu != NULL) | |
11979 | { | |
11980 | addr_base = cu->addr_base; | |
11981 | addr_size = cu->header.addr_size; | |
11982 | } | |
11983 | else | |
11984 | { | |
11985 | struct dwarf2_read_addr_index_data aidata; | |
11986 | ||
11987 | init_cutu_and_read_dies_simple (per_cu, dwarf2_read_addr_index_reader, | |
11988 | &aidata); | |
11989 | addr_base = aidata.addr_base; | |
11990 | addr_size = aidata.addr_size; | |
11991 | } | |
11992 | ||
11993 | return read_addr_index_1 (addr_index, addr_base, addr_size); | |
11994 | } | |
11995 | ||
11996 | /* Given a DW_AT_str_index, fetch the string. */ | |
11997 | ||
11998 | static char * | |
11999 | read_str_index (const struct die_reader_specs *reader, | |
12000 | struct dwarf2_cu *cu, ULONGEST str_index) | |
12001 | { | |
12002 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
12003 | const char *dwo_name = objfile->name; | |
12004 | bfd *abfd = objfile->obfd; | |
12005 | struct dwo_sections *sections = &reader->dwo_file->sections; | |
12006 | gdb_byte *info_ptr; | |
12007 | ULONGEST str_offset; | |
12008 | ||
12009 | dwarf2_read_section (objfile, §ions->str); | |
12010 | dwarf2_read_section (objfile, §ions->str_offsets); | |
12011 | if (sections->str.buffer == NULL) | |
12012 | error (_("DW_FORM_str_index used without .debug_str.dwo section" | |
12013 | " in CU at offset 0x%lx [in module %s]"), | |
12014 | (long) cu->header.offset.sect_off, dwo_name); | |
12015 | if (sections->str_offsets.buffer == NULL) | |
12016 | error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section" | |
12017 | " in CU at offset 0x%lx [in module %s]"), | |
12018 | (long) cu->header.offset.sect_off, dwo_name); | |
12019 | if (str_index * cu->header.offset_size >= sections->str_offsets.size) | |
12020 | error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo" | |
12021 | " section in CU at offset 0x%lx [in module %s]"), | |
12022 | (long) cu->header.offset.sect_off, dwo_name); | |
12023 | info_ptr = (sections->str_offsets.buffer | |
12024 | + str_index * cu->header.offset_size); | |
12025 | if (cu->header.offset_size == 4) | |
12026 | str_offset = bfd_get_32 (abfd, info_ptr); | |
12027 | else | |
12028 | str_offset = bfd_get_64 (abfd, info_ptr); | |
12029 | if (str_offset >= sections->str.size) | |
12030 | error (_("Offset from DW_FORM_str_index pointing outside of" | |
12031 | " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"), | |
12032 | (long) cu->header.offset.sect_off, dwo_name); | |
12033 | return (char *) (sections->str.buffer + str_offset); | |
12034 | } | |
12035 | ||
4bb7a0a7 DJ |
12036 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
12037 | ||
fe1b8b76 JB |
12038 | static gdb_byte * |
12039 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
12040 | { |
12041 | int byte; | |
12042 | ||
12043 | while (1) | |
12044 | { | |
fe1b8b76 | 12045 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
12046 | buf++; |
12047 | if ((byte & 128) == 0) | |
12048 | return buf; | |
12049 | } | |
12050 | } | |
12051 | ||
3019eac3 DE |
12052 | /* Return the length of an LEB128 number in BUF. */ |
12053 | ||
12054 | static int | |
12055 | leb128_size (const gdb_byte *buf) | |
12056 | { | |
12057 | const gdb_byte *begin = buf; | |
12058 | gdb_byte byte; | |
12059 | ||
12060 | while (1) | |
12061 | { | |
12062 | byte = *buf++; | |
12063 | if ((byte & 128) == 0) | |
12064 | return buf - begin; | |
12065 | } | |
12066 | } | |
12067 | ||
c906108c | 12068 | static void |
e142c38c | 12069 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
12070 | { |
12071 | switch (lang) | |
12072 | { | |
12073 | case DW_LANG_C89: | |
76bee0cc | 12074 | case DW_LANG_C99: |
c906108c | 12075 | case DW_LANG_C: |
e142c38c | 12076 | cu->language = language_c; |
c906108c SS |
12077 | break; |
12078 | case DW_LANG_C_plus_plus: | |
e142c38c | 12079 | cu->language = language_cplus; |
c906108c | 12080 | break; |
6aecb9c2 JB |
12081 | case DW_LANG_D: |
12082 | cu->language = language_d; | |
12083 | break; | |
c906108c SS |
12084 | case DW_LANG_Fortran77: |
12085 | case DW_LANG_Fortran90: | |
b21b22e0 | 12086 | case DW_LANG_Fortran95: |
e142c38c | 12087 | cu->language = language_fortran; |
c906108c | 12088 | break; |
a766d390 DE |
12089 | case DW_LANG_Go: |
12090 | cu->language = language_go; | |
12091 | break; | |
c906108c | 12092 | case DW_LANG_Mips_Assembler: |
e142c38c | 12093 | cu->language = language_asm; |
c906108c | 12094 | break; |
bebd888e | 12095 | case DW_LANG_Java: |
e142c38c | 12096 | cu->language = language_java; |
bebd888e | 12097 | break; |
c906108c | 12098 | case DW_LANG_Ada83: |
8aaf0b47 | 12099 | case DW_LANG_Ada95: |
bc5f45f8 JB |
12100 | cu->language = language_ada; |
12101 | break; | |
72019c9c GM |
12102 | case DW_LANG_Modula2: |
12103 | cu->language = language_m2; | |
12104 | break; | |
fe8e67fd PM |
12105 | case DW_LANG_Pascal83: |
12106 | cu->language = language_pascal; | |
12107 | break; | |
22566fbd DJ |
12108 | case DW_LANG_ObjC: |
12109 | cu->language = language_objc; | |
12110 | break; | |
c906108c SS |
12111 | case DW_LANG_Cobol74: |
12112 | case DW_LANG_Cobol85: | |
c906108c | 12113 | default: |
e142c38c | 12114 | cu->language = language_minimal; |
c906108c SS |
12115 | break; |
12116 | } | |
e142c38c | 12117 | cu->language_defn = language_def (cu->language); |
c906108c SS |
12118 | } |
12119 | ||
12120 | /* Return the named attribute or NULL if not there. */ | |
12121 | ||
12122 | static struct attribute * | |
e142c38c | 12123 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c | 12124 | { |
a48e046c | 12125 | for (;;) |
c906108c | 12126 | { |
a48e046c TT |
12127 | unsigned int i; |
12128 | struct attribute *spec = NULL; | |
12129 | ||
12130 | for (i = 0; i < die->num_attrs; ++i) | |
12131 | { | |
12132 | if (die->attrs[i].name == name) | |
12133 | return &die->attrs[i]; | |
12134 | if (die->attrs[i].name == DW_AT_specification | |
12135 | || die->attrs[i].name == DW_AT_abstract_origin) | |
12136 | spec = &die->attrs[i]; | |
12137 | } | |
12138 | ||
12139 | if (!spec) | |
12140 | break; | |
c906108c | 12141 | |
f2f0e013 | 12142 | die = follow_die_ref (die, spec, &cu); |
f2f0e013 | 12143 | } |
c5aa993b | 12144 | |
c906108c SS |
12145 | return NULL; |
12146 | } | |
12147 | ||
348e048f DE |
12148 | /* Return the named attribute or NULL if not there, |
12149 | but do not follow DW_AT_specification, etc. | |
12150 | This is for use in contexts where we're reading .debug_types dies. | |
12151 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
12152 | back up the chain, and we want to go down. */ | |
12153 | ||
12154 | static struct attribute * | |
12155 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
12156 | struct dwarf2_cu *cu) | |
12157 | { | |
12158 | unsigned int i; | |
12159 | ||
12160 | for (i = 0; i < die->num_attrs; ++i) | |
12161 | if (die->attrs[i].name == name) | |
12162 | return &die->attrs[i]; | |
12163 | ||
12164 | return NULL; | |
12165 | } | |
12166 | ||
05cf31d1 JB |
12167 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
12168 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 12169 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
12170 | |
12171 | static int | |
12172 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
12173 | { | |
12174 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
12175 | ||
12176 | return (attr && DW_UNSND (attr)); | |
12177 | } | |
12178 | ||
3ca72b44 | 12179 | static int |
e142c38c | 12180 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 12181 | { |
05cf31d1 JB |
12182 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
12183 | which value is non-zero. However, we have to be careful with | |
12184 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
12185 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
12186 | end up accidently finding a declaration attribute that belongs | |
12187 | to a different DIE referenced by the specification attribute, | |
12188 | even though the given DIE does not have a declaration attribute. */ | |
12189 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
12190 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
12191 | } |
12192 | ||
63d06c5c | 12193 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 12194 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
12195 | containing the return value on output. If there is no |
12196 | specification, but there is an abstract origin, that is | |
12197 | returned. */ | |
63d06c5c DC |
12198 | |
12199 | static struct die_info * | |
f2f0e013 | 12200 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 12201 | { |
f2f0e013 DJ |
12202 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
12203 | *spec_cu); | |
63d06c5c | 12204 | |
edb3359d DJ |
12205 | if (spec_attr == NULL) |
12206 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
12207 | ||
63d06c5c DC |
12208 | if (spec_attr == NULL) |
12209 | return NULL; | |
12210 | else | |
f2f0e013 | 12211 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 12212 | } |
c906108c | 12213 | |
debd256d | 12214 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
12215 | refers to. |
12216 | NOTE: This is also used as a "cleanup" function. */ | |
12217 | ||
debd256d JB |
12218 | static void |
12219 | free_line_header (struct line_header *lh) | |
12220 | { | |
12221 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 12222 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
12223 | |
12224 | /* Remember that all the lh->file_names[i].name pointers are | |
12225 | pointers into debug_line_buffer, and don't need to be freed. */ | |
12226 | if (lh->file_names) | |
a8bc7b56 | 12227 | xfree (lh->file_names); |
debd256d JB |
12228 | |
12229 | /* Similarly for the include directory names. */ | |
12230 | if (lh->include_dirs) | |
a8bc7b56 | 12231 | xfree (lh->include_dirs); |
debd256d | 12232 | |
a8bc7b56 | 12233 | xfree (lh); |
debd256d JB |
12234 | } |
12235 | ||
debd256d | 12236 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 12237 | |
debd256d JB |
12238 | static void |
12239 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 12240 | { |
debd256d JB |
12241 | /* Grow the array if necessary. */ |
12242 | if (lh->include_dirs_size == 0) | |
c5aa993b | 12243 | { |
debd256d JB |
12244 | lh->include_dirs_size = 1; /* for testing */ |
12245 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
12246 | * sizeof (*lh->include_dirs)); | |
12247 | } | |
12248 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
12249 | { | |
12250 | lh->include_dirs_size *= 2; | |
12251 | lh->include_dirs = xrealloc (lh->include_dirs, | |
12252 | (lh->include_dirs_size | |
12253 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 12254 | } |
c906108c | 12255 | |
debd256d JB |
12256 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
12257 | } | |
6e70227d | 12258 | |
debd256d | 12259 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 12260 | |
debd256d JB |
12261 | static void |
12262 | add_file_name (struct line_header *lh, | |
12263 | char *name, | |
12264 | unsigned int dir_index, | |
12265 | unsigned int mod_time, | |
12266 | unsigned int length) | |
12267 | { | |
12268 | struct file_entry *fe; | |
12269 | ||
12270 | /* Grow the array if necessary. */ | |
12271 | if (lh->file_names_size == 0) | |
12272 | { | |
12273 | lh->file_names_size = 1; /* for testing */ | |
12274 | lh->file_names = xmalloc (lh->file_names_size | |
12275 | * sizeof (*lh->file_names)); | |
12276 | } | |
12277 | else if (lh->num_file_names >= lh->file_names_size) | |
12278 | { | |
12279 | lh->file_names_size *= 2; | |
12280 | lh->file_names = xrealloc (lh->file_names, | |
12281 | (lh->file_names_size | |
12282 | * sizeof (*lh->file_names))); | |
12283 | } | |
12284 | ||
12285 | fe = &lh->file_names[lh->num_file_names++]; | |
12286 | fe->name = name; | |
12287 | fe->dir_index = dir_index; | |
12288 | fe->mod_time = mod_time; | |
12289 | fe->length = length; | |
aaa75496 | 12290 | fe->included_p = 0; |
cb1df416 | 12291 | fe->symtab = NULL; |
debd256d | 12292 | } |
6e70227d | 12293 | |
debd256d | 12294 | /* Read the statement program header starting at OFFSET in |
3019eac3 | 12295 | .debug_line, or .debug_line.dwo. Return a pointer |
6502dd73 | 12296 | to a struct line_header, allocated using xmalloc. |
debd256d JB |
12297 | |
12298 | NOTE: the strings in the include directory and file name tables of | |
3019eac3 DE |
12299 | the returned object point into the dwarf line section buffer, |
12300 | and must not be freed. */ | |
ae2de4f8 | 12301 | |
debd256d | 12302 | static struct line_header * |
3019eac3 | 12303 | dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu) |
debd256d JB |
12304 | { |
12305 | struct cleanup *back_to; | |
12306 | struct line_header *lh; | |
fe1b8b76 | 12307 | gdb_byte *line_ptr; |
c764a876 | 12308 | unsigned int bytes_read, offset_size; |
debd256d JB |
12309 | int i; |
12310 | char *cur_dir, *cur_file; | |
3019eac3 DE |
12311 | struct dwarf2_section_info *section; |
12312 | bfd *abfd; | |
12313 | ||
12314 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the | |
12315 | DWO file. */ | |
12316 | if (cu->dwo_unit && cu->per_cu->is_debug_types) | |
12317 | section = &cu->dwo_unit->dwo_file->sections.line; | |
12318 | else | |
12319 | section = &dwarf2_per_objfile->line; | |
12320 | abfd = section->asection->owner; | |
debd256d | 12321 | |
3019eac3 DE |
12322 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); |
12323 | if (section->buffer == NULL) | |
debd256d | 12324 | { |
3019eac3 DE |
12325 | if (cu->dwo_unit && cu->per_cu->is_debug_types) |
12326 | complaint (&symfile_complaints, _("missing .debug_line.dwo section")); | |
12327 | else | |
12328 | complaint (&symfile_complaints, _("missing .debug_line section")); | |
debd256d JB |
12329 | return 0; |
12330 | } | |
12331 | ||
a738430d MK |
12332 | /* Make sure that at least there's room for the total_length field. |
12333 | That could be 12 bytes long, but we're just going to fudge that. */ | |
3019eac3 | 12334 | if (offset + 4 >= section->size) |
debd256d | 12335 | { |
4d3c2250 | 12336 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
12337 | return 0; |
12338 | } | |
12339 | ||
12340 | lh = xmalloc (sizeof (*lh)); | |
12341 | memset (lh, 0, sizeof (*lh)); | |
12342 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
12343 | (void *) lh); | |
12344 | ||
3019eac3 | 12345 | line_ptr = section->buffer + offset; |
debd256d | 12346 | |
a738430d | 12347 | /* Read in the header. */ |
6e70227d | 12348 | lh->total_length = |
c764a876 DE |
12349 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
12350 | &bytes_read, &offset_size); | |
debd256d | 12351 | line_ptr += bytes_read; |
3019eac3 | 12352 | if (line_ptr + lh->total_length > (section->buffer + section->size)) |
debd256d | 12353 | { |
4d3c2250 | 12354 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
12355 | return 0; |
12356 | } | |
12357 | lh->statement_program_end = line_ptr + lh->total_length; | |
12358 | lh->version = read_2_bytes (abfd, line_ptr); | |
12359 | line_ptr += 2; | |
c764a876 DE |
12360 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
12361 | line_ptr += offset_size; | |
debd256d JB |
12362 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
12363 | line_ptr += 1; | |
2dc7f7b3 TT |
12364 | if (lh->version >= 4) |
12365 | { | |
12366 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
12367 | line_ptr += 1; | |
12368 | } | |
12369 | else | |
12370 | lh->maximum_ops_per_instruction = 1; | |
12371 | ||
12372 | if (lh->maximum_ops_per_instruction == 0) | |
12373 | { | |
12374 | lh->maximum_ops_per_instruction = 1; | |
12375 | complaint (&symfile_complaints, | |
3e43a32a MS |
12376 | _("invalid maximum_ops_per_instruction " |
12377 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
12378 | } |
12379 | ||
debd256d JB |
12380 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
12381 | line_ptr += 1; | |
12382 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
12383 | line_ptr += 1; | |
12384 | lh->line_range = read_1_byte (abfd, line_ptr); | |
12385 | line_ptr += 1; | |
12386 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
12387 | line_ptr += 1; | |
12388 | lh->standard_opcode_lengths | |
fe1b8b76 | 12389 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
12390 | |
12391 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
12392 | for (i = 1; i < lh->opcode_base; ++i) | |
12393 | { | |
12394 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
12395 | line_ptr += 1; | |
12396 | } | |
12397 | ||
a738430d | 12398 | /* Read directory table. */ |
9b1c24c8 | 12399 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
12400 | { |
12401 | line_ptr += bytes_read; | |
12402 | add_include_dir (lh, cur_dir); | |
12403 | } | |
12404 | line_ptr += bytes_read; | |
12405 | ||
a738430d | 12406 | /* Read file name table. */ |
9b1c24c8 | 12407 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
12408 | { |
12409 | unsigned int dir_index, mod_time, length; | |
12410 | ||
12411 | line_ptr += bytes_read; | |
12412 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12413 | line_ptr += bytes_read; | |
12414 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12415 | line_ptr += bytes_read; | |
12416 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12417 | line_ptr += bytes_read; | |
12418 | ||
12419 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
12420 | } | |
12421 | line_ptr += bytes_read; | |
6e70227d | 12422 | lh->statement_program_start = line_ptr; |
debd256d | 12423 | |
3019eac3 | 12424 | if (line_ptr > (section->buffer + section->size)) |
4d3c2250 | 12425 | complaint (&symfile_complaints, |
3e43a32a MS |
12426 | _("line number info header doesn't " |
12427 | "fit in `.debug_line' section")); | |
debd256d JB |
12428 | |
12429 | discard_cleanups (back_to); | |
12430 | return lh; | |
12431 | } | |
c906108c | 12432 | |
c6da4cef DE |
12433 | /* Subroutine of dwarf_decode_lines to simplify it. |
12434 | Return the file name of the psymtab for included file FILE_INDEX | |
12435 | in line header LH of PST. | |
12436 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
12437 | If space for the result is malloc'd, it will be freed by a cleanup. | |
12438 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
12439 | ||
12440 | static char * | |
12441 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
12442 | const struct partial_symtab *pst, | |
12443 | const char *comp_dir) | |
12444 | { | |
12445 | const struct file_entry fe = lh->file_names [file_index]; | |
12446 | char *include_name = fe.name; | |
12447 | char *include_name_to_compare = include_name; | |
12448 | char *dir_name = NULL; | |
72b9f47f TT |
12449 | const char *pst_filename; |
12450 | char *copied_name = NULL; | |
c6da4cef DE |
12451 | int file_is_pst; |
12452 | ||
12453 | if (fe.dir_index) | |
12454 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
12455 | ||
12456 | if (!IS_ABSOLUTE_PATH (include_name) | |
12457 | && (dir_name != NULL || comp_dir != NULL)) | |
12458 | { | |
12459 | /* Avoid creating a duplicate psymtab for PST. | |
12460 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
12461 | Before we do the comparison, however, we need to account | |
12462 | for DIR_NAME and COMP_DIR. | |
12463 | First prepend dir_name (if non-NULL). If we still don't | |
12464 | have an absolute path prepend comp_dir (if non-NULL). | |
12465 | However, the directory we record in the include-file's | |
12466 | psymtab does not contain COMP_DIR (to match the | |
12467 | corresponding symtab(s)). | |
12468 | ||
12469 | Example: | |
12470 | ||
12471 | bash$ cd /tmp | |
12472 | bash$ gcc -g ./hello.c | |
12473 | include_name = "hello.c" | |
12474 | dir_name = "." | |
12475 | DW_AT_comp_dir = comp_dir = "/tmp" | |
12476 | DW_AT_name = "./hello.c" */ | |
12477 | ||
12478 | if (dir_name != NULL) | |
12479 | { | |
12480 | include_name = concat (dir_name, SLASH_STRING, | |
12481 | include_name, (char *)NULL); | |
12482 | include_name_to_compare = include_name; | |
12483 | make_cleanup (xfree, include_name); | |
12484 | } | |
12485 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
12486 | { | |
12487 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
12488 | include_name, (char *)NULL); | |
12489 | } | |
12490 | } | |
12491 | ||
12492 | pst_filename = pst->filename; | |
12493 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
12494 | { | |
72b9f47f TT |
12495 | copied_name = concat (pst->dirname, SLASH_STRING, |
12496 | pst_filename, (char *)NULL); | |
12497 | pst_filename = copied_name; | |
c6da4cef DE |
12498 | } |
12499 | ||
1e3fad37 | 12500 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
12501 | |
12502 | if (include_name_to_compare != include_name) | |
12503 | xfree (include_name_to_compare); | |
72b9f47f TT |
12504 | if (copied_name != NULL) |
12505 | xfree (copied_name); | |
c6da4cef DE |
12506 | |
12507 | if (file_is_pst) | |
12508 | return NULL; | |
12509 | return include_name; | |
12510 | } | |
12511 | ||
c91513d8 PP |
12512 | /* Ignore this record_line request. */ |
12513 | ||
12514 | static void | |
12515 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
12516 | { | |
12517 | return; | |
12518 | } | |
12519 | ||
f3f5162e DE |
12520 | /* Subroutine of dwarf_decode_lines to simplify it. |
12521 | Process the line number information in LH. */ | |
debd256d | 12522 | |
c906108c | 12523 | static void |
f3f5162e DE |
12524 | dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, |
12525 | struct dwarf2_cu *cu, struct partial_symtab *pst) | |
c906108c | 12526 | { |
a8c50c1f | 12527 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 12528 | gdb_byte *line_end; |
a8c50c1f | 12529 | unsigned int bytes_read, extended_len; |
c906108c | 12530 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
12531 | CORE_ADDR baseaddr; |
12532 | struct objfile *objfile = cu->objfile; | |
f3f5162e | 12533 | bfd *abfd = objfile->obfd; |
fbf65064 | 12534 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 12535 | const int decode_for_pst_p = (pst != NULL); |
f3f5162e | 12536 | struct subfile *last_subfile = NULL; |
c91513d8 PP |
12537 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
12538 | = record_line; | |
e142c38c DJ |
12539 | |
12540 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 12541 | |
debd256d JB |
12542 | line_ptr = lh->statement_program_start; |
12543 | line_end = lh->statement_program_end; | |
c906108c SS |
12544 | |
12545 | /* Read the statement sequences until there's nothing left. */ | |
12546 | while (line_ptr < line_end) | |
12547 | { | |
12548 | /* state machine registers */ | |
12549 | CORE_ADDR address = 0; | |
12550 | unsigned int file = 1; | |
12551 | unsigned int line = 1; | |
12552 | unsigned int column = 0; | |
debd256d | 12553 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
12554 | int basic_block = 0; |
12555 | int end_sequence = 0; | |
fbf65064 | 12556 | CORE_ADDR addr; |
2dc7f7b3 | 12557 | unsigned char op_index = 0; |
c906108c | 12558 | |
aaa75496 | 12559 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 12560 | { |
aaa75496 | 12561 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
12562 | /* lh->include_dirs and lh->file_names are 0-based, but the |
12563 | directory and file name numbers in the statement program | |
12564 | are 1-based. */ | |
12565 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 12566 | char *dir = NULL; |
a738430d | 12567 | |
debd256d JB |
12568 | if (fe->dir_index) |
12569 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
12570 | |
12571 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
12572 | } |
12573 | ||
a738430d | 12574 | /* Decode the table. */ |
c5aa993b | 12575 | while (!end_sequence) |
c906108c SS |
12576 | { |
12577 | op_code = read_1_byte (abfd, line_ptr); | |
12578 | line_ptr += 1; | |
59205f5a JB |
12579 | if (line_ptr > line_end) |
12580 | { | |
12581 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
12582 | break; | |
12583 | } | |
9aa1fe7e | 12584 | |
debd256d | 12585 | if (op_code >= lh->opcode_base) |
6e70227d | 12586 | { |
a738430d | 12587 | /* Special operand. */ |
debd256d | 12588 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
12589 | address += (((op_index + (adj_opcode / lh->line_range)) |
12590 | / lh->maximum_ops_per_instruction) | |
12591 | * lh->minimum_instruction_length); | |
12592 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
12593 | % lh->maximum_ops_per_instruction); | |
debd256d | 12594 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 12595 | if (lh->num_file_names < file || file == 0) |
25e43795 | 12596 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
12597 | /* For now we ignore lines not starting on an |
12598 | instruction boundary. */ | |
12599 | else if (op_index == 0) | |
25e43795 DJ |
12600 | { |
12601 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 12602 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
12603 | { |
12604 | if (last_subfile != current_subfile) | |
12605 | { | |
12606 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
12607 | if (last_subfile) | |
c91513d8 | 12608 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
12609 | last_subfile = current_subfile; |
12610 | } | |
25e43795 | 12611 | /* Append row to matrix using current values. */ |
7019d805 | 12612 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 12613 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 12614 | } |
25e43795 | 12615 | } |
ca5f395d | 12616 | basic_block = 0; |
9aa1fe7e GK |
12617 | } |
12618 | else switch (op_code) | |
c906108c SS |
12619 | { |
12620 | case DW_LNS_extended_op: | |
3e43a32a MS |
12621 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
12622 | &bytes_read); | |
473b7be6 | 12623 | line_ptr += bytes_read; |
a8c50c1f | 12624 | extended_end = line_ptr + extended_len; |
c906108c SS |
12625 | extended_op = read_1_byte (abfd, line_ptr); |
12626 | line_ptr += 1; | |
12627 | switch (extended_op) | |
12628 | { | |
12629 | case DW_LNE_end_sequence: | |
c91513d8 | 12630 | p_record_line = record_line; |
c906108c | 12631 | end_sequence = 1; |
c906108c SS |
12632 | break; |
12633 | case DW_LNE_set_address: | |
e7c27a73 | 12634 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
12635 | |
12636 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
12637 | { | |
12638 | /* This line table is for a function which has been | |
12639 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
12640 | ||
12641 | long line_offset | |
12642 | = line_ptr - dwarf2_per_objfile->line.buffer; | |
12643 | ||
12644 | complaint (&symfile_complaints, | |
12645 | _(".debug_line address at offset 0x%lx is 0 " | |
12646 | "[in module %s]"), | |
bb5ed363 | 12647 | line_offset, objfile->name); |
c91513d8 PP |
12648 | p_record_line = noop_record_line; |
12649 | } | |
12650 | ||
2dc7f7b3 | 12651 | op_index = 0; |
107d2387 AC |
12652 | line_ptr += bytes_read; |
12653 | address += baseaddr; | |
c906108c SS |
12654 | break; |
12655 | case DW_LNE_define_file: | |
debd256d JB |
12656 | { |
12657 | char *cur_file; | |
12658 | unsigned int dir_index, mod_time, length; | |
6e70227d | 12659 | |
3e43a32a MS |
12660 | cur_file = read_direct_string (abfd, line_ptr, |
12661 | &bytes_read); | |
debd256d JB |
12662 | line_ptr += bytes_read; |
12663 | dir_index = | |
12664 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12665 | line_ptr += bytes_read; | |
12666 | mod_time = | |
12667 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12668 | line_ptr += bytes_read; | |
12669 | length = | |
12670 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12671 | line_ptr += bytes_read; | |
12672 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
12673 | } | |
c906108c | 12674 | break; |
d0c6ba3d CC |
12675 | case DW_LNE_set_discriminator: |
12676 | /* The discriminator is not interesting to the debugger; | |
12677 | just ignore it. */ | |
12678 | line_ptr = extended_end; | |
12679 | break; | |
c906108c | 12680 | default: |
4d3c2250 | 12681 | complaint (&symfile_complaints, |
e2e0b3e5 | 12682 | _("mangled .debug_line section")); |
debd256d | 12683 | return; |
c906108c | 12684 | } |
a8c50c1f DJ |
12685 | /* Make sure that we parsed the extended op correctly. If e.g. |
12686 | we expected a different address size than the producer used, | |
12687 | we may have read the wrong number of bytes. */ | |
12688 | if (line_ptr != extended_end) | |
12689 | { | |
12690 | complaint (&symfile_complaints, | |
12691 | _("mangled .debug_line section")); | |
12692 | return; | |
12693 | } | |
c906108c SS |
12694 | break; |
12695 | case DW_LNS_copy: | |
59205f5a | 12696 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
12697 | dwarf2_debug_line_missing_file_complaint (); |
12698 | else | |
366da635 | 12699 | { |
25e43795 | 12700 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 12701 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
12702 | { |
12703 | if (last_subfile != current_subfile) | |
12704 | { | |
12705 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
12706 | if (last_subfile) | |
c91513d8 | 12707 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
12708 | last_subfile = current_subfile; |
12709 | } | |
7019d805 | 12710 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 12711 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 12712 | } |
366da635 | 12713 | } |
c906108c SS |
12714 | basic_block = 0; |
12715 | break; | |
12716 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
12717 | { |
12718 | CORE_ADDR adjust | |
12719 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12720 | ||
12721 | address += (((op_index + adjust) | |
12722 | / lh->maximum_ops_per_instruction) | |
12723 | * lh->minimum_instruction_length); | |
12724 | op_index = ((op_index + adjust) | |
12725 | % lh->maximum_ops_per_instruction); | |
12726 | line_ptr += bytes_read; | |
12727 | } | |
c906108c SS |
12728 | break; |
12729 | case DW_LNS_advance_line: | |
12730 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
12731 | line_ptr += bytes_read; | |
12732 | break; | |
12733 | case DW_LNS_set_file: | |
debd256d | 12734 | { |
a738430d MK |
12735 | /* The arrays lh->include_dirs and lh->file_names are |
12736 | 0-based, but the directory and file name numbers in | |
12737 | the statement program are 1-based. */ | |
debd256d | 12738 | struct file_entry *fe; |
4f1520fb | 12739 | char *dir = NULL; |
a738430d | 12740 | |
debd256d JB |
12741 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
12742 | line_ptr += bytes_read; | |
59205f5a | 12743 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
12744 | dwarf2_debug_line_missing_file_complaint (); |
12745 | else | |
12746 | { | |
12747 | fe = &lh->file_names[file - 1]; | |
12748 | if (fe->dir_index) | |
12749 | dir = lh->include_dirs[fe->dir_index - 1]; | |
12750 | if (!decode_for_pst_p) | |
12751 | { | |
12752 | last_subfile = current_subfile; | |
12753 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
12754 | } | |
12755 | } | |
debd256d | 12756 | } |
c906108c SS |
12757 | break; |
12758 | case DW_LNS_set_column: | |
12759 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12760 | line_ptr += bytes_read; | |
12761 | break; | |
12762 | case DW_LNS_negate_stmt: | |
12763 | is_stmt = (!is_stmt); | |
12764 | break; | |
12765 | case DW_LNS_set_basic_block: | |
12766 | basic_block = 1; | |
12767 | break; | |
c2c6d25f JM |
12768 | /* Add to the address register of the state machine the |
12769 | address increment value corresponding to special opcode | |
a738430d MK |
12770 | 255. I.e., this value is scaled by the minimum |
12771 | instruction length since special opcode 255 would have | |
b021a221 | 12772 | scaled the increment. */ |
c906108c | 12773 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
12774 | { |
12775 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
12776 | ||
12777 | address += (((op_index + adjust) | |
12778 | / lh->maximum_ops_per_instruction) | |
12779 | * lh->minimum_instruction_length); | |
12780 | op_index = ((op_index + adjust) | |
12781 | % lh->maximum_ops_per_instruction); | |
12782 | } | |
c906108c SS |
12783 | break; |
12784 | case DW_LNS_fixed_advance_pc: | |
12785 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 12786 | op_index = 0; |
c906108c SS |
12787 | line_ptr += 2; |
12788 | break; | |
9aa1fe7e | 12789 | default: |
a738430d MK |
12790 | { |
12791 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 12792 | int i; |
a738430d | 12793 | |
debd256d | 12794 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
12795 | { |
12796 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
12797 | line_ptr += bytes_read; | |
12798 | } | |
12799 | } | |
c906108c SS |
12800 | } |
12801 | } | |
59205f5a JB |
12802 | if (lh->num_file_names < file || file == 0) |
12803 | dwarf2_debug_line_missing_file_complaint (); | |
12804 | else | |
12805 | { | |
12806 | lh->file_names[file - 1].included_p = 1; | |
12807 | if (!decode_for_pst_p) | |
fbf65064 UW |
12808 | { |
12809 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 12810 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 12811 | } |
59205f5a | 12812 | } |
c906108c | 12813 | } |
f3f5162e DE |
12814 | } |
12815 | ||
12816 | /* Decode the Line Number Program (LNP) for the given line_header | |
12817 | structure and CU. The actual information extracted and the type | |
12818 | of structures created from the LNP depends on the value of PST. | |
12819 | ||
12820 | 1. If PST is NULL, then this procedure uses the data from the program | |
12821 | to create all necessary symbol tables, and their linetables. | |
12822 | ||
12823 | 2. If PST is not NULL, this procedure reads the program to determine | |
12824 | the list of files included by the unit represented by PST, and | |
12825 | builds all the associated partial symbol tables. | |
12826 | ||
12827 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
12828 | It is used for relative paths in the line table. | |
12829 | NOTE: When processing partial symtabs (pst != NULL), | |
12830 | comp_dir == pst->dirname. | |
12831 | ||
12832 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
12833 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
12834 | symtab we don't use it in the name of the psymtabs we create. | |
12835 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
12836 | A good testcase for this is mb-inline.exp. */ | |
12837 | ||
12838 | static void | |
12839 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, | |
12840 | struct dwarf2_cu *cu, struct partial_symtab *pst, | |
12841 | int want_line_info) | |
12842 | { | |
12843 | struct objfile *objfile = cu->objfile; | |
12844 | const int decode_for_pst_p = (pst != NULL); | |
12845 | struct subfile *first_subfile = current_subfile; | |
12846 | ||
12847 | if (want_line_info) | |
12848 | dwarf_decode_lines_1 (lh, comp_dir, cu, pst); | |
aaa75496 JB |
12849 | |
12850 | if (decode_for_pst_p) | |
12851 | { | |
12852 | int file_index; | |
12853 | ||
12854 | /* Now that we're done scanning the Line Header Program, we can | |
12855 | create the psymtab of each included file. */ | |
12856 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
12857 | if (lh->file_names[file_index].included_p == 1) | |
12858 | { | |
c6da4cef DE |
12859 | char *include_name = |
12860 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
12861 | if (include_name != NULL) | |
aaa75496 JB |
12862 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
12863 | } | |
12864 | } | |
cb1df416 DJ |
12865 | else |
12866 | { | |
12867 | /* Make sure a symtab is created for every file, even files | |
12868 | which contain only variables (i.e. no code with associated | |
12869 | line numbers). */ | |
cb1df416 | 12870 | int i; |
cb1df416 DJ |
12871 | |
12872 | for (i = 0; i < lh->num_file_names; i++) | |
12873 | { | |
12874 | char *dir = NULL; | |
f3f5162e | 12875 | struct file_entry *fe; |
9a619af0 | 12876 | |
cb1df416 DJ |
12877 | fe = &lh->file_names[i]; |
12878 | if (fe->dir_index) | |
12879 | dir = lh->include_dirs[fe->dir_index - 1]; | |
12880 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
12881 | ||
12882 | /* Skip the main file; we don't need it, and it must be | |
12883 | allocated last, so that it will show up before the | |
12884 | non-primary symtabs in the objfile's symtab list. */ | |
12885 | if (current_subfile == first_subfile) | |
12886 | continue; | |
12887 | ||
12888 | if (current_subfile->symtab == NULL) | |
12889 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
bb5ed363 | 12890 | objfile); |
cb1df416 DJ |
12891 | fe->symtab = current_subfile->symtab; |
12892 | } | |
12893 | } | |
c906108c SS |
12894 | } |
12895 | ||
12896 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
12897 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
12898 | or NULL if not known. COMP_DIR is the compilation directory for the |
12899 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
12900 | This routine tries to keep line numbers from identical absolute and |
12901 | relative file names in a common subfile. | |
12902 | ||
12903 | Using the `list' example from the GDB testsuite, which resides in | |
12904 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
12905 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
12906 | ||
c5aa993b JM |
12907 | DW_AT_name: /srcdir/list0.c |
12908 | DW_AT_comp_dir: /compdir | |
357e46e7 | 12909 | files.files[0].name: list0.h |
c5aa993b | 12910 | files.files[0].dir: /srcdir |
357e46e7 | 12911 | files.files[1].name: list0.c |
c5aa993b | 12912 | files.files[1].dir: /srcdir |
c906108c SS |
12913 | |
12914 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
12915 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
12916 | start_subfile will ensure that this happens provided that we pass the | |
12917 | concatenation of files.files[1].dir and files.files[1].name as the | |
12918 | subfile's name. */ | |
c906108c SS |
12919 | |
12920 | static void | |
3e43a32a MS |
12921 | dwarf2_start_subfile (char *filename, const char *dirname, |
12922 | const char *comp_dir) | |
c906108c | 12923 | { |
4f1520fb FR |
12924 | char *fullname; |
12925 | ||
12926 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
12927 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
12928 | second argument to start_subfile. To be consistent, we do the | |
12929 | same here. In order not to lose the line information directory, | |
12930 | we concatenate it to the filename when it makes sense. | |
12931 | Note that the Dwarf3 standard says (speaking of filenames in line | |
12932 | information): ``The directory index is ignored for file names | |
12933 | that represent full path names''. Thus ignoring dirname in the | |
12934 | `else' branch below isn't an issue. */ | |
c906108c | 12935 | |
d5166ae1 | 12936 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
12937 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
12938 | else | |
12939 | fullname = filename; | |
c906108c | 12940 | |
4f1520fb FR |
12941 | start_subfile (fullname, comp_dir); |
12942 | ||
12943 | if (fullname != filename) | |
12944 | xfree (fullname); | |
c906108c SS |
12945 | } |
12946 | ||
4c2df51b DJ |
12947 | static void |
12948 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 12949 | struct dwarf2_cu *cu) |
4c2df51b | 12950 | { |
e7c27a73 DJ |
12951 | struct objfile *objfile = cu->objfile; |
12952 | struct comp_unit_head *cu_header = &cu->header; | |
12953 | ||
4c2df51b DJ |
12954 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
12955 | code here to turn a symbol with DW_AT_external and a | |
12956 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
12957 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
12958 | with some versions of binutils) where shared libraries could have | |
12959 | relocations against symbols in their debug information - the | |
12960 | minimal symbol would have the right address, but the debug info | |
12961 | would not. It's no longer necessary, because we will explicitly | |
12962 | apply relocations when we read in the debug information now. */ | |
12963 | ||
12964 | /* A DW_AT_location attribute with no contents indicates that a | |
12965 | variable has been optimized away. */ | |
12966 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
12967 | { | |
12968 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
12969 | return; | |
12970 | } | |
12971 | ||
12972 | /* Handle one degenerate form of location expression specially, to | |
12973 | preserve GDB's previous behavior when section offsets are | |
3019eac3 DE |
12974 | specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index |
12975 | then mark this symbol as LOC_STATIC. */ | |
4c2df51b DJ |
12976 | |
12977 | if (attr_form_is_block (attr) | |
3019eac3 DE |
12978 | && ((DW_BLOCK (attr)->data[0] == DW_OP_addr |
12979 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size) | |
12980 | || (DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index | |
12981 | && (DW_BLOCK (attr)->size | |
12982 | == 1 + leb128_size (&DW_BLOCK (attr)->data[1]))))) | |
4c2df51b | 12983 | { |
891d2f0b | 12984 | unsigned int dummy; |
4c2df51b | 12985 | |
3019eac3 DE |
12986 | if (DW_BLOCK (attr)->data[0] == DW_OP_addr) |
12987 | SYMBOL_VALUE_ADDRESS (sym) = | |
12988 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); | |
12989 | else | |
12990 | SYMBOL_VALUE_ADDRESS (sym) = | |
12991 | read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy); | |
907fc202 | 12992 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
12993 | fixup_symbol_section (sym, objfile); |
12994 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
12995 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
12996 | return; |
12997 | } | |
12998 | ||
12999 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
13000 | expression evaluator, and use LOC_COMPUTED only when necessary | |
13001 | (i.e. when the value of a register or memory location is | |
13002 | referenced, or a thread-local block, etc.). Then again, it might | |
13003 | not be worthwhile. I'm assuming that it isn't unless performance | |
13004 | or memory numbers show me otherwise. */ | |
13005 | ||
e7c27a73 | 13006 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b | 13007 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8be455d7 JK |
13008 | |
13009 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) | |
13010 | cu->has_loclist = 1; | |
4c2df51b DJ |
13011 | } |
13012 | ||
c906108c SS |
13013 | /* Given a pointer to a DWARF information entry, figure out if we need |
13014 | to make a symbol table entry for it, and if so, create a new entry | |
13015 | and return a pointer to it. | |
13016 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
13017 | used the passed type. |
13018 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
13019 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
13020 | |
13021 | static struct symbol * | |
34eaf542 TT |
13022 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
13023 | struct symbol *space) | |
c906108c | 13024 | { |
e7c27a73 | 13025 | struct objfile *objfile = cu->objfile; |
c906108c SS |
13026 | struct symbol *sym = NULL; |
13027 | char *name; | |
13028 | struct attribute *attr = NULL; | |
13029 | struct attribute *attr2 = NULL; | |
e142c38c | 13030 | CORE_ADDR baseaddr; |
e37fd15a SW |
13031 | struct pending **list_to_add = NULL; |
13032 | ||
edb3359d | 13033 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
13034 | |
13035 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 13036 | |
94af9270 | 13037 | name = dwarf2_name (die, cu); |
c906108c SS |
13038 | if (name) |
13039 | { | |
94af9270 | 13040 | const char *linkagename; |
34eaf542 | 13041 | int suppress_add = 0; |
94af9270 | 13042 | |
34eaf542 TT |
13043 | if (space) |
13044 | sym = space; | |
13045 | else | |
13046 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 13047 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
13048 | |
13049 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 13050 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
13051 | linkagename = dwarf2_physname (name, die, cu); |
13052 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 13053 | |
f55ee35c JK |
13054 | /* Fortran does not have mangling standard and the mangling does differ |
13055 | between gfortran, iFort etc. */ | |
13056 | if (cu->language == language_fortran | |
b250c185 | 13057 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
13058 | symbol_set_demangled_name (&(sym->ginfo), |
13059 | (char *) dwarf2_full_name (name, die, cu), | |
13060 | NULL); | |
f55ee35c | 13061 | |
c906108c | 13062 | /* Default assumptions. |
c5aa993b | 13063 | Use the passed type or decode it from the die. */ |
176620f1 | 13064 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 13065 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
13066 | if (type != NULL) |
13067 | SYMBOL_TYPE (sym) = type; | |
13068 | else | |
e7c27a73 | 13069 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
13070 | attr = dwarf2_attr (die, |
13071 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
13072 | cu); | |
c906108c SS |
13073 | if (attr) |
13074 | { | |
13075 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
13076 | } | |
cb1df416 | 13077 | |
edb3359d DJ |
13078 | attr = dwarf2_attr (die, |
13079 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
13080 | cu); | |
cb1df416 DJ |
13081 | if (attr) |
13082 | { | |
13083 | int file_index = DW_UNSND (attr); | |
9a619af0 | 13084 | |
cb1df416 DJ |
13085 | if (cu->line_header == NULL |
13086 | || file_index > cu->line_header->num_file_names) | |
13087 | complaint (&symfile_complaints, | |
13088 | _("file index out of range")); | |
1c3d648d | 13089 | else if (file_index > 0) |
cb1df416 DJ |
13090 | { |
13091 | struct file_entry *fe; | |
9a619af0 | 13092 | |
cb1df416 DJ |
13093 | fe = &cu->line_header->file_names[file_index - 1]; |
13094 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
13095 | } | |
13096 | } | |
13097 | ||
c906108c SS |
13098 | switch (die->tag) |
13099 | { | |
13100 | case DW_TAG_label: | |
e142c38c | 13101 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
13102 | if (attr) |
13103 | { | |
13104 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
13105 | } | |
0f5238ed TT |
13106 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
13107 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 13108 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 13109 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
13110 | break; |
13111 | case DW_TAG_subprogram: | |
13112 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
13113 | finish_block. */ | |
13114 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 13115 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
13116 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
13117 | || cu->language == language_ada) | |
c906108c | 13118 | { |
2cfa0c8d JB |
13119 | /* Subprograms marked external are stored as a global symbol. |
13120 | Ada subprograms, whether marked external or not, are always | |
13121 | stored as a global symbol, because we want to be able to | |
13122 | access them globally. For instance, we want to be able | |
13123 | to break on a nested subprogram without having to | |
13124 | specify the context. */ | |
e37fd15a | 13125 | list_to_add = &global_symbols; |
c906108c SS |
13126 | } |
13127 | else | |
13128 | { | |
e37fd15a | 13129 | list_to_add = cu->list_in_scope; |
c906108c SS |
13130 | } |
13131 | break; | |
edb3359d DJ |
13132 | case DW_TAG_inlined_subroutine: |
13133 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
13134 | finish_block. */ | |
13135 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
13136 | SYMBOL_INLINED (sym) = 1; | |
481860b3 | 13137 | list_to_add = cu->list_in_scope; |
edb3359d | 13138 | break; |
34eaf542 TT |
13139 | case DW_TAG_template_value_param: |
13140 | suppress_add = 1; | |
13141 | /* Fall through. */ | |
72929c62 | 13142 | case DW_TAG_constant: |
c906108c | 13143 | case DW_TAG_variable: |
254e6b9e | 13144 | case DW_TAG_member: |
0963b4bd MS |
13145 | /* Compilation with minimal debug info may result in |
13146 | variables with missing type entries. Change the | |
13147 | misleading `void' type to something sensible. */ | |
c906108c | 13148 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 13149 | SYMBOL_TYPE (sym) |
46bf5051 | 13150 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 13151 | |
e142c38c | 13152 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
13153 | /* In the case of DW_TAG_member, we should only be called for |
13154 | static const members. */ | |
13155 | if (die->tag == DW_TAG_member) | |
13156 | { | |
3863f96c DE |
13157 | /* dwarf2_add_field uses die_is_declaration, |
13158 | so we do the same. */ | |
254e6b9e DE |
13159 | gdb_assert (die_is_declaration (die, cu)); |
13160 | gdb_assert (attr); | |
13161 | } | |
c906108c SS |
13162 | if (attr) |
13163 | { | |
e7c27a73 | 13164 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 13165 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 13166 | if (!suppress_add) |
34eaf542 TT |
13167 | { |
13168 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 13169 | list_to_add = &global_symbols; |
34eaf542 | 13170 | else |
e37fd15a | 13171 | list_to_add = cu->list_in_scope; |
34eaf542 | 13172 | } |
c906108c SS |
13173 | break; |
13174 | } | |
e142c38c | 13175 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
13176 | if (attr) |
13177 | { | |
e7c27a73 | 13178 | var_decode_location (attr, sym, cu); |
e142c38c | 13179 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
13180 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
13181 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
13182 | && !dwarf2_per_objfile->has_section_at_zero) | |
13183 | { | |
13184 | /* When a static variable is eliminated by the linker, | |
13185 | the corresponding debug information is not stripped | |
13186 | out, but the variable address is set to null; | |
13187 | do not add such variables into symbol table. */ | |
13188 | } | |
13189 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 13190 | { |
f55ee35c JK |
13191 | /* Workaround gfortran PR debug/40040 - it uses |
13192 | DW_AT_location for variables in -fPIC libraries which may | |
13193 | get overriden by other libraries/executable and get | |
13194 | a different address. Resolve it by the minimal symbol | |
13195 | which may come from inferior's executable using copy | |
13196 | relocation. Make this workaround only for gfortran as for | |
13197 | other compilers GDB cannot guess the minimal symbol | |
13198 | Fortran mangling kind. */ | |
13199 | if (cu->language == language_fortran && die->parent | |
13200 | && die->parent->tag == DW_TAG_module | |
13201 | && cu->producer | |
13202 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
13203 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
13204 | ||
1c809c68 TT |
13205 | /* A variable with DW_AT_external is never static, |
13206 | but it may be block-scoped. */ | |
13207 | list_to_add = (cu->list_in_scope == &file_symbols | |
13208 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 13209 | } |
c906108c | 13210 | else |
e37fd15a | 13211 | list_to_add = cu->list_in_scope; |
c906108c SS |
13212 | } |
13213 | else | |
13214 | { | |
13215 | /* We do not know the address of this symbol. | |
c5aa993b JM |
13216 | If it is an external symbol and we have type information |
13217 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
13218 | The address of the variable will then be determined from | |
13219 | the minimal symbol table whenever the variable is | |
13220 | referenced. */ | |
e142c38c | 13221 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 13222 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 13223 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 13224 | { |
0fe7935b DJ |
13225 | /* A variable with DW_AT_external is never static, but it |
13226 | may be block-scoped. */ | |
13227 | list_to_add = (cu->list_in_scope == &file_symbols | |
13228 | ? &global_symbols : cu->list_in_scope); | |
13229 | ||
c906108c | 13230 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 13231 | } |
442ddf59 JK |
13232 | else if (!die_is_declaration (die, cu)) |
13233 | { | |
13234 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
13235 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
13236 | if (!suppress_add) |
13237 | list_to_add = cu->list_in_scope; | |
442ddf59 | 13238 | } |
c906108c SS |
13239 | } |
13240 | break; | |
13241 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
13242 | /* If we are inside a function, mark this as an argument. If |
13243 | not, we might be looking at an argument to an inlined function | |
13244 | when we do not have enough information to show inlined frames; | |
13245 | pretend it's a local variable in that case so that the user can | |
13246 | still see it. */ | |
13247 | if (context_stack_depth > 0 | |
13248 | && context_stack[context_stack_depth - 1].name != NULL) | |
13249 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 13250 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
13251 | if (attr) |
13252 | { | |
e7c27a73 | 13253 | var_decode_location (attr, sym, cu); |
c906108c | 13254 | } |
e142c38c | 13255 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
13256 | if (attr) |
13257 | { | |
e7c27a73 | 13258 | dwarf2_const_value (attr, sym, cu); |
c906108c | 13259 | } |
f346a30d | 13260 | |
e37fd15a | 13261 | list_to_add = cu->list_in_scope; |
c906108c SS |
13262 | break; |
13263 | case DW_TAG_unspecified_parameters: | |
13264 | /* From varargs functions; gdb doesn't seem to have any | |
13265 | interest in this information, so just ignore it for now. | |
13266 | (FIXME?) */ | |
13267 | break; | |
34eaf542 TT |
13268 | case DW_TAG_template_type_param: |
13269 | suppress_add = 1; | |
13270 | /* Fall through. */ | |
c906108c | 13271 | case DW_TAG_class_type: |
680b30c7 | 13272 | case DW_TAG_interface_type: |
c906108c SS |
13273 | case DW_TAG_structure_type: |
13274 | case DW_TAG_union_type: | |
72019c9c | 13275 | case DW_TAG_set_type: |
c906108c SS |
13276 | case DW_TAG_enumeration_type: |
13277 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 13278 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 13279 | |
63d06c5c | 13280 | { |
987504bb | 13281 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
13282 | really ever be static objects: otherwise, if you try |
13283 | to, say, break of a class's method and you're in a file | |
13284 | which doesn't mention that class, it won't work unless | |
13285 | the check for all static symbols in lookup_symbol_aux | |
13286 | saves you. See the OtherFileClass tests in | |
13287 | gdb.c++/namespace.exp. */ | |
13288 | ||
e37fd15a | 13289 | if (!suppress_add) |
34eaf542 | 13290 | { |
34eaf542 TT |
13291 | list_to_add = (cu->list_in_scope == &file_symbols |
13292 | && (cu->language == language_cplus | |
13293 | || cu->language == language_java) | |
13294 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 13295 | |
64382290 TT |
13296 | /* The semantics of C++ state that "struct foo { |
13297 | ... }" also defines a typedef for "foo". A Java | |
13298 | class declaration also defines a typedef for the | |
13299 | class. */ | |
13300 | if (cu->language == language_cplus | |
13301 | || cu->language == language_java | |
13302 | || cu->language == language_ada) | |
13303 | { | |
13304 | /* The symbol's name is already allocated along | |
13305 | with this objfile, so we don't need to | |
13306 | duplicate it for the type. */ | |
13307 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
13308 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
13309 | } | |
63d06c5c DC |
13310 | } |
13311 | } | |
c906108c SS |
13312 | break; |
13313 | case DW_TAG_typedef: | |
63d06c5c DC |
13314 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
13315 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 13316 | list_to_add = cu->list_in_scope; |
63d06c5c | 13317 | break; |
c906108c | 13318 | case DW_TAG_base_type: |
a02abb62 | 13319 | case DW_TAG_subrange_type: |
c906108c | 13320 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 13321 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 13322 | list_to_add = cu->list_in_scope; |
c906108c SS |
13323 | break; |
13324 | case DW_TAG_enumerator: | |
e142c38c | 13325 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
13326 | if (attr) |
13327 | { | |
e7c27a73 | 13328 | dwarf2_const_value (attr, sym, cu); |
c906108c | 13329 | } |
63d06c5c DC |
13330 | { |
13331 | /* NOTE: carlton/2003-11-10: See comment above in the | |
13332 | DW_TAG_class_type, etc. block. */ | |
13333 | ||
e142c38c | 13334 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
13335 | && (cu->language == language_cplus |
13336 | || cu->language == language_java) | |
e142c38c | 13337 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 13338 | } |
c906108c | 13339 | break; |
5c4e30ca DC |
13340 | case DW_TAG_namespace: |
13341 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 13342 | list_to_add = &global_symbols; |
5c4e30ca | 13343 | break; |
c906108c SS |
13344 | default: |
13345 | /* Not a tag we recognize. Hopefully we aren't processing | |
13346 | trash data, but since we must specifically ignore things | |
13347 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 13348 | this point. */ |
e2e0b3e5 | 13349 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 13350 | dwarf_tag_name (die->tag)); |
c906108c SS |
13351 | break; |
13352 | } | |
df8a16a1 | 13353 | |
e37fd15a SW |
13354 | if (suppress_add) |
13355 | { | |
13356 | sym->hash_next = objfile->template_symbols; | |
13357 | objfile->template_symbols = sym; | |
13358 | list_to_add = NULL; | |
13359 | } | |
13360 | ||
13361 | if (list_to_add != NULL) | |
13362 | add_symbol_to_list (sym, list_to_add); | |
13363 | ||
df8a16a1 DJ |
13364 | /* For the benefit of old versions of GCC, check for anonymous |
13365 | namespaces based on the demangled name. */ | |
13366 | if (!processing_has_namespace_info | |
94af9270 | 13367 | && cu->language == language_cplus) |
a10964d1 | 13368 | cp_scan_for_anonymous_namespaces (sym, objfile); |
c906108c SS |
13369 | } |
13370 | return (sym); | |
13371 | } | |
13372 | ||
34eaf542 TT |
13373 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
13374 | ||
13375 | static struct symbol * | |
13376 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
13377 | { | |
13378 | return new_symbol_full (die, type, cu, NULL); | |
13379 | } | |
13380 | ||
98bfdba5 PA |
13381 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
13382 | zero-extend it as appropriate for the symbol's type. The DWARF | |
13383 | standard (v4) is not entirely clear about the meaning of using | |
13384 | DW_FORM_dataN for a constant with a signed type, where the type is | |
13385 | wider than the data. The conclusion of a discussion on the DWARF | |
13386 | list was that this is unspecified. We choose to always zero-extend | |
13387 | because that is the interpretation long in use by GCC. */ | |
c906108c | 13388 | |
98bfdba5 PA |
13389 | static gdb_byte * |
13390 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
13391 | const char *name, struct obstack *obstack, | |
12df843f | 13392 | struct dwarf2_cu *cu, LONGEST *value, int bits) |
c906108c | 13393 | { |
e7c27a73 | 13394 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
13395 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
13396 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
13397 | LONGEST l = DW_UNSND (attr); |
13398 | ||
13399 | if (bits < sizeof (*value) * 8) | |
13400 | { | |
13401 | l &= ((LONGEST) 1 << bits) - 1; | |
13402 | *value = l; | |
13403 | } | |
13404 | else if (bits == sizeof (*value) * 8) | |
13405 | *value = l; | |
13406 | else | |
13407 | { | |
13408 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
13409 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
13410 | return bytes; | |
13411 | } | |
13412 | ||
13413 | return NULL; | |
13414 | } | |
13415 | ||
13416 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
13417 | the value does not fit in *VALUE, set *BYTES - either already | |
13418 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
13419 | or, set *BATON, if we translated the constant to a location | |
13420 | expression. */ | |
13421 | ||
13422 | static void | |
13423 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
13424 | const char *name, struct obstack *obstack, | |
13425 | struct dwarf2_cu *cu, | |
12df843f | 13426 | LONGEST *value, gdb_byte **bytes, |
98bfdba5 PA |
13427 | struct dwarf2_locexpr_baton **baton) |
13428 | { | |
13429 | struct objfile *objfile = cu->objfile; | |
13430 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 13431 | struct dwarf_block *blk; |
98bfdba5 PA |
13432 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
13433 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
13434 | ||
13435 | *value = 0; | |
13436 | *bytes = NULL; | |
13437 | *baton = NULL; | |
c906108c SS |
13438 | |
13439 | switch (attr->form) | |
13440 | { | |
13441 | case DW_FORM_addr: | |
3019eac3 | 13442 | case DW_FORM_GNU_addr_index: |
ac56253d | 13443 | { |
ac56253d TT |
13444 | gdb_byte *data; |
13445 | ||
98bfdba5 PA |
13446 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
13447 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 13448 | cu_header->addr_size, |
98bfdba5 | 13449 | TYPE_LENGTH (type)); |
ac56253d TT |
13450 | /* Symbols of this form are reasonably rare, so we just |
13451 | piggyback on the existing location code rather than writing | |
13452 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
13453 | *baton = obstack_alloc (&objfile->objfile_obstack, |
13454 | sizeof (struct dwarf2_locexpr_baton)); | |
13455 | (*baton)->per_cu = cu->per_cu; | |
13456 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 13457 | |
98bfdba5 PA |
13458 | (*baton)->size = 2 + cu_header->addr_size; |
13459 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
13460 | (*baton)->data = data; | |
ac56253d TT |
13461 | |
13462 | data[0] = DW_OP_addr; | |
13463 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
13464 | byte_order, DW_ADDR (attr)); | |
13465 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 13466 | } |
c906108c | 13467 | break; |
4ac36638 | 13468 | case DW_FORM_string: |
93b5768b | 13469 | case DW_FORM_strp: |
3019eac3 | 13470 | case DW_FORM_GNU_str_index: |
98bfdba5 PA |
13471 | /* DW_STRING is already allocated on the objfile obstack, point |
13472 | directly to it. */ | |
13473 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 13474 | break; |
c906108c SS |
13475 | case DW_FORM_block1: |
13476 | case DW_FORM_block2: | |
13477 | case DW_FORM_block4: | |
13478 | case DW_FORM_block: | |
2dc7f7b3 | 13479 | case DW_FORM_exprloc: |
c906108c | 13480 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
13481 | if (TYPE_LENGTH (type) != blk->size) |
13482 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
13483 | TYPE_LENGTH (type)); | |
13484 | *bytes = blk->data; | |
c906108c | 13485 | break; |
2df3850c JM |
13486 | |
13487 | /* The DW_AT_const_value attributes are supposed to carry the | |
13488 | symbol's value "represented as it would be on the target | |
13489 | architecture." By the time we get here, it's already been | |
13490 | converted to host endianness, so we just need to sign- or | |
13491 | zero-extend it as appropriate. */ | |
13492 | case DW_FORM_data1: | |
3e43a32a MS |
13493 | *bytes = dwarf2_const_value_data (attr, type, name, |
13494 | obstack, cu, value, 8); | |
2df3850c | 13495 | break; |
c906108c | 13496 | case DW_FORM_data2: |
3e43a32a MS |
13497 | *bytes = dwarf2_const_value_data (attr, type, name, |
13498 | obstack, cu, value, 16); | |
2df3850c | 13499 | break; |
c906108c | 13500 | case DW_FORM_data4: |
3e43a32a MS |
13501 | *bytes = dwarf2_const_value_data (attr, type, name, |
13502 | obstack, cu, value, 32); | |
2df3850c | 13503 | break; |
c906108c | 13504 | case DW_FORM_data8: |
3e43a32a MS |
13505 | *bytes = dwarf2_const_value_data (attr, type, name, |
13506 | obstack, cu, value, 64); | |
2df3850c JM |
13507 | break; |
13508 | ||
c906108c | 13509 | case DW_FORM_sdata: |
98bfdba5 | 13510 | *value = DW_SND (attr); |
2df3850c JM |
13511 | break; |
13512 | ||
c906108c | 13513 | case DW_FORM_udata: |
98bfdba5 | 13514 | *value = DW_UNSND (attr); |
c906108c | 13515 | break; |
2df3850c | 13516 | |
c906108c | 13517 | default: |
4d3c2250 | 13518 | complaint (&symfile_complaints, |
e2e0b3e5 | 13519 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 13520 | dwarf_form_name (attr->form)); |
98bfdba5 | 13521 | *value = 0; |
c906108c SS |
13522 | break; |
13523 | } | |
13524 | } | |
13525 | ||
2df3850c | 13526 | |
98bfdba5 PA |
13527 | /* Copy constant value from an attribute to a symbol. */ |
13528 | ||
2df3850c | 13529 | static void |
98bfdba5 PA |
13530 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
13531 | struct dwarf2_cu *cu) | |
2df3850c | 13532 | { |
98bfdba5 PA |
13533 | struct objfile *objfile = cu->objfile; |
13534 | struct comp_unit_head *cu_header = &cu->header; | |
12df843f | 13535 | LONGEST value; |
98bfdba5 PA |
13536 | gdb_byte *bytes; |
13537 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 13538 | |
98bfdba5 PA |
13539 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
13540 | SYMBOL_PRINT_NAME (sym), | |
13541 | &objfile->objfile_obstack, cu, | |
13542 | &value, &bytes, &baton); | |
2df3850c | 13543 | |
98bfdba5 PA |
13544 | if (baton != NULL) |
13545 | { | |
13546 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
13547 | SYMBOL_LOCATION_BATON (sym) = baton; | |
13548 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
13549 | } | |
13550 | else if (bytes != NULL) | |
13551 | { | |
13552 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
13553 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
13554 | } | |
13555 | else | |
13556 | { | |
13557 | SYMBOL_VALUE (sym) = value; | |
13558 | SYMBOL_CLASS (sym) = LOC_CONST; | |
13559 | } | |
2df3850c JM |
13560 | } |
13561 | ||
c906108c SS |
13562 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
13563 | ||
13564 | static struct type * | |
e7c27a73 | 13565 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13566 | { |
c906108c | 13567 | struct attribute *type_attr; |
c906108c | 13568 | |
e142c38c | 13569 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
13570 | if (!type_attr) |
13571 | { | |
13572 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 13573 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 13574 | } |
348e048f | 13575 | |
673bfd45 | 13576 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
13577 | } |
13578 | ||
b4ba55a1 JB |
13579 | /* True iff CU's producer generates GNAT Ada auxiliary information |
13580 | that allows to find parallel types through that information instead | |
13581 | of having to do expensive parallel lookups by type name. */ | |
13582 | ||
13583 | static int | |
13584 | need_gnat_info (struct dwarf2_cu *cu) | |
13585 | { | |
13586 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
13587 | of GNAT produces this auxiliary information, without any indication | |
13588 | that it is produced. Part of enhancing the FSF version of GNAT | |
13589 | to produce that information will be to put in place an indicator | |
13590 | that we can use in order to determine whether the descriptive type | |
13591 | info is available or not. One suggestion that has been made is | |
13592 | to use a new attribute, attached to the CU die. For now, assume | |
13593 | that the descriptive type info is not available. */ | |
13594 | return 0; | |
13595 | } | |
13596 | ||
b4ba55a1 JB |
13597 | /* Return the auxiliary type of the die in question using its |
13598 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
13599 | attribute is not present. */ | |
13600 | ||
13601 | static struct type * | |
13602 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
13603 | { | |
b4ba55a1 | 13604 | struct attribute *type_attr; |
b4ba55a1 JB |
13605 | |
13606 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
13607 | if (!type_attr) | |
13608 | return NULL; | |
13609 | ||
673bfd45 | 13610 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
13611 | } |
13612 | ||
13613 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
13614 | descriptive type accordingly. */ | |
13615 | ||
13616 | static void | |
13617 | set_descriptive_type (struct type *type, struct die_info *die, | |
13618 | struct dwarf2_cu *cu) | |
13619 | { | |
13620 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
13621 | ||
13622 | if (descriptive_type) | |
13623 | { | |
13624 | ALLOCATE_GNAT_AUX_TYPE (type); | |
13625 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
13626 | } | |
13627 | } | |
13628 | ||
c906108c SS |
13629 | /* Return the containing type of the die in question using its |
13630 | DW_AT_containing_type attribute. */ | |
13631 | ||
13632 | static struct type * | |
e7c27a73 | 13633 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13634 | { |
c906108c | 13635 | struct attribute *type_attr; |
c906108c | 13636 | |
e142c38c | 13637 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
13638 | if (!type_attr) |
13639 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
13640 | "[in module %s]"), cu->objfile->name); | |
13641 | ||
673bfd45 | 13642 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
13643 | } |
13644 | ||
673bfd45 DE |
13645 | /* Look up the type of DIE in CU using its type attribute ATTR. |
13646 | If there is no type substitute an error marker. */ | |
13647 | ||
c906108c | 13648 | static struct type * |
673bfd45 DE |
13649 | lookup_die_type (struct die_info *die, struct attribute *attr, |
13650 | struct dwarf2_cu *cu) | |
c906108c | 13651 | { |
bb5ed363 | 13652 | struct objfile *objfile = cu->objfile; |
f792889a DJ |
13653 | struct type *this_type; |
13654 | ||
673bfd45 DE |
13655 | /* First see if we have it cached. */ |
13656 | ||
13657 | if (is_ref_attr (attr)) | |
13658 | { | |
b64f50a1 | 13659 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
673bfd45 DE |
13660 | |
13661 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
13662 | } | |
55f1336d | 13663 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
13664 | { |
13665 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
673bfd45 DE |
13666 | |
13667 | /* sig_type will be NULL if the signatured type is missing from | |
13668 | the debug info. */ | |
13669 | if (sig_type == NULL) | |
13670 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
13671 | "at 0x%x [in module %s]"), | |
b64f50a1 | 13672 | die->offset.sect_off, objfile->name); |
673bfd45 | 13673 | |
3019eac3 DE |
13674 | gdb_assert (sig_type->per_cu.is_debug_types); |
13675 | /* If we haven't filled in type_offset_in_section yet, then we | |
13676 | haven't read the type in yet. */ | |
13677 | this_type = NULL; | |
13678 | if (sig_type->type_offset_in_section.sect_off != 0) | |
13679 | { | |
13680 | this_type = | |
13681 | get_die_type_at_offset (sig_type->type_offset_in_section, | |
13682 | &sig_type->per_cu); | |
13683 | } | |
673bfd45 DE |
13684 | } |
13685 | else | |
13686 | { | |
13687 | dump_die_for_error (die); | |
13688 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
bb5ed363 | 13689 | dwarf_attr_name (attr->name), objfile->name); |
673bfd45 DE |
13690 | } |
13691 | ||
13692 | /* If not cached we need to read it in. */ | |
13693 | ||
13694 | if (this_type == NULL) | |
13695 | { | |
13696 | struct die_info *type_die; | |
13697 | struct dwarf2_cu *type_cu = cu; | |
13698 | ||
13699 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
3019eac3 DE |
13700 | /* If we found the type now, it's probably because the type came |
13701 | from an inter-CU reference and the type's CU got expanded before | |
13702 | ours. */ | |
13703 | this_type = get_die_type (type_die, type_cu); | |
13704 | if (this_type == NULL) | |
13705 | this_type = read_type_die_1 (type_die, type_cu); | |
673bfd45 DE |
13706 | } |
13707 | ||
13708 | /* If we still don't have a type use an error marker. */ | |
13709 | ||
13710 | if (this_type == NULL) | |
c906108c | 13711 | { |
b00fdb78 TT |
13712 | char *message, *saved; |
13713 | ||
13714 | /* read_type_die already issued a complaint. */ | |
13715 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
bb5ed363 | 13716 | objfile->name, |
b64f50a1 JK |
13717 | cu->header.offset.sect_off, |
13718 | die->offset.sect_off); | |
bb5ed363 | 13719 | saved = obstack_copy0 (&objfile->objfile_obstack, |
b00fdb78 TT |
13720 | message, strlen (message)); |
13721 | xfree (message); | |
13722 | ||
bb5ed363 | 13723 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile); |
c906108c | 13724 | } |
673bfd45 | 13725 | |
f792889a | 13726 | return this_type; |
c906108c SS |
13727 | } |
13728 | ||
673bfd45 DE |
13729 | /* Return the type in DIE, CU. |
13730 | Returns NULL for invalid types. | |
13731 | ||
13732 | This first does a lookup in the appropriate type_hash table, | |
13733 | and only reads the die in if necessary. | |
13734 | ||
13735 | NOTE: This can be called when reading in partial or full symbols. */ | |
13736 | ||
f792889a | 13737 | static struct type * |
e7c27a73 | 13738 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13739 | { |
f792889a DJ |
13740 | struct type *this_type; |
13741 | ||
13742 | this_type = get_die_type (die, cu); | |
13743 | if (this_type) | |
13744 | return this_type; | |
13745 | ||
673bfd45 DE |
13746 | return read_type_die_1 (die, cu); |
13747 | } | |
13748 | ||
13749 | /* Read the type in DIE, CU. | |
13750 | Returns NULL for invalid types. */ | |
13751 | ||
13752 | static struct type * | |
13753 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
13754 | { | |
13755 | struct type *this_type = NULL; | |
13756 | ||
c906108c SS |
13757 | switch (die->tag) |
13758 | { | |
13759 | case DW_TAG_class_type: | |
680b30c7 | 13760 | case DW_TAG_interface_type: |
c906108c SS |
13761 | case DW_TAG_structure_type: |
13762 | case DW_TAG_union_type: | |
f792889a | 13763 | this_type = read_structure_type (die, cu); |
c906108c SS |
13764 | break; |
13765 | case DW_TAG_enumeration_type: | |
f792889a | 13766 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
13767 | break; |
13768 | case DW_TAG_subprogram: | |
13769 | case DW_TAG_subroutine_type: | |
edb3359d | 13770 | case DW_TAG_inlined_subroutine: |
f792889a | 13771 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
13772 | break; |
13773 | case DW_TAG_array_type: | |
f792889a | 13774 | this_type = read_array_type (die, cu); |
c906108c | 13775 | break; |
72019c9c | 13776 | case DW_TAG_set_type: |
f792889a | 13777 | this_type = read_set_type (die, cu); |
72019c9c | 13778 | break; |
c906108c | 13779 | case DW_TAG_pointer_type: |
f792889a | 13780 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
13781 | break; |
13782 | case DW_TAG_ptr_to_member_type: | |
f792889a | 13783 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
13784 | break; |
13785 | case DW_TAG_reference_type: | |
f792889a | 13786 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
13787 | break; |
13788 | case DW_TAG_const_type: | |
f792889a | 13789 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
13790 | break; |
13791 | case DW_TAG_volatile_type: | |
f792889a | 13792 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
13793 | break; |
13794 | case DW_TAG_string_type: | |
f792889a | 13795 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
13796 | break; |
13797 | case DW_TAG_typedef: | |
f792889a | 13798 | this_type = read_typedef (die, cu); |
c906108c | 13799 | break; |
a02abb62 | 13800 | case DW_TAG_subrange_type: |
f792889a | 13801 | this_type = read_subrange_type (die, cu); |
a02abb62 | 13802 | break; |
c906108c | 13803 | case DW_TAG_base_type: |
f792889a | 13804 | this_type = read_base_type (die, cu); |
c906108c | 13805 | break; |
81a17f79 | 13806 | case DW_TAG_unspecified_type: |
f792889a | 13807 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 13808 | break; |
0114d602 DJ |
13809 | case DW_TAG_namespace: |
13810 | this_type = read_namespace_type (die, cu); | |
13811 | break; | |
f55ee35c JK |
13812 | case DW_TAG_module: |
13813 | this_type = read_module_type (die, cu); | |
13814 | break; | |
c906108c | 13815 | default: |
3e43a32a MS |
13816 | complaint (&symfile_complaints, |
13817 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 13818 | dwarf_tag_name (die->tag)); |
c906108c SS |
13819 | break; |
13820 | } | |
63d06c5c | 13821 | |
f792889a | 13822 | return this_type; |
63d06c5c DC |
13823 | } |
13824 | ||
abc72ce4 DE |
13825 | /* See if we can figure out if the class lives in a namespace. We do |
13826 | this by looking for a member function; its demangled name will | |
13827 | contain namespace info, if there is any. | |
13828 | Return the computed name or NULL. | |
13829 | Space for the result is allocated on the objfile's obstack. | |
13830 | This is the full-die version of guess_partial_die_structure_name. | |
13831 | In this case we know DIE has no useful parent. */ | |
13832 | ||
13833 | static char * | |
13834 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
13835 | { | |
13836 | struct die_info *spec_die; | |
13837 | struct dwarf2_cu *spec_cu; | |
13838 | struct die_info *child; | |
13839 | ||
13840 | spec_cu = cu; | |
13841 | spec_die = die_specification (die, &spec_cu); | |
13842 | if (spec_die != NULL) | |
13843 | { | |
13844 | die = spec_die; | |
13845 | cu = spec_cu; | |
13846 | } | |
13847 | ||
13848 | for (child = die->child; | |
13849 | child != NULL; | |
13850 | child = child->sibling) | |
13851 | { | |
13852 | if (child->tag == DW_TAG_subprogram) | |
13853 | { | |
13854 | struct attribute *attr; | |
13855 | ||
13856 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
13857 | if (attr == NULL) | |
13858 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
13859 | if (attr != NULL) | |
13860 | { | |
13861 | char *actual_name | |
13862 | = language_class_name_from_physname (cu->language_defn, | |
13863 | DW_STRING (attr)); | |
13864 | char *name = NULL; | |
13865 | ||
13866 | if (actual_name != NULL) | |
13867 | { | |
13868 | char *die_name = dwarf2_name (die, cu); | |
13869 | ||
13870 | if (die_name != NULL | |
13871 | && strcmp (die_name, actual_name) != 0) | |
13872 | { | |
13873 | /* Strip off the class name from the full name. | |
13874 | We want the prefix. */ | |
13875 | int die_name_len = strlen (die_name); | |
13876 | int actual_name_len = strlen (actual_name); | |
13877 | ||
13878 | /* Test for '::' as a sanity check. */ | |
13879 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
13880 | && actual_name[actual_name_len |
13881 | - die_name_len - 1] == ':') | |
abc72ce4 DE |
13882 | name = |
13883 | obsavestring (actual_name, | |
13884 | actual_name_len - die_name_len - 2, | |
13885 | &cu->objfile->objfile_obstack); | |
13886 | } | |
13887 | } | |
13888 | xfree (actual_name); | |
13889 | return name; | |
13890 | } | |
13891 | } | |
13892 | } | |
13893 | ||
13894 | return NULL; | |
13895 | } | |
13896 | ||
96408a79 SA |
13897 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
13898 | prefix part in such case. See | |
13899 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
13900 | ||
13901 | static char * | |
13902 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) | |
13903 | { | |
13904 | struct attribute *attr; | |
13905 | char *base; | |
13906 | ||
13907 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type | |
13908 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) | |
13909 | return NULL; | |
13910 | ||
13911 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
13912 | if (attr != NULL && DW_STRING (attr) != NULL) | |
13913 | return NULL; | |
13914 | ||
13915 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
13916 | if (attr == NULL) | |
13917 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
13918 | if (attr == NULL || DW_STRING (attr) == NULL) | |
13919 | return NULL; | |
13920 | ||
13921 | /* dwarf2_name had to be already called. */ | |
13922 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); | |
13923 | ||
13924 | /* Strip the base name, keep any leading namespaces/classes. */ | |
13925 | base = strrchr (DW_STRING (attr), ':'); | |
13926 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') | |
13927 | return ""; | |
13928 | ||
13929 | return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr), | |
13930 | &cu->objfile->objfile_obstack); | |
13931 | } | |
13932 | ||
fdde2d81 | 13933 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 13934 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 13935 | |
0114d602 DJ |
13936 | For example, if we're within the method foo() in the following |
13937 | code: | |
13938 | ||
13939 | namespace N { | |
13940 | class C { | |
13941 | void foo () { | |
13942 | } | |
13943 | }; | |
13944 | } | |
13945 | ||
13946 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 | 13947 | |
0d5cff50 | 13948 | static const char * |
e142c38c | 13949 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 13950 | { |
0114d602 DJ |
13951 | struct die_info *parent, *spec_die; |
13952 | struct dwarf2_cu *spec_cu; | |
13953 | struct type *parent_type; | |
96408a79 | 13954 | char *retval; |
63d06c5c | 13955 | |
f55ee35c JK |
13956 | if (cu->language != language_cplus && cu->language != language_java |
13957 | && cu->language != language_fortran) | |
0114d602 DJ |
13958 | return ""; |
13959 | ||
96408a79 SA |
13960 | retval = anonymous_struct_prefix (die, cu); |
13961 | if (retval) | |
13962 | return retval; | |
13963 | ||
0114d602 DJ |
13964 | /* We have to be careful in the presence of DW_AT_specification. |
13965 | For example, with GCC 3.4, given the code | |
13966 | ||
13967 | namespace N { | |
13968 | void foo() { | |
13969 | // Definition of N::foo. | |
13970 | } | |
13971 | } | |
13972 | ||
13973 | then we'll have a tree of DIEs like this: | |
13974 | ||
13975 | 1: DW_TAG_compile_unit | |
13976 | 2: DW_TAG_namespace // N | |
13977 | 3: DW_TAG_subprogram // declaration of N::foo | |
13978 | 4: DW_TAG_subprogram // definition of N::foo | |
13979 | DW_AT_specification // refers to die #3 | |
13980 | ||
13981 | Thus, when processing die #4, we have to pretend that we're in | |
13982 | the context of its DW_AT_specification, namely the contex of die | |
13983 | #3. */ | |
13984 | spec_cu = cu; | |
13985 | spec_die = die_specification (die, &spec_cu); | |
13986 | if (spec_die == NULL) | |
13987 | parent = die->parent; | |
13988 | else | |
63d06c5c | 13989 | { |
0114d602 DJ |
13990 | parent = spec_die->parent; |
13991 | cu = spec_cu; | |
63d06c5c | 13992 | } |
0114d602 DJ |
13993 | |
13994 | if (parent == NULL) | |
13995 | return ""; | |
98bfdba5 PA |
13996 | else if (parent->building_fullname) |
13997 | { | |
13998 | const char *name; | |
13999 | const char *parent_name; | |
14000 | ||
14001 | /* It has been seen on RealView 2.2 built binaries, | |
14002 | DW_TAG_template_type_param types actually _defined_ as | |
14003 | children of the parent class: | |
14004 | ||
14005 | enum E {}; | |
14006 | template class <class Enum> Class{}; | |
14007 | Class<enum E> class_e; | |
14008 | ||
14009 | 1: DW_TAG_class_type (Class) | |
14010 | 2: DW_TAG_enumeration_type (E) | |
14011 | 3: DW_TAG_enumerator (enum1:0) | |
14012 | 3: DW_TAG_enumerator (enum2:1) | |
14013 | ... | |
14014 | 2: DW_TAG_template_type_param | |
14015 | DW_AT_type DW_FORM_ref_udata (E) | |
14016 | ||
14017 | Besides being broken debug info, it can put GDB into an | |
14018 | infinite loop. Consider: | |
14019 | ||
14020 | When we're building the full name for Class<E>, we'll start | |
14021 | at Class, and go look over its template type parameters, | |
14022 | finding E. We'll then try to build the full name of E, and | |
14023 | reach here. We're now trying to build the full name of E, | |
14024 | and look over the parent DIE for containing scope. In the | |
14025 | broken case, if we followed the parent DIE of E, we'd again | |
14026 | find Class, and once again go look at its template type | |
14027 | arguments, etc., etc. Simply don't consider such parent die | |
14028 | as source-level parent of this die (it can't be, the language | |
14029 | doesn't allow it), and break the loop here. */ | |
14030 | name = dwarf2_name (die, cu); | |
14031 | parent_name = dwarf2_name (parent, cu); | |
14032 | complaint (&symfile_complaints, | |
14033 | _("template param type '%s' defined within parent '%s'"), | |
14034 | name ? name : "<unknown>", | |
14035 | parent_name ? parent_name : "<unknown>"); | |
14036 | return ""; | |
14037 | } | |
63d06c5c | 14038 | else |
0114d602 DJ |
14039 | switch (parent->tag) |
14040 | { | |
63d06c5c | 14041 | case DW_TAG_namespace: |
0114d602 | 14042 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
14043 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
14044 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
14045 | Work around this problem here. */ | |
14046 | if (cu->language == language_cplus | |
14047 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
14048 | return ""; | |
0114d602 DJ |
14049 | /* We give a name to even anonymous namespaces. */ |
14050 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 14051 | case DW_TAG_class_type: |
680b30c7 | 14052 | case DW_TAG_interface_type: |
63d06c5c | 14053 | case DW_TAG_structure_type: |
0114d602 | 14054 | case DW_TAG_union_type: |
f55ee35c | 14055 | case DW_TAG_module: |
0114d602 DJ |
14056 | parent_type = read_type_die (parent, cu); |
14057 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
14058 | return TYPE_TAG_NAME (parent_type); | |
14059 | else | |
14060 | /* An anonymous structure is only allowed non-static data | |
14061 | members; no typedefs, no member functions, et cetera. | |
14062 | So it does not need a prefix. */ | |
14063 | return ""; | |
abc72ce4 DE |
14064 | case DW_TAG_compile_unit: |
14065 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ | |
14066 | if (cu->language == language_cplus | |
8b70b953 | 14067 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
14068 | && die->child != NULL |
14069 | && (die->tag == DW_TAG_class_type | |
14070 | || die->tag == DW_TAG_structure_type | |
14071 | || die->tag == DW_TAG_union_type)) | |
14072 | { | |
14073 | char *name = guess_full_die_structure_name (die, cu); | |
14074 | if (name != NULL) | |
14075 | return name; | |
14076 | } | |
14077 | return ""; | |
63d06c5c | 14078 | default: |
8176b9b8 | 14079 | return determine_prefix (parent, cu); |
63d06c5c | 14080 | } |
63d06c5c DC |
14081 | } |
14082 | ||
3e43a32a MS |
14083 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
14084 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
14085 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
14086 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
14087 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 14088 | |
f55ee35c | 14089 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
14090 | |
14091 | static char * | |
f55ee35c JK |
14092 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
14093 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 14094 | { |
f55ee35c | 14095 | const char *lead = ""; |
5c315b68 | 14096 | const char *sep; |
63d06c5c | 14097 | |
3e43a32a MS |
14098 | if (suffix == NULL || suffix[0] == '\0' |
14099 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
14100 | sep = ""; |
14101 | else if (cu->language == language_java) | |
14102 | sep = "."; | |
f55ee35c JK |
14103 | else if (cu->language == language_fortran && physname) |
14104 | { | |
14105 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
14106 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
14107 | ||
14108 | lead = "__"; | |
14109 | sep = "_MOD_"; | |
14110 | } | |
987504bb JJ |
14111 | else |
14112 | sep = "::"; | |
63d06c5c | 14113 | |
6dd47d34 DE |
14114 | if (prefix == NULL) |
14115 | prefix = ""; | |
14116 | if (suffix == NULL) | |
14117 | suffix = ""; | |
14118 | ||
987504bb JJ |
14119 | if (obs == NULL) |
14120 | { | |
3e43a32a MS |
14121 | char *retval |
14122 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 14123 | |
f55ee35c JK |
14124 | strcpy (retval, lead); |
14125 | strcat (retval, prefix); | |
6dd47d34 DE |
14126 | strcat (retval, sep); |
14127 | strcat (retval, suffix); | |
63d06c5c DC |
14128 | return retval; |
14129 | } | |
987504bb JJ |
14130 | else |
14131 | { | |
14132 | /* We have an obstack. */ | |
f55ee35c | 14133 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 14134 | } |
63d06c5c DC |
14135 | } |
14136 | ||
c906108c SS |
14137 | /* Return sibling of die, NULL if no sibling. */ |
14138 | ||
f9aca02d | 14139 | static struct die_info * |
fba45db2 | 14140 | sibling_die (struct die_info *die) |
c906108c | 14141 | { |
639d11d3 | 14142 | return die->sibling; |
c906108c SS |
14143 | } |
14144 | ||
71c25dea TT |
14145 | /* Get name of a die, return NULL if not found. */ |
14146 | ||
14147 | static char * | |
14148 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
14149 | struct obstack *obstack) | |
14150 | { | |
14151 | if (name && cu->language == language_cplus) | |
14152 | { | |
14153 | char *canon_name = cp_canonicalize_string (name); | |
14154 | ||
14155 | if (canon_name != NULL) | |
14156 | { | |
14157 | if (strcmp (canon_name, name) != 0) | |
14158 | name = obsavestring (canon_name, strlen (canon_name), | |
14159 | obstack); | |
14160 | xfree (canon_name); | |
14161 | } | |
14162 | } | |
14163 | ||
14164 | return name; | |
c906108c SS |
14165 | } |
14166 | ||
9219021c DC |
14167 | /* Get name of a die, return NULL if not found. */ |
14168 | ||
14169 | static char * | |
e142c38c | 14170 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
14171 | { |
14172 | struct attribute *attr; | |
14173 | ||
e142c38c | 14174 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
14175 | if ((!attr || !DW_STRING (attr)) |
14176 | && die->tag != DW_TAG_class_type | |
14177 | && die->tag != DW_TAG_interface_type | |
14178 | && die->tag != DW_TAG_structure_type | |
14179 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
14180 | return NULL; |
14181 | ||
14182 | switch (die->tag) | |
14183 | { | |
14184 | case DW_TAG_compile_unit: | |
14185 | /* Compilation units have a DW_AT_name that is a filename, not | |
14186 | a source language identifier. */ | |
14187 | case DW_TAG_enumeration_type: | |
14188 | case DW_TAG_enumerator: | |
14189 | /* These tags always have simple identifiers already; no need | |
14190 | to canonicalize them. */ | |
14191 | return DW_STRING (attr); | |
907af001 | 14192 | |
418835cc KS |
14193 | case DW_TAG_subprogram: |
14194 | /* Java constructors will all be named "<init>", so return | |
14195 | the class name when we see this special case. */ | |
14196 | if (cu->language == language_java | |
14197 | && DW_STRING (attr) != NULL | |
14198 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
14199 | { | |
14200 | struct dwarf2_cu *spec_cu = cu; | |
14201 | struct die_info *spec_die; | |
14202 | ||
14203 | /* GCJ will output '<init>' for Java constructor names. | |
14204 | For this special case, return the name of the parent class. */ | |
14205 | ||
14206 | /* GCJ may output suprogram DIEs with AT_specification set. | |
14207 | If so, use the name of the specified DIE. */ | |
14208 | spec_die = die_specification (die, &spec_cu); | |
14209 | if (spec_die != NULL) | |
14210 | return dwarf2_name (spec_die, spec_cu); | |
14211 | ||
14212 | do | |
14213 | { | |
14214 | die = die->parent; | |
14215 | if (die->tag == DW_TAG_class_type) | |
14216 | return dwarf2_name (die, cu); | |
14217 | } | |
14218 | while (die->tag != DW_TAG_compile_unit); | |
14219 | } | |
907af001 UW |
14220 | break; |
14221 | ||
14222 | case DW_TAG_class_type: | |
14223 | case DW_TAG_interface_type: | |
14224 | case DW_TAG_structure_type: | |
14225 | case DW_TAG_union_type: | |
14226 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
14227 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
14228 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
14229 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
14230 | if (attr && DW_STRING (attr) |
14231 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
14232 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 14233 | return NULL; |
53832f31 TT |
14234 | |
14235 | /* GCC might emit a nameless typedef that has a linkage name. See | |
14236 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
14237 | if (!attr || DW_STRING (attr) == NULL) | |
14238 | { | |
df5c6c50 | 14239 | char *demangled = NULL; |
53832f31 TT |
14240 | |
14241 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
14242 | if (attr == NULL) | |
14243 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
14244 | ||
14245 | if (attr == NULL || DW_STRING (attr) == NULL) | |
14246 | return NULL; | |
14247 | ||
df5c6c50 JK |
14248 | /* Avoid demangling DW_STRING (attr) the second time on a second |
14249 | call for the same DIE. */ | |
14250 | if (!DW_STRING_IS_CANONICAL (attr)) | |
14251 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
14252 | |
14253 | if (demangled) | |
14254 | { | |
96408a79 SA |
14255 | char *base; |
14256 | ||
53832f31 | 14257 | /* FIXME: we already did this for the partial symbol... */ |
96408a79 SA |
14258 | DW_STRING (attr) = obsavestring (demangled, strlen (demangled), |
14259 | &cu->objfile->objfile_obstack); | |
53832f31 TT |
14260 | DW_STRING_IS_CANONICAL (attr) = 1; |
14261 | xfree (demangled); | |
96408a79 SA |
14262 | |
14263 | /* Strip any leading namespaces/classes, keep only the base name. | |
14264 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
14265 | base = strrchr (DW_STRING (attr), ':'); | |
14266 | if (base && base > DW_STRING (attr) && base[-1] == ':') | |
14267 | return &base[1]; | |
14268 | else | |
14269 | return DW_STRING (attr); | |
53832f31 TT |
14270 | } |
14271 | } | |
907af001 UW |
14272 | break; |
14273 | ||
71c25dea | 14274 | default: |
907af001 UW |
14275 | break; |
14276 | } | |
14277 | ||
14278 | if (!DW_STRING_IS_CANONICAL (attr)) | |
14279 | { | |
14280 | DW_STRING (attr) | |
14281 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
14282 | &cu->objfile->objfile_obstack); | |
14283 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 14284 | } |
907af001 | 14285 | return DW_STRING (attr); |
9219021c DC |
14286 | } |
14287 | ||
14288 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
14289 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
14290 | containing the return value on output. */ | |
9219021c DC |
14291 | |
14292 | static struct die_info * | |
f2f0e013 | 14293 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
14294 | { |
14295 | struct attribute *attr; | |
9219021c | 14296 | |
f2f0e013 | 14297 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
14298 | if (attr == NULL) |
14299 | return NULL; | |
14300 | ||
f2f0e013 | 14301 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
14302 | } |
14303 | ||
c906108c SS |
14304 | /* Convert a DIE tag into its string name. */ |
14305 | ||
14306 | static char * | |
aa1ee363 | 14307 | dwarf_tag_name (unsigned tag) |
c906108c SS |
14308 | { |
14309 | switch (tag) | |
14310 | { | |
14311 | case DW_TAG_padding: | |
14312 | return "DW_TAG_padding"; | |
14313 | case DW_TAG_array_type: | |
14314 | return "DW_TAG_array_type"; | |
14315 | case DW_TAG_class_type: | |
14316 | return "DW_TAG_class_type"; | |
14317 | case DW_TAG_entry_point: | |
14318 | return "DW_TAG_entry_point"; | |
14319 | case DW_TAG_enumeration_type: | |
14320 | return "DW_TAG_enumeration_type"; | |
14321 | case DW_TAG_formal_parameter: | |
14322 | return "DW_TAG_formal_parameter"; | |
14323 | case DW_TAG_imported_declaration: | |
14324 | return "DW_TAG_imported_declaration"; | |
14325 | case DW_TAG_label: | |
14326 | return "DW_TAG_label"; | |
14327 | case DW_TAG_lexical_block: | |
14328 | return "DW_TAG_lexical_block"; | |
14329 | case DW_TAG_member: | |
14330 | return "DW_TAG_member"; | |
14331 | case DW_TAG_pointer_type: | |
14332 | return "DW_TAG_pointer_type"; | |
14333 | case DW_TAG_reference_type: | |
14334 | return "DW_TAG_reference_type"; | |
14335 | case DW_TAG_compile_unit: | |
14336 | return "DW_TAG_compile_unit"; | |
14337 | case DW_TAG_string_type: | |
14338 | return "DW_TAG_string_type"; | |
14339 | case DW_TAG_structure_type: | |
14340 | return "DW_TAG_structure_type"; | |
14341 | case DW_TAG_subroutine_type: | |
14342 | return "DW_TAG_subroutine_type"; | |
14343 | case DW_TAG_typedef: | |
14344 | return "DW_TAG_typedef"; | |
14345 | case DW_TAG_union_type: | |
14346 | return "DW_TAG_union_type"; | |
14347 | case DW_TAG_unspecified_parameters: | |
14348 | return "DW_TAG_unspecified_parameters"; | |
14349 | case DW_TAG_variant: | |
14350 | return "DW_TAG_variant"; | |
14351 | case DW_TAG_common_block: | |
14352 | return "DW_TAG_common_block"; | |
14353 | case DW_TAG_common_inclusion: | |
14354 | return "DW_TAG_common_inclusion"; | |
14355 | case DW_TAG_inheritance: | |
14356 | return "DW_TAG_inheritance"; | |
14357 | case DW_TAG_inlined_subroutine: | |
14358 | return "DW_TAG_inlined_subroutine"; | |
14359 | case DW_TAG_module: | |
14360 | return "DW_TAG_module"; | |
14361 | case DW_TAG_ptr_to_member_type: | |
14362 | return "DW_TAG_ptr_to_member_type"; | |
14363 | case DW_TAG_set_type: | |
14364 | return "DW_TAG_set_type"; | |
14365 | case DW_TAG_subrange_type: | |
14366 | return "DW_TAG_subrange_type"; | |
14367 | case DW_TAG_with_stmt: | |
14368 | return "DW_TAG_with_stmt"; | |
14369 | case DW_TAG_access_declaration: | |
14370 | return "DW_TAG_access_declaration"; | |
14371 | case DW_TAG_base_type: | |
14372 | return "DW_TAG_base_type"; | |
14373 | case DW_TAG_catch_block: | |
14374 | return "DW_TAG_catch_block"; | |
14375 | case DW_TAG_const_type: | |
14376 | return "DW_TAG_const_type"; | |
14377 | case DW_TAG_constant: | |
14378 | return "DW_TAG_constant"; | |
14379 | case DW_TAG_enumerator: | |
14380 | return "DW_TAG_enumerator"; | |
14381 | case DW_TAG_file_type: | |
14382 | return "DW_TAG_file_type"; | |
14383 | case DW_TAG_friend: | |
14384 | return "DW_TAG_friend"; | |
14385 | case DW_TAG_namelist: | |
14386 | return "DW_TAG_namelist"; | |
14387 | case DW_TAG_namelist_item: | |
14388 | return "DW_TAG_namelist_item"; | |
14389 | case DW_TAG_packed_type: | |
14390 | return "DW_TAG_packed_type"; | |
14391 | case DW_TAG_subprogram: | |
14392 | return "DW_TAG_subprogram"; | |
14393 | case DW_TAG_template_type_param: | |
14394 | return "DW_TAG_template_type_param"; | |
14395 | case DW_TAG_template_value_param: | |
14396 | return "DW_TAG_template_value_param"; | |
14397 | case DW_TAG_thrown_type: | |
14398 | return "DW_TAG_thrown_type"; | |
14399 | case DW_TAG_try_block: | |
14400 | return "DW_TAG_try_block"; | |
14401 | case DW_TAG_variant_part: | |
14402 | return "DW_TAG_variant_part"; | |
14403 | case DW_TAG_variable: | |
14404 | return "DW_TAG_variable"; | |
14405 | case DW_TAG_volatile_type: | |
14406 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
14407 | case DW_TAG_dwarf_procedure: |
14408 | return "DW_TAG_dwarf_procedure"; | |
14409 | case DW_TAG_restrict_type: | |
14410 | return "DW_TAG_restrict_type"; | |
14411 | case DW_TAG_interface_type: | |
14412 | return "DW_TAG_interface_type"; | |
14413 | case DW_TAG_namespace: | |
14414 | return "DW_TAG_namespace"; | |
14415 | case DW_TAG_imported_module: | |
14416 | return "DW_TAG_imported_module"; | |
14417 | case DW_TAG_unspecified_type: | |
14418 | return "DW_TAG_unspecified_type"; | |
14419 | case DW_TAG_partial_unit: | |
14420 | return "DW_TAG_partial_unit"; | |
14421 | case DW_TAG_imported_unit: | |
14422 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
14423 | case DW_TAG_condition: |
14424 | return "DW_TAG_condition"; | |
14425 | case DW_TAG_shared_type: | |
14426 | return "DW_TAG_shared_type"; | |
348e048f DE |
14427 | case DW_TAG_type_unit: |
14428 | return "DW_TAG_type_unit"; | |
c906108c SS |
14429 | case DW_TAG_MIPS_loop: |
14430 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
14431 | case DW_TAG_HP_array_descriptor: |
14432 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
14433 | case DW_TAG_format_label: |
14434 | return "DW_TAG_format_label"; | |
14435 | case DW_TAG_function_template: | |
14436 | return "DW_TAG_function_template"; | |
14437 | case DW_TAG_class_template: | |
14438 | return "DW_TAG_class_template"; | |
b7619582 GF |
14439 | case DW_TAG_GNU_BINCL: |
14440 | return "DW_TAG_GNU_BINCL"; | |
14441 | case DW_TAG_GNU_EINCL: | |
14442 | return "DW_TAG_GNU_EINCL"; | |
14443 | case DW_TAG_upc_shared_type: | |
14444 | return "DW_TAG_upc_shared_type"; | |
14445 | case DW_TAG_upc_strict_type: | |
14446 | return "DW_TAG_upc_strict_type"; | |
14447 | case DW_TAG_upc_relaxed_type: | |
14448 | return "DW_TAG_upc_relaxed_type"; | |
14449 | case DW_TAG_PGI_kanji_type: | |
14450 | return "DW_TAG_PGI_kanji_type"; | |
14451 | case DW_TAG_PGI_interface_block: | |
14452 | return "DW_TAG_PGI_interface_block"; | |
96408a79 SA |
14453 | case DW_TAG_GNU_call_site: |
14454 | return "DW_TAG_GNU_call_site"; | |
c906108c SS |
14455 | default: |
14456 | return "DW_TAG_<unknown>"; | |
14457 | } | |
14458 | } | |
14459 | ||
14460 | /* Convert a DWARF attribute code into its string name. */ | |
14461 | ||
14462 | static char * | |
aa1ee363 | 14463 | dwarf_attr_name (unsigned attr) |
c906108c SS |
14464 | { |
14465 | switch (attr) | |
14466 | { | |
14467 | case DW_AT_sibling: | |
14468 | return "DW_AT_sibling"; | |
14469 | case DW_AT_location: | |
14470 | return "DW_AT_location"; | |
14471 | case DW_AT_name: | |
14472 | return "DW_AT_name"; | |
14473 | case DW_AT_ordering: | |
14474 | return "DW_AT_ordering"; | |
14475 | case DW_AT_subscr_data: | |
14476 | return "DW_AT_subscr_data"; | |
14477 | case DW_AT_byte_size: | |
14478 | return "DW_AT_byte_size"; | |
14479 | case DW_AT_bit_offset: | |
14480 | return "DW_AT_bit_offset"; | |
14481 | case DW_AT_bit_size: | |
14482 | return "DW_AT_bit_size"; | |
14483 | case DW_AT_element_list: | |
14484 | return "DW_AT_element_list"; | |
14485 | case DW_AT_stmt_list: | |
14486 | return "DW_AT_stmt_list"; | |
14487 | case DW_AT_low_pc: | |
14488 | return "DW_AT_low_pc"; | |
14489 | case DW_AT_high_pc: | |
14490 | return "DW_AT_high_pc"; | |
14491 | case DW_AT_language: | |
14492 | return "DW_AT_language"; | |
14493 | case DW_AT_member: | |
14494 | return "DW_AT_member"; | |
14495 | case DW_AT_discr: | |
14496 | return "DW_AT_discr"; | |
14497 | case DW_AT_discr_value: | |
14498 | return "DW_AT_discr_value"; | |
14499 | case DW_AT_visibility: | |
14500 | return "DW_AT_visibility"; | |
14501 | case DW_AT_import: | |
14502 | return "DW_AT_import"; | |
14503 | case DW_AT_string_length: | |
14504 | return "DW_AT_string_length"; | |
14505 | case DW_AT_common_reference: | |
14506 | return "DW_AT_common_reference"; | |
14507 | case DW_AT_comp_dir: | |
14508 | return "DW_AT_comp_dir"; | |
14509 | case DW_AT_const_value: | |
14510 | return "DW_AT_const_value"; | |
14511 | case DW_AT_containing_type: | |
14512 | return "DW_AT_containing_type"; | |
14513 | case DW_AT_default_value: | |
14514 | return "DW_AT_default_value"; | |
14515 | case DW_AT_inline: | |
14516 | return "DW_AT_inline"; | |
14517 | case DW_AT_is_optional: | |
14518 | return "DW_AT_is_optional"; | |
14519 | case DW_AT_lower_bound: | |
14520 | return "DW_AT_lower_bound"; | |
14521 | case DW_AT_producer: | |
14522 | return "DW_AT_producer"; | |
14523 | case DW_AT_prototyped: | |
14524 | return "DW_AT_prototyped"; | |
14525 | case DW_AT_return_addr: | |
14526 | return "DW_AT_return_addr"; | |
14527 | case DW_AT_start_scope: | |
14528 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
14529 | case DW_AT_bit_stride: |
14530 | return "DW_AT_bit_stride"; | |
c906108c SS |
14531 | case DW_AT_upper_bound: |
14532 | return "DW_AT_upper_bound"; | |
14533 | case DW_AT_abstract_origin: | |
14534 | return "DW_AT_abstract_origin"; | |
14535 | case DW_AT_accessibility: | |
14536 | return "DW_AT_accessibility"; | |
14537 | case DW_AT_address_class: | |
14538 | return "DW_AT_address_class"; | |
14539 | case DW_AT_artificial: | |
14540 | return "DW_AT_artificial"; | |
14541 | case DW_AT_base_types: | |
14542 | return "DW_AT_base_types"; | |
14543 | case DW_AT_calling_convention: | |
14544 | return "DW_AT_calling_convention"; | |
14545 | case DW_AT_count: | |
14546 | return "DW_AT_count"; | |
14547 | case DW_AT_data_member_location: | |
14548 | return "DW_AT_data_member_location"; | |
14549 | case DW_AT_decl_column: | |
14550 | return "DW_AT_decl_column"; | |
14551 | case DW_AT_decl_file: | |
14552 | return "DW_AT_decl_file"; | |
14553 | case DW_AT_decl_line: | |
14554 | return "DW_AT_decl_line"; | |
14555 | case DW_AT_declaration: | |
14556 | return "DW_AT_declaration"; | |
14557 | case DW_AT_discr_list: | |
14558 | return "DW_AT_discr_list"; | |
14559 | case DW_AT_encoding: | |
14560 | return "DW_AT_encoding"; | |
14561 | case DW_AT_external: | |
14562 | return "DW_AT_external"; | |
14563 | case DW_AT_frame_base: | |
14564 | return "DW_AT_frame_base"; | |
14565 | case DW_AT_friend: | |
14566 | return "DW_AT_friend"; | |
14567 | case DW_AT_identifier_case: | |
14568 | return "DW_AT_identifier_case"; | |
14569 | case DW_AT_macro_info: | |
14570 | return "DW_AT_macro_info"; | |
14571 | case DW_AT_namelist_items: | |
14572 | return "DW_AT_namelist_items"; | |
14573 | case DW_AT_priority: | |
14574 | return "DW_AT_priority"; | |
14575 | case DW_AT_segment: | |
14576 | return "DW_AT_segment"; | |
14577 | case DW_AT_specification: | |
14578 | return "DW_AT_specification"; | |
14579 | case DW_AT_static_link: | |
14580 | return "DW_AT_static_link"; | |
14581 | case DW_AT_type: | |
14582 | return "DW_AT_type"; | |
14583 | case DW_AT_use_location: | |
14584 | return "DW_AT_use_location"; | |
14585 | case DW_AT_variable_parameter: | |
14586 | return "DW_AT_variable_parameter"; | |
14587 | case DW_AT_virtuality: | |
14588 | return "DW_AT_virtuality"; | |
14589 | case DW_AT_vtable_elem_location: | |
14590 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 14591 | /* DWARF 3 values. */ |
d9fa45fe DC |
14592 | case DW_AT_allocated: |
14593 | return "DW_AT_allocated"; | |
14594 | case DW_AT_associated: | |
14595 | return "DW_AT_associated"; | |
14596 | case DW_AT_data_location: | |
14597 | return "DW_AT_data_location"; | |
09fa0d7c JK |
14598 | case DW_AT_byte_stride: |
14599 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
14600 | case DW_AT_entry_pc: |
14601 | return "DW_AT_entry_pc"; | |
14602 | case DW_AT_use_UTF8: | |
14603 | return "DW_AT_use_UTF8"; | |
14604 | case DW_AT_extension: | |
14605 | return "DW_AT_extension"; | |
14606 | case DW_AT_ranges: | |
14607 | return "DW_AT_ranges"; | |
14608 | case DW_AT_trampoline: | |
14609 | return "DW_AT_trampoline"; | |
14610 | case DW_AT_call_column: | |
14611 | return "DW_AT_call_column"; | |
14612 | case DW_AT_call_file: | |
14613 | return "DW_AT_call_file"; | |
14614 | case DW_AT_call_line: | |
14615 | return "DW_AT_call_line"; | |
b7619582 GF |
14616 | case DW_AT_description: |
14617 | return "DW_AT_description"; | |
14618 | case DW_AT_binary_scale: | |
14619 | return "DW_AT_binary_scale"; | |
14620 | case DW_AT_decimal_scale: | |
14621 | return "DW_AT_decimal_scale"; | |
14622 | case DW_AT_small: | |
14623 | return "DW_AT_small"; | |
14624 | case DW_AT_decimal_sign: | |
14625 | return "DW_AT_decimal_sign"; | |
14626 | case DW_AT_digit_count: | |
14627 | return "DW_AT_digit_count"; | |
14628 | case DW_AT_picture_string: | |
14629 | return "DW_AT_picture_string"; | |
14630 | case DW_AT_mutable: | |
14631 | return "DW_AT_mutable"; | |
14632 | case DW_AT_threads_scaled: | |
14633 | return "DW_AT_threads_scaled"; | |
14634 | case DW_AT_explicit: | |
14635 | return "DW_AT_explicit"; | |
14636 | case DW_AT_object_pointer: | |
14637 | return "DW_AT_object_pointer"; | |
14638 | case DW_AT_endianity: | |
14639 | return "DW_AT_endianity"; | |
14640 | case DW_AT_elemental: | |
14641 | return "DW_AT_elemental"; | |
14642 | case DW_AT_pure: | |
14643 | return "DW_AT_pure"; | |
14644 | case DW_AT_recursive: | |
14645 | return "DW_AT_recursive"; | |
348e048f DE |
14646 | /* DWARF 4 values. */ |
14647 | case DW_AT_signature: | |
14648 | return "DW_AT_signature"; | |
31ef98ae TT |
14649 | case DW_AT_linkage_name: |
14650 | return "DW_AT_linkage_name"; | |
3019eac3 DE |
14651 | /* Tentative Fission values. */ |
14652 | case DW_AT_GNU_dwo_name: | |
14653 | return "DW_AT_GNU_dwo_name"; | |
14654 | case DW_AT_GNU_dwo_id: | |
14655 | return "DW_AT_GNU_dwo_id"; | |
14656 | case DW_AT_GNU_addr_base: | |
14657 | return "DW_AT_GNU_addr_base"; | |
14658 | case DW_AT_GNU_pubnames: | |
14659 | return "DW_AT_GNU_pubnames"; | |
14660 | case DW_AT_GNU_pubtypes: | |
14661 | return "DW_AT_GNU_pubtypes"; | |
b7619582 | 14662 | /* SGI/MIPS extensions. */ |
c764a876 | 14663 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
14664 | case DW_AT_MIPS_fde: |
14665 | return "DW_AT_MIPS_fde"; | |
c764a876 | 14666 | #endif |
c906108c SS |
14667 | case DW_AT_MIPS_loop_begin: |
14668 | return "DW_AT_MIPS_loop_begin"; | |
14669 | case DW_AT_MIPS_tail_loop_begin: | |
14670 | return "DW_AT_MIPS_tail_loop_begin"; | |
14671 | case DW_AT_MIPS_epilog_begin: | |
14672 | return "DW_AT_MIPS_epilog_begin"; | |
14673 | case DW_AT_MIPS_loop_unroll_factor: | |
14674 | return "DW_AT_MIPS_loop_unroll_factor"; | |
14675 | case DW_AT_MIPS_software_pipeline_depth: | |
14676 | return "DW_AT_MIPS_software_pipeline_depth"; | |
14677 | case DW_AT_MIPS_linkage_name: | |
14678 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
14679 | case DW_AT_MIPS_stride: |
14680 | return "DW_AT_MIPS_stride"; | |
14681 | case DW_AT_MIPS_abstract_name: | |
14682 | return "DW_AT_MIPS_abstract_name"; | |
14683 | case DW_AT_MIPS_clone_origin: | |
14684 | return "DW_AT_MIPS_clone_origin"; | |
14685 | case DW_AT_MIPS_has_inlines: | |
14686 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 14687 | /* HP extensions. */ |
c764a876 | 14688 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
14689 | case DW_AT_HP_block_index: |
14690 | return "DW_AT_HP_block_index"; | |
c764a876 | 14691 | #endif |
b7619582 GF |
14692 | case DW_AT_HP_unmodifiable: |
14693 | return "DW_AT_HP_unmodifiable"; | |
14694 | case DW_AT_HP_actuals_stmt_list: | |
14695 | return "DW_AT_HP_actuals_stmt_list"; | |
14696 | case DW_AT_HP_proc_per_section: | |
14697 | return "DW_AT_HP_proc_per_section"; | |
14698 | case DW_AT_HP_raw_data_ptr: | |
14699 | return "DW_AT_HP_raw_data_ptr"; | |
14700 | case DW_AT_HP_pass_by_reference: | |
14701 | return "DW_AT_HP_pass_by_reference"; | |
14702 | case DW_AT_HP_opt_level: | |
14703 | return "DW_AT_HP_opt_level"; | |
14704 | case DW_AT_HP_prof_version_id: | |
14705 | return "DW_AT_HP_prof_version_id"; | |
14706 | case DW_AT_HP_opt_flags: | |
14707 | return "DW_AT_HP_opt_flags"; | |
14708 | case DW_AT_HP_cold_region_low_pc: | |
14709 | return "DW_AT_HP_cold_region_low_pc"; | |
14710 | case DW_AT_HP_cold_region_high_pc: | |
14711 | return "DW_AT_HP_cold_region_high_pc"; | |
14712 | case DW_AT_HP_all_variables_modifiable: | |
14713 | return "DW_AT_HP_all_variables_modifiable"; | |
14714 | case DW_AT_HP_linkage_name: | |
14715 | return "DW_AT_HP_linkage_name"; | |
14716 | case DW_AT_HP_prof_flags: | |
14717 | return "DW_AT_HP_prof_flags"; | |
14718 | /* GNU extensions. */ | |
c906108c SS |
14719 | case DW_AT_sf_names: |
14720 | return "DW_AT_sf_names"; | |
14721 | case DW_AT_src_info: | |
14722 | return "DW_AT_src_info"; | |
14723 | case DW_AT_mac_info: | |
14724 | return "DW_AT_mac_info"; | |
14725 | case DW_AT_src_coords: | |
14726 | return "DW_AT_src_coords"; | |
14727 | case DW_AT_body_begin: | |
14728 | return "DW_AT_body_begin"; | |
14729 | case DW_AT_body_end: | |
14730 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
14731 | case DW_AT_GNU_vector: |
14732 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
14733 | case DW_AT_GNU_odr_signature: |
14734 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
14735 | /* VMS extensions. */ |
14736 | case DW_AT_VMS_rtnbeg_pd_address: | |
14737 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
14738 | /* UPC extension. */ | |
14739 | case DW_AT_upc_threads_scaled: | |
14740 | return "DW_AT_upc_threads_scaled"; | |
14741 | /* PGI (STMicroelectronics) extensions. */ | |
14742 | case DW_AT_PGI_lbase: | |
14743 | return "DW_AT_PGI_lbase"; | |
14744 | case DW_AT_PGI_soffset: | |
14745 | return "DW_AT_PGI_soffset"; | |
14746 | case DW_AT_PGI_lstride: | |
14747 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
14748 | default: |
14749 | return "DW_AT_<unknown>"; | |
14750 | } | |
14751 | } | |
14752 | ||
14753 | /* Convert a DWARF value form code into its string name. */ | |
14754 | ||
14755 | static char * | |
aa1ee363 | 14756 | dwarf_form_name (unsigned form) |
c906108c SS |
14757 | { |
14758 | switch (form) | |
14759 | { | |
14760 | case DW_FORM_addr: | |
14761 | return "DW_FORM_addr"; | |
14762 | case DW_FORM_block2: | |
14763 | return "DW_FORM_block2"; | |
14764 | case DW_FORM_block4: | |
14765 | return "DW_FORM_block4"; | |
14766 | case DW_FORM_data2: | |
14767 | return "DW_FORM_data2"; | |
14768 | case DW_FORM_data4: | |
14769 | return "DW_FORM_data4"; | |
14770 | case DW_FORM_data8: | |
14771 | return "DW_FORM_data8"; | |
14772 | case DW_FORM_string: | |
14773 | return "DW_FORM_string"; | |
14774 | case DW_FORM_block: | |
14775 | return "DW_FORM_block"; | |
14776 | case DW_FORM_block1: | |
14777 | return "DW_FORM_block1"; | |
14778 | case DW_FORM_data1: | |
14779 | return "DW_FORM_data1"; | |
14780 | case DW_FORM_flag: | |
14781 | return "DW_FORM_flag"; | |
14782 | case DW_FORM_sdata: | |
14783 | return "DW_FORM_sdata"; | |
14784 | case DW_FORM_strp: | |
14785 | return "DW_FORM_strp"; | |
14786 | case DW_FORM_udata: | |
14787 | return "DW_FORM_udata"; | |
14788 | case DW_FORM_ref_addr: | |
14789 | return "DW_FORM_ref_addr"; | |
14790 | case DW_FORM_ref1: | |
14791 | return "DW_FORM_ref1"; | |
14792 | case DW_FORM_ref2: | |
14793 | return "DW_FORM_ref2"; | |
14794 | case DW_FORM_ref4: | |
14795 | return "DW_FORM_ref4"; | |
14796 | case DW_FORM_ref8: | |
14797 | return "DW_FORM_ref8"; | |
14798 | case DW_FORM_ref_udata: | |
14799 | return "DW_FORM_ref_udata"; | |
14800 | case DW_FORM_indirect: | |
14801 | return "DW_FORM_indirect"; | |
348e048f DE |
14802 | case DW_FORM_sec_offset: |
14803 | return "DW_FORM_sec_offset"; | |
14804 | case DW_FORM_exprloc: | |
14805 | return "DW_FORM_exprloc"; | |
14806 | case DW_FORM_flag_present: | |
14807 | return "DW_FORM_flag_present"; | |
55f1336d TT |
14808 | case DW_FORM_ref_sig8: |
14809 | return "DW_FORM_ref_sig8"; | |
3019eac3 DE |
14810 | case DW_FORM_GNU_addr_index: |
14811 | return "DW_FORM_GNU_addr_index"; | |
14812 | case DW_FORM_GNU_str_index: | |
14813 | return "DW_FORM_GNU_str_index"; | |
c906108c SS |
14814 | default: |
14815 | return "DW_FORM_<unknown>"; | |
14816 | } | |
14817 | } | |
14818 | ||
14819 | /* Convert a DWARF stack opcode into its string name. */ | |
14820 | ||
9eae7c52 | 14821 | const char * |
b1bfef65 | 14822 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
14823 | { |
14824 | switch (op) | |
14825 | { | |
14826 | case DW_OP_addr: | |
14827 | return "DW_OP_addr"; | |
14828 | case DW_OP_deref: | |
14829 | return "DW_OP_deref"; | |
14830 | case DW_OP_const1u: | |
14831 | return "DW_OP_const1u"; | |
14832 | case DW_OP_const1s: | |
14833 | return "DW_OP_const1s"; | |
14834 | case DW_OP_const2u: | |
14835 | return "DW_OP_const2u"; | |
14836 | case DW_OP_const2s: | |
14837 | return "DW_OP_const2s"; | |
14838 | case DW_OP_const4u: | |
14839 | return "DW_OP_const4u"; | |
14840 | case DW_OP_const4s: | |
14841 | return "DW_OP_const4s"; | |
14842 | case DW_OP_const8u: | |
14843 | return "DW_OP_const8u"; | |
14844 | case DW_OP_const8s: | |
14845 | return "DW_OP_const8s"; | |
14846 | case DW_OP_constu: | |
14847 | return "DW_OP_constu"; | |
14848 | case DW_OP_consts: | |
14849 | return "DW_OP_consts"; | |
14850 | case DW_OP_dup: | |
14851 | return "DW_OP_dup"; | |
14852 | case DW_OP_drop: | |
14853 | return "DW_OP_drop"; | |
14854 | case DW_OP_over: | |
14855 | return "DW_OP_over"; | |
14856 | case DW_OP_pick: | |
14857 | return "DW_OP_pick"; | |
14858 | case DW_OP_swap: | |
14859 | return "DW_OP_swap"; | |
14860 | case DW_OP_rot: | |
14861 | return "DW_OP_rot"; | |
14862 | case DW_OP_xderef: | |
14863 | return "DW_OP_xderef"; | |
14864 | case DW_OP_abs: | |
14865 | return "DW_OP_abs"; | |
14866 | case DW_OP_and: | |
14867 | return "DW_OP_and"; | |
14868 | case DW_OP_div: | |
14869 | return "DW_OP_div"; | |
14870 | case DW_OP_minus: | |
14871 | return "DW_OP_minus"; | |
14872 | case DW_OP_mod: | |
14873 | return "DW_OP_mod"; | |
14874 | case DW_OP_mul: | |
14875 | return "DW_OP_mul"; | |
14876 | case DW_OP_neg: | |
14877 | return "DW_OP_neg"; | |
14878 | case DW_OP_not: | |
14879 | return "DW_OP_not"; | |
14880 | case DW_OP_or: | |
14881 | return "DW_OP_or"; | |
14882 | case DW_OP_plus: | |
14883 | return "DW_OP_plus"; | |
14884 | case DW_OP_plus_uconst: | |
14885 | return "DW_OP_plus_uconst"; | |
14886 | case DW_OP_shl: | |
14887 | return "DW_OP_shl"; | |
14888 | case DW_OP_shr: | |
14889 | return "DW_OP_shr"; | |
14890 | case DW_OP_shra: | |
14891 | return "DW_OP_shra"; | |
14892 | case DW_OP_xor: | |
14893 | return "DW_OP_xor"; | |
14894 | case DW_OP_bra: | |
14895 | return "DW_OP_bra"; | |
14896 | case DW_OP_eq: | |
14897 | return "DW_OP_eq"; | |
14898 | case DW_OP_ge: | |
14899 | return "DW_OP_ge"; | |
14900 | case DW_OP_gt: | |
14901 | return "DW_OP_gt"; | |
14902 | case DW_OP_le: | |
14903 | return "DW_OP_le"; | |
14904 | case DW_OP_lt: | |
14905 | return "DW_OP_lt"; | |
14906 | case DW_OP_ne: | |
14907 | return "DW_OP_ne"; | |
14908 | case DW_OP_skip: | |
14909 | return "DW_OP_skip"; | |
14910 | case DW_OP_lit0: | |
14911 | return "DW_OP_lit0"; | |
14912 | case DW_OP_lit1: | |
14913 | return "DW_OP_lit1"; | |
14914 | case DW_OP_lit2: | |
14915 | return "DW_OP_lit2"; | |
14916 | case DW_OP_lit3: | |
14917 | return "DW_OP_lit3"; | |
14918 | case DW_OP_lit4: | |
14919 | return "DW_OP_lit4"; | |
14920 | case DW_OP_lit5: | |
14921 | return "DW_OP_lit5"; | |
14922 | case DW_OP_lit6: | |
14923 | return "DW_OP_lit6"; | |
14924 | case DW_OP_lit7: | |
14925 | return "DW_OP_lit7"; | |
14926 | case DW_OP_lit8: | |
14927 | return "DW_OP_lit8"; | |
14928 | case DW_OP_lit9: | |
14929 | return "DW_OP_lit9"; | |
14930 | case DW_OP_lit10: | |
14931 | return "DW_OP_lit10"; | |
14932 | case DW_OP_lit11: | |
14933 | return "DW_OP_lit11"; | |
14934 | case DW_OP_lit12: | |
14935 | return "DW_OP_lit12"; | |
14936 | case DW_OP_lit13: | |
14937 | return "DW_OP_lit13"; | |
14938 | case DW_OP_lit14: | |
14939 | return "DW_OP_lit14"; | |
14940 | case DW_OP_lit15: | |
14941 | return "DW_OP_lit15"; | |
14942 | case DW_OP_lit16: | |
14943 | return "DW_OP_lit16"; | |
14944 | case DW_OP_lit17: | |
14945 | return "DW_OP_lit17"; | |
14946 | case DW_OP_lit18: | |
14947 | return "DW_OP_lit18"; | |
14948 | case DW_OP_lit19: | |
14949 | return "DW_OP_lit19"; | |
14950 | case DW_OP_lit20: | |
14951 | return "DW_OP_lit20"; | |
14952 | case DW_OP_lit21: | |
14953 | return "DW_OP_lit21"; | |
14954 | case DW_OP_lit22: | |
14955 | return "DW_OP_lit22"; | |
14956 | case DW_OP_lit23: | |
14957 | return "DW_OP_lit23"; | |
14958 | case DW_OP_lit24: | |
14959 | return "DW_OP_lit24"; | |
14960 | case DW_OP_lit25: | |
14961 | return "DW_OP_lit25"; | |
14962 | case DW_OP_lit26: | |
14963 | return "DW_OP_lit26"; | |
14964 | case DW_OP_lit27: | |
14965 | return "DW_OP_lit27"; | |
14966 | case DW_OP_lit28: | |
14967 | return "DW_OP_lit28"; | |
14968 | case DW_OP_lit29: | |
14969 | return "DW_OP_lit29"; | |
14970 | case DW_OP_lit30: | |
14971 | return "DW_OP_lit30"; | |
14972 | case DW_OP_lit31: | |
14973 | return "DW_OP_lit31"; | |
14974 | case DW_OP_reg0: | |
14975 | return "DW_OP_reg0"; | |
14976 | case DW_OP_reg1: | |
14977 | return "DW_OP_reg1"; | |
14978 | case DW_OP_reg2: | |
14979 | return "DW_OP_reg2"; | |
14980 | case DW_OP_reg3: | |
14981 | return "DW_OP_reg3"; | |
14982 | case DW_OP_reg4: | |
14983 | return "DW_OP_reg4"; | |
14984 | case DW_OP_reg5: | |
14985 | return "DW_OP_reg5"; | |
14986 | case DW_OP_reg6: | |
14987 | return "DW_OP_reg6"; | |
14988 | case DW_OP_reg7: | |
14989 | return "DW_OP_reg7"; | |
14990 | case DW_OP_reg8: | |
14991 | return "DW_OP_reg8"; | |
14992 | case DW_OP_reg9: | |
14993 | return "DW_OP_reg9"; | |
14994 | case DW_OP_reg10: | |
14995 | return "DW_OP_reg10"; | |
14996 | case DW_OP_reg11: | |
14997 | return "DW_OP_reg11"; | |
14998 | case DW_OP_reg12: | |
14999 | return "DW_OP_reg12"; | |
15000 | case DW_OP_reg13: | |
15001 | return "DW_OP_reg13"; | |
15002 | case DW_OP_reg14: | |
15003 | return "DW_OP_reg14"; | |
15004 | case DW_OP_reg15: | |
15005 | return "DW_OP_reg15"; | |
15006 | case DW_OP_reg16: | |
15007 | return "DW_OP_reg16"; | |
15008 | case DW_OP_reg17: | |
15009 | return "DW_OP_reg17"; | |
15010 | case DW_OP_reg18: | |
15011 | return "DW_OP_reg18"; | |
15012 | case DW_OP_reg19: | |
15013 | return "DW_OP_reg19"; | |
15014 | case DW_OP_reg20: | |
15015 | return "DW_OP_reg20"; | |
15016 | case DW_OP_reg21: | |
15017 | return "DW_OP_reg21"; | |
15018 | case DW_OP_reg22: | |
15019 | return "DW_OP_reg22"; | |
15020 | case DW_OP_reg23: | |
15021 | return "DW_OP_reg23"; | |
15022 | case DW_OP_reg24: | |
15023 | return "DW_OP_reg24"; | |
15024 | case DW_OP_reg25: | |
15025 | return "DW_OP_reg25"; | |
15026 | case DW_OP_reg26: | |
15027 | return "DW_OP_reg26"; | |
15028 | case DW_OP_reg27: | |
15029 | return "DW_OP_reg27"; | |
15030 | case DW_OP_reg28: | |
15031 | return "DW_OP_reg28"; | |
15032 | case DW_OP_reg29: | |
15033 | return "DW_OP_reg29"; | |
15034 | case DW_OP_reg30: | |
15035 | return "DW_OP_reg30"; | |
15036 | case DW_OP_reg31: | |
15037 | return "DW_OP_reg31"; | |
15038 | case DW_OP_breg0: | |
15039 | return "DW_OP_breg0"; | |
15040 | case DW_OP_breg1: | |
15041 | return "DW_OP_breg1"; | |
15042 | case DW_OP_breg2: | |
15043 | return "DW_OP_breg2"; | |
15044 | case DW_OP_breg3: | |
15045 | return "DW_OP_breg3"; | |
15046 | case DW_OP_breg4: | |
15047 | return "DW_OP_breg4"; | |
15048 | case DW_OP_breg5: | |
15049 | return "DW_OP_breg5"; | |
15050 | case DW_OP_breg6: | |
15051 | return "DW_OP_breg6"; | |
15052 | case DW_OP_breg7: | |
15053 | return "DW_OP_breg7"; | |
15054 | case DW_OP_breg8: | |
15055 | return "DW_OP_breg8"; | |
15056 | case DW_OP_breg9: | |
15057 | return "DW_OP_breg9"; | |
15058 | case DW_OP_breg10: | |
15059 | return "DW_OP_breg10"; | |
15060 | case DW_OP_breg11: | |
15061 | return "DW_OP_breg11"; | |
15062 | case DW_OP_breg12: | |
15063 | return "DW_OP_breg12"; | |
15064 | case DW_OP_breg13: | |
15065 | return "DW_OP_breg13"; | |
15066 | case DW_OP_breg14: | |
15067 | return "DW_OP_breg14"; | |
15068 | case DW_OP_breg15: | |
15069 | return "DW_OP_breg15"; | |
15070 | case DW_OP_breg16: | |
15071 | return "DW_OP_breg16"; | |
15072 | case DW_OP_breg17: | |
15073 | return "DW_OP_breg17"; | |
15074 | case DW_OP_breg18: | |
15075 | return "DW_OP_breg18"; | |
15076 | case DW_OP_breg19: | |
15077 | return "DW_OP_breg19"; | |
15078 | case DW_OP_breg20: | |
15079 | return "DW_OP_breg20"; | |
15080 | case DW_OP_breg21: | |
15081 | return "DW_OP_breg21"; | |
15082 | case DW_OP_breg22: | |
15083 | return "DW_OP_breg22"; | |
15084 | case DW_OP_breg23: | |
15085 | return "DW_OP_breg23"; | |
15086 | case DW_OP_breg24: | |
15087 | return "DW_OP_breg24"; | |
15088 | case DW_OP_breg25: | |
15089 | return "DW_OP_breg25"; | |
15090 | case DW_OP_breg26: | |
15091 | return "DW_OP_breg26"; | |
15092 | case DW_OP_breg27: | |
15093 | return "DW_OP_breg27"; | |
15094 | case DW_OP_breg28: | |
15095 | return "DW_OP_breg28"; | |
15096 | case DW_OP_breg29: | |
15097 | return "DW_OP_breg29"; | |
15098 | case DW_OP_breg30: | |
15099 | return "DW_OP_breg30"; | |
15100 | case DW_OP_breg31: | |
15101 | return "DW_OP_breg31"; | |
15102 | case DW_OP_regx: | |
15103 | return "DW_OP_regx"; | |
15104 | case DW_OP_fbreg: | |
15105 | return "DW_OP_fbreg"; | |
15106 | case DW_OP_bregx: | |
15107 | return "DW_OP_bregx"; | |
15108 | case DW_OP_piece: | |
15109 | return "DW_OP_piece"; | |
15110 | case DW_OP_deref_size: | |
15111 | return "DW_OP_deref_size"; | |
15112 | case DW_OP_xderef_size: | |
15113 | return "DW_OP_xderef_size"; | |
15114 | case DW_OP_nop: | |
15115 | return "DW_OP_nop"; | |
b7619582 | 15116 | /* DWARF 3 extensions. */ |
ed348acc EZ |
15117 | case DW_OP_push_object_address: |
15118 | return "DW_OP_push_object_address"; | |
15119 | case DW_OP_call2: | |
15120 | return "DW_OP_call2"; | |
15121 | case DW_OP_call4: | |
15122 | return "DW_OP_call4"; | |
15123 | case DW_OP_call_ref: | |
15124 | return "DW_OP_call_ref"; | |
b7619582 GF |
15125 | case DW_OP_form_tls_address: |
15126 | return "DW_OP_form_tls_address"; | |
15127 | case DW_OP_call_frame_cfa: | |
15128 | return "DW_OP_call_frame_cfa"; | |
15129 | case DW_OP_bit_piece: | |
15130 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
15131 | /* DWARF 4 extensions. */ |
15132 | case DW_OP_implicit_value: | |
15133 | return "DW_OP_implicit_value"; | |
15134 | case DW_OP_stack_value: | |
15135 | return "DW_OP_stack_value"; | |
15136 | /* GNU extensions. */ | |
ed348acc EZ |
15137 | case DW_OP_GNU_push_tls_address: |
15138 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
15139 | case DW_OP_GNU_uninit: |
15140 | return "DW_OP_GNU_uninit"; | |
589b4a32 DE |
15141 | case DW_OP_GNU_encoded_addr: |
15142 | return "DW_OP_GNU_encoded_addr"; | |
8cf6f0b1 TT |
15143 | case DW_OP_GNU_implicit_pointer: |
15144 | return "DW_OP_GNU_implicit_pointer"; | |
8a9b8146 TT |
15145 | case DW_OP_GNU_entry_value: |
15146 | return "DW_OP_GNU_entry_value"; | |
15147 | case DW_OP_GNU_const_type: | |
15148 | return "DW_OP_GNU_const_type"; | |
15149 | case DW_OP_GNU_regval_type: | |
15150 | return "DW_OP_GNU_regval_type"; | |
15151 | case DW_OP_GNU_deref_type: | |
15152 | return "DW_OP_GNU_deref_type"; | |
15153 | case DW_OP_GNU_convert: | |
15154 | return "DW_OP_GNU_convert"; | |
15155 | case DW_OP_GNU_reinterpret: | |
15156 | return "DW_OP_GNU_reinterpret"; | |
589b4a32 DE |
15157 | case DW_OP_GNU_parameter_ref: |
15158 | return "DW_OP_GNU_parameter_ref"; | |
c906108c | 15159 | default: |
b1bfef65 | 15160 | return NULL; |
c906108c SS |
15161 | } |
15162 | } | |
15163 | ||
15164 | static char * | |
fba45db2 | 15165 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
15166 | { |
15167 | if (mybool) | |
15168 | return "TRUE"; | |
15169 | else | |
15170 | return "FALSE"; | |
15171 | } | |
15172 | ||
15173 | /* Convert a DWARF type code into its string name. */ | |
15174 | ||
15175 | static char * | |
aa1ee363 | 15176 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
15177 | { |
15178 | switch (enc) | |
15179 | { | |
b7619582 GF |
15180 | case DW_ATE_void: |
15181 | return "DW_ATE_void"; | |
c906108c SS |
15182 | case DW_ATE_address: |
15183 | return "DW_ATE_address"; | |
15184 | case DW_ATE_boolean: | |
15185 | return "DW_ATE_boolean"; | |
15186 | case DW_ATE_complex_float: | |
15187 | return "DW_ATE_complex_float"; | |
15188 | case DW_ATE_float: | |
15189 | return "DW_ATE_float"; | |
15190 | case DW_ATE_signed: | |
15191 | return "DW_ATE_signed"; | |
15192 | case DW_ATE_signed_char: | |
15193 | return "DW_ATE_signed_char"; | |
15194 | case DW_ATE_unsigned: | |
15195 | return "DW_ATE_unsigned"; | |
15196 | case DW_ATE_unsigned_char: | |
15197 | return "DW_ATE_unsigned_char"; | |
b7619582 | 15198 | /* DWARF 3. */ |
d9fa45fe DC |
15199 | case DW_ATE_imaginary_float: |
15200 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
15201 | case DW_ATE_packed_decimal: |
15202 | return "DW_ATE_packed_decimal"; | |
15203 | case DW_ATE_numeric_string: | |
15204 | return "DW_ATE_numeric_string"; | |
15205 | case DW_ATE_edited: | |
15206 | return "DW_ATE_edited"; | |
15207 | case DW_ATE_signed_fixed: | |
15208 | return "DW_ATE_signed_fixed"; | |
15209 | case DW_ATE_unsigned_fixed: | |
15210 | return "DW_ATE_unsigned_fixed"; | |
15211 | case DW_ATE_decimal_float: | |
15212 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
15213 | /* DWARF 4. */ |
15214 | case DW_ATE_UTF: | |
15215 | return "DW_ATE_UTF"; | |
b7619582 GF |
15216 | /* HP extensions. */ |
15217 | case DW_ATE_HP_float80: | |
15218 | return "DW_ATE_HP_float80"; | |
15219 | case DW_ATE_HP_complex_float80: | |
15220 | return "DW_ATE_HP_complex_float80"; | |
15221 | case DW_ATE_HP_float128: | |
15222 | return "DW_ATE_HP_float128"; | |
15223 | case DW_ATE_HP_complex_float128: | |
15224 | return "DW_ATE_HP_complex_float128"; | |
15225 | case DW_ATE_HP_floathpintel: | |
15226 | return "DW_ATE_HP_floathpintel"; | |
15227 | case DW_ATE_HP_imaginary_float80: | |
15228 | return "DW_ATE_HP_imaginary_float80"; | |
15229 | case DW_ATE_HP_imaginary_float128: | |
15230 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
15231 | default: |
15232 | return "DW_ATE_<unknown>"; | |
15233 | } | |
15234 | } | |
15235 | ||
0963b4bd | 15236 | /* Convert a DWARF call frame info operation to its string name. */ |
c906108c SS |
15237 | |
15238 | #if 0 | |
15239 | static char * | |
aa1ee363 | 15240 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
15241 | { |
15242 | switch (cfi_opc) | |
15243 | { | |
15244 | case DW_CFA_advance_loc: | |
15245 | return "DW_CFA_advance_loc"; | |
15246 | case DW_CFA_offset: | |
15247 | return "DW_CFA_offset"; | |
15248 | case DW_CFA_restore: | |
15249 | return "DW_CFA_restore"; | |
15250 | case DW_CFA_nop: | |
15251 | return "DW_CFA_nop"; | |
15252 | case DW_CFA_set_loc: | |
15253 | return "DW_CFA_set_loc"; | |
15254 | case DW_CFA_advance_loc1: | |
15255 | return "DW_CFA_advance_loc1"; | |
15256 | case DW_CFA_advance_loc2: | |
15257 | return "DW_CFA_advance_loc2"; | |
15258 | case DW_CFA_advance_loc4: | |
15259 | return "DW_CFA_advance_loc4"; | |
15260 | case DW_CFA_offset_extended: | |
15261 | return "DW_CFA_offset_extended"; | |
15262 | case DW_CFA_restore_extended: | |
15263 | return "DW_CFA_restore_extended"; | |
15264 | case DW_CFA_undefined: | |
15265 | return "DW_CFA_undefined"; | |
15266 | case DW_CFA_same_value: | |
15267 | return "DW_CFA_same_value"; | |
15268 | case DW_CFA_register: | |
15269 | return "DW_CFA_register"; | |
15270 | case DW_CFA_remember_state: | |
15271 | return "DW_CFA_remember_state"; | |
15272 | case DW_CFA_restore_state: | |
15273 | return "DW_CFA_restore_state"; | |
15274 | case DW_CFA_def_cfa: | |
15275 | return "DW_CFA_def_cfa"; | |
15276 | case DW_CFA_def_cfa_register: | |
15277 | return "DW_CFA_def_cfa_register"; | |
15278 | case DW_CFA_def_cfa_offset: | |
15279 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 15280 | /* DWARF 3. */ |
985cb1a3 JM |
15281 | case DW_CFA_def_cfa_expression: |
15282 | return "DW_CFA_def_cfa_expression"; | |
15283 | case DW_CFA_expression: | |
15284 | return "DW_CFA_expression"; | |
15285 | case DW_CFA_offset_extended_sf: | |
15286 | return "DW_CFA_offset_extended_sf"; | |
15287 | case DW_CFA_def_cfa_sf: | |
15288 | return "DW_CFA_def_cfa_sf"; | |
15289 | case DW_CFA_def_cfa_offset_sf: | |
15290 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
15291 | case DW_CFA_val_offset: |
15292 | return "DW_CFA_val_offset"; | |
15293 | case DW_CFA_val_offset_sf: | |
15294 | return "DW_CFA_val_offset_sf"; | |
15295 | case DW_CFA_val_expression: | |
15296 | return "DW_CFA_val_expression"; | |
15297 | /* SGI/MIPS specific. */ | |
c906108c SS |
15298 | case DW_CFA_MIPS_advance_loc8: |
15299 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 15300 | /* GNU extensions. */ |
985cb1a3 JM |
15301 | case DW_CFA_GNU_window_save: |
15302 | return "DW_CFA_GNU_window_save"; | |
15303 | case DW_CFA_GNU_args_size: | |
15304 | return "DW_CFA_GNU_args_size"; | |
15305 | case DW_CFA_GNU_negative_offset_extended: | |
15306 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
15307 | default: |
15308 | return "DW_CFA_<unknown>"; | |
15309 | } | |
15310 | } | |
15311 | #endif | |
15312 | ||
f9aca02d | 15313 | static void |
d97bc12b | 15314 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
15315 | { |
15316 | unsigned int i; | |
15317 | ||
d97bc12b DE |
15318 | print_spaces (indent, f); |
15319 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
b64f50a1 | 15320 | dwarf_tag_name (die->tag), die->abbrev, die->offset.sect_off); |
d97bc12b DE |
15321 | |
15322 | if (die->parent != NULL) | |
15323 | { | |
15324 | print_spaces (indent, f); | |
15325 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
b64f50a1 | 15326 | die->parent->offset.sect_off); |
d97bc12b DE |
15327 | } |
15328 | ||
15329 | print_spaces (indent, f); | |
15330 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 15331 | dwarf_bool_name (die->child != NULL)); |
c906108c | 15332 | |
d97bc12b DE |
15333 | print_spaces (indent, f); |
15334 | fprintf_unfiltered (f, " attributes:\n"); | |
15335 | ||
c906108c SS |
15336 | for (i = 0; i < die->num_attrs; ++i) |
15337 | { | |
d97bc12b DE |
15338 | print_spaces (indent, f); |
15339 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
15340 | dwarf_attr_name (die->attrs[i].name), |
15341 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 15342 | |
c906108c SS |
15343 | switch (die->attrs[i].form) |
15344 | { | |
c906108c | 15345 | case DW_FORM_addr: |
3019eac3 | 15346 | case DW_FORM_GNU_addr_index: |
d97bc12b | 15347 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 15348 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
15349 | break; |
15350 | case DW_FORM_block2: | |
15351 | case DW_FORM_block4: | |
15352 | case DW_FORM_block: | |
15353 | case DW_FORM_block1: | |
3e43a32a MS |
15354 | fprintf_unfiltered (f, "block: size %d", |
15355 | DW_BLOCK (&die->attrs[i])->size); | |
c906108c | 15356 | break; |
2dc7f7b3 TT |
15357 | case DW_FORM_exprloc: |
15358 | fprintf_unfiltered (f, "expression: size %u", | |
15359 | DW_BLOCK (&die->attrs[i])->size); | |
15360 | break; | |
4568ecf9 DE |
15361 | case DW_FORM_ref_addr: |
15362 | fprintf_unfiltered (f, "ref address: "); | |
15363 | fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f); | |
15364 | break; | |
10b3939b DJ |
15365 | case DW_FORM_ref1: |
15366 | case DW_FORM_ref2: | |
15367 | case DW_FORM_ref4: | |
4568ecf9 DE |
15368 | case DW_FORM_ref8: |
15369 | case DW_FORM_ref_udata: | |
d97bc12b | 15370 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
4568ecf9 | 15371 | (long) (DW_UNSND (&die->attrs[i]))); |
10b3939b | 15372 | break; |
c906108c SS |
15373 | case DW_FORM_data1: |
15374 | case DW_FORM_data2: | |
15375 | case DW_FORM_data4: | |
ce5d95e1 | 15376 | case DW_FORM_data8: |
c906108c SS |
15377 | case DW_FORM_udata: |
15378 | case DW_FORM_sdata: | |
43bbcdc2 PH |
15379 | fprintf_unfiltered (f, "constant: %s", |
15380 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 15381 | break; |
2dc7f7b3 TT |
15382 | case DW_FORM_sec_offset: |
15383 | fprintf_unfiltered (f, "section offset: %s", | |
15384 | pulongest (DW_UNSND (&die->attrs[i]))); | |
15385 | break; | |
55f1336d | 15386 | case DW_FORM_ref_sig8: |
348e048f DE |
15387 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
15388 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
b64f50a1 | 15389 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset.sect_off); |
348e048f DE |
15390 | else |
15391 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
15392 | break; | |
c906108c | 15393 | case DW_FORM_string: |
4bdf3d34 | 15394 | case DW_FORM_strp: |
3019eac3 | 15395 | case DW_FORM_GNU_str_index: |
8285870a | 15396 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 15397 | DW_STRING (&die->attrs[i]) |
8285870a JK |
15398 | ? DW_STRING (&die->attrs[i]) : "", |
15399 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
15400 | break; |
15401 | case DW_FORM_flag: | |
15402 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 15403 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 15404 | else |
d97bc12b | 15405 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 15406 | break; |
2dc7f7b3 TT |
15407 | case DW_FORM_flag_present: |
15408 | fprintf_unfiltered (f, "flag: TRUE"); | |
15409 | break; | |
a8329558 | 15410 | case DW_FORM_indirect: |
0963b4bd MS |
15411 | /* The reader will have reduced the indirect form to |
15412 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
15413 | fprintf_unfiltered (f, |
15414 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 15415 | break; |
c906108c | 15416 | default: |
d97bc12b | 15417 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 15418 | die->attrs[i].form); |
d97bc12b | 15419 | break; |
c906108c | 15420 | } |
d97bc12b | 15421 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
15422 | } |
15423 | } | |
15424 | ||
f9aca02d | 15425 | static void |
d97bc12b | 15426 | dump_die_for_error (struct die_info *die) |
c906108c | 15427 | { |
d97bc12b DE |
15428 | dump_die_shallow (gdb_stderr, 0, die); |
15429 | } | |
15430 | ||
15431 | static void | |
15432 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
15433 | { | |
15434 | int indent = level * 4; | |
15435 | ||
15436 | gdb_assert (die != NULL); | |
15437 | ||
15438 | if (level >= max_level) | |
15439 | return; | |
15440 | ||
15441 | dump_die_shallow (f, indent, die); | |
15442 | ||
15443 | if (die->child != NULL) | |
c906108c | 15444 | { |
d97bc12b DE |
15445 | print_spaces (indent, f); |
15446 | fprintf_unfiltered (f, " Children:"); | |
15447 | if (level + 1 < max_level) | |
15448 | { | |
15449 | fprintf_unfiltered (f, "\n"); | |
15450 | dump_die_1 (f, level + 1, max_level, die->child); | |
15451 | } | |
15452 | else | |
15453 | { | |
3e43a32a MS |
15454 | fprintf_unfiltered (f, |
15455 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
15456 | } |
15457 | } | |
15458 | ||
15459 | if (die->sibling != NULL && level > 0) | |
15460 | { | |
15461 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
15462 | } |
15463 | } | |
15464 | ||
d97bc12b DE |
15465 | /* This is called from the pdie macro in gdbinit.in. |
15466 | It's not static so gcc will keep a copy callable from gdb. */ | |
15467 | ||
15468 | void | |
15469 | dump_die (struct die_info *die, int max_level) | |
15470 | { | |
15471 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
15472 | } | |
15473 | ||
f9aca02d | 15474 | static void |
51545339 | 15475 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 15476 | { |
51545339 | 15477 | void **slot; |
c906108c | 15478 | |
b64f50a1 JK |
15479 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset.sect_off, |
15480 | INSERT); | |
51545339 DJ |
15481 | |
15482 | *slot = die; | |
c906108c SS |
15483 | } |
15484 | ||
b64f50a1 JK |
15485 | /* DW_ADDR is always stored already as sect_offset; despite for the forms |
15486 | besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ | |
15487 | ||
93311388 DE |
15488 | static int |
15489 | is_ref_attr (struct attribute *attr) | |
c906108c | 15490 | { |
c906108c SS |
15491 | switch (attr->form) |
15492 | { | |
15493 | case DW_FORM_ref_addr: | |
c906108c SS |
15494 | case DW_FORM_ref1: |
15495 | case DW_FORM_ref2: | |
15496 | case DW_FORM_ref4: | |
613e1657 | 15497 | case DW_FORM_ref8: |
c906108c | 15498 | case DW_FORM_ref_udata: |
93311388 | 15499 | return 1; |
c906108c | 15500 | default: |
93311388 | 15501 | return 0; |
c906108c | 15502 | } |
93311388 DE |
15503 | } |
15504 | ||
b64f50a1 JK |
15505 | /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the |
15506 | required kind. */ | |
15507 | ||
15508 | static sect_offset | |
93311388 DE |
15509 | dwarf2_get_ref_die_offset (struct attribute *attr) |
15510 | { | |
4568ecf9 | 15511 | sect_offset retval = { DW_UNSND (attr) }; |
b64f50a1 | 15512 | |
93311388 | 15513 | if (is_ref_attr (attr)) |
b64f50a1 | 15514 | return retval; |
93311388 | 15515 | |
b64f50a1 | 15516 | retval.sect_off = 0; |
93311388 DE |
15517 | complaint (&symfile_complaints, |
15518 | _("unsupported die ref attribute form: '%s'"), | |
15519 | dwarf_form_name (attr->form)); | |
b64f50a1 | 15520 | return retval; |
c906108c SS |
15521 | } |
15522 | ||
43bbcdc2 PH |
15523 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
15524 | * the value held by the attribute is not constant. */ | |
a02abb62 | 15525 | |
43bbcdc2 | 15526 | static LONGEST |
a02abb62 JB |
15527 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
15528 | { | |
15529 | if (attr->form == DW_FORM_sdata) | |
15530 | return DW_SND (attr); | |
15531 | else if (attr->form == DW_FORM_udata | |
15532 | || attr->form == DW_FORM_data1 | |
15533 | || attr->form == DW_FORM_data2 | |
15534 | || attr->form == DW_FORM_data4 | |
15535 | || attr->form == DW_FORM_data8) | |
15536 | return DW_UNSND (attr); | |
15537 | else | |
15538 | { | |
3e43a32a MS |
15539 | complaint (&symfile_complaints, |
15540 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
15541 | dwarf_form_name (attr->form)); |
15542 | return default_value; | |
15543 | } | |
15544 | } | |
15545 | ||
03dd20cc | 15546 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
15547 | unit and add it to our queue. |
15548 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
15549 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 15550 | |
348e048f | 15551 | static int |
03dd20cc DJ |
15552 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
15553 | struct dwarf2_per_cu_data *per_cu) | |
15554 | { | |
98bfdba5 PA |
15555 | /* We may arrive here during partial symbol reading, if we need full |
15556 | DIEs to process an unusual case (e.g. template arguments). Do | |
15557 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
15558 | if (dwarf2_per_objfile->reading_partial_symbols) | |
15559 | { | |
15560 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
15561 | return 1; | |
15562 | return 0; | |
15563 | } | |
15564 | ||
03dd20cc DJ |
15565 | /* Mark the dependence relation so that we don't flush PER_CU |
15566 | too early. */ | |
15567 | dwarf2_add_dependence (this_cu, per_cu); | |
15568 | ||
15569 | /* If it's already on the queue, we have nothing to do. */ | |
15570 | if (per_cu->queued) | |
348e048f | 15571 | return 0; |
03dd20cc DJ |
15572 | |
15573 | /* If the compilation unit is already loaded, just mark it as | |
15574 | used. */ | |
15575 | if (per_cu->cu != NULL) | |
15576 | { | |
15577 | per_cu->cu->last_used = 0; | |
348e048f | 15578 | return 0; |
03dd20cc DJ |
15579 | } |
15580 | ||
15581 | /* Add it to the queue. */ | |
a0f42c21 | 15582 | queue_comp_unit (per_cu); |
348e048f DE |
15583 | |
15584 | return 1; | |
15585 | } | |
15586 | ||
15587 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
15588 | On entry *REF_CU is the CU of SRC_DIE. | |
15589 | On exit *REF_CU is the CU of the result. */ | |
15590 | ||
15591 | static struct die_info * | |
15592 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
15593 | struct dwarf2_cu **ref_cu) | |
15594 | { | |
15595 | struct die_info *die; | |
15596 | ||
15597 | if (is_ref_attr (attr)) | |
15598 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 15599 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
15600 | die = follow_die_sig (src_die, attr, ref_cu); |
15601 | else | |
15602 | { | |
15603 | dump_die_for_error (src_die); | |
15604 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
15605 | (*ref_cu)->objfile->name); | |
15606 | } | |
15607 | ||
15608 | return die; | |
03dd20cc DJ |
15609 | } |
15610 | ||
5c631832 | 15611 | /* Follow reference OFFSET. |
673bfd45 DE |
15612 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
15613 | On exit *REF_CU is the CU of the result. | |
15614 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 15615 | |
f9aca02d | 15616 | static struct die_info * |
b64f50a1 | 15617 | follow_die_offset (sect_offset offset, struct dwarf2_cu **ref_cu) |
c906108c | 15618 | { |
10b3939b | 15619 | struct die_info temp_die; |
f2f0e013 | 15620 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 15621 | |
348e048f DE |
15622 | gdb_assert (cu->per_cu != NULL); |
15623 | ||
98bfdba5 PA |
15624 | target_cu = cu; |
15625 | ||
3019eac3 | 15626 | if (cu->per_cu->is_debug_types) |
348e048f DE |
15627 | { |
15628 | /* .debug_types CUs cannot reference anything outside their CU. | |
15629 | If they need to, they have to reference a signatured type via | |
55f1336d | 15630 | DW_FORM_ref_sig8. */ |
348e048f | 15631 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 15632 | return NULL; |
348e048f DE |
15633 | } |
15634 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
15635 | { |
15636 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 15637 | |
45452591 | 15638 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
15639 | |
15640 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f | 15641 | if (maybe_queue_comp_unit (cu, per_cu)) |
a0f42c21 | 15642 | load_full_comp_unit (per_cu); |
03dd20cc | 15643 | |
10b3939b DJ |
15644 | target_cu = per_cu->cu; |
15645 | } | |
98bfdba5 PA |
15646 | else if (cu->dies == NULL) |
15647 | { | |
15648 | /* We're loading full DIEs during partial symbol reading. */ | |
15649 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
a0f42c21 | 15650 | load_full_comp_unit (cu->per_cu); |
98bfdba5 | 15651 | } |
c906108c | 15652 | |
f2f0e013 | 15653 | *ref_cu = target_cu; |
51545339 | 15654 | temp_die.offset = offset; |
b64f50a1 | 15655 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset.sect_off); |
5c631832 | 15656 | } |
10b3939b | 15657 | |
5c631832 JK |
15658 | /* Follow reference attribute ATTR of SRC_DIE. |
15659 | On entry *REF_CU is the CU of SRC_DIE. | |
15660 | On exit *REF_CU is the CU of the result. */ | |
15661 | ||
15662 | static struct die_info * | |
15663 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
15664 | struct dwarf2_cu **ref_cu) | |
15665 | { | |
b64f50a1 | 15666 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
5c631832 JK |
15667 | struct dwarf2_cu *cu = *ref_cu; |
15668 | struct die_info *die; | |
15669 | ||
15670 | die = follow_die_offset (offset, ref_cu); | |
15671 | if (!die) | |
15672 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
15673 | "at 0x%x [in module %s]"), | |
b64f50a1 | 15674 | offset.sect_off, src_die->offset.sect_off, cu->objfile->name); |
348e048f | 15675 | |
5c631832 JK |
15676 | return die; |
15677 | } | |
15678 | ||
d83e736b JK |
15679 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
15680 | Returned value is intended for DW_OP_call*. Returned | |
15681 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ | |
5c631832 JK |
15682 | |
15683 | struct dwarf2_locexpr_baton | |
b64f50a1 | 15684 | dwarf2_fetch_die_location_block (cu_offset offset_in_cu, |
8cf6f0b1 TT |
15685 | struct dwarf2_per_cu_data *per_cu, |
15686 | CORE_ADDR (*get_frame_pc) (void *baton), | |
15687 | void *baton) | |
5c631832 | 15688 | { |
b64f50a1 | 15689 | sect_offset offset = { per_cu->offset.sect_off + offset_in_cu.cu_off }; |
918dd910 | 15690 | struct dwarf2_cu *cu; |
5c631832 JK |
15691 | struct die_info *die; |
15692 | struct attribute *attr; | |
15693 | struct dwarf2_locexpr_baton retval; | |
15694 | ||
8cf6f0b1 TT |
15695 | dw2_setup (per_cu->objfile); |
15696 | ||
918dd910 JK |
15697 | if (per_cu->cu == NULL) |
15698 | load_cu (per_cu); | |
15699 | cu = per_cu->cu; | |
15700 | ||
5c631832 JK |
15701 | die = follow_die_offset (offset, &cu); |
15702 | if (!die) | |
15703 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
b64f50a1 | 15704 | offset.sect_off, per_cu->objfile->name); |
5c631832 JK |
15705 | |
15706 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
15707 | if (!attr) | |
15708 | { | |
e103e986 JK |
15709 | /* DWARF: "If there is no such attribute, then there is no effect.". |
15710 | DATA is ignored if SIZE is 0. */ | |
5c631832 | 15711 | |
e103e986 | 15712 | retval.data = NULL; |
5c631832 JK |
15713 | retval.size = 0; |
15714 | } | |
8cf6f0b1 TT |
15715 | else if (attr_form_is_section_offset (attr)) |
15716 | { | |
15717 | struct dwarf2_loclist_baton loclist_baton; | |
15718 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
15719 | size_t size; | |
15720 | ||
15721 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
15722 | ||
15723 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
15724 | &size, pc); | |
15725 | retval.size = size; | |
15726 | } | |
5c631832 JK |
15727 | else |
15728 | { | |
15729 | if (!attr_form_is_block (attr)) | |
15730 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
15731 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
b64f50a1 | 15732 | offset.sect_off, per_cu->objfile->name); |
5c631832 JK |
15733 | |
15734 | retval.data = DW_BLOCK (attr)->data; | |
15735 | retval.size = DW_BLOCK (attr)->size; | |
15736 | } | |
15737 | retval.per_cu = cu->per_cu; | |
918dd910 | 15738 | |
918dd910 JK |
15739 | age_cached_comp_units (); |
15740 | ||
5c631832 | 15741 | return retval; |
348e048f DE |
15742 | } |
15743 | ||
8a9b8146 TT |
15744 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
15745 | PER_CU. */ | |
15746 | ||
15747 | struct type * | |
b64f50a1 | 15748 | dwarf2_get_die_type (cu_offset die_offset, |
8a9b8146 TT |
15749 | struct dwarf2_per_cu_data *per_cu) |
15750 | { | |
b64f50a1 JK |
15751 | sect_offset die_offset_sect; |
15752 | ||
8a9b8146 | 15753 | dw2_setup (per_cu->objfile); |
b64f50a1 JK |
15754 | |
15755 | die_offset_sect.sect_off = per_cu->offset.sect_off + die_offset.cu_off; | |
15756 | return get_die_type_at_offset (die_offset_sect, per_cu); | |
8a9b8146 TT |
15757 | } |
15758 | ||
348e048f DE |
15759 | /* Follow the signature attribute ATTR in SRC_DIE. |
15760 | On entry *REF_CU is the CU of SRC_DIE. | |
15761 | On exit *REF_CU is the CU of the result. */ | |
15762 | ||
15763 | static struct die_info * | |
15764 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
15765 | struct dwarf2_cu **ref_cu) | |
15766 | { | |
15767 | struct objfile *objfile = (*ref_cu)->objfile; | |
15768 | struct die_info temp_die; | |
15769 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
15770 | struct dwarf2_cu *sig_cu; | |
15771 | struct die_info *die; | |
15772 | ||
15773 | /* sig_type will be NULL if the signatured type is missing from | |
15774 | the debug info. */ | |
15775 | if (sig_type == NULL) | |
15776 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
15777 | "at 0x%x [in module %s]"), | |
b64f50a1 | 15778 | src_die->offset.sect_off, objfile->name); |
348e048f DE |
15779 | |
15780 | /* If necessary, add it to the queue and load its DIEs. */ | |
15781 | ||
15782 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
a0f42c21 | 15783 | read_signatured_type (sig_type); |
348e048f DE |
15784 | |
15785 | gdb_assert (sig_type->per_cu.cu != NULL); | |
15786 | ||
15787 | sig_cu = sig_type->per_cu.cu; | |
3019eac3 DE |
15788 | gdb_assert (sig_type->type_offset_in_section.sect_off != 0); |
15789 | temp_die.offset = sig_type->type_offset_in_section; | |
b64f50a1 JK |
15790 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, |
15791 | temp_die.offset.sect_off); | |
348e048f DE |
15792 | if (die) |
15793 | { | |
15794 | *ref_cu = sig_cu; | |
15795 | return die; | |
15796 | } | |
15797 | ||
3e43a32a MS |
15798 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
15799 | "from DIE at 0x%x [in module %s]"), | |
b64f50a1 | 15800 | temp_die.offset.sect_off, src_die->offset.sect_off, objfile->name); |
348e048f DE |
15801 | } |
15802 | ||
15803 | /* Given an offset of a signatured type, return its signatured_type. */ | |
15804 | ||
15805 | static struct signatured_type * | |
8b70b953 TT |
15806 | lookup_signatured_type_at_offset (struct objfile *objfile, |
15807 | struct dwarf2_section_info *section, | |
b64f50a1 | 15808 | sect_offset offset) |
348e048f | 15809 | { |
b64f50a1 | 15810 | gdb_byte *info_ptr = section->buffer + offset.sect_off; |
348e048f DE |
15811 | unsigned int length, initial_length_size; |
15812 | unsigned int sig_offset; | |
52dc124a | 15813 | struct signatured_type find_entry, *sig_type; |
348e048f DE |
15814 | |
15815 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
15816 | sig_offset = (initial_length_size | |
15817 | + 2 /*version*/ | |
15818 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
15819 | + 1 /*address_size*/); | |
15820 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
52dc124a | 15821 | sig_type = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
348e048f DE |
15822 | |
15823 | /* This is only used to lookup previously recorded types. | |
15824 | If we didn't find it, it's our bug. */ | |
52dc124a DE |
15825 | gdb_assert (sig_type != NULL); |
15826 | gdb_assert (offset.sect_off == sig_type->per_cu.offset.sect_off); | |
348e048f | 15827 | |
52dc124a | 15828 | return sig_type; |
348e048f DE |
15829 | } |
15830 | ||
e5fe5e75 | 15831 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
348e048f DE |
15832 | |
15833 | static void | |
e5fe5e75 | 15834 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
348e048f | 15835 | { |
e5fe5e75 | 15836 | struct objfile *objfile = per_cu->objfile; |
3019eac3 | 15837 | struct dwarf2_section_info *sect = per_cu->info_or_types_section; |
b64f50a1 | 15838 | sect_offset offset = per_cu->offset; |
52dc124a | 15839 | struct signatured_type *sig_type; |
348e048f | 15840 | |
8b70b953 | 15841 | dwarf2_read_section (objfile, sect); |
be391dca | 15842 | |
348e048f | 15843 | /* We have the section offset, but we need the signature to do the |
e5fe5e75 DE |
15844 | hash table lookup. */ |
15845 | /* FIXME: This is sorta unnecessary, read_signatured_type only uses | |
15846 | the signature to assert we found the right one. | |
15847 | Ok, but it's a lot of work. We should simplify things so any needed | |
15848 | assert doesn't require all this clumsiness. */ | |
52dc124a | 15849 | sig_type = lookup_signatured_type_at_offset (objfile, sect, offset); |
348e048f | 15850 | |
dee91e82 | 15851 | gdb_assert (&sig_type->per_cu == per_cu); |
52dc124a | 15852 | gdb_assert (sig_type->per_cu.cu == NULL); |
348e048f | 15853 | |
52dc124a | 15854 | read_signatured_type (sig_type); |
348e048f | 15855 | |
52dc124a | 15856 | gdb_assert (sig_type->per_cu.cu != NULL); |
348e048f DE |
15857 | } |
15858 | ||
dee91e82 DE |
15859 | /* die_reader_func for read_signatured_type. |
15860 | This is identical to load_full_comp_unit_reader, | |
15861 | but is kept separate for now. */ | |
348e048f DE |
15862 | |
15863 | static void | |
dee91e82 DE |
15864 | read_signatured_type_reader (const struct die_reader_specs *reader, |
15865 | gdb_byte *info_ptr, | |
15866 | struct die_info *comp_unit_die, | |
15867 | int has_children, | |
15868 | void *data) | |
348e048f | 15869 | { |
dee91e82 DE |
15870 | struct dwarf2_cu *cu = reader->cu; |
15871 | struct attribute *attr; | |
348e048f | 15872 | |
dee91e82 DE |
15873 | gdb_assert (cu->die_hash == NULL); |
15874 | cu->die_hash = | |
15875 | htab_create_alloc_ex (cu->header.length / 12, | |
15876 | die_hash, | |
15877 | die_eq, | |
15878 | NULL, | |
15879 | &cu->comp_unit_obstack, | |
15880 | hashtab_obstack_allocate, | |
15881 | dummy_obstack_deallocate); | |
348e048f | 15882 | |
dee91e82 DE |
15883 | if (has_children) |
15884 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
15885 | &info_ptr, comp_unit_die); | |
15886 | cu->dies = comp_unit_die; | |
15887 | /* comp_unit_die is not stored in die_hash, no need. */ | |
348e048f DE |
15888 | |
15889 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 15890 | all CUs needed for references have been loaded yet, and symbol |
348e048f | 15891 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
15892 | or we won't be able to build types correctly. |
15893 | Similarly, if we do not read the producer, we can not apply | |
15894 | producer-specific interpretation. */ | |
9816fde3 | 15895 | prepare_one_comp_unit (cu, cu->dies); |
dee91e82 | 15896 | } |
348e048f | 15897 | |
3019eac3 DE |
15898 | /* Read in a signatured type and build its CU and DIEs. |
15899 | If the type is a stub for the real type in a DWO file, | |
15900 | read in the real type from the DWO file as well. */ | |
dee91e82 DE |
15901 | |
15902 | static void | |
15903 | read_signatured_type (struct signatured_type *sig_type) | |
15904 | { | |
15905 | struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu; | |
348e048f | 15906 | |
3019eac3 | 15907 | gdb_assert (per_cu->is_debug_types); |
dee91e82 | 15908 | gdb_assert (per_cu->cu == NULL); |
348e048f | 15909 | |
dee91e82 | 15910 | init_tu_and_read_dies (per_cu, 1, read_signatured_type_reader, NULL); |
c906108c SS |
15911 | } |
15912 | ||
c906108c SS |
15913 | /* Decode simple location descriptions. |
15914 | Given a pointer to a dwarf block that defines a location, compute | |
15915 | the location and return the value. | |
15916 | ||
4cecd739 DJ |
15917 | NOTE drow/2003-11-18: This function is called in two situations |
15918 | now: for the address of static or global variables (partial symbols | |
15919 | only) and for offsets into structures which are expected to be | |
15920 | (more or less) constant. The partial symbol case should go away, | |
15921 | and only the constant case should remain. That will let this | |
15922 | function complain more accurately. A few special modes are allowed | |
15923 | without complaint for global variables (for instance, global | |
15924 | register values and thread-local values). | |
c906108c SS |
15925 | |
15926 | A location description containing no operations indicates that the | |
4cecd739 | 15927 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
15928 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
15929 | callers will only want a very basic result and this can become a | |
21ae7a4d JK |
15930 | complaint. |
15931 | ||
15932 | Note that stack[0] is unused except as a default error return. */ | |
c906108c SS |
15933 | |
15934 | static CORE_ADDR | |
e7c27a73 | 15935 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 15936 | { |
e7c27a73 | 15937 | struct objfile *objfile = cu->objfile; |
21ae7a4d JK |
15938 | int i; |
15939 | int size = blk->size; | |
15940 | gdb_byte *data = blk->data; | |
15941 | CORE_ADDR stack[64]; | |
15942 | int stacki; | |
15943 | unsigned int bytes_read, unsnd; | |
15944 | gdb_byte op; | |
c906108c | 15945 | |
21ae7a4d JK |
15946 | i = 0; |
15947 | stacki = 0; | |
15948 | stack[stacki] = 0; | |
15949 | stack[++stacki] = 0; | |
15950 | ||
15951 | while (i < size) | |
15952 | { | |
15953 | op = data[i++]; | |
15954 | switch (op) | |
15955 | { | |
15956 | case DW_OP_lit0: | |
15957 | case DW_OP_lit1: | |
15958 | case DW_OP_lit2: | |
15959 | case DW_OP_lit3: | |
15960 | case DW_OP_lit4: | |
15961 | case DW_OP_lit5: | |
15962 | case DW_OP_lit6: | |
15963 | case DW_OP_lit7: | |
15964 | case DW_OP_lit8: | |
15965 | case DW_OP_lit9: | |
15966 | case DW_OP_lit10: | |
15967 | case DW_OP_lit11: | |
15968 | case DW_OP_lit12: | |
15969 | case DW_OP_lit13: | |
15970 | case DW_OP_lit14: | |
15971 | case DW_OP_lit15: | |
15972 | case DW_OP_lit16: | |
15973 | case DW_OP_lit17: | |
15974 | case DW_OP_lit18: | |
15975 | case DW_OP_lit19: | |
15976 | case DW_OP_lit20: | |
15977 | case DW_OP_lit21: | |
15978 | case DW_OP_lit22: | |
15979 | case DW_OP_lit23: | |
15980 | case DW_OP_lit24: | |
15981 | case DW_OP_lit25: | |
15982 | case DW_OP_lit26: | |
15983 | case DW_OP_lit27: | |
15984 | case DW_OP_lit28: | |
15985 | case DW_OP_lit29: | |
15986 | case DW_OP_lit30: | |
15987 | case DW_OP_lit31: | |
15988 | stack[++stacki] = op - DW_OP_lit0; | |
15989 | break; | |
f1bea926 | 15990 | |
21ae7a4d JK |
15991 | case DW_OP_reg0: |
15992 | case DW_OP_reg1: | |
15993 | case DW_OP_reg2: | |
15994 | case DW_OP_reg3: | |
15995 | case DW_OP_reg4: | |
15996 | case DW_OP_reg5: | |
15997 | case DW_OP_reg6: | |
15998 | case DW_OP_reg7: | |
15999 | case DW_OP_reg8: | |
16000 | case DW_OP_reg9: | |
16001 | case DW_OP_reg10: | |
16002 | case DW_OP_reg11: | |
16003 | case DW_OP_reg12: | |
16004 | case DW_OP_reg13: | |
16005 | case DW_OP_reg14: | |
16006 | case DW_OP_reg15: | |
16007 | case DW_OP_reg16: | |
16008 | case DW_OP_reg17: | |
16009 | case DW_OP_reg18: | |
16010 | case DW_OP_reg19: | |
16011 | case DW_OP_reg20: | |
16012 | case DW_OP_reg21: | |
16013 | case DW_OP_reg22: | |
16014 | case DW_OP_reg23: | |
16015 | case DW_OP_reg24: | |
16016 | case DW_OP_reg25: | |
16017 | case DW_OP_reg26: | |
16018 | case DW_OP_reg27: | |
16019 | case DW_OP_reg28: | |
16020 | case DW_OP_reg29: | |
16021 | case DW_OP_reg30: | |
16022 | case DW_OP_reg31: | |
16023 | stack[++stacki] = op - DW_OP_reg0; | |
16024 | if (i < size) | |
16025 | dwarf2_complex_location_expr_complaint (); | |
16026 | break; | |
c906108c | 16027 | |
21ae7a4d JK |
16028 | case DW_OP_regx: |
16029 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
16030 | i += bytes_read; | |
16031 | stack[++stacki] = unsnd; | |
16032 | if (i < size) | |
16033 | dwarf2_complex_location_expr_complaint (); | |
16034 | break; | |
c906108c | 16035 | |
21ae7a4d JK |
16036 | case DW_OP_addr: |
16037 | stack[++stacki] = read_address (objfile->obfd, &data[i], | |
16038 | cu, &bytes_read); | |
16039 | i += bytes_read; | |
16040 | break; | |
d53d4ac5 | 16041 | |
21ae7a4d JK |
16042 | case DW_OP_const1u: |
16043 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
16044 | i += 1; | |
16045 | break; | |
16046 | ||
16047 | case DW_OP_const1s: | |
16048 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
16049 | i += 1; | |
16050 | break; | |
16051 | ||
16052 | case DW_OP_const2u: | |
16053 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
16054 | i += 2; | |
16055 | break; | |
16056 | ||
16057 | case DW_OP_const2s: | |
16058 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
16059 | i += 2; | |
16060 | break; | |
d53d4ac5 | 16061 | |
21ae7a4d JK |
16062 | case DW_OP_const4u: |
16063 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
16064 | i += 4; | |
16065 | break; | |
16066 | ||
16067 | case DW_OP_const4s: | |
16068 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
16069 | i += 4; | |
16070 | break; | |
16071 | ||
585861ea JK |
16072 | case DW_OP_const8u: |
16073 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); | |
16074 | i += 8; | |
16075 | break; | |
16076 | ||
21ae7a4d JK |
16077 | case DW_OP_constu: |
16078 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
16079 | &bytes_read); | |
16080 | i += bytes_read; | |
16081 | break; | |
16082 | ||
16083 | case DW_OP_consts: | |
16084 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
16085 | i += bytes_read; | |
16086 | break; | |
16087 | ||
16088 | case DW_OP_dup: | |
16089 | stack[stacki + 1] = stack[stacki]; | |
16090 | stacki++; | |
16091 | break; | |
16092 | ||
16093 | case DW_OP_plus: | |
16094 | stack[stacki - 1] += stack[stacki]; | |
16095 | stacki--; | |
16096 | break; | |
16097 | ||
16098 | case DW_OP_plus_uconst: | |
16099 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), | |
16100 | &bytes_read); | |
16101 | i += bytes_read; | |
16102 | break; | |
16103 | ||
16104 | case DW_OP_minus: | |
16105 | stack[stacki - 1] -= stack[stacki]; | |
16106 | stacki--; | |
16107 | break; | |
16108 | ||
16109 | case DW_OP_deref: | |
16110 | /* If we're not the last op, then we definitely can't encode | |
16111 | this using GDB's address_class enum. This is valid for partial | |
16112 | global symbols, although the variable's address will be bogus | |
16113 | in the psymtab. */ | |
16114 | if (i < size) | |
16115 | dwarf2_complex_location_expr_complaint (); | |
16116 | break; | |
16117 | ||
16118 | case DW_OP_GNU_push_tls_address: | |
16119 | /* The top of the stack has the offset from the beginning | |
16120 | of the thread control block at which the variable is located. */ | |
16121 | /* Nothing should follow this operator, so the top of stack would | |
16122 | be returned. */ | |
16123 | /* This is valid for partial global symbols, but the variable's | |
585861ea JK |
16124 | address will be bogus in the psymtab. Make it always at least |
16125 | non-zero to not look as a variable garbage collected by linker | |
16126 | which have DW_OP_addr 0. */ | |
21ae7a4d JK |
16127 | if (i < size) |
16128 | dwarf2_complex_location_expr_complaint (); | |
585861ea | 16129 | stack[stacki]++; |
21ae7a4d JK |
16130 | break; |
16131 | ||
16132 | case DW_OP_GNU_uninit: | |
16133 | break; | |
16134 | ||
3019eac3 DE |
16135 | case DW_OP_GNU_addr_index: |
16136 | stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i], | |
16137 | &bytes_read); | |
16138 | i += bytes_read; | |
16139 | break; | |
16140 | ||
21ae7a4d JK |
16141 | default: |
16142 | { | |
16143 | const char *name = dwarf_stack_op_name (op); | |
16144 | ||
16145 | if (name) | |
16146 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
16147 | name); | |
16148 | else | |
16149 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
16150 | op); | |
16151 | } | |
16152 | ||
16153 | return (stack[stacki]); | |
d53d4ac5 | 16154 | } |
3c6e0cb3 | 16155 | |
21ae7a4d JK |
16156 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
16157 | outside of the allocated space. Also enforce minimum>0. */ | |
16158 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
16159 | { | |
16160 | complaint (&symfile_complaints, | |
16161 | _("location description stack overflow")); | |
16162 | return 0; | |
16163 | } | |
16164 | ||
16165 | if (stacki <= 0) | |
16166 | { | |
16167 | complaint (&symfile_complaints, | |
16168 | _("location description stack underflow")); | |
16169 | return 0; | |
16170 | } | |
16171 | } | |
16172 | return (stack[stacki]); | |
c906108c SS |
16173 | } |
16174 | ||
16175 | /* memory allocation interface */ | |
16176 | ||
c906108c | 16177 | static struct dwarf_block * |
7b5a2f43 | 16178 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
16179 | { |
16180 | struct dwarf_block *blk; | |
16181 | ||
16182 | blk = (struct dwarf_block *) | |
7b5a2f43 | 16183 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
16184 | return (blk); |
16185 | } | |
16186 | ||
16187 | static struct abbrev_info * | |
f3dd6933 | 16188 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
16189 | { |
16190 | struct abbrev_info *abbrev; | |
16191 | ||
f3dd6933 DJ |
16192 | abbrev = (struct abbrev_info *) |
16193 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
16194 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
16195 | return (abbrev); | |
16196 | } | |
16197 | ||
16198 | static struct die_info * | |
b60c80d6 | 16199 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
16200 | { |
16201 | struct die_info *die; | |
b60c80d6 DJ |
16202 | size_t size = sizeof (struct die_info); |
16203 | ||
16204 | if (num_attrs > 1) | |
16205 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 16206 | |
b60c80d6 | 16207 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
16208 | memset (die, 0, sizeof (struct die_info)); |
16209 | return (die); | |
16210 | } | |
2e276125 JB |
16211 | |
16212 | \f | |
16213 | /* Macro support. */ | |
16214 | ||
2e276125 JB |
16215 | /* Return the full name of file number I in *LH's file name table. |
16216 | Use COMP_DIR as the name of the current directory of the | |
16217 | compilation. The result is allocated using xmalloc; the caller is | |
16218 | responsible for freeing it. */ | |
16219 | static char * | |
16220 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
16221 | { | |
6a83a1e6 EZ |
16222 | /* Is the file number a valid index into the line header's file name |
16223 | table? Remember that file numbers start with one, not zero. */ | |
16224 | if (1 <= file && file <= lh->num_file_names) | |
16225 | { | |
16226 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 16227 | |
6a83a1e6 EZ |
16228 | if (IS_ABSOLUTE_PATH (fe->name)) |
16229 | return xstrdup (fe->name); | |
16230 | else | |
16231 | { | |
16232 | const char *dir; | |
16233 | int dir_len; | |
16234 | char *full_name; | |
16235 | ||
16236 | if (fe->dir_index) | |
16237 | dir = lh->include_dirs[fe->dir_index - 1]; | |
16238 | else | |
16239 | dir = comp_dir; | |
16240 | ||
16241 | if (dir) | |
16242 | { | |
16243 | dir_len = strlen (dir); | |
16244 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
16245 | strcpy (full_name, dir); | |
16246 | full_name[dir_len] = '/'; | |
16247 | strcpy (full_name + dir_len + 1, fe->name); | |
16248 | return full_name; | |
16249 | } | |
16250 | else | |
16251 | return xstrdup (fe->name); | |
16252 | } | |
16253 | } | |
2e276125 JB |
16254 | else |
16255 | { | |
6a83a1e6 EZ |
16256 | /* The compiler produced a bogus file number. We can at least |
16257 | record the macro definitions made in the file, even if we | |
16258 | won't be able to find the file by name. */ | |
16259 | char fake_name[80]; | |
9a619af0 | 16260 | |
6a83a1e6 | 16261 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 16262 | |
6e70227d | 16263 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
16264 | _("bad file number in macro information (%d)"), |
16265 | file); | |
2e276125 | 16266 | |
6a83a1e6 | 16267 | return xstrdup (fake_name); |
2e276125 JB |
16268 | } |
16269 | } | |
16270 | ||
16271 | ||
16272 | static struct macro_source_file * | |
16273 | macro_start_file (int file, int line, | |
16274 | struct macro_source_file *current_file, | |
16275 | const char *comp_dir, | |
16276 | struct line_header *lh, struct objfile *objfile) | |
16277 | { | |
16278 | /* The full name of this source file. */ | |
16279 | char *full_name = file_full_name (file, lh, comp_dir); | |
16280 | ||
16281 | /* We don't create a macro table for this compilation unit | |
16282 | at all until we actually get a filename. */ | |
16283 | if (! pending_macros) | |
4a146b47 | 16284 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 16285 | objfile->macro_cache); |
2e276125 JB |
16286 | |
16287 | if (! current_file) | |
16288 | /* If we have no current file, then this must be the start_file | |
16289 | directive for the compilation unit's main source file. */ | |
16290 | current_file = macro_set_main (pending_macros, full_name); | |
16291 | else | |
16292 | current_file = macro_include (current_file, line, full_name); | |
16293 | ||
16294 | xfree (full_name); | |
6e70227d | 16295 | |
2e276125 JB |
16296 | return current_file; |
16297 | } | |
16298 | ||
16299 | ||
16300 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
16301 | followed by a null byte. */ | |
16302 | static char * | |
16303 | copy_string (const char *buf, int len) | |
16304 | { | |
16305 | char *s = xmalloc (len + 1); | |
9a619af0 | 16306 | |
2e276125 JB |
16307 | memcpy (s, buf, len); |
16308 | s[len] = '\0'; | |
2e276125 JB |
16309 | return s; |
16310 | } | |
16311 | ||
16312 | ||
16313 | static const char * | |
16314 | consume_improper_spaces (const char *p, const char *body) | |
16315 | { | |
16316 | if (*p == ' ') | |
16317 | { | |
4d3c2250 | 16318 | complaint (&symfile_complaints, |
3e43a32a MS |
16319 | _("macro definition contains spaces " |
16320 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 16321 | body); |
2e276125 JB |
16322 | |
16323 | while (*p == ' ') | |
16324 | p++; | |
16325 | } | |
16326 | ||
16327 | return p; | |
16328 | } | |
16329 | ||
16330 | ||
16331 | static void | |
16332 | parse_macro_definition (struct macro_source_file *file, int line, | |
16333 | const char *body) | |
16334 | { | |
16335 | const char *p; | |
16336 | ||
16337 | /* The body string takes one of two forms. For object-like macro | |
16338 | definitions, it should be: | |
16339 | ||
16340 | <macro name> " " <definition> | |
16341 | ||
16342 | For function-like macro definitions, it should be: | |
16343 | ||
16344 | <macro name> "() " <definition> | |
16345 | or | |
16346 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
16347 | ||
16348 | Spaces may appear only where explicitly indicated, and in the | |
16349 | <definition>. | |
16350 | ||
16351 | The Dwarf 2 spec says that an object-like macro's name is always | |
16352 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 16353 | the space when the macro's definition is the empty string. |
2e276125 JB |
16354 | |
16355 | The Dwarf 2 spec says that there should be no spaces between the | |
16356 | formal arguments in a function-like macro's formal argument list, | |
16357 | but versions of GCC around March 2002 include spaces after the | |
16358 | commas. */ | |
16359 | ||
16360 | ||
16361 | /* Find the extent of the macro name. The macro name is terminated | |
16362 | by either a space or null character (for an object-like macro) or | |
16363 | an opening paren (for a function-like macro). */ | |
16364 | for (p = body; *p; p++) | |
16365 | if (*p == ' ' || *p == '(') | |
16366 | break; | |
16367 | ||
16368 | if (*p == ' ' || *p == '\0') | |
16369 | { | |
16370 | /* It's an object-like macro. */ | |
16371 | int name_len = p - body; | |
16372 | char *name = copy_string (body, name_len); | |
16373 | const char *replacement; | |
16374 | ||
16375 | if (*p == ' ') | |
16376 | replacement = body + name_len + 1; | |
16377 | else | |
16378 | { | |
4d3c2250 | 16379 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
16380 | replacement = body + name_len; |
16381 | } | |
6e70227d | 16382 | |
2e276125 JB |
16383 | macro_define_object (file, line, name, replacement); |
16384 | ||
16385 | xfree (name); | |
16386 | } | |
16387 | else if (*p == '(') | |
16388 | { | |
16389 | /* It's a function-like macro. */ | |
16390 | char *name = copy_string (body, p - body); | |
16391 | int argc = 0; | |
16392 | int argv_size = 1; | |
16393 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
16394 | ||
16395 | p++; | |
16396 | ||
16397 | p = consume_improper_spaces (p, body); | |
16398 | ||
16399 | /* Parse the formal argument list. */ | |
16400 | while (*p && *p != ')') | |
16401 | { | |
16402 | /* Find the extent of the current argument name. */ | |
16403 | const char *arg_start = p; | |
16404 | ||
16405 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
16406 | p++; | |
16407 | ||
16408 | if (! *p || p == arg_start) | |
4d3c2250 | 16409 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
16410 | else |
16411 | { | |
16412 | /* Make sure argv has room for the new argument. */ | |
16413 | if (argc >= argv_size) | |
16414 | { | |
16415 | argv_size *= 2; | |
16416 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
16417 | } | |
16418 | ||
16419 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
16420 | } | |
16421 | ||
16422 | p = consume_improper_spaces (p, body); | |
16423 | ||
16424 | /* Consume the comma, if present. */ | |
16425 | if (*p == ',') | |
16426 | { | |
16427 | p++; | |
16428 | ||
16429 | p = consume_improper_spaces (p, body); | |
16430 | } | |
16431 | } | |
16432 | ||
16433 | if (*p == ')') | |
16434 | { | |
16435 | p++; | |
16436 | ||
16437 | if (*p == ' ') | |
16438 | /* Perfectly formed definition, no complaints. */ | |
16439 | macro_define_function (file, line, name, | |
6e70227d | 16440 | argc, (const char **) argv, |
2e276125 JB |
16441 | p + 1); |
16442 | else if (*p == '\0') | |
16443 | { | |
16444 | /* Complain, but do define it. */ | |
4d3c2250 | 16445 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 16446 | macro_define_function (file, line, name, |
6e70227d | 16447 | argc, (const char **) argv, |
2e276125 JB |
16448 | p); |
16449 | } | |
16450 | else | |
16451 | /* Just complain. */ | |
4d3c2250 | 16452 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
16453 | } |
16454 | else | |
16455 | /* Just complain. */ | |
4d3c2250 | 16456 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
16457 | |
16458 | xfree (name); | |
16459 | { | |
16460 | int i; | |
16461 | ||
16462 | for (i = 0; i < argc; i++) | |
16463 | xfree (argv[i]); | |
16464 | } | |
16465 | xfree (argv); | |
16466 | } | |
16467 | else | |
4d3c2250 | 16468 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
16469 | } |
16470 | ||
cf2c3c16 TT |
16471 | /* Skip some bytes from BYTES according to the form given in FORM. |
16472 | Returns the new pointer. */ | |
2e276125 | 16473 | |
cf2c3c16 TT |
16474 | static gdb_byte * |
16475 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, | |
16476 | enum dwarf_form form, | |
16477 | unsigned int offset_size, | |
16478 | struct dwarf2_section_info *section) | |
2e276125 | 16479 | { |
cf2c3c16 | 16480 | unsigned int bytes_read; |
2e276125 | 16481 | |
cf2c3c16 | 16482 | switch (form) |
2e276125 | 16483 | { |
cf2c3c16 TT |
16484 | case DW_FORM_data1: |
16485 | case DW_FORM_flag: | |
16486 | ++bytes; | |
16487 | break; | |
16488 | ||
16489 | case DW_FORM_data2: | |
16490 | bytes += 2; | |
16491 | break; | |
16492 | ||
16493 | case DW_FORM_data4: | |
16494 | bytes += 4; | |
16495 | break; | |
16496 | ||
16497 | case DW_FORM_data8: | |
16498 | bytes += 8; | |
16499 | break; | |
16500 | ||
16501 | case DW_FORM_string: | |
16502 | read_direct_string (abfd, bytes, &bytes_read); | |
16503 | bytes += bytes_read; | |
16504 | break; | |
16505 | ||
16506 | case DW_FORM_sec_offset: | |
16507 | case DW_FORM_strp: | |
16508 | bytes += offset_size; | |
16509 | break; | |
16510 | ||
16511 | case DW_FORM_block: | |
16512 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); | |
16513 | bytes += bytes_read; | |
16514 | break; | |
16515 | ||
16516 | case DW_FORM_block1: | |
16517 | bytes += 1 + read_1_byte (abfd, bytes); | |
16518 | break; | |
16519 | case DW_FORM_block2: | |
16520 | bytes += 2 + read_2_bytes (abfd, bytes); | |
16521 | break; | |
16522 | case DW_FORM_block4: | |
16523 | bytes += 4 + read_4_bytes (abfd, bytes); | |
16524 | break; | |
16525 | ||
16526 | case DW_FORM_sdata: | |
16527 | case DW_FORM_udata: | |
3019eac3 DE |
16528 | case DW_FORM_GNU_addr_index: |
16529 | case DW_FORM_GNU_str_index: | |
cf2c3c16 TT |
16530 | bytes = skip_leb128 (abfd, bytes); |
16531 | break; | |
16532 | ||
16533 | default: | |
16534 | { | |
16535 | complain: | |
16536 | complaint (&symfile_complaints, | |
16537 | _("invalid form 0x%x in `%s'"), | |
16538 | form, | |
16539 | section->asection->name); | |
16540 | return NULL; | |
16541 | } | |
2e276125 JB |
16542 | } |
16543 | ||
cf2c3c16 TT |
16544 | return bytes; |
16545 | } | |
757a13d0 | 16546 | |
cf2c3c16 TT |
16547 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
16548 | opcode. Returns an updated pointer to the macro data buffer; or, | |
16549 | on error, issues a complaint and returns NULL. */ | |
757a13d0 | 16550 | |
cf2c3c16 TT |
16551 | static gdb_byte * |
16552 | skip_unknown_opcode (unsigned int opcode, | |
16553 | gdb_byte **opcode_definitions, | |
16554 | gdb_byte *mac_ptr, | |
16555 | bfd *abfd, | |
16556 | unsigned int offset_size, | |
16557 | struct dwarf2_section_info *section) | |
16558 | { | |
16559 | unsigned int bytes_read, i; | |
16560 | unsigned long arg; | |
16561 | gdb_byte *defn; | |
2e276125 | 16562 | |
cf2c3c16 | 16563 | if (opcode_definitions[opcode] == NULL) |
2e276125 | 16564 | { |
cf2c3c16 TT |
16565 | complaint (&symfile_complaints, |
16566 | _("unrecognized DW_MACFINO opcode 0x%x"), | |
16567 | opcode); | |
16568 | return NULL; | |
16569 | } | |
2e276125 | 16570 | |
cf2c3c16 TT |
16571 | defn = opcode_definitions[opcode]; |
16572 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); | |
16573 | defn += bytes_read; | |
2e276125 | 16574 | |
cf2c3c16 TT |
16575 | for (i = 0; i < arg; ++i) |
16576 | { | |
16577 | mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section); | |
16578 | if (mac_ptr == NULL) | |
16579 | { | |
16580 | /* skip_form_bytes already issued the complaint. */ | |
16581 | return NULL; | |
16582 | } | |
16583 | } | |
757a13d0 | 16584 | |
cf2c3c16 TT |
16585 | return mac_ptr; |
16586 | } | |
757a13d0 | 16587 | |
cf2c3c16 TT |
16588 | /* A helper function which parses the header of a macro section. |
16589 | If the macro section is the extended (for now called "GNU") type, | |
16590 | then this updates *OFFSET_SIZE. Returns a pointer to just after | |
16591 | the header, or issues a complaint and returns NULL on error. */ | |
757a13d0 | 16592 | |
cf2c3c16 TT |
16593 | static gdb_byte * |
16594 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, | |
16595 | bfd *abfd, | |
16596 | gdb_byte *mac_ptr, | |
16597 | unsigned int *offset_size, | |
16598 | int section_is_gnu) | |
16599 | { | |
16600 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); | |
757a13d0 | 16601 | |
cf2c3c16 TT |
16602 | if (section_is_gnu) |
16603 | { | |
16604 | unsigned int version, flags; | |
757a13d0 | 16605 | |
cf2c3c16 TT |
16606 | version = read_2_bytes (abfd, mac_ptr); |
16607 | if (version != 4) | |
16608 | { | |
16609 | complaint (&symfile_complaints, | |
16610 | _("unrecognized version `%d' in .debug_macro section"), | |
16611 | version); | |
16612 | return NULL; | |
16613 | } | |
16614 | mac_ptr += 2; | |
757a13d0 | 16615 | |
cf2c3c16 TT |
16616 | flags = read_1_byte (abfd, mac_ptr); |
16617 | ++mac_ptr; | |
16618 | *offset_size = (flags & 1) ? 8 : 4; | |
757a13d0 | 16619 | |
cf2c3c16 TT |
16620 | if ((flags & 2) != 0) |
16621 | /* We don't need the line table offset. */ | |
16622 | mac_ptr += *offset_size; | |
757a13d0 | 16623 | |
cf2c3c16 TT |
16624 | /* Vendor opcode descriptions. */ |
16625 | if ((flags & 4) != 0) | |
16626 | { | |
16627 | unsigned int i, count; | |
757a13d0 | 16628 | |
cf2c3c16 TT |
16629 | count = read_1_byte (abfd, mac_ptr); |
16630 | ++mac_ptr; | |
16631 | for (i = 0; i < count; ++i) | |
16632 | { | |
16633 | unsigned int opcode, bytes_read; | |
16634 | unsigned long arg; | |
16635 | ||
16636 | opcode = read_1_byte (abfd, mac_ptr); | |
16637 | ++mac_ptr; | |
16638 | opcode_definitions[opcode] = mac_ptr; | |
16639 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16640 | mac_ptr += bytes_read; | |
16641 | mac_ptr += arg; | |
16642 | } | |
757a13d0 | 16643 | } |
cf2c3c16 | 16644 | } |
757a13d0 | 16645 | |
cf2c3c16 TT |
16646 | return mac_ptr; |
16647 | } | |
757a13d0 | 16648 | |
cf2c3c16 | 16649 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
8fc3fc34 | 16650 | including DW_MACRO_GNU_transparent_include. */ |
cf2c3c16 TT |
16651 | |
16652 | static void | |
16653 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, | |
16654 | struct macro_source_file *current_file, | |
16655 | struct line_header *lh, char *comp_dir, | |
16656 | struct dwarf2_section_info *section, | |
16657 | int section_is_gnu, | |
16658 | unsigned int offset_size, | |
8fc3fc34 TT |
16659 | struct objfile *objfile, |
16660 | htab_t include_hash) | |
cf2c3c16 TT |
16661 | { |
16662 | enum dwarf_macro_record_type macinfo_type; | |
16663 | int at_commandline; | |
16664 | gdb_byte *opcode_definitions[256]; | |
757a13d0 | 16665 | |
cf2c3c16 TT |
16666 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
16667 | &offset_size, section_is_gnu); | |
16668 | if (mac_ptr == NULL) | |
16669 | { | |
16670 | /* We already issued a complaint. */ | |
16671 | return; | |
16672 | } | |
757a13d0 JK |
16673 | |
16674 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
16675 | GDB is still reading the definitions from command line. First | |
16676 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
16677 | to create CURRENT_FILE for the main source holding also the command line | |
16678 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
16679 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
16680 | ||
16681 | at_commandline = 1; | |
16682 | ||
16683 | do | |
16684 | { | |
16685 | /* Do we at least have room for a macinfo type byte? */ | |
16686 | if (mac_ptr >= mac_end) | |
16687 | { | |
cf2c3c16 | 16688 | dwarf2_macros_too_long_complaint (section); |
757a13d0 JK |
16689 | break; |
16690 | } | |
16691 | ||
16692 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
16693 | mac_ptr++; | |
16694 | ||
cf2c3c16 TT |
16695 | /* Note that we rely on the fact that the corresponding GNU and |
16696 | DWARF constants are the same. */ | |
757a13d0 JK |
16697 | switch (macinfo_type) |
16698 | { | |
16699 | /* A zero macinfo type indicates the end of the macro | |
16700 | information. */ | |
16701 | case 0: | |
16702 | break; | |
2e276125 | 16703 | |
cf2c3c16 TT |
16704 | case DW_MACRO_GNU_define: |
16705 | case DW_MACRO_GNU_undef: | |
16706 | case DW_MACRO_GNU_define_indirect: | |
16707 | case DW_MACRO_GNU_undef_indirect: | |
2e276125 | 16708 | { |
891d2f0b | 16709 | unsigned int bytes_read; |
2e276125 JB |
16710 | int line; |
16711 | char *body; | |
cf2c3c16 | 16712 | int is_define; |
2e276125 | 16713 | |
cf2c3c16 TT |
16714 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
16715 | mac_ptr += bytes_read; | |
16716 | ||
16717 | if (macinfo_type == DW_MACRO_GNU_define | |
16718 | || macinfo_type == DW_MACRO_GNU_undef) | |
16719 | { | |
16720 | body = read_direct_string (abfd, mac_ptr, &bytes_read); | |
16721 | mac_ptr += bytes_read; | |
16722 | } | |
16723 | else | |
16724 | { | |
16725 | LONGEST str_offset; | |
16726 | ||
16727 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
16728 | mac_ptr += offset_size; | |
2e276125 | 16729 | |
cf2c3c16 TT |
16730 | body = read_indirect_string_at_offset (abfd, str_offset); |
16731 | } | |
16732 | ||
16733 | is_define = (macinfo_type == DW_MACRO_GNU_define | |
16734 | || macinfo_type == DW_MACRO_GNU_define_indirect); | |
2e276125 | 16735 | if (! current_file) |
757a13d0 JK |
16736 | { |
16737 | /* DWARF violation as no main source is present. */ | |
16738 | complaint (&symfile_complaints, | |
16739 | _("debug info with no main source gives macro %s " | |
16740 | "on line %d: %s"), | |
cf2c3c16 TT |
16741 | is_define ? _("definition") : _("undefinition"), |
16742 | line, body); | |
757a13d0 JK |
16743 | break; |
16744 | } | |
3e43a32a MS |
16745 | if ((line == 0 && !at_commandline) |
16746 | || (line != 0 && at_commandline)) | |
4d3c2250 | 16747 | complaint (&symfile_complaints, |
757a13d0 JK |
16748 | _("debug info gives %s macro %s with %s line %d: %s"), |
16749 | at_commandline ? _("command-line") : _("in-file"), | |
cf2c3c16 | 16750 | is_define ? _("definition") : _("undefinition"), |
757a13d0 JK |
16751 | line == 0 ? _("zero") : _("non-zero"), line, body); |
16752 | ||
cf2c3c16 | 16753 | if (is_define) |
757a13d0 | 16754 | parse_macro_definition (current_file, line, body); |
cf2c3c16 TT |
16755 | else |
16756 | { | |
16757 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef | |
16758 | || macinfo_type == DW_MACRO_GNU_undef_indirect); | |
16759 | macro_undef (current_file, line, body); | |
16760 | } | |
2e276125 JB |
16761 | } |
16762 | break; | |
16763 | ||
cf2c3c16 | 16764 | case DW_MACRO_GNU_start_file: |
2e276125 | 16765 | { |
891d2f0b | 16766 | unsigned int bytes_read; |
2e276125 JB |
16767 | int line, file; |
16768 | ||
16769 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16770 | mac_ptr += bytes_read; | |
16771 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16772 | mac_ptr += bytes_read; | |
16773 | ||
3e43a32a MS |
16774 | if ((line == 0 && !at_commandline) |
16775 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
16776 | complaint (&symfile_complaints, |
16777 | _("debug info gives source %d included " | |
16778 | "from %s at %s line %d"), | |
16779 | file, at_commandline ? _("command-line") : _("file"), | |
16780 | line == 0 ? _("zero") : _("non-zero"), line); | |
16781 | ||
16782 | if (at_commandline) | |
16783 | { | |
cf2c3c16 TT |
16784 | /* This DW_MACRO_GNU_start_file was executed in the |
16785 | pass one. */ | |
757a13d0 JK |
16786 | at_commandline = 0; |
16787 | } | |
16788 | else | |
16789 | current_file = macro_start_file (file, line, | |
16790 | current_file, comp_dir, | |
cf2c3c16 | 16791 | lh, objfile); |
2e276125 JB |
16792 | } |
16793 | break; | |
16794 | ||
cf2c3c16 | 16795 | case DW_MACRO_GNU_end_file: |
2e276125 | 16796 | if (! current_file) |
4d3c2250 | 16797 | complaint (&symfile_complaints, |
3e43a32a MS |
16798 | _("macro debug info has an unmatched " |
16799 | "`close_file' directive")); | |
2e276125 JB |
16800 | else |
16801 | { | |
16802 | current_file = current_file->included_by; | |
16803 | if (! current_file) | |
16804 | { | |
cf2c3c16 | 16805 | enum dwarf_macro_record_type next_type; |
2e276125 JB |
16806 | |
16807 | /* GCC circa March 2002 doesn't produce the zero | |
16808 | type byte marking the end of the compilation | |
16809 | unit. Complain if it's not there, but exit no | |
16810 | matter what. */ | |
16811 | ||
16812 | /* Do we at least have room for a macinfo type byte? */ | |
16813 | if (mac_ptr >= mac_end) | |
16814 | { | |
cf2c3c16 | 16815 | dwarf2_macros_too_long_complaint (section); |
2e276125 JB |
16816 | return; |
16817 | } | |
16818 | ||
16819 | /* We don't increment mac_ptr here, so this is just | |
16820 | a look-ahead. */ | |
16821 | next_type = read_1_byte (abfd, mac_ptr); | |
16822 | if (next_type != 0) | |
4d3c2250 | 16823 | complaint (&symfile_complaints, |
3e43a32a MS |
16824 | _("no terminating 0-type entry for " |
16825 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
16826 | |
16827 | return; | |
16828 | } | |
16829 | } | |
16830 | break; | |
16831 | ||
cf2c3c16 TT |
16832 | case DW_MACRO_GNU_transparent_include: |
16833 | { | |
16834 | LONGEST offset; | |
8fc3fc34 | 16835 | void **slot; |
cf2c3c16 TT |
16836 | |
16837 | offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
16838 | mac_ptr += offset_size; | |
16839 | ||
8fc3fc34 TT |
16840 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); |
16841 | if (*slot != NULL) | |
16842 | { | |
16843 | /* This has actually happened; see | |
16844 | http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */ | |
16845 | complaint (&symfile_complaints, | |
16846 | _("recursive DW_MACRO_GNU_transparent_include in " | |
16847 | ".debug_macro section")); | |
16848 | } | |
16849 | else | |
16850 | { | |
16851 | *slot = mac_ptr; | |
16852 | ||
16853 | dwarf_decode_macro_bytes (abfd, | |
16854 | section->buffer + offset, | |
16855 | mac_end, current_file, | |
16856 | lh, comp_dir, | |
16857 | section, section_is_gnu, | |
16858 | offset_size, objfile, include_hash); | |
16859 | ||
16860 | htab_remove_elt (include_hash, mac_ptr); | |
16861 | } | |
cf2c3c16 TT |
16862 | } |
16863 | break; | |
16864 | ||
2e276125 | 16865 | case DW_MACINFO_vendor_ext: |
cf2c3c16 TT |
16866 | if (!section_is_gnu) |
16867 | { | |
16868 | unsigned int bytes_read; | |
16869 | int constant; | |
2e276125 | 16870 | |
cf2c3c16 TT |
16871 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
16872 | mac_ptr += bytes_read; | |
16873 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
16874 | mac_ptr += bytes_read; | |
2e276125 | 16875 | |
cf2c3c16 TT |
16876 | /* We don't recognize any vendor extensions. */ |
16877 | break; | |
16878 | } | |
16879 | /* FALLTHROUGH */ | |
16880 | ||
16881 | default: | |
16882 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
16883 | mac_ptr, abfd, offset_size, | |
16884 | section); | |
16885 | if (mac_ptr == NULL) | |
16886 | return; | |
16887 | break; | |
2e276125 | 16888 | } |
757a13d0 | 16889 | } while (macinfo_type != 0); |
2e276125 | 16890 | } |
8e19ed76 | 16891 | |
cf2c3c16 TT |
16892 | static void |
16893 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
16894 | char *comp_dir, bfd *abfd, | |
16895 | struct dwarf2_cu *cu, | |
16896 | struct dwarf2_section_info *section, | |
16897 | int section_is_gnu) | |
16898 | { | |
bb5ed363 | 16899 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
cf2c3c16 TT |
16900 | gdb_byte *mac_ptr, *mac_end; |
16901 | struct macro_source_file *current_file = 0; | |
16902 | enum dwarf_macro_record_type macinfo_type; | |
16903 | unsigned int offset_size = cu->header.offset_size; | |
16904 | gdb_byte *opcode_definitions[256]; | |
8fc3fc34 TT |
16905 | struct cleanup *cleanup; |
16906 | htab_t include_hash; | |
16907 | void **slot; | |
cf2c3c16 | 16908 | |
bb5ed363 | 16909 | dwarf2_read_section (objfile, section); |
cf2c3c16 TT |
16910 | if (section->buffer == NULL) |
16911 | { | |
16912 | complaint (&symfile_complaints, _("missing %s section"), | |
16913 | section->asection->name); | |
16914 | return; | |
16915 | } | |
16916 | ||
16917 | /* First pass: Find the name of the base filename. | |
16918 | This filename is needed in order to process all macros whose definition | |
16919 | (or undefinition) comes from the command line. These macros are defined | |
16920 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
16921 | associated to the base file. | |
16922 | ||
16923 | To determine the base file name, we scan the macro definitions until we | |
16924 | reach the first DW_MACINFO_start_file entry. We then initialize | |
16925 | CURRENT_FILE accordingly so that any macro definition found before the | |
16926 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
16927 | ||
16928 | mac_ptr = section->buffer + offset; | |
16929 | mac_end = section->buffer + section->size; | |
16930 | ||
16931 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, | |
16932 | &offset_size, section_is_gnu); | |
16933 | if (mac_ptr == NULL) | |
16934 | { | |
16935 | /* We already issued a complaint. */ | |
16936 | return; | |
16937 | } | |
16938 | ||
16939 | do | |
16940 | { | |
16941 | /* Do we at least have room for a macinfo type byte? */ | |
16942 | if (mac_ptr >= mac_end) | |
16943 | { | |
16944 | /* Complaint is printed during the second pass as GDB will probably | |
16945 | stop the first pass earlier upon finding | |
16946 | DW_MACINFO_start_file. */ | |
16947 | break; | |
16948 | } | |
16949 | ||
16950 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
16951 | mac_ptr++; | |
16952 | ||
16953 | /* Note that we rely on the fact that the corresponding GNU and | |
16954 | DWARF constants are the same. */ | |
16955 | switch (macinfo_type) | |
16956 | { | |
16957 | /* A zero macinfo type indicates the end of the macro | |
16958 | information. */ | |
16959 | case 0: | |
16960 | break; | |
16961 | ||
16962 | case DW_MACRO_GNU_define: | |
16963 | case DW_MACRO_GNU_undef: | |
16964 | /* Only skip the data by MAC_PTR. */ | |
16965 | { | |
16966 | unsigned int bytes_read; | |
16967 | ||
16968 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16969 | mac_ptr += bytes_read; | |
16970 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
16971 | mac_ptr += bytes_read; | |
16972 | } | |
16973 | break; | |
16974 | ||
16975 | case DW_MACRO_GNU_start_file: | |
16976 | { | |
16977 | unsigned int bytes_read; | |
16978 | int line, file; | |
16979 | ||
16980 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16981 | mac_ptr += bytes_read; | |
16982 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
16983 | mac_ptr += bytes_read; | |
16984 | ||
16985 | current_file = macro_start_file (file, line, current_file, | |
bb5ed363 | 16986 | comp_dir, lh, objfile); |
cf2c3c16 TT |
16987 | } |
16988 | break; | |
16989 | ||
16990 | case DW_MACRO_GNU_end_file: | |
16991 | /* No data to skip by MAC_PTR. */ | |
16992 | break; | |
16993 | ||
16994 | case DW_MACRO_GNU_define_indirect: | |
16995 | case DW_MACRO_GNU_undef_indirect: | |
16996 | { | |
16997 | unsigned int bytes_read; | |
16998 | ||
16999 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
17000 | mac_ptr += bytes_read; | |
17001 | mac_ptr += offset_size; | |
17002 | } | |
17003 | break; | |
17004 | ||
17005 | case DW_MACRO_GNU_transparent_include: | |
17006 | /* Note that, according to the spec, a transparent include | |
17007 | chain cannot call DW_MACRO_GNU_start_file. So, we can just | |
17008 | skip this opcode. */ | |
17009 | mac_ptr += offset_size; | |
17010 | break; | |
17011 | ||
17012 | case DW_MACINFO_vendor_ext: | |
17013 | /* Only skip the data by MAC_PTR. */ | |
17014 | if (!section_is_gnu) | |
17015 | { | |
17016 | unsigned int bytes_read; | |
17017 | ||
17018 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
17019 | mac_ptr += bytes_read; | |
17020 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
17021 | mac_ptr += bytes_read; | |
17022 | } | |
17023 | /* FALLTHROUGH */ | |
17024 | ||
17025 | default: | |
17026 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
17027 | mac_ptr, abfd, offset_size, | |
17028 | section); | |
17029 | if (mac_ptr == NULL) | |
17030 | return; | |
17031 | break; | |
17032 | } | |
17033 | } while (macinfo_type != 0 && current_file == NULL); | |
17034 | ||
17035 | /* Second pass: Process all entries. | |
17036 | ||
17037 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
17038 | command-line macro definitions/undefinitions. This flag is unset when we | |
17039 | reach the first DW_MACINFO_start_file entry. */ | |
17040 | ||
8fc3fc34 TT |
17041 | include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, |
17042 | NULL, xcalloc, xfree); | |
17043 | cleanup = make_cleanup_htab_delete (include_hash); | |
17044 | mac_ptr = section->buffer + offset; | |
17045 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); | |
17046 | *slot = mac_ptr; | |
17047 | dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end, | |
cf2c3c16 | 17048 | current_file, lh, comp_dir, section, section_is_gnu, |
8fc3fc34 TT |
17049 | offset_size, objfile, include_hash); |
17050 | do_cleanups (cleanup); | |
cf2c3c16 TT |
17051 | } |
17052 | ||
8e19ed76 | 17053 | /* Check if the attribute's form is a DW_FORM_block* |
0963b4bd | 17054 | if so return true else false. */ |
380bca97 | 17055 | |
8e19ed76 PS |
17056 | static int |
17057 | attr_form_is_block (struct attribute *attr) | |
17058 | { | |
17059 | return (attr == NULL ? 0 : | |
17060 | attr->form == DW_FORM_block1 | |
17061 | || attr->form == DW_FORM_block2 | |
17062 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
17063 | || attr->form == DW_FORM_block |
17064 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 17065 | } |
4c2df51b | 17066 | |
c6a0999f JB |
17067 | /* Return non-zero if ATTR's value is a section offset --- classes |
17068 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
17069 | You may use DW_UNSND (attr) to retrieve such offsets. | |
17070 | ||
17071 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
17072 | may have a value that belongs to more than one of these classes; it | |
17073 | would be ambiguous if we did, because we use the same forms for all | |
17074 | of them. */ | |
380bca97 | 17075 | |
3690dd37 JB |
17076 | static int |
17077 | attr_form_is_section_offset (struct attribute *attr) | |
17078 | { | |
17079 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
17080 | || attr->form == DW_FORM_data8 |
17081 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
17082 | } |
17083 | ||
3690dd37 JB |
17084 | /* Return non-zero if ATTR's value falls in the 'constant' class, or |
17085 | zero otherwise. When this function returns true, you can apply | |
17086 | dwarf2_get_attr_constant_value to it. | |
17087 | ||
17088 | However, note that for some attributes you must check | |
17089 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
17090 | and DW_FORM_data8 are members of both the constant class, and of | |
17091 | the classes that contain offsets into other debug sections | |
17092 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
17093 | that, if an attribute's can be either a constant or one of the | |
17094 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
17095 | taken as section offsets, not constants. */ | |
380bca97 | 17096 | |
3690dd37 JB |
17097 | static int |
17098 | attr_form_is_constant (struct attribute *attr) | |
17099 | { | |
17100 | switch (attr->form) | |
17101 | { | |
17102 | case DW_FORM_sdata: | |
17103 | case DW_FORM_udata: | |
17104 | case DW_FORM_data1: | |
17105 | case DW_FORM_data2: | |
17106 | case DW_FORM_data4: | |
17107 | case DW_FORM_data8: | |
17108 | return 1; | |
17109 | default: | |
17110 | return 0; | |
17111 | } | |
17112 | } | |
17113 | ||
3019eac3 DE |
17114 | /* Return the .debug_loc section to use for CU. |
17115 | For DWO files use .debug_loc.dwo. */ | |
17116 | ||
17117 | static struct dwarf2_section_info * | |
17118 | cu_debug_loc_section (struct dwarf2_cu *cu) | |
17119 | { | |
17120 | if (cu->dwo_unit) | |
17121 | return &cu->dwo_unit->dwo_file->sections.loc; | |
17122 | return &dwarf2_per_objfile->loc; | |
17123 | } | |
17124 | ||
8cf6f0b1 TT |
17125 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
17126 | ||
17127 | static void | |
17128 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
17129 | struct dwarf2_loclist_baton *baton, | |
17130 | struct attribute *attr) | |
17131 | { | |
3019eac3 DE |
17132 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
17133 | ||
17134 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); | |
8cf6f0b1 TT |
17135 | |
17136 | baton->per_cu = cu->per_cu; | |
17137 | gdb_assert (baton->per_cu); | |
17138 | /* We don't know how long the location list is, but make sure we | |
17139 | don't run off the edge of the section. */ | |
3019eac3 DE |
17140 | baton->size = section->size - DW_UNSND (attr); |
17141 | baton->data = section->buffer + DW_UNSND (attr); | |
8cf6f0b1 TT |
17142 | baton->base_address = cu->base_address; |
17143 | } | |
17144 | ||
4c2df51b DJ |
17145 | static void |
17146 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 17147 | struct dwarf2_cu *cu) |
4c2df51b | 17148 | { |
bb5ed363 | 17149 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
3019eac3 | 17150 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
bb5ed363 | 17151 | |
3690dd37 | 17152 | if (attr_form_is_section_offset (attr) |
3019eac3 | 17153 | /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside |
99bcc461 DJ |
17154 | the section. If so, fall through to the complaint in the |
17155 | other branch. */ | |
3019eac3 | 17156 | && DW_UNSND (attr) < dwarf2_section_size (objfile, section)) |
4c2df51b | 17157 | { |
0d53c4c4 | 17158 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 17159 | |
bb5ed363 | 17160 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 17161 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 17162 | |
8cf6f0b1 | 17163 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 17164 | |
d00adf39 | 17165 | if (cu->base_known == 0) |
0d53c4c4 | 17166 | complaint (&symfile_complaints, |
3e43a32a MS |
17167 | _("Location list used without " |
17168 | "specifying the CU base address.")); | |
4c2df51b | 17169 | |
768a979c | 17170 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
17171 | SYMBOL_LOCATION_BATON (sym) = baton; |
17172 | } | |
17173 | else | |
17174 | { | |
17175 | struct dwarf2_locexpr_baton *baton; | |
17176 | ||
bb5ed363 | 17177 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 17178 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
17179 | baton->per_cu = cu->per_cu; |
17180 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
17181 | |
17182 | if (attr_form_is_block (attr)) | |
17183 | { | |
17184 | /* Note that we're just copying the block's data pointer | |
17185 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
17186 | info_buffer for SYM's objfile; right now we never release |
17187 | that buffer, but when we do clean up properly this may | |
17188 | need to change. */ | |
0d53c4c4 DJ |
17189 | baton->size = DW_BLOCK (attr)->size; |
17190 | baton->data = DW_BLOCK (attr)->data; | |
17191 | } | |
17192 | else | |
17193 | { | |
17194 | dwarf2_invalid_attrib_class_complaint ("location description", | |
17195 | SYMBOL_NATURAL_NAME (sym)); | |
17196 | baton->size = 0; | |
0d53c4c4 | 17197 | } |
6e70227d | 17198 | |
768a979c | 17199 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
17200 | SYMBOL_LOCATION_BATON (sym) = baton; |
17201 | } | |
4c2df51b | 17202 | } |
6502dd73 | 17203 | |
9aa1f1e3 TT |
17204 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
17205 | came from a separate debuginfo file, then the master objfile is | |
17206 | returned. */ | |
ae0d2f24 UW |
17207 | |
17208 | struct objfile * | |
17209 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
17210 | { | |
9291a0cd | 17211 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
17212 | |
17213 | /* Return the master objfile, so that we can report and look up the | |
17214 | correct file containing this variable. */ | |
17215 | if (objfile->separate_debug_objfile_backlink) | |
17216 | objfile = objfile->separate_debug_objfile_backlink; | |
17217 | ||
17218 | return objfile; | |
17219 | } | |
17220 | ||
96408a79 SA |
17221 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
17222 | (CU_HEADERP is unused in such case) or prepare a temporary copy at | |
17223 | CU_HEADERP first. */ | |
17224 | ||
17225 | static const struct comp_unit_head * | |
17226 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, | |
17227 | struct dwarf2_per_cu_data *per_cu) | |
17228 | { | |
17229 | struct objfile *objfile; | |
17230 | struct dwarf2_per_objfile *per_objfile; | |
17231 | gdb_byte *info_ptr; | |
17232 | ||
17233 | if (per_cu->cu) | |
17234 | return &per_cu->cu->header; | |
17235 | ||
17236 | objfile = per_cu->objfile; | |
17237 | per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
b64f50a1 | 17238 | info_ptr = per_objfile->info.buffer + per_cu->offset.sect_off; |
96408a79 SA |
17239 | |
17240 | memset (cu_headerp, 0, sizeof (*cu_headerp)); | |
17241 | read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd); | |
17242 | ||
17243 | return cu_headerp; | |
17244 | } | |
17245 | ||
ae0d2f24 UW |
17246 | /* Return the address size given in the compilation unit header for CU. */ |
17247 | ||
98714339 | 17248 | int |
ae0d2f24 UW |
17249 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
17250 | { | |
96408a79 SA |
17251 | struct comp_unit_head cu_header_local; |
17252 | const struct comp_unit_head *cu_headerp; | |
c471e790 | 17253 | |
96408a79 SA |
17254 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
17255 | ||
17256 | return cu_headerp->addr_size; | |
ae0d2f24 UW |
17257 | } |
17258 | ||
9eae7c52 TT |
17259 | /* Return the offset size given in the compilation unit header for CU. */ |
17260 | ||
17261 | int | |
17262 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
17263 | { | |
96408a79 SA |
17264 | struct comp_unit_head cu_header_local; |
17265 | const struct comp_unit_head *cu_headerp; | |
9c6c53f7 | 17266 | |
96408a79 SA |
17267 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
17268 | ||
17269 | return cu_headerp->offset_size; | |
17270 | } | |
17271 | ||
17272 | /* See its dwarf2loc.h declaration. */ | |
17273 | ||
17274 | int | |
17275 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) | |
17276 | { | |
17277 | struct comp_unit_head cu_header_local; | |
17278 | const struct comp_unit_head *cu_headerp; | |
17279 | ||
17280 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); | |
17281 | ||
17282 | if (cu_headerp->version == 2) | |
17283 | return cu_headerp->addr_size; | |
17284 | else | |
17285 | return cu_headerp->offset_size; | |
181cebd4 JK |
17286 | } |
17287 | ||
9aa1f1e3 TT |
17288 | /* Return the text offset of the CU. The returned offset comes from |
17289 | this CU's objfile. If this objfile came from a separate debuginfo | |
17290 | file, then the offset may be different from the corresponding | |
17291 | offset in the parent objfile. */ | |
17292 | ||
17293 | CORE_ADDR | |
17294 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
17295 | { | |
bb3fa9d0 | 17296 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
17297 | |
17298 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
17299 | } | |
17300 | ||
348e048f DE |
17301 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
17302 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
17303 | |
17304 | static struct dwarf2_per_cu_data * | |
b64f50a1 | 17305 | dwarf2_find_containing_comp_unit (sect_offset offset, |
ae038cb0 DJ |
17306 | struct objfile *objfile) |
17307 | { | |
17308 | struct dwarf2_per_cu_data *this_cu; | |
17309 | int low, high; | |
17310 | ||
ae038cb0 DJ |
17311 | low = 0; |
17312 | high = dwarf2_per_objfile->n_comp_units - 1; | |
17313 | while (high > low) | |
17314 | { | |
17315 | int mid = low + (high - low) / 2; | |
9a619af0 | 17316 | |
b64f50a1 JK |
17317 | if (dwarf2_per_objfile->all_comp_units[mid]->offset.sect_off |
17318 | >= offset.sect_off) | |
ae038cb0 DJ |
17319 | high = mid; |
17320 | else | |
17321 | low = mid + 1; | |
17322 | } | |
17323 | gdb_assert (low == high); | |
b64f50a1 JK |
17324 | if (dwarf2_per_objfile->all_comp_units[low]->offset.sect_off |
17325 | > offset.sect_off) | |
ae038cb0 | 17326 | { |
10b3939b | 17327 | if (low == 0) |
8a3fe4f8 AC |
17328 | error (_("Dwarf Error: could not find partial DIE containing " |
17329 | "offset 0x%lx [in module %s]"), | |
b64f50a1 | 17330 | (long) offset.sect_off, bfd_get_filename (objfile->obfd)); |
10b3939b | 17331 | |
b64f50a1 JK |
17332 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset.sect_off |
17333 | <= offset.sect_off); | |
ae038cb0 DJ |
17334 | return dwarf2_per_objfile->all_comp_units[low-1]; |
17335 | } | |
17336 | else | |
17337 | { | |
17338 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
17339 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
b64f50a1 JK |
17340 | && offset.sect_off >= this_cu->offset.sect_off + this_cu->length) |
17341 | error (_("invalid dwarf2 offset %u"), offset.sect_off); | |
17342 | gdb_assert (offset.sect_off < this_cu->offset.sect_off + this_cu->length); | |
ae038cb0 DJ |
17343 | return this_cu; |
17344 | } | |
17345 | } | |
17346 | ||
23745b47 | 17347 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
93311388 | 17348 | |
9816fde3 | 17349 | static void |
23745b47 | 17350 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
93311388 | 17351 | { |
9816fde3 | 17352 | memset (cu, 0, sizeof (*cu)); |
23745b47 DE |
17353 | per_cu->cu = cu; |
17354 | cu->per_cu = per_cu; | |
17355 | cu->objfile = per_cu->objfile; | |
93311388 | 17356 | obstack_init (&cu->comp_unit_obstack); |
9816fde3 JK |
17357 | } |
17358 | ||
17359 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
17360 | ||
17361 | static void | |
17362 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) | |
17363 | { | |
17364 | struct attribute *attr; | |
17365 | ||
17366 | /* Set the language we're debugging. */ | |
17367 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
17368 | if (attr) | |
17369 | set_cu_language (DW_UNSND (attr), cu); | |
17370 | else | |
9cded63f TT |
17371 | { |
17372 | cu->language = language_minimal; | |
17373 | cu->language_defn = language_def (cu->language); | |
17374 | } | |
dee91e82 DE |
17375 | |
17376 | attr = dwarf2_attr (comp_unit_die, DW_AT_producer, cu); | |
17377 | if (attr) | |
17378 | cu->producer = DW_STRING (attr); | |
93311388 DE |
17379 | } |
17380 | ||
ae038cb0 DJ |
17381 | /* Release one cached compilation unit, CU. We unlink it from the tree |
17382 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
17383 | the caller is responsible for that. |
17384 | NOTE: DATA is a void * because this function is also used as a | |
17385 | cleanup routine. */ | |
ae038cb0 DJ |
17386 | |
17387 | static void | |
68dc6402 | 17388 | free_heap_comp_unit (void *data) |
ae038cb0 DJ |
17389 | { |
17390 | struct dwarf2_cu *cu = data; | |
17391 | ||
23745b47 DE |
17392 | gdb_assert (cu->per_cu != NULL); |
17393 | cu->per_cu->cu = NULL; | |
ae038cb0 DJ |
17394 | cu->per_cu = NULL; |
17395 | ||
17396 | obstack_free (&cu->comp_unit_obstack, NULL); | |
17397 | ||
17398 | xfree (cu); | |
17399 | } | |
17400 | ||
72bf9492 | 17401 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 | 17402 | when we're finished with it. We can't free the pointer itself, but be |
dee91e82 | 17403 | sure to unlink it from the cache. Also release any associated storage. */ |
72bf9492 DJ |
17404 | |
17405 | static void | |
17406 | free_stack_comp_unit (void *data) | |
17407 | { | |
17408 | struct dwarf2_cu *cu = data; | |
17409 | ||
23745b47 DE |
17410 | gdb_assert (cu->per_cu != NULL); |
17411 | cu->per_cu->cu = NULL; | |
17412 | cu->per_cu = NULL; | |
17413 | ||
72bf9492 DJ |
17414 | obstack_free (&cu->comp_unit_obstack, NULL); |
17415 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
17416 | } |
17417 | ||
17418 | /* Free all cached compilation units. */ | |
17419 | ||
17420 | static void | |
17421 | free_cached_comp_units (void *data) | |
17422 | { | |
17423 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
17424 | ||
17425 | per_cu = dwarf2_per_objfile->read_in_chain; | |
17426 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
17427 | while (per_cu != NULL) | |
17428 | { | |
17429 | struct dwarf2_per_cu_data *next_cu; | |
17430 | ||
17431 | next_cu = per_cu->cu->read_in_chain; | |
17432 | ||
68dc6402 | 17433 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
17434 | *last_chain = next_cu; |
17435 | ||
17436 | per_cu = next_cu; | |
17437 | } | |
17438 | } | |
17439 | ||
17440 | /* Increase the age counter on each cached compilation unit, and free | |
17441 | any that are too old. */ | |
17442 | ||
17443 | static void | |
17444 | age_cached_comp_units (void) | |
17445 | { | |
17446 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
17447 | ||
17448 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
17449 | per_cu = dwarf2_per_objfile->read_in_chain; | |
17450 | while (per_cu != NULL) | |
17451 | { | |
17452 | per_cu->cu->last_used ++; | |
17453 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
17454 | dwarf2_mark (per_cu->cu); | |
17455 | per_cu = per_cu->cu->read_in_chain; | |
17456 | } | |
17457 | ||
17458 | per_cu = dwarf2_per_objfile->read_in_chain; | |
17459 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
17460 | while (per_cu != NULL) | |
17461 | { | |
17462 | struct dwarf2_per_cu_data *next_cu; | |
17463 | ||
17464 | next_cu = per_cu->cu->read_in_chain; | |
17465 | ||
17466 | if (!per_cu->cu->mark) | |
17467 | { | |
68dc6402 | 17468 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
17469 | *last_chain = next_cu; |
17470 | } | |
17471 | else | |
17472 | last_chain = &per_cu->cu->read_in_chain; | |
17473 | ||
17474 | per_cu = next_cu; | |
17475 | } | |
17476 | } | |
17477 | ||
17478 | /* Remove a single compilation unit from the cache. */ | |
17479 | ||
17480 | static void | |
dee91e82 | 17481 | free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu) |
ae038cb0 DJ |
17482 | { |
17483 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
17484 | ||
17485 | per_cu = dwarf2_per_objfile->read_in_chain; | |
17486 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
17487 | while (per_cu != NULL) | |
17488 | { | |
17489 | struct dwarf2_per_cu_data *next_cu; | |
17490 | ||
17491 | next_cu = per_cu->cu->read_in_chain; | |
17492 | ||
dee91e82 | 17493 | if (per_cu == target_per_cu) |
ae038cb0 | 17494 | { |
68dc6402 | 17495 | free_heap_comp_unit (per_cu->cu); |
dee91e82 | 17496 | per_cu->cu = NULL; |
ae038cb0 DJ |
17497 | *last_chain = next_cu; |
17498 | break; | |
17499 | } | |
17500 | else | |
17501 | last_chain = &per_cu->cu->read_in_chain; | |
17502 | ||
17503 | per_cu = next_cu; | |
17504 | } | |
17505 | } | |
17506 | ||
fe3e1990 DJ |
17507 | /* Release all extra memory associated with OBJFILE. */ |
17508 | ||
17509 | void | |
17510 | dwarf2_free_objfile (struct objfile *objfile) | |
17511 | { | |
17512 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
17513 | ||
17514 | if (dwarf2_per_objfile == NULL) | |
17515 | return; | |
17516 | ||
17517 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
17518 | free_cached_comp_units (NULL); | |
17519 | ||
7b9f3c50 DE |
17520 | if (dwarf2_per_objfile->quick_file_names_table) |
17521 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 17522 | |
fe3e1990 DJ |
17523 | /* Everything else should be on the objfile obstack. */ |
17524 | } | |
17525 | ||
dee91e82 DE |
17526 | /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer. |
17527 | We store these in a hash table separate from the DIEs, and preserve them | |
17528 | when the DIEs are flushed out of cache. | |
17529 | ||
17530 | The CU "per_cu" pointer is needed because offset alone is not enough to | |
3019eac3 DE |
17531 | uniquely identify the type. A file may have multiple .debug_types sections, |
17532 | or the type may come from a DWO file. We have to use something in | |
17533 | dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup | |
17534 | routine, get_die_type_at_offset, from outside this file, and thus won't | |
17535 | necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life | |
17536 | of the objfile. */ | |
1c379e20 | 17537 | |
dee91e82 | 17538 | struct dwarf2_per_cu_offset_and_type |
1c379e20 | 17539 | { |
dee91e82 | 17540 | const struct dwarf2_per_cu_data *per_cu; |
b64f50a1 | 17541 | sect_offset offset; |
1c379e20 DJ |
17542 | struct type *type; |
17543 | }; | |
17544 | ||
dee91e82 | 17545 | /* Hash function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
17546 | |
17547 | static hashval_t | |
dee91e82 | 17548 | per_cu_offset_and_type_hash (const void *item) |
1c379e20 | 17549 | { |
dee91e82 | 17550 | const struct dwarf2_per_cu_offset_and_type *ofs = item; |
9a619af0 | 17551 | |
dee91e82 | 17552 | return (uintptr_t) ofs->per_cu + ofs->offset.sect_off; |
1c379e20 DJ |
17553 | } |
17554 | ||
dee91e82 | 17555 | /* Equality function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
17556 | |
17557 | static int | |
dee91e82 | 17558 | per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs) |
1c379e20 | 17559 | { |
dee91e82 DE |
17560 | const struct dwarf2_per_cu_offset_and_type *ofs_lhs = item_lhs; |
17561 | const struct dwarf2_per_cu_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 17562 | |
dee91e82 DE |
17563 | return (ofs_lhs->per_cu == ofs_rhs->per_cu |
17564 | && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off); | |
1c379e20 DJ |
17565 | } |
17566 | ||
17567 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
17568 | table if necessary. For convenience, return TYPE. |
17569 | ||
17570 | The DIEs reading must have careful ordering to: | |
17571 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
17572 | reading current DIE. | |
17573 | * Not trying to dereference contents of still incompletely read in types | |
17574 | while reading in other DIEs. | |
17575 | * Enable referencing still incompletely read in types just by a pointer to | |
17576 | the type without accessing its fields. | |
17577 | ||
17578 | Therefore caller should follow these rules: | |
17579 | * Try to fetch any prerequisite types we may need to build this DIE type | |
17580 | before building the type and calling set_die_type. | |
e71ec853 | 17581 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
17582 | possible before fetching more types to complete the current type. |
17583 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 17584 | |
f792889a | 17585 | static struct type * |
1c379e20 DJ |
17586 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
17587 | { | |
dee91e82 | 17588 | struct dwarf2_per_cu_offset_and_type **slot, ofs; |
673bfd45 | 17589 | struct objfile *objfile = cu->objfile; |
1c379e20 | 17590 | |
b4ba55a1 JB |
17591 | /* For Ada types, make sure that the gnat-specific data is always |
17592 | initialized (if not already set). There are a few types where | |
17593 | we should not be doing so, because the type-specific area is | |
17594 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
17595 | where the type-specific area is used to store the floatformat). | |
17596 | But this is not a problem, because the gnat-specific information | |
17597 | is actually not needed for these types. */ | |
17598 | if (need_gnat_info (cu) | |
17599 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
17600 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
17601 | && !HAVE_GNAT_AUX_INFO (type)) | |
17602 | INIT_GNAT_SPECIFIC (type); | |
17603 | ||
dee91e82 | 17604 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 17605 | { |
dee91e82 DE |
17606 | dwarf2_per_objfile->die_type_hash = |
17607 | htab_create_alloc_ex (127, | |
17608 | per_cu_offset_and_type_hash, | |
17609 | per_cu_offset_and_type_eq, | |
17610 | NULL, | |
17611 | &objfile->objfile_obstack, | |
17612 | hashtab_obstack_allocate, | |
17613 | dummy_obstack_deallocate); | |
f792889a | 17614 | } |
1c379e20 | 17615 | |
dee91e82 | 17616 | ofs.per_cu = cu->per_cu; |
1c379e20 DJ |
17617 | ofs.offset = die->offset; |
17618 | ofs.type = type; | |
dee91e82 DE |
17619 | slot = (struct dwarf2_per_cu_offset_and_type **) |
17620 | htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT); | |
7e314c57 JK |
17621 | if (*slot) |
17622 | complaint (&symfile_complaints, | |
17623 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
b64f50a1 | 17624 | die->offset.sect_off); |
673bfd45 | 17625 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 17626 | **slot = ofs; |
f792889a | 17627 | return type; |
1c379e20 DJ |
17628 | } |
17629 | ||
380bca97 | 17630 | /* Look up the type for the die at OFFSET in the appropriate type_hash |
673bfd45 | 17631 | table, or return NULL if the die does not have a saved type. */ |
1c379e20 DJ |
17632 | |
17633 | static struct type * | |
b64f50a1 | 17634 | get_die_type_at_offset (sect_offset offset, |
673bfd45 | 17635 | struct dwarf2_per_cu_data *per_cu) |
1c379e20 | 17636 | { |
dee91e82 | 17637 | struct dwarf2_per_cu_offset_and_type *slot, ofs; |
f792889a | 17638 | |
dee91e82 | 17639 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 17640 | return NULL; |
1c379e20 | 17641 | |
dee91e82 | 17642 | ofs.per_cu = per_cu; |
673bfd45 | 17643 | ofs.offset = offset; |
dee91e82 | 17644 | slot = htab_find (dwarf2_per_objfile->die_type_hash, &ofs); |
1c379e20 DJ |
17645 | if (slot) |
17646 | return slot->type; | |
17647 | else | |
17648 | return NULL; | |
17649 | } | |
17650 | ||
673bfd45 DE |
17651 | /* Look up the type for DIE in the appropriate type_hash table, |
17652 | or return NULL if DIE does not have a saved type. */ | |
17653 | ||
17654 | static struct type * | |
17655 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
17656 | { | |
17657 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
17658 | } | |
17659 | ||
10b3939b DJ |
17660 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
17661 | ||
17662 | static void | |
17663 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
17664 | struct dwarf2_per_cu_data *ref_per_cu) | |
17665 | { | |
17666 | void **slot; | |
17667 | ||
17668 | if (cu->dependencies == NULL) | |
17669 | cu->dependencies | |
17670 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
17671 | NULL, &cu->comp_unit_obstack, | |
17672 | hashtab_obstack_allocate, | |
17673 | dummy_obstack_deallocate); | |
17674 | ||
17675 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
17676 | if (*slot == NULL) | |
17677 | *slot = ref_per_cu; | |
17678 | } | |
1c379e20 | 17679 | |
f504f079 DE |
17680 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
17681 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
17682 | cache that we must keep because we are keeping CU. */ |
17683 | ||
10b3939b DJ |
17684 | static int |
17685 | dwarf2_mark_helper (void **slot, void *data) | |
17686 | { | |
17687 | struct dwarf2_per_cu_data *per_cu; | |
17688 | ||
17689 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
d07ed419 JK |
17690 | |
17691 | /* cu->dependencies references may not yet have been ever read if QUIT aborts | |
17692 | reading of the chain. As such dependencies remain valid it is not much | |
17693 | useful to track and undo them during QUIT cleanups. */ | |
17694 | if (per_cu->cu == NULL) | |
17695 | return 1; | |
17696 | ||
10b3939b DJ |
17697 | if (per_cu->cu->mark) |
17698 | return 1; | |
17699 | per_cu->cu->mark = 1; | |
17700 | ||
17701 | if (per_cu->cu->dependencies != NULL) | |
17702 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
17703 | ||
17704 | return 1; | |
17705 | } | |
17706 | ||
f504f079 DE |
17707 | /* Set the mark field in CU and in every other compilation unit in the |
17708 | cache that we must keep because we are keeping CU. */ | |
17709 | ||
ae038cb0 DJ |
17710 | static void |
17711 | dwarf2_mark (struct dwarf2_cu *cu) | |
17712 | { | |
17713 | if (cu->mark) | |
17714 | return; | |
17715 | cu->mark = 1; | |
10b3939b DJ |
17716 | if (cu->dependencies != NULL) |
17717 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
17718 | } |
17719 | ||
17720 | static void | |
17721 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
17722 | { | |
17723 | while (per_cu) | |
17724 | { | |
17725 | per_cu->cu->mark = 0; | |
17726 | per_cu = per_cu->cu->read_in_chain; | |
17727 | } | |
72bf9492 DJ |
17728 | } |
17729 | ||
72bf9492 DJ |
17730 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
17731 | is its offset in .debug_info for this objfile. */ | |
17732 | ||
17733 | static hashval_t | |
17734 | partial_die_hash (const void *item) | |
17735 | { | |
17736 | const struct partial_die_info *part_die = item; | |
9a619af0 | 17737 | |
b64f50a1 | 17738 | return part_die->offset.sect_off; |
72bf9492 DJ |
17739 | } |
17740 | ||
17741 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
17742 | are equal if they have the same offset. */ | |
17743 | ||
17744 | static int | |
17745 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
17746 | { | |
17747 | const struct partial_die_info *part_die_lhs = item_lhs; | |
17748 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 17749 | |
b64f50a1 | 17750 | return part_die_lhs->offset.sect_off == part_die_rhs->offset.sect_off; |
72bf9492 DJ |
17751 | } |
17752 | ||
ae038cb0 DJ |
17753 | static struct cmd_list_element *set_dwarf2_cmdlist; |
17754 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
17755 | ||
17756 | static void | |
17757 | set_dwarf2_cmd (char *args, int from_tty) | |
17758 | { | |
17759 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
17760 | } | |
17761 | ||
17762 | static void | |
17763 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 17764 | { |
ae038cb0 DJ |
17765 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
17766 | } | |
17767 | ||
dce234bc PP |
17768 | /* If section described by INFO was mmapped, munmap it now. */ |
17769 | ||
17770 | static void | |
17771 | munmap_section_buffer (struct dwarf2_section_info *info) | |
17772 | { | |
b315ab21 | 17773 | if (info->map_addr != NULL) |
dce234bc PP |
17774 | { |
17775 | #ifdef HAVE_MMAP | |
b315ab21 | 17776 | int res; |
9a619af0 | 17777 | |
b315ab21 TG |
17778 | res = munmap (info->map_addr, info->map_len); |
17779 | gdb_assert (res == 0); | |
dce234bc PP |
17780 | #else |
17781 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 17782 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
17783 | #endif |
17784 | } | |
17785 | } | |
17786 | ||
17787 | /* munmap debug sections for OBJFILE, if necessary. */ | |
17788 | ||
17789 | static void | |
c1bd65d0 | 17790 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
17791 | { |
17792 | struct dwarf2_per_objfile *data = d; | |
8b70b953 TT |
17793 | int ix; |
17794 | struct dwarf2_section_info *section; | |
9a619af0 | 17795 | |
16be1145 DE |
17796 | /* This is sorted according to the order they're defined in to make it easier |
17797 | to keep in sync. */ | |
dce234bc PP |
17798 | munmap_section_buffer (&data->info); |
17799 | munmap_section_buffer (&data->abbrev); | |
17800 | munmap_section_buffer (&data->line); | |
16be1145 | 17801 | munmap_section_buffer (&data->loc); |
dce234bc | 17802 | munmap_section_buffer (&data->macinfo); |
cf2c3c16 | 17803 | munmap_section_buffer (&data->macro); |
16be1145 | 17804 | munmap_section_buffer (&data->str); |
dce234bc | 17805 | munmap_section_buffer (&data->ranges); |
3019eac3 | 17806 | munmap_section_buffer (&data->addr); |
dce234bc PP |
17807 | munmap_section_buffer (&data->frame); |
17808 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd | 17809 | munmap_section_buffer (&data->gdb_index); |
8b70b953 TT |
17810 | |
17811 | for (ix = 0; | |
17812 | VEC_iterate (dwarf2_section_info_def, data->types, ix, section); | |
17813 | ++ix) | |
17814 | munmap_section_buffer (section); | |
17815 | ||
17816 | VEC_free (dwarf2_section_info_def, data->types); | |
3019eac3 DE |
17817 | |
17818 | if (data->dwo_files) | |
17819 | free_dwo_files (data->dwo_files, objfile); | |
9291a0cd TT |
17820 | } |
17821 | ||
17822 | \f | |
ae2de4f8 | 17823 | /* The "save gdb-index" command. */ |
9291a0cd TT |
17824 | |
17825 | /* The contents of the hash table we create when building the string | |
17826 | table. */ | |
17827 | struct strtab_entry | |
17828 | { | |
17829 | offset_type offset; | |
17830 | const char *str; | |
17831 | }; | |
17832 | ||
559a7a62 JK |
17833 | /* Hash function for a strtab_entry. |
17834 | ||
17835 | Function is used only during write_hash_table so no index format backward | |
17836 | compatibility is needed. */ | |
b89be57b | 17837 | |
9291a0cd TT |
17838 | static hashval_t |
17839 | hash_strtab_entry (const void *e) | |
17840 | { | |
17841 | const struct strtab_entry *entry = e; | |
559a7a62 | 17842 | return mapped_index_string_hash (INT_MAX, entry->str); |
9291a0cd TT |
17843 | } |
17844 | ||
17845 | /* Equality function for a strtab_entry. */ | |
b89be57b | 17846 | |
9291a0cd TT |
17847 | static int |
17848 | eq_strtab_entry (const void *a, const void *b) | |
17849 | { | |
17850 | const struct strtab_entry *ea = a; | |
17851 | const struct strtab_entry *eb = b; | |
17852 | return !strcmp (ea->str, eb->str); | |
17853 | } | |
17854 | ||
17855 | /* Create a strtab_entry hash table. */ | |
b89be57b | 17856 | |
9291a0cd TT |
17857 | static htab_t |
17858 | create_strtab (void) | |
17859 | { | |
17860 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
17861 | xfree, xcalloc, xfree); | |
17862 | } | |
17863 | ||
17864 | /* Add a string to the constant pool. Return the string's offset in | |
17865 | host order. */ | |
b89be57b | 17866 | |
9291a0cd TT |
17867 | static offset_type |
17868 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
17869 | { | |
17870 | void **slot; | |
17871 | struct strtab_entry entry; | |
17872 | struct strtab_entry *result; | |
17873 | ||
17874 | entry.str = str; | |
17875 | slot = htab_find_slot (table, &entry, INSERT); | |
17876 | if (*slot) | |
17877 | result = *slot; | |
17878 | else | |
17879 | { | |
17880 | result = XNEW (struct strtab_entry); | |
17881 | result->offset = obstack_object_size (cpool); | |
17882 | result->str = str; | |
17883 | obstack_grow_str0 (cpool, str); | |
17884 | *slot = result; | |
17885 | } | |
17886 | return result->offset; | |
17887 | } | |
17888 | ||
17889 | /* An entry in the symbol table. */ | |
17890 | struct symtab_index_entry | |
17891 | { | |
17892 | /* The name of the symbol. */ | |
17893 | const char *name; | |
17894 | /* The offset of the name in the constant pool. */ | |
17895 | offset_type index_offset; | |
17896 | /* A sorted vector of the indices of all the CUs that hold an object | |
17897 | of this name. */ | |
17898 | VEC (offset_type) *cu_indices; | |
17899 | }; | |
17900 | ||
17901 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
17902 | struct mapped_symtab | |
17903 | { | |
17904 | offset_type n_elements; | |
17905 | offset_type size; | |
17906 | struct symtab_index_entry **data; | |
17907 | }; | |
17908 | ||
17909 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 17910 | |
9291a0cd TT |
17911 | static hashval_t |
17912 | hash_symtab_entry (const void *e) | |
17913 | { | |
17914 | const struct symtab_index_entry *entry = e; | |
17915 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
17916 | sizeof (offset_type) * VEC_length (offset_type, | |
17917 | entry->cu_indices), | |
17918 | 0); | |
17919 | } | |
17920 | ||
17921 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 17922 | |
9291a0cd TT |
17923 | static int |
17924 | eq_symtab_entry (const void *a, const void *b) | |
17925 | { | |
17926 | const struct symtab_index_entry *ea = a; | |
17927 | const struct symtab_index_entry *eb = b; | |
17928 | int len = VEC_length (offset_type, ea->cu_indices); | |
17929 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
17930 | return 0; | |
17931 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
17932 | VEC_address (offset_type, eb->cu_indices), | |
17933 | sizeof (offset_type) * len); | |
17934 | } | |
17935 | ||
17936 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 17937 | |
9291a0cd TT |
17938 | static void |
17939 | delete_symtab_entry (void *p) | |
17940 | { | |
17941 | struct symtab_index_entry *entry = p; | |
17942 | VEC_free (offset_type, entry->cu_indices); | |
17943 | xfree (entry); | |
17944 | } | |
17945 | ||
17946 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 17947 | |
9291a0cd | 17948 | static htab_t |
3876f04e | 17949 | create_symbol_hash_table (void) |
9291a0cd TT |
17950 | { |
17951 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
17952 | delete_symtab_entry, xcalloc, xfree); | |
17953 | } | |
17954 | ||
17955 | /* Create a new mapped symtab object. */ | |
b89be57b | 17956 | |
9291a0cd TT |
17957 | static struct mapped_symtab * |
17958 | create_mapped_symtab (void) | |
17959 | { | |
17960 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
17961 | symtab->n_elements = 0; | |
17962 | symtab->size = 1024; | |
17963 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
17964 | return symtab; | |
17965 | } | |
17966 | ||
17967 | /* Destroy a mapped_symtab. */ | |
b89be57b | 17968 | |
9291a0cd TT |
17969 | static void |
17970 | cleanup_mapped_symtab (void *p) | |
17971 | { | |
17972 | struct mapped_symtab *symtab = p; | |
17973 | /* The contents of the array are freed when the other hash table is | |
17974 | destroyed. */ | |
17975 | xfree (symtab->data); | |
17976 | xfree (symtab); | |
17977 | } | |
17978 | ||
17979 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
559a7a62 JK |
17980 | the slot. |
17981 | ||
17982 | Function is used only during write_hash_table so no index format backward | |
17983 | compatibility is needed. */ | |
b89be57b | 17984 | |
9291a0cd TT |
17985 | static struct symtab_index_entry ** |
17986 | find_slot (struct mapped_symtab *symtab, const char *name) | |
17987 | { | |
559a7a62 | 17988 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd TT |
17989 | |
17990 | index = hash & (symtab->size - 1); | |
17991 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
17992 | ||
17993 | for (;;) | |
17994 | { | |
17995 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
17996 | return &symtab->data[index]; | |
17997 | index = (index + step) & (symtab->size - 1); | |
17998 | } | |
17999 | } | |
18000 | ||
18001 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 18002 | |
9291a0cd TT |
18003 | static void |
18004 | hash_expand (struct mapped_symtab *symtab) | |
18005 | { | |
18006 | offset_type old_size = symtab->size; | |
18007 | offset_type i; | |
18008 | struct symtab_index_entry **old_entries = symtab->data; | |
18009 | ||
18010 | symtab->size *= 2; | |
18011 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
18012 | ||
18013 | for (i = 0; i < old_size; ++i) | |
18014 | { | |
18015 | if (old_entries[i]) | |
18016 | { | |
18017 | struct symtab_index_entry **slot = find_slot (symtab, | |
18018 | old_entries[i]->name); | |
18019 | *slot = old_entries[i]; | |
18020 | } | |
18021 | } | |
18022 | ||
18023 | xfree (old_entries); | |
18024 | } | |
18025 | ||
18026 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
18027 | is the index of the CU in which the symbol appears. */ | |
b89be57b | 18028 | |
9291a0cd TT |
18029 | static void |
18030 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
18031 | offset_type cu_index) | |
18032 | { | |
18033 | struct symtab_index_entry **slot; | |
18034 | ||
18035 | ++symtab->n_elements; | |
18036 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
18037 | hash_expand (symtab); | |
18038 | ||
18039 | slot = find_slot (symtab, name); | |
18040 | if (!*slot) | |
18041 | { | |
18042 | *slot = XNEW (struct symtab_index_entry); | |
18043 | (*slot)->name = name; | |
18044 | (*slot)->cu_indices = NULL; | |
18045 | } | |
18046 | /* Don't push an index twice. Due to how we add entries we only | |
18047 | have to check the last one. */ | |
18048 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
cf31e6f9 | 18049 | || VEC_last (offset_type, (*slot)->cu_indices) != cu_index) |
9291a0cd TT |
18050 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); |
18051 | } | |
18052 | ||
18053 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 18054 | |
9291a0cd | 18055 | static offset_type |
3876f04e | 18056 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
18057 | struct symtab_index_entry *entry) |
18058 | { | |
18059 | void **slot; | |
18060 | ||
3876f04e | 18061 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
18062 | if (!*slot) |
18063 | { | |
18064 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
18065 | offset_type val = MAYBE_SWAP (len); | |
18066 | offset_type iter; | |
18067 | int i; | |
18068 | ||
18069 | *slot = entry; | |
18070 | entry->index_offset = obstack_object_size (cpool); | |
18071 | ||
18072 | obstack_grow (cpool, &val, sizeof (val)); | |
18073 | for (i = 0; | |
18074 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
18075 | ++i) | |
18076 | { | |
18077 | val = MAYBE_SWAP (iter); | |
18078 | obstack_grow (cpool, &val, sizeof (val)); | |
18079 | } | |
18080 | } | |
18081 | else | |
18082 | { | |
18083 | struct symtab_index_entry *old_entry = *slot; | |
18084 | entry->index_offset = old_entry->index_offset; | |
18085 | entry = old_entry; | |
18086 | } | |
18087 | return entry->index_offset; | |
18088 | } | |
18089 | ||
18090 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
18091 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 18092 | |
9291a0cd TT |
18093 | static void |
18094 | write_hash_table (struct mapped_symtab *symtab, | |
18095 | struct obstack *output, struct obstack *cpool) | |
18096 | { | |
18097 | offset_type i; | |
3876f04e | 18098 | htab_t symbol_hash_table; |
9291a0cd TT |
18099 | htab_t str_table; |
18100 | ||
3876f04e | 18101 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 18102 | str_table = create_strtab (); |
3876f04e | 18103 | |
9291a0cd TT |
18104 | /* We add all the index vectors to the constant pool first, to |
18105 | ensure alignment is ok. */ | |
18106 | for (i = 0; i < symtab->size; ++i) | |
18107 | { | |
18108 | if (symtab->data[i]) | |
3876f04e | 18109 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
18110 | } |
18111 | ||
18112 | /* Now write out the hash table. */ | |
18113 | for (i = 0; i < symtab->size; ++i) | |
18114 | { | |
18115 | offset_type str_off, vec_off; | |
18116 | ||
18117 | if (symtab->data[i]) | |
18118 | { | |
18119 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
18120 | vec_off = symtab->data[i]->index_offset; | |
18121 | } | |
18122 | else | |
18123 | { | |
18124 | /* While 0 is a valid constant pool index, it is not valid | |
18125 | to have 0 for both offsets. */ | |
18126 | str_off = 0; | |
18127 | vec_off = 0; | |
18128 | } | |
18129 | ||
18130 | str_off = MAYBE_SWAP (str_off); | |
18131 | vec_off = MAYBE_SWAP (vec_off); | |
18132 | ||
18133 | obstack_grow (output, &str_off, sizeof (str_off)); | |
18134 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
18135 | } | |
18136 | ||
18137 | htab_delete (str_table); | |
3876f04e | 18138 | htab_delete (symbol_hash_table); |
9291a0cd TT |
18139 | } |
18140 | ||
0a5429f6 DE |
18141 | /* Struct to map psymtab to CU index in the index file. */ |
18142 | struct psymtab_cu_index_map | |
18143 | { | |
18144 | struct partial_symtab *psymtab; | |
18145 | unsigned int cu_index; | |
18146 | }; | |
18147 | ||
18148 | static hashval_t | |
18149 | hash_psymtab_cu_index (const void *item) | |
18150 | { | |
18151 | const struct psymtab_cu_index_map *map = item; | |
18152 | ||
18153 | return htab_hash_pointer (map->psymtab); | |
18154 | } | |
18155 | ||
18156 | static int | |
18157 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
18158 | { | |
18159 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
18160 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
18161 | ||
18162 | return lhs->psymtab == rhs->psymtab; | |
18163 | } | |
18164 | ||
18165 | /* Helper struct for building the address table. */ | |
18166 | struct addrmap_index_data | |
18167 | { | |
18168 | struct objfile *objfile; | |
18169 | struct obstack *addr_obstack; | |
18170 | htab_t cu_index_htab; | |
18171 | ||
18172 | /* Non-zero if the previous_* fields are valid. | |
18173 | We can't write an entry until we see the next entry (since it is only then | |
18174 | that we know the end of the entry). */ | |
18175 | int previous_valid; | |
18176 | /* Index of the CU in the table of all CUs in the index file. */ | |
18177 | unsigned int previous_cu_index; | |
0963b4bd | 18178 | /* Start address of the CU. */ |
0a5429f6 DE |
18179 | CORE_ADDR previous_cu_start; |
18180 | }; | |
18181 | ||
18182 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 18183 | |
9291a0cd | 18184 | static void |
0a5429f6 DE |
18185 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
18186 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 18187 | { |
0a5429f6 | 18188 | offset_type cu_index_to_write; |
9291a0cd TT |
18189 | char addr[8]; |
18190 | CORE_ADDR baseaddr; | |
18191 | ||
18192 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
18193 | ||
0a5429f6 DE |
18194 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
18195 | obstack_grow (obstack, addr, 8); | |
18196 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
18197 | obstack_grow (obstack, addr, 8); | |
18198 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
18199 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
18200 | } | |
18201 | ||
18202 | /* Worker function for traversing an addrmap to build the address table. */ | |
18203 | ||
18204 | static int | |
18205 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
18206 | { | |
18207 | struct addrmap_index_data *data = datap; | |
18208 | struct partial_symtab *pst = obj; | |
18209 | offset_type cu_index; | |
18210 | void **slot; | |
18211 | ||
18212 | if (data->previous_valid) | |
18213 | add_address_entry (data->objfile, data->addr_obstack, | |
18214 | data->previous_cu_start, start_addr, | |
18215 | data->previous_cu_index); | |
18216 | ||
18217 | data->previous_cu_start = start_addr; | |
18218 | if (pst != NULL) | |
18219 | { | |
18220 | struct psymtab_cu_index_map find_map, *map; | |
18221 | find_map.psymtab = pst; | |
18222 | map = htab_find (data->cu_index_htab, &find_map); | |
18223 | gdb_assert (map != NULL); | |
18224 | data->previous_cu_index = map->cu_index; | |
18225 | data->previous_valid = 1; | |
18226 | } | |
18227 | else | |
18228 | data->previous_valid = 0; | |
18229 | ||
18230 | return 0; | |
18231 | } | |
18232 | ||
18233 | /* Write OBJFILE's address map to OBSTACK. | |
18234 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
18235 | in the index file. */ | |
18236 | ||
18237 | static void | |
18238 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
18239 | htab_t cu_index_htab) | |
18240 | { | |
18241 | struct addrmap_index_data addrmap_index_data; | |
18242 | ||
18243 | /* When writing the address table, we have to cope with the fact that | |
18244 | the addrmap iterator only provides the start of a region; we have to | |
18245 | wait until the next invocation to get the start of the next region. */ | |
18246 | ||
18247 | addrmap_index_data.objfile = objfile; | |
18248 | addrmap_index_data.addr_obstack = obstack; | |
18249 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
18250 | addrmap_index_data.previous_valid = 0; | |
18251 | ||
18252 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
18253 | &addrmap_index_data); | |
18254 | ||
18255 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
18256 | is valid, but we should still handle it. | |
18257 | The end address is recorded as the start of the next region, but that | |
18258 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
18259 | anyway. */ | |
18260 | if (addrmap_index_data.previous_valid) | |
18261 | add_address_entry (objfile, obstack, | |
18262 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
18263 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
18264 | } |
18265 | ||
18266 | /* Add a list of partial symbols to SYMTAB. */ | |
b89be57b | 18267 | |
9291a0cd TT |
18268 | static void |
18269 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 18270 | htab_t psyms_seen, |
9291a0cd TT |
18271 | struct partial_symbol **psymp, |
18272 | int count, | |
987d643c TT |
18273 | offset_type cu_index, |
18274 | int is_static) | |
9291a0cd TT |
18275 | { |
18276 | for (; count-- > 0; ++psymp) | |
18277 | { | |
987d643c TT |
18278 | void **slot, *lookup; |
18279 | ||
9291a0cd TT |
18280 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
18281 | error (_("Ada is not currently supported by the index")); | |
987d643c TT |
18282 | |
18283 | /* We only want to add a given psymbol once. However, we also | |
18284 | want to account for whether it is global or static. So, we | |
18285 | may add it twice, using slightly different values. */ | |
18286 | if (is_static) | |
18287 | { | |
18288 | uintptr_t val = 1 | (uintptr_t) *psymp; | |
18289 | ||
18290 | lookup = (void *) val; | |
18291 | } | |
18292 | else | |
18293 | lookup = *psymp; | |
18294 | ||
18295 | /* Only add a given psymbol once. */ | |
18296 | slot = htab_find_slot (psyms_seen, lookup, INSERT); | |
18297 | if (!*slot) | |
18298 | { | |
18299 | *slot = lookup; | |
bb2f58dc | 18300 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index); |
987d643c | 18301 | } |
9291a0cd TT |
18302 | } |
18303 | } | |
18304 | ||
18305 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
18306 | exception if there is an error. */ | |
b89be57b | 18307 | |
9291a0cd TT |
18308 | static void |
18309 | write_obstack (FILE *file, struct obstack *obstack) | |
18310 | { | |
18311 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
18312 | file) | |
18313 | != obstack_object_size (obstack)) | |
18314 | error (_("couldn't data write to file")); | |
18315 | } | |
18316 | ||
18317 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 18318 | |
9291a0cd TT |
18319 | static void |
18320 | unlink_if_set (void *p) | |
18321 | { | |
18322 | char **filename = p; | |
18323 | if (*filename) | |
18324 | unlink (*filename); | |
18325 | } | |
18326 | ||
1fd400ff TT |
18327 | /* A helper struct used when iterating over debug_types. */ |
18328 | struct signatured_type_index_data | |
18329 | { | |
18330 | struct objfile *objfile; | |
18331 | struct mapped_symtab *symtab; | |
18332 | struct obstack *types_list; | |
987d643c | 18333 | htab_t psyms_seen; |
1fd400ff TT |
18334 | int cu_index; |
18335 | }; | |
18336 | ||
18337 | /* A helper function that writes a single signatured_type to an | |
18338 | obstack. */ | |
b89be57b | 18339 | |
1fd400ff TT |
18340 | static int |
18341 | write_one_signatured_type (void **slot, void *d) | |
18342 | { | |
18343 | struct signatured_type_index_data *info = d; | |
18344 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
18345 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
18346 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
18347 | gdb_byte val[8]; |
18348 | ||
18349 | write_psymbols (info->symtab, | |
987d643c | 18350 | info->psyms_seen, |
3e43a32a MS |
18351 | info->objfile->global_psymbols.list |
18352 | + psymtab->globals_offset, | |
987d643c TT |
18353 | psymtab->n_global_syms, info->cu_index, |
18354 | 0); | |
1fd400ff | 18355 | write_psymbols (info->symtab, |
987d643c | 18356 | info->psyms_seen, |
3e43a32a MS |
18357 | info->objfile->static_psymbols.list |
18358 | + psymtab->statics_offset, | |
987d643c TT |
18359 | psymtab->n_static_syms, info->cu_index, |
18360 | 1); | |
1fd400ff | 18361 | |
b64f50a1 JK |
18362 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
18363 | entry->per_cu.offset.sect_off); | |
1fd400ff | 18364 | obstack_grow (info->types_list, val, 8); |
3019eac3 DE |
18365 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
18366 | entry->type_offset_in_tu.cu_off); | |
1fd400ff TT |
18367 | obstack_grow (info->types_list, val, 8); |
18368 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
18369 | obstack_grow (info->types_list, val, 8); | |
18370 | ||
18371 | ++info->cu_index; | |
18372 | ||
18373 | return 1; | |
18374 | } | |
18375 | ||
9291a0cd | 18376 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 18377 | |
9291a0cd TT |
18378 | static void |
18379 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
18380 | { | |
18381 | struct cleanup *cleanup; | |
18382 | char *filename, *cleanup_filename; | |
1fd400ff TT |
18383 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
18384 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
18385 | int i; |
18386 | FILE *out_file; | |
18387 | struct mapped_symtab *symtab; | |
18388 | offset_type val, size_of_contents, total_len; | |
18389 | struct stat st; | |
18390 | char buf[8]; | |
987d643c | 18391 | htab_t psyms_seen; |
0a5429f6 DE |
18392 | htab_t cu_index_htab; |
18393 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd | 18394 | |
b4f2f049 | 18395 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
9291a0cd | 18396 | return; |
b4f2f049 | 18397 | |
9291a0cd TT |
18398 | if (dwarf2_per_objfile->using_index) |
18399 | error (_("Cannot use an index to create the index")); | |
18400 | ||
8b70b953 TT |
18401 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
18402 | error (_("Cannot make an index when the file has multiple .debug_types sections")); | |
18403 | ||
9291a0cd | 18404 | if (stat (objfile->name, &st) < 0) |
7e17e088 | 18405 | perror_with_name (objfile->name); |
9291a0cd TT |
18406 | |
18407 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
18408 | INDEX_SUFFIX, (char *) NULL); | |
18409 | cleanup = make_cleanup (xfree, filename); | |
18410 | ||
18411 | out_file = fopen (filename, "wb"); | |
18412 | if (!out_file) | |
18413 | error (_("Can't open `%s' for writing"), filename); | |
18414 | ||
18415 | cleanup_filename = filename; | |
18416 | make_cleanup (unlink_if_set, &cleanup_filename); | |
18417 | ||
18418 | symtab = create_mapped_symtab (); | |
18419 | make_cleanup (cleanup_mapped_symtab, symtab); | |
18420 | ||
18421 | obstack_init (&addr_obstack); | |
18422 | make_cleanup_obstack_free (&addr_obstack); | |
18423 | ||
18424 | obstack_init (&cu_list); | |
18425 | make_cleanup_obstack_free (&cu_list); | |
18426 | ||
1fd400ff TT |
18427 | obstack_init (&types_cu_list); |
18428 | make_cleanup_obstack_free (&types_cu_list); | |
18429 | ||
987d643c TT |
18430 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
18431 | NULL, xcalloc, xfree); | |
96408a79 | 18432 | make_cleanup_htab_delete (psyms_seen); |
987d643c | 18433 | |
0a5429f6 DE |
18434 | /* While we're scanning CU's create a table that maps a psymtab pointer |
18435 | (which is what addrmap records) to its index (which is what is recorded | |
18436 | in the index file). This will later be needed to write the address | |
18437 | table. */ | |
18438 | cu_index_htab = htab_create_alloc (100, | |
18439 | hash_psymtab_cu_index, | |
18440 | eq_psymtab_cu_index, | |
18441 | NULL, xcalloc, xfree); | |
96408a79 | 18442 | make_cleanup_htab_delete (cu_index_htab); |
0a5429f6 DE |
18443 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
18444 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
18445 | * dwarf2_per_objfile->n_comp_units); | |
18446 | make_cleanup (xfree, psymtab_cu_index_map); | |
18447 | ||
18448 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
18449 | work here. Also, the debug_types entries do not appear in |
18450 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
18451 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
18452 | { | |
3e43a32a MS |
18453 | struct dwarf2_per_cu_data *per_cu |
18454 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 18455 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 18456 | gdb_byte val[8]; |
0a5429f6 DE |
18457 | struct psymtab_cu_index_map *map; |
18458 | void **slot; | |
9291a0cd TT |
18459 | |
18460 | write_psymbols (symtab, | |
987d643c | 18461 | psyms_seen, |
9291a0cd | 18462 | objfile->global_psymbols.list + psymtab->globals_offset, |
987d643c TT |
18463 | psymtab->n_global_syms, i, |
18464 | 0); | |
9291a0cd | 18465 | write_psymbols (symtab, |
987d643c | 18466 | psyms_seen, |
9291a0cd | 18467 | objfile->static_psymbols.list + psymtab->statics_offset, |
987d643c TT |
18468 | psymtab->n_static_syms, i, |
18469 | 1); | |
9291a0cd | 18470 | |
0a5429f6 DE |
18471 | map = &psymtab_cu_index_map[i]; |
18472 | map->psymtab = psymtab; | |
18473 | map->cu_index = i; | |
18474 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
18475 | gdb_assert (slot != NULL); | |
18476 | gdb_assert (*slot == NULL); | |
18477 | *slot = map; | |
9291a0cd | 18478 | |
b64f50a1 JK |
18479 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
18480 | per_cu->offset.sect_off); | |
9291a0cd | 18481 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 18482 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
18483 | obstack_grow (&cu_list, val, 8); |
18484 | } | |
18485 | ||
0a5429f6 DE |
18486 | /* Dump the address map. */ |
18487 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
18488 | ||
1fd400ff TT |
18489 | /* Write out the .debug_type entries, if any. */ |
18490 | if (dwarf2_per_objfile->signatured_types) | |
18491 | { | |
18492 | struct signatured_type_index_data sig_data; | |
18493 | ||
18494 | sig_data.objfile = objfile; | |
18495 | sig_data.symtab = symtab; | |
18496 | sig_data.types_list = &types_cu_list; | |
987d643c | 18497 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
18498 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
18499 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
18500 | write_one_signatured_type, &sig_data); | |
18501 | } | |
18502 | ||
9291a0cd TT |
18503 | obstack_init (&constant_pool); |
18504 | make_cleanup_obstack_free (&constant_pool); | |
18505 | obstack_init (&symtab_obstack); | |
18506 | make_cleanup_obstack_free (&symtab_obstack); | |
18507 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
18508 | ||
18509 | obstack_init (&contents); | |
18510 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 18511 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
18512 | total_len = size_of_contents; |
18513 | ||
18514 | /* The version number. */ | |
481860b3 | 18515 | val = MAYBE_SWAP (6); |
9291a0cd TT |
18516 | obstack_grow (&contents, &val, sizeof (val)); |
18517 | ||
18518 | /* The offset of the CU list from the start of the file. */ | |
18519 | val = MAYBE_SWAP (total_len); | |
18520 | obstack_grow (&contents, &val, sizeof (val)); | |
18521 | total_len += obstack_object_size (&cu_list); | |
18522 | ||
1fd400ff TT |
18523 | /* The offset of the types CU list from the start of the file. */ |
18524 | val = MAYBE_SWAP (total_len); | |
18525 | obstack_grow (&contents, &val, sizeof (val)); | |
18526 | total_len += obstack_object_size (&types_cu_list); | |
18527 | ||
9291a0cd TT |
18528 | /* The offset of the address table from the start of the file. */ |
18529 | val = MAYBE_SWAP (total_len); | |
18530 | obstack_grow (&contents, &val, sizeof (val)); | |
18531 | total_len += obstack_object_size (&addr_obstack); | |
18532 | ||
18533 | /* The offset of the symbol table from the start of the file. */ | |
18534 | val = MAYBE_SWAP (total_len); | |
18535 | obstack_grow (&contents, &val, sizeof (val)); | |
18536 | total_len += obstack_object_size (&symtab_obstack); | |
18537 | ||
18538 | /* The offset of the constant pool from the start of the file. */ | |
18539 | val = MAYBE_SWAP (total_len); | |
18540 | obstack_grow (&contents, &val, sizeof (val)); | |
18541 | total_len += obstack_object_size (&constant_pool); | |
18542 | ||
18543 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
18544 | ||
18545 | write_obstack (out_file, &contents); | |
18546 | write_obstack (out_file, &cu_list); | |
1fd400ff | 18547 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
18548 | write_obstack (out_file, &addr_obstack); |
18549 | write_obstack (out_file, &symtab_obstack); | |
18550 | write_obstack (out_file, &constant_pool); | |
18551 | ||
18552 | fclose (out_file); | |
18553 | ||
18554 | /* We want to keep the file, so we set cleanup_filename to NULL | |
18555 | here. See unlink_if_set. */ | |
18556 | cleanup_filename = NULL; | |
18557 | ||
18558 | do_cleanups (cleanup); | |
18559 | } | |
18560 | ||
90476074 TT |
18561 | /* Implementation of the `save gdb-index' command. |
18562 | ||
18563 | Note that the file format used by this command is documented in the | |
18564 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 18565 | |
9291a0cd TT |
18566 | static void |
18567 | save_gdb_index_command (char *arg, int from_tty) | |
18568 | { | |
18569 | struct objfile *objfile; | |
18570 | ||
18571 | if (!arg || !*arg) | |
96d19272 | 18572 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
18573 | |
18574 | ALL_OBJFILES (objfile) | |
18575 | { | |
18576 | struct stat st; | |
18577 | ||
18578 | /* If the objfile does not correspond to an actual file, skip it. */ | |
18579 | if (stat (objfile->name, &st) < 0) | |
18580 | continue; | |
18581 | ||
18582 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
18583 | if (dwarf2_per_objfile) | |
18584 | { | |
18585 | volatile struct gdb_exception except; | |
18586 | ||
18587 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
18588 | { | |
18589 | write_psymtabs_to_index (objfile, arg); | |
18590 | } | |
18591 | if (except.reason < 0) | |
18592 | exception_fprintf (gdb_stderr, except, | |
18593 | _("Error while writing index for `%s': "), | |
18594 | objfile->name); | |
18595 | } | |
18596 | } | |
dce234bc PP |
18597 | } |
18598 | ||
9291a0cd TT |
18599 | \f |
18600 | ||
9eae7c52 TT |
18601 | int dwarf2_always_disassemble; |
18602 | ||
18603 | static void | |
18604 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
18605 | struct cmd_list_element *c, const char *value) | |
18606 | { | |
3e43a32a MS |
18607 | fprintf_filtered (file, |
18608 | _("Whether to always disassemble " | |
18609 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
18610 | value); |
18611 | } | |
18612 | ||
900e11f9 JK |
18613 | static void |
18614 | show_check_physname (struct ui_file *file, int from_tty, | |
18615 | struct cmd_list_element *c, const char *value) | |
18616 | { | |
18617 | fprintf_filtered (file, | |
18618 | _("Whether to check \"physname\" is %s.\n"), | |
18619 | value); | |
18620 | } | |
18621 | ||
6502dd73 DJ |
18622 | void _initialize_dwarf2_read (void); |
18623 | ||
18624 | void | |
18625 | _initialize_dwarf2_read (void) | |
18626 | { | |
96d19272 JK |
18627 | struct cmd_list_element *c; |
18628 | ||
dce234bc | 18629 | dwarf2_objfile_data_key |
c1bd65d0 | 18630 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 18631 | |
1bedd215 AC |
18632 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
18633 | Set DWARF 2 specific variables.\n\ | |
18634 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
18635 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
18636 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
18637 | ||
1bedd215 AC |
18638 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
18639 | Show DWARF 2 specific variables\n\ | |
18640 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
18641 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
18642 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
18643 | ||
18644 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
18645 | &dwarf2_max_cache_age, _("\ |
18646 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
18647 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
18648 | A higher limit means that cached compilation units will be stored\n\ | |
18649 | in memory longer, and more total memory will be used. Zero disables\n\ | |
18650 | caching, which can slow down startup."), | |
2c5b56ce | 18651 | NULL, |
920d2a44 | 18652 | show_dwarf2_max_cache_age, |
2c5b56ce | 18653 | &set_dwarf2_cmdlist, |
ae038cb0 | 18654 | &show_dwarf2_cmdlist); |
d97bc12b | 18655 | |
9eae7c52 TT |
18656 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
18657 | &dwarf2_always_disassemble, _("\ | |
18658 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
18659 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
18660 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
18661 | syntax. When disabled, expressions will be printed in a more\n\ | |
18662 | conversational style, when possible."), | |
18663 | NULL, | |
18664 | show_dwarf2_always_disassemble, | |
18665 | &set_dwarf2_cmdlist, | |
18666 | &show_dwarf2_cmdlist); | |
18667 | ||
d97bc12b DE |
18668 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
18669 | Set debugging of the dwarf2 DIE reader."), _("\ | |
18670 | Show debugging of the dwarf2 DIE reader."), _("\ | |
18671 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
18672 | The value is the maximum depth to print."), | |
18673 | NULL, | |
18674 | NULL, | |
18675 | &setdebuglist, &showdebuglist); | |
9291a0cd | 18676 | |
900e11f9 JK |
18677 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
18678 | Set cross-checking of \"physname\" code against demangler."), _("\ | |
18679 | Show cross-checking of \"physname\" code against demangler."), _("\ | |
18680 | When enabled, GDB's internal \"physname\" code is checked against\n\ | |
18681 | the demangler."), | |
18682 | NULL, show_check_physname, | |
18683 | &setdebuglist, &showdebuglist); | |
18684 | ||
96d19272 | 18685 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 18686 | _("\ |
fc1a9d6e | 18687 | Save a gdb-index file.\n\ |
11570e71 | 18688 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
18689 | &save_cmdlist); |
18690 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 18691 | } |