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"
71 #include "filestuff.h"
74 #include "gdb_string.h"
75 #include "gdb_assert.h"
76 #include <sys/types.h>
78 typedef struct symbol *symbolp;
81 /* When non-zero, print basic high level tracing messages.
82 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
83 static int dwarf2_read_debug = 0;
85 /* When non-zero, dump DIEs after they are read in. */
86 static unsigned int dwarf2_die_debug = 0;
88 /* When non-zero, cross-check physname against demangler. */
89 static int check_physname = 0;
91 /* When non-zero, do not reject deprecated .gdb_index sections. */
92 static int use_deprecated_index_sections = 0;
94 static const struct objfile_data *dwarf2_objfile_data_key;
96 /* The "aclass" indices for various kinds of computed DWARF symbols. */
98 static int dwarf2_locexpr_index;
99 static int dwarf2_loclist_index;
100 static int dwarf2_locexpr_block_index;
101 static int dwarf2_loclist_block_index;
103 struct dwarf2_section_info
106 const gdb_byte *buffer;
108 /* True if we have tried to read this section. */
112 typedef struct dwarf2_section_info dwarf2_section_info_def;
113 DEF_VEC_O (dwarf2_section_info_def);
115 /* All offsets in the index are of this type. It must be
116 architecture-independent. */
117 typedef uint32_t offset_type;
119 DEF_VEC_I (offset_type);
121 /* Ensure only legit values are used. */
122 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
124 gdb_assert ((unsigned int) (value) <= 1); \
125 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
128 /* Ensure only legit values are used. */
129 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
131 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
132 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
133 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
136 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
137 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
139 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
140 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
143 /* A description of the mapped index. The file format is described in
144 a comment by the code that writes the index. */
147 /* Index data format version. */
150 /* The total length of the buffer. */
153 /* A pointer to the address table data. */
154 const gdb_byte *address_table;
156 /* Size of the address table data in bytes. */
157 offset_type address_table_size;
159 /* The symbol table, implemented as a hash table. */
160 const offset_type *symbol_table;
162 /* Size in slots, each slot is 2 offset_types. */
163 offset_type symbol_table_slots;
165 /* A pointer to the constant pool. */
166 const char *constant_pool;
169 typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr;
170 DEF_VEC_P (dwarf2_per_cu_ptr);
172 /* Collection of data recorded per objfile.
173 This hangs off of dwarf2_objfile_data_key. */
175 struct dwarf2_per_objfile
177 struct dwarf2_section_info info;
178 struct dwarf2_section_info abbrev;
179 struct dwarf2_section_info line;
180 struct dwarf2_section_info loc;
181 struct dwarf2_section_info macinfo;
182 struct dwarf2_section_info macro;
183 struct dwarf2_section_info str;
184 struct dwarf2_section_info ranges;
185 struct dwarf2_section_info addr;
186 struct dwarf2_section_info frame;
187 struct dwarf2_section_info eh_frame;
188 struct dwarf2_section_info gdb_index;
190 VEC (dwarf2_section_info_def) *types;
193 struct objfile *objfile;
195 /* Table of all the compilation units. This is used to locate
196 the target compilation unit of a particular reference. */
197 struct dwarf2_per_cu_data **all_comp_units;
199 /* The number of compilation units in ALL_COMP_UNITS. */
202 /* The number of .debug_types-related CUs. */
205 /* The .debug_types-related CUs (TUs). */
206 struct signatured_type **all_type_units;
208 /* The number of entries in all_type_unit_groups. */
209 int n_type_unit_groups;
211 /* Table of type unit groups.
212 This exists to make it easy to iterate over all CUs and TU groups. */
213 struct type_unit_group **all_type_unit_groups;
215 /* Table of struct type_unit_group objects.
216 The hash key is the DW_AT_stmt_list value. */
217 htab_t type_unit_groups;
219 /* A table mapping .debug_types signatures to its signatured_type entry.
220 This is NULL if the .debug_types section hasn't been read in yet. */
221 htab_t signatured_types;
223 /* Type unit statistics, to see how well the scaling improvements
227 int nr_uniq_abbrev_tables;
229 int nr_symtab_sharers;
230 int nr_stmt_less_type_units;
233 /* A chain of compilation units that are currently read in, so that
234 they can be freed later. */
235 struct dwarf2_per_cu_data *read_in_chain;
237 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
238 This is NULL if the table hasn't been allocated yet. */
241 /* Non-zero if we've check for whether there is a DWP file. */
244 /* The DWP file if there is one, or NULL. */
245 struct dwp_file *dwp_file;
247 /* The shared '.dwz' file, if one exists. This is used when the
248 original data was compressed using 'dwz -m'. */
249 struct dwz_file *dwz_file;
251 /* A flag indicating wether this objfile has a section loaded at a
253 int has_section_at_zero;
255 /* True if we are using the mapped index,
256 or we are faking it for OBJF_READNOW's sake. */
257 unsigned char using_index;
259 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
260 struct mapped_index *index_table;
262 /* When using index_table, this keeps track of all quick_file_names entries.
263 TUs typically share line table entries with a CU, so we maintain a
264 separate table of all line table entries to support the sharing.
265 Note that while there can be way more TUs than CUs, we've already
266 sorted all the TUs into "type unit groups", grouped by their
267 DW_AT_stmt_list value. Therefore the only sharing done here is with a
268 CU and its associated TU group if there is one. */
269 htab_t quick_file_names_table;
271 /* Set during partial symbol reading, to prevent queueing of full
273 int reading_partial_symbols;
275 /* Table mapping type DIEs to their struct type *.
276 This is NULL if not allocated yet.
277 The mapping is done via (CU/TU + DIE offset) -> type. */
278 htab_t die_type_hash;
280 /* The CUs we recently read. */
281 VEC (dwarf2_per_cu_ptr) *just_read_cus;
284 static struct dwarf2_per_objfile *dwarf2_per_objfile;
286 /* Default names of the debugging sections. */
288 /* Note that if the debugging section has been compressed, it might
289 have a name like .zdebug_info. */
291 static const struct dwarf2_debug_sections dwarf2_elf_names =
293 { ".debug_info", ".zdebug_info" },
294 { ".debug_abbrev", ".zdebug_abbrev" },
295 { ".debug_line", ".zdebug_line" },
296 { ".debug_loc", ".zdebug_loc" },
297 { ".debug_macinfo", ".zdebug_macinfo" },
298 { ".debug_macro", ".zdebug_macro" },
299 { ".debug_str", ".zdebug_str" },
300 { ".debug_ranges", ".zdebug_ranges" },
301 { ".debug_types", ".zdebug_types" },
302 { ".debug_addr", ".zdebug_addr" },
303 { ".debug_frame", ".zdebug_frame" },
304 { ".eh_frame", NULL },
305 { ".gdb_index", ".zgdb_index" },
309 /* List of DWO/DWP sections. */
311 static const struct dwop_section_names
313 struct dwarf2_section_names abbrev_dwo;
314 struct dwarf2_section_names info_dwo;
315 struct dwarf2_section_names line_dwo;
316 struct dwarf2_section_names loc_dwo;
317 struct dwarf2_section_names macinfo_dwo;
318 struct dwarf2_section_names macro_dwo;
319 struct dwarf2_section_names str_dwo;
320 struct dwarf2_section_names str_offsets_dwo;
321 struct dwarf2_section_names types_dwo;
322 struct dwarf2_section_names cu_index;
323 struct dwarf2_section_names tu_index;
327 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
328 { ".debug_info.dwo", ".zdebug_info.dwo" },
329 { ".debug_line.dwo", ".zdebug_line.dwo" },
330 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
331 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
332 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
333 { ".debug_str.dwo", ".zdebug_str.dwo" },
334 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
335 { ".debug_types.dwo", ".zdebug_types.dwo" },
336 { ".debug_cu_index", ".zdebug_cu_index" },
337 { ".debug_tu_index", ".zdebug_tu_index" },
340 /* local data types */
342 /* The data in a compilation unit header, after target2host
343 translation, looks like this. */
344 struct comp_unit_head
348 unsigned char addr_size;
349 unsigned char signed_addr_p;
350 sect_offset abbrev_offset;
352 /* Size of file offsets; either 4 or 8. */
353 unsigned int offset_size;
355 /* Size of the length field; either 4 or 12. */
356 unsigned int initial_length_size;
358 /* Offset to the first byte of this compilation unit header in the
359 .debug_info section, for resolving relative reference dies. */
362 /* Offset to first die in this cu from the start of the cu.
363 This will be the first byte following the compilation unit header. */
364 cu_offset first_die_offset;
367 /* Type used for delaying computation of method physnames.
368 See comments for compute_delayed_physnames. */
369 struct delayed_method_info
371 /* The type to which the method is attached, i.e., its parent class. */
374 /* The index of the method in the type's function fieldlists. */
377 /* The index of the method in the fieldlist. */
380 /* The name of the DIE. */
383 /* The DIE associated with this method. */
384 struct die_info *die;
387 typedef struct delayed_method_info delayed_method_info;
388 DEF_VEC_O (delayed_method_info);
390 /* Internal state when decoding a particular compilation unit. */
393 /* The objfile containing this compilation unit. */
394 struct objfile *objfile;
396 /* The header of the compilation unit. */
397 struct comp_unit_head header;
399 /* Base address of this compilation unit. */
400 CORE_ADDR base_address;
402 /* Non-zero if base_address has been set. */
405 /* The language we are debugging. */
406 enum language language;
407 const struct language_defn *language_defn;
409 const char *producer;
411 /* The generic symbol table building routines have separate lists for
412 file scope symbols and all all other scopes (local scopes). So
413 we need to select the right one to pass to add_symbol_to_list().
414 We do it by keeping a pointer to the correct list in list_in_scope.
416 FIXME: The original dwarf code just treated the file scope as the
417 first local scope, and all other local scopes as nested local
418 scopes, and worked fine. Check to see if we really need to
419 distinguish these in buildsym.c. */
420 struct pending **list_in_scope;
422 /* The abbrev table for this CU.
423 Normally this points to the abbrev table in the objfile.
424 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
425 struct abbrev_table *abbrev_table;
427 /* Hash table holding all the loaded partial DIEs
428 with partial_die->offset.SECT_OFF as hash. */
431 /* Storage for things with the same lifetime as this read-in compilation
432 unit, including partial DIEs. */
433 struct obstack comp_unit_obstack;
435 /* When multiple dwarf2_cu structures are living in memory, this field
436 chains them all together, so that they can be released efficiently.
437 We will probably also want a generation counter so that most-recently-used
438 compilation units are cached... */
439 struct dwarf2_per_cu_data *read_in_chain;
441 /* Backchain to our per_cu entry if the tree has been built. */
442 struct dwarf2_per_cu_data *per_cu;
444 /* How many compilation units ago was this CU last referenced? */
447 /* A hash table of DIE cu_offset for following references with
448 die_info->offset.sect_off as hash. */
451 /* Full DIEs if read in. */
452 struct die_info *dies;
454 /* A set of pointers to dwarf2_per_cu_data objects for compilation
455 units referenced by this one. Only set during full symbol processing;
456 partial symbol tables do not have dependencies. */
459 /* Header data from the line table, during full symbol processing. */
460 struct line_header *line_header;
462 /* A list of methods which need to have physnames computed
463 after all type information has been read. */
464 VEC (delayed_method_info) *method_list;
466 /* To be copied to symtab->call_site_htab. */
467 htab_t call_site_htab;
469 /* Non-NULL if this CU came from a DWO file.
470 There is an invariant here that is important to remember:
471 Except for attributes copied from the top level DIE in the "main"
472 (or "stub") file in preparation for reading the DWO file
473 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
474 Either there isn't a DWO file (in which case this is NULL and the point
475 is moot), or there is and either we're not going to read it (in which
476 case this is NULL) or there is and we are reading it (in which case this
478 struct dwo_unit *dwo_unit;
480 /* The DW_AT_addr_base attribute if present, zero otherwise
481 (zero is a valid value though).
482 Note this value comes from the stub CU/TU's DIE. */
485 /* The DW_AT_ranges_base attribute if present, zero otherwise
486 (zero is a valid value though).
487 Note this value comes from the stub CU/TU's DIE.
488 Also note that the value is zero in the non-DWO case so this value can
489 be used without needing to know whether DWO files are in use or not.
490 N.B. This does not apply to DW_AT_ranges appearing in
491 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
492 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
493 DW_AT_ranges_base *would* have to be applied, and we'd have to care
494 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
495 ULONGEST ranges_base;
497 /* Mark used when releasing cached dies. */
498 unsigned int mark : 1;
500 /* This CU references .debug_loc. See the symtab->locations_valid field.
501 This test is imperfect as there may exist optimized debug code not using
502 any location list and still facing inlining issues if handled as
503 unoptimized code. For a future better test see GCC PR other/32998. */
504 unsigned int has_loclist : 1;
506 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
507 if all the producer_is_* fields are valid. This information is cached
508 because profiling CU expansion showed excessive time spent in
509 producer_is_gxx_lt_4_6. */
510 unsigned int checked_producer : 1;
511 unsigned int producer_is_gxx_lt_4_6 : 1;
512 unsigned int producer_is_gcc_lt_4_3 : 1;
513 unsigned int producer_is_icc : 1;
515 /* When set, the file that we're processing is known to have
516 debugging info for C++ namespaces. GCC 3.3.x did not produce
517 this information, but later versions do. */
519 unsigned int processing_has_namespace_info : 1;
522 /* Persistent data held for a compilation unit, even when not
523 processing it. We put a pointer to this structure in the
524 read_symtab_private field of the psymtab. */
526 struct dwarf2_per_cu_data
528 /* The start offset and length of this compilation unit.
529 NOTE: Unlike comp_unit_head.length, this length includes
531 If the DIE refers to a DWO file, this is always of the original die,
536 /* Flag indicating this compilation unit will be read in before
537 any of the current compilation units are processed. */
538 unsigned int queued : 1;
540 /* This flag will be set when reading partial DIEs if we need to load
541 absolutely all DIEs for this compilation unit, instead of just the ones
542 we think are interesting. It gets set if we look for a DIE in the
543 hash table and don't find it. */
544 unsigned int load_all_dies : 1;
546 /* Non-zero if this CU is from .debug_types.
547 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
549 unsigned int is_debug_types : 1;
551 /* Non-zero if this CU is from the .dwz file. */
552 unsigned int is_dwz : 1;
554 /* The section this CU/TU lives in.
555 If the DIE refers to a DWO file, this is always the original die,
557 struct dwarf2_section_info *section;
559 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
560 of the CU cache it gets reset to NULL again. */
561 struct dwarf2_cu *cu;
563 /* The corresponding objfile.
564 Normally we can get the objfile from dwarf2_per_objfile.
565 However we can enter this file with just a "per_cu" handle. */
566 struct objfile *objfile;
568 /* When using partial symbol tables, the 'psymtab' field is active.
569 Otherwise the 'quick' field is active. */
572 /* The partial symbol table associated with this compilation unit,
573 or NULL for unread partial units. */
574 struct partial_symtab *psymtab;
576 /* Data needed by the "quick" functions. */
577 struct dwarf2_per_cu_quick_data *quick;
580 /* The CUs we import using DW_TAG_imported_unit. This is filled in
581 while reading psymtabs, used to compute the psymtab dependencies,
582 and then cleared. Then it is filled in again while reading full
583 symbols, and only deleted when the objfile is destroyed.
585 This is also used to work around a difference between the way gold
586 generates .gdb_index version <=7 and the way gdb does. Arguably this
587 is a gold bug. For symbols coming from TUs, gold records in the index
588 the CU that includes the TU instead of the TU itself. This breaks
589 dw2_lookup_symbol: It assumes that if the index says symbol X lives
590 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
591 will find X. Alas TUs live in their own symtab, so after expanding CU Y
592 we need to look in TU Z to find X. Fortunately, this is akin to
593 DW_TAG_imported_unit, so we just use the same mechanism: For
594 .gdb_index version <=7 this also records the TUs that the CU referred
595 to. Concurrently with this change gdb was modified to emit version 8
596 indices so we only pay a price for gold generated indices. */
597 VEC (dwarf2_per_cu_ptr) *imported_symtabs;
600 /* Entry in the signatured_types hash table. */
602 struct signatured_type
604 /* The "per_cu" object of this type.
605 This struct is used iff per_cu.is_debug_types.
606 N.B.: This is the first member so that it's easy to convert pointers
608 struct dwarf2_per_cu_data per_cu;
610 /* The type's signature. */
613 /* Offset in the TU of the type's DIE, as read from the TU header.
614 If this TU is a DWO stub and the definition lives in a DWO file
615 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
616 cu_offset type_offset_in_tu;
618 /* Offset in the section of the type's DIE.
619 If the definition lives in a DWO file, this is the offset in the
620 .debug_types.dwo section.
621 The value is zero until the actual value is known.
622 Zero is otherwise not a valid section offset. */
623 sect_offset type_offset_in_section;
625 /* Type units are grouped by their DW_AT_stmt_list entry so that they
626 can share them. This points to the containing symtab. */
627 struct type_unit_group *type_unit_group;
630 The first time we encounter this type we fully read it in and install it
631 in the symbol tables. Subsequent times we only need the type. */
635 typedef struct signatured_type *sig_type_ptr;
636 DEF_VEC_P (sig_type_ptr);
638 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
639 This includes type_unit_group and quick_file_names. */
641 struct stmt_list_hash
643 /* The DWO unit this table is from or NULL if there is none. */
644 struct dwo_unit *dwo_unit;
646 /* Offset in .debug_line or .debug_line.dwo. */
647 sect_offset line_offset;
650 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
651 an object of this type. */
653 struct type_unit_group
655 /* dwarf2read.c's main "handle" on a TU symtab.
656 To simplify things we create an artificial CU that "includes" all the
657 type units using this stmt_list so that the rest of the code still has
658 a "per_cu" handle on the symtab.
659 This PER_CU is recognized by having no section. */
660 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
661 struct dwarf2_per_cu_data per_cu;
663 /* The TUs that share this DW_AT_stmt_list entry.
664 This is added to while parsing type units to build partial symtabs,
665 and is deleted afterwards and not used again. */
666 VEC (sig_type_ptr) *tus;
668 /* The primary symtab.
669 Type units in a group needn't all be defined in the same source file,
670 so we create an essentially anonymous symtab as the primary symtab. */
671 struct symtab *primary_symtab;
673 /* The data used to construct the hash key. */
674 struct stmt_list_hash hash;
676 /* The number of symtabs from the line header.
677 The value here must match line_header.num_file_names. */
678 unsigned int num_symtabs;
680 /* The symbol tables for this TU (obtained from the files listed in
682 WARNING: The order of entries here must match the order of entries
683 in the line header. After the first TU using this type_unit_group, the
684 line header for the subsequent TUs is recreated from this. This is done
685 because we need to use the same symtabs for each TU using the same
686 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
687 there's no guarantee the line header doesn't have duplicate entries. */
688 struct symtab **symtabs;
691 /* These sections are what may appear in a DWO file. */
695 struct dwarf2_section_info abbrev;
696 struct dwarf2_section_info line;
697 struct dwarf2_section_info loc;
698 struct dwarf2_section_info macinfo;
699 struct dwarf2_section_info macro;
700 struct dwarf2_section_info str;
701 struct dwarf2_section_info str_offsets;
702 /* In the case of a virtual DWO file, these two are unused. */
703 struct dwarf2_section_info info;
704 VEC (dwarf2_section_info_def) *types;
707 /* CUs/TUs in DWP/DWO files. */
711 /* Backlink to the containing struct dwo_file. */
712 struct dwo_file *dwo_file;
714 /* The "id" that distinguishes this CU/TU.
715 .debug_info calls this "dwo_id", .debug_types calls this "signature".
716 Since signatures came first, we stick with it for consistency. */
719 /* The section this CU/TU lives in, in the DWO file. */
720 struct dwarf2_section_info *section;
722 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
726 /* For types, offset in the type's DIE of the type defined by this TU. */
727 cu_offset type_offset_in_tu;
730 /* Data for one DWO file.
731 This includes virtual DWO files that have been packaged into a
736 /* The DW_AT_GNU_dwo_name attribute.
737 For virtual DWO files the name is constructed from the section offsets
738 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
739 from related CU+TUs. */
740 const char *dwo_name;
742 /* The DW_AT_comp_dir attribute. */
743 const char *comp_dir;
745 /* The bfd, when the file is open. Otherwise this is NULL.
746 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
749 /* Section info for this file. */
750 struct dwo_sections sections;
752 /* The CU in the file.
753 We only support one because having more than one requires hacking the
754 dwo_name of each to match, which is highly unlikely to happen.
755 Doing this means all TUs can share comp_dir: We also assume that
756 DW_AT_comp_dir across all TUs in a DWO file will be identical. */
759 /* Table of TUs in the file.
760 Each element is a struct dwo_unit. */
764 /* These sections are what may appear in a DWP file. */
768 struct dwarf2_section_info str;
769 struct dwarf2_section_info cu_index;
770 struct dwarf2_section_info tu_index;
771 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
772 by section number. We don't need to record them here. */
775 /* These sections are what may appear in a virtual DWO file. */
777 struct virtual_dwo_sections
779 struct dwarf2_section_info abbrev;
780 struct dwarf2_section_info line;
781 struct dwarf2_section_info loc;
782 struct dwarf2_section_info macinfo;
783 struct dwarf2_section_info macro;
784 struct dwarf2_section_info str_offsets;
785 /* Each DWP hash table entry records one CU or one TU.
786 That is recorded here, and copied to dwo_unit.section. */
787 struct dwarf2_section_info info_or_types;
790 /* Contents of DWP hash tables. */
792 struct dwp_hash_table
794 uint32_t nr_units, nr_slots;
795 const gdb_byte *hash_table, *unit_table, *section_pool;
798 /* Data for one DWP file. */
802 /* Name of the file. */
805 /* The bfd, when the file is open. Otherwise this is NULL. */
808 /* Section info for this file. */
809 struct dwp_sections sections;
811 /* Table of CUs in the file. */
812 const struct dwp_hash_table *cus;
814 /* Table of TUs in the file. */
815 const struct dwp_hash_table *tus;
817 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
820 /* Table to map ELF section numbers to their sections. */
821 unsigned int num_sections;
822 asection **elf_sections;
825 /* This represents a '.dwz' file. */
829 /* A dwz file can only contain a few sections. */
830 struct dwarf2_section_info abbrev;
831 struct dwarf2_section_info info;
832 struct dwarf2_section_info str;
833 struct dwarf2_section_info line;
834 struct dwarf2_section_info macro;
835 struct dwarf2_section_info gdb_index;
841 /* Struct used to pass misc. parameters to read_die_and_children, et
842 al. which are used for both .debug_info and .debug_types dies.
843 All parameters here are unchanging for the life of the call. This
844 struct exists to abstract away the constant parameters of die reading. */
846 struct die_reader_specs
848 /* die_section->asection->owner. */
851 /* The CU of the DIE we are parsing. */
852 struct dwarf2_cu *cu;
854 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
855 struct dwo_file *dwo_file;
857 /* The section the die comes from.
858 This is either .debug_info or .debug_types, or the .dwo variants. */
859 struct dwarf2_section_info *die_section;
861 /* die_section->buffer. */
862 const gdb_byte *buffer;
864 /* The end of the buffer. */
865 const gdb_byte *buffer_end;
868 /* Type of function passed to init_cutu_and_read_dies, et.al. */
869 typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader,
870 const gdb_byte *info_ptr,
871 struct die_info *comp_unit_die,
875 /* The line number information for a compilation unit (found in the
876 .debug_line section) begins with a "statement program header",
877 which contains the following information. */
880 unsigned int total_length;
881 unsigned short version;
882 unsigned int header_length;
883 unsigned char minimum_instruction_length;
884 unsigned char maximum_ops_per_instruction;
885 unsigned char default_is_stmt;
887 unsigned char line_range;
888 unsigned char opcode_base;
890 /* standard_opcode_lengths[i] is the number of operands for the
891 standard opcode whose value is i. This means that
892 standard_opcode_lengths[0] is unused, and the last meaningful
893 element is standard_opcode_lengths[opcode_base - 1]. */
894 unsigned char *standard_opcode_lengths;
896 /* The include_directories table. NOTE! These strings are not
897 allocated with xmalloc; instead, they are pointers into
898 debug_line_buffer. If you try to free them, `free' will get
900 unsigned int num_include_dirs, include_dirs_size;
901 const char **include_dirs;
903 /* The file_names table. NOTE! These strings are not allocated
904 with xmalloc; instead, they are pointers into debug_line_buffer.
905 Don't try to free them directly. */
906 unsigned int num_file_names, file_names_size;
910 unsigned int dir_index;
911 unsigned int mod_time;
913 int included_p; /* Non-zero if referenced by the Line Number Program. */
914 struct symtab *symtab; /* The associated symbol table, if any. */
917 /* The start and end of the statement program following this
918 header. These point into dwarf2_per_objfile->line_buffer. */
919 const gdb_byte *statement_program_start, *statement_program_end;
922 /* When we construct a partial symbol table entry we only
923 need this much information. */
924 struct partial_die_info
926 /* Offset of this DIE. */
929 /* DWARF-2 tag for this DIE. */
930 ENUM_BITFIELD(dwarf_tag) tag : 16;
932 /* Assorted flags describing the data found in this DIE. */
933 unsigned int has_children : 1;
934 unsigned int is_external : 1;
935 unsigned int is_declaration : 1;
936 unsigned int has_type : 1;
937 unsigned int has_specification : 1;
938 unsigned int has_pc_info : 1;
939 unsigned int may_be_inlined : 1;
941 /* Flag set if the SCOPE field of this structure has been
943 unsigned int scope_set : 1;
945 /* Flag set if the DIE has a byte_size attribute. */
946 unsigned int has_byte_size : 1;
948 /* Flag set if any of the DIE's children are template arguments. */
949 unsigned int has_template_arguments : 1;
951 /* Flag set if fixup_partial_die has been called on this die. */
952 unsigned int fixup_called : 1;
954 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
955 unsigned int is_dwz : 1;
957 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
958 unsigned int spec_is_dwz : 1;
960 /* The name of this DIE. Normally the value of DW_AT_name, but
961 sometimes a default name for unnamed DIEs. */
964 /* The linkage name, if present. */
965 const char *linkage_name;
967 /* The scope to prepend to our children. This is generally
968 allocated on the comp_unit_obstack, so will disappear
969 when this compilation unit leaves the cache. */
972 /* Some data associated with the partial DIE. The tag determines
973 which field is live. */
976 /* The location description associated with this DIE, if any. */
977 struct dwarf_block *locdesc;
978 /* The offset of an import, for DW_TAG_imported_unit. */
982 /* If HAS_PC_INFO, the PC range associated with this DIE. */
986 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
987 DW_AT_sibling, if any. */
988 /* NOTE: This member isn't strictly necessary, read_partial_die could
989 return DW_AT_sibling values to its caller load_partial_dies. */
990 const gdb_byte *sibling;
992 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
993 DW_AT_specification (or DW_AT_abstract_origin or
995 sect_offset spec_offset;
997 /* Pointers to this DIE's parent, first child, and next sibling,
999 struct partial_die_info *die_parent, *die_child, *die_sibling;
1002 /* This data structure holds the information of an abbrev. */
1005 unsigned int number; /* number identifying abbrev */
1006 enum dwarf_tag tag; /* dwarf tag */
1007 unsigned short has_children; /* boolean */
1008 unsigned short num_attrs; /* number of attributes */
1009 struct attr_abbrev *attrs; /* an array of attribute descriptions */
1010 struct abbrev_info *next; /* next in chain */
1015 ENUM_BITFIELD(dwarf_attribute) name : 16;
1016 ENUM_BITFIELD(dwarf_form) form : 16;
1019 /* Size of abbrev_table.abbrev_hash_table. */
1020 #define ABBREV_HASH_SIZE 121
1022 /* Top level data structure to contain an abbreviation table. */
1026 /* Where the abbrev table came from.
1027 This is used as a sanity check when the table is used. */
1030 /* Storage for the abbrev table. */
1031 struct obstack abbrev_obstack;
1033 /* Hash table of abbrevs.
1034 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1035 It could be statically allocated, but the previous code didn't so we
1037 struct abbrev_info **abbrevs;
1040 /* Attributes have a name and a value. */
1043 ENUM_BITFIELD(dwarf_attribute) name : 16;
1044 ENUM_BITFIELD(dwarf_form) form : 15;
1046 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1047 field should be in u.str (existing only for DW_STRING) but it is kept
1048 here for better struct attribute alignment. */
1049 unsigned int string_is_canonical : 1;
1054 struct dwarf_block *blk;
1063 /* This data structure holds a complete die structure. */
1066 /* DWARF-2 tag for this DIE. */
1067 ENUM_BITFIELD(dwarf_tag) tag : 16;
1069 /* Number of attributes */
1070 unsigned char num_attrs;
1072 /* True if we're presently building the full type name for the
1073 type derived from this DIE. */
1074 unsigned char building_fullname : 1;
1077 unsigned int abbrev;
1079 /* Offset in .debug_info or .debug_types section. */
1082 /* The dies in a compilation unit form an n-ary tree. PARENT
1083 points to this die's parent; CHILD points to the first child of
1084 this node; and all the children of a given node are chained
1085 together via their SIBLING fields. */
1086 struct die_info *child; /* Its first child, if any. */
1087 struct die_info *sibling; /* Its next sibling, if any. */
1088 struct die_info *parent; /* Its parent, if any. */
1090 /* An array of attributes, with NUM_ATTRS elements. There may be
1091 zero, but it's not common and zero-sized arrays are not
1092 sufficiently portable C. */
1093 struct attribute attrs[1];
1096 /* Get at parts of an attribute structure. */
1098 #define DW_STRING(attr) ((attr)->u.str)
1099 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1100 #define DW_UNSND(attr) ((attr)->u.unsnd)
1101 #define DW_BLOCK(attr) ((attr)->u.blk)
1102 #define DW_SND(attr) ((attr)->u.snd)
1103 #define DW_ADDR(attr) ((attr)->u.addr)
1104 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1106 /* Blocks are a bunch of untyped bytes. */
1111 /* Valid only if SIZE is not zero. */
1112 const gdb_byte *data;
1115 #ifndef ATTR_ALLOC_CHUNK
1116 #define ATTR_ALLOC_CHUNK 4
1119 /* Allocate fields for structs, unions and enums in this size. */
1120 #ifndef DW_FIELD_ALLOC_CHUNK
1121 #define DW_FIELD_ALLOC_CHUNK 4
1124 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1125 but this would require a corresponding change in unpack_field_as_long
1127 static int bits_per_byte = 8;
1129 /* The routines that read and process dies for a C struct or C++ class
1130 pass lists of data member fields and lists of member function fields
1131 in an instance of a field_info structure, as defined below. */
1134 /* List of data member and baseclasses fields. */
1137 struct nextfield *next;
1142 *fields, *baseclasses;
1144 /* Number of fields (including baseclasses). */
1147 /* Number of baseclasses. */
1150 /* Set if the accesibility of one of the fields is not public. */
1151 int non_public_fields;
1153 /* Member function fields array, entries are allocated in the order they
1154 are encountered in the object file. */
1157 struct nextfnfield *next;
1158 struct fn_field fnfield;
1162 /* Member function fieldlist array, contains name of possibly overloaded
1163 member function, number of overloaded member functions and a pointer
1164 to the head of the member function field chain. */
1169 struct nextfnfield *head;
1173 /* Number of entries in the fnfieldlists array. */
1176 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1177 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1178 struct typedef_field_list
1180 struct typedef_field field;
1181 struct typedef_field_list *next;
1183 *typedef_field_list;
1184 unsigned typedef_field_list_count;
1187 /* One item on the queue of compilation units to read in full symbols
1189 struct dwarf2_queue_item
1191 struct dwarf2_per_cu_data *per_cu;
1192 enum language pretend_language;
1193 struct dwarf2_queue_item *next;
1196 /* The current queue. */
1197 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
1199 /* Loaded secondary compilation units are kept in memory until they
1200 have not been referenced for the processing of this many
1201 compilation units. Set this to zero to disable caching. Cache
1202 sizes of up to at least twenty will improve startup time for
1203 typical inter-CU-reference binaries, at an obvious memory cost. */
1204 static int dwarf2_max_cache_age = 5;
1206 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
1207 struct cmd_list_element *c, const char *value)
1209 fprintf_filtered (file, _("The upper bound on the age of cached "
1210 "dwarf2 compilation units is %s.\n"),
1215 /* Various complaints about symbol reading that don't abort the process. */
1218 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1220 complaint (&symfile_complaints,
1221 _("statement list doesn't fit in .debug_line section"));
1225 dwarf2_debug_line_missing_file_complaint (void)
1227 complaint (&symfile_complaints,
1228 _(".debug_line section has line data without a file"));
1232 dwarf2_debug_line_missing_end_sequence_complaint (void)
1234 complaint (&symfile_complaints,
1235 _(".debug_line section has line "
1236 "program sequence without an end"));
1240 dwarf2_complex_location_expr_complaint (void)
1242 complaint (&symfile_complaints, _("location expression too complex"));
1246 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
1249 complaint (&symfile_complaints,
1250 _("const value length mismatch for '%s', got %d, expected %d"),
1255 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section)
1257 complaint (&symfile_complaints,
1258 _("debug info runs off end of %s section"
1260 section->asection->name,
1261 bfd_get_filename (section->asection->owner));
1265 dwarf2_macro_malformed_definition_complaint (const char *arg1)
1267 complaint (&symfile_complaints,
1268 _("macro debug info contains a "
1269 "malformed macro definition:\n`%s'"),
1274 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
1276 complaint (&symfile_complaints,
1277 _("invalid attribute class or form for '%s' in '%s'"),
1281 /* local function prototypes */
1283 static void dwarf2_locate_sections (bfd *, asection *, void *);
1285 static void dwarf2_find_base_address (struct die_info *die,
1286 struct dwarf2_cu *cu);
1288 static struct partial_symtab *create_partial_symtab
1289 (struct dwarf2_per_cu_data *per_cu, const char *name);
1291 static void dwarf2_build_psymtabs_hard (struct objfile *);
1293 static void scan_partial_symbols (struct partial_die_info *,
1294 CORE_ADDR *, CORE_ADDR *,
1295 int, struct dwarf2_cu *);
1297 static void add_partial_symbol (struct partial_die_info *,
1298 struct dwarf2_cu *);
1300 static void add_partial_namespace (struct partial_die_info *pdi,
1301 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1302 int need_pc, struct dwarf2_cu *cu);
1304 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
1305 CORE_ADDR *highpc, int need_pc,
1306 struct dwarf2_cu *cu);
1308 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
1309 struct dwarf2_cu *cu);
1311 static void add_partial_subprogram (struct partial_die_info *pdi,
1312 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1313 int need_pc, struct dwarf2_cu *cu);
1315 static void dwarf2_read_symtab (struct partial_symtab *,
1318 static void psymtab_to_symtab_1 (struct partial_symtab *);
1320 static struct abbrev_info *abbrev_table_lookup_abbrev
1321 (const struct abbrev_table *, unsigned int);
1323 static struct abbrev_table *abbrev_table_read_table
1324 (struct dwarf2_section_info *, sect_offset);
1326 static void abbrev_table_free (struct abbrev_table *);
1328 static void abbrev_table_free_cleanup (void *);
1330 static void dwarf2_read_abbrevs (struct dwarf2_cu *,
1331 struct dwarf2_section_info *);
1333 static void dwarf2_free_abbrev_table (void *);
1335 static unsigned int peek_abbrev_code (bfd *, const gdb_byte *);
1337 static struct partial_die_info *load_partial_dies
1338 (const struct die_reader_specs *, const gdb_byte *, int);
1340 static const gdb_byte *read_partial_die (const struct die_reader_specs *,
1341 struct partial_die_info *,
1342 struct abbrev_info *,
1346 static struct partial_die_info *find_partial_die (sect_offset, int,
1347 struct dwarf2_cu *);
1349 static void fixup_partial_die (struct partial_die_info *,
1350 struct dwarf2_cu *);
1352 static const gdb_byte *read_attribute (const struct die_reader_specs *,
1353 struct attribute *, struct attr_abbrev *,
1356 static unsigned int read_1_byte (bfd *, const gdb_byte *);
1358 static int read_1_signed_byte (bfd *, const gdb_byte *);
1360 static unsigned int read_2_bytes (bfd *, const gdb_byte *);
1362 static unsigned int read_4_bytes (bfd *, const gdb_byte *);
1364 static ULONGEST read_8_bytes (bfd *, const gdb_byte *);
1366 static CORE_ADDR read_address (bfd *, const gdb_byte *ptr, struct dwarf2_cu *,
1369 static LONGEST read_initial_length (bfd *, const gdb_byte *, unsigned int *);
1371 static LONGEST read_checked_initial_length_and_offset
1372 (bfd *, const gdb_byte *, const struct comp_unit_head *,
1373 unsigned int *, unsigned int *);
1375 static LONGEST read_offset (bfd *, const gdb_byte *,
1376 const struct comp_unit_head *,
1379 static LONGEST read_offset_1 (bfd *, const gdb_byte *, unsigned int);
1381 static sect_offset read_abbrev_offset (struct dwarf2_section_info *,
1384 static const gdb_byte *read_n_bytes (bfd *, const gdb_byte *, unsigned int);
1386 static const char *read_direct_string (bfd *, const gdb_byte *, unsigned int *);
1388 static const char *read_indirect_string (bfd *, const gdb_byte *,
1389 const struct comp_unit_head *,
1392 static const char *read_indirect_string_from_dwz (struct dwz_file *, LONGEST);
1394 static ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
1396 static LONGEST read_signed_leb128 (bfd *, const gdb_byte *, unsigned int *);
1398 static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *,
1402 static const char *read_str_index (const struct die_reader_specs *reader,
1403 struct dwarf2_cu *cu, ULONGEST str_index);
1405 static void set_cu_language (unsigned int, struct dwarf2_cu *);
1407 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
1408 struct dwarf2_cu *);
1410 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
1413 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
1414 struct dwarf2_cu *cu);
1416 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
1418 static struct die_info *die_specification (struct die_info *die,
1419 struct dwarf2_cu **);
1421 static void free_line_header (struct line_header *lh);
1423 static struct line_header *dwarf_decode_line_header (unsigned int offset,
1424 struct dwarf2_cu *cu);
1426 static void dwarf_decode_lines (struct line_header *, const char *,
1427 struct dwarf2_cu *, struct partial_symtab *,
1430 static void dwarf2_start_subfile (const char *, const char *, const char *);
1432 static void dwarf2_start_symtab (struct dwarf2_cu *,
1433 const char *, const char *, CORE_ADDR);
1435 static struct symbol *new_symbol (struct die_info *, struct type *,
1436 struct dwarf2_cu *);
1438 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1439 struct dwarf2_cu *, struct symbol *);
1441 static void dwarf2_const_value (struct attribute *, struct symbol *,
1442 struct dwarf2_cu *);
1444 static void dwarf2_const_value_attr (struct attribute *attr,
1447 struct obstack *obstack,
1448 struct dwarf2_cu *cu, LONGEST *value,
1449 const gdb_byte **bytes,
1450 struct dwarf2_locexpr_baton **baton);
1452 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1454 static int need_gnat_info (struct dwarf2_cu *);
1456 static struct type *die_descriptive_type (struct die_info *,
1457 struct dwarf2_cu *);
1459 static void set_descriptive_type (struct type *, struct die_info *,
1460 struct dwarf2_cu *);
1462 static struct type *die_containing_type (struct die_info *,
1463 struct dwarf2_cu *);
1465 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1466 struct dwarf2_cu *);
1468 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1470 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1472 static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1474 static char *typename_concat (struct obstack *obs, const char *prefix,
1475 const char *suffix, int physname,
1476 struct dwarf2_cu *cu);
1478 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1480 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1482 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1484 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1486 static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
1488 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1489 struct dwarf2_cu *, struct partial_symtab *);
1491 static int dwarf2_get_pc_bounds (struct die_info *,
1492 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1493 struct partial_symtab *);
1495 static void get_scope_pc_bounds (struct die_info *,
1496 CORE_ADDR *, CORE_ADDR *,
1497 struct dwarf2_cu *);
1499 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1500 CORE_ADDR, struct dwarf2_cu *);
1502 static void dwarf2_add_field (struct field_info *, struct die_info *,
1503 struct dwarf2_cu *);
1505 static void dwarf2_attach_fields_to_type (struct field_info *,
1506 struct type *, struct dwarf2_cu *);
1508 static void dwarf2_add_member_fn (struct field_info *,
1509 struct die_info *, struct type *,
1510 struct dwarf2_cu *);
1512 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1514 struct dwarf2_cu *);
1516 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1518 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1520 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1522 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1524 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1526 static struct type *read_module_type (struct die_info *die,
1527 struct dwarf2_cu *cu);
1529 static const char *namespace_name (struct die_info *die,
1530 int *is_anonymous, struct dwarf2_cu *);
1532 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1534 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1536 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1537 struct dwarf2_cu *);
1539 static struct die_info *read_die_and_siblings_1
1540 (const struct die_reader_specs *, const gdb_byte *, const gdb_byte **,
1543 static struct die_info *read_die_and_siblings (const struct die_reader_specs *,
1544 const gdb_byte *info_ptr,
1545 const gdb_byte **new_info_ptr,
1546 struct die_info *parent);
1548 static const gdb_byte *read_full_die_1 (const struct die_reader_specs *,
1549 struct die_info **, const gdb_byte *,
1552 static const gdb_byte *read_full_die (const struct die_reader_specs *,
1553 struct die_info **, const gdb_byte *,
1556 static void process_die (struct die_info *, struct dwarf2_cu *);
1558 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu *,
1561 static const char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1563 static const char *dwarf2_full_name (const char *name,
1564 struct die_info *die,
1565 struct dwarf2_cu *cu);
1567 static const char *dwarf2_physname (const char *name, struct die_info *die,
1568 struct dwarf2_cu *cu);
1570 static struct die_info *dwarf2_extension (struct die_info *die,
1571 struct dwarf2_cu **);
1573 static const char *dwarf_tag_name (unsigned int);
1575 static const char *dwarf_attr_name (unsigned int);
1577 static const char *dwarf_form_name (unsigned int);
1579 static char *dwarf_bool_name (unsigned int);
1581 static const char *dwarf_type_encoding_name (unsigned int);
1583 static struct die_info *sibling_die (struct die_info *);
1585 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1587 static void dump_die_for_error (struct die_info *);
1589 static void dump_die_1 (struct ui_file *, int level, int max_level,
1592 /*static*/ void dump_die (struct die_info *, int max_level);
1594 static void store_in_ref_table (struct die_info *,
1595 struct dwarf2_cu *);
1597 static int is_ref_attr (struct attribute *);
1599 static sect_offset dwarf2_get_ref_die_offset (struct attribute *);
1601 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1603 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1605 struct dwarf2_cu **);
1607 static struct die_info *follow_die_ref (struct die_info *,
1609 struct dwarf2_cu **);
1611 static struct die_info *follow_die_sig (struct die_info *,
1613 struct dwarf2_cu **);
1615 static struct type *get_signatured_type (struct die_info *, ULONGEST,
1616 struct dwarf2_cu *);
1618 static struct type *get_DW_AT_signature_type (struct die_info *,
1620 struct dwarf2_cu *);
1622 static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
1624 static void read_signatured_type (struct signatured_type *);
1626 static struct type_unit_group *get_type_unit_group
1627 (struct dwarf2_cu *, struct attribute *);
1629 static void build_type_unit_groups (die_reader_func_ftype *, void *);
1631 /* memory allocation interface */
1633 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1635 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1637 static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int,
1640 static int attr_form_is_block (struct attribute *);
1642 static int attr_form_is_section_offset (struct attribute *);
1644 static int attr_form_is_constant (struct attribute *);
1646 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1647 struct dwarf2_loclist_baton *baton,
1648 struct attribute *attr);
1650 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1652 struct dwarf2_cu *cu,
1655 static const gdb_byte *skip_one_die (const struct die_reader_specs *reader,
1656 const gdb_byte *info_ptr,
1657 struct abbrev_info *abbrev);
1659 static void free_stack_comp_unit (void *);
1661 static hashval_t partial_die_hash (const void *item);
1663 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1665 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1666 (sect_offset offset, unsigned int offset_in_dwz, struct objfile *objfile);
1668 static void init_one_comp_unit (struct dwarf2_cu *cu,
1669 struct dwarf2_per_cu_data *per_cu);
1671 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1672 struct die_info *comp_unit_die,
1673 enum language pretend_language);
1675 static void free_heap_comp_unit (void *);
1677 static void free_cached_comp_units (void *);
1679 static void age_cached_comp_units (void);
1681 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *);
1683 static struct type *set_die_type (struct die_info *, struct type *,
1684 struct dwarf2_cu *);
1686 static void create_all_comp_units (struct objfile *);
1688 static int create_all_type_units (struct objfile *);
1690 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1693 static void process_full_comp_unit (struct dwarf2_per_cu_data *,
1696 static void process_full_type_unit (struct dwarf2_per_cu_data *,
1699 static void dwarf2_add_dependence (struct dwarf2_cu *,
1700 struct dwarf2_per_cu_data *);
1702 static void dwarf2_mark (struct dwarf2_cu *);
1704 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1706 static struct type *get_die_type_at_offset (sect_offset,
1707 struct dwarf2_per_cu_data *);
1709 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1711 static void dwarf2_release_queue (void *dummy);
1713 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1714 enum language pretend_language);
1716 static int maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
1717 struct dwarf2_per_cu_data *per_cu,
1718 enum language pretend_language);
1720 static void process_queue (void);
1722 static void find_file_and_directory (struct die_info *die,
1723 struct dwarf2_cu *cu,
1724 const char **name, const char **comp_dir);
1726 static char *file_full_name (int file, struct line_header *lh,
1727 const char *comp_dir);
1729 static const gdb_byte *read_and_check_comp_unit_head
1730 (struct comp_unit_head *header,
1731 struct dwarf2_section_info *section,
1732 struct dwarf2_section_info *abbrev_section, const gdb_byte *info_ptr,
1733 int is_debug_types_section);
1735 static void init_cutu_and_read_dies
1736 (struct dwarf2_per_cu_data *this_cu, struct abbrev_table *abbrev_table,
1737 int use_existing_cu, int keep,
1738 die_reader_func_ftype *die_reader_func, void *data);
1740 static void init_cutu_and_read_dies_simple
1741 (struct dwarf2_per_cu_data *this_cu,
1742 die_reader_func_ftype *die_reader_func, void *data);
1744 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1746 static htab_t allocate_dwo_unit_table (struct objfile *objfile);
1748 static struct dwo_unit *lookup_dwo_comp_unit
1749 (struct dwarf2_per_cu_data *, const char *, const char *, ULONGEST);
1751 static struct dwo_unit *lookup_dwo_type_unit
1752 (struct signatured_type *, const char *, const char *);
1754 static void free_dwo_file_cleanup (void *);
1756 static void process_cu_includes (void);
1758 static void check_producer (struct dwarf2_cu *cu);
1762 /* Convert VALUE between big- and little-endian. */
1764 byte_swap (offset_type value)
1768 result = (value & 0xff) << 24;
1769 result |= (value & 0xff00) << 8;
1770 result |= (value & 0xff0000) >> 8;
1771 result |= (value & 0xff000000) >> 24;
1775 #define MAYBE_SWAP(V) byte_swap (V)
1778 #define MAYBE_SWAP(V) (V)
1779 #endif /* WORDS_BIGENDIAN */
1781 /* The suffix for an index file. */
1782 #define INDEX_SUFFIX ".gdb-index"
1784 /* Try to locate the sections we need for DWARF 2 debugging
1785 information and return true if we have enough to do something.
1786 NAMES points to the dwarf2 section names, or is NULL if the standard
1787 ELF names are used. */
1790 dwarf2_has_info (struct objfile *objfile,
1791 const struct dwarf2_debug_sections *names)
1793 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1794 if (!dwarf2_per_objfile)
1796 /* Initialize per-objfile state. */
1797 struct dwarf2_per_objfile *data
1798 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1800 memset (data, 0, sizeof (*data));
1801 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1802 dwarf2_per_objfile = data;
1804 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1806 dwarf2_per_objfile->objfile = objfile;
1808 return (dwarf2_per_objfile->info.asection != NULL
1809 && dwarf2_per_objfile->abbrev.asection != NULL);
1812 /* When loading sections, we look either for uncompressed section or for
1813 compressed section names. */
1816 section_is_p (const char *section_name,
1817 const struct dwarf2_section_names *names)
1819 if (names->normal != NULL
1820 && strcmp (section_name, names->normal) == 0)
1822 if (names->compressed != NULL
1823 && strcmp (section_name, names->compressed) == 0)
1828 /* This function is mapped across the sections and remembers the
1829 offset and size of each of the debugging sections we are interested
1833 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1835 const struct dwarf2_debug_sections *names;
1836 flagword aflag = bfd_get_section_flags (abfd, sectp);
1839 names = &dwarf2_elf_names;
1841 names = (const struct dwarf2_debug_sections *) vnames;
1843 if ((aflag & SEC_HAS_CONTENTS) == 0)
1846 else if (section_is_p (sectp->name, &names->info))
1848 dwarf2_per_objfile->info.asection = sectp;
1849 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1851 else if (section_is_p (sectp->name, &names->abbrev))
1853 dwarf2_per_objfile->abbrev.asection = sectp;
1854 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1856 else if (section_is_p (sectp->name, &names->line))
1858 dwarf2_per_objfile->line.asection = sectp;
1859 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1861 else if (section_is_p (sectp->name, &names->loc))
1863 dwarf2_per_objfile->loc.asection = sectp;
1864 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1866 else if (section_is_p (sectp->name, &names->macinfo))
1868 dwarf2_per_objfile->macinfo.asection = sectp;
1869 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1871 else if (section_is_p (sectp->name, &names->macro))
1873 dwarf2_per_objfile->macro.asection = sectp;
1874 dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
1876 else if (section_is_p (sectp->name, &names->str))
1878 dwarf2_per_objfile->str.asection = sectp;
1879 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1881 else if (section_is_p (sectp->name, &names->addr))
1883 dwarf2_per_objfile->addr.asection = sectp;
1884 dwarf2_per_objfile->addr.size = bfd_get_section_size (sectp);
1886 else if (section_is_p (sectp->name, &names->frame))
1888 dwarf2_per_objfile->frame.asection = sectp;
1889 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1891 else if (section_is_p (sectp->name, &names->eh_frame))
1893 dwarf2_per_objfile->eh_frame.asection = sectp;
1894 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1896 else if (section_is_p (sectp->name, &names->ranges))
1898 dwarf2_per_objfile->ranges.asection = sectp;
1899 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1901 else if (section_is_p (sectp->name, &names->types))
1903 struct dwarf2_section_info type_section;
1905 memset (&type_section, 0, sizeof (type_section));
1906 type_section.asection = sectp;
1907 type_section.size = bfd_get_section_size (sectp);
1909 VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
1912 else if (section_is_p (sectp->name, &names->gdb_index))
1914 dwarf2_per_objfile->gdb_index.asection = sectp;
1915 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1918 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1919 && bfd_section_vma (abfd, sectp) == 0)
1920 dwarf2_per_objfile->has_section_at_zero = 1;
1923 /* A helper function that decides whether a section is empty,
1927 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1929 return info->asection == NULL || info->size == 0;
1932 /* Read the contents of the section INFO.
1933 OBJFILE is the main object file, but not necessarily the file where
1934 the section comes from. E.g., for DWO files INFO->asection->owner
1935 is the bfd of the DWO file.
1936 If the section is compressed, uncompress it before returning. */
1939 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1941 asection *sectp = info->asection;
1943 gdb_byte *buf, *retbuf;
1944 unsigned char header[4];
1948 info->buffer = NULL;
1951 if (dwarf2_section_empty_p (info))
1954 abfd = sectp->owner;
1956 /* If the section has relocations, we must read it ourselves.
1957 Otherwise we attach it to the BFD. */
1958 if ((sectp->flags & SEC_RELOC) == 0)
1960 info->buffer = gdb_bfd_map_section (sectp, &info->size);
1964 buf = obstack_alloc (&objfile->objfile_obstack, info->size);
1967 /* When debugging .o files, we may need to apply relocations; see
1968 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1969 We never compress sections in .o files, so we only need to
1970 try this when the section is not compressed. */
1971 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1974 info->buffer = retbuf;
1978 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1979 || bfd_bread (buf, info->size, abfd) != info->size)
1980 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1981 bfd_get_filename (abfd));
1984 /* A helper function that returns the size of a section in a safe way.
1985 If you are positive that the section has been read before using the
1986 size, then it is safe to refer to the dwarf2_section_info object's
1987 "size" field directly. In other cases, you must call this
1988 function, because for compressed sections the size field is not set
1989 correctly until the section has been read. */
1991 static bfd_size_type
1992 dwarf2_section_size (struct objfile *objfile,
1993 struct dwarf2_section_info *info)
1996 dwarf2_read_section (objfile, info);
2000 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2004 dwarf2_get_section_info (struct objfile *objfile,
2005 enum dwarf2_section_enum sect,
2006 asection **sectp, const gdb_byte **bufp,
2007 bfd_size_type *sizep)
2009 struct dwarf2_per_objfile *data
2010 = objfile_data (objfile, dwarf2_objfile_data_key);
2011 struct dwarf2_section_info *info;
2013 /* We may see an objfile without any DWARF, in which case we just
2024 case DWARF2_DEBUG_FRAME:
2025 info = &data->frame;
2027 case DWARF2_EH_FRAME:
2028 info = &data->eh_frame;
2031 gdb_assert_not_reached ("unexpected section");
2034 dwarf2_read_section (objfile, info);
2036 *sectp = info->asection;
2037 *bufp = info->buffer;
2038 *sizep = info->size;
2041 /* A helper function to find the sections for a .dwz file. */
2044 locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
2046 struct dwz_file *dwz_file = arg;
2048 /* Note that we only support the standard ELF names, because .dwz
2049 is ELF-only (at the time of writing). */
2050 if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev))
2052 dwz_file->abbrev.asection = sectp;
2053 dwz_file->abbrev.size = bfd_get_section_size (sectp);
2055 else if (section_is_p (sectp->name, &dwarf2_elf_names.info))
2057 dwz_file->info.asection = sectp;
2058 dwz_file->info.size = bfd_get_section_size (sectp);
2060 else if (section_is_p (sectp->name, &dwarf2_elf_names.str))
2062 dwz_file->str.asection = sectp;
2063 dwz_file->str.size = bfd_get_section_size (sectp);
2065 else if (section_is_p (sectp->name, &dwarf2_elf_names.line))
2067 dwz_file->line.asection = sectp;
2068 dwz_file->line.size = bfd_get_section_size (sectp);
2070 else if (section_is_p (sectp->name, &dwarf2_elf_names.macro))
2072 dwz_file->macro.asection = sectp;
2073 dwz_file->macro.size = bfd_get_section_size (sectp);
2075 else if (section_is_p (sectp->name, &dwarf2_elf_names.gdb_index))
2077 dwz_file->gdb_index.asection = sectp;
2078 dwz_file->gdb_index.size = bfd_get_section_size (sectp);
2082 /* Open the separate '.dwz' debug file, if needed. Error if the file
2085 static struct dwz_file *
2086 dwarf2_get_dwz_file (void)
2088 bfd *abfd, *dwz_bfd;
2091 struct cleanup *cleanup;
2092 const char *filename;
2093 struct dwz_file *result;
2095 if (dwarf2_per_objfile->dwz_file != NULL)
2096 return dwarf2_per_objfile->dwz_file;
2098 abfd = dwarf2_per_objfile->objfile->obfd;
2099 section = bfd_get_section_by_name (abfd, ".gnu_debugaltlink");
2100 if (section == NULL)
2101 error (_("could not find '.gnu_debugaltlink' section"));
2102 if (!bfd_malloc_and_get_section (abfd, section, &data))
2103 error (_("could not read '.gnu_debugaltlink' section: %s"),
2104 bfd_errmsg (bfd_get_error ()));
2105 cleanup = make_cleanup (xfree, data);
2107 filename = (const char *) data;
2108 if (!IS_ABSOLUTE_PATH (filename))
2110 char *abs = gdb_realpath (dwarf2_per_objfile->objfile->name);
2113 make_cleanup (xfree, abs);
2114 abs = ldirname (abs);
2115 make_cleanup (xfree, abs);
2117 rel = concat (abs, SLASH_STRING, filename, (char *) NULL);
2118 make_cleanup (xfree, rel);
2122 /* The format is just a NUL-terminated file name, followed by the
2123 build-id. For now, though, we ignore the build-id. */
2124 dwz_bfd = gdb_bfd_open (filename, gnutarget, -1);
2125 if (dwz_bfd == NULL)
2126 error (_("could not read '%s': %s"), filename,
2127 bfd_errmsg (bfd_get_error ()));
2129 if (!bfd_check_format (dwz_bfd, bfd_object))
2131 gdb_bfd_unref (dwz_bfd);
2132 error (_("file '%s' was not usable: %s"), filename,
2133 bfd_errmsg (bfd_get_error ()));
2136 result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack,
2138 result->dwz_bfd = dwz_bfd;
2140 bfd_map_over_sections (dwz_bfd, locate_dwz_sections, result);
2142 do_cleanups (cleanup);
2144 dwarf2_per_objfile->dwz_file = result;
2148 /* DWARF quick_symbols_functions support. */
2150 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2151 unique line tables, so we maintain a separate table of all .debug_line
2152 derived entries to support the sharing.
2153 All the quick functions need is the list of file names. We discard the
2154 line_header when we're done and don't need to record it here. */
2155 struct quick_file_names
2157 /* The data used to construct the hash key. */
2158 struct stmt_list_hash hash;
2160 /* The number of entries in file_names, real_names. */
2161 unsigned int num_file_names;
2163 /* The file names from the line table, after being run through
2165 const char **file_names;
2167 /* The file names from the line table after being run through
2168 gdb_realpath. These are computed lazily. */
2169 const char **real_names;
2172 /* When using the index (and thus not using psymtabs), each CU has an
2173 object of this type. This is used to hold information needed by
2174 the various "quick" methods. */
2175 struct dwarf2_per_cu_quick_data
2177 /* The file table. This can be NULL if there was no file table
2178 or it's currently not read in.
2179 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2180 struct quick_file_names *file_names;
2182 /* The corresponding symbol table. This is NULL if symbols for this
2183 CU have not yet been read. */
2184 struct symtab *symtab;
2186 /* A temporary mark bit used when iterating over all CUs in
2187 expand_symtabs_matching. */
2188 unsigned int mark : 1;
2190 /* True if we've tried to read the file table and found there isn't one.
2191 There will be no point in trying to read it again next time. */
2192 unsigned int no_file_data : 1;
2195 /* Utility hash function for a stmt_list_hash. */
2198 hash_stmt_list_entry (const struct stmt_list_hash *stmt_list_hash)
2202 if (stmt_list_hash->dwo_unit != NULL)
2203 v += (uintptr_t) stmt_list_hash->dwo_unit->dwo_file;
2204 v += stmt_list_hash->line_offset.sect_off;
2208 /* Utility equality function for a stmt_list_hash. */
2211 eq_stmt_list_entry (const struct stmt_list_hash *lhs,
2212 const struct stmt_list_hash *rhs)
2214 if ((lhs->dwo_unit != NULL) != (rhs->dwo_unit != NULL))
2216 if (lhs->dwo_unit != NULL
2217 && lhs->dwo_unit->dwo_file != rhs->dwo_unit->dwo_file)
2220 return lhs->line_offset.sect_off == rhs->line_offset.sect_off;
2223 /* Hash function for a quick_file_names. */
2226 hash_file_name_entry (const void *e)
2228 const struct quick_file_names *file_data = e;
2230 return hash_stmt_list_entry (&file_data->hash);
2233 /* Equality function for a quick_file_names. */
2236 eq_file_name_entry (const void *a, const void *b)
2238 const struct quick_file_names *ea = a;
2239 const struct quick_file_names *eb = b;
2241 return eq_stmt_list_entry (&ea->hash, &eb->hash);
2244 /* Delete function for a quick_file_names. */
2247 delete_file_name_entry (void *e)
2249 struct quick_file_names *file_data = e;
2252 for (i = 0; i < file_data->num_file_names; ++i)
2254 xfree ((void*) file_data->file_names[i]);
2255 if (file_data->real_names)
2256 xfree ((void*) file_data->real_names[i]);
2259 /* The space for the struct itself lives on objfile_obstack,
2260 so we don't free it here. */
2263 /* Create a quick_file_names hash table. */
2266 create_quick_file_names_table (unsigned int nr_initial_entries)
2268 return htab_create_alloc (nr_initial_entries,
2269 hash_file_name_entry, eq_file_name_entry,
2270 delete_file_name_entry, xcalloc, xfree);
2273 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2274 have to be created afterwards. You should call age_cached_comp_units after
2275 processing PER_CU->CU. dw2_setup must have been already called. */
2278 load_cu (struct dwarf2_per_cu_data *per_cu)
2280 if (per_cu->is_debug_types)
2281 load_full_type_unit (per_cu);
2283 load_full_comp_unit (per_cu, language_minimal);
2285 gdb_assert (per_cu->cu != NULL);
2287 dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
2290 /* Read in the symbols for PER_CU. */
2293 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
2295 struct cleanup *back_to;
2297 /* Skip type_unit_groups, reading the type units they contain
2298 is handled elsewhere. */
2299 if (IS_TYPE_UNIT_GROUP (per_cu))
2302 back_to = make_cleanup (dwarf2_release_queue, NULL);
2304 if (dwarf2_per_objfile->using_index
2305 ? per_cu->v.quick->symtab == NULL
2306 : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin))
2308 queue_comp_unit (per_cu, language_minimal);
2314 /* Age the cache, releasing compilation units that have not
2315 been used recently. */
2316 age_cached_comp_units ();
2318 do_cleanups (back_to);
2321 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2322 the objfile from which this CU came. Returns the resulting symbol
2325 static struct symtab *
2326 dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
2328 gdb_assert (dwarf2_per_objfile->using_index);
2329 if (!per_cu->v.quick->symtab)
2331 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
2332 increment_reading_symtab ();
2333 dw2_do_instantiate_symtab (per_cu);
2334 process_cu_includes ();
2335 do_cleanups (back_to);
2337 return per_cu->v.quick->symtab;
2340 /* Return the CU given its index.
2342 This is intended for loops like:
2344 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2345 + dwarf2_per_objfile->n_type_units); ++i)
2347 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2353 static struct dwarf2_per_cu_data *
2354 dw2_get_cu (int index)
2356 if (index >= dwarf2_per_objfile->n_comp_units)
2358 index -= dwarf2_per_objfile->n_comp_units;
2359 gdb_assert (index < dwarf2_per_objfile->n_type_units);
2360 return &dwarf2_per_objfile->all_type_units[index]->per_cu;
2363 return dwarf2_per_objfile->all_comp_units[index];
2366 /* Return the primary CU given its index.
2367 The difference between this function and dw2_get_cu is in the handling
2368 of type units (TUs). Here we return the type_unit_group object.
2370 This is intended for loops like:
2372 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2373 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2375 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2381 static struct dwarf2_per_cu_data *
2382 dw2_get_primary_cu (int index)
2384 if (index >= dwarf2_per_objfile->n_comp_units)
2386 index -= dwarf2_per_objfile->n_comp_units;
2387 gdb_assert (index < dwarf2_per_objfile->n_type_unit_groups);
2388 return &dwarf2_per_objfile->all_type_unit_groups[index]->per_cu;
2391 return dwarf2_per_objfile->all_comp_units[index];
2394 /* A helper for create_cus_from_index that handles a given list of
2398 create_cus_from_index_list (struct objfile *objfile,
2399 const gdb_byte *cu_list, offset_type n_elements,
2400 struct dwarf2_section_info *section,
2406 for (i = 0; i < n_elements; i += 2)
2408 struct dwarf2_per_cu_data *the_cu;
2409 ULONGEST offset, length;
2411 gdb_static_assert (sizeof (ULONGEST) >= 8);
2412 offset = extract_unsigned_integer (cu_list, 8, BFD_ENDIAN_LITTLE);
2413 length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE);
2416 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2417 struct dwarf2_per_cu_data);
2418 the_cu->offset.sect_off = offset;
2419 the_cu->length = length;
2420 the_cu->objfile = objfile;
2421 the_cu->section = section;
2422 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2423 struct dwarf2_per_cu_quick_data);
2424 the_cu->is_dwz = is_dwz;
2425 dwarf2_per_objfile->all_comp_units[base_offset + i / 2] = the_cu;
2429 /* Read the CU list from the mapped index, and use it to create all
2430 the CU objects for this objfile. */
2433 create_cus_from_index (struct objfile *objfile,
2434 const gdb_byte *cu_list, offset_type cu_list_elements,
2435 const gdb_byte *dwz_list, offset_type dwz_elements)
2437 struct dwz_file *dwz;
2439 dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2;
2440 dwarf2_per_objfile->all_comp_units
2441 = obstack_alloc (&objfile->objfile_obstack,
2442 dwarf2_per_objfile->n_comp_units
2443 * sizeof (struct dwarf2_per_cu_data *));
2445 create_cus_from_index_list (objfile, cu_list, cu_list_elements,
2446 &dwarf2_per_objfile->info, 0, 0);
2448 if (dwz_elements == 0)
2451 dwz = dwarf2_get_dwz_file ();
2452 create_cus_from_index_list (objfile, dwz_list, dwz_elements, &dwz->info, 1,
2453 cu_list_elements / 2);
2456 /* Create the signatured type hash table from the index. */
2459 create_signatured_type_table_from_index (struct objfile *objfile,
2460 struct dwarf2_section_info *section,
2461 const gdb_byte *bytes,
2462 offset_type elements)
2465 htab_t sig_types_hash;
2467 dwarf2_per_objfile->n_type_units = elements / 3;
2468 dwarf2_per_objfile->all_type_units
2469 = obstack_alloc (&objfile->objfile_obstack,
2470 dwarf2_per_objfile->n_type_units
2471 * sizeof (struct signatured_type *));
2473 sig_types_hash = allocate_signatured_type_table (objfile);
2475 for (i = 0; i < elements; i += 3)
2477 struct signatured_type *sig_type;
2478 ULONGEST offset, type_offset_in_tu, signature;
2481 gdb_static_assert (sizeof (ULONGEST) >= 8);
2482 offset = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
2483 type_offset_in_tu = extract_unsigned_integer (bytes + 8, 8,
2485 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
2488 sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2489 struct signatured_type);
2490 sig_type->signature = signature;
2491 sig_type->type_offset_in_tu.cu_off = type_offset_in_tu;
2492 sig_type->per_cu.is_debug_types = 1;
2493 sig_type->per_cu.section = section;
2494 sig_type->per_cu.offset.sect_off = offset;
2495 sig_type->per_cu.objfile = objfile;
2496 sig_type->per_cu.v.quick
2497 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2498 struct dwarf2_per_cu_quick_data);
2500 slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
2503 dwarf2_per_objfile->all_type_units[i / 3] = sig_type;
2506 dwarf2_per_objfile->signatured_types = sig_types_hash;
2509 /* Read the address map data from the mapped index, and use it to
2510 populate the objfile's psymtabs_addrmap. */
2513 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
2515 const gdb_byte *iter, *end;
2516 struct obstack temp_obstack;
2517 struct addrmap *mutable_map;
2518 struct cleanup *cleanup;
2521 obstack_init (&temp_obstack);
2522 cleanup = make_cleanup_obstack_free (&temp_obstack);
2523 mutable_map = addrmap_create_mutable (&temp_obstack);
2525 iter = index->address_table;
2526 end = iter + index->address_table_size;
2528 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2532 ULONGEST hi, lo, cu_index;
2533 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2535 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2537 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
2540 if (cu_index < dwarf2_per_objfile->n_comp_units)
2542 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
2543 dw2_get_cu (cu_index));
2547 complaint (&symfile_complaints,
2548 _(".gdb_index address table has invalid CU number %u"),
2549 (unsigned) cu_index);
2553 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
2554 &objfile->objfile_obstack);
2555 do_cleanups (cleanup);
2558 /* The hash function for strings in the mapped index. This is the same as
2559 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2560 implementation. This is necessary because the hash function is tied to the
2561 format of the mapped index file. The hash values do not have to match with
2564 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2567 mapped_index_string_hash (int index_version, const void *p)
2569 const unsigned char *str = (const unsigned char *) p;
2573 while ((c = *str++) != 0)
2575 if (index_version >= 5)
2577 r = r * 67 + c - 113;
2583 /* Find a slot in the mapped index INDEX for the object named NAME.
2584 If NAME is found, set *VEC_OUT to point to the CU vector in the
2585 constant pool and return 1. If NAME cannot be found, return 0. */
2588 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2589 offset_type **vec_out)
2591 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2593 offset_type slot, step;
2594 int (*cmp) (const char *, const char *);
2596 if (current_language->la_language == language_cplus
2597 || current_language->la_language == language_java
2598 || current_language->la_language == language_fortran)
2600 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2602 const char *paren = strchr (name, '(');
2608 dup = xmalloc (paren - name + 1);
2609 memcpy (dup, name, paren - name);
2610 dup[paren - name] = 0;
2612 make_cleanup (xfree, dup);
2617 /* Index version 4 did not support case insensitive searches. But the
2618 indices for case insensitive languages are built in lowercase, therefore
2619 simulate our NAME being searched is also lowercased. */
2620 hash = mapped_index_string_hash ((index->version == 4
2621 && case_sensitivity == case_sensitive_off
2622 ? 5 : index->version),
2625 slot = hash & (index->symbol_table_slots - 1);
2626 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2627 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2631 /* Convert a slot number to an offset into the table. */
2632 offset_type i = 2 * slot;
2634 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2636 do_cleanups (back_to);
2640 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2641 if (!cmp (name, str))
2643 *vec_out = (offset_type *) (index->constant_pool
2644 + MAYBE_SWAP (index->symbol_table[i + 1]));
2645 do_cleanups (back_to);
2649 slot = (slot + step) & (index->symbol_table_slots - 1);
2653 /* A helper function that reads the .gdb_index from SECTION and fills
2654 in MAP. FILENAME is the name of the file containing the section;
2655 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2656 ok to use deprecated sections.
2658 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2659 out parameters that are filled in with information about the CU and
2660 TU lists in the section.
2662 Returns 1 if all went well, 0 otherwise. */
2665 read_index_from_section (struct objfile *objfile,
2666 const char *filename,
2668 struct dwarf2_section_info *section,
2669 struct mapped_index *map,
2670 const gdb_byte **cu_list,
2671 offset_type *cu_list_elements,
2672 const gdb_byte **types_list,
2673 offset_type *types_list_elements)
2675 const gdb_byte *addr;
2676 offset_type version;
2677 offset_type *metadata;
2680 if (dwarf2_section_empty_p (section))
2683 /* Older elfutils strip versions could keep the section in the main
2684 executable while splitting it for the separate debug info file. */
2685 if ((bfd_get_file_flags (section->asection) & SEC_HAS_CONTENTS) == 0)
2688 dwarf2_read_section (objfile, section);
2690 addr = section->buffer;
2691 /* Version check. */
2692 version = MAYBE_SWAP (*(offset_type *) addr);
2693 /* Versions earlier than 3 emitted every copy of a psymbol. This
2694 causes the index to behave very poorly for certain requests. Version 3
2695 contained incomplete addrmap. So, it seems better to just ignore such
2699 static int warning_printed = 0;
2700 if (!warning_printed)
2702 warning (_("Skipping obsolete .gdb_index section in %s."),
2704 warning_printed = 1;
2708 /* Index version 4 uses a different hash function than index version
2711 Versions earlier than 6 did not emit psymbols for inlined
2712 functions. Using these files will cause GDB not to be able to
2713 set breakpoints on inlined functions by name, so we ignore these
2714 indices unless the user has done
2715 "set use-deprecated-index-sections on". */
2716 if (version < 6 && !deprecated_ok)
2718 static int warning_printed = 0;
2719 if (!warning_printed)
2722 Skipping deprecated .gdb_index section in %s.\n\
2723 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2724 to use the section anyway."),
2726 warning_printed = 1;
2730 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2731 of the TU (for symbols coming from TUs). It's just a performance bug, and
2732 we can't distinguish gdb-generated indices from gold-generated ones, so
2733 nothing to do here. */
2735 /* Indexes with higher version than the one supported by GDB may be no
2736 longer backward compatible. */
2740 map->version = version;
2741 map->total_size = section->size;
2743 metadata = (offset_type *) (addr + sizeof (offset_type));
2746 *cu_list = addr + MAYBE_SWAP (metadata[i]);
2747 *cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2751 *types_list = addr + MAYBE_SWAP (metadata[i]);
2752 *types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2753 - MAYBE_SWAP (metadata[i]))
2757 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2758 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2759 - MAYBE_SWAP (metadata[i]));
2762 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2763 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2764 - MAYBE_SWAP (metadata[i]))
2765 / (2 * sizeof (offset_type)));
2768 map->constant_pool = (char *) (addr + MAYBE_SWAP (metadata[i]));
2774 /* Read the index file. If everything went ok, initialize the "quick"
2775 elements of all the CUs and return 1. Otherwise, return 0. */
2778 dwarf2_read_index (struct objfile *objfile)
2780 struct mapped_index local_map, *map;
2781 const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
2782 offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
2784 if (!read_index_from_section (objfile, objfile->name,
2785 use_deprecated_index_sections,
2786 &dwarf2_per_objfile->gdb_index, &local_map,
2787 &cu_list, &cu_list_elements,
2788 &types_list, &types_list_elements))
2791 /* Don't use the index if it's empty. */
2792 if (local_map.symbol_table_slots == 0)
2795 /* If there is a .dwz file, read it so we can get its CU list as
2797 if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
2799 struct dwz_file *dwz = dwarf2_get_dwz_file ();
2800 struct mapped_index dwz_map;
2801 const gdb_byte *dwz_types_ignore;
2802 offset_type dwz_types_elements_ignore;
2804 if (!read_index_from_section (objfile, bfd_get_filename (dwz->dwz_bfd),
2806 &dwz->gdb_index, &dwz_map,
2807 &dwz_list, &dwz_list_elements,
2809 &dwz_types_elements_ignore))
2811 warning (_("could not read '.gdb_index' section from %s; skipping"),
2812 bfd_get_filename (dwz->dwz_bfd));
2817 create_cus_from_index (objfile, cu_list, cu_list_elements, dwz_list,
2820 if (types_list_elements)
2822 struct dwarf2_section_info *section;
2824 /* We can only handle a single .debug_types when we have an
2826 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
2829 section = VEC_index (dwarf2_section_info_def,
2830 dwarf2_per_objfile->types, 0);
2832 create_signatured_type_table_from_index (objfile, section, types_list,
2833 types_list_elements);
2836 create_addrmap_from_index (objfile, &local_map);
2838 map = obstack_alloc (&objfile->objfile_obstack, sizeof (struct mapped_index));
2841 dwarf2_per_objfile->index_table = map;
2842 dwarf2_per_objfile->using_index = 1;
2843 dwarf2_per_objfile->quick_file_names_table =
2844 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2849 /* A helper for the "quick" functions which sets the global
2850 dwarf2_per_objfile according to OBJFILE. */
2853 dw2_setup (struct objfile *objfile)
2855 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2856 gdb_assert (dwarf2_per_objfile);
2859 /* die_reader_func for dw2_get_file_names. */
2862 dw2_get_file_names_reader (const struct die_reader_specs *reader,
2863 const gdb_byte *info_ptr,
2864 struct die_info *comp_unit_die,
2868 struct dwarf2_cu *cu = reader->cu;
2869 struct dwarf2_per_cu_data *this_cu = cu->per_cu;
2870 struct objfile *objfile = dwarf2_per_objfile->objfile;
2871 struct dwarf2_per_cu_data *lh_cu;
2872 struct line_header *lh;
2873 struct attribute *attr;
2875 const char *name, *comp_dir;
2877 struct quick_file_names *qfn;
2878 unsigned int line_offset;
2880 gdb_assert (! this_cu->is_debug_types);
2882 /* Our callers never want to match partial units -- instead they
2883 will match the enclosing full CU. */
2884 if (comp_unit_die->tag == DW_TAG_partial_unit)
2886 this_cu->v.quick->no_file_data = 1;
2895 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu);
2898 struct quick_file_names find_entry;
2900 line_offset = DW_UNSND (attr);
2902 /* We may have already read in this line header (TU line header sharing).
2903 If we have we're done. */
2904 find_entry.hash.dwo_unit = cu->dwo_unit;
2905 find_entry.hash.line_offset.sect_off = line_offset;
2906 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2907 &find_entry, INSERT);
2910 lh_cu->v.quick->file_names = *slot;
2914 lh = dwarf_decode_line_header (line_offset, cu);
2918 lh_cu->v.quick->no_file_data = 1;
2922 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2923 qfn->hash.dwo_unit = cu->dwo_unit;
2924 qfn->hash.line_offset.sect_off = line_offset;
2925 gdb_assert (slot != NULL);
2928 find_file_and_directory (comp_unit_die, cu, &name, &comp_dir);
2930 qfn->num_file_names = lh->num_file_names;
2931 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2932 lh->num_file_names * sizeof (char *));
2933 for (i = 0; i < lh->num_file_names; ++i)
2934 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2935 qfn->real_names = NULL;
2937 free_line_header (lh);
2939 lh_cu->v.quick->file_names = qfn;
2942 /* A helper for the "quick" functions which attempts to read the line
2943 table for THIS_CU. */
2945 static struct quick_file_names *
2946 dw2_get_file_names (struct dwarf2_per_cu_data *this_cu)
2948 /* This should never be called for TUs. */
2949 gdb_assert (! this_cu->is_debug_types);
2950 /* Nor type unit groups. */
2951 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu));
2953 if (this_cu->v.quick->file_names != NULL)
2954 return this_cu->v.quick->file_names;
2955 /* If we know there is no line data, no point in looking again. */
2956 if (this_cu->v.quick->no_file_data)
2959 init_cutu_and_read_dies_simple (this_cu, dw2_get_file_names_reader, NULL);
2961 if (this_cu->v.quick->no_file_data)
2963 return this_cu->v.quick->file_names;
2966 /* A helper for the "quick" functions which computes and caches the
2967 real path for a given file name from the line table. */
2970 dw2_get_real_path (struct objfile *objfile,
2971 struct quick_file_names *qfn, int index)
2973 if (qfn->real_names == NULL)
2974 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
2975 qfn->num_file_names, sizeof (char *));
2977 if (qfn->real_names[index] == NULL)
2978 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
2980 return qfn->real_names[index];
2983 static struct symtab *
2984 dw2_find_last_source_symtab (struct objfile *objfile)
2988 dw2_setup (objfile);
2989 index = dwarf2_per_objfile->n_comp_units - 1;
2990 return dw2_instantiate_symtab (dw2_get_cu (index));
2993 /* Traversal function for dw2_forget_cached_source_info. */
2996 dw2_free_cached_file_names (void **slot, void *info)
2998 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
3000 if (file_data->real_names)
3004 for (i = 0; i < file_data->num_file_names; ++i)
3006 xfree ((void*) file_data->real_names[i]);
3007 file_data->real_names[i] = NULL;
3015 dw2_forget_cached_source_info (struct objfile *objfile)
3017 dw2_setup (objfile);
3019 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
3020 dw2_free_cached_file_names, NULL);
3023 /* Helper function for dw2_map_symtabs_matching_filename that expands
3024 the symtabs and calls the iterator. */
3027 dw2_map_expand_apply (struct objfile *objfile,
3028 struct dwarf2_per_cu_data *per_cu,
3029 const char *name, const char *real_path,
3030 int (*callback) (struct symtab *, void *),
3033 struct symtab *last_made = objfile->symtabs;
3035 /* Don't visit already-expanded CUs. */
3036 if (per_cu->v.quick->symtab)
3039 /* This may expand more than one symtab, and we want to iterate over
3041 dw2_instantiate_symtab (per_cu);
3043 return iterate_over_some_symtabs (name, real_path, callback, data,
3044 objfile->symtabs, last_made);
3047 /* Implementation of the map_symtabs_matching_filename method. */
3050 dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
3051 const char *real_path,
3052 int (*callback) (struct symtab *, void *),
3056 const char *name_basename = lbasename (name);
3058 dw2_setup (objfile);
3060 /* The rule is CUs specify all the files, including those used by
3061 any TU, so there's no need to scan TUs here. */
3063 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3066 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
3067 struct quick_file_names *file_data;
3069 /* We only need to look at symtabs not already expanded. */
3070 if (per_cu->v.quick->symtab)
3073 file_data = dw2_get_file_names (per_cu);
3074 if (file_data == NULL)
3077 for (j = 0; j < file_data->num_file_names; ++j)
3079 const char *this_name = file_data->file_names[j];
3080 const char *this_real_name;
3082 if (compare_filenames_for_search (this_name, name))
3084 if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
3090 /* Before we invoke realpath, which can get expensive when many
3091 files are involved, do a quick comparison of the basenames. */
3092 if (! basenames_may_differ
3093 && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
3096 this_real_name = dw2_get_real_path (objfile, file_data, j);
3097 if (compare_filenames_for_search (this_real_name, name))
3099 if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
3105 if (real_path != NULL)
3107 gdb_assert (IS_ABSOLUTE_PATH (real_path));
3108 gdb_assert (IS_ABSOLUTE_PATH (name));
3109 if (this_real_name != NULL
3110 && FILENAME_CMP (real_path, this_real_name) == 0)
3112 if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
3124 /* Struct used to manage iterating over all CUs looking for a symbol. */
3126 struct dw2_symtab_iterator
3128 /* The internalized form of .gdb_index. */
3129 struct mapped_index *index;
3130 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
3131 int want_specific_block;
3132 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
3133 Unused if !WANT_SPECIFIC_BLOCK. */
3135 /* The kind of symbol we're looking for. */
3137 /* The list of CUs from the index entry of the symbol,
3138 or NULL if not found. */
3140 /* The next element in VEC to look at. */
3142 /* The number of elements in VEC, or zero if there is no match. */
3146 /* Initialize the index symtab iterator ITER.
3147 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
3148 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
3151 dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
3152 struct mapped_index *index,
3153 int want_specific_block,
3158 iter->index = index;
3159 iter->want_specific_block = want_specific_block;
3160 iter->block_index = block_index;
3161 iter->domain = domain;
3164 if (find_slot_in_mapped_hash (index, name, &iter->vec))
3165 iter->length = MAYBE_SWAP (*iter->vec);
3173 /* Return the next matching CU or NULL if there are no more. */
3175 static struct dwarf2_per_cu_data *
3176 dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
3178 for ( ; iter->next < iter->length; ++iter->next)
3180 offset_type cu_index_and_attrs =
3181 MAYBE_SWAP (iter->vec[iter->next + 1]);
3182 offset_type cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs);
3183 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
3184 int want_static = iter->block_index != GLOBAL_BLOCK;
3185 /* This value is only valid for index versions >= 7. */
3186 int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs);
3187 gdb_index_symbol_kind symbol_kind =
3188 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs);
3189 /* Only check the symbol attributes if they're present.
3190 Indices prior to version 7 don't record them,
3191 and indices >= 7 may elide them for certain symbols
3192 (gold does this). */
3194 (iter->index->version >= 7
3195 && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
3197 /* Skip if already read in. */
3198 if (per_cu->v.quick->symtab)
3202 && iter->want_specific_block
3203 && want_static != is_static)
3206 /* Only check the symbol's kind if it has one. */
3209 switch (iter->domain)
3212 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE
3213 && symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION
3214 /* Some types are also in VAR_DOMAIN. */
3215 && symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3219 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3223 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
3238 static struct symtab *
3239 dw2_lookup_symbol (struct objfile *objfile, int block_index,
3240 const char *name, domain_enum domain)
3242 struct symtab *stab_best = NULL;
3243 struct mapped_index *index;
3245 dw2_setup (objfile);
3247 index = dwarf2_per_objfile->index_table;
3249 /* index is NULL if OBJF_READNOW. */
3252 struct dw2_symtab_iterator iter;
3253 struct dwarf2_per_cu_data *per_cu;
3255 dw2_symtab_iter_init (&iter, index, 1, block_index, domain, name);
3257 while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
3259 struct symbol *sym = NULL;
3260 struct symtab *stab = dw2_instantiate_symtab (per_cu);
3262 /* Some caution must be observed with overloaded functions
3263 and methods, since the index will not contain any overload
3264 information (but NAME might contain it). */
3267 struct blockvector *bv = BLOCKVECTOR (stab);
3268 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
3270 sym = lookup_block_symbol (block, name, domain);
3273 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
3275 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
3281 /* Keep looking through other CUs. */
3289 dw2_print_stats (struct objfile *objfile)
3291 int i, total, count;
3293 dw2_setup (objfile);
3294 total = dwarf2_per_objfile->n_comp_units + dwarf2_per_objfile->n_type_units;
3296 for (i = 0; i < total; ++i)
3298 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3300 if (!per_cu->v.quick->symtab)
3303 printf_filtered (_(" Number of read CUs: %d\n"), total - count);
3304 printf_filtered (_(" Number of unread CUs: %d\n"), count);
3308 dw2_dump (struct objfile *objfile)
3310 /* Nothing worth printing. */
3314 dw2_relocate (struct objfile *objfile,
3315 const struct section_offsets *new_offsets,
3316 const struct section_offsets *delta)
3318 /* There's nothing to relocate here. */
3322 dw2_expand_symtabs_for_function (struct objfile *objfile,
3323 const char *func_name)
3325 struct mapped_index *index;
3327 dw2_setup (objfile);
3329 index = dwarf2_per_objfile->index_table;
3331 /* index is NULL if OBJF_READNOW. */
3334 struct dw2_symtab_iterator iter;
3335 struct dwarf2_per_cu_data *per_cu;
3337 /* Note: It doesn't matter what we pass for block_index here. */
3338 dw2_symtab_iter_init (&iter, index, 0, GLOBAL_BLOCK, VAR_DOMAIN,
3341 while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
3342 dw2_instantiate_symtab (per_cu);
3347 dw2_expand_all_symtabs (struct objfile *objfile)
3351 dw2_setup (objfile);
3353 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3354 + dwarf2_per_objfile->n_type_units); ++i)
3356 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3358 dw2_instantiate_symtab (per_cu);
3363 dw2_expand_symtabs_with_fullname (struct objfile *objfile,
3364 const char *fullname)
3368 dw2_setup (objfile);
3370 /* We don't need to consider type units here.
3371 This is only called for examining code, e.g. expand_line_sal.
3372 There can be an order of magnitude (or more) more type units
3373 than comp units, and we avoid them if we can. */
3375 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3378 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3379 struct quick_file_names *file_data;
3381 /* We only need to look at symtabs not already expanded. */
3382 if (per_cu->v.quick->symtab)
3385 file_data = dw2_get_file_names (per_cu);
3386 if (file_data == NULL)
3389 for (j = 0; j < file_data->num_file_names; ++j)
3391 const char *this_fullname = file_data->file_names[j];
3393 if (filename_cmp (this_fullname, fullname) == 0)
3395 dw2_instantiate_symtab (per_cu);
3402 /* A helper function for dw2_find_symbol_file that finds the primary
3403 file name for a given CU. This is a die_reader_func. */
3406 dw2_get_primary_filename_reader (const struct die_reader_specs *reader,
3407 const gdb_byte *info_ptr,
3408 struct die_info *comp_unit_die,
3412 const char **result_ptr = data;
3413 struct dwarf2_cu *cu = reader->cu;
3414 struct attribute *attr;
3416 attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu);
3420 *result_ptr = DW_STRING (attr);
3424 dw2_find_symbol_file (struct objfile *objfile, const char *name)
3426 struct dwarf2_per_cu_data *per_cu;
3428 const char *filename;
3430 dw2_setup (objfile);
3432 /* index_table is NULL if OBJF_READNOW. */
3433 if (!dwarf2_per_objfile->index_table)
3437 ALL_OBJFILE_PRIMARY_SYMTABS (objfile, s)
3439 struct blockvector *bv = BLOCKVECTOR (s);
3440 const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
3441 struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
3445 /* Only file extension of returned filename is recognized. */
3446 return SYMBOL_SYMTAB (sym)->filename;
3452 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
3456 /* Note that this just looks at the very first one named NAME -- but
3457 actually we are looking for a function. find_main_filename
3458 should be rewritten so that it doesn't require a custom hook. It
3459 could just use the ordinary symbol tables. */
3460 /* vec[0] is the length, which must always be >0. */
3461 per_cu = dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec[1])));
3463 if (per_cu->v.quick->symtab != NULL)
3465 /* Only file extension of returned filename is recognized. */
3466 return per_cu->v.quick->symtab->filename;
3469 /* Initialize filename in case there's a problem reading the DWARF,
3470 dw2_get_primary_filename_reader may not get called. */
3472 init_cutu_and_read_dies (per_cu, NULL, 0, 0,
3473 dw2_get_primary_filename_reader, &filename);
3475 /* Only file extension of returned filename is recognized. */
3480 dw2_map_matching_symbols (const char * name, domain_enum namespace,
3481 struct objfile *objfile, int global,
3482 int (*callback) (struct block *,
3483 struct symbol *, void *),
3484 void *data, symbol_compare_ftype *match,
3485 symbol_compare_ftype *ordered_compare)
3487 /* Currently unimplemented; used for Ada. The function can be called if the
3488 current language is Ada for a non-Ada objfile using GNU index. As Ada
3489 does not look for non-Ada symbols this function should just return. */
3493 dw2_expand_symtabs_matching
3494 (struct objfile *objfile,
3495 int (*file_matcher) (const char *, void *, int basenames),
3496 int (*name_matcher) (const char *, void *),
3497 enum search_domain kind,
3502 struct mapped_index *index;
3504 dw2_setup (objfile);
3506 /* index_table is NULL if OBJF_READNOW. */
3507 if (!dwarf2_per_objfile->index_table)
3509 index = dwarf2_per_objfile->index_table;
3511 if (file_matcher != NULL)
3513 struct cleanup *cleanup;
3514 htab_t visited_found, visited_not_found;
3516 visited_found = htab_create_alloc (10,
3517 htab_hash_pointer, htab_eq_pointer,
3518 NULL, xcalloc, xfree);
3519 cleanup = make_cleanup_htab_delete (visited_found);
3520 visited_not_found = htab_create_alloc (10,
3521 htab_hash_pointer, htab_eq_pointer,
3522 NULL, xcalloc, xfree);
3523 make_cleanup_htab_delete (visited_not_found);
3525 /* The rule is CUs specify all the files, including those used by
3526 any TU, so there's no need to scan TUs here. */
3528 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3531 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
3532 struct quick_file_names *file_data;
3535 per_cu->v.quick->mark = 0;
3537 /* We only need to look at symtabs not already expanded. */
3538 if (per_cu->v.quick->symtab)
3541 file_data = dw2_get_file_names (per_cu);
3542 if (file_data == NULL)
3545 if (htab_find (visited_not_found, file_data) != NULL)
3547 else if (htab_find (visited_found, file_data) != NULL)
3549 per_cu->v.quick->mark = 1;
3553 for (j = 0; j < file_data->num_file_names; ++j)
3555 const char *this_real_name;
3557 if (file_matcher (file_data->file_names[j], data, 0))
3559 per_cu->v.quick->mark = 1;
3563 /* Before we invoke realpath, which can get expensive when many
3564 files are involved, do a quick comparison of the basenames. */
3565 if (!basenames_may_differ
3566 && !file_matcher (lbasename (file_data->file_names[j]),
3570 this_real_name = dw2_get_real_path (objfile, file_data, j);
3571 if (file_matcher (this_real_name, data, 0))
3573 per_cu->v.quick->mark = 1;
3578 slot = htab_find_slot (per_cu->v.quick->mark
3580 : visited_not_found,
3585 do_cleanups (cleanup);
3588 for (iter = 0; iter < index->symbol_table_slots; ++iter)
3590 offset_type idx = 2 * iter;
3592 offset_type *vec, vec_len, vec_idx;
3594 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
3597 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
3599 if (! (*name_matcher) (name, data))
3602 /* The name was matched, now expand corresponding CUs that were
3604 vec = (offset_type *) (index->constant_pool
3605 + MAYBE_SWAP (index->symbol_table[idx + 1]));
3606 vec_len = MAYBE_SWAP (vec[0]);
3607 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
3609 struct dwarf2_per_cu_data *per_cu;
3610 offset_type cu_index_and_attrs = MAYBE_SWAP (vec[vec_idx + 1]);
3611 gdb_index_symbol_kind symbol_kind =
3612 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs);
3613 int cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs);
3615 /* Don't crash on bad data. */
3616 if (cu_index >= (dwarf2_per_objfile->n_comp_units
3617 + dwarf2_per_objfile->n_type_units))
3620 /* Only check the symbol's kind if it has one.
3621 Indices prior to version 7 don't record it. */
3622 if (index->version >= 7)
3626 case VARIABLES_DOMAIN:
3627 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE)
3630 case FUNCTIONS_DOMAIN:
3631 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION)
3635 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3643 per_cu = dw2_get_cu (cu_index);
3644 if (file_matcher == NULL || per_cu->v.quick->mark)
3645 dw2_instantiate_symtab (per_cu);
3650 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3653 static struct symtab *
3654 recursively_find_pc_sect_symtab (struct symtab *symtab, CORE_ADDR pc)
3658 if (BLOCKVECTOR (symtab) != NULL
3659 && blockvector_contains_pc (BLOCKVECTOR (symtab), pc))
3662 if (symtab->includes == NULL)
3665 for (i = 0; symtab->includes[i]; ++i)
3667 struct symtab *s = symtab->includes[i];
3669 s = recursively_find_pc_sect_symtab (s, pc);
3677 static struct symtab *
3678 dw2_find_pc_sect_symtab (struct objfile *objfile,
3679 struct minimal_symbol *msymbol,
3681 struct obj_section *section,
3684 struct dwarf2_per_cu_data *data;
3685 struct symtab *result;
3687 dw2_setup (objfile);
3689 if (!objfile->psymtabs_addrmap)
3692 data = addrmap_find (objfile->psymtabs_addrmap, pc);
3696 if (warn_if_readin && data->v.quick->symtab)
3697 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3698 paddress (get_objfile_arch (objfile), pc));
3700 result = recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data), pc);
3701 gdb_assert (result != NULL);
3706 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
3707 void *data, int need_fullname)
3710 struct cleanup *cleanup;
3711 htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
3712 NULL, xcalloc, xfree);
3714 cleanup = make_cleanup_htab_delete (visited);
3715 dw2_setup (objfile);
3717 /* The rule is CUs specify all the files, including those used by
3718 any TU, so there's no need to scan TUs here.
3719 We can ignore file names coming from already-expanded CUs. */
3721 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3723 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3725 if (per_cu->v.quick->symtab)
3727 void **slot = htab_find_slot (visited, per_cu->v.quick->file_names,
3730 *slot = per_cu->v.quick->file_names;
3734 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3737 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
3738 struct quick_file_names *file_data;
3741 /* We only need to look at symtabs not already expanded. */
3742 if (per_cu->v.quick->symtab)
3745 file_data = dw2_get_file_names (per_cu);
3746 if (file_data == NULL)
3749 slot = htab_find_slot (visited, file_data, INSERT);
3752 /* Already visited. */
3757 for (j = 0; j < file_data->num_file_names; ++j)
3759 const char *this_real_name;
3762 this_real_name = dw2_get_real_path (objfile, file_data, j);
3764 this_real_name = NULL;
3765 (*fun) (file_data->file_names[j], this_real_name, data);
3769 do_cleanups (cleanup);
3773 dw2_has_symbols (struct objfile *objfile)
3778 const struct quick_symbol_functions dwarf2_gdb_index_functions =
3781 dw2_find_last_source_symtab,
3782 dw2_forget_cached_source_info,
3783 dw2_map_symtabs_matching_filename,
3788 dw2_expand_symtabs_for_function,
3789 dw2_expand_all_symtabs,
3790 dw2_expand_symtabs_with_fullname,
3791 dw2_find_symbol_file,
3792 dw2_map_matching_symbols,
3793 dw2_expand_symtabs_matching,
3794 dw2_find_pc_sect_symtab,
3795 dw2_map_symbol_filenames
3798 /* Initialize for reading DWARF for this objfile. Return 0 if this
3799 file will use psymtabs, or 1 if using the GNU index. */
3802 dwarf2_initialize_objfile (struct objfile *objfile)
3804 /* If we're about to read full symbols, don't bother with the
3805 indices. In this case we also don't care if some other debug
3806 format is making psymtabs, because they are all about to be
3808 if ((objfile->flags & OBJF_READNOW))
3812 dwarf2_per_objfile->using_index = 1;
3813 create_all_comp_units (objfile);
3814 create_all_type_units (objfile);
3815 dwarf2_per_objfile->quick_file_names_table =
3816 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
3818 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3819 + dwarf2_per_objfile->n_type_units); ++i)
3821 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3823 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
3824 struct dwarf2_per_cu_quick_data);
3827 /* Return 1 so that gdb sees the "quick" functions. However,
3828 these functions will be no-ops because we will have expanded
3833 if (dwarf2_read_index (objfile))
3841 /* Build a partial symbol table. */
3844 dwarf2_build_psymtabs (struct objfile *objfile)
3846 volatile struct gdb_exception except;
3848 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
3850 init_psymbol_list (objfile, 1024);
3853 TRY_CATCH (except, RETURN_MASK_ERROR)
3855 /* This isn't really ideal: all the data we allocate on the
3856 objfile's obstack is still uselessly kept around. However,
3857 freeing it seems unsafe. */
3858 struct cleanup *cleanups = make_cleanup_discard_psymtabs (objfile);
3860 dwarf2_build_psymtabs_hard (objfile);
3861 discard_cleanups (cleanups);
3863 if (except.reason < 0)
3864 exception_print (gdb_stderr, except);
3867 /* Return the total length of the CU described by HEADER. */
3870 get_cu_length (const struct comp_unit_head *header)
3872 return header->initial_length_size + header->length;
3875 /* Return TRUE if OFFSET is within CU_HEADER. */
3878 offset_in_cu_p (const struct comp_unit_head *cu_header, sect_offset offset)
3880 sect_offset bottom = { cu_header->offset.sect_off };
3881 sect_offset top = { cu_header->offset.sect_off + get_cu_length (cu_header) };
3883 return (offset.sect_off >= bottom.sect_off && offset.sect_off < top.sect_off);
3886 /* Find the base address of the compilation unit for range lists and
3887 location lists. It will normally be specified by DW_AT_low_pc.
3888 In DWARF-3 draft 4, the base address could be overridden by
3889 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3890 compilation units with discontinuous ranges. */
3893 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3895 struct attribute *attr;
3898 cu->base_address = 0;
3900 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3903 cu->base_address = DW_ADDR (attr);
3908 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3911 cu->base_address = DW_ADDR (attr);
3917 /* Read in the comp unit header information from the debug_info at info_ptr.
3918 NOTE: This leaves members offset, first_die_offset to be filled in
3921 static const gdb_byte *
3922 read_comp_unit_head (struct comp_unit_head *cu_header,
3923 const gdb_byte *info_ptr, bfd *abfd)
3926 unsigned int bytes_read;
3928 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
3929 cu_header->initial_length_size = bytes_read;
3930 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
3931 info_ptr += bytes_read;
3932 cu_header->version = read_2_bytes (abfd, info_ptr);
3934 cu_header->abbrev_offset.sect_off = read_offset (abfd, info_ptr, cu_header,
3936 info_ptr += bytes_read;
3937 cu_header->addr_size = read_1_byte (abfd, info_ptr);
3939 signed_addr = bfd_get_sign_extend_vma (abfd);
3940 if (signed_addr < 0)
3941 internal_error (__FILE__, __LINE__,
3942 _("read_comp_unit_head: dwarf from non elf file"));
3943 cu_header->signed_addr_p = signed_addr;
3948 /* Helper function that returns the proper abbrev section for
3951 static struct dwarf2_section_info *
3952 get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
3954 struct dwarf2_section_info *abbrev;
3956 if (this_cu->is_dwz)
3957 abbrev = &dwarf2_get_dwz_file ()->abbrev;
3959 abbrev = &dwarf2_per_objfile->abbrev;
3964 /* Subroutine of read_and_check_comp_unit_head and
3965 read_and_check_type_unit_head to simplify them.
3966 Perform various error checking on the header. */
3969 error_check_comp_unit_head (struct comp_unit_head *header,
3970 struct dwarf2_section_info *section,
3971 struct dwarf2_section_info *abbrev_section)
3973 bfd *abfd = section->asection->owner;
3974 const char *filename = bfd_get_filename (abfd);
3976 if (header->version != 2 && header->version != 3 && header->version != 4)
3977 error (_("Dwarf Error: wrong version in compilation unit header "
3978 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
3981 if (header->abbrev_offset.sect_off
3982 >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
3983 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3984 "(offset 0x%lx + 6) [in module %s]"),
3985 (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off,
3988 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3989 avoid potential 32-bit overflow. */
3990 if (((unsigned long) header->offset.sect_off + get_cu_length (header))
3992 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3993 "(offset 0x%lx + 0) [in module %s]"),
3994 (long) header->length, (long) header->offset.sect_off,
3998 /* Read in a CU/TU header and perform some basic error checking.
3999 The contents of the header are stored in HEADER.
4000 The result is a pointer to the start of the first DIE. */
4002 static const gdb_byte *
4003 read_and_check_comp_unit_head (struct comp_unit_head *header,
4004 struct dwarf2_section_info *section,
4005 struct dwarf2_section_info *abbrev_section,
4006 const gdb_byte *info_ptr,
4007 int is_debug_types_section)
4009 const gdb_byte *beg_of_comp_unit = info_ptr;
4010 bfd *abfd = section->asection->owner;
4012 header->offset.sect_off = beg_of_comp_unit - section->buffer;
4014 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
4016 /* If we're reading a type unit, skip over the signature and
4017 type_offset fields. */
4018 if (is_debug_types_section)
4019 info_ptr += 8 /*signature*/ + header->offset_size;
4021 header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit;
4023 error_check_comp_unit_head (header, section, abbrev_section);
4028 /* Read in the types comp unit header information from .debug_types entry at
4029 types_ptr. The result is a pointer to one past the end of the header. */
4031 static const gdb_byte *
4032 read_and_check_type_unit_head (struct comp_unit_head *header,
4033 struct dwarf2_section_info *section,
4034 struct dwarf2_section_info *abbrev_section,
4035 const gdb_byte *info_ptr,
4036 ULONGEST *signature,
4037 cu_offset *type_offset_in_tu)
4039 const gdb_byte *beg_of_comp_unit = info_ptr;
4040 bfd *abfd = section->asection->owner;
4042 header->offset.sect_off = beg_of_comp_unit - section->buffer;
4044 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
4046 /* If we're reading a type unit, skip over the signature and
4047 type_offset fields. */
4048 if (signature != NULL)
4049 *signature = read_8_bytes (abfd, info_ptr);
4051 if (type_offset_in_tu != NULL)
4052 type_offset_in_tu->cu_off = read_offset_1 (abfd, info_ptr,
4053 header->offset_size);
4054 info_ptr += header->offset_size;
4056 header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit;
4058 error_check_comp_unit_head (header, section, abbrev_section);
4063 /* Fetch the abbreviation table offset from a comp or type unit header. */
4066 read_abbrev_offset (struct dwarf2_section_info *section,
4069 bfd *abfd = section->asection->owner;
4070 const gdb_byte *info_ptr;
4071 unsigned int length, initial_length_size, offset_size;
4072 sect_offset abbrev_offset;
4074 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
4075 info_ptr = section->buffer + offset.sect_off;
4076 length = read_initial_length (abfd, info_ptr, &initial_length_size);
4077 offset_size = initial_length_size == 4 ? 4 : 8;
4078 info_ptr += initial_length_size + 2 /*version*/;
4079 abbrev_offset.sect_off = read_offset_1 (abfd, info_ptr, offset_size);
4080 return abbrev_offset;
4083 /* Allocate a new partial symtab for file named NAME and mark this new
4084 partial symtab as being an include of PST. */
4087 dwarf2_create_include_psymtab (const char *name, struct partial_symtab *pst,
4088 struct objfile *objfile)
4090 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
4092 if (!IS_ABSOLUTE_PATH (subpst->filename))
4094 /* It shares objfile->objfile_obstack. */
4095 subpst->dirname = pst->dirname;
4098 subpst->section_offsets = pst->section_offsets;
4099 subpst->textlow = 0;
4100 subpst->texthigh = 0;
4102 subpst->dependencies = (struct partial_symtab **)
4103 obstack_alloc (&objfile->objfile_obstack,
4104 sizeof (struct partial_symtab *));
4105 subpst->dependencies[0] = pst;
4106 subpst->number_of_dependencies = 1;
4108 subpst->globals_offset = 0;
4109 subpst->n_global_syms = 0;
4110 subpst->statics_offset = 0;
4111 subpst->n_static_syms = 0;
4112 subpst->symtab = NULL;
4113 subpst->read_symtab = pst->read_symtab;
4116 /* No private part is necessary for include psymtabs. This property
4117 can be used to differentiate between such include psymtabs and
4118 the regular ones. */
4119 subpst->read_symtab_private = NULL;
4122 /* Read the Line Number Program data and extract the list of files
4123 included by the source file represented by PST. Build an include
4124 partial symtab for each of these included files. */
4127 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
4128 struct die_info *die,
4129 struct partial_symtab *pst)
4131 struct line_header *lh = NULL;
4132 struct attribute *attr;
4134 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
4136 lh = dwarf_decode_line_header (DW_UNSND (attr), cu);
4138 return; /* No linetable, so no includes. */
4140 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4141 dwarf_decode_lines (lh, pst->dirname, cu, pst, 1);
4143 free_line_header (lh);
4147 hash_signatured_type (const void *item)
4149 const struct signatured_type *sig_type = item;
4151 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4152 return sig_type->signature;
4156 eq_signatured_type (const void *item_lhs, const void *item_rhs)
4158 const struct signatured_type *lhs = item_lhs;
4159 const struct signatured_type *rhs = item_rhs;
4161 return lhs->signature == rhs->signature;
4164 /* Allocate a hash table for signatured types. */
4167 allocate_signatured_type_table (struct objfile *objfile)
4169 return htab_create_alloc_ex (41,
4170 hash_signatured_type,
4173 &objfile->objfile_obstack,
4174 hashtab_obstack_allocate,
4175 dummy_obstack_deallocate);
4178 /* A helper function to add a signatured type CU to a table. */
4181 add_signatured_type_cu_to_table (void **slot, void *datum)
4183 struct signatured_type *sigt = *slot;
4184 struct signatured_type ***datap = datum;
4192 /* Create the hash table of all entries in the .debug_types
4193 (or .debug_types.dwo) section(s).
4194 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
4195 otherwise it is NULL.
4197 The result is a pointer to the hash table or NULL if there are no types.
4199 Note: This function processes DWO files only, not DWP files. */
4202 create_debug_types_hash_table (struct dwo_file *dwo_file,
4203 VEC (dwarf2_section_info_def) *types)
4205 struct objfile *objfile = dwarf2_per_objfile->objfile;
4206 htab_t types_htab = NULL;
4208 struct dwarf2_section_info *section;
4209 struct dwarf2_section_info *abbrev_section;
4211 if (VEC_empty (dwarf2_section_info_def, types))
4214 abbrev_section = (dwo_file != NULL
4215 ? &dwo_file->sections.abbrev
4216 : &dwarf2_per_objfile->abbrev);
4218 if (dwarf2_read_debug)
4219 fprintf_unfiltered (gdb_stdlog, "Reading .debug_types%s for %s:\n",
4220 dwo_file ? ".dwo" : "",
4221 bfd_get_filename (abbrev_section->asection->owner));
4224 VEC_iterate (dwarf2_section_info_def, types, ix, section);
4228 const gdb_byte *info_ptr, *end_ptr;
4229 struct dwarf2_section_info *abbrev_section;
4231 dwarf2_read_section (objfile, section);
4232 info_ptr = section->buffer;
4234 if (info_ptr == NULL)
4237 /* We can't set abfd until now because the section may be empty or
4238 not present, in which case section->asection will be NULL. */
4239 abfd = section->asection->owner;
4242 abbrev_section = &dwo_file->sections.abbrev;
4244 abbrev_section = &dwarf2_per_objfile->abbrev;
4246 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4247 because we don't need to read any dies: the signature is in the
4250 end_ptr = info_ptr + section->size;
4251 while (info_ptr < end_ptr)
4254 cu_offset type_offset_in_tu;
4256 struct signatured_type *sig_type;
4257 struct dwo_unit *dwo_tu;
4259 const gdb_byte *ptr = info_ptr;
4260 struct comp_unit_head header;
4261 unsigned int length;
4263 offset.sect_off = ptr - section->buffer;
4265 /* We need to read the type's signature in order to build the hash
4266 table, but we don't need anything else just yet. */
4268 ptr = read_and_check_type_unit_head (&header, section,
4269 abbrev_section, ptr,
4270 &signature, &type_offset_in_tu);
4272 length = get_cu_length (&header);
4274 /* Skip dummy type units. */
4275 if (ptr >= info_ptr + length
4276 || peek_abbrev_code (abfd, ptr) == 0)
4282 if (types_htab == NULL)
4285 types_htab = allocate_dwo_unit_table (objfile);
4287 types_htab = allocate_signatured_type_table (objfile);
4293 dwo_tu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
4295 dwo_tu->dwo_file = dwo_file;
4296 dwo_tu->signature = signature;
4297 dwo_tu->type_offset_in_tu = type_offset_in_tu;
4298 dwo_tu->section = section;
4299 dwo_tu->offset = offset;
4300 dwo_tu->length = length;
4304 /* N.B.: type_offset is not usable if this type uses a DWO file.
4305 The real type_offset is in the DWO file. */
4307 sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
4308 struct signatured_type);
4309 sig_type->signature = signature;
4310 sig_type->type_offset_in_tu = type_offset_in_tu;
4311 sig_type->per_cu.objfile = objfile;
4312 sig_type->per_cu.is_debug_types = 1;
4313 sig_type->per_cu.section = section;
4314 sig_type->per_cu.offset = offset;
4315 sig_type->per_cu.length = length;
4318 slot = htab_find_slot (types_htab,
4319 dwo_file ? (void*) dwo_tu : (void *) sig_type,
4321 gdb_assert (slot != NULL);
4324 sect_offset dup_offset;
4328 const struct dwo_unit *dup_tu = *slot;
4330 dup_offset = dup_tu->offset;
4334 const struct signatured_type *dup_tu = *slot;
4336 dup_offset = dup_tu->per_cu.offset;
4339 complaint (&symfile_complaints,
4340 _("debug type entry at offset 0x%x is duplicate to"
4341 " the entry at offset 0x%x, signature %s"),
4342 offset.sect_off, dup_offset.sect_off,
4343 hex_string (signature));
4345 *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type;
4347 if (dwarf2_read_debug)
4348 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature %s\n",
4350 hex_string (signature));
4359 /* Create the hash table of all entries in the .debug_types section,
4360 and initialize all_type_units.
4361 The result is zero if there is an error (e.g. missing .debug_types section),
4362 otherwise non-zero. */
4365 create_all_type_units (struct objfile *objfile)
4368 struct signatured_type **iter;
4370 types_htab = create_debug_types_hash_table (NULL, dwarf2_per_objfile->types);
4371 if (types_htab == NULL)
4373 dwarf2_per_objfile->signatured_types = NULL;
4377 dwarf2_per_objfile->signatured_types = types_htab;
4379 dwarf2_per_objfile->n_type_units = htab_elements (types_htab);
4380 dwarf2_per_objfile->all_type_units
4381 = obstack_alloc (&objfile->objfile_obstack,
4382 dwarf2_per_objfile->n_type_units
4383 * sizeof (struct signatured_type *));
4384 iter = &dwarf2_per_objfile->all_type_units[0];
4385 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter);
4386 gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0]
4387 == dwarf2_per_objfile->n_type_units);
4392 /* Lookup a signature based type for DW_FORM_ref_sig8.
4393 Returns NULL if signature SIG is not present in the table.
4394 It is up to the caller to complain about this. */
4396 static struct signatured_type *
4397 lookup_signatured_type (ULONGEST sig)
4399 struct signatured_type find_entry, *entry;
4401 if (dwarf2_per_objfile->signatured_types == NULL)
4403 find_entry.signature = sig;
4404 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
4408 /* Low level DIE reading support. */
4410 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4413 init_cu_die_reader (struct die_reader_specs *reader,
4414 struct dwarf2_cu *cu,
4415 struct dwarf2_section_info *section,
4416 struct dwo_file *dwo_file)
4418 gdb_assert (section->readin && section->buffer != NULL);
4419 reader->abfd = section->asection->owner;
4421 reader->dwo_file = dwo_file;
4422 reader->die_section = section;
4423 reader->buffer = section->buffer;
4424 reader->buffer_end = section->buffer + section->size;
4427 /* Subroutine of init_cutu_and_read_dies to simplify it.
4428 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
4429 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
4432 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
4433 from it to the DIE in the DWO. If NULL we are skipping the stub.
4434 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
4435 are filled in with the info of the DIE from the DWO file.
4436 ABBREV_TABLE_PROVIDED is non-zero if the caller of init_cutu_and_read_dies
4437 provided an abbrev table to use.
4438 The result is non-zero if a valid (non-dummy) DIE was found. */
4441 read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
4442 struct dwo_unit *dwo_unit,
4443 int abbrev_table_provided,
4444 struct die_info *stub_comp_unit_die,
4445 struct die_reader_specs *result_reader,
4446 const gdb_byte **result_info_ptr,
4447 struct die_info **result_comp_unit_die,
4448 int *result_has_children)
4450 struct objfile *objfile = dwarf2_per_objfile->objfile;
4451 struct dwarf2_cu *cu = this_cu->cu;
4452 struct dwarf2_section_info *section;
4454 const gdb_byte *begin_info_ptr, *info_ptr;
4455 const char *comp_dir_string;
4456 ULONGEST signature; /* Or dwo_id. */
4457 struct attribute *comp_dir, *stmt_list, *low_pc, *high_pc, *ranges;
4458 int i,num_extra_attrs;
4459 struct dwarf2_section_info *dwo_abbrev_section;
4460 struct attribute *attr;
4461 struct die_info *comp_unit_die;
4463 /* These attributes aren't processed until later:
4464 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4465 However, the attribute is found in the stub which we won't have later.
4466 In order to not impose this complication on the rest of the code,
4467 we read them here and copy them to the DWO CU/TU die. */
4475 if (stub_comp_unit_die != NULL)
4477 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4479 if (! this_cu->is_debug_types)
4480 stmt_list = dwarf2_attr (stub_comp_unit_die, DW_AT_stmt_list, cu);
4481 low_pc = dwarf2_attr (stub_comp_unit_die, DW_AT_low_pc, cu);
4482 high_pc = dwarf2_attr (stub_comp_unit_die, DW_AT_high_pc, cu);
4483 ranges = dwarf2_attr (stub_comp_unit_die, DW_AT_ranges, cu);
4484 comp_dir = dwarf2_attr (stub_comp_unit_die, DW_AT_comp_dir, cu);
4486 /* There should be a DW_AT_addr_base attribute here (if needed).
4487 We need the value before we can process DW_FORM_GNU_addr_index. */
4489 attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_addr_base, cu);
4491 cu->addr_base = DW_UNSND (attr);
4493 /* There should be a DW_AT_ranges_base attribute here (if needed).
4494 We need the value before we can process DW_AT_ranges. */
4495 cu->ranges_base = 0;
4496 attr = dwarf2_attr (stub_comp_unit_die, DW_AT_GNU_ranges_base, cu);
4498 cu->ranges_base = DW_UNSND (attr);
4501 /* Set up for reading the DWO CU/TU. */
4502 cu->dwo_unit = dwo_unit;
4503 section = dwo_unit->section;
4504 dwarf2_read_section (objfile, section);
4505 abfd = section->asection->owner;
4506 begin_info_ptr = info_ptr = section->buffer + dwo_unit->offset.sect_off;
4507 dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev;
4508 init_cu_die_reader (result_reader, cu, section, dwo_unit->dwo_file);
4510 if (this_cu->is_debug_types)
4512 ULONGEST header_signature;
4513 cu_offset type_offset_in_tu;
4514 struct signatured_type *sig_type = (struct signatured_type *) this_cu;
4516 info_ptr = read_and_check_type_unit_head (&cu->header, section,
4520 &type_offset_in_tu);
4521 gdb_assert (sig_type->signature == header_signature);
4522 gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off);
4523 /* For DWOs coming from DWP files, we don't know the CU length
4524 nor the type's offset in the TU until now. */
4525 dwo_unit->length = get_cu_length (&cu->header);
4526 dwo_unit->type_offset_in_tu = type_offset_in_tu;
4528 /* Establish the type offset that can be used to lookup the type.
4529 For DWO files, we don't know it until now. */
4530 sig_type->type_offset_in_section.sect_off =
4531 dwo_unit->offset.sect_off + dwo_unit->type_offset_in_tu.cu_off;
4535 info_ptr = read_and_check_comp_unit_head (&cu->header, section,
4538 gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off);
4539 /* For DWOs coming from DWP files, we don't know the CU length
4541 dwo_unit->length = get_cu_length (&cu->header);
4544 /* Replace the CU's original abbrev table with the DWO's.
4545 Reminder: We can't read the abbrev table until we've read the header. */
4546 if (abbrev_table_provided)
4548 /* Don't free the provided abbrev table, the caller of
4549 init_cutu_and_read_dies owns it. */
4550 dwarf2_read_abbrevs (cu, dwo_abbrev_section);
4551 /* Ensure the DWO abbrev table gets freed. */
4552 make_cleanup (dwarf2_free_abbrev_table, cu);
4556 dwarf2_free_abbrev_table (cu);
4557 dwarf2_read_abbrevs (cu, dwo_abbrev_section);
4558 /* Leave any existing abbrev table cleanup as is. */
4561 /* Read in the die, but leave space to copy over the attributes
4562 from the stub. This has the benefit of simplifying the rest of
4563 the code - all the work to maintain the illusion of a single
4564 DW_TAG_{compile,type}_unit DIE is done here. */
4565 num_extra_attrs = ((stmt_list != NULL)
4569 + (comp_dir != NULL));
4570 info_ptr = read_full_die_1 (result_reader, result_comp_unit_die, info_ptr,
4571 result_has_children, num_extra_attrs);
4573 /* Copy over the attributes from the stub to the DIE we just read in. */
4574 comp_unit_die = *result_comp_unit_die;
4575 i = comp_unit_die->num_attrs;
4576 if (stmt_list != NULL)
4577 comp_unit_die->attrs[i++] = *stmt_list;
4579 comp_unit_die->attrs[i++] = *low_pc;
4580 if (high_pc != NULL)
4581 comp_unit_die->attrs[i++] = *high_pc;
4583 comp_unit_die->attrs[i++] = *ranges;
4584 if (comp_dir != NULL)
4585 comp_unit_die->attrs[i++] = *comp_dir;
4586 comp_unit_die->num_attrs += num_extra_attrs;
4588 if (dwarf2_die_debug)
4590 fprintf_unfiltered (gdb_stdlog,
4591 "Read die from %s@0x%x of %s:\n",
4592 bfd_section_name (abfd, section->asection),
4593 (unsigned) (begin_info_ptr - section->buffer),
4594 bfd_get_filename (abfd));
4595 dump_die (comp_unit_die, dwarf2_die_debug);
4598 /* Skip dummy compilation units. */
4599 if (info_ptr >= begin_info_ptr + dwo_unit->length
4600 || peek_abbrev_code (abfd, info_ptr) == 0)
4603 *result_info_ptr = info_ptr;
4607 /* Subroutine of init_cutu_and_read_dies to simplify it.
4608 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
4609 Returns NULL if the specified DWO unit cannot be found. */
4611 static struct dwo_unit *
4612 lookup_dwo_unit (struct dwarf2_per_cu_data *this_cu,
4613 struct die_info *comp_unit_die)
4615 struct dwarf2_cu *cu = this_cu->cu;
4616 struct attribute *attr;
4618 struct dwo_unit *dwo_unit;
4619 const char *comp_dir, *dwo_name;
4621 /* Yeah, we look dwo_name up again, but it simplifies the code. */
4622 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu);
4623 gdb_assert (attr != NULL);
4624 dwo_name = DW_STRING (attr);
4626 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu);
4628 comp_dir = DW_STRING (attr);
4630 if (this_cu->is_debug_types)
4632 struct signatured_type *sig_type;
4634 /* Since this_cu is the first member of struct signatured_type,
4635 we can go from a pointer to one to a pointer to the other. */
4636 sig_type = (struct signatured_type *) this_cu;
4637 signature = sig_type->signature;
4638 dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir);
4642 struct attribute *attr;
4644 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
4646 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
4648 dwo_name, this_cu->objfile->name);
4649 signature = DW_UNSND (attr);
4650 dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir,
4657 /* Initialize a CU (or TU) and read its DIEs.
4658 If the CU defers to a DWO file, read the DWO file as well.
4660 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4661 Otherwise the table specified in the comp unit header is read in and used.
4662 This is an optimization for when we already have the abbrev table.
4664 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4665 Otherwise, a new CU is allocated with xmalloc.
4667 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4668 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4670 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4671 linker) then DIE_READER_FUNC will not get called. */
4674 init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu,
4675 struct abbrev_table *abbrev_table,
4676 int use_existing_cu, int keep,
4677 die_reader_func_ftype *die_reader_func,
4680 struct objfile *objfile = dwarf2_per_objfile->objfile;
4681 struct dwarf2_section_info *section = this_cu->section;
4682 bfd *abfd = section->asection->owner;
4683 struct dwarf2_cu *cu;
4684 const gdb_byte *begin_info_ptr, *info_ptr;
4685 struct die_reader_specs reader;
4686 struct die_info *comp_unit_die;
4688 struct attribute *attr;
4689 struct cleanup *cleanups, *free_cu_cleanup = NULL;
4690 struct signatured_type *sig_type = NULL;
4691 struct dwarf2_section_info *abbrev_section;
4692 /* Non-zero if CU currently points to a DWO file and we need to
4693 reread it. When this happens we need to reread the skeleton die
4694 before we can reread the DWO file. */
4695 int rereading_dwo_cu = 0;
4697 if (dwarf2_die_debug)
4698 fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n",
4699 this_cu->is_debug_types ? "type" : "comp",
4700 this_cu->offset.sect_off);
4702 if (use_existing_cu)
4705 cleanups = make_cleanup (null_cleanup, NULL);
4707 /* This is cheap if the section is already read in. */
4708 dwarf2_read_section (objfile, section);
4710 begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off;
4712 abbrev_section = get_abbrev_section_for_cu (this_cu);
4714 if (use_existing_cu && this_cu->cu != NULL)
4718 /* If this CU is from a DWO file we need to start over, we need to
4719 refetch the attributes from the skeleton CU.
4720 This could be optimized by retrieving those attributes from when we
4721 were here the first time: the previous comp_unit_die was stored in
4722 comp_unit_obstack. But there's no data yet that we need this
4724 if (cu->dwo_unit != NULL)
4725 rereading_dwo_cu = 1;
4729 /* If !use_existing_cu, this_cu->cu must be NULL. */
4730 gdb_assert (this_cu->cu == NULL);
4732 cu = xmalloc (sizeof (*cu));
4733 init_one_comp_unit (cu, this_cu);
4735 /* If an error occurs while loading, release our storage. */
4736 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
4739 /* Get the header. */
4740 if (cu->header.first_die_offset.cu_off != 0 && ! rereading_dwo_cu)
4742 /* We already have the header, there's no need to read it in again. */
4743 info_ptr += cu->header.first_die_offset.cu_off;
4747 if (this_cu->is_debug_types)
4750 cu_offset type_offset_in_tu;
4752 info_ptr = read_and_check_type_unit_head (&cu->header, section,
4753 abbrev_section, info_ptr,
4755 &type_offset_in_tu);
4757 /* Since per_cu is the first member of struct signatured_type,
4758 we can go from a pointer to one to a pointer to the other. */
4759 sig_type = (struct signatured_type *) this_cu;
4760 gdb_assert (sig_type->signature == signature);
4761 gdb_assert (sig_type->type_offset_in_tu.cu_off
4762 == type_offset_in_tu.cu_off);
4763 gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off);
4765 /* LENGTH has not been set yet for type units if we're
4766 using .gdb_index. */
4767 this_cu->length = get_cu_length (&cu->header);
4769 /* Establish the type offset that can be used to lookup the type. */
4770 sig_type->type_offset_in_section.sect_off =
4771 this_cu->offset.sect_off + sig_type->type_offset_in_tu.cu_off;
4775 info_ptr = read_and_check_comp_unit_head (&cu->header, section,
4779 gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off);
4780 gdb_assert (this_cu->length == get_cu_length (&cu->header));
4784 /* Skip dummy compilation units. */
4785 if (info_ptr >= begin_info_ptr + this_cu->length
4786 || peek_abbrev_code (abfd, info_ptr) == 0)
4788 do_cleanups (cleanups);
4792 /* If we don't have them yet, read the abbrevs for this compilation unit.
4793 And if we need to read them now, make sure they're freed when we're
4794 done. Note that it's important that if the CU had an abbrev table
4795 on entry we don't free it when we're done: Somewhere up the call stack
4796 it may be in use. */
4797 if (abbrev_table != NULL)
4799 gdb_assert (cu->abbrev_table == NULL);
4800 gdb_assert (cu->header.abbrev_offset.sect_off
4801 == abbrev_table->offset.sect_off);
4802 cu->abbrev_table = abbrev_table;
4804 else if (cu->abbrev_table == NULL)
4806 dwarf2_read_abbrevs (cu, abbrev_section);
4807 make_cleanup (dwarf2_free_abbrev_table, cu);
4809 else if (rereading_dwo_cu)
4811 dwarf2_free_abbrev_table (cu);
4812 dwarf2_read_abbrevs (cu, abbrev_section);
4815 /* Read the top level CU/TU die. */
4816 init_cu_die_reader (&reader, cu, section, NULL);
4817 info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children);
4819 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
4821 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
4822 DWO CU, that this test will fail (the attribute will not be present). */
4823 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu);
4826 struct dwo_unit *dwo_unit;
4827 struct die_info *dwo_comp_unit_die;
4831 complaint (&symfile_complaints,
4832 _("compilation unit with DW_AT_GNU_dwo_name"
4833 " has children (offset 0x%x) [in module %s]"),
4834 this_cu->offset.sect_off, bfd_get_filename (abfd));
4836 dwo_unit = lookup_dwo_unit (this_cu, comp_unit_die);
4837 if (dwo_unit != NULL)
4839 if (read_cutu_die_from_dwo (this_cu, dwo_unit,
4840 abbrev_table != NULL,
4843 &dwo_comp_unit_die, &has_children) == 0)
4846 do_cleanups (cleanups);
4849 comp_unit_die = dwo_comp_unit_die;
4853 /* Yikes, we couldn't find the rest of the DIE, we only have
4854 the stub. A complaint has already been logged. There's
4855 not much more we can do except pass on the stub DIE to
4856 die_reader_func. We don't want to throw an error on bad
4861 /* All of the above is setup for this call. Yikes. */
4862 die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data);
4864 /* Done, clean up. */
4865 if (free_cu_cleanup != NULL)
4869 /* We've successfully allocated this compilation unit. Let our
4870 caller clean it up when finished with it. */
4871 discard_cleanups (free_cu_cleanup);
4873 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4874 So we have to manually free the abbrev table. */
4875 dwarf2_free_abbrev_table (cu);
4877 /* Link this CU into read_in_chain. */
4878 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4879 dwarf2_per_objfile->read_in_chain = this_cu;
4882 do_cleanups (free_cu_cleanup);
4885 do_cleanups (cleanups);
4888 /* Read CU/TU THIS_CU in section SECTION,
4889 but do not follow DW_AT_GNU_dwo_name if present.
4890 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4891 to have already done the lookup to find the DWO/DWP file).
4893 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4894 THIS_CU->is_debug_types, but nothing else.
4896 We fill in THIS_CU->length.
4898 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4899 linker) then DIE_READER_FUNC will not get called.
4901 THIS_CU->cu is always freed when done.
4902 This is done in order to not leave THIS_CU->cu in a state where we have
4903 to care whether it refers to the "main" CU or the DWO CU. */
4906 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu,
4907 struct dwarf2_section_info *abbrev_section,
4908 struct dwo_file *dwo_file,
4909 die_reader_func_ftype *die_reader_func,
4912 struct objfile *objfile = dwarf2_per_objfile->objfile;
4913 struct dwarf2_section_info *section = this_cu->section;
4914 bfd *abfd = section->asection->owner;
4915 struct dwarf2_cu cu;
4916 const gdb_byte *begin_info_ptr, *info_ptr;
4917 struct die_reader_specs reader;
4918 struct cleanup *cleanups;
4919 struct die_info *comp_unit_die;
4922 if (dwarf2_die_debug)
4923 fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n",
4924 this_cu->is_debug_types ? "type" : "comp",
4925 this_cu->offset.sect_off);
4927 gdb_assert (this_cu->cu == NULL);
4929 /* This is cheap if the section is already read in. */
4930 dwarf2_read_section (objfile, section);
4932 init_one_comp_unit (&cu, this_cu);
4934 cleanups = make_cleanup (free_stack_comp_unit, &cu);
4936 begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off;
4937 info_ptr = read_and_check_comp_unit_head (&cu.header, section,
4938 abbrev_section, info_ptr,
4939 this_cu->is_debug_types);
4941 this_cu->length = get_cu_length (&cu.header);
4943 /* Skip dummy compilation units. */
4944 if (info_ptr >= begin_info_ptr + this_cu->length
4945 || peek_abbrev_code (abfd, info_ptr) == 0)
4947 do_cleanups (cleanups);
4951 dwarf2_read_abbrevs (&cu, abbrev_section);
4952 make_cleanup (dwarf2_free_abbrev_table, &cu);
4954 init_cu_die_reader (&reader, &cu, section, dwo_file);
4955 info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children);
4957 die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data);
4959 do_cleanups (cleanups);
4962 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4963 does not lookup the specified DWO file.
4964 This cannot be used to read DWO files.
4966 THIS_CU->cu is always freed when done.
4967 This is done in order to not leave THIS_CU->cu in a state where we have
4968 to care whether it refers to the "main" CU or the DWO CU.
4969 We can revisit this if the data shows there's a performance issue. */
4972 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu,
4973 die_reader_func_ftype *die_reader_func,
4976 init_cutu_and_read_dies_no_follow (this_cu,
4977 get_abbrev_section_for_cu (this_cu),
4979 die_reader_func, data);
4982 /* Type Unit Groups.
4984 Type Unit Groups are a way to collapse the set of all TUs (type units) into
4985 a more manageable set. The grouping is done by DW_AT_stmt_list entry
4986 so that all types coming from the same compilation (.o file) are grouped
4987 together. A future step could be to put the types in the same symtab as
4988 the CU the types ultimately came from. */
4991 hash_type_unit_group (const void *item)
4993 const struct type_unit_group *tu_group = item;
4995 return hash_stmt_list_entry (&tu_group->hash);
4999 eq_type_unit_group (const void *item_lhs, const void *item_rhs)
5001 const struct type_unit_group *lhs = item_lhs;
5002 const struct type_unit_group *rhs = item_rhs;
5004 return eq_stmt_list_entry (&lhs->hash, &rhs->hash);
5007 /* Allocate a hash table for type unit groups. */
5010 allocate_type_unit_groups_table (void)
5012 return htab_create_alloc_ex (3,
5013 hash_type_unit_group,
5016 &dwarf2_per_objfile->objfile->objfile_obstack,
5017 hashtab_obstack_allocate,
5018 dummy_obstack_deallocate);
5021 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5022 partial symtabs. We combine several TUs per psymtab to not let the size
5023 of any one psymtab grow too big. */
5024 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5025 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5027 /* Helper routine for get_type_unit_group.
5028 Create the type_unit_group object used to hold one or more TUs. */
5030 static struct type_unit_group *
5031 create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
5033 struct objfile *objfile = dwarf2_per_objfile->objfile;
5034 struct dwarf2_per_cu_data *per_cu;
5035 struct type_unit_group *tu_group;
5037 tu_group = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5038 struct type_unit_group);
5039 per_cu = &tu_group->per_cu;
5040 per_cu->objfile = objfile;
5042 if (dwarf2_per_objfile->using_index)
5044 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5045 struct dwarf2_per_cu_quick_data);
5049 unsigned int line_offset = line_offset_struct.sect_off;
5050 struct partial_symtab *pst;
5053 /* Give the symtab a useful name for debug purposes. */
5054 if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0)
5055 name = xstrprintf ("<type_units_%d>",
5056 (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
5058 name = xstrprintf ("<type_units_at_0x%x>", line_offset);
5060 pst = create_partial_symtab (per_cu, name);
5066 tu_group->hash.dwo_unit = cu->dwo_unit;
5067 tu_group->hash.line_offset = line_offset_struct;
5072 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5073 STMT_LIST is a DW_AT_stmt_list attribute. */
5075 static struct type_unit_group *
5076 get_type_unit_group (struct dwarf2_cu *cu, struct attribute *stmt_list)
5078 struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
5079 struct type_unit_group *tu_group;
5081 unsigned int line_offset;
5082 struct type_unit_group type_unit_group_for_lookup;
5084 if (dwarf2_per_objfile->type_unit_groups == NULL)
5086 dwarf2_per_objfile->type_unit_groups =
5087 allocate_type_unit_groups_table ();
5090 /* Do we need to create a new group, or can we use an existing one? */
5094 line_offset = DW_UNSND (stmt_list);
5095 ++tu_stats->nr_symtab_sharers;
5099 /* Ugh, no stmt_list. Rare, but we have to handle it.
5100 We can do various things here like create one group per TU or
5101 spread them over multiple groups to split up the expansion work.
5102 To avoid worst case scenarios (too many groups or too large groups)
5103 we, umm, group them in bunches. */
5104 line_offset = (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5105 | (tu_stats->nr_stmt_less_type_units
5106 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE));
5107 ++tu_stats->nr_stmt_less_type_units;
5110 type_unit_group_for_lookup.hash.dwo_unit = cu->dwo_unit;
5111 type_unit_group_for_lookup.hash.line_offset.sect_off = line_offset;
5112 slot = htab_find_slot (dwarf2_per_objfile->type_unit_groups,
5113 &type_unit_group_for_lookup, INSERT);
5117 gdb_assert (tu_group != NULL);
5121 sect_offset line_offset_struct;
5123 line_offset_struct.sect_off = line_offset;
5124 tu_group = create_type_unit_group (cu, line_offset_struct);
5126 ++tu_stats->nr_symtabs;
5132 /* Struct used to sort TUs by their abbreviation table offset. */
5134 struct tu_abbrev_offset
5136 struct signatured_type *sig_type;
5137 sect_offset abbrev_offset;
5140 /* Helper routine for build_type_unit_groups, passed to qsort. */
5143 sort_tu_by_abbrev_offset (const void *ap, const void *bp)
5145 const struct tu_abbrev_offset * const *a = ap;
5146 const struct tu_abbrev_offset * const *b = bp;
5147 unsigned int aoff = (*a)->abbrev_offset.sect_off;
5148 unsigned int boff = (*b)->abbrev_offset.sect_off;
5150 return (aoff > boff) - (aoff < boff);
5153 /* A helper function to add a type_unit_group to a table. */
5156 add_type_unit_group_to_table (void **slot, void *datum)
5158 struct type_unit_group *tu_group = *slot;
5159 struct type_unit_group ***datap = datum;
5167 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5168 each one passing FUNC,DATA.
5170 The efficiency is because we sort TUs by the abbrev table they use and
5171 only read each abbrev table once. In one program there are 200K TUs
5172 sharing 8K abbrev tables.
5174 The main purpose of this function is to support building the
5175 dwarf2_per_objfile->type_unit_groups table.
5176 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5177 can collapse the search space by grouping them by stmt_list.
5178 The savings can be significant, in the same program from above the 200K TUs
5179 share 8K stmt_list tables.
5181 FUNC is expected to call get_type_unit_group, which will create the
5182 struct type_unit_group if necessary and add it to
5183 dwarf2_per_objfile->type_unit_groups. */
5186 build_type_unit_groups (die_reader_func_ftype *func, void *data)
5188 struct objfile *objfile = dwarf2_per_objfile->objfile;
5189 struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
5190 struct cleanup *cleanups;
5191 struct abbrev_table *abbrev_table;
5192 sect_offset abbrev_offset;
5193 struct tu_abbrev_offset *sorted_by_abbrev;
5194 struct type_unit_group **iter;
5197 /* It's up to the caller to not call us multiple times. */
5198 gdb_assert (dwarf2_per_objfile->type_unit_groups == NULL);
5200 if (dwarf2_per_objfile->n_type_units == 0)
5203 /* TUs typically share abbrev tables, and there can be way more TUs than
5204 abbrev tables. Sort by abbrev table to reduce the number of times we
5205 read each abbrev table in.
5206 Alternatives are to punt or to maintain a cache of abbrev tables.
5207 This is simpler and efficient enough for now.
5209 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5210 symtab to use). Typically TUs with the same abbrev offset have the same
5211 stmt_list value too so in practice this should work well.
5213 The basic algorithm here is:
5215 sort TUs by abbrev table
5216 for each TU with same abbrev table:
5217 read abbrev table if first user
5218 read TU top level DIE
5219 [IWBN if DWO skeletons had DW_AT_stmt_list]
5222 if (dwarf2_read_debug)
5223 fprintf_unfiltered (gdb_stdlog, "Building type unit groups ...\n");
5225 /* Sort in a separate table to maintain the order of all_type_units
5226 for .gdb_index: TU indices directly index all_type_units. */
5227 sorted_by_abbrev = XNEWVEC (struct tu_abbrev_offset,
5228 dwarf2_per_objfile->n_type_units);
5229 for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
5231 struct signatured_type *sig_type = dwarf2_per_objfile->all_type_units[i];
5233 sorted_by_abbrev[i].sig_type = sig_type;
5234 sorted_by_abbrev[i].abbrev_offset =
5235 read_abbrev_offset (sig_type->per_cu.section,
5236 sig_type->per_cu.offset);
5238 cleanups = make_cleanup (xfree, sorted_by_abbrev);
5239 qsort (sorted_by_abbrev, dwarf2_per_objfile->n_type_units,
5240 sizeof (struct tu_abbrev_offset), sort_tu_by_abbrev_offset);
5242 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5243 called any number of times, so we don't reset tu_stats here. */
5245 abbrev_offset.sect_off = ~(unsigned) 0;
5246 abbrev_table = NULL;
5247 make_cleanup (abbrev_table_free_cleanup, &abbrev_table);
5249 for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
5251 const struct tu_abbrev_offset *tu = &sorted_by_abbrev[i];
5253 /* Switch to the next abbrev table if necessary. */
5254 if (abbrev_table == NULL
5255 || tu->abbrev_offset.sect_off != abbrev_offset.sect_off)
5257 if (abbrev_table != NULL)
5259 abbrev_table_free (abbrev_table);
5260 /* Reset to NULL in case abbrev_table_read_table throws
5261 an error: abbrev_table_free_cleanup will get called. */
5262 abbrev_table = NULL;
5264 abbrev_offset = tu->abbrev_offset;
5266 abbrev_table_read_table (&dwarf2_per_objfile->abbrev,
5268 ++tu_stats->nr_uniq_abbrev_tables;
5271 init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table, 0, 0,
5275 /* Create a vector of pointers to primary type units to make it easy to
5276 iterate over them and CUs. See dw2_get_primary_cu. */
5277 dwarf2_per_objfile->n_type_unit_groups =
5278 htab_elements (dwarf2_per_objfile->type_unit_groups);
5279 dwarf2_per_objfile->all_type_unit_groups =
5280 obstack_alloc (&objfile->objfile_obstack,
5281 dwarf2_per_objfile->n_type_unit_groups
5282 * sizeof (struct type_unit_group *));
5283 iter = &dwarf2_per_objfile->all_type_unit_groups[0];
5284 htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups,
5285 add_type_unit_group_to_table, &iter);
5286 gdb_assert (iter - &dwarf2_per_objfile->all_type_unit_groups[0]
5287 == dwarf2_per_objfile->n_type_unit_groups);
5289 do_cleanups (cleanups);
5291 if (dwarf2_read_debug)
5293 fprintf_unfiltered (gdb_stdlog, "Done building type unit groups:\n");
5294 fprintf_unfiltered (gdb_stdlog, " %d TUs\n",
5295 dwarf2_per_objfile->n_type_units);
5296 fprintf_unfiltered (gdb_stdlog, " %d uniq abbrev tables\n",
5297 tu_stats->nr_uniq_abbrev_tables);
5298 fprintf_unfiltered (gdb_stdlog, " %d symtabs from stmt_list entries\n",
5299 tu_stats->nr_symtabs);
5300 fprintf_unfiltered (gdb_stdlog, " %d symtab sharers\n",
5301 tu_stats->nr_symtab_sharers);
5302 fprintf_unfiltered (gdb_stdlog, " %d type units without a stmt_list\n",
5303 tu_stats->nr_stmt_less_type_units);
5307 /* Partial symbol tables. */
5309 /* Create a psymtab named NAME and assign it to PER_CU.
5311 The caller must fill in the following details:
5312 dirname, textlow, texthigh. */
5314 static struct partial_symtab *
5315 create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name)
5317 struct objfile *objfile = per_cu->objfile;
5318 struct partial_symtab *pst;
5320 pst = start_psymtab_common (objfile, objfile->section_offsets,
5322 objfile->global_psymbols.next,
5323 objfile->static_psymbols.next);
5325 pst->psymtabs_addrmap_supported = 1;
5327 /* This is the glue that links PST into GDB's symbol API. */
5328 pst->read_symtab_private = per_cu;
5329 pst->read_symtab = dwarf2_read_symtab;
5330 per_cu->v.psymtab = pst;
5335 /* die_reader_func for process_psymtab_comp_unit. */
5338 process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
5339 const gdb_byte *info_ptr,
5340 struct die_info *comp_unit_die,
5344 struct dwarf2_cu *cu = reader->cu;
5345 struct objfile *objfile = cu->objfile;
5346 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
5347 struct attribute *attr;
5349 CORE_ADDR best_lowpc = 0, best_highpc = 0;
5350 struct partial_symtab *pst;
5352 const char *filename;
5353 int *want_partial_unit_ptr = data;
5355 if (comp_unit_die->tag == DW_TAG_partial_unit
5356 && (want_partial_unit_ptr == NULL
5357 || !*want_partial_unit_ptr))
5360 gdb_assert (! per_cu->is_debug_types);
5362 prepare_one_comp_unit (cu, comp_unit_die, language_minimal);
5364 cu->list_in_scope = &file_symbols;
5366 /* Allocate a new partial symbol table structure. */
5367 attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu);
5368 if (attr == NULL || !DW_STRING (attr))
5371 filename = DW_STRING (attr);
5373 pst = create_partial_symtab (per_cu, filename);
5375 /* This must be done before calling dwarf2_build_include_psymtabs. */
5376 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu);
5378 pst->dirname = DW_STRING (attr);
5380 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5382 dwarf2_find_base_address (comp_unit_die, cu);
5384 /* Possibly set the default values of LOWPC and HIGHPC from
5386 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
5387 &best_highpc, cu, pst);
5388 if (has_pc_info == 1 && best_lowpc < best_highpc)
5389 /* Store the contiguous range if it is not empty; it can be empty for
5390 CUs with no code. */
5391 addrmap_set_empty (objfile->psymtabs_addrmap,
5392 best_lowpc + baseaddr,
5393 best_highpc + baseaddr - 1, pst);
5395 /* Check if comp unit has_children.
5396 If so, read the rest of the partial symbols from this comp unit.
5397 If not, there's no more debug_info for this comp unit. */
5400 struct partial_die_info *first_die;
5401 CORE_ADDR lowpc, highpc;
5403 lowpc = ((CORE_ADDR) -1);
5404 highpc = ((CORE_ADDR) 0);
5406 first_die = load_partial_dies (reader, info_ptr, 1);
5408 scan_partial_symbols (first_die, &lowpc, &highpc,
5411 /* If we didn't find a lowpc, set it to highpc to avoid
5412 complaints from `maint check'. */
5413 if (lowpc == ((CORE_ADDR) -1))
5416 /* If the compilation unit didn't have an explicit address range,
5417 then use the information extracted from its child dies. */
5421 best_highpc = highpc;
5424 pst->textlow = best_lowpc + baseaddr;
5425 pst->texthigh = best_highpc + baseaddr;
5427 pst->n_global_syms = objfile->global_psymbols.next -
5428 (objfile->global_psymbols.list + pst->globals_offset);
5429 pst->n_static_syms = objfile->static_psymbols.next -
5430 (objfile->static_psymbols.list + pst->statics_offset);
5431 sort_pst_symbols (objfile, pst);
5433 if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs))
5436 int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
5437 struct dwarf2_per_cu_data *iter;
5439 /* Fill in 'dependencies' here; we fill in 'users' in a
5441 pst->number_of_dependencies = len;
5442 pst->dependencies = obstack_alloc (&objfile->objfile_obstack,
5443 len * sizeof (struct symtab *));
5445 VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
5448 pst->dependencies[i] = iter->v.psymtab;
5450 VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
5453 /* Get the list of files included in the current compilation unit,
5454 and build a psymtab for each of them. */
5455 dwarf2_build_include_psymtabs (cu, comp_unit_die, pst);
5457 if (dwarf2_read_debug)
5459 struct gdbarch *gdbarch = get_objfile_arch (objfile);
5461 fprintf_unfiltered (gdb_stdlog,
5462 "Psymtab for %s unit @0x%x: %s - %s"
5463 ", %d global, %d static syms\n",
5464 per_cu->is_debug_types ? "type" : "comp",
5465 per_cu->offset.sect_off,
5466 paddress (gdbarch, pst->textlow),
5467 paddress (gdbarch, pst->texthigh),
5468 pst->n_global_syms, pst->n_static_syms);
5472 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5473 Process compilation unit THIS_CU for a psymtab. */
5476 process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
5477 int want_partial_unit)
5479 /* If this compilation unit was already read in, free the
5480 cached copy in order to read it in again. This is
5481 necessary because we skipped some symbols when we first
5482 read in the compilation unit (see load_partial_dies).
5483 This problem could be avoided, but the benefit is unclear. */
5484 if (this_cu->cu != NULL)
5485 free_one_cached_comp_unit (this_cu);
5487 gdb_assert (! this_cu->is_debug_types);
5488 init_cutu_and_read_dies (this_cu, NULL, 0, 0,
5489 process_psymtab_comp_unit_reader,
5490 &want_partial_unit);
5492 /* Age out any secondary CUs. */
5493 age_cached_comp_units ();
5496 /* Reader function for build_type_psymtabs. */
5499 build_type_psymtabs_reader (const struct die_reader_specs *reader,
5500 const gdb_byte *info_ptr,
5501 struct die_info *type_unit_die,
5505 struct objfile *objfile = dwarf2_per_objfile->objfile;
5506 struct dwarf2_cu *cu = reader->cu;
5507 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
5508 struct signatured_type *sig_type;
5509 struct type_unit_group *tu_group;
5510 struct attribute *attr;
5511 struct partial_die_info *first_die;
5512 CORE_ADDR lowpc, highpc;
5513 struct partial_symtab *pst;
5515 gdb_assert (data == NULL);
5516 gdb_assert (per_cu->is_debug_types);
5517 sig_type = (struct signatured_type *) per_cu;
5522 attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
5523 tu_group = get_type_unit_group (cu, attr);
5525 VEC_safe_push (sig_type_ptr, tu_group->tus, sig_type);
5527 prepare_one_comp_unit (cu, type_unit_die, language_minimal);
5528 cu->list_in_scope = &file_symbols;
5529 pst = create_partial_symtab (per_cu, "");
5532 first_die = load_partial_dies (reader, info_ptr, 1);
5534 lowpc = (CORE_ADDR) -1;
5535 highpc = (CORE_ADDR) 0;
5536 scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu);
5538 pst->n_global_syms = objfile->global_psymbols.next -
5539 (objfile->global_psymbols.list + pst->globals_offset);
5540 pst->n_static_syms = objfile->static_psymbols.next -
5541 (objfile->static_psymbols.list + pst->statics_offset);
5542 sort_pst_symbols (objfile, pst);
5545 /* Traversal function for build_type_psymtabs. */
5548 build_type_psymtab_dependencies (void **slot, void *info)
5550 struct objfile *objfile = dwarf2_per_objfile->objfile;
5551 struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
5552 struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
5553 struct partial_symtab *pst = per_cu->v.psymtab;
5554 int len = VEC_length (sig_type_ptr, tu_group->tus);
5555 struct signatured_type *iter;
5558 gdb_assert (len > 0);
5559 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu));
5561 pst->number_of_dependencies = len;
5562 pst->dependencies = obstack_alloc (&objfile->objfile_obstack,
5563 len * sizeof (struct psymtab *));
5565 VEC_iterate (sig_type_ptr, tu_group->tus, i, iter);
5568 gdb_assert (iter->per_cu.is_debug_types);
5569 pst->dependencies[i] = iter->per_cu.v.psymtab;
5570 iter->type_unit_group = tu_group;
5573 VEC_free (sig_type_ptr, tu_group->tus);
5578 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5579 Build partial symbol tables for the .debug_types comp-units. */
5582 build_type_psymtabs (struct objfile *objfile)
5584 if (! create_all_type_units (objfile))
5587 build_type_unit_groups (build_type_psymtabs_reader, NULL);
5589 /* Now that all TUs have been processed we can fill in the dependencies. */
5590 htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups,
5591 build_type_psymtab_dependencies, NULL);
5594 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5597 psymtabs_addrmap_cleanup (void *o)
5599 struct objfile *objfile = o;
5601 objfile->psymtabs_addrmap = NULL;
5604 /* Compute the 'user' field for each psymtab in OBJFILE. */
5607 set_partial_user (struct objfile *objfile)
5611 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
5613 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
5614 struct partial_symtab *pst = per_cu->v.psymtab;
5620 for (j = 0; j < pst->number_of_dependencies; ++j)
5622 /* Set the 'user' field only if it is not already set. */
5623 if (pst->dependencies[j]->user == NULL)
5624 pst->dependencies[j]->user = pst;
5629 /* Build the partial symbol table by doing a quick pass through the
5630 .debug_info and .debug_abbrev sections. */
5633 dwarf2_build_psymtabs_hard (struct objfile *objfile)
5635 struct cleanup *back_to, *addrmap_cleanup;
5636 struct obstack temp_obstack;
5639 if (dwarf2_read_debug)
5641 fprintf_unfiltered (gdb_stdlog, "Building psymtabs of objfile %s ...\n",
5645 dwarf2_per_objfile->reading_partial_symbols = 1;
5647 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
5649 /* Any cached compilation units will be linked by the per-objfile
5650 read_in_chain. Make sure to free them when we're done. */
5651 back_to = make_cleanup (free_cached_comp_units, NULL);
5653 build_type_psymtabs (objfile);
5655 create_all_comp_units (objfile);
5657 /* Create a temporary address map on a temporary obstack. We later
5658 copy this to the final obstack. */
5659 obstack_init (&temp_obstack);
5660 make_cleanup_obstack_free (&temp_obstack);
5661 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
5662 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
5664 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
5666 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
5668 process_psymtab_comp_unit (per_cu, 0);
5671 set_partial_user (objfile);
5673 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
5674 &objfile->objfile_obstack);
5675 discard_cleanups (addrmap_cleanup);
5677 do_cleanups (back_to);
5679 if (dwarf2_read_debug)
5680 fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n",
5684 /* die_reader_func for load_partial_comp_unit. */
5687 load_partial_comp_unit_reader (const struct die_reader_specs *reader,
5688 const gdb_byte *info_ptr,
5689 struct die_info *comp_unit_die,
5693 struct dwarf2_cu *cu = reader->cu;
5695 prepare_one_comp_unit (cu, comp_unit_die, language_minimal);
5697 /* Check if comp unit has_children.
5698 If so, read the rest of the partial symbols from this comp unit.
5699 If not, there's no more debug_info for this comp unit. */
5701 load_partial_dies (reader, info_ptr, 0);
5704 /* Load the partial DIEs for a secondary CU into memory.
5705 This is also used when rereading a primary CU with load_all_dies. */
5708 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
5710 init_cutu_and_read_dies (this_cu, NULL, 1, 1,
5711 load_partial_comp_unit_reader, NULL);
5715 read_comp_units_from_section (struct objfile *objfile,
5716 struct dwarf2_section_info *section,
5717 unsigned int is_dwz,
5720 struct dwarf2_per_cu_data ***all_comp_units)
5722 const gdb_byte *info_ptr;
5723 bfd *abfd = section->asection->owner;
5725 if (dwarf2_read_debug)
5726 fprintf_unfiltered (gdb_stdlog, "Reading %s for %s\n",
5727 section->asection->name, bfd_get_filename (abfd));
5729 dwarf2_read_section (objfile, section);
5731 info_ptr = section->buffer;
5733 while (info_ptr < section->buffer + section->size)
5735 unsigned int length, initial_length_size;
5736 struct dwarf2_per_cu_data *this_cu;
5739 offset.sect_off = info_ptr - section->buffer;
5741 /* Read just enough information to find out where the next
5742 compilation unit is. */
5743 length = read_initial_length (abfd, info_ptr, &initial_length_size);
5745 /* Save the compilation unit for later lookup. */
5746 this_cu = obstack_alloc (&objfile->objfile_obstack,
5747 sizeof (struct dwarf2_per_cu_data));
5748 memset (this_cu, 0, sizeof (*this_cu));
5749 this_cu->offset = offset;
5750 this_cu->length = length + initial_length_size;
5751 this_cu->is_dwz = is_dwz;
5752 this_cu->objfile = objfile;
5753 this_cu->section = section;
5755 if (*n_comp_units == *n_allocated)
5758 *all_comp_units = xrealloc (*all_comp_units,
5760 * sizeof (struct dwarf2_per_cu_data *));
5762 (*all_comp_units)[*n_comp_units] = this_cu;
5765 info_ptr = info_ptr + this_cu->length;
5769 /* Create a list of all compilation units in OBJFILE.
5770 This is only done for -readnow and building partial symtabs. */
5773 create_all_comp_units (struct objfile *objfile)
5777 struct dwarf2_per_cu_data **all_comp_units;
5781 all_comp_units = xmalloc (n_allocated
5782 * sizeof (struct dwarf2_per_cu_data *));
5784 read_comp_units_from_section (objfile, &dwarf2_per_objfile->info, 0,
5785 &n_allocated, &n_comp_units, &all_comp_units);
5787 if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
5789 struct dwz_file *dwz = dwarf2_get_dwz_file ();
5791 read_comp_units_from_section (objfile, &dwz->info, 1,
5792 &n_allocated, &n_comp_units,
5796 dwarf2_per_objfile->all_comp_units
5797 = obstack_alloc (&objfile->objfile_obstack,
5798 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
5799 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
5800 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
5801 xfree (all_comp_units);
5802 dwarf2_per_objfile->n_comp_units = n_comp_units;
5805 /* Process all loaded DIEs for compilation unit CU, starting at
5806 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5807 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5808 DW_AT_ranges). If NEED_PC is set, then this function will set
5809 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5810 and record the covered ranges in the addrmap. */
5813 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
5814 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
5816 struct partial_die_info *pdi;
5818 /* Now, march along the PDI's, descending into ones which have
5819 interesting children but skipping the children of the other ones,
5820 until we reach the end of the compilation unit. */
5826 fixup_partial_die (pdi, cu);
5828 /* Anonymous namespaces or modules have no name but have interesting
5829 children, so we need to look at them. Ditto for anonymous
5832 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
5833 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type
5834 || pdi->tag == DW_TAG_imported_unit)
5838 case DW_TAG_subprogram:
5839 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
5841 case DW_TAG_constant:
5842 case DW_TAG_variable:
5843 case DW_TAG_typedef:
5844 case DW_TAG_union_type:
5845 if (!pdi->is_declaration)
5847 add_partial_symbol (pdi, cu);
5850 case DW_TAG_class_type:
5851 case DW_TAG_interface_type:
5852 case DW_TAG_structure_type:
5853 if (!pdi->is_declaration)
5855 add_partial_symbol (pdi, cu);
5858 case DW_TAG_enumeration_type:
5859 if (!pdi->is_declaration)
5860 add_partial_enumeration (pdi, cu);
5862 case DW_TAG_base_type:
5863 case DW_TAG_subrange_type:
5864 /* File scope base type definitions are added to the partial
5866 add_partial_symbol (pdi, cu);
5868 case DW_TAG_namespace:
5869 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
5872 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
5874 case DW_TAG_imported_unit:
5876 struct dwarf2_per_cu_data *per_cu;
5878 /* For now we don't handle imported units in type units. */
5879 if (cu->per_cu->is_debug_types)
5881 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5882 " supported in type units [in module %s]"),
5886 per_cu = dwarf2_find_containing_comp_unit (pdi->d.offset,
5890 /* Go read the partial unit, if needed. */
5891 if (per_cu->v.psymtab == NULL)
5892 process_psymtab_comp_unit (per_cu, 1);
5894 VEC_safe_push (dwarf2_per_cu_ptr,
5895 cu->per_cu->imported_symtabs, per_cu);
5903 /* If the die has a sibling, skip to the sibling. */
5905 pdi = pdi->die_sibling;
5909 /* Functions used to compute the fully scoped name of a partial DIE.
5911 Normally, this is simple. For C++, the parent DIE's fully scoped
5912 name is concatenated with "::" and the partial DIE's name. For
5913 Java, the same thing occurs except that "." is used instead of "::".
5914 Enumerators are an exception; they use the scope of their parent
5915 enumeration type, i.e. the name of the enumeration type is not
5916 prepended to the enumerator.
5918 There are two complexities. One is DW_AT_specification; in this
5919 case "parent" means the parent of the target of the specification,
5920 instead of the direct parent of the DIE. The other is compilers
5921 which do not emit DW_TAG_namespace; in this case we try to guess
5922 the fully qualified name of structure types from their members'
5923 linkage names. This must be done using the DIE's children rather
5924 than the children of any DW_AT_specification target. We only need
5925 to do this for structures at the top level, i.e. if the target of
5926 any DW_AT_specification (if any; otherwise the DIE itself) does not
5929 /* Compute the scope prefix associated with PDI's parent, in
5930 compilation unit CU. The result will be allocated on CU's
5931 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5932 field. NULL is returned if no prefix is necessary. */
5934 partial_die_parent_scope (struct partial_die_info *pdi,
5935 struct dwarf2_cu *cu)
5937 const char *grandparent_scope;
5938 struct partial_die_info *parent, *real_pdi;
5940 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5941 then this means the parent of the specification DIE. */
5944 while (real_pdi->has_specification)
5945 real_pdi = find_partial_die (real_pdi->spec_offset,
5946 real_pdi->spec_is_dwz, cu);
5948 parent = real_pdi->die_parent;
5952 if (parent->scope_set)
5953 return parent->scope;
5955 fixup_partial_die (parent, cu);
5957 grandparent_scope = partial_die_parent_scope (parent, cu);
5959 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5960 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5961 Work around this problem here. */
5962 if (cu->language == language_cplus
5963 && parent->tag == DW_TAG_namespace
5964 && strcmp (parent->name, "::") == 0
5965 && grandparent_scope == NULL)
5967 parent->scope = NULL;
5968 parent->scope_set = 1;
5972 if (pdi->tag == DW_TAG_enumerator)
5973 /* Enumerators should not get the name of the enumeration as a prefix. */
5974 parent->scope = grandparent_scope;
5975 else if (parent->tag == DW_TAG_namespace
5976 || parent->tag == DW_TAG_module
5977 || parent->tag == DW_TAG_structure_type
5978 || parent->tag == DW_TAG_class_type
5979 || parent->tag == DW_TAG_interface_type
5980 || parent->tag == DW_TAG_union_type
5981 || parent->tag == DW_TAG_enumeration_type)
5983 if (grandparent_scope == NULL)
5984 parent->scope = parent->name;
5986 parent->scope = typename_concat (&cu->comp_unit_obstack,
5988 parent->name, 0, cu);
5992 /* FIXME drow/2004-04-01: What should we be doing with
5993 function-local names? For partial symbols, we should probably be
5995 complaint (&symfile_complaints,
5996 _("unhandled containing DIE tag %d for DIE at %d"),
5997 parent->tag, pdi->offset.sect_off);
5998 parent->scope = grandparent_scope;
6001 parent->scope_set = 1;
6002 return parent->scope;
6005 /* Return the fully scoped name associated with PDI, from compilation unit
6006 CU. The result will be allocated with malloc. */
6009 partial_die_full_name (struct partial_die_info *pdi,
6010 struct dwarf2_cu *cu)
6012 const char *parent_scope;
6014 /* If this is a template instantiation, we can not work out the
6015 template arguments from partial DIEs. So, unfortunately, we have
6016 to go through the full DIEs. At least any work we do building
6017 types here will be reused if full symbols are loaded later. */
6018 if (pdi->has_template_arguments)
6020 fixup_partial_die (pdi, cu);
6022 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
6024 struct die_info *die;
6025 struct attribute attr;
6026 struct dwarf2_cu *ref_cu = cu;
6028 /* DW_FORM_ref_addr is using section offset. */
6030 attr.form = DW_FORM_ref_addr;
6031 attr.u.unsnd = pdi->offset.sect_off;
6032 die = follow_die_ref (NULL, &attr, &ref_cu);
6034 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
6038 parent_scope = partial_die_parent_scope (pdi, cu);
6039 if (parent_scope == NULL)
6042 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
6046 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
6048 struct objfile *objfile = cu->objfile;
6050 const char *actual_name = NULL;
6052 char *built_actual_name;
6054 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6056 built_actual_name = partial_die_full_name (pdi, cu);
6057 if (built_actual_name != NULL)
6058 actual_name = built_actual_name;
6060 if (actual_name == NULL)
6061 actual_name = pdi->name;
6065 case DW_TAG_subprogram:
6066 if (pdi->is_external || cu->language == language_ada)
6068 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
6069 of the global scope. But in Ada, we want to be able to access
6070 nested procedures globally. So all Ada subprograms are stored
6071 in the global scope. */
6072 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
6073 mst_text, objfile); */
6074 add_psymbol_to_list (actual_name, strlen (actual_name),
6075 built_actual_name != NULL,
6076 VAR_DOMAIN, LOC_BLOCK,
6077 &objfile->global_psymbols,
6078 0, pdi->lowpc + baseaddr,
6079 cu->language, objfile);
6083 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
6084 mst_file_text, objfile); */
6085 add_psymbol_to_list (actual_name, strlen (actual_name),
6086 built_actual_name != NULL,
6087 VAR_DOMAIN, LOC_BLOCK,
6088 &objfile->static_psymbols,
6089 0, pdi->lowpc + baseaddr,
6090 cu->language, objfile);
6093 case DW_TAG_constant:
6095 struct psymbol_allocation_list *list;
6097 if (pdi->is_external)
6098 list = &objfile->global_psymbols;
6100 list = &objfile->static_psymbols;
6101 add_psymbol_to_list (actual_name, strlen (actual_name),
6102 built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
6103 list, 0, 0, cu->language, objfile);
6106 case DW_TAG_variable:
6108 addr = decode_locdesc (pdi->d.locdesc, cu);
6112 && !dwarf2_per_objfile->has_section_at_zero)
6114 /* A global or static variable may also have been stripped
6115 out by the linker if unused, in which case its address
6116 will be nullified; do not add such variables into partial
6117 symbol table then. */
6119 else if (pdi->is_external)
6122 Don't enter into the minimal symbol tables as there is
6123 a minimal symbol table entry from the ELF symbols already.
6124 Enter into partial symbol table if it has a location
6125 descriptor or a type.
6126 If the location descriptor is missing, new_symbol will create
6127 a LOC_UNRESOLVED symbol, the address of the variable will then
6128 be determined from the minimal symbol table whenever the variable
6130 The address for the partial symbol table entry is not
6131 used by GDB, but it comes in handy for debugging partial symbol
6134 if (pdi->d.locdesc || pdi->has_type)
6135 add_psymbol_to_list (actual_name, strlen (actual_name),
6136 built_actual_name != NULL,
6137 VAR_DOMAIN, LOC_STATIC,
6138 &objfile->global_psymbols,
6140 cu->language, objfile);
6144 /* Static Variable. Skip symbols without location descriptors. */
6145 if (pdi->d.locdesc == NULL)
6147 xfree (built_actual_name);
6150 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
6151 mst_file_data, objfile); */
6152 add_psymbol_to_list (actual_name, strlen (actual_name),
6153 built_actual_name != NULL,
6154 VAR_DOMAIN, LOC_STATIC,
6155 &objfile->static_psymbols,
6157 cu->language, objfile);
6160 case DW_TAG_typedef:
6161 case DW_TAG_base_type:
6162 case DW_TAG_subrange_type:
6163 add_psymbol_to_list (actual_name, strlen (actual_name),
6164 built_actual_name != NULL,
6165 VAR_DOMAIN, LOC_TYPEDEF,
6166 &objfile->static_psymbols,
6167 0, (CORE_ADDR) 0, cu->language, objfile);
6169 case DW_TAG_namespace:
6170 add_psymbol_to_list (actual_name, strlen (actual_name),
6171 built_actual_name != NULL,
6172 VAR_DOMAIN, LOC_TYPEDEF,
6173 &objfile->global_psymbols,
6174 0, (CORE_ADDR) 0, cu->language, objfile);
6176 case DW_TAG_class_type:
6177 case DW_TAG_interface_type:
6178 case DW_TAG_structure_type:
6179 case DW_TAG_union_type:
6180 case DW_TAG_enumeration_type:
6181 /* Skip external references. The DWARF standard says in the section
6182 about "Structure, Union, and Class Type Entries": "An incomplete
6183 structure, union or class type is represented by a structure,
6184 union or class entry that does not have a byte size attribute
6185 and that has a DW_AT_declaration attribute." */
6186 if (!pdi->has_byte_size && pdi->is_declaration)
6188 xfree (built_actual_name);
6192 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
6193 static vs. global. */
6194 add_psymbol_to_list (actual_name, strlen (actual_name),
6195 built_actual_name != NULL,
6196 STRUCT_DOMAIN, LOC_TYPEDEF,
6197 (cu->language == language_cplus
6198 || cu->language == language_java)
6199 ? &objfile->global_psymbols
6200 : &objfile->static_psymbols,
6201 0, (CORE_ADDR) 0, cu->language, objfile);
6204 case DW_TAG_enumerator:
6205 add_psymbol_to_list (actual_name, strlen (actual_name),
6206 built_actual_name != NULL,
6207 VAR_DOMAIN, LOC_CONST,
6208 (cu->language == language_cplus
6209 || cu->language == language_java)
6210 ? &objfile->global_psymbols
6211 : &objfile->static_psymbols,
6212 0, (CORE_ADDR) 0, cu->language, objfile);
6218 xfree (built_actual_name);
6221 /* Read a partial die corresponding to a namespace; also, add a symbol
6222 corresponding to that namespace to the symbol table. NAMESPACE is
6223 the name of the enclosing namespace. */
6226 add_partial_namespace (struct partial_die_info *pdi,
6227 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6228 int need_pc, struct dwarf2_cu *cu)
6230 /* Add a symbol for the namespace. */
6232 add_partial_symbol (pdi, cu);
6234 /* Now scan partial symbols in that namespace. */
6236 if (pdi->has_children)
6237 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
6240 /* Read a partial die corresponding to a Fortran module. */
6243 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
6244 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
6246 /* Now scan partial symbols in that module. */
6248 if (pdi->has_children)
6249 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
6252 /* Read a partial die corresponding to a subprogram and create a partial
6253 symbol for that subprogram. When the CU language allows it, this
6254 routine also defines a partial symbol for each nested subprogram
6255 that this subprogram contains.
6257 DIE my also be a lexical block, in which case we simply search
6258 recursively for suprograms defined inside that lexical block.
6259 Again, this is only performed when the CU language allows this
6260 type of definitions. */
6263 add_partial_subprogram (struct partial_die_info *pdi,
6264 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6265 int need_pc, struct dwarf2_cu *cu)
6267 if (pdi->tag == DW_TAG_subprogram)
6269 if (pdi->has_pc_info)
6271 if (pdi->lowpc < *lowpc)
6272 *lowpc = pdi->lowpc;
6273 if (pdi->highpc > *highpc)
6274 *highpc = pdi->highpc;
6278 struct objfile *objfile = cu->objfile;
6280 baseaddr = ANOFFSET (objfile->section_offsets,
6281 SECT_OFF_TEXT (objfile));
6282 addrmap_set_empty (objfile->psymtabs_addrmap,
6283 pdi->lowpc + baseaddr,
6284 pdi->highpc - 1 + baseaddr,
6285 cu->per_cu->v.psymtab);
6289 if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined))
6291 if (!pdi->is_declaration)
6292 /* Ignore subprogram DIEs that do not have a name, they are
6293 illegal. Do not emit a complaint at this point, we will
6294 do so when we convert this psymtab into a symtab. */
6296 add_partial_symbol (pdi, cu);
6300 if (! pdi->has_children)
6303 if (cu->language == language_ada)
6305 pdi = pdi->die_child;
6308 fixup_partial_die (pdi, cu);
6309 if (pdi->tag == DW_TAG_subprogram
6310 || pdi->tag == DW_TAG_lexical_block)
6311 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
6312 pdi = pdi->die_sibling;
6317 /* Read a partial die corresponding to an enumeration type. */
6320 add_partial_enumeration (struct partial_die_info *enum_pdi,
6321 struct dwarf2_cu *cu)
6323 struct partial_die_info *pdi;
6325 if (enum_pdi->name != NULL)
6326 add_partial_symbol (enum_pdi, cu);
6328 pdi = enum_pdi->die_child;
6331 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
6332 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
6334 add_partial_symbol (pdi, cu);
6335 pdi = pdi->die_sibling;
6339 /* Return the initial uleb128 in the die at INFO_PTR. */
6342 peek_abbrev_code (bfd *abfd, const gdb_byte *info_ptr)
6344 unsigned int bytes_read;
6346 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6349 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6350 Return the corresponding abbrev, or NULL if the number is zero (indicating
6351 an empty DIE). In either case *BYTES_READ will be set to the length of
6352 the initial number. */
6354 static struct abbrev_info *
6355 peek_die_abbrev (const gdb_byte *info_ptr, unsigned int *bytes_read,
6356 struct dwarf2_cu *cu)
6358 bfd *abfd = cu->objfile->obfd;
6359 unsigned int abbrev_number;
6360 struct abbrev_info *abbrev;
6362 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
6364 if (abbrev_number == 0)
6367 abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number);
6370 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6371 abbrev_number, bfd_get_filename (abfd));
6377 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6378 Returns a pointer to the end of a series of DIEs, terminated by an empty
6379 DIE. Any children of the skipped DIEs will also be skipped. */
6381 static const gdb_byte *
6382 skip_children (const struct die_reader_specs *reader, const gdb_byte *info_ptr)
6384 struct dwarf2_cu *cu = reader->cu;
6385 struct abbrev_info *abbrev;
6386 unsigned int bytes_read;
6390 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
6392 return info_ptr + bytes_read;
6394 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
6398 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6399 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6400 abbrev corresponding to that skipped uleb128 should be passed in
6401 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6404 static const gdb_byte *
6405 skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr,
6406 struct abbrev_info *abbrev)
6408 unsigned int bytes_read;
6409 struct attribute attr;
6410 bfd *abfd = reader->abfd;
6411 struct dwarf2_cu *cu = reader->cu;
6412 const gdb_byte *buffer = reader->buffer;
6413 const gdb_byte *buffer_end = reader->buffer_end;
6414 const gdb_byte *start_info_ptr = info_ptr;
6415 unsigned int form, i;
6417 for (i = 0; i < abbrev->num_attrs; i++)
6419 /* The only abbrev we care about is DW_AT_sibling. */
6420 if (abbrev->attrs[i].name == DW_AT_sibling)
6422 read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
6423 if (attr.form == DW_FORM_ref_addr)
6424 complaint (&symfile_complaints,
6425 _("ignoring absolute DW_AT_sibling"));
6427 return buffer + dwarf2_get_ref_die_offset (&attr).sect_off;
6430 /* If it isn't DW_AT_sibling, skip this attribute. */
6431 form = abbrev->attrs[i].form;
6435 case DW_FORM_ref_addr:
6436 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6437 and later it is offset sized. */
6438 if (cu->header.version == 2)
6439 info_ptr += cu->header.addr_size;
6441 info_ptr += cu->header.offset_size;
6443 case DW_FORM_GNU_ref_alt:
6444 info_ptr += cu->header.offset_size;
6447 info_ptr += cu->header.addr_size;
6454 case DW_FORM_flag_present:
6466 case DW_FORM_ref_sig8:
6469 case DW_FORM_string:
6470 read_direct_string (abfd, info_ptr, &bytes_read);
6471 info_ptr += bytes_read;
6473 case DW_FORM_sec_offset:
6475 case DW_FORM_GNU_strp_alt:
6476 info_ptr += cu->header.offset_size;
6478 case DW_FORM_exprloc:
6480 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6481 info_ptr += bytes_read;
6483 case DW_FORM_block1:
6484 info_ptr += 1 + read_1_byte (abfd, info_ptr);
6486 case DW_FORM_block2:
6487 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
6489 case DW_FORM_block4:
6490 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
6494 case DW_FORM_ref_udata:
6495 case DW_FORM_GNU_addr_index:
6496 case DW_FORM_GNU_str_index:
6497 info_ptr = safe_skip_leb128 (info_ptr, buffer_end);
6499 case DW_FORM_indirect:
6500 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6501 info_ptr += bytes_read;
6502 /* We need to continue parsing from here, so just go back to
6504 goto skip_attribute;
6507 error (_("Dwarf Error: Cannot handle %s "
6508 "in DWARF reader [in module %s]"),
6509 dwarf_form_name (form),
6510 bfd_get_filename (abfd));
6514 if (abbrev->has_children)
6515 return skip_children (reader, info_ptr);
6520 /* Locate ORIG_PDI's sibling.
6521 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6523 static const gdb_byte *
6524 locate_pdi_sibling (const struct die_reader_specs *reader,
6525 struct partial_die_info *orig_pdi,
6526 const gdb_byte *info_ptr)
6528 /* Do we know the sibling already? */
6530 if (orig_pdi->sibling)
6531 return orig_pdi->sibling;
6533 /* Are there any children to deal with? */
6535 if (!orig_pdi->has_children)
6538 /* Skip the children the long way. */
6540 return skip_children (reader, info_ptr);
6543 /* Expand this partial symbol table into a full symbol table. SELF is
6547 dwarf2_read_symtab (struct partial_symtab *self,
6548 struct objfile *objfile)
6552 warning (_("bug: psymtab for %s is already read in."),
6559 printf_filtered (_("Reading in symbols for %s..."),
6561 gdb_flush (gdb_stdout);
6564 /* Restore our global data. */
6565 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
6567 /* If this psymtab is constructed from a debug-only objfile, the
6568 has_section_at_zero flag will not necessarily be correct. We
6569 can get the correct value for this flag by looking at the data
6570 associated with the (presumably stripped) associated objfile. */
6571 if (objfile->separate_debug_objfile_backlink)
6573 struct dwarf2_per_objfile *dpo_backlink
6574 = objfile_data (objfile->separate_debug_objfile_backlink,
6575 dwarf2_objfile_data_key);
6577 dwarf2_per_objfile->has_section_at_zero
6578 = dpo_backlink->has_section_at_zero;
6581 dwarf2_per_objfile->reading_partial_symbols = 0;
6583 psymtab_to_symtab_1 (self);
6585 /* Finish up the debug error message. */
6587 printf_filtered (_("done.\n"));
6590 process_cu_includes ();
6593 /* Reading in full CUs. */
6595 /* Add PER_CU to the queue. */
6598 queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
6599 enum language pretend_language)
6601 struct dwarf2_queue_item *item;
6604 item = xmalloc (sizeof (*item));
6605 item->per_cu = per_cu;
6606 item->pretend_language = pretend_language;
6609 if (dwarf2_queue == NULL)
6610 dwarf2_queue = item;
6612 dwarf2_queue_tail->next = item;
6614 dwarf2_queue_tail = item;
6617 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6618 unit and add it to our queue.
6619 The result is non-zero if PER_CU was queued, otherwise the result is zero
6620 meaning either PER_CU is already queued or it is already loaded. */
6623 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
6624 struct dwarf2_per_cu_data *per_cu,
6625 enum language pretend_language)
6627 /* We may arrive here during partial symbol reading, if we need full
6628 DIEs to process an unusual case (e.g. template arguments). Do
6629 not queue PER_CU, just tell our caller to load its DIEs. */
6630 if (dwarf2_per_objfile->reading_partial_symbols)
6632 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
6637 /* Mark the dependence relation so that we don't flush PER_CU
6639 dwarf2_add_dependence (this_cu, per_cu);
6641 /* If it's already on the queue, we have nothing to do. */
6645 /* If the compilation unit is already loaded, just mark it as
6647 if (per_cu->cu != NULL)
6649 per_cu->cu->last_used = 0;
6653 /* Add it to the queue. */
6654 queue_comp_unit (per_cu, pretend_language);
6659 /* Process the queue. */
6662 process_queue (void)
6664 struct dwarf2_queue_item *item, *next_item;
6666 if (dwarf2_read_debug)
6668 fprintf_unfiltered (gdb_stdlog,
6669 "Expanding one or more symtabs of objfile %s ...\n",
6670 dwarf2_per_objfile->objfile->name);
6673 /* The queue starts out with one item, but following a DIE reference
6674 may load a new CU, adding it to the end of the queue. */
6675 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
6677 if (dwarf2_per_objfile->using_index
6678 ? !item->per_cu->v.quick->symtab
6679 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
6681 struct dwarf2_per_cu_data *per_cu = item->per_cu;
6683 if (dwarf2_read_debug)
6685 fprintf_unfiltered (gdb_stdlog,
6686 "Expanding symtab of %s at offset 0x%x\n",
6687 per_cu->is_debug_types ? "TU" : "CU",
6688 per_cu->offset.sect_off);
6691 if (per_cu->is_debug_types)
6692 process_full_type_unit (per_cu, item->pretend_language);
6694 process_full_comp_unit (per_cu, item->pretend_language);
6696 if (dwarf2_read_debug)
6698 fprintf_unfiltered (gdb_stdlog,
6699 "Done expanding %s at offset 0x%x\n",
6700 per_cu->is_debug_types ? "TU" : "CU",
6701 per_cu->offset.sect_off);
6705 item->per_cu->queued = 0;
6706 next_item = item->next;
6710 dwarf2_queue_tail = NULL;
6712 if (dwarf2_read_debug)
6714 fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n",
6715 dwarf2_per_objfile->objfile->name);
6719 /* Free all allocated queue entries. This function only releases anything if
6720 an error was thrown; if the queue was processed then it would have been
6721 freed as we went along. */
6724 dwarf2_release_queue (void *dummy)
6726 struct dwarf2_queue_item *item, *last;
6728 item = dwarf2_queue;
6731 /* Anything still marked queued is likely to be in an
6732 inconsistent state, so discard it. */
6733 if (item->per_cu->queued)
6735 if (item->per_cu->cu != NULL)
6736 free_one_cached_comp_unit (item->per_cu);
6737 item->per_cu->queued = 0;
6745 dwarf2_queue = dwarf2_queue_tail = NULL;
6748 /* Read in full symbols for PST, and anything it depends on. */
6751 psymtab_to_symtab_1 (struct partial_symtab *pst)
6753 struct dwarf2_per_cu_data *per_cu;
6759 for (i = 0; i < pst->number_of_dependencies; i++)
6760 if (!pst->dependencies[i]->readin
6761 && pst->dependencies[i]->user == NULL)
6763 /* Inform about additional files that need to be read in. */
6766 /* FIXME: i18n: Need to make this a single string. */
6767 fputs_filtered (" ", gdb_stdout);
6769 fputs_filtered ("and ", gdb_stdout);
6771 printf_filtered ("%s...", pst->dependencies[i]->filename);
6772 wrap_here (""); /* Flush output. */
6773 gdb_flush (gdb_stdout);
6775 psymtab_to_symtab_1 (pst->dependencies[i]);
6778 per_cu = pst->read_symtab_private;
6782 /* It's an include file, no symbols to read for it.
6783 Everything is in the parent symtab. */
6788 dw2_do_instantiate_symtab (per_cu);
6791 /* Trivial hash function for die_info: the hash value of a DIE
6792 is its offset in .debug_info for this objfile. */
6795 die_hash (const void *item)
6797 const struct die_info *die = item;
6799 return die->offset.sect_off;
6802 /* Trivial comparison function for die_info structures: two DIEs
6803 are equal if they have the same offset. */
6806 die_eq (const void *item_lhs, const void *item_rhs)
6808 const struct die_info *die_lhs = item_lhs;
6809 const struct die_info *die_rhs = item_rhs;
6811 return die_lhs->offset.sect_off == die_rhs->offset.sect_off;
6814 /* die_reader_func for load_full_comp_unit.
6815 This is identical to read_signatured_type_reader,
6816 but is kept separate for now. */
6819 load_full_comp_unit_reader (const struct die_reader_specs *reader,
6820 const gdb_byte *info_ptr,
6821 struct die_info *comp_unit_die,
6825 struct dwarf2_cu *cu = reader->cu;
6826 enum language *language_ptr = data;
6828 gdb_assert (cu->die_hash == NULL);
6830 htab_create_alloc_ex (cu->header.length / 12,
6834 &cu->comp_unit_obstack,
6835 hashtab_obstack_allocate,
6836 dummy_obstack_deallocate);
6839 comp_unit_die->child = read_die_and_siblings (reader, info_ptr,
6840 &info_ptr, comp_unit_die);
6841 cu->dies = comp_unit_die;
6842 /* comp_unit_die is not stored in die_hash, no need. */
6844 /* We try not to read any attributes in this function, because not
6845 all CUs needed for references have been loaded yet, and symbol
6846 table processing isn't initialized. But we have to set the CU language,
6847 or we won't be able to build types correctly.
6848 Similarly, if we do not read the producer, we can not apply
6849 producer-specific interpretation. */
6850 prepare_one_comp_unit (cu, cu->dies, *language_ptr);
6853 /* Load the DIEs associated with PER_CU into memory. */
6856 load_full_comp_unit (struct dwarf2_per_cu_data *this_cu,
6857 enum language pretend_language)
6859 gdb_assert (! this_cu->is_debug_types);
6861 init_cutu_and_read_dies (this_cu, NULL, 1, 1,
6862 load_full_comp_unit_reader, &pretend_language);
6865 /* Add a DIE to the delayed physname list. */
6868 add_to_method_list (struct type *type, int fnfield_index, int index,
6869 const char *name, struct die_info *die,
6870 struct dwarf2_cu *cu)
6872 struct delayed_method_info mi;
6874 mi.fnfield_index = fnfield_index;
6878 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
6881 /* A cleanup for freeing the delayed method list. */
6884 free_delayed_list (void *ptr)
6886 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
6887 if (cu->method_list != NULL)
6889 VEC_free (delayed_method_info, cu->method_list);
6890 cu->method_list = NULL;
6894 /* Compute the physnames of any methods on the CU's method list.
6896 The computation of method physnames is delayed in order to avoid the
6897 (bad) condition that one of the method's formal parameters is of an as yet
6901 compute_delayed_physnames (struct dwarf2_cu *cu)
6904 struct delayed_method_info *mi;
6905 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
6907 const char *physname;
6908 struct fn_fieldlist *fn_flp
6909 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
6910 physname = dwarf2_physname (mi->name, mi->die, cu);
6911 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
6915 /* Go objects should be embedded in a DW_TAG_module DIE,
6916 and it's not clear if/how imported objects will appear.
6917 To keep Go support simple until that's worked out,
6918 go back through what we've read and create something usable.
6919 We could do this while processing each DIE, and feels kinda cleaner,
6920 but that way is more invasive.
6921 This is to, for example, allow the user to type "p var" or "b main"
6922 without having to specify the package name, and allow lookups
6923 of module.object to work in contexts that use the expression
6927 fixup_go_packaging (struct dwarf2_cu *cu)
6929 char *package_name = NULL;
6930 struct pending *list;
6933 for (list = global_symbols; list != NULL; list = list->next)
6935 for (i = 0; i < list->nsyms; ++i)
6937 struct symbol *sym = list->symbol[i];
6939 if (SYMBOL_LANGUAGE (sym) == language_go
6940 && SYMBOL_CLASS (sym) == LOC_BLOCK)
6942 char *this_package_name = go_symbol_package_name (sym);
6944 if (this_package_name == NULL)
6946 if (package_name == NULL)
6947 package_name = this_package_name;
6950 if (strcmp (package_name, this_package_name) != 0)
6951 complaint (&symfile_complaints,
6952 _("Symtab %s has objects from two different Go packages: %s and %s"),
6953 (SYMBOL_SYMTAB (sym)
6954 ? symtab_to_filename_for_display (SYMBOL_SYMTAB (sym))
6955 : cu->objfile->name),
6956 this_package_name, package_name);
6957 xfree (this_package_name);
6963 if (package_name != NULL)
6965 struct objfile *objfile = cu->objfile;
6966 const char *saved_package_name = obstack_copy0 (&objfile->objfile_obstack,
6968 strlen (package_name));
6969 struct type *type = init_type (TYPE_CODE_MODULE, 0, 0,
6970 saved_package_name, objfile);
6973 TYPE_TAG_NAME (type) = TYPE_NAME (type);
6975 sym = allocate_symbol (objfile);
6976 SYMBOL_SET_LANGUAGE (sym, language_go, &objfile->objfile_obstack);
6977 SYMBOL_SET_NAMES (sym, saved_package_name,
6978 strlen (saved_package_name), 0, objfile);
6979 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6980 e.g., "main" finds the "main" module and not C's main(). */
6981 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
6982 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
6983 SYMBOL_TYPE (sym) = type;
6985 add_symbol_to_list (sym, &global_symbols);
6987 xfree (package_name);
6991 /* Return the symtab for PER_CU. This works properly regardless of
6992 whether we're using the index or psymtabs. */
6994 static struct symtab *
6995 get_symtab (struct dwarf2_per_cu_data *per_cu)
6997 return (dwarf2_per_objfile->using_index
6998 ? per_cu->v.quick->symtab
6999 : per_cu->v.psymtab->symtab);
7002 /* A helper function for computing the list of all symbol tables
7003 included by PER_CU. */
7006 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr) **result,
7007 htab_t all_children,
7008 struct dwarf2_per_cu_data *per_cu)
7012 struct dwarf2_per_cu_data *iter;
7014 slot = htab_find_slot (all_children, per_cu, INSERT);
7017 /* This inclusion and its children have been processed. */
7022 /* Only add a CU if it has a symbol table. */
7023 if (get_symtab (per_cu) != NULL)
7024 VEC_safe_push (dwarf2_per_cu_ptr, *result, per_cu);
7027 VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter);
7029 recursively_compute_inclusions (result, all_children, iter);
7032 /* Compute the symtab 'includes' fields for the symtab related to
7036 compute_symtab_includes (struct dwarf2_per_cu_data *per_cu)
7038 gdb_assert (! per_cu->is_debug_types);
7040 if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs))
7043 struct dwarf2_per_cu_data *iter;
7044 VEC (dwarf2_per_cu_ptr) *result_children = NULL;
7045 htab_t all_children;
7046 struct symtab *symtab = get_symtab (per_cu);
7048 /* If we don't have a symtab, we can just skip this case. */
7052 all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
7053 NULL, xcalloc, xfree);
7056 VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs,
7059 recursively_compute_inclusions (&result_children, all_children, iter);
7061 /* Now we have a transitive closure of all the included CUs, and
7062 for .gdb_index version 7 the included TUs, so we can convert it
7063 to a list of symtabs. */
7064 len = VEC_length (dwarf2_per_cu_ptr, result_children);
7066 = obstack_alloc (&dwarf2_per_objfile->objfile->objfile_obstack,
7067 (len + 1) * sizeof (struct symtab *));
7069 VEC_iterate (dwarf2_per_cu_ptr, result_children, ix, iter);
7071 symtab->includes[ix] = get_symtab (iter);
7072 symtab->includes[len] = NULL;
7074 VEC_free (dwarf2_per_cu_ptr, result_children);
7075 htab_delete (all_children);
7079 /* Compute the 'includes' field for the symtabs of all the CUs we just
7083 process_cu_includes (void)
7086 struct dwarf2_per_cu_data *iter;
7089 VEC_iterate (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus,
7093 if (! iter->is_debug_types)
7094 compute_symtab_includes (iter);
7097 VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus);
7100 /* Generate full symbol information for PER_CU, whose DIEs have
7101 already been loaded into memory. */
7104 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
7105 enum language pretend_language)
7107 struct dwarf2_cu *cu = per_cu->cu;
7108 struct objfile *objfile = per_cu->objfile;
7109 CORE_ADDR lowpc, highpc;
7110 struct symtab *symtab;
7111 struct cleanup *back_to, *delayed_list_cleanup;
7113 struct block *static_block;
7115 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
7118 back_to = make_cleanup (really_free_pendings, NULL);
7119 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
7121 cu->list_in_scope = &file_symbols;
7123 cu->language = pretend_language;
7124 cu->language_defn = language_def (cu->language);
7126 /* Do line number decoding in read_file_scope () */
7127 process_die (cu->dies, cu);
7129 /* For now fudge the Go package. */
7130 if (cu->language == language_go)
7131 fixup_go_packaging (cu);
7133 /* Now that we have processed all the DIEs in the CU, all the types
7134 should be complete, and it should now be safe to compute all of the
7136 compute_delayed_physnames (cu);
7137 do_cleanups (delayed_list_cleanup);
7139 /* Some compilers don't define a DW_AT_high_pc attribute for the
7140 compilation unit. If the DW_AT_high_pc is missing, synthesize
7141 it, by scanning the DIE's below the compilation unit. */
7142 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
7145 = end_symtab_get_static_block (highpc + baseaddr, objfile, 0, 1);
7147 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
7148 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
7149 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
7150 addrmap to help ensure it has an accurate map of pc values belonging to
7152 dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu);
7154 symtab = end_symtab_from_static_block (static_block, objfile,
7155 SECT_OFF_TEXT (objfile), 0);
7159 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
7161 /* Set symtab language to language from DW_AT_language. If the
7162 compilation is from a C file generated by language preprocessors, do
7163 not set the language if it was already deduced by start_subfile. */
7164 if (!(cu->language == language_c && symtab->language != language_c))
7165 symtab->language = cu->language;
7167 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
7168 produce DW_AT_location with location lists but it can be possibly
7169 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
7170 there were bugs in prologue debug info, fixed later in GCC-4.5
7171 by "unwind info for epilogues" patch (which is not directly related).
7173 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
7174 needed, it would be wrong due to missing DW_AT_producer there.
7176 Still one can confuse GDB by using non-standard GCC compilation
7177 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
7179 if (cu->has_loclist && gcc_4_minor >= 5)
7180 symtab->locations_valid = 1;
7182 if (gcc_4_minor >= 5)
7183 symtab->epilogue_unwind_valid = 1;
7185 symtab->call_site_htab = cu->call_site_htab;
7188 if (dwarf2_per_objfile->using_index)
7189 per_cu->v.quick->symtab = symtab;
7192 struct partial_symtab *pst = per_cu->v.psymtab;
7193 pst->symtab = symtab;
7197 /* Push it for inclusion processing later. */
7198 VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu);
7200 do_cleanups (back_to);
7203 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7204 already been loaded into memory. */
7207 process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
7208 enum language pretend_language)
7210 struct dwarf2_cu *cu = per_cu->cu;
7211 struct objfile *objfile = per_cu->objfile;
7212 struct symtab *symtab;
7213 struct cleanup *back_to, *delayed_list_cleanup;
7214 struct signatured_type *sig_type;
7216 gdb_assert (per_cu->is_debug_types);
7217 sig_type = (struct signatured_type *) per_cu;
7220 back_to = make_cleanup (really_free_pendings, NULL);
7221 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
7223 cu->list_in_scope = &file_symbols;
7225 cu->language = pretend_language;
7226 cu->language_defn = language_def (cu->language);
7228 /* The symbol tables are set up in read_type_unit_scope. */
7229 process_die (cu->dies, cu);
7231 /* For now fudge the Go package. */
7232 if (cu->language == language_go)
7233 fixup_go_packaging (cu);
7235 /* Now that we have processed all the DIEs in the CU, all the types
7236 should be complete, and it should now be safe to compute all of the
7238 compute_delayed_physnames (cu);
7239 do_cleanups (delayed_list_cleanup);
7241 /* TUs share symbol tables.
7242 If this is the first TU to use this symtab, complete the construction
7243 of it with end_expandable_symtab. Otherwise, complete the addition of
7244 this TU's symbols to the existing symtab. */
7245 if (sig_type->type_unit_group->primary_symtab == NULL)
7247 symtab = end_expandable_symtab (0, objfile, SECT_OFF_TEXT (objfile));
7248 sig_type->type_unit_group->primary_symtab = symtab;
7252 /* Set symtab language to language from DW_AT_language. If the
7253 compilation is from a C file generated by language preprocessors,
7254 do not set the language if it was already deduced by
7256 if (!(cu->language == language_c && symtab->language != language_c))
7257 symtab->language = cu->language;
7262 augment_type_symtab (objfile,
7263 sig_type->type_unit_group->primary_symtab);
7264 symtab = sig_type->type_unit_group->primary_symtab;
7267 if (dwarf2_per_objfile->using_index)
7268 per_cu->v.quick->symtab = symtab;
7271 struct partial_symtab *pst = per_cu->v.psymtab;
7272 pst->symtab = symtab;
7276 do_cleanups (back_to);
7279 /* Process an imported unit DIE. */
7282 process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
7284 struct attribute *attr;
7286 /* For now we don't handle imported units in type units. */
7287 if (cu->per_cu->is_debug_types)
7289 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7290 " supported in type units [in module %s]"),
7294 attr = dwarf2_attr (die, DW_AT_import, cu);
7297 struct dwarf2_per_cu_data *per_cu;
7298 struct symtab *imported_symtab;
7302 offset = dwarf2_get_ref_die_offset (attr);
7303 is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
7304 per_cu = dwarf2_find_containing_comp_unit (offset, is_dwz, cu->objfile);
7306 /* Queue the unit, if needed. */
7307 if (maybe_queue_comp_unit (cu, per_cu, cu->language))
7308 load_full_comp_unit (per_cu, cu->language);
7310 VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
7315 /* Process a die and its children. */
7318 process_die (struct die_info *die, struct dwarf2_cu *cu)
7322 case DW_TAG_padding:
7324 case DW_TAG_compile_unit:
7325 case DW_TAG_partial_unit:
7326 read_file_scope (die, cu);
7328 case DW_TAG_type_unit:
7329 read_type_unit_scope (die, cu);
7331 case DW_TAG_subprogram:
7332 case DW_TAG_inlined_subroutine:
7333 read_func_scope (die, cu);
7335 case DW_TAG_lexical_block:
7336 case DW_TAG_try_block:
7337 case DW_TAG_catch_block:
7338 read_lexical_block_scope (die, cu);
7340 case DW_TAG_GNU_call_site:
7341 read_call_site_scope (die, cu);
7343 case DW_TAG_class_type:
7344 case DW_TAG_interface_type:
7345 case DW_TAG_structure_type:
7346 case DW_TAG_union_type:
7347 process_structure_scope (die, cu);
7349 case DW_TAG_enumeration_type:
7350 process_enumeration_scope (die, cu);
7353 /* These dies have a type, but processing them does not create
7354 a symbol or recurse to process the children. Therefore we can
7355 read them on-demand through read_type_die. */
7356 case DW_TAG_subroutine_type:
7357 case DW_TAG_set_type:
7358 case DW_TAG_array_type:
7359 case DW_TAG_pointer_type:
7360 case DW_TAG_ptr_to_member_type:
7361 case DW_TAG_reference_type:
7362 case DW_TAG_string_type:
7365 case DW_TAG_base_type:
7366 case DW_TAG_subrange_type:
7367 case DW_TAG_typedef:
7368 /* Add a typedef symbol for the type definition, if it has a
7370 new_symbol (die, read_type_die (die, cu), cu);
7372 case DW_TAG_common_block:
7373 read_common_block (die, cu);
7375 case DW_TAG_common_inclusion:
7377 case DW_TAG_namespace:
7378 cu->processing_has_namespace_info = 1;
7379 read_namespace (die, cu);
7382 cu->processing_has_namespace_info = 1;
7383 read_module (die, cu);
7385 case DW_TAG_imported_declaration:
7386 case DW_TAG_imported_module:
7387 cu->processing_has_namespace_info = 1;
7388 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
7389 || cu->language != language_fortran))
7390 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
7391 dwarf_tag_name (die->tag));
7392 read_import_statement (die, cu);
7395 case DW_TAG_imported_unit:
7396 process_imported_unit_die (die, cu);
7400 new_symbol (die, NULL, cu);
7405 /* DWARF name computation. */
7407 /* A helper function for dwarf2_compute_name which determines whether DIE
7408 needs to have the name of the scope prepended to the name listed in the
7412 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
7414 struct attribute *attr;
7418 case DW_TAG_namespace:
7419 case DW_TAG_typedef:
7420 case DW_TAG_class_type:
7421 case DW_TAG_interface_type:
7422 case DW_TAG_structure_type:
7423 case DW_TAG_union_type:
7424 case DW_TAG_enumeration_type:
7425 case DW_TAG_enumerator:
7426 case DW_TAG_subprogram:
7430 case DW_TAG_variable:
7431 case DW_TAG_constant:
7432 /* We only need to prefix "globally" visible variables. These include
7433 any variable marked with DW_AT_external or any variable that
7434 lives in a namespace. [Variables in anonymous namespaces
7435 require prefixing, but they are not DW_AT_external.] */
7437 if (dwarf2_attr (die, DW_AT_specification, cu))
7439 struct dwarf2_cu *spec_cu = cu;
7441 return die_needs_namespace (die_specification (die, &spec_cu),
7445 attr = dwarf2_attr (die, DW_AT_external, cu);
7446 if (attr == NULL && die->parent->tag != DW_TAG_namespace
7447 && die->parent->tag != DW_TAG_module)
7449 /* A variable in a lexical block of some kind does not need a
7450 namespace, even though in C++ such variables may be external
7451 and have a mangled name. */
7452 if (die->parent->tag == DW_TAG_lexical_block
7453 || die->parent->tag == DW_TAG_try_block
7454 || die->parent->tag == DW_TAG_catch_block
7455 || die->parent->tag == DW_TAG_subprogram)
7464 /* Retrieve the last character from a mem_file. */
7467 do_ui_file_peek_last (void *object, const char *buffer, long length)
7469 char *last_char_p = (char *) object;
7472 *last_char_p = buffer[length - 1];
7475 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7476 compute the physname for the object, which include a method's:
7477 - formal parameters (C++/Java),
7478 - receiver type (Go),
7479 - return type (Java).
7481 The term "physname" is a bit confusing.
7482 For C++, for example, it is the demangled name.
7483 For Go, for example, it's the mangled name.
7485 For Ada, return the DIE's linkage name rather than the fully qualified
7486 name. PHYSNAME is ignored..
7488 The result is allocated on the objfile_obstack and canonicalized. */
7491 dwarf2_compute_name (const char *name,
7492 struct die_info *die, struct dwarf2_cu *cu,
7495 struct objfile *objfile = cu->objfile;
7498 name = dwarf2_name (die, cu);
7500 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7501 compute it by typename_concat inside GDB. */
7502 if (cu->language == language_ada
7503 || (cu->language == language_fortran && physname))
7505 /* For Ada unit, we prefer the linkage name over the name, as
7506 the former contains the exported name, which the user expects
7507 to be able to reference. Ideally, we want the user to be able
7508 to reference this entity using either natural or linkage name,
7509 but we haven't started looking at this enhancement yet. */
7510 struct attribute *attr;
7512 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
7514 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7515 if (attr && DW_STRING (attr))
7516 return DW_STRING (attr);
7519 /* These are the only languages we know how to qualify names in. */
7521 && (cu->language == language_cplus || cu->language == language_java
7522 || cu->language == language_fortran))
7524 if (die_needs_namespace (die, cu))
7528 struct ui_file *buf;
7530 prefix = determine_prefix (die, cu);
7531 buf = mem_fileopen ();
7532 if (*prefix != '\0')
7534 char *prefixed_name = typename_concat (NULL, prefix, name,
7537 fputs_unfiltered (prefixed_name, buf);
7538 xfree (prefixed_name);
7541 fputs_unfiltered (name, buf);
7543 /* Template parameters may be specified in the DIE's DW_AT_name, or
7544 as children with DW_TAG_template_type_param or
7545 DW_TAG_value_type_param. If the latter, add them to the name
7546 here. If the name already has template parameters, then
7547 skip this step; some versions of GCC emit both, and
7548 it is more efficient to use the pre-computed name.
7550 Something to keep in mind about this process: it is very
7551 unlikely, or in some cases downright impossible, to produce
7552 something that will match the mangled name of a function.
7553 If the definition of the function has the same debug info,
7554 we should be able to match up with it anyway. But fallbacks
7555 using the minimal symbol, for instance to find a method
7556 implemented in a stripped copy of libstdc++, will not work.
7557 If we do not have debug info for the definition, we will have to
7558 match them up some other way.
7560 When we do name matching there is a related problem with function
7561 templates; two instantiated function templates are allowed to
7562 differ only by their return types, which we do not add here. */
7564 if (cu->language == language_cplus && strchr (name, '<') == NULL)
7566 struct attribute *attr;
7567 struct die_info *child;
7570 die->building_fullname = 1;
7572 for (child = die->child; child != NULL; child = child->sibling)
7576 const gdb_byte *bytes;
7577 struct dwarf2_locexpr_baton *baton;
7580 if (child->tag != DW_TAG_template_type_param
7581 && child->tag != DW_TAG_template_value_param)
7586 fputs_unfiltered ("<", buf);
7590 fputs_unfiltered (", ", buf);
7592 attr = dwarf2_attr (child, DW_AT_type, cu);
7595 complaint (&symfile_complaints,
7596 _("template parameter missing DW_AT_type"));
7597 fputs_unfiltered ("UNKNOWN_TYPE", buf);
7600 type = die_type (child, cu);
7602 if (child->tag == DW_TAG_template_type_param)
7604 c_print_type (type, "", buf, -1, 0, &type_print_raw_options);
7608 attr = dwarf2_attr (child, DW_AT_const_value, cu);
7611 complaint (&symfile_complaints,
7612 _("template parameter missing "
7613 "DW_AT_const_value"));
7614 fputs_unfiltered ("UNKNOWN_VALUE", buf);
7618 dwarf2_const_value_attr (attr, type, name,
7619 &cu->comp_unit_obstack, cu,
7620 &value, &bytes, &baton);
7622 if (TYPE_NOSIGN (type))
7623 /* GDB prints characters as NUMBER 'CHAR'. If that's
7624 changed, this can use value_print instead. */
7625 c_printchar (value, type, buf);
7628 struct value_print_options opts;
7631 v = dwarf2_evaluate_loc_desc (type, NULL,
7635 else if (bytes != NULL)
7637 v = allocate_value (type);
7638 memcpy (value_contents_writeable (v), bytes,
7639 TYPE_LENGTH (type));
7642 v = value_from_longest (type, value);
7644 /* Specify decimal so that we do not depend on
7646 get_formatted_print_options (&opts, 'd');
7648 value_print (v, buf, &opts);
7654 die->building_fullname = 0;
7658 /* Close the argument list, with a space if necessary
7659 (nested templates). */
7660 char last_char = '\0';
7661 ui_file_put (buf, do_ui_file_peek_last, &last_char);
7662 if (last_char == '>')
7663 fputs_unfiltered (" >", buf);
7665 fputs_unfiltered (">", buf);
7669 /* For Java and C++ methods, append formal parameter type
7670 information, if PHYSNAME. */
7672 if (physname && die->tag == DW_TAG_subprogram
7673 && (cu->language == language_cplus
7674 || cu->language == language_java))
7676 struct type *type = read_type_die (die, cu);
7678 c_type_print_args (type, buf, 1, cu->language,
7679 &type_print_raw_options);
7681 if (cu->language == language_java)
7683 /* For java, we must append the return type to method
7685 if (die->tag == DW_TAG_subprogram)
7686 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
7687 0, 0, &type_print_raw_options);
7689 else if (cu->language == language_cplus)
7691 /* Assume that an artificial first parameter is
7692 "this", but do not crash if it is not. RealView
7693 marks unnamed (and thus unused) parameters as
7694 artificial; there is no way to differentiate
7696 if (TYPE_NFIELDS (type) > 0
7697 && TYPE_FIELD_ARTIFICIAL (type, 0)
7698 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
7699 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
7701 fputs_unfiltered (" const", buf);
7705 name = ui_file_obsavestring (buf, &objfile->objfile_obstack,
7707 ui_file_delete (buf);
7709 if (cu->language == language_cplus)
7712 = dwarf2_canonicalize_name (name, cu,
7713 &objfile->objfile_obstack);
7724 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7725 If scope qualifiers are appropriate they will be added. The result
7726 will be allocated on the objfile_obstack, or NULL if the DIE does
7727 not have a name. NAME may either be from a previous call to
7728 dwarf2_name or NULL.
7730 The output string will be canonicalized (if C++/Java). */
7733 dwarf2_full_name (const char *name, struct die_info *die, struct dwarf2_cu *cu)
7735 return dwarf2_compute_name (name, die, cu, 0);
7738 /* Construct a physname for the given DIE in CU. NAME may either be
7739 from a previous call to dwarf2_name or NULL. The result will be
7740 allocated on the objfile_objstack or NULL if the DIE does not have a
7743 The output string will be canonicalized (if C++/Java). */
7746 dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu)
7748 struct objfile *objfile = cu->objfile;
7749 struct attribute *attr;
7750 const char *retval, *mangled = NULL, *canon = NULL;
7751 struct cleanup *back_to;
7754 /* In this case dwarf2_compute_name is just a shortcut not building anything
7756 if (!die_needs_namespace (die, cu))
7757 return dwarf2_compute_name (name, die, cu, 1);
7759 back_to = make_cleanup (null_cleanup, NULL);
7761 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
7763 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7765 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7767 if (attr && DW_STRING (attr))
7771 mangled = DW_STRING (attr);
7773 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7774 type. It is easier for GDB users to search for such functions as
7775 `name(params)' than `long name(params)'. In such case the minimal
7776 symbol names do not match the full symbol names but for template
7777 functions there is never a need to look up their definition from their
7778 declaration so the only disadvantage remains the minimal symbol
7779 variant `long name(params)' does not have the proper inferior type.
7782 if (cu->language == language_go)
7784 /* This is a lie, but we already lie to the caller new_symbol_full.
7785 new_symbol_full assumes we return the mangled name.
7786 This just undoes that lie until things are cleaned up. */
7791 demangled = gdb_demangle (mangled,
7792 (DMGL_PARAMS | DMGL_ANSI
7793 | (cu->language == language_java
7794 ? DMGL_JAVA | DMGL_RET_POSTFIX
7799 make_cleanup (xfree, demangled);
7809 if (canon == NULL || check_physname)
7811 const char *physname = dwarf2_compute_name (name, die, cu, 1);
7813 if (canon != NULL && strcmp (physname, canon) != 0)
7815 /* It may not mean a bug in GDB. The compiler could also
7816 compute DW_AT_linkage_name incorrectly. But in such case
7817 GDB would need to be bug-to-bug compatible. */
7819 complaint (&symfile_complaints,
7820 _("Computed physname <%s> does not match demangled <%s> "
7821 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7822 physname, canon, mangled, die->offset.sect_off, objfile->name);
7824 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7825 is available here - over computed PHYSNAME. It is safer
7826 against both buggy GDB and buggy compilers. */
7840 retval = obstack_copy0 (&objfile->objfile_obstack, retval, strlen (retval));
7842 do_cleanups (back_to);
7846 /* Read the import statement specified by the given die and record it. */
7849 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
7851 struct objfile *objfile = cu->objfile;
7852 struct attribute *import_attr;
7853 struct die_info *imported_die, *child_die;
7854 struct dwarf2_cu *imported_cu;
7855 const char *imported_name;
7856 const char *imported_name_prefix;
7857 const char *canonical_name;
7858 const char *import_alias;
7859 const char *imported_declaration = NULL;
7860 const char *import_prefix;
7861 VEC (const_char_ptr) *excludes = NULL;
7862 struct cleanup *cleanups;
7864 import_attr = dwarf2_attr (die, DW_AT_import, cu);
7865 if (import_attr == NULL)
7867 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
7868 dwarf_tag_name (die->tag));
7873 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
7874 imported_name = dwarf2_name (imported_die, imported_cu);
7875 if (imported_name == NULL)
7877 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7879 The import in the following code:
7893 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7894 <52> DW_AT_decl_file : 1
7895 <53> DW_AT_decl_line : 6
7896 <54> DW_AT_import : <0x75>
7897 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7899 <5b> DW_AT_decl_file : 1
7900 <5c> DW_AT_decl_line : 2
7901 <5d> DW_AT_type : <0x6e>
7903 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7904 <76> DW_AT_byte_size : 4
7905 <77> DW_AT_encoding : 5 (signed)
7907 imports the wrong die ( 0x75 instead of 0x58 ).
7908 This case will be ignored until the gcc bug is fixed. */
7912 /* Figure out the local name after import. */
7913 import_alias = dwarf2_name (die, cu);
7915 /* Figure out where the statement is being imported to. */
7916 import_prefix = determine_prefix (die, cu);
7918 /* Figure out what the scope of the imported die is and prepend it
7919 to the name of the imported die. */
7920 imported_name_prefix = determine_prefix (imported_die, imported_cu);
7922 if (imported_die->tag != DW_TAG_namespace
7923 && imported_die->tag != DW_TAG_module)
7925 imported_declaration = imported_name;
7926 canonical_name = imported_name_prefix;
7928 else if (strlen (imported_name_prefix) > 0)
7929 canonical_name = obconcat (&objfile->objfile_obstack,
7930 imported_name_prefix, "::", imported_name,
7933 canonical_name = imported_name;
7935 cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
7937 if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
7938 for (child_die = die->child; child_die && child_die->tag;
7939 child_die = sibling_die (child_die))
7941 /* DWARF-4: A Fortran use statement with a “rename list” may be
7942 represented by an imported module entry with an import attribute
7943 referring to the module and owned entries corresponding to those
7944 entities that are renamed as part of being imported. */
7946 if (child_die->tag != DW_TAG_imported_declaration)
7948 complaint (&symfile_complaints,
7949 _("child DW_TAG_imported_declaration expected "
7950 "- DIE at 0x%x [in module %s]"),
7951 child_die->offset.sect_off, objfile->name);
7955 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
7956 if (import_attr == NULL)
7958 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
7959 dwarf_tag_name (child_die->tag));
7964 imported_die = follow_die_ref_or_sig (child_die, import_attr,
7966 imported_name = dwarf2_name (imported_die, imported_cu);
7967 if (imported_name == NULL)
7969 complaint (&symfile_complaints,
7970 _("child DW_TAG_imported_declaration has unknown "
7971 "imported name - DIE at 0x%x [in module %s]"),
7972 child_die->offset.sect_off, objfile->name);
7976 VEC_safe_push (const_char_ptr, excludes, imported_name);
7978 process_die (child_die, cu);
7981 cp_add_using_directive (import_prefix,
7984 imported_declaration,
7987 &objfile->objfile_obstack);
7989 do_cleanups (cleanups);
7992 /* Cleanup function for handle_DW_AT_stmt_list. */
7995 free_cu_line_header (void *arg)
7997 struct dwarf2_cu *cu = arg;
7999 free_line_header (cu->line_header);
8000 cu->line_header = NULL;
8003 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
8004 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
8005 this, it was first present in GCC release 4.3.0. */
8008 producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu)
8010 if (!cu->checked_producer)
8011 check_producer (cu);
8013 return cu->producer_is_gcc_lt_4_3;
8017 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
8018 const char **name, const char **comp_dir)
8020 struct attribute *attr;
8025 /* Find the filename. Do not use dwarf2_name here, since the filename
8026 is not a source language identifier. */
8027 attr = dwarf2_attr (die, DW_AT_name, cu);
8030 *name = DW_STRING (attr);
8033 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
8035 *comp_dir = DW_STRING (attr);
8036 else if (producer_is_gcc_lt_4_3 (cu) && *name != NULL
8037 && IS_ABSOLUTE_PATH (*name))
8039 char *d = ldirname (*name);
8043 make_cleanup (xfree, d);
8045 if (*comp_dir != NULL)
8047 /* Irix 6.2 native cc prepends <machine>.: to the compilation
8048 directory, get rid of it. */
8049 char *cp = strchr (*comp_dir, ':');
8051 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
8056 *name = "<unknown>";
8059 /* Handle DW_AT_stmt_list for a compilation unit.
8060 DIE is the DW_TAG_compile_unit die for CU.
8061 COMP_DIR is the compilation directory.
8062 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
8065 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
8066 const char *comp_dir) /* ARI: editCase function */
8068 struct attribute *attr;
8070 gdb_assert (! cu->per_cu->is_debug_types);
8072 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
8075 unsigned int line_offset = DW_UNSND (attr);
8076 struct line_header *line_header
8077 = dwarf_decode_line_header (line_offset, cu);
8081 cu->line_header = line_header;
8082 make_cleanup (free_cu_line_header, cu);
8083 dwarf_decode_lines (line_header, comp_dir, cu, NULL, 1);
8088 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
8091 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
8093 struct objfile *objfile = dwarf2_per_objfile->objfile;
8094 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
8095 CORE_ADDR lowpc = ((CORE_ADDR) -1);
8096 CORE_ADDR highpc = ((CORE_ADDR) 0);
8097 struct attribute *attr;
8098 const char *name = NULL;
8099 const char *comp_dir = NULL;
8100 struct die_info *child_die;
8101 bfd *abfd = objfile->obfd;
8104 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
8106 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
8108 /* If we didn't find a lowpc, set it to highpc to avoid complaints
8109 from finish_block. */
8110 if (lowpc == ((CORE_ADDR) -1))
8115 find_file_and_directory (die, cu, &name, &comp_dir);
8117 prepare_one_comp_unit (cu, die, cu->language);
8119 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
8120 standardised yet. As a workaround for the language detection we fall
8121 back to the DW_AT_producer string. */
8122 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
8123 cu->language = language_opencl;
8125 /* Similar hack for Go. */
8126 if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL)
8127 set_cu_language (DW_LANG_Go, cu);
8129 dwarf2_start_symtab (cu, name, comp_dir, lowpc);
8131 /* Decode line number information if present. We do this before
8132 processing child DIEs, so that the line header table is available
8133 for DW_AT_decl_file. */
8134 handle_DW_AT_stmt_list (die, cu, comp_dir);
8136 /* Process all dies in compilation unit. */
8137 if (die->child != NULL)
8139 child_die = die->child;
8140 while (child_die && child_die->tag)
8142 process_die (child_die, cu);
8143 child_die = sibling_die (child_die);
8147 /* Decode macro information, if present. Dwarf 2 macro information
8148 refers to information in the line number info statement program
8149 header, so we can only read it if we've read the header
8151 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
8152 if (attr && cu->line_header)
8154 if (dwarf2_attr (die, DW_AT_macro_info, cu))
8155 complaint (&symfile_complaints,
8156 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
8158 dwarf_decode_macros (cu, DW_UNSND (attr), comp_dir, 1);
8162 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
8163 if (attr && cu->line_header)
8165 unsigned int macro_offset = DW_UNSND (attr);
8167 dwarf_decode_macros (cu, macro_offset, comp_dir, 0);
8171 do_cleanups (back_to);
8174 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
8175 Create the set of symtabs used by this TU, or if this TU is sharing
8176 symtabs with another TU and the symtabs have already been created
8177 then restore those symtabs in the line header.
8178 We don't need the pc/line-number mapping for type units. */
8181 setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
8183 struct objfile *objfile = dwarf2_per_objfile->objfile;
8184 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
8185 struct type_unit_group *tu_group;
8187 struct line_header *lh;
8188 struct attribute *attr;
8189 unsigned int i, line_offset;
8190 struct signatured_type *sig_type;
8192 gdb_assert (per_cu->is_debug_types);
8193 sig_type = (struct signatured_type *) per_cu;
8195 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
8197 /* If we're using .gdb_index (includes -readnow) then
8198 per_cu->type_unit_group may not have been set up yet. */
8199 if (sig_type->type_unit_group == NULL)
8200 sig_type->type_unit_group = get_type_unit_group (cu, attr);
8201 tu_group = sig_type->type_unit_group;
8203 /* If we've already processed this stmt_list there's no real need to
8204 do it again, we could fake it and just recreate the part we need
8205 (file name,index -> symtab mapping). If data shows this optimization
8206 is useful we can do it then. */
8207 first_time = tu_group->primary_symtab == NULL;
8209 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
8214 line_offset = DW_UNSND (attr);
8215 lh = dwarf_decode_line_header (line_offset, cu);
8220 dwarf2_start_symtab (cu, "", NULL, 0);
8223 gdb_assert (tu_group->symtabs == NULL);
8226 /* Note: The primary symtab will get allocated at the end. */
8230 cu->line_header = lh;
8231 make_cleanup (free_cu_line_header, cu);
8235 dwarf2_start_symtab (cu, "", NULL, 0);
8237 tu_group->num_symtabs = lh->num_file_names;
8238 tu_group->symtabs = XNEWVEC (struct symtab *, lh->num_file_names);
8240 for (i = 0; i < lh->num_file_names; ++i)
8242 const char *dir = NULL;
8243 struct file_entry *fe = &lh->file_names[i];
8246 dir = lh->include_dirs[fe->dir_index - 1];
8247 dwarf2_start_subfile (fe->name, dir, NULL);
8249 /* Note: We don't have to watch for the main subfile here, type units
8250 don't have DW_AT_name. */
8252 if (current_subfile->symtab == NULL)
8254 /* NOTE: start_subfile will recognize when it's been passed
8255 a file it has already seen. So we can't assume there's a
8256 simple mapping from lh->file_names to subfiles,
8257 lh->file_names may contain dups. */
8258 current_subfile->symtab = allocate_symtab (current_subfile->name,
8262 fe->symtab = current_subfile->symtab;
8263 tu_group->symtabs[i] = fe->symtab;
8270 for (i = 0; i < lh->num_file_names; ++i)
8272 struct file_entry *fe = &lh->file_names[i];
8274 fe->symtab = tu_group->symtabs[i];
8278 /* The main symtab is allocated last. Type units don't have DW_AT_name
8279 so they don't have a "real" (so to speak) symtab anyway.
8280 There is later code that will assign the main symtab to all symbols
8281 that don't have one. We need to handle the case of a symbol with a
8282 missing symtab (DW_AT_decl_file) anyway. */
8285 /* Process DW_TAG_type_unit.
8286 For TUs we want to skip the first top level sibling if it's not the
8287 actual type being defined by this TU. In this case the first top
8288 level sibling is there to provide context only. */
8291 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
8293 struct die_info *child_die;
8295 prepare_one_comp_unit (cu, die, language_minimal);
8297 /* Initialize (or reinitialize) the machinery for building symtabs.
8298 We do this before processing child DIEs, so that the line header table
8299 is available for DW_AT_decl_file. */
8300 setup_type_unit_groups (die, cu);
8302 if (die->child != NULL)
8304 child_die = die->child;
8305 while (child_die && child_die->tag)
8307 process_die (child_die, cu);
8308 child_die = sibling_die (child_die);
8315 http://gcc.gnu.org/wiki/DebugFission
8316 http://gcc.gnu.org/wiki/DebugFissionDWP
8318 To simplify handling of both DWO files ("object" files with the DWARF info)
8319 and DWP files (a file with the DWOs packaged up into one file), we treat
8320 DWP files as having a collection of virtual DWO files. */
8323 hash_dwo_file (const void *item)
8325 const struct dwo_file *dwo_file = item;
8327 return (htab_hash_string (dwo_file->dwo_name)
8328 + htab_hash_string (dwo_file->comp_dir));
8332 eq_dwo_file (const void *item_lhs, const void *item_rhs)
8334 const struct dwo_file *lhs = item_lhs;
8335 const struct dwo_file *rhs = item_rhs;
8337 return (strcmp (lhs->dwo_name, rhs->dwo_name) == 0
8338 && strcmp (lhs->comp_dir, rhs->comp_dir) == 0);
8341 /* Allocate a hash table for DWO files. */
8344 allocate_dwo_file_hash_table (void)
8346 struct objfile *objfile = dwarf2_per_objfile->objfile;
8348 return htab_create_alloc_ex (41,
8352 &objfile->objfile_obstack,
8353 hashtab_obstack_allocate,
8354 dummy_obstack_deallocate);
8357 /* Lookup DWO file DWO_NAME. */
8360 lookup_dwo_file_slot (const char *dwo_name, const char *comp_dir)
8362 struct dwo_file find_entry;
8365 if (dwarf2_per_objfile->dwo_files == NULL)
8366 dwarf2_per_objfile->dwo_files = allocate_dwo_file_hash_table ();
8368 memset (&find_entry, 0, sizeof (find_entry));
8369 find_entry.dwo_name = dwo_name;
8370 find_entry.comp_dir = comp_dir;
8371 slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT);
8377 hash_dwo_unit (const void *item)
8379 const struct dwo_unit *dwo_unit = item;
8381 /* This drops the top 32 bits of the id, but is ok for a hash. */
8382 return dwo_unit->signature;
8386 eq_dwo_unit (const void *item_lhs, const void *item_rhs)
8388 const struct dwo_unit *lhs = item_lhs;
8389 const struct dwo_unit *rhs = item_rhs;
8391 /* The signature is assumed to be unique within the DWO file.
8392 So while object file CU dwo_id's always have the value zero,
8393 that's OK, assuming each object file DWO file has only one CU,
8394 and that's the rule for now. */
8395 return lhs->signature == rhs->signature;
8398 /* Allocate a hash table for DWO CUs,TUs.
8399 There is one of these tables for each of CUs,TUs for each DWO file. */
8402 allocate_dwo_unit_table (struct objfile *objfile)
8404 /* Start out with a pretty small number.
8405 Generally DWO files contain only one CU and maybe some TUs. */
8406 return htab_create_alloc_ex (3,
8410 &objfile->objfile_obstack,
8411 hashtab_obstack_allocate,
8412 dummy_obstack_deallocate);
8415 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8417 struct create_dwo_cu_data
8419 struct dwo_file *dwo_file;
8420 struct dwo_unit dwo_unit;
8423 /* die_reader_func for create_dwo_cu. */
8426 create_dwo_cu_reader (const struct die_reader_specs *reader,
8427 const gdb_byte *info_ptr,
8428 struct die_info *comp_unit_die,
8432 struct dwarf2_cu *cu = reader->cu;
8433 struct objfile *objfile = dwarf2_per_objfile->objfile;
8434 sect_offset offset = cu->per_cu->offset;
8435 struct dwarf2_section_info *section = cu->per_cu->section;
8436 struct create_dwo_cu_data *data = datap;
8437 struct dwo_file *dwo_file = data->dwo_file;
8438 struct dwo_unit *dwo_unit = &data->dwo_unit;
8439 struct attribute *attr;
8441 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
8444 complaint (&symfile_complaints,
8445 _("Dwarf Error: debug entry at offset 0x%x is missing"
8446 " its dwo_id [in module %s]"),
8447 offset.sect_off, dwo_file->dwo_name);
8451 dwo_unit->dwo_file = dwo_file;
8452 dwo_unit->signature = DW_UNSND (attr);
8453 dwo_unit->section = section;
8454 dwo_unit->offset = offset;
8455 dwo_unit->length = cu->per_cu->length;
8457 if (dwarf2_read_debug)
8458 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, dwo_id %s\n",
8459 offset.sect_off, hex_string (dwo_unit->signature));
8462 /* Create the dwo_unit for the lone CU in DWO_FILE.
8463 Note: This function processes DWO files only, not DWP files. */
8465 static struct dwo_unit *
8466 create_dwo_cu (struct dwo_file *dwo_file)
8468 struct objfile *objfile = dwarf2_per_objfile->objfile;
8469 struct dwarf2_section_info *section = &dwo_file->sections.info;
8472 const gdb_byte *info_ptr, *end_ptr;
8473 struct create_dwo_cu_data create_dwo_cu_data;
8474 struct dwo_unit *dwo_unit;
8476 dwarf2_read_section (objfile, section);
8477 info_ptr = section->buffer;
8479 if (info_ptr == NULL)
8482 /* We can't set abfd until now because the section may be empty or
8483 not present, in which case section->asection will be NULL. */
8484 abfd = section->asection->owner;
8486 if (dwarf2_read_debug)
8488 fprintf_unfiltered (gdb_stdlog, "Reading %s for %s:\n",
8489 bfd_section_name (abfd, section->asection),
8490 bfd_get_filename (abfd));
8493 create_dwo_cu_data.dwo_file = dwo_file;
8496 end_ptr = info_ptr + section->size;
8497 while (info_ptr < end_ptr)
8499 struct dwarf2_per_cu_data per_cu;
8501 memset (&create_dwo_cu_data.dwo_unit, 0,
8502 sizeof (create_dwo_cu_data.dwo_unit));
8503 memset (&per_cu, 0, sizeof (per_cu));
8504 per_cu.objfile = objfile;
8505 per_cu.is_debug_types = 0;
8506 per_cu.offset.sect_off = info_ptr - section->buffer;
8507 per_cu.section = section;
8509 init_cutu_and_read_dies_no_follow (&per_cu,
8510 &dwo_file->sections.abbrev,
8512 create_dwo_cu_reader,
8513 &create_dwo_cu_data);
8515 if (create_dwo_cu_data.dwo_unit.dwo_file != NULL)
8517 /* If we've already found one, complain. We only support one
8518 because having more than one requires hacking the dwo_name of
8519 each to match, which is highly unlikely to happen. */
8520 if (dwo_unit != NULL)
8522 complaint (&symfile_complaints,
8523 _("Multiple CUs in DWO file %s [in module %s]"),
8524 dwo_file->dwo_name, objfile->name);
8528 dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit);
8529 *dwo_unit = create_dwo_cu_data.dwo_unit;
8532 info_ptr += per_cu.length;
8538 /* DWP file .debug_{cu,tu}_index section format:
8539 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8541 Both index sections have the same format, and serve to map a 64-bit
8542 signature to a set of section numbers. Each section begins with a header,
8543 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8544 indexes, and a pool of 32-bit section numbers. The index sections will be
8545 aligned at 8-byte boundaries in the file.
8547 The index section header contains two unsigned 32-bit values (using the
8548 byte order of the application binary):
8550 N, the number of compilation units or type units in the index
8551 M, the number of slots in the hash table
8553 (We assume that N and M will not exceed 2^32 - 1.)
8555 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8557 The hash table begins at offset 8 in the section, and consists of an array
8558 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8559 order of the application binary). Unused slots in the hash table are 0.
8560 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8562 The parallel table begins immediately after the hash table
8563 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8564 array of 32-bit indexes (using the byte order of the application binary),
8565 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8566 table contains a 32-bit index into the pool of section numbers. For unused
8567 hash table slots, the corresponding entry in the parallel table will be 0.
8569 Given a 64-bit compilation unit signature or a type signature S, an entry
8570 in the hash table is located as follows:
8572 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8573 the low-order k bits all set to 1.
8575 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8577 3) If the hash table entry at index H matches the signature, use that
8578 entry. If the hash table entry at index H is unused (all zeroes),
8579 terminate the search: the signature is not present in the table.
8581 4) Let H = (H + H') modulo M. Repeat at Step 3.
8583 Because M > N and H' and M are relatively prime, the search is guaranteed
8584 to stop at an unused slot or find the match.
8586 The pool of section numbers begins immediately following the hash table
8587 (at offset 8 + 12 * M from the beginning of the section). The pool of
8588 section numbers consists of an array of 32-bit words (using the byte order
8589 of the application binary). Each item in the array is indexed starting
8590 from 0. The hash table entry provides the index of the first section
8591 number in the set. Additional section numbers in the set follow, and the
8592 set is terminated by a 0 entry (section number 0 is not used in ELF).
8594 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8595 section must be the first entry in the set, and the .debug_abbrev.dwo must
8596 be the second entry. Other members of the set may follow in any order. */
8598 /* Create a hash table to map DWO IDs to their CU/TU entry in
8599 .debug_{info,types}.dwo in DWP_FILE.
8600 Returns NULL if there isn't one.
8601 Note: This function processes DWP files only, not DWO files. */
8603 static struct dwp_hash_table *
8604 create_dwp_hash_table (struct dwp_file *dwp_file, int is_debug_types)
8606 struct objfile *objfile = dwarf2_per_objfile->objfile;
8607 bfd *dbfd = dwp_file->dbfd;
8608 const gdb_byte *index_ptr, *index_end;
8609 struct dwarf2_section_info *index;
8610 uint32_t version, nr_units, nr_slots;
8611 struct dwp_hash_table *htab;
8614 index = &dwp_file->sections.tu_index;
8616 index = &dwp_file->sections.cu_index;
8618 if (dwarf2_section_empty_p (index))
8620 dwarf2_read_section (objfile, index);
8622 index_ptr = index->buffer;
8623 index_end = index_ptr + index->size;
8625 version = read_4_bytes (dbfd, index_ptr);
8626 index_ptr += 8; /* Skip the unused word. */
8627 nr_units = read_4_bytes (dbfd, index_ptr);
8629 nr_slots = read_4_bytes (dbfd, index_ptr);
8634 error (_("Dwarf Error: unsupported DWP file version (%u)"
8636 version, dwp_file->name);
8638 if (nr_slots != (nr_slots & -nr_slots))
8640 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8641 " is not power of 2 [in module %s]"),
8642 nr_slots, dwp_file->name);
8645 htab = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_hash_table);
8646 htab->nr_units = nr_units;
8647 htab->nr_slots = nr_slots;
8648 htab->hash_table = index_ptr;
8649 htab->unit_table = htab->hash_table + sizeof (uint64_t) * nr_slots;
8650 htab->section_pool = htab->unit_table + sizeof (uint32_t) * nr_slots;
8655 /* Update SECTIONS with the data from SECTP.
8657 This function is like the other "locate" section routines that are
8658 passed to bfd_map_over_sections, but in this context the sections to
8659 read comes from the DWP hash table, not the full ELF section table.
8661 The result is non-zero for success, or zero if an error was found. */
8664 locate_virtual_dwo_sections (asection *sectp,
8665 struct virtual_dwo_sections *sections)
8667 const struct dwop_section_names *names = &dwop_section_names;
8669 if (section_is_p (sectp->name, &names->abbrev_dwo))
8671 /* There can be only one. */
8672 if (sections->abbrev.asection != NULL)
8674 sections->abbrev.asection = sectp;
8675 sections->abbrev.size = bfd_get_section_size (sectp);
8677 else if (section_is_p (sectp->name, &names->info_dwo)
8678 || section_is_p (sectp->name, &names->types_dwo))
8680 /* There can be only one. */
8681 if (sections->info_or_types.asection != NULL)
8683 sections->info_or_types.asection = sectp;
8684 sections->info_or_types.size = bfd_get_section_size (sectp);
8686 else if (section_is_p (sectp->name, &names->line_dwo))
8688 /* There can be only one. */
8689 if (sections->line.asection != NULL)
8691 sections->line.asection = sectp;
8692 sections->line.size = bfd_get_section_size (sectp);
8694 else if (section_is_p (sectp->name, &names->loc_dwo))
8696 /* There can be only one. */
8697 if (sections->loc.asection != NULL)
8699 sections->loc.asection = sectp;
8700 sections->loc.size = bfd_get_section_size (sectp);
8702 else if (section_is_p (sectp->name, &names->macinfo_dwo))
8704 /* There can be only one. */
8705 if (sections->macinfo.asection != NULL)
8707 sections->macinfo.asection = sectp;
8708 sections->macinfo.size = bfd_get_section_size (sectp);
8710 else if (section_is_p (sectp->name, &names->macro_dwo))
8712 /* There can be only one. */
8713 if (sections->macro.asection != NULL)
8715 sections->macro.asection = sectp;
8716 sections->macro.size = bfd_get_section_size (sectp);
8718 else if (section_is_p (sectp->name, &names->str_offsets_dwo))
8720 /* There can be only one. */
8721 if (sections->str_offsets.asection != NULL)
8723 sections->str_offsets.asection = sectp;
8724 sections->str_offsets.size = bfd_get_section_size (sectp);
8728 /* No other kind of section is valid. */
8735 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8736 HTAB is the hash table from the DWP file.
8737 SECTION_INDEX is the index of the DWO in HTAB.
8738 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU. */
8740 static struct dwo_unit *
8741 create_dwo_in_dwp (struct dwp_file *dwp_file,
8742 const struct dwp_hash_table *htab,
8743 uint32_t section_index,
8744 const char *comp_dir,
8745 ULONGEST signature, int is_debug_types)
8747 struct objfile *objfile = dwarf2_per_objfile->objfile;
8748 bfd *dbfd = dwp_file->dbfd;
8749 const char *kind = is_debug_types ? "TU" : "CU";
8750 struct dwo_file *dwo_file;
8751 struct dwo_unit *dwo_unit;
8752 struct virtual_dwo_sections sections;
8753 void **dwo_file_slot;
8754 char *virtual_dwo_name;
8755 struct dwarf2_section_info *cutu;
8756 struct cleanup *cleanups;
8759 if (dwarf2_read_debug)
8761 fprintf_unfiltered (gdb_stdlog, "Reading %s %u/%s in DWP file: %s\n",
8763 section_index, hex_string (signature),
8767 /* Fetch the sections of this DWO.
8768 Put a limit on the number of sections we look for so that bad data
8769 doesn't cause us to loop forever. */
8771 #define MAX_NR_DWO_SECTIONS \
8772 (1 /* .debug_info or .debug_types */ \
8773 + 1 /* .debug_abbrev */ \
8774 + 1 /* .debug_line */ \
8775 + 1 /* .debug_loc */ \
8776 + 1 /* .debug_str_offsets */ \
8777 + 1 /* .debug_macro */ \
8778 + 1 /* .debug_macinfo */ \
8779 + 1 /* trailing zero */)
8781 memset (§ions, 0, sizeof (sections));
8782 cleanups = make_cleanup (null_cleanup, 0);
8784 for (i = 0; i < MAX_NR_DWO_SECTIONS; ++i)
8787 uint32_t section_nr =
8790 + (section_index + i) * sizeof (uint32_t));
8792 if (section_nr == 0)
8794 if (section_nr >= dwp_file->num_sections)
8796 error (_("Dwarf Error: bad DWP hash table, section number too large"
8801 sectp = dwp_file->elf_sections[section_nr];
8802 if (! locate_virtual_dwo_sections (sectp, §ions))
8804 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8811 || sections.info_or_types.asection == NULL
8812 || sections.abbrev.asection == NULL)
8814 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8818 if (i == MAX_NR_DWO_SECTIONS)
8820 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8825 /* It's easier for the rest of the code if we fake a struct dwo_file and
8826 have dwo_unit "live" in that. At least for now.
8828 The DWP file can be made up of a random collection of CUs and TUs.
8829 However, for each CU + set of TUs that came from the same original DWO
8830 file, we want to combine them back into a virtual DWO file to save space
8831 (fewer struct dwo_file objects to allocated). Remember that for really
8832 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8835 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
8836 sections.abbrev.asection ? sections.abbrev.asection->id : 0,
8837 sections.line.asection ? sections.line.asection->id : 0,
8838 sections.loc.asection ? sections.loc.asection->id : 0,
8839 (sections.str_offsets.asection
8840 ? sections.str_offsets.asection->id
8842 make_cleanup (xfree, virtual_dwo_name);
8843 /* Can we use an existing virtual DWO file? */
8844 dwo_file_slot = lookup_dwo_file_slot (virtual_dwo_name, comp_dir);
8845 /* Create one if necessary. */
8846 if (*dwo_file_slot == NULL)
8848 if (dwarf2_read_debug)
8850 fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n",
8853 dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
8854 dwo_file->dwo_name = obstack_copy0 (&objfile->objfile_obstack,
8856 strlen (virtual_dwo_name));
8857 dwo_file->comp_dir = comp_dir;
8858 dwo_file->sections.abbrev = sections.abbrev;
8859 dwo_file->sections.line = sections.line;
8860 dwo_file->sections.loc = sections.loc;
8861 dwo_file->sections.macinfo = sections.macinfo;
8862 dwo_file->sections.macro = sections.macro;
8863 dwo_file->sections.str_offsets = sections.str_offsets;
8864 /* The "str" section is global to the entire DWP file. */
8865 dwo_file->sections.str = dwp_file->sections.str;
8866 /* The info or types section is assigned later to dwo_unit,
8867 there's no need to record it in dwo_file.
8868 Also, we can't simply record type sections in dwo_file because
8869 we record a pointer into the vector in dwo_unit. As we collect more
8870 types we'll grow the vector and eventually have to reallocate space
8871 for it, invalidating all the pointers into the current copy. */
8872 *dwo_file_slot = dwo_file;
8876 if (dwarf2_read_debug)
8878 fprintf_unfiltered (gdb_stdlog, "Using existing virtual DWO: %s\n",
8881 dwo_file = *dwo_file_slot;
8883 do_cleanups (cleanups);
8885 dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit);
8886 dwo_unit->dwo_file = dwo_file;
8887 dwo_unit->signature = signature;
8888 dwo_unit->section = obstack_alloc (&objfile->objfile_obstack,
8889 sizeof (struct dwarf2_section_info));
8890 *dwo_unit->section = sections.info_or_types;
8891 /* offset, length, type_offset_in_tu are set later. */
8896 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8898 static struct dwo_unit *
8899 lookup_dwo_in_dwp (struct dwp_file *dwp_file,
8900 const struct dwp_hash_table *htab,
8901 const char *comp_dir,
8902 ULONGEST signature, int is_debug_types)
8904 bfd *dbfd = dwp_file->dbfd;
8905 uint32_t mask = htab->nr_slots - 1;
8906 uint32_t hash = signature & mask;
8907 uint32_t hash2 = ((signature >> 32) & mask) | 1;
8910 struct dwo_unit find_dwo_cu, *dwo_cu;
8912 memset (&find_dwo_cu, 0, sizeof (find_dwo_cu));
8913 find_dwo_cu.signature = signature;
8914 slot = htab_find_slot (dwp_file->loaded_cutus, &find_dwo_cu, INSERT);
8919 /* Use a for loop so that we don't loop forever on bad debug info. */
8920 for (i = 0; i < htab->nr_slots; ++i)
8922 ULONGEST signature_in_table;
8924 signature_in_table =
8925 read_8_bytes (dbfd, htab->hash_table + hash * sizeof (uint64_t));
8926 if (signature_in_table == signature)
8928 uint32_t section_index =
8929 read_4_bytes (dbfd, htab->unit_table + hash * sizeof (uint32_t));
8931 *slot = create_dwo_in_dwp (dwp_file, htab, section_index,
8932 comp_dir, signature, is_debug_types);
8935 if (signature_in_table == 0)
8937 hash = (hash + hash2) & mask;
8940 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8945 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
8946 Open the file specified by FILE_NAME and hand it off to BFD for
8947 preliminary analysis. Return a newly initialized bfd *, which
8948 includes a canonicalized copy of FILE_NAME.
8949 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8950 In case of trouble, return NULL.
8951 NOTE: This function is derived from symfile_bfd_open. */
8954 try_open_dwop_file (const char *file_name, int is_dwp)
8958 char *absolute_name;
8960 flags = OPF_TRY_CWD_FIRST;
8962 flags |= OPF_SEARCH_IN_PATH;
8963 desc = openp (debug_file_directory, flags, file_name,
8964 O_RDONLY | O_BINARY, &absolute_name);
8968 sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc);
8971 xfree (absolute_name);
8974 xfree (absolute_name);
8975 bfd_set_cacheable (sym_bfd, 1);
8977 if (!bfd_check_format (sym_bfd, bfd_object))
8979 gdb_bfd_unref (sym_bfd); /* This also closes desc. */
8986 /* Try to open DWO file FILE_NAME.
8987 COMP_DIR is the DW_AT_comp_dir attribute.
8988 The result is the bfd handle of the file.
8989 If there is a problem finding or opening the file, return NULL.
8990 Upon success, the canonicalized path of the file is stored in the bfd,
8991 same as symfile_bfd_open. */
8994 open_dwo_file (const char *file_name, const char *comp_dir)
8998 if (IS_ABSOLUTE_PATH (file_name))
8999 return try_open_dwop_file (file_name, 0 /*is_dwp*/);
9001 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
9003 if (comp_dir != NULL)
9005 char *path_to_try = concat (comp_dir, SLASH_STRING, file_name, NULL);
9007 /* NOTE: If comp_dir is a relative path, this will also try the
9008 search path, which seems useful. */
9009 abfd = try_open_dwop_file (path_to_try, 0 /*is_dwp*/);
9010 xfree (path_to_try);
9015 /* That didn't work, try debug-file-directory, which, despite its name,
9016 is a list of paths. */
9018 if (*debug_file_directory == '\0')
9021 return try_open_dwop_file (file_name, 0 /*is_dwp*/);
9024 /* This function is mapped across the sections and remembers the offset and
9025 size of each of the DWO debugging sections we are interested in. */
9028 dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr)
9030 struct dwo_sections *dwo_sections = dwo_sections_ptr;
9031 const struct dwop_section_names *names = &dwop_section_names;
9033 if (section_is_p (sectp->name, &names->abbrev_dwo))
9035 dwo_sections->abbrev.asection = sectp;
9036 dwo_sections->abbrev.size = bfd_get_section_size (sectp);
9038 else if (section_is_p (sectp->name, &names->info_dwo))
9040 dwo_sections->info.asection = sectp;
9041 dwo_sections->info.size = bfd_get_section_size (sectp);
9043 else if (section_is_p (sectp->name, &names->line_dwo))
9045 dwo_sections->line.asection = sectp;
9046 dwo_sections->line.size = bfd_get_section_size (sectp);
9048 else if (section_is_p (sectp->name, &names->loc_dwo))
9050 dwo_sections->loc.asection = sectp;
9051 dwo_sections->loc.size = bfd_get_section_size (sectp);
9053 else if (section_is_p (sectp->name, &names->macinfo_dwo))
9055 dwo_sections->macinfo.asection = sectp;
9056 dwo_sections->macinfo.size = bfd_get_section_size (sectp);
9058 else if (section_is_p (sectp->name, &names->macro_dwo))
9060 dwo_sections->macro.asection = sectp;
9061 dwo_sections->macro.size = bfd_get_section_size (sectp);
9063 else if (section_is_p (sectp->name, &names->str_dwo))
9065 dwo_sections->str.asection = sectp;
9066 dwo_sections->str.size = bfd_get_section_size (sectp);
9068 else if (section_is_p (sectp->name, &names->str_offsets_dwo))
9070 dwo_sections->str_offsets.asection = sectp;
9071 dwo_sections->str_offsets.size = bfd_get_section_size (sectp);
9073 else if (section_is_p (sectp->name, &names->types_dwo))
9075 struct dwarf2_section_info type_section;
9077 memset (&type_section, 0, sizeof (type_section));
9078 type_section.asection = sectp;
9079 type_section.size = bfd_get_section_size (sectp);
9080 VEC_safe_push (dwarf2_section_info_def, dwo_sections->types,
9085 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
9086 by PER_CU. This is for the non-DWP case.
9087 The result is NULL if DWO_NAME can't be found. */
9089 static struct dwo_file *
9090 open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu,
9091 const char *dwo_name, const char *comp_dir)
9093 struct objfile *objfile = dwarf2_per_objfile->objfile;
9094 struct dwo_file *dwo_file;
9096 struct cleanup *cleanups;
9098 dbfd = open_dwo_file (dwo_name, comp_dir);
9101 if (dwarf2_read_debug)
9102 fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name);
9105 dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
9106 dwo_file->dwo_name = dwo_name;
9107 dwo_file->comp_dir = comp_dir;
9108 dwo_file->dbfd = dbfd;
9110 cleanups = make_cleanup (free_dwo_file_cleanup, dwo_file);
9112 bfd_map_over_sections (dbfd, dwarf2_locate_dwo_sections, &dwo_file->sections);
9114 dwo_file->cu = create_dwo_cu (dwo_file);
9116 dwo_file->tus = create_debug_types_hash_table (dwo_file,
9117 dwo_file->sections.types);
9119 discard_cleanups (cleanups);
9121 if (dwarf2_read_debug)
9122 fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name);
9127 /* This function is mapped across the sections and remembers the offset and
9128 size of each of the DWP debugging sections we are interested in. */
9131 dwarf2_locate_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_ptr)
9133 struct dwp_file *dwp_file = dwp_file_ptr;
9134 const struct dwop_section_names *names = &dwop_section_names;
9135 unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
9137 /* Record the ELF section number for later lookup: this is what the
9138 .debug_cu_index,.debug_tu_index tables use. */
9139 gdb_assert (elf_section_nr < dwp_file->num_sections);
9140 dwp_file->elf_sections[elf_section_nr] = sectp;
9142 /* Look for specific sections that we need. */
9143 if (section_is_p (sectp->name, &names->str_dwo))
9145 dwp_file->sections.str.asection = sectp;
9146 dwp_file->sections.str.size = bfd_get_section_size (sectp);
9148 else if (section_is_p (sectp->name, &names->cu_index))
9150 dwp_file->sections.cu_index.asection = sectp;
9151 dwp_file->sections.cu_index.size = bfd_get_section_size (sectp);
9153 else if (section_is_p (sectp->name, &names->tu_index))
9155 dwp_file->sections.tu_index.asection = sectp;
9156 dwp_file->sections.tu_index.size = bfd_get_section_size (sectp);
9160 /* Hash function for dwp_file loaded CUs/TUs. */
9163 hash_dwp_loaded_cutus (const void *item)
9165 const struct dwo_unit *dwo_unit = item;
9167 /* This drops the top 32 bits of the signature, but is ok for a hash. */
9168 return dwo_unit->signature;
9171 /* Equality function for dwp_file loaded CUs/TUs. */
9174 eq_dwp_loaded_cutus (const void *a, const void *b)
9176 const struct dwo_unit *dua = a;
9177 const struct dwo_unit *dub = b;
9179 return dua->signature == dub->signature;
9182 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
9185 allocate_dwp_loaded_cutus_table (struct objfile *objfile)
9187 return htab_create_alloc_ex (3,
9188 hash_dwp_loaded_cutus,
9189 eq_dwp_loaded_cutus,
9191 &objfile->objfile_obstack,
9192 hashtab_obstack_allocate,
9193 dummy_obstack_deallocate);
9196 /* Try to open DWP file FILE_NAME.
9197 The result is the bfd handle of the file.
9198 If there is a problem finding or opening the file, return NULL.
9199 Upon success, the canonicalized path of the file is stored in the bfd,
9200 same as symfile_bfd_open. */
9203 open_dwp_file (const char *file_name)
9205 return try_open_dwop_file (file_name, 1 /*is_dwp*/);
9208 /* Initialize the use of the DWP file for the current objfile.
9209 By convention the name of the DWP file is ${objfile}.dwp.
9210 The result is NULL if it can't be found. */
9212 static struct dwp_file *
9213 open_and_init_dwp_file (void)
9215 struct objfile *objfile = dwarf2_per_objfile->objfile;
9216 struct dwp_file *dwp_file;
9219 struct cleanup *cleanups;
9221 dwp_name = xstrprintf ("%s.dwp", dwarf2_per_objfile->objfile->name);
9222 cleanups = make_cleanup (xfree, dwp_name);
9224 dbfd = open_dwp_file (dwp_name);
9227 if (dwarf2_read_debug)
9228 fprintf_unfiltered (gdb_stdlog, "DWP file not found: %s\n", dwp_name);
9229 do_cleanups (cleanups);
9232 dwp_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_file);
9233 dwp_file->name = obstack_copy0 (&objfile->objfile_obstack,
9234 dwp_name, strlen (dwp_name));
9235 dwp_file->dbfd = dbfd;
9236 do_cleanups (cleanups);
9238 /* +1: section 0 is unused */
9239 dwp_file->num_sections = bfd_count_sections (dbfd) + 1;
9240 dwp_file->elf_sections =
9241 OBSTACK_CALLOC (&objfile->objfile_obstack,
9242 dwp_file->num_sections, asection *);
9244 bfd_map_over_sections (dbfd, dwarf2_locate_dwp_sections, dwp_file);
9246 dwp_file->cus = create_dwp_hash_table (dwp_file, 0);
9248 dwp_file->tus = create_dwp_hash_table (dwp_file, 1);
9250 dwp_file->loaded_cutus = allocate_dwp_loaded_cutus_table (objfile);
9252 if (dwarf2_read_debug)
9254 fprintf_unfiltered (gdb_stdlog, "DWP file found: %s\n", dwp_file->name);
9255 fprintf_unfiltered (gdb_stdlog,
9256 " %u CUs, %u TUs\n",
9257 dwp_file->cus ? dwp_file->cus->nr_units : 0,
9258 dwp_file->tus ? dwp_file->tus->nr_units : 0);
9264 /* Wrapper around open_and_init_dwp_file, only open it once. */
9266 static struct dwp_file *
9269 if (! dwarf2_per_objfile->dwp_checked)
9271 dwarf2_per_objfile->dwp_file = open_and_init_dwp_file ();
9272 dwarf2_per_objfile->dwp_checked = 1;
9274 return dwarf2_per_objfile->dwp_file;
9277 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9278 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9279 or in the DWP file for the objfile, referenced by THIS_UNIT.
9280 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9281 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9283 This is called, for example, when wanting to read a variable with a
9284 complex location. Therefore we don't want to do file i/o for every call.
9285 Therefore we don't want to look for a DWO file on every call.
9286 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9287 then we check if we've already seen DWO_NAME, and only THEN do we check
9290 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9291 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9293 static struct dwo_unit *
9294 lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
9295 const char *dwo_name, const char *comp_dir,
9296 ULONGEST signature, int is_debug_types)
9298 struct objfile *objfile = dwarf2_per_objfile->objfile;
9299 const char *kind = is_debug_types ? "TU" : "CU";
9300 void **dwo_file_slot;
9301 struct dwo_file *dwo_file;
9302 struct dwp_file *dwp_file;
9304 /* First see if there's a DWP file.
9305 If we have a DWP file but didn't find the DWO inside it, don't
9306 look for the original DWO file. It makes gdb behave differently
9307 depending on whether one is debugging in the build tree. */
9309 dwp_file = get_dwp_file ();
9310 if (dwp_file != NULL)
9312 const struct dwp_hash_table *dwp_htab =
9313 is_debug_types ? dwp_file->tus : dwp_file->cus;
9315 if (dwp_htab != NULL)
9317 struct dwo_unit *dwo_cutu =
9318 lookup_dwo_in_dwp (dwp_file, dwp_htab, comp_dir,
9319 signature, is_debug_types);
9321 if (dwo_cutu != NULL)
9323 if (dwarf2_read_debug)
9325 fprintf_unfiltered (gdb_stdlog,
9326 "Virtual DWO %s %s found: @%s\n",
9327 kind, hex_string (signature),
9328 host_address_to_string (dwo_cutu));
9336 /* No DWP file, look for the DWO file. */
9338 dwo_file_slot = lookup_dwo_file_slot (dwo_name, comp_dir);
9339 if (*dwo_file_slot == NULL)
9341 /* Read in the file and build a table of the CUs/TUs it contains. */
9342 *dwo_file_slot = open_and_init_dwo_file (this_unit, dwo_name, comp_dir);
9344 /* NOTE: This will be NULL if unable to open the file. */
9345 dwo_file = *dwo_file_slot;
9347 if (dwo_file != NULL)
9349 struct dwo_unit *dwo_cutu = NULL;
9351 if (is_debug_types && dwo_file->tus)
9353 struct dwo_unit find_dwo_cutu;
9355 memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
9356 find_dwo_cutu.signature = signature;
9357 dwo_cutu = htab_find (dwo_file->tus, &find_dwo_cutu);
9359 else if (!is_debug_types && dwo_file->cu)
9361 if (signature == dwo_file->cu->signature)
9362 dwo_cutu = dwo_file->cu;
9365 if (dwo_cutu != NULL)
9367 if (dwarf2_read_debug)
9369 fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) found: @%s\n",
9370 kind, dwo_name, hex_string (signature),
9371 host_address_to_string (dwo_cutu));
9378 /* We didn't find it. This could mean a dwo_id mismatch, or
9379 someone deleted the DWO/DWP file, or the search path isn't set up
9380 correctly to find the file. */
9382 if (dwarf2_read_debug)
9384 fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) not found\n",
9385 kind, dwo_name, hex_string (signature));
9388 complaint (&symfile_complaints,
9389 _("Could not find DWO %s %s(%s) referenced by CU at offset 0x%x"
9391 kind, dwo_name, hex_string (signature),
9392 this_unit->offset.sect_off, objfile->name);
9396 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9397 See lookup_dwo_cutu_unit for details. */
9399 static struct dwo_unit *
9400 lookup_dwo_comp_unit (struct dwarf2_per_cu_data *this_cu,
9401 const char *dwo_name, const char *comp_dir,
9404 return lookup_dwo_cutu (this_cu, dwo_name, comp_dir, signature, 0);
9407 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9408 See lookup_dwo_cutu_unit for details. */
9410 static struct dwo_unit *
9411 lookup_dwo_type_unit (struct signatured_type *this_tu,
9412 const char *dwo_name, const char *comp_dir)
9414 return lookup_dwo_cutu (&this_tu->per_cu, dwo_name, comp_dir, this_tu->signature, 1);
9417 /* Free all resources associated with DWO_FILE.
9418 Close the DWO file and munmap the sections.
9419 All memory should be on the objfile obstack. */
9422 free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile)
9425 struct dwarf2_section_info *section;
9427 /* Note: dbfd is NULL for virtual DWO files. */
9428 gdb_bfd_unref (dwo_file->dbfd);
9430 VEC_free (dwarf2_section_info_def, dwo_file->sections.types);
9433 /* Wrapper for free_dwo_file for use in cleanups. */
9436 free_dwo_file_cleanup (void *arg)
9438 struct dwo_file *dwo_file = (struct dwo_file *) arg;
9439 struct objfile *objfile = dwarf2_per_objfile->objfile;
9441 free_dwo_file (dwo_file, objfile);
9444 /* Traversal function for free_dwo_files. */
9447 free_dwo_file_from_slot (void **slot, void *info)
9449 struct dwo_file *dwo_file = (struct dwo_file *) *slot;
9450 struct objfile *objfile = (struct objfile *) info;
9452 free_dwo_file (dwo_file, objfile);
9457 /* Free all resources associated with DWO_FILES. */
9460 free_dwo_files (htab_t dwo_files, struct objfile *objfile)
9462 htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile);
9465 /* Read in various DIEs. */
9467 /* qsort helper for inherit_abstract_dies. */
9470 unsigned_int_compar (const void *ap, const void *bp)
9472 unsigned int a = *(unsigned int *) ap;
9473 unsigned int b = *(unsigned int *) bp;
9475 return (a > b) - (b > a);
9478 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9479 Inherit only the children of the DW_AT_abstract_origin DIE not being
9480 already referenced by DW_AT_abstract_origin from the children of the
9484 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
9486 struct die_info *child_die;
9487 unsigned die_children_count;
9488 /* CU offsets which were referenced by children of the current DIE. */
9489 sect_offset *offsets;
9490 sect_offset *offsets_end, *offsetp;
9491 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9492 struct die_info *origin_die;
9493 /* Iterator of the ORIGIN_DIE children. */
9494 struct die_info *origin_child_die;
9495 struct cleanup *cleanups;
9496 struct attribute *attr;
9497 struct dwarf2_cu *origin_cu;
9498 struct pending **origin_previous_list_in_scope;
9500 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
9504 /* Note that following die references may follow to a die in a
9508 origin_die = follow_die_ref (die, attr, &origin_cu);
9510 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9512 origin_previous_list_in_scope = origin_cu->list_in_scope;
9513 origin_cu->list_in_scope = cu->list_in_scope;
9515 if (die->tag != origin_die->tag
9516 && !(die->tag == DW_TAG_inlined_subroutine
9517 && origin_die->tag == DW_TAG_subprogram))
9518 complaint (&symfile_complaints,
9519 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9520 die->offset.sect_off, origin_die->offset.sect_off);
9522 child_die = die->child;
9523 die_children_count = 0;
9524 while (child_die && child_die->tag)
9526 child_die = sibling_die (child_die);
9527 die_children_count++;
9529 offsets = xmalloc (sizeof (*offsets) * die_children_count);
9530 cleanups = make_cleanup (xfree, offsets);
9532 offsets_end = offsets;
9533 child_die = die->child;
9534 while (child_die && child_die->tag)
9536 /* For each CHILD_DIE, find the corresponding child of
9537 ORIGIN_DIE. If there is more than one layer of
9538 DW_AT_abstract_origin, follow them all; there shouldn't be,
9539 but GCC versions at least through 4.4 generate this (GCC PR
9541 struct die_info *child_origin_die = child_die;
9542 struct dwarf2_cu *child_origin_cu = cu;
9546 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
9550 child_origin_die = follow_die_ref (child_origin_die, attr,
9554 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9555 counterpart may exist. */
9556 if (child_origin_die != child_die)
9558 if (child_die->tag != child_origin_die->tag
9559 && !(child_die->tag == DW_TAG_inlined_subroutine
9560 && child_origin_die->tag == DW_TAG_subprogram))
9561 complaint (&symfile_complaints,
9562 _("Child DIE 0x%x and its abstract origin 0x%x have "
9563 "different tags"), child_die->offset.sect_off,
9564 child_origin_die->offset.sect_off);
9565 if (child_origin_die->parent != origin_die)
9566 complaint (&symfile_complaints,
9567 _("Child DIE 0x%x and its abstract origin 0x%x have "
9568 "different parents"), child_die->offset.sect_off,
9569 child_origin_die->offset.sect_off);
9571 *offsets_end++ = child_origin_die->offset;
9573 child_die = sibling_die (child_die);
9575 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
9576 unsigned_int_compar);
9577 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
9578 if (offsetp[-1].sect_off == offsetp->sect_off)
9579 complaint (&symfile_complaints,
9580 _("Multiple children of DIE 0x%x refer "
9581 "to DIE 0x%x as their abstract origin"),
9582 die->offset.sect_off, offsetp->sect_off);
9585 origin_child_die = origin_die->child;
9586 while (origin_child_die && origin_child_die->tag)
9588 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9589 while (offsetp < offsets_end
9590 && offsetp->sect_off < origin_child_die->offset.sect_off)
9592 if (offsetp >= offsets_end
9593 || offsetp->sect_off > origin_child_die->offset.sect_off)
9595 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9596 process_die (origin_child_die, origin_cu);
9598 origin_child_die = sibling_die (origin_child_die);
9600 origin_cu->list_in_scope = origin_previous_list_in_scope;
9602 do_cleanups (cleanups);
9606 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
9608 struct objfile *objfile = cu->objfile;
9609 struct context_stack *new;
9612 struct die_info *child_die;
9613 struct attribute *attr, *call_line, *call_file;
9616 struct block *block;
9617 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
9618 VEC (symbolp) *template_args = NULL;
9619 struct template_symbol *templ_func = NULL;
9623 /* If we do not have call site information, we can't show the
9624 caller of this inlined function. That's too confusing, so
9625 only use the scope for local variables. */
9626 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
9627 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
9628 if (call_line == NULL || call_file == NULL)
9630 read_lexical_block_scope (die, cu);
9635 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9637 name = dwarf2_name (die, cu);
9639 /* Ignore functions with missing or empty names. These are actually
9640 illegal according to the DWARF standard. */
9643 complaint (&symfile_complaints,
9644 _("missing name for subprogram DIE at %d"),
9645 die->offset.sect_off);
9649 /* Ignore functions with missing or invalid low and high pc attributes. */
9650 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
9652 attr = dwarf2_attr (die, DW_AT_external, cu);
9653 if (!attr || !DW_UNSND (attr))
9654 complaint (&symfile_complaints,
9655 _("cannot get low and high bounds "
9656 "for subprogram DIE at %d"),
9657 die->offset.sect_off);
9664 /* If we have any template arguments, then we must allocate a
9665 different sort of symbol. */
9666 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
9668 if (child_die->tag == DW_TAG_template_type_param
9669 || child_die->tag == DW_TAG_template_value_param)
9671 templ_func = allocate_template_symbol (objfile);
9672 templ_func->base.is_cplus_template_function = 1;
9677 new = push_context (0, lowpc);
9678 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
9679 (struct symbol *) templ_func);
9681 /* If there is a location expression for DW_AT_frame_base, record
9683 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
9685 dwarf2_symbol_mark_computed (attr, new->name, cu, 1);
9687 cu->list_in_scope = &local_symbols;
9689 if (die->child != NULL)
9691 child_die = die->child;
9692 while (child_die && child_die->tag)
9694 if (child_die->tag == DW_TAG_template_type_param
9695 || child_die->tag == DW_TAG_template_value_param)
9697 struct symbol *arg = new_symbol (child_die, NULL, cu);
9700 VEC_safe_push (symbolp, template_args, arg);
9703 process_die (child_die, cu);
9704 child_die = sibling_die (child_die);
9708 inherit_abstract_dies (die, cu);
9710 /* If we have a DW_AT_specification, we might need to import using
9711 directives from the context of the specification DIE. See the
9712 comment in determine_prefix. */
9713 if (cu->language == language_cplus
9714 && dwarf2_attr (die, DW_AT_specification, cu))
9716 struct dwarf2_cu *spec_cu = cu;
9717 struct die_info *spec_die = die_specification (die, &spec_cu);
9721 child_die = spec_die->child;
9722 while (child_die && child_die->tag)
9724 if (child_die->tag == DW_TAG_imported_module)
9725 process_die (child_die, spec_cu);
9726 child_die = sibling_die (child_die);
9729 /* In some cases, GCC generates specification DIEs that
9730 themselves contain DW_AT_specification attributes. */
9731 spec_die = die_specification (spec_die, &spec_cu);
9735 new = pop_context ();
9736 /* Make a block for the local symbols within. */
9737 block = finish_block (new->name, &local_symbols, new->old_blocks,
9738 lowpc, highpc, objfile);
9740 /* For C++, set the block's scope. */
9741 if ((cu->language == language_cplus || cu->language == language_fortran)
9742 && cu->processing_has_namespace_info)
9743 block_set_scope (block, determine_prefix (die, cu),
9744 &objfile->objfile_obstack);
9746 /* If we have address ranges, record them. */
9747 dwarf2_record_block_ranges (die, block, baseaddr, cu);
9749 /* Attach template arguments to function. */
9750 if (! VEC_empty (symbolp, template_args))
9752 gdb_assert (templ_func != NULL);
9754 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
9755 templ_func->template_arguments
9756 = obstack_alloc (&objfile->objfile_obstack,
9757 (templ_func->n_template_arguments
9758 * sizeof (struct symbol *)));
9759 memcpy (templ_func->template_arguments,
9760 VEC_address (symbolp, template_args),
9761 (templ_func->n_template_arguments * sizeof (struct symbol *)));
9762 VEC_free (symbolp, template_args);
9765 /* In C++, we can have functions nested inside functions (e.g., when
9766 a function declares a class that has methods). This means that
9767 when we finish processing a function scope, we may need to go
9768 back to building a containing block's symbol lists. */
9769 local_symbols = new->locals;
9770 using_directives = new->using_directives;
9772 /* If we've finished processing a top-level function, subsequent
9773 symbols go in the file symbol list. */
9774 if (outermost_context_p ())
9775 cu->list_in_scope = &file_symbols;
9778 /* Process all the DIES contained within a lexical block scope. Start
9779 a new scope, process the dies, and then close the scope. */
9782 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
9784 struct objfile *objfile = cu->objfile;
9785 struct context_stack *new;
9786 CORE_ADDR lowpc, highpc;
9787 struct die_info *child_die;
9790 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9792 /* Ignore blocks with missing or invalid low and high pc attributes. */
9793 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9794 as multiple lexical blocks? Handling children in a sane way would
9795 be nasty. Might be easier to properly extend generic blocks to
9797 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
9802 push_context (0, lowpc);
9803 if (die->child != NULL)
9805 child_die = die->child;
9806 while (child_die && child_die->tag)
9808 process_die (child_die, cu);
9809 child_die = sibling_die (child_die);
9812 new = pop_context ();
9814 if (local_symbols != NULL || using_directives != NULL)
9817 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
9820 /* Note that recording ranges after traversing children, as we
9821 do here, means that recording a parent's ranges entails
9822 walking across all its children's ranges as they appear in
9823 the address map, which is quadratic behavior.
9825 It would be nicer to record the parent's ranges before
9826 traversing its children, simply overriding whatever you find
9827 there. But since we don't even decide whether to create a
9828 block until after we've traversed its children, that's hard
9830 dwarf2_record_block_ranges (die, block, baseaddr, cu);
9832 local_symbols = new->locals;
9833 using_directives = new->using_directives;
9836 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9839 read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
9841 struct objfile *objfile = cu->objfile;
9842 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9843 CORE_ADDR pc, baseaddr;
9844 struct attribute *attr;
9845 struct call_site *call_site, call_site_local;
9848 struct die_info *child_die;
9850 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9852 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
9855 complaint (&symfile_complaints,
9856 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9857 "DIE 0x%x [in module %s]"),
9858 die->offset.sect_off, objfile->name);
9861 pc = DW_ADDR (attr) + baseaddr;
9863 if (cu->call_site_htab == NULL)
9864 cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
9865 NULL, &objfile->objfile_obstack,
9866 hashtab_obstack_allocate, NULL);
9867 call_site_local.pc = pc;
9868 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
9871 complaint (&symfile_complaints,
9872 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9873 "DIE 0x%x [in module %s]"),
9874 paddress (gdbarch, pc), die->offset.sect_off, objfile->name);
9878 /* Count parameters at the caller. */
9881 for (child_die = die->child; child_die && child_die->tag;
9882 child_die = sibling_die (child_die))
9884 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
9886 complaint (&symfile_complaints,
9887 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9888 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9889 child_die->tag, child_die->offset.sect_off, objfile->name);
9896 call_site = obstack_alloc (&objfile->objfile_obstack,
9897 (sizeof (*call_site)
9898 + (sizeof (*call_site->parameter)
9901 memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
9904 if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
9906 struct die_info *func_die;
9908 /* Skip also over DW_TAG_inlined_subroutine. */
9909 for (func_die = die->parent;
9910 func_die && func_die->tag != DW_TAG_subprogram
9911 && func_die->tag != DW_TAG_subroutine_type;
9912 func_die = func_die->parent);
9914 /* DW_AT_GNU_all_call_sites is a superset
9915 of DW_AT_GNU_all_tail_call_sites. */
9917 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
9918 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
9920 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9921 not complete. But keep CALL_SITE for look ups via call_site_htab,
9922 both the initial caller containing the real return address PC and
9923 the final callee containing the current PC of a chain of tail
9924 calls do not need to have the tail call list complete. But any
9925 function candidate for a virtual tail call frame searched via
9926 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9927 determined unambiguously. */
9931 struct type *func_type = NULL;
9934 func_type = get_die_type (func_die, cu);
9935 if (func_type != NULL)
9937 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
9939 /* Enlist this call site to the function. */
9940 call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
9941 TYPE_TAIL_CALL_LIST (func_type) = call_site;
9944 complaint (&symfile_complaints,
9945 _("Cannot find function owning DW_TAG_GNU_call_site "
9946 "DIE 0x%x [in module %s]"),
9947 die->offset.sect_off, objfile->name);
9951 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
9953 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
9954 SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
9955 if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
9956 /* Keep NULL DWARF_BLOCK. */;
9957 else if (attr_form_is_block (attr))
9959 struct dwarf2_locexpr_baton *dlbaton;
9961 dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton));
9962 dlbaton->data = DW_BLOCK (attr)->data;
9963 dlbaton->size = DW_BLOCK (attr)->size;
9964 dlbaton->per_cu = cu->per_cu;
9966 SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
9968 else if (is_ref_attr (attr))
9970 struct dwarf2_cu *target_cu = cu;
9971 struct die_info *target_die;
9973 target_die = follow_die_ref (die, attr, &target_cu);
9974 gdb_assert (target_cu->objfile == objfile);
9975 if (die_is_declaration (target_die, target_cu))
9977 const char *target_physname = NULL;
9978 struct attribute *target_attr;
9980 /* Prefer the mangled name; otherwise compute the demangled one. */
9981 target_attr = dwarf2_attr (target_die, DW_AT_linkage_name, target_cu);
9982 if (target_attr == NULL)
9983 target_attr = dwarf2_attr (target_die, DW_AT_MIPS_linkage_name,
9985 if (target_attr != NULL && DW_STRING (target_attr) != NULL)
9986 target_physname = DW_STRING (target_attr);
9988 target_physname = dwarf2_physname (NULL, target_die, target_cu);
9989 if (target_physname == NULL)
9990 complaint (&symfile_complaints,
9991 _("DW_AT_GNU_call_site_target target DIE has invalid "
9992 "physname, for referencing DIE 0x%x [in module %s]"),
9993 die->offset.sect_off, objfile->name);
9995 SET_FIELD_PHYSNAME (call_site->target, target_physname);
10001 /* DW_AT_entry_pc should be preferred. */
10002 if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
10003 complaint (&symfile_complaints,
10004 _("DW_AT_GNU_call_site_target target DIE has invalid "
10005 "low pc, for referencing DIE 0x%x [in module %s]"),
10006 die->offset.sect_off, objfile->name);
10008 SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
10012 complaint (&symfile_complaints,
10013 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
10014 "block nor reference, for DIE 0x%x [in module %s]"),
10015 die->offset.sect_off, objfile->name);
10017 call_site->per_cu = cu->per_cu;
10019 for (child_die = die->child;
10020 child_die && child_die->tag;
10021 child_die = sibling_die (child_die))
10023 struct call_site_parameter *parameter;
10024 struct attribute *loc, *origin;
10026 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
10028 /* Already printed the complaint above. */
10032 gdb_assert (call_site->parameter_count < nparams);
10033 parameter = &call_site->parameter[call_site->parameter_count];
10035 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
10036 specifies DW_TAG_formal_parameter. Value of the data assumed for the
10037 register is contained in DW_AT_GNU_call_site_value. */
10039 loc = dwarf2_attr (child_die, DW_AT_location, cu);
10040 origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu);
10041 if (loc == NULL && origin != NULL && is_ref_attr (origin))
10043 sect_offset offset;
10045 parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET;
10046 offset = dwarf2_get_ref_die_offset (origin);
10047 if (!offset_in_cu_p (&cu->header, offset))
10049 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
10050 binding can be done only inside one CU. Such referenced DIE
10051 therefore cannot be even moved to DW_TAG_partial_unit. */
10052 complaint (&symfile_complaints,
10053 _("DW_AT_abstract_origin offset is not in CU for "
10054 "DW_TAG_GNU_call_site child DIE 0x%x "
10056 child_die->offset.sect_off, objfile->name);
10059 parameter->u.param_offset.cu_off = (offset.sect_off
10060 - cu->header.offset.sect_off);
10062 else if (loc == NULL || origin != NULL || !attr_form_is_block (loc))
10064 complaint (&symfile_complaints,
10065 _("No DW_FORM_block* DW_AT_location for "
10066 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10067 child_die->offset.sect_off, objfile->name);
10072 parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg
10073 (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]);
10074 if (parameter->u.dwarf_reg != -1)
10075 parameter->kind = CALL_SITE_PARAMETER_DWARF_REG;
10076 else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data,
10077 &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size],
10078 ¶meter->u.fb_offset))
10079 parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET;
10082 complaint (&symfile_complaints,
10083 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
10084 "for DW_FORM_block* DW_AT_location is supported for "
10085 "DW_TAG_GNU_call_site child DIE 0x%x "
10087 child_die->offset.sect_off, objfile->name);
10092 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
10093 if (!attr_form_is_block (attr))
10095 complaint (&symfile_complaints,
10096 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
10097 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10098 child_die->offset.sect_off, objfile->name);
10101 parameter->value = DW_BLOCK (attr)->data;
10102 parameter->value_size = DW_BLOCK (attr)->size;
10104 /* Parameters are not pre-cleared by memset above. */
10105 parameter->data_value = NULL;
10106 parameter->data_value_size = 0;
10107 call_site->parameter_count++;
10109 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
10112 if (!attr_form_is_block (attr))
10113 complaint (&symfile_complaints,
10114 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
10115 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
10116 child_die->offset.sect_off, objfile->name);
10119 parameter->data_value = DW_BLOCK (attr)->data;
10120 parameter->data_value_size = DW_BLOCK (attr)->size;
10126 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
10127 Return 1 if the attributes are present and valid, otherwise, return 0.
10128 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
10131 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
10132 CORE_ADDR *high_return, struct dwarf2_cu *cu,
10133 struct partial_symtab *ranges_pst)
10135 struct objfile *objfile = cu->objfile;
10136 struct comp_unit_head *cu_header = &cu->header;
10137 bfd *obfd = objfile->obfd;
10138 unsigned int addr_size = cu_header->addr_size;
10139 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
10140 /* Base address selection entry. */
10143 unsigned int dummy;
10144 const gdb_byte *buffer;
10148 CORE_ADDR high = 0;
10149 CORE_ADDR baseaddr;
10151 found_base = cu->base_known;
10152 base = cu->base_address;
10154 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
10155 if (offset >= dwarf2_per_objfile->ranges.size)
10157 complaint (&symfile_complaints,
10158 _("Offset %d out of bounds for DW_AT_ranges attribute"),
10162 buffer = dwarf2_per_objfile->ranges.buffer + offset;
10164 /* Read in the largest possible address. */
10165 marker = read_address (obfd, buffer, cu, &dummy);
10166 if ((marker & mask) == mask)
10168 /* If we found the largest possible address, then
10169 read the base address. */
10170 base = read_address (obfd, buffer + addr_size, cu, &dummy);
10171 buffer += 2 * addr_size;
10172 offset += 2 * addr_size;
10178 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
10182 CORE_ADDR range_beginning, range_end;
10184 range_beginning = read_address (obfd, buffer, cu, &dummy);
10185 buffer += addr_size;
10186 range_end = read_address (obfd, buffer, cu, &dummy);
10187 buffer += addr_size;
10188 offset += 2 * addr_size;
10190 /* An end of list marker is a pair of zero addresses. */
10191 if (range_beginning == 0 && range_end == 0)
10192 /* Found the end of list entry. */
10195 /* Each base address selection entry is a pair of 2 values.
10196 The first is the largest possible address, the second is
10197 the base address. Check for a base address here. */
10198 if ((range_beginning & mask) == mask)
10200 /* If we found the largest possible address, then
10201 read the base address. */
10202 base = read_address (obfd, buffer + addr_size, cu, &dummy);
10209 /* We have no valid base address for the ranges
10211 complaint (&symfile_complaints,
10212 _("Invalid .debug_ranges data (no base address)"));
10216 if (range_beginning > range_end)
10218 /* Inverted range entries are invalid. */
10219 complaint (&symfile_complaints,
10220 _("Invalid .debug_ranges data (inverted range)"));
10224 /* Empty range entries have no effect. */
10225 if (range_beginning == range_end)
10228 range_beginning += base;
10231 /* A not-uncommon case of bad debug info.
10232 Don't pollute the addrmap with bad data. */
10233 if (range_beginning + baseaddr == 0
10234 && !dwarf2_per_objfile->has_section_at_zero)
10236 complaint (&symfile_complaints,
10237 _(".debug_ranges entry has start address of zero"
10238 " [in module %s]"), objfile->name);
10242 if (ranges_pst != NULL)
10243 addrmap_set_empty (objfile->psymtabs_addrmap,
10244 range_beginning + baseaddr,
10245 range_end - 1 + baseaddr,
10248 /* FIXME: This is recording everything as a low-high
10249 segment of consecutive addresses. We should have a
10250 data structure for discontiguous block ranges
10254 low = range_beginning;
10260 if (range_beginning < low)
10261 low = range_beginning;
10262 if (range_end > high)
10268 /* If the first entry is an end-of-list marker, the range
10269 describes an empty scope, i.e. no instructions. */
10275 *high_return = high;
10279 /* Get low and high pc attributes from a die. Return 1 if the attributes
10280 are present and valid, otherwise, return 0. Return -1 if the range is
10281 discontinuous, i.e. derived from DW_AT_ranges information. */
10284 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
10285 CORE_ADDR *highpc, struct dwarf2_cu *cu,
10286 struct partial_symtab *pst)
10288 struct attribute *attr;
10289 struct attribute *attr_high;
10291 CORE_ADDR high = 0;
10294 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
10297 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
10300 low = DW_ADDR (attr);
10301 if (attr_high->form == DW_FORM_addr
10302 || attr_high->form == DW_FORM_GNU_addr_index)
10303 high = DW_ADDR (attr_high);
10305 high = low + DW_UNSND (attr_high);
10308 /* Found high w/o low attribute. */
10311 /* Found consecutive range of addresses. */
10316 attr = dwarf2_attr (die, DW_AT_ranges, cu);
10319 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10320 We take advantage of the fact that DW_AT_ranges does not appear
10321 in DW_TAG_compile_unit of DWO files. */
10322 int need_ranges_base = die->tag != DW_TAG_compile_unit;
10323 unsigned int ranges_offset = (DW_UNSND (attr)
10324 + (need_ranges_base
10328 /* Value of the DW_AT_ranges attribute is the offset in the
10329 .debug_ranges section. */
10330 if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst))
10332 /* Found discontinuous range of addresses. */
10337 /* read_partial_die has also the strict LOW < HIGH requirement. */
10341 /* When using the GNU linker, .gnu.linkonce. sections are used to
10342 eliminate duplicate copies of functions and vtables and such.
10343 The linker will arbitrarily choose one and discard the others.
10344 The AT_*_pc values for such functions refer to local labels in
10345 these sections. If the section from that file was discarded, the
10346 labels are not in the output, so the relocs get a value of 0.
10347 If this is a discarded function, mark the pc bounds as invalid,
10348 so that GDB will ignore it. */
10349 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
10358 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10359 its low and high PC addresses. Do nothing if these addresses could not
10360 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10361 and HIGHPC to the high address if greater than HIGHPC. */
10364 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
10365 CORE_ADDR *lowpc, CORE_ADDR *highpc,
10366 struct dwarf2_cu *cu)
10368 CORE_ADDR low, high;
10369 struct die_info *child = die->child;
10371 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
10373 *lowpc = min (*lowpc, low);
10374 *highpc = max (*highpc, high);
10377 /* If the language does not allow nested subprograms (either inside
10378 subprograms or lexical blocks), we're done. */
10379 if (cu->language != language_ada)
10382 /* Check all the children of the given DIE. If it contains nested
10383 subprograms, then check their pc bounds. Likewise, we need to
10384 check lexical blocks as well, as they may also contain subprogram
10386 while (child && child->tag)
10388 if (child->tag == DW_TAG_subprogram
10389 || child->tag == DW_TAG_lexical_block)
10390 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
10391 child = sibling_die (child);
10395 /* Get the low and high pc's represented by the scope DIE, and store
10396 them in *LOWPC and *HIGHPC. If the correct values can't be
10397 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10400 get_scope_pc_bounds (struct die_info *die,
10401 CORE_ADDR *lowpc, CORE_ADDR *highpc,
10402 struct dwarf2_cu *cu)
10404 CORE_ADDR best_low = (CORE_ADDR) -1;
10405 CORE_ADDR best_high = (CORE_ADDR) 0;
10406 CORE_ADDR current_low, current_high;
10408 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
10410 best_low = current_low;
10411 best_high = current_high;
10415 struct die_info *child = die->child;
10417 while (child && child->tag)
10419 switch (child->tag) {
10420 case DW_TAG_subprogram:
10421 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
10423 case DW_TAG_namespace:
10424 case DW_TAG_module:
10425 /* FIXME: carlton/2004-01-16: Should we do this for
10426 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10427 that current GCC's always emit the DIEs corresponding
10428 to definitions of methods of classes as children of a
10429 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10430 the DIEs giving the declarations, which could be
10431 anywhere). But I don't see any reason why the
10432 standards says that they have to be there. */
10433 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
10435 if (current_low != ((CORE_ADDR) -1))
10437 best_low = min (best_low, current_low);
10438 best_high = max (best_high, current_high);
10446 child = sibling_die (child);
10451 *highpc = best_high;
10454 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10458 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
10459 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
10461 struct objfile *objfile = cu->objfile;
10462 struct attribute *attr;
10463 struct attribute *attr_high;
10465 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
10468 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
10471 CORE_ADDR low = DW_ADDR (attr);
10473 if (attr_high->form == DW_FORM_addr
10474 || attr_high->form == DW_FORM_GNU_addr_index)
10475 high = DW_ADDR (attr_high);
10477 high = low + DW_UNSND (attr_high);
10479 record_block_range (block, baseaddr + low, baseaddr + high - 1);
10483 attr = dwarf2_attr (die, DW_AT_ranges, cu);
10486 bfd *obfd = objfile->obfd;
10487 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
10488 We take advantage of the fact that DW_AT_ranges does not appear
10489 in DW_TAG_compile_unit of DWO files. */
10490 int need_ranges_base = die->tag != DW_TAG_compile_unit;
10492 /* The value of the DW_AT_ranges attribute is the offset of the
10493 address range list in the .debug_ranges section. */
10494 unsigned long offset = (DW_UNSND (attr)
10495 + (need_ranges_base ? cu->ranges_base : 0));
10496 const gdb_byte *buffer;
10498 /* For some target architectures, but not others, the
10499 read_address function sign-extends the addresses it returns.
10500 To recognize base address selection entries, we need a
10502 unsigned int addr_size = cu->header.addr_size;
10503 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
10505 /* The base address, to which the next pair is relative. Note
10506 that this 'base' is a DWARF concept: most entries in a range
10507 list are relative, to reduce the number of relocs against the
10508 debugging information. This is separate from this function's
10509 'baseaddr' argument, which GDB uses to relocate debugging
10510 information from a shared library based on the address at
10511 which the library was loaded. */
10512 CORE_ADDR base = cu->base_address;
10513 int base_known = cu->base_known;
10515 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
10516 if (offset >= dwarf2_per_objfile->ranges.size)
10518 complaint (&symfile_complaints,
10519 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10523 buffer = dwarf2_per_objfile->ranges.buffer + offset;
10527 unsigned int bytes_read;
10528 CORE_ADDR start, end;
10530 start = read_address (obfd, buffer, cu, &bytes_read);
10531 buffer += bytes_read;
10532 end = read_address (obfd, buffer, cu, &bytes_read);
10533 buffer += bytes_read;
10535 /* Did we find the end of the range list? */
10536 if (start == 0 && end == 0)
10539 /* Did we find a base address selection entry? */
10540 else if ((start & base_select_mask) == base_select_mask)
10546 /* We found an ordinary address range. */
10551 complaint (&symfile_complaints,
10552 _("Invalid .debug_ranges data "
10553 "(no base address)"));
10559 /* Inverted range entries are invalid. */
10560 complaint (&symfile_complaints,
10561 _("Invalid .debug_ranges data "
10562 "(inverted range)"));
10566 /* Empty range entries have no effect. */
10570 start += base + baseaddr;
10571 end += base + baseaddr;
10573 /* A not-uncommon case of bad debug info.
10574 Don't pollute the addrmap with bad data. */
10575 if (start == 0 && !dwarf2_per_objfile->has_section_at_zero)
10577 complaint (&symfile_complaints,
10578 _(".debug_ranges entry has start address of zero"
10579 " [in module %s]"), objfile->name);
10583 record_block_range (block, start, end - 1);
10589 /* Check whether the producer field indicates either of GCC < 4.6, or the
10590 Intel C/C++ compiler, and cache the result in CU. */
10593 check_producer (struct dwarf2_cu *cu)
10596 int major, minor, release;
10598 if (cu->producer == NULL)
10600 /* For unknown compilers expect their behavior is DWARF version
10603 GCC started to support .debug_types sections by -gdwarf-4 since
10604 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10605 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10606 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10607 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10609 else if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) == 0)
10611 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10613 cs = &cu->producer[strlen ("GNU ")];
10614 while (*cs && !isdigit (*cs))
10616 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
10618 /* Not recognized as GCC. */
10622 cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
10623 cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3);
10626 else if (strncmp (cu->producer, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10627 cu->producer_is_icc = 1;
10630 /* For other non-GCC compilers, expect their behavior is DWARF version
10634 cu->checked_producer = 1;
10637 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10638 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10639 during 4.6.0 experimental. */
10642 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
10644 if (!cu->checked_producer)
10645 check_producer (cu);
10647 return cu->producer_is_gxx_lt_4_6;
10650 /* Return the default accessibility type if it is not overriden by
10651 DW_AT_accessibility. */
10653 static enum dwarf_access_attribute
10654 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
10656 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
10658 /* The default DWARF 2 accessibility for members is public, the default
10659 accessibility for inheritance is private. */
10661 if (die->tag != DW_TAG_inheritance)
10662 return DW_ACCESS_public;
10664 return DW_ACCESS_private;
10668 /* DWARF 3+ defines the default accessibility a different way. The same
10669 rules apply now for DW_TAG_inheritance as for the members and it only
10670 depends on the container kind. */
10672 if (die->parent->tag == DW_TAG_class_type)
10673 return DW_ACCESS_private;
10675 return DW_ACCESS_public;
10679 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10680 offset. If the attribute was not found return 0, otherwise return
10681 1. If it was found but could not properly be handled, set *OFFSET
10685 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
10688 struct attribute *attr;
10690 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
10695 /* Note that we do not check for a section offset first here.
10696 This is because DW_AT_data_member_location is new in DWARF 4,
10697 so if we see it, we can assume that a constant form is really
10698 a constant and not a section offset. */
10699 if (attr_form_is_constant (attr))
10700 *offset = dwarf2_get_attr_constant_value (attr, 0);
10701 else if (attr_form_is_section_offset (attr))
10702 dwarf2_complex_location_expr_complaint ();
10703 else if (attr_form_is_block (attr))
10704 *offset = decode_locdesc (DW_BLOCK (attr), cu);
10706 dwarf2_complex_location_expr_complaint ();
10714 /* Add an aggregate field to the field list. */
10717 dwarf2_add_field (struct field_info *fip, struct die_info *die,
10718 struct dwarf2_cu *cu)
10720 struct objfile *objfile = cu->objfile;
10721 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10722 struct nextfield *new_field;
10723 struct attribute *attr;
10725 const char *fieldname = "";
10727 /* Allocate a new field list entry and link it in. */
10728 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
10729 make_cleanup (xfree, new_field);
10730 memset (new_field, 0, sizeof (struct nextfield));
10732 if (die->tag == DW_TAG_inheritance)
10734 new_field->next = fip->baseclasses;
10735 fip->baseclasses = new_field;
10739 new_field->next = fip->fields;
10740 fip->fields = new_field;
10744 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
10746 new_field->accessibility = DW_UNSND (attr);
10748 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
10749 if (new_field->accessibility != DW_ACCESS_public)
10750 fip->non_public_fields = 1;
10752 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
10754 new_field->virtuality = DW_UNSND (attr);
10756 new_field->virtuality = DW_VIRTUALITY_none;
10758 fp = &new_field->field;
10760 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
10764 /* Data member other than a C++ static data member. */
10766 /* Get type of field. */
10767 fp->type = die_type (die, cu);
10769 SET_FIELD_BITPOS (*fp, 0);
10771 /* Get bit size of field (zero if none). */
10772 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
10775 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
10779 FIELD_BITSIZE (*fp) = 0;
10782 /* Get bit offset of field. */
10783 if (handle_data_member_location (die, cu, &offset))
10784 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
10785 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
10788 if (gdbarch_bits_big_endian (gdbarch))
10790 /* For big endian bits, the DW_AT_bit_offset gives the
10791 additional bit offset from the MSB of the containing
10792 anonymous object to the MSB of the field. We don't
10793 have to do anything special since we don't need to
10794 know the size of the anonymous object. */
10795 SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr));
10799 /* For little endian bits, compute the bit offset to the
10800 MSB of the anonymous object, subtract off the number of
10801 bits from the MSB of the field to the MSB of the
10802 object, and then subtract off the number of bits of
10803 the field itself. The result is the bit offset of
10804 the LSB of the field. */
10805 int anonymous_size;
10806 int bit_offset = DW_UNSND (attr);
10808 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
10811 /* The size of the anonymous object containing
10812 the bit field is explicit, so use the
10813 indicated size (in bytes). */
10814 anonymous_size = DW_UNSND (attr);
10818 /* The size of the anonymous object containing
10819 the bit field must be inferred from the type
10820 attribute of the data member containing the
10822 anonymous_size = TYPE_LENGTH (fp->type);
10824 SET_FIELD_BITPOS (*fp,
10825 (FIELD_BITPOS (*fp)
10826 + anonymous_size * bits_per_byte
10827 - bit_offset - FIELD_BITSIZE (*fp)));
10831 /* Get name of field. */
10832 fieldname = dwarf2_name (die, cu);
10833 if (fieldname == NULL)
10836 /* The name is already allocated along with this objfile, so we don't
10837 need to duplicate it for the type. */
10838 fp->name = fieldname;
10840 /* Change accessibility for artificial fields (e.g. virtual table
10841 pointer or virtual base class pointer) to private. */
10842 if (dwarf2_attr (die, DW_AT_artificial, cu))
10844 FIELD_ARTIFICIAL (*fp) = 1;
10845 new_field->accessibility = DW_ACCESS_private;
10846 fip->non_public_fields = 1;
10849 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
10851 /* C++ static member. */
10853 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10854 is a declaration, but all versions of G++ as of this writing
10855 (so through at least 3.2.1) incorrectly generate
10856 DW_TAG_variable tags. */
10858 const char *physname;
10860 /* Get name of field. */
10861 fieldname = dwarf2_name (die, cu);
10862 if (fieldname == NULL)
10865 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10867 /* Only create a symbol if this is an external value.
10868 new_symbol checks this and puts the value in the global symbol
10869 table, which we want. If it is not external, new_symbol
10870 will try to put the value in cu->list_in_scope which is wrong. */
10871 && dwarf2_flag_true_p (die, DW_AT_external, cu))
10873 /* A static const member, not much different than an enum as far as
10874 we're concerned, except that we can support more types. */
10875 new_symbol (die, NULL, cu);
10878 /* Get physical name. */
10879 physname = dwarf2_physname (fieldname, die, cu);
10881 /* The name is already allocated along with this objfile, so we don't
10882 need to duplicate it for the type. */
10883 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
10884 FIELD_TYPE (*fp) = die_type (die, cu);
10885 FIELD_NAME (*fp) = fieldname;
10887 else if (die->tag == DW_TAG_inheritance)
10891 /* C++ base class field. */
10892 if (handle_data_member_location (die, cu, &offset))
10893 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
10894 FIELD_BITSIZE (*fp) = 0;
10895 FIELD_TYPE (*fp) = die_type (die, cu);
10896 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
10897 fip->nbaseclasses++;
10901 /* Add a typedef defined in the scope of the FIP's class. */
10904 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
10905 struct dwarf2_cu *cu)
10907 struct objfile *objfile = cu->objfile;
10908 struct typedef_field_list *new_field;
10909 struct attribute *attr;
10910 struct typedef_field *fp;
10911 char *fieldname = "";
10913 /* Allocate a new field list entry and link it in. */
10914 new_field = xzalloc (sizeof (*new_field));
10915 make_cleanup (xfree, new_field);
10917 gdb_assert (die->tag == DW_TAG_typedef);
10919 fp = &new_field->field;
10921 /* Get name of field. */
10922 fp->name = dwarf2_name (die, cu);
10923 if (fp->name == NULL)
10926 fp->type = read_type_die (die, cu);
10928 new_field->next = fip->typedef_field_list;
10929 fip->typedef_field_list = new_field;
10930 fip->typedef_field_list_count++;
10933 /* Create the vector of fields, and attach it to the type. */
10936 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
10937 struct dwarf2_cu *cu)
10939 int nfields = fip->nfields;
10941 /* Record the field count, allocate space for the array of fields,
10942 and create blank accessibility bitfields if necessary. */
10943 TYPE_NFIELDS (type) = nfields;
10944 TYPE_FIELDS (type) = (struct field *)
10945 TYPE_ALLOC (type, sizeof (struct field) * nfields);
10946 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
10948 if (fip->non_public_fields && cu->language != language_ada)
10950 ALLOCATE_CPLUS_STRUCT_TYPE (type);
10952 TYPE_FIELD_PRIVATE_BITS (type) =
10953 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
10954 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
10956 TYPE_FIELD_PROTECTED_BITS (type) =
10957 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
10958 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
10960 TYPE_FIELD_IGNORE_BITS (type) =
10961 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
10962 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
10965 /* If the type has baseclasses, allocate and clear a bit vector for
10966 TYPE_FIELD_VIRTUAL_BITS. */
10967 if (fip->nbaseclasses && cu->language != language_ada)
10969 int num_bytes = B_BYTES (fip->nbaseclasses);
10970 unsigned char *pointer;
10972 ALLOCATE_CPLUS_STRUCT_TYPE (type);
10973 pointer = TYPE_ALLOC (type, num_bytes);
10974 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
10975 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
10976 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
10979 /* Copy the saved-up fields into the field vector. Start from the head of
10980 the list, adding to the tail of the field array, so that they end up in
10981 the same order in the array in which they were added to the list. */
10982 while (nfields-- > 0)
10984 struct nextfield *fieldp;
10988 fieldp = fip->fields;
10989 fip->fields = fieldp->next;
10993 fieldp = fip->baseclasses;
10994 fip->baseclasses = fieldp->next;
10997 TYPE_FIELD (type, nfields) = fieldp->field;
10998 switch (fieldp->accessibility)
11000 case DW_ACCESS_private:
11001 if (cu->language != language_ada)
11002 SET_TYPE_FIELD_PRIVATE (type, nfields);
11005 case DW_ACCESS_protected:
11006 if (cu->language != language_ada)
11007 SET_TYPE_FIELD_PROTECTED (type, nfields);
11010 case DW_ACCESS_public:
11014 /* Unknown accessibility. Complain and treat it as public. */
11016 complaint (&symfile_complaints, _("unsupported accessibility %d"),
11017 fieldp->accessibility);
11021 if (nfields < fip->nbaseclasses)
11023 switch (fieldp->virtuality)
11025 case DW_VIRTUALITY_virtual:
11026 case DW_VIRTUALITY_pure_virtual:
11027 if (cu->language == language_ada)
11028 error (_("unexpected virtuality in component of Ada type"));
11029 SET_TYPE_FIELD_VIRTUAL (type, nfields);
11036 /* Return true if this member function is a constructor, false
11040 dwarf2_is_constructor (struct die_info *die, struct dwarf2_cu *cu)
11042 const char *fieldname;
11043 const char *typename;
11046 if (die->parent == NULL)
11049 if (die->parent->tag != DW_TAG_structure_type
11050 && die->parent->tag != DW_TAG_union_type
11051 && die->parent->tag != DW_TAG_class_type)
11054 fieldname = dwarf2_name (die, cu);
11055 typename = dwarf2_name (die->parent, cu);
11056 if (fieldname == NULL || typename == NULL)
11059 len = strlen (fieldname);
11060 return (strncmp (fieldname, typename, len) == 0
11061 && (typename[len] == '\0' || typename[len] == '<'));
11064 /* Add a member function to the proper fieldlist. */
11067 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
11068 struct type *type, struct dwarf2_cu *cu)
11070 struct objfile *objfile = cu->objfile;
11071 struct attribute *attr;
11072 struct fnfieldlist *flp;
11074 struct fn_field *fnp;
11075 const char *fieldname;
11076 struct nextfnfield *new_fnfield;
11077 struct type *this_type;
11078 enum dwarf_access_attribute accessibility;
11080 if (cu->language == language_ada)
11081 error (_("unexpected member function in Ada type"));
11083 /* Get name of member function. */
11084 fieldname = dwarf2_name (die, cu);
11085 if (fieldname == NULL)
11088 /* Look up member function name in fieldlist. */
11089 for (i = 0; i < fip->nfnfields; i++)
11091 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
11095 /* Create new list element if necessary. */
11096 if (i < fip->nfnfields)
11097 flp = &fip->fnfieldlists[i];
11100 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
11102 fip->fnfieldlists = (struct fnfieldlist *)
11103 xrealloc (fip->fnfieldlists,
11104 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
11105 * sizeof (struct fnfieldlist));
11106 if (fip->nfnfields == 0)
11107 make_cleanup (free_current_contents, &fip->fnfieldlists);
11109 flp = &fip->fnfieldlists[fip->nfnfields];
11110 flp->name = fieldname;
11113 i = fip->nfnfields++;
11116 /* Create a new member function field and chain it to the field list
11118 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
11119 make_cleanup (xfree, new_fnfield);
11120 memset (new_fnfield, 0, sizeof (struct nextfnfield));
11121 new_fnfield->next = flp->head;
11122 flp->head = new_fnfield;
11125 /* Fill in the member function field info. */
11126 fnp = &new_fnfield->fnfield;
11128 /* Delay processing of the physname until later. */
11129 if (cu->language == language_cplus || cu->language == language_java)
11131 add_to_method_list (type, i, flp->length - 1, fieldname,
11136 const char *physname = dwarf2_physname (fieldname, die, cu);
11137 fnp->physname = physname ? physname : "";
11140 fnp->type = alloc_type (objfile);
11141 this_type = read_type_die (die, cu);
11142 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
11144 int nparams = TYPE_NFIELDS (this_type);
11146 /* TYPE is the domain of this method, and THIS_TYPE is the type
11147 of the method itself (TYPE_CODE_METHOD). */
11148 smash_to_method_type (fnp->type, type,
11149 TYPE_TARGET_TYPE (this_type),
11150 TYPE_FIELDS (this_type),
11151 TYPE_NFIELDS (this_type),
11152 TYPE_VARARGS (this_type));
11154 /* Handle static member functions.
11155 Dwarf2 has no clean way to discern C++ static and non-static
11156 member functions. G++ helps GDB by marking the first
11157 parameter for non-static member functions (which is the this
11158 pointer) as artificial. We obtain this information from
11159 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
11160 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
11161 fnp->voffset = VOFFSET_STATIC;
11164 complaint (&symfile_complaints, _("member function type missing for '%s'"),
11165 dwarf2_full_name (fieldname, die, cu));
11167 /* Get fcontext from DW_AT_containing_type if present. */
11168 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
11169 fnp->fcontext = die_containing_type (die, cu);
11171 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
11172 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
11174 /* Get accessibility. */
11175 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
11177 accessibility = DW_UNSND (attr);
11179 accessibility = dwarf2_default_access_attribute (die, cu);
11180 switch (accessibility)
11182 case DW_ACCESS_private:
11183 fnp->is_private = 1;
11185 case DW_ACCESS_protected:
11186 fnp->is_protected = 1;
11190 /* Check for artificial methods. */
11191 attr = dwarf2_attr (die, DW_AT_artificial, cu);
11192 if (attr && DW_UNSND (attr) != 0)
11193 fnp->is_artificial = 1;
11195 fnp->is_constructor = dwarf2_is_constructor (die, cu);
11197 /* Get index in virtual function table if it is a virtual member
11198 function. For older versions of GCC, this is an offset in the
11199 appropriate virtual table, as specified by DW_AT_containing_type.
11200 For everyone else, it is an expression to be evaluated relative
11201 to the object address. */
11203 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
11206 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
11208 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
11210 /* Old-style GCC. */
11211 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
11213 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
11214 || (DW_BLOCK (attr)->size > 1
11215 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
11216 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
11218 struct dwarf_block blk;
11221 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
11223 blk.size = DW_BLOCK (attr)->size - offset;
11224 blk.data = DW_BLOCK (attr)->data + offset;
11225 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
11226 if ((fnp->voffset % cu->header.addr_size) != 0)
11227 dwarf2_complex_location_expr_complaint ();
11229 fnp->voffset /= cu->header.addr_size;
11233 dwarf2_complex_location_expr_complaint ();
11235 if (!fnp->fcontext)
11236 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
11238 else if (attr_form_is_section_offset (attr))
11240 dwarf2_complex_location_expr_complaint ();
11244 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
11250 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
11251 if (attr && DW_UNSND (attr))
11253 /* GCC does this, as of 2008-08-25; PR debug/37237. */
11254 complaint (&symfile_complaints,
11255 _("Member function \"%s\" (offset %d) is virtual "
11256 "but the vtable offset is not specified"),
11257 fieldname, die->offset.sect_off);
11258 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11259 TYPE_CPLUS_DYNAMIC (type) = 1;
11264 /* Create the vector of member function fields, and attach it to the type. */
11267 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
11268 struct dwarf2_cu *cu)
11270 struct fnfieldlist *flp;
11273 if (cu->language == language_ada)
11274 error (_("unexpected member functions in Ada type"));
11276 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11277 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
11278 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
11280 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
11282 struct nextfnfield *nfp = flp->head;
11283 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
11286 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
11287 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
11288 fn_flp->fn_fields = (struct fn_field *)
11289 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
11290 for (k = flp->length; (k--, nfp); nfp = nfp->next)
11291 fn_flp->fn_fields[k] = nfp->fnfield;
11294 TYPE_NFN_FIELDS (type) = fip->nfnfields;
11297 /* Returns non-zero if NAME is the name of a vtable member in CU's
11298 language, zero otherwise. */
11300 is_vtable_name (const char *name, struct dwarf2_cu *cu)
11302 static const char vptr[] = "_vptr";
11303 static const char vtable[] = "vtable";
11305 /* Look for the C++ and Java forms of the vtable. */
11306 if ((cu->language == language_java
11307 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
11308 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
11309 && is_cplus_marker (name[sizeof (vptr) - 1])))
11315 /* GCC outputs unnamed structures that are really pointers to member
11316 functions, with the ABI-specified layout. If TYPE describes
11317 such a structure, smash it into a member function type.
11319 GCC shouldn't do this; it should just output pointer to member DIEs.
11320 This is GCC PR debug/28767. */
11323 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
11325 struct type *pfn_type, *domain_type, *new_type;
11327 /* Check for a structure with no name and two children. */
11328 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
11331 /* Check for __pfn and __delta members. */
11332 if (TYPE_FIELD_NAME (type, 0) == NULL
11333 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
11334 || TYPE_FIELD_NAME (type, 1) == NULL
11335 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
11338 /* Find the type of the method. */
11339 pfn_type = TYPE_FIELD_TYPE (type, 0);
11340 if (pfn_type == NULL
11341 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
11342 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
11345 /* Look for the "this" argument. */
11346 pfn_type = TYPE_TARGET_TYPE (pfn_type);
11347 if (TYPE_NFIELDS (pfn_type) == 0
11348 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11349 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
11352 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
11353 new_type = alloc_type (objfile);
11354 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
11355 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
11356 TYPE_VARARGS (pfn_type));
11357 smash_to_methodptr_type (type, new_type);
11360 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11364 producer_is_icc (struct dwarf2_cu *cu)
11366 if (!cu->checked_producer)
11367 check_producer (cu);
11369 return cu->producer_is_icc;
11372 /* Called when we find the DIE that starts a structure or union scope
11373 (definition) to create a type for the structure or union. Fill in
11374 the type's name and general properties; the members will not be
11375 processed until process_structure_scope.
11377 NOTE: we need to call these functions regardless of whether or not the
11378 DIE has a DW_AT_name attribute, since it might be an anonymous
11379 structure or union. This gets the type entered into our set of
11380 user defined types.
11382 However, if the structure is incomplete (an opaque struct/union)
11383 then suppress creating a symbol table entry for it since gdb only
11384 wants to find the one with the complete definition. Note that if
11385 it is complete, we just call new_symbol, which does it's own
11386 checking about whether the struct/union is anonymous or not (and
11387 suppresses creating a symbol table entry itself). */
11389 static struct type *
11390 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
11392 struct objfile *objfile = cu->objfile;
11394 struct attribute *attr;
11397 /* If the definition of this type lives in .debug_types, read that type.
11398 Don't follow DW_AT_specification though, that will take us back up
11399 the chain and we want to go down. */
11400 attr = dwarf2_attr_no_follow (die, DW_AT_signature);
11403 type = get_DW_AT_signature_type (die, attr, cu);
11405 /* The type's CU may not be the same as CU.
11406 Ensure TYPE is recorded with CU in die_type_hash. */
11407 return set_die_type (die, type, cu);
11410 type = alloc_type (objfile);
11411 INIT_CPLUS_SPECIFIC (type);
11413 name = dwarf2_name (die, cu);
11416 if (cu->language == language_cplus
11417 || cu->language == language_java)
11419 const char *full_name = dwarf2_full_name (name, die, cu);
11421 /* dwarf2_full_name might have already finished building the DIE's
11422 type. If so, there is no need to continue. */
11423 if (get_die_type (die, cu) != NULL)
11424 return get_die_type (die, cu);
11426 TYPE_TAG_NAME (type) = full_name;
11427 if (die->tag == DW_TAG_structure_type
11428 || die->tag == DW_TAG_class_type)
11429 TYPE_NAME (type) = TYPE_TAG_NAME (type);
11433 /* The name is already allocated along with this objfile, so
11434 we don't need to duplicate it for the type. */
11435 TYPE_TAG_NAME (type) = name;
11436 if (die->tag == DW_TAG_class_type)
11437 TYPE_NAME (type) = TYPE_TAG_NAME (type);
11441 if (die->tag == DW_TAG_structure_type)
11443 TYPE_CODE (type) = TYPE_CODE_STRUCT;
11445 else if (die->tag == DW_TAG_union_type)
11447 TYPE_CODE (type) = TYPE_CODE_UNION;
11451 TYPE_CODE (type) = TYPE_CODE_CLASS;
11454 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
11455 TYPE_DECLARED_CLASS (type) = 1;
11457 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11460 TYPE_LENGTH (type) = DW_UNSND (attr);
11464 TYPE_LENGTH (type) = 0;
11467 if (producer_is_icc (cu))
11469 /* ICC does not output the required DW_AT_declaration
11470 on incomplete types, but gives them a size of zero. */
11473 TYPE_STUB_SUPPORTED (type) = 1;
11475 if (die_is_declaration (die, cu))
11476 TYPE_STUB (type) = 1;
11477 else if (attr == NULL && die->child == NULL
11478 && producer_is_realview (cu->producer))
11479 /* RealView does not output the required DW_AT_declaration
11480 on incomplete types. */
11481 TYPE_STUB (type) = 1;
11483 /* We need to add the type field to the die immediately so we don't
11484 infinitely recurse when dealing with pointers to the structure
11485 type within the structure itself. */
11486 set_die_type (die, type, cu);
11488 /* set_die_type should be already done. */
11489 set_descriptive_type (type, die, cu);
11494 /* Finish creating a structure or union type, including filling in
11495 its members and creating a symbol for it. */
11498 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
11500 struct objfile *objfile = cu->objfile;
11501 struct die_info *child_die = die->child;
11504 type = get_die_type (die, cu);
11506 type = read_structure_type (die, cu);
11508 if (die->child != NULL && ! die_is_declaration (die, cu))
11510 struct field_info fi;
11511 struct die_info *child_die;
11512 VEC (symbolp) *template_args = NULL;
11513 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
11515 memset (&fi, 0, sizeof (struct field_info));
11517 child_die = die->child;
11519 while (child_die && child_die->tag)
11521 if (child_die->tag == DW_TAG_member
11522 || child_die->tag == DW_TAG_variable)
11524 /* NOTE: carlton/2002-11-05: A C++ static data member
11525 should be a DW_TAG_member that is a declaration, but
11526 all versions of G++ as of this writing (so through at
11527 least 3.2.1) incorrectly generate DW_TAG_variable
11528 tags for them instead. */
11529 dwarf2_add_field (&fi, child_die, cu);
11531 else if (child_die->tag == DW_TAG_subprogram)
11533 /* C++ member function. */
11534 dwarf2_add_member_fn (&fi, child_die, type, cu);
11536 else if (child_die->tag == DW_TAG_inheritance)
11538 /* C++ base class field. */
11539 dwarf2_add_field (&fi, child_die, cu);
11541 else if (child_die->tag == DW_TAG_typedef)
11542 dwarf2_add_typedef (&fi, child_die, cu);
11543 else if (child_die->tag == DW_TAG_template_type_param
11544 || child_die->tag == DW_TAG_template_value_param)
11546 struct symbol *arg = new_symbol (child_die, NULL, cu);
11549 VEC_safe_push (symbolp, template_args, arg);
11552 child_die = sibling_die (child_die);
11555 /* Attach template arguments to type. */
11556 if (! VEC_empty (symbolp, template_args))
11558 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11559 TYPE_N_TEMPLATE_ARGUMENTS (type)
11560 = VEC_length (symbolp, template_args);
11561 TYPE_TEMPLATE_ARGUMENTS (type)
11562 = obstack_alloc (&objfile->objfile_obstack,
11563 (TYPE_N_TEMPLATE_ARGUMENTS (type)
11564 * sizeof (struct symbol *)));
11565 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
11566 VEC_address (symbolp, template_args),
11567 (TYPE_N_TEMPLATE_ARGUMENTS (type)
11568 * sizeof (struct symbol *)));
11569 VEC_free (symbolp, template_args);
11572 /* Attach fields and member functions to the type. */
11574 dwarf2_attach_fields_to_type (&fi, type, cu);
11577 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
11579 /* Get the type which refers to the base class (possibly this
11580 class itself) which contains the vtable pointer for the current
11581 class from the DW_AT_containing_type attribute. This use of
11582 DW_AT_containing_type is a GNU extension. */
11584 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
11586 struct type *t = die_containing_type (die, cu);
11588 TYPE_VPTR_BASETYPE (type) = t;
11593 /* Our own class provides vtbl ptr. */
11594 for (i = TYPE_NFIELDS (t) - 1;
11595 i >= TYPE_N_BASECLASSES (t);
11598 const char *fieldname = TYPE_FIELD_NAME (t, i);
11600 if (is_vtable_name (fieldname, cu))
11602 TYPE_VPTR_FIELDNO (type) = i;
11607 /* Complain if virtual function table field not found. */
11608 if (i < TYPE_N_BASECLASSES (t))
11609 complaint (&symfile_complaints,
11610 _("virtual function table pointer "
11611 "not found when defining class '%s'"),
11612 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
11617 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
11620 else if (cu->producer
11621 && strncmp (cu->producer,
11622 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11624 /* The IBM XLC compiler does not provide direct indication
11625 of the containing type, but the vtable pointer is
11626 always named __vfp. */
11630 for (i = TYPE_NFIELDS (type) - 1;
11631 i >= TYPE_N_BASECLASSES (type);
11634 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
11636 TYPE_VPTR_FIELDNO (type) = i;
11637 TYPE_VPTR_BASETYPE (type) = type;
11644 /* Copy fi.typedef_field_list linked list elements content into the
11645 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11646 if (fi.typedef_field_list)
11648 int i = fi.typedef_field_list_count;
11650 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11651 TYPE_TYPEDEF_FIELD_ARRAY (type)
11652 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
11653 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
11655 /* Reverse the list order to keep the debug info elements order. */
11658 struct typedef_field *dest, *src;
11660 dest = &TYPE_TYPEDEF_FIELD (type, i);
11661 src = &fi.typedef_field_list->field;
11662 fi.typedef_field_list = fi.typedef_field_list->next;
11667 do_cleanups (back_to);
11669 if (HAVE_CPLUS_STRUCT (type))
11670 TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
11673 quirk_gcc_member_function_pointer (type, objfile);
11675 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11676 snapshots) has been known to create a die giving a declaration
11677 for a class that has, as a child, a die giving a definition for a
11678 nested class. So we have to process our children even if the
11679 current die is a declaration. Normally, of course, a declaration
11680 won't have any children at all. */
11682 while (child_die != NULL && child_die->tag)
11684 if (child_die->tag == DW_TAG_member
11685 || child_die->tag == DW_TAG_variable
11686 || child_die->tag == DW_TAG_inheritance
11687 || child_die->tag == DW_TAG_template_value_param
11688 || child_die->tag == DW_TAG_template_type_param)
11693 process_die (child_die, cu);
11695 child_die = sibling_die (child_die);
11698 /* Do not consider external references. According to the DWARF standard,
11699 these DIEs are identified by the fact that they have no byte_size
11700 attribute, and a declaration attribute. */
11701 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
11702 || !die_is_declaration (die, cu))
11703 new_symbol (die, type, cu);
11706 /* Given a DW_AT_enumeration_type die, set its type. We do not
11707 complete the type's fields yet, or create any symbols. */
11709 static struct type *
11710 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
11712 struct objfile *objfile = cu->objfile;
11714 struct attribute *attr;
11717 /* If the definition of this type lives in .debug_types, read that type.
11718 Don't follow DW_AT_specification though, that will take us back up
11719 the chain and we want to go down. */
11720 attr = dwarf2_attr_no_follow (die, DW_AT_signature);
11723 type = get_DW_AT_signature_type (die, attr, cu);
11725 /* The type's CU may not be the same as CU.
11726 Ensure TYPE is recorded with CU in die_type_hash. */
11727 return set_die_type (die, type, cu);
11730 type = alloc_type (objfile);
11732 TYPE_CODE (type) = TYPE_CODE_ENUM;
11733 name = dwarf2_full_name (NULL, die, cu);
11735 TYPE_TAG_NAME (type) = name;
11737 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11740 TYPE_LENGTH (type) = DW_UNSND (attr);
11744 TYPE_LENGTH (type) = 0;
11747 /* The enumeration DIE can be incomplete. In Ada, any type can be
11748 declared as private in the package spec, and then defined only
11749 inside the package body. Such types are known as Taft Amendment
11750 Types. When another package uses such a type, an incomplete DIE
11751 may be generated by the compiler. */
11752 if (die_is_declaration (die, cu))
11753 TYPE_STUB (type) = 1;
11755 return set_die_type (die, type, cu);
11758 /* Given a pointer to a die which begins an enumeration, process all
11759 the dies that define the members of the enumeration, and create the
11760 symbol for the enumeration type.
11762 NOTE: We reverse the order of the element list. */
11765 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
11767 struct type *this_type;
11769 this_type = get_die_type (die, cu);
11770 if (this_type == NULL)
11771 this_type = read_enumeration_type (die, cu);
11773 if (die->child != NULL)
11775 struct die_info *child_die;
11776 struct symbol *sym;
11777 struct field *fields = NULL;
11778 int num_fields = 0;
11779 int unsigned_enum = 1;
11784 child_die = die->child;
11785 while (child_die && child_die->tag)
11787 if (child_die->tag != DW_TAG_enumerator)
11789 process_die (child_die, cu);
11793 name = dwarf2_name (child_die, cu);
11796 sym = new_symbol (child_die, this_type, cu);
11797 if (SYMBOL_VALUE (sym) < 0)
11802 else if ((mask & SYMBOL_VALUE (sym)) != 0)
11805 mask |= SYMBOL_VALUE (sym);
11807 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
11809 fields = (struct field *)
11811 (num_fields + DW_FIELD_ALLOC_CHUNK)
11812 * sizeof (struct field));
11815 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
11816 FIELD_TYPE (fields[num_fields]) = NULL;
11817 SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym));
11818 FIELD_BITSIZE (fields[num_fields]) = 0;
11824 child_die = sibling_die (child_die);
11829 TYPE_NFIELDS (this_type) = num_fields;
11830 TYPE_FIELDS (this_type) = (struct field *)
11831 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
11832 memcpy (TYPE_FIELDS (this_type), fields,
11833 sizeof (struct field) * num_fields);
11837 TYPE_UNSIGNED (this_type) = 1;
11839 TYPE_FLAG_ENUM (this_type) = 1;
11842 /* If we are reading an enum from a .debug_types unit, and the enum
11843 is a declaration, and the enum is not the signatured type in the
11844 unit, then we do not want to add a symbol for it. Adding a
11845 symbol would in some cases obscure the true definition of the
11846 enum, giving users an incomplete type when the definition is
11847 actually available. Note that we do not want to do this for all
11848 enums which are just declarations, because C++0x allows forward
11849 enum declarations. */
11850 if (cu->per_cu->is_debug_types
11851 && die_is_declaration (die, cu))
11853 struct signatured_type *sig_type;
11855 sig_type = (struct signatured_type *) cu->per_cu;
11856 gdb_assert (sig_type->type_offset_in_section.sect_off != 0);
11857 if (sig_type->type_offset_in_section.sect_off != die->offset.sect_off)
11861 new_symbol (die, this_type, cu);
11864 /* Extract all information from a DW_TAG_array_type DIE and put it in
11865 the DIE's type field. For now, this only handles one dimensional
11868 static struct type *
11869 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
11871 struct objfile *objfile = cu->objfile;
11872 struct die_info *child_die;
11874 struct type *element_type, *range_type, *index_type;
11875 struct type **range_types = NULL;
11876 struct attribute *attr;
11878 struct cleanup *back_to;
11881 element_type = die_type (die, cu);
11883 /* The die_type call above may have already set the type for this DIE. */
11884 type = get_die_type (die, cu);
11888 /* Irix 6.2 native cc creates array types without children for
11889 arrays with unspecified length. */
11890 if (die->child == NULL)
11892 index_type = objfile_type (objfile)->builtin_int;
11893 range_type = create_range_type (NULL, index_type, 0, -1);
11894 type = create_array_type (NULL, element_type, range_type);
11895 return set_die_type (die, type, cu);
11898 back_to = make_cleanup (null_cleanup, NULL);
11899 child_die = die->child;
11900 while (child_die && child_die->tag)
11902 if (child_die->tag == DW_TAG_subrange_type)
11904 struct type *child_type = read_type_die (child_die, cu);
11906 if (child_type != NULL)
11908 /* The range type was succesfully read. Save it for the
11909 array type creation. */
11910 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
11912 range_types = (struct type **)
11913 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
11914 * sizeof (struct type *));
11916 make_cleanup (free_current_contents, &range_types);
11918 range_types[ndim++] = child_type;
11921 child_die = sibling_die (child_die);
11924 /* Dwarf2 dimensions are output from left to right, create the
11925 necessary array types in backwards order. */
11927 type = element_type;
11929 if (read_array_order (die, cu) == DW_ORD_col_major)
11934 type = create_array_type (NULL, type, range_types[i++]);
11939 type = create_array_type (NULL, type, range_types[ndim]);
11942 /* Understand Dwarf2 support for vector types (like they occur on
11943 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11944 array type. This is not part of the Dwarf2/3 standard yet, but a
11945 custom vendor extension. The main difference between a regular
11946 array and the vector variant is that vectors are passed by value
11948 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
11950 make_vector_type (type);
11952 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11953 implementation may choose to implement triple vectors using this
11955 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11958 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
11959 TYPE_LENGTH (type) = DW_UNSND (attr);
11961 complaint (&symfile_complaints,
11962 _("DW_AT_byte_size for array type smaller "
11963 "than the total size of elements"));
11966 name = dwarf2_name (die, cu);
11968 TYPE_NAME (type) = name;
11970 /* Install the type in the die. */
11971 set_die_type (die, type, cu);
11973 /* set_die_type should be already done. */
11974 set_descriptive_type (type, die, cu);
11976 do_cleanups (back_to);
11981 static enum dwarf_array_dim_ordering
11982 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
11984 struct attribute *attr;
11986 attr = dwarf2_attr (die, DW_AT_ordering, cu);
11988 if (attr) return DW_SND (attr);
11990 /* GNU F77 is a special case, as at 08/2004 array type info is the
11991 opposite order to the dwarf2 specification, but data is still
11992 laid out as per normal fortran.
11994 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11995 version checking. */
11997 if (cu->language == language_fortran
11998 && cu->producer && strstr (cu->producer, "GNU F77"))
12000 return DW_ORD_row_major;
12003 switch (cu->language_defn->la_array_ordering)
12005 case array_column_major:
12006 return DW_ORD_col_major;
12007 case array_row_major:
12009 return DW_ORD_row_major;
12013 /* Extract all information from a DW_TAG_set_type DIE and put it in
12014 the DIE's type field. */
12016 static struct type *
12017 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
12019 struct type *domain_type, *set_type;
12020 struct attribute *attr;
12022 domain_type = die_type (die, cu);
12024 /* The die_type call above may have already set the type for this DIE. */
12025 set_type = get_die_type (die, cu);
12029 set_type = create_set_type (NULL, domain_type);
12031 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12033 TYPE_LENGTH (set_type) = DW_UNSND (attr);
12035 return set_die_type (die, set_type, cu);
12038 /* A helper for read_common_block that creates a locexpr baton.
12039 SYM is the symbol which we are marking as computed.
12040 COMMON_DIE is the DIE for the common block.
12041 COMMON_LOC is the location expression attribute for the common
12043 MEMBER_LOC is the location expression attribute for the particular
12044 member of the common block that we are processing.
12045 CU is the CU from which the above come. */
12048 mark_common_block_symbol_computed (struct symbol *sym,
12049 struct die_info *common_die,
12050 struct attribute *common_loc,
12051 struct attribute *member_loc,
12052 struct dwarf2_cu *cu)
12054 struct objfile *objfile = dwarf2_per_objfile->objfile;
12055 struct dwarf2_locexpr_baton *baton;
12057 unsigned int cu_off;
12058 enum bfd_endian byte_order = gdbarch_byte_order (get_objfile_arch (objfile));
12059 LONGEST offset = 0;
12061 gdb_assert (common_loc && member_loc);
12062 gdb_assert (attr_form_is_block (common_loc));
12063 gdb_assert (attr_form_is_block (member_loc)
12064 || attr_form_is_constant (member_loc));
12066 baton = obstack_alloc (&objfile->objfile_obstack,
12067 sizeof (struct dwarf2_locexpr_baton));
12068 baton->per_cu = cu->per_cu;
12069 gdb_assert (baton->per_cu);
12071 baton->size = 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
12073 if (attr_form_is_constant (member_loc))
12075 offset = dwarf2_get_attr_constant_value (member_loc, 0);
12076 baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
12079 baton->size += DW_BLOCK (member_loc)->size;
12081 ptr = obstack_alloc (&objfile->objfile_obstack, baton->size);
12084 *ptr++ = DW_OP_call4;
12085 cu_off = common_die->offset.sect_off - cu->per_cu->offset.sect_off;
12086 store_unsigned_integer (ptr, 4, byte_order, cu_off);
12089 if (attr_form_is_constant (member_loc))
12091 *ptr++ = DW_OP_addr;
12092 store_unsigned_integer (ptr, cu->header.addr_size, byte_order, offset);
12093 ptr += cu->header.addr_size;
12097 /* We have to copy the data here, because DW_OP_call4 will only
12098 use a DW_AT_location attribute. */
12099 memcpy (ptr, DW_BLOCK (member_loc)->data, DW_BLOCK (member_loc)->size);
12100 ptr += DW_BLOCK (member_loc)->size;
12103 *ptr++ = DW_OP_plus;
12104 gdb_assert (ptr - baton->data == baton->size);
12106 SYMBOL_LOCATION_BATON (sym) = baton;
12107 SYMBOL_ACLASS_INDEX (sym) = dwarf2_locexpr_index;
12110 /* Create appropriate locally-scoped variables for all the
12111 DW_TAG_common_block entries. Also create a struct common_block
12112 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
12113 is used to sepate the common blocks name namespace from regular
12117 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
12119 struct attribute *attr;
12121 attr = dwarf2_attr (die, DW_AT_location, cu);
12124 /* Support the .debug_loc offsets. */
12125 if (attr_form_is_block (attr))
12129 else if (attr_form_is_section_offset (attr))
12131 dwarf2_complex_location_expr_complaint ();
12136 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
12137 "common block member");
12142 if (die->child != NULL)
12144 struct objfile *objfile = cu->objfile;
12145 struct die_info *child_die;
12146 size_t n_entries = 0, size;
12147 struct common_block *common_block;
12148 struct symbol *sym;
12150 for (child_die = die->child;
12151 child_die && child_die->tag;
12152 child_die = sibling_die (child_die))
12155 size = (sizeof (struct common_block)
12156 + (n_entries - 1) * sizeof (struct symbol *));
12157 common_block = obstack_alloc (&objfile->objfile_obstack, size);
12158 memset (common_block->contents, 0, n_entries * sizeof (struct symbol *));
12159 common_block->n_entries = 0;
12161 for (child_die = die->child;
12162 child_die && child_die->tag;
12163 child_die = sibling_die (child_die))
12165 /* Create the symbol in the DW_TAG_common_block block in the current
12167 sym = new_symbol (child_die, NULL, cu);
12170 struct attribute *member_loc;
12172 common_block->contents[common_block->n_entries++] = sym;
12174 member_loc = dwarf2_attr (child_die, DW_AT_data_member_location,
12178 /* GDB has handled this for a long time, but it is
12179 not specified by DWARF. It seems to have been
12180 emitted by gfortran at least as recently as:
12181 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
12182 complaint (&symfile_complaints,
12183 _("Variable in common block has "
12184 "DW_AT_data_member_location "
12185 "- DIE at 0x%x [in module %s]"),
12186 child_die->offset.sect_off, cu->objfile->name);
12188 if (attr_form_is_section_offset (member_loc))
12189 dwarf2_complex_location_expr_complaint ();
12190 else if (attr_form_is_constant (member_loc)
12191 || attr_form_is_block (member_loc))
12194 mark_common_block_symbol_computed (sym, die, attr,
12198 dwarf2_complex_location_expr_complaint ();
12203 sym = new_symbol (die, objfile_type (objfile)->builtin_void, cu);
12204 SYMBOL_VALUE_COMMON_BLOCK (sym) = common_block;
12208 /* Create a type for a C++ namespace. */
12210 static struct type *
12211 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
12213 struct objfile *objfile = cu->objfile;
12214 const char *previous_prefix, *name;
12218 /* For extensions, reuse the type of the original namespace. */
12219 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
12221 struct die_info *ext_die;
12222 struct dwarf2_cu *ext_cu = cu;
12224 ext_die = dwarf2_extension (die, &ext_cu);
12225 type = read_type_die (ext_die, ext_cu);
12227 /* EXT_CU may not be the same as CU.
12228 Ensure TYPE is recorded with CU in die_type_hash. */
12229 return set_die_type (die, type, cu);
12232 name = namespace_name (die, &is_anonymous, cu);
12234 /* Now build the name of the current namespace. */
12236 previous_prefix = determine_prefix (die, cu);
12237 if (previous_prefix[0] != '\0')
12238 name = typename_concat (&objfile->objfile_obstack,
12239 previous_prefix, name, 0, cu);
12241 /* Create the type. */
12242 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
12244 TYPE_NAME (type) = name;
12245 TYPE_TAG_NAME (type) = TYPE_NAME (type);
12247 return set_die_type (die, type, cu);
12250 /* Read a C++ namespace. */
12253 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
12255 struct objfile *objfile = cu->objfile;
12258 /* Add a symbol associated to this if we haven't seen the namespace
12259 before. Also, add a using directive if it's an anonymous
12262 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
12266 type = read_type_die (die, cu);
12267 new_symbol (die, type, cu);
12269 namespace_name (die, &is_anonymous, cu);
12272 const char *previous_prefix = determine_prefix (die, cu);
12274 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
12275 NULL, NULL, 0, &objfile->objfile_obstack);
12279 if (die->child != NULL)
12281 struct die_info *child_die = die->child;
12283 while (child_die && child_die->tag)
12285 process_die (child_die, cu);
12286 child_die = sibling_die (child_die);
12291 /* Read a Fortran module as type. This DIE can be only a declaration used for
12292 imported module. Still we need that type as local Fortran "use ... only"
12293 declaration imports depend on the created type in determine_prefix. */
12295 static struct type *
12296 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
12298 struct objfile *objfile = cu->objfile;
12299 const char *module_name;
12302 module_name = dwarf2_name (die, cu);
12304 complaint (&symfile_complaints,
12305 _("DW_TAG_module has no name, offset 0x%x"),
12306 die->offset.sect_off);
12307 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
12309 /* determine_prefix uses TYPE_TAG_NAME. */
12310 TYPE_TAG_NAME (type) = TYPE_NAME (type);
12312 return set_die_type (die, type, cu);
12315 /* Read a Fortran module. */
12318 read_module (struct die_info *die, struct dwarf2_cu *cu)
12320 struct die_info *child_die = die->child;
12322 while (child_die && child_die->tag)
12324 process_die (child_die, cu);
12325 child_die = sibling_die (child_die);
12329 /* Return the name of the namespace represented by DIE. Set
12330 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12333 static const char *
12334 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
12336 struct die_info *current_die;
12337 const char *name = NULL;
12339 /* Loop through the extensions until we find a name. */
12341 for (current_die = die;
12342 current_die != NULL;
12343 current_die = dwarf2_extension (die, &cu))
12345 name = dwarf2_name (current_die, cu);
12350 /* Is it an anonymous namespace? */
12352 *is_anonymous = (name == NULL);
12354 name = CP_ANONYMOUS_NAMESPACE_STR;
12359 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12360 the user defined type vector. */
12362 static struct type *
12363 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
12365 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
12366 struct comp_unit_head *cu_header = &cu->header;
12368 struct attribute *attr_byte_size;
12369 struct attribute *attr_address_class;
12370 int byte_size, addr_class;
12371 struct type *target_type;
12373 target_type = die_type (die, cu);
12375 /* The die_type call above may have already set the type for this DIE. */
12376 type = get_die_type (die, cu);
12380 type = lookup_pointer_type (target_type);
12382 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
12383 if (attr_byte_size)
12384 byte_size = DW_UNSND (attr_byte_size);
12386 byte_size = cu_header->addr_size;
12388 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
12389 if (attr_address_class)
12390 addr_class = DW_UNSND (attr_address_class);
12392 addr_class = DW_ADDR_none;
12394 /* If the pointer size or address class is different than the
12395 default, create a type variant marked as such and set the
12396 length accordingly. */
12397 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
12399 if (gdbarch_address_class_type_flags_p (gdbarch))
12403 type_flags = gdbarch_address_class_type_flags
12404 (gdbarch, byte_size, addr_class);
12405 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
12407 type = make_type_with_address_space (type, type_flags);
12409 else if (TYPE_LENGTH (type) != byte_size)
12411 complaint (&symfile_complaints,
12412 _("invalid pointer size %d"), byte_size);
12416 /* Should we also complain about unhandled address classes? */
12420 TYPE_LENGTH (type) = byte_size;
12421 return set_die_type (die, type, cu);
12424 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12425 the user defined type vector. */
12427 static struct type *
12428 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
12431 struct type *to_type;
12432 struct type *domain;
12434 to_type = die_type (die, cu);
12435 domain = die_containing_type (die, cu);
12437 /* The calls above may have already set the type for this DIE. */
12438 type = get_die_type (die, cu);
12442 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
12443 type = lookup_methodptr_type (to_type);
12444 else if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_FUNC)
12446 struct type *new_type = alloc_type (cu->objfile);
12448 smash_to_method_type (new_type, domain, TYPE_TARGET_TYPE (to_type),
12449 TYPE_FIELDS (to_type), TYPE_NFIELDS (to_type),
12450 TYPE_VARARGS (to_type));
12451 type = lookup_methodptr_type (new_type);
12454 type = lookup_memberptr_type (to_type, domain);
12456 return set_die_type (die, type, cu);
12459 /* Extract all information from a DW_TAG_reference_type DIE and add to
12460 the user defined type vector. */
12462 static struct type *
12463 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
12465 struct comp_unit_head *cu_header = &cu->header;
12466 struct type *type, *target_type;
12467 struct attribute *attr;
12469 target_type = die_type (die, cu);
12471 /* The die_type call above may have already set the type for this DIE. */
12472 type = get_die_type (die, cu);
12476 type = lookup_reference_type (target_type);
12477 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12480 TYPE_LENGTH (type) = DW_UNSND (attr);
12484 TYPE_LENGTH (type) = cu_header->addr_size;
12486 return set_die_type (die, type, cu);
12489 static struct type *
12490 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
12492 struct type *base_type, *cv_type;
12494 base_type = die_type (die, cu);
12496 /* The die_type call above may have already set the type for this DIE. */
12497 cv_type = get_die_type (die, cu);
12501 /* In case the const qualifier is applied to an array type, the element type
12502 is so qualified, not the array type (section 6.7.3 of C99). */
12503 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
12505 struct type *el_type, *inner_array;
12507 base_type = copy_type (base_type);
12508 inner_array = base_type;
12510 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
12512 TYPE_TARGET_TYPE (inner_array) =
12513 copy_type (TYPE_TARGET_TYPE (inner_array));
12514 inner_array = TYPE_TARGET_TYPE (inner_array);
12517 el_type = TYPE_TARGET_TYPE (inner_array);
12518 TYPE_TARGET_TYPE (inner_array) =
12519 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
12521 return set_die_type (die, base_type, cu);
12524 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
12525 return set_die_type (die, cv_type, cu);
12528 static struct type *
12529 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
12531 struct type *base_type, *cv_type;
12533 base_type = die_type (die, cu);
12535 /* The die_type call above may have already set the type for this DIE. */
12536 cv_type = get_die_type (die, cu);
12540 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
12541 return set_die_type (die, cv_type, cu);
12544 /* Handle DW_TAG_restrict_type. */
12546 static struct type *
12547 read_tag_restrict_type (struct die_info *die, struct dwarf2_cu *cu)
12549 struct type *base_type, *cv_type;
12551 base_type = die_type (die, cu);
12553 /* The die_type call above may have already set the type for this DIE. */
12554 cv_type = get_die_type (die, cu);
12558 cv_type = make_restrict_type (base_type);
12559 return set_die_type (die, cv_type, cu);
12562 /* Extract all information from a DW_TAG_string_type DIE and add to
12563 the user defined type vector. It isn't really a user defined type,
12564 but it behaves like one, with other DIE's using an AT_user_def_type
12565 attribute to reference it. */
12567 static struct type *
12568 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
12570 struct objfile *objfile = cu->objfile;
12571 struct gdbarch *gdbarch = get_objfile_arch (objfile);
12572 struct type *type, *range_type, *index_type, *char_type;
12573 struct attribute *attr;
12574 unsigned int length;
12576 attr = dwarf2_attr (die, DW_AT_string_length, cu);
12579 length = DW_UNSND (attr);
12583 /* Check for the DW_AT_byte_size attribute. */
12584 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12587 length = DW_UNSND (attr);
12595 index_type = objfile_type (objfile)->builtin_int;
12596 range_type = create_range_type (NULL, index_type, 1, length);
12597 char_type = language_string_char_type (cu->language_defn, gdbarch);
12598 type = create_string_type (NULL, char_type, range_type);
12600 return set_die_type (die, type, cu);
12603 /* Assuming that DIE corresponds to a function, returns nonzero
12604 if the function is prototyped. */
12607 prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu)
12609 struct attribute *attr;
12611 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
12612 if (attr && (DW_UNSND (attr) != 0))
12615 /* The DWARF standard implies that the DW_AT_prototyped attribute
12616 is only meaninful for C, but the concept also extends to other
12617 languages that allow unprototyped functions (Eg: Objective C).
12618 For all other languages, assume that functions are always
12620 if (cu->language != language_c
12621 && cu->language != language_objc
12622 && cu->language != language_opencl)
12625 /* RealView does not emit DW_AT_prototyped. We can not distinguish
12626 prototyped and unprototyped functions; default to prototyped,
12627 since that is more common in modern code (and RealView warns
12628 about unprototyped functions). */
12629 if (producer_is_realview (cu->producer))
12635 /* Handle DIES due to C code like:
12639 int (*funcp)(int a, long l);
12643 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12645 static struct type *
12646 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
12648 struct objfile *objfile = cu->objfile;
12649 struct type *type; /* Type that this function returns. */
12650 struct type *ftype; /* Function that returns above type. */
12651 struct attribute *attr;
12653 type = die_type (die, cu);
12655 /* The die_type call above may have already set the type for this DIE. */
12656 ftype = get_die_type (die, cu);
12660 ftype = lookup_function_type (type);
12662 if (prototyped_function_p (die, cu))
12663 TYPE_PROTOTYPED (ftype) = 1;
12665 /* Store the calling convention in the type if it's available in
12666 the subroutine die. Otherwise set the calling convention to
12667 the default value DW_CC_normal. */
12668 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
12670 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
12671 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
12672 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
12674 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
12676 /* We need to add the subroutine type to the die immediately so
12677 we don't infinitely recurse when dealing with parameters
12678 declared as the same subroutine type. */
12679 set_die_type (die, ftype, cu);
12681 if (die->child != NULL)
12683 struct type *void_type = objfile_type (objfile)->builtin_void;
12684 struct die_info *child_die;
12685 int nparams, iparams;
12687 /* Count the number of parameters.
12688 FIXME: GDB currently ignores vararg functions, but knows about
12689 vararg member functions. */
12691 child_die = die->child;
12692 while (child_die && child_die->tag)
12694 if (child_die->tag == DW_TAG_formal_parameter)
12696 else if (child_die->tag == DW_TAG_unspecified_parameters)
12697 TYPE_VARARGS (ftype) = 1;
12698 child_die = sibling_die (child_die);
12701 /* Allocate storage for parameters and fill them in. */
12702 TYPE_NFIELDS (ftype) = nparams;
12703 TYPE_FIELDS (ftype) = (struct field *)
12704 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
12706 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12707 even if we error out during the parameters reading below. */
12708 for (iparams = 0; iparams < nparams; iparams++)
12709 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
12712 child_die = die->child;
12713 while (child_die && child_die->tag)
12715 if (child_die->tag == DW_TAG_formal_parameter)
12717 struct type *arg_type;
12719 /* DWARF version 2 has no clean way to discern C++
12720 static and non-static member functions. G++ helps
12721 GDB by marking the first parameter for non-static
12722 member functions (which is the this pointer) as
12723 artificial. We pass this information to
12724 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12726 DWARF version 3 added DW_AT_object_pointer, which GCC
12727 4.5 does not yet generate. */
12728 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
12730 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
12733 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
12735 /* GCC/43521: In java, the formal parameter
12736 "this" is sometimes not marked with DW_AT_artificial. */
12737 if (cu->language == language_java)
12739 const char *name = dwarf2_name (child_die, cu);
12741 if (name && !strcmp (name, "this"))
12742 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
12745 arg_type = die_type (child_die, cu);
12747 /* RealView does not mark THIS as const, which the testsuite
12748 expects. GCC marks THIS as const in method definitions,
12749 but not in the class specifications (GCC PR 43053). */
12750 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
12751 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
12754 struct dwarf2_cu *arg_cu = cu;
12755 const char *name = dwarf2_name (child_die, cu);
12757 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
12760 /* If the compiler emits this, use it. */
12761 if (follow_die_ref (die, attr, &arg_cu) == child_die)
12764 else if (name && strcmp (name, "this") == 0)
12765 /* Function definitions will have the argument names. */
12767 else if (name == NULL && iparams == 0)
12768 /* Declarations may not have the names, so like
12769 elsewhere in GDB, assume an artificial first
12770 argument is "this". */
12774 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
12778 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
12781 child_die = sibling_die (child_die);
12788 static struct type *
12789 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
12791 struct objfile *objfile = cu->objfile;
12792 const char *name = NULL;
12793 struct type *this_type, *target_type;
12795 name = dwarf2_full_name (NULL, die, cu);
12796 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
12797 TYPE_FLAG_TARGET_STUB, NULL, objfile);
12798 TYPE_NAME (this_type) = name;
12799 set_die_type (die, this_type, cu);
12800 target_type = die_type (die, cu);
12801 if (target_type != this_type)
12802 TYPE_TARGET_TYPE (this_type) = target_type;
12805 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12806 spec and cause infinite loops in GDB. */
12807 complaint (&symfile_complaints,
12808 _("Self-referential DW_TAG_typedef "
12809 "- DIE at 0x%x [in module %s]"),
12810 die->offset.sect_off, objfile->name);
12811 TYPE_TARGET_TYPE (this_type) = NULL;
12816 /* Find a representation of a given base type and install
12817 it in the TYPE field of the die. */
12819 static struct type *
12820 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
12822 struct objfile *objfile = cu->objfile;
12824 struct attribute *attr;
12825 int encoding = 0, size = 0;
12827 enum type_code code = TYPE_CODE_INT;
12828 int type_flags = 0;
12829 struct type *target_type = NULL;
12831 attr = dwarf2_attr (die, DW_AT_encoding, cu);
12834 encoding = DW_UNSND (attr);
12836 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12839 size = DW_UNSND (attr);
12841 name = dwarf2_name (die, cu);
12844 complaint (&symfile_complaints,
12845 _("DW_AT_name missing from DW_TAG_base_type"));
12850 case DW_ATE_address:
12851 /* Turn DW_ATE_address into a void * pointer. */
12852 code = TYPE_CODE_PTR;
12853 type_flags |= TYPE_FLAG_UNSIGNED;
12854 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
12856 case DW_ATE_boolean:
12857 code = TYPE_CODE_BOOL;
12858 type_flags |= TYPE_FLAG_UNSIGNED;
12860 case DW_ATE_complex_float:
12861 code = TYPE_CODE_COMPLEX;
12862 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
12864 case DW_ATE_decimal_float:
12865 code = TYPE_CODE_DECFLOAT;
12868 code = TYPE_CODE_FLT;
12870 case DW_ATE_signed:
12872 case DW_ATE_unsigned:
12873 type_flags |= TYPE_FLAG_UNSIGNED;
12874 if (cu->language == language_fortran
12876 && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
12877 code = TYPE_CODE_CHAR;
12879 case DW_ATE_signed_char:
12880 if (cu->language == language_ada || cu->language == language_m2
12881 || cu->language == language_pascal
12882 || cu->language == language_fortran)
12883 code = TYPE_CODE_CHAR;
12885 case DW_ATE_unsigned_char:
12886 if (cu->language == language_ada || cu->language == language_m2
12887 || cu->language == language_pascal
12888 || cu->language == language_fortran)
12889 code = TYPE_CODE_CHAR;
12890 type_flags |= TYPE_FLAG_UNSIGNED;
12893 /* We just treat this as an integer and then recognize the
12894 type by name elsewhere. */
12898 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
12899 dwarf_type_encoding_name (encoding));
12903 type = init_type (code, size, type_flags, NULL, objfile);
12904 TYPE_NAME (type) = name;
12905 TYPE_TARGET_TYPE (type) = target_type;
12907 if (name && strcmp (name, "char") == 0)
12908 TYPE_NOSIGN (type) = 1;
12910 return set_die_type (die, type, cu);
12913 /* Read the given DW_AT_subrange DIE. */
12915 static struct type *
12916 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
12918 struct type *base_type, *orig_base_type;
12919 struct type *range_type;
12920 struct attribute *attr;
12922 int low_default_is_valid;
12924 LONGEST negative_mask;
12926 orig_base_type = die_type (die, cu);
12927 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
12928 whereas the real type might be. So, we use ORIG_BASE_TYPE when
12929 creating the range type, but we use the result of check_typedef
12930 when examining properties of the type. */
12931 base_type = check_typedef (orig_base_type);
12933 /* The die_type call above may have already set the type for this DIE. */
12934 range_type = get_die_type (die, cu);
12938 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12939 omitting DW_AT_lower_bound. */
12940 switch (cu->language)
12943 case language_cplus:
12945 low_default_is_valid = 1;
12947 case language_fortran:
12949 low_default_is_valid = 1;
12952 case language_java:
12953 case language_objc:
12955 low_default_is_valid = (cu->header.version >= 4);
12959 case language_pascal:
12961 low_default_is_valid = (cu->header.version >= 4);
12965 low_default_is_valid = 0;
12969 /* FIXME: For variable sized arrays either of these could be
12970 a variable rather than a constant value. We'll allow it,
12971 but we don't know how to handle it. */
12972 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
12974 low = dwarf2_get_attr_constant_value (attr, low);
12975 else if (!low_default_is_valid)
12976 complaint (&symfile_complaints, _("Missing DW_AT_lower_bound "
12977 "- DIE at 0x%x [in module %s]"),
12978 die->offset.sect_off, cu->objfile->name);
12980 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
12983 if (attr_form_is_block (attr) || is_ref_attr (attr))
12985 /* GCC encodes arrays with unspecified or dynamic length
12986 with a DW_FORM_block1 attribute or a reference attribute.
12987 FIXME: GDB does not yet know how to handle dynamic
12988 arrays properly, treat them as arrays with unspecified
12991 FIXME: jimb/2003-09-22: GDB does not really know
12992 how to handle arrays of unspecified length
12993 either; we just represent them as zero-length
12994 arrays. Choose an appropriate upper bound given
12995 the lower bound we've computed above. */
12999 high = dwarf2_get_attr_constant_value (attr, 1);
13003 attr = dwarf2_attr (die, DW_AT_count, cu);
13006 int count = dwarf2_get_attr_constant_value (attr, 1);
13007 high = low + count - 1;
13011 /* Unspecified array length. */
13016 /* Dwarf-2 specifications explicitly allows to create subrange types
13017 without specifying a base type.
13018 In that case, the base type must be set to the type of
13019 the lower bound, upper bound or count, in that order, if any of these
13020 three attributes references an object that has a type.
13021 If no base type is found, the Dwarf-2 specifications say that
13022 a signed integer type of size equal to the size of an address should
13024 For the following C code: `extern char gdb_int [];'
13025 GCC produces an empty range DIE.
13026 FIXME: muller/2010-05-28: Possible references to object for low bound,
13027 high bound or count are not yet handled by this code. */
13028 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
13030 struct objfile *objfile = cu->objfile;
13031 struct gdbarch *gdbarch = get_objfile_arch (objfile);
13032 int addr_size = gdbarch_addr_bit (gdbarch) /8;
13033 struct type *int_type = objfile_type (objfile)->builtin_int;
13035 /* Test "int", "long int", and "long long int" objfile types,
13036 and select the first one having a size above or equal to the
13037 architecture address size. */
13038 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
13039 base_type = int_type;
13042 int_type = objfile_type (objfile)->builtin_long;
13043 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
13044 base_type = int_type;
13047 int_type = objfile_type (objfile)->builtin_long_long;
13048 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
13049 base_type = int_type;
13055 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
13056 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
13057 low |= negative_mask;
13058 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
13059 high |= negative_mask;
13061 range_type = create_range_type (NULL, orig_base_type, low, high);
13063 /* Mark arrays with dynamic length at least as an array of unspecified
13064 length. GDB could check the boundary but before it gets implemented at
13065 least allow accessing the array elements. */
13066 if (attr && attr_form_is_block (attr))
13067 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
13069 /* Ada expects an empty array on no boundary attributes. */
13070 if (attr == NULL && cu->language != language_ada)
13071 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
13073 name = dwarf2_name (die, cu);
13075 TYPE_NAME (range_type) = name;
13077 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
13079 TYPE_LENGTH (range_type) = DW_UNSND (attr);
13081 set_die_type (die, range_type, cu);
13083 /* set_die_type should be already done. */
13084 set_descriptive_type (range_type, die, cu);
13089 static struct type *
13090 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
13094 /* For now, we only support the C meaning of an unspecified type: void. */
13096 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
13097 TYPE_NAME (type) = dwarf2_name (die, cu);
13099 return set_die_type (die, type, cu);
13102 /* Read a single die and all its descendents. Set the die's sibling
13103 field to NULL; set other fields in the die correctly, and set all
13104 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
13105 location of the info_ptr after reading all of those dies. PARENT
13106 is the parent of the die in question. */
13108 static struct die_info *
13109 read_die_and_children (const struct die_reader_specs *reader,
13110 const gdb_byte *info_ptr,
13111 const gdb_byte **new_info_ptr,
13112 struct die_info *parent)
13114 struct die_info *die;
13115 const gdb_byte *cur_ptr;
13118 cur_ptr = read_full_die_1 (reader, &die, info_ptr, &has_children, 0);
13121 *new_info_ptr = cur_ptr;
13124 store_in_ref_table (die, reader->cu);
13127 die->child = read_die_and_siblings_1 (reader, cur_ptr, new_info_ptr, die);
13131 *new_info_ptr = cur_ptr;
13134 die->sibling = NULL;
13135 die->parent = parent;
13139 /* Read a die, all of its descendents, and all of its siblings; set
13140 all of the fields of all of the dies correctly. Arguments are as
13141 in read_die_and_children. */
13143 static struct die_info *
13144 read_die_and_siblings_1 (const struct die_reader_specs *reader,
13145 const gdb_byte *info_ptr,
13146 const gdb_byte **new_info_ptr,
13147 struct die_info *parent)
13149 struct die_info *first_die, *last_sibling;
13150 const gdb_byte *cur_ptr;
13152 cur_ptr = info_ptr;
13153 first_die = last_sibling = NULL;
13157 struct die_info *die
13158 = read_die_and_children (reader, cur_ptr, &cur_ptr, parent);
13162 *new_info_ptr = cur_ptr;
13169 last_sibling->sibling = die;
13171 last_sibling = die;
13175 /* Read a die, all of its descendents, and all of its siblings; set
13176 all of the fields of all of the dies correctly. Arguments are as
13177 in read_die_and_children.
13178 This the main entry point for reading a DIE and all its children. */
13180 static struct die_info *
13181 read_die_and_siblings (const struct die_reader_specs *reader,
13182 const gdb_byte *info_ptr,
13183 const gdb_byte **new_info_ptr,
13184 struct die_info *parent)
13186 struct die_info *die = read_die_and_siblings_1 (reader, info_ptr,
13187 new_info_ptr, parent);
13189 if (dwarf2_die_debug)
13191 fprintf_unfiltered (gdb_stdlog,
13192 "Read die from %s@0x%x of %s:\n",
13193 bfd_section_name (reader->abfd,
13194 reader->die_section->asection),
13195 (unsigned) (info_ptr - reader->die_section->buffer),
13196 bfd_get_filename (reader->abfd));
13197 dump_die (die, dwarf2_die_debug);
13203 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
13205 The caller is responsible for filling in the extra attributes
13206 and updating (*DIEP)->num_attrs.
13207 Set DIEP to point to a newly allocated die with its information,
13208 except for its child, sibling, and parent fields.
13209 Set HAS_CHILDREN to tell whether the die has children or not. */
13211 static const gdb_byte *
13212 read_full_die_1 (const struct die_reader_specs *reader,
13213 struct die_info **diep, const gdb_byte *info_ptr,
13214 int *has_children, int num_extra_attrs)
13216 unsigned int abbrev_number, bytes_read, i;
13217 sect_offset offset;
13218 struct abbrev_info *abbrev;
13219 struct die_info *die;
13220 struct dwarf2_cu *cu = reader->cu;
13221 bfd *abfd = reader->abfd;
13223 offset.sect_off = info_ptr - reader->buffer;
13224 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
13225 info_ptr += bytes_read;
13226 if (!abbrev_number)
13233 abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number);
13235 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
13237 bfd_get_filename (abfd));
13239 die = dwarf_alloc_die (cu, abbrev->num_attrs + num_extra_attrs);
13240 die->offset = offset;
13241 die->tag = abbrev->tag;
13242 die->abbrev = abbrev_number;
13244 /* Make the result usable.
13245 The caller needs to update num_attrs after adding the extra
13247 die->num_attrs = abbrev->num_attrs;
13249 for (i = 0; i < abbrev->num_attrs; ++i)
13250 info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i],
13254 *has_children = abbrev->has_children;
13258 /* Read a die and all its attributes.
13259 Set DIEP to point to a newly allocated die with its information,
13260 except for its child, sibling, and parent fields.
13261 Set HAS_CHILDREN to tell whether the die has children or not. */
13263 static const gdb_byte *
13264 read_full_die (const struct die_reader_specs *reader,
13265 struct die_info **diep, const gdb_byte *info_ptr,
13268 const gdb_byte *result;
13270 result = read_full_die_1 (reader, diep, info_ptr, has_children, 0);
13272 if (dwarf2_die_debug)
13274 fprintf_unfiltered (gdb_stdlog,
13275 "Read die from %s@0x%x of %s:\n",
13276 bfd_section_name (reader->abfd,
13277 reader->die_section->asection),
13278 (unsigned) (info_ptr - reader->die_section->buffer),
13279 bfd_get_filename (reader->abfd));
13280 dump_die (*diep, dwarf2_die_debug);
13286 /* Abbreviation tables.
13288 In DWARF version 2, the description of the debugging information is
13289 stored in a separate .debug_abbrev section. Before we read any
13290 dies from a section we read in all abbreviations and install them
13291 in a hash table. */
13293 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
13295 static struct abbrev_info *
13296 abbrev_table_alloc_abbrev (struct abbrev_table *abbrev_table)
13298 struct abbrev_info *abbrev;
13300 abbrev = (struct abbrev_info *)
13301 obstack_alloc (&abbrev_table->abbrev_obstack, sizeof (struct abbrev_info));
13302 memset (abbrev, 0, sizeof (struct abbrev_info));
13306 /* Add an abbreviation to the table. */
13309 abbrev_table_add_abbrev (struct abbrev_table *abbrev_table,
13310 unsigned int abbrev_number,
13311 struct abbrev_info *abbrev)
13313 unsigned int hash_number;
13315 hash_number = abbrev_number % ABBREV_HASH_SIZE;
13316 abbrev->next = abbrev_table->abbrevs[hash_number];
13317 abbrev_table->abbrevs[hash_number] = abbrev;
13320 /* Look up an abbrev in the table.
13321 Returns NULL if the abbrev is not found. */
13323 static struct abbrev_info *
13324 abbrev_table_lookup_abbrev (const struct abbrev_table *abbrev_table,
13325 unsigned int abbrev_number)
13327 unsigned int hash_number;
13328 struct abbrev_info *abbrev;
13330 hash_number = abbrev_number % ABBREV_HASH_SIZE;
13331 abbrev = abbrev_table->abbrevs[hash_number];
13335 if (abbrev->number == abbrev_number)
13337 abbrev = abbrev->next;
13342 /* Read in an abbrev table. */
13344 static struct abbrev_table *
13345 abbrev_table_read_table (struct dwarf2_section_info *section,
13346 sect_offset offset)
13348 struct objfile *objfile = dwarf2_per_objfile->objfile;
13349 bfd *abfd = section->asection->owner;
13350 struct abbrev_table *abbrev_table;
13351 const gdb_byte *abbrev_ptr;
13352 struct abbrev_info *cur_abbrev;
13353 unsigned int abbrev_number, bytes_read, abbrev_name;
13354 unsigned int abbrev_form;
13355 struct attr_abbrev *cur_attrs;
13356 unsigned int allocated_attrs;
13358 abbrev_table = XMALLOC (struct abbrev_table);
13359 abbrev_table->offset = offset;
13360 obstack_init (&abbrev_table->abbrev_obstack);
13361 abbrev_table->abbrevs = obstack_alloc (&abbrev_table->abbrev_obstack,
13363 * sizeof (struct abbrev_info *)));
13364 memset (abbrev_table->abbrevs, 0,
13365 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
13367 dwarf2_read_section (objfile, section);
13368 abbrev_ptr = section->buffer + offset.sect_off;
13369 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13370 abbrev_ptr += bytes_read;
13372 allocated_attrs = ATTR_ALLOC_CHUNK;
13373 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
13375 /* Loop until we reach an abbrev number of 0. */
13376 while (abbrev_number)
13378 cur_abbrev = abbrev_table_alloc_abbrev (abbrev_table);
13380 /* read in abbrev header */
13381 cur_abbrev->number = abbrev_number;
13382 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13383 abbrev_ptr += bytes_read;
13384 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
13387 /* now read in declarations */
13388 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13389 abbrev_ptr += bytes_read;
13390 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13391 abbrev_ptr += bytes_read;
13392 while (abbrev_name)
13394 if (cur_abbrev->num_attrs == allocated_attrs)
13396 allocated_attrs += ATTR_ALLOC_CHUNK;
13398 = xrealloc (cur_attrs, (allocated_attrs
13399 * sizeof (struct attr_abbrev)));
13402 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
13403 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
13404 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13405 abbrev_ptr += bytes_read;
13406 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13407 abbrev_ptr += bytes_read;
13410 cur_abbrev->attrs = obstack_alloc (&abbrev_table->abbrev_obstack,
13411 (cur_abbrev->num_attrs
13412 * sizeof (struct attr_abbrev)));
13413 memcpy (cur_abbrev->attrs, cur_attrs,
13414 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
13416 abbrev_table_add_abbrev (abbrev_table, abbrev_number, cur_abbrev);
13418 /* Get next abbreviation.
13419 Under Irix6 the abbreviations for a compilation unit are not
13420 always properly terminated with an abbrev number of 0.
13421 Exit loop if we encounter an abbreviation which we have
13422 already read (which means we are about to read the abbreviations
13423 for the next compile unit) or if the end of the abbreviation
13424 table is reached. */
13425 if ((unsigned int) (abbrev_ptr - section->buffer) >= section->size)
13427 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13428 abbrev_ptr += bytes_read;
13429 if (abbrev_table_lookup_abbrev (abbrev_table, abbrev_number) != NULL)
13434 return abbrev_table;
13437 /* Free the resources held by ABBREV_TABLE. */
13440 abbrev_table_free (struct abbrev_table *abbrev_table)
13442 obstack_free (&abbrev_table->abbrev_obstack, NULL);
13443 xfree (abbrev_table);
13446 /* Same as abbrev_table_free but as a cleanup.
13447 We pass in a pointer to the pointer to the table so that we can
13448 set the pointer to NULL when we're done. It also simplifies
13449 build_type_unit_groups. */
13452 abbrev_table_free_cleanup (void *table_ptr)
13454 struct abbrev_table **abbrev_table_ptr = table_ptr;
13456 if (*abbrev_table_ptr != NULL)
13457 abbrev_table_free (*abbrev_table_ptr);
13458 *abbrev_table_ptr = NULL;
13461 /* Read the abbrev table for CU from ABBREV_SECTION. */
13464 dwarf2_read_abbrevs (struct dwarf2_cu *cu,
13465 struct dwarf2_section_info *abbrev_section)
13468 abbrev_table_read_table (abbrev_section, cu->header.abbrev_offset);
13471 /* Release the memory used by the abbrev table for a compilation unit. */
13474 dwarf2_free_abbrev_table (void *ptr_to_cu)
13476 struct dwarf2_cu *cu = ptr_to_cu;
13478 abbrev_table_free (cu->abbrev_table);
13479 /* Set this to NULL so that we SEGV if we try to read it later,
13480 and also because free_comp_unit verifies this is NULL. */
13481 cu->abbrev_table = NULL;
13484 /* Returns nonzero if TAG represents a type that we might generate a partial
13488 is_type_tag_for_partial (int tag)
13493 /* Some types that would be reasonable to generate partial symbols for,
13494 that we don't at present. */
13495 case DW_TAG_array_type:
13496 case DW_TAG_file_type:
13497 case DW_TAG_ptr_to_member_type:
13498 case DW_TAG_set_type:
13499 case DW_TAG_string_type:
13500 case DW_TAG_subroutine_type:
13502 case DW_TAG_base_type:
13503 case DW_TAG_class_type:
13504 case DW_TAG_interface_type:
13505 case DW_TAG_enumeration_type:
13506 case DW_TAG_structure_type:
13507 case DW_TAG_subrange_type:
13508 case DW_TAG_typedef:
13509 case DW_TAG_union_type:
13516 /* Load all DIEs that are interesting for partial symbols into memory. */
13518 static struct partial_die_info *
13519 load_partial_dies (const struct die_reader_specs *reader,
13520 const gdb_byte *info_ptr, int building_psymtab)
13522 struct dwarf2_cu *cu = reader->cu;
13523 struct objfile *objfile = cu->objfile;
13524 struct partial_die_info *part_die;
13525 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
13526 struct abbrev_info *abbrev;
13527 unsigned int bytes_read;
13528 unsigned int load_all = 0;
13529 int nesting_level = 1;
13534 gdb_assert (cu->per_cu != NULL);
13535 if (cu->per_cu->load_all_dies)
13539 = htab_create_alloc_ex (cu->header.length / 12,
13543 &cu->comp_unit_obstack,
13544 hashtab_obstack_allocate,
13545 dummy_obstack_deallocate);
13547 part_die = obstack_alloc (&cu->comp_unit_obstack,
13548 sizeof (struct partial_die_info));
13552 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
13554 /* A NULL abbrev means the end of a series of children. */
13555 if (abbrev == NULL)
13557 if (--nesting_level == 0)
13559 /* PART_DIE was probably the last thing allocated on the
13560 comp_unit_obstack, so we could call obstack_free
13561 here. We don't do that because the waste is small,
13562 and will be cleaned up when we're done with this
13563 compilation unit. This way, we're also more robust
13564 against other users of the comp_unit_obstack. */
13567 info_ptr += bytes_read;
13568 last_die = parent_die;
13569 parent_die = parent_die->die_parent;
13573 /* Check for template arguments. We never save these; if
13574 they're seen, we just mark the parent, and go on our way. */
13575 if (parent_die != NULL
13576 && cu->language == language_cplus
13577 && (abbrev->tag == DW_TAG_template_type_param
13578 || abbrev->tag == DW_TAG_template_value_param))
13580 parent_die->has_template_arguments = 1;
13584 /* We don't need a partial DIE for the template argument. */
13585 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
13590 /* We only recurse into c++ subprograms looking for template arguments.
13591 Skip their other children. */
13593 && cu->language == language_cplus
13594 && parent_die != NULL
13595 && parent_die->tag == DW_TAG_subprogram)
13597 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
13601 /* Check whether this DIE is interesting enough to save. Normally
13602 we would not be interested in members here, but there may be
13603 later variables referencing them via DW_AT_specification (for
13604 static members). */
13606 && !is_type_tag_for_partial (abbrev->tag)
13607 && abbrev->tag != DW_TAG_constant
13608 && abbrev->tag != DW_TAG_enumerator
13609 && abbrev->tag != DW_TAG_subprogram
13610 && abbrev->tag != DW_TAG_lexical_block
13611 && abbrev->tag != DW_TAG_variable
13612 && abbrev->tag != DW_TAG_namespace
13613 && abbrev->tag != DW_TAG_module
13614 && abbrev->tag != DW_TAG_member
13615 && abbrev->tag != DW_TAG_imported_unit)
13617 /* Otherwise we skip to the next sibling, if any. */
13618 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
13622 info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read,
13625 /* This two-pass algorithm for processing partial symbols has a
13626 high cost in cache pressure. Thus, handle some simple cases
13627 here which cover the majority of C partial symbols. DIEs
13628 which neither have specification tags in them, nor could have
13629 specification tags elsewhere pointing at them, can simply be
13630 processed and discarded.
13632 This segment is also optional; scan_partial_symbols and
13633 add_partial_symbol will handle these DIEs if we chain
13634 them in normally. When compilers which do not emit large
13635 quantities of duplicate debug information are more common,
13636 this code can probably be removed. */
13638 /* Any complete simple types at the top level (pretty much all
13639 of them, for a language without namespaces), can be processed
13641 if (parent_die == NULL
13642 && part_die->has_specification == 0
13643 && part_die->is_declaration == 0
13644 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
13645 || part_die->tag == DW_TAG_base_type
13646 || part_die->tag == DW_TAG_subrange_type))
13648 if (building_psymtab && part_die->name != NULL)
13649 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
13650 VAR_DOMAIN, LOC_TYPEDEF,
13651 &objfile->static_psymbols,
13652 0, (CORE_ADDR) 0, cu->language, objfile);
13653 info_ptr = locate_pdi_sibling (reader, part_die, info_ptr);
13657 /* The exception for DW_TAG_typedef with has_children above is
13658 a workaround of GCC PR debug/47510. In the case of this complaint
13659 type_name_no_tag_or_error will error on such types later.
13661 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13662 it could not find the child DIEs referenced later, this is checked
13663 above. In correct DWARF DW_TAG_typedef should have no children. */
13665 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
13666 complaint (&symfile_complaints,
13667 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13668 "- DIE at 0x%x [in module %s]"),
13669 part_die->offset.sect_off, objfile->name);
13671 /* If we're at the second level, and we're an enumerator, and
13672 our parent has no specification (meaning possibly lives in a
13673 namespace elsewhere), then we can add the partial symbol now
13674 instead of queueing it. */
13675 if (part_die->tag == DW_TAG_enumerator
13676 && parent_die != NULL
13677 && parent_die->die_parent == NULL
13678 && parent_die->tag == DW_TAG_enumeration_type
13679 && parent_die->has_specification == 0)
13681 if (part_die->name == NULL)
13682 complaint (&symfile_complaints,
13683 _("malformed enumerator DIE ignored"));
13684 else if (building_psymtab)
13685 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
13686 VAR_DOMAIN, LOC_CONST,
13687 (cu->language == language_cplus
13688 || cu->language == language_java)
13689 ? &objfile->global_psymbols
13690 : &objfile->static_psymbols,
13691 0, (CORE_ADDR) 0, cu->language, objfile);
13693 info_ptr = locate_pdi_sibling (reader, part_die, info_ptr);
13697 /* We'll save this DIE so link it in. */
13698 part_die->die_parent = parent_die;
13699 part_die->die_sibling = NULL;
13700 part_die->die_child = NULL;
13702 if (last_die && last_die == parent_die)
13703 last_die->die_child = part_die;
13705 last_die->die_sibling = part_die;
13707 last_die = part_die;
13709 if (first_die == NULL)
13710 first_die = part_die;
13712 /* Maybe add the DIE to the hash table. Not all DIEs that we
13713 find interesting need to be in the hash table, because we
13714 also have the parent/sibling/child chains; only those that we
13715 might refer to by offset later during partial symbol reading.
13717 For now this means things that might have be the target of a
13718 DW_AT_specification, DW_AT_abstract_origin, or
13719 DW_AT_extension. DW_AT_extension will refer only to
13720 namespaces; DW_AT_abstract_origin refers to functions (and
13721 many things under the function DIE, but we do not recurse
13722 into function DIEs during partial symbol reading) and
13723 possibly variables as well; DW_AT_specification refers to
13724 declarations. Declarations ought to have the DW_AT_declaration
13725 flag. It happens that GCC forgets to put it in sometimes, but
13726 only for functions, not for types.
13728 Adding more things than necessary to the hash table is harmless
13729 except for the performance cost. Adding too few will result in
13730 wasted time in find_partial_die, when we reread the compilation
13731 unit with load_all_dies set. */
13734 || abbrev->tag == DW_TAG_constant
13735 || abbrev->tag == DW_TAG_subprogram
13736 || abbrev->tag == DW_TAG_variable
13737 || abbrev->tag == DW_TAG_namespace
13738 || part_die->is_declaration)
13742 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
13743 part_die->offset.sect_off, INSERT);
13747 part_die = obstack_alloc (&cu->comp_unit_obstack,
13748 sizeof (struct partial_die_info));
13750 /* For some DIEs we want to follow their children (if any). For C
13751 we have no reason to follow the children of structures; for other
13752 languages we have to, so that we can get at method physnames
13753 to infer fully qualified class names, for DW_AT_specification,
13754 and for C++ template arguments. For C++, we also look one level
13755 inside functions to find template arguments (if the name of the
13756 function does not already contain the template arguments).
13758 For Ada, we need to scan the children of subprograms and lexical
13759 blocks as well because Ada allows the definition of nested
13760 entities that could be interesting for the debugger, such as
13761 nested subprograms for instance. */
13762 if (last_die->has_children
13764 || last_die->tag == DW_TAG_namespace
13765 || last_die->tag == DW_TAG_module
13766 || last_die->tag == DW_TAG_enumeration_type
13767 || (cu->language == language_cplus
13768 && last_die->tag == DW_TAG_subprogram
13769 && (last_die->name == NULL
13770 || strchr (last_die->name, '<') == NULL))
13771 || (cu->language != language_c
13772 && (last_die->tag == DW_TAG_class_type
13773 || last_die->tag == DW_TAG_interface_type
13774 || last_die->tag == DW_TAG_structure_type
13775 || last_die->tag == DW_TAG_union_type))
13776 || (cu->language == language_ada
13777 && (last_die->tag == DW_TAG_subprogram
13778 || last_die->tag == DW_TAG_lexical_block))))
13781 parent_die = last_die;
13785 /* Otherwise we skip to the next sibling, if any. */
13786 info_ptr = locate_pdi_sibling (reader, last_die, info_ptr);
13788 /* Back to the top, do it again. */
13792 /* Read a minimal amount of information into the minimal die structure. */
13794 static const gdb_byte *
13795 read_partial_die (const struct die_reader_specs *reader,
13796 struct partial_die_info *part_die,
13797 struct abbrev_info *abbrev, unsigned int abbrev_len,
13798 const gdb_byte *info_ptr)
13800 struct dwarf2_cu *cu = reader->cu;
13801 struct objfile *objfile = cu->objfile;
13802 const gdb_byte *buffer = reader->buffer;
13804 struct attribute attr;
13805 int has_low_pc_attr = 0;
13806 int has_high_pc_attr = 0;
13807 int high_pc_relative = 0;
13809 memset (part_die, 0, sizeof (struct partial_die_info));
13811 part_die->offset.sect_off = info_ptr - buffer;
13813 info_ptr += abbrev_len;
13815 if (abbrev == NULL)
13818 part_die->tag = abbrev->tag;
13819 part_die->has_children = abbrev->has_children;
13821 for (i = 0; i < abbrev->num_attrs; ++i)
13823 info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
13825 /* Store the data if it is of an attribute we want to keep in a
13826 partial symbol table. */
13830 switch (part_die->tag)
13832 case DW_TAG_compile_unit:
13833 case DW_TAG_partial_unit:
13834 case DW_TAG_type_unit:
13835 /* Compilation units have a DW_AT_name that is a filename, not
13836 a source language identifier. */
13837 case DW_TAG_enumeration_type:
13838 case DW_TAG_enumerator:
13839 /* These tags always have simple identifiers already; no need
13840 to canonicalize them. */
13841 part_die->name = DW_STRING (&attr);
13845 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
13846 &objfile->objfile_obstack);
13850 case DW_AT_linkage_name:
13851 case DW_AT_MIPS_linkage_name:
13852 /* Note that both forms of linkage name might appear. We
13853 assume they will be the same, and we only store the last
13855 if (cu->language == language_ada)
13856 part_die->name = DW_STRING (&attr);
13857 part_die->linkage_name = DW_STRING (&attr);
13860 has_low_pc_attr = 1;
13861 part_die->lowpc = DW_ADDR (&attr);
13863 case DW_AT_high_pc:
13864 has_high_pc_attr = 1;
13865 if (attr.form == DW_FORM_addr
13866 || attr.form == DW_FORM_GNU_addr_index)
13867 part_die->highpc = DW_ADDR (&attr);
13870 high_pc_relative = 1;
13871 part_die->highpc = DW_UNSND (&attr);
13874 case DW_AT_location:
13875 /* Support the .debug_loc offsets. */
13876 if (attr_form_is_block (&attr))
13878 part_die->d.locdesc = DW_BLOCK (&attr);
13880 else if (attr_form_is_section_offset (&attr))
13882 dwarf2_complex_location_expr_complaint ();
13886 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13887 "partial symbol information");
13890 case DW_AT_external:
13891 part_die->is_external = DW_UNSND (&attr);
13893 case DW_AT_declaration:
13894 part_die->is_declaration = DW_UNSND (&attr);
13897 part_die->has_type = 1;
13899 case DW_AT_abstract_origin:
13900 case DW_AT_specification:
13901 case DW_AT_extension:
13902 part_die->has_specification = 1;
13903 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
13904 part_die->spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt
13905 || cu->per_cu->is_dwz);
13907 case DW_AT_sibling:
13908 /* Ignore absolute siblings, they might point outside of
13909 the current compile unit. */
13910 if (attr.form == DW_FORM_ref_addr)
13911 complaint (&symfile_complaints,
13912 _("ignoring absolute DW_AT_sibling"));
13914 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr).sect_off;
13916 case DW_AT_byte_size:
13917 part_die->has_byte_size = 1;
13919 case DW_AT_calling_convention:
13920 /* DWARF doesn't provide a way to identify a program's source-level
13921 entry point. DW_AT_calling_convention attributes are only meant
13922 to describe functions' calling conventions.
13924 However, because it's a necessary piece of information in
13925 Fortran, and because DW_CC_program is the only piece of debugging
13926 information whose definition refers to a 'main program' at all,
13927 several compilers have begun marking Fortran main programs with
13928 DW_CC_program --- even when those functions use the standard
13929 calling conventions.
13931 So until DWARF specifies a way to provide this information and
13932 compilers pick up the new representation, we'll support this
13934 if (DW_UNSND (&attr) == DW_CC_program
13935 && cu->language == language_fortran)
13937 set_main_name (part_die->name);
13939 /* As this DIE has a static linkage the name would be difficult
13940 to look up later. */
13941 language_of_main = language_fortran;
13945 if (DW_UNSND (&attr) == DW_INL_inlined
13946 || DW_UNSND (&attr) == DW_INL_declared_inlined)
13947 part_die->may_be_inlined = 1;
13951 if (part_die->tag == DW_TAG_imported_unit)
13953 part_die->d.offset = dwarf2_get_ref_die_offset (&attr);
13954 part_die->is_dwz = (attr.form == DW_FORM_GNU_ref_alt
13955 || cu->per_cu->is_dwz);
13964 if (high_pc_relative)
13965 part_die->highpc += part_die->lowpc;
13967 if (has_low_pc_attr && has_high_pc_attr)
13969 /* When using the GNU linker, .gnu.linkonce. sections are used to
13970 eliminate duplicate copies of functions and vtables and such.
13971 The linker will arbitrarily choose one and discard the others.
13972 The AT_*_pc values for such functions refer to local labels in
13973 these sections. If the section from that file was discarded, the
13974 labels are not in the output, so the relocs get a value of 0.
13975 If this is a discarded function, mark the pc bounds as invalid,
13976 so that GDB will ignore it. */
13977 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
13979 struct gdbarch *gdbarch = get_objfile_arch (objfile);
13981 complaint (&symfile_complaints,
13982 _("DW_AT_low_pc %s is zero "
13983 "for DIE at 0x%x [in module %s]"),
13984 paddress (gdbarch, part_die->lowpc),
13985 part_die->offset.sect_off, objfile->name);
13987 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13988 else if (part_die->lowpc >= part_die->highpc)
13990 struct gdbarch *gdbarch = get_objfile_arch (objfile);
13992 complaint (&symfile_complaints,
13993 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13994 "for DIE at 0x%x [in module %s]"),
13995 paddress (gdbarch, part_die->lowpc),
13996 paddress (gdbarch, part_die->highpc),
13997 part_die->offset.sect_off, objfile->name);
14000 part_die->has_pc_info = 1;
14006 /* Find a cached partial DIE at OFFSET in CU. */
14008 static struct partial_die_info *
14009 find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu)
14011 struct partial_die_info *lookup_die = NULL;
14012 struct partial_die_info part_die;
14014 part_die.offset = offset;
14015 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die,
14021 /* Find a partial DIE at OFFSET, which may or may not be in CU,
14022 except in the case of .debug_types DIEs which do not reference
14023 outside their CU (they do however referencing other types via
14024 DW_FORM_ref_sig8). */
14026 static struct partial_die_info *
14027 find_partial_die (sect_offset offset, int offset_in_dwz, struct dwarf2_cu *cu)
14029 struct objfile *objfile = cu->objfile;
14030 struct dwarf2_per_cu_data *per_cu = NULL;
14031 struct partial_die_info *pd = NULL;
14033 if (offset_in_dwz == cu->per_cu->is_dwz
14034 && offset_in_cu_p (&cu->header, offset))
14036 pd = find_partial_die_in_comp_unit (offset, cu);
14039 /* We missed recording what we needed.
14040 Load all dies and try again. */
14041 per_cu = cu->per_cu;
14045 /* TUs don't reference other CUs/TUs (except via type signatures). */
14046 if (cu->per_cu->is_debug_types)
14048 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
14049 " external reference to offset 0x%lx [in module %s].\n"),
14050 (long) cu->header.offset.sect_off, (long) offset.sect_off,
14051 bfd_get_filename (objfile->obfd));
14053 per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
14056 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
14057 load_partial_comp_unit (per_cu);
14059 per_cu->cu->last_used = 0;
14060 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
14063 /* If we didn't find it, and not all dies have been loaded,
14064 load them all and try again. */
14066 if (pd == NULL && per_cu->load_all_dies == 0)
14068 per_cu->load_all_dies = 1;
14070 /* This is nasty. When we reread the DIEs, somewhere up the call chain
14071 THIS_CU->cu may already be in use. So we can't just free it and
14072 replace its DIEs with the ones we read in. Instead, we leave those
14073 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
14074 and clobber THIS_CU->cu->partial_dies with the hash table for the new
14076 load_partial_comp_unit (per_cu);
14078 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
14082 internal_error (__FILE__, __LINE__,
14083 _("could not find partial DIE 0x%x "
14084 "in cache [from module %s]\n"),
14085 offset.sect_off, bfd_get_filename (objfile->obfd));
14089 /* See if we can figure out if the class lives in a namespace. We do
14090 this by looking for a member function; its demangled name will
14091 contain namespace info, if there is any. */
14094 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
14095 struct dwarf2_cu *cu)
14097 /* NOTE: carlton/2003-10-07: Getting the info this way changes
14098 what template types look like, because the demangler
14099 frequently doesn't give the same name as the debug info. We
14100 could fix this by only using the demangled name to get the
14101 prefix (but see comment in read_structure_type). */
14103 struct partial_die_info *real_pdi;
14104 struct partial_die_info *child_pdi;
14106 /* If this DIE (this DIE's specification, if any) has a parent, then
14107 we should not do this. We'll prepend the parent's fully qualified
14108 name when we create the partial symbol. */
14110 real_pdi = struct_pdi;
14111 while (real_pdi->has_specification)
14112 real_pdi = find_partial_die (real_pdi->spec_offset,
14113 real_pdi->spec_is_dwz, cu);
14115 if (real_pdi->die_parent != NULL)
14118 for (child_pdi = struct_pdi->die_child;
14120 child_pdi = child_pdi->die_sibling)
14122 if (child_pdi->tag == DW_TAG_subprogram
14123 && child_pdi->linkage_name != NULL)
14125 char *actual_class_name
14126 = language_class_name_from_physname (cu->language_defn,
14127 child_pdi->linkage_name);
14128 if (actual_class_name != NULL)
14131 = obstack_copy0 (&cu->objfile->objfile_obstack,
14133 strlen (actual_class_name));
14134 xfree (actual_class_name);
14141 /* Adjust PART_DIE before generating a symbol for it. This function
14142 may set the is_external flag or change the DIE's name. */
14145 fixup_partial_die (struct partial_die_info *part_die,
14146 struct dwarf2_cu *cu)
14148 /* Once we've fixed up a die, there's no point in doing so again.
14149 This also avoids a memory leak if we were to call
14150 guess_partial_die_structure_name multiple times. */
14151 if (part_die->fixup_called)
14154 /* If we found a reference attribute and the DIE has no name, try
14155 to find a name in the referred to DIE. */
14157 if (part_die->name == NULL && part_die->has_specification)
14159 struct partial_die_info *spec_die;
14161 spec_die = find_partial_die (part_die->spec_offset,
14162 part_die->spec_is_dwz, cu);
14164 fixup_partial_die (spec_die, cu);
14166 if (spec_die->name)
14168 part_die->name = spec_die->name;
14170 /* Copy DW_AT_external attribute if it is set. */
14171 if (spec_die->is_external)
14172 part_die->is_external = spec_die->is_external;
14176 /* Set default names for some unnamed DIEs. */
14178 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
14179 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
14181 /* If there is no parent die to provide a namespace, and there are
14182 children, see if we can determine the namespace from their linkage
14184 if (cu->language == language_cplus
14185 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
14186 && part_die->die_parent == NULL
14187 && part_die->has_children
14188 && (part_die->tag == DW_TAG_class_type
14189 || part_die->tag == DW_TAG_structure_type
14190 || part_die->tag == DW_TAG_union_type))
14191 guess_partial_die_structure_name (part_die, cu);
14193 /* GCC might emit a nameless struct or union that has a linkage
14194 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
14195 if (part_die->name == NULL
14196 && (part_die->tag == DW_TAG_class_type
14197 || part_die->tag == DW_TAG_interface_type
14198 || part_die->tag == DW_TAG_structure_type
14199 || part_die->tag == DW_TAG_union_type)
14200 && part_die->linkage_name != NULL)
14204 demangled = gdb_demangle (part_die->linkage_name, DMGL_TYPES);
14209 /* Strip any leading namespaces/classes, keep only the base name.
14210 DW_AT_name for named DIEs does not contain the prefixes. */
14211 base = strrchr (demangled, ':');
14212 if (base && base > demangled && base[-1] == ':')
14217 part_die->name = obstack_copy0 (&cu->objfile->objfile_obstack,
14218 base, strlen (base));
14223 part_die->fixup_called = 1;
14226 /* Read an attribute value described by an attribute form. */
14228 static const gdb_byte *
14229 read_attribute_value (const struct die_reader_specs *reader,
14230 struct attribute *attr, unsigned form,
14231 const gdb_byte *info_ptr)
14233 struct dwarf2_cu *cu = reader->cu;
14234 bfd *abfd = reader->abfd;
14235 struct comp_unit_head *cu_header = &cu->header;
14236 unsigned int bytes_read;
14237 struct dwarf_block *blk;
14242 case DW_FORM_ref_addr:
14243 if (cu->header.version == 2)
14244 DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
14246 DW_UNSND (attr) = read_offset (abfd, info_ptr,
14247 &cu->header, &bytes_read);
14248 info_ptr += bytes_read;
14250 case DW_FORM_GNU_ref_alt:
14251 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
14252 info_ptr += bytes_read;
14255 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
14256 info_ptr += bytes_read;
14258 case DW_FORM_block2:
14259 blk = dwarf_alloc_block (cu);
14260 blk->size = read_2_bytes (abfd, info_ptr);
14262 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
14263 info_ptr += blk->size;
14264 DW_BLOCK (attr) = blk;
14266 case DW_FORM_block4:
14267 blk = dwarf_alloc_block (cu);
14268 blk->size = read_4_bytes (abfd, info_ptr);
14270 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
14271 info_ptr += blk->size;
14272 DW_BLOCK (attr) = blk;
14274 case DW_FORM_data2:
14275 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
14278 case DW_FORM_data4:
14279 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
14282 case DW_FORM_data8:
14283 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
14286 case DW_FORM_sec_offset:
14287 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
14288 info_ptr += bytes_read;
14290 case DW_FORM_string:
14291 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
14292 DW_STRING_IS_CANONICAL (attr) = 0;
14293 info_ptr += bytes_read;
14296 if (!cu->per_cu->is_dwz)
14298 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
14300 DW_STRING_IS_CANONICAL (attr) = 0;
14301 info_ptr += bytes_read;
14305 case DW_FORM_GNU_strp_alt:
14307 struct dwz_file *dwz = dwarf2_get_dwz_file ();
14308 LONGEST str_offset = read_offset (abfd, info_ptr, cu_header,
14311 DW_STRING (attr) = read_indirect_string_from_dwz (dwz, str_offset);
14312 DW_STRING_IS_CANONICAL (attr) = 0;
14313 info_ptr += bytes_read;
14316 case DW_FORM_exprloc:
14317 case DW_FORM_block:
14318 blk = dwarf_alloc_block (cu);
14319 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14320 info_ptr += bytes_read;
14321 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
14322 info_ptr += blk->size;
14323 DW_BLOCK (attr) = blk;
14325 case DW_FORM_block1:
14326 blk = dwarf_alloc_block (cu);
14327 blk->size = read_1_byte (abfd, info_ptr);
14329 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
14330 info_ptr += blk->size;
14331 DW_BLOCK (attr) = blk;
14333 case DW_FORM_data1:
14334 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
14338 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
14341 case DW_FORM_flag_present:
14342 DW_UNSND (attr) = 1;
14344 case DW_FORM_sdata:
14345 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
14346 info_ptr += bytes_read;
14348 case DW_FORM_udata:
14349 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14350 info_ptr += bytes_read;
14353 DW_UNSND (attr) = (cu->header.offset.sect_off
14354 + read_1_byte (abfd, info_ptr));
14358 DW_UNSND (attr) = (cu->header.offset.sect_off
14359 + read_2_bytes (abfd, info_ptr));
14363 DW_UNSND (attr) = (cu->header.offset.sect_off
14364 + read_4_bytes (abfd, info_ptr));
14368 DW_UNSND (attr) = (cu->header.offset.sect_off
14369 + read_8_bytes (abfd, info_ptr));
14372 case DW_FORM_ref_sig8:
14373 DW_SIGNATURE (attr) = read_8_bytes (abfd, info_ptr);
14376 case DW_FORM_ref_udata:
14377 DW_UNSND (attr) = (cu->header.offset.sect_off
14378 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
14379 info_ptr += bytes_read;
14381 case DW_FORM_indirect:
14382 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14383 info_ptr += bytes_read;
14384 info_ptr = read_attribute_value (reader, attr, form, info_ptr);
14386 case DW_FORM_GNU_addr_index:
14387 if (reader->dwo_file == NULL)
14389 /* For now flag a hard error.
14390 Later we can turn this into a complaint. */
14391 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14392 dwarf_form_name (form),
14393 bfd_get_filename (abfd));
14395 DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read);
14396 info_ptr += bytes_read;
14398 case DW_FORM_GNU_str_index:
14399 if (reader->dwo_file == NULL)
14401 /* For now flag a hard error.
14402 Later we can turn this into a complaint if warranted. */
14403 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14404 dwarf_form_name (form),
14405 bfd_get_filename (abfd));
14408 ULONGEST str_index =
14409 read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14411 DW_STRING (attr) = read_str_index (reader, cu, str_index);
14412 DW_STRING_IS_CANONICAL (attr) = 0;
14413 info_ptr += bytes_read;
14417 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14418 dwarf_form_name (form),
14419 bfd_get_filename (abfd));
14423 if (cu->per_cu->is_dwz && is_ref_attr (attr))
14424 attr->form = DW_FORM_GNU_ref_alt;
14426 /* We have seen instances where the compiler tried to emit a byte
14427 size attribute of -1 which ended up being encoded as an unsigned
14428 0xffffffff. Although 0xffffffff is technically a valid size value,
14429 an object of this size seems pretty unlikely so we can relatively
14430 safely treat these cases as if the size attribute was invalid and
14431 treat them as zero by default. */
14432 if (attr->name == DW_AT_byte_size
14433 && form == DW_FORM_data4
14434 && DW_UNSND (attr) >= 0xffffffff)
14437 (&symfile_complaints,
14438 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14439 hex_string (DW_UNSND (attr)));
14440 DW_UNSND (attr) = 0;
14446 /* Read an attribute described by an abbreviated attribute. */
14448 static const gdb_byte *
14449 read_attribute (const struct die_reader_specs *reader,
14450 struct attribute *attr, struct attr_abbrev *abbrev,
14451 const gdb_byte *info_ptr)
14453 attr->name = abbrev->name;
14454 return read_attribute_value (reader, attr, abbrev->form, info_ptr);
14457 /* Read dwarf information from a buffer. */
14459 static unsigned int
14460 read_1_byte (bfd *abfd, const gdb_byte *buf)
14462 return bfd_get_8 (abfd, buf);
14466 read_1_signed_byte (bfd *abfd, const gdb_byte *buf)
14468 return bfd_get_signed_8 (abfd, buf);
14471 static unsigned int
14472 read_2_bytes (bfd *abfd, const gdb_byte *buf)
14474 return bfd_get_16 (abfd, buf);
14478 read_2_signed_bytes (bfd *abfd, const gdb_byte *buf)
14480 return bfd_get_signed_16 (abfd, buf);
14483 static unsigned int
14484 read_4_bytes (bfd *abfd, const gdb_byte *buf)
14486 return bfd_get_32 (abfd, buf);
14490 read_4_signed_bytes (bfd *abfd, const gdb_byte *buf)
14492 return bfd_get_signed_32 (abfd, buf);
14496 read_8_bytes (bfd *abfd, const gdb_byte *buf)
14498 return bfd_get_64 (abfd, buf);
14502 read_address (bfd *abfd, const gdb_byte *buf, struct dwarf2_cu *cu,
14503 unsigned int *bytes_read)
14505 struct comp_unit_head *cu_header = &cu->header;
14506 CORE_ADDR retval = 0;
14508 if (cu_header->signed_addr_p)
14510 switch (cu_header->addr_size)
14513 retval = bfd_get_signed_16 (abfd, buf);
14516 retval = bfd_get_signed_32 (abfd, buf);
14519 retval = bfd_get_signed_64 (abfd, buf);
14522 internal_error (__FILE__, __LINE__,
14523 _("read_address: bad switch, signed [in module %s]"),
14524 bfd_get_filename (abfd));
14529 switch (cu_header->addr_size)
14532 retval = bfd_get_16 (abfd, buf);
14535 retval = bfd_get_32 (abfd, buf);
14538 retval = bfd_get_64 (abfd, buf);
14541 internal_error (__FILE__, __LINE__,
14542 _("read_address: bad switch, "
14543 "unsigned [in module %s]"),
14544 bfd_get_filename (abfd));
14548 *bytes_read = cu_header->addr_size;
14552 /* Read the initial length from a section. The (draft) DWARF 3
14553 specification allows the initial length to take up either 4 bytes
14554 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14555 bytes describe the length and all offsets will be 8 bytes in length
14558 An older, non-standard 64-bit format is also handled by this
14559 function. The older format in question stores the initial length
14560 as an 8-byte quantity without an escape value. Lengths greater
14561 than 2^32 aren't very common which means that the initial 4 bytes
14562 is almost always zero. Since a length value of zero doesn't make
14563 sense for the 32-bit format, this initial zero can be considered to
14564 be an escape value which indicates the presence of the older 64-bit
14565 format. As written, the code can't detect (old format) lengths
14566 greater than 4GB. If it becomes necessary to handle lengths
14567 somewhat larger than 4GB, we could allow other small values (such
14568 as the non-sensical values of 1, 2, and 3) to also be used as
14569 escape values indicating the presence of the old format.
14571 The value returned via bytes_read should be used to increment the
14572 relevant pointer after calling read_initial_length().
14574 [ Note: read_initial_length() and read_offset() are based on the
14575 document entitled "DWARF Debugging Information Format", revision
14576 3, draft 8, dated November 19, 2001. This document was obtained
14579 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14581 This document is only a draft and is subject to change. (So beware.)
14583 Details regarding the older, non-standard 64-bit format were
14584 determined empirically by examining 64-bit ELF files produced by
14585 the SGI toolchain on an IRIX 6.5 machine.
14587 - Kevin, July 16, 2002
14591 read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read)
14593 LONGEST length = bfd_get_32 (abfd, buf);
14595 if (length == 0xffffffff)
14597 length = bfd_get_64 (abfd, buf + 4);
14600 else if (length == 0)
14602 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14603 length = bfd_get_64 (abfd, buf);
14614 /* Cover function for read_initial_length.
14615 Returns the length of the object at BUF, and stores the size of the
14616 initial length in *BYTES_READ and stores the size that offsets will be in
14618 If the initial length size is not equivalent to that specified in
14619 CU_HEADER then issue a complaint.
14620 This is useful when reading non-comp-unit headers. */
14623 read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf,
14624 const struct comp_unit_head *cu_header,
14625 unsigned int *bytes_read,
14626 unsigned int *offset_size)
14628 LONGEST length = read_initial_length (abfd, buf, bytes_read);
14630 gdb_assert (cu_header->initial_length_size == 4
14631 || cu_header->initial_length_size == 8
14632 || cu_header->initial_length_size == 12);
14634 if (cu_header->initial_length_size != *bytes_read)
14635 complaint (&symfile_complaints,
14636 _("intermixed 32-bit and 64-bit DWARF sections"));
14638 *offset_size = (*bytes_read == 4) ? 4 : 8;
14642 /* Read an offset from the data stream. The size of the offset is
14643 given by cu_header->offset_size. */
14646 read_offset (bfd *abfd, const gdb_byte *buf,
14647 const struct comp_unit_head *cu_header,
14648 unsigned int *bytes_read)
14650 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
14652 *bytes_read = cu_header->offset_size;
14656 /* Read an offset from the data stream. */
14659 read_offset_1 (bfd *abfd, const gdb_byte *buf, unsigned int offset_size)
14661 LONGEST retval = 0;
14663 switch (offset_size)
14666 retval = bfd_get_32 (abfd, buf);
14669 retval = bfd_get_64 (abfd, buf);
14672 internal_error (__FILE__, __LINE__,
14673 _("read_offset_1: bad switch [in module %s]"),
14674 bfd_get_filename (abfd));
14680 static const gdb_byte *
14681 read_n_bytes (bfd *abfd, const gdb_byte *buf, unsigned int size)
14683 /* If the size of a host char is 8 bits, we can return a pointer
14684 to the buffer, otherwise we have to copy the data to a buffer
14685 allocated on the temporary obstack. */
14686 gdb_assert (HOST_CHAR_BIT == 8);
14690 static const char *
14691 read_direct_string (bfd *abfd, const gdb_byte *buf,
14692 unsigned int *bytes_read_ptr)
14694 /* If the size of a host char is 8 bits, we can return a pointer
14695 to the string, otherwise we have to copy the string to a buffer
14696 allocated on the temporary obstack. */
14697 gdb_assert (HOST_CHAR_BIT == 8);
14700 *bytes_read_ptr = 1;
14703 *bytes_read_ptr = strlen ((const char *) buf) + 1;
14704 return (const char *) buf;
14707 static const char *
14708 read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
14710 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
14711 if (dwarf2_per_objfile->str.buffer == NULL)
14712 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14713 bfd_get_filename (abfd));
14714 if (str_offset >= dwarf2_per_objfile->str.size)
14715 error (_("DW_FORM_strp pointing outside of "
14716 ".debug_str section [in module %s]"),
14717 bfd_get_filename (abfd));
14718 gdb_assert (HOST_CHAR_BIT == 8);
14719 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
14721 return (const char *) (dwarf2_per_objfile->str.buffer + str_offset);
14724 /* Read a string at offset STR_OFFSET in the .debug_str section from
14725 the .dwz file DWZ. Throw an error if the offset is too large. If
14726 the string consists of a single NUL byte, return NULL; otherwise
14727 return a pointer to the string. */
14729 static const char *
14730 read_indirect_string_from_dwz (struct dwz_file *dwz, LONGEST str_offset)
14732 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwz->str);
14734 if (dwz->str.buffer == NULL)
14735 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14736 "section [in module %s]"),
14737 bfd_get_filename (dwz->dwz_bfd));
14738 if (str_offset >= dwz->str.size)
14739 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14740 ".debug_str section [in module %s]"),
14741 bfd_get_filename (dwz->dwz_bfd));
14742 gdb_assert (HOST_CHAR_BIT == 8);
14743 if (dwz->str.buffer[str_offset] == '\0')
14745 return (const char *) (dwz->str.buffer + str_offset);
14748 static const char *
14749 read_indirect_string (bfd *abfd, const gdb_byte *buf,
14750 const struct comp_unit_head *cu_header,
14751 unsigned int *bytes_read_ptr)
14753 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
14755 return read_indirect_string_at_offset (abfd, str_offset);
14759 read_unsigned_leb128 (bfd *abfd, const gdb_byte *buf,
14760 unsigned int *bytes_read_ptr)
14763 unsigned int num_read;
14765 unsigned char byte;
14773 byte = bfd_get_8 (abfd, buf);
14776 result |= ((ULONGEST) (byte & 127) << shift);
14777 if ((byte & 128) == 0)
14783 *bytes_read_ptr = num_read;
14788 read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
14789 unsigned int *bytes_read_ptr)
14792 int i, shift, num_read;
14793 unsigned char byte;
14801 byte = bfd_get_8 (abfd, buf);
14804 result |= ((LONGEST) (byte & 127) << shift);
14806 if ((byte & 128) == 0)
14811 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
14812 result |= -(((LONGEST) 1) << shift);
14813 *bytes_read_ptr = num_read;
14817 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14818 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14819 ADDR_SIZE is the size of addresses from the CU header. */
14822 read_addr_index_1 (unsigned int addr_index, ULONGEST addr_base, int addr_size)
14824 struct objfile *objfile = dwarf2_per_objfile->objfile;
14825 bfd *abfd = objfile->obfd;
14826 const gdb_byte *info_ptr;
14828 dwarf2_read_section (objfile, &dwarf2_per_objfile->addr);
14829 if (dwarf2_per_objfile->addr.buffer == NULL)
14830 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14832 if (addr_base + addr_index * addr_size >= dwarf2_per_objfile->addr.size)
14833 error (_("DW_FORM_addr_index pointing outside of "
14834 ".debug_addr section [in module %s]"),
14836 info_ptr = (dwarf2_per_objfile->addr.buffer
14837 + addr_base + addr_index * addr_size);
14838 if (addr_size == 4)
14839 return bfd_get_32 (abfd, info_ptr);
14841 return bfd_get_64 (abfd, info_ptr);
14844 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14847 read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index)
14849 return read_addr_index_1 (addr_index, cu->addr_base, cu->header.addr_size);
14852 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14855 read_addr_index_from_leb128 (struct dwarf2_cu *cu, const gdb_byte *info_ptr,
14856 unsigned int *bytes_read)
14858 bfd *abfd = cu->objfile->obfd;
14859 unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
14861 return read_addr_index (cu, addr_index);
14864 /* Data structure to pass results from dwarf2_read_addr_index_reader
14865 back to dwarf2_read_addr_index. */
14867 struct dwarf2_read_addr_index_data
14869 ULONGEST addr_base;
14873 /* die_reader_func for dwarf2_read_addr_index. */
14876 dwarf2_read_addr_index_reader (const struct die_reader_specs *reader,
14877 const gdb_byte *info_ptr,
14878 struct die_info *comp_unit_die,
14882 struct dwarf2_cu *cu = reader->cu;
14883 struct dwarf2_read_addr_index_data *aidata =
14884 (struct dwarf2_read_addr_index_data *) data;
14886 aidata->addr_base = cu->addr_base;
14887 aidata->addr_size = cu->header.addr_size;
14890 /* Given an index in .debug_addr, fetch the value.
14891 NOTE: This can be called during dwarf expression evaluation,
14892 long after the debug information has been read, and thus per_cu->cu
14893 may no longer exist. */
14896 dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
14897 unsigned int addr_index)
14899 struct objfile *objfile = per_cu->objfile;
14900 struct dwarf2_cu *cu = per_cu->cu;
14901 ULONGEST addr_base;
14904 /* This is intended to be called from outside this file. */
14905 dw2_setup (objfile);
14907 /* We need addr_base and addr_size.
14908 If we don't have PER_CU->cu, we have to get it.
14909 Nasty, but the alternative is storing the needed info in PER_CU,
14910 which at this point doesn't seem justified: it's not clear how frequently
14911 it would get used and it would increase the size of every PER_CU.
14912 Entry points like dwarf2_per_cu_addr_size do a similar thing
14913 so we're not in uncharted territory here.
14914 Alas we need to be a bit more complicated as addr_base is contained
14917 We don't need to read the entire CU(/TU).
14918 We just need the header and top level die.
14920 IWBN to use the aging mechanism to let us lazily later discard the CU.
14921 For now we skip this optimization. */
14925 addr_base = cu->addr_base;
14926 addr_size = cu->header.addr_size;
14930 struct dwarf2_read_addr_index_data aidata;
14932 /* Note: We can't use init_cutu_and_read_dies_simple here,
14933 we need addr_base. */
14934 init_cutu_and_read_dies (per_cu, NULL, 0, 0,
14935 dwarf2_read_addr_index_reader, &aidata);
14936 addr_base = aidata.addr_base;
14937 addr_size = aidata.addr_size;
14940 return read_addr_index_1 (addr_index, addr_base, addr_size);
14943 /* Given a DW_AT_str_index, fetch the string. */
14945 static const char *
14946 read_str_index (const struct die_reader_specs *reader,
14947 struct dwarf2_cu *cu, ULONGEST str_index)
14949 struct objfile *objfile = dwarf2_per_objfile->objfile;
14950 const char *dwo_name = objfile->name;
14951 bfd *abfd = objfile->obfd;
14952 struct dwo_sections *sections = &reader->dwo_file->sections;
14953 const gdb_byte *info_ptr;
14954 ULONGEST str_offset;
14956 dwarf2_read_section (objfile, §ions->str);
14957 dwarf2_read_section (objfile, §ions->str_offsets);
14958 if (sections->str.buffer == NULL)
14959 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14960 " in CU at offset 0x%lx [in module %s]"),
14961 (long) cu->header.offset.sect_off, dwo_name);
14962 if (sections->str_offsets.buffer == NULL)
14963 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14964 " in CU at offset 0x%lx [in module %s]"),
14965 (long) cu->header.offset.sect_off, dwo_name);
14966 if (str_index * cu->header.offset_size >= sections->str_offsets.size)
14967 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14968 " section in CU at offset 0x%lx [in module %s]"),
14969 (long) cu->header.offset.sect_off, dwo_name);
14970 info_ptr = (sections->str_offsets.buffer
14971 + str_index * cu->header.offset_size);
14972 if (cu->header.offset_size == 4)
14973 str_offset = bfd_get_32 (abfd, info_ptr);
14975 str_offset = bfd_get_64 (abfd, info_ptr);
14976 if (str_offset >= sections->str.size)
14977 error (_("Offset from DW_FORM_str_index pointing outside of"
14978 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14979 (long) cu->header.offset.sect_off, dwo_name);
14980 return (const char *) (sections->str.buffer + str_offset);
14983 /* Return the length of an LEB128 number in BUF. */
14986 leb128_size (const gdb_byte *buf)
14988 const gdb_byte *begin = buf;
14994 if ((byte & 128) == 0)
14995 return buf - begin;
15000 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
15008 cu->language = language_c;
15010 case DW_LANG_C_plus_plus:
15011 cu->language = language_cplus;
15014 cu->language = language_d;
15016 case DW_LANG_Fortran77:
15017 case DW_LANG_Fortran90:
15018 case DW_LANG_Fortran95:
15019 cu->language = language_fortran;
15022 cu->language = language_go;
15024 case DW_LANG_Mips_Assembler:
15025 cu->language = language_asm;
15028 cu->language = language_java;
15030 case DW_LANG_Ada83:
15031 case DW_LANG_Ada95:
15032 cu->language = language_ada;
15034 case DW_LANG_Modula2:
15035 cu->language = language_m2;
15037 case DW_LANG_Pascal83:
15038 cu->language = language_pascal;
15041 cu->language = language_objc;
15043 case DW_LANG_Cobol74:
15044 case DW_LANG_Cobol85:
15046 cu->language = language_minimal;
15049 cu->language_defn = language_def (cu->language);
15052 /* Return the named attribute or NULL if not there. */
15054 static struct attribute *
15055 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
15060 struct attribute *spec = NULL;
15062 for (i = 0; i < die->num_attrs; ++i)
15064 if (die->attrs[i].name == name)
15065 return &die->attrs[i];
15066 if (die->attrs[i].name == DW_AT_specification
15067 || die->attrs[i].name == DW_AT_abstract_origin)
15068 spec = &die->attrs[i];
15074 die = follow_die_ref (die, spec, &cu);
15080 /* Return the named attribute or NULL if not there,
15081 but do not follow DW_AT_specification, etc.
15082 This is for use in contexts where we're reading .debug_types dies.
15083 Following DW_AT_specification, DW_AT_abstract_origin will take us
15084 back up the chain, and we want to go down. */
15086 static struct attribute *
15087 dwarf2_attr_no_follow (struct die_info *die, unsigned int name)
15091 for (i = 0; i < die->num_attrs; ++i)
15092 if (die->attrs[i].name == name)
15093 return &die->attrs[i];
15098 /* Return non-zero iff the attribute NAME is defined for the given DIE,
15099 and holds a non-zero value. This function should only be used for
15100 DW_FORM_flag or DW_FORM_flag_present attributes. */
15103 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
15105 struct attribute *attr = dwarf2_attr (die, name, cu);
15107 return (attr && DW_UNSND (attr));
15111 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
15113 /* A DIE is a declaration if it has a DW_AT_declaration attribute
15114 which value is non-zero. However, we have to be careful with
15115 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
15116 (via dwarf2_flag_true_p) follows this attribute. So we may
15117 end up accidently finding a declaration attribute that belongs
15118 to a different DIE referenced by the specification attribute,
15119 even though the given DIE does not have a declaration attribute. */
15120 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
15121 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
15124 /* Return the die giving the specification for DIE, if there is
15125 one. *SPEC_CU is the CU containing DIE on input, and the CU
15126 containing the return value on output. If there is no
15127 specification, but there is an abstract origin, that is
15130 static struct die_info *
15131 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
15133 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
15136 if (spec_attr == NULL)
15137 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
15139 if (spec_attr == NULL)
15142 return follow_die_ref (die, spec_attr, spec_cu);
15145 /* Free the line_header structure *LH, and any arrays and strings it
15147 NOTE: This is also used as a "cleanup" function. */
15150 free_line_header (struct line_header *lh)
15152 if (lh->standard_opcode_lengths)
15153 xfree (lh->standard_opcode_lengths);
15155 /* Remember that all the lh->file_names[i].name pointers are
15156 pointers into debug_line_buffer, and don't need to be freed. */
15157 if (lh->file_names)
15158 xfree (lh->file_names);
15160 /* Similarly for the include directory names. */
15161 if (lh->include_dirs)
15162 xfree (lh->include_dirs);
15167 /* Add an entry to LH's include directory table. */
15170 add_include_dir (struct line_header *lh, const char *include_dir)
15172 /* Grow the array if necessary. */
15173 if (lh->include_dirs_size == 0)
15175 lh->include_dirs_size = 1; /* for testing */
15176 lh->include_dirs = xmalloc (lh->include_dirs_size
15177 * sizeof (*lh->include_dirs));
15179 else if (lh->num_include_dirs >= lh->include_dirs_size)
15181 lh->include_dirs_size *= 2;
15182 lh->include_dirs = xrealloc (lh->include_dirs,
15183 (lh->include_dirs_size
15184 * sizeof (*lh->include_dirs)));
15187 lh->include_dirs[lh->num_include_dirs++] = include_dir;
15190 /* Add an entry to LH's file name table. */
15193 add_file_name (struct line_header *lh,
15195 unsigned int dir_index,
15196 unsigned int mod_time,
15197 unsigned int length)
15199 struct file_entry *fe;
15201 /* Grow the array if necessary. */
15202 if (lh->file_names_size == 0)
15204 lh->file_names_size = 1; /* for testing */
15205 lh->file_names = xmalloc (lh->file_names_size
15206 * sizeof (*lh->file_names));
15208 else if (lh->num_file_names >= lh->file_names_size)
15210 lh->file_names_size *= 2;
15211 lh->file_names = xrealloc (lh->file_names,
15212 (lh->file_names_size
15213 * sizeof (*lh->file_names)));
15216 fe = &lh->file_names[lh->num_file_names++];
15218 fe->dir_index = dir_index;
15219 fe->mod_time = mod_time;
15220 fe->length = length;
15221 fe->included_p = 0;
15225 /* A convenience function to find the proper .debug_line section for a
15228 static struct dwarf2_section_info *
15229 get_debug_line_section (struct dwarf2_cu *cu)
15231 struct dwarf2_section_info *section;
15233 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
15235 if (cu->dwo_unit && cu->per_cu->is_debug_types)
15236 section = &cu->dwo_unit->dwo_file->sections.line;
15237 else if (cu->per_cu->is_dwz)
15239 struct dwz_file *dwz = dwarf2_get_dwz_file ();
15241 section = &dwz->line;
15244 section = &dwarf2_per_objfile->line;
15249 /* Read the statement program header starting at OFFSET in
15250 .debug_line, or .debug_line.dwo. Return a pointer
15251 to a struct line_header, allocated using xmalloc.
15253 NOTE: the strings in the include directory and file name tables of
15254 the returned object point into the dwarf line section buffer,
15255 and must not be freed. */
15257 static struct line_header *
15258 dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu)
15260 struct cleanup *back_to;
15261 struct line_header *lh;
15262 const gdb_byte *line_ptr;
15263 unsigned int bytes_read, offset_size;
15265 const char *cur_dir, *cur_file;
15266 struct dwarf2_section_info *section;
15269 section = get_debug_line_section (cu);
15270 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
15271 if (section->buffer == NULL)
15273 if (cu->dwo_unit && cu->per_cu->is_debug_types)
15274 complaint (&symfile_complaints, _("missing .debug_line.dwo section"));
15276 complaint (&symfile_complaints, _("missing .debug_line section"));
15280 /* We can't do this until we know the section is non-empty.
15281 Only then do we know we have such a section. */
15282 abfd = section->asection->owner;
15284 /* Make sure that at least there's room for the total_length field.
15285 That could be 12 bytes long, but we're just going to fudge that. */
15286 if (offset + 4 >= section->size)
15288 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15292 lh = xmalloc (sizeof (*lh));
15293 memset (lh, 0, sizeof (*lh));
15294 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
15297 line_ptr = section->buffer + offset;
15299 /* Read in the header. */
15301 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
15302 &bytes_read, &offset_size);
15303 line_ptr += bytes_read;
15304 if (line_ptr + lh->total_length > (section->buffer + section->size))
15306 dwarf2_statement_list_fits_in_line_number_section_complaint ();
15309 lh->statement_program_end = line_ptr + lh->total_length;
15310 lh->version = read_2_bytes (abfd, line_ptr);
15312 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
15313 line_ptr += offset_size;
15314 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
15316 if (lh->version >= 4)
15318 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
15322 lh->maximum_ops_per_instruction = 1;
15324 if (lh->maximum_ops_per_instruction == 0)
15326 lh->maximum_ops_per_instruction = 1;
15327 complaint (&symfile_complaints,
15328 _("invalid maximum_ops_per_instruction "
15329 "in `.debug_line' section"));
15332 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
15334 lh->line_base = read_1_signed_byte (abfd, line_ptr);
15336 lh->line_range = read_1_byte (abfd, line_ptr);
15338 lh->opcode_base = read_1_byte (abfd, line_ptr);
15340 lh->standard_opcode_lengths
15341 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
15343 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
15344 for (i = 1; i < lh->opcode_base; ++i)
15346 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
15350 /* Read directory table. */
15351 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
15353 line_ptr += bytes_read;
15354 add_include_dir (lh, cur_dir);
15356 line_ptr += bytes_read;
15358 /* Read file name table. */
15359 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
15361 unsigned int dir_index, mod_time, length;
15363 line_ptr += bytes_read;
15364 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15365 line_ptr += bytes_read;
15366 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15367 line_ptr += bytes_read;
15368 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15369 line_ptr += bytes_read;
15371 add_file_name (lh, cur_file, dir_index, mod_time, length);
15373 line_ptr += bytes_read;
15374 lh->statement_program_start = line_ptr;
15376 if (line_ptr > (section->buffer + section->size))
15377 complaint (&symfile_complaints,
15378 _("line number info header doesn't "
15379 "fit in `.debug_line' section"));
15381 discard_cleanups (back_to);
15385 /* Subroutine of dwarf_decode_lines to simplify it.
15386 Return the file name of the psymtab for included file FILE_INDEX
15387 in line header LH of PST.
15388 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15389 If space for the result is malloc'd, it will be freed by a cleanup.
15390 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename.
15392 The function creates dangling cleanup registration. */
15394 static const char *
15395 psymtab_include_file_name (const struct line_header *lh, int file_index,
15396 const struct partial_symtab *pst,
15397 const char *comp_dir)
15399 const struct file_entry fe = lh->file_names [file_index];
15400 const char *include_name = fe.name;
15401 const char *include_name_to_compare = include_name;
15402 const char *dir_name = NULL;
15403 const char *pst_filename;
15404 char *copied_name = NULL;
15408 dir_name = lh->include_dirs[fe.dir_index - 1];
15410 if (!IS_ABSOLUTE_PATH (include_name)
15411 && (dir_name != NULL || comp_dir != NULL))
15413 /* Avoid creating a duplicate psymtab for PST.
15414 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15415 Before we do the comparison, however, we need to account
15416 for DIR_NAME and COMP_DIR.
15417 First prepend dir_name (if non-NULL). If we still don't
15418 have an absolute path prepend comp_dir (if non-NULL).
15419 However, the directory we record in the include-file's
15420 psymtab does not contain COMP_DIR (to match the
15421 corresponding symtab(s)).
15426 bash$ gcc -g ./hello.c
15427 include_name = "hello.c"
15429 DW_AT_comp_dir = comp_dir = "/tmp"
15430 DW_AT_name = "./hello.c" */
15432 if (dir_name != NULL)
15434 char *tem = concat (dir_name, SLASH_STRING,
15435 include_name, (char *)NULL);
15437 make_cleanup (xfree, tem);
15438 include_name = tem;
15439 include_name_to_compare = include_name;
15441 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
15443 char *tem = concat (comp_dir, SLASH_STRING,
15444 include_name, (char *)NULL);
15446 make_cleanup (xfree, tem);
15447 include_name_to_compare = tem;
15451 pst_filename = pst->filename;
15452 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
15454 copied_name = concat (pst->dirname, SLASH_STRING,
15455 pst_filename, (char *)NULL);
15456 pst_filename = copied_name;
15459 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
15461 if (copied_name != NULL)
15462 xfree (copied_name);
15466 return include_name;
15469 /* Ignore this record_line request. */
15472 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
15477 /* Subroutine of dwarf_decode_lines to simplify it.
15478 Process the line number information in LH. */
15481 dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
15482 struct dwarf2_cu *cu, struct partial_symtab *pst)
15484 const gdb_byte *line_ptr, *extended_end;
15485 const gdb_byte *line_end;
15486 unsigned int bytes_read, extended_len;
15487 unsigned char op_code, extended_op, adj_opcode;
15488 CORE_ADDR baseaddr;
15489 struct objfile *objfile = cu->objfile;
15490 bfd *abfd = objfile->obfd;
15491 struct gdbarch *gdbarch = get_objfile_arch (objfile);
15492 const int decode_for_pst_p = (pst != NULL);
15493 struct subfile *last_subfile = NULL;
15494 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
15497 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15499 line_ptr = lh->statement_program_start;
15500 line_end = lh->statement_program_end;
15502 /* Read the statement sequences until there's nothing left. */
15503 while (line_ptr < line_end)
15505 /* state machine registers */
15506 CORE_ADDR address = 0;
15507 unsigned int file = 1;
15508 unsigned int line = 1;
15509 unsigned int column = 0;
15510 int is_stmt = lh->default_is_stmt;
15511 int basic_block = 0;
15512 int end_sequence = 0;
15514 unsigned char op_index = 0;
15516 if (!decode_for_pst_p && lh->num_file_names >= file)
15518 /* Start a subfile for the current file of the state machine. */
15519 /* lh->include_dirs and lh->file_names are 0-based, but the
15520 directory and file name numbers in the statement program
15522 struct file_entry *fe = &lh->file_names[file - 1];
15523 const char *dir = NULL;
15526 dir = lh->include_dirs[fe->dir_index - 1];
15528 dwarf2_start_subfile (fe->name, dir, comp_dir);
15531 /* Decode the table. */
15532 while (!end_sequence)
15534 op_code = read_1_byte (abfd, line_ptr);
15536 if (line_ptr > line_end)
15538 dwarf2_debug_line_missing_end_sequence_complaint ();
15542 if (op_code >= lh->opcode_base)
15544 /* Special operand. */
15545 adj_opcode = op_code - lh->opcode_base;
15546 address += (((op_index + (adj_opcode / lh->line_range))
15547 / lh->maximum_ops_per_instruction)
15548 * lh->minimum_instruction_length);
15549 op_index = ((op_index + (adj_opcode / lh->line_range))
15550 % lh->maximum_ops_per_instruction);
15551 line += lh->line_base + (adj_opcode % lh->line_range);
15552 if (lh->num_file_names < file || file == 0)
15553 dwarf2_debug_line_missing_file_complaint ();
15554 /* For now we ignore lines not starting on an
15555 instruction boundary. */
15556 else if (op_index == 0)
15558 lh->file_names[file - 1].included_p = 1;
15559 if (!decode_for_pst_p && is_stmt)
15561 if (last_subfile != current_subfile)
15563 addr = gdbarch_addr_bits_remove (gdbarch, address);
15565 (*p_record_line) (last_subfile, 0, addr);
15566 last_subfile = current_subfile;
15568 /* Append row to matrix using current values. */
15569 addr = gdbarch_addr_bits_remove (gdbarch, address);
15570 (*p_record_line) (current_subfile, line, addr);
15575 else switch (op_code)
15577 case DW_LNS_extended_op:
15578 extended_len = read_unsigned_leb128 (abfd, line_ptr,
15580 line_ptr += bytes_read;
15581 extended_end = line_ptr + extended_len;
15582 extended_op = read_1_byte (abfd, line_ptr);
15584 switch (extended_op)
15586 case DW_LNE_end_sequence:
15587 p_record_line = record_line;
15590 case DW_LNE_set_address:
15591 address = read_address (abfd, line_ptr, cu, &bytes_read);
15593 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
15595 /* This line table is for a function which has been
15596 GCd by the linker. Ignore it. PR gdb/12528 */
15599 = line_ptr - get_debug_line_section (cu)->buffer;
15601 complaint (&symfile_complaints,
15602 _(".debug_line address at offset 0x%lx is 0 "
15604 line_offset, objfile->name);
15605 p_record_line = noop_record_line;
15609 line_ptr += bytes_read;
15610 address += baseaddr;
15612 case DW_LNE_define_file:
15614 const char *cur_file;
15615 unsigned int dir_index, mod_time, length;
15617 cur_file = read_direct_string (abfd, line_ptr,
15619 line_ptr += bytes_read;
15621 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15622 line_ptr += bytes_read;
15624 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15625 line_ptr += bytes_read;
15627 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15628 line_ptr += bytes_read;
15629 add_file_name (lh, cur_file, dir_index, mod_time, length);
15632 case DW_LNE_set_discriminator:
15633 /* The discriminator is not interesting to the debugger;
15635 line_ptr = extended_end;
15638 complaint (&symfile_complaints,
15639 _("mangled .debug_line section"));
15642 /* Make sure that we parsed the extended op correctly. If e.g.
15643 we expected a different address size than the producer used,
15644 we may have read the wrong number of bytes. */
15645 if (line_ptr != extended_end)
15647 complaint (&symfile_complaints,
15648 _("mangled .debug_line section"));
15653 if (lh->num_file_names < file || file == 0)
15654 dwarf2_debug_line_missing_file_complaint ();
15657 lh->file_names[file - 1].included_p = 1;
15658 if (!decode_for_pst_p && is_stmt)
15660 if (last_subfile != current_subfile)
15662 addr = gdbarch_addr_bits_remove (gdbarch, address);
15664 (*p_record_line) (last_subfile, 0, addr);
15665 last_subfile = current_subfile;
15667 addr = gdbarch_addr_bits_remove (gdbarch, address);
15668 (*p_record_line) (current_subfile, line, addr);
15673 case DW_LNS_advance_pc:
15676 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15678 address += (((op_index + adjust)
15679 / lh->maximum_ops_per_instruction)
15680 * lh->minimum_instruction_length);
15681 op_index = ((op_index + adjust)
15682 % lh->maximum_ops_per_instruction);
15683 line_ptr += bytes_read;
15686 case DW_LNS_advance_line:
15687 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
15688 line_ptr += bytes_read;
15690 case DW_LNS_set_file:
15692 /* The arrays lh->include_dirs and lh->file_names are
15693 0-based, but the directory and file name numbers in
15694 the statement program are 1-based. */
15695 struct file_entry *fe;
15696 const char *dir = NULL;
15698 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15699 line_ptr += bytes_read;
15700 if (lh->num_file_names < file || file == 0)
15701 dwarf2_debug_line_missing_file_complaint ();
15704 fe = &lh->file_names[file - 1];
15706 dir = lh->include_dirs[fe->dir_index - 1];
15707 if (!decode_for_pst_p)
15709 last_subfile = current_subfile;
15710 dwarf2_start_subfile (fe->name, dir, comp_dir);
15715 case DW_LNS_set_column:
15716 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15717 line_ptr += bytes_read;
15719 case DW_LNS_negate_stmt:
15720 is_stmt = (!is_stmt);
15722 case DW_LNS_set_basic_block:
15725 /* Add to the address register of the state machine the
15726 address increment value corresponding to special opcode
15727 255. I.e., this value is scaled by the minimum
15728 instruction length since special opcode 255 would have
15729 scaled the increment. */
15730 case DW_LNS_const_add_pc:
15732 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
15734 address += (((op_index + adjust)
15735 / lh->maximum_ops_per_instruction)
15736 * lh->minimum_instruction_length);
15737 op_index = ((op_index + adjust)
15738 % lh->maximum_ops_per_instruction);
15741 case DW_LNS_fixed_advance_pc:
15742 address += read_2_bytes (abfd, line_ptr);
15748 /* Unknown standard opcode, ignore it. */
15751 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
15753 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15754 line_ptr += bytes_read;
15759 if (lh->num_file_names < file || file == 0)
15760 dwarf2_debug_line_missing_file_complaint ();
15763 lh->file_names[file - 1].included_p = 1;
15764 if (!decode_for_pst_p)
15766 addr = gdbarch_addr_bits_remove (gdbarch, address);
15767 (*p_record_line) (current_subfile, 0, addr);
15773 /* Decode the Line Number Program (LNP) for the given line_header
15774 structure and CU. The actual information extracted and the type
15775 of structures created from the LNP depends on the value of PST.
15777 1. If PST is NULL, then this procedure uses the data from the program
15778 to create all necessary symbol tables, and their linetables.
15780 2. If PST is not NULL, this procedure reads the program to determine
15781 the list of files included by the unit represented by PST, and
15782 builds all the associated partial symbol tables.
15784 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15785 It is used for relative paths in the line table.
15786 NOTE: When processing partial symtabs (pst != NULL),
15787 comp_dir == pst->dirname.
15789 NOTE: It is important that psymtabs have the same file name (via strcmp)
15790 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15791 symtab we don't use it in the name of the psymtabs we create.
15792 E.g. expand_line_sal requires this when finding psymtabs to expand.
15793 A good testcase for this is mb-inline.exp. */
15796 dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
15797 struct dwarf2_cu *cu, struct partial_symtab *pst,
15798 int want_line_info)
15800 struct objfile *objfile = cu->objfile;
15801 const int decode_for_pst_p = (pst != NULL);
15802 struct subfile *first_subfile = current_subfile;
15804 if (want_line_info)
15805 dwarf_decode_lines_1 (lh, comp_dir, cu, pst);
15807 if (decode_for_pst_p)
15811 /* Now that we're done scanning the Line Header Program, we can
15812 create the psymtab of each included file. */
15813 for (file_index = 0; file_index < lh->num_file_names; file_index++)
15814 if (lh->file_names[file_index].included_p == 1)
15816 const char *include_name =
15817 psymtab_include_file_name (lh, file_index, pst, comp_dir);
15818 if (include_name != NULL)
15819 dwarf2_create_include_psymtab (include_name, pst, objfile);
15824 /* Make sure a symtab is created for every file, even files
15825 which contain only variables (i.e. no code with associated
15829 for (i = 0; i < lh->num_file_names; i++)
15831 const char *dir = NULL;
15832 struct file_entry *fe;
15834 fe = &lh->file_names[i];
15836 dir = lh->include_dirs[fe->dir_index - 1];
15837 dwarf2_start_subfile (fe->name, dir, comp_dir);
15839 /* Skip the main file; we don't need it, and it must be
15840 allocated last, so that it will show up before the
15841 non-primary symtabs in the objfile's symtab list. */
15842 if (current_subfile == first_subfile)
15845 if (current_subfile->symtab == NULL)
15846 current_subfile->symtab = allocate_symtab (current_subfile->name,
15848 fe->symtab = current_subfile->symtab;
15853 /* Start a subfile for DWARF. FILENAME is the name of the file and
15854 DIRNAME the name of the source directory which contains FILENAME
15855 or NULL if not known. COMP_DIR is the compilation directory for the
15856 linetable's compilation unit or NULL if not known.
15857 This routine tries to keep line numbers from identical absolute and
15858 relative file names in a common subfile.
15860 Using the `list' example from the GDB testsuite, which resides in
15861 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15862 of /srcdir/list0.c yields the following debugging information for list0.c:
15864 DW_AT_name: /srcdir/list0.c
15865 DW_AT_comp_dir: /compdir
15866 files.files[0].name: list0.h
15867 files.files[0].dir: /srcdir
15868 files.files[1].name: list0.c
15869 files.files[1].dir: /srcdir
15871 The line number information for list0.c has to end up in a single
15872 subfile, so that `break /srcdir/list0.c:1' works as expected.
15873 start_subfile will ensure that this happens provided that we pass the
15874 concatenation of files.files[1].dir and files.files[1].name as the
15878 dwarf2_start_subfile (const char *filename, const char *dirname,
15879 const char *comp_dir)
15883 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15884 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15885 second argument to start_subfile. To be consistent, we do the
15886 same here. In order not to lose the line information directory,
15887 we concatenate it to the filename when it makes sense.
15888 Note that the Dwarf3 standard says (speaking of filenames in line
15889 information): ``The directory index is ignored for file names
15890 that represent full path names''. Thus ignoring dirname in the
15891 `else' branch below isn't an issue. */
15893 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
15895 copy = concat (dirname, SLASH_STRING, filename, (char *)NULL);
15899 start_subfile (filename, comp_dir);
15905 /* Start a symtab for DWARF.
15906 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15909 dwarf2_start_symtab (struct dwarf2_cu *cu,
15910 const char *name, const char *comp_dir, CORE_ADDR low_pc)
15912 start_symtab (name, comp_dir, low_pc);
15913 record_debugformat ("DWARF 2");
15914 record_producer (cu->producer);
15916 /* We assume that we're processing GCC output. */
15917 processing_gcc_compilation = 2;
15919 cu->processing_has_namespace_info = 0;
15923 var_decode_location (struct attribute *attr, struct symbol *sym,
15924 struct dwarf2_cu *cu)
15926 struct objfile *objfile = cu->objfile;
15927 struct comp_unit_head *cu_header = &cu->header;
15929 /* NOTE drow/2003-01-30: There used to be a comment and some special
15930 code here to turn a symbol with DW_AT_external and a
15931 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15932 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15933 with some versions of binutils) where shared libraries could have
15934 relocations against symbols in their debug information - the
15935 minimal symbol would have the right address, but the debug info
15936 would not. It's no longer necessary, because we will explicitly
15937 apply relocations when we read in the debug information now. */
15939 /* A DW_AT_location attribute with no contents indicates that a
15940 variable has been optimized away. */
15941 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
15943 SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
15947 /* Handle one degenerate form of location expression specially, to
15948 preserve GDB's previous behavior when section offsets are
15949 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15950 then mark this symbol as LOC_STATIC. */
15952 if (attr_form_is_block (attr)
15953 && ((DW_BLOCK (attr)->data[0] == DW_OP_addr
15954 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size)
15955 || (DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index
15956 && (DW_BLOCK (attr)->size
15957 == 1 + leb128_size (&DW_BLOCK (attr)->data[1])))))
15959 unsigned int dummy;
15961 if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
15962 SYMBOL_VALUE_ADDRESS (sym) =
15963 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
15965 SYMBOL_VALUE_ADDRESS (sym) =
15966 read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy);
15967 SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
15968 fixup_symbol_section (sym, objfile);
15969 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
15970 SYMBOL_SECTION (sym));
15974 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15975 expression evaluator, and use LOC_COMPUTED only when necessary
15976 (i.e. when the value of a register or memory location is
15977 referenced, or a thread-local block, etc.). Then again, it might
15978 not be worthwhile. I'm assuming that it isn't unless performance
15979 or memory numbers show me otherwise. */
15981 dwarf2_symbol_mark_computed (attr, sym, cu, 0);
15983 if (SYMBOL_COMPUTED_OPS (sym)->location_has_loclist)
15984 cu->has_loclist = 1;
15987 /* Given a pointer to a DWARF information entry, figure out if we need
15988 to make a symbol table entry for it, and if so, create a new entry
15989 and return a pointer to it.
15990 If TYPE is NULL, determine symbol type from the die, otherwise
15991 used the passed type.
15992 If SPACE is not NULL, use it to hold the new symbol. If it is
15993 NULL, allocate a new symbol on the objfile's obstack. */
15995 static struct symbol *
15996 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
15997 struct symbol *space)
15999 struct objfile *objfile = cu->objfile;
16000 struct symbol *sym = NULL;
16002 struct attribute *attr = NULL;
16003 struct attribute *attr2 = NULL;
16004 CORE_ADDR baseaddr;
16005 struct pending **list_to_add = NULL;
16007 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
16009 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
16011 name = dwarf2_name (die, cu);
16014 const char *linkagename;
16015 int suppress_add = 0;
16020 sym = allocate_symbol (objfile);
16021 OBJSTAT (objfile, n_syms++);
16023 /* Cache this symbol's name and the name's demangled form (if any). */
16024 SYMBOL_SET_LANGUAGE (sym, cu->language, &objfile->objfile_obstack);
16025 linkagename = dwarf2_physname (name, die, cu);
16026 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
16028 /* Fortran does not have mangling standard and the mangling does differ
16029 between gfortran, iFort etc. */
16030 if (cu->language == language_fortran
16031 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
16032 symbol_set_demangled_name (&(sym->ginfo),
16033 dwarf2_full_name (name, die, cu),
16036 /* Default assumptions.
16037 Use the passed type or decode it from the die. */
16038 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
16039 SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
16041 SYMBOL_TYPE (sym) = type;
16043 SYMBOL_TYPE (sym) = die_type (die, cu);
16044 attr = dwarf2_attr (die,
16045 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
16049 SYMBOL_LINE (sym) = DW_UNSND (attr);
16052 attr = dwarf2_attr (die,
16053 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
16057 int file_index = DW_UNSND (attr);
16059 if (cu->line_header == NULL
16060 || file_index > cu->line_header->num_file_names)
16061 complaint (&symfile_complaints,
16062 _("file index out of range"));
16063 else if (file_index > 0)
16065 struct file_entry *fe;
16067 fe = &cu->line_header->file_names[file_index - 1];
16068 SYMBOL_SYMTAB (sym) = fe->symtab;
16075 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
16078 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
16080 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
16081 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
16082 SYMBOL_ACLASS_INDEX (sym) = LOC_LABEL;
16083 add_symbol_to_list (sym, cu->list_in_scope);
16085 case DW_TAG_subprogram:
16086 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
16088 SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
16089 attr2 = dwarf2_attr (die, DW_AT_external, cu);
16090 if ((attr2 && (DW_UNSND (attr2) != 0))
16091 || cu->language == language_ada)
16093 /* Subprograms marked external are stored as a global symbol.
16094 Ada subprograms, whether marked external or not, are always
16095 stored as a global symbol, because we want to be able to
16096 access them globally. For instance, we want to be able
16097 to break on a nested subprogram without having to
16098 specify the context. */
16099 list_to_add = &global_symbols;
16103 list_to_add = cu->list_in_scope;
16106 case DW_TAG_inlined_subroutine:
16107 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
16109 SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
16110 SYMBOL_INLINED (sym) = 1;
16111 list_to_add = cu->list_in_scope;
16113 case DW_TAG_template_value_param:
16115 /* Fall through. */
16116 case DW_TAG_constant:
16117 case DW_TAG_variable:
16118 case DW_TAG_member:
16119 /* Compilation with minimal debug info may result in
16120 variables with missing type entries. Change the
16121 misleading `void' type to something sensible. */
16122 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
16124 = objfile_type (objfile)->nodebug_data_symbol;
16126 attr = dwarf2_attr (die, DW_AT_const_value, cu);
16127 /* In the case of DW_TAG_member, we should only be called for
16128 static const members. */
16129 if (die->tag == DW_TAG_member)
16131 /* dwarf2_add_field uses die_is_declaration,
16132 so we do the same. */
16133 gdb_assert (die_is_declaration (die, cu));
16138 dwarf2_const_value (attr, sym, cu);
16139 attr2 = dwarf2_attr (die, DW_AT_external, cu);
16142 if (attr2 && (DW_UNSND (attr2) != 0))
16143 list_to_add = &global_symbols;
16145 list_to_add = cu->list_in_scope;
16149 attr = dwarf2_attr (die, DW_AT_location, cu);
16152 var_decode_location (attr, sym, cu);
16153 attr2 = dwarf2_attr (die, DW_AT_external, cu);
16155 /* Fortran explicitly imports any global symbols to the local
16156 scope by DW_TAG_common_block. */
16157 if (cu->language == language_fortran && die->parent
16158 && die->parent->tag == DW_TAG_common_block)
16161 if (SYMBOL_CLASS (sym) == LOC_STATIC
16162 && SYMBOL_VALUE_ADDRESS (sym) == 0
16163 && !dwarf2_per_objfile->has_section_at_zero)
16165 /* When a static variable is eliminated by the linker,
16166 the corresponding debug information is not stripped
16167 out, but the variable address is set to null;
16168 do not add such variables into symbol table. */
16170 else if (attr2 && (DW_UNSND (attr2) != 0))
16172 /* Workaround gfortran PR debug/40040 - it uses
16173 DW_AT_location for variables in -fPIC libraries which may
16174 get overriden by other libraries/executable and get
16175 a different address. Resolve it by the minimal symbol
16176 which may come from inferior's executable using copy
16177 relocation. Make this workaround only for gfortran as for
16178 other compilers GDB cannot guess the minimal symbol
16179 Fortran mangling kind. */
16180 if (cu->language == language_fortran && die->parent
16181 && die->parent->tag == DW_TAG_module
16183 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
16184 SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
16186 /* A variable with DW_AT_external is never static,
16187 but it may be block-scoped. */
16188 list_to_add = (cu->list_in_scope == &file_symbols
16189 ? &global_symbols : cu->list_in_scope);
16192 list_to_add = cu->list_in_scope;
16196 /* We do not know the address of this symbol.
16197 If it is an external symbol and we have type information
16198 for it, enter the symbol as a LOC_UNRESOLVED symbol.
16199 The address of the variable will then be determined from
16200 the minimal symbol table whenever the variable is
16202 attr2 = dwarf2_attr (die, DW_AT_external, cu);
16204 /* Fortran explicitly imports any global symbols to the local
16205 scope by DW_TAG_common_block. */
16206 if (cu->language == language_fortran && die->parent
16207 && die->parent->tag == DW_TAG_common_block)
16209 /* SYMBOL_CLASS doesn't matter here because
16210 read_common_block is going to reset it. */
16212 list_to_add = cu->list_in_scope;
16214 else if (attr2 && (DW_UNSND (attr2) != 0)
16215 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
16217 /* A variable with DW_AT_external is never static, but it
16218 may be block-scoped. */
16219 list_to_add = (cu->list_in_scope == &file_symbols
16220 ? &global_symbols : cu->list_in_scope);
16222 SYMBOL_ACLASS_INDEX (sym) = LOC_UNRESOLVED;
16224 else if (!die_is_declaration (die, cu))
16226 /* Use the default LOC_OPTIMIZED_OUT class. */
16227 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
16229 list_to_add = cu->list_in_scope;
16233 case DW_TAG_formal_parameter:
16234 /* If we are inside a function, mark this as an argument. If
16235 not, we might be looking at an argument to an inlined function
16236 when we do not have enough information to show inlined frames;
16237 pretend it's a local variable in that case so that the user can
16239 if (context_stack_depth > 0
16240 && context_stack[context_stack_depth - 1].name != NULL)
16241 SYMBOL_IS_ARGUMENT (sym) = 1;
16242 attr = dwarf2_attr (die, DW_AT_location, cu);
16245 var_decode_location (attr, sym, cu);
16247 attr = dwarf2_attr (die, DW_AT_const_value, cu);
16250 dwarf2_const_value (attr, sym, cu);
16253 list_to_add = cu->list_in_scope;
16255 case DW_TAG_unspecified_parameters:
16256 /* From varargs functions; gdb doesn't seem to have any
16257 interest in this information, so just ignore it for now.
16260 case DW_TAG_template_type_param:
16262 /* Fall through. */
16263 case DW_TAG_class_type:
16264 case DW_TAG_interface_type:
16265 case DW_TAG_structure_type:
16266 case DW_TAG_union_type:
16267 case DW_TAG_set_type:
16268 case DW_TAG_enumeration_type:
16269 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
16270 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
16273 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
16274 really ever be static objects: otherwise, if you try
16275 to, say, break of a class's method and you're in a file
16276 which doesn't mention that class, it won't work unless
16277 the check for all static symbols in lookup_symbol_aux
16278 saves you. See the OtherFileClass tests in
16279 gdb.c++/namespace.exp. */
16283 list_to_add = (cu->list_in_scope == &file_symbols
16284 && (cu->language == language_cplus
16285 || cu->language == language_java)
16286 ? &global_symbols : cu->list_in_scope);
16288 /* The semantics of C++ state that "struct foo {
16289 ... }" also defines a typedef for "foo". A Java
16290 class declaration also defines a typedef for the
16292 if (cu->language == language_cplus
16293 || cu->language == language_java
16294 || cu->language == language_ada)
16296 /* The symbol's name is already allocated along
16297 with this objfile, so we don't need to
16298 duplicate it for the type. */
16299 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
16300 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
16305 case DW_TAG_typedef:
16306 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
16307 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
16308 list_to_add = cu->list_in_scope;
16310 case DW_TAG_base_type:
16311 case DW_TAG_subrange_type:
16312 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
16313 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
16314 list_to_add = cu->list_in_scope;
16316 case DW_TAG_enumerator:
16317 attr = dwarf2_attr (die, DW_AT_const_value, cu);
16320 dwarf2_const_value (attr, sym, cu);
16323 /* NOTE: carlton/2003-11-10: See comment above in the
16324 DW_TAG_class_type, etc. block. */
16326 list_to_add = (cu->list_in_scope == &file_symbols
16327 && (cu->language == language_cplus
16328 || cu->language == language_java)
16329 ? &global_symbols : cu->list_in_scope);
16332 case DW_TAG_namespace:
16333 SYMBOL_ACLASS_INDEX (sym) = LOC_TYPEDEF;
16334 list_to_add = &global_symbols;
16336 case DW_TAG_common_block:
16337 SYMBOL_ACLASS_INDEX (sym) = LOC_COMMON_BLOCK;
16338 SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
16339 add_symbol_to_list (sym, cu->list_in_scope);
16342 /* Not a tag we recognize. Hopefully we aren't processing
16343 trash data, but since we must specifically ignore things
16344 we don't recognize, there is nothing else we should do at
16346 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
16347 dwarf_tag_name (die->tag));
16353 sym->hash_next = objfile->template_symbols;
16354 objfile->template_symbols = sym;
16355 list_to_add = NULL;
16358 if (list_to_add != NULL)
16359 add_symbol_to_list (sym, list_to_add);
16361 /* For the benefit of old versions of GCC, check for anonymous
16362 namespaces based on the demangled name. */
16363 if (!cu->processing_has_namespace_info
16364 && cu->language == language_cplus)
16365 cp_scan_for_anonymous_namespaces (sym, objfile);
16370 /* A wrapper for new_symbol_full that always allocates a new symbol. */
16372 static struct symbol *
16373 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
16375 return new_symbol_full (die, type, cu, NULL);
16378 /* Given an attr with a DW_FORM_dataN value in host byte order,
16379 zero-extend it as appropriate for the symbol's type. The DWARF
16380 standard (v4) is not entirely clear about the meaning of using
16381 DW_FORM_dataN for a constant with a signed type, where the type is
16382 wider than the data. The conclusion of a discussion on the DWARF
16383 list was that this is unspecified. We choose to always zero-extend
16384 because that is the interpretation long in use by GCC. */
16387 dwarf2_const_value_data (struct attribute *attr, struct obstack *obstack,
16388 struct dwarf2_cu *cu, LONGEST *value, int bits)
16390 struct objfile *objfile = cu->objfile;
16391 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
16392 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
16393 LONGEST l = DW_UNSND (attr);
16395 if (bits < sizeof (*value) * 8)
16397 l &= ((LONGEST) 1 << bits) - 1;
16400 else if (bits == sizeof (*value) * 8)
16404 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
16405 store_unsigned_integer (bytes, bits / 8, byte_order, l);
16412 /* Read a constant value from an attribute. Either set *VALUE, or if
16413 the value does not fit in *VALUE, set *BYTES - either already
16414 allocated on the objfile obstack, or newly allocated on OBSTACK,
16415 or, set *BATON, if we translated the constant to a location
16419 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
16420 const char *name, struct obstack *obstack,
16421 struct dwarf2_cu *cu,
16422 LONGEST *value, const gdb_byte **bytes,
16423 struct dwarf2_locexpr_baton **baton)
16425 struct objfile *objfile = cu->objfile;
16426 struct comp_unit_head *cu_header = &cu->header;
16427 struct dwarf_block *blk;
16428 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
16429 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
16435 switch (attr->form)
16438 case DW_FORM_GNU_addr_index:
16442 if (TYPE_LENGTH (type) != cu_header->addr_size)
16443 dwarf2_const_value_length_mismatch_complaint (name,
16444 cu_header->addr_size,
16445 TYPE_LENGTH (type));
16446 /* Symbols of this form are reasonably rare, so we just
16447 piggyback on the existing location code rather than writing
16448 a new implementation of symbol_computed_ops. */
16449 *baton = obstack_alloc (obstack, sizeof (struct dwarf2_locexpr_baton));
16450 (*baton)->per_cu = cu->per_cu;
16451 gdb_assert ((*baton)->per_cu);
16453 (*baton)->size = 2 + cu_header->addr_size;
16454 data = obstack_alloc (obstack, (*baton)->size);
16455 (*baton)->data = data;
16457 data[0] = DW_OP_addr;
16458 store_unsigned_integer (&data[1], cu_header->addr_size,
16459 byte_order, DW_ADDR (attr));
16460 data[cu_header->addr_size + 1] = DW_OP_stack_value;
16463 case DW_FORM_string:
16465 case DW_FORM_GNU_str_index:
16466 case DW_FORM_GNU_strp_alt:
16467 /* DW_STRING is already allocated on the objfile obstack, point
16469 *bytes = (const gdb_byte *) DW_STRING (attr);
16471 case DW_FORM_block1:
16472 case DW_FORM_block2:
16473 case DW_FORM_block4:
16474 case DW_FORM_block:
16475 case DW_FORM_exprloc:
16476 blk = DW_BLOCK (attr);
16477 if (TYPE_LENGTH (type) != blk->size)
16478 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
16479 TYPE_LENGTH (type));
16480 *bytes = blk->data;
16483 /* The DW_AT_const_value attributes are supposed to carry the
16484 symbol's value "represented as it would be on the target
16485 architecture." By the time we get here, it's already been
16486 converted to host endianness, so we just need to sign- or
16487 zero-extend it as appropriate. */
16488 case DW_FORM_data1:
16489 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 8);
16491 case DW_FORM_data2:
16492 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 16);
16494 case DW_FORM_data4:
16495 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 32);
16497 case DW_FORM_data8:
16498 *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 64);
16501 case DW_FORM_sdata:
16502 *value = DW_SND (attr);
16505 case DW_FORM_udata:
16506 *value = DW_UNSND (attr);
16510 complaint (&symfile_complaints,
16511 _("unsupported const value attribute form: '%s'"),
16512 dwarf_form_name (attr->form));
16519 /* Copy constant value from an attribute to a symbol. */
16522 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
16523 struct dwarf2_cu *cu)
16525 struct objfile *objfile = cu->objfile;
16526 struct comp_unit_head *cu_header = &cu->header;
16528 const gdb_byte *bytes;
16529 struct dwarf2_locexpr_baton *baton;
16531 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
16532 SYMBOL_PRINT_NAME (sym),
16533 &objfile->objfile_obstack, cu,
16534 &value, &bytes, &baton);
16538 SYMBOL_LOCATION_BATON (sym) = baton;
16539 SYMBOL_ACLASS_INDEX (sym) = dwarf2_locexpr_index;
16541 else if (bytes != NULL)
16543 SYMBOL_VALUE_BYTES (sym) = bytes;
16544 SYMBOL_ACLASS_INDEX (sym) = LOC_CONST_BYTES;
16548 SYMBOL_VALUE (sym) = value;
16549 SYMBOL_ACLASS_INDEX (sym) = LOC_CONST;
16553 /* Return the type of the die in question using its DW_AT_type attribute. */
16555 static struct type *
16556 die_type (struct die_info *die, struct dwarf2_cu *cu)
16558 struct attribute *type_attr;
16560 type_attr = dwarf2_attr (die, DW_AT_type, cu);
16563 /* A missing DW_AT_type represents a void type. */
16564 return objfile_type (cu->objfile)->builtin_void;
16567 return lookup_die_type (die, type_attr, cu);
16570 /* True iff CU's producer generates GNAT Ada auxiliary information
16571 that allows to find parallel types through that information instead
16572 of having to do expensive parallel lookups by type name. */
16575 need_gnat_info (struct dwarf2_cu *cu)
16577 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16578 of GNAT produces this auxiliary information, without any indication
16579 that it is produced. Part of enhancing the FSF version of GNAT
16580 to produce that information will be to put in place an indicator
16581 that we can use in order to determine whether the descriptive type
16582 info is available or not. One suggestion that has been made is
16583 to use a new attribute, attached to the CU die. For now, assume
16584 that the descriptive type info is not available. */
16588 /* Return the auxiliary type of the die in question using its
16589 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16590 attribute is not present. */
16592 static struct type *
16593 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
16595 struct attribute *type_attr;
16597 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
16601 return lookup_die_type (die, type_attr, cu);
16604 /* If DIE has a descriptive_type attribute, then set the TYPE's
16605 descriptive type accordingly. */
16608 set_descriptive_type (struct type *type, struct die_info *die,
16609 struct dwarf2_cu *cu)
16611 struct type *descriptive_type = die_descriptive_type (die, cu);
16613 if (descriptive_type)
16615 ALLOCATE_GNAT_AUX_TYPE (type);
16616 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
16620 /* Return the containing type of the die in question using its
16621 DW_AT_containing_type attribute. */
16623 static struct type *
16624 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
16626 struct attribute *type_attr;
16628 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
16630 error (_("Dwarf Error: Problem turning containing type into gdb type "
16631 "[in module %s]"), cu->objfile->name);
16633 return lookup_die_type (die, type_attr, cu);
16636 /* Return an error marker type to use for the ill formed type in DIE/CU. */
16638 static struct type *
16639 build_error_marker_type (struct dwarf2_cu *cu, struct die_info *die)
16641 struct objfile *objfile = dwarf2_per_objfile->objfile;
16642 char *message, *saved;
16644 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16646 cu->header.offset.sect_off,
16647 die->offset.sect_off);
16648 saved = obstack_copy0 (&objfile->objfile_obstack,
16649 message, strlen (message));
16652 return init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
16655 /* Look up the type of DIE in CU using its type attribute ATTR.
16656 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
16657 DW_AT_containing_type.
16658 If there is no type substitute an error marker. */
16660 static struct type *
16661 lookup_die_type (struct die_info *die, struct attribute *attr,
16662 struct dwarf2_cu *cu)
16664 struct objfile *objfile = cu->objfile;
16665 struct type *this_type;
16667 gdb_assert (attr->name == DW_AT_type
16668 || attr->name == DW_AT_GNAT_descriptive_type
16669 || attr->name == DW_AT_containing_type);
16671 /* First see if we have it cached. */
16673 if (attr->form == DW_FORM_GNU_ref_alt)
16675 struct dwarf2_per_cu_data *per_cu;
16676 sect_offset offset = dwarf2_get_ref_die_offset (attr);
16678 per_cu = dwarf2_find_containing_comp_unit (offset, 1, cu->objfile);
16679 this_type = get_die_type_at_offset (offset, per_cu);
16681 else if (is_ref_attr (attr))
16683 sect_offset offset = dwarf2_get_ref_die_offset (attr);
16685 this_type = get_die_type_at_offset (offset, cu->per_cu);
16687 else if (attr->form == DW_FORM_ref_sig8)
16689 ULONGEST signature = DW_SIGNATURE (attr);
16691 return get_signatured_type (die, signature, cu);
16695 complaint (&symfile_complaints,
16696 _("Dwarf Error: Bad type attribute %s in DIE"
16697 " at 0x%x [in module %s]"),
16698 dwarf_attr_name (attr->name), die->offset.sect_off,
16700 return build_error_marker_type (cu, die);
16703 /* If not cached we need to read it in. */
16705 if (this_type == NULL)
16707 struct die_info *type_die = NULL;
16708 struct dwarf2_cu *type_cu = cu;
16710 if (is_ref_attr (attr))
16711 type_die = follow_die_ref (die, attr, &type_cu);
16712 if (type_die == NULL)
16713 return build_error_marker_type (cu, die);
16714 /* If we find the type now, it's probably because the type came
16715 from an inter-CU reference and the type's CU got expanded before
16717 this_type = read_type_die (type_die, type_cu);
16720 /* If we still don't have a type use an error marker. */
16722 if (this_type == NULL)
16723 return build_error_marker_type (cu, die);
16728 /* Return the type in DIE, CU.
16729 Returns NULL for invalid types.
16731 This first does a lookup in die_type_hash,
16732 and only reads the die in if necessary.
16734 NOTE: This can be called when reading in partial or full symbols. */
16736 static struct type *
16737 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
16739 struct type *this_type;
16741 this_type = get_die_type (die, cu);
16745 return read_type_die_1 (die, cu);
16748 /* Read the type in DIE, CU.
16749 Returns NULL for invalid types. */
16751 static struct type *
16752 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
16754 struct type *this_type = NULL;
16758 case DW_TAG_class_type:
16759 case DW_TAG_interface_type:
16760 case DW_TAG_structure_type:
16761 case DW_TAG_union_type:
16762 this_type = read_structure_type (die, cu);
16764 case DW_TAG_enumeration_type:
16765 this_type = read_enumeration_type (die, cu);
16767 case DW_TAG_subprogram:
16768 case DW_TAG_subroutine_type:
16769 case DW_TAG_inlined_subroutine:
16770 this_type = read_subroutine_type (die, cu);
16772 case DW_TAG_array_type:
16773 this_type = read_array_type (die, cu);
16775 case DW_TAG_set_type:
16776 this_type = read_set_type (die, cu);
16778 case DW_TAG_pointer_type:
16779 this_type = read_tag_pointer_type (die, cu);
16781 case DW_TAG_ptr_to_member_type:
16782 this_type = read_tag_ptr_to_member_type (die, cu);
16784 case DW_TAG_reference_type:
16785 this_type = read_tag_reference_type (die, cu);
16787 case DW_TAG_const_type:
16788 this_type = read_tag_const_type (die, cu);
16790 case DW_TAG_volatile_type:
16791 this_type = read_tag_volatile_type (die, cu);
16793 case DW_TAG_restrict_type:
16794 this_type = read_tag_restrict_type (die, cu);
16796 case DW_TAG_string_type:
16797 this_type = read_tag_string_type (die, cu);
16799 case DW_TAG_typedef:
16800 this_type = read_typedef (die, cu);
16802 case DW_TAG_subrange_type:
16803 this_type = read_subrange_type (die, cu);
16805 case DW_TAG_base_type:
16806 this_type = read_base_type (die, cu);
16808 case DW_TAG_unspecified_type:
16809 this_type = read_unspecified_type (die, cu);
16811 case DW_TAG_namespace:
16812 this_type = read_namespace_type (die, cu);
16814 case DW_TAG_module:
16815 this_type = read_module_type (die, cu);
16818 complaint (&symfile_complaints,
16819 _("unexpected tag in read_type_die: '%s'"),
16820 dwarf_tag_name (die->tag));
16827 /* See if we can figure out if the class lives in a namespace. We do
16828 this by looking for a member function; its demangled name will
16829 contain namespace info, if there is any.
16830 Return the computed name or NULL.
16831 Space for the result is allocated on the objfile's obstack.
16832 This is the full-die version of guess_partial_die_structure_name.
16833 In this case we know DIE has no useful parent. */
16836 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
16838 struct die_info *spec_die;
16839 struct dwarf2_cu *spec_cu;
16840 struct die_info *child;
16843 spec_die = die_specification (die, &spec_cu);
16844 if (spec_die != NULL)
16850 for (child = die->child;
16852 child = child->sibling)
16854 if (child->tag == DW_TAG_subprogram)
16856 struct attribute *attr;
16858 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
16860 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
16864 = language_class_name_from_physname (cu->language_defn,
16868 if (actual_name != NULL)
16870 const char *die_name = dwarf2_name (die, cu);
16872 if (die_name != NULL
16873 && strcmp (die_name, actual_name) != 0)
16875 /* Strip off the class name from the full name.
16876 We want the prefix. */
16877 int die_name_len = strlen (die_name);
16878 int actual_name_len = strlen (actual_name);
16880 /* Test for '::' as a sanity check. */
16881 if (actual_name_len > die_name_len + 2
16882 && actual_name[actual_name_len
16883 - die_name_len - 1] == ':')
16885 obstack_copy0 (&cu->objfile->objfile_obstack,
16887 actual_name_len - die_name_len - 2);
16890 xfree (actual_name);
16899 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16900 prefix part in such case. See
16901 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16904 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
16906 struct attribute *attr;
16909 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
16910 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
16913 attr = dwarf2_attr (die, DW_AT_name, cu);
16914 if (attr != NULL && DW_STRING (attr) != NULL)
16917 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
16919 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
16920 if (attr == NULL || DW_STRING (attr) == NULL)
16923 /* dwarf2_name had to be already called. */
16924 gdb_assert (DW_STRING_IS_CANONICAL (attr));
16926 /* Strip the base name, keep any leading namespaces/classes. */
16927 base = strrchr (DW_STRING (attr), ':');
16928 if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
16931 return obstack_copy0 (&cu->objfile->objfile_obstack,
16932 DW_STRING (attr), &base[-1] - DW_STRING (attr));
16935 /* Return the name of the namespace/class that DIE is defined within,
16936 or "" if we can't tell. The caller should not xfree the result.
16938 For example, if we're within the method foo() in the following
16948 then determine_prefix on foo's die will return "N::C". */
16950 static const char *
16951 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
16953 struct die_info *parent, *spec_die;
16954 struct dwarf2_cu *spec_cu;
16955 struct type *parent_type;
16958 if (cu->language != language_cplus && cu->language != language_java
16959 && cu->language != language_fortran)
16962 retval = anonymous_struct_prefix (die, cu);
16966 /* We have to be careful in the presence of DW_AT_specification.
16967 For example, with GCC 3.4, given the code
16971 // Definition of N::foo.
16975 then we'll have a tree of DIEs like this:
16977 1: DW_TAG_compile_unit
16978 2: DW_TAG_namespace // N
16979 3: DW_TAG_subprogram // declaration of N::foo
16980 4: DW_TAG_subprogram // definition of N::foo
16981 DW_AT_specification // refers to die #3
16983 Thus, when processing die #4, we have to pretend that we're in
16984 the context of its DW_AT_specification, namely the contex of die
16987 spec_die = die_specification (die, &spec_cu);
16988 if (spec_die == NULL)
16989 parent = die->parent;
16992 parent = spec_die->parent;
16996 if (parent == NULL)
16998 else if (parent->building_fullname)
17001 const char *parent_name;
17003 /* It has been seen on RealView 2.2 built binaries,
17004 DW_TAG_template_type_param types actually _defined_ as
17005 children of the parent class:
17008 template class <class Enum> Class{};
17009 Class<enum E> class_e;
17011 1: DW_TAG_class_type (Class)
17012 2: DW_TAG_enumeration_type (E)
17013 3: DW_TAG_enumerator (enum1:0)
17014 3: DW_TAG_enumerator (enum2:1)
17016 2: DW_TAG_template_type_param
17017 DW_AT_type DW_FORM_ref_udata (E)
17019 Besides being broken debug info, it can put GDB into an
17020 infinite loop. Consider:
17022 When we're building the full name for Class<E>, we'll start
17023 at Class, and go look over its template type parameters,
17024 finding E. We'll then try to build the full name of E, and
17025 reach here. We're now trying to build the full name of E,
17026 and look over the parent DIE for containing scope. In the
17027 broken case, if we followed the parent DIE of E, we'd again
17028 find Class, and once again go look at its template type
17029 arguments, etc., etc. Simply don't consider such parent die
17030 as source-level parent of this die (it can't be, the language
17031 doesn't allow it), and break the loop here. */
17032 name = dwarf2_name (die, cu);
17033 parent_name = dwarf2_name (parent, cu);
17034 complaint (&symfile_complaints,
17035 _("template param type '%s' defined within parent '%s'"),
17036 name ? name : "<unknown>",
17037 parent_name ? parent_name : "<unknown>");
17041 switch (parent->tag)
17043 case DW_TAG_namespace:
17044 parent_type = read_type_die (parent, cu);
17045 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
17046 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
17047 Work around this problem here. */
17048 if (cu->language == language_cplus
17049 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
17051 /* We give a name to even anonymous namespaces. */
17052 return TYPE_TAG_NAME (parent_type);
17053 case DW_TAG_class_type:
17054 case DW_TAG_interface_type:
17055 case DW_TAG_structure_type:
17056 case DW_TAG_union_type:
17057 case DW_TAG_module:
17058 parent_type = read_type_die (parent, cu);
17059 if (TYPE_TAG_NAME (parent_type) != NULL)
17060 return TYPE_TAG_NAME (parent_type);
17062 /* An anonymous structure is only allowed non-static data
17063 members; no typedefs, no member functions, et cetera.
17064 So it does not need a prefix. */
17066 case DW_TAG_compile_unit:
17067 case DW_TAG_partial_unit:
17068 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
17069 if (cu->language == language_cplus
17070 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
17071 && die->child != NULL
17072 && (die->tag == DW_TAG_class_type
17073 || die->tag == DW_TAG_structure_type
17074 || die->tag == DW_TAG_union_type))
17076 char *name = guess_full_die_structure_name (die, cu);
17082 return determine_prefix (parent, cu);
17086 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
17087 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
17088 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
17089 an obconcat, otherwise allocate storage for the result. The CU argument is
17090 used to determine the language and hence, the appropriate separator. */
17092 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
17095 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
17096 int physname, struct dwarf2_cu *cu)
17098 const char *lead = "";
17101 if (suffix == NULL || suffix[0] == '\0'
17102 || prefix == NULL || prefix[0] == '\0')
17104 else if (cu->language == language_java)
17106 else if (cu->language == language_fortran && physname)
17108 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
17109 DW_AT_MIPS_linkage_name is preferred and used instead. */
17117 if (prefix == NULL)
17119 if (suffix == NULL)
17125 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
17127 strcpy (retval, lead);
17128 strcat (retval, prefix);
17129 strcat (retval, sep);
17130 strcat (retval, suffix);
17135 /* We have an obstack. */
17136 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
17140 /* Return sibling of die, NULL if no sibling. */
17142 static struct die_info *
17143 sibling_die (struct die_info *die)
17145 return die->sibling;
17148 /* Get name of a die, return NULL if not found. */
17150 static const char *
17151 dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu,
17152 struct obstack *obstack)
17154 if (name && cu->language == language_cplus)
17156 char *canon_name = cp_canonicalize_string (name);
17158 if (canon_name != NULL)
17160 if (strcmp (canon_name, name) != 0)
17161 name = obstack_copy0 (obstack, canon_name, strlen (canon_name));
17162 xfree (canon_name);
17169 /* Get name of a die, return NULL if not found. */
17171 static const char *
17172 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
17174 struct attribute *attr;
17176 attr = dwarf2_attr (die, DW_AT_name, cu);
17177 if ((!attr || !DW_STRING (attr))
17178 && die->tag != DW_TAG_class_type
17179 && die->tag != DW_TAG_interface_type
17180 && die->tag != DW_TAG_structure_type
17181 && die->tag != DW_TAG_union_type)
17186 case DW_TAG_compile_unit:
17187 case DW_TAG_partial_unit:
17188 /* Compilation units have a DW_AT_name that is a filename, not
17189 a source language identifier. */
17190 case DW_TAG_enumeration_type:
17191 case DW_TAG_enumerator:
17192 /* These tags always have simple identifiers already; no need
17193 to canonicalize them. */
17194 return DW_STRING (attr);
17196 case DW_TAG_subprogram:
17197 /* Java constructors will all be named "<init>", so return
17198 the class name when we see this special case. */
17199 if (cu->language == language_java
17200 && DW_STRING (attr) != NULL
17201 && strcmp (DW_STRING (attr), "<init>") == 0)
17203 struct dwarf2_cu *spec_cu = cu;
17204 struct die_info *spec_die;
17206 /* GCJ will output '<init>' for Java constructor names.
17207 For this special case, return the name of the parent class. */
17209 /* GCJ may output suprogram DIEs with AT_specification set.
17210 If so, use the name of the specified DIE. */
17211 spec_die = die_specification (die, &spec_cu);
17212 if (spec_die != NULL)
17213 return dwarf2_name (spec_die, spec_cu);
17218 if (die->tag == DW_TAG_class_type)
17219 return dwarf2_name (die, cu);
17221 while (die->tag != DW_TAG_compile_unit
17222 && die->tag != DW_TAG_partial_unit);
17226 case DW_TAG_class_type:
17227 case DW_TAG_interface_type:
17228 case DW_TAG_structure_type:
17229 case DW_TAG_union_type:
17230 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
17231 structures or unions. These were of the form "._%d" in GCC 4.1,
17232 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
17233 and GCC 4.4. We work around this problem by ignoring these. */
17234 if (attr && DW_STRING (attr)
17235 && (strncmp (DW_STRING (attr), "._", 2) == 0
17236 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
17239 /* GCC might emit a nameless typedef that has a linkage name. See
17240 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
17241 if (!attr || DW_STRING (attr) == NULL)
17243 char *demangled = NULL;
17245 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
17247 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
17249 if (attr == NULL || DW_STRING (attr) == NULL)
17252 /* Avoid demangling DW_STRING (attr) the second time on a second
17253 call for the same DIE. */
17254 if (!DW_STRING_IS_CANONICAL (attr))
17255 demangled = gdb_demangle (DW_STRING (attr), DMGL_TYPES);
17261 /* FIXME: we already did this for the partial symbol... */
17262 DW_STRING (attr) = obstack_copy0 (&cu->objfile->objfile_obstack,
17263 demangled, strlen (demangled));
17264 DW_STRING_IS_CANONICAL (attr) = 1;
17267 /* Strip any leading namespaces/classes, keep only the base name.
17268 DW_AT_name for named DIEs does not contain the prefixes. */
17269 base = strrchr (DW_STRING (attr), ':');
17270 if (base && base > DW_STRING (attr) && base[-1] == ':')
17273 return DW_STRING (attr);
17282 if (!DW_STRING_IS_CANONICAL (attr))
17285 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
17286 &cu->objfile->objfile_obstack);
17287 DW_STRING_IS_CANONICAL (attr) = 1;
17289 return DW_STRING (attr);
17292 /* Return the die that this die in an extension of, or NULL if there
17293 is none. *EXT_CU is the CU containing DIE on input, and the CU
17294 containing the return value on output. */
17296 static struct die_info *
17297 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
17299 struct attribute *attr;
17301 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
17305 return follow_die_ref (die, attr, ext_cu);
17308 /* Convert a DIE tag into its string name. */
17310 static const char *
17311 dwarf_tag_name (unsigned tag)
17313 const char *name = get_DW_TAG_name (tag);
17316 return "DW_TAG_<unknown>";
17321 /* Convert a DWARF attribute code into its string name. */
17323 static const char *
17324 dwarf_attr_name (unsigned attr)
17328 #ifdef MIPS /* collides with DW_AT_HP_block_index */
17329 if (attr == DW_AT_MIPS_fde)
17330 return "DW_AT_MIPS_fde";
17332 if (attr == DW_AT_HP_block_index)
17333 return "DW_AT_HP_block_index";
17336 name = get_DW_AT_name (attr);
17339 return "DW_AT_<unknown>";
17344 /* Convert a DWARF value form code into its string name. */
17346 static const char *
17347 dwarf_form_name (unsigned form)
17349 const char *name = get_DW_FORM_name (form);
17352 return "DW_FORM_<unknown>";
17358 dwarf_bool_name (unsigned mybool)
17366 /* Convert a DWARF type code into its string name. */
17368 static const char *
17369 dwarf_type_encoding_name (unsigned enc)
17371 const char *name = get_DW_ATE_name (enc);
17374 return "DW_ATE_<unknown>";
17380 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
17384 print_spaces (indent, f);
17385 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
17386 dwarf_tag_name (die->tag), die->abbrev, die->offset.sect_off);
17388 if (die->parent != NULL)
17390 print_spaces (indent, f);
17391 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
17392 die->parent->offset.sect_off);
17395 print_spaces (indent, f);
17396 fprintf_unfiltered (f, " has children: %s\n",
17397 dwarf_bool_name (die->child != NULL));
17399 print_spaces (indent, f);
17400 fprintf_unfiltered (f, " attributes:\n");
17402 for (i = 0; i < die->num_attrs; ++i)
17404 print_spaces (indent, f);
17405 fprintf_unfiltered (f, " %s (%s) ",
17406 dwarf_attr_name (die->attrs[i].name),
17407 dwarf_form_name (die->attrs[i].form));
17409 switch (die->attrs[i].form)
17412 case DW_FORM_GNU_addr_index:
17413 fprintf_unfiltered (f, "address: ");
17414 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
17416 case DW_FORM_block2:
17417 case DW_FORM_block4:
17418 case DW_FORM_block:
17419 case DW_FORM_block1:
17420 fprintf_unfiltered (f, "block: size %s",
17421 pulongest (DW_BLOCK (&die->attrs[i])->size));
17423 case DW_FORM_exprloc:
17424 fprintf_unfiltered (f, "expression: size %s",
17425 pulongest (DW_BLOCK (&die->attrs[i])->size));
17427 case DW_FORM_ref_addr:
17428 fprintf_unfiltered (f, "ref address: ");
17429 fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
17431 case DW_FORM_GNU_ref_alt:
17432 fprintf_unfiltered (f, "alt ref address: ");
17433 fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
17439 case DW_FORM_ref_udata:
17440 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
17441 (long) (DW_UNSND (&die->attrs[i])));
17443 case DW_FORM_data1:
17444 case DW_FORM_data2:
17445 case DW_FORM_data4:
17446 case DW_FORM_data8:
17447 case DW_FORM_udata:
17448 case DW_FORM_sdata:
17449 fprintf_unfiltered (f, "constant: %s",
17450 pulongest (DW_UNSND (&die->attrs[i])));
17452 case DW_FORM_sec_offset:
17453 fprintf_unfiltered (f, "section offset: %s",
17454 pulongest (DW_UNSND (&die->attrs[i])));
17456 case DW_FORM_ref_sig8:
17457 fprintf_unfiltered (f, "signature: %s",
17458 hex_string (DW_SIGNATURE (&die->attrs[i])));
17460 case DW_FORM_string:
17462 case DW_FORM_GNU_str_index:
17463 case DW_FORM_GNU_strp_alt:
17464 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
17465 DW_STRING (&die->attrs[i])
17466 ? DW_STRING (&die->attrs[i]) : "",
17467 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
17470 if (DW_UNSND (&die->attrs[i]))
17471 fprintf_unfiltered (f, "flag: TRUE");
17473 fprintf_unfiltered (f, "flag: FALSE");
17475 case DW_FORM_flag_present:
17476 fprintf_unfiltered (f, "flag: TRUE");
17478 case DW_FORM_indirect:
17479 /* The reader will have reduced the indirect form to
17480 the "base form" so this form should not occur. */
17481 fprintf_unfiltered (f,
17482 "unexpected attribute form: DW_FORM_indirect");
17485 fprintf_unfiltered (f, "unsupported attribute form: %d.",
17486 die->attrs[i].form);
17489 fprintf_unfiltered (f, "\n");
17494 dump_die_for_error (struct die_info *die)
17496 dump_die_shallow (gdb_stderr, 0, die);
17500 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
17502 int indent = level * 4;
17504 gdb_assert (die != NULL);
17506 if (level >= max_level)
17509 dump_die_shallow (f, indent, die);
17511 if (die->child != NULL)
17513 print_spaces (indent, f);
17514 fprintf_unfiltered (f, " Children:");
17515 if (level + 1 < max_level)
17517 fprintf_unfiltered (f, "\n");
17518 dump_die_1 (f, level + 1, max_level, die->child);
17522 fprintf_unfiltered (f,
17523 " [not printed, max nesting level reached]\n");
17527 if (die->sibling != NULL && level > 0)
17529 dump_die_1 (f, level, max_level, die->sibling);
17533 /* This is called from the pdie macro in gdbinit.in.
17534 It's not static so gcc will keep a copy callable from gdb. */
17537 dump_die (struct die_info *die, int max_level)
17539 dump_die_1 (gdb_stdlog, 0, max_level, die);
17543 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
17547 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset.sect_off,
17553 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17554 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17557 is_ref_attr (struct attribute *attr)
17559 switch (attr->form)
17561 case DW_FORM_ref_addr:
17566 case DW_FORM_ref_udata:
17567 case DW_FORM_GNU_ref_alt:
17574 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17578 dwarf2_get_ref_die_offset (struct attribute *attr)
17580 sect_offset retval = { DW_UNSND (attr) };
17582 if (is_ref_attr (attr))
17585 retval.sect_off = 0;
17586 complaint (&symfile_complaints,
17587 _("unsupported die ref attribute form: '%s'"),
17588 dwarf_form_name (attr->form));
17592 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17593 * the value held by the attribute is not constant. */
17596 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
17598 if (attr->form == DW_FORM_sdata)
17599 return DW_SND (attr);
17600 else if (attr->form == DW_FORM_udata
17601 || attr->form == DW_FORM_data1
17602 || attr->form == DW_FORM_data2
17603 || attr->form == DW_FORM_data4
17604 || attr->form == DW_FORM_data8)
17605 return DW_UNSND (attr);
17608 complaint (&symfile_complaints,
17609 _("Attribute value is not a constant (%s)"),
17610 dwarf_form_name (attr->form));
17611 return default_value;
17615 /* Follow reference or signature attribute ATTR of SRC_DIE.
17616 On entry *REF_CU is the CU of SRC_DIE.
17617 On exit *REF_CU is the CU of the result. */
17619 static struct die_info *
17620 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
17621 struct dwarf2_cu **ref_cu)
17623 struct die_info *die;
17625 if (is_ref_attr (attr))
17626 die = follow_die_ref (src_die, attr, ref_cu);
17627 else if (attr->form == DW_FORM_ref_sig8)
17628 die = follow_die_sig (src_die, attr, ref_cu);
17631 dump_die_for_error (src_die);
17632 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17633 (*ref_cu)->objfile->name);
17639 /* Follow reference OFFSET.
17640 On entry *REF_CU is the CU of the source die referencing OFFSET.
17641 On exit *REF_CU is the CU of the result.
17642 Returns NULL if OFFSET is invalid. */
17644 static struct die_info *
17645 follow_die_offset (sect_offset offset, int offset_in_dwz,
17646 struct dwarf2_cu **ref_cu)
17648 struct die_info temp_die;
17649 struct dwarf2_cu *target_cu, *cu = *ref_cu;
17651 gdb_assert (cu->per_cu != NULL);
17655 if (cu->per_cu->is_debug_types)
17657 /* .debug_types CUs cannot reference anything outside their CU.
17658 If they need to, they have to reference a signatured type via
17659 DW_FORM_ref_sig8. */
17660 if (! offset_in_cu_p (&cu->header, offset))
17663 else if (offset_in_dwz != cu->per_cu->is_dwz
17664 || ! offset_in_cu_p (&cu->header, offset))
17666 struct dwarf2_per_cu_data *per_cu;
17668 per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
17671 /* If necessary, add it to the queue and load its DIEs. */
17672 if (maybe_queue_comp_unit (cu, per_cu, cu->language))
17673 load_full_comp_unit (per_cu, cu->language);
17675 target_cu = per_cu->cu;
17677 else if (cu->dies == NULL)
17679 /* We're loading full DIEs during partial symbol reading. */
17680 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
17681 load_full_comp_unit (cu->per_cu, language_minimal);
17684 *ref_cu = target_cu;
17685 temp_die.offset = offset;
17686 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset.sect_off);
17689 /* Follow reference attribute ATTR of SRC_DIE.
17690 On entry *REF_CU is the CU of SRC_DIE.
17691 On exit *REF_CU is the CU of the result. */
17693 static struct die_info *
17694 follow_die_ref (struct die_info *src_die, struct attribute *attr,
17695 struct dwarf2_cu **ref_cu)
17697 sect_offset offset = dwarf2_get_ref_die_offset (attr);
17698 struct dwarf2_cu *cu = *ref_cu;
17699 struct die_info *die;
17701 die = follow_die_offset (offset,
17702 (attr->form == DW_FORM_GNU_ref_alt
17703 || cu->per_cu->is_dwz),
17706 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17707 "at 0x%x [in module %s]"),
17708 offset.sect_off, src_die->offset.sect_off, cu->objfile->name);
17713 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17714 Returned value is intended for DW_OP_call*. Returned
17715 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17717 struct dwarf2_locexpr_baton
17718 dwarf2_fetch_die_loc_sect_off (sect_offset offset,
17719 struct dwarf2_per_cu_data *per_cu,
17720 CORE_ADDR (*get_frame_pc) (void *baton),
17723 struct dwarf2_cu *cu;
17724 struct die_info *die;
17725 struct attribute *attr;
17726 struct dwarf2_locexpr_baton retval;
17728 dw2_setup (per_cu->objfile);
17730 if (per_cu->cu == NULL)
17734 die = follow_die_offset (offset, per_cu->is_dwz, &cu);
17736 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17737 offset.sect_off, per_cu->objfile->name);
17739 attr = dwarf2_attr (die, DW_AT_location, cu);
17742 /* DWARF: "If there is no such attribute, then there is no effect.".
17743 DATA is ignored if SIZE is 0. */
17745 retval.data = NULL;
17748 else if (attr_form_is_section_offset (attr))
17750 struct dwarf2_loclist_baton loclist_baton;
17751 CORE_ADDR pc = (*get_frame_pc) (baton);
17754 fill_in_loclist_baton (cu, &loclist_baton, attr);
17756 retval.data = dwarf2_find_location_expression (&loclist_baton,
17758 retval.size = size;
17762 if (!attr_form_is_block (attr))
17763 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17764 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17765 offset.sect_off, per_cu->objfile->name);
17767 retval.data = DW_BLOCK (attr)->data;
17768 retval.size = DW_BLOCK (attr)->size;
17770 retval.per_cu = cu->per_cu;
17772 age_cached_comp_units ();
17777 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
17780 struct dwarf2_locexpr_baton
17781 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu,
17782 struct dwarf2_per_cu_data *per_cu,
17783 CORE_ADDR (*get_frame_pc) (void *baton),
17786 sect_offset offset = { per_cu->offset.sect_off + offset_in_cu.cu_off };
17788 return dwarf2_fetch_die_loc_sect_off (offset, per_cu, get_frame_pc, baton);
17791 /* Write a constant of a given type as target-ordered bytes into
17794 static const gdb_byte *
17795 write_constant_as_bytes (struct obstack *obstack,
17796 enum bfd_endian byte_order,
17803 *len = TYPE_LENGTH (type);
17804 result = obstack_alloc (obstack, *len);
17805 store_unsigned_integer (result, *len, byte_order, value);
17810 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
17811 pointer to the constant bytes and set LEN to the length of the
17812 data. If memory is needed, allocate it on OBSTACK. If the DIE
17813 does not have a DW_AT_const_value, return NULL. */
17816 dwarf2_fetch_constant_bytes (sect_offset offset,
17817 struct dwarf2_per_cu_data *per_cu,
17818 struct obstack *obstack,
17821 struct dwarf2_cu *cu;
17822 struct die_info *die;
17823 struct attribute *attr;
17824 const gdb_byte *result = NULL;
17827 enum bfd_endian byte_order;
17829 dw2_setup (per_cu->objfile);
17831 if (per_cu->cu == NULL)
17835 die = follow_die_offset (offset, per_cu->is_dwz, &cu);
17837 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17838 offset.sect_off, per_cu->objfile->name);
17841 attr = dwarf2_attr (die, DW_AT_const_value, cu);
17845 byte_order = (bfd_big_endian (per_cu->objfile->obfd)
17846 ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
17848 switch (attr->form)
17851 case DW_FORM_GNU_addr_index:
17855 *len = cu->header.addr_size;
17856 tem = obstack_alloc (obstack, *len);
17857 store_unsigned_integer (tem, *len, byte_order, DW_ADDR (attr));
17861 case DW_FORM_string:
17863 case DW_FORM_GNU_str_index:
17864 case DW_FORM_GNU_strp_alt:
17865 /* DW_STRING is already allocated on the objfile obstack, point
17867 result = (const gdb_byte *) DW_STRING (attr);
17868 *len = strlen (DW_STRING (attr));
17870 case DW_FORM_block1:
17871 case DW_FORM_block2:
17872 case DW_FORM_block4:
17873 case DW_FORM_block:
17874 case DW_FORM_exprloc:
17875 result = DW_BLOCK (attr)->data;
17876 *len = DW_BLOCK (attr)->size;
17879 /* The DW_AT_const_value attributes are supposed to carry the
17880 symbol's value "represented as it would be on the target
17881 architecture." By the time we get here, it's already been
17882 converted to host endianness, so we just need to sign- or
17883 zero-extend it as appropriate. */
17884 case DW_FORM_data1:
17885 type = die_type (die, cu);
17886 result = dwarf2_const_value_data (attr, obstack, cu, &value, 8);
17887 if (result == NULL)
17888 result = write_constant_as_bytes (obstack, byte_order,
17891 case DW_FORM_data2:
17892 type = die_type (die, cu);
17893 result = dwarf2_const_value_data (attr, obstack, cu, &value, 16);
17894 if (result == NULL)
17895 result = write_constant_as_bytes (obstack, byte_order,
17898 case DW_FORM_data4:
17899 type = die_type (die, cu);
17900 result = dwarf2_const_value_data (attr, obstack, cu, &value, 32);
17901 if (result == NULL)
17902 result = write_constant_as_bytes (obstack, byte_order,
17905 case DW_FORM_data8:
17906 type = die_type (die, cu);
17907 result = dwarf2_const_value_data (attr, obstack, cu, &value, 64);
17908 if (result == NULL)
17909 result = write_constant_as_bytes (obstack, byte_order,
17913 case DW_FORM_sdata:
17914 type = die_type (die, cu);
17915 result = write_constant_as_bytes (obstack, byte_order,
17916 type, DW_SND (attr), len);
17919 case DW_FORM_udata:
17920 type = die_type (die, cu);
17921 result = write_constant_as_bytes (obstack, byte_order,
17922 type, DW_UNSND (attr), len);
17926 complaint (&symfile_complaints,
17927 _("unsupported const value attribute form: '%s'"),
17928 dwarf_form_name (attr->form));
17935 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17939 dwarf2_get_die_type (cu_offset die_offset,
17940 struct dwarf2_per_cu_data *per_cu)
17942 sect_offset die_offset_sect;
17944 dw2_setup (per_cu->objfile);
17946 die_offset_sect.sect_off = per_cu->offset.sect_off + die_offset.cu_off;
17947 return get_die_type_at_offset (die_offset_sect, per_cu);
17950 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
17951 On entry *REF_CU is the CU of SRC_DIE.
17952 On exit *REF_CU is the CU of the result.
17953 Returns NULL if the referenced DIE isn't found. */
17955 static struct die_info *
17956 follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
17957 struct dwarf2_cu **ref_cu)
17959 struct objfile *objfile = (*ref_cu)->objfile;
17960 struct die_info temp_die;
17961 struct dwarf2_cu *sig_cu;
17962 struct die_info *die;
17964 /* While it might be nice to assert sig_type->type == NULL here,
17965 we can get here for DW_AT_imported_declaration where we need
17966 the DIE not the type. */
17968 /* If necessary, add it to the queue and load its DIEs. */
17970 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, language_minimal))
17971 read_signatured_type (sig_type);
17973 gdb_assert (sig_type->per_cu.cu != NULL);
17975 sig_cu = sig_type->per_cu.cu;
17976 gdb_assert (sig_type->type_offset_in_section.sect_off != 0);
17977 temp_die.offset = sig_type->type_offset_in_section;
17978 die = htab_find_with_hash (sig_cu->die_hash, &temp_die,
17979 temp_die.offset.sect_off);
17982 /* For .gdb_index version 7 keep track of included TUs.
17983 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
17984 if (dwarf2_per_objfile->index_table != NULL
17985 && dwarf2_per_objfile->index_table->version <= 7)
17987 VEC_safe_push (dwarf2_per_cu_ptr,
17988 (*ref_cu)->per_cu->imported_symtabs,
17999 /* Follow signatured type referenced by ATTR in SRC_DIE.
18000 On entry *REF_CU is the CU of SRC_DIE.
18001 On exit *REF_CU is the CU of the result.
18002 The result is the DIE of the type.
18003 If the referenced type cannot be found an error is thrown. */
18005 static struct die_info *
18006 follow_die_sig (struct die_info *src_die, struct attribute *attr,
18007 struct dwarf2_cu **ref_cu)
18009 ULONGEST signature = DW_SIGNATURE (attr);
18010 struct signatured_type *sig_type;
18011 struct die_info *die;
18013 gdb_assert (attr->form == DW_FORM_ref_sig8);
18015 sig_type = lookup_signatured_type (signature);
18016 /* sig_type will be NULL if the signatured type is missing from
18018 if (sig_type == NULL)
18020 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
18021 " from DIE at 0x%x [in module %s]"),
18022 hex_string (signature), src_die->offset.sect_off,
18023 (*ref_cu)->objfile->name);
18026 die = follow_die_sig_1 (src_die, sig_type, ref_cu);
18029 dump_die_for_error (src_die);
18030 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
18031 " from DIE at 0x%x [in module %s]"),
18032 hex_string (signature), src_die->offset.sect_off,
18033 (*ref_cu)->objfile->name);
18039 /* Get the type specified by SIGNATURE referenced in DIE/CU,
18040 reading in and processing the type unit if necessary. */
18042 static struct type *
18043 get_signatured_type (struct die_info *die, ULONGEST signature,
18044 struct dwarf2_cu *cu)
18046 struct signatured_type *sig_type;
18047 struct dwarf2_cu *type_cu;
18048 struct die_info *type_die;
18051 sig_type = lookup_signatured_type (signature);
18052 /* sig_type will be NULL if the signatured type is missing from
18054 if (sig_type == NULL)
18056 complaint (&symfile_complaints,
18057 _("Dwarf Error: Cannot find signatured DIE %s referenced"
18058 " from DIE at 0x%x [in module %s]"),
18059 hex_string (signature), die->offset.sect_off,
18060 dwarf2_per_objfile->objfile->name);
18061 return build_error_marker_type (cu, die);
18064 /* If we already know the type we're done. */
18065 if (sig_type->type != NULL)
18066 return sig_type->type;
18069 type_die = follow_die_sig_1 (die, sig_type, &type_cu);
18070 if (type_die != NULL)
18072 /* N.B. We need to call get_die_type to ensure only one type for this DIE
18073 is created. This is important, for example, because for c++ classes
18074 we need TYPE_NAME set which is only done by new_symbol. Blech. */
18075 type = read_type_die (type_die, type_cu);
18078 complaint (&symfile_complaints,
18079 _("Dwarf Error: Cannot build signatured type %s"
18080 " referenced from DIE at 0x%x [in module %s]"),
18081 hex_string (signature), die->offset.sect_off,
18082 dwarf2_per_objfile->objfile->name);
18083 type = build_error_marker_type (cu, die);
18088 complaint (&symfile_complaints,
18089 _("Dwarf Error: Problem reading signatured DIE %s referenced"
18090 " from DIE at 0x%x [in module %s]"),
18091 hex_string (signature), die->offset.sect_off,
18092 dwarf2_per_objfile->objfile->name);
18093 type = build_error_marker_type (cu, die);
18095 sig_type->type = type;
18100 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
18101 reading in and processing the type unit if necessary. */
18103 static struct type *
18104 get_DW_AT_signature_type (struct die_info *die, struct attribute *attr,
18105 struct dwarf2_cu *cu) /* ARI: editCase function */
18107 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
18108 if (is_ref_attr (attr))
18110 struct dwarf2_cu *type_cu = cu;
18111 struct die_info *type_die = follow_die_ref (die, attr, &type_cu);
18113 return read_type_die (type_die, type_cu);
18115 else if (attr->form == DW_FORM_ref_sig8)
18117 return get_signatured_type (die, DW_SIGNATURE (attr), cu);
18121 complaint (&symfile_complaints,
18122 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
18123 " at 0x%x [in module %s]"),
18124 dwarf_form_name (attr->form), die->offset.sect_off,
18125 dwarf2_per_objfile->objfile->name);
18126 return build_error_marker_type (cu, die);
18130 /* Load the DIEs associated with type unit PER_CU into memory. */
18133 load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
18135 struct signatured_type *sig_type;
18137 /* Caller is responsible for ensuring type_unit_groups don't get here. */
18138 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu));
18140 /* We have the per_cu, but we need the signatured_type.
18141 Fortunately this is an easy translation. */
18142 gdb_assert (per_cu->is_debug_types);
18143 sig_type = (struct signatured_type *) per_cu;
18145 gdb_assert (per_cu->cu == NULL);
18147 read_signatured_type (sig_type);
18149 gdb_assert (per_cu->cu != NULL);
18152 /* die_reader_func for read_signatured_type.
18153 This is identical to load_full_comp_unit_reader,
18154 but is kept separate for now. */
18157 read_signatured_type_reader (const struct die_reader_specs *reader,
18158 const gdb_byte *info_ptr,
18159 struct die_info *comp_unit_die,
18163 struct dwarf2_cu *cu = reader->cu;
18165 gdb_assert (cu->die_hash == NULL);
18167 htab_create_alloc_ex (cu->header.length / 12,
18171 &cu->comp_unit_obstack,
18172 hashtab_obstack_allocate,
18173 dummy_obstack_deallocate);
18176 comp_unit_die->child = read_die_and_siblings (reader, info_ptr,
18177 &info_ptr, comp_unit_die);
18178 cu->dies = comp_unit_die;
18179 /* comp_unit_die is not stored in die_hash, no need. */
18181 /* We try not to read any attributes in this function, because not
18182 all CUs needed for references have been loaded yet, and symbol
18183 table processing isn't initialized. But we have to set the CU language,
18184 or we won't be able to build types correctly.
18185 Similarly, if we do not read the producer, we can not apply
18186 producer-specific interpretation. */
18187 prepare_one_comp_unit (cu, cu->dies, language_minimal);
18190 /* Read in a signatured type and build its CU and DIEs.
18191 If the type is a stub for the real type in a DWO file,
18192 read in the real type from the DWO file as well. */
18195 read_signatured_type (struct signatured_type *sig_type)
18197 struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu;
18199 gdb_assert (per_cu->is_debug_types);
18200 gdb_assert (per_cu->cu == NULL);
18202 init_cutu_and_read_dies (per_cu, NULL, 0, 1,
18203 read_signatured_type_reader, NULL);
18206 /* Decode simple location descriptions.
18207 Given a pointer to a dwarf block that defines a location, compute
18208 the location and return the value.
18210 NOTE drow/2003-11-18: This function is called in two situations
18211 now: for the address of static or global variables (partial symbols
18212 only) and for offsets into structures which are expected to be
18213 (more or less) constant. The partial symbol case should go away,
18214 and only the constant case should remain. That will let this
18215 function complain more accurately. A few special modes are allowed
18216 without complaint for global variables (for instance, global
18217 register values and thread-local values).
18219 A location description containing no operations indicates that the
18220 object is optimized out. The return value is 0 for that case.
18221 FIXME drow/2003-11-16: No callers check for this case any more; soon all
18222 callers will only want a very basic result and this can become a
18225 Note that stack[0] is unused except as a default error return. */
18228 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
18230 struct objfile *objfile = cu->objfile;
18232 size_t size = blk->size;
18233 const gdb_byte *data = blk->data;
18234 CORE_ADDR stack[64];
18236 unsigned int bytes_read, unsnd;
18242 stack[++stacki] = 0;
18281 stack[++stacki] = op - DW_OP_lit0;
18316 stack[++stacki] = op - DW_OP_reg0;
18318 dwarf2_complex_location_expr_complaint ();
18322 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
18324 stack[++stacki] = unsnd;
18326 dwarf2_complex_location_expr_complaint ();
18330 stack[++stacki] = read_address (objfile->obfd, &data[i],
18335 case DW_OP_const1u:
18336 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
18340 case DW_OP_const1s:
18341 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
18345 case DW_OP_const2u:
18346 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
18350 case DW_OP_const2s:
18351 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
18355 case DW_OP_const4u:
18356 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
18360 case DW_OP_const4s:
18361 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
18365 case DW_OP_const8u:
18366 stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]);
18371 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
18377 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
18382 stack[stacki + 1] = stack[stacki];
18387 stack[stacki - 1] += stack[stacki];
18391 case DW_OP_plus_uconst:
18392 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
18398 stack[stacki - 1] -= stack[stacki];
18403 /* If we're not the last op, then we definitely can't encode
18404 this using GDB's address_class enum. This is valid for partial
18405 global symbols, although the variable's address will be bogus
18408 dwarf2_complex_location_expr_complaint ();
18411 case DW_OP_GNU_push_tls_address:
18412 /* The top of the stack has the offset from the beginning
18413 of the thread control block at which the variable is located. */
18414 /* Nothing should follow this operator, so the top of stack would
18416 /* This is valid for partial global symbols, but the variable's
18417 address will be bogus in the psymtab. Make it always at least
18418 non-zero to not look as a variable garbage collected by linker
18419 which have DW_OP_addr 0. */
18421 dwarf2_complex_location_expr_complaint ();
18425 case DW_OP_GNU_uninit:
18428 case DW_OP_GNU_addr_index:
18429 case DW_OP_GNU_const_index:
18430 stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i],
18437 const char *name = get_DW_OP_name (op);
18440 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
18443 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
18447 return (stack[stacki]);
18450 /* Enforce maximum stack depth of SIZE-1 to avoid writing
18451 outside of the allocated space. Also enforce minimum>0. */
18452 if (stacki >= ARRAY_SIZE (stack) - 1)
18454 complaint (&symfile_complaints,
18455 _("location description stack overflow"));
18461 complaint (&symfile_complaints,
18462 _("location description stack underflow"));
18466 return (stack[stacki]);
18469 /* memory allocation interface */
18471 static struct dwarf_block *
18472 dwarf_alloc_block (struct dwarf2_cu *cu)
18474 struct dwarf_block *blk;
18476 blk = (struct dwarf_block *)
18477 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
18481 static struct die_info *
18482 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
18484 struct die_info *die;
18485 size_t size = sizeof (struct die_info);
18488 size += (num_attrs - 1) * sizeof (struct attribute);
18490 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
18491 memset (die, 0, sizeof (struct die_info));
18496 /* Macro support. */
18498 /* Return file name relative to the compilation directory of file number I in
18499 *LH's file name table. The result is allocated using xmalloc; the caller is
18500 responsible for freeing it. */
18503 file_file_name (int file, struct line_header *lh)
18505 /* Is the file number a valid index into the line header's file name
18506 table? Remember that file numbers start with one, not zero. */
18507 if (1 <= file && file <= lh->num_file_names)
18509 struct file_entry *fe = &lh->file_names[file - 1];
18511 if (IS_ABSOLUTE_PATH (fe->name) || fe->dir_index == 0)
18512 return xstrdup (fe->name);
18513 return concat (lh->include_dirs[fe->dir_index - 1], SLASH_STRING,
18518 /* The compiler produced a bogus file number. We can at least
18519 record the macro definitions made in the file, even if we
18520 won't be able to find the file by name. */
18521 char fake_name[80];
18523 xsnprintf (fake_name, sizeof (fake_name),
18524 "<bad macro file number %d>", file);
18526 complaint (&symfile_complaints,
18527 _("bad file number in macro information (%d)"),
18530 return xstrdup (fake_name);
18534 /* Return the full name of file number I in *LH's file name table.
18535 Use COMP_DIR as the name of the current directory of the
18536 compilation. The result is allocated using xmalloc; the caller is
18537 responsible for freeing it. */
18539 file_full_name (int file, struct line_header *lh, const char *comp_dir)
18541 /* Is the file number a valid index into the line header's file name
18542 table? Remember that file numbers start with one, not zero. */
18543 if (1 <= file && file <= lh->num_file_names)
18545 char *relative = file_file_name (file, lh);
18547 if (IS_ABSOLUTE_PATH (relative) || comp_dir == NULL)
18549 return reconcat (relative, comp_dir, SLASH_STRING, relative, NULL);
18552 return file_file_name (file, lh);
18556 static struct macro_source_file *
18557 macro_start_file (int file, int line,
18558 struct macro_source_file *current_file,
18559 const char *comp_dir,
18560 struct line_header *lh, struct objfile *objfile)
18562 /* File name relative to the compilation directory of this source file. */
18563 char *file_name = file_file_name (file, lh);
18565 /* We don't create a macro table for this compilation unit
18566 at all until we actually get a filename. */
18567 if (! pending_macros)
18568 pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
18569 objfile->per_bfd->macro_cache,
18572 if (! current_file)
18574 /* If we have no current file, then this must be the start_file
18575 directive for the compilation unit's main source file. */
18576 current_file = macro_set_main (pending_macros, file_name);
18577 macro_define_special (pending_macros);
18580 current_file = macro_include (current_file, line, file_name);
18584 return current_file;
18588 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
18589 followed by a null byte. */
18591 copy_string (const char *buf, int len)
18593 char *s = xmalloc (len + 1);
18595 memcpy (s, buf, len);
18601 static const char *
18602 consume_improper_spaces (const char *p, const char *body)
18606 complaint (&symfile_complaints,
18607 _("macro definition contains spaces "
18608 "in formal argument list:\n`%s'"),
18620 parse_macro_definition (struct macro_source_file *file, int line,
18625 /* The body string takes one of two forms. For object-like macro
18626 definitions, it should be:
18628 <macro name> " " <definition>
18630 For function-like macro definitions, it should be:
18632 <macro name> "() " <definition>
18634 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
18636 Spaces may appear only where explicitly indicated, and in the
18639 The Dwarf 2 spec says that an object-like macro's name is always
18640 followed by a space, but versions of GCC around March 2002 omit
18641 the space when the macro's definition is the empty string.
18643 The Dwarf 2 spec says that there should be no spaces between the
18644 formal arguments in a function-like macro's formal argument list,
18645 but versions of GCC around March 2002 include spaces after the
18649 /* Find the extent of the macro name. The macro name is terminated
18650 by either a space or null character (for an object-like macro) or
18651 an opening paren (for a function-like macro). */
18652 for (p = body; *p; p++)
18653 if (*p == ' ' || *p == '(')
18656 if (*p == ' ' || *p == '\0')
18658 /* It's an object-like macro. */
18659 int name_len = p - body;
18660 char *name = copy_string (body, name_len);
18661 const char *replacement;
18664 replacement = body + name_len + 1;
18667 dwarf2_macro_malformed_definition_complaint (body);
18668 replacement = body + name_len;
18671 macro_define_object (file, line, name, replacement);
18675 else if (*p == '(')
18677 /* It's a function-like macro. */
18678 char *name = copy_string (body, p - body);
18681 char **argv = xmalloc (argv_size * sizeof (*argv));
18685 p = consume_improper_spaces (p, body);
18687 /* Parse the formal argument list. */
18688 while (*p && *p != ')')
18690 /* Find the extent of the current argument name. */
18691 const char *arg_start = p;
18693 while (*p && *p != ',' && *p != ')' && *p != ' ')
18696 if (! *p || p == arg_start)
18697 dwarf2_macro_malformed_definition_complaint (body);
18700 /* Make sure argv has room for the new argument. */
18701 if (argc >= argv_size)
18704 argv = xrealloc (argv, argv_size * sizeof (*argv));
18707 argv[argc++] = copy_string (arg_start, p - arg_start);
18710 p = consume_improper_spaces (p, body);
18712 /* Consume the comma, if present. */
18717 p = consume_improper_spaces (p, body);
18726 /* Perfectly formed definition, no complaints. */
18727 macro_define_function (file, line, name,
18728 argc, (const char **) argv,
18730 else if (*p == '\0')
18732 /* Complain, but do define it. */
18733 dwarf2_macro_malformed_definition_complaint (body);
18734 macro_define_function (file, line, name,
18735 argc, (const char **) argv,
18739 /* Just complain. */
18740 dwarf2_macro_malformed_definition_complaint (body);
18743 /* Just complain. */
18744 dwarf2_macro_malformed_definition_complaint (body);
18750 for (i = 0; i < argc; i++)
18756 dwarf2_macro_malformed_definition_complaint (body);
18759 /* Skip some bytes from BYTES according to the form given in FORM.
18760 Returns the new pointer. */
18762 static const gdb_byte *
18763 skip_form_bytes (bfd *abfd, const gdb_byte *bytes, const gdb_byte *buffer_end,
18764 enum dwarf_form form,
18765 unsigned int offset_size,
18766 struct dwarf2_section_info *section)
18768 unsigned int bytes_read;
18772 case DW_FORM_data1:
18777 case DW_FORM_data2:
18781 case DW_FORM_data4:
18785 case DW_FORM_data8:
18789 case DW_FORM_string:
18790 read_direct_string (abfd, bytes, &bytes_read);
18791 bytes += bytes_read;
18794 case DW_FORM_sec_offset:
18796 case DW_FORM_GNU_strp_alt:
18797 bytes += offset_size;
18800 case DW_FORM_block:
18801 bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
18802 bytes += bytes_read;
18805 case DW_FORM_block1:
18806 bytes += 1 + read_1_byte (abfd, bytes);
18808 case DW_FORM_block2:
18809 bytes += 2 + read_2_bytes (abfd, bytes);
18811 case DW_FORM_block4:
18812 bytes += 4 + read_4_bytes (abfd, bytes);
18815 case DW_FORM_sdata:
18816 case DW_FORM_udata:
18817 case DW_FORM_GNU_addr_index:
18818 case DW_FORM_GNU_str_index:
18819 bytes = gdb_skip_leb128 (bytes, buffer_end);
18822 dwarf2_section_buffer_overflow_complaint (section);
18830 complaint (&symfile_complaints,
18831 _("invalid form 0x%x in `%s'"),
18833 section->asection->name);
18841 /* A helper for dwarf_decode_macros that handles skipping an unknown
18842 opcode. Returns an updated pointer to the macro data buffer; or,
18843 on error, issues a complaint and returns NULL. */
18845 static const gdb_byte *
18846 skip_unknown_opcode (unsigned int opcode,
18847 const gdb_byte **opcode_definitions,
18848 const gdb_byte *mac_ptr, const gdb_byte *mac_end,
18850 unsigned int offset_size,
18851 struct dwarf2_section_info *section)
18853 unsigned int bytes_read, i;
18855 const gdb_byte *defn;
18857 if (opcode_definitions[opcode] == NULL)
18859 complaint (&symfile_complaints,
18860 _("unrecognized DW_MACFINO opcode 0x%x"),
18865 defn = opcode_definitions[opcode];
18866 arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
18867 defn += bytes_read;
18869 for (i = 0; i < arg; ++i)
18871 mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, defn[i], offset_size,
18873 if (mac_ptr == NULL)
18875 /* skip_form_bytes already issued the complaint. */
18883 /* A helper function which parses the header of a macro section.
18884 If the macro section is the extended (for now called "GNU") type,
18885 then this updates *OFFSET_SIZE. Returns a pointer to just after
18886 the header, or issues a complaint and returns NULL on error. */
18888 static const gdb_byte *
18889 dwarf_parse_macro_header (const gdb_byte **opcode_definitions,
18891 const gdb_byte *mac_ptr,
18892 unsigned int *offset_size,
18893 int section_is_gnu)
18895 memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
18897 if (section_is_gnu)
18899 unsigned int version, flags;
18901 version = read_2_bytes (abfd, mac_ptr);
18904 complaint (&symfile_complaints,
18905 _("unrecognized version `%d' in .debug_macro section"),
18911 flags = read_1_byte (abfd, mac_ptr);
18913 *offset_size = (flags & 1) ? 8 : 4;
18915 if ((flags & 2) != 0)
18916 /* We don't need the line table offset. */
18917 mac_ptr += *offset_size;
18919 /* Vendor opcode descriptions. */
18920 if ((flags & 4) != 0)
18922 unsigned int i, count;
18924 count = read_1_byte (abfd, mac_ptr);
18926 for (i = 0; i < count; ++i)
18928 unsigned int opcode, bytes_read;
18931 opcode = read_1_byte (abfd, mac_ptr);
18933 opcode_definitions[opcode] = mac_ptr;
18934 arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18935 mac_ptr += bytes_read;
18944 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18945 including DW_MACRO_GNU_transparent_include. */
18948 dwarf_decode_macro_bytes (bfd *abfd,
18949 const gdb_byte *mac_ptr, const gdb_byte *mac_end,
18950 struct macro_source_file *current_file,
18951 struct line_header *lh, const char *comp_dir,
18952 struct dwarf2_section_info *section,
18953 int section_is_gnu, int section_is_dwz,
18954 unsigned int offset_size,
18955 struct objfile *objfile,
18956 htab_t include_hash)
18958 enum dwarf_macro_record_type macinfo_type;
18959 int at_commandline;
18960 const gdb_byte *opcode_definitions[256];
18962 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
18963 &offset_size, section_is_gnu);
18964 if (mac_ptr == NULL)
18966 /* We already issued a complaint. */
18970 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18971 GDB is still reading the definitions from command line. First
18972 DW_MACINFO_start_file will need to be ignored as it was already executed
18973 to create CURRENT_FILE for the main source holding also the command line
18974 definitions. On first met DW_MACINFO_start_file this flag is reset to
18975 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18977 at_commandline = 1;
18981 /* Do we at least have room for a macinfo type byte? */
18982 if (mac_ptr >= mac_end)
18984 dwarf2_section_buffer_overflow_complaint (section);
18988 macinfo_type = read_1_byte (abfd, mac_ptr);
18991 /* Note that we rely on the fact that the corresponding GNU and
18992 DWARF constants are the same. */
18993 switch (macinfo_type)
18995 /* A zero macinfo type indicates the end of the macro
19000 case DW_MACRO_GNU_define:
19001 case DW_MACRO_GNU_undef:
19002 case DW_MACRO_GNU_define_indirect:
19003 case DW_MACRO_GNU_undef_indirect:
19004 case DW_MACRO_GNU_define_indirect_alt:
19005 case DW_MACRO_GNU_undef_indirect_alt:
19007 unsigned int bytes_read;
19012 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19013 mac_ptr += bytes_read;
19015 if (macinfo_type == DW_MACRO_GNU_define
19016 || macinfo_type == DW_MACRO_GNU_undef)
19018 body = read_direct_string (abfd, mac_ptr, &bytes_read);
19019 mac_ptr += bytes_read;
19023 LONGEST str_offset;
19025 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
19026 mac_ptr += offset_size;
19028 if (macinfo_type == DW_MACRO_GNU_define_indirect_alt
19029 || macinfo_type == DW_MACRO_GNU_undef_indirect_alt
19032 struct dwz_file *dwz = dwarf2_get_dwz_file ();
19034 body = read_indirect_string_from_dwz (dwz, str_offset);
19037 body = read_indirect_string_at_offset (abfd, str_offset);
19040 is_define = (macinfo_type == DW_MACRO_GNU_define
19041 || macinfo_type == DW_MACRO_GNU_define_indirect
19042 || macinfo_type == DW_MACRO_GNU_define_indirect_alt);
19043 if (! current_file)
19045 /* DWARF violation as no main source is present. */
19046 complaint (&symfile_complaints,
19047 _("debug info with no main source gives macro %s "
19049 is_define ? _("definition") : _("undefinition"),
19053 if ((line == 0 && !at_commandline)
19054 || (line != 0 && at_commandline))
19055 complaint (&symfile_complaints,
19056 _("debug info gives %s macro %s with %s line %d: %s"),
19057 at_commandline ? _("command-line") : _("in-file"),
19058 is_define ? _("definition") : _("undefinition"),
19059 line == 0 ? _("zero") : _("non-zero"), line, body);
19062 parse_macro_definition (current_file, line, body);
19065 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
19066 || macinfo_type == DW_MACRO_GNU_undef_indirect
19067 || macinfo_type == DW_MACRO_GNU_undef_indirect_alt);
19068 macro_undef (current_file, line, body);
19073 case DW_MACRO_GNU_start_file:
19075 unsigned int bytes_read;
19078 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19079 mac_ptr += bytes_read;
19080 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19081 mac_ptr += bytes_read;
19083 if ((line == 0 && !at_commandline)
19084 || (line != 0 && at_commandline))
19085 complaint (&symfile_complaints,
19086 _("debug info gives source %d included "
19087 "from %s at %s line %d"),
19088 file, at_commandline ? _("command-line") : _("file"),
19089 line == 0 ? _("zero") : _("non-zero"), line);
19091 if (at_commandline)
19093 /* This DW_MACRO_GNU_start_file was executed in the
19095 at_commandline = 0;
19098 current_file = macro_start_file (file, line,
19099 current_file, comp_dir,
19104 case DW_MACRO_GNU_end_file:
19105 if (! current_file)
19106 complaint (&symfile_complaints,
19107 _("macro debug info has an unmatched "
19108 "`close_file' directive"));
19111 current_file = current_file->included_by;
19112 if (! current_file)
19114 enum dwarf_macro_record_type next_type;
19116 /* GCC circa March 2002 doesn't produce the zero
19117 type byte marking the end of the compilation
19118 unit. Complain if it's not there, but exit no
19121 /* Do we at least have room for a macinfo type byte? */
19122 if (mac_ptr >= mac_end)
19124 dwarf2_section_buffer_overflow_complaint (section);
19128 /* We don't increment mac_ptr here, so this is just
19130 next_type = read_1_byte (abfd, mac_ptr);
19131 if (next_type != 0)
19132 complaint (&symfile_complaints,
19133 _("no terminating 0-type entry for "
19134 "macros in `.debug_macinfo' section"));
19141 case DW_MACRO_GNU_transparent_include:
19142 case DW_MACRO_GNU_transparent_include_alt:
19146 bfd *include_bfd = abfd;
19147 struct dwarf2_section_info *include_section = section;
19148 struct dwarf2_section_info alt_section;
19149 const gdb_byte *include_mac_end = mac_end;
19150 int is_dwz = section_is_dwz;
19151 const gdb_byte *new_mac_ptr;
19153 offset = read_offset_1 (abfd, mac_ptr, offset_size);
19154 mac_ptr += offset_size;
19156 if (macinfo_type == DW_MACRO_GNU_transparent_include_alt)
19158 struct dwz_file *dwz = dwarf2_get_dwz_file ();
19160 dwarf2_read_section (dwarf2_per_objfile->objfile,
19163 include_bfd = dwz->macro.asection->owner;
19164 include_section = &dwz->macro;
19165 include_mac_end = dwz->macro.buffer + dwz->macro.size;
19169 new_mac_ptr = include_section->buffer + offset;
19170 slot = htab_find_slot (include_hash, new_mac_ptr, INSERT);
19174 /* This has actually happened; see
19175 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
19176 complaint (&symfile_complaints,
19177 _("recursive DW_MACRO_GNU_transparent_include in "
19178 ".debug_macro section"));
19182 *slot = (void *) new_mac_ptr;
19184 dwarf_decode_macro_bytes (include_bfd, new_mac_ptr,
19185 include_mac_end, current_file,
19187 section, section_is_gnu, is_dwz,
19188 offset_size, objfile, include_hash);
19190 htab_remove_elt (include_hash, (void *) new_mac_ptr);
19195 case DW_MACINFO_vendor_ext:
19196 if (!section_is_gnu)
19198 unsigned int bytes_read;
19201 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19202 mac_ptr += bytes_read;
19203 read_direct_string (abfd, mac_ptr, &bytes_read);
19204 mac_ptr += bytes_read;
19206 /* We don't recognize any vendor extensions. */
19212 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
19213 mac_ptr, mac_end, abfd, offset_size,
19215 if (mac_ptr == NULL)
19219 } while (macinfo_type != 0);
19223 dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
19224 const char *comp_dir, int section_is_gnu)
19226 struct objfile *objfile = dwarf2_per_objfile->objfile;
19227 struct line_header *lh = cu->line_header;
19229 const gdb_byte *mac_ptr, *mac_end;
19230 struct macro_source_file *current_file = 0;
19231 enum dwarf_macro_record_type macinfo_type;
19232 unsigned int offset_size = cu->header.offset_size;
19233 const gdb_byte *opcode_definitions[256];
19234 struct cleanup *cleanup;
19235 htab_t include_hash;
19237 struct dwarf2_section_info *section;
19238 const char *section_name;
19240 if (cu->dwo_unit != NULL)
19242 if (section_is_gnu)
19244 section = &cu->dwo_unit->dwo_file->sections.macro;
19245 section_name = ".debug_macro.dwo";
19249 section = &cu->dwo_unit->dwo_file->sections.macinfo;
19250 section_name = ".debug_macinfo.dwo";
19255 if (section_is_gnu)
19257 section = &dwarf2_per_objfile->macro;
19258 section_name = ".debug_macro";
19262 section = &dwarf2_per_objfile->macinfo;
19263 section_name = ".debug_macinfo";
19267 dwarf2_read_section (objfile, section);
19268 if (section->buffer == NULL)
19270 complaint (&symfile_complaints, _("missing %s section"), section_name);
19273 abfd = section->asection->owner;
19275 /* First pass: Find the name of the base filename.
19276 This filename is needed in order to process all macros whose definition
19277 (or undefinition) comes from the command line. These macros are defined
19278 before the first DW_MACINFO_start_file entry, and yet still need to be
19279 associated to the base file.
19281 To determine the base file name, we scan the macro definitions until we
19282 reach the first DW_MACINFO_start_file entry. We then initialize
19283 CURRENT_FILE accordingly so that any macro definition found before the
19284 first DW_MACINFO_start_file can still be associated to the base file. */
19286 mac_ptr = section->buffer + offset;
19287 mac_end = section->buffer + section->size;
19289 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
19290 &offset_size, section_is_gnu);
19291 if (mac_ptr == NULL)
19293 /* We already issued a complaint. */
19299 /* Do we at least have room for a macinfo type byte? */
19300 if (mac_ptr >= mac_end)
19302 /* Complaint is printed during the second pass as GDB will probably
19303 stop the first pass earlier upon finding
19304 DW_MACINFO_start_file. */
19308 macinfo_type = read_1_byte (abfd, mac_ptr);
19311 /* Note that we rely on the fact that the corresponding GNU and
19312 DWARF constants are the same. */
19313 switch (macinfo_type)
19315 /* A zero macinfo type indicates the end of the macro
19320 case DW_MACRO_GNU_define:
19321 case DW_MACRO_GNU_undef:
19322 /* Only skip the data by MAC_PTR. */
19324 unsigned int bytes_read;
19326 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19327 mac_ptr += bytes_read;
19328 read_direct_string (abfd, mac_ptr, &bytes_read);
19329 mac_ptr += bytes_read;
19333 case DW_MACRO_GNU_start_file:
19335 unsigned int bytes_read;
19338 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19339 mac_ptr += bytes_read;
19340 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19341 mac_ptr += bytes_read;
19343 current_file = macro_start_file (file, line, current_file,
19344 comp_dir, lh, objfile);
19348 case DW_MACRO_GNU_end_file:
19349 /* No data to skip by MAC_PTR. */
19352 case DW_MACRO_GNU_define_indirect:
19353 case DW_MACRO_GNU_undef_indirect:
19354 case DW_MACRO_GNU_define_indirect_alt:
19355 case DW_MACRO_GNU_undef_indirect_alt:
19357 unsigned int bytes_read;
19359 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19360 mac_ptr += bytes_read;
19361 mac_ptr += offset_size;
19365 case DW_MACRO_GNU_transparent_include:
19366 case DW_MACRO_GNU_transparent_include_alt:
19367 /* Note that, according to the spec, a transparent include
19368 chain cannot call DW_MACRO_GNU_start_file. So, we can just
19369 skip this opcode. */
19370 mac_ptr += offset_size;
19373 case DW_MACINFO_vendor_ext:
19374 /* Only skip the data by MAC_PTR. */
19375 if (!section_is_gnu)
19377 unsigned int bytes_read;
19379 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
19380 mac_ptr += bytes_read;
19381 read_direct_string (abfd, mac_ptr, &bytes_read);
19382 mac_ptr += bytes_read;
19387 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
19388 mac_ptr, mac_end, abfd, offset_size,
19390 if (mac_ptr == NULL)
19394 } while (macinfo_type != 0 && current_file == NULL);
19396 /* Second pass: Process all entries.
19398 Use the AT_COMMAND_LINE flag to determine whether we are still processing
19399 command-line macro definitions/undefinitions. This flag is unset when we
19400 reach the first DW_MACINFO_start_file entry. */
19402 include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
19403 NULL, xcalloc, xfree);
19404 cleanup = make_cleanup_htab_delete (include_hash);
19405 mac_ptr = section->buffer + offset;
19406 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
19407 *slot = (void *) mac_ptr;
19408 dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
19409 current_file, lh, comp_dir, section,
19411 offset_size, objfile, include_hash);
19412 do_cleanups (cleanup);
19415 /* Check if the attribute's form is a DW_FORM_block*
19416 if so return true else false. */
19419 attr_form_is_block (struct attribute *attr)
19421 return (attr == NULL ? 0 :
19422 attr->form == DW_FORM_block1
19423 || attr->form == DW_FORM_block2
19424 || attr->form == DW_FORM_block4
19425 || attr->form == DW_FORM_block
19426 || attr->form == DW_FORM_exprloc);
19429 /* Return non-zero if ATTR's value is a section offset --- classes
19430 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
19431 You may use DW_UNSND (attr) to retrieve such offsets.
19433 Section 7.5.4, "Attribute Encodings", explains that no attribute
19434 may have a value that belongs to more than one of these classes; it
19435 would be ambiguous if we did, because we use the same forms for all
19439 attr_form_is_section_offset (struct attribute *attr)
19441 return (attr->form == DW_FORM_data4
19442 || attr->form == DW_FORM_data8
19443 || attr->form == DW_FORM_sec_offset);
19446 /* Return non-zero if ATTR's value falls in the 'constant' class, or
19447 zero otherwise. When this function returns true, you can apply
19448 dwarf2_get_attr_constant_value to it.
19450 However, note that for some attributes you must check
19451 attr_form_is_section_offset before using this test. DW_FORM_data4
19452 and DW_FORM_data8 are members of both the constant class, and of
19453 the classes that contain offsets into other debug sections
19454 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
19455 that, if an attribute's can be either a constant or one of the
19456 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
19457 taken as section offsets, not constants. */
19460 attr_form_is_constant (struct attribute *attr)
19462 switch (attr->form)
19464 case DW_FORM_sdata:
19465 case DW_FORM_udata:
19466 case DW_FORM_data1:
19467 case DW_FORM_data2:
19468 case DW_FORM_data4:
19469 case DW_FORM_data8:
19476 /* Return the .debug_loc section to use for CU.
19477 For DWO files use .debug_loc.dwo. */
19479 static struct dwarf2_section_info *
19480 cu_debug_loc_section (struct dwarf2_cu *cu)
19483 return &cu->dwo_unit->dwo_file->sections.loc;
19484 return &dwarf2_per_objfile->loc;
19487 /* A helper function that fills in a dwarf2_loclist_baton. */
19490 fill_in_loclist_baton (struct dwarf2_cu *cu,
19491 struct dwarf2_loclist_baton *baton,
19492 struct attribute *attr)
19494 struct dwarf2_section_info *section = cu_debug_loc_section (cu);
19496 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
19498 baton->per_cu = cu->per_cu;
19499 gdb_assert (baton->per_cu);
19500 /* We don't know how long the location list is, but make sure we
19501 don't run off the edge of the section. */
19502 baton->size = section->size - DW_UNSND (attr);
19503 baton->data = section->buffer + DW_UNSND (attr);
19504 baton->base_address = cu->base_address;
19505 baton->from_dwo = cu->dwo_unit != NULL;
19509 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
19510 struct dwarf2_cu *cu, int is_block)
19512 struct objfile *objfile = dwarf2_per_objfile->objfile;
19513 struct dwarf2_section_info *section = cu_debug_loc_section (cu);
19515 if (attr_form_is_section_offset (attr)
19516 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
19517 the section. If so, fall through to the complaint in the
19519 && DW_UNSND (attr) < dwarf2_section_size (objfile, section))
19521 struct dwarf2_loclist_baton *baton;
19523 baton = obstack_alloc (&objfile->objfile_obstack,
19524 sizeof (struct dwarf2_loclist_baton));
19526 fill_in_loclist_baton (cu, baton, attr);
19528 if (cu->base_known == 0)
19529 complaint (&symfile_complaints,
19530 _("Location list used without "
19531 "specifying the CU base address."));
19533 SYMBOL_ACLASS_INDEX (sym) = (is_block
19534 ? dwarf2_loclist_block_index
19535 : dwarf2_loclist_index);
19536 SYMBOL_LOCATION_BATON (sym) = baton;
19540 struct dwarf2_locexpr_baton *baton;
19542 baton = obstack_alloc (&objfile->objfile_obstack,
19543 sizeof (struct dwarf2_locexpr_baton));
19544 baton->per_cu = cu->per_cu;
19545 gdb_assert (baton->per_cu);
19547 if (attr_form_is_block (attr))
19549 /* Note that we're just copying the block's data pointer
19550 here, not the actual data. We're still pointing into the
19551 info_buffer for SYM's objfile; right now we never release
19552 that buffer, but when we do clean up properly this may
19554 baton->size = DW_BLOCK (attr)->size;
19555 baton->data = DW_BLOCK (attr)->data;
19559 dwarf2_invalid_attrib_class_complaint ("location description",
19560 SYMBOL_NATURAL_NAME (sym));
19564 SYMBOL_ACLASS_INDEX (sym) = (is_block
19565 ? dwarf2_locexpr_block_index
19566 : dwarf2_locexpr_index);
19567 SYMBOL_LOCATION_BATON (sym) = baton;
19571 /* Return the OBJFILE associated with the compilation unit CU. If CU
19572 came from a separate debuginfo file, then the master objfile is
19576 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
19578 struct objfile *objfile = per_cu->objfile;
19580 /* Return the master objfile, so that we can report and look up the
19581 correct file containing this variable. */
19582 if (objfile->separate_debug_objfile_backlink)
19583 objfile = objfile->separate_debug_objfile_backlink;
19588 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
19589 (CU_HEADERP is unused in such case) or prepare a temporary copy at
19590 CU_HEADERP first. */
19592 static const struct comp_unit_head *
19593 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
19594 struct dwarf2_per_cu_data *per_cu)
19596 const gdb_byte *info_ptr;
19599 return &per_cu->cu->header;
19601 info_ptr = per_cu->section->buffer + per_cu->offset.sect_off;
19603 memset (cu_headerp, 0, sizeof (*cu_headerp));
19604 read_comp_unit_head (cu_headerp, info_ptr, per_cu->objfile->obfd);
19609 /* Return the address size given in the compilation unit header for CU. */
19612 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
19614 struct comp_unit_head cu_header_local;
19615 const struct comp_unit_head *cu_headerp;
19617 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
19619 return cu_headerp->addr_size;
19622 /* Return the offset size given in the compilation unit header for CU. */
19625 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
19627 struct comp_unit_head cu_header_local;
19628 const struct comp_unit_head *cu_headerp;
19630 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
19632 return cu_headerp->offset_size;
19635 /* See its dwarf2loc.h declaration. */
19638 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
19640 struct comp_unit_head cu_header_local;
19641 const struct comp_unit_head *cu_headerp;
19643 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
19645 if (cu_headerp->version == 2)
19646 return cu_headerp->addr_size;
19648 return cu_headerp->offset_size;
19651 /* Return the text offset of the CU. The returned offset comes from
19652 this CU's objfile. If this objfile came from a separate debuginfo
19653 file, then the offset may be different from the corresponding
19654 offset in the parent objfile. */
19657 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
19659 struct objfile *objfile = per_cu->objfile;
19661 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
19664 /* Locate the .debug_info compilation unit from CU's objfile which contains
19665 the DIE at OFFSET. Raises an error on failure. */
19667 static struct dwarf2_per_cu_data *
19668 dwarf2_find_containing_comp_unit (sect_offset offset,
19669 unsigned int offset_in_dwz,
19670 struct objfile *objfile)
19672 struct dwarf2_per_cu_data *this_cu;
19674 const sect_offset *cu_off;
19677 high = dwarf2_per_objfile->n_comp_units - 1;
19680 struct dwarf2_per_cu_data *mid_cu;
19681 int mid = low + (high - low) / 2;
19683 mid_cu = dwarf2_per_objfile->all_comp_units[mid];
19684 cu_off = &mid_cu->offset;
19685 if (mid_cu->is_dwz > offset_in_dwz
19686 || (mid_cu->is_dwz == offset_in_dwz
19687 && cu_off->sect_off >= offset.sect_off))
19692 gdb_assert (low == high);
19693 this_cu = dwarf2_per_objfile->all_comp_units[low];
19694 cu_off = &this_cu->offset;
19695 if (this_cu->is_dwz != offset_in_dwz || cu_off->sect_off > offset.sect_off)
19697 if (low == 0 || this_cu->is_dwz != offset_in_dwz)
19698 error (_("Dwarf Error: could not find partial DIE containing "
19699 "offset 0x%lx [in module %s]"),
19700 (long) offset.sect_off, bfd_get_filename (objfile->obfd));
19702 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset.sect_off
19703 <= offset.sect_off);
19704 return dwarf2_per_objfile->all_comp_units[low-1];
19708 this_cu = dwarf2_per_objfile->all_comp_units[low];
19709 if (low == dwarf2_per_objfile->n_comp_units - 1
19710 && offset.sect_off >= this_cu->offset.sect_off + this_cu->length)
19711 error (_("invalid dwarf2 offset %u"), offset.sect_off);
19712 gdb_assert (offset.sect_off < this_cu->offset.sect_off + this_cu->length);
19717 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19720 init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu)
19722 memset (cu, 0, sizeof (*cu));
19724 cu->per_cu = per_cu;
19725 cu->objfile = per_cu->objfile;
19726 obstack_init (&cu->comp_unit_obstack);
19729 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19732 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
19733 enum language pretend_language)
19735 struct attribute *attr;
19737 /* Set the language we're debugging. */
19738 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
19740 set_cu_language (DW_UNSND (attr), cu);
19743 cu->language = pretend_language;
19744 cu->language_defn = language_def (cu->language);
19747 attr = dwarf2_attr (comp_unit_die, DW_AT_producer, cu);
19749 cu->producer = DW_STRING (attr);
19752 /* Release one cached compilation unit, CU. We unlink it from the tree
19753 of compilation units, but we don't remove it from the read_in_chain;
19754 the caller is responsible for that.
19755 NOTE: DATA is a void * because this function is also used as a
19756 cleanup routine. */
19759 free_heap_comp_unit (void *data)
19761 struct dwarf2_cu *cu = data;
19763 gdb_assert (cu->per_cu != NULL);
19764 cu->per_cu->cu = NULL;
19767 obstack_free (&cu->comp_unit_obstack, NULL);
19772 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19773 when we're finished with it. We can't free the pointer itself, but be
19774 sure to unlink it from the cache. Also release any associated storage. */
19777 free_stack_comp_unit (void *data)
19779 struct dwarf2_cu *cu = data;
19781 gdb_assert (cu->per_cu != NULL);
19782 cu->per_cu->cu = NULL;
19785 obstack_free (&cu->comp_unit_obstack, NULL);
19786 cu->partial_dies = NULL;
19789 /* Free all cached compilation units. */
19792 free_cached_comp_units (void *data)
19794 struct dwarf2_per_cu_data *per_cu, **last_chain;
19796 per_cu = dwarf2_per_objfile->read_in_chain;
19797 last_chain = &dwarf2_per_objfile->read_in_chain;
19798 while (per_cu != NULL)
19800 struct dwarf2_per_cu_data *next_cu;
19802 next_cu = per_cu->cu->read_in_chain;
19804 free_heap_comp_unit (per_cu->cu);
19805 *last_chain = next_cu;
19811 /* Increase the age counter on each cached compilation unit, and free
19812 any that are too old. */
19815 age_cached_comp_units (void)
19817 struct dwarf2_per_cu_data *per_cu, **last_chain;
19819 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
19820 per_cu = dwarf2_per_objfile->read_in_chain;
19821 while (per_cu != NULL)
19823 per_cu->cu->last_used ++;
19824 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
19825 dwarf2_mark (per_cu->cu);
19826 per_cu = per_cu->cu->read_in_chain;
19829 per_cu = dwarf2_per_objfile->read_in_chain;
19830 last_chain = &dwarf2_per_objfile->read_in_chain;
19831 while (per_cu != NULL)
19833 struct dwarf2_per_cu_data *next_cu;
19835 next_cu = per_cu->cu->read_in_chain;
19837 if (!per_cu->cu->mark)
19839 free_heap_comp_unit (per_cu->cu);
19840 *last_chain = next_cu;
19843 last_chain = &per_cu->cu->read_in_chain;
19849 /* Remove a single compilation unit from the cache. */
19852 free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu)
19854 struct dwarf2_per_cu_data *per_cu, **last_chain;
19856 per_cu = dwarf2_per_objfile->read_in_chain;
19857 last_chain = &dwarf2_per_objfile->read_in_chain;
19858 while (per_cu != NULL)
19860 struct dwarf2_per_cu_data *next_cu;
19862 next_cu = per_cu->cu->read_in_chain;
19864 if (per_cu == target_per_cu)
19866 free_heap_comp_unit (per_cu->cu);
19868 *last_chain = next_cu;
19872 last_chain = &per_cu->cu->read_in_chain;
19878 /* Release all extra memory associated with OBJFILE. */
19881 dwarf2_free_objfile (struct objfile *objfile)
19883 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
19885 if (dwarf2_per_objfile == NULL)
19888 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19889 free_cached_comp_units (NULL);
19891 if (dwarf2_per_objfile->quick_file_names_table)
19892 htab_delete (dwarf2_per_objfile->quick_file_names_table);
19894 /* Everything else should be on the objfile obstack. */
19897 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19898 We store these in a hash table separate from the DIEs, and preserve them
19899 when the DIEs are flushed out of cache.
19901 The CU "per_cu" pointer is needed because offset alone is not enough to
19902 uniquely identify the type. A file may have multiple .debug_types sections,
19903 or the type may come from a DWO file. Furthermore, while it's more logical
19904 to use per_cu->section+offset, with Fission the section with the data is in
19905 the DWO file but we don't know that section at the point we need it.
19906 We have to use something in dwarf2_per_cu_data (or the pointer to it)
19907 because we can enter the lookup routine, get_die_type_at_offset, from
19908 outside this file, and thus won't necessarily have PER_CU->cu.
19909 Fortunately, PER_CU is stable for the life of the objfile. */
19911 struct dwarf2_per_cu_offset_and_type
19913 const struct dwarf2_per_cu_data *per_cu;
19914 sect_offset offset;
19918 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19921 per_cu_offset_and_type_hash (const void *item)
19923 const struct dwarf2_per_cu_offset_and_type *ofs = item;
19925 return (uintptr_t) ofs->per_cu + ofs->offset.sect_off;
19928 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19931 per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
19933 const struct dwarf2_per_cu_offset_and_type *ofs_lhs = item_lhs;
19934 const struct dwarf2_per_cu_offset_and_type *ofs_rhs = item_rhs;
19936 return (ofs_lhs->per_cu == ofs_rhs->per_cu
19937 && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off);
19940 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19941 table if necessary. For convenience, return TYPE.
19943 The DIEs reading must have careful ordering to:
19944 * Not cause infite loops trying to read in DIEs as a prerequisite for
19945 reading current DIE.
19946 * Not trying to dereference contents of still incompletely read in types
19947 while reading in other DIEs.
19948 * Enable referencing still incompletely read in types just by a pointer to
19949 the type without accessing its fields.
19951 Therefore caller should follow these rules:
19952 * Try to fetch any prerequisite types we may need to build this DIE type
19953 before building the type and calling set_die_type.
19954 * After building type call set_die_type for current DIE as soon as
19955 possible before fetching more types to complete the current type.
19956 * Make the type as complete as possible before fetching more types. */
19958 static struct type *
19959 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
19961 struct dwarf2_per_cu_offset_and_type **slot, ofs;
19962 struct objfile *objfile = cu->objfile;
19964 /* For Ada types, make sure that the gnat-specific data is always
19965 initialized (if not already set). There are a few types where
19966 we should not be doing so, because the type-specific area is
19967 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19968 where the type-specific area is used to store the floatformat).
19969 But this is not a problem, because the gnat-specific information
19970 is actually not needed for these types. */
19971 if (need_gnat_info (cu)
19972 && TYPE_CODE (type) != TYPE_CODE_FUNC
19973 && TYPE_CODE (type) != TYPE_CODE_FLT
19974 && !HAVE_GNAT_AUX_INFO (type))
19975 INIT_GNAT_SPECIFIC (type);
19977 if (dwarf2_per_objfile->die_type_hash == NULL)
19979 dwarf2_per_objfile->die_type_hash =
19980 htab_create_alloc_ex (127,
19981 per_cu_offset_and_type_hash,
19982 per_cu_offset_and_type_eq,
19984 &objfile->objfile_obstack,
19985 hashtab_obstack_allocate,
19986 dummy_obstack_deallocate);
19989 ofs.per_cu = cu->per_cu;
19990 ofs.offset = die->offset;
19992 slot = (struct dwarf2_per_cu_offset_and_type **)
19993 htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT);
19995 complaint (&symfile_complaints,
19996 _("A problem internal to GDB: DIE 0x%x has type already set"),
19997 die->offset.sect_off);
19998 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
20003 /* Look up the type for the die at OFFSET in PER_CU in die_type_hash,
20004 or return NULL if the die does not have a saved type. */
20006 static struct type *
20007 get_die_type_at_offset (sect_offset offset,
20008 struct dwarf2_per_cu_data *per_cu)
20010 struct dwarf2_per_cu_offset_and_type *slot, ofs;
20012 if (dwarf2_per_objfile->die_type_hash == NULL)
20015 ofs.per_cu = per_cu;
20016 ofs.offset = offset;
20017 slot = htab_find (dwarf2_per_objfile->die_type_hash, &ofs);
20024 /* Look up the type for DIE in CU in die_type_hash,
20025 or return NULL if DIE does not have a saved type. */
20027 static struct type *
20028 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
20030 return get_die_type_at_offset (die->offset, cu->per_cu);
20033 /* Add a dependence relationship from CU to REF_PER_CU. */
20036 dwarf2_add_dependence (struct dwarf2_cu *cu,
20037 struct dwarf2_per_cu_data *ref_per_cu)
20041 if (cu->dependencies == NULL)
20043 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
20044 NULL, &cu->comp_unit_obstack,
20045 hashtab_obstack_allocate,
20046 dummy_obstack_deallocate);
20048 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
20050 *slot = ref_per_cu;
20053 /* Subroutine of dwarf2_mark to pass to htab_traverse.
20054 Set the mark field in every compilation unit in the
20055 cache that we must keep because we are keeping CU. */
20058 dwarf2_mark_helper (void **slot, void *data)
20060 struct dwarf2_per_cu_data *per_cu;
20062 per_cu = (struct dwarf2_per_cu_data *) *slot;
20064 /* cu->dependencies references may not yet have been ever read if QUIT aborts
20065 reading of the chain. As such dependencies remain valid it is not much
20066 useful to track and undo them during QUIT cleanups. */
20067 if (per_cu->cu == NULL)
20070 if (per_cu->cu->mark)
20072 per_cu->cu->mark = 1;
20074 if (per_cu->cu->dependencies != NULL)
20075 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
20080 /* Set the mark field in CU and in every other compilation unit in the
20081 cache that we must keep because we are keeping CU. */
20084 dwarf2_mark (struct dwarf2_cu *cu)
20089 if (cu->dependencies != NULL)
20090 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
20094 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
20098 per_cu->cu->mark = 0;
20099 per_cu = per_cu->cu->read_in_chain;
20103 /* Trivial hash function for partial_die_info: the hash value of a DIE
20104 is its offset in .debug_info for this objfile. */
20107 partial_die_hash (const void *item)
20109 const struct partial_die_info *part_die = item;
20111 return part_die->offset.sect_off;
20114 /* Trivial comparison function for partial_die_info structures: two DIEs
20115 are equal if they have the same offset. */
20118 partial_die_eq (const void *item_lhs, const void *item_rhs)
20120 const struct partial_die_info *part_die_lhs = item_lhs;
20121 const struct partial_die_info *part_die_rhs = item_rhs;
20123 return part_die_lhs->offset.sect_off == part_die_rhs->offset.sect_off;
20126 static struct cmd_list_element *set_dwarf2_cmdlist;
20127 static struct cmd_list_element *show_dwarf2_cmdlist;
20130 set_dwarf2_cmd (char *args, int from_tty)
20132 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
20136 show_dwarf2_cmd (char *args, int from_tty)
20138 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
20141 /* Free data associated with OBJFILE, if necessary. */
20144 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
20146 struct dwarf2_per_objfile *data = d;
20149 for (ix = 0; ix < dwarf2_per_objfile->n_comp_units; ++ix)
20150 VEC_free (dwarf2_per_cu_ptr,
20151 dwarf2_per_objfile->all_comp_units[ix]->imported_symtabs);
20153 for (ix = 0; ix < dwarf2_per_objfile->n_type_units; ++ix)
20154 VEC_free (dwarf2_per_cu_ptr,
20155 dwarf2_per_objfile->all_type_units[ix]->per_cu.imported_symtabs);
20157 VEC_free (dwarf2_section_info_def, data->types);
20159 if (data->dwo_files)
20160 free_dwo_files (data->dwo_files, objfile);
20161 if (data->dwp_file)
20162 gdb_bfd_unref (data->dwp_file->dbfd);
20164 if (data->dwz_file && data->dwz_file->dwz_bfd)
20165 gdb_bfd_unref (data->dwz_file->dwz_bfd);
20169 /* The "save gdb-index" command. */
20171 /* The contents of the hash table we create when building the string
20173 struct strtab_entry
20175 offset_type offset;
20179 /* Hash function for a strtab_entry.
20181 Function is used only during write_hash_table so no index format backward
20182 compatibility is needed. */
20185 hash_strtab_entry (const void *e)
20187 const struct strtab_entry *entry = e;
20188 return mapped_index_string_hash (INT_MAX, entry->str);
20191 /* Equality function for a strtab_entry. */
20194 eq_strtab_entry (const void *a, const void *b)
20196 const struct strtab_entry *ea = a;
20197 const struct strtab_entry *eb = b;
20198 return !strcmp (ea->str, eb->str);
20201 /* Create a strtab_entry hash table. */
20204 create_strtab (void)
20206 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
20207 xfree, xcalloc, xfree);
20210 /* Add a string to the constant pool. Return the string's offset in
20214 add_string (htab_t table, struct obstack *cpool, const char *str)
20217 struct strtab_entry entry;
20218 struct strtab_entry *result;
20221 slot = htab_find_slot (table, &entry, INSERT);
20226 result = XNEW (struct strtab_entry);
20227 result->offset = obstack_object_size (cpool);
20229 obstack_grow_str0 (cpool, str);
20232 return result->offset;
20235 /* An entry in the symbol table. */
20236 struct symtab_index_entry
20238 /* The name of the symbol. */
20240 /* The offset of the name in the constant pool. */
20241 offset_type index_offset;
20242 /* A sorted vector of the indices of all the CUs that hold an object
20244 VEC (offset_type) *cu_indices;
20247 /* The symbol table. This is a power-of-2-sized hash table. */
20248 struct mapped_symtab
20250 offset_type n_elements;
20252 struct symtab_index_entry **data;
20255 /* Hash function for a symtab_index_entry. */
20258 hash_symtab_entry (const void *e)
20260 const struct symtab_index_entry *entry = e;
20261 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
20262 sizeof (offset_type) * VEC_length (offset_type,
20263 entry->cu_indices),
20267 /* Equality function for a symtab_index_entry. */
20270 eq_symtab_entry (const void *a, const void *b)
20272 const struct symtab_index_entry *ea = a;
20273 const struct symtab_index_entry *eb = b;
20274 int len = VEC_length (offset_type, ea->cu_indices);
20275 if (len != VEC_length (offset_type, eb->cu_indices))
20277 return !memcmp (VEC_address (offset_type, ea->cu_indices),
20278 VEC_address (offset_type, eb->cu_indices),
20279 sizeof (offset_type) * len);
20282 /* Destroy a symtab_index_entry. */
20285 delete_symtab_entry (void *p)
20287 struct symtab_index_entry *entry = p;
20288 VEC_free (offset_type, entry->cu_indices);
20292 /* Create a hash table holding symtab_index_entry objects. */
20295 create_symbol_hash_table (void)
20297 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
20298 delete_symtab_entry, xcalloc, xfree);
20301 /* Create a new mapped symtab object. */
20303 static struct mapped_symtab *
20304 create_mapped_symtab (void)
20306 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
20307 symtab->n_elements = 0;
20308 symtab->size = 1024;
20309 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
20313 /* Destroy a mapped_symtab. */
20316 cleanup_mapped_symtab (void *p)
20318 struct mapped_symtab *symtab = p;
20319 /* The contents of the array are freed when the other hash table is
20321 xfree (symtab->data);
20325 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
20328 Function is used only during write_hash_table so no index format backward
20329 compatibility is needed. */
20331 static struct symtab_index_entry **
20332 find_slot (struct mapped_symtab *symtab, const char *name)
20334 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
20336 index = hash & (symtab->size - 1);
20337 step = ((hash * 17) & (symtab->size - 1)) | 1;
20341 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
20342 return &symtab->data[index];
20343 index = (index + step) & (symtab->size - 1);
20347 /* Expand SYMTAB's hash table. */
20350 hash_expand (struct mapped_symtab *symtab)
20352 offset_type old_size = symtab->size;
20354 struct symtab_index_entry **old_entries = symtab->data;
20357 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
20359 for (i = 0; i < old_size; ++i)
20361 if (old_entries[i])
20363 struct symtab_index_entry **slot = find_slot (symtab,
20364 old_entries[i]->name);
20365 *slot = old_entries[i];
20369 xfree (old_entries);
20372 /* Add an entry to SYMTAB. NAME is the name of the symbol.
20373 CU_INDEX is the index of the CU in which the symbol appears.
20374 IS_STATIC is one if the symbol is static, otherwise zero (global). */
20377 add_index_entry (struct mapped_symtab *symtab, const char *name,
20378 int is_static, gdb_index_symbol_kind kind,
20379 offset_type cu_index)
20381 struct symtab_index_entry **slot;
20382 offset_type cu_index_and_attrs;
20384 ++symtab->n_elements;
20385 if (4 * symtab->n_elements / 3 >= symtab->size)
20386 hash_expand (symtab);
20388 slot = find_slot (symtab, name);
20391 *slot = XNEW (struct symtab_index_entry);
20392 (*slot)->name = name;
20393 /* index_offset is set later. */
20394 (*slot)->cu_indices = NULL;
20397 cu_index_and_attrs = 0;
20398 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs, cu_index);
20399 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs, is_static);
20400 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs, kind);
20402 /* We don't want to record an index value twice as we want to avoid the
20404 We process all global symbols and then all static symbols
20405 (which would allow us to avoid the duplication by only having to check
20406 the last entry pushed), but a symbol could have multiple kinds in one CU.
20407 To keep things simple we don't worry about the duplication here and
20408 sort and uniqufy the list after we've processed all symbols. */
20409 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index_and_attrs);
20412 /* qsort helper routine for uniquify_cu_indices. */
20415 offset_type_compare (const void *ap, const void *bp)
20417 offset_type a = *(offset_type *) ap;
20418 offset_type b = *(offset_type *) bp;
20420 return (a > b) - (b > a);
20423 /* Sort and remove duplicates of all symbols' cu_indices lists. */
20426 uniquify_cu_indices (struct mapped_symtab *symtab)
20430 for (i = 0; i < symtab->size; ++i)
20432 struct symtab_index_entry *entry = symtab->data[i];
20435 && entry->cu_indices != NULL)
20437 unsigned int next_to_insert, next_to_check;
20438 offset_type last_value;
20440 qsort (VEC_address (offset_type, entry->cu_indices),
20441 VEC_length (offset_type, entry->cu_indices),
20442 sizeof (offset_type), offset_type_compare);
20444 last_value = VEC_index (offset_type, entry->cu_indices, 0);
20445 next_to_insert = 1;
20446 for (next_to_check = 1;
20447 next_to_check < VEC_length (offset_type, entry->cu_indices);
20450 if (VEC_index (offset_type, entry->cu_indices, next_to_check)
20453 last_value = VEC_index (offset_type, entry->cu_indices,
20455 VEC_replace (offset_type, entry->cu_indices, next_to_insert,
20460 VEC_truncate (offset_type, entry->cu_indices, next_to_insert);
20465 /* Add a vector of indices to the constant pool. */
20468 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
20469 struct symtab_index_entry *entry)
20473 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
20476 offset_type len = VEC_length (offset_type, entry->cu_indices);
20477 offset_type val = MAYBE_SWAP (len);
20482 entry->index_offset = obstack_object_size (cpool);
20484 obstack_grow (cpool, &val, sizeof (val));
20486 VEC_iterate (offset_type, entry->cu_indices, i, iter);
20489 val = MAYBE_SWAP (iter);
20490 obstack_grow (cpool, &val, sizeof (val));
20495 struct symtab_index_entry *old_entry = *slot;
20496 entry->index_offset = old_entry->index_offset;
20499 return entry->index_offset;
20502 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
20503 constant pool entries going into the obstack CPOOL. */
20506 write_hash_table (struct mapped_symtab *symtab,
20507 struct obstack *output, struct obstack *cpool)
20510 htab_t symbol_hash_table;
20513 symbol_hash_table = create_symbol_hash_table ();
20514 str_table = create_strtab ();
20516 /* We add all the index vectors to the constant pool first, to
20517 ensure alignment is ok. */
20518 for (i = 0; i < symtab->size; ++i)
20520 if (symtab->data[i])
20521 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
20524 /* Now write out the hash table. */
20525 for (i = 0; i < symtab->size; ++i)
20527 offset_type str_off, vec_off;
20529 if (symtab->data[i])
20531 str_off = add_string (str_table, cpool, symtab->data[i]->name);
20532 vec_off = symtab->data[i]->index_offset;
20536 /* While 0 is a valid constant pool index, it is not valid
20537 to have 0 for both offsets. */
20542 str_off = MAYBE_SWAP (str_off);
20543 vec_off = MAYBE_SWAP (vec_off);
20545 obstack_grow (output, &str_off, sizeof (str_off));
20546 obstack_grow (output, &vec_off, sizeof (vec_off));
20549 htab_delete (str_table);
20550 htab_delete (symbol_hash_table);
20553 /* Struct to map psymtab to CU index in the index file. */
20554 struct psymtab_cu_index_map
20556 struct partial_symtab *psymtab;
20557 unsigned int cu_index;
20561 hash_psymtab_cu_index (const void *item)
20563 const struct psymtab_cu_index_map *map = item;
20565 return htab_hash_pointer (map->psymtab);
20569 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
20571 const struct psymtab_cu_index_map *lhs = item_lhs;
20572 const struct psymtab_cu_index_map *rhs = item_rhs;
20574 return lhs->psymtab == rhs->psymtab;
20577 /* Helper struct for building the address table. */
20578 struct addrmap_index_data
20580 struct objfile *objfile;
20581 struct obstack *addr_obstack;
20582 htab_t cu_index_htab;
20584 /* Non-zero if the previous_* fields are valid.
20585 We can't write an entry until we see the next entry (since it is only then
20586 that we know the end of the entry). */
20587 int previous_valid;
20588 /* Index of the CU in the table of all CUs in the index file. */
20589 unsigned int previous_cu_index;
20590 /* Start address of the CU. */
20591 CORE_ADDR previous_cu_start;
20594 /* Write an address entry to OBSTACK. */
20597 add_address_entry (struct objfile *objfile, struct obstack *obstack,
20598 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
20600 offset_type cu_index_to_write;
20602 CORE_ADDR baseaddr;
20604 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
20606 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
20607 obstack_grow (obstack, addr, 8);
20608 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
20609 obstack_grow (obstack, addr, 8);
20610 cu_index_to_write = MAYBE_SWAP (cu_index);
20611 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
20614 /* Worker function for traversing an addrmap to build the address table. */
20617 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
20619 struct addrmap_index_data *data = datap;
20620 struct partial_symtab *pst = obj;
20622 if (data->previous_valid)
20623 add_address_entry (data->objfile, data->addr_obstack,
20624 data->previous_cu_start, start_addr,
20625 data->previous_cu_index);
20627 data->previous_cu_start = start_addr;
20630 struct psymtab_cu_index_map find_map, *map;
20631 find_map.psymtab = pst;
20632 map = htab_find (data->cu_index_htab, &find_map);
20633 gdb_assert (map != NULL);
20634 data->previous_cu_index = map->cu_index;
20635 data->previous_valid = 1;
20638 data->previous_valid = 0;
20643 /* Write OBJFILE's address map to OBSTACK.
20644 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
20645 in the index file. */
20648 write_address_map (struct objfile *objfile, struct obstack *obstack,
20649 htab_t cu_index_htab)
20651 struct addrmap_index_data addrmap_index_data;
20653 /* When writing the address table, we have to cope with the fact that
20654 the addrmap iterator only provides the start of a region; we have to
20655 wait until the next invocation to get the start of the next region. */
20657 addrmap_index_data.objfile = objfile;
20658 addrmap_index_data.addr_obstack = obstack;
20659 addrmap_index_data.cu_index_htab = cu_index_htab;
20660 addrmap_index_data.previous_valid = 0;
20662 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
20663 &addrmap_index_data);
20665 /* It's highly unlikely the last entry (end address = 0xff...ff)
20666 is valid, but we should still handle it.
20667 The end address is recorded as the start of the next region, but that
20668 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20670 if (addrmap_index_data.previous_valid)
20671 add_address_entry (objfile, obstack,
20672 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
20673 addrmap_index_data.previous_cu_index);
20676 /* Return the symbol kind of PSYM. */
20678 static gdb_index_symbol_kind
20679 symbol_kind (struct partial_symbol *psym)
20681 domain_enum domain = PSYMBOL_DOMAIN (psym);
20682 enum address_class aclass = PSYMBOL_CLASS (psym);
20690 return GDB_INDEX_SYMBOL_KIND_FUNCTION;
20692 return GDB_INDEX_SYMBOL_KIND_TYPE;
20694 case LOC_CONST_BYTES:
20695 case LOC_OPTIMIZED_OUT:
20697 return GDB_INDEX_SYMBOL_KIND_VARIABLE;
20699 /* Note: It's currently impossible to recognize psyms as enum values
20700 short of reading the type info. For now punt. */
20701 return GDB_INDEX_SYMBOL_KIND_VARIABLE;
20703 /* There are other LOC_FOO values that one might want to classify
20704 as variables, but dwarf2read.c doesn't currently use them. */
20705 return GDB_INDEX_SYMBOL_KIND_OTHER;
20707 case STRUCT_DOMAIN:
20708 return GDB_INDEX_SYMBOL_KIND_TYPE;
20710 return GDB_INDEX_SYMBOL_KIND_OTHER;
20714 /* Add a list of partial symbols to SYMTAB. */
20717 write_psymbols (struct mapped_symtab *symtab,
20719 struct partial_symbol **psymp,
20721 offset_type cu_index,
20724 for (; count-- > 0; ++psymp)
20726 struct partial_symbol *psym = *psymp;
20729 if (SYMBOL_LANGUAGE (psym) == language_ada)
20730 error (_("Ada is not currently supported by the index"));
20732 /* Only add a given psymbol once. */
20733 slot = htab_find_slot (psyms_seen, psym, INSERT);
20736 gdb_index_symbol_kind kind = symbol_kind (psym);
20739 add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym),
20740 is_static, kind, cu_index);
20745 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20746 exception if there is an error. */
20749 write_obstack (FILE *file, struct obstack *obstack)
20751 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
20753 != obstack_object_size (obstack))
20754 error (_("couldn't data write to file"));
20757 /* Unlink a file if the argument is not NULL. */
20760 unlink_if_set (void *p)
20762 char **filename = p;
20764 unlink (*filename);
20767 /* A helper struct used when iterating over debug_types. */
20768 struct signatured_type_index_data
20770 struct objfile *objfile;
20771 struct mapped_symtab *symtab;
20772 struct obstack *types_list;
20777 /* A helper function that writes a single signatured_type to an
20781 write_one_signatured_type (void **slot, void *d)
20783 struct signatured_type_index_data *info = d;
20784 struct signatured_type *entry = (struct signatured_type *) *slot;
20785 struct partial_symtab *psymtab = entry->per_cu.v.psymtab;
20788 write_psymbols (info->symtab,
20790 info->objfile->global_psymbols.list
20791 + psymtab->globals_offset,
20792 psymtab->n_global_syms, info->cu_index,
20794 write_psymbols (info->symtab,
20796 info->objfile->static_psymbols.list
20797 + psymtab->statics_offset,
20798 psymtab->n_static_syms, info->cu_index,
20801 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
20802 entry->per_cu.offset.sect_off);
20803 obstack_grow (info->types_list, val, 8);
20804 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
20805 entry->type_offset_in_tu.cu_off);
20806 obstack_grow (info->types_list, val, 8);
20807 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
20808 obstack_grow (info->types_list, val, 8);
20815 /* Recurse into all "included" dependencies and write their symbols as
20816 if they appeared in this psymtab. */
20819 recursively_write_psymbols (struct objfile *objfile,
20820 struct partial_symtab *psymtab,
20821 struct mapped_symtab *symtab,
20823 offset_type cu_index)
20827 for (i = 0; i < psymtab->number_of_dependencies; ++i)
20828 if (psymtab->dependencies[i]->user != NULL)
20829 recursively_write_psymbols (objfile, psymtab->dependencies[i],
20830 symtab, psyms_seen, cu_index);
20832 write_psymbols (symtab,
20834 objfile->global_psymbols.list + psymtab->globals_offset,
20835 psymtab->n_global_syms, cu_index,
20837 write_psymbols (symtab,
20839 objfile->static_psymbols.list + psymtab->statics_offset,
20840 psymtab->n_static_syms, cu_index,
20844 /* Create an index file for OBJFILE in the directory DIR. */
20847 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
20849 struct cleanup *cleanup;
20850 char *filename, *cleanup_filename;
20851 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
20852 struct obstack cu_list, types_cu_list;
20855 struct mapped_symtab *symtab;
20856 offset_type val, size_of_contents, total_len;
20859 htab_t cu_index_htab;
20860 struct psymtab_cu_index_map *psymtab_cu_index_map;
20862 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
20865 if (dwarf2_per_objfile->using_index)
20866 error (_("Cannot use an index to create the index"));
20868 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
20869 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20871 if (stat (objfile->name, &st) < 0)
20872 perror_with_name (objfile->name);
20874 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
20875 INDEX_SUFFIX, (char *) NULL);
20876 cleanup = make_cleanup (xfree, filename);
20878 out_file = gdb_fopen_cloexec (filename, "wb");
20880 error (_("Can't open `%s' for writing"), filename);
20882 cleanup_filename = filename;
20883 make_cleanup (unlink_if_set, &cleanup_filename);
20885 symtab = create_mapped_symtab ();
20886 make_cleanup (cleanup_mapped_symtab, symtab);
20888 obstack_init (&addr_obstack);
20889 make_cleanup_obstack_free (&addr_obstack);
20891 obstack_init (&cu_list);
20892 make_cleanup_obstack_free (&cu_list);
20894 obstack_init (&types_cu_list);
20895 make_cleanup_obstack_free (&types_cu_list);
20897 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
20898 NULL, xcalloc, xfree);
20899 make_cleanup_htab_delete (psyms_seen);
20901 /* While we're scanning CU's create a table that maps a psymtab pointer
20902 (which is what addrmap records) to its index (which is what is recorded
20903 in the index file). This will later be needed to write the address
20905 cu_index_htab = htab_create_alloc (100,
20906 hash_psymtab_cu_index,
20907 eq_psymtab_cu_index,
20908 NULL, xcalloc, xfree);
20909 make_cleanup_htab_delete (cu_index_htab);
20910 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
20911 xmalloc (sizeof (struct psymtab_cu_index_map)
20912 * dwarf2_per_objfile->n_comp_units);
20913 make_cleanup (xfree, psymtab_cu_index_map);
20915 /* The CU list is already sorted, so we don't need to do additional
20916 work here. Also, the debug_types entries do not appear in
20917 all_comp_units, but only in their own hash table. */
20918 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
20920 struct dwarf2_per_cu_data *per_cu
20921 = dwarf2_per_objfile->all_comp_units[i];
20922 struct partial_symtab *psymtab = per_cu->v.psymtab;
20924 struct psymtab_cu_index_map *map;
20927 if (psymtab->user == NULL)
20928 recursively_write_psymbols (objfile, psymtab, symtab, psyms_seen, i);
20930 map = &psymtab_cu_index_map[i];
20931 map->psymtab = psymtab;
20933 slot = htab_find_slot (cu_index_htab, map, INSERT);
20934 gdb_assert (slot != NULL);
20935 gdb_assert (*slot == NULL);
20938 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
20939 per_cu->offset.sect_off);
20940 obstack_grow (&cu_list, val, 8);
20941 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
20942 obstack_grow (&cu_list, val, 8);
20945 /* Dump the address map. */
20946 write_address_map (objfile, &addr_obstack, cu_index_htab);
20948 /* Write out the .debug_type entries, if any. */
20949 if (dwarf2_per_objfile->signatured_types)
20951 struct signatured_type_index_data sig_data;
20953 sig_data.objfile = objfile;
20954 sig_data.symtab = symtab;
20955 sig_data.types_list = &types_cu_list;
20956 sig_data.psyms_seen = psyms_seen;
20957 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
20958 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
20959 write_one_signatured_type, &sig_data);
20962 /* Now that we've processed all symbols we can shrink their cu_indices
20964 uniquify_cu_indices (symtab);
20966 obstack_init (&constant_pool);
20967 make_cleanup_obstack_free (&constant_pool);
20968 obstack_init (&symtab_obstack);
20969 make_cleanup_obstack_free (&symtab_obstack);
20970 write_hash_table (symtab, &symtab_obstack, &constant_pool);
20972 obstack_init (&contents);
20973 make_cleanup_obstack_free (&contents);
20974 size_of_contents = 6 * sizeof (offset_type);
20975 total_len = size_of_contents;
20977 /* The version number. */
20978 val = MAYBE_SWAP (8);
20979 obstack_grow (&contents, &val, sizeof (val));
20981 /* The offset of the CU list from the start of the file. */
20982 val = MAYBE_SWAP (total_len);
20983 obstack_grow (&contents, &val, sizeof (val));
20984 total_len += obstack_object_size (&cu_list);
20986 /* The offset of the types CU list from the start of the file. */
20987 val = MAYBE_SWAP (total_len);
20988 obstack_grow (&contents, &val, sizeof (val));
20989 total_len += obstack_object_size (&types_cu_list);
20991 /* The offset of the address table from the start of the file. */
20992 val = MAYBE_SWAP (total_len);
20993 obstack_grow (&contents, &val, sizeof (val));
20994 total_len += obstack_object_size (&addr_obstack);
20996 /* The offset of the symbol table from the start of the file. */
20997 val = MAYBE_SWAP (total_len);
20998 obstack_grow (&contents, &val, sizeof (val));
20999 total_len += obstack_object_size (&symtab_obstack);
21001 /* The offset of the constant pool from the start of the file. */
21002 val = MAYBE_SWAP (total_len);
21003 obstack_grow (&contents, &val, sizeof (val));
21004 total_len += obstack_object_size (&constant_pool);
21006 gdb_assert (obstack_object_size (&contents) == size_of_contents);
21008 write_obstack (out_file, &contents);
21009 write_obstack (out_file, &cu_list);
21010 write_obstack (out_file, &types_cu_list);
21011 write_obstack (out_file, &addr_obstack);
21012 write_obstack (out_file, &symtab_obstack);
21013 write_obstack (out_file, &constant_pool);
21017 /* We want to keep the file, so we set cleanup_filename to NULL
21018 here. See unlink_if_set. */
21019 cleanup_filename = NULL;
21021 do_cleanups (cleanup);
21024 /* Implementation of the `save gdb-index' command.
21026 Note that the file format used by this command is documented in the
21027 GDB manual. Any changes here must be documented there. */
21030 save_gdb_index_command (char *arg, int from_tty)
21032 struct objfile *objfile;
21035 error (_("usage: save gdb-index DIRECTORY"));
21037 ALL_OBJFILES (objfile)
21041 /* If the objfile does not correspond to an actual file, skip it. */
21042 if (stat (objfile->name, &st) < 0)
21045 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
21046 if (dwarf2_per_objfile)
21048 volatile struct gdb_exception except;
21050 TRY_CATCH (except, RETURN_MASK_ERROR)
21052 write_psymtabs_to_index (objfile, arg);
21054 if (except.reason < 0)
21055 exception_fprintf (gdb_stderr, except,
21056 _("Error while writing index for `%s': "),
21064 int dwarf2_always_disassemble;
21067 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
21068 struct cmd_list_element *c, const char *value)
21070 fprintf_filtered (file,
21071 _("Whether to always disassemble "
21072 "DWARF expressions is %s.\n"),
21077 show_check_physname (struct ui_file *file, int from_tty,
21078 struct cmd_list_element *c, const char *value)
21080 fprintf_filtered (file,
21081 _("Whether to check \"physname\" is %s.\n"),
21085 void _initialize_dwarf2_read (void);
21088 _initialize_dwarf2_read (void)
21090 struct cmd_list_element *c;
21092 dwarf2_objfile_data_key
21093 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
21095 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
21096 Set DWARF 2 specific variables.\n\
21097 Configure DWARF 2 variables such as the cache size"),
21098 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
21099 0/*allow-unknown*/, &maintenance_set_cmdlist);
21101 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
21102 Show DWARF 2 specific variables\n\
21103 Show DWARF 2 variables such as the cache size"),
21104 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
21105 0/*allow-unknown*/, &maintenance_show_cmdlist);
21107 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
21108 &dwarf2_max_cache_age, _("\
21109 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
21110 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
21111 A higher limit means that cached compilation units will be stored\n\
21112 in memory longer, and more total memory will be used. Zero disables\n\
21113 caching, which can slow down startup."),
21115 show_dwarf2_max_cache_age,
21116 &set_dwarf2_cmdlist,
21117 &show_dwarf2_cmdlist);
21119 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
21120 &dwarf2_always_disassemble, _("\
21121 Set whether `info address' always disassembles DWARF expressions."), _("\
21122 Show whether `info address' always disassembles DWARF expressions."), _("\
21123 When enabled, DWARF expressions are always printed in an assembly-like\n\
21124 syntax. When disabled, expressions will be printed in a more\n\
21125 conversational style, when possible."),
21127 show_dwarf2_always_disassemble,
21128 &set_dwarf2_cmdlist,
21129 &show_dwarf2_cmdlist);
21131 add_setshow_boolean_cmd ("dwarf2-read", no_class, &dwarf2_read_debug, _("\
21132 Set debugging of the dwarf2 reader."), _("\
21133 Show debugging of the dwarf2 reader."), _("\
21134 When enabled, debugging messages are printed during dwarf2 reading\n\
21135 and symtab expansion."),
21138 &setdebuglist, &showdebuglist);
21140 add_setshow_zuinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
21141 Set debugging of the dwarf2 DIE reader."), _("\
21142 Show debugging of the dwarf2 DIE reader."), _("\
21143 When enabled (non-zero), DIEs are dumped after they are read in.\n\
21144 The value is the maximum depth to print."),
21147 &setdebuglist, &showdebuglist);
21149 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
21150 Set cross-checking of \"physname\" code against demangler."), _("\
21151 Show cross-checking of \"physname\" code against demangler."), _("\
21152 When enabled, GDB's internal \"physname\" code is checked against\n\
21154 NULL, show_check_physname,
21155 &setdebuglist, &showdebuglist);
21157 add_setshow_boolean_cmd ("use-deprecated-index-sections",
21158 no_class, &use_deprecated_index_sections, _("\
21159 Set whether to use deprecated gdb_index sections."), _("\
21160 Show whether to use deprecated gdb_index sections."), _("\
21161 When enabled, deprecated .gdb_index sections are used anyway.\n\
21162 Normally they are ignored either because of a missing feature or\n\
21163 performance issue.\n\
21164 Warning: This option must be enabled before gdb reads the file."),
21167 &setlist, &showlist);
21169 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
21171 Save a gdb-index file.\n\
21172 Usage: save gdb-index DIRECTORY"),
21174 set_cmd_completer (c, filename_completer);
21176 dwarf2_locexpr_index = register_symbol_computed_impl (LOC_COMPUTED,
21177 &dwarf2_locexpr_funcs);
21178 dwarf2_loclist_index = register_symbol_computed_impl (LOC_COMPUTED,
21179 &dwarf2_loclist_funcs);
21181 dwarf2_locexpr_block_index = register_symbol_block_impl (LOC_BLOCK,
21182 &dwarf2_block_frame_base_locexpr_funcs);
21183 dwarf2_loclist_block_index = register_symbol_block_impl (LOC_BLOCK,
21184 &dwarf2_block_frame_base_loclist_funcs);