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 PA |
61 | #include "c-lang.h" |
62 | #include "valprint.h" | |
60d5a603 | 63 | #include <ctype.h> |
4c2df51b | 64 | |
c906108c SS |
65 | #include <fcntl.h> |
66 | #include "gdb_string.h" | |
4bdf3d34 | 67 | #include "gdb_assert.h" |
c906108c | 68 | #include <sys/types.h> |
233a11ab CS |
69 | #ifdef HAVE_ZLIB_H |
70 | #include <zlib.h> | |
71 | #endif | |
dce234bc PP |
72 | #ifdef HAVE_MMAP |
73 | #include <sys/mman.h> | |
85d9bd0e TT |
74 | #ifndef MAP_FAILED |
75 | #define MAP_FAILED ((void *) -1) | |
76 | #endif | |
dce234bc | 77 | #endif |
d8151005 | 78 | |
34eaf542 TT |
79 | typedef struct symbol *symbolp; |
80 | DEF_VEC_P (symbolp); | |
81 | ||
d97bc12b DE |
82 | /* When non-zero, dump DIEs after they are read in. */ |
83 | static int dwarf2_die_debug = 0; | |
84 | ||
900e11f9 JK |
85 | /* When non-zero, cross-check physname against demangler. */ |
86 | static int check_physname = 0; | |
87 | ||
dce234bc PP |
88 | static int pagesize; |
89 | ||
df8a16a1 DJ |
90 | /* When set, the file that we're processing is known to have debugging |
91 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
92 | but later versions do. */ | |
93 | ||
94 | static int processing_has_namespace_info; | |
95 | ||
6502dd73 DJ |
96 | static const struct objfile_data *dwarf2_objfile_data_key; |
97 | ||
dce234bc PP |
98 | struct dwarf2_section_info |
99 | { | |
100 | asection *asection; | |
101 | gdb_byte *buffer; | |
102 | bfd_size_type size; | |
b315ab21 TG |
103 | /* Not NULL if the section was actually mmapped. */ |
104 | void *map_addr; | |
105 | /* Page aligned size of mmapped area. */ | |
106 | bfd_size_type map_len; | |
be391dca TT |
107 | /* True if we have tried to read this section. */ |
108 | int readin; | |
dce234bc PP |
109 | }; |
110 | ||
8b70b953 TT |
111 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
112 | DEF_VEC_O (dwarf2_section_info_def); | |
113 | ||
9291a0cd TT |
114 | /* All offsets in the index are of this type. It must be |
115 | architecture-independent. */ | |
116 | typedef uint32_t offset_type; | |
117 | ||
118 | DEF_VEC_I (offset_type); | |
119 | ||
120 | /* A description of the mapped index. The file format is described in | |
121 | a comment by the code that writes the index. */ | |
122 | struct mapped_index | |
123 | { | |
559a7a62 JK |
124 | /* Index data format version. */ |
125 | int version; | |
126 | ||
9291a0cd TT |
127 | /* The total length of the buffer. */ |
128 | off_t total_size; | |
b11b1f88 | 129 | |
9291a0cd TT |
130 | /* A pointer to the address table data. */ |
131 | const gdb_byte *address_table; | |
b11b1f88 | 132 | |
9291a0cd TT |
133 | /* Size of the address table data in bytes. */ |
134 | offset_type address_table_size; | |
b11b1f88 | 135 | |
3876f04e DE |
136 | /* The symbol table, implemented as a hash table. */ |
137 | const offset_type *symbol_table; | |
b11b1f88 | 138 | |
9291a0cd | 139 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 140 | offset_type symbol_table_slots; |
b11b1f88 | 141 | |
9291a0cd TT |
142 | /* A pointer to the constant pool. */ |
143 | const char *constant_pool; | |
144 | }; | |
145 | ||
9cdd5dbd DE |
146 | /* Collection of data recorded per objfile. |
147 | This hangs off of dwarf2_objfile_data_key. */ | |
148 | ||
6502dd73 DJ |
149 | struct dwarf2_per_objfile |
150 | { | |
dce234bc PP |
151 | struct dwarf2_section_info info; |
152 | struct dwarf2_section_info abbrev; | |
153 | struct dwarf2_section_info line; | |
dce234bc PP |
154 | struct dwarf2_section_info loc; |
155 | struct dwarf2_section_info macinfo; | |
cf2c3c16 | 156 | struct dwarf2_section_info macro; |
dce234bc PP |
157 | struct dwarf2_section_info str; |
158 | struct dwarf2_section_info ranges; | |
159 | struct dwarf2_section_info frame; | |
160 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 161 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 162 | |
8b70b953 TT |
163 | VEC (dwarf2_section_info_def) *types; |
164 | ||
be391dca TT |
165 | /* Back link. */ |
166 | struct objfile *objfile; | |
167 | ||
d467dd73 | 168 | /* Table of all the compilation units. This is used to locate |
10b3939b | 169 | the target compilation unit of a particular reference. */ |
ae038cb0 DJ |
170 | struct dwarf2_per_cu_data **all_comp_units; |
171 | ||
172 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
173 | int n_comp_units; | |
174 | ||
1fd400ff | 175 | /* The number of .debug_types-related CUs. */ |
d467dd73 | 176 | int n_type_units; |
1fd400ff | 177 | |
d467dd73 DE |
178 | /* The .debug_types-related CUs (TUs). */ |
179 | struct dwarf2_per_cu_data **all_type_units; | |
1fd400ff | 180 | |
ae038cb0 DJ |
181 | /* A chain of compilation units that are currently read in, so that |
182 | they can be freed later. */ | |
183 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 184 | |
348e048f DE |
185 | /* A table mapping .debug_types signatures to its signatured_type entry. |
186 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
187 | htab_t signatured_types; | |
188 | ||
72dca2f5 FR |
189 | /* A flag indicating wether this objfile has a section loaded at a |
190 | VMA of 0. */ | |
191 | int has_section_at_zero; | |
9291a0cd | 192 | |
ae2de4f8 DE |
193 | /* True if we are using the mapped index, |
194 | or we are faking it for OBJF_READNOW's sake. */ | |
9291a0cd TT |
195 | unsigned char using_index; |
196 | ||
ae2de4f8 | 197 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
9291a0cd | 198 | struct mapped_index *index_table; |
98bfdba5 | 199 | |
7b9f3c50 DE |
200 | /* When using index_table, this keeps track of all quick_file_names entries. |
201 | TUs can share line table entries with CUs or other TUs, and there can be | |
202 | a lot more TUs than unique line tables, so we maintain a separate table | |
203 | of all line table entries to support the sharing. */ | |
204 | htab_t quick_file_names_table; | |
205 | ||
98bfdba5 PA |
206 | /* Set during partial symbol reading, to prevent queueing of full |
207 | symbols. */ | |
208 | int reading_partial_symbols; | |
673bfd45 DE |
209 | |
210 | /* Table mapping type .debug_info DIE offsets to types. | |
211 | This is NULL if not allocated yet. | |
212 | It (currently) makes sense to allocate debug_types_type_hash lazily. | |
213 | To keep things simple we allocate both lazily. */ | |
214 | htab_t debug_info_type_hash; | |
215 | ||
216 | /* Table mapping type .debug_types DIE offsets to types. | |
217 | This is NULL if not allocated yet. */ | |
218 | htab_t debug_types_type_hash; | |
6502dd73 DJ |
219 | }; |
220 | ||
221 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 222 | |
251d32d9 | 223 | /* Default names of the debugging sections. */ |
c906108c | 224 | |
233a11ab CS |
225 | /* Note that if the debugging section has been compressed, it might |
226 | have a name like .zdebug_info. */ | |
227 | ||
9cdd5dbd DE |
228 | static const struct dwarf2_debug_sections dwarf2_elf_names = |
229 | { | |
251d32d9 TG |
230 | { ".debug_info", ".zdebug_info" }, |
231 | { ".debug_abbrev", ".zdebug_abbrev" }, | |
232 | { ".debug_line", ".zdebug_line" }, | |
233 | { ".debug_loc", ".zdebug_loc" }, | |
234 | { ".debug_macinfo", ".zdebug_macinfo" }, | |
cf2c3c16 | 235 | { ".debug_macro", ".zdebug_macro" }, |
251d32d9 TG |
236 | { ".debug_str", ".zdebug_str" }, |
237 | { ".debug_ranges", ".zdebug_ranges" }, | |
238 | { ".debug_types", ".zdebug_types" }, | |
239 | { ".debug_frame", ".zdebug_frame" }, | |
240 | { ".eh_frame", NULL }, | |
24d3216f TT |
241 | { ".gdb_index", ".zgdb_index" }, |
242 | 23 | |
251d32d9 | 243 | }; |
c906108c SS |
244 | |
245 | /* local data types */ | |
246 | ||
0963b4bd | 247 | /* We hold several abbreviation tables in memory at the same time. */ |
57349743 JB |
248 | #ifndef ABBREV_HASH_SIZE |
249 | #define ABBREV_HASH_SIZE 121 | |
250 | #endif | |
251 | ||
107d2387 AC |
252 | /* The data in a compilation unit header, after target2host |
253 | translation, looks like this. */ | |
c906108c | 254 | struct comp_unit_head |
a738430d | 255 | { |
c764a876 | 256 | unsigned int length; |
a738430d | 257 | short version; |
a738430d MK |
258 | unsigned char addr_size; |
259 | unsigned char signed_addr_p; | |
9cbfa09e | 260 | unsigned int abbrev_offset; |
57349743 | 261 | |
a738430d MK |
262 | /* Size of file offsets; either 4 or 8. */ |
263 | unsigned int offset_size; | |
57349743 | 264 | |
a738430d MK |
265 | /* Size of the length field; either 4 or 12. */ |
266 | unsigned int initial_length_size; | |
57349743 | 267 | |
a738430d MK |
268 | /* Offset to the first byte of this compilation unit header in the |
269 | .debug_info section, for resolving relative reference dies. */ | |
270 | unsigned int offset; | |
57349743 | 271 | |
d00adf39 DE |
272 | /* Offset to first die in this cu from the start of the cu. |
273 | This will be the first byte following the compilation unit header. */ | |
274 | unsigned int first_die_offset; | |
a738430d | 275 | }; |
c906108c | 276 | |
3da10d80 KS |
277 | /* Type used for delaying computation of method physnames. |
278 | See comments for compute_delayed_physnames. */ | |
279 | struct delayed_method_info | |
280 | { | |
281 | /* The type to which the method is attached, i.e., its parent class. */ | |
282 | struct type *type; | |
283 | ||
284 | /* The index of the method in the type's function fieldlists. */ | |
285 | int fnfield_index; | |
286 | ||
287 | /* The index of the method in the fieldlist. */ | |
288 | int index; | |
289 | ||
290 | /* The name of the DIE. */ | |
291 | const char *name; | |
292 | ||
293 | /* The DIE associated with this method. */ | |
294 | struct die_info *die; | |
295 | }; | |
296 | ||
297 | typedef struct delayed_method_info delayed_method_info; | |
298 | DEF_VEC_O (delayed_method_info); | |
299 | ||
e7c27a73 DJ |
300 | /* Internal state when decoding a particular compilation unit. */ |
301 | struct dwarf2_cu | |
302 | { | |
303 | /* The objfile containing this compilation unit. */ | |
304 | struct objfile *objfile; | |
305 | ||
d00adf39 | 306 | /* The header of the compilation unit. */ |
e7c27a73 | 307 | struct comp_unit_head header; |
e142c38c | 308 | |
d00adf39 DE |
309 | /* Base address of this compilation unit. */ |
310 | CORE_ADDR base_address; | |
311 | ||
312 | /* Non-zero if base_address has been set. */ | |
313 | int base_known; | |
314 | ||
e142c38c DJ |
315 | /* The language we are debugging. */ |
316 | enum language language; | |
317 | const struct language_defn *language_defn; | |
318 | ||
b0f35d58 DL |
319 | const char *producer; |
320 | ||
e142c38c DJ |
321 | /* The generic symbol table building routines have separate lists for |
322 | file scope symbols and all all other scopes (local scopes). So | |
323 | we need to select the right one to pass to add_symbol_to_list(). | |
324 | We do it by keeping a pointer to the correct list in list_in_scope. | |
325 | ||
326 | FIXME: The original dwarf code just treated the file scope as the | |
327 | first local scope, and all other local scopes as nested local | |
328 | scopes, and worked fine. Check to see if we really need to | |
329 | distinguish these in buildsym.c. */ | |
330 | struct pending **list_in_scope; | |
331 | ||
f3dd6933 DJ |
332 | /* DWARF abbreviation table associated with this compilation unit. */ |
333 | struct abbrev_info **dwarf2_abbrevs; | |
334 | ||
335 | /* Storage for the abbrev table. */ | |
336 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
337 | |
338 | /* Hash table holding all the loaded partial DIEs. */ | |
339 | htab_t partial_dies; | |
340 | ||
341 | /* Storage for things with the same lifetime as this read-in compilation | |
342 | unit, including partial DIEs. */ | |
343 | struct obstack comp_unit_obstack; | |
344 | ||
ae038cb0 DJ |
345 | /* When multiple dwarf2_cu structures are living in memory, this field |
346 | chains them all together, so that they can be released efficiently. | |
347 | We will probably also want a generation counter so that most-recently-used | |
348 | compilation units are cached... */ | |
349 | struct dwarf2_per_cu_data *read_in_chain; | |
350 | ||
351 | /* Backchain to our per_cu entry if the tree has been built. */ | |
352 | struct dwarf2_per_cu_data *per_cu; | |
353 | ||
354 | /* How many compilation units ago was this CU last referenced? */ | |
355 | int last_used; | |
356 | ||
10b3939b | 357 | /* A hash table of die offsets for following references. */ |
51545339 | 358 | htab_t die_hash; |
10b3939b DJ |
359 | |
360 | /* Full DIEs if read in. */ | |
361 | struct die_info *dies; | |
362 | ||
363 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
364 | units referenced by this one. Only set during full symbol processing; | |
365 | partial symbol tables do not have dependencies. */ | |
366 | htab_t dependencies; | |
367 | ||
cb1df416 DJ |
368 | /* Header data from the line table, during full symbol processing. */ |
369 | struct line_header *line_header; | |
370 | ||
3da10d80 KS |
371 | /* A list of methods which need to have physnames computed |
372 | after all type information has been read. */ | |
373 | VEC (delayed_method_info) *method_list; | |
374 | ||
96408a79 SA |
375 | /* To be copied to symtab->call_site_htab. */ |
376 | htab_t call_site_htab; | |
377 | ||
ae038cb0 DJ |
378 | /* Mark used when releasing cached dies. */ |
379 | unsigned int mark : 1; | |
380 | ||
8be455d7 JK |
381 | /* This CU references .debug_loc. See the symtab->locations_valid field. |
382 | This test is imperfect as there may exist optimized debug code not using | |
383 | any location list and still facing inlining issues if handled as | |
384 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
8be455d7 | 385 | unsigned int has_loclist : 1; |
e7c27a73 DJ |
386 | }; |
387 | ||
10b3939b DJ |
388 | /* Persistent data held for a compilation unit, even when not |
389 | processing it. We put a pointer to this structure in the | |
28dee7f5 | 390 | read_symtab_private field of the psymtab. */ |
10b3939b | 391 | |
ae038cb0 DJ |
392 | struct dwarf2_per_cu_data |
393 | { | |
348e048f | 394 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 395 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
396 | - if it doesn't, GDB will fall over anyway. |
397 | NOTE: Unlike comp_unit_head.length, this length includes | |
398 | initial_length_size. */ | |
c764a876 | 399 | unsigned int offset; |
348e048f | 400 | unsigned int length : 29; |
ae038cb0 DJ |
401 | |
402 | /* Flag indicating this compilation unit will be read in before | |
403 | any of the current compilation units are processed. */ | |
c764a876 | 404 | unsigned int queued : 1; |
ae038cb0 | 405 | |
5afb4e99 DJ |
406 | /* This flag will be set if we need to load absolutely all DIEs |
407 | for this compilation unit, instead of just the ones we think | |
408 | are interesting. It gets set if we look for a DIE in the | |
409 | hash table and don't find it. */ | |
410 | unsigned int load_all_dies : 1; | |
411 | ||
8b70b953 TT |
412 | /* Non-null if this CU is from .debug_types; in which case it points |
413 | to the section. Otherwise it's from .debug_info. */ | |
b0df02fd | 414 | struct dwarf2_section_info *debug_types_section; |
348e048f | 415 | |
17ea53c3 JK |
416 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
417 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 418 | struct dwarf2_cu *cu; |
1c379e20 | 419 | |
9cdd5dbd DE |
420 | /* The corresponding objfile. |
421 | Normally we can get the objfile from dwarf2_per_objfile. | |
422 | However we can enter this file with just a "per_cu" handle. */ | |
9291a0cd TT |
423 | struct objfile *objfile; |
424 | ||
425 | /* When using partial symbol tables, the 'psymtab' field is active. | |
426 | Otherwise the 'quick' field is active. */ | |
427 | union | |
428 | { | |
429 | /* The partial symbol table associated with this compilation unit, | |
430 | or NULL for partial units (which do not have an associated | |
431 | symtab). */ | |
432 | struct partial_symtab *psymtab; | |
433 | ||
434 | /* Data needed by the "quick" functions. */ | |
435 | struct dwarf2_per_cu_quick_data *quick; | |
436 | } v; | |
ae038cb0 DJ |
437 | }; |
438 | ||
348e048f DE |
439 | /* Entry in the signatured_types hash table. */ |
440 | ||
441 | struct signatured_type | |
442 | { | |
443 | ULONGEST signature; | |
444 | ||
348e048f DE |
445 | /* Offset in .debug_types of the type defined by this TU. */ |
446 | unsigned int type_offset; | |
447 | ||
448 | /* The CU(/TU) of this type. */ | |
449 | struct dwarf2_per_cu_data per_cu; | |
450 | }; | |
451 | ||
0963b4bd MS |
452 | /* Struct used to pass misc. parameters to read_die_and_children, et |
453 | al. which are used for both .debug_info and .debug_types dies. | |
454 | All parameters here are unchanging for the life of the call. This | |
455 | struct exists to abstract away the constant parameters of die | |
456 | reading. */ | |
93311388 DE |
457 | |
458 | struct die_reader_specs | |
459 | { | |
460 | /* The bfd of this objfile. */ | |
461 | bfd* abfd; | |
462 | ||
463 | /* The CU of the DIE we are parsing. */ | |
464 | struct dwarf2_cu *cu; | |
465 | ||
466 | /* Pointer to start of section buffer. | |
467 | This is either the start of .debug_info or .debug_types. */ | |
468 | const gdb_byte *buffer; | |
469 | }; | |
470 | ||
debd256d JB |
471 | /* The line number information for a compilation unit (found in the |
472 | .debug_line section) begins with a "statement program header", | |
473 | which contains the following information. */ | |
474 | struct line_header | |
475 | { | |
476 | unsigned int total_length; | |
477 | unsigned short version; | |
478 | unsigned int header_length; | |
479 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 480 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
481 | unsigned char default_is_stmt; |
482 | int line_base; | |
483 | unsigned char line_range; | |
484 | unsigned char opcode_base; | |
485 | ||
486 | /* standard_opcode_lengths[i] is the number of operands for the | |
487 | standard opcode whose value is i. This means that | |
488 | standard_opcode_lengths[0] is unused, and the last meaningful | |
489 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
490 | unsigned char *standard_opcode_lengths; | |
491 | ||
492 | /* The include_directories table. NOTE! These strings are not | |
493 | allocated with xmalloc; instead, they are pointers into | |
494 | debug_line_buffer. If you try to free them, `free' will get | |
495 | indigestion. */ | |
496 | unsigned int num_include_dirs, include_dirs_size; | |
497 | char **include_dirs; | |
498 | ||
499 | /* The file_names table. NOTE! These strings are not allocated | |
500 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
501 | Don't try to free them directly. */ | |
502 | unsigned int num_file_names, file_names_size; | |
503 | struct file_entry | |
c906108c | 504 | { |
debd256d JB |
505 | char *name; |
506 | unsigned int dir_index; | |
507 | unsigned int mod_time; | |
508 | unsigned int length; | |
aaa75496 | 509 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 510 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
511 | } *file_names; |
512 | ||
513 | /* The start and end of the statement program following this | |
6502dd73 | 514 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 515 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 516 | }; |
c906108c SS |
517 | |
518 | /* When we construct a partial symbol table entry we only | |
0963b4bd | 519 | need this much information. */ |
c906108c SS |
520 | struct partial_die_info |
521 | { | |
72bf9492 | 522 | /* Offset of this DIE. */ |
c906108c | 523 | unsigned int offset; |
72bf9492 DJ |
524 | |
525 | /* DWARF-2 tag for this DIE. */ | |
526 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
527 | ||
72bf9492 DJ |
528 | /* Assorted flags describing the data found in this DIE. */ |
529 | unsigned int has_children : 1; | |
530 | unsigned int is_external : 1; | |
531 | unsigned int is_declaration : 1; | |
532 | unsigned int has_type : 1; | |
533 | unsigned int has_specification : 1; | |
534 | unsigned int has_pc_info : 1; | |
535 | ||
536 | /* Flag set if the SCOPE field of this structure has been | |
537 | computed. */ | |
538 | unsigned int scope_set : 1; | |
539 | ||
fa4028e9 JB |
540 | /* Flag set if the DIE has a byte_size attribute. */ |
541 | unsigned int has_byte_size : 1; | |
542 | ||
98bfdba5 PA |
543 | /* Flag set if any of the DIE's children are template arguments. */ |
544 | unsigned int has_template_arguments : 1; | |
545 | ||
abc72ce4 DE |
546 | /* Flag set if fixup_partial_die has been called on this die. */ |
547 | unsigned int fixup_called : 1; | |
548 | ||
72bf9492 | 549 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 550 | sometimes a default name for unnamed DIEs. */ |
c906108c | 551 | char *name; |
72bf9492 | 552 | |
abc72ce4 DE |
553 | /* The linkage name, if present. */ |
554 | const char *linkage_name; | |
555 | ||
72bf9492 DJ |
556 | /* The scope to prepend to our children. This is generally |
557 | allocated on the comp_unit_obstack, so will disappear | |
558 | when this compilation unit leaves the cache. */ | |
559 | char *scope; | |
560 | ||
561 | /* The location description associated with this DIE, if any. */ | |
562 | struct dwarf_block *locdesc; | |
563 | ||
564 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
565 | CORE_ADDR lowpc; |
566 | CORE_ADDR highpc; | |
72bf9492 | 567 | |
93311388 | 568 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 569 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
570 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
571 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
fe1b8b76 | 572 | gdb_byte *sibling; |
72bf9492 DJ |
573 | |
574 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
575 | DW_AT_specification (or DW_AT_abstract_origin or | |
576 | DW_AT_extension). */ | |
577 | unsigned int spec_offset; | |
578 | ||
579 | /* Pointers to this DIE's parent, first child, and next sibling, | |
580 | if any. */ | |
581 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
582 | }; |
583 | ||
0963b4bd | 584 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
585 | struct abbrev_info |
586 | { | |
587 | unsigned int number; /* number identifying abbrev */ | |
588 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
589 | unsigned short has_children; /* boolean */ |
590 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
591 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
592 | struct abbrev_info *next; /* next in chain */ | |
593 | }; | |
594 | ||
595 | struct attr_abbrev | |
596 | { | |
9d25dd43 DE |
597 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
598 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
599 | }; |
600 | ||
0963b4bd | 601 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
602 | struct attribute |
603 | { | |
9d25dd43 | 604 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
605 | ENUM_BITFIELD(dwarf_form) form : 15; |
606 | ||
607 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
608 | field should be in u.str (existing only for DW_STRING) but it is kept | |
609 | here for better struct attribute alignment. */ | |
610 | unsigned int string_is_canonical : 1; | |
611 | ||
b60c80d6 DJ |
612 | union |
613 | { | |
614 | char *str; | |
615 | struct dwarf_block *blk; | |
43bbcdc2 PH |
616 | ULONGEST unsnd; |
617 | LONGEST snd; | |
b60c80d6 | 618 | CORE_ADDR addr; |
348e048f | 619 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
620 | } |
621 | u; | |
622 | }; | |
623 | ||
0963b4bd | 624 | /* This data structure holds a complete die structure. */ |
c906108c SS |
625 | struct die_info |
626 | { | |
76815b17 DE |
627 | /* DWARF-2 tag for this DIE. */ |
628 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
629 | ||
630 | /* Number of attributes */ | |
98bfdba5 PA |
631 | unsigned char num_attrs; |
632 | ||
633 | /* True if we're presently building the full type name for the | |
634 | type derived from this DIE. */ | |
635 | unsigned char building_fullname : 1; | |
76815b17 DE |
636 | |
637 | /* Abbrev number */ | |
638 | unsigned int abbrev; | |
639 | ||
93311388 | 640 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 641 | unsigned int offset; |
78ba4af6 JB |
642 | |
643 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
644 | points to this die's parent; CHILD points to the first child of | |
645 | this node; and all the children of a given node are chained | |
4950bc1c | 646 | together via their SIBLING fields. */ |
639d11d3 DC |
647 | struct die_info *child; /* Its first child, if any. */ |
648 | struct die_info *sibling; /* Its next sibling, if any. */ | |
649 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 650 | |
b60c80d6 DJ |
651 | /* An array of attributes, with NUM_ATTRS elements. There may be |
652 | zero, but it's not common and zero-sized arrays are not | |
653 | sufficiently portable C. */ | |
654 | struct attribute attrs[1]; | |
c906108c SS |
655 | }; |
656 | ||
0963b4bd | 657 | /* Get at parts of an attribute structure. */ |
c906108c SS |
658 | |
659 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 660 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
661 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
662 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
663 | #define DW_SND(attr) ((attr)->u.snd) | |
664 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 665 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c | 666 | |
0963b4bd | 667 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
668 | struct dwarf_block |
669 | { | |
670 | unsigned int size; | |
1d6edc3c JK |
671 | |
672 | /* Valid only if SIZE is not zero. */ | |
fe1b8b76 | 673 | gdb_byte *data; |
c906108c SS |
674 | }; |
675 | ||
c906108c SS |
676 | #ifndef ATTR_ALLOC_CHUNK |
677 | #define ATTR_ALLOC_CHUNK 4 | |
678 | #endif | |
679 | ||
c906108c SS |
680 | /* Allocate fields for structs, unions and enums in this size. */ |
681 | #ifndef DW_FIELD_ALLOC_CHUNK | |
682 | #define DW_FIELD_ALLOC_CHUNK 4 | |
683 | #endif | |
684 | ||
c906108c SS |
685 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
686 | but this would require a corresponding change in unpack_field_as_long | |
687 | and friends. */ | |
688 | static int bits_per_byte = 8; | |
689 | ||
690 | /* The routines that read and process dies for a C struct or C++ class | |
691 | pass lists of data member fields and lists of member function fields | |
692 | in an instance of a field_info structure, as defined below. */ | |
693 | struct field_info | |
c5aa993b | 694 | { |
0963b4bd | 695 | /* List of data member and baseclasses fields. */ |
c5aa993b JM |
696 | struct nextfield |
697 | { | |
698 | struct nextfield *next; | |
699 | int accessibility; | |
700 | int virtuality; | |
701 | struct field field; | |
702 | } | |
7d0ccb61 | 703 | *fields, *baseclasses; |
c906108c | 704 | |
7d0ccb61 | 705 | /* Number of fields (including baseclasses). */ |
c5aa993b | 706 | int nfields; |
c906108c | 707 | |
c5aa993b JM |
708 | /* Number of baseclasses. */ |
709 | int nbaseclasses; | |
c906108c | 710 | |
c5aa993b JM |
711 | /* Set if the accesibility of one of the fields is not public. */ |
712 | int non_public_fields; | |
c906108c | 713 | |
c5aa993b JM |
714 | /* Member function fields array, entries are allocated in the order they |
715 | are encountered in the object file. */ | |
716 | struct nextfnfield | |
717 | { | |
718 | struct nextfnfield *next; | |
719 | struct fn_field fnfield; | |
720 | } | |
721 | *fnfields; | |
c906108c | 722 | |
c5aa993b JM |
723 | /* Member function fieldlist array, contains name of possibly overloaded |
724 | member function, number of overloaded member functions and a pointer | |
725 | to the head of the member function field chain. */ | |
726 | struct fnfieldlist | |
727 | { | |
728 | char *name; | |
729 | int length; | |
730 | struct nextfnfield *head; | |
731 | } | |
732 | *fnfieldlists; | |
c906108c | 733 | |
c5aa993b JM |
734 | /* Number of entries in the fnfieldlists array. */ |
735 | int nfnfields; | |
98751a41 JK |
736 | |
737 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
738 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
739 | struct typedef_field_list | |
740 | { | |
741 | struct typedef_field field; | |
742 | struct typedef_field_list *next; | |
743 | } | |
744 | *typedef_field_list; | |
745 | unsigned typedef_field_list_count; | |
c5aa993b | 746 | }; |
c906108c | 747 | |
10b3939b DJ |
748 | /* One item on the queue of compilation units to read in full symbols |
749 | for. */ | |
750 | struct dwarf2_queue_item | |
751 | { | |
752 | struct dwarf2_per_cu_data *per_cu; | |
753 | struct dwarf2_queue_item *next; | |
754 | }; | |
755 | ||
756 | /* The current queue. */ | |
757 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
758 | ||
ae038cb0 DJ |
759 | /* Loaded secondary compilation units are kept in memory until they |
760 | have not been referenced for the processing of this many | |
761 | compilation units. Set this to zero to disable caching. Cache | |
762 | sizes of up to at least twenty will improve startup time for | |
763 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
764 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
765 | static void |
766 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
767 | struct cmd_list_element *c, const char *value) | |
768 | { | |
3e43a32a MS |
769 | fprintf_filtered (file, _("The upper bound on the age of cached " |
770 | "dwarf2 compilation units is %s.\n"), | |
920d2a44 AC |
771 | value); |
772 | } | |
773 | ||
ae038cb0 | 774 | |
0963b4bd | 775 | /* Various complaints about symbol reading that don't abort the process. */ |
c906108c | 776 | |
4d3c2250 KB |
777 | static void |
778 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 779 | { |
4d3c2250 | 780 | complaint (&symfile_complaints, |
e2e0b3e5 | 781 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
782 | } |
783 | ||
25e43795 DJ |
784 | static void |
785 | dwarf2_debug_line_missing_file_complaint (void) | |
786 | { | |
787 | complaint (&symfile_complaints, | |
788 | _(".debug_line section has line data without a file")); | |
789 | } | |
790 | ||
59205f5a JB |
791 | static void |
792 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
793 | { | |
794 | complaint (&symfile_complaints, | |
3e43a32a MS |
795 | _(".debug_line section has line " |
796 | "program sequence without an end")); | |
59205f5a JB |
797 | } |
798 | ||
4d3c2250 KB |
799 | static void |
800 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 801 | { |
e2e0b3e5 | 802 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
803 | } |
804 | ||
4d3c2250 KB |
805 | static void |
806 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
807 | int arg3) | |
2e276125 | 808 | { |
4d3c2250 | 809 | complaint (&symfile_complaints, |
3e43a32a MS |
810 | _("const value length mismatch for '%s', got %d, expected %d"), |
811 | arg1, arg2, arg3); | |
4d3c2250 KB |
812 | } |
813 | ||
814 | static void | |
cf2c3c16 | 815 | dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section) |
2e276125 | 816 | { |
4d3c2250 | 817 | complaint (&symfile_complaints, |
cf2c3c16 TT |
818 | _("macro info runs off end of `%s' section"), |
819 | section->asection->name); | |
4d3c2250 KB |
820 | } |
821 | ||
822 | static void | |
823 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 824 | { |
4d3c2250 | 825 | complaint (&symfile_complaints, |
3e43a32a MS |
826 | _("macro debug info contains a " |
827 | "malformed macro definition:\n`%s'"), | |
4d3c2250 KB |
828 | arg1); |
829 | } | |
830 | ||
831 | static void | |
832 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 833 | { |
4d3c2250 | 834 | complaint (&symfile_complaints, |
3e43a32a MS |
835 | _("invalid attribute class or form for '%s' in '%s'"), |
836 | arg1, arg2); | |
4d3c2250 | 837 | } |
c906108c | 838 | |
c906108c SS |
839 | /* local function prototypes */ |
840 | ||
4efb68b1 | 841 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 842 | |
aaa75496 JB |
843 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
844 | struct objfile *); | |
845 | ||
918dd910 JK |
846 | static void dwarf2_find_base_address (struct die_info *die, |
847 | struct dwarf2_cu *cu); | |
848 | ||
c67a9c90 | 849 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 850 | |
72bf9492 DJ |
851 | static void scan_partial_symbols (struct partial_die_info *, |
852 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 853 | int, struct dwarf2_cu *); |
c906108c | 854 | |
72bf9492 DJ |
855 | static void add_partial_symbol (struct partial_die_info *, |
856 | struct dwarf2_cu *); | |
63d06c5c | 857 | |
72bf9492 DJ |
858 | static void add_partial_namespace (struct partial_die_info *pdi, |
859 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 860 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 861 | |
5d7cb8df JK |
862 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
863 | CORE_ADDR *highpc, int need_pc, | |
864 | struct dwarf2_cu *cu); | |
865 | ||
72bf9492 DJ |
866 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
867 | struct dwarf2_cu *cu); | |
91c24f0a | 868 | |
bc30ff58 JB |
869 | static void add_partial_subprogram (struct partial_die_info *pdi, |
870 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 871 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 872 | |
fe1b8b76 | 873 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
874 | gdb_byte *buffer, gdb_byte *info_ptr, |
875 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 876 | |
a14ed312 | 877 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 878 | |
a14ed312 | 879 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 880 | |
e5fe5e75 | 881 | static void dwarf2_read_abbrevs (struct dwarf2_cu *cu); |
c906108c | 882 | |
f3dd6933 | 883 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 884 | |
6caca83c CC |
885 | static unsigned int peek_abbrev_code (bfd *, gdb_byte *); |
886 | ||
fe1b8b76 | 887 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 888 | struct dwarf2_cu *); |
72bf9492 | 889 | |
57349743 | 890 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 891 | struct dwarf2_cu *); |
c906108c | 892 | |
93311388 DE |
893 | static struct partial_die_info *load_partial_dies (bfd *, |
894 | gdb_byte *, gdb_byte *, | |
895 | int, struct dwarf2_cu *); | |
72bf9492 | 896 | |
fe1b8b76 | 897 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
898 | struct abbrev_info *abbrev, |
899 | unsigned int, bfd *, | |
900 | gdb_byte *, gdb_byte *, | |
901 | struct dwarf2_cu *); | |
c906108c | 902 | |
c764a876 | 903 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 904 | struct dwarf2_cu *); |
72bf9492 DJ |
905 | |
906 | static void fixup_partial_die (struct partial_die_info *, | |
907 | struct dwarf2_cu *); | |
908 | ||
fe1b8b76 JB |
909 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
910 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 911 | |
fe1b8b76 JB |
912 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
913 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 914 | |
fe1b8b76 | 915 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 916 | |
fe1b8b76 | 917 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 918 | |
fe1b8b76 | 919 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 920 | |
fe1b8b76 | 921 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 922 | |
93311388 | 923 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 924 | |
fe1b8b76 | 925 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 926 | unsigned int *); |
c906108c | 927 | |
c764a876 DE |
928 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
929 | ||
930 | static LONGEST read_checked_initial_length_and_offset | |
931 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
932 | unsigned int *, unsigned int *); | |
613e1657 | 933 | |
fe1b8b76 | 934 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
935 | unsigned int *); |
936 | ||
937 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 938 | |
fe1b8b76 | 939 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 940 | |
9b1c24c8 | 941 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 942 | |
fe1b8b76 JB |
943 | static char *read_indirect_string (bfd *, gdb_byte *, |
944 | const struct comp_unit_head *, | |
945 | unsigned int *); | |
4bdf3d34 | 946 | |
fe1b8b76 | 947 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 948 | |
fe1b8b76 | 949 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 950 | |
fe1b8b76 | 951 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 952 | |
e142c38c | 953 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 954 | |
e142c38c DJ |
955 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
956 | struct dwarf2_cu *); | |
c906108c | 957 | |
348e048f DE |
958 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
959 | unsigned int, | |
960 | struct dwarf2_cu *); | |
961 | ||
05cf31d1 JB |
962 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
963 | struct dwarf2_cu *cu); | |
964 | ||
e142c38c | 965 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 966 | |
e142c38c | 967 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 968 | struct dwarf2_cu **); |
63d06c5c | 969 | |
debd256d JB |
970 | static void free_line_header (struct line_header *lh); |
971 | ||
aaa75496 JB |
972 | static void add_file_name (struct line_header *, char *, unsigned int, |
973 | unsigned int, unsigned int); | |
974 | ||
debd256d JB |
975 | static struct line_header *(dwarf_decode_line_header |
976 | (unsigned int offset, | |
e7c27a73 | 977 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d | 978 | |
f3f5162e DE |
979 | static void dwarf_decode_lines (struct line_header *, const char *, |
980 | struct dwarf2_cu *, struct partial_symtab *, | |
981 | int); | |
c906108c | 982 | |
72b9f47f | 983 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 984 | |
a14ed312 | 985 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 986 | struct dwarf2_cu *); |
c906108c | 987 | |
34eaf542 TT |
988 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
989 | struct dwarf2_cu *, struct symbol *); | |
990 | ||
a14ed312 | 991 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 992 | struct dwarf2_cu *); |
c906108c | 993 | |
98bfdba5 PA |
994 | static void dwarf2_const_value_attr (struct attribute *attr, |
995 | struct type *type, | |
996 | const char *name, | |
997 | struct obstack *obstack, | |
998 | struct dwarf2_cu *cu, long *value, | |
999 | gdb_byte **bytes, | |
1000 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1001 | |
e7c27a73 | 1002 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1003 | |
b4ba55a1 JB |
1004 | static int need_gnat_info (struct dwarf2_cu *); |
1005 | ||
3e43a32a MS |
1006 | static struct type *die_descriptive_type (struct die_info *, |
1007 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1008 | |
1009 | static void set_descriptive_type (struct type *, struct die_info *, | |
1010 | struct dwarf2_cu *); | |
1011 | ||
e7c27a73 DJ |
1012 | static struct type *die_containing_type (struct die_info *, |
1013 | struct dwarf2_cu *); | |
c906108c | 1014 | |
673bfd45 DE |
1015 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1016 | struct dwarf2_cu *); | |
c906108c | 1017 | |
f792889a | 1018 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1019 | |
673bfd45 DE |
1020 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1021 | ||
0d5cff50 | 1022 | static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1023 | |
6e70227d | 1024 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1025 | const char *suffix, int physname, |
1026 | struct dwarf2_cu *cu); | |
63d06c5c | 1027 | |
e7c27a73 | 1028 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1029 | |
348e048f DE |
1030 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1031 | ||
e7c27a73 | 1032 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1033 | |
e7c27a73 | 1034 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1035 | |
96408a79 SA |
1036 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
1037 | ||
ff013f42 JK |
1038 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1039 | struct dwarf2_cu *, struct partial_symtab *); | |
1040 | ||
a14ed312 | 1041 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1042 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1043 | struct partial_symtab *); | |
c906108c | 1044 | |
fae299cd DC |
1045 | static void get_scope_pc_bounds (struct die_info *, |
1046 | CORE_ADDR *, CORE_ADDR *, | |
1047 | struct dwarf2_cu *); | |
1048 | ||
801e3a5b JB |
1049 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1050 | CORE_ADDR, struct dwarf2_cu *); | |
1051 | ||
a14ed312 | 1052 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1053 | struct dwarf2_cu *); |
c906108c | 1054 | |
a14ed312 | 1055 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1056 | struct type *, struct dwarf2_cu *); |
c906108c | 1057 | |
a14ed312 | 1058 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1059 | struct die_info *, struct type *, |
e7c27a73 | 1060 | struct dwarf2_cu *); |
c906108c | 1061 | |
a14ed312 | 1062 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1063 | struct type *, |
1064 | struct dwarf2_cu *); | |
c906108c | 1065 | |
134d01f1 | 1066 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1067 | |
e7c27a73 | 1068 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1069 | |
e7c27a73 | 1070 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1071 | |
5d7cb8df JK |
1072 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1073 | ||
27aa8d6a SW |
1074 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1075 | ||
f55ee35c JK |
1076 | static struct type *read_module_type (struct die_info *die, |
1077 | struct dwarf2_cu *cu); | |
1078 | ||
38d518c9 | 1079 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1080 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1081 | |
134d01f1 | 1082 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1083 | |
e7c27a73 | 1084 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1085 | |
6e70227d | 1086 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1087 | struct dwarf2_cu *); |
1088 | ||
93311388 | 1089 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1090 | |
93311388 DE |
1091 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1092 | gdb_byte *info_ptr, | |
d97bc12b DE |
1093 | gdb_byte **new_info_ptr, |
1094 | struct die_info *parent); | |
1095 | ||
93311388 DE |
1096 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1097 | gdb_byte *info_ptr, | |
fe1b8b76 | 1098 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1099 | struct die_info *parent); |
1100 | ||
93311388 DE |
1101 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1102 | gdb_byte *info_ptr, | |
fe1b8b76 | 1103 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1104 | struct die_info *parent); |
1105 | ||
93311388 DE |
1106 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1107 | struct die_info **, gdb_byte *, | |
1108 | int *); | |
1109 | ||
e7c27a73 | 1110 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1111 | |
71c25dea TT |
1112 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1113 | struct obstack *); | |
1114 | ||
e142c38c | 1115 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1116 | |
98bfdba5 PA |
1117 | static const char *dwarf2_full_name (char *name, |
1118 | struct die_info *die, | |
1119 | struct dwarf2_cu *cu); | |
1120 | ||
e142c38c | 1121 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1122 | struct dwarf2_cu **); |
9219021c | 1123 | |
a14ed312 | 1124 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1125 | |
a14ed312 | 1126 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1127 | |
a14ed312 | 1128 | static char *dwarf_form_name (unsigned int); |
c906108c | 1129 | |
a14ed312 | 1130 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1131 | |
a14ed312 | 1132 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1133 | |
1134 | #if 0 | |
a14ed312 | 1135 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1136 | #endif |
1137 | ||
f9aca02d | 1138 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1139 | |
d97bc12b DE |
1140 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1141 | ||
1142 | static void dump_die_for_error (struct die_info *); | |
1143 | ||
1144 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1145 | struct die_info *); | |
c906108c | 1146 | |
d97bc12b | 1147 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1148 | |
51545339 | 1149 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1150 | struct dwarf2_cu *); |
c906108c | 1151 | |
93311388 DE |
1152 | static int is_ref_attr (struct attribute *); |
1153 | ||
c764a876 | 1154 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1155 | |
43bbcdc2 | 1156 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1157 | |
348e048f DE |
1158 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1159 | struct attribute *, | |
1160 | struct dwarf2_cu **); | |
1161 | ||
10b3939b DJ |
1162 | static struct die_info *follow_die_ref (struct die_info *, |
1163 | struct attribute *, | |
f2f0e013 | 1164 | struct dwarf2_cu **); |
c906108c | 1165 | |
348e048f DE |
1166 | static struct die_info *follow_die_sig (struct die_info *, |
1167 | struct attribute *, | |
1168 | struct dwarf2_cu **); | |
1169 | ||
6c83ed52 TT |
1170 | static struct signatured_type *lookup_signatured_type_at_offset |
1171 | (struct objfile *objfile, | |
1172 | struct dwarf2_section_info *section, | |
1173 | unsigned int offset); | |
1174 | ||
e5fe5e75 | 1175 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
348e048f | 1176 | |
a0f42c21 | 1177 | static void read_signatured_type (struct signatured_type *type_sig); |
348e048f | 1178 | |
c906108c SS |
1179 | /* memory allocation interface */ |
1180 | ||
7b5a2f43 | 1181 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1182 | |
f3dd6933 | 1183 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1184 | |
b60c80d6 | 1185 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1186 | |
2e276125 | 1187 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
cf2c3c16 TT |
1188 | char *, bfd *, struct dwarf2_cu *, |
1189 | struct dwarf2_section_info *, | |
1190 | int); | |
2e276125 | 1191 | |
8e19ed76 PS |
1192 | static int attr_form_is_block (struct attribute *); |
1193 | ||
3690dd37 JB |
1194 | static int attr_form_is_section_offset (struct attribute *); |
1195 | ||
1196 | static int attr_form_is_constant (struct attribute *); | |
1197 | ||
8cf6f0b1 TT |
1198 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1199 | struct dwarf2_loclist_baton *baton, | |
1200 | struct attribute *attr); | |
1201 | ||
93e7bd98 DJ |
1202 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1203 | struct symbol *sym, | |
1204 | struct dwarf2_cu *cu); | |
4c2df51b | 1205 | |
93311388 DE |
1206 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1207 | struct abbrev_info *abbrev, | |
1208 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1209 | |
72bf9492 DJ |
1210 | static void free_stack_comp_unit (void *); |
1211 | ||
72bf9492 DJ |
1212 | static hashval_t partial_die_hash (const void *item); |
1213 | ||
1214 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1215 | ||
ae038cb0 | 1216 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1217 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1218 | |
9816fde3 | 1219 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
23745b47 | 1220 | struct dwarf2_per_cu_data *per_cu); |
9816fde3 JK |
1221 | |
1222 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
1223 | struct die_info *comp_unit_die); | |
93311388 | 1224 | |
68dc6402 | 1225 | static void free_heap_comp_unit (void *); |
ae038cb0 DJ |
1226 | |
1227 | static void free_cached_comp_units (void *); | |
1228 | ||
1229 | static void age_cached_comp_units (void); | |
1230 | ||
1231 | static void free_one_cached_comp_unit (void *); | |
1232 | ||
f792889a DJ |
1233 | static struct type *set_die_type (struct die_info *, struct type *, |
1234 | struct dwarf2_cu *); | |
1c379e20 | 1235 | |
ae038cb0 DJ |
1236 | static void create_all_comp_units (struct objfile *); |
1237 | ||
1fd400ff TT |
1238 | static int create_debug_types_hash_table (struct objfile *objfile); |
1239 | ||
a0f42c21 | 1240 | static void load_full_comp_unit (struct dwarf2_per_cu_data *); |
10b3939b DJ |
1241 | |
1242 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1243 | ||
1244 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1245 | struct dwarf2_per_cu_data *); | |
1246 | ||
ae038cb0 DJ |
1247 | static void dwarf2_mark (struct dwarf2_cu *); |
1248 | ||
1249 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1250 | ||
673bfd45 DE |
1251 | static struct type *get_die_type_at_offset (unsigned int, |
1252 | struct dwarf2_per_cu_data *per_cu); | |
1253 | ||
f792889a | 1254 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1255 | |
9291a0cd TT |
1256 | static void dwarf2_release_queue (void *dummy); |
1257 | ||
a0f42c21 | 1258 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu); |
9291a0cd | 1259 | |
a0f42c21 | 1260 | static void process_queue (void); |
9291a0cd TT |
1261 | |
1262 | static void find_file_and_directory (struct die_info *die, | |
1263 | struct dwarf2_cu *cu, | |
1264 | char **name, char **comp_dir); | |
1265 | ||
1266 | static char *file_full_name (int file, struct line_header *lh, | |
1267 | const char *comp_dir); | |
1268 | ||
9ff913ba DE |
1269 | static gdb_byte *read_and_check_comp_unit_head |
1270 | (struct comp_unit_head *header, | |
1271 | struct dwarf2_section_info *section, gdb_byte *info_ptr, | |
1272 | int is_debug_types_section); | |
9291a0cd TT |
1273 | |
1274 | static void init_cu_die_reader (struct die_reader_specs *reader, | |
1275 | struct dwarf2_cu *cu); | |
1276 | ||
673bfd45 | 1277 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1278 | |
9291a0cd TT |
1279 | #if WORDS_BIGENDIAN |
1280 | ||
1281 | /* Convert VALUE between big- and little-endian. */ | |
1282 | static offset_type | |
1283 | byte_swap (offset_type value) | |
1284 | { | |
1285 | offset_type result; | |
1286 | ||
1287 | result = (value & 0xff) << 24; | |
1288 | result |= (value & 0xff00) << 8; | |
1289 | result |= (value & 0xff0000) >> 8; | |
1290 | result |= (value & 0xff000000) >> 24; | |
1291 | return result; | |
1292 | } | |
1293 | ||
1294 | #define MAYBE_SWAP(V) byte_swap (V) | |
1295 | ||
1296 | #else | |
1297 | #define MAYBE_SWAP(V) (V) | |
1298 | #endif /* WORDS_BIGENDIAN */ | |
1299 | ||
1300 | /* The suffix for an index file. */ | |
1301 | #define INDEX_SUFFIX ".gdb-index" | |
1302 | ||
3da10d80 KS |
1303 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1304 | struct dwarf2_cu *cu); | |
1305 | ||
c906108c | 1306 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
1307 | information and return true if we have enough to do something. |
1308 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
1309 | ELF names are used. */ | |
c906108c SS |
1310 | |
1311 | int | |
251d32d9 TG |
1312 | dwarf2_has_info (struct objfile *objfile, |
1313 | const struct dwarf2_debug_sections *names) | |
c906108c | 1314 | { |
be391dca TT |
1315 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1316 | if (!dwarf2_per_objfile) | |
1317 | { | |
1318 | /* Initialize per-objfile state. */ | |
1319 | struct dwarf2_per_objfile *data | |
1320 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1321 | |
be391dca TT |
1322 | memset (data, 0, sizeof (*data)); |
1323 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1324 | dwarf2_per_objfile = data; | |
6502dd73 | 1325 | |
251d32d9 TG |
1326 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
1327 | (void *) names); | |
be391dca TT |
1328 | dwarf2_per_objfile->objfile = objfile; |
1329 | } | |
1330 | return (dwarf2_per_objfile->info.asection != NULL | |
1331 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1332 | } |
1333 | ||
251d32d9 TG |
1334 | /* When loading sections, we look either for uncompressed section or for |
1335 | compressed section names. */ | |
233a11ab CS |
1336 | |
1337 | static int | |
251d32d9 TG |
1338 | section_is_p (const char *section_name, |
1339 | const struct dwarf2_section_names *names) | |
233a11ab | 1340 | { |
251d32d9 TG |
1341 | if (names->normal != NULL |
1342 | && strcmp (section_name, names->normal) == 0) | |
1343 | return 1; | |
1344 | if (names->compressed != NULL | |
1345 | && strcmp (section_name, names->compressed) == 0) | |
1346 | return 1; | |
1347 | return 0; | |
233a11ab CS |
1348 | } |
1349 | ||
c906108c SS |
1350 | /* This function is mapped across the sections and remembers the |
1351 | offset and size of each of the debugging sections we are interested | |
1352 | in. */ | |
1353 | ||
1354 | static void | |
251d32d9 | 1355 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
c906108c | 1356 | { |
251d32d9 TG |
1357 | const struct dwarf2_debug_sections *names; |
1358 | ||
1359 | if (vnames == NULL) | |
1360 | names = &dwarf2_elf_names; | |
1361 | else | |
1362 | names = (const struct dwarf2_debug_sections *) vnames; | |
1363 | ||
1364 | if (section_is_p (sectp->name, &names->info)) | |
c906108c | 1365 | { |
dce234bc PP |
1366 | dwarf2_per_objfile->info.asection = sectp; |
1367 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1368 | } |
251d32d9 | 1369 | else if (section_is_p (sectp->name, &names->abbrev)) |
c906108c | 1370 | { |
dce234bc PP |
1371 | dwarf2_per_objfile->abbrev.asection = sectp; |
1372 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1373 | } |
251d32d9 | 1374 | else if (section_is_p (sectp->name, &names->line)) |
c906108c | 1375 | { |
dce234bc PP |
1376 | dwarf2_per_objfile->line.asection = sectp; |
1377 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1378 | } |
251d32d9 | 1379 | else if (section_is_p (sectp->name, &names->loc)) |
c906108c | 1380 | { |
dce234bc PP |
1381 | dwarf2_per_objfile->loc.asection = sectp; |
1382 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1383 | } |
251d32d9 | 1384 | else if (section_is_p (sectp->name, &names->macinfo)) |
c906108c | 1385 | { |
dce234bc PP |
1386 | dwarf2_per_objfile->macinfo.asection = sectp; |
1387 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1388 | } |
cf2c3c16 TT |
1389 | else if (section_is_p (sectp->name, &names->macro)) |
1390 | { | |
1391 | dwarf2_per_objfile->macro.asection = sectp; | |
1392 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); | |
1393 | } | |
251d32d9 | 1394 | else if (section_is_p (sectp->name, &names->str)) |
c906108c | 1395 | { |
dce234bc PP |
1396 | dwarf2_per_objfile->str.asection = sectp; |
1397 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1398 | } |
251d32d9 | 1399 | else if (section_is_p (sectp->name, &names->frame)) |
b6af0555 | 1400 | { |
dce234bc PP |
1401 | dwarf2_per_objfile->frame.asection = sectp; |
1402 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1403 | } |
251d32d9 | 1404 | else if (section_is_p (sectp->name, &names->eh_frame)) |
b6af0555 | 1405 | { |
3799ccc6 | 1406 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1407 | |
3799ccc6 EZ |
1408 | if (aflag & SEC_HAS_CONTENTS) |
1409 | { | |
dce234bc PP |
1410 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1411 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1412 | } |
b6af0555 | 1413 | } |
251d32d9 | 1414 | else if (section_is_p (sectp->name, &names->ranges)) |
af34e669 | 1415 | { |
dce234bc PP |
1416 | dwarf2_per_objfile->ranges.asection = sectp; |
1417 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1418 | } |
251d32d9 | 1419 | else if (section_is_p (sectp->name, &names->types)) |
348e048f | 1420 | { |
8b70b953 TT |
1421 | struct dwarf2_section_info type_section; |
1422 | ||
1423 | memset (&type_section, 0, sizeof (type_section)); | |
1424 | type_section.asection = sectp; | |
1425 | type_section.size = bfd_get_section_size (sectp); | |
1426 | ||
1427 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
1428 | &type_section); | |
348e048f | 1429 | } |
251d32d9 | 1430 | else if (section_is_p (sectp->name, &names->gdb_index)) |
9291a0cd TT |
1431 | { |
1432 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1433 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1434 | } | |
dce234bc | 1435 | |
72dca2f5 FR |
1436 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1437 | && bfd_section_vma (abfd, sectp) == 0) | |
1438 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1439 | } |
1440 | ||
dce234bc PP |
1441 | /* Decompress a section that was compressed using zlib. Store the |
1442 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1443 | |
1444 | static void | |
dce234bc PP |
1445 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1446 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1447 | { | |
1448 | bfd *abfd = objfile->obfd; | |
1449 | #ifndef HAVE_ZLIB_H | |
1450 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1451 | "is disabled in this copy of GDB"), | |
1452 | bfd_get_filename (abfd)); | |
1453 | #else | |
1454 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1455 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1456 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1457 | bfd_size_type uncompressed_size; |
1458 | gdb_byte *uncompressed_buffer; | |
1459 | z_stream strm; | |
1460 | int rc; | |
1461 | int header_size = 12; | |
1462 | ||
1463 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
3e43a32a MS |
1464 | || bfd_bread (compressed_buffer, |
1465 | compressed_size, abfd) != compressed_size) | |
dce234bc PP |
1466 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
1467 | bfd_get_filename (abfd)); | |
1468 | ||
1469 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1470 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1471 | if (compressed_size < header_size | |
1472 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1473 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1474 | bfd_get_filename (abfd)); | |
1475 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1476 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1477 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1478 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1479 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1480 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1481 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1482 | uncompressed_size += compressed_buffer[11]; | |
1483 | ||
1484 | /* It is possible the section consists of several compressed | |
1485 | buffers concatenated together, so we uncompress in a loop. */ | |
1486 | strm.zalloc = NULL; | |
1487 | strm.zfree = NULL; | |
1488 | strm.opaque = NULL; | |
1489 | strm.avail_in = compressed_size - header_size; | |
1490 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1491 | strm.avail_out = uncompressed_size; | |
1492 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1493 | uncompressed_size); | |
1494 | rc = inflateInit (&strm); | |
1495 | while (strm.avail_in > 0) | |
1496 | { | |
1497 | if (rc != Z_OK) | |
1498 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1499 | bfd_get_filename (abfd), rc); | |
1500 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1501 | + (uncompressed_size - strm.avail_out)); | |
1502 | rc = inflate (&strm, Z_FINISH); | |
1503 | if (rc != Z_STREAM_END) | |
1504 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1505 | bfd_get_filename (abfd), rc); | |
1506 | rc = inflateReset (&strm); | |
1507 | } | |
1508 | rc = inflateEnd (&strm); | |
1509 | if (rc != Z_OK | |
1510 | || strm.avail_out != 0) | |
1511 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1512 | bfd_get_filename (abfd), rc); | |
1513 | ||
affddf13 | 1514 | do_cleanups (cleanup); |
dce234bc PP |
1515 | *outbuf = uncompressed_buffer; |
1516 | *outsize = uncompressed_size; | |
1517 | #endif | |
233a11ab CS |
1518 | } |
1519 | ||
9e0ac564 TT |
1520 | /* A helper function that decides whether a section is empty. */ |
1521 | ||
1522 | static int | |
1523 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1524 | { | |
1525 | return info->asection == NULL || info->size == 0; | |
1526 | } | |
1527 | ||
9cdd5dbd | 1528 | /* Read the contents of the section INFO from object file specified by |
dce234bc PP |
1529 | OBJFILE, store info about the section into INFO. |
1530 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1531 | |
dce234bc PP |
1532 | static void |
1533 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1534 | { |
dce234bc PP |
1535 | bfd *abfd = objfile->obfd; |
1536 | asection *sectp = info->asection; | |
1537 | gdb_byte *buf, *retbuf; | |
1538 | unsigned char header[4]; | |
c906108c | 1539 | |
be391dca TT |
1540 | if (info->readin) |
1541 | return; | |
dce234bc | 1542 | info->buffer = NULL; |
b315ab21 | 1543 | info->map_addr = NULL; |
be391dca | 1544 | info->readin = 1; |
188dd5d6 | 1545 | |
9e0ac564 | 1546 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1547 | return; |
c906108c | 1548 | |
dce234bc PP |
1549 | /* Check if the file has a 4-byte header indicating compression. */ |
1550 | if (info->size > sizeof (header) | |
1551 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1552 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1553 | { | |
1554 | /* Upon decompression, update the buffer and its size. */ | |
1555 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1556 | { | |
1557 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1558 | &info->size); | |
1559 | return; | |
1560 | } | |
1561 | } | |
4bdf3d34 | 1562 | |
dce234bc PP |
1563 | #ifdef HAVE_MMAP |
1564 | if (pagesize == 0) | |
1565 | pagesize = getpagesize (); | |
2e276125 | 1566 | |
dce234bc PP |
1567 | /* Only try to mmap sections which are large enough: we don't want to |
1568 | waste space due to fragmentation. Also, only try mmap for sections | |
1569 | without relocations. */ | |
1570 | ||
1571 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1572 | { | |
b315ab21 TG |
1573 | info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ, |
1574 | MAP_PRIVATE, sectp->filepos, | |
1575 | &info->map_addr, &info->map_len); | |
dce234bc | 1576 | |
b315ab21 | 1577 | if ((caddr_t)info->buffer != MAP_FAILED) |
dce234bc | 1578 | { |
be391dca | 1579 | #if HAVE_POSIX_MADVISE |
b315ab21 | 1580 | posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED); |
be391dca | 1581 | #endif |
dce234bc PP |
1582 | return; |
1583 | } | |
1584 | } | |
1585 | #endif | |
1586 | ||
1587 | /* If we get here, we are a normal, not-compressed section. */ | |
1588 | info->buffer = buf | |
1589 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1590 | ||
1591 | /* When debugging .o files, we may need to apply relocations; see | |
1592 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1593 | We never compress sections in .o files, so we only need to | |
1594 | try this when the section is not compressed. */ | |
ac8035ab | 1595 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1596 | if (retbuf != NULL) |
1597 | { | |
1598 | info->buffer = retbuf; | |
1599 | return; | |
1600 | } | |
1601 | ||
1602 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1603 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1604 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1605 | bfd_get_filename (abfd)); | |
1606 | } | |
1607 | ||
9e0ac564 TT |
1608 | /* A helper function that returns the size of a section in a safe way. |
1609 | If you are positive that the section has been read before using the | |
1610 | size, then it is safe to refer to the dwarf2_section_info object's | |
1611 | "size" field directly. In other cases, you must call this | |
1612 | function, because for compressed sections the size field is not set | |
1613 | correctly until the section has been read. */ | |
1614 | ||
1615 | static bfd_size_type | |
1616 | dwarf2_section_size (struct objfile *objfile, | |
1617 | struct dwarf2_section_info *info) | |
1618 | { | |
1619 | if (!info->readin) | |
1620 | dwarf2_read_section (objfile, info); | |
1621 | return info->size; | |
1622 | } | |
1623 | ||
dce234bc | 1624 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1625 | SECTION_NAME. */ |
af34e669 | 1626 | |
dce234bc | 1627 | void |
3017a003 TG |
1628 | dwarf2_get_section_info (struct objfile *objfile, |
1629 | enum dwarf2_section_enum sect, | |
dce234bc PP |
1630 | asection **sectp, gdb_byte **bufp, |
1631 | bfd_size_type *sizep) | |
1632 | { | |
1633 | struct dwarf2_per_objfile *data | |
1634 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1635 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1636 | |
1637 | /* We may see an objfile without any DWARF, in which case we just | |
1638 | return nothing. */ | |
1639 | if (data == NULL) | |
1640 | { | |
1641 | *sectp = NULL; | |
1642 | *bufp = NULL; | |
1643 | *sizep = 0; | |
1644 | return; | |
1645 | } | |
3017a003 TG |
1646 | switch (sect) |
1647 | { | |
1648 | case DWARF2_DEBUG_FRAME: | |
1649 | info = &data->frame; | |
1650 | break; | |
1651 | case DWARF2_EH_FRAME: | |
1652 | info = &data->eh_frame; | |
1653 | break; | |
1654 | default: | |
1655 | gdb_assert_not_reached ("unexpected section"); | |
1656 | } | |
dce234bc | 1657 | |
9e0ac564 | 1658 | dwarf2_read_section (objfile, info); |
dce234bc PP |
1659 | |
1660 | *sectp = info->asection; | |
1661 | *bufp = info->buffer; | |
1662 | *sizep = info->size; | |
1663 | } | |
1664 | ||
9291a0cd | 1665 | \f |
7b9f3c50 DE |
1666 | /* DWARF quick_symbols_functions support. */ |
1667 | ||
1668 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
1669 | unique line tables, so we maintain a separate table of all .debug_line | |
1670 | derived entries to support the sharing. | |
1671 | All the quick functions need is the list of file names. We discard the | |
1672 | line_header when we're done and don't need to record it here. */ | |
1673 | struct quick_file_names | |
1674 | { | |
1675 | /* The offset in .debug_line of the line table. We hash on this. */ | |
1676 | unsigned int offset; | |
1677 | ||
1678 | /* The number of entries in file_names, real_names. */ | |
1679 | unsigned int num_file_names; | |
1680 | ||
1681 | /* The file names from the line table, after being run through | |
1682 | file_full_name. */ | |
1683 | const char **file_names; | |
1684 | ||
1685 | /* The file names from the line table after being run through | |
1686 | gdb_realpath. These are computed lazily. */ | |
1687 | const char **real_names; | |
1688 | }; | |
1689 | ||
1690 | /* When using the index (and thus not using psymtabs), each CU has an | |
1691 | object of this type. This is used to hold information needed by | |
1692 | the various "quick" methods. */ | |
1693 | struct dwarf2_per_cu_quick_data | |
1694 | { | |
1695 | /* The file table. This can be NULL if there was no file table | |
1696 | or it's currently not read in. | |
1697 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
1698 | struct quick_file_names *file_names; | |
1699 | ||
1700 | /* The corresponding symbol table. This is NULL if symbols for this | |
1701 | CU have not yet been read. */ | |
1702 | struct symtab *symtab; | |
1703 | ||
1704 | /* A temporary mark bit used when iterating over all CUs in | |
1705 | expand_symtabs_matching. */ | |
1706 | unsigned int mark : 1; | |
1707 | ||
1708 | /* True if we've tried to read the file table and found there isn't one. | |
1709 | There will be no point in trying to read it again next time. */ | |
1710 | unsigned int no_file_data : 1; | |
1711 | }; | |
1712 | ||
1713 | /* Hash function for a quick_file_names. */ | |
1714 | ||
1715 | static hashval_t | |
1716 | hash_file_name_entry (const void *e) | |
1717 | { | |
1718 | const struct quick_file_names *file_data = e; | |
1719 | ||
1720 | return file_data->offset; | |
1721 | } | |
1722 | ||
1723 | /* Equality function for a quick_file_names. */ | |
1724 | ||
1725 | static int | |
1726 | eq_file_name_entry (const void *a, const void *b) | |
1727 | { | |
1728 | const struct quick_file_names *ea = a; | |
1729 | const struct quick_file_names *eb = b; | |
1730 | ||
1731 | return ea->offset == eb->offset; | |
1732 | } | |
1733 | ||
1734 | /* Delete function for a quick_file_names. */ | |
1735 | ||
1736 | static void | |
1737 | delete_file_name_entry (void *e) | |
1738 | { | |
1739 | struct quick_file_names *file_data = e; | |
1740 | int i; | |
1741 | ||
1742 | for (i = 0; i < file_data->num_file_names; ++i) | |
1743 | { | |
1744 | xfree ((void*) file_data->file_names[i]); | |
1745 | if (file_data->real_names) | |
1746 | xfree ((void*) file_data->real_names[i]); | |
1747 | } | |
1748 | ||
1749 | /* The space for the struct itself lives on objfile_obstack, | |
1750 | so we don't free it here. */ | |
1751 | } | |
1752 | ||
1753 | /* Create a quick_file_names hash table. */ | |
1754 | ||
1755 | static htab_t | |
1756 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
1757 | { | |
1758 | return htab_create_alloc (nr_initial_entries, | |
1759 | hash_file_name_entry, eq_file_name_entry, | |
1760 | delete_file_name_entry, xcalloc, xfree); | |
1761 | } | |
9291a0cd | 1762 | |
918dd910 JK |
1763 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
1764 | have to be created afterwards. You should call age_cached_comp_units after | |
1765 | processing PER_CU->CU. dw2_setup must have been already called. */ | |
1766 | ||
1767 | static void | |
1768 | load_cu (struct dwarf2_per_cu_data *per_cu) | |
1769 | { | |
b0df02fd | 1770 | if (per_cu->debug_types_section) |
e5fe5e75 | 1771 | load_full_type_unit (per_cu); |
918dd910 | 1772 | else |
a0f42c21 | 1773 | load_full_comp_unit (per_cu); |
918dd910 | 1774 | |
918dd910 | 1775 | gdb_assert (per_cu->cu != NULL); |
2dc860c0 DE |
1776 | |
1777 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); | |
918dd910 JK |
1778 | } |
1779 | ||
a0f42c21 | 1780 | /* Read in the symbols for PER_CU. */ |
2fdf6df6 | 1781 | |
9291a0cd | 1782 | static void |
a0f42c21 | 1783 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1784 | { |
1785 | struct cleanup *back_to; | |
1786 | ||
1787 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1788 | ||
a0f42c21 | 1789 | queue_comp_unit (per_cu); |
9291a0cd | 1790 | |
918dd910 | 1791 | load_cu (per_cu); |
9291a0cd | 1792 | |
a0f42c21 | 1793 | process_queue (); |
9291a0cd TT |
1794 | |
1795 | /* Age the cache, releasing compilation units that have not | |
1796 | been used recently. */ | |
1797 | age_cached_comp_units (); | |
1798 | ||
1799 | do_cleanups (back_to); | |
1800 | } | |
1801 | ||
1802 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1803 | the objfile from which this CU came. Returns the resulting symbol | |
1804 | table. */ | |
2fdf6df6 | 1805 | |
9291a0cd | 1806 | static struct symtab * |
a0f42c21 | 1807 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1808 | { |
1809 | if (!per_cu->v.quick->symtab) | |
1810 | { | |
1811 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1812 | increment_reading_symtab (); | |
a0f42c21 | 1813 | dw2_do_instantiate_symtab (per_cu); |
9291a0cd TT |
1814 | do_cleanups (back_to); |
1815 | } | |
1816 | return per_cu->v.quick->symtab; | |
1817 | } | |
1818 | ||
1fd400ff | 1819 | /* Return the CU given its index. */ |
2fdf6df6 | 1820 | |
1fd400ff TT |
1821 | static struct dwarf2_per_cu_data * |
1822 | dw2_get_cu (int index) | |
1823 | { | |
1824 | if (index >= dwarf2_per_objfile->n_comp_units) | |
1825 | { | |
1826 | index -= dwarf2_per_objfile->n_comp_units; | |
d467dd73 | 1827 | return dwarf2_per_objfile->all_type_units[index]; |
1fd400ff TT |
1828 | } |
1829 | return dwarf2_per_objfile->all_comp_units[index]; | |
1830 | } | |
1831 | ||
9291a0cd TT |
1832 | /* A helper function that knows how to read a 64-bit value in a way |
1833 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1834 | otherwise. */ | |
2fdf6df6 | 1835 | |
9291a0cd TT |
1836 | static int |
1837 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1838 | { | |
1839 | if (sizeof (ULONGEST) < 8) | |
1840 | { | |
1841 | int i; | |
1842 | ||
1843 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1844 | for (i = 0; i < 4; ++i) | |
1845 | if (bytes[i + 4] != 0) | |
1846 | return 0; | |
1847 | ||
1848 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1849 | } | |
1850 | else | |
1851 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1852 | return 1; | |
1853 | } | |
1854 | ||
1855 | /* Read the CU list from the mapped index, and use it to create all | |
1856 | the CU objects for this objfile. Return 0 if something went wrong, | |
1857 | 1 if everything went ok. */ | |
2fdf6df6 | 1858 | |
9291a0cd | 1859 | static int |
1fd400ff TT |
1860 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
1861 | offset_type cu_list_elements) | |
9291a0cd TT |
1862 | { |
1863 | offset_type i; | |
9291a0cd TT |
1864 | |
1865 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1866 | dwarf2_per_objfile->all_comp_units | |
1867 | = obstack_alloc (&objfile->objfile_obstack, | |
1868 | dwarf2_per_objfile->n_comp_units | |
1869 | * sizeof (struct dwarf2_per_cu_data *)); | |
1870 | ||
1871 | for (i = 0; i < cu_list_elements; i += 2) | |
1872 | { | |
1873 | struct dwarf2_per_cu_data *the_cu; | |
1874 | ULONGEST offset, length; | |
1875 | ||
1876 | if (!extract_cu_value (cu_list, &offset) | |
1877 | || !extract_cu_value (cu_list + 8, &length)) | |
1878 | return 0; | |
1879 | cu_list += 2 * 8; | |
1880 | ||
1881 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1882 | struct dwarf2_per_cu_data); | |
1883 | the_cu->offset = offset; | |
1884 | the_cu->length = length; | |
1885 | the_cu->objfile = objfile; | |
1886 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1887 | struct dwarf2_per_cu_quick_data); | |
1888 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1889 | } | |
1890 | ||
1891 | return 1; | |
1892 | } | |
1893 | ||
1fd400ff | 1894 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 1895 | |
1fd400ff | 1896 | static int |
673bfd45 | 1897 | create_signatured_type_table_from_index (struct objfile *objfile, |
8b70b953 | 1898 | struct dwarf2_section_info *section, |
673bfd45 DE |
1899 | const gdb_byte *bytes, |
1900 | offset_type elements) | |
1fd400ff TT |
1901 | { |
1902 | offset_type i; | |
673bfd45 | 1903 | htab_t sig_types_hash; |
1fd400ff | 1904 | |
d467dd73 DE |
1905 | dwarf2_per_objfile->n_type_units = elements / 3; |
1906 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 1907 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 1908 | dwarf2_per_objfile->n_type_units |
1fd400ff TT |
1909 | * sizeof (struct dwarf2_per_cu_data *)); |
1910 | ||
673bfd45 | 1911 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
1912 | |
1913 | for (i = 0; i < elements; i += 3) | |
1914 | { | |
1915 | struct signatured_type *type_sig; | |
1916 | ULONGEST offset, type_offset, signature; | |
1917 | void **slot; | |
1918 | ||
1919 | if (!extract_cu_value (bytes, &offset) | |
1920 | || !extract_cu_value (bytes + 8, &type_offset)) | |
1921 | return 0; | |
1922 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
1923 | bytes += 3 * 8; | |
1924 | ||
1925 | type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1926 | struct signatured_type); | |
1927 | type_sig->signature = signature; | |
1fd400ff | 1928 | type_sig->type_offset = type_offset; |
b0df02fd | 1929 | type_sig->per_cu.debug_types_section = section; |
1fd400ff TT |
1930 | type_sig->per_cu.offset = offset; |
1931 | type_sig->per_cu.objfile = objfile; | |
1932 | type_sig->per_cu.v.quick | |
1933 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1934 | struct dwarf2_per_cu_quick_data); | |
1935 | ||
673bfd45 | 1936 | slot = htab_find_slot (sig_types_hash, type_sig, INSERT); |
1fd400ff TT |
1937 | *slot = type_sig; |
1938 | ||
d467dd73 | 1939 | dwarf2_per_objfile->all_type_units[i / 3] = &type_sig->per_cu; |
1fd400ff TT |
1940 | } |
1941 | ||
673bfd45 | 1942 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
1943 | |
1944 | return 1; | |
1945 | } | |
1946 | ||
9291a0cd TT |
1947 | /* Read the address map data from the mapped index, and use it to |
1948 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 1949 | |
9291a0cd TT |
1950 | static void |
1951 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
1952 | { | |
1953 | const gdb_byte *iter, *end; | |
1954 | struct obstack temp_obstack; | |
1955 | struct addrmap *mutable_map; | |
1956 | struct cleanup *cleanup; | |
1957 | CORE_ADDR baseaddr; | |
1958 | ||
1959 | obstack_init (&temp_obstack); | |
1960 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
1961 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
1962 | ||
1963 | iter = index->address_table; | |
1964 | end = iter + index->address_table_size; | |
1965 | ||
1966 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1967 | ||
1968 | while (iter < end) | |
1969 | { | |
1970 | ULONGEST hi, lo, cu_index; | |
1971 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1972 | iter += 8; | |
1973 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1974 | iter += 8; | |
1975 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
1976 | iter += 4; | |
1977 | ||
1978 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 1979 | dw2_get_cu (cu_index)); |
9291a0cd TT |
1980 | } |
1981 | ||
1982 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
1983 | &objfile->objfile_obstack); | |
1984 | do_cleanups (cleanup); | |
1985 | } | |
1986 | ||
59d7bcaf JK |
1987 | /* The hash function for strings in the mapped index. This is the same as |
1988 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
1989 | implementation. This is necessary because the hash function is tied to the | |
1990 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
1991 | SYMBOL_HASH_NEXT. |
1992 | ||
1993 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 1994 | |
9291a0cd | 1995 | static hashval_t |
559a7a62 | 1996 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
1997 | { |
1998 | const unsigned char *str = (const unsigned char *) p; | |
1999 | hashval_t r = 0; | |
2000 | unsigned char c; | |
2001 | ||
2002 | while ((c = *str++) != 0) | |
559a7a62 JK |
2003 | { |
2004 | if (index_version >= 5) | |
2005 | c = tolower (c); | |
2006 | r = r * 67 + c - 113; | |
2007 | } | |
9291a0cd TT |
2008 | |
2009 | return r; | |
2010 | } | |
2011 | ||
2012 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
2013 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
2014 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 2015 | |
9291a0cd TT |
2016 | static int |
2017 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
2018 | offset_type **vec_out) | |
2019 | { | |
0cf03b49 JK |
2020 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2021 | offset_type hash; | |
9291a0cd | 2022 | offset_type slot, step; |
559a7a62 | 2023 | int (*cmp) (const char *, const char *); |
9291a0cd | 2024 | |
0cf03b49 JK |
2025 | if (current_language->la_language == language_cplus |
2026 | || current_language->la_language == language_java | |
2027 | || current_language->la_language == language_fortran) | |
2028 | { | |
2029 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2030 | not contain any. */ | |
2031 | const char *paren = strchr (name, '('); | |
2032 | ||
2033 | if (paren) | |
2034 | { | |
2035 | char *dup; | |
2036 | ||
2037 | dup = xmalloc (paren - name + 1); | |
2038 | memcpy (dup, name, paren - name); | |
2039 | dup[paren - name] = 0; | |
2040 | ||
2041 | make_cleanup (xfree, dup); | |
2042 | name = dup; | |
2043 | } | |
2044 | } | |
2045 | ||
559a7a62 | 2046 | /* Index version 4 did not support case insensitive searches. But the |
feea76c2 | 2047 | indices for case insensitive languages are built in lowercase, therefore |
559a7a62 JK |
2048 | simulate our NAME being searched is also lowercased. */ |
2049 | hash = mapped_index_string_hash ((index->version == 4 | |
2050 | && case_sensitivity == case_sensitive_off | |
2051 | ? 5 : index->version), | |
2052 | name); | |
2053 | ||
3876f04e DE |
2054 | slot = hash & (index->symbol_table_slots - 1); |
2055 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 2056 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
2057 | |
2058 | for (;;) | |
2059 | { | |
2060 | /* Convert a slot number to an offset into the table. */ | |
2061 | offset_type i = 2 * slot; | |
2062 | const char *str; | |
3876f04e | 2063 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2064 | { |
2065 | do_cleanups (back_to); | |
2066 | return 0; | |
2067 | } | |
9291a0cd | 2068 | |
3876f04e | 2069 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 2070 | if (!cmp (name, str)) |
9291a0cd TT |
2071 | { |
2072 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2073 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2074 | do_cleanups (back_to); |
9291a0cd TT |
2075 | return 1; |
2076 | } | |
2077 | ||
3876f04e | 2078 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2079 | } |
2080 | } | |
2081 | ||
2082 | /* Read the index file. If everything went ok, initialize the "quick" | |
2083 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2fdf6df6 | 2084 | |
9291a0cd TT |
2085 | static int |
2086 | dwarf2_read_index (struct objfile *objfile) | |
2087 | { | |
9291a0cd TT |
2088 | char *addr; |
2089 | struct mapped_index *map; | |
b3b272e1 | 2090 | offset_type *metadata; |
ac0b195c KW |
2091 | const gdb_byte *cu_list; |
2092 | const gdb_byte *types_list = NULL; | |
2093 | offset_type version, cu_list_elements; | |
2094 | offset_type types_list_elements = 0; | |
1fd400ff | 2095 | int i; |
9291a0cd | 2096 | |
9e0ac564 | 2097 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
9291a0cd | 2098 | return 0; |
82430852 JK |
2099 | |
2100 | /* Older elfutils strip versions could keep the section in the main | |
2101 | executable while splitting it for the separate debug info file. */ | |
2102 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
2103 | & SEC_HAS_CONTENTS) == 0) | |
2104 | return 0; | |
2105 | ||
9291a0cd TT |
2106 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
2107 | ||
2108 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
2109 | /* Version check. */ | |
1fd400ff | 2110 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2111 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2112 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 2113 | contained incomplete addrmap. So, it seems better to just ignore such |
559a7a62 JK |
2114 | indices. Index version 4 uses a different hash function than index |
2115 | version 5 and later. */ | |
831adc1f | 2116 | if (version < 4) |
9291a0cd | 2117 | return 0; |
feea76c2 | 2118 | /* Indices with higher version than the one supported by GDB may be no |
594e8718 | 2119 | longer backward compatible. */ |
559a7a62 | 2120 | if (version > 5) |
594e8718 | 2121 | return 0; |
9291a0cd TT |
2122 | |
2123 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
559a7a62 | 2124 | map->version = version; |
b3b272e1 | 2125 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
2126 | |
2127 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2128 | |
2129 | i = 0; | |
2130 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
2131 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 2132 | / 8); |
1fd400ff TT |
2133 | ++i; |
2134 | ||
987d643c TT |
2135 | types_list = addr + MAYBE_SWAP (metadata[i]); |
2136 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2137 | - MAYBE_SWAP (metadata[i])) | |
2138 | / 8); | |
2139 | ++i; | |
1fd400ff TT |
2140 | |
2141 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2142 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2143 | - MAYBE_SWAP (metadata[i])); | |
2144 | ++i; | |
2145 | ||
3876f04e DE |
2146 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2147 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2148 | - MAYBE_SWAP (metadata[i])) | |
2149 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2150 | ++i; |
9291a0cd | 2151 | |
1fd400ff TT |
2152 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2153 | ||
2154 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) | |
2155 | return 0; | |
2156 | ||
8b70b953 TT |
2157 | if (types_list_elements) |
2158 | { | |
2159 | struct dwarf2_section_info *section; | |
2160 | ||
2161 | /* We can only handle a single .debug_types when we have an | |
2162 | index. */ | |
2163 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) | |
2164 | return 0; | |
2165 | ||
2166 | section = VEC_index (dwarf2_section_info_def, | |
2167 | dwarf2_per_objfile->types, 0); | |
2168 | ||
2169 | if (!create_signatured_type_table_from_index (objfile, section, | |
2170 | types_list, | |
2171 | types_list_elements)) | |
2172 | return 0; | |
2173 | } | |
9291a0cd TT |
2174 | |
2175 | create_addrmap_from_index (objfile, map); | |
2176 | ||
2177 | dwarf2_per_objfile->index_table = map; | |
2178 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2179 | dwarf2_per_objfile->quick_file_names_table = |
2180 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2181 | |
2182 | return 1; | |
2183 | } | |
2184 | ||
2185 | /* A helper for the "quick" functions which sets the global | |
2186 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2187 | |
9291a0cd TT |
2188 | static void |
2189 | dw2_setup (struct objfile *objfile) | |
2190 | { | |
2191 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2192 | gdb_assert (dwarf2_per_objfile); | |
2193 | } | |
2194 | ||
2195 | /* A helper for the "quick" functions which attempts to read the line | |
2196 | table for THIS_CU. */ | |
2fdf6df6 | 2197 | |
7b9f3c50 DE |
2198 | static struct quick_file_names * |
2199 | dw2_get_file_names (struct objfile *objfile, | |
2200 | struct dwarf2_per_cu_data *this_cu) | |
9291a0cd TT |
2201 | { |
2202 | bfd *abfd = objfile->obfd; | |
7b9f3c50 | 2203 | struct line_header *lh; |
9291a0cd TT |
2204 | struct attribute *attr; |
2205 | struct cleanup *cleanups; | |
2206 | struct die_info *comp_unit_die; | |
36374493 | 2207 | struct dwarf2_section_info* sec; |
9ff913ba | 2208 | gdb_byte *info_ptr; |
9291a0cd TT |
2209 | int has_children, i; |
2210 | struct dwarf2_cu cu; | |
9ff913ba | 2211 | unsigned int bytes_read; |
9291a0cd TT |
2212 | struct die_reader_specs reader_specs; |
2213 | char *name, *comp_dir; | |
7b9f3c50 DE |
2214 | void **slot; |
2215 | struct quick_file_names *qfn; | |
2216 | unsigned int line_offset; | |
9291a0cd | 2217 | |
7b9f3c50 DE |
2218 | if (this_cu->v.quick->file_names != NULL) |
2219 | return this_cu->v.quick->file_names; | |
2220 | /* If we know there is no line data, no point in looking again. */ | |
2221 | if (this_cu->v.quick->no_file_data) | |
2222 | return NULL; | |
9291a0cd | 2223 | |
23745b47 | 2224 | init_one_comp_unit (&cu, this_cu); |
9291a0cd TT |
2225 | cleanups = make_cleanup (free_stack_comp_unit, &cu); |
2226 | ||
b0df02fd DE |
2227 | if (this_cu->debug_types_section) |
2228 | sec = this_cu->debug_types_section; | |
36374493 DE |
2229 | else |
2230 | sec = &dwarf2_per_objfile->info; | |
2231 | dwarf2_read_section (objfile, sec); | |
9ff913ba | 2232 | info_ptr = sec->buffer + this_cu->offset; |
9291a0cd | 2233 | |
9ff913ba DE |
2234 | info_ptr = read_and_check_comp_unit_head (&cu.header, sec, info_ptr, |
2235 | this_cu->debug_types_section != NULL); | |
9291a0cd | 2236 | |
6caca83c | 2237 | /* Skip dummy compilation units. */ |
9ff913ba | 2238 | if (info_ptr >= (sec->buffer + sec->size) |
6caca83c CC |
2239 | || peek_abbrev_code (abfd, info_ptr) == 0) |
2240 | { | |
2241 | do_cleanups (cleanups); | |
2242 | return NULL; | |
2243 | } | |
2244 | ||
e5fe5e75 | 2245 | dwarf2_read_abbrevs (&cu); |
9291a0cd TT |
2246 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
2247 | ||
9291a0cd | 2248 | init_cu_die_reader (&reader_specs, &cu); |
e8e80198 MS |
2249 | read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
2250 | &has_children); | |
9291a0cd | 2251 | |
7b9f3c50 DE |
2252 | lh = NULL; |
2253 | slot = NULL; | |
2254 | line_offset = 0; | |
9291a0cd TT |
2255 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); |
2256 | if (attr) | |
2257 | { | |
7b9f3c50 DE |
2258 | struct quick_file_names find_entry; |
2259 | ||
2260 | line_offset = DW_UNSND (attr); | |
2261 | ||
2262 | /* We may have already read in this line header (TU line header sharing). | |
2263 | If we have we're done. */ | |
2264 | find_entry.offset = line_offset; | |
2265 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, | |
2266 | &find_entry, INSERT); | |
2267 | if (*slot != NULL) | |
2268 | { | |
2269 | do_cleanups (cleanups); | |
2270 | this_cu->v.quick->file_names = *slot; | |
2271 | return *slot; | |
2272 | } | |
2273 | ||
9291a0cd TT |
2274 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); |
2275 | } | |
2276 | if (lh == NULL) | |
2277 | { | |
2278 | do_cleanups (cleanups); | |
7b9f3c50 DE |
2279 | this_cu->v.quick->no_file_data = 1; |
2280 | return NULL; | |
9291a0cd TT |
2281 | } |
2282 | ||
7b9f3c50 DE |
2283 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
2284 | qfn->offset = line_offset; | |
2285 | gdb_assert (slot != NULL); | |
2286 | *slot = qfn; | |
9291a0cd | 2287 | |
7b9f3c50 | 2288 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); |
9291a0cd | 2289 | |
7b9f3c50 DE |
2290 | qfn->num_file_names = lh->num_file_names; |
2291 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2292 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2293 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2294 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2295 | qfn->real_names = NULL; | |
9291a0cd | 2296 | |
7b9f3c50 | 2297 | free_line_header (lh); |
9291a0cd | 2298 | do_cleanups (cleanups); |
7b9f3c50 DE |
2299 | |
2300 | this_cu->v.quick->file_names = qfn; | |
2301 | return qfn; | |
9291a0cd TT |
2302 | } |
2303 | ||
2304 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2305 | real path for a given file name from the line table. */ |
2fdf6df6 | 2306 | |
9291a0cd | 2307 | static const char * |
7b9f3c50 DE |
2308 | dw2_get_real_path (struct objfile *objfile, |
2309 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2310 | { |
7b9f3c50 DE |
2311 | if (qfn->real_names == NULL) |
2312 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2313 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2314 | |
7b9f3c50 DE |
2315 | if (qfn->real_names[index] == NULL) |
2316 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2317 | |
7b9f3c50 | 2318 | return qfn->real_names[index]; |
9291a0cd TT |
2319 | } |
2320 | ||
2321 | static struct symtab * | |
2322 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2323 | { | |
2324 | int index; | |
ae2de4f8 | 2325 | |
9291a0cd TT |
2326 | dw2_setup (objfile); |
2327 | index = dwarf2_per_objfile->n_comp_units - 1; | |
a0f42c21 | 2328 | return dw2_instantiate_symtab (dw2_get_cu (index)); |
9291a0cd TT |
2329 | } |
2330 | ||
7b9f3c50 DE |
2331 | /* Traversal function for dw2_forget_cached_source_info. */ |
2332 | ||
2333 | static int | |
2334 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2335 | { |
7b9f3c50 | 2336 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2337 | |
7b9f3c50 | 2338 | if (file_data->real_names) |
9291a0cd | 2339 | { |
7b9f3c50 | 2340 | int i; |
9291a0cd | 2341 | |
7b9f3c50 | 2342 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2343 | { |
7b9f3c50 DE |
2344 | xfree ((void*) file_data->real_names[i]); |
2345 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
2346 | } |
2347 | } | |
7b9f3c50 DE |
2348 | |
2349 | return 1; | |
2350 | } | |
2351 | ||
2352 | static void | |
2353 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2354 | { | |
2355 | dw2_setup (objfile); | |
2356 | ||
2357 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
2358 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
2359 | } |
2360 | ||
f8eba3c6 TT |
2361 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
2362 | the symtabs and calls the iterator. */ | |
2363 | ||
2364 | static int | |
2365 | dw2_map_expand_apply (struct objfile *objfile, | |
2366 | struct dwarf2_per_cu_data *per_cu, | |
2367 | const char *name, | |
2368 | const char *full_path, const char *real_path, | |
2369 | int (*callback) (struct symtab *, void *), | |
2370 | void *data) | |
2371 | { | |
2372 | struct symtab *last_made = objfile->symtabs; | |
2373 | ||
2374 | /* Don't visit already-expanded CUs. */ | |
2375 | if (per_cu->v.quick->symtab) | |
2376 | return 0; | |
2377 | ||
2378 | /* This may expand more than one symtab, and we want to iterate over | |
2379 | all of them. */ | |
a0f42c21 | 2380 | dw2_instantiate_symtab (per_cu); |
f8eba3c6 TT |
2381 | |
2382 | return iterate_over_some_symtabs (name, full_path, real_path, callback, data, | |
2383 | objfile->symtabs, last_made); | |
2384 | } | |
2385 | ||
2386 | /* Implementation of the map_symtabs_matching_filename method. */ | |
2387 | ||
9291a0cd | 2388 | static int |
f8eba3c6 TT |
2389 | dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name, |
2390 | const char *full_path, const char *real_path, | |
2391 | int (*callback) (struct symtab *, void *), | |
2392 | void *data) | |
9291a0cd TT |
2393 | { |
2394 | int i; | |
c011a4f4 | 2395 | const char *name_basename = lbasename (name); |
4aac40c8 TT |
2396 | int name_len = strlen (name); |
2397 | int is_abs = IS_ABSOLUTE_PATH (name); | |
9291a0cd TT |
2398 | |
2399 | dw2_setup (objfile); | |
ae2de4f8 | 2400 | |
1fd400ff | 2401 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2402 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2403 | { |
2404 | int j; | |
e254ef6a | 2405 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2406 | struct quick_file_names *file_data; |
9291a0cd | 2407 | |
3d7bb9d9 | 2408 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2409 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2410 | continue; |
2411 | ||
7b9f3c50 DE |
2412 | file_data = dw2_get_file_names (objfile, per_cu); |
2413 | if (file_data == NULL) | |
9291a0cd TT |
2414 | continue; |
2415 | ||
7b9f3c50 | 2416 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2417 | { |
7b9f3c50 | 2418 | const char *this_name = file_data->file_names[j]; |
9291a0cd | 2419 | |
4aac40c8 TT |
2420 | if (FILENAME_CMP (name, this_name) == 0 |
2421 | || (!is_abs && compare_filenames_for_search (this_name, | |
2422 | name, name_len))) | |
9291a0cd | 2423 | { |
f8eba3c6 TT |
2424 | if (dw2_map_expand_apply (objfile, per_cu, |
2425 | name, full_path, real_path, | |
2426 | callback, data)) | |
2427 | return 1; | |
4aac40c8 | 2428 | } |
9291a0cd | 2429 | |
c011a4f4 DE |
2430 | /* Before we invoke realpath, which can get expensive when many |
2431 | files are involved, do a quick comparison of the basenames. */ | |
2432 | if (! basenames_may_differ | |
2433 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) | |
2434 | continue; | |
2435 | ||
9291a0cd TT |
2436 | if (full_path != NULL) |
2437 | { | |
7b9f3c50 DE |
2438 | const char *this_real_name = dw2_get_real_path (objfile, |
2439 | file_data, j); | |
9291a0cd | 2440 | |
7b9f3c50 | 2441 | if (this_real_name != NULL |
4aac40c8 TT |
2442 | && (FILENAME_CMP (full_path, this_real_name) == 0 |
2443 | || (!is_abs | |
2444 | && compare_filenames_for_search (this_real_name, | |
2445 | name, name_len)))) | |
9291a0cd | 2446 | { |
f8eba3c6 TT |
2447 | if (dw2_map_expand_apply (objfile, per_cu, |
2448 | name, full_path, real_path, | |
2449 | callback, data)) | |
2450 | return 1; | |
9291a0cd TT |
2451 | } |
2452 | } | |
2453 | ||
2454 | if (real_path != NULL) | |
2455 | { | |
7b9f3c50 DE |
2456 | const char *this_real_name = dw2_get_real_path (objfile, |
2457 | file_data, j); | |
9291a0cd | 2458 | |
7b9f3c50 | 2459 | if (this_real_name != NULL |
4aac40c8 TT |
2460 | && (FILENAME_CMP (real_path, this_real_name) == 0 |
2461 | || (!is_abs | |
2462 | && compare_filenames_for_search (this_real_name, | |
2463 | name, name_len)))) | |
9291a0cd | 2464 | { |
f8eba3c6 TT |
2465 | if (dw2_map_expand_apply (objfile, per_cu, |
2466 | name, full_path, real_path, | |
2467 | callback, data)) | |
2468 | return 1; | |
9291a0cd TT |
2469 | } |
2470 | } | |
2471 | } | |
2472 | } | |
2473 | ||
9291a0cd TT |
2474 | return 0; |
2475 | } | |
2476 | ||
2477 | static struct symtab * | |
2478 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2479 | const char *name, domain_enum domain) | |
2480 | { | |
774b6a14 | 2481 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2482 | instead. */ |
2483 | return NULL; | |
2484 | } | |
2485 | ||
2486 | /* A helper function that expands all symtabs that hold an object | |
2487 | named NAME. */ | |
2fdf6df6 | 2488 | |
9291a0cd TT |
2489 | static void |
2490 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2491 | { | |
2492 | dw2_setup (objfile); | |
2493 | ||
ae2de4f8 | 2494 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2495 | if (dwarf2_per_objfile->index_table) |
2496 | { | |
2497 | offset_type *vec; | |
2498 | ||
2499 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2500 | name, &vec)) | |
2501 | { | |
2502 | offset_type i, len = MAYBE_SWAP (*vec); | |
2503 | for (i = 0; i < len; ++i) | |
2504 | { | |
2505 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2506 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2507 | |
a0f42c21 | 2508 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2509 | } |
2510 | } | |
2511 | } | |
2512 | } | |
2513 | ||
774b6a14 TT |
2514 | static void |
2515 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
8903c50d | 2516 | enum block_enum block_kind, const char *name, |
774b6a14 | 2517 | domain_enum domain) |
9291a0cd | 2518 | { |
774b6a14 | 2519 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2520 | } |
2521 | ||
2522 | static void | |
2523 | dw2_print_stats (struct objfile *objfile) | |
2524 | { | |
2525 | int i, count; | |
2526 | ||
2527 | dw2_setup (objfile); | |
2528 | count = 0; | |
1fd400ff | 2529 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2530 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2531 | { |
e254ef6a | 2532 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2533 | |
e254ef6a | 2534 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2535 | ++count; |
2536 | } | |
2537 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2538 | } | |
2539 | ||
2540 | static void | |
2541 | dw2_dump (struct objfile *objfile) | |
2542 | { | |
2543 | /* Nothing worth printing. */ | |
2544 | } | |
2545 | ||
2546 | static void | |
2547 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2548 | struct section_offsets *delta) | |
2549 | { | |
2550 | /* There's nothing to relocate here. */ | |
2551 | } | |
2552 | ||
2553 | static void | |
2554 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2555 | const char *func_name) | |
2556 | { | |
2557 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2558 | } | |
2559 | ||
2560 | static void | |
2561 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2562 | { | |
2563 | int i; | |
2564 | ||
2565 | dw2_setup (objfile); | |
1fd400ff TT |
2566 | |
2567 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 2568 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2569 | { |
e254ef6a | 2570 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2571 | |
a0f42c21 | 2572 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2573 | } |
2574 | } | |
2575 | ||
2576 | static void | |
2577 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2578 | const char *filename) | |
2579 | { | |
2580 | int i; | |
2581 | ||
2582 | dw2_setup (objfile); | |
d4637a04 DE |
2583 | |
2584 | /* We don't need to consider type units here. | |
2585 | This is only called for examining code, e.g. expand_line_sal. | |
2586 | There can be an order of magnitude (or more) more type units | |
2587 | than comp units, and we avoid them if we can. */ | |
2588 | ||
2589 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
2590 | { |
2591 | int j; | |
e254ef6a | 2592 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2593 | struct quick_file_names *file_data; |
9291a0cd | 2594 | |
3d7bb9d9 | 2595 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2596 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2597 | continue; |
2598 | ||
7b9f3c50 DE |
2599 | file_data = dw2_get_file_names (objfile, per_cu); |
2600 | if (file_data == NULL) | |
9291a0cd TT |
2601 | continue; |
2602 | ||
7b9f3c50 | 2603 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2604 | { |
7b9f3c50 | 2605 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 2606 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 2607 | { |
a0f42c21 | 2608 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2609 | break; |
2610 | } | |
2611 | } | |
2612 | } | |
2613 | } | |
2614 | ||
dd786858 | 2615 | static const char * |
9291a0cd TT |
2616 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2617 | { | |
e254ef6a | 2618 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 2619 | offset_type *vec; |
7b9f3c50 | 2620 | struct quick_file_names *file_data; |
9291a0cd TT |
2621 | |
2622 | dw2_setup (objfile); | |
2623 | ||
ae2de4f8 | 2624 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd | 2625 | if (!dwarf2_per_objfile->index_table) |
96408a79 SA |
2626 | { |
2627 | struct symtab *s; | |
2628 | ||
2629 | ALL_OBJFILE_SYMTABS (objfile, s) | |
2630 | if (s->primary) | |
2631 | { | |
2632 | struct blockvector *bv = BLOCKVECTOR (s); | |
2633 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
2634 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); | |
2635 | ||
2636 | if (sym) | |
2637 | return sym->symtab->filename; | |
2638 | } | |
2639 | return NULL; | |
2640 | } | |
9291a0cd TT |
2641 | |
2642 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2643 | name, &vec)) | |
2644 | return NULL; | |
2645 | ||
2646 | /* Note that this just looks at the very first one named NAME -- but | |
2647 | actually we are looking for a function. find_main_filename | |
2648 | should be rewritten so that it doesn't require a custom hook. It | |
2649 | could just use the ordinary symbol tables. */ | |
2650 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2651 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2652 | |
7b9f3c50 DE |
2653 | file_data = dw2_get_file_names (objfile, per_cu); |
2654 | if (file_data == NULL) | |
9291a0cd TT |
2655 | return NULL; |
2656 | ||
7b9f3c50 | 2657 | return file_data->file_names[file_data->num_file_names - 1]; |
9291a0cd TT |
2658 | } |
2659 | ||
2660 | static void | |
40658b94 PH |
2661 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
2662 | struct objfile *objfile, int global, | |
2663 | int (*callback) (struct block *, | |
2664 | struct symbol *, void *), | |
2edb89d3 JK |
2665 | void *data, symbol_compare_ftype *match, |
2666 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 2667 | { |
40658b94 | 2668 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
2669 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
2670 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
2671 | } |
2672 | ||
2673 | static void | |
f8eba3c6 TT |
2674 | dw2_expand_symtabs_matching |
2675 | (struct objfile *objfile, | |
2676 | int (*file_matcher) (const char *, void *), | |
e078317b | 2677 | int (*name_matcher) (const char *, void *), |
f8eba3c6 TT |
2678 | enum search_domain kind, |
2679 | void *data) | |
9291a0cd TT |
2680 | { |
2681 | int i; | |
2682 | offset_type iter; | |
4b5246aa | 2683 | struct mapped_index *index; |
9291a0cd TT |
2684 | |
2685 | dw2_setup (objfile); | |
ae2de4f8 DE |
2686 | |
2687 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
2688 | if (!dwarf2_per_objfile->index_table) |
2689 | return; | |
4b5246aa | 2690 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 2691 | |
7b08b9eb | 2692 | if (file_matcher != NULL) |
24c79950 TT |
2693 | { |
2694 | struct cleanup *cleanup; | |
2695 | htab_t visited_found, visited_not_found; | |
2696 | ||
2697 | visited_found = htab_create_alloc (10, | |
2698 | htab_hash_pointer, htab_eq_pointer, | |
2699 | NULL, xcalloc, xfree); | |
2700 | cleanup = make_cleanup_htab_delete (visited_found); | |
2701 | visited_not_found = htab_create_alloc (10, | |
2702 | htab_hash_pointer, htab_eq_pointer, | |
2703 | NULL, xcalloc, xfree); | |
2704 | make_cleanup_htab_delete (visited_not_found); | |
2705 | ||
2706 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2707 | + dwarf2_per_objfile->n_type_units); ++i) | |
2708 | { | |
2709 | int j; | |
2710 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2711 | struct quick_file_names *file_data; | |
2712 | void **slot; | |
7b08b9eb | 2713 | |
24c79950 | 2714 | per_cu->v.quick->mark = 0; |
3d7bb9d9 | 2715 | |
24c79950 TT |
2716 | /* We only need to look at symtabs not already expanded. */ |
2717 | if (per_cu->v.quick->symtab) | |
2718 | continue; | |
7b08b9eb | 2719 | |
24c79950 TT |
2720 | file_data = dw2_get_file_names (objfile, per_cu); |
2721 | if (file_data == NULL) | |
2722 | continue; | |
7b08b9eb | 2723 | |
24c79950 TT |
2724 | if (htab_find (visited_not_found, file_data) != NULL) |
2725 | continue; | |
2726 | else if (htab_find (visited_found, file_data) != NULL) | |
2727 | { | |
2728 | per_cu->v.quick->mark = 1; | |
2729 | continue; | |
2730 | } | |
2731 | ||
2732 | for (j = 0; j < file_data->num_file_names; ++j) | |
2733 | { | |
2734 | if (file_matcher (file_data->file_names[j], data)) | |
2735 | { | |
2736 | per_cu->v.quick->mark = 1; | |
2737 | break; | |
2738 | } | |
2739 | } | |
2740 | ||
2741 | slot = htab_find_slot (per_cu->v.quick->mark | |
2742 | ? visited_found | |
2743 | : visited_not_found, | |
2744 | file_data, INSERT); | |
2745 | *slot = file_data; | |
2746 | } | |
2747 | ||
2748 | do_cleanups (cleanup); | |
2749 | } | |
9291a0cd | 2750 | |
3876f04e | 2751 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
2752 | { |
2753 | offset_type idx = 2 * iter; | |
2754 | const char *name; | |
2755 | offset_type *vec, vec_len, vec_idx; | |
2756 | ||
3876f04e | 2757 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
2758 | continue; |
2759 | ||
3876f04e | 2760 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd | 2761 | |
e078317b | 2762 | if (! (*name_matcher) (name, data)) |
9291a0cd TT |
2763 | continue; |
2764 | ||
2765 | /* The name was matched, now expand corresponding CUs that were | |
2766 | marked. */ | |
4b5246aa | 2767 | vec = (offset_type *) (index->constant_pool |
3876f04e | 2768 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
2769 | vec_len = MAYBE_SWAP (vec[0]); |
2770 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2771 | { | |
e254ef6a | 2772 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2773 | |
e254ef6a | 2774 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
7b08b9eb | 2775 | if (file_matcher == NULL || per_cu->v.quick->mark) |
a0f42c21 | 2776 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2777 | } |
2778 | } | |
2779 | } | |
2780 | ||
2781 | static struct symtab * | |
2782 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2783 | struct minimal_symbol *msymbol, | |
2784 | CORE_ADDR pc, | |
2785 | struct obj_section *section, | |
2786 | int warn_if_readin) | |
2787 | { | |
2788 | struct dwarf2_per_cu_data *data; | |
2789 | ||
2790 | dw2_setup (objfile); | |
2791 | ||
2792 | if (!objfile->psymtabs_addrmap) | |
2793 | return NULL; | |
2794 | ||
2795 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2796 | if (!data) | |
2797 | return NULL; | |
2798 | ||
2799 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2800 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2801 | paddress (get_objfile_arch (objfile), pc)); |
2802 | ||
a0f42c21 | 2803 | return dw2_instantiate_symtab (data); |
9291a0cd TT |
2804 | } |
2805 | ||
9291a0cd | 2806 | static void |
44b13c5a | 2807 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
74e2f255 | 2808 | void *data, int need_fullname) |
9291a0cd TT |
2809 | { |
2810 | int i; | |
24c79950 TT |
2811 | struct cleanup *cleanup; |
2812 | htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer, | |
2813 | NULL, xcalloc, xfree); | |
9291a0cd | 2814 | |
24c79950 | 2815 | cleanup = make_cleanup_htab_delete (visited); |
9291a0cd | 2816 | dw2_setup (objfile); |
ae2de4f8 | 2817 | |
24c79950 TT |
2818 | /* We can ignore file names coming from already-expanded CUs. */ |
2819 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2820 | + dwarf2_per_objfile->n_type_units); ++i) | |
2821 | { | |
2822 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2823 | ||
2824 | if (per_cu->v.quick->symtab) | |
2825 | { | |
2826 | void **slot = htab_find_slot (visited, per_cu->v.quick->file_names, | |
2827 | INSERT); | |
2828 | ||
2829 | *slot = per_cu->v.quick->file_names; | |
2830 | } | |
2831 | } | |
2832 | ||
1fd400ff | 2833 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2834 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2835 | { |
2836 | int j; | |
e254ef6a | 2837 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2838 | struct quick_file_names *file_data; |
24c79950 | 2839 | void **slot; |
9291a0cd | 2840 | |
3d7bb9d9 | 2841 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2842 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2843 | continue; |
2844 | ||
7b9f3c50 DE |
2845 | file_data = dw2_get_file_names (objfile, per_cu); |
2846 | if (file_data == NULL) | |
9291a0cd TT |
2847 | continue; |
2848 | ||
24c79950 TT |
2849 | slot = htab_find_slot (visited, file_data, INSERT); |
2850 | if (*slot) | |
2851 | { | |
2852 | /* Already visited. */ | |
2853 | continue; | |
2854 | } | |
2855 | *slot = file_data; | |
2856 | ||
7b9f3c50 | 2857 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2858 | { |
74e2f255 DE |
2859 | const char *this_real_name; |
2860 | ||
2861 | if (need_fullname) | |
2862 | this_real_name = dw2_get_real_path (objfile, file_data, j); | |
2863 | else | |
2864 | this_real_name = NULL; | |
7b9f3c50 | 2865 | (*fun) (file_data->file_names[j], this_real_name, data); |
9291a0cd TT |
2866 | } |
2867 | } | |
24c79950 TT |
2868 | |
2869 | do_cleanups (cleanup); | |
9291a0cd TT |
2870 | } |
2871 | ||
2872 | static int | |
2873 | dw2_has_symbols (struct objfile *objfile) | |
2874 | { | |
2875 | return 1; | |
2876 | } | |
2877 | ||
2878 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2879 | { | |
2880 | dw2_has_symbols, | |
2881 | dw2_find_last_source_symtab, | |
2882 | dw2_forget_cached_source_info, | |
f8eba3c6 | 2883 | dw2_map_symtabs_matching_filename, |
9291a0cd | 2884 | dw2_lookup_symbol, |
774b6a14 | 2885 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
2886 | dw2_print_stats, |
2887 | dw2_dump, | |
2888 | dw2_relocate, | |
2889 | dw2_expand_symtabs_for_function, | |
2890 | dw2_expand_all_symtabs, | |
2891 | dw2_expand_symtabs_with_filename, | |
2892 | dw2_find_symbol_file, | |
40658b94 | 2893 | dw2_map_matching_symbols, |
9291a0cd TT |
2894 | dw2_expand_symtabs_matching, |
2895 | dw2_find_pc_sect_symtab, | |
9291a0cd TT |
2896 | dw2_map_symbol_filenames |
2897 | }; | |
2898 | ||
2899 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2900 | file will use psymtabs, or 1 if using the GNU index. */ | |
2901 | ||
2902 | int | |
2903 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2904 | { | |
2905 | /* If we're about to read full symbols, don't bother with the | |
2906 | indices. In this case we also don't care if some other debug | |
2907 | format is making psymtabs, because they are all about to be | |
2908 | expanded anyway. */ | |
2909 | if ((objfile->flags & OBJF_READNOW)) | |
2910 | { | |
2911 | int i; | |
2912 | ||
2913 | dwarf2_per_objfile->using_index = 1; | |
2914 | create_all_comp_units (objfile); | |
1fd400ff | 2915 | create_debug_types_hash_table (objfile); |
7b9f3c50 DE |
2916 | dwarf2_per_objfile->quick_file_names_table = |
2917 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 2918 | |
1fd400ff | 2919 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2920 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2921 | { |
e254ef6a | 2922 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2923 | |
e254ef6a DE |
2924 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2925 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
2926 | } |
2927 | ||
2928 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2929 | these functions will be no-ops because we will have expanded | |
2930 | all symtabs. */ | |
2931 | return 1; | |
2932 | } | |
2933 | ||
2934 | if (dwarf2_read_index (objfile)) | |
2935 | return 1; | |
2936 | ||
9291a0cd TT |
2937 | return 0; |
2938 | } | |
2939 | ||
2940 | \f | |
2941 | ||
dce234bc PP |
2942 | /* Build a partial symbol table. */ |
2943 | ||
2944 | void | |
f29dff0a | 2945 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2946 | { |
f29dff0a | 2947 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2948 | { |
2949 | init_psymbol_list (objfile, 1024); | |
2950 | } | |
2951 | ||
d146bf1e | 2952 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2953 | } |
c906108c | 2954 | |
45452591 DE |
2955 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2956 | ||
2957 | static inline int | |
2958 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2959 | { | |
2960 | unsigned int bottom = cu_header->offset; | |
2961 | unsigned int top = (cu_header->offset | |
2962 | + cu_header->length | |
2963 | + cu_header->initial_length_size); | |
9a619af0 | 2964 | |
45452591 DE |
2965 | return (offset >= bottom && offset < top); |
2966 | } | |
2967 | ||
93311388 DE |
2968 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2969 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2970 | by the caller. */ | |
107d2387 | 2971 | |
fe1b8b76 | 2972 | static gdb_byte * |
107d2387 | 2973 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2974 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2975 | { |
2976 | int signed_addr; | |
891d2f0b | 2977 | unsigned int bytes_read; |
c764a876 DE |
2978 | |
2979 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2980 | cu_header->initial_length_size = bytes_read; | |
2981 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2982 | info_ptr += bytes_read; |
107d2387 AC |
2983 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2984 | info_ptr += 2; | |
613e1657 | 2985 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2986 | &bytes_read); |
613e1657 | 2987 | info_ptr += bytes_read; |
107d2387 AC |
2988 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2989 | info_ptr += 1; | |
2990 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2991 | if (signed_addr < 0) | |
8e65ff28 | 2992 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2993 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2994 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2995 | |
107d2387 AC |
2996 | return info_ptr; |
2997 | } | |
2998 | ||
9ff913ba DE |
2999 | /* Subroutine of read_and_check_comp_unit_head and |
3000 | read_and_check_type_unit_head to simplify them. | |
3001 | Perform various error checking on the header. */ | |
3002 | ||
3003 | static void | |
3004 | error_check_comp_unit_head (struct comp_unit_head *header, | |
3005 | struct dwarf2_section_info *section) | |
3006 | { | |
3007 | bfd *abfd = section->asection->owner; | |
3008 | const char *filename = bfd_get_filename (abfd); | |
3009 | ||
3010 | if (header->version != 2 && header->version != 3 && header->version != 4) | |
3011 | error (_("Dwarf Error: wrong version in compilation unit header " | |
3012 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, | |
3013 | filename); | |
3014 | ||
3015 | if (header->abbrev_offset | |
3016 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, | |
3017 | &dwarf2_per_objfile->abbrev)) | |
3018 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " | |
3019 | "(offset 0x%lx + 6) [in module %s]"), | |
3020 | (long) header->abbrev_offset, (long) header->offset, | |
3021 | filename); | |
3022 | ||
3023 | /* Cast to unsigned long to use 64-bit arithmetic when possible to | |
3024 | avoid potential 32-bit overflow. */ | |
3025 | if (((unsigned long) header->offset | |
3026 | + header->length + header->initial_length_size) | |
3027 | > section->size) | |
3028 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " | |
3029 | "(offset 0x%lx + 0) [in module %s]"), | |
3030 | (long) header->length, (long) header->offset, | |
3031 | filename); | |
3032 | } | |
3033 | ||
3034 | /* Read in a CU/TU header and perform some basic error checking. | |
3035 | The contents of the header are stored in HEADER. | |
3036 | The result is a pointer to the start of the first DIE. */ | |
adabb602 | 3037 | |
fe1b8b76 | 3038 | static gdb_byte * |
9ff913ba DE |
3039 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
3040 | struct dwarf2_section_info *section, | |
3041 | gdb_byte *info_ptr, | |
3042 | int is_debug_types_section) | |
72bf9492 | 3043 | { |
fe1b8b76 | 3044 | gdb_byte *beg_of_comp_unit = info_ptr; |
9ff913ba | 3045 | bfd *abfd = section->asection->owner; |
72bf9492 | 3046 | |
9ff913ba | 3047 | header->offset = beg_of_comp_unit - section->buffer; |
adabb602 | 3048 | |
72bf9492 DJ |
3049 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
3050 | ||
460c1c54 CC |
3051 | /* If we're reading a type unit, skip over the signature and |
3052 | type_offset fields. */ | |
b0df02fd | 3053 | if (is_debug_types_section) |
460c1c54 CC |
3054 | info_ptr += 8 /*signature*/ + header->offset_size; |
3055 | ||
adabb602 DE |
3056 | header->first_die_offset = info_ptr - beg_of_comp_unit; |
3057 | ||
9ff913ba | 3058 | error_check_comp_unit_head (header, section); |
72bf9492 DJ |
3059 | |
3060 | return info_ptr; | |
3061 | } | |
3062 | ||
348e048f DE |
3063 | /* Read in the types comp unit header information from .debug_types entry at |
3064 | types_ptr. The result is a pointer to one past the end of the header. */ | |
3065 | ||
3066 | static gdb_byte * | |
9ff913ba DE |
3067 | read_and_check_type_unit_head (struct comp_unit_head *header, |
3068 | struct dwarf2_section_info *section, | |
3069 | gdb_byte *info_ptr, | |
3070 | ULONGEST *signature, unsigned int *type_offset) | |
348e048f | 3071 | { |
9ff913ba DE |
3072 | gdb_byte *beg_of_comp_unit = info_ptr; |
3073 | bfd *abfd = section->asection->owner; | |
348e048f | 3074 | |
9ff913ba | 3075 | header->offset = beg_of_comp_unit - section->buffer; |
348e048f | 3076 | |
9ff913ba | 3077 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
348e048f | 3078 | |
9ff913ba DE |
3079 | /* If we're reading a type unit, skip over the signature and |
3080 | type_offset fields. */ | |
3081 | if (signature != NULL) | |
3082 | *signature = read_8_bytes (abfd, info_ptr); | |
3083 | info_ptr += 8; | |
3084 | if (type_offset != NULL) | |
3085 | *type_offset = read_offset_1 (abfd, info_ptr, header->offset_size); | |
3086 | info_ptr += header->offset_size; | |
3087 | ||
3088 | header->first_die_offset = info_ptr - beg_of_comp_unit; | |
348e048f | 3089 | |
9ff913ba DE |
3090 | error_check_comp_unit_head (header, section); |
3091 | ||
3092 | return info_ptr; | |
348e048f DE |
3093 | } |
3094 | ||
aaa75496 JB |
3095 | /* Allocate a new partial symtab for file named NAME and mark this new |
3096 | partial symtab as being an include of PST. */ | |
3097 | ||
3098 | static void | |
3099 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
3100 | struct objfile *objfile) | |
3101 | { | |
3102 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
3103 | ||
3104 | subpst->section_offsets = pst->section_offsets; | |
3105 | subpst->textlow = 0; | |
3106 | subpst->texthigh = 0; | |
3107 | ||
3108 | subpst->dependencies = (struct partial_symtab **) | |
3109 | obstack_alloc (&objfile->objfile_obstack, | |
3110 | sizeof (struct partial_symtab *)); | |
3111 | subpst->dependencies[0] = pst; | |
3112 | subpst->number_of_dependencies = 1; | |
3113 | ||
3114 | subpst->globals_offset = 0; | |
3115 | subpst->n_global_syms = 0; | |
3116 | subpst->statics_offset = 0; | |
3117 | subpst->n_static_syms = 0; | |
3118 | subpst->symtab = NULL; | |
3119 | subpst->read_symtab = pst->read_symtab; | |
3120 | subpst->readin = 0; | |
3121 | ||
3122 | /* No private part is necessary for include psymtabs. This property | |
3123 | can be used to differentiate between such include psymtabs and | |
10b3939b | 3124 | the regular ones. */ |
58a9656e | 3125 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
3126 | } |
3127 | ||
3128 | /* Read the Line Number Program data and extract the list of files | |
3129 | included by the source file represented by PST. Build an include | |
d85a05f0 | 3130 | partial symtab for each of these included files. */ |
aaa75496 JB |
3131 | |
3132 | static void | |
3133 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 3134 | struct die_info *die, |
aaa75496 JB |
3135 | struct partial_symtab *pst) |
3136 | { | |
3137 | struct objfile *objfile = cu->objfile; | |
3138 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
3139 | struct line_header *lh = NULL; |
3140 | struct attribute *attr; | |
aaa75496 | 3141 | |
d85a05f0 DJ |
3142 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
3143 | if (attr) | |
3144 | { | |
3145 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 3146 | |
d85a05f0 DJ |
3147 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
3148 | } | |
aaa75496 JB |
3149 | if (lh == NULL) |
3150 | return; /* No linetable, so no includes. */ | |
3151 | ||
c6da4cef | 3152 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
f3f5162e | 3153 | dwarf_decode_lines (lh, pst->dirname, cu, pst, 1); |
aaa75496 JB |
3154 | |
3155 | free_line_header (lh); | |
3156 | } | |
3157 | ||
348e048f DE |
3158 | static hashval_t |
3159 | hash_type_signature (const void *item) | |
3160 | { | |
3161 | const struct signatured_type *type_sig = item; | |
9a619af0 | 3162 | |
348e048f DE |
3163 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
3164 | return type_sig->signature; | |
3165 | } | |
3166 | ||
3167 | static int | |
3168 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
3169 | { | |
3170 | const struct signatured_type *lhs = item_lhs; | |
3171 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 3172 | |
348e048f DE |
3173 | return lhs->signature == rhs->signature; |
3174 | } | |
3175 | ||
1fd400ff TT |
3176 | /* Allocate a hash table for signatured types. */ |
3177 | ||
3178 | static htab_t | |
673bfd45 | 3179 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
3180 | { |
3181 | return htab_create_alloc_ex (41, | |
3182 | hash_type_signature, | |
3183 | eq_type_signature, | |
3184 | NULL, | |
3185 | &objfile->objfile_obstack, | |
3186 | hashtab_obstack_allocate, | |
3187 | dummy_obstack_deallocate); | |
3188 | } | |
3189 | ||
d467dd73 | 3190 | /* A helper function to add a signatured type CU to a table. */ |
1fd400ff TT |
3191 | |
3192 | static int | |
d467dd73 | 3193 | add_signatured_type_cu_to_table (void **slot, void *datum) |
1fd400ff TT |
3194 | { |
3195 | struct signatured_type *sigt = *slot; | |
3196 | struct dwarf2_per_cu_data ***datap = datum; | |
3197 | ||
3198 | **datap = &sigt->per_cu; | |
3199 | ++*datap; | |
3200 | ||
3201 | return 1; | |
3202 | } | |
3203 | ||
d467dd73 | 3204 | /* Create the hash table of all entries in the .debug_types section(s). |
348e048f DE |
3205 | The result is zero if there is an error (e.g. missing .debug_types section), |
3206 | otherwise non-zero. */ | |
3207 | ||
3208 | static int | |
3209 | create_debug_types_hash_table (struct objfile *objfile) | |
3210 | { | |
8b70b953 | 3211 | htab_t types_htab = NULL; |
1fd400ff | 3212 | struct dwarf2_per_cu_data **iter; |
8b70b953 TT |
3213 | int ix; |
3214 | struct dwarf2_section_info *section; | |
348e048f | 3215 | |
8b70b953 | 3216 | if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)) |
348e048f DE |
3217 | { |
3218 | dwarf2_per_objfile->signatured_types = NULL; | |
3219 | return 0; | |
3220 | } | |
3221 | ||
8b70b953 TT |
3222 | for (ix = 0; |
3223 | VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
3224 | ix, section); | |
3225 | ++ix) | |
3226 | { | |
3227 | gdb_byte *info_ptr, *end_ptr; | |
348e048f | 3228 | |
8b70b953 TT |
3229 | dwarf2_read_section (objfile, section); |
3230 | info_ptr = section->buffer; | |
348e048f | 3231 | |
8b70b953 TT |
3232 | if (info_ptr == NULL) |
3233 | continue; | |
348e048f | 3234 | |
8b70b953 TT |
3235 | if (types_htab == NULL) |
3236 | types_htab = allocate_signatured_type_table (objfile); | |
348e048f | 3237 | |
8b70b953 TT |
3238 | if (dwarf2_die_debug) |
3239 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
3240 | ||
3241 | end_ptr = info_ptr + section->size; | |
3242 | while (info_ptr < end_ptr) | |
3243 | { | |
3244 | unsigned int offset; | |
8b70b953 | 3245 | unsigned int type_offset; |
8b70b953 TT |
3246 | ULONGEST signature; |
3247 | struct signatured_type *type_sig; | |
3248 | void **slot; | |
3249 | gdb_byte *ptr = info_ptr; | |
9ff913ba | 3250 | struct comp_unit_head header; |
348e048f | 3251 | |
8b70b953 | 3252 | offset = ptr - section->buffer; |
348e048f | 3253 | |
8b70b953 | 3254 | /* We need to read the type's signature in order to build the hash |
9ff913ba | 3255 | table, but we don't need anything else just yet. */ |
348e048f | 3256 | |
9ff913ba DE |
3257 | ptr = read_and_check_type_unit_head (&header, section, ptr, |
3258 | &signature, &type_offset); | |
6caca83c CC |
3259 | |
3260 | /* Skip dummy type units. */ | |
3261 | if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0) | |
3262 | { | |
9ff913ba | 3263 | info_ptr = info_ptr + header.initial_length_size + header.length; |
6caca83c CC |
3264 | continue; |
3265 | } | |
8b70b953 TT |
3266 | |
3267 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
3268 | memset (type_sig, 0, sizeof (*type_sig)); | |
3269 | type_sig->signature = signature; | |
3270 | type_sig->type_offset = type_offset; | |
3271 | type_sig->per_cu.objfile = objfile; | |
b0df02fd | 3272 | type_sig->per_cu.debug_types_section = section; |
8b70b953 TT |
3273 | type_sig->per_cu.offset = offset; |
3274 | ||
3275 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
3276 | gdb_assert (slot != NULL); | |
3277 | if (*slot != NULL) | |
3278 | { | |
3279 | const struct signatured_type *dup_sig = *slot; | |
b3c8eb43 | 3280 | |
8b70b953 TT |
3281 | complaint (&symfile_complaints, |
3282 | _("debug type entry at offset 0x%x is duplicate to the " | |
3283 | "entry at offset 0x%x, signature 0x%s"), | |
3284 | offset, dup_sig->per_cu.offset, | |
3285 | phex (signature, sizeof (signature))); | |
3286 | gdb_assert (signature == dup_sig->signature); | |
3287 | } | |
3288 | *slot = type_sig; | |
348e048f | 3289 | |
8b70b953 TT |
3290 | if (dwarf2_die_debug) |
3291 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
3292 | offset, phex (signature, sizeof (signature))); | |
348e048f | 3293 | |
9ff913ba | 3294 | info_ptr = info_ptr + header.initial_length_size + header.length; |
8b70b953 | 3295 | } |
348e048f DE |
3296 | } |
3297 | ||
3298 | dwarf2_per_objfile->signatured_types = types_htab; | |
3299 | ||
d467dd73 DE |
3300 | dwarf2_per_objfile->n_type_units = htab_elements (types_htab); |
3301 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 3302 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 3303 | dwarf2_per_objfile->n_type_units |
1fd400ff | 3304 | * sizeof (struct dwarf2_per_cu_data *)); |
d467dd73 DE |
3305 | iter = &dwarf2_per_objfile->all_type_units[0]; |
3306 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); | |
3307 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] | |
3308 | == dwarf2_per_objfile->n_type_units); | |
1fd400ff | 3309 | |
348e048f DE |
3310 | return 1; |
3311 | } | |
3312 | ||
3313 | /* Lookup a signature based type. | |
3314 | Returns NULL if SIG is not present in the table. */ | |
3315 | ||
3316 | static struct signatured_type * | |
3317 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
3318 | { | |
3319 | struct signatured_type find_entry, *entry; | |
3320 | ||
3321 | if (dwarf2_per_objfile->signatured_types == NULL) | |
3322 | { | |
3323 | complaint (&symfile_complaints, | |
55f1336d | 3324 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
348e048f DE |
3325 | return 0; |
3326 | } | |
3327 | ||
3328 | find_entry.signature = sig; | |
3329 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
3330 | return entry; | |
3331 | } | |
3332 | ||
d85a05f0 DJ |
3333 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
3334 | ||
3335 | static void | |
3336 | init_cu_die_reader (struct die_reader_specs *reader, | |
3337 | struct dwarf2_cu *cu) | |
3338 | { | |
3339 | reader->abfd = cu->objfile->obfd; | |
3340 | reader->cu = cu; | |
b0df02fd | 3341 | if (cu->per_cu->debug_types_section) |
be391dca | 3342 | { |
b0df02fd DE |
3343 | gdb_assert (cu->per_cu->debug_types_section->readin); |
3344 | reader->buffer = cu->per_cu->debug_types_section->buffer; | |
be391dca | 3345 | } |
d85a05f0 | 3346 | else |
be391dca TT |
3347 | { |
3348 | gdb_assert (dwarf2_per_objfile->info.readin); | |
3349 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
3350 | } | |
d85a05f0 DJ |
3351 | } |
3352 | ||
3353 | /* Find the base address of the compilation unit for range lists and | |
3354 | location lists. It will normally be specified by DW_AT_low_pc. | |
3355 | In DWARF-3 draft 4, the base address could be overridden by | |
3356 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3357 | compilation units with discontinuous ranges. */ | |
3358 | ||
3359 | static void | |
3360 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3361 | { | |
3362 | struct attribute *attr; | |
3363 | ||
3364 | cu->base_known = 0; | |
3365 | cu->base_address = 0; | |
3366 | ||
3367 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3368 | if (attr) | |
3369 | { | |
3370 | cu->base_address = DW_ADDR (attr); | |
3371 | cu->base_known = 1; | |
3372 | } | |
3373 | else | |
3374 | { | |
3375 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3376 | if (attr) | |
3377 | { | |
3378 | cu->base_address = DW_ADDR (attr); | |
3379 | cu->base_known = 1; | |
3380 | } | |
3381 | } | |
3382 | } | |
3383 | ||
348e048f DE |
3384 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
3385 | to combine the common parts. | |
21b2bd31 DE |
3386 | Process compilation unit THIS_CU for a psymtab. |
3387 | SECTION is the section the CU/TU comes from, | |
3388 | either .debug_info or .debug_types. */ | |
aaa75496 | 3389 | |
70221824 | 3390 | static void |
a0f42c21 | 3391 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, |
21b2bd31 DE |
3392 | struct dwarf2_section_info *section, |
3393 | int is_debug_types_section) | |
c906108c | 3394 | { |
a0f42c21 | 3395 | struct objfile *objfile = this_cu->objfile; |
c906108c | 3396 | bfd *abfd = objfile->obfd; |
21b2bd31 DE |
3397 | gdb_byte *buffer = section->buffer; |
3398 | gdb_byte *info_ptr = buffer + this_cu->offset; | |
3399 | unsigned int buffer_size = section->size; | |
93311388 | 3400 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 3401 | struct die_info *comp_unit_die; |
c906108c | 3402 | struct partial_symtab *pst; |
5734ee8b | 3403 | CORE_ADDR baseaddr; |
93311388 DE |
3404 | struct cleanup *back_to_inner; |
3405 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
3406 | int has_children, has_pc_info; |
3407 | struct attribute *attr; | |
d85a05f0 DJ |
3408 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
3409 | struct die_reader_specs reader_specs; | |
3e2a0cee | 3410 | const char *filename; |
c906108c | 3411 | |
23745b47 DE |
3412 | /* If this compilation unit was already read in, free the |
3413 | cached copy in order to read it in again. This is | |
3414 | necessary because we skipped some symbols when we first | |
3415 | read in the compilation unit (see load_partial_dies). | |
3416 | This problem could be avoided, but the benefit is | |
3417 | unclear. */ | |
3418 | if (this_cu->cu != NULL) | |
3419 | free_one_cached_comp_unit (this_cu->cu); | |
3420 | ||
3421 | /* Note that this is a pointer to our stack frame, being | |
3422 | added to a global data structure. It will be cleaned up | |
3423 | in free_stack_comp_unit when we finish with this | |
3424 | compilation unit. */ | |
3425 | init_one_comp_unit (&cu, this_cu); | |
93311388 | 3426 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 3427 | |
9ff913ba DE |
3428 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr, |
3429 | is_debug_types_section); | |
10b3939b | 3430 | |
6caca83c CC |
3431 | /* Skip dummy compilation units. */ |
3432 | if (info_ptr >= buffer + buffer_size | |
3433 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
3434 | { | |
6caca83c | 3435 | do_cleanups (back_to_inner); |
21b2bd31 | 3436 | return; |
6caca83c CC |
3437 | } |
3438 | ||
93311388 | 3439 | cu.list_in_scope = &file_symbols; |
af703f96 | 3440 | |
93311388 | 3441 | /* Read the abbrevs for this compilation unit into a table. */ |
e5fe5e75 | 3442 | dwarf2_read_abbrevs (&cu); |
93311388 | 3443 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
af703f96 | 3444 | |
93311388 | 3445 | /* Read the compilation unit die. */ |
d85a05f0 DJ |
3446 | init_cu_die_reader (&reader_specs, &cu); |
3447 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3448 | &has_children); | |
93311388 | 3449 | |
21b2bd31 | 3450 | if (is_debug_types_section) |
348e048f | 3451 | { |
b3c8eb43 JK |
3452 | /* LENGTH has not been set yet for type units. */ |
3453 | gdb_assert (this_cu->offset == cu.header.offset); | |
348e048f DE |
3454 | this_cu->length = cu.header.length + cu.header.initial_length_size; |
3455 | } | |
d85a05f0 | 3456 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 3457 | { |
93311388 | 3458 | do_cleanups (back_to_inner); |
21b2bd31 | 3459 | return; |
93311388 | 3460 | } |
72bf9492 | 3461 | |
9816fde3 | 3462 | prepare_one_comp_unit (&cu, comp_unit_die); |
c906108c | 3463 | |
93311388 | 3464 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 3465 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
3e2a0cee TT |
3466 | if (attr == NULL || !DW_STRING (attr)) |
3467 | filename = ""; | |
3468 | else | |
3469 | filename = DW_STRING (attr); | |
93311388 | 3470 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
3e2a0cee | 3471 | filename, |
93311388 DE |
3472 | /* TEXTLOW and TEXTHIGH are set below. */ |
3473 | 0, | |
3474 | objfile->global_psymbols.next, | |
3475 | objfile->static_psymbols.next); | |
9750bca9 | 3476 | pst->psymtabs_addrmap_supported = 1; |
72bf9492 | 3477 | |
d85a05f0 DJ |
3478 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
3479 | if (attr != NULL) | |
3480 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 3481 | |
e38df1d0 | 3482 | pst->read_symtab_private = this_cu; |
72bf9492 | 3483 | |
93311388 | 3484 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 3485 | |
0963b4bd | 3486 | /* Store the function that reads in the rest of the symbol table. */ |
93311388 | 3487 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
57349743 | 3488 | |
9291a0cd | 3489 | this_cu->v.psymtab = pst; |
c906108c | 3490 | |
d85a05f0 DJ |
3491 | dwarf2_find_base_address (comp_unit_die, &cu); |
3492 | ||
93311388 DE |
3493 | /* Possibly set the default values of LOWPC and HIGHPC from |
3494 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
3495 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
3496 | &best_highpc, &cu, pst); | |
3497 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
3498 | /* Store the contiguous range if it is not empty; it can be empty for |
3499 | CUs with no code. */ | |
3500 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
3501 | best_lowpc + baseaddr, |
3502 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
3503 | |
3504 | /* Check if comp unit has_children. | |
3505 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3506 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3507 | if (has_children) |
93311388 DE |
3508 | { |
3509 | struct partial_die_info *first_die; | |
3510 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 3511 | |
93311388 DE |
3512 | lowpc = ((CORE_ADDR) -1); |
3513 | highpc = ((CORE_ADDR) 0); | |
c906108c | 3514 | |
93311388 | 3515 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 3516 | |
93311388 | 3517 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 3518 | ! has_pc_info, &cu); |
57c22c6c | 3519 | |
93311388 DE |
3520 | /* If we didn't find a lowpc, set it to highpc to avoid |
3521 | complaints from `maint check'. */ | |
3522 | if (lowpc == ((CORE_ADDR) -1)) | |
3523 | lowpc = highpc; | |
10b3939b | 3524 | |
93311388 DE |
3525 | /* If the compilation unit didn't have an explicit address range, |
3526 | then use the information extracted from its child dies. */ | |
d85a05f0 | 3527 | if (! has_pc_info) |
93311388 | 3528 | { |
d85a05f0 DJ |
3529 | best_lowpc = lowpc; |
3530 | best_highpc = highpc; | |
93311388 DE |
3531 | } |
3532 | } | |
d85a05f0 DJ |
3533 | pst->textlow = best_lowpc + baseaddr; |
3534 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 3535 | |
93311388 DE |
3536 | pst->n_global_syms = objfile->global_psymbols.next - |
3537 | (objfile->global_psymbols.list + pst->globals_offset); | |
3538 | pst->n_static_syms = objfile->static_psymbols.next - | |
3539 | (objfile->static_psymbols.list + pst->statics_offset); | |
3540 | sort_pst_symbols (pst); | |
c906108c | 3541 | |
21b2bd31 | 3542 | if (is_debug_types_section) |
348e048f DE |
3543 | { |
3544 | /* It's not clear we want to do anything with stmt lists here. | |
3545 | Waiting to see what gcc ultimately does. */ | |
3546 | } | |
d85a05f0 | 3547 | else |
93311388 DE |
3548 | { |
3549 | /* Get the list of files included in the current compilation unit, | |
3550 | and build a psymtab for each of them. */ | |
d85a05f0 | 3551 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 3552 | } |
ae038cb0 | 3553 | |
93311388 | 3554 | do_cleanups (back_to_inner); |
93311388 | 3555 | } |
ff013f42 | 3556 | |
348e048f DE |
3557 | /* Traversal function for htab_traverse_noresize. |
3558 | Process one .debug_types comp-unit. */ | |
3559 | ||
3560 | static int | |
3561 | process_type_comp_unit (void **slot, void *info) | |
3562 | { | |
3563 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
348e048f DE |
3564 | struct dwarf2_per_cu_data *this_cu; |
3565 | ||
a0f42c21 | 3566 | gdb_assert (info == NULL); |
348e048f | 3567 | this_cu = &entry->per_cu; |
348e048f | 3568 | |
b0df02fd | 3569 | gdb_assert (this_cu->debug_types_section->readin); |
21b2bd31 | 3570 | process_psymtab_comp_unit (this_cu, this_cu->debug_types_section, 1); |
348e048f DE |
3571 | |
3572 | return 1; | |
3573 | } | |
3574 | ||
3575 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
3576 | Build partial symbol tables for the .debug_types comp-units. */ | |
3577 | ||
3578 | static void | |
3579 | build_type_psymtabs (struct objfile *objfile) | |
3580 | { | |
3581 | if (! create_debug_types_hash_table (objfile)) | |
3582 | return; | |
3583 | ||
3584 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
a0f42c21 | 3585 | process_type_comp_unit, NULL); |
348e048f DE |
3586 | } |
3587 | ||
60606b2c TT |
3588 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
3589 | ||
3590 | static void | |
3591 | psymtabs_addrmap_cleanup (void *o) | |
3592 | { | |
3593 | struct objfile *objfile = o; | |
ec61707d | 3594 | |
60606b2c TT |
3595 | objfile->psymtabs_addrmap = NULL; |
3596 | } | |
3597 | ||
93311388 DE |
3598 | /* Build the partial symbol table by doing a quick pass through the |
3599 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3600 | |
93311388 | 3601 | static void |
c67a9c90 | 3602 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3603 | { |
60606b2c TT |
3604 | struct cleanup *back_to, *addrmap_cleanup; |
3605 | struct obstack temp_obstack; | |
21b2bd31 | 3606 | int i; |
93311388 | 3607 | |
98bfdba5 PA |
3608 | dwarf2_per_objfile->reading_partial_symbols = 1; |
3609 | ||
be391dca | 3610 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
91c24f0a | 3611 | |
93311388 DE |
3612 | /* Any cached compilation units will be linked by the per-objfile |
3613 | read_in_chain. Make sure to free them when we're done. */ | |
3614 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3615 | |
348e048f DE |
3616 | build_type_psymtabs (objfile); |
3617 | ||
93311388 | 3618 | create_all_comp_units (objfile); |
c906108c | 3619 | |
60606b2c TT |
3620 | /* Create a temporary address map on a temporary obstack. We later |
3621 | copy this to the final obstack. */ | |
3622 | obstack_init (&temp_obstack); | |
3623 | make_cleanup_obstack_free (&temp_obstack); | |
3624 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3625 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3626 | |
21b2bd31 | 3627 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
93311388 | 3628 | { |
21b2bd31 | 3629 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
aaa75496 | 3630 | |
21b2bd31 | 3631 | process_psymtab_comp_unit (per_cu, &dwarf2_per_objfile->info, 0); |
c906108c | 3632 | } |
ff013f42 JK |
3633 | |
3634 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3635 | &objfile->objfile_obstack); | |
60606b2c | 3636 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3637 | |
ae038cb0 DJ |
3638 | do_cleanups (back_to); |
3639 | } | |
3640 | ||
93311388 | 3641 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3642 | |
3643 | static void | |
a0f42c21 | 3644 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) |
ae038cb0 | 3645 | { |
a0f42c21 | 3646 | struct objfile *objfile = this_cu->objfile; |
ae038cb0 | 3647 | bfd *abfd = objfile->obfd; |
adabb602 | 3648 | gdb_byte *info_ptr; |
d85a05f0 | 3649 | struct die_info *comp_unit_die; |
ae038cb0 | 3650 | struct dwarf2_cu *cu; |
1d9ec526 | 3651 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
d85a05f0 DJ |
3652 | int has_children; |
3653 | struct die_reader_specs reader_specs; | |
98bfdba5 | 3654 | int read_cu = 0; |
9ff913ba | 3655 | struct dwarf2_section_info *section = &dwarf2_per_objfile->info; |
ae038cb0 | 3656 | |
b0df02fd | 3657 | gdb_assert (! this_cu->debug_types_section); |
348e048f | 3658 | |
9ff913ba DE |
3659 | gdb_assert (section->readin); |
3660 | info_ptr = section->buffer + this_cu->offset; | |
ae038cb0 | 3661 | |
98bfdba5 PA |
3662 | if (this_cu->cu == NULL) |
3663 | { | |
9816fde3 | 3664 | cu = xmalloc (sizeof (*cu)); |
23745b47 | 3665 | init_one_comp_unit (cu, this_cu); |
ae038cb0 | 3666 | |
98bfdba5 | 3667 | read_cu = 1; |
ae038cb0 | 3668 | |
98bfdba5 | 3669 | /* If an error occurs while loading, release our storage. */ |
68dc6402 | 3670 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
328c9494 | 3671 | |
9ff913ba DE |
3672 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, info_ptr, |
3673 | 0); | |
ae038cb0 | 3674 | |
6caca83c | 3675 | /* Skip dummy compilation units. */ |
9ff913ba | 3676 | if (info_ptr >= (section->buffer + section->size) |
6caca83c CC |
3677 | || peek_abbrev_code (abfd, info_ptr) == 0) |
3678 | { | |
3679 | do_cleanups (free_cu_cleanup); | |
3680 | return; | |
3681 | } | |
3682 | ||
98bfdba5 PA |
3683 | /* Link this CU into read_in_chain. */ |
3684 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3685 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3686 | } | |
3687 | else | |
3688 | { | |
3689 | cu = this_cu->cu; | |
3690 | info_ptr += cu->header.first_die_offset; | |
3691 | } | |
ae038cb0 DJ |
3692 | |
3693 | /* Read the abbrevs for this compilation unit into a table. */ | |
98bfdba5 | 3694 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
e5fe5e75 | 3695 | dwarf2_read_abbrevs (cu); |
98bfdba5 | 3696 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
ae038cb0 DJ |
3697 | |
3698 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3699 | init_cu_die_reader (&reader_specs, cu); |
3700 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3701 | &has_children); | |
ae038cb0 | 3702 | |
9816fde3 | 3703 | prepare_one_comp_unit (cu, comp_unit_die); |
ae038cb0 | 3704 | |
ae038cb0 DJ |
3705 | /* Check if comp unit has_children. |
3706 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3707 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3708 | if (has_children) |
9ff913ba | 3709 | load_partial_dies (abfd, section->buffer, info_ptr, 0, cu); |
ae038cb0 | 3710 | |
98bfdba5 PA |
3711 | do_cleanups (free_abbrevs_cleanup); |
3712 | ||
3713 | if (read_cu) | |
3714 | { | |
3715 | /* We've successfully allocated this compilation unit. Let our | |
3716 | caller clean it up when finished with it. */ | |
3717 | discard_cleanups (free_cu_cleanup); | |
3718 | } | |
ae038cb0 DJ |
3719 | } |
3720 | ||
9cdd5dbd DE |
3721 | /* Create a list of all compilation units in OBJFILE. |
3722 | This is only done for -readnow and building partial symtabs. */ | |
ae038cb0 DJ |
3723 | |
3724 | static void | |
3725 | create_all_comp_units (struct objfile *objfile) | |
3726 | { | |
3727 | int n_allocated; | |
3728 | int n_comp_units; | |
3729 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3730 | gdb_byte *info_ptr; |
3731 | ||
3732 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3733 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3734 | |
3735 | n_comp_units = 0; | |
3736 | n_allocated = 10; | |
3737 | all_comp_units = xmalloc (n_allocated | |
3738 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3739 | |
3e43a32a MS |
3740 | while (info_ptr < dwarf2_per_objfile->info.buffer |
3741 | + dwarf2_per_objfile->info.size) | |
ae038cb0 | 3742 | { |
c764a876 | 3743 | unsigned int length, initial_length_size; |
ae038cb0 | 3744 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3745 | unsigned int offset; |
ae038cb0 | 3746 | |
dce234bc | 3747 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3748 | |
3749 | /* Read just enough information to find out where the next | |
3750 | compilation unit is. */ | |
c764a876 DE |
3751 | length = read_initial_length (objfile->obfd, info_ptr, |
3752 | &initial_length_size); | |
ae038cb0 DJ |
3753 | |
3754 | /* Save the compilation unit for later lookup. */ | |
3755 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3756 | sizeof (struct dwarf2_per_cu_data)); | |
3757 | memset (this_cu, 0, sizeof (*this_cu)); | |
3758 | this_cu->offset = offset; | |
c764a876 | 3759 | this_cu->length = length + initial_length_size; |
9291a0cd | 3760 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3761 | |
3762 | if (n_comp_units == n_allocated) | |
3763 | { | |
3764 | n_allocated *= 2; | |
3765 | all_comp_units = xrealloc (all_comp_units, | |
3766 | n_allocated | |
3767 | * sizeof (struct dwarf2_per_cu_data *)); | |
3768 | } | |
3769 | all_comp_units[n_comp_units++] = this_cu; | |
3770 | ||
3771 | info_ptr = info_ptr + this_cu->length; | |
3772 | } | |
3773 | ||
3774 | dwarf2_per_objfile->all_comp_units | |
3775 | = obstack_alloc (&objfile->objfile_obstack, | |
3776 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3777 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3778 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3779 | xfree (all_comp_units); | |
3780 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3781 | } |
3782 | ||
5734ee8b DJ |
3783 | /* Process all loaded DIEs for compilation unit CU, starting at |
3784 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3785 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3786 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3787 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3788 | and record the covered ranges in the addrmap. */ | |
c906108c | 3789 | |
72bf9492 DJ |
3790 | static void |
3791 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3792 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3793 | { |
72bf9492 | 3794 | struct partial_die_info *pdi; |
c906108c | 3795 | |
91c24f0a DC |
3796 | /* Now, march along the PDI's, descending into ones which have |
3797 | interesting children but skipping the children of the other ones, | |
3798 | until we reach the end of the compilation unit. */ | |
c906108c | 3799 | |
72bf9492 | 3800 | pdi = first_die; |
91c24f0a | 3801 | |
72bf9492 DJ |
3802 | while (pdi != NULL) |
3803 | { | |
3804 | fixup_partial_die (pdi, cu); | |
c906108c | 3805 | |
f55ee35c | 3806 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3807 | children, so we need to look at them. Ditto for anonymous |
3808 | enums. */ | |
933c6fe4 | 3809 | |
72bf9492 | 3810 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3811 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3812 | { |
72bf9492 | 3813 | switch (pdi->tag) |
c906108c SS |
3814 | { |
3815 | case DW_TAG_subprogram: | |
5734ee8b | 3816 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 3817 | break; |
72929c62 | 3818 | case DW_TAG_constant: |
c906108c SS |
3819 | case DW_TAG_variable: |
3820 | case DW_TAG_typedef: | |
91c24f0a | 3821 | case DW_TAG_union_type: |
72bf9492 | 3822 | if (!pdi->is_declaration) |
63d06c5c | 3823 | { |
72bf9492 | 3824 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3825 | } |
3826 | break; | |
c906108c | 3827 | case DW_TAG_class_type: |
680b30c7 | 3828 | case DW_TAG_interface_type: |
c906108c | 3829 | case DW_TAG_structure_type: |
72bf9492 | 3830 | if (!pdi->is_declaration) |
c906108c | 3831 | { |
72bf9492 | 3832 | add_partial_symbol (pdi, cu); |
c906108c SS |
3833 | } |
3834 | break; | |
91c24f0a | 3835 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3836 | if (!pdi->is_declaration) |
3837 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3838 | break; |
3839 | case DW_TAG_base_type: | |
a02abb62 | 3840 | case DW_TAG_subrange_type: |
c906108c | 3841 | /* File scope base type definitions are added to the partial |
c5aa993b | 3842 | symbol table. */ |
72bf9492 | 3843 | add_partial_symbol (pdi, cu); |
c906108c | 3844 | break; |
d9fa45fe | 3845 | case DW_TAG_namespace: |
5734ee8b | 3846 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3847 | break; |
5d7cb8df JK |
3848 | case DW_TAG_module: |
3849 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3850 | break; | |
c906108c SS |
3851 | default: |
3852 | break; | |
3853 | } | |
3854 | } | |
3855 | ||
72bf9492 DJ |
3856 | /* If the die has a sibling, skip to the sibling. */ |
3857 | ||
3858 | pdi = pdi->die_sibling; | |
3859 | } | |
3860 | } | |
3861 | ||
3862 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3863 | |
72bf9492 | 3864 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3865 | name is concatenated with "::" and the partial DIE's name. For |
3866 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3867 | Enumerators are an exception; they use the scope of their parent |
3868 | enumeration type, i.e. the name of the enumeration type is not | |
3869 | prepended to the enumerator. | |
91c24f0a | 3870 | |
72bf9492 DJ |
3871 | There are two complexities. One is DW_AT_specification; in this |
3872 | case "parent" means the parent of the target of the specification, | |
3873 | instead of the direct parent of the DIE. The other is compilers | |
3874 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3875 | the fully qualified name of structure types from their members' | |
3876 | linkage names. This must be done using the DIE's children rather | |
3877 | than the children of any DW_AT_specification target. We only need | |
3878 | to do this for structures at the top level, i.e. if the target of | |
3879 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3880 | have a parent. */ | |
3881 | ||
3882 | /* Compute the scope prefix associated with PDI's parent, in | |
3883 | compilation unit CU. The result will be allocated on CU's | |
3884 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3885 | field. NULL is returned if no prefix is necessary. */ | |
3886 | static char * | |
3887 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3888 | struct dwarf2_cu *cu) | |
3889 | { | |
3890 | char *grandparent_scope; | |
3891 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3892 | |
72bf9492 DJ |
3893 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3894 | then this means the parent of the specification DIE. */ | |
3895 | ||
3896 | real_pdi = pdi; | |
72bf9492 | 3897 | while (real_pdi->has_specification) |
10b3939b | 3898 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3899 | |
3900 | parent = real_pdi->die_parent; | |
3901 | if (parent == NULL) | |
3902 | return NULL; | |
3903 | ||
3904 | if (parent->scope_set) | |
3905 | return parent->scope; | |
3906 | ||
3907 | fixup_partial_die (parent, cu); | |
3908 | ||
10b3939b | 3909 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3910 | |
acebe513 UW |
3911 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3912 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3913 | Work around this problem here. */ | |
3914 | if (cu->language == language_cplus | |
6e70227d | 3915 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3916 | && strcmp (parent->name, "::") == 0 |
3917 | && grandparent_scope == NULL) | |
3918 | { | |
3919 | parent->scope = NULL; | |
3920 | parent->scope_set = 1; | |
3921 | return NULL; | |
3922 | } | |
3923 | ||
9c6c53f7 SA |
3924 | if (pdi->tag == DW_TAG_enumerator) |
3925 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
3926 | parent->scope = grandparent_scope; | |
3927 | else if (parent->tag == DW_TAG_namespace | |
f55ee35c | 3928 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3929 | || parent->tag == DW_TAG_structure_type |
3930 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3931 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3932 | || parent->tag == DW_TAG_union_type |
3933 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3934 | { |
3935 | if (grandparent_scope == NULL) | |
3936 | parent->scope = parent->name; | |
3937 | else | |
3e43a32a MS |
3938 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
3939 | grandparent_scope, | |
f55ee35c | 3940 | parent->name, 0, cu); |
72bf9492 | 3941 | } |
72bf9492 DJ |
3942 | else |
3943 | { | |
3944 | /* FIXME drow/2004-04-01: What should we be doing with | |
3945 | function-local names? For partial symbols, we should probably be | |
3946 | ignoring them. */ | |
3947 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3948 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3949 | parent->tag, pdi->offset); |
3950 | parent->scope = grandparent_scope; | |
c906108c SS |
3951 | } |
3952 | ||
72bf9492 DJ |
3953 | parent->scope_set = 1; |
3954 | return parent->scope; | |
3955 | } | |
3956 | ||
3957 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3958 | CU. The result will be allocated with malloc. */ | |
3959 | static char * | |
3960 | partial_die_full_name (struct partial_die_info *pdi, | |
3961 | struct dwarf2_cu *cu) | |
3962 | { | |
3963 | char *parent_scope; | |
3964 | ||
98bfdba5 PA |
3965 | /* If this is a template instantiation, we can not work out the |
3966 | template arguments from partial DIEs. So, unfortunately, we have | |
3967 | to go through the full DIEs. At least any work we do building | |
3968 | types here will be reused if full symbols are loaded later. */ | |
3969 | if (pdi->has_template_arguments) | |
3970 | { | |
3971 | fixup_partial_die (pdi, cu); | |
3972 | ||
3973 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
3974 | { | |
3975 | struct die_info *die; | |
3976 | struct attribute attr; | |
3977 | struct dwarf2_cu *ref_cu = cu; | |
3978 | ||
3979 | attr.name = 0; | |
3980 | attr.form = DW_FORM_ref_addr; | |
3981 | attr.u.addr = pdi->offset; | |
3982 | die = follow_die_ref (NULL, &attr, &ref_cu); | |
3983 | ||
3984 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
3985 | } | |
3986 | } | |
3987 | ||
72bf9492 DJ |
3988 | parent_scope = partial_die_parent_scope (pdi, cu); |
3989 | if (parent_scope == NULL) | |
3990 | return NULL; | |
3991 | else | |
f55ee35c | 3992 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3993 | } |
3994 | ||
3995 | static void | |
72bf9492 | 3996 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3997 | { |
e7c27a73 | 3998 | struct objfile *objfile = cu->objfile; |
c906108c | 3999 | CORE_ADDR addr = 0; |
decbce07 | 4000 | char *actual_name = NULL; |
e142c38c | 4001 | CORE_ADDR baseaddr; |
72bf9492 | 4002 | int built_actual_name = 0; |
e142c38c DJ |
4003 | |
4004 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 4005 | |
94af9270 KS |
4006 | actual_name = partial_die_full_name (pdi, cu); |
4007 | if (actual_name) | |
4008 | built_actual_name = 1; | |
63d06c5c | 4009 | |
72bf9492 DJ |
4010 | if (actual_name == NULL) |
4011 | actual_name = pdi->name; | |
4012 | ||
c906108c SS |
4013 | switch (pdi->tag) |
4014 | { | |
4015 | case DW_TAG_subprogram: | |
2cfa0c8d | 4016 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 4017 | { |
2cfa0c8d JB |
4018 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
4019 | of the global scope. But in Ada, we want to be able to access | |
4020 | nested procedures globally. So all Ada subprograms are stored | |
4021 | in the global scope. */ | |
f47fb265 | 4022 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 4023 | mst_text, objfile); */ |
f47fb265 MS |
4024 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4025 | built_actual_name, | |
4026 | VAR_DOMAIN, LOC_BLOCK, | |
4027 | &objfile->global_psymbols, | |
4028 | 0, pdi->lowpc + baseaddr, | |
4029 | cu->language, objfile); | |
c906108c SS |
4030 | } |
4031 | else | |
4032 | { | |
f47fb265 | 4033 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 4034 | mst_file_text, objfile); */ |
f47fb265 MS |
4035 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4036 | built_actual_name, | |
4037 | VAR_DOMAIN, LOC_BLOCK, | |
4038 | &objfile->static_psymbols, | |
4039 | 0, pdi->lowpc + baseaddr, | |
4040 | cu->language, objfile); | |
c906108c SS |
4041 | } |
4042 | break; | |
72929c62 JB |
4043 | case DW_TAG_constant: |
4044 | { | |
4045 | struct psymbol_allocation_list *list; | |
4046 | ||
4047 | if (pdi->is_external) | |
4048 | list = &objfile->global_psymbols; | |
4049 | else | |
4050 | list = &objfile->static_psymbols; | |
f47fb265 MS |
4051 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4052 | built_actual_name, VAR_DOMAIN, LOC_STATIC, | |
4053 | list, 0, 0, cu->language, objfile); | |
72929c62 JB |
4054 | } |
4055 | break; | |
c906108c | 4056 | case DW_TAG_variable: |
caac4577 JG |
4057 | if (pdi->locdesc) |
4058 | addr = decode_locdesc (pdi->locdesc, cu); | |
4059 | ||
4060 | if (pdi->locdesc | |
4061 | && addr == 0 | |
4062 | && !dwarf2_per_objfile->has_section_at_zero) | |
4063 | { | |
4064 | /* A global or static variable may also have been stripped | |
4065 | out by the linker if unused, in which case its address | |
4066 | will be nullified; do not add such variables into partial | |
4067 | symbol table then. */ | |
4068 | } | |
4069 | else if (pdi->is_external) | |
c906108c SS |
4070 | { |
4071 | /* Global Variable. | |
4072 | Don't enter into the minimal symbol tables as there is | |
4073 | a minimal symbol table entry from the ELF symbols already. | |
4074 | Enter into partial symbol table if it has a location | |
4075 | descriptor or a type. | |
4076 | If the location descriptor is missing, new_symbol will create | |
4077 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
4078 | be determined from the minimal symbol table whenever the variable | |
4079 | is referenced. | |
4080 | The address for the partial symbol table entry is not | |
4081 | used by GDB, but it comes in handy for debugging partial symbol | |
4082 | table building. */ | |
4083 | ||
c906108c | 4084 | if (pdi->locdesc || pdi->has_type) |
f47fb265 MS |
4085 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4086 | built_actual_name, | |
4087 | VAR_DOMAIN, LOC_STATIC, | |
4088 | &objfile->global_psymbols, | |
4089 | 0, addr + baseaddr, | |
4090 | cu->language, objfile); | |
c906108c SS |
4091 | } |
4092 | else | |
4093 | { | |
0963b4bd | 4094 | /* Static Variable. Skip symbols without location descriptors. */ |
c906108c | 4095 | if (pdi->locdesc == NULL) |
decbce07 MS |
4096 | { |
4097 | if (built_actual_name) | |
4098 | xfree (actual_name); | |
4099 | return; | |
4100 | } | |
f47fb265 | 4101 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 4102 | mst_file_data, objfile); */ |
f47fb265 MS |
4103 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4104 | built_actual_name, | |
4105 | VAR_DOMAIN, LOC_STATIC, | |
4106 | &objfile->static_psymbols, | |
4107 | 0, addr + baseaddr, | |
4108 | cu->language, objfile); | |
c906108c SS |
4109 | } |
4110 | break; | |
4111 | case DW_TAG_typedef: | |
4112 | case DW_TAG_base_type: | |
a02abb62 | 4113 | case DW_TAG_subrange_type: |
38d518c9 | 4114 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4115 | built_actual_name, |
176620f1 | 4116 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 4117 | &objfile->static_psymbols, |
e142c38c | 4118 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4119 | break; |
72bf9492 DJ |
4120 | case DW_TAG_namespace: |
4121 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 4122 | built_actual_name, |
72bf9492 DJ |
4123 | VAR_DOMAIN, LOC_TYPEDEF, |
4124 | &objfile->global_psymbols, | |
4125 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
4126 | break; | |
c906108c | 4127 | case DW_TAG_class_type: |
680b30c7 | 4128 | case DW_TAG_interface_type: |
c906108c SS |
4129 | case DW_TAG_structure_type: |
4130 | case DW_TAG_union_type: | |
4131 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
4132 | /* Skip external references. The DWARF standard says in the section |
4133 | about "Structure, Union, and Class Type Entries": "An incomplete | |
4134 | structure, union or class type is represented by a structure, | |
4135 | union or class entry that does not have a byte size attribute | |
4136 | and that has a DW_AT_declaration attribute." */ | |
4137 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
4138 | { |
4139 | if (built_actual_name) | |
4140 | xfree (actual_name); | |
4141 | return; | |
4142 | } | |
fa4028e9 | 4143 | |
63d06c5c DC |
4144 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
4145 | static vs. global. */ | |
38d518c9 | 4146 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4147 | built_actual_name, |
176620f1 | 4148 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
4149 | (cu->language == language_cplus |
4150 | || cu->language == language_java) | |
63d06c5c DC |
4151 | ? &objfile->global_psymbols |
4152 | : &objfile->static_psymbols, | |
e142c38c | 4153 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4154 | |
c906108c SS |
4155 | break; |
4156 | case DW_TAG_enumerator: | |
38d518c9 | 4157 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4158 | built_actual_name, |
176620f1 | 4159 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
4160 | (cu->language == language_cplus |
4161 | || cu->language == language_java) | |
f6fe98ef DJ |
4162 | ? &objfile->global_psymbols |
4163 | : &objfile->static_psymbols, | |
e142c38c | 4164 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
4165 | break; |
4166 | default: | |
4167 | break; | |
4168 | } | |
5c4e30ca | 4169 | |
72bf9492 DJ |
4170 | if (built_actual_name) |
4171 | xfree (actual_name); | |
c906108c SS |
4172 | } |
4173 | ||
5c4e30ca DC |
4174 | /* Read a partial die corresponding to a namespace; also, add a symbol |
4175 | corresponding to that namespace to the symbol table. NAMESPACE is | |
4176 | the name of the enclosing namespace. */ | |
91c24f0a | 4177 | |
72bf9492 DJ |
4178 | static void |
4179 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 4180 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 4181 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 4182 | { |
72bf9492 | 4183 | /* Add a symbol for the namespace. */ |
e7c27a73 | 4184 | |
72bf9492 | 4185 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
4186 | |
4187 | /* Now scan partial symbols in that namespace. */ | |
4188 | ||
91c24f0a | 4189 | if (pdi->has_children) |
5734ee8b | 4190 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
4191 | } |
4192 | ||
5d7cb8df JK |
4193 | /* Read a partial die corresponding to a Fortran module. */ |
4194 | ||
4195 | static void | |
4196 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
4197 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
4198 | { | |
f55ee35c | 4199 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
4200 | |
4201 | if (pdi->has_children) | |
4202 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
4203 | } | |
4204 | ||
bc30ff58 JB |
4205 | /* Read a partial die corresponding to a subprogram and create a partial |
4206 | symbol for that subprogram. When the CU language allows it, this | |
4207 | routine also defines a partial symbol for each nested subprogram | |
4208 | that this subprogram contains. | |
6e70227d | 4209 | |
bc30ff58 JB |
4210 | DIE my also be a lexical block, in which case we simply search |
4211 | recursively for suprograms defined inside that lexical block. | |
4212 | Again, this is only performed when the CU language allows this | |
4213 | type of definitions. */ | |
4214 | ||
4215 | static void | |
4216 | add_partial_subprogram (struct partial_die_info *pdi, | |
4217 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 4218 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
4219 | { |
4220 | if (pdi->tag == DW_TAG_subprogram) | |
4221 | { | |
4222 | if (pdi->has_pc_info) | |
4223 | { | |
4224 | if (pdi->lowpc < *lowpc) | |
4225 | *lowpc = pdi->lowpc; | |
4226 | if (pdi->highpc > *highpc) | |
4227 | *highpc = pdi->highpc; | |
5734ee8b DJ |
4228 | if (need_pc) |
4229 | { | |
4230 | CORE_ADDR baseaddr; | |
4231 | struct objfile *objfile = cu->objfile; | |
4232 | ||
4233 | baseaddr = ANOFFSET (objfile->section_offsets, | |
4234 | SECT_OFF_TEXT (objfile)); | |
4235 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
4236 | pdi->lowpc + baseaddr, |
4237 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 4238 | cu->per_cu->v.psymtab); |
5734ee8b | 4239 | } |
bc30ff58 | 4240 | if (!pdi->is_declaration) |
e8d05480 JB |
4241 | /* Ignore subprogram DIEs that do not have a name, they are |
4242 | illegal. Do not emit a complaint at this point, we will | |
4243 | do so when we convert this psymtab into a symtab. */ | |
4244 | if (pdi->name) | |
4245 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
4246 | } |
4247 | } | |
6e70227d | 4248 | |
bc30ff58 JB |
4249 | if (! pdi->has_children) |
4250 | return; | |
4251 | ||
4252 | if (cu->language == language_ada) | |
4253 | { | |
4254 | pdi = pdi->die_child; | |
4255 | while (pdi != NULL) | |
4256 | { | |
4257 | fixup_partial_die (pdi, cu); | |
4258 | if (pdi->tag == DW_TAG_subprogram | |
4259 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 4260 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
4261 | pdi = pdi->die_sibling; |
4262 | } | |
4263 | } | |
4264 | } | |
4265 | ||
91c24f0a DC |
4266 | /* Read a partial die corresponding to an enumeration type. */ |
4267 | ||
72bf9492 DJ |
4268 | static void |
4269 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
4270 | struct dwarf2_cu *cu) | |
91c24f0a | 4271 | { |
72bf9492 | 4272 | struct partial_die_info *pdi; |
91c24f0a DC |
4273 | |
4274 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
4275 | add_partial_symbol (enum_pdi, cu); |
4276 | ||
4277 | pdi = enum_pdi->die_child; | |
4278 | while (pdi) | |
91c24f0a | 4279 | { |
72bf9492 | 4280 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 4281 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 4282 | else |
72bf9492 DJ |
4283 | add_partial_symbol (pdi, cu); |
4284 | pdi = pdi->die_sibling; | |
91c24f0a | 4285 | } |
91c24f0a DC |
4286 | } |
4287 | ||
6caca83c CC |
4288 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
4289 | ||
4290 | static unsigned int | |
4291 | peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr) | |
4292 | { | |
4293 | unsigned int bytes_read; | |
4294 | ||
4295 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4296 | } | |
4297 | ||
4bb7a0a7 DJ |
4298 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
4299 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
4300 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
4301 | the initial number. */ | |
4302 | ||
4303 | static struct abbrev_info * | |
fe1b8b76 | 4304 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 4305 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4306 | { |
4307 | bfd *abfd = cu->objfile->obfd; | |
4308 | unsigned int abbrev_number; | |
4309 | struct abbrev_info *abbrev; | |
4310 | ||
4311 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
4312 | ||
4313 | if (abbrev_number == 0) | |
4314 | return NULL; | |
4315 | ||
4316 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
4317 | if (!abbrev) | |
4318 | { | |
3e43a32a MS |
4319 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
4320 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
4321 | } |
4322 | ||
4323 | return abbrev; | |
4324 | } | |
4325 | ||
93311388 DE |
4326 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4327 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
4328 | DIE. Any children of the skipped DIEs will also be skipped. */ |
4329 | ||
fe1b8b76 | 4330 | static gdb_byte * |
93311388 | 4331 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4332 | { |
4333 | struct abbrev_info *abbrev; | |
4334 | unsigned int bytes_read; | |
4335 | ||
4336 | while (1) | |
4337 | { | |
4338 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4339 | if (abbrev == NULL) | |
4340 | return info_ptr + bytes_read; | |
4341 | else | |
93311388 | 4342 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
4343 | } |
4344 | } | |
4345 | ||
93311388 DE |
4346 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4347 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4348 | abbrev corresponding to that skipped uleb128 should be passed in |
4349 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4350 | children. */ | |
4351 | ||
fe1b8b76 | 4352 | static gdb_byte * |
93311388 DE |
4353 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
4354 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
4355 | { |
4356 | unsigned int bytes_read; | |
4357 | struct attribute attr; | |
4358 | bfd *abfd = cu->objfile->obfd; | |
4359 | unsigned int form, i; | |
4360 | ||
4361 | for (i = 0; i < abbrev->num_attrs; i++) | |
4362 | { | |
4363 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4364 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4365 | { | |
4366 | read_attribute (&attr, &abbrev->attrs[i], | |
4367 | abfd, info_ptr, cu); | |
4368 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
4369 | complaint (&symfile_complaints, |
4370 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 4371 | else |
93311388 | 4372 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
4373 | } |
4374 | ||
4375 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4376 | form = abbrev->attrs[i].form; | |
4377 | skip_attribute: | |
4378 | switch (form) | |
4379 | { | |
4bb7a0a7 | 4380 | case DW_FORM_ref_addr: |
ae411497 TT |
4381 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4382 | and later it is offset sized. */ | |
4383 | if (cu->header.version == 2) | |
4384 | info_ptr += cu->header.addr_size; | |
4385 | else | |
4386 | info_ptr += cu->header.offset_size; | |
4387 | break; | |
4388 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4389 | info_ptr += cu->header.addr_size; |
4390 | break; | |
4391 | case DW_FORM_data1: | |
4392 | case DW_FORM_ref1: | |
4393 | case DW_FORM_flag: | |
4394 | info_ptr += 1; | |
4395 | break; | |
2dc7f7b3 TT |
4396 | case DW_FORM_flag_present: |
4397 | break; | |
4bb7a0a7 DJ |
4398 | case DW_FORM_data2: |
4399 | case DW_FORM_ref2: | |
4400 | info_ptr += 2; | |
4401 | break; | |
4402 | case DW_FORM_data4: | |
4403 | case DW_FORM_ref4: | |
4404 | info_ptr += 4; | |
4405 | break; | |
4406 | case DW_FORM_data8: | |
4407 | case DW_FORM_ref8: | |
55f1336d | 4408 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
4409 | info_ptr += 8; |
4410 | break; | |
4411 | case DW_FORM_string: | |
9b1c24c8 | 4412 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
4413 | info_ptr += bytes_read; |
4414 | break; | |
2dc7f7b3 | 4415 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
4416 | case DW_FORM_strp: |
4417 | info_ptr += cu->header.offset_size; | |
4418 | break; | |
2dc7f7b3 | 4419 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
4420 | case DW_FORM_block: |
4421 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4422 | info_ptr += bytes_read; | |
4423 | break; | |
4424 | case DW_FORM_block1: | |
4425 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
4426 | break; | |
4427 | case DW_FORM_block2: | |
4428 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
4429 | break; | |
4430 | case DW_FORM_block4: | |
4431 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
4432 | break; | |
4433 | case DW_FORM_sdata: | |
4434 | case DW_FORM_udata: | |
4435 | case DW_FORM_ref_udata: | |
4436 | info_ptr = skip_leb128 (abfd, info_ptr); | |
4437 | break; | |
4438 | case DW_FORM_indirect: | |
4439 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4440 | info_ptr += bytes_read; | |
4441 | /* We need to continue parsing from here, so just go back to | |
4442 | the top. */ | |
4443 | goto skip_attribute; | |
4444 | ||
4445 | default: | |
3e43a32a MS |
4446 | error (_("Dwarf Error: Cannot handle %s " |
4447 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
4448 | dwarf_form_name (form), |
4449 | bfd_get_filename (abfd)); | |
4450 | } | |
4451 | } | |
4452 | ||
4453 | if (abbrev->has_children) | |
93311388 | 4454 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
4455 | else |
4456 | return info_ptr; | |
4457 | } | |
4458 | ||
93311388 DE |
4459 | /* Locate ORIG_PDI's sibling. |
4460 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
4461 | in BUFFER. */ | |
91c24f0a | 4462 | |
fe1b8b76 | 4463 | static gdb_byte * |
93311388 DE |
4464 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
4465 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 4466 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
4467 | { |
4468 | /* Do we know the sibling already? */ | |
72bf9492 | 4469 | |
91c24f0a DC |
4470 | if (orig_pdi->sibling) |
4471 | return orig_pdi->sibling; | |
4472 | ||
4473 | /* Are there any children to deal with? */ | |
4474 | ||
4475 | if (!orig_pdi->has_children) | |
4476 | return info_ptr; | |
4477 | ||
4bb7a0a7 | 4478 | /* Skip the children the long way. */ |
91c24f0a | 4479 | |
93311388 | 4480 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
4481 | } |
4482 | ||
c906108c SS |
4483 | /* Expand this partial symbol table into a full symbol table. */ |
4484 | ||
4485 | static void | |
fba45db2 | 4486 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 4487 | { |
c906108c SS |
4488 | if (pst != NULL) |
4489 | { | |
4490 | if (pst->readin) | |
4491 | { | |
3e43a32a MS |
4492 | warning (_("bug: psymtab for %s is already read in."), |
4493 | pst->filename); | |
c906108c SS |
4494 | } |
4495 | else | |
4496 | { | |
4497 | if (info_verbose) | |
4498 | { | |
3e43a32a MS |
4499 | printf_filtered (_("Reading in symbols for %s..."), |
4500 | pst->filename); | |
c906108c SS |
4501 | gdb_flush (gdb_stdout); |
4502 | } | |
4503 | ||
10b3939b DJ |
4504 | /* Restore our global data. */ |
4505 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
4506 | dwarf2_objfile_data_key); | |
4507 | ||
b2ab525c KB |
4508 | /* If this psymtab is constructed from a debug-only objfile, the |
4509 | has_section_at_zero flag will not necessarily be correct. We | |
4510 | can get the correct value for this flag by looking at the data | |
4511 | associated with the (presumably stripped) associated objfile. */ | |
4512 | if (pst->objfile->separate_debug_objfile_backlink) | |
4513 | { | |
4514 | struct dwarf2_per_objfile *dpo_backlink | |
4515 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
4516 | dwarf2_objfile_data_key); | |
9a619af0 | 4517 | |
b2ab525c KB |
4518 | dwarf2_per_objfile->has_section_at_zero |
4519 | = dpo_backlink->has_section_at_zero; | |
4520 | } | |
4521 | ||
98bfdba5 PA |
4522 | dwarf2_per_objfile->reading_partial_symbols = 0; |
4523 | ||
c906108c SS |
4524 | psymtab_to_symtab_1 (pst); |
4525 | ||
4526 | /* Finish up the debug error message. */ | |
4527 | if (info_verbose) | |
a3f17187 | 4528 | printf_filtered (_("done.\n")); |
c906108c SS |
4529 | } |
4530 | } | |
4531 | } | |
9cdd5dbd DE |
4532 | \f |
4533 | /* Reading in full CUs. */ | |
c906108c | 4534 | |
10b3939b DJ |
4535 | /* Add PER_CU to the queue. */ |
4536 | ||
4537 | static void | |
a0f42c21 | 4538 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) |
10b3939b DJ |
4539 | { |
4540 | struct dwarf2_queue_item *item; | |
4541 | ||
4542 | per_cu->queued = 1; | |
4543 | item = xmalloc (sizeof (*item)); | |
4544 | item->per_cu = per_cu; | |
4545 | item->next = NULL; | |
4546 | ||
4547 | if (dwarf2_queue == NULL) | |
4548 | dwarf2_queue = item; | |
4549 | else | |
4550 | dwarf2_queue_tail->next = item; | |
4551 | ||
4552 | dwarf2_queue_tail = item; | |
4553 | } | |
4554 | ||
4555 | /* Process the queue. */ | |
4556 | ||
4557 | static void | |
a0f42c21 | 4558 | process_queue (void) |
10b3939b DJ |
4559 | { |
4560 | struct dwarf2_queue_item *item, *next_item; | |
4561 | ||
03dd20cc DJ |
4562 | /* The queue starts out with one item, but following a DIE reference |
4563 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
4564 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
4565 | { | |
9291a0cd TT |
4566 | if (dwarf2_per_objfile->using_index |
4567 | ? !item->per_cu->v.quick->symtab | |
4568 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
4569 | process_full_comp_unit (item->per_cu); |
4570 | ||
4571 | item->per_cu->queued = 0; | |
4572 | next_item = item->next; | |
4573 | xfree (item); | |
4574 | } | |
4575 | ||
4576 | dwarf2_queue_tail = NULL; | |
4577 | } | |
4578 | ||
4579 | /* Free all allocated queue entries. This function only releases anything if | |
4580 | an error was thrown; if the queue was processed then it would have been | |
4581 | freed as we went along. */ | |
4582 | ||
4583 | static void | |
4584 | dwarf2_release_queue (void *dummy) | |
4585 | { | |
4586 | struct dwarf2_queue_item *item, *last; | |
4587 | ||
4588 | item = dwarf2_queue; | |
4589 | while (item) | |
4590 | { | |
4591 | /* Anything still marked queued is likely to be in an | |
4592 | inconsistent state, so discard it. */ | |
4593 | if (item->per_cu->queued) | |
4594 | { | |
4595 | if (item->per_cu->cu != NULL) | |
4596 | free_one_cached_comp_unit (item->per_cu->cu); | |
4597 | item->per_cu->queued = 0; | |
4598 | } | |
4599 | ||
4600 | last = item; | |
4601 | item = item->next; | |
4602 | xfree (last); | |
4603 | } | |
4604 | ||
4605 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
4606 | } | |
4607 | ||
4608 | /* Read in full symbols for PST, and anything it depends on. */ | |
4609 | ||
c906108c | 4610 | static void |
fba45db2 | 4611 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 4612 | { |
10b3939b | 4613 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 4614 | struct cleanup *back_to; |
aaa75496 JB |
4615 | int i; |
4616 | ||
4617 | for (i = 0; i < pst->number_of_dependencies; i++) | |
4618 | if (!pst->dependencies[i]->readin) | |
4619 | { | |
4620 | /* Inform about additional files that need to be read in. */ | |
4621 | if (info_verbose) | |
4622 | { | |
a3f17187 | 4623 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4624 | fputs_filtered (" ", gdb_stdout); |
4625 | wrap_here (""); | |
4626 | fputs_filtered ("and ", gdb_stdout); | |
4627 | wrap_here (""); | |
4628 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 4629 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
4630 | gdb_flush (gdb_stdout); |
4631 | } | |
4632 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4633 | } | |
4634 | ||
e38df1d0 | 4635 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4636 | |
4637 | if (per_cu == NULL) | |
aaa75496 JB |
4638 | { |
4639 | /* It's an include file, no symbols to read for it. | |
4640 | Everything is in the parent symtab. */ | |
4641 | pst->readin = 1; | |
4642 | return; | |
4643 | } | |
c906108c | 4644 | |
a0f42c21 | 4645 | dw2_do_instantiate_symtab (per_cu); |
10b3939b DJ |
4646 | } |
4647 | ||
93311388 | 4648 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4649 | |
93311388 | 4650 | static void |
a0f42c21 | 4651 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu) |
10b3939b | 4652 | { |
a0f42c21 | 4653 | struct objfile *objfile = per_cu->objfile; |
31ffec48 | 4654 | bfd *abfd = objfile->obfd; |
10b3939b | 4655 | struct dwarf2_cu *cu; |
c764a876 | 4656 | unsigned int offset; |
93311388 | 4657 | gdb_byte *info_ptr, *beg_of_comp_unit; |
98bfdba5 | 4658 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
10b3939b | 4659 | struct attribute *attr; |
98bfdba5 | 4660 | int read_cu = 0; |
6502dd73 | 4661 | |
b0df02fd | 4662 | gdb_assert (! per_cu->debug_types_section); |
348e048f | 4663 | |
c906108c | 4664 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4665 | offset = per_cu->offset; |
6502dd73 | 4666 | |
be391dca | 4667 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4668 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4669 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4670 | |
98bfdba5 PA |
4671 | if (per_cu->cu == NULL) |
4672 | { | |
9816fde3 | 4673 | cu = xmalloc (sizeof (*cu)); |
23745b47 | 4674 | init_one_comp_unit (cu, per_cu); |
98bfdba5 PA |
4675 | |
4676 | read_cu = 1; | |
c906108c | 4677 | |
98bfdba5 | 4678 | /* If an error occurs while loading, release our storage. */ |
68dc6402 | 4679 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
c906108c | 4680 | |
98bfdba5 PA |
4681 | /* Read in the comp_unit header. */ |
4682 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); | |
c906108c | 4683 | |
6caca83c CC |
4684 | /* Skip dummy compilation units. */ |
4685 | if (info_ptr >= (dwarf2_per_objfile->info.buffer | |
4686 | + dwarf2_per_objfile->info.size) | |
4687 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
4688 | { | |
4689 | do_cleanups (free_cu_cleanup); | |
4690 | return; | |
4691 | } | |
4692 | ||
98bfdba5 PA |
4693 | /* Complete the cu_header. */ |
4694 | cu->header.offset = offset; | |
4695 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
93311388 | 4696 | |
98bfdba5 | 4697 | /* Read the abbrevs for this compilation unit. */ |
e5fe5e75 | 4698 | dwarf2_read_abbrevs (cu); |
98bfdba5 | 4699 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
10b3939b | 4700 | |
98bfdba5 PA |
4701 | /* Link this CU into read_in_chain. */ |
4702 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4703 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4704 | } | |
4705 | else | |
4706 | { | |
4707 | cu = per_cu->cu; | |
4708 | info_ptr += cu->header.first_die_offset; | |
4709 | } | |
e142c38c | 4710 | |
93311388 | 4711 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4712 | |
4713 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 4714 | all CUs needed for references have been loaded yet, and symbol |
10b3939b DJ |
4715 | table processing isn't initialized. But we have to set the CU language, |
4716 | or we won't be able to build types correctly. */ | |
9816fde3 | 4717 | prepare_one_comp_unit (cu, cu->dies); |
10b3939b | 4718 | |
a6c727b2 DJ |
4719 | /* Similarly, if we do not read the producer, we can not apply |
4720 | producer-specific interpretation. */ | |
4721 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4722 | if (attr) | |
4723 | cu->producer = DW_STRING (attr); | |
4724 | ||
98bfdba5 PA |
4725 | if (read_cu) |
4726 | { | |
4727 | do_cleanups (free_abbrevs_cleanup); | |
e142c38c | 4728 | |
98bfdba5 PA |
4729 | /* We've successfully allocated this compilation unit. Let our |
4730 | caller clean it up when finished with it. */ | |
4731 | discard_cleanups (free_cu_cleanup); | |
4732 | } | |
10b3939b DJ |
4733 | } |
4734 | ||
3da10d80 KS |
4735 | /* Add a DIE to the delayed physname list. */ |
4736 | ||
4737 | static void | |
4738 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
4739 | const char *name, struct die_info *die, | |
4740 | struct dwarf2_cu *cu) | |
4741 | { | |
4742 | struct delayed_method_info mi; | |
4743 | mi.type = type; | |
4744 | mi.fnfield_index = fnfield_index; | |
4745 | mi.index = index; | |
4746 | mi.name = name; | |
4747 | mi.die = die; | |
4748 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
4749 | } | |
4750 | ||
4751 | /* A cleanup for freeing the delayed method list. */ | |
4752 | ||
4753 | static void | |
4754 | free_delayed_list (void *ptr) | |
4755 | { | |
4756 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
4757 | if (cu->method_list != NULL) | |
4758 | { | |
4759 | VEC_free (delayed_method_info, cu->method_list); | |
4760 | cu->method_list = NULL; | |
4761 | } | |
4762 | } | |
4763 | ||
4764 | /* Compute the physnames of any methods on the CU's method list. | |
4765 | ||
4766 | The computation of method physnames is delayed in order to avoid the | |
4767 | (bad) condition that one of the method's formal parameters is of an as yet | |
4768 | incomplete type. */ | |
4769 | ||
4770 | static void | |
4771 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
4772 | { | |
4773 | int i; | |
4774 | struct delayed_method_info *mi; | |
4775 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
4776 | { | |
1d06ead6 | 4777 | const char *physname; |
3da10d80 KS |
4778 | struct fn_fieldlist *fn_flp |
4779 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
1d06ead6 | 4780 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
3da10d80 KS |
4781 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
4782 | } | |
4783 | } | |
4784 | ||
9cdd5dbd | 4785 | /* Generate full symbol information for PER_CU, whose DIEs have |
10b3939b DJ |
4786 | already been loaded into memory. */ |
4787 | ||
4788 | static void | |
4789 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4790 | { | |
10b3939b | 4791 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4792 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4793 | CORE_ADDR lowpc, highpc; |
4794 | struct symtab *symtab; | |
3da10d80 | 4795 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
4796 | CORE_ADDR baseaddr; |
4797 | ||
4798 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4799 | ||
10b3939b DJ |
4800 | buildsym_init (); |
4801 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 4802 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
4803 | |
4804 | cu->list_in_scope = &file_symbols; | |
c906108c SS |
4805 | |
4806 | /* Do line number decoding in read_file_scope () */ | |
10b3939b | 4807 | process_die (cu->dies, cu); |
c906108c | 4808 | |
3da10d80 KS |
4809 | /* Now that we have processed all the DIEs in the CU, all the types |
4810 | should be complete, and it should now be safe to compute all of the | |
4811 | physnames. */ | |
4812 | compute_delayed_physnames (cu); | |
4813 | do_cleanups (delayed_list_cleanup); | |
4814 | ||
fae299cd DC |
4815 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4816 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4817 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4818 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4819 | |
613e1657 | 4820 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c | 4821 | |
8be455d7 | 4822 | if (symtab != NULL) |
c906108c | 4823 | { |
df15bd07 | 4824 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
4632c0d0 | 4825 | |
8be455d7 JK |
4826 | /* Set symtab language to language from DW_AT_language. If the |
4827 | compilation is from a C file generated by language preprocessors, do | |
4828 | not set the language if it was already deduced by start_subfile. */ | |
4829 | if (!(cu->language == language_c && symtab->language != language_c)) | |
4830 | symtab->language = cu->language; | |
4831 | ||
4832 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
4833 | produce DW_AT_location with location lists but it can be possibly | |
4834 | invalid without -fvar-tracking. | |
4835 | ||
4836 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
4837 | needed, it would be wrong due to missing DW_AT_producer there. | |
4838 | ||
4839 | Still one can confuse GDB by using non-standard GCC compilation | |
4840 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
4841 | */ | |
4632c0d0 | 4842 | if (cu->has_loclist && gcc_4_minor >= 0) |
8be455d7 | 4843 | symtab->locations_valid = 1; |
e0d00bc7 JK |
4844 | |
4845 | if (gcc_4_minor >= 5) | |
4846 | symtab->epilogue_unwind_valid = 1; | |
96408a79 SA |
4847 | |
4848 | symtab->call_site_htab = cu->call_site_htab; | |
c906108c | 4849 | } |
9291a0cd TT |
4850 | |
4851 | if (dwarf2_per_objfile->using_index) | |
4852 | per_cu->v.quick->symtab = symtab; | |
4853 | else | |
4854 | { | |
4855 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4856 | pst->symtab = symtab; | |
4857 | pst->readin = 1; | |
4858 | } | |
c906108c SS |
4859 | |
4860 | do_cleanups (back_to); | |
4861 | } | |
4862 | ||
4863 | /* Process a die and its children. */ | |
4864 | ||
4865 | static void | |
e7c27a73 | 4866 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4867 | { |
4868 | switch (die->tag) | |
4869 | { | |
4870 | case DW_TAG_padding: | |
4871 | break; | |
4872 | case DW_TAG_compile_unit: | |
e7c27a73 | 4873 | read_file_scope (die, cu); |
c906108c | 4874 | break; |
348e048f DE |
4875 | case DW_TAG_type_unit: |
4876 | read_type_unit_scope (die, cu); | |
4877 | break; | |
c906108c | 4878 | case DW_TAG_subprogram: |
c906108c | 4879 | case DW_TAG_inlined_subroutine: |
edb3359d | 4880 | read_func_scope (die, cu); |
c906108c SS |
4881 | break; |
4882 | case DW_TAG_lexical_block: | |
14898363 L |
4883 | case DW_TAG_try_block: |
4884 | case DW_TAG_catch_block: | |
e7c27a73 | 4885 | read_lexical_block_scope (die, cu); |
c906108c | 4886 | break; |
96408a79 SA |
4887 | case DW_TAG_GNU_call_site: |
4888 | read_call_site_scope (die, cu); | |
4889 | break; | |
c906108c | 4890 | case DW_TAG_class_type: |
680b30c7 | 4891 | case DW_TAG_interface_type: |
c906108c SS |
4892 | case DW_TAG_structure_type: |
4893 | case DW_TAG_union_type: | |
134d01f1 | 4894 | process_structure_scope (die, cu); |
c906108c SS |
4895 | break; |
4896 | case DW_TAG_enumeration_type: | |
134d01f1 | 4897 | process_enumeration_scope (die, cu); |
c906108c | 4898 | break; |
134d01f1 | 4899 | |
f792889a DJ |
4900 | /* These dies have a type, but processing them does not create |
4901 | a symbol or recurse to process the children. Therefore we can | |
4902 | read them on-demand through read_type_die. */ | |
c906108c | 4903 | case DW_TAG_subroutine_type: |
72019c9c | 4904 | case DW_TAG_set_type: |
c906108c | 4905 | case DW_TAG_array_type: |
c906108c | 4906 | case DW_TAG_pointer_type: |
c906108c | 4907 | case DW_TAG_ptr_to_member_type: |
c906108c | 4908 | case DW_TAG_reference_type: |
c906108c | 4909 | case DW_TAG_string_type: |
c906108c | 4910 | break; |
134d01f1 | 4911 | |
c906108c | 4912 | case DW_TAG_base_type: |
a02abb62 | 4913 | case DW_TAG_subrange_type: |
cb249c71 | 4914 | case DW_TAG_typedef: |
134d01f1 DJ |
4915 | /* Add a typedef symbol for the type definition, if it has a |
4916 | DW_AT_name. */ | |
f792889a | 4917 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4918 | break; |
c906108c | 4919 | case DW_TAG_common_block: |
e7c27a73 | 4920 | read_common_block (die, cu); |
c906108c SS |
4921 | break; |
4922 | case DW_TAG_common_inclusion: | |
4923 | break; | |
d9fa45fe | 4924 | case DW_TAG_namespace: |
63d06c5c | 4925 | processing_has_namespace_info = 1; |
e7c27a73 | 4926 | read_namespace (die, cu); |
d9fa45fe | 4927 | break; |
5d7cb8df | 4928 | case DW_TAG_module: |
f55ee35c | 4929 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4930 | read_module (die, cu); |
4931 | break; | |
d9fa45fe DC |
4932 | case DW_TAG_imported_declaration: |
4933 | case DW_TAG_imported_module: | |
63d06c5c | 4934 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4935 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4936 | || cu->language != language_fortran)) | |
4937 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4938 | dwarf_tag_name (die->tag)); | |
4939 | read_import_statement (die, cu); | |
d9fa45fe | 4940 | break; |
c906108c | 4941 | default: |
e7c27a73 | 4942 | new_symbol (die, NULL, cu); |
c906108c SS |
4943 | break; |
4944 | } | |
4945 | } | |
4946 | ||
94af9270 KS |
4947 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4948 | needs to have the name of the scope prepended to the name listed in the | |
4949 | die. */ | |
4950 | ||
4951 | static int | |
4952 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4953 | { | |
1c809c68 TT |
4954 | struct attribute *attr; |
4955 | ||
94af9270 KS |
4956 | switch (die->tag) |
4957 | { | |
4958 | case DW_TAG_namespace: | |
4959 | case DW_TAG_typedef: | |
4960 | case DW_TAG_class_type: | |
4961 | case DW_TAG_interface_type: | |
4962 | case DW_TAG_structure_type: | |
4963 | case DW_TAG_union_type: | |
4964 | case DW_TAG_enumeration_type: | |
4965 | case DW_TAG_enumerator: | |
4966 | case DW_TAG_subprogram: | |
4967 | case DW_TAG_member: | |
4968 | return 1; | |
4969 | ||
4970 | case DW_TAG_variable: | |
c2b0a229 | 4971 | case DW_TAG_constant: |
94af9270 KS |
4972 | /* We only need to prefix "globally" visible variables. These include |
4973 | any variable marked with DW_AT_external or any variable that | |
4974 | lives in a namespace. [Variables in anonymous namespaces | |
4975 | require prefixing, but they are not DW_AT_external.] */ | |
4976 | ||
4977 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4978 | { | |
4979 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4980 | |
94af9270 KS |
4981 | return die_needs_namespace (die_specification (die, &spec_cu), |
4982 | spec_cu); | |
4983 | } | |
4984 | ||
1c809c68 | 4985 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4986 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4987 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4988 | return 0; |
4989 | /* A variable in a lexical block of some kind does not need a | |
4990 | namespace, even though in C++ such variables may be external | |
4991 | and have a mangled name. */ | |
4992 | if (die->parent->tag == DW_TAG_lexical_block | |
4993 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4994 | || die->parent->tag == DW_TAG_catch_block |
4995 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4996 | return 0; |
4997 | return 1; | |
94af9270 KS |
4998 | |
4999 | default: | |
5000 | return 0; | |
5001 | } | |
5002 | } | |
5003 | ||
98bfdba5 PA |
5004 | /* Retrieve the last character from a mem_file. */ |
5005 | ||
5006 | static void | |
5007 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
5008 | { | |
5009 | char *last_char_p = (char *) object; | |
5010 | ||
5011 | if (length > 0) | |
5012 | *last_char_p = buffer[length - 1]; | |
5013 | } | |
5014 | ||
94af9270 KS |
5015 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
5016 | compute the physname for the object, which include a method's | |
5017 | formal parameters (C++/Java) and return type (Java). | |
5018 | ||
af6b7be1 JB |
5019 | For Ada, return the DIE's linkage name rather than the fully qualified |
5020 | name. PHYSNAME is ignored.. | |
5021 | ||
94af9270 KS |
5022 | The result is allocated on the objfile_obstack and canonicalized. */ |
5023 | ||
5024 | static const char * | |
5025 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
5026 | int physname) | |
5027 | { | |
bb5ed363 DE |
5028 | struct objfile *objfile = cu->objfile; |
5029 | ||
94af9270 KS |
5030 | if (name == NULL) |
5031 | name = dwarf2_name (die, cu); | |
5032 | ||
f55ee35c JK |
5033 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
5034 | compute it by typename_concat inside GDB. */ | |
5035 | if (cu->language == language_ada | |
5036 | || (cu->language == language_fortran && physname)) | |
5037 | { | |
5038 | /* For Ada unit, we prefer the linkage name over the name, as | |
5039 | the former contains the exported name, which the user expects | |
5040 | to be able to reference. Ideally, we want the user to be able | |
5041 | to reference this entity using either natural or linkage name, | |
5042 | but we haven't started looking at this enhancement yet. */ | |
5043 | struct attribute *attr; | |
5044 | ||
5045 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5046 | if (attr == NULL) | |
5047 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5048 | if (attr && DW_STRING (attr)) | |
5049 | return DW_STRING (attr); | |
5050 | } | |
5051 | ||
94af9270 KS |
5052 | /* These are the only languages we know how to qualify names in. */ |
5053 | if (name != NULL | |
f55ee35c JK |
5054 | && (cu->language == language_cplus || cu->language == language_java |
5055 | || cu->language == language_fortran)) | |
94af9270 KS |
5056 | { |
5057 | if (die_needs_namespace (die, cu)) | |
5058 | { | |
5059 | long length; | |
0d5cff50 | 5060 | const char *prefix; |
94af9270 KS |
5061 | struct ui_file *buf; |
5062 | ||
5063 | prefix = determine_prefix (die, cu); | |
5064 | buf = mem_fileopen (); | |
5065 | if (*prefix != '\0') | |
5066 | { | |
f55ee35c JK |
5067 | char *prefixed_name = typename_concat (NULL, prefix, name, |
5068 | physname, cu); | |
9a619af0 | 5069 | |
94af9270 KS |
5070 | fputs_unfiltered (prefixed_name, buf); |
5071 | xfree (prefixed_name); | |
5072 | } | |
5073 | else | |
62d5b8da | 5074 | fputs_unfiltered (name, buf); |
94af9270 | 5075 | |
98bfdba5 PA |
5076 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
5077 | as children with DW_TAG_template_type_param or | |
5078 | DW_TAG_value_type_param. If the latter, add them to the name | |
5079 | here. If the name already has template parameters, then | |
5080 | skip this step; some versions of GCC emit both, and | |
5081 | it is more efficient to use the pre-computed name. | |
5082 | ||
5083 | Something to keep in mind about this process: it is very | |
5084 | unlikely, or in some cases downright impossible, to produce | |
5085 | something that will match the mangled name of a function. | |
5086 | If the definition of the function has the same debug info, | |
5087 | we should be able to match up with it anyway. But fallbacks | |
5088 | using the minimal symbol, for instance to find a method | |
5089 | implemented in a stripped copy of libstdc++, will not work. | |
5090 | If we do not have debug info for the definition, we will have to | |
5091 | match them up some other way. | |
5092 | ||
5093 | When we do name matching there is a related problem with function | |
5094 | templates; two instantiated function templates are allowed to | |
5095 | differ only by their return types, which we do not add here. */ | |
5096 | ||
5097 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
5098 | { | |
5099 | struct attribute *attr; | |
5100 | struct die_info *child; | |
5101 | int first = 1; | |
5102 | ||
5103 | die->building_fullname = 1; | |
5104 | ||
5105 | for (child = die->child; child != NULL; child = child->sibling) | |
5106 | { | |
5107 | struct type *type; | |
5108 | long value; | |
5109 | gdb_byte *bytes; | |
5110 | struct dwarf2_locexpr_baton *baton; | |
5111 | struct value *v; | |
5112 | ||
5113 | if (child->tag != DW_TAG_template_type_param | |
5114 | && child->tag != DW_TAG_template_value_param) | |
5115 | continue; | |
5116 | ||
5117 | if (first) | |
5118 | { | |
5119 | fputs_unfiltered ("<", buf); | |
5120 | first = 0; | |
5121 | } | |
5122 | else | |
5123 | fputs_unfiltered (", ", buf); | |
5124 | ||
5125 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
5126 | if (attr == NULL) | |
5127 | { | |
5128 | complaint (&symfile_complaints, | |
5129 | _("template parameter missing DW_AT_type")); | |
5130 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
5131 | continue; | |
5132 | } | |
5133 | type = die_type (child, cu); | |
5134 | ||
5135 | if (child->tag == DW_TAG_template_type_param) | |
5136 | { | |
5137 | c_print_type (type, "", buf, -1, 0); | |
5138 | continue; | |
5139 | } | |
5140 | ||
5141 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
5142 | if (attr == NULL) | |
5143 | { | |
5144 | complaint (&symfile_complaints, | |
3e43a32a MS |
5145 | _("template parameter missing " |
5146 | "DW_AT_const_value")); | |
98bfdba5 PA |
5147 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
5148 | continue; | |
5149 | } | |
5150 | ||
5151 | dwarf2_const_value_attr (attr, type, name, | |
5152 | &cu->comp_unit_obstack, cu, | |
5153 | &value, &bytes, &baton); | |
5154 | ||
5155 | if (TYPE_NOSIGN (type)) | |
5156 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
5157 | changed, this can use value_print instead. */ | |
5158 | c_printchar (value, type, buf); | |
5159 | else | |
5160 | { | |
5161 | struct value_print_options opts; | |
5162 | ||
5163 | if (baton != NULL) | |
5164 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
5165 | baton->data, | |
5166 | baton->size, | |
5167 | baton->per_cu); | |
5168 | else if (bytes != NULL) | |
5169 | { | |
5170 | v = allocate_value (type); | |
5171 | memcpy (value_contents_writeable (v), bytes, | |
5172 | TYPE_LENGTH (type)); | |
5173 | } | |
5174 | else | |
5175 | v = value_from_longest (type, value); | |
5176 | ||
3e43a32a MS |
5177 | /* Specify decimal so that we do not depend on |
5178 | the radix. */ | |
98bfdba5 PA |
5179 | get_formatted_print_options (&opts, 'd'); |
5180 | opts.raw = 1; | |
5181 | value_print (v, buf, &opts); | |
5182 | release_value (v); | |
5183 | value_free (v); | |
5184 | } | |
5185 | } | |
5186 | ||
5187 | die->building_fullname = 0; | |
5188 | ||
5189 | if (!first) | |
5190 | { | |
5191 | /* Close the argument list, with a space if necessary | |
5192 | (nested templates). */ | |
5193 | char last_char = '\0'; | |
5194 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
5195 | if (last_char == '>') | |
5196 | fputs_unfiltered (" >", buf); | |
5197 | else | |
5198 | fputs_unfiltered (">", buf); | |
5199 | } | |
5200 | } | |
5201 | ||
94af9270 KS |
5202 | /* For Java and C++ methods, append formal parameter type |
5203 | information, if PHYSNAME. */ | |
6e70227d | 5204 | |
94af9270 KS |
5205 | if (physname && die->tag == DW_TAG_subprogram |
5206 | && (cu->language == language_cplus | |
5207 | || cu->language == language_java)) | |
5208 | { | |
5209 | struct type *type = read_type_die (die, cu); | |
5210 | ||
3167638f | 5211 | c_type_print_args (type, buf, 1, cu->language); |
94af9270 KS |
5212 | |
5213 | if (cu->language == language_java) | |
5214 | { | |
5215 | /* For java, we must append the return type to method | |
0963b4bd | 5216 | names. */ |
94af9270 KS |
5217 | if (die->tag == DW_TAG_subprogram) |
5218 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
5219 | 0, 0); | |
5220 | } | |
5221 | else if (cu->language == language_cplus) | |
5222 | { | |
60430eff DJ |
5223 | /* Assume that an artificial first parameter is |
5224 | "this", but do not crash if it is not. RealView | |
5225 | marks unnamed (and thus unused) parameters as | |
5226 | artificial; there is no way to differentiate | |
5227 | the two cases. */ | |
94af9270 KS |
5228 | if (TYPE_NFIELDS (type) > 0 |
5229 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 5230 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
5231 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
5232 | 0)))) | |
94af9270 KS |
5233 | fputs_unfiltered (" const", buf); |
5234 | } | |
5235 | } | |
5236 | ||
bb5ed363 | 5237 | name = ui_file_obsavestring (buf, &objfile->objfile_obstack, |
94af9270 KS |
5238 | &length); |
5239 | ui_file_delete (buf); | |
5240 | ||
5241 | if (cu->language == language_cplus) | |
5242 | { | |
5243 | char *cname | |
5244 | = dwarf2_canonicalize_name (name, cu, | |
bb5ed363 | 5245 | &objfile->objfile_obstack); |
9a619af0 | 5246 | |
94af9270 KS |
5247 | if (cname != NULL) |
5248 | name = cname; | |
5249 | } | |
5250 | } | |
5251 | } | |
5252 | ||
5253 | return name; | |
5254 | } | |
5255 | ||
0114d602 DJ |
5256 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
5257 | If scope qualifiers are appropriate they will be added. The result | |
5258 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
5259 | not have a name. NAME may either be from a previous call to |
5260 | dwarf2_name or NULL. | |
5261 | ||
0963b4bd | 5262 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
5263 | |
5264 | static const char * | |
94af9270 | 5265 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 5266 | { |
94af9270 KS |
5267 | return dwarf2_compute_name (name, die, cu, 0); |
5268 | } | |
0114d602 | 5269 | |
94af9270 KS |
5270 | /* Construct a physname for the given DIE in CU. NAME may either be |
5271 | from a previous call to dwarf2_name or NULL. The result will be | |
5272 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
5273 | name. | |
0114d602 | 5274 | |
94af9270 | 5275 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 5276 | |
94af9270 KS |
5277 | static const char * |
5278 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
5279 | { | |
bb5ed363 | 5280 | struct objfile *objfile = cu->objfile; |
900e11f9 JK |
5281 | struct attribute *attr; |
5282 | const char *retval, *mangled = NULL, *canon = NULL; | |
5283 | struct cleanup *back_to; | |
5284 | int need_copy = 1; | |
5285 | ||
5286 | /* In this case dwarf2_compute_name is just a shortcut not building anything | |
5287 | on its own. */ | |
5288 | if (!die_needs_namespace (die, cu)) | |
5289 | return dwarf2_compute_name (name, die, cu, 1); | |
5290 | ||
5291 | back_to = make_cleanup (null_cleanup, NULL); | |
5292 | ||
5293 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5294 | if (!attr) | |
5295 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5296 | ||
5297 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB | |
5298 | has computed. */ | |
5299 | if (attr && DW_STRING (attr)) | |
5300 | { | |
5301 | char *demangled; | |
5302 | ||
5303 | mangled = DW_STRING (attr); | |
5304 | ||
5305 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return | |
5306 | type. It is easier for GDB users to search for such functions as | |
5307 | `name(params)' than `long name(params)'. In such case the minimal | |
5308 | symbol names do not match the full symbol names but for template | |
5309 | functions there is never a need to look up their definition from their | |
5310 | declaration so the only disadvantage remains the minimal symbol | |
5311 | variant `long name(params)' does not have the proper inferior type. | |
5312 | */ | |
5313 | ||
5314 | demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI | |
5315 | | (cu->language == language_java | |
5316 | ? DMGL_JAVA | DMGL_RET_POSTFIX | |
5317 | : DMGL_RET_DROP))); | |
5318 | if (demangled) | |
5319 | { | |
5320 | make_cleanup (xfree, demangled); | |
5321 | canon = demangled; | |
5322 | } | |
5323 | else | |
5324 | { | |
5325 | canon = mangled; | |
5326 | need_copy = 0; | |
5327 | } | |
5328 | } | |
5329 | ||
5330 | if (canon == NULL || check_physname) | |
5331 | { | |
5332 | const char *physname = dwarf2_compute_name (name, die, cu, 1); | |
5333 | ||
5334 | if (canon != NULL && strcmp (physname, canon) != 0) | |
5335 | { | |
5336 | /* It may not mean a bug in GDB. The compiler could also | |
5337 | compute DW_AT_linkage_name incorrectly. But in such case | |
5338 | GDB would need to be bug-to-bug compatible. */ | |
5339 | ||
5340 | complaint (&symfile_complaints, | |
5341 | _("Computed physname <%s> does not match demangled <%s> " | |
5342 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), | |
bb5ed363 | 5343 | physname, canon, mangled, die->offset, objfile->name); |
900e11f9 JK |
5344 | |
5345 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it | |
5346 | is available here - over computed PHYSNAME. It is safer | |
5347 | against both buggy GDB and buggy compilers. */ | |
5348 | ||
5349 | retval = canon; | |
5350 | } | |
5351 | else | |
5352 | { | |
5353 | retval = physname; | |
5354 | need_copy = 0; | |
5355 | } | |
5356 | } | |
5357 | else | |
5358 | retval = canon; | |
5359 | ||
5360 | if (need_copy) | |
5361 | retval = obsavestring (retval, strlen (retval), | |
bb5ed363 | 5362 | &objfile->objfile_obstack); |
900e11f9 JK |
5363 | |
5364 | do_cleanups (back_to); | |
5365 | return retval; | |
0114d602 DJ |
5366 | } |
5367 | ||
27aa8d6a SW |
5368 | /* Read the import statement specified by the given die and record it. */ |
5369 | ||
5370 | static void | |
5371 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
5372 | { | |
bb5ed363 | 5373 | struct objfile *objfile = cu->objfile; |
27aa8d6a | 5374 | struct attribute *import_attr; |
32019081 | 5375 | struct die_info *imported_die, *child_die; |
de4affc9 | 5376 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 5377 | const char *imported_name; |
794684b6 | 5378 | const char *imported_name_prefix; |
13387711 SW |
5379 | const char *canonical_name; |
5380 | const char *import_alias; | |
5381 | const char *imported_declaration = NULL; | |
794684b6 | 5382 | const char *import_prefix; |
32019081 JK |
5383 | VEC (const_char_ptr) *excludes = NULL; |
5384 | struct cleanup *cleanups; | |
13387711 SW |
5385 | |
5386 | char *temp; | |
27aa8d6a SW |
5387 | |
5388 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
5389 | if (import_attr == NULL) | |
5390 | { | |
5391 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5392 | dwarf_tag_name (die->tag)); | |
5393 | return; | |
5394 | } | |
5395 | ||
de4affc9 CC |
5396 | imported_cu = cu; |
5397 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
5398 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
5399 | if (imported_name == NULL) |
5400 | { | |
5401 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
5402 | ||
5403 | The import in the following code: | |
5404 | namespace A | |
5405 | { | |
5406 | typedef int B; | |
5407 | } | |
5408 | ||
5409 | int main () | |
5410 | { | |
5411 | using A::B; | |
5412 | B b; | |
5413 | return b; | |
5414 | } | |
5415 | ||
5416 | ... | |
5417 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
5418 | <52> DW_AT_decl_file : 1 | |
5419 | <53> DW_AT_decl_line : 6 | |
5420 | <54> DW_AT_import : <0x75> | |
5421 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
5422 | <59> DW_AT_name : B | |
5423 | <5b> DW_AT_decl_file : 1 | |
5424 | <5c> DW_AT_decl_line : 2 | |
5425 | <5d> DW_AT_type : <0x6e> | |
5426 | ... | |
5427 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
5428 | <76> DW_AT_byte_size : 4 | |
5429 | <77> DW_AT_encoding : 5 (signed) | |
5430 | ||
5431 | imports the wrong die ( 0x75 instead of 0x58 ). | |
5432 | This case will be ignored until the gcc bug is fixed. */ | |
5433 | return; | |
5434 | } | |
5435 | ||
82856980 SW |
5436 | /* Figure out the local name after import. */ |
5437 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 5438 | |
794684b6 SW |
5439 | /* Figure out where the statement is being imported to. */ |
5440 | import_prefix = determine_prefix (die, cu); | |
5441 | ||
5442 | /* Figure out what the scope of the imported die is and prepend it | |
5443 | to the name of the imported die. */ | |
de4affc9 | 5444 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 5445 | |
f55ee35c JK |
5446 | if (imported_die->tag != DW_TAG_namespace |
5447 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 5448 | { |
13387711 SW |
5449 | imported_declaration = imported_name; |
5450 | canonical_name = imported_name_prefix; | |
794684b6 | 5451 | } |
13387711 | 5452 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 5453 | { |
13387711 SW |
5454 | temp = alloca (strlen (imported_name_prefix) |
5455 | + 2 + strlen (imported_name) + 1); | |
5456 | strcpy (temp, imported_name_prefix); | |
5457 | strcat (temp, "::"); | |
5458 | strcat (temp, imported_name); | |
5459 | canonical_name = temp; | |
794684b6 | 5460 | } |
13387711 SW |
5461 | else |
5462 | canonical_name = imported_name; | |
794684b6 | 5463 | |
32019081 JK |
5464 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
5465 | ||
5466 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) | |
5467 | for (child_die = die->child; child_die && child_die->tag; | |
5468 | child_die = sibling_die (child_die)) | |
5469 | { | |
5470 | /* DWARF-4: A Fortran use statement with a “rename list” may be | |
5471 | represented by an imported module entry with an import attribute | |
5472 | referring to the module and owned entries corresponding to those | |
5473 | entities that are renamed as part of being imported. */ | |
5474 | ||
5475 | if (child_die->tag != DW_TAG_imported_declaration) | |
5476 | { | |
5477 | complaint (&symfile_complaints, | |
5478 | _("child DW_TAG_imported_declaration expected " | |
5479 | "- DIE at 0x%x [in module %s]"), | |
bb5ed363 | 5480 | child_die->offset, objfile->name); |
32019081 JK |
5481 | continue; |
5482 | } | |
5483 | ||
5484 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); | |
5485 | if (import_attr == NULL) | |
5486 | { | |
5487 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5488 | dwarf_tag_name (child_die->tag)); | |
5489 | continue; | |
5490 | } | |
5491 | ||
5492 | imported_cu = cu; | |
5493 | imported_die = follow_die_ref_or_sig (child_die, import_attr, | |
5494 | &imported_cu); | |
5495 | imported_name = dwarf2_name (imported_die, imported_cu); | |
5496 | if (imported_name == NULL) | |
5497 | { | |
5498 | complaint (&symfile_complaints, | |
5499 | _("child DW_TAG_imported_declaration has unknown " | |
5500 | "imported name - DIE at 0x%x [in module %s]"), | |
bb5ed363 | 5501 | child_die->offset, objfile->name); |
32019081 JK |
5502 | continue; |
5503 | } | |
5504 | ||
5505 | VEC_safe_push (const_char_ptr, excludes, imported_name); | |
5506 | ||
5507 | process_die (child_die, cu); | |
5508 | } | |
5509 | ||
c0cc3a76 SW |
5510 | cp_add_using_directive (import_prefix, |
5511 | canonical_name, | |
5512 | import_alias, | |
13387711 | 5513 | imported_declaration, |
32019081 | 5514 | excludes, |
bb5ed363 | 5515 | &objfile->objfile_obstack); |
32019081 JK |
5516 | |
5517 | do_cleanups (cleanups); | |
27aa8d6a SW |
5518 | } |
5519 | ||
ae2de4f8 DE |
5520 | /* Cleanup function for read_file_scope. */ |
5521 | ||
cb1df416 DJ |
5522 | static void |
5523 | free_cu_line_header (void *arg) | |
5524 | { | |
5525 | struct dwarf2_cu *cu = arg; | |
5526 | ||
5527 | free_line_header (cu->line_header); | |
5528 | cu->line_header = NULL; | |
5529 | } | |
5530 | ||
9291a0cd TT |
5531 | static void |
5532 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
5533 | char **name, char **comp_dir) | |
5534 | { | |
5535 | struct attribute *attr; | |
5536 | ||
5537 | *name = NULL; | |
5538 | *comp_dir = NULL; | |
5539 | ||
5540 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5541 | is not a source language identifier. */ | |
5542 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5543 | if (attr) | |
5544 | { | |
5545 | *name = DW_STRING (attr); | |
5546 | } | |
5547 | ||
5548 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5549 | if (attr) | |
5550 | *comp_dir = DW_STRING (attr); | |
5551 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
5552 | { | |
5553 | *comp_dir = ldirname (*name); | |
5554 | if (*comp_dir != NULL) | |
5555 | make_cleanup (xfree, *comp_dir); | |
5556 | } | |
5557 | if (*comp_dir != NULL) | |
5558 | { | |
5559 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
5560 | directory, get rid of it. */ | |
5561 | char *cp = strchr (*comp_dir, ':'); | |
5562 | ||
5563 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
5564 | *comp_dir = cp + 1; | |
5565 | } | |
5566 | ||
5567 | if (*name == NULL) | |
5568 | *name = "<unknown>"; | |
5569 | } | |
5570 | ||
f3f5162e DE |
5571 | /* Handle DW_AT_stmt_list for a compilation unit or type unit. |
5572 | DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU. | |
5573 | COMP_DIR is the compilation directory. | |
5574 | WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */ | |
2ab95328 TT |
5575 | |
5576 | static void | |
5577 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, | |
f3f5162e | 5578 | const char *comp_dir, int want_line_info) |
2ab95328 TT |
5579 | { |
5580 | struct attribute *attr; | |
5581 | struct objfile *objfile = cu->objfile; | |
5582 | bfd *abfd = objfile->obfd; | |
5583 | ||
2ab95328 TT |
5584 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5585 | if (attr) | |
5586 | { | |
5587 | unsigned int line_offset = DW_UNSND (attr); | |
5588 | struct line_header *line_header | |
5589 | = dwarf_decode_line_header (line_offset, abfd, cu); | |
5590 | ||
5591 | if (line_header) | |
5592 | { | |
5593 | cu->line_header = line_header; | |
5594 | make_cleanup (free_cu_line_header, cu); | |
f3f5162e | 5595 | dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info); |
2ab95328 TT |
5596 | } |
5597 | } | |
5598 | } | |
5599 | ||
ae2de4f8 DE |
5600 | /* Process DW_TAG_compile_unit. */ |
5601 | ||
c906108c | 5602 | static void |
e7c27a73 | 5603 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5604 | { |
e7c27a73 | 5605 | struct objfile *objfile = cu->objfile; |
debd256d | 5606 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 5607 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
5608 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
5609 | struct attribute *attr; | |
e1024ff1 | 5610 | char *name = NULL; |
c906108c SS |
5611 | char *comp_dir = NULL; |
5612 | struct die_info *child_die; | |
5613 | bfd *abfd = objfile->obfd; | |
e142c38c | 5614 | CORE_ADDR baseaddr; |
6e70227d | 5615 | |
e142c38c | 5616 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 5617 | |
fae299cd | 5618 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
5619 | |
5620 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
5621 | from finish_block. */ | |
2acceee2 | 5622 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
5623 | lowpc = highpc; |
5624 | lowpc += baseaddr; | |
5625 | highpc += baseaddr; | |
5626 | ||
9291a0cd | 5627 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 5628 | |
e142c38c | 5629 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
5630 | if (attr) |
5631 | { | |
e142c38c | 5632 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
5633 | } |
5634 | ||
b0f35d58 | 5635 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 5636 | if (attr) |
b0f35d58 | 5637 | cu->producer = DW_STRING (attr); |
303b6f5d | 5638 | |
f4b8a18d KW |
5639 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
5640 | standardised yet. As a workaround for the language detection we fall | |
5641 | back to the DW_AT_producer string. */ | |
5642 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
5643 | cu->language = language_opencl; | |
5644 | ||
0963b4bd | 5645 | /* We assume that we're processing GCC output. */ |
c906108c | 5646 | processing_gcc_compilation = 2; |
c906108c | 5647 | |
df8a16a1 DJ |
5648 | processing_has_namespace_info = 0; |
5649 | ||
c906108c SS |
5650 | start_symtab (name, comp_dir, lowpc); |
5651 | record_debugformat ("DWARF 2"); | |
303b6f5d | 5652 | record_producer (cu->producer); |
c906108c | 5653 | |
f3f5162e DE |
5654 | /* Decode line number information if present. We do this before |
5655 | processing child DIEs, so that the line header table is available | |
5656 | for DW_AT_decl_file. */ | |
5657 | handle_DW_AT_stmt_list (die, cu, comp_dir, 1); | |
debd256d | 5658 | |
cb1df416 DJ |
5659 | /* Process all dies in compilation unit. */ |
5660 | if (die->child != NULL) | |
5661 | { | |
5662 | child_die = die->child; | |
5663 | while (child_die && child_die->tag) | |
5664 | { | |
5665 | process_die (child_die, cu); | |
5666 | child_die = sibling_die (child_die); | |
5667 | } | |
5668 | } | |
5669 | ||
2e276125 JB |
5670 | /* Decode macro information, if present. Dwarf 2 macro information |
5671 | refers to information in the line number info statement program | |
5672 | header, so we can only read it if we've read the header | |
5673 | successfully. */ | |
cf2c3c16 | 5674 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); |
2ab95328 | 5675 | if (attr && cu->line_header) |
2e276125 | 5676 | { |
cf2c3c16 TT |
5677 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) |
5678 | complaint (&symfile_complaints, | |
5679 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); | |
5680 | ||
5681 | dwarf_decode_macros (cu->line_header, DW_UNSND (attr), | |
5682 | comp_dir, abfd, cu, | |
5683 | &dwarf2_per_objfile->macro, 1); | |
5684 | } | |
5685 | else | |
5686 | { | |
5687 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |
5688 | if (attr && cu->line_header) | |
5689 | { | |
5690 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 5691 | |
cf2c3c16 TT |
5692 | dwarf_decode_macros (cu->line_header, macro_offset, |
5693 | comp_dir, abfd, cu, | |
5694 | &dwarf2_per_objfile->macinfo, 0); | |
5695 | } | |
2e276125 | 5696 | } |
9cdd5dbd | 5697 | |
debd256d | 5698 | do_cleanups (back_to); |
5fb290d7 DJ |
5699 | } |
5700 | ||
ae2de4f8 DE |
5701 | /* Process DW_TAG_type_unit. |
5702 | For TUs we want to skip the first top level sibling if it's not the | |
348e048f DE |
5703 | actual type being defined by this TU. In this case the first top |
5704 | level sibling is there to provide context only. */ | |
5705 | ||
5706 | static void | |
5707 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5708 | { | |
5709 | struct objfile *objfile = cu->objfile; | |
5710 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
5711 | CORE_ADDR lowpc; | |
5712 | struct attribute *attr; | |
5713 | char *name = NULL; | |
5714 | char *comp_dir = NULL; | |
5715 | struct die_info *child_die; | |
5716 | bfd *abfd = objfile->obfd; | |
348e048f DE |
5717 | |
5718 | /* start_symtab needs a low pc, but we don't really have one. | |
5719 | Do what read_file_scope would do in the absence of such info. */ | |
5720 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5721 | ||
5722 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5723 | is not a source language identifier. */ | |
5724 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5725 | if (attr) | |
5726 | name = DW_STRING (attr); | |
5727 | ||
5728 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5729 | if (attr) | |
5730 | comp_dir = DW_STRING (attr); | |
5731 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
5732 | { | |
5733 | comp_dir = ldirname (name); | |
5734 | if (comp_dir != NULL) | |
5735 | make_cleanup (xfree, comp_dir); | |
5736 | } | |
5737 | ||
5738 | if (name == NULL) | |
5739 | name = "<unknown>"; | |
5740 | ||
5741 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
5742 | if (attr) | |
5743 | set_cu_language (DW_UNSND (attr), cu); | |
5744 | ||
5745 | /* This isn't technically needed today. It is done for symmetry | |
5746 | with read_file_scope. */ | |
5747 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 5748 | if (attr) |
348e048f DE |
5749 | cu->producer = DW_STRING (attr); |
5750 | ||
0963b4bd | 5751 | /* We assume that we're processing GCC output. */ |
348e048f DE |
5752 | processing_gcc_compilation = 2; |
5753 | ||
5754 | processing_has_namespace_info = 0; | |
5755 | ||
5756 | start_symtab (name, comp_dir, lowpc); | |
5757 | record_debugformat ("DWARF 2"); | |
5758 | record_producer (cu->producer); | |
5759 | ||
f3f5162e DE |
5760 | /* Decode line number information if present. We do this before |
5761 | processing child DIEs, so that the line header table is available | |
5762 | for DW_AT_decl_file. | |
5763 | We don't need the pc/line-number mapping for type units. */ | |
5764 | handle_DW_AT_stmt_list (die, cu, comp_dir, 0); | |
2ab95328 | 5765 | |
348e048f DE |
5766 | /* Process the dies in the type unit. */ |
5767 | if (die->child == NULL) | |
5768 | { | |
5769 | dump_die_for_error (die); | |
5770 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
5771 | bfd_get_filename (abfd)); | |
5772 | } | |
5773 | ||
5774 | child_die = die->child; | |
5775 | ||
5776 | while (child_die && child_die->tag) | |
5777 | { | |
5778 | process_die (child_die, cu); | |
5779 | ||
5780 | child_die = sibling_die (child_die); | |
5781 | } | |
5782 | ||
5783 | do_cleanups (back_to); | |
5784 | } | |
5785 | ||
d389af10 JK |
5786 | /* qsort helper for inherit_abstract_dies. */ |
5787 | ||
5788 | static int | |
5789 | unsigned_int_compar (const void *ap, const void *bp) | |
5790 | { | |
5791 | unsigned int a = *(unsigned int *) ap; | |
5792 | unsigned int b = *(unsigned int *) bp; | |
5793 | ||
5794 | return (a > b) - (b > a); | |
5795 | } | |
5796 | ||
5797 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
5798 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
5799 | already referenced by DW_AT_abstract_origin from the children of the | |
5800 | current DIE. */ | |
d389af10 JK |
5801 | |
5802 | static void | |
5803 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
5804 | { | |
5805 | struct die_info *child_die; | |
5806 | unsigned die_children_count; | |
5807 | /* CU offsets which were referenced by children of the current DIE. */ | |
5808 | unsigned *offsets; | |
5809 | unsigned *offsets_end, *offsetp; | |
5810 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
5811 | struct die_info *origin_die; | |
5812 | /* Iterator of the ORIGIN_DIE children. */ | |
5813 | struct die_info *origin_child_die; | |
5814 | struct cleanup *cleanups; | |
5815 | struct attribute *attr; | |
cd02d79d PA |
5816 | struct dwarf2_cu *origin_cu; |
5817 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
5818 | |
5819 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
5820 | if (!attr) | |
5821 | return; | |
5822 | ||
cd02d79d PA |
5823 | /* Note that following die references may follow to a die in a |
5824 | different cu. */ | |
5825 | ||
5826 | origin_cu = cu; | |
5827 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
5828 | ||
5829 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
5830 | symbols in. */ | |
5831 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
5832 | origin_cu->list_in_scope = cu->list_in_scope; | |
5833 | ||
edb3359d DJ |
5834 | if (die->tag != origin_die->tag |
5835 | && !(die->tag == DW_TAG_inlined_subroutine | |
5836 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5837 | complaint (&symfile_complaints, |
5838 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
5839 | die->offset, origin_die->offset); | |
5840 | ||
5841 | child_die = die->child; | |
5842 | die_children_count = 0; | |
5843 | while (child_die && child_die->tag) | |
5844 | { | |
5845 | child_die = sibling_die (child_die); | |
5846 | die_children_count++; | |
5847 | } | |
5848 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
5849 | cleanups = make_cleanup (xfree, offsets); | |
5850 | ||
5851 | offsets_end = offsets; | |
5852 | child_die = die->child; | |
5853 | while (child_die && child_die->tag) | |
5854 | { | |
c38f313d DJ |
5855 | /* For each CHILD_DIE, find the corresponding child of |
5856 | ORIGIN_DIE. If there is more than one layer of | |
5857 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
5858 | but GCC versions at least through 4.4 generate this (GCC PR | |
5859 | 40573). */ | |
5860 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 5861 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 5862 | |
c38f313d DJ |
5863 | while (1) |
5864 | { | |
cd02d79d PA |
5865 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
5866 | child_origin_cu); | |
c38f313d DJ |
5867 | if (attr == NULL) |
5868 | break; | |
cd02d79d PA |
5869 | child_origin_die = follow_die_ref (child_origin_die, attr, |
5870 | &child_origin_cu); | |
c38f313d DJ |
5871 | } |
5872 | ||
d389af10 JK |
5873 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
5874 | counterpart may exist. */ | |
c38f313d | 5875 | if (child_origin_die != child_die) |
d389af10 | 5876 | { |
edb3359d DJ |
5877 | if (child_die->tag != child_origin_die->tag |
5878 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
5879 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5880 | complaint (&symfile_complaints, |
5881 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5882 | "different tags"), child_die->offset, | |
5883 | child_origin_die->offset); | |
c38f313d DJ |
5884 | if (child_origin_die->parent != origin_die) |
5885 | complaint (&symfile_complaints, | |
5886 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5887 | "different parents"), child_die->offset, | |
5888 | child_origin_die->offset); | |
5889 | else | |
5890 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
5891 | } |
5892 | child_die = sibling_die (child_die); | |
5893 | } | |
5894 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
5895 | unsigned_int_compar); | |
5896 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
5897 | if (offsetp[-1] == *offsetp) | |
3e43a32a MS |
5898 | complaint (&symfile_complaints, |
5899 | _("Multiple children of DIE 0x%x refer " | |
5900 | "to DIE 0x%x as their abstract origin"), | |
d389af10 JK |
5901 | die->offset, *offsetp); |
5902 | ||
5903 | offsetp = offsets; | |
5904 | origin_child_die = origin_die->child; | |
5905 | while (origin_child_die && origin_child_die->tag) | |
5906 | { | |
5907 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
5908 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
5909 | offsetp++; | |
5910 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
5911 | { | |
5912 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 5913 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
5914 | } |
5915 | origin_child_die = sibling_die (origin_child_die); | |
5916 | } | |
cd02d79d | 5917 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
5918 | |
5919 | do_cleanups (cleanups); | |
5920 | } | |
5921 | ||
c906108c | 5922 | static void |
e7c27a73 | 5923 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5924 | { |
e7c27a73 | 5925 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5926 | struct context_stack *new; |
c906108c SS |
5927 | CORE_ADDR lowpc; |
5928 | CORE_ADDR highpc; | |
5929 | struct die_info *child_die; | |
edb3359d | 5930 | struct attribute *attr, *call_line, *call_file; |
c906108c | 5931 | char *name; |
e142c38c | 5932 | CORE_ADDR baseaddr; |
801e3a5b | 5933 | struct block *block; |
edb3359d | 5934 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
5935 | VEC (symbolp) *template_args = NULL; |
5936 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
5937 | |
5938 | if (inlined_func) | |
5939 | { | |
5940 | /* If we do not have call site information, we can't show the | |
5941 | caller of this inlined function. That's too confusing, so | |
5942 | only use the scope for local variables. */ | |
5943 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
5944 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
5945 | if (call_line == NULL || call_file == NULL) | |
5946 | { | |
5947 | read_lexical_block_scope (die, cu); | |
5948 | return; | |
5949 | } | |
5950 | } | |
c906108c | 5951 | |
e142c38c DJ |
5952 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
5953 | ||
94af9270 | 5954 | name = dwarf2_name (die, cu); |
c906108c | 5955 | |
e8d05480 JB |
5956 | /* Ignore functions with missing or empty names. These are actually |
5957 | illegal according to the DWARF standard. */ | |
5958 | if (name == NULL) | |
5959 | { | |
5960 | complaint (&symfile_complaints, | |
5961 | _("missing name for subprogram DIE at %d"), die->offset); | |
5962 | return; | |
5963 | } | |
5964 | ||
5965 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
5966 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
5967 | { | |
ae4d0c03 PM |
5968 | attr = dwarf2_attr (die, DW_AT_external, cu); |
5969 | if (!attr || !DW_UNSND (attr)) | |
5970 | complaint (&symfile_complaints, | |
3e43a32a MS |
5971 | _("cannot get low and high bounds " |
5972 | "for subprogram DIE at %d"), | |
ae4d0c03 | 5973 | die->offset); |
e8d05480 JB |
5974 | return; |
5975 | } | |
c906108c SS |
5976 | |
5977 | lowpc += baseaddr; | |
5978 | highpc += baseaddr; | |
5979 | ||
34eaf542 TT |
5980 | /* If we have any template arguments, then we must allocate a |
5981 | different sort of symbol. */ | |
5982 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
5983 | { | |
5984 | if (child_die->tag == DW_TAG_template_type_param | |
5985 | || child_die->tag == DW_TAG_template_value_param) | |
5986 | { | |
5987 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5988 | struct template_symbol); | |
5989 | templ_func->base.is_cplus_template_function = 1; | |
5990 | break; | |
5991 | } | |
5992 | } | |
5993 | ||
c906108c | 5994 | new = push_context (0, lowpc); |
34eaf542 TT |
5995 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
5996 | (struct symbol *) templ_func); | |
4c2df51b | 5997 | |
4cecd739 DJ |
5998 | /* If there is a location expression for DW_AT_frame_base, record |
5999 | it. */ | |
e142c38c | 6000 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 6001 | if (attr) |
c034e007 AC |
6002 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
6003 | expression is being recorded directly in the function's symbol | |
6004 | and not in a separate frame-base object. I guess this hack is | |
6005 | to avoid adding some sort of frame-base adjunct/annex to the | |
6006 | function's symbol :-(. The problem with doing this is that it | |
6007 | results in a function symbol with a location expression that | |
6008 | has nothing to do with the location of the function, ouch! The | |
6009 | relationship should be: a function's symbol has-a frame base; a | |
6010 | frame-base has-a location expression. */ | |
e7c27a73 | 6011 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 6012 | |
e142c38c | 6013 | cu->list_in_scope = &local_symbols; |
c906108c | 6014 | |
639d11d3 | 6015 | if (die->child != NULL) |
c906108c | 6016 | { |
639d11d3 | 6017 | child_die = die->child; |
c906108c SS |
6018 | while (child_die && child_die->tag) |
6019 | { | |
34eaf542 TT |
6020 | if (child_die->tag == DW_TAG_template_type_param |
6021 | || child_die->tag == DW_TAG_template_value_param) | |
6022 | { | |
6023 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
6024 | ||
f1078f66 DJ |
6025 | if (arg != NULL) |
6026 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
6027 | } |
6028 | else | |
6029 | process_die (child_die, cu); | |
c906108c SS |
6030 | child_die = sibling_die (child_die); |
6031 | } | |
6032 | } | |
6033 | ||
d389af10 JK |
6034 | inherit_abstract_dies (die, cu); |
6035 | ||
4a811a97 UW |
6036 | /* If we have a DW_AT_specification, we might need to import using |
6037 | directives from the context of the specification DIE. See the | |
6038 | comment in determine_prefix. */ | |
6039 | if (cu->language == language_cplus | |
6040 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
6041 | { | |
6042 | struct dwarf2_cu *spec_cu = cu; | |
6043 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
6044 | ||
6045 | while (spec_die) | |
6046 | { | |
6047 | child_die = spec_die->child; | |
6048 | while (child_die && child_die->tag) | |
6049 | { | |
6050 | if (child_die->tag == DW_TAG_imported_module) | |
6051 | process_die (child_die, spec_cu); | |
6052 | child_die = sibling_die (child_die); | |
6053 | } | |
6054 | ||
6055 | /* In some cases, GCC generates specification DIEs that | |
6056 | themselves contain DW_AT_specification attributes. */ | |
6057 | spec_die = die_specification (spec_die, &spec_cu); | |
6058 | } | |
6059 | } | |
6060 | ||
c906108c SS |
6061 | new = pop_context (); |
6062 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
6063 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
6064 | lowpc, highpc, objfile); | |
6065 | ||
df8a16a1 | 6066 | /* For C++, set the block's scope. */ |
f55ee35c | 6067 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 6068 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 6069 | determine_prefix (die, cu), |
df8a16a1 DJ |
6070 | processing_has_namespace_info); |
6071 | ||
801e3a5b JB |
6072 | /* If we have address ranges, record them. */ |
6073 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 6074 | |
34eaf542 TT |
6075 | /* Attach template arguments to function. */ |
6076 | if (! VEC_empty (symbolp, template_args)) | |
6077 | { | |
6078 | gdb_assert (templ_func != NULL); | |
6079 | ||
6080 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
6081 | templ_func->template_arguments | |
6082 | = obstack_alloc (&objfile->objfile_obstack, | |
6083 | (templ_func->n_template_arguments | |
6084 | * sizeof (struct symbol *))); | |
6085 | memcpy (templ_func->template_arguments, | |
6086 | VEC_address (symbolp, template_args), | |
6087 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
6088 | VEC_free (symbolp, template_args); | |
6089 | } | |
6090 | ||
208d8187 JB |
6091 | /* In C++, we can have functions nested inside functions (e.g., when |
6092 | a function declares a class that has methods). This means that | |
6093 | when we finish processing a function scope, we may need to go | |
6094 | back to building a containing block's symbol lists. */ | |
6095 | local_symbols = new->locals; | |
6096 | param_symbols = new->params; | |
27aa8d6a | 6097 | using_directives = new->using_directives; |
208d8187 | 6098 | |
921e78cf JB |
6099 | /* If we've finished processing a top-level function, subsequent |
6100 | symbols go in the file symbol list. */ | |
6101 | if (outermost_context_p ()) | |
e142c38c | 6102 | cu->list_in_scope = &file_symbols; |
c906108c SS |
6103 | } |
6104 | ||
6105 | /* Process all the DIES contained within a lexical block scope. Start | |
6106 | a new scope, process the dies, and then close the scope. */ | |
6107 | ||
6108 | static void | |
e7c27a73 | 6109 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6110 | { |
e7c27a73 | 6111 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 6112 | struct context_stack *new; |
c906108c SS |
6113 | CORE_ADDR lowpc, highpc; |
6114 | struct die_info *child_die; | |
e142c38c DJ |
6115 | CORE_ADDR baseaddr; |
6116 | ||
6117 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
6118 | |
6119 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
6120 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
6121 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 6122 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 6123 | describe ranges. */ |
d85a05f0 | 6124 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
6125 | return; |
6126 | lowpc += baseaddr; | |
6127 | highpc += baseaddr; | |
6128 | ||
6129 | push_context (0, lowpc); | |
639d11d3 | 6130 | if (die->child != NULL) |
c906108c | 6131 | { |
639d11d3 | 6132 | child_die = die->child; |
c906108c SS |
6133 | while (child_die && child_die->tag) |
6134 | { | |
e7c27a73 | 6135 | process_die (child_die, cu); |
c906108c SS |
6136 | child_die = sibling_die (child_die); |
6137 | } | |
6138 | } | |
6139 | new = pop_context (); | |
6140 | ||
8540c487 | 6141 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 6142 | { |
801e3a5b JB |
6143 | struct block *block |
6144 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
6145 | highpc, objfile); | |
6146 | ||
6147 | /* Note that recording ranges after traversing children, as we | |
6148 | do here, means that recording a parent's ranges entails | |
6149 | walking across all its children's ranges as they appear in | |
6150 | the address map, which is quadratic behavior. | |
6151 | ||
6152 | It would be nicer to record the parent's ranges before | |
6153 | traversing its children, simply overriding whatever you find | |
6154 | there. But since we don't even decide whether to create a | |
6155 | block until after we've traversed its children, that's hard | |
6156 | to do. */ | |
6157 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
6158 | } |
6159 | local_symbols = new->locals; | |
27aa8d6a | 6160 | using_directives = new->using_directives; |
c906108c SS |
6161 | } |
6162 | ||
96408a79 SA |
6163 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
6164 | ||
6165 | static void | |
6166 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6167 | { | |
6168 | struct objfile *objfile = cu->objfile; | |
6169 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
6170 | CORE_ADDR pc, baseaddr; | |
6171 | struct attribute *attr; | |
6172 | struct call_site *call_site, call_site_local; | |
6173 | void **slot; | |
6174 | int nparams; | |
6175 | struct die_info *child_die; | |
6176 | ||
6177 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6178 | ||
6179 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
6180 | if (!attr) | |
6181 | { | |
6182 | complaint (&symfile_complaints, | |
6183 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " | |
6184 | "DIE 0x%x [in module %s]"), | |
bb5ed363 | 6185 | die->offset, objfile->name); |
96408a79 SA |
6186 | return; |
6187 | } | |
6188 | pc = DW_ADDR (attr) + baseaddr; | |
6189 | ||
6190 | if (cu->call_site_htab == NULL) | |
6191 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, | |
6192 | NULL, &objfile->objfile_obstack, | |
6193 | hashtab_obstack_allocate, NULL); | |
6194 | call_site_local.pc = pc; | |
6195 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); | |
6196 | if (*slot != NULL) | |
6197 | { | |
6198 | complaint (&symfile_complaints, | |
6199 | _("Duplicate PC %s for DW_TAG_GNU_call_site " | |
6200 | "DIE 0x%x [in module %s]"), | |
bb5ed363 | 6201 | paddress (gdbarch, pc), die->offset, objfile->name); |
96408a79 SA |
6202 | return; |
6203 | } | |
6204 | ||
6205 | /* Count parameters at the caller. */ | |
6206 | ||
6207 | nparams = 0; | |
6208 | for (child_die = die->child; child_die && child_die->tag; | |
6209 | child_die = sibling_die (child_die)) | |
6210 | { | |
6211 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6212 | { | |
6213 | complaint (&symfile_complaints, | |
6214 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " | |
6215 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6216 | child_die->tag, child_die->offset, objfile->name); |
96408a79 SA |
6217 | continue; |
6218 | } | |
6219 | ||
6220 | nparams++; | |
6221 | } | |
6222 | ||
6223 | call_site = obstack_alloc (&objfile->objfile_obstack, | |
6224 | (sizeof (*call_site) | |
6225 | + (sizeof (*call_site->parameter) | |
6226 | * (nparams - 1)))); | |
6227 | *slot = call_site; | |
6228 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); | |
6229 | call_site->pc = pc; | |
6230 | ||
6231 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) | |
6232 | { | |
6233 | struct die_info *func_die; | |
6234 | ||
6235 | /* Skip also over DW_TAG_inlined_subroutine. */ | |
6236 | for (func_die = die->parent; | |
6237 | func_die && func_die->tag != DW_TAG_subprogram | |
6238 | && func_die->tag != DW_TAG_subroutine_type; | |
6239 | func_die = func_die->parent); | |
6240 | ||
6241 | /* DW_AT_GNU_all_call_sites is a superset | |
6242 | of DW_AT_GNU_all_tail_call_sites. */ | |
6243 | if (func_die | |
6244 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) | |
6245 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) | |
6246 | { | |
6247 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is | |
6248 | not complete. But keep CALL_SITE for look ups via call_site_htab, | |
6249 | both the initial caller containing the real return address PC and | |
6250 | the final callee containing the current PC of a chain of tail | |
6251 | calls do not need to have the tail call list complete. But any | |
6252 | function candidate for a virtual tail call frame searched via | |
6253 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be | |
6254 | determined unambiguously. */ | |
6255 | } | |
6256 | else | |
6257 | { | |
6258 | struct type *func_type = NULL; | |
6259 | ||
6260 | if (func_die) | |
6261 | func_type = get_die_type (func_die, cu); | |
6262 | if (func_type != NULL) | |
6263 | { | |
6264 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); | |
6265 | ||
6266 | /* Enlist this call site to the function. */ | |
6267 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); | |
6268 | TYPE_TAIL_CALL_LIST (func_type) = call_site; | |
6269 | } | |
6270 | else | |
6271 | complaint (&symfile_complaints, | |
6272 | _("Cannot find function owning DW_TAG_GNU_call_site " | |
6273 | "DIE 0x%x [in module %s]"), | |
bb5ed363 | 6274 | die->offset, objfile->name); |
96408a79 SA |
6275 | } |
6276 | } | |
6277 | ||
6278 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); | |
6279 | if (attr == NULL) | |
6280 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
6281 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); | |
6282 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) | |
6283 | /* Keep NULL DWARF_BLOCK. */; | |
6284 | else if (attr_form_is_block (attr)) | |
6285 | { | |
6286 | struct dwarf2_locexpr_baton *dlbaton; | |
6287 | ||
6288 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); | |
6289 | dlbaton->data = DW_BLOCK (attr)->data; | |
6290 | dlbaton->size = DW_BLOCK (attr)->size; | |
6291 | dlbaton->per_cu = cu->per_cu; | |
6292 | ||
6293 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); | |
6294 | } | |
6295 | else if (is_ref_attr (attr)) | |
6296 | { | |
96408a79 SA |
6297 | struct dwarf2_cu *target_cu = cu; |
6298 | struct die_info *target_die; | |
6299 | ||
6300 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); | |
6301 | gdb_assert (target_cu->objfile == objfile); | |
6302 | if (die_is_declaration (target_die, target_cu)) | |
6303 | { | |
6304 | const char *target_physname; | |
6305 | ||
6306 | target_physname = dwarf2_physname (NULL, target_die, target_cu); | |
6307 | if (target_physname == NULL) | |
6308 | complaint (&symfile_complaints, | |
6309 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6310 | "physname, for referencing DIE 0x%x [in module %s]"), | |
bb5ed363 | 6311 | die->offset, objfile->name); |
96408a79 SA |
6312 | else |
6313 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); | |
6314 | } | |
6315 | else | |
6316 | { | |
6317 | CORE_ADDR lowpc; | |
6318 | ||
6319 | /* DW_AT_entry_pc should be preferred. */ | |
6320 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) | |
6321 | complaint (&symfile_complaints, | |
6322 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6323 | "low pc, for referencing DIE 0x%x [in module %s]"), | |
bb5ed363 | 6324 | die->offset, objfile->name); |
96408a79 SA |
6325 | else |
6326 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); | |
6327 | } | |
6328 | } | |
6329 | else | |
6330 | complaint (&symfile_complaints, | |
6331 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " | |
6332 | "block nor reference, for DIE 0x%x [in module %s]"), | |
bb5ed363 | 6333 | die->offset, objfile->name); |
96408a79 SA |
6334 | |
6335 | call_site->per_cu = cu->per_cu; | |
6336 | ||
6337 | for (child_die = die->child; | |
6338 | child_die && child_die->tag; | |
6339 | child_die = sibling_die (child_die)) | |
6340 | { | |
6341 | struct dwarf2_locexpr_baton *dlbaton; | |
6342 | struct call_site_parameter *parameter; | |
6343 | ||
6344 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6345 | { | |
6346 | /* Already printed the complaint above. */ | |
6347 | continue; | |
6348 | } | |
6349 | ||
6350 | gdb_assert (call_site->parameter_count < nparams); | |
6351 | parameter = &call_site->parameter[call_site->parameter_count]; | |
6352 | ||
6353 | /* DW_AT_location specifies the register number. Value of the data | |
6354 | assumed for the register is contained in DW_AT_GNU_call_site_value. */ | |
6355 | ||
6356 | attr = dwarf2_attr (child_die, DW_AT_location, cu); | |
6357 | if (!attr || !attr_form_is_block (attr)) | |
6358 | { | |
6359 | complaint (&symfile_complaints, | |
6360 | _("No DW_FORM_block* DW_AT_location for " | |
6361 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6362 | child_die->offset, objfile->name); |
96408a79 SA |
6363 | continue; |
6364 | } | |
6365 | parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data, | |
6366 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]); | |
6367 | if (parameter->dwarf_reg == -1 | |
6368 | && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data, | |
6369 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size], | |
6370 | ¶meter->fb_offset)) | |
6371 | { | |
6372 | complaint (&symfile_complaints, | |
6373 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " | |
6374 | "for DW_FORM_block* DW_AT_location for " | |
6375 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6376 | child_die->offset, objfile->name); |
96408a79 SA |
6377 | continue; |
6378 | } | |
6379 | ||
6380 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); | |
6381 | if (!attr_form_is_block (attr)) | |
6382 | { | |
6383 | complaint (&symfile_complaints, | |
6384 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " | |
6385 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6386 | child_die->offset, objfile->name); |
96408a79 SA |
6387 | continue; |
6388 | } | |
6389 | parameter->value = DW_BLOCK (attr)->data; | |
6390 | parameter->value_size = DW_BLOCK (attr)->size; | |
6391 | ||
6392 | /* Parameters are not pre-cleared by memset above. */ | |
6393 | parameter->data_value = NULL; | |
6394 | parameter->data_value_size = 0; | |
6395 | call_site->parameter_count++; | |
6396 | ||
6397 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); | |
6398 | if (attr) | |
6399 | { | |
6400 | if (!attr_form_is_block (attr)) | |
6401 | complaint (&symfile_complaints, | |
6402 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " | |
6403 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6404 | child_die->offset, objfile->name); |
96408a79 SA |
6405 | else |
6406 | { | |
6407 | parameter->data_value = DW_BLOCK (attr)->data; | |
6408 | parameter->data_value_size = DW_BLOCK (attr)->size; | |
6409 | } | |
6410 | } | |
6411 | } | |
6412 | } | |
6413 | ||
43039443 | 6414 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
6415 | Return 1 if the attributes are present and valid, otherwise, return 0. |
6416 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
6417 | |
6418 | static int | |
6419 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
6420 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
6421 | struct partial_symtab *ranges_pst) | |
43039443 JK |
6422 | { |
6423 | struct objfile *objfile = cu->objfile; | |
6424 | struct comp_unit_head *cu_header = &cu->header; | |
6425 | bfd *obfd = objfile->obfd; | |
6426 | unsigned int addr_size = cu_header->addr_size; | |
6427 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6428 | /* Base address selection entry. */ | |
6429 | CORE_ADDR base; | |
6430 | int found_base; | |
6431 | unsigned int dummy; | |
6432 | gdb_byte *buffer; | |
6433 | CORE_ADDR marker; | |
6434 | int low_set; | |
6435 | CORE_ADDR low = 0; | |
6436 | CORE_ADDR high = 0; | |
ff013f42 | 6437 | CORE_ADDR baseaddr; |
43039443 | 6438 | |
d00adf39 DE |
6439 | found_base = cu->base_known; |
6440 | base = cu->base_address; | |
43039443 | 6441 | |
be391dca | 6442 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 6443 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
6444 | { |
6445 | complaint (&symfile_complaints, | |
6446 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
6447 | offset); | |
6448 | return 0; | |
6449 | } | |
dce234bc | 6450 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
6451 | |
6452 | /* Read in the largest possible address. */ | |
6453 | marker = read_address (obfd, buffer, cu, &dummy); | |
6454 | if ((marker & mask) == mask) | |
6455 | { | |
6456 | /* If we found the largest possible address, then | |
6457 | read the base address. */ | |
6458 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6459 | buffer += 2 * addr_size; | |
6460 | offset += 2 * addr_size; | |
6461 | found_base = 1; | |
6462 | } | |
6463 | ||
6464 | low_set = 0; | |
6465 | ||
e7030f15 | 6466 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 6467 | |
43039443 JK |
6468 | while (1) |
6469 | { | |
6470 | CORE_ADDR range_beginning, range_end; | |
6471 | ||
6472 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
6473 | buffer += addr_size; | |
6474 | range_end = read_address (obfd, buffer, cu, &dummy); | |
6475 | buffer += addr_size; | |
6476 | offset += 2 * addr_size; | |
6477 | ||
6478 | /* An end of list marker is a pair of zero addresses. */ | |
6479 | if (range_beginning == 0 && range_end == 0) | |
6480 | /* Found the end of list entry. */ | |
6481 | break; | |
6482 | ||
6483 | /* Each base address selection entry is a pair of 2 values. | |
6484 | The first is the largest possible address, the second is | |
6485 | the base address. Check for a base address here. */ | |
6486 | if ((range_beginning & mask) == mask) | |
6487 | { | |
6488 | /* If we found the largest possible address, then | |
6489 | read the base address. */ | |
6490 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6491 | found_base = 1; | |
6492 | continue; | |
6493 | } | |
6494 | ||
6495 | if (!found_base) | |
6496 | { | |
6497 | /* We have no valid base address for the ranges | |
6498 | data. */ | |
6499 | complaint (&symfile_complaints, | |
6500 | _("Invalid .debug_ranges data (no base address)")); | |
6501 | return 0; | |
6502 | } | |
6503 | ||
9277c30c UW |
6504 | if (range_beginning > range_end) |
6505 | { | |
6506 | /* Inverted range entries are invalid. */ | |
6507 | complaint (&symfile_complaints, | |
6508 | _("Invalid .debug_ranges data (inverted range)")); | |
6509 | return 0; | |
6510 | } | |
6511 | ||
6512 | /* Empty range entries have no effect. */ | |
6513 | if (range_beginning == range_end) | |
6514 | continue; | |
6515 | ||
43039443 JK |
6516 | range_beginning += base; |
6517 | range_end += base; | |
6518 | ||
9277c30c | 6519 | if (ranges_pst != NULL) |
ff013f42 | 6520 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
6521 | range_beginning + baseaddr, |
6522 | range_end - 1 + baseaddr, | |
ff013f42 JK |
6523 | ranges_pst); |
6524 | ||
43039443 JK |
6525 | /* FIXME: This is recording everything as a low-high |
6526 | segment of consecutive addresses. We should have a | |
6527 | data structure for discontiguous block ranges | |
6528 | instead. */ | |
6529 | if (! low_set) | |
6530 | { | |
6531 | low = range_beginning; | |
6532 | high = range_end; | |
6533 | low_set = 1; | |
6534 | } | |
6535 | else | |
6536 | { | |
6537 | if (range_beginning < low) | |
6538 | low = range_beginning; | |
6539 | if (range_end > high) | |
6540 | high = range_end; | |
6541 | } | |
6542 | } | |
6543 | ||
6544 | if (! low_set) | |
6545 | /* If the first entry is an end-of-list marker, the range | |
6546 | describes an empty scope, i.e. no instructions. */ | |
6547 | return 0; | |
6548 | ||
6549 | if (low_return) | |
6550 | *low_return = low; | |
6551 | if (high_return) | |
6552 | *high_return = high; | |
6553 | return 1; | |
6554 | } | |
6555 | ||
af34e669 DJ |
6556 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
6557 | are present and valid, otherwise, return 0. Return -1 if the range is | |
6558 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 6559 | static int |
af34e669 | 6560 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
6561 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
6562 | struct partial_symtab *pst) | |
c906108c SS |
6563 | { |
6564 | struct attribute *attr; | |
af34e669 DJ |
6565 | CORE_ADDR low = 0; |
6566 | CORE_ADDR high = 0; | |
6567 | int ret = 0; | |
c906108c | 6568 | |
e142c38c | 6569 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 6570 | if (attr) |
af34e669 DJ |
6571 | { |
6572 | high = DW_ADDR (attr); | |
e142c38c | 6573 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
6574 | if (attr) |
6575 | low = DW_ADDR (attr); | |
6576 | else | |
6577 | /* Found high w/o low attribute. */ | |
6578 | return 0; | |
6579 | ||
6580 | /* Found consecutive range of addresses. */ | |
6581 | ret = 1; | |
6582 | } | |
c906108c | 6583 | else |
af34e669 | 6584 | { |
e142c38c | 6585 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
6586 | if (attr != NULL) |
6587 | { | |
af34e669 | 6588 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 6589 | .debug_ranges section. */ |
d85a05f0 | 6590 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 6591 | return 0; |
43039443 | 6592 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
6593 | ret = -1; |
6594 | } | |
6595 | } | |
c906108c | 6596 | |
9373cf26 JK |
6597 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
6598 | if (high <= low) | |
c906108c SS |
6599 | return 0; |
6600 | ||
6601 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
6602 | eliminate duplicate copies of functions and vtables and such. | |
6603 | The linker will arbitrarily choose one and discard the others. | |
6604 | The AT_*_pc values for such functions refer to local labels in | |
6605 | these sections. If the section from that file was discarded, the | |
6606 | labels are not in the output, so the relocs get a value of 0. | |
6607 | If this is a discarded function, mark the pc bounds as invalid, | |
6608 | so that GDB will ignore it. */ | |
72dca2f5 | 6609 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
6610 | return 0; |
6611 | ||
6612 | *lowpc = low; | |
96408a79 SA |
6613 | if (highpc) |
6614 | *highpc = high; | |
af34e669 | 6615 | return ret; |
c906108c SS |
6616 | } |
6617 | ||
b084d499 JB |
6618 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
6619 | its low and high PC addresses. Do nothing if these addresses could not | |
6620 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
6621 | and HIGHPC to the high address if greater than HIGHPC. */ | |
6622 | ||
6623 | static void | |
6624 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
6625 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6626 | struct dwarf2_cu *cu) | |
6627 | { | |
6628 | CORE_ADDR low, high; | |
6629 | struct die_info *child = die->child; | |
6630 | ||
d85a05f0 | 6631 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
6632 | { |
6633 | *lowpc = min (*lowpc, low); | |
6634 | *highpc = max (*highpc, high); | |
6635 | } | |
6636 | ||
6637 | /* If the language does not allow nested subprograms (either inside | |
6638 | subprograms or lexical blocks), we're done. */ | |
6639 | if (cu->language != language_ada) | |
6640 | return; | |
6e70227d | 6641 | |
b084d499 JB |
6642 | /* Check all the children of the given DIE. If it contains nested |
6643 | subprograms, then check their pc bounds. Likewise, we need to | |
6644 | check lexical blocks as well, as they may also contain subprogram | |
6645 | definitions. */ | |
6646 | while (child && child->tag) | |
6647 | { | |
6648 | if (child->tag == DW_TAG_subprogram | |
6649 | || child->tag == DW_TAG_lexical_block) | |
6650 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
6651 | child = sibling_die (child); | |
6652 | } | |
6653 | } | |
6654 | ||
fae299cd DC |
6655 | /* Get the low and high pc's represented by the scope DIE, and store |
6656 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
6657 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
6658 | ||
6659 | static void | |
6660 | get_scope_pc_bounds (struct die_info *die, | |
6661 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6662 | struct dwarf2_cu *cu) | |
6663 | { | |
6664 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
6665 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
6666 | CORE_ADDR current_low, current_high; | |
6667 | ||
d85a05f0 | 6668 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
6669 | { |
6670 | best_low = current_low; | |
6671 | best_high = current_high; | |
6672 | } | |
6673 | else | |
6674 | { | |
6675 | struct die_info *child = die->child; | |
6676 | ||
6677 | while (child && child->tag) | |
6678 | { | |
6679 | switch (child->tag) { | |
6680 | case DW_TAG_subprogram: | |
b084d499 | 6681 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
6682 | break; |
6683 | case DW_TAG_namespace: | |
f55ee35c | 6684 | case DW_TAG_module: |
fae299cd DC |
6685 | /* FIXME: carlton/2004-01-16: Should we do this for |
6686 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
6687 | that current GCC's always emit the DIEs corresponding | |
6688 | to definitions of methods of classes as children of a | |
6689 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
6690 | the DIEs giving the declarations, which could be | |
6691 | anywhere). But I don't see any reason why the | |
6692 | standards says that they have to be there. */ | |
6693 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
6694 | ||
6695 | if (current_low != ((CORE_ADDR) -1)) | |
6696 | { | |
6697 | best_low = min (best_low, current_low); | |
6698 | best_high = max (best_high, current_high); | |
6699 | } | |
6700 | break; | |
6701 | default: | |
0963b4bd | 6702 | /* Ignore. */ |
fae299cd DC |
6703 | break; |
6704 | } | |
6705 | ||
6706 | child = sibling_die (child); | |
6707 | } | |
6708 | } | |
6709 | ||
6710 | *lowpc = best_low; | |
6711 | *highpc = best_high; | |
6712 | } | |
6713 | ||
801e3a5b JB |
6714 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
6715 | in DIE. */ | |
6716 | static void | |
6717 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
6718 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
6719 | { | |
bb5ed363 | 6720 | struct objfile *objfile = cu->objfile; |
801e3a5b JB |
6721 | struct attribute *attr; |
6722 | ||
6723 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
6724 | if (attr) | |
6725 | { | |
6726 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 6727 | |
801e3a5b JB |
6728 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
6729 | if (attr) | |
6730 | { | |
6731 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 6732 | |
801e3a5b JB |
6733 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
6734 | } | |
6735 | } | |
6736 | ||
6737 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
6738 | if (attr) | |
6739 | { | |
bb5ed363 | 6740 | bfd *obfd = objfile->obfd; |
801e3a5b JB |
6741 | |
6742 | /* The value of the DW_AT_ranges attribute is the offset of the | |
6743 | address range list in the .debug_ranges section. */ | |
6744 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 6745 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
6746 | |
6747 | /* For some target architectures, but not others, the | |
6748 | read_address function sign-extends the addresses it returns. | |
6749 | To recognize base address selection entries, we need a | |
6750 | mask. */ | |
6751 | unsigned int addr_size = cu->header.addr_size; | |
6752 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6753 | ||
6754 | /* The base address, to which the next pair is relative. Note | |
6755 | that this 'base' is a DWARF concept: most entries in a range | |
6756 | list are relative, to reduce the number of relocs against the | |
6757 | debugging information. This is separate from this function's | |
6758 | 'baseaddr' argument, which GDB uses to relocate debugging | |
6759 | information from a shared library based on the address at | |
6760 | which the library was loaded. */ | |
d00adf39 DE |
6761 | CORE_ADDR base = cu->base_address; |
6762 | int base_known = cu->base_known; | |
801e3a5b | 6763 | |
be391dca | 6764 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 6765 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
6766 | { |
6767 | complaint (&symfile_complaints, | |
6768 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
6769 | offset); | |
6770 | return; | |
6771 | } | |
6772 | ||
6773 | for (;;) | |
6774 | { | |
6775 | unsigned int bytes_read; | |
6776 | CORE_ADDR start, end; | |
6777 | ||
6778 | start = read_address (obfd, buffer, cu, &bytes_read); | |
6779 | buffer += bytes_read; | |
6780 | end = read_address (obfd, buffer, cu, &bytes_read); | |
6781 | buffer += bytes_read; | |
6782 | ||
6783 | /* Did we find the end of the range list? */ | |
6784 | if (start == 0 && end == 0) | |
6785 | break; | |
6786 | ||
6787 | /* Did we find a base address selection entry? */ | |
6788 | else if ((start & base_select_mask) == base_select_mask) | |
6789 | { | |
6790 | base = end; | |
6791 | base_known = 1; | |
6792 | } | |
6793 | ||
6794 | /* We found an ordinary address range. */ | |
6795 | else | |
6796 | { | |
6797 | if (!base_known) | |
6798 | { | |
6799 | complaint (&symfile_complaints, | |
3e43a32a MS |
6800 | _("Invalid .debug_ranges data " |
6801 | "(no base address)")); | |
801e3a5b JB |
6802 | return; |
6803 | } | |
6804 | ||
9277c30c UW |
6805 | if (start > end) |
6806 | { | |
6807 | /* Inverted range entries are invalid. */ | |
6808 | complaint (&symfile_complaints, | |
6809 | _("Invalid .debug_ranges data " | |
6810 | "(inverted range)")); | |
6811 | return; | |
6812 | } | |
6813 | ||
6814 | /* Empty range entries have no effect. */ | |
6815 | if (start == end) | |
6816 | continue; | |
6817 | ||
6e70227d DE |
6818 | record_block_range (block, |
6819 | baseaddr + base + start, | |
801e3a5b JB |
6820 | baseaddr + base + end - 1); |
6821 | } | |
6822 | } | |
6823 | } | |
6824 | } | |
6825 | ||
60d5a603 JK |
6826 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
6827 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
6828 | during 4.6.0 experimental. */ | |
6829 | ||
6830 | static int | |
6831 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
6832 | { | |
6833 | const char *cs; | |
6834 | int major, minor, release; | |
6835 | ||
6836 | if (cu->producer == NULL) | |
6837 | { | |
6838 | /* For unknown compilers expect their behavior is DWARF version | |
6839 | compliant. | |
6840 | ||
6841 | GCC started to support .debug_types sections by -gdwarf-4 since | |
6842 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
6843 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
6844 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
6845 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
6846 | ||
6847 | return 0; | |
6848 | } | |
6849 | ||
6850 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ | |
6851 | ||
6852 | if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) | |
6853 | { | |
6854 | /* For non-GCC compilers expect their behavior is DWARF version | |
6855 | compliant. */ | |
6856 | ||
6857 | return 0; | |
6858 | } | |
6859 | cs = &cu->producer[strlen ("GNU ")]; | |
6860 | while (*cs && !isdigit (*cs)) | |
6861 | cs++; | |
6862 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) | |
6863 | { | |
6864 | /* Not recognized as GCC. */ | |
6865 | ||
6866 | return 0; | |
6867 | } | |
6868 | ||
6869 | return major < 4 || (major == 4 && minor < 6); | |
6870 | } | |
6871 | ||
6872 | /* Return the default accessibility type if it is not overriden by | |
6873 | DW_AT_accessibility. */ | |
6874 | ||
6875 | static enum dwarf_access_attribute | |
6876 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
6877 | { | |
6878 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
6879 | { | |
6880 | /* The default DWARF 2 accessibility for members is public, the default | |
6881 | accessibility for inheritance is private. */ | |
6882 | ||
6883 | if (die->tag != DW_TAG_inheritance) | |
6884 | return DW_ACCESS_public; | |
6885 | else | |
6886 | return DW_ACCESS_private; | |
6887 | } | |
6888 | else | |
6889 | { | |
6890 | /* DWARF 3+ defines the default accessibility a different way. The same | |
6891 | rules apply now for DW_TAG_inheritance as for the members and it only | |
6892 | depends on the container kind. */ | |
6893 | ||
6894 | if (die->parent->tag == DW_TAG_class_type) | |
6895 | return DW_ACCESS_private; | |
6896 | else | |
6897 | return DW_ACCESS_public; | |
6898 | } | |
6899 | } | |
6900 | ||
74ac6d43 TT |
6901 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
6902 | offset. If the attribute was not found return 0, otherwise return | |
6903 | 1. If it was found but could not properly be handled, set *OFFSET | |
6904 | to 0. */ | |
6905 | ||
6906 | static int | |
6907 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
6908 | LONGEST *offset) | |
6909 | { | |
6910 | struct attribute *attr; | |
6911 | ||
6912 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
6913 | if (attr != NULL) | |
6914 | { | |
6915 | *offset = 0; | |
6916 | ||
6917 | /* Note that we do not check for a section offset first here. | |
6918 | This is because DW_AT_data_member_location is new in DWARF 4, | |
6919 | so if we see it, we can assume that a constant form is really | |
6920 | a constant and not a section offset. */ | |
6921 | if (attr_form_is_constant (attr)) | |
6922 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
6923 | else if (attr_form_is_section_offset (attr)) | |
6924 | dwarf2_complex_location_expr_complaint (); | |
6925 | else if (attr_form_is_block (attr)) | |
6926 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6927 | else | |
6928 | dwarf2_complex_location_expr_complaint (); | |
6929 | ||
6930 | return 1; | |
6931 | } | |
6932 | ||
6933 | return 0; | |
6934 | } | |
6935 | ||
c906108c SS |
6936 | /* Add an aggregate field to the field list. */ |
6937 | ||
6938 | static void | |
107d2387 | 6939 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6940 | struct dwarf2_cu *cu) |
6e70227d | 6941 | { |
e7c27a73 | 6942 | struct objfile *objfile = cu->objfile; |
5e2b427d | 6943 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
6944 | struct nextfield *new_field; |
6945 | struct attribute *attr; | |
6946 | struct field *fp; | |
6947 | char *fieldname = ""; | |
6948 | ||
6949 | /* Allocate a new field list entry and link it in. */ | |
6950 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 6951 | make_cleanup (xfree, new_field); |
c906108c | 6952 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
6953 | |
6954 | if (die->tag == DW_TAG_inheritance) | |
6955 | { | |
6956 | new_field->next = fip->baseclasses; | |
6957 | fip->baseclasses = new_field; | |
6958 | } | |
6959 | else | |
6960 | { | |
6961 | new_field->next = fip->fields; | |
6962 | fip->fields = new_field; | |
6963 | } | |
c906108c SS |
6964 | fip->nfields++; |
6965 | ||
e142c38c | 6966 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6967 | if (attr) |
6968 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
6969 | else |
6970 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
6971 | if (new_field->accessibility != DW_ACCESS_public) |
6972 | fip->non_public_fields = 1; | |
60d5a603 | 6973 | |
e142c38c | 6974 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
6975 | if (attr) |
6976 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
6977 | else |
6978 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
6979 | |
6980 | fp = &new_field->field; | |
a9a9bd0f | 6981 | |
e142c38c | 6982 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 6983 | { |
74ac6d43 TT |
6984 | LONGEST offset; |
6985 | ||
a9a9bd0f | 6986 | /* Data member other than a C++ static data member. */ |
6e70227d | 6987 | |
c906108c | 6988 | /* Get type of field. */ |
e7c27a73 | 6989 | fp->type = die_type (die, cu); |
c906108c | 6990 | |
d6a843b5 | 6991 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 6992 | |
c906108c | 6993 | /* Get bit size of field (zero if none). */ |
e142c38c | 6994 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
6995 | if (attr) |
6996 | { | |
6997 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
6998 | } | |
6999 | else | |
7000 | { | |
7001 | FIELD_BITSIZE (*fp) = 0; | |
7002 | } | |
7003 | ||
7004 | /* Get bit offset of field. */ | |
74ac6d43 TT |
7005 | if (handle_data_member_location (die, cu, &offset)) |
7006 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 7007 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
7008 | if (attr) |
7009 | { | |
5e2b427d | 7010 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
7011 | { |
7012 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
7013 | additional bit offset from the MSB of the containing |
7014 | anonymous object to the MSB of the field. We don't | |
7015 | have to do anything special since we don't need to | |
7016 | know the size of the anonymous object. */ | |
c906108c SS |
7017 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
7018 | } | |
7019 | else | |
7020 | { | |
7021 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
7022 | MSB of the anonymous object, subtract off the number of |
7023 | bits from the MSB of the field to the MSB of the | |
7024 | object, and then subtract off the number of bits of | |
7025 | the field itself. The result is the bit offset of | |
7026 | the LSB of the field. */ | |
c906108c SS |
7027 | int anonymous_size; |
7028 | int bit_offset = DW_UNSND (attr); | |
7029 | ||
e142c38c | 7030 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7031 | if (attr) |
7032 | { | |
7033 | /* The size of the anonymous object containing | |
7034 | the bit field is explicit, so use the | |
7035 | indicated size (in bytes). */ | |
7036 | anonymous_size = DW_UNSND (attr); | |
7037 | } | |
7038 | else | |
7039 | { | |
7040 | /* The size of the anonymous object containing | |
7041 | the bit field must be inferred from the type | |
7042 | attribute of the data member containing the | |
7043 | bit field. */ | |
7044 | anonymous_size = TYPE_LENGTH (fp->type); | |
7045 | } | |
7046 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
7047 | - bit_offset - FIELD_BITSIZE (*fp); | |
7048 | } | |
7049 | } | |
7050 | ||
7051 | /* Get name of field. */ | |
39cbfefa DJ |
7052 | fieldname = dwarf2_name (die, cu); |
7053 | if (fieldname == NULL) | |
7054 | fieldname = ""; | |
d8151005 DJ |
7055 | |
7056 | /* The name is already allocated along with this objfile, so we don't | |
7057 | need to duplicate it for the type. */ | |
7058 | fp->name = fieldname; | |
c906108c SS |
7059 | |
7060 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 7061 | pointer or virtual base class pointer) to private. */ |
e142c38c | 7062 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 7063 | { |
d48cc9dd | 7064 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
7065 | new_field->accessibility = DW_ACCESS_private; |
7066 | fip->non_public_fields = 1; | |
7067 | } | |
7068 | } | |
a9a9bd0f | 7069 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 7070 | { |
a9a9bd0f DC |
7071 | /* C++ static member. */ |
7072 | ||
7073 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
7074 | is a declaration, but all versions of G++ as of this writing | |
7075 | (so through at least 3.2.1) incorrectly generate | |
7076 | DW_TAG_variable tags. */ | |
6e70227d | 7077 | |
ff355380 | 7078 | const char *physname; |
c906108c | 7079 | |
a9a9bd0f | 7080 | /* Get name of field. */ |
39cbfefa DJ |
7081 | fieldname = dwarf2_name (die, cu); |
7082 | if (fieldname == NULL) | |
c906108c SS |
7083 | return; |
7084 | ||
254e6b9e | 7085 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
7086 | if (attr |
7087 | /* Only create a symbol if this is an external value. | |
7088 | new_symbol checks this and puts the value in the global symbol | |
7089 | table, which we want. If it is not external, new_symbol | |
7090 | will try to put the value in cu->list_in_scope which is wrong. */ | |
7091 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
7092 | { |
7093 | /* A static const member, not much different than an enum as far as | |
7094 | we're concerned, except that we can support more types. */ | |
7095 | new_symbol (die, NULL, cu); | |
7096 | } | |
7097 | ||
2df3850c | 7098 | /* Get physical name. */ |
ff355380 | 7099 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 7100 | |
d8151005 DJ |
7101 | /* The name is already allocated along with this objfile, so we don't |
7102 | need to duplicate it for the type. */ | |
7103 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 7104 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 7105 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
7106 | } |
7107 | else if (die->tag == DW_TAG_inheritance) | |
7108 | { | |
74ac6d43 | 7109 | LONGEST offset; |
d4b96c9a | 7110 | |
74ac6d43 TT |
7111 | /* C++ base class field. */ |
7112 | if (handle_data_member_location (die, cu, &offset)) | |
7113 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 7114 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 7115 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
7116 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
7117 | fip->nbaseclasses++; | |
7118 | } | |
7119 | } | |
7120 | ||
98751a41 JK |
7121 | /* Add a typedef defined in the scope of the FIP's class. */ |
7122 | ||
7123 | static void | |
7124 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
7125 | struct dwarf2_cu *cu) | |
6e70227d | 7126 | { |
98751a41 | 7127 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
7128 | struct typedef_field_list *new_field; |
7129 | struct attribute *attr; | |
7130 | struct typedef_field *fp; | |
7131 | char *fieldname = ""; | |
7132 | ||
7133 | /* Allocate a new field list entry and link it in. */ | |
7134 | new_field = xzalloc (sizeof (*new_field)); | |
7135 | make_cleanup (xfree, new_field); | |
7136 | ||
7137 | gdb_assert (die->tag == DW_TAG_typedef); | |
7138 | ||
7139 | fp = &new_field->field; | |
7140 | ||
7141 | /* Get name of field. */ | |
7142 | fp->name = dwarf2_name (die, cu); | |
7143 | if (fp->name == NULL) | |
7144 | return; | |
7145 | ||
7146 | fp->type = read_type_die (die, cu); | |
7147 | ||
7148 | new_field->next = fip->typedef_field_list; | |
7149 | fip->typedef_field_list = new_field; | |
7150 | fip->typedef_field_list_count++; | |
7151 | } | |
7152 | ||
c906108c SS |
7153 | /* Create the vector of fields, and attach it to the type. */ |
7154 | ||
7155 | static void | |
fba45db2 | 7156 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7157 | struct dwarf2_cu *cu) |
c906108c SS |
7158 | { |
7159 | int nfields = fip->nfields; | |
7160 | ||
7161 | /* Record the field count, allocate space for the array of fields, | |
7162 | and create blank accessibility bitfields if necessary. */ | |
7163 | TYPE_NFIELDS (type) = nfields; | |
7164 | TYPE_FIELDS (type) = (struct field *) | |
7165 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
7166 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
7167 | ||
b4ba55a1 | 7168 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
7169 | { |
7170 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7171 | ||
7172 | TYPE_FIELD_PRIVATE_BITS (type) = | |
7173 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7174 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
7175 | ||
7176 | TYPE_FIELD_PROTECTED_BITS (type) = | |
7177 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7178 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
7179 | ||
774b6a14 TT |
7180 | TYPE_FIELD_IGNORE_BITS (type) = |
7181 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7182 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
7183 | } |
7184 | ||
7185 | /* If the type has baseclasses, allocate and clear a bit vector for | |
7186 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 7187 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
7188 | { |
7189 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 7190 | unsigned char *pointer; |
c906108c SS |
7191 | |
7192 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
7193 | pointer = TYPE_ALLOC (type, num_bytes); |
7194 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
7195 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
7196 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
7197 | } | |
7198 | ||
3e43a32a MS |
7199 | /* Copy the saved-up fields into the field vector. Start from the head of |
7200 | the list, adding to the tail of the field array, so that they end up in | |
7201 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
7202 | while (nfields-- > 0) |
7203 | { | |
7d0ccb61 DJ |
7204 | struct nextfield *fieldp; |
7205 | ||
7206 | if (fip->fields) | |
7207 | { | |
7208 | fieldp = fip->fields; | |
7209 | fip->fields = fieldp->next; | |
7210 | } | |
7211 | else | |
7212 | { | |
7213 | fieldp = fip->baseclasses; | |
7214 | fip->baseclasses = fieldp->next; | |
7215 | } | |
7216 | ||
7217 | TYPE_FIELD (type, nfields) = fieldp->field; | |
7218 | switch (fieldp->accessibility) | |
c906108c | 7219 | { |
c5aa993b | 7220 | case DW_ACCESS_private: |
b4ba55a1 JB |
7221 | if (cu->language != language_ada) |
7222 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 7223 | break; |
c906108c | 7224 | |
c5aa993b | 7225 | case DW_ACCESS_protected: |
b4ba55a1 JB |
7226 | if (cu->language != language_ada) |
7227 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 7228 | break; |
c906108c | 7229 | |
c5aa993b JM |
7230 | case DW_ACCESS_public: |
7231 | break; | |
c906108c | 7232 | |
c5aa993b JM |
7233 | default: |
7234 | /* Unknown accessibility. Complain and treat it as public. */ | |
7235 | { | |
e2e0b3e5 | 7236 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 7237 | fieldp->accessibility); |
c5aa993b JM |
7238 | } |
7239 | break; | |
c906108c SS |
7240 | } |
7241 | if (nfields < fip->nbaseclasses) | |
7242 | { | |
7d0ccb61 | 7243 | switch (fieldp->virtuality) |
c906108c | 7244 | { |
c5aa993b JM |
7245 | case DW_VIRTUALITY_virtual: |
7246 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 7247 | if (cu->language == language_ada) |
a73c6dcd | 7248 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
7249 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
7250 | break; | |
c906108c SS |
7251 | } |
7252 | } | |
c906108c SS |
7253 | } |
7254 | } | |
7255 | ||
c906108c SS |
7256 | /* Add a member function to the proper fieldlist. */ |
7257 | ||
7258 | static void | |
107d2387 | 7259 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 7260 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 7261 | { |
e7c27a73 | 7262 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7263 | struct attribute *attr; |
7264 | struct fnfieldlist *flp; | |
7265 | int i; | |
7266 | struct fn_field *fnp; | |
7267 | char *fieldname; | |
c906108c | 7268 | struct nextfnfield *new_fnfield; |
f792889a | 7269 | struct type *this_type; |
60d5a603 | 7270 | enum dwarf_access_attribute accessibility; |
c906108c | 7271 | |
b4ba55a1 | 7272 | if (cu->language == language_ada) |
a73c6dcd | 7273 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 7274 | |
2df3850c | 7275 | /* Get name of member function. */ |
39cbfefa DJ |
7276 | fieldname = dwarf2_name (die, cu); |
7277 | if (fieldname == NULL) | |
2df3850c | 7278 | return; |
c906108c | 7279 | |
c906108c SS |
7280 | /* Look up member function name in fieldlist. */ |
7281 | for (i = 0; i < fip->nfnfields; i++) | |
7282 | { | |
27bfe10e | 7283 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
7284 | break; |
7285 | } | |
7286 | ||
7287 | /* Create new list element if necessary. */ | |
7288 | if (i < fip->nfnfields) | |
7289 | flp = &fip->fnfieldlists[i]; | |
7290 | else | |
7291 | { | |
7292 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7293 | { | |
7294 | fip->fnfieldlists = (struct fnfieldlist *) | |
7295 | xrealloc (fip->fnfieldlists, | |
7296 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7297 | * sizeof (struct fnfieldlist)); |
c906108c | 7298 | if (fip->nfnfields == 0) |
c13c43fd | 7299 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
7300 | } |
7301 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
7302 | flp->name = fieldname; | |
7303 | flp->length = 0; | |
7304 | flp->head = NULL; | |
3da10d80 | 7305 | i = fip->nfnfields++; |
c906108c SS |
7306 | } |
7307 | ||
7308 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 7309 | entry. */ |
c906108c | 7310 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 7311 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
7312 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
7313 | new_fnfield->next = flp->head; | |
7314 | flp->head = new_fnfield; | |
7315 | flp->length++; | |
7316 | ||
7317 | /* Fill in the member function field info. */ | |
7318 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
7319 | |
7320 | /* Delay processing of the physname until later. */ | |
7321 | if (cu->language == language_cplus || cu->language == language_java) | |
7322 | { | |
7323 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
7324 | die, cu); | |
7325 | } | |
7326 | else | |
7327 | { | |
1d06ead6 | 7328 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
7329 | fnp->physname = physname ? physname : ""; |
7330 | } | |
7331 | ||
c906108c | 7332 | fnp->type = alloc_type (objfile); |
f792889a DJ |
7333 | this_type = read_type_die (die, cu); |
7334 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 7335 | { |
f792889a | 7336 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 7337 | |
f792889a | 7338 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
7339 | of the method itself (TYPE_CODE_METHOD). */ |
7340 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
7341 | TYPE_TARGET_TYPE (this_type), |
7342 | TYPE_FIELDS (this_type), | |
7343 | TYPE_NFIELDS (this_type), | |
7344 | TYPE_VARARGS (this_type)); | |
c906108c SS |
7345 | |
7346 | /* Handle static member functions. | |
c5aa993b | 7347 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
7348 | member functions. G++ helps GDB by marking the first |
7349 | parameter for non-static member functions (which is the this | |
7350 | pointer) as artificial. We obtain this information from | |
7351 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 7352 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
7353 | fnp->voffset = VOFFSET_STATIC; |
7354 | } | |
7355 | else | |
e2e0b3e5 | 7356 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 7357 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
7358 | |
7359 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 7360 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 7361 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 7362 | |
3e43a32a MS |
7363 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
7364 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
7365 | |
7366 | /* Get accessibility. */ | |
e142c38c | 7367 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 7368 | if (attr) |
60d5a603 JK |
7369 | accessibility = DW_UNSND (attr); |
7370 | else | |
7371 | accessibility = dwarf2_default_access_attribute (die, cu); | |
7372 | switch (accessibility) | |
c906108c | 7373 | { |
60d5a603 JK |
7374 | case DW_ACCESS_private: |
7375 | fnp->is_private = 1; | |
7376 | break; | |
7377 | case DW_ACCESS_protected: | |
7378 | fnp->is_protected = 1; | |
7379 | break; | |
c906108c SS |
7380 | } |
7381 | ||
b02dede2 | 7382 | /* Check for artificial methods. */ |
e142c38c | 7383 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
7384 | if (attr && DW_UNSND (attr) != 0) |
7385 | fnp->is_artificial = 1; | |
7386 | ||
0d564a31 | 7387 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
7388 | function. For older versions of GCC, this is an offset in the |
7389 | appropriate virtual table, as specified by DW_AT_containing_type. | |
7390 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
7391 | to the object address. */ |
7392 | ||
e142c38c | 7393 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 7394 | if (attr) |
8e19ed76 | 7395 | { |
aec5aa8b | 7396 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 7397 | { |
aec5aa8b TT |
7398 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
7399 | { | |
7400 | /* Old-style GCC. */ | |
7401 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
7402 | } | |
7403 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7404 | || (DW_BLOCK (attr)->size > 1 | |
7405 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
7406 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
7407 | { | |
7408 | struct dwarf_block blk; | |
7409 | int offset; | |
7410 | ||
7411 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7412 | ? 1 : 2); | |
7413 | blk.size = DW_BLOCK (attr)->size - offset; | |
7414 | blk.data = DW_BLOCK (attr)->data + offset; | |
7415 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
7416 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
7417 | dwarf2_complex_location_expr_complaint (); | |
7418 | else | |
7419 | fnp->voffset /= cu->header.addr_size; | |
7420 | fnp->voffset += 2; | |
7421 | } | |
7422 | else | |
7423 | dwarf2_complex_location_expr_complaint (); | |
7424 | ||
7425 | if (!fnp->fcontext) | |
7426 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
7427 | } | |
3690dd37 | 7428 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 7429 | { |
4d3c2250 | 7430 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
7431 | } |
7432 | else | |
7433 | { | |
4d3c2250 KB |
7434 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
7435 | fieldname); | |
8e19ed76 | 7436 | } |
0d564a31 | 7437 | } |
d48cc9dd DJ |
7438 | else |
7439 | { | |
7440 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
7441 | if (attr && DW_UNSND (attr)) | |
7442 | { | |
7443 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
7444 | complaint (&symfile_complaints, | |
3e43a32a MS |
7445 | _("Member function \"%s\" (offset %d) is virtual " |
7446 | "but the vtable offset is not specified"), | |
d48cc9dd | 7447 | fieldname, die->offset); |
9655fd1a | 7448 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
7449 | TYPE_CPLUS_DYNAMIC (type) = 1; |
7450 | } | |
7451 | } | |
c906108c SS |
7452 | } |
7453 | ||
7454 | /* Create the vector of member function fields, and attach it to the type. */ | |
7455 | ||
7456 | static void | |
fba45db2 | 7457 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7458 | struct dwarf2_cu *cu) |
c906108c SS |
7459 | { |
7460 | struct fnfieldlist *flp; | |
c906108c SS |
7461 | int i; |
7462 | ||
b4ba55a1 | 7463 | if (cu->language == language_ada) |
a73c6dcd | 7464 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 7465 | |
c906108c SS |
7466 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
7467 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
7468 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
7469 | ||
7470 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
7471 | { | |
7472 | struct nextfnfield *nfp = flp->head; | |
7473 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
7474 | int k; | |
7475 | ||
7476 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
7477 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
7478 | fn_flp->fn_fields = (struct fn_field *) | |
7479 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
7480 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 7481 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
7482 | } |
7483 | ||
7484 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
c906108c SS |
7485 | } |
7486 | ||
1168df01 JB |
7487 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
7488 | language, zero otherwise. */ | |
7489 | static int | |
7490 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
7491 | { | |
7492 | static const char vptr[] = "_vptr"; | |
987504bb | 7493 | static const char vtable[] = "vtable"; |
1168df01 | 7494 | |
987504bb JJ |
7495 | /* Look for the C++ and Java forms of the vtable. */ |
7496 | if ((cu->language == language_java | |
7497 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
7498 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
7499 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
7500 | return 1; |
7501 | ||
7502 | return 0; | |
7503 | } | |
7504 | ||
c0dd20ea | 7505 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
7506 | functions, with the ABI-specified layout. If TYPE describes |
7507 | such a structure, smash it into a member function type. | |
61049d3b DJ |
7508 | |
7509 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
7510 | This is GCC PR debug/28767. */ | |
c0dd20ea | 7511 | |
0b92b5bb TT |
7512 | static void |
7513 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 7514 | { |
0b92b5bb | 7515 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
7516 | |
7517 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
7518 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
7519 | return; | |
c0dd20ea DJ |
7520 | |
7521 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
7522 | if (TYPE_FIELD_NAME (type, 0) == NULL |
7523 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
7524 | || TYPE_FIELD_NAME (type, 1) == NULL | |
7525 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
7526 | return; | |
c0dd20ea DJ |
7527 | |
7528 | /* Find the type of the method. */ | |
0b92b5bb | 7529 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
7530 | if (pfn_type == NULL |
7531 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
7532 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 7533 | return; |
c0dd20ea DJ |
7534 | |
7535 | /* Look for the "this" argument. */ | |
7536 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
7537 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 7538 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 7539 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 7540 | return; |
c0dd20ea DJ |
7541 | |
7542 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
7543 | new_type = alloc_type (objfile); |
7544 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
7545 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
7546 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 7547 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 7548 | } |
1168df01 | 7549 | |
c906108c | 7550 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
7551 | (definition) to create a type for the structure or union. Fill in |
7552 | the type's name and general properties; the members will not be | |
7553 | processed until process_structure_type. | |
c906108c | 7554 | |
c767944b DJ |
7555 | NOTE: we need to call these functions regardless of whether or not the |
7556 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
7557 | structure or union. This gets the type entered into our set of |
7558 | user defined types. | |
7559 | ||
7560 | However, if the structure is incomplete (an opaque struct/union) | |
7561 | then suppress creating a symbol table entry for it since gdb only | |
7562 | wants to find the one with the complete definition. Note that if | |
7563 | it is complete, we just call new_symbol, which does it's own | |
7564 | checking about whether the struct/union is anonymous or not (and | |
7565 | suppresses creating a symbol table entry itself). */ | |
7566 | ||
f792889a | 7567 | static struct type * |
134d01f1 | 7568 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7569 | { |
e7c27a73 | 7570 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7571 | struct type *type; |
7572 | struct attribute *attr; | |
39cbfefa | 7573 | char *name; |
c906108c | 7574 | |
348e048f DE |
7575 | /* If the definition of this type lives in .debug_types, read that type. |
7576 | Don't follow DW_AT_specification though, that will take us back up | |
7577 | the chain and we want to go down. */ | |
7578 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7579 | if (attr) | |
7580 | { | |
7581 | struct dwarf2_cu *type_cu = cu; | |
7582 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7583 | |
348e048f DE |
7584 | /* We could just recurse on read_structure_type, but we need to call |
7585 | get_die_type to ensure only one type for this DIE is created. | |
7586 | This is important, for example, because for c++ classes we need | |
7587 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
7588 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
7589 | |
7590 | /* TYPE_CU may not be the same as CU. | |
7591 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7592 | return set_die_type (die, type, cu); |
7593 | } | |
7594 | ||
c0dd20ea | 7595 | type = alloc_type (objfile); |
c906108c | 7596 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 7597 | |
39cbfefa DJ |
7598 | name = dwarf2_name (die, cu); |
7599 | if (name != NULL) | |
c906108c | 7600 | { |
987504bb JJ |
7601 | if (cu->language == language_cplus |
7602 | || cu->language == language_java) | |
63d06c5c | 7603 | { |
3da10d80 KS |
7604 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
7605 | ||
7606 | /* dwarf2_full_name might have already finished building the DIE's | |
7607 | type. If so, there is no need to continue. */ | |
7608 | if (get_die_type (die, cu) != NULL) | |
7609 | return get_die_type (die, cu); | |
7610 | ||
7611 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
7612 | if (die->tag == DW_TAG_structure_type |
7613 | || die->tag == DW_TAG_class_type) | |
7614 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
7615 | } |
7616 | else | |
7617 | { | |
d8151005 DJ |
7618 | /* The name is already allocated along with this objfile, so |
7619 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
7620 | TYPE_TAG_NAME (type) = (char *) name; |
7621 | if (die->tag == DW_TAG_class_type) | |
7622 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 7623 | } |
c906108c SS |
7624 | } |
7625 | ||
7626 | if (die->tag == DW_TAG_structure_type) | |
7627 | { | |
7628 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
7629 | } | |
7630 | else if (die->tag == DW_TAG_union_type) | |
7631 | { | |
7632 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
7633 | } | |
7634 | else | |
7635 | { | |
c906108c SS |
7636 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
7637 | } | |
7638 | ||
0cc2414c TT |
7639 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
7640 | TYPE_DECLARED_CLASS (type) = 1; | |
7641 | ||
e142c38c | 7642 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7643 | if (attr) |
7644 | { | |
7645 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7646 | } | |
7647 | else | |
7648 | { | |
7649 | TYPE_LENGTH (type) = 0; | |
7650 | } | |
7651 | ||
876cecd0 | 7652 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 7653 | if (die_is_declaration (die, cu)) |
876cecd0 | 7654 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
7655 | else if (attr == NULL && die->child == NULL |
7656 | && producer_is_realview (cu->producer)) | |
7657 | /* RealView does not output the required DW_AT_declaration | |
7658 | on incomplete types. */ | |
7659 | TYPE_STUB (type) = 1; | |
dc718098 | 7660 | |
c906108c SS |
7661 | /* We need to add the type field to the die immediately so we don't |
7662 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 7663 | type within the structure itself. */ |
1c379e20 | 7664 | set_die_type (die, type, cu); |
c906108c | 7665 | |
7e314c57 JK |
7666 | /* set_die_type should be already done. */ |
7667 | set_descriptive_type (type, die, cu); | |
7668 | ||
c767944b DJ |
7669 | return type; |
7670 | } | |
7671 | ||
7672 | /* Finish creating a structure or union type, including filling in | |
7673 | its members and creating a symbol for it. */ | |
7674 | ||
7675 | static void | |
7676 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7677 | { | |
7678 | struct objfile *objfile = cu->objfile; | |
7679 | struct die_info *child_die = die->child; | |
7680 | struct type *type; | |
7681 | ||
7682 | type = get_die_type (die, cu); | |
7683 | if (type == NULL) | |
7684 | type = read_structure_type (die, cu); | |
7685 | ||
e142c38c | 7686 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
7687 | { |
7688 | struct field_info fi; | |
7689 | struct die_info *child_die; | |
34eaf542 | 7690 | VEC (symbolp) *template_args = NULL; |
c767944b | 7691 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
7692 | |
7693 | memset (&fi, 0, sizeof (struct field_info)); | |
7694 | ||
639d11d3 | 7695 | child_die = die->child; |
c906108c SS |
7696 | |
7697 | while (child_die && child_die->tag) | |
7698 | { | |
a9a9bd0f DC |
7699 | if (child_die->tag == DW_TAG_member |
7700 | || child_die->tag == DW_TAG_variable) | |
c906108c | 7701 | { |
a9a9bd0f DC |
7702 | /* NOTE: carlton/2002-11-05: A C++ static data member |
7703 | should be a DW_TAG_member that is a declaration, but | |
7704 | all versions of G++ as of this writing (so through at | |
7705 | least 3.2.1) incorrectly generate DW_TAG_variable | |
7706 | tags for them instead. */ | |
e7c27a73 | 7707 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7708 | } |
8713b1b1 | 7709 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 7710 | { |
0963b4bd | 7711 | /* C++ member function. */ |
e7c27a73 | 7712 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
7713 | } |
7714 | else if (child_die->tag == DW_TAG_inheritance) | |
7715 | { | |
7716 | /* C++ base class field. */ | |
e7c27a73 | 7717 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7718 | } |
98751a41 JK |
7719 | else if (child_die->tag == DW_TAG_typedef) |
7720 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
7721 | else if (child_die->tag == DW_TAG_template_type_param |
7722 | || child_die->tag == DW_TAG_template_value_param) | |
7723 | { | |
7724 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
7725 | ||
f1078f66 DJ |
7726 | if (arg != NULL) |
7727 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
7728 | } |
7729 | ||
c906108c SS |
7730 | child_die = sibling_die (child_die); |
7731 | } | |
7732 | ||
34eaf542 TT |
7733 | /* Attach template arguments to type. */ |
7734 | if (! VEC_empty (symbolp, template_args)) | |
7735 | { | |
7736 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7737 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7738 | = VEC_length (symbolp, template_args); | |
7739 | TYPE_TEMPLATE_ARGUMENTS (type) | |
7740 | = obstack_alloc (&objfile->objfile_obstack, | |
7741 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7742 | * sizeof (struct symbol *))); | |
7743 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
7744 | VEC_address (symbolp, template_args), | |
7745 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7746 | * sizeof (struct symbol *))); | |
7747 | VEC_free (symbolp, template_args); | |
7748 | } | |
7749 | ||
c906108c SS |
7750 | /* Attach fields and member functions to the type. */ |
7751 | if (fi.nfields) | |
e7c27a73 | 7752 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
7753 | if (fi.nfnfields) |
7754 | { | |
e7c27a73 | 7755 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 7756 | |
c5aa993b | 7757 | /* Get the type which refers to the base class (possibly this |
c906108c | 7758 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
7759 | class from the DW_AT_containing_type attribute. This use of |
7760 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 7761 | |
e142c38c | 7762 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 7763 | { |
e7c27a73 | 7764 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
7765 | |
7766 | TYPE_VPTR_BASETYPE (type) = t; | |
7767 | if (type == t) | |
7768 | { | |
c906108c SS |
7769 | int i; |
7770 | ||
7771 | /* Our own class provides vtbl ptr. */ | |
7772 | for (i = TYPE_NFIELDS (t) - 1; | |
7773 | i >= TYPE_N_BASECLASSES (t); | |
7774 | --i) | |
7775 | { | |
0d5cff50 | 7776 | const char *fieldname = TYPE_FIELD_NAME (t, i); |
c906108c | 7777 | |
1168df01 | 7778 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
7779 | { |
7780 | TYPE_VPTR_FIELDNO (type) = i; | |
7781 | break; | |
7782 | } | |
7783 | } | |
7784 | ||
7785 | /* Complain if virtual function table field not found. */ | |
7786 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 7787 | complaint (&symfile_complaints, |
3e43a32a MS |
7788 | _("virtual function table pointer " |
7789 | "not found when defining class '%s'"), | |
4d3c2250 KB |
7790 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
7791 | ""); | |
c906108c SS |
7792 | } |
7793 | else | |
7794 | { | |
7795 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
7796 | } | |
7797 | } | |
f6235d4c EZ |
7798 | else if (cu->producer |
7799 | && strncmp (cu->producer, | |
7800 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
7801 | { | |
7802 | /* The IBM XLC compiler does not provide direct indication | |
7803 | of the containing type, but the vtable pointer is | |
7804 | always named __vfp. */ | |
7805 | ||
7806 | int i; | |
7807 | ||
7808 | for (i = TYPE_NFIELDS (type) - 1; | |
7809 | i >= TYPE_N_BASECLASSES (type); | |
7810 | --i) | |
7811 | { | |
7812 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
7813 | { | |
7814 | TYPE_VPTR_FIELDNO (type) = i; | |
7815 | TYPE_VPTR_BASETYPE (type) = type; | |
7816 | break; | |
7817 | } | |
7818 | } | |
7819 | } | |
c906108c | 7820 | } |
98751a41 JK |
7821 | |
7822 | /* Copy fi.typedef_field_list linked list elements content into the | |
7823 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
7824 | if (fi.typedef_field_list) | |
7825 | { | |
7826 | int i = fi.typedef_field_list_count; | |
7827 | ||
a0d7a4ff | 7828 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
7829 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
7830 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
7831 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
7832 | ||
7833 | /* Reverse the list order to keep the debug info elements order. */ | |
7834 | while (--i >= 0) | |
7835 | { | |
7836 | struct typedef_field *dest, *src; | |
6e70227d | 7837 | |
98751a41 JK |
7838 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
7839 | src = &fi.typedef_field_list->field; | |
7840 | fi.typedef_field_list = fi.typedef_field_list->next; | |
7841 | *dest = *src; | |
7842 | } | |
7843 | } | |
c767944b DJ |
7844 | |
7845 | do_cleanups (back_to); | |
eb2a6f42 TT |
7846 | |
7847 | if (HAVE_CPLUS_STRUCT (type)) | |
7848 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; | |
c906108c | 7849 | } |
63d06c5c | 7850 | |
bb5ed363 | 7851 | quirk_gcc_member_function_pointer (type, objfile); |
0b92b5bb | 7852 | |
90aeadfc DC |
7853 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
7854 | snapshots) has been known to create a die giving a declaration | |
7855 | for a class that has, as a child, a die giving a definition for a | |
7856 | nested class. So we have to process our children even if the | |
7857 | current die is a declaration. Normally, of course, a declaration | |
7858 | won't have any children at all. */ | |
134d01f1 | 7859 | |
90aeadfc DC |
7860 | while (child_die != NULL && child_die->tag) |
7861 | { | |
7862 | if (child_die->tag == DW_TAG_member | |
7863 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
7864 | || child_die->tag == DW_TAG_inheritance |
7865 | || child_die->tag == DW_TAG_template_value_param | |
7866 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 7867 | { |
90aeadfc | 7868 | /* Do nothing. */ |
134d01f1 | 7869 | } |
90aeadfc DC |
7870 | else |
7871 | process_die (child_die, cu); | |
134d01f1 | 7872 | |
90aeadfc | 7873 | child_die = sibling_die (child_die); |
134d01f1 DJ |
7874 | } |
7875 | ||
fa4028e9 JB |
7876 | /* Do not consider external references. According to the DWARF standard, |
7877 | these DIEs are identified by the fact that they have no byte_size | |
7878 | attribute, and a declaration attribute. */ | |
7879 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
7880 | || !die_is_declaration (die, cu)) | |
c767944b | 7881 | new_symbol (die, type, cu); |
134d01f1 DJ |
7882 | } |
7883 | ||
7884 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
7885 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 7886 | |
f792889a | 7887 | static struct type * |
134d01f1 | 7888 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7889 | { |
e7c27a73 | 7890 | struct objfile *objfile = cu->objfile; |
c906108c | 7891 | struct type *type; |
c906108c | 7892 | struct attribute *attr; |
0114d602 | 7893 | const char *name; |
134d01f1 | 7894 | |
348e048f DE |
7895 | /* If the definition of this type lives in .debug_types, read that type. |
7896 | Don't follow DW_AT_specification though, that will take us back up | |
7897 | the chain and we want to go down. */ | |
7898 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7899 | if (attr) | |
7900 | { | |
7901 | struct dwarf2_cu *type_cu = cu; | |
7902 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7903 | |
348e048f | 7904 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
7905 | |
7906 | /* TYPE_CU may not be the same as CU. | |
7907 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7908 | return set_die_type (die, type, cu); |
7909 | } | |
7910 | ||
c906108c SS |
7911 | type = alloc_type (objfile); |
7912 | ||
7913 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 7914 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 7915 | if (name != NULL) |
0114d602 | 7916 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 7917 | |
e142c38c | 7918 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7919 | if (attr) |
7920 | { | |
7921 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7922 | } | |
7923 | else | |
7924 | { | |
7925 | TYPE_LENGTH (type) = 0; | |
7926 | } | |
7927 | ||
137033e9 JB |
7928 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
7929 | declared as private in the package spec, and then defined only | |
7930 | inside the package body. Such types are known as Taft Amendment | |
7931 | Types. When another package uses such a type, an incomplete DIE | |
7932 | may be generated by the compiler. */ | |
02eb380e | 7933 | if (die_is_declaration (die, cu)) |
876cecd0 | 7934 | TYPE_STUB (type) = 1; |
02eb380e | 7935 | |
f792889a | 7936 | return set_die_type (die, type, cu); |
134d01f1 DJ |
7937 | } |
7938 | ||
7939 | /* Given a pointer to a die which begins an enumeration, process all | |
7940 | the dies that define the members of the enumeration, and create the | |
7941 | symbol for the enumeration type. | |
7942 | ||
7943 | NOTE: We reverse the order of the element list. */ | |
7944 | ||
7945 | static void | |
7946 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7947 | { | |
f792889a | 7948 | struct type *this_type; |
134d01f1 | 7949 | |
f792889a DJ |
7950 | this_type = get_die_type (die, cu); |
7951 | if (this_type == NULL) | |
7952 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 7953 | |
639d11d3 | 7954 | if (die->child != NULL) |
c906108c | 7955 | { |
9dc481d3 DE |
7956 | struct die_info *child_die; |
7957 | struct symbol *sym; | |
7958 | struct field *fields = NULL; | |
7959 | int num_fields = 0; | |
7960 | int unsigned_enum = 1; | |
7961 | char *name; | |
cafec441 TT |
7962 | int flag_enum = 1; |
7963 | ULONGEST mask = 0; | |
9dc481d3 | 7964 | |
639d11d3 | 7965 | child_die = die->child; |
c906108c SS |
7966 | while (child_die && child_die->tag) |
7967 | { | |
7968 | if (child_die->tag != DW_TAG_enumerator) | |
7969 | { | |
e7c27a73 | 7970 | process_die (child_die, cu); |
c906108c SS |
7971 | } |
7972 | else | |
7973 | { | |
39cbfefa DJ |
7974 | name = dwarf2_name (child_die, cu); |
7975 | if (name) | |
c906108c | 7976 | { |
f792889a | 7977 | sym = new_symbol (child_die, this_type, cu); |
c906108c | 7978 | if (SYMBOL_VALUE (sym) < 0) |
cafec441 TT |
7979 | { |
7980 | unsigned_enum = 0; | |
7981 | flag_enum = 0; | |
7982 | } | |
7983 | else if ((mask & SYMBOL_VALUE (sym)) != 0) | |
7984 | flag_enum = 0; | |
7985 | else | |
7986 | mask |= SYMBOL_VALUE (sym); | |
c906108c SS |
7987 | |
7988 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7989 | { | |
7990 | fields = (struct field *) | |
7991 | xrealloc (fields, | |
7992 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7993 | * sizeof (struct field)); |
c906108c SS |
7994 | } |
7995 | ||
3567439c | 7996 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 7997 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 7998 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
7999 | FIELD_BITSIZE (fields[num_fields]) = 0; |
8000 | ||
8001 | num_fields++; | |
8002 | } | |
8003 | } | |
8004 | ||
8005 | child_die = sibling_die (child_die); | |
8006 | } | |
8007 | ||
8008 | if (num_fields) | |
8009 | { | |
f792889a DJ |
8010 | TYPE_NFIELDS (this_type) = num_fields; |
8011 | TYPE_FIELDS (this_type) = (struct field *) | |
8012 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
8013 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 8014 | sizeof (struct field) * num_fields); |
b8c9b27d | 8015 | xfree (fields); |
c906108c SS |
8016 | } |
8017 | if (unsigned_enum) | |
876cecd0 | 8018 | TYPE_UNSIGNED (this_type) = 1; |
cafec441 TT |
8019 | if (flag_enum) |
8020 | TYPE_FLAG_ENUM (this_type) = 1; | |
c906108c | 8021 | } |
134d01f1 | 8022 | |
6c83ed52 TT |
8023 | /* If we are reading an enum from a .debug_types unit, and the enum |
8024 | is a declaration, and the enum is not the signatured type in the | |
8025 | unit, then we do not want to add a symbol for it. Adding a | |
8026 | symbol would in some cases obscure the true definition of the | |
8027 | enum, giving users an incomplete type when the definition is | |
8028 | actually available. Note that we do not want to do this for all | |
8029 | enums which are just declarations, because C++0x allows forward | |
8030 | enum declarations. */ | |
b0df02fd | 8031 | if (cu->per_cu->debug_types_section |
6c83ed52 TT |
8032 | && die_is_declaration (die, cu)) |
8033 | { | |
8034 | struct signatured_type *type_sig; | |
8035 | ||
8036 | type_sig | |
8037 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, | |
b0df02fd | 8038 | cu->per_cu->debug_types_section, |
6c83ed52 TT |
8039 | cu->per_cu->offset); |
8040 | if (type_sig->type_offset != die->offset) | |
8041 | return; | |
8042 | } | |
8043 | ||
f792889a | 8044 | new_symbol (die, this_type, cu); |
c906108c SS |
8045 | } |
8046 | ||
8047 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
8048 | the DIE's type field. For now, this only handles one dimensional | |
8049 | arrays. */ | |
8050 | ||
f792889a | 8051 | static struct type * |
e7c27a73 | 8052 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8053 | { |
e7c27a73 | 8054 | struct objfile *objfile = cu->objfile; |
c906108c | 8055 | struct die_info *child_die; |
7e314c57 | 8056 | struct type *type; |
c906108c SS |
8057 | struct type *element_type, *range_type, *index_type; |
8058 | struct type **range_types = NULL; | |
8059 | struct attribute *attr; | |
8060 | int ndim = 0; | |
8061 | struct cleanup *back_to; | |
39cbfefa | 8062 | char *name; |
c906108c | 8063 | |
e7c27a73 | 8064 | element_type = die_type (die, cu); |
c906108c | 8065 | |
7e314c57 JK |
8066 | /* The die_type call above may have already set the type for this DIE. */ |
8067 | type = get_die_type (die, cu); | |
8068 | if (type) | |
8069 | return type; | |
8070 | ||
c906108c SS |
8071 | /* Irix 6.2 native cc creates array types without children for |
8072 | arrays with unspecified length. */ | |
639d11d3 | 8073 | if (die->child == NULL) |
c906108c | 8074 | { |
46bf5051 | 8075 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8076 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
8077 | type = create_array_type (NULL, element_type, range_type); |
8078 | return set_die_type (die, type, cu); | |
c906108c SS |
8079 | } |
8080 | ||
8081 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 8082 | child_die = die->child; |
c906108c SS |
8083 | while (child_die && child_die->tag) |
8084 | { | |
8085 | if (child_die->tag == DW_TAG_subrange_type) | |
8086 | { | |
f792889a | 8087 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 8088 | |
f792889a | 8089 | if (child_type != NULL) |
a02abb62 | 8090 | { |
0963b4bd MS |
8091 | /* The range type was succesfully read. Save it for the |
8092 | array type creation. */ | |
a02abb62 JB |
8093 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
8094 | { | |
8095 | range_types = (struct type **) | |
8096 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
8097 | * sizeof (struct type *)); | |
8098 | if (ndim == 0) | |
8099 | make_cleanup (free_current_contents, &range_types); | |
8100 | } | |
f792889a | 8101 | range_types[ndim++] = child_type; |
a02abb62 | 8102 | } |
c906108c SS |
8103 | } |
8104 | child_die = sibling_die (child_die); | |
8105 | } | |
8106 | ||
8107 | /* Dwarf2 dimensions are output from left to right, create the | |
8108 | necessary array types in backwards order. */ | |
7ca2d3a3 | 8109 | |
c906108c | 8110 | type = element_type; |
7ca2d3a3 DL |
8111 | |
8112 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
8113 | { | |
8114 | int i = 0; | |
9a619af0 | 8115 | |
7ca2d3a3 DL |
8116 | while (i < ndim) |
8117 | type = create_array_type (NULL, type, range_types[i++]); | |
8118 | } | |
8119 | else | |
8120 | { | |
8121 | while (ndim-- > 0) | |
8122 | type = create_array_type (NULL, type, range_types[ndim]); | |
8123 | } | |
c906108c | 8124 | |
f5f8a009 EZ |
8125 | /* Understand Dwarf2 support for vector types (like they occur on |
8126 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
8127 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
8128 | custom vendor extension. The main difference between a regular | |
8129 | array and the vector variant is that vectors are passed by value | |
8130 | to functions. */ | |
e142c38c | 8131 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 8132 | if (attr) |
ea37ba09 | 8133 | make_vector_type (type); |
f5f8a009 | 8134 | |
dbc98a8b KW |
8135 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
8136 | implementation may choose to implement triple vectors using this | |
8137 | attribute. */ | |
8138 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
8139 | if (attr) | |
8140 | { | |
8141 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
8142 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8143 | else | |
3e43a32a MS |
8144 | complaint (&symfile_complaints, |
8145 | _("DW_AT_byte_size for array type smaller " | |
8146 | "than the total size of elements")); | |
dbc98a8b KW |
8147 | } |
8148 | ||
39cbfefa DJ |
8149 | name = dwarf2_name (die, cu); |
8150 | if (name) | |
8151 | TYPE_NAME (type) = name; | |
6e70227d | 8152 | |
0963b4bd | 8153 | /* Install the type in the die. */ |
7e314c57 JK |
8154 | set_die_type (die, type, cu); |
8155 | ||
8156 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8157 | set_descriptive_type (type, die, cu); |
8158 | ||
c906108c SS |
8159 | do_cleanups (back_to); |
8160 | ||
7e314c57 | 8161 | return type; |
c906108c SS |
8162 | } |
8163 | ||
7ca2d3a3 | 8164 | static enum dwarf_array_dim_ordering |
6e70227d | 8165 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
8166 | { |
8167 | struct attribute *attr; | |
8168 | ||
8169 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
8170 | ||
8171 | if (attr) return DW_SND (attr); | |
8172 | ||
0963b4bd MS |
8173 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
8174 | opposite order to the dwarf2 specification, but data is still | |
8175 | laid out as per normal fortran. | |
7ca2d3a3 | 8176 | |
0963b4bd MS |
8177 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
8178 | version checking. */ | |
7ca2d3a3 | 8179 | |
905e0470 PM |
8180 | if (cu->language == language_fortran |
8181 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
8182 | { |
8183 | return DW_ORD_row_major; | |
8184 | } | |
8185 | ||
6e70227d | 8186 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
8187 | { |
8188 | case array_column_major: | |
8189 | return DW_ORD_col_major; | |
8190 | case array_row_major: | |
8191 | default: | |
8192 | return DW_ORD_row_major; | |
8193 | }; | |
8194 | } | |
8195 | ||
72019c9c | 8196 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 8197 | the DIE's type field. */ |
72019c9c | 8198 | |
f792889a | 8199 | static struct type * |
72019c9c GM |
8200 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
8201 | { | |
7e314c57 JK |
8202 | struct type *domain_type, *set_type; |
8203 | struct attribute *attr; | |
f792889a | 8204 | |
7e314c57 JK |
8205 | domain_type = die_type (die, cu); |
8206 | ||
8207 | /* The die_type call above may have already set the type for this DIE. */ | |
8208 | set_type = get_die_type (die, cu); | |
8209 | if (set_type) | |
8210 | return set_type; | |
8211 | ||
8212 | set_type = create_set_type (NULL, domain_type); | |
8213 | ||
8214 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
8215 | if (attr) |
8216 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 8217 | |
f792889a | 8218 | return set_die_type (die, set_type, cu); |
72019c9c | 8219 | } |
7ca2d3a3 | 8220 | |
c906108c SS |
8221 | /* First cut: install each common block member as a global variable. */ |
8222 | ||
8223 | static void | |
e7c27a73 | 8224 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8225 | { |
8226 | struct die_info *child_die; | |
8227 | struct attribute *attr; | |
8228 | struct symbol *sym; | |
8229 | CORE_ADDR base = (CORE_ADDR) 0; | |
8230 | ||
e142c38c | 8231 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8232 | if (attr) |
8233 | { | |
0963b4bd | 8234 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
8235 | if (attr_form_is_block (attr)) |
8236 | { | |
e7c27a73 | 8237 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 8238 | } |
3690dd37 | 8239 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 8240 | { |
4d3c2250 | 8241 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8242 | } |
8243 | else | |
8244 | { | |
4d3c2250 KB |
8245 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
8246 | "common block member"); | |
8e19ed76 | 8247 | } |
c906108c | 8248 | } |
639d11d3 | 8249 | if (die->child != NULL) |
c906108c | 8250 | { |
639d11d3 | 8251 | child_die = die->child; |
c906108c SS |
8252 | while (child_die && child_die->tag) |
8253 | { | |
74ac6d43 TT |
8254 | LONGEST offset; |
8255 | ||
e7c27a73 | 8256 | sym = new_symbol (child_die, NULL, cu); |
e8d28ef4 TT |
8257 | if (sym != NULL |
8258 | && handle_data_member_location (child_die, cu, &offset)) | |
c906108c | 8259 | { |
74ac6d43 | 8260 | SYMBOL_VALUE_ADDRESS (sym) = base + offset; |
c906108c SS |
8261 | add_symbol_to_list (sym, &global_symbols); |
8262 | } | |
8263 | child_die = sibling_die (child_die); | |
8264 | } | |
8265 | } | |
8266 | } | |
8267 | ||
0114d602 | 8268 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 8269 | |
0114d602 DJ |
8270 | static struct type * |
8271 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 8272 | { |
e7c27a73 | 8273 | struct objfile *objfile = cu->objfile; |
0114d602 | 8274 | const char *previous_prefix, *name; |
9219021c | 8275 | int is_anonymous; |
0114d602 DJ |
8276 | struct type *type; |
8277 | ||
8278 | /* For extensions, reuse the type of the original namespace. */ | |
8279 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
8280 | { | |
8281 | struct die_info *ext_die; | |
8282 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 8283 | |
0114d602 DJ |
8284 | ext_die = dwarf2_extension (die, &ext_cu); |
8285 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
8286 | |
8287 | /* EXT_CU may not be the same as CU. | |
8288 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
8289 | return set_die_type (die, type, cu); |
8290 | } | |
9219021c | 8291 | |
e142c38c | 8292 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
8293 | |
8294 | /* Now build the name of the current namespace. */ | |
8295 | ||
0114d602 DJ |
8296 | previous_prefix = determine_prefix (die, cu); |
8297 | if (previous_prefix[0] != '\0') | |
8298 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 8299 | previous_prefix, name, 0, cu); |
0114d602 DJ |
8300 | |
8301 | /* Create the type. */ | |
8302 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
8303 | objfile); | |
8304 | TYPE_NAME (type) = (char *) name; | |
8305 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8306 | ||
60531b24 | 8307 | return set_die_type (die, type, cu); |
0114d602 DJ |
8308 | } |
8309 | ||
8310 | /* Read a C++ namespace. */ | |
8311 | ||
8312 | static void | |
8313 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
8314 | { | |
8315 | struct objfile *objfile = cu->objfile; | |
0114d602 | 8316 | int is_anonymous; |
9219021c | 8317 | |
5c4e30ca DC |
8318 | /* Add a symbol associated to this if we haven't seen the namespace |
8319 | before. Also, add a using directive if it's an anonymous | |
8320 | namespace. */ | |
9219021c | 8321 | |
f2f0e013 | 8322 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
8323 | { |
8324 | struct type *type; | |
8325 | ||
0114d602 | 8326 | type = read_type_die (die, cu); |
e7c27a73 | 8327 | new_symbol (die, type, cu); |
5c4e30ca | 8328 | |
e8e80198 | 8329 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 8330 | if (is_anonymous) |
0114d602 DJ |
8331 | { |
8332 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 8333 | |
c0cc3a76 | 8334 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
32019081 | 8335 | NULL, NULL, &objfile->objfile_obstack); |
0114d602 | 8336 | } |
5c4e30ca | 8337 | } |
9219021c | 8338 | |
639d11d3 | 8339 | if (die->child != NULL) |
d9fa45fe | 8340 | { |
639d11d3 | 8341 | struct die_info *child_die = die->child; |
6e70227d | 8342 | |
d9fa45fe DC |
8343 | while (child_die && child_die->tag) |
8344 | { | |
e7c27a73 | 8345 | process_die (child_die, cu); |
d9fa45fe DC |
8346 | child_die = sibling_die (child_die); |
8347 | } | |
8348 | } | |
38d518c9 EZ |
8349 | } |
8350 | ||
f55ee35c JK |
8351 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
8352 | imported module. Still we need that type as local Fortran "use ... only" | |
8353 | declaration imports depend on the created type in determine_prefix. */ | |
8354 | ||
8355 | static struct type * | |
8356 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
8357 | { | |
8358 | struct objfile *objfile = cu->objfile; | |
8359 | char *module_name; | |
8360 | struct type *type; | |
8361 | ||
8362 | module_name = dwarf2_name (die, cu); | |
8363 | if (!module_name) | |
3e43a32a MS |
8364 | complaint (&symfile_complaints, |
8365 | _("DW_TAG_module has no name, offset 0x%x"), | |
f55ee35c JK |
8366 | die->offset); |
8367 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
8368 | ||
8369 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
8370 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8371 | ||
8372 | return set_die_type (die, type, cu); | |
8373 | } | |
8374 | ||
5d7cb8df JK |
8375 | /* Read a Fortran module. */ |
8376 | ||
8377 | static void | |
8378 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
8379 | { | |
8380 | struct die_info *child_die = die->child; | |
8381 | ||
5d7cb8df JK |
8382 | while (child_die && child_die->tag) |
8383 | { | |
8384 | process_die (child_die, cu); | |
8385 | child_die = sibling_die (child_die); | |
8386 | } | |
8387 | } | |
8388 | ||
38d518c9 EZ |
8389 | /* Return the name of the namespace represented by DIE. Set |
8390 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
8391 | namespace. */ | |
8392 | ||
8393 | static const char * | |
e142c38c | 8394 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
8395 | { |
8396 | struct die_info *current_die; | |
8397 | const char *name = NULL; | |
8398 | ||
8399 | /* Loop through the extensions until we find a name. */ | |
8400 | ||
8401 | for (current_die = die; | |
8402 | current_die != NULL; | |
f2f0e013 | 8403 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 8404 | { |
e142c38c | 8405 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
8406 | if (name != NULL) |
8407 | break; | |
8408 | } | |
8409 | ||
8410 | /* Is it an anonymous namespace? */ | |
8411 | ||
8412 | *is_anonymous = (name == NULL); | |
8413 | if (*is_anonymous) | |
2b1dbab0 | 8414 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
8415 | |
8416 | return name; | |
d9fa45fe DC |
8417 | } |
8418 | ||
c906108c SS |
8419 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
8420 | the user defined type vector. */ | |
8421 | ||
f792889a | 8422 | static struct type * |
e7c27a73 | 8423 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8424 | { |
5e2b427d | 8425 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 8426 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 8427 | struct type *type; |
8b2dbe47 KB |
8428 | struct attribute *attr_byte_size; |
8429 | struct attribute *attr_address_class; | |
8430 | int byte_size, addr_class; | |
7e314c57 JK |
8431 | struct type *target_type; |
8432 | ||
8433 | target_type = die_type (die, cu); | |
c906108c | 8434 | |
7e314c57 JK |
8435 | /* The die_type call above may have already set the type for this DIE. */ |
8436 | type = get_die_type (die, cu); | |
8437 | if (type) | |
8438 | return type; | |
8439 | ||
8440 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 8441 | |
e142c38c | 8442 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
8443 | if (attr_byte_size) |
8444 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 8445 | else |
8b2dbe47 KB |
8446 | byte_size = cu_header->addr_size; |
8447 | ||
e142c38c | 8448 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
8449 | if (attr_address_class) |
8450 | addr_class = DW_UNSND (attr_address_class); | |
8451 | else | |
8452 | addr_class = DW_ADDR_none; | |
8453 | ||
8454 | /* If the pointer size or address class is different than the | |
8455 | default, create a type variant marked as such and set the | |
8456 | length accordingly. */ | |
8457 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 8458 | { |
5e2b427d | 8459 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
8460 | { |
8461 | int type_flags; | |
8462 | ||
849957d9 | 8463 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 8464 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
8465 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
8466 | == 0); | |
8b2dbe47 KB |
8467 | type = make_type_with_address_space (type, type_flags); |
8468 | } | |
8469 | else if (TYPE_LENGTH (type) != byte_size) | |
8470 | { | |
3e43a32a MS |
8471 | complaint (&symfile_complaints, |
8472 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 8473 | } |
6e70227d | 8474 | else |
9a619af0 MS |
8475 | { |
8476 | /* Should we also complain about unhandled address classes? */ | |
8477 | } | |
c906108c | 8478 | } |
8b2dbe47 KB |
8479 | |
8480 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 8481 | return set_die_type (die, type, cu); |
c906108c SS |
8482 | } |
8483 | ||
8484 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
8485 | the user defined type vector. */ | |
8486 | ||
f792889a | 8487 | static struct type * |
e7c27a73 | 8488 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8489 | { |
8490 | struct type *type; | |
8491 | struct type *to_type; | |
8492 | struct type *domain; | |
8493 | ||
e7c27a73 DJ |
8494 | to_type = die_type (die, cu); |
8495 | domain = die_containing_type (die, cu); | |
0d5de010 | 8496 | |
7e314c57 JK |
8497 | /* The calls above may have already set the type for this DIE. */ |
8498 | type = get_die_type (die, cu); | |
8499 | if (type) | |
8500 | return type; | |
8501 | ||
0d5de010 DJ |
8502 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
8503 | type = lookup_methodptr_type (to_type); | |
8504 | else | |
8505 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 8506 | |
f792889a | 8507 | return set_die_type (die, type, cu); |
c906108c SS |
8508 | } |
8509 | ||
8510 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
8511 | the user defined type vector. */ | |
8512 | ||
f792889a | 8513 | static struct type * |
e7c27a73 | 8514 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8515 | { |
e7c27a73 | 8516 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 8517 | struct type *type, *target_type; |
c906108c SS |
8518 | struct attribute *attr; |
8519 | ||
7e314c57 JK |
8520 | target_type = die_type (die, cu); |
8521 | ||
8522 | /* The die_type call above may have already set the type for this DIE. */ | |
8523 | type = get_die_type (die, cu); | |
8524 | if (type) | |
8525 | return type; | |
8526 | ||
8527 | type = lookup_reference_type (target_type); | |
e142c38c | 8528 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8529 | if (attr) |
8530 | { | |
8531 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8532 | } | |
8533 | else | |
8534 | { | |
107d2387 | 8535 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 8536 | } |
f792889a | 8537 | return set_die_type (die, type, cu); |
c906108c SS |
8538 | } |
8539 | ||
f792889a | 8540 | static struct type * |
e7c27a73 | 8541 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8542 | { |
f792889a | 8543 | struct type *base_type, *cv_type; |
c906108c | 8544 | |
e7c27a73 | 8545 | base_type = die_type (die, cu); |
7e314c57 JK |
8546 | |
8547 | /* The die_type call above may have already set the type for this DIE. */ | |
8548 | cv_type = get_die_type (die, cu); | |
8549 | if (cv_type) | |
8550 | return cv_type; | |
8551 | ||
2f608a3a KW |
8552 | /* In case the const qualifier is applied to an array type, the element type |
8553 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
8554 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
8555 | { | |
8556 | struct type *el_type, *inner_array; | |
8557 | ||
8558 | base_type = copy_type (base_type); | |
8559 | inner_array = base_type; | |
8560 | ||
8561 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
8562 | { | |
8563 | TYPE_TARGET_TYPE (inner_array) = | |
8564 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
8565 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
8566 | } | |
8567 | ||
8568 | el_type = TYPE_TARGET_TYPE (inner_array); | |
8569 | TYPE_TARGET_TYPE (inner_array) = | |
8570 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
8571 | ||
8572 | return set_die_type (die, base_type, cu); | |
8573 | } | |
8574 | ||
f792889a DJ |
8575 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
8576 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8577 | } |
8578 | ||
f792889a | 8579 | static struct type * |
e7c27a73 | 8580 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8581 | { |
f792889a | 8582 | struct type *base_type, *cv_type; |
c906108c | 8583 | |
e7c27a73 | 8584 | base_type = die_type (die, cu); |
7e314c57 JK |
8585 | |
8586 | /* The die_type call above may have already set the type for this DIE. */ | |
8587 | cv_type = get_die_type (die, cu); | |
8588 | if (cv_type) | |
8589 | return cv_type; | |
8590 | ||
f792889a DJ |
8591 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
8592 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8593 | } |
8594 | ||
8595 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
8596 | the user defined type vector. It isn't really a user defined type, | |
8597 | but it behaves like one, with other DIE's using an AT_user_def_type | |
8598 | attribute to reference it. */ | |
8599 | ||
f792889a | 8600 | static struct type * |
e7c27a73 | 8601 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8602 | { |
e7c27a73 | 8603 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 8604 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
8605 | struct type *type, *range_type, *index_type, *char_type; |
8606 | struct attribute *attr; | |
8607 | unsigned int length; | |
8608 | ||
e142c38c | 8609 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
8610 | if (attr) |
8611 | { | |
8612 | length = DW_UNSND (attr); | |
8613 | } | |
8614 | else | |
8615 | { | |
0963b4bd | 8616 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 8617 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
8618 | if (attr) |
8619 | { | |
8620 | length = DW_UNSND (attr); | |
8621 | } | |
8622 | else | |
8623 | { | |
8624 | length = 1; | |
8625 | } | |
c906108c | 8626 | } |
6ccb9162 | 8627 | |
46bf5051 | 8628 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8629 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
8630 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
8631 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 8632 | |
f792889a | 8633 | return set_die_type (die, type, cu); |
c906108c SS |
8634 | } |
8635 | ||
8636 | /* Handle DIES due to C code like: | |
8637 | ||
8638 | struct foo | |
c5aa993b JM |
8639 | { |
8640 | int (*funcp)(int a, long l); | |
8641 | int b; | |
8642 | }; | |
c906108c | 8643 | |
0963b4bd | 8644 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 8645 | |
f792889a | 8646 | static struct type * |
e7c27a73 | 8647 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8648 | { |
bb5ed363 | 8649 | struct objfile *objfile = cu->objfile; |
0963b4bd MS |
8650 | struct type *type; /* Type that this function returns. */ |
8651 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
8652 | struct attribute *attr; |
8653 | ||
e7c27a73 | 8654 | type = die_type (die, cu); |
7e314c57 JK |
8655 | |
8656 | /* The die_type call above may have already set the type for this DIE. */ | |
8657 | ftype = get_die_type (die, cu); | |
8658 | if (ftype) | |
8659 | return ftype; | |
8660 | ||
0c8b41f1 | 8661 | ftype = lookup_function_type (type); |
c906108c | 8662 | |
5b8101ae | 8663 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 8664 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 8665 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 8666 | || cu->language == language_cplus |
5b8101ae PM |
8667 | || cu->language == language_java |
8668 | || cu->language == language_pascal) | |
876cecd0 | 8669 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
8670 | else if (producer_is_realview (cu->producer)) |
8671 | /* RealView does not emit DW_AT_prototyped. We can not | |
8672 | distinguish prototyped and unprototyped functions; default to | |
8673 | prototyped, since that is more common in modern code (and | |
8674 | RealView warns about unprototyped functions). */ | |
8675 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 8676 | |
c055b101 CV |
8677 | /* Store the calling convention in the type if it's available in |
8678 | the subroutine die. Otherwise set the calling convention to | |
8679 | the default value DW_CC_normal. */ | |
8680 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
8681 | if (attr) |
8682 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
8683 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
8684 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
8685 | else | |
8686 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
8687 | |
8688 | /* We need to add the subroutine type to the die immediately so | |
8689 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 8690 | declared as the same subroutine type. */ |
76c10ea2 | 8691 | set_die_type (die, ftype, cu); |
6e70227d | 8692 | |
639d11d3 | 8693 | if (die->child != NULL) |
c906108c | 8694 | { |
bb5ed363 | 8695 | struct type *void_type = objfile_type (objfile)->builtin_void; |
c906108c | 8696 | struct die_info *child_die; |
8072405b | 8697 | int nparams, iparams; |
c906108c SS |
8698 | |
8699 | /* Count the number of parameters. | |
8700 | FIXME: GDB currently ignores vararg functions, but knows about | |
8701 | vararg member functions. */ | |
8072405b | 8702 | nparams = 0; |
639d11d3 | 8703 | child_die = die->child; |
c906108c SS |
8704 | while (child_die && child_die->tag) |
8705 | { | |
8706 | if (child_die->tag == DW_TAG_formal_parameter) | |
8707 | nparams++; | |
8708 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 8709 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
8710 | child_die = sibling_die (child_die); |
8711 | } | |
8712 | ||
8713 | /* Allocate storage for parameters and fill them in. */ | |
8714 | TYPE_NFIELDS (ftype) = nparams; | |
8715 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 8716 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 8717 | |
8072405b JK |
8718 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
8719 | even if we error out during the parameters reading below. */ | |
8720 | for (iparams = 0; iparams < nparams; iparams++) | |
8721 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
8722 | ||
8723 | iparams = 0; | |
639d11d3 | 8724 | child_die = die->child; |
c906108c SS |
8725 | while (child_die && child_die->tag) |
8726 | { | |
8727 | if (child_die->tag == DW_TAG_formal_parameter) | |
8728 | { | |
3ce3b1ba PA |
8729 | struct type *arg_type; |
8730 | ||
8731 | /* DWARF version 2 has no clean way to discern C++ | |
8732 | static and non-static member functions. G++ helps | |
8733 | GDB by marking the first parameter for non-static | |
8734 | member functions (which is the this pointer) as | |
8735 | artificial. We pass this information to | |
8736 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
8737 | ||
8738 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
8739 | 4.5 does not yet generate. */ | |
e142c38c | 8740 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
8741 | if (attr) |
8742 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
8743 | else | |
418835cc KS |
8744 | { |
8745 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
8746 | ||
8747 | /* GCC/43521: In java, the formal parameter | |
8748 | "this" is sometimes not marked with DW_AT_artificial. */ | |
8749 | if (cu->language == language_java) | |
8750 | { | |
8751 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 8752 | |
418835cc KS |
8753 | if (name && !strcmp (name, "this")) |
8754 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
8755 | } | |
8756 | } | |
3ce3b1ba PA |
8757 | arg_type = die_type (child_die, cu); |
8758 | ||
8759 | /* RealView does not mark THIS as const, which the testsuite | |
8760 | expects. GCC marks THIS as const in method definitions, | |
8761 | but not in the class specifications (GCC PR 43053). */ | |
8762 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
8763 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
8764 | { | |
8765 | int is_this = 0; | |
8766 | struct dwarf2_cu *arg_cu = cu; | |
8767 | const char *name = dwarf2_name (child_die, cu); | |
8768 | ||
8769 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
8770 | if (attr) | |
8771 | { | |
8772 | /* If the compiler emits this, use it. */ | |
8773 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
8774 | is_this = 1; | |
8775 | } | |
8776 | else if (name && strcmp (name, "this") == 0) | |
8777 | /* Function definitions will have the argument names. */ | |
8778 | is_this = 1; | |
8779 | else if (name == NULL && iparams == 0) | |
8780 | /* Declarations may not have the names, so like | |
8781 | elsewhere in GDB, assume an artificial first | |
8782 | argument is "this". */ | |
8783 | is_this = 1; | |
8784 | ||
8785 | if (is_this) | |
8786 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
8787 | arg_type, 0); | |
8788 | } | |
8789 | ||
8790 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
8791 | iparams++; |
8792 | } | |
8793 | child_die = sibling_die (child_die); | |
8794 | } | |
8795 | } | |
8796 | ||
76c10ea2 | 8797 | return ftype; |
c906108c SS |
8798 | } |
8799 | ||
f792889a | 8800 | static struct type * |
e7c27a73 | 8801 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8802 | { |
e7c27a73 | 8803 | struct objfile *objfile = cu->objfile; |
0114d602 | 8804 | const char *name = NULL; |
3c8e0968 | 8805 | struct type *this_type, *target_type; |
c906108c | 8806 | |
94af9270 | 8807 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 8808 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
8809 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
8810 | TYPE_NAME (this_type) = (char *) name; | |
f792889a | 8811 | set_die_type (die, this_type, cu); |
3c8e0968 DE |
8812 | target_type = die_type (die, cu); |
8813 | if (target_type != this_type) | |
8814 | TYPE_TARGET_TYPE (this_type) = target_type; | |
8815 | else | |
8816 | { | |
8817 | /* Self-referential typedefs are, it seems, not allowed by the DWARF | |
8818 | spec and cause infinite loops in GDB. */ | |
8819 | complaint (&symfile_complaints, | |
8820 | _("Self-referential DW_TAG_typedef " | |
8821 | "- DIE at 0x%x [in module %s]"), | |
bb5ed363 | 8822 | die->offset, objfile->name); |
3c8e0968 DE |
8823 | TYPE_TARGET_TYPE (this_type) = NULL; |
8824 | } | |
f792889a | 8825 | return this_type; |
c906108c SS |
8826 | } |
8827 | ||
8828 | /* Find a representation of a given base type and install | |
8829 | it in the TYPE field of the die. */ | |
8830 | ||
f792889a | 8831 | static struct type * |
e7c27a73 | 8832 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8833 | { |
e7c27a73 | 8834 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8835 | struct type *type; |
8836 | struct attribute *attr; | |
8837 | int encoding = 0, size = 0; | |
39cbfefa | 8838 | char *name; |
6ccb9162 UW |
8839 | enum type_code code = TYPE_CODE_INT; |
8840 | int type_flags = 0; | |
8841 | struct type *target_type = NULL; | |
c906108c | 8842 | |
e142c38c | 8843 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
8844 | if (attr) |
8845 | { | |
8846 | encoding = DW_UNSND (attr); | |
8847 | } | |
e142c38c | 8848 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8849 | if (attr) |
8850 | { | |
8851 | size = DW_UNSND (attr); | |
8852 | } | |
39cbfefa | 8853 | name = dwarf2_name (die, cu); |
6ccb9162 | 8854 | if (!name) |
c906108c | 8855 | { |
6ccb9162 UW |
8856 | complaint (&symfile_complaints, |
8857 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 8858 | } |
6ccb9162 UW |
8859 | |
8860 | switch (encoding) | |
c906108c | 8861 | { |
6ccb9162 UW |
8862 | case DW_ATE_address: |
8863 | /* Turn DW_ATE_address into a void * pointer. */ | |
8864 | code = TYPE_CODE_PTR; | |
8865 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8866 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
8867 | break; | |
8868 | case DW_ATE_boolean: | |
8869 | code = TYPE_CODE_BOOL; | |
8870 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8871 | break; | |
8872 | case DW_ATE_complex_float: | |
8873 | code = TYPE_CODE_COMPLEX; | |
8874 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
8875 | break; | |
8876 | case DW_ATE_decimal_float: | |
8877 | code = TYPE_CODE_DECFLOAT; | |
8878 | break; | |
8879 | case DW_ATE_float: | |
8880 | code = TYPE_CODE_FLT; | |
8881 | break; | |
8882 | case DW_ATE_signed: | |
8883 | break; | |
8884 | case DW_ATE_unsigned: | |
8885 | type_flags |= TYPE_FLAG_UNSIGNED; | |
3b2b8fea TT |
8886 | if (cu->language == language_fortran |
8887 | && name | |
8888 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) | |
8889 | code = TYPE_CODE_CHAR; | |
6ccb9162 UW |
8890 | break; |
8891 | case DW_ATE_signed_char: | |
6e70227d | 8892 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
8893 | || cu->language == language_pascal |
8894 | || cu->language == language_fortran) | |
6ccb9162 UW |
8895 | code = TYPE_CODE_CHAR; |
8896 | break; | |
8897 | case DW_ATE_unsigned_char: | |
868a0084 | 8898 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
8899 | || cu->language == language_pascal |
8900 | || cu->language == language_fortran) | |
6ccb9162 UW |
8901 | code = TYPE_CODE_CHAR; |
8902 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8903 | break; | |
75079b2b TT |
8904 | case DW_ATE_UTF: |
8905 | /* We just treat this as an integer and then recognize the | |
8906 | type by name elsewhere. */ | |
8907 | break; | |
8908 | ||
6ccb9162 UW |
8909 | default: |
8910 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
8911 | dwarf_type_encoding_name (encoding)); | |
8912 | break; | |
c906108c | 8913 | } |
6ccb9162 | 8914 | |
0114d602 DJ |
8915 | type = init_type (code, size, type_flags, NULL, objfile); |
8916 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
8917 | TYPE_TARGET_TYPE (type) = target_type; |
8918 | ||
0114d602 | 8919 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 8920 | TYPE_NOSIGN (type) = 1; |
0114d602 | 8921 | |
f792889a | 8922 | return set_die_type (die, type, cu); |
c906108c SS |
8923 | } |
8924 | ||
a02abb62 JB |
8925 | /* Read the given DW_AT_subrange DIE. */ |
8926 | ||
f792889a | 8927 | static struct type * |
a02abb62 JB |
8928 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
8929 | { | |
8930 | struct type *base_type; | |
8931 | struct type *range_type; | |
8932 | struct attribute *attr; | |
43bbcdc2 PH |
8933 | LONGEST low = 0; |
8934 | LONGEST high = -1; | |
39cbfefa | 8935 | char *name; |
43bbcdc2 | 8936 | LONGEST negative_mask; |
e77813c8 | 8937 | |
a02abb62 | 8938 | base_type = die_type (die, cu); |
953ac07e JK |
8939 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
8940 | check_typedef (base_type); | |
a02abb62 | 8941 | |
7e314c57 JK |
8942 | /* The die_type call above may have already set the type for this DIE. */ |
8943 | range_type = get_die_type (die, cu); | |
8944 | if (range_type) | |
8945 | return range_type; | |
8946 | ||
e142c38c | 8947 | if (cu->language == language_fortran) |
6e70227d | 8948 | { |
a02abb62 JB |
8949 | /* FORTRAN implies a lower bound of 1, if not given. */ |
8950 | low = 1; | |
8951 | } | |
8952 | ||
dd5e6932 DJ |
8953 | /* FIXME: For variable sized arrays either of these could be |
8954 | a variable rather than a constant value. We'll allow it, | |
8955 | but we don't know how to handle it. */ | |
e142c38c | 8956 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
8957 | if (attr) |
8958 | low = dwarf2_get_attr_constant_value (attr, 0); | |
8959 | ||
e142c38c | 8960 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 8961 | if (attr) |
6e70227d | 8962 | { |
d48323d8 | 8963 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
a02abb62 JB |
8964 | { |
8965 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 8966 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
8967 | FIXME: GDB does not yet know how to handle dynamic |
8968 | arrays properly, treat them as arrays with unspecified | |
8969 | length for now. | |
8970 | ||
8971 | FIXME: jimb/2003-09-22: GDB does not really know | |
8972 | how to handle arrays of unspecified length | |
8973 | either; we just represent them as zero-length | |
8974 | arrays. Choose an appropriate upper bound given | |
8975 | the lower bound we've computed above. */ | |
8976 | high = low - 1; | |
8977 | } | |
8978 | else | |
8979 | high = dwarf2_get_attr_constant_value (attr, 1); | |
8980 | } | |
e77813c8 PM |
8981 | else |
8982 | { | |
8983 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
8984 | if (attr) | |
8985 | { | |
8986 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
8987 | high = low + count - 1; | |
8988 | } | |
c2ff108b JK |
8989 | else |
8990 | { | |
8991 | /* Unspecified array length. */ | |
8992 | high = low - 1; | |
8993 | } | |
e77813c8 PM |
8994 | } |
8995 | ||
8996 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
8997 | without specifying a base type. | |
8998 | In that case, the base type must be set to the type of | |
8999 | the lower bound, upper bound or count, in that order, if any of these | |
9000 | three attributes references an object that has a type. | |
9001 | If no base type is found, the Dwarf-2 specifications say that | |
9002 | a signed integer type of size equal to the size of an address should | |
9003 | be used. | |
9004 | For the following C code: `extern char gdb_int [];' | |
9005 | GCC produces an empty range DIE. | |
9006 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 9007 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
9008 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
9009 | { | |
9010 | struct objfile *objfile = cu->objfile; | |
9011 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
9012 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
9013 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
9014 | ||
9015 | /* Test "int", "long int", and "long long int" objfile types, | |
9016 | and select the first one having a size above or equal to the | |
9017 | architecture address size. */ | |
9018 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
9019 | base_type = int_type; | |
9020 | else | |
9021 | { | |
9022 | int_type = objfile_type (objfile)->builtin_long; | |
9023 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
9024 | base_type = int_type; | |
9025 | else | |
9026 | { | |
9027 | int_type = objfile_type (objfile)->builtin_long_long; | |
9028 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
9029 | base_type = int_type; | |
9030 | } | |
9031 | } | |
9032 | } | |
a02abb62 | 9033 | |
6e70227d | 9034 | negative_mask = |
43bbcdc2 PH |
9035 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
9036 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
9037 | low |= negative_mask; | |
9038 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
9039 | high |= negative_mask; | |
9040 | ||
a02abb62 JB |
9041 | range_type = create_range_type (NULL, base_type, low, high); |
9042 | ||
bbb0eef6 JK |
9043 | /* Mark arrays with dynamic length at least as an array of unspecified |
9044 | length. GDB could check the boundary but before it gets implemented at | |
9045 | least allow accessing the array elements. */ | |
d48323d8 | 9046 | if (attr && attr_form_is_block (attr)) |
bbb0eef6 JK |
9047 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
9048 | ||
c2ff108b JK |
9049 | /* Ada expects an empty array on no boundary attributes. */ |
9050 | if (attr == NULL && cu->language != language_ada) | |
9051 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
9052 | ||
39cbfefa DJ |
9053 | name = dwarf2_name (die, cu); |
9054 | if (name) | |
9055 | TYPE_NAME (range_type) = name; | |
6e70227d | 9056 | |
e142c38c | 9057 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
9058 | if (attr) |
9059 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
9060 | ||
7e314c57 JK |
9061 | set_die_type (die, range_type, cu); |
9062 | ||
9063 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
9064 | set_descriptive_type (range_type, die, cu); |
9065 | ||
7e314c57 | 9066 | return range_type; |
a02abb62 | 9067 | } |
6e70227d | 9068 | |
f792889a | 9069 | static struct type * |
81a17f79 JB |
9070 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
9071 | { | |
9072 | struct type *type; | |
81a17f79 | 9073 | |
81a17f79 JB |
9074 | /* For now, we only support the C meaning of an unspecified type: void. */ |
9075 | ||
0114d602 DJ |
9076 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
9077 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 9078 | |
f792889a | 9079 | return set_die_type (die, type, cu); |
81a17f79 | 9080 | } |
a02abb62 | 9081 | |
51545339 DJ |
9082 | /* Trivial hash function for die_info: the hash value of a DIE |
9083 | is its offset in .debug_info for this objfile. */ | |
9084 | ||
9085 | static hashval_t | |
9086 | die_hash (const void *item) | |
9087 | { | |
9088 | const struct die_info *die = item; | |
9a619af0 | 9089 | |
51545339 DJ |
9090 | return die->offset; |
9091 | } | |
9092 | ||
9093 | /* Trivial comparison function for die_info structures: two DIEs | |
9094 | are equal if they have the same offset. */ | |
9095 | ||
9096 | static int | |
9097 | die_eq (const void *item_lhs, const void *item_rhs) | |
9098 | { | |
9099 | const struct die_info *die_lhs = item_lhs; | |
9100 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 9101 | |
51545339 DJ |
9102 | return die_lhs->offset == die_rhs->offset; |
9103 | } | |
9104 | ||
c906108c SS |
9105 | /* Read a whole compilation unit into a linked list of dies. */ |
9106 | ||
f9aca02d | 9107 | static struct die_info * |
93311388 | 9108 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 9109 | { |
93311388 | 9110 | struct die_reader_specs reader_specs; |
98bfdba5 | 9111 | int read_abbrevs = 0; |
1d9ec526 | 9112 | struct cleanup *back_to = NULL; |
98bfdba5 PA |
9113 | struct die_info *die; |
9114 | ||
9115 | if (cu->dwarf2_abbrevs == NULL) | |
9116 | { | |
e5fe5e75 | 9117 | dwarf2_read_abbrevs (cu); |
98bfdba5 PA |
9118 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
9119 | read_abbrevs = 1; | |
9120 | } | |
93311388 | 9121 | |
348e048f | 9122 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
9123 | cu->die_hash |
9124 | = htab_create_alloc_ex (cu->header.length / 12, | |
9125 | die_hash, | |
9126 | die_eq, | |
9127 | NULL, | |
9128 | &cu->comp_unit_obstack, | |
9129 | hashtab_obstack_allocate, | |
9130 | dummy_obstack_deallocate); | |
9131 | ||
93311388 DE |
9132 | init_cu_die_reader (&reader_specs, cu); |
9133 | ||
98bfdba5 PA |
9134 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
9135 | ||
9136 | if (read_abbrevs) | |
9137 | do_cleanups (back_to); | |
9138 | ||
9139 | return die; | |
639d11d3 DC |
9140 | } |
9141 | ||
d97bc12b DE |
9142 | /* Main entry point for reading a DIE and all children. |
9143 | Read the DIE and dump it if requested. */ | |
9144 | ||
9145 | static struct die_info * | |
93311388 DE |
9146 | read_die_and_children (const struct die_reader_specs *reader, |
9147 | gdb_byte *info_ptr, | |
d97bc12b DE |
9148 | gdb_byte **new_info_ptr, |
9149 | struct die_info *parent) | |
9150 | { | |
93311388 | 9151 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
9152 | new_info_ptr, parent); |
9153 | ||
9154 | if (dwarf2_die_debug) | |
9155 | { | |
348e048f DE |
9156 | fprintf_unfiltered (gdb_stdlog, |
9157 | "\nRead die from %s of %s:\n", | |
b0df02fd | 9158 | (reader->cu->per_cu->debug_types_section |
8b70b953 TT |
9159 | ? ".debug_types" |
9160 | : ".debug_info"), | |
348e048f | 9161 | reader->abfd->filename); |
d97bc12b DE |
9162 | dump_die (result, dwarf2_die_debug); |
9163 | } | |
9164 | ||
9165 | return result; | |
9166 | } | |
9167 | ||
639d11d3 DC |
9168 | /* Read a single die and all its descendents. Set the die's sibling |
9169 | field to NULL; set other fields in the die correctly, and set all | |
9170 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
9171 | location of the info_ptr after reading all of those dies. PARENT | |
9172 | is the parent of the die in question. */ | |
9173 | ||
9174 | static struct die_info * | |
93311388 DE |
9175 | read_die_and_children_1 (const struct die_reader_specs *reader, |
9176 | gdb_byte *info_ptr, | |
d97bc12b DE |
9177 | gdb_byte **new_info_ptr, |
9178 | struct die_info *parent) | |
639d11d3 DC |
9179 | { |
9180 | struct die_info *die; | |
fe1b8b76 | 9181 | gdb_byte *cur_ptr; |
639d11d3 DC |
9182 | int has_children; |
9183 | ||
93311388 | 9184 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
9185 | if (die == NULL) |
9186 | { | |
9187 | *new_info_ptr = cur_ptr; | |
9188 | return NULL; | |
9189 | } | |
93311388 | 9190 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
9191 | |
9192 | if (has_children) | |
348e048f | 9193 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
9194 | else |
9195 | { | |
9196 | die->child = NULL; | |
9197 | *new_info_ptr = cur_ptr; | |
9198 | } | |
9199 | ||
9200 | die->sibling = NULL; | |
9201 | die->parent = parent; | |
9202 | return die; | |
9203 | } | |
9204 | ||
9205 | /* Read a die, all of its descendents, and all of its siblings; set | |
9206 | all of the fields of all of the dies correctly. Arguments are as | |
9207 | in read_die_and_children. */ | |
9208 | ||
9209 | static struct die_info * | |
93311388 DE |
9210 | read_die_and_siblings (const struct die_reader_specs *reader, |
9211 | gdb_byte *info_ptr, | |
fe1b8b76 | 9212 | gdb_byte **new_info_ptr, |
639d11d3 DC |
9213 | struct die_info *parent) |
9214 | { | |
9215 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 9216 | gdb_byte *cur_ptr; |
639d11d3 | 9217 | |
c906108c | 9218 | cur_ptr = info_ptr; |
639d11d3 DC |
9219 | first_die = last_sibling = NULL; |
9220 | ||
9221 | while (1) | |
c906108c | 9222 | { |
639d11d3 | 9223 | struct die_info *die |
93311388 | 9224 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 9225 | |
1d325ec1 | 9226 | if (die == NULL) |
c906108c | 9227 | { |
639d11d3 DC |
9228 | *new_info_ptr = cur_ptr; |
9229 | return first_die; | |
c906108c | 9230 | } |
1d325ec1 DJ |
9231 | |
9232 | if (!first_die) | |
9233 | first_die = die; | |
c906108c | 9234 | else |
1d325ec1 DJ |
9235 | last_sibling->sibling = die; |
9236 | ||
9237 | last_sibling = die; | |
c906108c | 9238 | } |
c906108c SS |
9239 | } |
9240 | ||
93311388 DE |
9241 | /* Read the die from the .debug_info section buffer. Set DIEP to |
9242 | point to a newly allocated die with its information, except for its | |
9243 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
9244 | whether the die has children or not. */ | |
9245 | ||
9246 | static gdb_byte * | |
9247 | read_full_die (const struct die_reader_specs *reader, | |
9248 | struct die_info **diep, gdb_byte *info_ptr, | |
9249 | int *has_children) | |
9250 | { | |
9251 | unsigned int abbrev_number, bytes_read, i, offset; | |
9252 | struct abbrev_info *abbrev; | |
9253 | struct die_info *die; | |
9254 | struct dwarf2_cu *cu = reader->cu; | |
9255 | bfd *abfd = reader->abfd; | |
9256 | ||
9257 | offset = info_ptr - reader->buffer; | |
9258 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
9259 | info_ptr += bytes_read; | |
9260 | if (!abbrev_number) | |
9261 | { | |
9262 | *diep = NULL; | |
9263 | *has_children = 0; | |
9264 | return info_ptr; | |
9265 | } | |
9266 | ||
9267 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
9268 | if (!abbrev) | |
348e048f DE |
9269 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
9270 | abbrev_number, | |
9271 | bfd_get_filename (abfd)); | |
9272 | ||
93311388 DE |
9273 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
9274 | die->offset = offset; | |
9275 | die->tag = abbrev->tag; | |
9276 | die->abbrev = abbrev_number; | |
9277 | ||
9278 | die->num_attrs = abbrev->num_attrs; | |
9279 | ||
9280 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9281 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
9282 | abfd, info_ptr, cu); | |
9283 | ||
9284 | *diep = die; | |
9285 | *has_children = abbrev->has_children; | |
9286 | return info_ptr; | |
9287 | } | |
9288 | ||
c906108c SS |
9289 | /* In DWARF version 2, the description of the debugging information is |
9290 | stored in a separate .debug_abbrev section. Before we read any | |
9291 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
9292 | in a hash table. This function also sets flags in CU describing |
9293 | the data found in the abbrev table. */ | |
c906108c SS |
9294 | |
9295 | static void | |
e5fe5e75 | 9296 | dwarf2_read_abbrevs (struct dwarf2_cu *cu) |
c906108c | 9297 | { |
e5fe5e75 | 9298 | bfd *abfd = cu->objfile->obfd; |
e7c27a73 | 9299 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 9300 | gdb_byte *abbrev_ptr; |
c906108c SS |
9301 | struct abbrev_info *cur_abbrev; |
9302 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
9303 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
9304 | struct attr_abbrev *cur_attrs; |
9305 | unsigned int allocated_attrs; | |
c906108c | 9306 | |
0963b4bd | 9307 | /* Initialize dwarf2 abbrevs. */ |
f3dd6933 DJ |
9308 | obstack_init (&cu->abbrev_obstack); |
9309 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
9310 | (ABBREV_HASH_SIZE | |
9311 | * sizeof (struct abbrev_info *))); | |
9312 | memset (cu->dwarf2_abbrevs, 0, | |
9313 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 9314 | |
be391dca TT |
9315 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
9316 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 9317 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
9318 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9319 | abbrev_ptr += bytes_read; | |
9320 | ||
f3dd6933 DJ |
9321 | allocated_attrs = ATTR_ALLOC_CHUNK; |
9322 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 9323 | |
0963b4bd | 9324 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
9325 | while (abbrev_number) |
9326 | { | |
f3dd6933 | 9327 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
9328 | |
9329 | /* read in abbrev header */ | |
9330 | cur_abbrev->number = abbrev_number; | |
9331 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9332 | abbrev_ptr += bytes_read; | |
9333 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
9334 | abbrev_ptr += 1; | |
9335 | ||
9336 | /* now read in declarations */ | |
9337 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9338 | abbrev_ptr += bytes_read; | |
9339 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9340 | abbrev_ptr += bytes_read; | |
9341 | while (abbrev_name) | |
9342 | { | |
f3dd6933 | 9343 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 9344 | { |
f3dd6933 DJ |
9345 | allocated_attrs += ATTR_ALLOC_CHUNK; |
9346 | cur_attrs | |
9347 | = xrealloc (cur_attrs, (allocated_attrs | |
9348 | * sizeof (struct attr_abbrev))); | |
c906108c | 9349 | } |
ae038cb0 | 9350 | |
f3dd6933 DJ |
9351 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
9352 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
9353 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9354 | abbrev_ptr += bytes_read; | |
9355 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9356 | abbrev_ptr += bytes_read; | |
9357 | } | |
9358 | ||
f3dd6933 DJ |
9359 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
9360 | (cur_abbrev->num_attrs | |
9361 | * sizeof (struct attr_abbrev))); | |
9362 | memcpy (cur_abbrev->attrs, cur_attrs, | |
9363 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
9364 | ||
c906108c | 9365 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
9366 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
9367 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
9368 | |
9369 | /* Get next abbreviation. | |
9370 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
9371 | always properly terminated with an abbrev number of 0. |
9372 | Exit loop if we encounter an abbreviation which we have | |
9373 | already read (which means we are about to read the abbreviations | |
9374 | for the next compile unit) or if the end of the abbreviation | |
9375 | table is reached. */ | |
dce234bc PP |
9376 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
9377 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
9378 | break; |
9379 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9380 | abbrev_ptr += bytes_read; | |
e7c27a73 | 9381 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
9382 | break; |
9383 | } | |
f3dd6933 DJ |
9384 | |
9385 | xfree (cur_attrs); | |
c906108c SS |
9386 | } |
9387 | ||
f3dd6933 | 9388 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 9389 | |
c906108c | 9390 | static void |
f3dd6933 | 9391 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 9392 | { |
f3dd6933 | 9393 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 9394 | |
f3dd6933 DJ |
9395 | obstack_free (&cu->abbrev_obstack, NULL); |
9396 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
9397 | } |
9398 | ||
9399 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
9400 | ||
9401 | static struct abbrev_info * | |
e7c27a73 | 9402 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
9403 | { |
9404 | unsigned int hash_number; | |
9405 | struct abbrev_info *abbrev; | |
9406 | ||
9407 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 9408 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
9409 | |
9410 | while (abbrev) | |
9411 | { | |
9412 | if (abbrev->number == number) | |
9413 | return abbrev; | |
9414 | else | |
9415 | abbrev = abbrev->next; | |
9416 | } | |
9417 | return NULL; | |
9418 | } | |
9419 | ||
72bf9492 DJ |
9420 | /* Returns nonzero if TAG represents a type that we might generate a partial |
9421 | symbol for. */ | |
9422 | ||
9423 | static int | |
9424 | is_type_tag_for_partial (int tag) | |
9425 | { | |
9426 | switch (tag) | |
9427 | { | |
9428 | #if 0 | |
9429 | /* Some types that would be reasonable to generate partial symbols for, | |
9430 | that we don't at present. */ | |
9431 | case DW_TAG_array_type: | |
9432 | case DW_TAG_file_type: | |
9433 | case DW_TAG_ptr_to_member_type: | |
9434 | case DW_TAG_set_type: | |
9435 | case DW_TAG_string_type: | |
9436 | case DW_TAG_subroutine_type: | |
9437 | #endif | |
9438 | case DW_TAG_base_type: | |
9439 | case DW_TAG_class_type: | |
680b30c7 | 9440 | case DW_TAG_interface_type: |
72bf9492 DJ |
9441 | case DW_TAG_enumeration_type: |
9442 | case DW_TAG_structure_type: | |
9443 | case DW_TAG_subrange_type: | |
9444 | case DW_TAG_typedef: | |
9445 | case DW_TAG_union_type: | |
9446 | return 1; | |
9447 | default: | |
9448 | return 0; | |
9449 | } | |
9450 | } | |
9451 | ||
9452 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
9453 | ||
9454 | static struct partial_die_info * | |
93311388 DE |
9455 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
9456 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 | 9457 | { |
bb5ed363 | 9458 | struct objfile *objfile = cu->objfile; |
72bf9492 DJ |
9459 | struct partial_die_info *part_die; |
9460 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
9461 | struct abbrev_info *abbrev; | |
9462 | unsigned int bytes_read; | |
5afb4e99 | 9463 | unsigned int load_all = 0; |
72bf9492 DJ |
9464 | |
9465 | int nesting_level = 1; | |
9466 | ||
9467 | parent_die = NULL; | |
9468 | last_die = NULL; | |
9469 | ||
5afb4e99 DJ |
9470 | if (cu->per_cu && cu->per_cu->load_all_dies) |
9471 | load_all = 1; | |
9472 | ||
72bf9492 DJ |
9473 | cu->partial_dies |
9474 | = htab_create_alloc_ex (cu->header.length / 12, | |
9475 | partial_die_hash, | |
9476 | partial_die_eq, | |
9477 | NULL, | |
9478 | &cu->comp_unit_obstack, | |
9479 | hashtab_obstack_allocate, | |
9480 | dummy_obstack_deallocate); | |
9481 | ||
9482 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9483 | sizeof (struct partial_die_info)); | |
9484 | ||
9485 | while (1) | |
9486 | { | |
9487 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
9488 | ||
9489 | /* A NULL abbrev means the end of a series of children. */ | |
9490 | if (abbrev == NULL) | |
9491 | { | |
9492 | if (--nesting_level == 0) | |
9493 | { | |
9494 | /* PART_DIE was probably the last thing allocated on the | |
9495 | comp_unit_obstack, so we could call obstack_free | |
9496 | here. We don't do that because the waste is small, | |
9497 | and will be cleaned up when we're done with this | |
9498 | compilation unit. This way, we're also more robust | |
9499 | against other users of the comp_unit_obstack. */ | |
9500 | return first_die; | |
9501 | } | |
9502 | info_ptr += bytes_read; | |
9503 | last_die = parent_die; | |
9504 | parent_die = parent_die->die_parent; | |
9505 | continue; | |
9506 | } | |
9507 | ||
98bfdba5 PA |
9508 | /* Check for template arguments. We never save these; if |
9509 | they're seen, we just mark the parent, and go on our way. */ | |
9510 | if (parent_die != NULL | |
9511 | && cu->language == language_cplus | |
9512 | && (abbrev->tag == DW_TAG_template_type_param | |
9513 | || abbrev->tag == DW_TAG_template_value_param)) | |
9514 | { | |
9515 | parent_die->has_template_arguments = 1; | |
9516 | ||
9517 | if (!load_all) | |
9518 | { | |
9519 | /* We don't need a partial DIE for the template argument. */ | |
9520 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, | |
9521 | cu); | |
9522 | continue; | |
9523 | } | |
9524 | } | |
9525 | ||
9526 | /* We only recurse into subprograms looking for template arguments. | |
9527 | Skip their other children. */ | |
9528 | if (!load_all | |
9529 | && cu->language == language_cplus | |
9530 | && parent_die != NULL | |
9531 | && parent_die->tag == DW_TAG_subprogram) | |
9532 | { | |
9533 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); | |
9534 | continue; | |
9535 | } | |
9536 | ||
5afb4e99 DJ |
9537 | /* Check whether this DIE is interesting enough to save. Normally |
9538 | we would not be interested in members here, but there may be | |
9539 | later variables referencing them via DW_AT_specification (for | |
9540 | static members). */ | |
9541 | if (!load_all | |
9542 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 9543 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
9544 | && abbrev->tag != DW_TAG_enumerator |
9545 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 9546 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 9547 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 9548 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 9549 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 9550 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
9551 | { |
9552 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9553 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
9554 | continue; |
9555 | } | |
9556 | ||
93311388 DE |
9557 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
9558 | buffer, info_ptr, cu); | |
72bf9492 DJ |
9559 | |
9560 | /* This two-pass algorithm for processing partial symbols has a | |
9561 | high cost in cache pressure. Thus, handle some simple cases | |
9562 | here which cover the majority of C partial symbols. DIEs | |
9563 | which neither have specification tags in them, nor could have | |
9564 | specification tags elsewhere pointing at them, can simply be | |
9565 | processed and discarded. | |
9566 | ||
9567 | This segment is also optional; scan_partial_symbols and | |
9568 | add_partial_symbol will handle these DIEs if we chain | |
9569 | them in normally. When compilers which do not emit large | |
9570 | quantities of duplicate debug information are more common, | |
9571 | this code can probably be removed. */ | |
9572 | ||
9573 | /* Any complete simple types at the top level (pretty much all | |
9574 | of them, for a language without namespaces), can be processed | |
9575 | directly. */ | |
9576 | if (parent_die == NULL | |
9577 | && part_die->has_specification == 0 | |
9578 | && part_die->is_declaration == 0 | |
d8228535 | 9579 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
9580 | || part_die->tag == DW_TAG_base_type |
9581 | || part_die->tag == DW_TAG_subrange_type)) | |
9582 | { | |
9583 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 9584 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9585 | VAR_DOMAIN, LOC_TYPEDEF, |
bb5ed363 DE |
9586 | &objfile->static_psymbols, |
9587 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
93311388 | 9588 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9589 | continue; |
9590 | } | |
9591 | ||
d8228535 JK |
9592 | /* The exception for DW_TAG_typedef with has_children above is |
9593 | a workaround of GCC PR debug/47510. In the case of this complaint | |
9594 | type_name_no_tag_or_error will error on such types later. | |
9595 | ||
9596 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
9597 | it could not find the child DIEs referenced later, this is checked | |
9598 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
9599 | ||
9600 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
9601 | complaint (&symfile_complaints, | |
9602 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
9603 | "- DIE at 0x%x [in module %s]"), | |
bb5ed363 | 9604 | part_die->offset, objfile->name); |
d8228535 | 9605 | |
72bf9492 DJ |
9606 | /* If we're at the second level, and we're an enumerator, and |
9607 | our parent has no specification (meaning possibly lives in a | |
9608 | namespace elsewhere), then we can add the partial symbol now | |
9609 | instead of queueing it. */ | |
9610 | if (part_die->tag == DW_TAG_enumerator | |
9611 | && parent_die != NULL | |
9612 | && parent_die->die_parent == NULL | |
9613 | && parent_die->tag == DW_TAG_enumeration_type | |
9614 | && parent_die->has_specification == 0) | |
9615 | { | |
9616 | if (part_die->name == NULL) | |
3e43a32a MS |
9617 | complaint (&symfile_complaints, |
9618 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 9619 | else if (building_psymtab) |
04a679b8 | 9620 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9621 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
9622 | (cu->language == language_cplus |
9623 | || cu->language == language_java) | |
bb5ed363 DE |
9624 | ? &objfile->global_psymbols |
9625 | : &objfile->static_psymbols, | |
9626 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
72bf9492 | 9627 | |
93311388 | 9628 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9629 | continue; |
9630 | } | |
9631 | ||
9632 | /* We'll save this DIE so link it in. */ | |
9633 | part_die->die_parent = parent_die; | |
9634 | part_die->die_sibling = NULL; | |
9635 | part_die->die_child = NULL; | |
9636 | ||
9637 | if (last_die && last_die == parent_die) | |
9638 | last_die->die_child = part_die; | |
9639 | else if (last_die) | |
9640 | last_die->die_sibling = part_die; | |
9641 | ||
9642 | last_die = part_die; | |
9643 | ||
9644 | if (first_die == NULL) | |
9645 | first_die = part_die; | |
9646 | ||
9647 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
9648 | find interesting need to be in the hash table, because we | |
9649 | also have the parent/sibling/child chains; only those that we | |
9650 | might refer to by offset later during partial symbol reading. | |
9651 | ||
9652 | For now this means things that might have be the target of a | |
9653 | DW_AT_specification, DW_AT_abstract_origin, or | |
9654 | DW_AT_extension. DW_AT_extension will refer only to | |
9655 | namespaces; DW_AT_abstract_origin refers to functions (and | |
9656 | many things under the function DIE, but we do not recurse | |
9657 | into function DIEs during partial symbol reading) and | |
9658 | possibly variables as well; DW_AT_specification refers to | |
9659 | declarations. Declarations ought to have the DW_AT_declaration | |
9660 | flag. It happens that GCC forgets to put it in sometimes, but | |
9661 | only for functions, not for types. | |
9662 | ||
9663 | Adding more things than necessary to the hash table is harmless | |
9664 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
9665 | wasted time in find_partial_die, when we reread the compilation |
9666 | unit with load_all_dies set. */ | |
72bf9492 | 9667 | |
5afb4e99 | 9668 | if (load_all |
72929c62 | 9669 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 9670 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
9671 | || abbrev->tag == DW_TAG_variable |
9672 | || abbrev->tag == DW_TAG_namespace | |
9673 | || part_die->is_declaration) | |
9674 | { | |
9675 | void **slot; | |
9676 | ||
9677 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
9678 | part_die->offset, INSERT); | |
9679 | *slot = part_die; | |
9680 | } | |
9681 | ||
9682 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9683 | sizeof (struct partial_die_info)); | |
9684 | ||
9685 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 9686 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
9687 | languages we have to, so that we can get at method physnames |
9688 | to infer fully qualified class names, for DW_AT_specification, | |
9689 | and for C++ template arguments. For C++, we also look one level | |
9690 | inside functions to find template arguments (if the name of the | |
9691 | function does not already contain the template arguments). | |
bc30ff58 JB |
9692 | |
9693 | For Ada, we need to scan the children of subprograms and lexical | |
9694 | blocks as well because Ada allows the definition of nested | |
9695 | entities that could be interesting for the debugger, such as | |
9696 | nested subprograms for instance. */ | |
72bf9492 | 9697 | if (last_die->has_children |
5afb4e99 DJ |
9698 | && (load_all |
9699 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 9700 | || last_die->tag == DW_TAG_module |
72bf9492 | 9701 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
9702 | || (cu->language == language_cplus |
9703 | && last_die->tag == DW_TAG_subprogram | |
9704 | && (last_die->name == NULL | |
9705 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
9706 | || (cu->language != language_c |
9707 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 9708 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 9709 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
9710 | || last_die->tag == DW_TAG_union_type)) |
9711 | || (cu->language == language_ada | |
9712 | && (last_die->tag == DW_TAG_subprogram | |
9713 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
9714 | { |
9715 | nesting_level++; | |
9716 | parent_die = last_die; | |
9717 | continue; | |
9718 | } | |
9719 | ||
9720 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9721 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9722 | |
9723 | /* Back to the top, do it again. */ | |
9724 | } | |
9725 | } | |
9726 | ||
c906108c SS |
9727 | /* Read a minimal amount of information into the minimal die structure. */ |
9728 | ||
fe1b8b76 | 9729 | static gdb_byte * |
72bf9492 DJ |
9730 | read_partial_die (struct partial_die_info *part_die, |
9731 | struct abbrev_info *abbrev, | |
9732 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
9733 | gdb_byte *buffer, gdb_byte *info_ptr, |
9734 | struct dwarf2_cu *cu) | |
c906108c | 9735 | { |
bb5ed363 | 9736 | struct objfile *objfile = cu->objfile; |
fa238c03 | 9737 | unsigned int i; |
c906108c | 9738 | struct attribute attr; |
c5aa993b | 9739 | int has_low_pc_attr = 0; |
c906108c SS |
9740 | int has_high_pc_attr = 0; |
9741 | ||
72bf9492 | 9742 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 9743 | |
93311388 | 9744 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
9745 | |
9746 | info_ptr += abbrev_len; | |
9747 | ||
9748 | if (abbrev == NULL) | |
9749 | return info_ptr; | |
9750 | ||
c906108c SS |
9751 | part_die->tag = abbrev->tag; |
9752 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
9753 | |
9754 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9755 | { | |
e7c27a73 | 9756 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
9757 | |
9758 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 9759 | partial symbol table. */ |
c906108c SS |
9760 | switch (attr.name) |
9761 | { | |
9762 | case DW_AT_name: | |
71c25dea TT |
9763 | switch (part_die->tag) |
9764 | { | |
9765 | case DW_TAG_compile_unit: | |
348e048f | 9766 | case DW_TAG_type_unit: |
71c25dea TT |
9767 | /* Compilation units have a DW_AT_name that is a filename, not |
9768 | a source language identifier. */ | |
9769 | case DW_TAG_enumeration_type: | |
9770 | case DW_TAG_enumerator: | |
9771 | /* These tags always have simple identifiers already; no need | |
9772 | to canonicalize them. */ | |
9773 | part_die->name = DW_STRING (&attr); | |
9774 | break; | |
9775 | default: | |
9776 | part_die->name | |
9777 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
bb5ed363 | 9778 | &objfile->objfile_obstack); |
71c25dea TT |
9779 | break; |
9780 | } | |
c906108c | 9781 | break; |
31ef98ae | 9782 | case DW_AT_linkage_name: |
c906108c | 9783 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
9784 | /* Note that both forms of linkage name might appear. We |
9785 | assume they will be the same, and we only store the last | |
9786 | one we see. */ | |
94af9270 KS |
9787 | if (cu->language == language_ada) |
9788 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 9789 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
9790 | break; |
9791 | case DW_AT_low_pc: | |
9792 | has_low_pc_attr = 1; | |
9793 | part_die->lowpc = DW_ADDR (&attr); | |
9794 | break; | |
9795 | case DW_AT_high_pc: | |
9796 | has_high_pc_attr = 1; | |
9797 | part_die->highpc = DW_ADDR (&attr); | |
9798 | break; | |
9799 | case DW_AT_location: | |
0963b4bd | 9800 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
9801 | if (attr_form_is_block (&attr)) |
9802 | { | |
9803 | part_die->locdesc = DW_BLOCK (&attr); | |
9804 | } | |
3690dd37 | 9805 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 9806 | { |
4d3c2250 | 9807 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
9808 | } |
9809 | else | |
9810 | { | |
4d3c2250 KB |
9811 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
9812 | "partial symbol information"); | |
8e19ed76 | 9813 | } |
c906108c | 9814 | break; |
c906108c SS |
9815 | case DW_AT_external: |
9816 | part_die->is_external = DW_UNSND (&attr); | |
9817 | break; | |
9818 | case DW_AT_declaration: | |
9819 | part_die->is_declaration = DW_UNSND (&attr); | |
9820 | break; | |
9821 | case DW_AT_type: | |
9822 | part_die->has_type = 1; | |
9823 | break; | |
9824 | case DW_AT_abstract_origin: | |
9825 | case DW_AT_specification: | |
72bf9492 DJ |
9826 | case DW_AT_extension: |
9827 | part_die->has_specification = 1; | |
c764a876 | 9828 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
9829 | break; |
9830 | case DW_AT_sibling: | |
9831 | /* Ignore absolute siblings, they might point outside of | |
9832 | the current compile unit. */ | |
9833 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
9834 | complaint (&symfile_complaints, |
9835 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 9836 | else |
93311388 | 9837 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 9838 | break; |
fa4028e9 JB |
9839 | case DW_AT_byte_size: |
9840 | part_die->has_byte_size = 1; | |
9841 | break; | |
68511cec CES |
9842 | case DW_AT_calling_convention: |
9843 | /* DWARF doesn't provide a way to identify a program's source-level | |
9844 | entry point. DW_AT_calling_convention attributes are only meant | |
9845 | to describe functions' calling conventions. | |
9846 | ||
9847 | However, because it's a necessary piece of information in | |
9848 | Fortran, and because DW_CC_program is the only piece of debugging | |
9849 | information whose definition refers to a 'main program' at all, | |
9850 | several compilers have begun marking Fortran main programs with | |
9851 | DW_CC_program --- even when those functions use the standard | |
9852 | calling conventions. | |
9853 | ||
9854 | So until DWARF specifies a way to provide this information and | |
9855 | compilers pick up the new representation, we'll support this | |
9856 | practice. */ | |
9857 | if (DW_UNSND (&attr) == DW_CC_program | |
9858 | && cu->language == language_fortran) | |
01f8c46d JK |
9859 | { |
9860 | set_main_name (part_die->name); | |
9861 | ||
9862 | /* As this DIE has a static linkage the name would be difficult | |
9863 | to look up later. */ | |
9864 | language_of_main = language_fortran; | |
9865 | } | |
68511cec | 9866 | break; |
c906108c SS |
9867 | default: |
9868 | break; | |
9869 | } | |
9870 | } | |
9871 | ||
9373cf26 JK |
9872 | if (has_low_pc_attr && has_high_pc_attr) |
9873 | { | |
9874 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
9875 | eliminate duplicate copies of functions and vtables and such. | |
9876 | The linker will arbitrarily choose one and discard the others. | |
9877 | The AT_*_pc values for such functions refer to local labels in | |
9878 | these sections. If the section from that file was discarded, the | |
9879 | labels are not in the output, so the relocs get a value of 0. | |
9880 | If this is a discarded function, mark the pc bounds as invalid, | |
9881 | so that GDB will ignore it. */ | |
9882 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
9883 | { | |
bb5ed363 | 9884 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
9885 | |
9886 | complaint (&symfile_complaints, | |
9887 | _("DW_AT_low_pc %s is zero " | |
9888 | "for DIE at 0x%x [in module %s]"), | |
9889 | paddress (gdbarch, part_die->lowpc), | |
bb5ed363 | 9890 | part_die->offset, objfile->name); |
9373cf26 JK |
9891 | } |
9892 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
9893 | else if (part_die->lowpc >= part_die->highpc) | |
9894 | { | |
bb5ed363 | 9895 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
9896 | |
9897 | complaint (&symfile_complaints, | |
9898 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
9899 | "for DIE at 0x%x [in module %s]"), | |
9900 | paddress (gdbarch, part_die->lowpc), | |
9901 | paddress (gdbarch, part_die->highpc), | |
bb5ed363 | 9902 | part_die->offset, objfile->name); |
9373cf26 JK |
9903 | } |
9904 | else | |
9905 | part_die->has_pc_info = 1; | |
9906 | } | |
85cbf3d3 | 9907 | |
c906108c SS |
9908 | return info_ptr; |
9909 | } | |
9910 | ||
72bf9492 DJ |
9911 | /* Find a cached partial DIE at OFFSET in CU. */ |
9912 | ||
9913 | static struct partial_die_info * | |
c764a876 | 9914 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
9915 | { |
9916 | struct partial_die_info *lookup_die = NULL; | |
9917 | struct partial_die_info part_die; | |
9918 | ||
9919 | part_die.offset = offset; | |
9920 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
9921 | ||
72bf9492 DJ |
9922 | return lookup_die; |
9923 | } | |
9924 | ||
348e048f DE |
9925 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
9926 | except in the case of .debug_types DIEs which do not reference | |
9927 | outside their CU (they do however referencing other types via | |
55f1336d | 9928 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
9929 | |
9930 | static struct partial_die_info * | |
c764a876 | 9931 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 9932 | { |
bb5ed363 | 9933 | struct objfile *objfile = cu->objfile; |
5afb4e99 DJ |
9934 | struct dwarf2_per_cu_data *per_cu = NULL; |
9935 | struct partial_die_info *pd = NULL; | |
72bf9492 | 9936 | |
b0df02fd | 9937 | if (cu->per_cu->debug_types_section) |
348e048f DE |
9938 | { |
9939 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9940 | if (pd != NULL) | |
9941 | return pd; | |
9942 | goto not_found; | |
9943 | } | |
9944 | ||
45452591 | 9945 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
9946 | { |
9947 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9948 | if (pd != NULL) | |
9949 | return pd; | |
9950 | } | |
72bf9492 | 9951 | |
bb5ed363 | 9952 | per_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
ae038cb0 | 9953 | |
98bfdba5 | 9954 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
a0f42c21 | 9955 | load_partial_comp_unit (per_cu); |
ae038cb0 DJ |
9956 | |
9957 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
9958 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
9959 | ||
9960 | if (pd == NULL && per_cu->load_all_dies == 0) | |
9961 | { | |
9962 | struct cleanup *back_to; | |
9963 | struct partial_die_info comp_unit_die; | |
9964 | struct abbrev_info *abbrev; | |
9965 | unsigned int bytes_read; | |
9966 | char *info_ptr; | |
9967 | ||
9968 | per_cu->load_all_dies = 1; | |
9969 | ||
9970 | /* Re-read the DIEs. */ | |
9971 | back_to = make_cleanup (null_cleanup, 0); | |
9972 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
9973 | { | |
e5fe5e75 | 9974 | dwarf2_read_abbrevs (per_cu->cu); |
53d72f98 | 9975 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 9976 | } |
dce234bc | 9977 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
9978 | + per_cu->cu->header.offset |
9979 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
9980 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
9981 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
bb5ed363 | 9982 | objfile->obfd, |
93311388 | 9983 | dwarf2_per_objfile->info.buffer, info_ptr, |
5afb4e99 DJ |
9984 | per_cu->cu); |
9985 | if (comp_unit_die.has_children) | |
bb5ed363 | 9986 | load_partial_dies (objfile->obfd, |
93311388 DE |
9987 | dwarf2_per_objfile->info.buffer, info_ptr, |
9988 | 0, per_cu->cu); | |
5afb4e99 DJ |
9989 | do_cleanups (back_to); |
9990 | ||
9991 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
9992 | } | |
9993 | ||
348e048f DE |
9994 | not_found: |
9995 | ||
5afb4e99 DJ |
9996 | if (pd == NULL) |
9997 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
9998 | _("could not find partial DIE 0x%x " |
9999 | "in cache [from module %s]\n"), | |
bb5ed363 | 10000 | offset, bfd_get_filename (objfile->obfd)); |
5afb4e99 | 10001 | return pd; |
72bf9492 DJ |
10002 | } |
10003 | ||
abc72ce4 DE |
10004 | /* See if we can figure out if the class lives in a namespace. We do |
10005 | this by looking for a member function; its demangled name will | |
10006 | contain namespace info, if there is any. */ | |
10007 | ||
10008 | static void | |
10009 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
10010 | struct dwarf2_cu *cu) | |
10011 | { | |
10012 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
10013 | what template types look like, because the demangler | |
10014 | frequently doesn't give the same name as the debug info. We | |
10015 | could fix this by only using the demangled name to get the | |
10016 | prefix (but see comment in read_structure_type). */ | |
10017 | ||
10018 | struct partial_die_info *real_pdi; | |
10019 | struct partial_die_info *child_pdi; | |
10020 | ||
10021 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
10022 | we should not do this. We'll prepend the parent's fully qualified | |
10023 | name when we create the partial symbol. */ | |
10024 | ||
10025 | real_pdi = struct_pdi; | |
10026 | while (real_pdi->has_specification) | |
10027 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |
10028 | ||
10029 | if (real_pdi->die_parent != NULL) | |
10030 | return; | |
10031 | ||
10032 | for (child_pdi = struct_pdi->die_child; | |
10033 | child_pdi != NULL; | |
10034 | child_pdi = child_pdi->die_sibling) | |
10035 | { | |
10036 | if (child_pdi->tag == DW_TAG_subprogram | |
10037 | && child_pdi->linkage_name != NULL) | |
10038 | { | |
10039 | char *actual_class_name | |
10040 | = language_class_name_from_physname (cu->language_defn, | |
10041 | child_pdi->linkage_name); | |
10042 | if (actual_class_name != NULL) | |
10043 | { | |
10044 | struct_pdi->name | |
10045 | = obsavestring (actual_class_name, | |
10046 | strlen (actual_class_name), | |
10047 | &cu->objfile->objfile_obstack); | |
10048 | xfree (actual_class_name); | |
10049 | } | |
10050 | break; | |
10051 | } | |
10052 | } | |
10053 | } | |
10054 | ||
72bf9492 DJ |
10055 | /* Adjust PART_DIE before generating a symbol for it. This function |
10056 | may set the is_external flag or change the DIE's name. */ | |
10057 | ||
10058 | static void | |
10059 | fixup_partial_die (struct partial_die_info *part_die, | |
10060 | struct dwarf2_cu *cu) | |
10061 | { | |
abc72ce4 DE |
10062 | /* Once we've fixed up a die, there's no point in doing so again. |
10063 | This also avoids a memory leak if we were to call | |
10064 | guess_partial_die_structure_name multiple times. */ | |
10065 | if (part_die->fixup_called) | |
10066 | return; | |
10067 | ||
72bf9492 DJ |
10068 | /* If we found a reference attribute and the DIE has no name, try |
10069 | to find a name in the referred to DIE. */ | |
10070 | ||
10071 | if (part_die->name == NULL && part_die->has_specification) | |
10072 | { | |
10073 | struct partial_die_info *spec_die; | |
72bf9492 | 10074 | |
10b3939b | 10075 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 10076 | |
10b3939b | 10077 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
10078 | |
10079 | if (spec_die->name) | |
10080 | { | |
10081 | part_die->name = spec_die->name; | |
10082 | ||
10083 | /* Copy DW_AT_external attribute if it is set. */ | |
10084 | if (spec_die->is_external) | |
10085 | part_die->is_external = spec_die->is_external; | |
10086 | } | |
10087 | } | |
10088 | ||
10089 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
10090 | |
10091 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 10092 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 10093 | |
abc72ce4 DE |
10094 | /* If there is no parent die to provide a namespace, and there are |
10095 | children, see if we can determine the namespace from their linkage | |
122d1940 | 10096 | name. */ |
abc72ce4 | 10097 | if (cu->language == language_cplus |
8b70b953 | 10098 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
10099 | && part_die->die_parent == NULL |
10100 | && part_die->has_children | |
10101 | && (part_die->tag == DW_TAG_class_type | |
10102 | || part_die->tag == DW_TAG_structure_type | |
10103 | || part_die->tag == DW_TAG_union_type)) | |
10104 | guess_partial_die_structure_name (part_die, cu); | |
10105 | ||
53832f31 TT |
10106 | /* GCC might emit a nameless struct or union that has a linkage |
10107 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
10108 | if (part_die->name == NULL | |
96408a79 SA |
10109 | && (part_die->tag == DW_TAG_class_type |
10110 | || part_die->tag == DW_TAG_interface_type | |
10111 | || part_die->tag == DW_TAG_structure_type | |
10112 | || part_die->tag == DW_TAG_union_type) | |
53832f31 TT |
10113 | && part_die->linkage_name != NULL) |
10114 | { | |
10115 | char *demangled; | |
10116 | ||
10117 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
10118 | if (demangled) | |
10119 | { | |
96408a79 SA |
10120 | const char *base; |
10121 | ||
10122 | /* Strip any leading namespaces/classes, keep only the base name. | |
10123 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
10124 | base = strrchr (demangled, ':'); | |
10125 | if (base && base > demangled && base[-1] == ':') | |
10126 | base++; | |
10127 | else | |
10128 | base = demangled; | |
10129 | ||
10130 | part_die->name = obsavestring (base, strlen (base), | |
53832f31 TT |
10131 | &cu->objfile->objfile_obstack); |
10132 | xfree (demangled); | |
10133 | } | |
10134 | } | |
10135 | ||
abc72ce4 | 10136 | part_die->fixup_called = 1; |
72bf9492 DJ |
10137 | } |
10138 | ||
a8329558 | 10139 | /* Read an attribute value described by an attribute form. */ |
c906108c | 10140 | |
fe1b8b76 | 10141 | static gdb_byte * |
a8329558 | 10142 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 10143 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 10144 | struct dwarf2_cu *cu) |
c906108c | 10145 | { |
e7c27a73 | 10146 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10147 | unsigned int bytes_read; |
10148 | struct dwarf_block *blk; | |
10149 | ||
a8329558 KW |
10150 | attr->form = form; |
10151 | switch (form) | |
c906108c | 10152 | { |
c906108c | 10153 | case DW_FORM_ref_addr: |
ae411497 TT |
10154 | if (cu->header.version == 2) |
10155 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
10156 | else | |
3e43a32a MS |
10157 | DW_ADDR (attr) = read_offset (abfd, info_ptr, |
10158 | &cu->header, &bytes_read); | |
ae411497 TT |
10159 | info_ptr += bytes_read; |
10160 | break; | |
10161 | case DW_FORM_addr: | |
e7c27a73 | 10162 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 10163 | info_ptr += bytes_read; |
c906108c SS |
10164 | break; |
10165 | case DW_FORM_block2: | |
7b5a2f43 | 10166 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10167 | blk->size = read_2_bytes (abfd, info_ptr); |
10168 | info_ptr += 2; | |
10169 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10170 | info_ptr += blk->size; | |
10171 | DW_BLOCK (attr) = blk; | |
10172 | break; | |
10173 | case DW_FORM_block4: | |
7b5a2f43 | 10174 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10175 | blk->size = read_4_bytes (abfd, info_ptr); |
10176 | info_ptr += 4; | |
10177 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10178 | info_ptr += blk->size; | |
10179 | DW_BLOCK (attr) = blk; | |
10180 | break; | |
10181 | case DW_FORM_data2: | |
10182 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
10183 | info_ptr += 2; | |
10184 | break; | |
10185 | case DW_FORM_data4: | |
10186 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
10187 | info_ptr += 4; | |
10188 | break; | |
10189 | case DW_FORM_data8: | |
10190 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
10191 | info_ptr += 8; | |
10192 | break; | |
2dc7f7b3 TT |
10193 | case DW_FORM_sec_offset: |
10194 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
10195 | info_ptr += bytes_read; | |
10196 | break; | |
c906108c | 10197 | case DW_FORM_string: |
9b1c24c8 | 10198 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 10199 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
10200 | info_ptr += bytes_read; |
10201 | break; | |
4bdf3d34 JJ |
10202 | case DW_FORM_strp: |
10203 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
10204 | &bytes_read); | |
8285870a | 10205 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
10206 | info_ptr += bytes_read; |
10207 | break; | |
2dc7f7b3 | 10208 | case DW_FORM_exprloc: |
c906108c | 10209 | case DW_FORM_block: |
7b5a2f43 | 10210 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10211 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10212 | info_ptr += bytes_read; | |
10213 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10214 | info_ptr += blk->size; | |
10215 | DW_BLOCK (attr) = blk; | |
10216 | break; | |
10217 | case DW_FORM_block1: | |
7b5a2f43 | 10218 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10219 | blk->size = read_1_byte (abfd, info_ptr); |
10220 | info_ptr += 1; | |
10221 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10222 | info_ptr += blk->size; | |
10223 | DW_BLOCK (attr) = blk; | |
10224 | break; | |
10225 | case DW_FORM_data1: | |
10226 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10227 | info_ptr += 1; | |
10228 | break; | |
10229 | case DW_FORM_flag: | |
10230 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10231 | info_ptr += 1; | |
10232 | break; | |
2dc7f7b3 TT |
10233 | case DW_FORM_flag_present: |
10234 | DW_UNSND (attr) = 1; | |
10235 | break; | |
c906108c SS |
10236 | case DW_FORM_sdata: |
10237 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
10238 | info_ptr += bytes_read; | |
10239 | break; | |
10240 | case DW_FORM_udata: | |
10241 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
10242 | info_ptr += bytes_read; | |
10243 | break; | |
10244 | case DW_FORM_ref1: | |
10b3939b | 10245 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
10246 | info_ptr += 1; |
10247 | break; | |
10248 | case DW_FORM_ref2: | |
10b3939b | 10249 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
10250 | info_ptr += 2; |
10251 | break; | |
10252 | case DW_FORM_ref4: | |
10b3939b | 10253 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
10254 | info_ptr += 4; |
10255 | break; | |
613e1657 | 10256 | case DW_FORM_ref8: |
10b3939b | 10257 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
10258 | info_ptr += 8; |
10259 | break; | |
55f1336d | 10260 | case DW_FORM_ref_sig8: |
348e048f DE |
10261 | /* Convert the signature to something we can record in DW_UNSND |
10262 | for later lookup. | |
10263 | NOTE: This is NULL if the type wasn't found. */ | |
10264 | DW_SIGNATURED_TYPE (attr) = | |
10265 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
10266 | info_ptr += 8; | |
10267 | break; | |
c906108c | 10268 | case DW_FORM_ref_udata: |
10b3939b DJ |
10269 | DW_ADDR (attr) = (cu->header.offset |
10270 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
10271 | info_ptr += bytes_read; |
10272 | break; | |
c906108c | 10273 | case DW_FORM_indirect: |
a8329558 KW |
10274 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10275 | info_ptr += bytes_read; | |
e7c27a73 | 10276 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 10277 | break; |
c906108c | 10278 | default: |
8a3fe4f8 | 10279 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
10280 | dwarf_form_name (form), |
10281 | bfd_get_filename (abfd)); | |
c906108c | 10282 | } |
28e94949 JB |
10283 | |
10284 | /* We have seen instances where the compiler tried to emit a byte | |
10285 | size attribute of -1 which ended up being encoded as an unsigned | |
10286 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
10287 | an object of this size seems pretty unlikely so we can relatively | |
10288 | safely treat these cases as if the size attribute was invalid and | |
10289 | treat them as zero by default. */ | |
10290 | if (attr->name == DW_AT_byte_size | |
10291 | && form == DW_FORM_data4 | |
10292 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
10293 | { |
10294 | complaint | |
10295 | (&symfile_complaints, | |
43bbcdc2 PH |
10296 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
10297 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
10298 | DW_UNSND (attr) = 0; |
10299 | } | |
28e94949 | 10300 | |
c906108c SS |
10301 | return info_ptr; |
10302 | } | |
10303 | ||
a8329558 KW |
10304 | /* Read an attribute described by an abbreviated attribute. */ |
10305 | ||
fe1b8b76 | 10306 | static gdb_byte * |
a8329558 | 10307 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 10308 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
10309 | { |
10310 | attr->name = abbrev->name; | |
e7c27a73 | 10311 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
10312 | } |
10313 | ||
0963b4bd | 10314 | /* Read dwarf information from a buffer. */ |
c906108c SS |
10315 | |
10316 | static unsigned int | |
fe1b8b76 | 10317 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10318 | { |
fe1b8b76 | 10319 | return bfd_get_8 (abfd, buf); |
c906108c SS |
10320 | } |
10321 | ||
10322 | static int | |
fe1b8b76 | 10323 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10324 | { |
fe1b8b76 | 10325 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
10326 | } |
10327 | ||
10328 | static unsigned int | |
fe1b8b76 | 10329 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10330 | { |
fe1b8b76 | 10331 | return bfd_get_16 (abfd, buf); |
c906108c SS |
10332 | } |
10333 | ||
21ae7a4d JK |
10334 | static int |
10335 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) | |
10336 | { | |
10337 | return bfd_get_signed_16 (abfd, buf); | |
10338 | } | |
10339 | ||
c906108c | 10340 | static unsigned int |
fe1b8b76 | 10341 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10342 | { |
fe1b8b76 | 10343 | return bfd_get_32 (abfd, buf); |
c906108c SS |
10344 | } |
10345 | ||
21ae7a4d JK |
10346 | static int |
10347 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) | |
10348 | { | |
10349 | return bfd_get_signed_32 (abfd, buf); | |
10350 | } | |
10351 | ||
93311388 | 10352 | static ULONGEST |
fe1b8b76 | 10353 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10354 | { |
fe1b8b76 | 10355 | return bfd_get_64 (abfd, buf); |
c906108c SS |
10356 | } |
10357 | ||
10358 | static CORE_ADDR | |
fe1b8b76 | 10359 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 10360 | unsigned int *bytes_read) |
c906108c | 10361 | { |
e7c27a73 | 10362 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10363 | CORE_ADDR retval = 0; |
10364 | ||
107d2387 | 10365 | if (cu_header->signed_addr_p) |
c906108c | 10366 | { |
107d2387 AC |
10367 | switch (cu_header->addr_size) |
10368 | { | |
10369 | case 2: | |
fe1b8b76 | 10370 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
10371 | break; |
10372 | case 4: | |
fe1b8b76 | 10373 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
10374 | break; |
10375 | case 8: | |
fe1b8b76 | 10376 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
10377 | break; |
10378 | default: | |
8e65ff28 | 10379 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 10380 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 10381 | bfd_get_filename (abfd)); |
107d2387 AC |
10382 | } |
10383 | } | |
10384 | else | |
10385 | { | |
10386 | switch (cu_header->addr_size) | |
10387 | { | |
10388 | case 2: | |
fe1b8b76 | 10389 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
10390 | break; |
10391 | case 4: | |
fe1b8b76 | 10392 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
10393 | break; |
10394 | case 8: | |
fe1b8b76 | 10395 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
10396 | break; |
10397 | default: | |
8e65ff28 | 10398 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
10399 | _("read_address: bad switch, " |
10400 | "unsigned [in module %s]"), | |
659b0389 | 10401 | bfd_get_filename (abfd)); |
107d2387 | 10402 | } |
c906108c | 10403 | } |
64367e0a | 10404 | |
107d2387 AC |
10405 | *bytes_read = cu_header->addr_size; |
10406 | return retval; | |
c906108c SS |
10407 | } |
10408 | ||
f7ef9339 | 10409 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
10410 | specification allows the initial length to take up either 4 bytes |
10411 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
10412 | bytes describe the length and all offsets will be 8 bytes in length | |
10413 | instead of 4. | |
10414 | ||
f7ef9339 KB |
10415 | An older, non-standard 64-bit format is also handled by this |
10416 | function. The older format in question stores the initial length | |
10417 | as an 8-byte quantity without an escape value. Lengths greater | |
10418 | than 2^32 aren't very common which means that the initial 4 bytes | |
10419 | is almost always zero. Since a length value of zero doesn't make | |
10420 | sense for the 32-bit format, this initial zero can be considered to | |
10421 | be an escape value which indicates the presence of the older 64-bit | |
10422 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
10423 | greater than 4GB. If it becomes necessary to handle lengths |
10424 | somewhat larger than 4GB, we could allow other small values (such | |
10425 | as the non-sensical values of 1, 2, and 3) to also be used as | |
10426 | escape values indicating the presence of the old format. | |
f7ef9339 | 10427 | |
917c78fc MK |
10428 | The value returned via bytes_read should be used to increment the |
10429 | relevant pointer after calling read_initial_length(). | |
c764a876 | 10430 | |
613e1657 KB |
10431 | [ Note: read_initial_length() and read_offset() are based on the |
10432 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 10433 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
10434 | from: |
10435 | ||
f7ef9339 | 10436 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 10437 | |
613e1657 KB |
10438 | This document is only a draft and is subject to change. (So beware.) |
10439 | ||
f7ef9339 | 10440 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
10441 | determined empirically by examining 64-bit ELF files produced by |
10442 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
10443 | |
10444 | - Kevin, July 16, 2002 | |
613e1657 KB |
10445 | ] */ |
10446 | ||
10447 | static LONGEST | |
c764a876 | 10448 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 10449 | { |
fe1b8b76 | 10450 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 10451 | |
dd373385 | 10452 | if (length == 0xffffffff) |
613e1657 | 10453 | { |
fe1b8b76 | 10454 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 10455 | *bytes_read = 12; |
613e1657 | 10456 | } |
dd373385 | 10457 | else if (length == 0) |
f7ef9339 | 10458 | { |
dd373385 | 10459 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 10460 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 10461 | *bytes_read = 8; |
f7ef9339 | 10462 | } |
613e1657 KB |
10463 | else |
10464 | { | |
10465 | *bytes_read = 4; | |
613e1657 KB |
10466 | } |
10467 | ||
c764a876 DE |
10468 | return length; |
10469 | } | |
dd373385 | 10470 | |
c764a876 DE |
10471 | /* Cover function for read_initial_length. |
10472 | Returns the length of the object at BUF, and stores the size of the | |
10473 | initial length in *BYTES_READ and stores the size that offsets will be in | |
10474 | *OFFSET_SIZE. | |
10475 | If the initial length size is not equivalent to that specified in | |
10476 | CU_HEADER then issue a complaint. | |
10477 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 10478 | |
c764a876 DE |
10479 | static LONGEST |
10480 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
10481 | const struct comp_unit_head *cu_header, | |
10482 | unsigned int *bytes_read, | |
10483 | unsigned int *offset_size) | |
10484 | { | |
10485 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
10486 | ||
10487 | gdb_assert (cu_header->initial_length_size == 4 | |
10488 | || cu_header->initial_length_size == 8 | |
10489 | || cu_header->initial_length_size == 12); | |
10490 | ||
10491 | if (cu_header->initial_length_size != *bytes_read) | |
10492 | complaint (&symfile_complaints, | |
10493 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 10494 | |
c764a876 | 10495 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 10496 | return length; |
613e1657 KB |
10497 | } |
10498 | ||
10499 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 10500 | given by cu_header->offset_size. */ |
613e1657 KB |
10501 | |
10502 | static LONGEST | |
fe1b8b76 | 10503 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 10504 | unsigned int *bytes_read) |
c764a876 DE |
10505 | { |
10506 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 10507 | |
c764a876 DE |
10508 | *bytes_read = cu_header->offset_size; |
10509 | return offset; | |
10510 | } | |
10511 | ||
10512 | /* Read an offset from the data stream. */ | |
10513 | ||
10514 | static LONGEST | |
10515 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
10516 | { |
10517 | LONGEST retval = 0; | |
10518 | ||
c764a876 | 10519 | switch (offset_size) |
613e1657 KB |
10520 | { |
10521 | case 4: | |
fe1b8b76 | 10522 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
10523 | break; |
10524 | case 8: | |
fe1b8b76 | 10525 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
10526 | break; |
10527 | default: | |
8e65ff28 | 10528 | internal_error (__FILE__, __LINE__, |
c764a876 | 10529 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 10530 | bfd_get_filename (abfd)); |
613e1657 KB |
10531 | } |
10532 | ||
917c78fc | 10533 | return retval; |
613e1657 KB |
10534 | } |
10535 | ||
fe1b8b76 JB |
10536 | static gdb_byte * |
10537 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
10538 | { |
10539 | /* If the size of a host char is 8 bits, we can return a pointer | |
10540 | to the buffer, otherwise we have to copy the data to a buffer | |
10541 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10542 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 10543 | return buf; |
c906108c SS |
10544 | } |
10545 | ||
10546 | static char * | |
9b1c24c8 | 10547 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
10548 | { |
10549 | /* If the size of a host char is 8 bits, we can return a pointer | |
10550 | to the string, otherwise we have to copy the string to a buffer | |
10551 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10552 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
10553 | if (*buf == '\0') |
10554 | { | |
10555 | *bytes_read_ptr = 1; | |
10556 | return NULL; | |
10557 | } | |
fe1b8b76 JB |
10558 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
10559 | return (char *) buf; | |
4bdf3d34 JJ |
10560 | } |
10561 | ||
10562 | static char * | |
cf2c3c16 | 10563 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
4bdf3d34 | 10564 | { |
be391dca | 10565 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 10566 | if (dwarf2_per_objfile->str.buffer == NULL) |
cf2c3c16 TT |
10567 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
10568 | bfd_get_filename (abfd)); | |
dce234bc | 10569 | if (str_offset >= dwarf2_per_objfile->str.size) |
cf2c3c16 TT |
10570 | error (_("DW_FORM_strp pointing outside of " |
10571 | ".debug_str section [in module %s]"), | |
10572 | bfd_get_filename (abfd)); | |
4bdf3d34 | 10573 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 10574 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 10575 | return NULL; |
dce234bc | 10576 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
10577 | } |
10578 | ||
cf2c3c16 TT |
10579 | static char * |
10580 | read_indirect_string (bfd *abfd, gdb_byte *buf, | |
10581 | const struct comp_unit_head *cu_header, | |
10582 | unsigned int *bytes_read_ptr) | |
10583 | { | |
10584 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
10585 | ||
10586 | return read_indirect_string_at_offset (abfd, str_offset); | |
10587 | } | |
10588 | ||
ce5d95e1 | 10589 | static unsigned long |
fe1b8b76 | 10590 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10591 | { |
ce5d95e1 JB |
10592 | unsigned long result; |
10593 | unsigned int num_read; | |
c906108c SS |
10594 | int i, shift; |
10595 | unsigned char byte; | |
10596 | ||
10597 | result = 0; | |
10598 | shift = 0; | |
10599 | num_read = 0; | |
10600 | i = 0; | |
10601 | while (1) | |
10602 | { | |
fe1b8b76 | 10603 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10604 | buf++; |
10605 | num_read++; | |
ce5d95e1 | 10606 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
10607 | if ((byte & 128) == 0) |
10608 | { | |
10609 | break; | |
10610 | } | |
10611 | shift += 7; | |
10612 | } | |
10613 | *bytes_read_ptr = num_read; | |
10614 | return result; | |
10615 | } | |
10616 | ||
ce5d95e1 | 10617 | static long |
fe1b8b76 | 10618 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10619 | { |
ce5d95e1 | 10620 | long result; |
77e0b926 | 10621 | int i, shift, num_read; |
c906108c SS |
10622 | unsigned char byte; |
10623 | ||
10624 | result = 0; | |
10625 | shift = 0; | |
c906108c SS |
10626 | num_read = 0; |
10627 | i = 0; | |
10628 | while (1) | |
10629 | { | |
fe1b8b76 | 10630 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10631 | buf++; |
10632 | num_read++; | |
ce5d95e1 | 10633 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
10634 | shift += 7; |
10635 | if ((byte & 128) == 0) | |
10636 | { | |
10637 | break; | |
10638 | } | |
10639 | } | |
77e0b926 DJ |
10640 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
10641 | result |= -(((long)1) << shift); | |
c906108c SS |
10642 | *bytes_read_ptr = num_read; |
10643 | return result; | |
10644 | } | |
10645 | ||
4bb7a0a7 DJ |
10646 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
10647 | ||
fe1b8b76 JB |
10648 | static gdb_byte * |
10649 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
10650 | { |
10651 | int byte; | |
10652 | ||
10653 | while (1) | |
10654 | { | |
fe1b8b76 | 10655 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
10656 | buf++; |
10657 | if ((byte & 128) == 0) | |
10658 | return buf; | |
10659 | } | |
10660 | } | |
10661 | ||
c906108c | 10662 | static void |
e142c38c | 10663 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
10664 | { |
10665 | switch (lang) | |
10666 | { | |
10667 | case DW_LANG_C89: | |
76bee0cc | 10668 | case DW_LANG_C99: |
c906108c | 10669 | case DW_LANG_C: |
e142c38c | 10670 | cu->language = language_c; |
c906108c SS |
10671 | break; |
10672 | case DW_LANG_C_plus_plus: | |
e142c38c | 10673 | cu->language = language_cplus; |
c906108c | 10674 | break; |
6aecb9c2 JB |
10675 | case DW_LANG_D: |
10676 | cu->language = language_d; | |
10677 | break; | |
c906108c SS |
10678 | case DW_LANG_Fortran77: |
10679 | case DW_LANG_Fortran90: | |
b21b22e0 | 10680 | case DW_LANG_Fortran95: |
e142c38c | 10681 | cu->language = language_fortran; |
c906108c SS |
10682 | break; |
10683 | case DW_LANG_Mips_Assembler: | |
e142c38c | 10684 | cu->language = language_asm; |
c906108c | 10685 | break; |
bebd888e | 10686 | case DW_LANG_Java: |
e142c38c | 10687 | cu->language = language_java; |
bebd888e | 10688 | break; |
c906108c | 10689 | case DW_LANG_Ada83: |
8aaf0b47 | 10690 | case DW_LANG_Ada95: |
bc5f45f8 JB |
10691 | cu->language = language_ada; |
10692 | break; | |
72019c9c GM |
10693 | case DW_LANG_Modula2: |
10694 | cu->language = language_m2; | |
10695 | break; | |
fe8e67fd PM |
10696 | case DW_LANG_Pascal83: |
10697 | cu->language = language_pascal; | |
10698 | break; | |
22566fbd DJ |
10699 | case DW_LANG_ObjC: |
10700 | cu->language = language_objc; | |
10701 | break; | |
c906108c SS |
10702 | case DW_LANG_Cobol74: |
10703 | case DW_LANG_Cobol85: | |
c906108c | 10704 | default: |
e142c38c | 10705 | cu->language = language_minimal; |
c906108c SS |
10706 | break; |
10707 | } | |
e142c38c | 10708 | cu->language_defn = language_def (cu->language); |
c906108c SS |
10709 | } |
10710 | ||
10711 | /* Return the named attribute or NULL if not there. */ | |
10712 | ||
10713 | static struct attribute * | |
e142c38c | 10714 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
10715 | { |
10716 | unsigned int i; | |
10717 | struct attribute *spec = NULL; | |
10718 | ||
10719 | for (i = 0; i < die->num_attrs; ++i) | |
10720 | { | |
10721 | if (die->attrs[i].name == name) | |
10b3939b | 10722 | return &die->attrs[i]; |
c906108c SS |
10723 | if (die->attrs[i].name == DW_AT_specification |
10724 | || die->attrs[i].name == DW_AT_abstract_origin) | |
10725 | spec = &die->attrs[i]; | |
10726 | } | |
c906108c | 10727 | |
10b3939b | 10728 | if (spec) |
f2f0e013 DJ |
10729 | { |
10730 | die = follow_die_ref (die, spec, &cu); | |
10731 | return dwarf2_attr (die, name, cu); | |
10732 | } | |
c5aa993b | 10733 | |
c906108c SS |
10734 | return NULL; |
10735 | } | |
10736 | ||
348e048f DE |
10737 | /* Return the named attribute or NULL if not there, |
10738 | but do not follow DW_AT_specification, etc. | |
10739 | This is for use in contexts where we're reading .debug_types dies. | |
10740 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
10741 | back up the chain, and we want to go down. */ | |
10742 | ||
10743 | static struct attribute * | |
10744 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
10745 | struct dwarf2_cu *cu) | |
10746 | { | |
10747 | unsigned int i; | |
10748 | ||
10749 | for (i = 0; i < die->num_attrs; ++i) | |
10750 | if (die->attrs[i].name == name) | |
10751 | return &die->attrs[i]; | |
10752 | ||
10753 | return NULL; | |
10754 | } | |
10755 | ||
05cf31d1 JB |
10756 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
10757 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 10758 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
10759 | |
10760 | static int | |
10761 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
10762 | { | |
10763 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
10764 | ||
10765 | return (attr && DW_UNSND (attr)); | |
10766 | } | |
10767 | ||
3ca72b44 | 10768 | static int |
e142c38c | 10769 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 10770 | { |
05cf31d1 JB |
10771 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
10772 | which value is non-zero. However, we have to be careful with | |
10773 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
10774 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
10775 | end up accidently finding a declaration attribute that belongs | |
10776 | to a different DIE referenced by the specification attribute, | |
10777 | even though the given DIE does not have a declaration attribute. */ | |
10778 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
10779 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
10780 | } |
10781 | ||
63d06c5c | 10782 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 10783 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
10784 | containing the return value on output. If there is no |
10785 | specification, but there is an abstract origin, that is | |
10786 | returned. */ | |
63d06c5c DC |
10787 | |
10788 | static struct die_info * | |
f2f0e013 | 10789 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 10790 | { |
f2f0e013 DJ |
10791 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
10792 | *spec_cu); | |
63d06c5c | 10793 | |
edb3359d DJ |
10794 | if (spec_attr == NULL) |
10795 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
10796 | ||
63d06c5c DC |
10797 | if (spec_attr == NULL) |
10798 | return NULL; | |
10799 | else | |
f2f0e013 | 10800 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 10801 | } |
c906108c | 10802 | |
debd256d | 10803 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
10804 | refers to. |
10805 | NOTE: This is also used as a "cleanup" function. */ | |
10806 | ||
debd256d JB |
10807 | static void |
10808 | free_line_header (struct line_header *lh) | |
10809 | { | |
10810 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 10811 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
10812 | |
10813 | /* Remember that all the lh->file_names[i].name pointers are | |
10814 | pointers into debug_line_buffer, and don't need to be freed. */ | |
10815 | if (lh->file_names) | |
a8bc7b56 | 10816 | xfree (lh->file_names); |
debd256d JB |
10817 | |
10818 | /* Similarly for the include directory names. */ | |
10819 | if (lh->include_dirs) | |
a8bc7b56 | 10820 | xfree (lh->include_dirs); |
debd256d | 10821 | |
a8bc7b56 | 10822 | xfree (lh); |
debd256d JB |
10823 | } |
10824 | ||
debd256d | 10825 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 10826 | |
debd256d JB |
10827 | static void |
10828 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 10829 | { |
debd256d JB |
10830 | /* Grow the array if necessary. */ |
10831 | if (lh->include_dirs_size == 0) | |
c5aa993b | 10832 | { |
debd256d JB |
10833 | lh->include_dirs_size = 1; /* for testing */ |
10834 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
10835 | * sizeof (*lh->include_dirs)); | |
10836 | } | |
10837 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
10838 | { | |
10839 | lh->include_dirs_size *= 2; | |
10840 | lh->include_dirs = xrealloc (lh->include_dirs, | |
10841 | (lh->include_dirs_size | |
10842 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 10843 | } |
c906108c | 10844 | |
debd256d JB |
10845 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
10846 | } | |
6e70227d | 10847 | |
debd256d | 10848 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 10849 | |
debd256d JB |
10850 | static void |
10851 | add_file_name (struct line_header *lh, | |
10852 | char *name, | |
10853 | unsigned int dir_index, | |
10854 | unsigned int mod_time, | |
10855 | unsigned int length) | |
10856 | { | |
10857 | struct file_entry *fe; | |
10858 | ||
10859 | /* Grow the array if necessary. */ | |
10860 | if (lh->file_names_size == 0) | |
10861 | { | |
10862 | lh->file_names_size = 1; /* for testing */ | |
10863 | lh->file_names = xmalloc (lh->file_names_size | |
10864 | * sizeof (*lh->file_names)); | |
10865 | } | |
10866 | else if (lh->num_file_names >= lh->file_names_size) | |
10867 | { | |
10868 | lh->file_names_size *= 2; | |
10869 | lh->file_names = xrealloc (lh->file_names, | |
10870 | (lh->file_names_size | |
10871 | * sizeof (*lh->file_names))); | |
10872 | } | |
10873 | ||
10874 | fe = &lh->file_names[lh->num_file_names++]; | |
10875 | fe->name = name; | |
10876 | fe->dir_index = dir_index; | |
10877 | fe->mod_time = mod_time; | |
10878 | fe->length = length; | |
aaa75496 | 10879 | fe->included_p = 0; |
cb1df416 | 10880 | fe->symtab = NULL; |
debd256d | 10881 | } |
6e70227d | 10882 | |
debd256d | 10883 | /* Read the statement program header starting at OFFSET in |
6502dd73 DJ |
10884 | .debug_line, according to the endianness of ABFD. Return a pointer |
10885 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
10886 | |
10887 | NOTE: the strings in the include directory and file name tables of | |
10888 | the returned object point into debug_line_buffer, and must not be | |
10889 | freed. */ | |
ae2de4f8 | 10890 | |
debd256d JB |
10891 | static struct line_header * |
10892 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 10893 | struct dwarf2_cu *cu) |
debd256d JB |
10894 | { |
10895 | struct cleanup *back_to; | |
10896 | struct line_header *lh; | |
fe1b8b76 | 10897 | gdb_byte *line_ptr; |
c764a876 | 10898 | unsigned int bytes_read, offset_size; |
debd256d JB |
10899 | int i; |
10900 | char *cur_dir, *cur_file; | |
10901 | ||
be391dca | 10902 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 10903 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 10904 | { |
e2e0b3e5 | 10905 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
10906 | return 0; |
10907 | } | |
10908 | ||
a738430d MK |
10909 | /* Make sure that at least there's room for the total_length field. |
10910 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 10911 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 10912 | { |
4d3c2250 | 10913 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10914 | return 0; |
10915 | } | |
10916 | ||
10917 | lh = xmalloc (sizeof (*lh)); | |
10918 | memset (lh, 0, sizeof (*lh)); | |
10919 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
10920 | (void *) lh); | |
10921 | ||
dce234bc | 10922 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 10923 | |
a738430d | 10924 | /* Read in the header. */ |
6e70227d | 10925 | lh->total_length = |
c764a876 DE |
10926 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
10927 | &bytes_read, &offset_size); | |
debd256d | 10928 | line_ptr += bytes_read; |
dce234bc PP |
10929 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
10930 | + dwarf2_per_objfile->line.size)) | |
debd256d | 10931 | { |
4d3c2250 | 10932 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10933 | return 0; |
10934 | } | |
10935 | lh->statement_program_end = line_ptr + lh->total_length; | |
10936 | lh->version = read_2_bytes (abfd, line_ptr); | |
10937 | line_ptr += 2; | |
c764a876 DE |
10938 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
10939 | line_ptr += offset_size; | |
debd256d JB |
10940 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
10941 | line_ptr += 1; | |
2dc7f7b3 TT |
10942 | if (lh->version >= 4) |
10943 | { | |
10944 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
10945 | line_ptr += 1; | |
10946 | } | |
10947 | else | |
10948 | lh->maximum_ops_per_instruction = 1; | |
10949 | ||
10950 | if (lh->maximum_ops_per_instruction == 0) | |
10951 | { | |
10952 | lh->maximum_ops_per_instruction = 1; | |
10953 | complaint (&symfile_complaints, | |
3e43a32a MS |
10954 | _("invalid maximum_ops_per_instruction " |
10955 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
10956 | } |
10957 | ||
debd256d JB |
10958 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
10959 | line_ptr += 1; | |
10960 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
10961 | line_ptr += 1; | |
10962 | lh->line_range = read_1_byte (abfd, line_ptr); | |
10963 | line_ptr += 1; | |
10964 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
10965 | line_ptr += 1; | |
10966 | lh->standard_opcode_lengths | |
fe1b8b76 | 10967 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
10968 | |
10969 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
10970 | for (i = 1; i < lh->opcode_base; ++i) | |
10971 | { | |
10972 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
10973 | line_ptr += 1; | |
10974 | } | |
10975 | ||
a738430d | 10976 | /* Read directory table. */ |
9b1c24c8 | 10977 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10978 | { |
10979 | line_ptr += bytes_read; | |
10980 | add_include_dir (lh, cur_dir); | |
10981 | } | |
10982 | line_ptr += bytes_read; | |
10983 | ||
a738430d | 10984 | /* Read file name table. */ |
9b1c24c8 | 10985 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10986 | { |
10987 | unsigned int dir_index, mod_time, length; | |
10988 | ||
10989 | line_ptr += bytes_read; | |
10990 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10991 | line_ptr += bytes_read; | |
10992 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10993 | line_ptr += bytes_read; | |
10994 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10995 | line_ptr += bytes_read; | |
10996 | ||
10997 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10998 | } | |
10999 | line_ptr += bytes_read; | |
6e70227d | 11000 | lh->statement_program_start = line_ptr; |
debd256d | 11001 | |
dce234bc PP |
11002 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
11003 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 11004 | complaint (&symfile_complaints, |
3e43a32a MS |
11005 | _("line number info header doesn't " |
11006 | "fit in `.debug_line' section")); | |
debd256d JB |
11007 | |
11008 | discard_cleanups (back_to); | |
11009 | return lh; | |
11010 | } | |
c906108c | 11011 | |
c6da4cef DE |
11012 | /* Subroutine of dwarf_decode_lines to simplify it. |
11013 | Return the file name of the psymtab for included file FILE_INDEX | |
11014 | in line header LH of PST. | |
11015 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
11016 | If space for the result is malloc'd, it will be freed by a cleanup. | |
11017 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
11018 | ||
11019 | static char * | |
11020 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
11021 | const struct partial_symtab *pst, | |
11022 | const char *comp_dir) | |
11023 | { | |
11024 | const struct file_entry fe = lh->file_names [file_index]; | |
11025 | char *include_name = fe.name; | |
11026 | char *include_name_to_compare = include_name; | |
11027 | char *dir_name = NULL; | |
72b9f47f TT |
11028 | const char *pst_filename; |
11029 | char *copied_name = NULL; | |
c6da4cef DE |
11030 | int file_is_pst; |
11031 | ||
11032 | if (fe.dir_index) | |
11033 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
11034 | ||
11035 | if (!IS_ABSOLUTE_PATH (include_name) | |
11036 | && (dir_name != NULL || comp_dir != NULL)) | |
11037 | { | |
11038 | /* Avoid creating a duplicate psymtab for PST. | |
11039 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
11040 | Before we do the comparison, however, we need to account | |
11041 | for DIR_NAME and COMP_DIR. | |
11042 | First prepend dir_name (if non-NULL). If we still don't | |
11043 | have an absolute path prepend comp_dir (if non-NULL). | |
11044 | However, the directory we record in the include-file's | |
11045 | psymtab does not contain COMP_DIR (to match the | |
11046 | corresponding symtab(s)). | |
11047 | ||
11048 | Example: | |
11049 | ||
11050 | bash$ cd /tmp | |
11051 | bash$ gcc -g ./hello.c | |
11052 | include_name = "hello.c" | |
11053 | dir_name = "." | |
11054 | DW_AT_comp_dir = comp_dir = "/tmp" | |
11055 | DW_AT_name = "./hello.c" */ | |
11056 | ||
11057 | if (dir_name != NULL) | |
11058 | { | |
11059 | include_name = concat (dir_name, SLASH_STRING, | |
11060 | include_name, (char *)NULL); | |
11061 | include_name_to_compare = include_name; | |
11062 | make_cleanup (xfree, include_name); | |
11063 | } | |
11064 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
11065 | { | |
11066 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
11067 | include_name, (char *)NULL); | |
11068 | } | |
11069 | } | |
11070 | ||
11071 | pst_filename = pst->filename; | |
11072 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
11073 | { | |
72b9f47f TT |
11074 | copied_name = concat (pst->dirname, SLASH_STRING, |
11075 | pst_filename, (char *)NULL); | |
11076 | pst_filename = copied_name; | |
c6da4cef DE |
11077 | } |
11078 | ||
1e3fad37 | 11079 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
11080 | |
11081 | if (include_name_to_compare != include_name) | |
11082 | xfree (include_name_to_compare); | |
72b9f47f TT |
11083 | if (copied_name != NULL) |
11084 | xfree (copied_name); | |
c6da4cef DE |
11085 | |
11086 | if (file_is_pst) | |
11087 | return NULL; | |
11088 | return include_name; | |
11089 | } | |
11090 | ||
c91513d8 PP |
11091 | /* Ignore this record_line request. */ |
11092 | ||
11093 | static void | |
11094 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
11095 | { | |
11096 | return; | |
11097 | } | |
11098 | ||
f3f5162e DE |
11099 | /* Subroutine of dwarf_decode_lines to simplify it. |
11100 | Process the line number information in LH. */ | |
debd256d | 11101 | |
c906108c | 11102 | static void |
f3f5162e DE |
11103 | dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, |
11104 | struct dwarf2_cu *cu, struct partial_symtab *pst) | |
c906108c | 11105 | { |
a8c50c1f | 11106 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 11107 | gdb_byte *line_end; |
a8c50c1f | 11108 | unsigned int bytes_read, extended_len; |
c906108c | 11109 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
11110 | CORE_ADDR baseaddr; |
11111 | struct objfile *objfile = cu->objfile; | |
f3f5162e | 11112 | bfd *abfd = objfile->obfd; |
fbf65064 | 11113 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 11114 | const int decode_for_pst_p = (pst != NULL); |
f3f5162e | 11115 | struct subfile *last_subfile = NULL; |
c91513d8 PP |
11116 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
11117 | = record_line; | |
e142c38c DJ |
11118 | |
11119 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11120 | |
debd256d JB |
11121 | line_ptr = lh->statement_program_start; |
11122 | line_end = lh->statement_program_end; | |
c906108c SS |
11123 | |
11124 | /* Read the statement sequences until there's nothing left. */ | |
11125 | while (line_ptr < line_end) | |
11126 | { | |
11127 | /* state machine registers */ | |
11128 | CORE_ADDR address = 0; | |
11129 | unsigned int file = 1; | |
11130 | unsigned int line = 1; | |
11131 | unsigned int column = 0; | |
debd256d | 11132 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
11133 | int basic_block = 0; |
11134 | int end_sequence = 0; | |
fbf65064 | 11135 | CORE_ADDR addr; |
2dc7f7b3 | 11136 | unsigned char op_index = 0; |
c906108c | 11137 | |
aaa75496 | 11138 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 11139 | { |
aaa75496 | 11140 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
11141 | /* lh->include_dirs and lh->file_names are 0-based, but the |
11142 | directory and file name numbers in the statement program | |
11143 | are 1-based. */ | |
11144 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 11145 | char *dir = NULL; |
a738430d | 11146 | |
debd256d JB |
11147 | if (fe->dir_index) |
11148 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
11149 | |
11150 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
11151 | } |
11152 | ||
a738430d | 11153 | /* Decode the table. */ |
c5aa993b | 11154 | while (!end_sequence) |
c906108c SS |
11155 | { |
11156 | op_code = read_1_byte (abfd, line_ptr); | |
11157 | line_ptr += 1; | |
59205f5a JB |
11158 | if (line_ptr > line_end) |
11159 | { | |
11160 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
11161 | break; | |
11162 | } | |
9aa1fe7e | 11163 | |
debd256d | 11164 | if (op_code >= lh->opcode_base) |
6e70227d | 11165 | { |
a738430d | 11166 | /* Special operand. */ |
debd256d | 11167 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
11168 | address += (((op_index + (adj_opcode / lh->line_range)) |
11169 | / lh->maximum_ops_per_instruction) | |
11170 | * lh->minimum_instruction_length); | |
11171 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
11172 | % lh->maximum_ops_per_instruction); | |
debd256d | 11173 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 11174 | if (lh->num_file_names < file || file == 0) |
25e43795 | 11175 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
11176 | /* For now we ignore lines not starting on an |
11177 | instruction boundary. */ | |
11178 | else if (op_index == 0) | |
25e43795 DJ |
11179 | { |
11180 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 11181 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11182 | { |
11183 | if (last_subfile != current_subfile) | |
11184 | { | |
11185 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11186 | if (last_subfile) | |
c91513d8 | 11187 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11188 | last_subfile = current_subfile; |
11189 | } | |
25e43795 | 11190 | /* Append row to matrix using current values. */ |
7019d805 | 11191 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 11192 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 11193 | } |
25e43795 | 11194 | } |
ca5f395d | 11195 | basic_block = 0; |
9aa1fe7e GK |
11196 | } |
11197 | else switch (op_code) | |
c906108c SS |
11198 | { |
11199 | case DW_LNS_extended_op: | |
3e43a32a MS |
11200 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
11201 | &bytes_read); | |
473b7be6 | 11202 | line_ptr += bytes_read; |
a8c50c1f | 11203 | extended_end = line_ptr + extended_len; |
c906108c SS |
11204 | extended_op = read_1_byte (abfd, line_ptr); |
11205 | line_ptr += 1; | |
11206 | switch (extended_op) | |
11207 | { | |
11208 | case DW_LNE_end_sequence: | |
c91513d8 | 11209 | p_record_line = record_line; |
c906108c | 11210 | end_sequence = 1; |
c906108c SS |
11211 | break; |
11212 | case DW_LNE_set_address: | |
e7c27a73 | 11213 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
11214 | |
11215 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
11216 | { | |
11217 | /* This line table is for a function which has been | |
11218 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
11219 | ||
11220 | long line_offset | |
11221 | = line_ptr - dwarf2_per_objfile->line.buffer; | |
11222 | ||
11223 | complaint (&symfile_complaints, | |
11224 | _(".debug_line address at offset 0x%lx is 0 " | |
11225 | "[in module %s]"), | |
bb5ed363 | 11226 | line_offset, objfile->name); |
c91513d8 PP |
11227 | p_record_line = noop_record_line; |
11228 | } | |
11229 | ||
2dc7f7b3 | 11230 | op_index = 0; |
107d2387 AC |
11231 | line_ptr += bytes_read; |
11232 | address += baseaddr; | |
c906108c SS |
11233 | break; |
11234 | case DW_LNE_define_file: | |
debd256d JB |
11235 | { |
11236 | char *cur_file; | |
11237 | unsigned int dir_index, mod_time, length; | |
6e70227d | 11238 | |
3e43a32a MS |
11239 | cur_file = read_direct_string (abfd, line_ptr, |
11240 | &bytes_read); | |
debd256d JB |
11241 | line_ptr += bytes_read; |
11242 | dir_index = | |
11243 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11244 | line_ptr += bytes_read; | |
11245 | mod_time = | |
11246 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11247 | line_ptr += bytes_read; | |
11248 | length = | |
11249 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11250 | line_ptr += bytes_read; | |
11251 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
11252 | } | |
c906108c | 11253 | break; |
d0c6ba3d CC |
11254 | case DW_LNE_set_discriminator: |
11255 | /* The discriminator is not interesting to the debugger; | |
11256 | just ignore it. */ | |
11257 | line_ptr = extended_end; | |
11258 | break; | |
c906108c | 11259 | default: |
4d3c2250 | 11260 | complaint (&symfile_complaints, |
e2e0b3e5 | 11261 | _("mangled .debug_line section")); |
debd256d | 11262 | return; |
c906108c | 11263 | } |
a8c50c1f DJ |
11264 | /* Make sure that we parsed the extended op correctly. If e.g. |
11265 | we expected a different address size than the producer used, | |
11266 | we may have read the wrong number of bytes. */ | |
11267 | if (line_ptr != extended_end) | |
11268 | { | |
11269 | complaint (&symfile_complaints, | |
11270 | _("mangled .debug_line section")); | |
11271 | return; | |
11272 | } | |
c906108c SS |
11273 | break; |
11274 | case DW_LNS_copy: | |
59205f5a | 11275 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11276 | dwarf2_debug_line_missing_file_complaint (); |
11277 | else | |
366da635 | 11278 | { |
25e43795 | 11279 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 11280 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11281 | { |
11282 | if (last_subfile != current_subfile) | |
11283 | { | |
11284 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11285 | if (last_subfile) | |
c91513d8 | 11286 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11287 | last_subfile = current_subfile; |
11288 | } | |
7019d805 | 11289 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 11290 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 11291 | } |
366da635 | 11292 | } |
c906108c SS |
11293 | basic_block = 0; |
11294 | break; | |
11295 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
11296 | { |
11297 | CORE_ADDR adjust | |
11298 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11299 | ||
11300 | address += (((op_index + adjust) | |
11301 | / lh->maximum_ops_per_instruction) | |
11302 | * lh->minimum_instruction_length); | |
11303 | op_index = ((op_index + adjust) | |
11304 | % lh->maximum_ops_per_instruction); | |
11305 | line_ptr += bytes_read; | |
11306 | } | |
c906108c SS |
11307 | break; |
11308 | case DW_LNS_advance_line: | |
11309 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
11310 | line_ptr += bytes_read; | |
11311 | break; | |
11312 | case DW_LNS_set_file: | |
debd256d | 11313 | { |
a738430d MK |
11314 | /* The arrays lh->include_dirs and lh->file_names are |
11315 | 0-based, but the directory and file name numbers in | |
11316 | the statement program are 1-based. */ | |
debd256d | 11317 | struct file_entry *fe; |
4f1520fb | 11318 | char *dir = NULL; |
a738430d | 11319 | |
debd256d JB |
11320 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
11321 | line_ptr += bytes_read; | |
59205f5a | 11322 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11323 | dwarf2_debug_line_missing_file_complaint (); |
11324 | else | |
11325 | { | |
11326 | fe = &lh->file_names[file - 1]; | |
11327 | if (fe->dir_index) | |
11328 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11329 | if (!decode_for_pst_p) | |
11330 | { | |
11331 | last_subfile = current_subfile; | |
11332 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11333 | } | |
11334 | } | |
debd256d | 11335 | } |
c906108c SS |
11336 | break; |
11337 | case DW_LNS_set_column: | |
11338 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11339 | line_ptr += bytes_read; | |
11340 | break; | |
11341 | case DW_LNS_negate_stmt: | |
11342 | is_stmt = (!is_stmt); | |
11343 | break; | |
11344 | case DW_LNS_set_basic_block: | |
11345 | basic_block = 1; | |
11346 | break; | |
c2c6d25f JM |
11347 | /* Add to the address register of the state machine the |
11348 | address increment value corresponding to special opcode | |
a738430d MK |
11349 | 255. I.e., this value is scaled by the minimum |
11350 | instruction length since special opcode 255 would have | |
b021a221 | 11351 | scaled the increment. */ |
c906108c | 11352 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
11353 | { |
11354 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
11355 | ||
11356 | address += (((op_index + adjust) | |
11357 | / lh->maximum_ops_per_instruction) | |
11358 | * lh->minimum_instruction_length); | |
11359 | op_index = ((op_index + adjust) | |
11360 | % lh->maximum_ops_per_instruction); | |
11361 | } | |
c906108c SS |
11362 | break; |
11363 | case DW_LNS_fixed_advance_pc: | |
11364 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 11365 | op_index = 0; |
c906108c SS |
11366 | line_ptr += 2; |
11367 | break; | |
9aa1fe7e | 11368 | default: |
a738430d MK |
11369 | { |
11370 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 11371 | int i; |
a738430d | 11372 | |
debd256d | 11373 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
11374 | { |
11375 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11376 | line_ptr += bytes_read; | |
11377 | } | |
11378 | } | |
c906108c SS |
11379 | } |
11380 | } | |
59205f5a JB |
11381 | if (lh->num_file_names < file || file == 0) |
11382 | dwarf2_debug_line_missing_file_complaint (); | |
11383 | else | |
11384 | { | |
11385 | lh->file_names[file - 1].included_p = 1; | |
11386 | if (!decode_for_pst_p) | |
fbf65064 UW |
11387 | { |
11388 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 11389 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 11390 | } |
59205f5a | 11391 | } |
c906108c | 11392 | } |
f3f5162e DE |
11393 | } |
11394 | ||
11395 | /* Decode the Line Number Program (LNP) for the given line_header | |
11396 | structure and CU. The actual information extracted and the type | |
11397 | of structures created from the LNP depends on the value of PST. | |
11398 | ||
11399 | 1. If PST is NULL, then this procedure uses the data from the program | |
11400 | to create all necessary symbol tables, and their linetables. | |
11401 | ||
11402 | 2. If PST is not NULL, this procedure reads the program to determine | |
11403 | the list of files included by the unit represented by PST, and | |
11404 | builds all the associated partial symbol tables. | |
11405 | ||
11406 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
11407 | It is used for relative paths in the line table. | |
11408 | NOTE: When processing partial symtabs (pst != NULL), | |
11409 | comp_dir == pst->dirname. | |
11410 | ||
11411 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
11412 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
11413 | symtab we don't use it in the name of the psymtabs we create. | |
11414 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
11415 | A good testcase for this is mb-inline.exp. */ | |
11416 | ||
11417 | static void | |
11418 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, | |
11419 | struct dwarf2_cu *cu, struct partial_symtab *pst, | |
11420 | int want_line_info) | |
11421 | { | |
11422 | struct objfile *objfile = cu->objfile; | |
11423 | const int decode_for_pst_p = (pst != NULL); | |
11424 | struct subfile *first_subfile = current_subfile; | |
11425 | ||
11426 | if (want_line_info) | |
11427 | dwarf_decode_lines_1 (lh, comp_dir, cu, pst); | |
aaa75496 JB |
11428 | |
11429 | if (decode_for_pst_p) | |
11430 | { | |
11431 | int file_index; | |
11432 | ||
11433 | /* Now that we're done scanning the Line Header Program, we can | |
11434 | create the psymtab of each included file. */ | |
11435 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
11436 | if (lh->file_names[file_index].included_p == 1) | |
11437 | { | |
c6da4cef DE |
11438 | char *include_name = |
11439 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
11440 | if (include_name != NULL) | |
aaa75496 JB |
11441 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
11442 | } | |
11443 | } | |
cb1df416 DJ |
11444 | else |
11445 | { | |
11446 | /* Make sure a symtab is created for every file, even files | |
11447 | which contain only variables (i.e. no code with associated | |
11448 | line numbers). */ | |
cb1df416 | 11449 | int i; |
cb1df416 DJ |
11450 | |
11451 | for (i = 0; i < lh->num_file_names; i++) | |
11452 | { | |
11453 | char *dir = NULL; | |
f3f5162e | 11454 | struct file_entry *fe; |
9a619af0 | 11455 | |
cb1df416 DJ |
11456 | fe = &lh->file_names[i]; |
11457 | if (fe->dir_index) | |
11458 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11459 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11460 | ||
11461 | /* Skip the main file; we don't need it, and it must be | |
11462 | allocated last, so that it will show up before the | |
11463 | non-primary symtabs in the objfile's symtab list. */ | |
11464 | if (current_subfile == first_subfile) | |
11465 | continue; | |
11466 | ||
11467 | if (current_subfile->symtab == NULL) | |
11468 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
bb5ed363 | 11469 | objfile); |
cb1df416 DJ |
11470 | fe->symtab = current_subfile->symtab; |
11471 | } | |
11472 | } | |
c906108c SS |
11473 | } |
11474 | ||
11475 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
11476 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
11477 | or NULL if not known. COMP_DIR is the compilation directory for the |
11478 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
11479 | This routine tries to keep line numbers from identical absolute and |
11480 | relative file names in a common subfile. | |
11481 | ||
11482 | Using the `list' example from the GDB testsuite, which resides in | |
11483 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
11484 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
11485 | ||
c5aa993b JM |
11486 | DW_AT_name: /srcdir/list0.c |
11487 | DW_AT_comp_dir: /compdir | |
357e46e7 | 11488 | files.files[0].name: list0.h |
c5aa993b | 11489 | files.files[0].dir: /srcdir |
357e46e7 | 11490 | files.files[1].name: list0.c |
c5aa993b | 11491 | files.files[1].dir: /srcdir |
c906108c SS |
11492 | |
11493 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
11494 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
11495 | start_subfile will ensure that this happens provided that we pass the | |
11496 | concatenation of files.files[1].dir and files.files[1].name as the | |
11497 | subfile's name. */ | |
c906108c SS |
11498 | |
11499 | static void | |
3e43a32a MS |
11500 | dwarf2_start_subfile (char *filename, const char *dirname, |
11501 | const char *comp_dir) | |
c906108c | 11502 | { |
4f1520fb FR |
11503 | char *fullname; |
11504 | ||
11505 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
11506 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
11507 | second argument to start_subfile. To be consistent, we do the | |
11508 | same here. In order not to lose the line information directory, | |
11509 | we concatenate it to the filename when it makes sense. | |
11510 | Note that the Dwarf3 standard says (speaking of filenames in line | |
11511 | information): ``The directory index is ignored for file names | |
11512 | that represent full path names''. Thus ignoring dirname in the | |
11513 | `else' branch below isn't an issue. */ | |
c906108c | 11514 | |
d5166ae1 | 11515 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
11516 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
11517 | else | |
11518 | fullname = filename; | |
c906108c | 11519 | |
4f1520fb FR |
11520 | start_subfile (fullname, comp_dir); |
11521 | ||
11522 | if (fullname != filename) | |
11523 | xfree (fullname); | |
c906108c SS |
11524 | } |
11525 | ||
4c2df51b DJ |
11526 | static void |
11527 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11528 | struct dwarf2_cu *cu) |
4c2df51b | 11529 | { |
e7c27a73 DJ |
11530 | struct objfile *objfile = cu->objfile; |
11531 | struct comp_unit_head *cu_header = &cu->header; | |
11532 | ||
4c2df51b DJ |
11533 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
11534 | code here to turn a symbol with DW_AT_external and a | |
11535 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
11536 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
11537 | with some versions of binutils) where shared libraries could have | |
11538 | relocations against symbols in their debug information - the | |
11539 | minimal symbol would have the right address, but the debug info | |
11540 | would not. It's no longer necessary, because we will explicitly | |
11541 | apply relocations when we read in the debug information now. */ | |
11542 | ||
11543 | /* A DW_AT_location attribute with no contents indicates that a | |
11544 | variable has been optimized away. */ | |
11545 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
11546 | { | |
11547 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
11548 | return; | |
11549 | } | |
11550 | ||
11551 | /* Handle one degenerate form of location expression specially, to | |
11552 | preserve GDB's previous behavior when section offsets are | |
11553 | specified. If this is just a DW_OP_addr then mark this symbol | |
11554 | as LOC_STATIC. */ | |
11555 | ||
11556 | if (attr_form_is_block (attr) | |
11557 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
11558 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
11559 | { | |
891d2f0b | 11560 | unsigned int dummy; |
4c2df51b DJ |
11561 | |
11562 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 11563 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 11564 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
11565 | fixup_symbol_section (sym, objfile); |
11566 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
11567 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
11568 | return; |
11569 | } | |
11570 | ||
11571 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
11572 | expression evaluator, and use LOC_COMPUTED only when necessary | |
11573 | (i.e. when the value of a register or memory location is | |
11574 | referenced, or a thread-local block, etc.). Then again, it might | |
11575 | not be worthwhile. I'm assuming that it isn't unless performance | |
11576 | or memory numbers show me otherwise. */ | |
11577 | ||
e7c27a73 | 11578 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b | 11579 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8be455d7 JK |
11580 | |
11581 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) | |
11582 | cu->has_loclist = 1; | |
4c2df51b DJ |
11583 | } |
11584 | ||
c906108c SS |
11585 | /* Given a pointer to a DWARF information entry, figure out if we need |
11586 | to make a symbol table entry for it, and if so, create a new entry | |
11587 | and return a pointer to it. | |
11588 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
11589 | used the passed type. |
11590 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
11591 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
11592 | |
11593 | static struct symbol * | |
34eaf542 TT |
11594 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
11595 | struct symbol *space) | |
c906108c | 11596 | { |
e7c27a73 | 11597 | struct objfile *objfile = cu->objfile; |
c906108c SS |
11598 | struct symbol *sym = NULL; |
11599 | char *name; | |
11600 | struct attribute *attr = NULL; | |
11601 | struct attribute *attr2 = NULL; | |
e142c38c | 11602 | CORE_ADDR baseaddr; |
e37fd15a SW |
11603 | struct pending **list_to_add = NULL; |
11604 | ||
edb3359d | 11605 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
11606 | |
11607 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11608 | |
94af9270 | 11609 | name = dwarf2_name (die, cu); |
c906108c SS |
11610 | if (name) |
11611 | { | |
94af9270 | 11612 | const char *linkagename; |
34eaf542 | 11613 | int suppress_add = 0; |
94af9270 | 11614 | |
34eaf542 TT |
11615 | if (space) |
11616 | sym = space; | |
11617 | else | |
11618 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 11619 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
11620 | |
11621 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 11622 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
11623 | linkagename = dwarf2_physname (name, die, cu); |
11624 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 11625 | |
f55ee35c JK |
11626 | /* Fortran does not have mangling standard and the mangling does differ |
11627 | between gfortran, iFort etc. */ | |
11628 | if (cu->language == language_fortran | |
b250c185 | 11629 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
11630 | symbol_set_demangled_name (&(sym->ginfo), |
11631 | (char *) dwarf2_full_name (name, die, cu), | |
11632 | NULL); | |
f55ee35c | 11633 | |
c906108c | 11634 | /* Default assumptions. |
c5aa993b | 11635 | Use the passed type or decode it from the die. */ |
176620f1 | 11636 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 11637 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
11638 | if (type != NULL) |
11639 | SYMBOL_TYPE (sym) = type; | |
11640 | else | |
e7c27a73 | 11641 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
11642 | attr = dwarf2_attr (die, |
11643 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
11644 | cu); | |
c906108c SS |
11645 | if (attr) |
11646 | { | |
11647 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
11648 | } | |
cb1df416 | 11649 | |
edb3359d DJ |
11650 | attr = dwarf2_attr (die, |
11651 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
11652 | cu); | |
cb1df416 DJ |
11653 | if (attr) |
11654 | { | |
11655 | int file_index = DW_UNSND (attr); | |
9a619af0 | 11656 | |
cb1df416 DJ |
11657 | if (cu->line_header == NULL |
11658 | || file_index > cu->line_header->num_file_names) | |
11659 | complaint (&symfile_complaints, | |
11660 | _("file index out of range")); | |
1c3d648d | 11661 | else if (file_index > 0) |
cb1df416 DJ |
11662 | { |
11663 | struct file_entry *fe; | |
9a619af0 | 11664 | |
cb1df416 DJ |
11665 | fe = &cu->line_header->file_names[file_index - 1]; |
11666 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
11667 | } | |
11668 | } | |
11669 | ||
c906108c SS |
11670 | switch (die->tag) |
11671 | { | |
11672 | case DW_TAG_label: | |
e142c38c | 11673 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
11674 | if (attr) |
11675 | { | |
11676 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
11677 | } | |
0f5238ed TT |
11678 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
11679 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 11680 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 11681 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
11682 | break; |
11683 | case DW_TAG_subprogram: | |
11684 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11685 | finish_block. */ | |
11686 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 11687 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
11688 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
11689 | || cu->language == language_ada) | |
c906108c | 11690 | { |
2cfa0c8d JB |
11691 | /* Subprograms marked external are stored as a global symbol. |
11692 | Ada subprograms, whether marked external or not, are always | |
11693 | stored as a global symbol, because we want to be able to | |
11694 | access them globally. For instance, we want to be able | |
11695 | to break on a nested subprogram without having to | |
11696 | specify the context. */ | |
e37fd15a | 11697 | list_to_add = &global_symbols; |
c906108c SS |
11698 | } |
11699 | else | |
11700 | { | |
e37fd15a | 11701 | list_to_add = cu->list_in_scope; |
c906108c SS |
11702 | } |
11703 | break; | |
edb3359d DJ |
11704 | case DW_TAG_inlined_subroutine: |
11705 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11706 | finish_block. */ | |
11707 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
11708 | SYMBOL_INLINED (sym) = 1; | |
11709 | /* Do not add the symbol to any lists. It will be found via | |
11710 | BLOCK_FUNCTION from the blockvector. */ | |
11711 | break; | |
34eaf542 TT |
11712 | case DW_TAG_template_value_param: |
11713 | suppress_add = 1; | |
11714 | /* Fall through. */ | |
72929c62 | 11715 | case DW_TAG_constant: |
c906108c | 11716 | case DW_TAG_variable: |
254e6b9e | 11717 | case DW_TAG_member: |
0963b4bd MS |
11718 | /* Compilation with minimal debug info may result in |
11719 | variables with missing type entries. Change the | |
11720 | misleading `void' type to something sensible. */ | |
c906108c | 11721 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 11722 | SYMBOL_TYPE (sym) |
46bf5051 | 11723 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 11724 | |
e142c38c | 11725 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
11726 | /* In the case of DW_TAG_member, we should only be called for |
11727 | static const members. */ | |
11728 | if (die->tag == DW_TAG_member) | |
11729 | { | |
3863f96c DE |
11730 | /* dwarf2_add_field uses die_is_declaration, |
11731 | so we do the same. */ | |
254e6b9e DE |
11732 | gdb_assert (die_is_declaration (die, cu)); |
11733 | gdb_assert (attr); | |
11734 | } | |
c906108c SS |
11735 | if (attr) |
11736 | { | |
e7c27a73 | 11737 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 11738 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 11739 | if (!suppress_add) |
34eaf542 TT |
11740 | { |
11741 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 11742 | list_to_add = &global_symbols; |
34eaf542 | 11743 | else |
e37fd15a | 11744 | list_to_add = cu->list_in_scope; |
34eaf542 | 11745 | } |
c906108c SS |
11746 | break; |
11747 | } | |
e142c38c | 11748 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11749 | if (attr) |
11750 | { | |
e7c27a73 | 11751 | var_decode_location (attr, sym, cu); |
e142c38c | 11752 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
11753 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
11754 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
11755 | && !dwarf2_per_objfile->has_section_at_zero) | |
11756 | { | |
11757 | /* When a static variable is eliminated by the linker, | |
11758 | the corresponding debug information is not stripped | |
11759 | out, but the variable address is set to null; | |
11760 | do not add such variables into symbol table. */ | |
11761 | } | |
11762 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 11763 | { |
f55ee35c JK |
11764 | /* Workaround gfortran PR debug/40040 - it uses |
11765 | DW_AT_location for variables in -fPIC libraries which may | |
11766 | get overriden by other libraries/executable and get | |
11767 | a different address. Resolve it by the minimal symbol | |
11768 | which may come from inferior's executable using copy | |
11769 | relocation. Make this workaround only for gfortran as for | |
11770 | other compilers GDB cannot guess the minimal symbol | |
11771 | Fortran mangling kind. */ | |
11772 | if (cu->language == language_fortran && die->parent | |
11773 | && die->parent->tag == DW_TAG_module | |
11774 | && cu->producer | |
11775 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
11776 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
11777 | ||
1c809c68 TT |
11778 | /* A variable with DW_AT_external is never static, |
11779 | but it may be block-scoped. */ | |
11780 | list_to_add = (cu->list_in_scope == &file_symbols | |
11781 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 11782 | } |
c906108c | 11783 | else |
e37fd15a | 11784 | list_to_add = cu->list_in_scope; |
c906108c SS |
11785 | } |
11786 | else | |
11787 | { | |
11788 | /* We do not know the address of this symbol. | |
c5aa993b JM |
11789 | If it is an external symbol and we have type information |
11790 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
11791 | The address of the variable will then be determined from | |
11792 | the minimal symbol table whenever the variable is | |
11793 | referenced. */ | |
e142c38c | 11794 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 11795 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 11796 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 11797 | { |
0fe7935b DJ |
11798 | /* A variable with DW_AT_external is never static, but it |
11799 | may be block-scoped. */ | |
11800 | list_to_add = (cu->list_in_scope == &file_symbols | |
11801 | ? &global_symbols : cu->list_in_scope); | |
11802 | ||
c906108c | 11803 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 11804 | } |
442ddf59 JK |
11805 | else if (!die_is_declaration (die, cu)) |
11806 | { | |
11807 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
11808 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
11809 | if (!suppress_add) |
11810 | list_to_add = cu->list_in_scope; | |
442ddf59 | 11811 | } |
c906108c SS |
11812 | } |
11813 | break; | |
11814 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
11815 | /* If we are inside a function, mark this as an argument. If |
11816 | not, we might be looking at an argument to an inlined function | |
11817 | when we do not have enough information to show inlined frames; | |
11818 | pretend it's a local variable in that case so that the user can | |
11819 | still see it. */ | |
11820 | if (context_stack_depth > 0 | |
11821 | && context_stack[context_stack_depth - 1].name != NULL) | |
11822 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 11823 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11824 | if (attr) |
11825 | { | |
e7c27a73 | 11826 | var_decode_location (attr, sym, cu); |
c906108c | 11827 | } |
e142c38c | 11828 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11829 | if (attr) |
11830 | { | |
e7c27a73 | 11831 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11832 | } |
f346a30d | 11833 | |
e37fd15a | 11834 | list_to_add = cu->list_in_scope; |
c906108c SS |
11835 | break; |
11836 | case DW_TAG_unspecified_parameters: | |
11837 | /* From varargs functions; gdb doesn't seem to have any | |
11838 | interest in this information, so just ignore it for now. | |
11839 | (FIXME?) */ | |
11840 | break; | |
34eaf542 TT |
11841 | case DW_TAG_template_type_param: |
11842 | suppress_add = 1; | |
11843 | /* Fall through. */ | |
c906108c | 11844 | case DW_TAG_class_type: |
680b30c7 | 11845 | case DW_TAG_interface_type: |
c906108c SS |
11846 | case DW_TAG_structure_type: |
11847 | case DW_TAG_union_type: | |
72019c9c | 11848 | case DW_TAG_set_type: |
c906108c SS |
11849 | case DW_TAG_enumeration_type: |
11850 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 11851 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 11852 | |
63d06c5c | 11853 | { |
987504bb | 11854 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
11855 | really ever be static objects: otherwise, if you try |
11856 | to, say, break of a class's method and you're in a file | |
11857 | which doesn't mention that class, it won't work unless | |
11858 | the check for all static symbols in lookup_symbol_aux | |
11859 | saves you. See the OtherFileClass tests in | |
11860 | gdb.c++/namespace.exp. */ | |
11861 | ||
e37fd15a | 11862 | if (!suppress_add) |
34eaf542 | 11863 | { |
34eaf542 TT |
11864 | list_to_add = (cu->list_in_scope == &file_symbols |
11865 | && (cu->language == language_cplus | |
11866 | || cu->language == language_java) | |
11867 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 11868 | |
64382290 TT |
11869 | /* The semantics of C++ state that "struct foo { |
11870 | ... }" also defines a typedef for "foo". A Java | |
11871 | class declaration also defines a typedef for the | |
11872 | class. */ | |
11873 | if (cu->language == language_cplus | |
11874 | || cu->language == language_java | |
11875 | || cu->language == language_ada) | |
11876 | { | |
11877 | /* The symbol's name is already allocated along | |
11878 | with this objfile, so we don't need to | |
11879 | duplicate it for the type. */ | |
11880 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
11881 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
11882 | } | |
63d06c5c DC |
11883 | } |
11884 | } | |
c906108c SS |
11885 | break; |
11886 | case DW_TAG_typedef: | |
63d06c5c DC |
11887 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
11888 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 11889 | list_to_add = cu->list_in_scope; |
63d06c5c | 11890 | break; |
c906108c | 11891 | case DW_TAG_base_type: |
a02abb62 | 11892 | case DW_TAG_subrange_type: |
c906108c | 11893 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 11894 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 11895 | list_to_add = cu->list_in_scope; |
c906108c SS |
11896 | break; |
11897 | case DW_TAG_enumerator: | |
e142c38c | 11898 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11899 | if (attr) |
11900 | { | |
e7c27a73 | 11901 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11902 | } |
63d06c5c DC |
11903 | { |
11904 | /* NOTE: carlton/2003-11-10: See comment above in the | |
11905 | DW_TAG_class_type, etc. block. */ | |
11906 | ||
e142c38c | 11907 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
11908 | && (cu->language == language_cplus |
11909 | || cu->language == language_java) | |
e142c38c | 11910 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 11911 | } |
c906108c | 11912 | break; |
5c4e30ca DC |
11913 | case DW_TAG_namespace: |
11914 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 11915 | list_to_add = &global_symbols; |
5c4e30ca | 11916 | break; |
c906108c SS |
11917 | default: |
11918 | /* Not a tag we recognize. Hopefully we aren't processing | |
11919 | trash data, but since we must specifically ignore things | |
11920 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 11921 | this point. */ |
e2e0b3e5 | 11922 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 11923 | dwarf_tag_name (die->tag)); |
c906108c SS |
11924 | break; |
11925 | } | |
df8a16a1 | 11926 | |
e37fd15a SW |
11927 | if (suppress_add) |
11928 | { | |
11929 | sym->hash_next = objfile->template_symbols; | |
11930 | objfile->template_symbols = sym; | |
11931 | list_to_add = NULL; | |
11932 | } | |
11933 | ||
11934 | if (list_to_add != NULL) | |
11935 | add_symbol_to_list (sym, list_to_add); | |
11936 | ||
df8a16a1 DJ |
11937 | /* For the benefit of old versions of GCC, check for anonymous |
11938 | namespaces based on the demangled name. */ | |
11939 | if (!processing_has_namespace_info | |
94af9270 | 11940 | && cu->language == language_cplus) |
a10964d1 | 11941 | cp_scan_for_anonymous_namespaces (sym, objfile); |
c906108c SS |
11942 | } |
11943 | return (sym); | |
11944 | } | |
11945 | ||
34eaf542 TT |
11946 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
11947 | ||
11948 | static struct symbol * | |
11949 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
11950 | { | |
11951 | return new_symbol_full (die, type, cu, NULL); | |
11952 | } | |
11953 | ||
98bfdba5 PA |
11954 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
11955 | zero-extend it as appropriate for the symbol's type. The DWARF | |
11956 | standard (v4) is not entirely clear about the meaning of using | |
11957 | DW_FORM_dataN for a constant with a signed type, where the type is | |
11958 | wider than the data. The conclusion of a discussion on the DWARF | |
11959 | list was that this is unspecified. We choose to always zero-extend | |
11960 | because that is the interpretation long in use by GCC. */ | |
c906108c | 11961 | |
98bfdba5 PA |
11962 | static gdb_byte * |
11963 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
11964 | const char *name, struct obstack *obstack, | |
11965 | struct dwarf2_cu *cu, long *value, int bits) | |
c906108c | 11966 | { |
e7c27a73 | 11967 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
11968 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
11969 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
11970 | LONGEST l = DW_UNSND (attr); |
11971 | ||
11972 | if (bits < sizeof (*value) * 8) | |
11973 | { | |
11974 | l &= ((LONGEST) 1 << bits) - 1; | |
11975 | *value = l; | |
11976 | } | |
11977 | else if (bits == sizeof (*value) * 8) | |
11978 | *value = l; | |
11979 | else | |
11980 | { | |
11981 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
11982 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
11983 | return bytes; | |
11984 | } | |
11985 | ||
11986 | return NULL; | |
11987 | } | |
11988 | ||
11989 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
11990 | the value does not fit in *VALUE, set *BYTES - either already | |
11991 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
11992 | or, set *BATON, if we translated the constant to a location | |
11993 | expression. */ | |
11994 | ||
11995 | static void | |
11996 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
11997 | const char *name, struct obstack *obstack, | |
11998 | struct dwarf2_cu *cu, | |
11999 | long *value, gdb_byte **bytes, | |
12000 | struct dwarf2_locexpr_baton **baton) | |
12001 | { | |
12002 | struct objfile *objfile = cu->objfile; | |
12003 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 12004 | struct dwarf_block *blk; |
98bfdba5 PA |
12005 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
12006 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
12007 | ||
12008 | *value = 0; | |
12009 | *bytes = NULL; | |
12010 | *baton = NULL; | |
c906108c SS |
12011 | |
12012 | switch (attr->form) | |
12013 | { | |
12014 | case DW_FORM_addr: | |
ac56253d | 12015 | { |
ac56253d TT |
12016 | gdb_byte *data; |
12017 | ||
98bfdba5 PA |
12018 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
12019 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 12020 | cu_header->addr_size, |
98bfdba5 | 12021 | TYPE_LENGTH (type)); |
ac56253d TT |
12022 | /* Symbols of this form are reasonably rare, so we just |
12023 | piggyback on the existing location code rather than writing | |
12024 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
12025 | *baton = obstack_alloc (&objfile->objfile_obstack, |
12026 | sizeof (struct dwarf2_locexpr_baton)); | |
12027 | (*baton)->per_cu = cu->per_cu; | |
12028 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 12029 | |
98bfdba5 PA |
12030 | (*baton)->size = 2 + cu_header->addr_size; |
12031 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
12032 | (*baton)->data = data; | |
ac56253d TT |
12033 | |
12034 | data[0] = DW_OP_addr; | |
12035 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
12036 | byte_order, DW_ADDR (attr)); | |
12037 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 12038 | } |
c906108c | 12039 | break; |
4ac36638 | 12040 | case DW_FORM_string: |
93b5768b | 12041 | case DW_FORM_strp: |
98bfdba5 PA |
12042 | /* DW_STRING is already allocated on the objfile obstack, point |
12043 | directly to it. */ | |
12044 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 12045 | break; |
c906108c SS |
12046 | case DW_FORM_block1: |
12047 | case DW_FORM_block2: | |
12048 | case DW_FORM_block4: | |
12049 | case DW_FORM_block: | |
2dc7f7b3 | 12050 | case DW_FORM_exprloc: |
c906108c | 12051 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
12052 | if (TYPE_LENGTH (type) != blk->size) |
12053 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
12054 | TYPE_LENGTH (type)); | |
12055 | *bytes = blk->data; | |
c906108c | 12056 | break; |
2df3850c JM |
12057 | |
12058 | /* The DW_AT_const_value attributes are supposed to carry the | |
12059 | symbol's value "represented as it would be on the target | |
12060 | architecture." By the time we get here, it's already been | |
12061 | converted to host endianness, so we just need to sign- or | |
12062 | zero-extend it as appropriate. */ | |
12063 | case DW_FORM_data1: | |
3e43a32a MS |
12064 | *bytes = dwarf2_const_value_data (attr, type, name, |
12065 | obstack, cu, value, 8); | |
2df3850c | 12066 | break; |
c906108c | 12067 | case DW_FORM_data2: |
3e43a32a MS |
12068 | *bytes = dwarf2_const_value_data (attr, type, name, |
12069 | obstack, cu, value, 16); | |
2df3850c | 12070 | break; |
c906108c | 12071 | case DW_FORM_data4: |
3e43a32a MS |
12072 | *bytes = dwarf2_const_value_data (attr, type, name, |
12073 | obstack, cu, value, 32); | |
2df3850c | 12074 | break; |
c906108c | 12075 | case DW_FORM_data8: |
3e43a32a MS |
12076 | *bytes = dwarf2_const_value_data (attr, type, name, |
12077 | obstack, cu, value, 64); | |
2df3850c JM |
12078 | break; |
12079 | ||
c906108c | 12080 | case DW_FORM_sdata: |
98bfdba5 | 12081 | *value = DW_SND (attr); |
2df3850c JM |
12082 | break; |
12083 | ||
c906108c | 12084 | case DW_FORM_udata: |
98bfdba5 | 12085 | *value = DW_UNSND (attr); |
c906108c | 12086 | break; |
2df3850c | 12087 | |
c906108c | 12088 | default: |
4d3c2250 | 12089 | complaint (&symfile_complaints, |
e2e0b3e5 | 12090 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 12091 | dwarf_form_name (attr->form)); |
98bfdba5 | 12092 | *value = 0; |
c906108c SS |
12093 | break; |
12094 | } | |
12095 | } | |
12096 | ||
2df3850c | 12097 | |
98bfdba5 PA |
12098 | /* Copy constant value from an attribute to a symbol. */ |
12099 | ||
2df3850c | 12100 | static void |
98bfdba5 PA |
12101 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
12102 | struct dwarf2_cu *cu) | |
2df3850c | 12103 | { |
98bfdba5 PA |
12104 | struct objfile *objfile = cu->objfile; |
12105 | struct comp_unit_head *cu_header = &cu->header; | |
12106 | long value; | |
12107 | gdb_byte *bytes; | |
12108 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 12109 | |
98bfdba5 PA |
12110 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
12111 | SYMBOL_PRINT_NAME (sym), | |
12112 | &objfile->objfile_obstack, cu, | |
12113 | &value, &bytes, &baton); | |
2df3850c | 12114 | |
98bfdba5 PA |
12115 | if (baton != NULL) |
12116 | { | |
12117 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
12118 | SYMBOL_LOCATION_BATON (sym) = baton; | |
12119 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
12120 | } | |
12121 | else if (bytes != NULL) | |
12122 | { | |
12123 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
12124 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
12125 | } | |
12126 | else | |
12127 | { | |
12128 | SYMBOL_VALUE (sym) = value; | |
12129 | SYMBOL_CLASS (sym) = LOC_CONST; | |
12130 | } | |
2df3850c JM |
12131 | } |
12132 | ||
c906108c SS |
12133 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
12134 | ||
12135 | static struct type * | |
e7c27a73 | 12136 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12137 | { |
c906108c | 12138 | struct attribute *type_attr; |
c906108c | 12139 | |
e142c38c | 12140 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
12141 | if (!type_attr) |
12142 | { | |
12143 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 12144 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 12145 | } |
348e048f | 12146 | |
673bfd45 | 12147 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12148 | } |
12149 | ||
b4ba55a1 JB |
12150 | /* True iff CU's producer generates GNAT Ada auxiliary information |
12151 | that allows to find parallel types through that information instead | |
12152 | of having to do expensive parallel lookups by type name. */ | |
12153 | ||
12154 | static int | |
12155 | need_gnat_info (struct dwarf2_cu *cu) | |
12156 | { | |
12157 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
12158 | of GNAT produces this auxiliary information, without any indication | |
12159 | that it is produced. Part of enhancing the FSF version of GNAT | |
12160 | to produce that information will be to put in place an indicator | |
12161 | that we can use in order to determine whether the descriptive type | |
12162 | info is available or not. One suggestion that has been made is | |
12163 | to use a new attribute, attached to the CU die. For now, assume | |
12164 | that the descriptive type info is not available. */ | |
12165 | return 0; | |
12166 | } | |
12167 | ||
b4ba55a1 JB |
12168 | /* Return the auxiliary type of the die in question using its |
12169 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
12170 | attribute is not present. */ | |
12171 | ||
12172 | static struct type * | |
12173 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
12174 | { | |
b4ba55a1 | 12175 | struct attribute *type_attr; |
b4ba55a1 JB |
12176 | |
12177 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
12178 | if (!type_attr) | |
12179 | return NULL; | |
12180 | ||
673bfd45 | 12181 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
12182 | } |
12183 | ||
12184 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
12185 | descriptive type accordingly. */ | |
12186 | ||
12187 | static void | |
12188 | set_descriptive_type (struct type *type, struct die_info *die, | |
12189 | struct dwarf2_cu *cu) | |
12190 | { | |
12191 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
12192 | ||
12193 | if (descriptive_type) | |
12194 | { | |
12195 | ALLOCATE_GNAT_AUX_TYPE (type); | |
12196 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
12197 | } | |
12198 | } | |
12199 | ||
c906108c SS |
12200 | /* Return the containing type of the die in question using its |
12201 | DW_AT_containing_type attribute. */ | |
12202 | ||
12203 | static struct type * | |
e7c27a73 | 12204 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12205 | { |
c906108c | 12206 | struct attribute *type_attr; |
c906108c | 12207 | |
e142c38c | 12208 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
12209 | if (!type_attr) |
12210 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
12211 | "[in module %s]"), cu->objfile->name); | |
12212 | ||
673bfd45 | 12213 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12214 | } |
12215 | ||
673bfd45 DE |
12216 | /* Look up the type of DIE in CU using its type attribute ATTR. |
12217 | If there is no type substitute an error marker. */ | |
12218 | ||
c906108c | 12219 | static struct type * |
673bfd45 DE |
12220 | lookup_die_type (struct die_info *die, struct attribute *attr, |
12221 | struct dwarf2_cu *cu) | |
c906108c | 12222 | { |
bb5ed363 | 12223 | struct objfile *objfile = cu->objfile; |
f792889a DJ |
12224 | struct type *this_type; |
12225 | ||
673bfd45 DE |
12226 | /* First see if we have it cached. */ |
12227 | ||
12228 | if (is_ref_attr (attr)) | |
12229 | { | |
12230 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
12231 | ||
12232 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
12233 | } | |
55f1336d | 12234 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
12235 | { |
12236 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
12237 | struct dwarf2_cu *sig_cu; | |
12238 | unsigned int offset; | |
12239 | ||
12240 | /* sig_type will be NULL if the signatured type is missing from | |
12241 | the debug info. */ | |
12242 | if (sig_type == NULL) | |
12243 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
12244 | "at 0x%x [in module %s]"), | |
bb5ed363 | 12245 | die->offset, objfile->name); |
673bfd45 | 12246 | |
b0df02fd | 12247 | gdb_assert (sig_type->per_cu.debug_types_section); |
b3c8eb43 | 12248 | offset = sig_type->per_cu.offset + sig_type->type_offset; |
673bfd45 DE |
12249 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); |
12250 | } | |
12251 | else | |
12252 | { | |
12253 | dump_die_for_error (die); | |
12254 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
bb5ed363 | 12255 | dwarf_attr_name (attr->name), objfile->name); |
673bfd45 DE |
12256 | } |
12257 | ||
12258 | /* If not cached we need to read it in. */ | |
12259 | ||
12260 | if (this_type == NULL) | |
12261 | { | |
12262 | struct die_info *type_die; | |
12263 | struct dwarf2_cu *type_cu = cu; | |
12264 | ||
12265 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
12266 | /* If the type is cached, we should have found it above. */ | |
12267 | gdb_assert (get_die_type (type_die, type_cu) == NULL); | |
12268 | this_type = read_type_die_1 (type_die, type_cu); | |
12269 | } | |
12270 | ||
12271 | /* If we still don't have a type use an error marker. */ | |
12272 | ||
12273 | if (this_type == NULL) | |
c906108c | 12274 | { |
b00fdb78 TT |
12275 | char *message, *saved; |
12276 | ||
12277 | /* read_type_die already issued a complaint. */ | |
12278 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
bb5ed363 | 12279 | objfile->name, |
b00fdb78 TT |
12280 | cu->header.offset, |
12281 | die->offset); | |
bb5ed363 | 12282 | saved = obstack_copy0 (&objfile->objfile_obstack, |
b00fdb78 TT |
12283 | message, strlen (message)); |
12284 | xfree (message); | |
12285 | ||
bb5ed363 | 12286 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile); |
c906108c | 12287 | } |
673bfd45 | 12288 | |
f792889a | 12289 | return this_type; |
c906108c SS |
12290 | } |
12291 | ||
673bfd45 DE |
12292 | /* Return the type in DIE, CU. |
12293 | Returns NULL for invalid types. | |
12294 | ||
12295 | This first does a lookup in the appropriate type_hash table, | |
12296 | and only reads the die in if necessary. | |
12297 | ||
12298 | NOTE: This can be called when reading in partial or full symbols. */ | |
12299 | ||
f792889a | 12300 | static struct type * |
e7c27a73 | 12301 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12302 | { |
f792889a DJ |
12303 | struct type *this_type; |
12304 | ||
12305 | this_type = get_die_type (die, cu); | |
12306 | if (this_type) | |
12307 | return this_type; | |
12308 | ||
673bfd45 DE |
12309 | return read_type_die_1 (die, cu); |
12310 | } | |
12311 | ||
12312 | /* Read the type in DIE, CU. | |
12313 | Returns NULL for invalid types. */ | |
12314 | ||
12315 | static struct type * | |
12316 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
12317 | { | |
12318 | struct type *this_type = NULL; | |
12319 | ||
c906108c SS |
12320 | switch (die->tag) |
12321 | { | |
12322 | case DW_TAG_class_type: | |
680b30c7 | 12323 | case DW_TAG_interface_type: |
c906108c SS |
12324 | case DW_TAG_structure_type: |
12325 | case DW_TAG_union_type: | |
f792889a | 12326 | this_type = read_structure_type (die, cu); |
c906108c SS |
12327 | break; |
12328 | case DW_TAG_enumeration_type: | |
f792889a | 12329 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
12330 | break; |
12331 | case DW_TAG_subprogram: | |
12332 | case DW_TAG_subroutine_type: | |
edb3359d | 12333 | case DW_TAG_inlined_subroutine: |
f792889a | 12334 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
12335 | break; |
12336 | case DW_TAG_array_type: | |
f792889a | 12337 | this_type = read_array_type (die, cu); |
c906108c | 12338 | break; |
72019c9c | 12339 | case DW_TAG_set_type: |
f792889a | 12340 | this_type = read_set_type (die, cu); |
72019c9c | 12341 | break; |
c906108c | 12342 | case DW_TAG_pointer_type: |
f792889a | 12343 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
12344 | break; |
12345 | case DW_TAG_ptr_to_member_type: | |
f792889a | 12346 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
12347 | break; |
12348 | case DW_TAG_reference_type: | |
f792889a | 12349 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
12350 | break; |
12351 | case DW_TAG_const_type: | |
f792889a | 12352 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
12353 | break; |
12354 | case DW_TAG_volatile_type: | |
f792889a | 12355 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
12356 | break; |
12357 | case DW_TAG_string_type: | |
f792889a | 12358 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
12359 | break; |
12360 | case DW_TAG_typedef: | |
f792889a | 12361 | this_type = read_typedef (die, cu); |
c906108c | 12362 | break; |
a02abb62 | 12363 | case DW_TAG_subrange_type: |
f792889a | 12364 | this_type = read_subrange_type (die, cu); |
a02abb62 | 12365 | break; |
c906108c | 12366 | case DW_TAG_base_type: |
f792889a | 12367 | this_type = read_base_type (die, cu); |
c906108c | 12368 | break; |
81a17f79 | 12369 | case DW_TAG_unspecified_type: |
f792889a | 12370 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 12371 | break; |
0114d602 DJ |
12372 | case DW_TAG_namespace: |
12373 | this_type = read_namespace_type (die, cu); | |
12374 | break; | |
f55ee35c JK |
12375 | case DW_TAG_module: |
12376 | this_type = read_module_type (die, cu); | |
12377 | break; | |
c906108c | 12378 | default: |
3e43a32a MS |
12379 | complaint (&symfile_complaints, |
12380 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 12381 | dwarf_tag_name (die->tag)); |
c906108c SS |
12382 | break; |
12383 | } | |
63d06c5c | 12384 | |
f792889a | 12385 | return this_type; |
63d06c5c DC |
12386 | } |
12387 | ||
abc72ce4 DE |
12388 | /* See if we can figure out if the class lives in a namespace. We do |
12389 | this by looking for a member function; its demangled name will | |
12390 | contain namespace info, if there is any. | |
12391 | Return the computed name or NULL. | |
12392 | Space for the result is allocated on the objfile's obstack. | |
12393 | This is the full-die version of guess_partial_die_structure_name. | |
12394 | In this case we know DIE has no useful parent. */ | |
12395 | ||
12396 | static char * | |
12397 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
12398 | { | |
12399 | struct die_info *spec_die; | |
12400 | struct dwarf2_cu *spec_cu; | |
12401 | struct die_info *child; | |
12402 | ||
12403 | spec_cu = cu; | |
12404 | spec_die = die_specification (die, &spec_cu); | |
12405 | if (spec_die != NULL) | |
12406 | { | |
12407 | die = spec_die; | |
12408 | cu = spec_cu; | |
12409 | } | |
12410 | ||
12411 | for (child = die->child; | |
12412 | child != NULL; | |
12413 | child = child->sibling) | |
12414 | { | |
12415 | if (child->tag == DW_TAG_subprogram) | |
12416 | { | |
12417 | struct attribute *attr; | |
12418 | ||
12419 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
12420 | if (attr == NULL) | |
12421 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
12422 | if (attr != NULL) | |
12423 | { | |
12424 | char *actual_name | |
12425 | = language_class_name_from_physname (cu->language_defn, | |
12426 | DW_STRING (attr)); | |
12427 | char *name = NULL; | |
12428 | ||
12429 | if (actual_name != NULL) | |
12430 | { | |
12431 | char *die_name = dwarf2_name (die, cu); | |
12432 | ||
12433 | if (die_name != NULL | |
12434 | && strcmp (die_name, actual_name) != 0) | |
12435 | { | |
12436 | /* Strip off the class name from the full name. | |
12437 | We want the prefix. */ | |
12438 | int die_name_len = strlen (die_name); | |
12439 | int actual_name_len = strlen (actual_name); | |
12440 | ||
12441 | /* Test for '::' as a sanity check. */ | |
12442 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
12443 | && actual_name[actual_name_len |
12444 | - die_name_len - 1] == ':') | |
abc72ce4 DE |
12445 | name = |
12446 | obsavestring (actual_name, | |
12447 | actual_name_len - die_name_len - 2, | |
12448 | &cu->objfile->objfile_obstack); | |
12449 | } | |
12450 | } | |
12451 | xfree (actual_name); | |
12452 | return name; | |
12453 | } | |
12454 | } | |
12455 | } | |
12456 | ||
12457 | return NULL; | |
12458 | } | |
12459 | ||
96408a79 SA |
12460 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
12461 | prefix part in such case. See | |
12462 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12463 | ||
12464 | static char * | |
12465 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) | |
12466 | { | |
12467 | struct attribute *attr; | |
12468 | char *base; | |
12469 | ||
12470 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type | |
12471 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) | |
12472 | return NULL; | |
12473 | ||
12474 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
12475 | if (attr != NULL && DW_STRING (attr) != NULL) | |
12476 | return NULL; | |
12477 | ||
12478 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12479 | if (attr == NULL) | |
12480 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12481 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12482 | return NULL; | |
12483 | ||
12484 | /* dwarf2_name had to be already called. */ | |
12485 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); | |
12486 | ||
12487 | /* Strip the base name, keep any leading namespaces/classes. */ | |
12488 | base = strrchr (DW_STRING (attr), ':'); | |
12489 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') | |
12490 | return ""; | |
12491 | ||
12492 | return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr), | |
12493 | &cu->objfile->objfile_obstack); | |
12494 | } | |
12495 | ||
fdde2d81 | 12496 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 12497 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 12498 | |
0114d602 DJ |
12499 | For example, if we're within the method foo() in the following |
12500 | code: | |
12501 | ||
12502 | namespace N { | |
12503 | class C { | |
12504 | void foo () { | |
12505 | } | |
12506 | }; | |
12507 | } | |
12508 | ||
12509 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 | 12510 | |
0d5cff50 | 12511 | static const char * |
e142c38c | 12512 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 12513 | { |
0114d602 DJ |
12514 | struct die_info *parent, *spec_die; |
12515 | struct dwarf2_cu *spec_cu; | |
12516 | struct type *parent_type; | |
96408a79 | 12517 | char *retval; |
63d06c5c | 12518 | |
f55ee35c JK |
12519 | if (cu->language != language_cplus && cu->language != language_java |
12520 | && cu->language != language_fortran) | |
0114d602 DJ |
12521 | return ""; |
12522 | ||
96408a79 SA |
12523 | retval = anonymous_struct_prefix (die, cu); |
12524 | if (retval) | |
12525 | return retval; | |
12526 | ||
0114d602 DJ |
12527 | /* We have to be careful in the presence of DW_AT_specification. |
12528 | For example, with GCC 3.4, given the code | |
12529 | ||
12530 | namespace N { | |
12531 | void foo() { | |
12532 | // Definition of N::foo. | |
12533 | } | |
12534 | } | |
12535 | ||
12536 | then we'll have a tree of DIEs like this: | |
12537 | ||
12538 | 1: DW_TAG_compile_unit | |
12539 | 2: DW_TAG_namespace // N | |
12540 | 3: DW_TAG_subprogram // declaration of N::foo | |
12541 | 4: DW_TAG_subprogram // definition of N::foo | |
12542 | DW_AT_specification // refers to die #3 | |
12543 | ||
12544 | Thus, when processing die #4, we have to pretend that we're in | |
12545 | the context of its DW_AT_specification, namely the contex of die | |
12546 | #3. */ | |
12547 | spec_cu = cu; | |
12548 | spec_die = die_specification (die, &spec_cu); | |
12549 | if (spec_die == NULL) | |
12550 | parent = die->parent; | |
12551 | else | |
63d06c5c | 12552 | { |
0114d602 DJ |
12553 | parent = spec_die->parent; |
12554 | cu = spec_cu; | |
63d06c5c | 12555 | } |
0114d602 DJ |
12556 | |
12557 | if (parent == NULL) | |
12558 | return ""; | |
98bfdba5 PA |
12559 | else if (parent->building_fullname) |
12560 | { | |
12561 | const char *name; | |
12562 | const char *parent_name; | |
12563 | ||
12564 | /* It has been seen on RealView 2.2 built binaries, | |
12565 | DW_TAG_template_type_param types actually _defined_ as | |
12566 | children of the parent class: | |
12567 | ||
12568 | enum E {}; | |
12569 | template class <class Enum> Class{}; | |
12570 | Class<enum E> class_e; | |
12571 | ||
12572 | 1: DW_TAG_class_type (Class) | |
12573 | 2: DW_TAG_enumeration_type (E) | |
12574 | 3: DW_TAG_enumerator (enum1:0) | |
12575 | 3: DW_TAG_enumerator (enum2:1) | |
12576 | ... | |
12577 | 2: DW_TAG_template_type_param | |
12578 | DW_AT_type DW_FORM_ref_udata (E) | |
12579 | ||
12580 | Besides being broken debug info, it can put GDB into an | |
12581 | infinite loop. Consider: | |
12582 | ||
12583 | When we're building the full name for Class<E>, we'll start | |
12584 | at Class, and go look over its template type parameters, | |
12585 | finding E. We'll then try to build the full name of E, and | |
12586 | reach here. We're now trying to build the full name of E, | |
12587 | and look over the parent DIE for containing scope. In the | |
12588 | broken case, if we followed the parent DIE of E, we'd again | |
12589 | find Class, and once again go look at its template type | |
12590 | arguments, etc., etc. Simply don't consider such parent die | |
12591 | as source-level parent of this die (it can't be, the language | |
12592 | doesn't allow it), and break the loop here. */ | |
12593 | name = dwarf2_name (die, cu); | |
12594 | parent_name = dwarf2_name (parent, cu); | |
12595 | complaint (&symfile_complaints, | |
12596 | _("template param type '%s' defined within parent '%s'"), | |
12597 | name ? name : "<unknown>", | |
12598 | parent_name ? parent_name : "<unknown>"); | |
12599 | return ""; | |
12600 | } | |
63d06c5c | 12601 | else |
0114d602 DJ |
12602 | switch (parent->tag) |
12603 | { | |
63d06c5c | 12604 | case DW_TAG_namespace: |
0114d602 | 12605 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
12606 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
12607 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
12608 | Work around this problem here. */ | |
12609 | if (cu->language == language_cplus | |
12610 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
12611 | return ""; | |
0114d602 DJ |
12612 | /* We give a name to even anonymous namespaces. */ |
12613 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 12614 | case DW_TAG_class_type: |
680b30c7 | 12615 | case DW_TAG_interface_type: |
63d06c5c | 12616 | case DW_TAG_structure_type: |
0114d602 | 12617 | case DW_TAG_union_type: |
f55ee35c | 12618 | case DW_TAG_module: |
0114d602 DJ |
12619 | parent_type = read_type_die (parent, cu); |
12620 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
12621 | return TYPE_TAG_NAME (parent_type); | |
12622 | else | |
12623 | /* An anonymous structure is only allowed non-static data | |
12624 | members; no typedefs, no member functions, et cetera. | |
12625 | So it does not need a prefix. */ | |
12626 | return ""; | |
abc72ce4 DE |
12627 | case DW_TAG_compile_unit: |
12628 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ | |
12629 | if (cu->language == language_cplus | |
8b70b953 | 12630 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
12631 | && die->child != NULL |
12632 | && (die->tag == DW_TAG_class_type | |
12633 | || die->tag == DW_TAG_structure_type | |
12634 | || die->tag == DW_TAG_union_type)) | |
12635 | { | |
12636 | char *name = guess_full_die_structure_name (die, cu); | |
12637 | if (name != NULL) | |
12638 | return name; | |
12639 | } | |
12640 | return ""; | |
63d06c5c | 12641 | default: |
8176b9b8 | 12642 | return determine_prefix (parent, cu); |
63d06c5c | 12643 | } |
63d06c5c DC |
12644 | } |
12645 | ||
3e43a32a MS |
12646 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
12647 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
12648 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
12649 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
12650 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 12651 | |
f55ee35c | 12652 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
12653 | |
12654 | static char * | |
f55ee35c JK |
12655 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
12656 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 12657 | { |
f55ee35c | 12658 | const char *lead = ""; |
5c315b68 | 12659 | const char *sep; |
63d06c5c | 12660 | |
3e43a32a MS |
12661 | if (suffix == NULL || suffix[0] == '\0' |
12662 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
12663 | sep = ""; |
12664 | else if (cu->language == language_java) | |
12665 | sep = "."; | |
f55ee35c JK |
12666 | else if (cu->language == language_fortran && physname) |
12667 | { | |
12668 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
12669 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
12670 | ||
12671 | lead = "__"; | |
12672 | sep = "_MOD_"; | |
12673 | } | |
987504bb JJ |
12674 | else |
12675 | sep = "::"; | |
63d06c5c | 12676 | |
6dd47d34 DE |
12677 | if (prefix == NULL) |
12678 | prefix = ""; | |
12679 | if (suffix == NULL) | |
12680 | suffix = ""; | |
12681 | ||
987504bb JJ |
12682 | if (obs == NULL) |
12683 | { | |
3e43a32a MS |
12684 | char *retval |
12685 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 12686 | |
f55ee35c JK |
12687 | strcpy (retval, lead); |
12688 | strcat (retval, prefix); | |
6dd47d34 DE |
12689 | strcat (retval, sep); |
12690 | strcat (retval, suffix); | |
63d06c5c DC |
12691 | return retval; |
12692 | } | |
987504bb JJ |
12693 | else |
12694 | { | |
12695 | /* We have an obstack. */ | |
f55ee35c | 12696 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 12697 | } |
63d06c5c DC |
12698 | } |
12699 | ||
c906108c SS |
12700 | /* Return sibling of die, NULL if no sibling. */ |
12701 | ||
f9aca02d | 12702 | static struct die_info * |
fba45db2 | 12703 | sibling_die (struct die_info *die) |
c906108c | 12704 | { |
639d11d3 | 12705 | return die->sibling; |
c906108c SS |
12706 | } |
12707 | ||
71c25dea TT |
12708 | /* Get name of a die, return NULL if not found. */ |
12709 | ||
12710 | static char * | |
12711 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
12712 | struct obstack *obstack) | |
12713 | { | |
12714 | if (name && cu->language == language_cplus) | |
12715 | { | |
12716 | char *canon_name = cp_canonicalize_string (name); | |
12717 | ||
12718 | if (canon_name != NULL) | |
12719 | { | |
12720 | if (strcmp (canon_name, name) != 0) | |
12721 | name = obsavestring (canon_name, strlen (canon_name), | |
12722 | obstack); | |
12723 | xfree (canon_name); | |
12724 | } | |
12725 | } | |
12726 | ||
12727 | return name; | |
c906108c SS |
12728 | } |
12729 | ||
9219021c DC |
12730 | /* Get name of a die, return NULL if not found. */ |
12731 | ||
12732 | static char * | |
e142c38c | 12733 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
12734 | { |
12735 | struct attribute *attr; | |
12736 | ||
e142c38c | 12737 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
12738 | if ((!attr || !DW_STRING (attr)) |
12739 | && die->tag != DW_TAG_class_type | |
12740 | && die->tag != DW_TAG_interface_type | |
12741 | && die->tag != DW_TAG_structure_type | |
12742 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
12743 | return NULL; |
12744 | ||
12745 | switch (die->tag) | |
12746 | { | |
12747 | case DW_TAG_compile_unit: | |
12748 | /* Compilation units have a DW_AT_name that is a filename, not | |
12749 | a source language identifier. */ | |
12750 | case DW_TAG_enumeration_type: | |
12751 | case DW_TAG_enumerator: | |
12752 | /* These tags always have simple identifiers already; no need | |
12753 | to canonicalize them. */ | |
12754 | return DW_STRING (attr); | |
907af001 | 12755 | |
418835cc KS |
12756 | case DW_TAG_subprogram: |
12757 | /* Java constructors will all be named "<init>", so return | |
12758 | the class name when we see this special case. */ | |
12759 | if (cu->language == language_java | |
12760 | && DW_STRING (attr) != NULL | |
12761 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
12762 | { | |
12763 | struct dwarf2_cu *spec_cu = cu; | |
12764 | struct die_info *spec_die; | |
12765 | ||
12766 | /* GCJ will output '<init>' for Java constructor names. | |
12767 | For this special case, return the name of the parent class. */ | |
12768 | ||
12769 | /* GCJ may output suprogram DIEs with AT_specification set. | |
12770 | If so, use the name of the specified DIE. */ | |
12771 | spec_die = die_specification (die, &spec_cu); | |
12772 | if (spec_die != NULL) | |
12773 | return dwarf2_name (spec_die, spec_cu); | |
12774 | ||
12775 | do | |
12776 | { | |
12777 | die = die->parent; | |
12778 | if (die->tag == DW_TAG_class_type) | |
12779 | return dwarf2_name (die, cu); | |
12780 | } | |
12781 | while (die->tag != DW_TAG_compile_unit); | |
12782 | } | |
907af001 UW |
12783 | break; |
12784 | ||
12785 | case DW_TAG_class_type: | |
12786 | case DW_TAG_interface_type: | |
12787 | case DW_TAG_structure_type: | |
12788 | case DW_TAG_union_type: | |
12789 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
12790 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
12791 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
12792 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
12793 | if (attr && DW_STRING (attr) |
12794 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
12795 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 12796 | return NULL; |
53832f31 TT |
12797 | |
12798 | /* GCC might emit a nameless typedef that has a linkage name. See | |
12799 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12800 | if (!attr || DW_STRING (attr) == NULL) | |
12801 | { | |
df5c6c50 | 12802 | char *demangled = NULL; |
53832f31 TT |
12803 | |
12804 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12805 | if (attr == NULL) | |
12806 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12807 | ||
12808 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12809 | return NULL; | |
12810 | ||
df5c6c50 JK |
12811 | /* Avoid demangling DW_STRING (attr) the second time on a second |
12812 | call for the same DIE. */ | |
12813 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12814 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
12815 | |
12816 | if (demangled) | |
12817 | { | |
96408a79 SA |
12818 | char *base; |
12819 | ||
53832f31 | 12820 | /* FIXME: we already did this for the partial symbol... */ |
96408a79 SA |
12821 | DW_STRING (attr) = obsavestring (demangled, strlen (demangled), |
12822 | &cu->objfile->objfile_obstack); | |
53832f31 TT |
12823 | DW_STRING_IS_CANONICAL (attr) = 1; |
12824 | xfree (demangled); | |
96408a79 SA |
12825 | |
12826 | /* Strip any leading namespaces/classes, keep only the base name. | |
12827 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
12828 | base = strrchr (DW_STRING (attr), ':'); | |
12829 | if (base && base > DW_STRING (attr) && base[-1] == ':') | |
12830 | return &base[1]; | |
12831 | else | |
12832 | return DW_STRING (attr); | |
53832f31 TT |
12833 | } |
12834 | } | |
907af001 UW |
12835 | break; |
12836 | ||
71c25dea | 12837 | default: |
907af001 UW |
12838 | break; |
12839 | } | |
12840 | ||
12841 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12842 | { | |
12843 | DW_STRING (attr) | |
12844 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
12845 | &cu->objfile->objfile_obstack); | |
12846 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 12847 | } |
907af001 | 12848 | return DW_STRING (attr); |
9219021c DC |
12849 | } |
12850 | ||
12851 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
12852 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
12853 | containing the return value on output. */ | |
9219021c DC |
12854 | |
12855 | static struct die_info * | |
f2f0e013 | 12856 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
12857 | { |
12858 | struct attribute *attr; | |
9219021c | 12859 | |
f2f0e013 | 12860 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
12861 | if (attr == NULL) |
12862 | return NULL; | |
12863 | ||
f2f0e013 | 12864 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
12865 | } |
12866 | ||
c906108c SS |
12867 | /* Convert a DIE tag into its string name. */ |
12868 | ||
12869 | static char * | |
aa1ee363 | 12870 | dwarf_tag_name (unsigned tag) |
c906108c SS |
12871 | { |
12872 | switch (tag) | |
12873 | { | |
12874 | case DW_TAG_padding: | |
12875 | return "DW_TAG_padding"; | |
12876 | case DW_TAG_array_type: | |
12877 | return "DW_TAG_array_type"; | |
12878 | case DW_TAG_class_type: | |
12879 | return "DW_TAG_class_type"; | |
12880 | case DW_TAG_entry_point: | |
12881 | return "DW_TAG_entry_point"; | |
12882 | case DW_TAG_enumeration_type: | |
12883 | return "DW_TAG_enumeration_type"; | |
12884 | case DW_TAG_formal_parameter: | |
12885 | return "DW_TAG_formal_parameter"; | |
12886 | case DW_TAG_imported_declaration: | |
12887 | return "DW_TAG_imported_declaration"; | |
12888 | case DW_TAG_label: | |
12889 | return "DW_TAG_label"; | |
12890 | case DW_TAG_lexical_block: | |
12891 | return "DW_TAG_lexical_block"; | |
12892 | case DW_TAG_member: | |
12893 | return "DW_TAG_member"; | |
12894 | case DW_TAG_pointer_type: | |
12895 | return "DW_TAG_pointer_type"; | |
12896 | case DW_TAG_reference_type: | |
12897 | return "DW_TAG_reference_type"; | |
12898 | case DW_TAG_compile_unit: | |
12899 | return "DW_TAG_compile_unit"; | |
12900 | case DW_TAG_string_type: | |
12901 | return "DW_TAG_string_type"; | |
12902 | case DW_TAG_structure_type: | |
12903 | return "DW_TAG_structure_type"; | |
12904 | case DW_TAG_subroutine_type: | |
12905 | return "DW_TAG_subroutine_type"; | |
12906 | case DW_TAG_typedef: | |
12907 | return "DW_TAG_typedef"; | |
12908 | case DW_TAG_union_type: | |
12909 | return "DW_TAG_union_type"; | |
12910 | case DW_TAG_unspecified_parameters: | |
12911 | return "DW_TAG_unspecified_parameters"; | |
12912 | case DW_TAG_variant: | |
12913 | return "DW_TAG_variant"; | |
12914 | case DW_TAG_common_block: | |
12915 | return "DW_TAG_common_block"; | |
12916 | case DW_TAG_common_inclusion: | |
12917 | return "DW_TAG_common_inclusion"; | |
12918 | case DW_TAG_inheritance: | |
12919 | return "DW_TAG_inheritance"; | |
12920 | case DW_TAG_inlined_subroutine: | |
12921 | return "DW_TAG_inlined_subroutine"; | |
12922 | case DW_TAG_module: | |
12923 | return "DW_TAG_module"; | |
12924 | case DW_TAG_ptr_to_member_type: | |
12925 | return "DW_TAG_ptr_to_member_type"; | |
12926 | case DW_TAG_set_type: | |
12927 | return "DW_TAG_set_type"; | |
12928 | case DW_TAG_subrange_type: | |
12929 | return "DW_TAG_subrange_type"; | |
12930 | case DW_TAG_with_stmt: | |
12931 | return "DW_TAG_with_stmt"; | |
12932 | case DW_TAG_access_declaration: | |
12933 | return "DW_TAG_access_declaration"; | |
12934 | case DW_TAG_base_type: | |
12935 | return "DW_TAG_base_type"; | |
12936 | case DW_TAG_catch_block: | |
12937 | return "DW_TAG_catch_block"; | |
12938 | case DW_TAG_const_type: | |
12939 | return "DW_TAG_const_type"; | |
12940 | case DW_TAG_constant: | |
12941 | return "DW_TAG_constant"; | |
12942 | case DW_TAG_enumerator: | |
12943 | return "DW_TAG_enumerator"; | |
12944 | case DW_TAG_file_type: | |
12945 | return "DW_TAG_file_type"; | |
12946 | case DW_TAG_friend: | |
12947 | return "DW_TAG_friend"; | |
12948 | case DW_TAG_namelist: | |
12949 | return "DW_TAG_namelist"; | |
12950 | case DW_TAG_namelist_item: | |
12951 | return "DW_TAG_namelist_item"; | |
12952 | case DW_TAG_packed_type: | |
12953 | return "DW_TAG_packed_type"; | |
12954 | case DW_TAG_subprogram: | |
12955 | return "DW_TAG_subprogram"; | |
12956 | case DW_TAG_template_type_param: | |
12957 | return "DW_TAG_template_type_param"; | |
12958 | case DW_TAG_template_value_param: | |
12959 | return "DW_TAG_template_value_param"; | |
12960 | case DW_TAG_thrown_type: | |
12961 | return "DW_TAG_thrown_type"; | |
12962 | case DW_TAG_try_block: | |
12963 | return "DW_TAG_try_block"; | |
12964 | case DW_TAG_variant_part: | |
12965 | return "DW_TAG_variant_part"; | |
12966 | case DW_TAG_variable: | |
12967 | return "DW_TAG_variable"; | |
12968 | case DW_TAG_volatile_type: | |
12969 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
12970 | case DW_TAG_dwarf_procedure: |
12971 | return "DW_TAG_dwarf_procedure"; | |
12972 | case DW_TAG_restrict_type: | |
12973 | return "DW_TAG_restrict_type"; | |
12974 | case DW_TAG_interface_type: | |
12975 | return "DW_TAG_interface_type"; | |
12976 | case DW_TAG_namespace: | |
12977 | return "DW_TAG_namespace"; | |
12978 | case DW_TAG_imported_module: | |
12979 | return "DW_TAG_imported_module"; | |
12980 | case DW_TAG_unspecified_type: | |
12981 | return "DW_TAG_unspecified_type"; | |
12982 | case DW_TAG_partial_unit: | |
12983 | return "DW_TAG_partial_unit"; | |
12984 | case DW_TAG_imported_unit: | |
12985 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
12986 | case DW_TAG_condition: |
12987 | return "DW_TAG_condition"; | |
12988 | case DW_TAG_shared_type: | |
12989 | return "DW_TAG_shared_type"; | |
348e048f DE |
12990 | case DW_TAG_type_unit: |
12991 | return "DW_TAG_type_unit"; | |
c906108c SS |
12992 | case DW_TAG_MIPS_loop: |
12993 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
12994 | case DW_TAG_HP_array_descriptor: |
12995 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
12996 | case DW_TAG_format_label: |
12997 | return "DW_TAG_format_label"; | |
12998 | case DW_TAG_function_template: | |
12999 | return "DW_TAG_function_template"; | |
13000 | case DW_TAG_class_template: | |
13001 | return "DW_TAG_class_template"; | |
b7619582 GF |
13002 | case DW_TAG_GNU_BINCL: |
13003 | return "DW_TAG_GNU_BINCL"; | |
13004 | case DW_TAG_GNU_EINCL: | |
13005 | return "DW_TAG_GNU_EINCL"; | |
13006 | case DW_TAG_upc_shared_type: | |
13007 | return "DW_TAG_upc_shared_type"; | |
13008 | case DW_TAG_upc_strict_type: | |
13009 | return "DW_TAG_upc_strict_type"; | |
13010 | case DW_TAG_upc_relaxed_type: | |
13011 | return "DW_TAG_upc_relaxed_type"; | |
13012 | case DW_TAG_PGI_kanji_type: | |
13013 | return "DW_TAG_PGI_kanji_type"; | |
13014 | case DW_TAG_PGI_interface_block: | |
13015 | return "DW_TAG_PGI_interface_block"; | |
96408a79 SA |
13016 | case DW_TAG_GNU_call_site: |
13017 | return "DW_TAG_GNU_call_site"; | |
c906108c SS |
13018 | default: |
13019 | return "DW_TAG_<unknown>"; | |
13020 | } | |
13021 | } | |
13022 | ||
13023 | /* Convert a DWARF attribute code into its string name. */ | |
13024 | ||
13025 | static char * | |
aa1ee363 | 13026 | dwarf_attr_name (unsigned attr) |
c906108c SS |
13027 | { |
13028 | switch (attr) | |
13029 | { | |
13030 | case DW_AT_sibling: | |
13031 | return "DW_AT_sibling"; | |
13032 | case DW_AT_location: | |
13033 | return "DW_AT_location"; | |
13034 | case DW_AT_name: | |
13035 | return "DW_AT_name"; | |
13036 | case DW_AT_ordering: | |
13037 | return "DW_AT_ordering"; | |
13038 | case DW_AT_subscr_data: | |
13039 | return "DW_AT_subscr_data"; | |
13040 | case DW_AT_byte_size: | |
13041 | return "DW_AT_byte_size"; | |
13042 | case DW_AT_bit_offset: | |
13043 | return "DW_AT_bit_offset"; | |
13044 | case DW_AT_bit_size: | |
13045 | return "DW_AT_bit_size"; | |
13046 | case DW_AT_element_list: | |
13047 | return "DW_AT_element_list"; | |
13048 | case DW_AT_stmt_list: | |
13049 | return "DW_AT_stmt_list"; | |
13050 | case DW_AT_low_pc: | |
13051 | return "DW_AT_low_pc"; | |
13052 | case DW_AT_high_pc: | |
13053 | return "DW_AT_high_pc"; | |
13054 | case DW_AT_language: | |
13055 | return "DW_AT_language"; | |
13056 | case DW_AT_member: | |
13057 | return "DW_AT_member"; | |
13058 | case DW_AT_discr: | |
13059 | return "DW_AT_discr"; | |
13060 | case DW_AT_discr_value: | |
13061 | return "DW_AT_discr_value"; | |
13062 | case DW_AT_visibility: | |
13063 | return "DW_AT_visibility"; | |
13064 | case DW_AT_import: | |
13065 | return "DW_AT_import"; | |
13066 | case DW_AT_string_length: | |
13067 | return "DW_AT_string_length"; | |
13068 | case DW_AT_common_reference: | |
13069 | return "DW_AT_common_reference"; | |
13070 | case DW_AT_comp_dir: | |
13071 | return "DW_AT_comp_dir"; | |
13072 | case DW_AT_const_value: | |
13073 | return "DW_AT_const_value"; | |
13074 | case DW_AT_containing_type: | |
13075 | return "DW_AT_containing_type"; | |
13076 | case DW_AT_default_value: | |
13077 | return "DW_AT_default_value"; | |
13078 | case DW_AT_inline: | |
13079 | return "DW_AT_inline"; | |
13080 | case DW_AT_is_optional: | |
13081 | return "DW_AT_is_optional"; | |
13082 | case DW_AT_lower_bound: | |
13083 | return "DW_AT_lower_bound"; | |
13084 | case DW_AT_producer: | |
13085 | return "DW_AT_producer"; | |
13086 | case DW_AT_prototyped: | |
13087 | return "DW_AT_prototyped"; | |
13088 | case DW_AT_return_addr: | |
13089 | return "DW_AT_return_addr"; | |
13090 | case DW_AT_start_scope: | |
13091 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
13092 | case DW_AT_bit_stride: |
13093 | return "DW_AT_bit_stride"; | |
c906108c SS |
13094 | case DW_AT_upper_bound: |
13095 | return "DW_AT_upper_bound"; | |
13096 | case DW_AT_abstract_origin: | |
13097 | return "DW_AT_abstract_origin"; | |
13098 | case DW_AT_accessibility: | |
13099 | return "DW_AT_accessibility"; | |
13100 | case DW_AT_address_class: | |
13101 | return "DW_AT_address_class"; | |
13102 | case DW_AT_artificial: | |
13103 | return "DW_AT_artificial"; | |
13104 | case DW_AT_base_types: | |
13105 | return "DW_AT_base_types"; | |
13106 | case DW_AT_calling_convention: | |
13107 | return "DW_AT_calling_convention"; | |
13108 | case DW_AT_count: | |
13109 | return "DW_AT_count"; | |
13110 | case DW_AT_data_member_location: | |
13111 | return "DW_AT_data_member_location"; | |
13112 | case DW_AT_decl_column: | |
13113 | return "DW_AT_decl_column"; | |
13114 | case DW_AT_decl_file: | |
13115 | return "DW_AT_decl_file"; | |
13116 | case DW_AT_decl_line: | |
13117 | return "DW_AT_decl_line"; | |
13118 | case DW_AT_declaration: | |
13119 | return "DW_AT_declaration"; | |
13120 | case DW_AT_discr_list: | |
13121 | return "DW_AT_discr_list"; | |
13122 | case DW_AT_encoding: | |
13123 | return "DW_AT_encoding"; | |
13124 | case DW_AT_external: | |
13125 | return "DW_AT_external"; | |
13126 | case DW_AT_frame_base: | |
13127 | return "DW_AT_frame_base"; | |
13128 | case DW_AT_friend: | |
13129 | return "DW_AT_friend"; | |
13130 | case DW_AT_identifier_case: | |
13131 | return "DW_AT_identifier_case"; | |
13132 | case DW_AT_macro_info: | |
13133 | return "DW_AT_macro_info"; | |
13134 | case DW_AT_namelist_items: | |
13135 | return "DW_AT_namelist_items"; | |
13136 | case DW_AT_priority: | |
13137 | return "DW_AT_priority"; | |
13138 | case DW_AT_segment: | |
13139 | return "DW_AT_segment"; | |
13140 | case DW_AT_specification: | |
13141 | return "DW_AT_specification"; | |
13142 | case DW_AT_static_link: | |
13143 | return "DW_AT_static_link"; | |
13144 | case DW_AT_type: | |
13145 | return "DW_AT_type"; | |
13146 | case DW_AT_use_location: | |
13147 | return "DW_AT_use_location"; | |
13148 | case DW_AT_variable_parameter: | |
13149 | return "DW_AT_variable_parameter"; | |
13150 | case DW_AT_virtuality: | |
13151 | return "DW_AT_virtuality"; | |
13152 | case DW_AT_vtable_elem_location: | |
13153 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 13154 | /* DWARF 3 values. */ |
d9fa45fe DC |
13155 | case DW_AT_allocated: |
13156 | return "DW_AT_allocated"; | |
13157 | case DW_AT_associated: | |
13158 | return "DW_AT_associated"; | |
13159 | case DW_AT_data_location: | |
13160 | return "DW_AT_data_location"; | |
09fa0d7c JK |
13161 | case DW_AT_byte_stride: |
13162 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
13163 | case DW_AT_entry_pc: |
13164 | return "DW_AT_entry_pc"; | |
13165 | case DW_AT_use_UTF8: | |
13166 | return "DW_AT_use_UTF8"; | |
13167 | case DW_AT_extension: | |
13168 | return "DW_AT_extension"; | |
13169 | case DW_AT_ranges: | |
13170 | return "DW_AT_ranges"; | |
13171 | case DW_AT_trampoline: | |
13172 | return "DW_AT_trampoline"; | |
13173 | case DW_AT_call_column: | |
13174 | return "DW_AT_call_column"; | |
13175 | case DW_AT_call_file: | |
13176 | return "DW_AT_call_file"; | |
13177 | case DW_AT_call_line: | |
13178 | return "DW_AT_call_line"; | |
b7619582 GF |
13179 | case DW_AT_description: |
13180 | return "DW_AT_description"; | |
13181 | case DW_AT_binary_scale: | |
13182 | return "DW_AT_binary_scale"; | |
13183 | case DW_AT_decimal_scale: | |
13184 | return "DW_AT_decimal_scale"; | |
13185 | case DW_AT_small: | |
13186 | return "DW_AT_small"; | |
13187 | case DW_AT_decimal_sign: | |
13188 | return "DW_AT_decimal_sign"; | |
13189 | case DW_AT_digit_count: | |
13190 | return "DW_AT_digit_count"; | |
13191 | case DW_AT_picture_string: | |
13192 | return "DW_AT_picture_string"; | |
13193 | case DW_AT_mutable: | |
13194 | return "DW_AT_mutable"; | |
13195 | case DW_AT_threads_scaled: | |
13196 | return "DW_AT_threads_scaled"; | |
13197 | case DW_AT_explicit: | |
13198 | return "DW_AT_explicit"; | |
13199 | case DW_AT_object_pointer: | |
13200 | return "DW_AT_object_pointer"; | |
13201 | case DW_AT_endianity: | |
13202 | return "DW_AT_endianity"; | |
13203 | case DW_AT_elemental: | |
13204 | return "DW_AT_elemental"; | |
13205 | case DW_AT_pure: | |
13206 | return "DW_AT_pure"; | |
13207 | case DW_AT_recursive: | |
13208 | return "DW_AT_recursive"; | |
348e048f DE |
13209 | /* DWARF 4 values. */ |
13210 | case DW_AT_signature: | |
13211 | return "DW_AT_signature"; | |
31ef98ae TT |
13212 | case DW_AT_linkage_name: |
13213 | return "DW_AT_linkage_name"; | |
b7619582 | 13214 | /* SGI/MIPS extensions. */ |
c764a876 | 13215 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
13216 | case DW_AT_MIPS_fde: |
13217 | return "DW_AT_MIPS_fde"; | |
c764a876 | 13218 | #endif |
c906108c SS |
13219 | case DW_AT_MIPS_loop_begin: |
13220 | return "DW_AT_MIPS_loop_begin"; | |
13221 | case DW_AT_MIPS_tail_loop_begin: | |
13222 | return "DW_AT_MIPS_tail_loop_begin"; | |
13223 | case DW_AT_MIPS_epilog_begin: | |
13224 | return "DW_AT_MIPS_epilog_begin"; | |
13225 | case DW_AT_MIPS_loop_unroll_factor: | |
13226 | return "DW_AT_MIPS_loop_unroll_factor"; | |
13227 | case DW_AT_MIPS_software_pipeline_depth: | |
13228 | return "DW_AT_MIPS_software_pipeline_depth"; | |
13229 | case DW_AT_MIPS_linkage_name: | |
13230 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
13231 | case DW_AT_MIPS_stride: |
13232 | return "DW_AT_MIPS_stride"; | |
13233 | case DW_AT_MIPS_abstract_name: | |
13234 | return "DW_AT_MIPS_abstract_name"; | |
13235 | case DW_AT_MIPS_clone_origin: | |
13236 | return "DW_AT_MIPS_clone_origin"; | |
13237 | case DW_AT_MIPS_has_inlines: | |
13238 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 13239 | /* HP extensions. */ |
c764a876 | 13240 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
13241 | case DW_AT_HP_block_index: |
13242 | return "DW_AT_HP_block_index"; | |
c764a876 | 13243 | #endif |
b7619582 GF |
13244 | case DW_AT_HP_unmodifiable: |
13245 | return "DW_AT_HP_unmodifiable"; | |
13246 | case DW_AT_HP_actuals_stmt_list: | |
13247 | return "DW_AT_HP_actuals_stmt_list"; | |
13248 | case DW_AT_HP_proc_per_section: | |
13249 | return "DW_AT_HP_proc_per_section"; | |
13250 | case DW_AT_HP_raw_data_ptr: | |
13251 | return "DW_AT_HP_raw_data_ptr"; | |
13252 | case DW_AT_HP_pass_by_reference: | |
13253 | return "DW_AT_HP_pass_by_reference"; | |
13254 | case DW_AT_HP_opt_level: | |
13255 | return "DW_AT_HP_opt_level"; | |
13256 | case DW_AT_HP_prof_version_id: | |
13257 | return "DW_AT_HP_prof_version_id"; | |
13258 | case DW_AT_HP_opt_flags: | |
13259 | return "DW_AT_HP_opt_flags"; | |
13260 | case DW_AT_HP_cold_region_low_pc: | |
13261 | return "DW_AT_HP_cold_region_low_pc"; | |
13262 | case DW_AT_HP_cold_region_high_pc: | |
13263 | return "DW_AT_HP_cold_region_high_pc"; | |
13264 | case DW_AT_HP_all_variables_modifiable: | |
13265 | return "DW_AT_HP_all_variables_modifiable"; | |
13266 | case DW_AT_HP_linkage_name: | |
13267 | return "DW_AT_HP_linkage_name"; | |
13268 | case DW_AT_HP_prof_flags: | |
13269 | return "DW_AT_HP_prof_flags"; | |
13270 | /* GNU extensions. */ | |
c906108c SS |
13271 | case DW_AT_sf_names: |
13272 | return "DW_AT_sf_names"; | |
13273 | case DW_AT_src_info: | |
13274 | return "DW_AT_src_info"; | |
13275 | case DW_AT_mac_info: | |
13276 | return "DW_AT_mac_info"; | |
13277 | case DW_AT_src_coords: | |
13278 | return "DW_AT_src_coords"; | |
13279 | case DW_AT_body_begin: | |
13280 | return "DW_AT_body_begin"; | |
13281 | case DW_AT_body_end: | |
13282 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
13283 | case DW_AT_GNU_vector: |
13284 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
13285 | case DW_AT_GNU_odr_signature: |
13286 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
13287 | /* VMS extensions. */ |
13288 | case DW_AT_VMS_rtnbeg_pd_address: | |
13289 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
13290 | /* UPC extension. */ | |
13291 | case DW_AT_upc_threads_scaled: | |
13292 | return "DW_AT_upc_threads_scaled"; | |
13293 | /* PGI (STMicroelectronics) extensions. */ | |
13294 | case DW_AT_PGI_lbase: | |
13295 | return "DW_AT_PGI_lbase"; | |
13296 | case DW_AT_PGI_soffset: | |
13297 | return "DW_AT_PGI_soffset"; | |
13298 | case DW_AT_PGI_lstride: | |
13299 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
13300 | default: |
13301 | return "DW_AT_<unknown>"; | |
13302 | } | |
13303 | } | |
13304 | ||
13305 | /* Convert a DWARF value form code into its string name. */ | |
13306 | ||
13307 | static char * | |
aa1ee363 | 13308 | dwarf_form_name (unsigned form) |
c906108c SS |
13309 | { |
13310 | switch (form) | |
13311 | { | |
13312 | case DW_FORM_addr: | |
13313 | return "DW_FORM_addr"; | |
13314 | case DW_FORM_block2: | |
13315 | return "DW_FORM_block2"; | |
13316 | case DW_FORM_block4: | |
13317 | return "DW_FORM_block4"; | |
13318 | case DW_FORM_data2: | |
13319 | return "DW_FORM_data2"; | |
13320 | case DW_FORM_data4: | |
13321 | return "DW_FORM_data4"; | |
13322 | case DW_FORM_data8: | |
13323 | return "DW_FORM_data8"; | |
13324 | case DW_FORM_string: | |
13325 | return "DW_FORM_string"; | |
13326 | case DW_FORM_block: | |
13327 | return "DW_FORM_block"; | |
13328 | case DW_FORM_block1: | |
13329 | return "DW_FORM_block1"; | |
13330 | case DW_FORM_data1: | |
13331 | return "DW_FORM_data1"; | |
13332 | case DW_FORM_flag: | |
13333 | return "DW_FORM_flag"; | |
13334 | case DW_FORM_sdata: | |
13335 | return "DW_FORM_sdata"; | |
13336 | case DW_FORM_strp: | |
13337 | return "DW_FORM_strp"; | |
13338 | case DW_FORM_udata: | |
13339 | return "DW_FORM_udata"; | |
13340 | case DW_FORM_ref_addr: | |
13341 | return "DW_FORM_ref_addr"; | |
13342 | case DW_FORM_ref1: | |
13343 | return "DW_FORM_ref1"; | |
13344 | case DW_FORM_ref2: | |
13345 | return "DW_FORM_ref2"; | |
13346 | case DW_FORM_ref4: | |
13347 | return "DW_FORM_ref4"; | |
13348 | case DW_FORM_ref8: | |
13349 | return "DW_FORM_ref8"; | |
13350 | case DW_FORM_ref_udata: | |
13351 | return "DW_FORM_ref_udata"; | |
13352 | case DW_FORM_indirect: | |
13353 | return "DW_FORM_indirect"; | |
348e048f DE |
13354 | case DW_FORM_sec_offset: |
13355 | return "DW_FORM_sec_offset"; | |
13356 | case DW_FORM_exprloc: | |
13357 | return "DW_FORM_exprloc"; | |
13358 | case DW_FORM_flag_present: | |
13359 | return "DW_FORM_flag_present"; | |
55f1336d TT |
13360 | case DW_FORM_ref_sig8: |
13361 | return "DW_FORM_ref_sig8"; | |
c906108c SS |
13362 | default: |
13363 | return "DW_FORM_<unknown>"; | |
13364 | } | |
13365 | } | |
13366 | ||
13367 | /* Convert a DWARF stack opcode into its string name. */ | |
13368 | ||
9eae7c52 | 13369 | const char * |
b1bfef65 | 13370 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
13371 | { |
13372 | switch (op) | |
13373 | { | |
13374 | case DW_OP_addr: | |
13375 | return "DW_OP_addr"; | |
13376 | case DW_OP_deref: | |
13377 | return "DW_OP_deref"; | |
13378 | case DW_OP_const1u: | |
13379 | return "DW_OP_const1u"; | |
13380 | case DW_OP_const1s: | |
13381 | return "DW_OP_const1s"; | |
13382 | case DW_OP_const2u: | |
13383 | return "DW_OP_const2u"; | |
13384 | case DW_OP_const2s: | |
13385 | return "DW_OP_const2s"; | |
13386 | case DW_OP_const4u: | |
13387 | return "DW_OP_const4u"; | |
13388 | case DW_OP_const4s: | |
13389 | return "DW_OP_const4s"; | |
13390 | case DW_OP_const8u: | |
13391 | return "DW_OP_const8u"; | |
13392 | case DW_OP_const8s: | |
13393 | return "DW_OP_const8s"; | |
13394 | case DW_OP_constu: | |
13395 | return "DW_OP_constu"; | |
13396 | case DW_OP_consts: | |
13397 | return "DW_OP_consts"; | |
13398 | case DW_OP_dup: | |
13399 | return "DW_OP_dup"; | |
13400 | case DW_OP_drop: | |
13401 | return "DW_OP_drop"; | |
13402 | case DW_OP_over: | |
13403 | return "DW_OP_over"; | |
13404 | case DW_OP_pick: | |
13405 | return "DW_OP_pick"; | |
13406 | case DW_OP_swap: | |
13407 | return "DW_OP_swap"; | |
13408 | case DW_OP_rot: | |
13409 | return "DW_OP_rot"; | |
13410 | case DW_OP_xderef: | |
13411 | return "DW_OP_xderef"; | |
13412 | case DW_OP_abs: | |
13413 | return "DW_OP_abs"; | |
13414 | case DW_OP_and: | |
13415 | return "DW_OP_and"; | |
13416 | case DW_OP_div: | |
13417 | return "DW_OP_div"; | |
13418 | case DW_OP_minus: | |
13419 | return "DW_OP_minus"; | |
13420 | case DW_OP_mod: | |
13421 | return "DW_OP_mod"; | |
13422 | case DW_OP_mul: | |
13423 | return "DW_OP_mul"; | |
13424 | case DW_OP_neg: | |
13425 | return "DW_OP_neg"; | |
13426 | case DW_OP_not: | |
13427 | return "DW_OP_not"; | |
13428 | case DW_OP_or: | |
13429 | return "DW_OP_or"; | |
13430 | case DW_OP_plus: | |
13431 | return "DW_OP_plus"; | |
13432 | case DW_OP_plus_uconst: | |
13433 | return "DW_OP_plus_uconst"; | |
13434 | case DW_OP_shl: | |
13435 | return "DW_OP_shl"; | |
13436 | case DW_OP_shr: | |
13437 | return "DW_OP_shr"; | |
13438 | case DW_OP_shra: | |
13439 | return "DW_OP_shra"; | |
13440 | case DW_OP_xor: | |
13441 | return "DW_OP_xor"; | |
13442 | case DW_OP_bra: | |
13443 | return "DW_OP_bra"; | |
13444 | case DW_OP_eq: | |
13445 | return "DW_OP_eq"; | |
13446 | case DW_OP_ge: | |
13447 | return "DW_OP_ge"; | |
13448 | case DW_OP_gt: | |
13449 | return "DW_OP_gt"; | |
13450 | case DW_OP_le: | |
13451 | return "DW_OP_le"; | |
13452 | case DW_OP_lt: | |
13453 | return "DW_OP_lt"; | |
13454 | case DW_OP_ne: | |
13455 | return "DW_OP_ne"; | |
13456 | case DW_OP_skip: | |
13457 | return "DW_OP_skip"; | |
13458 | case DW_OP_lit0: | |
13459 | return "DW_OP_lit0"; | |
13460 | case DW_OP_lit1: | |
13461 | return "DW_OP_lit1"; | |
13462 | case DW_OP_lit2: | |
13463 | return "DW_OP_lit2"; | |
13464 | case DW_OP_lit3: | |
13465 | return "DW_OP_lit3"; | |
13466 | case DW_OP_lit4: | |
13467 | return "DW_OP_lit4"; | |
13468 | case DW_OP_lit5: | |
13469 | return "DW_OP_lit5"; | |
13470 | case DW_OP_lit6: | |
13471 | return "DW_OP_lit6"; | |
13472 | case DW_OP_lit7: | |
13473 | return "DW_OP_lit7"; | |
13474 | case DW_OP_lit8: | |
13475 | return "DW_OP_lit8"; | |
13476 | case DW_OP_lit9: | |
13477 | return "DW_OP_lit9"; | |
13478 | case DW_OP_lit10: | |
13479 | return "DW_OP_lit10"; | |
13480 | case DW_OP_lit11: | |
13481 | return "DW_OP_lit11"; | |
13482 | case DW_OP_lit12: | |
13483 | return "DW_OP_lit12"; | |
13484 | case DW_OP_lit13: | |
13485 | return "DW_OP_lit13"; | |
13486 | case DW_OP_lit14: | |
13487 | return "DW_OP_lit14"; | |
13488 | case DW_OP_lit15: | |
13489 | return "DW_OP_lit15"; | |
13490 | case DW_OP_lit16: | |
13491 | return "DW_OP_lit16"; | |
13492 | case DW_OP_lit17: | |
13493 | return "DW_OP_lit17"; | |
13494 | case DW_OP_lit18: | |
13495 | return "DW_OP_lit18"; | |
13496 | case DW_OP_lit19: | |
13497 | return "DW_OP_lit19"; | |
13498 | case DW_OP_lit20: | |
13499 | return "DW_OP_lit20"; | |
13500 | case DW_OP_lit21: | |
13501 | return "DW_OP_lit21"; | |
13502 | case DW_OP_lit22: | |
13503 | return "DW_OP_lit22"; | |
13504 | case DW_OP_lit23: | |
13505 | return "DW_OP_lit23"; | |
13506 | case DW_OP_lit24: | |
13507 | return "DW_OP_lit24"; | |
13508 | case DW_OP_lit25: | |
13509 | return "DW_OP_lit25"; | |
13510 | case DW_OP_lit26: | |
13511 | return "DW_OP_lit26"; | |
13512 | case DW_OP_lit27: | |
13513 | return "DW_OP_lit27"; | |
13514 | case DW_OP_lit28: | |
13515 | return "DW_OP_lit28"; | |
13516 | case DW_OP_lit29: | |
13517 | return "DW_OP_lit29"; | |
13518 | case DW_OP_lit30: | |
13519 | return "DW_OP_lit30"; | |
13520 | case DW_OP_lit31: | |
13521 | return "DW_OP_lit31"; | |
13522 | case DW_OP_reg0: | |
13523 | return "DW_OP_reg0"; | |
13524 | case DW_OP_reg1: | |
13525 | return "DW_OP_reg1"; | |
13526 | case DW_OP_reg2: | |
13527 | return "DW_OP_reg2"; | |
13528 | case DW_OP_reg3: | |
13529 | return "DW_OP_reg3"; | |
13530 | case DW_OP_reg4: | |
13531 | return "DW_OP_reg4"; | |
13532 | case DW_OP_reg5: | |
13533 | return "DW_OP_reg5"; | |
13534 | case DW_OP_reg6: | |
13535 | return "DW_OP_reg6"; | |
13536 | case DW_OP_reg7: | |
13537 | return "DW_OP_reg7"; | |
13538 | case DW_OP_reg8: | |
13539 | return "DW_OP_reg8"; | |
13540 | case DW_OP_reg9: | |
13541 | return "DW_OP_reg9"; | |
13542 | case DW_OP_reg10: | |
13543 | return "DW_OP_reg10"; | |
13544 | case DW_OP_reg11: | |
13545 | return "DW_OP_reg11"; | |
13546 | case DW_OP_reg12: | |
13547 | return "DW_OP_reg12"; | |
13548 | case DW_OP_reg13: | |
13549 | return "DW_OP_reg13"; | |
13550 | case DW_OP_reg14: | |
13551 | return "DW_OP_reg14"; | |
13552 | case DW_OP_reg15: | |
13553 | return "DW_OP_reg15"; | |
13554 | case DW_OP_reg16: | |
13555 | return "DW_OP_reg16"; | |
13556 | case DW_OP_reg17: | |
13557 | return "DW_OP_reg17"; | |
13558 | case DW_OP_reg18: | |
13559 | return "DW_OP_reg18"; | |
13560 | case DW_OP_reg19: | |
13561 | return "DW_OP_reg19"; | |
13562 | case DW_OP_reg20: | |
13563 | return "DW_OP_reg20"; | |
13564 | case DW_OP_reg21: | |
13565 | return "DW_OP_reg21"; | |
13566 | case DW_OP_reg22: | |
13567 | return "DW_OP_reg22"; | |
13568 | case DW_OP_reg23: | |
13569 | return "DW_OP_reg23"; | |
13570 | case DW_OP_reg24: | |
13571 | return "DW_OP_reg24"; | |
13572 | case DW_OP_reg25: | |
13573 | return "DW_OP_reg25"; | |
13574 | case DW_OP_reg26: | |
13575 | return "DW_OP_reg26"; | |
13576 | case DW_OP_reg27: | |
13577 | return "DW_OP_reg27"; | |
13578 | case DW_OP_reg28: | |
13579 | return "DW_OP_reg28"; | |
13580 | case DW_OP_reg29: | |
13581 | return "DW_OP_reg29"; | |
13582 | case DW_OP_reg30: | |
13583 | return "DW_OP_reg30"; | |
13584 | case DW_OP_reg31: | |
13585 | return "DW_OP_reg31"; | |
13586 | case DW_OP_breg0: | |
13587 | return "DW_OP_breg0"; | |
13588 | case DW_OP_breg1: | |
13589 | return "DW_OP_breg1"; | |
13590 | case DW_OP_breg2: | |
13591 | return "DW_OP_breg2"; | |
13592 | case DW_OP_breg3: | |
13593 | return "DW_OP_breg3"; | |
13594 | case DW_OP_breg4: | |
13595 | return "DW_OP_breg4"; | |
13596 | case DW_OP_breg5: | |
13597 | return "DW_OP_breg5"; | |
13598 | case DW_OP_breg6: | |
13599 | return "DW_OP_breg6"; | |
13600 | case DW_OP_breg7: | |
13601 | return "DW_OP_breg7"; | |
13602 | case DW_OP_breg8: | |
13603 | return "DW_OP_breg8"; | |
13604 | case DW_OP_breg9: | |
13605 | return "DW_OP_breg9"; | |
13606 | case DW_OP_breg10: | |
13607 | return "DW_OP_breg10"; | |
13608 | case DW_OP_breg11: | |
13609 | return "DW_OP_breg11"; | |
13610 | case DW_OP_breg12: | |
13611 | return "DW_OP_breg12"; | |
13612 | case DW_OP_breg13: | |
13613 | return "DW_OP_breg13"; | |
13614 | case DW_OP_breg14: | |
13615 | return "DW_OP_breg14"; | |
13616 | case DW_OP_breg15: | |
13617 | return "DW_OP_breg15"; | |
13618 | case DW_OP_breg16: | |
13619 | return "DW_OP_breg16"; | |
13620 | case DW_OP_breg17: | |
13621 | return "DW_OP_breg17"; | |
13622 | case DW_OP_breg18: | |
13623 | return "DW_OP_breg18"; | |
13624 | case DW_OP_breg19: | |
13625 | return "DW_OP_breg19"; | |
13626 | case DW_OP_breg20: | |
13627 | return "DW_OP_breg20"; | |
13628 | case DW_OP_breg21: | |
13629 | return "DW_OP_breg21"; | |
13630 | case DW_OP_breg22: | |
13631 | return "DW_OP_breg22"; | |
13632 | case DW_OP_breg23: | |
13633 | return "DW_OP_breg23"; | |
13634 | case DW_OP_breg24: | |
13635 | return "DW_OP_breg24"; | |
13636 | case DW_OP_breg25: | |
13637 | return "DW_OP_breg25"; | |
13638 | case DW_OP_breg26: | |
13639 | return "DW_OP_breg26"; | |
13640 | case DW_OP_breg27: | |
13641 | return "DW_OP_breg27"; | |
13642 | case DW_OP_breg28: | |
13643 | return "DW_OP_breg28"; | |
13644 | case DW_OP_breg29: | |
13645 | return "DW_OP_breg29"; | |
13646 | case DW_OP_breg30: | |
13647 | return "DW_OP_breg30"; | |
13648 | case DW_OP_breg31: | |
13649 | return "DW_OP_breg31"; | |
13650 | case DW_OP_regx: | |
13651 | return "DW_OP_regx"; | |
13652 | case DW_OP_fbreg: | |
13653 | return "DW_OP_fbreg"; | |
13654 | case DW_OP_bregx: | |
13655 | return "DW_OP_bregx"; | |
13656 | case DW_OP_piece: | |
13657 | return "DW_OP_piece"; | |
13658 | case DW_OP_deref_size: | |
13659 | return "DW_OP_deref_size"; | |
13660 | case DW_OP_xderef_size: | |
13661 | return "DW_OP_xderef_size"; | |
13662 | case DW_OP_nop: | |
13663 | return "DW_OP_nop"; | |
b7619582 | 13664 | /* DWARF 3 extensions. */ |
ed348acc EZ |
13665 | case DW_OP_push_object_address: |
13666 | return "DW_OP_push_object_address"; | |
13667 | case DW_OP_call2: | |
13668 | return "DW_OP_call2"; | |
13669 | case DW_OP_call4: | |
13670 | return "DW_OP_call4"; | |
13671 | case DW_OP_call_ref: | |
13672 | return "DW_OP_call_ref"; | |
b7619582 GF |
13673 | case DW_OP_form_tls_address: |
13674 | return "DW_OP_form_tls_address"; | |
13675 | case DW_OP_call_frame_cfa: | |
13676 | return "DW_OP_call_frame_cfa"; | |
13677 | case DW_OP_bit_piece: | |
13678 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
13679 | /* DWARF 4 extensions. */ |
13680 | case DW_OP_implicit_value: | |
13681 | return "DW_OP_implicit_value"; | |
13682 | case DW_OP_stack_value: | |
13683 | return "DW_OP_stack_value"; | |
13684 | /* GNU extensions. */ | |
ed348acc EZ |
13685 | case DW_OP_GNU_push_tls_address: |
13686 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
13687 | case DW_OP_GNU_uninit: |
13688 | return "DW_OP_GNU_uninit"; | |
8cf6f0b1 TT |
13689 | case DW_OP_GNU_implicit_pointer: |
13690 | return "DW_OP_GNU_implicit_pointer"; | |
8a9b8146 TT |
13691 | case DW_OP_GNU_entry_value: |
13692 | return "DW_OP_GNU_entry_value"; | |
13693 | case DW_OP_GNU_const_type: | |
13694 | return "DW_OP_GNU_const_type"; | |
13695 | case DW_OP_GNU_regval_type: | |
13696 | return "DW_OP_GNU_regval_type"; | |
13697 | case DW_OP_GNU_deref_type: | |
13698 | return "DW_OP_GNU_deref_type"; | |
13699 | case DW_OP_GNU_convert: | |
13700 | return "DW_OP_GNU_convert"; | |
13701 | case DW_OP_GNU_reinterpret: | |
13702 | return "DW_OP_GNU_reinterpret"; | |
c906108c | 13703 | default: |
b1bfef65 | 13704 | return NULL; |
c906108c SS |
13705 | } |
13706 | } | |
13707 | ||
13708 | static char * | |
fba45db2 | 13709 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
13710 | { |
13711 | if (mybool) | |
13712 | return "TRUE"; | |
13713 | else | |
13714 | return "FALSE"; | |
13715 | } | |
13716 | ||
13717 | /* Convert a DWARF type code into its string name. */ | |
13718 | ||
13719 | static char * | |
aa1ee363 | 13720 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
13721 | { |
13722 | switch (enc) | |
13723 | { | |
b7619582 GF |
13724 | case DW_ATE_void: |
13725 | return "DW_ATE_void"; | |
c906108c SS |
13726 | case DW_ATE_address: |
13727 | return "DW_ATE_address"; | |
13728 | case DW_ATE_boolean: | |
13729 | return "DW_ATE_boolean"; | |
13730 | case DW_ATE_complex_float: | |
13731 | return "DW_ATE_complex_float"; | |
13732 | case DW_ATE_float: | |
13733 | return "DW_ATE_float"; | |
13734 | case DW_ATE_signed: | |
13735 | return "DW_ATE_signed"; | |
13736 | case DW_ATE_signed_char: | |
13737 | return "DW_ATE_signed_char"; | |
13738 | case DW_ATE_unsigned: | |
13739 | return "DW_ATE_unsigned"; | |
13740 | case DW_ATE_unsigned_char: | |
13741 | return "DW_ATE_unsigned_char"; | |
b7619582 | 13742 | /* DWARF 3. */ |
d9fa45fe DC |
13743 | case DW_ATE_imaginary_float: |
13744 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
13745 | case DW_ATE_packed_decimal: |
13746 | return "DW_ATE_packed_decimal"; | |
13747 | case DW_ATE_numeric_string: | |
13748 | return "DW_ATE_numeric_string"; | |
13749 | case DW_ATE_edited: | |
13750 | return "DW_ATE_edited"; | |
13751 | case DW_ATE_signed_fixed: | |
13752 | return "DW_ATE_signed_fixed"; | |
13753 | case DW_ATE_unsigned_fixed: | |
13754 | return "DW_ATE_unsigned_fixed"; | |
13755 | case DW_ATE_decimal_float: | |
13756 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
13757 | /* DWARF 4. */ |
13758 | case DW_ATE_UTF: | |
13759 | return "DW_ATE_UTF"; | |
b7619582 GF |
13760 | /* HP extensions. */ |
13761 | case DW_ATE_HP_float80: | |
13762 | return "DW_ATE_HP_float80"; | |
13763 | case DW_ATE_HP_complex_float80: | |
13764 | return "DW_ATE_HP_complex_float80"; | |
13765 | case DW_ATE_HP_float128: | |
13766 | return "DW_ATE_HP_float128"; | |
13767 | case DW_ATE_HP_complex_float128: | |
13768 | return "DW_ATE_HP_complex_float128"; | |
13769 | case DW_ATE_HP_floathpintel: | |
13770 | return "DW_ATE_HP_floathpintel"; | |
13771 | case DW_ATE_HP_imaginary_float80: | |
13772 | return "DW_ATE_HP_imaginary_float80"; | |
13773 | case DW_ATE_HP_imaginary_float128: | |
13774 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
13775 | default: |
13776 | return "DW_ATE_<unknown>"; | |
13777 | } | |
13778 | } | |
13779 | ||
0963b4bd | 13780 | /* Convert a DWARF call frame info operation to its string name. */ |
c906108c SS |
13781 | |
13782 | #if 0 | |
13783 | static char * | |
aa1ee363 | 13784 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
13785 | { |
13786 | switch (cfi_opc) | |
13787 | { | |
13788 | case DW_CFA_advance_loc: | |
13789 | return "DW_CFA_advance_loc"; | |
13790 | case DW_CFA_offset: | |
13791 | return "DW_CFA_offset"; | |
13792 | case DW_CFA_restore: | |
13793 | return "DW_CFA_restore"; | |
13794 | case DW_CFA_nop: | |
13795 | return "DW_CFA_nop"; | |
13796 | case DW_CFA_set_loc: | |
13797 | return "DW_CFA_set_loc"; | |
13798 | case DW_CFA_advance_loc1: | |
13799 | return "DW_CFA_advance_loc1"; | |
13800 | case DW_CFA_advance_loc2: | |
13801 | return "DW_CFA_advance_loc2"; | |
13802 | case DW_CFA_advance_loc4: | |
13803 | return "DW_CFA_advance_loc4"; | |
13804 | case DW_CFA_offset_extended: | |
13805 | return "DW_CFA_offset_extended"; | |
13806 | case DW_CFA_restore_extended: | |
13807 | return "DW_CFA_restore_extended"; | |
13808 | case DW_CFA_undefined: | |
13809 | return "DW_CFA_undefined"; | |
13810 | case DW_CFA_same_value: | |
13811 | return "DW_CFA_same_value"; | |
13812 | case DW_CFA_register: | |
13813 | return "DW_CFA_register"; | |
13814 | case DW_CFA_remember_state: | |
13815 | return "DW_CFA_remember_state"; | |
13816 | case DW_CFA_restore_state: | |
13817 | return "DW_CFA_restore_state"; | |
13818 | case DW_CFA_def_cfa: | |
13819 | return "DW_CFA_def_cfa"; | |
13820 | case DW_CFA_def_cfa_register: | |
13821 | return "DW_CFA_def_cfa_register"; | |
13822 | case DW_CFA_def_cfa_offset: | |
13823 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 13824 | /* DWARF 3. */ |
985cb1a3 JM |
13825 | case DW_CFA_def_cfa_expression: |
13826 | return "DW_CFA_def_cfa_expression"; | |
13827 | case DW_CFA_expression: | |
13828 | return "DW_CFA_expression"; | |
13829 | case DW_CFA_offset_extended_sf: | |
13830 | return "DW_CFA_offset_extended_sf"; | |
13831 | case DW_CFA_def_cfa_sf: | |
13832 | return "DW_CFA_def_cfa_sf"; | |
13833 | case DW_CFA_def_cfa_offset_sf: | |
13834 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
13835 | case DW_CFA_val_offset: |
13836 | return "DW_CFA_val_offset"; | |
13837 | case DW_CFA_val_offset_sf: | |
13838 | return "DW_CFA_val_offset_sf"; | |
13839 | case DW_CFA_val_expression: | |
13840 | return "DW_CFA_val_expression"; | |
13841 | /* SGI/MIPS specific. */ | |
c906108c SS |
13842 | case DW_CFA_MIPS_advance_loc8: |
13843 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 13844 | /* GNU extensions. */ |
985cb1a3 JM |
13845 | case DW_CFA_GNU_window_save: |
13846 | return "DW_CFA_GNU_window_save"; | |
13847 | case DW_CFA_GNU_args_size: | |
13848 | return "DW_CFA_GNU_args_size"; | |
13849 | case DW_CFA_GNU_negative_offset_extended: | |
13850 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
13851 | default: |
13852 | return "DW_CFA_<unknown>"; | |
13853 | } | |
13854 | } | |
13855 | #endif | |
13856 | ||
f9aca02d | 13857 | static void |
d97bc12b | 13858 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
13859 | { |
13860 | unsigned int i; | |
13861 | ||
d97bc12b DE |
13862 | print_spaces (indent, f); |
13863 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 13864 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
13865 | |
13866 | if (die->parent != NULL) | |
13867 | { | |
13868 | print_spaces (indent, f); | |
13869 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
13870 | die->parent->offset); | |
13871 | } | |
13872 | ||
13873 | print_spaces (indent, f); | |
13874 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 13875 | dwarf_bool_name (die->child != NULL)); |
c906108c | 13876 | |
d97bc12b DE |
13877 | print_spaces (indent, f); |
13878 | fprintf_unfiltered (f, " attributes:\n"); | |
13879 | ||
c906108c SS |
13880 | for (i = 0; i < die->num_attrs; ++i) |
13881 | { | |
d97bc12b DE |
13882 | print_spaces (indent, f); |
13883 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
13884 | dwarf_attr_name (die->attrs[i].name), |
13885 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 13886 | |
c906108c SS |
13887 | switch (die->attrs[i].form) |
13888 | { | |
13889 | case DW_FORM_ref_addr: | |
13890 | case DW_FORM_addr: | |
d97bc12b | 13891 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 13892 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
13893 | break; |
13894 | case DW_FORM_block2: | |
13895 | case DW_FORM_block4: | |
13896 | case DW_FORM_block: | |
13897 | case DW_FORM_block1: | |
3e43a32a MS |
13898 | fprintf_unfiltered (f, "block: size %d", |
13899 | DW_BLOCK (&die->attrs[i])->size); | |
c906108c | 13900 | break; |
2dc7f7b3 TT |
13901 | case DW_FORM_exprloc: |
13902 | fprintf_unfiltered (f, "expression: size %u", | |
13903 | DW_BLOCK (&die->attrs[i])->size); | |
13904 | break; | |
10b3939b DJ |
13905 | case DW_FORM_ref1: |
13906 | case DW_FORM_ref2: | |
13907 | case DW_FORM_ref4: | |
d97bc12b | 13908 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
13909 | (long) (DW_ADDR (&die->attrs[i]))); |
13910 | break; | |
c906108c SS |
13911 | case DW_FORM_data1: |
13912 | case DW_FORM_data2: | |
13913 | case DW_FORM_data4: | |
ce5d95e1 | 13914 | case DW_FORM_data8: |
c906108c SS |
13915 | case DW_FORM_udata: |
13916 | case DW_FORM_sdata: | |
43bbcdc2 PH |
13917 | fprintf_unfiltered (f, "constant: %s", |
13918 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 13919 | break; |
2dc7f7b3 TT |
13920 | case DW_FORM_sec_offset: |
13921 | fprintf_unfiltered (f, "section offset: %s", | |
13922 | pulongest (DW_UNSND (&die->attrs[i]))); | |
13923 | break; | |
55f1336d | 13924 | case DW_FORM_ref_sig8: |
348e048f DE |
13925 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
13926 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
b3c8eb43 | 13927 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset); |
348e048f DE |
13928 | else |
13929 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
13930 | break; | |
c906108c | 13931 | case DW_FORM_string: |
4bdf3d34 | 13932 | case DW_FORM_strp: |
8285870a | 13933 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 13934 | DW_STRING (&die->attrs[i]) |
8285870a JK |
13935 | ? DW_STRING (&die->attrs[i]) : "", |
13936 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
13937 | break; |
13938 | case DW_FORM_flag: | |
13939 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 13940 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 13941 | else |
d97bc12b | 13942 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 13943 | break; |
2dc7f7b3 TT |
13944 | case DW_FORM_flag_present: |
13945 | fprintf_unfiltered (f, "flag: TRUE"); | |
13946 | break; | |
a8329558 | 13947 | case DW_FORM_indirect: |
0963b4bd MS |
13948 | /* The reader will have reduced the indirect form to |
13949 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
13950 | fprintf_unfiltered (f, |
13951 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 13952 | break; |
c906108c | 13953 | default: |
d97bc12b | 13954 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 13955 | die->attrs[i].form); |
d97bc12b | 13956 | break; |
c906108c | 13957 | } |
d97bc12b | 13958 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
13959 | } |
13960 | } | |
13961 | ||
f9aca02d | 13962 | static void |
d97bc12b | 13963 | dump_die_for_error (struct die_info *die) |
c906108c | 13964 | { |
d97bc12b DE |
13965 | dump_die_shallow (gdb_stderr, 0, die); |
13966 | } | |
13967 | ||
13968 | static void | |
13969 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
13970 | { | |
13971 | int indent = level * 4; | |
13972 | ||
13973 | gdb_assert (die != NULL); | |
13974 | ||
13975 | if (level >= max_level) | |
13976 | return; | |
13977 | ||
13978 | dump_die_shallow (f, indent, die); | |
13979 | ||
13980 | if (die->child != NULL) | |
c906108c | 13981 | { |
d97bc12b DE |
13982 | print_spaces (indent, f); |
13983 | fprintf_unfiltered (f, " Children:"); | |
13984 | if (level + 1 < max_level) | |
13985 | { | |
13986 | fprintf_unfiltered (f, "\n"); | |
13987 | dump_die_1 (f, level + 1, max_level, die->child); | |
13988 | } | |
13989 | else | |
13990 | { | |
3e43a32a MS |
13991 | fprintf_unfiltered (f, |
13992 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
13993 | } |
13994 | } | |
13995 | ||
13996 | if (die->sibling != NULL && level > 0) | |
13997 | { | |
13998 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
13999 | } |
14000 | } | |
14001 | ||
d97bc12b DE |
14002 | /* This is called from the pdie macro in gdbinit.in. |
14003 | It's not static so gcc will keep a copy callable from gdb. */ | |
14004 | ||
14005 | void | |
14006 | dump_die (struct die_info *die, int max_level) | |
14007 | { | |
14008 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
14009 | } | |
14010 | ||
f9aca02d | 14011 | static void |
51545339 | 14012 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14013 | { |
51545339 | 14014 | void **slot; |
c906108c | 14015 | |
51545339 DJ |
14016 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
14017 | ||
14018 | *slot = die; | |
c906108c SS |
14019 | } |
14020 | ||
93311388 DE |
14021 | static int |
14022 | is_ref_attr (struct attribute *attr) | |
c906108c | 14023 | { |
c906108c SS |
14024 | switch (attr->form) |
14025 | { | |
14026 | case DW_FORM_ref_addr: | |
c906108c SS |
14027 | case DW_FORM_ref1: |
14028 | case DW_FORM_ref2: | |
14029 | case DW_FORM_ref4: | |
613e1657 | 14030 | case DW_FORM_ref8: |
c906108c | 14031 | case DW_FORM_ref_udata: |
93311388 | 14032 | return 1; |
c906108c | 14033 | default: |
93311388 | 14034 | return 0; |
c906108c | 14035 | } |
93311388 DE |
14036 | } |
14037 | ||
14038 | static unsigned int | |
14039 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
14040 | { | |
14041 | if (is_ref_attr (attr)) | |
14042 | return DW_ADDR (attr); | |
14043 | ||
14044 | complaint (&symfile_complaints, | |
14045 | _("unsupported die ref attribute form: '%s'"), | |
14046 | dwarf_form_name (attr->form)); | |
14047 | return 0; | |
c906108c SS |
14048 | } |
14049 | ||
43bbcdc2 PH |
14050 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
14051 | * the value held by the attribute is not constant. */ | |
a02abb62 | 14052 | |
43bbcdc2 | 14053 | static LONGEST |
a02abb62 JB |
14054 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
14055 | { | |
14056 | if (attr->form == DW_FORM_sdata) | |
14057 | return DW_SND (attr); | |
14058 | else if (attr->form == DW_FORM_udata | |
14059 | || attr->form == DW_FORM_data1 | |
14060 | || attr->form == DW_FORM_data2 | |
14061 | || attr->form == DW_FORM_data4 | |
14062 | || attr->form == DW_FORM_data8) | |
14063 | return DW_UNSND (attr); | |
14064 | else | |
14065 | { | |
3e43a32a MS |
14066 | complaint (&symfile_complaints, |
14067 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
14068 | dwarf_form_name (attr->form)); |
14069 | return default_value; | |
14070 | } | |
14071 | } | |
14072 | ||
03dd20cc | 14073 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
14074 | unit and add it to our queue. |
14075 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
14076 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 14077 | |
348e048f | 14078 | static int |
03dd20cc DJ |
14079 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
14080 | struct dwarf2_per_cu_data *per_cu) | |
14081 | { | |
98bfdba5 PA |
14082 | /* We may arrive here during partial symbol reading, if we need full |
14083 | DIEs to process an unusual case (e.g. template arguments). Do | |
14084 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
14085 | if (dwarf2_per_objfile->reading_partial_symbols) | |
14086 | { | |
14087 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
14088 | return 1; | |
14089 | return 0; | |
14090 | } | |
14091 | ||
03dd20cc DJ |
14092 | /* Mark the dependence relation so that we don't flush PER_CU |
14093 | too early. */ | |
14094 | dwarf2_add_dependence (this_cu, per_cu); | |
14095 | ||
14096 | /* If it's already on the queue, we have nothing to do. */ | |
14097 | if (per_cu->queued) | |
348e048f | 14098 | return 0; |
03dd20cc DJ |
14099 | |
14100 | /* If the compilation unit is already loaded, just mark it as | |
14101 | used. */ | |
14102 | if (per_cu->cu != NULL) | |
14103 | { | |
14104 | per_cu->cu->last_used = 0; | |
348e048f | 14105 | return 0; |
03dd20cc DJ |
14106 | } |
14107 | ||
14108 | /* Add it to the queue. */ | |
a0f42c21 | 14109 | queue_comp_unit (per_cu); |
348e048f DE |
14110 | |
14111 | return 1; | |
14112 | } | |
14113 | ||
14114 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
14115 | On entry *REF_CU is the CU of SRC_DIE. | |
14116 | On exit *REF_CU is the CU of the result. */ | |
14117 | ||
14118 | static struct die_info * | |
14119 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
14120 | struct dwarf2_cu **ref_cu) | |
14121 | { | |
14122 | struct die_info *die; | |
14123 | ||
14124 | if (is_ref_attr (attr)) | |
14125 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 14126 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
14127 | die = follow_die_sig (src_die, attr, ref_cu); |
14128 | else | |
14129 | { | |
14130 | dump_die_for_error (src_die); | |
14131 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
14132 | (*ref_cu)->objfile->name); | |
14133 | } | |
14134 | ||
14135 | return die; | |
03dd20cc DJ |
14136 | } |
14137 | ||
5c631832 | 14138 | /* Follow reference OFFSET. |
673bfd45 DE |
14139 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
14140 | On exit *REF_CU is the CU of the result. | |
14141 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 14142 | |
f9aca02d | 14143 | static struct die_info * |
5c631832 | 14144 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 14145 | { |
10b3939b | 14146 | struct die_info temp_die; |
f2f0e013 | 14147 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 14148 | |
348e048f DE |
14149 | gdb_assert (cu->per_cu != NULL); |
14150 | ||
98bfdba5 PA |
14151 | target_cu = cu; |
14152 | ||
b0df02fd | 14153 | if (cu->per_cu->debug_types_section) |
348e048f DE |
14154 | { |
14155 | /* .debug_types CUs cannot reference anything outside their CU. | |
14156 | If they need to, they have to reference a signatured type via | |
55f1336d | 14157 | DW_FORM_ref_sig8. */ |
348e048f | 14158 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 14159 | return NULL; |
348e048f DE |
14160 | } |
14161 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
14162 | { |
14163 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 14164 | |
45452591 | 14165 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
14166 | |
14167 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f | 14168 | if (maybe_queue_comp_unit (cu, per_cu)) |
a0f42c21 | 14169 | load_full_comp_unit (per_cu); |
03dd20cc | 14170 | |
10b3939b DJ |
14171 | target_cu = per_cu->cu; |
14172 | } | |
98bfdba5 PA |
14173 | else if (cu->dies == NULL) |
14174 | { | |
14175 | /* We're loading full DIEs during partial symbol reading. */ | |
14176 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
a0f42c21 | 14177 | load_full_comp_unit (cu->per_cu); |
98bfdba5 | 14178 | } |
c906108c | 14179 | |
f2f0e013 | 14180 | *ref_cu = target_cu; |
51545339 | 14181 | temp_die.offset = offset; |
5c631832 JK |
14182 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
14183 | } | |
10b3939b | 14184 | |
5c631832 JK |
14185 | /* Follow reference attribute ATTR of SRC_DIE. |
14186 | On entry *REF_CU is the CU of SRC_DIE. | |
14187 | On exit *REF_CU is the CU of the result. */ | |
14188 | ||
14189 | static struct die_info * | |
14190 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
14191 | struct dwarf2_cu **ref_cu) | |
14192 | { | |
14193 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
14194 | struct dwarf2_cu *cu = *ref_cu; | |
14195 | struct die_info *die; | |
14196 | ||
14197 | die = follow_die_offset (offset, ref_cu); | |
14198 | if (!die) | |
14199 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
14200 | "at 0x%x [in module %s]"), | |
14201 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 14202 | |
5c631832 JK |
14203 | return die; |
14204 | } | |
14205 | ||
d83e736b JK |
14206 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
14207 | Returned value is intended for DW_OP_call*. Returned | |
14208 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ | |
5c631832 JK |
14209 | |
14210 | struct dwarf2_locexpr_baton | |
14211 | dwarf2_fetch_die_location_block (unsigned int offset, | |
8cf6f0b1 TT |
14212 | struct dwarf2_per_cu_data *per_cu, |
14213 | CORE_ADDR (*get_frame_pc) (void *baton), | |
14214 | void *baton) | |
5c631832 | 14215 | { |
918dd910 | 14216 | struct dwarf2_cu *cu; |
5c631832 JK |
14217 | struct die_info *die; |
14218 | struct attribute *attr; | |
14219 | struct dwarf2_locexpr_baton retval; | |
14220 | ||
8cf6f0b1 TT |
14221 | dw2_setup (per_cu->objfile); |
14222 | ||
918dd910 JK |
14223 | if (per_cu->cu == NULL) |
14224 | load_cu (per_cu); | |
14225 | cu = per_cu->cu; | |
14226 | ||
5c631832 JK |
14227 | die = follow_die_offset (offset, &cu); |
14228 | if (!die) | |
14229 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
bb5ed363 | 14230 | offset, per_cu->objfile->name); |
5c631832 JK |
14231 | |
14232 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
14233 | if (!attr) | |
14234 | { | |
e103e986 JK |
14235 | /* DWARF: "If there is no such attribute, then there is no effect.". |
14236 | DATA is ignored if SIZE is 0. */ | |
5c631832 | 14237 | |
e103e986 | 14238 | retval.data = NULL; |
5c631832 JK |
14239 | retval.size = 0; |
14240 | } | |
8cf6f0b1 TT |
14241 | else if (attr_form_is_section_offset (attr)) |
14242 | { | |
14243 | struct dwarf2_loclist_baton loclist_baton; | |
14244 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
14245 | size_t size; | |
14246 | ||
14247 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
14248 | ||
14249 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
14250 | &size, pc); | |
14251 | retval.size = size; | |
14252 | } | |
5c631832 JK |
14253 | else |
14254 | { | |
14255 | if (!attr_form_is_block (attr)) | |
14256 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
14257 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
bb5ed363 | 14258 | offset, per_cu->objfile->name); |
5c631832 JK |
14259 | |
14260 | retval.data = DW_BLOCK (attr)->data; | |
14261 | retval.size = DW_BLOCK (attr)->size; | |
14262 | } | |
14263 | retval.per_cu = cu->per_cu; | |
918dd910 | 14264 | |
918dd910 JK |
14265 | age_cached_comp_units (); |
14266 | ||
5c631832 | 14267 | return retval; |
348e048f DE |
14268 | } |
14269 | ||
8a9b8146 TT |
14270 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
14271 | PER_CU. */ | |
14272 | ||
14273 | struct type * | |
14274 | dwarf2_get_die_type (unsigned int die_offset, | |
14275 | struct dwarf2_per_cu_data *per_cu) | |
14276 | { | |
8a9b8146 | 14277 | dw2_setup (per_cu->objfile); |
9ff3b74f | 14278 | return get_die_type_at_offset (die_offset, per_cu); |
8a9b8146 TT |
14279 | } |
14280 | ||
348e048f DE |
14281 | /* Follow the signature attribute ATTR in SRC_DIE. |
14282 | On entry *REF_CU is the CU of SRC_DIE. | |
14283 | On exit *REF_CU is the CU of the result. */ | |
14284 | ||
14285 | static struct die_info * | |
14286 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
14287 | struct dwarf2_cu **ref_cu) | |
14288 | { | |
14289 | struct objfile *objfile = (*ref_cu)->objfile; | |
14290 | struct die_info temp_die; | |
14291 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
14292 | struct dwarf2_cu *sig_cu; | |
14293 | struct die_info *die; | |
14294 | ||
14295 | /* sig_type will be NULL if the signatured type is missing from | |
14296 | the debug info. */ | |
14297 | if (sig_type == NULL) | |
14298 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
14299 | "at 0x%x [in module %s]"), | |
14300 | src_die->offset, objfile->name); | |
14301 | ||
14302 | /* If necessary, add it to the queue and load its DIEs. */ | |
14303 | ||
14304 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
a0f42c21 | 14305 | read_signatured_type (sig_type); |
348e048f DE |
14306 | |
14307 | gdb_assert (sig_type->per_cu.cu != NULL); | |
14308 | ||
14309 | sig_cu = sig_type->per_cu.cu; | |
14310 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
14311 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
14312 | if (die) | |
14313 | { | |
14314 | *ref_cu = sig_cu; | |
14315 | return die; | |
14316 | } | |
14317 | ||
3e43a32a MS |
14318 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
14319 | "from DIE at 0x%x [in module %s]"), | |
348e048f DE |
14320 | sig_type->type_offset, src_die->offset, objfile->name); |
14321 | } | |
14322 | ||
14323 | /* Given an offset of a signatured type, return its signatured_type. */ | |
14324 | ||
14325 | static struct signatured_type * | |
8b70b953 TT |
14326 | lookup_signatured_type_at_offset (struct objfile *objfile, |
14327 | struct dwarf2_section_info *section, | |
14328 | unsigned int offset) | |
348e048f | 14329 | { |
8b70b953 | 14330 | gdb_byte *info_ptr = section->buffer + offset; |
348e048f DE |
14331 | unsigned int length, initial_length_size; |
14332 | unsigned int sig_offset; | |
14333 | struct signatured_type find_entry, *type_sig; | |
14334 | ||
14335 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
14336 | sig_offset = (initial_length_size | |
14337 | + 2 /*version*/ | |
14338 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
14339 | + 1 /*address_size*/); | |
14340 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
14341 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
14342 | ||
14343 | /* This is only used to lookup previously recorded types. | |
14344 | If we didn't find it, it's our bug. */ | |
14345 | gdb_assert (type_sig != NULL); | |
b3c8eb43 | 14346 | gdb_assert (offset == type_sig->per_cu.offset); |
348e048f DE |
14347 | |
14348 | return type_sig; | |
14349 | } | |
14350 | ||
e5fe5e75 | 14351 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
348e048f DE |
14352 | |
14353 | static void | |
e5fe5e75 | 14354 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
348e048f | 14355 | { |
e5fe5e75 DE |
14356 | struct objfile *objfile = per_cu->objfile; |
14357 | struct dwarf2_section_info *sect = per_cu->debug_types_section; | |
14358 | unsigned int offset = per_cu->offset; | |
348e048f DE |
14359 | struct signatured_type *type_sig; |
14360 | ||
8b70b953 | 14361 | dwarf2_read_section (objfile, sect); |
be391dca | 14362 | |
348e048f | 14363 | /* We have the section offset, but we need the signature to do the |
e5fe5e75 DE |
14364 | hash table lookup. */ |
14365 | /* FIXME: This is sorta unnecessary, read_signatured_type only uses | |
14366 | the signature to assert we found the right one. | |
14367 | Ok, but it's a lot of work. We should simplify things so any needed | |
14368 | assert doesn't require all this clumsiness. */ | |
8b70b953 | 14369 | type_sig = lookup_signatured_type_at_offset (objfile, sect, offset); |
348e048f DE |
14370 | |
14371 | gdb_assert (type_sig->per_cu.cu == NULL); | |
14372 | ||
a0f42c21 | 14373 | read_signatured_type (type_sig); |
348e048f DE |
14374 | |
14375 | gdb_assert (type_sig->per_cu.cu != NULL); | |
14376 | } | |
14377 | ||
14378 | /* Read in a signatured type and build its CU and DIEs. */ | |
14379 | ||
14380 | static void | |
a0f42c21 | 14381 | read_signatured_type (struct signatured_type *type_sig) |
348e048f | 14382 | { |
a0f42c21 | 14383 | struct objfile *objfile = type_sig->per_cu.objfile; |
1fd400ff | 14384 | gdb_byte *types_ptr; |
348e048f DE |
14385 | struct die_reader_specs reader_specs; |
14386 | struct dwarf2_cu *cu; | |
14387 | ULONGEST signature; | |
14388 | struct cleanup *back_to, *free_cu_cleanup; | |
b0df02fd | 14389 | struct dwarf2_section_info *section = type_sig->per_cu.debug_types_section; |
348e048f | 14390 | |
8b70b953 TT |
14391 | dwarf2_read_section (objfile, section); |
14392 | types_ptr = section->buffer + type_sig->per_cu.offset; | |
1fd400ff | 14393 | |
348e048f DE |
14394 | gdb_assert (type_sig->per_cu.cu == NULL); |
14395 | ||
9816fde3 | 14396 | cu = xmalloc (sizeof (*cu)); |
23745b47 | 14397 | init_one_comp_unit (cu, &type_sig->per_cu); |
348e048f DE |
14398 | |
14399 | /* If an error occurs while loading, release our storage. */ | |
68dc6402 | 14400 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
348e048f | 14401 | |
9ff913ba DE |
14402 | types_ptr = read_and_check_type_unit_head (&cu->header, section, types_ptr, |
14403 | &signature, NULL); | |
348e048f DE |
14404 | gdb_assert (signature == type_sig->signature); |
14405 | ||
14406 | cu->die_hash | |
14407 | = htab_create_alloc_ex (cu->header.length / 12, | |
14408 | die_hash, | |
14409 | die_eq, | |
14410 | NULL, | |
14411 | &cu->comp_unit_obstack, | |
14412 | hashtab_obstack_allocate, | |
14413 | dummy_obstack_deallocate); | |
14414 | ||
e5fe5e75 | 14415 | dwarf2_read_abbrevs (cu); |
348e048f DE |
14416 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
14417 | ||
14418 | init_cu_die_reader (&reader_specs, cu); | |
14419 | ||
14420 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
14421 | NULL /*parent*/); | |
14422 | ||
14423 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 14424 | all CUs needed for references have been loaded yet, and symbol |
348e048f DE |
14425 | table processing isn't initialized. But we have to set the CU language, |
14426 | or we won't be able to build types correctly. */ | |
9816fde3 | 14427 | prepare_one_comp_unit (cu, cu->dies); |
348e048f DE |
14428 | |
14429 | do_cleanups (back_to); | |
14430 | ||
14431 | /* We've successfully allocated this compilation unit. Let our caller | |
14432 | clean it up when finished with it. */ | |
14433 | discard_cleanups (free_cu_cleanup); | |
14434 | ||
14435 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
14436 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
14437 | } |
14438 | ||
c906108c SS |
14439 | /* Decode simple location descriptions. |
14440 | Given a pointer to a dwarf block that defines a location, compute | |
14441 | the location and return the value. | |
14442 | ||
4cecd739 DJ |
14443 | NOTE drow/2003-11-18: This function is called in two situations |
14444 | now: for the address of static or global variables (partial symbols | |
14445 | only) and for offsets into structures which are expected to be | |
14446 | (more or less) constant. The partial symbol case should go away, | |
14447 | and only the constant case should remain. That will let this | |
14448 | function complain more accurately. A few special modes are allowed | |
14449 | without complaint for global variables (for instance, global | |
14450 | register values and thread-local values). | |
c906108c SS |
14451 | |
14452 | A location description containing no operations indicates that the | |
4cecd739 | 14453 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
14454 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
14455 | callers will only want a very basic result and this can become a | |
21ae7a4d JK |
14456 | complaint. |
14457 | ||
14458 | Note that stack[0] is unused except as a default error return. */ | |
c906108c SS |
14459 | |
14460 | static CORE_ADDR | |
e7c27a73 | 14461 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 14462 | { |
e7c27a73 | 14463 | struct objfile *objfile = cu->objfile; |
21ae7a4d JK |
14464 | int i; |
14465 | int size = blk->size; | |
14466 | gdb_byte *data = blk->data; | |
14467 | CORE_ADDR stack[64]; | |
14468 | int stacki; | |
14469 | unsigned int bytes_read, unsnd; | |
14470 | gdb_byte op; | |
c906108c | 14471 | |
21ae7a4d JK |
14472 | i = 0; |
14473 | stacki = 0; | |
14474 | stack[stacki] = 0; | |
14475 | stack[++stacki] = 0; | |
14476 | ||
14477 | while (i < size) | |
14478 | { | |
14479 | op = data[i++]; | |
14480 | switch (op) | |
14481 | { | |
14482 | case DW_OP_lit0: | |
14483 | case DW_OP_lit1: | |
14484 | case DW_OP_lit2: | |
14485 | case DW_OP_lit3: | |
14486 | case DW_OP_lit4: | |
14487 | case DW_OP_lit5: | |
14488 | case DW_OP_lit6: | |
14489 | case DW_OP_lit7: | |
14490 | case DW_OP_lit8: | |
14491 | case DW_OP_lit9: | |
14492 | case DW_OP_lit10: | |
14493 | case DW_OP_lit11: | |
14494 | case DW_OP_lit12: | |
14495 | case DW_OP_lit13: | |
14496 | case DW_OP_lit14: | |
14497 | case DW_OP_lit15: | |
14498 | case DW_OP_lit16: | |
14499 | case DW_OP_lit17: | |
14500 | case DW_OP_lit18: | |
14501 | case DW_OP_lit19: | |
14502 | case DW_OP_lit20: | |
14503 | case DW_OP_lit21: | |
14504 | case DW_OP_lit22: | |
14505 | case DW_OP_lit23: | |
14506 | case DW_OP_lit24: | |
14507 | case DW_OP_lit25: | |
14508 | case DW_OP_lit26: | |
14509 | case DW_OP_lit27: | |
14510 | case DW_OP_lit28: | |
14511 | case DW_OP_lit29: | |
14512 | case DW_OP_lit30: | |
14513 | case DW_OP_lit31: | |
14514 | stack[++stacki] = op - DW_OP_lit0; | |
14515 | break; | |
f1bea926 | 14516 | |
21ae7a4d JK |
14517 | case DW_OP_reg0: |
14518 | case DW_OP_reg1: | |
14519 | case DW_OP_reg2: | |
14520 | case DW_OP_reg3: | |
14521 | case DW_OP_reg4: | |
14522 | case DW_OP_reg5: | |
14523 | case DW_OP_reg6: | |
14524 | case DW_OP_reg7: | |
14525 | case DW_OP_reg8: | |
14526 | case DW_OP_reg9: | |
14527 | case DW_OP_reg10: | |
14528 | case DW_OP_reg11: | |
14529 | case DW_OP_reg12: | |
14530 | case DW_OP_reg13: | |
14531 | case DW_OP_reg14: | |
14532 | case DW_OP_reg15: | |
14533 | case DW_OP_reg16: | |
14534 | case DW_OP_reg17: | |
14535 | case DW_OP_reg18: | |
14536 | case DW_OP_reg19: | |
14537 | case DW_OP_reg20: | |
14538 | case DW_OP_reg21: | |
14539 | case DW_OP_reg22: | |
14540 | case DW_OP_reg23: | |
14541 | case DW_OP_reg24: | |
14542 | case DW_OP_reg25: | |
14543 | case DW_OP_reg26: | |
14544 | case DW_OP_reg27: | |
14545 | case DW_OP_reg28: | |
14546 | case DW_OP_reg29: | |
14547 | case DW_OP_reg30: | |
14548 | case DW_OP_reg31: | |
14549 | stack[++stacki] = op - DW_OP_reg0; | |
14550 | if (i < size) | |
14551 | dwarf2_complex_location_expr_complaint (); | |
14552 | break; | |
c906108c | 14553 | |
21ae7a4d JK |
14554 | case DW_OP_regx: |
14555 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
14556 | i += bytes_read; | |
14557 | stack[++stacki] = unsnd; | |
14558 | if (i < size) | |
14559 | dwarf2_complex_location_expr_complaint (); | |
14560 | break; | |
c906108c | 14561 | |
21ae7a4d JK |
14562 | case DW_OP_addr: |
14563 | stack[++stacki] = read_address (objfile->obfd, &data[i], | |
14564 | cu, &bytes_read); | |
14565 | i += bytes_read; | |
14566 | break; | |
d53d4ac5 | 14567 | |
21ae7a4d JK |
14568 | case DW_OP_const1u: |
14569 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
14570 | i += 1; | |
14571 | break; | |
14572 | ||
14573 | case DW_OP_const1s: | |
14574 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
14575 | i += 1; | |
14576 | break; | |
14577 | ||
14578 | case DW_OP_const2u: | |
14579 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
14580 | i += 2; | |
14581 | break; | |
14582 | ||
14583 | case DW_OP_const2s: | |
14584 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
14585 | i += 2; | |
14586 | break; | |
d53d4ac5 | 14587 | |
21ae7a4d JK |
14588 | case DW_OP_const4u: |
14589 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
14590 | i += 4; | |
14591 | break; | |
14592 | ||
14593 | case DW_OP_const4s: | |
14594 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
14595 | i += 4; | |
14596 | break; | |
14597 | ||
585861ea JK |
14598 | case DW_OP_const8u: |
14599 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); | |
14600 | i += 8; | |
14601 | break; | |
14602 | ||
21ae7a4d JK |
14603 | case DW_OP_constu: |
14604 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
14605 | &bytes_read); | |
14606 | i += bytes_read; | |
14607 | break; | |
14608 | ||
14609 | case DW_OP_consts: | |
14610 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
14611 | i += bytes_read; | |
14612 | break; | |
14613 | ||
14614 | case DW_OP_dup: | |
14615 | stack[stacki + 1] = stack[stacki]; | |
14616 | stacki++; | |
14617 | break; | |
14618 | ||
14619 | case DW_OP_plus: | |
14620 | stack[stacki - 1] += stack[stacki]; | |
14621 | stacki--; | |
14622 | break; | |
14623 | ||
14624 | case DW_OP_plus_uconst: | |
14625 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), | |
14626 | &bytes_read); | |
14627 | i += bytes_read; | |
14628 | break; | |
14629 | ||
14630 | case DW_OP_minus: | |
14631 | stack[stacki - 1] -= stack[stacki]; | |
14632 | stacki--; | |
14633 | break; | |
14634 | ||
14635 | case DW_OP_deref: | |
14636 | /* If we're not the last op, then we definitely can't encode | |
14637 | this using GDB's address_class enum. This is valid for partial | |
14638 | global symbols, although the variable's address will be bogus | |
14639 | in the psymtab. */ | |
14640 | if (i < size) | |
14641 | dwarf2_complex_location_expr_complaint (); | |
14642 | break; | |
14643 | ||
14644 | case DW_OP_GNU_push_tls_address: | |
14645 | /* The top of the stack has the offset from the beginning | |
14646 | of the thread control block at which the variable is located. */ | |
14647 | /* Nothing should follow this operator, so the top of stack would | |
14648 | be returned. */ | |
14649 | /* This is valid for partial global symbols, but the variable's | |
585861ea JK |
14650 | address will be bogus in the psymtab. Make it always at least |
14651 | non-zero to not look as a variable garbage collected by linker | |
14652 | which have DW_OP_addr 0. */ | |
21ae7a4d JK |
14653 | if (i < size) |
14654 | dwarf2_complex_location_expr_complaint (); | |
585861ea | 14655 | stack[stacki]++; |
21ae7a4d JK |
14656 | break; |
14657 | ||
14658 | case DW_OP_GNU_uninit: | |
14659 | break; | |
14660 | ||
14661 | default: | |
14662 | { | |
14663 | const char *name = dwarf_stack_op_name (op); | |
14664 | ||
14665 | if (name) | |
14666 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
14667 | name); | |
14668 | else | |
14669 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
14670 | op); | |
14671 | } | |
14672 | ||
14673 | return (stack[stacki]); | |
d53d4ac5 | 14674 | } |
3c6e0cb3 | 14675 | |
21ae7a4d JK |
14676 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
14677 | outside of the allocated space. Also enforce minimum>0. */ | |
14678 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
14679 | { | |
14680 | complaint (&symfile_complaints, | |
14681 | _("location description stack overflow")); | |
14682 | return 0; | |
14683 | } | |
14684 | ||
14685 | if (stacki <= 0) | |
14686 | { | |
14687 | complaint (&symfile_complaints, | |
14688 | _("location description stack underflow")); | |
14689 | return 0; | |
14690 | } | |
14691 | } | |
14692 | return (stack[stacki]); | |
c906108c SS |
14693 | } |
14694 | ||
14695 | /* memory allocation interface */ | |
14696 | ||
c906108c | 14697 | static struct dwarf_block * |
7b5a2f43 | 14698 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
14699 | { |
14700 | struct dwarf_block *blk; | |
14701 | ||
14702 | blk = (struct dwarf_block *) | |
7b5a2f43 | 14703 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
14704 | return (blk); |
14705 | } | |
14706 | ||
14707 | static struct abbrev_info * | |
f3dd6933 | 14708 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
14709 | { |
14710 | struct abbrev_info *abbrev; | |
14711 | ||
f3dd6933 DJ |
14712 | abbrev = (struct abbrev_info *) |
14713 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
14714 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
14715 | return (abbrev); | |
14716 | } | |
14717 | ||
14718 | static struct die_info * | |
b60c80d6 | 14719 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
14720 | { |
14721 | struct die_info *die; | |
b60c80d6 DJ |
14722 | size_t size = sizeof (struct die_info); |
14723 | ||
14724 | if (num_attrs > 1) | |
14725 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 14726 | |
b60c80d6 | 14727 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
14728 | memset (die, 0, sizeof (struct die_info)); |
14729 | return (die); | |
14730 | } | |
2e276125 JB |
14731 | |
14732 | \f | |
14733 | /* Macro support. */ | |
14734 | ||
2e276125 JB |
14735 | /* Return the full name of file number I in *LH's file name table. |
14736 | Use COMP_DIR as the name of the current directory of the | |
14737 | compilation. The result is allocated using xmalloc; the caller is | |
14738 | responsible for freeing it. */ | |
14739 | static char * | |
14740 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
14741 | { | |
6a83a1e6 EZ |
14742 | /* Is the file number a valid index into the line header's file name |
14743 | table? Remember that file numbers start with one, not zero. */ | |
14744 | if (1 <= file && file <= lh->num_file_names) | |
14745 | { | |
14746 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 14747 | |
6a83a1e6 EZ |
14748 | if (IS_ABSOLUTE_PATH (fe->name)) |
14749 | return xstrdup (fe->name); | |
14750 | else | |
14751 | { | |
14752 | const char *dir; | |
14753 | int dir_len; | |
14754 | char *full_name; | |
14755 | ||
14756 | if (fe->dir_index) | |
14757 | dir = lh->include_dirs[fe->dir_index - 1]; | |
14758 | else | |
14759 | dir = comp_dir; | |
14760 | ||
14761 | if (dir) | |
14762 | { | |
14763 | dir_len = strlen (dir); | |
14764 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
14765 | strcpy (full_name, dir); | |
14766 | full_name[dir_len] = '/'; | |
14767 | strcpy (full_name + dir_len + 1, fe->name); | |
14768 | return full_name; | |
14769 | } | |
14770 | else | |
14771 | return xstrdup (fe->name); | |
14772 | } | |
14773 | } | |
2e276125 JB |
14774 | else |
14775 | { | |
6a83a1e6 EZ |
14776 | /* The compiler produced a bogus file number. We can at least |
14777 | record the macro definitions made in the file, even if we | |
14778 | won't be able to find the file by name. */ | |
14779 | char fake_name[80]; | |
9a619af0 | 14780 | |
6a83a1e6 | 14781 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 14782 | |
6e70227d | 14783 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
14784 | _("bad file number in macro information (%d)"), |
14785 | file); | |
2e276125 | 14786 | |
6a83a1e6 | 14787 | return xstrdup (fake_name); |
2e276125 JB |
14788 | } |
14789 | } | |
14790 | ||
14791 | ||
14792 | static struct macro_source_file * | |
14793 | macro_start_file (int file, int line, | |
14794 | struct macro_source_file *current_file, | |
14795 | const char *comp_dir, | |
14796 | struct line_header *lh, struct objfile *objfile) | |
14797 | { | |
14798 | /* The full name of this source file. */ | |
14799 | char *full_name = file_full_name (file, lh, comp_dir); | |
14800 | ||
14801 | /* We don't create a macro table for this compilation unit | |
14802 | at all until we actually get a filename. */ | |
14803 | if (! pending_macros) | |
4a146b47 | 14804 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 14805 | objfile->macro_cache); |
2e276125 JB |
14806 | |
14807 | if (! current_file) | |
14808 | /* If we have no current file, then this must be the start_file | |
14809 | directive for the compilation unit's main source file. */ | |
14810 | current_file = macro_set_main (pending_macros, full_name); | |
14811 | else | |
14812 | current_file = macro_include (current_file, line, full_name); | |
14813 | ||
14814 | xfree (full_name); | |
6e70227d | 14815 | |
2e276125 JB |
14816 | return current_file; |
14817 | } | |
14818 | ||
14819 | ||
14820 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
14821 | followed by a null byte. */ | |
14822 | static char * | |
14823 | copy_string (const char *buf, int len) | |
14824 | { | |
14825 | char *s = xmalloc (len + 1); | |
9a619af0 | 14826 | |
2e276125 JB |
14827 | memcpy (s, buf, len); |
14828 | s[len] = '\0'; | |
2e276125 JB |
14829 | return s; |
14830 | } | |
14831 | ||
14832 | ||
14833 | static const char * | |
14834 | consume_improper_spaces (const char *p, const char *body) | |
14835 | { | |
14836 | if (*p == ' ') | |
14837 | { | |
4d3c2250 | 14838 | complaint (&symfile_complaints, |
3e43a32a MS |
14839 | _("macro definition contains spaces " |
14840 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 14841 | body); |
2e276125 JB |
14842 | |
14843 | while (*p == ' ') | |
14844 | p++; | |
14845 | } | |
14846 | ||
14847 | return p; | |
14848 | } | |
14849 | ||
14850 | ||
14851 | static void | |
14852 | parse_macro_definition (struct macro_source_file *file, int line, | |
14853 | const char *body) | |
14854 | { | |
14855 | const char *p; | |
14856 | ||
14857 | /* The body string takes one of two forms. For object-like macro | |
14858 | definitions, it should be: | |
14859 | ||
14860 | <macro name> " " <definition> | |
14861 | ||
14862 | For function-like macro definitions, it should be: | |
14863 | ||
14864 | <macro name> "() " <definition> | |
14865 | or | |
14866 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
14867 | ||
14868 | Spaces may appear only where explicitly indicated, and in the | |
14869 | <definition>. | |
14870 | ||
14871 | The Dwarf 2 spec says that an object-like macro's name is always | |
14872 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 14873 | the space when the macro's definition is the empty string. |
2e276125 JB |
14874 | |
14875 | The Dwarf 2 spec says that there should be no spaces between the | |
14876 | formal arguments in a function-like macro's formal argument list, | |
14877 | but versions of GCC around March 2002 include spaces after the | |
14878 | commas. */ | |
14879 | ||
14880 | ||
14881 | /* Find the extent of the macro name. The macro name is terminated | |
14882 | by either a space or null character (for an object-like macro) or | |
14883 | an opening paren (for a function-like macro). */ | |
14884 | for (p = body; *p; p++) | |
14885 | if (*p == ' ' || *p == '(') | |
14886 | break; | |
14887 | ||
14888 | if (*p == ' ' || *p == '\0') | |
14889 | { | |
14890 | /* It's an object-like macro. */ | |
14891 | int name_len = p - body; | |
14892 | char *name = copy_string (body, name_len); | |
14893 | const char *replacement; | |
14894 | ||
14895 | if (*p == ' ') | |
14896 | replacement = body + name_len + 1; | |
14897 | else | |
14898 | { | |
4d3c2250 | 14899 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14900 | replacement = body + name_len; |
14901 | } | |
6e70227d | 14902 | |
2e276125 JB |
14903 | macro_define_object (file, line, name, replacement); |
14904 | ||
14905 | xfree (name); | |
14906 | } | |
14907 | else if (*p == '(') | |
14908 | { | |
14909 | /* It's a function-like macro. */ | |
14910 | char *name = copy_string (body, p - body); | |
14911 | int argc = 0; | |
14912 | int argv_size = 1; | |
14913 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
14914 | ||
14915 | p++; | |
14916 | ||
14917 | p = consume_improper_spaces (p, body); | |
14918 | ||
14919 | /* Parse the formal argument list. */ | |
14920 | while (*p && *p != ')') | |
14921 | { | |
14922 | /* Find the extent of the current argument name. */ | |
14923 | const char *arg_start = p; | |
14924 | ||
14925 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
14926 | p++; | |
14927 | ||
14928 | if (! *p || p == arg_start) | |
4d3c2250 | 14929 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14930 | else |
14931 | { | |
14932 | /* Make sure argv has room for the new argument. */ | |
14933 | if (argc >= argv_size) | |
14934 | { | |
14935 | argv_size *= 2; | |
14936 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
14937 | } | |
14938 | ||
14939 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
14940 | } | |
14941 | ||
14942 | p = consume_improper_spaces (p, body); | |
14943 | ||
14944 | /* Consume the comma, if present. */ | |
14945 | if (*p == ',') | |
14946 | { | |
14947 | p++; | |
14948 | ||
14949 | p = consume_improper_spaces (p, body); | |
14950 | } | |
14951 | } | |
14952 | ||
14953 | if (*p == ')') | |
14954 | { | |
14955 | p++; | |
14956 | ||
14957 | if (*p == ' ') | |
14958 | /* Perfectly formed definition, no complaints. */ | |
14959 | macro_define_function (file, line, name, | |
6e70227d | 14960 | argc, (const char **) argv, |
2e276125 JB |
14961 | p + 1); |
14962 | else if (*p == '\0') | |
14963 | { | |
14964 | /* Complain, but do define it. */ | |
4d3c2250 | 14965 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 14966 | macro_define_function (file, line, name, |
6e70227d | 14967 | argc, (const char **) argv, |
2e276125 JB |
14968 | p); |
14969 | } | |
14970 | else | |
14971 | /* Just complain. */ | |
4d3c2250 | 14972 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14973 | } |
14974 | else | |
14975 | /* Just complain. */ | |
4d3c2250 | 14976 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14977 | |
14978 | xfree (name); | |
14979 | { | |
14980 | int i; | |
14981 | ||
14982 | for (i = 0; i < argc; i++) | |
14983 | xfree (argv[i]); | |
14984 | } | |
14985 | xfree (argv); | |
14986 | } | |
14987 | else | |
4d3c2250 | 14988 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14989 | } |
14990 | ||
cf2c3c16 TT |
14991 | /* Skip some bytes from BYTES according to the form given in FORM. |
14992 | Returns the new pointer. */ | |
2e276125 | 14993 | |
cf2c3c16 TT |
14994 | static gdb_byte * |
14995 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, | |
14996 | enum dwarf_form form, | |
14997 | unsigned int offset_size, | |
14998 | struct dwarf2_section_info *section) | |
2e276125 | 14999 | { |
cf2c3c16 | 15000 | unsigned int bytes_read; |
2e276125 | 15001 | |
cf2c3c16 | 15002 | switch (form) |
2e276125 | 15003 | { |
cf2c3c16 TT |
15004 | case DW_FORM_data1: |
15005 | case DW_FORM_flag: | |
15006 | ++bytes; | |
15007 | break; | |
15008 | ||
15009 | case DW_FORM_data2: | |
15010 | bytes += 2; | |
15011 | break; | |
15012 | ||
15013 | case DW_FORM_data4: | |
15014 | bytes += 4; | |
15015 | break; | |
15016 | ||
15017 | case DW_FORM_data8: | |
15018 | bytes += 8; | |
15019 | break; | |
15020 | ||
15021 | case DW_FORM_string: | |
15022 | read_direct_string (abfd, bytes, &bytes_read); | |
15023 | bytes += bytes_read; | |
15024 | break; | |
15025 | ||
15026 | case DW_FORM_sec_offset: | |
15027 | case DW_FORM_strp: | |
15028 | bytes += offset_size; | |
15029 | break; | |
15030 | ||
15031 | case DW_FORM_block: | |
15032 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); | |
15033 | bytes += bytes_read; | |
15034 | break; | |
15035 | ||
15036 | case DW_FORM_block1: | |
15037 | bytes += 1 + read_1_byte (abfd, bytes); | |
15038 | break; | |
15039 | case DW_FORM_block2: | |
15040 | bytes += 2 + read_2_bytes (abfd, bytes); | |
15041 | break; | |
15042 | case DW_FORM_block4: | |
15043 | bytes += 4 + read_4_bytes (abfd, bytes); | |
15044 | break; | |
15045 | ||
15046 | case DW_FORM_sdata: | |
15047 | case DW_FORM_udata: | |
15048 | bytes = skip_leb128 (abfd, bytes); | |
15049 | break; | |
15050 | ||
15051 | default: | |
15052 | { | |
15053 | complain: | |
15054 | complaint (&symfile_complaints, | |
15055 | _("invalid form 0x%x in `%s'"), | |
15056 | form, | |
15057 | section->asection->name); | |
15058 | return NULL; | |
15059 | } | |
2e276125 JB |
15060 | } |
15061 | ||
cf2c3c16 TT |
15062 | return bytes; |
15063 | } | |
757a13d0 | 15064 | |
cf2c3c16 TT |
15065 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
15066 | opcode. Returns an updated pointer to the macro data buffer; or, | |
15067 | on error, issues a complaint and returns NULL. */ | |
757a13d0 | 15068 | |
cf2c3c16 TT |
15069 | static gdb_byte * |
15070 | skip_unknown_opcode (unsigned int opcode, | |
15071 | gdb_byte **opcode_definitions, | |
15072 | gdb_byte *mac_ptr, | |
15073 | bfd *abfd, | |
15074 | unsigned int offset_size, | |
15075 | struct dwarf2_section_info *section) | |
15076 | { | |
15077 | unsigned int bytes_read, i; | |
15078 | unsigned long arg; | |
15079 | gdb_byte *defn; | |
2e276125 | 15080 | |
cf2c3c16 | 15081 | if (opcode_definitions[opcode] == NULL) |
2e276125 | 15082 | { |
cf2c3c16 TT |
15083 | complaint (&symfile_complaints, |
15084 | _("unrecognized DW_MACFINO opcode 0x%x"), | |
15085 | opcode); | |
15086 | return NULL; | |
15087 | } | |
2e276125 | 15088 | |
cf2c3c16 TT |
15089 | defn = opcode_definitions[opcode]; |
15090 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); | |
15091 | defn += bytes_read; | |
2e276125 | 15092 | |
cf2c3c16 TT |
15093 | for (i = 0; i < arg; ++i) |
15094 | { | |
15095 | mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section); | |
15096 | if (mac_ptr == NULL) | |
15097 | { | |
15098 | /* skip_form_bytes already issued the complaint. */ | |
15099 | return NULL; | |
15100 | } | |
15101 | } | |
757a13d0 | 15102 | |
cf2c3c16 TT |
15103 | return mac_ptr; |
15104 | } | |
757a13d0 | 15105 | |
cf2c3c16 TT |
15106 | /* A helper function which parses the header of a macro section. |
15107 | If the macro section is the extended (for now called "GNU") type, | |
15108 | then this updates *OFFSET_SIZE. Returns a pointer to just after | |
15109 | the header, or issues a complaint and returns NULL on error. */ | |
757a13d0 | 15110 | |
cf2c3c16 TT |
15111 | static gdb_byte * |
15112 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, | |
15113 | bfd *abfd, | |
15114 | gdb_byte *mac_ptr, | |
15115 | unsigned int *offset_size, | |
15116 | int section_is_gnu) | |
15117 | { | |
15118 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); | |
757a13d0 | 15119 | |
cf2c3c16 TT |
15120 | if (section_is_gnu) |
15121 | { | |
15122 | unsigned int version, flags; | |
757a13d0 | 15123 | |
cf2c3c16 TT |
15124 | version = read_2_bytes (abfd, mac_ptr); |
15125 | if (version != 4) | |
15126 | { | |
15127 | complaint (&symfile_complaints, | |
15128 | _("unrecognized version `%d' in .debug_macro section"), | |
15129 | version); | |
15130 | return NULL; | |
15131 | } | |
15132 | mac_ptr += 2; | |
757a13d0 | 15133 | |
cf2c3c16 TT |
15134 | flags = read_1_byte (abfd, mac_ptr); |
15135 | ++mac_ptr; | |
15136 | *offset_size = (flags & 1) ? 8 : 4; | |
757a13d0 | 15137 | |
cf2c3c16 TT |
15138 | if ((flags & 2) != 0) |
15139 | /* We don't need the line table offset. */ | |
15140 | mac_ptr += *offset_size; | |
757a13d0 | 15141 | |
cf2c3c16 TT |
15142 | /* Vendor opcode descriptions. */ |
15143 | if ((flags & 4) != 0) | |
15144 | { | |
15145 | unsigned int i, count; | |
757a13d0 | 15146 | |
cf2c3c16 TT |
15147 | count = read_1_byte (abfd, mac_ptr); |
15148 | ++mac_ptr; | |
15149 | for (i = 0; i < count; ++i) | |
15150 | { | |
15151 | unsigned int opcode, bytes_read; | |
15152 | unsigned long arg; | |
15153 | ||
15154 | opcode = read_1_byte (abfd, mac_ptr); | |
15155 | ++mac_ptr; | |
15156 | opcode_definitions[opcode] = mac_ptr; | |
15157 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15158 | mac_ptr += bytes_read; | |
15159 | mac_ptr += arg; | |
15160 | } | |
757a13d0 | 15161 | } |
cf2c3c16 | 15162 | } |
757a13d0 | 15163 | |
cf2c3c16 TT |
15164 | return mac_ptr; |
15165 | } | |
757a13d0 | 15166 | |
cf2c3c16 | 15167 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
8fc3fc34 | 15168 | including DW_MACRO_GNU_transparent_include. */ |
cf2c3c16 TT |
15169 | |
15170 | static void | |
15171 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, | |
15172 | struct macro_source_file *current_file, | |
15173 | struct line_header *lh, char *comp_dir, | |
15174 | struct dwarf2_section_info *section, | |
15175 | int section_is_gnu, | |
15176 | unsigned int offset_size, | |
8fc3fc34 TT |
15177 | struct objfile *objfile, |
15178 | htab_t include_hash) | |
cf2c3c16 TT |
15179 | { |
15180 | enum dwarf_macro_record_type macinfo_type; | |
15181 | int at_commandline; | |
15182 | gdb_byte *opcode_definitions[256]; | |
757a13d0 | 15183 | |
cf2c3c16 TT |
15184 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
15185 | &offset_size, section_is_gnu); | |
15186 | if (mac_ptr == NULL) | |
15187 | { | |
15188 | /* We already issued a complaint. */ | |
15189 | return; | |
15190 | } | |
757a13d0 JK |
15191 | |
15192 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
15193 | GDB is still reading the definitions from command line. First | |
15194 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
15195 | to create CURRENT_FILE for the main source holding also the command line | |
15196 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
15197 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
15198 | ||
15199 | at_commandline = 1; | |
15200 | ||
15201 | do | |
15202 | { | |
15203 | /* Do we at least have room for a macinfo type byte? */ | |
15204 | if (mac_ptr >= mac_end) | |
15205 | { | |
cf2c3c16 | 15206 | dwarf2_macros_too_long_complaint (section); |
757a13d0 JK |
15207 | break; |
15208 | } | |
15209 | ||
15210 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15211 | mac_ptr++; | |
15212 | ||
cf2c3c16 TT |
15213 | /* Note that we rely on the fact that the corresponding GNU and |
15214 | DWARF constants are the same. */ | |
757a13d0 JK |
15215 | switch (macinfo_type) |
15216 | { | |
15217 | /* A zero macinfo type indicates the end of the macro | |
15218 | information. */ | |
15219 | case 0: | |
15220 | break; | |
2e276125 | 15221 | |
cf2c3c16 TT |
15222 | case DW_MACRO_GNU_define: |
15223 | case DW_MACRO_GNU_undef: | |
15224 | case DW_MACRO_GNU_define_indirect: | |
15225 | case DW_MACRO_GNU_undef_indirect: | |
2e276125 | 15226 | { |
891d2f0b | 15227 | unsigned int bytes_read; |
2e276125 JB |
15228 | int line; |
15229 | char *body; | |
cf2c3c16 | 15230 | int is_define; |
2e276125 | 15231 | |
cf2c3c16 TT |
15232 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15233 | mac_ptr += bytes_read; | |
15234 | ||
15235 | if (macinfo_type == DW_MACRO_GNU_define | |
15236 | || macinfo_type == DW_MACRO_GNU_undef) | |
15237 | { | |
15238 | body = read_direct_string (abfd, mac_ptr, &bytes_read); | |
15239 | mac_ptr += bytes_read; | |
15240 | } | |
15241 | else | |
15242 | { | |
15243 | LONGEST str_offset; | |
15244 | ||
15245 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15246 | mac_ptr += offset_size; | |
2e276125 | 15247 | |
cf2c3c16 TT |
15248 | body = read_indirect_string_at_offset (abfd, str_offset); |
15249 | } | |
15250 | ||
15251 | is_define = (macinfo_type == DW_MACRO_GNU_define | |
15252 | || macinfo_type == DW_MACRO_GNU_define_indirect); | |
2e276125 | 15253 | if (! current_file) |
757a13d0 JK |
15254 | { |
15255 | /* DWARF violation as no main source is present. */ | |
15256 | complaint (&symfile_complaints, | |
15257 | _("debug info with no main source gives macro %s " | |
15258 | "on line %d: %s"), | |
cf2c3c16 TT |
15259 | is_define ? _("definition") : _("undefinition"), |
15260 | line, body); | |
757a13d0 JK |
15261 | break; |
15262 | } | |
3e43a32a MS |
15263 | if ((line == 0 && !at_commandline) |
15264 | || (line != 0 && at_commandline)) | |
4d3c2250 | 15265 | complaint (&symfile_complaints, |
757a13d0 JK |
15266 | _("debug info gives %s macro %s with %s line %d: %s"), |
15267 | at_commandline ? _("command-line") : _("in-file"), | |
cf2c3c16 | 15268 | is_define ? _("definition") : _("undefinition"), |
757a13d0 JK |
15269 | line == 0 ? _("zero") : _("non-zero"), line, body); |
15270 | ||
cf2c3c16 | 15271 | if (is_define) |
757a13d0 | 15272 | parse_macro_definition (current_file, line, body); |
cf2c3c16 TT |
15273 | else |
15274 | { | |
15275 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef | |
15276 | || macinfo_type == DW_MACRO_GNU_undef_indirect); | |
15277 | macro_undef (current_file, line, body); | |
15278 | } | |
2e276125 JB |
15279 | } |
15280 | break; | |
15281 | ||
cf2c3c16 | 15282 | case DW_MACRO_GNU_start_file: |
2e276125 | 15283 | { |
891d2f0b | 15284 | unsigned int bytes_read; |
2e276125 JB |
15285 | int line, file; |
15286 | ||
15287 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15288 | mac_ptr += bytes_read; | |
15289 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15290 | mac_ptr += bytes_read; | |
15291 | ||
3e43a32a MS |
15292 | if ((line == 0 && !at_commandline) |
15293 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
15294 | complaint (&symfile_complaints, |
15295 | _("debug info gives source %d included " | |
15296 | "from %s at %s line %d"), | |
15297 | file, at_commandline ? _("command-line") : _("file"), | |
15298 | line == 0 ? _("zero") : _("non-zero"), line); | |
15299 | ||
15300 | if (at_commandline) | |
15301 | { | |
cf2c3c16 TT |
15302 | /* This DW_MACRO_GNU_start_file was executed in the |
15303 | pass one. */ | |
757a13d0 JK |
15304 | at_commandline = 0; |
15305 | } | |
15306 | else | |
15307 | current_file = macro_start_file (file, line, | |
15308 | current_file, comp_dir, | |
cf2c3c16 | 15309 | lh, objfile); |
2e276125 JB |
15310 | } |
15311 | break; | |
15312 | ||
cf2c3c16 | 15313 | case DW_MACRO_GNU_end_file: |
2e276125 | 15314 | if (! current_file) |
4d3c2250 | 15315 | complaint (&symfile_complaints, |
3e43a32a MS |
15316 | _("macro debug info has an unmatched " |
15317 | "`close_file' directive")); | |
2e276125 JB |
15318 | else |
15319 | { | |
15320 | current_file = current_file->included_by; | |
15321 | if (! current_file) | |
15322 | { | |
cf2c3c16 | 15323 | enum dwarf_macro_record_type next_type; |
2e276125 JB |
15324 | |
15325 | /* GCC circa March 2002 doesn't produce the zero | |
15326 | type byte marking the end of the compilation | |
15327 | unit. Complain if it's not there, but exit no | |
15328 | matter what. */ | |
15329 | ||
15330 | /* Do we at least have room for a macinfo type byte? */ | |
15331 | if (mac_ptr >= mac_end) | |
15332 | { | |
cf2c3c16 | 15333 | dwarf2_macros_too_long_complaint (section); |
2e276125 JB |
15334 | return; |
15335 | } | |
15336 | ||
15337 | /* We don't increment mac_ptr here, so this is just | |
15338 | a look-ahead. */ | |
15339 | next_type = read_1_byte (abfd, mac_ptr); | |
15340 | if (next_type != 0) | |
4d3c2250 | 15341 | complaint (&symfile_complaints, |
3e43a32a MS |
15342 | _("no terminating 0-type entry for " |
15343 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
15344 | |
15345 | return; | |
15346 | } | |
15347 | } | |
15348 | break; | |
15349 | ||
cf2c3c16 TT |
15350 | case DW_MACRO_GNU_transparent_include: |
15351 | { | |
15352 | LONGEST offset; | |
8fc3fc34 | 15353 | void **slot; |
cf2c3c16 TT |
15354 | |
15355 | offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15356 | mac_ptr += offset_size; | |
15357 | ||
8fc3fc34 TT |
15358 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); |
15359 | if (*slot != NULL) | |
15360 | { | |
15361 | /* This has actually happened; see | |
15362 | http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */ | |
15363 | complaint (&symfile_complaints, | |
15364 | _("recursive DW_MACRO_GNU_transparent_include in " | |
15365 | ".debug_macro section")); | |
15366 | } | |
15367 | else | |
15368 | { | |
15369 | *slot = mac_ptr; | |
15370 | ||
15371 | dwarf_decode_macro_bytes (abfd, | |
15372 | section->buffer + offset, | |
15373 | mac_end, current_file, | |
15374 | lh, comp_dir, | |
15375 | section, section_is_gnu, | |
15376 | offset_size, objfile, include_hash); | |
15377 | ||
15378 | htab_remove_elt (include_hash, mac_ptr); | |
15379 | } | |
cf2c3c16 TT |
15380 | } |
15381 | break; | |
15382 | ||
2e276125 | 15383 | case DW_MACINFO_vendor_ext: |
cf2c3c16 TT |
15384 | if (!section_is_gnu) |
15385 | { | |
15386 | unsigned int bytes_read; | |
15387 | int constant; | |
2e276125 | 15388 | |
cf2c3c16 TT |
15389 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15390 | mac_ptr += bytes_read; | |
15391 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15392 | mac_ptr += bytes_read; | |
2e276125 | 15393 | |
cf2c3c16 TT |
15394 | /* We don't recognize any vendor extensions. */ |
15395 | break; | |
15396 | } | |
15397 | /* FALLTHROUGH */ | |
15398 | ||
15399 | default: | |
15400 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15401 | mac_ptr, abfd, offset_size, | |
15402 | section); | |
15403 | if (mac_ptr == NULL) | |
15404 | return; | |
15405 | break; | |
2e276125 | 15406 | } |
757a13d0 | 15407 | } while (macinfo_type != 0); |
2e276125 | 15408 | } |
8e19ed76 | 15409 | |
cf2c3c16 TT |
15410 | static void |
15411 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
15412 | char *comp_dir, bfd *abfd, | |
15413 | struct dwarf2_cu *cu, | |
15414 | struct dwarf2_section_info *section, | |
15415 | int section_is_gnu) | |
15416 | { | |
bb5ed363 | 15417 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
cf2c3c16 TT |
15418 | gdb_byte *mac_ptr, *mac_end; |
15419 | struct macro_source_file *current_file = 0; | |
15420 | enum dwarf_macro_record_type macinfo_type; | |
15421 | unsigned int offset_size = cu->header.offset_size; | |
15422 | gdb_byte *opcode_definitions[256]; | |
8fc3fc34 TT |
15423 | struct cleanup *cleanup; |
15424 | htab_t include_hash; | |
15425 | void **slot; | |
cf2c3c16 | 15426 | |
bb5ed363 | 15427 | dwarf2_read_section (objfile, section); |
cf2c3c16 TT |
15428 | if (section->buffer == NULL) |
15429 | { | |
15430 | complaint (&symfile_complaints, _("missing %s section"), | |
15431 | section->asection->name); | |
15432 | return; | |
15433 | } | |
15434 | ||
15435 | /* First pass: Find the name of the base filename. | |
15436 | This filename is needed in order to process all macros whose definition | |
15437 | (or undefinition) comes from the command line. These macros are defined | |
15438 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
15439 | associated to the base file. | |
15440 | ||
15441 | To determine the base file name, we scan the macro definitions until we | |
15442 | reach the first DW_MACINFO_start_file entry. We then initialize | |
15443 | CURRENT_FILE accordingly so that any macro definition found before the | |
15444 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
15445 | ||
15446 | mac_ptr = section->buffer + offset; | |
15447 | mac_end = section->buffer + section->size; | |
15448 | ||
15449 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, | |
15450 | &offset_size, section_is_gnu); | |
15451 | if (mac_ptr == NULL) | |
15452 | { | |
15453 | /* We already issued a complaint. */ | |
15454 | return; | |
15455 | } | |
15456 | ||
15457 | do | |
15458 | { | |
15459 | /* Do we at least have room for a macinfo type byte? */ | |
15460 | if (mac_ptr >= mac_end) | |
15461 | { | |
15462 | /* Complaint is printed during the second pass as GDB will probably | |
15463 | stop the first pass earlier upon finding | |
15464 | DW_MACINFO_start_file. */ | |
15465 | break; | |
15466 | } | |
15467 | ||
15468 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15469 | mac_ptr++; | |
15470 | ||
15471 | /* Note that we rely on the fact that the corresponding GNU and | |
15472 | DWARF constants are the same. */ | |
15473 | switch (macinfo_type) | |
15474 | { | |
15475 | /* A zero macinfo type indicates the end of the macro | |
15476 | information. */ | |
15477 | case 0: | |
15478 | break; | |
15479 | ||
15480 | case DW_MACRO_GNU_define: | |
15481 | case DW_MACRO_GNU_undef: | |
15482 | /* Only skip the data by MAC_PTR. */ | |
15483 | { | |
15484 | unsigned int bytes_read; | |
15485 | ||
15486 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15487 | mac_ptr += bytes_read; | |
15488 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15489 | mac_ptr += bytes_read; | |
15490 | } | |
15491 | break; | |
15492 | ||
15493 | case DW_MACRO_GNU_start_file: | |
15494 | { | |
15495 | unsigned int bytes_read; | |
15496 | int line, file; | |
15497 | ||
15498 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15499 | mac_ptr += bytes_read; | |
15500 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15501 | mac_ptr += bytes_read; | |
15502 | ||
15503 | current_file = macro_start_file (file, line, current_file, | |
bb5ed363 | 15504 | comp_dir, lh, objfile); |
cf2c3c16 TT |
15505 | } |
15506 | break; | |
15507 | ||
15508 | case DW_MACRO_GNU_end_file: | |
15509 | /* No data to skip by MAC_PTR. */ | |
15510 | break; | |
15511 | ||
15512 | case DW_MACRO_GNU_define_indirect: | |
15513 | case DW_MACRO_GNU_undef_indirect: | |
15514 | { | |
15515 | unsigned int bytes_read; | |
15516 | ||
15517 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15518 | mac_ptr += bytes_read; | |
15519 | mac_ptr += offset_size; | |
15520 | } | |
15521 | break; | |
15522 | ||
15523 | case DW_MACRO_GNU_transparent_include: | |
15524 | /* Note that, according to the spec, a transparent include | |
15525 | chain cannot call DW_MACRO_GNU_start_file. So, we can just | |
15526 | skip this opcode. */ | |
15527 | mac_ptr += offset_size; | |
15528 | break; | |
15529 | ||
15530 | case DW_MACINFO_vendor_ext: | |
15531 | /* Only skip the data by MAC_PTR. */ | |
15532 | if (!section_is_gnu) | |
15533 | { | |
15534 | unsigned int bytes_read; | |
15535 | ||
15536 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15537 | mac_ptr += bytes_read; | |
15538 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15539 | mac_ptr += bytes_read; | |
15540 | } | |
15541 | /* FALLTHROUGH */ | |
15542 | ||
15543 | default: | |
15544 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15545 | mac_ptr, abfd, offset_size, | |
15546 | section); | |
15547 | if (mac_ptr == NULL) | |
15548 | return; | |
15549 | break; | |
15550 | } | |
15551 | } while (macinfo_type != 0 && current_file == NULL); | |
15552 | ||
15553 | /* Second pass: Process all entries. | |
15554 | ||
15555 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
15556 | command-line macro definitions/undefinitions. This flag is unset when we | |
15557 | reach the first DW_MACINFO_start_file entry. */ | |
15558 | ||
8fc3fc34 TT |
15559 | include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, |
15560 | NULL, xcalloc, xfree); | |
15561 | cleanup = make_cleanup_htab_delete (include_hash); | |
15562 | mac_ptr = section->buffer + offset; | |
15563 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); | |
15564 | *slot = mac_ptr; | |
15565 | dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end, | |
cf2c3c16 | 15566 | current_file, lh, comp_dir, section, section_is_gnu, |
8fc3fc34 TT |
15567 | offset_size, objfile, include_hash); |
15568 | do_cleanups (cleanup); | |
cf2c3c16 TT |
15569 | } |
15570 | ||
8e19ed76 | 15571 | /* Check if the attribute's form is a DW_FORM_block* |
0963b4bd | 15572 | if so return true else false. */ |
8e19ed76 PS |
15573 | static int |
15574 | attr_form_is_block (struct attribute *attr) | |
15575 | { | |
15576 | return (attr == NULL ? 0 : | |
15577 | attr->form == DW_FORM_block1 | |
15578 | || attr->form == DW_FORM_block2 | |
15579 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
15580 | || attr->form == DW_FORM_block |
15581 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 15582 | } |
4c2df51b | 15583 | |
c6a0999f JB |
15584 | /* Return non-zero if ATTR's value is a section offset --- classes |
15585 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
15586 | You may use DW_UNSND (attr) to retrieve such offsets. | |
15587 | ||
15588 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
15589 | may have a value that belongs to more than one of these classes; it | |
15590 | would be ambiguous if we did, because we use the same forms for all | |
15591 | of them. */ | |
3690dd37 JB |
15592 | static int |
15593 | attr_form_is_section_offset (struct attribute *attr) | |
15594 | { | |
15595 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
15596 | || attr->form == DW_FORM_data8 |
15597 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
15598 | } |
15599 | ||
15600 | ||
15601 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
15602 | zero otherwise. When this function returns true, you can apply | |
15603 | dwarf2_get_attr_constant_value to it. | |
15604 | ||
15605 | However, note that for some attributes you must check | |
15606 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
15607 | and DW_FORM_data8 are members of both the constant class, and of | |
15608 | the classes that contain offsets into other debug sections | |
15609 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
15610 | that, if an attribute's can be either a constant or one of the | |
15611 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
15612 | taken as section offsets, not constants. */ | |
15613 | static int | |
15614 | attr_form_is_constant (struct attribute *attr) | |
15615 | { | |
15616 | switch (attr->form) | |
15617 | { | |
15618 | case DW_FORM_sdata: | |
15619 | case DW_FORM_udata: | |
15620 | case DW_FORM_data1: | |
15621 | case DW_FORM_data2: | |
15622 | case DW_FORM_data4: | |
15623 | case DW_FORM_data8: | |
15624 | return 1; | |
15625 | default: | |
15626 | return 0; | |
15627 | } | |
15628 | } | |
15629 | ||
8cf6f0b1 TT |
15630 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
15631 | ||
15632 | static void | |
15633 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
15634 | struct dwarf2_loclist_baton *baton, | |
15635 | struct attribute *attr) | |
15636 | { | |
15637 | dwarf2_read_section (dwarf2_per_objfile->objfile, | |
15638 | &dwarf2_per_objfile->loc); | |
15639 | ||
15640 | baton->per_cu = cu->per_cu; | |
15641 | gdb_assert (baton->per_cu); | |
15642 | /* We don't know how long the location list is, but make sure we | |
15643 | don't run off the edge of the section. */ | |
15644 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); | |
15645 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
15646 | baton->base_address = cu->base_address; | |
15647 | } | |
15648 | ||
4c2df51b DJ |
15649 | static void |
15650 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 15651 | struct dwarf2_cu *cu) |
4c2df51b | 15652 | { |
bb5ed363 DE |
15653 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
15654 | ||
3690dd37 | 15655 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
15656 | /* ".debug_loc" may not exist at all, or the offset may be outside |
15657 | the section. If so, fall through to the complaint in the | |
15658 | other branch. */ | |
bb5ed363 | 15659 | && DW_UNSND (attr) < dwarf2_section_size (objfile, |
9e0ac564 | 15660 | &dwarf2_per_objfile->loc)) |
4c2df51b | 15661 | { |
0d53c4c4 | 15662 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 15663 | |
bb5ed363 | 15664 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 15665 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 15666 | |
8cf6f0b1 | 15667 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 15668 | |
d00adf39 | 15669 | if (cu->base_known == 0) |
0d53c4c4 | 15670 | complaint (&symfile_complaints, |
3e43a32a MS |
15671 | _("Location list used without " |
15672 | "specifying the CU base address.")); | |
4c2df51b | 15673 | |
768a979c | 15674 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
15675 | SYMBOL_LOCATION_BATON (sym) = baton; |
15676 | } | |
15677 | else | |
15678 | { | |
15679 | struct dwarf2_locexpr_baton *baton; | |
15680 | ||
bb5ed363 | 15681 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 15682 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
15683 | baton->per_cu = cu->per_cu; |
15684 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
15685 | |
15686 | if (attr_form_is_block (attr)) | |
15687 | { | |
15688 | /* Note that we're just copying the block's data pointer | |
15689 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
15690 | info_buffer for SYM's objfile; right now we never release |
15691 | that buffer, but when we do clean up properly this may | |
15692 | need to change. */ | |
0d53c4c4 DJ |
15693 | baton->size = DW_BLOCK (attr)->size; |
15694 | baton->data = DW_BLOCK (attr)->data; | |
15695 | } | |
15696 | else | |
15697 | { | |
15698 | dwarf2_invalid_attrib_class_complaint ("location description", | |
15699 | SYMBOL_NATURAL_NAME (sym)); | |
15700 | baton->size = 0; | |
0d53c4c4 | 15701 | } |
6e70227d | 15702 | |
768a979c | 15703 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
15704 | SYMBOL_LOCATION_BATON (sym) = baton; |
15705 | } | |
4c2df51b | 15706 | } |
6502dd73 | 15707 | |
9aa1f1e3 TT |
15708 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
15709 | came from a separate debuginfo file, then the master objfile is | |
15710 | returned. */ | |
ae0d2f24 UW |
15711 | |
15712 | struct objfile * | |
15713 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
15714 | { | |
9291a0cd | 15715 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
15716 | |
15717 | /* Return the master objfile, so that we can report and look up the | |
15718 | correct file containing this variable. */ | |
15719 | if (objfile->separate_debug_objfile_backlink) | |
15720 | objfile = objfile->separate_debug_objfile_backlink; | |
15721 | ||
15722 | return objfile; | |
15723 | } | |
15724 | ||
96408a79 SA |
15725 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
15726 | (CU_HEADERP is unused in such case) or prepare a temporary copy at | |
15727 | CU_HEADERP first. */ | |
15728 | ||
15729 | static const struct comp_unit_head * | |
15730 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, | |
15731 | struct dwarf2_per_cu_data *per_cu) | |
15732 | { | |
15733 | struct objfile *objfile; | |
15734 | struct dwarf2_per_objfile *per_objfile; | |
15735 | gdb_byte *info_ptr; | |
15736 | ||
15737 | if (per_cu->cu) | |
15738 | return &per_cu->cu->header; | |
15739 | ||
15740 | objfile = per_cu->objfile; | |
15741 | per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15742 | info_ptr = per_objfile->info.buffer + per_cu->offset; | |
15743 | ||
15744 | memset (cu_headerp, 0, sizeof (*cu_headerp)); | |
15745 | read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd); | |
15746 | ||
15747 | return cu_headerp; | |
15748 | } | |
15749 | ||
ae0d2f24 UW |
15750 | /* Return the address size given in the compilation unit header for CU. */ |
15751 | ||
98714339 | 15752 | int |
ae0d2f24 UW |
15753 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
15754 | { | |
96408a79 SA |
15755 | struct comp_unit_head cu_header_local; |
15756 | const struct comp_unit_head *cu_headerp; | |
c471e790 | 15757 | |
96408a79 SA |
15758 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
15759 | ||
15760 | return cu_headerp->addr_size; | |
ae0d2f24 UW |
15761 | } |
15762 | ||
9eae7c52 TT |
15763 | /* Return the offset size given in the compilation unit header for CU. */ |
15764 | ||
15765 | int | |
15766 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
15767 | { | |
96408a79 SA |
15768 | struct comp_unit_head cu_header_local; |
15769 | const struct comp_unit_head *cu_headerp; | |
9c6c53f7 | 15770 | |
96408a79 SA |
15771 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
15772 | ||
15773 | return cu_headerp->offset_size; | |
15774 | } | |
15775 | ||
15776 | /* See its dwarf2loc.h declaration. */ | |
15777 | ||
15778 | int | |
15779 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) | |
15780 | { | |
15781 | struct comp_unit_head cu_header_local; | |
15782 | const struct comp_unit_head *cu_headerp; | |
15783 | ||
15784 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); | |
15785 | ||
15786 | if (cu_headerp->version == 2) | |
15787 | return cu_headerp->addr_size; | |
15788 | else | |
15789 | return cu_headerp->offset_size; | |
181cebd4 JK |
15790 | } |
15791 | ||
9aa1f1e3 TT |
15792 | /* Return the text offset of the CU. The returned offset comes from |
15793 | this CU's objfile. If this objfile came from a separate debuginfo | |
15794 | file, then the offset may be different from the corresponding | |
15795 | offset in the parent objfile. */ | |
15796 | ||
15797 | CORE_ADDR | |
15798 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
15799 | { | |
bb3fa9d0 | 15800 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
15801 | |
15802 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
15803 | } | |
15804 | ||
348e048f DE |
15805 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
15806 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
15807 | |
15808 | static struct dwarf2_per_cu_data * | |
c764a876 | 15809 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
15810 | struct objfile *objfile) |
15811 | { | |
15812 | struct dwarf2_per_cu_data *this_cu; | |
15813 | int low, high; | |
15814 | ||
ae038cb0 DJ |
15815 | low = 0; |
15816 | high = dwarf2_per_objfile->n_comp_units - 1; | |
15817 | while (high > low) | |
15818 | { | |
15819 | int mid = low + (high - low) / 2; | |
9a619af0 | 15820 | |
ae038cb0 DJ |
15821 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
15822 | high = mid; | |
15823 | else | |
15824 | low = mid + 1; | |
15825 | } | |
15826 | gdb_assert (low == high); | |
15827 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
15828 | { | |
10b3939b | 15829 | if (low == 0) |
8a3fe4f8 AC |
15830 | error (_("Dwarf Error: could not find partial DIE containing " |
15831 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
15832 | (long) offset, bfd_get_filename (objfile->obfd)); |
15833 | ||
ae038cb0 DJ |
15834 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
15835 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
15836 | } | |
15837 | else | |
15838 | { | |
15839 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
15840 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
15841 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 15842 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
15843 | gdb_assert (offset < this_cu->offset + this_cu->length); |
15844 | return this_cu; | |
15845 | } | |
15846 | } | |
15847 | ||
23745b47 | 15848 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
93311388 | 15849 | |
9816fde3 | 15850 | static void |
23745b47 | 15851 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
93311388 | 15852 | { |
9816fde3 | 15853 | memset (cu, 0, sizeof (*cu)); |
23745b47 DE |
15854 | per_cu->cu = cu; |
15855 | cu->per_cu = per_cu; | |
15856 | cu->objfile = per_cu->objfile; | |
93311388 | 15857 | obstack_init (&cu->comp_unit_obstack); |
9816fde3 JK |
15858 | } |
15859 | ||
15860 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
15861 | ||
15862 | static void | |
15863 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) | |
15864 | { | |
15865 | struct attribute *attr; | |
15866 | ||
15867 | /* Set the language we're debugging. */ | |
15868 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
15869 | if (attr) | |
15870 | set_cu_language (DW_UNSND (attr), cu); | |
15871 | else | |
9cded63f TT |
15872 | { |
15873 | cu->language = language_minimal; | |
15874 | cu->language_defn = language_def (cu->language); | |
15875 | } | |
93311388 DE |
15876 | } |
15877 | ||
ae038cb0 DJ |
15878 | /* Release one cached compilation unit, CU. We unlink it from the tree |
15879 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
15880 | the caller is responsible for that. |
15881 | NOTE: DATA is a void * because this function is also used as a | |
15882 | cleanup routine. */ | |
ae038cb0 DJ |
15883 | |
15884 | static void | |
68dc6402 | 15885 | free_heap_comp_unit (void *data) |
ae038cb0 DJ |
15886 | { |
15887 | struct dwarf2_cu *cu = data; | |
15888 | ||
23745b47 DE |
15889 | gdb_assert (cu->per_cu != NULL); |
15890 | cu->per_cu->cu = NULL; | |
ae038cb0 DJ |
15891 | cu->per_cu = NULL; |
15892 | ||
15893 | obstack_free (&cu->comp_unit_obstack, NULL); | |
15894 | ||
15895 | xfree (cu); | |
15896 | } | |
15897 | ||
72bf9492 | 15898 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
15899 | when we're finished with it. We can't free the pointer itself, but be |
15900 | sure to unlink it from the cache. Also release any associated storage | |
15901 | and perform cache maintenance. | |
72bf9492 DJ |
15902 | |
15903 | Only used during partial symbol parsing. */ | |
15904 | ||
15905 | static void | |
15906 | free_stack_comp_unit (void *data) | |
15907 | { | |
15908 | struct dwarf2_cu *cu = data; | |
15909 | ||
23745b47 DE |
15910 | gdb_assert (cu->per_cu != NULL); |
15911 | cu->per_cu->cu = NULL; | |
15912 | cu->per_cu = NULL; | |
15913 | ||
72bf9492 DJ |
15914 | obstack_free (&cu->comp_unit_obstack, NULL); |
15915 | cu->partial_dies = NULL; | |
ae038cb0 | 15916 | |
23745b47 DE |
15917 | /* The previous code only did this if per_cu != NULL. |
15918 | But that would always succeed, so now we just unconditionally do | |
15919 | the aging. This seems like the wrong place to do such aging, | |
15920 | but cleaning that up is left for later. */ | |
15921 | age_cached_comp_units (); | |
ae038cb0 DJ |
15922 | } |
15923 | ||
15924 | /* Free all cached compilation units. */ | |
15925 | ||
15926 | static void | |
15927 | free_cached_comp_units (void *data) | |
15928 | { | |
15929 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15930 | ||
15931 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15932 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15933 | while (per_cu != NULL) | |
15934 | { | |
15935 | struct dwarf2_per_cu_data *next_cu; | |
15936 | ||
15937 | next_cu = per_cu->cu->read_in_chain; | |
15938 | ||
68dc6402 | 15939 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
15940 | *last_chain = next_cu; |
15941 | ||
15942 | per_cu = next_cu; | |
15943 | } | |
15944 | } | |
15945 | ||
15946 | /* Increase the age counter on each cached compilation unit, and free | |
15947 | any that are too old. */ | |
15948 | ||
15949 | static void | |
15950 | age_cached_comp_units (void) | |
15951 | { | |
15952 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15953 | ||
15954 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
15955 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15956 | while (per_cu != NULL) | |
15957 | { | |
15958 | per_cu->cu->last_used ++; | |
15959 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
15960 | dwarf2_mark (per_cu->cu); | |
15961 | per_cu = per_cu->cu->read_in_chain; | |
15962 | } | |
15963 | ||
15964 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15965 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15966 | while (per_cu != NULL) | |
15967 | { | |
15968 | struct dwarf2_per_cu_data *next_cu; | |
15969 | ||
15970 | next_cu = per_cu->cu->read_in_chain; | |
15971 | ||
15972 | if (!per_cu->cu->mark) | |
15973 | { | |
68dc6402 | 15974 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
15975 | *last_chain = next_cu; |
15976 | } | |
15977 | else | |
15978 | last_chain = &per_cu->cu->read_in_chain; | |
15979 | ||
15980 | per_cu = next_cu; | |
15981 | } | |
15982 | } | |
15983 | ||
15984 | /* Remove a single compilation unit from the cache. */ | |
15985 | ||
15986 | static void | |
15987 | free_one_cached_comp_unit (void *target_cu) | |
15988 | { | |
15989 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15990 | ||
15991 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15992 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15993 | while (per_cu != NULL) | |
15994 | { | |
15995 | struct dwarf2_per_cu_data *next_cu; | |
15996 | ||
15997 | next_cu = per_cu->cu->read_in_chain; | |
15998 | ||
15999 | if (per_cu->cu == target_cu) | |
16000 | { | |
68dc6402 | 16001 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
16002 | *last_chain = next_cu; |
16003 | break; | |
16004 | } | |
16005 | else | |
16006 | last_chain = &per_cu->cu->read_in_chain; | |
16007 | ||
16008 | per_cu = next_cu; | |
16009 | } | |
16010 | } | |
16011 | ||
fe3e1990 DJ |
16012 | /* Release all extra memory associated with OBJFILE. */ |
16013 | ||
16014 | void | |
16015 | dwarf2_free_objfile (struct objfile *objfile) | |
16016 | { | |
16017 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
16018 | ||
16019 | if (dwarf2_per_objfile == NULL) | |
16020 | return; | |
16021 | ||
16022 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
16023 | free_cached_comp_units (NULL); | |
16024 | ||
7b9f3c50 DE |
16025 | if (dwarf2_per_objfile->quick_file_names_table) |
16026 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 16027 | |
fe3e1990 DJ |
16028 | /* Everything else should be on the objfile obstack. */ |
16029 | } | |
16030 | ||
1c379e20 DJ |
16031 | /* A pair of DIE offset and GDB type pointer. We store these |
16032 | in a hash table separate from the DIEs, and preserve them | |
16033 | when the DIEs are flushed out of cache. */ | |
16034 | ||
16035 | struct dwarf2_offset_and_type | |
16036 | { | |
16037 | unsigned int offset; | |
16038 | struct type *type; | |
16039 | }; | |
16040 | ||
16041 | /* Hash function for a dwarf2_offset_and_type. */ | |
16042 | ||
16043 | static hashval_t | |
16044 | offset_and_type_hash (const void *item) | |
16045 | { | |
16046 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 16047 | |
1c379e20 DJ |
16048 | return ofs->offset; |
16049 | } | |
16050 | ||
16051 | /* Equality function for a dwarf2_offset_and_type. */ | |
16052 | ||
16053 | static int | |
16054 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
16055 | { | |
16056 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
16057 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 16058 | |
1c379e20 DJ |
16059 | return ofs_lhs->offset == ofs_rhs->offset; |
16060 | } | |
16061 | ||
16062 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
16063 | table if necessary. For convenience, return TYPE. |
16064 | ||
16065 | The DIEs reading must have careful ordering to: | |
16066 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
16067 | reading current DIE. | |
16068 | * Not trying to dereference contents of still incompletely read in types | |
16069 | while reading in other DIEs. | |
16070 | * Enable referencing still incompletely read in types just by a pointer to | |
16071 | the type without accessing its fields. | |
16072 | ||
16073 | Therefore caller should follow these rules: | |
16074 | * Try to fetch any prerequisite types we may need to build this DIE type | |
16075 | before building the type and calling set_die_type. | |
e71ec853 | 16076 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
16077 | possible before fetching more types to complete the current type. |
16078 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 16079 | |
f792889a | 16080 | static struct type * |
1c379e20 DJ |
16081 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
16082 | { | |
16083 | struct dwarf2_offset_and_type **slot, ofs; | |
673bfd45 DE |
16084 | struct objfile *objfile = cu->objfile; |
16085 | htab_t *type_hash_ptr; | |
1c379e20 | 16086 | |
b4ba55a1 JB |
16087 | /* For Ada types, make sure that the gnat-specific data is always |
16088 | initialized (if not already set). There are a few types where | |
16089 | we should not be doing so, because the type-specific area is | |
16090 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
16091 | where the type-specific area is used to store the floatformat). | |
16092 | But this is not a problem, because the gnat-specific information | |
16093 | is actually not needed for these types. */ | |
16094 | if (need_gnat_info (cu) | |
16095 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
16096 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
16097 | && !HAVE_GNAT_AUX_INFO (type)) | |
16098 | INIT_GNAT_SPECIFIC (type); | |
16099 | ||
b0df02fd | 16100 | if (cu->per_cu->debug_types_section) |
673bfd45 DE |
16101 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; |
16102 | else | |
16103 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; | |
16104 | ||
16105 | if (*type_hash_ptr == NULL) | |
f792889a | 16106 | { |
673bfd45 DE |
16107 | *type_hash_ptr |
16108 | = htab_create_alloc_ex (127, | |
f792889a DJ |
16109 | offset_and_type_hash, |
16110 | offset_and_type_eq, | |
16111 | NULL, | |
673bfd45 | 16112 | &objfile->objfile_obstack, |
f792889a DJ |
16113 | hashtab_obstack_allocate, |
16114 | dummy_obstack_deallocate); | |
f792889a | 16115 | } |
1c379e20 DJ |
16116 | |
16117 | ofs.offset = die->offset; | |
16118 | ofs.type = type; | |
16119 | slot = (struct dwarf2_offset_and_type **) | |
673bfd45 | 16120 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
16121 | if (*slot) |
16122 | complaint (&symfile_complaints, | |
16123 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
16124 | die->offset); | |
673bfd45 | 16125 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 16126 | **slot = ofs; |
f792889a | 16127 | return type; |
1c379e20 DJ |
16128 | } |
16129 | ||
673bfd45 DE |
16130 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
16131 | table, or return NULL if the die does not have a saved type. */ | |
1c379e20 DJ |
16132 | |
16133 | static struct type * | |
673bfd45 DE |
16134 | get_die_type_at_offset (unsigned int offset, |
16135 | struct dwarf2_per_cu_data *per_cu) | |
1c379e20 DJ |
16136 | { |
16137 | struct dwarf2_offset_and_type *slot, ofs; | |
673bfd45 | 16138 | htab_t type_hash; |
f792889a | 16139 | |
b0df02fd | 16140 | if (per_cu->debug_types_section) |
673bfd45 DE |
16141 | type_hash = dwarf2_per_objfile->debug_types_type_hash; |
16142 | else | |
16143 | type_hash = dwarf2_per_objfile->debug_info_type_hash; | |
f792889a DJ |
16144 | if (type_hash == NULL) |
16145 | return NULL; | |
1c379e20 | 16146 | |
673bfd45 | 16147 | ofs.offset = offset; |
1c379e20 DJ |
16148 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
16149 | if (slot) | |
16150 | return slot->type; | |
16151 | else | |
16152 | return NULL; | |
16153 | } | |
16154 | ||
673bfd45 DE |
16155 | /* Look up the type for DIE in the appropriate type_hash table, |
16156 | or return NULL if DIE does not have a saved type. */ | |
16157 | ||
16158 | static struct type * | |
16159 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
16160 | { | |
16161 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
16162 | } | |
16163 | ||
10b3939b DJ |
16164 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
16165 | ||
16166 | static void | |
16167 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
16168 | struct dwarf2_per_cu_data *ref_per_cu) | |
16169 | { | |
16170 | void **slot; | |
16171 | ||
16172 | if (cu->dependencies == NULL) | |
16173 | cu->dependencies | |
16174 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
16175 | NULL, &cu->comp_unit_obstack, | |
16176 | hashtab_obstack_allocate, | |
16177 | dummy_obstack_deallocate); | |
16178 | ||
16179 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
16180 | if (*slot == NULL) | |
16181 | *slot = ref_per_cu; | |
16182 | } | |
1c379e20 | 16183 | |
f504f079 DE |
16184 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
16185 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
16186 | cache that we must keep because we are keeping CU. */ |
16187 | ||
10b3939b DJ |
16188 | static int |
16189 | dwarf2_mark_helper (void **slot, void *data) | |
16190 | { | |
16191 | struct dwarf2_per_cu_data *per_cu; | |
16192 | ||
16193 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
d07ed419 JK |
16194 | |
16195 | /* cu->dependencies references may not yet have been ever read if QUIT aborts | |
16196 | reading of the chain. As such dependencies remain valid it is not much | |
16197 | useful to track and undo them during QUIT cleanups. */ | |
16198 | if (per_cu->cu == NULL) | |
16199 | return 1; | |
16200 | ||
10b3939b DJ |
16201 | if (per_cu->cu->mark) |
16202 | return 1; | |
16203 | per_cu->cu->mark = 1; | |
16204 | ||
16205 | if (per_cu->cu->dependencies != NULL) | |
16206 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
16207 | ||
16208 | return 1; | |
16209 | } | |
16210 | ||
f504f079 DE |
16211 | /* Set the mark field in CU and in every other compilation unit in the |
16212 | cache that we must keep because we are keeping CU. */ | |
16213 | ||
ae038cb0 DJ |
16214 | static void |
16215 | dwarf2_mark (struct dwarf2_cu *cu) | |
16216 | { | |
16217 | if (cu->mark) | |
16218 | return; | |
16219 | cu->mark = 1; | |
10b3939b DJ |
16220 | if (cu->dependencies != NULL) |
16221 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
16222 | } |
16223 | ||
16224 | static void | |
16225 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
16226 | { | |
16227 | while (per_cu) | |
16228 | { | |
16229 | per_cu->cu->mark = 0; | |
16230 | per_cu = per_cu->cu->read_in_chain; | |
16231 | } | |
72bf9492 DJ |
16232 | } |
16233 | ||
72bf9492 DJ |
16234 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
16235 | is its offset in .debug_info for this objfile. */ | |
16236 | ||
16237 | static hashval_t | |
16238 | partial_die_hash (const void *item) | |
16239 | { | |
16240 | const struct partial_die_info *part_die = item; | |
9a619af0 | 16241 | |
72bf9492 DJ |
16242 | return part_die->offset; |
16243 | } | |
16244 | ||
16245 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
16246 | are equal if they have the same offset. */ | |
16247 | ||
16248 | static int | |
16249 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
16250 | { | |
16251 | const struct partial_die_info *part_die_lhs = item_lhs; | |
16252 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 16253 | |
72bf9492 DJ |
16254 | return part_die_lhs->offset == part_die_rhs->offset; |
16255 | } | |
16256 | ||
ae038cb0 DJ |
16257 | static struct cmd_list_element *set_dwarf2_cmdlist; |
16258 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
16259 | ||
16260 | static void | |
16261 | set_dwarf2_cmd (char *args, int from_tty) | |
16262 | { | |
16263 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
16264 | } | |
16265 | ||
16266 | static void | |
16267 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 16268 | { |
ae038cb0 DJ |
16269 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
16270 | } | |
16271 | ||
dce234bc PP |
16272 | /* If section described by INFO was mmapped, munmap it now. */ |
16273 | ||
16274 | static void | |
16275 | munmap_section_buffer (struct dwarf2_section_info *info) | |
16276 | { | |
b315ab21 | 16277 | if (info->map_addr != NULL) |
dce234bc PP |
16278 | { |
16279 | #ifdef HAVE_MMAP | |
b315ab21 | 16280 | int res; |
9a619af0 | 16281 | |
b315ab21 TG |
16282 | res = munmap (info->map_addr, info->map_len); |
16283 | gdb_assert (res == 0); | |
dce234bc PP |
16284 | #else |
16285 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 16286 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
16287 | #endif |
16288 | } | |
16289 | } | |
16290 | ||
16291 | /* munmap debug sections for OBJFILE, if necessary. */ | |
16292 | ||
16293 | static void | |
c1bd65d0 | 16294 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
16295 | { |
16296 | struct dwarf2_per_objfile *data = d; | |
8b70b953 TT |
16297 | int ix; |
16298 | struct dwarf2_section_info *section; | |
9a619af0 | 16299 | |
16be1145 DE |
16300 | /* This is sorted according to the order they're defined in to make it easier |
16301 | to keep in sync. */ | |
dce234bc PP |
16302 | munmap_section_buffer (&data->info); |
16303 | munmap_section_buffer (&data->abbrev); | |
16304 | munmap_section_buffer (&data->line); | |
16be1145 | 16305 | munmap_section_buffer (&data->loc); |
dce234bc | 16306 | munmap_section_buffer (&data->macinfo); |
cf2c3c16 | 16307 | munmap_section_buffer (&data->macro); |
16be1145 | 16308 | munmap_section_buffer (&data->str); |
dce234bc | 16309 | munmap_section_buffer (&data->ranges); |
dce234bc PP |
16310 | munmap_section_buffer (&data->frame); |
16311 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd | 16312 | munmap_section_buffer (&data->gdb_index); |
8b70b953 TT |
16313 | |
16314 | for (ix = 0; | |
16315 | VEC_iterate (dwarf2_section_info_def, data->types, ix, section); | |
16316 | ++ix) | |
16317 | munmap_section_buffer (section); | |
16318 | ||
16319 | VEC_free (dwarf2_section_info_def, data->types); | |
9291a0cd TT |
16320 | } |
16321 | ||
16322 | \f | |
ae2de4f8 | 16323 | /* The "save gdb-index" command. */ |
9291a0cd TT |
16324 | |
16325 | /* The contents of the hash table we create when building the string | |
16326 | table. */ | |
16327 | struct strtab_entry | |
16328 | { | |
16329 | offset_type offset; | |
16330 | const char *str; | |
16331 | }; | |
16332 | ||
559a7a62 JK |
16333 | /* Hash function for a strtab_entry. |
16334 | ||
16335 | Function is used only during write_hash_table so no index format backward | |
16336 | compatibility is needed. */ | |
b89be57b | 16337 | |
9291a0cd TT |
16338 | static hashval_t |
16339 | hash_strtab_entry (const void *e) | |
16340 | { | |
16341 | const struct strtab_entry *entry = e; | |
559a7a62 | 16342 | return mapped_index_string_hash (INT_MAX, entry->str); |
9291a0cd TT |
16343 | } |
16344 | ||
16345 | /* Equality function for a strtab_entry. */ | |
b89be57b | 16346 | |
9291a0cd TT |
16347 | static int |
16348 | eq_strtab_entry (const void *a, const void *b) | |
16349 | { | |
16350 | const struct strtab_entry *ea = a; | |
16351 | const struct strtab_entry *eb = b; | |
16352 | return !strcmp (ea->str, eb->str); | |
16353 | } | |
16354 | ||
16355 | /* Create a strtab_entry hash table. */ | |
b89be57b | 16356 | |
9291a0cd TT |
16357 | static htab_t |
16358 | create_strtab (void) | |
16359 | { | |
16360 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
16361 | xfree, xcalloc, xfree); | |
16362 | } | |
16363 | ||
16364 | /* Add a string to the constant pool. Return the string's offset in | |
16365 | host order. */ | |
b89be57b | 16366 | |
9291a0cd TT |
16367 | static offset_type |
16368 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
16369 | { | |
16370 | void **slot; | |
16371 | struct strtab_entry entry; | |
16372 | struct strtab_entry *result; | |
16373 | ||
16374 | entry.str = str; | |
16375 | slot = htab_find_slot (table, &entry, INSERT); | |
16376 | if (*slot) | |
16377 | result = *slot; | |
16378 | else | |
16379 | { | |
16380 | result = XNEW (struct strtab_entry); | |
16381 | result->offset = obstack_object_size (cpool); | |
16382 | result->str = str; | |
16383 | obstack_grow_str0 (cpool, str); | |
16384 | *slot = result; | |
16385 | } | |
16386 | return result->offset; | |
16387 | } | |
16388 | ||
16389 | /* An entry in the symbol table. */ | |
16390 | struct symtab_index_entry | |
16391 | { | |
16392 | /* The name of the symbol. */ | |
16393 | const char *name; | |
16394 | /* The offset of the name in the constant pool. */ | |
16395 | offset_type index_offset; | |
16396 | /* A sorted vector of the indices of all the CUs that hold an object | |
16397 | of this name. */ | |
16398 | VEC (offset_type) *cu_indices; | |
16399 | }; | |
16400 | ||
16401 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
16402 | struct mapped_symtab | |
16403 | { | |
16404 | offset_type n_elements; | |
16405 | offset_type size; | |
16406 | struct symtab_index_entry **data; | |
16407 | }; | |
16408 | ||
16409 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 16410 | |
9291a0cd TT |
16411 | static hashval_t |
16412 | hash_symtab_entry (const void *e) | |
16413 | { | |
16414 | const struct symtab_index_entry *entry = e; | |
16415 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
16416 | sizeof (offset_type) * VEC_length (offset_type, | |
16417 | entry->cu_indices), | |
16418 | 0); | |
16419 | } | |
16420 | ||
16421 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 16422 | |
9291a0cd TT |
16423 | static int |
16424 | eq_symtab_entry (const void *a, const void *b) | |
16425 | { | |
16426 | const struct symtab_index_entry *ea = a; | |
16427 | const struct symtab_index_entry *eb = b; | |
16428 | int len = VEC_length (offset_type, ea->cu_indices); | |
16429 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
16430 | return 0; | |
16431 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
16432 | VEC_address (offset_type, eb->cu_indices), | |
16433 | sizeof (offset_type) * len); | |
16434 | } | |
16435 | ||
16436 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 16437 | |
9291a0cd TT |
16438 | static void |
16439 | delete_symtab_entry (void *p) | |
16440 | { | |
16441 | struct symtab_index_entry *entry = p; | |
16442 | VEC_free (offset_type, entry->cu_indices); | |
16443 | xfree (entry); | |
16444 | } | |
16445 | ||
16446 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 16447 | |
9291a0cd | 16448 | static htab_t |
3876f04e | 16449 | create_symbol_hash_table (void) |
9291a0cd TT |
16450 | { |
16451 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
16452 | delete_symtab_entry, xcalloc, xfree); | |
16453 | } | |
16454 | ||
16455 | /* Create a new mapped symtab object. */ | |
b89be57b | 16456 | |
9291a0cd TT |
16457 | static struct mapped_symtab * |
16458 | create_mapped_symtab (void) | |
16459 | { | |
16460 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
16461 | symtab->n_elements = 0; | |
16462 | symtab->size = 1024; | |
16463 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16464 | return symtab; | |
16465 | } | |
16466 | ||
16467 | /* Destroy a mapped_symtab. */ | |
b89be57b | 16468 | |
9291a0cd TT |
16469 | static void |
16470 | cleanup_mapped_symtab (void *p) | |
16471 | { | |
16472 | struct mapped_symtab *symtab = p; | |
16473 | /* The contents of the array are freed when the other hash table is | |
16474 | destroyed. */ | |
16475 | xfree (symtab->data); | |
16476 | xfree (symtab); | |
16477 | } | |
16478 | ||
16479 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
559a7a62 JK |
16480 | the slot. |
16481 | ||
16482 | Function is used only during write_hash_table so no index format backward | |
16483 | compatibility is needed. */ | |
b89be57b | 16484 | |
9291a0cd TT |
16485 | static struct symtab_index_entry ** |
16486 | find_slot (struct mapped_symtab *symtab, const char *name) | |
16487 | { | |
559a7a62 | 16488 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd TT |
16489 | |
16490 | index = hash & (symtab->size - 1); | |
16491 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
16492 | ||
16493 | for (;;) | |
16494 | { | |
16495 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
16496 | return &symtab->data[index]; | |
16497 | index = (index + step) & (symtab->size - 1); | |
16498 | } | |
16499 | } | |
16500 | ||
16501 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 16502 | |
9291a0cd TT |
16503 | static void |
16504 | hash_expand (struct mapped_symtab *symtab) | |
16505 | { | |
16506 | offset_type old_size = symtab->size; | |
16507 | offset_type i; | |
16508 | struct symtab_index_entry **old_entries = symtab->data; | |
16509 | ||
16510 | symtab->size *= 2; | |
16511 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16512 | ||
16513 | for (i = 0; i < old_size; ++i) | |
16514 | { | |
16515 | if (old_entries[i]) | |
16516 | { | |
16517 | struct symtab_index_entry **slot = find_slot (symtab, | |
16518 | old_entries[i]->name); | |
16519 | *slot = old_entries[i]; | |
16520 | } | |
16521 | } | |
16522 | ||
16523 | xfree (old_entries); | |
16524 | } | |
16525 | ||
16526 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
16527 | is the index of the CU in which the symbol appears. */ | |
b89be57b | 16528 | |
9291a0cd TT |
16529 | static void |
16530 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
16531 | offset_type cu_index) | |
16532 | { | |
16533 | struct symtab_index_entry **slot; | |
16534 | ||
16535 | ++symtab->n_elements; | |
16536 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
16537 | hash_expand (symtab); | |
16538 | ||
16539 | slot = find_slot (symtab, name); | |
16540 | if (!*slot) | |
16541 | { | |
16542 | *slot = XNEW (struct symtab_index_entry); | |
16543 | (*slot)->name = name; | |
16544 | (*slot)->cu_indices = NULL; | |
16545 | } | |
16546 | /* Don't push an index twice. Due to how we add entries we only | |
16547 | have to check the last one. */ | |
16548 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
cf31e6f9 | 16549 | || VEC_last (offset_type, (*slot)->cu_indices) != cu_index) |
9291a0cd TT |
16550 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); |
16551 | } | |
16552 | ||
16553 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 16554 | |
9291a0cd | 16555 | static offset_type |
3876f04e | 16556 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
16557 | struct symtab_index_entry *entry) |
16558 | { | |
16559 | void **slot; | |
16560 | ||
3876f04e | 16561 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
16562 | if (!*slot) |
16563 | { | |
16564 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
16565 | offset_type val = MAYBE_SWAP (len); | |
16566 | offset_type iter; | |
16567 | int i; | |
16568 | ||
16569 | *slot = entry; | |
16570 | entry->index_offset = obstack_object_size (cpool); | |
16571 | ||
16572 | obstack_grow (cpool, &val, sizeof (val)); | |
16573 | for (i = 0; | |
16574 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
16575 | ++i) | |
16576 | { | |
16577 | val = MAYBE_SWAP (iter); | |
16578 | obstack_grow (cpool, &val, sizeof (val)); | |
16579 | } | |
16580 | } | |
16581 | else | |
16582 | { | |
16583 | struct symtab_index_entry *old_entry = *slot; | |
16584 | entry->index_offset = old_entry->index_offset; | |
16585 | entry = old_entry; | |
16586 | } | |
16587 | return entry->index_offset; | |
16588 | } | |
16589 | ||
16590 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
16591 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 16592 | |
9291a0cd TT |
16593 | static void |
16594 | write_hash_table (struct mapped_symtab *symtab, | |
16595 | struct obstack *output, struct obstack *cpool) | |
16596 | { | |
16597 | offset_type i; | |
3876f04e | 16598 | htab_t symbol_hash_table; |
9291a0cd TT |
16599 | htab_t str_table; |
16600 | ||
3876f04e | 16601 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 16602 | str_table = create_strtab (); |
3876f04e | 16603 | |
9291a0cd TT |
16604 | /* We add all the index vectors to the constant pool first, to |
16605 | ensure alignment is ok. */ | |
16606 | for (i = 0; i < symtab->size; ++i) | |
16607 | { | |
16608 | if (symtab->data[i]) | |
3876f04e | 16609 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
16610 | } |
16611 | ||
16612 | /* Now write out the hash table. */ | |
16613 | for (i = 0; i < symtab->size; ++i) | |
16614 | { | |
16615 | offset_type str_off, vec_off; | |
16616 | ||
16617 | if (symtab->data[i]) | |
16618 | { | |
16619 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
16620 | vec_off = symtab->data[i]->index_offset; | |
16621 | } | |
16622 | else | |
16623 | { | |
16624 | /* While 0 is a valid constant pool index, it is not valid | |
16625 | to have 0 for both offsets. */ | |
16626 | str_off = 0; | |
16627 | vec_off = 0; | |
16628 | } | |
16629 | ||
16630 | str_off = MAYBE_SWAP (str_off); | |
16631 | vec_off = MAYBE_SWAP (vec_off); | |
16632 | ||
16633 | obstack_grow (output, &str_off, sizeof (str_off)); | |
16634 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
16635 | } | |
16636 | ||
16637 | htab_delete (str_table); | |
3876f04e | 16638 | htab_delete (symbol_hash_table); |
9291a0cd TT |
16639 | } |
16640 | ||
0a5429f6 DE |
16641 | /* Struct to map psymtab to CU index in the index file. */ |
16642 | struct psymtab_cu_index_map | |
16643 | { | |
16644 | struct partial_symtab *psymtab; | |
16645 | unsigned int cu_index; | |
16646 | }; | |
16647 | ||
16648 | static hashval_t | |
16649 | hash_psymtab_cu_index (const void *item) | |
16650 | { | |
16651 | const struct psymtab_cu_index_map *map = item; | |
16652 | ||
16653 | return htab_hash_pointer (map->psymtab); | |
16654 | } | |
16655 | ||
16656 | static int | |
16657 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
16658 | { | |
16659 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
16660 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
16661 | ||
16662 | return lhs->psymtab == rhs->psymtab; | |
16663 | } | |
16664 | ||
16665 | /* Helper struct for building the address table. */ | |
16666 | struct addrmap_index_data | |
16667 | { | |
16668 | struct objfile *objfile; | |
16669 | struct obstack *addr_obstack; | |
16670 | htab_t cu_index_htab; | |
16671 | ||
16672 | /* Non-zero if the previous_* fields are valid. | |
16673 | We can't write an entry until we see the next entry (since it is only then | |
16674 | that we know the end of the entry). */ | |
16675 | int previous_valid; | |
16676 | /* Index of the CU in the table of all CUs in the index file. */ | |
16677 | unsigned int previous_cu_index; | |
0963b4bd | 16678 | /* Start address of the CU. */ |
0a5429f6 DE |
16679 | CORE_ADDR previous_cu_start; |
16680 | }; | |
16681 | ||
16682 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 16683 | |
9291a0cd | 16684 | static void |
0a5429f6 DE |
16685 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
16686 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 16687 | { |
0a5429f6 | 16688 | offset_type cu_index_to_write; |
9291a0cd TT |
16689 | char addr[8]; |
16690 | CORE_ADDR baseaddr; | |
16691 | ||
16692 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
16693 | ||
0a5429f6 DE |
16694 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
16695 | obstack_grow (obstack, addr, 8); | |
16696 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
16697 | obstack_grow (obstack, addr, 8); | |
16698 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
16699 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
16700 | } | |
16701 | ||
16702 | /* Worker function for traversing an addrmap to build the address table. */ | |
16703 | ||
16704 | static int | |
16705 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
16706 | { | |
16707 | struct addrmap_index_data *data = datap; | |
16708 | struct partial_symtab *pst = obj; | |
16709 | offset_type cu_index; | |
16710 | void **slot; | |
16711 | ||
16712 | if (data->previous_valid) | |
16713 | add_address_entry (data->objfile, data->addr_obstack, | |
16714 | data->previous_cu_start, start_addr, | |
16715 | data->previous_cu_index); | |
16716 | ||
16717 | data->previous_cu_start = start_addr; | |
16718 | if (pst != NULL) | |
16719 | { | |
16720 | struct psymtab_cu_index_map find_map, *map; | |
16721 | find_map.psymtab = pst; | |
16722 | map = htab_find (data->cu_index_htab, &find_map); | |
16723 | gdb_assert (map != NULL); | |
16724 | data->previous_cu_index = map->cu_index; | |
16725 | data->previous_valid = 1; | |
16726 | } | |
16727 | else | |
16728 | data->previous_valid = 0; | |
16729 | ||
16730 | return 0; | |
16731 | } | |
16732 | ||
16733 | /* Write OBJFILE's address map to OBSTACK. | |
16734 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
16735 | in the index file. */ | |
16736 | ||
16737 | static void | |
16738 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
16739 | htab_t cu_index_htab) | |
16740 | { | |
16741 | struct addrmap_index_data addrmap_index_data; | |
16742 | ||
16743 | /* When writing the address table, we have to cope with the fact that | |
16744 | the addrmap iterator only provides the start of a region; we have to | |
16745 | wait until the next invocation to get the start of the next region. */ | |
16746 | ||
16747 | addrmap_index_data.objfile = objfile; | |
16748 | addrmap_index_data.addr_obstack = obstack; | |
16749 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
16750 | addrmap_index_data.previous_valid = 0; | |
16751 | ||
16752 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
16753 | &addrmap_index_data); | |
16754 | ||
16755 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
16756 | is valid, but we should still handle it. | |
16757 | The end address is recorded as the start of the next region, but that | |
16758 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
16759 | anyway. */ | |
16760 | if (addrmap_index_data.previous_valid) | |
16761 | add_address_entry (objfile, obstack, | |
16762 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
16763 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
16764 | } |
16765 | ||
16766 | /* Add a list of partial symbols to SYMTAB. */ | |
b89be57b | 16767 | |
9291a0cd TT |
16768 | static void |
16769 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 16770 | htab_t psyms_seen, |
9291a0cd TT |
16771 | struct partial_symbol **psymp, |
16772 | int count, | |
987d643c TT |
16773 | offset_type cu_index, |
16774 | int is_static) | |
9291a0cd TT |
16775 | { |
16776 | for (; count-- > 0; ++psymp) | |
16777 | { | |
987d643c TT |
16778 | void **slot, *lookup; |
16779 | ||
9291a0cd TT |
16780 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
16781 | error (_("Ada is not currently supported by the index")); | |
987d643c TT |
16782 | |
16783 | /* We only want to add a given psymbol once. However, we also | |
16784 | want to account for whether it is global or static. So, we | |
16785 | may add it twice, using slightly different values. */ | |
16786 | if (is_static) | |
16787 | { | |
16788 | uintptr_t val = 1 | (uintptr_t) *psymp; | |
16789 | ||
16790 | lookup = (void *) val; | |
16791 | } | |
16792 | else | |
16793 | lookup = *psymp; | |
16794 | ||
16795 | /* Only add a given psymbol once. */ | |
16796 | slot = htab_find_slot (psyms_seen, lookup, INSERT); | |
16797 | if (!*slot) | |
16798 | { | |
16799 | *slot = lookup; | |
bb2f58dc | 16800 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index); |
987d643c | 16801 | } |
9291a0cd TT |
16802 | } |
16803 | } | |
16804 | ||
16805 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
16806 | exception if there is an error. */ | |
b89be57b | 16807 | |
9291a0cd TT |
16808 | static void |
16809 | write_obstack (FILE *file, struct obstack *obstack) | |
16810 | { | |
16811 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
16812 | file) | |
16813 | != obstack_object_size (obstack)) | |
16814 | error (_("couldn't data write to file")); | |
16815 | } | |
16816 | ||
16817 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 16818 | |
9291a0cd TT |
16819 | static void |
16820 | unlink_if_set (void *p) | |
16821 | { | |
16822 | char **filename = p; | |
16823 | if (*filename) | |
16824 | unlink (*filename); | |
16825 | } | |
16826 | ||
1fd400ff TT |
16827 | /* A helper struct used when iterating over debug_types. */ |
16828 | struct signatured_type_index_data | |
16829 | { | |
16830 | struct objfile *objfile; | |
16831 | struct mapped_symtab *symtab; | |
16832 | struct obstack *types_list; | |
987d643c | 16833 | htab_t psyms_seen; |
1fd400ff TT |
16834 | int cu_index; |
16835 | }; | |
16836 | ||
16837 | /* A helper function that writes a single signatured_type to an | |
16838 | obstack. */ | |
b89be57b | 16839 | |
1fd400ff TT |
16840 | static int |
16841 | write_one_signatured_type (void **slot, void *d) | |
16842 | { | |
16843 | struct signatured_type_index_data *info = d; | |
16844 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
16845 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
16846 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
16847 | gdb_byte val[8]; |
16848 | ||
16849 | write_psymbols (info->symtab, | |
987d643c | 16850 | info->psyms_seen, |
3e43a32a MS |
16851 | info->objfile->global_psymbols.list |
16852 | + psymtab->globals_offset, | |
987d643c TT |
16853 | psymtab->n_global_syms, info->cu_index, |
16854 | 0); | |
1fd400ff | 16855 | write_psymbols (info->symtab, |
987d643c | 16856 | info->psyms_seen, |
3e43a32a MS |
16857 | info->objfile->static_psymbols.list |
16858 | + psymtab->statics_offset, | |
987d643c TT |
16859 | psymtab->n_static_syms, info->cu_index, |
16860 | 1); | |
1fd400ff | 16861 | |
b3c8eb43 | 16862 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset); |
1fd400ff TT |
16863 | obstack_grow (info->types_list, val, 8); |
16864 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); | |
16865 | obstack_grow (info->types_list, val, 8); | |
16866 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
16867 | obstack_grow (info->types_list, val, 8); | |
16868 | ||
16869 | ++info->cu_index; | |
16870 | ||
16871 | return 1; | |
16872 | } | |
16873 | ||
9291a0cd | 16874 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 16875 | |
9291a0cd TT |
16876 | static void |
16877 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
16878 | { | |
16879 | struct cleanup *cleanup; | |
16880 | char *filename, *cleanup_filename; | |
1fd400ff TT |
16881 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
16882 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
16883 | int i; |
16884 | FILE *out_file; | |
16885 | struct mapped_symtab *symtab; | |
16886 | offset_type val, size_of_contents, total_len; | |
16887 | struct stat st; | |
16888 | char buf[8]; | |
987d643c | 16889 | htab_t psyms_seen; |
0a5429f6 DE |
16890 | htab_t cu_index_htab; |
16891 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd | 16892 | |
b4f2f049 | 16893 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
9291a0cd | 16894 | return; |
b4f2f049 | 16895 | |
9291a0cd TT |
16896 | if (dwarf2_per_objfile->using_index) |
16897 | error (_("Cannot use an index to create the index")); | |
16898 | ||
8b70b953 TT |
16899 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
16900 | error (_("Cannot make an index when the file has multiple .debug_types sections")); | |
16901 | ||
9291a0cd | 16902 | if (stat (objfile->name, &st) < 0) |
7e17e088 | 16903 | perror_with_name (objfile->name); |
9291a0cd TT |
16904 | |
16905 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
16906 | INDEX_SUFFIX, (char *) NULL); | |
16907 | cleanup = make_cleanup (xfree, filename); | |
16908 | ||
16909 | out_file = fopen (filename, "wb"); | |
16910 | if (!out_file) | |
16911 | error (_("Can't open `%s' for writing"), filename); | |
16912 | ||
16913 | cleanup_filename = filename; | |
16914 | make_cleanup (unlink_if_set, &cleanup_filename); | |
16915 | ||
16916 | symtab = create_mapped_symtab (); | |
16917 | make_cleanup (cleanup_mapped_symtab, symtab); | |
16918 | ||
16919 | obstack_init (&addr_obstack); | |
16920 | make_cleanup_obstack_free (&addr_obstack); | |
16921 | ||
16922 | obstack_init (&cu_list); | |
16923 | make_cleanup_obstack_free (&cu_list); | |
16924 | ||
1fd400ff TT |
16925 | obstack_init (&types_cu_list); |
16926 | make_cleanup_obstack_free (&types_cu_list); | |
16927 | ||
987d643c TT |
16928 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
16929 | NULL, xcalloc, xfree); | |
96408a79 | 16930 | make_cleanup_htab_delete (psyms_seen); |
987d643c | 16931 | |
0a5429f6 DE |
16932 | /* While we're scanning CU's create a table that maps a psymtab pointer |
16933 | (which is what addrmap records) to its index (which is what is recorded | |
16934 | in the index file). This will later be needed to write the address | |
16935 | table. */ | |
16936 | cu_index_htab = htab_create_alloc (100, | |
16937 | hash_psymtab_cu_index, | |
16938 | eq_psymtab_cu_index, | |
16939 | NULL, xcalloc, xfree); | |
96408a79 | 16940 | make_cleanup_htab_delete (cu_index_htab); |
0a5429f6 DE |
16941 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
16942 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
16943 | * dwarf2_per_objfile->n_comp_units); | |
16944 | make_cleanup (xfree, psymtab_cu_index_map); | |
16945 | ||
16946 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
16947 | work here. Also, the debug_types entries do not appear in |
16948 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
16949 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
16950 | { | |
3e43a32a MS |
16951 | struct dwarf2_per_cu_data *per_cu |
16952 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 16953 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 16954 | gdb_byte val[8]; |
0a5429f6 DE |
16955 | struct psymtab_cu_index_map *map; |
16956 | void **slot; | |
9291a0cd TT |
16957 | |
16958 | write_psymbols (symtab, | |
987d643c | 16959 | psyms_seen, |
9291a0cd | 16960 | objfile->global_psymbols.list + psymtab->globals_offset, |
987d643c TT |
16961 | psymtab->n_global_syms, i, |
16962 | 0); | |
9291a0cd | 16963 | write_psymbols (symtab, |
987d643c | 16964 | psyms_seen, |
9291a0cd | 16965 | objfile->static_psymbols.list + psymtab->statics_offset, |
987d643c TT |
16966 | psymtab->n_static_syms, i, |
16967 | 1); | |
9291a0cd | 16968 | |
0a5429f6 DE |
16969 | map = &psymtab_cu_index_map[i]; |
16970 | map->psymtab = psymtab; | |
16971 | map->cu_index = i; | |
16972 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
16973 | gdb_assert (slot != NULL); | |
16974 | gdb_assert (*slot == NULL); | |
16975 | *slot = map; | |
9291a0cd | 16976 | |
e254ef6a | 16977 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
9291a0cd | 16978 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 16979 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
16980 | obstack_grow (&cu_list, val, 8); |
16981 | } | |
16982 | ||
0a5429f6 DE |
16983 | /* Dump the address map. */ |
16984 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
16985 | ||
1fd400ff TT |
16986 | /* Write out the .debug_type entries, if any. */ |
16987 | if (dwarf2_per_objfile->signatured_types) | |
16988 | { | |
16989 | struct signatured_type_index_data sig_data; | |
16990 | ||
16991 | sig_data.objfile = objfile; | |
16992 | sig_data.symtab = symtab; | |
16993 | sig_data.types_list = &types_cu_list; | |
987d643c | 16994 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
16995 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
16996 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
16997 | write_one_signatured_type, &sig_data); | |
16998 | } | |
16999 | ||
9291a0cd TT |
17000 | obstack_init (&constant_pool); |
17001 | make_cleanup_obstack_free (&constant_pool); | |
17002 | obstack_init (&symtab_obstack); | |
17003 | make_cleanup_obstack_free (&symtab_obstack); | |
17004 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
17005 | ||
17006 | obstack_init (&contents); | |
17007 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 17008 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
17009 | total_len = size_of_contents; |
17010 | ||
17011 | /* The version number. */ | |
559a7a62 | 17012 | val = MAYBE_SWAP (5); |
9291a0cd TT |
17013 | obstack_grow (&contents, &val, sizeof (val)); |
17014 | ||
17015 | /* The offset of the CU list from the start of the file. */ | |
17016 | val = MAYBE_SWAP (total_len); | |
17017 | obstack_grow (&contents, &val, sizeof (val)); | |
17018 | total_len += obstack_object_size (&cu_list); | |
17019 | ||
1fd400ff TT |
17020 | /* The offset of the types CU list from the start of the file. */ |
17021 | val = MAYBE_SWAP (total_len); | |
17022 | obstack_grow (&contents, &val, sizeof (val)); | |
17023 | total_len += obstack_object_size (&types_cu_list); | |
17024 | ||
9291a0cd TT |
17025 | /* The offset of the address table from the start of the file. */ |
17026 | val = MAYBE_SWAP (total_len); | |
17027 | obstack_grow (&contents, &val, sizeof (val)); | |
17028 | total_len += obstack_object_size (&addr_obstack); | |
17029 | ||
17030 | /* The offset of the symbol table from the start of the file. */ | |
17031 | val = MAYBE_SWAP (total_len); | |
17032 | obstack_grow (&contents, &val, sizeof (val)); | |
17033 | total_len += obstack_object_size (&symtab_obstack); | |
17034 | ||
17035 | /* The offset of the constant pool from the start of the file. */ | |
17036 | val = MAYBE_SWAP (total_len); | |
17037 | obstack_grow (&contents, &val, sizeof (val)); | |
17038 | total_len += obstack_object_size (&constant_pool); | |
17039 | ||
17040 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
17041 | ||
17042 | write_obstack (out_file, &contents); | |
17043 | write_obstack (out_file, &cu_list); | |
1fd400ff | 17044 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
17045 | write_obstack (out_file, &addr_obstack); |
17046 | write_obstack (out_file, &symtab_obstack); | |
17047 | write_obstack (out_file, &constant_pool); | |
17048 | ||
17049 | fclose (out_file); | |
17050 | ||
17051 | /* We want to keep the file, so we set cleanup_filename to NULL | |
17052 | here. See unlink_if_set. */ | |
17053 | cleanup_filename = NULL; | |
17054 | ||
17055 | do_cleanups (cleanup); | |
17056 | } | |
17057 | ||
90476074 TT |
17058 | /* Implementation of the `save gdb-index' command. |
17059 | ||
17060 | Note that the file format used by this command is documented in the | |
17061 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 17062 | |
9291a0cd TT |
17063 | static void |
17064 | save_gdb_index_command (char *arg, int from_tty) | |
17065 | { | |
17066 | struct objfile *objfile; | |
17067 | ||
17068 | if (!arg || !*arg) | |
96d19272 | 17069 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
17070 | |
17071 | ALL_OBJFILES (objfile) | |
17072 | { | |
17073 | struct stat st; | |
17074 | ||
17075 | /* If the objfile does not correspond to an actual file, skip it. */ | |
17076 | if (stat (objfile->name, &st) < 0) | |
17077 | continue; | |
17078 | ||
17079 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
17080 | if (dwarf2_per_objfile) | |
17081 | { | |
17082 | volatile struct gdb_exception except; | |
17083 | ||
17084 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
17085 | { | |
17086 | write_psymtabs_to_index (objfile, arg); | |
17087 | } | |
17088 | if (except.reason < 0) | |
17089 | exception_fprintf (gdb_stderr, except, | |
17090 | _("Error while writing index for `%s': "), | |
17091 | objfile->name); | |
17092 | } | |
17093 | } | |
dce234bc PP |
17094 | } |
17095 | ||
9291a0cd TT |
17096 | \f |
17097 | ||
9eae7c52 TT |
17098 | int dwarf2_always_disassemble; |
17099 | ||
17100 | static void | |
17101 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
17102 | struct cmd_list_element *c, const char *value) | |
17103 | { | |
3e43a32a MS |
17104 | fprintf_filtered (file, |
17105 | _("Whether to always disassemble " | |
17106 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
17107 | value); |
17108 | } | |
17109 | ||
900e11f9 JK |
17110 | static void |
17111 | show_check_physname (struct ui_file *file, int from_tty, | |
17112 | struct cmd_list_element *c, const char *value) | |
17113 | { | |
17114 | fprintf_filtered (file, | |
17115 | _("Whether to check \"physname\" is %s.\n"), | |
17116 | value); | |
17117 | } | |
17118 | ||
6502dd73 DJ |
17119 | void _initialize_dwarf2_read (void); |
17120 | ||
17121 | void | |
17122 | _initialize_dwarf2_read (void) | |
17123 | { | |
96d19272 JK |
17124 | struct cmd_list_element *c; |
17125 | ||
dce234bc | 17126 | dwarf2_objfile_data_key |
c1bd65d0 | 17127 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 17128 | |
1bedd215 AC |
17129 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
17130 | Set DWARF 2 specific variables.\n\ | |
17131 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
17132 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
17133 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
17134 | ||
1bedd215 AC |
17135 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
17136 | Show DWARF 2 specific variables\n\ | |
17137 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
17138 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
17139 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
17140 | ||
17141 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
17142 | &dwarf2_max_cache_age, _("\ |
17143 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
17144 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
17145 | A higher limit means that cached compilation units will be stored\n\ | |
17146 | in memory longer, and more total memory will be used. Zero disables\n\ | |
17147 | caching, which can slow down startup."), | |
2c5b56ce | 17148 | NULL, |
920d2a44 | 17149 | show_dwarf2_max_cache_age, |
2c5b56ce | 17150 | &set_dwarf2_cmdlist, |
ae038cb0 | 17151 | &show_dwarf2_cmdlist); |
d97bc12b | 17152 | |
9eae7c52 TT |
17153 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
17154 | &dwarf2_always_disassemble, _("\ | |
17155 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
17156 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
17157 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
17158 | syntax. When disabled, expressions will be printed in a more\n\ | |
17159 | conversational style, when possible."), | |
17160 | NULL, | |
17161 | show_dwarf2_always_disassemble, | |
17162 | &set_dwarf2_cmdlist, | |
17163 | &show_dwarf2_cmdlist); | |
17164 | ||
d97bc12b DE |
17165 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
17166 | Set debugging of the dwarf2 DIE reader."), _("\ | |
17167 | Show debugging of the dwarf2 DIE reader."), _("\ | |
17168 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
17169 | The value is the maximum depth to print."), | |
17170 | NULL, | |
17171 | NULL, | |
17172 | &setdebuglist, &showdebuglist); | |
9291a0cd | 17173 | |
900e11f9 JK |
17174 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
17175 | Set cross-checking of \"physname\" code against demangler."), _("\ | |
17176 | Show cross-checking of \"physname\" code against demangler."), _("\ | |
17177 | When enabled, GDB's internal \"physname\" code is checked against\n\ | |
17178 | the demangler."), | |
17179 | NULL, show_check_physname, | |
17180 | &setdebuglist, &showdebuglist); | |
17181 | ||
96d19272 | 17182 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 17183 | _("\ |
fc1a9d6e | 17184 | Save a gdb-index file.\n\ |
11570e71 | 17185 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
17186 | &save_cmdlist); |
17187 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 17188 | } |