1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2013 Free Software Foundation, Inc.
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
12 This file is part of GDB.
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
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
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.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "exceptions.h"
60 #include "completer.h"
65 #include "gdbcore.h" /* for gnutarget */
66 #include "gdb/gdb-index.h"
73 #include "gdb_string.h"
74 #include "gdb_assert.h"
75 #include <sys/types.h>
77 typedef struct symbol *symbolp;
80 /* When non-zero, print basic high level tracing messages.
81 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
82 static int dwarf2_read_debug = 0;
84 /* When non-zero, dump DIEs after they are read in. */
85 static unsigned int dwarf2_die_debug = 0;
87 /* When non-zero, cross-check physname against demangler. */
88 static int check_physname = 0;
90 /* When non-zero, do not reject deprecated .gdb_index sections. */
91 static int use_deprecated_index_sections = 0;
93 static const struct objfile_data *dwarf2_objfile_data_key;
95 /* The "aclass" indices for various kinds of computed DWARF symbols. */
97 static int dwarf2_locexpr_index;
98 static int dwarf2_loclist_index;
99 static int dwarf2_locexpr_block_index;
100 static int dwarf2_loclist_block_index;
102 struct dwarf2_section_info
107 /* True if we have tried to read this section. */
111 typedef struct dwarf2_section_info dwarf2_section_info_def;
112 DEF_VEC_O (dwarf2_section_info_def);
114 /* All offsets in the index are of this type. It must be
115 architecture-independent. */
116 typedef uint32_t offset_type;
118 DEF_VEC_I (offset_type);
120 /* Ensure only legit values are used. */
121 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
123 gdb_assert ((unsigned int) (value) <= 1); \
124 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
127 /* Ensure only legit values are used. */
128 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
130 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
131 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
132 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
135 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
136 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
138 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
139 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
142 /* A description of the mapped index. The file format is described in
143 a comment by the code that writes the index. */
146 /* Index data format version. */
149 /* The total length of the buffer. */
152 /* A pointer to the address table data. */
153 const gdb_byte *address_table;
155 /* Size of the address table data in bytes. */
156 offset_type address_table_size;
158 /* The symbol table, implemented as a hash table. */
159 const offset_type *symbol_table;
161 /* Size in slots, each slot is 2 offset_types. */
162 offset_type symbol_table_slots;
164 /* A pointer to the constant pool. */
165 const char *constant_pool;
168 typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr;
169 DEF_VEC_P (dwarf2_per_cu_ptr);
171 /* Collection of data recorded per objfile.
172 This hangs off of dwarf2_objfile_data_key. */
174 struct dwarf2_per_objfile
176 struct dwarf2_section_info info;
177 struct dwarf2_section_info abbrev;
178 struct dwarf2_section_info line;
179 struct dwarf2_section_info loc;
180 struct dwarf2_section_info macinfo;
181 struct dwarf2_section_info macro;
182 struct dwarf2_section_info str;
183 struct dwarf2_section_info ranges;
184 struct dwarf2_section_info addr;
185 struct dwarf2_section_info frame;
186 struct dwarf2_section_info eh_frame;
187 struct dwarf2_section_info gdb_index;
189 VEC (dwarf2_section_info_def) *types;
192 struct objfile *objfile;
194 /* Table of all the compilation units. This is used to locate
195 the target compilation unit of a particular reference. */
196 struct dwarf2_per_cu_data **all_comp_units;
198 /* The number of compilation units in ALL_COMP_UNITS. */
201 /* The number of .debug_types-related CUs. */
204 /* The .debug_types-related CUs (TUs). */
205 struct signatured_type **all_type_units;
207 /* The number of entries in all_type_unit_groups. */
208 int n_type_unit_groups;
210 /* Table of type unit groups.
211 This exists to make it easy to iterate over all CUs and TU groups. */
212 struct type_unit_group **all_type_unit_groups;
214 /* Table of struct type_unit_group objects.
215 The hash key is the DW_AT_stmt_list value. */
216 htab_t type_unit_groups;
218 /* A table mapping .debug_types signatures to its signatured_type entry.
219 This is NULL if the .debug_types section hasn't been read in yet. */
220 htab_t signatured_types;
222 /* Type unit statistics, to see how well the scaling improvements
226 int nr_uniq_abbrev_tables;
228 int nr_symtab_sharers;
229 int nr_stmt_less_type_units;
232 /* A chain of compilation units that are currently read in, so that
233 they can be freed later. */
234 struct dwarf2_per_cu_data *read_in_chain;
236 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
237 This is NULL if the table hasn't been allocated yet. */
240 /* Non-zero if we've check for whether there is a DWP file. */
243 /* The DWP file if there is one, or NULL. */
244 struct dwp_file *dwp_file;
246 /* The shared '.dwz' file, if one exists. This is used when the
247 original data was compressed using 'dwz -m'. */
248 struct dwz_file *dwz_file;
250 /* A flag indicating wether this objfile has a section loaded at a
252 int has_section_at_zero;
254 /* True if we are using the mapped index,
255 or we are faking it for OBJF_READNOW's sake. */
256 unsigned char using_index;
258 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
259 struct mapped_index *index_table;
261 /* When using index_table, this keeps track of all quick_file_names entries.
262 TUs typically share line table entries with a CU, so we maintain a
263 separate table of all line table entries to support the sharing.
264 Note that while there can be way more TUs than CUs, we've already
265 sorted all the TUs into "type unit groups", grouped by their
266 DW_AT_stmt_list value. Therefore the only sharing done here is with a
267 CU and its associated TU group if there is one. */
268 htab_t quick_file_names_table;
270 /* Set during partial symbol reading, to prevent queueing of full
272 int reading_partial_symbols;
274 /* Table mapping type DIEs to their struct type *.
275 This is NULL if not allocated yet.
276 The mapping is done via (CU/TU signature + DIE offset) -> type. */
277 htab_t die_type_hash;
279 /* The CUs we recently read. */
280 VEC (dwarf2_per_cu_ptr) *just_read_cus;
283 static struct dwarf2_per_objfile *dwarf2_per_objfile;
285 /* Default names of the debugging sections. */
287 /* Note that if the debugging section has been compressed, it might
288 have a name like .zdebug_info. */
290 static const struct dwarf2_debug_sections dwarf2_elf_names =
292 { ".debug_info", ".zdebug_info" },
293 { ".debug_abbrev", ".zdebug_abbrev" },
294 { ".debug_line", ".zdebug_line" },
295 { ".debug_loc", ".zdebug_loc" },
296 { ".debug_macinfo", ".zdebug_macinfo" },
297 { ".debug_macro", ".zdebug_macro" },
298 { ".debug_str", ".zdebug_str" },
299 { ".debug_ranges", ".zdebug_ranges" },
300 { ".debug_types", ".zdebug_types" },
301 { ".debug_addr", ".zdebug_addr" },
302 { ".debug_frame", ".zdebug_frame" },
303 { ".eh_frame", NULL },
304 { ".gdb_index", ".zgdb_index" },
308 /* List of DWO/DWP sections. */
310 static const struct dwop_section_names
312 struct dwarf2_section_names abbrev_dwo;
313 struct dwarf2_section_names info_dwo;
314 struct dwarf2_section_names line_dwo;
315 struct dwarf2_section_names loc_dwo;
316 struct dwarf2_section_names macinfo_dwo;
317 struct dwarf2_section_names macro_dwo;
318 struct dwarf2_section_names str_dwo;
319 struct dwarf2_section_names str_offsets_dwo;
320 struct dwarf2_section_names types_dwo;
321 struct dwarf2_section_names cu_index;
322 struct dwarf2_section_names tu_index;
326 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
327 { ".debug_info.dwo", ".zdebug_info.dwo" },
328 { ".debug_line.dwo", ".zdebug_line.dwo" },
329 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
330 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
331 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
332 { ".debug_str.dwo", ".zdebug_str.dwo" },
333 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
334 { ".debug_types.dwo", ".zdebug_types.dwo" },
335 { ".debug_cu_index", ".zdebug_cu_index" },
336 { ".debug_tu_index", ".zdebug_tu_index" },
339 /* local data types */
341 /* The data in a compilation unit header, after target2host
342 translation, looks like this. */
343 struct comp_unit_head
347 unsigned char addr_size;
348 unsigned char signed_addr_p;
349 sect_offset abbrev_offset;
351 /* Size of file offsets; either 4 or 8. */
352 unsigned int offset_size;
354 /* Size of the length field; either 4 or 12. */
355 unsigned int initial_length_size;
357 /* Offset to the first byte of this compilation unit header in the
358 .debug_info section, for resolving relative reference dies. */
361 /* Offset to first die in this cu from the start of the cu.
362 This will be the first byte following the compilation unit header. */
363 cu_offset first_die_offset;
366 /* Type used for delaying computation of method physnames.
367 See comments for compute_delayed_physnames. */
368 struct delayed_method_info
370 /* The type to which the method is attached, i.e., its parent class. */
373 /* The index of the method in the type's function fieldlists. */
376 /* The index of the method in the fieldlist. */
379 /* The name of the DIE. */
382 /* The DIE associated with this method. */
383 struct die_info *die;
386 typedef struct delayed_method_info delayed_method_info;
387 DEF_VEC_O (delayed_method_info);
389 /* Internal state when decoding a particular compilation unit. */
392 /* The objfile containing this compilation unit. */
393 struct objfile *objfile;
395 /* The header of the compilation unit. */
396 struct comp_unit_head header;
398 /* Base address of this compilation unit. */
399 CORE_ADDR base_address;
401 /* Non-zero if base_address has been set. */
404 /* The language we are debugging. */
405 enum language language;
406 const struct language_defn *language_defn;
408 const char *producer;
410 /* The generic symbol table building routines have separate lists for
411 file scope symbols and all all other scopes (local scopes). So
412 we need to select the right one to pass to add_symbol_to_list().
413 We do it by keeping a pointer to the correct list in list_in_scope.
415 FIXME: The original dwarf code just treated the file scope as the
416 first local scope, and all other local scopes as nested local
417 scopes, and worked fine. Check to see if we really need to
418 distinguish these in buildsym.c. */
419 struct pending **list_in_scope;
421 /* The abbrev table for this CU.
422 Normally this points to the abbrev table in the objfile.
423 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
424 struct abbrev_table *abbrev_table;
426 /* Hash table holding all the loaded partial DIEs
427 with partial_die->offset.SECT_OFF as hash. */
430 /* Storage for things with the same lifetime as this read-in compilation
431 unit, including partial DIEs. */
432 struct obstack comp_unit_obstack;
434 /* When multiple dwarf2_cu structures are living in memory, this field
435 chains them all together, so that they can be released efficiently.
436 We will probably also want a generation counter so that most-recently-used
437 compilation units are cached... */
438 struct dwarf2_per_cu_data *read_in_chain;
440 /* Backchain to our per_cu entry if the tree has been built. */
441 struct dwarf2_per_cu_data *per_cu;
443 /* How many compilation units ago was this CU last referenced? */
446 /* A hash table of DIE cu_offset for following references with
447 die_info->offset.sect_off as hash. */
450 /* Full DIEs if read in. */
451 struct die_info *dies;
453 /* A set of pointers to dwarf2_per_cu_data objects for compilation
454 units referenced by this one. Only set during full symbol processing;
455 partial symbol tables do not have dependencies. */
458 /* Header data from the line table, during full symbol processing. */
459 struct line_header *line_header;
461 /* A list of methods which need to have physnames computed
462 after all type information has been read. */
463 VEC (delayed_method_info) *method_list;
465 /* To be copied to symtab->call_site_htab. */
466 htab_t call_site_htab;
468 /* Non-NULL if this CU came from a DWO file.
469 There is an invariant here that is important to remember:
470 Except for attributes copied from the top level DIE in the "main"
471 (or "stub") file in preparation for reading the DWO file
472 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
473 Either there isn't a DWO file (in which case this is NULL and the point
474 is moot), or there is and either we're not going to read it (in which
475 case this is NULL) or there is and we are reading it (in which case this
477 struct dwo_unit *dwo_unit;
479 /* The DW_AT_addr_base attribute if present, zero otherwise
480 (zero is a valid value though).
481 Note this value comes from the stub CU/TU's DIE. */
484 /* The DW_AT_ranges_base attribute if present, zero otherwise
485 (zero is a valid value though).
486 Note this value comes from the stub CU/TU's DIE.
487 Also note that the value is zero in the non-DWO case so this value can
488 be used without needing to know whether DWO files are in use or not.
489 N.B. This does not apply to DW_AT_ranges appearing in
490 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
491 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
492 DW_AT_ranges_base *would* have to be applied, and we'd have to care
493 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
494 ULONGEST ranges_base;
496 /* Mark used when releasing cached dies. */
497 unsigned int mark : 1;
499 /* This CU references .debug_loc. See the symtab->locations_valid field.
500 This test is imperfect as there may exist optimized debug code not using
501 any location list and still facing inlining issues if handled as
502 unoptimized code. For a future better test see GCC PR other/32998. */
503 unsigned int has_loclist : 1;
505 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
506 if all the producer_is_* fields are valid. This information is cached
507 because profiling CU expansion showed excessive time spent in
508 producer_is_gxx_lt_4_6. */
509 unsigned int checked_producer : 1;
510 unsigned int producer_is_gxx_lt_4_6 : 1;
511 unsigned int producer_is_gcc_lt_4_3 : 1;
512 unsigned int producer_is_icc : 1;
514 /* When set, the file that we're processing is known to have
515 debugging info for C++ namespaces. GCC 3.3.x did not produce
516 this information, but later versions do. */
518 unsigned int processing_has_namespace_info : 1;
521 /* Persistent data held for a compilation unit, even when not
522 processing it. We put a pointer to this structure in the
523 read_symtab_private field of the psymtab. */
525 struct dwarf2_per_cu_data
527 /* The start offset and length of this compilation unit.
528 NOTE: Unlike comp_unit_head.length, this length includes
530 If the DIE refers to a DWO file, this is always of the original die,
535 /* Flag indicating this compilation unit will be read in before
536 any of the current compilation units are processed. */
537 unsigned int queued : 1;
539 /* This flag will be set when reading partial DIEs if we need to load
540 absolutely all DIEs for this compilation unit, instead of just the ones
541 we think are interesting. It gets set if we look for a DIE in the
542 hash table and don't find it. */
543 unsigned int load_all_dies : 1;
545 /* Non-zero if this CU is from .debug_types.
546 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
548 unsigned int is_debug_types : 1;
550 /* Non-zero if this CU is from the .dwz file. */
551 unsigned int is_dwz : 1;
553 /* The section this CU/TU lives in.
554 If the DIE refers to a DWO file, this is always the original die,
556 struct dwarf2_section_info *section;
558 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
559 of the CU cache it gets reset to NULL again. */
560 struct dwarf2_cu *cu;
562 /* The corresponding objfile.
563 Normally we can get the objfile from dwarf2_per_objfile.
564 However we can enter this file with just a "per_cu" handle. */
565 struct objfile *objfile;
567 /* When using partial symbol tables, the 'psymtab' field is active.
568 Otherwise the 'quick' field is active. */
571 /* The partial symbol table associated with this compilation unit,
572 or NULL for unread partial units. */
573 struct partial_symtab *psymtab;
575 /* Data needed by the "quick" functions. */
576 struct dwarf2_per_cu_quick_data *quick;
579 /* The CUs we import using DW_TAG_imported_unit. This is filled in
580 while reading psymtabs, used to compute the psymtab dependencies,
581 and then cleared. Then it is filled in again while reading full
582 symbols, and only deleted when the objfile is destroyed.
584 This is also used to work around a difference between the way gold
585 generates .gdb_index version <=7 and the way gdb does. Arguably this
586 is a gold bug. For symbols coming from TUs, gold records in the index
587 the CU that includes the TU instead of the TU itself. This breaks
588 dw2_lookup_symbol: It assumes that if the index says symbol X lives
589 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
590 will find X. Alas TUs live in their own symtab, so after expanding CU Y
591 we need to look in TU Z to find X. Fortunately, this is akin to
592 DW_TAG_imported_unit, so we just use the same mechanism: For
593 .gdb_index version <=7 this also records the TUs that the CU referred
594 to. Concurrently with this change gdb was modified to emit version 8
595 indices so we only pay a price for gold generated indices. */
596 VEC (dwarf2_per_cu_ptr) *imported_symtabs;
599 /* Entry in the signatured_types hash table. */
601 struct signatured_type
603 /* The "per_cu" object of this type.
604 N.B.: This is the first member so that it's easy to convert pointers
606 struct dwarf2_per_cu_data per_cu;
608 /* The type's signature. */
611 /* Offset in the TU of the type's DIE, as read from the TU header.
612 If this TU is a DWO stub and the definition lives in a DWO file
613 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
614 cu_offset type_offset_in_tu;
616 /* Offset in the section of the type's DIE.
617 If the definition lives in a DWO file, this is the offset in the
618 .debug_types.dwo section.
619 The value is zero until the actual value is known.
620 Zero is otherwise not a valid section offset. */
621 sect_offset type_offset_in_section;
623 /* Type units are grouped by their DW_AT_stmt_list entry so that they
624 can share them. This points to the containing symtab. */
625 struct type_unit_group *type_unit_group;
628 typedef struct signatured_type *sig_type_ptr;
629 DEF_VEC_P (sig_type_ptr);
631 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
632 This includes type_unit_group and quick_file_names. */
634 struct stmt_list_hash
636 /* The DWO unit this table is from or NULL if there is none. */
637 struct dwo_unit *dwo_unit;
639 /* Offset in .debug_line or .debug_line.dwo. */
640 sect_offset line_offset;
643 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
644 an object of this type. */
646 struct type_unit_group
648 /* dwarf2read.c's main "handle" on a TU symtab.
649 To simplify things we create an artificial CU that "includes" all the
650 type units using this stmt_list so that the rest of the code still has
651 a "per_cu" handle on the symtab.
652 This PER_CU is recognized by having no section. */
653 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
654 struct dwarf2_per_cu_data per_cu;
656 /* The TUs that share this DW_AT_stmt_list entry.
657 This is added to while parsing type units to build partial symtabs,
658 and is deleted afterwards and not used again. */
659 VEC (sig_type_ptr) *tus;
661 /* The primary symtab.
662 Type units in a group needn't all be defined in the same source file,
663 so we create an essentially anonymous symtab as the primary symtab. */
664 struct symtab *primary_symtab;
666 /* The data used to construct the hash key. */
667 struct stmt_list_hash hash;
669 /* The number of symtabs from the line header.
670 The value here must match line_header.num_file_names. */
671 unsigned int num_symtabs;
673 /* The symbol tables for this TU (obtained from the files listed in
675 WARNING: The order of entries here must match the order of entries
676 in the line header. After the first TU using this type_unit_group, the
677 line header for the subsequent TUs is recreated from this. This is done
678 because we need to use the same symtabs for each TU using the same
679 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
680 there's no guarantee the line header doesn't have duplicate entries. */
681 struct symtab **symtabs;
684 /* These sections are what may appear in a DWO file. */
688 struct dwarf2_section_info abbrev;
689 struct dwarf2_section_info line;
690 struct dwarf2_section_info loc;
691 struct dwarf2_section_info macinfo;
692 struct dwarf2_section_info macro;
693 struct dwarf2_section_info str;
694 struct dwarf2_section_info str_offsets;
695 /* In the case of a virtual DWO file, these two are unused. */
696 struct dwarf2_section_info info;
697 VEC (dwarf2_section_info_def) *types;
700 /* CUs/TUs in DWP/DWO files. */
704 /* Backlink to the containing struct dwo_file. */
705 struct dwo_file *dwo_file;
707 /* The "id" that distinguishes this CU/TU.
708 .debug_info calls this "dwo_id", .debug_types calls this "signature".
709 Since signatures came first, we stick with it for consistency. */
712 /* The section this CU/TU lives in, in the DWO file. */
713 struct dwarf2_section_info *section;
715 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
719 /* For types, offset in the type's DIE of the type defined by this TU. */
720 cu_offset type_offset_in_tu;
723 /* Data for one DWO file.
724 This includes virtual DWO files that have been packaged into a
729 /* The DW_AT_GNU_dwo_name attribute. This is the hash key.
730 For virtual DWO files the name is constructed from the section offsets
731 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
732 from related CU+TUs. */
735 /* The bfd, when the file is open. Otherwise this is NULL.
736 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
739 /* Section info for this file. */
740 struct dwo_sections sections;
742 /* Table of CUs in the file.
743 Each element is a struct dwo_unit. */
746 /* Table of TUs in the file.
747 Each element is a struct dwo_unit. */
751 /* These sections are what may appear in a DWP file. */
755 struct dwarf2_section_info str;
756 struct dwarf2_section_info cu_index;
757 struct dwarf2_section_info tu_index;
758 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
759 by section number. We don't need to record them here. */
762 /* These sections are what may appear in a virtual DWO file. */
764 struct virtual_dwo_sections
766 struct dwarf2_section_info abbrev;
767 struct dwarf2_section_info line;
768 struct dwarf2_section_info loc;
769 struct dwarf2_section_info macinfo;
770 struct dwarf2_section_info macro;
771 struct dwarf2_section_info str_offsets;
772 /* Each DWP hash table entry records one CU or one TU.
773 That is recorded here, and copied to dwo_unit.section. */
774 struct dwarf2_section_info info_or_types;
777 /* Contents of DWP hash tables. */
779 struct dwp_hash_table
781 uint32_t nr_units, nr_slots;
782 const gdb_byte *hash_table, *unit_table, *section_pool;
785 /* Data for one DWP file. */
789 /* Name of the file. */
792 /* The bfd, when the file is open. Otherwise this is NULL. */
795 /* Section info for this file. */
796 struct dwp_sections sections;
798 /* Table of CUs in the file. */
799 const struct dwp_hash_table *cus;
801 /* Table of TUs in the file. */
802 const struct dwp_hash_table *tus;
804 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
807 /* Table to map ELF section numbers to their sections. */
808 unsigned int num_sections;
809 asection **elf_sections;
812 /* This represents a '.dwz' file. */
816 /* A dwz file can only contain a few sections. */
817 struct dwarf2_section_info abbrev;
818 struct dwarf2_section_info info;
819 struct dwarf2_section_info str;
820 struct dwarf2_section_info line;
821 struct dwarf2_section_info macro;
822 struct dwarf2_section_info gdb_index;
828 /* Struct used to pass misc. parameters to read_die_and_children, et
829 al. which are used for both .debug_info and .debug_types dies.
830 All parameters here are unchanging for the life of the call. This
831 struct exists to abstract away the constant parameters of die reading. */
833 struct die_reader_specs
835 /* die_section->asection->owner. */
838 /* The CU of the DIE we are parsing. */
839 struct dwarf2_cu *cu;
841 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
842 struct dwo_file *dwo_file;
844 /* The section the die comes from.
845 This is either .debug_info or .debug_types, or the .dwo variants. */
846 struct dwarf2_section_info *die_section;
848 /* die_section->buffer. */
851 /* The end of the buffer. */
852 const gdb_byte *buffer_end;
855 /* Type of function passed to init_cutu_and_read_dies, et.al. */
856 typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader,
858 struct die_info *comp_unit_die,
862 /* The line number information for a compilation unit (found in the
863 .debug_line section) begins with a "statement program header",
864 which contains the following information. */
867 unsigned int total_length;
868 unsigned short version;
869 unsigned int header_length;
870 unsigned char minimum_instruction_length;
871 unsigned char maximum_ops_per_instruction;
872 unsigned char default_is_stmt;
874 unsigned char line_range;
875 unsigned char opcode_base;
877 /* standard_opcode_lengths[i] is the number of operands for the
878 standard opcode whose value is i. This means that
879 standard_opcode_lengths[0] is unused, and the last meaningful
880 element is standard_opcode_lengths[opcode_base - 1]. */
881 unsigned char *standard_opcode_lengths;
883 /* The include_directories table. NOTE! These strings are not
884 allocated with xmalloc; instead, they are pointers into
885 debug_line_buffer. If you try to free them, `free' will get
887 unsigned int num_include_dirs, include_dirs_size;
890 /* The file_names table. NOTE! These strings are not allocated
891 with xmalloc; instead, they are pointers into debug_line_buffer.
892 Don't try to free them directly. */
893 unsigned int num_file_names, file_names_size;
897 unsigned int dir_index;
898 unsigned int mod_time;
900 int included_p; /* Non-zero if referenced by the Line Number Program. */
901 struct symtab *symtab; /* The associated symbol table, if any. */
904 /* The start and end of the statement program following this
905 header. These point into dwarf2_per_objfile->line_buffer. */
906 gdb_byte *statement_program_start, *statement_program_end;
909 /* When we construct a partial symbol table entry we only
910 need this much information. */
911 struct partial_die_info
913 /* Offset of this DIE. */
916 /* DWARF-2 tag for this DIE. */
917 ENUM_BITFIELD(dwarf_tag) tag : 16;
919 /* Assorted flags describing the data found in this DIE. */
920 unsigned int has_children : 1;
921 unsigned int is_external : 1;
922 unsigned int is_declaration : 1;
923 unsigned int has_type : 1;
924 unsigned int has_specification : 1;
925 unsigned int has_pc_info : 1;
926 unsigned int may_be_inlined : 1;
928 /* Flag set if the SCOPE field of this structure has been
930 unsigned int scope_set : 1;
932 /* Flag set if the DIE has a byte_size attribute. */
933 unsigned int has_byte_size : 1;
935 /* Flag set if any of the DIE's children are template arguments. */
936 unsigned int has_template_arguments : 1;
938 /* Flag set if fixup_partial_die has been called on this die. */
939 unsigned int fixup_called : 1;
941 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
942 unsigned int is_dwz : 1;
944 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
945 unsigned int spec_is_dwz : 1;
947 /* The name of this DIE. Normally the value of DW_AT_name, but
948 sometimes a default name for unnamed DIEs. */
951 /* The linkage name, if present. */
952 const char *linkage_name;
954 /* The scope to prepend to our children. This is generally
955 allocated on the comp_unit_obstack, so will disappear
956 when this compilation unit leaves the cache. */
959 /* Some data associated with the partial DIE. The tag determines
960 which field is live. */
963 /* The location description associated with this DIE, if any. */
964 struct dwarf_block *locdesc;
965 /* The offset of an import, for DW_TAG_imported_unit. */
969 /* If HAS_PC_INFO, the PC range associated with this DIE. */
973 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
974 DW_AT_sibling, if any. */
975 /* NOTE: This member isn't strictly necessary, read_partial_die could
976 return DW_AT_sibling values to its caller load_partial_dies. */
979 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
980 DW_AT_specification (or DW_AT_abstract_origin or
982 sect_offset spec_offset;
984 /* Pointers to this DIE's parent, first child, and next sibling,
986 struct partial_die_info *die_parent, *die_child, *die_sibling;
989 /* This data structure holds the information of an abbrev. */
992 unsigned int number; /* number identifying abbrev */
993 enum dwarf_tag tag; /* dwarf tag */
994 unsigned short has_children; /* boolean */
995 unsigned short num_attrs; /* number of attributes */
996 struct attr_abbrev *attrs; /* an array of attribute descriptions */
997 struct abbrev_info *next; /* next in chain */
1002 ENUM_BITFIELD(dwarf_attribute) name : 16;
1003 ENUM_BITFIELD(dwarf_form) form : 16;
1006 /* Size of abbrev_table.abbrev_hash_table. */
1007 #define ABBREV_HASH_SIZE 121
1009 /* Top level data structure to contain an abbreviation table. */
1013 /* Where the abbrev table came from.
1014 This is used as a sanity check when the table is used. */
1017 /* Storage for the abbrev table. */
1018 struct obstack abbrev_obstack;
1020 /* Hash table of abbrevs.
1021 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1022 It could be statically allocated, but the previous code didn't so we
1024 struct abbrev_info **abbrevs;
1027 /* Attributes have a name and a value. */
1030 ENUM_BITFIELD(dwarf_attribute) name : 16;
1031 ENUM_BITFIELD(dwarf_form) form : 15;
1033 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1034 field should be in u.str (existing only for DW_STRING) but it is kept
1035 here for better struct attribute alignment. */
1036 unsigned int string_is_canonical : 1;
1041 struct dwarf_block *blk;
1045 struct signatured_type *signatured_type;
1050 /* This data structure holds a complete die structure. */
1053 /* DWARF-2 tag for this DIE. */
1054 ENUM_BITFIELD(dwarf_tag) tag : 16;
1056 /* Number of attributes */
1057 unsigned char num_attrs;
1059 /* True if we're presently building the full type name for the
1060 type derived from this DIE. */
1061 unsigned char building_fullname : 1;
1064 unsigned int abbrev;
1066 /* Offset in .debug_info or .debug_types section. */
1069 /* The dies in a compilation unit form an n-ary tree. PARENT
1070 points to this die's parent; CHILD points to the first child of
1071 this node; and all the children of a given node are chained
1072 together via their SIBLING fields. */
1073 struct die_info *child; /* Its first child, if any. */
1074 struct die_info *sibling; /* Its next sibling, if any. */
1075 struct die_info *parent; /* Its parent, if any. */
1077 /* An array of attributes, with NUM_ATTRS elements. There may be
1078 zero, but it's not common and zero-sized arrays are not
1079 sufficiently portable C. */
1080 struct attribute attrs[1];
1083 /* Get at parts of an attribute structure. */
1085 #define DW_STRING(attr) ((attr)->u.str)
1086 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1087 #define DW_UNSND(attr) ((attr)->u.unsnd)
1088 #define DW_BLOCK(attr) ((attr)->u.blk)
1089 #define DW_SND(attr) ((attr)->u.snd)
1090 #define DW_ADDR(attr) ((attr)->u.addr)
1091 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
1093 /* Blocks are a bunch of untyped bytes. */
1098 /* Valid only if SIZE is not zero. */
1102 #ifndef ATTR_ALLOC_CHUNK
1103 #define ATTR_ALLOC_CHUNK 4
1106 /* Allocate fields for structs, unions and enums in this size. */
1107 #ifndef DW_FIELD_ALLOC_CHUNK
1108 #define DW_FIELD_ALLOC_CHUNK 4
1111 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1112 but this would require a corresponding change in unpack_field_as_long
1114 static int bits_per_byte = 8;
1116 /* The routines that read and process dies for a C struct or C++ class
1117 pass lists of data member fields and lists of member function fields
1118 in an instance of a field_info structure, as defined below. */
1121 /* List of data member and baseclasses fields. */
1124 struct nextfield *next;
1129 *fields, *baseclasses;
1131 /* Number of fields (including baseclasses). */
1134 /* Number of baseclasses. */
1137 /* Set if the accesibility of one of the fields is not public. */
1138 int non_public_fields;
1140 /* Member function fields array, entries are allocated in the order they
1141 are encountered in the object file. */
1144 struct nextfnfield *next;
1145 struct fn_field fnfield;
1149 /* Member function fieldlist array, contains name of possibly overloaded
1150 member function, number of overloaded member functions and a pointer
1151 to the head of the member function field chain. */
1156 struct nextfnfield *head;
1160 /* Number of entries in the fnfieldlists array. */
1163 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1164 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1165 struct typedef_field_list
1167 struct typedef_field field;
1168 struct typedef_field_list *next;
1170 *typedef_field_list;
1171 unsigned typedef_field_list_count;
1174 /* One item on the queue of compilation units to read in full symbols
1176 struct dwarf2_queue_item
1178 struct dwarf2_per_cu_data *per_cu;
1179 enum language pretend_language;
1180 struct dwarf2_queue_item *next;
1183 /* The current queue. */
1184 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
1186 /* Loaded secondary compilation units are kept in memory until they
1187 have not been referenced for the processing of this many
1188 compilation units. Set this to zero to disable caching. Cache
1189 sizes of up to at least twenty will improve startup time for
1190 typical inter-CU-reference binaries, at an obvious memory cost. */
1191 static int dwarf2_max_cache_age = 5;
1193 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
1194 struct cmd_list_element *c, const char *value)
1196 fprintf_filtered (file, _("The upper bound on the age of cached "
1197 "dwarf2 compilation units is %s.\n"),
1202 /* Various complaints about symbol reading that don't abort the process. */
1205 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1207 complaint (&symfile_complaints,
1208 _("statement list doesn't fit in .debug_line section"));
1212 dwarf2_debug_line_missing_file_complaint (void)
1214 complaint (&symfile_complaints,
1215 _(".debug_line section has line data without a file"));
1219 dwarf2_debug_line_missing_end_sequence_complaint (void)
1221 complaint (&symfile_complaints,
1222 _(".debug_line section has line "
1223 "program sequence without an end"));
1227 dwarf2_complex_location_expr_complaint (void)
1229 complaint (&symfile_complaints, _("location expression too complex"));
1233 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
1236 complaint (&symfile_complaints,
1237 _("const value length mismatch for '%s', got %d, expected %d"),
1242 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section)
1244 complaint (&symfile_complaints,
1245 _("debug info runs off end of %s section"
1247 section->asection->name,
1248 bfd_get_filename (section->asection->owner));
1252 dwarf2_macro_malformed_definition_complaint (const char *arg1)
1254 complaint (&symfile_complaints,
1255 _("macro debug info contains a "
1256 "malformed macro definition:\n`%s'"),
1261 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
1263 complaint (&symfile_complaints,
1264 _("invalid attribute class or form for '%s' in '%s'"),
1268 /* local function prototypes */
1270 static void dwarf2_locate_sections (bfd *, asection *, void *);
1272 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
1275 static void dwarf2_find_base_address (struct die_info *die,
1276 struct dwarf2_cu *cu);
1278 static struct partial_symtab *create_partial_symtab
1279 (struct dwarf2_per_cu_data *per_cu, const char *name);
1281 static void dwarf2_build_psymtabs_hard (struct objfile *);
1283 static void scan_partial_symbols (struct partial_die_info *,
1284 CORE_ADDR *, CORE_ADDR *,
1285 int, struct dwarf2_cu *);
1287 static void add_partial_symbol (struct partial_die_info *,
1288 struct dwarf2_cu *);
1290 static void add_partial_namespace (struct partial_die_info *pdi,
1291 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1292 int need_pc, struct dwarf2_cu *cu);
1294 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
1295 CORE_ADDR *highpc, int need_pc,
1296 struct dwarf2_cu *cu);
1298 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
1299 struct dwarf2_cu *cu);
1301 static void add_partial_subprogram (struct partial_die_info *pdi,
1302 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1303 int need_pc, struct dwarf2_cu *cu);
1305 static void dwarf2_read_symtab (struct partial_symtab *,
1308 static void psymtab_to_symtab_1 (struct partial_symtab *);
1310 static struct abbrev_info *abbrev_table_lookup_abbrev
1311 (const struct abbrev_table *, unsigned int);
1313 static struct abbrev_table *abbrev_table_read_table
1314 (struct dwarf2_section_info *, sect_offset);
1316 static void abbrev_table_free (struct abbrev_table *);
1318 static void abbrev_table_free_cleanup (void *);
1320 static void dwarf2_read_abbrevs (struct dwarf2_cu *,
1321 struct dwarf2_section_info *);
1323 static void dwarf2_free_abbrev_table (void *);
1325 static unsigned int peek_abbrev_code (bfd *, gdb_byte *);
1327 static struct partial_die_info *load_partial_dies
1328 (const struct die_reader_specs *, gdb_byte *, int);
1330 static gdb_byte *read_partial_die (const struct die_reader_specs *,
1331 struct partial_die_info *,
1332 struct abbrev_info *,
1336 static struct partial_die_info *find_partial_die (sect_offset, int,
1337 struct dwarf2_cu *);
1339 static void fixup_partial_die (struct partial_die_info *,
1340 struct dwarf2_cu *);
1342 static gdb_byte *read_attribute (const struct die_reader_specs *,
1343 struct attribute *, struct attr_abbrev *,
1346 static unsigned int read_1_byte (bfd *, const gdb_byte *);
1348 static int read_1_signed_byte (bfd *, const gdb_byte *);
1350 static unsigned int read_2_bytes (bfd *, const gdb_byte *);
1352 static unsigned int read_4_bytes (bfd *, const gdb_byte *);
1354 static ULONGEST read_8_bytes (bfd *, const gdb_byte *);
1356 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
1359 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
1361 static LONGEST read_checked_initial_length_and_offset
1362 (bfd *, gdb_byte *, const struct comp_unit_head *,
1363 unsigned int *, unsigned int *);
1365 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
1368 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
1370 static sect_offset read_abbrev_offset (struct dwarf2_section_info *,
1373 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
1375 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
1377 static char *read_indirect_string (bfd *, gdb_byte *,
1378 const struct comp_unit_head *,
1381 static char *read_indirect_string_from_dwz (struct dwz_file *, LONGEST);
1383 static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
1385 static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
1387 static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, gdb_byte *,
1390 static char *read_str_index (const struct die_reader_specs *reader,
1391 struct dwarf2_cu *cu, ULONGEST str_index);
1393 static void set_cu_language (unsigned int, struct dwarf2_cu *);
1395 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
1396 struct dwarf2_cu *);
1398 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
1401 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
1402 struct dwarf2_cu *cu);
1404 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
1406 static struct die_info *die_specification (struct die_info *die,
1407 struct dwarf2_cu **);
1409 static void free_line_header (struct line_header *lh);
1411 static void add_file_name (struct line_header *, char *, unsigned int,
1412 unsigned int, unsigned int);
1414 static struct line_header *dwarf_decode_line_header (unsigned int offset,
1415 struct dwarf2_cu *cu);
1417 static void dwarf_decode_lines (struct line_header *, const char *,
1418 struct dwarf2_cu *, struct partial_symtab *,
1421 static void dwarf2_start_subfile (char *, const char *, const char *);
1423 static void dwarf2_start_symtab (struct dwarf2_cu *,
1424 const char *, const char *, CORE_ADDR);
1426 static struct symbol *new_symbol (struct die_info *, struct type *,
1427 struct dwarf2_cu *);
1429 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1430 struct dwarf2_cu *, struct symbol *);
1432 static void dwarf2_const_value (struct attribute *, struct symbol *,
1433 struct dwarf2_cu *);
1435 static void dwarf2_const_value_attr (struct attribute *attr,
1438 struct obstack *obstack,
1439 struct dwarf2_cu *cu, LONGEST *value,
1441 struct dwarf2_locexpr_baton **baton);
1443 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1445 static int need_gnat_info (struct dwarf2_cu *);
1447 static struct type *die_descriptive_type (struct die_info *,
1448 struct dwarf2_cu *);
1450 static void set_descriptive_type (struct type *, struct die_info *,
1451 struct dwarf2_cu *);
1453 static struct type *die_containing_type (struct die_info *,
1454 struct dwarf2_cu *);
1456 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1457 struct dwarf2_cu *);
1459 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1461 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1463 static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1465 static char *typename_concat (struct obstack *obs, const char *prefix,
1466 const char *suffix, int physname,
1467 struct dwarf2_cu *cu);
1469 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1471 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1473 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1475 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1477 static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
1479 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1480 struct dwarf2_cu *, struct partial_symtab *);
1482 static int dwarf2_get_pc_bounds (struct die_info *,
1483 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1484 struct partial_symtab *);
1486 static void get_scope_pc_bounds (struct die_info *,
1487 CORE_ADDR *, CORE_ADDR *,
1488 struct dwarf2_cu *);
1490 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1491 CORE_ADDR, struct dwarf2_cu *);
1493 static void dwarf2_add_field (struct field_info *, struct die_info *,
1494 struct dwarf2_cu *);
1496 static void dwarf2_attach_fields_to_type (struct field_info *,
1497 struct type *, struct dwarf2_cu *);
1499 static void dwarf2_add_member_fn (struct field_info *,
1500 struct die_info *, struct type *,
1501 struct dwarf2_cu *);
1503 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1505 struct dwarf2_cu *);
1507 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1509 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1511 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1513 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1515 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1517 static struct type *read_module_type (struct die_info *die,
1518 struct dwarf2_cu *cu);
1520 static const char *namespace_name (struct die_info *die,
1521 int *is_anonymous, struct dwarf2_cu *);
1523 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1525 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1527 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1528 struct dwarf2_cu *);
1530 static struct die_info *read_die_and_children (const struct die_reader_specs *,
1532 gdb_byte **new_info_ptr,
1533 struct die_info *parent);
1535 static struct die_info *read_die_and_siblings (const struct die_reader_specs *,
1537 gdb_byte **new_info_ptr,
1538 struct die_info *parent);
1540 static gdb_byte *read_full_die_1 (const struct die_reader_specs *,
1541 struct die_info **, gdb_byte *, int *, int);
1543 static gdb_byte *read_full_die (const struct die_reader_specs *,
1544 struct die_info **, gdb_byte *, int *);
1546 static void process_die (struct die_info *, struct dwarf2_cu *);
1548 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu *,
1551 static const char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1553 static const char *dwarf2_full_name (const char *name,
1554 struct die_info *die,
1555 struct dwarf2_cu *cu);
1557 static const char *dwarf2_physname (const char *name, struct die_info *die,
1558 struct dwarf2_cu *cu);
1560 static struct die_info *dwarf2_extension (struct die_info *die,
1561 struct dwarf2_cu **);
1563 static const char *dwarf_tag_name (unsigned int);
1565 static const char *dwarf_attr_name (unsigned int);
1567 static const char *dwarf_form_name (unsigned int);
1569 static char *dwarf_bool_name (unsigned int);
1571 static const char *dwarf_type_encoding_name (unsigned int);
1573 static struct die_info *sibling_die (struct die_info *);
1575 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1577 static void dump_die_for_error (struct die_info *);
1579 static void dump_die_1 (struct ui_file *, int level, int max_level,
1582 /*static*/ void dump_die (struct die_info *, int max_level);
1584 static void store_in_ref_table (struct die_info *,
1585 struct dwarf2_cu *);
1587 static int is_ref_attr (struct attribute *);
1589 static sect_offset dwarf2_get_ref_die_offset (struct attribute *);
1591 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1593 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1595 struct dwarf2_cu **);
1597 static struct die_info *follow_die_ref (struct die_info *,
1599 struct dwarf2_cu **);
1601 static struct die_info *follow_die_sig (struct die_info *,
1603 struct dwarf2_cu **);
1605 static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
1607 static void read_signatured_type (struct signatured_type *);
1609 static struct type_unit_group *get_type_unit_group
1610 (struct dwarf2_cu *, struct attribute *);
1612 static void build_type_unit_groups (die_reader_func_ftype *, void *);
1614 /* memory allocation interface */
1616 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1618 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1620 static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int,
1623 static int attr_form_is_block (struct attribute *);
1625 static int attr_form_is_section_offset (struct attribute *);
1627 static int attr_form_is_constant (struct attribute *);
1629 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1630 struct dwarf2_loclist_baton *baton,
1631 struct attribute *attr);
1633 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1635 struct dwarf2_cu *cu,
1638 static gdb_byte *skip_one_die (const struct die_reader_specs *reader,
1640 struct abbrev_info *abbrev);
1642 static void free_stack_comp_unit (void *);
1644 static hashval_t partial_die_hash (const void *item);
1646 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1648 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1649 (sect_offset offset, unsigned int offset_in_dwz, struct objfile *objfile);
1651 static void init_one_comp_unit (struct dwarf2_cu *cu,
1652 struct dwarf2_per_cu_data *per_cu);
1654 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1655 struct die_info *comp_unit_die,
1656 enum language pretend_language);
1658 static void free_heap_comp_unit (void *);
1660 static void free_cached_comp_units (void *);
1662 static void age_cached_comp_units (void);
1664 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *);
1666 static struct type *set_die_type (struct die_info *, struct type *,
1667 struct dwarf2_cu *);
1669 static void create_all_comp_units (struct objfile *);
1671 static int create_all_type_units (struct objfile *);
1673 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1676 static void process_full_comp_unit (struct dwarf2_per_cu_data *,
1679 static void process_full_type_unit (struct dwarf2_per_cu_data *,
1682 static void dwarf2_add_dependence (struct dwarf2_cu *,
1683 struct dwarf2_per_cu_data *);
1685 static void dwarf2_mark (struct dwarf2_cu *);
1687 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1689 static struct type *get_die_type_at_offset (sect_offset,
1690 struct dwarf2_per_cu_data *per_cu);
1692 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1694 static void dwarf2_release_queue (void *dummy);
1696 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1697 enum language pretend_language);
1699 static int maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
1700 struct dwarf2_per_cu_data *per_cu,
1701 enum language pretend_language);
1703 static void process_queue (void);
1705 static void find_file_and_directory (struct die_info *die,
1706 struct dwarf2_cu *cu,
1707 const char **name, const char **comp_dir);
1709 static char *file_full_name (int file, struct line_header *lh,
1710 const char *comp_dir);
1712 static gdb_byte *read_and_check_comp_unit_head
1713 (struct comp_unit_head *header,
1714 struct dwarf2_section_info *section,
1715 struct dwarf2_section_info *abbrev_section, gdb_byte *info_ptr,
1716 int is_debug_types_section);
1718 static void init_cutu_and_read_dies
1719 (struct dwarf2_per_cu_data *this_cu, struct abbrev_table *abbrev_table,
1720 int use_existing_cu, int keep,
1721 die_reader_func_ftype *die_reader_func, void *data);
1723 static void init_cutu_and_read_dies_simple
1724 (struct dwarf2_per_cu_data *this_cu,
1725 die_reader_func_ftype *die_reader_func, void *data);
1727 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1729 static htab_t allocate_dwo_unit_table (struct objfile *objfile);
1731 static struct dwo_unit *lookup_dwo_comp_unit
1732 (struct dwarf2_per_cu_data *, const char *, const char *, ULONGEST);
1734 static struct dwo_unit *lookup_dwo_type_unit
1735 (struct signatured_type *, const char *, const char *);
1737 static void free_dwo_file_cleanup (void *);
1739 static void process_cu_includes (void);
1741 static void check_producer (struct dwarf2_cu *cu);
1745 /* Convert VALUE between big- and little-endian. */
1747 byte_swap (offset_type value)
1751 result = (value & 0xff) << 24;
1752 result |= (value & 0xff00) << 8;
1753 result |= (value & 0xff0000) >> 8;
1754 result |= (value & 0xff000000) >> 24;
1758 #define MAYBE_SWAP(V) byte_swap (V)
1761 #define MAYBE_SWAP(V) (V)
1762 #endif /* WORDS_BIGENDIAN */
1764 /* The suffix for an index file. */
1765 #define INDEX_SUFFIX ".gdb-index"
1767 /* Try to locate the sections we need for DWARF 2 debugging
1768 information and return true if we have enough to do something.
1769 NAMES points to the dwarf2 section names, or is NULL if the standard
1770 ELF names are used. */
1773 dwarf2_has_info (struct objfile *objfile,
1774 const struct dwarf2_debug_sections *names)
1776 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1777 if (!dwarf2_per_objfile)
1779 /* Initialize per-objfile state. */
1780 struct dwarf2_per_objfile *data
1781 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1783 memset (data, 0, sizeof (*data));
1784 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1785 dwarf2_per_objfile = data;
1787 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1789 dwarf2_per_objfile->objfile = objfile;
1791 return (dwarf2_per_objfile->info.asection != NULL
1792 && dwarf2_per_objfile->abbrev.asection != NULL);
1795 /* When loading sections, we look either for uncompressed section or for
1796 compressed section names. */
1799 section_is_p (const char *section_name,
1800 const struct dwarf2_section_names *names)
1802 if (names->normal != NULL
1803 && strcmp (section_name, names->normal) == 0)
1805 if (names->compressed != NULL
1806 && strcmp (section_name, names->compressed) == 0)
1811 /* This function is mapped across the sections and remembers the
1812 offset and size of each of the debugging sections we are interested
1816 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1818 const struct dwarf2_debug_sections *names;
1819 flagword aflag = bfd_get_section_flags (abfd, sectp);
1822 names = &dwarf2_elf_names;
1824 names = (const struct dwarf2_debug_sections *) vnames;
1826 if ((aflag & SEC_HAS_CONTENTS) == 0)
1829 else if (section_is_p (sectp->name, &names->info))
1831 dwarf2_per_objfile->info.asection = sectp;
1832 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1834 else if (section_is_p (sectp->name, &names->abbrev))
1836 dwarf2_per_objfile->abbrev.asection = sectp;
1837 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1839 else if (section_is_p (sectp->name, &names->line))
1841 dwarf2_per_objfile->line.asection = sectp;
1842 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1844 else if (section_is_p (sectp->name, &names->loc))
1846 dwarf2_per_objfile->loc.asection = sectp;
1847 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1849 else if (section_is_p (sectp->name, &names->macinfo))
1851 dwarf2_per_objfile->macinfo.asection = sectp;
1852 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1854 else if (section_is_p (sectp->name, &names->macro))
1856 dwarf2_per_objfile->macro.asection = sectp;
1857 dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
1859 else if (section_is_p (sectp->name, &names->str))
1861 dwarf2_per_objfile->str.asection = sectp;
1862 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1864 else if (section_is_p (sectp->name, &names->addr))
1866 dwarf2_per_objfile->addr.asection = sectp;
1867 dwarf2_per_objfile->addr.size = bfd_get_section_size (sectp);
1869 else if (section_is_p (sectp->name, &names->frame))
1871 dwarf2_per_objfile->frame.asection = sectp;
1872 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1874 else if (section_is_p (sectp->name, &names->eh_frame))
1876 dwarf2_per_objfile->eh_frame.asection = sectp;
1877 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1879 else if (section_is_p (sectp->name, &names->ranges))
1881 dwarf2_per_objfile->ranges.asection = sectp;
1882 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1884 else if (section_is_p (sectp->name, &names->types))
1886 struct dwarf2_section_info type_section;
1888 memset (&type_section, 0, sizeof (type_section));
1889 type_section.asection = sectp;
1890 type_section.size = bfd_get_section_size (sectp);
1892 VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
1895 else if (section_is_p (sectp->name, &names->gdb_index))
1897 dwarf2_per_objfile->gdb_index.asection = sectp;
1898 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1901 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1902 && bfd_section_vma (abfd, sectp) == 0)
1903 dwarf2_per_objfile->has_section_at_zero = 1;
1906 /* A helper function that decides whether a section is empty,
1910 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1912 return info->asection == NULL || info->size == 0;
1915 /* Read the contents of the section INFO.
1916 OBJFILE is the main object file, but not necessarily the file where
1917 the section comes from. E.g., for DWO files INFO->asection->owner
1918 is the bfd of the DWO file.
1919 If the section is compressed, uncompress it before returning. */
1922 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1924 asection *sectp = info->asection;
1926 gdb_byte *buf, *retbuf;
1927 unsigned char header[4];
1931 info->buffer = NULL;
1934 if (dwarf2_section_empty_p (info))
1937 abfd = sectp->owner;
1939 /* If the section has relocations, we must read it ourselves.
1940 Otherwise we attach it to the BFD. */
1941 if ((sectp->flags & SEC_RELOC) == 0)
1943 const gdb_byte *bytes = gdb_bfd_map_section (sectp, &info->size);
1945 /* We have to cast away const here for historical reasons.
1946 Fixing dwarf2read to be const-correct would be quite nice. */
1947 info->buffer = (gdb_byte *) bytes;
1951 buf = obstack_alloc (&objfile->objfile_obstack, info->size);
1954 /* When debugging .o files, we may need to apply relocations; see
1955 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1956 We never compress sections in .o files, so we only need to
1957 try this when the section is not compressed. */
1958 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1961 info->buffer = retbuf;
1965 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1966 || bfd_bread (buf, info->size, abfd) != info->size)
1967 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1968 bfd_get_filename (abfd));
1971 /* A helper function that returns the size of a section in a safe way.
1972 If you are positive that the section has been read before using the
1973 size, then it is safe to refer to the dwarf2_section_info object's
1974 "size" field directly. In other cases, you must call this
1975 function, because for compressed sections the size field is not set
1976 correctly until the section has been read. */
1978 static bfd_size_type
1979 dwarf2_section_size (struct objfile *objfile,
1980 struct dwarf2_section_info *info)
1983 dwarf2_read_section (objfile, info);
1987 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1991 dwarf2_get_section_info (struct objfile *objfile,
1992 enum dwarf2_section_enum sect,
1993 asection **sectp, gdb_byte **bufp,
1994 bfd_size_type *sizep)
1996 struct dwarf2_per_objfile *data
1997 = objfile_data (objfile, dwarf2_objfile_data_key);
1998 struct dwarf2_section_info *info;
2000 /* We may see an objfile without any DWARF, in which case we just
2011 case DWARF2_DEBUG_FRAME:
2012 info = &data->frame;
2014 case DWARF2_EH_FRAME:
2015 info = &data->eh_frame;
2018 gdb_assert_not_reached ("unexpected section");
2021 dwarf2_read_section (objfile, info);
2023 *sectp = info->asection;
2024 *bufp = info->buffer;
2025 *sizep = info->size;
2028 /* A helper function to find the sections for a .dwz file. */
2031 locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
2033 struct dwz_file *dwz_file = arg;
2035 /* Note that we only support the standard ELF names, because .dwz
2036 is ELF-only (at the time of writing). */
2037 if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev))
2039 dwz_file->abbrev.asection = sectp;
2040 dwz_file->abbrev.size = bfd_get_section_size (sectp);
2042 else if (section_is_p (sectp->name, &dwarf2_elf_names.info))
2044 dwz_file->info.asection = sectp;
2045 dwz_file->info.size = bfd_get_section_size (sectp);
2047 else if (section_is_p (sectp->name, &dwarf2_elf_names.str))
2049 dwz_file->str.asection = sectp;
2050 dwz_file->str.size = bfd_get_section_size (sectp);
2052 else if (section_is_p (sectp->name, &dwarf2_elf_names.line))
2054 dwz_file->line.asection = sectp;
2055 dwz_file->line.size = bfd_get_section_size (sectp);
2057 else if (section_is_p (sectp->name, &dwarf2_elf_names.macro))
2059 dwz_file->macro.asection = sectp;
2060 dwz_file->macro.size = bfd_get_section_size (sectp);
2062 else if (section_is_p (sectp->name, &dwarf2_elf_names.gdb_index))
2064 dwz_file->gdb_index.asection = sectp;
2065 dwz_file->gdb_index.size = bfd_get_section_size (sectp);
2069 /* Open the separate '.dwz' debug file, if needed. Error if the file
2072 static struct dwz_file *
2073 dwarf2_get_dwz_file (void)
2075 bfd *abfd, *dwz_bfd;
2078 struct cleanup *cleanup;
2079 const char *filename;
2080 struct dwz_file *result;
2082 if (dwarf2_per_objfile->dwz_file != NULL)
2083 return dwarf2_per_objfile->dwz_file;
2085 abfd = dwarf2_per_objfile->objfile->obfd;
2086 section = bfd_get_section_by_name (abfd, ".gnu_debugaltlink");
2087 if (section == NULL)
2088 error (_("could not find '.gnu_debugaltlink' section"));
2089 if (!bfd_malloc_and_get_section (abfd, section, &data))
2090 error (_("could not read '.gnu_debugaltlink' section: %s"),
2091 bfd_errmsg (bfd_get_error ()));
2092 cleanup = make_cleanup (xfree, data);
2095 if (!IS_ABSOLUTE_PATH (filename))
2097 char *abs = gdb_realpath (dwarf2_per_objfile->objfile->name);
2100 make_cleanup (xfree, abs);
2101 abs = ldirname (abs);
2102 make_cleanup (xfree, abs);
2104 rel = concat (abs, SLASH_STRING, filename, (char *) NULL);
2105 make_cleanup (xfree, rel);
2109 /* The format is just a NUL-terminated file name, followed by the
2110 build-id. For now, though, we ignore the build-id. */
2111 dwz_bfd = gdb_bfd_open (filename, gnutarget, -1);
2112 if (dwz_bfd == NULL)
2113 error (_("could not read '%s': %s"), filename,
2114 bfd_errmsg (bfd_get_error ()));
2116 if (!bfd_check_format (dwz_bfd, bfd_object))
2118 gdb_bfd_unref (dwz_bfd);
2119 error (_("file '%s' was not usable: %s"), filename,
2120 bfd_errmsg (bfd_get_error ()));
2123 result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack,
2125 result->dwz_bfd = dwz_bfd;
2127 bfd_map_over_sections (dwz_bfd, locate_dwz_sections, result);
2129 do_cleanups (cleanup);
2131 dwarf2_per_objfile->dwz_file = result;
2135 /* DWARF quick_symbols_functions support. */
2137 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2138 unique line tables, so we maintain a separate table of all .debug_line
2139 derived entries to support the sharing.
2140 All the quick functions need is the list of file names. We discard the
2141 line_header when we're done and don't need to record it here. */
2142 struct quick_file_names
2144 /* The data used to construct the hash key. */
2145 struct stmt_list_hash hash;
2147 /* The number of entries in file_names, real_names. */
2148 unsigned int num_file_names;
2150 /* The file names from the line table, after being run through
2152 const char **file_names;
2154 /* The file names from the line table after being run through
2155 gdb_realpath. These are computed lazily. */
2156 const char **real_names;
2159 /* When using the index (and thus not using psymtabs), each CU has an
2160 object of this type. This is used to hold information needed by
2161 the various "quick" methods. */
2162 struct dwarf2_per_cu_quick_data
2164 /* The file table. This can be NULL if there was no file table
2165 or it's currently not read in.
2166 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2167 struct quick_file_names *file_names;
2169 /* The corresponding symbol table. This is NULL if symbols for this
2170 CU have not yet been read. */
2171 struct symtab *symtab;
2173 /* A temporary mark bit used when iterating over all CUs in
2174 expand_symtabs_matching. */
2175 unsigned int mark : 1;
2177 /* True if we've tried to read the file table and found there isn't one.
2178 There will be no point in trying to read it again next time. */
2179 unsigned int no_file_data : 1;
2182 /* Utility hash function for a stmt_list_hash. */
2185 hash_stmt_list_entry (const struct stmt_list_hash *stmt_list_hash)
2189 if (stmt_list_hash->dwo_unit != NULL)
2190 v += (uintptr_t) stmt_list_hash->dwo_unit->dwo_file;
2191 v += stmt_list_hash->line_offset.sect_off;
2195 /* Utility equality function for a stmt_list_hash. */
2198 eq_stmt_list_entry (const struct stmt_list_hash *lhs,
2199 const struct stmt_list_hash *rhs)
2201 if ((lhs->dwo_unit != NULL) != (rhs->dwo_unit != NULL))
2203 if (lhs->dwo_unit != NULL
2204 && lhs->dwo_unit->dwo_file != rhs->dwo_unit->dwo_file)
2207 return lhs->line_offset.sect_off == rhs->line_offset.sect_off;
2210 /* Hash function for a quick_file_names. */
2213 hash_file_name_entry (const void *e)
2215 const struct quick_file_names *file_data = e;
2217 return hash_stmt_list_entry (&file_data->hash);
2220 /* Equality function for a quick_file_names. */
2223 eq_file_name_entry (const void *a, const void *b)
2225 const struct quick_file_names *ea = a;
2226 const struct quick_file_names *eb = b;
2228 return eq_stmt_list_entry (&ea->hash, &eb->hash);
2231 /* Delete function for a quick_file_names. */
2234 delete_file_name_entry (void *e)
2236 struct quick_file_names *file_data = e;
2239 for (i = 0; i < file_data->num_file_names; ++i)
2241 xfree ((void*) file_data->file_names[i]);
2242 if (file_data->real_names)
2243 xfree ((void*) file_data->real_names[i]);
2246 /* The space for the struct itself lives on objfile_obstack,
2247 so we don't free it here. */
2250 /* Create a quick_file_names hash table. */
2253 create_quick_file_names_table (unsigned int nr_initial_entries)
2255 return htab_create_alloc (nr_initial_entries,
2256 hash_file_name_entry, eq_file_name_entry,
2257 delete_file_name_entry, xcalloc, xfree);
2260 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2261 have to be created afterwards. You should call age_cached_comp_units after
2262 processing PER_CU->CU. dw2_setup must have been already called. */
2265 load_cu (struct dwarf2_per_cu_data *per_cu)
2267 if (per_cu->is_debug_types)
2268 load_full_type_unit (per_cu);
2270 load_full_comp_unit (per_cu, language_minimal);
2272 gdb_assert (per_cu->cu != NULL);
2274 dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
2277 /* Read in the symbols for PER_CU. */
2280 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
2282 struct cleanup *back_to;
2284 /* Skip type_unit_groups, reading the type units they contain
2285 is handled elsewhere. */
2286 if (IS_TYPE_UNIT_GROUP (per_cu))
2289 back_to = make_cleanup (dwarf2_release_queue, NULL);
2291 if (dwarf2_per_objfile->using_index
2292 ? per_cu->v.quick->symtab == NULL
2293 : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin))
2295 queue_comp_unit (per_cu, language_minimal);
2301 /* Age the cache, releasing compilation units that have not
2302 been used recently. */
2303 age_cached_comp_units ();
2305 do_cleanups (back_to);
2308 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2309 the objfile from which this CU came. Returns the resulting symbol
2312 static struct symtab *
2313 dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
2315 gdb_assert (dwarf2_per_objfile->using_index);
2316 if (!per_cu->v.quick->symtab)
2318 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
2319 increment_reading_symtab ();
2320 dw2_do_instantiate_symtab (per_cu);
2321 process_cu_includes ();
2322 do_cleanups (back_to);
2324 return per_cu->v.quick->symtab;
2327 /* Return the CU given its index.
2329 This is intended for loops like:
2331 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2332 + dwarf2_per_objfile->n_type_units); ++i)
2334 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2340 static struct dwarf2_per_cu_data *
2341 dw2_get_cu (int index)
2343 if (index >= dwarf2_per_objfile->n_comp_units)
2345 index -= dwarf2_per_objfile->n_comp_units;
2346 gdb_assert (index < dwarf2_per_objfile->n_type_units);
2347 return &dwarf2_per_objfile->all_type_units[index]->per_cu;
2350 return dwarf2_per_objfile->all_comp_units[index];
2353 /* Return the primary CU given its index.
2354 The difference between this function and dw2_get_cu is in the handling
2355 of type units (TUs). Here we return the type_unit_group object.
2357 This is intended for loops like:
2359 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2360 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2362 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2368 static struct dwarf2_per_cu_data *
2369 dw2_get_primary_cu (int index)
2371 if (index >= dwarf2_per_objfile->n_comp_units)
2373 index -= dwarf2_per_objfile->n_comp_units;
2374 gdb_assert (index < dwarf2_per_objfile->n_type_unit_groups);
2375 return &dwarf2_per_objfile->all_type_unit_groups[index]->per_cu;
2378 return dwarf2_per_objfile->all_comp_units[index];
2381 /* A helper for create_cus_from_index that handles a given list of
2385 create_cus_from_index_list (struct objfile *objfile,
2386 const gdb_byte *cu_list, offset_type n_elements,
2387 struct dwarf2_section_info *section,
2393 for (i = 0; i < n_elements; i += 2)
2395 struct dwarf2_per_cu_data *the_cu;
2396 ULONGEST offset, length;
2398 gdb_static_assert (sizeof (ULONGEST) >= 8);
2399 offset = extract_unsigned_integer (cu_list, 8, BFD_ENDIAN_LITTLE);
2400 length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE);
2403 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2404 struct dwarf2_per_cu_data);
2405 the_cu->offset.sect_off = offset;
2406 the_cu->length = length;
2407 the_cu->objfile = objfile;
2408 the_cu->section = section;
2409 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2410 struct dwarf2_per_cu_quick_data);
2411 the_cu->is_dwz = is_dwz;
2412 dwarf2_per_objfile->all_comp_units[base_offset + i / 2] = the_cu;
2416 /* Read the CU list from the mapped index, and use it to create all
2417 the CU objects for this objfile. */
2420 create_cus_from_index (struct objfile *objfile,
2421 const gdb_byte *cu_list, offset_type cu_list_elements,
2422 const gdb_byte *dwz_list, offset_type dwz_elements)
2424 struct dwz_file *dwz;
2426 dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2;
2427 dwarf2_per_objfile->all_comp_units
2428 = obstack_alloc (&objfile->objfile_obstack,
2429 dwarf2_per_objfile->n_comp_units
2430 * sizeof (struct dwarf2_per_cu_data *));
2432 create_cus_from_index_list (objfile, cu_list, cu_list_elements,
2433 &dwarf2_per_objfile->info, 0, 0);
2435 if (dwz_elements == 0)
2438 dwz = dwarf2_get_dwz_file ();
2439 create_cus_from_index_list (objfile, dwz_list, dwz_elements, &dwz->info, 1,
2440 cu_list_elements / 2);
2443 /* Create the signatured type hash table from the index. */
2446 create_signatured_type_table_from_index (struct objfile *objfile,
2447 struct dwarf2_section_info *section,
2448 const gdb_byte *bytes,
2449 offset_type elements)
2452 htab_t sig_types_hash;
2454 dwarf2_per_objfile->n_type_units = elements / 3;
2455 dwarf2_per_objfile->all_type_units
2456 = obstack_alloc (&objfile->objfile_obstack,
2457 dwarf2_per_objfile->n_type_units
2458 * sizeof (struct signatured_type *));
2460 sig_types_hash = allocate_signatured_type_table (objfile);
2462 for (i = 0; i < elements; i += 3)
2464 struct signatured_type *sig_type;
2465 ULONGEST offset, type_offset_in_tu, signature;
2468 gdb_static_assert (sizeof (ULONGEST) >= 8);
2469 offset = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
2470 type_offset_in_tu = extract_unsigned_integer (bytes + 8, 8,
2472 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
2475 sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2476 struct signatured_type);
2477 sig_type->signature = signature;
2478 sig_type->type_offset_in_tu.cu_off = type_offset_in_tu;
2479 sig_type->per_cu.is_debug_types = 1;
2480 sig_type->per_cu.section = section;
2481 sig_type->per_cu.offset.sect_off = offset;
2482 sig_type->per_cu.objfile = objfile;
2483 sig_type->per_cu.v.quick
2484 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2485 struct dwarf2_per_cu_quick_data);
2487 slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
2490 dwarf2_per_objfile->all_type_units[i / 3] = sig_type;
2493 dwarf2_per_objfile->signatured_types = sig_types_hash;
2496 /* Read the address map data from the mapped index, and use it to
2497 populate the objfile's psymtabs_addrmap. */
2500 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
2502 const gdb_byte *iter, *end;
2503 struct obstack temp_obstack;
2504 struct addrmap *mutable_map;
2505 struct cleanup *cleanup;
2508 obstack_init (&temp_obstack);
2509 cleanup = make_cleanup_obstack_free (&temp_obstack);
2510 mutable_map = addrmap_create_mutable (&temp_obstack);
2512 iter = index->address_table;
2513 end = iter + index->address_table_size;
2515 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2519 ULONGEST hi, lo, cu_index;
2520 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2522 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2524 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
2527 if (cu_index < dwarf2_per_objfile->n_comp_units)
2529 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
2530 dw2_get_cu (cu_index));
2534 complaint (&symfile_complaints,
2535 _(".gdb_index address table has invalid CU number %u"),
2536 (unsigned) cu_index);
2540 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
2541 &objfile->objfile_obstack);
2542 do_cleanups (cleanup);
2545 /* The hash function for strings in the mapped index. This is the same as
2546 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2547 implementation. This is necessary because the hash function is tied to the
2548 format of the mapped index file. The hash values do not have to match with
2551 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2554 mapped_index_string_hash (int index_version, const void *p)
2556 const unsigned char *str = (const unsigned char *) p;
2560 while ((c = *str++) != 0)
2562 if (index_version >= 5)
2564 r = r * 67 + c - 113;
2570 /* Find a slot in the mapped index INDEX for the object named NAME.
2571 If NAME is found, set *VEC_OUT to point to the CU vector in the
2572 constant pool and return 1. If NAME cannot be found, return 0. */
2575 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2576 offset_type **vec_out)
2578 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2580 offset_type slot, step;
2581 int (*cmp) (const char *, const char *);
2583 if (current_language->la_language == language_cplus
2584 || current_language->la_language == language_java
2585 || current_language->la_language == language_fortran)
2587 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2589 const char *paren = strchr (name, '(');
2595 dup = xmalloc (paren - name + 1);
2596 memcpy (dup, name, paren - name);
2597 dup[paren - name] = 0;
2599 make_cleanup (xfree, dup);
2604 /* Index version 4 did not support case insensitive searches. But the
2605 indices for case insensitive languages are built in lowercase, therefore
2606 simulate our NAME being searched is also lowercased. */
2607 hash = mapped_index_string_hash ((index->version == 4
2608 && case_sensitivity == case_sensitive_off
2609 ? 5 : index->version),
2612 slot = hash & (index->symbol_table_slots - 1);
2613 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2614 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2618 /* Convert a slot number to an offset into the table. */
2619 offset_type i = 2 * slot;
2621 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2623 do_cleanups (back_to);
2627 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2628 if (!cmp (name, str))
2630 *vec_out = (offset_type *) (index->constant_pool
2631 + MAYBE_SWAP (index->symbol_table[i + 1]));
2632 do_cleanups (back_to);
2636 slot = (slot + step) & (index->symbol_table_slots - 1);
2640 /* A helper function that reads the .gdb_index from SECTION and fills
2641 in MAP. FILENAME is the name of the file containing the section;
2642 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2643 ok to use deprecated sections.
2645 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2646 out parameters that are filled in with information about the CU and
2647 TU lists in the section.
2649 Returns 1 if all went well, 0 otherwise. */
2652 read_index_from_section (struct objfile *objfile,
2653 const char *filename,
2655 struct dwarf2_section_info *section,
2656 struct mapped_index *map,
2657 const gdb_byte **cu_list,
2658 offset_type *cu_list_elements,
2659 const gdb_byte **types_list,
2660 offset_type *types_list_elements)
2663 offset_type version;
2664 offset_type *metadata;
2667 if (dwarf2_section_empty_p (section))
2670 /* Older elfutils strip versions could keep the section in the main
2671 executable while splitting it for the separate debug info file. */
2672 if ((bfd_get_file_flags (section->asection) & SEC_HAS_CONTENTS) == 0)
2675 dwarf2_read_section (objfile, section);
2677 addr = section->buffer;
2678 /* Version check. */
2679 version = MAYBE_SWAP (*(offset_type *) addr);
2680 /* Versions earlier than 3 emitted every copy of a psymbol. This
2681 causes the index to behave very poorly for certain requests. Version 3
2682 contained incomplete addrmap. So, it seems better to just ignore such
2686 static int warning_printed = 0;
2687 if (!warning_printed)
2689 warning (_("Skipping obsolete .gdb_index section in %s."),
2691 warning_printed = 1;
2695 /* Index version 4 uses a different hash function than index version
2698 Versions earlier than 6 did not emit psymbols for inlined
2699 functions. Using these files will cause GDB not to be able to
2700 set breakpoints on inlined functions by name, so we ignore these
2701 indices unless the user has done
2702 "set use-deprecated-index-sections on". */
2703 if (version < 6 && !deprecated_ok)
2705 static int warning_printed = 0;
2706 if (!warning_printed)
2709 Skipping deprecated .gdb_index section in %s.\n\
2710 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2711 to use the section anyway."),
2713 warning_printed = 1;
2717 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2718 of the TU (for symbols coming from TUs). It's just a performance bug, and
2719 we can't distinguish gdb-generated indices from gold-generated ones, so
2720 nothing to do here. */
2722 /* Indexes with higher version than the one supported by GDB may be no
2723 longer backward compatible. */
2727 map->version = version;
2728 map->total_size = section->size;
2730 metadata = (offset_type *) (addr + sizeof (offset_type));
2733 *cu_list = addr + MAYBE_SWAP (metadata[i]);
2734 *cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2738 *types_list = addr + MAYBE_SWAP (metadata[i]);
2739 *types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2740 - MAYBE_SWAP (metadata[i]))
2744 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2745 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2746 - MAYBE_SWAP (metadata[i]));
2749 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2750 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2751 - MAYBE_SWAP (metadata[i]))
2752 / (2 * sizeof (offset_type)));
2755 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2761 /* Read the index file. If everything went ok, initialize the "quick"
2762 elements of all the CUs and return 1. Otherwise, return 0. */
2765 dwarf2_read_index (struct objfile *objfile)
2767 struct mapped_index local_map, *map;
2768 const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
2769 offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
2771 if (!read_index_from_section (objfile, objfile->name,
2772 use_deprecated_index_sections,
2773 &dwarf2_per_objfile->gdb_index, &local_map,
2774 &cu_list, &cu_list_elements,
2775 &types_list, &types_list_elements))
2778 /* Don't use the index if it's empty. */
2779 if (local_map.symbol_table_slots == 0)
2782 /* If there is a .dwz file, read it so we can get its CU list as
2784 if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
2786 struct dwz_file *dwz = dwarf2_get_dwz_file ();
2787 struct mapped_index dwz_map;
2788 const gdb_byte *dwz_types_ignore;
2789 offset_type dwz_types_elements_ignore;
2791 if (!read_index_from_section (objfile, bfd_get_filename (dwz->dwz_bfd),
2793 &dwz->gdb_index, &dwz_map,
2794 &dwz_list, &dwz_list_elements,
2796 &dwz_types_elements_ignore))
2798 warning (_("could not read '.gdb_index' section from %s; skipping"),
2799 bfd_get_filename (dwz->dwz_bfd));
2804 create_cus_from_index (objfile, cu_list, cu_list_elements, dwz_list,
2807 if (types_list_elements)
2809 struct dwarf2_section_info *section;
2811 /* We can only handle a single .debug_types when we have an
2813 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
2816 section = VEC_index (dwarf2_section_info_def,
2817 dwarf2_per_objfile->types, 0);
2819 create_signatured_type_table_from_index (objfile, section, types_list,
2820 types_list_elements);
2823 create_addrmap_from_index (objfile, &local_map);
2825 map = obstack_alloc (&objfile->objfile_obstack, sizeof (struct mapped_index));
2828 dwarf2_per_objfile->index_table = map;
2829 dwarf2_per_objfile->using_index = 1;
2830 dwarf2_per_objfile->quick_file_names_table =
2831 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2836 /* A helper for the "quick" functions which sets the global
2837 dwarf2_per_objfile according to OBJFILE. */
2840 dw2_setup (struct objfile *objfile)
2842 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2843 gdb_assert (dwarf2_per_objfile);
2846 /* die_reader_func for dw2_get_file_names. */
2849 dw2_get_file_names_reader (const struct die_reader_specs *reader,
2851 struct die_info *comp_unit_die,
2855 struct dwarf2_cu *cu = reader->cu;
2856 struct dwarf2_per_cu_data *this_cu = cu->per_cu;
2857 struct objfile *objfile = dwarf2_per_objfile->objfile;
2858 struct dwarf2_per_cu_data *lh_cu;
2859 struct line_header *lh;
2860 struct attribute *attr;
2862 const char *name, *comp_dir;
2864 struct quick_file_names *qfn;
2865 unsigned int line_offset;
2867 gdb_assert (! this_cu->is_debug_types);
2869 /* Our callers never want to match partial units -- instead they
2870 will match the enclosing full CU. */
2871 if (comp_unit_die->tag == DW_TAG_partial_unit)
2873 this_cu->v.quick->no_file_data = 1;
2882 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu);
2885 struct quick_file_names find_entry;
2887 line_offset = DW_UNSND (attr);
2889 /* We may have already read in this line header (TU line header sharing).
2890 If we have we're done. */
2891 find_entry.hash.dwo_unit = cu->dwo_unit;
2892 find_entry.hash.line_offset.sect_off = line_offset;
2893 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2894 &find_entry, INSERT);
2897 lh_cu->v.quick->file_names = *slot;
2901 lh = dwarf_decode_line_header (line_offset, cu);
2905 lh_cu->v.quick->no_file_data = 1;
2909 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2910 qfn->hash.dwo_unit = cu->dwo_unit;
2911 qfn->hash.line_offset.sect_off = line_offset;
2912 gdb_assert (slot != NULL);
2915 find_file_and_directory (comp_unit_die, cu, &name, &comp_dir);
2917 qfn->num_file_names = lh->num_file_names;
2918 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2919 lh->num_file_names * sizeof (char *));
2920 for (i = 0; i < lh->num_file_names; ++i)
2921 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2922 qfn->real_names = NULL;
2924 free_line_header (lh);
2926 lh_cu->v.quick->file_names = qfn;
2929 /* A helper for the "quick" functions which attempts to read the line
2930 table for THIS_CU. */
2932 static struct quick_file_names *
2933 dw2_get_file_names (struct dwarf2_per_cu_data *this_cu)
2935 /* This should never be called for TUs. */
2936 gdb_assert (! this_cu->is_debug_types);
2937 /* Nor type unit groups. */
2938 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu));
2940 if (this_cu->v.quick->file_names != NULL)
2941 return this_cu->v.quick->file_names;
2942 /* If we know there is no line data, no point in looking again. */
2943 if (this_cu->v.quick->no_file_data)
2946 init_cutu_and_read_dies_simple (this_cu, dw2_get_file_names_reader, NULL);
2948 if (this_cu->v.quick->no_file_data)
2950 return this_cu->v.quick->file_names;
2953 /* A helper for the "quick" functions which computes and caches the
2954 real path for a given file name from the line table. */
2957 dw2_get_real_path (struct objfile *objfile,
2958 struct quick_file_names *qfn, int index)
2960 if (qfn->real_names == NULL)
2961 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2962 qfn->num_file_names, sizeof (char *));
2964 if (qfn->real_names[index] == NULL)
2965 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2967 return qfn->real_names[index];
2970 static struct symtab *
2971 dw2_find_last_source_symtab (struct objfile *objfile)
2975 dw2_setup (objfile);
2976 index = dwarf2_per_objfile->n_comp_units - 1;
2977 return dw2_instantiate_symtab (dw2_get_cu (index));
2980 /* Traversal function for dw2_forget_cached_source_info. */
2983 dw2_free_cached_file_names (void **slot, void *info)
2985 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
2987 if (file_data->real_names)
2991 for (i = 0; i < file_data->num_file_names; ++i)
2993 xfree ((void*) file_data->real_names[i]);
2994 file_data->real_names[i] = NULL;
3002 dw2_forget_cached_source_info (struct objfile *objfile)
3004 dw2_setup (objfile);
3006 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
3007 dw2_free_cached_file_names, NULL);
3010 /* Helper function for dw2_map_symtabs_matching_filename that expands
3011 the symtabs and calls the iterator. */
3014 dw2_map_expand_apply (struct objfile *objfile,
3015 struct dwarf2_per_cu_data *per_cu,
3016 const char *name, const char *real_path,
3017 int (*callback) (struct symtab *, void *),
3020 struct symtab *last_made = objfile->symtabs;
3022 /* Don't visit already-expanded CUs. */
3023 if (per_cu->v.quick->symtab)
3026 /* This may expand more than one symtab, and we want to iterate over
3028 dw2_instantiate_symtab (per_cu);
3030 return iterate_over_some_symtabs (name, real_path, callback, data,
3031 objfile->symtabs, last_made);
3034 /* Implementation of the map_symtabs_matching_filename method. */
3037 dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
3038 const char *real_path,
3039 int (*callback) (struct symtab *, void *),
3043 const char *name_basename = lbasename (name);
3045 dw2_setup (objfile);
3047 /* The rule is CUs specify all the files, including those used by
3048 any TU, so there's no need to scan TUs here. */
3050 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3053 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
3054 struct quick_file_names *file_data;
3056 /* We only need to look at symtabs not already expanded. */
3057 if (per_cu->v.quick->symtab)
3060 file_data = dw2_get_file_names (per_cu);
3061 if (file_data == NULL)
3064 for (j = 0; j < file_data->num_file_names; ++j)
3066 const char *this_name = file_data->file_names[j];
3067 const char *this_real_name;
3069 if (compare_filenames_for_search (this_name, name))
3071 if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
3077 /* Before we invoke realpath, which can get expensive when many
3078 files are involved, do a quick comparison of the basenames. */
3079 if (! basenames_may_differ
3080 && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
3083 this_real_name = dw2_get_real_path (objfile, file_data, j);
3084 if (compare_filenames_for_search (this_real_name, name))
3086 if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
3092 if (real_path != NULL)
3094 gdb_assert (IS_ABSOLUTE_PATH (real_path));
3095 gdb_assert (IS_ABSOLUTE_PATH (name));
3096 if (this_real_name != NULL
3097 && FILENAME_CMP (real_path, this_real_name) == 0)
3099 if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
3111 /* Struct used to manage iterating over all CUs looking for a symbol. */
3113 struct dw2_symtab_iterator
3115 /* The internalized form of .gdb_index. */
3116 struct mapped_index *index;
3117 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3118 int want_specific_block;
3119 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3120 Unused if !WANT_SPECIFIC_BLOCK. */
3122 /* The kind of symbol we're looking for. */
3124 /* The list of CUs from the index entry of the symbol,
3125 or NULL if not found. */
3127 /* The next element in VEC to look at. */
3129 /* The number of elements in VEC, or zero if there is no match. */
3133 /* Initialize the index symtab iterator ITER.
3134 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3135 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3138 dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
3139 struct mapped_index *index,
3140 int want_specific_block,
3145 iter->index = index;
3146 iter->want_specific_block = want_specific_block;
3147 iter->block_index = block_index;
3148 iter->domain = domain;
3151 if (find_slot_in_mapped_hash (index, name, &iter->vec))
3152 iter->length = MAYBE_SWAP (*iter->vec);
3160 /* Return the next matching CU or NULL if there are no more. */
3162 static struct dwarf2_per_cu_data *
3163 dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
3165 for ( ; iter->next < iter->length; ++iter->next)
3167 offset_type cu_index_and_attrs =
3168 MAYBE_SWAP (iter->vec[iter->next + 1]);
3169 offset_type cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs);
3170 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
3171 int want_static = iter->block_index != GLOBAL_BLOCK;
3172 /* This value is only valid for index versions >= 7. */
3173 int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs);
3174 gdb_index_symbol_kind symbol_kind =
3175 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs);
3176 /* Only check the symbol attributes if they're present.
3177 Indices prior to version 7 don't record them,
3178 and indices >= 7 may elide them for certain symbols
3179 (gold does this). */
3181 (iter->index->version >= 7
3182 && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
3184 /* Skip if already read in. */
3185 if (per_cu->v.quick->symtab)
3189 && iter->want_specific_block
3190 && want_static != is_static)
3193 /* Only check the symbol's kind if it has one. */
3196 switch (iter->domain)
3199 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE
3200 && symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION
3201 /* Some types are also in VAR_DOMAIN. */
3202 && symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3206 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3210 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
3225 static struct symtab *
3226 dw2_lookup_symbol (struct objfile *objfile, int block_index,
3227 const char *name, domain_enum domain)
3229 struct symtab *stab_best = NULL;
3230 struct mapped_index *index;
3232 dw2_setup (objfile);
3234 index = dwarf2_per_objfile->index_table;
3236 /* index is NULL if OBJF_READNOW. */
3239 struct dw2_symtab_iterator iter;
3240 struct dwarf2_per_cu_data *per_cu;
3242 dw2_symtab_iter_init (&iter, index, 1, block_index, domain, name);
3244 while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
3246 struct symbol *sym = NULL;
3247 struct symtab *stab = dw2_instantiate_symtab (per_cu);
3249 /* Some caution must be observed with overloaded functions
3250 and methods, since the index will not contain any overload
3251 information (but NAME might contain it). */
3254 struct blockvector *bv = BLOCKVECTOR (stab);
3255 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
3257 sym = lookup_block_symbol (block, name, domain);
3260 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
3262 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
3268 /* Keep looking through other CUs. */
3276 dw2_print_stats (struct objfile *objfile)
3278 int i, total, count;
3280 dw2_setup (objfile);
3281 total = dwarf2_per_objfile->n_comp_units + dwarf2_per_objfile->n_type_units;
3283 for (i = 0; i < total; ++i)
3285 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3287 if (!per_cu->v.quick->symtab)
3290 printf_filtered (_(" Number of read CUs: %d\n"), total - count);
3291 printf_filtered (_(" Number of unread CUs: %d\n"), count);
3295 dw2_dump (struct objfile *objfile)
3297 /* Nothing worth printing. */
3301 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
3302 struct section_offsets *delta)
3304 /* There's nothing to relocate here. */
3308 dw2_expand_symtabs_for_function (struct objfile *objfile,
3309 const char *func_name)
3311 struct mapped_index *index;
3313 dw2_setup (objfile);
3315 index = dwarf2_per_objfile->index_table;
3317 /* index is NULL if OBJF_READNOW. */
3320 struct dw2_symtab_iterator iter;
3321 struct dwarf2_per_cu_data *per_cu;
3323 /* Note: It doesn't matter what we pass for block_index here. */
3324 dw2_symtab_iter_init (&iter, index, 0, GLOBAL_BLOCK, VAR_DOMAIN,
3327 while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
3328 dw2_instantiate_symtab (per_cu);
3333 dw2_expand_all_symtabs (struct objfile *objfile)
3337 dw2_setup (objfile);
3339 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3340 + dwarf2_per_objfile->n_type_units); ++i)
3342 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3344 dw2_instantiate_symtab (per_cu);
3349 dw2_expand_symtabs_with_fullname (struct objfile *objfile,
3350 const char *fullname)
3354 dw2_setup (objfile);
3356 /* We don't need to consider type units here.
3357 This is only called for examining code, e.g. expand_line_sal.
3358 There can be an order of magnitude (or more) more type units
3359 than comp units, and we avoid them if we can. */
3361 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3364 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3365 struct quick_file_names *file_data;
3367 /* We only need to look at symtabs not already expanded. */
3368 if (per_cu->v.quick->symtab)
3371 file_data = dw2_get_file_names (per_cu);
3372 if (file_data == NULL)
3375 for (j = 0; j < file_data->num_file_names; ++j)
3377 const char *this_fullname = file_data->file_names[j];
3379 if (filename_cmp (this_fullname, fullname) == 0)
3381 dw2_instantiate_symtab (per_cu);
3388 /* A helper function for dw2_find_symbol_file that finds the primary
3389 file name for a given CU. This is a die_reader_func. */
3392 dw2_get_primary_filename_reader (const struct die_reader_specs *reader,
3394 struct die_info *comp_unit_die,
3398 const char **result_ptr = data;
3399 struct dwarf2_cu *cu = reader->cu;
3400 struct attribute *attr;
3402 attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu);
3406 *result_ptr = DW_STRING (attr);
3410 dw2_find_symbol_file (struct objfile *objfile, const char *name)
3412 struct dwarf2_per_cu_data *per_cu;
3414 const char *filename;
3416 dw2_setup (objfile);
3418 /* index_table is NULL if OBJF_READNOW. */
3419 if (!dwarf2_per_objfile->index_table)
3423 ALL_OBJFILE_PRIMARY_SYMTABS (objfile, s)
3425 struct blockvector *bv = BLOCKVECTOR (s);
3426 const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
3427 struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
3431 /* Only file extension of returned filename is recognized. */
3432 return SYMBOL_SYMTAB (sym)->filename;
3438 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
3442 /* Note that this just looks at the very first one named NAME -- but
3443 actually we are looking for a function. find_main_filename
3444 should be rewritten so that it doesn't require a custom hook. It
3445 could just use the ordinary symbol tables. */
3446 /* vec[0] is the length, which must always be >0. */
3447 per_cu = dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec[1])));
3449 if (per_cu->v.quick->symtab != NULL)
3451 /* Only file extension of returned filename is recognized. */
3452 return per_cu->v.quick->symtab->filename;
3455 init_cutu_and_read_dies (per_cu, NULL, 0, 0,
3456 dw2_get_primary_filename_reader, &filename);
3458 /* Only file extension of returned filename is recognized. */
3463 dw2_map_matching_symbols (const char * name, domain_enum namespace,
3464 struct objfile *objfile, int global,
3465 int (*callback) (struct block *,
3466 struct symbol *, void *),
3467 void *data, symbol_compare_ftype *match,
3468 symbol_compare_ftype *ordered_compare)
3470 /* Currently unimplemented; used for Ada. The function can be called if the
3471 current language is Ada for a non-Ada objfile using GNU index. As Ada
3472 does not look for non-Ada symbols this function should just return. */
3476 dw2_expand_symtabs_matching
3477 (struct objfile *objfile,
3478 int (*file_matcher) (const char *, void *, int basenames),
3479 int (*name_matcher) (const char *, void *),
3480 enum search_domain kind,
3485 struct mapped_index *index;
3487 dw2_setup (objfile);
3489 /* index_table is NULL if OBJF_READNOW. */
3490 if (!dwarf2_per_objfile->index_table)
3492 index = dwarf2_per_objfile->index_table;
3494 if (file_matcher != NULL)
3496 struct cleanup *cleanup;
3497 htab_t visited_found, visited_not_found;
3499 visited_found = htab_create_alloc (10,
3500 htab_hash_pointer, htab_eq_pointer,
3501 NULL, xcalloc, xfree);
3502 cleanup = make_cleanup_htab_delete (visited_found);
3503 visited_not_found = htab_create_alloc (10,
3504 htab_hash_pointer, htab_eq_pointer,
3505 NULL, xcalloc, xfree);
3506 make_cleanup_htab_delete (visited_not_found);
3508 /* The rule is CUs specify all the files, including those used by
3509 any TU, so there's no need to scan TUs here. */
3511 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3514 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
3515 struct quick_file_names *file_data;
3518 per_cu->v.quick->mark = 0;
3520 /* We only need to look at symtabs not already expanded. */
3521 if (per_cu->v.quick->symtab)
3524 file_data = dw2_get_file_names (per_cu);
3525 if (file_data == NULL)
3528 if (htab_find (visited_not_found, file_data) != NULL)
3530 else if (htab_find (visited_found, file_data) != NULL)
3532 per_cu->v.quick->mark = 1;
3536 for (j = 0; j < file_data->num_file_names; ++j)
3538 const char *this_real_name;
3540 if (file_matcher (file_data->file_names[j], data, 0))
3542 per_cu->v.quick->mark = 1;
3546 /* Before we invoke realpath, which can get expensive when many
3547 files are involved, do a quick comparison of the basenames. */
3548 if (!basenames_may_differ
3549 && !file_matcher (lbasename (file_data->file_names[j]),
3553 this_real_name = dw2_get_real_path (objfile, file_data, j);
3554 if (file_matcher (this_real_name, data, 0))
3556 per_cu->v.quick->mark = 1;
3561 slot = htab_find_slot (per_cu->v.quick->mark
3563 : visited_not_found,
3568 do_cleanups (cleanup);
3571 for (iter = 0; iter < index->symbol_table_slots; ++iter)
3573 offset_type idx = 2 * iter;
3575 offset_type *vec, vec_len, vec_idx;
3577 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
3580 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
3582 if (! (*name_matcher) (name, data))
3585 /* The name was matched, now expand corresponding CUs that were
3587 vec = (offset_type *) (index->constant_pool
3588 + MAYBE_SWAP (index->symbol_table[idx + 1]));
3589 vec_len = MAYBE_SWAP (vec[0]);
3590 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
3592 struct dwarf2_per_cu_data *per_cu;
3593 offset_type cu_index_and_attrs = MAYBE_SWAP (vec[vec_idx + 1]);
3594 gdb_index_symbol_kind symbol_kind =
3595 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs);
3596 int cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs);
3598 /* Don't crash on bad data. */
3599 if (cu_index >= (dwarf2_per_objfile->n_comp_units
3600 + dwarf2_per_objfile->n_type_units))
3603 /* Only check the symbol's kind if it has one.
3604 Indices prior to version 7 don't record it. */
3605 if (index->version >= 7)
3609 case VARIABLES_DOMAIN:
3610 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE)
3613 case FUNCTIONS_DOMAIN:
3614 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION)
3618 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3626 per_cu = dw2_get_cu (cu_index);
3627 if (file_matcher == NULL || per_cu->v.quick->mark)
3628 dw2_instantiate_symtab (per_cu);
3633 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3636 static struct symtab *
3637 recursively_find_pc_sect_symtab (struct symtab *symtab, CORE_ADDR pc)
3641 if (BLOCKVECTOR (symtab) != NULL
3642 && blockvector_contains_pc (BLOCKVECTOR (symtab), pc))
3645 if (symtab->includes == NULL)
3648 for (i = 0; symtab->includes[i]; ++i)
3650 struct symtab *s = symtab->includes[i];
3652 s = recursively_find_pc_sect_symtab (s, pc);
3660 static struct symtab *
3661 dw2_find_pc_sect_symtab (struct objfile *objfile,
3662 struct minimal_symbol *msymbol,
3664 struct obj_section *section,
3667 struct dwarf2_per_cu_data *data;
3668 struct symtab *result;
3670 dw2_setup (objfile);
3672 if (!objfile->psymtabs_addrmap)
3675 data = addrmap_find (objfile->psymtabs_addrmap, pc);
3679 if (warn_if_readin && data->v.quick->symtab)
3680 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3681 paddress (get_objfile_arch (objfile), pc));
3683 result = recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data), pc);
3684 gdb_assert (result != NULL);
3689 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
3690 void *data, int need_fullname)
3693 struct cleanup *cleanup;
3694 htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
3695 NULL, xcalloc, xfree);
3697 cleanup = make_cleanup_htab_delete (visited);
3698 dw2_setup (objfile);
3700 /* The rule is CUs specify all the files, including those used by
3701 any TU, so there's no need to scan TUs here.
3702 We can ignore file names coming from already-expanded CUs. */
3704 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3706 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3708 if (per_cu->v.quick->symtab)
3710 void **slot = htab_find_slot (visited, per_cu->v.quick->file_names,
3713 *slot = per_cu->v.quick->file_names;
3717 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3720 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
3721 struct quick_file_names *file_data;
3724 /* We only need to look at symtabs not already expanded. */
3725 if (per_cu->v.quick->symtab)
3728 file_data = dw2_get_file_names (per_cu);
3729 if (file_data == NULL)
3732 slot = htab_find_slot (visited, file_data, INSERT);
3735 /* Already visited. */
3740 for (j = 0; j < file_data->num_file_names; ++j)
3742 const char *this_real_name;
3745 this_real_name = dw2_get_real_path (objfile, file_data, j);
3747 this_real_name = NULL;
3748 (*fun) (file_data->file_names[j], this_real_name, data);
3752 do_cleanups (cleanup);
3756 dw2_has_symbols (struct objfile *objfile)
3761 const struct quick_symbol_functions dwarf2_gdb_index_functions =
3764 dw2_find_last_source_symtab,
3765 dw2_forget_cached_source_info,
3766 dw2_map_symtabs_matching_filename,
3771 dw2_expand_symtabs_for_function,
3772 dw2_expand_all_symtabs,
3773 dw2_expand_symtabs_with_fullname,
3774 dw2_find_symbol_file,
3775 dw2_map_matching_symbols,
3776 dw2_expand_symtabs_matching,
3777 dw2_find_pc_sect_symtab,
3778 dw2_map_symbol_filenames
3781 /* Initialize for reading DWARF for this objfile. Return 0 if this
3782 file will use psymtabs, or 1 if using the GNU index. */
3785 dwarf2_initialize_objfile (struct objfile *objfile)
3787 /* If we're about to read full symbols, don't bother with the
3788 indices. In this case we also don't care if some other debug
3789 format is making psymtabs, because they are all about to be
3791 if ((objfile->flags & OBJF_READNOW))
3795 dwarf2_per_objfile->using_index = 1;
3796 create_all_comp_units (objfile);
3797 create_all_type_units (objfile);
3798 dwarf2_per_objfile->quick_file_names_table =
3799 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
3801 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3802 + dwarf2_per_objfile->n_type_units); ++i)
3804 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3806 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
3807 struct dwarf2_per_cu_quick_data);
3810 /* Return 1 so that gdb sees the "quick" functions. However,
3811 these functions will be no-ops because we will have expanded
3816 if (dwarf2_read_index (objfile))
3824 /* Build a partial symbol table. */
3827 dwarf2_build_psymtabs (struct objfile *objfile)
3829 volatile struct gdb_exception except;
3831 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
3833 init_psymbol_list (objfile, 1024);
3836 TRY_CATCH (except, RETURN_MASK_ERROR)
3838 /* This isn't really ideal: all the data we allocate on the
3839 objfile's obstack is still uselessly kept around. However,
3840 freeing it seems unsafe. */
3841 struct cleanup *cleanups = make_cleanup_discard_psymtabs (objfile);
3843 dwarf2_build_psymtabs_hard (objfile);
3844 discard_cleanups (cleanups);
3846 if (except.reason < 0)
3847 exception_print (gdb_stderr, except);
3850 /* Return the total length of the CU described by HEADER. */
3853 get_cu_length (const struct comp_unit_head *header)
3855 return header->initial_length_size + header->length;
3858 /* Return TRUE if OFFSET is within CU_HEADER. */
3861 offset_in_cu_p (const struct comp_unit_head *cu_header, sect_offset offset)
3863 sect_offset bottom = { cu_header->offset.sect_off };
3864 sect_offset top = { cu_header->offset.sect_off + get_cu_length (cu_header) };
3866 return (offset.sect_off >= bottom.sect_off && offset.sect_off < top.sect_off);
3869 /* Find the base address of the compilation unit for range lists and
3870 location lists. It will normally be specified by DW_AT_low_pc.
3871 In DWARF-3 draft 4, the base address could be overridden by
3872 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3873 compilation units with discontinuous ranges. */
3876 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3878 struct attribute *attr;
3881 cu->base_address = 0;
3883 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3886 cu->base_address = DW_ADDR (attr);
3891 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3894 cu->base_address = DW_ADDR (attr);
3900 /* Read in the comp unit header information from the debug_info at info_ptr.
3901 NOTE: This leaves members offset, first_die_offset to be filled in
3905 read_comp_unit_head (struct comp_unit_head *cu_header,
3906 gdb_byte *info_ptr, bfd *abfd)
3909 unsigned int bytes_read;
3911 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
3912 cu_header->initial_length_size = bytes_read;
3913 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
3914 info_ptr += bytes_read;
3915 cu_header->version = read_2_bytes (abfd, info_ptr);
3917 cu_header->abbrev_offset.sect_off = read_offset (abfd, info_ptr, cu_header,
3919 info_ptr += bytes_read;
3920 cu_header->addr_size = read_1_byte (abfd, info_ptr);
3922 signed_addr = bfd_get_sign_extend_vma (abfd);
3923 if (signed_addr < 0)
3924 internal_error (__FILE__, __LINE__,
3925 _("read_comp_unit_head: dwarf from non elf file"));
3926 cu_header->signed_addr_p = signed_addr;
3931 /* Helper function that returns the proper abbrev section for
3934 static struct dwarf2_section_info *
3935 get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
3937 struct dwarf2_section_info *abbrev;
3939 if (this_cu->is_dwz)
3940 abbrev = &dwarf2_get_dwz_file ()->abbrev;
3942 abbrev = &dwarf2_per_objfile->abbrev;
3947 /* Subroutine of read_and_check_comp_unit_head and
3948 read_and_check_type_unit_head to simplify them.
3949 Perform various error checking on the header. */
3952 error_check_comp_unit_head (struct comp_unit_head *header,
3953 struct dwarf2_section_info *section,
3954 struct dwarf2_section_info *abbrev_section)
3956 bfd *abfd = section->asection->owner;
3957 const char *filename = bfd_get_filename (abfd);
3959 if (header->version != 2 && header->version != 3 && header->version != 4)
3960 error (_("Dwarf Error: wrong version in compilation unit header "
3961 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
3964 if (header->abbrev_offset.sect_off
3965 >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
3966 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3967 "(offset 0x%lx + 6) [in module %s]"),
3968 (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off,
3971 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3972 avoid potential 32-bit overflow. */
3973 if (((unsigned long) header->offset.sect_off + get_cu_length (header))
3975 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3976 "(offset 0x%lx + 0) [in module %s]"),
3977 (long) header->length, (long) header->offset.sect_off,
3981 /* Read in a CU/TU header and perform some basic error checking.
3982 The contents of the header are stored in HEADER.
3983 The result is a pointer to the start of the first DIE. */
3986 read_and_check_comp_unit_head (struct comp_unit_head *header,
3987 struct dwarf2_section_info *section,
3988 struct dwarf2_section_info *abbrev_section,
3990 int is_debug_types_section)
3992 gdb_byte *beg_of_comp_unit = info_ptr;
3993 bfd *abfd = section->asection->owner;
3995 header->offset.sect_off = beg_of_comp_unit - section->buffer;
3997 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3999 /* If we're reading a type unit, skip over the signature and
4000 type_offset fields. */
4001 if (is_debug_types_section)
4002 info_ptr += 8 /*signature*/ + header->offset_size;
4004 header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit;
4006 error_check_comp_unit_head (header, section, abbrev_section);
4011 /* Read in the types comp unit header information from .debug_types entry at
4012 types_ptr. The result is a pointer to one past the end of the header. */
4015 read_and_check_type_unit_head (struct comp_unit_head *header,
4016 struct dwarf2_section_info *section,
4017 struct dwarf2_section_info *abbrev_section,
4019 ULONGEST *signature,
4020 cu_offset *type_offset_in_tu)
4022 gdb_byte *beg_of_comp_unit = info_ptr;
4023 bfd *abfd = section->asection->owner;
4025 header->offset.sect_off = beg_of_comp_unit - section->buffer;
4027 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
4029 /* If we're reading a type unit, skip over the signature and
4030 type_offset fields. */
4031 if (signature != NULL)
4032 *signature = read_8_bytes (abfd, info_ptr);
4034 if (type_offset_in_tu != NULL)
4035 type_offset_in_tu->cu_off = read_offset_1 (abfd, info_ptr,
4036 header->offset_size);
4037 info_ptr += header->offset_size;
4039 header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit;
4041 error_check_comp_unit_head (header, section, abbrev_section);
4046 /* Fetch the abbreviation table offset from a comp or type unit header. */
4049 read_abbrev_offset (struct dwarf2_section_info *section,
4052 bfd *abfd = section->asection->owner;
4054 unsigned int length, initial_length_size, offset_size;
4055 sect_offset abbrev_offset;
4057 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
4058 info_ptr = section->buffer + offset.sect_off;
4059 length = read_initial_length (abfd, info_ptr, &initial_length_size);
4060 offset_size = initial_length_size == 4 ? 4 : 8;
4061 info_ptr += initial_length_size + 2 /*version*/;
4062 abbrev_offset.sect_off = read_offset_1 (abfd, info_ptr, offset_size);
4063 return abbrev_offset;
4066 /* Allocate a new partial symtab for file named NAME and mark this new
4067 partial symtab as being an include of PST. */
4070 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
4071 struct objfile *objfile)
4073 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
4075 if (!IS_ABSOLUTE_PATH (subpst->filename))
4077 /* It shares objfile->objfile_obstack. */
4078 subpst->dirname = pst->dirname;
4081 subpst->section_offsets = pst->section_offsets;
4082 subpst->textlow = 0;
4083 subpst->texthigh = 0;
4085 subpst->dependencies = (struct partial_symtab **)
4086 obstack_alloc (&objfile->objfile_obstack,
4087 sizeof (struct partial_symtab *));
4088 subpst->dependencies[0] = pst;
4089 subpst->number_of_dependencies = 1;
4091 subpst->globals_offset = 0;
4092 subpst->n_global_syms = 0;
4093 subpst->statics_offset = 0;
4094 subpst->n_static_syms = 0;
4095 subpst->symtab = NULL;
4096 subpst->read_symtab = pst->read_symtab;
4099 /* No private part is necessary for include psymtabs. This property
4100 can be used to differentiate between such include psymtabs and
4101 the regular ones. */
4102 subpst->read_symtab_private = NULL;
4105 /* Read the Line Number Program data and extract the list of files
4106 included by the source file represented by PST. Build an include
4107 partial symtab for each of these included files. */
4110 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
4111 struct die_info *die,
4112 struct partial_symtab *pst)
4114 struct line_header *lh = NULL;
4115 struct attribute *attr;
4117 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
4119 lh = dwarf_decode_line_header (DW_UNSND (attr), cu);
4121 return; /* No linetable, so no includes. */
4123 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4124 dwarf_decode_lines (lh, pst->dirname, cu, pst, 1);
4126 free_line_header (lh);
4130 hash_signatured_type (const void *item)
4132 const struct signatured_type *sig_type = item;
4134 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4135 return sig_type->signature;
4139 eq_signatured_type (const void *item_lhs, const void *item_rhs)
4141 const struct signatured_type *lhs = item_lhs;
4142 const struct signatured_type *rhs = item_rhs;
4144 return lhs->signature == rhs->signature;
4147 /* Allocate a hash table for signatured types. */
4150 allocate_signatured_type_table (struct objfile *objfile)
4152 return htab_create_alloc_ex (41,
4153 hash_signatured_type,
4156 &objfile->objfile_obstack,
4157 hashtab_obstack_allocate,
4158 dummy_obstack_deallocate);
4161 /* A helper function to add a signatured type CU to a table. */
4164 add_signatured_type_cu_to_table (void **slot, void *datum)
4166 struct signatured_type *sigt = *slot;
4167 struct signatured_type ***datap = datum;
4175 /* Create the hash table of all entries in the .debug_types
4176 (or .debug_types.dwo) section(s).
4177 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4178 otherwise it is NULL.
4180 The result is a pointer to the hash table or NULL if there are no types.
4182 Note: This function processes DWO files only, not DWP files. */
4185 create_debug_types_hash_table (struct dwo_file *dwo_file,
4186 VEC (dwarf2_section_info_def) *types)
4188 struct objfile *objfile = dwarf2_per_objfile->objfile;
4189 htab_t types_htab = NULL;
4191 struct dwarf2_section_info *section;
4192 struct dwarf2_section_info *abbrev_section;
4194 if (VEC_empty (dwarf2_section_info_def, types))
4197 abbrev_section = (dwo_file != NULL
4198 ? &dwo_file->sections.abbrev
4199 : &dwarf2_per_objfile->abbrev);
4201 if (dwarf2_read_debug)
4202 fprintf_unfiltered (gdb_stdlog, "Reading .debug_types%s for %s:\n",
4203 dwo_file ? ".dwo" : "",
4204 bfd_get_filename (abbrev_section->asection->owner));
4207 VEC_iterate (dwarf2_section_info_def, types, ix, section);
4211 gdb_byte *info_ptr, *end_ptr;
4212 struct dwarf2_section_info *abbrev_section;
4214 dwarf2_read_section (objfile, section);
4215 info_ptr = section->buffer;
4217 if (info_ptr == NULL)
4220 /* We can't set abfd until now because the section may be empty or
4221 not present, in which case section->asection will be NULL. */
4222 abfd = section->asection->owner;
4225 abbrev_section = &dwo_file->sections.abbrev;
4227 abbrev_section = &dwarf2_per_objfile->abbrev;
4229 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4230 because we don't need to read any dies: the signature is in the
4233 end_ptr = info_ptr + section->size;
4234 while (info_ptr < end_ptr)
4237 cu_offset type_offset_in_tu;
4239 struct signatured_type *sig_type;
4240 struct dwo_unit *dwo_tu;
4242 gdb_byte *ptr = info_ptr;
4243 struct comp_unit_head header;
4244 unsigned int length;
4246 offset.sect_off = ptr - section->buffer;
4248 /* We need to read the type's signature in order to build the hash
4249 table, but we don't need anything else just yet. */
4251 ptr = read_and_check_type_unit_head (&header, section,
4252 abbrev_section, ptr,
4253 &signature, &type_offset_in_tu);
4255 length = get_cu_length (&header);
4257 /* Skip dummy type units. */
4258 if (ptr >= info_ptr + length
4259 || peek_abbrev_code (abfd, ptr) == 0)
4265 if (types_htab == NULL)
4268 types_htab = allocate_dwo_unit_table (objfile);
4270 types_htab = allocate_signatured_type_table (objfile);
4276 dwo_tu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
4278 dwo_tu->dwo_file = dwo_file;
4279 dwo_tu->signature = signature;
4280 dwo_tu->type_offset_in_tu = type_offset_in_tu;
4281 dwo_tu->section = section;
4282 dwo_tu->offset = offset;
4283 dwo_tu->length = length;
4287 /* N.B.: type_offset is not usable if this type uses a DWO file.
4288 The real type_offset is in the DWO file. */
4290 sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
4291 struct signatured_type);
4292 sig_type->signature = signature;
4293 sig_type->type_offset_in_tu = type_offset_in_tu;
4294 sig_type->per_cu.objfile = objfile;
4295 sig_type->per_cu.is_debug_types = 1;
4296 sig_type->per_cu.section = section;
4297 sig_type->per_cu.offset = offset;
4298 sig_type->per_cu.length = length;
4301 slot = htab_find_slot (types_htab,
4302 dwo_file ? (void*) dwo_tu : (void *) sig_type,
4304 gdb_assert (slot != NULL);
4307 sect_offset dup_offset;
4311 const struct dwo_unit *dup_tu = *slot;
4313 dup_offset = dup_tu->offset;
4317 const struct signatured_type *dup_tu = *slot;
4319 dup_offset = dup_tu->per_cu.offset;
4322 complaint (&symfile_complaints,
4323 _("debug type entry at offset 0x%x is duplicate to"
4324 " the entry at offset 0x%x, signature 0x%s"),
4325 offset.sect_off, dup_offset.sect_off,
4326 phex (signature, sizeof (signature)));
4328 *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type;
4330 if (dwarf2_read_debug)
4331 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
4333 phex (signature, sizeof (signature)));
4342 /* Create the hash table of all entries in the .debug_types section,
4343 and initialize all_type_units.
4344 The result is zero if there is an error (e.g. missing .debug_types section),
4345 otherwise non-zero. */
4348 create_all_type_units (struct objfile *objfile)
4351 struct signatured_type **iter;
4353 types_htab = create_debug_types_hash_table (NULL, dwarf2_per_objfile->types);
4354 if (types_htab == NULL)
4356 dwarf2_per_objfile->signatured_types = NULL;
4360 dwarf2_per_objfile->signatured_types = types_htab;
4362 dwarf2_per_objfile->n_type_units = htab_elements (types_htab);
4363 dwarf2_per_objfile->all_type_units
4364 = obstack_alloc (&objfile->objfile_obstack,
4365 dwarf2_per_objfile->n_type_units
4366 * sizeof (struct signatured_type *));
4367 iter = &dwarf2_per_objfile->all_type_units[0];
4368 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter);
4369 gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0]
4370 == dwarf2_per_objfile->n_type_units);
4375 /* Lookup a signature based type for DW_FORM_ref_sig8.
4376 Returns NULL if signature SIG is not present in the table.
4377 It is up to the caller to complain about this. */
4379 static struct signatured_type *
4380 lookup_signatured_type (ULONGEST sig)
4382 struct signatured_type find_entry, *entry;
4384 if (dwarf2_per_objfile->signatured_types == NULL)
4386 find_entry.signature = sig;
4387 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
4391 /* Low level DIE reading support. */
4393 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4396 init_cu_die_reader (struct die_reader_specs *reader,
4397 struct dwarf2_cu *cu,
4398 struct dwarf2_section_info *section,
4399 struct dwo_file *dwo_file)
4401 gdb_assert (section->readin && section->buffer != NULL);
4402 reader->abfd = section->asection->owner;
4404 reader->dwo_file = dwo_file;
4405 reader->die_section = section;
4406 reader->buffer = section->buffer;
4407 reader->buffer_end = section->buffer + section->size;
4410 /* Subroutine of init_cutu_and_read_dies to simplify it.
4411 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
4412 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
4415 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
4416 from it to the DIE in the DWO. If NULL we are skipping the stub.
4417 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
4418 are filled in with the info of the DIE from the DWO file.
4419 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
4420 provided an abbrev table to use.
4421 The result is non-zero if a valid (non-dummy) DIE was found. */
4424 read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
4425 struct dwo_unit *dwo_unit,
4426 int abbrev_table_provided,
4427 struct die_info *stub_comp_unit_die,
4428 struct die_reader_specs *result_reader,
4429 gdb_byte **result_info_ptr,
4430 struct die_info **result_comp_unit_die,
4431 int *result_has_children)
4433 struct objfile *objfile = dwarf2_per_objfile->objfile;
4434 struct dwarf2_cu *cu = this_cu->cu;
4435 struct dwarf2_section_info *section;
4437 gdb_byte *begin_info_ptr, *info_ptr;
4438 const char *comp_dir_string;
4439 ULONGEST signature; /* Or dwo_id. */
4440 struct attribute *comp_dir, *stmt_list, *low_pc, *high_pc, *ranges;
4441 int i,num_extra_attrs;
4442 struct dwarf2_section_info *dwo_abbrev_section;
4443 struct attribute *attr;
4444 struct die_info *comp_unit_die;
4446 /* These attributes aren't processed until later:
4447 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4448 However, the attribute is found in the stub which we won't have later.
4449 In order to not impose this complication on the rest of the code,
4450 we read them here and copy them to the DWO CU/TU die. */
4458 if (stub_comp_unit_die != NULL)
4460 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4462 if (! this_cu->is_debug_types)
4463 stmt_list = dwarf2_attr (stub_comp_unit_die, DW_AT_stmt_list, cu);
4464 low_pc = dwarf2_attr (stub_comp_unit_die, DW_AT_low_pc, cu);
4465 high_pc = dwarf2_attr (stub_comp_unit_die, DW_AT_high_pc, cu);
4466 ranges = dwarf2_attr (stub_comp_unit_die, DW_AT_ranges, cu);
4467 comp_dir = dwarf2_attr (stub_comp_unit_die, DW_AT_comp_dir, cu);
4469 /* There should be a DW_AT_addr_base attribute here (if needed).
4470 We need the value before we can process DW_FORM_GNU_addr_index. */
4472 attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_addr_base, cu);
4474 cu->addr_base = DW_UNSND (attr);
4476 /* There should be a DW_AT_ranges_base attribute here (if needed).
4477 We need the value before we can process DW_AT_ranges. */
4478 cu->ranges_base = 0;
4479 attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_ranges_base, cu);
4481 cu->ranges_base = DW_UNSND (attr);
4484 /* Set up for reading the DWO CU/TU. */
4485 cu->dwo_unit = dwo_unit;
4486 section = dwo_unit->section;
4487 dwarf2_read_section (objfile, section);
4488 abfd = section->asection->owner;
4489 begin_info_ptr = info_ptr = section->buffer + dwo_unit->offset.sect_off;
4490 dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev;
4491 init_cu_die_reader (result_reader, cu, section, dwo_unit->dwo_file);
4493 if (this_cu->is_debug_types)
4495 ULONGEST header_signature;
4496 cu_offset type_offset_in_tu;
4497 struct signatured_type *sig_type = (struct signatured_type *) this_cu;
4499 info_ptr = read_and_check_type_unit_head (&cu->header, section,
4503 &type_offset_in_tu);
4504 gdb_assert (sig_type->signature == header_signature);
4505 gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off);
4506 /* For DWOs coming from DWP files, we don't know the CU length
4507 nor the type's offset in the TU until now. */
4508 dwo_unit->length = get_cu_length (&cu->header);
4509 dwo_unit->type_offset_in_tu = type_offset_in_tu;
4511 /* Establish the type offset that can be used to lookup the type.
4512 For DWO files, we don't know it until now. */
4513 sig_type->type_offset_in_section.sect_off =
4514 dwo_unit->offset.sect_off + dwo_unit->type_offset_in_tu.cu_off;
4518 info_ptr = read_and_check_comp_unit_head (&cu->header, section,
4521 gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off);
4522 /* For DWOs coming from DWP files, we don't know the CU length
4524 dwo_unit->length = get_cu_length (&cu->header);
4527 /* Replace the CU's original abbrev table with the DWO's. */
4528 if (abbrev_table_provided)
4530 /* Don't free the provided abbrev table, the caller of
4531 init_cutu_and_read_dies owns it. */
4532 dwarf2_read_abbrevs (cu, dwo_abbrev_section);
4533 make_cleanup (dwarf2_free_abbrev_table, cu);
4537 dwarf2_free_abbrev_table (cu);
4538 dwarf2_read_abbrevs (cu, dwo_abbrev_section);
4541 /* Read in the die, but leave space to copy over the attributes
4542 from the stub. This has the benefit of simplifying the rest of
4543 the code - all the work to maintain the illusion of a single
4544 DW_TAG_{compile,type}_unit DIE is done here. */
4545 num_extra_attrs = ((stmt_list != NULL)
4549 + (comp_dir != NULL));
4550 info_ptr = read_full_die_1 (result_reader, result_comp_unit_die, info_ptr,
4551 result_has_children, num_extra_attrs);
4553 /* Copy over the attributes from the stub to the DIE we just read in. */
4554 comp_unit_die = *result_comp_unit_die;
4555 i = comp_unit_die->num_attrs;
4556 if (stmt_list != NULL)
4557 comp_unit_die->attrs[i++] = *stmt_list;
4559 comp_unit_die->attrs[i++] = *low_pc;
4560 if (high_pc != NULL)
4561 comp_unit_die->attrs[i++] = *high_pc;
4563 comp_unit_die->attrs[i++] = *ranges;
4564 if (comp_dir != NULL)
4565 comp_unit_die->attrs[i++] = *comp_dir;
4566 comp_unit_die->num_attrs += num_extra_attrs;
4568 /* Skip dummy compilation units. */
4569 if (info_ptr >= begin_info_ptr + dwo_unit->length
4570 || peek_abbrev_code (abfd, info_ptr) == 0)
4573 *result_info_ptr = info_ptr;
4577 /* Subroutine of init_cutu_and_read_dies to simplify it.
4578 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
4579 If the specified DWO unit cannot be found an error is thrown. */
4581 static struct dwo_unit *
4582 lookup_dwo_unit (struct dwarf2_per_cu_data *this_cu,
4583 struct die_info *comp_unit_die)
4585 struct dwarf2_cu *cu = this_cu->cu;
4586 struct attribute *attr;
4588 struct dwo_unit *dwo_unit;
4589 const char *comp_dir, *dwo_name;
4591 /* Yeah, we look dwo_name up again, but it simplifies the code. */
4592 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu);
4593 gdb_assert (attr != NULL);
4594 dwo_name = DW_STRING (attr);
4596 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu);
4598 comp_dir = DW_STRING (attr);
4600 if (this_cu->is_debug_types)
4602 struct signatured_type *sig_type;
4604 /* Since this_cu is the first member of struct signatured_type,
4605 we can go from a pointer to one to a pointer to the other. */
4606 sig_type = (struct signatured_type *) this_cu;
4607 signature = sig_type->signature;
4608 dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir);
4612 struct attribute *attr;
4614 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
4616 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
4618 dwo_name, this_cu->objfile->name);
4619 signature = DW_UNSND (attr);
4620 dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir,
4624 if (dwo_unit == NULL)
4626 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4627 " with ID %s [in module %s]"),
4628 this_cu->offset.sect_off,
4629 phex (signature, sizeof (signature)),
4630 this_cu->objfile->name);
4636 /* Initialize a CU (or TU) and read its DIEs.
4637 If the CU defers to a DWO file, read the DWO file as well.
4639 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4640 Otherwise the table specified in the comp unit header is read in and used.
4641 This is an optimization for when we already have the abbrev table.
4643 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4644 Otherwise, a new CU is allocated with xmalloc.
4646 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4647 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4649 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4650 linker) then DIE_READER_FUNC will not get called. */
4653 init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu,
4654 struct abbrev_table *abbrev_table,
4655 int use_existing_cu, int keep,
4656 die_reader_func_ftype *die_reader_func,
4659 struct objfile *objfile = dwarf2_per_objfile->objfile;
4660 struct dwarf2_section_info *section = this_cu->section;
4661 bfd *abfd = section->asection->owner;
4662 struct dwarf2_cu *cu;
4663 gdb_byte *begin_info_ptr, *info_ptr;
4664 struct die_reader_specs reader;
4665 struct die_info *comp_unit_die;
4667 struct attribute *attr;
4668 struct cleanup *cleanups, *free_cu_cleanup = NULL;
4669 struct signatured_type *sig_type = NULL;
4670 struct dwarf2_section_info *abbrev_section;
4671 /* Non-zero if CU currently points to a DWO file and we need to
4672 reread it. When this happens we need to reread the skeleton die
4673 before we can reread the DWO file. */
4674 int rereading_dwo_cu = 0;
4676 if (dwarf2_die_debug)
4677 fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n",
4678 this_cu->is_debug_types ? "type" : "comp",
4679 this_cu->offset.sect_off);
4681 if (use_existing_cu)
4684 cleanups = make_cleanup (null_cleanup, NULL);
4686 /* This is cheap if the section is already read in. */
4687 dwarf2_read_section (objfile, section);
4689 begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off;
4691 abbrev_section = get_abbrev_section_for_cu (this_cu);
4693 if (use_existing_cu && this_cu->cu != NULL)
4697 /* If this CU is from a DWO file we need to start over, we need to
4698 refetch the attributes from the skeleton CU.
4699 This could be optimized by retrieving those attributes from when we
4700 were here the first time: the previous comp_unit_die was stored in
4701 comp_unit_obstack. But there's no data yet that we need this
4703 if (cu->dwo_unit != NULL)
4704 rereading_dwo_cu = 1;
4708 /* If !use_existing_cu, this_cu->cu must be NULL. */
4709 gdb_assert (this_cu->cu == NULL);
4711 cu = xmalloc (sizeof (*cu));
4712 init_one_comp_unit (cu, this_cu);
4714 /* If an error occurs while loading, release our storage. */
4715 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
4718 /* Get the header. */
4719 if (cu->header.first_die_offset.cu_off != 0 && ! rereading_dwo_cu)
4721 /* We already have the header, there's no need to read it in again. */
4722 info_ptr += cu->header.first_die_offset.cu_off;
4726 if (this_cu->is_debug_types)
4729 cu_offset type_offset_in_tu;
4731 info_ptr = read_and_check_type_unit_head (&cu->header, section,
4732 abbrev_section, info_ptr,
4734 &type_offset_in_tu);
4736 /* Since per_cu is the first member of struct signatured_type,
4737 we can go from a pointer to one to a pointer to the other. */
4738 sig_type = (struct signatured_type *) this_cu;
4739 gdb_assert (sig_type->signature == signature);
4740 gdb_assert (sig_type->type_offset_in_tu.cu_off
4741 == type_offset_in_tu.cu_off);
4742 gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off);
4744 /* LENGTH has not been set yet for type units if we're
4745 using .gdb_index. */
4746 this_cu->length = get_cu_length (&cu->header);
4748 /* Establish the type offset that can be used to lookup the type. */
4749 sig_type->type_offset_in_section.sect_off =
4750 this_cu->offset.sect_off + sig_type->type_offset_in_tu.cu_off;
4754 info_ptr = read_and_check_comp_unit_head (&cu->header, section,
4758 gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off);
4759 gdb_assert (this_cu->length == get_cu_length (&cu->header));
4763 /* Skip dummy compilation units. */
4764 if (info_ptr >= begin_info_ptr + this_cu->length
4765 || peek_abbrev_code (abfd, info_ptr) == 0)
4767 do_cleanups (cleanups);
4771 /* If we don't have them yet, read the abbrevs for this compilation unit.
4772 And if we need to read them now, make sure they're freed when we're
4773 done. Note that it's important that if the CU had an abbrev table
4774 on entry we don't free it when we're done: Somewhere up the call stack
4775 it may be in use. */
4776 if (abbrev_table != NULL)
4778 gdb_assert (cu->abbrev_table == NULL);
4779 gdb_assert (cu->header.abbrev_offset.sect_off
4780 == abbrev_table->offset.sect_off);
4781 cu->abbrev_table = abbrev_table;
4783 else if (cu->abbrev_table == NULL)
4785 dwarf2_read_abbrevs (cu, abbrev_section);
4786 make_cleanup (dwarf2_free_abbrev_table, cu);
4788 else if (rereading_dwo_cu)
4790 dwarf2_free_abbrev_table (cu);
4791 dwarf2_read_abbrevs (cu, abbrev_section);
4794 /* Read the top level CU/TU die. */
4795 init_cu_die_reader (&reader, cu, section, NULL);
4796 info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children);
4798 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
4800 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
4801 DWO CU, that this test will fail (the attribute will not be present). */
4802 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu);
4805 struct dwo_unit *dwo_unit;
4806 struct die_info *dwo_comp_unit_die;
4809 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4810 " has children (offset 0x%x) [in module %s]"),
4811 this_cu->offset.sect_off, bfd_get_filename (abfd));
4812 dwo_unit = lookup_dwo_unit (this_cu, comp_unit_die);
4813 if (read_cutu_die_from_dwo (this_cu, dwo_unit,
4814 abbrev_table != NULL,
4817 &dwo_comp_unit_die, &has_children) == 0)
4820 do_cleanups (cleanups);
4823 comp_unit_die = dwo_comp_unit_die;
4826 /* All of the above is setup for this call. Yikes. */
4827 die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data);
4829 /* Done, clean up. */
4830 if (free_cu_cleanup != NULL)
4834 /* We've successfully allocated this compilation unit. Let our
4835 caller clean it up when finished with it. */
4836 discard_cleanups (free_cu_cleanup);
4838 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4839 So we have to manually free the abbrev table. */
4840 dwarf2_free_abbrev_table (cu);
4842 /* Link this CU into read_in_chain. */
4843 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4844 dwarf2_per_objfile->read_in_chain = this_cu;
4847 do_cleanups (free_cu_cleanup);
4850 do_cleanups (cleanups);
4853 /* Read CU/TU THIS_CU in section SECTION,
4854 but do not follow DW_AT_GNU_dwo_name if present.
4855 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4856 to have already done the lookup to find the DWO/DWP file).
4858 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4859 THIS_CU->is_debug_types, but nothing else.
4861 We fill in THIS_CU->length.
4863 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4864 linker) then DIE_READER_FUNC will not get called.
4866 THIS_CU->cu is always freed when done.
4867 This is done in order to not leave THIS_CU->cu in a state where we have
4868 to care whether it refers to the "main" CU or the DWO CU. */
4871 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu,
4872 struct dwarf2_section_info *abbrev_section,
4873 struct dwo_file *dwo_file,
4874 die_reader_func_ftype *die_reader_func,
4877 struct objfile *objfile = dwarf2_per_objfile->objfile;
4878 struct dwarf2_section_info *section = this_cu->section;
4879 bfd *abfd = section->asection->owner;
4880 struct dwarf2_cu cu;
4881 gdb_byte *begin_info_ptr, *info_ptr;
4882 struct die_reader_specs reader;
4883 struct cleanup *cleanups;
4884 struct die_info *comp_unit_die;
4887 if (dwarf2_die_debug)
4888 fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n",
4889 this_cu->is_debug_types ? "type" : "comp",
4890 this_cu->offset.sect_off);
4892 gdb_assert (this_cu->cu == NULL);
4894 /* This is cheap if the section is already read in. */
4895 dwarf2_read_section (objfile, section);
4897 init_one_comp_unit (&cu, this_cu);
4899 cleanups = make_cleanup (free_stack_comp_unit, &cu);
4901 begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off;
4902 info_ptr = read_and_check_comp_unit_head (&cu.header, section,
4903 abbrev_section, info_ptr,
4904 this_cu->is_debug_types);
4906 this_cu->length = get_cu_length (&cu.header);
4908 /* Skip dummy compilation units. */
4909 if (info_ptr >= begin_info_ptr + this_cu->length
4910 || peek_abbrev_code (abfd, info_ptr) == 0)
4912 do_cleanups (cleanups);
4916 dwarf2_read_abbrevs (&cu, abbrev_section);
4917 make_cleanup (dwarf2_free_abbrev_table, &cu);
4919 init_cu_die_reader (&reader, &cu, section, dwo_file);
4920 info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children);
4922 die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data);
4924 do_cleanups (cleanups);
4927 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4928 does not lookup the specified DWO file.
4929 This cannot be used to read DWO files.
4931 THIS_CU->cu is always freed when done.
4932 This is done in order to not leave THIS_CU->cu in a state where we have
4933 to care whether it refers to the "main" CU or the DWO CU.
4934 We can revisit this if the data shows there's a performance issue. */
4937 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu,
4938 die_reader_func_ftype *die_reader_func,
4941 init_cutu_and_read_dies_no_follow (this_cu,
4942 get_abbrev_section_for_cu (this_cu),
4944 die_reader_func, data);
4947 /* Type Unit Groups.
4949 Type Unit Groups are a way to collapse the set of all TUs (type units) into
4950 a more manageable set. The grouping is done by DW_AT_stmt_list entry
4951 so that all types coming from the same compilation (.o file) are grouped
4952 together. A future step could be to put the types in the same symtab as
4953 the CU the types ultimately came from. */
4956 hash_type_unit_group (const void *item)
4958 const struct type_unit_group *tu_group = item;
4960 return hash_stmt_list_entry (&tu_group->hash);
4964 eq_type_unit_group (const void *item_lhs, const void *item_rhs)
4966 const struct type_unit_group *lhs = item_lhs;
4967 const struct type_unit_group *rhs = item_rhs;
4969 return eq_stmt_list_entry (&lhs->hash, &rhs->hash);
4972 /* Allocate a hash table for type unit groups. */
4975 allocate_type_unit_groups_table (void)
4977 return htab_create_alloc_ex (3,
4978 hash_type_unit_group,
4981 &dwarf2_per_objfile->objfile->objfile_obstack,
4982 hashtab_obstack_allocate,
4983 dummy_obstack_deallocate);
4986 /* Type units that don't have DW_AT_stmt_list are grouped into their own
4987 partial symtabs. We combine several TUs per psymtab to not let the size
4988 of any one psymtab grow too big. */
4989 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
4990 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
4992 /* Helper routine for get_type_unit_group.
4993 Create the type_unit_group object used to hold one or more TUs. */
4995 static struct type_unit_group *
4996 create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
4998 struct objfile *objfile = dwarf2_per_objfile->objfile;
4999 struct dwarf2_per_cu_data *per_cu;
5000 struct type_unit_group *tu_group;
5002 tu_group = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5003 struct type_unit_group);
5004 per_cu = &tu_group->per_cu;
5005 per_cu->objfile = objfile;
5007 if (dwarf2_per_objfile->using_index)
5009 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5010 struct dwarf2_per_cu_quick_data);
5014 unsigned int line_offset = line_offset_struct.sect_off;
5015 struct partial_symtab *pst;
5018 /* Give the symtab a useful name for debug purposes. */
5019 if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0)
5020 name = xstrprintf ("<type_units_%d>",
5021 (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
5023 name = xstrprintf ("<type_units_at_0x%x>", line_offset);
5025 pst = create_partial_symtab (per_cu, name);
5031 tu_group->hash.dwo_unit = cu->dwo_unit;
5032 tu_group->hash.line_offset = line_offset_struct;
5037 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5038 STMT_LIST is a DW_AT_stmt_list attribute. */
5040 static struct type_unit_group *
5041 get_type_unit_group (struct dwarf2_cu *cu, struct attribute *stmt_list)
5043 struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
5044 struct type_unit_group *tu_group;
5046 unsigned int line_offset;
5047 struct type_unit_group type_unit_group_for_lookup;
5049 if (dwarf2_per_objfile->type_unit_groups == NULL)
5051 dwarf2_per_objfile->type_unit_groups =
5052 allocate_type_unit_groups_table ();
5055 /* Do we need to create a new group, or can we use an existing one? */
5059 line_offset = DW_UNSND (stmt_list);
5060 ++tu_stats->nr_symtab_sharers;
5064 /* Ugh, no stmt_list. Rare, but we have to handle it.
5065 We can do various things here like create one group per TU or
5066 spread them over multiple groups to split up the expansion work.
5067 To avoid worst case scenarios (too many groups or too large groups)
5068 we, umm, group them in bunches. */
5069 line_offset = (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5070 | (tu_stats->nr_stmt_less_type_units
5071 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE));
5072 ++tu_stats->nr_stmt_less_type_units;
5075 type_unit_group_for_lookup.hash.dwo_unit = cu->dwo_unit;
5076 type_unit_group_for_lookup.hash.line_offset.sect_off = line_offset;
5077 slot = htab_find_slot (dwarf2_per_objfile->type_unit_groups,
5078 &type_unit_group_for_lookup, INSERT);
5082 gdb_assert (tu_group != NULL);
5086 sect_offset line_offset_struct;
5088 line_offset_struct.sect_off = line_offset;
5089 tu_group = create_type_unit_group (cu, line_offset_struct);
5091 ++tu_stats->nr_symtabs;
5097 /* Struct used to sort TUs by their abbreviation table offset. */
5099 struct tu_abbrev_offset
5101 struct signatured_type *sig_type;
5102 sect_offset abbrev_offset;
5105 /* Helper routine for build_type_unit_groups, passed to qsort. */
5108 sort_tu_by_abbrev_offset (const void *ap, const void *bp)
5110 const struct tu_abbrev_offset * const *a = ap;
5111 const struct tu_abbrev_offset * const *b = bp;
5112 unsigned int aoff = (*a)->abbrev_offset.sect_off;
5113 unsigned int boff = (*b)->abbrev_offset.sect_off;
5115 return (aoff > boff) - (aoff < boff);
5118 /* A helper function to add a type_unit_group to a table. */
5121 add_type_unit_group_to_table (void **slot, void *datum)
5123 struct type_unit_group *tu_group = *slot;
5124 struct type_unit_group ***datap = datum;
5132 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5133 each one passing FUNC,DATA.
5135 The efficiency is because we sort TUs by the abbrev table they use and
5136 only read each abbrev table once. In one program there are 200K TUs
5137 sharing 8K abbrev tables.
5139 The main purpose of this function is to support building the
5140 dwarf2_per_objfile->type_unit_groups table.
5141 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5142 can collapse the search space by grouping them by stmt_list.
5143 The savings can be significant, in the same program from above the 200K TUs
5144 share 8K stmt_list tables.
5146 FUNC is expected to call get_type_unit_group, which will create the
5147 struct type_unit_group if necessary and add it to
5148 dwarf2_per_objfile->type_unit_groups. */
5151 build_type_unit_groups (die_reader_func_ftype *func, void *data)
5153 struct objfile *objfile = dwarf2_per_objfile->objfile;
5154 struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
5155 struct cleanup *cleanups;
5156 struct abbrev_table *abbrev_table;
5157 sect_offset abbrev_offset;
5158 struct tu_abbrev_offset *sorted_by_abbrev;
5159 struct type_unit_group **iter;
5162 /* It's up to the caller to not call us multiple times. */
5163 gdb_assert (dwarf2_per_objfile->type_unit_groups == NULL);
5165 if (dwarf2_per_objfile->n_type_units == 0)
5168 /* TUs typically share abbrev tables, and there can be way more TUs than
5169 abbrev tables. Sort by abbrev table to reduce the number of times we
5170 read each abbrev table in.
5171 Alternatives are to punt or to maintain a cache of abbrev tables.
5172 This is simpler and efficient enough for now.
5174 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5175 symtab to use). Typically TUs with the same abbrev offset have the same
5176 stmt_list value too so in practice this should work well.
5178 The basic algorithm here is:
5180 sort TUs by abbrev table
5181 for each TU with same abbrev table:
5182 read abbrev table if first user
5183 read TU top level DIE
5184 [IWBN if DWO skeletons had DW_AT_stmt_list]
5187 if (dwarf2_read_debug)
5188 fprintf_unfiltered (gdb_stdlog, "Building type unit groups ...\n");
5190 /* Sort in a separate table to maintain the order of all_type_units
5191 for .gdb_index: TU indices directly index all_type_units. */
5192 sorted_by_abbrev = XNEWVEC (struct tu_abbrev_offset,
5193 dwarf2_per_objfile->n_type_units);
5194 for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
5196 struct signatured_type *sig_type = dwarf2_per_objfile->all_type_units[i];
5198 sorted_by_abbrev[i].sig_type = sig_type;
5199 sorted_by_abbrev[i].abbrev_offset =
5200 read_abbrev_offset (sig_type->per_cu.section,
5201 sig_type->per_cu.offset);
5203 cleanups = make_cleanup (xfree, sorted_by_abbrev);
5204 qsort (sorted_by_abbrev, dwarf2_per_objfile->n_type_units,
5205 sizeof (struct tu_abbrev_offset), sort_tu_by_abbrev_offset);
5207 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5208 called any number of times, so we don't reset tu_stats here. */
5210 abbrev_offset.sect_off = ~(unsigned) 0;
5211 abbrev_table = NULL;
5212 make_cleanup (abbrev_table_free_cleanup, &abbrev_table);
5214 for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
5216 const struct tu_abbrev_offset *tu = &sorted_by_abbrev[i];
5218 /* Switch to the next abbrev table if necessary. */
5219 if (abbrev_table == NULL
5220 || tu->abbrev_offset.sect_off != abbrev_offset.sect_off)
5222 if (abbrev_table != NULL)
5224 abbrev_table_free (abbrev_table);
5225 /* Reset to NULL in case abbrev_table_read_table throws
5226 an error: abbrev_table_free_cleanup will get called. */
5227 abbrev_table = NULL;
5229 abbrev_offset = tu->abbrev_offset;
5231 abbrev_table_read_table (&dwarf2_per_objfile->abbrev,
5233 ++tu_stats->nr_uniq_abbrev_tables;
5236 init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table, 0, 0,
5240 /* Create a vector of pointers to primary type units to make it easy to
5241 iterate over them and CUs. See dw2_get_primary_cu. */
5242 dwarf2_per_objfile->n_type_unit_groups =
5243 htab_elements (dwarf2_per_objfile->type_unit_groups);
5244 dwarf2_per_objfile->all_type_unit_groups =
5245 obstack_alloc (&objfile->objfile_obstack,
5246 dwarf2_per_objfile->n_type_unit_groups
5247 * sizeof (struct type_unit_group *));
5248 iter = &dwarf2_per_objfile->all_type_unit_groups[0];
5249 htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups,
5250 add_type_unit_group_to_table, &iter);
5251 gdb_assert (iter - &dwarf2_per_objfile->all_type_unit_groups[0]
5252 == dwarf2_per_objfile->n_type_unit_groups);
5254 do_cleanups (cleanups);
5256 if (dwarf2_read_debug)
5258 fprintf_unfiltered (gdb_stdlog, "Done building type unit groups:\n");
5259 fprintf_unfiltered (gdb_stdlog, " %d TUs\n",
5260 dwarf2_per_objfile->n_type_units);
5261 fprintf_unfiltered (gdb_stdlog, " %d uniq abbrev tables\n",
5262 tu_stats->nr_uniq_abbrev_tables);
5263 fprintf_unfiltered (gdb_stdlog, " %d symtabs from stmt_list entries\n",
5264 tu_stats->nr_symtabs);
5265 fprintf_unfiltered (gdb_stdlog, " %d symtab sharers\n",
5266 tu_stats->nr_symtab_sharers);
5267 fprintf_unfiltered (gdb_stdlog, " %d type units without a stmt_list\n",
5268 tu_stats->nr_stmt_less_type_units);
5272 /* Partial symbol tables. */
5274 /* Create a psymtab named NAME and assign it to PER_CU.
5276 The caller must fill in the following details:
5277 dirname, textlow, texthigh. */
5279 static struct partial_symtab *
5280 create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name)
5282 struct objfile *objfile = per_cu->objfile;
5283 struct partial_symtab *pst;
5285 pst = start_psymtab_common (objfile, objfile->section_offsets,
5287 objfile->global_psymbols.next,
5288 objfile->static_psymbols.next);
5290 pst->psymtabs_addrmap_supported = 1;
5292 /* This is the glue that links PST into GDB's symbol API. */
5293 pst->read_symtab_private = per_cu;
5294 pst->read_symtab = dwarf2_read_symtab;
5295 per_cu->v.psymtab = pst;
5300 /* die_reader_func for process_psymtab_comp_unit. */
5303 process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
5305 struct die_info *comp_unit_die,
5309 struct dwarf2_cu *cu = reader->cu;
5310 struct objfile *objfile = cu->objfile;
5311 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
5312 struct attribute *attr;
5314 CORE_ADDR best_lowpc = 0, best_highpc = 0;
5315 struct partial_symtab *pst;
5317 const char *filename;
5318 int *want_partial_unit_ptr = data;
5320 if (comp_unit_die->tag == DW_TAG_partial_unit
5321 && (want_partial_unit_ptr == NULL
5322 || !*want_partial_unit_ptr))
5325 gdb_assert (! per_cu->is_debug_types);
5327 prepare_one_comp_unit (cu, comp_unit_die, language_minimal);
5329 cu->list_in_scope = &file_symbols;
5331 /* Allocate a new partial symbol table structure. */
5332 attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu);
5333 if (attr == NULL || !DW_STRING (attr))
5336 filename = DW_STRING (attr);
5338 pst = create_partial_symtab (per_cu, filename);
5340 /* This must be done before calling dwarf2_build_include_psymtabs. */
5341 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu);
5343 pst->dirname = DW_STRING (attr);
5345 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5347 dwarf2_find_base_address (comp_unit_die, cu);
5349 /* Possibly set the default values of LOWPC and HIGHPC from
5351 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
5352 &best_highpc, cu, pst);
5353 if (has_pc_info == 1 && best_lowpc < best_highpc)
5354 /* Store the contiguous range if it is not empty; it can be empty for
5355 CUs with no code. */
5356 addrmap_set_empty (objfile->psymtabs_addrmap,
5357 best_lowpc + baseaddr,
5358 best_highpc + baseaddr - 1, pst);
5360 /* Check if comp unit has_children.
5361 If so, read the rest of the partial symbols from this comp unit.
5362 If not, there's no more debug_info for this comp unit. */
5365 struct partial_die_info *first_die;
5366 CORE_ADDR lowpc, highpc;
5368 lowpc = ((CORE_ADDR) -1);
5369 highpc = ((CORE_ADDR) 0);
5371 first_die = load_partial_dies (reader, info_ptr, 1);
5373 scan_partial_symbols (first_die, &lowpc, &highpc,
5376 /* If we didn't find a lowpc, set it to highpc to avoid
5377 complaints from `maint check'. */
5378 if (lowpc == ((CORE_ADDR) -1))
5381 /* If the compilation unit didn't have an explicit address range,
5382 then use the information extracted from its child dies. */
5386 best_highpc = highpc;
5389 pst->textlow = best_lowpc + baseaddr;
5390 pst->texthigh = best_highpc + baseaddr;
5392 pst->n_global_syms = objfile->global_psymbols.next -
5393 (objfile->global_psymbols.list + pst->globals_offset);
5394 pst->n_static_syms = objfile->static_psymbols.next -
5395 (objfile->static_psymbols.list + pst->statics_offset);
5396 sort_pst_symbols (objfile, pst);
5398 if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs))
5401 int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
5402 struct dwarf2_per_cu_data *iter;
5404 /* Fill in 'dependencies' here; we fill in 'users' in a
5406 pst->number_of_dependencies = len;
5407 pst->dependencies = obstack_alloc (&objfile->objfile_obstack,
5408 len * sizeof (struct symtab *));
5410 VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
5413 pst->dependencies[i] = iter->v.psymtab;
5415 VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
5418 /* Get the list of files included in the current compilation unit,
5419 and build a psymtab for each of them. */
5420 dwarf2_build_include_psymtabs (cu, comp_unit_die, pst);
5422 if (dwarf2_read_debug)
5424 struct gdbarch *gdbarch = get_objfile_arch (objfile);
5426 fprintf_unfiltered (gdb_stdlog,
5427 "Psymtab for %s unit @0x%x: %s - %s"
5428 ", %d global, %d static syms\n",
5429 per_cu->is_debug_types ? "type" : "comp",
5430 per_cu->offset.sect_off,
5431 paddress (gdbarch, pst->textlow),
5432 paddress (gdbarch, pst->texthigh),
5433 pst->n_global_syms, pst->n_static_syms);
5437 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5438 Process compilation unit THIS_CU for a psymtab. */
5441 process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
5442 int want_partial_unit)
5444 /* If this compilation unit was already read in, free the
5445 cached copy in order to read it in again. This is
5446 necessary because we skipped some symbols when we first
5447 read in the compilation unit (see load_partial_dies).
5448 This problem could be avoided, but the benefit is unclear. */
5449 if (this_cu->cu != NULL)
5450 free_one_cached_comp_unit (this_cu);
5452 gdb_assert (! this_cu->is_debug_types);
5453 init_cutu_and_read_dies (this_cu, NULL, 0, 0,
5454 process_psymtab_comp_unit_reader,
5455 &want_partial_unit);
5457 /* Age out any secondary CUs. */
5458 age_cached_comp_units ();
5461 /* Reader function for build_type_psymtabs. */
5464 build_type_psymtabs_reader (const struct die_reader_specs *reader,
5466 struct die_info *type_unit_die,
5470 struct objfile *objfile = dwarf2_per_objfile->objfile;
5471 struct dwarf2_cu *cu = reader->cu;
5472 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
5473 struct signatured_type *sig_type;
5474 struct type_unit_group *tu_group;
5475 struct attribute *attr;
5476 struct partial_die_info *first_die;
5477 CORE_ADDR lowpc, highpc;
5478 struct partial_symtab *pst;
5480 gdb_assert (data == NULL);
5481 gdb_assert (per_cu->is_debug_types);
5482 sig_type = (struct signatured_type *) per_cu;
5487 attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
5488 tu_group = get_type_unit_group (cu, attr);
5490 VEC_safe_push (sig_type_ptr, tu_group->tus, sig_type);
5492 prepare_one_comp_unit (cu, type_unit_die, language_minimal);
5493 cu->list_in_scope = &file_symbols;
5494 pst = create_partial_symtab (per_cu, "");
5497 first_die = load_partial_dies (reader, info_ptr, 1);
5499 lowpc = (CORE_ADDR) -1;
5500 highpc = (CORE_ADDR) 0;
5501 scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu);
5503 pst->n_global_syms = objfile->global_psymbols.next -
5504 (objfile->global_psymbols.list + pst->globals_offset);
5505 pst->n_static_syms = objfile->static_psymbols.next -
5506 (objfile->static_psymbols.list + pst->statics_offset);
5507 sort_pst_symbols (objfile, pst);
5510 /* Traversal function for build_type_psymtabs. */
5513 build_type_psymtab_dependencies (void **slot, void *info)
5515 struct objfile *objfile = dwarf2_per_objfile->objfile;
5516 struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
5517 struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
5518 struct partial_symtab *pst = per_cu->v.psymtab;
5519 int len = VEC_length (sig_type_ptr, tu_group->tus);
5520 struct signatured_type *iter;
5523 gdb_assert (len > 0);
5524 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu));
5526 pst->number_of_dependencies = len;
5527 pst->dependencies = obstack_alloc (&objfile->objfile_obstack,
5528 len * sizeof (struct psymtab *));
5530 VEC_iterate (sig_type_ptr, tu_group->tus, i, iter);
5533 gdb_assert (iter->per_cu.is_debug_types);
5534 pst->dependencies[i] = iter->per_cu.v.psymtab;
5535 iter->type_unit_group = tu_group;
5538 VEC_free (sig_type_ptr, tu_group->tus);
5543 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5544 Build partial symbol tables for the .debug_types comp-units. */
5547 build_type_psymtabs (struct objfile *objfile)
5549 if (! create_all_type_units (objfile))
5552 build_type_unit_groups (build_type_psymtabs_reader, NULL);
5554 /* Now that all TUs have been processed we can fill in the dependencies. */
5555 htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups,
5556 build_type_psymtab_dependencies, NULL);
5559 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5562 psymtabs_addrmap_cleanup (void *o)
5564 struct objfile *objfile = o;
5566 objfile->psymtabs_addrmap = NULL;
5569 /* Compute the 'user' field for each psymtab in OBJFILE. */
5572 set_partial_user (struct objfile *objfile)
5576 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
5578 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
5579 struct partial_symtab *pst = per_cu->v.psymtab;
5585 for (j = 0; j < pst->number_of_dependencies; ++j)
5587 /* Set the 'user' field only if it is not already set. */
5588 if (pst->dependencies[j]->user == NULL)
5589 pst->dependencies[j]->user = pst;
5594 /* Build the partial symbol table by doing a quick pass through the
5595 .debug_info and .debug_abbrev sections. */
5598 dwarf2_build_psymtabs_hard (struct objfile *objfile)
5600 struct cleanup *back_to, *addrmap_cleanup;
5601 struct obstack temp_obstack;
5604 if (dwarf2_read_debug)
5606 fprintf_unfiltered (gdb_stdlog, "Building psymtabs of objfile %s ...\n",
5610 dwarf2_per_objfile->reading_partial_symbols = 1;
5612 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
5614 /* Any cached compilation units will be linked by the per-objfile
5615 read_in_chain. Make sure to free them when we're done. */
5616 back_to = make_cleanup (free_cached_comp_units, NULL);
5618 build_type_psymtabs (objfile);
5620 create_all_comp_units (objfile);
5622 /* Create a temporary address map on a temporary obstack. We later
5623 copy this to the final obstack. */
5624 obstack_init (&temp_obstack);
5625 make_cleanup_obstack_free (&temp_obstack);
5626 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
5627 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
5629 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
5631 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
5633 process_psymtab_comp_unit (per_cu, 0);
5636 set_partial_user (objfile);
5638 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
5639 &objfile->objfile_obstack);
5640 discard_cleanups (addrmap_cleanup);
5642 do_cleanups (back_to);
5644 if (dwarf2_read_debug)
5645 fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n",
5649 /* die_reader_func for load_partial_comp_unit. */
5652 load_partial_comp_unit_reader (const struct die_reader_specs *reader,
5654 struct die_info *comp_unit_die,
5658 struct dwarf2_cu *cu = reader->cu;
5660 prepare_one_comp_unit (cu, comp_unit_die, language_minimal);
5662 /* Check if comp unit has_children.
5663 If so, read the rest of the partial symbols from this comp unit.
5664 If not, there's no more debug_info for this comp unit. */
5666 load_partial_dies (reader, info_ptr, 0);
5669 /* Load the partial DIEs for a secondary CU into memory.
5670 This is also used when rereading a primary CU with load_all_dies. */
5673 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
5675 init_cutu_and_read_dies (this_cu, NULL, 1, 1,
5676 load_partial_comp_unit_reader, NULL);
5680 read_comp_units_from_section (struct objfile *objfile,
5681 struct dwarf2_section_info *section,
5682 unsigned int is_dwz,
5685 struct dwarf2_per_cu_data ***all_comp_units)
5688 bfd *abfd = section->asection->owner;
5690 dwarf2_read_section (objfile, section);
5692 info_ptr = section->buffer;
5694 while (info_ptr < section->buffer + section->size)
5696 unsigned int length, initial_length_size;
5697 struct dwarf2_per_cu_data *this_cu;
5700 offset.sect_off = info_ptr - section->buffer;
5702 /* Read just enough information to find out where the next
5703 compilation unit is. */
5704 length = read_initial_length (abfd, info_ptr, &initial_length_size);
5706 /* Save the compilation unit for later lookup. */
5707 this_cu = obstack_alloc (&objfile->objfile_obstack,
5708 sizeof (struct dwarf2_per_cu_data));
5709 memset (this_cu, 0, sizeof (*this_cu));
5710 this_cu->offset = offset;
5711 this_cu->length = length + initial_length_size;
5712 this_cu->is_dwz = is_dwz;
5713 this_cu->objfile = objfile;
5714 this_cu->section = section;
5716 if (*n_comp_units == *n_allocated)
5719 *all_comp_units = xrealloc (*all_comp_units,
5721 * sizeof (struct dwarf2_per_cu_data *));
5723 (*all_comp_units)[*n_comp_units] = this_cu;
5726 info_ptr = info_ptr + this_cu->length;
5730 /* Create a list of all compilation units in OBJFILE.
5731 This is only done for -readnow and building partial symtabs. */
5734 create_all_comp_units (struct objfile *objfile)
5738 struct dwarf2_per_cu_data **all_comp_units;
5742 all_comp_units = xmalloc (n_allocated
5743 * sizeof (struct dwarf2_per_cu_data *));
5745 read_comp_units_from_section (objfile, &dwarf2_per_objfile->info, 0,
5746 &n_allocated, &n_comp_units, &all_comp_units);
5748 if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
5750 struct dwz_file *dwz = dwarf2_get_dwz_file ();
5752 read_comp_units_from_section (objfile, &dwz->info, 1,
5753 &n_allocated, &n_comp_units,
5757 dwarf2_per_objfile->all_comp_units
5758 = obstack_alloc (&objfile->objfile_obstack,
5759 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
5760 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
5761 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
5762 xfree (all_comp_units);
5763 dwarf2_per_objfile->n_comp_units = n_comp_units;
5766 /* Process all loaded DIEs for compilation unit CU, starting at
5767 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5768 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5769 DW_AT_ranges). If NEED_PC is set, then this function will set
5770 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5771 and record the covered ranges in the addrmap. */
5774 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
5775 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
5777 struct partial_die_info *pdi;
5779 /* Now, march along the PDI's, descending into ones which have
5780 interesting children but skipping the children of the other ones,
5781 until we reach the end of the compilation unit. */
5787 fixup_partial_die (pdi, cu);
5789 /* Anonymous namespaces or modules have no name but have interesting
5790 children, so we need to look at them. Ditto for anonymous
5793 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
5794 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type
5795 || pdi->tag == DW_TAG_imported_unit)
5799 case DW_TAG_subprogram:
5800 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
5802 case DW_TAG_constant:
5803 case DW_TAG_variable:
5804 case DW_TAG_typedef:
5805 case DW_TAG_union_type:
5806 if (!pdi->is_declaration)
5808 add_partial_symbol (pdi, cu);
5811 case DW_TAG_class_type:
5812 case DW_TAG_interface_type:
5813 case DW_TAG_structure_type:
5814 if (!pdi->is_declaration)
5816 add_partial_symbol (pdi, cu);
5819 case DW_TAG_enumeration_type:
5820 if (!pdi->is_declaration)
5821 add_partial_enumeration (pdi, cu);
5823 case DW_TAG_base_type:
5824 case DW_TAG_subrange_type:
5825 /* File scope base type definitions are added to the partial
5827 add_partial_symbol (pdi, cu);
5829 case DW_TAG_namespace:
5830 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
5833 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
5835 case DW_TAG_imported_unit:
5837 struct dwarf2_per_cu_data *per_cu;
5839 /* For now we don't handle imported units in type units. */
5840 if (cu->per_cu->is_debug_types)
5842 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5843 " supported in type units [in module %s]"),
5847 per_cu = dwarf2_find_containing_comp_unit (pdi->d.offset,
5851 /* Go read the partial unit, if needed. */
5852 if (per_cu->v.psymtab == NULL)
5853 process_psymtab_comp_unit (per_cu, 1);
5855 VEC_safe_push (dwarf2_per_cu_ptr,
5856 cu->per_cu->imported_symtabs, per_cu);
5864 /* If the die has a sibling, skip to the sibling. */
5866 pdi = pdi->die_sibling;
5870 /* Functions used to compute the fully scoped name of a partial DIE.
5872 Normally, this is simple. For C++, the parent DIE's fully scoped
5873 name is concatenated with "::" and the partial DIE's name. For
5874 Java, the same thing occurs except that "." is used instead of "::".
5875 Enumerators are an exception; they use the scope of their parent
5876 enumeration type, i.e. the name of the enumeration type is not
5877 prepended to the enumerator.
5879 There are two complexities. One is DW_AT_specification; in this
5880 case "parent" means the parent of the target of the specification,
5881 instead of the direct parent of the DIE. The other is compilers
5882 which do not emit DW_TAG_namespace; in this case we try to guess
5883 the fully qualified name of structure types from their members'
5884 linkage names. This must be done using the DIE's children rather
5885 than the children of any DW_AT_specification target. We only need
5886 to do this for structures at the top level, i.e. if the target of
5887 any DW_AT_specification (if any; otherwise the DIE itself) does not
5890 /* Compute the scope prefix associated with PDI's parent, in
5891 compilation unit CU. The result will be allocated on CU's
5892 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5893 field. NULL is returned if no prefix is necessary. */
5895 partial_die_parent_scope (struct partial_die_info *pdi,
5896 struct dwarf2_cu *cu)
5898 const char *grandparent_scope;
5899 struct partial_die_info *parent, *real_pdi;
5901 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5902 then this means the parent of the specification DIE. */
5905 while (real_pdi->has_specification)
5906 real_pdi = find_partial_die (real_pdi->spec_offset,
5907 real_pdi->spec_is_dwz, cu);
5909 parent = real_pdi->die_parent;
5913 if (parent->scope_set)
5914 return parent->scope;
5916 fixup_partial_die (parent, cu);
5918 grandparent_scope = partial_die_parent_scope (parent, cu);
5920 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5921 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5922 Work around this problem here. */
5923 if (cu->language == language_cplus
5924 && parent->tag == DW_TAG_namespace
5925 && strcmp (parent->name, "::") == 0
5926 && grandparent_scope == NULL)
5928 parent->scope = NULL;
5929 parent->scope_set = 1;
5933 if (pdi->tag == DW_TAG_enumerator)
5934 /* Enumerators should not get the name of the enumeration as a prefix. */
5935 parent->scope = grandparent_scope;
5936 else if (parent->tag == DW_TAG_namespace
5937 || parent->tag == DW_TAG_module
5938 || parent->tag == DW_TAG_structure_type
5939 || parent->tag == DW_TAG_class_type
5940 || parent->tag == DW_TAG_interface_type
5941 || parent->tag == DW_TAG_union_type
5942 || parent->tag == DW_TAG_enumeration_type)
5944 if (grandparent_scope == NULL)
5945 parent->scope = parent->name;
5947 parent->scope = typename_concat (&cu->comp_unit_obstack,
5949 parent->name, 0, cu);
5953 /* FIXME drow/2004-04-01: What should we be doing with
5954 function-local names? For partial symbols, we should probably be
5956 complaint (&symfile_complaints,
5957 _("unhandled containing DIE tag %d for DIE at %d"),
5958 parent->tag, pdi->offset.sect_off);
5959 parent->scope = grandparent_scope;
5962 parent->scope_set = 1;
5963 return parent->scope;
5966 /* Return the fully scoped name associated with PDI, from compilation unit
5967 CU. The result will be allocated with malloc. */
5970 partial_die_full_name (struct partial_die_info *pdi,
5971 struct dwarf2_cu *cu)
5973 const char *parent_scope;
5975 /* If this is a template instantiation, we can not work out the
5976 template arguments from partial DIEs. So, unfortunately, we have
5977 to go through the full DIEs. At least any work we do building
5978 types here will be reused if full symbols are loaded later. */
5979 if (pdi->has_template_arguments)
5981 fixup_partial_die (pdi, cu);
5983 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
5985 struct die_info *die;
5986 struct attribute attr;
5987 struct dwarf2_cu *ref_cu = cu;
5989 /* DW_FORM_ref_addr is using section offset. */
5991 attr.form = DW_FORM_ref_addr;
5992 attr.u.unsnd = pdi->offset.sect_off;
5993 die = follow_die_ref (NULL, &attr, &ref_cu);
5995 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
5999 parent_scope = partial_die_parent_scope (pdi, cu);
6000 if (parent_scope == NULL)
6003 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
6007 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
6009 struct objfile *objfile = cu->objfile;
6011 const char *actual_name = NULL;
6013 char *built_actual_name;
6015 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6017 built_actual_name = partial_die_full_name (pdi, cu);
6018 if (built_actual_name != NULL)
6019 actual_name = built_actual_name;
6021 if (actual_name == NULL)
6022 actual_name = pdi->name;
6026 case DW_TAG_subprogram:
6027 if (pdi->is_external || cu->language == language_ada)
6029 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
6030 of the global scope. But in Ada, we want to be able to access
6031 nested procedures globally. So all Ada subprograms are stored
6032 in the global scope. */
6033 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
6034 mst_text, objfile); */
6035 add_psymbol_to_list (actual_name, strlen (actual_name),
6036 built_actual_name != NULL,
6037 VAR_DOMAIN, LOC_BLOCK,
6038 &objfile->global_psymbols,
6039 0, pdi->lowpc + baseaddr,
6040 cu->language, objfile);
6044 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
6045 mst_file_text, objfile); */
6046 add_psymbol_to_list (actual_name, strlen (actual_name),
6047 built_actual_name != NULL,
6048 VAR_DOMAIN, LOC_BLOCK,
6049 &objfile->static_psymbols,
6050 0, pdi->lowpc + baseaddr,
6051 cu->language, objfile);
6054 case DW_TAG_constant:
6056 struct psymbol_allocation_list *list;
6058 if (pdi->is_external)
6059 list = &objfile->global_psymbols;
6061 list = &objfile->static_psymbols;
6062 add_psymbol_to_list (actual_name, strlen (actual_name),
6063 built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
6064 list, 0, 0, cu->language, objfile);
6067 case DW_TAG_variable:
6069 addr = decode_locdesc (pdi->d.locdesc, cu);
6073 && !dwarf2_per_objfile->has_section_at_zero)
6075 /* A global or static variable may also have been stripped
6076 out by the linker if unused, in which case its address
6077 will be nullified; do not add such variables into partial
6078 symbol table then. */
6080 else if (pdi->is_external)
6083 Don't enter into the minimal symbol tables as there is
6084 a minimal symbol table entry from the ELF symbols already.
6085 Enter into partial symbol table if it has a location
6086 descriptor or a type.
6087 If the location descriptor is missing, new_symbol will create
6088 a LOC_UNRESOLVED symbol, the address of the variable will then
6089 be determined from the minimal symbol table whenever the variable
6091 The address for the partial symbol table entry is not
6092 used by GDB, but it comes in handy for debugging partial symbol
6095 if (pdi->d.locdesc || pdi->has_type)
6096 add_psymbol_to_list (actual_name, strlen (actual_name),
6097 built_actual_name != NULL,
6098 VAR_DOMAIN, LOC_STATIC,
6099 &objfile->global_psymbols,
6101 cu->language, objfile);
6105 /* Static Variable. Skip symbols without location descriptors. */
6106 if (pdi->d.locdesc == NULL)
6108 xfree (built_actual_name);
6111 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
6112 mst_file_data, objfile); */
6113 add_psymbol_to_list (actual_name, strlen (actual_name),
6114 built_actual_name != NULL,
6115 VAR_DOMAIN, LOC_STATIC,
6116 &objfile->static_psymbols,
6118 cu->language, objfile);
6121 case DW_TAG_typedef:
6122 case DW_TAG_base_type:
6123 case DW_TAG_subrange_type:
6124 add_psymbol_to_list (actual_name, strlen (actual_name),
6125 built_actual_name != NULL,
6126 VAR_DOMAIN, LOC_TYPEDEF,
6127 &objfile->static_psymbols,
6128 0, (CORE_ADDR) 0, cu->language, objfile);
6130 case DW_TAG_namespace:
6131 add_psymbol_to_list (actual_name, strlen (actual_name),
6132 built_actual_name != NULL,
6133 VAR_DOMAIN, LOC_TYPEDEF,
6134 &objfile->global_psymbols,
6135 0, (CORE_ADDR) 0, cu->language, objfile);
6137 case DW_TAG_class_type:
6138 case DW_TAG_interface_type:
6139 case DW_TAG_structure_type:
6140 case DW_TAG_union_type:
6141 case DW_TAG_enumeration_type:
6142 /* Skip external references. The DWARF standard says in the section
6143 about "Structure, Union, and Class Type Entries": "An incomplete
6144 structure, union or class type is represented by a structure,
6145 union or class entry that does not have a byte size attribute
6146 and that has a DW_AT_declaration attribute." */
6147 if (!pdi->has_byte_size && pdi->is_declaration)
6149 xfree (built_actual_name);
6153 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
6154 static vs. global. */
6155 add_psymbol_to_list (actual_name, strlen (actual_name),
6156 built_actual_name != NULL,
6157 STRUCT_DOMAIN, LOC_TYPEDEF,
6158 (cu->language == language_cplus
6159 || cu->language == language_java)
6160 ? &objfile->global_psymbols
6161 : &objfile->static_psymbols,
6162 0, (CORE_ADDR) 0, cu->language, objfile);
6165 case DW_TAG_enumerator:
6166 add_psymbol_to_list (actual_name, strlen (actual_name),
6167 built_actual_name != NULL,
6168 VAR_DOMAIN, LOC_CONST,
6169 (cu->language == language_cplus
6170 || cu->language == language_java)
6171 ? &objfile->global_psymbols
6172 : &objfile->static_psymbols,
6173 0, (CORE_ADDR) 0, cu->language, objfile);
6179 xfree (built_actual_name);
6182 /* Read a partial die corresponding to a namespace; also, add a symbol
6183 corresponding to that namespace to the symbol table. NAMESPACE is
6184 the name of the enclosing namespace. */
6187 add_partial_namespace (struct partial_die_info *pdi,
6188 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6189 int need_pc, struct dwarf2_cu *cu)
6191 /* Add a symbol for the namespace. */
6193 add_partial_symbol (pdi, cu);
6195 /* Now scan partial symbols in that namespace. */
6197 if (pdi->has_children)
6198 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
6201 /* Read a partial die corresponding to a Fortran module. */
6204 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
6205 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
6207 /* Now scan partial symbols in that module. */
6209 if (pdi->has_children)
6210 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
6213 /* Read a partial die corresponding to a subprogram and create a partial
6214 symbol for that subprogram. When the CU language allows it, this
6215 routine also defines a partial symbol for each nested subprogram
6216 that this subprogram contains.
6218 DIE my also be a lexical block, in which case we simply search
6219 recursively for suprograms defined inside that lexical block.
6220 Again, this is only performed when the CU language allows this
6221 type of definitions. */
6224 add_partial_subprogram (struct partial_die_info *pdi,
6225 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6226 int need_pc, struct dwarf2_cu *cu)
6228 if (pdi->tag == DW_TAG_subprogram)
6230 if (pdi->has_pc_info)
6232 if (pdi->lowpc < *lowpc)
6233 *lowpc = pdi->lowpc;
6234 if (pdi->highpc > *highpc)
6235 *highpc = pdi->highpc;
6239 struct objfile *objfile = cu->objfile;
6241 baseaddr = ANOFFSET (objfile->section_offsets,
6242 SECT_OFF_TEXT (objfile));
6243 addrmap_set_empty (objfile->psymtabs_addrmap,
6244 pdi->lowpc + baseaddr,
6245 pdi->highpc - 1 + baseaddr,
6246 cu->per_cu->v.psymtab);
6250 if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined))
6252 if (!pdi->is_declaration)
6253 /* Ignore subprogram DIEs that do not have a name, they are
6254 illegal. Do not emit a complaint at this point, we will
6255 do so when we convert this psymtab into a symtab. */
6257 add_partial_symbol (pdi, cu);
6261 if (! pdi->has_children)
6264 if (cu->language == language_ada)
6266 pdi = pdi->die_child;
6269 fixup_partial_die (pdi, cu);
6270 if (pdi->tag == DW_TAG_subprogram
6271 || pdi->tag == DW_TAG_lexical_block)
6272 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
6273 pdi = pdi->die_sibling;
6278 /* Read a partial die corresponding to an enumeration type. */
6281 add_partial_enumeration (struct partial_die_info *enum_pdi,
6282 struct dwarf2_cu *cu)
6284 struct partial_die_info *pdi;
6286 if (enum_pdi->name != NULL)
6287 add_partial_symbol (enum_pdi, cu);
6289 pdi = enum_pdi->die_child;
6292 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
6293 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
6295 add_partial_symbol (pdi, cu);
6296 pdi = pdi->die_sibling;
6300 /* Return the initial uleb128 in the die at INFO_PTR. */
6303 peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr)
6305 unsigned int bytes_read;
6307 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6310 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6311 Return the corresponding abbrev, or NULL if the number is zero (indicating
6312 an empty DIE). In either case *BYTES_READ will be set to the length of
6313 the initial number. */
6315 static struct abbrev_info *
6316 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
6317 struct dwarf2_cu *cu)
6319 bfd *abfd = cu->objfile->obfd;
6320 unsigned int abbrev_number;
6321 struct abbrev_info *abbrev;
6323 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
6325 if (abbrev_number == 0)
6328 abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number);
6331 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6332 abbrev_number, bfd_get_filename (abfd));
6338 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6339 Returns a pointer to the end of a series of DIEs, terminated by an empty
6340 DIE. Any children of the skipped DIEs will also be skipped. */
6343 skip_children (const struct die_reader_specs *reader, gdb_byte *info_ptr)
6345 struct dwarf2_cu *cu = reader->cu;
6346 struct abbrev_info *abbrev;
6347 unsigned int bytes_read;
6351 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
6353 return info_ptr + bytes_read;
6355 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
6359 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6360 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6361 abbrev corresponding to that skipped uleb128 should be passed in
6362 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6366 skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr,
6367 struct abbrev_info *abbrev)
6369 unsigned int bytes_read;
6370 struct attribute attr;
6371 bfd *abfd = reader->abfd;
6372 struct dwarf2_cu *cu = reader->cu;
6373 gdb_byte *buffer = reader->buffer;
6374 const gdb_byte *buffer_end = reader->buffer_end;
6375 gdb_byte *start_info_ptr = info_ptr;
6376 unsigned int form, i;
6378 for (i = 0; i < abbrev->num_attrs; i++)
6380 /* The only abbrev we care about is DW_AT_sibling. */
6381 if (abbrev->attrs[i].name == DW_AT_sibling)
6383 read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
6384 if (attr.form == DW_FORM_ref_addr)
6385 complaint (&symfile_complaints,
6386 _("ignoring absolute DW_AT_sibling"));
6388 return buffer + dwarf2_get_ref_die_offset (&attr).sect_off;
6391 /* If it isn't DW_AT_sibling, skip this attribute. */
6392 form = abbrev->attrs[i].form;
6396 case DW_FORM_ref_addr:
6397 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6398 and later it is offset sized. */
6399 if (cu->header.version == 2)
6400 info_ptr += cu->header.addr_size;
6402 info_ptr += cu->header.offset_size;
6404 case DW_FORM_GNU_ref_alt:
6405 info_ptr += cu->header.offset_size;
6408 info_ptr += cu->header.addr_size;
6415 case DW_FORM_flag_present:
6427 case DW_FORM_ref_sig8:
6430 case DW_FORM_string:
6431 read_direct_string (abfd, info_ptr, &bytes_read);
6432 info_ptr += bytes_read;
6434 case DW_FORM_sec_offset:
6436 case DW_FORM_GNU_strp_alt:
6437 info_ptr += cu->header.offset_size;
6439 case DW_FORM_exprloc:
6441 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6442 info_ptr += bytes_read;
6444 case DW_FORM_block1:
6445 info_ptr += 1 + read_1_byte (abfd, info_ptr);
6447 case DW_FORM_block2:
6448 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
6450 case DW_FORM_block4:
6451 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
6455 case DW_FORM_ref_udata:
6456 case DW_FORM_GNU_addr_index:
6457 case DW_FORM_GNU_str_index:
6458 info_ptr = (gdb_byte *) safe_skip_leb128 (info_ptr, buffer_end);
6460 case DW_FORM_indirect:
6461 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6462 info_ptr += bytes_read;
6463 /* We need to continue parsing from here, so just go back to
6465 goto skip_attribute;
6468 error (_("Dwarf Error: Cannot handle %s "
6469 "in DWARF reader [in module %s]"),
6470 dwarf_form_name (form),
6471 bfd_get_filename (abfd));
6475 if (abbrev->has_children)
6476 return skip_children (reader, info_ptr);
6481 /* Locate ORIG_PDI's sibling.
6482 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6485 locate_pdi_sibling (const struct die_reader_specs *reader,
6486 struct partial_die_info *orig_pdi,
6489 /* Do we know the sibling already? */
6491 if (orig_pdi->sibling)
6492 return orig_pdi->sibling;
6494 /* Are there any children to deal with? */
6496 if (!orig_pdi->has_children)
6499 /* Skip the children the long way. */
6501 return skip_children (reader, info_ptr);
6504 /* Expand this partial symbol table into a full symbol table. SELF is
6508 dwarf2_read_symtab (struct partial_symtab *self,
6509 struct objfile *objfile)
6513 warning (_("bug: psymtab for %s is already read in."),
6520 printf_filtered (_("Reading in symbols for %s..."),
6522 gdb_flush (gdb_stdout);
6525 /* Restore our global data. */
6526 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
6528 /* If this psymtab is constructed from a debug-only objfile, the
6529 has_section_at_zero flag will not necessarily be correct. We
6530 can get the correct value for this flag by looking at the data
6531 associated with the (presumably stripped) associated objfile. */
6532 if (objfile->separate_debug_objfile_backlink)
6534 struct dwarf2_per_objfile *dpo_backlink
6535 = objfile_data (objfile->separate_debug_objfile_backlink,
6536 dwarf2_objfile_data_key);
6538 dwarf2_per_objfile->has_section_at_zero
6539 = dpo_backlink->has_section_at_zero;
6542 dwarf2_per_objfile->reading_partial_symbols = 0;
6544 psymtab_to_symtab_1 (self);
6546 /* Finish up the debug error message. */
6548 printf_filtered (_("done.\n"));
6551 process_cu_includes ();
6554 /* Reading in full CUs. */
6556 /* Add PER_CU to the queue. */
6559 queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
6560 enum language pretend_language)
6562 struct dwarf2_queue_item *item;
6565 item = xmalloc (sizeof (*item));
6566 item->per_cu = per_cu;
6567 item->pretend_language = pretend_language;
6570 if (dwarf2_queue == NULL)
6571 dwarf2_queue = item;
6573 dwarf2_queue_tail->next = item;
6575 dwarf2_queue_tail = item;
6578 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6579 unit and add it to our queue.
6580 The result is non-zero if PER_CU was queued, otherwise the result is zero
6581 meaning either PER_CU is already queued or it is already loaded. */
6584 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
6585 struct dwarf2_per_cu_data *per_cu,
6586 enum language pretend_language)
6588 /* We may arrive here during partial symbol reading, if we need full
6589 DIEs to process an unusual case (e.g. template arguments). Do
6590 not queue PER_CU, just tell our caller to load its DIEs. */
6591 if (dwarf2_per_objfile->reading_partial_symbols)
6593 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
6598 /* Mark the dependence relation so that we don't flush PER_CU
6600 dwarf2_add_dependence (this_cu, per_cu);
6602 /* If it's already on the queue, we have nothing to do. */
6606 /* If the compilation unit is already loaded, just mark it as
6608 if (per_cu->cu != NULL)
6610 per_cu->cu->last_used = 0;
6614 /* Add it to the queue. */
6615 queue_comp_unit (per_cu, pretend_language);
6620 /* Process the queue. */
6623 process_queue (void)
6625 struct dwarf2_queue_item *item, *next_item;
6627 if (dwarf2_read_debug)
6629 fprintf_unfiltered (gdb_stdlog,
6630 "Expanding one or more symtabs of objfile %s ...\n",
6631 dwarf2_per_objfile->objfile->name);
6634 /* The queue starts out with one item, but following a DIE reference
6635 may load a new CU, adding it to the end of the queue. */
6636 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
6638 if (dwarf2_per_objfile->using_index
6639 ? !item->per_cu->v.quick->symtab
6640 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
6642 struct dwarf2_per_cu_data *per_cu = item->per_cu;
6644 if (dwarf2_read_debug)
6646 fprintf_unfiltered (gdb_stdlog,
6647 "Expanding symtab of %s at offset 0x%x\n",
6648 per_cu->is_debug_types ? "TU" : "CU",
6649 per_cu->offset.sect_off);
6652 if (per_cu->is_debug_types)
6653 process_full_type_unit (per_cu, item->pretend_language);
6655 process_full_comp_unit (per_cu, item->pretend_language);
6657 if (dwarf2_read_debug)
6659 fprintf_unfiltered (gdb_stdlog,
6660 "Done expanding %s at offset 0x%x\n",
6661 per_cu->is_debug_types ? "TU" : "CU",
6662 per_cu->offset.sect_off);
6666 item->per_cu->queued = 0;
6667 next_item = item->next;
6671 dwarf2_queue_tail = NULL;
6673 if (dwarf2_read_debug)
6675 fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n",
6676 dwarf2_per_objfile->objfile->name);
6680 /* Free all allocated queue entries. This function only releases anything if
6681 an error was thrown; if the queue was processed then it would have been
6682 freed as we went along. */
6685 dwarf2_release_queue (void *dummy)
6687 struct dwarf2_queue_item *item, *last;
6689 item = dwarf2_queue;
6692 /* Anything still marked queued is likely to be in an
6693 inconsistent state, so discard it. */
6694 if (item->per_cu->queued)
6696 if (item->per_cu->cu != NULL)
6697 free_one_cached_comp_unit (item->per_cu);
6698 item->per_cu->queued = 0;
6706 dwarf2_queue = dwarf2_queue_tail = NULL;
6709 /* Read in full symbols for PST, and anything it depends on. */
6712 psymtab_to_symtab_1 (struct partial_symtab *pst)
6714 struct dwarf2_per_cu_data *per_cu;
6720 for (i = 0; i < pst->number_of_dependencies; i++)
6721 if (!pst->dependencies[i]->readin
6722 && pst->dependencies[i]->user == NULL)
6724 /* Inform about additional files that need to be read in. */
6727 /* FIXME: i18n: Need to make this a single string. */
6728 fputs_filtered (" ", gdb_stdout);
6730 fputs_filtered ("and ", gdb_stdout);
6732 printf_filtered ("%s...", pst->dependencies[i]->filename);
6733 wrap_here (""); /* Flush output. */
6734 gdb_flush (gdb_stdout);
6736 psymtab_to_symtab_1 (pst->dependencies[i]);
6739 per_cu = pst->read_symtab_private;
6743 /* It's an include file, no symbols to read for it.
6744 Everything is in the parent symtab. */
6749 dw2_do_instantiate_symtab (per_cu);
6752 /* Trivial hash function for die_info: the hash value of a DIE
6753 is its offset in .debug_info for this objfile. */
6756 die_hash (const void *item)
6758 const struct die_info *die = item;
6760 return die->offset.sect_off;
6763 /* Trivial comparison function for die_info structures: two DIEs
6764 are equal if they have the same offset. */
6767 die_eq (const void *item_lhs, const void *item_rhs)
6769 const struct die_info *die_lhs = item_lhs;
6770 const struct die_info *die_rhs = item_rhs;
6772 return die_lhs->offset.sect_off == die_rhs->offset.sect_off;
6775 /* die_reader_func for load_full_comp_unit.
6776 This is identical to read_signatured_type_reader,
6777 but is kept separate for now. */
6780 load_full_comp_unit_reader (const struct die_reader_specs *reader,
6782 struct die_info *comp_unit_die,
6786 struct dwarf2_cu *cu = reader->cu;
6787 enum language *language_ptr = data;
6789 gdb_assert (cu->die_hash == NULL);
6791 htab_create_alloc_ex (cu->header.length / 12,
6795 &cu->comp_unit_obstack,
6796 hashtab_obstack_allocate,
6797 dummy_obstack_deallocate);
6800 comp_unit_die->child = read_die_and_siblings (reader, info_ptr,
6801 &info_ptr, comp_unit_die);
6802 cu->dies = comp_unit_die;
6803 /* comp_unit_die is not stored in die_hash, no need. */
6805 /* We try not to read any attributes in this function, because not
6806 all CUs needed for references have been loaded yet, and symbol
6807 table processing isn't initialized. But we have to set the CU language,
6808 or we won't be able to build types correctly.
6809 Similarly, if we do not read the producer, we can not apply
6810 producer-specific interpretation. */
6811 prepare_one_comp_unit (cu, cu->dies, *language_ptr);
6814 /* Load the DIEs associated with PER_CU into memory. */
6817 load_full_comp_unit (struct dwarf2_per_cu_data *this_cu,
6818 enum language pretend_language)
6820 gdb_assert (! this_cu->is_debug_types);
6822 init_cutu_and_read_dies (this_cu, NULL, 1, 1,
6823 load_full_comp_unit_reader, &pretend_language);
6826 /* Add a DIE to the delayed physname list. */
6829 add_to_method_list (struct type *type, int fnfield_index, int index,
6830 const char *name, struct die_info *die,
6831 struct dwarf2_cu *cu)
6833 struct delayed_method_info mi;
6835 mi.fnfield_index = fnfield_index;
6839 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
6842 /* A cleanup for freeing the delayed method list. */
6845 free_delayed_list (void *ptr)
6847 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
6848 if (cu->method_list != NULL)
6850 VEC_free (delayed_method_info, cu->method_list);
6851 cu->method_list = NULL;
6855 /* Compute the physnames of any methods on the CU's method list.
6857 The computation of method physnames is delayed in order to avoid the
6858 (bad) condition that one of the method's formal parameters is of an as yet
6862 compute_delayed_physnames (struct dwarf2_cu *cu)
6865 struct delayed_method_info *mi;
6866 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
6868 const char *physname;
6869 struct fn_fieldlist *fn_flp
6870 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
6871 physname = dwarf2_physname (mi->name, mi->die, cu);
6872 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
6876 /* Go objects should be embedded in a DW_TAG_module DIE,
6877 and it's not clear if/how imported objects will appear.
6878 To keep Go support simple until that's worked out,
6879 go back through what we've read and create something usable.
6880 We could do this while processing each DIE, and feels kinda cleaner,
6881 but that way is more invasive.
6882 This is to, for example, allow the user to type "p var" or "b main"
6883 without having to specify the package name, and allow lookups
6884 of module.object to work in contexts that use the expression
6888 fixup_go_packaging (struct dwarf2_cu *cu)
6890 char *package_name = NULL;
6891 struct pending *list;
6894 for (list = global_symbols; list != NULL; list = list->next)
6896 for (i = 0; i < list->nsyms; ++i)
6898 struct symbol *sym = list->symbol[i];
6900 if (SYMBOL_LANGUAGE (sym) == language_go
6901 && SYMBOL_CLASS (sym) == LOC_BLOCK)
6903 char *this_package_name = go_symbol_package_name (sym);
6905 if (this_package_name == NULL)
6907 if (package_name == NULL)
6908 package_name = this_package_name;
6911 if (strcmp (package_name, this_package_name) != 0)
6912 complaint (&symfile_complaints,
6913 _("Symtab %s has objects from two different Go packages: %s and %s"),
6914 (SYMBOL_SYMTAB (sym)
6915 ? symtab_to_filename_for_display (SYMBOL_SYMTAB (sym))
6916 : cu->objfile->name),
6917 this_package_name, package_name);
6918 xfree (this_package_name);
6924 if (package_name != NULL)
6926 struct objfile *objfile = cu->objfile;
6927 const char *saved_package_name = obstack_copy0 (&objfile->objfile_obstack,
6929 strlen (package_name));
6930 struct type *type = init_type (TYPE_CODE_MODULE, 0, 0,
6931 saved_package_name, objfile);
6934 TYPE_TAG_NAME (type) = TYPE_NAME (type);
6936 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
6937 SYMBOL_SET_LANGUAGE (sym, language_go);
6938 SYMBOL_SET_NAMES (sym, saved_package_name,
6939 strlen (saved_package_name), 0, objfile);
6940 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6941 e.g., "main" finds the "main" module and not C's main(). */
6942 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
6943 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
6944 SYMBOL_TYPE (sym) = type;
6946 add_symbol_to_list (sym, &global_symbols);
6948 xfree (package_name);
6952 /* Return the symtab for PER_CU. This works properly regardless of
6953 whether we're using the index or psymtabs. */
6955 static struct symtab *
6956 get_symtab (struct dwarf2_per_cu_data *per_cu)
6958 return (dwarf2_per_objfile->using_index
6959 ? per_cu->v.quick->symtab
6960 : per_cu->v.psymtab->symtab);
6963 /* A helper function for computing the list of all symbol tables
6964 included by PER_CU. */
6967 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr) **result,
6968 htab_t all_children,
6969 struct dwarf2_per_cu_data *per_cu)
6973 struct dwarf2_per_cu_data *iter;
6975 slot = htab_find_slot (all_children, per_cu, INSERT);
6978 /* This inclusion and its children have been processed. */
6983 /* Only add a CU if it has a symbol table. */
6984 if (get_symtab (per_cu) != NULL)
6985 VEC_safe_push (dwarf2_per_cu_ptr, *result, per_cu);
6988 VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter);
6990 recursively_compute_inclusions (result, all_children, iter);
6993 /* Compute the symtab 'includes' fields for the symtab related to
6997 compute_symtab_includes (struct dwarf2_per_cu_data *per_cu)
6999 gdb_assert (! per_cu->is_debug_types);
7001 if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs))
7004 struct dwarf2_per_cu_data *iter;
7005 VEC (dwarf2_per_cu_ptr) *result_children = NULL;
7006 htab_t all_children;
7007 struct symtab *symtab = get_symtab (per_cu);
7009 /* If we don't have a symtab, we can just skip this case. */
7013 all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
7014 NULL, xcalloc, xfree);
7017 VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs,
7020 recursively_compute_inclusions (&result_children, all_children, iter);
7022 /* Now we have a transitive closure of all the included CUs, and
7023 for .gdb_index version 7 the included TUs, so we can convert it
7024 to a list of symtabs. */
7025 len = VEC_length (dwarf2_per_cu_ptr, result_children);
7027 = obstack_alloc (&dwarf2_per_objfile->objfile->objfile_obstack,
7028 (len + 1) * sizeof (struct symtab *));
7030 VEC_iterate (dwarf2_per_cu_ptr, result_children, ix, iter);
7032 symtab->includes[ix] = get_symtab (iter);
7033 symtab->includes[len] = NULL;
7035 VEC_free (dwarf2_per_cu_ptr, result_children);
7036 htab_delete (all_children);
7040 /* Compute the 'includes' field for the symtabs of all the CUs we just
7044 process_cu_includes (void)
7047 struct dwarf2_per_cu_data *iter;
7050 VEC_iterate (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus,
7054 if (! iter->is_debug_types)
7055 compute_symtab_includes (iter);
7058 VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus);
7061 /* Generate full symbol information for PER_CU, whose DIEs have
7062 already been loaded into memory. */
7065 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
7066 enum language pretend_language)
7068 struct dwarf2_cu *cu = per_cu->cu;
7069 struct objfile *objfile = per_cu->objfile;
7070 CORE_ADDR lowpc, highpc;
7071 struct symtab *symtab;
7072 struct cleanup *back_to, *delayed_list_cleanup;
7074 struct block *static_block;
7076 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
7079 back_to = make_cleanup (really_free_pendings, NULL);
7080 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
7082 cu->list_in_scope = &file_symbols;
7084 cu->language = pretend_language;
7085 cu->language_defn = language_def (cu->language);
7087 /* Do line number decoding in read_file_scope () */
7088 process_die (cu->dies, cu);
7090 /* For now fudge the Go package. */
7091 if (cu->language == language_go)
7092 fixup_go_packaging (cu);
7094 /* Now that we have processed all the DIEs in the CU, all the types
7095 should be complete, and it should now be safe to compute all of the
7097 compute_delayed_physnames (cu);
7098 do_cleanups (delayed_list_cleanup);
7100 /* Some compilers don't define a DW_AT_high_pc attribute for the
7101 compilation unit. If the DW_AT_high_pc is missing, synthesize
7102 it, by scanning the DIE's below the compilation unit. */
7103 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
7106 = end_symtab_get_static_block (highpc + baseaddr, objfile, 0,
7107 per_cu->imported_symtabs != NULL);
7109 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
7110 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
7111 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
7112 addrmap to help ensure it has an accurate map of pc values belonging to
7114 dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu);
7116 symtab = end_symtab_from_static_block (static_block, objfile,
7117 SECT_OFF_TEXT (objfile), 0);
7121 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
7123 /* Set symtab language to language from DW_AT_language. If the
7124 compilation is from a C file generated by language preprocessors, do
7125 not set the language if it was already deduced by start_subfile. */
7126 if (!(cu->language == language_c && symtab->language != language_c))
7127 symtab->language = cu->language;
7129 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
7130 produce DW_AT_location with location lists but it can be possibly
7131 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
7132 there were bugs in prologue debug info, fixed later in GCC-4.5
7133 by "unwind info for epilogues" patch (which is not directly related).
7135 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
7136 needed, it would be wrong due to missing DW_AT_producer there.
7138 Still one can confuse GDB by using non-standard GCC compilation
7139 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
7141 if (cu->has_loclist && gcc_4_minor >= 5)
7142 symtab->locations_valid = 1;
7144 if (gcc_4_minor >= 5)
7145 symtab->epilogue_unwind_valid = 1;
7147 symtab->call_site_htab = cu->call_site_htab;
7150 if (dwarf2_per_objfile->using_index)
7151 per_cu->v.quick->symtab = symtab;
7154 struct partial_symtab *pst = per_cu->v.psymtab;
7155 pst->symtab = symtab;
7159 /* Push it for inclusion processing later. */
7160 VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu);
7162 do_cleanups (back_to);
7165 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7166 already been loaded into memory. */
7169 process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
7170 enum language pretend_language)
7172 struct dwarf2_cu *cu = per_cu->cu;
7173 struct objfile *objfile = per_cu->objfile;
7174 struct symtab *symtab;
7175 struct cleanup *back_to, *delayed_list_cleanup;
7176 struct signatured_type *sig_type;
7178 gdb_assert (per_cu->is_debug_types);
7179 sig_type = (struct signatured_type *) per_cu;
7182 back_to = make_cleanup (really_free_pendings, NULL);
7183 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
7185 cu->list_in_scope = &file_symbols;
7187 cu->language = pretend_language;
7188 cu->language_defn = language_def (cu->language);
7190 /* The symbol tables are set up in read_type_unit_scope. */
7191 process_die (cu->dies, cu);
7193 /* For now fudge the Go package. */
7194 if (cu->language == language_go)
7195 fixup_go_packaging (cu);
7197 /* Now that we have processed all the DIEs in the CU, all the types
7198 should be complete, and it should now be safe to compute all of the
7200 compute_delayed_physnames (cu);
7201 do_cleanups (delayed_list_cleanup);
7203 /* TUs share symbol tables.
7204 If this is the first TU to use this symtab, complete the construction
7205 of it with end_expandable_symtab. Otherwise, complete the addition of
7206 this TU's symbols to the existing symtab. */
7207 if (sig_type->type_unit_group->primary_symtab == NULL)
7209 symtab = end_expandable_symtab (0, objfile, SECT_OFF_TEXT (objfile));
7210 sig_type->type_unit_group->primary_symtab = symtab;
7214 /* Set symtab language to language from DW_AT_language. If the
7215 compilation is from a C file generated by language preprocessors,
7216 do not set the language if it was already deduced by
7218 if (!(cu->language == language_c && symtab->language != language_c))
7219 symtab->language = cu->language;
7224 augment_type_symtab (objfile,
7225 sig_type->type_unit_group->primary_symtab);
7226 symtab = sig_type->type_unit_group->primary_symtab;
7229 if (dwarf2_per_objfile->using_index)
7230 per_cu->v.quick->symtab = symtab;
7233 struct partial_symtab *pst = per_cu->v.psymtab;
7234 pst->symtab = symtab;
7238 do_cleanups (back_to);
7241 /* Process an imported unit DIE. */
7244 process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
7246 struct attribute *attr;
7248 /* For now we don't handle imported units in type units. */
7249 if (cu->per_cu->is_debug_types)
7251 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7252 " supported in type units [in module %s]"),
7256 attr = dwarf2_attr (die, DW_AT_import, cu);
7259 struct dwarf2_per_cu_data *per_cu;
7260 struct symtab *imported_symtab;
7264 offset = dwarf2_get_ref_die_offset (attr);
7265 is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
7266 per_cu = dwarf2_find_containing_comp_unit (offset, is_dwz, cu->objfile);
7268 /* Queue the unit, if needed. */
7269 if (maybe_queue_comp_unit (cu, per_cu, cu->language))
7270 load_full_comp_unit (per_cu, cu->language);
7272 VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
7277 /* Process a die and its children. */
7280 process_die (struct die_info *die, struct dwarf2_cu *cu)
7284 case DW_TAG_padding:
7286 case DW_TAG_compile_unit:
7287 case DW_TAG_partial_unit:
7288 read_file_scope (die, cu);
7290 case DW_TAG_type_unit:
7291 read_type_unit_scope (die, cu);
7293 case DW_TAG_subprogram:
7294 case DW_TAG_inlined_subroutine:
7295 read_func_scope (die, cu);
7297 case DW_TAG_lexical_block:
7298 case DW_TAG_try_block:
7299 case DW_TAG_catch_block:
7300 read_lexical_block_scope (die, cu);
7302 case DW_TAG_GNU_call_site:
7303 read_call_site_scope (die, cu);
7305 case DW_TAG_class_type:
7306 case DW_TAG_interface_type:
7307 case DW_TAG_structure_type:
7308 case DW_TAG_union_type:
7309 process_structure_scope (die, cu);
7311 case DW_TAG_enumeration_type:
7312 process_enumeration_scope (die, cu);
7315 /* These dies have a type, but processing them does not create
7316 a symbol or recurse to process the children. Therefore we can
7317 read them on-demand through read_type_die. */
7318 case DW_TAG_subroutine_type:
7319 case DW_TAG_set_type:
7320 case DW_TAG_array_type:
7321 case DW_TAG_pointer_type:
7322 case DW_TAG_ptr_to_member_type:
7323 case DW_TAG_reference_type:
7324 case DW_TAG_string_type:
7327 case DW_TAG_base_type:
7328 case DW_TAG_subrange_type:
7329 case DW_TAG_typedef:
7330 /* Add a typedef symbol for the type definition, if it has a
7332 new_symbol (die, read_type_die (die, cu), cu);
7334 case DW_TAG_common_block:
7335 read_common_block (die, cu);
7337 case DW_TAG_common_inclusion:
7339 case DW_TAG_namespace:
7340 cu->processing_has_namespace_info = 1;
7341 read_namespace (die, cu);
7344 cu->processing_has_namespace_info = 1;
7345 read_module (die, cu);
7347 case DW_TAG_imported_declaration:
7348 case DW_TAG_imported_module:
7349 cu->processing_has_namespace_info = 1;
7350 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
7351 || cu->language != language_fortran))
7352 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
7353 dwarf_tag_name (die->tag));
7354 read_import_statement (die, cu);
7357 case DW_TAG_imported_unit:
7358 process_imported_unit_die (die, cu);
7362 new_symbol (die, NULL, cu);
7367 /* DWARF name computation. */
7369 /* A helper function for dwarf2_compute_name which determines whether DIE
7370 needs to have the name of the scope prepended to the name listed in the
7374 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
7376 struct attribute *attr;
7380 case DW_TAG_namespace:
7381 case DW_TAG_typedef:
7382 case DW_TAG_class_type:
7383 case DW_TAG_interface_type:
7384 case DW_TAG_structure_type:
7385 case DW_TAG_union_type:
7386 case DW_TAG_enumeration_type:
7387 case DW_TAG_enumerator:
7388 case DW_TAG_subprogram:
7392 case DW_TAG_variable:
7393 case DW_TAG_constant:
7394 /* We only need to prefix "globally" visible variables. These include
7395 any variable marked with DW_AT_external or any variable that
7396 lives in a namespace. [Variables in anonymous namespaces
7397 require prefixing, but they are not DW_AT_external.] */
7399 if (dwarf2_attr (die, DW_AT_specification, cu))
7401 struct dwarf2_cu *spec_cu = cu;
7403 return die_needs_namespace (die_specification (die, &spec_cu),
7407 attr = dwarf2_attr (die, DW_AT_external, cu);
7408 if (attr == NULL && die->parent->tag != DW_TAG_namespace
7409 && die->parent->tag != DW_TAG_module)
7411 /* A variable in a lexical block of some kind does not need a
7412 namespace, even though in C++ such variables may be external
7413 and have a mangled name. */
7414 if (die->parent->tag == DW_TAG_lexical_block
7415 || die->parent->tag == DW_TAG_try_block
7416 || die->parent->tag == DW_TAG_catch_block
7417 || die->parent->tag == DW_TAG_subprogram)
7426 /* Retrieve the last character from a mem_file. */
7429 do_ui_file_peek_last (void *object, const char *buffer, long length)
7431 char *last_char_p = (char *) object;
7434 *last_char_p = buffer[length - 1];
7437 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7438 compute the physname for the object, which include a method's:
7439 - formal parameters (C++/Java),
7440 - receiver type (Go),
7441 - return type (Java).
7443 The term "physname" is a bit confusing.
7444 For C++, for example, it is the demangled name.
7445 For Go, for example, it's the mangled name.
7447 For Ada, return the DIE's linkage name rather than the fully qualified
7448 name. PHYSNAME is ignored..
7450 The result is allocated on the objfile_obstack and canonicalized. */
7453 dwarf2_compute_name (const char *name,
7454 struct die_info *die, struct dwarf2_cu *cu,
7457 struct objfile *objfile = cu->objfile;
7460 name = dwarf2_name (die, cu);
7462 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7463 compute it by typename_concat inside GDB. */
7464 if (cu->language == language_ada
7465 || (cu->language == language_fortran && physname))
7467 /* For Ada unit, we prefer the linkage name over the name, as
7468 the former contains the exported name, which the user expects
7469 to be able to reference. Ideally, we want the user to be able
7470 to reference this entity using either natural or linkage name,
7471 but we haven't started looking at this enhancement yet. */
7472 struct attribute *attr;
7474 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
7476 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7477 if (attr && DW_STRING (attr))
7478 return DW_STRING (attr);
7481 /* These are the only languages we know how to qualify names in. */
7483 && (cu->language == language_cplus || cu->language == language_java
7484 || cu->language == language_fortran))
7486 if (die_needs_namespace (die, cu))
7490 struct ui_file *buf;
7492 prefix = determine_prefix (die, cu);
7493 buf = mem_fileopen ();
7494 if (*prefix != '\0')
7496 char *prefixed_name = typename_concat (NULL, prefix, name,
7499 fputs_unfiltered (prefixed_name, buf);
7500 xfree (prefixed_name);
7503 fputs_unfiltered (name, buf);
7505 /* Template parameters may be specified in the DIE's DW_AT_name, or
7506 as children with DW_TAG_template_type_param or
7507 DW_TAG_value_type_param. If the latter, add them to the name
7508 here. If the name already has template parameters, then
7509 skip this step; some versions of GCC emit both, and
7510 it is more efficient to use the pre-computed name.
7512 Something to keep in mind about this process: it is very
7513 unlikely, or in some cases downright impossible, to produce
7514 something that will match the mangled name of a function.
7515 If the definition of the function has the same debug info,
7516 we should be able to match up with it anyway. But fallbacks
7517 using the minimal symbol, for instance to find a method
7518 implemented in a stripped copy of libstdc++, will not work.
7519 If we do not have debug info for the definition, we will have to
7520 match them up some other way.
7522 When we do name matching there is a related problem with function
7523 templates; two instantiated function templates are allowed to
7524 differ only by their return types, which we do not add here. */
7526 if (cu->language == language_cplus && strchr (name, '<') == NULL)
7528 struct attribute *attr;
7529 struct die_info *child;
7532 die->building_fullname = 1;
7534 for (child = die->child; child != NULL; child = child->sibling)
7539 struct dwarf2_locexpr_baton *baton;
7542 if (child->tag != DW_TAG_template_type_param
7543 && child->tag != DW_TAG_template_value_param)
7548 fputs_unfiltered ("<", buf);
7552 fputs_unfiltered (", ", buf);
7554 attr = dwarf2_attr (child, DW_AT_type, cu);
7557 complaint (&symfile_complaints,
7558 _("template parameter missing DW_AT_type"));
7559 fputs_unfiltered ("UNKNOWN_TYPE", buf);
7562 type = die_type (child, cu);
7564 if (child->tag == DW_TAG_template_type_param)
7566 c_print_type (type, "", buf, -1, 0, &type_print_raw_options);
7570 attr = dwarf2_attr (child, DW_AT_const_value, cu);
7573 complaint (&symfile_complaints,
7574 _("template parameter missing "
7575 "DW_AT_const_value"));
7576 fputs_unfiltered ("UNKNOWN_VALUE", buf);
7580 dwarf2_const_value_attr (attr, type, name,
7581 &cu->comp_unit_obstack, cu,
7582 &value, &bytes, &baton);
7584 if (TYPE_NOSIGN (type))
7585 /* GDB prints characters as NUMBER 'CHAR'. If that's
7586 changed, this can use value_print instead. */
7587 c_printchar (value, type, buf);
7590 struct value_print_options opts;
7593 v = dwarf2_evaluate_loc_desc (type, NULL,
7597 else if (bytes != NULL)
7599 v = allocate_value (type);
7600 memcpy (value_contents_writeable (v), bytes,
7601 TYPE_LENGTH (type));
7604 v = value_from_longest (type, value);
7606 /* Specify decimal so that we do not depend on
7608 get_formatted_print_options (&opts, 'd');
7610 value_print (v, buf, &opts);
7616 die->building_fullname = 0;
7620 /* Close the argument list, with a space if necessary
7621 (nested templates). */
7622 char last_char = '\0';
7623 ui_file_put (buf, do_ui_file_peek_last, &last_char);
7624 if (last_char == '>')
7625 fputs_unfiltered (" >", buf);
7627 fputs_unfiltered (">", buf);
7631 /* For Java and C++ methods, append formal parameter type
7632 information, if PHYSNAME. */
7634 if (physname && die->tag == DW_TAG_subprogram
7635 && (cu->language == language_cplus
7636 || cu->language == language_java))
7638 struct type *type = read_type_die (die, cu);
7640 c_type_print_args (type, buf, 1, cu->language,
7641 &type_print_raw_options);
7643 if (cu->language == language_java)
7645 /* For java, we must append the return type to method
7647 if (die->tag == DW_TAG_subprogram)
7648 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
7649 0, 0, &type_print_raw_options);
7651 else if (cu->language == language_cplus)
7653 /* Assume that an artificial first parameter is
7654 "this", but do not crash if it is not. RealView
7655 marks unnamed (and thus unused) parameters as
7656 artificial; there is no way to differentiate
7658 if (TYPE_NFIELDS (type) > 0
7659 && TYPE_FIELD_ARTIFICIAL (type, 0)
7660 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
7661 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
7663 fputs_unfiltered (" const", buf);
7667 name = ui_file_obsavestring (buf, &objfile->objfile_obstack,
7669 ui_file_delete (buf);
7671 if (cu->language == language_cplus)
7674 = dwarf2_canonicalize_name (name, cu,
7675 &objfile->objfile_obstack);
7686 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7687 If scope qualifiers are appropriate they will be added. The result
7688 will be allocated on the objfile_obstack, or NULL if the DIE does
7689 not have a name. NAME may either be from a previous call to
7690 dwarf2_name or NULL.
7692 The output string will be canonicalized (if C++/Java). */
7695 dwarf2_full_name (const char *name, struct die_info *die, struct dwarf2_cu *cu)
7697 return dwarf2_compute_name (name, die, cu, 0);
7700 /* Construct a physname for the given DIE in CU. NAME may either be
7701 from a previous call to dwarf2_name or NULL. The result will be
7702 allocated on the objfile_objstack or NULL if the DIE does not have a
7705 The output string will be canonicalized (if C++/Java). */
7708 dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
7710 struct objfile *objfile = cu->objfile;
7711 struct attribute *attr;
7712 const char *retval, *mangled = NULL, *canon = NULL;
7713 struct cleanup *back_to;
7716 /* In this case dwarf2_compute_name is just a shortcut not building anything
7718 if (!die_needs_namespace (die, cu))
7719 return dwarf2_compute_name (name, die, cu, 1);
7721 back_to = make_cleanup (null_cleanup, NULL);
7723 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
7725 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7727 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7729 if (attr && DW_STRING (attr))
7733 mangled = DW_STRING (attr);
7735 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7736 type. It is easier for GDB users to search for such functions as
7737 `name(params)' than `long name(params)'. In such case the minimal
7738 symbol names do not match the full symbol names but for template
7739 functions there is never a need to look up their definition from their
7740 declaration so the only disadvantage remains the minimal symbol
7741 variant `long name(params)' does not have the proper inferior type.
7744 if (cu->language == language_go)
7746 /* This is a lie, but we already lie to the caller new_symbol_full.
7747 new_symbol_full assumes we return the mangled name.
7748 This just undoes that lie until things are cleaned up. */
7753 demangled = cplus_demangle (mangled,
7754 (DMGL_PARAMS | DMGL_ANSI
7755 | (cu->language == language_java
7756 ? DMGL_JAVA | DMGL_RET_POSTFIX
7761 make_cleanup (xfree, demangled);
7771 if (canon == NULL || check_physname)
7773 const char *physname = dwarf2_compute_name (name, die, cu, 1);
7775 if (canon != NULL && strcmp (physname, canon) != 0)
7777 /* It may not mean a bug in GDB. The compiler could also
7778 compute DW_AT_linkage_name incorrectly. But in such case
7779 GDB would need to be bug-to-bug compatible. */
7781 complaint (&symfile_complaints,
7782 _("Computed physname <%s> does not match demangled <%s> "
7783 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7784 physname, canon, mangled, die->offset.sect_off, objfile->name);
7786 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7787 is available here - over computed PHYSNAME. It is safer
7788 against both buggy GDB and buggy compilers. */
7802 retval = obstack_copy0 (&objfile->objfile_obstack, retval, strlen (retval));
7804 do_cleanups (back_to);
7808 /* Read the import statement specified by the given die and record it. */
7811 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
7813 struct objfile *objfile = cu->objfile;
7814 struct attribute *import_attr;
7815 struct die_info *imported_die, *child_die;
7816 struct dwarf2_cu *imported_cu;
7817 const char *imported_name;
7818 const char *imported_name_prefix;
7819 const char *canonical_name;
7820 const char *import_alias;
7821 const char *imported_declaration = NULL;
7822 const char *import_prefix;
7823 VEC (const_char_ptr) *excludes = NULL;
7824 struct cleanup *cleanups;
7826 import_attr = dwarf2_attr (die, DW_AT_import, cu);
7827 if (import_attr == NULL)
7829 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
7830 dwarf_tag_name (die->tag));
7835 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
7836 imported_name = dwarf2_name (imported_die, imported_cu);
7837 if (imported_name == NULL)
7839 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7841 The import in the following code:
7855 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7856 <52> DW_AT_decl_file : 1
7857 <53> DW_AT_decl_line : 6
7858 <54> DW_AT_import : <0x75>
7859 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7861 <5b> DW_AT_decl_file : 1
7862 <5c> DW_AT_decl_line : 2
7863 <5d> DW_AT_type : <0x6e>
7865 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7866 <76> DW_AT_byte_size : 4
7867 <77> DW_AT_encoding : 5 (signed)
7869 imports the wrong die ( 0x75 instead of 0x58 ).
7870 This case will be ignored until the gcc bug is fixed. */
7874 /* Figure out the local name after import. */
7875 import_alias = dwarf2_name (die, cu);
7877 /* Figure out where the statement is being imported to. */
7878 import_prefix = determine_prefix (die, cu);
7880 /* Figure out what the scope of the imported die is and prepend it
7881 to the name of the imported die. */
7882 imported_name_prefix = determine_prefix (imported_die, imported_cu);
7884 if (imported_die->tag != DW_TAG_namespace
7885 && imported_die->tag != DW_TAG_module)
7887 imported_declaration = imported_name;
7888 canonical_name = imported_name_prefix;
7890 else if (strlen (imported_name_prefix) > 0)
7891 canonical_name = obconcat (&objfile->objfile_obstack,
7892 imported_name_prefix, "::", imported_name,
7895 canonical_name = imported_name;
7897 cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
7899 if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
7900 for (child_die = die->child; child_die && child_die->tag;
7901 child_die = sibling_die (child_die))
7903 /* DWARF-4: A Fortran use statement with a “rename list” may be
7904 represented by an imported module entry with an import attribute
7905 referring to the module and owned entries corresponding to those
7906 entities that are renamed as part of being imported. */
7908 if (child_die->tag != DW_TAG_imported_declaration)
7910 complaint (&symfile_complaints,
7911 _("child DW_TAG_imported_declaration expected "
7912 "- DIE at 0x%x [in module %s]"),
7913 child_die->offset.sect_off, objfile->name);
7917 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
7918 if (import_attr == NULL)
7920 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
7921 dwarf_tag_name (child_die->tag));
7926 imported_die = follow_die_ref_or_sig (child_die, import_attr,
7928 imported_name = dwarf2_name (imported_die, imported_cu);
7929 if (imported_name == NULL)
7931 complaint (&symfile_complaints,
7932 _("child DW_TAG_imported_declaration has unknown "
7933 "imported name - DIE at 0x%x [in module %s]"),
7934 child_die->offset.sect_off, objfile->name);
7938 VEC_safe_push (const_char_ptr, excludes, imported_name);
7940 process_die (child_die, cu);
7943 cp_add_using_directive (import_prefix,
7946 imported_declaration,
7949 &objfile->objfile_obstack);
7951 do_cleanups (cleanups);
7954 /* Cleanup function for handle_DW_AT_stmt_list. */
7957 free_cu_line_header (void *arg)
7959 struct dwarf2_cu *cu = arg;
7961 free_line_header (cu->line_header);
7962 cu->line_header = NULL;
7965 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
7966 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
7967 this, it was first present in GCC release 4.3.0. */
7970 producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu)
7972 if (!cu->checked_producer)
7973 check_producer (cu);
7975 return cu->producer_is_gcc_lt_4_3;
7979 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
7980 const char **name, const char **comp_dir)
7982 struct attribute *attr;
7987 /* Find the filename. Do not use dwarf2_name here, since the filename
7988 is not a source language identifier. */
7989 attr = dwarf2_attr (die, DW_AT_name, cu);
7992 *name = DW_STRING (attr);
7995 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
7997 *comp_dir = DW_STRING (attr);
7998 else if (producer_is_gcc_lt_4_3 (cu) && *name != NULL
7999 && IS_ABSOLUTE_PATH (*name))
8001 char *d = ldirname (*name);
8005 make_cleanup (xfree, d);
8007 if (*comp_dir != NULL)
8009 /* Irix 6.2 native cc prepends <machine>.: to the compilation
8010 directory, get rid of it. */
8011 char *cp = strchr (*comp_dir, ':');
8013 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
8018 *name = "<unknown>";
8021 /* Handle DW_AT_stmt_list for a compilation unit.
8022 DIE is the DW_TAG_compile_unit die for CU.
8023 COMP_DIR is the compilation directory.
8024 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
8027 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
8028 const char *comp_dir)
8030 struct attribute *attr;
8032 gdb_assert (! cu->per_cu->is_debug_types);
8034 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
8037 unsigned int line_offset = DW_UNSND (attr);
8038 struct line_header *line_header
8039 = dwarf_decode_line_header (line_offset, cu);
8043 cu->line_header = line_header;
8044 make_cleanup (free_cu_line_header, cu);
8045 dwarf_decode_lines (line_header, comp_dir, cu, NULL, 1);
8050 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
8053 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
8055 struct objfile *objfile = dwarf2_per_objfile->objfile;
8056 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
8057 CORE_ADDR lowpc = ((CORE_ADDR) -1);
8058 CORE_ADDR highpc = ((CORE_ADDR) 0);
8059 struct attribute *attr;
8060 const char *name = NULL;
8061 const char *comp_dir = NULL;
8062 struct die_info *child_die;
8063 bfd *abfd = objfile->obfd;
8066 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
8068 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
8070 /* If we didn't find a lowpc, set it to highpc to avoid complaints
8071 from finish_block. */
8072 if (lowpc == ((CORE_ADDR) -1))
8077 find_file_and_directory (die, cu, &name, &comp_dir);
8079 prepare_one_comp_unit (cu, die, cu->language);
8081 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
8082 standardised yet. As a workaround for the language detection we fall
8083 back to the DW_AT_producer string. */
8084 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
8085 cu->language = language_opencl;
8087 /* Similar hack for Go. */
8088 if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL)
8089 set_cu_language (DW_LANG_Go, cu);
8091 dwarf2_start_symtab (cu, name, comp_dir, lowpc);
8093 /* Decode line number information if present. We do this before
8094 processing child DIEs, so that the line header table is available
8095 for DW_AT_decl_file. */
8096 handle_DW_AT_stmt_list (die, cu, comp_dir);
8098 /* Process all dies in compilation unit. */
8099 if (die->child != NULL)
8101 child_die = die->child;
8102 while (child_die && child_die->tag)
8104 process_die (child_die, cu);
8105 child_die = sibling_die (child_die);
8109 /* Decode macro information, if present. Dwarf 2 macro information
8110 refers to information in the line number info statement program
8111 header, so we can only read it if we've read the header
8113 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
8114 if (attr && cu->line_header)
8116 if (dwarf2_attr (die, DW_AT_macro_info, cu))
8117 complaint (&symfile_complaints,
8118 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
8120 dwarf_decode_macros (cu, DW_UNSND (attr), comp_dir, 1);
8124 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
8125 if (attr && cu->line_header)
8127 unsigned int macro_offset = DW_UNSND (attr);
8129 dwarf_decode_macros (cu, macro_offset, comp_dir, 0);
8133 do_cleanups (back_to);
8136 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
8137 Create the set of symtabs used by this TU, or if this TU is sharing
8138 symtabs with another TU and the symtabs have already been created
8139 then restore those symtabs in the line header.
8140 We don't need the pc/line-number mapping for type units. */
8143 setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
8145 struct objfile *objfile = dwarf2_per_objfile->objfile;
8146 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
8147 struct type_unit_group *tu_group;
8149 struct line_header *lh;
8150 struct attribute *attr;
8151 unsigned int i, line_offset;
8152 struct signatured_type *sig_type;
8154 gdb_assert (per_cu->is_debug_types);
8155 sig_type = (struct signatured_type *) per_cu;
8157 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
8159 /* If we're using .gdb_index (includes -readnow) then
8160 per_cu->s.type_unit_group may not have been set up yet. */
8161 if (sig_type->type_unit_group == NULL)
8162 sig_type->type_unit_group = get_type_unit_group (cu, attr);
8163 tu_group = sig_type->type_unit_group;
8165 /* If we've already processed this stmt_list there's no real need to
8166 do it again, we could fake it and just recreate the part we need
8167 (file name,index -> symtab mapping). If data shows this optimization
8168 is useful we can do it then. */
8169 first_time = tu_group->primary_symtab == NULL;
8171 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
8176 line_offset = DW_UNSND (attr);
8177 lh = dwarf_decode_line_header (line_offset, cu);
8182 dwarf2_start_symtab (cu, "", NULL, 0);
8185 gdb_assert (tu_group->symtabs == NULL);
8188 /* Note: The primary symtab will get allocated at the end. */
8192 cu->line_header = lh;
8193 make_cleanup (free_cu_line_header, cu);
8197 dwarf2_start_symtab (cu, "", NULL, 0);
8199 tu_group->num_symtabs = lh->num_file_names;
8200 tu_group->symtabs = XNEWVEC (struct symtab *, lh->num_file_names);
8202 for (i = 0; i < lh->num_file_names; ++i)
8205 struct file_entry *fe = &lh->file_names[i];
8208 dir = lh->include_dirs[fe->dir_index - 1];
8209 dwarf2_start_subfile (fe->name, dir, NULL);
8211 /* Note: We don't have to watch for the main subfile here, type units
8212 don't have DW_AT_name. */
8214 if (current_subfile->symtab == NULL)
8216 /* NOTE: start_subfile will recognize when it's been passed
8217 a file it has already seen. So we can't assume there's a
8218 simple mapping from lh->file_names to subfiles,
8219 lh->file_names may contain dups. */
8220 current_subfile->symtab = allocate_symtab (current_subfile->name,
8224 fe->symtab = current_subfile->symtab;
8225 tu_group->symtabs[i] = fe->symtab;
8232 for (i = 0; i < lh->num_file_names; ++i)
8234 struct file_entry *fe = &lh->file_names[i];
8236 fe->symtab = tu_group->symtabs[i];
8240 /* The main symtab is allocated last. Type units don't have DW_AT_name
8241 so they don't have a "real" (so to speak) symtab anyway.
8242 There is later code that will assign the main symtab to all symbols
8243 that don't have one. We need to handle the case of a symbol with a
8244 missing symtab (DW_AT_decl_file) anyway. */
8247 /* Process DW_TAG_type_unit.
8248 For TUs we want to skip the first top level sibling if it's not the
8249 actual type being defined by this TU. In this case the first top
8250 level sibling is there to provide context only. */
8253 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
8255 struct die_info *child_die;
8257 prepare_one_comp_unit (cu, die, language_minimal);
8259 /* Initialize (or reinitialize) the machinery for building symtabs.
8260 We do this before processing child DIEs, so that the line header table
8261 is available for DW_AT_decl_file. */
8262 setup_type_unit_groups (die, cu);
8264 if (die->child != NULL)
8266 child_die = die->child;
8267 while (child_die && child_die->tag)
8269 process_die (child_die, cu);
8270 child_die = sibling_die (child_die);
8277 http://gcc.gnu.org/wiki/DebugFission
8278 http://gcc.gnu.org/wiki/DebugFissionDWP
8280 To simplify handling of both DWO files ("object" files with the DWARF info)
8281 and DWP files (a file with the DWOs packaged up into one file), we treat
8282 DWP files as having a collection of virtual DWO files. */
8285 hash_dwo_file (const void *item)
8287 const struct dwo_file *dwo_file = item;
8289 return htab_hash_string (dwo_file->name);
8293 eq_dwo_file (const void *item_lhs, const void *item_rhs)
8295 const struct dwo_file *lhs = item_lhs;
8296 const struct dwo_file *rhs = item_rhs;
8298 return strcmp (lhs->name, rhs->name) == 0;
8301 /* Allocate a hash table for DWO files. */
8304 allocate_dwo_file_hash_table (void)
8306 struct objfile *objfile = dwarf2_per_objfile->objfile;
8308 return htab_create_alloc_ex (41,
8312 &objfile->objfile_obstack,
8313 hashtab_obstack_allocate,
8314 dummy_obstack_deallocate);
8317 /* Lookup DWO file DWO_NAME. */
8320 lookup_dwo_file_slot (const char *dwo_name)
8322 struct dwo_file find_entry;
8325 if (dwarf2_per_objfile->dwo_files == NULL)
8326 dwarf2_per_objfile->dwo_files = allocate_dwo_file_hash_table ();
8328 memset (&find_entry, 0, sizeof (find_entry));
8329 find_entry.name = dwo_name;
8330 slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT);
8336 hash_dwo_unit (const void *item)
8338 const struct dwo_unit *dwo_unit = item;
8340 /* This drops the top 32 bits of the id, but is ok for a hash. */
8341 return dwo_unit->signature;
8345 eq_dwo_unit (const void *item_lhs, const void *item_rhs)
8347 const struct dwo_unit *lhs = item_lhs;
8348 const struct dwo_unit *rhs = item_rhs;
8350 /* The signature is assumed to be unique within the DWO file.
8351 So while object file CU dwo_id's always have the value zero,
8352 that's OK, assuming each object file DWO file has only one CU,
8353 and that's the rule for now. */
8354 return lhs->signature == rhs->signature;
8357 /* Allocate a hash table for DWO CUs,TUs.
8358 There is one of these tables for each of CUs,TUs for each DWO file. */
8361 allocate_dwo_unit_table (struct objfile *objfile)
8363 /* Start out with a pretty small number.
8364 Generally DWO files contain only one CU and maybe some TUs. */
8365 return htab_create_alloc_ex (3,
8369 &objfile->objfile_obstack,
8370 hashtab_obstack_allocate,
8371 dummy_obstack_deallocate);
8374 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8376 struct create_dwo_info_table_data
8378 struct dwo_file *dwo_file;
8382 /* die_reader_func for create_dwo_debug_info_hash_table. */
8385 create_dwo_debug_info_hash_table_reader (const struct die_reader_specs *reader,
8387 struct die_info *comp_unit_die,
8391 struct dwarf2_cu *cu = reader->cu;
8392 struct objfile *objfile = dwarf2_per_objfile->objfile;
8393 sect_offset offset = cu->per_cu->offset;
8394 struct dwarf2_section_info *section = cu->per_cu->section;
8395 struct create_dwo_info_table_data *data = datap;
8396 struct dwo_file *dwo_file = data->dwo_file;
8397 htab_t cu_htab = data->cu_htab;
8399 struct attribute *attr;
8400 struct dwo_unit *dwo_unit;
8402 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
8405 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8406 " its dwo_id [in module %s]"),
8407 offset.sect_off, dwo_file->name);
8411 dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit);
8412 dwo_unit->dwo_file = dwo_file;
8413 dwo_unit->signature = DW_UNSND (attr);
8414 dwo_unit->section = section;
8415 dwo_unit->offset = offset;
8416 dwo_unit->length = cu->per_cu->length;
8418 slot = htab_find_slot (cu_htab, dwo_unit, INSERT);
8419 gdb_assert (slot != NULL);
8422 const struct dwo_unit *dup_dwo_unit = *slot;
8424 complaint (&symfile_complaints,
8425 _("debug entry at offset 0x%x is duplicate to the entry at"
8426 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8427 offset.sect_off, dup_dwo_unit->offset.sect_off,
8428 phex (dwo_unit->signature, sizeof (dwo_unit->signature)),
8434 if (dwarf2_read_debug)
8435 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, dwo_id 0x%s\n",
8437 phex (dwo_unit->signature,
8438 sizeof (dwo_unit->signature)));
8441 /* Create a hash table to map DWO IDs to their CU entry in
8442 .debug_info.dwo in DWO_FILE.
8443 Note: This function processes DWO files only, not DWP files.
8444 Note: A DWO file generally contains one CU, but we don't assume this. */
8447 create_dwo_debug_info_hash_table (struct dwo_file *dwo_file)
8449 struct objfile *objfile = dwarf2_per_objfile->objfile;
8450 struct dwarf2_section_info *section = &dwo_file->sections.info;
8453 gdb_byte *info_ptr, *end_ptr;
8454 struct create_dwo_info_table_data create_dwo_info_table_data;
8456 dwarf2_read_section (objfile, section);
8457 info_ptr = section->buffer;
8459 if (info_ptr == NULL)
8462 /* We can't set abfd until now because the section may be empty or
8463 not present, in which case section->asection will be NULL. */
8464 abfd = section->asection->owner;
8466 if (dwarf2_read_debug)
8467 fprintf_unfiltered (gdb_stdlog, "Reading .debug_info.dwo for %s:\n",
8468 bfd_get_filename (abfd));
8470 cu_htab = allocate_dwo_unit_table (objfile);
8472 create_dwo_info_table_data.dwo_file = dwo_file;
8473 create_dwo_info_table_data.cu_htab = cu_htab;
8475 end_ptr = info_ptr + section->size;
8476 while (info_ptr < end_ptr)
8478 struct dwarf2_per_cu_data per_cu;
8480 memset (&per_cu, 0, sizeof (per_cu));
8481 per_cu.objfile = objfile;
8482 per_cu.is_debug_types = 0;
8483 per_cu.offset.sect_off = info_ptr - section->buffer;
8484 per_cu.section = section;
8486 init_cutu_and_read_dies_no_follow (&per_cu,
8487 &dwo_file->sections.abbrev,
8489 create_dwo_debug_info_hash_table_reader,
8490 &create_dwo_info_table_data);
8492 info_ptr += per_cu.length;
8498 /* DWP file .debug_{cu,tu}_index section format:
8499 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8501 Both index sections have the same format, and serve to map a 64-bit
8502 signature to a set of section numbers. Each section begins with a header,
8503 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8504 indexes, and a pool of 32-bit section numbers. The index sections will be
8505 aligned at 8-byte boundaries in the file.
8507 The index section header contains two unsigned 32-bit values (using the
8508 byte order of the application binary):
8510 N, the number of compilation units or type units in the index
8511 M, the number of slots in the hash table
8513 (We assume that N and M will not exceed 2^32 - 1.)
8515 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8517 The hash table begins at offset 8 in the section, and consists of an array
8518 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8519 order of the application binary). Unused slots in the hash table are 0.
8520 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8522 The parallel table begins immediately after the hash table
8523 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8524 array of 32-bit indexes (using the byte order of the application binary),
8525 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8526 table contains a 32-bit index into the pool of section numbers. For unused
8527 hash table slots, the corresponding entry in the parallel table will be 0.
8529 Given a 64-bit compilation unit signature or a type signature S, an entry
8530 in the hash table is located as follows:
8532 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8533 the low-order k bits all set to 1.
8535 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8537 3) If the hash table entry at index H matches the signature, use that
8538 entry. If the hash table entry at index H is unused (all zeroes),
8539 terminate the search: the signature is not present in the table.
8541 4) Let H = (H + H') modulo M. Repeat at Step 3.
8543 Because M > N and H' and M are relatively prime, the search is guaranteed
8544 to stop at an unused slot or find the match.
8546 The pool of section numbers begins immediately following the hash table
8547 (at offset 8 + 12 * M from the beginning of the section). The pool of
8548 section numbers consists of an array of 32-bit words (using the byte order
8549 of the application binary). Each item in the array is indexed starting
8550 from 0. The hash table entry provides the index of the first section
8551 number in the set. Additional section numbers in the set follow, and the
8552 set is terminated by a 0 entry (section number 0 is not used in ELF).
8554 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8555 section must be the first entry in the set, and the .debug_abbrev.dwo must
8556 be the second entry. Other members of the set may follow in any order. */
8558 /* Create a hash table to map DWO IDs to their CU/TU entry in
8559 .debug_{info,types}.dwo in DWP_FILE.
8560 Returns NULL if there isn't one.
8561 Note: This function processes DWP files only, not DWO files. */
8563 static struct dwp_hash_table *
8564 create_dwp_hash_table (struct dwp_file *dwp_file, int is_debug_types)
8566 struct objfile *objfile = dwarf2_per_objfile->objfile;
8567 bfd *dbfd = dwp_file->dbfd;
8568 char *index_ptr, *index_end;
8569 struct dwarf2_section_info *index;
8570 uint32_t version, nr_units, nr_slots;
8571 struct dwp_hash_table *htab;
8574 index = &dwp_file->sections.tu_index;
8576 index = &dwp_file->sections.cu_index;
8578 if (dwarf2_section_empty_p (index))
8580 dwarf2_read_section (objfile, index);
8582 index_ptr = index->buffer;
8583 index_end = index_ptr + index->size;
8585 version = read_4_bytes (dbfd, index_ptr);
8586 index_ptr += 8; /* Skip the unused word. */
8587 nr_units = read_4_bytes (dbfd, index_ptr);
8589 nr_slots = read_4_bytes (dbfd, index_ptr);
8594 error (_("Dwarf Error: unsupported DWP file version (%u)"
8596 version, dwp_file->name);
8598 if (nr_slots != (nr_slots & -nr_slots))
8600 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8601 " is not power of 2 [in module %s]"),
8602 nr_slots, dwp_file->name);
8605 htab = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_hash_table);
8606 htab->nr_units = nr_units;
8607 htab->nr_slots = nr_slots;
8608 htab->hash_table = index_ptr;
8609 htab->unit_table = htab->hash_table + sizeof (uint64_t) * nr_slots;
8610 htab->section_pool = htab->unit_table + sizeof (uint32_t) * nr_slots;
8615 /* Update SECTIONS with the data from SECTP.
8617 This function is like the other "locate" section routines that are
8618 passed to bfd_map_over_sections, but in this context the sections to
8619 read comes from the DWP hash table, not the full ELF section table.
8621 The result is non-zero for success, or zero if an error was found. */
8624 locate_virtual_dwo_sections (asection *sectp,
8625 struct virtual_dwo_sections *sections)
8627 const struct dwop_section_names *names = &dwop_section_names;
8629 if (section_is_p (sectp->name, &names->abbrev_dwo))
8631 /* There can be only one. */
8632 if (sections->abbrev.asection != NULL)
8634 sections->abbrev.asection = sectp;
8635 sections->abbrev.size = bfd_get_section_size (sectp);
8637 else if (section_is_p (sectp->name, &names->info_dwo)
8638 || section_is_p (sectp->name, &names->types_dwo))
8640 /* There can be only one. */
8641 if (sections->info_or_types.asection != NULL)
8643 sections->info_or_types.asection = sectp;
8644 sections->info_or_types.size = bfd_get_section_size (sectp);
8646 else if (section_is_p (sectp->name, &names->line_dwo))
8648 /* There can be only one. */
8649 if (sections->line.asection != NULL)
8651 sections->line.asection = sectp;
8652 sections->line.size = bfd_get_section_size (sectp);
8654 else if (section_is_p (sectp->name, &names->loc_dwo))
8656 /* There can be only one. */
8657 if (sections->loc.asection != NULL)
8659 sections->loc.asection = sectp;
8660 sections->loc.size = bfd_get_section_size (sectp);
8662 else if (section_is_p (sectp->name, &names->macinfo_dwo))
8664 /* There can be only one. */
8665 if (sections->macinfo.asection != NULL)
8667 sections->macinfo.asection = sectp;
8668 sections->macinfo.size = bfd_get_section_size (sectp);
8670 else if (section_is_p (sectp->name, &names->macro_dwo))
8672 /* There can be only one. */
8673 if (sections->macro.asection != NULL)
8675 sections->macro.asection = sectp;
8676 sections->macro.size = bfd_get_section_size (sectp);
8678 else if (section_is_p (sectp->name, &names->str_offsets_dwo))
8680 /* There can be only one. */
8681 if (sections->str_offsets.asection != NULL)
8683 sections->str_offsets.asection = sectp;
8684 sections->str_offsets.size = bfd_get_section_size (sectp);
8688 /* No other kind of section is valid. */
8695 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8696 HTAB is the hash table from the DWP file.
8697 SECTION_INDEX is the index of the DWO in HTAB. */
8699 static struct dwo_unit *
8700 create_dwo_in_dwp (struct dwp_file *dwp_file,
8701 const struct dwp_hash_table *htab,
8702 uint32_t section_index,
8703 ULONGEST signature, int is_debug_types)
8705 struct objfile *objfile = dwarf2_per_objfile->objfile;
8706 bfd *dbfd = dwp_file->dbfd;
8707 const char *kind = is_debug_types ? "TU" : "CU";
8708 struct dwo_file *dwo_file;
8709 struct dwo_unit *dwo_unit;
8710 struct virtual_dwo_sections sections;
8711 void **dwo_file_slot;
8712 char *virtual_dwo_name;
8713 struct dwarf2_section_info *cutu;
8714 struct cleanup *cleanups;
8717 if (dwarf2_read_debug)
8719 fprintf_unfiltered (gdb_stdlog, "Reading %s %u/0x%s in DWP file: %s\n",
8721 section_index, phex (signature, sizeof (signature)),
8725 /* Fetch the sections of this DWO.
8726 Put a limit on the number of sections we look for so that bad data
8727 doesn't cause us to loop forever. */
8729 #define MAX_NR_DWO_SECTIONS \
8730 (1 /* .debug_info or .debug_types */ \
8731 + 1 /* .debug_abbrev */ \
8732 + 1 /* .debug_line */ \
8733 + 1 /* .debug_loc */ \
8734 + 1 /* .debug_str_offsets */ \
8735 + 1 /* .debug_macro */ \
8736 + 1 /* .debug_macinfo */ \
8737 + 1 /* trailing zero */)
8739 memset (§ions, 0, sizeof (sections));
8740 cleanups = make_cleanup (null_cleanup, 0);
8742 for (i = 0; i < MAX_NR_DWO_SECTIONS; ++i)
8745 uint32_t section_nr =
8748 + (section_index + i) * sizeof (uint32_t));
8750 if (section_nr == 0)
8752 if (section_nr >= dwp_file->num_sections)
8754 error (_("Dwarf Error: bad DWP hash table, section number too large"
8759 sectp = dwp_file->elf_sections[section_nr];
8760 if (! locate_virtual_dwo_sections (sectp, §ions))
8762 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8769 || sections.info_or_types.asection == NULL
8770 || sections.abbrev.asection == NULL)
8772 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8776 if (i == MAX_NR_DWO_SECTIONS)
8778 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8783 /* It's easier for the rest of the code if we fake a struct dwo_file and
8784 have dwo_unit "live" in that. At least for now.
8786 The DWP file can be made up of a random collection of CUs and TUs.
8787 However, for each CU + set of TUs that came from the same original DWO
8788 file, we want to combine them back into a virtual DWO file to save space
8789 (fewer struct dwo_file objects to allocated). Remember that for really
8790 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8793 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
8794 sections.abbrev.asection ? sections.abbrev.asection->id : 0,
8795 sections.line.asection ? sections.line.asection->id : 0,
8796 sections.loc.asection ? sections.loc.asection->id : 0,
8797 (sections.str_offsets.asection
8798 ? sections.str_offsets.asection->id
8800 make_cleanup (xfree, virtual_dwo_name);
8801 /* Can we use an existing virtual DWO file? */
8802 dwo_file_slot = lookup_dwo_file_slot (virtual_dwo_name);
8803 /* Create one if necessary. */
8804 if (*dwo_file_slot == NULL)
8806 if (dwarf2_read_debug)
8808 fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n",
8811 dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
8812 dwo_file->name = obstack_copy0 (&objfile->objfile_obstack,
8814 strlen (virtual_dwo_name));
8815 dwo_file->sections.abbrev = sections.abbrev;
8816 dwo_file->sections.line = sections.line;
8817 dwo_file->sections.loc = sections.loc;
8818 dwo_file->sections.macinfo = sections.macinfo;
8819 dwo_file->sections.macro = sections.macro;
8820 dwo_file->sections.str_offsets = sections.str_offsets;
8821 /* The "str" section is global to the entire DWP file. */
8822 dwo_file->sections.str = dwp_file->sections.str;
8823 /* The info or types section is assigned later to dwo_unit,
8824 there's no need to record it in dwo_file.
8825 Also, we can't simply record type sections in dwo_file because
8826 we record a pointer into the vector in dwo_unit. As we collect more
8827 types we'll grow the vector and eventually have to reallocate space
8828 for it, invalidating all the pointers into the current copy. */
8829 *dwo_file_slot = dwo_file;
8833 if (dwarf2_read_debug)
8835 fprintf_unfiltered (gdb_stdlog, "Using existing virtual DWO: %s\n",
8838 dwo_file = *dwo_file_slot;
8840 do_cleanups (cleanups);
8842 dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit);
8843 dwo_unit->dwo_file = dwo_file;
8844 dwo_unit->signature = signature;
8845 dwo_unit->section = obstack_alloc (&objfile->objfile_obstack,
8846 sizeof (struct dwarf2_section_info));
8847 *dwo_unit->section = sections.info_or_types;
8848 /* offset, length, type_offset_in_tu are set later. */
8853 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8855 static struct dwo_unit *
8856 lookup_dwo_in_dwp (struct dwp_file *dwp_file,
8857 const struct dwp_hash_table *htab,
8858 ULONGEST signature, int is_debug_types)
8860 bfd *dbfd = dwp_file->dbfd;
8861 uint32_t mask = htab->nr_slots - 1;
8862 uint32_t hash = signature & mask;
8863 uint32_t hash2 = ((signature >> 32) & mask) | 1;
8866 struct dwo_unit find_dwo_cu, *dwo_cu;
8868 memset (&find_dwo_cu, 0, sizeof (find_dwo_cu));
8869 find_dwo_cu.signature = signature;
8870 slot = htab_find_slot (dwp_file->loaded_cutus, &find_dwo_cu, INSERT);
8875 /* Use a for loop so that we don't loop forever on bad debug info. */
8876 for (i = 0; i < htab->nr_slots; ++i)
8878 ULONGEST signature_in_table;
8880 signature_in_table =
8881 read_8_bytes (dbfd, htab->hash_table + hash * sizeof (uint64_t));
8882 if (signature_in_table == signature)
8884 uint32_t section_index =
8885 read_4_bytes (dbfd, htab->unit_table + hash * sizeof (uint32_t));
8887 *slot = create_dwo_in_dwp (dwp_file, htab, section_index,
8888 signature, is_debug_types);
8891 if (signature_in_table == 0)
8893 hash = (hash + hash2) & mask;
8896 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8901 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
8902 Open the file specified by FILE_NAME and hand it off to BFD for
8903 preliminary analysis. Return a newly initialized bfd *, which
8904 includes a canonicalized copy of FILE_NAME.
8905 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8906 In case of trouble, return NULL.
8907 NOTE: This function is derived from symfile_bfd_open. */
8910 try_open_dwop_file (const char *file_name, int is_dwp)
8914 char *absolute_name;
8916 flags = OPF_TRY_CWD_FIRST;
8918 flags |= OPF_SEARCH_IN_PATH;
8919 desc = openp (debug_file_directory, flags, file_name,
8920 O_RDONLY | O_BINARY, &absolute_name);
8924 sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc);
8927 xfree (absolute_name);
8930 xfree (absolute_name);
8931 bfd_set_cacheable (sym_bfd, 1);
8933 if (!bfd_check_format (sym_bfd, bfd_object))
8935 gdb_bfd_unref (sym_bfd); /* This also closes desc. */
8942 /* Try to open DWO file FILE_NAME.
8943 COMP_DIR is the DW_AT_comp_dir attribute.
8944 The result is the bfd handle of the file.
8945 If there is a problem finding or opening the file, return NULL.
8946 Upon success, the canonicalized path of the file is stored in the bfd,
8947 same as symfile_bfd_open. */
8950 open_dwo_file (const char *file_name, const char *comp_dir)
8954 if (IS_ABSOLUTE_PATH (file_name))
8955 return try_open_dwop_file (file_name, 0 /*is_dwp*/);
8957 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8959 if (comp_dir != NULL)
8961 char *path_to_try = concat (comp_dir, SLASH_STRING, file_name, NULL);
8963 /* NOTE: If comp_dir is a relative path, this will also try the
8964 search path, which seems useful. */
8965 abfd = try_open_dwop_file (path_to_try, 0 /*is_dwp*/);
8966 xfree (path_to_try);
8971 /* That didn't work, try debug-file-directory, which, despite its name,
8972 is a list of paths. */
8974 if (*debug_file_directory == '\0')
8977 return try_open_dwop_file (file_name, 0 /*is_dwp*/);
8980 /* This function is mapped across the sections and remembers the offset and
8981 size of each of the DWO debugging sections we are interested in. */
8984 dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr)
8986 struct dwo_sections *dwo_sections = dwo_sections_ptr;
8987 const struct dwop_section_names *names = &dwop_section_names;
8989 if (section_is_p (sectp->name, &names->abbrev_dwo))
8991 dwo_sections->abbrev.asection = sectp;
8992 dwo_sections->abbrev.size = bfd_get_section_size (sectp);
8994 else if (section_is_p (sectp->name, &names->info_dwo))
8996 dwo_sections->info.asection = sectp;
8997 dwo_sections->info.size = bfd_get_section_size (sectp);
8999 else if (section_is_p (sectp->name, &names->line_dwo))
9001 dwo_sections->line.asection = sectp;
9002 dwo_sections->line.size = bfd_get_section_size (sectp);
9004 else if (section_is_p (sectp->name, &names->loc_dwo))
9006 dwo_sections->loc.asection = sectp;
9007 dwo_sections->loc.size = bfd_get_section_size (sectp);
9009 else if (section_is_p (sectp->name, &names->macinfo_dwo))
9011 dwo_sections->macinfo.asection = sectp;
9012 dwo_sections->macinfo.size = bfd_get_section_size (sectp);
9014 else if (section_is_p (sectp->name, &names->macro_dwo))
9016 dwo_sections->macro.asection = sectp;
9017 dwo_sections->macro.size = bfd_get_section_size (sectp);
9019 else if (section_is_p (sectp->name, &names->str_dwo))
9021 dwo_sections->str.asection = sectp;
9022 dwo_sections->str.size = bfd_get_section_size (sectp);
9024 else if (section_is_p (sectp->name, &names->str_offsets_dwo))
9026 dwo_sections->str_offsets.asection = sectp;
9027 dwo_sections->str_offsets.size = bfd_get_section_size (sectp);
9029 else if (section_is_p (sectp->name, &names->types_dwo))
9031 struct dwarf2_section_info type_section;
9033 memset (&type_section, 0, sizeof (type_section));
9034 type_section.asection = sectp;
9035 type_section.size = bfd_get_section_size (sectp);
9036 VEC_safe_push (dwarf2_section_info_def, dwo_sections->types,
9041 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
9043 The result is NULL if DWO_NAME can't be found. */
9045 static struct dwo_file *
9046 open_and_init_dwo_file (const char *dwo_name, const char *comp_dir)
9048 struct objfile *objfile = dwarf2_per_objfile->objfile;
9049 struct dwo_file *dwo_file;
9051 struct cleanup *cleanups;
9053 dbfd = open_dwo_file (dwo_name, comp_dir);
9056 if (dwarf2_read_debug)
9057 fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name);
9060 dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
9061 dwo_file->name = obstack_copy0 (&objfile->objfile_obstack,
9062 dwo_name, strlen (dwo_name));
9063 dwo_file->dbfd = dbfd;
9065 cleanups = make_cleanup (free_dwo_file_cleanup, dwo_file);
9067 bfd_map_over_sections (dbfd, dwarf2_locate_dwo_sections, &dwo_file->sections);
9069 dwo_file->cus = create_dwo_debug_info_hash_table (dwo_file);
9071 dwo_file->tus = create_debug_types_hash_table (dwo_file,
9072 dwo_file->sections.types);
9074 discard_cleanups (cleanups);
9076 if (dwarf2_read_debug)
9077 fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name);
9082 /* This function is mapped across the sections and remembers the offset and
9083 size of each of the DWP debugging sections we are interested in. */
9086 dwarf2_locate_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_ptr)
9088 struct dwp_file *dwp_file = dwp_file_ptr;
9089 const struct dwop_section_names *names = &dwop_section_names;
9090 unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
9092 /* Record the ELF section number for later lookup: this is what the
9093 .debug_cu_index,.debug_tu_index tables use. */
9094 gdb_assert (elf_section_nr < dwp_file->num_sections);
9095 dwp_file->elf_sections[elf_section_nr] = sectp;
9097 /* Look for specific sections that we need. */
9098 if (section_is_p (sectp->name, &names->str_dwo))
9100 dwp_file->sections.str.asection = sectp;
9101 dwp_file->sections.str.size = bfd_get_section_size (sectp);
9103 else if (section_is_p (sectp->name, &names->cu_index))
9105 dwp_file->sections.cu_index.asection = sectp;
9106 dwp_file->sections.cu_index.size = bfd_get_section_size (sectp);
9108 else if (section_is_p (sectp->name, &names->tu_index))
9110 dwp_file->sections.tu_index.asection = sectp;
9111 dwp_file->sections.tu_index.size = bfd_get_section_size (sectp);
9115 /* Hash function for dwp_file loaded CUs/TUs. */
9118 hash_dwp_loaded_cutus (const void *item)
9120 const struct dwo_unit *dwo_unit = item;
9122 /* This drops the top 32 bits of the signature, but is ok for a hash. */
9123 return dwo_unit->signature;
9126 /* Equality function for dwp_file loaded CUs/TUs. */
9129 eq_dwp_loaded_cutus (const void *a, const void *b)
9131 const struct dwo_unit *dua = a;
9132 const struct dwo_unit *dub = b;
9134 return dua->signature == dub->signature;
9137 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
9140 allocate_dwp_loaded_cutus_table (struct objfile *objfile)
9142 return htab_create_alloc_ex (3,
9143 hash_dwp_loaded_cutus,
9144 eq_dwp_loaded_cutus,
9146 &objfile->objfile_obstack,
9147 hashtab_obstack_allocate,
9148 dummy_obstack_deallocate);
9151 /* Try to open DWP file FILE_NAME.
9152 The result is the bfd handle of the file.
9153 If there is a problem finding or opening the file, return NULL.
9154 Upon success, the canonicalized path of the file is stored in the bfd,
9155 same as symfile_bfd_open. */
9158 open_dwp_file (const char *file_name)
9160 return try_open_dwop_file (file_name, 1 /*is_dwp*/);
9163 /* Initialize the use of the DWP file for the current objfile.
9164 By convention the name of the DWP file is ${objfile}.dwp.
9165 The result is NULL if it can't be found. */
9167 static struct dwp_file *
9168 open_and_init_dwp_file (void)
9170 struct objfile *objfile = dwarf2_per_objfile->objfile;
9171 struct dwp_file *dwp_file;
9174 struct cleanup *cleanups;
9176 dwp_name = xstrprintf ("%s.dwp", dwarf2_per_objfile->objfile->name);
9177 cleanups = make_cleanup (xfree, dwp_name);
9179 dbfd = open_dwp_file (dwp_name);
9182 if (dwarf2_read_debug)
9183 fprintf_unfiltered (gdb_stdlog, "DWP file not found: %s\n", dwp_name);
9184 do_cleanups (cleanups);
9187 dwp_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_file);
9188 dwp_file->name = obstack_copy0 (&objfile->objfile_obstack,
9189 dwp_name, strlen (dwp_name));
9190 dwp_file->dbfd = dbfd;
9191 do_cleanups (cleanups);
9193 /* +1: section 0 is unused */
9194 dwp_file->num_sections = bfd_count_sections (dbfd) + 1;
9195 dwp_file->elf_sections =
9196 OBSTACK_CALLOC (&objfile->objfile_obstack,
9197 dwp_file->num_sections, asection *);
9199 bfd_map_over_sections (dbfd, dwarf2_locate_dwp_sections, dwp_file);
9201 dwp_file->cus = create_dwp_hash_table (dwp_file, 0);
9203 dwp_file->tus = create_dwp_hash_table (dwp_file, 1);
9205 dwp_file->loaded_cutus = allocate_dwp_loaded_cutus_table (objfile);
9207 if (dwarf2_read_debug)
9209 fprintf_unfiltered (gdb_stdlog, "DWP file found: %s\n", dwp_file->name);
9210 fprintf_unfiltered (gdb_stdlog,
9211 " %u CUs, %u TUs\n",
9212 dwp_file->cus ? dwp_file->cus->nr_units : 0,
9213 dwp_file->tus ? dwp_file->tus->nr_units : 0);
9219 /* Wrapper around open_and_init_dwp_file, only open it once. */
9221 static struct dwp_file *
9224 if (! dwarf2_per_objfile->dwp_checked)
9226 dwarf2_per_objfile->dwp_file = open_and_init_dwp_file ();
9227 dwarf2_per_objfile->dwp_checked = 1;
9229 return dwarf2_per_objfile->dwp_file;
9232 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9233 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9234 or in the DWP file for the objfile, referenced by THIS_UNIT.
9235 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9236 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9238 This is called, for example, when wanting to read a variable with a
9239 complex location. Therefore we don't want to do file i/o for every call.
9240 Therefore we don't want to look for a DWO file on every call.
9241 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9242 then we check if we've already seen DWO_NAME, and only THEN do we check
9245 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9246 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9248 static struct dwo_unit *
9249 lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
9250 const char *dwo_name, const char *comp_dir,
9251 ULONGEST signature, int is_debug_types)
9253 struct objfile *objfile = dwarf2_per_objfile->objfile;
9254 const char *kind = is_debug_types ? "TU" : "CU";
9255 void **dwo_file_slot;
9256 struct dwo_file *dwo_file;
9257 struct dwp_file *dwp_file;
9259 /* Have we already read SIGNATURE from a DWP file? */
9261 dwp_file = get_dwp_file ();
9262 if (dwp_file != NULL)
9264 const struct dwp_hash_table *dwp_htab =
9265 is_debug_types ? dwp_file->tus : dwp_file->cus;
9267 if (dwp_htab != NULL)
9269 struct dwo_unit *dwo_cutu =
9270 lookup_dwo_in_dwp (dwp_file, dwp_htab, signature, is_debug_types);
9272 if (dwo_cutu != NULL)
9274 if (dwarf2_read_debug)
9276 fprintf_unfiltered (gdb_stdlog,
9277 "Virtual DWO %s %s found: @%s\n",
9278 kind, hex_string (signature),
9279 host_address_to_string (dwo_cutu));
9286 /* Have we already seen DWO_NAME? */
9288 dwo_file_slot = lookup_dwo_file_slot (dwo_name);
9289 if (*dwo_file_slot == NULL)
9291 /* Read in the file and build a table of the DWOs it contains. */
9292 *dwo_file_slot = open_and_init_dwo_file (dwo_name, comp_dir);
9294 /* NOTE: This will be NULL if unable to open the file. */
9295 dwo_file = *dwo_file_slot;
9297 if (dwo_file != NULL)
9299 htab_t htab = is_debug_types ? dwo_file->tus : dwo_file->cus;
9303 struct dwo_unit find_dwo_cutu, *dwo_cutu;
9305 memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
9306 find_dwo_cutu.signature = signature;
9307 dwo_cutu = htab_find (htab, &find_dwo_cutu);
9309 if (dwo_cutu != NULL)
9311 if (dwarf2_read_debug)
9313 fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) found: @%s\n",
9314 kind, dwo_name, hex_string (signature),
9315 host_address_to_string (dwo_cutu));
9322 /* We didn't find it. This could mean a dwo_id mismatch, or
9323 someone deleted the DWO/DWP file, or the search path isn't set up
9324 correctly to find the file. */
9326 if (dwarf2_read_debug)
9328 fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) not found\n",
9329 kind, dwo_name, hex_string (signature));
9332 complaint (&symfile_complaints,
9333 _("Could not find DWO %s referenced by CU at offset 0x%x"
9335 kind, this_unit->offset.sect_off, objfile->name);
9339 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9340 See lookup_dwo_cutu_unit for details. */
9342 static struct dwo_unit *
9343 lookup_dwo_comp_unit (struct dwarf2_per_cu_data *this_cu,
9344 const char *dwo_name, const char *comp_dir,
9347 return lookup_dwo_cutu (this_cu, dwo_name, comp_dir, signature, 0);
9350 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9351 See lookup_dwo_cutu_unit for details. */
9353 static struct dwo_unit *
9354 lookup_dwo_type_unit (struct signatured_type *this_tu,
9355 const char *dwo_name, const char *comp_dir)
9357 return lookup_dwo_cutu (&this_tu->per_cu, dwo_name, comp_dir, this_tu->signature, 1);
9360 /* Free all resources associated with DWO_FILE.
9361 Close the DWO file and munmap the sections.
9362 All memory should be on the objfile obstack. */
9365 free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile)
9368 struct dwarf2_section_info *section;
9370 /* Note: dbfd is NULL for virtual DWO files. */
9371 gdb_bfd_unref (dwo_file->dbfd);
9373 VEC_free (dwarf2_section_info_def, dwo_file->sections.types);
9376 /* Wrapper for free_dwo_file for use in cleanups. */
9379 free_dwo_file_cleanup (void *arg)
9381 struct dwo_file *dwo_file = (struct dwo_file *) arg;
9382 struct objfile *objfile = dwarf2_per_objfile->objfile;
9384 free_dwo_file (dwo_file, objfile);
9387 /* Traversal function for free_dwo_files. */
9390 free_dwo_file_from_slot (void **slot, void *info)
9392 struct dwo_file *dwo_file = (struct dwo_file *) *slot;
9393 struct objfile *objfile = (struct objfile *) info;
9395 free_dwo_file (dwo_file, objfile);
9400 /* Free all resources associated with DWO_FILES. */
9403 free_dwo_files (htab_t dwo_files, struct objfile *objfile)
9405 htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile);
9408 /* Read in various DIEs. */
9410 /* qsort helper for inherit_abstract_dies. */
9413 unsigned_int_compar (const void *ap, const void *bp)
9415 unsigned int a = *(unsigned int *) ap;
9416 unsigned int b = *(unsigned int *) bp;
9418 return (a > b) - (b > a);
9421 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9422 Inherit only the children of the DW_AT_abstract_origin DIE not being
9423 already referenced by DW_AT_abstract_origin from the children of the
9427 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
9429 struct die_info *child_die;
9430 unsigned die_children_count;
9431 /* CU offsets which were referenced by children of the current DIE. */
9432 sect_offset *offsets;
9433 sect_offset *offsets_end, *offsetp;
9434 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9435 struct die_info *origin_die;
9436 /* Iterator of the ORIGIN_DIE children. */
9437 struct die_info *origin_child_die;
9438 struct cleanup *cleanups;
9439 struct attribute *attr;
9440 struct dwarf2_cu *origin_cu;
9441 struct pending **origin_previous_list_in_scope;
9443 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
9447 /* Note that following die references may follow to a die in a
9451 origin_die = follow_die_ref (die, attr, &origin_cu);
9453 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9455 origin_previous_list_in_scope = origin_cu->list_in_scope;
9456 origin_cu->list_in_scope = cu->list_in_scope;
9458 if (die->tag != origin_die->tag
9459 && !(die->tag == DW_TAG_inlined_subroutine
9460 && origin_die->tag == DW_TAG_subprogram))
9461 complaint (&symfile_complaints,
9462 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9463 die->offset.sect_off, origin_die->offset.sect_off);
9465 child_die = die->child;
9466 die_children_count = 0;
9467 while (child_die && child_die->tag)
9469 child_die = sibling_die (child_die);
9470 die_children_count++;
9472 offsets = xmalloc (sizeof (*offsets) * die_children_count);
9473 cleanups = make_cleanup (xfree, offsets);
9475 offsets_end = offsets;
9476 child_die = die->child;
9477 while (child_die && child_die->tag)
9479 /* For each CHILD_DIE, find the corresponding child of
9480 ORIGIN_DIE. If there is more than one layer of
9481 DW_AT_abstract_origin, follow them all; there shouldn't be,
9482 but GCC versions at least through 4.4 generate this (GCC PR
9484 struct die_info *child_origin_die = child_die;
9485 struct dwarf2_cu *child_origin_cu = cu;
9489 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
9493 child_origin_die = follow_die_ref (child_origin_die, attr,
9497 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9498 counterpart may exist. */
9499 if (child_origin_die != child_die)
9501 if (child_die->tag != child_origin_die->tag
9502 && !(child_die->tag == DW_TAG_inlined_subroutine
9503 && child_origin_die->tag == DW_TAG_subprogram))
9504 complaint (&symfile_complaints,
9505 _("Child DIE 0x%x and its abstract origin 0x%x have "
9506 "different tags"), child_die->offset.sect_off,
9507 child_origin_die->offset.sect_off);
9508 if (child_origin_die->parent != origin_die)
9509 complaint (&symfile_complaints,
9510 _("Child DIE 0x%x and its abstract origin 0x%x have "
9511 "different parents"), child_die->offset.sect_off,
9512 child_origin_die->offset.sect_off);
9514 *offsets_end++ = child_origin_die->offset;
9516 child_die = sibling_die (child_die);
9518 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
9519 unsigned_int_compar);
9520 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
9521 if (offsetp[-1].sect_off == offsetp->sect_off)
9522 complaint (&symfile_complaints,
9523 _("Multiple children of DIE 0x%x refer "
9524 "to DIE 0x%x as their abstract origin"),
9525 die->offset.sect_off, offsetp->sect_off);
9528 origin_child_die = origin_die->child;
9529 while (origin_child_die && origin_child_die->tag)
9531 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9532 while (offsetp < offsets_end
9533 && offsetp->sect_off < origin_child_die->offset.sect_off)
9535 if (offsetp >= offsets_end
9536 || offsetp->sect_off > origin_child_die->offset.sect_off)
9538 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9539 process_die (origin_child_die, origin_cu);
9541 origin_child_die = sibling_die (origin_child_die);
9543 origin_cu->list_in_scope = origin_previous_list_in_scope;
9545 do_cleanups (cleanups);
9549 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
9551 struct objfile *objfile = cu->objfile;
9552 struct context_stack *new;
9555 struct die_info *child_die;
9556 struct attribute *attr, *call_line, *call_file;
9559 struct block *block;
9560 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
9561 VEC (symbolp) *template_args = NULL;
9562 struct template_symbol *templ_func = NULL;
9566 /* If we do not have call site information, we can't show the
9567 caller of this inlined function. That's too confusing, so
9568 only use the scope for local variables. */
9569 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
9570 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
9571 if (call_line == NULL || call_file == NULL)
9573 read_lexical_block_scope (die, cu);
9578 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9580 name = dwarf2_name (die, cu);
9582 /* Ignore functions with missing or empty names. These are actually
9583 illegal according to the DWARF standard. */
9586 complaint (&symfile_complaints,
9587 _("missing name for subprogram DIE at %d"),
9588 die->offset.sect_off);
9592 /* Ignore functions with missing or invalid low and high pc attributes. */
9593 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
9595 attr = dwarf2_attr (die, DW_AT_external, cu);
9596 if (!attr || !DW_UNSND (attr))
9597 complaint (&symfile_complaints,
9598 _("cannot get low and high bounds "
9599 "for subprogram DIE at %d"),
9600 die->offset.sect_off);
9607 /* If we have any template arguments, then we must allocate a
9608 different sort of symbol. */
9609 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
9611 if (child_die->tag == DW_TAG_template_type_param
9612 || child_die->tag == DW_TAG_template_value_param)
9614 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
9615 struct template_symbol);
9616 templ_func->base.is_cplus_template_function = 1;
9621 new = push_context (0, lowpc);
9622 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
9623 (struct symbol *) templ_func);
9625 /* If there is a location expression for DW_AT_frame_base, record
9627 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
9629 dwarf2_symbol_mark_computed (attr, new->name, cu, 1);
9631 cu->list_in_scope = &local_symbols;
9633 if (die->child != NULL)
9635 child_die = die->child;
9636 while (child_die && child_die->tag)
9638 if (child_die->tag == DW_TAG_template_type_param
9639 || child_die->tag == DW_TAG_template_value_param)
9641 struct symbol *arg = new_symbol (child_die, NULL, cu);
9644 VEC_safe_push (symbolp, template_args, arg);
9647 process_die (child_die, cu);
9648 child_die = sibling_die (child_die);
9652 inherit_abstract_dies (die, cu);
9654 /* If we have a DW_AT_specification, we might need to import using
9655 directives from the context of the specification DIE. See the
9656 comment in determine_prefix. */
9657 if (cu->language == language_cplus
9658 && dwarf2_attr (die, DW_AT_specification, cu))
9660 struct dwarf2_cu *spec_cu = cu;
9661 struct die_info *spec_die = die_specification (die, &spec_cu);
9665 child_die = spec_die->child;
9666 while (child_die && child_die->tag)
9668 if (child_die->tag == DW_TAG_imported_module)
9669 process_die (child_die, spec_cu);
9670 child_die = sibling_die (child_die);
9673 /* In some cases, GCC generates specification DIEs that
9674 themselves contain DW_AT_specification attributes. */
9675 spec_die = die_specification (spec_die, &spec_cu);
9679 new = pop_context ();
9680 /* Make a block for the local symbols within. */
9681 block = finish_block (new->name, &local_symbols, new->old_blocks,
9682 lowpc, highpc, objfile);
9684 /* For C++, set the block's scope. */
9685 if ((cu->language == language_cplus || cu->language == language_fortran)
9686 && cu->processing_has_namespace_info)
9687 block_set_scope (block, determine_prefix (die, cu),
9688 &objfile->objfile_obstack);
9690 /* If we have address ranges, record them. */
9691 dwarf2_record_block_ranges (die, block, baseaddr, cu);
9693 /* Attach template arguments to function. */
9694 if (! VEC_empty (symbolp, template_args))
9696 gdb_assert (templ_func != NULL);
9698 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
9699 templ_func->template_arguments
9700 = obstack_alloc (&objfile->objfile_obstack,
9701 (templ_func->n_template_arguments
9702 * sizeof (struct symbol *)));
9703 memcpy (templ_func->template_arguments,
9704 VEC_address (symbolp, template_args),
9705 (templ_func->n_template_arguments * sizeof (struct symbol *)));
9706 VEC_free (symbolp, template_args);
9709 /* In C++, we can have functions nested inside functions (e.g., when
9710 a function declares a class that has methods). This means that
9711 when we finish processing a function scope, we may need to go
9712 back to building a containing block's symbol lists. */
9713 local_symbols = new->locals;
9714 using_directives = new->using_directives;
9716 /* If we've finished processing a top-level function, subsequent
9717 symbols go in the file symbol list. */
9718 if (outermost_context_p ())
9719 cu->list_in_scope = &file_symbols;
9722 /* Process all the DIES contained within a lexical block scope. Start
9723 a new scope, process the dies, and then close the scope. */
9726 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
9728 struct objfile *objfile = cu->objfile;
9729 struct context_stack *new;
9730 CORE_ADDR lowpc, highpc;
9731 struct die_info *child_die;
9734 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9736 /* Ignore blocks with missing or invalid low and high pc attributes. */
9737 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9738 as multiple lexical blocks? Handling children in a sane way would
9739 be nasty. Might be easier to properly extend generic blocks to
9741 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
9746 push_context (0, lowpc);
9747 if (die->child != NULL)
9749 child_die = die->child;
9750 while (child_die && child_die->tag)
9752 process_die (child_die, cu);
9753 child_die = sibling_die (child_die);
9756 new = pop_context ();
9758 if (local_symbols != NULL || using_directives != NULL)
9761 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
9764 /* Note that recording ranges after traversing children, as we
9765 do here, means that recording a parent's ranges entails
9766 walking across all its children's ranges as they appear in
9767 the address map, which is quadratic behavior.
9769 It would be nicer to record the parent's ranges before
9770 traversing its children, simply overriding whatever you find
9771 there. But since we don't even decide whether to create a
9772 block until after we've traversed its children, that's hard
9774 dwarf2_record_block_ranges (die, block, baseaddr, cu);
9776 local_symbols = new->locals;
9777 using_directives = new->using_directives;
9780 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9783 read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
9785 struct objfile *objfile = cu->objfile;
9786 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9787 CORE_ADDR pc, baseaddr;
9788 struct attribute *attr;
9789 struct call_site *call_site, call_site_local;
9792 struct die_info *child_die;
9794 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9796 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
9799 complaint (&symfile_complaints,
9800 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9801 "DIE 0x%x [in module %s]"),
9802 die->offset.sect_off, objfile->name);
9805 pc = DW_ADDR (attr) + baseaddr;
9807 if (cu->call_site_htab == NULL)
9808 cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
9809 NULL, &objfile->objfile_obstack,
9810 hashtab_obstack_allocate, NULL);
9811 call_site_local.pc = pc;
9812 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
9815 complaint (&symfile_complaints,
9816 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9817 "DIE 0x%x [in module %s]"),
9818 paddress (gdbarch, pc), die->offset.sect_off, objfile->name);
9822 /* Count parameters at the caller. */
9825 for (child_die = die->child; child_die && child_die->tag;
9826 child_die = sibling_die (child_die))
9828 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
9830 complaint (&symfile_complaints,
9831 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9832 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9833 child_die->tag, child_die->offset.sect_off, objfile->name);
9840 call_site = obstack_alloc (&objfile->objfile_obstack,
9841 (sizeof (*call_site)
9842 + (sizeof (*call_site->parameter)
9845 memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
9848 if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
9850 struct die_info *func_die;
9852 /* Skip also over DW_TAG_inlined_subroutine. */
9853 for (func_die = die->parent;
9854 func_die && func_die->tag != DW_TAG_subprogram
9855 && func_die->tag != DW_TAG_subroutine_type;
9856 func_die = func_die->parent);
9858 /* DW_AT_GNU_all_call_sites is a superset
9859 of DW_AT_GNU_all_tail_call_sites. */
9861 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
9862 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
9864 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9865 not complete. But keep CALL_SITE for look ups via call_site_htab,
9866 both the initial caller containing the real return address PC and
9867 the final callee containing the current PC of a chain of tail
9868 calls do not need to have the tail call list complete. But any
9869 function candidate for a virtual tail call frame searched via
9870 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9871 determined unambiguously. */
9875 struct type *func_type = NULL;
9878 func_type = get_die_type (func_die, cu);
9879 if (func_type != NULL)
9881 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
9883 /* Enlist this call site to the function. */
9884 call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
9885 TYPE_TAIL_CALL_LIST (func_type) = call_site;
9888 complaint (&symfile_complaints,
9889 _("Cannot find function owning DW_TAG_GNU_call_site "
9890 "DIE 0x%x [in module %s]"),
9891 die->offset.sect_off, objfile->name);
9895 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
9897 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
9898 SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
9899 if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
9900 /* Keep NULL DWARF_BLOCK. */;
9901 else if (attr_form_is_block (attr))
9903 struct dwarf2_locexpr_baton *dlbaton;
9905 dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton));
9906 dlbaton->data = DW_BLOCK (attr)->data;
9907 dlbaton->size = DW_BLOCK (attr)->size;
9908 dlbaton->per_cu = cu->per_cu;
9910 SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
9912 else if (is_ref_attr (attr))
9914 struct dwarf2_cu *target_cu = cu;
9915 struct die_info *target_die;
9917 target_die = follow_die_ref_or_sig (die, attr, &target_cu);
9918 gdb_assert (target_cu->objfile == objfile);
9919 if (die_is_declaration (target_die, target_cu))
9921 const char *target_physname = NULL;
9922 struct attribute *target_attr;
9924 /* Prefer the mangled name; otherwise compute the demangled one. */
9925 target_attr = dwarf2_attr (target_die, DW_AT_linkage_name, target_cu);
9926 if (target_attr == NULL)
9927 target_attr = dwarf2_attr (target_die, DW_AT_MIPS_linkage_name,
9929 if (target_attr != NULL && DW_STRING (target_attr) != NULL)
9930 target_physname = DW_STRING (target_attr);
9932 target_physname = dwarf2_physname (NULL, target_die, target_cu);
9933 if (target_physname == NULL)
9934 complaint (&symfile_complaints,
9935 _("DW_AT_GNU_call_site_target target DIE has invalid "
9936 "physname, for referencing DIE 0x%x [in module %s]"),
9937 die->offset.sect_off, objfile->name);
9939 SET_FIELD_PHYSNAME (call_site->target, target_physname);
9945 /* DW_AT_entry_pc should be preferred. */
9946 if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
9947 complaint (&symfile_complaints,
9948 _("DW_AT_GNU_call_site_target target DIE has invalid "
9949 "low pc, for referencing DIE 0x%x [in module %s]"),
9950 die->offset.sect_off, objfile->name);
9952 SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
9956 complaint (&symfile_complaints,
9957 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9958 "block nor reference, for DIE 0x%x [in module %s]"),
9959 die->offset.sect_off, objfile->name);
9961 call_site->per_cu = cu->per_cu;
9963 for (child_die = die->child;
9964 child_die && child_die->tag;
9965 child_die = sibling_die (child_die))
9967 struct call_site_parameter *parameter;
9968 struct attribute *loc, *origin;
9970 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
9972 /* Already printed the complaint above. */
9976 gdb_assert (call_site->parameter_count < nparams);
9977 parameter = &call_site->parameter[call_site->parameter_count];
9979 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9980 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9981 register is contained in DW_AT_GNU_call_site_value. */
9983 loc = dwarf2_attr (child_die, DW_AT_location, cu);
9984 origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu);
9985 if (loc == NULL && origin != NULL && is_ref_attr (origin))
9989 parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET;
9990 offset = dwarf2_get_ref_die_offset (origin);
9991 if (!offset_in_cu_p (&cu->header, offset))
9993 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9994 binding can be done only inside one CU. Such referenced DIE
9995 therefore cannot be even moved to DW_TAG_partial_unit. */
9996 complaint (&symfile_complaints,
9997 _("DW_AT_abstract_origin offset is not in CU for "
9998 "DW_TAG_GNU_call_site child DIE 0x%x "
10000 child_die->offset.sect_off, objfile->name);
10003 parameter->u.param_offset.cu_off = (offset.sect_off
10004 - cu->header.offset.sect_off);
10006 else if (loc == NULL || origin != NULL || !attr_form_is_block (loc))
10008 complaint (&symfile_complaints,
10009 _("No DW_FORM_block* DW_AT_location for "
10010 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10011 child_die->offset.sect_off, objfile->name);
10016 parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg
10017 (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]);
10018 if (parameter->u.dwarf_reg != -1)
10019 parameter->kind = CALL_SITE_PARAMETER_DWARF_REG;
10020 else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data,
10021 &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size],
10022 ¶meter->u.fb_offset))
10023 parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET;
10026 complaint (&symfile_complaints,
10027 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
10028 "for DW_FORM_block* DW_AT_location is supported for "
10029 "DW_TAG_GNU_call_site child DIE 0x%x "
10031 child_die->offset.sect_off, objfile->name);
10036 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
10037 if (!attr_form_is_block (attr))
10039 complaint (&symfile_complaints,
10040 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
10041 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10042 child_die->offset.sect_off, objfile->name);
10045 parameter->value = DW_BLOCK (attr)->data;
10046 parameter->value_size = DW_BLOCK (attr)->size;
10048 /* Parameters are not pre-cleared by memset above. */
10049 parameter->data_value = NULL;
10050 parameter->data_value_size = 0;
10051 call_site->parameter_count++;
10053 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
10056 if (!attr_form_is_block (attr))
10057 complaint (&symfile_complaints,
10058 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
10059 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10060 child_die->offset.sect_off, objfile->name);
10063 parameter->data_value = DW_BLOCK (attr)->data;
10064 parameter->data_value_size = DW_BLOCK (attr)->size;
10070 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
10071 Return 1 if the attributes are present and valid, otherwise, return 0.
10072 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
10075 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
10076 CORE_ADDR *high_return, struct dwarf2_cu *cu,
10077 struct partial_symtab *ranges_pst)
10079 struct objfile *objfile = cu->objfile;
10080 struct comp_unit_head *cu_header = &cu->header;
10081 bfd *obfd = objfile->obfd;
10082 unsigned int addr_size = cu_header->addr_size;
10083 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
10084 /* Base address selection entry. */
10087 unsigned int dummy;
10092 CORE_ADDR high = 0;
10093 CORE_ADDR baseaddr;
10095 found_base = cu->base_known;
10096 base = cu->base_address;
10098 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
10099 if (offset >= dwarf2_per_objfile->ranges.size)
10101 complaint (&symfile_complaints,
10102 _("Offset %d out of bounds for DW_AT_ranges attribute"),
10106 buffer = dwarf2_per_objfile->ranges.buffer + offset;
10108 /* Read in the largest possible address. */
10109 marker = read_address (obfd, buffer, cu, &dummy);
10110 if ((marker & mask) == mask)
10112 /* If we found the largest possible address, then
10113 read the base address. */
10114 base = read_address (obfd, buffer + addr_size, cu, &dummy);
10115 buffer += 2 * addr_size;
10116 offset += 2 * addr_size;
10122 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10126 CORE_ADDR range_beginning, range_end;
10128 range_beginning = read_address (obfd, buffer, cu, &dummy);
10129 buffer += addr_size;
10130 range_end = read_address (obfd, buffer, cu, &dummy);
10131 buffer += addr_size;
10132 offset += 2 * addr_size;
10134 /* An end of list marker is a pair of zero addresses. */
10135 if (range_beginning == 0 && range_end == 0)
10136 /* Found the end of list entry. */
10139 /* Each base address selection entry is a pair of 2 values.
10140 The first is the largest possible address, the second is
10141 the base address. Check for a base address here. */
10142 if ((range_beginning & mask) == mask)
10144 /* If we found the largest possible address, then
10145 read the base address. */
10146 base = read_address (obfd, buffer + addr_size, cu, &dummy);
10153 /* We have no valid base address for the ranges
10155 complaint (&symfile_complaints,
10156 _("Invalid .debug_ranges data (no base address)"));
10160 if (range_beginning > range_end)
10162 /* Inverted range entries are invalid. */
10163 complaint (&symfile_complaints,
10164 _("Invalid .debug_ranges data (inverted range)"));
10168 /* Empty range entries have no effect. */
10169 if (range_beginning == range_end)
10172 range_beginning += base;
10175 /* A not-uncommon case of bad debug info.
10176 Don't pollute the addrmap with bad data. */
10177 if (range_beginning + baseaddr == 0
10178 && !dwarf2_per_objfile->has_section_at_zero)
10180 complaint (&symfile_complaints,
10181 _(".debug_ranges entry has start address of zero"
10182 " [in module %s]"), objfile->name);
10186 if (ranges_pst != NULL)
10187 addrmap_set_empty (objfile->psymtabs_addrmap,
10188 range_beginning + baseaddr,
10189 range_end - 1 + baseaddr,
10192 /* FIXME: This is recording everything as a low-high
10193 segment of consecutive addresses. We should have a
10194 data structure for discontiguous block ranges
10198 low = range_beginning;
10204 if (range_beginning < low)
10205 low = range_beginning;
10206 if (range_end > high)
10212 /* If the first entry is an end-of-list marker, the range
10213 describes an empty scope, i.e. no instructions. */
10219 *high_return = high;
10223 /* Get low and high pc attributes from a die. Return 1 if the attributes
10224 are present and valid, otherwise, return 0. Return -1 if the range is
10225 discontinuous, i.e. derived from DW_AT_ranges information. */
10228 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
10229 CORE_ADDR *highpc, struct dwarf2_cu *cu,
10230 struct partial_symtab *pst)
10232 struct attribute *attr;
10233 struct attribute *attr_high;
10235 CORE_ADDR high = 0;
10238 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
10241 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
10244 low = DW_ADDR (attr);
10245 if (attr_high->form == DW_FORM_addr
10246 || attr_high->form == DW_FORM_GNU_addr_index)
10247 high = DW_ADDR (attr_high);
10249 high = low + DW_UNSND (attr_high);
10252 /* Found high w/o low attribute. */
10255 /* Found consecutive range of addresses. */
10260 attr = dwarf2_attr (die, DW_AT_ranges, cu);
10263 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10264 We take advantage of the fact that DW_AT_ranges does not appear
10265 in DW_TAG_compile_unit of DWO files. */
10266 int need_ranges_base = die->tag != DW_TAG_compile_unit;
10267 unsigned int ranges_offset = (DW_UNSND (attr)
10268 + (need_ranges_base
10272 /* Value of the DW_AT_ranges attribute is the offset in the
10273 .debug_ranges section. */
10274 if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst))
10276 /* Found discontinuous range of addresses. */
10281 /* read_partial_die has also the strict LOW < HIGH requirement. */
10285 /* When using the GNU linker, .gnu.linkonce. sections are used to
10286 eliminate duplicate copies of functions and vtables and such.
10287 The linker will arbitrarily choose one and discard the others.
10288 The AT_*_pc values for such functions refer to local labels in
10289 these sections. If the section from that file was discarded, the
10290 labels are not in the output, so the relocs get a value of 0.
10291 If this is a discarded function, mark the pc bounds as invalid,
10292 so that GDB will ignore it. */
10293 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
10302 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10303 its low and high PC addresses. Do nothing if these addresses could not
10304 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10305 and HIGHPC to the high address if greater than HIGHPC. */
10308 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
10309 CORE_ADDR *lowpc, CORE_ADDR *highpc,
10310 struct dwarf2_cu *cu)
10312 CORE_ADDR low, high;
10313 struct die_info *child = die->child;
10315 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
10317 *lowpc = min (*lowpc, low);
10318 *highpc = max (*highpc, high);
10321 /* If the language does not allow nested subprograms (either inside
10322 subprograms or lexical blocks), we're done. */
10323 if (cu->language != language_ada)
10326 /* Check all the children of the given DIE. If it contains nested
10327 subprograms, then check their pc bounds. Likewise, we need to
10328 check lexical blocks as well, as they may also contain subprogram
10330 while (child && child->tag)
10332 if (child->tag == DW_TAG_subprogram
10333 || child->tag == DW_TAG_lexical_block)
10334 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
10335 child = sibling_die (child);
10339 /* Get the low and high pc's represented by the scope DIE, and store
10340 them in *LOWPC and *HIGHPC. If the correct values can't be
10341 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10344 get_scope_pc_bounds (struct die_info *die,
10345 CORE_ADDR *lowpc, CORE_ADDR *highpc,
10346 struct dwarf2_cu *cu)
10348 CORE_ADDR best_low = (CORE_ADDR) -1;
10349 CORE_ADDR best_high = (CORE_ADDR) 0;
10350 CORE_ADDR current_low, current_high;
10352 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
10354 best_low = current_low;
10355 best_high = current_high;
10359 struct die_info *child = die->child;
10361 while (child && child->tag)
10363 switch (child->tag) {
10364 case DW_TAG_subprogram:
10365 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
10367 case DW_TAG_namespace:
10368 case DW_TAG_module:
10369 /* FIXME: carlton/2004-01-16: Should we do this for
10370 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10371 that current GCC's always emit the DIEs corresponding
10372 to definitions of methods of classes as children of a
10373 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10374 the DIEs giving the declarations, which could be
10375 anywhere). But I don't see any reason why the
10376 standards says that they have to be there. */
10377 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
10379 if (current_low != ((CORE_ADDR) -1))
10381 best_low = min (best_low, current_low);
10382 best_high = max (best_high, current_high);
10390 child = sibling_die (child);
10395 *highpc = best_high;
10398 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10402 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
10403 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
10405 struct objfile *objfile = cu->objfile;
10406 struct attribute *attr;
10407 struct attribute *attr_high;
10409 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
10412 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
10415 CORE_ADDR low = DW_ADDR (attr);
10417 if (attr_high->form == DW_FORM_addr
10418 || attr_high->form == DW_FORM_GNU_addr_index)
10419 high = DW_ADDR (attr_high);
10421 high = low + DW_UNSND (attr_high);
10423 record_block_range (block, baseaddr + low, baseaddr + high - 1);
10427 attr = dwarf2_attr (die, DW_AT_ranges, cu);
10430 bfd *obfd = objfile->obfd;
10431 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10432 We take advantage of the fact that DW_AT_ranges does not appear
10433 in DW_TAG_compile_unit of DWO files. */
10434 int need_ranges_base = die->tag != DW_TAG_compile_unit;
10436 /* The value of the DW_AT_ranges attribute is the offset of the
10437 address range list in the .debug_ranges section. */
10438 unsigned long offset = (DW_UNSND (attr)
10439 + (need_ranges_base ? cu->ranges_base : 0));
10440 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
10442 /* For some target architectures, but not others, the
10443 read_address function sign-extends the addresses it returns.
10444 To recognize base address selection entries, we need a
10446 unsigned int addr_size = cu->header.addr_size;
10447 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
10449 /* The base address, to which the next pair is relative. Note
10450 that this 'base' is a DWARF concept: most entries in a range
10451 list are relative, to reduce the number of relocs against the
10452 debugging information. This is separate from this function's
10453 'baseaddr' argument, which GDB uses to relocate debugging
10454 information from a shared library based on the address at
10455 which the library was loaded. */
10456 CORE_ADDR base = cu->base_address;
10457 int base_known = cu->base_known;
10459 gdb_assert (dwarf2_per_objfile->ranges.readin);
10460 if (offset >= dwarf2_per_objfile->ranges.size)
10462 complaint (&symfile_complaints,
10463 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10470 unsigned int bytes_read;
10471 CORE_ADDR start, end;
10473 start = read_address (obfd, buffer, cu, &bytes_read);
10474 buffer += bytes_read;
10475 end = read_address (obfd, buffer, cu, &bytes_read);
10476 buffer += bytes_read;
10478 /* Did we find the end of the range list? */
10479 if (start == 0 && end == 0)
10482 /* Did we find a base address selection entry? */
10483 else if ((start & base_select_mask) == base_select_mask)
10489 /* We found an ordinary address range. */
10494 complaint (&symfile_complaints,
10495 _("Invalid .debug_ranges data "
10496 "(no base address)"));
10502 /* Inverted range entries are invalid. */
10503 complaint (&symfile_complaints,
10504 _("Invalid .debug_ranges data "
10505 "(inverted range)"));
10509 /* Empty range entries have no effect. */
10513 start += base + baseaddr;
10514 end += base + baseaddr;
10516 /* A not-uncommon case of bad debug info.
10517 Don't pollute the addrmap with bad data. */
10518 if (start == 0 && !dwarf2_per_objfile->has_section_at_zero)
10520 complaint (&symfile_complaints,
10521 _(".debug_ranges entry has start address of zero"
10522 " [in module %s]"), objfile->name);
10526 record_block_range (block, start, end - 1);
10532 /* Check whether the producer field indicates either of GCC < 4.6, or the
10533 Intel C/C++ compiler, and cache the result in CU. */
10536 check_producer (struct dwarf2_cu *cu)
10539 int major, minor, release;
10541 if (cu->producer == NULL)
10543 /* For unknown compilers expect their behavior is DWARF version
10546 GCC started to support .debug_types sections by -gdwarf-4 since
10547 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10548 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10549 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10550 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10552 else if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) == 0)
10554 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10556 cs = &cu->producer[strlen ("GNU ")];
10557 while (*cs && !isdigit (*cs))
10559 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
10561 /* Not recognized as GCC. */
10565 cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
10566 cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
10569 else if (strncmp (cu->producer, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10570 cu->producer_is_icc = 1;
10573 /* For other non-GCC compilers, expect their behavior is DWARF version
10577 cu->checked_producer = 1;
10580 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10581 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10582 during 4.6.0 experimental. */
10585 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
10587 if (!cu->checked_producer)
10588 check_producer (cu);
10590 return cu->producer_is_gxx_lt_4_6;
10593 /* Return the default accessibility type if it is not overriden by
10594 DW_AT_accessibility. */
10596 static enum dwarf_access_attribute
10597 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
10599 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
10601 /* The default DWARF 2 accessibility for members is public, the default
10602 accessibility for inheritance is private. */
10604 if (die->tag != DW_TAG_inheritance)
10605 return DW_ACCESS_public;
10607 return DW_ACCESS_private;
10611 /* DWARF 3+ defines the default accessibility a different way. The same
10612 rules apply now for DW_TAG_inheritance as for the members and it only
10613 depends on the container kind. */
10615 if (die->parent->tag == DW_TAG_class_type)
10616 return DW_ACCESS_private;
10618 return DW_ACCESS_public;
10622 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10623 offset. If the attribute was not found return 0, otherwise return
10624 1. If it was found but could not properly be handled, set *OFFSET
10628 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
10631 struct attribute *attr;
10633 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
10638 /* Note that we do not check for a section offset first here.
10639 This is because DW_AT_data_member_location is new in DWARF 4,
10640 so if we see it, we can assume that a constant form is really
10641 a constant and not a section offset. */
10642 if (attr_form_is_constant (attr))
10643 *offset = dwarf2_get_attr_constant_value (attr, 0);
10644 else if (attr_form_is_section_offset (attr))
10645 dwarf2_complex_location_expr_complaint ();
10646 else if (attr_form_is_block (attr))
10647 *offset = decode_locdesc (DW_BLOCK (attr), cu);
10649 dwarf2_complex_location_expr_complaint ();
10657 /* Add an aggregate field to the field list. */
10660 dwarf2_add_field (struct field_info *fip, struct die_info *die,
10661 struct dwarf2_cu *cu)
10663 struct objfile *objfile = cu->objfile;
10664 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10665 struct nextfield *new_field;
10666 struct attribute *attr;
10668 const char *fieldname = "";
10670 /* Allocate a new field list entry and link it in. */
10671 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
10672 make_cleanup (xfree, new_field);
10673 memset (new_field, 0, sizeof (struct nextfield));
10675 if (die->tag == DW_TAG_inheritance)
10677 new_field->next = fip->baseclasses;
10678 fip->baseclasses = new_field;
10682 new_field->next = fip->fields;
10683 fip->fields = new_field;
10687 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
10689 new_field->accessibility = DW_UNSND (attr);
10691 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
10692 if (new_field->accessibility != DW_ACCESS_public)
10693 fip->non_public_fields = 1;
10695 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
10697 new_field->virtuality = DW_UNSND (attr);
10699 new_field->virtuality = DW_VIRTUALITY_none;
10701 fp = &new_field->field;
10703 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
10707 /* Data member other than a C++ static data member. */
10709 /* Get type of field. */
10710 fp->type = die_type (die, cu);
10712 SET_FIELD_BITPOS (*fp, 0);
10714 /* Get bit size of field (zero if none). */
10715 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
10718 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
10722 FIELD_BITSIZE (*fp) = 0;
10725 /* Get bit offset of field. */
10726 if (handle_data_member_location (die, cu, &offset))
10727 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
10728 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
10731 if (gdbarch_bits_big_endian (gdbarch))
10733 /* For big endian bits, the DW_AT_bit_offset gives the
10734 additional bit offset from the MSB of the containing
10735 anonymous object to the MSB of the field. We don't
10736 have to do anything special since we don't need to
10737 know the size of the anonymous object. */
10738 SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr));
10742 /* For little endian bits, compute the bit offset to the
10743 MSB of the anonymous object, subtract off the number of
10744 bits from the MSB of the field to the MSB of the
10745 object, and then subtract off the number of bits of
10746 the field itself. The result is the bit offset of
10747 the LSB of the field. */
10748 int anonymous_size;
10749 int bit_offset = DW_UNSND (attr);
10751 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
10754 /* The size of the anonymous object containing
10755 the bit field is explicit, so use the
10756 indicated size (in bytes). */
10757 anonymous_size = DW_UNSND (attr);
10761 /* The size of the anonymous object containing
10762 the bit field must be inferred from the type
10763 attribute of the data member containing the
10765 anonymous_size = TYPE_LENGTH (fp->type);
10767 SET_FIELD_BITPOS (*fp,
10768 (FIELD_BITPOS (*fp)
10769 + anonymous_size * bits_per_byte
10770 - bit_offset - FIELD_BITSIZE (*fp)));
10774 /* Get name of field. */
10775 fieldname = dwarf2_name (die, cu);
10776 if (fieldname == NULL)
10779 /* The name is already allocated along with this objfile, so we don't
10780 need to duplicate it for the type. */
10781 fp->name = fieldname;
10783 /* Change accessibility for artificial fields (e.g. virtual table
10784 pointer or virtual base class pointer) to private. */
10785 if (dwarf2_attr (die, DW_AT_artificial, cu))
10787 FIELD_ARTIFICIAL (*fp) = 1;
10788 new_field->accessibility = DW_ACCESS_private;
10789 fip->non_public_fields = 1;
10792 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
10794 /* C++ static member. */
10796 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10797 is a declaration, but all versions of G++ as of this writing
10798 (so through at least 3.2.1) incorrectly generate
10799 DW_TAG_variable tags. */
10801 const char *physname;
10803 /* Get name of field. */
10804 fieldname = dwarf2_name (die, cu);
10805 if (fieldname == NULL)
10808 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10810 /* Only create a symbol if this is an external value.
10811 new_symbol checks this and puts the value in the global symbol
10812 table, which we want. If it is not external, new_symbol
10813 will try to put the value in cu->list_in_scope which is wrong. */
10814 && dwarf2_flag_true_p (die, DW_AT_external, cu))
10816 /* A static const member, not much different than an enum as far as
10817 we're concerned, except that we can support more types. */
10818 new_symbol (die, NULL, cu);
10821 /* Get physical name. */
10822 physname = dwarf2_physname (fieldname, die, cu);
10824 /* The name is already allocated along with this objfile, so we don't
10825 need to duplicate it for the type. */
10826 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
10827 FIELD_TYPE (*fp) = die_type (die, cu);
10828 FIELD_NAME (*fp) = fieldname;
10830 else if (die->tag == DW_TAG_inheritance)
10834 /* C++ base class field. */
10835 if (handle_data_member_location (die, cu, &offset))
10836 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
10837 FIELD_BITSIZE (*fp) = 0;
10838 FIELD_TYPE (*fp) = die_type (die, cu);
10839 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
10840 fip->nbaseclasses++;
10844 /* Add a typedef defined in the scope of the FIP's class. */
10847 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
10848 struct dwarf2_cu *cu)
10850 struct objfile *objfile = cu->objfile;
10851 struct typedef_field_list *new_field;
10852 struct attribute *attr;
10853 struct typedef_field *fp;
10854 char *fieldname = "";
10856 /* Allocate a new field list entry and link it in. */
10857 new_field = xzalloc (sizeof (*new_field));
10858 make_cleanup (xfree, new_field);
10860 gdb_assert (die->tag == DW_TAG_typedef);
10862 fp = &new_field->field;
10864 /* Get name of field. */
10865 fp->name = dwarf2_name (die, cu);
10866 if (fp->name == NULL)
10869 fp->type = read_type_die (die, cu);
10871 new_field->next = fip->typedef_field_list;
10872 fip->typedef_field_list = new_field;
10873 fip->typedef_field_list_count++;
10876 /* Create the vector of fields, and attach it to the type. */
10879 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
10880 struct dwarf2_cu *cu)
10882 int nfields = fip->nfields;
10884 /* Record the field count, allocate space for the array of fields,
10885 and create blank accessibility bitfields if necessary. */
10886 TYPE_NFIELDS (type) = nfields;
10887 TYPE_FIELDS (type) = (struct field *)
10888 TYPE_ALLOC (type, sizeof (struct field) * nfields);
10889 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
10891 if (fip->non_public_fields && cu->language != language_ada)
10893 ALLOCATE_CPLUS_STRUCT_TYPE (type);
10895 TYPE_FIELD_PRIVATE_BITS (type) =
10896 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
10897 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
10899 TYPE_FIELD_PROTECTED_BITS (type) =
10900 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
10901 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
10903 TYPE_FIELD_IGNORE_BITS (type) =
10904 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
10905 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
10908 /* If the type has baseclasses, allocate and clear a bit vector for
10909 TYPE_FIELD_VIRTUAL_BITS. */
10910 if (fip->nbaseclasses && cu->language != language_ada)
10912 int num_bytes = B_BYTES (fip->nbaseclasses);
10913 unsigned char *pointer;
10915 ALLOCATE_CPLUS_STRUCT_TYPE (type);
10916 pointer = TYPE_ALLOC (type, num_bytes);
10917 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
10918 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
10919 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
10922 /* Copy the saved-up fields into the field vector. Start from the head of
10923 the list, adding to the tail of the field array, so that they end up in
10924 the same order in the array in which they were added to the list. */
10925 while (nfields-- > 0)
10927 struct nextfield *fieldp;
10931 fieldp = fip->fields;
10932 fip->fields = fieldp->next;
10936 fieldp = fip->baseclasses;
10937 fip->baseclasses = fieldp->next;
10940 TYPE_FIELD (type, nfields) = fieldp->field;
10941 switch (fieldp->accessibility)
10943 case DW_ACCESS_private:
10944 if (cu->language != language_ada)
10945 SET_TYPE_FIELD_PRIVATE (type, nfields);
10948 case DW_ACCESS_protected:
10949 if (cu->language != language_ada)
10950 SET_TYPE_FIELD_PROTECTED (type, nfields);
10953 case DW_ACCESS_public:
10957 /* Unknown accessibility. Complain and treat it as public. */
10959 complaint (&symfile_complaints, _("unsupported accessibility %d"),
10960 fieldp->accessibility);
10964 if (nfields < fip->nbaseclasses)
10966 switch (fieldp->virtuality)
10968 case DW_VIRTUALITY_virtual:
10969 case DW_VIRTUALITY_pure_virtual:
10970 if (cu->language == language_ada)
10971 error (_("unexpected virtuality in component of Ada type"));
10972 SET_TYPE_FIELD_VIRTUAL (type, nfields);
10979 /* Return true if this member function is a constructor, false
10983 dwarf2_is_constructor (struct die_info *die, struct dwarf2_cu *cu)
10985 const char *fieldname;
10986 const char *typename;
10989 if (die->parent == NULL)
10992 if (die->parent->tag != DW_TAG_structure_type
10993 && die->parent->tag != DW_TAG_union_type
10994 && die->parent->tag != DW_TAG_class_type)
10997 fieldname = dwarf2_name (die, cu);
10998 typename = dwarf2_name (die->parent, cu);
10999 if (fieldname == NULL || typename == NULL)
11002 len = strlen (fieldname);
11003 return (strncmp (fieldname, typename, len) == 0
11004 && (typename[len] == '\0' || typename[len] == '<'));
11007 /* Add a member function to the proper fieldlist. */
11010 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
11011 struct type *type, struct dwarf2_cu *cu)
11013 struct objfile *objfile = cu->objfile;
11014 struct attribute *attr;
11015 struct fnfieldlist *flp;
11017 struct fn_field *fnp;
11018 const char *fieldname;
11019 struct nextfnfield *new_fnfield;
11020 struct type *this_type;
11021 enum dwarf_access_attribute accessibility;
11023 if (cu->language == language_ada)
11024 error (_("unexpected member function in Ada type"));
11026 /* Get name of member function. */
11027 fieldname = dwarf2_name (die, cu);
11028 if (fieldname == NULL)
11031 /* Look up member function name in fieldlist. */
11032 for (i = 0; i < fip->nfnfields; i++)
11034 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
11038 /* Create new list element if necessary. */
11039 if (i < fip->nfnfields)
11040 flp = &fip->fnfieldlists[i];
11043 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
11045 fip->fnfieldlists = (struct fnfieldlist *)
11046 xrealloc (fip->fnfieldlists,
11047 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
11048 * sizeof (struct fnfieldlist));
11049 if (fip->nfnfields == 0)
11050 make_cleanup (free_current_contents, &fip->fnfieldlists);
11052 flp = &fip->fnfieldlists[fip->nfnfields];
11053 flp->name = fieldname;
11056 i = fip->nfnfields++;
11059 /* Create a new member function field and chain it to the field list
11061 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
11062 make_cleanup (xfree, new_fnfield);
11063 memset (new_fnfield, 0, sizeof (struct nextfnfield));
11064 new_fnfield->next = flp->head;
11065 flp->head = new_fnfield;
11068 /* Fill in the member function field info. */
11069 fnp = &new_fnfield->fnfield;
11071 /* Delay processing of the physname until later. */
11072 if (cu->language == language_cplus || cu->language == language_java)
11074 add_to_method_list (type, i, flp->length - 1, fieldname,
11079 const char *physname = dwarf2_physname (fieldname, die, cu);
11080 fnp->physname = physname ? physname : "";
11083 fnp->type = alloc_type (objfile);
11084 this_type = read_type_die (die, cu);
11085 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
11087 int nparams = TYPE_NFIELDS (this_type);
11089 /* TYPE is the domain of this method, and THIS_TYPE is the type
11090 of the method itself (TYPE_CODE_METHOD). */
11091 smash_to_method_type (fnp->type, type,
11092 TYPE_TARGET_TYPE (this_type),
11093 TYPE_FIELDS (this_type),
11094 TYPE_NFIELDS (this_type),
11095 TYPE_VARARGS (this_type));
11097 /* Handle static member functions.
11098 Dwarf2 has no clean way to discern C++ static and non-static
11099 member functions. G++ helps GDB by marking the first
11100 parameter for non-static member functions (which is the this
11101 pointer) as artificial. We obtain this information from
11102 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
11103 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
11104 fnp->voffset = VOFFSET_STATIC;
11107 complaint (&symfile_complaints, _("member function type missing for '%s'"),
11108 dwarf2_full_name (fieldname, die, cu));
11110 /* Get fcontext from DW_AT_containing_type if present. */
11111 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
11112 fnp->fcontext = die_containing_type (die, cu);
11114 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
11115 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
11117 /* Get accessibility. */
11118 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
11120 accessibility = DW_UNSND (attr);
11122 accessibility = dwarf2_default_access_attribute (die, cu);
11123 switch (accessibility)
11125 case DW_ACCESS_private:
11126 fnp->is_private = 1;
11128 case DW_ACCESS_protected:
11129 fnp->is_protected = 1;
11133 /* Check for artificial methods. */
11134 attr = dwarf2_attr (die, DW_AT_artificial, cu);
11135 if (attr && DW_UNSND (attr) != 0)
11136 fnp->is_artificial = 1;
11138 fnp->is_constructor = dwarf2_is_constructor (die, cu);
11140 /* Get index in virtual function table if it is a virtual member
11141 function. For older versions of GCC, this is an offset in the
11142 appropriate virtual table, as specified by DW_AT_containing_type.
11143 For everyone else, it is an expression to be evaluated relative
11144 to the object address. */
11146 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
11149 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
11151 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
11153 /* Old-style GCC. */
11154 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
11156 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
11157 || (DW_BLOCK (attr)->size > 1
11158 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
11159 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
11161 struct dwarf_block blk;
11164 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
11166 blk.size = DW_BLOCK (attr)->size - offset;
11167 blk.data = DW_BLOCK (attr)->data + offset;
11168 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
11169 if ((fnp->voffset % cu->header.addr_size) != 0)
11170 dwarf2_complex_location_expr_complaint ();
11172 fnp->voffset /= cu->header.addr_size;
11176 dwarf2_complex_location_expr_complaint ();
11178 if (!fnp->fcontext)
11179 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
11181 else if (attr_form_is_section_offset (attr))
11183 dwarf2_complex_location_expr_complaint ();
11187 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
11193 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
11194 if (attr && DW_UNSND (attr))
11196 /* GCC does this, as of 2008-08-25; PR debug/37237. */
11197 complaint (&symfile_complaints,
11198 _("Member function \"%s\" (offset %d) is virtual "
11199 "but the vtable offset is not specified"),
11200 fieldname, die->offset.sect_off);
11201 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11202 TYPE_CPLUS_DYNAMIC (type) = 1;
11207 /* Create the vector of member function fields, and attach it to the type. */
11210 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
11211 struct dwarf2_cu *cu)
11213 struct fnfieldlist *flp;
11216 if (cu->language == language_ada)
11217 error (_("unexpected member functions in Ada type"));
11219 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11220 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
11221 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
11223 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
11225 struct nextfnfield *nfp = flp->head;
11226 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
11229 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
11230 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
11231 fn_flp->fn_fields = (struct fn_field *)
11232 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
11233 for (k = flp->length; (k--, nfp); nfp = nfp->next)
11234 fn_flp->fn_fields[k] = nfp->fnfield;
11237 TYPE_NFN_FIELDS (type) = fip->nfnfields;
11240 /* Returns non-zero if NAME is the name of a vtable member in CU's
11241 language, zero otherwise. */
11243 is_vtable_name (const char *name, struct dwarf2_cu *cu)
11245 static const char vptr[] = "_vptr";
11246 static const char vtable[] = "vtable";
11248 /* Look for the C++ and Java forms of the vtable. */
11249 if ((cu->language == language_java
11250 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
11251 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
11252 && is_cplus_marker (name[sizeof (vptr) - 1])))
11258 /* GCC outputs unnamed structures that are really pointers to member
11259 functions, with the ABI-specified layout. If TYPE describes
11260 such a structure, smash it into a member function type.
11262 GCC shouldn't do this; it should just output pointer to member DIEs.
11263 This is GCC PR debug/28767. */
11266 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
11268 struct type *pfn_type, *domain_type, *new_type;
11270 /* Check for a structure with no name and two children. */
11271 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
11274 /* Check for __pfn and __delta members. */
11275 if (TYPE_FIELD_NAME (type, 0) == NULL
11276 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
11277 || TYPE_FIELD_NAME (type, 1) == NULL
11278 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
11281 /* Find the type of the method. */
11282 pfn_type = TYPE_FIELD_TYPE (type, 0);
11283 if (pfn_type == NULL
11284 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
11285 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
11288 /* Look for the "this" argument. */
11289 pfn_type = TYPE_TARGET_TYPE (pfn_type);
11290 if (TYPE_NFIELDS (pfn_type) == 0
11291 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11292 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
11295 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
11296 new_type = alloc_type (objfile);
11297 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
11298 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
11299 TYPE_VARARGS (pfn_type));
11300 smash_to_methodptr_type (type, new_type);
11303 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11307 producer_is_icc (struct dwarf2_cu *cu)
11309 if (!cu->checked_producer)
11310 check_producer (cu);
11312 return cu->producer_is_icc;
11315 /* Called when we find the DIE that starts a structure or union scope
11316 (definition) to create a type for the structure or union. Fill in
11317 the type's name and general properties; the members will not be
11318 processed until process_structure_type.
11320 NOTE: we need to call these functions regardless of whether or not the
11321 DIE has a DW_AT_name attribute, since it might be an anonymous
11322 structure or union. This gets the type entered into our set of
11323 user defined types.
11325 However, if the structure is incomplete (an opaque struct/union)
11326 then suppress creating a symbol table entry for it since gdb only
11327 wants to find the one with the complete definition. Note that if
11328 it is complete, we just call new_symbol, which does it's own
11329 checking about whether the struct/union is anonymous or not (and
11330 suppresses creating a symbol table entry itself). */
11332 static struct type *
11333 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
11335 struct objfile *objfile = cu->objfile;
11337 struct attribute *attr;
11340 /* If the definition of this type lives in .debug_types, read that type.
11341 Don't follow DW_AT_specification though, that will take us back up
11342 the chain and we want to go down. */
11343 attr = dwarf2_attr_no_follow (die, DW_AT_signature);
11346 struct dwarf2_cu *type_cu = cu;
11347 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11349 /* We could just recurse on read_structure_type, but we need to call
11350 get_die_type to ensure only one type for this DIE is created.
11351 This is important, for example, because for c++ classes we need
11352 TYPE_NAME set which is only done by new_symbol. Blech. */
11353 type = read_type_die (type_die, type_cu);
11355 /* TYPE_CU may not be the same as CU.
11356 Ensure TYPE is recorded in CU's type_hash table. */
11357 return set_die_type (die, type, cu);
11360 type = alloc_type (objfile);
11361 INIT_CPLUS_SPECIFIC (type);
11363 name = dwarf2_name (die, cu);
11366 if (cu->language == language_cplus
11367 || cu->language == language_java)
11369 const char *full_name = dwarf2_full_name (name, die, cu);
11371 /* dwarf2_full_name might have already finished building the DIE's
11372 type. If so, there is no need to continue. */
11373 if (get_die_type (die, cu) != NULL)
11374 return get_die_type (die, cu);
11376 TYPE_TAG_NAME (type) = full_name;
11377 if (die->tag == DW_TAG_structure_type
11378 || die->tag == DW_TAG_class_type)
11379 TYPE_NAME (type) = TYPE_TAG_NAME (type);
11383 /* The name is already allocated along with this objfile, so
11384 we don't need to duplicate it for the type. */
11385 TYPE_TAG_NAME (type) = name;
11386 if (die->tag == DW_TAG_class_type)
11387 TYPE_NAME (type) = TYPE_TAG_NAME (type);
11391 if (die->tag == DW_TAG_structure_type)
11393 TYPE_CODE (type) = TYPE_CODE_STRUCT;
11395 else if (die->tag == DW_TAG_union_type)
11397 TYPE_CODE (type) = TYPE_CODE_UNION;
11401 TYPE_CODE (type) = TYPE_CODE_CLASS;
11404 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
11405 TYPE_DECLARED_CLASS (type) = 1;
11407 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11410 TYPE_LENGTH (type) = DW_UNSND (attr);
11414 TYPE_LENGTH (type) = 0;
11417 if (producer_is_icc (cu))
11419 /* ICC does not output the required DW_AT_declaration
11420 on incomplete types, but gives them a size of zero. */
11423 TYPE_STUB_SUPPORTED (type) = 1;
11425 if (die_is_declaration (die, cu))
11426 TYPE_STUB (type) = 1;
11427 else if (attr == NULL && die->child == NULL
11428 && producer_is_realview (cu->producer))
11429 /* RealView does not output the required DW_AT_declaration
11430 on incomplete types. */
11431 TYPE_STUB (type) = 1;
11433 /* We need to add the type field to the die immediately so we don't
11434 infinitely recurse when dealing with pointers to the structure
11435 type within the structure itself. */
11436 set_die_type (die, type, cu);
11438 /* set_die_type should be already done. */
11439 set_descriptive_type (type, die, cu);
11444 /* Finish creating a structure or union type, including filling in
11445 its members and creating a symbol for it. */
11448 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
11450 struct objfile *objfile = cu->objfile;
11451 struct die_info *child_die = die->child;
11454 type = get_die_type (die, cu);
11456 type = read_structure_type (die, cu);
11458 if (die->child != NULL && ! die_is_declaration (die, cu))
11460 struct field_info fi;
11461 struct die_info *child_die;
11462 VEC (symbolp) *template_args = NULL;
11463 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
11465 memset (&fi, 0, sizeof (struct field_info));
11467 child_die = die->child;
11469 while (child_die && child_die->tag)
11471 if (child_die->tag == DW_TAG_member
11472 || child_die->tag == DW_TAG_variable)
11474 /* NOTE: carlton/2002-11-05: A C++ static data member
11475 should be a DW_TAG_member that is a declaration, but
11476 all versions of G++ as of this writing (so through at
11477 least 3.2.1) incorrectly generate DW_TAG_variable
11478 tags for them instead. */
11479 dwarf2_add_field (&fi, child_die, cu);
11481 else if (child_die->tag == DW_TAG_subprogram)
11483 /* C++ member function. */
11484 dwarf2_add_member_fn (&fi, child_die, type, cu);
11486 else if (child_die->tag == DW_TAG_inheritance)
11488 /* C++ base class field. */
11489 dwarf2_add_field (&fi, child_die, cu);
11491 else if (child_die->tag == DW_TAG_typedef)
11492 dwarf2_add_typedef (&fi, child_die, cu);
11493 else if (child_die->tag == DW_TAG_template_type_param
11494 || child_die->tag == DW_TAG_template_value_param)
11496 struct symbol *arg = new_symbol (child_die, NULL, cu);
11499 VEC_safe_push (symbolp, template_args, arg);
11502 child_die = sibling_die (child_die);
11505 /* Attach template arguments to type. */
11506 if (! VEC_empty (symbolp, template_args))
11508 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11509 TYPE_N_TEMPLATE_ARGUMENTS (type)
11510 = VEC_length (symbolp, template_args);
11511 TYPE_TEMPLATE_ARGUMENTS (type)
11512 = obstack_alloc (&objfile->objfile_obstack,
11513 (TYPE_N_TEMPLATE_ARGUMENTS (type)
11514 * sizeof (struct symbol *)));
11515 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
11516 VEC_address (symbolp, template_args),
11517 (TYPE_N_TEMPLATE_ARGUMENTS (type)
11518 * sizeof (struct symbol *)));
11519 VEC_free (symbolp, template_args);
11522 /* Attach fields and member functions to the type. */
11524 dwarf2_attach_fields_to_type (&fi, type, cu);
11527 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
11529 /* Get the type which refers to the base class (possibly this
11530 class itself) which contains the vtable pointer for the current
11531 class from the DW_AT_containing_type attribute. This use of
11532 DW_AT_containing_type is a GNU extension. */
11534 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
11536 struct type *t = die_containing_type (die, cu);
11538 TYPE_VPTR_BASETYPE (type) = t;
11543 /* Our own class provides vtbl ptr. */
11544 for (i = TYPE_NFIELDS (t) - 1;
11545 i >= TYPE_N_BASECLASSES (t);
11548 const char *fieldname = TYPE_FIELD_NAME (t, i);
11550 if (is_vtable_name (fieldname, cu))
11552 TYPE_VPTR_FIELDNO (type) = i;
11557 /* Complain if virtual function table field not found. */
11558 if (i < TYPE_N_BASECLASSES (t))
11559 complaint (&symfile_complaints,
11560 _("virtual function table pointer "
11561 "not found when defining class '%s'"),
11562 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
11567 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
11570 else if (cu->producer
11571 && strncmp (cu->producer,
11572 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11574 /* The IBM XLC compiler does not provide direct indication
11575 of the containing type, but the vtable pointer is
11576 always named __vfp. */
11580 for (i = TYPE_NFIELDS (type) - 1;
11581 i >= TYPE_N_BASECLASSES (type);
11584 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
11586 TYPE_VPTR_FIELDNO (type) = i;
11587 TYPE_VPTR_BASETYPE (type) = type;
11594 /* Copy fi.typedef_field_list linked list elements content into the
11595 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11596 if (fi.typedef_field_list)
11598 int i = fi.typedef_field_list_count;
11600 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11601 TYPE_TYPEDEF_FIELD_ARRAY (type)
11602 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
11603 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
11605 /* Reverse the list order to keep the debug info elements order. */
11608 struct typedef_field *dest, *src;
11610 dest = &TYPE_TYPEDEF_FIELD (type, i);
11611 src = &fi.typedef_field_list->field;
11612 fi.typedef_field_list = fi.typedef_field_list->next;
11617 do_cleanups (back_to);
11619 if (HAVE_CPLUS_STRUCT (type))
11620 TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
11623 quirk_gcc_member_function_pointer (type, objfile);
11625 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11626 snapshots) has been known to create a die giving a declaration
11627 for a class that has, as a child, a die giving a definition for a
11628 nested class. So we have to process our children even if the
11629 current die is a declaration. Normally, of course, a declaration
11630 won't have any children at all. */
11632 while (child_die != NULL && child_die->tag)
11634 if (child_die->tag == DW_TAG_member
11635 || child_die->tag == DW_TAG_variable
11636 || child_die->tag == DW_TAG_inheritance
11637 || child_die->tag == DW_TAG_template_value_param
11638 || child_die->tag == DW_TAG_template_type_param)
11643 process_die (child_die, cu);
11645 child_die = sibling_die (child_die);
11648 /* Do not consider external references. According to the DWARF standard,
11649 these DIEs are identified by the fact that they have no byte_size
11650 attribute, and a declaration attribute. */
11651 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
11652 || !die_is_declaration (die, cu))
11653 new_symbol (die, type, cu);
11656 /* Given a DW_AT_enumeration_type die, set its type. We do not
11657 complete the type's fields yet, or create any symbols. */
11659 static struct type *
11660 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
11662 struct objfile *objfile = cu->objfile;
11664 struct attribute *attr;
11667 /* If the definition of this type lives in .debug_types, read that type.
11668 Don't follow DW_AT_specification though, that will take us back up
11669 the chain and we want to go down. */
11670 attr = dwarf2_attr_no_follow (die, DW_AT_signature);
11673 struct dwarf2_cu *type_cu = cu;
11674 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11676 type = read_type_die (type_die, type_cu);
11678 /* TYPE_CU may not be the same as CU.
11679 Ensure TYPE is recorded in CU's type_hash table. */
11680 return set_die_type (die, type, cu);
11683 type = alloc_type (objfile);
11685 TYPE_CODE (type) = TYPE_CODE_ENUM;
11686 name = dwarf2_full_name (NULL, die, cu);
11688 TYPE_TAG_NAME (type) = name;
11690 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11693 TYPE_LENGTH (type) = DW_UNSND (attr);
11697 TYPE_LENGTH (type) = 0;
11700 /* The enumeration DIE can be incomplete. In Ada, any type can be
11701 declared as private in the package spec, and then defined only
11702 inside the package body. Such types are known as Taft Amendment
11703 Types. When another package uses such a type, an incomplete DIE
11704 may be generated by the compiler. */
11705 if (die_is_declaration (die, cu))
11706 TYPE_STUB (type) = 1;
11708 return set_die_type (die, type, cu);
11711 /* Given a pointer to a die which begins an enumeration, process all
11712 the dies that define the members of the enumeration, and create the
11713 symbol for the enumeration type.
11715 NOTE: We reverse the order of the element list. */
11718 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
11720 struct type *this_type;
11722 this_type = get_die_type (die, cu);
11723 if (this_type == NULL)
11724 this_type = read_enumeration_type (die, cu);
11726 if (die->child != NULL)
11728 struct die_info *child_die;
11729 struct symbol *sym;
11730 struct field *fields = NULL;
11731 int num_fields = 0;
11732 int unsigned_enum = 1;
11737 child_die = die->child;
11738 while (child_die && child_die->tag)
11740 if (child_die->tag != DW_TAG_enumerator)
11742 process_die (child_die, cu);
11746 name = dwarf2_name (child_die, cu);
11749 sym = new_symbol (child_die, this_type, cu);
11750 if (SYMBOL_VALUE (sym) < 0)
11755 else if ((mask & SYMBOL_VALUE (sym)) != 0)
11758 mask |= SYMBOL_VALUE (sym);
11760 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
11762 fields = (struct field *)
11764 (num_fields + DW_FIELD_ALLOC_CHUNK)
11765 * sizeof (struct field));
11768 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
11769 FIELD_TYPE (fields[num_fields]) = NULL;
11770 SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym));
11771 FIELD_BITSIZE (fields[num_fields]) = 0;
11777 child_die = sibling_die (child_die);
11782 TYPE_NFIELDS (this_type) = num_fields;
11783 TYPE_FIELDS (this_type) = (struct field *)
11784 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
11785 memcpy (TYPE_FIELDS (this_type), fields,
11786 sizeof (struct field) * num_fields);
11790 TYPE_UNSIGNED (this_type) = 1;
11792 TYPE_FLAG_ENUM (this_type) = 1;
11795 /* If we are reading an enum from a .debug_types unit, and the enum
11796 is a declaration, and the enum is not the signatured type in the
11797 unit, then we do not want to add a symbol for it. Adding a
11798 symbol would in some cases obscure the true definition of the
11799 enum, giving users an incomplete type when the definition is
11800 actually available. Note that we do not want to do this for all
11801 enums which are just declarations, because C++0x allows forward
11802 enum declarations. */
11803 if (cu->per_cu->is_debug_types
11804 && die_is_declaration (die, cu))
11806 struct signatured_type *sig_type;
11808 sig_type = (struct signatured_type *) cu->per_cu;
11809 gdb_assert (sig_type->type_offset_in_section.sect_off != 0);
11810 if (sig_type->type_offset_in_section.sect_off != die->offset.sect_off)
11814 new_symbol (die, this_type, cu);
11817 /* Extract all information from a DW_TAG_array_type DIE and put it in
11818 the DIE's type field. For now, this only handles one dimensional
11821 static struct type *
11822 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
11824 struct objfile *objfile = cu->objfile;
11825 struct die_info *child_die;
11827 struct type *element_type, *range_type, *index_type;
11828 struct type **range_types = NULL;
11829 struct attribute *attr;
11831 struct cleanup *back_to;
11834 element_type = die_type (die, cu);
11836 /* The die_type call above may have already set the type for this DIE. */
11837 type = get_die_type (die, cu);
11841 /* Irix 6.2 native cc creates array types without children for
11842 arrays with unspecified length. */
11843 if (die->child == NULL)
11845 index_type = objfile_type (objfile)->builtin_int;
11846 range_type = create_range_type (NULL, index_type, 0, -1);
11847 type = create_array_type (NULL, element_type, range_type);
11848 return set_die_type (die, type, cu);
11851 back_to = make_cleanup (null_cleanup, NULL);
11852 child_die = die->child;
11853 while (child_die && child_die->tag)
11855 if (child_die->tag == DW_TAG_subrange_type)
11857 struct type *child_type = read_type_die (child_die, cu);
11859 if (child_type != NULL)
11861 /* The range type was succesfully read. Save it for the
11862 array type creation. */
11863 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
11865 range_types = (struct type **)
11866 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
11867 * sizeof (struct type *));
11869 make_cleanup (free_current_contents, &range_types);
11871 range_types[ndim++] = child_type;
11874 child_die = sibling_die (child_die);
11877 /* Dwarf2 dimensions are output from left to right, create the
11878 necessary array types in backwards order. */
11880 type = element_type;
11882 if (read_array_order (die, cu) == DW_ORD_col_major)
11887 type = create_array_type (NULL, type, range_types[i++]);
11892 type = create_array_type (NULL, type, range_types[ndim]);
11895 /* Understand Dwarf2 support for vector types (like they occur on
11896 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11897 array type. This is not part of the Dwarf2/3 standard yet, but a
11898 custom vendor extension. The main difference between a regular
11899 array and the vector variant is that vectors are passed by value
11901 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
11903 make_vector_type (type);
11905 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11906 implementation may choose to implement triple vectors using this
11908 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11911 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
11912 TYPE_LENGTH (type) = DW_UNSND (attr);
11914 complaint (&symfile_complaints,
11915 _("DW_AT_byte_size for array type smaller "
11916 "than the total size of elements"));
11919 name = dwarf2_name (die, cu);
11921 TYPE_NAME (type) = name;
11923 /* Install the type in the die. */
11924 set_die_type (die, type, cu);
11926 /* set_die_type should be already done. */
11927 set_descriptive_type (type, die, cu);
11929 do_cleanups (back_to);
11934 static enum dwarf_array_dim_ordering
11935 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
11937 struct attribute *attr;
11939 attr = dwarf2_attr (die, DW_AT_ordering, cu);
11941 if (attr) return DW_SND (attr);
11943 /* GNU F77 is a special case, as at 08/2004 array type info is the
11944 opposite order to the dwarf2 specification, but data is still
11945 laid out as per normal fortran.
11947 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11948 version checking. */
11950 if (cu->language == language_fortran
11951 && cu->producer && strstr (cu->producer, "GNU F77"))
11953 return DW_ORD_row_major;
11956 switch (cu->language_defn->la_array_ordering)
11958 case array_column_major:
11959 return DW_ORD_col_major;
11960 case array_row_major:
11962 return DW_ORD_row_major;
11966 /* Extract all information from a DW_TAG_set_type DIE and put it in
11967 the DIE's type field. */
11969 static struct type *
11970 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
11972 struct type *domain_type, *set_type;
11973 struct attribute *attr;
11975 domain_type = die_type (die, cu);
11977 /* The die_type call above may have already set the type for this DIE. */
11978 set_type = get_die_type (die, cu);
11982 set_type = create_set_type (NULL, domain_type);
11984 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11986 TYPE_LENGTH (set_type) = DW_UNSND (attr);
11988 return set_die_type (die, set_type, cu);
11991 /* A helper for read_common_block that creates a locexpr baton.
11992 SYM is the symbol which we are marking as computed.
11993 COMMON_DIE is the DIE for the common block.
11994 COMMON_LOC is the location expression attribute for the common
11996 MEMBER_LOC is the location expression attribute for the particular
11997 member of the common block that we are processing.
11998 CU is the CU from which the above come. */
12001 mark_common_block_symbol_computed (struct symbol *sym,
12002 struct die_info *common_die,
12003 struct attribute *common_loc,
12004 struct attribute *member_loc,
12005 struct dwarf2_cu *cu)
12007 struct objfile *objfile = dwarf2_per_objfile->objfile;
12008 struct dwarf2_locexpr_baton *baton;
12010 unsigned int cu_off;
12011 enum bfd_endian byte_order = gdbarch_byte_order (get_objfile_arch (objfile));
12012 LONGEST offset = 0;
12014 gdb_assert (common_loc && member_loc);
12015 gdb_assert (attr_form_is_block (common_loc));
12016 gdb_assert (attr_form_is_block (member_loc)
12017 || attr_form_is_constant (member_loc));
12019 baton = obstack_alloc (&objfile->objfile_obstack,
12020 sizeof (struct dwarf2_locexpr_baton));
12021 baton->per_cu = cu->per_cu;
12022 gdb_assert (baton->per_cu);
12024 baton->size = 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
12026 if (attr_form_is_constant (member_loc))
12028 offset = dwarf2_get_attr_constant_value (member_loc, 0);
12029 baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
12032 baton->size += DW_BLOCK (member_loc)->size;
12034 ptr = obstack_alloc (&objfile->objfile_obstack, baton->size);
12037 *ptr++ = DW_OP_call4;
12038 cu_off = common_die->offset.sect_off - cu->per_cu->offset.sect_off;
12039 store_unsigned_integer (ptr, 4, byte_order, cu_off);
12042 if (attr_form_is_constant (member_loc))
12044 *ptr++ = DW_OP_addr;
12045 store_unsigned_integer (ptr, cu->header.addr_size, byte_order, offset);
12046 ptr += cu->header.addr_size;
12050 /* We have to copy the data here, because DW_OP_call4 will only
12051 use a DW_AT_location attribute. */
12052 memcpy (ptr, DW_BLOCK (member_loc)->data, DW_BLOCK (member_loc)->size);
12053 ptr += DW_BLOCK (member_loc)->size;
12056 *ptr++ = DW_OP_plus;
12057 gdb_assert (ptr - baton->data == baton->size);
12059 SYMBOL_LOCATION_BATON (sym) = baton;
12060 SYMBOL_ACLASS_INDEX (sym) = dwarf2_locexpr_index;
12063 /* Create appropriate locally-scoped variables for all the
12064 DW_TAG_common_block entries. Also create a struct common_block
12065 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
12066 is used to sepate the common blocks name namespace from regular
12070 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
12072 struct attribute *attr;
12074 attr = dwarf2_attr (die, DW_AT_location, cu);
12077 /* Support the .debug_loc offsets. */
12078 if (attr_form_is_block (attr))
12082 else if (attr_form_is_section_offset (attr))
12084 dwarf2_complex_location_expr_complaint ();
12089 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12090 "common block member");
12095 if (die->child != NULL)
12097 struct objfile *objfile = cu->objfile;
12098 struct die_info *child_die;
12099 size_t n_entries = 0, size;
12100 struct common_block *common_block;
12101 struct symbol *sym;
12103 for (child_die = die->child;
12104 child_die && child_die->tag;
12105 child_die = sibling_die (child_die))
12108 size = (sizeof (struct common_block)
12109 + (n_entries - 1) * sizeof (struct symbol *));
12110 common_block = obstack_alloc (&objfile->objfile_obstack, size);
12111 memset (common_block->contents, 0, n_entries * sizeof (struct symbol *));
12112 common_block->n_entries = 0;
12114 for (child_die = die->child;
12115 child_die && child_die->tag;
12116 child_die = sibling_die (child_die))
12118 /* Create the symbol in the DW_TAG_common_block block in the current
12120 sym = new_symbol (child_die, NULL, cu);
12123 struct attribute *member_loc;
12125 common_block->contents[common_block->n_entries++] = sym;
12127 member_loc = dwarf2_attr (child_die, DW_AT_data_member_location,
12131 /* GDB has handled this for a long time, but it is
12132 not specified by DWARF. It seems to have been
12133 emitted by gfortran at least as recently as:
12134 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
12135 complaint (&symfile_complaints,
12136 _("Variable in common block has "
12137 "DW_AT_data_member_location "
12138 "- DIE at 0x%x [in module %s]"),
12139 child_die->offset.sect_off, cu->objfile->name);
12141 if (attr_form_is_section_offset (member_loc))
12142 dwarf2_complex_location_expr_complaint ();
12143 else if (attr_form_is_constant (member_loc)
12144 || attr_form_is_block (member_loc))
12147 mark_common_block_symbol_computed (sym, die, attr,
12151 dwarf2_complex_location_expr_complaint ();
12156 sym = new_symbol (die, objfile_type (objfile)->builtin_void, cu);
12157 SYMBOL_VALUE_COMMON_BLOCK (sym) = common_block;
12161 /* Create a type for a C++ namespace. */
12163 static struct type *
12164 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
12166 struct objfile *objfile = cu->objfile;
12167 const char *previous_prefix, *name;
12171 /* For extensions, reuse the type of the original namespace. */
12172 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
12174 struct die_info *ext_die;
12175 struct dwarf2_cu *ext_cu = cu;
12177 ext_die = dwarf2_extension (die, &ext_cu);
12178 type = read_type_die (ext_die, ext_cu);
12180 /* EXT_CU may not be the same as CU.
12181 Ensure TYPE is recorded in CU's type_hash table. */
12182 return set_die_type (die, type, cu);
12185 name = namespace_name (die, &is_anonymous, cu);
12187 /* Now build the name of the current namespace. */
12189 previous_prefix = determine_prefix (die, cu);
12190 if (previous_prefix[0] != '\0')
12191 name = typename_concat (&objfile->objfile_obstack,
12192 previous_prefix, name, 0, cu);
12194 /* Create the type. */
12195 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
12197 TYPE_NAME (type) = name;
12198 TYPE_TAG_NAME (type) = TYPE_NAME (type);
12200 return set_die_type (die, type, cu);
12203 /* Read a C++ namespace. */
12206 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
12208 struct objfile *objfile = cu->objfile;
12211 /* Add a symbol associated to this if we haven't seen the namespace
12212 before. Also, add a using directive if it's an anonymous
12215 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
12219 type = read_type_die (die, cu);
12220 new_symbol (die, type, cu);
12222 namespace_name (die, &is_anonymous, cu);
12225 const char *previous_prefix = determine_prefix (die, cu);
12227 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
12228 NULL, NULL, 0, &objfile->objfile_obstack);
12232 if (die->child != NULL)
12234 struct die_info *child_die = die->child;
12236 while (child_die && child_die->tag)
12238 process_die (child_die, cu);
12239 child_die = sibling_die (child_die);
12244 /* Read a Fortran module as type. This DIE can be only a declaration used for
12245 imported module. Still we need that type as local Fortran "use ... only"
12246 declaration imports depend on the created type in determine_prefix. */
12248 static struct type *
12249 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
12251 struct objfile *objfile = cu->objfile;
12252 const char *module_name;
12255 module_name = dwarf2_name (die, cu);
12257 complaint (&symfile_complaints,
12258 _("DW_TAG_module has no name, offset 0x%x"),
12259 die->offset.sect_off);
12260 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
12262 /* determine_prefix uses TYPE_TAG_NAME. */
12263 TYPE_TAG_NAME (type) = TYPE_NAME (type);
12265 return set_die_type (die, type, cu);
12268 /* Read a Fortran module. */
12271 read_module (struct die_info *die, struct dwarf2_cu *cu)
12273 struct die_info *child_die = die->child;
12275 while (child_die && child_die->tag)
12277 process_die (child_die, cu);
12278 child_die = sibling_die (child_die);
12282 /* Return the name of the namespace represented by DIE. Set
12283 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12286 static const char *
12287 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
12289 struct die_info *current_die;
12290 const char *name = NULL;
12292 /* Loop through the extensions until we find a name. */
12294 for (current_die = die;
12295 current_die != NULL;
12296 current_die = dwarf2_extension (die, &cu))
12298 name = dwarf2_name (current_die, cu);
12303 /* Is it an anonymous namespace? */
12305 *is_anonymous = (name == NULL);
12307 name = CP_ANONYMOUS_NAMESPACE_STR;
12312 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12313 the user defined type vector. */
12315 static struct type *
12316 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
12318 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
12319 struct comp_unit_head *cu_header = &cu->header;
12321 struct attribute *attr_byte_size;
12322 struct attribute *attr_address_class;
12323 int byte_size, addr_class;
12324 struct type *target_type;
12326 target_type = die_type (die, cu);
12328 /* The die_type call above may have already set the type for this DIE. */
12329 type = get_die_type (die, cu);
12333 type = lookup_pointer_type (target_type);
12335 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
12336 if (attr_byte_size)
12337 byte_size = DW_UNSND (attr_byte_size);
12339 byte_size = cu_header->addr_size;
12341 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
12342 if (attr_address_class)
12343 addr_class = DW_UNSND (attr_address_class);
12345 addr_class = DW_ADDR_none;
12347 /* If the pointer size or address class is different than the
12348 default, create a type variant marked as such and set the
12349 length accordingly. */
12350 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
12352 if (gdbarch_address_class_type_flags_p (gdbarch))
12356 type_flags = gdbarch_address_class_type_flags
12357 (gdbarch, byte_size, addr_class);
12358 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
12360 type = make_type_with_address_space (type, type_flags);
12362 else if (TYPE_LENGTH (type) != byte_size)
12364 complaint (&symfile_complaints,
12365 _("invalid pointer size %d"), byte_size);
12369 /* Should we also complain about unhandled address classes? */
12373 TYPE_LENGTH (type) = byte_size;
12374 return set_die_type (die, type, cu);
12377 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12378 the user defined type vector. */
12380 static struct type *
12381 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
12384 struct type *to_type;
12385 struct type *domain;
12387 to_type = die_type (die, cu);
12388 domain = die_containing_type (die, cu);
12390 /* The calls above may have already set the type for this DIE. */
12391 type = get_die_type (die, cu);
12395 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
12396 type = lookup_methodptr_type (to_type);
12397 else if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_FUNC)
12399 struct type *new_type = alloc_type (cu->objfile);
12401 smash_to_method_type (new_type, domain, TYPE_TARGET_TYPE (to_type),
12402 TYPE_FIELDS (to_type), TYPE_NFIELDS (to_type),
12403 TYPE_VARARGS (to_type));
12404 type = lookup_methodptr_type (new_type);
12407 type = lookup_memberptr_type (to_type, domain);
12409 return set_die_type (die, type, cu);
12412 /* Extract all information from a DW_TAG_reference_type DIE and add to
12413 the user defined type vector. */
12415 static struct type *
12416 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
12418 struct comp_unit_head *cu_header = &cu->header;
12419 struct type *type, *target_type;
12420 struct attribute *attr;
12422 target_type = die_type (die, cu);
12424 /* The die_type call above may have already set the type for this DIE. */
12425 type = get_die_type (die, cu);
12429 type = lookup_reference_type (target_type);
12430 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12433 TYPE_LENGTH (type) = DW_UNSND (attr);
12437 TYPE_LENGTH (type) = cu_header->addr_size;
12439 return set_die_type (die, type, cu);
12442 static struct type *
12443 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
12445 struct type *base_type, *cv_type;
12447 base_type = die_type (die, cu);
12449 /* The die_type call above may have already set the type for this DIE. */
12450 cv_type = get_die_type (die, cu);
12454 /* In case the const qualifier is applied to an array type, the element type
12455 is so qualified, not the array type (section 6.7.3 of C99). */
12456 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
12458 struct type *el_type, *inner_array;
12460 base_type = copy_type (base_type);
12461 inner_array = base_type;
12463 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
12465 TYPE_TARGET_TYPE (inner_array) =
12466 copy_type (TYPE_TARGET_TYPE (inner_array));
12467 inner_array = TYPE_TARGET_TYPE (inner_array);
12470 el_type = TYPE_TARGET_TYPE (inner_array);
12471 TYPE_TARGET_TYPE (inner_array) =
12472 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
12474 return set_die_type (die, base_type, cu);
12477 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
12478 return set_die_type (die, cv_type, cu);
12481 static struct type *
12482 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
12484 struct type *base_type, *cv_type;
12486 base_type = die_type (die, cu);
12488 /* The die_type call above may have already set the type for this DIE. */
12489 cv_type = get_die_type (die, cu);
12493 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
12494 return set_die_type (die, cv_type, cu);
12497 /* Handle DW_TAG_restrict_type. */
12499 static struct type *
12500 read_tag_restrict_type (struct die_info *die, struct dwarf2_cu *cu)
12502 struct type *base_type, *cv_type;
12504 base_type = die_type (die, cu);
12506 /* The die_type call above may have already set the type for this DIE. */
12507 cv_type = get_die_type (die, cu);
12511 cv_type = make_restrict_type (base_type);
12512 return set_die_type (die, cv_type, cu);
12515 /* Extract all information from a DW_TAG_string_type DIE and add to
12516 the user defined type vector. It isn't really a user defined type,
12517 but it behaves like one, with other DIE's using an AT_user_def_type
12518 attribute to reference it. */
12520 static struct type *
12521 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
12523 struct objfile *objfile = cu->objfile;
12524 struct gdbarch *gdbarch = get_objfile_arch (objfile);
12525 struct type *type, *range_type, *index_type, *char_type;
12526 struct attribute *attr;
12527 unsigned int length;
12529 attr = dwarf2_attr (die, DW_AT_string_length, cu);
12532 length = DW_UNSND (attr);
12536 /* Check for the DW_AT_byte_size attribute. */
12537 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12540 length = DW_UNSND (attr);
12548 index_type = objfile_type (objfile)->builtin_int;
12549 range_type = create_range_type (NULL, index_type, 1, length);
12550 char_type = language_string_char_type (cu->language_defn, gdbarch);
12551 type = create_string_type (NULL, char_type, range_type);
12553 return set_die_type (die, type, cu);
12556 /* Handle DIES due to C code like:
12560 int (*funcp)(int a, long l);
12564 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12566 static struct type *
12567 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
12569 struct objfile *objfile = cu->objfile;
12570 struct type *type; /* Type that this function returns. */
12571 struct type *ftype; /* Function that returns above type. */
12572 struct attribute *attr;
12574 type = die_type (die, cu);
12576 /* The die_type call above may have already set the type for this DIE. */
12577 ftype = get_die_type (die, cu);
12581 ftype = lookup_function_type (type);
12583 /* All functions in C++, Pascal and Java have prototypes. */
12584 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
12585 if ((attr && (DW_UNSND (attr) != 0))
12586 || cu->language == language_cplus
12587 || cu->language == language_java
12588 || cu->language == language_pascal)
12589 TYPE_PROTOTYPED (ftype) = 1;
12590 else if (producer_is_realview (cu->producer))
12591 /* RealView does not emit DW_AT_prototyped. We can not
12592 distinguish prototyped and unprototyped functions; default to
12593 prototyped, since that is more common in modern code (and
12594 RealView warns about unprototyped functions). */
12595 TYPE_PROTOTYPED (ftype) = 1;
12597 /* Store the calling convention in the type if it's available in
12598 the subroutine die. Otherwise set the calling convention to
12599 the default value DW_CC_normal. */
12600 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
12602 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
12603 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
12604 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
12606 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
12608 /* We need to add the subroutine type to the die immediately so
12609 we don't infinitely recurse when dealing with parameters
12610 declared as the same subroutine type. */
12611 set_die_type (die, ftype, cu);
12613 if (die->child != NULL)
12615 struct type *void_type = objfile_type (objfile)->builtin_void;
12616 struct die_info *child_die;
12617 int nparams, iparams;
12619 /* Count the number of parameters.
12620 FIXME: GDB currently ignores vararg functions, but knows about
12621 vararg member functions. */
12623 child_die = die->child;
12624 while (child_die && child_die->tag)
12626 if (child_die->tag == DW_TAG_formal_parameter)
12628 else if (child_die->tag == DW_TAG_unspecified_parameters)
12629 TYPE_VARARGS (ftype) = 1;
12630 child_die = sibling_die (child_die);
12633 /* Allocate storage for parameters and fill them in. */
12634 TYPE_NFIELDS (ftype) = nparams;
12635 TYPE_FIELDS (ftype) = (struct field *)
12636 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
12638 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12639 even if we error out during the parameters reading below. */
12640 for (iparams = 0; iparams < nparams; iparams++)
12641 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
12644 child_die = die->child;
12645 while (child_die && child_die->tag)
12647 if (child_die->tag == DW_TAG_formal_parameter)
12649 struct type *arg_type;
12651 /* DWARF version 2 has no clean way to discern C++
12652 static and non-static member functions. G++ helps
12653 GDB by marking the first parameter for non-static
12654 member functions (which is the this pointer) as
12655 artificial. We pass this information to
12656 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12658 DWARF version 3 added DW_AT_object_pointer, which GCC
12659 4.5 does not yet generate. */
12660 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
12662 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
12665 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
12667 /* GCC/43521: In java, the formal parameter
12668 "this" is sometimes not marked with DW_AT_artificial. */
12669 if (cu->language == language_java)
12671 const char *name = dwarf2_name (child_die, cu);
12673 if (name && !strcmp (name, "this"))
12674 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
12677 arg_type = die_type (child_die, cu);
12679 /* RealView does not mark THIS as const, which the testsuite
12680 expects. GCC marks THIS as const in method definitions,
12681 but not in the class specifications (GCC PR 43053). */
12682 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
12683 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
12686 struct dwarf2_cu *arg_cu = cu;
12687 const char *name = dwarf2_name (child_die, cu);
12689 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
12692 /* If the compiler emits this, use it. */
12693 if (follow_die_ref (die, attr, &arg_cu) == child_die)
12696 else if (name && strcmp (name, "this") == 0)
12697 /* Function definitions will have the argument names. */
12699 else if (name == NULL && iparams == 0)
12700 /* Declarations may not have the names, so like
12701 elsewhere in GDB, assume an artificial first
12702 argument is "this". */
12706 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
12710 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
12713 child_die = sibling_die (child_die);
12720 static struct type *
12721 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
12723 struct objfile *objfile = cu->objfile;
12724 const char *name = NULL;
12725 struct type *this_type, *target_type;
12727 name = dwarf2_full_name (NULL, die, cu);
12728 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
12729 TYPE_FLAG_TARGET_STUB, NULL, objfile);
12730 TYPE_NAME (this_type) = name;
12731 set_die_type (die, this_type, cu);
12732 target_type = die_type (die, cu);
12733 if (target_type != this_type)
12734 TYPE_TARGET_TYPE (this_type) = target_type;
12737 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12738 spec and cause infinite loops in GDB. */
12739 complaint (&symfile_complaints,
12740 _("Self-referential DW_TAG_typedef "
12741 "- DIE at 0x%x [in module %s]"),
12742 die->offset.sect_off, objfile->name);
12743 TYPE_TARGET_TYPE (this_type) = NULL;
12748 /* Find a representation of a given base type and install
12749 it in the TYPE field of the die. */
12751 static struct type *
12752 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
12754 struct objfile *objfile = cu->objfile;
12756 struct attribute *attr;
12757 int encoding = 0, size = 0;
12759 enum type_code code = TYPE_CODE_INT;
12760 int type_flags = 0;
12761 struct type *target_type = NULL;
12763 attr = dwarf2_attr (die, DW_AT_encoding, cu);
12766 encoding = DW_UNSND (attr);
12768 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12771 size = DW_UNSND (attr);
12773 name = dwarf2_name (die, cu);
12776 complaint (&symfile_complaints,
12777 _("DW_AT_name missing from DW_TAG_base_type"));
12782 case DW_ATE_address:
12783 /* Turn DW_ATE_address into a void * pointer. */
12784 code = TYPE_CODE_PTR;
12785 type_flags |= TYPE_FLAG_UNSIGNED;
12786 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
12788 case DW_ATE_boolean:
12789 code = TYPE_CODE_BOOL;
12790 type_flags |= TYPE_FLAG_UNSIGNED;
12792 case DW_ATE_complex_float:
12793 code = TYPE_CODE_COMPLEX;
12794 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
12796 case DW_ATE_decimal_float:
12797 code = TYPE_CODE_DECFLOAT;
12800 code = TYPE_CODE_FLT;
12802 case DW_ATE_signed:
12804 case DW_ATE_unsigned:
12805 type_flags |= TYPE_FLAG_UNSIGNED;
12806 if (cu->language == language_fortran
12808 && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
12809 code = TYPE_CODE_CHAR;
12811 case DW_ATE_signed_char:
12812 if (cu->language == language_ada || cu->language == language_m2
12813 || cu->language == language_pascal
12814 || cu->language == language_fortran)
12815 code = TYPE_CODE_CHAR;
12817 case DW_ATE_unsigned_char:
12818 if (cu->language == language_ada || cu->language == language_m2
12819 || cu->language == language_pascal
12820 || cu->language == language_fortran)
12821 code = TYPE_CODE_CHAR;
12822 type_flags |= TYPE_FLAG_UNSIGNED;
12825 /* We just treat this as an integer and then recognize the
12826 type by name elsewhere. */
12830 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
12831 dwarf_type_encoding_name (encoding));
12835 type = init_type (code, size, type_flags, NULL, objfile);
12836 TYPE_NAME (type) = name;
12837 TYPE_TARGET_TYPE (type) = target_type;
12839 if (name && strcmp (name, "char") == 0)
12840 TYPE_NOSIGN (type) = 1;
12842 return set_die_type (die, type, cu);
12845 /* Read the given DW_AT_subrange DIE. */
12847 static struct type *
12848 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
12850 struct type *base_type, *orig_base_type;
12851 struct type *range_type;
12852 struct attribute *attr;
12854 int low_default_is_valid;
12856 LONGEST negative_mask;
12858 orig_base_type = die_type (die, cu);
12859 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
12860 whereas the real type might be. So, we use ORIG_BASE_TYPE when
12861 creating the range type, but we use the result of check_typedef
12862 when examining properties of the type. */
12863 base_type = check_typedef (orig_base_type);
12865 /* The die_type call above may have already set the type for this DIE. */
12866 range_type = get_die_type (die, cu);
12870 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12871 omitting DW_AT_lower_bound. */
12872 switch (cu->language)
12875 case language_cplus:
12877 low_default_is_valid = 1;
12879 case language_fortran:
12881 low_default_is_valid = 1;
12884 case language_java:
12885 case language_objc:
12887 low_default_is_valid = (cu->header.version >= 4);
12891 case language_pascal:
12893 low_default_is_valid = (cu->header.version >= 4);
12897 low_default_is_valid = 0;
12901 /* FIXME: For variable sized arrays either of these could be
12902 a variable rather than a constant value. We'll allow it,
12903 but we don't know how to handle it. */
12904 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
12906 low = dwarf2_get_attr_constant_value (attr, low);
12907 else if (!low_default_is_valid)
12908 complaint (&symfile_complaints, _("Missing DW_AT_lower_bound "
12909 "- DIE at 0x%x [in module %s]"),
12910 die->offset.sect_off, cu->objfile->name);
12912 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
12915 if (attr_form_is_block (attr) || is_ref_attr (attr))
12917 /* GCC encodes arrays with unspecified or dynamic length
12918 with a DW_FORM_block1 attribute or a reference attribute.
12919 FIXME: GDB does not yet know how to handle dynamic
12920 arrays properly, treat them as arrays with unspecified
12923 FIXME: jimb/2003-09-22: GDB does not really know
12924 how to handle arrays of unspecified length
12925 either; we just represent them as zero-length
12926 arrays. Choose an appropriate upper bound given
12927 the lower bound we've computed above. */
12931 high = dwarf2_get_attr_constant_value (attr, 1);
12935 attr = dwarf2_attr (die, DW_AT_count, cu);
12938 int count = dwarf2_get_attr_constant_value (attr, 1);
12939 high = low + count - 1;
12943 /* Unspecified array length. */
12948 /* Dwarf-2 specifications explicitly allows to create subrange types
12949 without specifying a base type.
12950 In that case, the base type must be set to the type of
12951 the lower bound, upper bound or count, in that order, if any of these
12952 three attributes references an object that has a type.
12953 If no base type is found, the Dwarf-2 specifications say that
12954 a signed integer type of size equal to the size of an address should
12956 For the following C code: `extern char gdb_int [];'
12957 GCC produces an empty range DIE.
12958 FIXME: muller/2010-05-28: Possible references to object for low bound,
12959 high bound or count are not yet handled by this code. */
12960 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
12962 struct objfile *objfile = cu->objfile;
12963 struct gdbarch *gdbarch = get_objfile_arch (objfile);
12964 int addr_size = gdbarch_addr_bit (gdbarch) /8;
12965 struct type *int_type = objfile_type (objfile)->builtin_int;
12967 /* Test "int", "long int", and "long long int" objfile types,
12968 and select the first one having a size above or equal to the
12969 architecture address size. */
12970 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
12971 base_type = int_type;
12974 int_type = objfile_type (objfile)->builtin_long;
12975 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
12976 base_type = int_type;
12979 int_type = objfile_type (objfile)->builtin_long_long;
12980 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
12981 base_type = int_type;
12987 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
12988 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
12989 low |= negative_mask;
12990 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
12991 high |= negative_mask;
12993 range_type = create_range_type (NULL, orig_base_type, low, high);
12995 /* Mark arrays with dynamic length at least as an array of unspecified
12996 length. GDB could check the boundary but before it gets implemented at
12997 least allow accessing the array elements. */
12998 if (attr && attr_form_is_block (attr))
12999 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
13001 /* Ada expects an empty array on no boundary attributes. */
13002 if (attr == NULL && cu->language != language_ada)
13003 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
13005 name = dwarf2_name (die, cu);
13007 TYPE_NAME (range_type) = name;
13009 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
13011 TYPE_LENGTH (range_type) = DW_UNSND (attr);
13013 set_die_type (die, range_type, cu);
13015 /* set_die_type should be already done. */
13016 set_descriptive_type (range_type, die, cu);
13021 static struct type *
13022 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
13026 /* For now, we only support the C meaning of an unspecified type: void. */
13028 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
13029 TYPE_NAME (type) = dwarf2_name (die, cu);
13031 return set_die_type (die, type, cu);
13034 /* Read a single die and all its descendents. Set the die's sibling
13035 field to NULL; set other fields in the die correctly, and set all
13036 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
13037 location of the info_ptr after reading all of those dies. PARENT
13038 is the parent of the die in question. */
13040 static struct die_info *
13041 read_die_and_children (const struct die_reader_specs *reader,
13042 gdb_byte *info_ptr,
13043 gdb_byte **new_info_ptr,
13044 struct die_info *parent)
13046 struct die_info *die;
13050 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
13053 *new_info_ptr = cur_ptr;
13056 store_in_ref_table (die, reader->cu);
13059 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
13063 *new_info_ptr = cur_ptr;
13066 die->sibling = NULL;
13067 die->parent = parent;
13071 /* Read a die, all of its descendents, and all of its siblings; set
13072 all of the fields of all of the dies correctly. Arguments are as
13073 in read_die_and_children. */
13075 static struct die_info *
13076 read_die_and_siblings (const struct die_reader_specs *reader,
13077 gdb_byte *info_ptr,
13078 gdb_byte **new_info_ptr,
13079 struct die_info *parent)
13081 struct die_info *first_die, *last_sibling;
13084 cur_ptr = info_ptr;
13085 first_die = last_sibling = NULL;
13089 struct die_info *die
13090 = read_die_and_children (reader, cur_ptr, &cur_ptr, parent);
13094 *new_info_ptr = cur_ptr;
13101 last_sibling->sibling = die;
13103 last_sibling = die;
13107 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
13109 The caller is responsible for filling in the extra attributes
13110 and updating (*DIEP)->num_attrs.
13111 Set DIEP to point to a newly allocated die with its information,
13112 except for its child, sibling, and parent fields.
13113 Set HAS_CHILDREN to tell whether the die has children or not. */
13116 read_full_die_1 (const struct die_reader_specs *reader,
13117 struct die_info **diep, gdb_byte *info_ptr,
13118 int *has_children, int num_extra_attrs)
13120 unsigned int abbrev_number, bytes_read, i;
13121 sect_offset offset;
13122 struct abbrev_info *abbrev;
13123 struct die_info *die;
13124 struct dwarf2_cu *cu = reader->cu;
13125 bfd *abfd = reader->abfd;
13127 offset.sect_off = info_ptr - reader->buffer;
13128 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
13129 info_ptr += bytes_read;
13130 if (!abbrev_number)
13137 abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number);
13139 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
13141 bfd_get_filename (abfd));
13143 die = dwarf_alloc_die (cu, abbrev->num_attrs + num_extra_attrs);
13144 die->offset = offset;
13145 die->tag = abbrev->tag;
13146 die->abbrev = abbrev_number;
13148 /* Make the result usable.
13149 The caller needs to update num_attrs after adding the extra
13151 die->num_attrs = abbrev->num_attrs;
13153 for (i = 0; i < abbrev->num_attrs; ++i)
13154 info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i],
13158 *has_children = abbrev->has_children;
13162 /* Read a die and all its attributes.
13163 Set DIEP to point to a newly allocated die with its information,
13164 except for its child, sibling, and parent fields.
13165 Set HAS_CHILDREN to tell whether the die has children or not. */
13168 read_full_die (const struct die_reader_specs *reader,
13169 struct die_info **diep, gdb_byte *info_ptr,
13172 return read_full_die_1 (reader, diep, info_ptr, has_children, 0);
13175 /* Abbreviation tables.
13177 In DWARF version 2, the description of the debugging information is
13178 stored in a separate .debug_abbrev section. Before we read any
13179 dies from a section we read in all abbreviations and install them
13180 in a hash table. */
13182 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
13184 static struct abbrev_info *
13185 abbrev_table_alloc_abbrev (struct abbrev_table *abbrev_table)
13187 struct abbrev_info *abbrev;
13189 abbrev = (struct abbrev_info *)
13190 obstack_alloc (&abbrev_table->abbrev_obstack, sizeof (struct abbrev_info));
13191 memset (abbrev, 0, sizeof (struct abbrev_info));
13195 /* Add an abbreviation to the table. */
13198 abbrev_table_add_abbrev (struct abbrev_table *abbrev_table,
13199 unsigned int abbrev_number,
13200 struct abbrev_info *abbrev)
13202 unsigned int hash_number;
13204 hash_number = abbrev_number % ABBREV_HASH_SIZE;
13205 abbrev->next = abbrev_table->abbrevs[hash_number];
13206 abbrev_table->abbrevs[hash_number] = abbrev;
13209 /* Look up an abbrev in the table.
13210 Returns NULL if the abbrev is not found. */
13212 static struct abbrev_info *
13213 abbrev_table_lookup_abbrev (const struct abbrev_table *abbrev_table,
13214 unsigned int abbrev_number)
13216 unsigned int hash_number;
13217 struct abbrev_info *abbrev;
13219 hash_number = abbrev_number % ABBREV_HASH_SIZE;
13220 abbrev = abbrev_table->abbrevs[hash_number];
13224 if (abbrev->number == abbrev_number)
13226 abbrev = abbrev->next;
13231 /* Read in an abbrev table. */
13233 static struct abbrev_table *
13234 abbrev_table_read_table (struct dwarf2_section_info *section,
13235 sect_offset offset)
13237 struct objfile *objfile = dwarf2_per_objfile->objfile;
13238 bfd *abfd = section->asection->owner;
13239 struct abbrev_table *abbrev_table;
13240 gdb_byte *abbrev_ptr;
13241 struct abbrev_info *cur_abbrev;
13242 unsigned int abbrev_number, bytes_read, abbrev_name;
13243 unsigned int abbrev_form;
13244 struct attr_abbrev *cur_attrs;
13245 unsigned int allocated_attrs;
13247 abbrev_table = XMALLOC (struct abbrev_table);
13248 abbrev_table->offset = offset;
13249 obstack_init (&abbrev_table->abbrev_obstack);
13250 abbrev_table->abbrevs = obstack_alloc (&abbrev_table->abbrev_obstack,
13252 * sizeof (struct abbrev_info *)));
13253 memset (abbrev_table->abbrevs, 0,
13254 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
13256 dwarf2_read_section (objfile, section);
13257 abbrev_ptr = section->buffer + offset.sect_off;
13258 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13259 abbrev_ptr += bytes_read;
13261 allocated_attrs = ATTR_ALLOC_CHUNK;
13262 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
13264 /* Loop until we reach an abbrev number of 0. */
13265 while (abbrev_number)
13267 cur_abbrev = abbrev_table_alloc_abbrev (abbrev_table);
13269 /* read in abbrev header */
13270 cur_abbrev->number = abbrev_number;
13271 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13272 abbrev_ptr += bytes_read;
13273 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
13276 /* now read in declarations */
13277 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13278 abbrev_ptr += bytes_read;
13279 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13280 abbrev_ptr += bytes_read;
13281 while (abbrev_name)
13283 if (cur_abbrev->num_attrs == allocated_attrs)
13285 allocated_attrs += ATTR_ALLOC_CHUNK;
13287 = xrealloc (cur_attrs, (allocated_attrs
13288 * sizeof (struct attr_abbrev)));
13291 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
13292 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
13293 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13294 abbrev_ptr += bytes_read;
13295 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13296 abbrev_ptr += bytes_read;
13299 cur_abbrev->attrs = obstack_alloc (&abbrev_table->abbrev_obstack,
13300 (cur_abbrev->num_attrs
13301 * sizeof (struct attr_abbrev)));
13302 memcpy (cur_abbrev->attrs, cur_attrs,
13303 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
13305 abbrev_table_add_abbrev (abbrev_table, abbrev_number, cur_abbrev);
13307 /* Get next abbreviation.
13308 Under Irix6 the abbreviations for a compilation unit are not
13309 always properly terminated with an abbrev number of 0.
13310 Exit loop if we encounter an abbreviation which we have
13311 already read (which means we are about to read the abbreviations
13312 for the next compile unit) or if the end of the abbreviation
13313 table is reached. */
13314 if ((unsigned int) (abbrev_ptr - section->buffer) >= section->size)
13316 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13317 abbrev_ptr += bytes_read;
13318 if (abbrev_table_lookup_abbrev (abbrev_table, abbrev_number) != NULL)
13323 return abbrev_table;
13326 /* Free the resources held by ABBREV_TABLE. */
13329 abbrev_table_free (struct abbrev_table *abbrev_table)
13331 obstack_free (&abbrev_table->abbrev_obstack, NULL);
13332 xfree (abbrev_table);
13335 /* Same as abbrev_table_free but as a cleanup.
13336 We pass in a pointer to the pointer to the table so that we can
13337 set the pointer to NULL when we're done. It also simplifies
13338 build_type_unit_groups. */
13341 abbrev_table_free_cleanup (void *table_ptr)
13343 struct abbrev_table **abbrev_table_ptr = table_ptr;
13345 if (*abbrev_table_ptr != NULL)
13346 abbrev_table_free (*abbrev_table_ptr);
13347 *abbrev_table_ptr = NULL;
13350 /* Read the abbrev table for CU from ABBREV_SECTION. */
13353 dwarf2_read_abbrevs (struct dwarf2_cu *cu,
13354 struct dwarf2_section_info *abbrev_section)
13357 abbrev_table_read_table (abbrev_section, cu->header.abbrev_offset);
13360 /* Release the memory used by the abbrev table for a compilation unit. */
13363 dwarf2_free_abbrev_table (void *ptr_to_cu)
13365 struct dwarf2_cu *cu = ptr_to_cu;
13367 abbrev_table_free (cu->abbrev_table);
13368 /* Set this to NULL so that we SEGV if we try to read it later,
13369 and also because free_comp_unit verifies this is NULL. */
13370 cu->abbrev_table = NULL;
13373 /* Returns nonzero if TAG represents a type that we might generate a partial
13377 is_type_tag_for_partial (int tag)
13382 /* Some types that would be reasonable to generate partial symbols for,
13383 that we don't at present. */
13384 case DW_TAG_array_type:
13385 case DW_TAG_file_type:
13386 case DW_TAG_ptr_to_member_type:
13387 case DW_TAG_set_type:
13388 case DW_TAG_string_type:
13389 case DW_TAG_subroutine_type:
13391 case DW_TAG_base_type:
13392 case DW_TAG_class_type:
13393 case DW_TAG_interface_type:
13394 case DW_TAG_enumeration_type:
13395 case DW_TAG_structure_type:
13396 case DW_TAG_subrange_type:
13397 case DW_TAG_typedef:
13398 case DW_TAG_union_type:
13405 /* Load all DIEs that are interesting for partial symbols into memory. */
13407 static struct partial_die_info *
13408 load_partial_dies (const struct die_reader_specs *reader,
13409 gdb_byte *info_ptr, int building_psymtab)
13411 struct dwarf2_cu *cu = reader->cu;
13412 struct objfile *objfile = cu->objfile;
13413 struct partial_die_info *part_die;
13414 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
13415 struct abbrev_info *abbrev;
13416 unsigned int bytes_read;
13417 unsigned int load_all = 0;
13418 int nesting_level = 1;
13423 gdb_assert (cu->per_cu != NULL);
13424 if (cu->per_cu->load_all_dies)
13428 = htab_create_alloc_ex (cu->header.length / 12,
13432 &cu->comp_unit_obstack,
13433 hashtab_obstack_allocate,
13434 dummy_obstack_deallocate);
13436 part_die = obstack_alloc (&cu->comp_unit_obstack,
13437 sizeof (struct partial_die_info));
13441 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
13443 /* A NULL abbrev means the end of a series of children. */
13444 if (abbrev == NULL)
13446 if (--nesting_level == 0)
13448 /* PART_DIE was probably the last thing allocated on the
13449 comp_unit_obstack, so we could call obstack_free
13450 here. We don't do that because the waste is small,
13451 and will be cleaned up when we're done with this
13452 compilation unit. This way, we're also more robust
13453 against other users of the comp_unit_obstack. */
13456 info_ptr += bytes_read;
13457 last_die = parent_die;
13458 parent_die = parent_die->die_parent;
13462 /* Check for template arguments. We never save these; if
13463 they're seen, we just mark the parent, and go on our way. */
13464 if (parent_die != NULL
13465 && cu->language == language_cplus
13466 && (abbrev->tag == DW_TAG_template_type_param
13467 || abbrev->tag == DW_TAG_template_value_param))
13469 parent_die->has_template_arguments = 1;
13473 /* We don't need a partial DIE for the template argument. */
13474 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
13479 /* We only recurse into c++ subprograms looking for template arguments.
13480 Skip their other children. */
13482 && cu->language == language_cplus
13483 && parent_die != NULL
13484 && parent_die->tag == DW_TAG_subprogram)
13486 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
13490 /* Check whether this DIE is interesting enough to save. Normally
13491 we would not be interested in members here, but there may be
13492 later variables referencing them via DW_AT_specification (for
13493 static members). */
13495 && !is_type_tag_for_partial (abbrev->tag)
13496 && abbrev->tag != DW_TAG_constant
13497 && abbrev->tag != DW_TAG_enumerator
13498 && abbrev->tag != DW_TAG_subprogram
13499 && abbrev->tag != DW_TAG_lexical_block
13500 && abbrev->tag != DW_TAG_variable
13501 && abbrev->tag != DW_TAG_namespace
13502 && abbrev->tag != DW_TAG_module
13503 && abbrev->tag != DW_TAG_member
13504 && abbrev->tag != DW_TAG_imported_unit)
13506 /* Otherwise we skip to the next sibling, if any. */
13507 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
13511 info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read,
13514 /* This two-pass algorithm for processing partial symbols has a
13515 high cost in cache pressure. Thus, handle some simple cases
13516 here which cover the majority of C partial symbols. DIEs
13517 which neither have specification tags in them, nor could have
13518 specification tags elsewhere pointing at them, can simply be
13519 processed and discarded.
13521 This segment is also optional; scan_partial_symbols and
13522 add_partial_symbol will handle these DIEs if we chain
13523 them in normally. When compilers which do not emit large
13524 quantities of duplicate debug information are more common,
13525 this code can probably be removed. */
13527 /* Any complete simple types at the top level (pretty much all
13528 of them, for a language without namespaces), can be processed
13530 if (parent_die == NULL
13531 && part_die->has_specification == 0
13532 && part_die->is_declaration == 0
13533 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
13534 || part_die->tag == DW_TAG_base_type
13535 || part_die->tag == DW_TAG_subrange_type))
13537 if (building_psymtab && part_die->name != NULL)
13538 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
13539 VAR_DOMAIN, LOC_TYPEDEF,
13540 &objfile->static_psymbols,
13541 0, (CORE_ADDR) 0, cu->language, objfile);
13542 info_ptr = locate_pdi_sibling (reader, part_die, info_ptr);
13546 /* The exception for DW_TAG_typedef with has_children above is
13547 a workaround of GCC PR debug/47510. In the case of this complaint
13548 type_name_no_tag_or_error will error on such types later.
13550 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13551 it could not find the child DIEs referenced later, this is checked
13552 above. In correct DWARF DW_TAG_typedef should have no children. */
13554 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
13555 complaint (&symfile_complaints,
13556 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13557 "- DIE at 0x%x [in module %s]"),
13558 part_die->offset.sect_off, objfile->name);
13560 /* If we're at the second level, and we're an enumerator, and
13561 our parent has no specification (meaning possibly lives in a
13562 namespace elsewhere), then we can add the partial symbol now
13563 instead of queueing it. */
13564 if (part_die->tag == DW_TAG_enumerator
13565 && parent_die != NULL
13566 && parent_die->die_parent == NULL
13567 && parent_die->tag == DW_TAG_enumeration_type
13568 && parent_die->has_specification == 0)
13570 if (part_die->name == NULL)
13571 complaint (&symfile_complaints,
13572 _("malformed enumerator DIE ignored"));
13573 else if (building_psymtab)
13574 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
13575 VAR_DOMAIN, LOC_CONST,
13576 (cu->language == language_cplus
13577 || cu->language == language_java)
13578 ? &objfile->global_psymbols
13579 : &objfile->static_psymbols,
13580 0, (CORE_ADDR) 0, cu->language, objfile);
13582 info_ptr = locate_pdi_sibling (reader, part_die, info_ptr);
13586 /* We'll save this DIE so link it in. */
13587 part_die->die_parent = parent_die;
13588 part_die->die_sibling = NULL;
13589 part_die->die_child = NULL;
13591 if (last_die && last_die == parent_die)
13592 last_die->die_child = part_die;
13594 last_die->die_sibling = part_die;
13596 last_die = part_die;
13598 if (first_die == NULL)
13599 first_die = part_die;
13601 /* Maybe add the DIE to the hash table. Not all DIEs that we
13602 find interesting need to be in the hash table, because we
13603 also have the parent/sibling/child chains; only those that we
13604 might refer to by offset later during partial symbol reading.
13606 For now this means things that might have be the target of a
13607 DW_AT_specification, DW_AT_abstract_origin, or
13608 DW_AT_extension. DW_AT_extension will refer only to
13609 namespaces; DW_AT_abstract_origin refers to functions (and
13610 many things under the function DIE, but we do not recurse
13611 into function DIEs during partial symbol reading) and
13612 possibly variables as well; DW_AT_specification refers to
13613 declarations. Declarations ought to have the DW_AT_declaration
13614 flag. It happens that GCC forgets to put it in sometimes, but
13615 only for functions, not for types.
13617 Adding more things than necessary to the hash table is harmless
13618 except for the performance cost. Adding too few will result in
13619 wasted time in find_partial_die, when we reread the compilation
13620 unit with load_all_dies set. */
13623 || abbrev->tag == DW_TAG_constant
13624 || abbrev->tag == DW_TAG_subprogram
13625 || abbrev->tag == DW_TAG_variable
13626 || abbrev->tag == DW_TAG_namespace
13627 || part_die->is_declaration)
13631 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
13632 part_die->offset.sect_off, INSERT);
13636 part_die = obstack_alloc (&cu->comp_unit_obstack,
13637 sizeof (struct partial_die_info));
13639 /* For some DIEs we want to follow their children (if any). For C
13640 we have no reason to follow the children of structures; for other
13641 languages we have to, so that we can get at method physnames
13642 to infer fully qualified class names, for DW_AT_specification,
13643 and for C++ template arguments. For C++, we also look one level
13644 inside functions to find template arguments (if the name of the
13645 function does not already contain the template arguments).
13647 For Ada, we need to scan the children of subprograms and lexical
13648 blocks as well because Ada allows the definition of nested
13649 entities that could be interesting for the debugger, such as
13650 nested subprograms for instance. */
13651 if (last_die->has_children
13653 || last_die->tag == DW_TAG_namespace
13654 || last_die->tag == DW_TAG_module
13655 || last_die->tag == DW_TAG_enumeration_type
13656 || (cu->language == language_cplus
13657 && last_die->tag == DW_TAG_subprogram
13658 && (last_die->name == NULL
13659 || strchr (last_die->name, '<') == NULL))
13660 || (cu->language != language_c
13661 && (last_die->tag == DW_TAG_class_type
13662 || last_die->tag == DW_TAG_interface_type
13663 || last_die->tag == DW_TAG_structure_type
13664 || last_die->tag == DW_TAG_union_type))
13665 || (cu->language == language_ada
13666 && (last_die->tag == DW_TAG_subprogram
13667 || last_die->tag == DW_TAG_lexical_block))))
13670 parent_die = last_die;
13674 /* Otherwise we skip to the next sibling, if any. */
13675 info_ptr = locate_pdi_sibling (reader, last_die, info_ptr);
13677 /* Back to the top, do it again. */
13681 /* Read a minimal amount of information into the minimal die structure. */
13684 read_partial_die (const struct die_reader_specs *reader,
13685 struct partial_die_info *part_die,
13686 struct abbrev_info *abbrev, unsigned int abbrev_len,
13687 gdb_byte *info_ptr)
13689 struct dwarf2_cu *cu = reader->cu;
13690 struct objfile *objfile = cu->objfile;
13691 gdb_byte *buffer = reader->buffer;
13693 struct attribute attr;
13694 int has_low_pc_attr = 0;
13695 int has_high_pc_attr = 0;
13696 int high_pc_relative = 0;
13698 memset (part_die, 0, sizeof (struct partial_die_info));
13700 part_die->offset.sect_off = info_ptr - buffer;
13702 info_ptr += abbrev_len;
13704 if (abbrev == NULL)
13707 part_die->tag = abbrev->tag;
13708 part_die->has_children = abbrev->has_children;
13710 for (i = 0; i < abbrev->num_attrs; ++i)
13712 info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
13714 /* Store the data if it is of an attribute we want to keep in a
13715 partial symbol table. */
13719 switch (part_die->tag)
13721 case DW_TAG_compile_unit:
13722 case DW_TAG_partial_unit:
13723 case DW_TAG_type_unit:
13724 /* Compilation units have a DW_AT_name that is a filename, not
13725 a source language identifier. */
13726 case DW_TAG_enumeration_type:
13727 case DW_TAG_enumerator:
13728 /* These tags always have simple identifiers already; no need
13729 to canonicalize them. */
13730 part_die->name = DW_STRING (&attr);
13734 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
13735 &objfile->objfile_obstack);
13739 case DW_AT_linkage_name:
13740 case DW_AT_MIPS_linkage_name:
13741 /* Note that both forms of linkage name might appear. We
13742 assume they will be the same, and we only store the last
13744 if (cu->language == language_ada)
13745 part_die->name = DW_STRING (&attr);
13746 part_die->linkage_name = DW_STRING (&attr);
13749 has_low_pc_attr = 1;
13750 part_die->lowpc = DW_ADDR (&attr);
13752 case DW_AT_high_pc:
13753 has_high_pc_attr = 1;
13754 if (attr.form == DW_FORM_addr
13755 || attr.form == DW_FORM_GNU_addr_index)
13756 part_die->highpc = DW_ADDR (&attr);
13759 high_pc_relative = 1;
13760 part_die->highpc = DW_UNSND (&attr);
13763 case DW_AT_location:
13764 /* Support the .debug_loc offsets. */
13765 if (attr_form_is_block (&attr))
13767 part_die->d.locdesc = DW_BLOCK (&attr);
13769 else if (attr_form_is_section_offset (&attr))
13771 dwarf2_complex_location_expr_complaint ();
13775 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13776 "partial symbol information");
13779 case DW_AT_external:
13780 part_die->is_external = DW_UNSND (&attr);
13782 case DW_AT_declaration:
13783 part_die->is_declaration = DW_UNSND (&attr);
13786 part_die->has_type = 1;
13788 case DW_AT_abstract_origin:
13789 case DW_AT_specification:
13790 case DW_AT_extension:
13791 part_die->has_specification = 1;
13792 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
13793 part_die->spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt
13794 || cu->per_cu->is_dwz);
13796 case DW_AT_sibling:
13797 /* Ignore absolute siblings, they might point outside of
13798 the current compile unit. */
13799 if (attr.form == DW_FORM_ref_addr)
13800 complaint (&symfile_complaints,
13801 _("ignoring absolute DW_AT_sibling"));
13803 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr).sect_off;
13805 case DW_AT_byte_size:
13806 part_die->has_byte_size = 1;
13808 case DW_AT_calling_convention:
13809 /* DWARF doesn't provide a way to identify a program's source-level
13810 entry point. DW_AT_calling_convention attributes are only meant
13811 to describe functions' calling conventions.
13813 However, because it's a necessary piece of information in
13814 Fortran, and because DW_CC_program is the only piece of debugging
13815 information whose definition refers to a 'main program' at all,
13816 several compilers have begun marking Fortran main programs with
13817 DW_CC_program --- even when those functions use the standard
13818 calling conventions.
13820 So until DWARF specifies a way to provide this information and
13821 compilers pick up the new representation, we'll support this
13823 if (DW_UNSND (&attr) == DW_CC_program
13824 && cu->language == language_fortran)
13826 set_main_name (part_die->name);
13828 /* As this DIE has a static linkage the name would be difficult
13829 to look up later. */
13830 language_of_main = language_fortran;
13834 if (DW_UNSND (&attr) == DW_INL_inlined
13835 || DW_UNSND (&attr) == DW_INL_declared_inlined)
13836 part_die->may_be_inlined = 1;
13840 if (part_die->tag == DW_TAG_imported_unit)
13842 part_die->d.offset = dwarf2_get_ref_die_offset (&attr);
13843 part_die->is_dwz = (attr.form == DW_FORM_GNU_ref_alt
13844 || cu->per_cu->is_dwz);
13853 if (high_pc_relative)
13854 part_die->highpc += part_die->lowpc;
13856 if (has_low_pc_attr && has_high_pc_attr)
13858 /* When using the GNU linker, .gnu.linkonce. sections are used to
13859 eliminate duplicate copies of functions and vtables and such.
13860 The linker will arbitrarily choose one and discard the others.
13861 The AT_*_pc values for such functions refer to local labels in
13862 these sections. If the section from that file was discarded, the
13863 labels are not in the output, so the relocs get a value of 0.
13864 If this is a discarded function, mark the pc bounds as invalid,
13865 so that GDB will ignore it. */
13866 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
13868 struct gdbarch *gdbarch = get_objfile_arch (objfile);
13870 complaint (&symfile_complaints,
13871 _("DW_AT_low_pc %s is zero "
13872 "for DIE at 0x%x [in module %s]"),
13873 paddress (gdbarch, part_die->lowpc),
13874 part_die->offset.sect_off, objfile->name);
13876 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13877 else if (part_die->lowpc >= part_die->highpc)
13879 struct gdbarch *gdbarch = get_objfile_arch (objfile);
13881 complaint (&symfile_complaints,
13882 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13883 "for DIE at 0x%x [in module %s]"),
13884 paddress (gdbarch, part_die->lowpc),
13885 paddress (gdbarch, part_die->highpc),
13886 part_die->offset.sect_off, objfile->name);
13889 part_die->has_pc_info = 1;
13895 /* Find a cached partial DIE at OFFSET in CU. */
13897 static struct partial_die_info *
13898 find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu)
13900 struct partial_die_info *lookup_die = NULL;
13901 struct partial_die_info part_die;
13903 part_die.offset = offset;
13904 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die,
13910 /* Find a partial DIE at OFFSET, which may or may not be in CU,
13911 except in the case of .debug_types DIEs which do not reference
13912 outside their CU (they do however referencing other types via
13913 DW_FORM_ref_sig8). */
13915 static struct partial_die_info *
13916 find_partial_die (sect_offset offset, int offset_in_dwz, struct dwarf2_cu *cu)
13918 struct objfile *objfile = cu->objfile;
13919 struct dwarf2_per_cu_data *per_cu = NULL;
13920 struct partial_die_info *pd = NULL;
13922 if (offset_in_dwz == cu->per_cu->is_dwz
13923 && offset_in_cu_p (&cu->header, offset))
13925 pd = find_partial_die_in_comp_unit (offset, cu);
13928 /* We missed recording what we needed.
13929 Load all dies and try again. */
13930 per_cu = cu->per_cu;
13934 /* TUs don't reference other CUs/TUs (except via type signatures). */
13935 if (cu->per_cu->is_debug_types)
13937 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
13938 " external reference to offset 0x%lx [in module %s].\n"),
13939 (long) cu->header.offset.sect_off, (long) offset.sect_off,
13940 bfd_get_filename (objfile->obfd));
13942 per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
13945 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
13946 load_partial_comp_unit (per_cu);
13948 per_cu->cu->last_used = 0;
13949 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
13952 /* If we didn't find it, and not all dies have been loaded,
13953 load them all and try again. */
13955 if (pd == NULL && per_cu->load_all_dies == 0)
13957 per_cu->load_all_dies = 1;
13959 /* This is nasty. When we reread the DIEs, somewhere up the call chain
13960 THIS_CU->cu may already be in use. So we can't just free it and
13961 replace its DIEs with the ones we read in. Instead, we leave those
13962 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
13963 and clobber THIS_CU->cu->partial_dies with the hash table for the new
13965 load_partial_comp_unit (per_cu);
13967 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
13971 internal_error (__FILE__, __LINE__,
13972 _("could not find partial DIE 0x%x "
13973 "in cache [from module %s]\n"),
13974 offset.sect_off, bfd_get_filename (objfile->obfd));
13978 /* See if we can figure out if the class lives in a namespace. We do
13979 this by looking for a member function; its demangled name will
13980 contain namespace info, if there is any. */
13983 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
13984 struct dwarf2_cu *cu)
13986 /* NOTE: carlton/2003-10-07: Getting the info this way changes
13987 what template types look like, because the demangler
13988 frequently doesn't give the same name as the debug info. We
13989 could fix this by only using the demangled name to get the
13990 prefix (but see comment in read_structure_type). */
13992 struct partial_die_info *real_pdi;
13993 struct partial_die_info *child_pdi;
13995 /* If this DIE (this DIE's specification, if any) has a parent, then
13996 we should not do this. We'll prepend the parent's fully qualified
13997 name when we create the partial symbol. */
13999 real_pdi = struct_pdi;
14000 while (real_pdi->has_specification)
14001 real_pdi = find_partial_die (real_pdi->spec_offset,
14002 real_pdi->spec_is_dwz, cu);
14004 if (real_pdi->die_parent != NULL)
14007 for (child_pdi = struct_pdi->die_child;
14009 child_pdi = child_pdi->die_sibling)
14011 if (child_pdi->tag == DW_TAG_subprogram
14012 && child_pdi->linkage_name != NULL)
14014 char *actual_class_name
14015 = language_class_name_from_physname (cu->language_defn,
14016 child_pdi->linkage_name);
14017 if (actual_class_name != NULL)
14020 = obstack_copy0 (&cu->objfile->objfile_obstack,
14022 strlen (actual_class_name));
14023 xfree (actual_class_name);
14030 /* Adjust PART_DIE before generating a symbol for it. This function
14031 may set the is_external flag or change the DIE's name. */
14034 fixup_partial_die (struct partial_die_info *part_die,
14035 struct dwarf2_cu *cu)
14037 /* Once we've fixed up a die, there's no point in doing so again.
14038 This also avoids a memory leak if we were to call
14039 guess_partial_die_structure_name multiple times. */
14040 if (part_die->fixup_called)
14043 /* If we found a reference attribute and the DIE has no name, try
14044 to find a name in the referred to DIE. */
14046 if (part_die->name == NULL && part_die->has_specification)
14048 struct partial_die_info *spec_die;
14050 spec_die = find_partial_die (part_die->spec_offset,
14051 part_die->spec_is_dwz, cu);
14053 fixup_partial_die (spec_die, cu);
14055 if (spec_die->name)
14057 part_die->name = spec_die->name;
14059 /* Copy DW_AT_external attribute if it is set. */
14060 if (spec_die->is_external)
14061 part_die->is_external = spec_die->is_external;
14065 /* Set default names for some unnamed DIEs. */
14067 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
14068 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
14070 /* If there is no parent die to provide a namespace, and there are
14071 children, see if we can determine the namespace from their linkage
14073 if (cu->language == language_cplus
14074 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
14075 && part_die->die_parent == NULL
14076 && part_die->has_children
14077 && (part_die->tag == DW_TAG_class_type
14078 || part_die->tag == DW_TAG_structure_type
14079 || part_die->tag == DW_TAG_union_type))
14080 guess_partial_die_structure_name (part_die, cu);
14082 /* GCC might emit a nameless struct or union that has a linkage
14083 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14084 if (part_die->name == NULL
14085 && (part_die->tag == DW_TAG_class_type
14086 || part_die->tag == DW_TAG_interface_type
14087 || part_die->tag == DW_TAG_structure_type
14088 || part_die->tag == DW_TAG_union_type)
14089 && part_die->linkage_name != NULL)
14093 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
14098 /* Strip any leading namespaces/classes, keep only the base name.
14099 DW_AT_name for named DIEs does not contain the prefixes. */
14100 base = strrchr (demangled, ':');
14101 if (base && base > demangled && base[-1] == ':')
14106 part_die->name = obstack_copy0 (&cu->objfile->objfile_obstack,
14107 base, strlen (base));
14112 part_die->fixup_called = 1;
14115 /* Read an attribute value described by an attribute form. */
14118 read_attribute_value (const struct die_reader_specs *reader,
14119 struct attribute *attr, unsigned form,
14120 gdb_byte *info_ptr)
14122 struct dwarf2_cu *cu = reader->cu;
14123 bfd *abfd = reader->abfd;
14124 struct comp_unit_head *cu_header = &cu->header;
14125 unsigned int bytes_read;
14126 struct dwarf_block *blk;
14131 case DW_FORM_ref_addr:
14132 if (cu->header.version == 2)
14133 DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
14135 DW_UNSND (attr) = read_offset (abfd, info_ptr,
14136 &cu->header, &bytes_read);
14137 info_ptr += bytes_read;
14139 case DW_FORM_GNU_ref_alt:
14140 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
14141 info_ptr += bytes_read;
14144 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
14145 info_ptr += bytes_read;
14147 case DW_FORM_block2:
14148 blk = dwarf_alloc_block (cu);
14149 blk->size = read_2_bytes (abfd, info_ptr);
14151 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
14152 info_ptr += blk->size;
14153 DW_BLOCK (attr) = blk;
14155 case DW_FORM_block4:
14156 blk = dwarf_alloc_block (cu);
14157 blk->size = read_4_bytes (abfd, info_ptr);
14159 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
14160 info_ptr += blk->size;
14161 DW_BLOCK (attr) = blk;
14163 case DW_FORM_data2:
14164 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
14167 case DW_FORM_data4:
14168 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
14171 case DW_FORM_data8:
14172 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
14175 case DW_FORM_sec_offset:
14176 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
14177 info_ptr += bytes_read;
14179 case DW_FORM_string:
14180 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
14181 DW_STRING_IS_CANONICAL (attr) = 0;
14182 info_ptr += bytes_read;
14185 if (!cu->per_cu->is_dwz)
14187 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
14189 DW_STRING_IS_CANONICAL (attr) = 0;
14190 info_ptr += bytes_read;
14194 case DW_FORM_GNU_strp_alt:
14196 struct dwz_file *dwz = dwarf2_get_dwz_file ();
14197 LONGEST str_offset = read_offset (abfd, info_ptr, cu_header,
14200 DW_STRING (attr) = read_indirect_string_from_dwz (dwz, str_offset);
14201 DW_STRING_IS_CANONICAL (attr) = 0;
14202 info_ptr += bytes_read;
14205 case DW_FORM_exprloc:
14206 case DW_FORM_block:
14207 blk = dwarf_alloc_block (cu);
14208 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14209 info_ptr += bytes_read;
14210 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
14211 info_ptr += blk->size;
14212 DW_BLOCK (attr) = blk;
14214 case DW_FORM_block1:
14215 blk = dwarf_alloc_block (cu);
14216 blk->size = read_1_byte (abfd, info_ptr);
14218 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
14219 info_ptr += blk->size;
14220 DW_BLOCK (attr) = blk;
14222 case DW_FORM_data1:
14223 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
14227 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
14230 case DW_FORM_flag_present:
14231 DW_UNSND (attr) = 1;
14233 case DW_FORM_sdata:
14234 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
14235 info_ptr += bytes_read;
14237 case DW_FORM_udata:
14238 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14239 info_ptr += bytes_read;
14242 DW_UNSND (attr) = (cu->header.offset.sect_off
14243 + read_1_byte (abfd, info_ptr));
14247 DW_UNSND (attr) = (cu->header.offset.sect_off
14248 + read_2_bytes (abfd, info_ptr));
14252 DW_UNSND (attr) = (cu->header.offset.sect_off
14253 + read_4_bytes (abfd, info_ptr));
14257 DW_UNSND (attr) = (cu->header.offset.sect_off
14258 + read_8_bytes (abfd, info_ptr));
14261 case DW_FORM_ref_sig8:
14262 /* Convert the signature to something we can record in DW_UNSND
14264 NOTE: This is NULL if the type wasn't found. */
14265 DW_SIGNATURED_TYPE (attr) =
14266 lookup_signatured_type (read_8_bytes (abfd, info_ptr));
14269 case DW_FORM_ref_udata:
14270 DW_UNSND (attr) = (cu->header.offset.sect_off
14271 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
14272 info_ptr += bytes_read;
14274 case DW_FORM_indirect:
14275 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14276 info_ptr += bytes_read;
14277 info_ptr = read_attribute_value (reader, attr, form, info_ptr);
14279 case DW_FORM_GNU_addr_index:
14280 if (reader->dwo_file == NULL)
14282 /* For now flag a hard error.
14283 Later we can turn this into a complaint. */
14284 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14285 dwarf_form_name (form),
14286 bfd_get_filename (abfd));
14288 DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read);
14289 info_ptr += bytes_read;
14291 case DW_FORM_GNU_str_index:
14292 if (reader->dwo_file == NULL)
14294 /* For now flag a hard error.
14295 Later we can turn this into a complaint if warranted. */
14296 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14297 dwarf_form_name (form),
14298 bfd_get_filename (abfd));
14301 ULONGEST str_index =
14302 read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14304 DW_STRING (attr) = read_str_index (reader, cu, str_index);
14305 DW_STRING_IS_CANONICAL (attr) = 0;
14306 info_ptr += bytes_read;
14310 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14311 dwarf_form_name (form),
14312 bfd_get_filename (abfd));
14316 if (cu->per_cu->is_dwz && is_ref_attr (attr))
14317 attr->form = DW_FORM_GNU_ref_alt;
14319 /* We have seen instances where the compiler tried to emit a byte
14320 size attribute of -1 which ended up being encoded as an unsigned
14321 0xffffffff. Although 0xffffffff is technically a valid size value,
14322 an object of this size seems pretty unlikely so we can relatively
14323 safely treat these cases as if the size attribute was invalid and
14324 treat them as zero by default. */
14325 if (attr->name == DW_AT_byte_size
14326 && form == DW_FORM_data4
14327 && DW_UNSND (attr) >= 0xffffffff)
14330 (&symfile_complaints,
14331 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14332 hex_string (DW_UNSND (attr)));
14333 DW_UNSND (attr) = 0;
14339 /* Read an attribute described by an abbreviated attribute. */
14342 read_attribute (const struct die_reader_specs *reader,
14343 struct attribute *attr, struct attr_abbrev *abbrev,
14344 gdb_byte *info_ptr)
14346 attr->name = abbrev->name;
14347 return read_attribute_value (reader, attr, abbrev->form, info_ptr);
14350 /* Read dwarf information from a buffer. */
14352 static unsigned int
14353 read_1_byte (bfd *abfd, const gdb_byte *buf)
14355 return bfd_get_8 (abfd, buf);
14359 read_1_signed_byte (bfd *abfd, const gdb_byte *buf)
14361 return bfd_get_signed_8 (abfd, buf);
14364 static unsigned int
14365 read_2_bytes (bfd *abfd, const gdb_byte *buf)
14367 return bfd_get_16 (abfd, buf);
14371 read_2_signed_bytes (bfd *abfd, const gdb_byte *buf)
14373 return bfd_get_signed_16 (abfd, buf);
14376 static unsigned int
14377 read_4_bytes (bfd *abfd, const gdb_byte *buf)
14379 return bfd_get_32 (abfd, buf);
14383 read_4_signed_bytes (bfd *abfd, const gdb_byte *buf)
14385 return bfd_get_signed_32 (abfd, buf);
14389 read_8_bytes (bfd *abfd, const gdb_byte *buf)
14391 return bfd_get_64 (abfd, buf);
14395 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
14396 unsigned int *bytes_read)
14398 struct comp_unit_head *cu_header = &cu->header;
14399 CORE_ADDR retval = 0;
14401 if (cu_header->signed_addr_p)
14403 switch (cu_header->addr_size)
14406 retval = bfd_get_signed_16 (abfd, buf);
14409 retval = bfd_get_signed_32 (abfd, buf);
14412 retval = bfd_get_signed_64 (abfd, buf);
14415 internal_error (__FILE__, __LINE__,
14416 _("read_address: bad switch, signed [in module %s]"),
14417 bfd_get_filename (abfd));
14422 switch (cu_header->addr_size)
14425 retval = bfd_get_16 (abfd, buf);
14428 retval = bfd_get_32 (abfd, buf);
14431 retval = bfd_get_64 (abfd, buf);
14434 internal_error (__FILE__, __LINE__,
14435 _("read_address: bad switch, "
14436 "unsigned [in module %s]"),
14437 bfd_get_filename (abfd));
14441 *bytes_read = cu_header->addr_size;
14445 /* Read the initial length from a section. The (draft) DWARF 3
14446 specification allows the initial length to take up either 4 bytes
14447 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14448 bytes describe the length and all offsets will be 8 bytes in length
14451 An older, non-standard 64-bit format is also handled by this
14452 function. The older format in question stores the initial length
14453 as an 8-byte quantity without an escape value. Lengths greater
14454 than 2^32 aren't very common which means that the initial 4 bytes
14455 is almost always zero. Since a length value of zero doesn't make
14456 sense for the 32-bit format, this initial zero can be considered to
14457 be an escape value which indicates the presence of the older 64-bit
14458 format. As written, the code can't detect (old format) lengths
14459 greater than 4GB. If it becomes necessary to handle lengths
14460 somewhat larger than 4GB, we could allow other small values (such
14461 as the non-sensical values of 1, 2, and 3) to also be used as
14462 escape values indicating the presence of the old format.
14464 The value returned via bytes_read should be used to increment the
14465 relevant pointer after calling read_initial_length().
14467 [ Note: read_initial_length() and read_offset() are based on the
14468 document entitled "DWARF Debugging Information Format", revision
14469 3, draft 8, dated November 19, 2001. This document was obtained
14472 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14474 This document is only a draft and is subject to change. (So beware.)
14476 Details regarding the older, non-standard 64-bit format were
14477 determined empirically by examining 64-bit ELF files produced by
14478 the SGI toolchain on an IRIX 6.5 machine.
14480 - Kevin, July 16, 2002
14484 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
14486 LONGEST length = bfd_get_32 (abfd, buf);
14488 if (length == 0xffffffff)
14490 length = bfd_get_64 (abfd, buf + 4);
14493 else if (length == 0)
14495 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14496 length = bfd_get_64 (abfd, buf);
14507 /* Cover function for read_initial_length.
14508 Returns the length of the object at BUF, and stores the size of the
14509 initial length in *BYTES_READ and stores the size that offsets will be in
14511 If the initial length size is not equivalent to that specified in
14512 CU_HEADER then issue a complaint.
14513 This is useful when reading non-comp-unit headers. */
14516 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
14517 const struct comp_unit_head *cu_header,
14518 unsigned int *bytes_read,
14519 unsigned int *offset_size)
14521 LONGEST length = read_initial_length (abfd, buf, bytes_read);
14523 gdb_assert (cu_header->initial_length_size == 4
14524 || cu_header->initial_length_size == 8
14525 || cu_header->initial_length_size == 12);
14527 if (cu_header->initial_length_size != *bytes_read)
14528 complaint (&symfile_complaints,
14529 _("intermixed 32-bit and 64-bit DWARF sections"));
14531 *offset_size = (*bytes_read == 4) ? 4 : 8;
14535 /* Read an offset from the data stream. The size of the offset is
14536 given by cu_header->offset_size. */
14539 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
14540 unsigned int *bytes_read)
14542 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
14544 *bytes_read = cu_header->offset_size;
14548 /* Read an offset from the data stream. */
14551 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
14553 LONGEST retval = 0;
14555 switch (offset_size)
14558 retval = bfd_get_32 (abfd, buf);
14561 retval = bfd_get_64 (abfd, buf);
14564 internal_error (__FILE__, __LINE__,
14565 _("read_offset_1: bad switch [in module %s]"),
14566 bfd_get_filename (abfd));
14573 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
14575 /* If the size of a host char is 8 bits, we can return a pointer
14576 to the buffer, otherwise we have to copy the data to a buffer
14577 allocated on the temporary obstack. */
14578 gdb_assert (HOST_CHAR_BIT == 8);
14583 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
14585 /* If the size of a host char is 8 bits, we can return a pointer
14586 to the string, otherwise we have to copy the string to a buffer
14587 allocated on the temporary obstack. */
14588 gdb_assert (HOST_CHAR_BIT == 8);
14591 *bytes_read_ptr = 1;
14594 *bytes_read_ptr = strlen ((char *) buf) + 1;
14595 return (char *) buf;
14599 read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
14601 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
14602 if (dwarf2_per_objfile->str.buffer == NULL)
14603 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14604 bfd_get_filename (abfd));
14605 if (str_offset >= dwarf2_per_objfile->str.size)
14606 error (_("DW_FORM_strp pointing outside of "
14607 ".debug_str section [in module %s]"),
14608 bfd_get_filename (abfd));
14609 gdb_assert (HOST_CHAR_BIT == 8);
14610 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
14612 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
14615 /* Read a string at offset STR_OFFSET in the .debug_str section from
14616 the .dwz file DWZ. Throw an error if the offset is too large. If
14617 the string consists of a single NUL byte, return NULL; otherwise
14618 return a pointer to the string. */
14621 read_indirect_string_from_dwz (struct dwz_file *dwz, LONGEST str_offset)
14623 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwz->str);
14625 if (dwz->str.buffer == NULL)
14626 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14627 "section [in module %s]"),
14628 bfd_get_filename (dwz->dwz_bfd));
14629 if (str_offset >= dwz->str.size)
14630 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14631 ".debug_str section [in module %s]"),
14632 bfd_get_filename (dwz->dwz_bfd));
14633 gdb_assert (HOST_CHAR_BIT == 8);
14634 if (dwz->str.buffer[str_offset] == '\0')
14636 return (char *) (dwz->str.buffer + str_offset);
14640 read_indirect_string (bfd *abfd, gdb_byte *buf,
14641 const struct comp_unit_head *cu_header,
14642 unsigned int *bytes_read_ptr)
14644 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
14646 return read_indirect_string_at_offset (abfd, str_offset);
14650 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
14653 unsigned int num_read;
14655 unsigned char byte;
14663 byte = bfd_get_8 (abfd, buf);
14666 result |= ((ULONGEST) (byte & 127) << shift);
14667 if ((byte & 128) == 0)
14673 *bytes_read_ptr = num_read;
14678 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
14681 int i, shift, num_read;
14682 unsigned char byte;
14690 byte = bfd_get_8 (abfd, buf);
14693 result |= ((LONGEST) (byte & 127) << shift);
14695 if ((byte & 128) == 0)
14700 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
14701 result |= -(((LONGEST) 1) << shift);
14702 *bytes_read_ptr = num_read;
14706 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14707 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14708 ADDR_SIZE is the size of addresses from the CU header. */
14711 read_addr_index_1 (unsigned int addr_index, ULONGEST addr_base, int addr_size)
14713 struct objfile *objfile = dwarf2_per_objfile->objfile;
14714 bfd *abfd = objfile->obfd;
14715 const gdb_byte *info_ptr;
14717 dwarf2_read_section (objfile, &dwarf2_per_objfile->addr);
14718 if (dwarf2_per_objfile->addr.buffer == NULL)
14719 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14721 if (addr_base + addr_index * addr_size >= dwarf2_per_objfile->addr.size)
14722 error (_("DW_FORM_addr_index pointing outside of "
14723 ".debug_addr section [in module %s]"),
14725 info_ptr = (dwarf2_per_objfile->addr.buffer
14726 + addr_base + addr_index * addr_size);
14727 if (addr_size == 4)
14728 return bfd_get_32 (abfd, info_ptr);
14730 return bfd_get_64 (abfd, info_ptr);
14733 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14736 read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index)
14738 return read_addr_index_1 (addr_index, cu->addr_base, cu->header.addr_size);
14741 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14744 read_addr_index_from_leb128 (struct dwarf2_cu *cu, gdb_byte *info_ptr,
14745 unsigned int *bytes_read)
14747 bfd *abfd = cu->objfile->obfd;
14748 unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
14750 return read_addr_index (cu, addr_index);
14753 /* Data structure to pass results from dwarf2_read_addr_index_reader
14754 back to dwarf2_read_addr_index. */
14756 struct dwarf2_read_addr_index_data
14758 ULONGEST addr_base;
14762 /* die_reader_func for dwarf2_read_addr_index. */
14765 dwarf2_read_addr_index_reader (const struct die_reader_specs *reader,
14766 gdb_byte *info_ptr,
14767 struct die_info *comp_unit_die,
14771 struct dwarf2_cu *cu = reader->cu;
14772 struct dwarf2_read_addr_index_data *aidata =
14773 (struct dwarf2_read_addr_index_data *) data;
14775 aidata->addr_base = cu->addr_base;
14776 aidata->addr_size = cu->header.addr_size;
14779 /* Given an index in .debug_addr, fetch the value.
14780 NOTE: This can be called during dwarf expression evaluation,
14781 long after the debug information has been read, and thus per_cu->cu
14782 may no longer exist. */
14785 dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
14786 unsigned int addr_index)
14788 struct objfile *objfile = per_cu->objfile;
14789 struct dwarf2_cu *cu = per_cu->cu;
14790 ULONGEST addr_base;
14793 /* This is intended to be called from outside this file. */
14794 dw2_setup (objfile);
14796 /* We need addr_base and addr_size.
14797 If we don't have PER_CU->cu, we have to get it.
14798 Nasty, but the alternative is storing the needed info in PER_CU,
14799 which at this point doesn't seem justified: it's not clear how frequently
14800 it would get used and it would increase the size of every PER_CU.
14801 Entry points like dwarf2_per_cu_addr_size do a similar thing
14802 so we're not in uncharted territory here.
14803 Alas we need to be a bit more complicated as addr_base is contained
14806 We don't need to read the entire CU(/TU).
14807 We just need the header and top level die.
14809 IWBN to use the aging mechanism to let us lazily later discard the CU.
14810 For now we skip this optimization. */
14814 addr_base = cu->addr_base;
14815 addr_size = cu->header.addr_size;
14819 struct dwarf2_read_addr_index_data aidata;
14821 /* Note: We can't use init_cutu_and_read_dies_simple here,
14822 we need addr_base. */
14823 init_cutu_and_read_dies (per_cu, NULL, 0, 0,
14824 dwarf2_read_addr_index_reader, &aidata);
14825 addr_base = aidata.addr_base;
14826 addr_size = aidata.addr_size;
14829 return read_addr_index_1 (addr_index, addr_base, addr_size);
14832 /* Given a DW_AT_str_index, fetch the string. */
14835 read_str_index (const struct die_reader_specs *reader,
14836 struct dwarf2_cu *cu, ULONGEST str_index)
14838 struct objfile *objfile = dwarf2_per_objfile->objfile;
14839 const char *dwo_name = objfile->name;
14840 bfd *abfd = objfile->obfd;
14841 struct dwo_sections *sections = &reader->dwo_file->sections;
14842 gdb_byte *info_ptr;
14843 ULONGEST str_offset;
14845 dwarf2_read_section (objfile, §ions->str);
14846 dwarf2_read_section (objfile, §ions->str_offsets);
14847 if (sections->str.buffer == NULL)
14848 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14849 " in CU at offset 0x%lx [in module %s]"),
14850 (long) cu->header.offset.sect_off, dwo_name);
14851 if (sections->str_offsets.buffer == NULL)
14852 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14853 " in CU at offset 0x%lx [in module %s]"),
14854 (long) cu->header.offset.sect_off, dwo_name);
14855 if (str_index * cu->header.offset_size >= sections->str_offsets.size)
14856 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14857 " section in CU at offset 0x%lx [in module %s]"),
14858 (long) cu->header.offset.sect_off, dwo_name);
14859 info_ptr = (sections->str_offsets.buffer
14860 + str_index * cu->header.offset_size);
14861 if (cu->header.offset_size == 4)
14862 str_offset = bfd_get_32 (abfd, info_ptr);
14864 str_offset = bfd_get_64 (abfd, info_ptr);
14865 if (str_offset >= sections->str.size)
14866 error (_("Offset from DW_FORM_str_index pointing outside of"
14867 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14868 (long) cu->header.offset.sect_off, dwo_name);
14869 return (char *) (sections->str.buffer + str_offset);
14872 /* Return the length of an LEB128 number in BUF. */
14875 leb128_size (const gdb_byte *buf)
14877 const gdb_byte *begin = buf;
14883 if ((byte & 128) == 0)
14884 return buf - begin;
14889 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
14896 cu->language = language_c;
14898 case DW_LANG_C_plus_plus:
14899 cu->language = language_cplus;
14902 cu->language = language_d;
14904 case DW_LANG_Fortran77:
14905 case DW_LANG_Fortran90:
14906 case DW_LANG_Fortran95:
14907 cu->language = language_fortran;
14910 cu->language = language_go;
14912 case DW_LANG_Mips_Assembler:
14913 cu->language = language_asm;
14916 cu->language = language_java;
14918 case DW_LANG_Ada83:
14919 case DW_LANG_Ada95:
14920 cu->language = language_ada;
14922 case DW_LANG_Modula2:
14923 cu->language = language_m2;
14925 case DW_LANG_Pascal83:
14926 cu->language = language_pascal;
14929 cu->language = language_objc;
14931 case DW_LANG_Cobol74:
14932 case DW_LANG_Cobol85:
14934 cu->language = language_minimal;
14937 cu->language_defn = language_def (cu->language);
14940 /* Return the named attribute or NULL if not there. */
14942 static struct attribute *
14943 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
14948 struct attribute *spec = NULL;
14950 for (i = 0; i < die->num_attrs; ++i)
14952 if (die->attrs[i].name == name)
14953 return &die->attrs[i];
14954 if (die->attrs[i].name == DW_AT_specification
14955 || die->attrs[i].name == DW_AT_abstract_origin)
14956 spec = &die->attrs[i];
14962 die = follow_die_ref (die, spec, &cu);
14968 /* Return the named attribute or NULL if not there,
14969 but do not follow DW_AT_specification, etc.
14970 This is for use in contexts where we're reading .debug_types dies.
14971 Following DW_AT_specification, DW_AT_abstract_origin will take us
14972 back up the chain, and we want to go down. */
14974 static struct attribute *
14975 dwarf2_attr_no_follow (struct die_info *die, unsigned int name)
14979 for (i = 0; i < die->num_attrs; ++i)
14980 if (die->attrs[i].name == name)
14981 return &die->attrs[i];
14986 /* Return non-zero iff the attribute NAME is defined for the given DIE,
14987 and holds a non-zero value. This function should only be used for
14988 DW_FORM_flag or DW_FORM_flag_present attributes. */
14991 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
14993 struct attribute *attr = dwarf2_attr (die, name, cu);
14995 return (attr && DW_UNSND (attr));
14999 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
15001 /* A DIE is a declaration if it has a DW_AT_declaration attribute
15002 which value is non-zero. However, we have to be careful with
15003 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
15004 (via dwarf2_flag_true_p) follows this attribute. So we may
15005 end up accidently finding a declaration attribute that belongs
15006 to a different DIE referenced by the specification attribute,
15007 even though the given DIE does not have a declaration attribute. */
15008 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
15009 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
15012 /* Return the die giving the specification for DIE, if there is
15013 one. *SPEC_CU is the CU containing DIE on input, and the CU
15014 containing the return value on output. If there is no
15015 specification, but there is an abstract origin, that is
15018 static struct die_info *
15019 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
15021 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
15024 if (spec_attr == NULL)
15025 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
15027 if (spec_attr == NULL)
15030 return follow_die_ref (die, spec_attr, spec_cu);
15033 /* Free the line_header structure *LH, and any arrays and strings it
15035 NOTE: This is also used as a "cleanup" function. */
15038 free_line_header (struct line_header *lh)
15040 if (lh->standard_opcode_lengths)
15041 xfree (lh->standard_opcode_lengths);
15043 /* Remember that all the lh->file_names[i].name pointers are
15044 pointers into debug_line_buffer, and don't need to be freed. */
15045 if (lh->file_names)
15046 xfree (lh->file_names);
15048 /* Similarly for the include directory names. */
15049 if (lh->include_dirs)
15050 xfree (lh->include_dirs);
15055 /* Add an entry to LH's include directory table. */
15058 add_include_dir (struct line_header *lh, char *include_dir)
15060 /* Grow the array if necessary. */
15061 if (lh->include_dirs_size == 0)
15063 lh->include_dirs_size = 1; /* for testing */
15064 lh->include_dirs = xmalloc (lh->include_dirs_size
15065 * sizeof (*lh->include_dirs));
15067 else if (lh->num_include_dirs >= lh->include_dirs_size)
15069 lh->include_dirs_size *= 2;
15070 lh->include_dirs = xrealloc (lh->include_dirs,
15071 (lh->include_dirs_size
15072 * sizeof (*lh->include_dirs)));
15075 lh->include_dirs[lh->num_include_dirs++] = include_dir;
15078 /* Add an entry to LH's file name table. */
15081 add_file_name (struct line_header *lh,
15083 unsigned int dir_index,
15084 unsigned int mod_time,
15085 unsigned int length)
15087 struct file_entry *fe;
15089 /* Grow the array if necessary. */
15090 if (lh->file_names_size == 0)
15092 lh->file_names_size = 1; /* for testing */
15093 lh->file_names = xmalloc (lh->file_names_size
15094 * sizeof (*lh->file_names));
15096 else if (lh->num_file_names >= lh->file_names_size)
15098 lh->file_names_size *= 2;
15099 lh->file_names = xrealloc (lh->file_names,
15100 (lh->file_names_size
15101 * sizeof (*lh->file_names)));
15104 fe = &lh->file_names[lh->num_file_names++];
15106 fe->dir_index = dir_index;
15107 fe->mod_time = mod_time;
15108 fe->length = length;
15109 fe->included_p = 0;
15113 /* A convenience function to find the proper .debug_line section for a
15116 static struct dwarf2_section_info *
15117 get_debug_line_section (struct dwarf2_cu *cu)
15119 struct dwarf2_section_info *section;
15121 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
15123 if (cu->dwo_unit && cu->per_cu->is_debug_types)
15124 section = &cu->dwo_unit->dwo_file->sections.line;
15125 else if (cu->per_cu->is_dwz)
15127 struct dwz_file *dwz = dwarf2_get_dwz_file ();
15129 section = &dwz->line;
15132 section = &dwarf2_per_objfile->line;
15137 /* Read the statement program header starting at OFFSET in
15138 .debug_line, or .debug_line.dwo. Return a pointer
15139 to a struct line_header, allocated using xmalloc.
15141 NOTE: the strings in the include directory and file name tables of
15142 the returned object point into the dwarf line section buffer,
15143 and must not be freed. */
15145 static struct line_header *
15146 dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu)
15148 struct cleanup *back_to;
15149 struct line_header *lh;
15150 gdb_byte *line_ptr;
15151 unsigned int bytes_read, offset_size;
15153 char *cur_dir, *cur_file;
15154 struct dwarf2_section_info *section;
15157 section = get_debug_line_section (cu);
15158 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
15159 if (section->buffer == NULL)
15161 if (cu->dwo_unit && cu->per_cu->is_debug_types)
15162 complaint (&symfile_complaints, _("missing .debug_line.dwo section"));
15164 complaint (&symfile_complaints, _("missing .debug_line section"));
15168 /* We can't do this until we know the section is non-empty.
15169 Only then do we know we have such a section. */
15170 abfd = section->asection->owner;
15172 /* Make sure that at least there's room for the total_length field.
15173 That could be 12 bytes long, but we're just going to fudge that. */
15174 if (offset + 4 >= section->size)
15176 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15180 lh = xmalloc (sizeof (*lh));
15181 memset (lh, 0, sizeof (*lh));
15182 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
15185 line_ptr = section->buffer + offset;
15187 /* Read in the header. */
15189 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
15190 &bytes_read, &offset_size);
15191 line_ptr += bytes_read;
15192 if (line_ptr + lh->total_length > (section->buffer + section->size))
15194 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15197 lh->statement_program_end = line_ptr + lh->total_length;
15198 lh->version = read_2_bytes (abfd, line_ptr);
15200 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
15201 line_ptr += offset_size;
15202 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
15204 if (lh->version >= 4)
15206 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
15210 lh->maximum_ops_per_instruction = 1;
15212 if (lh->maximum_ops_per_instruction == 0)
15214 lh->maximum_ops_per_instruction = 1;
15215 complaint (&symfile_complaints,
15216 _("invalid maximum_ops_per_instruction "
15217 "in `.debug_line' section"));
15220 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
15222 lh->line_base = read_1_signed_byte (abfd, line_ptr);
15224 lh->line_range = read_1_byte (abfd, line_ptr);
15226 lh->opcode_base = read_1_byte (abfd, line_ptr);
15228 lh->standard_opcode_lengths
15229 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
15231 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
15232 for (i = 1; i < lh->opcode_base; ++i)
15234 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
15238 /* Read directory table. */
15239 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
15241 line_ptr += bytes_read;
15242 add_include_dir (lh, cur_dir);
15244 line_ptr += bytes_read;
15246 /* Read file name table. */
15247 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
15249 unsigned int dir_index, mod_time, length;
15251 line_ptr += bytes_read;
15252 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15253 line_ptr += bytes_read;
15254 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15255 line_ptr += bytes_read;
15256 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15257 line_ptr += bytes_read;
15259 add_file_name (lh, cur_file, dir_index, mod_time, length);
15261 line_ptr += bytes_read;
15262 lh->statement_program_start = line_ptr;
15264 if (line_ptr > (section->buffer + section->size))
15265 complaint (&symfile_complaints,
15266 _("line number info header doesn't "
15267 "fit in `.debug_line' section"));
15269 discard_cleanups (back_to);
15273 /* Subroutine of dwarf_decode_lines to simplify it.
15274 Return the file name of the psymtab for included file FILE_INDEX
15275 in line header LH of PST.
15276 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15277 If space for the result is malloc'd, it will be freed by a cleanup.
15278 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
15280 The function creates dangling cleanup registration. */
15283 psymtab_include_file_name (const struct line_header *lh, int file_index,
15284 const struct partial_symtab *pst,
15285 const char *comp_dir)
15287 const struct file_entry fe = lh->file_names [file_index];
15288 char *include_name = fe.name;
15289 char *include_name_to_compare = include_name;
15290 char *dir_name = NULL;
15291 const char *pst_filename;
15292 char *copied_name = NULL;
15296 dir_name = lh->include_dirs[fe.dir_index - 1];
15298 if (!IS_ABSOLUTE_PATH (include_name)
15299 && (dir_name != NULL || comp_dir != NULL))
15301 /* Avoid creating a duplicate psymtab for PST.
15302 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15303 Before we do the comparison, however, we need to account
15304 for DIR_NAME and COMP_DIR.
15305 First prepend dir_name (if non-NULL). If we still don't
15306 have an absolute path prepend comp_dir (if non-NULL).
15307 However, the directory we record in the include-file's
15308 psymtab does not contain COMP_DIR (to match the
15309 corresponding symtab(s)).
15314 bash$ gcc -g ./hello.c
15315 include_name = "hello.c"
15317 DW_AT_comp_dir = comp_dir = "/tmp"
15318 DW_AT_name = "./hello.c" */
15320 if (dir_name != NULL)
15322 include_name = concat (dir_name, SLASH_STRING,
15323 include_name, (char *)NULL);
15324 include_name_to_compare = include_name;
15325 make_cleanup (xfree, include_name);
15327 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
15329 include_name_to_compare = concat (comp_dir, SLASH_STRING,
15330 include_name, (char *)NULL);
15334 pst_filename = pst->filename;
15335 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
15337 copied_name = concat (pst->dirname, SLASH_STRING,
15338 pst_filename, (char *)NULL);
15339 pst_filename = copied_name;
15342 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
15344 if (include_name_to_compare != include_name)
15345 xfree (include_name_to_compare);
15346 if (copied_name != NULL)
15347 xfree (copied_name);
15351 return include_name;
15354 /* Ignore this record_line request. */
15357 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
15362 /* Subroutine of dwarf_decode_lines to simplify it.
15363 Process the line number information in LH. */
15366 dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
15367 struct dwarf2_cu *cu, struct partial_symtab *pst)
15369 gdb_byte *line_ptr, *extended_end;
15370 gdb_byte *line_end;
15371 unsigned int bytes_read, extended_len;
15372 unsigned char op_code, extended_op, adj_opcode;
15373 CORE_ADDR baseaddr;
15374 struct objfile *objfile = cu->objfile;
15375 bfd *abfd = objfile->obfd;
15376 struct gdbarch *gdbarch = get_objfile_arch (objfile);
15377 const int decode_for_pst_p = (pst != NULL);
15378 struct subfile *last_subfile = NULL;
15379 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
15382 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15384 line_ptr = lh->statement_program_start;
15385 line_end = lh->statement_program_end;
15387 /* Read the statement sequences until there's nothing left. */
15388 while (line_ptr < line_end)
15390 /* state machine registers */
15391 CORE_ADDR address = 0;
15392 unsigned int file = 1;
15393 unsigned int line = 1;
15394 unsigned int column = 0;
15395 int is_stmt = lh->default_is_stmt;
15396 int basic_block = 0;
15397 int end_sequence = 0;
15399 unsigned char op_index = 0;
15401 if (!decode_for_pst_p && lh->num_file_names >= file)
15403 /* Start a subfile for the current file of the state machine. */
15404 /* lh->include_dirs and lh->file_names are 0-based, but the
15405 directory and file name numbers in the statement program
15407 struct file_entry *fe = &lh->file_names[file - 1];
15411 dir = lh->include_dirs[fe->dir_index - 1];
15413 dwarf2_start_subfile (fe->name, dir, comp_dir);
15416 /* Decode the table. */
15417 while (!end_sequence)
15419 op_code = read_1_byte (abfd, line_ptr);
15421 if (line_ptr > line_end)
15423 dwarf2_debug_line_missing_end_sequence_complaint ();
15427 if (op_code >= lh->opcode_base)
15429 /* Special operand. */
15430 adj_opcode = op_code - lh->opcode_base;
15431 address += (((op_index + (adj_opcode / lh->line_range))
15432 / lh->maximum_ops_per_instruction)
15433 * lh->minimum_instruction_length);
15434 op_index = ((op_index + (adj_opcode / lh->line_range))
15435 % lh->maximum_ops_per_instruction);
15436 line += lh->line_base + (adj_opcode % lh->line_range);
15437 if (lh->num_file_names < file || file == 0)
15438 dwarf2_debug_line_missing_file_complaint ();
15439 /* For now we ignore lines not starting on an
15440 instruction boundary. */
15441 else if (op_index == 0)
15443 lh->file_names[file - 1].included_p = 1;
15444 if (!decode_for_pst_p && is_stmt)
15446 if (last_subfile != current_subfile)
15448 addr = gdbarch_addr_bits_remove (gdbarch, address);
15450 (*p_record_line) (last_subfile, 0, addr);
15451 last_subfile = current_subfile;
15453 /* Append row to matrix using current values. */
15454 addr = gdbarch_addr_bits_remove (gdbarch, address);
15455 (*p_record_line) (current_subfile, line, addr);
15460 else switch (op_code)
15462 case DW_LNS_extended_op:
15463 extended_len = read_unsigned_leb128 (abfd, line_ptr,
15465 line_ptr += bytes_read;
15466 extended_end = line_ptr + extended_len;
15467 extended_op = read_1_byte (abfd, line_ptr);
15469 switch (extended_op)
15471 case DW_LNE_end_sequence:
15472 p_record_line = record_line;
15475 case DW_LNE_set_address:
15476 address = read_address (abfd, line_ptr, cu, &bytes_read);
15478 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
15480 /* This line table is for a function which has been
15481 GCd by the linker. Ignore it. PR gdb/12528 */
15484 = line_ptr - get_debug_line_section (cu)->buffer;
15486 complaint (&symfile_complaints,
15487 _(".debug_line address at offset 0x%lx is 0 "
15489 line_offset, objfile->name);
15490 p_record_line = noop_record_line;
15494 line_ptr += bytes_read;
15495 address += baseaddr;
15497 case DW_LNE_define_file:
15500 unsigned int dir_index, mod_time, length;
15502 cur_file = read_direct_string (abfd, line_ptr,
15504 line_ptr += bytes_read;
15506 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15507 line_ptr += bytes_read;
15509 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15510 line_ptr += bytes_read;
15512 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15513 line_ptr += bytes_read;
15514 add_file_name (lh, cur_file, dir_index, mod_time, length);
15517 case DW_LNE_set_discriminator:
15518 /* The discriminator is not interesting to the debugger;
15520 line_ptr = extended_end;
15523 complaint (&symfile_complaints,
15524 _("mangled .debug_line section"));
15527 /* Make sure that we parsed the extended op correctly. If e.g.
15528 we expected a different address size than the producer used,
15529 we may have read the wrong number of bytes. */
15530 if (line_ptr != extended_end)
15532 complaint (&symfile_complaints,
15533 _("mangled .debug_line section"));
15538 if (lh->num_file_names < file || file == 0)
15539 dwarf2_debug_line_missing_file_complaint ();
15542 lh->file_names[file - 1].included_p = 1;
15543 if (!decode_for_pst_p && is_stmt)
15545 if (last_subfile != current_subfile)
15547 addr = gdbarch_addr_bits_remove (gdbarch, address);
15549 (*p_record_line) (last_subfile, 0, addr);
15550 last_subfile = current_subfile;
15552 addr = gdbarch_addr_bits_remove (gdbarch, address);
15553 (*p_record_line) (current_subfile, line, addr);
15558 case DW_LNS_advance_pc:
15561 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15563 address += (((op_index + adjust)
15564 / lh->maximum_ops_per_instruction)
15565 * lh->minimum_instruction_length);
15566 op_index = ((op_index + adjust)
15567 % lh->maximum_ops_per_instruction);
15568 line_ptr += bytes_read;
15571 case DW_LNS_advance_line:
15572 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
15573 line_ptr += bytes_read;
15575 case DW_LNS_set_file:
15577 /* The arrays lh->include_dirs and lh->file_names are
15578 0-based, but the directory and file name numbers in
15579 the statement program are 1-based. */
15580 struct file_entry *fe;
15583 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15584 line_ptr += bytes_read;
15585 if (lh->num_file_names < file || file == 0)
15586 dwarf2_debug_line_missing_file_complaint ();
15589 fe = &lh->file_names[file - 1];
15591 dir = lh->include_dirs[fe->dir_index - 1];
15592 if (!decode_for_pst_p)
15594 last_subfile = current_subfile;
15595 dwarf2_start_subfile (fe->name, dir, comp_dir);
15600 case DW_LNS_set_column:
15601 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15602 line_ptr += bytes_read;
15604 case DW_LNS_negate_stmt:
15605 is_stmt = (!is_stmt);
15607 case DW_LNS_set_basic_block:
15610 /* Add to the address register of the state machine the
15611 address increment value corresponding to special opcode
15612 255. I.e., this value is scaled by the minimum
15613 instruction length since special opcode 255 would have
15614 scaled the increment. */
15615 case DW_LNS_const_add_pc:
15617 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
15619 address += (((op_index + adjust)
15620 / lh->maximum_ops_per_instruction)
15621 * lh->minimum_instruction_length);
15622 op_index = ((op_index + adjust)
15623 % lh->maximum_ops_per_instruction);
15626 case DW_LNS_fixed_advance_pc:
15627 address += read_2_bytes (abfd, line_ptr);
15633 /* Unknown standard opcode, ignore it. */
15636 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
15638 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15639 line_ptr += bytes_read;
15644 if (lh->num_file_names < file || file == 0)
15645 dwarf2_debug_line_missing_file_complaint ();
15648 lh->file_names[file - 1].included_p = 1;
15649 if (!decode_for_pst_p)
15651 addr = gdbarch_addr_bits_remove (gdbarch, address);
15652 (*p_record_line) (current_subfile, 0, addr);
15658 /* Decode the Line Number Program (LNP) for the given line_header
15659 structure and CU. The actual information extracted and the type
15660 of structures created from the LNP depends on the value of PST.
15662 1. If PST is NULL, then this procedure uses the data from the program
15663 to create all necessary symbol tables, and their linetables.
15665 2. If PST is not NULL, this procedure reads the program to determine
15666 the list of files included by the unit represented by PST, and
15667 builds all the associated partial symbol tables.
15669 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15670 It is used for relative paths in the line table.
15671 NOTE: When processing partial symtabs (pst != NULL),
15672 comp_dir == pst->dirname.
15674 NOTE: It is important that psymtabs have the same file name (via strcmp)
15675 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15676 symtab we don't use it in the name of the psymtabs we create.
15677 E.g. expand_line_sal requires this when finding psymtabs to expand.
15678 A good testcase for this is mb-inline.exp. */
15681 dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
15682 struct dwarf2_cu *cu, struct partial_symtab *pst,
15683 int want_line_info)
15685 struct objfile *objfile = cu->objfile;
15686 const int decode_for_pst_p = (pst != NULL);
15687 struct subfile *first_subfile = current_subfile;
15689 if (want_line_info)
15690 dwarf_decode_lines_1 (lh, comp_dir, cu, pst);
15692 if (decode_for_pst_p)
15696 /* Now that we're done scanning the Line Header Program, we can
15697 create the psymtab of each included file. */
15698 for (file_index = 0; file_index < lh->num_file_names; file_index++)
15699 if (lh->file_names[file_index].included_p == 1)
15701 char *include_name =
15702 psymtab_include_file_name (lh, file_index, pst, comp_dir);
15703 if (include_name != NULL)
15704 dwarf2_create_include_psymtab (include_name, pst, objfile);
15709 /* Make sure a symtab is created for every file, even files
15710 which contain only variables (i.e. no code with associated
15714 for (i = 0; i < lh->num_file_names; i++)
15717 struct file_entry *fe;
15719 fe = &lh->file_names[i];
15721 dir = lh->include_dirs[fe->dir_index - 1];
15722 dwarf2_start_subfile (fe->name, dir, comp_dir);
15724 /* Skip the main file; we don't need it, and it must be
15725 allocated last, so that it will show up before the
15726 non-primary symtabs in the objfile's symtab list. */
15727 if (current_subfile == first_subfile)
15730 if (current_subfile->symtab == NULL)
15731 current_subfile->symtab = allocate_symtab (current_subfile->name,
15733 fe->symtab = current_subfile->symtab;
15738 /* Start a subfile for DWARF. FILENAME is the name of the file and
15739 DIRNAME the name of the source directory which contains FILENAME
15740 or NULL if not known. COMP_DIR is the compilation directory for the
15741 linetable's compilation unit or NULL if not known.
15742 This routine tries to keep line numbers from identical absolute and
15743 relative file names in a common subfile.
15745 Using the `list' example from the GDB testsuite, which resides in
15746 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15747 of /srcdir/list0.c yields the following debugging information for list0.c:
15749 DW_AT_name: /srcdir/list0.c
15750 DW_AT_comp_dir: /compdir
15751 files.files[0].name: list0.h
15752 files.files[0].dir: /srcdir
15753 files.files[1].name: list0.c
15754 files.files[1].dir: /srcdir
15756 The line number information for list0.c has to end up in a single
15757 subfile, so that `break /srcdir/list0.c:1' works as expected.
15758 start_subfile will ensure that this happens provided that we pass the
15759 concatenation of files.files[1].dir and files.files[1].name as the
15763 dwarf2_start_subfile (char *filename, const char *dirname,
15764 const char *comp_dir)
15768 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15769 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15770 second argument to start_subfile. To be consistent, we do the
15771 same here. In order not to lose the line information directory,
15772 we concatenate it to the filename when it makes sense.
15773 Note that the Dwarf3 standard says (speaking of filenames in line
15774 information): ``The directory index is ignored for file names
15775 that represent full path names''. Thus ignoring dirname in the
15776 `else' branch below isn't an issue. */
15778 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
15779 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
15781 fullname = filename;
15783 start_subfile (fullname, comp_dir);
15785 if (fullname != filename)
15789 /* Start a symtab for DWARF.
15790 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15793 dwarf2_start_symtab (struct dwarf2_cu *cu,
15794 const char *name, const char *comp_dir, CORE_ADDR low_pc)
15796 start_symtab (name, comp_dir, low_pc);
15797 record_debugformat ("DWARF 2");
15798 record_producer (cu->producer);
15800 /* We assume that we're processing GCC output. */
15801 processing_gcc_compilation = 2;
15803 cu->processing_has_namespace_info = 0;
15807 var_decode_location (struct attribute *attr, struct symbol *sym,
15808 struct dwarf2_cu *cu)
15810 struct objfile *objfile = cu->objfile;
15811 struct comp_unit_head *cu_header = &cu->header;
15813 /* NOTE drow/2003-01-30: There used to be a comment and some special
15814 code here to turn a symbol with DW_AT_external and a
15815 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15816 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15817 with some versions of binutils) where shared libraries could have
15818 relocations against symbols in their debug information - the
15819 minimal symbol would have the right address, but the debug info
15820 would not. It's no longer necessary, because we will explicitly
15821 apply relocations when we read in the debug information now. */
15823 /* A DW_AT_location attribute with no contents indicates that a
15824 variable has been optimized away. */
15825 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
15827 SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
15831 /* Handle one degenerate form of location expression specially, to
15832 preserve GDB's previous behavior when section offsets are
15833 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15834 then mark this symbol as LOC_STATIC. */
15836 if (attr_form_is_block (attr)
15837 && ((DW_BLOCK (attr)->data[0] == DW_OP_addr
15838 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size)
15839 || (DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index
15840 && (DW_BLOCK (attr)->size
15841 == 1 + leb128_size (&DW_BLOCK (attr)->data[1])))))
15843 unsigned int dummy;
15845 if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
15846 SYMBOL_VALUE_ADDRESS (sym) =
15847 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
15849 SYMBOL_VALUE_ADDRESS (sym) =
15850 read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy);
15851 SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
15852 fixup_symbol_section (sym, objfile);
15853 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
15854 SYMBOL_SECTION (sym));
15858 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15859 expression evaluator, and use LOC_COMPUTED only when necessary
15860 (i.e. when the value of a register or memory location is
15861 referenced, or a thread-local block, etc.). Then again, it might
15862 not be worthwhile. I'm assuming that it isn't unless performance
15863 or memory numbers show me otherwise. */
15865 dwarf2_symbol_mark_computed (attr, sym, cu, 0);
15867 if (SYMBOL_COMPUTED_OPS (sym)->location_has_loclist)
15868 cu->has_loclist = 1;
15871 /* Given a pointer to a DWARF information entry, figure out if we need
15872 to make a symbol table entry for it, and if so, create a new entry
15873 and return a pointer to it.
15874 If TYPE is NULL, determine symbol type from the die, otherwise
15875 used the passed type.
15876 If SPACE is not NULL, use it to hold the new symbol. If it is
15877 NULL, allocate a new symbol on the objfile's obstack. */
15879 static struct symbol *
15880 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
15881 struct symbol *space)
15883 struct objfile *objfile = cu->objfile;
15884 struct symbol *sym = NULL;
15886 struct attribute *attr = NULL;
15887 struct attribute *attr2 = NULL;
15888 CORE_ADDR baseaddr;
15889 struct pending **list_to_add = NULL;
15891 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
15893 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15895 name = dwarf2_name (die, cu);
15898 const char *linkagename;
15899 int suppress_add = 0;
15904 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
15905 OBJSTAT (objfile, n_syms++);
15907 /* Cache this symbol's name and the name's demangled form (if any). */
15908 SYMBOL_SET_LANGUAGE (sym, cu->language);
15909 linkagename = dwarf2_physname (name, die, cu);
15910 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
15912 /* Fortran does not have mangling standard and the mangling does differ
15913 between gfortran, iFort etc. */
15914 if (cu->language == language_fortran
15915 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
15916 symbol_set_demangled_name (&(sym->ginfo),
15917 dwarf2_full_name (name, die, cu),
15920 /* Default assumptions.
15921 Use the passed type or decode it from the die. */
15922 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
15923 SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
15925 SYMBOL_TYPE (sym) = type;
15927 SYMBOL_TYPE (sym) = die_type (die, cu);
15928 attr = dwarf2_attr (die,
15929 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
15933 SYMBOL_LINE (sym) = DW_UNSND (attr);
15936 attr = dwarf2_attr (die,
15937 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
15941 int file_index = DW_UNSND (attr);
15943 if (cu->line_header == NULL
15944 || file_index > cu->line_header->num_file_names)
15945 complaint (&symfile_complaints,
15946 _("file index out of range"));
15947 else if (file_index > 0)
15949 struct file_entry *fe;
15951 fe = &cu->line_header->file_names[file_index - 1];
15952 SYMBOL_SYMTAB (sym) = fe->symtab;
15959 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
15962 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
15964 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
15965 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
15966 SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
15967 add_symbol_to_list (sym, cu->list_in_scope);
15969 case DW_TAG_subprogram:
15970 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15972 SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
15973 attr2 = dwarf2_attr (die, DW_AT_external, cu);
15974 if ((attr2 && (DW_UNSND (attr2) != 0))
15975 || cu->language == language_ada)
15977 /* Subprograms marked external are stored as a global symbol.
15978 Ada subprograms, whether marked external or not, are always
15979 stored as a global symbol, because we want to be able to
15980 access them globally. For instance, we want to be able
15981 to break on a nested subprogram without having to
15982 specify the context. */
15983 list_to_add = &global_symbols;
15987 list_to_add = cu->list_in_scope;
15990 case DW_TAG_inlined_subroutine:
15991 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15993 SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
15994 SYMBOL_INLINED (sym) = 1;
15995 list_to_add = cu->list_in_scope;
15997 case DW_TAG_template_value_param:
15999 /* Fall through. */
16000 case DW_TAG_constant:
16001 case DW_TAG_variable:
16002 case DW_TAG_member:
16003 /* Compilation with minimal debug info may result in
16004 variables with missing type entries. Change the
16005 misleading `void' type to something sensible. */
16006 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
16008 = objfile_type (objfile)->nodebug_data_symbol;
16010 attr = dwarf2_attr (die, DW_AT_const_value, cu);
16011 /* In the case of DW_TAG_member, we should only be called for
16012 static const members. */
16013 if (die->tag == DW_TAG_member)
16015 /* dwarf2_add_field uses die_is_declaration,
16016 so we do the same. */
16017 gdb_assert (die_is_declaration (die, cu));
16022 dwarf2_const_value (attr, sym, cu);
16023 attr2 = dwarf2_attr (die, DW_AT_external, cu);
16026 if (attr2 && (DW_UNSND (attr2) != 0))
16027 list_to_add = &global_symbols;
16029 list_to_add = cu->list_in_scope;
16033 attr = dwarf2_attr (die, DW_AT_location, cu);
16036 var_decode_location (attr, sym, cu);
16037 attr2 = dwarf2_attr (die, DW_AT_external, cu);
16039 /* Fortran explicitly imports any global symbols to the local
16040 scope by DW_TAG_common_block. */
16041 if (cu->language == language_fortran && die->parent
16042 && die->parent->tag == DW_TAG_common_block)
16045 if (SYMBOL_CLASS (sym) == LOC_STATIC
16046 && SYMBOL_VALUE_ADDRESS (sym) == 0
16047 && !dwarf2_per_objfile->has_section_at_zero)
16049 /* When a static variable is eliminated by the linker,
16050 the corresponding debug information is not stripped
16051 out, but the variable address is set to null;
16052 do not add such variables into symbol table. */
16054 else if (attr2 && (DW_UNSND (attr2) != 0))
16056 /* Workaround gfortran PR debug/40040 - it uses
16057 DW_AT_location for variables in -fPIC libraries which may
16058 get overriden by other libraries/executable and get
16059 a different address. Resolve it by the minimal symbol
16060 which may come from inferior's executable using copy
16061 relocation. Make this workaround only for gfortran as for
16062 other compilers GDB cannot guess the minimal symbol
16063 Fortran mangling kind. */
16064 if (cu->language == language_fortran && die->parent
16065 && die->parent->tag == DW_TAG_module
16067 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
16068 SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
16070 /* A variable with DW_AT_external is never static,
16071 but it may be block-scoped. */
16072 list_to_add = (cu->list_in_scope == &file_symbols
16073 ? &global_symbols : cu->list_in_scope);
16076 list_to_add = cu->list_in_scope;
16080 /* We do not know the address of this symbol.
16081 If it is an external symbol and we have type information
16082 for it, enter the symbol as a LOC_UNRESOLVED symbol.
16083 The address of the variable will then be determined from
16084 the minimal symbol table whenever the variable is
16086 attr2 = dwarf2_attr (die, DW_AT_external, cu);
16088 /* Fortran explicitly imports any global symbols to the local
16089 scope by DW_TAG_common_block. */
16090 if (cu->language == language_fortran && die->parent
16091 && die->parent->tag == DW_TAG_common_block)
16093 /* SYMBOL_CLASS doesn't matter here because
16094 read_common_block is going to reset it. */
16096 list_to_add = cu->list_in_scope;
16098 else if (attr2 && (DW_UNSND (attr2) != 0)
16099 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
16101 /* A variable with DW_AT_external is never static, but it
16102 may be block-scoped. */
16103 list_to_add = (cu->list_in_scope == &file_symbols
16104 ? &global_symbols : cu->list_in_scope);
16106 SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
16108 else if (!die_is_declaration (die, cu))
16110 /* Use the default LOC_OPTIMIZED_OUT class. */
16111 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
16113 list_to_add = cu->list_in_scope;
16117 case DW_TAG_formal_parameter:
16118 /* If we are inside a function, mark this as an argument. If
16119 not, we might be looking at an argument to an inlined function
16120 when we do not have enough information to show inlined frames;
16121 pretend it's a local variable in that case so that the user can
16123 if (context_stack_depth > 0
16124 && context_stack[context_stack_depth - 1].name != NULL)
16125 SYMBOL_IS_ARGUMENT (sym) = 1;
16126 attr = dwarf2_attr (die, DW_AT_location, cu);
16129 var_decode_location (attr, sym, cu);
16131 attr = dwarf2_attr (die, DW_AT_const_value, cu);
16134 dwarf2_const_value (attr, sym, cu);
16137 list_to_add = cu->list_in_scope;
16139 case DW_TAG_unspecified_parameters:
16140 /* From varargs functions; gdb doesn't seem to have any
16141 interest in this information, so just ignore it for now.
16144 case DW_TAG_template_type_param:
16146 /* Fall through. */
16147 case DW_TAG_class_type:
16148 case DW_TAG_interface_type:
16149 case DW_TAG_structure_type:
16150 case DW_TAG_union_type:
16151 case DW_TAG_set_type:
16152 case DW_TAG_enumeration_type:
16153 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
16154 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
16157 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
16158 really ever be static objects: otherwise, if you try
16159 to, say, break of a class's method and you're in a file
16160 which doesn't mention that class, it won't work unless
16161 the check for all static symbols in lookup_symbol_aux
16162 saves you. See the OtherFileClass tests in
16163 gdb.c++/namespace.exp. */
16167 list_to_add = (cu->list_in_scope == &file_symbols
16168 && (cu->language == language_cplus
16169 || cu->language == language_java)
16170 ? &global_symbols : cu->list_in_scope);
16172 /* The semantics of C++ state that "struct foo {
16173 ... }" also defines a typedef for "foo". A Java
16174 class declaration also defines a typedef for the
16176 if (cu->language == language_cplus
16177 || cu->language == language_java
16178 || cu->language == language_ada)
16180 /* The symbol's name is already allocated along
16181 with this objfile, so we don't need to
16182 duplicate it for the type. */
16183 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
16184 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
16189 case DW_TAG_typedef:
16190 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
16191 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
16192 list_to_add = cu->list_in_scope;
16194 case DW_TAG_base_type:
16195 case DW_TAG_subrange_type:
16196 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
16197 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
16198 list_to_add = cu->list_in_scope;
16200 case DW_TAG_enumerator:
16201 attr = dwarf2_attr (die, DW_AT_const_value, cu);
16204 dwarf2_const_value (attr, sym, cu);
16207 /* NOTE: carlton/2003-11-10: See comment above in the
16208 DW_TAG_class_type, etc. block. */
16210 list_to_add = (cu->list_in_scope == &file_symbols
16211 && (cu->language == language_cplus
16212 || cu->language == language_java)
16213 ? &global_symbols : cu->list_in_scope);
16216 case DW_TAG_namespace:
16217 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
16218 list_to_add = &global_symbols;
16220 case DW_TAG_common_block:
16221 SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
16222 SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
16223 add_symbol_to_list (sym, cu->list_in_scope);
16226 /* Not a tag we recognize. Hopefully we aren't processing
16227 trash data, but since we must specifically ignore things
16228 we don't recognize, there is nothing else we should do at
16230 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
16231 dwarf_tag_name (die->tag));
16237 sym->hash_next = objfile->template_symbols;
16238 objfile->template_symbols = sym;
16239 list_to_add = NULL;
16242 if (list_to_add != NULL)
16243 add_symbol_to_list (sym, list_to_add);
16245 /* For the benefit of old versions of GCC, check for anonymous
16246 namespaces based on the demangled name. */
16247 if (!cu->processing_has_namespace_info
16248 && cu->language == language_cplus)
16249 cp_scan_for_anonymous_namespaces (sym, objfile);
16254 /* A wrapper for new_symbol_full that always allocates a new symbol. */
16256 static struct symbol *
16257 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
16259 return new_symbol_full (die, type, cu, NULL);
16262 /* Given an attr with a DW_FORM_dataN value in host byte order,
16263 zero-extend it as appropriate for the symbol's type. The DWARF
16264 standard (v4) is not entirely clear about the meaning of using
16265 DW_FORM_dataN for a constant with a signed type, where the type is
16266 wider than the data. The conclusion of a discussion on the DWARF
16267 list was that this is unspecified. We choose to always zero-extend
16268 because that is the interpretation long in use by GCC. */
16271 dwarf2_const_value_data (struct attribute *attr, struct type *type,
16272 const char *name, struct obstack *obstack,
16273 struct dwarf2_cu *cu, LONGEST *value, int bits)
16275 struct objfile *objfile = cu->objfile;
16276 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
16277 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
16278 LONGEST l = DW_UNSND (attr);
16280 if (bits < sizeof (*value) * 8)
16282 l &= ((LONGEST) 1 << bits) - 1;
16285 else if (bits == sizeof (*value) * 8)
16289 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
16290 store_unsigned_integer (bytes, bits / 8, byte_order, l);
16297 /* Read a constant value from an attribute. Either set *VALUE, or if
16298 the value does not fit in *VALUE, set *BYTES - either already
16299 allocated on the objfile obstack, or newly allocated on OBSTACK,
16300 or, set *BATON, if we translated the constant to a location
16304 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
16305 const char *name, struct obstack *obstack,
16306 struct dwarf2_cu *cu,
16307 LONGEST *value, gdb_byte **bytes,
16308 struct dwarf2_locexpr_baton **baton)
16310 struct objfile *objfile = cu->objfile;
16311 struct comp_unit_head *cu_header = &cu->header;
16312 struct dwarf_block *blk;
16313 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
16314 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
16320 switch (attr->form)
16323 case DW_FORM_GNU_addr_index:
16327 if (TYPE_LENGTH (type) != cu_header->addr_size)
16328 dwarf2_const_value_length_mismatch_complaint (name,
16329 cu_header->addr_size,
16330 TYPE_LENGTH (type));
16331 /* Symbols of this form are reasonably rare, so we just
16332 piggyback on the existing location code rather than writing
16333 a new implementation of symbol_computed_ops. */
16334 *baton = obstack_alloc (&objfile->objfile_obstack,
16335 sizeof (struct dwarf2_locexpr_baton));
16336 (*baton)->per_cu = cu->per_cu;
16337 gdb_assert ((*baton)->per_cu);
16339 (*baton)->size = 2 + cu_header->addr_size;
16340 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
16341 (*baton)->data = data;
16343 data[0] = DW_OP_addr;
16344 store_unsigned_integer (&data[1], cu_header->addr_size,
16345 byte_order, DW_ADDR (attr));
16346 data[cu_header->addr_size + 1] = DW_OP_stack_value;
16349 case DW_FORM_string:
16351 case DW_FORM_GNU_str_index:
16352 case DW_FORM_GNU_strp_alt:
16353 /* DW_STRING is already allocated on the objfile obstack, point
16355 *bytes = (gdb_byte *) DW_STRING (attr);
16357 case DW_FORM_block1:
16358 case DW_FORM_block2:
16359 case DW_FORM_block4:
16360 case DW_FORM_block:
16361 case DW_FORM_exprloc:
16362 blk = DW_BLOCK (attr);
16363 if (TYPE_LENGTH (type) != blk->size)
16364 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
16365 TYPE_LENGTH (type));
16366 *bytes = blk->data;
16369 /* The DW_AT_const_value attributes are supposed to carry the
16370 symbol's value "represented as it would be on the target
16371 architecture." By the time we get here, it's already been
16372 converted to host endianness, so we just need to sign- or
16373 zero-extend it as appropriate. */
16374 case DW_FORM_data1:
16375 *bytes = dwarf2_const_value_data (attr, type, name,
16376 obstack, cu, value, 8);
16378 case DW_FORM_data2:
16379 *bytes = dwarf2_const_value_data (attr, type, name,
16380 obstack, cu, value, 16);
16382 case DW_FORM_data4:
16383 *bytes = dwarf2_const_value_data (attr, type, name,
16384 obstack, cu, value, 32);
16386 case DW_FORM_data8:
16387 *bytes = dwarf2_const_value_data (attr, type, name,
16388 obstack, cu, value, 64);
16391 case DW_FORM_sdata:
16392 *value = DW_SND (attr);
16395 case DW_FORM_udata:
16396 *value = DW_UNSND (attr);
16400 complaint (&symfile_complaints,
16401 _("unsupported const value attribute form: '%s'"),
16402 dwarf_form_name (attr->form));
16409 /* Copy constant value from an attribute to a symbol. */
16412 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
16413 struct dwarf2_cu *cu)
16415 struct objfile *objfile = cu->objfile;
16416 struct comp_unit_head *cu_header = &cu->header;
16419 struct dwarf2_locexpr_baton *baton;
16421 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
16422 SYMBOL_PRINT_NAME (sym),
16423 &objfile->objfile_obstack, cu,
16424 &value, &bytes, &baton);
16428 SYMBOL_LOCATION_BATON (sym) = baton;
16429 SYMBOL_ACLASS_INDEX (sym) = dwarf2_locexpr_index;
16431 else if (bytes != NULL)
16433 SYMBOL_VALUE_BYTES (sym) = bytes;
16434 SYMBOL_ACLASS_INDEX (sym) = LOC_CONST_BYTES;
16438 SYMBOL_VALUE (sym) = value;
16439 SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
16443 /* Return the type of the die in question using its DW_AT_type attribute. */
16445 static struct type *
16446 die_type (struct die_info *die, struct dwarf2_cu *cu)
16448 struct attribute *type_attr;
16450 type_attr = dwarf2_attr (die, DW_AT_type, cu);
16453 /* A missing DW_AT_type represents a void type. */
16454 return objfile_type (cu->objfile)->builtin_void;
16457 return lookup_die_type (die, type_attr, cu);
16460 /* True iff CU's producer generates GNAT Ada auxiliary information
16461 that allows to find parallel types through that information instead
16462 of having to do expensive parallel lookups by type name. */
16465 need_gnat_info (struct dwarf2_cu *cu)
16467 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16468 of GNAT produces this auxiliary information, without any indication
16469 that it is produced. Part of enhancing the FSF version of GNAT
16470 to produce that information will be to put in place an indicator
16471 that we can use in order to determine whether the descriptive type
16472 info is available or not. One suggestion that has been made is
16473 to use a new attribute, attached to the CU die. For now, assume
16474 that the descriptive type info is not available. */
16478 /* Return the auxiliary type of the die in question using its
16479 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16480 attribute is not present. */
16482 static struct type *
16483 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
16485 struct attribute *type_attr;
16487 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
16491 return lookup_die_type (die, type_attr, cu);
16494 /* If DIE has a descriptive_type attribute, then set the TYPE's
16495 descriptive type accordingly. */
16498 set_descriptive_type (struct type *type, struct die_info *die,
16499 struct dwarf2_cu *cu)
16501 struct type *descriptive_type = die_descriptive_type (die, cu);
16503 if (descriptive_type)
16505 ALLOCATE_GNAT_AUX_TYPE (type);
16506 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
16510 /* Return the containing type of the die in question using its
16511 DW_AT_containing_type attribute. */
16513 static struct type *
16514 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
16516 struct attribute *type_attr;
16518 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
16520 error (_("Dwarf Error: Problem turning containing type into gdb type "
16521 "[in module %s]"), cu->objfile->name);
16523 return lookup_die_type (die, type_attr, cu);
16526 /* Look up the type of DIE in CU using its type attribute ATTR.
16527 If there is no type substitute an error marker. */
16529 static struct type *
16530 lookup_die_type (struct die_info *die, struct attribute *attr,
16531 struct dwarf2_cu *cu)
16533 struct objfile *objfile = cu->objfile;
16534 struct type *this_type;
16536 /* First see if we have it cached. */
16538 if (attr->form == DW_FORM_GNU_ref_alt)
16540 struct dwarf2_per_cu_data *per_cu;
16541 sect_offset offset = dwarf2_get_ref_die_offset (attr);
16543 per_cu = dwarf2_find_containing_comp_unit (offset, 1, cu->objfile);
16544 this_type = get_die_type_at_offset (offset, per_cu);
16546 else if (is_ref_attr (attr))
16548 sect_offset offset = dwarf2_get_ref_die_offset (attr);
16550 this_type = get_die_type_at_offset (offset, cu->per_cu);
16552 else if (attr->form == DW_FORM_ref_sig8)
16554 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
16556 /* sig_type will be NULL if the signatured type is missing from
16558 if (sig_type == NULL)
16559 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16560 "at 0x%x [in module %s]"),
16561 die->offset.sect_off, objfile->name);
16563 gdb_assert (sig_type->per_cu.is_debug_types);
16564 /* If we haven't filled in type_offset_in_section yet, then we
16565 haven't read the type in yet. */
16567 if (sig_type->type_offset_in_section.sect_off != 0)
16570 get_die_type_at_offset (sig_type->type_offset_in_section,
16571 &sig_type->per_cu);
16576 dump_die_for_error (die);
16577 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
16578 dwarf_attr_name (attr->name), objfile->name);
16581 /* If not cached we need to read it in. */
16583 if (this_type == NULL)
16585 struct die_info *type_die;
16586 struct dwarf2_cu *type_cu = cu;
16588 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
16589 /* If we found the type now, it's probably because the type came
16590 from an inter-CU reference and the type's CU got expanded before
16592 this_type = get_die_type (type_die, type_cu);
16593 if (this_type == NULL)
16594 this_type = read_type_die_1 (type_die, type_cu);
16597 /* If we still don't have a type use an error marker. */
16599 if (this_type == NULL)
16601 char *message, *saved;
16603 /* read_type_die already issued a complaint. */
16604 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16606 cu->header.offset.sect_off,
16607 die->offset.sect_off);
16608 saved = obstack_copy0 (&objfile->objfile_obstack,
16609 message, strlen (message));
16612 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
16618 /* Return the type in DIE, CU.
16619 Returns NULL for invalid types.
16621 This first does a lookup in the appropriate type_hash table,
16622 and only reads the die in if necessary.
16624 NOTE: This can be called when reading in partial or full symbols. */
16626 static struct type *
16627 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
16629 struct type *this_type;
16631 this_type = get_die_type (die, cu);
16635 return read_type_die_1 (die, cu);
16638 /* Read the type in DIE, CU.
16639 Returns NULL for invalid types. */
16641 static struct type *
16642 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
16644 struct type *this_type = NULL;
16648 case DW_TAG_class_type:
16649 case DW_TAG_interface_type:
16650 case DW_TAG_structure_type:
16651 case DW_TAG_union_type:
16652 this_type = read_structure_type (die, cu);
16654 case DW_TAG_enumeration_type:
16655 this_type = read_enumeration_type (die, cu);
16657 case DW_TAG_subprogram:
16658 case DW_TAG_subroutine_type:
16659 case DW_TAG_inlined_subroutine:
16660 this_type = read_subroutine_type (die, cu);
16662 case DW_TAG_array_type:
16663 this_type = read_array_type (die, cu);
16665 case DW_TAG_set_type:
16666 this_type = read_set_type (die, cu);
16668 case DW_TAG_pointer_type:
16669 this_type = read_tag_pointer_type (die, cu);
16671 case DW_TAG_ptr_to_member_type:
16672 this_type = read_tag_ptr_to_member_type (die, cu);
16674 case DW_TAG_reference_type:
16675 this_type = read_tag_reference_type (die, cu);
16677 case DW_TAG_const_type:
16678 this_type = read_tag_const_type (die, cu);
16680 case DW_TAG_volatile_type:
16681 this_type = read_tag_volatile_type (die, cu);
16683 case DW_TAG_restrict_type:
16684 this_type = read_tag_restrict_type (die, cu);
16686 case DW_TAG_string_type:
16687 this_type = read_tag_string_type (die, cu);
16689 case DW_TAG_typedef:
16690 this_type = read_typedef (die, cu);
16692 case DW_TAG_subrange_type:
16693 this_type = read_subrange_type (die, cu);
16695 case DW_TAG_base_type:
16696 this_type = read_base_type (die, cu);
16698 case DW_TAG_unspecified_type:
16699 this_type = read_unspecified_type (die, cu);
16701 case DW_TAG_namespace:
16702 this_type = read_namespace_type (die, cu);
16704 case DW_TAG_module:
16705 this_type = read_module_type (die, cu);
16708 complaint (&symfile_complaints,
16709 _("unexpected tag in read_type_die: '%s'"),
16710 dwarf_tag_name (die->tag));
16717 /* See if we can figure out if the class lives in a namespace. We do
16718 this by looking for a member function; its demangled name will
16719 contain namespace info, if there is any.
16720 Return the computed name or NULL.
16721 Space for the result is allocated on the objfile's obstack.
16722 This is the full-die version of guess_partial_die_structure_name.
16723 In this case we know DIE has no useful parent. */
16726 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
16728 struct die_info *spec_die;
16729 struct dwarf2_cu *spec_cu;
16730 struct die_info *child;
16733 spec_die = die_specification (die, &spec_cu);
16734 if (spec_die != NULL)
16740 for (child = die->child;
16742 child = child->sibling)
16744 if (child->tag == DW_TAG_subprogram)
16746 struct attribute *attr;
16748 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
16750 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
16754 = language_class_name_from_physname (cu->language_defn,
16758 if (actual_name != NULL)
16760 const char *die_name = dwarf2_name (die, cu);
16762 if (die_name != NULL
16763 && strcmp (die_name, actual_name) != 0)
16765 /* Strip off the class name from the full name.
16766 We want the prefix. */
16767 int die_name_len = strlen (die_name);
16768 int actual_name_len = strlen (actual_name);
16770 /* Test for '::' as a sanity check. */
16771 if (actual_name_len > die_name_len + 2
16772 && actual_name[actual_name_len
16773 - die_name_len - 1] == ':')
16775 obstack_copy0 (&cu->objfile->objfile_obstack,
16777 actual_name_len - die_name_len - 2);
16780 xfree (actual_name);
16789 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16790 prefix part in such case. See
16791 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16794 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
16796 struct attribute *attr;
16799 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
16800 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
16803 attr = dwarf2_attr (die, DW_AT_name, cu);
16804 if (attr != NULL && DW_STRING (attr) != NULL)
16807 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
16809 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
16810 if (attr == NULL || DW_STRING (attr) == NULL)
16813 /* dwarf2_name had to be already called. */
16814 gdb_assert (DW_STRING_IS_CANONICAL (attr));
16816 /* Strip the base name, keep any leading namespaces/classes. */
16817 base = strrchr (DW_STRING (attr), ':');
16818 if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
16821 return obstack_copy0 (&cu->objfile->objfile_obstack,
16822 DW_STRING (attr), &base[-1] - DW_STRING (attr));
16825 /* Return the name of the namespace/class that DIE is defined within,
16826 or "" if we can't tell. The caller should not xfree the result.
16828 For example, if we're within the method foo() in the following
16838 then determine_prefix on foo's die will return "N::C". */
16840 static const char *
16841 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
16843 struct die_info *parent, *spec_die;
16844 struct dwarf2_cu *spec_cu;
16845 struct type *parent_type;
16848 if (cu->language != language_cplus && cu->language != language_java
16849 && cu->language != language_fortran)
16852 retval = anonymous_struct_prefix (die, cu);
16856 /* We have to be careful in the presence of DW_AT_specification.
16857 For example, with GCC 3.4, given the code
16861 // Definition of N::foo.
16865 then we'll have a tree of DIEs like this:
16867 1: DW_TAG_compile_unit
16868 2: DW_TAG_namespace // N
16869 3: DW_TAG_subprogram // declaration of N::foo
16870 4: DW_TAG_subprogram // definition of N::foo
16871 DW_AT_specification // refers to die #3
16873 Thus, when processing die #4, we have to pretend that we're in
16874 the context of its DW_AT_specification, namely the contex of die
16877 spec_die = die_specification (die, &spec_cu);
16878 if (spec_die == NULL)
16879 parent = die->parent;
16882 parent = spec_die->parent;
16886 if (parent == NULL)
16888 else if (parent->building_fullname)
16891 const char *parent_name;
16893 /* It has been seen on RealView 2.2 built binaries,
16894 DW_TAG_template_type_param types actually _defined_ as
16895 children of the parent class:
16898 template class <class Enum> Class{};
16899 Class<enum E> class_e;
16901 1: DW_TAG_class_type (Class)
16902 2: DW_TAG_enumeration_type (E)
16903 3: DW_TAG_enumerator (enum1:0)
16904 3: DW_TAG_enumerator (enum2:1)
16906 2: DW_TAG_template_type_param
16907 DW_AT_type DW_FORM_ref_udata (E)
16909 Besides being broken debug info, it can put GDB into an
16910 infinite loop. Consider:
16912 When we're building the full name for Class<E>, we'll start
16913 at Class, and go look over its template type parameters,
16914 finding E. We'll then try to build the full name of E, and
16915 reach here. We're now trying to build the full name of E,
16916 and look over the parent DIE for containing scope. In the
16917 broken case, if we followed the parent DIE of E, we'd again
16918 find Class, and once again go look at its template type
16919 arguments, etc., etc. Simply don't consider such parent die
16920 as source-level parent of this die (it can't be, the language
16921 doesn't allow it), and break the loop here. */
16922 name = dwarf2_name (die, cu);
16923 parent_name = dwarf2_name (parent, cu);
16924 complaint (&symfile_complaints,
16925 _("template param type '%s' defined within parent '%s'"),
16926 name ? name : "<unknown>",
16927 parent_name ? parent_name : "<unknown>");
16931 switch (parent->tag)
16933 case DW_TAG_namespace:
16934 parent_type = read_type_die (parent, cu);
16935 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
16936 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
16937 Work around this problem here. */
16938 if (cu->language == language_cplus
16939 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
16941 /* We give a name to even anonymous namespaces. */
16942 return TYPE_TAG_NAME (parent_type);
16943 case DW_TAG_class_type:
16944 case DW_TAG_interface_type:
16945 case DW_TAG_structure_type:
16946 case DW_TAG_union_type:
16947 case DW_TAG_module:
16948 parent_type = read_type_die (parent, cu);
16949 if (TYPE_TAG_NAME (parent_type) != NULL)
16950 return TYPE_TAG_NAME (parent_type);
16952 /* An anonymous structure is only allowed non-static data
16953 members; no typedefs, no member functions, et cetera.
16954 So it does not need a prefix. */
16956 case DW_TAG_compile_unit:
16957 case DW_TAG_partial_unit:
16958 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
16959 if (cu->language == language_cplus
16960 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
16961 && die->child != NULL
16962 && (die->tag == DW_TAG_class_type
16963 || die->tag == DW_TAG_structure_type
16964 || die->tag == DW_TAG_union_type))
16966 char *name = guess_full_die_structure_name (die, cu);
16972 return determine_prefix (parent, cu);
16976 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
16977 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
16978 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
16979 an obconcat, otherwise allocate storage for the result. The CU argument is
16980 used to determine the language and hence, the appropriate separator. */
16982 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
16985 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
16986 int physname, struct dwarf2_cu *cu)
16988 const char *lead = "";
16991 if (suffix == NULL || suffix[0] == '\0'
16992 || prefix == NULL || prefix[0] == '\0')
16994 else if (cu->language == language_java)
16996 else if (cu->language == language_fortran && physname)
16998 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
16999 DW_AT_MIPS_linkage_name is preferred and used instead. */
17007 if (prefix == NULL)
17009 if (suffix == NULL)
17015 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
17017 strcpy (retval, lead);
17018 strcat (retval, prefix);
17019 strcat (retval, sep);
17020 strcat (retval, suffix);
17025 /* We have an obstack. */
17026 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
17030 /* Return sibling of die, NULL if no sibling. */
17032 static struct die_info *
17033 sibling_die (struct die_info *die)
17035 return die->sibling;
17038 /* Get name of a die, return NULL if not found. */
17040 static const char *
17041 dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu,
17042 struct obstack *obstack)
17044 if (name && cu->language == language_cplus)
17046 char *canon_name = cp_canonicalize_string (name);
17048 if (canon_name != NULL)
17050 if (strcmp (canon_name, name) != 0)
17051 name = obstack_copy0 (obstack, canon_name, strlen (canon_name));
17052 xfree (canon_name);
17059 /* Get name of a die, return NULL if not found. */
17061 static const char *
17062 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
17064 struct attribute *attr;
17066 attr = dwarf2_attr (die, DW_AT_name, cu);
17067 if ((!attr || !DW_STRING (attr))
17068 && die->tag != DW_TAG_class_type
17069 && die->tag != DW_TAG_interface_type
17070 && die->tag != DW_TAG_structure_type
17071 && die->tag != DW_TAG_union_type)
17076 case DW_TAG_compile_unit:
17077 case DW_TAG_partial_unit:
17078 /* Compilation units have a DW_AT_name that is a filename, not
17079 a source language identifier. */
17080 case DW_TAG_enumeration_type:
17081 case DW_TAG_enumerator:
17082 /* These tags always have simple identifiers already; no need
17083 to canonicalize them. */
17084 return DW_STRING (attr);
17086 case DW_TAG_subprogram:
17087 /* Java constructors will all be named "<init>", so return
17088 the class name when we see this special case. */
17089 if (cu->language == language_java
17090 && DW_STRING (attr) != NULL
17091 && strcmp (DW_STRING (attr), "<init>") == 0)
17093 struct dwarf2_cu *spec_cu = cu;
17094 struct die_info *spec_die;
17096 /* GCJ will output '<init>' for Java constructor names.
17097 For this special case, return the name of the parent class. */
17099 /* GCJ may output suprogram DIEs with AT_specification set.
17100 If so, use the name of the specified DIE. */
17101 spec_die = die_specification (die, &spec_cu);
17102 if (spec_die != NULL)
17103 return dwarf2_name (spec_die, spec_cu);
17108 if (die->tag == DW_TAG_class_type)
17109 return dwarf2_name (die, cu);
17111 while (die->tag != DW_TAG_compile_unit
17112 && die->tag != DW_TAG_partial_unit);
17116 case DW_TAG_class_type:
17117 case DW_TAG_interface_type:
17118 case DW_TAG_structure_type:
17119 case DW_TAG_union_type:
17120 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
17121 structures or unions. These were of the form "._%d" in GCC 4.1,
17122 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
17123 and GCC 4.4. We work around this problem by ignoring these. */
17124 if (attr && DW_STRING (attr)
17125 && (strncmp (DW_STRING (attr), "._", 2) == 0
17126 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
17129 /* GCC might emit a nameless typedef that has a linkage name. See
17130 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
17131 if (!attr || DW_STRING (attr) == NULL)
17133 char *demangled = NULL;
17135 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
17137 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
17139 if (attr == NULL || DW_STRING (attr) == NULL)
17142 /* Avoid demangling DW_STRING (attr) the second time on a second
17143 call for the same DIE. */
17144 if (!DW_STRING_IS_CANONICAL (attr))
17145 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
17151 /* FIXME: we already did this for the partial symbol... */
17152 DW_STRING (attr) = obstack_copy0 (&cu->objfile->objfile_obstack,
17153 demangled, strlen (demangled));
17154 DW_STRING_IS_CANONICAL (attr) = 1;
17157 /* Strip any leading namespaces/classes, keep only the base name.
17158 DW_AT_name for named DIEs does not contain the prefixes. */
17159 base = strrchr (DW_STRING (attr), ':');
17160 if (base && base > DW_STRING (attr) && base[-1] == ':')
17163 return DW_STRING (attr);
17172 if (!DW_STRING_IS_CANONICAL (attr))
17175 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
17176 &cu->objfile->objfile_obstack);
17177 DW_STRING_IS_CANONICAL (attr) = 1;
17179 return DW_STRING (attr);
17182 /* Return the die that this die in an extension of, or NULL if there
17183 is none. *EXT_CU is the CU containing DIE on input, and the CU
17184 containing the return value on output. */
17186 static struct die_info *
17187 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
17189 struct attribute *attr;
17191 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
17195 return follow_die_ref (die, attr, ext_cu);
17198 /* Convert a DIE tag into its string name. */
17200 static const char *
17201 dwarf_tag_name (unsigned tag)
17203 const char *name = get_DW_TAG_name (tag);
17206 return "DW_TAG_<unknown>";
17211 /* Convert a DWARF attribute code into its string name. */
17213 static const char *
17214 dwarf_attr_name (unsigned attr)
17218 #ifdef MIPS /* collides with DW_AT_HP_block_index */
17219 if (attr == DW_AT_MIPS_fde)
17220 return "DW_AT_MIPS_fde";
17222 if (attr == DW_AT_HP_block_index)
17223 return "DW_AT_HP_block_index";
17226 name = get_DW_AT_name (attr);
17229 return "DW_AT_<unknown>";
17234 /* Convert a DWARF value form code into its string name. */
17236 static const char *
17237 dwarf_form_name (unsigned form)
17239 const char *name = get_DW_FORM_name (form);
17242 return "DW_FORM_<unknown>";
17248 dwarf_bool_name (unsigned mybool)
17256 /* Convert a DWARF type code into its string name. */
17258 static const char *
17259 dwarf_type_encoding_name (unsigned enc)
17261 const char *name = get_DW_ATE_name (enc);
17264 return "DW_ATE_<unknown>";
17270 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
17274 print_spaces (indent, f);
17275 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
17276 dwarf_tag_name (die->tag), die->abbrev, die->offset.sect_off);
17278 if (die->parent != NULL)
17280 print_spaces (indent, f);
17281 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
17282 die->parent->offset.sect_off);
17285 print_spaces (indent, f);
17286 fprintf_unfiltered (f, " has children: %s\n",
17287 dwarf_bool_name (die->child != NULL));
17289 print_spaces (indent, f);
17290 fprintf_unfiltered (f, " attributes:\n");
17292 for (i = 0; i < die->num_attrs; ++i)
17294 print_spaces (indent, f);
17295 fprintf_unfiltered (f, " %s (%s) ",
17296 dwarf_attr_name (die->attrs[i].name),
17297 dwarf_form_name (die->attrs[i].form));
17299 switch (die->attrs[i].form)
17302 case DW_FORM_GNU_addr_index:
17303 fprintf_unfiltered (f, "address: ");
17304 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
17306 case DW_FORM_block2:
17307 case DW_FORM_block4:
17308 case DW_FORM_block:
17309 case DW_FORM_block1:
17310 fprintf_unfiltered (f, "block: size %s",
17311 pulongest (DW_BLOCK (&die->attrs[i])->size));
17313 case DW_FORM_exprloc:
17314 fprintf_unfiltered (f, "expression: size %s",
17315 pulongest (DW_BLOCK (&die->attrs[i])->size));
17317 case DW_FORM_ref_addr:
17318 fprintf_unfiltered (f, "ref address: ");
17319 fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
17321 case DW_FORM_GNU_ref_alt:
17322 fprintf_unfiltered (f, "alt ref address: ");
17323 fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
17329 case DW_FORM_ref_udata:
17330 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
17331 (long) (DW_UNSND (&die->attrs[i])));
17333 case DW_FORM_data1:
17334 case DW_FORM_data2:
17335 case DW_FORM_data4:
17336 case DW_FORM_data8:
17337 case DW_FORM_udata:
17338 case DW_FORM_sdata:
17339 fprintf_unfiltered (f, "constant: %s",
17340 pulongest (DW_UNSND (&die->attrs[i])));
17342 case DW_FORM_sec_offset:
17343 fprintf_unfiltered (f, "section offset: %s",
17344 pulongest (DW_UNSND (&die->attrs[i])));
17346 case DW_FORM_ref_sig8:
17347 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
17349 struct signatured_type *sig_type =
17350 DW_SIGNATURED_TYPE (&die->attrs[i]);
17352 fprintf_unfiltered (f, "signatured type: 0x%s, offset 0x%x",
17353 hex_string (sig_type->signature),
17354 sig_type->per_cu.offset.sect_off);
17357 fprintf_unfiltered (f, "signatured type, unknown");
17359 case DW_FORM_string:
17361 case DW_FORM_GNU_str_index:
17362 case DW_FORM_GNU_strp_alt:
17363 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
17364 DW_STRING (&die->attrs[i])
17365 ? DW_STRING (&die->attrs[i]) : "",
17366 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
17369 if (DW_UNSND (&die->attrs[i]))
17370 fprintf_unfiltered (f, "flag: TRUE");
17372 fprintf_unfiltered (f, "flag: FALSE");
17374 case DW_FORM_flag_present:
17375 fprintf_unfiltered (f, "flag: TRUE");
17377 case DW_FORM_indirect:
17378 /* The reader will have reduced the indirect form to
17379 the "base form" so this form should not occur. */
17380 fprintf_unfiltered (f,
17381 "unexpected attribute form: DW_FORM_indirect");
17384 fprintf_unfiltered (f, "unsupported attribute form: %d.",
17385 die->attrs[i].form);
17388 fprintf_unfiltered (f, "\n");
17393 dump_die_for_error (struct die_info *die)
17395 dump_die_shallow (gdb_stderr, 0, die);
17399 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
17401 int indent = level * 4;
17403 gdb_assert (die != NULL);
17405 if (level >= max_level)
17408 dump_die_shallow (f, indent, die);
17410 if (die->child != NULL)
17412 print_spaces (indent, f);
17413 fprintf_unfiltered (f, " Children:");
17414 if (level + 1 < max_level)
17416 fprintf_unfiltered (f, "\n");
17417 dump_die_1 (f, level + 1, max_level, die->child);
17421 fprintf_unfiltered (f,
17422 " [not printed, max nesting level reached]\n");
17426 if (die->sibling != NULL && level > 0)
17428 dump_die_1 (f, level, max_level, die->sibling);
17432 /* This is called from the pdie macro in gdbinit.in.
17433 It's not static so gcc will keep a copy callable from gdb. */
17436 dump_die (struct die_info *die, int max_level)
17438 dump_die_1 (gdb_stdlog, 0, max_level, die);
17442 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
17446 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset.sect_off,
17452 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17453 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17456 is_ref_attr (struct attribute *attr)
17458 switch (attr->form)
17460 case DW_FORM_ref_addr:
17465 case DW_FORM_ref_udata:
17466 case DW_FORM_GNU_ref_alt:
17473 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17477 dwarf2_get_ref_die_offset (struct attribute *attr)
17479 sect_offset retval = { DW_UNSND (attr) };
17481 if (is_ref_attr (attr))
17484 retval.sect_off = 0;
17485 complaint (&symfile_complaints,
17486 _("unsupported die ref attribute form: '%s'"),
17487 dwarf_form_name (attr->form));
17491 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17492 * the value held by the attribute is not constant. */
17495 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
17497 if (attr->form == DW_FORM_sdata)
17498 return DW_SND (attr);
17499 else if (attr->form == DW_FORM_udata
17500 || attr->form == DW_FORM_data1
17501 || attr->form == DW_FORM_data2
17502 || attr->form == DW_FORM_data4
17503 || attr->form == DW_FORM_data8)
17504 return DW_UNSND (attr);
17507 complaint (&symfile_complaints,
17508 _("Attribute value is not a constant (%s)"),
17509 dwarf_form_name (attr->form));
17510 return default_value;
17514 /* Follow reference or signature attribute ATTR of SRC_DIE.
17515 On entry *REF_CU is the CU of SRC_DIE.
17516 On exit *REF_CU is the CU of the result. */
17518 static struct die_info *
17519 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
17520 struct dwarf2_cu **ref_cu)
17522 struct die_info *die;
17524 if (is_ref_attr (attr))
17525 die = follow_die_ref (src_die, attr, ref_cu);
17526 else if (attr->form == DW_FORM_ref_sig8)
17527 die = follow_die_sig (src_die, attr, ref_cu);
17530 dump_die_for_error (src_die);
17531 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17532 (*ref_cu)->objfile->name);
17538 /* Follow reference OFFSET.
17539 On entry *REF_CU is the CU of the source die referencing OFFSET.
17540 On exit *REF_CU is the CU of the result.
17541 Returns NULL if OFFSET is invalid. */
17543 static struct die_info *
17544 follow_die_offset (sect_offset offset, int offset_in_dwz,
17545 struct dwarf2_cu **ref_cu)
17547 struct die_info temp_die;
17548 struct dwarf2_cu *target_cu, *cu = *ref_cu;
17550 gdb_assert (cu->per_cu != NULL);
17554 if (cu->per_cu->is_debug_types)
17556 /* .debug_types CUs cannot reference anything outside their CU.
17557 If they need to, they have to reference a signatured type via
17558 DW_FORM_ref_sig8. */
17559 if (! offset_in_cu_p (&cu->header, offset))
17562 else if (offset_in_dwz != cu->per_cu->is_dwz
17563 || ! offset_in_cu_p (&cu->header, offset))
17565 struct dwarf2_per_cu_data *per_cu;
17567 per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
17570 /* If necessary, add it to the queue and load its DIEs. */
17571 if (maybe_queue_comp_unit (cu, per_cu, cu->language))
17572 load_full_comp_unit (per_cu, cu->language);
17574 target_cu = per_cu->cu;
17576 else if (cu->dies == NULL)
17578 /* We're loading full DIEs during partial symbol reading. */
17579 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
17580 load_full_comp_unit (cu->per_cu, language_minimal);
17583 *ref_cu = target_cu;
17584 temp_die.offset = offset;
17585 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset.sect_off);
17588 /* Follow reference attribute ATTR of SRC_DIE.
17589 On entry *REF_CU is the CU of SRC_DIE.
17590 On exit *REF_CU is the CU of the result. */
17592 static struct die_info *
17593 follow_die_ref (struct die_info *src_die, struct attribute *attr,
17594 struct dwarf2_cu **ref_cu)
17596 sect_offset offset = dwarf2_get_ref_die_offset (attr);
17597 struct dwarf2_cu *cu = *ref_cu;
17598 struct die_info *die;
17600 die = follow_die_offset (offset,
17601 (attr->form == DW_FORM_GNU_ref_alt
17602 || cu->per_cu->is_dwz),
17605 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17606 "at 0x%x [in module %s]"),
17607 offset.sect_off, src_die->offset.sect_off, cu->objfile->name);
17612 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17613 Returned value is intended for DW_OP_call*. Returned
17614 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17616 struct dwarf2_locexpr_baton
17617 dwarf2_fetch_die_loc_sect_off (sect_offset offset,
17618 struct dwarf2_per_cu_data *per_cu,
17619 CORE_ADDR (*get_frame_pc) (void *baton),
17622 struct dwarf2_cu *cu;
17623 struct die_info *die;
17624 struct attribute *attr;
17625 struct dwarf2_locexpr_baton retval;
17627 dw2_setup (per_cu->objfile);
17629 if (per_cu->cu == NULL)
17633 die = follow_die_offset (offset, per_cu->is_dwz, &cu);
17635 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17636 offset.sect_off, per_cu->objfile->name);
17638 attr = dwarf2_attr (die, DW_AT_location, cu);
17641 /* DWARF: "If there is no such attribute, then there is no effect.".
17642 DATA is ignored if SIZE is 0. */
17644 retval.data = NULL;
17647 else if (attr_form_is_section_offset (attr))
17649 struct dwarf2_loclist_baton loclist_baton;
17650 CORE_ADDR pc = (*get_frame_pc) (baton);
17653 fill_in_loclist_baton (cu, &loclist_baton, attr);
17655 retval.data = dwarf2_find_location_expression (&loclist_baton,
17657 retval.size = size;
17661 if (!attr_form_is_block (attr))
17662 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17663 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17664 offset.sect_off, per_cu->objfile->name);
17666 retval.data = DW_BLOCK (attr)->data;
17667 retval.size = DW_BLOCK (attr)->size;
17669 retval.per_cu = cu->per_cu;
17671 age_cached_comp_units ();
17676 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
17679 struct dwarf2_locexpr_baton
17680 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu,
17681 struct dwarf2_per_cu_data *per_cu,
17682 CORE_ADDR (*get_frame_pc) (void *baton),
17685 sect_offset offset = { per_cu->offset.sect_off + offset_in_cu.cu_off };
17687 return dwarf2_fetch_die_loc_sect_off (offset, per_cu, get_frame_pc, baton);
17690 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17694 dwarf2_get_die_type (cu_offset die_offset,
17695 struct dwarf2_per_cu_data *per_cu)
17697 sect_offset die_offset_sect;
17699 dw2_setup (per_cu->objfile);
17701 die_offset_sect.sect_off = per_cu->offset.sect_off + die_offset.cu_off;
17702 return get_die_type_at_offset (die_offset_sect, per_cu);
17705 /* Follow the signature attribute ATTR in SRC_DIE.
17706 On entry *REF_CU is the CU of SRC_DIE.
17707 On exit *REF_CU is the CU of the result. */
17709 static struct die_info *
17710 follow_die_sig (struct die_info *src_die, struct attribute *attr,
17711 struct dwarf2_cu **ref_cu)
17713 struct objfile *objfile = (*ref_cu)->objfile;
17714 struct die_info temp_die;
17715 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
17716 struct dwarf2_cu *sig_cu;
17717 struct die_info *die;
17719 /* sig_type will be NULL if the signatured type is missing from
17721 if (sig_type == NULL)
17722 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
17723 "at 0x%x [in module %s]"),
17724 src_die->offset.sect_off, objfile->name);
17726 /* If necessary, add it to the queue and load its DIEs. */
17728 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, language_minimal))
17729 read_signatured_type (sig_type);
17731 gdb_assert (sig_type->per_cu.cu != NULL);
17733 sig_cu = sig_type->per_cu.cu;
17734 gdb_assert (sig_type->type_offset_in_section.sect_off != 0);
17735 temp_die.offset = sig_type->type_offset_in_section;
17736 die = htab_find_with_hash (sig_cu->die_hash, &temp_die,
17737 temp_die.offset.sect_off);
17740 /* For .gdb_index version 7 keep track of included TUs.
17741 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
17742 if (dwarf2_per_objfile->index_table != NULL
17743 && dwarf2_per_objfile->index_table->version <= 7)
17745 VEC_safe_push (dwarf2_per_cu_ptr,
17746 (*ref_cu)->per_cu->imported_symtabs,
17754 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
17755 "from DIE at 0x%x [in module %s]"),
17756 temp_die.offset.sect_off, src_die->offset.sect_off, objfile->name);
17759 /* Load the DIEs associated with type unit PER_CU into memory. */
17762 load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
17764 struct signatured_type *sig_type;
17766 /* Caller is responsible for ensuring type_unit_groups don't get here. */
17767 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu));
17769 /* We have the per_cu, but we need the signatured_type.
17770 Fortunately this is an easy translation. */
17771 gdb_assert (per_cu->is_debug_types);
17772 sig_type = (struct signatured_type *) per_cu;
17774 gdb_assert (per_cu->cu == NULL);
17776 read_signatured_type (sig_type);
17778 gdb_assert (per_cu->cu != NULL);
17781 /* die_reader_func for read_signatured_type.
17782 This is identical to load_full_comp_unit_reader,
17783 but is kept separate for now. */
17786 read_signatured_type_reader (const struct die_reader_specs *reader,
17787 gdb_byte *info_ptr,
17788 struct die_info *comp_unit_die,
17792 struct dwarf2_cu *cu = reader->cu;
17794 gdb_assert (cu->die_hash == NULL);
17796 htab_create_alloc_ex (cu->header.length / 12,
17800 &cu->comp_unit_obstack,
17801 hashtab_obstack_allocate,
17802 dummy_obstack_deallocate);
17805 comp_unit_die->child = read_die_and_siblings (reader, info_ptr,
17806 &info_ptr, comp_unit_die);
17807 cu->dies = comp_unit_die;
17808 /* comp_unit_die is not stored in die_hash, no need. */
17810 /* We try not to read any attributes in this function, because not
17811 all CUs needed for references have been loaded yet, and symbol
17812 table processing isn't initialized. But we have to set the CU language,
17813 or we won't be able to build types correctly.
17814 Similarly, if we do not read the producer, we can not apply
17815 producer-specific interpretation. */
17816 prepare_one_comp_unit (cu, cu->dies, language_minimal);
17819 /* Read in a signatured type and build its CU and DIEs.
17820 If the type is a stub for the real type in a DWO file,
17821 read in the real type from the DWO file as well. */
17824 read_signatured_type (struct signatured_type *sig_type)
17826 struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu;
17828 gdb_assert (per_cu->is_debug_types);
17829 gdb_assert (per_cu->cu == NULL);
17831 init_cutu_and_read_dies (per_cu, NULL, 0, 1,
17832 read_signatured_type_reader, NULL);
17835 /* Decode simple location descriptions.
17836 Given a pointer to a dwarf block that defines a location, compute
17837 the location and return the value.
17839 NOTE drow/2003-11-18: This function is called in two situations
17840 now: for the address of static or global variables (partial symbols
17841 only) and for offsets into structures which are expected to be
17842 (more or less) constant. The partial symbol case should go away,
17843 and only the constant case should remain. That will let this
17844 function complain more accurately. A few special modes are allowed
17845 without complaint for global variables (for instance, global
17846 register values and thread-local values).
17848 A location description containing no operations indicates that the
17849 object is optimized out. The return value is 0 for that case.
17850 FIXME drow/2003-11-16: No callers check for this case any more; soon all
17851 callers will only want a very basic result and this can become a
17854 Note that stack[0] is unused except as a default error return. */
17857 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
17859 struct objfile *objfile = cu->objfile;
17861 size_t size = blk->size;
17862 gdb_byte *data = blk->data;
17863 CORE_ADDR stack[64];
17865 unsigned int bytes_read, unsnd;
17871 stack[++stacki] = 0;
17910 stack[++stacki] = op - DW_OP_lit0;
17945 stack[++stacki] = op - DW_OP_reg0;
17947 dwarf2_complex_location_expr_complaint ();
17951 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
17953 stack[++stacki] = unsnd;
17955 dwarf2_complex_location_expr_complaint ();
17959 stack[++stacki] = read_address (objfile->obfd, &data[i],
17964 case DW_OP_const1u:
17965 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
17969 case DW_OP_const1s:
17970 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
17974 case DW_OP_const2u:
17975 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
17979 case DW_OP_const2s:
17980 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
17984 case DW_OP_const4u:
17985 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
17989 case DW_OP_const4s:
17990 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
17994 case DW_OP_const8u:
17995 stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]);
18000 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
18006 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
18011 stack[stacki + 1] = stack[stacki];
18016 stack[stacki - 1] += stack[stacki];
18020 case DW_OP_plus_uconst:
18021 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
18027 stack[stacki - 1] -= stack[stacki];
18032 /* If we're not the last op, then we definitely can't encode
18033 this using GDB's address_class enum. This is valid for partial
18034 global symbols, although the variable's address will be bogus
18037 dwarf2_complex_location_expr_complaint ();
18040 case DW_OP_GNU_push_tls_address:
18041 /* The top of the stack has the offset from the beginning
18042 of the thread control block at which the variable is located. */
18043 /* Nothing should follow this operator, so the top of stack would
18045 /* This is valid for partial global symbols, but the variable's
18046 address will be bogus in the psymtab. Make it always at least
18047 non-zero to not look as a variable garbage collected by linker
18048 which have DW_OP_addr 0. */
18050 dwarf2_complex_location_expr_complaint ();
18054 case DW_OP_GNU_uninit:
18057 case DW_OP_GNU_addr_index:
18058 case DW_OP_GNU_const_index:
18059 stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i],
18066 const char *name = get_DW_OP_name (op);
18069 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
18072 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
18076 return (stack[stacki]);
18079 /* Enforce maximum stack depth of SIZE-1 to avoid writing
18080 outside of the allocated space. Also enforce minimum>0. */
18081 if (stacki >= ARRAY_SIZE (stack) - 1)
18083 complaint (&symfile_complaints,
18084 _("location description stack overflow"));
18090 complaint (&symfile_complaints,
18091 _("location description stack underflow"));
18095 return (stack[stacki]);
18098 /* memory allocation interface */
18100 static struct dwarf_block *
18101 dwarf_alloc_block (struct dwarf2_cu *cu)
18103 struct dwarf_block *blk;
18105 blk = (struct dwarf_block *)
18106 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
18110 static struct die_info *
18111 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
18113 struct die_info *die;
18114 size_t size = sizeof (struct die_info);
18117 size += (num_attrs - 1) * sizeof (struct attribute);
18119 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
18120 memset (die, 0, sizeof (struct die_info));
18125 /* Macro support. */
18127 /* Return file name relative to the compilation directory of file number I in
18128 *LH's file name table. The result is allocated using xmalloc; the caller is
18129 responsible for freeing it. */
18132 file_file_name (int file, struct line_header *lh)
18134 /* Is the file number a valid index into the line header's file name
18135 table? Remember that file numbers start with one, not zero. */
18136 if (1 <= file && file <= lh->num_file_names)
18138 struct file_entry *fe = &lh->file_names[file - 1];
18140 if (IS_ABSOLUTE_PATH (fe->name) || fe->dir_index == 0)
18141 return xstrdup (fe->name);
18142 return concat (lh->include_dirs[fe->dir_index - 1], SLASH_STRING,
18147 /* The compiler produced a bogus file number. We can at least
18148 record the macro definitions made in the file, even if we
18149 won't be able to find the file by name. */
18150 char fake_name[80];
18152 xsnprintf (fake_name, sizeof (fake_name),
18153 "<bad macro file number %d>", file);
18155 complaint (&symfile_complaints,
18156 _("bad file number in macro information (%d)"),
18159 return xstrdup (fake_name);
18163 /* Return the full name of file number I in *LH's file name table.
18164 Use COMP_DIR as the name of the current directory of the
18165 compilation. The result is allocated using xmalloc; the caller is
18166 responsible for freeing it. */
18168 file_full_name (int file, struct line_header *lh, const char *comp_dir)
18170 /* Is the file number a valid index into the line header's file name
18171 table? Remember that file numbers start with one, not zero. */
18172 if (1 <= file && file <= lh->num_file_names)
18174 char *relative = file_file_name (file, lh);
18176 if (IS_ABSOLUTE_PATH (relative) || comp_dir == NULL)
18178 return reconcat (relative, comp_dir, SLASH_STRING, relative, NULL);
18181 return file_file_name (file, lh);
18185 static struct macro_source_file *
18186 macro_start_file (int file, int line,
18187 struct macro_source_file *current_file,
18188 const char *comp_dir,
18189 struct line_header *lh, struct objfile *objfile)
18191 /* File name relative to the compilation directory of this source file. */
18192 char *file_name = file_file_name (file, lh);
18194 /* We don't create a macro table for this compilation unit
18195 at all until we actually get a filename. */
18196 if (! pending_macros)
18197 pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
18198 objfile->per_bfd->macro_cache,
18201 if (! current_file)
18203 /* If we have no current file, then this must be the start_file
18204 directive for the compilation unit's main source file. */
18205 current_file = macro_set_main (pending_macros, file_name);
18206 macro_define_special (pending_macros);
18209 current_file = macro_include (current_file, line, file_name);
18213 return current_file;
18217 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
18218 followed by a null byte. */
18220 copy_string (const char *buf, int len)
18222 char *s = xmalloc (len + 1);
18224 memcpy (s, buf, len);
18230 static const char *
18231 consume_improper_spaces (const char *p, const char *body)
18235 complaint (&symfile_complaints,
18236 _("macro definition contains spaces "
18237 "in formal argument list:\n`%s'"),
18249 parse_macro_definition (struct macro_source_file *file, int line,
18254 /* The body string takes one of two forms. For object-like macro
18255 definitions, it should be:
18257 <macro name> " " <definition>
18259 For function-like macro definitions, it should be:
18261 <macro name> "() " <definition>
18263 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
18265 Spaces may appear only where explicitly indicated, and in the
18268 The Dwarf 2 spec says that an object-like macro's name is always
18269 followed by a space, but versions of GCC around March 2002 omit
18270 the space when the macro's definition is the empty string.
18272 The Dwarf 2 spec says that there should be no spaces between the
18273 formal arguments in a function-like macro's formal argument list,
18274 but versions of GCC around March 2002 include spaces after the
18278 /* Find the extent of the macro name. The macro name is terminated
18279 by either a space or null character (for an object-like macro) or
18280 an opening paren (for a function-like macro). */
18281 for (p = body; *p; p++)
18282 if (*p == ' ' || *p == '(')
18285 if (*p == ' ' || *p == '\0')
18287 /* It's an object-like macro. */
18288 int name_len = p - body;
18289 char *name = copy_string (body, name_len);
18290 const char *replacement;
18293 replacement = body + name_len + 1;
18296 dwarf2_macro_malformed_definition_complaint (body);
18297 replacement = body + name_len;
18300 macro_define_object (file, line, name, replacement);
18304 else if (*p == '(')
18306 /* It's a function-like macro. */
18307 char *name = copy_string (body, p - body);
18310 char **argv = xmalloc (argv_size * sizeof (*argv));
18314 p = consume_improper_spaces (p, body);
18316 /* Parse the formal argument list. */
18317 while (*p && *p != ')')
18319 /* Find the extent of the current argument name. */
18320 const char *arg_start = p;
18322 while (*p && *p != ',' && *p != ')' && *p != ' ')
18325 if (! *p || p == arg_start)
18326 dwarf2_macro_malformed_definition_complaint (body);
18329 /* Make sure argv has room for the new argument. */
18330 if (argc >= argv_size)
18333 argv = xrealloc (argv, argv_size * sizeof (*argv));
18336 argv[argc++] = copy_string (arg_start, p - arg_start);
18339 p = consume_improper_spaces (p, body);
18341 /* Consume the comma, if present. */
18346 p = consume_improper_spaces (p, body);
18355 /* Perfectly formed definition, no complaints. */
18356 macro_define_function (file, line, name,
18357 argc, (const char **) argv,
18359 else if (*p == '\0')
18361 /* Complain, but do define it. */
18362 dwarf2_macro_malformed_definition_complaint (body);
18363 macro_define_function (file, line, name,
18364 argc, (const char **) argv,
18368 /* Just complain. */
18369 dwarf2_macro_malformed_definition_complaint (body);
18372 /* Just complain. */
18373 dwarf2_macro_malformed_definition_complaint (body);
18379 for (i = 0; i < argc; i++)
18385 dwarf2_macro_malformed_definition_complaint (body);
18388 /* Skip some bytes from BYTES according to the form given in FORM.
18389 Returns the new pointer. */
18392 skip_form_bytes (bfd *abfd, gdb_byte *bytes, gdb_byte *buffer_end,
18393 enum dwarf_form form,
18394 unsigned int offset_size,
18395 struct dwarf2_section_info *section)
18397 unsigned int bytes_read;
18401 case DW_FORM_data1:
18406 case DW_FORM_data2:
18410 case DW_FORM_data4:
18414 case DW_FORM_data8:
18418 case DW_FORM_string:
18419 read_direct_string (abfd, bytes, &bytes_read);
18420 bytes += bytes_read;
18423 case DW_FORM_sec_offset:
18425 case DW_FORM_GNU_strp_alt:
18426 bytes += offset_size;
18429 case DW_FORM_block:
18430 bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
18431 bytes += bytes_read;
18434 case DW_FORM_block1:
18435 bytes += 1 + read_1_byte (abfd, bytes);
18437 case DW_FORM_block2:
18438 bytes += 2 + read_2_bytes (abfd, bytes);
18440 case DW_FORM_block4:
18441 bytes += 4 + read_4_bytes (abfd, bytes);
18444 case DW_FORM_sdata:
18445 case DW_FORM_udata:
18446 case DW_FORM_GNU_addr_index:
18447 case DW_FORM_GNU_str_index:
18448 bytes = (gdb_byte *) gdb_skip_leb128 (bytes, buffer_end);
18451 dwarf2_section_buffer_overflow_complaint (section);
18459 complaint (&symfile_complaints,
18460 _("invalid form 0x%x in `%s'"),
18462 section->asection->name);
18470 /* A helper for dwarf_decode_macros that handles skipping an unknown
18471 opcode. Returns an updated pointer to the macro data buffer; or,
18472 on error, issues a complaint and returns NULL. */
18475 skip_unknown_opcode (unsigned int opcode,
18476 gdb_byte **opcode_definitions,
18477 gdb_byte *mac_ptr, gdb_byte *mac_end,
18479 unsigned int offset_size,
18480 struct dwarf2_section_info *section)
18482 unsigned int bytes_read, i;
18486 if (opcode_definitions[opcode] == NULL)
18488 complaint (&symfile_complaints,
18489 _("unrecognized DW_MACFINO opcode 0x%x"),
18494 defn = opcode_definitions[opcode];
18495 arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
18496 defn += bytes_read;
18498 for (i = 0; i < arg; ++i)
18500 mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, defn[i], offset_size,
18502 if (mac_ptr == NULL)
18504 /* skip_form_bytes already issued the complaint. */
18512 /* A helper function which parses the header of a macro section.
18513 If the macro section is the extended (for now called "GNU") type,
18514 then this updates *OFFSET_SIZE. Returns a pointer to just after
18515 the header, or issues a complaint and returns NULL on error. */
18518 dwarf_parse_macro_header (gdb_byte **opcode_definitions,
18521 unsigned int *offset_size,
18522 int section_is_gnu)
18524 memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
18526 if (section_is_gnu)
18528 unsigned int version, flags;
18530 version = read_2_bytes (abfd, mac_ptr);
18533 complaint (&symfile_complaints,
18534 _("unrecognized version `%d' in .debug_macro section"),
18540 flags = read_1_byte (abfd, mac_ptr);
18542 *offset_size = (flags & 1) ? 8 : 4;
18544 if ((flags & 2) != 0)
18545 /* We don't need the line table offset. */
18546 mac_ptr += *offset_size;
18548 /* Vendor opcode descriptions. */
18549 if ((flags & 4) != 0)
18551 unsigned int i, count;
18553 count = read_1_byte (abfd, mac_ptr);
18555 for (i = 0; i < count; ++i)
18557 unsigned int opcode, bytes_read;
18560 opcode = read_1_byte (abfd, mac_ptr);
18562 opcode_definitions[opcode] = mac_ptr;
18563 arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18564 mac_ptr += bytes_read;
18573 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18574 including DW_MACRO_GNU_transparent_include. */
18577 dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
18578 struct macro_source_file *current_file,
18579 struct line_header *lh, const char *comp_dir,
18580 struct dwarf2_section_info *section,
18581 int section_is_gnu, int section_is_dwz,
18582 unsigned int offset_size,
18583 struct objfile *objfile,
18584 htab_t include_hash)
18586 enum dwarf_macro_record_type macinfo_type;
18587 int at_commandline;
18588 gdb_byte *opcode_definitions[256];
18590 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
18591 &offset_size, section_is_gnu);
18592 if (mac_ptr == NULL)
18594 /* We already issued a complaint. */
18598 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18599 GDB is still reading the definitions from command line. First
18600 DW_MACINFO_start_file will need to be ignored as it was already executed
18601 to create CURRENT_FILE for the main source holding also the command line
18602 definitions. On first met DW_MACINFO_start_file this flag is reset to
18603 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18605 at_commandline = 1;
18609 /* Do we at least have room for a macinfo type byte? */
18610 if (mac_ptr >= mac_end)
18612 dwarf2_section_buffer_overflow_complaint (section);
18616 macinfo_type = read_1_byte (abfd, mac_ptr);
18619 /* Note that we rely on the fact that the corresponding GNU and
18620 DWARF constants are the same. */
18621 switch (macinfo_type)
18623 /* A zero macinfo type indicates the end of the macro
18628 case DW_MACRO_GNU_define:
18629 case DW_MACRO_GNU_undef:
18630 case DW_MACRO_GNU_define_indirect:
18631 case DW_MACRO_GNU_undef_indirect:
18632 case DW_MACRO_GNU_define_indirect_alt:
18633 case DW_MACRO_GNU_undef_indirect_alt:
18635 unsigned int bytes_read;
18640 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18641 mac_ptr += bytes_read;
18643 if (macinfo_type == DW_MACRO_GNU_define
18644 || macinfo_type == DW_MACRO_GNU_undef)
18646 body = read_direct_string (abfd, mac_ptr, &bytes_read);
18647 mac_ptr += bytes_read;
18651 LONGEST str_offset;
18653 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
18654 mac_ptr += offset_size;
18656 if (macinfo_type == DW_MACRO_GNU_define_indirect_alt
18657 || macinfo_type == DW_MACRO_GNU_undef_indirect_alt
18660 struct dwz_file *dwz = dwarf2_get_dwz_file ();
18662 body = read_indirect_string_from_dwz (dwz, str_offset);
18665 body = read_indirect_string_at_offset (abfd, str_offset);
18668 is_define = (macinfo_type == DW_MACRO_GNU_define
18669 || macinfo_type == DW_MACRO_GNU_define_indirect
18670 || macinfo_type == DW_MACRO_GNU_define_indirect_alt);
18671 if (! current_file)
18673 /* DWARF violation as no main source is present. */
18674 complaint (&symfile_complaints,
18675 _("debug info with no main source gives macro %s "
18677 is_define ? _("definition") : _("undefinition"),
18681 if ((line == 0 && !at_commandline)
18682 || (line != 0 && at_commandline))
18683 complaint (&symfile_complaints,
18684 _("debug info gives %s macro %s with %s line %d: %s"),
18685 at_commandline ? _("command-line") : _("in-file"),
18686 is_define ? _("definition") : _("undefinition"),
18687 line == 0 ? _("zero") : _("non-zero"), line, body);
18690 parse_macro_definition (current_file, line, body);
18693 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
18694 || macinfo_type == DW_MACRO_GNU_undef_indirect
18695 || macinfo_type == DW_MACRO_GNU_undef_indirect_alt);
18696 macro_undef (current_file, line, body);
18701 case DW_MACRO_GNU_start_file:
18703 unsigned int bytes_read;
18706 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18707 mac_ptr += bytes_read;
18708 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18709 mac_ptr += bytes_read;
18711 if ((line == 0 && !at_commandline)
18712 || (line != 0 && at_commandline))
18713 complaint (&symfile_complaints,
18714 _("debug info gives source %d included "
18715 "from %s at %s line %d"),
18716 file, at_commandline ? _("command-line") : _("file"),
18717 line == 0 ? _("zero") : _("non-zero"), line);
18719 if (at_commandline)
18721 /* This DW_MACRO_GNU_start_file was executed in the
18723 at_commandline = 0;
18726 current_file = macro_start_file (file, line,
18727 current_file, comp_dir,
18732 case DW_MACRO_GNU_end_file:
18733 if (! current_file)
18734 complaint (&symfile_complaints,
18735 _("macro debug info has an unmatched "
18736 "`close_file' directive"));
18739 current_file = current_file->included_by;
18740 if (! current_file)
18742 enum dwarf_macro_record_type next_type;
18744 /* GCC circa March 2002 doesn't produce the zero
18745 type byte marking the end of the compilation
18746 unit. Complain if it's not there, but exit no
18749 /* Do we at least have room for a macinfo type byte? */
18750 if (mac_ptr >= mac_end)
18752 dwarf2_section_buffer_overflow_complaint (section);
18756 /* We don't increment mac_ptr here, so this is just
18758 next_type = read_1_byte (abfd, mac_ptr);
18759 if (next_type != 0)
18760 complaint (&symfile_complaints,
18761 _("no terminating 0-type entry for "
18762 "macros in `.debug_macinfo' section"));
18769 case DW_MACRO_GNU_transparent_include:
18770 case DW_MACRO_GNU_transparent_include_alt:
18774 bfd *include_bfd = abfd;
18775 struct dwarf2_section_info *include_section = section;
18776 struct dwarf2_section_info alt_section;
18777 gdb_byte *include_mac_end = mac_end;
18778 int is_dwz = section_is_dwz;
18779 gdb_byte *new_mac_ptr;
18781 offset = read_offset_1 (abfd, mac_ptr, offset_size);
18782 mac_ptr += offset_size;
18784 if (macinfo_type == DW_MACRO_GNU_transparent_include_alt)
18786 struct dwz_file *dwz = dwarf2_get_dwz_file ();
18788 dwarf2_read_section (dwarf2_per_objfile->objfile,
18791 include_bfd = dwz->macro.asection->owner;
18792 include_section = &dwz->macro;
18793 include_mac_end = dwz->macro.buffer + dwz->macro.size;
18797 new_mac_ptr = include_section->buffer + offset;
18798 slot = htab_find_slot (include_hash, new_mac_ptr, INSERT);
18802 /* This has actually happened; see
18803 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
18804 complaint (&symfile_complaints,
18805 _("recursive DW_MACRO_GNU_transparent_include in "
18806 ".debug_macro section"));
18810 *slot = new_mac_ptr;
18812 dwarf_decode_macro_bytes (include_bfd, new_mac_ptr,
18813 include_mac_end, current_file,
18815 section, section_is_gnu, is_dwz,
18816 offset_size, objfile, include_hash);
18818 htab_remove_elt (include_hash, new_mac_ptr);
18823 case DW_MACINFO_vendor_ext:
18824 if (!section_is_gnu)
18826 unsigned int bytes_read;
18829 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18830 mac_ptr += bytes_read;
18831 read_direct_string (abfd, mac_ptr, &bytes_read);
18832 mac_ptr += bytes_read;
18834 /* We don't recognize any vendor extensions. */
18840 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
18841 mac_ptr, mac_end, abfd, offset_size,
18843 if (mac_ptr == NULL)
18847 } while (macinfo_type != 0);
18851 dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
18852 const char *comp_dir, int section_is_gnu)
18854 struct objfile *objfile = dwarf2_per_objfile->objfile;
18855 struct line_header *lh = cu->line_header;
18857 gdb_byte *mac_ptr, *mac_end;
18858 struct macro_source_file *current_file = 0;
18859 enum dwarf_macro_record_type macinfo_type;
18860 unsigned int offset_size = cu->header.offset_size;
18861 gdb_byte *opcode_definitions[256];
18862 struct cleanup *cleanup;
18863 htab_t include_hash;
18865 struct dwarf2_section_info *section;
18866 const char *section_name;
18868 if (cu->dwo_unit != NULL)
18870 if (section_is_gnu)
18872 section = &cu->dwo_unit->dwo_file->sections.macro;
18873 section_name = ".debug_macro.dwo";
18877 section = &cu->dwo_unit->dwo_file->sections.macinfo;
18878 section_name = ".debug_macinfo.dwo";
18883 if (section_is_gnu)
18885 section = &dwarf2_per_objfile->macro;
18886 section_name = ".debug_macro";
18890 section = &dwarf2_per_objfile->macinfo;
18891 section_name = ".debug_macinfo";
18895 dwarf2_read_section (objfile, section);
18896 if (section->buffer == NULL)
18898 complaint (&symfile_complaints, _("missing %s section"), section_name);
18901 abfd = section->asection->owner;
18903 /* First pass: Find the name of the base filename.
18904 This filename is needed in order to process all macros whose definition
18905 (or undefinition) comes from the command line. These macros are defined
18906 before the first DW_MACINFO_start_file entry, and yet still need to be
18907 associated to the base file.
18909 To determine the base file name, we scan the macro definitions until we
18910 reach the first DW_MACINFO_start_file entry. We then initialize
18911 CURRENT_FILE accordingly so that any macro definition found before the
18912 first DW_MACINFO_start_file can still be associated to the base file. */
18914 mac_ptr = section->buffer + offset;
18915 mac_end = section->buffer + section->size;
18917 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
18918 &offset_size, section_is_gnu);
18919 if (mac_ptr == NULL)
18921 /* We already issued a complaint. */
18927 /* Do we at least have room for a macinfo type byte? */
18928 if (mac_ptr >= mac_end)
18930 /* Complaint is printed during the second pass as GDB will probably
18931 stop the first pass earlier upon finding
18932 DW_MACINFO_start_file. */
18936 macinfo_type = read_1_byte (abfd, mac_ptr);
18939 /* Note that we rely on the fact that the corresponding GNU and
18940 DWARF constants are the same. */
18941 switch (macinfo_type)
18943 /* A zero macinfo type indicates the end of the macro
18948 case DW_MACRO_GNU_define:
18949 case DW_MACRO_GNU_undef:
18950 /* Only skip the data by MAC_PTR. */
18952 unsigned int bytes_read;
18954 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18955 mac_ptr += bytes_read;
18956 read_direct_string (abfd, mac_ptr, &bytes_read);
18957 mac_ptr += bytes_read;
18961 case DW_MACRO_GNU_start_file:
18963 unsigned int bytes_read;
18966 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18967 mac_ptr += bytes_read;
18968 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18969 mac_ptr += bytes_read;
18971 current_file = macro_start_file (file, line, current_file,
18972 comp_dir, lh, objfile);
18976 case DW_MACRO_GNU_end_file:
18977 /* No data to skip by MAC_PTR. */
18980 case DW_MACRO_GNU_define_indirect:
18981 case DW_MACRO_GNU_undef_indirect:
18982 case DW_MACRO_GNU_define_indirect_alt:
18983 case DW_MACRO_GNU_undef_indirect_alt:
18985 unsigned int bytes_read;
18987 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18988 mac_ptr += bytes_read;
18989 mac_ptr += offset_size;
18993 case DW_MACRO_GNU_transparent_include:
18994 case DW_MACRO_GNU_transparent_include_alt:
18995 /* Note that, according to the spec, a transparent include
18996 chain cannot call DW_MACRO_GNU_start_file. So, we can just
18997 skip this opcode. */
18998 mac_ptr += offset_size;
19001 case DW_MACINFO_vendor_ext:
19002 /* Only skip the data by MAC_PTR. */
19003 if (!section_is_gnu)
19005 unsigned int bytes_read;
19007 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19008 mac_ptr += bytes_read;
19009 read_direct_string (abfd, mac_ptr, &bytes_read);
19010 mac_ptr += bytes_read;
19015 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
19016 mac_ptr, mac_end, abfd, offset_size,
19018 if (mac_ptr == NULL)
19022 } while (macinfo_type != 0 && current_file == NULL);
19024 /* Second pass: Process all entries.
19026 Use the AT_COMMAND_LINE flag to determine whether we are still processing
19027 command-line macro definitions/undefinitions. This flag is unset when we
19028 reach the first DW_MACINFO_start_file entry. */
19030 include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
19031 NULL, xcalloc, xfree);
19032 cleanup = make_cleanup_htab_delete (include_hash);
19033 mac_ptr = section->buffer + offset;
19034 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
19036 dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
19037 current_file, lh, comp_dir, section,
19039 offset_size, objfile, include_hash);
19040 do_cleanups (cleanup);
19043 /* Check if the attribute's form is a DW_FORM_block*
19044 if so return true else false. */
19047 attr_form_is_block (struct attribute *attr)
19049 return (attr == NULL ? 0 :
19050 attr->form == DW_FORM_block1
19051 || attr->form == DW_FORM_block2
19052 || attr->form == DW_FORM_block4
19053 || attr->form == DW_FORM_block
19054 || attr->form == DW_FORM_exprloc);
19057 /* Return non-zero if ATTR's value is a section offset --- classes
19058 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
19059 You may use DW_UNSND (attr) to retrieve such offsets.
19061 Section 7.5.4, "Attribute Encodings", explains that no attribute
19062 may have a value that belongs to more than one of these classes; it
19063 would be ambiguous if we did, because we use the same forms for all
19067 attr_form_is_section_offset (struct attribute *attr)
19069 return (attr->form == DW_FORM_data4
19070 || attr->form == DW_FORM_data8
19071 || attr->form == DW_FORM_sec_offset);
19074 /* Return non-zero if ATTR's value falls in the 'constant' class, or
19075 zero otherwise. When this function returns true, you can apply
19076 dwarf2_get_attr_constant_value to it.
19078 However, note that for some attributes you must check
19079 attr_form_is_section_offset before using this test. DW_FORM_data4
19080 and DW_FORM_data8 are members of both the constant class, and of
19081 the classes that contain offsets into other debug sections
19082 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
19083 that, if an attribute's can be either a constant or one of the
19084 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
19085 taken as section offsets, not constants. */
19088 attr_form_is_constant (struct attribute *attr)
19090 switch (attr->form)
19092 case DW_FORM_sdata:
19093 case DW_FORM_udata:
19094 case DW_FORM_data1:
19095 case DW_FORM_data2:
19096 case DW_FORM_data4:
19097 case DW_FORM_data8:
19104 /* Return the .debug_loc section to use for CU.
19105 For DWO files use .debug_loc.dwo. */
19107 static struct dwarf2_section_info *
19108 cu_debug_loc_section (struct dwarf2_cu *cu)
19111 return &cu->dwo_unit->dwo_file->sections.loc;
19112 return &dwarf2_per_objfile->loc;
19115 /* A helper function that fills in a dwarf2_loclist_baton. */
19118 fill_in_loclist_baton (struct dwarf2_cu *cu,
19119 struct dwarf2_loclist_baton *baton,
19120 struct attribute *attr)
19122 struct dwarf2_section_info *section = cu_debug_loc_section (cu);
19124 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
19126 baton->per_cu = cu->per_cu;
19127 gdb_assert (baton->per_cu);
19128 /* We don't know how long the location list is, but make sure we
19129 don't run off the edge of the section. */
19130 baton->size = section->size - DW_UNSND (attr);
19131 baton->data = section->buffer + DW_UNSND (attr);
19132 baton->base_address = cu->base_address;
19133 baton->from_dwo = cu->dwo_unit != NULL;
19137 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
19138 struct dwarf2_cu *cu, int is_block)
19140 struct objfile *objfile = dwarf2_per_objfile->objfile;
19141 struct dwarf2_section_info *section = cu_debug_loc_section (cu);
19143 if (attr_form_is_section_offset (attr)
19144 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
19145 the section. If so, fall through to the complaint in the
19147 && DW_UNSND (attr) < dwarf2_section_size (objfile, section))
19149 struct dwarf2_loclist_baton *baton;
19151 baton = obstack_alloc (&objfile->objfile_obstack,
19152 sizeof (struct dwarf2_loclist_baton));
19154 fill_in_loclist_baton (cu, baton, attr);
19156 if (cu->base_known == 0)
19157 complaint (&symfile_complaints,
19158 _("Location list used without "
19159 "specifying the CU base address."));
19161 SYMBOL_ACLASS_INDEX (sym) = (is_block
19162 ? dwarf2_loclist_block_index
19163 : dwarf2_loclist_index);
19164 SYMBOL_LOCATION_BATON (sym) = baton;
19168 struct dwarf2_locexpr_baton *baton;
19170 baton = obstack_alloc (&objfile->objfile_obstack,
19171 sizeof (struct dwarf2_locexpr_baton));
19172 baton->per_cu = cu->per_cu;
19173 gdb_assert (baton->per_cu);
19175 if (attr_form_is_block (attr))
19177 /* Note that we're just copying the block's data pointer
19178 here, not the actual data. We're still pointing into the
19179 info_buffer for SYM's objfile; right now we never release
19180 that buffer, but when we do clean up properly this may
19182 baton->size = DW_BLOCK (attr)->size;
19183 baton->data = DW_BLOCK (attr)->data;
19187 dwarf2_invalid_attrib_class_complaint ("location description",
19188 SYMBOL_NATURAL_NAME (sym));
19192 SYMBOL_ACLASS_INDEX (sym) = (is_block
19193 ? dwarf2_locexpr_block_index
19194 : dwarf2_locexpr_index);
19195 SYMBOL_LOCATION_BATON (sym) = baton;
19199 /* Return the OBJFILE associated with the compilation unit CU. If CU
19200 came from a separate debuginfo file, then the master objfile is
19204 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
19206 struct objfile *objfile = per_cu->objfile;
19208 /* Return the master objfile, so that we can report and look up the
19209 correct file containing this variable. */
19210 if (objfile->separate_debug_objfile_backlink)
19211 objfile = objfile->separate_debug_objfile_backlink;
19216 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
19217 (CU_HEADERP is unused in such case) or prepare a temporary copy at
19218 CU_HEADERP first. */
19220 static const struct comp_unit_head *
19221 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
19222 struct dwarf2_per_cu_data *per_cu)
19224 gdb_byte *info_ptr;
19227 return &per_cu->cu->header;
19229 info_ptr = per_cu->section->buffer + per_cu->offset.sect_off;
19231 memset (cu_headerp, 0, sizeof (*cu_headerp));
19232 read_comp_unit_head (cu_headerp, info_ptr, per_cu->objfile->obfd);
19237 /* Return the address size given in the compilation unit header for CU. */
19240 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
19242 struct comp_unit_head cu_header_local;
19243 const struct comp_unit_head *cu_headerp;
19245 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
19247 return cu_headerp->addr_size;
19250 /* Return the offset size given in the compilation unit header for CU. */
19253 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
19255 struct comp_unit_head cu_header_local;
19256 const struct comp_unit_head *cu_headerp;
19258 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
19260 return cu_headerp->offset_size;
19263 /* See its dwarf2loc.h declaration. */
19266 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
19268 struct comp_unit_head cu_header_local;
19269 const struct comp_unit_head *cu_headerp;
19271 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
19273 if (cu_headerp->version == 2)
19274 return cu_headerp->addr_size;
19276 return cu_headerp->offset_size;
19279 /* Return the text offset of the CU. The returned offset comes from
19280 this CU's objfile. If this objfile came from a separate debuginfo
19281 file, then the offset may be different from the corresponding
19282 offset in the parent objfile. */
19285 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
19287 struct objfile *objfile = per_cu->objfile;
19289 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
19292 /* Locate the .debug_info compilation unit from CU's objfile which contains
19293 the DIE at OFFSET. Raises an error on failure. */
19295 static struct dwarf2_per_cu_data *
19296 dwarf2_find_containing_comp_unit (sect_offset offset,
19297 unsigned int offset_in_dwz,
19298 struct objfile *objfile)
19300 struct dwarf2_per_cu_data *this_cu;
19302 const sect_offset *cu_off;
19305 high = dwarf2_per_objfile->n_comp_units - 1;
19308 struct dwarf2_per_cu_data *mid_cu;
19309 int mid = low + (high - low) / 2;
19311 mid_cu = dwarf2_per_objfile->all_comp_units[mid];
19312 cu_off = &mid_cu->offset;
19313 if (mid_cu->is_dwz > offset_in_dwz
19314 || (mid_cu->is_dwz == offset_in_dwz
19315 && cu_off->sect_off >= offset.sect_off))
19320 gdb_assert (low == high);
19321 this_cu = dwarf2_per_objfile->all_comp_units[low];
19322 cu_off = &this_cu->offset;
19323 if (this_cu->is_dwz != offset_in_dwz || cu_off->sect_off > offset.sect_off)
19325 if (low == 0 || this_cu->is_dwz != offset_in_dwz)
19326 error (_("Dwarf Error: could not find partial DIE containing "
19327 "offset 0x%lx [in module %s]"),
19328 (long) offset.sect_off, bfd_get_filename (objfile->obfd));
19330 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset.sect_off
19331 <= offset.sect_off);
19332 return dwarf2_per_objfile->all_comp_units[low-1];
19336 this_cu = dwarf2_per_objfile->all_comp_units[low];
19337 if (low == dwarf2_per_objfile->n_comp_units - 1
19338 && offset.sect_off >= this_cu->offset.sect_off + this_cu->length)
19339 error (_("invalid dwarf2 offset %u"), offset.sect_off);
19340 gdb_assert (offset.sect_off < this_cu->offset.sect_off + this_cu->length);
19345 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19348 init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu)
19350 memset (cu, 0, sizeof (*cu));
19352 cu->per_cu = per_cu;
19353 cu->objfile = per_cu->objfile;
19354 obstack_init (&cu->comp_unit_obstack);
19357 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19360 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
19361 enum language pretend_language)
19363 struct attribute *attr;
19365 /* Set the language we're debugging. */
19366 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
19368 set_cu_language (DW_UNSND (attr), cu);
19371 cu->language = pretend_language;
19372 cu->language_defn = language_def (cu->language);
19375 attr = dwarf2_attr (comp_unit_die, DW_AT_producer, cu);
19377 cu->producer = DW_STRING (attr);
19380 /* Release one cached compilation unit, CU. We unlink it from the tree
19381 of compilation units, but we don't remove it from the read_in_chain;
19382 the caller is responsible for that.
19383 NOTE: DATA is a void * because this function is also used as a
19384 cleanup routine. */
19387 free_heap_comp_unit (void *data)
19389 struct dwarf2_cu *cu = data;
19391 gdb_assert (cu->per_cu != NULL);
19392 cu->per_cu->cu = NULL;
19395 obstack_free (&cu->comp_unit_obstack, NULL);
19400 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19401 when we're finished with it. We can't free the pointer itself, but be
19402 sure to unlink it from the cache. Also release any associated storage. */
19405 free_stack_comp_unit (void *data)
19407 struct dwarf2_cu *cu = data;
19409 gdb_assert (cu->per_cu != NULL);
19410 cu->per_cu->cu = NULL;
19413 obstack_free (&cu->comp_unit_obstack, NULL);
19414 cu->partial_dies = NULL;
19417 /* Free all cached compilation units. */
19420 free_cached_comp_units (void *data)
19422 struct dwarf2_per_cu_data *per_cu, **last_chain;
19424 per_cu = dwarf2_per_objfile->read_in_chain;
19425 last_chain = &dwarf2_per_objfile->read_in_chain;
19426 while (per_cu != NULL)
19428 struct dwarf2_per_cu_data *next_cu;
19430 next_cu = per_cu->cu->read_in_chain;
19432 free_heap_comp_unit (per_cu->cu);
19433 *last_chain = next_cu;
19439 /* Increase the age counter on each cached compilation unit, and free
19440 any that are too old. */
19443 age_cached_comp_units (void)
19445 struct dwarf2_per_cu_data *per_cu, **last_chain;
19447 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
19448 per_cu = dwarf2_per_objfile->read_in_chain;
19449 while (per_cu != NULL)
19451 per_cu->cu->last_used ++;
19452 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
19453 dwarf2_mark (per_cu->cu);
19454 per_cu = per_cu->cu->read_in_chain;
19457 per_cu = dwarf2_per_objfile->read_in_chain;
19458 last_chain = &dwarf2_per_objfile->read_in_chain;
19459 while (per_cu != NULL)
19461 struct dwarf2_per_cu_data *next_cu;
19463 next_cu = per_cu->cu->read_in_chain;
19465 if (!per_cu->cu->mark)
19467 free_heap_comp_unit (per_cu->cu);
19468 *last_chain = next_cu;
19471 last_chain = &per_cu->cu->read_in_chain;
19477 /* Remove a single compilation unit from the cache. */
19480 free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu)
19482 struct dwarf2_per_cu_data *per_cu, **last_chain;
19484 per_cu = dwarf2_per_objfile->read_in_chain;
19485 last_chain = &dwarf2_per_objfile->read_in_chain;
19486 while (per_cu != NULL)
19488 struct dwarf2_per_cu_data *next_cu;
19490 next_cu = per_cu->cu->read_in_chain;
19492 if (per_cu == target_per_cu)
19494 free_heap_comp_unit (per_cu->cu);
19496 *last_chain = next_cu;
19500 last_chain = &per_cu->cu->read_in_chain;
19506 /* Release all extra memory associated with OBJFILE. */
19509 dwarf2_free_objfile (struct objfile *objfile)
19511 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
19513 if (dwarf2_per_objfile == NULL)
19516 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19517 free_cached_comp_units (NULL);
19519 if (dwarf2_per_objfile->quick_file_names_table)
19520 htab_delete (dwarf2_per_objfile->quick_file_names_table);
19522 /* Everything else should be on the objfile obstack. */
19525 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19526 We store these in a hash table separate from the DIEs, and preserve them
19527 when the DIEs are flushed out of cache.
19529 The CU "per_cu" pointer is needed because offset alone is not enough to
19530 uniquely identify the type. A file may have multiple .debug_types sections,
19531 or the type may come from a DWO file. Furthermore, while it's more logical
19532 to use per_cu->section+offset, with Fission the section with the data is in
19533 the DWO file but we don't know that section at the point we need it.
19534 We have to use something in dwarf2_per_cu_data (or the pointer to it)
19535 because we can enter the lookup routine, get_die_type_at_offset, from
19536 outside this file, and thus won't necessarily have PER_CU->cu.
19537 Fortunately, PER_CU is stable for the life of the objfile. */
19539 struct dwarf2_per_cu_offset_and_type
19541 const struct dwarf2_per_cu_data *per_cu;
19542 sect_offset offset;
19546 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19549 per_cu_offset_and_type_hash (const void *item)
19551 const struct dwarf2_per_cu_offset_and_type *ofs = item;
19553 return (uintptr_t) ofs->per_cu + ofs->offset.sect_off;
19556 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19559 per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
19561 const struct dwarf2_per_cu_offset_and_type *ofs_lhs = item_lhs;
19562 const struct dwarf2_per_cu_offset_and_type *ofs_rhs = item_rhs;
19564 return (ofs_lhs->per_cu == ofs_rhs->per_cu
19565 && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off);
19568 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19569 table if necessary. For convenience, return TYPE.
19571 The DIEs reading must have careful ordering to:
19572 * Not cause infite loops trying to read in DIEs as a prerequisite for
19573 reading current DIE.
19574 * Not trying to dereference contents of still incompletely read in types
19575 while reading in other DIEs.
19576 * Enable referencing still incompletely read in types just by a pointer to
19577 the type without accessing its fields.
19579 Therefore caller should follow these rules:
19580 * Try to fetch any prerequisite types we may need to build this DIE type
19581 before building the type and calling set_die_type.
19582 * After building type call set_die_type for current DIE as soon as
19583 possible before fetching more types to complete the current type.
19584 * Make the type as complete as possible before fetching more types. */
19586 static struct type *
19587 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
19589 struct dwarf2_per_cu_offset_and_type **slot, ofs;
19590 struct objfile *objfile = cu->objfile;
19592 /* For Ada types, make sure that the gnat-specific data is always
19593 initialized (if not already set). There are a few types where
19594 we should not be doing so, because the type-specific area is
19595 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19596 where the type-specific area is used to store the floatformat).
19597 But this is not a problem, because the gnat-specific information
19598 is actually not needed for these types. */
19599 if (need_gnat_info (cu)
19600 && TYPE_CODE (type) != TYPE_CODE_FUNC
19601 && TYPE_CODE (type) != TYPE_CODE_FLT
19602 && !HAVE_GNAT_AUX_INFO (type))
19603 INIT_GNAT_SPECIFIC (type);
19605 if (dwarf2_per_objfile->die_type_hash == NULL)
19607 dwarf2_per_objfile->die_type_hash =
19608 htab_create_alloc_ex (127,
19609 per_cu_offset_and_type_hash,
19610 per_cu_offset_and_type_eq,
19612 &objfile->objfile_obstack,
19613 hashtab_obstack_allocate,
19614 dummy_obstack_deallocate);
19617 ofs.per_cu = cu->per_cu;
19618 ofs.offset = die->offset;
19620 slot = (struct dwarf2_per_cu_offset_and_type **)
19621 htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT);
19623 complaint (&symfile_complaints,
19624 _("A problem internal to GDB: DIE 0x%x has type already set"),
19625 die->offset.sect_off);
19626 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
19631 /* Look up the type for the die at OFFSET in the appropriate type_hash
19632 table, or return NULL if the die does not have a saved type. */
19634 static struct type *
19635 get_die_type_at_offset (sect_offset offset,
19636 struct dwarf2_per_cu_data *per_cu)
19638 struct dwarf2_per_cu_offset_and_type *slot, ofs;
19640 if (dwarf2_per_objfile->die_type_hash == NULL)
19643 ofs.per_cu = per_cu;
19644 ofs.offset = offset;
19645 slot = htab_find (dwarf2_per_objfile->die_type_hash, &ofs);
19652 /* Look up the type for DIE in the appropriate type_hash table,
19653 or return NULL if DIE does not have a saved type. */
19655 static struct type *
19656 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
19658 return get_die_type_at_offset (die->offset, cu->per_cu);
19661 /* Add a dependence relationship from CU to REF_PER_CU. */
19664 dwarf2_add_dependence (struct dwarf2_cu *cu,
19665 struct dwarf2_per_cu_data *ref_per_cu)
19669 if (cu->dependencies == NULL)
19671 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
19672 NULL, &cu->comp_unit_obstack,
19673 hashtab_obstack_allocate,
19674 dummy_obstack_deallocate);
19676 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
19678 *slot = ref_per_cu;
19681 /* Subroutine of dwarf2_mark to pass to htab_traverse.
19682 Set the mark field in every compilation unit in the
19683 cache that we must keep because we are keeping CU. */
19686 dwarf2_mark_helper (void **slot, void *data)
19688 struct dwarf2_per_cu_data *per_cu;
19690 per_cu = (struct dwarf2_per_cu_data *) *slot;
19692 /* cu->dependencies references may not yet have been ever read if QUIT aborts
19693 reading of the chain. As such dependencies remain valid it is not much
19694 useful to track and undo them during QUIT cleanups. */
19695 if (per_cu->cu == NULL)
19698 if (per_cu->cu->mark)
19700 per_cu->cu->mark = 1;
19702 if (per_cu->cu->dependencies != NULL)
19703 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
19708 /* Set the mark field in CU and in every other compilation unit in the
19709 cache that we must keep because we are keeping CU. */
19712 dwarf2_mark (struct dwarf2_cu *cu)
19717 if (cu->dependencies != NULL)
19718 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
19722 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
19726 per_cu->cu->mark = 0;
19727 per_cu = per_cu->cu->read_in_chain;
19731 /* Trivial hash function for partial_die_info: the hash value of a DIE
19732 is its offset in .debug_info for this objfile. */
19735 partial_die_hash (const void *item)
19737 const struct partial_die_info *part_die = item;
19739 return part_die->offset.sect_off;
19742 /* Trivial comparison function for partial_die_info structures: two DIEs
19743 are equal if they have the same offset. */
19746 partial_die_eq (const void *item_lhs, const void *item_rhs)
19748 const struct partial_die_info *part_die_lhs = item_lhs;
19749 const struct partial_die_info *part_die_rhs = item_rhs;
19751 return part_die_lhs->offset.sect_off == part_die_rhs->offset.sect_off;
19754 static struct cmd_list_element *set_dwarf2_cmdlist;
19755 static struct cmd_list_element *show_dwarf2_cmdlist;
19758 set_dwarf2_cmd (char *args, int from_tty)
19760 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
19764 show_dwarf2_cmd (char *args, int from_tty)
19766 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
19769 /* Free data associated with OBJFILE, if necessary. */
19772 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
19774 struct dwarf2_per_objfile *data = d;
19777 for (ix = 0; ix < dwarf2_per_objfile->n_comp_units; ++ix)
19778 VEC_free (dwarf2_per_cu_ptr,
19779 dwarf2_per_objfile->all_comp_units[ix]->imported_symtabs);
19781 for (ix = 0; ix < dwarf2_per_objfile->n_type_units; ++ix)
19782 VEC_free (dwarf2_per_cu_ptr,
19783 dwarf2_per_objfile->all_type_units[ix]->per_cu.imported_symtabs);
19785 VEC_free (dwarf2_section_info_def, data->types);
19787 if (data->dwo_files)
19788 free_dwo_files (data->dwo_files, objfile);
19789 if (data->dwp_file)
19790 gdb_bfd_unref (data->dwp_file->dbfd);
19792 if (data->dwz_file && data->dwz_file->dwz_bfd)
19793 gdb_bfd_unref (data->dwz_file->dwz_bfd);
19797 /* The "save gdb-index" command. */
19799 /* The contents of the hash table we create when building the string
19801 struct strtab_entry
19803 offset_type offset;
19807 /* Hash function for a strtab_entry.
19809 Function is used only during write_hash_table so no index format backward
19810 compatibility is needed. */
19813 hash_strtab_entry (const void *e)
19815 const struct strtab_entry *entry = e;
19816 return mapped_index_string_hash (INT_MAX, entry->str);
19819 /* Equality function for a strtab_entry. */
19822 eq_strtab_entry (const void *a, const void *b)
19824 const struct strtab_entry *ea = a;
19825 const struct strtab_entry *eb = b;
19826 return !strcmp (ea->str, eb->str);
19829 /* Create a strtab_entry hash table. */
19832 create_strtab (void)
19834 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
19835 xfree, xcalloc, xfree);
19838 /* Add a string to the constant pool. Return the string's offset in
19842 add_string (htab_t table, struct obstack *cpool, const char *str)
19845 struct strtab_entry entry;
19846 struct strtab_entry *result;
19849 slot = htab_find_slot (table, &entry, INSERT);
19854 result = XNEW (struct strtab_entry);
19855 result->offset = obstack_object_size (cpool);
19857 obstack_grow_str0 (cpool, str);
19860 return result->offset;
19863 /* An entry in the symbol table. */
19864 struct symtab_index_entry
19866 /* The name of the symbol. */
19868 /* The offset of the name in the constant pool. */
19869 offset_type index_offset;
19870 /* A sorted vector of the indices of all the CUs that hold an object
19872 VEC (offset_type) *cu_indices;
19875 /* The symbol table. This is a power-of-2-sized hash table. */
19876 struct mapped_symtab
19878 offset_type n_elements;
19880 struct symtab_index_entry **data;
19883 /* Hash function for a symtab_index_entry. */
19886 hash_symtab_entry (const void *e)
19888 const struct symtab_index_entry *entry = e;
19889 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
19890 sizeof (offset_type) * VEC_length (offset_type,
19891 entry->cu_indices),
19895 /* Equality function for a symtab_index_entry. */
19898 eq_symtab_entry (const void *a, const void *b)
19900 const struct symtab_index_entry *ea = a;
19901 const struct symtab_index_entry *eb = b;
19902 int len = VEC_length (offset_type, ea->cu_indices);
19903 if (len != VEC_length (offset_type, eb->cu_indices))
19905 return !memcmp (VEC_address (offset_type, ea->cu_indices),
19906 VEC_address (offset_type, eb->cu_indices),
19907 sizeof (offset_type) * len);
19910 /* Destroy a symtab_index_entry. */
19913 delete_symtab_entry (void *p)
19915 struct symtab_index_entry *entry = p;
19916 VEC_free (offset_type, entry->cu_indices);
19920 /* Create a hash table holding symtab_index_entry objects. */
19923 create_symbol_hash_table (void)
19925 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
19926 delete_symtab_entry, xcalloc, xfree);
19929 /* Create a new mapped symtab object. */
19931 static struct mapped_symtab *
19932 create_mapped_symtab (void)
19934 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
19935 symtab->n_elements = 0;
19936 symtab->size = 1024;
19937 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
19941 /* Destroy a mapped_symtab. */
19944 cleanup_mapped_symtab (void *p)
19946 struct mapped_symtab *symtab = p;
19947 /* The contents of the array are freed when the other hash table is
19949 xfree (symtab->data);
19953 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
19956 Function is used only during write_hash_table so no index format backward
19957 compatibility is needed. */
19959 static struct symtab_index_entry **
19960 find_slot (struct mapped_symtab *symtab, const char *name)
19962 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
19964 index = hash & (symtab->size - 1);
19965 step = ((hash * 17) & (symtab->size - 1)) | 1;
19969 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
19970 return &symtab->data[index];
19971 index = (index + step) & (symtab->size - 1);
19975 /* Expand SYMTAB's hash table. */
19978 hash_expand (struct mapped_symtab *symtab)
19980 offset_type old_size = symtab->size;
19982 struct symtab_index_entry **old_entries = symtab->data;
19985 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
19987 for (i = 0; i < old_size; ++i)
19989 if (old_entries[i])
19991 struct symtab_index_entry **slot = find_slot (symtab,
19992 old_entries[i]->name);
19993 *slot = old_entries[i];
19997 xfree (old_entries);
20000 /* Add an entry to SYMTAB. NAME is the name of the symbol.
20001 CU_INDEX is the index of the CU in which the symbol appears.
20002 IS_STATIC is one if the symbol is static, otherwise zero (global). */
20005 add_index_entry (struct mapped_symtab *symtab, const char *name,
20006 int is_static, gdb_index_symbol_kind kind,
20007 offset_type cu_index)
20009 struct symtab_index_entry **slot;
20010 offset_type cu_index_and_attrs;
20012 ++symtab->n_elements;
20013 if (4 * symtab->n_elements / 3 >= symtab->size)
20014 hash_expand (symtab);
20016 slot = find_slot (symtab, name);
20019 *slot = XNEW (struct symtab_index_entry);
20020 (*slot)->name = name;
20021 /* index_offset is set later. */
20022 (*slot)->cu_indices = NULL;
20025 cu_index_and_attrs = 0;
20026 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs, cu_index);
20027 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs, is_static);
20028 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs, kind);
20030 /* We don't want to record an index value twice as we want to avoid the
20032 We process all global symbols and then all static symbols
20033 (which would allow us to avoid the duplication by only having to check
20034 the last entry pushed), but a symbol could have multiple kinds in one CU.
20035 To keep things simple we don't worry about the duplication here and
20036 sort and uniqufy the list after we've processed all symbols. */
20037 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index_and_attrs);
20040 /* qsort helper routine for uniquify_cu_indices. */
20043 offset_type_compare (const void *ap, const void *bp)
20045 offset_type a = *(offset_type *) ap;
20046 offset_type b = *(offset_type *) bp;
20048 return (a > b) - (b > a);
20051 /* Sort and remove duplicates of all symbols' cu_indices lists. */
20054 uniquify_cu_indices (struct mapped_symtab *symtab)
20058 for (i = 0; i < symtab->size; ++i)
20060 struct symtab_index_entry *entry = symtab->data[i];
20063 && entry->cu_indices != NULL)
20065 unsigned int next_to_insert, next_to_check;
20066 offset_type last_value;
20068 qsort (VEC_address (offset_type, entry->cu_indices),
20069 VEC_length (offset_type, entry->cu_indices),
20070 sizeof (offset_type), offset_type_compare);
20072 last_value = VEC_index (offset_type, entry->cu_indices, 0);
20073 next_to_insert = 1;
20074 for (next_to_check = 1;
20075 next_to_check < VEC_length (offset_type, entry->cu_indices);
20078 if (VEC_index (offset_type, entry->cu_indices, next_to_check)
20081 last_value = VEC_index (offset_type, entry->cu_indices,
20083 VEC_replace (offset_type, entry->cu_indices, next_to_insert,
20088 VEC_truncate (offset_type, entry->cu_indices, next_to_insert);
20093 /* Add a vector of indices to the constant pool. */
20096 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
20097 struct symtab_index_entry *entry)
20101 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
20104 offset_type len = VEC_length (offset_type, entry->cu_indices);
20105 offset_type val = MAYBE_SWAP (len);
20110 entry->index_offset = obstack_object_size (cpool);
20112 obstack_grow (cpool, &val, sizeof (val));
20114 VEC_iterate (offset_type, entry->cu_indices, i, iter);
20117 val = MAYBE_SWAP (iter);
20118 obstack_grow (cpool, &val, sizeof (val));
20123 struct symtab_index_entry *old_entry = *slot;
20124 entry->index_offset = old_entry->index_offset;
20127 return entry->index_offset;
20130 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
20131 constant pool entries going into the obstack CPOOL. */
20134 write_hash_table (struct mapped_symtab *symtab,
20135 struct obstack *output, struct obstack *cpool)
20138 htab_t symbol_hash_table;
20141 symbol_hash_table = create_symbol_hash_table ();
20142 str_table = create_strtab ();
20144 /* We add all the index vectors to the constant pool first, to
20145 ensure alignment is ok. */
20146 for (i = 0; i < symtab->size; ++i)
20148 if (symtab->data[i])
20149 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
20152 /* Now write out the hash table. */
20153 for (i = 0; i < symtab->size; ++i)
20155 offset_type str_off, vec_off;
20157 if (symtab->data[i])
20159 str_off = add_string (str_table, cpool, symtab->data[i]->name);
20160 vec_off = symtab->data[i]->index_offset;
20164 /* While 0 is a valid constant pool index, it is not valid
20165 to have 0 for both offsets. */
20170 str_off = MAYBE_SWAP (str_off);
20171 vec_off = MAYBE_SWAP (vec_off);
20173 obstack_grow (output, &str_off, sizeof (str_off));
20174 obstack_grow (output, &vec_off, sizeof (vec_off));
20177 htab_delete (str_table);
20178 htab_delete (symbol_hash_table);
20181 /* Struct to map psymtab to CU index in the index file. */
20182 struct psymtab_cu_index_map
20184 struct partial_symtab *psymtab;
20185 unsigned int cu_index;
20189 hash_psymtab_cu_index (const void *item)
20191 const struct psymtab_cu_index_map *map = item;
20193 return htab_hash_pointer (map->psymtab);
20197 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
20199 const struct psymtab_cu_index_map *lhs = item_lhs;
20200 const struct psymtab_cu_index_map *rhs = item_rhs;
20202 return lhs->psymtab == rhs->psymtab;
20205 /* Helper struct for building the address table. */
20206 struct addrmap_index_data
20208 struct objfile *objfile;
20209 struct obstack *addr_obstack;
20210 htab_t cu_index_htab;
20212 /* Non-zero if the previous_* fields are valid.
20213 We can't write an entry until we see the next entry (since it is only then
20214 that we know the end of the entry). */
20215 int previous_valid;
20216 /* Index of the CU in the table of all CUs in the index file. */
20217 unsigned int previous_cu_index;
20218 /* Start address of the CU. */
20219 CORE_ADDR previous_cu_start;
20222 /* Write an address entry to OBSTACK. */
20225 add_address_entry (struct objfile *objfile, struct obstack *obstack,
20226 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
20228 offset_type cu_index_to_write;
20230 CORE_ADDR baseaddr;
20232 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
20234 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
20235 obstack_grow (obstack, addr, 8);
20236 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
20237 obstack_grow (obstack, addr, 8);
20238 cu_index_to_write = MAYBE_SWAP (cu_index);
20239 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
20242 /* Worker function for traversing an addrmap to build the address table. */
20245 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
20247 struct addrmap_index_data *data = datap;
20248 struct partial_symtab *pst = obj;
20250 if (data->previous_valid)
20251 add_address_entry (data->objfile, data->addr_obstack,
20252 data->previous_cu_start, start_addr,
20253 data->previous_cu_index);
20255 data->previous_cu_start = start_addr;
20258 struct psymtab_cu_index_map find_map, *map;
20259 find_map.psymtab = pst;
20260 map = htab_find (data->cu_index_htab, &find_map);
20261 gdb_assert (map != NULL);
20262 data->previous_cu_index = map->cu_index;
20263 data->previous_valid = 1;
20266 data->previous_valid = 0;
20271 /* Write OBJFILE's address map to OBSTACK.
20272 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
20273 in the index file. */
20276 write_address_map (struct objfile *objfile, struct obstack *obstack,
20277 htab_t cu_index_htab)
20279 struct addrmap_index_data addrmap_index_data;
20281 /* When writing the address table, we have to cope with the fact that
20282 the addrmap iterator only provides the start of a region; we have to
20283 wait until the next invocation to get the start of the next region. */
20285 addrmap_index_data.objfile = objfile;
20286 addrmap_index_data.addr_obstack = obstack;
20287 addrmap_index_data.cu_index_htab = cu_index_htab;
20288 addrmap_index_data.previous_valid = 0;
20290 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
20291 &addrmap_index_data);
20293 /* It's highly unlikely the last entry (end address = 0xff...ff)
20294 is valid, but we should still handle it.
20295 The end address is recorded as the start of the next region, but that
20296 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20298 if (addrmap_index_data.previous_valid)
20299 add_address_entry (objfile, obstack,
20300 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
20301 addrmap_index_data.previous_cu_index);
20304 /* Return the symbol kind of PSYM. */
20306 static gdb_index_symbol_kind
20307 symbol_kind (struct partial_symbol *psym)
20309 domain_enum domain = PSYMBOL_DOMAIN (psym);
20310 enum address_class aclass = PSYMBOL_CLASS (psym);
20318 return GDB_INDEX_SYMBOL_KIND_FUNCTION;
20320 return GDB_INDEX_SYMBOL_KIND_TYPE;
20322 case LOC_CONST_BYTES:
20323 case LOC_OPTIMIZED_OUT:
20325 return GDB_INDEX_SYMBOL_KIND_VARIABLE;
20327 /* Note: It's currently impossible to recognize psyms as enum values
20328 short of reading the type info. For now punt. */
20329 return GDB_INDEX_SYMBOL_KIND_VARIABLE;
20331 /* There are other LOC_FOO values that one might want to classify
20332 as variables, but dwarf2read.c doesn't currently use them. */
20333 return GDB_INDEX_SYMBOL_KIND_OTHER;
20335 case STRUCT_DOMAIN:
20336 return GDB_INDEX_SYMBOL_KIND_TYPE;
20338 return GDB_INDEX_SYMBOL_KIND_OTHER;
20342 /* Add a list of partial symbols to SYMTAB. */
20345 write_psymbols (struct mapped_symtab *symtab,
20347 struct partial_symbol **psymp,
20349 offset_type cu_index,
20352 for (; count-- > 0; ++psymp)
20354 struct partial_symbol *psym = *psymp;
20357 if (SYMBOL_LANGUAGE (psym) == language_ada)
20358 error (_("Ada is not currently supported by the index"));
20360 /* Only add a given psymbol once. */
20361 slot = htab_find_slot (psyms_seen, psym, INSERT);
20364 gdb_index_symbol_kind kind = symbol_kind (psym);
20367 add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym),
20368 is_static, kind, cu_index);
20373 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20374 exception if there is an error. */
20377 write_obstack (FILE *file, struct obstack *obstack)
20379 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
20381 != obstack_object_size (obstack))
20382 error (_("couldn't data write to file"));
20385 /* Unlink a file if the argument is not NULL. */
20388 unlink_if_set (void *p)
20390 char **filename = p;
20392 unlink (*filename);
20395 /* A helper struct used when iterating over debug_types. */
20396 struct signatured_type_index_data
20398 struct objfile *objfile;
20399 struct mapped_symtab *symtab;
20400 struct obstack *types_list;
20405 /* A helper function that writes a single signatured_type to an
20409 write_one_signatured_type (void **slot, void *d)
20411 struct signatured_type_index_data *info = d;
20412 struct signatured_type *entry = (struct signatured_type *) *slot;
20413 struct partial_symtab *psymtab = entry->per_cu.v.psymtab;
20416 write_psymbols (info->symtab,
20418 info->objfile->global_psymbols.list
20419 + psymtab->globals_offset,
20420 psymtab->n_global_syms, info->cu_index,
20422 write_psymbols (info->symtab,
20424 info->objfile->static_psymbols.list
20425 + psymtab->statics_offset,
20426 psymtab->n_static_syms, info->cu_index,
20429 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
20430 entry->per_cu.offset.sect_off);
20431 obstack_grow (info->types_list, val, 8);
20432 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
20433 entry->type_offset_in_tu.cu_off);
20434 obstack_grow (info->types_list, val, 8);
20435 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
20436 obstack_grow (info->types_list, val, 8);
20443 /* Recurse into all "included" dependencies and write their symbols as
20444 if they appeared in this psymtab. */
20447 recursively_write_psymbols (struct objfile *objfile,
20448 struct partial_symtab *psymtab,
20449 struct mapped_symtab *symtab,
20451 offset_type cu_index)
20455 for (i = 0; i < psymtab->number_of_dependencies; ++i)
20456 if (psymtab->dependencies[i]->user != NULL)
20457 recursively_write_psymbols (objfile, psymtab->dependencies[i],
20458 symtab, psyms_seen, cu_index);
20460 write_psymbols (symtab,
20462 objfile->global_psymbols.list + psymtab->globals_offset,
20463 psymtab->n_global_syms, cu_index,
20465 write_psymbols (symtab,
20467 objfile->static_psymbols.list + psymtab->statics_offset,
20468 psymtab->n_static_syms, cu_index,
20472 /* Create an index file for OBJFILE in the directory DIR. */
20475 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
20477 struct cleanup *cleanup;
20478 char *filename, *cleanup_filename;
20479 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
20480 struct obstack cu_list, types_cu_list;
20483 struct mapped_symtab *symtab;
20484 offset_type val, size_of_contents, total_len;
20487 htab_t cu_index_htab;
20488 struct psymtab_cu_index_map *psymtab_cu_index_map;
20490 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
20493 if (dwarf2_per_objfile->using_index)
20494 error (_("Cannot use an index to create the index"));
20496 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
20497 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20499 if (stat (objfile->name, &st) < 0)
20500 perror_with_name (objfile->name);
20502 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
20503 INDEX_SUFFIX, (char *) NULL);
20504 cleanup = make_cleanup (xfree, filename);
20506 out_file = fopen (filename, "wb");
20508 error (_("Can't open `%s' for writing"), filename);
20510 cleanup_filename = filename;
20511 make_cleanup (unlink_if_set, &cleanup_filename);
20513 symtab = create_mapped_symtab ();
20514 make_cleanup (cleanup_mapped_symtab, symtab);
20516 obstack_init (&addr_obstack);
20517 make_cleanup_obstack_free (&addr_obstack);
20519 obstack_init (&cu_list);
20520 make_cleanup_obstack_free (&cu_list);
20522 obstack_init (&types_cu_list);
20523 make_cleanup_obstack_free (&types_cu_list);
20525 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
20526 NULL, xcalloc, xfree);
20527 make_cleanup_htab_delete (psyms_seen);
20529 /* While we're scanning CU's create a table that maps a psymtab pointer
20530 (which is what addrmap records) to its index (which is what is recorded
20531 in the index file). This will later be needed to write the address
20533 cu_index_htab = htab_create_alloc (100,
20534 hash_psymtab_cu_index,
20535 eq_psymtab_cu_index,
20536 NULL, xcalloc, xfree);
20537 make_cleanup_htab_delete (cu_index_htab);
20538 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
20539 xmalloc (sizeof (struct psymtab_cu_index_map)
20540 * dwarf2_per_objfile->n_comp_units);
20541 make_cleanup (xfree, psymtab_cu_index_map);
20543 /* The CU list is already sorted, so we don't need to do additional
20544 work here. Also, the debug_types entries do not appear in
20545 all_comp_units, but only in their own hash table. */
20546 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
20548 struct dwarf2_per_cu_data *per_cu
20549 = dwarf2_per_objfile->all_comp_units[i];
20550 struct partial_symtab *psymtab = per_cu->v.psymtab;
20552 struct psymtab_cu_index_map *map;
20555 if (psymtab->user == NULL)
20556 recursively_write_psymbols (objfile, psymtab, symtab, psyms_seen, i);
20558 map = &psymtab_cu_index_map[i];
20559 map->psymtab = psymtab;
20561 slot = htab_find_slot (cu_index_htab, map, INSERT);
20562 gdb_assert (slot != NULL);
20563 gdb_assert (*slot == NULL);
20566 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
20567 per_cu->offset.sect_off);
20568 obstack_grow (&cu_list, val, 8);
20569 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
20570 obstack_grow (&cu_list, val, 8);
20573 /* Dump the address map. */
20574 write_address_map (objfile, &addr_obstack, cu_index_htab);
20576 /* Write out the .debug_type entries, if any. */
20577 if (dwarf2_per_objfile->signatured_types)
20579 struct signatured_type_index_data sig_data;
20581 sig_data.objfile = objfile;
20582 sig_data.symtab = symtab;
20583 sig_data.types_list = &types_cu_list;
20584 sig_data.psyms_seen = psyms_seen;
20585 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
20586 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
20587 write_one_signatured_type, &sig_data);
20590 /* Now that we've processed all symbols we can shrink their cu_indices
20592 uniquify_cu_indices (symtab);
20594 obstack_init (&constant_pool);
20595 make_cleanup_obstack_free (&constant_pool);
20596 obstack_init (&symtab_obstack);
20597 make_cleanup_obstack_free (&symtab_obstack);
20598 write_hash_table (symtab, &symtab_obstack, &constant_pool);
20600 obstack_init (&contents);
20601 make_cleanup_obstack_free (&contents);
20602 size_of_contents = 6 * sizeof (offset_type);
20603 total_len = size_of_contents;
20605 /* The version number. */
20606 val = MAYBE_SWAP (8);
20607 obstack_grow (&contents, &val, sizeof (val));
20609 /* The offset of the CU list from the start of the file. */
20610 val = MAYBE_SWAP (total_len);
20611 obstack_grow (&contents, &val, sizeof (val));
20612 total_len += obstack_object_size (&cu_list);
20614 /* The offset of the types CU list from the start of the file. */
20615 val = MAYBE_SWAP (total_len);
20616 obstack_grow (&contents, &val, sizeof (val));
20617 total_len += obstack_object_size (&types_cu_list);
20619 /* The offset of the address table from the start of the file. */
20620 val = MAYBE_SWAP (total_len);
20621 obstack_grow (&contents, &val, sizeof (val));
20622 total_len += obstack_object_size (&addr_obstack);
20624 /* The offset of the symbol table from the start of the file. */
20625 val = MAYBE_SWAP (total_len);
20626 obstack_grow (&contents, &val, sizeof (val));
20627 total_len += obstack_object_size (&symtab_obstack);
20629 /* The offset of the constant pool from the start of the file. */
20630 val = MAYBE_SWAP (total_len);
20631 obstack_grow (&contents, &val, sizeof (val));
20632 total_len += obstack_object_size (&constant_pool);
20634 gdb_assert (obstack_object_size (&contents) == size_of_contents);
20636 write_obstack (out_file, &contents);
20637 write_obstack (out_file, &cu_list);
20638 write_obstack (out_file, &types_cu_list);
20639 write_obstack (out_file, &addr_obstack);
20640 write_obstack (out_file, &symtab_obstack);
20641 write_obstack (out_file, &constant_pool);
20645 /* We want to keep the file, so we set cleanup_filename to NULL
20646 here. See unlink_if_set. */
20647 cleanup_filename = NULL;
20649 do_cleanups (cleanup);
20652 /* Implementation of the `save gdb-index' command.
20654 Note that the file format used by this command is documented in the
20655 GDB manual. Any changes here must be documented there. */
20658 save_gdb_index_command (char *arg, int from_tty)
20660 struct objfile *objfile;
20663 error (_("usage: save gdb-index DIRECTORY"));
20665 ALL_OBJFILES (objfile)
20669 /* If the objfile does not correspond to an actual file, skip it. */
20670 if (stat (objfile->name, &st) < 0)
20673 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
20674 if (dwarf2_per_objfile)
20676 volatile struct gdb_exception except;
20678 TRY_CATCH (except, RETURN_MASK_ERROR)
20680 write_psymtabs_to_index (objfile, arg);
20682 if (except.reason < 0)
20683 exception_fprintf (gdb_stderr, except,
20684 _("Error while writing index for `%s': "),
20692 int dwarf2_always_disassemble;
20695 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
20696 struct cmd_list_element *c, const char *value)
20698 fprintf_filtered (file,
20699 _("Whether to always disassemble "
20700 "DWARF expressions is %s.\n"),
20705 show_check_physname (struct ui_file *file, int from_tty,
20706 struct cmd_list_element *c, const char *value)
20708 fprintf_filtered (file,
20709 _("Whether to check \"physname\" is %s.\n"),
20713 void _initialize_dwarf2_read (void);
20716 _initialize_dwarf2_read (void)
20718 struct cmd_list_element *c;
20720 dwarf2_objfile_data_key
20721 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
20723 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
20724 Set DWARF 2 specific variables.\n\
20725 Configure DWARF 2 variables such as the cache size"),
20726 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
20727 0/*allow-unknown*/, &maintenance_set_cmdlist);
20729 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
20730 Show DWARF 2 specific variables\n\
20731 Show DWARF 2 variables such as the cache size"),
20732 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
20733 0/*allow-unknown*/, &maintenance_show_cmdlist);
20735 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
20736 &dwarf2_max_cache_age, _("\
20737 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
20738 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
20739 A higher limit means that cached compilation units will be stored\n\
20740 in memory longer, and more total memory will be used. Zero disables\n\
20741 caching, which can slow down startup."),
20743 show_dwarf2_max_cache_age,
20744 &set_dwarf2_cmdlist,
20745 &show_dwarf2_cmdlist);
20747 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
20748 &dwarf2_always_disassemble, _("\
20749 Set whether `info address' always disassembles DWARF expressions."), _("\
20750 Show whether `info address' always disassembles DWARF expressions."), _("\
20751 When enabled, DWARF expressions are always printed in an assembly-like\n\
20752 syntax. When disabled, expressions will be printed in a more\n\
20753 conversational style, when possible."),
20755 show_dwarf2_always_disassemble,
20756 &set_dwarf2_cmdlist,
20757 &show_dwarf2_cmdlist);
20759 add_setshow_boolean_cmd ("dwarf2-read", no_class, &dwarf2_read_debug, _("\
20760 Set debugging of the dwarf2 reader."), _("\
20761 Show debugging of the dwarf2 reader."), _("\
20762 When enabled, debugging messages are printed during dwarf2 reading\n\
20763 and symtab expansion."),
20766 &setdebuglist, &showdebuglist);
20768 add_setshow_zuinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
20769 Set debugging of the dwarf2 DIE reader."), _("\
20770 Show debugging of the dwarf2 DIE reader."), _("\
20771 When enabled (non-zero), DIEs are dumped after they are read in.\n\
20772 The value is the maximum depth to print."),
20775 &setdebuglist, &showdebuglist);
20777 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
20778 Set cross-checking of \"physname\" code against demangler."), _("\
20779 Show cross-checking of \"physname\" code against demangler."), _("\
20780 When enabled, GDB's internal \"physname\" code is checked against\n\
20782 NULL, show_check_physname,
20783 &setdebuglist, &showdebuglist);
20785 add_setshow_boolean_cmd ("use-deprecated-index-sections",
20786 no_class, &use_deprecated_index_sections, _("\
20787 Set whether to use deprecated gdb_index sections."), _("\
20788 Show whether to use deprecated gdb_index sections."), _("\
20789 When enabled, deprecated .gdb_index sections are used anyway.\n\
20790 Normally they are ignored either because of a missing feature or\n\
20791 performance issue.\n\
20792 Warning: This option must be enabled before gdb reads the file."),
20795 &setlist, &showlist);
20797 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
20799 Save a gdb-index file.\n\
20800 Usage: save gdb-index DIRECTORY"),
20802 set_cmd_completer (c, filename_completer);
20804 dwarf2_locexpr_index = register_symbol_computed_impl (LOC_COMPUTED,
20805 &dwarf2_locexpr_funcs);
20806 dwarf2_loclist_index = register_symbol_computed_impl (LOC_COMPUTED,
20807 &dwarf2_loclist_funcs);
20809 dwarf2_locexpr_block_index = register_symbol_block_impl (LOC_BLOCK,
20810 &dwarf2_block_frame_base_locexpr_funcs);
20811 dwarf2_loclist_block_index = register_symbol_block_impl (LOC_BLOCK,
20812 &dwarf2_block_frame_base_loclist_funcs);