1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2012 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"
72 #include "gdb_string.h"
73 #include "gdb_assert.h"
74 #include <sys/types.h>
76 typedef struct symbol *symbolp;
79 /* When non-zero, print basic high level tracing messages.
80 This is in contrast to the low level DIE reading of dwarf2_die_debug. */
81 static int dwarf2_read_debug = 0;
83 /* When non-zero, dump DIEs after they are read in. */
84 static unsigned int dwarf2_die_debug = 0;
86 /* When non-zero, cross-check physname against demangler. */
87 static int check_physname = 0;
89 /* When non-zero, do not reject deprecated .gdb_index sections. */
90 static int use_deprecated_index_sections = 0;
92 /* When set, the file that we're processing is known to have debugging
93 info for C++ namespaces. GCC 3.3.x did not produce this information,
94 but later versions do. */
96 static int processing_has_namespace_info;
98 static const struct objfile_data *dwarf2_objfile_data_key;
100 struct dwarf2_section_info
105 /* True if we have tried to read this section. */
109 typedef struct dwarf2_section_info dwarf2_section_info_def;
110 DEF_VEC_O (dwarf2_section_info_def);
112 /* All offsets in the index are of this type. It must be
113 architecture-independent. */
114 typedef uint32_t offset_type;
116 DEF_VEC_I (offset_type);
118 /* Ensure only legit values are used. */
119 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
121 gdb_assert ((unsigned int) (value) <= 1); \
122 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
125 /* Ensure only legit values are used. */
126 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
128 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
129 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
130 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
133 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
134 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
136 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
137 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
140 /* A description of the mapped index. The file format is described in
141 a comment by the code that writes the index. */
144 /* Index data format version. */
147 /* The total length of the buffer. */
150 /* A pointer to the address table data. */
151 const gdb_byte *address_table;
153 /* Size of the address table data in bytes. */
154 offset_type address_table_size;
156 /* The symbol table, implemented as a hash table. */
157 const offset_type *symbol_table;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type symbol_table_slots;
162 /* A pointer to the constant pool. */
163 const char *constant_pool;
166 typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr;
167 DEF_VEC_P (dwarf2_per_cu_ptr);
169 /* Collection of data recorded per objfile.
170 This hangs off of dwarf2_objfile_data_key. */
172 struct dwarf2_per_objfile
174 struct dwarf2_section_info info;
175 struct dwarf2_section_info abbrev;
176 struct dwarf2_section_info line;
177 struct dwarf2_section_info loc;
178 struct dwarf2_section_info macinfo;
179 struct dwarf2_section_info macro;
180 struct dwarf2_section_info str;
181 struct dwarf2_section_info ranges;
182 struct dwarf2_section_info addr;
183 struct dwarf2_section_info frame;
184 struct dwarf2_section_info eh_frame;
185 struct dwarf2_section_info gdb_index;
187 VEC (dwarf2_section_info_def) *types;
190 struct objfile *objfile;
192 /* Table of all the compilation units. This is used to locate
193 the target compilation unit of a particular reference. */
194 struct dwarf2_per_cu_data **all_comp_units;
196 /* The number of compilation units in ALL_COMP_UNITS. */
199 /* The number of .debug_types-related CUs. */
202 /* The .debug_types-related CUs (TUs). */
203 struct signatured_type **all_type_units;
205 /* The number of entries in all_type_unit_groups. */
206 int n_type_unit_groups;
208 /* Table of type unit groups.
209 This exists to make it easy to iterate over all CUs and TU groups. */
210 struct type_unit_group **all_type_unit_groups;
212 /* Table of struct type_unit_group objects.
213 The hash key is the DW_AT_stmt_list value. */
214 htab_t type_unit_groups;
216 /* A table mapping .debug_types signatures to its signatured_type entry.
217 This is NULL if the .debug_types section hasn't been read in yet. */
218 htab_t signatured_types;
220 /* Type unit statistics, to see how well the scaling improvements
224 int nr_uniq_abbrev_tables;
226 int nr_symtab_sharers;
227 int nr_stmt_less_type_units;
230 /* A chain of compilation units that are currently read in, so that
231 they can be freed later. */
232 struct dwarf2_per_cu_data *read_in_chain;
234 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
235 This is NULL if the table hasn't been allocated yet. */
238 /* Non-zero if we've check for whether there is a DWP file. */
241 /* The DWP file if there is one, or NULL. */
242 struct dwp_file *dwp_file;
244 /* The shared '.dwz' file, if one exists. This is used when the
245 original data was compressed using 'dwz -m'. */
246 struct dwz_file *dwz_file;
248 /* A flag indicating wether this objfile has a section loaded at a
250 int has_section_at_zero;
252 /* True if we are using the mapped index,
253 or we are faking it for OBJF_READNOW's sake. */
254 unsigned char using_index;
256 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
257 struct mapped_index *index_table;
259 /* When using index_table, this keeps track of all quick_file_names entries.
260 TUs can share line table entries with CUs or other TUs, and there can be
261 a lot more TUs than unique line tables, so we maintain a separate table
262 of all line table entries to support the sharing. */
263 htab_t quick_file_names_table;
265 /* Set during partial symbol reading, to prevent queueing of full
267 int reading_partial_symbols;
269 /* Table mapping type DIEs to their struct type *.
270 This is NULL if not allocated yet.
271 The mapping is done via (CU/TU signature + DIE offset) -> type. */
272 htab_t die_type_hash;
274 /* The CUs we recently read. */
275 VEC (dwarf2_per_cu_ptr) *just_read_cus;
278 static struct dwarf2_per_objfile *dwarf2_per_objfile;
280 /* Default names of the debugging sections. */
282 /* Note that if the debugging section has been compressed, it might
283 have a name like .zdebug_info. */
285 static const struct dwarf2_debug_sections dwarf2_elf_names =
287 { ".debug_info", ".zdebug_info" },
288 { ".debug_abbrev", ".zdebug_abbrev" },
289 { ".debug_line", ".zdebug_line" },
290 { ".debug_loc", ".zdebug_loc" },
291 { ".debug_macinfo", ".zdebug_macinfo" },
292 { ".debug_macro", ".zdebug_macro" },
293 { ".debug_str", ".zdebug_str" },
294 { ".debug_ranges", ".zdebug_ranges" },
295 { ".debug_types", ".zdebug_types" },
296 { ".debug_addr", ".zdebug_addr" },
297 { ".debug_frame", ".zdebug_frame" },
298 { ".eh_frame", NULL },
299 { ".gdb_index", ".zgdb_index" },
303 /* List of DWO/DWP sections. */
305 static const struct dwop_section_names
307 struct dwarf2_section_names abbrev_dwo;
308 struct dwarf2_section_names info_dwo;
309 struct dwarf2_section_names line_dwo;
310 struct dwarf2_section_names loc_dwo;
311 struct dwarf2_section_names macinfo_dwo;
312 struct dwarf2_section_names macro_dwo;
313 struct dwarf2_section_names str_dwo;
314 struct dwarf2_section_names str_offsets_dwo;
315 struct dwarf2_section_names types_dwo;
316 struct dwarf2_section_names cu_index;
317 struct dwarf2_section_names tu_index;
321 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
322 { ".debug_info.dwo", ".zdebug_info.dwo" },
323 { ".debug_line.dwo", ".zdebug_line.dwo" },
324 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
325 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
326 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
327 { ".debug_str.dwo", ".zdebug_str.dwo" },
328 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
329 { ".debug_types.dwo", ".zdebug_types.dwo" },
330 { ".debug_cu_index", ".zdebug_cu_index" },
331 { ".debug_tu_index", ".zdebug_tu_index" },
334 /* local data types */
336 /* The data in a compilation unit header, after target2host
337 translation, looks like this. */
338 struct comp_unit_head
342 unsigned char addr_size;
343 unsigned char signed_addr_p;
344 sect_offset abbrev_offset;
346 /* Size of file offsets; either 4 or 8. */
347 unsigned int offset_size;
349 /* Size of the length field; either 4 or 12. */
350 unsigned int initial_length_size;
352 /* Offset to the first byte of this compilation unit header in the
353 .debug_info section, for resolving relative reference dies. */
356 /* Offset to first die in this cu from the start of the cu.
357 This will be the first byte following the compilation unit header. */
358 cu_offset first_die_offset;
361 /* Type used for delaying computation of method physnames.
362 See comments for compute_delayed_physnames. */
363 struct delayed_method_info
365 /* The type to which the method is attached, i.e., its parent class. */
368 /* The index of the method in the type's function fieldlists. */
371 /* The index of the method in the fieldlist. */
374 /* The name of the DIE. */
377 /* The DIE associated with this method. */
378 struct die_info *die;
381 typedef struct delayed_method_info delayed_method_info;
382 DEF_VEC_O (delayed_method_info);
384 /* Internal state when decoding a particular compilation unit. */
387 /* The objfile containing this compilation unit. */
388 struct objfile *objfile;
390 /* The header of the compilation unit. */
391 struct comp_unit_head header;
393 /* Base address of this compilation unit. */
394 CORE_ADDR base_address;
396 /* Non-zero if base_address has been set. */
399 /* The language we are debugging. */
400 enum language language;
401 const struct language_defn *language_defn;
403 const char *producer;
405 /* The generic symbol table building routines have separate lists for
406 file scope symbols and all all other scopes (local scopes). So
407 we need to select the right one to pass to add_symbol_to_list().
408 We do it by keeping a pointer to the correct list in list_in_scope.
410 FIXME: The original dwarf code just treated the file scope as the
411 first local scope, and all other local scopes as nested local
412 scopes, and worked fine. Check to see if we really need to
413 distinguish these in buildsym.c. */
414 struct pending **list_in_scope;
416 /* The abbrev table for this CU.
417 Normally this points to the abbrev table in the objfile.
418 But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */
419 struct abbrev_table *abbrev_table;
421 /* Hash table holding all the loaded partial DIEs
422 with partial_die->offset.SECT_OFF as hash. */
425 /* Storage for things with the same lifetime as this read-in compilation
426 unit, including partial DIEs. */
427 struct obstack comp_unit_obstack;
429 /* When multiple dwarf2_cu structures are living in memory, this field
430 chains them all together, so that they can be released efficiently.
431 We will probably also want a generation counter so that most-recently-used
432 compilation units are cached... */
433 struct dwarf2_per_cu_data *read_in_chain;
435 /* Backchain to our per_cu entry if the tree has been built. */
436 struct dwarf2_per_cu_data *per_cu;
438 /* How many compilation units ago was this CU last referenced? */
441 /* A hash table of DIE cu_offset for following references with
442 die_info->offset.sect_off as hash. */
445 /* Full DIEs if read in. */
446 struct die_info *dies;
448 /* A set of pointers to dwarf2_per_cu_data objects for compilation
449 units referenced by this one. Only set during full symbol processing;
450 partial symbol tables do not have dependencies. */
453 /* Header data from the line table, during full symbol processing. */
454 struct line_header *line_header;
456 /* A list of methods which need to have physnames computed
457 after all type information has been read. */
458 VEC (delayed_method_info) *method_list;
460 /* To be copied to symtab->call_site_htab. */
461 htab_t call_site_htab;
463 /* Non-NULL if this CU came from a DWO file.
464 There is an invariant here that is important to remember:
465 Except for attributes copied from the top level DIE in the "main"
466 (or "stub") file in preparation for reading the DWO file
467 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
468 Either there isn't a DWO file (in which case this is NULL and the point
469 is moot), or there is and either we're not going to read it (in which
470 case this is NULL) or there is and we are reading it (in which case this
472 struct dwo_unit *dwo_unit;
474 /* The DW_AT_addr_base attribute if present, zero otherwise
475 (zero is a valid value though).
476 Note this value comes from the stub CU/TU's DIE. */
479 /* The DW_AT_ranges_base attribute if present, zero otherwise
480 (zero is a valid value though).
481 Note this value comes from the stub CU/TU's DIE.
482 Also note that the value is zero in the non-DWO case so this value can
483 be used without needing to know whether DWO files are in use or not. */
484 ULONGEST ranges_base;
486 /* Mark used when releasing cached dies. */
487 unsigned int mark : 1;
489 /* This CU references .debug_loc. See the symtab->locations_valid field.
490 This test is imperfect as there may exist optimized debug code not using
491 any location list and still facing inlining issues if handled as
492 unoptimized code. For a future better test see GCC PR other/32998. */
493 unsigned int has_loclist : 1;
495 /* These cache the results for producer_is_gxx_lt_4_6 and producer_is_icc.
496 CHECKED_PRODUCER is set if both PRODUCER_IS_GXX_LT_4_6 and PRODUCER_IS_ICC
497 are valid. This information is cached because profiling CU expansion
498 showed excessive time spent in producer_is_gxx_lt_4_6. */
499 unsigned int checked_producer : 1;
500 unsigned int producer_is_gxx_lt_4_6 : 1;
501 unsigned int producer_is_icc : 1;
504 /* Persistent data held for a compilation unit, even when not
505 processing it. We put a pointer to this structure in the
506 read_symtab_private field of the psymtab. */
508 struct dwarf2_per_cu_data
510 /* The start offset and length of this compilation unit.
511 NOTE: Unlike comp_unit_head.length, this length includes
513 If the DIE refers to a DWO file, this is always of the original die,
518 /* Flag indicating this compilation unit will be read in before
519 any of the current compilation units are processed. */
520 unsigned int queued : 1;
522 /* This flag will be set when reading partial DIEs if we need to load
523 absolutely all DIEs for this compilation unit, instead of just the ones
524 we think are interesting. It gets set if we look for a DIE in the
525 hash table and don't find it. */
526 unsigned int load_all_dies : 1;
528 /* Non-zero if this CU is from .debug_types. */
529 unsigned int is_debug_types : 1;
531 /* Non-zero if this CU is from the .dwz file. */
532 unsigned int is_dwz : 1;
534 /* The section this CU/TU lives in.
535 If the DIE refers to a DWO file, this is always the original die,
537 struct dwarf2_section_info *info_or_types_section;
539 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
540 of the CU cache it gets reset to NULL again. */
541 struct dwarf2_cu *cu;
543 /* The corresponding objfile.
544 Normally we can get the objfile from dwarf2_per_objfile.
545 However we can enter this file with just a "per_cu" handle. */
546 struct objfile *objfile;
548 /* When using partial symbol tables, the 'psymtab' field is active.
549 Otherwise the 'quick' field is active. */
552 /* The partial symbol table associated with this compilation unit,
553 or NULL for unread partial units. */
554 struct partial_symtab *psymtab;
556 /* Data needed by the "quick" functions. */
557 struct dwarf2_per_cu_quick_data *quick;
562 /* The CUs we import using DW_TAG_imported_unit. This is filled in
563 while reading psymtabs, used to compute the psymtab dependencies,
564 and then cleared. Then it is filled in again while reading full
565 symbols, and only deleted when the objfile is destroyed. */
566 VEC (dwarf2_per_cu_ptr) *imported_symtabs;
568 /* Type units are grouped by their DW_AT_stmt_list entry so that they
569 can share them. If this is a TU, this points to the containing
571 struct type_unit_group *type_unit_group;
575 /* Entry in the signatured_types hash table. */
577 struct signatured_type
579 /* The "per_cu" object of this type.
580 N.B.: This is the first member so that it's easy to convert pointers
582 struct dwarf2_per_cu_data per_cu;
584 /* The type's signature. */
587 /* Offset in the TU of the type's DIE, as read from the TU header.
588 If the definition lives in a DWO file, this value is unusable. */
589 cu_offset type_offset_in_tu;
591 /* Offset in the section of the type's DIE.
592 If the definition lives in a DWO file, this is the offset in the
593 .debug_types.dwo section.
594 The value is zero until the actual value is known.
595 Zero is otherwise not a valid section offset. */
596 sect_offset type_offset_in_section;
599 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
600 This includes type_unit_group and quick_file_names. */
602 struct stmt_list_hash
604 /* The DWO unit this table is from or NULL if there is none. */
605 struct dwo_unit *dwo_unit;
607 /* Offset in .debug_line or .debug_line.dwo. */
608 sect_offset line_offset;
611 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
612 an object of this type. */
614 struct type_unit_group
616 /* dwarf2read.c's main "handle" on the symtab.
617 To simplify things we create an artificial CU that "includes" all the
618 type units using this stmt_list so that the rest of the code still has
619 a "per_cu" handle on the symtab.
620 This PER_CU is recognized by having no section. */
621 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL)
622 struct dwarf2_per_cu_data per_cu;
626 /* The TUs that share this DW_AT_stmt_list entry.
627 This is added to while parsing type units to build partial symtabs,
628 and is deleted afterwards and not used again. */
629 VEC (dwarf2_per_cu_ptr) *tus;
631 /* When reading the line table in "quick" functions, we need a real TU.
632 Any will do, we know they all share the same DW_AT_stmt_list entry.
633 For simplicity's sake, we pick the first one. */
634 struct dwarf2_per_cu_data *first_tu;
637 /* The primary symtab.
638 Type units in a group needn't all be defined in the same source file,
639 so we create an essentially anonymous symtab as the primary symtab. */
640 struct symtab *primary_symtab;
642 /* The data used to construct the hash key. */
643 struct stmt_list_hash hash;
645 /* The number of symtabs from the line header.
646 The value here must match line_header.num_file_names. */
647 unsigned int num_symtabs;
649 /* The symbol tables for this TU (obtained from the files listed in
651 WARNING: The order of entries here must match the order of entries
652 in the line header. After the first TU using this type_unit_group, the
653 line header for the subsequent TUs is recreated from this. This is done
654 because we need to use the same symtabs for each TU using the same
655 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
656 there's no guarantee the line header doesn't have duplicate entries. */
657 struct symtab **symtabs;
660 /* These sections are what may appear in a DWO file. */
664 struct dwarf2_section_info abbrev;
665 struct dwarf2_section_info line;
666 struct dwarf2_section_info loc;
667 struct dwarf2_section_info macinfo;
668 struct dwarf2_section_info macro;
669 struct dwarf2_section_info str;
670 struct dwarf2_section_info str_offsets;
671 /* In the case of a virtual DWO file, these two are unused. */
672 struct dwarf2_section_info info;
673 VEC (dwarf2_section_info_def) *types;
676 /* Common bits of DWO CUs/TUs. */
680 /* Backlink to the containing struct dwo_file. */
681 struct dwo_file *dwo_file;
683 /* The "id" that distinguishes this CU/TU.
684 .debug_info calls this "dwo_id", .debug_types calls this "signature".
685 Since signatures came first, we stick with it for consistency. */
688 /* The section this CU/TU lives in, in the DWO file. */
689 struct dwarf2_section_info *info_or_types_section;
691 /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */
695 /* For types, offset in the type's DIE of the type defined by this TU. */
696 cu_offset type_offset_in_tu;
699 /* Data for one DWO file.
700 This includes virtual DWO files that have been packaged into a
705 /* The DW_AT_GNU_dwo_name attribute. This is the hash key.
706 For virtual DWO files the name is constructed from the section offsets
707 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
708 from related CU+TUs. */
711 /* The bfd, when the file is open. Otherwise this is NULL.
712 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
715 /* Section info for this file. */
716 struct dwo_sections sections;
718 /* Table of CUs in the file.
719 Each element is a struct dwo_unit. */
722 /* Table of TUs in the file.
723 Each element is a struct dwo_unit. */
727 /* These sections are what may appear in a DWP file. */
731 struct dwarf2_section_info str;
732 struct dwarf2_section_info cu_index;
733 struct dwarf2_section_info tu_index;
734 /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced
735 by section number. We don't need to record them here. */
738 /* These sections are what may appear in a virtual DWO file. */
740 struct virtual_dwo_sections
742 struct dwarf2_section_info abbrev;
743 struct dwarf2_section_info line;
744 struct dwarf2_section_info loc;
745 struct dwarf2_section_info macinfo;
746 struct dwarf2_section_info macro;
747 struct dwarf2_section_info str_offsets;
748 /* Each DWP hash table entry records one CU or one TU.
749 That is recorded here, and copied to dwo_unit.info_or_types_section. */
750 struct dwarf2_section_info info_or_types;
753 /* Contents of DWP hash tables. */
755 struct dwp_hash_table
757 uint32_t nr_units, nr_slots;
758 const gdb_byte *hash_table, *unit_table, *section_pool;
761 /* Data for one DWP file. */
765 /* Name of the file. */
768 /* The bfd, when the file is open. Otherwise this is NULL. */
771 /* Section info for this file. */
772 struct dwp_sections sections;
774 /* Table of CUs in the file. */
775 const struct dwp_hash_table *cus;
777 /* Table of TUs in the file. */
778 const struct dwp_hash_table *tus;
780 /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
783 /* Table to map ELF section numbers to their sections. */
784 unsigned int num_sections;
785 asection **elf_sections;
788 /* This represents a '.dwz' file. */
792 /* A dwz file can only contain a few sections. */
793 struct dwarf2_section_info abbrev;
794 struct dwarf2_section_info info;
795 struct dwarf2_section_info str;
796 struct dwarf2_section_info line;
797 struct dwarf2_section_info macro;
798 struct dwarf2_section_info gdb_index;
804 /* Struct used to pass misc. parameters to read_die_and_children, et
805 al. which are used for both .debug_info and .debug_types dies.
806 All parameters here are unchanging for the life of the call. This
807 struct exists to abstract away the constant parameters of die reading. */
809 struct die_reader_specs
811 /* die_section->asection->owner. */
814 /* The CU of the DIE we are parsing. */
815 struct dwarf2_cu *cu;
817 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
818 struct dwo_file *dwo_file;
820 /* The section the die comes from.
821 This is either .debug_info or .debug_types, or the .dwo variants. */
822 struct dwarf2_section_info *die_section;
824 /* die_section->buffer. */
827 /* The end of the buffer. */
828 const gdb_byte *buffer_end;
831 /* Type of function passed to init_cutu_and_read_dies, et.al. */
832 typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader,
834 struct die_info *comp_unit_die,
838 /* The line number information for a compilation unit (found in the
839 .debug_line section) begins with a "statement program header",
840 which contains the following information. */
843 unsigned int total_length;
844 unsigned short version;
845 unsigned int header_length;
846 unsigned char minimum_instruction_length;
847 unsigned char maximum_ops_per_instruction;
848 unsigned char default_is_stmt;
850 unsigned char line_range;
851 unsigned char opcode_base;
853 /* standard_opcode_lengths[i] is the number of operands for the
854 standard opcode whose value is i. This means that
855 standard_opcode_lengths[0] is unused, and the last meaningful
856 element is standard_opcode_lengths[opcode_base - 1]. */
857 unsigned char *standard_opcode_lengths;
859 /* The include_directories table. NOTE! These strings are not
860 allocated with xmalloc; instead, they are pointers into
861 debug_line_buffer. If you try to free them, `free' will get
863 unsigned int num_include_dirs, include_dirs_size;
866 /* The file_names table. NOTE! These strings are not allocated
867 with xmalloc; instead, they are pointers into debug_line_buffer.
868 Don't try to free them directly. */
869 unsigned int num_file_names, file_names_size;
873 unsigned int dir_index;
874 unsigned int mod_time;
876 int included_p; /* Non-zero if referenced by the Line Number Program. */
877 struct symtab *symtab; /* The associated symbol table, if any. */
880 /* The start and end of the statement program following this
881 header. These point into dwarf2_per_objfile->line_buffer. */
882 gdb_byte *statement_program_start, *statement_program_end;
885 /* When we construct a partial symbol table entry we only
886 need this much information. */
887 struct partial_die_info
889 /* Offset of this DIE. */
892 /* DWARF-2 tag for this DIE. */
893 ENUM_BITFIELD(dwarf_tag) tag : 16;
895 /* Assorted flags describing the data found in this DIE. */
896 unsigned int has_children : 1;
897 unsigned int is_external : 1;
898 unsigned int is_declaration : 1;
899 unsigned int has_type : 1;
900 unsigned int has_specification : 1;
901 unsigned int has_pc_info : 1;
902 unsigned int may_be_inlined : 1;
904 /* Flag set if the SCOPE field of this structure has been
906 unsigned int scope_set : 1;
908 /* Flag set if the DIE has a byte_size attribute. */
909 unsigned int has_byte_size : 1;
911 /* Flag set if any of the DIE's children are template arguments. */
912 unsigned int has_template_arguments : 1;
914 /* Flag set if fixup_partial_die has been called on this die. */
915 unsigned int fixup_called : 1;
917 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
918 unsigned int is_dwz : 1;
920 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
921 unsigned int spec_is_dwz : 1;
923 /* The name of this DIE. Normally the value of DW_AT_name, but
924 sometimes a default name for unnamed DIEs. */
927 /* The linkage name, if present. */
928 const char *linkage_name;
930 /* The scope to prepend to our children. This is generally
931 allocated on the comp_unit_obstack, so will disappear
932 when this compilation unit leaves the cache. */
935 /* Some data associated with the partial DIE. The tag determines
936 which field is live. */
939 /* The location description associated with this DIE, if any. */
940 struct dwarf_block *locdesc;
941 /* The offset of an import, for DW_TAG_imported_unit. */
945 /* If HAS_PC_INFO, the PC range associated with this DIE. */
949 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
950 DW_AT_sibling, if any. */
951 /* NOTE: This member isn't strictly necessary, read_partial_die could
952 return DW_AT_sibling values to its caller load_partial_dies. */
955 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
956 DW_AT_specification (or DW_AT_abstract_origin or
958 sect_offset spec_offset;
960 /* Pointers to this DIE's parent, first child, and next sibling,
962 struct partial_die_info *die_parent, *die_child, *die_sibling;
965 /* This data structure holds the information of an abbrev. */
968 unsigned int number; /* number identifying abbrev */
969 enum dwarf_tag tag; /* dwarf tag */
970 unsigned short has_children; /* boolean */
971 unsigned short num_attrs; /* number of attributes */
972 struct attr_abbrev *attrs; /* an array of attribute descriptions */
973 struct abbrev_info *next; /* next in chain */
978 ENUM_BITFIELD(dwarf_attribute) name : 16;
979 ENUM_BITFIELD(dwarf_form) form : 16;
982 /* Size of abbrev_table.abbrev_hash_table. */
983 #define ABBREV_HASH_SIZE 121
985 /* Top level data structure to contain an abbreviation table. */
989 /* Where the abbrev table came from.
990 This is used as a sanity check when the table is used. */
993 /* Storage for the abbrev table. */
994 struct obstack abbrev_obstack;
996 /* Hash table of abbrevs.
997 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
998 It could be statically allocated, but the previous code didn't so we
1000 struct abbrev_info **abbrevs;
1003 /* Attributes have a name and a value. */
1006 ENUM_BITFIELD(dwarf_attribute) name : 16;
1007 ENUM_BITFIELD(dwarf_form) form : 15;
1009 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1010 field should be in u.str (existing only for DW_STRING) but it is kept
1011 here for better struct attribute alignment. */
1012 unsigned int string_is_canonical : 1;
1017 struct dwarf_block *blk;
1021 struct signatured_type *signatured_type;
1026 /* This data structure holds a complete die structure. */
1029 /* DWARF-2 tag for this DIE. */
1030 ENUM_BITFIELD(dwarf_tag) tag : 16;
1032 /* Number of attributes */
1033 unsigned char num_attrs;
1035 /* True if we're presently building the full type name for the
1036 type derived from this DIE. */
1037 unsigned char building_fullname : 1;
1040 unsigned int abbrev;
1042 /* Offset in .debug_info or .debug_types section. */
1045 /* The dies in a compilation unit form an n-ary tree. PARENT
1046 points to this die's parent; CHILD points to the first child of
1047 this node; and all the children of a given node are chained
1048 together via their SIBLING fields. */
1049 struct die_info *child; /* Its first child, if any. */
1050 struct die_info *sibling; /* Its next sibling, if any. */
1051 struct die_info *parent; /* Its parent, if any. */
1053 /* An array of attributes, with NUM_ATTRS elements. There may be
1054 zero, but it's not common and zero-sized arrays are not
1055 sufficiently portable C. */
1056 struct attribute attrs[1];
1059 /* Get at parts of an attribute structure. */
1061 #define DW_STRING(attr) ((attr)->u.str)
1062 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1063 #define DW_UNSND(attr) ((attr)->u.unsnd)
1064 #define DW_BLOCK(attr) ((attr)->u.blk)
1065 #define DW_SND(attr) ((attr)->u.snd)
1066 #define DW_ADDR(attr) ((attr)->u.addr)
1067 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
1069 /* Blocks are a bunch of untyped bytes. */
1074 /* Valid only if SIZE is not zero. */
1078 #ifndef ATTR_ALLOC_CHUNK
1079 #define ATTR_ALLOC_CHUNK 4
1082 /* Allocate fields for structs, unions and enums in this size. */
1083 #ifndef DW_FIELD_ALLOC_CHUNK
1084 #define DW_FIELD_ALLOC_CHUNK 4
1087 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1088 but this would require a corresponding change in unpack_field_as_long
1090 static int bits_per_byte = 8;
1092 /* The routines that read and process dies for a C struct or C++ class
1093 pass lists of data member fields and lists of member function fields
1094 in an instance of a field_info structure, as defined below. */
1097 /* List of data member and baseclasses fields. */
1100 struct nextfield *next;
1105 *fields, *baseclasses;
1107 /* Number of fields (including baseclasses). */
1110 /* Number of baseclasses. */
1113 /* Set if the accesibility of one of the fields is not public. */
1114 int non_public_fields;
1116 /* Member function fields array, entries are allocated in the order they
1117 are encountered in the object file. */
1120 struct nextfnfield *next;
1121 struct fn_field fnfield;
1125 /* Member function fieldlist array, contains name of possibly overloaded
1126 member function, number of overloaded member functions and a pointer
1127 to the head of the member function field chain. */
1132 struct nextfnfield *head;
1136 /* Number of entries in the fnfieldlists array. */
1139 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1140 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1141 struct typedef_field_list
1143 struct typedef_field field;
1144 struct typedef_field_list *next;
1146 *typedef_field_list;
1147 unsigned typedef_field_list_count;
1150 /* One item on the queue of compilation units to read in full symbols
1152 struct dwarf2_queue_item
1154 struct dwarf2_per_cu_data *per_cu;
1155 enum language pretend_language;
1156 struct dwarf2_queue_item *next;
1159 /* The current queue. */
1160 static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
1162 /* Loaded secondary compilation units are kept in memory until they
1163 have not been referenced for the processing of this many
1164 compilation units. Set this to zero to disable caching. Cache
1165 sizes of up to at least twenty will improve startup time for
1166 typical inter-CU-reference binaries, at an obvious memory cost. */
1167 static int dwarf2_max_cache_age = 5;
1169 show_dwarf2_max_cache_age (struct ui_file *file, int from_tty,
1170 struct cmd_list_element *c, const char *value)
1172 fprintf_filtered (file, _("The upper bound on the age of cached "
1173 "dwarf2 compilation units is %s.\n"),
1178 /* Various complaints about symbol reading that don't abort the process. */
1181 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1183 complaint (&symfile_complaints,
1184 _("statement list doesn't fit in .debug_line section"));
1188 dwarf2_debug_line_missing_file_complaint (void)
1190 complaint (&symfile_complaints,
1191 _(".debug_line section has line data without a file"));
1195 dwarf2_debug_line_missing_end_sequence_complaint (void)
1197 complaint (&symfile_complaints,
1198 _(".debug_line section has line "
1199 "program sequence without an end"));
1203 dwarf2_complex_location_expr_complaint (void)
1205 complaint (&symfile_complaints, _("location expression too complex"));
1209 dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2,
1212 complaint (&symfile_complaints,
1213 _("const value length mismatch for '%s', got %d, expected %d"),
1218 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section)
1220 complaint (&symfile_complaints,
1221 _("debug info runs off end of %s section"
1223 section->asection->name,
1224 bfd_get_filename (section->asection->owner));
1228 dwarf2_macro_malformed_definition_complaint (const char *arg1)
1230 complaint (&symfile_complaints,
1231 _("macro debug info contains a "
1232 "malformed macro definition:\n`%s'"),
1237 dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2)
1239 complaint (&symfile_complaints,
1240 _("invalid attribute class or form for '%s' in '%s'"),
1244 /* local function prototypes */
1246 static void dwarf2_locate_sections (bfd *, asection *, void *);
1248 static void dwarf2_create_include_psymtab (char *, struct partial_symtab *,
1251 static void dwarf2_find_base_address (struct die_info *die,
1252 struct dwarf2_cu *cu);
1254 static void dwarf2_build_psymtabs_hard (struct objfile *);
1256 static void scan_partial_symbols (struct partial_die_info *,
1257 CORE_ADDR *, CORE_ADDR *,
1258 int, struct dwarf2_cu *);
1260 static void add_partial_symbol (struct partial_die_info *,
1261 struct dwarf2_cu *);
1263 static void add_partial_namespace (struct partial_die_info *pdi,
1264 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1265 int need_pc, struct dwarf2_cu *cu);
1267 static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
1268 CORE_ADDR *highpc, int need_pc,
1269 struct dwarf2_cu *cu);
1271 static void add_partial_enumeration (struct partial_die_info *enum_pdi,
1272 struct dwarf2_cu *cu);
1274 static void add_partial_subprogram (struct partial_die_info *pdi,
1275 CORE_ADDR *lowpc, CORE_ADDR *highpc,
1276 int need_pc, struct dwarf2_cu *cu);
1278 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
1280 static void psymtab_to_symtab_1 (struct partial_symtab *);
1282 static struct abbrev_info *abbrev_table_lookup_abbrev
1283 (const struct abbrev_table *, unsigned int);
1285 static struct abbrev_table *abbrev_table_read_table
1286 (struct dwarf2_section_info *, sect_offset);
1288 static void abbrev_table_free (struct abbrev_table *);
1290 static void abbrev_table_free_cleanup (void *);
1292 static void dwarf2_read_abbrevs (struct dwarf2_cu *,
1293 struct dwarf2_section_info *);
1295 static void dwarf2_free_abbrev_table (void *);
1297 static unsigned int peek_abbrev_code (bfd *, gdb_byte *);
1299 static struct partial_die_info *load_partial_dies
1300 (const struct die_reader_specs *, gdb_byte *, int);
1302 static gdb_byte *read_partial_die (const struct die_reader_specs *,
1303 struct partial_die_info *,
1304 struct abbrev_info *,
1308 static struct partial_die_info *find_partial_die (sect_offset, int,
1309 struct dwarf2_cu *);
1311 static void fixup_partial_die (struct partial_die_info *,
1312 struct dwarf2_cu *);
1314 static gdb_byte *read_attribute (const struct die_reader_specs *,
1315 struct attribute *, struct attr_abbrev *,
1318 static unsigned int read_1_byte (bfd *, const gdb_byte *);
1320 static int read_1_signed_byte (bfd *, const gdb_byte *);
1322 static unsigned int read_2_bytes (bfd *, const gdb_byte *);
1324 static unsigned int read_4_bytes (bfd *, const gdb_byte *);
1326 static ULONGEST read_8_bytes (bfd *, const gdb_byte *);
1328 static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *,
1331 static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *);
1333 static LONGEST read_checked_initial_length_and_offset
1334 (bfd *, gdb_byte *, const struct comp_unit_head *,
1335 unsigned int *, unsigned int *);
1337 static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *,
1340 static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int);
1342 static sect_offset read_abbrev_offset (struct dwarf2_section_info *,
1345 static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int);
1347 static char *read_direct_string (bfd *, gdb_byte *, unsigned int *);
1349 static char *read_indirect_string (bfd *, gdb_byte *,
1350 const struct comp_unit_head *,
1353 static char *read_indirect_string_from_dwz (struct dwz_file *, LONGEST);
1355 static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *);
1357 static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *);
1359 static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, gdb_byte *,
1362 static char *read_str_index (const struct die_reader_specs *reader,
1363 struct dwarf2_cu *cu, ULONGEST str_index);
1365 static void set_cu_language (unsigned int, struct dwarf2_cu *);
1367 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
1368 struct dwarf2_cu *);
1370 static struct attribute *dwarf2_attr_no_follow (struct die_info *,
1373 static int dwarf2_flag_true_p (struct die_info *die, unsigned name,
1374 struct dwarf2_cu *cu);
1376 static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu);
1378 static struct die_info *die_specification (struct die_info *die,
1379 struct dwarf2_cu **);
1381 static void free_line_header (struct line_header *lh);
1383 static void add_file_name (struct line_header *, char *, unsigned int,
1384 unsigned int, unsigned int);
1386 static struct line_header *dwarf_decode_line_header (unsigned int offset,
1387 struct dwarf2_cu *cu);
1389 static void dwarf_decode_lines (struct line_header *, const char *,
1390 struct dwarf2_cu *, struct partial_symtab *,
1393 static void dwarf2_start_subfile (char *, const char *, const char *);
1395 static void dwarf2_start_symtab (struct dwarf2_cu *,
1396 char *, char *, CORE_ADDR);
1398 static struct symbol *new_symbol (struct die_info *, struct type *,
1399 struct dwarf2_cu *);
1401 static struct symbol *new_symbol_full (struct die_info *, struct type *,
1402 struct dwarf2_cu *, struct symbol *);
1404 static void dwarf2_const_value (struct attribute *, struct symbol *,
1405 struct dwarf2_cu *);
1407 static void dwarf2_const_value_attr (struct attribute *attr,
1410 struct obstack *obstack,
1411 struct dwarf2_cu *cu, LONGEST *value,
1413 struct dwarf2_locexpr_baton **baton);
1415 static struct type *die_type (struct die_info *, struct dwarf2_cu *);
1417 static int need_gnat_info (struct dwarf2_cu *);
1419 static struct type *die_descriptive_type (struct die_info *,
1420 struct dwarf2_cu *);
1422 static void set_descriptive_type (struct type *, struct die_info *,
1423 struct dwarf2_cu *);
1425 static struct type *die_containing_type (struct die_info *,
1426 struct dwarf2_cu *);
1428 static struct type *lookup_die_type (struct die_info *, struct attribute *,
1429 struct dwarf2_cu *);
1431 static struct type *read_type_die (struct die_info *, struct dwarf2_cu *);
1433 static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *);
1435 static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *);
1437 static char *typename_concat (struct obstack *obs, const char *prefix,
1438 const char *suffix, int physname,
1439 struct dwarf2_cu *cu);
1441 static void read_file_scope (struct die_info *, struct dwarf2_cu *);
1443 static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *);
1445 static void read_func_scope (struct die_info *, struct dwarf2_cu *);
1447 static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *);
1449 static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu);
1451 static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *,
1452 struct dwarf2_cu *, struct partial_symtab *);
1454 static int dwarf2_get_pc_bounds (struct die_info *,
1455 CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *,
1456 struct partial_symtab *);
1458 static void get_scope_pc_bounds (struct die_info *,
1459 CORE_ADDR *, CORE_ADDR *,
1460 struct dwarf2_cu *);
1462 static void dwarf2_record_block_ranges (struct die_info *, struct block *,
1463 CORE_ADDR, struct dwarf2_cu *);
1465 static void dwarf2_add_field (struct field_info *, struct die_info *,
1466 struct dwarf2_cu *);
1468 static void dwarf2_attach_fields_to_type (struct field_info *,
1469 struct type *, struct dwarf2_cu *);
1471 static void dwarf2_add_member_fn (struct field_info *,
1472 struct die_info *, struct type *,
1473 struct dwarf2_cu *);
1475 static void dwarf2_attach_fn_fields_to_type (struct field_info *,
1477 struct dwarf2_cu *);
1479 static void process_structure_scope (struct die_info *, struct dwarf2_cu *);
1481 static void read_common_block (struct die_info *, struct dwarf2_cu *);
1483 static void read_namespace (struct die_info *die, struct dwarf2_cu *);
1485 static void read_module (struct die_info *die, struct dwarf2_cu *cu);
1487 static void read_import_statement (struct die_info *die, struct dwarf2_cu *);
1489 static struct type *read_module_type (struct die_info *die,
1490 struct dwarf2_cu *cu);
1492 static const char *namespace_name (struct die_info *die,
1493 int *is_anonymous, struct dwarf2_cu *);
1495 static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *);
1497 static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
1499 static enum dwarf_array_dim_ordering read_array_order (struct die_info *,
1500 struct dwarf2_cu *);
1502 static struct die_info *read_die_and_children (const struct die_reader_specs *,
1504 gdb_byte **new_info_ptr,
1505 struct die_info *parent);
1507 static struct die_info *read_die_and_siblings (const struct die_reader_specs *,
1509 gdb_byte **new_info_ptr,
1510 struct die_info *parent);
1512 static gdb_byte *read_full_die_1 (const struct die_reader_specs *,
1513 struct die_info **, gdb_byte *, int *, int);
1515 static gdb_byte *read_full_die (const struct die_reader_specs *,
1516 struct die_info **, gdb_byte *, int *);
1518 static void process_die (struct die_info *, struct dwarf2_cu *);
1520 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *,
1523 static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *);
1525 static const char *dwarf2_full_name (char *name,
1526 struct die_info *die,
1527 struct dwarf2_cu *cu);
1529 static struct die_info *dwarf2_extension (struct die_info *die,
1530 struct dwarf2_cu **);
1532 static const char *dwarf_tag_name (unsigned int);
1534 static const char *dwarf_attr_name (unsigned int);
1536 static const char *dwarf_form_name (unsigned int);
1538 static char *dwarf_bool_name (unsigned int);
1540 static const char *dwarf_type_encoding_name (unsigned int);
1542 static struct die_info *sibling_die (struct die_info *);
1544 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
1546 static void dump_die_for_error (struct die_info *);
1548 static void dump_die_1 (struct ui_file *, int level, int max_level,
1551 /*static*/ void dump_die (struct die_info *, int max_level);
1553 static void store_in_ref_table (struct die_info *,
1554 struct dwarf2_cu *);
1556 static int is_ref_attr (struct attribute *);
1558 static sect_offset dwarf2_get_ref_die_offset (struct attribute *);
1560 static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int);
1562 static struct die_info *follow_die_ref_or_sig (struct die_info *,
1564 struct dwarf2_cu **);
1566 static struct die_info *follow_die_ref (struct die_info *,
1568 struct dwarf2_cu **);
1570 static struct die_info *follow_die_sig (struct die_info *,
1572 struct dwarf2_cu **);
1574 static struct signatured_type *lookup_signatured_type_at_offset
1575 (struct objfile *objfile,
1576 struct dwarf2_section_info *section, sect_offset offset);
1578 static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
1580 static void read_signatured_type (struct signatured_type *);
1582 static struct type_unit_group *get_type_unit_group
1583 (struct dwarf2_cu *, struct attribute *);
1585 static void build_type_unit_groups (die_reader_func_ftype *, void *);
1587 /* memory allocation interface */
1589 static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *);
1591 static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
1593 static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int,
1596 static int attr_form_is_block (struct attribute *);
1598 static int attr_form_is_section_offset (struct attribute *);
1600 static int attr_form_is_constant (struct attribute *);
1602 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
1603 struct dwarf2_loclist_baton *baton,
1604 struct attribute *attr);
1606 static void dwarf2_symbol_mark_computed (struct attribute *attr,
1608 struct dwarf2_cu *cu);
1610 static gdb_byte *skip_one_die (const struct die_reader_specs *reader,
1612 struct abbrev_info *abbrev);
1614 static void free_stack_comp_unit (void *);
1616 static hashval_t partial_die_hash (const void *item);
1618 static int partial_die_eq (const void *item_lhs, const void *item_rhs);
1620 static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit
1621 (sect_offset offset, unsigned int offset_in_dwz, struct objfile *objfile);
1623 static void init_one_comp_unit (struct dwarf2_cu *cu,
1624 struct dwarf2_per_cu_data *per_cu);
1626 static void prepare_one_comp_unit (struct dwarf2_cu *cu,
1627 struct die_info *comp_unit_die,
1628 enum language pretend_language);
1630 static void free_heap_comp_unit (void *);
1632 static void free_cached_comp_units (void *);
1634 static void age_cached_comp_units (void);
1636 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *);
1638 static struct type *set_die_type (struct die_info *, struct type *,
1639 struct dwarf2_cu *);
1641 static void create_all_comp_units (struct objfile *);
1643 static int create_all_type_units (struct objfile *);
1645 static void load_full_comp_unit (struct dwarf2_per_cu_data *,
1648 static void process_full_comp_unit (struct dwarf2_per_cu_data *,
1651 static void process_full_type_unit (struct dwarf2_per_cu_data *,
1654 static void dwarf2_add_dependence (struct dwarf2_cu *,
1655 struct dwarf2_per_cu_data *);
1657 static void dwarf2_mark (struct dwarf2_cu *);
1659 static void dwarf2_clear_marks (struct dwarf2_per_cu_data *);
1661 static struct type *get_die_type_at_offset (sect_offset,
1662 struct dwarf2_per_cu_data *per_cu);
1664 static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
1666 static void dwarf2_release_queue (void *dummy);
1668 static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
1669 enum language pretend_language);
1671 static int maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
1672 struct dwarf2_per_cu_data *per_cu,
1673 enum language pretend_language);
1675 static void process_queue (void);
1677 static void find_file_and_directory (struct die_info *die,
1678 struct dwarf2_cu *cu,
1679 char **name, char **comp_dir);
1681 static char *file_full_name (int file, struct line_header *lh,
1682 const char *comp_dir);
1684 static gdb_byte *read_and_check_comp_unit_head
1685 (struct comp_unit_head *header,
1686 struct dwarf2_section_info *section,
1687 struct dwarf2_section_info *abbrev_section, gdb_byte *info_ptr,
1688 int is_debug_types_section);
1690 static void init_cutu_and_read_dies
1691 (struct dwarf2_per_cu_data *this_cu, struct abbrev_table *abbrev_table,
1692 int use_existing_cu, int keep,
1693 die_reader_func_ftype *die_reader_func, void *data);
1695 static void init_cutu_and_read_dies_simple
1696 (struct dwarf2_per_cu_data *this_cu,
1697 die_reader_func_ftype *die_reader_func, void *data);
1699 static htab_t allocate_signatured_type_table (struct objfile *objfile);
1701 static htab_t allocate_dwo_unit_table (struct objfile *objfile);
1703 static struct dwo_unit *lookup_dwo_comp_unit
1704 (struct dwarf2_per_cu_data *, const char *, const char *, ULONGEST);
1706 static struct dwo_unit *lookup_dwo_type_unit
1707 (struct signatured_type *, const char *, const char *);
1709 static void free_dwo_file_cleanup (void *);
1711 static void process_cu_includes (void);
1715 /* Convert VALUE between big- and little-endian. */
1717 byte_swap (offset_type value)
1721 result = (value & 0xff) << 24;
1722 result |= (value & 0xff00) << 8;
1723 result |= (value & 0xff0000) >> 8;
1724 result |= (value & 0xff000000) >> 24;
1728 #define MAYBE_SWAP(V) byte_swap (V)
1731 #define MAYBE_SWAP(V) (V)
1732 #endif /* WORDS_BIGENDIAN */
1734 /* The suffix for an index file. */
1735 #define INDEX_SUFFIX ".gdb-index"
1737 static const char *dwarf2_physname (char *name, struct die_info *die,
1738 struct dwarf2_cu *cu);
1740 /* Try to locate the sections we need for DWARF 2 debugging
1741 information and return true if we have enough to do something.
1742 NAMES points to the dwarf2 section names, or is NULL if the standard
1743 ELF names are used. */
1746 dwarf2_has_info (struct objfile *objfile,
1747 const struct dwarf2_debug_sections *names)
1749 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
1750 if (!dwarf2_per_objfile)
1752 /* Initialize per-objfile state. */
1753 struct dwarf2_per_objfile *data
1754 = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
1756 memset (data, 0, sizeof (*data));
1757 set_objfile_data (objfile, dwarf2_objfile_data_key, data);
1758 dwarf2_per_objfile = data;
1760 bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections,
1762 dwarf2_per_objfile->objfile = objfile;
1764 return (dwarf2_per_objfile->info.asection != NULL
1765 && dwarf2_per_objfile->abbrev.asection != NULL);
1768 /* When loading sections, we look either for uncompressed section or for
1769 compressed section names. */
1772 section_is_p (const char *section_name,
1773 const struct dwarf2_section_names *names)
1775 if (names->normal != NULL
1776 && strcmp (section_name, names->normal) == 0)
1778 if (names->compressed != NULL
1779 && strcmp (section_name, names->compressed) == 0)
1784 /* This function is mapped across the sections and remembers the
1785 offset and size of each of the debugging sections we are interested
1789 dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames)
1791 const struct dwarf2_debug_sections *names;
1792 flagword aflag = bfd_get_section_flags (abfd, sectp);
1795 names = &dwarf2_elf_names;
1797 names = (const struct dwarf2_debug_sections *) vnames;
1799 if ((aflag & SEC_HAS_CONTENTS) == 0)
1802 else if (section_is_p (sectp->name, &names->info))
1804 dwarf2_per_objfile->info.asection = sectp;
1805 dwarf2_per_objfile->info.size = bfd_get_section_size (sectp);
1807 else if (section_is_p (sectp->name, &names->abbrev))
1809 dwarf2_per_objfile->abbrev.asection = sectp;
1810 dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp);
1812 else if (section_is_p (sectp->name, &names->line))
1814 dwarf2_per_objfile->line.asection = sectp;
1815 dwarf2_per_objfile->line.size = bfd_get_section_size (sectp);
1817 else if (section_is_p (sectp->name, &names->loc))
1819 dwarf2_per_objfile->loc.asection = sectp;
1820 dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp);
1822 else if (section_is_p (sectp->name, &names->macinfo))
1824 dwarf2_per_objfile->macinfo.asection = sectp;
1825 dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp);
1827 else if (section_is_p (sectp->name, &names->macro))
1829 dwarf2_per_objfile->macro.asection = sectp;
1830 dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp);
1832 else if (section_is_p (sectp->name, &names->str))
1834 dwarf2_per_objfile->str.asection = sectp;
1835 dwarf2_per_objfile->str.size = bfd_get_section_size (sectp);
1837 else if (section_is_p (sectp->name, &names->addr))
1839 dwarf2_per_objfile->addr.asection = sectp;
1840 dwarf2_per_objfile->addr.size = bfd_get_section_size (sectp);
1842 else if (section_is_p (sectp->name, &names->frame))
1844 dwarf2_per_objfile->frame.asection = sectp;
1845 dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp);
1847 else if (section_is_p (sectp->name, &names->eh_frame))
1849 dwarf2_per_objfile->eh_frame.asection = sectp;
1850 dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp);
1852 else if (section_is_p (sectp->name, &names->ranges))
1854 dwarf2_per_objfile->ranges.asection = sectp;
1855 dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp);
1857 else if (section_is_p (sectp->name, &names->types))
1859 struct dwarf2_section_info type_section;
1861 memset (&type_section, 0, sizeof (type_section));
1862 type_section.asection = sectp;
1863 type_section.size = bfd_get_section_size (sectp);
1865 VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types,
1868 else if (section_is_p (sectp->name, &names->gdb_index))
1870 dwarf2_per_objfile->gdb_index.asection = sectp;
1871 dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp);
1874 if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
1875 && bfd_section_vma (abfd, sectp) == 0)
1876 dwarf2_per_objfile->has_section_at_zero = 1;
1879 /* A helper function that decides whether a section is empty,
1883 dwarf2_section_empty_p (struct dwarf2_section_info *info)
1885 return info->asection == NULL || info->size == 0;
1888 /* Read the contents of the section INFO.
1889 OBJFILE is the main object file, but not necessarily the file where
1890 the section comes from. E.g., for DWO files INFO->asection->owner
1891 is the bfd of the DWO file.
1892 If the section is compressed, uncompress it before returning. */
1895 dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
1897 asection *sectp = info->asection;
1899 gdb_byte *buf, *retbuf;
1900 unsigned char header[4];
1904 info->buffer = NULL;
1907 if (dwarf2_section_empty_p (info))
1910 abfd = sectp->owner;
1912 /* If the section has relocations, we must read it ourselves.
1913 Otherwise we attach it to the BFD. */
1914 if ((sectp->flags & SEC_RELOC) == 0)
1916 const gdb_byte *bytes = gdb_bfd_map_section (sectp, &info->size);
1918 /* We have to cast away const here for historical reasons.
1919 Fixing dwarf2read to be const-correct would be quite nice. */
1920 info->buffer = (gdb_byte *) bytes;
1924 buf = obstack_alloc (&objfile->objfile_obstack, info->size);
1927 /* When debugging .o files, we may need to apply relocations; see
1928 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1929 We never compress sections in .o files, so we only need to
1930 try this when the section is not compressed. */
1931 retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
1934 info->buffer = retbuf;
1938 if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
1939 || bfd_bread (buf, info->size, abfd) != info->size)
1940 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1941 bfd_get_filename (abfd));
1944 /* A helper function that returns the size of a section in a safe way.
1945 If you are positive that the section has been read before using the
1946 size, then it is safe to refer to the dwarf2_section_info object's
1947 "size" field directly. In other cases, you must call this
1948 function, because for compressed sections the size field is not set
1949 correctly until the section has been read. */
1951 static bfd_size_type
1952 dwarf2_section_size (struct objfile *objfile,
1953 struct dwarf2_section_info *info)
1956 dwarf2_read_section (objfile, info);
1960 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1964 dwarf2_get_section_info (struct objfile *objfile,
1965 enum dwarf2_section_enum sect,
1966 asection **sectp, gdb_byte **bufp,
1967 bfd_size_type *sizep)
1969 struct dwarf2_per_objfile *data
1970 = objfile_data (objfile, dwarf2_objfile_data_key);
1971 struct dwarf2_section_info *info;
1973 /* We may see an objfile without any DWARF, in which case we just
1984 case DWARF2_DEBUG_FRAME:
1985 info = &data->frame;
1987 case DWARF2_EH_FRAME:
1988 info = &data->eh_frame;
1991 gdb_assert_not_reached ("unexpected section");
1994 dwarf2_read_section (objfile, info);
1996 *sectp = info->asection;
1997 *bufp = info->buffer;
1998 *sizep = info->size;
2001 /* A helper function to find the sections for a .dwz file. */
2004 locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
2006 struct dwz_file *dwz_file = arg;
2008 /* Note that we only support the standard ELF names, because .dwz
2009 is ELF-only (at the time of writing). */
2010 if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev))
2012 dwz_file->abbrev.asection = sectp;
2013 dwz_file->abbrev.size = bfd_get_section_size (sectp);
2015 else if (section_is_p (sectp->name, &dwarf2_elf_names.info))
2017 dwz_file->info.asection = sectp;
2018 dwz_file->info.size = bfd_get_section_size (sectp);
2020 else if (section_is_p (sectp->name, &dwarf2_elf_names.str))
2022 dwz_file->str.asection = sectp;
2023 dwz_file->str.size = bfd_get_section_size (sectp);
2025 else if (section_is_p (sectp->name, &dwarf2_elf_names.line))
2027 dwz_file->line.asection = sectp;
2028 dwz_file->line.size = bfd_get_section_size (sectp);
2030 else if (section_is_p (sectp->name, &dwarf2_elf_names.macro))
2032 dwz_file->macro.asection = sectp;
2033 dwz_file->macro.size = bfd_get_section_size (sectp);
2035 else if (section_is_p (sectp->name, &dwarf2_elf_names.gdb_index))
2037 dwz_file->gdb_index.asection = sectp;
2038 dwz_file->gdb_index.size = bfd_get_section_size (sectp);
2042 /* Open the separate '.dwz' debug file, if needed. Error if the file
2045 static struct dwz_file *
2046 dwarf2_get_dwz_file (void)
2048 bfd *abfd, *dwz_bfd;
2051 struct cleanup *cleanup;
2052 const char *filename;
2053 struct dwz_file *result;
2055 if (dwarf2_per_objfile->dwz_file != NULL)
2056 return dwarf2_per_objfile->dwz_file;
2058 abfd = dwarf2_per_objfile->objfile->obfd;
2059 section = bfd_get_section_by_name (abfd, ".gnu_debugaltlink");
2060 if (section == NULL)
2061 error (_("could not find '.gnu_debugaltlink' section"));
2062 if (!bfd_malloc_and_get_section (abfd, section, &data))
2063 error (_("could not read '.gnu_debugaltlink' section: %s"),
2064 bfd_errmsg (bfd_get_error ()));
2065 cleanup = make_cleanup (xfree, data);
2068 if (!IS_ABSOLUTE_PATH (filename))
2070 char *abs = gdb_realpath (dwarf2_per_objfile->objfile->name);
2073 make_cleanup (xfree, abs);
2074 abs = ldirname (abs);
2075 make_cleanup (xfree, abs);
2077 rel = concat (abs, SLASH_STRING, filename, (char *) NULL);
2078 make_cleanup (xfree, rel);
2082 /* The format is just a NUL-terminated file name, followed by the
2083 build-id. For now, though, we ignore the build-id. */
2084 dwz_bfd = gdb_bfd_open (filename, gnutarget, -1);
2085 if (dwz_bfd == NULL)
2086 error (_("could not read '%s': %s"), filename,
2087 bfd_errmsg (bfd_get_error ()));
2089 if (!bfd_check_format (dwz_bfd, bfd_object))
2091 gdb_bfd_unref (dwz_bfd);
2092 error (_("file '%s' was not usable: %s"), filename,
2093 bfd_errmsg (bfd_get_error ()));
2096 result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack,
2098 result->dwz_bfd = dwz_bfd;
2100 bfd_map_over_sections (dwz_bfd, locate_dwz_sections, result);
2102 do_cleanups (cleanup);
2107 /* DWARF quick_symbols_functions support. */
2109 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2110 unique line tables, so we maintain a separate table of all .debug_line
2111 derived entries to support the sharing.
2112 All the quick functions need is the list of file names. We discard the
2113 line_header when we're done and don't need to record it here. */
2114 struct quick_file_names
2116 /* The data used to construct the hash key. */
2117 struct stmt_list_hash hash;
2119 /* The number of entries in file_names, real_names. */
2120 unsigned int num_file_names;
2122 /* The file names from the line table, after being run through
2124 const char **file_names;
2126 /* The file names from the line table after being run through
2127 gdb_realpath. These are computed lazily. */
2128 const char **real_names;
2131 /* When using the index (and thus not using psymtabs), each CU has an
2132 object of this type. This is used to hold information needed by
2133 the various "quick" methods. */
2134 struct dwarf2_per_cu_quick_data
2136 /* The file table. This can be NULL if there was no file table
2137 or it's currently not read in.
2138 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2139 struct quick_file_names *file_names;
2141 /* The corresponding symbol table. This is NULL if symbols for this
2142 CU have not yet been read. */
2143 struct symtab *symtab;
2145 /* A temporary mark bit used when iterating over all CUs in
2146 expand_symtabs_matching. */
2147 unsigned int mark : 1;
2149 /* True if we've tried to read the file table and found there isn't one.
2150 There will be no point in trying to read it again next time. */
2151 unsigned int no_file_data : 1;
2154 /* Utility hash function for a stmt_list_hash. */
2157 hash_stmt_list_entry (const struct stmt_list_hash *stmt_list_hash)
2161 if (stmt_list_hash->dwo_unit != NULL)
2162 v += (uintptr_t) stmt_list_hash->dwo_unit->dwo_file;
2163 v += stmt_list_hash->line_offset.sect_off;
2167 /* Utility equality function for a stmt_list_hash. */
2170 eq_stmt_list_entry (const struct stmt_list_hash *lhs,
2171 const struct stmt_list_hash *rhs)
2173 if ((lhs->dwo_unit != NULL) != (rhs->dwo_unit != NULL))
2175 if (lhs->dwo_unit != NULL
2176 && lhs->dwo_unit->dwo_file != rhs->dwo_unit->dwo_file)
2179 return lhs->line_offset.sect_off == rhs->line_offset.sect_off;
2182 /* Hash function for a quick_file_names. */
2185 hash_file_name_entry (const void *e)
2187 const struct quick_file_names *file_data = e;
2189 return hash_stmt_list_entry (&file_data->hash);
2192 /* Equality function for a quick_file_names. */
2195 eq_file_name_entry (const void *a, const void *b)
2197 const struct quick_file_names *ea = a;
2198 const struct quick_file_names *eb = b;
2200 return eq_stmt_list_entry (&ea->hash, &eb->hash);
2203 /* Delete function for a quick_file_names. */
2206 delete_file_name_entry (void *e)
2208 struct quick_file_names *file_data = e;
2211 for (i = 0; i < file_data->num_file_names; ++i)
2213 xfree ((void*) file_data->file_names[i]);
2214 if (file_data->real_names)
2215 xfree ((void*) file_data->real_names[i]);
2218 /* The space for the struct itself lives on objfile_obstack,
2219 so we don't free it here. */
2222 /* Create a quick_file_names hash table. */
2225 create_quick_file_names_table (unsigned int nr_initial_entries)
2227 return htab_create_alloc (nr_initial_entries,
2228 hash_file_name_entry, eq_file_name_entry,
2229 delete_file_name_entry, xcalloc, xfree);
2232 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2233 have to be created afterwards. You should call age_cached_comp_units after
2234 processing PER_CU->CU. dw2_setup must have been already called. */
2237 load_cu (struct dwarf2_per_cu_data *per_cu)
2239 if (per_cu->is_debug_types)
2240 load_full_type_unit (per_cu);
2242 load_full_comp_unit (per_cu, language_minimal);
2244 gdb_assert (per_cu->cu != NULL);
2246 dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
2249 /* Read in the symbols for PER_CU. */
2252 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
2254 struct cleanup *back_to;
2256 /* Skip type_unit_groups, reading the type units they contain
2257 is handled elsewhere. */
2258 if (IS_TYPE_UNIT_GROUP (per_cu))
2261 back_to = make_cleanup (dwarf2_release_queue, NULL);
2263 if (dwarf2_per_objfile->using_index
2264 ? per_cu->v.quick->symtab == NULL
2265 : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin))
2267 queue_comp_unit (per_cu, language_minimal);
2273 /* Age the cache, releasing compilation units that have not
2274 been used recently. */
2275 age_cached_comp_units ();
2277 do_cleanups (back_to);
2280 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2281 the objfile from which this CU came. Returns the resulting symbol
2284 static struct symtab *
2285 dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
2287 gdb_assert (dwarf2_per_objfile->using_index);
2288 if (!per_cu->v.quick->symtab)
2290 struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
2291 increment_reading_symtab ();
2292 dw2_do_instantiate_symtab (per_cu);
2293 process_cu_includes ();
2294 do_cleanups (back_to);
2296 return per_cu->v.quick->symtab;
2299 /* Return the CU given its index.
2301 This is intended for loops like:
2303 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2304 + dwarf2_per_objfile->n_type_units); ++i)
2306 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
2312 static struct dwarf2_per_cu_data *
2313 dw2_get_cu (int index)
2315 if (index >= dwarf2_per_objfile->n_comp_units)
2317 index -= dwarf2_per_objfile->n_comp_units;
2318 gdb_assert (index < dwarf2_per_objfile->n_type_units);
2319 return &dwarf2_per_objfile->all_type_units[index]->per_cu;
2322 return dwarf2_per_objfile->all_comp_units[index];
2325 /* Return the primary CU given its index.
2326 The difference between this function and dw2_get_cu is in the handling
2327 of type units (TUs). Here we return the type_unit_group object.
2329 This is intended for loops like:
2331 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
2332 + dwarf2_per_objfile->n_type_unit_groups); ++i)
2334 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
2340 static struct dwarf2_per_cu_data *
2341 dw2_get_primary_cu (int index)
2343 if (index >= dwarf2_per_objfile->n_comp_units)
2345 index -= dwarf2_per_objfile->n_comp_units;
2346 gdb_assert (index < dwarf2_per_objfile->n_type_unit_groups);
2347 return &dwarf2_per_objfile->all_type_unit_groups[index]->per_cu;
2350 return dwarf2_per_objfile->all_comp_units[index];
2353 /* A helper function that knows how to read a 64-bit value in a way
2354 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
2358 extract_cu_value (const char *bytes, ULONGEST *result)
2360 if (sizeof (ULONGEST) < 8)
2364 /* Ignore the upper 4 bytes if they are all zero. */
2365 for (i = 0; i < 4; ++i)
2366 if (bytes[i + 4] != 0)
2369 *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE);
2372 *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE);
2376 /* A helper for create_cus_from_index that handles a given list of
2380 create_cus_from_index_list (struct objfile *objfile,
2381 const gdb_byte *cu_list, offset_type n_elements,
2382 struct dwarf2_section_info *section,
2388 for (i = 0; i < n_elements; i += 2)
2390 struct dwarf2_per_cu_data *the_cu;
2391 ULONGEST offset, length;
2393 if (!extract_cu_value (cu_list, &offset)
2394 || !extract_cu_value (cu_list + 8, &length))
2398 the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2399 struct dwarf2_per_cu_data);
2400 the_cu->offset.sect_off = offset;
2401 the_cu->length = length;
2402 the_cu->objfile = objfile;
2403 the_cu->info_or_types_section = section;
2404 the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2405 struct dwarf2_per_cu_quick_data);
2406 the_cu->is_dwz = is_dwz;
2407 dwarf2_per_objfile->all_comp_units[base_offset + i / 2] = the_cu;
2413 /* Read the CU list from the mapped index, and use it to create all
2414 the CU objects for this objfile. Return 0 if something went wrong,
2415 1 if everything went ok. */
2418 create_cus_from_index (struct objfile *objfile,
2419 const gdb_byte *cu_list, offset_type cu_list_elements,
2420 const gdb_byte *dwz_list, offset_type dwz_elements)
2422 struct dwz_file *dwz;
2424 dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2;
2425 dwarf2_per_objfile->all_comp_units
2426 = obstack_alloc (&objfile->objfile_obstack,
2427 dwarf2_per_objfile->n_comp_units
2428 * sizeof (struct dwarf2_per_cu_data *));
2430 if (!create_cus_from_index_list (objfile, cu_list, cu_list_elements,
2431 &dwarf2_per_objfile->info, 0, 0))
2434 if (dwz_elements == 0)
2437 dwz = dwarf2_get_dwz_file ();
2438 return create_cus_from_index_list (objfile, dwz_list, dwz_elements,
2439 &dwz->info, 1, cu_list_elements / 2);
2442 /* Create the signatured type hash table from the index. */
2445 create_signatured_type_table_from_index (struct objfile *objfile,
2446 struct dwarf2_section_info *section,
2447 const gdb_byte *bytes,
2448 offset_type elements)
2451 htab_t sig_types_hash;
2453 dwarf2_per_objfile->n_type_units = elements / 3;
2454 dwarf2_per_objfile->all_type_units
2455 = obstack_alloc (&objfile->objfile_obstack,
2456 dwarf2_per_objfile->n_type_units
2457 * sizeof (struct signatured_type *));
2459 sig_types_hash = allocate_signatured_type_table (objfile);
2461 for (i = 0; i < elements; i += 3)
2463 struct signatured_type *sig_type;
2464 ULONGEST offset, type_offset_in_tu, signature;
2467 if (!extract_cu_value (bytes, &offset)
2468 || !extract_cu_value (bytes + 8, &type_offset_in_tu))
2470 signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
2473 sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2474 struct signatured_type);
2475 sig_type->signature = signature;
2476 sig_type->type_offset_in_tu.cu_off = type_offset_in_tu;
2477 sig_type->per_cu.is_debug_types = 1;
2478 sig_type->per_cu.info_or_types_section = section;
2479 sig_type->per_cu.offset.sect_off = offset;
2480 sig_type->per_cu.objfile = objfile;
2481 sig_type->per_cu.v.quick
2482 = OBSTACK_ZALLOC (&objfile->objfile_obstack,
2483 struct dwarf2_per_cu_quick_data);
2485 slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
2488 dwarf2_per_objfile->all_type_units[i / 3] = sig_type;
2491 dwarf2_per_objfile->signatured_types = sig_types_hash;
2496 /* Read the address map data from the mapped index, and use it to
2497 populate the objfile's psymtabs_addrmap. */
2500 create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index)
2502 const gdb_byte *iter, *end;
2503 struct obstack temp_obstack;
2504 struct addrmap *mutable_map;
2505 struct cleanup *cleanup;
2508 obstack_init (&temp_obstack);
2509 cleanup = make_cleanup_obstack_free (&temp_obstack);
2510 mutable_map = addrmap_create_mutable (&temp_obstack);
2512 iter = index->address_table;
2513 end = iter + index->address_table_size;
2515 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2519 ULONGEST hi, lo, cu_index;
2520 lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2522 hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE);
2524 cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE);
2527 addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1,
2528 dw2_get_cu (cu_index));
2531 objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map,
2532 &objfile->objfile_obstack);
2533 do_cleanups (cleanup);
2536 /* The hash function for strings in the mapped index. This is the same as
2537 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
2538 implementation. This is necessary because the hash function is tied to the
2539 format of the mapped index file. The hash values do not have to match with
2542 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
2545 mapped_index_string_hash (int index_version, const void *p)
2547 const unsigned char *str = (const unsigned char *) p;
2551 while ((c = *str++) != 0)
2553 if (index_version >= 5)
2555 r = r * 67 + c - 113;
2561 /* Find a slot in the mapped index INDEX for the object named NAME.
2562 If NAME is found, set *VEC_OUT to point to the CU vector in the
2563 constant pool and return 1. If NAME cannot be found, return 0. */
2566 find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
2567 offset_type **vec_out)
2569 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
2571 offset_type slot, step;
2572 int (*cmp) (const char *, const char *);
2574 if (current_language->la_language == language_cplus
2575 || current_language->la_language == language_java
2576 || current_language->la_language == language_fortran)
2578 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2580 const char *paren = strchr (name, '(');
2586 dup = xmalloc (paren - name + 1);
2587 memcpy (dup, name, paren - name);
2588 dup[paren - name] = 0;
2590 make_cleanup (xfree, dup);
2595 /* Index version 4 did not support case insensitive searches. But the
2596 indices for case insensitive languages are built in lowercase, therefore
2597 simulate our NAME being searched is also lowercased. */
2598 hash = mapped_index_string_hash ((index->version == 4
2599 && case_sensitivity == case_sensitive_off
2600 ? 5 : index->version),
2603 slot = hash & (index->symbol_table_slots - 1);
2604 step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1;
2605 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
2609 /* Convert a slot number to an offset into the table. */
2610 offset_type i = 2 * slot;
2612 if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0)
2614 do_cleanups (back_to);
2618 str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]);
2619 if (!cmp (name, str))
2621 *vec_out = (offset_type *) (index->constant_pool
2622 + MAYBE_SWAP (index->symbol_table[i + 1]));
2623 do_cleanups (back_to);
2627 slot = (slot + step) & (index->symbol_table_slots - 1);
2631 /* A helper function that reads the .gdb_index from SECTION and fills
2632 in MAP. FILENAME is the name of the file containing the section;
2633 it is used for error reporting. DEPRECATED_OK is nonzero if it is
2634 ok to use deprecated sections.
2636 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2637 out parameters that are filled in with information about the CU and
2638 TU lists in the section.
2640 Returns 1 if all went well, 0 otherwise. */
2643 read_index_from_section (struct objfile *objfile,
2644 const char *filename,
2646 struct dwarf2_section_info *section,
2647 struct mapped_index *map,
2648 const gdb_byte **cu_list,
2649 offset_type *cu_list_elements,
2650 const gdb_byte **types_list,
2651 offset_type *types_list_elements)
2654 offset_type version;
2655 offset_type *metadata;
2658 if (dwarf2_section_empty_p (section))
2661 /* Older elfutils strip versions could keep the section in the main
2662 executable while splitting it for the separate debug info file. */
2663 if ((bfd_get_file_flags (section->asection) & SEC_HAS_CONTENTS) == 0)
2666 dwarf2_read_section (objfile, section);
2668 addr = section->buffer;
2669 /* Version check. */
2670 version = MAYBE_SWAP (*(offset_type *) addr);
2671 /* Versions earlier than 3 emitted every copy of a psymbol. This
2672 causes the index to behave very poorly for certain requests. Version 3
2673 contained incomplete addrmap. So, it seems better to just ignore such
2677 static int warning_printed = 0;
2678 if (!warning_printed)
2680 warning (_("Skipping obsolete .gdb_index section in %s."),
2682 warning_printed = 1;
2686 /* Index version 4 uses a different hash function than index version
2689 Versions earlier than 6 did not emit psymbols for inlined
2690 functions. Using these files will cause GDB not to be able to
2691 set breakpoints on inlined functions by name, so we ignore these
2692 indices unless the user has done
2693 "set use-deprecated-index-sections on". */
2694 if (version < 6 && !deprecated_ok)
2696 static int warning_printed = 0;
2697 if (!warning_printed)
2700 Skipping deprecated .gdb_index section in %s.\n\
2701 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2702 to use the section anyway."),
2704 warning_printed = 1;
2708 /* Indexes with higher version than the one supported by GDB may be no
2709 longer backward compatible. */
2713 map->version = version;
2714 map->total_size = section->size;
2716 metadata = (offset_type *) (addr + sizeof (offset_type));
2719 *cu_list = addr + MAYBE_SWAP (metadata[i]);
2720 *cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i]))
2724 *types_list = addr + MAYBE_SWAP (metadata[i]);
2725 *types_list_elements = ((MAYBE_SWAP (metadata[i + 1])
2726 - MAYBE_SWAP (metadata[i]))
2730 map->address_table = addr + MAYBE_SWAP (metadata[i]);
2731 map->address_table_size = (MAYBE_SWAP (metadata[i + 1])
2732 - MAYBE_SWAP (metadata[i]));
2735 map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i]));
2736 map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1])
2737 - MAYBE_SWAP (metadata[i]))
2738 / (2 * sizeof (offset_type)));
2741 map->constant_pool = addr + MAYBE_SWAP (metadata[i]);
2747 /* Read the index file. If everything went ok, initialize the "quick"
2748 elements of all the CUs and return 1. Otherwise, return 0. */
2751 dwarf2_read_index (struct objfile *objfile)
2753 struct mapped_index local_map, *map;
2754 const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
2755 offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
2757 if (!read_index_from_section (objfile, objfile->name,
2758 use_deprecated_index_sections,
2759 &dwarf2_per_objfile->gdb_index, &local_map,
2760 &cu_list, &cu_list_elements,
2761 &types_list, &types_list_elements))
2764 /* Don't use the index if it's empty. */
2765 if (local_map.symbol_table_slots == 0)
2768 /* If there is a .dwz file, read it so we can get its CU list as
2770 if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
2772 struct dwz_file *dwz = dwarf2_get_dwz_file ();
2773 struct mapped_index dwz_map;
2774 const gdb_byte *dwz_types_ignore;
2775 offset_type dwz_types_elements_ignore;
2777 if (!read_index_from_section (objfile, bfd_get_filename (dwz->dwz_bfd),
2779 &dwz->gdb_index, &dwz_map,
2780 &dwz_list, &dwz_list_elements,
2782 &dwz_types_elements_ignore))
2784 warning (_("could not read '.gdb_index' section from %s; skipping"),
2785 bfd_get_filename (dwz->dwz_bfd));
2790 if (!create_cus_from_index (objfile, cu_list, cu_list_elements,
2791 dwz_list, dwz_list_elements))
2794 if (types_list_elements)
2796 struct dwarf2_section_info *section;
2798 /* We can only handle a single .debug_types when we have an
2800 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
2803 section = VEC_index (dwarf2_section_info_def,
2804 dwarf2_per_objfile->types, 0);
2806 if (!create_signatured_type_table_from_index (objfile, section,
2808 types_list_elements))
2812 create_addrmap_from_index (objfile, &local_map);
2814 map = obstack_alloc (&objfile->objfile_obstack, sizeof (struct mapped_index));
2817 dwarf2_per_objfile->index_table = map;
2818 dwarf2_per_objfile->using_index = 1;
2819 dwarf2_per_objfile->quick_file_names_table =
2820 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
2825 /* A helper for the "quick" functions which sets the global
2826 dwarf2_per_objfile according to OBJFILE. */
2829 dw2_setup (struct objfile *objfile)
2831 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
2832 gdb_assert (dwarf2_per_objfile);
2835 /* Reader function for dw2_build_type_unit_groups. */
2838 dw2_build_type_unit_groups_reader (const struct die_reader_specs *reader,
2840 struct die_info *type_unit_die,
2844 struct dwarf2_cu *cu = reader->cu;
2845 struct attribute *attr;
2846 struct type_unit_group *tu_group;
2848 gdb_assert (data == NULL);
2853 attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
2854 /* Call this for its side-effect of creating the associated
2855 struct type_unit_group if it doesn't already exist. */
2856 tu_group = get_type_unit_group (cu, attr);
2859 /* Build dwarf2_per_objfile->type_unit_groups.
2860 This function may be called multiple times. */
2863 dw2_build_type_unit_groups (void)
2865 if (dwarf2_per_objfile->type_unit_groups == NULL)
2866 build_type_unit_groups (dw2_build_type_unit_groups_reader, NULL);
2869 /* die_reader_func for dw2_get_file_names. */
2872 dw2_get_file_names_reader (const struct die_reader_specs *reader,
2874 struct die_info *comp_unit_die,
2878 struct dwarf2_cu *cu = reader->cu;
2879 struct dwarf2_per_cu_data *this_cu = cu->per_cu;
2880 struct objfile *objfile = dwarf2_per_objfile->objfile;
2881 struct dwarf2_per_cu_data *lh_cu;
2882 struct line_header *lh;
2883 struct attribute *attr;
2885 char *name, *comp_dir;
2887 struct quick_file_names *qfn;
2888 unsigned int line_offset;
2890 /* Our callers never want to match partial units -- instead they
2891 will match the enclosing full CU. */
2892 if (comp_unit_die->tag == DW_TAG_partial_unit)
2894 this_cu->v.quick->no_file_data = 1;
2898 /* If we're reading the line header for TUs, store it in the "per_cu"
2900 if (this_cu->is_debug_types)
2902 struct type_unit_group *tu_group = data;
2904 gdb_assert (tu_group != NULL);
2905 lh_cu = &tu_group->per_cu;
2914 attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu);
2917 struct quick_file_names find_entry;
2919 line_offset = DW_UNSND (attr);
2921 /* We may have already read in this line header (TU line header sharing).
2922 If we have we're done. */
2923 find_entry.hash.dwo_unit = cu->dwo_unit;
2924 find_entry.hash.line_offset.sect_off = line_offset;
2925 slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
2926 &find_entry, INSERT);
2929 lh_cu->v.quick->file_names = *slot;
2933 lh = dwarf_decode_line_header (line_offset, cu);
2937 lh_cu->v.quick->no_file_data = 1;
2941 qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn));
2942 qfn->hash.dwo_unit = cu->dwo_unit;
2943 qfn->hash.line_offset.sect_off = line_offset;
2944 gdb_assert (slot != NULL);
2947 find_file_and_directory (comp_unit_die, cu, &name, &comp_dir);
2949 qfn->num_file_names = lh->num_file_names;
2950 qfn->file_names = obstack_alloc (&objfile->objfile_obstack,
2951 lh->num_file_names * sizeof (char *));
2952 for (i = 0; i < lh->num_file_names; ++i)
2953 qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir);
2954 qfn->real_names = NULL;
2956 free_line_header (lh);
2958 lh_cu->v.quick->file_names = qfn;
2961 /* A helper for the "quick" functions which attempts to read the line
2962 table for THIS_CU. */
2964 static struct quick_file_names *
2965 dw2_get_file_names (struct objfile *objfile,
2966 struct dwarf2_per_cu_data *this_cu)
2968 /* For TUs this should only be called on the parent group. */
2969 if (this_cu->is_debug_types)
2970 gdb_assert (IS_TYPE_UNIT_GROUP (this_cu));
2972 if (this_cu->v.quick->file_names != NULL)
2973 return this_cu->v.quick->file_names;
2974 /* If we know there is no line data, no point in looking again. */
2975 if (this_cu->v.quick->no_file_data)
2978 /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute
2979 in the stub for CUs, there's is no need to lookup the DWO file.
2980 However, that's not the case for TUs where DW_AT_stmt_list lives in the
2982 if (this_cu->is_debug_types)
2984 struct type_unit_group *tu_group = this_cu->s.type_unit_group;
2986 init_cutu_and_read_dies (tu_group->t.first_tu, NULL, 0, 0,
2987 dw2_get_file_names_reader, tu_group);
2990 init_cutu_and_read_dies_simple (this_cu, dw2_get_file_names_reader, NULL);
2992 if (this_cu->v.quick->no_file_data)
2994 return this_cu->v.quick->file_names;
2997 /* A helper for the "quick" functions which computes and caches the
2998 real path for a given file name from the line table. */
3001 dw2_get_real_path (struct objfile *objfile,
3002 struct quick_file_names *qfn, int index)
3004 if (qfn->real_names == NULL)
3005 qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack,
3006 qfn->num_file_names, sizeof (char *));
3008 if (qfn->real_names[index] == NULL)
3009 qfn->real_names[index] = gdb_realpath (qfn->file_names[index]);
3011 return qfn->real_names[index];
3014 static struct symtab *
3015 dw2_find_last_source_symtab (struct objfile *objfile)
3019 dw2_setup (objfile);
3020 index = dwarf2_per_objfile->n_comp_units - 1;
3021 return dw2_instantiate_symtab (dw2_get_cu (index));
3024 /* Traversal function for dw2_forget_cached_source_info. */
3027 dw2_free_cached_file_names (void **slot, void *info)
3029 struct quick_file_names *file_data = (struct quick_file_names *) *slot;
3031 if (file_data->real_names)
3035 for (i = 0; i < file_data->num_file_names; ++i)
3037 xfree ((void*) file_data->real_names[i]);
3038 file_data->real_names[i] = NULL;
3046 dw2_forget_cached_source_info (struct objfile *objfile)
3048 dw2_setup (objfile);
3050 htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
3051 dw2_free_cached_file_names, NULL);
3054 /* Helper function for dw2_map_symtabs_matching_filename that expands
3055 the symtabs and calls the iterator. */
3058 dw2_map_expand_apply (struct objfile *objfile,
3059 struct dwarf2_per_cu_data *per_cu,
3061 const char *full_path, const char *real_path,
3062 int (*callback) (struct symtab *, void *),
3065 struct symtab *last_made = objfile->symtabs;
3067 /* Don't visit already-expanded CUs. */
3068 if (per_cu->v.quick->symtab)
3071 /* This may expand more than one symtab, and we want to iterate over
3073 dw2_instantiate_symtab (per_cu);
3075 return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
3076 objfile->symtabs, last_made);
3079 /* Implementation of the map_symtabs_matching_filename method. */
3082 dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name,
3083 const char *full_path, const char *real_path,
3084 int (*callback) (struct symtab *, void *),
3088 const char *name_basename = lbasename (name);
3089 int name_len = strlen (name);
3090 int is_abs = IS_ABSOLUTE_PATH (name);
3092 dw2_setup (objfile);
3094 dw2_build_type_unit_groups ();
3096 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3097 + dwarf2_per_objfile->n_type_unit_groups); ++i)
3100 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
3101 struct quick_file_names *file_data;
3103 /* We only need to look at symtabs not already expanded. */
3104 if (per_cu->v.quick->symtab)
3107 file_data = dw2_get_file_names (objfile, per_cu);
3108 if (file_data == NULL)
3111 for (j = 0; j < file_data->num_file_names; ++j)
3113 const char *this_name = file_data->file_names[j];
3115 if (FILENAME_CMP (name, this_name) == 0
3116 || (!is_abs && compare_filenames_for_search (this_name,
3119 if (dw2_map_expand_apply (objfile, per_cu,
3120 name, full_path, real_path,
3125 /* Before we invoke realpath, which can get expensive when many
3126 files are involved, do a quick comparison of the basenames. */
3127 if (! basenames_may_differ
3128 && FILENAME_CMP (lbasename (this_name), name_basename) != 0)
3131 if (full_path != NULL)
3133 const char *this_real_name = dw2_get_real_path (objfile,
3136 if (this_real_name != NULL
3137 && (FILENAME_CMP (full_path, this_real_name) == 0
3139 && compare_filenames_for_search (this_real_name,
3142 if (dw2_map_expand_apply (objfile, per_cu,
3143 name, full_path, real_path,
3149 if (real_path != NULL)
3151 const char *this_real_name = dw2_get_real_path (objfile,
3154 if (this_real_name != NULL
3155 && (FILENAME_CMP (real_path, this_real_name) == 0
3157 && compare_filenames_for_search (this_real_name,
3160 if (dw2_map_expand_apply (objfile, per_cu,
3161 name, full_path, real_path,
3172 static struct symtab *
3173 dw2_lookup_symbol (struct objfile *objfile, int block_index,
3174 const char *name, domain_enum domain)
3176 /* We do all the work in the pre_expand_symtabs_matching hook
3181 /* A helper function that expands all symtabs that hold an object
3182 named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for
3183 symbols in block BLOCK_KIND. */
3186 dw2_do_expand_symtabs_matching (struct objfile *objfile,
3187 int want_specific_block,
3188 enum block_enum block_kind,
3189 const char *name, domain_enum domain)
3191 struct mapped_index *index;
3193 dw2_setup (objfile);
3195 index = dwarf2_per_objfile->index_table;
3197 /* index_table is NULL if OBJF_READNOW. */
3202 if (find_slot_in_mapped_hash (index, name, &vec))
3204 offset_type i, len = MAYBE_SWAP (*vec);
3205 for (i = 0; i < len; ++i)
3207 offset_type cu_index_and_attrs = MAYBE_SWAP (vec[i + 1]);
3208 offset_type cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs);
3209 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
3210 int want_static = block_kind != GLOBAL_BLOCK;
3211 /* This value is only valid for index versions >= 7. */
3212 int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs);
3213 gdb_index_symbol_kind symbol_kind =
3214 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs);
3215 /* Only check the symbol attributes if they're present.
3216 Indices prior to version 7 don't record them,
3217 and indices >= 7 may elide them for certain symbols
3218 (gold does this). */
3220 (index->version >= 7
3221 && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
3224 && want_specific_block
3225 && want_static != is_static)
3228 /* Only check the symbol's kind if it has one. */
3234 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE
3235 && symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION
3236 /* Some types are also in VAR_DOMAIN. */
3237 && symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3241 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3245 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER)
3253 dw2_instantiate_symtab (per_cu);
3260 dw2_pre_expand_symtabs_matching (struct objfile *objfile,
3261 enum block_enum block_kind, const char *name,
3264 dw2_do_expand_symtabs_matching (objfile, 1, block_kind, name, domain);
3268 dw2_print_stats (struct objfile *objfile)
3272 dw2_setup (objfile);
3274 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3275 + dwarf2_per_objfile->n_type_units); ++i)
3277 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3279 if (!per_cu->v.quick->symtab)
3282 printf_filtered (_(" Number of unread CUs: %d\n"), count);
3286 dw2_dump (struct objfile *objfile)
3288 /* Nothing worth printing. */
3292 dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets,
3293 struct section_offsets *delta)
3295 /* There's nothing to relocate here. */
3299 dw2_expand_symtabs_for_function (struct objfile *objfile,
3300 const char *func_name)
3302 /* Note: It doesn't matter what we pass for block_kind here. */
3303 dw2_do_expand_symtabs_matching (objfile, 0, GLOBAL_BLOCK, func_name,
3308 dw2_expand_all_symtabs (struct objfile *objfile)
3312 dw2_setup (objfile);
3314 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3315 + dwarf2_per_objfile->n_type_units); ++i)
3317 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3319 dw2_instantiate_symtab (per_cu);
3324 dw2_expand_symtabs_with_filename (struct objfile *objfile,
3325 const char *filename)
3329 dw2_setup (objfile);
3331 /* We don't need to consider type units here.
3332 This is only called for examining code, e.g. expand_line_sal.
3333 There can be an order of magnitude (or more) more type units
3334 than comp units, and we avoid them if we can. */
3336 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
3339 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3340 struct quick_file_names *file_data;
3342 /* We only need to look at symtabs not already expanded. */
3343 if (per_cu->v.quick->symtab)
3346 file_data = dw2_get_file_names (objfile, per_cu);
3347 if (file_data == NULL)
3350 for (j = 0; j < file_data->num_file_names; ++j)
3352 const char *this_name = file_data->file_names[j];
3353 if (FILENAME_CMP (this_name, filename) == 0)
3355 dw2_instantiate_symtab (per_cu);
3362 /* A helper function for dw2_find_symbol_file that finds the primary
3363 file name for a given CU. This is a die_reader_func. */
3366 dw2_get_primary_filename_reader (const struct die_reader_specs *reader,
3368 struct die_info *comp_unit_die,
3372 const char **result_ptr = data;
3373 struct dwarf2_cu *cu = reader->cu;
3374 struct attribute *attr;
3376 attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu);
3380 *result_ptr = DW_STRING (attr);
3384 dw2_find_symbol_file (struct objfile *objfile, const char *name)
3386 struct dwarf2_per_cu_data *per_cu;
3388 struct quick_file_names *file_data;
3389 const char *filename;
3391 dw2_setup (objfile);
3393 /* index_table is NULL if OBJF_READNOW. */
3394 if (!dwarf2_per_objfile->index_table)
3398 ALL_OBJFILE_PRIMARY_SYMTABS (objfile, s)
3400 struct blockvector *bv = BLOCKVECTOR (s);
3401 const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
3402 struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN);
3405 return SYMBOL_SYMTAB (sym)->filename;
3410 if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table,
3414 /* Note that this just looks at the very first one named NAME -- but
3415 actually we are looking for a function. find_main_filename
3416 should be rewritten so that it doesn't require a custom hook. It
3417 could just use the ordinary symbol tables. */
3418 /* vec[0] is the length, which must always be >0. */
3419 per_cu = dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec[1])));
3421 if (per_cu->v.quick->symtab != NULL)
3422 return per_cu->v.quick->symtab->filename;
3424 init_cutu_and_read_dies (per_cu, NULL, 0, 0,
3425 dw2_get_primary_filename_reader, &filename);
3431 dw2_map_matching_symbols (const char * name, domain_enum namespace,
3432 struct objfile *objfile, int global,
3433 int (*callback) (struct block *,
3434 struct symbol *, void *),
3435 void *data, symbol_compare_ftype *match,
3436 symbol_compare_ftype *ordered_compare)
3438 /* Currently unimplemented; used for Ada. The function can be called if the
3439 current language is Ada for a non-Ada objfile using GNU index. As Ada
3440 does not look for non-Ada symbols this function should just return. */
3444 dw2_expand_symtabs_matching
3445 (struct objfile *objfile,
3446 int (*file_matcher) (const char *, void *),
3447 int (*name_matcher) (const char *, void *),
3448 enum search_domain kind,
3453 struct mapped_index *index;
3455 dw2_setup (objfile);
3457 /* index_table is NULL if OBJF_READNOW. */
3458 if (!dwarf2_per_objfile->index_table)
3460 index = dwarf2_per_objfile->index_table;
3462 if (file_matcher != NULL)
3464 struct cleanup *cleanup;
3465 htab_t visited_found, visited_not_found;
3467 dw2_build_type_unit_groups ();
3469 visited_found = htab_create_alloc (10,
3470 htab_hash_pointer, htab_eq_pointer,
3471 NULL, xcalloc, xfree);
3472 cleanup = make_cleanup_htab_delete (visited_found);
3473 visited_not_found = htab_create_alloc (10,
3474 htab_hash_pointer, htab_eq_pointer,
3475 NULL, xcalloc, xfree);
3476 make_cleanup_htab_delete (visited_not_found);
3478 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3479 + dwarf2_per_objfile->n_type_unit_groups); ++i)
3482 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
3483 struct quick_file_names *file_data;
3486 per_cu->v.quick->mark = 0;
3488 /* We only need to look at symtabs not already expanded. */
3489 if (per_cu->v.quick->symtab)
3492 file_data = dw2_get_file_names (objfile, per_cu);
3493 if (file_data == NULL)
3496 if (htab_find (visited_not_found, file_data) != NULL)
3498 else if (htab_find (visited_found, file_data) != NULL)
3500 per_cu->v.quick->mark = 1;
3504 for (j = 0; j < file_data->num_file_names; ++j)
3506 if (file_matcher (file_data->file_names[j], data))
3508 per_cu->v.quick->mark = 1;
3513 slot = htab_find_slot (per_cu->v.quick->mark
3515 : visited_not_found,
3520 do_cleanups (cleanup);
3523 for (iter = 0; iter < index->symbol_table_slots; ++iter)
3525 offset_type idx = 2 * iter;
3527 offset_type *vec, vec_len, vec_idx;
3529 if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0)
3532 name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]);
3534 if (! (*name_matcher) (name, data))
3537 /* The name was matched, now expand corresponding CUs that were
3539 vec = (offset_type *) (index->constant_pool
3540 + MAYBE_SWAP (index->symbol_table[idx + 1]));
3541 vec_len = MAYBE_SWAP (vec[0]);
3542 for (vec_idx = 0; vec_idx < vec_len; ++vec_idx)
3544 struct dwarf2_per_cu_data *per_cu;
3545 offset_type cu_index_and_attrs = MAYBE_SWAP (vec[vec_idx + 1]);
3546 gdb_index_symbol_kind symbol_kind =
3547 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs);
3548 int cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs);
3550 /* Don't crash on bad data. */
3551 if (cu_index >= (dwarf2_per_objfile->n_comp_units
3552 + dwarf2_per_objfile->n_type_units))
3555 /* Only check the symbol's kind if it has one.
3556 Indices prior to version 7 don't record it. */
3557 if (index->version >= 7)
3561 case VARIABLES_DOMAIN:
3562 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE)
3565 case FUNCTIONS_DOMAIN:
3566 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION)
3570 if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE)
3578 per_cu = dw2_get_cu (cu_index);
3579 if (file_matcher == NULL || per_cu->v.quick->mark)
3580 dw2_instantiate_symtab (per_cu);
3585 /* A helper for dw2_find_pc_sect_symtab which finds the most specific
3588 static struct symtab *
3589 recursively_find_pc_sect_symtab (struct symtab *symtab, CORE_ADDR pc)
3593 if (BLOCKVECTOR (symtab) != NULL
3594 && blockvector_contains_pc (BLOCKVECTOR (symtab), pc))
3597 if (symtab->includes == NULL)
3600 for (i = 0; symtab->includes[i]; ++i)
3602 struct symtab *s = symtab->includes[i];
3604 s = recursively_find_pc_sect_symtab (s, pc);
3612 static struct symtab *
3613 dw2_find_pc_sect_symtab (struct objfile *objfile,
3614 struct minimal_symbol *msymbol,
3616 struct obj_section *section,
3619 struct dwarf2_per_cu_data *data;
3620 struct symtab *result;
3622 dw2_setup (objfile);
3624 if (!objfile->psymtabs_addrmap)
3627 data = addrmap_find (objfile->psymtabs_addrmap, pc);
3631 if (warn_if_readin && data->v.quick->symtab)
3632 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
3633 paddress (get_objfile_arch (objfile), pc));
3635 result = recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data), pc);
3636 gdb_assert (result != NULL);
3641 dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
3642 void *data, int need_fullname)
3645 struct cleanup *cleanup;
3646 htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
3647 NULL, xcalloc, xfree);
3649 cleanup = make_cleanup_htab_delete (visited);
3650 dw2_setup (objfile);
3652 dw2_build_type_unit_groups ();
3654 /* We can ignore file names coming from already-expanded CUs. */
3655 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3656 + dwarf2_per_objfile->n_type_units); ++i)
3658 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3660 if (per_cu->v.quick->symtab)
3662 void **slot = htab_find_slot (visited, per_cu->v.quick->file_names,
3665 *slot = per_cu->v.quick->file_names;
3669 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3670 + dwarf2_per_objfile->n_type_unit_groups); ++i)
3673 struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i);
3674 struct quick_file_names *file_data;
3677 /* We only need to look at symtabs not already expanded. */
3678 if (per_cu->v.quick->symtab)
3681 file_data = dw2_get_file_names (objfile, per_cu);
3682 if (file_data == NULL)
3685 slot = htab_find_slot (visited, file_data, INSERT);
3688 /* Already visited. */
3693 for (j = 0; j < file_data->num_file_names; ++j)
3695 const char *this_real_name;
3698 this_real_name = dw2_get_real_path (objfile, file_data, j);
3700 this_real_name = NULL;
3701 (*fun) (file_data->file_names[j], this_real_name, data);
3705 do_cleanups (cleanup);
3709 dw2_has_symbols (struct objfile *objfile)
3714 const struct quick_symbol_functions dwarf2_gdb_index_functions =
3717 dw2_find_last_source_symtab,
3718 dw2_forget_cached_source_info,
3719 dw2_map_symtabs_matching_filename,
3721 dw2_pre_expand_symtabs_matching,
3725 dw2_expand_symtabs_for_function,
3726 dw2_expand_all_symtabs,
3727 dw2_expand_symtabs_with_filename,
3728 dw2_find_symbol_file,
3729 dw2_map_matching_symbols,
3730 dw2_expand_symtabs_matching,
3731 dw2_find_pc_sect_symtab,
3732 dw2_map_symbol_filenames
3735 /* Initialize for reading DWARF for this objfile. Return 0 if this
3736 file will use psymtabs, or 1 if using the GNU index. */
3739 dwarf2_initialize_objfile (struct objfile *objfile)
3741 /* If we're about to read full symbols, don't bother with the
3742 indices. In this case we also don't care if some other debug
3743 format is making psymtabs, because they are all about to be
3745 if ((objfile->flags & OBJF_READNOW))
3749 dwarf2_per_objfile->using_index = 1;
3750 create_all_comp_units (objfile);
3751 create_all_type_units (objfile);
3752 dwarf2_per_objfile->quick_file_names_table =
3753 create_quick_file_names_table (dwarf2_per_objfile->n_comp_units);
3755 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3756 + dwarf2_per_objfile->n_type_units); ++i)
3758 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
3760 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
3761 struct dwarf2_per_cu_quick_data);
3764 /* Return 1 so that gdb sees the "quick" functions. However,
3765 these functions will be no-ops because we will have expanded
3770 if (dwarf2_read_index (objfile))
3778 /* Build a partial symbol table. */
3781 dwarf2_build_psymtabs (struct objfile *objfile)
3783 if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
3785 init_psymbol_list (objfile, 1024);
3788 dwarf2_build_psymtabs_hard (objfile);
3791 /* Return the total length of the CU described by HEADER. */
3794 get_cu_length (const struct comp_unit_head *header)
3796 return header->initial_length_size + header->length;
3799 /* Return TRUE if OFFSET is within CU_HEADER. */
3802 offset_in_cu_p (const struct comp_unit_head *cu_header, sect_offset offset)
3804 sect_offset bottom = { cu_header->offset.sect_off };
3805 sect_offset top = { cu_header->offset.sect_off + get_cu_length (cu_header) };
3807 return (offset.sect_off >= bottom.sect_off && offset.sect_off < top.sect_off);
3810 /* Find the base address of the compilation unit for range lists and
3811 location lists. It will normally be specified by DW_AT_low_pc.
3812 In DWARF-3 draft 4, the base address could be overridden by
3813 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3814 compilation units with discontinuous ranges. */
3817 dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
3819 struct attribute *attr;
3822 cu->base_address = 0;
3824 attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
3827 cu->base_address = DW_ADDR (attr);
3832 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
3835 cu->base_address = DW_ADDR (attr);
3841 /* Read in the comp unit header information from the debug_info at info_ptr.
3842 NOTE: This leaves members offset, first_die_offset to be filled in
3846 read_comp_unit_head (struct comp_unit_head *cu_header,
3847 gdb_byte *info_ptr, bfd *abfd)
3850 unsigned int bytes_read;
3852 cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
3853 cu_header->initial_length_size = bytes_read;
3854 cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
3855 info_ptr += bytes_read;
3856 cu_header->version = read_2_bytes (abfd, info_ptr);
3858 cu_header->abbrev_offset.sect_off = read_offset (abfd, info_ptr, cu_header,
3860 info_ptr += bytes_read;
3861 cu_header->addr_size = read_1_byte (abfd, info_ptr);
3863 signed_addr = bfd_get_sign_extend_vma (abfd);
3864 if (signed_addr < 0)
3865 internal_error (__FILE__, __LINE__,
3866 _("read_comp_unit_head: dwarf from non elf file"));
3867 cu_header->signed_addr_p = signed_addr;
3872 /* Helper function that returns the proper abbrev section for
3875 static struct dwarf2_section_info *
3876 get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
3878 struct dwarf2_section_info *abbrev;
3880 if (this_cu->is_dwz)
3881 abbrev = &dwarf2_get_dwz_file ()->abbrev;
3883 abbrev = &dwarf2_per_objfile->abbrev;
3888 /* Subroutine of read_and_check_comp_unit_head and
3889 read_and_check_type_unit_head to simplify them.
3890 Perform various error checking on the header. */
3893 error_check_comp_unit_head (struct comp_unit_head *header,
3894 struct dwarf2_section_info *section,
3895 struct dwarf2_section_info *abbrev_section)
3897 bfd *abfd = section->asection->owner;
3898 const char *filename = bfd_get_filename (abfd);
3900 if (header->version != 2 && header->version != 3 && header->version != 4)
3901 error (_("Dwarf Error: wrong version in compilation unit header "
3902 "(is %d, should be 2, 3, or 4) [in module %s]"), header->version,
3905 if (header->abbrev_offset.sect_off
3906 >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
3907 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
3908 "(offset 0x%lx + 6) [in module %s]"),
3909 (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off,
3912 /* Cast to unsigned long to use 64-bit arithmetic when possible to
3913 avoid potential 32-bit overflow. */
3914 if (((unsigned long) header->offset.sect_off + get_cu_length (header))
3916 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
3917 "(offset 0x%lx + 0) [in module %s]"),
3918 (long) header->length, (long) header->offset.sect_off,
3922 /* Read in a CU/TU header and perform some basic error checking.
3923 The contents of the header are stored in HEADER.
3924 The result is a pointer to the start of the first DIE. */
3927 read_and_check_comp_unit_head (struct comp_unit_head *header,
3928 struct dwarf2_section_info *section,
3929 struct dwarf2_section_info *abbrev_section,
3931 int is_debug_types_section)
3933 gdb_byte *beg_of_comp_unit = info_ptr;
3934 bfd *abfd = section->asection->owner;
3936 header->offset.sect_off = beg_of_comp_unit - section->buffer;
3938 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3940 /* If we're reading a type unit, skip over the signature and
3941 type_offset fields. */
3942 if (is_debug_types_section)
3943 info_ptr += 8 /*signature*/ + header->offset_size;
3945 header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit;
3947 error_check_comp_unit_head (header, section, abbrev_section);
3952 /* Read in the types comp unit header information from .debug_types entry at
3953 types_ptr. The result is a pointer to one past the end of the header. */
3956 read_and_check_type_unit_head (struct comp_unit_head *header,
3957 struct dwarf2_section_info *section,
3958 struct dwarf2_section_info *abbrev_section,
3960 ULONGEST *signature,
3961 cu_offset *type_offset_in_tu)
3963 gdb_byte *beg_of_comp_unit = info_ptr;
3964 bfd *abfd = section->asection->owner;
3966 header->offset.sect_off = beg_of_comp_unit - section->buffer;
3968 info_ptr = read_comp_unit_head (header, info_ptr, abfd);
3970 /* If we're reading a type unit, skip over the signature and
3971 type_offset fields. */
3972 if (signature != NULL)
3973 *signature = read_8_bytes (abfd, info_ptr);
3975 if (type_offset_in_tu != NULL)
3976 type_offset_in_tu->cu_off = read_offset_1 (abfd, info_ptr,
3977 header->offset_size);
3978 info_ptr += header->offset_size;
3980 header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit;
3982 error_check_comp_unit_head (header, section, abbrev_section);
3987 /* Fetch the abbreviation table offset from a comp or type unit header. */
3990 read_abbrev_offset (struct dwarf2_section_info *section,
3993 bfd *abfd = section->asection->owner;
3995 unsigned int length, initial_length_size, offset_size;
3996 sect_offset abbrev_offset;
3998 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
3999 info_ptr = section->buffer + offset.sect_off;
4000 length = read_initial_length (abfd, info_ptr, &initial_length_size);
4001 offset_size = initial_length_size == 4 ? 4 : 8;
4002 info_ptr += initial_length_size + 2 /*version*/;
4003 abbrev_offset.sect_off = read_offset_1 (abfd, info_ptr, offset_size);
4004 return abbrev_offset;
4007 /* Allocate a new partial symtab for file named NAME and mark this new
4008 partial symtab as being an include of PST. */
4011 dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst,
4012 struct objfile *objfile)
4014 struct partial_symtab *subpst = allocate_psymtab (name, objfile);
4016 subpst->section_offsets = pst->section_offsets;
4017 subpst->textlow = 0;
4018 subpst->texthigh = 0;
4020 subpst->dependencies = (struct partial_symtab **)
4021 obstack_alloc (&objfile->objfile_obstack,
4022 sizeof (struct partial_symtab *));
4023 subpst->dependencies[0] = pst;
4024 subpst->number_of_dependencies = 1;
4026 subpst->globals_offset = 0;
4027 subpst->n_global_syms = 0;
4028 subpst->statics_offset = 0;
4029 subpst->n_static_syms = 0;
4030 subpst->symtab = NULL;
4031 subpst->read_symtab = pst->read_symtab;
4034 /* No private part is necessary for include psymtabs. This property
4035 can be used to differentiate between such include psymtabs and
4036 the regular ones. */
4037 subpst->read_symtab_private = NULL;
4040 /* Read the Line Number Program data and extract the list of files
4041 included by the source file represented by PST. Build an include
4042 partial symtab for each of these included files. */
4045 dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
4046 struct die_info *die,
4047 struct partial_symtab *pst)
4049 struct line_header *lh = NULL;
4050 struct attribute *attr;
4052 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
4054 lh = dwarf_decode_line_header (DW_UNSND (attr), cu);
4056 return; /* No linetable, so no includes. */
4058 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
4059 dwarf_decode_lines (lh, pst->dirname, cu, pst, 1);
4061 free_line_header (lh);
4065 hash_signatured_type (const void *item)
4067 const struct signatured_type *sig_type = item;
4069 /* This drops the top 32 bits of the signature, but is ok for a hash. */
4070 return sig_type->signature;
4074 eq_signatured_type (const void *item_lhs, const void *item_rhs)
4076 const struct signatured_type *lhs = item_lhs;
4077 const struct signatured_type *rhs = item_rhs;
4079 return lhs->signature == rhs->signature;
4082 /* Allocate a hash table for signatured types. */
4085 allocate_signatured_type_table (struct objfile *objfile)
4087 return htab_create_alloc_ex (41,
4088 hash_signatured_type,
4091 &objfile->objfile_obstack,
4092 hashtab_obstack_allocate,
4093 dummy_obstack_deallocate);
4096 /* A helper function to add a signatured type CU to a table. */
4099 add_signatured_type_cu_to_table (void **slot, void *datum)
4101 struct signatured_type *sigt = *slot;
4102 struct signatured_type ***datap = datum;
4110 /* Create the hash table of all entries in the .debug_types section.
4111 DWO_FILE is a pointer to the DWO file for .debug_types.dwo,
4113 Note: This function processes DWO files only, not DWP files.
4114 The result is a pointer to the hash table or NULL if there are
4118 create_debug_types_hash_table (struct dwo_file *dwo_file,
4119 VEC (dwarf2_section_info_def) *types)
4121 struct objfile *objfile = dwarf2_per_objfile->objfile;
4122 htab_t types_htab = NULL;
4124 struct dwarf2_section_info *section;
4125 struct dwarf2_section_info *abbrev_section;
4127 if (VEC_empty (dwarf2_section_info_def, types))
4130 abbrev_section = (dwo_file != NULL
4131 ? &dwo_file->sections.abbrev
4132 : &dwarf2_per_objfile->abbrev);
4134 if (dwarf2_read_debug)
4135 fprintf_unfiltered (gdb_stdlog, "Reading .debug_types%s for %s:\n",
4136 dwo_file ? ".dwo" : "",
4137 bfd_get_filename (abbrev_section->asection->owner));
4140 VEC_iterate (dwarf2_section_info_def, types, ix, section);
4144 gdb_byte *info_ptr, *end_ptr;
4145 struct dwarf2_section_info *abbrev_section;
4147 dwarf2_read_section (objfile, section);
4148 info_ptr = section->buffer;
4150 if (info_ptr == NULL)
4153 /* We can't set abfd until now because the section may be empty or
4154 not present, in which case section->asection will be NULL. */
4155 abfd = section->asection->owner;
4158 abbrev_section = &dwo_file->sections.abbrev;
4160 abbrev_section = &dwarf2_per_objfile->abbrev;
4162 if (types_htab == NULL)
4165 types_htab = allocate_dwo_unit_table (objfile);
4167 types_htab = allocate_signatured_type_table (objfile);
4170 /* We don't use init_cutu_and_read_dies_simple, or some such, here
4171 because we don't need to read any dies: the signature is in the
4174 end_ptr = info_ptr + section->size;
4175 while (info_ptr < end_ptr)
4178 cu_offset type_offset_in_tu;
4180 struct signatured_type *sig_type;
4181 struct dwo_unit *dwo_tu;
4183 gdb_byte *ptr = info_ptr;
4184 struct comp_unit_head header;
4185 unsigned int length;
4187 offset.sect_off = ptr - section->buffer;
4189 /* We need to read the type's signature in order to build the hash
4190 table, but we don't need anything else just yet. */
4192 ptr = read_and_check_type_unit_head (&header, section,
4193 abbrev_section, ptr,
4194 &signature, &type_offset_in_tu);
4196 length = get_cu_length (&header);
4198 /* Skip dummy type units. */
4199 if (ptr >= info_ptr + length
4200 || peek_abbrev_code (abfd, ptr) == 0)
4209 dwo_tu = OBSTACK_ZALLOC (&objfile->objfile_obstack,
4211 dwo_tu->dwo_file = dwo_file;
4212 dwo_tu->signature = signature;
4213 dwo_tu->type_offset_in_tu = type_offset_in_tu;
4214 dwo_tu->info_or_types_section = section;
4215 dwo_tu->offset = offset;
4216 dwo_tu->length = length;
4220 /* N.B.: type_offset is not usable if this type uses a DWO file.
4221 The real type_offset is in the DWO file. */
4223 sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
4224 struct signatured_type);
4225 sig_type->signature = signature;
4226 sig_type->type_offset_in_tu = type_offset_in_tu;
4227 sig_type->per_cu.objfile = objfile;
4228 sig_type->per_cu.is_debug_types = 1;
4229 sig_type->per_cu.info_or_types_section = section;
4230 sig_type->per_cu.offset = offset;
4231 sig_type->per_cu.length = length;
4234 slot = htab_find_slot (types_htab,
4235 dwo_file ? (void*) dwo_tu : (void *) sig_type,
4237 gdb_assert (slot != NULL);
4240 sect_offset dup_offset;
4244 const struct dwo_unit *dup_tu = *slot;
4246 dup_offset = dup_tu->offset;
4250 const struct signatured_type *dup_tu = *slot;
4252 dup_offset = dup_tu->per_cu.offset;
4255 complaint (&symfile_complaints,
4256 _("debug type entry at offset 0x%x is duplicate to the "
4257 "entry at offset 0x%x, signature 0x%s"),
4258 offset.sect_off, dup_offset.sect_off,
4259 phex (signature, sizeof (signature)));
4261 *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type;
4263 if (dwarf2_read_debug)
4264 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n",
4266 phex (signature, sizeof (signature)));
4275 /* Create the hash table of all entries in the .debug_types section,
4276 and initialize all_type_units.
4277 The result is zero if there is an error (e.g. missing .debug_types section),
4278 otherwise non-zero. */
4281 create_all_type_units (struct objfile *objfile)
4284 struct signatured_type **iter;
4286 types_htab = create_debug_types_hash_table (NULL, dwarf2_per_objfile->types);
4287 if (types_htab == NULL)
4289 dwarf2_per_objfile->signatured_types = NULL;
4293 dwarf2_per_objfile->signatured_types = types_htab;
4295 dwarf2_per_objfile->n_type_units = htab_elements (types_htab);
4296 dwarf2_per_objfile->all_type_units
4297 = obstack_alloc (&objfile->objfile_obstack,
4298 dwarf2_per_objfile->n_type_units
4299 * sizeof (struct signatured_type *));
4300 iter = &dwarf2_per_objfile->all_type_units[0];
4301 htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter);
4302 gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0]
4303 == dwarf2_per_objfile->n_type_units);
4308 /* Lookup a signature based type for DW_FORM_ref_sig8.
4309 Returns NULL if signature SIG is not present in the table. */
4311 static struct signatured_type *
4312 lookup_signatured_type (ULONGEST sig)
4314 struct signatured_type find_entry, *entry;
4316 if (dwarf2_per_objfile->signatured_types == NULL)
4318 complaint (&symfile_complaints,
4319 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
4323 find_entry.signature = sig;
4324 entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
4328 /* Low level DIE reading support. */
4330 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
4333 init_cu_die_reader (struct die_reader_specs *reader,
4334 struct dwarf2_cu *cu,
4335 struct dwarf2_section_info *section,
4336 struct dwo_file *dwo_file)
4338 gdb_assert (section->readin && section->buffer != NULL);
4339 reader->abfd = section->asection->owner;
4341 reader->dwo_file = dwo_file;
4342 reader->die_section = section;
4343 reader->buffer = section->buffer;
4344 reader->buffer_end = section->buffer + section->size;
4347 /* Initialize a CU (or TU) and read its DIEs.
4348 If the CU defers to a DWO file, read the DWO file as well.
4350 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
4351 Otherwise the table specified in the comp unit header is read in and used.
4352 This is an optimization for when we already have the abbrev table.
4354 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
4355 Otherwise, a new CU is allocated with xmalloc.
4357 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
4358 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
4360 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4361 linker) then DIE_READER_FUNC will not get called. */
4364 init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu,
4365 struct abbrev_table *abbrev_table,
4366 int use_existing_cu, int keep,
4367 die_reader_func_ftype *die_reader_func,
4370 struct objfile *objfile = dwarf2_per_objfile->objfile;
4371 struct dwarf2_section_info *section = this_cu->info_or_types_section;
4372 bfd *abfd = section->asection->owner;
4373 struct dwarf2_cu *cu;
4374 gdb_byte *begin_info_ptr, *info_ptr;
4375 struct die_reader_specs reader;
4376 struct die_info *comp_unit_die;
4378 struct attribute *attr;
4379 struct cleanup *cleanups, *free_cu_cleanup = NULL;
4380 struct signatured_type *sig_type = NULL;
4381 struct dwarf2_section_info *abbrev_section;
4382 /* Non-zero if CU currently points to a DWO file and we need to
4383 reread it. When this happens we need to reread the skeleton die
4384 before we can reread the DWO file. */
4385 int rereading_dwo_cu = 0;
4387 if (dwarf2_die_debug)
4388 fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n",
4389 this_cu->is_debug_types ? "type" : "comp",
4390 this_cu->offset.sect_off);
4392 if (use_existing_cu)
4395 cleanups = make_cleanup (null_cleanup, NULL);
4397 /* This is cheap if the section is already read in. */
4398 dwarf2_read_section (objfile, section);
4400 begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off;
4402 abbrev_section = get_abbrev_section_for_cu (this_cu);
4404 if (use_existing_cu && this_cu->cu != NULL)
4408 /* If this CU is from a DWO file we need to start over, we need to
4409 refetch the attributes from the skeleton CU.
4410 This could be optimized by retrieving those attributes from when we
4411 were here the first time: the previous comp_unit_die was stored in
4412 comp_unit_obstack. But there's no data yet that we need this
4414 if (cu->dwo_unit != NULL)
4415 rereading_dwo_cu = 1;
4419 /* If !use_existing_cu, this_cu->cu must be NULL. */
4420 gdb_assert (this_cu->cu == NULL);
4422 cu = xmalloc (sizeof (*cu));
4423 init_one_comp_unit (cu, this_cu);
4425 /* If an error occurs while loading, release our storage. */
4426 free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
4429 if (cu->header.first_die_offset.cu_off != 0 && ! rereading_dwo_cu)
4431 /* We already have the header, there's no need to read it in again. */
4432 info_ptr += cu->header.first_die_offset.cu_off;
4436 if (this_cu->is_debug_types)
4439 cu_offset type_offset_in_tu;
4441 info_ptr = read_and_check_type_unit_head (&cu->header, section,
4442 abbrev_section, info_ptr,
4444 &type_offset_in_tu);
4446 /* Since per_cu is the first member of struct signatured_type,
4447 we can go from a pointer to one to a pointer to the other. */
4448 sig_type = (struct signatured_type *) this_cu;
4449 gdb_assert (sig_type->signature == signature);
4450 gdb_assert (sig_type->type_offset_in_tu.cu_off
4451 == type_offset_in_tu.cu_off);
4452 gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off);
4454 /* LENGTH has not been set yet for type units if we're
4455 using .gdb_index. */
4456 this_cu->length = get_cu_length (&cu->header);
4458 /* Establish the type offset that can be used to lookup the type. */
4459 sig_type->type_offset_in_section.sect_off =
4460 this_cu->offset.sect_off + sig_type->type_offset_in_tu.cu_off;
4464 info_ptr = read_and_check_comp_unit_head (&cu->header, section,
4468 gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off);
4469 gdb_assert (this_cu->length == get_cu_length (&cu->header));
4473 /* Skip dummy compilation units. */
4474 if (info_ptr >= begin_info_ptr + this_cu->length
4475 || peek_abbrev_code (abfd, info_ptr) == 0)
4477 do_cleanups (cleanups);
4481 /* If we don't have them yet, read the abbrevs for this compilation unit.
4482 And if we need to read them now, make sure they're freed when we're
4483 done. Note that it's important that if the CU had an abbrev table
4484 on entry we don't free it when we're done: Somewhere up the call stack
4485 it may be in use. */
4486 if (abbrev_table != NULL)
4488 gdb_assert (cu->abbrev_table == NULL);
4489 gdb_assert (cu->header.abbrev_offset.sect_off
4490 == abbrev_table->offset.sect_off);
4491 cu->abbrev_table = abbrev_table;
4493 else if (cu->abbrev_table == NULL)
4495 dwarf2_read_abbrevs (cu, abbrev_section);
4496 make_cleanup (dwarf2_free_abbrev_table, cu);
4498 else if (rereading_dwo_cu)
4500 dwarf2_free_abbrev_table (cu);
4501 dwarf2_read_abbrevs (cu, abbrev_section);
4504 /* Read the top level CU/TU die. */
4505 init_cu_die_reader (&reader, cu, section, NULL);
4506 info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children);
4508 /* If we have a DWO stub, process it and then read in the DWO file.
4509 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains
4510 a DWO CU, that this test will fail. */
4511 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu);
4514 char *dwo_name = DW_STRING (attr);
4515 const char *comp_dir_string;
4516 struct dwo_unit *dwo_unit;
4517 ULONGEST signature; /* Or dwo_id. */
4518 struct attribute *comp_dir, *stmt_list, *low_pc, *high_pc, *ranges;
4519 int i,num_extra_attrs;
4520 struct dwarf2_section_info *dwo_abbrev_section;
4523 error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name"
4524 " has children (offset 0x%x) [in module %s]"),
4525 this_cu->offset.sect_off, bfd_get_filename (abfd));
4527 /* These attributes aren't processed until later:
4528 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
4529 However, the attribute is found in the stub which we won't have later.
4530 In order to not impose this complication on the rest of the code,
4531 we read them here and copy them to the DWO CU/TU die. */
4533 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
4536 if (! this_cu->is_debug_types)
4537 stmt_list = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu);
4538 low_pc = dwarf2_attr (comp_unit_die, DW_AT_low_pc, cu);
4539 high_pc = dwarf2_attr (comp_unit_die, DW_AT_high_pc, cu);
4540 ranges = dwarf2_attr (comp_unit_die, DW_AT_ranges, cu);
4541 comp_dir = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu);
4543 /* There should be a DW_AT_addr_base attribute here (if needed).
4544 We need the value before we can process DW_FORM_GNU_addr_index. */
4546 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_addr_base, cu);
4548 cu->addr_base = DW_UNSND (attr);
4550 /* There should be a DW_AT_ranges_base attribute here (if needed).
4551 We need the value before we can process DW_AT_ranges. */
4552 cu->ranges_base = 0;
4553 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_ranges_base, cu);
4555 cu->ranges_base = DW_UNSND (attr);
4557 if (this_cu->is_debug_types)
4559 gdb_assert (sig_type != NULL);
4560 signature = sig_type->signature;
4564 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
4566 error (_("Dwarf Error: missing dwo_id [in module %s]"),
4568 signature = DW_UNSND (attr);
4571 /* We may need the comp_dir in order to find the DWO file. */
4572 comp_dir_string = NULL;
4574 comp_dir_string = DW_STRING (comp_dir);
4576 if (this_cu->is_debug_types)
4577 dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir_string);
4579 dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir_string,
4582 if (dwo_unit == NULL)
4584 error (_("Dwarf Error: CU at offset 0x%x references unknown DWO"
4585 " with ID %s [in module %s]"),
4586 this_cu->offset.sect_off,
4587 phex (signature, sizeof (signature)),
4591 /* Set up for reading the DWO CU/TU. */
4592 cu->dwo_unit = dwo_unit;
4593 section = dwo_unit->info_or_types_section;
4594 dwarf2_read_section (objfile, section);
4595 begin_info_ptr = info_ptr = section->buffer + dwo_unit->offset.sect_off;
4596 dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev;
4597 init_cu_die_reader (&reader, cu, section, dwo_unit->dwo_file);
4599 if (this_cu->is_debug_types)
4602 cu_offset type_offset_in_tu;
4604 info_ptr = read_and_check_type_unit_head (&cu->header, section,
4608 &type_offset_in_tu);
4609 gdb_assert (sig_type->signature == signature);
4610 gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off);
4611 /* For DWOs coming from DWP files, we don't know the CU length
4612 nor the type's offset in the TU until now. */
4613 dwo_unit->length = get_cu_length (&cu->header);
4614 dwo_unit->type_offset_in_tu = type_offset_in_tu;
4616 /* Establish the type offset that can be used to lookup the type.
4617 For DWO files, we don't know it until now. */
4618 sig_type->type_offset_in_section.sect_off =
4619 dwo_unit->offset.sect_off + dwo_unit->type_offset_in_tu.cu_off;
4623 info_ptr = read_and_check_comp_unit_head (&cu->header, section,
4626 gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off);
4627 /* For DWOs coming from DWP files, we don't know the CU length
4629 dwo_unit->length = get_cu_length (&cu->header);
4632 /* Discard the original CU's abbrev table, and read the DWO's. */
4633 if (abbrev_table == NULL)
4635 dwarf2_free_abbrev_table (cu);
4636 dwarf2_read_abbrevs (cu, dwo_abbrev_section);
4640 dwarf2_read_abbrevs (cu, dwo_abbrev_section);
4641 make_cleanup (dwarf2_free_abbrev_table, cu);
4644 /* Read in the die, but leave space to copy over the attributes
4645 from the stub. This has the benefit of simplifying the rest of
4646 the code - all the real work is done here. */
4647 num_extra_attrs = ((stmt_list != NULL)
4651 + (comp_dir != NULL));
4652 info_ptr = read_full_die_1 (&reader, &comp_unit_die, info_ptr,
4653 &has_children, num_extra_attrs);
4655 /* Copy over the attributes from the stub to the DWO die. */
4656 i = comp_unit_die->num_attrs;
4657 if (stmt_list != NULL)
4658 comp_unit_die->attrs[i++] = *stmt_list;
4660 comp_unit_die->attrs[i++] = *low_pc;
4661 if (high_pc != NULL)
4662 comp_unit_die->attrs[i++] = *high_pc;
4664 comp_unit_die->attrs[i++] = *ranges;
4665 if (comp_dir != NULL)
4666 comp_unit_die->attrs[i++] = *comp_dir;
4667 comp_unit_die->num_attrs += num_extra_attrs;
4669 /* Skip dummy compilation units. */
4670 if (info_ptr >= begin_info_ptr + dwo_unit->length
4671 || peek_abbrev_code (abfd, info_ptr) == 0)
4673 do_cleanups (cleanups);
4678 die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data);
4680 if (free_cu_cleanup != NULL)
4684 /* We've successfully allocated this compilation unit. Let our
4685 caller clean it up when finished with it. */
4686 discard_cleanups (free_cu_cleanup);
4688 /* We can only discard free_cu_cleanup and all subsequent cleanups.
4689 So we have to manually free the abbrev table. */
4690 dwarf2_free_abbrev_table (cu);
4692 /* Link this CU into read_in_chain. */
4693 this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
4694 dwarf2_per_objfile->read_in_chain = this_cu;
4697 do_cleanups (free_cu_cleanup);
4700 do_cleanups (cleanups);
4703 /* Read CU/TU THIS_CU in section SECTION,
4704 but do not follow DW_AT_GNU_dwo_name if present.
4705 DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed
4706 to have already done the lookup to find the DWO/DWP file).
4708 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
4709 THIS_CU->is_debug_types, but nothing else.
4711 We fill in THIS_CU->length.
4713 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
4714 linker) then DIE_READER_FUNC will not get called.
4716 THIS_CU->cu is always freed when done.
4717 This is done in order to not leave THIS_CU->cu in a state where we have
4718 to care whether it refers to the "main" CU or the DWO CU. */
4721 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu,
4722 struct dwarf2_section_info *abbrev_section,
4723 struct dwo_file *dwo_file,
4724 die_reader_func_ftype *die_reader_func,
4727 struct objfile *objfile = dwarf2_per_objfile->objfile;
4728 struct dwarf2_section_info *section = this_cu->info_or_types_section;
4729 bfd *abfd = section->asection->owner;
4730 struct dwarf2_cu cu;
4731 gdb_byte *begin_info_ptr, *info_ptr;
4732 struct die_reader_specs reader;
4733 struct cleanup *cleanups;
4734 struct die_info *comp_unit_die;
4737 if (dwarf2_die_debug)
4738 fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n",
4739 this_cu->is_debug_types ? "type" : "comp",
4740 this_cu->offset.sect_off);
4742 gdb_assert (this_cu->cu == NULL);
4744 /* This is cheap if the section is already read in. */
4745 dwarf2_read_section (objfile, section);
4747 init_one_comp_unit (&cu, this_cu);
4749 cleanups = make_cleanup (free_stack_comp_unit, &cu);
4751 begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off;
4752 info_ptr = read_and_check_comp_unit_head (&cu.header, section,
4753 abbrev_section, info_ptr,
4754 this_cu->is_debug_types);
4756 this_cu->length = get_cu_length (&cu.header);
4758 /* Skip dummy compilation units. */
4759 if (info_ptr >= begin_info_ptr + this_cu->length
4760 || peek_abbrev_code (abfd, info_ptr) == 0)
4762 do_cleanups (cleanups);
4766 dwarf2_read_abbrevs (&cu, abbrev_section);
4767 make_cleanup (dwarf2_free_abbrev_table, &cu);
4769 init_cu_die_reader (&reader, &cu, section, dwo_file);
4770 info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children);
4772 die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data);
4774 do_cleanups (cleanups);
4777 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
4778 does not lookup the specified DWO file.
4779 This cannot be used to read DWO files.
4781 THIS_CU->cu is always freed when done.
4782 This is done in order to not leave THIS_CU->cu in a state where we have
4783 to care whether it refers to the "main" CU or the DWO CU.
4784 We can revisit this if the data shows there's a performance issue. */
4787 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu,
4788 die_reader_func_ftype *die_reader_func,
4791 init_cutu_and_read_dies_no_follow (this_cu,
4792 get_abbrev_section_for_cu (this_cu),
4794 die_reader_func, data);
4797 /* Create a psymtab named NAME and assign it to PER_CU.
4799 The caller must fill in the following details:
4800 dirname, textlow, texthigh. */
4802 static struct partial_symtab *
4803 create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name)
4805 struct objfile *objfile = per_cu->objfile;
4806 struct partial_symtab *pst;
4808 pst = start_psymtab_common (objfile, objfile->section_offsets,
4810 objfile->global_psymbols.next,
4811 objfile->static_psymbols.next);
4813 pst->psymtabs_addrmap_supported = 1;
4815 /* This is the glue that links PST into GDB's symbol API. */
4816 pst->read_symtab_private = per_cu;
4817 pst->read_symtab = dwarf2_psymtab_to_symtab;
4818 per_cu->v.psymtab = pst;
4823 /* die_reader_func for process_psymtab_comp_unit. */
4826 process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
4828 struct die_info *comp_unit_die,
4832 struct dwarf2_cu *cu = reader->cu;
4833 struct objfile *objfile = cu->objfile;
4834 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
4835 struct attribute *attr;
4837 CORE_ADDR best_lowpc = 0, best_highpc = 0;
4838 struct partial_symtab *pst;
4840 const char *filename;
4841 int *want_partial_unit_ptr = data;
4843 if (comp_unit_die->tag == DW_TAG_partial_unit
4844 && (want_partial_unit_ptr == NULL
4845 || !*want_partial_unit_ptr))
4848 gdb_assert (! per_cu->is_debug_types);
4850 prepare_one_comp_unit (cu, comp_unit_die, language_minimal);
4852 cu->list_in_scope = &file_symbols;
4854 /* Allocate a new partial symbol table structure. */
4855 attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu);
4856 if (attr == NULL || !DW_STRING (attr))
4859 filename = DW_STRING (attr);
4861 pst = create_partial_symtab (per_cu, filename);
4863 /* This must be done before calling dwarf2_build_include_psymtabs. */
4864 attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu);
4866 pst->dirname = DW_STRING (attr);
4868 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
4870 dwarf2_find_base_address (comp_unit_die, cu);
4872 /* Possibly set the default values of LOWPC and HIGHPC from
4874 has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
4875 &best_highpc, cu, pst);
4876 if (has_pc_info == 1 && best_lowpc < best_highpc)
4877 /* Store the contiguous range if it is not empty; it can be empty for
4878 CUs with no code. */
4879 addrmap_set_empty (objfile->psymtabs_addrmap,
4880 best_lowpc + baseaddr,
4881 best_highpc + baseaddr - 1, pst);
4883 /* Check if comp unit has_children.
4884 If so, read the rest of the partial symbols from this comp unit.
4885 If not, there's no more debug_info for this comp unit. */
4888 struct partial_die_info *first_die;
4889 CORE_ADDR lowpc, highpc;
4891 lowpc = ((CORE_ADDR) -1);
4892 highpc = ((CORE_ADDR) 0);
4894 first_die = load_partial_dies (reader, info_ptr, 1);
4896 scan_partial_symbols (first_die, &lowpc, &highpc,
4899 /* If we didn't find a lowpc, set it to highpc to avoid
4900 complaints from `maint check'. */
4901 if (lowpc == ((CORE_ADDR) -1))
4904 /* If the compilation unit didn't have an explicit address range,
4905 then use the information extracted from its child dies. */
4909 best_highpc = highpc;
4912 pst->textlow = best_lowpc + baseaddr;
4913 pst->texthigh = best_highpc + baseaddr;
4915 pst->n_global_syms = objfile->global_psymbols.next -
4916 (objfile->global_psymbols.list + pst->globals_offset);
4917 pst->n_static_syms = objfile->static_psymbols.next -
4918 (objfile->static_psymbols.list + pst->statics_offset);
4919 sort_pst_symbols (pst);
4921 if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs))
4924 int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs);
4925 struct dwarf2_per_cu_data *iter;
4927 /* Fill in 'dependencies' here; we fill in 'users' in a
4929 pst->number_of_dependencies = len;
4930 pst->dependencies = obstack_alloc (&objfile->objfile_obstack,
4931 len * sizeof (struct symtab *));
4933 VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs,
4936 pst->dependencies[i] = iter->v.psymtab;
4938 VEC_free (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs);
4941 /* Get the list of files included in the current compilation unit,
4942 and build a psymtab for each of them. */
4943 dwarf2_build_include_psymtabs (cu, comp_unit_die, pst);
4945 if (dwarf2_read_debug)
4947 struct gdbarch *gdbarch = get_objfile_arch (objfile);
4949 fprintf_unfiltered (gdb_stdlog,
4950 "Psymtab for %s unit @0x%x: %s - %s"
4951 ", %d global, %d static syms\n",
4952 per_cu->is_debug_types ? "type" : "comp",
4953 per_cu->offset.sect_off,
4954 paddress (gdbarch, pst->textlow),
4955 paddress (gdbarch, pst->texthigh),
4956 pst->n_global_syms, pst->n_static_syms);
4960 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
4961 Process compilation unit THIS_CU for a psymtab. */
4964 process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
4965 int want_partial_unit)
4967 /* If this compilation unit was already read in, free the
4968 cached copy in order to read it in again. This is
4969 necessary because we skipped some symbols when we first
4970 read in the compilation unit (see load_partial_dies).
4971 This problem could be avoided, but the benefit is unclear. */
4972 if (this_cu->cu != NULL)
4973 free_one_cached_comp_unit (this_cu);
4975 gdb_assert (! this_cu->is_debug_types);
4976 init_cutu_and_read_dies (this_cu, NULL, 0, 0,
4977 process_psymtab_comp_unit_reader,
4978 &want_partial_unit);
4980 /* Age out any secondary CUs. */
4981 age_cached_comp_units ();
4985 hash_type_unit_group (const void *item)
4987 const struct type_unit_group *tu_group = item;
4989 return hash_stmt_list_entry (&tu_group->hash);
4993 eq_type_unit_group (const void *item_lhs, const void *item_rhs)
4995 const struct type_unit_group *lhs = item_lhs;
4996 const struct type_unit_group *rhs = item_rhs;
4998 return eq_stmt_list_entry (&lhs->hash, &rhs->hash);
5001 /* Allocate a hash table for type unit groups. */
5004 allocate_type_unit_groups_table (void)
5006 return htab_create_alloc_ex (3,
5007 hash_type_unit_group,
5010 &dwarf2_per_objfile->objfile->objfile_obstack,
5011 hashtab_obstack_allocate,
5012 dummy_obstack_deallocate);
5015 /* Type units that don't have DW_AT_stmt_list are grouped into their own
5016 partial symtabs. We combine several TUs per psymtab to not let the size
5017 of any one psymtab grow too big. */
5018 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
5019 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
5021 /* Helper routine for get_type_unit_group.
5022 Create the type_unit_group object used to hold one or more TUs. */
5024 static struct type_unit_group *
5025 create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
5027 struct objfile *objfile = dwarf2_per_objfile->objfile;
5028 struct dwarf2_per_cu_data *per_cu;
5029 struct type_unit_group *tu_group;
5031 tu_group = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5032 struct type_unit_group);
5033 per_cu = &tu_group->per_cu;
5034 per_cu->objfile = objfile;
5035 per_cu->is_debug_types = 1;
5036 per_cu->s.type_unit_group = tu_group;
5038 if (dwarf2_per_objfile->using_index)
5040 per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack,
5041 struct dwarf2_per_cu_quick_data);
5042 tu_group->t.first_tu = cu->per_cu;
5046 unsigned int line_offset = line_offset_struct.sect_off;
5047 struct partial_symtab *pst;
5050 /* Give the symtab a useful name for debug purposes. */
5051 if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0)
5052 name = xstrprintf ("<type_units_%d>",
5053 (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB));
5055 name = xstrprintf ("<type_units_at_0x%x>", line_offset);
5057 pst = create_partial_symtab (per_cu, name);
5063 tu_group->hash.dwo_unit = cu->dwo_unit;
5064 tu_group->hash.line_offset = line_offset_struct;
5069 /* Look up the type_unit_group for type unit CU, and create it if necessary.
5070 STMT_LIST is a DW_AT_stmt_list attribute. */
5072 static struct type_unit_group *
5073 get_type_unit_group (struct dwarf2_cu *cu, struct attribute *stmt_list)
5075 struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
5076 struct type_unit_group *tu_group;
5078 unsigned int line_offset;
5079 struct type_unit_group type_unit_group_for_lookup;
5081 if (dwarf2_per_objfile->type_unit_groups == NULL)
5083 dwarf2_per_objfile->type_unit_groups =
5084 allocate_type_unit_groups_table ();
5087 /* Do we need to create a new group, or can we use an existing one? */
5091 line_offset = DW_UNSND (stmt_list);
5092 ++tu_stats->nr_symtab_sharers;
5096 /* Ugh, no stmt_list. Rare, but we have to handle it.
5097 We can do various things here like create one group per TU or
5098 spread them over multiple groups to split up the expansion work.
5099 To avoid worst case scenarios (too many groups or too large groups)
5100 we, umm, group them in bunches. */
5101 line_offset = (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
5102 | (tu_stats->nr_stmt_less_type_units
5103 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE));
5104 ++tu_stats->nr_stmt_less_type_units;
5107 type_unit_group_for_lookup.hash.dwo_unit = cu->dwo_unit;
5108 type_unit_group_for_lookup.hash.line_offset.sect_off = line_offset;
5109 slot = htab_find_slot (dwarf2_per_objfile->type_unit_groups,
5110 &type_unit_group_for_lookup, INSERT);
5114 gdb_assert (tu_group != NULL);
5118 sect_offset line_offset_struct;
5120 line_offset_struct.sect_off = line_offset;
5121 tu_group = create_type_unit_group (cu, line_offset_struct);
5123 ++tu_stats->nr_symtabs;
5129 /* Struct used to sort TUs by their abbreviation table offset. */
5131 struct tu_abbrev_offset
5133 struct signatured_type *sig_type;
5134 sect_offset abbrev_offset;
5137 /* Helper routine for build_type_unit_groups, passed to qsort. */
5140 sort_tu_by_abbrev_offset (const void *ap, const void *bp)
5142 const struct tu_abbrev_offset * const *a = ap;
5143 const struct tu_abbrev_offset * const *b = bp;
5144 unsigned int aoff = (*a)->abbrev_offset.sect_off;
5145 unsigned int boff = (*b)->abbrev_offset.sect_off;
5147 return (aoff > boff) - (aoff < boff);
5150 /* A helper function to add a type_unit_group to a table. */
5153 add_type_unit_group_to_table (void **slot, void *datum)
5155 struct type_unit_group *tu_group = *slot;
5156 struct type_unit_group ***datap = datum;
5164 /* Efficiently read all the type units, calling init_cutu_and_read_dies on
5165 each one passing FUNC,DATA.
5167 The efficiency is because we sort TUs by the abbrev table they use and
5168 only read each abbrev table once. In one program there are 200K TUs
5169 sharing 8K abbrev tables.
5171 The main purpose of this function is to support building the
5172 dwarf2_per_objfile->type_unit_groups table.
5173 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
5174 can collapse the search space by grouping them by stmt_list.
5175 The savings can be significant, in the same program from above the 200K TUs
5176 share 8K stmt_list tables.
5178 FUNC is expected to call get_type_unit_group, which will create the
5179 struct type_unit_group if necessary and add it to
5180 dwarf2_per_objfile->type_unit_groups. */
5183 build_type_unit_groups (die_reader_func_ftype *func, void *data)
5185 struct objfile *objfile = dwarf2_per_objfile->objfile;
5186 struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
5187 struct cleanup *cleanups;
5188 struct abbrev_table *abbrev_table;
5189 sect_offset abbrev_offset;
5190 struct tu_abbrev_offset *sorted_by_abbrev;
5191 struct type_unit_group **iter;
5194 /* It's up to the caller to not call us multiple times. */
5195 gdb_assert (dwarf2_per_objfile->type_unit_groups == NULL);
5197 if (dwarf2_per_objfile->n_type_units == 0)
5200 /* TUs typically share abbrev tables, and there can be way more TUs than
5201 abbrev tables. Sort by abbrev table to reduce the number of times we
5202 read each abbrev table in.
5203 Alternatives are to punt or to maintain a cache of abbrev tables.
5204 This is simpler and efficient enough for now.
5206 Later we group TUs by their DW_AT_stmt_list value (as this defines the
5207 symtab to use). Typically TUs with the same abbrev offset have the same
5208 stmt_list value too so in practice this should work well.
5210 The basic algorithm here is:
5212 sort TUs by abbrev table
5213 for each TU with same abbrev table:
5214 read abbrev table if first user
5215 read TU top level DIE
5216 [IWBN if DWO skeletons had DW_AT_stmt_list]
5219 if (dwarf2_read_debug)
5220 fprintf_unfiltered (gdb_stdlog, "Building type unit groups ...\n");
5222 /* Sort in a separate table to maintain the order of all_type_units
5223 for .gdb_index: TU indices directly index all_type_units. */
5224 sorted_by_abbrev = XNEWVEC (struct tu_abbrev_offset,
5225 dwarf2_per_objfile->n_type_units);
5226 for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
5228 struct signatured_type *sig_type = dwarf2_per_objfile->all_type_units[i];
5230 sorted_by_abbrev[i].sig_type = sig_type;
5231 sorted_by_abbrev[i].abbrev_offset =
5232 read_abbrev_offset (sig_type->per_cu.info_or_types_section,
5233 sig_type->per_cu.offset);
5235 cleanups = make_cleanup (xfree, sorted_by_abbrev);
5236 qsort (sorted_by_abbrev, dwarf2_per_objfile->n_type_units,
5237 sizeof (struct tu_abbrev_offset), sort_tu_by_abbrev_offset);
5239 /* Note: In the .gdb_index case, get_type_unit_group may have already been
5240 called any number of times, so we don't reset tu_stats here. */
5242 abbrev_offset.sect_off = ~(unsigned) 0;
5243 abbrev_table = NULL;
5244 make_cleanup (abbrev_table_free_cleanup, &abbrev_table);
5246 for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
5248 const struct tu_abbrev_offset *tu = &sorted_by_abbrev[i];
5250 /* Switch to the next abbrev table if necessary. */
5251 if (abbrev_table == NULL
5252 || tu->abbrev_offset.sect_off != abbrev_offset.sect_off)
5254 if (abbrev_table != NULL)
5256 abbrev_table_free (abbrev_table);
5257 /* Reset to NULL in case abbrev_table_read_table throws
5258 an error: abbrev_table_free_cleanup will get called. */
5259 abbrev_table = NULL;
5261 abbrev_offset = tu->abbrev_offset;
5263 abbrev_table_read_table (&dwarf2_per_objfile->abbrev,
5265 ++tu_stats->nr_uniq_abbrev_tables;
5268 init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table, 0, 0,
5272 /* Create a vector of pointers to primary type units to make it easy to
5273 iterate over them and CUs. See dw2_get_primary_cu. */
5274 dwarf2_per_objfile->n_type_unit_groups =
5275 htab_elements (dwarf2_per_objfile->type_unit_groups);
5276 dwarf2_per_objfile->all_type_unit_groups =
5277 obstack_alloc (&objfile->objfile_obstack,
5278 dwarf2_per_objfile->n_type_unit_groups
5279 * sizeof (struct type_unit_group *));
5280 iter = &dwarf2_per_objfile->all_type_unit_groups[0];
5281 htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups,
5282 add_type_unit_group_to_table, &iter);
5283 gdb_assert (iter - &dwarf2_per_objfile->all_type_unit_groups[0]
5284 == dwarf2_per_objfile->n_type_unit_groups);
5286 do_cleanups (cleanups);
5288 if (dwarf2_read_debug)
5290 fprintf_unfiltered (gdb_stdlog, "Done building type unit groups:\n");
5291 fprintf_unfiltered (gdb_stdlog, " %d TUs\n",
5292 dwarf2_per_objfile->n_type_units);
5293 fprintf_unfiltered (gdb_stdlog, " %d uniq abbrev tables\n",
5294 tu_stats->nr_uniq_abbrev_tables);
5295 fprintf_unfiltered (gdb_stdlog, " %d symtabs from stmt_list entries\n",
5296 tu_stats->nr_symtabs);
5297 fprintf_unfiltered (gdb_stdlog, " %d symtab sharers\n",
5298 tu_stats->nr_symtab_sharers);
5299 fprintf_unfiltered (gdb_stdlog, " %d type units without a stmt_list\n",
5300 tu_stats->nr_stmt_less_type_units);
5304 /* Reader function for build_type_psymtabs. */
5307 build_type_psymtabs_reader (const struct die_reader_specs *reader,
5309 struct die_info *type_unit_die,
5313 struct objfile *objfile = dwarf2_per_objfile->objfile;
5314 struct dwarf2_cu *cu = reader->cu;
5315 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
5316 struct type_unit_group *tu_group;
5317 struct attribute *attr;
5318 struct partial_die_info *first_die;
5319 CORE_ADDR lowpc, highpc;
5320 struct partial_symtab *pst;
5322 gdb_assert (data == NULL);
5327 attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
5328 tu_group = get_type_unit_group (cu, attr);
5330 VEC_safe_push (dwarf2_per_cu_ptr, tu_group->t.tus, per_cu);
5332 prepare_one_comp_unit (cu, type_unit_die, language_minimal);
5333 cu->list_in_scope = &file_symbols;
5334 pst = create_partial_symtab (per_cu, "");
5337 first_die = load_partial_dies (reader, info_ptr, 1);
5339 lowpc = (CORE_ADDR) -1;
5340 highpc = (CORE_ADDR) 0;
5341 scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu);
5343 pst->n_global_syms = objfile->global_psymbols.next -
5344 (objfile->global_psymbols.list + pst->globals_offset);
5345 pst->n_static_syms = objfile->static_psymbols.next -
5346 (objfile->static_psymbols.list + pst->statics_offset);
5347 sort_pst_symbols (pst);
5350 /* Traversal function for build_type_psymtabs. */
5353 build_type_psymtab_dependencies (void **slot, void *info)
5355 struct objfile *objfile = dwarf2_per_objfile->objfile;
5356 struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
5357 struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
5358 struct partial_symtab *pst = per_cu->v.psymtab;
5359 int len = VEC_length (dwarf2_per_cu_ptr, tu_group->t.tus);
5360 struct dwarf2_per_cu_data *iter;
5363 gdb_assert (len > 0);
5365 pst->number_of_dependencies = len;
5366 pst->dependencies = obstack_alloc (&objfile->objfile_obstack,
5367 len * sizeof (struct psymtab *));
5369 VEC_iterate (dwarf2_per_cu_ptr, tu_group->t.tus, i, iter);
5372 pst->dependencies[i] = iter->v.psymtab;
5373 iter->s.type_unit_group = tu_group;
5376 VEC_free (dwarf2_per_cu_ptr, tu_group->t.tus);
5381 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
5382 Build partial symbol tables for the .debug_types comp-units. */
5385 build_type_psymtabs (struct objfile *objfile)
5387 if (! create_all_type_units (objfile))
5390 build_type_unit_groups (build_type_psymtabs_reader, NULL);
5392 /* Now that all TUs have been processed we can fill in the dependencies. */
5393 htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups,
5394 build_type_psymtab_dependencies, NULL);
5397 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
5400 psymtabs_addrmap_cleanup (void *o)
5402 struct objfile *objfile = o;
5404 objfile->psymtabs_addrmap = NULL;
5407 /* Compute the 'user' field for each psymtab in OBJFILE. */
5410 set_partial_user (struct objfile *objfile)
5414 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
5416 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
5417 struct partial_symtab *pst = per_cu->v.psymtab;
5423 for (j = 0; j < pst->number_of_dependencies; ++j)
5425 /* Set the 'user' field only if it is not already set. */
5426 if (pst->dependencies[j]->user == NULL)
5427 pst->dependencies[j]->user = pst;
5432 /* Build the partial symbol table by doing a quick pass through the
5433 .debug_info and .debug_abbrev sections. */
5436 dwarf2_build_psymtabs_hard (struct objfile *objfile)
5438 struct cleanup *back_to, *addrmap_cleanup;
5439 struct obstack temp_obstack;
5442 if (dwarf2_read_debug)
5444 fprintf_unfiltered (gdb_stdlog, "Building psymtabs of objfile %s ...\n",
5448 dwarf2_per_objfile->reading_partial_symbols = 1;
5450 dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
5452 /* Any cached compilation units will be linked by the per-objfile
5453 read_in_chain. Make sure to free them when we're done. */
5454 back_to = make_cleanup (free_cached_comp_units, NULL);
5456 build_type_psymtabs (objfile);
5458 create_all_comp_units (objfile);
5460 /* Create a temporary address map on a temporary obstack. We later
5461 copy this to the final obstack. */
5462 obstack_init (&temp_obstack);
5463 make_cleanup_obstack_free (&temp_obstack);
5464 objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack);
5465 addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile);
5467 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
5469 struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
5471 process_psymtab_comp_unit (per_cu, 0);
5474 set_partial_user (objfile);
5476 objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap,
5477 &objfile->objfile_obstack);
5478 discard_cleanups (addrmap_cleanup);
5480 do_cleanups (back_to);
5482 if (dwarf2_read_debug)
5483 fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n",
5487 /* die_reader_func for load_partial_comp_unit. */
5490 load_partial_comp_unit_reader (const struct die_reader_specs *reader,
5492 struct die_info *comp_unit_die,
5496 struct dwarf2_cu *cu = reader->cu;
5498 prepare_one_comp_unit (cu, comp_unit_die, language_minimal);
5500 /* Check if comp unit has_children.
5501 If so, read the rest of the partial symbols from this comp unit.
5502 If not, there's no more debug_info for this comp unit. */
5504 load_partial_dies (reader, info_ptr, 0);
5507 /* Load the partial DIEs for a secondary CU into memory.
5508 This is also used when rereading a primary CU with load_all_dies. */
5511 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
5513 init_cutu_and_read_dies (this_cu, NULL, 1, 1,
5514 load_partial_comp_unit_reader, NULL);
5518 read_comp_units_from_section (struct objfile *objfile,
5519 struct dwarf2_section_info *section,
5520 unsigned int is_dwz,
5523 struct dwarf2_per_cu_data ***all_comp_units)
5526 bfd *abfd = section->asection->owner;
5528 dwarf2_read_section (objfile, section);
5530 info_ptr = section->buffer;
5532 while (info_ptr < section->buffer + section->size)
5534 unsigned int length, initial_length_size;
5535 struct dwarf2_per_cu_data *this_cu;
5538 offset.sect_off = info_ptr - section->buffer;
5540 /* Read just enough information to find out where the next
5541 compilation unit is. */
5542 length = read_initial_length (abfd, info_ptr, &initial_length_size);
5544 /* Save the compilation unit for later lookup. */
5545 this_cu = obstack_alloc (&objfile->objfile_obstack,
5546 sizeof (struct dwarf2_per_cu_data));
5547 memset (this_cu, 0, sizeof (*this_cu));
5548 this_cu->offset = offset;
5549 this_cu->length = length + initial_length_size;
5550 this_cu->is_dwz = is_dwz;
5551 this_cu->objfile = objfile;
5552 this_cu->info_or_types_section = section;
5554 if (*n_comp_units == *n_allocated)
5557 *all_comp_units = xrealloc (*all_comp_units,
5559 * sizeof (struct dwarf2_per_cu_data *));
5561 (*all_comp_units)[*n_comp_units] = this_cu;
5564 info_ptr = info_ptr + this_cu->length;
5568 /* Create a list of all compilation units in OBJFILE.
5569 This is only done for -readnow and building partial symtabs. */
5572 create_all_comp_units (struct objfile *objfile)
5576 struct dwarf2_per_cu_data **all_comp_units;
5580 all_comp_units = xmalloc (n_allocated
5581 * sizeof (struct dwarf2_per_cu_data *));
5583 read_comp_units_from_section (objfile, &dwarf2_per_objfile->info, 0,
5584 &n_allocated, &n_comp_units, &all_comp_units);
5586 if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL)
5588 struct dwz_file *dwz = dwarf2_get_dwz_file ();
5590 read_comp_units_from_section (objfile, &dwz->info, 1,
5591 &n_allocated, &n_comp_units,
5595 dwarf2_per_objfile->all_comp_units
5596 = obstack_alloc (&objfile->objfile_obstack,
5597 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
5598 memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units,
5599 n_comp_units * sizeof (struct dwarf2_per_cu_data *));
5600 xfree (all_comp_units);
5601 dwarf2_per_objfile->n_comp_units = n_comp_units;
5604 /* Process all loaded DIEs for compilation unit CU, starting at
5605 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
5606 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
5607 DW_AT_ranges). If NEED_PC is set, then this function will set
5608 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
5609 and record the covered ranges in the addrmap. */
5612 scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
5613 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
5615 struct partial_die_info *pdi;
5617 /* Now, march along the PDI's, descending into ones which have
5618 interesting children but skipping the children of the other ones,
5619 until we reach the end of the compilation unit. */
5625 fixup_partial_die (pdi, cu);
5627 /* Anonymous namespaces or modules have no name but have interesting
5628 children, so we need to look at them. Ditto for anonymous
5631 if (pdi->name != NULL || pdi->tag == DW_TAG_namespace
5632 || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type
5633 || pdi->tag == DW_TAG_imported_unit)
5637 case DW_TAG_subprogram:
5638 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
5640 case DW_TAG_constant:
5641 case DW_TAG_variable:
5642 case DW_TAG_typedef:
5643 case DW_TAG_union_type:
5644 if (!pdi->is_declaration)
5646 add_partial_symbol (pdi, cu);
5649 case DW_TAG_class_type:
5650 case DW_TAG_interface_type:
5651 case DW_TAG_structure_type:
5652 if (!pdi->is_declaration)
5654 add_partial_symbol (pdi, cu);
5657 case DW_TAG_enumeration_type:
5658 if (!pdi->is_declaration)
5659 add_partial_enumeration (pdi, cu);
5661 case DW_TAG_base_type:
5662 case DW_TAG_subrange_type:
5663 /* File scope base type definitions are added to the partial
5665 add_partial_symbol (pdi, cu);
5667 case DW_TAG_namespace:
5668 add_partial_namespace (pdi, lowpc, highpc, need_pc, cu);
5671 add_partial_module (pdi, lowpc, highpc, need_pc, cu);
5673 case DW_TAG_imported_unit:
5675 struct dwarf2_per_cu_data *per_cu;
5677 /* For now we don't handle imported units in type units. */
5678 if (cu->per_cu->is_debug_types)
5680 error (_("Dwarf Error: DW_TAG_imported_unit is not"
5681 " supported in type units [in module %s]"),
5685 per_cu = dwarf2_find_containing_comp_unit (pdi->d.offset,
5689 /* Go read the partial unit, if needed. */
5690 if (per_cu->v.psymtab == NULL)
5691 process_psymtab_comp_unit (per_cu, 1);
5693 VEC_safe_push (dwarf2_per_cu_ptr,
5694 cu->per_cu->s.imported_symtabs, per_cu);
5702 /* If the die has a sibling, skip to the sibling. */
5704 pdi = pdi->die_sibling;
5708 /* Functions used to compute the fully scoped name of a partial DIE.
5710 Normally, this is simple. For C++, the parent DIE's fully scoped
5711 name is concatenated with "::" and the partial DIE's name. For
5712 Java, the same thing occurs except that "." is used instead of "::".
5713 Enumerators are an exception; they use the scope of their parent
5714 enumeration type, i.e. the name of the enumeration type is not
5715 prepended to the enumerator.
5717 There are two complexities. One is DW_AT_specification; in this
5718 case "parent" means the parent of the target of the specification,
5719 instead of the direct parent of the DIE. The other is compilers
5720 which do not emit DW_TAG_namespace; in this case we try to guess
5721 the fully qualified name of structure types from their members'
5722 linkage names. This must be done using the DIE's children rather
5723 than the children of any DW_AT_specification target. We only need
5724 to do this for structures at the top level, i.e. if the target of
5725 any DW_AT_specification (if any; otherwise the DIE itself) does not
5728 /* Compute the scope prefix associated with PDI's parent, in
5729 compilation unit CU. The result will be allocated on CU's
5730 comp_unit_obstack, or a copy of the already allocated PDI->NAME
5731 field. NULL is returned if no prefix is necessary. */
5733 partial_die_parent_scope (struct partial_die_info *pdi,
5734 struct dwarf2_cu *cu)
5736 char *grandparent_scope;
5737 struct partial_die_info *parent, *real_pdi;
5739 /* We need to look at our parent DIE; if we have a DW_AT_specification,
5740 then this means the parent of the specification DIE. */
5743 while (real_pdi->has_specification)
5744 real_pdi = find_partial_die (real_pdi->spec_offset,
5745 real_pdi->spec_is_dwz, cu);
5747 parent = real_pdi->die_parent;
5751 if (parent->scope_set)
5752 return parent->scope;
5754 fixup_partial_die (parent, cu);
5756 grandparent_scope = partial_die_parent_scope (parent, cu);
5758 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
5759 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
5760 Work around this problem here. */
5761 if (cu->language == language_cplus
5762 && parent->tag == DW_TAG_namespace
5763 && strcmp (parent->name, "::") == 0
5764 && grandparent_scope == NULL)
5766 parent->scope = NULL;
5767 parent->scope_set = 1;
5771 if (pdi->tag == DW_TAG_enumerator)
5772 /* Enumerators should not get the name of the enumeration as a prefix. */
5773 parent->scope = grandparent_scope;
5774 else if (parent->tag == DW_TAG_namespace
5775 || parent->tag == DW_TAG_module
5776 || parent->tag == DW_TAG_structure_type
5777 || parent->tag == DW_TAG_class_type
5778 || parent->tag == DW_TAG_interface_type
5779 || parent->tag == DW_TAG_union_type
5780 || parent->tag == DW_TAG_enumeration_type)
5782 if (grandparent_scope == NULL)
5783 parent->scope = parent->name;
5785 parent->scope = typename_concat (&cu->comp_unit_obstack,
5787 parent->name, 0, cu);
5791 /* FIXME drow/2004-04-01: What should we be doing with
5792 function-local names? For partial symbols, we should probably be
5794 complaint (&symfile_complaints,
5795 _("unhandled containing DIE tag %d for DIE at %d"),
5796 parent->tag, pdi->offset.sect_off);
5797 parent->scope = grandparent_scope;
5800 parent->scope_set = 1;
5801 return parent->scope;
5804 /* Return the fully scoped name associated with PDI, from compilation unit
5805 CU. The result will be allocated with malloc. */
5808 partial_die_full_name (struct partial_die_info *pdi,
5809 struct dwarf2_cu *cu)
5813 /* If this is a template instantiation, we can not work out the
5814 template arguments from partial DIEs. So, unfortunately, we have
5815 to go through the full DIEs. At least any work we do building
5816 types here will be reused if full symbols are loaded later. */
5817 if (pdi->has_template_arguments)
5819 fixup_partial_die (pdi, cu);
5821 if (pdi->name != NULL && strchr (pdi->name, '<') == NULL)
5823 struct die_info *die;
5824 struct attribute attr;
5825 struct dwarf2_cu *ref_cu = cu;
5827 /* DW_FORM_ref_addr is using section offset. */
5829 attr.form = DW_FORM_ref_addr;
5830 attr.u.unsnd = pdi->offset.sect_off;
5831 die = follow_die_ref (NULL, &attr, &ref_cu);
5833 return xstrdup (dwarf2_full_name (NULL, die, ref_cu));
5837 parent_scope = partial_die_parent_scope (pdi, cu);
5838 if (parent_scope == NULL)
5841 return typename_concat (NULL, parent_scope, pdi->name, 0, cu);
5845 add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
5847 struct objfile *objfile = cu->objfile;
5849 char *actual_name = NULL;
5851 int built_actual_name = 0;
5853 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
5855 actual_name = partial_die_full_name (pdi, cu);
5857 built_actual_name = 1;
5859 if (actual_name == NULL)
5860 actual_name = pdi->name;
5864 case DW_TAG_subprogram:
5865 if (pdi->is_external || cu->language == language_ada)
5867 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
5868 of the global scope. But in Ada, we want to be able to access
5869 nested procedures globally. So all Ada subprograms are stored
5870 in the global scope. */
5871 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5872 mst_text, objfile); */
5873 add_psymbol_to_list (actual_name, strlen (actual_name),
5875 VAR_DOMAIN, LOC_BLOCK,
5876 &objfile->global_psymbols,
5877 0, pdi->lowpc + baseaddr,
5878 cu->language, objfile);
5882 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
5883 mst_file_text, objfile); */
5884 add_psymbol_to_list (actual_name, strlen (actual_name),
5886 VAR_DOMAIN, LOC_BLOCK,
5887 &objfile->static_psymbols,
5888 0, pdi->lowpc + baseaddr,
5889 cu->language, objfile);
5892 case DW_TAG_constant:
5894 struct psymbol_allocation_list *list;
5896 if (pdi->is_external)
5897 list = &objfile->global_psymbols;
5899 list = &objfile->static_psymbols;
5900 add_psymbol_to_list (actual_name, strlen (actual_name),
5901 built_actual_name, VAR_DOMAIN, LOC_STATIC,
5902 list, 0, 0, cu->language, objfile);
5905 case DW_TAG_variable:
5907 addr = decode_locdesc (pdi->d.locdesc, cu);
5911 && !dwarf2_per_objfile->has_section_at_zero)
5913 /* A global or static variable may also have been stripped
5914 out by the linker if unused, in which case its address
5915 will be nullified; do not add such variables into partial
5916 symbol table then. */
5918 else if (pdi->is_external)
5921 Don't enter into the minimal symbol tables as there is
5922 a minimal symbol table entry from the ELF symbols already.
5923 Enter into partial symbol table if it has a location
5924 descriptor or a type.
5925 If the location descriptor is missing, new_symbol will create
5926 a LOC_UNRESOLVED symbol, the address of the variable will then
5927 be determined from the minimal symbol table whenever the variable
5929 The address for the partial symbol table entry is not
5930 used by GDB, but it comes in handy for debugging partial symbol
5933 if (pdi->d.locdesc || pdi->has_type)
5934 add_psymbol_to_list (actual_name, strlen (actual_name),
5936 VAR_DOMAIN, LOC_STATIC,
5937 &objfile->global_psymbols,
5939 cu->language, objfile);
5943 /* Static Variable. Skip symbols without location descriptors. */
5944 if (pdi->d.locdesc == NULL)
5946 if (built_actual_name)
5947 xfree (actual_name);
5950 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
5951 mst_file_data, objfile); */
5952 add_psymbol_to_list (actual_name, strlen (actual_name),
5954 VAR_DOMAIN, LOC_STATIC,
5955 &objfile->static_psymbols,
5957 cu->language, objfile);
5960 case DW_TAG_typedef:
5961 case DW_TAG_base_type:
5962 case DW_TAG_subrange_type:
5963 add_psymbol_to_list (actual_name, strlen (actual_name),
5965 VAR_DOMAIN, LOC_TYPEDEF,
5966 &objfile->static_psymbols,
5967 0, (CORE_ADDR) 0, cu->language, objfile);
5969 case DW_TAG_namespace:
5970 add_psymbol_to_list (actual_name, strlen (actual_name),
5972 VAR_DOMAIN, LOC_TYPEDEF,
5973 &objfile->global_psymbols,
5974 0, (CORE_ADDR) 0, cu->language, objfile);
5976 case DW_TAG_class_type:
5977 case DW_TAG_interface_type:
5978 case DW_TAG_structure_type:
5979 case DW_TAG_union_type:
5980 case DW_TAG_enumeration_type:
5981 /* Skip external references. The DWARF standard says in the section
5982 about "Structure, Union, and Class Type Entries": "An incomplete
5983 structure, union or class type is represented by a structure,
5984 union or class entry that does not have a byte size attribute
5985 and that has a DW_AT_declaration attribute." */
5986 if (!pdi->has_byte_size && pdi->is_declaration)
5988 if (built_actual_name)
5989 xfree (actual_name);
5993 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
5994 static vs. global. */
5995 add_psymbol_to_list (actual_name, strlen (actual_name),
5997 STRUCT_DOMAIN, LOC_TYPEDEF,
5998 (cu->language == language_cplus
5999 || cu->language == language_java)
6000 ? &objfile->global_psymbols
6001 : &objfile->static_psymbols,
6002 0, (CORE_ADDR) 0, cu->language, objfile);
6005 case DW_TAG_enumerator:
6006 add_psymbol_to_list (actual_name, strlen (actual_name),
6008 VAR_DOMAIN, LOC_CONST,
6009 (cu->language == language_cplus
6010 || cu->language == language_java)
6011 ? &objfile->global_psymbols
6012 : &objfile->static_psymbols,
6013 0, (CORE_ADDR) 0, cu->language, objfile);
6019 if (built_actual_name)
6020 xfree (actual_name);
6023 /* Read a partial die corresponding to a namespace; also, add a symbol
6024 corresponding to that namespace to the symbol table. NAMESPACE is
6025 the name of the enclosing namespace. */
6028 add_partial_namespace (struct partial_die_info *pdi,
6029 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6030 int need_pc, struct dwarf2_cu *cu)
6032 /* Add a symbol for the namespace. */
6034 add_partial_symbol (pdi, cu);
6036 /* Now scan partial symbols in that namespace. */
6038 if (pdi->has_children)
6039 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
6042 /* Read a partial die corresponding to a Fortran module. */
6045 add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc,
6046 CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu)
6048 /* Now scan partial symbols in that module. */
6050 if (pdi->has_children)
6051 scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu);
6054 /* Read a partial die corresponding to a subprogram and create a partial
6055 symbol for that subprogram. When the CU language allows it, this
6056 routine also defines a partial symbol for each nested subprogram
6057 that this subprogram contains.
6059 DIE my also be a lexical block, in which case we simply search
6060 recursively for suprograms defined inside that lexical block.
6061 Again, this is only performed when the CU language allows this
6062 type of definitions. */
6065 add_partial_subprogram (struct partial_die_info *pdi,
6066 CORE_ADDR *lowpc, CORE_ADDR *highpc,
6067 int need_pc, struct dwarf2_cu *cu)
6069 if (pdi->tag == DW_TAG_subprogram)
6071 if (pdi->has_pc_info)
6073 if (pdi->lowpc < *lowpc)
6074 *lowpc = pdi->lowpc;
6075 if (pdi->highpc > *highpc)
6076 *highpc = pdi->highpc;
6080 struct objfile *objfile = cu->objfile;
6082 baseaddr = ANOFFSET (objfile->section_offsets,
6083 SECT_OFF_TEXT (objfile));
6084 addrmap_set_empty (objfile->psymtabs_addrmap,
6085 pdi->lowpc + baseaddr,
6086 pdi->highpc - 1 + baseaddr,
6087 cu->per_cu->v.psymtab);
6091 if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined))
6093 if (!pdi->is_declaration)
6094 /* Ignore subprogram DIEs that do not have a name, they are
6095 illegal. Do not emit a complaint at this point, we will
6096 do so when we convert this psymtab into a symtab. */
6098 add_partial_symbol (pdi, cu);
6102 if (! pdi->has_children)
6105 if (cu->language == language_ada)
6107 pdi = pdi->die_child;
6110 fixup_partial_die (pdi, cu);
6111 if (pdi->tag == DW_TAG_subprogram
6112 || pdi->tag == DW_TAG_lexical_block)
6113 add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu);
6114 pdi = pdi->die_sibling;
6119 /* Read a partial die corresponding to an enumeration type. */
6122 add_partial_enumeration (struct partial_die_info *enum_pdi,
6123 struct dwarf2_cu *cu)
6125 struct partial_die_info *pdi;
6127 if (enum_pdi->name != NULL)
6128 add_partial_symbol (enum_pdi, cu);
6130 pdi = enum_pdi->die_child;
6133 if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL)
6134 complaint (&symfile_complaints, _("malformed enumerator DIE ignored"));
6136 add_partial_symbol (pdi, cu);
6137 pdi = pdi->die_sibling;
6141 /* Return the initial uleb128 in the die at INFO_PTR. */
6144 peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr)
6146 unsigned int bytes_read;
6148 return read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6151 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
6152 Return the corresponding abbrev, or NULL if the number is zero (indicating
6153 an empty DIE). In either case *BYTES_READ will be set to the length of
6154 the initial number. */
6156 static struct abbrev_info *
6157 peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read,
6158 struct dwarf2_cu *cu)
6160 bfd *abfd = cu->objfile->obfd;
6161 unsigned int abbrev_number;
6162 struct abbrev_info *abbrev;
6164 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
6166 if (abbrev_number == 0)
6169 abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number);
6172 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
6173 abbrev_number, bfd_get_filename (abfd));
6179 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6180 Returns a pointer to the end of a series of DIEs, terminated by an empty
6181 DIE. Any children of the skipped DIEs will also be skipped. */
6184 skip_children (const struct die_reader_specs *reader, gdb_byte *info_ptr)
6186 struct dwarf2_cu *cu = reader->cu;
6187 struct abbrev_info *abbrev;
6188 unsigned int bytes_read;
6192 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
6194 return info_ptr + bytes_read;
6196 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
6200 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
6201 INFO_PTR should point just after the initial uleb128 of a DIE, and the
6202 abbrev corresponding to that skipped uleb128 should be passed in
6203 ABBREV. Returns a pointer to this DIE's sibling, skipping any
6207 skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr,
6208 struct abbrev_info *abbrev)
6210 unsigned int bytes_read;
6211 struct attribute attr;
6212 bfd *abfd = reader->abfd;
6213 struct dwarf2_cu *cu = reader->cu;
6214 gdb_byte *buffer = reader->buffer;
6215 const gdb_byte *buffer_end = reader->buffer_end;
6216 gdb_byte *start_info_ptr = info_ptr;
6217 unsigned int form, i;
6219 for (i = 0; i < abbrev->num_attrs; i++)
6221 /* The only abbrev we care about is DW_AT_sibling. */
6222 if (abbrev->attrs[i].name == DW_AT_sibling)
6224 read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
6225 if (attr.form == DW_FORM_ref_addr)
6226 complaint (&symfile_complaints,
6227 _("ignoring absolute DW_AT_sibling"));
6229 return buffer + dwarf2_get_ref_die_offset (&attr).sect_off;
6232 /* If it isn't DW_AT_sibling, skip this attribute. */
6233 form = abbrev->attrs[i].form;
6237 case DW_FORM_ref_addr:
6238 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
6239 and later it is offset sized. */
6240 if (cu->header.version == 2)
6241 info_ptr += cu->header.addr_size;
6243 info_ptr += cu->header.offset_size;
6245 case DW_FORM_GNU_ref_alt:
6246 info_ptr += cu->header.offset_size;
6249 info_ptr += cu->header.addr_size;
6256 case DW_FORM_flag_present:
6268 case DW_FORM_ref_sig8:
6271 case DW_FORM_string:
6272 read_direct_string (abfd, info_ptr, &bytes_read);
6273 info_ptr += bytes_read;
6275 case DW_FORM_sec_offset:
6277 case DW_FORM_GNU_strp_alt:
6278 info_ptr += cu->header.offset_size;
6280 case DW_FORM_exprloc:
6282 info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6283 info_ptr += bytes_read;
6285 case DW_FORM_block1:
6286 info_ptr += 1 + read_1_byte (abfd, info_ptr);
6288 case DW_FORM_block2:
6289 info_ptr += 2 + read_2_bytes (abfd, info_ptr);
6291 case DW_FORM_block4:
6292 info_ptr += 4 + read_4_bytes (abfd, info_ptr);
6296 case DW_FORM_ref_udata:
6297 case DW_FORM_GNU_addr_index:
6298 case DW_FORM_GNU_str_index:
6299 info_ptr = (gdb_byte *) safe_skip_leb128 (info_ptr, buffer_end);
6301 case DW_FORM_indirect:
6302 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
6303 info_ptr += bytes_read;
6304 /* We need to continue parsing from here, so just go back to
6306 goto skip_attribute;
6309 error (_("Dwarf Error: Cannot handle %s "
6310 "in DWARF reader [in module %s]"),
6311 dwarf_form_name (form),
6312 bfd_get_filename (abfd));
6316 if (abbrev->has_children)
6317 return skip_children (reader, info_ptr);
6322 /* Locate ORIG_PDI's sibling.
6323 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
6326 locate_pdi_sibling (const struct die_reader_specs *reader,
6327 struct partial_die_info *orig_pdi,
6330 /* Do we know the sibling already? */
6332 if (orig_pdi->sibling)
6333 return orig_pdi->sibling;
6335 /* Are there any children to deal with? */
6337 if (!orig_pdi->has_children)
6340 /* Skip the children the long way. */
6342 return skip_children (reader, info_ptr);
6345 /* Expand this partial symbol table into a full symbol table. */
6348 dwarf2_psymtab_to_symtab (struct partial_symtab *pst)
6354 warning (_("bug: psymtab for %s is already read in."),
6361 printf_filtered (_("Reading in symbols for %s..."),
6363 gdb_flush (gdb_stdout);
6366 /* Restore our global data. */
6367 dwarf2_per_objfile = objfile_data (pst->objfile,
6368 dwarf2_objfile_data_key);
6370 /* If this psymtab is constructed from a debug-only objfile, the
6371 has_section_at_zero flag will not necessarily be correct. We
6372 can get the correct value for this flag by looking at the data
6373 associated with the (presumably stripped) associated objfile. */
6374 if (pst->objfile->separate_debug_objfile_backlink)
6376 struct dwarf2_per_objfile *dpo_backlink
6377 = objfile_data (pst->objfile->separate_debug_objfile_backlink,
6378 dwarf2_objfile_data_key);
6380 dwarf2_per_objfile->has_section_at_zero
6381 = dpo_backlink->has_section_at_zero;
6384 dwarf2_per_objfile->reading_partial_symbols = 0;
6386 psymtab_to_symtab_1 (pst);
6388 /* Finish up the debug error message. */
6390 printf_filtered (_("done.\n"));
6394 process_cu_includes ();
6397 /* Reading in full CUs. */
6399 /* Add PER_CU to the queue. */
6402 queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
6403 enum language pretend_language)
6405 struct dwarf2_queue_item *item;
6408 item = xmalloc (sizeof (*item));
6409 item->per_cu = per_cu;
6410 item->pretend_language = pretend_language;
6413 if (dwarf2_queue == NULL)
6414 dwarf2_queue = item;
6416 dwarf2_queue_tail->next = item;
6418 dwarf2_queue_tail = item;
6421 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
6422 unit and add it to our queue.
6423 The result is non-zero if PER_CU was queued, otherwise the result is zero
6424 meaning either PER_CU is already queued or it is already loaded. */
6427 maybe_queue_comp_unit (struct dwarf2_cu *this_cu,
6428 struct dwarf2_per_cu_data *per_cu,
6429 enum language pretend_language)
6431 /* We may arrive here during partial symbol reading, if we need full
6432 DIEs to process an unusual case (e.g. template arguments). Do
6433 not queue PER_CU, just tell our caller to load its DIEs. */
6434 if (dwarf2_per_objfile->reading_partial_symbols)
6436 if (per_cu->cu == NULL || per_cu->cu->dies == NULL)
6441 /* Mark the dependence relation so that we don't flush PER_CU
6443 dwarf2_add_dependence (this_cu, per_cu);
6445 /* If it's already on the queue, we have nothing to do. */
6449 /* If the compilation unit is already loaded, just mark it as
6451 if (per_cu->cu != NULL)
6453 per_cu->cu->last_used = 0;
6457 /* Add it to the queue. */
6458 queue_comp_unit (per_cu, pretend_language);
6463 /* Process the queue. */
6466 process_queue (void)
6468 struct dwarf2_queue_item *item, *next_item;
6470 if (dwarf2_read_debug)
6472 fprintf_unfiltered (gdb_stdlog,
6473 "Expanding one or more symtabs of objfile %s ...\n",
6474 dwarf2_per_objfile->objfile->name);
6477 /* The queue starts out with one item, but following a DIE reference
6478 may load a new CU, adding it to the end of the queue. */
6479 for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
6481 if (dwarf2_per_objfile->using_index
6482 ? !item->per_cu->v.quick->symtab
6483 : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
6485 struct dwarf2_per_cu_data *per_cu = item->per_cu;
6487 if (dwarf2_read_debug)
6489 fprintf_unfiltered (gdb_stdlog,
6490 "Expanding symtab of %s at offset 0x%x\n",
6491 per_cu->is_debug_types ? "TU" : "CU",
6492 per_cu->offset.sect_off);
6495 if (per_cu->is_debug_types)
6496 process_full_type_unit (per_cu, item->pretend_language);
6498 process_full_comp_unit (per_cu, item->pretend_language);
6500 if (dwarf2_read_debug)
6502 fprintf_unfiltered (gdb_stdlog,
6503 "Done expanding %s at offset 0x%x\n",
6504 per_cu->is_debug_types ? "TU" : "CU",
6505 per_cu->offset.sect_off);
6509 item->per_cu->queued = 0;
6510 next_item = item->next;
6514 dwarf2_queue_tail = NULL;
6516 if (dwarf2_read_debug)
6518 fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n",
6519 dwarf2_per_objfile->objfile->name);
6523 /* Free all allocated queue entries. This function only releases anything if
6524 an error was thrown; if the queue was processed then it would have been
6525 freed as we went along. */
6528 dwarf2_release_queue (void *dummy)
6530 struct dwarf2_queue_item *item, *last;
6532 item = dwarf2_queue;
6535 /* Anything still marked queued is likely to be in an
6536 inconsistent state, so discard it. */
6537 if (item->per_cu->queued)
6539 if (item->per_cu->cu != NULL)
6540 free_one_cached_comp_unit (item->per_cu);
6541 item->per_cu->queued = 0;
6549 dwarf2_queue = dwarf2_queue_tail = NULL;
6552 /* Read in full symbols for PST, and anything it depends on. */
6555 psymtab_to_symtab_1 (struct partial_symtab *pst)
6557 struct dwarf2_per_cu_data *per_cu;
6563 for (i = 0; i < pst->number_of_dependencies; i++)
6564 if (!pst->dependencies[i]->readin
6565 && pst->dependencies[i]->user == NULL)
6567 /* Inform about additional files that need to be read in. */
6570 /* FIXME: i18n: Need to make this a single string. */
6571 fputs_filtered (" ", gdb_stdout);
6573 fputs_filtered ("and ", gdb_stdout);
6575 printf_filtered ("%s...", pst->dependencies[i]->filename);
6576 wrap_here (""); /* Flush output. */
6577 gdb_flush (gdb_stdout);
6579 psymtab_to_symtab_1 (pst->dependencies[i]);
6582 per_cu = pst->read_symtab_private;
6586 /* It's an include file, no symbols to read for it.
6587 Everything is in the parent symtab. */
6592 dw2_do_instantiate_symtab (per_cu);
6595 /* Trivial hash function for die_info: the hash value of a DIE
6596 is its offset in .debug_info for this objfile. */
6599 die_hash (const void *item)
6601 const struct die_info *die = item;
6603 return die->offset.sect_off;
6606 /* Trivial comparison function for die_info structures: two DIEs
6607 are equal if they have the same offset. */
6610 die_eq (const void *item_lhs, const void *item_rhs)
6612 const struct die_info *die_lhs = item_lhs;
6613 const struct die_info *die_rhs = item_rhs;
6615 return die_lhs->offset.sect_off == die_rhs->offset.sect_off;
6618 /* die_reader_func for load_full_comp_unit.
6619 This is identical to read_signatured_type_reader,
6620 but is kept separate for now. */
6623 load_full_comp_unit_reader (const struct die_reader_specs *reader,
6625 struct die_info *comp_unit_die,
6629 struct dwarf2_cu *cu = reader->cu;
6630 enum language *language_ptr = data;
6632 gdb_assert (cu->die_hash == NULL);
6634 htab_create_alloc_ex (cu->header.length / 12,
6638 &cu->comp_unit_obstack,
6639 hashtab_obstack_allocate,
6640 dummy_obstack_deallocate);
6643 comp_unit_die->child = read_die_and_siblings (reader, info_ptr,
6644 &info_ptr, comp_unit_die);
6645 cu->dies = comp_unit_die;
6646 /* comp_unit_die is not stored in die_hash, no need. */
6648 /* We try not to read any attributes in this function, because not
6649 all CUs needed for references have been loaded yet, and symbol
6650 table processing isn't initialized. But we have to set the CU language,
6651 or we won't be able to build types correctly.
6652 Similarly, if we do not read the producer, we can not apply
6653 producer-specific interpretation. */
6654 prepare_one_comp_unit (cu, cu->dies, *language_ptr);
6657 /* Load the DIEs associated with PER_CU into memory. */
6660 load_full_comp_unit (struct dwarf2_per_cu_data *this_cu,
6661 enum language pretend_language)
6663 gdb_assert (! this_cu->is_debug_types);
6665 init_cutu_and_read_dies (this_cu, NULL, 1, 1,
6666 load_full_comp_unit_reader, &pretend_language);
6669 /* Add a DIE to the delayed physname list. */
6672 add_to_method_list (struct type *type, int fnfield_index, int index,
6673 const char *name, struct die_info *die,
6674 struct dwarf2_cu *cu)
6676 struct delayed_method_info mi;
6678 mi.fnfield_index = fnfield_index;
6682 VEC_safe_push (delayed_method_info, cu->method_list, &mi);
6685 /* A cleanup for freeing the delayed method list. */
6688 free_delayed_list (void *ptr)
6690 struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr;
6691 if (cu->method_list != NULL)
6693 VEC_free (delayed_method_info, cu->method_list);
6694 cu->method_list = NULL;
6698 /* Compute the physnames of any methods on the CU's method list.
6700 The computation of method physnames is delayed in order to avoid the
6701 (bad) condition that one of the method's formal parameters is of an as yet
6705 compute_delayed_physnames (struct dwarf2_cu *cu)
6708 struct delayed_method_info *mi;
6709 for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i)
6711 const char *physname;
6712 struct fn_fieldlist *fn_flp
6713 = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index);
6714 physname = dwarf2_physname ((char *) mi->name, mi->die, cu);
6715 fn_flp->fn_fields[mi->index].physname = physname ? physname : "";
6719 /* Go objects should be embedded in a DW_TAG_module DIE,
6720 and it's not clear if/how imported objects will appear.
6721 To keep Go support simple until that's worked out,
6722 go back through what we've read and create something usable.
6723 We could do this while processing each DIE, and feels kinda cleaner,
6724 but that way is more invasive.
6725 This is to, for example, allow the user to type "p var" or "b main"
6726 without having to specify the package name, and allow lookups
6727 of module.object to work in contexts that use the expression
6731 fixup_go_packaging (struct dwarf2_cu *cu)
6733 char *package_name = NULL;
6734 struct pending *list;
6737 for (list = global_symbols; list != NULL; list = list->next)
6739 for (i = 0; i < list->nsyms; ++i)
6741 struct symbol *sym = list->symbol[i];
6743 if (SYMBOL_LANGUAGE (sym) == language_go
6744 && SYMBOL_CLASS (sym) == LOC_BLOCK)
6746 char *this_package_name = go_symbol_package_name (sym);
6748 if (this_package_name == NULL)
6750 if (package_name == NULL)
6751 package_name = this_package_name;
6754 if (strcmp (package_name, this_package_name) != 0)
6755 complaint (&symfile_complaints,
6756 _("Symtab %s has objects from two different Go packages: %s and %s"),
6757 (SYMBOL_SYMTAB (sym)
6758 && SYMBOL_SYMTAB (sym)->filename
6759 ? SYMBOL_SYMTAB (sym)->filename
6760 : cu->objfile->name),
6761 this_package_name, package_name);
6762 xfree (this_package_name);
6768 if (package_name != NULL)
6770 struct objfile *objfile = cu->objfile;
6771 struct type *type = init_type (TYPE_CODE_MODULE, 0, 0,
6772 package_name, objfile);
6775 TYPE_TAG_NAME (type) = TYPE_NAME (type);
6777 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
6778 SYMBOL_SET_LANGUAGE (sym, language_go);
6779 SYMBOL_SET_NAMES (sym, package_name, strlen (package_name), 1, objfile);
6780 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
6781 e.g., "main" finds the "main" module and not C's main(). */
6782 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
6783 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
6784 SYMBOL_TYPE (sym) = type;
6786 add_symbol_to_list (sym, &global_symbols);
6788 xfree (package_name);
6792 static void compute_symtab_includes (struct dwarf2_per_cu_data *per_cu);
6794 /* Return the symtab for PER_CU. This works properly regardless of
6795 whether we're using the index or psymtabs. */
6797 static struct symtab *
6798 get_symtab (struct dwarf2_per_cu_data *per_cu)
6800 return (dwarf2_per_objfile->using_index
6801 ? per_cu->v.quick->symtab
6802 : per_cu->v.psymtab->symtab);
6805 /* A helper function for computing the list of all symbol tables
6806 included by PER_CU. */
6809 recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr) **result,
6810 htab_t all_children,
6811 struct dwarf2_per_cu_data *per_cu)
6815 struct dwarf2_per_cu_data *iter;
6817 slot = htab_find_slot (all_children, per_cu, INSERT);
6820 /* This inclusion and its children have been processed. */
6825 /* Only add a CU if it has a symbol table. */
6826 if (get_symtab (per_cu) != NULL)
6827 VEC_safe_push (dwarf2_per_cu_ptr, *result, per_cu);
6830 VEC_iterate (dwarf2_per_cu_ptr, per_cu->s.imported_symtabs, ix, iter);
6832 recursively_compute_inclusions (result, all_children, iter);
6835 /* Compute the symtab 'includes' fields for the symtab related to
6839 compute_symtab_includes (struct dwarf2_per_cu_data *per_cu)
6841 gdb_assert (! per_cu->is_debug_types);
6843 if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->s.imported_symtabs))
6846 struct dwarf2_per_cu_data *iter;
6847 VEC (dwarf2_per_cu_ptr) *result_children = NULL;
6848 htab_t all_children;
6849 struct symtab *symtab = get_symtab (per_cu);
6851 /* If we don't have a symtab, we can just skip this case. */
6855 all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
6856 NULL, xcalloc, xfree);
6859 VEC_iterate (dwarf2_per_cu_ptr, per_cu->s.imported_symtabs,
6862 recursively_compute_inclusions (&result_children, all_children, iter);
6864 /* Now we have a transitive closure of all the included CUs, so
6865 we can convert it to a list of symtabs. */
6866 len = VEC_length (dwarf2_per_cu_ptr, result_children);
6868 = obstack_alloc (&dwarf2_per_objfile->objfile->objfile_obstack,
6869 (len + 1) * sizeof (struct symtab *));
6871 VEC_iterate (dwarf2_per_cu_ptr, result_children, ix, iter);
6873 symtab->includes[ix] = get_symtab (iter);
6874 symtab->includes[len] = NULL;
6876 VEC_free (dwarf2_per_cu_ptr, result_children);
6877 htab_delete (all_children);
6881 /* Compute the 'includes' field for the symtabs of all the CUs we just
6885 process_cu_includes (void)
6888 struct dwarf2_per_cu_data *iter;
6891 VEC_iterate (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus,
6895 if (! iter->is_debug_types)
6896 compute_symtab_includes (iter);
6899 VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus);
6902 /* Generate full symbol information for PER_CU, whose DIEs have
6903 already been loaded into memory. */
6906 process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
6907 enum language pretend_language)
6909 struct dwarf2_cu *cu = per_cu->cu;
6910 struct objfile *objfile = per_cu->objfile;
6911 CORE_ADDR lowpc, highpc;
6912 struct symtab *symtab;
6913 struct cleanup *back_to, *delayed_list_cleanup;
6915 struct block *static_block;
6917 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
6920 back_to = make_cleanup (really_free_pendings, NULL);
6921 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
6923 cu->list_in_scope = &file_symbols;
6925 cu->language = pretend_language;
6926 cu->language_defn = language_def (cu->language);
6928 /* Do line number decoding in read_file_scope () */
6929 process_die (cu->dies, cu);
6931 /* For now fudge the Go package. */
6932 if (cu->language == language_go)
6933 fixup_go_packaging (cu);
6935 /* Now that we have processed all the DIEs in the CU, all the types
6936 should be complete, and it should now be safe to compute all of the
6938 compute_delayed_physnames (cu);
6939 do_cleanups (delayed_list_cleanup);
6941 /* Some compilers don't define a DW_AT_high_pc attribute for the
6942 compilation unit. If the DW_AT_high_pc is missing, synthesize
6943 it, by scanning the DIE's below the compilation unit. */
6944 get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu);
6947 = end_symtab_get_static_block (highpc + baseaddr, objfile, 0,
6948 per_cu->s.imported_symtabs != NULL);
6950 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
6951 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
6952 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
6953 addrmap to help ensure it has an accurate map of pc values belonging to
6955 dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu);
6957 symtab = end_symtab_from_static_block (static_block, objfile,
6958 SECT_OFF_TEXT (objfile), 0);
6962 int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer);
6964 /* Set symtab language to language from DW_AT_language. If the
6965 compilation is from a C file generated by language preprocessors, do
6966 not set the language if it was already deduced by start_subfile. */
6967 if (!(cu->language == language_c && symtab->language != language_c))
6968 symtab->language = cu->language;
6970 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
6971 produce DW_AT_location with location lists but it can be possibly
6972 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
6973 there were bugs in prologue debug info, fixed later in GCC-4.5
6974 by "unwind info for epilogues" patch (which is not directly related).
6976 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
6977 needed, it would be wrong due to missing DW_AT_producer there.
6979 Still one can confuse GDB by using non-standard GCC compilation
6980 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
6982 if (cu->has_loclist && gcc_4_minor >= 5)
6983 symtab->locations_valid = 1;
6985 if (gcc_4_minor >= 5)
6986 symtab->epilogue_unwind_valid = 1;
6988 symtab->call_site_htab = cu->call_site_htab;
6991 if (dwarf2_per_objfile->using_index)
6992 per_cu->v.quick->symtab = symtab;
6995 struct partial_symtab *pst = per_cu->v.psymtab;
6996 pst->symtab = symtab;
7000 /* Push it for inclusion processing later. */
7001 VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu);
7003 do_cleanups (back_to);
7006 /* Generate full symbol information for type unit PER_CU, whose DIEs have
7007 already been loaded into memory. */
7010 process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
7011 enum language pretend_language)
7013 struct dwarf2_cu *cu = per_cu->cu;
7014 struct objfile *objfile = per_cu->objfile;
7015 struct symtab *symtab;
7016 struct cleanup *back_to, *delayed_list_cleanup;
7019 back_to = make_cleanup (really_free_pendings, NULL);
7020 delayed_list_cleanup = make_cleanup (free_delayed_list, cu);
7022 cu->list_in_scope = &file_symbols;
7024 cu->language = pretend_language;
7025 cu->language_defn = language_def (cu->language);
7027 /* The symbol tables are set up in read_type_unit_scope. */
7028 process_die (cu->dies, cu);
7030 /* For now fudge the Go package. */
7031 if (cu->language == language_go)
7032 fixup_go_packaging (cu);
7034 /* Now that we have processed all the DIEs in the CU, all the types
7035 should be complete, and it should now be safe to compute all of the
7037 compute_delayed_physnames (cu);
7038 do_cleanups (delayed_list_cleanup);
7040 /* TUs share symbol tables.
7041 If this is the first TU to use this symtab, complete the construction
7042 of it with end_expandable_symtab. Otherwise, complete the addition of
7043 this TU's symbols to the existing symtab. */
7044 if (per_cu->s.type_unit_group->primary_symtab == NULL)
7046 symtab = end_expandable_symtab (0, objfile, SECT_OFF_TEXT (objfile));
7047 per_cu->s.type_unit_group->primary_symtab = symtab;
7051 /* Set symtab language to language from DW_AT_language. If the
7052 compilation is from a C file generated by language preprocessors,
7053 do not set the language if it was already deduced by
7055 if (!(cu->language == language_c && symtab->language != language_c))
7056 symtab->language = cu->language;
7061 augment_type_symtab (objfile,
7062 per_cu->s.type_unit_group->primary_symtab);
7063 symtab = per_cu->s.type_unit_group->primary_symtab;
7066 if (dwarf2_per_objfile->using_index)
7067 per_cu->v.quick->symtab = symtab;
7070 struct partial_symtab *pst = per_cu->v.psymtab;
7071 pst->symtab = symtab;
7075 do_cleanups (back_to);
7078 /* Process an imported unit DIE. */
7081 process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
7083 struct attribute *attr;
7085 /* For now we don't handle imported units in type units. */
7086 if (cu->per_cu->is_debug_types)
7088 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7089 " supported in type units [in module %s]"),
7093 attr = dwarf2_attr (die, DW_AT_import, cu);
7096 struct dwarf2_per_cu_data *per_cu;
7097 struct symtab *imported_symtab;
7101 offset = dwarf2_get_ref_die_offset (attr);
7102 is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
7103 per_cu = dwarf2_find_containing_comp_unit (offset, is_dwz, cu->objfile);
7105 /* Queue the unit, if needed. */
7106 if (maybe_queue_comp_unit (cu, per_cu, cu->language))
7107 load_full_comp_unit (per_cu, cu->language);
7109 VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs,
7114 /* Process a die and its children. */
7117 process_die (struct die_info *die, struct dwarf2_cu *cu)
7121 case DW_TAG_padding:
7123 case DW_TAG_compile_unit:
7124 case DW_TAG_partial_unit:
7125 read_file_scope (die, cu);
7127 case DW_TAG_type_unit:
7128 read_type_unit_scope (die, cu);
7130 case DW_TAG_subprogram:
7131 case DW_TAG_inlined_subroutine:
7132 read_func_scope (die, cu);
7134 case DW_TAG_lexical_block:
7135 case DW_TAG_try_block:
7136 case DW_TAG_catch_block:
7137 read_lexical_block_scope (die, cu);
7139 case DW_TAG_GNU_call_site:
7140 read_call_site_scope (die, cu);
7142 case DW_TAG_class_type:
7143 case DW_TAG_interface_type:
7144 case DW_TAG_structure_type:
7145 case DW_TAG_union_type:
7146 process_structure_scope (die, cu);
7148 case DW_TAG_enumeration_type:
7149 process_enumeration_scope (die, cu);
7152 /* These dies have a type, but processing them does not create
7153 a symbol or recurse to process the children. Therefore we can
7154 read them on-demand through read_type_die. */
7155 case DW_TAG_subroutine_type:
7156 case DW_TAG_set_type:
7157 case DW_TAG_array_type:
7158 case DW_TAG_pointer_type:
7159 case DW_TAG_ptr_to_member_type:
7160 case DW_TAG_reference_type:
7161 case DW_TAG_string_type:
7164 case DW_TAG_base_type:
7165 case DW_TAG_subrange_type:
7166 case DW_TAG_typedef:
7167 /* Add a typedef symbol for the type definition, if it has a
7169 new_symbol (die, read_type_die (die, cu), cu);
7171 case DW_TAG_common_block:
7172 read_common_block (die, cu);
7174 case DW_TAG_common_inclusion:
7176 case DW_TAG_namespace:
7177 processing_has_namespace_info = 1;
7178 read_namespace (die, cu);
7181 processing_has_namespace_info = 1;
7182 read_module (die, cu);
7184 case DW_TAG_imported_declaration:
7185 case DW_TAG_imported_module:
7186 processing_has_namespace_info = 1;
7187 if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
7188 || cu->language != language_fortran))
7189 complaint (&symfile_complaints, _("Tag '%s' has unexpected children"),
7190 dwarf_tag_name (die->tag));
7191 read_import_statement (die, cu);
7194 case DW_TAG_imported_unit:
7195 process_imported_unit_die (die, cu);
7199 new_symbol (die, NULL, cu);
7204 /* A helper function for dwarf2_compute_name which determines whether DIE
7205 needs to have the name of the scope prepended to the name listed in the
7209 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
7211 struct attribute *attr;
7215 case DW_TAG_namespace:
7216 case DW_TAG_typedef:
7217 case DW_TAG_class_type:
7218 case DW_TAG_interface_type:
7219 case DW_TAG_structure_type:
7220 case DW_TAG_union_type:
7221 case DW_TAG_enumeration_type:
7222 case DW_TAG_enumerator:
7223 case DW_TAG_subprogram:
7227 case DW_TAG_variable:
7228 case DW_TAG_constant:
7229 /* We only need to prefix "globally" visible variables. These include
7230 any variable marked with DW_AT_external or any variable that
7231 lives in a namespace. [Variables in anonymous namespaces
7232 require prefixing, but they are not DW_AT_external.] */
7234 if (dwarf2_attr (die, DW_AT_specification, cu))
7236 struct dwarf2_cu *spec_cu = cu;
7238 return die_needs_namespace (die_specification (die, &spec_cu),
7242 attr = dwarf2_attr (die, DW_AT_external, cu);
7243 if (attr == NULL && die->parent->tag != DW_TAG_namespace
7244 && die->parent->tag != DW_TAG_module)
7246 /* A variable in a lexical block of some kind does not need a
7247 namespace, even though in C++ such variables may be external
7248 and have a mangled name. */
7249 if (die->parent->tag == DW_TAG_lexical_block
7250 || die->parent->tag == DW_TAG_try_block
7251 || die->parent->tag == DW_TAG_catch_block
7252 || die->parent->tag == DW_TAG_subprogram)
7261 /* Retrieve the last character from a mem_file. */
7264 do_ui_file_peek_last (void *object, const char *buffer, long length)
7266 char *last_char_p = (char *) object;
7269 *last_char_p = buffer[length - 1];
7272 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
7273 compute the physname for the object, which include a method's:
7274 - formal parameters (C++/Java),
7275 - receiver type (Go),
7276 - return type (Java).
7278 The term "physname" is a bit confusing.
7279 For C++, for example, it is the demangled name.
7280 For Go, for example, it's the mangled name.
7282 For Ada, return the DIE's linkage name rather than the fully qualified
7283 name. PHYSNAME is ignored..
7285 The result is allocated on the objfile_obstack and canonicalized. */
7288 dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
7291 struct objfile *objfile = cu->objfile;
7294 name = dwarf2_name (die, cu);
7296 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
7297 compute it by typename_concat inside GDB. */
7298 if (cu->language == language_ada
7299 || (cu->language == language_fortran && physname))
7301 /* For Ada unit, we prefer the linkage name over the name, as
7302 the former contains the exported name, which the user expects
7303 to be able to reference. Ideally, we want the user to be able
7304 to reference this entity using either natural or linkage name,
7305 but we haven't started looking at this enhancement yet. */
7306 struct attribute *attr;
7308 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
7310 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7311 if (attr && DW_STRING (attr))
7312 return DW_STRING (attr);
7315 /* These are the only languages we know how to qualify names in. */
7317 && (cu->language == language_cplus || cu->language == language_java
7318 || cu->language == language_fortran))
7320 if (die_needs_namespace (die, cu))
7324 struct ui_file *buf;
7326 prefix = determine_prefix (die, cu);
7327 buf = mem_fileopen ();
7328 if (*prefix != '\0')
7330 char *prefixed_name = typename_concat (NULL, prefix, name,
7333 fputs_unfiltered (prefixed_name, buf);
7334 xfree (prefixed_name);
7337 fputs_unfiltered (name, buf);
7339 /* Template parameters may be specified in the DIE's DW_AT_name, or
7340 as children with DW_TAG_template_type_param or
7341 DW_TAG_value_type_param. If the latter, add them to the name
7342 here. If the name already has template parameters, then
7343 skip this step; some versions of GCC emit both, and
7344 it is more efficient to use the pre-computed name.
7346 Something to keep in mind about this process: it is very
7347 unlikely, or in some cases downright impossible, to produce
7348 something that will match the mangled name of a function.
7349 If the definition of the function has the same debug info,
7350 we should be able to match up with it anyway. But fallbacks
7351 using the minimal symbol, for instance to find a method
7352 implemented in a stripped copy of libstdc++, will not work.
7353 If we do not have debug info for the definition, we will have to
7354 match them up some other way.
7356 When we do name matching there is a related problem with function
7357 templates; two instantiated function templates are allowed to
7358 differ only by their return types, which we do not add here. */
7360 if (cu->language == language_cplus && strchr (name, '<') == NULL)
7362 struct attribute *attr;
7363 struct die_info *child;
7366 die->building_fullname = 1;
7368 for (child = die->child; child != NULL; child = child->sibling)
7373 struct dwarf2_locexpr_baton *baton;
7376 if (child->tag != DW_TAG_template_type_param
7377 && child->tag != DW_TAG_template_value_param)
7382 fputs_unfiltered ("<", buf);
7386 fputs_unfiltered (", ", buf);
7388 attr = dwarf2_attr (child, DW_AT_type, cu);
7391 complaint (&symfile_complaints,
7392 _("template parameter missing DW_AT_type"));
7393 fputs_unfiltered ("UNKNOWN_TYPE", buf);
7396 type = die_type (child, cu);
7398 if (child->tag == DW_TAG_template_type_param)
7400 c_print_type (type, "", buf, -1, 0, &type_print_raw_options);
7404 attr = dwarf2_attr (child, DW_AT_const_value, cu);
7407 complaint (&symfile_complaints,
7408 _("template parameter missing "
7409 "DW_AT_const_value"));
7410 fputs_unfiltered ("UNKNOWN_VALUE", buf);
7414 dwarf2_const_value_attr (attr, type, name,
7415 &cu->comp_unit_obstack, cu,
7416 &value, &bytes, &baton);
7418 if (TYPE_NOSIGN (type))
7419 /* GDB prints characters as NUMBER 'CHAR'. If that's
7420 changed, this can use value_print instead. */
7421 c_printchar (value, type, buf);
7424 struct value_print_options opts;
7427 v = dwarf2_evaluate_loc_desc (type, NULL,
7431 else if (bytes != NULL)
7433 v = allocate_value (type);
7434 memcpy (value_contents_writeable (v), bytes,
7435 TYPE_LENGTH (type));
7438 v = value_from_longest (type, value);
7440 /* Specify decimal so that we do not depend on
7442 get_formatted_print_options (&opts, 'd');
7444 value_print (v, buf, &opts);
7450 die->building_fullname = 0;
7454 /* Close the argument list, with a space if necessary
7455 (nested templates). */
7456 char last_char = '\0';
7457 ui_file_put (buf, do_ui_file_peek_last, &last_char);
7458 if (last_char == '>')
7459 fputs_unfiltered (" >", buf);
7461 fputs_unfiltered (">", buf);
7465 /* For Java and C++ methods, append formal parameter type
7466 information, if PHYSNAME. */
7468 if (physname && die->tag == DW_TAG_subprogram
7469 && (cu->language == language_cplus
7470 || cu->language == language_java))
7472 struct type *type = read_type_die (die, cu);
7474 c_type_print_args (type, buf, 1, cu->language,
7475 &type_print_raw_options);
7477 if (cu->language == language_java)
7479 /* For java, we must append the return type to method
7481 if (die->tag == DW_TAG_subprogram)
7482 java_print_type (TYPE_TARGET_TYPE (type), "", buf,
7483 0, 0, &type_print_raw_options);
7485 else if (cu->language == language_cplus)
7487 /* Assume that an artificial first parameter is
7488 "this", but do not crash if it is not. RealView
7489 marks unnamed (and thus unused) parameters as
7490 artificial; there is no way to differentiate
7492 if (TYPE_NFIELDS (type) > 0
7493 && TYPE_FIELD_ARTIFICIAL (type, 0)
7494 && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR
7495 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
7497 fputs_unfiltered (" const", buf);
7501 name = ui_file_obsavestring (buf, &objfile->objfile_obstack,
7503 ui_file_delete (buf);
7505 if (cu->language == language_cplus)
7508 = dwarf2_canonicalize_name (name, cu,
7509 &objfile->objfile_obstack);
7520 /* Return the fully qualified name of DIE, based on its DW_AT_name.
7521 If scope qualifiers are appropriate they will be added. The result
7522 will be allocated on the objfile_obstack, or NULL if the DIE does
7523 not have a name. NAME may either be from a previous call to
7524 dwarf2_name or NULL.
7526 The output string will be canonicalized (if C++/Java). */
7529 dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu)
7531 return dwarf2_compute_name (name, die, cu, 0);
7534 /* Construct a physname for the given DIE in CU. NAME may either be
7535 from a previous call to dwarf2_name or NULL. The result will be
7536 allocated on the objfile_objstack or NULL if the DIE does not have a
7539 The output string will be canonicalized (if C++/Java). */
7542 dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
7544 struct objfile *objfile = cu->objfile;
7545 struct attribute *attr;
7546 const char *retval, *mangled = NULL, *canon = NULL;
7547 struct cleanup *back_to;
7550 /* In this case dwarf2_compute_name is just a shortcut not building anything
7552 if (!die_needs_namespace (die, cu))
7553 return dwarf2_compute_name (name, die, cu, 1);
7555 back_to = make_cleanup (null_cleanup, NULL);
7557 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
7559 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
7561 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
7563 if (attr && DW_STRING (attr))
7567 mangled = DW_STRING (attr);
7569 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
7570 type. It is easier for GDB users to search for such functions as
7571 `name(params)' than `long name(params)'. In such case the minimal
7572 symbol names do not match the full symbol names but for template
7573 functions there is never a need to look up their definition from their
7574 declaration so the only disadvantage remains the minimal symbol
7575 variant `long name(params)' does not have the proper inferior type.
7578 if (cu->language == language_go)
7580 /* This is a lie, but we already lie to the caller new_symbol_full.
7581 new_symbol_full assumes we return the mangled name.
7582 This just undoes that lie until things are cleaned up. */
7587 demangled = cplus_demangle (mangled,
7588 (DMGL_PARAMS | DMGL_ANSI
7589 | (cu->language == language_java
7590 ? DMGL_JAVA | DMGL_RET_POSTFIX
7595 make_cleanup (xfree, demangled);
7605 if (canon == NULL || check_physname)
7607 const char *physname = dwarf2_compute_name (name, die, cu, 1);
7609 if (canon != NULL && strcmp (physname, canon) != 0)
7611 /* It may not mean a bug in GDB. The compiler could also
7612 compute DW_AT_linkage_name incorrectly. But in such case
7613 GDB would need to be bug-to-bug compatible. */
7615 complaint (&symfile_complaints,
7616 _("Computed physname <%s> does not match demangled <%s> "
7617 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
7618 physname, canon, mangled, die->offset.sect_off, objfile->name);
7620 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
7621 is available here - over computed PHYSNAME. It is safer
7622 against both buggy GDB and buggy compilers. */
7636 retval = obsavestring (retval, strlen (retval),
7637 &objfile->objfile_obstack);
7639 do_cleanups (back_to);
7643 /* Read the import statement specified by the given die and record it. */
7646 read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
7648 struct objfile *objfile = cu->objfile;
7649 struct attribute *import_attr;
7650 struct die_info *imported_die, *child_die;
7651 struct dwarf2_cu *imported_cu;
7652 const char *imported_name;
7653 const char *imported_name_prefix;
7654 const char *canonical_name;
7655 const char *import_alias;
7656 const char *imported_declaration = NULL;
7657 const char *import_prefix;
7658 VEC (const_char_ptr) *excludes = NULL;
7659 struct cleanup *cleanups;
7663 import_attr = dwarf2_attr (die, DW_AT_import, cu);
7664 if (import_attr == NULL)
7666 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
7667 dwarf_tag_name (die->tag));
7672 imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu);
7673 imported_name = dwarf2_name (imported_die, imported_cu);
7674 if (imported_name == NULL)
7676 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
7678 The import in the following code:
7692 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
7693 <52> DW_AT_decl_file : 1
7694 <53> DW_AT_decl_line : 6
7695 <54> DW_AT_import : <0x75>
7696 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
7698 <5b> DW_AT_decl_file : 1
7699 <5c> DW_AT_decl_line : 2
7700 <5d> DW_AT_type : <0x6e>
7702 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
7703 <76> DW_AT_byte_size : 4
7704 <77> DW_AT_encoding : 5 (signed)
7706 imports the wrong die ( 0x75 instead of 0x58 ).
7707 This case will be ignored until the gcc bug is fixed. */
7711 /* Figure out the local name after import. */
7712 import_alias = dwarf2_name (die, cu);
7714 /* Figure out where the statement is being imported to. */
7715 import_prefix = determine_prefix (die, cu);
7717 /* Figure out what the scope of the imported die is and prepend it
7718 to the name of the imported die. */
7719 imported_name_prefix = determine_prefix (imported_die, imported_cu);
7721 if (imported_die->tag != DW_TAG_namespace
7722 && imported_die->tag != DW_TAG_module)
7724 imported_declaration = imported_name;
7725 canonical_name = imported_name_prefix;
7727 else if (strlen (imported_name_prefix) > 0)
7729 temp = alloca (strlen (imported_name_prefix)
7730 + 2 + strlen (imported_name) + 1);
7731 strcpy (temp, imported_name_prefix);
7732 strcat (temp, "::");
7733 strcat (temp, imported_name);
7734 canonical_name = temp;
7737 canonical_name = imported_name;
7739 cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes);
7741 if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
7742 for (child_die = die->child; child_die && child_die->tag;
7743 child_die = sibling_die (child_die))
7745 /* DWARF-4: A Fortran use statement with a “rename list” may be
7746 represented by an imported module entry with an import attribute
7747 referring to the module and owned entries corresponding to those
7748 entities that are renamed as part of being imported. */
7750 if (child_die->tag != DW_TAG_imported_declaration)
7752 complaint (&symfile_complaints,
7753 _("child DW_TAG_imported_declaration expected "
7754 "- DIE at 0x%x [in module %s]"),
7755 child_die->offset.sect_off, objfile->name);
7759 import_attr = dwarf2_attr (child_die, DW_AT_import, cu);
7760 if (import_attr == NULL)
7762 complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"),
7763 dwarf_tag_name (child_die->tag));
7768 imported_die = follow_die_ref_or_sig (child_die, import_attr,
7770 imported_name = dwarf2_name (imported_die, imported_cu);
7771 if (imported_name == NULL)
7773 complaint (&symfile_complaints,
7774 _("child DW_TAG_imported_declaration has unknown "
7775 "imported name - DIE at 0x%x [in module %s]"),
7776 child_die->offset.sect_off, objfile->name);
7780 VEC_safe_push (const_char_ptr, excludes, imported_name);
7782 process_die (child_die, cu);
7785 cp_add_using_directive (import_prefix,
7788 imported_declaration,
7790 &objfile->objfile_obstack);
7792 do_cleanups (cleanups);
7795 /* Cleanup function for handle_DW_AT_stmt_list. */
7798 free_cu_line_header (void *arg)
7800 struct dwarf2_cu *cu = arg;
7802 free_line_header (cu->line_header);
7803 cu->line_header = NULL;
7807 find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu,
7808 char **name, char **comp_dir)
7810 struct attribute *attr;
7815 /* Find the filename. Do not use dwarf2_name here, since the filename
7816 is not a source language identifier. */
7817 attr = dwarf2_attr (die, DW_AT_name, cu);
7820 *name = DW_STRING (attr);
7823 attr = dwarf2_attr (die, DW_AT_comp_dir, cu);
7825 *comp_dir = DW_STRING (attr);
7826 else if (*name != NULL && IS_ABSOLUTE_PATH (*name))
7828 *comp_dir = ldirname (*name);
7829 if (*comp_dir != NULL)
7830 make_cleanup (xfree, *comp_dir);
7832 if (*comp_dir != NULL)
7834 /* Irix 6.2 native cc prepends <machine>.: to the compilation
7835 directory, get rid of it. */
7836 char *cp = strchr (*comp_dir, ':');
7838 if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/')
7843 *name = "<unknown>";
7846 /* Handle DW_AT_stmt_list for a compilation unit.
7847 DIE is the DW_TAG_compile_unit die for CU.
7848 COMP_DIR is the compilation directory.
7849 WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */
7852 handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
7853 const char *comp_dir)
7855 struct attribute *attr;
7857 gdb_assert (! cu->per_cu->is_debug_types);
7859 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
7862 unsigned int line_offset = DW_UNSND (attr);
7863 struct line_header *line_header
7864 = dwarf_decode_line_header (line_offset, cu);
7868 cu->line_header = line_header;
7869 make_cleanup (free_cu_line_header, cu);
7870 dwarf_decode_lines (line_header, comp_dir, cu, NULL, 1);
7875 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
7878 read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
7880 struct objfile *objfile = dwarf2_per_objfile->objfile;
7881 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
7882 CORE_ADDR lowpc = ((CORE_ADDR) -1);
7883 CORE_ADDR highpc = ((CORE_ADDR) 0);
7884 struct attribute *attr;
7886 char *comp_dir = NULL;
7887 struct die_info *child_die;
7888 bfd *abfd = objfile->obfd;
7891 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
7893 get_scope_pc_bounds (die, &lowpc, &highpc, cu);
7895 /* If we didn't find a lowpc, set it to highpc to avoid complaints
7896 from finish_block. */
7897 if (lowpc == ((CORE_ADDR) -1))
7902 find_file_and_directory (die, cu, &name, &comp_dir);
7904 prepare_one_comp_unit (cu, die, cu->language);
7906 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
7907 standardised yet. As a workaround for the language detection we fall
7908 back to the DW_AT_producer string. */
7909 if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
7910 cu->language = language_opencl;
7912 /* Similar hack for Go. */
7913 if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL)
7914 set_cu_language (DW_LANG_Go, cu);
7916 dwarf2_start_symtab (cu, name, comp_dir, lowpc);
7918 /* Decode line number information if present. We do this before
7919 processing child DIEs, so that the line header table is available
7920 for DW_AT_decl_file. */
7921 handle_DW_AT_stmt_list (die, cu, comp_dir);
7923 /* Process all dies in compilation unit. */
7924 if (die->child != NULL)
7926 child_die = die->child;
7927 while (child_die && child_die->tag)
7929 process_die (child_die, cu);
7930 child_die = sibling_die (child_die);
7934 /* Decode macro information, if present. Dwarf 2 macro information
7935 refers to information in the line number info statement program
7936 header, so we can only read it if we've read the header
7938 attr = dwarf2_attr (die, DW_AT_GNU_macros, cu);
7939 if (attr && cu->line_header)
7941 if (dwarf2_attr (die, DW_AT_macro_info, cu))
7942 complaint (&symfile_complaints,
7943 _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info"));
7945 dwarf_decode_macros (cu, DW_UNSND (attr), comp_dir, 1);
7949 attr = dwarf2_attr (die, DW_AT_macro_info, cu);
7950 if (attr && cu->line_header)
7952 unsigned int macro_offset = DW_UNSND (attr);
7954 dwarf_decode_macros (cu, macro_offset, comp_dir, 0);
7958 do_cleanups (back_to);
7961 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
7962 Create the set of symtabs used by this TU, or if this TU is sharing
7963 symtabs with another TU and the symtabs have already been created
7964 then restore those symtabs in the line header.
7965 We don't need the pc/line-number mapping for type units. */
7968 setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu)
7970 struct objfile *objfile = dwarf2_per_objfile->objfile;
7971 struct dwarf2_per_cu_data *per_cu = cu->per_cu;
7972 struct type_unit_group *tu_group;
7974 struct line_header *lh;
7975 struct attribute *attr;
7976 unsigned int i, line_offset;
7978 gdb_assert (per_cu->is_debug_types);
7980 attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
7982 /* If we're using .gdb_index (includes -readnow) then
7983 per_cu->s.type_unit_group may not have been set up yet. */
7984 if (per_cu->s.type_unit_group == NULL)
7985 per_cu->s.type_unit_group = get_type_unit_group (cu, attr);
7986 tu_group = per_cu->s.type_unit_group;
7988 /* If we've already processed this stmt_list there's no real need to
7989 do it again, we could fake it and just recreate the part we need
7990 (file name,index -> symtab mapping). If data shows this optimization
7991 is useful we can do it then. */
7992 first_time = tu_group->primary_symtab == NULL;
7994 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
7999 line_offset = DW_UNSND (attr);
8000 lh = dwarf_decode_line_header (line_offset, cu);
8005 dwarf2_start_symtab (cu, "", NULL, 0);
8008 gdb_assert (tu_group->symtabs == NULL);
8011 /* Note: The primary symtab will get allocated at the end. */
8015 cu->line_header = lh;
8016 make_cleanup (free_cu_line_header, cu);
8020 dwarf2_start_symtab (cu, "", NULL, 0);
8022 tu_group->num_symtabs = lh->num_file_names;
8023 tu_group->symtabs = XNEWVEC (struct symtab *, lh->num_file_names);
8025 for (i = 0; i < lh->num_file_names; ++i)
8028 struct file_entry *fe = &lh->file_names[i];
8031 dir = lh->include_dirs[fe->dir_index - 1];
8032 dwarf2_start_subfile (fe->name, dir, NULL);
8034 /* Note: We don't have to watch for the main subfile here, type units
8035 don't have DW_AT_name. */
8037 if (current_subfile->symtab == NULL)
8039 /* NOTE: start_subfile will recognize when it's been passed
8040 a file it has already seen. So we can't assume there's a
8041 simple mapping from lh->file_names to subfiles,
8042 lh->file_names may contain dups. */
8043 current_subfile->symtab = allocate_symtab (current_subfile->name,
8047 fe->symtab = current_subfile->symtab;
8048 tu_group->symtabs[i] = fe->symtab;
8055 for (i = 0; i < lh->num_file_names; ++i)
8057 struct file_entry *fe = &lh->file_names[i];
8059 fe->symtab = tu_group->symtabs[i];
8063 /* The main symtab is allocated last. Type units don't have DW_AT_name
8064 so they don't have a "real" (so to speak) symtab anyway.
8065 There is later code that will assign the main symtab to all symbols
8066 that don't have one. We need to handle the case of a symbol with a
8067 missing symtab (DW_AT_decl_file) anyway. */
8070 /* Process DW_TAG_type_unit.
8071 For TUs we want to skip the first top level sibling if it's not the
8072 actual type being defined by this TU. In this case the first top
8073 level sibling is there to provide context only. */
8076 read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
8078 struct die_info *child_die;
8080 prepare_one_comp_unit (cu, die, language_minimal);
8082 /* Initialize (or reinitialize) the machinery for building symtabs.
8083 We do this before processing child DIEs, so that the line header table
8084 is available for DW_AT_decl_file. */
8085 setup_type_unit_groups (die, cu);
8087 if (die->child != NULL)
8089 child_die = die->child;
8090 while (child_die && child_die->tag)
8092 process_die (child_die, cu);
8093 child_die = sibling_die (child_die);
8100 http://gcc.gnu.org/wiki/DebugFission
8101 http://gcc.gnu.org/wiki/DebugFissionDWP
8103 To simplify handling of both DWO files ("object" files with the DWARF info)
8104 and DWP files (a file with the DWOs packaged up into one file), we treat
8105 DWP files as having a collection of virtual DWO files. */
8108 hash_dwo_file (const void *item)
8110 const struct dwo_file *dwo_file = item;
8112 return htab_hash_string (dwo_file->name);
8116 eq_dwo_file (const void *item_lhs, const void *item_rhs)
8118 const struct dwo_file *lhs = item_lhs;
8119 const struct dwo_file *rhs = item_rhs;
8121 return strcmp (lhs->name, rhs->name) == 0;
8124 /* Allocate a hash table for DWO files. */
8127 allocate_dwo_file_hash_table (void)
8129 struct objfile *objfile = dwarf2_per_objfile->objfile;
8131 return htab_create_alloc_ex (41,
8135 &objfile->objfile_obstack,
8136 hashtab_obstack_allocate,
8137 dummy_obstack_deallocate);
8140 /* Lookup DWO file DWO_NAME. */
8143 lookup_dwo_file_slot (const char *dwo_name)
8145 struct dwo_file find_entry;
8148 if (dwarf2_per_objfile->dwo_files == NULL)
8149 dwarf2_per_objfile->dwo_files = allocate_dwo_file_hash_table ();
8151 memset (&find_entry, 0, sizeof (find_entry));
8152 find_entry.name = dwo_name;
8153 slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT);
8159 hash_dwo_unit (const void *item)
8161 const struct dwo_unit *dwo_unit = item;
8163 /* This drops the top 32 bits of the id, but is ok for a hash. */
8164 return dwo_unit->signature;
8168 eq_dwo_unit (const void *item_lhs, const void *item_rhs)
8170 const struct dwo_unit *lhs = item_lhs;
8171 const struct dwo_unit *rhs = item_rhs;
8173 /* The signature is assumed to be unique within the DWO file.
8174 So while object file CU dwo_id's always have the value zero,
8175 that's OK, assuming each object file DWO file has only one CU,
8176 and that's the rule for now. */
8177 return lhs->signature == rhs->signature;
8180 /* Allocate a hash table for DWO CUs,TUs.
8181 There is one of these tables for each of CUs,TUs for each DWO file. */
8184 allocate_dwo_unit_table (struct objfile *objfile)
8186 /* Start out with a pretty small number.
8187 Generally DWO files contain only one CU and maybe some TUs. */
8188 return htab_create_alloc_ex (3,
8192 &objfile->objfile_obstack,
8193 hashtab_obstack_allocate,
8194 dummy_obstack_deallocate);
8197 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
8199 struct create_dwo_info_table_data
8201 struct dwo_file *dwo_file;
8205 /* die_reader_func for create_dwo_debug_info_hash_table. */
8208 create_dwo_debug_info_hash_table_reader (const struct die_reader_specs *reader,
8210 struct die_info *comp_unit_die,
8214 struct dwarf2_cu *cu = reader->cu;
8215 struct objfile *objfile = dwarf2_per_objfile->objfile;
8216 sect_offset offset = cu->per_cu->offset;
8217 struct dwarf2_section_info *section = cu->per_cu->info_or_types_section;
8218 struct create_dwo_info_table_data *data = datap;
8219 struct dwo_file *dwo_file = data->dwo_file;
8220 htab_t cu_htab = data->cu_htab;
8222 struct attribute *attr;
8223 struct dwo_unit *dwo_unit;
8225 attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu);
8228 error (_("Dwarf Error: debug entry at offset 0x%x is missing"
8229 " its dwo_id [in module %s]"),
8230 offset.sect_off, dwo_file->name);
8234 dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit);
8235 dwo_unit->dwo_file = dwo_file;
8236 dwo_unit->signature = DW_UNSND (attr);
8237 dwo_unit->info_or_types_section = section;
8238 dwo_unit->offset = offset;
8239 dwo_unit->length = cu->per_cu->length;
8241 slot = htab_find_slot (cu_htab, dwo_unit, INSERT);
8242 gdb_assert (slot != NULL);
8245 const struct dwo_unit *dup_dwo_unit = *slot;
8247 complaint (&symfile_complaints,
8248 _("debug entry at offset 0x%x is duplicate to the entry at"
8249 " offset 0x%x, dwo_id 0x%s [in module %s]"),
8250 offset.sect_off, dup_dwo_unit->offset.sect_off,
8251 phex (dwo_unit->signature, sizeof (dwo_unit->signature)),
8257 if (dwarf2_read_debug)
8258 fprintf_unfiltered (gdb_stdlog, " offset 0x%x, dwo_id 0x%s\n",
8260 phex (dwo_unit->signature,
8261 sizeof (dwo_unit->signature)));
8264 /* Create a hash table to map DWO IDs to their CU entry in
8265 .debug_info.dwo in DWO_FILE.
8266 Note: This function processes DWO files only, not DWP files. */
8269 create_dwo_debug_info_hash_table (struct dwo_file *dwo_file)
8271 struct objfile *objfile = dwarf2_per_objfile->objfile;
8272 struct dwarf2_section_info *section = &dwo_file->sections.info;
8275 gdb_byte *info_ptr, *end_ptr;
8276 struct create_dwo_info_table_data create_dwo_info_table_data;
8278 dwarf2_read_section (objfile, section);
8279 info_ptr = section->buffer;
8281 if (info_ptr == NULL)
8284 /* We can't set abfd until now because the section may be empty or
8285 not present, in which case section->asection will be NULL. */
8286 abfd = section->asection->owner;
8288 if (dwarf2_read_debug)
8289 fprintf_unfiltered (gdb_stdlog, "Reading .debug_info.dwo for %s:\n",
8290 bfd_get_filename (abfd));
8292 cu_htab = allocate_dwo_unit_table (objfile);
8294 create_dwo_info_table_data.dwo_file = dwo_file;
8295 create_dwo_info_table_data.cu_htab = cu_htab;
8297 end_ptr = info_ptr + section->size;
8298 while (info_ptr < end_ptr)
8300 struct dwarf2_per_cu_data per_cu;
8302 memset (&per_cu, 0, sizeof (per_cu));
8303 per_cu.objfile = objfile;
8304 per_cu.is_debug_types = 0;
8305 per_cu.offset.sect_off = info_ptr - section->buffer;
8306 per_cu.info_or_types_section = section;
8308 init_cutu_and_read_dies_no_follow (&per_cu,
8309 &dwo_file->sections.abbrev,
8311 create_dwo_debug_info_hash_table_reader,
8312 &create_dwo_info_table_data);
8314 info_ptr += per_cu.length;
8320 /* DWP file .debug_{cu,tu}_index section format:
8321 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
8323 Both index sections have the same format, and serve to map a 64-bit
8324 signature to a set of section numbers. Each section begins with a header,
8325 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
8326 indexes, and a pool of 32-bit section numbers. The index sections will be
8327 aligned at 8-byte boundaries in the file.
8329 The index section header contains two unsigned 32-bit values (using the
8330 byte order of the application binary):
8332 N, the number of compilation units or type units in the index
8333 M, the number of slots in the hash table
8335 (We assume that N and M will not exceed 2^32 - 1.)
8337 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
8339 The hash table begins at offset 8 in the section, and consists of an array
8340 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
8341 order of the application binary). Unused slots in the hash table are 0.
8342 (We rely on the extreme unlikeliness of a signature being exactly 0.)
8344 The parallel table begins immediately after the hash table
8345 (at offset 8 + 8 * M from the beginning of the section), and consists of an
8346 array of 32-bit indexes (using the byte order of the application binary),
8347 corresponding 1-1 with slots in the hash table. Each entry in the parallel
8348 table contains a 32-bit index into the pool of section numbers. For unused
8349 hash table slots, the corresponding entry in the parallel table will be 0.
8351 Given a 64-bit compilation unit signature or a type signature S, an entry
8352 in the hash table is located as follows:
8354 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
8355 the low-order k bits all set to 1.
8357 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
8359 3) If the hash table entry at index H matches the signature, use that
8360 entry. If the hash table entry at index H is unused (all zeroes),
8361 terminate the search: the signature is not present in the table.
8363 4) Let H = (H + H') modulo M. Repeat at Step 3.
8365 Because M > N and H' and M are relatively prime, the search is guaranteed
8366 to stop at an unused slot or find the match.
8368 The pool of section numbers begins immediately following the hash table
8369 (at offset 8 + 12 * M from the beginning of the section). The pool of
8370 section numbers consists of an array of 32-bit words (using the byte order
8371 of the application binary). Each item in the array is indexed starting
8372 from 0. The hash table entry provides the index of the first section
8373 number in the set. Additional section numbers in the set follow, and the
8374 set is terminated by a 0 entry (section number 0 is not used in ELF).
8376 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
8377 section must be the first entry in the set, and the .debug_abbrev.dwo must
8378 be the second entry. Other members of the set may follow in any order. */
8380 /* Create a hash table to map DWO IDs to their CU/TU entry in
8381 .debug_{info,types}.dwo in DWP_FILE.
8382 Returns NULL if there isn't one.
8383 Note: This function processes DWP files only, not DWO files. */
8385 static struct dwp_hash_table *
8386 create_dwp_hash_table (struct dwp_file *dwp_file, int is_debug_types)
8388 struct objfile *objfile = dwarf2_per_objfile->objfile;
8389 bfd *dbfd = dwp_file->dbfd;
8390 char *index_ptr, *index_end;
8391 struct dwarf2_section_info *index;
8392 uint32_t version, nr_units, nr_slots;
8393 struct dwp_hash_table *htab;
8396 index = &dwp_file->sections.tu_index;
8398 index = &dwp_file->sections.cu_index;
8400 if (dwarf2_section_empty_p (index))
8402 dwarf2_read_section (objfile, index);
8404 index_ptr = index->buffer;
8405 index_end = index_ptr + index->size;
8407 version = read_4_bytes (dbfd, index_ptr);
8408 index_ptr += 8; /* Skip the unused word. */
8409 nr_units = read_4_bytes (dbfd, index_ptr);
8411 nr_slots = read_4_bytes (dbfd, index_ptr);
8416 error (_("Dwarf Error: unsupported DWP file version (%u)"
8418 version, dwp_file->name);
8420 if (nr_slots != (nr_slots & -nr_slots))
8422 error (_("Dwarf Error: number of slots in DWP hash table (%u)"
8423 " is not power of 2 [in module %s]"),
8424 nr_slots, dwp_file->name);
8427 htab = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_hash_table);
8428 htab->nr_units = nr_units;
8429 htab->nr_slots = nr_slots;
8430 htab->hash_table = index_ptr;
8431 htab->unit_table = htab->hash_table + sizeof (uint64_t) * nr_slots;
8432 htab->section_pool = htab->unit_table + sizeof (uint32_t) * nr_slots;
8437 /* Update SECTIONS with the data from SECTP.
8439 This function is like the other "locate" section routines that are
8440 passed to bfd_map_over_sections, but in this context the sections to
8441 read comes from the DWP hash table, not the full ELF section table.
8443 The result is non-zero for success, or zero if an error was found. */
8446 locate_virtual_dwo_sections (asection *sectp,
8447 struct virtual_dwo_sections *sections)
8449 const struct dwop_section_names *names = &dwop_section_names;
8451 if (section_is_p (sectp->name, &names->abbrev_dwo))
8453 /* There can be only one. */
8454 if (sections->abbrev.asection != NULL)
8456 sections->abbrev.asection = sectp;
8457 sections->abbrev.size = bfd_get_section_size (sectp);
8459 else if (section_is_p (sectp->name, &names->info_dwo)
8460 || section_is_p (sectp->name, &names->types_dwo))
8462 /* There can be only one. */
8463 if (sections->info_or_types.asection != NULL)
8465 sections->info_or_types.asection = sectp;
8466 sections->info_or_types.size = bfd_get_section_size (sectp);
8468 else if (section_is_p (sectp->name, &names->line_dwo))
8470 /* There can be only one. */
8471 if (sections->line.asection != NULL)
8473 sections->line.asection = sectp;
8474 sections->line.size = bfd_get_section_size (sectp);
8476 else if (section_is_p (sectp->name, &names->loc_dwo))
8478 /* There can be only one. */
8479 if (sections->loc.asection != NULL)
8481 sections->loc.asection = sectp;
8482 sections->loc.size = bfd_get_section_size (sectp);
8484 else if (section_is_p (sectp->name, &names->macinfo_dwo))
8486 /* There can be only one. */
8487 if (sections->macinfo.asection != NULL)
8489 sections->macinfo.asection = sectp;
8490 sections->macinfo.size = bfd_get_section_size (sectp);
8492 else if (section_is_p (sectp->name, &names->macro_dwo))
8494 /* There can be only one. */
8495 if (sections->macro.asection != NULL)
8497 sections->macro.asection = sectp;
8498 sections->macro.size = bfd_get_section_size (sectp);
8500 else if (section_is_p (sectp->name, &names->str_offsets_dwo))
8502 /* There can be only one. */
8503 if (sections->str_offsets.asection != NULL)
8505 sections->str_offsets.asection = sectp;
8506 sections->str_offsets.size = bfd_get_section_size (sectp);
8510 /* No other kind of section is valid. */
8517 /* Create a dwo_unit object for the DWO with signature SIGNATURE.
8518 HTAB is the hash table from the DWP file.
8519 SECTION_INDEX is the index of the DWO in HTAB. */
8521 static struct dwo_unit *
8522 create_dwo_in_dwp (struct dwp_file *dwp_file,
8523 const struct dwp_hash_table *htab,
8524 uint32_t section_index,
8525 ULONGEST signature, int is_debug_types)
8527 struct objfile *objfile = dwarf2_per_objfile->objfile;
8528 bfd *dbfd = dwp_file->dbfd;
8529 const char *kind = is_debug_types ? "TU" : "CU";
8530 struct dwo_file *dwo_file;
8531 struct dwo_unit *dwo_unit;
8532 struct virtual_dwo_sections sections;
8533 void **dwo_file_slot;
8534 char *virtual_dwo_name;
8535 struct dwarf2_section_info *cutu;
8536 struct cleanup *cleanups;
8539 if (dwarf2_read_debug)
8541 fprintf_unfiltered (gdb_stdlog, "Reading %s %u/0x%s in DWP file: %s\n",
8543 section_index, phex (signature, sizeof (signature)),
8547 /* Fetch the sections of this DWO.
8548 Put a limit on the number of sections we look for so that bad data
8549 doesn't cause us to loop forever. */
8551 #define MAX_NR_DWO_SECTIONS \
8552 (1 /* .debug_info or .debug_types */ \
8553 + 1 /* .debug_abbrev */ \
8554 + 1 /* .debug_line */ \
8555 + 1 /* .debug_loc */ \
8556 + 1 /* .debug_str_offsets */ \
8557 + 1 /* .debug_macro */ \
8558 + 1 /* .debug_macinfo */ \
8559 + 1 /* trailing zero */)
8561 memset (§ions, 0, sizeof (sections));
8562 cleanups = make_cleanup (null_cleanup, 0);
8564 for (i = 0; i < MAX_NR_DWO_SECTIONS; ++i)
8567 uint32_t section_nr =
8570 + (section_index + i) * sizeof (uint32_t));
8572 if (section_nr == 0)
8574 if (section_nr >= dwp_file->num_sections)
8576 error (_("Dwarf Error: bad DWP hash table, section number too large"
8581 sectp = dwp_file->elf_sections[section_nr];
8582 if (! locate_virtual_dwo_sections (sectp, §ions))
8584 error (_("Dwarf Error: bad DWP hash table, invalid section found"
8591 || sections.info_or_types.asection == NULL
8592 || sections.abbrev.asection == NULL)
8594 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
8598 if (i == MAX_NR_DWO_SECTIONS)
8600 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
8605 /* It's easier for the rest of the code if we fake a struct dwo_file and
8606 have dwo_unit "live" in that. At least for now.
8608 The DWP file can be made up of a random collection of CUs and TUs.
8609 However, for each CU + set of TUs that came from the same original
8610 DWO file, we want combine them back into a virtual DWO file to save space
8611 (fewer struct dwo_file objects to allocated). Remember that for really
8612 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
8615 xstrprintf ("virtual-dwo/%d-%d-%d-%d",
8616 sections.abbrev.asection ? sections.abbrev.asection->id : 0,
8617 sections.line.asection ? sections.line.asection->id : 0,
8618 sections.loc.asection ? sections.loc.asection->id : 0,
8619 (sections.str_offsets.asection
8620 ? sections.str_offsets.asection->id
8622 make_cleanup (xfree, virtual_dwo_name);
8623 /* Can we use an existing virtual DWO file? */
8624 dwo_file_slot = lookup_dwo_file_slot (virtual_dwo_name);
8625 /* Create one if necessary. */
8626 if (*dwo_file_slot == NULL)
8628 if (dwarf2_read_debug)
8630 fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n",
8633 dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
8634 dwo_file->name = obstack_copy0 (&objfile->objfile_obstack,
8636 strlen (virtual_dwo_name));
8637 dwo_file->sections.abbrev = sections.abbrev;
8638 dwo_file->sections.line = sections.line;
8639 dwo_file->sections.loc = sections.loc;
8640 dwo_file->sections.macinfo = sections.macinfo;
8641 dwo_file->sections.macro = sections.macro;
8642 dwo_file->sections.str_offsets = sections.str_offsets;
8643 /* The "str" section is global to the entire DWP file. */
8644 dwo_file->sections.str = dwp_file->sections.str;
8645 /* The info or types section is assigned later to dwo_unit,
8646 there's no need to record it in dwo_file.
8647 Also, we can't simply record type sections in dwo_file because
8648 we record a pointer into the vector in dwo_unit. As we collect more
8649 types we'll grow the vector and eventually have to reallocate space
8650 for it, invalidating all the pointers into the current copy. */
8651 *dwo_file_slot = dwo_file;
8655 if (dwarf2_read_debug)
8657 fprintf_unfiltered (gdb_stdlog, "Using existing virtual DWO: %s\n",
8660 dwo_file = *dwo_file_slot;
8662 do_cleanups (cleanups);
8664 dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit);
8665 dwo_unit->dwo_file = dwo_file;
8666 dwo_unit->signature = signature;
8667 dwo_unit->info_or_types_section =
8668 obstack_alloc (&objfile->objfile_obstack,
8669 sizeof (struct dwarf2_section_info));
8670 *dwo_unit->info_or_types_section = sections.info_or_types;
8671 /* offset, length, type_offset_in_tu are set later. */
8676 /* Lookup the DWO with SIGNATURE in DWP_FILE. */
8678 static struct dwo_unit *
8679 lookup_dwo_in_dwp (struct dwp_file *dwp_file,
8680 const struct dwp_hash_table *htab,
8681 ULONGEST signature, int is_debug_types)
8683 bfd *dbfd = dwp_file->dbfd;
8684 uint32_t mask = htab->nr_slots - 1;
8685 uint32_t hash = signature & mask;
8686 uint32_t hash2 = ((signature >> 32) & mask) | 1;
8689 struct dwo_unit find_dwo_cu, *dwo_cu;
8691 memset (&find_dwo_cu, 0, sizeof (find_dwo_cu));
8692 find_dwo_cu.signature = signature;
8693 slot = htab_find_slot (dwp_file->loaded_cutus, &find_dwo_cu, INSERT);
8698 /* Use a for loop so that we don't loop forever on bad debug info. */
8699 for (i = 0; i < htab->nr_slots; ++i)
8701 ULONGEST signature_in_table;
8703 signature_in_table =
8704 read_8_bytes (dbfd, htab->hash_table + hash * sizeof (uint64_t));
8705 if (signature_in_table == signature)
8707 uint32_t section_index =
8708 read_4_bytes (dbfd, htab->unit_table + hash * sizeof (uint32_t));
8710 *slot = create_dwo_in_dwp (dwp_file, htab, section_index,
8711 signature, is_debug_types);
8714 if (signature_in_table == 0)
8716 hash = (hash + hash2) & mask;
8719 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
8724 /* Subroutine of open_dwop_file to simplify it.
8725 Open the file specified by FILE_NAME and hand it off to BFD for
8726 preliminary analysis. Return a newly initialized bfd *, which
8727 includes a canonicalized copy of FILE_NAME.
8728 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8729 In case of trouble, return NULL.
8730 NOTE: This function is derived from symfile_bfd_open. */
8733 try_open_dwop_file (const char *file_name, int is_dwp)
8737 char *absolute_name;
8739 flags = OPF_TRY_CWD_FIRST;
8741 flags |= OPF_SEARCH_IN_PATH;
8742 desc = openp (debug_file_directory, flags, file_name,
8743 O_RDONLY | O_BINARY, &absolute_name);
8747 sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc);
8750 xfree (absolute_name);
8753 xfree (absolute_name);
8754 bfd_set_cacheable (sym_bfd, 1);
8756 if (!bfd_check_format (sym_bfd, bfd_object))
8758 gdb_bfd_unref (sym_bfd); /* This also closes desc. */
8765 /* Try to open DWO/DWP file FILE_NAME.
8766 COMP_DIR is the DW_AT_comp_dir attribute.
8767 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
8768 The result is the bfd handle of the file.
8769 If there is a problem finding or opening the file, return NULL.
8770 Upon success, the canonicalized path of the file is stored in the bfd,
8771 same as symfile_bfd_open. */
8774 open_dwop_file (const char *file_name, const char *comp_dir, int is_dwp)
8778 if (IS_ABSOLUTE_PATH (file_name))
8779 return try_open_dwop_file (file_name, is_dwp);
8781 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
8783 if (comp_dir != NULL)
8785 char *path_to_try = concat (comp_dir, SLASH_STRING, file_name, NULL);
8787 /* NOTE: If comp_dir is a relative path, this will also try the
8788 search path, which seems useful. */
8789 abfd = try_open_dwop_file (path_to_try, is_dwp);
8790 xfree (path_to_try);
8795 /* That didn't work, try debug-file-directory, which, despite its name,
8796 is a list of paths. */
8798 if (*debug_file_directory == '\0')
8801 return try_open_dwop_file (file_name, is_dwp);
8804 /* This function is mapped across the sections and remembers the offset and
8805 size of each of the DWO debugging sections we are interested in. */
8808 dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr)
8810 struct dwo_sections *dwo_sections = dwo_sections_ptr;
8811 const struct dwop_section_names *names = &dwop_section_names;
8813 if (section_is_p (sectp->name, &names->abbrev_dwo))
8815 dwo_sections->abbrev.asection = sectp;
8816 dwo_sections->abbrev.size = bfd_get_section_size (sectp);
8818 else if (section_is_p (sectp->name, &names->info_dwo))
8820 dwo_sections->info.asection = sectp;
8821 dwo_sections->info.size = bfd_get_section_size (sectp);
8823 else if (section_is_p (sectp->name, &names->line_dwo))
8825 dwo_sections->line.asection = sectp;
8826 dwo_sections->line.size = bfd_get_section_size (sectp);
8828 else if (section_is_p (sectp->name, &names->loc_dwo))
8830 dwo_sections->loc.asection = sectp;
8831 dwo_sections->loc.size = bfd_get_section_size (sectp);
8833 else if (section_is_p (sectp->name, &names->macinfo_dwo))
8835 dwo_sections->macinfo.asection = sectp;
8836 dwo_sections->macinfo.size = bfd_get_section_size (sectp);
8838 else if (section_is_p (sectp->name, &names->macro_dwo))
8840 dwo_sections->macro.asection = sectp;
8841 dwo_sections->macro.size = bfd_get_section_size (sectp);
8843 else if (section_is_p (sectp->name, &names->str_dwo))
8845 dwo_sections->str.asection = sectp;
8846 dwo_sections->str.size = bfd_get_section_size (sectp);
8848 else if (section_is_p (sectp->name, &names->str_offsets_dwo))
8850 dwo_sections->str_offsets.asection = sectp;
8851 dwo_sections->str_offsets.size = bfd_get_section_size (sectp);
8853 else if (section_is_p (sectp->name, &names->types_dwo))
8855 struct dwarf2_section_info type_section;
8857 memset (&type_section, 0, sizeof (type_section));
8858 type_section.asection = sectp;
8859 type_section.size = bfd_get_section_size (sectp);
8860 VEC_safe_push (dwarf2_section_info_def, dwo_sections->types,
8865 /* Initialize the use of the DWO file specified by DWO_NAME.
8866 The result is NULL if DWO_NAME can't be found. */
8868 static struct dwo_file *
8869 open_and_init_dwo_file (const char *dwo_name, const char *comp_dir)
8871 struct objfile *objfile = dwarf2_per_objfile->objfile;
8872 struct dwo_file *dwo_file;
8874 struct cleanup *cleanups;
8876 dbfd = open_dwop_file (dwo_name, comp_dir, 0);
8879 if (dwarf2_read_debug)
8880 fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name);
8883 dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
8884 dwo_file->name = obstack_copy0 (&objfile->objfile_obstack,
8885 dwo_name, strlen (dwo_name));
8886 dwo_file->dbfd = dbfd;
8888 cleanups = make_cleanup (free_dwo_file_cleanup, dwo_file);
8890 bfd_map_over_sections (dbfd, dwarf2_locate_dwo_sections, &dwo_file->sections);
8892 dwo_file->cus = create_dwo_debug_info_hash_table (dwo_file);
8894 dwo_file->tus = create_debug_types_hash_table (dwo_file,
8895 dwo_file->sections.types);
8897 discard_cleanups (cleanups);
8899 if (dwarf2_read_debug)
8900 fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name);
8905 /* This function is mapped across the sections and remembers the offset and
8906 size of each of the DWP debugging sections we are interested in. */
8909 dwarf2_locate_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_ptr)
8911 struct dwp_file *dwp_file = dwp_file_ptr;
8912 const struct dwop_section_names *names = &dwop_section_names;
8913 unsigned int elf_section_nr = elf_section_data (sectp)->this_idx;
8915 /* Record the ELF section number for later lookup: this is what the
8916 .debug_cu_index,.debug_tu_index tables use. */
8917 gdb_assert (elf_section_nr < dwp_file->num_sections);
8918 dwp_file->elf_sections[elf_section_nr] = sectp;
8920 /* Look for specific sections that we need. */
8921 if (section_is_p (sectp->name, &names->str_dwo))
8923 dwp_file->sections.str.asection = sectp;
8924 dwp_file->sections.str.size = bfd_get_section_size (sectp);
8926 else if (section_is_p (sectp->name, &names->cu_index))
8928 dwp_file->sections.cu_index.asection = sectp;
8929 dwp_file->sections.cu_index.size = bfd_get_section_size (sectp);
8931 else if (section_is_p (sectp->name, &names->tu_index))
8933 dwp_file->sections.tu_index.asection = sectp;
8934 dwp_file->sections.tu_index.size = bfd_get_section_size (sectp);
8938 /* Hash function for dwp_file loaded CUs/TUs. */
8941 hash_dwp_loaded_cutus (const void *item)
8943 const struct dwo_unit *dwo_unit = item;
8945 /* This drops the top 32 bits of the signature, but is ok for a hash. */
8946 return dwo_unit->signature;
8949 /* Equality function for dwp_file loaded CUs/TUs. */
8952 eq_dwp_loaded_cutus (const void *a, const void *b)
8954 const struct dwo_unit *dua = a;
8955 const struct dwo_unit *dub = b;
8957 return dua->signature == dub->signature;
8960 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
8963 allocate_dwp_loaded_cutus_table (struct objfile *objfile)
8965 return htab_create_alloc_ex (3,
8966 hash_dwp_loaded_cutus,
8967 eq_dwp_loaded_cutus,
8969 &objfile->objfile_obstack,
8970 hashtab_obstack_allocate,
8971 dummy_obstack_deallocate);
8974 /* Initialize the use of the DWP file for the current objfile.
8975 By convention the name of the DWP file is ${objfile}.dwp.
8976 The result is NULL if it can't be found. */
8978 static struct dwp_file *
8979 open_and_init_dwp_file (const char *comp_dir)
8981 struct objfile *objfile = dwarf2_per_objfile->objfile;
8982 struct dwp_file *dwp_file;
8985 struct cleanup *cleanups;
8987 dwp_name = xstrprintf ("%s.dwp", dwarf2_per_objfile->objfile->name);
8988 cleanups = make_cleanup (xfree, dwp_name);
8990 dbfd = open_dwop_file (dwp_name, comp_dir, 1);
8993 if (dwarf2_read_debug)
8994 fprintf_unfiltered (gdb_stdlog, "DWP file not found: %s\n", dwp_name);
8995 do_cleanups (cleanups);
8998 dwp_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_file);
8999 dwp_file->name = obstack_copy0 (&objfile->objfile_obstack,
9000 dwp_name, strlen (dwp_name));
9001 dwp_file->dbfd = dbfd;
9002 do_cleanups (cleanups);
9004 cleanups = make_cleanup (free_dwo_file_cleanup, dwp_file);
9006 /* +1: section 0 is unused */
9007 dwp_file->num_sections = bfd_count_sections (dbfd) + 1;
9008 dwp_file->elf_sections =
9009 OBSTACK_CALLOC (&objfile->objfile_obstack,
9010 dwp_file->num_sections, asection *);
9012 bfd_map_over_sections (dbfd, dwarf2_locate_dwp_sections, dwp_file);
9014 dwp_file->cus = create_dwp_hash_table (dwp_file, 0);
9016 dwp_file->tus = create_dwp_hash_table (dwp_file, 1);
9018 dwp_file->loaded_cutus = allocate_dwp_loaded_cutus_table (objfile);
9020 discard_cleanups (cleanups);
9022 if (dwarf2_read_debug)
9024 fprintf_unfiltered (gdb_stdlog, "DWP file found: %s\n", dwp_file->name);
9025 fprintf_unfiltered (gdb_stdlog,
9026 " %u CUs, %u TUs\n",
9027 dwp_file->cus ? dwp_file->cus->nr_units : 0,
9028 dwp_file->tus ? dwp_file->tus->nr_units : 0);
9034 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
9035 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
9036 or in the DWP file for the objfile, referenced by THIS_UNIT.
9037 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
9038 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
9040 This is called, for example, when wanting to read a variable with a
9041 complex location. Therefore we don't want to do file i/o for every call.
9042 Therefore we don't want to look for a DWO file on every call.
9043 Therefore we first see if we've already seen SIGNATURE in a DWP file,
9044 then we check if we've already seen DWO_NAME, and only THEN do we check
9047 The result is a pointer to the dwo_unit object or NULL if we didn't find it
9048 (dwo_id mismatch or couldn't find the DWO/DWP file). */
9050 static struct dwo_unit *
9051 lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
9052 const char *dwo_name, const char *comp_dir,
9053 ULONGEST signature, int is_debug_types)
9055 struct objfile *objfile = dwarf2_per_objfile->objfile;
9056 const char *kind = is_debug_types ? "TU" : "CU";
9057 void **dwo_file_slot;
9058 struct dwo_file *dwo_file;
9059 struct dwp_file *dwp_file;
9061 /* Have we already read SIGNATURE from a DWP file? */
9063 if (! dwarf2_per_objfile->dwp_checked)
9065 dwarf2_per_objfile->dwp_file = open_and_init_dwp_file (comp_dir);
9066 dwarf2_per_objfile->dwp_checked = 1;
9068 dwp_file = dwarf2_per_objfile->dwp_file;
9070 if (dwp_file != NULL)
9072 const struct dwp_hash_table *dwp_htab =
9073 is_debug_types ? dwp_file->tus : dwp_file->cus;
9075 if (dwp_htab != NULL)
9077 struct dwo_unit *dwo_cutu =
9078 lookup_dwo_in_dwp (dwp_file, dwp_htab, signature, is_debug_types);
9080 if (dwo_cutu != NULL)
9082 if (dwarf2_read_debug)
9084 fprintf_unfiltered (gdb_stdlog,
9085 "Virtual DWO %s %s found: @%s\n",
9086 kind, hex_string (signature),
9087 host_address_to_string (dwo_cutu));
9094 /* Have we already seen DWO_NAME? */
9096 dwo_file_slot = lookup_dwo_file_slot (dwo_name);
9097 if (*dwo_file_slot == NULL)
9099 /* Read in the file and build a table of the DWOs it contains. */
9100 *dwo_file_slot = open_and_init_dwo_file (dwo_name, comp_dir);
9102 /* NOTE: This will be NULL if unable to open the file. */
9103 dwo_file = *dwo_file_slot;
9105 if (dwo_file != NULL)
9107 htab_t htab = is_debug_types ? dwo_file->tus : dwo_file->cus;
9111 struct dwo_unit find_dwo_cutu, *dwo_cutu;
9113 memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
9114 find_dwo_cutu.signature = signature;
9115 dwo_cutu = htab_find (htab, &find_dwo_cutu);
9117 if (dwo_cutu != NULL)
9119 if (dwarf2_read_debug)
9121 fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) found: @%s\n",
9122 kind, dwo_name, hex_string (signature),
9123 host_address_to_string (dwo_cutu));
9130 /* We didn't find it. This could mean a dwo_id mismatch, or
9131 someone deleted the DWO/DWP file, or the search path isn't set up
9132 correctly to find the file. */
9134 if (dwarf2_read_debug)
9136 fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) not found\n",
9137 kind, dwo_name, hex_string (signature));
9140 complaint (&symfile_complaints,
9141 _("Could not find DWO CU referenced by CU at offset 0x%x"
9143 this_unit->offset.sect_off, objfile->name);
9147 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
9148 See lookup_dwo_cutu_unit for details. */
9150 static struct dwo_unit *
9151 lookup_dwo_comp_unit (struct dwarf2_per_cu_data *this_cu,
9152 const char *dwo_name, const char *comp_dir,
9155 return lookup_dwo_cutu (this_cu, dwo_name, comp_dir, signature, 0);
9158 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
9159 See lookup_dwo_cutu_unit for details. */
9161 static struct dwo_unit *
9162 lookup_dwo_type_unit (struct signatured_type *this_tu,
9163 const char *dwo_name, const char *comp_dir)
9165 return lookup_dwo_cutu (&this_tu->per_cu, dwo_name, comp_dir, this_tu->signature, 1);
9168 /* Free all resources associated with DWO_FILE.
9169 Close the DWO file and munmap the sections.
9170 All memory should be on the objfile obstack. */
9173 free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile)
9176 struct dwarf2_section_info *section;
9178 gdb_assert (dwo_file->dbfd != objfile->obfd);
9179 gdb_bfd_unref (dwo_file->dbfd);
9181 VEC_free (dwarf2_section_info_def, dwo_file->sections.types);
9184 /* Wrapper for free_dwo_file for use in cleanups. */
9187 free_dwo_file_cleanup (void *arg)
9189 struct dwo_file *dwo_file = (struct dwo_file *) arg;
9190 struct objfile *objfile = dwarf2_per_objfile->objfile;
9192 free_dwo_file (dwo_file, objfile);
9195 /* Traversal function for free_dwo_files. */
9198 free_dwo_file_from_slot (void **slot, void *info)
9200 struct dwo_file *dwo_file = (struct dwo_file *) *slot;
9201 struct objfile *objfile = (struct objfile *) info;
9203 free_dwo_file (dwo_file, objfile);
9208 /* Free all resources associated with DWO_FILES. */
9211 free_dwo_files (htab_t dwo_files, struct objfile *objfile)
9213 htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile);
9216 /* Read in various DIEs. */
9218 /* qsort helper for inherit_abstract_dies. */
9221 unsigned_int_compar (const void *ap, const void *bp)
9223 unsigned int a = *(unsigned int *) ap;
9224 unsigned int b = *(unsigned int *) bp;
9226 return (a > b) - (b > a);
9229 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
9230 Inherit only the children of the DW_AT_abstract_origin DIE not being
9231 already referenced by DW_AT_abstract_origin from the children of the
9235 inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
9237 struct die_info *child_die;
9238 unsigned die_children_count;
9239 /* CU offsets which were referenced by children of the current DIE. */
9240 sect_offset *offsets;
9241 sect_offset *offsets_end, *offsetp;
9242 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
9243 struct die_info *origin_die;
9244 /* Iterator of the ORIGIN_DIE children. */
9245 struct die_info *origin_child_die;
9246 struct cleanup *cleanups;
9247 struct attribute *attr;
9248 struct dwarf2_cu *origin_cu;
9249 struct pending **origin_previous_list_in_scope;
9251 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
9255 /* Note that following die references may follow to a die in a
9259 origin_die = follow_die_ref (die, attr, &origin_cu);
9261 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
9263 origin_previous_list_in_scope = origin_cu->list_in_scope;
9264 origin_cu->list_in_scope = cu->list_in_scope;
9266 if (die->tag != origin_die->tag
9267 && !(die->tag == DW_TAG_inlined_subroutine
9268 && origin_die->tag == DW_TAG_subprogram))
9269 complaint (&symfile_complaints,
9270 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
9271 die->offset.sect_off, origin_die->offset.sect_off);
9273 child_die = die->child;
9274 die_children_count = 0;
9275 while (child_die && child_die->tag)
9277 child_die = sibling_die (child_die);
9278 die_children_count++;
9280 offsets = xmalloc (sizeof (*offsets) * die_children_count);
9281 cleanups = make_cleanup (xfree, offsets);
9283 offsets_end = offsets;
9284 child_die = die->child;
9285 while (child_die && child_die->tag)
9287 /* For each CHILD_DIE, find the corresponding child of
9288 ORIGIN_DIE. If there is more than one layer of
9289 DW_AT_abstract_origin, follow them all; there shouldn't be,
9290 but GCC versions at least through 4.4 generate this (GCC PR
9292 struct die_info *child_origin_die = child_die;
9293 struct dwarf2_cu *child_origin_cu = cu;
9297 attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin,
9301 child_origin_die = follow_die_ref (child_origin_die, attr,
9305 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
9306 counterpart may exist. */
9307 if (child_origin_die != child_die)
9309 if (child_die->tag != child_origin_die->tag
9310 && !(child_die->tag == DW_TAG_inlined_subroutine
9311 && child_origin_die->tag == DW_TAG_subprogram))
9312 complaint (&symfile_complaints,
9313 _("Child DIE 0x%x and its abstract origin 0x%x have "
9314 "different tags"), child_die->offset.sect_off,
9315 child_origin_die->offset.sect_off);
9316 if (child_origin_die->parent != origin_die)
9317 complaint (&symfile_complaints,
9318 _("Child DIE 0x%x and its abstract origin 0x%x have "
9319 "different parents"), child_die->offset.sect_off,
9320 child_origin_die->offset.sect_off);
9322 *offsets_end++ = child_origin_die->offset;
9324 child_die = sibling_die (child_die);
9326 qsort (offsets, offsets_end - offsets, sizeof (*offsets),
9327 unsigned_int_compar);
9328 for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++)
9329 if (offsetp[-1].sect_off == offsetp->sect_off)
9330 complaint (&symfile_complaints,
9331 _("Multiple children of DIE 0x%x refer "
9332 "to DIE 0x%x as their abstract origin"),
9333 die->offset.sect_off, offsetp->sect_off);
9336 origin_child_die = origin_die->child;
9337 while (origin_child_die && origin_child_die->tag)
9339 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
9340 while (offsetp < offsets_end
9341 && offsetp->sect_off < origin_child_die->offset.sect_off)
9343 if (offsetp >= offsets_end
9344 || offsetp->sect_off > origin_child_die->offset.sect_off)
9346 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
9347 process_die (origin_child_die, origin_cu);
9349 origin_child_die = sibling_die (origin_child_die);
9351 origin_cu->list_in_scope = origin_previous_list_in_scope;
9353 do_cleanups (cleanups);
9357 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
9359 struct objfile *objfile = cu->objfile;
9360 struct context_stack *new;
9363 struct die_info *child_die;
9364 struct attribute *attr, *call_line, *call_file;
9367 struct block *block;
9368 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
9369 VEC (symbolp) *template_args = NULL;
9370 struct template_symbol *templ_func = NULL;
9374 /* If we do not have call site information, we can't show the
9375 caller of this inlined function. That's too confusing, so
9376 only use the scope for local variables. */
9377 call_line = dwarf2_attr (die, DW_AT_call_line, cu);
9378 call_file = dwarf2_attr (die, DW_AT_call_file, cu);
9379 if (call_line == NULL || call_file == NULL)
9381 read_lexical_block_scope (die, cu);
9386 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9388 name = dwarf2_name (die, cu);
9390 /* Ignore functions with missing or empty names. These are actually
9391 illegal according to the DWARF standard. */
9394 complaint (&symfile_complaints,
9395 _("missing name for subprogram DIE at %d"),
9396 die->offset.sect_off);
9400 /* Ignore functions with missing or invalid low and high pc attributes. */
9401 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
9403 attr = dwarf2_attr (die, DW_AT_external, cu);
9404 if (!attr || !DW_UNSND (attr))
9405 complaint (&symfile_complaints,
9406 _("cannot get low and high bounds "
9407 "for subprogram DIE at %d"),
9408 die->offset.sect_off);
9415 /* If we have any template arguments, then we must allocate a
9416 different sort of symbol. */
9417 for (child_die = die->child; child_die; child_die = sibling_die (child_die))
9419 if (child_die->tag == DW_TAG_template_type_param
9420 || child_die->tag == DW_TAG_template_value_param)
9422 templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack,
9423 struct template_symbol);
9424 templ_func->base.is_cplus_template_function = 1;
9429 new = push_context (0, lowpc);
9430 new->name = new_symbol_full (die, read_type_die (die, cu), cu,
9431 (struct symbol *) templ_func);
9433 /* If there is a location expression for DW_AT_frame_base, record
9435 attr = dwarf2_attr (die, DW_AT_frame_base, cu);
9437 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
9438 expression is being recorded directly in the function's symbol
9439 and not in a separate frame-base object. I guess this hack is
9440 to avoid adding some sort of frame-base adjunct/annex to the
9441 function's symbol :-(. The problem with doing this is that it
9442 results in a function symbol with a location expression that
9443 has nothing to do with the location of the function, ouch! The
9444 relationship should be: a function's symbol has-a frame base; a
9445 frame-base has-a location expression. */
9446 dwarf2_symbol_mark_computed (attr, new->name, cu);
9448 cu->list_in_scope = &local_symbols;
9450 if (die->child != NULL)
9452 child_die = die->child;
9453 while (child_die && child_die->tag)
9455 if (child_die->tag == DW_TAG_template_type_param
9456 || child_die->tag == DW_TAG_template_value_param)
9458 struct symbol *arg = new_symbol (child_die, NULL, cu);
9461 VEC_safe_push (symbolp, template_args, arg);
9464 process_die (child_die, cu);
9465 child_die = sibling_die (child_die);
9469 inherit_abstract_dies (die, cu);
9471 /* If we have a DW_AT_specification, we might need to import using
9472 directives from the context of the specification DIE. See the
9473 comment in determine_prefix. */
9474 if (cu->language == language_cplus
9475 && dwarf2_attr (die, DW_AT_specification, cu))
9477 struct dwarf2_cu *spec_cu = cu;
9478 struct die_info *spec_die = die_specification (die, &spec_cu);
9482 child_die = spec_die->child;
9483 while (child_die && child_die->tag)
9485 if (child_die->tag == DW_TAG_imported_module)
9486 process_die (child_die, spec_cu);
9487 child_die = sibling_die (child_die);
9490 /* In some cases, GCC generates specification DIEs that
9491 themselves contain DW_AT_specification attributes. */
9492 spec_die = die_specification (spec_die, &spec_cu);
9496 new = pop_context ();
9497 /* Make a block for the local symbols within. */
9498 block = finish_block (new->name, &local_symbols, new->old_blocks,
9499 lowpc, highpc, objfile);
9501 /* For C++, set the block's scope. */
9502 if (cu->language == language_cplus || cu->language == language_fortran)
9503 cp_set_block_scope (new->name, block, &objfile->objfile_obstack,
9504 determine_prefix (die, cu),
9505 processing_has_namespace_info);
9507 /* If we have address ranges, record them. */
9508 dwarf2_record_block_ranges (die, block, baseaddr, cu);
9510 /* Attach template arguments to function. */
9511 if (! VEC_empty (symbolp, template_args))
9513 gdb_assert (templ_func != NULL);
9515 templ_func->n_template_arguments = VEC_length (symbolp, template_args);
9516 templ_func->template_arguments
9517 = obstack_alloc (&objfile->objfile_obstack,
9518 (templ_func->n_template_arguments
9519 * sizeof (struct symbol *)));
9520 memcpy (templ_func->template_arguments,
9521 VEC_address (symbolp, template_args),
9522 (templ_func->n_template_arguments * sizeof (struct symbol *)));
9523 VEC_free (symbolp, template_args);
9526 /* In C++, we can have functions nested inside functions (e.g., when
9527 a function declares a class that has methods). This means that
9528 when we finish processing a function scope, we may need to go
9529 back to building a containing block's symbol lists. */
9530 local_symbols = new->locals;
9531 using_directives = new->using_directives;
9533 /* If we've finished processing a top-level function, subsequent
9534 symbols go in the file symbol list. */
9535 if (outermost_context_p ())
9536 cu->list_in_scope = &file_symbols;
9539 /* Process all the DIES contained within a lexical block scope. Start
9540 a new scope, process the dies, and then close the scope. */
9543 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
9545 struct objfile *objfile = cu->objfile;
9546 struct context_stack *new;
9547 CORE_ADDR lowpc, highpc;
9548 struct die_info *child_die;
9551 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9553 /* Ignore blocks with missing or invalid low and high pc attributes. */
9554 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
9555 as multiple lexical blocks? Handling children in a sane way would
9556 be nasty. Might be easier to properly extend generic blocks to
9558 if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL))
9563 push_context (0, lowpc);
9564 if (die->child != NULL)
9566 child_die = die->child;
9567 while (child_die && child_die->tag)
9569 process_die (child_die, cu);
9570 child_die = sibling_die (child_die);
9573 new = pop_context ();
9575 if (local_symbols != NULL || using_directives != NULL)
9578 = finish_block (0, &local_symbols, new->old_blocks, new->start_addr,
9581 /* Note that recording ranges after traversing children, as we
9582 do here, means that recording a parent's ranges entails
9583 walking across all its children's ranges as they appear in
9584 the address map, which is quadratic behavior.
9586 It would be nicer to record the parent's ranges before
9587 traversing its children, simply overriding whatever you find
9588 there. But since we don't even decide whether to create a
9589 block until after we've traversed its children, that's hard
9591 dwarf2_record_block_ranges (die, block, baseaddr, cu);
9593 local_symbols = new->locals;
9594 using_directives = new->using_directives;
9597 /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */
9600 read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
9602 struct objfile *objfile = cu->objfile;
9603 struct gdbarch *gdbarch = get_objfile_arch (objfile);
9604 CORE_ADDR pc, baseaddr;
9605 struct attribute *attr;
9606 struct call_site *call_site, call_site_local;
9609 struct die_info *child_die;
9611 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9613 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
9616 complaint (&symfile_complaints,
9617 _("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
9618 "DIE 0x%x [in module %s]"),
9619 die->offset.sect_off, objfile->name);
9622 pc = DW_ADDR (attr) + baseaddr;
9624 if (cu->call_site_htab == NULL)
9625 cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq,
9626 NULL, &objfile->objfile_obstack,
9627 hashtab_obstack_allocate, NULL);
9628 call_site_local.pc = pc;
9629 slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
9632 complaint (&symfile_complaints,
9633 _("Duplicate PC %s for DW_TAG_GNU_call_site "
9634 "DIE 0x%x [in module %s]"),
9635 paddress (gdbarch, pc), die->offset.sect_off, objfile->name);
9639 /* Count parameters at the caller. */
9642 for (child_die = die->child; child_die && child_die->tag;
9643 child_die = sibling_die (child_die))
9645 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
9647 complaint (&symfile_complaints,
9648 _("Tag %d is not DW_TAG_GNU_call_site_parameter in "
9649 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9650 child_die->tag, child_die->offset.sect_off, objfile->name);
9657 call_site = obstack_alloc (&objfile->objfile_obstack,
9658 (sizeof (*call_site)
9659 + (sizeof (*call_site->parameter)
9662 memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
9665 if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
9667 struct die_info *func_die;
9669 /* Skip also over DW_TAG_inlined_subroutine. */
9670 for (func_die = die->parent;
9671 func_die && func_die->tag != DW_TAG_subprogram
9672 && func_die->tag != DW_TAG_subroutine_type;
9673 func_die = func_die->parent);
9675 /* DW_AT_GNU_all_call_sites is a superset
9676 of DW_AT_GNU_all_tail_call_sites. */
9678 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu)
9679 && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu))
9681 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
9682 not complete. But keep CALL_SITE for look ups via call_site_htab,
9683 both the initial caller containing the real return address PC and
9684 the final callee containing the current PC of a chain of tail
9685 calls do not need to have the tail call list complete. But any
9686 function candidate for a virtual tail call frame searched via
9687 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
9688 determined unambiguously. */
9692 struct type *func_type = NULL;
9695 func_type = get_die_type (func_die, cu);
9696 if (func_type != NULL)
9698 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
9700 /* Enlist this call site to the function. */
9701 call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type);
9702 TYPE_TAIL_CALL_LIST (func_type) = call_site;
9705 complaint (&symfile_complaints,
9706 _("Cannot find function owning DW_TAG_GNU_call_site "
9707 "DIE 0x%x [in module %s]"),
9708 die->offset.sect_off, objfile->name);
9712 attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu);
9714 attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
9715 SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
9716 if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
9717 /* Keep NULL DWARF_BLOCK. */;
9718 else if (attr_form_is_block (attr))
9720 struct dwarf2_locexpr_baton *dlbaton;
9722 dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton));
9723 dlbaton->data = DW_BLOCK (attr)->data;
9724 dlbaton->size = DW_BLOCK (attr)->size;
9725 dlbaton->per_cu = cu->per_cu;
9727 SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
9729 else if (is_ref_attr (attr))
9731 struct dwarf2_cu *target_cu = cu;
9732 struct die_info *target_die;
9734 target_die = follow_die_ref_or_sig (die, attr, &target_cu);
9735 gdb_assert (target_cu->objfile == objfile);
9736 if (die_is_declaration (target_die, target_cu))
9738 const char *target_physname;
9740 target_physname = dwarf2_physname (NULL, target_die, target_cu);
9741 if (target_physname == NULL)
9742 complaint (&symfile_complaints,
9743 _("DW_AT_GNU_call_site_target target DIE has invalid "
9744 "physname, for referencing DIE 0x%x [in module %s]"),
9745 die->offset.sect_off, objfile->name);
9747 SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname);
9753 /* DW_AT_entry_pc should be preferred. */
9754 if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL))
9755 complaint (&symfile_complaints,
9756 _("DW_AT_GNU_call_site_target target DIE has invalid "
9757 "low pc, for referencing DIE 0x%x [in module %s]"),
9758 die->offset.sect_off, objfile->name);
9760 SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
9764 complaint (&symfile_complaints,
9765 _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
9766 "block nor reference, for DIE 0x%x [in module %s]"),
9767 die->offset.sect_off, objfile->name);
9769 call_site->per_cu = cu->per_cu;
9771 for (child_die = die->child;
9772 child_die && child_die->tag;
9773 child_die = sibling_die (child_die))
9775 struct call_site_parameter *parameter;
9776 struct attribute *loc, *origin;
9778 if (child_die->tag != DW_TAG_GNU_call_site_parameter)
9780 /* Already printed the complaint above. */
9784 gdb_assert (call_site->parameter_count < nparams);
9785 parameter = &call_site->parameter[call_site->parameter_count];
9787 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
9788 specifies DW_TAG_formal_parameter. Value of the data assumed for the
9789 register is contained in DW_AT_GNU_call_site_value. */
9791 loc = dwarf2_attr (child_die, DW_AT_location, cu);
9792 origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu);
9793 if (loc == NULL && origin != NULL && is_ref_attr (origin))
9797 parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET;
9798 offset = dwarf2_get_ref_die_offset (origin);
9799 if (!offset_in_cu_p (&cu->header, offset))
9801 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
9802 binding can be done only inside one CU. Such referenced DIE
9803 therefore cannot be even moved to DW_TAG_partial_unit. */
9804 complaint (&symfile_complaints,
9805 _("DW_AT_abstract_origin offset is not in CU for "
9806 "DW_TAG_GNU_call_site child DIE 0x%x "
9808 child_die->offset.sect_off, objfile->name);
9811 parameter->u.param_offset.cu_off = (offset.sect_off
9812 - cu->header.offset.sect_off);
9814 else if (loc == NULL || origin != NULL || !attr_form_is_block (loc))
9816 complaint (&symfile_complaints,
9817 _("No DW_FORM_block* DW_AT_location for "
9818 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9819 child_die->offset.sect_off, objfile->name);
9824 parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg
9825 (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]);
9826 if (parameter->u.dwarf_reg != -1)
9827 parameter->kind = CALL_SITE_PARAMETER_DWARF_REG;
9828 else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data,
9829 &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size],
9830 ¶meter->u.fb_offset))
9831 parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET;
9834 complaint (&symfile_complaints,
9835 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
9836 "for DW_FORM_block* DW_AT_location is supported for "
9837 "DW_TAG_GNU_call_site child DIE 0x%x "
9839 child_die->offset.sect_off, objfile->name);
9844 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
9845 if (!attr_form_is_block (attr))
9847 complaint (&symfile_complaints,
9848 _("No DW_FORM_block* DW_AT_GNU_call_site_value for "
9849 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9850 child_die->offset.sect_off, objfile->name);
9853 parameter->value = DW_BLOCK (attr)->data;
9854 parameter->value_size = DW_BLOCK (attr)->size;
9856 /* Parameters are not pre-cleared by memset above. */
9857 parameter->data_value = NULL;
9858 parameter->data_value_size = 0;
9859 call_site->parameter_count++;
9861 attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
9864 if (!attr_form_is_block (attr))
9865 complaint (&symfile_complaints,
9866 _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
9867 "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
9868 child_die->offset.sect_off, objfile->name);
9871 parameter->data_value = DW_BLOCK (attr)->data;
9872 parameter->data_value_size = DW_BLOCK (attr)->size;
9878 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
9879 Return 1 if the attributes are present and valid, otherwise, return 0.
9880 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
9883 dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
9884 CORE_ADDR *high_return, struct dwarf2_cu *cu,
9885 struct partial_symtab *ranges_pst)
9887 struct objfile *objfile = cu->objfile;
9888 struct comp_unit_head *cu_header = &cu->header;
9889 bfd *obfd = objfile->obfd;
9890 unsigned int addr_size = cu_header->addr_size;
9891 CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
9892 /* Base address selection entry. */
9903 found_base = cu->base_known;
9904 base = cu->base_address;
9906 dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
9907 if (offset >= dwarf2_per_objfile->ranges.size)
9909 complaint (&symfile_complaints,
9910 _("Offset %d out of bounds for DW_AT_ranges attribute"),
9914 buffer = dwarf2_per_objfile->ranges.buffer + offset;
9916 /* Read in the largest possible address. */
9917 marker = read_address (obfd, buffer, cu, &dummy);
9918 if ((marker & mask) == mask)
9920 /* If we found the largest possible address, then
9921 read the base address. */
9922 base = read_address (obfd, buffer + addr_size, cu, &dummy);
9923 buffer += 2 * addr_size;
9924 offset += 2 * addr_size;
9930 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
9934 CORE_ADDR range_beginning, range_end;
9936 range_beginning = read_address (obfd, buffer, cu, &dummy);
9937 buffer += addr_size;
9938 range_end = read_address (obfd, buffer, cu, &dummy);
9939 buffer += addr_size;
9940 offset += 2 * addr_size;
9942 /* An end of list marker is a pair of zero addresses. */
9943 if (range_beginning == 0 && range_end == 0)
9944 /* Found the end of list entry. */
9947 /* Each base address selection entry is a pair of 2 values.
9948 The first is the largest possible address, the second is
9949 the base address. Check for a base address here. */
9950 if ((range_beginning & mask) == mask)
9952 /* If we found the largest possible address, then
9953 read the base address. */
9954 base = read_address (obfd, buffer + addr_size, cu, &dummy);
9961 /* We have no valid base address for the ranges
9963 complaint (&symfile_complaints,
9964 _("Invalid .debug_ranges data (no base address)"));
9968 if (range_beginning > range_end)
9970 /* Inverted range entries are invalid. */
9971 complaint (&symfile_complaints,
9972 _("Invalid .debug_ranges data (inverted range)"));
9976 /* Empty range entries have no effect. */
9977 if (range_beginning == range_end)
9980 range_beginning += base;
9983 /* A not-uncommon case of bad debug info.
9984 Don't pollute the addrmap with bad data. */
9985 if (range_beginning + baseaddr == 0
9986 && !dwarf2_per_objfile->has_section_at_zero)
9988 complaint (&symfile_complaints,
9989 _(".debug_ranges entry has start address of zero"
9990 " [in module %s]"), objfile->name);
9994 if (ranges_pst != NULL)
9995 addrmap_set_empty (objfile->psymtabs_addrmap,
9996 range_beginning + baseaddr,
9997 range_end - 1 + baseaddr,
10000 /* FIXME: This is recording everything as a low-high
10001 segment of consecutive addresses. We should have a
10002 data structure for discontiguous block ranges
10006 low = range_beginning;
10012 if (range_beginning < low)
10013 low = range_beginning;
10014 if (range_end > high)
10020 /* If the first entry is an end-of-list marker, the range
10021 describes an empty scope, i.e. no instructions. */
10027 *high_return = high;
10031 /* Get low and high pc attributes from a die. Return 1 if the attributes
10032 are present and valid, otherwise, return 0. Return -1 if the range is
10033 discontinuous, i.e. derived from DW_AT_ranges information. */
10036 dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
10037 CORE_ADDR *highpc, struct dwarf2_cu *cu,
10038 struct partial_symtab *pst)
10040 struct attribute *attr;
10041 struct attribute *attr_high;
10043 CORE_ADDR high = 0;
10046 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
10049 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
10052 low = DW_ADDR (attr);
10053 if (attr_high->form == DW_FORM_addr
10054 || attr_high->form == DW_FORM_GNU_addr_index)
10055 high = DW_ADDR (attr_high);
10057 high = low + DW_UNSND (attr_high);
10060 /* Found high w/o low attribute. */
10063 /* Found consecutive range of addresses. */
10068 attr = dwarf2_attr (die, DW_AT_ranges, cu);
10071 unsigned int ranges_offset = DW_UNSND (attr) + cu->ranges_base;
10073 /* Value of the DW_AT_ranges attribute is the offset in the
10074 .debug_ranges section. */
10075 if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst))
10077 /* Found discontinuous range of addresses. */
10082 /* read_partial_die has also the strict LOW < HIGH requirement. */
10086 /* When using the GNU linker, .gnu.linkonce. sections are used to
10087 eliminate duplicate copies of functions and vtables and such.
10088 The linker will arbitrarily choose one and discard the others.
10089 The AT_*_pc values for such functions refer to local labels in
10090 these sections. If the section from that file was discarded, the
10091 labels are not in the output, so the relocs get a value of 0.
10092 If this is a discarded function, mark the pc bounds as invalid,
10093 so that GDB will ignore it. */
10094 if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
10103 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
10104 its low and high PC addresses. Do nothing if these addresses could not
10105 be determined. Otherwise, set LOWPC to the low address if it is smaller,
10106 and HIGHPC to the high address if greater than HIGHPC. */
10109 dwarf2_get_subprogram_pc_bounds (struct die_info *die,
10110 CORE_ADDR *lowpc, CORE_ADDR *highpc,
10111 struct dwarf2_cu *cu)
10113 CORE_ADDR low, high;
10114 struct die_info *child = die->child;
10116 if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL))
10118 *lowpc = min (*lowpc, low);
10119 *highpc = max (*highpc, high);
10122 /* If the language does not allow nested subprograms (either inside
10123 subprograms or lexical blocks), we're done. */
10124 if (cu->language != language_ada)
10127 /* Check all the children of the given DIE. If it contains nested
10128 subprograms, then check their pc bounds. Likewise, we need to
10129 check lexical blocks as well, as they may also contain subprogram
10131 while (child && child->tag)
10133 if (child->tag == DW_TAG_subprogram
10134 || child->tag == DW_TAG_lexical_block)
10135 dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
10136 child = sibling_die (child);
10140 /* Get the low and high pc's represented by the scope DIE, and store
10141 them in *LOWPC and *HIGHPC. If the correct values can't be
10142 determined, set *LOWPC to -1 and *HIGHPC to 0. */
10145 get_scope_pc_bounds (struct die_info *die,
10146 CORE_ADDR *lowpc, CORE_ADDR *highpc,
10147 struct dwarf2_cu *cu)
10149 CORE_ADDR best_low = (CORE_ADDR) -1;
10150 CORE_ADDR best_high = (CORE_ADDR) 0;
10151 CORE_ADDR current_low, current_high;
10153 if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL))
10155 best_low = current_low;
10156 best_high = current_high;
10160 struct die_info *child = die->child;
10162 while (child && child->tag)
10164 switch (child->tag) {
10165 case DW_TAG_subprogram:
10166 dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu);
10168 case DW_TAG_namespace:
10169 case DW_TAG_module:
10170 /* FIXME: carlton/2004-01-16: Should we do this for
10171 DW_TAG_class_type/DW_TAG_structure_type, too? I think
10172 that current GCC's always emit the DIEs corresponding
10173 to definitions of methods of classes as children of a
10174 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
10175 the DIEs giving the declarations, which could be
10176 anywhere). But I don't see any reason why the
10177 standards says that they have to be there. */
10178 get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu);
10180 if (current_low != ((CORE_ADDR) -1))
10182 best_low = min (best_low, current_low);
10183 best_high = max (best_high, current_high);
10191 child = sibling_die (child);
10196 *highpc = best_high;
10199 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
10203 dwarf2_record_block_ranges (struct die_info *die, struct block *block,
10204 CORE_ADDR baseaddr, struct dwarf2_cu *cu)
10206 struct objfile *objfile = cu->objfile;
10207 struct attribute *attr;
10208 struct attribute *attr_high;
10210 attr_high = dwarf2_attr (die, DW_AT_high_pc, cu);
10213 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
10216 CORE_ADDR low = DW_ADDR (attr);
10218 if (attr_high->form == DW_FORM_addr
10219 || attr_high->form == DW_FORM_GNU_addr_index)
10220 high = DW_ADDR (attr_high);
10222 high = low + DW_UNSND (attr_high);
10224 record_block_range (block, baseaddr + low, baseaddr + high - 1);
10228 attr = dwarf2_attr (die, DW_AT_ranges, cu);
10231 bfd *obfd = objfile->obfd;
10233 /* The value of the DW_AT_ranges attribute is the offset of the
10234 address range list in the .debug_ranges section. */
10235 unsigned long offset = DW_UNSND (attr) + cu->ranges_base;
10236 gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset;
10238 /* For some target architectures, but not others, the
10239 read_address function sign-extends the addresses it returns.
10240 To recognize base address selection entries, we need a
10242 unsigned int addr_size = cu->header.addr_size;
10243 CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
10245 /* The base address, to which the next pair is relative. Note
10246 that this 'base' is a DWARF concept: most entries in a range
10247 list are relative, to reduce the number of relocs against the
10248 debugging information. This is separate from this function's
10249 'baseaddr' argument, which GDB uses to relocate debugging
10250 information from a shared library based on the address at
10251 which the library was loaded. */
10252 CORE_ADDR base = cu->base_address;
10253 int base_known = cu->base_known;
10255 gdb_assert (dwarf2_per_objfile->ranges.readin);
10256 if (offset >= dwarf2_per_objfile->ranges.size)
10258 complaint (&symfile_complaints,
10259 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
10266 unsigned int bytes_read;
10267 CORE_ADDR start, end;
10269 start = read_address (obfd, buffer, cu, &bytes_read);
10270 buffer += bytes_read;
10271 end = read_address (obfd, buffer, cu, &bytes_read);
10272 buffer += bytes_read;
10274 /* Did we find the end of the range list? */
10275 if (start == 0 && end == 0)
10278 /* Did we find a base address selection entry? */
10279 else if ((start & base_select_mask) == base_select_mask)
10285 /* We found an ordinary address range. */
10290 complaint (&symfile_complaints,
10291 _("Invalid .debug_ranges data "
10292 "(no base address)"));
10298 /* Inverted range entries are invalid. */
10299 complaint (&symfile_complaints,
10300 _("Invalid .debug_ranges data "
10301 "(inverted range)"));
10305 /* Empty range entries have no effect. */
10309 start += base + baseaddr;
10310 end += base + baseaddr;
10312 /* A not-uncommon case of bad debug info.
10313 Don't pollute the addrmap with bad data. */
10314 if (start == 0 && !dwarf2_per_objfile->has_section_at_zero)
10316 complaint (&symfile_complaints,
10317 _(".debug_ranges entry has start address of zero"
10318 " [in module %s]"), objfile->name);
10322 record_block_range (block, start, end - 1);
10328 /* Check whether the producer field indicates either of GCC < 4.6, or the
10329 Intel C/C++ compiler, and cache the result in CU. */
10332 check_producer (struct dwarf2_cu *cu)
10335 int major, minor, release;
10337 if (cu->producer == NULL)
10339 /* For unknown compilers expect their behavior is DWARF version
10342 GCC started to support .debug_types sections by -gdwarf-4 since
10343 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
10344 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
10345 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
10346 interpreted incorrectly by GDB now - GCC PR debug/48229. */
10348 else if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) == 0)
10350 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
10352 cs = &cu->producer[strlen ("GNU ")];
10353 while (*cs && !isdigit (*cs))
10355 if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3)
10357 /* Not recognized as GCC. */
10360 cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6);
10362 else if (strncmp (cu->producer, "Intel(R) C", strlen ("Intel(R) C")) == 0)
10363 cu->producer_is_icc = 1;
10366 /* For other non-GCC compilers, expect their behavior is DWARF version
10370 cu->checked_producer = 1;
10373 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
10374 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
10375 during 4.6.0 experimental. */
10378 producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu)
10380 if (!cu->checked_producer)
10381 check_producer (cu);
10383 return cu->producer_is_gxx_lt_4_6;
10386 /* Return the default accessibility type if it is not overriden by
10387 DW_AT_accessibility. */
10389 static enum dwarf_access_attribute
10390 dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu)
10392 if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu))
10394 /* The default DWARF 2 accessibility for members is public, the default
10395 accessibility for inheritance is private. */
10397 if (die->tag != DW_TAG_inheritance)
10398 return DW_ACCESS_public;
10400 return DW_ACCESS_private;
10404 /* DWARF 3+ defines the default accessibility a different way. The same
10405 rules apply now for DW_TAG_inheritance as for the members and it only
10406 depends on the container kind. */
10408 if (die->parent->tag == DW_TAG_class_type)
10409 return DW_ACCESS_private;
10411 return DW_ACCESS_public;
10415 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
10416 offset. If the attribute was not found return 0, otherwise return
10417 1. If it was found but could not properly be handled, set *OFFSET
10421 handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
10424 struct attribute *attr;
10426 attr = dwarf2_attr (die, DW_AT_data_member_location, cu);
10431 /* Note that we do not check for a section offset first here.
10432 This is because DW_AT_data_member_location is new in DWARF 4,
10433 so if we see it, we can assume that a constant form is really
10434 a constant and not a section offset. */
10435 if (attr_form_is_constant (attr))
10436 *offset = dwarf2_get_attr_constant_value (attr, 0);
10437 else if (attr_form_is_section_offset (attr))
10438 dwarf2_complex_location_expr_complaint ();
10439 else if (attr_form_is_block (attr))
10440 *offset = decode_locdesc (DW_BLOCK (attr), cu);
10442 dwarf2_complex_location_expr_complaint ();
10450 /* Add an aggregate field to the field list. */
10453 dwarf2_add_field (struct field_info *fip, struct die_info *die,
10454 struct dwarf2_cu *cu)
10456 struct objfile *objfile = cu->objfile;
10457 struct gdbarch *gdbarch = get_objfile_arch (objfile);
10458 struct nextfield *new_field;
10459 struct attribute *attr;
10461 char *fieldname = "";
10463 /* Allocate a new field list entry and link it in. */
10464 new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield));
10465 make_cleanup (xfree, new_field);
10466 memset (new_field, 0, sizeof (struct nextfield));
10468 if (die->tag == DW_TAG_inheritance)
10470 new_field->next = fip->baseclasses;
10471 fip->baseclasses = new_field;
10475 new_field->next = fip->fields;
10476 fip->fields = new_field;
10480 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
10482 new_field->accessibility = DW_UNSND (attr);
10484 new_field->accessibility = dwarf2_default_access_attribute (die, cu);
10485 if (new_field->accessibility != DW_ACCESS_public)
10486 fip->non_public_fields = 1;
10488 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
10490 new_field->virtuality = DW_UNSND (attr);
10492 new_field->virtuality = DW_VIRTUALITY_none;
10494 fp = &new_field->field;
10496 if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu))
10500 /* Data member other than a C++ static data member. */
10502 /* Get type of field. */
10503 fp->type = die_type (die, cu);
10505 SET_FIELD_BITPOS (*fp, 0);
10507 /* Get bit size of field (zero if none). */
10508 attr = dwarf2_attr (die, DW_AT_bit_size, cu);
10511 FIELD_BITSIZE (*fp) = DW_UNSND (attr);
10515 FIELD_BITSIZE (*fp) = 0;
10518 /* Get bit offset of field. */
10519 if (handle_data_member_location (die, cu, &offset))
10520 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
10521 attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
10524 if (gdbarch_bits_big_endian (gdbarch))
10526 /* For big endian bits, the DW_AT_bit_offset gives the
10527 additional bit offset from the MSB of the containing
10528 anonymous object to the MSB of the field. We don't
10529 have to do anything special since we don't need to
10530 know the size of the anonymous object. */
10531 SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr));
10535 /* For little endian bits, compute the bit offset to the
10536 MSB of the anonymous object, subtract off the number of
10537 bits from the MSB of the field to the MSB of the
10538 object, and then subtract off the number of bits of
10539 the field itself. The result is the bit offset of
10540 the LSB of the field. */
10541 int anonymous_size;
10542 int bit_offset = DW_UNSND (attr);
10544 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
10547 /* The size of the anonymous object containing
10548 the bit field is explicit, so use the
10549 indicated size (in bytes). */
10550 anonymous_size = DW_UNSND (attr);
10554 /* The size of the anonymous object containing
10555 the bit field must be inferred from the type
10556 attribute of the data member containing the
10558 anonymous_size = TYPE_LENGTH (fp->type);
10560 SET_FIELD_BITPOS (*fp,
10561 (FIELD_BITPOS (*fp)
10562 + anonymous_size * bits_per_byte
10563 - bit_offset - FIELD_BITSIZE (*fp)));
10567 /* Get name of field. */
10568 fieldname = dwarf2_name (die, cu);
10569 if (fieldname == NULL)
10572 /* The name is already allocated along with this objfile, so we don't
10573 need to duplicate it for the type. */
10574 fp->name = fieldname;
10576 /* Change accessibility for artificial fields (e.g. virtual table
10577 pointer or virtual base class pointer) to private. */
10578 if (dwarf2_attr (die, DW_AT_artificial, cu))
10580 FIELD_ARTIFICIAL (*fp) = 1;
10581 new_field->accessibility = DW_ACCESS_private;
10582 fip->non_public_fields = 1;
10585 else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable)
10587 /* C++ static member. */
10589 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
10590 is a declaration, but all versions of G++ as of this writing
10591 (so through at least 3.2.1) incorrectly generate
10592 DW_TAG_variable tags. */
10594 const char *physname;
10596 /* Get name of field. */
10597 fieldname = dwarf2_name (die, cu);
10598 if (fieldname == NULL)
10601 attr = dwarf2_attr (die, DW_AT_const_value, cu);
10603 /* Only create a symbol if this is an external value.
10604 new_symbol checks this and puts the value in the global symbol
10605 table, which we want. If it is not external, new_symbol
10606 will try to put the value in cu->list_in_scope which is wrong. */
10607 && dwarf2_flag_true_p (die, DW_AT_external, cu))
10609 /* A static const member, not much different than an enum as far as
10610 we're concerned, except that we can support more types. */
10611 new_symbol (die, NULL, cu);
10614 /* Get physical name. */
10615 physname = dwarf2_physname (fieldname, die, cu);
10617 /* The name is already allocated along with this objfile, so we don't
10618 need to duplicate it for the type. */
10619 SET_FIELD_PHYSNAME (*fp, physname ? physname : "");
10620 FIELD_TYPE (*fp) = die_type (die, cu);
10621 FIELD_NAME (*fp) = fieldname;
10623 else if (die->tag == DW_TAG_inheritance)
10627 /* C++ base class field. */
10628 if (handle_data_member_location (die, cu, &offset))
10629 SET_FIELD_BITPOS (*fp, offset * bits_per_byte);
10630 FIELD_BITSIZE (*fp) = 0;
10631 FIELD_TYPE (*fp) = die_type (die, cu);
10632 FIELD_NAME (*fp) = type_name_no_tag (fp->type);
10633 fip->nbaseclasses++;
10637 /* Add a typedef defined in the scope of the FIP's class. */
10640 dwarf2_add_typedef (struct field_info *fip, struct die_info *die,
10641 struct dwarf2_cu *cu)
10643 struct objfile *objfile = cu->objfile;
10644 struct typedef_field_list *new_field;
10645 struct attribute *attr;
10646 struct typedef_field *fp;
10647 char *fieldname = "";
10649 /* Allocate a new field list entry and link it in. */
10650 new_field = xzalloc (sizeof (*new_field));
10651 make_cleanup (xfree, new_field);
10653 gdb_assert (die->tag == DW_TAG_typedef);
10655 fp = &new_field->field;
10657 /* Get name of field. */
10658 fp->name = dwarf2_name (die, cu);
10659 if (fp->name == NULL)
10662 fp->type = read_type_die (die, cu);
10664 new_field->next = fip->typedef_field_list;
10665 fip->typedef_field_list = new_field;
10666 fip->typedef_field_list_count++;
10669 /* Create the vector of fields, and attach it to the type. */
10672 dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
10673 struct dwarf2_cu *cu)
10675 int nfields = fip->nfields;
10677 /* Record the field count, allocate space for the array of fields,
10678 and create blank accessibility bitfields if necessary. */
10679 TYPE_NFIELDS (type) = nfields;
10680 TYPE_FIELDS (type) = (struct field *)
10681 TYPE_ALLOC (type, sizeof (struct field) * nfields);
10682 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
10684 if (fip->non_public_fields && cu->language != language_ada)
10686 ALLOCATE_CPLUS_STRUCT_TYPE (type);
10688 TYPE_FIELD_PRIVATE_BITS (type) =
10689 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
10690 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
10692 TYPE_FIELD_PROTECTED_BITS (type) =
10693 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
10694 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
10696 TYPE_FIELD_IGNORE_BITS (type) =
10697 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
10698 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
10701 /* If the type has baseclasses, allocate and clear a bit vector for
10702 TYPE_FIELD_VIRTUAL_BITS. */
10703 if (fip->nbaseclasses && cu->language != language_ada)
10705 int num_bytes = B_BYTES (fip->nbaseclasses);
10706 unsigned char *pointer;
10708 ALLOCATE_CPLUS_STRUCT_TYPE (type);
10709 pointer = TYPE_ALLOC (type, num_bytes);
10710 TYPE_FIELD_VIRTUAL_BITS (type) = pointer;
10711 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses);
10712 TYPE_N_BASECLASSES (type) = fip->nbaseclasses;
10715 /* Copy the saved-up fields into the field vector. Start from the head of
10716 the list, adding to the tail of the field array, so that they end up in
10717 the same order in the array in which they were added to the list. */
10718 while (nfields-- > 0)
10720 struct nextfield *fieldp;
10724 fieldp = fip->fields;
10725 fip->fields = fieldp->next;
10729 fieldp = fip->baseclasses;
10730 fip->baseclasses = fieldp->next;
10733 TYPE_FIELD (type, nfields) = fieldp->field;
10734 switch (fieldp->accessibility)
10736 case DW_ACCESS_private:
10737 if (cu->language != language_ada)
10738 SET_TYPE_FIELD_PRIVATE (type, nfields);
10741 case DW_ACCESS_protected:
10742 if (cu->language != language_ada)
10743 SET_TYPE_FIELD_PROTECTED (type, nfields);
10746 case DW_ACCESS_public:
10750 /* Unknown accessibility. Complain and treat it as public. */
10752 complaint (&symfile_complaints, _("unsupported accessibility %d"),
10753 fieldp->accessibility);
10757 if (nfields < fip->nbaseclasses)
10759 switch (fieldp->virtuality)
10761 case DW_VIRTUALITY_virtual:
10762 case DW_VIRTUALITY_pure_virtual:
10763 if (cu->language == language_ada)
10764 error (_("unexpected virtuality in component of Ada type"));
10765 SET_TYPE_FIELD_VIRTUAL (type, nfields);
10772 /* Add a member function to the proper fieldlist. */
10775 dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
10776 struct type *type, struct dwarf2_cu *cu)
10778 struct objfile *objfile = cu->objfile;
10779 struct attribute *attr;
10780 struct fnfieldlist *flp;
10782 struct fn_field *fnp;
10784 struct nextfnfield *new_fnfield;
10785 struct type *this_type;
10786 enum dwarf_access_attribute accessibility;
10788 if (cu->language == language_ada)
10789 error (_("unexpected member function in Ada type"));
10791 /* Get name of member function. */
10792 fieldname = dwarf2_name (die, cu);
10793 if (fieldname == NULL)
10796 /* Look up member function name in fieldlist. */
10797 for (i = 0; i < fip->nfnfields; i++)
10799 if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0)
10803 /* Create new list element if necessary. */
10804 if (i < fip->nfnfields)
10805 flp = &fip->fnfieldlists[i];
10808 if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0)
10810 fip->fnfieldlists = (struct fnfieldlist *)
10811 xrealloc (fip->fnfieldlists,
10812 (fip->nfnfields + DW_FIELD_ALLOC_CHUNK)
10813 * sizeof (struct fnfieldlist));
10814 if (fip->nfnfields == 0)
10815 make_cleanup (free_current_contents, &fip->fnfieldlists);
10817 flp = &fip->fnfieldlists[fip->nfnfields];
10818 flp->name = fieldname;
10821 i = fip->nfnfields++;
10824 /* Create a new member function field and chain it to the field list
10826 new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield));
10827 make_cleanup (xfree, new_fnfield);
10828 memset (new_fnfield, 0, sizeof (struct nextfnfield));
10829 new_fnfield->next = flp->head;
10830 flp->head = new_fnfield;
10833 /* Fill in the member function field info. */
10834 fnp = &new_fnfield->fnfield;
10836 /* Delay processing of the physname until later. */
10837 if (cu->language == language_cplus || cu->language == language_java)
10839 add_to_method_list (type, i, flp->length - 1, fieldname,
10844 const char *physname = dwarf2_physname (fieldname, die, cu);
10845 fnp->physname = physname ? physname : "";
10848 fnp->type = alloc_type (objfile);
10849 this_type = read_type_die (die, cu);
10850 if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC)
10852 int nparams = TYPE_NFIELDS (this_type);
10854 /* TYPE is the domain of this method, and THIS_TYPE is the type
10855 of the method itself (TYPE_CODE_METHOD). */
10856 smash_to_method_type (fnp->type, type,
10857 TYPE_TARGET_TYPE (this_type),
10858 TYPE_FIELDS (this_type),
10859 TYPE_NFIELDS (this_type),
10860 TYPE_VARARGS (this_type));
10862 /* Handle static member functions.
10863 Dwarf2 has no clean way to discern C++ static and non-static
10864 member functions. G++ helps GDB by marking the first
10865 parameter for non-static member functions (which is the this
10866 pointer) as artificial. We obtain this information from
10867 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
10868 if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0)
10869 fnp->voffset = VOFFSET_STATIC;
10872 complaint (&symfile_complaints, _("member function type missing for '%s'"),
10873 dwarf2_full_name (fieldname, die, cu));
10875 /* Get fcontext from DW_AT_containing_type if present. */
10876 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
10877 fnp->fcontext = die_containing_type (die, cu);
10879 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
10880 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
10882 /* Get accessibility. */
10883 attr = dwarf2_attr (die, DW_AT_accessibility, cu);
10885 accessibility = DW_UNSND (attr);
10887 accessibility = dwarf2_default_access_attribute (die, cu);
10888 switch (accessibility)
10890 case DW_ACCESS_private:
10891 fnp->is_private = 1;
10893 case DW_ACCESS_protected:
10894 fnp->is_protected = 1;
10898 /* Check for artificial methods. */
10899 attr = dwarf2_attr (die, DW_AT_artificial, cu);
10900 if (attr && DW_UNSND (attr) != 0)
10901 fnp->is_artificial = 1;
10903 /* Get index in virtual function table if it is a virtual member
10904 function. For older versions of GCC, this is an offset in the
10905 appropriate virtual table, as specified by DW_AT_containing_type.
10906 For everyone else, it is an expression to be evaluated relative
10907 to the object address. */
10909 attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
10912 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
10914 if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
10916 /* Old-style GCC. */
10917 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2;
10919 else if (DW_BLOCK (attr)->data[0] == DW_OP_deref
10920 || (DW_BLOCK (attr)->size > 1
10921 && DW_BLOCK (attr)->data[0] == DW_OP_deref_size
10922 && DW_BLOCK (attr)->data[1] == cu->header.addr_size))
10924 struct dwarf_block blk;
10927 offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref
10929 blk.size = DW_BLOCK (attr)->size - offset;
10930 blk.data = DW_BLOCK (attr)->data + offset;
10931 fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu);
10932 if ((fnp->voffset % cu->header.addr_size) != 0)
10933 dwarf2_complex_location_expr_complaint ();
10935 fnp->voffset /= cu->header.addr_size;
10939 dwarf2_complex_location_expr_complaint ();
10941 if (!fnp->fcontext)
10942 fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0));
10944 else if (attr_form_is_section_offset (attr))
10946 dwarf2_complex_location_expr_complaint ();
10950 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
10956 attr = dwarf2_attr (die, DW_AT_virtuality, cu);
10957 if (attr && DW_UNSND (attr))
10959 /* GCC does this, as of 2008-08-25; PR debug/37237. */
10960 complaint (&symfile_complaints,
10961 _("Member function \"%s\" (offset %d) is virtual "
10962 "but the vtable offset is not specified"),
10963 fieldname, die->offset.sect_off);
10964 ALLOCATE_CPLUS_STRUCT_TYPE (type);
10965 TYPE_CPLUS_DYNAMIC (type) = 1;
10970 /* Create the vector of member function fields, and attach it to the type. */
10973 dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type,
10974 struct dwarf2_cu *cu)
10976 struct fnfieldlist *flp;
10979 if (cu->language == language_ada)
10980 error (_("unexpected member functions in Ada type"));
10982 ALLOCATE_CPLUS_STRUCT_TYPE (type);
10983 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
10984 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields);
10986 for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++)
10988 struct nextfnfield *nfp = flp->head;
10989 struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i);
10992 TYPE_FN_FIELDLIST_NAME (type, i) = flp->name;
10993 TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length;
10994 fn_flp->fn_fields = (struct fn_field *)
10995 TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length);
10996 for (k = flp->length; (k--, nfp); nfp = nfp->next)
10997 fn_flp->fn_fields[k] = nfp->fnfield;
11000 TYPE_NFN_FIELDS (type) = fip->nfnfields;
11003 /* Returns non-zero if NAME is the name of a vtable member in CU's
11004 language, zero otherwise. */
11006 is_vtable_name (const char *name, struct dwarf2_cu *cu)
11008 static const char vptr[] = "_vptr";
11009 static const char vtable[] = "vtable";
11011 /* Look for the C++ and Java forms of the vtable. */
11012 if ((cu->language == language_java
11013 && strncmp (name, vtable, sizeof (vtable) - 1) == 0)
11014 || (strncmp (name, vptr, sizeof (vptr) - 1) == 0
11015 && is_cplus_marker (name[sizeof (vptr) - 1])))
11021 /* GCC outputs unnamed structures that are really pointers to member
11022 functions, with the ABI-specified layout. If TYPE describes
11023 such a structure, smash it into a member function type.
11025 GCC shouldn't do this; it should just output pointer to member DIEs.
11026 This is GCC PR debug/28767. */
11029 quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
11031 struct type *pfn_type, *domain_type, *new_type;
11033 /* Check for a structure with no name and two children. */
11034 if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
11037 /* Check for __pfn and __delta members. */
11038 if (TYPE_FIELD_NAME (type, 0) == NULL
11039 || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0
11040 || TYPE_FIELD_NAME (type, 1) == NULL
11041 || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0)
11044 /* Find the type of the method. */
11045 pfn_type = TYPE_FIELD_TYPE (type, 0);
11046 if (pfn_type == NULL
11047 || TYPE_CODE (pfn_type) != TYPE_CODE_PTR
11048 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC)
11051 /* Look for the "this" argument. */
11052 pfn_type = TYPE_TARGET_TYPE (pfn_type);
11053 if (TYPE_NFIELDS (pfn_type) == 0
11054 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
11055 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR)
11058 domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
11059 new_type = alloc_type (objfile);
11060 smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type),
11061 TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
11062 TYPE_VARARGS (pfn_type));
11063 smash_to_methodptr_type (type, new_type);
11066 /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler
11070 producer_is_icc (struct dwarf2_cu *cu)
11072 if (!cu->checked_producer)
11073 check_producer (cu);
11075 return cu->producer_is_icc;
11078 /* Called when we find the DIE that starts a structure or union scope
11079 (definition) to create a type for the structure or union. Fill in
11080 the type's name and general properties; the members will not be
11081 processed until process_structure_type.
11083 NOTE: we need to call these functions regardless of whether or not the
11084 DIE has a DW_AT_name attribute, since it might be an anonymous
11085 structure or union. This gets the type entered into our set of
11086 user defined types.
11088 However, if the structure is incomplete (an opaque struct/union)
11089 then suppress creating a symbol table entry for it since gdb only
11090 wants to find the one with the complete definition. Note that if
11091 it is complete, we just call new_symbol, which does it's own
11092 checking about whether the struct/union is anonymous or not (and
11093 suppresses creating a symbol table entry itself). */
11095 static struct type *
11096 read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
11098 struct objfile *objfile = cu->objfile;
11100 struct attribute *attr;
11103 /* If the definition of this type lives in .debug_types, read that type.
11104 Don't follow DW_AT_specification though, that will take us back up
11105 the chain and we want to go down. */
11106 attr = dwarf2_attr_no_follow (die, DW_AT_signature);
11109 struct dwarf2_cu *type_cu = cu;
11110 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11112 /* We could just recurse on read_structure_type, but we need to call
11113 get_die_type to ensure only one type for this DIE is created.
11114 This is important, for example, because for c++ classes we need
11115 TYPE_NAME set which is only done by new_symbol. Blech. */
11116 type = read_type_die (type_die, type_cu);
11118 /* TYPE_CU may not be the same as CU.
11119 Ensure TYPE is recorded in CU's type_hash table. */
11120 return set_die_type (die, type, cu);
11123 type = alloc_type (objfile);
11124 INIT_CPLUS_SPECIFIC (type);
11126 name = dwarf2_name (die, cu);
11129 if (cu->language == language_cplus
11130 || cu->language == language_java)
11132 char *full_name = (char *) dwarf2_full_name (name, die, cu);
11134 /* dwarf2_full_name might have already finished building the DIE's
11135 type. If so, there is no need to continue. */
11136 if (get_die_type (die, cu) != NULL)
11137 return get_die_type (die, cu);
11139 TYPE_TAG_NAME (type) = full_name;
11140 if (die->tag == DW_TAG_structure_type
11141 || die->tag == DW_TAG_class_type)
11142 TYPE_NAME (type) = TYPE_TAG_NAME (type);
11146 /* The name is already allocated along with this objfile, so
11147 we don't need to duplicate it for the type. */
11148 TYPE_TAG_NAME (type) = (char *) name;
11149 if (die->tag == DW_TAG_class_type)
11150 TYPE_NAME (type) = TYPE_TAG_NAME (type);
11154 if (die->tag == DW_TAG_structure_type)
11156 TYPE_CODE (type) = TYPE_CODE_STRUCT;
11158 else if (die->tag == DW_TAG_union_type)
11160 TYPE_CODE (type) = TYPE_CODE_UNION;
11164 TYPE_CODE (type) = TYPE_CODE_CLASS;
11167 if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
11168 TYPE_DECLARED_CLASS (type) = 1;
11170 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11173 TYPE_LENGTH (type) = DW_UNSND (attr);
11177 TYPE_LENGTH (type) = 0;
11180 if (producer_is_icc (cu))
11182 /* ICC does not output the required DW_AT_declaration
11183 on incomplete types, but gives them a size of zero. */
11186 TYPE_STUB_SUPPORTED (type) = 1;
11188 if (die_is_declaration (die, cu))
11189 TYPE_STUB (type) = 1;
11190 else if (attr == NULL && die->child == NULL
11191 && producer_is_realview (cu->producer))
11192 /* RealView does not output the required DW_AT_declaration
11193 on incomplete types. */
11194 TYPE_STUB (type) = 1;
11196 /* We need to add the type field to the die immediately so we don't
11197 infinitely recurse when dealing with pointers to the structure
11198 type within the structure itself. */
11199 set_die_type (die, type, cu);
11201 /* set_die_type should be already done. */
11202 set_descriptive_type (type, die, cu);
11207 /* Finish creating a structure or union type, including filling in
11208 its members and creating a symbol for it. */
11211 process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
11213 struct objfile *objfile = cu->objfile;
11214 struct die_info *child_die = die->child;
11217 type = get_die_type (die, cu);
11219 type = read_structure_type (die, cu);
11221 if (die->child != NULL && ! die_is_declaration (die, cu))
11223 struct field_info fi;
11224 struct die_info *child_die;
11225 VEC (symbolp) *template_args = NULL;
11226 struct cleanup *back_to = make_cleanup (null_cleanup, 0);
11228 memset (&fi, 0, sizeof (struct field_info));
11230 child_die = die->child;
11232 while (child_die && child_die->tag)
11234 if (child_die->tag == DW_TAG_member
11235 || child_die->tag == DW_TAG_variable)
11237 /* NOTE: carlton/2002-11-05: A C++ static data member
11238 should be a DW_TAG_member that is a declaration, but
11239 all versions of G++ as of this writing (so through at
11240 least 3.2.1) incorrectly generate DW_TAG_variable
11241 tags for them instead. */
11242 dwarf2_add_field (&fi, child_die, cu);
11244 else if (child_die->tag == DW_TAG_subprogram)
11246 /* C++ member function. */
11247 dwarf2_add_member_fn (&fi, child_die, type, cu);
11249 else if (child_die->tag == DW_TAG_inheritance)
11251 /* C++ base class field. */
11252 dwarf2_add_field (&fi, child_die, cu);
11254 else if (child_die->tag == DW_TAG_typedef)
11255 dwarf2_add_typedef (&fi, child_die, cu);
11256 else if (child_die->tag == DW_TAG_template_type_param
11257 || child_die->tag == DW_TAG_template_value_param)
11259 struct symbol *arg = new_symbol (child_die, NULL, cu);
11262 VEC_safe_push (symbolp, template_args, arg);
11265 child_die = sibling_die (child_die);
11268 /* Attach template arguments to type. */
11269 if (! VEC_empty (symbolp, template_args))
11271 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11272 TYPE_N_TEMPLATE_ARGUMENTS (type)
11273 = VEC_length (symbolp, template_args);
11274 TYPE_TEMPLATE_ARGUMENTS (type)
11275 = obstack_alloc (&objfile->objfile_obstack,
11276 (TYPE_N_TEMPLATE_ARGUMENTS (type)
11277 * sizeof (struct symbol *)));
11278 memcpy (TYPE_TEMPLATE_ARGUMENTS (type),
11279 VEC_address (symbolp, template_args),
11280 (TYPE_N_TEMPLATE_ARGUMENTS (type)
11281 * sizeof (struct symbol *)));
11282 VEC_free (symbolp, template_args);
11285 /* Attach fields and member functions to the type. */
11287 dwarf2_attach_fields_to_type (&fi, type, cu);
11290 dwarf2_attach_fn_fields_to_type (&fi, type, cu);
11292 /* Get the type which refers to the base class (possibly this
11293 class itself) which contains the vtable pointer for the current
11294 class from the DW_AT_containing_type attribute. This use of
11295 DW_AT_containing_type is a GNU extension. */
11297 if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL)
11299 struct type *t = die_containing_type (die, cu);
11301 TYPE_VPTR_BASETYPE (type) = t;
11306 /* Our own class provides vtbl ptr. */
11307 for (i = TYPE_NFIELDS (t) - 1;
11308 i >= TYPE_N_BASECLASSES (t);
11311 const char *fieldname = TYPE_FIELD_NAME (t, i);
11313 if (is_vtable_name (fieldname, cu))
11315 TYPE_VPTR_FIELDNO (type) = i;
11320 /* Complain if virtual function table field not found. */
11321 if (i < TYPE_N_BASECLASSES (t))
11322 complaint (&symfile_complaints,
11323 _("virtual function table pointer "
11324 "not found when defining class '%s'"),
11325 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) :
11330 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
11333 else if (cu->producer
11334 && strncmp (cu->producer,
11335 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
11337 /* The IBM XLC compiler does not provide direct indication
11338 of the containing type, but the vtable pointer is
11339 always named __vfp. */
11343 for (i = TYPE_NFIELDS (type) - 1;
11344 i >= TYPE_N_BASECLASSES (type);
11347 if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0)
11349 TYPE_VPTR_FIELDNO (type) = i;
11350 TYPE_VPTR_BASETYPE (type) = type;
11357 /* Copy fi.typedef_field_list linked list elements content into the
11358 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
11359 if (fi.typedef_field_list)
11361 int i = fi.typedef_field_list_count;
11363 ALLOCATE_CPLUS_STRUCT_TYPE (type);
11364 TYPE_TYPEDEF_FIELD_ARRAY (type)
11365 = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i);
11366 TYPE_TYPEDEF_FIELD_COUNT (type) = i;
11368 /* Reverse the list order to keep the debug info elements order. */
11371 struct typedef_field *dest, *src;
11373 dest = &TYPE_TYPEDEF_FIELD (type, i);
11374 src = &fi.typedef_field_list->field;
11375 fi.typedef_field_list = fi.typedef_field_list->next;
11380 do_cleanups (back_to);
11382 if (HAVE_CPLUS_STRUCT (type))
11383 TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
11386 quirk_gcc_member_function_pointer (type, objfile);
11388 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
11389 snapshots) has been known to create a die giving a declaration
11390 for a class that has, as a child, a die giving a definition for a
11391 nested class. So we have to process our children even if the
11392 current die is a declaration. Normally, of course, a declaration
11393 won't have any children at all. */
11395 while (child_die != NULL && child_die->tag)
11397 if (child_die->tag == DW_TAG_member
11398 || child_die->tag == DW_TAG_variable
11399 || child_die->tag == DW_TAG_inheritance
11400 || child_die->tag == DW_TAG_template_value_param
11401 || child_die->tag == DW_TAG_template_type_param)
11406 process_die (child_die, cu);
11408 child_die = sibling_die (child_die);
11411 /* Do not consider external references. According to the DWARF standard,
11412 these DIEs are identified by the fact that they have no byte_size
11413 attribute, and a declaration attribute. */
11414 if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL
11415 || !die_is_declaration (die, cu))
11416 new_symbol (die, type, cu);
11419 /* Given a DW_AT_enumeration_type die, set its type. We do not
11420 complete the type's fields yet, or create any symbols. */
11422 static struct type *
11423 read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
11425 struct objfile *objfile = cu->objfile;
11427 struct attribute *attr;
11430 /* If the definition of this type lives in .debug_types, read that type.
11431 Don't follow DW_AT_specification though, that will take us back up
11432 the chain and we want to go down. */
11433 attr = dwarf2_attr_no_follow (die, DW_AT_signature);
11436 struct dwarf2_cu *type_cu = cu;
11437 struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu);
11439 type = read_type_die (type_die, type_cu);
11441 /* TYPE_CU may not be the same as CU.
11442 Ensure TYPE is recorded in CU's type_hash table. */
11443 return set_die_type (die, type, cu);
11446 type = alloc_type (objfile);
11448 TYPE_CODE (type) = TYPE_CODE_ENUM;
11449 name = dwarf2_full_name (NULL, die, cu);
11451 TYPE_TAG_NAME (type) = (char *) name;
11453 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11456 TYPE_LENGTH (type) = DW_UNSND (attr);
11460 TYPE_LENGTH (type) = 0;
11463 /* The enumeration DIE can be incomplete. In Ada, any type can be
11464 declared as private in the package spec, and then defined only
11465 inside the package body. Such types are known as Taft Amendment
11466 Types. When another package uses such a type, an incomplete DIE
11467 may be generated by the compiler. */
11468 if (die_is_declaration (die, cu))
11469 TYPE_STUB (type) = 1;
11471 return set_die_type (die, type, cu);
11474 /* Given a pointer to a die which begins an enumeration, process all
11475 the dies that define the members of the enumeration, and create the
11476 symbol for the enumeration type.
11478 NOTE: We reverse the order of the element list. */
11481 process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
11483 struct type *this_type;
11485 this_type = get_die_type (die, cu);
11486 if (this_type == NULL)
11487 this_type = read_enumeration_type (die, cu);
11489 if (die->child != NULL)
11491 struct die_info *child_die;
11492 struct symbol *sym;
11493 struct field *fields = NULL;
11494 int num_fields = 0;
11495 int unsigned_enum = 1;
11500 child_die = die->child;
11501 while (child_die && child_die->tag)
11503 if (child_die->tag != DW_TAG_enumerator)
11505 process_die (child_die, cu);
11509 name = dwarf2_name (child_die, cu);
11512 sym = new_symbol (child_die, this_type, cu);
11513 if (SYMBOL_VALUE (sym) < 0)
11518 else if ((mask & SYMBOL_VALUE (sym)) != 0)
11521 mask |= SYMBOL_VALUE (sym);
11523 if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0)
11525 fields = (struct field *)
11527 (num_fields + DW_FIELD_ALLOC_CHUNK)
11528 * sizeof (struct field));
11531 FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym);
11532 FIELD_TYPE (fields[num_fields]) = NULL;
11533 SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym));
11534 FIELD_BITSIZE (fields[num_fields]) = 0;
11540 child_die = sibling_die (child_die);
11545 TYPE_NFIELDS (this_type) = num_fields;
11546 TYPE_FIELDS (this_type) = (struct field *)
11547 TYPE_ALLOC (this_type, sizeof (struct field) * num_fields);
11548 memcpy (TYPE_FIELDS (this_type), fields,
11549 sizeof (struct field) * num_fields);
11553 TYPE_UNSIGNED (this_type) = 1;
11555 TYPE_FLAG_ENUM (this_type) = 1;
11558 /* If we are reading an enum from a .debug_types unit, and the enum
11559 is a declaration, and the enum is not the signatured type in the
11560 unit, then we do not want to add a symbol for it. Adding a
11561 symbol would in some cases obscure the true definition of the
11562 enum, giving users an incomplete type when the definition is
11563 actually available. Note that we do not want to do this for all
11564 enums which are just declarations, because C++0x allows forward
11565 enum declarations. */
11566 if (cu->per_cu->is_debug_types
11567 && die_is_declaration (die, cu))
11569 struct signatured_type *sig_type;
11572 = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile,
11573 cu->per_cu->info_or_types_section,
11574 cu->per_cu->offset);
11575 gdb_assert (sig_type->type_offset_in_section.sect_off != 0);
11576 if (sig_type->type_offset_in_section.sect_off != die->offset.sect_off)
11580 new_symbol (die, this_type, cu);
11583 /* Extract all information from a DW_TAG_array_type DIE and put it in
11584 the DIE's type field. For now, this only handles one dimensional
11587 static struct type *
11588 read_array_type (struct die_info *die, struct dwarf2_cu *cu)
11590 struct objfile *objfile = cu->objfile;
11591 struct die_info *child_die;
11593 struct type *element_type, *range_type, *index_type;
11594 struct type **range_types = NULL;
11595 struct attribute *attr;
11597 struct cleanup *back_to;
11600 element_type = die_type (die, cu);
11602 /* The die_type call above may have already set the type for this DIE. */
11603 type = get_die_type (die, cu);
11607 /* Irix 6.2 native cc creates array types without children for
11608 arrays with unspecified length. */
11609 if (die->child == NULL)
11611 index_type = objfile_type (objfile)->builtin_int;
11612 range_type = create_range_type (NULL, index_type, 0, -1);
11613 type = create_array_type (NULL, element_type, range_type);
11614 return set_die_type (die, type, cu);
11617 back_to = make_cleanup (null_cleanup, NULL);
11618 child_die = die->child;
11619 while (child_die && child_die->tag)
11621 if (child_die->tag == DW_TAG_subrange_type)
11623 struct type *child_type = read_type_die (child_die, cu);
11625 if (child_type != NULL)
11627 /* The range type was succesfully read. Save it for the
11628 array type creation. */
11629 if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0)
11631 range_types = (struct type **)
11632 xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK)
11633 * sizeof (struct type *));
11635 make_cleanup (free_current_contents, &range_types);
11637 range_types[ndim++] = child_type;
11640 child_die = sibling_die (child_die);
11643 /* Dwarf2 dimensions are output from left to right, create the
11644 necessary array types in backwards order. */
11646 type = element_type;
11648 if (read_array_order (die, cu) == DW_ORD_col_major)
11653 type = create_array_type (NULL, type, range_types[i++]);
11658 type = create_array_type (NULL, type, range_types[ndim]);
11661 /* Understand Dwarf2 support for vector types (like they occur on
11662 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
11663 array type. This is not part of the Dwarf2/3 standard yet, but a
11664 custom vendor extension. The main difference between a regular
11665 array and the vector variant is that vectors are passed by value
11667 attr = dwarf2_attr (die, DW_AT_GNU_vector, cu);
11669 make_vector_type (type);
11671 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
11672 implementation may choose to implement triple vectors using this
11674 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11677 if (DW_UNSND (attr) >= TYPE_LENGTH (type))
11678 TYPE_LENGTH (type) = DW_UNSND (attr);
11680 complaint (&symfile_complaints,
11681 _("DW_AT_byte_size for array type smaller "
11682 "than the total size of elements"));
11685 name = dwarf2_name (die, cu);
11687 TYPE_NAME (type) = name;
11689 /* Install the type in the die. */
11690 set_die_type (die, type, cu);
11692 /* set_die_type should be already done. */
11693 set_descriptive_type (type, die, cu);
11695 do_cleanups (back_to);
11700 static enum dwarf_array_dim_ordering
11701 read_array_order (struct die_info *die, struct dwarf2_cu *cu)
11703 struct attribute *attr;
11705 attr = dwarf2_attr (die, DW_AT_ordering, cu);
11707 if (attr) return DW_SND (attr);
11709 /* GNU F77 is a special case, as at 08/2004 array type info is the
11710 opposite order to the dwarf2 specification, but data is still
11711 laid out as per normal fortran.
11713 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
11714 version checking. */
11716 if (cu->language == language_fortran
11717 && cu->producer && strstr (cu->producer, "GNU F77"))
11719 return DW_ORD_row_major;
11722 switch (cu->language_defn->la_array_ordering)
11724 case array_column_major:
11725 return DW_ORD_col_major;
11726 case array_row_major:
11728 return DW_ORD_row_major;
11732 /* Extract all information from a DW_TAG_set_type DIE and put it in
11733 the DIE's type field. */
11735 static struct type *
11736 read_set_type (struct die_info *die, struct dwarf2_cu *cu)
11738 struct type *domain_type, *set_type;
11739 struct attribute *attr;
11741 domain_type = die_type (die, cu);
11743 /* The die_type call above may have already set the type for this DIE. */
11744 set_type = get_die_type (die, cu);
11748 set_type = create_set_type (NULL, domain_type);
11750 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
11752 TYPE_LENGTH (set_type) = DW_UNSND (attr);
11754 return set_die_type (die, set_type, cu);
11757 /* A helper for read_common_block that creates a locexpr baton.
11758 SYM is the symbol which we are marking as computed.
11759 COMMON_DIE is the DIE for the common block.
11760 COMMON_LOC is the location expression attribute for the common
11762 MEMBER_LOC is the location expression attribute for the particular
11763 member of the common block that we are processing.
11764 CU is the CU from which the above come. */
11767 mark_common_block_symbol_computed (struct symbol *sym,
11768 struct die_info *common_die,
11769 struct attribute *common_loc,
11770 struct attribute *member_loc,
11771 struct dwarf2_cu *cu)
11773 struct objfile *objfile = dwarf2_per_objfile->objfile;
11774 struct dwarf2_locexpr_baton *baton;
11776 unsigned int cu_off;
11777 enum bfd_endian byte_order = gdbarch_byte_order (get_objfile_arch (objfile));
11778 LONGEST offset = 0;
11780 gdb_assert (common_loc && member_loc);
11781 gdb_assert (attr_form_is_block (common_loc));
11782 gdb_assert (attr_form_is_block (member_loc)
11783 || attr_form_is_constant (member_loc));
11785 baton = obstack_alloc (&objfile->objfile_obstack,
11786 sizeof (struct dwarf2_locexpr_baton));
11787 baton->per_cu = cu->per_cu;
11788 gdb_assert (baton->per_cu);
11790 baton->size = 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
11792 if (attr_form_is_constant (member_loc))
11794 offset = dwarf2_get_attr_constant_value (member_loc, 0);
11795 baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
11798 baton->size += DW_BLOCK (member_loc)->size;
11800 ptr = obstack_alloc (&objfile->objfile_obstack, baton->size);
11803 *ptr++ = DW_OP_call4;
11804 cu_off = common_die->offset.sect_off - cu->per_cu->offset.sect_off;
11805 store_unsigned_integer (ptr, 4, byte_order, cu_off);
11808 if (attr_form_is_constant (member_loc))
11810 *ptr++ = DW_OP_addr;
11811 store_unsigned_integer (ptr, cu->header.addr_size, byte_order, offset);
11812 ptr += cu->header.addr_size;
11816 /* We have to copy the data here, because DW_OP_call4 will only
11817 use a DW_AT_location attribute. */
11818 memcpy (ptr, DW_BLOCK (member_loc)->data, DW_BLOCK (member_loc)->size);
11819 ptr += DW_BLOCK (member_loc)->size;
11822 *ptr++ = DW_OP_plus;
11823 gdb_assert (ptr - baton->data == baton->size);
11825 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
11826 SYMBOL_LOCATION_BATON (sym) = baton;
11827 SYMBOL_CLASS (sym) = LOC_COMPUTED;
11830 /* Create appropriate locally-scoped variables for all the
11831 DW_TAG_common_block entries. Also create a struct common_block
11832 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
11833 is used to sepate the common blocks name namespace from regular
11837 read_common_block (struct die_info *die, struct dwarf2_cu *cu)
11839 struct attribute *attr;
11841 attr = dwarf2_attr (die, DW_AT_location, cu);
11844 /* Support the .debug_loc offsets. */
11845 if (attr_form_is_block (attr))
11849 else if (attr_form_is_section_offset (attr))
11851 dwarf2_complex_location_expr_complaint ();
11856 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
11857 "common block member");
11862 if (die->child != NULL)
11864 struct objfile *objfile = cu->objfile;
11865 struct die_info *child_die;
11866 size_t n_entries = 0, size;
11867 struct common_block *common_block;
11868 struct symbol *sym;
11870 for (child_die = die->child;
11871 child_die && child_die->tag;
11872 child_die = sibling_die (child_die))
11875 size = (sizeof (struct common_block)
11876 + (n_entries - 1) * sizeof (struct symbol *));
11877 common_block = obstack_alloc (&objfile->objfile_obstack, size);
11878 memset (common_block->contents, 0, n_entries * sizeof (struct symbol *));
11879 common_block->n_entries = 0;
11881 for (child_die = die->child;
11882 child_die && child_die->tag;
11883 child_die = sibling_die (child_die))
11885 /* Create the symbol in the DW_TAG_common_block block in the current
11887 sym = new_symbol (child_die, NULL, cu);
11890 struct attribute *member_loc;
11892 common_block->contents[common_block->n_entries++] = sym;
11894 member_loc = dwarf2_attr (child_die, DW_AT_data_member_location,
11898 /* GDB has handled this for a long time, but it is
11899 not specified by DWARF. It seems to have been
11900 emitted by gfortran at least as recently as:
11901 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
11902 complaint (&symfile_complaints,
11903 _("Variable in common block has "
11904 "DW_AT_data_member_location "
11905 "- DIE at 0x%x [in module %s]"),
11906 child_die->offset.sect_off, cu->objfile->name);
11908 if (attr_form_is_section_offset (member_loc))
11909 dwarf2_complex_location_expr_complaint ();
11910 else if (attr_form_is_constant (member_loc)
11911 || attr_form_is_block (member_loc))
11914 mark_common_block_symbol_computed (sym, die, attr,
11918 dwarf2_complex_location_expr_complaint ();
11923 sym = new_symbol (die, objfile_type (objfile)->builtin_void, cu);
11924 SYMBOL_VALUE_COMMON_BLOCK (sym) = common_block;
11928 /* Create a type for a C++ namespace. */
11930 static struct type *
11931 read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
11933 struct objfile *objfile = cu->objfile;
11934 const char *previous_prefix, *name;
11938 /* For extensions, reuse the type of the original namespace. */
11939 if (dwarf2_attr (die, DW_AT_extension, cu) != NULL)
11941 struct die_info *ext_die;
11942 struct dwarf2_cu *ext_cu = cu;
11944 ext_die = dwarf2_extension (die, &ext_cu);
11945 type = read_type_die (ext_die, ext_cu);
11947 /* EXT_CU may not be the same as CU.
11948 Ensure TYPE is recorded in CU's type_hash table. */
11949 return set_die_type (die, type, cu);
11952 name = namespace_name (die, &is_anonymous, cu);
11954 /* Now build the name of the current namespace. */
11956 previous_prefix = determine_prefix (die, cu);
11957 if (previous_prefix[0] != '\0')
11958 name = typename_concat (&objfile->objfile_obstack,
11959 previous_prefix, name, 0, cu);
11961 /* Create the type. */
11962 type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL,
11964 TYPE_NAME (type) = (char *) name;
11965 TYPE_TAG_NAME (type) = TYPE_NAME (type);
11967 return set_die_type (die, type, cu);
11970 /* Read a C++ namespace. */
11973 read_namespace (struct die_info *die, struct dwarf2_cu *cu)
11975 struct objfile *objfile = cu->objfile;
11978 /* Add a symbol associated to this if we haven't seen the namespace
11979 before. Also, add a using directive if it's an anonymous
11982 if (dwarf2_attr (die, DW_AT_extension, cu) == NULL)
11986 type = read_type_die (die, cu);
11987 new_symbol (die, type, cu);
11989 namespace_name (die, &is_anonymous, cu);
11992 const char *previous_prefix = determine_prefix (die, cu);
11994 cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL,
11995 NULL, NULL, &objfile->objfile_obstack);
11999 if (die->child != NULL)
12001 struct die_info *child_die = die->child;
12003 while (child_die && child_die->tag)
12005 process_die (child_die, cu);
12006 child_die = sibling_die (child_die);
12011 /* Read a Fortran module as type. This DIE can be only a declaration used for
12012 imported module. Still we need that type as local Fortran "use ... only"
12013 declaration imports depend on the created type in determine_prefix. */
12015 static struct type *
12016 read_module_type (struct die_info *die, struct dwarf2_cu *cu)
12018 struct objfile *objfile = cu->objfile;
12022 module_name = dwarf2_name (die, cu);
12024 complaint (&symfile_complaints,
12025 _("DW_TAG_module has no name, offset 0x%x"),
12026 die->offset.sect_off);
12027 type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile);
12029 /* determine_prefix uses TYPE_TAG_NAME. */
12030 TYPE_TAG_NAME (type) = TYPE_NAME (type);
12032 return set_die_type (die, type, cu);
12035 /* Read a Fortran module. */
12038 read_module (struct die_info *die, struct dwarf2_cu *cu)
12040 struct die_info *child_die = die->child;
12042 while (child_die && child_die->tag)
12044 process_die (child_die, cu);
12045 child_die = sibling_die (child_die);
12049 /* Return the name of the namespace represented by DIE. Set
12050 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
12053 static const char *
12054 namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu)
12056 struct die_info *current_die;
12057 const char *name = NULL;
12059 /* Loop through the extensions until we find a name. */
12061 for (current_die = die;
12062 current_die != NULL;
12063 current_die = dwarf2_extension (die, &cu))
12065 name = dwarf2_name (current_die, cu);
12070 /* Is it an anonymous namespace? */
12072 *is_anonymous = (name == NULL);
12074 name = CP_ANONYMOUS_NAMESPACE_STR;
12079 /* Extract all information from a DW_TAG_pointer_type DIE and add to
12080 the user defined type vector. */
12082 static struct type *
12083 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
12085 struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
12086 struct comp_unit_head *cu_header = &cu->header;
12088 struct attribute *attr_byte_size;
12089 struct attribute *attr_address_class;
12090 int byte_size, addr_class;
12091 struct type *target_type;
12093 target_type = die_type (die, cu);
12095 /* The die_type call above may have already set the type for this DIE. */
12096 type = get_die_type (die, cu);
12100 type = lookup_pointer_type (target_type);
12102 attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
12103 if (attr_byte_size)
12104 byte_size = DW_UNSND (attr_byte_size);
12106 byte_size = cu_header->addr_size;
12108 attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu);
12109 if (attr_address_class)
12110 addr_class = DW_UNSND (attr_address_class);
12112 addr_class = DW_ADDR_none;
12114 /* If the pointer size or address class is different than the
12115 default, create a type variant marked as such and set the
12116 length accordingly. */
12117 if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
12119 if (gdbarch_address_class_type_flags_p (gdbarch))
12123 type_flags = gdbarch_address_class_type_flags
12124 (gdbarch, byte_size, addr_class);
12125 gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
12127 type = make_type_with_address_space (type, type_flags);
12129 else if (TYPE_LENGTH (type) != byte_size)
12131 complaint (&symfile_complaints,
12132 _("invalid pointer size %d"), byte_size);
12136 /* Should we also complain about unhandled address classes? */
12140 TYPE_LENGTH (type) = byte_size;
12141 return set_die_type (die, type, cu);
12144 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
12145 the user defined type vector. */
12147 static struct type *
12148 read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
12151 struct type *to_type;
12152 struct type *domain;
12154 to_type = die_type (die, cu);
12155 domain = die_containing_type (die, cu);
12157 /* The calls above may have already set the type for this DIE. */
12158 type = get_die_type (die, cu);
12162 if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD)
12163 type = lookup_methodptr_type (to_type);
12165 type = lookup_memberptr_type (to_type, domain);
12167 return set_die_type (die, type, cu);
12170 /* Extract all information from a DW_TAG_reference_type DIE and add to
12171 the user defined type vector. */
12173 static struct type *
12174 read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
12176 struct comp_unit_head *cu_header = &cu->header;
12177 struct type *type, *target_type;
12178 struct attribute *attr;
12180 target_type = die_type (die, cu);
12182 /* The die_type call above may have already set the type for this DIE. */
12183 type = get_die_type (die, cu);
12187 type = lookup_reference_type (target_type);
12188 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12191 TYPE_LENGTH (type) = DW_UNSND (attr);
12195 TYPE_LENGTH (type) = cu_header->addr_size;
12197 return set_die_type (die, type, cu);
12200 static struct type *
12201 read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu)
12203 struct type *base_type, *cv_type;
12205 base_type = die_type (die, cu);
12207 /* The die_type call above may have already set the type for this DIE. */
12208 cv_type = get_die_type (die, cu);
12212 /* In case the const qualifier is applied to an array type, the element type
12213 is so qualified, not the array type (section 6.7.3 of C99). */
12214 if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY)
12216 struct type *el_type, *inner_array;
12218 base_type = copy_type (base_type);
12219 inner_array = base_type;
12221 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY)
12223 TYPE_TARGET_TYPE (inner_array) =
12224 copy_type (TYPE_TARGET_TYPE (inner_array));
12225 inner_array = TYPE_TARGET_TYPE (inner_array);
12228 el_type = TYPE_TARGET_TYPE (inner_array);
12229 TYPE_TARGET_TYPE (inner_array) =
12230 make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL);
12232 return set_die_type (die, base_type, cu);
12235 cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0);
12236 return set_die_type (die, cv_type, cu);
12239 static struct type *
12240 read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu)
12242 struct type *base_type, *cv_type;
12244 base_type = die_type (die, cu);
12246 /* The die_type call above may have already set the type for this DIE. */
12247 cv_type = get_die_type (die, cu);
12251 cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0);
12252 return set_die_type (die, cv_type, cu);
12255 /* Extract all information from a DW_TAG_string_type DIE and add to
12256 the user defined type vector. It isn't really a user defined type,
12257 but it behaves like one, with other DIE's using an AT_user_def_type
12258 attribute to reference it. */
12260 static struct type *
12261 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
12263 struct objfile *objfile = cu->objfile;
12264 struct gdbarch *gdbarch = get_objfile_arch (objfile);
12265 struct type *type, *range_type, *index_type, *char_type;
12266 struct attribute *attr;
12267 unsigned int length;
12269 attr = dwarf2_attr (die, DW_AT_string_length, cu);
12272 length = DW_UNSND (attr);
12276 /* Check for the DW_AT_byte_size attribute. */
12277 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12280 length = DW_UNSND (attr);
12288 index_type = objfile_type (objfile)->builtin_int;
12289 range_type = create_range_type (NULL, index_type, 1, length);
12290 char_type = language_string_char_type (cu->language_defn, gdbarch);
12291 type = create_string_type (NULL, char_type, range_type);
12293 return set_die_type (die, type, cu);
12296 /* Handle DIES due to C code like:
12300 int (*funcp)(int a, long l);
12304 ('funcp' generates a DW_TAG_subroutine_type DIE). */
12306 static struct type *
12307 read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
12309 struct objfile *objfile = cu->objfile;
12310 struct type *type; /* Type that this function returns. */
12311 struct type *ftype; /* Function that returns above type. */
12312 struct attribute *attr;
12314 type = die_type (die, cu);
12316 /* The die_type call above may have already set the type for this DIE. */
12317 ftype = get_die_type (die, cu);
12321 ftype = lookup_function_type (type);
12323 /* All functions in C++, Pascal and Java have prototypes. */
12324 attr = dwarf2_attr (die, DW_AT_prototyped, cu);
12325 if ((attr && (DW_UNSND (attr) != 0))
12326 || cu->language == language_cplus
12327 || cu->language == language_java
12328 || cu->language == language_pascal)
12329 TYPE_PROTOTYPED (ftype) = 1;
12330 else if (producer_is_realview (cu->producer))
12331 /* RealView does not emit DW_AT_prototyped. We can not
12332 distinguish prototyped and unprototyped functions; default to
12333 prototyped, since that is more common in modern code (and
12334 RealView warns about unprototyped functions). */
12335 TYPE_PROTOTYPED (ftype) = 1;
12337 /* Store the calling convention in the type if it's available in
12338 the subroutine die. Otherwise set the calling convention to
12339 the default value DW_CC_normal. */
12340 attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
12342 TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
12343 else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
12344 TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
12346 TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal;
12348 /* We need to add the subroutine type to the die immediately so
12349 we don't infinitely recurse when dealing with parameters
12350 declared as the same subroutine type. */
12351 set_die_type (die, ftype, cu);
12353 if (die->child != NULL)
12355 struct type *void_type = objfile_type (objfile)->builtin_void;
12356 struct die_info *child_die;
12357 int nparams, iparams;
12359 /* Count the number of parameters.
12360 FIXME: GDB currently ignores vararg functions, but knows about
12361 vararg member functions. */
12363 child_die = die->child;
12364 while (child_die && child_die->tag)
12366 if (child_die->tag == DW_TAG_formal_parameter)
12368 else if (child_die->tag == DW_TAG_unspecified_parameters)
12369 TYPE_VARARGS (ftype) = 1;
12370 child_die = sibling_die (child_die);
12373 /* Allocate storage for parameters and fill them in. */
12374 TYPE_NFIELDS (ftype) = nparams;
12375 TYPE_FIELDS (ftype) = (struct field *)
12376 TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
12378 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
12379 even if we error out during the parameters reading below. */
12380 for (iparams = 0; iparams < nparams; iparams++)
12381 TYPE_FIELD_TYPE (ftype, iparams) = void_type;
12384 child_die = die->child;
12385 while (child_die && child_die->tag)
12387 if (child_die->tag == DW_TAG_formal_parameter)
12389 struct type *arg_type;
12391 /* DWARF version 2 has no clean way to discern C++
12392 static and non-static member functions. G++ helps
12393 GDB by marking the first parameter for non-static
12394 member functions (which is the this pointer) as
12395 artificial. We pass this information to
12396 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
12398 DWARF version 3 added DW_AT_object_pointer, which GCC
12399 4.5 does not yet generate. */
12400 attr = dwarf2_attr (child_die, DW_AT_artificial, cu);
12402 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr);
12405 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
12407 /* GCC/43521: In java, the formal parameter
12408 "this" is sometimes not marked with DW_AT_artificial. */
12409 if (cu->language == language_java)
12411 const char *name = dwarf2_name (child_die, cu);
12413 if (name && !strcmp (name, "this"))
12414 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1;
12417 arg_type = die_type (child_die, cu);
12419 /* RealView does not mark THIS as const, which the testsuite
12420 expects. GCC marks THIS as const in method definitions,
12421 but not in the class specifications (GCC PR 43053). */
12422 if (cu->language == language_cplus && !TYPE_CONST (arg_type)
12423 && TYPE_FIELD_ARTIFICIAL (ftype, iparams))
12426 struct dwarf2_cu *arg_cu = cu;
12427 const char *name = dwarf2_name (child_die, cu);
12429 attr = dwarf2_attr (die, DW_AT_object_pointer, cu);
12432 /* If the compiler emits this, use it. */
12433 if (follow_die_ref (die, attr, &arg_cu) == child_die)
12436 else if (name && strcmp (name, "this") == 0)
12437 /* Function definitions will have the argument names. */
12439 else if (name == NULL && iparams == 0)
12440 /* Declarations may not have the names, so like
12441 elsewhere in GDB, assume an artificial first
12442 argument is "this". */
12446 arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type),
12450 TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
12453 child_die = sibling_die (child_die);
12460 static struct type *
12461 read_typedef (struct die_info *die, struct dwarf2_cu *cu)
12463 struct objfile *objfile = cu->objfile;
12464 const char *name = NULL;
12465 struct type *this_type, *target_type;
12467 name = dwarf2_full_name (NULL, die, cu);
12468 this_type = init_type (TYPE_CODE_TYPEDEF, 0,
12469 TYPE_FLAG_TARGET_STUB, NULL, objfile);
12470 TYPE_NAME (this_type) = (char *) name;
12471 set_die_type (die, this_type, cu);
12472 target_type = die_type (die, cu);
12473 if (target_type != this_type)
12474 TYPE_TARGET_TYPE (this_type) = target_type;
12477 /* Self-referential typedefs are, it seems, not allowed by the DWARF
12478 spec and cause infinite loops in GDB. */
12479 complaint (&symfile_complaints,
12480 _("Self-referential DW_TAG_typedef "
12481 "- DIE at 0x%x [in module %s]"),
12482 die->offset.sect_off, objfile->name);
12483 TYPE_TARGET_TYPE (this_type) = NULL;
12488 /* Find a representation of a given base type and install
12489 it in the TYPE field of the die. */
12491 static struct type *
12492 read_base_type (struct die_info *die, struct dwarf2_cu *cu)
12494 struct objfile *objfile = cu->objfile;
12496 struct attribute *attr;
12497 int encoding = 0, size = 0;
12499 enum type_code code = TYPE_CODE_INT;
12500 int type_flags = 0;
12501 struct type *target_type = NULL;
12503 attr = dwarf2_attr (die, DW_AT_encoding, cu);
12506 encoding = DW_UNSND (attr);
12508 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12511 size = DW_UNSND (attr);
12513 name = dwarf2_name (die, cu);
12516 complaint (&symfile_complaints,
12517 _("DW_AT_name missing from DW_TAG_base_type"));
12522 case DW_ATE_address:
12523 /* Turn DW_ATE_address into a void * pointer. */
12524 code = TYPE_CODE_PTR;
12525 type_flags |= TYPE_FLAG_UNSIGNED;
12526 target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
12528 case DW_ATE_boolean:
12529 code = TYPE_CODE_BOOL;
12530 type_flags |= TYPE_FLAG_UNSIGNED;
12532 case DW_ATE_complex_float:
12533 code = TYPE_CODE_COMPLEX;
12534 target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile);
12536 case DW_ATE_decimal_float:
12537 code = TYPE_CODE_DECFLOAT;
12540 code = TYPE_CODE_FLT;
12542 case DW_ATE_signed:
12544 case DW_ATE_unsigned:
12545 type_flags |= TYPE_FLAG_UNSIGNED;
12546 if (cu->language == language_fortran
12548 && strncmp (name, "character(", sizeof ("character(") - 1) == 0)
12549 code = TYPE_CODE_CHAR;
12551 case DW_ATE_signed_char:
12552 if (cu->language == language_ada || cu->language == language_m2
12553 || cu->language == language_pascal
12554 || cu->language == language_fortran)
12555 code = TYPE_CODE_CHAR;
12557 case DW_ATE_unsigned_char:
12558 if (cu->language == language_ada || cu->language == language_m2
12559 || cu->language == language_pascal
12560 || cu->language == language_fortran)
12561 code = TYPE_CODE_CHAR;
12562 type_flags |= TYPE_FLAG_UNSIGNED;
12565 /* We just treat this as an integer and then recognize the
12566 type by name elsewhere. */
12570 complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"),
12571 dwarf_type_encoding_name (encoding));
12575 type = init_type (code, size, type_flags, NULL, objfile);
12576 TYPE_NAME (type) = name;
12577 TYPE_TARGET_TYPE (type) = target_type;
12579 if (name && strcmp (name, "char") == 0)
12580 TYPE_NOSIGN (type) = 1;
12582 return set_die_type (die, type, cu);
12585 /* Read the given DW_AT_subrange DIE. */
12587 static struct type *
12588 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
12590 struct type *base_type;
12591 struct type *range_type;
12592 struct attribute *attr;
12594 int low_default_is_valid;
12596 LONGEST negative_mask;
12598 base_type = die_type (die, cu);
12599 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
12600 check_typedef (base_type);
12602 /* The die_type call above may have already set the type for this DIE. */
12603 range_type = get_die_type (die, cu);
12607 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
12608 omitting DW_AT_lower_bound. */
12609 switch (cu->language)
12612 case language_cplus:
12614 low_default_is_valid = 1;
12616 case language_fortran:
12618 low_default_is_valid = 1;
12621 case language_java:
12622 case language_objc:
12624 low_default_is_valid = (cu->header.version >= 4);
12628 case language_pascal:
12630 low_default_is_valid = (cu->header.version >= 4);
12634 low_default_is_valid = 0;
12638 /* FIXME: For variable sized arrays either of these could be
12639 a variable rather than a constant value. We'll allow it,
12640 but we don't know how to handle it. */
12641 attr = dwarf2_attr (die, DW_AT_lower_bound, cu);
12643 low = dwarf2_get_attr_constant_value (attr, low);
12644 else if (!low_default_is_valid)
12645 complaint (&symfile_complaints, _("Missing DW_AT_lower_bound "
12646 "- DIE at 0x%x [in module %s]"),
12647 die->offset.sect_off, cu->objfile->name);
12649 attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
12652 if (attr_form_is_block (attr) || is_ref_attr (attr))
12654 /* GCC encodes arrays with unspecified or dynamic length
12655 with a DW_FORM_block1 attribute or a reference attribute.
12656 FIXME: GDB does not yet know how to handle dynamic
12657 arrays properly, treat them as arrays with unspecified
12660 FIXME: jimb/2003-09-22: GDB does not really know
12661 how to handle arrays of unspecified length
12662 either; we just represent them as zero-length
12663 arrays. Choose an appropriate upper bound given
12664 the lower bound we've computed above. */
12668 high = dwarf2_get_attr_constant_value (attr, 1);
12672 attr = dwarf2_attr (die, DW_AT_count, cu);
12675 int count = dwarf2_get_attr_constant_value (attr, 1);
12676 high = low + count - 1;
12680 /* Unspecified array length. */
12685 /* Dwarf-2 specifications explicitly allows to create subrange types
12686 without specifying a base type.
12687 In that case, the base type must be set to the type of
12688 the lower bound, upper bound or count, in that order, if any of these
12689 three attributes references an object that has a type.
12690 If no base type is found, the Dwarf-2 specifications say that
12691 a signed integer type of size equal to the size of an address should
12693 For the following C code: `extern char gdb_int [];'
12694 GCC produces an empty range DIE.
12695 FIXME: muller/2010-05-28: Possible references to object for low bound,
12696 high bound or count are not yet handled by this code. */
12697 if (TYPE_CODE (base_type) == TYPE_CODE_VOID)
12699 struct objfile *objfile = cu->objfile;
12700 struct gdbarch *gdbarch = get_objfile_arch (objfile);
12701 int addr_size = gdbarch_addr_bit (gdbarch) /8;
12702 struct type *int_type = objfile_type (objfile)->builtin_int;
12704 /* Test "int", "long int", and "long long int" objfile types,
12705 and select the first one having a size above or equal to the
12706 architecture address size. */
12707 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
12708 base_type = int_type;
12711 int_type = objfile_type (objfile)->builtin_long;
12712 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
12713 base_type = int_type;
12716 int_type = objfile_type (objfile)->builtin_long_long;
12717 if (int_type && TYPE_LENGTH (int_type) >= addr_size)
12718 base_type = int_type;
12724 (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1);
12725 if (!TYPE_UNSIGNED (base_type) && (low & negative_mask))
12726 low |= negative_mask;
12727 if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
12728 high |= negative_mask;
12730 range_type = create_range_type (NULL, base_type, low, high);
12732 /* Mark arrays with dynamic length at least as an array of unspecified
12733 length. GDB could check the boundary but before it gets implemented at
12734 least allow accessing the array elements. */
12735 if (attr && attr_form_is_block (attr))
12736 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
12738 /* Ada expects an empty array on no boundary attributes. */
12739 if (attr == NULL && cu->language != language_ada)
12740 TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
12742 name = dwarf2_name (die, cu);
12744 TYPE_NAME (range_type) = name;
12746 attr = dwarf2_attr (die, DW_AT_byte_size, cu);
12748 TYPE_LENGTH (range_type) = DW_UNSND (attr);
12750 set_die_type (die, range_type, cu);
12752 /* set_die_type should be already done. */
12753 set_descriptive_type (range_type, die, cu);
12758 static struct type *
12759 read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
12763 /* For now, we only support the C meaning of an unspecified type: void. */
12765 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile);
12766 TYPE_NAME (type) = dwarf2_name (die, cu);
12768 return set_die_type (die, type, cu);
12771 /* Read a single die and all its descendents. Set the die's sibling
12772 field to NULL; set other fields in the die correctly, and set all
12773 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
12774 location of the info_ptr after reading all of those dies. PARENT
12775 is the parent of the die in question. */
12777 static struct die_info *
12778 read_die_and_children (const struct die_reader_specs *reader,
12779 gdb_byte *info_ptr,
12780 gdb_byte **new_info_ptr,
12781 struct die_info *parent)
12783 struct die_info *die;
12787 cur_ptr = read_full_die (reader, &die, info_ptr, &has_children);
12790 *new_info_ptr = cur_ptr;
12793 store_in_ref_table (die, reader->cu);
12796 die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die);
12800 *new_info_ptr = cur_ptr;
12803 die->sibling = NULL;
12804 die->parent = parent;
12808 /* Read a die, all of its descendents, and all of its siblings; set
12809 all of the fields of all of the dies correctly. Arguments are as
12810 in read_die_and_children. */
12812 static struct die_info *
12813 read_die_and_siblings (const struct die_reader_specs *reader,
12814 gdb_byte *info_ptr,
12815 gdb_byte **new_info_ptr,
12816 struct die_info *parent)
12818 struct die_info *first_die, *last_sibling;
12821 cur_ptr = info_ptr;
12822 first_die = last_sibling = NULL;
12826 struct die_info *die
12827 = read_die_and_children (reader, cur_ptr, &cur_ptr, parent);
12831 *new_info_ptr = cur_ptr;
12838 last_sibling->sibling = die;
12840 last_sibling = die;
12844 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
12846 The caller is responsible for filling in the extra attributes
12847 and updating (*DIEP)->num_attrs.
12848 Set DIEP to point to a newly allocated die with its information,
12849 except for its child, sibling, and parent fields.
12850 Set HAS_CHILDREN to tell whether the die has children or not. */
12853 read_full_die_1 (const struct die_reader_specs *reader,
12854 struct die_info **diep, gdb_byte *info_ptr,
12855 int *has_children, int num_extra_attrs)
12857 unsigned int abbrev_number, bytes_read, i;
12858 sect_offset offset;
12859 struct abbrev_info *abbrev;
12860 struct die_info *die;
12861 struct dwarf2_cu *cu = reader->cu;
12862 bfd *abfd = reader->abfd;
12864 offset.sect_off = info_ptr - reader->buffer;
12865 abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
12866 info_ptr += bytes_read;
12867 if (!abbrev_number)
12874 abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number);
12876 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
12878 bfd_get_filename (abfd));
12880 die = dwarf_alloc_die (cu, abbrev->num_attrs + num_extra_attrs);
12881 die->offset = offset;
12882 die->tag = abbrev->tag;
12883 die->abbrev = abbrev_number;
12885 /* Make the result usable.
12886 The caller needs to update num_attrs after adding the extra
12888 die->num_attrs = abbrev->num_attrs;
12890 for (i = 0; i < abbrev->num_attrs; ++i)
12891 info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i],
12895 *has_children = abbrev->has_children;
12899 /* Read a die and all its attributes.
12900 Set DIEP to point to a newly allocated die with its information,
12901 except for its child, sibling, and parent fields.
12902 Set HAS_CHILDREN to tell whether the die has children or not. */
12905 read_full_die (const struct die_reader_specs *reader,
12906 struct die_info **diep, gdb_byte *info_ptr,
12909 return read_full_die_1 (reader, diep, info_ptr, has_children, 0);
12912 /* Abbreviation tables.
12914 In DWARF version 2, the description of the debugging information is
12915 stored in a separate .debug_abbrev section. Before we read any
12916 dies from a section we read in all abbreviations and install them
12917 in a hash table. */
12919 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
12921 static struct abbrev_info *
12922 abbrev_table_alloc_abbrev (struct abbrev_table *abbrev_table)
12924 struct abbrev_info *abbrev;
12926 abbrev = (struct abbrev_info *)
12927 obstack_alloc (&abbrev_table->abbrev_obstack, sizeof (struct abbrev_info));
12928 memset (abbrev, 0, sizeof (struct abbrev_info));
12932 /* Add an abbreviation to the table. */
12935 abbrev_table_add_abbrev (struct abbrev_table *abbrev_table,
12936 unsigned int abbrev_number,
12937 struct abbrev_info *abbrev)
12939 unsigned int hash_number;
12941 hash_number = abbrev_number % ABBREV_HASH_SIZE;
12942 abbrev->next = abbrev_table->abbrevs[hash_number];
12943 abbrev_table->abbrevs[hash_number] = abbrev;
12946 /* Look up an abbrev in the table.
12947 Returns NULL if the abbrev is not found. */
12949 static struct abbrev_info *
12950 abbrev_table_lookup_abbrev (const struct abbrev_table *abbrev_table,
12951 unsigned int abbrev_number)
12953 unsigned int hash_number;
12954 struct abbrev_info *abbrev;
12956 hash_number = abbrev_number % ABBREV_HASH_SIZE;
12957 abbrev = abbrev_table->abbrevs[hash_number];
12961 if (abbrev->number == abbrev_number)
12963 abbrev = abbrev->next;
12968 /* Read in an abbrev table. */
12970 static struct abbrev_table *
12971 abbrev_table_read_table (struct dwarf2_section_info *section,
12972 sect_offset offset)
12974 struct objfile *objfile = dwarf2_per_objfile->objfile;
12975 bfd *abfd = section->asection->owner;
12976 struct abbrev_table *abbrev_table;
12977 gdb_byte *abbrev_ptr;
12978 struct abbrev_info *cur_abbrev;
12979 unsigned int abbrev_number, bytes_read, abbrev_name;
12980 unsigned int abbrev_form;
12981 struct attr_abbrev *cur_attrs;
12982 unsigned int allocated_attrs;
12984 abbrev_table = XMALLOC (struct abbrev_table);
12985 abbrev_table->offset = offset;
12986 obstack_init (&abbrev_table->abbrev_obstack);
12987 abbrev_table->abbrevs = obstack_alloc (&abbrev_table->abbrev_obstack,
12989 * sizeof (struct abbrev_info *)));
12990 memset (abbrev_table->abbrevs, 0,
12991 ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
12993 dwarf2_read_section (objfile, section);
12994 abbrev_ptr = section->buffer + offset.sect_off;
12995 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
12996 abbrev_ptr += bytes_read;
12998 allocated_attrs = ATTR_ALLOC_CHUNK;
12999 cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev));
13001 /* Loop until we reach an abbrev number of 0. */
13002 while (abbrev_number)
13004 cur_abbrev = abbrev_table_alloc_abbrev (abbrev_table);
13006 /* read in abbrev header */
13007 cur_abbrev->number = abbrev_number;
13008 cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13009 abbrev_ptr += bytes_read;
13010 cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
13013 /* now read in declarations */
13014 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13015 abbrev_ptr += bytes_read;
13016 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13017 abbrev_ptr += bytes_read;
13018 while (abbrev_name)
13020 if (cur_abbrev->num_attrs == allocated_attrs)
13022 allocated_attrs += ATTR_ALLOC_CHUNK;
13024 = xrealloc (cur_attrs, (allocated_attrs
13025 * sizeof (struct attr_abbrev)));
13028 cur_attrs[cur_abbrev->num_attrs].name = abbrev_name;
13029 cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form;
13030 abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13031 abbrev_ptr += bytes_read;
13032 abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13033 abbrev_ptr += bytes_read;
13036 cur_abbrev->attrs = obstack_alloc (&abbrev_table->abbrev_obstack,
13037 (cur_abbrev->num_attrs
13038 * sizeof (struct attr_abbrev)));
13039 memcpy (cur_abbrev->attrs, cur_attrs,
13040 cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
13042 abbrev_table_add_abbrev (abbrev_table, abbrev_number, cur_abbrev);
13044 /* Get next abbreviation.
13045 Under Irix6 the abbreviations for a compilation unit are not
13046 always properly terminated with an abbrev number of 0.
13047 Exit loop if we encounter an abbreviation which we have
13048 already read (which means we are about to read the abbreviations
13049 for the next compile unit) or if the end of the abbreviation
13050 table is reached. */
13051 if ((unsigned int) (abbrev_ptr - section->buffer) >= section->size)
13053 abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
13054 abbrev_ptr += bytes_read;
13055 if (abbrev_table_lookup_abbrev (abbrev_table, abbrev_number) != NULL)
13060 return abbrev_table;
13063 /* Free the resources held by ABBREV_TABLE. */
13066 abbrev_table_free (struct abbrev_table *abbrev_table)
13068 obstack_free (&abbrev_table->abbrev_obstack, NULL);
13069 xfree (abbrev_table);
13072 /* Same as abbrev_table_free but as a cleanup.
13073 We pass in a pointer to the pointer to the table so that we can
13074 set the pointer to NULL when we're done. It also simplifies
13075 build_type_unit_groups. */
13078 abbrev_table_free_cleanup (void *table_ptr)
13080 struct abbrev_table **abbrev_table_ptr = table_ptr;
13082 if (*abbrev_table_ptr != NULL)
13083 abbrev_table_free (*abbrev_table_ptr);
13084 *abbrev_table_ptr = NULL;
13087 /* Read the abbrev table for CU from ABBREV_SECTION. */
13090 dwarf2_read_abbrevs (struct dwarf2_cu *cu,
13091 struct dwarf2_section_info *abbrev_section)
13094 abbrev_table_read_table (abbrev_section, cu->header.abbrev_offset);
13097 /* Release the memory used by the abbrev table for a compilation unit. */
13100 dwarf2_free_abbrev_table (void *ptr_to_cu)
13102 struct dwarf2_cu *cu = ptr_to_cu;
13104 abbrev_table_free (cu->abbrev_table);
13105 /* Set this to NULL so that we SEGV if we try to read it later,
13106 and also because free_comp_unit verifies this is NULL. */
13107 cu->abbrev_table = NULL;
13110 /* Returns nonzero if TAG represents a type that we might generate a partial
13114 is_type_tag_for_partial (int tag)
13119 /* Some types that would be reasonable to generate partial symbols for,
13120 that we don't at present. */
13121 case DW_TAG_array_type:
13122 case DW_TAG_file_type:
13123 case DW_TAG_ptr_to_member_type:
13124 case DW_TAG_set_type:
13125 case DW_TAG_string_type:
13126 case DW_TAG_subroutine_type:
13128 case DW_TAG_base_type:
13129 case DW_TAG_class_type:
13130 case DW_TAG_interface_type:
13131 case DW_TAG_enumeration_type:
13132 case DW_TAG_structure_type:
13133 case DW_TAG_subrange_type:
13134 case DW_TAG_typedef:
13135 case DW_TAG_union_type:
13142 /* Load all DIEs that are interesting for partial symbols into memory. */
13144 static struct partial_die_info *
13145 load_partial_dies (const struct die_reader_specs *reader,
13146 gdb_byte *info_ptr, int building_psymtab)
13148 struct dwarf2_cu *cu = reader->cu;
13149 struct objfile *objfile = cu->objfile;
13150 struct partial_die_info *part_die;
13151 struct partial_die_info *parent_die, *last_die, *first_die = NULL;
13152 struct abbrev_info *abbrev;
13153 unsigned int bytes_read;
13154 unsigned int load_all = 0;
13155 int nesting_level = 1;
13160 gdb_assert (cu->per_cu != NULL);
13161 if (cu->per_cu->load_all_dies)
13165 = htab_create_alloc_ex (cu->header.length / 12,
13169 &cu->comp_unit_obstack,
13170 hashtab_obstack_allocate,
13171 dummy_obstack_deallocate);
13173 part_die = obstack_alloc (&cu->comp_unit_obstack,
13174 sizeof (struct partial_die_info));
13178 abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu);
13180 /* A NULL abbrev means the end of a series of children. */
13181 if (abbrev == NULL)
13183 if (--nesting_level == 0)
13185 /* PART_DIE was probably the last thing allocated on the
13186 comp_unit_obstack, so we could call obstack_free
13187 here. We don't do that because the waste is small,
13188 and will be cleaned up when we're done with this
13189 compilation unit. This way, we're also more robust
13190 against other users of the comp_unit_obstack. */
13193 info_ptr += bytes_read;
13194 last_die = parent_die;
13195 parent_die = parent_die->die_parent;
13199 /* Check for template arguments. We never save these; if
13200 they're seen, we just mark the parent, and go on our way. */
13201 if (parent_die != NULL
13202 && cu->language == language_cplus
13203 && (abbrev->tag == DW_TAG_template_type_param
13204 || abbrev->tag == DW_TAG_template_value_param))
13206 parent_die->has_template_arguments = 1;
13210 /* We don't need a partial DIE for the template argument. */
13211 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
13216 /* We only recurse into c++ subprograms looking for template arguments.
13217 Skip their other children. */
13219 && cu->language == language_cplus
13220 && parent_die != NULL
13221 && parent_die->tag == DW_TAG_subprogram)
13223 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
13227 /* Check whether this DIE is interesting enough to save. Normally
13228 we would not be interested in members here, but there may be
13229 later variables referencing them via DW_AT_specification (for
13230 static members). */
13232 && !is_type_tag_for_partial (abbrev->tag)
13233 && abbrev->tag != DW_TAG_constant
13234 && abbrev->tag != DW_TAG_enumerator
13235 && abbrev->tag != DW_TAG_subprogram
13236 && abbrev->tag != DW_TAG_lexical_block
13237 && abbrev->tag != DW_TAG_variable
13238 && abbrev->tag != DW_TAG_namespace
13239 && abbrev->tag != DW_TAG_module
13240 && abbrev->tag != DW_TAG_member
13241 && abbrev->tag != DW_TAG_imported_unit)
13243 /* Otherwise we skip to the next sibling, if any. */
13244 info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev);
13248 info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read,
13251 /* This two-pass algorithm for processing partial symbols has a
13252 high cost in cache pressure. Thus, handle some simple cases
13253 here which cover the majority of C partial symbols. DIEs
13254 which neither have specification tags in them, nor could have
13255 specification tags elsewhere pointing at them, can simply be
13256 processed and discarded.
13258 This segment is also optional; scan_partial_symbols and
13259 add_partial_symbol will handle these DIEs if we chain
13260 them in normally. When compilers which do not emit large
13261 quantities of duplicate debug information are more common,
13262 this code can probably be removed. */
13264 /* Any complete simple types at the top level (pretty much all
13265 of them, for a language without namespaces), can be processed
13267 if (parent_die == NULL
13268 && part_die->has_specification == 0
13269 && part_die->is_declaration == 0
13270 && ((part_die->tag == DW_TAG_typedef && !part_die->has_children)
13271 || part_die->tag == DW_TAG_base_type
13272 || part_die->tag == DW_TAG_subrange_type))
13274 if (building_psymtab && part_die->name != NULL)
13275 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
13276 VAR_DOMAIN, LOC_TYPEDEF,
13277 &objfile->static_psymbols,
13278 0, (CORE_ADDR) 0, cu->language, objfile);
13279 info_ptr = locate_pdi_sibling (reader, part_die, info_ptr);
13283 /* The exception for DW_TAG_typedef with has_children above is
13284 a workaround of GCC PR debug/47510. In the case of this complaint
13285 type_name_no_tag_or_error will error on such types later.
13287 GDB skipped children of DW_TAG_typedef by the shortcut above and then
13288 it could not find the child DIEs referenced later, this is checked
13289 above. In correct DWARF DW_TAG_typedef should have no children. */
13291 if (part_die->tag == DW_TAG_typedef && part_die->has_children)
13292 complaint (&symfile_complaints,
13293 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
13294 "- DIE at 0x%x [in module %s]"),
13295 part_die->offset.sect_off, objfile->name);
13297 /* If we're at the second level, and we're an enumerator, and
13298 our parent has no specification (meaning possibly lives in a
13299 namespace elsewhere), then we can add the partial symbol now
13300 instead of queueing it. */
13301 if (part_die->tag == DW_TAG_enumerator
13302 && parent_die != NULL
13303 && parent_die->die_parent == NULL
13304 && parent_die->tag == DW_TAG_enumeration_type
13305 && parent_die->has_specification == 0)
13307 if (part_die->name == NULL)
13308 complaint (&symfile_complaints,
13309 _("malformed enumerator DIE ignored"));
13310 else if (building_psymtab)
13311 add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
13312 VAR_DOMAIN, LOC_CONST,
13313 (cu->language == language_cplus
13314 || cu->language == language_java)
13315 ? &objfile->global_psymbols
13316 : &objfile->static_psymbols,
13317 0, (CORE_ADDR) 0, cu->language, objfile);
13319 info_ptr = locate_pdi_sibling (reader, part_die, info_ptr);
13323 /* We'll save this DIE so link it in. */
13324 part_die->die_parent = parent_die;
13325 part_die->die_sibling = NULL;
13326 part_die->die_child = NULL;
13328 if (last_die && last_die == parent_die)
13329 last_die->die_child = part_die;
13331 last_die->die_sibling = part_die;
13333 last_die = part_die;
13335 if (first_die == NULL)
13336 first_die = part_die;
13338 /* Maybe add the DIE to the hash table. Not all DIEs that we
13339 find interesting need to be in the hash table, because we
13340 also have the parent/sibling/child chains; only those that we
13341 might refer to by offset later during partial symbol reading.
13343 For now this means things that might have be the target of a
13344 DW_AT_specification, DW_AT_abstract_origin, or
13345 DW_AT_extension. DW_AT_extension will refer only to
13346 namespaces; DW_AT_abstract_origin refers to functions (and
13347 many things under the function DIE, but we do not recurse
13348 into function DIEs during partial symbol reading) and
13349 possibly variables as well; DW_AT_specification refers to
13350 declarations. Declarations ought to have the DW_AT_declaration
13351 flag. It happens that GCC forgets to put it in sometimes, but
13352 only for functions, not for types.
13354 Adding more things than necessary to the hash table is harmless
13355 except for the performance cost. Adding too few will result in
13356 wasted time in find_partial_die, when we reread the compilation
13357 unit with load_all_dies set. */
13360 || abbrev->tag == DW_TAG_constant
13361 || abbrev->tag == DW_TAG_subprogram
13362 || abbrev->tag == DW_TAG_variable
13363 || abbrev->tag == DW_TAG_namespace
13364 || part_die->is_declaration)
13368 slot = htab_find_slot_with_hash (cu->partial_dies, part_die,
13369 part_die->offset.sect_off, INSERT);
13373 part_die = obstack_alloc (&cu->comp_unit_obstack,
13374 sizeof (struct partial_die_info));
13376 /* For some DIEs we want to follow their children (if any). For C
13377 we have no reason to follow the children of structures; for other
13378 languages we have to, so that we can get at method physnames
13379 to infer fully qualified class names, for DW_AT_specification,
13380 and for C++ template arguments. For C++, we also look one level
13381 inside functions to find template arguments (if the name of the
13382 function does not already contain the template arguments).
13384 For Ada, we need to scan the children of subprograms and lexical
13385 blocks as well because Ada allows the definition of nested
13386 entities that could be interesting for the debugger, such as
13387 nested subprograms for instance. */
13388 if (last_die->has_children
13390 || last_die->tag == DW_TAG_namespace
13391 || last_die->tag == DW_TAG_module
13392 || last_die->tag == DW_TAG_enumeration_type
13393 || (cu->language == language_cplus
13394 && last_die->tag == DW_TAG_subprogram
13395 && (last_die->name == NULL
13396 || strchr (last_die->name, '<') == NULL))
13397 || (cu->language != language_c
13398 && (last_die->tag == DW_TAG_class_type
13399 || last_die->tag == DW_TAG_interface_type
13400 || last_die->tag == DW_TAG_structure_type
13401 || last_die->tag == DW_TAG_union_type))
13402 || (cu->language == language_ada
13403 && (last_die->tag == DW_TAG_subprogram
13404 || last_die->tag == DW_TAG_lexical_block))))
13407 parent_die = last_die;
13411 /* Otherwise we skip to the next sibling, if any. */
13412 info_ptr = locate_pdi_sibling (reader, last_die, info_ptr);
13414 /* Back to the top, do it again. */
13418 /* Read a minimal amount of information into the minimal die structure. */
13421 read_partial_die (const struct die_reader_specs *reader,
13422 struct partial_die_info *part_die,
13423 struct abbrev_info *abbrev, unsigned int abbrev_len,
13424 gdb_byte *info_ptr)
13426 struct dwarf2_cu *cu = reader->cu;
13427 struct objfile *objfile = cu->objfile;
13428 gdb_byte *buffer = reader->buffer;
13430 struct attribute attr;
13431 int has_low_pc_attr = 0;
13432 int has_high_pc_attr = 0;
13433 int high_pc_relative = 0;
13435 memset (part_die, 0, sizeof (struct partial_die_info));
13437 part_die->offset.sect_off = info_ptr - buffer;
13439 info_ptr += abbrev_len;
13441 if (abbrev == NULL)
13444 part_die->tag = abbrev->tag;
13445 part_die->has_children = abbrev->has_children;
13447 for (i = 0; i < abbrev->num_attrs; ++i)
13449 info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr);
13451 /* Store the data if it is of an attribute we want to keep in a
13452 partial symbol table. */
13456 switch (part_die->tag)
13458 case DW_TAG_compile_unit:
13459 case DW_TAG_partial_unit:
13460 case DW_TAG_type_unit:
13461 /* Compilation units have a DW_AT_name that is a filename, not
13462 a source language identifier. */
13463 case DW_TAG_enumeration_type:
13464 case DW_TAG_enumerator:
13465 /* These tags always have simple identifiers already; no need
13466 to canonicalize them. */
13467 part_die->name = DW_STRING (&attr);
13471 = dwarf2_canonicalize_name (DW_STRING (&attr), cu,
13472 &objfile->objfile_obstack);
13476 case DW_AT_linkage_name:
13477 case DW_AT_MIPS_linkage_name:
13478 /* Note that both forms of linkage name might appear. We
13479 assume they will be the same, and we only store the last
13481 if (cu->language == language_ada)
13482 part_die->name = DW_STRING (&attr);
13483 part_die->linkage_name = DW_STRING (&attr);
13486 has_low_pc_attr = 1;
13487 part_die->lowpc = DW_ADDR (&attr);
13489 case DW_AT_high_pc:
13490 has_high_pc_attr = 1;
13491 if (attr.form == DW_FORM_addr
13492 || attr.form == DW_FORM_GNU_addr_index)
13493 part_die->highpc = DW_ADDR (&attr);
13496 high_pc_relative = 1;
13497 part_die->highpc = DW_UNSND (&attr);
13500 case DW_AT_location:
13501 /* Support the .debug_loc offsets. */
13502 if (attr_form_is_block (&attr))
13504 part_die->d.locdesc = DW_BLOCK (&attr);
13506 else if (attr_form_is_section_offset (&attr))
13508 dwarf2_complex_location_expr_complaint ();
13512 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
13513 "partial symbol information");
13516 case DW_AT_external:
13517 part_die->is_external = DW_UNSND (&attr);
13519 case DW_AT_declaration:
13520 part_die->is_declaration = DW_UNSND (&attr);
13523 part_die->has_type = 1;
13525 case DW_AT_abstract_origin:
13526 case DW_AT_specification:
13527 case DW_AT_extension:
13528 part_die->has_specification = 1;
13529 part_die->spec_offset = dwarf2_get_ref_die_offset (&attr);
13530 part_die->spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt
13531 || cu->per_cu->is_dwz);
13533 case DW_AT_sibling:
13534 /* Ignore absolute siblings, they might point outside of
13535 the current compile unit. */
13536 if (attr.form == DW_FORM_ref_addr)
13537 complaint (&symfile_complaints,
13538 _("ignoring absolute DW_AT_sibling"));
13540 part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr).sect_off;
13542 case DW_AT_byte_size:
13543 part_die->has_byte_size = 1;
13545 case DW_AT_calling_convention:
13546 /* DWARF doesn't provide a way to identify a program's source-level
13547 entry point. DW_AT_calling_convention attributes are only meant
13548 to describe functions' calling conventions.
13550 However, because it's a necessary piece of information in
13551 Fortran, and because DW_CC_program is the only piece of debugging
13552 information whose definition refers to a 'main program' at all,
13553 several compilers have begun marking Fortran main programs with
13554 DW_CC_program --- even when those functions use the standard
13555 calling conventions.
13557 So until DWARF specifies a way to provide this information and
13558 compilers pick up the new representation, we'll support this
13560 if (DW_UNSND (&attr) == DW_CC_program
13561 && cu->language == language_fortran)
13563 set_main_name (part_die->name);
13565 /* As this DIE has a static linkage the name would be difficult
13566 to look up later. */
13567 language_of_main = language_fortran;
13571 if (DW_UNSND (&attr) == DW_INL_inlined
13572 || DW_UNSND (&attr) == DW_INL_declared_inlined)
13573 part_die->may_be_inlined = 1;
13577 if (part_die->tag == DW_TAG_imported_unit)
13579 part_die->d.offset = dwarf2_get_ref_die_offset (&attr);
13580 part_die->is_dwz = (attr.form == DW_FORM_GNU_ref_alt
13581 || cu->per_cu->is_dwz);
13590 if (high_pc_relative)
13591 part_die->highpc += part_die->lowpc;
13593 if (has_low_pc_attr && has_high_pc_attr)
13595 /* When using the GNU linker, .gnu.linkonce. sections are used to
13596 eliminate duplicate copies of functions and vtables and such.
13597 The linker will arbitrarily choose one and discard the others.
13598 The AT_*_pc values for such functions refer to local labels in
13599 these sections. If the section from that file was discarded, the
13600 labels are not in the output, so the relocs get a value of 0.
13601 If this is a discarded function, mark the pc bounds as invalid,
13602 so that GDB will ignore it. */
13603 if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
13605 struct gdbarch *gdbarch = get_objfile_arch (objfile);
13607 complaint (&symfile_complaints,
13608 _("DW_AT_low_pc %s is zero "
13609 "for DIE at 0x%x [in module %s]"),
13610 paddress (gdbarch, part_die->lowpc),
13611 part_die->offset.sect_off, objfile->name);
13613 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
13614 else if (part_die->lowpc >= part_die->highpc)
13616 struct gdbarch *gdbarch = get_objfile_arch (objfile);
13618 complaint (&symfile_complaints,
13619 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
13620 "for DIE at 0x%x [in module %s]"),
13621 paddress (gdbarch, part_die->lowpc),
13622 paddress (gdbarch, part_die->highpc),
13623 part_die->offset.sect_off, objfile->name);
13626 part_die->has_pc_info = 1;
13632 /* Find a cached partial DIE at OFFSET in CU. */
13634 static struct partial_die_info *
13635 find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu)
13637 struct partial_die_info *lookup_die = NULL;
13638 struct partial_die_info part_die;
13640 part_die.offset = offset;
13641 lookup_die = htab_find_with_hash (cu->partial_dies, &part_die,
13647 /* Find a partial DIE at OFFSET, which may or may not be in CU,
13648 except in the case of .debug_types DIEs which do not reference
13649 outside their CU (they do however referencing other types via
13650 DW_FORM_ref_sig8). */
13652 static struct partial_die_info *
13653 find_partial_die (sect_offset offset, int offset_in_dwz, struct dwarf2_cu *cu)
13655 struct objfile *objfile = cu->objfile;
13656 struct dwarf2_per_cu_data *per_cu = NULL;
13657 struct partial_die_info *pd = NULL;
13659 if (offset_in_dwz == cu->per_cu->is_dwz
13660 && offset_in_cu_p (&cu->header, offset))
13662 pd = find_partial_die_in_comp_unit (offset, cu);
13665 /* We missed recording what we needed.
13666 Load all dies and try again. */
13667 per_cu = cu->per_cu;
13671 /* TUs don't reference other CUs/TUs (except via type signatures). */
13672 if (cu->per_cu->is_debug_types)
13674 error (_("Dwarf Error: Type Unit at offset 0x%lx contains"
13675 " external reference to offset 0x%lx [in module %s].\n"),
13676 (long) cu->header.offset.sect_off, (long) offset.sect_off,
13677 bfd_get_filename (objfile->obfd));
13679 per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
13682 if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
13683 load_partial_comp_unit (per_cu);
13685 per_cu->cu->last_used = 0;
13686 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
13689 /* If we didn't find it, and not all dies have been loaded,
13690 load them all and try again. */
13692 if (pd == NULL && per_cu->load_all_dies == 0)
13694 per_cu->load_all_dies = 1;
13696 /* This is nasty. When we reread the DIEs, somewhere up the call chain
13697 THIS_CU->cu may already be in use. So we can't just free it and
13698 replace its DIEs with the ones we read in. Instead, we leave those
13699 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
13700 and clobber THIS_CU->cu->partial_dies with the hash table for the new
13702 load_partial_comp_unit (per_cu);
13704 pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
13708 internal_error (__FILE__, __LINE__,
13709 _("could not find partial DIE 0x%x "
13710 "in cache [from module %s]\n"),
13711 offset.sect_off, bfd_get_filename (objfile->obfd));
13715 /* See if we can figure out if the class lives in a namespace. We do
13716 this by looking for a member function; its demangled name will
13717 contain namespace info, if there is any. */
13720 guess_partial_die_structure_name (struct partial_die_info *struct_pdi,
13721 struct dwarf2_cu *cu)
13723 /* NOTE: carlton/2003-10-07: Getting the info this way changes
13724 what template types look like, because the demangler
13725 frequently doesn't give the same name as the debug info. We
13726 could fix this by only using the demangled name to get the
13727 prefix (but see comment in read_structure_type). */
13729 struct partial_die_info *real_pdi;
13730 struct partial_die_info *child_pdi;
13732 /* If this DIE (this DIE's specification, if any) has a parent, then
13733 we should not do this. We'll prepend the parent's fully qualified
13734 name when we create the partial symbol. */
13736 real_pdi = struct_pdi;
13737 while (real_pdi->has_specification)
13738 real_pdi = find_partial_die (real_pdi->spec_offset,
13739 real_pdi->spec_is_dwz, cu);
13741 if (real_pdi->die_parent != NULL)
13744 for (child_pdi = struct_pdi->die_child;
13746 child_pdi = child_pdi->die_sibling)
13748 if (child_pdi->tag == DW_TAG_subprogram
13749 && child_pdi->linkage_name != NULL)
13751 char *actual_class_name
13752 = language_class_name_from_physname (cu->language_defn,
13753 child_pdi->linkage_name);
13754 if (actual_class_name != NULL)
13757 = obsavestring (actual_class_name,
13758 strlen (actual_class_name),
13759 &cu->objfile->objfile_obstack);
13760 xfree (actual_class_name);
13767 /* Adjust PART_DIE before generating a symbol for it. This function
13768 may set the is_external flag or change the DIE's name. */
13771 fixup_partial_die (struct partial_die_info *part_die,
13772 struct dwarf2_cu *cu)
13774 /* Once we've fixed up a die, there's no point in doing so again.
13775 This also avoids a memory leak if we were to call
13776 guess_partial_die_structure_name multiple times. */
13777 if (part_die->fixup_called)
13780 /* If we found a reference attribute and the DIE has no name, try
13781 to find a name in the referred to DIE. */
13783 if (part_die->name == NULL && part_die->has_specification)
13785 struct partial_die_info *spec_die;
13787 spec_die = find_partial_die (part_die->spec_offset,
13788 part_die->spec_is_dwz, cu);
13790 fixup_partial_die (spec_die, cu);
13792 if (spec_die->name)
13794 part_die->name = spec_die->name;
13796 /* Copy DW_AT_external attribute if it is set. */
13797 if (spec_die->is_external)
13798 part_die->is_external = spec_die->is_external;
13802 /* Set default names for some unnamed DIEs. */
13804 if (part_die->name == NULL && part_die->tag == DW_TAG_namespace)
13805 part_die->name = CP_ANONYMOUS_NAMESPACE_STR;
13807 /* If there is no parent die to provide a namespace, and there are
13808 children, see if we can determine the namespace from their linkage
13810 if (cu->language == language_cplus
13811 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
13812 && part_die->die_parent == NULL
13813 && part_die->has_children
13814 && (part_die->tag == DW_TAG_class_type
13815 || part_die->tag == DW_TAG_structure_type
13816 || part_die->tag == DW_TAG_union_type))
13817 guess_partial_die_structure_name (part_die, cu);
13819 /* GCC might emit a nameless struct or union that has a linkage
13820 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
13821 if (part_die->name == NULL
13822 && (part_die->tag == DW_TAG_class_type
13823 || part_die->tag == DW_TAG_interface_type
13824 || part_die->tag == DW_TAG_structure_type
13825 || part_die->tag == DW_TAG_union_type)
13826 && part_die->linkage_name != NULL)
13830 demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES);
13835 /* Strip any leading namespaces/classes, keep only the base name.
13836 DW_AT_name for named DIEs does not contain the prefixes. */
13837 base = strrchr (demangled, ':');
13838 if (base && base > demangled && base[-1] == ':')
13843 part_die->name = obsavestring (base, strlen (base),
13844 &cu->objfile->objfile_obstack);
13849 part_die->fixup_called = 1;
13852 /* Read an attribute value described by an attribute form. */
13855 read_attribute_value (const struct die_reader_specs *reader,
13856 struct attribute *attr, unsigned form,
13857 gdb_byte *info_ptr)
13859 struct dwarf2_cu *cu = reader->cu;
13860 bfd *abfd = reader->abfd;
13861 struct comp_unit_head *cu_header = &cu->header;
13862 unsigned int bytes_read;
13863 struct dwarf_block *blk;
13868 case DW_FORM_ref_addr:
13869 if (cu->header.version == 2)
13870 DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
13872 DW_UNSND (attr) = read_offset (abfd, info_ptr,
13873 &cu->header, &bytes_read);
13874 info_ptr += bytes_read;
13876 case DW_FORM_GNU_ref_alt:
13877 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
13878 info_ptr += bytes_read;
13881 DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
13882 info_ptr += bytes_read;
13884 case DW_FORM_block2:
13885 blk = dwarf_alloc_block (cu);
13886 blk->size = read_2_bytes (abfd, info_ptr);
13888 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
13889 info_ptr += blk->size;
13890 DW_BLOCK (attr) = blk;
13892 case DW_FORM_block4:
13893 blk = dwarf_alloc_block (cu);
13894 blk->size = read_4_bytes (abfd, info_ptr);
13896 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
13897 info_ptr += blk->size;
13898 DW_BLOCK (attr) = blk;
13900 case DW_FORM_data2:
13901 DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
13904 case DW_FORM_data4:
13905 DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
13908 case DW_FORM_data8:
13909 DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
13912 case DW_FORM_sec_offset:
13913 DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
13914 info_ptr += bytes_read;
13916 case DW_FORM_string:
13917 DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read);
13918 DW_STRING_IS_CANONICAL (attr) = 0;
13919 info_ptr += bytes_read;
13922 if (!cu->per_cu->is_dwz)
13924 DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
13926 DW_STRING_IS_CANONICAL (attr) = 0;
13927 info_ptr += bytes_read;
13931 case DW_FORM_GNU_strp_alt:
13933 struct dwz_file *dwz = dwarf2_get_dwz_file ();
13934 LONGEST str_offset = read_offset (abfd, info_ptr, cu_header,
13937 DW_STRING (attr) = read_indirect_string_from_dwz (dwz, str_offset);
13938 DW_STRING_IS_CANONICAL (attr) = 0;
13939 info_ptr += bytes_read;
13942 case DW_FORM_exprloc:
13943 case DW_FORM_block:
13944 blk = dwarf_alloc_block (cu);
13945 blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
13946 info_ptr += bytes_read;
13947 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
13948 info_ptr += blk->size;
13949 DW_BLOCK (attr) = blk;
13951 case DW_FORM_block1:
13952 blk = dwarf_alloc_block (cu);
13953 blk->size = read_1_byte (abfd, info_ptr);
13955 blk->data = read_n_bytes (abfd, info_ptr, blk->size);
13956 info_ptr += blk->size;
13957 DW_BLOCK (attr) = blk;
13959 case DW_FORM_data1:
13960 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
13964 DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
13967 case DW_FORM_flag_present:
13968 DW_UNSND (attr) = 1;
13970 case DW_FORM_sdata:
13971 DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read);
13972 info_ptr += bytes_read;
13974 case DW_FORM_udata:
13975 DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
13976 info_ptr += bytes_read;
13979 DW_UNSND (attr) = (cu->header.offset.sect_off
13980 + read_1_byte (abfd, info_ptr));
13984 DW_UNSND (attr) = (cu->header.offset.sect_off
13985 + read_2_bytes (abfd, info_ptr));
13989 DW_UNSND (attr) = (cu->header.offset.sect_off
13990 + read_4_bytes (abfd, info_ptr));
13994 DW_UNSND (attr) = (cu->header.offset.sect_off
13995 + read_8_bytes (abfd, info_ptr));
13998 case DW_FORM_ref_sig8:
13999 /* Convert the signature to something we can record in DW_UNSND
14001 NOTE: This is NULL if the type wasn't found. */
14002 DW_SIGNATURED_TYPE (attr) =
14003 lookup_signatured_type (read_8_bytes (abfd, info_ptr));
14006 case DW_FORM_ref_udata:
14007 DW_UNSND (attr) = (cu->header.offset.sect_off
14008 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
14009 info_ptr += bytes_read;
14011 case DW_FORM_indirect:
14012 form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14013 info_ptr += bytes_read;
14014 info_ptr = read_attribute_value (reader, attr, form, info_ptr);
14016 case DW_FORM_GNU_addr_index:
14017 if (reader->dwo_file == NULL)
14019 /* For now flag a hard error.
14020 Later we can turn this into a complaint. */
14021 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14022 dwarf_form_name (form),
14023 bfd_get_filename (abfd));
14025 DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read);
14026 info_ptr += bytes_read;
14028 case DW_FORM_GNU_str_index:
14029 if (reader->dwo_file == NULL)
14031 /* For now flag a hard error.
14032 Later we can turn this into a complaint if warranted. */
14033 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
14034 dwarf_form_name (form),
14035 bfd_get_filename (abfd));
14038 ULONGEST str_index =
14039 read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
14041 DW_STRING (attr) = read_str_index (reader, cu, str_index);
14042 DW_STRING_IS_CANONICAL (attr) = 0;
14043 info_ptr += bytes_read;
14047 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
14048 dwarf_form_name (form),
14049 bfd_get_filename (abfd));
14053 if (cu->per_cu->is_dwz && is_ref_attr (attr))
14054 attr->form = DW_FORM_GNU_ref_alt;
14056 /* We have seen instances where the compiler tried to emit a byte
14057 size attribute of -1 which ended up being encoded as an unsigned
14058 0xffffffff. Although 0xffffffff is technically a valid size value,
14059 an object of this size seems pretty unlikely so we can relatively
14060 safely treat these cases as if the size attribute was invalid and
14061 treat them as zero by default. */
14062 if (attr->name == DW_AT_byte_size
14063 && form == DW_FORM_data4
14064 && DW_UNSND (attr) >= 0xffffffff)
14067 (&symfile_complaints,
14068 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
14069 hex_string (DW_UNSND (attr)));
14070 DW_UNSND (attr) = 0;
14076 /* Read an attribute described by an abbreviated attribute. */
14079 read_attribute (const struct die_reader_specs *reader,
14080 struct attribute *attr, struct attr_abbrev *abbrev,
14081 gdb_byte *info_ptr)
14083 attr->name = abbrev->name;
14084 return read_attribute_value (reader, attr, abbrev->form, info_ptr);
14087 /* Read dwarf information from a buffer. */
14089 static unsigned int
14090 read_1_byte (bfd *abfd, const gdb_byte *buf)
14092 return bfd_get_8 (abfd, buf);
14096 read_1_signed_byte (bfd *abfd, const gdb_byte *buf)
14098 return bfd_get_signed_8 (abfd, buf);
14101 static unsigned int
14102 read_2_bytes (bfd *abfd, const gdb_byte *buf)
14104 return bfd_get_16 (abfd, buf);
14108 read_2_signed_bytes (bfd *abfd, const gdb_byte *buf)
14110 return bfd_get_signed_16 (abfd, buf);
14113 static unsigned int
14114 read_4_bytes (bfd *abfd, const gdb_byte *buf)
14116 return bfd_get_32 (abfd, buf);
14120 read_4_signed_bytes (bfd *abfd, const gdb_byte *buf)
14122 return bfd_get_signed_32 (abfd, buf);
14126 read_8_bytes (bfd *abfd, const gdb_byte *buf)
14128 return bfd_get_64 (abfd, buf);
14132 read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu,
14133 unsigned int *bytes_read)
14135 struct comp_unit_head *cu_header = &cu->header;
14136 CORE_ADDR retval = 0;
14138 if (cu_header->signed_addr_p)
14140 switch (cu_header->addr_size)
14143 retval = bfd_get_signed_16 (abfd, buf);
14146 retval = bfd_get_signed_32 (abfd, buf);
14149 retval = bfd_get_signed_64 (abfd, buf);
14152 internal_error (__FILE__, __LINE__,
14153 _("read_address: bad switch, signed [in module %s]"),
14154 bfd_get_filename (abfd));
14159 switch (cu_header->addr_size)
14162 retval = bfd_get_16 (abfd, buf);
14165 retval = bfd_get_32 (abfd, buf);
14168 retval = bfd_get_64 (abfd, buf);
14171 internal_error (__FILE__, __LINE__,
14172 _("read_address: bad switch, "
14173 "unsigned [in module %s]"),
14174 bfd_get_filename (abfd));
14178 *bytes_read = cu_header->addr_size;
14182 /* Read the initial length from a section. The (draft) DWARF 3
14183 specification allows the initial length to take up either 4 bytes
14184 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
14185 bytes describe the length and all offsets will be 8 bytes in length
14188 An older, non-standard 64-bit format is also handled by this
14189 function. The older format in question stores the initial length
14190 as an 8-byte quantity without an escape value. Lengths greater
14191 than 2^32 aren't very common which means that the initial 4 bytes
14192 is almost always zero. Since a length value of zero doesn't make
14193 sense for the 32-bit format, this initial zero can be considered to
14194 be an escape value which indicates the presence of the older 64-bit
14195 format. As written, the code can't detect (old format) lengths
14196 greater than 4GB. If it becomes necessary to handle lengths
14197 somewhat larger than 4GB, we could allow other small values (such
14198 as the non-sensical values of 1, 2, and 3) to also be used as
14199 escape values indicating the presence of the old format.
14201 The value returned via bytes_read should be used to increment the
14202 relevant pointer after calling read_initial_length().
14204 [ Note: read_initial_length() and read_offset() are based on the
14205 document entitled "DWARF Debugging Information Format", revision
14206 3, draft 8, dated November 19, 2001. This document was obtained
14209 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
14211 This document is only a draft and is subject to change. (So beware.)
14213 Details regarding the older, non-standard 64-bit format were
14214 determined empirically by examining 64-bit ELF files produced by
14215 the SGI toolchain on an IRIX 6.5 machine.
14217 - Kevin, July 16, 2002
14221 read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read)
14223 LONGEST length = bfd_get_32 (abfd, buf);
14225 if (length == 0xffffffff)
14227 length = bfd_get_64 (abfd, buf + 4);
14230 else if (length == 0)
14232 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
14233 length = bfd_get_64 (abfd, buf);
14244 /* Cover function for read_initial_length.
14245 Returns the length of the object at BUF, and stores the size of the
14246 initial length in *BYTES_READ and stores the size that offsets will be in
14248 If the initial length size is not equivalent to that specified in
14249 CU_HEADER then issue a complaint.
14250 This is useful when reading non-comp-unit headers. */
14253 read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf,
14254 const struct comp_unit_head *cu_header,
14255 unsigned int *bytes_read,
14256 unsigned int *offset_size)
14258 LONGEST length = read_initial_length (abfd, buf, bytes_read);
14260 gdb_assert (cu_header->initial_length_size == 4
14261 || cu_header->initial_length_size == 8
14262 || cu_header->initial_length_size == 12);
14264 if (cu_header->initial_length_size != *bytes_read)
14265 complaint (&symfile_complaints,
14266 _("intermixed 32-bit and 64-bit DWARF sections"));
14268 *offset_size = (*bytes_read == 4) ? 4 : 8;
14272 /* Read an offset from the data stream. The size of the offset is
14273 given by cu_header->offset_size. */
14276 read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header,
14277 unsigned int *bytes_read)
14279 LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
14281 *bytes_read = cu_header->offset_size;
14285 /* Read an offset from the data stream. */
14288 read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size)
14290 LONGEST retval = 0;
14292 switch (offset_size)
14295 retval = bfd_get_32 (abfd, buf);
14298 retval = bfd_get_64 (abfd, buf);
14301 internal_error (__FILE__, __LINE__,
14302 _("read_offset_1: bad switch [in module %s]"),
14303 bfd_get_filename (abfd));
14310 read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size)
14312 /* If the size of a host char is 8 bits, we can return a pointer
14313 to the buffer, otherwise we have to copy the data to a buffer
14314 allocated on the temporary obstack. */
14315 gdb_assert (HOST_CHAR_BIT == 8);
14320 read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
14322 /* If the size of a host char is 8 bits, we can return a pointer
14323 to the string, otherwise we have to copy the string to a buffer
14324 allocated on the temporary obstack. */
14325 gdb_assert (HOST_CHAR_BIT == 8);
14328 *bytes_read_ptr = 1;
14331 *bytes_read_ptr = strlen ((char *) buf) + 1;
14332 return (char *) buf;
14336 read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset)
14338 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str);
14339 if (dwarf2_per_objfile->str.buffer == NULL)
14340 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
14341 bfd_get_filename (abfd));
14342 if (str_offset >= dwarf2_per_objfile->str.size)
14343 error (_("DW_FORM_strp pointing outside of "
14344 ".debug_str section [in module %s]"),
14345 bfd_get_filename (abfd));
14346 gdb_assert (HOST_CHAR_BIT == 8);
14347 if (dwarf2_per_objfile->str.buffer[str_offset] == '\0')
14349 return (char *) (dwarf2_per_objfile->str.buffer + str_offset);
14352 /* Read a string at offset STR_OFFSET in the .debug_str section from
14353 the .dwz file DWZ. Throw an error if the offset is too large. If
14354 the string consists of a single NUL byte, return NULL; otherwise
14355 return a pointer to the string. */
14358 read_indirect_string_from_dwz (struct dwz_file *dwz, LONGEST str_offset)
14360 dwarf2_read_section (dwarf2_per_objfile->objfile, &dwz->str);
14362 if (dwz->str.buffer == NULL)
14363 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
14364 "section [in module %s]"),
14365 bfd_get_filename (dwz->dwz_bfd));
14366 if (str_offset >= dwz->str.size)
14367 error (_("DW_FORM_GNU_strp_alt pointing outside of "
14368 ".debug_str section [in module %s]"),
14369 bfd_get_filename (dwz->dwz_bfd));
14370 gdb_assert (HOST_CHAR_BIT == 8);
14371 if (dwz->str.buffer[str_offset] == '\0')
14373 return (char *) (dwz->str.buffer + str_offset);
14377 read_indirect_string (bfd *abfd, gdb_byte *buf,
14378 const struct comp_unit_head *cu_header,
14379 unsigned int *bytes_read_ptr)
14381 LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
14383 return read_indirect_string_at_offset (abfd, str_offset);
14387 read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
14390 unsigned int num_read;
14392 unsigned char byte;
14400 byte = bfd_get_8 (abfd, buf);
14403 result |= ((ULONGEST) (byte & 127) << shift);
14404 if ((byte & 128) == 0)
14410 *bytes_read_ptr = num_read;
14415 read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr)
14418 int i, shift, num_read;
14419 unsigned char byte;
14427 byte = bfd_get_8 (abfd, buf);
14430 result |= ((LONGEST) (byte & 127) << shift);
14432 if ((byte & 128) == 0)
14437 if ((shift < 8 * sizeof (result)) && (byte & 0x40))
14438 result |= -(((LONGEST) 1) << shift);
14439 *bytes_read_ptr = num_read;
14443 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
14444 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
14445 ADDR_SIZE is the size of addresses from the CU header. */
14448 read_addr_index_1 (unsigned int addr_index, ULONGEST addr_base, int addr_size)
14450 struct objfile *objfile = dwarf2_per_objfile->objfile;
14451 bfd *abfd = objfile->obfd;
14452 const gdb_byte *info_ptr;
14454 dwarf2_read_section (objfile, &dwarf2_per_objfile->addr);
14455 if (dwarf2_per_objfile->addr.buffer == NULL)
14456 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
14458 if (addr_base + addr_index * addr_size >= dwarf2_per_objfile->addr.size)
14459 error (_("DW_FORM_addr_index pointing outside of "
14460 ".debug_addr section [in module %s]"),
14462 info_ptr = (dwarf2_per_objfile->addr.buffer
14463 + addr_base + addr_index * addr_size);
14464 if (addr_size == 4)
14465 return bfd_get_32 (abfd, info_ptr);
14467 return bfd_get_64 (abfd, info_ptr);
14470 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
14473 read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index)
14475 return read_addr_index_1 (addr_index, cu->addr_base, cu->header.addr_size);
14478 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
14481 read_addr_index_from_leb128 (struct dwarf2_cu *cu, gdb_byte *info_ptr,
14482 unsigned int *bytes_read)
14484 bfd *abfd = cu->objfile->obfd;
14485 unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read);
14487 return read_addr_index (cu, addr_index);
14490 /* Data structure to pass results from dwarf2_read_addr_index_reader
14491 back to dwarf2_read_addr_index. */
14493 struct dwarf2_read_addr_index_data
14495 ULONGEST addr_base;
14499 /* die_reader_func for dwarf2_read_addr_index. */
14502 dwarf2_read_addr_index_reader (const struct die_reader_specs *reader,
14503 gdb_byte *info_ptr,
14504 struct die_info *comp_unit_die,
14508 struct dwarf2_cu *cu = reader->cu;
14509 struct dwarf2_read_addr_index_data *aidata =
14510 (struct dwarf2_read_addr_index_data *) data;
14512 aidata->addr_base = cu->addr_base;
14513 aidata->addr_size = cu->header.addr_size;
14516 /* Given an index in .debug_addr, fetch the value.
14517 NOTE: This can be called during dwarf expression evaluation,
14518 long after the debug information has been read, and thus per_cu->cu
14519 may no longer exist. */
14522 dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
14523 unsigned int addr_index)
14525 struct objfile *objfile = per_cu->objfile;
14526 struct dwarf2_cu *cu = per_cu->cu;
14527 ULONGEST addr_base;
14530 /* This is intended to be called from outside this file. */
14531 dw2_setup (objfile);
14533 /* We need addr_base and addr_size.
14534 If we don't have PER_CU->cu, we have to get it.
14535 Nasty, but the alternative is storing the needed info in PER_CU,
14536 which at this point doesn't seem justified: it's not clear how frequently
14537 it would get used and it would increase the size of every PER_CU.
14538 Entry points like dwarf2_per_cu_addr_size do a similar thing
14539 so we're not in uncharted territory here.
14540 Alas we need to be a bit more complicated as addr_base is contained
14543 We don't need to read the entire CU(/TU).
14544 We just need the header and top level die.
14546 IWBN to use the aging mechanism to let us lazily later discard the CU.
14547 For now we skip this optimization. */
14551 addr_base = cu->addr_base;
14552 addr_size = cu->header.addr_size;
14556 struct dwarf2_read_addr_index_data aidata;
14558 /* Note: We can't use init_cutu_and_read_dies_simple here,
14559 we need addr_base. */
14560 init_cutu_and_read_dies (per_cu, NULL, 0, 0,
14561 dwarf2_read_addr_index_reader, &aidata);
14562 addr_base = aidata.addr_base;
14563 addr_size = aidata.addr_size;
14566 return read_addr_index_1 (addr_index, addr_base, addr_size);
14569 /* Given a DW_AT_str_index, fetch the string. */
14572 read_str_index (const struct die_reader_specs *reader,
14573 struct dwarf2_cu *cu, ULONGEST str_index)
14575 struct objfile *objfile = dwarf2_per_objfile->objfile;
14576 const char *dwo_name = objfile->name;
14577 bfd *abfd = objfile->obfd;
14578 struct dwo_sections *sections = &reader->dwo_file->sections;
14579 gdb_byte *info_ptr;
14580 ULONGEST str_offset;
14582 dwarf2_read_section (objfile, §ions->str);
14583 dwarf2_read_section (objfile, §ions->str_offsets);
14584 if (sections->str.buffer == NULL)
14585 error (_("DW_FORM_str_index used without .debug_str.dwo section"
14586 " in CU at offset 0x%lx [in module %s]"),
14587 (long) cu->header.offset.sect_off, dwo_name);
14588 if (sections->str_offsets.buffer == NULL)
14589 error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section"
14590 " in CU at offset 0x%lx [in module %s]"),
14591 (long) cu->header.offset.sect_off, dwo_name);
14592 if (str_index * cu->header.offset_size >= sections->str_offsets.size)
14593 error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo"
14594 " section in CU at offset 0x%lx [in module %s]"),
14595 (long) cu->header.offset.sect_off, dwo_name);
14596 info_ptr = (sections->str_offsets.buffer
14597 + str_index * cu->header.offset_size);
14598 if (cu->header.offset_size == 4)
14599 str_offset = bfd_get_32 (abfd, info_ptr);
14601 str_offset = bfd_get_64 (abfd, info_ptr);
14602 if (str_offset >= sections->str.size)
14603 error (_("Offset from DW_FORM_str_index pointing outside of"
14604 " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"),
14605 (long) cu->header.offset.sect_off, dwo_name);
14606 return (char *) (sections->str.buffer + str_offset);
14609 /* Return the length of an LEB128 number in BUF. */
14612 leb128_size (const gdb_byte *buf)
14614 const gdb_byte *begin = buf;
14620 if ((byte & 128) == 0)
14621 return buf - begin;
14626 set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
14633 cu->language = language_c;
14635 case DW_LANG_C_plus_plus:
14636 cu->language = language_cplus;
14639 cu->language = language_d;
14641 case DW_LANG_Fortran77:
14642 case DW_LANG_Fortran90:
14643 case DW_LANG_Fortran95:
14644 cu->language = language_fortran;
14647 cu->language = language_go;
14649 case DW_LANG_Mips_Assembler:
14650 cu->language = language_asm;
14653 cu->language = language_java;
14655 case DW_LANG_Ada83:
14656 case DW_LANG_Ada95:
14657 cu->language = language_ada;
14659 case DW_LANG_Modula2:
14660 cu->language = language_m2;
14662 case DW_LANG_Pascal83:
14663 cu->language = language_pascal;
14666 cu->language = language_objc;
14668 case DW_LANG_Cobol74:
14669 case DW_LANG_Cobol85:
14671 cu->language = language_minimal;
14674 cu->language_defn = language_def (cu->language);
14677 /* Return the named attribute or NULL if not there. */
14679 static struct attribute *
14680 dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
14685 struct attribute *spec = NULL;
14687 for (i = 0; i < die->num_attrs; ++i)
14689 if (die->attrs[i].name == name)
14690 return &die->attrs[i];
14691 if (die->attrs[i].name == DW_AT_specification
14692 || die->attrs[i].name == DW_AT_abstract_origin)
14693 spec = &die->attrs[i];
14699 die = follow_die_ref (die, spec, &cu);
14705 /* Return the named attribute or NULL if not there,
14706 but do not follow DW_AT_specification, etc.
14707 This is for use in contexts where we're reading .debug_types dies.
14708 Following DW_AT_specification, DW_AT_abstract_origin will take us
14709 back up the chain, and we want to go down. */
14711 static struct attribute *
14712 dwarf2_attr_no_follow (struct die_info *die, unsigned int name)
14716 for (i = 0; i < die->num_attrs; ++i)
14717 if (die->attrs[i].name == name)
14718 return &die->attrs[i];
14723 /* Return non-zero iff the attribute NAME is defined for the given DIE,
14724 and holds a non-zero value. This function should only be used for
14725 DW_FORM_flag or DW_FORM_flag_present attributes. */
14728 dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu)
14730 struct attribute *attr = dwarf2_attr (die, name, cu);
14732 return (attr && DW_UNSND (attr));
14736 die_is_declaration (struct die_info *die, struct dwarf2_cu *cu)
14738 /* A DIE is a declaration if it has a DW_AT_declaration attribute
14739 which value is non-zero. However, we have to be careful with
14740 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
14741 (via dwarf2_flag_true_p) follows this attribute. So we may
14742 end up accidently finding a declaration attribute that belongs
14743 to a different DIE referenced by the specification attribute,
14744 even though the given DIE does not have a declaration attribute. */
14745 return (dwarf2_flag_true_p (die, DW_AT_declaration, cu)
14746 && dwarf2_attr (die, DW_AT_specification, cu) == NULL);
14749 /* Return the die giving the specification for DIE, if there is
14750 one. *SPEC_CU is the CU containing DIE on input, and the CU
14751 containing the return value on output. If there is no
14752 specification, but there is an abstract origin, that is
14755 static struct die_info *
14756 die_specification (struct die_info *die, struct dwarf2_cu **spec_cu)
14758 struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification,
14761 if (spec_attr == NULL)
14762 spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu);
14764 if (spec_attr == NULL)
14767 return follow_die_ref (die, spec_attr, spec_cu);
14770 /* Free the line_header structure *LH, and any arrays and strings it
14772 NOTE: This is also used as a "cleanup" function. */
14775 free_line_header (struct line_header *lh)
14777 if (lh->standard_opcode_lengths)
14778 xfree (lh->standard_opcode_lengths);
14780 /* Remember that all the lh->file_names[i].name pointers are
14781 pointers into debug_line_buffer, and don't need to be freed. */
14782 if (lh->file_names)
14783 xfree (lh->file_names);
14785 /* Similarly for the include directory names. */
14786 if (lh->include_dirs)
14787 xfree (lh->include_dirs);
14792 /* Add an entry to LH's include directory table. */
14795 add_include_dir (struct line_header *lh, char *include_dir)
14797 /* Grow the array if necessary. */
14798 if (lh->include_dirs_size == 0)
14800 lh->include_dirs_size = 1; /* for testing */
14801 lh->include_dirs = xmalloc (lh->include_dirs_size
14802 * sizeof (*lh->include_dirs));
14804 else if (lh->num_include_dirs >= lh->include_dirs_size)
14806 lh->include_dirs_size *= 2;
14807 lh->include_dirs = xrealloc (lh->include_dirs,
14808 (lh->include_dirs_size
14809 * sizeof (*lh->include_dirs)));
14812 lh->include_dirs[lh->num_include_dirs++] = include_dir;
14815 /* Add an entry to LH's file name table. */
14818 add_file_name (struct line_header *lh,
14820 unsigned int dir_index,
14821 unsigned int mod_time,
14822 unsigned int length)
14824 struct file_entry *fe;
14826 /* Grow the array if necessary. */
14827 if (lh->file_names_size == 0)
14829 lh->file_names_size = 1; /* for testing */
14830 lh->file_names = xmalloc (lh->file_names_size
14831 * sizeof (*lh->file_names));
14833 else if (lh->num_file_names >= lh->file_names_size)
14835 lh->file_names_size *= 2;
14836 lh->file_names = xrealloc (lh->file_names,
14837 (lh->file_names_size
14838 * sizeof (*lh->file_names)));
14841 fe = &lh->file_names[lh->num_file_names++];
14843 fe->dir_index = dir_index;
14844 fe->mod_time = mod_time;
14845 fe->length = length;
14846 fe->included_p = 0;
14850 /* A convenience function to find the proper .debug_line section for a
14853 static struct dwarf2_section_info *
14854 get_debug_line_section (struct dwarf2_cu *cu)
14856 struct dwarf2_section_info *section;
14858 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
14860 if (cu->dwo_unit && cu->per_cu->is_debug_types)
14861 section = &cu->dwo_unit->dwo_file->sections.line;
14862 else if (cu->per_cu->is_dwz)
14864 struct dwz_file *dwz = dwarf2_get_dwz_file ();
14866 section = &dwz->line;
14869 section = &dwarf2_per_objfile->line;
14874 /* Read the statement program header starting at OFFSET in
14875 .debug_line, or .debug_line.dwo. Return a pointer
14876 to a struct line_header, allocated using xmalloc.
14878 NOTE: the strings in the include directory and file name tables of
14879 the returned object point into the dwarf line section buffer,
14880 and must not be freed. */
14882 static struct line_header *
14883 dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu)
14885 struct cleanup *back_to;
14886 struct line_header *lh;
14887 gdb_byte *line_ptr;
14888 unsigned int bytes_read, offset_size;
14890 char *cur_dir, *cur_file;
14891 struct dwarf2_section_info *section;
14894 section = get_debug_line_section (cu);
14895 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
14896 if (section->buffer == NULL)
14898 if (cu->dwo_unit && cu->per_cu->is_debug_types)
14899 complaint (&symfile_complaints, _("missing .debug_line.dwo section"));
14901 complaint (&symfile_complaints, _("missing .debug_line section"));
14905 /* We can't do this until we know the section is non-empty.
14906 Only then do we know we have such a section. */
14907 abfd = section->asection->owner;
14909 /* Make sure that at least there's room for the total_length field.
14910 That could be 12 bytes long, but we're just going to fudge that. */
14911 if (offset + 4 >= section->size)
14913 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14917 lh = xmalloc (sizeof (*lh));
14918 memset (lh, 0, sizeof (*lh));
14919 back_to = make_cleanup ((make_cleanup_ftype *) free_line_header,
14922 line_ptr = section->buffer + offset;
14924 /* Read in the header. */
14926 read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
14927 &bytes_read, &offset_size);
14928 line_ptr += bytes_read;
14929 if (line_ptr + lh->total_length > (section->buffer + section->size))
14931 dwarf2_statement_list_fits_in_line_number_section_complaint ();
14934 lh->statement_program_end = line_ptr + lh->total_length;
14935 lh->version = read_2_bytes (abfd, line_ptr);
14937 lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
14938 line_ptr += offset_size;
14939 lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
14941 if (lh->version >= 4)
14943 lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
14947 lh->maximum_ops_per_instruction = 1;
14949 if (lh->maximum_ops_per_instruction == 0)
14951 lh->maximum_ops_per_instruction = 1;
14952 complaint (&symfile_complaints,
14953 _("invalid maximum_ops_per_instruction "
14954 "in `.debug_line' section"));
14957 lh->default_is_stmt = read_1_byte (abfd, line_ptr);
14959 lh->line_base = read_1_signed_byte (abfd, line_ptr);
14961 lh->line_range = read_1_byte (abfd, line_ptr);
14963 lh->opcode_base = read_1_byte (abfd, line_ptr);
14965 lh->standard_opcode_lengths
14966 = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0]));
14968 lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */
14969 for (i = 1; i < lh->opcode_base; ++i)
14971 lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
14975 /* Read directory table. */
14976 while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
14978 line_ptr += bytes_read;
14979 add_include_dir (lh, cur_dir);
14981 line_ptr += bytes_read;
14983 /* Read file name table. */
14984 while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
14986 unsigned int dir_index, mod_time, length;
14988 line_ptr += bytes_read;
14989 dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
14990 line_ptr += bytes_read;
14991 mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
14992 line_ptr += bytes_read;
14993 length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
14994 line_ptr += bytes_read;
14996 add_file_name (lh, cur_file, dir_index, mod_time, length);
14998 line_ptr += bytes_read;
14999 lh->statement_program_start = line_ptr;
15001 if (line_ptr > (section->buffer + section->size))
15002 complaint (&symfile_complaints,
15003 _("line number info header doesn't "
15004 "fit in `.debug_line' section"));
15006 discard_cleanups (back_to);
15010 /* Subroutine of dwarf_decode_lines to simplify it.
15011 Return the file name of the psymtab for included file FILE_INDEX
15012 in line header LH of PST.
15013 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15014 If space for the result is malloc'd, it will be freed by a cleanup.
15015 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
15018 psymtab_include_file_name (const struct line_header *lh, int file_index,
15019 const struct partial_symtab *pst,
15020 const char *comp_dir)
15022 const struct file_entry fe = lh->file_names [file_index];
15023 char *include_name = fe.name;
15024 char *include_name_to_compare = include_name;
15025 char *dir_name = NULL;
15026 const char *pst_filename;
15027 char *copied_name = NULL;
15031 dir_name = lh->include_dirs[fe.dir_index - 1];
15033 if (!IS_ABSOLUTE_PATH (include_name)
15034 && (dir_name != NULL || comp_dir != NULL))
15036 /* Avoid creating a duplicate psymtab for PST.
15037 We do this by comparing INCLUDE_NAME and PST_FILENAME.
15038 Before we do the comparison, however, we need to account
15039 for DIR_NAME and COMP_DIR.
15040 First prepend dir_name (if non-NULL). If we still don't
15041 have an absolute path prepend comp_dir (if non-NULL).
15042 However, the directory we record in the include-file's
15043 psymtab does not contain COMP_DIR (to match the
15044 corresponding symtab(s)).
15049 bash$ gcc -g ./hello.c
15050 include_name = "hello.c"
15052 DW_AT_comp_dir = comp_dir = "/tmp"
15053 DW_AT_name = "./hello.c" */
15055 if (dir_name != NULL)
15057 include_name = concat (dir_name, SLASH_STRING,
15058 include_name, (char *)NULL);
15059 include_name_to_compare = include_name;
15060 make_cleanup (xfree, include_name);
15062 if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL)
15064 include_name_to_compare = concat (comp_dir, SLASH_STRING,
15065 include_name, (char *)NULL);
15069 pst_filename = pst->filename;
15070 if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL)
15072 copied_name = concat (pst->dirname, SLASH_STRING,
15073 pst_filename, (char *)NULL);
15074 pst_filename = copied_name;
15077 file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0;
15079 if (include_name_to_compare != include_name)
15080 xfree (include_name_to_compare);
15081 if (copied_name != NULL)
15082 xfree (copied_name);
15086 return include_name;
15089 /* Ignore this record_line request. */
15092 noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc)
15097 /* Subroutine of dwarf_decode_lines to simplify it.
15098 Process the line number information in LH. */
15101 dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir,
15102 struct dwarf2_cu *cu, struct partial_symtab *pst)
15104 gdb_byte *line_ptr, *extended_end;
15105 gdb_byte *line_end;
15106 unsigned int bytes_read, extended_len;
15107 unsigned char op_code, extended_op, adj_opcode;
15108 CORE_ADDR baseaddr;
15109 struct objfile *objfile = cu->objfile;
15110 bfd *abfd = objfile->obfd;
15111 struct gdbarch *gdbarch = get_objfile_arch (objfile);
15112 const int decode_for_pst_p = (pst != NULL);
15113 struct subfile *last_subfile = NULL;
15114 void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc)
15117 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15119 line_ptr = lh->statement_program_start;
15120 line_end = lh->statement_program_end;
15122 /* Read the statement sequences until there's nothing left. */
15123 while (line_ptr < line_end)
15125 /* state machine registers */
15126 CORE_ADDR address = 0;
15127 unsigned int file = 1;
15128 unsigned int line = 1;
15129 unsigned int column = 0;
15130 int is_stmt = lh->default_is_stmt;
15131 int basic_block = 0;
15132 int end_sequence = 0;
15134 unsigned char op_index = 0;
15136 if (!decode_for_pst_p && lh->num_file_names >= file)
15138 /* Start a subfile for the current file of the state machine. */
15139 /* lh->include_dirs and lh->file_names are 0-based, but the
15140 directory and file name numbers in the statement program
15142 struct file_entry *fe = &lh->file_names[file - 1];
15146 dir = lh->include_dirs[fe->dir_index - 1];
15148 dwarf2_start_subfile (fe->name, dir, comp_dir);
15151 /* Decode the table. */
15152 while (!end_sequence)
15154 op_code = read_1_byte (abfd, line_ptr);
15156 if (line_ptr > line_end)
15158 dwarf2_debug_line_missing_end_sequence_complaint ();
15162 if (op_code >= lh->opcode_base)
15164 /* Special operand. */
15165 adj_opcode = op_code - lh->opcode_base;
15166 address += (((op_index + (adj_opcode / lh->line_range))
15167 / lh->maximum_ops_per_instruction)
15168 * lh->minimum_instruction_length);
15169 op_index = ((op_index + (adj_opcode / lh->line_range))
15170 % lh->maximum_ops_per_instruction);
15171 line += lh->line_base + (adj_opcode % lh->line_range);
15172 if (lh->num_file_names < file || file == 0)
15173 dwarf2_debug_line_missing_file_complaint ();
15174 /* For now we ignore lines not starting on an
15175 instruction boundary. */
15176 else if (op_index == 0)
15178 lh->file_names[file - 1].included_p = 1;
15179 if (!decode_for_pst_p && is_stmt)
15181 if (last_subfile != current_subfile)
15183 addr = gdbarch_addr_bits_remove (gdbarch, address);
15185 (*p_record_line) (last_subfile, 0, addr);
15186 last_subfile = current_subfile;
15188 /* Append row to matrix using current values. */
15189 addr = gdbarch_addr_bits_remove (gdbarch, address);
15190 (*p_record_line) (current_subfile, line, addr);
15195 else switch (op_code)
15197 case DW_LNS_extended_op:
15198 extended_len = read_unsigned_leb128 (abfd, line_ptr,
15200 line_ptr += bytes_read;
15201 extended_end = line_ptr + extended_len;
15202 extended_op = read_1_byte (abfd, line_ptr);
15204 switch (extended_op)
15206 case DW_LNE_end_sequence:
15207 p_record_line = record_line;
15210 case DW_LNE_set_address:
15211 address = read_address (abfd, line_ptr, cu, &bytes_read);
15213 if (address == 0 && !dwarf2_per_objfile->has_section_at_zero)
15215 /* This line table is for a function which has been
15216 GCd by the linker. Ignore it. PR gdb/12528 */
15219 = line_ptr - get_debug_line_section (cu)->buffer;
15221 complaint (&symfile_complaints,
15222 _(".debug_line address at offset 0x%lx is 0 "
15224 line_offset, objfile->name);
15225 p_record_line = noop_record_line;
15229 line_ptr += bytes_read;
15230 address += baseaddr;
15232 case DW_LNE_define_file:
15235 unsigned int dir_index, mod_time, length;
15237 cur_file = read_direct_string (abfd, line_ptr,
15239 line_ptr += bytes_read;
15241 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15242 line_ptr += bytes_read;
15244 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15245 line_ptr += bytes_read;
15247 read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15248 line_ptr += bytes_read;
15249 add_file_name (lh, cur_file, dir_index, mod_time, length);
15252 case DW_LNE_set_discriminator:
15253 /* The discriminator is not interesting to the debugger;
15255 line_ptr = extended_end;
15258 complaint (&symfile_complaints,
15259 _("mangled .debug_line section"));
15262 /* Make sure that we parsed the extended op correctly. If e.g.
15263 we expected a different address size than the producer used,
15264 we may have read the wrong number of bytes. */
15265 if (line_ptr != extended_end)
15267 complaint (&symfile_complaints,
15268 _("mangled .debug_line section"));
15273 if (lh->num_file_names < file || file == 0)
15274 dwarf2_debug_line_missing_file_complaint ();
15277 lh->file_names[file - 1].included_p = 1;
15278 if (!decode_for_pst_p && is_stmt)
15280 if (last_subfile != current_subfile)
15282 addr = gdbarch_addr_bits_remove (gdbarch, address);
15284 (*p_record_line) (last_subfile, 0, addr);
15285 last_subfile = current_subfile;
15287 addr = gdbarch_addr_bits_remove (gdbarch, address);
15288 (*p_record_line) (current_subfile, line, addr);
15293 case DW_LNS_advance_pc:
15296 = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15298 address += (((op_index + adjust)
15299 / lh->maximum_ops_per_instruction)
15300 * lh->minimum_instruction_length);
15301 op_index = ((op_index + adjust)
15302 % lh->maximum_ops_per_instruction);
15303 line_ptr += bytes_read;
15306 case DW_LNS_advance_line:
15307 line += read_signed_leb128 (abfd, line_ptr, &bytes_read);
15308 line_ptr += bytes_read;
15310 case DW_LNS_set_file:
15312 /* The arrays lh->include_dirs and lh->file_names are
15313 0-based, but the directory and file name numbers in
15314 the statement program are 1-based. */
15315 struct file_entry *fe;
15318 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15319 line_ptr += bytes_read;
15320 if (lh->num_file_names < file || file == 0)
15321 dwarf2_debug_line_missing_file_complaint ();
15324 fe = &lh->file_names[file - 1];
15326 dir = lh->include_dirs[fe->dir_index - 1];
15327 if (!decode_for_pst_p)
15329 last_subfile = current_subfile;
15330 dwarf2_start_subfile (fe->name, dir, comp_dir);
15335 case DW_LNS_set_column:
15336 column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15337 line_ptr += bytes_read;
15339 case DW_LNS_negate_stmt:
15340 is_stmt = (!is_stmt);
15342 case DW_LNS_set_basic_block:
15345 /* Add to the address register of the state machine the
15346 address increment value corresponding to special opcode
15347 255. I.e., this value is scaled by the minimum
15348 instruction length since special opcode 255 would have
15349 scaled the increment. */
15350 case DW_LNS_const_add_pc:
15352 CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range;
15354 address += (((op_index + adjust)
15355 / lh->maximum_ops_per_instruction)
15356 * lh->minimum_instruction_length);
15357 op_index = ((op_index + adjust)
15358 % lh->maximum_ops_per_instruction);
15361 case DW_LNS_fixed_advance_pc:
15362 address += read_2_bytes (abfd, line_ptr);
15368 /* Unknown standard opcode, ignore it. */
15371 for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++)
15373 (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
15374 line_ptr += bytes_read;
15379 if (lh->num_file_names < file || file == 0)
15380 dwarf2_debug_line_missing_file_complaint ();
15383 lh->file_names[file - 1].included_p = 1;
15384 if (!decode_for_pst_p)
15386 addr = gdbarch_addr_bits_remove (gdbarch, address);
15387 (*p_record_line) (current_subfile, 0, addr);
15393 /* Decode the Line Number Program (LNP) for the given line_header
15394 structure and CU. The actual information extracted and the type
15395 of structures created from the LNP depends on the value of PST.
15397 1. If PST is NULL, then this procedure uses the data from the program
15398 to create all necessary symbol tables, and their linetables.
15400 2. If PST is not NULL, this procedure reads the program to determine
15401 the list of files included by the unit represented by PST, and
15402 builds all the associated partial symbol tables.
15404 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
15405 It is used for relative paths in the line table.
15406 NOTE: When processing partial symtabs (pst != NULL),
15407 comp_dir == pst->dirname.
15409 NOTE: It is important that psymtabs have the same file name (via strcmp)
15410 as the corresponding symtab. Since COMP_DIR is not used in the name of the
15411 symtab we don't use it in the name of the psymtabs we create.
15412 E.g. expand_line_sal requires this when finding psymtabs to expand.
15413 A good testcase for this is mb-inline.exp. */
15416 dwarf_decode_lines (struct line_header *lh, const char *comp_dir,
15417 struct dwarf2_cu *cu, struct partial_symtab *pst,
15418 int want_line_info)
15420 struct objfile *objfile = cu->objfile;
15421 const int decode_for_pst_p = (pst != NULL);
15422 struct subfile *first_subfile = current_subfile;
15424 if (want_line_info)
15425 dwarf_decode_lines_1 (lh, comp_dir, cu, pst);
15427 if (decode_for_pst_p)
15431 /* Now that we're done scanning the Line Header Program, we can
15432 create the psymtab of each included file. */
15433 for (file_index = 0; file_index < lh->num_file_names; file_index++)
15434 if (lh->file_names[file_index].included_p == 1)
15436 char *include_name =
15437 psymtab_include_file_name (lh, file_index, pst, comp_dir);
15438 if (include_name != NULL)
15439 dwarf2_create_include_psymtab (include_name, pst, objfile);
15444 /* Make sure a symtab is created for every file, even files
15445 which contain only variables (i.e. no code with associated
15449 for (i = 0; i < lh->num_file_names; i++)
15452 struct file_entry *fe;
15454 fe = &lh->file_names[i];
15456 dir = lh->include_dirs[fe->dir_index - 1];
15457 dwarf2_start_subfile (fe->name, dir, comp_dir);
15459 /* Skip the main file; we don't need it, and it must be
15460 allocated last, so that it will show up before the
15461 non-primary symtabs in the objfile's symtab list. */
15462 if (current_subfile == first_subfile)
15465 if (current_subfile->symtab == NULL)
15466 current_subfile->symtab = allocate_symtab (current_subfile->name,
15468 fe->symtab = current_subfile->symtab;
15473 /* Start a subfile for DWARF. FILENAME is the name of the file and
15474 DIRNAME the name of the source directory which contains FILENAME
15475 or NULL if not known. COMP_DIR is the compilation directory for the
15476 linetable's compilation unit or NULL if not known.
15477 This routine tries to keep line numbers from identical absolute and
15478 relative file names in a common subfile.
15480 Using the `list' example from the GDB testsuite, which resides in
15481 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
15482 of /srcdir/list0.c yields the following debugging information for list0.c:
15484 DW_AT_name: /srcdir/list0.c
15485 DW_AT_comp_dir: /compdir
15486 files.files[0].name: list0.h
15487 files.files[0].dir: /srcdir
15488 files.files[1].name: list0.c
15489 files.files[1].dir: /srcdir
15491 The line number information for list0.c has to end up in a single
15492 subfile, so that `break /srcdir/list0.c:1' works as expected.
15493 start_subfile will ensure that this happens provided that we pass the
15494 concatenation of files.files[1].dir and files.files[1].name as the
15498 dwarf2_start_subfile (char *filename, const char *dirname,
15499 const char *comp_dir)
15503 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
15504 `start_symtab' will always pass the contents of DW_AT_comp_dir as
15505 second argument to start_subfile. To be consistent, we do the
15506 same here. In order not to lose the line information directory,
15507 we concatenate it to the filename when it makes sense.
15508 Note that the Dwarf3 standard says (speaking of filenames in line
15509 information): ``The directory index is ignored for file names
15510 that represent full path names''. Thus ignoring dirname in the
15511 `else' branch below isn't an issue. */
15513 if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL)
15514 fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL);
15516 fullname = filename;
15518 start_subfile (fullname, comp_dir);
15520 if (fullname != filename)
15524 /* Start a symtab for DWARF.
15525 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
15528 dwarf2_start_symtab (struct dwarf2_cu *cu,
15529 char *name, char *comp_dir, CORE_ADDR low_pc)
15531 start_symtab (name, comp_dir, low_pc);
15532 record_debugformat ("DWARF 2");
15533 record_producer (cu->producer);
15535 /* We assume that we're processing GCC output. */
15536 processing_gcc_compilation = 2;
15538 processing_has_namespace_info = 0;
15542 var_decode_location (struct attribute *attr, struct symbol *sym,
15543 struct dwarf2_cu *cu)
15545 struct objfile *objfile = cu->objfile;
15546 struct comp_unit_head *cu_header = &cu->header;
15548 /* NOTE drow/2003-01-30: There used to be a comment and some special
15549 code here to turn a symbol with DW_AT_external and a
15550 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
15551 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
15552 with some versions of binutils) where shared libraries could have
15553 relocations against symbols in their debug information - the
15554 minimal symbol would have the right address, but the debug info
15555 would not. It's no longer necessary, because we will explicitly
15556 apply relocations when we read in the debug information now. */
15558 /* A DW_AT_location attribute with no contents indicates that a
15559 variable has been optimized away. */
15560 if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
15562 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
15566 /* Handle one degenerate form of location expression specially, to
15567 preserve GDB's previous behavior when section offsets are
15568 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
15569 then mark this symbol as LOC_STATIC. */
15571 if (attr_form_is_block (attr)
15572 && ((DW_BLOCK (attr)->data[0] == DW_OP_addr
15573 && DW_BLOCK (attr)->size == 1 + cu_header->addr_size)
15574 || (DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index
15575 && (DW_BLOCK (attr)->size
15576 == 1 + leb128_size (&DW_BLOCK (attr)->data[1])))))
15578 unsigned int dummy;
15580 if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
15581 SYMBOL_VALUE_ADDRESS (sym) =
15582 read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy);
15584 SYMBOL_VALUE_ADDRESS (sym) =
15585 read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy);
15586 SYMBOL_CLASS (sym) = LOC_STATIC;
15587 fixup_symbol_section (sym, objfile);
15588 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
15589 SYMBOL_SECTION (sym));
15593 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
15594 expression evaluator, and use LOC_COMPUTED only when necessary
15595 (i.e. when the value of a register or memory location is
15596 referenced, or a thread-local block, etc.). Then again, it might
15597 not be worthwhile. I'm assuming that it isn't unless performance
15598 or memory numbers show me otherwise. */
15600 dwarf2_symbol_mark_computed (attr, sym, cu);
15601 SYMBOL_CLASS (sym) = LOC_COMPUTED;
15603 if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
15604 cu->has_loclist = 1;
15607 /* Given a pointer to a DWARF information entry, figure out if we need
15608 to make a symbol table entry for it, and if so, create a new entry
15609 and return a pointer to it.
15610 If TYPE is NULL, determine symbol type from the die, otherwise
15611 used the passed type.
15612 If SPACE is not NULL, use it to hold the new symbol. If it is
15613 NULL, allocate a new symbol on the objfile's obstack. */
15615 static struct symbol *
15616 new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
15617 struct symbol *space)
15619 struct objfile *objfile = cu->objfile;
15620 struct symbol *sym = NULL;
15622 struct attribute *attr = NULL;
15623 struct attribute *attr2 = NULL;
15624 CORE_ADDR baseaddr;
15625 struct pending **list_to_add = NULL;
15627 int inlined_func = (die->tag == DW_TAG_inlined_subroutine);
15629 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
15631 name = dwarf2_name (die, cu);
15634 const char *linkagename;
15635 int suppress_add = 0;
15640 sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
15641 OBJSTAT (objfile, n_syms++);
15643 /* Cache this symbol's name and the name's demangled form (if any). */
15644 SYMBOL_SET_LANGUAGE (sym, cu->language);
15645 linkagename = dwarf2_physname (name, die, cu);
15646 SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile);
15648 /* Fortran does not have mangling standard and the mangling does differ
15649 between gfortran, iFort etc. */
15650 if (cu->language == language_fortran
15651 && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
15652 symbol_set_demangled_name (&(sym->ginfo),
15653 (char *) dwarf2_full_name (name, die, cu),
15656 /* Default assumptions.
15657 Use the passed type or decode it from the die. */
15658 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
15659 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
15661 SYMBOL_TYPE (sym) = type;
15663 SYMBOL_TYPE (sym) = die_type (die, cu);
15664 attr = dwarf2_attr (die,
15665 inlined_func ? DW_AT_call_line : DW_AT_decl_line,
15669 SYMBOL_LINE (sym) = DW_UNSND (attr);
15672 attr = dwarf2_attr (die,
15673 inlined_func ? DW_AT_call_file : DW_AT_decl_file,
15677 int file_index = DW_UNSND (attr);
15679 if (cu->line_header == NULL
15680 || file_index > cu->line_header->num_file_names)
15681 complaint (&symfile_complaints,
15682 _("file index out of range"));
15683 else if (file_index > 0)
15685 struct file_entry *fe;
15687 fe = &cu->line_header->file_names[file_index - 1];
15688 SYMBOL_SYMTAB (sym) = fe->symtab;
15695 attr = dwarf2_attr (die, DW_AT_low_pc, cu);
15698 SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr;
15700 SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr;
15701 SYMBOL_DOMAIN (sym) = LABEL_DOMAIN;
15702 SYMBOL_CLASS (sym) = LOC_LABEL;
15703 add_symbol_to_list (sym, cu->list_in_scope);
15705 case DW_TAG_subprogram:
15706 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15708 SYMBOL_CLASS (sym) = LOC_BLOCK;
15709 attr2 = dwarf2_attr (die, DW_AT_external, cu);
15710 if ((attr2 && (DW_UNSND (attr2) != 0))
15711 || cu->language == language_ada)
15713 /* Subprograms marked external are stored as a global symbol.
15714 Ada subprograms, whether marked external or not, are always
15715 stored as a global symbol, because we want to be able to
15716 access them globally. For instance, we want to be able
15717 to break on a nested subprogram without having to
15718 specify the context. */
15719 list_to_add = &global_symbols;
15723 list_to_add = cu->list_in_scope;
15726 case DW_TAG_inlined_subroutine:
15727 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
15729 SYMBOL_CLASS (sym) = LOC_BLOCK;
15730 SYMBOL_INLINED (sym) = 1;
15731 list_to_add = cu->list_in_scope;
15733 case DW_TAG_template_value_param:
15735 /* Fall through. */
15736 case DW_TAG_constant:
15737 case DW_TAG_variable:
15738 case DW_TAG_member:
15739 /* Compilation with minimal debug info may result in
15740 variables with missing type entries. Change the
15741 misleading `void' type to something sensible. */
15742 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
15744 = objfile_type (objfile)->nodebug_data_symbol;
15746 attr = dwarf2_attr (die, DW_AT_const_value, cu);
15747 /* In the case of DW_TAG_member, we should only be called for
15748 static const members. */
15749 if (die->tag == DW_TAG_member)
15751 /* dwarf2_add_field uses die_is_declaration,
15752 so we do the same. */
15753 gdb_assert (die_is_declaration (die, cu));
15758 dwarf2_const_value (attr, sym, cu);
15759 attr2 = dwarf2_attr (die, DW_AT_external, cu);
15762 if (attr2 && (DW_UNSND (attr2) != 0))
15763 list_to_add = &global_symbols;
15765 list_to_add = cu->list_in_scope;
15769 attr = dwarf2_attr (die, DW_AT_location, cu);
15772 var_decode_location (attr, sym, cu);
15773 attr2 = dwarf2_attr (die, DW_AT_external, cu);
15775 /* Fortran explicitly imports any global symbols to the local
15776 scope by DW_TAG_common_block. */
15777 if (cu->language == language_fortran && die->parent
15778 && die->parent->tag == DW_TAG_common_block)
15781 if (SYMBOL_CLASS (sym) == LOC_STATIC
15782 && SYMBOL_VALUE_ADDRESS (sym) == 0
15783 && !dwarf2_per_objfile->has_section_at_zero)
15785 /* When a static variable is eliminated by the linker,
15786 the corresponding debug information is not stripped
15787 out, but the variable address is set to null;
15788 do not add such variables into symbol table. */
15790 else if (attr2 && (DW_UNSND (attr2) != 0))
15792 /* Workaround gfortran PR debug/40040 - it uses
15793 DW_AT_location for variables in -fPIC libraries which may
15794 get overriden by other libraries/executable and get
15795 a different address. Resolve it by the minimal symbol
15796 which may come from inferior's executable using copy
15797 relocation. Make this workaround only for gfortran as for
15798 other compilers GDB cannot guess the minimal symbol
15799 Fortran mangling kind. */
15800 if (cu->language == language_fortran && die->parent
15801 && die->parent->tag == DW_TAG_module
15803 && strncmp (cu->producer, "GNU Fortran ", 12) == 0)
15804 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
15806 /* A variable with DW_AT_external is never static,
15807 but it may be block-scoped. */
15808 list_to_add = (cu->list_in_scope == &file_symbols
15809 ? &global_symbols : cu->list_in_scope);
15812 list_to_add = cu->list_in_scope;
15816 /* We do not know the address of this symbol.
15817 If it is an external symbol and we have type information
15818 for it, enter the symbol as a LOC_UNRESOLVED symbol.
15819 The address of the variable will then be determined from
15820 the minimal symbol table whenever the variable is
15822 attr2 = dwarf2_attr (die, DW_AT_external, cu);
15824 /* Fortran explicitly imports any global symbols to the local
15825 scope by DW_TAG_common_block. */
15826 if (cu->language == language_fortran && die->parent
15827 && die->parent->tag == DW_TAG_common_block)
15829 /* SYMBOL_CLASS doesn't matter here because
15830 read_common_block is going to reset it. */
15832 list_to_add = cu->list_in_scope;
15834 else if (attr2 && (DW_UNSND (attr2) != 0)
15835 && dwarf2_attr (die, DW_AT_type, cu) != NULL)
15837 /* A variable with DW_AT_external is never static, but it
15838 may be block-scoped. */
15839 list_to_add = (cu->list_in_scope == &file_symbols
15840 ? &global_symbols : cu->list_in_scope);
15842 SYMBOL_CLASS (sym) = LOC_UNRESOLVED;
15844 else if (!die_is_declaration (die, cu))
15846 /* Use the default LOC_OPTIMIZED_OUT class. */
15847 gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT);
15849 list_to_add = cu->list_in_scope;
15853 case DW_TAG_formal_parameter:
15854 /* If we are inside a function, mark this as an argument. If
15855 not, we might be looking at an argument to an inlined function
15856 when we do not have enough information to show inlined frames;
15857 pretend it's a local variable in that case so that the user can
15859 if (context_stack_depth > 0
15860 && context_stack[context_stack_depth - 1].name != NULL)
15861 SYMBOL_IS_ARGUMENT (sym) = 1;
15862 attr = dwarf2_attr (die, DW_AT_location, cu);
15865 var_decode_location (attr, sym, cu);
15867 attr = dwarf2_attr (die, DW_AT_const_value, cu);
15870 dwarf2_const_value (attr, sym, cu);
15873 list_to_add = cu->list_in_scope;
15875 case DW_TAG_unspecified_parameters:
15876 /* From varargs functions; gdb doesn't seem to have any
15877 interest in this information, so just ignore it for now.
15880 case DW_TAG_template_type_param:
15882 /* Fall through. */
15883 case DW_TAG_class_type:
15884 case DW_TAG_interface_type:
15885 case DW_TAG_structure_type:
15886 case DW_TAG_union_type:
15887 case DW_TAG_set_type:
15888 case DW_TAG_enumeration_type:
15889 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
15890 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
15893 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
15894 really ever be static objects: otherwise, if you try
15895 to, say, break of a class's method and you're in a file
15896 which doesn't mention that class, it won't work unless
15897 the check for all static symbols in lookup_symbol_aux
15898 saves you. See the OtherFileClass tests in
15899 gdb.c++/namespace.exp. */
15903 list_to_add = (cu->list_in_scope == &file_symbols
15904 && (cu->language == language_cplus
15905 || cu->language == language_java)
15906 ? &global_symbols : cu->list_in_scope);
15908 /* The semantics of C++ state that "struct foo {
15909 ... }" also defines a typedef for "foo". A Java
15910 class declaration also defines a typedef for the
15912 if (cu->language == language_cplus
15913 || cu->language == language_java
15914 || cu->language == language_ada)
15916 /* The symbol's name is already allocated along
15917 with this objfile, so we don't need to
15918 duplicate it for the type. */
15919 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
15920 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym);
15925 case DW_TAG_typedef:
15926 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
15927 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
15928 list_to_add = cu->list_in_scope;
15930 case DW_TAG_base_type:
15931 case DW_TAG_subrange_type:
15932 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
15933 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
15934 list_to_add = cu->list_in_scope;
15936 case DW_TAG_enumerator:
15937 attr = dwarf2_attr (die, DW_AT_const_value, cu);
15940 dwarf2_const_value (attr, sym, cu);
15943 /* NOTE: carlton/2003-11-10: See comment above in the
15944 DW_TAG_class_type, etc. block. */
15946 list_to_add = (cu->list_in_scope == &file_symbols
15947 && (cu->language == language_cplus
15948 || cu->language == language_java)
15949 ? &global_symbols : cu->list_in_scope);
15952 case DW_TAG_namespace:
15953 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
15954 list_to_add = &global_symbols;
15956 case DW_TAG_common_block:
15957 SYMBOL_CLASS (sym) = LOC_STATIC;
15958 SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
15959 add_symbol_to_list (sym, cu->list_in_scope);
15962 /* Not a tag we recognize. Hopefully we aren't processing
15963 trash data, but since we must specifically ignore things
15964 we don't recognize, there is nothing else we should do at
15966 complaint (&symfile_complaints, _("unsupported tag: '%s'"),
15967 dwarf_tag_name (die->tag));
15973 sym->hash_next = objfile->template_symbols;
15974 objfile->template_symbols = sym;
15975 list_to_add = NULL;
15978 if (list_to_add != NULL)
15979 add_symbol_to_list (sym, list_to_add);
15981 /* For the benefit of old versions of GCC, check for anonymous
15982 namespaces based on the demangled name. */
15983 if (!processing_has_namespace_info
15984 && cu->language == language_cplus)
15985 cp_scan_for_anonymous_namespaces (sym, objfile);
15990 /* A wrapper for new_symbol_full that always allocates a new symbol. */
15992 static struct symbol *
15993 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
15995 return new_symbol_full (die, type, cu, NULL);
15998 /* Given an attr with a DW_FORM_dataN value in host byte order,
15999 zero-extend it as appropriate for the symbol's type. The DWARF
16000 standard (v4) is not entirely clear about the meaning of using
16001 DW_FORM_dataN for a constant with a signed type, where the type is
16002 wider than the data. The conclusion of a discussion on the DWARF
16003 list was that this is unspecified. We choose to always zero-extend
16004 because that is the interpretation long in use by GCC. */
16007 dwarf2_const_value_data (struct attribute *attr, struct type *type,
16008 const char *name, struct obstack *obstack,
16009 struct dwarf2_cu *cu, LONGEST *value, int bits)
16011 struct objfile *objfile = cu->objfile;
16012 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ?
16013 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
16014 LONGEST l = DW_UNSND (attr);
16016 if (bits < sizeof (*value) * 8)
16018 l &= ((LONGEST) 1 << bits) - 1;
16021 else if (bits == sizeof (*value) * 8)
16025 gdb_byte *bytes = obstack_alloc (obstack, bits / 8);
16026 store_unsigned_integer (bytes, bits / 8, byte_order, l);
16033 /* Read a constant value from an attribute. Either set *VALUE, or if
16034 the value does not fit in *VALUE, set *BYTES - either already
16035 allocated on the objfile obstack, or newly allocated on OBSTACK,
16036 or, set *BATON, if we translated the constant to a location
16040 dwarf2_const_value_attr (struct attribute *attr, struct type *type,
16041 const char *name, struct obstack *obstack,
16042 struct dwarf2_cu *cu,
16043 LONGEST *value, gdb_byte **bytes,
16044 struct dwarf2_locexpr_baton **baton)
16046 struct objfile *objfile = cu->objfile;
16047 struct comp_unit_head *cu_header = &cu->header;
16048 struct dwarf_block *blk;
16049 enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ?
16050 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
16056 switch (attr->form)
16059 case DW_FORM_GNU_addr_index:
16063 if (TYPE_LENGTH (type) != cu_header->addr_size)
16064 dwarf2_const_value_length_mismatch_complaint (name,
16065 cu_header->addr_size,
16066 TYPE_LENGTH (type));
16067 /* Symbols of this form are reasonably rare, so we just
16068 piggyback on the existing location code rather than writing
16069 a new implementation of symbol_computed_ops. */
16070 *baton = obstack_alloc (&objfile->objfile_obstack,
16071 sizeof (struct dwarf2_locexpr_baton));
16072 (*baton)->per_cu = cu->per_cu;
16073 gdb_assert ((*baton)->per_cu);
16075 (*baton)->size = 2 + cu_header->addr_size;
16076 data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size);
16077 (*baton)->data = data;
16079 data[0] = DW_OP_addr;
16080 store_unsigned_integer (&data[1], cu_header->addr_size,
16081 byte_order, DW_ADDR (attr));
16082 data[cu_header->addr_size + 1] = DW_OP_stack_value;
16085 case DW_FORM_string:
16087 case DW_FORM_GNU_str_index:
16088 case DW_FORM_GNU_strp_alt:
16089 /* DW_STRING is already allocated on the objfile obstack, point
16091 *bytes = (gdb_byte *) DW_STRING (attr);
16093 case DW_FORM_block1:
16094 case DW_FORM_block2:
16095 case DW_FORM_block4:
16096 case DW_FORM_block:
16097 case DW_FORM_exprloc:
16098 blk = DW_BLOCK (attr);
16099 if (TYPE_LENGTH (type) != blk->size)
16100 dwarf2_const_value_length_mismatch_complaint (name, blk->size,
16101 TYPE_LENGTH (type));
16102 *bytes = blk->data;
16105 /* The DW_AT_const_value attributes are supposed to carry the
16106 symbol's value "represented as it would be on the target
16107 architecture." By the time we get here, it's already been
16108 converted to host endianness, so we just need to sign- or
16109 zero-extend it as appropriate. */
16110 case DW_FORM_data1:
16111 *bytes = dwarf2_const_value_data (attr, type, name,
16112 obstack, cu, value, 8);
16114 case DW_FORM_data2:
16115 *bytes = dwarf2_const_value_data (attr, type, name,
16116 obstack, cu, value, 16);
16118 case DW_FORM_data4:
16119 *bytes = dwarf2_const_value_data (attr, type, name,
16120 obstack, cu, value, 32);
16122 case DW_FORM_data8:
16123 *bytes = dwarf2_const_value_data (attr, type, name,
16124 obstack, cu, value, 64);
16127 case DW_FORM_sdata:
16128 *value = DW_SND (attr);
16131 case DW_FORM_udata:
16132 *value = DW_UNSND (attr);
16136 complaint (&symfile_complaints,
16137 _("unsupported const value attribute form: '%s'"),
16138 dwarf_form_name (attr->form));
16145 /* Copy constant value from an attribute to a symbol. */
16148 dwarf2_const_value (struct attribute *attr, struct symbol *sym,
16149 struct dwarf2_cu *cu)
16151 struct objfile *objfile = cu->objfile;
16152 struct comp_unit_head *cu_header = &cu->header;
16155 struct dwarf2_locexpr_baton *baton;
16157 dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym),
16158 SYMBOL_PRINT_NAME (sym),
16159 &objfile->objfile_obstack, cu,
16160 &value, &bytes, &baton);
16164 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
16165 SYMBOL_LOCATION_BATON (sym) = baton;
16166 SYMBOL_CLASS (sym) = LOC_COMPUTED;
16168 else if (bytes != NULL)
16170 SYMBOL_VALUE_BYTES (sym) = bytes;
16171 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
16175 SYMBOL_VALUE (sym) = value;
16176 SYMBOL_CLASS (sym) = LOC_CONST;
16180 /* Return the type of the die in question using its DW_AT_type attribute. */
16182 static struct type *
16183 die_type (struct die_info *die, struct dwarf2_cu *cu)
16185 struct attribute *type_attr;
16187 type_attr = dwarf2_attr (die, DW_AT_type, cu);
16190 /* A missing DW_AT_type represents a void type. */
16191 return objfile_type (cu->objfile)->builtin_void;
16194 return lookup_die_type (die, type_attr, cu);
16197 /* True iff CU's producer generates GNAT Ada auxiliary information
16198 that allows to find parallel types through that information instead
16199 of having to do expensive parallel lookups by type name. */
16202 need_gnat_info (struct dwarf2_cu *cu)
16204 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
16205 of GNAT produces this auxiliary information, without any indication
16206 that it is produced. Part of enhancing the FSF version of GNAT
16207 to produce that information will be to put in place an indicator
16208 that we can use in order to determine whether the descriptive type
16209 info is available or not. One suggestion that has been made is
16210 to use a new attribute, attached to the CU die. For now, assume
16211 that the descriptive type info is not available. */
16215 /* Return the auxiliary type of the die in question using its
16216 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
16217 attribute is not present. */
16219 static struct type *
16220 die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu)
16222 struct attribute *type_attr;
16224 type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu);
16228 return lookup_die_type (die, type_attr, cu);
16231 /* If DIE has a descriptive_type attribute, then set the TYPE's
16232 descriptive type accordingly. */
16235 set_descriptive_type (struct type *type, struct die_info *die,
16236 struct dwarf2_cu *cu)
16238 struct type *descriptive_type = die_descriptive_type (die, cu);
16240 if (descriptive_type)
16242 ALLOCATE_GNAT_AUX_TYPE (type);
16243 TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type;
16247 /* Return the containing type of the die in question using its
16248 DW_AT_containing_type attribute. */
16250 static struct type *
16251 die_containing_type (struct die_info *die, struct dwarf2_cu *cu)
16253 struct attribute *type_attr;
16255 type_attr = dwarf2_attr (die, DW_AT_containing_type, cu);
16257 error (_("Dwarf Error: Problem turning containing type into gdb type "
16258 "[in module %s]"), cu->objfile->name);
16260 return lookup_die_type (die, type_attr, cu);
16263 /* Look up the type of DIE in CU using its type attribute ATTR.
16264 If there is no type substitute an error marker. */
16266 static struct type *
16267 lookup_die_type (struct die_info *die, struct attribute *attr,
16268 struct dwarf2_cu *cu)
16270 struct objfile *objfile = cu->objfile;
16271 struct type *this_type;
16273 /* First see if we have it cached. */
16275 if (attr->form == DW_FORM_GNU_ref_alt)
16277 struct dwarf2_per_cu_data *per_cu;
16278 sect_offset offset = dwarf2_get_ref_die_offset (attr);
16280 per_cu = dwarf2_find_containing_comp_unit (offset, 1, cu->objfile);
16281 this_type = get_die_type_at_offset (offset, per_cu);
16283 else if (is_ref_attr (attr))
16285 sect_offset offset = dwarf2_get_ref_die_offset (attr);
16287 this_type = get_die_type_at_offset (offset, cu->per_cu);
16289 else if (attr->form == DW_FORM_ref_sig8)
16291 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
16293 /* sig_type will be NULL if the signatured type is missing from
16295 if (sig_type == NULL)
16296 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
16297 "at 0x%x [in module %s]"),
16298 die->offset.sect_off, objfile->name);
16300 gdb_assert (sig_type->per_cu.is_debug_types);
16301 /* If we haven't filled in type_offset_in_section yet, then we
16302 haven't read the type in yet. */
16304 if (sig_type->type_offset_in_section.sect_off != 0)
16307 get_die_type_at_offset (sig_type->type_offset_in_section,
16308 &sig_type->per_cu);
16313 dump_die_for_error (die);
16314 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
16315 dwarf_attr_name (attr->name), objfile->name);
16318 /* If not cached we need to read it in. */
16320 if (this_type == NULL)
16322 struct die_info *type_die;
16323 struct dwarf2_cu *type_cu = cu;
16325 type_die = follow_die_ref_or_sig (die, attr, &type_cu);
16326 /* If we found the type now, it's probably because the type came
16327 from an inter-CU reference and the type's CU got expanded before
16329 this_type = get_die_type (type_die, type_cu);
16330 if (this_type == NULL)
16331 this_type = read_type_die_1 (type_die, type_cu);
16334 /* If we still don't have a type use an error marker. */
16336 if (this_type == NULL)
16338 char *message, *saved;
16340 /* read_type_die already issued a complaint. */
16341 message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
16343 cu->header.offset.sect_off,
16344 die->offset.sect_off);
16345 saved = obstack_copy0 (&objfile->objfile_obstack,
16346 message, strlen (message));
16349 this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
16355 /* Return the type in DIE, CU.
16356 Returns NULL for invalid types.
16358 This first does a lookup in the appropriate type_hash table,
16359 and only reads the die in if necessary.
16361 NOTE: This can be called when reading in partial or full symbols. */
16363 static struct type *
16364 read_type_die (struct die_info *die, struct dwarf2_cu *cu)
16366 struct type *this_type;
16368 this_type = get_die_type (die, cu);
16372 return read_type_die_1 (die, cu);
16375 /* Read the type in DIE, CU.
16376 Returns NULL for invalid types. */
16378 static struct type *
16379 read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
16381 struct type *this_type = NULL;
16385 case DW_TAG_class_type:
16386 case DW_TAG_interface_type:
16387 case DW_TAG_structure_type:
16388 case DW_TAG_union_type:
16389 this_type = read_structure_type (die, cu);
16391 case DW_TAG_enumeration_type:
16392 this_type = read_enumeration_type (die, cu);
16394 case DW_TAG_subprogram:
16395 case DW_TAG_subroutine_type:
16396 case DW_TAG_inlined_subroutine:
16397 this_type = read_subroutine_type (die, cu);
16399 case DW_TAG_array_type:
16400 this_type = read_array_type (die, cu);
16402 case DW_TAG_set_type:
16403 this_type = read_set_type (die, cu);
16405 case DW_TAG_pointer_type:
16406 this_type = read_tag_pointer_type (die, cu);
16408 case DW_TAG_ptr_to_member_type:
16409 this_type = read_tag_ptr_to_member_type (die, cu);
16411 case DW_TAG_reference_type:
16412 this_type = read_tag_reference_type (die, cu);
16414 case DW_TAG_const_type:
16415 this_type = read_tag_const_type (die, cu);
16417 case DW_TAG_volatile_type:
16418 this_type = read_tag_volatile_type (die, cu);
16420 case DW_TAG_string_type:
16421 this_type = read_tag_string_type (die, cu);
16423 case DW_TAG_typedef:
16424 this_type = read_typedef (die, cu);
16426 case DW_TAG_subrange_type:
16427 this_type = read_subrange_type (die, cu);
16429 case DW_TAG_base_type:
16430 this_type = read_base_type (die, cu);
16432 case DW_TAG_unspecified_type:
16433 this_type = read_unspecified_type (die, cu);
16435 case DW_TAG_namespace:
16436 this_type = read_namespace_type (die, cu);
16438 case DW_TAG_module:
16439 this_type = read_module_type (die, cu);
16442 complaint (&symfile_complaints,
16443 _("unexpected tag in read_type_die: '%s'"),
16444 dwarf_tag_name (die->tag));
16451 /* See if we can figure out if the class lives in a namespace. We do
16452 this by looking for a member function; its demangled name will
16453 contain namespace info, if there is any.
16454 Return the computed name or NULL.
16455 Space for the result is allocated on the objfile's obstack.
16456 This is the full-die version of guess_partial_die_structure_name.
16457 In this case we know DIE has no useful parent. */
16460 guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu)
16462 struct die_info *spec_die;
16463 struct dwarf2_cu *spec_cu;
16464 struct die_info *child;
16467 spec_die = die_specification (die, &spec_cu);
16468 if (spec_die != NULL)
16474 for (child = die->child;
16476 child = child->sibling)
16478 if (child->tag == DW_TAG_subprogram)
16480 struct attribute *attr;
16482 attr = dwarf2_attr (child, DW_AT_linkage_name, cu);
16484 attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu);
16488 = language_class_name_from_physname (cu->language_defn,
16492 if (actual_name != NULL)
16494 char *die_name = dwarf2_name (die, cu);
16496 if (die_name != NULL
16497 && strcmp (die_name, actual_name) != 0)
16499 /* Strip off the class name from the full name.
16500 We want the prefix. */
16501 int die_name_len = strlen (die_name);
16502 int actual_name_len = strlen (actual_name);
16504 /* Test for '::' as a sanity check. */
16505 if (actual_name_len > die_name_len + 2
16506 && actual_name[actual_name_len
16507 - die_name_len - 1] == ':')
16509 obsavestring (actual_name,
16510 actual_name_len - die_name_len - 2,
16511 &cu->objfile->objfile_obstack);
16514 xfree (actual_name);
16523 /* GCC might emit a nameless typedef that has a linkage name. Determine the
16524 prefix part in such case. See
16525 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16528 anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu)
16530 struct attribute *attr;
16533 if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type
16534 && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type)
16537 attr = dwarf2_attr (die, DW_AT_name, cu);
16538 if (attr != NULL && DW_STRING (attr) != NULL)
16541 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
16543 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
16544 if (attr == NULL || DW_STRING (attr) == NULL)
16547 /* dwarf2_name had to be already called. */
16548 gdb_assert (DW_STRING_IS_CANONICAL (attr));
16550 /* Strip the base name, keep any leading namespaces/classes. */
16551 base = strrchr (DW_STRING (attr), ':');
16552 if (base == NULL || base == DW_STRING (attr) || base[-1] != ':')
16555 return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr),
16556 &cu->objfile->objfile_obstack);
16559 /* Return the name of the namespace/class that DIE is defined within,
16560 or "" if we can't tell. The caller should not xfree the result.
16562 For example, if we're within the method foo() in the following
16572 then determine_prefix on foo's die will return "N::C". */
16574 static const char *
16575 determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
16577 struct die_info *parent, *spec_die;
16578 struct dwarf2_cu *spec_cu;
16579 struct type *parent_type;
16582 if (cu->language != language_cplus && cu->language != language_java
16583 && cu->language != language_fortran)
16586 retval = anonymous_struct_prefix (die, cu);
16590 /* We have to be careful in the presence of DW_AT_specification.
16591 For example, with GCC 3.4, given the code
16595 // Definition of N::foo.
16599 then we'll have a tree of DIEs like this:
16601 1: DW_TAG_compile_unit
16602 2: DW_TAG_namespace // N
16603 3: DW_TAG_subprogram // declaration of N::foo
16604 4: DW_TAG_subprogram // definition of N::foo
16605 DW_AT_specification // refers to die #3
16607 Thus, when processing die #4, we have to pretend that we're in
16608 the context of its DW_AT_specification, namely the contex of die
16611 spec_die = die_specification (die, &spec_cu);
16612 if (spec_die == NULL)
16613 parent = die->parent;
16616 parent = spec_die->parent;
16620 if (parent == NULL)
16622 else if (parent->building_fullname)
16625 const char *parent_name;
16627 /* It has been seen on RealView 2.2 built binaries,
16628 DW_TAG_template_type_param types actually _defined_ as
16629 children of the parent class:
16632 template class <class Enum> Class{};
16633 Class<enum E> class_e;
16635 1: DW_TAG_class_type (Class)
16636 2: DW_TAG_enumeration_type (E)
16637 3: DW_TAG_enumerator (enum1:0)
16638 3: DW_TAG_enumerator (enum2:1)
16640 2: DW_TAG_template_type_param
16641 DW_AT_type DW_FORM_ref_udata (E)
16643 Besides being broken debug info, it can put GDB into an
16644 infinite loop. Consider:
16646 When we're building the full name for Class<E>, we'll start
16647 at Class, and go look over its template type parameters,
16648 finding E. We'll then try to build the full name of E, and
16649 reach here. We're now trying to build the full name of E,
16650 and look over the parent DIE for containing scope. In the
16651 broken case, if we followed the parent DIE of E, we'd again
16652 find Class, and once again go look at its template type
16653 arguments, etc., etc. Simply don't consider such parent die
16654 as source-level parent of this die (it can't be, the language
16655 doesn't allow it), and break the loop here. */
16656 name = dwarf2_name (die, cu);
16657 parent_name = dwarf2_name (parent, cu);
16658 complaint (&symfile_complaints,
16659 _("template param type '%s' defined within parent '%s'"),
16660 name ? name : "<unknown>",
16661 parent_name ? parent_name : "<unknown>");
16665 switch (parent->tag)
16667 case DW_TAG_namespace:
16668 parent_type = read_type_die (parent, cu);
16669 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
16670 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
16671 Work around this problem here. */
16672 if (cu->language == language_cplus
16673 && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0)
16675 /* We give a name to even anonymous namespaces. */
16676 return TYPE_TAG_NAME (parent_type);
16677 case DW_TAG_class_type:
16678 case DW_TAG_interface_type:
16679 case DW_TAG_structure_type:
16680 case DW_TAG_union_type:
16681 case DW_TAG_module:
16682 parent_type = read_type_die (parent, cu);
16683 if (TYPE_TAG_NAME (parent_type) != NULL)
16684 return TYPE_TAG_NAME (parent_type);
16686 /* An anonymous structure is only allowed non-static data
16687 members; no typedefs, no member functions, et cetera.
16688 So it does not need a prefix. */
16690 case DW_TAG_compile_unit:
16691 case DW_TAG_partial_unit:
16692 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
16693 if (cu->language == language_cplus
16694 && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
16695 && die->child != NULL
16696 && (die->tag == DW_TAG_class_type
16697 || die->tag == DW_TAG_structure_type
16698 || die->tag == DW_TAG_union_type))
16700 char *name = guess_full_die_structure_name (die, cu);
16706 return determine_prefix (parent, cu);
16710 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
16711 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
16712 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
16713 an obconcat, otherwise allocate storage for the result. The CU argument is
16714 used to determine the language and hence, the appropriate separator. */
16716 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
16719 typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
16720 int physname, struct dwarf2_cu *cu)
16722 const char *lead = "";
16725 if (suffix == NULL || suffix[0] == '\0'
16726 || prefix == NULL || prefix[0] == '\0')
16728 else if (cu->language == language_java)
16730 else if (cu->language == language_fortran && physname)
16732 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
16733 DW_AT_MIPS_linkage_name is preferred and used instead. */
16741 if (prefix == NULL)
16743 if (suffix == NULL)
16749 = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1);
16751 strcpy (retval, lead);
16752 strcat (retval, prefix);
16753 strcat (retval, sep);
16754 strcat (retval, suffix);
16759 /* We have an obstack. */
16760 return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL);
16764 /* Return sibling of die, NULL if no sibling. */
16766 static struct die_info *
16767 sibling_die (struct die_info *die)
16769 return die->sibling;
16772 /* Get name of a die, return NULL if not found. */
16775 dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu,
16776 struct obstack *obstack)
16778 if (name && cu->language == language_cplus)
16780 char *canon_name = cp_canonicalize_string (name);
16782 if (canon_name != NULL)
16784 if (strcmp (canon_name, name) != 0)
16785 name = obsavestring (canon_name, strlen (canon_name),
16787 xfree (canon_name);
16794 /* Get name of a die, return NULL if not found. */
16797 dwarf2_name (struct die_info *die, struct dwarf2_cu *cu)
16799 struct attribute *attr;
16801 attr = dwarf2_attr (die, DW_AT_name, cu);
16802 if ((!attr || !DW_STRING (attr))
16803 && die->tag != DW_TAG_class_type
16804 && die->tag != DW_TAG_interface_type
16805 && die->tag != DW_TAG_structure_type
16806 && die->tag != DW_TAG_union_type)
16811 case DW_TAG_compile_unit:
16812 case DW_TAG_partial_unit:
16813 /* Compilation units have a DW_AT_name that is a filename, not
16814 a source language identifier. */
16815 case DW_TAG_enumeration_type:
16816 case DW_TAG_enumerator:
16817 /* These tags always have simple identifiers already; no need
16818 to canonicalize them. */
16819 return DW_STRING (attr);
16821 case DW_TAG_subprogram:
16822 /* Java constructors will all be named "<init>", so return
16823 the class name when we see this special case. */
16824 if (cu->language == language_java
16825 && DW_STRING (attr) != NULL
16826 && strcmp (DW_STRING (attr), "<init>") == 0)
16828 struct dwarf2_cu *spec_cu = cu;
16829 struct die_info *spec_die;
16831 /* GCJ will output '<init>' for Java constructor names.
16832 For this special case, return the name of the parent class. */
16834 /* GCJ may output suprogram DIEs with AT_specification set.
16835 If so, use the name of the specified DIE. */
16836 spec_die = die_specification (die, &spec_cu);
16837 if (spec_die != NULL)
16838 return dwarf2_name (spec_die, spec_cu);
16843 if (die->tag == DW_TAG_class_type)
16844 return dwarf2_name (die, cu);
16846 while (die->tag != DW_TAG_compile_unit
16847 && die->tag != DW_TAG_partial_unit);
16851 case DW_TAG_class_type:
16852 case DW_TAG_interface_type:
16853 case DW_TAG_structure_type:
16854 case DW_TAG_union_type:
16855 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
16856 structures or unions. These were of the form "._%d" in GCC 4.1,
16857 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
16858 and GCC 4.4. We work around this problem by ignoring these. */
16859 if (attr && DW_STRING (attr)
16860 && (strncmp (DW_STRING (attr), "._", 2) == 0
16861 || strncmp (DW_STRING (attr), "<anonymous", 10) == 0))
16864 /* GCC might emit a nameless typedef that has a linkage name. See
16865 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
16866 if (!attr || DW_STRING (attr) == NULL)
16868 char *demangled = NULL;
16870 attr = dwarf2_attr (die, DW_AT_linkage_name, cu);
16872 attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
16874 if (attr == NULL || DW_STRING (attr) == NULL)
16877 /* Avoid demangling DW_STRING (attr) the second time on a second
16878 call for the same DIE. */
16879 if (!DW_STRING_IS_CANONICAL (attr))
16880 demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES);
16886 /* FIXME: we already did this for the partial symbol... */
16887 DW_STRING (attr) = obsavestring (demangled, strlen (demangled),
16888 &cu->objfile->objfile_obstack);
16889 DW_STRING_IS_CANONICAL (attr) = 1;
16892 /* Strip any leading namespaces/classes, keep only the base name.
16893 DW_AT_name for named DIEs does not contain the prefixes. */
16894 base = strrchr (DW_STRING (attr), ':');
16895 if (base && base > DW_STRING (attr) && base[-1] == ':')
16898 return DW_STRING (attr);
16907 if (!DW_STRING_IS_CANONICAL (attr))
16910 = dwarf2_canonicalize_name (DW_STRING (attr), cu,
16911 &cu->objfile->objfile_obstack);
16912 DW_STRING_IS_CANONICAL (attr) = 1;
16914 return DW_STRING (attr);
16917 /* Return the die that this die in an extension of, or NULL if there
16918 is none. *EXT_CU is the CU containing DIE on input, and the CU
16919 containing the return value on output. */
16921 static struct die_info *
16922 dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu)
16924 struct attribute *attr;
16926 attr = dwarf2_attr (die, DW_AT_extension, *ext_cu);
16930 return follow_die_ref (die, attr, ext_cu);
16933 /* Convert a DIE tag into its string name. */
16935 static const char *
16936 dwarf_tag_name (unsigned tag)
16938 const char *name = get_DW_TAG_name (tag);
16941 return "DW_TAG_<unknown>";
16946 /* Convert a DWARF attribute code into its string name. */
16948 static const char *
16949 dwarf_attr_name (unsigned attr)
16953 #ifdef MIPS /* collides with DW_AT_HP_block_index */
16954 if (attr == DW_AT_MIPS_fde)
16955 return "DW_AT_MIPS_fde";
16957 if (attr == DW_AT_HP_block_index)
16958 return "DW_AT_HP_block_index";
16961 name = get_DW_AT_name (attr);
16964 return "DW_AT_<unknown>";
16969 /* Convert a DWARF value form code into its string name. */
16971 static const char *
16972 dwarf_form_name (unsigned form)
16974 const char *name = get_DW_FORM_name (form);
16977 return "DW_FORM_<unknown>";
16983 dwarf_bool_name (unsigned mybool)
16991 /* Convert a DWARF type code into its string name. */
16993 static const char *
16994 dwarf_type_encoding_name (unsigned enc)
16996 const char *name = get_DW_ATE_name (enc);
16999 return "DW_ATE_<unknown>";
17005 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
17009 print_spaces (indent, f);
17010 fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n",
17011 dwarf_tag_name (die->tag), die->abbrev, die->offset.sect_off);
17013 if (die->parent != NULL)
17015 print_spaces (indent, f);
17016 fprintf_unfiltered (f, " parent at offset: 0x%x\n",
17017 die->parent->offset.sect_off);
17020 print_spaces (indent, f);
17021 fprintf_unfiltered (f, " has children: %s\n",
17022 dwarf_bool_name (die->child != NULL));
17024 print_spaces (indent, f);
17025 fprintf_unfiltered (f, " attributes:\n");
17027 for (i = 0; i < die->num_attrs; ++i)
17029 print_spaces (indent, f);
17030 fprintf_unfiltered (f, " %s (%s) ",
17031 dwarf_attr_name (die->attrs[i].name),
17032 dwarf_form_name (die->attrs[i].form));
17034 switch (die->attrs[i].form)
17037 case DW_FORM_GNU_addr_index:
17038 fprintf_unfiltered (f, "address: ");
17039 fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f);
17041 case DW_FORM_block2:
17042 case DW_FORM_block4:
17043 case DW_FORM_block:
17044 case DW_FORM_block1:
17045 fprintf_unfiltered (f, "block: size %s",
17046 pulongest (DW_BLOCK (&die->attrs[i])->size));
17048 case DW_FORM_exprloc:
17049 fprintf_unfiltered (f, "expression: size %s",
17050 pulongest (DW_BLOCK (&die->attrs[i])->size));
17052 case DW_FORM_ref_addr:
17053 fprintf_unfiltered (f, "ref address: ");
17054 fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
17056 case DW_FORM_GNU_ref_alt:
17057 fprintf_unfiltered (f, "alt ref address: ");
17058 fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f);
17064 case DW_FORM_ref_udata:
17065 fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)",
17066 (long) (DW_UNSND (&die->attrs[i])));
17068 case DW_FORM_data1:
17069 case DW_FORM_data2:
17070 case DW_FORM_data4:
17071 case DW_FORM_data8:
17072 case DW_FORM_udata:
17073 case DW_FORM_sdata:
17074 fprintf_unfiltered (f, "constant: %s",
17075 pulongest (DW_UNSND (&die->attrs[i])));
17077 case DW_FORM_sec_offset:
17078 fprintf_unfiltered (f, "section offset: %s",
17079 pulongest (DW_UNSND (&die->attrs[i])));
17081 case DW_FORM_ref_sig8:
17082 if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL)
17083 fprintf_unfiltered (f, "signatured type, offset: 0x%x",
17084 DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset.sect_off);
17086 fprintf_unfiltered (f, "signatured type, offset: unknown");
17088 case DW_FORM_string:
17090 case DW_FORM_GNU_str_index:
17091 case DW_FORM_GNU_strp_alt:
17092 fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)",
17093 DW_STRING (&die->attrs[i])
17094 ? DW_STRING (&die->attrs[i]) : "",
17095 DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not");
17098 if (DW_UNSND (&die->attrs[i]))
17099 fprintf_unfiltered (f, "flag: TRUE");
17101 fprintf_unfiltered (f, "flag: FALSE");
17103 case DW_FORM_flag_present:
17104 fprintf_unfiltered (f, "flag: TRUE");
17106 case DW_FORM_indirect:
17107 /* The reader will have reduced the indirect form to
17108 the "base form" so this form should not occur. */
17109 fprintf_unfiltered (f,
17110 "unexpected attribute form: DW_FORM_indirect");
17113 fprintf_unfiltered (f, "unsupported attribute form: %d.",
17114 die->attrs[i].form);
17117 fprintf_unfiltered (f, "\n");
17122 dump_die_for_error (struct die_info *die)
17124 dump_die_shallow (gdb_stderr, 0, die);
17128 dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die)
17130 int indent = level * 4;
17132 gdb_assert (die != NULL);
17134 if (level >= max_level)
17137 dump_die_shallow (f, indent, die);
17139 if (die->child != NULL)
17141 print_spaces (indent, f);
17142 fprintf_unfiltered (f, " Children:");
17143 if (level + 1 < max_level)
17145 fprintf_unfiltered (f, "\n");
17146 dump_die_1 (f, level + 1, max_level, die->child);
17150 fprintf_unfiltered (f,
17151 " [not printed, max nesting level reached]\n");
17155 if (die->sibling != NULL && level > 0)
17157 dump_die_1 (f, level, max_level, die->sibling);
17161 /* This is called from the pdie macro in gdbinit.in.
17162 It's not static so gcc will keep a copy callable from gdb. */
17165 dump_die (struct die_info *die, int max_level)
17167 dump_die_1 (gdb_stdlog, 0, max_level, die);
17171 store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
17175 slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset.sect_off,
17181 /* DW_ADDR is always stored already as sect_offset; despite for the forms
17182 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
17185 is_ref_attr (struct attribute *attr)
17187 switch (attr->form)
17189 case DW_FORM_ref_addr:
17194 case DW_FORM_ref_udata:
17195 case DW_FORM_GNU_ref_alt:
17202 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
17206 dwarf2_get_ref_die_offset (struct attribute *attr)
17208 sect_offset retval = { DW_UNSND (attr) };
17210 if (is_ref_attr (attr))
17213 retval.sect_off = 0;
17214 complaint (&symfile_complaints,
17215 _("unsupported die ref attribute form: '%s'"),
17216 dwarf_form_name (attr->form));
17220 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
17221 * the value held by the attribute is not constant. */
17224 dwarf2_get_attr_constant_value (struct attribute *attr, int default_value)
17226 if (attr->form == DW_FORM_sdata)
17227 return DW_SND (attr);
17228 else if (attr->form == DW_FORM_udata
17229 || attr->form == DW_FORM_data1
17230 || attr->form == DW_FORM_data2
17231 || attr->form == DW_FORM_data4
17232 || attr->form == DW_FORM_data8)
17233 return DW_UNSND (attr);
17236 complaint (&symfile_complaints,
17237 _("Attribute value is not a constant (%s)"),
17238 dwarf_form_name (attr->form));
17239 return default_value;
17243 /* Follow reference or signature attribute ATTR of SRC_DIE.
17244 On entry *REF_CU is the CU of SRC_DIE.
17245 On exit *REF_CU is the CU of the result. */
17247 static struct die_info *
17248 follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr,
17249 struct dwarf2_cu **ref_cu)
17251 struct die_info *die;
17253 if (is_ref_attr (attr))
17254 die = follow_die_ref (src_die, attr, ref_cu);
17255 else if (attr->form == DW_FORM_ref_sig8)
17256 die = follow_die_sig (src_die, attr, ref_cu);
17259 dump_die_for_error (src_die);
17260 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
17261 (*ref_cu)->objfile->name);
17267 /* Follow reference OFFSET.
17268 On entry *REF_CU is the CU of the source die referencing OFFSET.
17269 On exit *REF_CU is the CU of the result.
17270 Returns NULL if OFFSET is invalid. */
17272 static struct die_info *
17273 follow_die_offset (sect_offset offset, int offset_in_dwz,
17274 struct dwarf2_cu **ref_cu)
17276 struct die_info temp_die;
17277 struct dwarf2_cu *target_cu, *cu = *ref_cu;
17279 gdb_assert (cu->per_cu != NULL);
17283 if (cu->per_cu->is_debug_types)
17285 /* .debug_types CUs cannot reference anything outside their CU.
17286 If they need to, they have to reference a signatured type via
17287 DW_FORM_ref_sig8. */
17288 if (! offset_in_cu_p (&cu->header, offset))
17291 else if (offset_in_dwz != cu->per_cu->is_dwz
17292 || ! offset_in_cu_p (&cu->header, offset))
17294 struct dwarf2_per_cu_data *per_cu;
17296 per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz,
17299 /* If necessary, add it to the queue and load its DIEs. */
17300 if (maybe_queue_comp_unit (cu, per_cu, cu->language))
17301 load_full_comp_unit (per_cu, cu->language);
17303 target_cu = per_cu->cu;
17305 else if (cu->dies == NULL)
17307 /* We're loading full DIEs during partial symbol reading. */
17308 gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
17309 load_full_comp_unit (cu->per_cu, language_minimal);
17312 *ref_cu = target_cu;
17313 temp_die.offset = offset;
17314 return htab_find_with_hash (target_cu->die_hash, &temp_die, offset.sect_off);
17317 /* Follow reference attribute ATTR of SRC_DIE.
17318 On entry *REF_CU is the CU of SRC_DIE.
17319 On exit *REF_CU is the CU of the result. */
17321 static struct die_info *
17322 follow_die_ref (struct die_info *src_die, struct attribute *attr,
17323 struct dwarf2_cu **ref_cu)
17325 sect_offset offset = dwarf2_get_ref_die_offset (attr);
17326 struct dwarf2_cu *cu = *ref_cu;
17327 struct die_info *die;
17329 die = follow_die_offset (offset,
17330 (attr->form == DW_FORM_GNU_ref_alt
17331 || cu->per_cu->is_dwz),
17334 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
17335 "at 0x%x [in module %s]"),
17336 offset.sect_off, src_die->offset.sect_off, cu->objfile->name);
17341 /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU.
17342 Returned value is intended for DW_OP_call*. Returned
17343 dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */
17345 struct dwarf2_locexpr_baton
17346 dwarf2_fetch_die_location_block (cu_offset offset_in_cu,
17347 struct dwarf2_per_cu_data *per_cu,
17348 CORE_ADDR (*get_frame_pc) (void *baton),
17351 sect_offset offset = { per_cu->offset.sect_off + offset_in_cu.cu_off };
17352 struct dwarf2_cu *cu;
17353 struct die_info *die;
17354 struct attribute *attr;
17355 struct dwarf2_locexpr_baton retval;
17357 dw2_setup (per_cu->objfile);
17359 if (per_cu->cu == NULL)
17363 die = follow_die_offset (offset, per_cu->is_dwz, &cu);
17365 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
17366 offset.sect_off, per_cu->objfile->name);
17368 attr = dwarf2_attr (die, DW_AT_location, cu);
17371 /* DWARF: "If there is no such attribute, then there is no effect.".
17372 DATA is ignored if SIZE is 0. */
17374 retval.data = NULL;
17377 else if (attr_form_is_section_offset (attr))
17379 struct dwarf2_loclist_baton loclist_baton;
17380 CORE_ADDR pc = (*get_frame_pc) (baton);
17383 fill_in_loclist_baton (cu, &loclist_baton, attr);
17385 retval.data = dwarf2_find_location_expression (&loclist_baton,
17387 retval.size = size;
17391 if (!attr_form_is_block (attr))
17392 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
17393 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
17394 offset.sect_off, per_cu->objfile->name);
17396 retval.data = DW_BLOCK (attr)->data;
17397 retval.size = DW_BLOCK (attr)->size;
17399 retval.per_cu = cu->per_cu;
17401 age_cached_comp_units ();
17406 /* Return the type of the DIE at DIE_OFFSET in the CU named by
17410 dwarf2_get_die_type (cu_offset die_offset,
17411 struct dwarf2_per_cu_data *per_cu)
17413 sect_offset die_offset_sect;
17415 dw2_setup (per_cu->objfile);
17417 die_offset_sect.sect_off = per_cu->offset.sect_off + die_offset.cu_off;
17418 return get_die_type_at_offset (die_offset_sect, per_cu);
17421 /* Follow the signature attribute ATTR in SRC_DIE.
17422 On entry *REF_CU is the CU of SRC_DIE.
17423 On exit *REF_CU is the CU of the result. */
17425 static struct die_info *
17426 follow_die_sig (struct die_info *src_die, struct attribute *attr,
17427 struct dwarf2_cu **ref_cu)
17429 struct objfile *objfile = (*ref_cu)->objfile;
17430 struct die_info temp_die;
17431 struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr);
17432 struct dwarf2_cu *sig_cu;
17433 struct die_info *die;
17435 /* sig_type will be NULL if the signatured type is missing from
17437 if (sig_type == NULL)
17438 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
17439 "at 0x%x [in module %s]"),
17440 src_die->offset.sect_off, objfile->name);
17442 /* If necessary, add it to the queue and load its DIEs. */
17444 if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, language_minimal))
17445 read_signatured_type (sig_type);
17447 gdb_assert (sig_type->per_cu.cu != NULL);
17449 sig_cu = sig_type->per_cu.cu;
17450 gdb_assert (sig_type->type_offset_in_section.sect_off != 0);
17451 temp_die.offset = sig_type->type_offset_in_section;
17452 die = htab_find_with_hash (sig_cu->die_hash, &temp_die,
17453 temp_die.offset.sect_off);
17460 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
17461 "from DIE at 0x%x [in module %s]"),
17462 temp_die.offset.sect_off, src_die->offset.sect_off, objfile->name);
17465 /* Given an offset of a signatured type, return its signatured_type. */
17467 static struct signatured_type *
17468 lookup_signatured_type_at_offset (struct objfile *objfile,
17469 struct dwarf2_section_info *section,
17470 sect_offset offset)
17472 gdb_byte *info_ptr = section->buffer + offset.sect_off;
17473 unsigned int length, initial_length_size;
17474 unsigned int sig_offset;
17475 struct signatured_type find_entry, *sig_type;
17477 length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size);
17478 sig_offset = (initial_length_size
17480 + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/
17481 + 1 /*address_size*/);
17482 find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset);
17483 sig_type = htab_find (dwarf2_per_objfile->signatured_types, &find_entry);
17485 /* This is only used to lookup previously recorded types.
17486 If we didn't find it, it's our bug. */
17487 gdb_assert (sig_type != NULL);
17488 gdb_assert (offset.sect_off == sig_type->per_cu.offset.sect_off);
17493 /* Load the DIEs associated with type unit PER_CU into memory. */
17496 load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
17498 struct signatured_type *sig_type;
17500 /* Caller is responsible for ensuring type_unit_groups don't get here. */
17501 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu));
17503 /* We have the per_cu, but we need the signatured_type.
17504 Fortunately this is an easy translation. */
17505 gdb_assert (per_cu->is_debug_types);
17506 sig_type = (struct signatured_type *) per_cu;
17508 gdb_assert (per_cu->cu == NULL);
17510 read_signatured_type (sig_type);
17512 gdb_assert (per_cu->cu != NULL);
17515 /* die_reader_func for read_signatured_type.
17516 This is identical to load_full_comp_unit_reader,
17517 but is kept separate for now. */
17520 read_signatured_type_reader (const struct die_reader_specs *reader,
17521 gdb_byte *info_ptr,
17522 struct die_info *comp_unit_die,
17526 struct dwarf2_cu *cu = reader->cu;
17528 gdb_assert (cu->die_hash == NULL);
17530 htab_create_alloc_ex (cu->header.length / 12,
17534 &cu->comp_unit_obstack,
17535 hashtab_obstack_allocate,
17536 dummy_obstack_deallocate);
17539 comp_unit_die->child = read_die_and_siblings (reader, info_ptr,
17540 &info_ptr, comp_unit_die);
17541 cu->dies = comp_unit_die;
17542 /* comp_unit_die is not stored in die_hash, no need. */
17544 /* We try not to read any attributes in this function, because not
17545 all CUs needed for references have been loaded yet, and symbol
17546 table processing isn't initialized. But we have to set the CU language,
17547 or we won't be able to build types correctly.
17548 Similarly, if we do not read the producer, we can not apply
17549 producer-specific interpretation. */
17550 prepare_one_comp_unit (cu, cu->dies, language_minimal);
17553 /* Read in a signatured type and build its CU and DIEs.
17554 If the type is a stub for the real type in a DWO file,
17555 read in the real type from the DWO file as well. */
17558 read_signatured_type (struct signatured_type *sig_type)
17560 struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu;
17562 gdb_assert (per_cu->is_debug_types);
17563 gdb_assert (per_cu->cu == NULL);
17565 init_cutu_and_read_dies (per_cu, NULL, 0, 1,
17566 read_signatured_type_reader, NULL);
17569 /* Decode simple location descriptions.
17570 Given a pointer to a dwarf block that defines a location, compute
17571 the location and return the value.
17573 NOTE drow/2003-11-18: This function is called in two situations
17574 now: for the address of static or global variables (partial symbols
17575 only) and for offsets into structures which are expected to be
17576 (more or less) constant. The partial symbol case should go away,
17577 and only the constant case should remain. That will let this
17578 function complain more accurately. A few special modes are allowed
17579 without complaint for global variables (for instance, global
17580 register values and thread-local values).
17582 A location description containing no operations indicates that the
17583 object is optimized out. The return value is 0 for that case.
17584 FIXME drow/2003-11-16: No callers check for this case any more; soon all
17585 callers will only want a very basic result and this can become a
17588 Note that stack[0] is unused except as a default error return. */
17591 decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
17593 struct objfile *objfile = cu->objfile;
17595 size_t size = blk->size;
17596 gdb_byte *data = blk->data;
17597 CORE_ADDR stack[64];
17599 unsigned int bytes_read, unsnd;
17605 stack[++stacki] = 0;
17644 stack[++stacki] = op - DW_OP_lit0;
17679 stack[++stacki] = op - DW_OP_reg0;
17681 dwarf2_complex_location_expr_complaint ();
17685 unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read);
17687 stack[++stacki] = unsnd;
17689 dwarf2_complex_location_expr_complaint ();
17693 stack[++stacki] = read_address (objfile->obfd, &data[i],
17698 case DW_OP_const1u:
17699 stack[++stacki] = read_1_byte (objfile->obfd, &data[i]);
17703 case DW_OP_const1s:
17704 stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]);
17708 case DW_OP_const2u:
17709 stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]);
17713 case DW_OP_const2s:
17714 stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]);
17718 case DW_OP_const4u:
17719 stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]);
17723 case DW_OP_const4s:
17724 stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]);
17728 case DW_OP_const8u:
17729 stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]);
17734 stack[++stacki] = read_unsigned_leb128 (NULL, (data + i),
17740 stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read);
17745 stack[stacki + 1] = stack[stacki];
17750 stack[stacki - 1] += stack[stacki];
17754 case DW_OP_plus_uconst:
17755 stack[stacki] += read_unsigned_leb128 (NULL, (data + i),
17761 stack[stacki - 1] -= stack[stacki];
17766 /* If we're not the last op, then we definitely can't encode
17767 this using GDB's address_class enum. This is valid for partial
17768 global symbols, although the variable's address will be bogus
17771 dwarf2_complex_location_expr_complaint ();
17774 case DW_OP_GNU_push_tls_address:
17775 /* The top of the stack has the offset from the beginning
17776 of the thread control block at which the variable is located. */
17777 /* Nothing should follow this operator, so the top of stack would
17779 /* This is valid for partial global symbols, but the variable's
17780 address will be bogus in the psymtab. Make it always at least
17781 non-zero to not look as a variable garbage collected by linker
17782 which have DW_OP_addr 0. */
17784 dwarf2_complex_location_expr_complaint ();
17788 case DW_OP_GNU_uninit:
17791 case DW_OP_GNU_addr_index:
17792 case DW_OP_GNU_const_index:
17793 stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i],
17800 const char *name = get_DW_OP_name (op);
17803 complaint (&symfile_complaints, _("unsupported stack op: '%s'"),
17806 complaint (&symfile_complaints, _("unsupported stack op: '%02x'"),
17810 return (stack[stacki]);
17813 /* Enforce maximum stack depth of SIZE-1 to avoid writing
17814 outside of the allocated space. Also enforce minimum>0. */
17815 if (stacki >= ARRAY_SIZE (stack) - 1)
17817 complaint (&symfile_complaints,
17818 _("location description stack overflow"));
17824 complaint (&symfile_complaints,
17825 _("location description stack underflow"));
17829 return (stack[stacki]);
17832 /* memory allocation interface */
17834 static struct dwarf_block *
17835 dwarf_alloc_block (struct dwarf2_cu *cu)
17837 struct dwarf_block *blk;
17839 blk = (struct dwarf_block *)
17840 obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block));
17844 static struct die_info *
17845 dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
17847 struct die_info *die;
17848 size_t size = sizeof (struct die_info);
17851 size += (num_attrs - 1) * sizeof (struct attribute);
17853 die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size);
17854 memset (die, 0, sizeof (struct die_info));
17859 /* Macro support. */
17861 /* Return the full name of file number I in *LH's file name table.
17862 Use COMP_DIR as the name of the current directory of the
17863 compilation. The result is allocated using xmalloc; the caller is
17864 responsible for freeing it. */
17866 file_full_name (int file, struct line_header *lh, const char *comp_dir)
17868 /* Is the file number a valid index into the line header's file name
17869 table? Remember that file numbers start with one, not zero. */
17870 if (1 <= file && file <= lh->num_file_names)
17872 struct file_entry *fe = &lh->file_names[file - 1];
17874 if (IS_ABSOLUTE_PATH (fe->name))
17875 return xstrdup (fe->name);
17883 dir = lh->include_dirs[fe->dir_index - 1];
17889 dir_len = strlen (dir);
17890 full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
17891 strcpy (full_name, dir);
17892 full_name[dir_len] = '/';
17893 strcpy (full_name + dir_len + 1, fe->name);
17897 return xstrdup (fe->name);
17902 /* The compiler produced a bogus file number. We can at least
17903 record the macro definitions made in the file, even if we
17904 won't be able to find the file by name. */
17905 char fake_name[80];
17907 xsnprintf (fake_name, sizeof (fake_name),
17908 "<bad macro file number %d>", file);
17910 complaint (&symfile_complaints,
17911 _("bad file number in macro information (%d)"),
17914 return xstrdup (fake_name);
17919 static struct macro_source_file *
17920 macro_start_file (int file, int line,
17921 struct macro_source_file *current_file,
17922 const char *comp_dir,
17923 struct line_header *lh, struct objfile *objfile)
17925 /* The full name of this source file. */
17926 char *full_name = file_full_name (file, lh, comp_dir);
17928 /* We don't create a macro table for this compilation unit
17929 at all until we actually get a filename. */
17930 if (! pending_macros)
17931 pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
17932 objfile->per_bfd->macro_cache);
17934 if (! current_file)
17936 /* If we have no current file, then this must be the start_file
17937 directive for the compilation unit's main source file. */
17938 current_file = macro_set_main (pending_macros, full_name);
17939 macro_define_special (pending_macros);
17942 current_file = macro_include (current_file, line, full_name);
17946 return current_file;
17950 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
17951 followed by a null byte. */
17953 copy_string (const char *buf, int len)
17955 char *s = xmalloc (len + 1);
17957 memcpy (s, buf, len);
17963 static const char *
17964 consume_improper_spaces (const char *p, const char *body)
17968 complaint (&symfile_complaints,
17969 _("macro definition contains spaces "
17970 "in formal argument list:\n`%s'"),
17982 parse_macro_definition (struct macro_source_file *file, int line,
17987 /* The body string takes one of two forms. For object-like macro
17988 definitions, it should be:
17990 <macro name> " " <definition>
17992 For function-like macro definitions, it should be:
17994 <macro name> "() " <definition>
17996 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
17998 Spaces may appear only where explicitly indicated, and in the
18001 The Dwarf 2 spec says that an object-like macro's name is always
18002 followed by a space, but versions of GCC around March 2002 omit
18003 the space when the macro's definition is the empty string.
18005 The Dwarf 2 spec says that there should be no spaces between the
18006 formal arguments in a function-like macro's formal argument list,
18007 but versions of GCC around March 2002 include spaces after the
18011 /* Find the extent of the macro name. The macro name is terminated
18012 by either a space or null character (for an object-like macro) or
18013 an opening paren (for a function-like macro). */
18014 for (p = body; *p; p++)
18015 if (*p == ' ' || *p == '(')
18018 if (*p == ' ' || *p == '\0')
18020 /* It's an object-like macro. */
18021 int name_len = p - body;
18022 char *name = copy_string (body, name_len);
18023 const char *replacement;
18026 replacement = body + name_len + 1;
18029 dwarf2_macro_malformed_definition_complaint (body);
18030 replacement = body + name_len;
18033 macro_define_object (file, line, name, replacement);
18037 else if (*p == '(')
18039 /* It's a function-like macro. */
18040 char *name = copy_string (body, p - body);
18043 char **argv = xmalloc (argv_size * sizeof (*argv));
18047 p = consume_improper_spaces (p, body);
18049 /* Parse the formal argument list. */
18050 while (*p && *p != ')')
18052 /* Find the extent of the current argument name. */
18053 const char *arg_start = p;
18055 while (*p && *p != ',' && *p != ')' && *p != ' ')
18058 if (! *p || p == arg_start)
18059 dwarf2_macro_malformed_definition_complaint (body);
18062 /* Make sure argv has room for the new argument. */
18063 if (argc >= argv_size)
18066 argv = xrealloc (argv, argv_size * sizeof (*argv));
18069 argv[argc++] = copy_string (arg_start, p - arg_start);
18072 p = consume_improper_spaces (p, body);
18074 /* Consume the comma, if present. */
18079 p = consume_improper_spaces (p, body);
18088 /* Perfectly formed definition, no complaints. */
18089 macro_define_function (file, line, name,
18090 argc, (const char **) argv,
18092 else if (*p == '\0')
18094 /* Complain, but do define it. */
18095 dwarf2_macro_malformed_definition_complaint (body);
18096 macro_define_function (file, line, name,
18097 argc, (const char **) argv,
18101 /* Just complain. */
18102 dwarf2_macro_malformed_definition_complaint (body);
18105 /* Just complain. */
18106 dwarf2_macro_malformed_definition_complaint (body);
18112 for (i = 0; i < argc; i++)
18118 dwarf2_macro_malformed_definition_complaint (body);
18121 /* Skip some bytes from BYTES according to the form given in FORM.
18122 Returns the new pointer. */
18125 skip_form_bytes (bfd *abfd, gdb_byte *bytes, gdb_byte *buffer_end,
18126 enum dwarf_form form,
18127 unsigned int offset_size,
18128 struct dwarf2_section_info *section)
18130 unsigned int bytes_read;
18134 case DW_FORM_data1:
18139 case DW_FORM_data2:
18143 case DW_FORM_data4:
18147 case DW_FORM_data8:
18151 case DW_FORM_string:
18152 read_direct_string (abfd, bytes, &bytes_read);
18153 bytes += bytes_read;
18156 case DW_FORM_sec_offset:
18158 case DW_FORM_GNU_strp_alt:
18159 bytes += offset_size;
18162 case DW_FORM_block:
18163 bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read);
18164 bytes += bytes_read;
18167 case DW_FORM_block1:
18168 bytes += 1 + read_1_byte (abfd, bytes);
18170 case DW_FORM_block2:
18171 bytes += 2 + read_2_bytes (abfd, bytes);
18173 case DW_FORM_block4:
18174 bytes += 4 + read_4_bytes (abfd, bytes);
18177 case DW_FORM_sdata:
18178 case DW_FORM_udata:
18179 case DW_FORM_GNU_addr_index:
18180 case DW_FORM_GNU_str_index:
18181 bytes = (gdb_byte *) gdb_skip_leb128 (bytes, buffer_end);
18184 dwarf2_section_buffer_overflow_complaint (section);
18192 complaint (&symfile_complaints,
18193 _("invalid form 0x%x in `%s'"),
18195 section->asection->name);
18203 /* A helper for dwarf_decode_macros that handles skipping an unknown
18204 opcode. Returns an updated pointer to the macro data buffer; or,
18205 on error, issues a complaint and returns NULL. */
18208 skip_unknown_opcode (unsigned int opcode,
18209 gdb_byte **opcode_definitions,
18210 gdb_byte *mac_ptr, gdb_byte *mac_end,
18212 unsigned int offset_size,
18213 struct dwarf2_section_info *section)
18215 unsigned int bytes_read, i;
18219 if (opcode_definitions[opcode] == NULL)
18221 complaint (&symfile_complaints,
18222 _("unrecognized DW_MACFINO opcode 0x%x"),
18227 defn = opcode_definitions[opcode];
18228 arg = read_unsigned_leb128 (abfd, defn, &bytes_read);
18229 defn += bytes_read;
18231 for (i = 0; i < arg; ++i)
18233 mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, defn[i], offset_size,
18235 if (mac_ptr == NULL)
18237 /* skip_form_bytes already issued the complaint. */
18245 /* A helper function which parses the header of a macro section.
18246 If the macro section is the extended (for now called "GNU") type,
18247 then this updates *OFFSET_SIZE. Returns a pointer to just after
18248 the header, or issues a complaint and returns NULL on error. */
18251 dwarf_parse_macro_header (gdb_byte **opcode_definitions,
18254 unsigned int *offset_size,
18255 int section_is_gnu)
18257 memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *));
18259 if (section_is_gnu)
18261 unsigned int version, flags;
18263 version = read_2_bytes (abfd, mac_ptr);
18266 complaint (&symfile_complaints,
18267 _("unrecognized version `%d' in .debug_macro section"),
18273 flags = read_1_byte (abfd, mac_ptr);
18275 *offset_size = (flags & 1) ? 8 : 4;
18277 if ((flags & 2) != 0)
18278 /* We don't need the line table offset. */
18279 mac_ptr += *offset_size;
18281 /* Vendor opcode descriptions. */
18282 if ((flags & 4) != 0)
18284 unsigned int i, count;
18286 count = read_1_byte (abfd, mac_ptr);
18288 for (i = 0; i < count; ++i)
18290 unsigned int opcode, bytes_read;
18293 opcode = read_1_byte (abfd, mac_ptr);
18295 opcode_definitions[opcode] = mac_ptr;
18296 arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18297 mac_ptr += bytes_read;
18306 /* A helper for dwarf_decode_macros that handles the GNU extensions,
18307 including DW_MACRO_GNU_transparent_include. */
18310 dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end,
18311 struct macro_source_file *current_file,
18312 struct line_header *lh, char *comp_dir,
18313 struct dwarf2_section_info *section,
18314 int section_is_gnu, int section_is_dwz,
18315 unsigned int offset_size,
18316 struct objfile *objfile,
18317 htab_t include_hash)
18319 enum dwarf_macro_record_type macinfo_type;
18320 int at_commandline;
18321 gdb_byte *opcode_definitions[256];
18323 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
18324 &offset_size, section_is_gnu);
18325 if (mac_ptr == NULL)
18327 /* We already issued a complaint. */
18331 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
18332 GDB is still reading the definitions from command line. First
18333 DW_MACINFO_start_file will need to be ignored as it was already executed
18334 to create CURRENT_FILE for the main source holding also the command line
18335 definitions. On first met DW_MACINFO_start_file this flag is reset to
18336 normally execute all the remaining DW_MACINFO_start_file macinfos. */
18338 at_commandline = 1;
18342 /* Do we at least have room for a macinfo type byte? */
18343 if (mac_ptr >= mac_end)
18345 dwarf2_section_buffer_overflow_complaint (section);
18349 macinfo_type = read_1_byte (abfd, mac_ptr);
18352 /* Note that we rely on the fact that the corresponding GNU and
18353 DWARF constants are the same. */
18354 switch (macinfo_type)
18356 /* A zero macinfo type indicates the end of the macro
18361 case DW_MACRO_GNU_define:
18362 case DW_MACRO_GNU_undef:
18363 case DW_MACRO_GNU_define_indirect:
18364 case DW_MACRO_GNU_undef_indirect:
18365 case DW_MACRO_GNU_define_indirect_alt:
18366 case DW_MACRO_GNU_undef_indirect_alt:
18368 unsigned int bytes_read;
18373 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18374 mac_ptr += bytes_read;
18376 if (macinfo_type == DW_MACRO_GNU_define
18377 || macinfo_type == DW_MACRO_GNU_undef)
18379 body = read_direct_string (abfd, mac_ptr, &bytes_read);
18380 mac_ptr += bytes_read;
18384 LONGEST str_offset;
18386 str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
18387 mac_ptr += offset_size;
18389 if (macinfo_type == DW_MACRO_GNU_define_indirect_alt
18390 || macinfo_type == DW_MACRO_GNU_undef_indirect_alt
18393 struct dwz_file *dwz = dwarf2_get_dwz_file ();
18395 body = read_indirect_string_from_dwz (dwz, str_offset);
18398 body = read_indirect_string_at_offset (abfd, str_offset);
18401 is_define = (macinfo_type == DW_MACRO_GNU_define
18402 || macinfo_type == DW_MACRO_GNU_define_indirect
18403 || macinfo_type == DW_MACRO_GNU_define_indirect_alt);
18404 if (! current_file)
18406 /* DWARF violation as no main source is present. */
18407 complaint (&symfile_complaints,
18408 _("debug info with no main source gives macro %s "
18410 is_define ? _("definition") : _("undefinition"),
18414 if ((line == 0 && !at_commandline)
18415 || (line != 0 && at_commandline))
18416 complaint (&symfile_complaints,
18417 _("debug info gives %s macro %s with %s line %d: %s"),
18418 at_commandline ? _("command-line") : _("in-file"),
18419 is_define ? _("definition") : _("undefinition"),
18420 line == 0 ? _("zero") : _("non-zero"), line, body);
18423 parse_macro_definition (current_file, line, body);
18426 gdb_assert (macinfo_type == DW_MACRO_GNU_undef
18427 || macinfo_type == DW_MACRO_GNU_undef_indirect
18428 || macinfo_type == DW_MACRO_GNU_undef_indirect_alt);
18429 macro_undef (current_file, line, body);
18434 case DW_MACRO_GNU_start_file:
18436 unsigned int bytes_read;
18439 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18440 mac_ptr += bytes_read;
18441 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18442 mac_ptr += bytes_read;
18444 if ((line == 0 && !at_commandline)
18445 || (line != 0 && at_commandline))
18446 complaint (&symfile_complaints,
18447 _("debug info gives source %d included "
18448 "from %s at %s line %d"),
18449 file, at_commandline ? _("command-line") : _("file"),
18450 line == 0 ? _("zero") : _("non-zero"), line);
18452 if (at_commandline)
18454 /* This DW_MACRO_GNU_start_file was executed in the
18456 at_commandline = 0;
18459 current_file = macro_start_file (file, line,
18460 current_file, comp_dir,
18465 case DW_MACRO_GNU_end_file:
18466 if (! current_file)
18467 complaint (&symfile_complaints,
18468 _("macro debug info has an unmatched "
18469 "`close_file' directive"));
18472 current_file = current_file->included_by;
18473 if (! current_file)
18475 enum dwarf_macro_record_type next_type;
18477 /* GCC circa March 2002 doesn't produce the zero
18478 type byte marking the end of the compilation
18479 unit. Complain if it's not there, but exit no
18482 /* Do we at least have room for a macinfo type byte? */
18483 if (mac_ptr >= mac_end)
18485 dwarf2_section_buffer_overflow_complaint (section);
18489 /* We don't increment mac_ptr here, so this is just
18491 next_type = read_1_byte (abfd, mac_ptr);
18492 if (next_type != 0)
18493 complaint (&symfile_complaints,
18494 _("no terminating 0-type entry for "
18495 "macros in `.debug_macinfo' section"));
18502 case DW_MACRO_GNU_transparent_include:
18503 case DW_MACRO_GNU_transparent_include_alt:
18507 bfd *include_bfd = abfd;
18508 struct dwarf2_section_info *include_section = section;
18509 struct dwarf2_section_info alt_section;
18510 gdb_byte *include_mac_end = mac_end;
18511 int is_dwz = section_is_dwz;
18512 gdb_byte *new_mac_ptr;
18514 offset = read_offset_1 (abfd, mac_ptr, offset_size);
18515 mac_ptr += offset_size;
18517 if (macinfo_type == DW_MACRO_GNU_transparent_include_alt)
18519 struct dwz_file *dwz = dwarf2_get_dwz_file ();
18521 dwarf2_read_section (dwarf2_per_objfile->objfile,
18524 include_bfd = dwz->macro.asection->owner;
18525 include_section = &dwz->macro;
18526 include_mac_end = dwz->macro.buffer + dwz->macro.size;
18530 new_mac_ptr = include_section->buffer + offset;
18531 slot = htab_find_slot (include_hash, new_mac_ptr, INSERT);
18535 /* This has actually happened; see
18536 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
18537 complaint (&symfile_complaints,
18538 _("recursive DW_MACRO_GNU_transparent_include in "
18539 ".debug_macro section"));
18543 *slot = new_mac_ptr;
18545 dwarf_decode_macro_bytes (include_bfd, new_mac_ptr,
18546 include_mac_end, current_file,
18548 section, section_is_gnu, is_dwz,
18549 offset_size, objfile, include_hash);
18551 htab_remove_elt (include_hash, new_mac_ptr);
18556 case DW_MACINFO_vendor_ext:
18557 if (!section_is_gnu)
18559 unsigned int bytes_read;
18562 constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18563 mac_ptr += bytes_read;
18564 read_direct_string (abfd, mac_ptr, &bytes_read);
18565 mac_ptr += bytes_read;
18567 /* We don't recognize any vendor extensions. */
18573 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
18574 mac_ptr, mac_end, abfd, offset_size,
18576 if (mac_ptr == NULL)
18580 } while (macinfo_type != 0);
18584 dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
18585 char *comp_dir, int section_is_gnu)
18587 struct objfile *objfile = dwarf2_per_objfile->objfile;
18588 struct line_header *lh = cu->line_header;
18590 gdb_byte *mac_ptr, *mac_end;
18591 struct macro_source_file *current_file = 0;
18592 enum dwarf_macro_record_type macinfo_type;
18593 unsigned int offset_size = cu->header.offset_size;
18594 gdb_byte *opcode_definitions[256];
18595 struct cleanup *cleanup;
18596 htab_t include_hash;
18598 struct dwarf2_section_info *section;
18599 const char *section_name;
18601 if (cu->dwo_unit != NULL)
18603 if (section_is_gnu)
18605 section = &cu->dwo_unit->dwo_file->sections.macro;
18606 section_name = ".debug_macro.dwo";
18610 section = &cu->dwo_unit->dwo_file->sections.macinfo;
18611 section_name = ".debug_macinfo.dwo";
18616 if (section_is_gnu)
18618 section = &dwarf2_per_objfile->macro;
18619 section_name = ".debug_macro";
18623 section = &dwarf2_per_objfile->macinfo;
18624 section_name = ".debug_macinfo";
18628 dwarf2_read_section (objfile, section);
18629 if (section->buffer == NULL)
18631 complaint (&symfile_complaints, _("missing %s section"), section_name);
18634 abfd = section->asection->owner;
18636 /* First pass: Find the name of the base filename.
18637 This filename is needed in order to process all macros whose definition
18638 (or undefinition) comes from the command line. These macros are defined
18639 before the first DW_MACINFO_start_file entry, and yet still need to be
18640 associated to the base file.
18642 To determine the base file name, we scan the macro definitions until we
18643 reach the first DW_MACINFO_start_file entry. We then initialize
18644 CURRENT_FILE accordingly so that any macro definition found before the
18645 first DW_MACINFO_start_file can still be associated to the base file. */
18647 mac_ptr = section->buffer + offset;
18648 mac_end = section->buffer + section->size;
18650 mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr,
18651 &offset_size, section_is_gnu);
18652 if (mac_ptr == NULL)
18654 /* We already issued a complaint. */
18660 /* Do we at least have room for a macinfo type byte? */
18661 if (mac_ptr >= mac_end)
18663 /* Complaint is printed during the second pass as GDB will probably
18664 stop the first pass earlier upon finding
18665 DW_MACINFO_start_file. */
18669 macinfo_type = read_1_byte (abfd, mac_ptr);
18672 /* Note that we rely on the fact that the corresponding GNU and
18673 DWARF constants are the same. */
18674 switch (macinfo_type)
18676 /* A zero macinfo type indicates the end of the macro
18681 case DW_MACRO_GNU_define:
18682 case DW_MACRO_GNU_undef:
18683 /* Only skip the data by MAC_PTR. */
18685 unsigned int bytes_read;
18687 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18688 mac_ptr += bytes_read;
18689 read_direct_string (abfd, mac_ptr, &bytes_read);
18690 mac_ptr += bytes_read;
18694 case DW_MACRO_GNU_start_file:
18696 unsigned int bytes_read;
18699 line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18700 mac_ptr += bytes_read;
18701 file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18702 mac_ptr += bytes_read;
18704 current_file = macro_start_file (file, line, current_file,
18705 comp_dir, lh, objfile);
18709 case DW_MACRO_GNU_end_file:
18710 /* No data to skip by MAC_PTR. */
18713 case DW_MACRO_GNU_define_indirect:
18714 case DW_MACRO_GNU_undef_indirect:
18715 case DW_MACRO_GNU_define_indirect_alt:
18716 case DW_MACRO_GNU_undef_indirect_alt:
18718 unsigned int bytes_read;
18720 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18721 mac_ptr += bytes_read;
18722 mac_ptr += offset_size;
18726 case DW_MACRO_GNU_transparent_include:
18727 case DW_MACRO_GNU_transparent_include_alt:
18728 /* Note that, according to the spec, a transparent include
18729 chain cannot call DW_MACRO_GNU_start_file. So, we can just
18730 skip this opcode. */
18731 mac_ptr += offset_size;
18734 case DW_MACINFO_vendor_ext:
18735 /* Only skip the data by MAC_PTR. */
18736 if (!section_is_gnu)
18738 unsigned int bytes_read;
18740 read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
18741 mac_ptr += bytes_read;
18742 read_direct_string (abfd, mac_ptr, &bytes_read);
18743 mac_ptr += bytes_read;
18748 mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions,
18749 mac_ptr, mac_end, abfd, offset_size,
18751 if (mac_ptr == NULL)
18755 } while (macinfo_type != 0 && current_file == NULL);
18757 /* Second pass: Process all entries.
18759 Use the AT_COMMAND_LINE flag to determine whether we are still processing
18760 command-line macro definitions/undefinitions. This flag is unset when we
18761 reach the first DW_MACINFO_start_file entry. */
18763 include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
18764 NULL, xcalloc, xfree);
18765 cleanup = make_cleanup_htab_delete (include_hash);
18766 mac_ptr = section->buffer + offset;
18767 slot = htab_find_slot (include_hash, mac_ptr, INSERT);
18769 dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
18770 current_file, lh, comp_dir, section,
18772 offset_size, objfile, include_hash);
18773 do_cleanups (cleanup);
18776 /* Check if the attribute's form is a DW_FORM_block*
18777 if so return true else false. */
18780 attr_form_is_block (struct attribute *attr)
18782 return (attr == NULL ? 0 :
18783 attr->form == DW_FORM_block1
18784 || attr->form == DW_FORM_block2
18785 || attr->form == DW_FORM_block4
18786 || attr->form == DW_FORM_block
18787 || attr->form == DW_FORM_exprloc);
18790 /* Return non-zero if ATTR's value is a section offset --- classes
18791 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
18792 You may use DW_UNSND (attr) to retrieve such offsets.
18794 Section 7.5.4, "Attribute Encodings", explains that no attribute
18795 may have a value that belongs to more than one of these classes; it
18796 would be ambiguous if we did, because we use the same forms for all
18800 attr_form_is_section_offset (struct attribute *attr)
18802 return (attr->form == DW_FORM_data4
18803 || attr->form == DW_FORM_data8
18804 || attr->form == DW_FORM_sec_offset);
18807 /* Return non-zero if ATTR's value falls in the 'constant' class, or
18808 zero otherwise. When this function returns true, you can apply
18809 dwarf2_get_attr_constant_value to it.
18811 However, note that for some attributes you must check
18812 attr_form_is_section_offset before using this test. DW_FORM_data4
18813 and DW_FORM_data8 are members of both the constant class, and of
18814 the classes that contain offsets into other debug sections
18815 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
18816 that, if an attribute's can be either a constant or one of the
18817 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
18818 taken as section offsets, not constants. */
18821 attr_form_is_constant (struct attribute *attr)
18823 switch (attr->form)
18825 case DW_FORM_sdata:
18826 case DW_FORM_udata:
18827 case DW_FORM_data1:
18828 case DW_FORM_data2:
18829 case DW_FORM_data4:
18830 case DW_FORM_data8:
18837 /* Return the .debug_loc section to use for CU.
18838 For DWO files use .debug_loc.dwo. */
18840 static struct dwarf2_section_info *
18841 cu_debug_loc_section (struct dwarf2_cu *cu)
18844 return &cu->dwo_unit->dwo_file->sections.loc;
18845 return &dwarf2_per_objfile->loc;
18848 /* A helper function that fills in a dwarf2_loclist_baton. */
18851 fill_in_loclist_baton (struct dwarf2_cu *cu,
18852 struct dwarf2_loclist_baton *baton,
18853 struct attribute *attr)
18855 struct dwarf2_section_info *section = cu_debug_loc_section (cu);
18857 dwarf2_read_section (dwarf2_per_objfile->objfile, section);
18859 baton->per_cu = cu->per_cu;
18860 gdb_assert (baton->per_cu);
18861 /* We don't know how long the location list is, but make sure we
18862 don't run off the edge of the section. */
18863 baton->size = section->size - DW_UNSND (attr);
18864 baton->data = section->buffer + DW_UNSND (attr);
18865 baton->base_address = cu->base_address;
18866 baton->from_dwo = cu->dwo_unit != NULL;
18870 dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
18871 struct dwarf2_cu *cu)
18873 struct objfile *objfile = dwarf2_per_objfile->objfile;
18874 struct dwarf2_section_info *section = cu_debug_loc_section (cu);
18876 if (attr_form_is_section_offset (attr)
18877 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
18878 the section. If so, fall through to the complaint in the
18880 && DW_UNSND (attr) < dwarf2_section_size (objfile, section))
18882 struct dwarf2_loclist_baton *baton;
18884 baton = obstack_alloc (&objfile->objfile_obstack,
18885 sizeof (struct dwarf2_loclist_baton));
18887 fill_in_loclist_baton (cu, baton, attr);
18889 if (cu->base_known == 0)
18890 complaint (&symfile_complaints,
18891 _("Location list used without "
18892 "specifying the CU base address."));
18894 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
18895 SYMBOL_LOCATION_BATON (sym) = baton;
18899 struct dwarf2_locexpr_baton *baton;
18901 baton = obstack_alloc (&objfile->objfile_obstack,
18902 sizeof (struct dwarf2_locexpr_baton));
18903 baton->per_cu = cu->per_cu;
18904 gdb_assert (baton->per_cu);
18906 if (attr_form_is_block (attr))
18908 /* Note that we're just copying the block's data pointer
18909 here, not the actual data. We're still pointing into the
18910 info_buffer for SYM's objfile; right now we never release
18911 that buffer, but when we do clean up properly this may
18913 baton->size = DW_BLOCK (attr)->size;
18914 baton->data = DW_BLOCK (attr)->data;
18918 dwarf2_invalid_attrib_class_complaint ("location description",
18919 SYMBOL_NATURAL_NAME (sym));
18923 SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
18924 SYMBOL_LOCATION_BATON (sym) = baton;
18928 /* Return the OBJFILE associated with the compilation unit CU. If CU
18929 came from a separate debuginfo file, then the master objfile is
18933 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
18935 struct objfile *objfile = per_cu->objfile;
18937 /* Return the master objfile, so that we can report and look up the
18938 correct file containing this variable. */
18939 if (objfile->separate_debug_objfile_backlink)
18940 objfile = objfile->separate_debug_objfile_backlink;
18945 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
18946 (CU_HEADERP is unused in such case) or prepare a temporary copy at
18947 CU_HEADERP first. */
18949 static const struct comp_unit_head *
18950 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
18951 struct dwarf2_per_cu_data *per_cu)
18953 gdb_byte *info_ptr;
18956 return &per_cu->cu->header;
18958 info_ptr = per_cu->info_or_types_section->buffer + per_cu->offset.sect_off;
18960 memset (cu_headerp, 0, sizeof (*cu_headerp));
18961 read_comp_unit_head (cu_headerp, info_ptr, per_cu->objfile->obfd);
18966 /* Return the address size given in the compilation unit header for CU. */
18969 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
18971 struct comp_unit_head cu_header_local;
18972 const struct comp_unit_head *cu_headerp;
18974 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
18976 return cu_headerp->addr_size;
18979 /* Return the offset size given in the compilation unit header for CU. */
18982 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
18984 struct comp_unit_head cu_header_local;
18985 const struct comp_unit_head *cu_headerp;
18987 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
18989 return cu_headerp->offset_size;
18992 /* See its dwarf2loc.h declaration. */
18995 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
18997 struct comp_unit_head cu_header_local;
18998 const struct comp_unit_head *cu_headerp;
19000 cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
19002 if (cu_headerp->version == 2)
19003 return cu_headerp->addr_size;
19005 return cu_headerp->offset_size;
19008 /* Return the text offset of the CU. The returned offset comes from
19009 this CU's objfile. If this objfile came from a separate debuginfo
19010 file, then the offset may be different from the corresponding
19011 offset in the parent objfile. */
19014 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
19016 struct objfile *objfile = per_cu->objfile;
19018 return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
19021 /* Locate the .debug_info compilation unit from CU's objfile which contains
19022 the DIE at OFFSET. Raises an error on failure. */
19024 static struct dwarf2_per_cu_data *
19025 dwarf2_find_containing_comp_unit (sect_offset offset,
19026 unsigned int offset_in_dwz,
19027 struct objfile *objfile)
19029 struct dwarf2_per_cu_data *this_cu;
19031 const sect_offset *cu_off;
19034 high = dwarf2_per_objfile->n_comp_units - 1;
19037 struct dwarf2_per_cu_data *mid_cu;
19038 int mid = low + (high - low) / 2;
19040 mid_cu = dwarf2_per_objfile->all_comp_units[mid];
19041 cu_off = &mid_cu->offset;
19042 if (mid_cu->is_dwz > offset_in_dwz
19043 || (mid_cu->is_dwz == offset_in_dwz
19044 && cu_off->sect_off >= offset.sect_off))
19049 gdb_assert (low == high);
19050 this_cu = dwarf2_per_objfile->all_comp_units[low];
19051 cu_off = &this_cu->offset;
19052 if (this_cu->is_dwz != offset_in_dwz || cu_off->sect_off > offset.sect_off)
19054 if (low == 0 || this_cu->is_dwz != offset_in_dwz)
19055 error (_("Dwarf Error: could not find partial DIE containing "
19056 "offset 0x%lx [in module %s]"),
19057 (long) offset.sect_off, bfd_get_filename (objfile->obfd));
19059 gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset.sect_off
19060 <= offset.sect_off);
19061 return dwarf2_per_objfile->all_comp_units[low-1];
19065 this_cu = dwarf2_per_objfile->all_comp_units[low];
19066 if (low == dwarf2_per_objfile->n_comp_units - 1
19067 && offset.sect_off >= this_cu->offset.sect_off + this_cu->length)
19068 error (_("invalid dwarf2 offset %u"), offset.sect_off);
19069 gdb_assert (offset.sect_off < this_cu->offset.sect_off + this_cu->length);
19074 /* Initialize dwarf2_cu CU, owned by PER_CU. */
19077 init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu)
19079 memset (cu, 0, sizeof (*cu));
19081 cu->per_cu = per_cu;
19082 cu->objfile = per_cu->objfile;
19083 obstack_init (&cu->comp_unit_obstack);
19086 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
19089 prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
19090 enum language pretend_language)
19092 struct attribute *attr;
19094 /* Set the language we're debugging. */
19095 attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
19097 set_cu_language (DW_UNSND (attr), cu);
19100 cu->language = pretend_language;
19101 cu->language_defn = language_def (cu->language);
19104 attr = dwarf2_attr (comp_unit_die, DW_AT_producer, cu);
19106 cu->producer = DW_STRING (attr);
19109 /* Release one cached compilation unit, CU. We unlink it from the tree
19110 of compilation units, but we don't remove it from the read_in_chain;
19111 the caller is responsible for that.
19112 NOTE: DATA is a void * because this function is also used as a
19113 cleanup routine. */
19116 free_heap_comp_unit (void *data)
19118 struct dwarf2_cu *cu = data;
19120 gdb_assert (cu->per_cu != NULL);
19121 cu->per_cu->cu = NULL;
19124 obstack_free (&cu->comp_unit_obstack, NULL);
19129 /* This cleanup function is passed the address of a dwarf2_cu on the stack
19130 when we're finished with it. We can't free the pointer itself, but be
19131 sure to unlink it from the cache. Also release any associated storage. */
19134 free_stack_comp_unit (void *data)
19136 struct dwarf2_cu *cu = data;
19138 gdb_assert (cu->per_cu != NULL);
19139 cu->per_cu->cu = NULL;
19142 obstack_free (&cu->comp_unit_obstack, NULL);
19143 cu->partial_dies = NULL;
19146 /* Free all cached compilation units. */
19149 free_cached_comp_units (void *data)
19151 struct dwarf2_per_cu_data *per_cu, **last_chain;
19153 per_cu = dwarf2_per_objfile->read_in_chain;
19154 last_chain = &dwarf2_per_objfile->read_in_chain;
19155 while (per_cu != NULL)
19157 struct dwarf2_per_cu_data *next_cu;
19159 next_cu = per_cu->cu->read_in_chain;
19161 free_heap_comp_unit (per_cu->cu);
19162 *last_chain = next_cu;
19168 /* Increase the age counter on each cached compilation unit, and free
19169 any that are too old. */
19172 age_cached_comp_units (void)
19174 struct dwarf2_per_cu_data *per_cu, **last_chain;
19176 dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain);
19177 per_cu = dwarf2_per_objfile->read_in_chain;
19178 while (per_cu != NULL)
19180 per_cu->cu->last_used ++;
19181 if (per_cu->cu->last_used <= dwarf2_max_cache_age)
19182 dwarf2_mark (per_cu->cu);
19183 per_cu = per_cu->cu->read_in_chain;
19186 per_cu = dwarf2_per_objfile->read_in_chain;
19187 last_chain = &dwarf2_per_objfile->read_in_chain;
19188 while (per_cu != NULL)
19190 struct dwarf2_per_cu_data *next_cu;
19192 next_cu = per_cu->cu->read_in_chain;
19194 if (!per_cu->cu->mark)
19196 free_heap_comp_unit (per_cu->cu);
19197 *last_chain = next_cu;
19200 last_chain = &per_cu->cu->read_in_chain;
19206 /* Remove a single compilation unit from the cache. */
19209 free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu)
19211 struct dwarf2_per_cu_data *per_cu, **last_chain;
19213 per_cu = dwarf2_per_objfile->read_in_chain;
19214 last_chain = &dwarf2_per_objfile->read_in_chain;
19215 while (per_cu != NULL)
19217 struct dwarf2_per_cu_data *next_cu;
19219 next_cu = per_cu->cu->read_in_chain;
19221 if (per_cu == target_per_cu)
19223 free_heap_comp_unit (per_cu->cu);
19225 *last_chain = next_cu;
19229 last_chain = &per_cu->cu->read_in_chain;
19235 /* Release all extra memory associated with OBJFILE. */
19238 dwarf2_free_objfile (struct objfile *objfile)
19240 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
19242 if (dwarf2_per_objfile == NULL)
19245 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
19246 free_cached_comp_units (NULL);
19248 if (dwarf2_per_objfile->quick_file_names_table)
19249 htab_delete (dwarf2_per_objfile->quick_file_names_table);
19251 /* Everything else should be on the objfile obstack. */
19254 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
19255 We store these in a hash table separate from the DIEs, and preserve them
19256 when the DIEs are flushed out of cache.
19258 The CU "per_cu" pointer is needed because offset alone is not enough to
19259 uniquely identify the type. A file may have multiple .debug_types sections,
19260 or the type may come from a DWO file. We have to use something in
19261 dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup
19262 routine, get_die_type_at_offset, from outside this file, and thus won't
19263 necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life
19266 struct dwarf2_per_cu_offset_and_type
19268 const struct dwarf2_per_cu_data *per_cu;
19269 sect_offset offset;
19273 /* Hash function for a dwarf2_per_cu_offset_and_type. */
19276 per_cu_offset_and_type_hash (const void *item)
19278 const struct dwarf2_per_cu_offset_and_type *ofs = item;
19280 return (uintptr_t) ofs->per_cu + ofs->offset.sect_off;
19283 /* Equality function for a dwarf2_per_cu_offset_and_type. */
19286 per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
19288 const struct dwarf2_per_cu_offset_and_type *ofs_lhs = item_lhs;
19289 const struct dwarf2_per_cu_offset_and_type *ofs_rhs = item_rhs;
19291 return (ofs_lhs->per_cu == ofs_rhs->per_cu
19292 && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off);
19295 /* Set the type associated with DIE to TYPE. Save it in CU's hash
19296 table if necessary. For convenience, return TYPE.
19298 The DIEs reading must have careful ordering to:
19299 * Not cause infite loops trying to read in DIEs as a prerequisite for
19300 reading current DIE.
19301 * Not trying to dereference contents of still incompletely read in types
19302 while reading in other DIEs.
19303 * Enable referencing still incompletely read in types just by a pointer to
19304 the type without accessing its fields.
19306 Therefore caller should follow these rules:
19307 * Try to fetch any prerequisite types we may need to build this DIE type
19308 before building the type and calling set_die_type.
19309 * After building type call set_die_type for current DIE as soon as
19310 possible before fetching more types to complete the current type.
19311 * Make the type as complete as possible before fetching more types. */
19313 static struct type *
19314 set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
19316 struct dwarf2_per_cu_offset_and_type **slot, ofs;
19317 struct objfile *objfile = cu->objfile;
19319 /* For Ada types, make sure that the gnat-specific data is always
19320 initialized (if not already set). There are a few types where
19321 we should not be doing so, because the type-specific area is
19322 already used to hold some other piece of info (eg: TYPE_CODE_FLT
19323 where the type-specific area is used to store the floatformat).
19324 But this is not a problem, because the gnat-specific information
19325 is actually not needed for these types. */
19326 if (need_gnat_info (cu)
19327 && TYPE_CODE (type) != TYPE_CODE_FUNC
19328 && TYPE_CODE (type) != TYPE_CODE_FLT
19329 && !HAVE_GNAT_AUX_INFO (type))
19330 INIT_GNAT_SPECIFIC (type);
19332 if (dwarf2_per_objfile->die_type_hash == NULL)
19334 dwarf2_per_objfile->die_type_hash =
19335 htab_create_alloc_ex (127,
19336 per_cu_offset_and_type_hash,
19337 per_cu_offset_and_type_eq,
19339 &objfile->objfile_obstack,
19340 hashtab_obstack_allocate,
19341 dummy_obstack_deallocate);
19344 ofs.per_cu = cu->per_cu;
19345 ofs.offset = die->offset;
19347 slot = (struct dwarf2_per_cu_offset_and_type **)
19348 htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT);
19350 complaint (&symfile_complaints,
19351 _("A problem internal to GDB: DIE 0x%x has type already set"),
19352 die->offset.sect_off);
19353 *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot));
19358 /* Look up the type for the die at OFFSET in the appropriate type_hash
19359 table, or return NULL if the die does not have a saved type. */
19361 static struct type *
19362 get_die_type_at_offset (sect_offset offset,
19363 struct dwarf2_per_cu_data *per_cu)
19365 struct dwarf2_per_cu_offset_and_type *slot, ofs;
19367 if (dwarf2_per_objfile->die_type_hash == NULL)
19370 ofs.per_cu = per_cu;
19371 ofs.offset = offset;
19372 slot = htab_find (dwarf2_per_objfile->die_type_hash, &ofs);
19379 /* Look up the type for DIE in the appropriate type_hash table,
19380 or return NULL if DIE does not have a saved type. */
19382 static struct type *
19383 get_die_type (struct die_info *die, struct dwarf2_cu *cu)
19385 return get_die_type_at_offset (die->offset, cu->per_cu);
19388 /* Add a dependence relationship from CU to REF_PER_CU. */
19391 dwarf2_add_dependence (struct dwarf2_cu *cu,
19392 struct dwarf2_per_cu_data *ref_per_cu)
19396 if (cu->dependencies == NULL)
19398 = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer,
19399 NULL, &cu->comp_unit_obstack,
19400 hashtab_obstack_allocate,
19401 dummy_obstack_deallocate);
19403 slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT);
19405 *slot = ref_per_cu;
19408 /* Subroutine of dwarf2_mark to pass to htab_traverse.
19409 Set the mark field in every compilation unit in the
19410 cache that we must keep because we are keeping CU. */
19413 dwarf2_mark_helper (void **slot, void *data)
19415 struct dwarf2_per_cu_data *per_cu;
19417 per_cu = (struct dwarf2_per_cu_data *) *slot;
19419 /* cu->dependencies references may not yet have been ever read if QUIT aborts
19420 reading of the chain. As such dependencies remain valid it is not much
19421 useful to track and undo them during QUIT cleanups. */
19422 if (per_cu->cu == NULL)
19425 if (per_cu->cu->mark)
19427 per_cu->cu->mark = 1;
19429 if (per_cu->cu->dependencies != NULL)
19430 htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL);
19435 /* Set the mark field in CU and in every other compilation unit in the
19436 cache that we must keep because we are keeping CU. */
19439 dwarf2_mark (struct dwarf2_cu *cu)
19444 if (cu->dependencies != NULL)
19445 htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL);
19449 dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu)
19453 per_cu->cu->mark = 0;
19454 per_cu = per_cu->cu->read_in_chain;
19458 /* Trivial hash function for partial_die_info: the hash value of a DIE
19459 is its offset in .debug_info for this objfile. */
19462 partial_die_hash (const void *item)
19464 const struct partial_die_info *part_die = item;
19466 return part_die->offset.sect_off;
19469 /* Trivial comparison function for partial_die_info structures: two DIEs
19470 are equal if they have the same offset. */
19473 partial_die_eq (const void *item_lhs, const void *item_rhs)
19475 const struct partial_die_info *part_die_lhs = item_lhs;
19476 const struct partial_die_info *part_die_rhs = item_rhs;
19478 return part_die_lhs->offset.sect_off == part_die_rhs->offset.sect_off;
19481 static struct cmd_list_element *set_dwarf2_cmdlist;
19482 static struct cmd_list_element *show_dwarf2_cmdlist;
19485 set_dwarf2_cmd (char *args, int from_tty)
19487 help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout);
19491 show_dwarf2_cmd (char *args, int from_tty)
19493 cmd_show_list (show_dwarf2_cmdlist, from_tty, "");
19496 /* Free data associated with OBJFILE, if necessary. */
19499 dwarf2_per_objfile_free (struct objfile *objfile, void *d)
19501 struct dwarf2_per_objfile *data = d;
19504 for (ix = 0; ix < dwarf2_per_objfile->n_comp_units; ++ix)
19505 VEC_free (dwarf2_per_cu_ptr,
19506 dwarf2_per_objfile->all_comp_units[ix]->s.imported_symtabs);
19508 VEC_free (dwarf2_section_info_def, data->types);
19510 if (data->dwo_files)
19511 free_dwo_files (data->dwo_files, objfile);
19513 if (data->dwz_file && data->dwz_file->dwz_bfd)
19514 gdb_bfd_unref (data->dwz_file->dwz_bfd);
19518 /* The "save gdb-index" command. */
19520 /* The contents of the hash table we create when building the string
19522 struct strtab_entry
19524 offset_type offset;
19528 /* Hash function for a strtab_entry.
19530 Function is used only during write_hash_table so no index format backward
19531 compatibility is needed. */
19534 hash_strtab_entry (const void *e)
19536 const struct strtab_entry *entry = e;
19537 return mapped_index_string_hash (INT_MAX, entry->str);
19540 /* Equality function for a strtab_entry. */
19543 eq_strtab_entry (const void *a, const void *b)
19545 const struct strtab_entry *ea = a;
19546 const struct strtab_entry *eb = b;
19547 return !strcmp (ea->str, eb->str);
19550 /* Create a strtab_entry hash table. */
19553 create_strtab (void)
19555 return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry,
19556 xfree, xcalloc, xfree);
19559 /* Add a string to the constant pool. Return the string's offset in
19563 add_string (htab_t table, struct obstack *cpool, const char *str)
19566 struct strtab_entry entry;
19567 struct strtab_entry *result;
19570 slot = htab_find_slot (table, &entry, INSERT);
19575 result = XNEW (struct strtab_entry);
19576 result->offset = obstack_object_size (cpool);
19578 obstack_grow_str0 (cpool, str);
19581 return result->offset;
19584 /* An entry in the symbol table. */
19585 struct symtab_index_entry
19587 /* The name of the symbol. */
19589 /* The offset of the name in the constant pool. */
19590 offset_type index_offset;
19591 /* A sorted vector of the indices of all the CUs that hold an object
19593 VEC (offset_type) *cu_indices;
19596 /* The symbol table. This is a power-of-2-sized hash table. */
19597 struct mapped_symtab
19599 offset_type n_elements;
19601 struct symtab_index_entry **data;
19604 /* Hash function for a symtab_index_entry. */
19607 hash_symtab_entry (const void *e)
19609 const struct symtab_index_entry *entry = e;
19610 return iterative_hash (VEC_address (offset_type, entry->cu_indices),
19611 sizeof (offset_type) * VEC_length (offset_type,
19612 entry->cu_indices),
19616 /* Equality function for a symtab_index_entry. */
19619 eq_symtab_entry (const void *a, const void *b)
19621 const struct symtab_index_entry *ea = a;
19622 const struct symtab_index_entry *eb = b;
19623 int len = VEC_length (offset_type, ea->cu_indices);
19624 if (len != VEC_length (offset_type, eb->cu_indices))
19626 return !memcmp (VEC_address (offset_type, ea->cu_indices),
19627 VEC_address (offset_type, eb->cu_indices),
19628 sizeof (offset_type) * len);
19631 /* Destroy a symtab_index_entry. */
19634 delete_symtab_entry (void *p)
19636 struct symtab_index_entry *entry = p;
19637 VEC_free (offset_type, entry->cu_indices);
19641 /* Create a hash table holding symtab_index_entry objects. */
19644 create_symbol_hash_table (void)
19646 return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry,
19647 delete_symtab_entry, xcalloc, xfree);
19650 /* Create a new mapped symtab object. */
19652 static struct mapped_symtab *
19653 create_mapped_symtab (void)
19655 struct mapped_symtab *symtab = XNEW (struct mapped_symtab);
19656 symtab->n_elements = 0;
19657 symtab->size = 1024;
19658 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
19662 /* Destroy a mapped_symtab. */
19665 cleanup_mapped_symtab (void *p)
19667 struct mapped_symtab *symtab = p;
19668 /* The contents of the array are freed when the other hash table is
19670 xfree (symtab->data);
19674 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
19677 Function is used only during write_hash_table so no index format backward
19678 compatibility is needed. */
19680 static struct symtab_index_entry **
19681 find_slot (struct mapped_symtab *symtab, const char *name)
19683 offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
19685 index = hash & (symtab->size - 1);
19686 step = ((hash * 17) & (symtab->size - 1)) | 1;
19690 if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name))
19691 return &symtab->data[index];
19692 index = (index + step) & (symtab->size - 1);
19696 /* Expand SYMTAB's hash table. */
19699 hash_expand (struct mapped_symtab *symtab)
19701 offset_type old_size = symtab->size;
19703 struct symtab_index_entry **old_entries = symtab->data;
19706 symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size);
19708 for (i = 0; i < old_size; ++i)
19710 if (old_entries[i])
19712 struct symtab_index_entry **slot = find_slot (symtab,
19713 old_entries[i]->name);
19714 *slot = old_entries[i];
19718 xfree (old_entries);
19721 /* Add an entry to SYMTAB. NAME is the name of the symbol.
19722 CU_INDEX is the index of the CU in which the symbol appears.
19723 IS_STATIC is one if the symbol is static, otherwise zero (global). */
19726 add_index_entry (struct mapped_symtab *symtab, const char *name,
19727 int is_static, gdb_index_symbol_kind kind,
19728 offset_type cu_index)
19730 struct symtab_index_entry **slot;
19731 offset_type cu_index_and_attrs;
19733 ++symtab->n_elements;
19734 if (4 * symtab->n_elements / 3 >= symtab->size)
19735 hash_expand (symtab);
19737 slot = find_slot (symtab, name);
19740 *slot = XNEW (struct symtab_index_entry);
19741 (*slot)->name = name;
19742 /* index_offset is set later. */
19743 (*slot)->cu_indices = NULL;
19746 cu_index_and_attrs = 0;
19747 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs, cu_index);
19748 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs, is_static);
19749 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs, kind);
19751 /* We don't want to record an index value twice as we want to avoid the
19753 We process all global symbols and then all static symbols
19754 (which would allow us to avoid the duplication by only having to check
19755 the last entry pushed), but a symbol could have multiple kinds in one CU.
19756 To keep things simple we don't worry about the duplication here and
19757 sort and uniqufy the list after we've processed all symbols. */
19758 VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index_and_attrs);
19761 /* qsort helper routine for uniquify_cu_indices. */
19764 offset_type_compare (const void *ap, const void *bp)
19766 offset_type a = *(offset_type *) ap;
19767 offset_type b = *(offset_type *) bp;
19769 return (a > b) - (b > a);
19772 /* Sort and remove duplicates of all symbols' cu_indices lists. */
19775 uniquify_cu_indices (struct mapped_symtab *symtab)
19779 for (i = 0; i < symtab->size; ++i)
19781 struct symtab_index_entry *entry = symtab->data[i];
19784 && entry->cu_indices != NULL)
19786 unsigned int next_to_insert, next_to_check;
19787 offset_type last_value;
19789 qsort (VEC_address (offset_type, entry->cu_indices),
19790 VEC_length (offset_type, entry->cu_indices),
19791 sizeof (offset_type), offset_type_compare);
19793 last_value = VEC_index (offset_type, entry->cu_indices, 0);
19794 next_to_insert = 1;
19795 for (next_to_check = 1;
19796 next_to_check < VEC_length (offset_type, entry->cu_indices);
19799 if (VEC_index (offset_type, entry->cu_indices, next_to_check)
19802 last_value = VEC_index (offset_type, entry->cu_indices,
19804 VEC_replace (offset_type, entry->cu_indices, next_to_insert,
19809 VEC_truncate (offset_type, entry->cu_indices, next_to_insert);
19814 /* Add a vector of indices to the constant pool. */
19817 add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool,
19818 struct symtab_index_entry *entry)
19822 slot = htab_find_slot (symbol_hash_table, entry, INSERT);
19825 offset_type len = VEC_length (offset_type, entry->cu_indices);
19826 offset_type val = MAYBE_SWAP (len);
19831 entry->index_offset = obstack_object_size (cpool);
19833 obstack_grow (cpool, &val, sizeof (val));
19835 VEC_iterate (offset_type, entry->cu_indices, i, iter);
19838 val = MAYBE_SWAP (iter);
19839 obstack_grow (cpool, &val, sizeof (val));
19844 struct symtab_index_entry *old_entry = *slot;
19845 entry->index_offset = old_entry->index_offset;
19848 return entry->index_offset;
19851 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
19852 constant pool entries going into the obstack CPOOL. */
19855 write_hash_table (struct mapped_symtab *symtab,
19856 struct obstack *output, struct obstack *cpool)
19859 htab_t symbol_hash_table;
19862 symbol_hash_table = create_symbol_hash_table ();
19863 str_table = create_strtab ();
19865 /* We add all the index vectors to the constant pool first, to
19866 ensure alignment is ok. */
19867 for (i = 0; i < symtab->size; ++i)
19869 if (symtab->data[i])
19870 add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]);
19873 /* Now write out the hash table. */
19874 for (i = 0; i < symtab->size; ++i)
19876 offset_type str_off, vec_off;
19878 if (symtab->data[i])
19880 str_off = add_string (str_table, cpool, symtab->data[i]->name);
19881 vec_off = symtab->data[i]->index_offset;
19885 /* While 0 is a valid constant pool index, it is not valid
19886 to have 0 for both offsets. */
19891 str_off = MAYBE_SWAP (str_off);
19892 vec_off = MAYBE_SWAP (vec_off);
19894 obstack_grow (output, &str_off, sizeof (str_off));
19895 obstack_grow (output, &vec_off, sizeof (vec_off));
19898 htab_delete (str_table);
19899 htab_delete (symbol_hash_table);
19902 /* Struct to map psymtab to CU index in the index file. */
19903 struct psymtab_cu_index_map
19905 struct partial_symtab *psymtab;
19906 unsigned int cu_index;
19910 hash_psymtab_cu_index (const void *item)
19912 const struct psymtab_cu_index_map *map = item;
19914 return htab_hash_pointer (map->psymtab);
19918 eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs)
19920 const struct psymtab_cu_index_map *lhs = item_lhs;
19921 const struct psymtab_cu_index_map *rhs = item_rhs;
19923 return lhs->psymtab == rhs->psymtab;
19926 /* Helper struct for building the address table. */
19927 struct addrmap_index_data
19929 struct objfile *objfile;
19930 struct obstack *addr_obstack;
19931 htab_t cu_index_htab;
19933 /* Non-zero if the previous_* fields are valid.
19934 We can't write an entry until we see the next entry (since it is only then
19935 that we know the end of the entry). */
19936 int previous_valid;
19937 /* Index of the CU in the table of all CUs in the index file. */
19938 unsigned int previous_cu_index;
19939 /* Start address of the CU. */
19940 CORE_ADDR previous_cu_start;
19943 /* Write an address entry to OBSTACK. */
19946 add_address_entry (struct objfile *objfile, struct obstack *obstack,
19947 CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
19949 offset_type cu_index_to_write;
19951 CORE_ADDR baseaddr;
19953 baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
19955 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr);
19956 obstack_grow (obstack, addr, 8);
19957 store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr);
19958 obstack_grow (obstack, addr, 8);
19959 cu_index_to_write = MAYBE_SWAP (cu_index);
19960 obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type));
19963 /* Worker function for traversing an addrmap to build the address table. */
19966 add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
19968 struct addrmap_index_data *data = datap;
19969 struct partial_symtab *pst = obj;
19971 if (data->previous_valid)
19972 add_address_entry (data->objfile, data->addr_obstack,
19973 data->previous_cu_start, start_addr,
19974 data->previous_cu_index);
19976 data->previous_cu_start = start_addr;
19979 struct psymtab_cu_index_map find_map, *map;
19980 find_map.psymtab = pst;
19981 map = htab_find (data->cu_index_htab, &find_map);
19982 gdb_assert (map != NULL);
19983 data->previous_cu_index = map->cu_index;
19984 data->previous_valid = 1;
19987 data->previous_valid = 0;
19992 /* Write OBJFILE's address map to OBSTACK.
19993 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
19994 in the index file. */
19997 write_address_map (struct objfile *objfile, struct obstack *obstack,
19998 htab_t cu_index_htab)
20000 struct addrmap_index_data addrmap_index_data;
20002 /* When writing the address table, we have to cope with the fact that
20003 the addrmap iterator only provides the start of a region; we have to
20004 wait until the next invocation to get the start of the next region. */
20006 addrmap_index_data.objfile = objfile;
20007 addrmap_index_data.addr_obstack = obstack;
20008 addrmap_index_data.cu_index_htab = cu_index_htab;
20009 addrmap_index_data.previous_valid = 0;
20011 addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker,
20012 &addrmap_index_data);
20014 /* It's highly unlikely the last entry (end address = 0xff...ff)
20015 is valid, but we should still handle it.
20016 The end address is recorded as the start of the next region, but that
20017 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
20019 if (addrmap_index_data.previous_valid)
20020 add_address_entry (objfile, obstack,
20021 addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
20022 addrmap_index_data.previous_cu_index);
20025 /* Return the symbol kind of PSYM. */
20027 static gdb_index_symbol_kind
20028 symbol_kind (struct partial_symbol *psym)
20030 domain_enum domain = PSYMBOL_DOMAIN (psym);
20031 enum address_class aclass = PSYMBOL_CLASS (psym);
20039 return GDB_INDEX_SYMBOL_KIND_FUNCTION;
20041 return GDB_INDEX_SYMBOL_KIND_TYPE;
20043 case LOC_CONST_BYTES:
20044 case LOC_OPTIMIZED_OUT:
20046 return GDB_INDEX_SYMBOL_KIND_VARIABLE;
20048 /* Note: It's currently impossible to recognize psyms as enum values
20049 short of reading the type info. For now punt. */
20050 return GDB_INDEX_SYMBOL_KIND_VARIABLE;
20052 /* There are other LOC_FOO values that one might want to classify
20053 as variables, but dwarf2read.c doesn't currently use them. */
20054 return GDB_INDEX_SYMBOL_KIND_OTHER;
20056 case STRUCT_DOMAIN:
20057 return GDB_INDEX_SYMBOL_KIND_TYPE;
20059 return GDB_INDEX_SYMBOL_KIND_OTHER;
20063 /* Add a list of partial symbols to SYMTAB. */
20066 write_psymbols (struct mapped_symtab *symtab,
20068 struct partial_symbol **psymp,
20070 offset_type cu_index,
20073 for (; count-- > 0; ++psymp)
20075 struct partial_symbol *psym = *psymp;
20078 if (SYMBOL_LANGUAGE (psym) == language_ada)
20079 error (_("Ada is not currently supported by the index"));
20081 /* Only add a given psymbol once. */
20082 slot = htab_find_slot (psyms_seen, psym, INSERT);
20085 gdb_index_symbol_kind kind = symbol_kind (psym);
20088 add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym),
20089 is_static, kind, cu_index);
20094 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
20095 exception if there is an error. */
20098 write_obstack (FILE *file, struct obstack *obstack)
20100 if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack),
20102 != obstack_object_size (obstack))
20103 error (_("couldn't data write to file"));
20106 /* Unlink a file if the argument is not NULL. */
20109 unlink_if_set (void *p)
20111 char **filename = p;
20113 unlink (*filename);
20116 /* A helper struct used when iterating over debug_types. */
20117 struct signatured_type_index_data
20119 struct objfile *objfile;
20120 struct mapped_symtab *symtab;
20121 struct obstack *types_list;
20126 /* A helper function that writes a single signatured_type to an
20130 write_one_signatured_type (void **slot, void *d)
20132 struct signatured_type_index_data *info = d;
20133 struct signatured_type *entry = (struct signatured_type *) *slot;
20134 struct dwarf2_per_cu_data *per_cu = &entry->per_cu;
20135 struct partial_symtab *psymtab = per_cu->v.psymtab;
20138 write_psymbols (info->symtab,
20140 info->objfile->global_psymbols.list
20141 + psymtab->globals_offset,
20142 psymtab->n_global_syms, info->cu_index,
20144 write_psymbols (info->symtab,
20146 info->objfile->static_psymbols.list
20147 + psymtab->statics_offset,
20148 psymtab->n_static_syms, info->cu_index,
20151 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
20152 entry->per_cu.offset.sect_off);
20153 obstack_grow (info->types_list, val, 8);
20154 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
20155 entry->type_offset_in_tu.cu_off);
20156 obstack_grow (info->types_list, val, 8);
20157 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature);
20158 obstack_grow (info->types_list, val, 8);
20165 /* Recurse into all "included" dependencies and write their symbols as
20166 if they appeared in this psymtab. */
20169 recursively_write_psymbols (struct objfile *objfile,
20170 struct partial_symtab *psymtab,
20171 struct mapped_symtab *symtab,
20173 offset_type cu_index)
20177 for (i = 0; i < psymtab->number_of_dependencies; ++i)
20178 if (psymtab->dependencies[i]->user != NULL)
20179 recursively_write_psymbols (objfile, psymtab->dependencies[i],
20180 symtab, psyms_seen, cu_index);
20182 write_psymbols (symtab,
20184 objfile->global_psymbols.list + psymtab->globals_offset,
20185 psymtab->n_global_syms, cu_index,
20187 write_psymbols (symtab,
20189 objfile->static_psymbols.list + psymtab->statics_offset,
20190 psymtab->n_static_syms, cu_index,
20194 /* Create an index file for OBJFILE in the directory DIR. */
20197 write_psymtabs_to_index (struct objfile *objfile, const char *dir)
20199 struct cleanup *cleanup;
20200 char *filename, *cleanup_filename;
20201 struct obstack contents, addr_obstack, constant_pool, symtab_obstack;
20202 struct obstack cu_list, types_cu_list;
20205 struct mapped_symtab *symtab;
20206 offset_type val, size_of_contents, total_len;
20209 htab_t cu_index_htab;
20210 struct psymtab_cu_index_map *psymtab_cu_index_map;
20212 if (!objfile->psymtabs || !objfile->psymtabs_addrmap)
20215 if (dwarf2_per_objfile->using_index)
20216 error (_("Cannot use an index to create the index"));
20218 if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
20219 error (_("Cannot make an index when the file has multiple .debug_types sections"));
20221 if (stat (objfile->name, &st) < 0)
20222 perror_with_name (objfile->name);
20224 filename = concat (dir, SLASH_STRING, lbasename (objfile->name),
20225 INDEX_SUFFIX, (char *) NULL);
20226 cleanup = make_cleanup (xfree, filename);
20228 out_file = fopen (filename, "wb");
20230 error (_("Can't open `%s' for writing"), filename);
20232 cleanup_filename = filename;
20233 make_cleanup (unlink_if_set, &cleanup_filename);
20235 symtab = create_mapped_symtab ();
20236 make_cleanup (cleanup_mapped_symtab, symtab);
20238 obstack_init (&addr_obstack);
20239 make_cleanup_obstack_free (&addr_obstack);
20241 obstack_init (&cu_list);
20242 make_cleanup_obstack_free (&cu_list);
20244 obstack_init (&types_cu_list);
20245 make_cleanup_obstack_free (&types_cu_list);
20247 psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
20248 NULL, xcalloc, xfree);
20249 make_cleanup_htab_delete (psyms_seen);
20251 /* While we're scanning CU's create a table that maps a psymtab pointer
20252 (which is what addrmap records) to its index (which is what is recorded
20253 in the index file). This will later be needed to write the address
20255 cu_index_htab = htab_create_alloc (100,
20256 hash_psymtab_cu_index,
20257 eq_psymtab_cu_index,
20258 NULL, xcalloc, xfree);
20259 make_cleanup_htab_delete (cu_index_htab);
20260 psymtab_cu_index_map = (struct psymtab_cu_index_map *)
20261 xmalloc (sizeof (struct psymtab_cu_index_map)
20262 * dwarf2_per_objfile->n_comp_units);
20263 make_cleanup (xfree, psymtab_cu_index_map);
20265 /* The CU list is already sorted, so we don't need to do additional
20266 work here. Also, the debug_types entries do not appear in
20267 all_comp_units, but only in their own hash table. */
20268 for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i)
20270 struct dwarf2_per_cu_data *per_cu
20271 = dwarf2_per_objfile->all_comp_units[i];
20272 struct partial_symtab *psymtab = per_cu->v.psymtab;
20274 struct psymtab_cu_index_map *map;
20277 if (psymtab->user == NULL)
20278 recursively_write_psymbols (objfile, psymtab, symtab, psyms_seen, i);
20280 map = &psymtab_cu_index_map[i];
20281 map->psymtab = psymtab;
20283 slot = htab_find_slot (cu_index_htab, map, INSERT);
20284 gdb_assert (slot != NULL);
20285 gdb_assert (*slot == NULL);
20288 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE,
20289 per_cu->offset.sect_off);
20290 obstack_grow (&cu_list, val, 8);
20291 store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length);
20292 obstack_grow (&cu_list, val, 8);
20295 /* Dump the address map. */
20296 write_address_map (objfile, &addr_obstack, cu_index_htab);
20298 /* Write out the .debug_type entries, if any. */
20299 if (dwarf2_per_objfile->signatured_types)
20301 struct signatured_type_index_data sig_data;
20303 sig_data.objfile = objfile;
20304 sig_data.symtab = symtab;
20305 sig_data.types_list = &types_cu_list;
20306 sig_data.psyms_seen = psyms_seen;
20307 sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
20308 htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
20309 write_one_signatured_type, &sig_data);
20312 /* Now that we've processed all symbols we can shrink their cu_indices
20314 uniquify_cu_indices (symtab);
20316 obstack_init (&constant_pool);
20317 make_cleanup_obstack_free (&constant_pool);
20318 obstack_init (&symtab_obstack);
20319 make_cleanup_obstack_free (&symtab_obstack);
20320 write_hash_table (symtab, &symtab_obstack, &constant_pool);
20322 obstack_init (&contents);
20323 make_cleanup_obstack_free (&contents);
20324 size_of_contents = 6 * sizeof (offset_type);
20325 total_len = size_of_contents;
20327 /* The version number. */
20328 val = MAYBE_SWAP (7);
20329 obstack_grow (&contents, &val, sizeof (val));
20331 /* The offset of the CU list from the start of the file. */
20332 val = MAYBE_SWAP (total_len);
20333 obstack_grow (&contents, &val, sizeof (val));
20334 total_len += obstack_object_size (&cu_list);
20336 /* The offset of the types CU list from the start of the file. */
20337 val = MAYBE_SWAP (total_len);
20338 obstack_grow (&contents, &val, sizeof (val));
20339 total_len += obstack_object_size (&types_cu_list);
20341 /* The offset of the address table from the start of the file. */
20342 val = MAYBE_SWAP (total_len);
20343 obstack_grow (&contents, &val, sizeof (val));
20344 total_len += obstack_object_size (&addr_obstack);
20346 /* The offset of the symbol table from the start of the file. */
20347 val = MAYBE_SWAP (total_len);
20348 obstack_grow (&contents, &val, sizeof (val));
20349 total_len += obstack_object_size (&symtab_obstack);
20351 /* The offset of the constant pool from the start of the file. */
20352 val = MAYBE_SWAP (total_len);
20353 obstack_grow (&contents, &val, sizeof (val));
20354 total_len += obstack_object_size (&constant_pool);
20356 gdb_assert (obstack_object_size (&contents) == size_of_contents);
20358 write_obstack (out_file, &contents);
20359 write_obstack (out_file, &cu_list);
20360 write_obstack (out_file, &types_cu_list);
20361 write_obstack (out_file, &addr_obstack);
20362 write_obstack (out_file, &symtab_obstack);
20363 write_obstack (out_file, &constant_pool);
20367 /* We want to keep the file, so we set cleanup_filename to NULL
20368 here. See unlink_if_set. */
20369 cleanup_filename = NULL;
20371 do_cleanups (cleanup);
20374 /* Implementation of the `save gdb-index' command.
20376 Note that the file format used by this command is documented in the
20377 GDB manual. Any changes here must be documented there. */
20380 save_gdb_index_command (char *arg, int from_tty)
20382 struct objfile *objfile;
20385 error (_("usage: save gdb-index DIRECTORY"));
20387 ALL_OBJFILES (objfile)
20391 /* If the objfile does not correspond to an actual file, skip it. */
20392 if (stat (objfile->name, &st) < 0)
20395 dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
20396 if (dwarf2_per_objfile)
20398 volatile struct gdb_exception except;
20400 TRY_CATCH (except, RETURN_MASK_ERROR)
20402 write_psymtabs_to_index (objfile, arg);
20404 if (except.reason < 0)
20405 exception_fprintf (gdb_stderr, except,
20406 _("Error while writing index for `%s': "),
20414 int dwarf2_always_disassemble;
20417 show_dwarf2_always_disassemble (struct ui_file *file, int from_tty,
20418 struct cmd_list_element *c, const char *value)
20420 fprintf_filtered (file,
20421 _("Whether to always disassemble "
20422 "DWARF expressions is %s.\n"),
20427 show_check_physname (struct ui_file *file, int from_tty,
20428 struct cmd_list_element *c, const char *value)
20430 fprintf_filtered (file,
20431 _("Whether to check \"physname\" is %s.\n"),
20435 void _initialize_dwarf2_read (void);
20438 _initialize_dwarf2_read (void)
20440 struct cmd_list_element *c;
20442 dwarf2_objfile_data_key
20443 = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free);
20445 add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\
20446 Set DWARF 2 specific variables.\n\
20447 Configure DWARF 2 variables such as the cache size"),
20448 &set_dwarf2_cmdlist, "maintenance set dwarf2 ",
20449 0/*allow-unknown*/, &maintenance_set_cmdlist);
20451 add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\
20452 Show DWARF 2 specific variables\n\
20453 Show DWARF 2 variables such as the cache size"),
20454 &show_dwarf2_cmdlist, "maintenance show dwarf2 ",
20455 0/*allow-unknown*/, &maintenance_show_cmdlist);
20457 add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
20458 &dwarf2_max_cache_age, _("\
20459 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
20460 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
20461 A higher limit means that cached compilation units will be stored\n\
20462 in memory longer, and more total memory will be used. Zero disables\n\
20463 caching, which can slow down startup."),
20465 show_dwarf2_max_cache_age,
20466 &set_dwarf2_cmdlist,
20467 &show_dwarf2_cmdlist);
20469 add_setshow_boolean_cmd ("always-disassemble", class_obscure,
20470 &dwarf2_always_disassemble, _("\
20471 Set whether `info address' always disassembles DWARF expressions."), _("\
20472 Show whether `info address' always disassembles DWARF expressions."), _("\
20473 When enabled, DWARF expressions are always printed in an assembly-like\n\
20474 syntax. When disabled, expressions will be printed in a more\n\
20475 conversational style, when possible."),
20477 show_dwarf2_always_disassemble,
20478 &set_dwarf2_cmdlist,
20479 &show_dwarf2_cmdlist);
20481 add_setshow_boolean_cmd ("dwarf2-read", no_class, &dwarf2_read_debug, _("\
20482 Set debugging of the dwarf2 reader."), _("\
20483 Show debugging of the dwarf2 reader."), _("\
20484 When enabled, debugging messages are printed during dwarf2 reading\n\
20485 and symtab expansion."),
20488 &setdebuglist, &showdebuglist);
20490 add_setshow_zuinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\
20491 Set debugging of the dwarf2 DIE reader."), _("\
20492 Show debugging of the dwarf2 DIE reader."), _("\
20493 When enabled (non-zero), DIEs are dumped after they are read in.\n\
20494 The value is the maximum depth to print."),
20497 &setdebuglist, &showdebuglist);
20499 add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\
20500 Set cross-checking of \"physname\" code against demangler."), _("\
20501 Show cross-checking of \"physname\" code against demangler."), _("\
20502 When enabled, GDB's internal \"physname\" code is checked against\n\
20504 NULL, show_check_physname,
20505 &setdebuglist, &showdebuglist);
20507 add_setshow_boolean_cmd ("use-deprecated-index-sections",
20508 no_class, &use_deprecated_index_sections, _("\
20509 Set whether to use deprecated gdb_index sections."), _("\
20510 Show whether to use deprecated gdb_index sections."), _("\
20511 When enabled, deprecated .gdb_index sections are used anyway.\n\
20512 Normally they are ignored either because of a missing feature or\n\
20513 performance issue.\n\
20514 Warning: This option must be enabled before gdb reads the file."),
20517 &setlist, &showlist);
20519 c = add_cmd ("gdb-index", class_files, save_gdb_index_command,
20521 Save a gdb-index file.\n\
20522 Usage: save gdb-index DIRECTORY"),
20524 set_cmd_completer (c, filename_completer);