1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2018 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 "completer.h"
63 #include "gdbcore.h" /* for gnutarget */
64 #include "gdb/gdb-index.h"
69 #include "filestuff.h"
71 #include "namespace.h"
72 #include "common/gdb_unlinker.h"
73 #include "common/function-view.h"
74 #include "common/gdb_optional.h"
75 #include "common/underlying.h"
76 #include "common/byte-vector.h"
77 #include "common/hash_enum.h"
78 #include "filename-seen-cache.h"
81 #include <sys/types.h>
83 #include <unordered_set>
84 #include <unordered_map>
88 #include <forward_list>
90 /* When == 1, print basic high level tracing messages.
91 When > 1, be more verbose.
92 This is in contrast to the low level DIE reading of dwarf_die_debug. */
93 static unsigned int dwarf_read_debug
= 0;
95 /* When non-zero, dump DIEs after they are read in. */
96 static unsigned int dwarf_die_debug
= 0;
98 /* When non-zero, dump line number entries as they are read in. */
99 static unsigned int dwarf_line_debug
= 0;
101 /* When non-zero, cross-check physname against demangler. */
102 static int check_physname
= 0;
104 /* When non-zero, do not reject deprecated .gdb_index sections. */
105 static int use_deprecated_index_sections
= 0;
107 static const struct objfile_data
*dwarf2_objfile_data_key
;
109 /* The "aclass" indices for various kinds of computed DWARF symbols. */
111 static int dwarf2_locexpr_index
;
112 static int dwarf2_loclist_index
;
113 static int dwarf2_locexpr_block_index
;
114 static int dwarf2_loclist_block_index
;
116 /* A descriptor for dwarf sections.
118 S.ASECTION, SIZE are typically initialized when the objfile is first
119 scanned. BUFFER, READIN are filled in later when the section is read.
120 If the section contained compressed data then SIZE is updated to record
121 the uncompressed size of the section.
123 DWP file format V2 introduces a wrinkle that is easiest to handle by
124 creating the concept of virtual sections contained within a real section.
125 In DWP V2 the sections of the input DWO files are concatenated together
126 into one section, but section offsets are kept relative to the original
128 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
129 the real section this "virtual" section is contained in, and BUFFER,SIZE
130 describe the virtual section. */
132 struct dwarf2_section_info
136 /* If this is a real section, the bfd section. */
138 /* If this is a virtual section, pointer to the containing ("real")
140 struct dwarf2_section_info
*containing_section
;
142 /* Pointer to section data, only valid if readin. */
143 const gdb_byte
*buffer
;
144 /* The size of the section, real or virtual. */
146 /* If this is a virtual section, the offset in the real section.
147 Only valid if is_virtual. */
148 bfd_size_type virtual_offset
;
149 /* True if we have tried to read this section. */
151 /* True if this is a virtual section, False otherwise.
152 This specifies which of s.section and s.containing_section to use. */
156 typedef struct dwarf2_section_info dwarf2_section_info_def
;
157 DEF_VEC_O (dwarf2_section_info_def
);
159 /* All offsets in the index are of this type. It must be
160 architecture-independent. */
161 typedef uint32_t offset_type
;
163 DEF_VEC_I (offset_type
);
165 /* Ensure only legit values are used. */
166 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
168 gdb_assert ((unsigned int) (value) <= 1); \
169 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
172 /* Ensure only legit values are used. */
173 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
175 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
176 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
177 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
180 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
181 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
183 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
184 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
189 /* Convert VALUE between big- and little-endian. */
192 byte_swap (offset_type value
)
196 result
= (value
& 0xff) << 24;
197 result
|= (value
& 0xff00) << 8;
198 result
|= (value
& 0xff0000) >> 8;
199 result
|= (value
& 0xff000000) >> 24;
203 #define MAYBE_SWAP(V) byte_swap (V)
206 #define MAYBE_SWAP(V) static_cast<offset_type> (V)
207 #endif /* WORDS_BIGENDIAN */
209 /* An index into a (C++) symbol name component in a symbol name as
210 recorded in the mapped_index's symbol table. For each C++ symbol
211 in the symbol table, we record one entry for the start of each
212 component in the symbol in a table of name components, and then
213 sort the table, in order to be able to binary search symbol names,
214 ignoring leading namespaces, both completion and regular look up.
215 For example, for symbol "A::B::C", we'll have an entry that points
216 to "A::B::C", another that points to "B::C", and another for "C".
217 Note that function symbols in GDB index have no parameter
218 information, just the function/method names. You can convert a
219 name_component to a "const char *" using the
220 'mapped_index::symbol_name_at(offset_type)' method. */
222 struct name_component
224 /* Offset in the symbol name where the component starts. Stored as
225 a (32-bit) offset instead of a pointer to save memory and improve
226 locality on 64-bit architectures. */
227 offset_type name_offset
;
229 /* The symbol's index in the symbol and constant pool tables of a
234 /* Base class containing bits shared by both .gdb_index and
235 .debug_name indexes. */
237 struct mapped_index_base
239 /* The name_component table (a sorted vector). See name_component's
240 description above. */
241 std::vector
<name_component
> name_components
;
243 /* How NAME_COMPONENTS is sorted. */
244 enum case_sensitivity name_components_casing
;
246 /* Return the number of names in the symbol table. */
247 virtual size_t symbol_name_count () const = 0;
249 /* Get the name of the symbol at IDX in the symbol table. */
250 virtual const char *symbol_name_at (offset_type idx
) const = 0;
252 /* Return whether the name at IDX in the symbol table should be
254 virtual bool symbol_name_slot_invalid (offset_type idx
) const
259 /* Build the symbol name component sorted vector, if we haven't
261 void build_name_components ();
263 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
264 possible matches for LN_NO_PARAMS in the name component
266 std::pair
<std::vector
<name_component
>::const_iterator
,
267 std::vector
<name_component
>::const_iterator
>
268 find_name_components_bounds (const lookup_name_info
&ln_no_params
) const;
270 /* Prevent deleting/destroying via a base class pointer. */
272 ~mapped_index_base() = default;
275 /* A description of the mapped index. The file format is described in
276 a comment by the code that writes the index. */
277 struct mapped_index final
: public mapped_index_base
279 /* A slot/bucket in the symbol table hash. */
280 struct symbol_table_slot
282 const offset_type name
;
283 const offset_type vec
;
286 /* Index data format version. */
289 /* The total length of the buffer. */
292 /* The address table data. */
293 gdb::array_view
<const gdb_byte
> address_table
;
295 /* The symbol table, implemented as a hash table. */
296 gdb::array_view
<symbol_table_slot
> symbol_table
;
298 /* A pointer to the constant pool. */
299 const char *constant_pool
;
301 bool symbol_name_slot_invalid (offset_type idx
) const override
303 const auto &bucket
= this->symbol_table
[idx
];
304 return bucket
.name
== 0 && bucket
.vec
;
307 /* Convenience method to get at the name of the symbol at IDX in the
309 const char *symbol_name_at (offset_type idx
) const override
310 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
312 size_t symbol_name_count () const override
313 { return this->symbol_table
.size (); }
316 /* A description of the mapped .debug_names.
317 Uninitialized map has CU_COUNT 0. */
318 struct mapped_debug_names final
: public mapped_index_base
320 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
321 : dwarf2_per_objfile (dwarf2_per_objfile_
)
324 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
325 bfd_endian dwarf5_byte_order
;
326 bool dwarf5_is_dwarf64
;
327 bool augmentation_is_gdb
;
329 uint32_t cu_count
= 0;
330 uint32_t tu_count
, bucket_count
, name_count
;
331 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
332 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
333 const gdb_byte
*name_table_string_offs_reordered
;
334 const gdb_byte
*name_table_entry_offs_reordered
;
335 const gdb_byte
*entry_pool
;
342 /* Attribute name DW_IDX_*. */
345 /* Attribute form DW_FORM_*. */
348 /* Value if FORM is DW_FORM_implicit_const. */
349 LONGEST implicit_const
;
351 std::vector
<attr
> attr_vec
;
354 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
356 const char *namei_to_name (uint32_t namei
) const;
358 /* Implementation of the mapped_index_base virtual interface, for
359 the name_components cache. */
361 const char *symbol_name_at (offset_type idx
) const override
362 { return namei_to_name (idx
); }
364 size_t symbol_name_count () const override
365 { return this->name_count
; }
368 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
369 DEF_VEC_P (dwarf2_per_cu_ptr
);
373 int nr_uniq_abbrev_tables
;
375 int nr_symtab_sharers
;
376 int nr_stmt_less_type_units
;
377 int nr_all_type_units_reallocs
;
380 /* Collection of data recorded per objfile.
381 This hangs off of dwarf2_objfile_data_key. */
383 struct dwarf2_per_objfile
385 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
386 dwarf2 section names, or is NULL if the standard ELF names are
388 dwarf2_per_objfile (struct objfile
*objfile
,
389 const dwarf2_debug_sections
*names
);
391 ~dwarf2_per_objfile ();
393 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile
);
395 /* Free all cached compilation units. */
396 void free_cached_comp_units ();
398 /* This function is mapped across the sections and remembers the
399 offset and size of each of the debugging sections we are
401 void locate_sections (bfd
*abfd
, asection
*sectp
,
402 const dwarf2_debug_sections
&names
);
405 dwarf2_section_info info
{};
406 dwarf2_section_info abbrev
{};
407 dwarf2_section_info line
{};
408 dwarf2_section_info loc
{};
409 dwarf2_section_info loclists
{};
410 dwarf2_section_info macinfo
{};
411 dwarf2_section_info macro
{};
412 dwarf2_section_info str
{};
413 dwarf2_section_info line_str
{};
414 dwarf2_section_info ranges
{};
415 dwarf2_section_info rnglists
{};
416 dwarf2_section_info addr
{};
417 dwarf2_section_info frame
{};
418 dwarf2_section_info eh_frame
{};
419 dwarf2_section_info gdb_index
{};
420 dwarf2_section_info debug_names
{};
421 dwarf2_section_info debug_aranges
{};
423 VEC (dwarf2_section_info_def
) *types
= NULL
;
426 struct objfile
*objfile
= NULL
;
428 /* Table of all the compilation units. This is used to locate
429 the target compilation unit of a particular reference. */
430 struct dwarf2_per_cu_data
**all_comp_units
= NULL
;
432 /* The number of compilation units in ALL_COMP_UNITS. */
433 int n_comp_units
= 0;
435 /* The number of .debug_types-related CUs. */
436 int n_type_units
= 0;
438 /* The number of elements allocated in all_type_units.
439 If there are skeleton-less TUs, we add them to all_type_units lazily. */
440 int n_allocated_type_units
= 0;
442 /* The .debug_types-related CUs (TUs).
443 This is stored in malloc space because we may realloc it. */
444 struct signatured_type
**all_type_units
= NULL
;
446 /* Table of struct type_unit_group objects.
447 The hash key is the DW_AT_stmt_list value. */
448 htab_t type_unit_groups
{};
450 /* A table mapping .debug_types signatures to its signatured_type entry.
451 This is NULL if the .debug_types section hasn't been read in yet. */
452 htab_t signatured_types
{};
454 /* Type unit statistics, to see how well the scaling improvements
456 struct tu_stats tu_stats
{};
458 /* A chain of compilation units that are currently read in, so that
459 they can be freed later. */
460 dwarf2_per_cu_data
*read_in_chain
= NULL
;
462 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
463 This is NULL if the table hasn't been allocated yet. */
466 /* True if we've checked for whether there is a DWP file. */
467 bool dwp_checked
= false;
469 /* The DWP file if there is one, or NULL. */
470 struct dwp_file
*dwp_file
= NULL
;
472 /* The shared '.dwz' file, if one exists. This is used when the
473 original data was compressed using 'dwz -m'. */
474 struct dwz_file
*dwz_file
= NULL
;
476 /* A flag indicating whether this objfile has a section loaded at a
478 bool has_section_at_zero
= false;
480 /* True if we are using the mapped index,
481 or we are faking it for OBJF_READNOW's sake. */
482 bool using_index
= false;
484 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
485 mapped_index
*index_table
= NULL
;
487 /* The mapped index, or NULL if .debug_names is missing or not being used. */
488 std::unique_ptr
<mapped_debug_names
> debug_names_table
;
490 /* When using index_table, this keeps track of all quick_file_names entries.
491 TUs typically share line table entries with a CU, so we maintain a
492 separate table of all line table entries to support the sharing.
493 Note that while there can be way more TUs than CUs, we've already
494 sorted all the TUs into "type unit groups", grouped by their
495 DW_AT_stmt_list value. Therefore the only sharing done here is with a
496 CU and its associated TU group if there is one. */
497 htab_t quick_file_names_table
{};
499 /* Set during partial symbol reading, to prevent queueing of full
501 bool reading_partial_symbols
= false;
503 /* Table mapping type DIEs to their struct type *.
504 This is NULL if not allocated yet.
505 The mapping is done via (CU/TU + DIE offset) -> type. */
506 htab_t die_type_hash
{};
508 /* The CUs we recently read. */
509 VEC (dwarf2_per_cu_ptr
) *just_read_cus
= NULL
;
511 /* Table containing line_header indexed by offset and offset_in_dwz. */
512 htab_t line_header_hash
{};
514 /* Table containing all filenames. This is an optional because the
515 table is lazily constructed on first access. */
516 gdb::optional
<filename_seen_cache
> filenames_cache
;
519 /* Get the dwarf2_per_objfile associated to OBJFILE. */
521 struct dwarf2_per_objfile
*
522 get_dwarf2_per_objfile (struct objfile
*objfile
)
524 return ((struct dwarf2_per_objfile
*)
525 objfile_data (objfile
, dwarf2_objfile_data_key
));
528 /* Set the dwarf2_per_objfile associated to OBJFILE. */
531 set_dwarf2_per_objfile (struct objfile
*objfile
,
532 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
534 gdb_assert (get_dwarf2_per_objfile (objfile
) == NULL
);
535 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
538 /* Default names of the debugging sections. */
540 /* Note that if the debugging section has been compressed, it might
541 have a name like .zdebug_info. */
543 static const struct dwarf2_debug_sections dwarf2_elf_names
=
545 { ".debug_info", ".zdebug_info" },
546 { ".debug_abbrev", ".zdebug_abbrev" },
547 { ".debug_line", ".zdebug_line" },
548 { ".debug_loc", ".zdebug_loc" },
549 { ".debug_loclists", ".zdebug_loclists" },
550 { ".debug_macinfo", ".zdebug_macinfo" },
551 { ".debug_macro", ".zdebug_macro" },
552 { ".debug_str", ".zdebug_str" },
553 { ".debug_line_str", ".zdebug_line_str" },
554 { ".debug_ranges", ".zdebug_ranges" },
555 { ".debug_rnglists", ".zdebug_rnglists" },
556 { ".debug_types", ".zdebug_types" },
557 { ".debug_addr", ".zdebug_addr" },
558 { ".debug_frame", ".zdebug_frame" },
559 { ".eh_frame", NULL
},
560 { ".gdb_index", ".zgdb_index" },
561 { ".debug_names", ".zdebug_names" },
562 { ".debug_aranges", ".zdebug_aranges" },
566 /* List of DWO/DWP sections. */
568 static const struct dwop_section_names
570 struct dwarf2_section_names abbrev_dwo
;
571 struct dwarf2_section_names info_dwo
;
572 struct dwarf2_section_names line_dwo
;
573 struct dwarf2_section_names loc_dwo
;
574 struct dwarf2_section_names loclists_dwo
;
575 struct dwarf2_section_names macinfo_dwo
;
576 struct dwarf2_section_names macro_dwo
;
577 struct dwarf2_section_names str_dwo
;
578 struct dwarf2_section_names str_offsets_dwo
;
579 struct dwarf2_section_names types_dwo
;
580 struct dwarf2_section_names cu_index
;
581 struct dwarf2_section_names tu_index
;
585 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
586 { ".debug_info.dwo", ".zdebug_info.dwo" },
587 { ".debug_line.dwo", ".zdebug_line.dwo" },
588 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
589 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
590 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
591 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
592 { ".debug_str.dwo", ".zdebug_str.dwo" },
593 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
594 { ".debug_types.dwo", ".zdebug_types.dwo" },
595 { ".debug_cu_index", ".zdebug_cu_index" },
596 { ".debug_tu_index", ".zdebug_tu_index" },
599 /* local data types */
601 /* The data in a compilation unit header, after target2host
602 translation, looks like this. */
603 struct comp_unit_head
607 unsigned char addr_size
;
608 unsigned char signed_addr_p
;
609 sect_offset abbrev_sect_off
;
611 /* Size of file offsets; either 4 or 8. */
612 unsigned int offset_size
;
614 /* Size of the length field; either 4 or 12. */
615 unsigned int initial_length_size
;
617 enum dwarf_unit_type unit_type
;
619 /* Offset to the first byte of this compilation unit header in the
620 .debug_info section, for resolving relative reference dies. */
621 sect_offset sect_off
;
623 /* Offset to first die in this cu from the start of the cu.
624 This will be the first byte following the compilation unit header. */
625 cu_offset first_die_cu_offset
;
627 /* 64-bit signature of this type unit - it is valid only for
628 UNIT_TYPE DW_UT_type. */
631 /* For types, offset in the type's DIE of the type defined by this TU. */
632 cu_offset type_cu_offset_in_tu
;
635 /* Type used for delaying computation of method physnames.
636 See comments for compute_delayed_physnames. */
637 struct delayed_method_info
639 /* The type to which the method is attached, i.e., its parent class. */
642 /* The index of the method in the type's function fieldlists. */
645 /* The index of the method in the fieldlist. */
648 /* The name of the DIE. */
651 /* The DIE associated with this method. */
652 struct die_info
*die
;
655 /* Internal state when decoding a particular compilation unit. */
658 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
661 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
663 /* The header of the compilation unit. */
664 struct comp_unit_head header
{};
666 /* Base address of this compilation unit. */
667 CORE_ADDR base_address
= 0;
669 /* Non-zero if base_address has been set. */
672 /* The language we are debugging. */
673 enum language language
= language_unknown
;
674 const struct language_defn
*language_defn
= nullptr;
676 const char *producer
= nullptr;
678 /* The generic symbol table building routines have separate lists for
679 file scope symbols and all all other scopes (local scopes). So
680 we need to select the right one to pass to add_symbol_to_list().
681 We do it by keeping a pointer to the correct list in list_in_scope.
683 FIXME: The original dwarf code just treated the file scope as the
684 first local scope, and all other local scopes as nested local
685 scopes, and worked fine. Check to see if we really need to
686 distinguish these in buildsym.c. */
687 struct pending
**list_in_scope
= nullptr;
689 /* Hash table holding all the loaded partial DIEs
690 with partial_die->offset.SECT_OFF as hash. */
691 htab_t partial_dies
= nullptr;
693 /* Storage for things with the same lifetime as this read-in compilation
694 unit, including partial DIEs. */
695 auto_obstack comp_unit_obstack
;
697 /* When multiple dwarf2_cu structures are living in memory, this field
698 chains them all together, so that they can be released efficiently.
699 We will probably also want a generation counter so that most-recently-used
700 compilation units are cached... */
701 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
703 /* Backlink to our per_cu entry. */
704 struct dwarf2_per_cu_data
*per_cu
;
706 /* How many compilation units ago was this CU last referenced? */
709 /* A hash table of DIE cu_offset for following references with
710 die_info->offset.sect_off as hash. */
711 htab_t die_hash
= nullptr;
713 /* Full DIEs if read in. */
714 struct die_info
*dies
= nullptr;
716 /* A set of pointers to dwarf2_per_cu_data objects for compilation
717 units referenced by this one. Only set during full symbol processing;
718 partial symbol tables do not have dependencies. */
719 htab_t dependencies
= nullptr;
721 /* Header data from the line table, during full symbol processing. */
722 struct line_header
*line_header
= nullptr;
723 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
724 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
725 this is the DW_TAG_compile_unit die for this CU. We'll hold on
726 to the line header as long as this DIE is being processed. See
727 process_die_scope. */
728 die_info
*line_header_die_owner
= nullptr;
730 /* A list of methods which need to have physnames computed
731 after all type information has been read. */
732 std::vector
<delayed_method_info
> method_list
;
734 /* To be copied to symtab->call_site_htab. */
735 htab_t call_site_htab
= nullptr;
737 /* Non-NULL if this CU came from a DWO file.
738 There is an invariant here that is important to remember:
739 Except for attributes copied from the top level DIE in the "main"
740 (or "stub") file in preparation for reading the DWO file
741 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
742 Either there isn't a DWO file (in which case this is NULL and the point
743 is moot), or there is and either we're not going to read it (in which
744 case this is NULL) or there is and we are reading it (in which case this
746 struct dwo_unit
*dwo_unit
= nullptr;
748 /* The DW_AT_addr_base attribute if present, zero otherwise
749 (zero is a valid value though).
750 Note this value comes from the Fission stub CU/TU's DIE. */
751 ULONGEST addr_base
= 0;
753 /* The DW_AT_ranges_base attribute if present, zero otherwise
754 (zero is a valid value though).
755 Note this value comes from the Fission stub CU/TU's DIE.
756 Also note that the value is zero in the non-DWO case so this value can
757 be used without needing to know whether DWO files are in use or not.
758 N.B. This does not apply to DW_AT_ranges appearing in
759 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
760 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
761 DW_AT_ranges_base *would* have to be applied, and we'd have to care
762 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
763 ULONGEST ranges_base
= 0;
765 /* Mark used when releasing cached dies. */
766 unsigned int mark
: 1;
768 /* This CU references .debug_loc. See the symtab->locations_valid field.
769 This test is imperfect as there may exist optimized debug code not using
770 any location list and still facing inlining issues if handled as
771 unoptimized code. For a future better test see GCC PR other/32998. */
772 unsigned int has_loclist
: 1;
774 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
775 if all the producer_is_* fields are valid. This information is cached
776 because profiling CU expansion showed excessive time spent in
777 producer_is_gxx_lt_4_6. */
778 unsigned int checked_producer
: 1;
779 unsigned int producer_is_gxx_lt_4_6
: 1;
780 unsigned int producer_is_gcc_lt_4_3
: 1;
781 unsigned int producer_is_icc_lt_14
: 1;
783 /* When set, the file that we're processing is known to have
784 debugging info for C++ namespaces. GCC 3.3.x did not produce
785 this information, but later versions do. */
787 unsigned int processing_has_namespace_info
: 1;
790 /* Persistent data held for a compilation unit, even when not
791 processing it. We put a pointer to this structure in the
792 read_symtab_private field of the psymtab. */
794 struct dwarf2_per_cu_data
796 /* The start offset and length of this compilation unit.
797 NOTE: Unlike comp_unit_head.length, this length includes
799 If the DIE refers to a DWO file, this is always of the original die,
801 sect_offset sect_off
;
804 /* DWARF standard version this data has been read from (such as 4 or 5). */
807 /* Flag indicating this compilation unit will be read in before
808 any of the current compilation units are processed. */
809 unsigned int queued
: 1;
811 /* This flag will be set when reading partial DIEs if we need to load
812 absolutely all DIEs for this compilation unit, instead of just the ones
813 we think are interesting. It gets set if we look for a DIE in the
814 hash table and don't find it. */
815 unsigned int load_all_dies
: 1;
817 /* Non-zero if this CU is from .debug_types.
818 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
820 unsigned int is_debug_types
: 1;
822 /* Non-zero if this CU is from the .dwz file. */
823 unsigned int is_dwz
: 1;
825 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
826 This flag is only valid if is_debug_types is true.
827 We can't read a CU directly from a DWO file: There are required
828 attributes in the stub. */
829 unsigned int reading_dwo_directly
: 1;
831 /* Non-zero if the TU has been read.
832 This is used to assist the "Stay in DWO Optimization" for Fission:
833 When reading a DWO, it's faster to read TUs from the DWO instead of
834 fetching them from random other DWOs (due to comdat folding).
835 If the TU has already been read, the optimization is unnecessary
836 (and unwise - we don't want to change where gdb thinks the TU lives
838 This flag is only valid if is_debug_types is true. */
839 unsigned int tu_read
: 1;
841 /* The section this CU/TU lives in.
842 If the DIE refers to a DWO file, this is always the original die,
844 struct dwarf2_section_info
*section
;
846 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
847 of the CU cache it gets reset to NULL again. This is left as NULL for
848 dummy CUs (a CU header, but nothing else). */
849 struct dwarf2_cu
*cu
;
851 /* The corresponding dwarf2_per_objfile. */
852 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
854 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
855 is active. Otherwise, the 'psymtab' field is active. */
858 /* The partial symbol table associated with this compilation unit,
859 or NULL for unread partial units. */
860 struct partial_symtab
*psymtab
;
862 /* Data needed by the "quick" functions. */
863 struct dwarf2_per_cu_quick_data
*quick
;
866 /* The CUs we import using DW_TAG_imported_unit. This is filled in
867 while reading psymtabs, used to compute the psymtab dependencies,
868 and then cleared. Then it is filled in again while reading full
869 symbols, and only deleted when the objfile is destroyed.
871 This is also used to work around a difference between the way gold
872 generates .gdb_index version <=7 and the way gdb does. Arguably this
873 is a gold bug. For symbols coming from TUs, gold records in the index
874 the CU that includes the TU instead of the TU itself. This breaks
875 dw2_lookup_symbol: It assumes that if the index says symbol X lives
876 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
877 will find X. Alas TUs live in their own symtab, so after expanding CU Y
878 we need to look in TU Z to find X. Fortunately, this is akin to
879 DW_TAG_imported_unit, so we just use the same mechanism: For
880 .gdb_index version <=7 this also records the TUs that the CU referred
881 to. Concurrently with this change gdb was modified to emit version 8
882 indices so we only pay a price for gold generated indices.
883 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
884 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
887 /* Entry in the signatured_types hash table. */
889 struct signatured_type
891 /* The "per_cu" object of this type.
892 This struct is used iff per_cu.is_debug_types.
893 N.B.: This is the first member so that it's easy to convert pointers
895 struct dwarf2_per_cu_data per_cu
;
897 /* The type's signature. */
900 /* Offset in the TU of the type's DIE, as read from the TU header.
901 If this TU is a DWO stub and the definition lives in a DWO file
902 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
903 cu_offset type_offset_in_tu
;
905 /* Offset in the section of the type's DIE.
906 If the definition lives in a DWO file, this is the offset in the
907 .debug_types.dwo section.
908 The value is zero until the actual value is known.
909 Zero is otherwise not a valid section offset. */
910 sect_offset type_offset_in_section
;
912 /* Type units are grouped by their DW_AT_stmt_list entry so that they
913 can share them. This points to the containing symtab. */
914 struct type_unit_group
*type_unit_group
;
917 The first time we encounter this type we fully read it in and install it
918 in the symbol tables. Subsequent times we only need the type. */
921 /* Containing DWO unit.
922 This field is valid iff per_cu.reading_dwo_directly. */
923 struct dwo_unit
*dwo_unit
;
926 typedef struct signatured_type
*sig_type_ptr
;
927 DEF_VEC_P (sig_type_ptr
);
929 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
930 This includes type_unit_group and quick_file_names. */
932 struct stmt_list_hash
934 /* The DWO unit this table is from or NULL if there is none. */
935 struct dwo_unit
*dwo_unit
;
937 /* Offset in .debug_line or .debug_line.dwo. */
938 sect_offset line_sect_off
;
941 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
942 an object of this type. */
944 struct type_unit_group
946 /* dwarf2read.c's main "handle" on a TU symtab.
947 To simplify things we create an artificial CU that "includes" all the
948 type units using this stmt_list so that the rest of the code still has
949 a "per_cu" handle on the symtab.
950 This PER_CU is recognized by having no section. */
951 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
952 struct dwarf2_per_cu_data per_cu
;
954 /* The TUs that share this DW_AT_stmt_list entry.
955 This is added to while parsing type units to build partial symtabs,
956 and is deleted afterwards and not used again. */
957 VEC (sig_type_ptr
) *tus
;
959 /* The compunit symtab.
960 Type units in a group needn't all be defined in the same source file,
961 so we create an essentially anonymous symtab as the compunit symtab. */
962 struct compunit_symtab
*compunit_symtab
;
964 /* The data used to construct the hash key. */
965 struct stmt_list_hash hash
;
967 /* The number of symtabs from the line header.
968 The value here must match line_header.num_file_names. */
969 unsigned int num_symtabs
;
971 /* The symbol tables for this TU (obtained from the files listed in
973 WARNING: The order of entries here must match the order of entries
974 in the line header. After the first TU using this type_unit_group, the
975 line header for the subsequent TUs is recreated from this. This is done
976 because we need to use the same symtabs for each TU using the same
977 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
978 there's no guarantee the line header doesn't have duplicate entries. */
979 struct symtab
**symtabs
;
982 /* These sections are what may appear in a (real or virtual) DWO file. */
986 struct dwarf2_section_info abbrev
;
987 struct dwarf2_section_info line
;
988 struct dwarf2_section_info loc
;
989 struct dwarf2_section_info loclists
;
990 struct dwarf2_section_info macinfo
;
991 struct dwarf2_section_info macro
;
992 struct dwarf2_section_info str
;
993 struct dwarf2_section_info str_offsets
;
994 /* In the case of a virtual DWO file, these two are unused. */
995 struct dwarf2_section_info info
;
996 VEC (dwarf2_section_info_def
) *types
;
999 /* CUs/TUs in DWP/DWO files. */
1003 /* Backlink to the containing struct dwo_file. */
1004 struct dwo_file
*dwo_file
;
1006 /* The "id" that distinguishes this CU/TU.
1007 .debug_info calls this "dwo_id", .debug_types calls this "signature".
1008 Since signatures came first, we stick with it for consistency. */
1011 /* The section this CU/TU lives in, in the DWO file. */
1012 struct dwarf2_section_info
*section
;
1014 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
1015 sect_offset sect_off
;
1016 unsigned int length
;
1018 /* For types, offset in the type's DIE of the type defined by this TU. */
1019 cu_offset type_offset_in_tu
;
1022 /* include/dwarf2.h defines the DWP section codes.
1023 It defines a max value but it doesn't define a min value, which we
1024 use for error checking, so provide one. */
1026 enum dwp_v2_section_ids
1031 /* Data for one DWO file.
1033 This includes virtual DWO files (a virtual DWO file is a DWO file as it
1034 appears in a DWP file). DWP files don't really have DWO files per se -
1035 comdat folding of types "loses" the DWO file they came from, and from
1036 a high level view DWP files appear to contain a mass of random types.
1037 However, to maintain consistency with the non-DWP case we pretend DWP
1038 files contain virtual DWO files, and we assign each TU with one virtual
1039 DWO file (generally based on the line and abbrev section offsets -
1040 a heuristic that seems to work in practice). */
1044 /* The DW_AT_GNU_dwo_name attribute.
1045 For virtual DWO files the name is constructed from the section offsets
1046 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
1047 from related CU+TUs. */
1048 const char *dwo_name
;
1050 /* The DW_AT_comp_dir attribute. */
1051 const char *comp_dir
;
1053 /* The bfd, when the file is open. Otherwise this is NULL.
1054 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
1057 /* The sections that make up this DWO file.
1058 Remember that for virtual DWO files in DWP V2, these are virtual
1059 sections (for lack of a better name). */
1060 struct dwo_sections sections
;
1062 /* The CUs in the file.
1063 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
1064 an extension to handle LLVM's Link Time Optimization output (where
1065 multiple source files may be compiled into a single object/dwo pair). */
1068 /* Table of TUs in the file.
1069 Each element is a struct dwo_unit. */
1073 /* These sections are what may appear in a DWP file. */
1077 /* These are used by both DWP version 1 and 2. */
1078 struct dwarf2_section_info str
;
1079 struct dwarf2_section_info cu_index
;
1080 struct dwarf2_section_info tu_index
;
1082 /* These are only used by DWP version 2 files.
1083 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
1084 sections are referenced by section number, and are not recorded here.
1085 In DWP version 2 there is at most one copy of all these sections, each
1086 section being (effectively) comprised of the concatenation of all of the
1087 individual sections that exist in the version 1 format.
1088 To keep the code simple we treat each of these concatenated pieces as a
1089 section itself (a virtual section?). */
1090 struct dwarf2_section_info abbrev
;
1091 struct dwarf2_section_info info
;
1092 struct dwarf2_section_info line
;
1093 struct dwarf2_section_info loc
;
1094 struct dwarf2_section_info macinfo
;
1095 struct dwarf2_section_info macro
;
1096 struct dwarf2_section_info str_offsets
;
1097 struct dwarf2_section_info types
;
1100 /* These sections are what may appear in a virtual DWO file in DWP version 1.
1101 A virtual DWO file is a DWO file as it appears in a DWP file. */
1103 struct virtual_v1_dwo_sections
1105 struct dwarf2_section_info abbrev
;
1106 struct dwarf2_section_info line
;
1107 struct dwarf2_section_info loc
;
1108 struct dwarf2_section_info macinfo
;
1109 struct dwarf2_section_info macro
;
1110 struct dwarf2_section_info str_offsets
;
1111 /* Each DWP hash table entry records one CU or one TU.
1112 That is recorded here, and copied to dwo_unit.section. */
1113 struct dwarf2_section_info info_or_types
;
1116 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
1117 In version 2, the sections of the DWO files are concatenated together
1118 and stored in one section of that name. Thus each ELF section contains
1119 several "virtual" sections. */
1121 struct virtual_v2_dwo_sections
1123 bfd_size_type abbrev_offset
;
1124 bfd_size_type abbrev_size
;
1126 bfd_size_type line_offset
;
1127 bfd_size_type line_size
;
1129 bfd_size_type loc_offset
;
1130 bfd_size_type loc_size
;
1132 bfd_size_type macinfo_offset
;
1133 bfd_size_type macinfo_size
;
1135 bfd_size_type macro_offset
;
1136 bfd_size_type macro_size
;
1138 bfd_size_type str_offsets_offset
;
1139 bfd_size_type str_offsets_size
;
1141 /* Each DWP hash table entry records one CU or one TU.
1142 That is recorded here, and copied to dwo_unit.section. */
1143 bfd_size_type info_or_types_offset
;
1144 bfd_size_type info_or_types_size
;
1147 /* Contents of DWP hash tables. */
1149 struct dwp_hash_table
1151 uint32_t version
, nr_columns
;
1152 uint32_t nr_units
, nr_slots
;
1153 const gdb_byte
*hash_table
, *unit_table
;
1158 const gdb_byte
*indices
;
1162 /* This is indexed by column number and gives the id of the section
1164 #define MAX_NR_V2_DWO_SECTIONS \
1165 (1 /* .debug_info or .debug_types */ \
1166 + 1 /* .debug_abbrev */ \
1167 + 1 /* .debug_line */ \
1168 + 1 /* .debug_loc */ \
1169 + 1 /* .debug_str_offsets */ \
1170 + 1 /* .debug_macro or .debug_macinfo */)
1171 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
1172 const gdb_byte
*offsets
;
1173 const gdb_byte
*sizes
;
1178 /* Data for one DWP file. */
1182 /* Name of the file. */
1185 /* File format version. */
1191 /* Section info for this file. */
1192 struct dwp_sections sections
;
1194 /* Table of CUs in the file. */
1195 const struct dwp_hash_table
*cus
;
1197 /* Table of TUs in the file. */
1198 const struct dwp_hash_table
*tus
;
1200 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1204 /* Table to map ELF section numbers to their sections.
1205 This is only needed for the DWP V1 file format. */
1206 unsigned int num_sections
;
1207 asection
**elf_sections
;
1210 /* This represents a '.dwz' file. */
1214 /* A dwz file can only contain a few sections. */
1215 struct dwarf2_section_info abbrev
;
1216 struct dwarf2_section_info info
;
1217 struct dwarf2_section_info str
;
1218 struct dwarf2_section_info line
;
1219 struct dwarf2_section_info macro
;
1220 struct dwarf2_section_info gdb_index
;
1221 struct dwarf2_section_info debug_names
;
1223 /* The dwz's BFD. */
1227 /* Struct used to pass misc. parameters to read_die_and_children, et
1228 al. which are used for both .debug_info and .debug_types dies.
1229 All parameters here are unchanging for the life of the call. This
1230 struct exists to abstract away the constant parameters of die reading. */
1232 struct die_reader_specs
1234 /* The bfd of die_section. */
1237 /* The CU of the DIE we are parsing. */
1238 struct dwarf2_cu
*cu
;
1240 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1241 struct dwo_file
*dwo_file
;
1243 /* The section the die comes from.
1244 This is either .debug_info or .debug_types, or the .dwo variants. */
1245 struct dwarf2_section_info
*die_section
;
1247 /* die_section->buffer. */
1248 const gdb_byte
*buffer
;
1250 /* The end of the buffer. */
1251 const gdb_byte
*buffer_end
;
1253 /* The value of the DW_AT_comp_dir attribute. */
1254 const char *comp_dir
;
1256 /* The abbreviation table to use when reading the DIEs. */
1257 struct abbrev_table
*abbrev_table
;
1260 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1261 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1262 const gdb_byte
*info_ptr
,
1263 struct die_info
*comp_unit_die
,
1267 /* A 1-based directory index. This is a strong typedef to prevent
1268 accidentally using a directory index as a 0-based index into an
1270 enum class dir_index
: unsigned int {};
1272 /* Likewise, a 1-based file name index. */
1273 enum class file_name_index
: unsigned int {};
1277 file_entry () = default;
1279 file_entry (const char *name_
, dir_index d_index_
,
1280 unsigned int mod_time_
, unsigned int length_
)
1283 mod_time (mod_time_
),
1287 /* Return the include directory at D_INDEX stored in LH. Returns
1288 NULL if D_INDEX is out of bounds. */
1289 const char *include_dir (const line_header
*lh
) const;
1291 /* The file name. Note this is an observing pointer. The memory is
1292 owned by debug_line_buffer. */
1293 const char *name
{};
1295 /* The directory index (1-based). */
1296 dir_index d_index
{};
1298 unsigned int mod_time
{};
1300 unsigned int length
{};
1302 /* True if referenced by the Line Number Program. */
1305 /* The associated symbol table, if any. */
1306 struct symtab
*symtab
{};
1309 /* The line number information for a compilation unit (found in the
1310 .debug_line section) begins with a "statement program header",
1311 which contains the following information. */
1318 /* Add an entry to the include directory table. */
1319 void add_include_dir (const char *include_dir
);
1321 /* Add an entry to the file name table. */
1322 void add_file_name (const char *name
, dir_index d_index
,
1323 unsigned int mod_time
, unsigned int length
);
1325 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1326 is out of bounds. */
1327 const char *include_dir_at (dir_index index
) const
1329 /* Convert directory index number (1-based) to vector index
1331 size_t vec_index
= to_underlying (index
) - 1;
1333 if (vec_index
>= include_dirs
.size ())
1335 return include_dirs
[vec_index
];
1338 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1339 is out of bounds. */
1340 file_entry
*file_name_at (file_name_index index
)
1342 /* Convert file name index number (1-based) to vector index
1344 size_t vec_index
= to_underlying (index
) - 1;
1346 if (vec_index
>= file_names
.size ())
1348 return &file_names
[vec_index
];
1351 /* Const version of the above. */
1352 const file_entry
*file_name_at (unsigned int index
) const
1354 if (index
>= file_names
.size ())
1356 return &file_names
[index
];
1359 /* Offset of line number information in .debug_line section. */
1360 sect_offset sect_off
{};
1362 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1363 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1365 unsigned int total_length
{};
1366 unsigned short version
{};
1367 unsigned int header_length
{};
1368 unsigned char minimum_instruction_length
{};
1369 unsigned char maximum_ops_per_instruction
{};
1370 unsigned char default_is_stmt
{};
1372 unsigned char line_range
{};
1373 unsigned char opcode_base
{};
1375 /* standard_opcode_lengths[i] is the number of operands for the
1376 standard opcode whose value is i. This means that
1377 standard_opcode_lengths[0] is unused, and the last meaningful
1378 element is standard_opcode_lengths[opcode_base - 1]. */
1379 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1381 /* The include_directories table. Note these are observing
1382 pointers. The memory is owned by debug_line_buffer. */
1383 std::vector
<const char *> include_dirs
;
1385 /* The file_names table. */
1386 std::vector
<file_entry
> file_names
;
1388 /* The start and end of the statement program following this
1389 header. These point into dwarf2_per_objfile->line_buffer. */
1390 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1393 typedef std::unique_ptr
<line_header
> line_header_up
;
1396 file_entry::include_dir (const line_header
*lh
) const
1398 return lh
->include_dir_at (d_index
);
1401 /* When we construct a partial symbol table entry we only
1402 need this much information. */
1403 struct partial_die_info
1405 /* Offset of this DIE. */
1406 sect_offset sect_off
;
1408 /* DWARF-2 tag for this DIE. */
1409 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1411 /* Assorted flags describing the data found in this DIE. */
1412 unsigned int has_children
: 1;
1413 unsigned int is_external
: 1;
1414 unsigned int is_declaration
: 1;
1415 unsigned int has_type
: 1;
1416 unsigned int has_specification
: 1;
1417 unsigned int has_pc_info
: 1;
1418 unsigned int may_be_inlined
: 1;
1420 /* This DIE has been marked DW_AT_main_subprogram. */
1421 unsigned int main_subprogram
: 1;
1423 /* Flag set if the SCOPE field of this structure has been
1425 unsigned int scope_set
: 1;
1427 /* Flag set if the DIE has a byte_size attribute. */
1428 unsigned int has_byte_size
: 1;
1430 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1431 unsigned int has_const_value
: 1;
1433 /* Flag set if any of the DIE's children are template arguments. */
1434 unsigned int has_template_arguments
: 1;
1436 /* Flag set if fixup_partial_die has been called on this die. */
1437 unsigned int fixup_called
: 1;
1439 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1440 unsigned int is_dwz
: 1;
1442 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1443 unsigned int spec_is_dwz
: 1;
1445 /* The name of this DIE. Normally the value of DW_AT_name, but
1446 sometimes a default name for unnamed DIEs. */
1449 /* The linkage name, if present. */
1450 const char *linkage_name
;
1452 /* The scope to prepend to our children. This is generally
1453 allocated on the comp_unit_obstack, so will disappear
1454 when this compilation unit leaves the cache. */
1457 /* Some data associated with the partial DIE. The tag determines
1458 which field is live. */
1461 /* The location description associated with this DIE, if any. */
1462 struct dwarf_block
*locdesc
;
1463 /* The offset of an import, for DW_TAG_imported_unit. */
1464 sect_offset sect_off
;
1467 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1471 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1472 DW_AT_sibling, if any. */
1473 /* NOTE: This member isn't strictly necessary, read_partial_die could
1474 return DW_AT_sibling values to its caller load_partial_dies. */
1475 const gdb_byte
*sibling
;
1477 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1478 DW_AT_specification (or DW_AT_abstract_origin or
1479 DW_AT_extension). */
1480 sect_offset spec_offset
;
1482 /* Pointers to this DIE's parent, first child, and next sibling,
1484 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1487 /* This data structure holds the information of an abbrev. */
1490 unsigned int number
; /* number identifying abbrev */
1491 enum dwarf_tag tag
; /* dwarf tag */
1492 unsigned short has_children
; /* boolean */
1493 unsigned short num_attrs
; /* number of attributes */
1494 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1495 struct abbrev_info
*next
; /* next in chain */
1500 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1501 ENUM_BITFIELD(dwarf_form
) form
: 16;
1503 /* It is valid only if FORM is DW_FORM_implicit_const. */
1504 LONGEST implicit_const
;
1507 /* Size of abbrev_table.abbrev_hash_table. */
1508 #define ABBREV_HASH_SIZE 121
1510 /* Top level data structure to contain an abbreviation table. */
1514 explicit abbrev_table (sect_offset off
)
1518 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1519 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1522 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1524 /* Allocate space for a struct abbrev_info object in
1526 struct abbrev_info
*alloc_abbrev ();
1528 /* Add an abbreviation to the table. */
1529 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1531 /* Look up an abbrev in the table.
1532 Returns NULL if the abbrev is not found. */
1534 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1537 /* Where the abbrev table came from.
1538 This is used as a sanity check when the table is used. */
1539 const sect_offset sect_off
;
1541 /* Storage for the abbrev table. */
1542 auto_obstack abbrev_obstack
;
1546 /* Hash table of abbrevs.
1547 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1548 It could be statically allocated, but the previous code didn't so we
1550 struct abbrev_info
**m_abbrevs
;
1553 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1555 /* Attributes have a name and a value. */
1558 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1559 ENUM_BITFIELD(dwarf_form
) form
: 15;
1561 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1562 field should be in u.str (existing only for DW_STRING) but it is kept
1563 here for better struct attribute alignment. */
1564 unsigned int string_is_canonical
: 1;
1569 struct dwarf_block
*blk
;
1578 /* This data structure holds a complete die structure. */
1581 /* DWARF-2 tag for this DIE. */
1582 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1584 /* Number of attributes */
1585 unsigned char num_attrs
;
1587 /* True if we're presently building the full type name for the
1588 type derived from this DIE. */
1589 unsigned char building_fullname
: 1;
1591 /* True if this die is in process. PR 16581. */
1592 unsigned char in_process
: 1;
1595 unsigned int abbrev
;
1597 /* Offset in .debug_info or .debug_types section. */
1598 sect_offset sect_off
;
1600 /* The dies in a compilation unit form an n-ary tree. PARENT
1601 points to this die's parent; CHILD points to the first child of
1602 this node; and all the children of a given node are chained
1603 together via their SIBLING fields. */
1604 struct die_info
*child
; /* Its first child, if any. */
1605 struct die_info
*sibling
; /* Its next sibling, if any. */
1606 struct die_info
*parent
; /* Its parent, if any. */
1608 /* An array of attributes, with NUM_ATTRS elements. There may be
1609 zero, but it's not common and zero-sized arrays are not
1610 sufficiently portable C. */
1611 struct attribute attrs
[1];
1614 /* Get at parts of an attribute structure. */
1616 #define DW_STRING(attr) ((attr)->u.str)
1617 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1618 #define DW_UNSND(attr) ((attr)->u.unsnd)
1619 #define DW_BLOCK(attr) ((attr)->u.blk)
1620 #define DW_SND(attr) ((attr)->u.snd)
1621 #define DW_ADDR(attr) ((attr)->u.addr)
1622 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1624 /* Blocks are a bunch of untyped bytes. */
1629 /* Valid only if SIZE is not zero. */
1630 const gdb_byte
*data
;
1633 #ifndef ATTR_ALLOC_CHUNK
1634 #define ATTR_ALLOC_CHUNK 4
1637 /* Allocate fields for structs, unions and enums in this size. */
1638 #ifndef DW_FIELD_ALLOC_CHUNK
1639 #define DW_FIELD_ALLOC_CHUNK 4
1642 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1643 but this would require a corresponding change in unpack_field_as_long
1645 static int bits_per_byte
= 8;
1649 struct nextfield
*next
;
1657 struct nextfnfield
*next
;
1658 struct fn_field fnfield
;
1665 struct nextfnfield
*head
;
1668 struct decl_field_list
1670 struct decl_field field
;
1671 struct decl_field_list
*next
;
1674 /* The routines that read and process dies for a C struct or C++ class
1675 pass lists of data member fields and lists of member function fields
1676 in an instance of a field_info structure, as defined below. */
1679 /* List of data member and baseclasses fields. */
1680 struct nextfield
*fields
, *baseclasses
;
1682 /* Number of fields (including baseclasses). */
1685 /* Number of baseclasses. */
1688 /* Set if the accesibility of one of the fields is not public. */
1689 int non_public_fields
;
1691 /* Member function fieldlist array, contains name of possibly overloaded
1692 member function, number of overloaded member functions and a pointer
1693 to the head of the member function field chain. */
1694 struct fnfieldlist
*fnfieldlists
;
1696 /* Number of entries in the fnfieldlists array. */
1699 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1700 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1701 struct decl_field_list
*typedef_field_list
;
1702 unsigned typedef_field_list_count
;
1704 /* Nested types defined by this class and the number of elements in this
1706 struct decl_field_list
*nested_types_list
;
1707 unsigned nested_types_list_count
;
1710 /* One item on the queue of compilation units to read in full symbols
1712 struct dwarf2_queue_item
1714 struct dwarf2_per_cu_data
*per_cu
;
1715 enum language pretend_language
;
1716 struct dwarf2_queue_item
*next
;
1719 /* The current queue. */
1720 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1722 /* Loaded secondary compilation units are kept in memory until they
1723 have not been referenced for the processing of this many
1724 compilation units. Set this to zero to disable caching. Cache
1725 sizes of up to at least twenty will improve startup time for
1726 typical inter-CU-reference binaries, at an obvious memory cost. */
1727 static int dwarf_max_cache_age
= 5;
1729 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1730 struct cmd_list_element
*c
, const char *value
)
1732 fprintf_filtered (file
, _("The upper bound on the age of cached "
1733 "DWARF compilation units is %s.\n"),
1737 /* local function prototypes */
1739 static const char *get_section_name (const struct dwarf2_section_info
*);
1741 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1743 static void dwarf2_find_base_address (struct die_info
*die
,
1744 struct dwarf2_cu
*cu
);
1746 static struct partial_symtab
*create_partial_symtab
1747 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1749 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1750 const gdb_byte
*info_ptr
,
1751 struct die_info
*type_unit_die
,
1752 int has_children
, void *data
);
1754 static void dwarf2_build_psymtabs_hard
1755 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1757 static void scan_partial_symbols (struct partial_die_info
*,
1758 CORE_ADDR
*, CORE_ADDR
*,
1759 int, struct dwarf2_cu
*);
1761 static void add_partial_symbol (struct partial_die_info
*,
1762 struct dwarf2_cu
*);
1764 static void add_partial_namespace (struct partial_die_info
*pdi
,
1765 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1766 int set_addrmap
, struct dwarf2_cu
*cu
);
1768 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1769 CORE_ADDR
*highpc
, int set_addrmap
,
1770 struct dwarf2_cu
*cu
);
1772 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1773 struct dwarf2_cu
*cu
);
1775 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1776 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1777 int need_pc
, struct dwarf2_cu
*cu
);
1779 static void dwarf2_read_symtab (struct partial_symtab
*,
1782 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1784 static abbrev_table_up abbrev_table_read_table
1785 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1788 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1790 static struct partial_die_info
*load_partial_dies
1791 (const struct die_reader_specs
*, const gdb_byte
*, int);
1793 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1794 struct partial_die_info
*,
1795 struct abbrev_info
*,
1799 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1800 struct dwarf2_cu
*);
1802 static void fixup_partial_die (struct partial_die_info
*,
1803 struct dwarf2_cu
*);
1805 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1806 struct attribute
*, struct attr_abbrev
*,
1809 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1811 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1813 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1815 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1817 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1819 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1822 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1824 static LONGEST read_checked_initial_length_and_offset
1825 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1826 unsigned int *, unsigned int *);
1828 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1829 const struct comp_unit_head
*,
1832 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1834 static sect_offset read_abbrev_offset
1835 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1836 struct dwarf2_section_info
*, sect_offset
);
1838 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1840 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1842 static const char *read_indirect_string
1843 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1844 const struct comp_unit_head
*, unsigned int *);
1846 static const char *read_indirect_line_string
1847 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1848 const struct comp_unit_head
*, unsigned int *);
1850 static const char *read_indirect_string_at_offset
1851 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1852 LONGEST str_offset
);
1854 static const char *read_indirect_string_from_dwz
1855 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1857 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1859 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1863 static const char *read_str_index (const struct die_reader_specs
*reader
,
1864 ULONGEST str_index
);
1866 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1868 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1869 struct dwarf2_cu
*);
1871 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1874 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1875 struct dwarf2_cu
*cu
);
1877 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1878 struct dwarf2_cu
*cu
);
1880 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1882 static struct die_info
*die_specification (struct die_info
*die
,
1883 struct dwarf2_cu
**);
1885 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1886 struct dwarf2_cu
*cu
);
1888 static void dwarf_decode_lines (struct line_header
*, const char *,
1889 struct dwarf2_cu
*, struct partial_symtab
*,
1890 CORE_ADDR
, int decode_mapping
);
1892 static void dwarf2_start_subfile (const char *, const char *);
1894 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1895 const char *, const char *,
1898 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1899 struct dwarf2_cu
*, struct symbol
* = NULL
);
1901 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1902 struct dwarf2_cu
*);
1904 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1907 struct obstack
*obstack
,
1908 struct dwarf2_cu
*cu
, LONGEST
*value
,
1909 const gdb_byte
**bytes
,
1910 struct dwarf2_locexpr_baton
**baton
);
1912 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1914 static int need_gnat_info (struct dwarf2_cu
*);
1916 static struct type
*die_descriptive_type (struct die_info
*,
1917 struct dwarf2_cu
*);
1919 static void set_descriptive_type (struct type
*, struct die_info
*,
1920 struct dwarf2_cu
*);
1922 static struct type
*die_containing_type (struct die_info
*,
1923 struct dwarf2_cu
*);
1925 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1926 struct dwarf2_cu
*);
1928 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1930 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1932 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1934 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1935 const char *suffix
, int physname
,
1936 struct dwarf2_cu
*cu
);
1938 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1940 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1942 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1944 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1946 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1948 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1950 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1951 struct dwarf2_cu
*, struct partial_symtab
*);
1953 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1954 values. Keep the items ordered with increasing constraints compliance. */
1957 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1958 PC_BOUNDS_NOT_PRESENT
,
1960 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1961 were present but they do not form a valid range of PC addresses. */
1964 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1967 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1971 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1972 CORE_ADDR
*, CORE_ADDR
*,
1974 struct partial_symtab
*);
1976 static void get_scope_pc_bounds (struct die_info
*,
1977 CORE_ADDR
*, CORE_ADDR
*,
1978 struct dwarf2_cu
*);
1980 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1981 CORE_ADDR
, struct dwarf2_cu
*);
1983 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1984 struct dwarf2_cu
*);
1986 static void dwarf2_attach_fields_to_type (struct field_info
*,
1987 struct type
*, struct dwarf2_cu
*);
1989 static void dwarf2_add_member_fn (struct field_info
*,
1990 struct die_info
*, struct type
*,
1991 struct dwarf2_cu
*);
1993 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1995 struct dwarf2_cu
*);
1997 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1999 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
2001 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
2003 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
2005 static struct using_direct
**using_directives (enum language
);
2007 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
2009 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
2011 static struct type
*read_module_type (struct die_info
*die
,
2012 struct dwarf2_cu
*cu
);
2014 static const char *namespace_name (struct die_info
*die
,
2015 int *is_anonymous
, struct dwarf2_cu
*);
2017 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
2019 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
2021 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
2022 struct dwarf2_cu
*);
2024 static struct die_info
*read_die_and_siblings_1
2025 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
2028 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
2029 const gdb_byte
*info_ptr
,
2030 const gdb_byte
**new_info_ptr
,
2031 struct die_info
*parent
);
2033 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
2034 struct die_info
**, const gdb_byte
*,
2037 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
2038 struct die_info
**, const gdb_byte
*,
2041 static void process_die (struct die_info
*, struct dwarf2_cu
*);
2043 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
2046 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
2048 static const char *dwarf2_full_name (const char *name
,
2049 struct die_info
*die
,
2050 struct dwarf2_cu
*cu
);
2052 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
2053 struct dwarf2_cu
*cu
);
2055 static struct die_info
*dwarf2_extension (struct die_info
*die
,
2056 struct dwarf2_cu
**);
2058 static const char *dwarf_tag_name (unsigned int);
2060 static const char *dwarf_attr_name (unsigned int);
2062 static const char *dwarf_form_name (unsigned int);
2064 static const char *dwarf_bool_name (unsigned int);
2066 static const char *dwarf_type_encoding_name (unsigned int);
2068 static struct die_info
*sibling_die (struct die_info
*);
2070 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
2072 static void dump_die_for_error (struct die_info
*);
2074 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
2077 /*static*/ void dump_die (struct die_info
*, int max_level
);
2079 static void store_in_ref_table (struct die_info
*,
2080 struct dwarf2_cu
*);
2082 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
2084 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
2086 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
2087 const struct attribute
*,
2088 struct dwarf2_cu
**);
2090 static struct die_info
*follow_die_ref (struct die_info
*,
2091 const struct attribute
*,
2092 struct dwarf2_cu
**);
2094 static struct die_info
*follow_die_sig (struct die_info
*,
2095 const struct attribute
*,
2096 struct dwarf2_cu
**);
2098 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
2099 struct dwarf2_cu
*);
2101 static struct type
*get_DW_AT_signature_type (struct die_info
*,
2102 const struct attribute
*,
2103 struct dwarf2_cu
*);
2105 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
2107 static void read_signatured_type (struct signatured_type
*);
2109 static int attr_to_dynamic_prop (const struct attribute
*attr
,
2110 struct die_info
*die
, struct dwarf2_cu
*cu
,
2111 struct dynamic_prop
*prop
);
2113 /* memory allocation interface */
2115 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
2117 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
2119 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
2121 static int attr_form_is_block (const struct attribute
*);
2123 static int attr_form_is_section_offset (const struct attribute
*);
2125 static int attr_form_is_constant (const struct attribute
*);
2127 static int attr_form_is_ref (const struct attribute
*);
2129 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
2130 struct dwarf2_loclist_baton
*baton
,
2131 const struct attribute
*attr
);
2133 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
2135 struct dwarf2_cu
*cu
,
2138 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
2139 const gdb_byte
*info_ptr
,
2140 struct abbrev_info
*abbrev
);
2142 static hashval_t
partial_die_hash (const void *item
);
2144 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
2146 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
2147 (sect_offset sect_off
, unsigned int offset_in_dwz
,
2148 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2150 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
2151 struct die_info
*comp_unit_die
,
2152 enum language pretend_language
);
2154 static void free_cached_comp_units (void *);
2156 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2158 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
2160 static struct type
*set_die_type (struct die_info
*, struct type
*,
2161 struct dwarf2_cu
*);
2163 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2165 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2167 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
2170 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
2173 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
2176 static void dwarf2_add_dependence (struct dwarf2_cu
*,
2177 struct dwarf2_per_cu_data
*);
2179 static void dwarf2_mark (struct dwarf2_cu
*);
2181 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
2183 static struct type
*get_die_type_at_offset (sect_offset
,
2184 struct dwarf2_per_cu_data
*);
2186 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
2188 static void dwarf2_release_queue (void *dummy
);
2190 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
2191 enum language pretend_language
);
2193 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2195 /* The return type of find_file_and_directory. Note, the enclosed
2196 string pointers are only valid while this object is valid. */
2198 struct file_and_directory
2200 /* The filename. This is never NULL. */
2203 /* The compilation directory. NULL if not known. If we needed to
2204 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2205 points directly to the DW_AT_comp_dir string attribute owned by
2206 the obstack that owns the DIE. */
2207 const char *comp_dir
;
2209 /* If we needed to build a new string for comp_dir, this is what
2210 owns the storage. */
2211 std::string comp_dir_storage
;
2214 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2215 struct dwarf2_cu
*cu
);
2217 static char *file_full_name (int file
, struct line_header
*lh
,
2218 const char *comp_dir
);
2220 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2221 enum class rcuh_kind
{ COMPILE
, TYPE
};
2223 static const gdb_byte
*read_and_check_comp_unit_head
2224 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2225 struct comp_unit_head
*header
,
2226 struct dwarf2_section_info
*section
,
2227 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2228 rcuh_kind section_kind
);
2230 static void init_cutu_and_read_dies
2231 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2232 int use_existing_cu
, int keep
,
2233 die_reader_func_ftype
*die_reader_func
, void *data
);
2235 static void init_cutu_and_read_dies_simple
2236 (struct dwarf2_per_cu_data
*this_cu
,
2237 die_reader_func_ftype
*die_reader_func
, void *data
);
2239 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2241 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2243 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2244 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2245 struct dwp_file
*dwp_file
, const char *comp_dir
,
2246 ULONGEST signature
, int is_debug_types
);
2248 static struct dwp_file
*get_dwp_file
2249 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2251 static struct dwo_unit
*lookup_dwo_comp_unit
2252 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2254 static struct dwo_unit
*lookup_dwo_type_unit
2255 (struct signatured_type
*, const char *, const char *);
2257 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2259 static void free_dwo_file_cleanup (void *);
2261 struct free_dwo_file_cleanup_data
2263 struct dwo_file
*dwo_file
;
2264 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
2267 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2269 static void check_producer (struct dwarf2_cu
*cu
);
2271 static void free_line_header_voidp (void *arg
);
2273 /* Various complaints about symbol reading that don't abort the process. */
2276 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2278 complaint (&symfile_complaints
,
2279 _("statement list doesn't fit in .debug_line section"));
2283 dwarf2_debug_line_missing_file_complaint (void)
2285 complaint (&symfile_complaints
,
2286 _(".debug_line section has line data without a file"));
2290 dwarf2_debug_line_missing_end_sequence_complaint (void)
2292 complaint (&symfile_complaints
,
2293 _(".debug_line section has line "
2294 "program sequence without an end"));
2298 dwarf2_complex_location_expr_complaint (void)
2300 complaint (&symfile_complaints
, _("location expression too complex"));
2304 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2307 complaint (&symfile_complaints
,
2308 _("const value length mismatch for '%s', got %d, expected %d"),
2313 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2315 complaint (&symfile_complaints
,
2316 _("debug info runs off end of %s section"
2318 get_section_name (section
),
2319 get_section_file_name (section
));
2323 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2325 complaint (&symfile_complaints
,
2326 _("macro debug info contains a "
2327 "malformed macro definition:\n`%s'"),
2332 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2334 complaint (&symfile_complaints
,
2335 _("invalid attribute class or form for '%s' in '%s'"),
2339 /* Hash function for line_header_hash. */
2342 line_header_hash (const struct line_header
*ofs
)
2344 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2347 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2350 line_header_hash_voidp (const void *item
)
2352 const struct line_header
*ofs
= (const struct line_header
*) item
;
2354 return line_header_hash (ofs
);
2357 /* Equality function for line_header_hash. */
2360 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2362 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2363 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2365 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2366 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2371 /* Read the given attribute value as an address, taking the attribute's
2372 form into account. */
2375 attr_value_as_address (struct attribute
*attr
)
2379 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2381 /* Aside from a few clearly defined exceptions, attributes that
2382 contain an address must always be in DW_FORM_addr form.
2383 Unfortunately, some compilers happen to be violating this
2384 requirement by encoding addresses using other forms, such
2385 as DW_FORM_data4 for example. For those broken compilers,
2386 we try to do our best, without any guarantee of success,
2387 to interpret the address correctly. It would also be nice
2388 to generate a complaint, but that would require us to maintain
2389 a list of legitimate cases where a non-address form is allowed,
2390 as well as update callers to pass in at least the CU's DWARF
2391 version. This is more overhead than what we're willing to
2392 expand for a pretty rare case. */
2393 addr
= DW_UNSND (attr
);
2396 addr
= DW_ADDR (attr
);
2401 /* The suffix for an index file. */
2402 #define INDEX4_SUFFIX ".gdb-index"
2403 #define INDEX5_SUFFIX ".debug_names"
2404 #define DEBUG_STR_SUFFIX ".debug_str"
2406 /* See declaration. */
2408 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2409 const dwarf2_debug_sections
*names
)
2410 : objfile (objfile_
)
2413 names
= &dwarf2_elf_names
;
2415 bfd
*obfd
= objfile
->obfd
;
2417 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2418 locate_sections (obfd
, sec
, *names
);
2421 dwarf2_per_objfile::~dwarf2_per_objfile ()
2423 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2424 free_cached_comp_units ();
2426 if (quick_file_names_table
)
2427 htab_delete (quick_file_names_table
);
2429 if (line_header_hash
)
2430 htab_delete (line_header_hash
);
2432 /* Everything else should be on the objfile obstack. */
2435 /* See declaration. */
2438 dwarf2_per_objfile::free_cached_comp_units ()
2440 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2441 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2442 while (per_cu
!= NULL
)
2444 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2447 *last_chain
= next_cu
;
2452 /* Try to locate the sections we need for DWARF 2 debugging
2453 information and return true if we have enough to do something.
2454 NAMES points to the dwarf2 section names, or is NULL if the standard
2455 ELF names are used. */
2458 dwarf2_has_info (struct objfile
*objfile
,
2459 const struct dwarf2_debug_sections
*names
)
2461 if (objfile
->flags
& OBJF_READNEVER
)
2464 struct dwarf2_per_objfile
*dwarf2_per_objfile
2465 = get_dwarf2_per_objfile (objfile
);
2467 if (dwarf2_per_objfile
== NULL
)
2469 /* Initialize per-objfile state. */
2470 struct dwarf2_per_objfile
*data
2471 = XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_per_objfile
);
2473 dwarf2_per_objfile
= new (data
) struct dwarf2_per_objfile (objfile
, names
);
2474 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2476 return (!dwarf2_per_objfile
->info
.is_virtual
2477 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2478 && !dwarf2_per_objfile
->abbrev
.is_virtual
2479 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2482 /* Return the containing section of virtual section SECTION. */
2484 static struct dwarf2_section_info
*
2485 get_containing_section (const struct dwarf2_section_info
*section
)
2487 gdb_assert (section
->is_virtual
);
2488 return section
->s
.containing_section
;
2491 /* Return the bfd owner of SECTION. */
2494 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2496 if (section
->is_virtual
)
2498 section
= get_containing_section (section
);
2499 gdb_assert (!section
->is_virtual
);
2501 return section
->s
.section
->owner
;
2504 /* Return the bfd section of SECTION.
2505 Returns NULL if the section is not present. */
2508 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2510 if (section
->is_virtual
)
2512 section
= get_containing_section (section
);
2513 gdb_assert (!section
->is_virtual
);
2515 return section
->s
.section
;
2518 /* Return the name of SECTION. */
2521 get_section_name (const struct dwarf2_section_info
*section
)
2523 asection
*sectp
= get_section_bfd_section (section
);
2525 gdb_assert (sectp
!= NULL
);
2526 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2529 /* Return the name of the file SECTION is in. */
2532 get_section_file_name (const struct dwarf2_section_info
*section
)
2534 bfd
*abfd
= get_section_bfd_owner (section
);
2536 return bfd_get_filename (abfd
);
2539 /* Return the id of SECTION.
2540 Returns 0 if SECTION doesn't exist. */
2543 get_section_id (const struct dwarf2_section_info
*section
)
2545 asection
*sectp
= get_section_bfd_section (section
);
2552 /* Return the flags of SECTION.
2553 SECTION (or containing section if this is a virtual section) must exist. */
2556 get_section_flags (const struct dwarf2_section_info
*section
)
2558 asection
*sectp
= get_section_bfd_section (section
);
2560 gdb_assert (sectp
!= NULL
);
2561 return bfd_get_section_flags (sectp
->owner
, sectp
);
2564 /* When loading sections, we look either for uncompressed section or for
2565 compressed section names. */
2568 section_is_p (const char *section_name
,
2569 const struct dwarf2_section_names
*names
)
2571 if (names
->normal
!= NULL
2572 && strcmp (section_name
, names
->normal
) == 0)
2574 if (names
->compressed
!= NULL
2575 && strcmp (section_name
, names
->compressed
) == 0)
2580 /* See declaration. */
2583 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2584 const dwarf2_debug_sections
&names
)
2586 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2588 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2591 else if (section_is_p (sectp
->name
, &names
.info
))
2593 this->info
.s
.section
= sectp
;
2594 this->info
.size
= bfd_get_section_size (sectp
);
2596 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2598 this->abbrev
.s
.section
= sectp
;
2599 this->abbrev
.size
= bfd_get_section_size (sectp
);
2601 else if (section_is_p (sectp
->name
, &names
.line
))
2603 this->line
.s
.section
= sectp
;
2604 this->line
.size
= bfd_get_section_size (sectp
);
2606 else if (section_is_p (sectp
->name
, &names
.loc
))
2608 this->loc
.s
.section
= sectp
;
2609 this->loc
.size
= bfd_get_section_size (sectp
);
2611 else if (section_is_p (sectp
->name
, &names
.loclists
))
2613 this->loclists
.s
.section
= sectp
;
2614 this->loclists
.size
= bfd_get_section_size (sectp
);
2616 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2618 this->macinfo
.s
.section
= sectp
;
2619 this->macinfo
.size
= bfd_get_section_size (sectp
);
2621 else if (section_is_p (sectp
->name
, &names
.macro
))
2623 this->macro
.s
.section
= sectp
;
2624 this->macro
.size
= bfd_get_section_size (sectp
);
2626 else if (section_is_p (sectp
->name
, &names
.str
))
2628 this->str
.s
.section
= sectp
;
2629 this->str
.size
= bfd_get_section_size (sectp
);
2631 else if (section_is_p (sectp
->name
, &names
.line_str
))
2633 this->line_str
.s
.section
= sectp
;
2634 this->line_str
.size
= bfd_get_section_size (sectp
);
2636 else if (section_is_p (sectp
->name
, &names
.addr
))
2638 this->addr
.s
.section
= sectp
;
2639 this->addr
.size
= bfd_get_section_size (sectp
);
2641 else if (section_is_p (sectp
->name
, &names
.frame
))
2643 this->frame
.s
.section
= sectp
;
2644 this->frame
.size
= bfd_get_section_size (sectp
);
2646 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2648 this->eh_frame
.s
.section
= sectp
;
2649 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2651 else if (section_is_p (sectp
->name
, &names
.ranges
))
2653 this->ranges
.s
.section
= sectp
;
2654 this->ranges
.size
= bfd_get_section_size (sectp
);
2656 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2658 this->rnglists
.s
.section
= sectp
;
2659 this->rnglists
.size
= bfd_get_section_size (sectp
);
2661 else if (section_is_p (sectp
->name
, &names
.types
))
2663 struct dwarf2_section_info type_section
;
2665 memset (&type_section
, 0, sizeof (type_section
));
2666 type_section
.s
.section
= sectp
;
2667 type_section
.size
= bfd_get_section_size (sectp
);
2669 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2672 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2674 this->gdb_index
.s
.section
= sectp
;
2675 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2677 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2679 this->debug_names
.s
.section
= sectp
;
2680 this->debug_names
.size
= bfd_get_section_size (sectp
);
2682 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2684 this->debug_aranges
.s
.section
= sectp
;
2685 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2688 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2689 && bfd_section_vma (abfd
, sectp
) == 0)
2690 this->has_section_at_zero
= true;
2693 /* A helper function that decides whether a section is empty,
2697 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2699 if (section
->is_virtual
)
2700 return section
->size
== 0;
2701 return section
->s
.section
== NULL
|| section
->size
== 0;
2704 /* Read the contents of the section INFO.
2705 OBJFILE is the main object file, but not necessarily the file where
2706 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2708 If the section is compressed, uncompress it before returning. */
2711 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2715 gdb_byte
*buf
, *retbuf
;
2719 info
->buffer
= NULL
;
2722 if (dwarf2_section_empty_p (info
))
2725 sectp
= get_section_bfd_section (info
);
2727 /* If this is a virtual section we need to read in the real one first. */
2728 if (info
->is_virtual
)
2730 struct dwarf2_section_info
*containing_section
=
2731 get_containing_section (info
);
2733 gdb_assert (sectp
!= NULL
);
2734 if ((sectp
->flags
& SEC_RELOC
) != 0)
2736 error (_("Dwarf Error: DWP format V2 with relocations is not"
2737 " supported in section %s [in module %s]"),
2738 get_section_name (info
), get_section_file_name (info
));
2740 dwarf2_read_section (objfile
, containing_section
);
2741 /* Other code should have already caught virtual sections that don't
2743 gdb_assert (info
->virtual_offset
+ info
->size
2744 <= containing_section
->size
);
2745 /* If the real section is empty or there was a problem reading the
2746 section we shouldn't get here. */
2747 gdb_assert (containing_section
->buffer
!= NULL
);
2748 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2752 /* If the section has relocations, we must read it ourselves.
2753 Otherwise we attach it to the BFD. */
2754 if ((sectp
->flags
& SEC_RELOC
) == 0)
2756 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2760 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2763 /* When debugging .o files, we may need to apply relocations; see
2764 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2765 We never compress sections in .o files, so we only need to
2766 try this when the section is not compressed. */
2767 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2770 info
->buffer
= retbuf
;
2774 abfd
= get_section_bfd_owner (info
);
2775 gdb_assert (abfd
!= NULL
);
2777 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2778 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2780 error (_("Dwarf Error: Can't read DWARF data"
2781 " in section %s [in module %s]"),
2782 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2786 /* A helper function that returns the size of a section in a safe way.
2787 If you are positive that the section has been read before using the
2788 size, then it is safe to refer to the dwarf2_section_info object's
2789 "size" field directly. In other cases, you must call this
2790 function, because for compressed sections the size field is not set
2791 correctly until the section has been read. */
2793 static bfd_size_type
2794 dwarf2_section_size (struct objfile
*objfile
,
2795 struct dwarf2_section_info
*info
)
2798 dwarf2_read_section (objfile
, info
);
2802 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2806 dwarf2_get_section_info (struct objfile
*objfile
,
2807 enum dwarf2_section_enum sect
,
2808 asection
**sectp
, const gdb_byte
**bufp
,
2809 bfd_size_type
*sizep
)
2811 struct dwarf2_per_objfile
*data
2812 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2813 dwarf2_objfile_data_key
);
2814 struct dwarf2_section_info
*info
;
2816 /* We may see an objfile without any DWARF, in which case we just
2827 case DWARF2_DEBUG_FRAME
:
2828 info
= &data
->frame
;
2830 case DWARF2_EH_FRAME
:
2831 info
= &data
->eh_frame
;
2834 gdb_assert_not_reached ("unexpected section");
2837 dwarf2_read_section (objfile
, info
);
2839 *sectp
= get_section_bfd_section (info
);
2840 *bufp
= info
->buffer
;
2841 *sizep
= info
->size
;
2844 /* A helper function to find the sections for a .dwz file. */
2847 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2849 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2851 /* Note that we only support the standard ELF names, because .dwz
2852 is ELF-only (at the time of writing). */
2853 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2855 dwz_file
->abbrev
.s
.section
= sectp
;
2856 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2858 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2860 dwz_file
->info
.s
.section
= sectp
;
2861 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2863 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2865 dwz_file
->str
.s
.section
= sectp
;
2866 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2868 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2870 dwz_file
->line
.s
.section
= sectp
;
2871 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2873 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2875 dwz_file
->macro
.s
.section
= sectp
;
2876 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2878 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2880 dwz_file
->gdb_index
.s
.section
= sectp
;
2881 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2883 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2885 dwz_file
->debug_names
.s
.section
= sectp
;
2886 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2890 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2891 there is no .gnu_debugaltlink section in the file. Error if there
2892 is such a section but the file cannot be found. */
2894 static struct dwz_file
*
2895 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2897 const char *filename
;
2898 struct dwz_file
*result
;
2899 bfd_size_type buildid_len_arg
;
2903 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2904 return dwarf2_per_objfile
->dwz_file
;
2906 bfd_set_error (bfd_error_no_error
);
2907 gdb::unique_xmalloc_ptr
<char> data
2908 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2909 &buildid_len_arg
, &buildid
));
2912 if (bfd_get_error () == bfd_error_no_error
)
2914 error (_("could not read '.gnu_debugaltlink' section: %s"),
2915 bfd_errmsg (bfd_get_error ()));
2918 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2920 buildid_len
= (size_t) buildid_len_arg
;
2922 filename
= data
.get ();
2924 std::string abs_storage
;
2925 if (!IS_ABSOLUTE_PATH (filename
))
2927 gdb::unique_xmalloc_ptr
<char> abs
2928 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2930 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2931 filename
= abs_storage
.c_str ();
2934 /* First try the file name given in the section. If that doesn't
2935 work, try to use the build-id instead. */
2936 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2937 if (dwz_bfd
!= NULL
)
2939 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2943 if (dwz_bfd
== NULL
)
2944 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2946 if (dwz_bfd
== NULL
)
2947 error (_("could not find '.gnu_debugaltlink' file for %s"),
2948 objfile_name (dwarf2_per_objfile
->objfile
));
2950 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
2952 result
->dwz_bfd
= dwz_bfd
.release ();
2954 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
2956 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
2957 dwarf2_per_objfile
->dwz_file
= result
;
2961 /* DWARF quick_symbols_functions support. */
2963 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2964 unique line tables, so we maintain a separate table of all .debug_line
2965 derived entries to support the sharing.
2966 All the quick functions need is the list of file names. We discard the
2967 line_header when we're done and don't need to record it here. */
2968 struct quick_file_names
2970 /* The data used to construct the hash key. */
2971 struct stmt_list_hash hash
;
2973 /* The number of entries in file_names, real_names. */
2974 unsigned int num_file_names
;
2976 /* The file names from the line table, after being run through
2978 const char **file_names
;
2980 /* The file names from the line table after being run through
2981 gdb_realpath. These are computed lazily. */
2982 const char **real_names
;
2985 /* When using the index (and thus not using psymtabs), each CU has an
2986 object of this type. This is used to hold information needed by
2987 the various "quick" methods. */
2988 struct dwarf2_per_cu_quick_data
2990 /* The file table. This can be NULL if there was no file table
2991 or it's currently not read in.
2992 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2993 struct quick_file_names
*file_names
;
2995 /* The corresponding symbol table. This is NULL if symbols for this
2996 CU have not yet been read. */
2997 struct compunit_symtab
*compunit_symtab
;
2999 /* A temporary mark bit used when iterating over all CUs in
3000 expand_symtabs_matching. */
3001 unsigned int mark
: 1;
3003 /* True if we've tried to read the file table and found there isn't one.
3004 There will be no point in trying to read it again next time. */
3005 unsigned int no_file_data
: 1;
3008 /* Utility hash function for a stmt_list_hash. */
3011 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
3015 if (stmt_list_hash
->dwo_unit
!= NULL
)
3016 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
3017 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
3021 /* Utility equality function for a stmt_list_hash. */
3024 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
3025 const struct stmt_list_hash
*rhs
)
3027 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
3029 if (lhs
->dwo_unit
!= NULL
3030 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
3033 return lhs
->line_sect_off
== rhs
->line_sect_off
;
3036 /* Hash function for a quick_file_names. */
3039 hash_file_name_entry (const void *e
)
3041 const struct quick_file_names
*file_data
3042 = (const struct quick_file_names
*) e
;
3044 return hash_stmt_list_entry (&file_data
->hash
);
3047 /* Equality function for a quick_file_names. */
3050 eq_file_name_entry (const void *a
, const void *b
)
3052 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
3053 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
3055 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
3058 /* Delete function for a quick_file_names. */
3061 delete_file_name_entry (void *e
)
3063 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
3066 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3068 xfree ((void*) file_data
->file_names
[i
]);
3069 if (file_data
->real_names
)
3070 xfree ((void*) file_data
->real_names
[i
]);
3073 /* The space for the struct itself lives on objfile_obstack,
3074 so we don't free it here. */
3077 /* Create a quick_file_names hash table. */
3080 create_quick_file_names_table (unsigned int nr_initial_entries
)
3082 return htab_create_alloc (nr_initial_entries
,
3083 hash_file_name_entry
, eq_file_name_entry
,
3084 delete_file_name_entry
, xcalloc
, xfree
);
3087 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
3088 have to be created afterwards. You should call age_cached_comp_units after
3089 processing PER_CU->CU. dw2_setup must have been already called. */
3092 load_cu (struct dwarf2_per_cu_data
*per_cu
)
3094 if (per_cu
->is_debug_types
)
3095 load_full_type_unit (per_cu
);
3097 load_full_comp_unit (per_cu
, language_minimal
);
3099 if (per_cu
->cu
== NULL
)
3100 return; /* Dummy CU. */
3102 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
3105 /* Read in the symbols for PER_CU. */
3108 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3110 struct cleanup
*back_to
;
3111 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3113 /* Skip type_unit_groups, reading the type units they contain
3114 is handled elsewhere. */
3115 if (IS_TYPE_UNIT_GROUP (per_cu
))
3118 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
3120 if (dwarf2_per_objfile
->using_index
3121 ? per_cu
->v
.quick
->compunit_symtab
== NULL
3122 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
3124 queue_comp_unit (per_cu
, language_minimal
);
3127 /* If we just loaded a CU from a DWO, and we're working with an index
3128 that may badly handle TUs, load all the TUs in that DWO as well.
3129 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
3130 if (!per_cu
->is_debug_types
3131 && per_cu
->cu
!= NULL
3132 && per_cu
->cu
->dwo_unit
!= NULL
3133 && dwarf2_per_objfile
->index_table
!= NULL
3134 && dwarf2_per_objfile
->index_table
->version
<= 7
3135 /* DWP files aren't supported yet. */
3136 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
3137 queue_and_load_all_dwo_tus (per_cu
);
3140 process_queue (dwarf2_per_objfile
);
3142 /* Age the cache, releasing compilation units that have not
3143 been used recently. */
3144 age_cached_comp_units (dwarf2_per_objfile
);
3146 do_cleanups (back_to
);
3149 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
3150 the objfile from which this CU came. Returns the resulting symbol
3153 static struct compunit_symtab
*
3154 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3156 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3158 gdb_assert (dwarf2_per_objfile
->using_index
);
3159 if (!per_cu
->v
.quick
->compunit_symtab
)
3161 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
,
3162 dwarf2_per_objfile
);
3163 scoped_restore decrementer
= increment_reading_symtab ();
3164 dw2_do_instantiate_symtab (per_cu
);
3165 process_cu_includes (dwarf2_per_objfile
);
3166 do_cleanups (back_to
);
3169 return per_cu
->v
.quick
->compunit_symtab
;
3172 /* Return the CU/TU given its index.
3174 This is intended for loops like:
3176 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3177 + dwarf2_per_objfile->n_type_units); ++i)
3179 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
3185 static struct dwarf2_per_cu_data
*
3186 dw2_get_cutu (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3189 if (index
>= dwarf2_per_objfile
->n_comp_units
)
3191 index
-= dwarf2_per_objfile
->n_comp_units
;
3192 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
3193 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
3196 return dwarf2_per_objfile
->all_comp_units
[index
];
3199 /* Return the CU given its index.
3200 This differs from dw2_get_cutu in that it's for when you know INDEX
3203 static struct dwarf2_per_cu_data
*
3204 dw2_get_cu (struct dwarf2_per_objfile
*dwarf2_per_objfile
, int index
)
3206 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
3208 return dwarf2_per_objfile
->all_comp_units
[index
];
3211 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3212 objfile_obstack, and constructed with the specified field
3215 static dwarf2_per_cu_data
*
3216 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3217 struct dwarf2_section_info
*section
,
3219 sect_offset sect_off
, ULONGEST length
)
3221 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3222 dwarf2_per_cu_data
*the_cu
3223 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3224 struct dwarf2_per_cu_data
);
3225 the_cu
->sect_off
= sect_off
;
3226 the_cu
->length
= length
;
3227 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3228 the_cu
->section
= section
;
3229 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3230 struct dwarf2_per_cu_quick_data
);
3231 the_cu
->is_dwz
= is_dwz
;
3235 /* A helper for create_cus_from_index that handles a given list of
3239 create_cus_from_index_list (struct objfile
*objfile
,
3240 const gdb_byte
*cu_list
, offset_type n_elements
,
3241 struct dwarf2_section_info
*section
,
3246 struct dwarf2_per_objfile
*dwarf2_per_objfile
3247 = get_dwarf2_per_objfile (objfile
);
3249 for (i
= 0; i
< n_elements
; i
+= 2)
3251 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3253 sect_offset sect_off
3254 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3255 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3258 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2]
3259 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3264 /* Read the CU list from the mapped index, and use it to create all
3265 the CU objects for this objfile. */
3268 create_cus_from_index (struct objfile
*objfile
,
3269 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3270 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3272 struct dwz_file
*dwz
;
3273 struct dwarf2_per_objfile
*dwarf2_per_objfile
3274 = get_dwarf2_per_objfile (objfile
);
3276 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3277 dwarf2_per_objfile
->all_comp_units
=
3278 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3279 dwarf2_per_objfile
->n_comp_units
);
3281 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3282 &dwarf2_per_objfile
->info
, 0, 0);
3284 if (dwz_elements
== 0)
3287 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3288 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3289 cu_list_elements
/ 2);
3292 /* Create the signatured type hash table from the index. */
3295 create_signatured_type_table_from_index (struct objfile
*objfile
,
3296 struct dwarf2_section_info
*section
,
3297 const gdb_byte
*bytes
,
3298 offset_type elements
)
3301 htab_t sig_types_hash
;
3302 struct dwarf2_per_objfile
*dwarf2_per_objfile
3303 = get_dwarf2_per_objfile (objfile
);
3305 dwarf2_per_objfile
->n_type_units
3306 = dwarf2_per_objfile
->n_allocated_type_units
3308 dwarf2_per_objfile
->all_type_units
=
3309 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3311 sig_types_hash
= allocate_signatured_type_table (objfile
);
3313 for (i
= 0; i
< elements
; i
+= 3)
3315 struct signatured_type
*sig_type
;
3318 cu_offset type_offset_in_tu
;
3320 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3321 sect_offset sect_off
3322 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3324 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3326 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3329 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3330 struct signatured_type
);
3331 sig_type
->signature
= signature
;
3332 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3333 sig_type
->per_cu
.is_debug_types
= 1;
3334 sig_type
->per_cu
.section
= section
;
3335 sig_type
->per_cu
.sect_off
= sect_off
;
3336 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3337 sig_type
->per_cu
.v
.quick
3338 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3339 struct dwarf2_per_cu_quick_data
);
3341 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3344 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3347 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3350 /* Create the signatured type hash table from .debug_names. */
3353 create_signatured_type_table_from_debug_names
3354 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3355 const mapped_debug_names
&map
,
3356 struct dwarf2_section_info
*section
,
3357 struct dwarf2_section_info
*abbrev_section
)
3359 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3361 dwarf2_read_section (objfile
, section
);
3362 dwarf2_read_section (objfile
, abbrev_section
);
3364 dwarf2_per_objfile
->n_type_units
3365 = dwarf2_per_objfile
->n_allocated_type_units
3367 dwarf2_per_objfile
->all_type_units
3368 = XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3370 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3372 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3374 struct signatured_type
*sig_type
;
3377 cu_offset type_offset_in_tu
;
3379 sect_offset sect_off
3380 = (sect_offset
) (extract_unsigned_integer
3381 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3383 map
.dwarf5_byte_order
));
3385 comp_unit_head cu_header
;
3386 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3388 section
->buffer
+ to_underlying (sect_off
),
3391 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3392 struct signatured_type
);
3393 sig_type
->signature
= cu_header
.signature
;
3394 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3395 sig_type
->per_cu
.is_debug_types
= 1;
3396 sig_type
->per_cu
.section
= section
;
3397 sig_type
->per_cu
.sect_off
= sect_off
;
3398 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3399 sig_type
->per_cu
.v
.quick
3400 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3401 struct dwarf2_per_cu_quick_data
);
3403 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3406 dwarf2_per_objfile
->all_type_units
[i
] = sig_type
;
3409 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3412 /* Read the address map data from the mapped index, and use it to
3413 populate the objfile's psymtabs_addrmap. */
3416 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3417 struct mapped_index
*index
)
3419 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3420 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3421 const gdb_byte
*iter
, *end
;
3422 struct addrmap
*mutable_map
;
3425 auto_obstack temp_obstack
;
3427 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3429 iter
= index
->address_table
.data ();
3430 end
= iter
+ index
->address_table
.size ();
3432 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3436 ULONGEST hi
, lo
, cu_index
;
3437 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3439 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3441 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3446 complaint (&symfile_complaints
,
3447 _(".gdb_index address table has invalid range (%s - %s)"),
3448 hex_string (lo
), hex_string (hi
));
3452 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3454 complaint (&symfile_complaints
,
3455 _(".gdb_index address table has invalid CU number %u"),
3456 (unsigned) cu_index
);
3460 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3461 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3462 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3463 dw2_get_cutu (dwarf2_per_objfile
, cu_index
));
3466 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3467 &objfile
->objfile_obstack
);
3470 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3471 populate the objfile's psymtabs_addrmap. */
3474 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3475 struct dwarf2_section_info
*section
)
3477 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3478 bfd
*abfd
= objfile
->obfd
;
3479 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3480 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3481 SECT_OFF_TEXT (objfile
));
3483 auto_obstack temp_obstack
;
3484 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3486 std::unordered_map
<sect_offset
,
3487 dwarf2_per_cu_data
*,
3488 gdb::hash_enum
<sect_offset
>>
3489 debug_info_offset_to_per_cu
;
3490 for (int cui
= 0; cui
< dwarf2_per_objfile
->n_comp_units
; ++cui
)
3492 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cui
);
3493 const auto insertpair
3494 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3495 if (!insertpair
.second
)
3497 warning (_("Section .debug_aranges in %s has duplicate "
3498 "debug_info_offset %u, ignoring .debug_aranges."),
3499 objfile_name (objfile
), to_underlying (per_cu
->sect_off
));
3504 dwarf2_read_section (objfile
, section
);
3506 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3508 const gdb_byte
*addr
= section
->buffer
;
3510 while (addr
< section
->buffer
+ section
->size
)
3512 const gdb_byte
*const entry_addr
= addr
;
3513 unsigned int bytes_read
;
3515 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3519 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3520 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3521 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3522 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3524 warning (_("Section .debug_aranges in %s entry at offset %zu "
3525 "length %s exceeds section length %s, "
3526 "ignoring .debug_aranges."),
3527 objfile_name (objfile
), entry_addr
- section
->buffer
,
3528 plongest (bytes_read
+ entry_length
),
3529 pulongest (section
->size
));
3533 /* The version number. */
3534 const uint16_t version
= read_2_bytes (abfd
, addr
);
3538 warning (_("Section .debug_aranges in %s entry at offset %zu "
3539 "has unsupported version %d, ignoring .debug_aranges."),
3540 objfile_name (objfile
), entry_addr
- section
->buffer
,
3545 const uint64_t debug_info_offset
3546 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3547 addr
+= offset_size
;
3548 const auto per_cu_it
3549 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3550 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3552 warning (_("Section .debug_aranges in %s entry at offset %zu "
3553 "debug_info_offset %s does not exists, "
3554 "ignoring .debug_aranges."),
3555 objfile_name (objfile
), entry_addr
- section
->buffer
,
3556 pulongest (debug_info_offset
));
3559 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3561 const uint8_t address_size
= *addr
++;
3562 if (address_size
< 1 || address_size
> 8)
3564 warning (_("Section .debug_aranges in %s entry at offset %zu "
3565 "address_size %u is invalid, ignoring .debug_aranges."),
3566 objfile_name (objfile
), entry_addr
- section
->buffer
,
3571 const uint8_t segment_selector_size
= *addr
++;
3572 if (segment_selector_size
!= 0)
3574 warning (_("Section .debug_aranges in %s entry at offset %zu "
3575 "segment_selector_size %u is not supported, "
3576 "ignoring .debug_aranges."),
3577 objfile_name (objfile
), entry_addr
- section
->buffer
,
3578 segment_selector_size
);
3582 /* Must pad to an alignment boundary that is twice the address
3583 size. It is undocumented by the DWARF standard but GCC does
3585 for (size_t padding
= ((-(addr
- section
->buffer
))
3586 & (2 * address_size
- 1));
3587 padding
> 0; padding
--)
3590 warning (_("Section .debug_aranges in %s entry at offset %zu "
3591 "padding is not zero, ignoring .debug_aranges."),
3592 objfile_name (objfile
), entry_addr
- section
->buffer
);
3598 if (addr
+ 2 * address_size
> entry_end
)
3600 warning (_("Section .debug_aranges in %s entry at offset %zu "
3601 "address list is not properly terminated, "
3602 "ignoring .debug_aranges."),
3603 objfile_name (objfile
), entry_addr
- section
->buffer
);
3606 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3608 addr
+= address_size
;
3609 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3611 addr
+= address_size
;
3612 if (start
== 0 && length
== 0)
3614 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3616 /* Symbol was eliminated due to a COMDAT group. */
3619 ULONGEST end
= start
+ length
;
3620 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3621 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3622 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3626 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3627 &objfile
->objfile_obstack
);
3630 /* The hash function for strings in the mapped index. This is the same as
3631 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3632 implementation. This is necessary because the hash function is tied to the
3633 format of the mapped index file. The hash values do not have to match with
3636 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3639 mapped_index_string_hash (int index_version
, const void *p
)
3641 const unsigned char *str
= (const unsigned char *) p
;
3645 while ((c
= *str
++) != 0)
3647 if (index_version
>= 5)
3649 r
= r
* 67 + c
- 113;
3655 /* Find a slot in the mapped index INDEX for the object named NAME.
3656 If NAME is found, set *VEC_OUT to point to the CU vector in the
3657 constant pool and return true. If NAME cannot be found, return
3661 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3662 offset_type
**vec_out
)
3665 offset_type slot
, step
;
3666 int (*cmp
) (const char *, const char *);
3668 gdb::unique_xmalloc_ptr
<char> without_params
;
3669 if (current_language
->la_language
== language_cplus
3670 || current_language
->la_language
== language_fortran
3671 || current_language
->la_language
== language_d
)
3673 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3676 if (strchr (name
, '(') != NULL
)
3678 without_params
= cp_remove_params (name
);
3680 if (without_params
!= NULL
)
3681 name
= without_params
.get ();
3685 /* Index version 4 did not support case insensitive searches. But the
3686 indices for case insensitive languages are built in lowercase, therefore
3687 simulate our NAME being searched is also lowercased. */
3688 hash
= mapped_index_string_hash ((index
->version
== 4
3689 && case_sensitivity
== case_sensitive_off
3690 ? 5 : index
->version
),
3693 slot
= hash
& (index
->symbol_table
.size () - 1);
3694 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3695 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3701 const auto &bucket
= index
->symbol_table
[slot
];
3702 if (bucket
.name
== 0 && bucket
.vec
== 0)
3705 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3706 if (!cmp (name
, str
))
3708 *vec_out
= (offset_type
*) (index
->constant_pool
3709 + MAYBE_SWAP (bucket
.vec
));
3713 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3717 /* A helper function that reads the .gdb_index from SECTION and fills
3718 in MAP. FILENAME is the name of the file containing the section;
3719 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3720 ok to use deprecated sections.
3722 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3723 out parameters that are filled in with information about the CU and
3724 TU lists in the section.
3726 Returns 1 if all went well, 0 otherwise. */
3729 read_index_from_section (struct objfile
*objfile
,
3730 const char *filename
,
3732 struct dwarf2_section_info
*section
,
3733 struct mapped_index
*map
,
3734 const gdb_byte
**cu_list
,
3735 offset_type
*cu_list_elements
,
3736 const gdb_byte
**types_list
,
3737 offset_type
*types_list_elements
)
3739 const gdb_byte
*addr
;
3740 offset_type version
;
3741 offset_type
*metadata
;
3744 if (dwarf2_section_empty_p (section
))
3747 /* Older elfutils strip versions could keep the section in the main
3748 executable while splitting it for the separate debug info file. */
3749 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3752 dwarf2_read_section (objfile
, section
);
3754 addr
= section
->buffer
;
3755 /* Version check. */
3756 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3757 /* Versions earlier than 3 emitted every copy of a psymbol. This
3758 causes the index to behave very poorly for certain requests. Version 3
3759 contained incomplete addrmap. So, it seems better to just ignore such
3763 static int warning_printed
= 0;
3764 if (!warning_printed
)
3766 warning (_("Skipping obsolete .gdb_index section in %s."),
3768 warning_printed
= 1;
3772 /* Index version 4 uses a different hash function than index version
3775 Versions earlier than 6 did not emit psymbols for inlined
3776 functions. Using these files will cause GDB not to be able to
3777 set breakpoints on inlined functions by name, so we ignore these
3778 indices unless the user has done
3779 "set use-deprecated-index-sections on". */
3780 if (version
< 6 && !deprecated_ok
)
3782 static int warning_printed
= 0;
3783 if (!warning_printed
)
3786 Skipping deprecated .gdb_index section in %s.\n\
3787 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3788 to use the section anyway."),
3790 warning_printed
= 1;
3794 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3795 of the TU (for symbols coming from TUs),
3796 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3797 Plus gold-generated indices can have duplicate entries for global symbols,
3798 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3799 These are just performance bugs, and we can't distinguish gdb-generated
3800 indices from gold-generated ones, so issue no warning here. */
3802 /* Indexes with higher version than the one supported by GDB may be no
3803 longer backward compatible. */
3807 map
->version
= version
;
3808 map
->total_size
= section
->size
;
3810 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3813 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3814 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3818 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3819 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3820 - MAYBE_SWAP (metadata
[i
]))
3824 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3825 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3827 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3830 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3831 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3833 = gdb::array_view
<mapped_index::symbol_table_slot
>
3834 ((mapped_index::symbol_table_slot
*) symbol_table
,
3835 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3838 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3843 /* Read .gdb_index. If everything went ok, initialize the "quick"
3844 elements of all the CUs and return 1. Otherwise, return 0. */
3847 dwarf2_read_index (struct objfile
*objfile
)
3849 struct mapped_index local_map
, *map
;
3850 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3851 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3852 struct dwz_file
*dwz
;
3853 struct dwarf2_per_objfile
*dwarf2_per_objfile
3854 = get_dwarf2_per_objfile (objfile
);
3856 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3857 use_deprecated_index_sections
,
3858 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3859 &cu_list
, &cu_list_elements
,
3860 &types_list
, &types_list_elements
))
3863 /* Don't use the index if it's empty. */
3864 if (local_map
.symbol_table
.empty ())
3867 /* If there is a .dwz file, read it so we can get its CU list as
3869 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3872 struct mapped_index dwz_map
;
3873 const gdb_byte
*dwz_types_ignore
;
3874 offset_type dwz_types_elements_ignore
;
3876 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3878 &dwz
->gdb_index
, &dwz_map
,
3879 &dwz_list
, &dwz_list_elements
,
3881 &dwz_types_elements_ignore
))
3883 warning (_("could not read '.gdb_index' section from %s; skipping"),
3884 bfd_get_filename (dwz
->dwz_bfd
));
3889 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3892 if (types_list_elements
)
3894 struct dwarf2_section_info
*section
;
3896 /* We can only handle a single .debug_types when we have an
3898 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3901 section
= VEC_index (dwarf2_section_info_def
,
3902 dwarf2_per_objfile
->types
, 0);
3904 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3905 types_list_elements
);
3908 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
3910 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3911 map
= new (map
) mapped_index ();
3914 dwarf2_per_objfile
->index_table
= map
;
3915 dwarf2_per_objfile
->using_index
= 1;
3916 dwarf2_per_objfile
->quick_file_names_table
=
3917 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3922 /* die_reader_func for dw2_get_file_names. */
3925 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3926 const gdb_byte
*info_ptr
,
3927 struct die_info
*comp_unit_die
,
3931 struct dwarf2_cu
*cu
= reader
->cu
;
3932 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3933 struct dwarf2_per_objfile
*dwarf2_per_objfile
3934 = cu
->per_cu
->dwarf2_per_objfile
;
3935 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3936 struct dwarf2_per_cu_data
*lh_cu
;
3937 struct attribute
*attr
;
3940 struct quick_file_names
*qfn
;
3942 gdb_assert (! this_cu
->is_debug_types
);
3944 /* Our callers never want to match partial units -- instead they
3945 will match the enclosing full CU. */
3946 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3948 this_cu
->v
.quick
->no_file_data
= 1;
3956 sect_offset line_offset
{};
3958 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3961 struct quick_file_names find_entry
;
3963 line_offset
= (sect_offset
) DW_UNSND (attr
);
3965 /* We may have already read in this line header (TU line header sharing).
3966 If we have we're done. */
3967 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3968 find_entry
.hash
.line_sect_off
= line_offset
;
3969 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3970 &find_entry
, INSERT
);
3973 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3977 lh
= dwarf_decode_line_header (line_offset
, cu
);
3981 lh_cu
->v
.quick
->no_file_data
= 1;
3985 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3986 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3987 qfn
->hash
.line_sect_off
= line_offset
;
3988 gdb_assert (slot
!= NULL
);
3991 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3993 qfn
->num_file_names
= lh
->file_names
.size ();
3995 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
3996 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3997 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3998 qfn
->real_names
= NULL
;
4000 lh_cu
->v
.quick
->file_names
= qfn
;
4003 /* A helper for the "quick" functions which attempts to read the line
4004 table for THIS_CU. */
4006 static struct quick_file_names
*
4007 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
4009 /* This should never be called for TUs. */
4010 gdb_assert (! this_cu
->is_debug_types
);
4011 /* Nor type unit groups. */
4012 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
4014 if (this_cu
->v
.quick
->file_names
!= NULL
)
4015 return this_cu
->v
.quick
->file_names
;
4016 /* If we know there is no line data, no point in looking again. */
4017 if (this_cu
->v
.quick
->no_file_data
)
4020 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
4022 if (this_cu
->v
.quick
->no_file_data
)
4024 return this_cu
->v
.quick
->file_names
;
4027 /* A helper for the "quick" functions which computes and caches the
4028 real path for a given file name from the line table. */
4031 dw2_get_real_path (struct objfile
*objfile
,
4032 struct quick_file_names
*qfn
, int index
)
4034 if (qfn
->real_names
== NULL
)
4035 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
4036 qfn
->num_file_names
, const char *);
4038 if (qfn
->real_names
[index
] == NULL
)
4039 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
4041 return qfn
->real_names
[index
];
4044 static struct symtab
*
4045 dw2_find_last_source_symtab (struct objfile
*objfile
)
4047 struct dwarf2_per_objfile
*dwarf2_per_objfile
4048 = get_dwarf2_per_objfile (objfile
);
4049 int index
= dwarf2_per_objfile
->n_comp_units
- 1;
4050 dwarf2_per_cu_data
*dwarf_cu
= dw2_get_cutu (dwarf2_per_objfile
, index
);
4051 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
);
4056 return compunit_primary_filetab (cust
);
4059 /* Traversal function for dw2_forget_cached_source_info. */
4062 dw2_free_cached_file_names (void **slot
, void *info
)
4064 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
4066 if (file_data
->real_names
)
4070 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
4072 xfree ((void*) file_data
->real_names
[i
]);
4073 file_data
->real_names
[i
] = NULL
;
4081 dw2_forget_cached_source_info (struct objfile
*objfile
)
4083 struct dwarf2_per_objfile
*dwarf2_per_objfile
4084 = get_dwarf2_per_objfile (objfile
);
4086 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
4087 dw2_free_cached_file_names
, NULL
);
4090 /* Helper function for dw2_map_symtabs_matching_filename that expands
4091 the symtabs and calls the iterator. */
4094 dw2_map_expand_apply (struct objfile
*objfile
,
4095 struct dwarf2_per_cu_data
*per_cu
,
4096 const char *name
, const char *real_path
,
4097 gdb::function_view
<bool (symtab
*)> callback
)
4099 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
4101 /* Don't visit already-expanded CUs. */
4102 if (per_cu
->v
.quick
->compunit_symtab
)
4105 /* This may expand more than one symtab, and we want to iterate over
4107 dw2_instantiate_symtab (per_cu
);
4109 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
4110 last_made
, callback
);
4113 /* Implementation of the map_symtabs_matching_filename method. */
4116 dw2_map_symtabs_matching_filename
4117 (struct objfile
*objfile
, const char *name
, const char *real_path
,
4118 gdb::function_view
<bool (symtab
*)> callback
)
4121 const char *name_basename
= lbasename (name
);
4122 struct dwarf2_per_objfile
*dwarf2_per_objfile
4123 = get_dwarf2_per_objfile (objfile
);
4125 /* The rule is CUs specify all the files, including those used by
4126 any TU, so there's no need to scan TUs here. */
4128 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4131 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
4132 struct quick_file_names
*file_data
;
4134 /* We only need to look at symtabs not already expanded. */
4135 if (per_cu
->v
.quick
->compunit_symtab
)
4138 file_data
= dw2_get_file_names (per_cu
);
4139 if (file_data
== NULL
)
4142 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4144 const char *this_name
= file_data
->file_names
[j
];
4145 const char *this_real_name
;
4147 if (compare_filenames_for_search (this_name
, name
))
4149 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4155 /* Before we invoke realpath, which can get expensive when many
4156 files are involved, do a quick comparison of the basenames. */
4157 if (! basenames_may_differ
4158 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
4161 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4162 if (compare_filenames_for_search (this_real_name
, name
))
4164 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4170 if (real_path
!= NULL
)
4172 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
4173 gdb_assert (IS_ABSOLUTE_PATH (name
));
4174 if (this_real_name
!= NULL
4175 && FILENAME_CMP (real_path
, this_real_name
) == 0)
4177 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4189 /* Struct used to manage iterating over all CUs looking for a symbol. */
4191 struct dw2_symtab_iterator
4193 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
4194 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
4195 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
4196 int want_specific_block
;
4197 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
4198 Unused if !WANT_SPECIFIC_BLOCK. */
4200 /* The kind of symbol we're looking for. */
4202 /* The list of CUs from the index entry of the symbol,
4203 or NULL if not found. */
4205 /* The next element in VEC to look at. */
4207 /* The number of elements in VEC, or zero if there is no match. */
4209 /* Have we seen a global version of the symbol?
4210 If so we can ignore all further global instances.
4211 This is to work around gold/15646, inefficient gold-generated
4216 /* Initialize the index symtab iterator ITER.
4217 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
4218 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
4221 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
4222 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4223 int want_specific_block
,
4228 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
4229 iter
->want_specific_block
= want_specific_block
;
4230 iter
->block_index
= block_index
;
4231 iter
->domain
= domain
;
4233 iter
->global_seen
= 0;
4235 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
4237 /* index is NULL if OBJF_READNOW. */
4238 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
4239 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4247 /* Return the next matching CU or NULL if there are no more. */
4249 static struct dwarf2_per_cu_data
*
4250 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4252 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
4254 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4256 offset_type cu_index_and_attrs
=
4257 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4258 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4259 struct dwarf2_per_cu_data
*per_cu
;
4260 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
4261 /* This value is only valid for index versions >= 7. */
4262 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4263 gdb_index_symbol_kind symbol_kind
=
4264 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4265 /* Only check the symbol attributes if they're present.
4266 Indices prior to version 7 don't record them,
4267 and indices >= 7 may elide them for certain symbols
4268 (gold does this). */
4270 (dwarf2_per_objfile
->index_table
->version
>= 7
4271 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4273 /* Don't crash on bad data. */
4274 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4275 + dwarf2_per_objfile
->n_type_units
))
4277 complaint (&symfile_complaints
,
4278 _(".gdb_index entry has bad CU index"
4280 objfile_name (dwarf2_per_objfile
->objfile
));
4284 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
4286 /* Skip if already read in. */
4287 if (per_cu
->v
.quick
->compunit_symtab
)
4290 /* Check static vs global. */
4293 if (iter
->want_specific_block
4294 && want_static
!= is_static
)
4296 /* Work around gold/15646. */
4297 if (!is_static
&& iter
->global_seen
)
4300 iter
->global_seen
= 1;
4303 /* Only check the symbol's kind if it has one. */
4306 switch (iter
->domain
)
4309 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4310 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4311 /* Some types are also in VAR_DOMAIN. */
4312 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4316 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4320 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4335 static struct compunit_symtab
*
4336 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4337 const char *name
, domain_enum domain
)
4339 struct compunit_symtab
*stab_best
= NULL
;
4340 struct dwarf2_per_objfile
*dwarf2_per_objfile
4341 = get_dwarf2_per_objfile (objfile
);
4343 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4345 struct dw2_symtab_iterator iter
;
4346 struct dwarf2_per_cu_data
*per_cu
;
4348 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4350 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4352 struct symbol
*sym
, *with_opaque
= NULL
;
4353 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4354 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4355 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4357 sym
= block_find_symbol (block
, name
, domain
,
4358 block_find_non_opaque_type_preferred
,
4361 /* Some caution must be observed with overloaded functions
4362 and methods, since the index will not contain any overload
4363 information (but NAME might contain it). */
4366 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4368 if (with_opaque
!= NULL
4369 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4372 /* Keep looking through other CUs. */
4379 dw2_print_stats (struct objfile
*objfile
)
4381 struct dwarf2_per_objfile
*dwarf2_per_objfile
4382 = get_dwarf2_per_objfile (objfile
);
4383 int total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
4386 for (int i
= 0; i
< total
; ++i
)
4388 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4390 if (!per_cu
->v
.quick
->compunit_symtab
)
4393 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4394 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4397 /* This dumps minimal information about the index.
4398 It is called via "mt print objfiles".
4399 One use is to verify .gdb_index has been loaded by the
4400 gdb.dwarf2/gdb-index.exp testcase. */
4403 dw2_dump (struct objfile
*objfile
)
4405 struct dwarf2_per_objfile
*dwarf2_per_objfile
4406 = get_dwarf2_per_objfile (objfile
);
4408 gdb_assert (dwarf2_per_objfile
->using_index
);
4409 printf_filtered (".gdb_index:");
4410 if (dwarf2_per_objfile
->index_table
!= NULL
)
4412 printf_filtered (" version %d\n",
4413 dwarf2_per_objfile
->index_table
->version
);
4416 printf_filtered (" faked for \"readnow\"\n");
4417 printf_filtered ("\n");
4421 dw2_relocate (struct objfile
*objfile
,
4422 const struct section_offsets
*new_offsets
,
4423 const struct section_offsets
*delta
)
4425 /* There's nothing to relocate here. */
4429 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4430 const char *func_name
)
4432 struct dwarf2_per_objfile
*dwarf2_per_objfile
4433 = get_dwarf2_per_objfile (objfile
);
4435 struct dw2_symtab_iterator iter
;
4436 struct dwarf2_per_cu_data
*per_cu
;
4438 /* Note: It doesn't matter what we pass for block_index here. */
4439 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4442 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4443 dw2_instantiate_symtab (per_cu
);
4448 dw2_expand_all_symtabs (struct objfile
*objfile
)
4450 struct dwarf2_per_objfile
*dwarf2_per_objfile
4451 = get_dwarf2_per_objfile (objfile
);
4452 int total_units
= (dwarf2_per_objfile
->n_comp_units
4453 + dwarf2_per_objfile
->n_type_units
);
4455 for (int i
= 0; i
< total_units
; ++i
)
4457 struct dwarf2_per_cu_data
*per_cu
4458 = dw2_get_cutu (dwarf2_per_objfile
, i
);
4460 dw2_instantiate_symtab (per_cu
);
4465 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4466 const char *fullname
)
4468 struct dwarf2_per_objfile
*dwarf2_per_objfile
4469 = get_dwarf2_per_objfile (objfile
);
4471 /* We don't need to consider type units here.
4472 This is only called for examining code, e.g. expand_line_sal.
4473 There can be an order of magnitude (or more) more type units
4474 than comp units, and we avoid them if we can. */
4476 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4479 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4480 struct quick_file_names
*file_data
;
4482 /* We only need to look at symtabs not already expanded. */
4483 if (per_cu
->v
.quick
->compunit_symtab
)
4486 file_data
= dw2_get_file_names (per_cu
);
4487 if (file_data
== NULL
)
4490 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4492 const char *this_fullname
= file_data
->file_names
[j
];
4494 if (filename_cmp (this_fullname
, fullname
) == 0)
4496 dw2_instantiate_symtab (per_cu
);
4504 dw2_map_matching_symbols (struct objfile
*objfile
,
4505 const char * name
, domain_enum domain
,
4507 int (*callback
) (struct block
*,
4508 struct symbol
*, void *),
4509 void *data
, symbol_name_match_type match
,
4510 symbol_compare_ftype
*ordered_compare
)
4512 /* Currently unimplemented; used for Ada. The function can be called if the
4513 current language is Ada for a non-Ada objfile using GNU index. As Ada
4514 does not look for non-Ada symbols this function should just return. */
4517 /* Symbol name matcher for .gdb_index names.
4519 Symbol names in .gdb_index have a few particularities:
4521 - There's no indication of which is the language of each symbol.
4523 Since each language has its own symbol name matching algorithm,
4524 and we don't know which language is the right one, we must match
4525 each symbol against all languages. This would be a potential
4526 performance problem if it were not mitigated by the
4527 mapped_index::name_components lookup table, which significantly
4528 reduces the number of times we need to call into this matcher,
4529 making it a non-issue.
4531 - Symbol names in the index have no overload (parameter)
4532 information. I.e., in C++, "foo(int)" and "foo(long)" both
4533 appear as "foo" in the index, for example.
4535 This means that the lookup names passed to the symbol name
4536 matcher functions must have no parameter information either
4537 because (e.g.) symbol search name "foo" does not match
4538 lookup-name "foo(int)" [while swapping search name for lookup
4541 class gdb_index_symbol_name_matcher
4544 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4545 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4547 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4548 Returns true if any matcher matches. */
4549 bool matches (const char *symbol_name
);
4552 /* A reference to the lookup name we're matching against. */
4553 const lookup_name_info
&m_lookup_name
;
4555 /* A vector holding all the different symbol name matchers, for all
4557 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4560 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4561 (const lookup_name_info
&lookup_name
)
4562 : m_lookup_name (lookup_name
)
4564 /* Prepare the vector of comparison functions upfront, to avoid
4565 doing the same work for each symbol. Care is taken to avoid
4566 matching with the same matcher more than once if/when multiple
4567 languages use the same matcher function. */
4568 auto &matchers
= m_symbol_name_matcher_funcs
;
4569 matchers
.reserve (nr_languages
);
4571 matchers
.push_back (default_symbol_name_matcher
);
4573 for (int i
= 0; i
< nr_languages
; i
++)
4575 const language_defn
*lang
= language_def ((enum language
) i
);
4576 symbol_name_matcher_ftype
*name_matcher
4577 = get_symbol_name_matcher (lang
, m_lookup_name
);
4579 /* Don't insert the same comparison routine more than once.
4580 Note that we do this linear walk instead of a seemingly
4581 cheaper sorted insert, or use a std::set or something like
4582 that, because relative order of function addresses is not
4583 stable. This is not a problem in practice because the number
4584 of supported languages is low, and the cost here is tiny
4585 compared to the number of searches we'll do afterwards using
4587 if (name_matcher
!= default_symbol_name_matcher
4588 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4589 == matchers
.end ()))
4590 matchers
.push_back (name_matcher
);
4595 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4597 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4598 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4604 /* Starting from a search name, return the string that finds the upper
4605 bound of all strings that start with SEARCH_NAME in a sorted name
4606 list. Returns the empty string to indicate that the upper bound is
4607 the end of the list. */
4610 make_sort_after_prefix_name (const char *search_name
)
4612 /* When looking to complete "func", we find the upper bound of all
4613 symbols that start with "func" by looking for where we'd insert
4614 the closest string that would follow "func" in lexicographical
4615 order. Usually, that's "func"-with-last-character-incremented,
4616 i.e. "fund". Mind non-ASCII characters, though. Usually those
4617 will be UTF-8 multi-byte sequences, but we can't be certain.
4618 Especially mind the 0xff character, which is a valid character in
4619 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4620 rule out compilers allowing it in identifiers. Note that
4621 conveniently, strcmp/strcasecmp are specified to compare
4622 characters interpreted as unsigned char. So what we do is treat
4623 the whole string as a base 256 number composed of a sequence of
4624 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4625 to 0, and carries 1 to the following more-significant position.
4626 If the very first character in SEARCH_NAME ends up incremented
4627 and carries/overflows, then the upper bound is the end of the
4628 list. The string after the empty string is also the empty
4631 Some examples of this operation:
4633 SEARCH_NAME => "+1" RESULT
4637 "\xff" "a" "\xff" => "\xff" "b"
4642 Then, with these symbols for example:
4648 completing "func" looks for symbols between "func" and
4649 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4650 which finds "func" and "func1", but not "fund".
4654 funcÿ (Latin1 'ÿ' [0xff])
4658 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4659 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4663 ÿÿ (Latin1 'ÿ' [0xff])
4666 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4667 the end of the list.
4669 std::string after
= search_name
;
4670 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4672 if (!after
.empty ())
4673 after
.back () = (unsigned char) after
.back () + 1;
4677 /* See declaration. */
4679 std::pair
<std::vector
<name_component
>::const_iterator
,
4680 std::vector
<name_component
>::const_iterator
>
4681 mapped_index_base::find_name_components_bounds
4682 (const lookup_name_info
&lookup_name_without_params
) const
4685 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4688 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4690 /* Comparison function object for lower_bound that matches against a
4691 given symbol name. */
4692 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4695 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4696 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4697 return name_cmp (elem_name
, name
) < 0;
4700 /* Comparison function object for upper_bound that matches against a
4701 given symbol name. */
4702 auto lookup_compare_upper
= [&] (const char *name
,
4703 const name_component
&elem
)
4705 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4706 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4707 return name_cmp (name
, elem_name
) < 0;
4710 auto begin
= this->name_components
.begin ();
4711 auto end
= this->name_components
.end ();
4713 /* Find the lower bound. */
4716 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4719 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4722 /* Find the upper bound. */
4725 if (lookup_name_without_params
.completion_mode ())
4727 /* In completion mode, we want UPPER to point past all
4728 symbols names that have the same prefix. I.e., with
4729 these symbols, and completing "func":
4731 function << lower bound
4733 other_function << upper bound
4735 We find the upper bound by looking for the insertion
4736 point of "func"-with-last-character-incremented,
4738 std::string after
= make_sort_after_prefix_name (cplus
);
4741 return std::lower_bound (lower
, end
, after
.c_str (),
4742 lookup_compare_lower
);
4745 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4748 return {lower
, upper
};
4751 /* See declaration. */
4754 mapped_index_base::build_name_components ()
4756 if (!this->name_components
.empty ())
4759 this->name_components_casing
= case_sensitivity
;
4761 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4763 /* The code below only knows how to break apart components of C++
4764 symbol names (and other languages that use '::' as
4765 namespace/module separator). If we add support for wild matching
4766 to some language that uses some other operator (E.g., Ada, Go and
4767 D use '.'), then we'll need to try splitting the symbol name
4768 according to that language too. Note that Ada does support wild
4769 matching, but doesn't currently support .gdb_index. */
4770 auto count
= this->symbol_name_count ();
4771 for (offset_type idx
= 0; idx
< count
; idx
++)
4773 if (this->symbol_name_slot_invalid (idx
))
4776 const char *name
= this->symbol_name_at (idx
);
4778 /* Add each name component to the name component table. */
4779 unsigned int previous_len
= 0;
4780 for (unsigned int current_len
= cp_find_first_component (name
);
4781 name
[current_len
] != '\0';
4782 current_len
+= cp_find_first_component (name
+ current_len
))
4784 gdb_assert (name
[current_len
] == ':');
4785 this->name_components
.push_back ({previous_len
, idx
});
4786 /* Skip the '::'. */
4788 previous_len
= current_len
;
4790 this->name_components
.push_back ({previous_len
, idx
});
4793 /* Sort name_components elements by name. */
4794 auto name_comp_compare
= [&] (const name_component
&left
,
4795 const name_component
&right
)
4797 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4798 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4800 const char *left_name
= left_qualified
+ left
.name_offset
;
4801 const char *right_name
= right_qualified
+ right
.name_offset
;
4803 return name_cmp (left_name
, right_name
) < 0;
4806 std::sort (this->name_components
.begin (),
4807 this->name_components
.end (),
4811 /* Helper for dw2_expand_symtabs_matching that works with a
4812 mapped_index_base instead of the containing objfile. This is split
4813 to a separate function in order to be able to unit test the
4814 name_components matching using a mock mapped_index_base. For each
4815 symbol name that matches, calls MATCH_CALLBACK, passing it the
4816 symbol's index in the mapped_index_base symbol table. */
4819 dw2_expand_symtabs_matching_symbol
4820 (mapped_index_base
&index
,
4821 const lookup_name_info
&lookup_name_in
,
4822 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4823 enum search_domain kind
,
4824 gdb::function_view
<void (offset_type
)> match_callback
)
4826 lookup_name_info lookup_name_without_params
4827 = lookup_name_in
.make_ignore_params ();
4828 gdb_index_symbol_name_matcher lookup_name_matcher
4829 (lookup_name_without_params
);
4831 /* Build the symbol name component sorted vector, if we haven't
4833 index
.build_name_components ();
4835 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4837 /* Now for each symbol name in range, check to see if we have a name
4838 match, and if so, call the MATCH_CALLBACK callback. */
4840 /* The same symbol may appear more than once in the range though.
4841 E.g., if we're looking for symbols that complete "w", and we have
4842 a symbol named "w1::w2", we'll find the two name components for
4843 that same symbol in the range. To be sure we only call the
4844 callback once per symbol, we first collect the symbol name
4845 indexes that matched in a temporary vector and ignore
4847 std::vector
<offset_type
> matches
;
4848 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4850 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4852 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4854 if (!lookup_name_matcher
.matches (qualified
)
4855 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4858 matches
.push_back (bounds
.first
->idx
);
4861 std::sort (matches
.begin (), matches
.end ());
4863 /* Finally call the callback, once per match. */
4865 for (offset_type idx
: matches
)
4869 match_callback (idx
);
4874 /* Above we use a type wider than idx's for 'prev', since 0 and
4875 (offset_type)-1 are both possible values. */
4876 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4881 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4883 /* A mock .gdb_index/.debug_names-like name index table, enough to
4884 exercise dw2_expand_symtabs_matching_symbol, which works with the
4885 mapped_index_base interface. Builds an index from the symbol list
4886 passed as parameter to the constructor. */
4887 class mock_mapped_index
: public mapped_index_base
4890 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4891 : m_symbol_table (symbols
)
4894 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4896 /* Return the number of names in the symbol table. */
4897 virtual size_t symbol_name_count () const
4899 return m_symbol_table
.size ();
4902 /* Get the name of the symbol at IDX in the symbol table. */
4903 virtual const char *symbol_name_at (offset_type idx
) const
4905 return m_symbol_table
[idx
];
4909 gdb::array_view
<const char *> m_symbol_table
;
4912 /* Convenience function that converts a NULL pointer to a "<null>"
4913 string, to pass to print routines. */
4916 string_or_null (const char *str
)
4918 return str
!= NULL
? str
: "<null>";
4921 /* Check if a lookup_name_info built from
4922 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4923 index. EXPECTED_LIST is the list of expected matches, in expected
4924 matching order. If no match expected, then an empty list is
4925 specified. Returns true on success. On failure prints a warning
4926 indicating the file:line that failed, and returns false. */
4929 check_match (const char *file
, int line
,
4930 mock_mapped_index
&mock_index
,
4931 const char *name
, symbol_name_match_type match_type
,
4932 bool completion_mode
,
4933 std::initializer_list
<const char *> expected_list
)
4935 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4937 bool matched
= true;
4939 auto mismatch
= [&] (const char *expected_str
,
4942 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4943 "expected=\"%s\", got=\"%s\"\n"),
4945 (match_type
== symbol_name_match_type::FULL
4947 name
, string_or_null (expected_str
), string_or_null (got
));
4951 auto expected_it
= expected_list
.begin ();
4952 auto expected_end
= expected_list
.end ();
4954 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4956 [&] (offset_type idx
)
4958 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4959 const char *expected_str
4960 = expected_it
== expected_end
? NULL
: *expected_it
++;
4962 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4963 mismatch (expected_str
, matched_name
);
4966 const char *expected_str
4967 = expected_it
== expected_end
? NULL
: *expected_it
++;
4968 if (expected_str
!= NULL
)
4969 mismatch (expected_str
, NULL
);
4974 /* The symbols added to the mock mapped_index for testing (in
4976 static const char *test_symbols
[] = {
4985 "ns2::tmpl<int>::foo2",
4986 "(anonymous namespace)::A::B::C",
4988 /* These are used to check that the increment-last-char in the
4989 matching algorithm for completion doesn't match "t1_fund" when
4990 completing "t1_func". */
4996 /* A UTF-8 name with multi-byte sequences to make sure that
4997 cp-name-parser understands this as a single identifier ("função"
4998 is "function" in PT). */
5001 /* \377 (0xff) is Latin1 'ÿ'. */
5004 /* \377 (0xff) is Latin1 'ÿ'. */
5008 /* A name with all sorts of complications. Starts with "z" to make
5009 it easier for the completion tests below. */
5010 #define Z_SYM_NAME \
5011 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
5012 "::tuple<(anonymous namespace)::ui*, " \
5013 "std::default_delete<(anonymous namespace)::ui>, void>"
5018 /* Returns true if the mapped_index_base::find_name_component_bounds
5019 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
5020 in completion mode. */
5023 check_find_bounds_finds (mapped_index_base
&index
,
5024 const char *search_name
,
5025 gdb::array_view
<const char *> expected_syms
)
5027 lookup_name_info
lookup_name (search_name
,
5028 symbol_name_match_type::FULL
, true);
5030 auto bounds
= index
.find_name_components_bounds (lookup_name
);
5032 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
5033 if (distance
!= expected_syms
.size ())
5036 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
5038 auto nc_elem
= bounds
.first
+ exp_elem
;
5039 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
5040 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
5047 /* Test the lower-level mapped_index::find_name_component_bounds
5051 test_mapped_index_find_name_component_bounds ()
5053 mock_mapped_index
mock_index (test_symbols
);
5055 mock_index
.build_name_components ();
5057 /* Test the lower-level mapped_index::find_name_component_bounds
5058 method in completion mode. */
5060 static const char *expected_syms
[] = {
5065 SELF_CHECK (check_find_bounds_finds (mock_index
,
5066 "t1_func", expected_syms
));
5069 /* Check that the increment-last-char in the name matching algorithm
5070 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
5072 static const char *expected_syms1
[] = {
5076 SELF_CHECK (check_find_bounds_finds (mock_index
,
5077 "\377", expected_syms1
));
5079 static const char *expected_syms2
[] = {
5082 SELF_CHECK (check_find_bounds_finds (mock_index
,
5083 "\377\377", expected_syms2
));
5087 /* Test dw2_expand_symtabs_matching_symbol. */
5090 test_dw2_expand_symtabs_matching_symbol ()
5092 mock_mapped_index
mock_index (test_symbols
);
5094 /* We let all tests run until the end even if some fails, for debug
5096 bool any_mismatch
= false;
5098 /* Create the expected symbols list (an initializer_list). Needed
5099 because lists have commas, and we need to pass them to CHECK,
5100 which is a macro. */
5101 #define EXPECT(...) { __VA_ARGS__ }
5103 /* Wrapper for check_match that passes down the current
5104 __FILE__/__LINE__. */
5105 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
5106 any_mismatch |= !check_match (__FILE__, __LINE__, \
5108 NAME, MATCH_TYPE, COMPLETION_MODE, \
5111 /* Identity checks. */
5112 for (const char *sym
: test_symbols
)
5114 /* Should be able to match all existing symbols. */
5115 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
5118 /* Should be able to match all existing symbols with
5120 std::string with_params
= std::string (sym
) + "(int)";
5121 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5124 /* Should be able to match all existing symbols with
5125 parameters and qualifiers. */
5126 with_params
= std::string (sym
) + " ( int ) const";
5127 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5130 /* This should really find sym, but cp-name-parser.y doesn't
5131 know about lvalue/rvalue qualifiers yet. */
5132 with_params
= std::string (sym
) + " ( int ) &&";
5133 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5137 /* Check that the name matching algorithm for completion doesn't get
5138 confused with Latin1 'ÿ' / 0xff. */
5140 static const char str
[] = "\377";
5141 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5142 EXPECT ("\377", "\377\377123"));
5145 /* Check that the increment-last-char in the matching algorithm for
5146 completion doesn't match "t1_fund" when completing "t1_func". */
5148 static const char str
[] = "t1_func";
5149 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5150 EXPECT ("t1_func", "t1_func1"));
5153 /* Check that completion mode works at each prefix of the expected
5156 static const char str
[] = "function(int)";
5157 size_t len
= strlen (str
);
5160 for (size_t i
= 1; i
< len
; i
++)
5162 lookup
.assign (str
, i
);
5163 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5164 EXPECT ("function"));
5168 /* While "w" is a prefix of both components, the match function
5169 should still only be called once. */
5171 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
5173 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
5177 /* Same, with a "complicated" symbol. */
5179 static const char str
[] = Z_SYM_NAME
;
5180 size_t len
= strlen (str
);
5183 for (size_t i
= 1; i
< len
; i
++)
5185 lookup
.assign (str
, i
);
5186 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5187 EXPECT (Z_SYM_NAME
));
5191 /* In FULL mode, an incomplete symbol doesn't match. */
5193 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
5197 /* A complete symbol with parameters matches any overload, since the
5198 index has no overload info. */
5200 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
5201 EXPECT ("std::zfunction", "std::zfunction2"));
5202 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
5203 EXPECT ("std::zfunction", "std::zfunction2"));
5204 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
5205 EXPECT ("std::zfunction", "std::zfunction2"));
5208 /* Check that whitespace is ignored appropriately. A symbol with a
5209 template argument list. */
5211 static const char expected
[] = "ns::foo<int>";
5212 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
5214 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
5218 /* Check that whitespace is ignored appropriately. A symbol with a
5219 template argument list that includes a pointer. */
5221 static const char expected
[] = "ns::foo<char*>";
5222 /* Try both completion and non-completion modes. */
5223 static const bool completion_mode
[2] = {false, true};
5224 for (size_t i
= 0; i
< 2; i
++)
5226 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
5227 completion_mode
[i
], EXPECT (expected
));
5228 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
5229 completion_mode
[i
], EXPECT (expected
));
5231 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
5232 completion_mode
[i
], EXPECT (expected
));
5233 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
5234 completion_mode
[i
], EXPECT (expected
));
5239 /* Check method qualifiers are ignored. */
5240 static const char expected
[] = "ns::foo<char*>";
5241 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
5242 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5243 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
5244 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5245 CHECK_MATCH ("foo < char * > ( int ) const",
5246 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5247 CHECK_MATCH ("foo < char * > ( int ) &&",
5248 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5251 /* Test lookup names that don't match anything. */
5253 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
5256 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
5260 /* Some wild matching tests, exercising "(anonymous namespace)",
5261 which should not be confused with a parameter list. */
5263 static const char *syms
[] = {
5267 "A :: B :: C ( int )",
5272 for (const char *s
: syms
)
5274 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
5275 EXPECT ("(anonymous namespace)::A::B::C"));
5280 static const char expected
[] = "ns2::tmpl<int>::foo2";
5281 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5283 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5287 SELF_CHECK (!any_mismatch
);
5296 test_mapped_index_find_name_component_bounds ();
5297 test_dw2_expand_symtabs_matching_symbol ();
5300 }} // namespace selftests::dw2_expand_symtabs_matching
5302 #endif /* GDB_SELF_TEST */
5304 /* If FILE_MATCHER is NULL or if PER_CU has
5305 dwarf2_per_cu_quick_data::MARK set (see
5306 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5307 EXPANSION_NOTIFY on it. */
5310 dw2_expand_symtabs_matching_one
5311 (struct dwarf2_per_cu_data
*per_cu
,
5312 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5313 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5315 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5317 bool symtab_was_null
5318 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5320 dw2_instantiate_symtab (per_cu
);
5322 if (expansion_notify
!= NULL
5324 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5325 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5329 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5330 matched, to expand corresponding CUs that were marked. IDX is the
5331 index of the symbol name that matched. */
5334 dw2_expand_marked_cus
5335 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5336 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5337 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5340 offset_type
*vec
, vec_len
, vec_idx
;
5341 bool global_seen
= false;
5342 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5344 vec
= (offset_type
*) (index
.constant_pool
5345 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5346 vec_len
= MAYBE_SWAP (vec
[0]);
5347 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5349 struct dwarf2_per_cu_data
*per_cu
;
5350 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5351 /* This value is only valid for index versions >= 7. */
5352 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5353 gdb_index_symbol_kind symbol_kind
=
5354 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5355 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5356 /* Only check the symbol attributes if they're present.
5357 Indices prior to version 7 don't record them,
5358 and indices >= 7 may elide them for certain symbols
5359 (gold does this). */
5362 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5364 /* Work around gold/15646. */
5367 if (!is_static
&& global_seen
)
5373 /* Only check the symbol's kind if it has one. */
5378 case VARIABLES_DOMAIN
:
5379 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5382 case FUNCTIONS_DOMAIN
:
5383 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5387 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5395 /* Don't crash on bad data. */
5396 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
5397 + dwarf2_per_objfile
->n_type_units
))
5399 complaint (&symfile_complaints
,
5400 _(".gdb_index entry has bad CU index"
5402 objfile_name (dwarf2_per_objfile
->objfile
));
5406 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
5407 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5412 /* If FILE_MATCHER is non-NULL, set all the
5413 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5414 that match FILE_MATCHER. */
5417 dw_expand_symtabs_matching_file_matcher
5418 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5419 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5421 if (file_matcher
== NULL
)
5424 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5426 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5428 NULL
, xcalloc
, xfree
));
5429 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5431 NULL
, xcalloc
, xfree
));
5433 /* The rule is CUs specify all the files, including those used by
5434 any TU, so there's no need to scan TUs here. */
5436 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5439 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5440 struct quick_file_names
*file_data
;
5445 per_cu
->v
.quick
->mark
= 0;
5447 /* We only need to look at symtabs not already expanded. */
5448 if (per_cu
->v
.quick
->compunit_symtab
)
5451 file_data
= dw2_get_file_names (per_cu
);
5452 if (file_data
== NULL
)
5455 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5457 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5459 per_cu
->v
.quick
->mark
= 1;
5463 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
5465 const char *this_real_name
;
5467 if (file_matcher (file_data
->file_names
[j
], false))
5469 per_cu
->v
.quick
->mark
= 1;
5473 /* Before we invoke realpath, which can get expensive when many
5474 files are involved, do a quick comparison of the basenames. */
5475 if (!basenames_may_differ
5476 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5480 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5481 if (file_matcher (this_real_name
, false))
5483 per_cu
->v
.quick
->mark
= 1;
5488 slot
= htab_find_slot (per_cu
->v
.quick
->mark
5489 ? visited_found
.get ()
5490 : visited_not_found
.get (),
5497 dw2_expand_symtabs_matching
5498 (struct objfile
*objfile
,
5499 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5500 const lookup_name_info
&lookup_name
,
5501 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5502 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5503 enum search_domain kind
)
5505 struct dwarf2_per_objfile
*dwarf2_per_objfile
5506 = get_dwarf2_per_objfile (objfile
);
5508 /* index_table is NULL if OBJF_READNOW. */
5509 if (!dwarf2_per_objfile
->index_table
)
5512 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5514 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5516 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5518 kind
, [&] (offset_type idx
)
5520 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5521 expansion_notify
, kind
);
5525 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5528 static struct compunit_symtab
*
5529 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5534 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5535 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5538 if (cust
->includes
== NULL
)
5541 for (i
= 0; cust
->includes
[i
]; ++i
)
5543 struct compunit_symtab
*s
= cust
->includes
[i
];
5545 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5553 static struct compunit_symtab
*
5554 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5555 struct bound_minimal_symbol msymbol
,
5557 struct obj_section
*section
,
5560 struct dwarf2_per_cu_data
*data
;
5561 struct compunit_symtab
*result
;
5563 if (!objfile
->psymtabs_addrmap
)
5566 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5571 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5572 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5573 paddress (get_objfile_arch (objfile
), pc
));
5576 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5578 gdb_assert (result
!= NULL
);
5583 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5584 void *data
, int need_fullname
)
5586 struct dwarf2_per_objfile
*dwarf2_per_objfile
5587 = get_dwarf2_per_objfile (objfile
);
5589 if (!dwarf2_per_objfile
->filenames_cache
)
5591 dwarf2_per_objfile
->filenames_cache
.emplace ();
5593 htab_up
visited (htab_create_alloc (10,
5594 htab_hash_pointer
, htab_eq_pointer
,
5595 NULL
, xcalloc
, xfree
));
5597 /* The rule is CUs specify all the files, including those used
5598 by any TU, so there's no need to scan TUs here. We can
5599 ignore file names coming from already-expanded CUs. */
5601 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5603 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
5605 if (per_cu
->v
.quick
->compunit_symtab
)
5607 void **slot
= htab_find_slot (visited
.get (),
5608 per_cu
->v
.quick
->file_names
,
5611 *slot
= per_cu
->v
.quick
->file_names
;
5615 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5617 dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5618 struct quick_file_names
*file_data
;
5621 /* We only need to look at symtabs not already expanded. */
5622 if (per_cu
->v
.quick
->compunit_symtab
)
5625 file_data
= dw2_get_file_names (per_cu
);
5626 if (file_data
== NULL
)
5629 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5632 /* Already visited. */
5637 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5639 const char *filename
= file_data
->file_names
[j
];
5640 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5645 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5647 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5650 this_real_name
= gdb_realpath (filename
);
5651 (*fun
) (filename
, this_real_name
.get (), data
);
5656 dw2_has_symbols (struct objfile
*objfile
)
5661 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5664 dw2_find_last_source_symtab
,
5665 dw2_forget_cached_source_info
,
5666 dw2_map_symtabs_matching_filename
,
5671 dw2_expand_symtabs_for_function
,
5672 dw2_expand_all_symtabs
,
5673 dw2_expand_symtabs_with_fullname
,
5674 dw2_map_matching_symbols
,
5675 dw2_expand_symtabs_matching
,
5676 dw2_find_pc_sect_compunit_symtab
,
5678 dw2_map_symbol_filenames
5681 /* DWARF-5 debug_names reader. */
5683 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5684 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5686 /* A helper function that reads the .debug_names section in SECTION
5687 and fills in MAP. FILENAME is the name of the file containing the
5688 section; it is used for error reporting.
5690 Returns true if all went well, false otherwise. */
5693 read_debug_names_from_section (struct objfile
*objfile
,
5694 const char *filename
,
5695 struct dwarf2_section_info
*section
,
5696 mapped_debug_names
&map
)
5698 if (dwarf2_section_empty_p (section
))
5701 /* Older elfutils strip versions could keep the section in the main
5702 executable while splitting it for the separate debug info file. */
5703 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5706 dwarf2_read_section (objfile
, section
);
5708 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5710 const gdb_byte
*addr
= section
->buffer
;
5712 bfd
*const abfd
= get_section_bfd_owner (section
);
5714 unsigned int bytes_read
;
5715 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5718 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5719 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5720 if (bytes_read
+ length
!= section
->size
)
5722 /* There may be multiple per-CU indices. */
5723 warning (_("Section .debug_names in %s length %s does not match "
5724 "section length %s, ignoring .debug_names."),
5725 filename
, plongest (bytes_read
+ length
),
5726 pulongest (section
->size
));
5730 /* The version number. */
5731 uint16_t version
= read_2_bytes (abfd
, addr
);
5735 warning (_("Section .debug_names in %s has unsupported version %d, "
5736 "ignoring .debug_names."),
5742 uint16_t padding
= read_2_bytes (abfd
, addr
);
5746 warning (_("Section .debug_names in %s has unsupported padding %d, "
5747 "ignoring .debug_names."),
5752 /* comp_unit_count - The number of CUs in the CU list. */
5753 map
.cu_count
= read_4_bytes (abfd
, addr
);
5756 /* local_type_unit_count - The number of TUs in the local TU
5758 map
.tu_count
= read_4_bytes (abfd
, addr
);
5761 /* foreign_type_unit_count - The number of TUs in the foreign TU
5763 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5765 if (foreign_tu_count
!= 0)
5767 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5768 "ignoring .debug_names."),
5769 filename
, static_cast<unsigned long> (foreign_tu_count
));
5773 /* bucket_count - The number of hash buckets in the hash lookup
5775 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5778 /* name_count - The number of unique names in the index. */
5779 map
.name_count
= read_4_bytes (abfd
, addr
);
5782 /* abbrev_table_size - The size in bytes of the abbreviations
5784 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5787 /* augmentation_string_size - The size in bytes of the augmentation
5788 string. This value is rounded up to a multiple of 4. */
5789 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5791 map
.augmentation_is_gdb
= ((augmentation_string_size
5792 == sizeof (dwarf5_augmentation
))
5793 && memcmp (addr
, dwarf5_augmentation
,
5794 sizeof (dwarf5_augmentation
)) == 0);
5795 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5796 addr
+= augmentation_string_size
;
5799 map
.cu_table_reordered
= addr
;
5800 addr
+= map
.cu_count
* map
.offset_size
;
5802 /* List of Local TUs */
5803 map
.tu_table_reordered
= addr
;
5804 addr
+= map
.tu_count
* map
.offset_size
;
5806 /* Hash Lookup Table */
5807 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5808 addr
+= map
.bucket_count
* 4;
5809 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5810 addr
+= map
.name_count
* 4;
5813 map
.name_table_string_offs_reordered
= addr
;
5814 addr
+= map
.name_count
* map
.offset_size
;
5815 map
.name_table_entry_offs_reordered
= addr
;
5816 addr
+= map
.name_count
* map
.offset_size
;
5818 const gdb_byte
*abbrev_table_start
= addr
;
5821 unsigned int bytes_read
;
5822 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5827 const auto insertpair
5828 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5829 if (!insertpair
.second
)
5831 warning (_("Section .debug_names in %s has duplicate index %s, "
5832 "ignoring .debug_names."),
5833 filename
, pulongest (index_num
));
5836 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5837 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5842 mapped_debug_names::index_val::attr attr
;
5843 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5845 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5847 if (attr
.form
== DW_FORM_implicit_const
)
5849 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5853 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5855 indexval
.attr_vec
.push_back (std::move (attr
));
5858 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5860 warning (_("Section .debug_names in %s has abbreviation_table "
5861 "of size %zu vs. written as %u, ignoring .debug_names."),
5862 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5865 map
.entry_pool
= addr
;
5870 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5874 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5875 const mapped_debug_names
&map
,
5876 dwarf2_section_info
§ion
,
5877 bool is_dwz
, int base_offset
)
5879 sect_offset sect_off_prev
;
5880 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5882 sect_offset sect_off_next
;
5883 if (i
< map
.cu_count
)
5886 = (sect_offset
) (extract_unsigned_integer
5887 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5889 map
.dwarf5_byte_order
));
5892 sect_off_next
= (sect_offset
) section
.size
;
5895 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5896 dwarf2_per_objfile
->all_comp_units
[base_offset
+ (i
- 1)]
5897 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5898 sect_off_prev
, length
);
5900 sect_off_prev
= sect_off_next
;
5904 /* Read the CU list from the mapped index, and use it to create all
5905 the CU objects for this dwarf2_per_objfile. */
5908 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5909 const mapped_debug_names
&map
,
5910 const mapped_debug_names
&dwz_map
)
5912 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5914 dwarf2_per_objfile
->n_comp_units
= map
.cu_count
+ dwz_map
.cu_count
;
5915 dwarf2_per_objfile
->all_comp_units
5916 = XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
5917 dwarf2_per_objfile
->n_comp_units
);
5919 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5920 dwarf2_per_objfile
->info
,
5922 0 /* base_offset */);
5924 if (dwz_map
.cu_count
== 0)
5927 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5928 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5930 map
.cu_count
/* base_offset */);
5933 /* Read .debug_names. If everything went ok, initialize the "quick"
5934 elements of all the CUs and return true. Otherwise, return false. */
5937 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5939 mapped_debug_names
local_map (dwarf2_per_objfile
);
5940 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5941 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5943 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5944 &dwarf2_per_objfile
->debug_names
,
5948 /* Don't use the index if it's empty. */
5949 if (local_map
.name_count
== 0)
5952 /* If there is a .dwz file, read it so we can get its CU list as
5954 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5957 if (!read_debug_names_from_section (objfile
,
5958 bfd_get_filename (dwz
->dwz_bfd
),
5959 &dwz
->debug_names
, dwz_map
))
5961 warning (_("could not read '.debug_names' section from %s; skipping"),
5962 bfd_get_filename (dwz
->dwz_bfd
));
5967 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
5969 if (local_map
.tu_count
!= 0)
5971 /* We can only handle a single .debug_types when we have an
5973 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
5976 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
5977 dwarf2_per_objfile
->types
, 0);
5979 create_signatured_type_table_from_debug_names
5980 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
5983 create_addrmap_from_aranges (dwarf2_per_objfile
,
5984 &dwarf2_per_objfile
->debug_aranges
);
5986 dwarf2_per_objfile
->debug_names_table
.reset
5987 (new mapped_debug_names (dwarf2_per_objfile
));
5988 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
5989 dwarf2_per_objfile
->using_index
= 1;
5990 dwarf2_per_objfile
->quick_file_names_table
=
5991 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
5996 /* Symbol name hashing function as specified by DWARF-5. */
5999 dwarf5_djb_hash (const char *str_
)
6001 const unsigned char *str
= (const unsigned char *) str_
;
6003 /* Note: tolower here ignores UTF-8, which isn't fully compliant.
6004 See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */
6006 uint32_t hash
= 5381;
6007 while (int c
= *str
++)
6008 hash
= hash
* 33 + tolower (c
);
6012 /* Type used to manage iterating over all CUs looking for a symbol for
6015 class dw2_debug_names_iterator
6018 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
6019 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
6020 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6021 bool want_specific_block
,
6022 block_enum block_index
, domain_enum domain
,
6024 : m_map (map
), m_want_specific_block (want_specific_block
),
6025 m_block_index (block_index
), m_domain (domain
),
6026 m_addr (find_vec_in_debug_names (map
, name
))
6029 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6030 search_domain search
, uint32_t namei
)
6033 m_addr (find_vec_in_debug_names (map
, namei
))
6036 /* Return the next matching CU or NULL if there are no more. */
6037 dwarf2_per_cu_data
*next ();
6040 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6042 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6045 /* The internalized form of .debug_names. */
6046 const mapped_debug_names
&m_map
;
6048 /* If true, only look for symbols that match BLOCK_INDEX. */
6049 const bool m_want_specific_block
= false;
6051 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
6052 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
6054 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
6056 /* The kind of symbol we're looking for. */
6057 const domain_enum m_domain
= UNDEF_DOMAIN
;
6058 const search_domain m_search
= ALL_DOMAIN
;
6060 /* The list of CUs from the index entry of the symbol, or NULL if
6062 const gdb_byte
*m_addr
;
6066 mapped_debug_names::namei_to_name (uint32_t namei
) const
6068 const ULONGEST namei_string_offs
6069 = extract_unsigned_integer ((name_table_string_offs_reordered
6070 + namei
* offset_size
),
6073 return read_indirect_string_at_offset
6074 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
6077 /* Find a slot in .debug_names for the object named NAME. If NAME is
6078 found, return pointer to its pool data. If NAME cannot be found,
6082 dw2_debug_names_iterator::find_vec_in_debug_names
6083 (const mapped_debug_names
&map
, const char *name
)
6085 int (*cmp
) (const char *, const char *);
6087 if (current_language
->la_language
== language_cplus
6088 || current_language
->la_language
== language_fortran
6089 || current_language
->la_language
== language_d
)
6091 /* NAME is already canonical. Drop any qualifiers as
6092 .debug_names does not contain any. */
6094 if (strchr (name
, '(') != NULL
)
6096 gdb::unique_xmalloc_ptr
<char> without_params
6097 = cp_remove_params (name
);
6099 if (without_params
!= NULL
)
6101 name
= without_params
.get();
6106 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
6108 const uint32_t full_hash
= dwarf5_djb_hash (name
);
6110 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6111 (map
.bucket_table_reordered
6112 + (full_hash
% map
.bucket_count
)), 4,
6113 map
.dwarf5_byte_order
);
6117 if (namei
>= map
.name_count
)
6119 complaint (&symfile_complaints
,
6120 _("Wrong .debug_names with name index %u but name_count=%u "
6122 namei
, map
.name_count
,
6123 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6129 const uint32_t namei_full_hash
6130 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6131 (map
.hash_table_reordered
+ namei
), 4,
6132 map
.dwarf5_byte_order
);
6133 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
6136 if (full_hash
== namei_full_hash
)
6138 const char *const namei_string
= map
.namei_to_name (namei
);
6140 #if 0 /* An expensive sanity check. */
6141 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
6143 complaint (&symfile_complaints
,
6144 _("Wrong .debug_names hash for string at index %u "
6146 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
6151 if (cmp (namei_string
, name
) == 0)
6153 const ULONGEST namei_entry_offs
6154 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6155 + namei
* map
.offset_size
),
6156 map
.offset_size
, map
.dwarf5_byte_order
);
6157 return map
.entry_pool
+ namei_entry_offs
;
6162 if (namei
>= map
.name_count
)
6168 dw2_debug_names_iterator::find_vec_in_debug_names
6169 (const mapped_debug_names
&map
, uint32_t namei
)
6171 if (namei
>= map
.name_count
)
6173 complaint (&symfile_complaints
,
6174 _("Wrong .debug_names with name index %u but name_count=%u "
6176 namei
, map
.name_count
,
6177 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6181 const ULONGEST namei_entry_offs
6182 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6183 + namei
* map
.offset_size
),
6184 map
.offset_size
, map
.dwarf5_byte_order
);
6185 return map
.entry_pool
+ namei_entry_offs
;
6188 /* See dw2_debug_names_iterator. */
6190 dwarf2_per_cu_data
*
6191 dw2_debug_names_iterator::next ()
6196 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
6197 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6198 bfd
*const abfd
= objfile
->obfd
;
6202 unsigned int bytes_read
;
6203 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6204 m_addr
+= bytes_read
;
6208 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
6209 if (indexval_it
== m_map
.abbrev_map
.cend ())
6211 complaint (&symfile_complaints
,
6212 _("Wrong .debug_names undefined abbrev code %s "
6214 pulongest (abbrev
), objfile_name (objfile
));
6217 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
6218 bool have_is_static
= false;
6220 dwarf2_per_cu_data
*per_cu
= NULL
;
6221 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
6226 case DW_FORM_implicit_const
:
6227 ull
= attr
.implicit_const
;
6229 case DW_FORM_flag_present
:
6233 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6234 m_addr
+= bytes_read
;
6237 complaint (&symfile_complaints
,
6238 _("Unsupported .debug_names form %s [in module %s]"),
6239 dwarf_form_name (attr
.form
),
6240 objfile_name (objfile
));
6243 switch (attr
.dw_idx
)
6245 case DW_IDX_compile_unit
:
6246 /* Don't crash on bad data. */
6247 if (ull
>= dwarf2_per_objfile
->n_comp_units
)
6249 complaint (&symfile_complaints
,
6250 _(".debug_names entry has bad CU index %s"
6253 objfile_name (dwarf2_per_objfile
->objfile
));
6256 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, ull
);
6258 case DW_IDX_type_unit
:
6259 /* Don't crash on bad data. */
6260 if (ull
>= dwarf2_per_objfile
->n_type_units
)
6262 complaint (&symfile_complaints
,
6263 _(".debug_names entry has bad TU index %s"
6266 objfile_name (dwarf2_per_objfile
->objfile
));
6269 per_cu
= dw2_get_cutu (dwarf2_per_objfile
,
6270 dwarf2_per_objfile
->n_comp_units
+ ull
);
6272 case DW_IDX_GNU_internal
:
6273 if (!m_map
.augmentation_is_gdb
)
6275 have_is_static
= true;
6278 case DW_IDX_GNU_external
:
6279 if (!m_map
.augmentation_is_gdb
)
6281 have_is_static
= true;
6287 /* Skip if already read in. */
6288 if (per_cu
->v
.quick
->compunit_symtab
)
6291 /* Check static vs global. */
6294 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
6295 if (m_want_specific_block
&& want_static
!= is_static
)
6299 /* Match dw2_symtab_iter_next, symbol_kind
6300 and debug_names::psymbol_tag. */
6304 switch (indexval
.dwarf_tag
)
6306 case DW_TAG_variable
:
6307 case DW_TAG_subprogram
:
6308 /* Some types are also in VAR_DOMAIN. */
6309 case DW_TAG_typedef
:
6310 case DW_TAG_structure_type
:
6317 switch (indexval
.dwarf_tag
)
6319 case DW_TAG_typedef
:
6320 case DW_TAG_structure_type
:
6327 switch (indexval
.dwarf_tag
)
6330 case DW_TAG_variable
:
6340 /* Match dw2_expand_symtabs_matching, symbol_kind and
6341 debug_names::psymbol_tag. */
6344 case VARIABLES_DOMAIN
:
6345 switch (indexval
.dwarf_tag
)
6347 case DW_TAG_variable
:
6353 case FUNCTIONS_DOMAIN
:
6354 switch (indexval
.dwarf_tag
)
6356 case DW_TAG_subprogram
:
6363 switch (indexval
.dwarf_tag
)
6365 case DW_TAG_typedef
:
6366 case DW_TAG_structure_type
:
6379 static struct compunit_symtab
*
6380 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6381 const char *name
, domain_enum domain
)
6383 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6384 struct dwarf2_per_objfile
*dwarf2_per_objfile
6385 = get_dwarf2_per_objfile (objfile
);
6387 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6390 /* index is NULL if OBJF_READNOW. */
6393 const auto &map
= *mapp
;
6395 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6396 block_index
, domain
, name
);
6398 struct compunit_symtab
*stab_best
= NULL
;
6399 struct dwarf2_per_cu_data
*per_cu
;
6400 while ((per_cu
= iter
.next ()) != NULL
)
6402 struct symbol
*sym
, *with_opaque
= NULL
;
6403 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6404 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6405 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6407 sym
= block_find_symbol (block
, name
, domain
,
6408 block_find_non_opaque_type_preferred
,
6411 /* Some caution must be observed with overloaded functions and
6412 methods, since the index will not contain any overload
6413 information (but NAME might contain it). */
6416 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6418 if (with_opaque
!= NULL
6419 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6422 /* Keep looking through other CUs. */
6428 /* This dumps minimal information about .debug_names. It is called
6429 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6430 uses this to verify that .debug_names has been loaded. */
6433 dw2_debug_names_dump (struct objfile
*objfile
)
6435 struct dwarf2_per_objfile
*dwarf2_per_objfile
6436 = get_dwarf2_per_objfile (objfile
);
6438 gdb_assert (dwarf2_per_objfile
->using_index
);
6439 printf_filtered (".debug_names:");
6440 if (dwarf2_per_objfile
->debug_names_table
)
6441 printf_filtered (" exists\n");
6443 printf_filtered (" faked for \"readnow\"\n");
6444 printf_filtered ("\n");
6448 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6449 const char *func_name
)
6451 struct dwarf2_per_objfile
*dwarf2_per_objfile
6452 = get_dwarf2_per_objfile (objfile
);
6454 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6455 if (dwarf2_per_objfile
->debug_names_table
)
6457 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6459 /* Note: It doesn't matter what we pass for block_index here. */
6460 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6461 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6463 struct dwarf2_per_cu_data
*per_cu
;
6464 while ((per_cu
= iter
.next ()) != NULL
)
6465 dw2_instantiate_symtab (per_cu
);
6470 dw2_debug_names_expand_symtabs_matching
6471 (struct objfile
*objfile
,
6472 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6473 const lookup_name_info
&lookup_name
,
6474 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6475 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6476 enum search_domain kind
)
6478 struct dwarf2_per_objfile
*dwarf2_per_objfile
6479 = get_dwarf2_per_objfile (objfile
);
6481 /* debug_names_table is NULL if OBJF_READNOW. */
6482 if (!dwarf2_per_objfile
->debug_names_table
)
6485 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6487 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6489 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6491 kind
, [&] (offset_type namei
)
6493 /* The name was matched, now expand corresponding CUs that were
6495 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6497 struct dwarf2_per_cu_data
*per_cu
;
6498 while ((per_cu
= iter
.next ()) != NULL
)
6499 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6504 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6507 dw2_find_last_source_symtab
,
6508 dw2_forget_cached_source_info
,
6509 dw2_map_symtabs_matching_filename
,
6510 dw2_debug_names_lookup_symbol
,
6512 dw2_debug_names_dump
,
6514 dw2_debug_names_expand_symtabs_for_function
,
6515 dw2_expand_all_symtabs
,
6516 dw2_expand_symtabs_with_fullname
,
6517 dw2_map_matching_symbols
,
6518 dw2_debug_names_expand_symtabs_matching
,
6519 dw2_find_pc_sect_compunit_symtab
,
6521 dw2_map_symbol_filenames
6524 /* See symfile.h. */
6527 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6529 struct dwarf2_per_objfile
*dwarf2_per_objfile
6530 = get_dwarf2_per_objfile (objfile
);
6532 /* If we're about to read full symbols, don't bother with the
6533 indices. In this case we also don't care if some other debug
6534 format is making psymtabs, because they are all about to be
6536 if ((objfile
->flags
& OBJF_READNOW
))
6540 dwarf2_per_objfile
->using_index
= 1;
6541 create_all_comp_units (dwarf2_per_objfile
);
6542 create_all_type_units (dwarf2_per_objfile
);
6543 dwarf2_per_objfile
->quick_file_names_table
=
6544 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6546 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
6547 + dwarf2_per_objfile
->n_type_units
); ++i
)
6549 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
6551 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6552 struct dwarf2_per_cu_quick_data
);
6555 /* Return 1 so that gdb sees the "quick" functions. However,
6556 these functions will be no-ops because we will have expanded
6558 *index_kind
= dw_index_kind::GDB_INDEX
;
6562 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6564 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6568 if (dwarf2_read_index (objfile
))
6570 *index_kind
= dw_index_kind::GDB_INDEX
;
6579 /* Build a partial symbol table. */
6582 dwarf2_build_psymtabs (struct objfile
*objfile
)
6584 struct dwarf2_per_objfile
*dwarf2_per_objfile
6585 = get_dwarf2_per_objfile (objfile
);
6587 if (objfile
->global_psymbols
.capacity () == 0
6588 && objfile
->static_psymbols
.capacity () == 0)
6589 init_psymbol_list (objfile
, 1024);
6593 /* This isn't really ideal: all the data we allocate on the
6594 objfile's obstack is still uselessly kept around. However,
6595 freeing it seems unsafe. */
6596 psymtab_discarder
psymtabs (objfile
);
6597 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6600 CATCH (except
, RETURN_MASK_ERROR
)
6602 exception_print (gdb_stderr
, except
);
6607 /* Return the total length of the CU described by HEADER. */
6610 get_cu_length (const struct comp_unit_head
*header
)
6612 return header
->initial_length_size
+ header
->length
;
6615 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6618 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6620 sect_offset bottom
= cu_header
->sect_off
;
6621 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6623 return sect_off
>= bottom
&& sect_off
< top
;
6626 /* Find the base address of the compilation unit for range lists and
6627 location lists. It will normally be specified by DW_AT_low_pc.
6628 In DWARF-3 draft 4, the base address could be overridden by
6629 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6630 compilation units with discontinuous ranges. */
6633 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6635 struct attribute
*attr
;
6638 cu
->base_address
= 0;
6640 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6643 cu
->base_address
= attr_value_as_address (attr
);
6648 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6651 cu
->base_address
= attr_value_as_address (attr
);
6657 /* Read in the comp unit header information from the debug_info at info_ptr.
6658 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6659 NOTE: This leaves members offset, first_die_offset to be filled in
6662 static const gdb_byte
*
6663 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6664 const gdb_byte
*info_ptr
,
6665 struct dwarf2_section_info
*section
,
6666 rcuh_kind section_kind
)
6669 unsigned int bytes_read
;
6670 const char *filename
= get_section_file_name (section
);
6671 bfd
*abfd
= get_section_bfd_owner (section
);
6673 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6674 cu_header
->initial_length_size
= bytes_read
;
6675 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6676 info_ptr
+= bytes_read
;
6677 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6679 if (cu_header
->version
< 5)
6680 switch (section_kind
)
6682 case rcuh_kind::COMPILE
:
6683 cu_header
->unit_type
= DW_UT_compile
;
6685 case rcuh_kind::TYPE
:
6686 cu_header
->unit_type
= DW_UT_type
;
6689 internal_error (__FILE__
, __LINE__
,
6690 _("read_comp_unit_head: invalid section_kind"));
6694 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6695 (read_1_byte (abfd
, info_ptr
));
6697 switch (cu_header
->unit_type
)
6700 if (section_kind
!= rcuh_kind::COMPILE
)
6701 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6702 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6706 section_kind
= rcuh_kind::TYPE
;
6709 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6710 "(is %d, should be %d or %d) [in module %s]"),
6711 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6714 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6717 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6720 info_ptr
+= bytes_read
;
6721 if (cu_header
->version
< 5)
6723 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6726 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6727 if (signed_addr
< 0)
6728 internal_error (__FILE__
, __LINE__
,
6729 _("read_comp_unit_head: dwarf from non elf file"));
6730 cu_header
->signed_addr_p
= signed_addr
;
6732 if (section_kind
== rcuh_kind::TYPE
)
6734 LONGEST type_offset
;
6736 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6739 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6740 info_ptr
+= bytes_read
;
6741 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6742 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6743 error (_("Dwarf Error: Too big type_offset in compilation unit "
6744 "header (is %s) [in module %s]"), plongest (type_offset
),
6751 /* Helper function that returns the proper abbrev section for
6754 static struct dwarf2_section_info
*
6755 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6757 struct dwarf2_section_info
*abbrev
;
6758 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6760 if (this_cu
->is_dwz
)
6761 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6763 abbrev
= &dwarf2_per_objfile
->abbrev
;
6768 /* Subroutine of read_and_check_comp_unit_head and
6769 read_and_check_type_unit_head to simplify them.
6770 Perform various error checking on the header. */
6773 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6774 struct comp_unit_head
*header
,
6775 struct dwarf2_section_info
*section
,
6776 struct dwarf2_section_info
*abbrev_section
)
6778 const char *filename
= get_section_file_name (section
);
6780 if (header
->version
< 2 || header
->version
> 5)
6781 error (_("Dwarf Error: wrong version in compilation unit header "
6782 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6785 if (to_underlying (header
->abbrev_sect_off
)
6786 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6787 error (_("Dwarf Error: bad offset (0x%x) in compilation unit header "
6788 "(offset 0x%x + 6) [in module %s]"),
6789 to_underlying (header
->abbrev_sect_off
),
6790 to_underlying (header
->sect_off
),
6793 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6794 avoid potential 32-bit overflow. */
6795 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6797 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6798 "(offset 0x%x + 0) [in module %s]"),
6799 header
->length
, to_underlying (header
->sect_off
),
6803 /* Read in a CU/TU header and perform some basic error checking.
6804 The contents of the header are stored in HEADER.
6805 The result is a pointer to the start of the first DIE. */
6807 static const gdb_byte
*
6808 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6809 struct comp_unit_head
*header
,
6810 struct dwarf2_section_info
*section
,
6811 struct dwarf2_section_info
*abbrev_section
,
6812 const gdb_byte
*info_ptr
,
6813 rcuh_kind section_kind
)
6815 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6817 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6819 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6821 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6823 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6829 /* Fetch the abbreviation table offset from a comp or type unit header. */
6832 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6833 struct dwarf2_section_info
*section
,
6834 sect_offset sect_off
)
6836 bfd
*abfd
= get_section_bfd_owner (section
);
6837 const gdb_byte
*info_ptr
;
6838 unsigned int initial_length_size
, offset_size
;
6841 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6842 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6843 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6844 offset_size
= initial_length_size
== 4 ? 4 : 8;
6845 info_ptr
+= initial_length_size
;
6847 version
= read_2_bytes (abfd
, info_ptr
);
6851 /* Skip unit type and address size. */
6855 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6858 /* Allocate a new partial symtab for file named NAME and mark this new
6859 partial symtab as being an include of PST. */
6862 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6863 struct objfile
*objfile
)
6865 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6867 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6869 /* It shares objfile->objfile_obstack. */
6870 subpst
->dirname
= pst
->dirname
;
6873 subpst
->textlow
= 0;
6874 subpst
->texthigh
= 0;
6876 subpst
->dependencies
6877 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6878 subpst
->dependencies
[0] = pst
;
6879 subpst
->number_of_dependencies
= 1;
6881 subpst
->globals_offset
= 0;
6882 subpst
->n_global_syms
= 0;
6883 subpst
->statics_offset
= 0;
6884 subpst
->n_static_syms
= 0;
6885 subpst
->compunit_symtab
= NULL
;
6886 subpst
->read_symtab
= pst
->read_symtab
;
6889 /* No private part is necessary for include psymtabs. This property
6890 can be used to differentiate between such include psymtabs and
6891 the regular ones. */
6892 subpst
->read_symtab_private
= NULL
;
6895 /* Read the Line Number Program data and extract the list of files
6896 included by the source file represented by PST. Build an include
6897 partial symtab for each of these included files. */
6900 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6901 struct die_info
*die
,
6902 struct partial_symtab
*pst
)
6905 struct attribute
*attr
;
6907 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6909 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6911 return; /* No linetable, so no includes. */
6913 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
6914 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
6918 hash_signatured_type (const void *item
)
6920 const struct signatured_type
*sig_type
6921 = (const struct signatured_type
*) item
;
6923 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6924 return sig_type
->signature
;
6928 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6930 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6931 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6933 return lhs
->signature
== rhs
->signature
;
6936 /* Allocate a hash table for signatured types. */
6939 allocate_signatured_type_table (struct objfile
*objfile
)
6941 return htab_create_alloc_ex (41,
6942 hash_signatured_type
,
6945 &objfile
->objfile_obstack
,
6946 hashtab_obstack_allocate
,
6947 dummy_obstack_deallocate
);
6950 /* A helper function to add a signatured type CU to a table. */
6953 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6955 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6956 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
6964 /* A helper for create_debug_types_hash_table. Read types from SECTION
6965 and fill them into TYPES_HTAB. It will process only type units,
6966 therefore DW_UT_type. */
6969 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6970 struct dwo_file
*dwo_file
,
6971 dwarf2_section_info
*section
, htab_t
&types_htab
,
6972 rcuh_kind section_kind
)
6974 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6975 struct dwarf2_section_info
*abbrev_section
;
6977 const gdb_byte
*info_ptr
, *end_ptr
;
6979 abbrev_section
= (dwo_file
!= NULL
6980 ? &dwo_file
->sections
.abbrev
6981 : &dwarf2_per_objfile
->abbrev
);
6983 if (dwarf_read_debug
)
6984 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6985 get_section_name (section
),
6986 get_section_file_name (abbrev_section
));
6988 dwarf2_read_section (objfile
, section
);
6989 info_ptr
= section
->buffer
;
6991 if (info_ptr
== NULL
)
6994 /* We can't set abfd until now because the section may be empty or
6995 not present, in which case the bfd is unknown. */
6996 abfd
= get_section_bfd_owner (section
);
6998 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6999 because we don't need to read any dies: the signature is in the
7002 end_ptr
= info_ptr
+ section
->size
;
7003 while (info_ptr
< end_ptr
)
7005 struct signatured_type
*sig_type
;
7006 struct dwo_unit
*dwo_tu
;
7008 const gdb_byte
*ptr
= info_ptr
;
7009 struct comp_unit_head header
;
7010 unsigned int length
;
7012 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
7014 /* Initialize it due to a false compiler warning. */
7015 header
.signature
= -1;
7016 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
7018 /* We need to read the type's signature in order to build the hash
7019 table, but we don't need anything else just yet. */
7021 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
7022 abbrev_section
, ptr
, section_kind
);
7024 length
= get_cu_length (&header
);
7026 /* Skip dummy type units. */
7027 if (ptr
>= info_ptr
+ length
7028 || peek_abbrev_code (abfd
, ptr
) == 0
7029 || header
.unit_type
!= DW_UT_type
)
7035 if (types_htab
== NULL
)
7038 types_htab
= allocate_dwo_unit_table (objfile
);
7040 types_htab
= allocate_signatured_type_table (objfile
);
7046 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7048 dwo_tu
->dwo_file
= dwo_file
;
7049 dwo_tu
->signature
= header
.signature
;
7050 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7051 dwo_tu
->section
= section
;
7052 dwo_tu
->sect_off
= sect_off
;
7053 dwo_tu
->length
= length
;
7057 /* N.B.: type_offset is not usable if this type uses a DWO file.
7058 The real type_offset is in the DWO file. */
7060 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7061 struct signatured_type
);
7062 sig_type
->signature
= header
.signature
;
7063 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7064 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7065 sig_type
->per_cu
.is_debug_types
= 1;
7066 sig_type
->per_cu
.section
= section
;
7067 sig_type
->per_cu
.sect_off
= sect_off
;
7068 sig_type
->per_cu
.length
= length
;
7071 slot
= htab_find_slot (types_htab
,
7072 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
7074 gdb_assert (slot
!= NULL
);
7077 sect_offset dup_sect_off
;
7081 const struct dwo_unit
*dup_tu
7082 = (const struct dwo_unit
*) *slot
;
7084 dup_sect_off
= dup_tu
->sect_off
;
7088 const struct signatured_type
*dup_tu
7089 = (const struct signatured_type
*) *slot
;
7091 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
7094 complaint (&symfile_complaints
,
7095 _("debug type entry at offset 0x%x is duplicate to"
7096 " the entry at offset 0x%x, signature %s"),
7097 to_underlying (sect_off
), to_underlying (dup_sect_off
),
7098 hex_string (header
.signature
));
7100 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
7102 if (dwarf_read_debug
> 1)
7103 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature %s\n",
7104 to_underlying (sect_off
),
7105 hex_string (header
.signature
));
7111 /* Create the hash table of all entries in the .debug_types
7112 (or .debug_types.dwo) section(s).
7113 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
7114 otherwise it is NULL.
7116 The result is a pointer to the hash table or NULL if there are no types.
7118 Note: This function processes DWO files only, not DWP files. */
7121 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7122 struct dwo_file
*dwo_file
,
7123 VEC (dwarf2_section_info_def
) *types
,
7127 struct dwarf2_section_info
*section
;
7129 if (VEC_empty (dwarf2_section_info_def
, types
))
7133 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
7135 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
7136 types_htab
, rcuh_kind::TYPE
);
7139 /* Create the hash table of all entries in the .debug_types section,
7140 and initialize all_type_units.
7141 The result is zero if there is an error (e.g. missing .debug_types section),
7142 otherwise non-zero. */
7145 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7147 htab_t types_htab
= NULL
;
7148 struct signatured_type
**iter
;
7150 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
7151 &dwarf2_per_objfile
->info
, types_htab
,
7152 rcuh_kind::COMPILE
);
7153 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
7154 dwarf2_per_objfile
->types
, types_htab
);
7155 if (types_htab
== NULL
)
7157 dwarf2_per_objfile
->signatured_types
= NULL
;
7161 dwarf2_per_objfile
->signatured_types
= types_htab
;
7163 dwarf2_per_objfile
->n_type_units
7164 = dwarf2_per_objfile
->n_allocated_type_units
7165 = htab_elements (types_htab
);
7166 dwarf2_per_objfile
->all_type_units
=
7167 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
7168 iter
= &dwarf2_per_objfile
->all_type_units
[0];
7169 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
7170 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
7171 == dwarf2_per_objfile
->n_type_units
);
7176 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
7177 If SLOT is non-NULL, it is the entry to use in the hash table.
7178 Otherwise we find one. */
7180 static struct signatured_type
*
7181 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
7184 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7185 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
7186 struct signatured_type
*sig_type
;
7188 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
7190 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
7192 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
7193 dwarf2_per_objfile
->n_allocated_type_units
= 1;
7194 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
7195 dwarf2_per_objfile
->all_type_units
7196 = XRESIZEVEC (struct signatured_type
*,
7197 dwarf2_per_objfile
->all_type_units
,
7198 dwarf2_per_objfile
->n_allocated_type_units
);
7199 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
7201 dwarf2_per_objfile
->n_type_units
= n_type_units
;
7203 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7204 struct signatured_type
);
7205 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
7206 sig_type
->signature
= sig
;
7207 sig_type
->per_cu
.is_debug_types
= 1;
7208 if (dwarf2_per_objfile
->using_index
)
7210 sig_type
->per_cu
.v
.quick
=
7211 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7212 struct dwarf2_per_cu_quick_data
);
7217 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7220 gdb_assert (*slot
== NULL
);
7222 /* The rest of sig_type must be filled in by the caller. */
7226 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7227 Fill in SIG_ENTRY with DWO_ENTRY. */
7230 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7231 struct signatured_type
*sig_entry
,
7232 struct dwo_unit
*dwo_entry
)
7234 /* Make sure we're not clobbering something we don't expect to. */
7235 gdb_assert (! sig_entry
->per_cu
.queued
);
7236 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7237 if (dwarf2_per_objfile
->using_index
)
7239 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7240 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7243 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7244 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7245 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7246 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7247 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7249 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7250 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7251 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7252 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7253 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7254 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7255 sig_entry
->dwo_unit
= dwo_entry
;
7258 /* Subroutine of lookup_signatured_type.
7259 If we haven't read the TU yet, create the signatured_type data structure
7260 for a TU to be read in directly from a DWO file, bypassing the stub.
7261 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7262 using .gdb_index, then when reading a CU we want to stay in the DWO file
7263 containing that CU. Otherwise we could end up reading several other DWO
7264 files (due to comdat folding) to process the transitive closure of all the
7265 mentioned TUs, and that can be slow. The current DWO file will have every
7266 type signature that it needs.
7267 We only do this for .gdb_index because in the psymtab case we already have
7268 to read all the DWOs to build the type unit groups. */
7270 static struct signatured_type
*
7271 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7273 struct dwarf2_per_objfile
*dwarf2_per_objfile
7274 = cu
->per_cu
->dwarf2_per_objfile
;
7275 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7276 struct dwo_file
*dwo_file
;
7277 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7278 struct signatured_type find_sig_entry
, *sig_entry
;
7281 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7283 /* If TU skeletons have been removed then we may not have read in any
7285 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7287 dwarf2_per_objfile
->signatured_types
7288 = allocate_signatured_type_table (objfile
);
7291 /* We only ever need to read in one copy of a signatured type.
7292 Use the global signatured_types array to do our own comdat-folding
7293 of types. If this is the first time we're reading this TU, and
7294 the TU has an entry in .gdb_index, replace the recorded data from
7295 .gdb_index with this TU. */
7297 find_sig_entry
.signature
= sig
;
7298 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7299 &find_sig_entry
, INSERT
);
7300 sig_entry
= (struct signatured_type
*) *slot
;
7302 /* We can get here with the TU already read, *or* in the process of being
7303 read. Don't reassign the global entry to point to this DWO if that's
7304 the case. Also note that if the TU is already being read, it may not
7305 have come from a DWO, the program may be a mix of Fission-compiled
7306 code and non-Fission-compiled code. */
7308 /* Have we already tried to read this TU?
7309 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7310 needn't exist in the global table yet). */
7311 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7314 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7315 dwo_unit of the TU itself. */
7316 dwo_file
= cu
->dwo_unit
->dwo_file
;
7318 /* Ok, this is the first time we're reading this TU. */
7319 if (dwo_file
->tus
== NULL
)
7321 find_dwo_entry
.signature
= sig
;
7322 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7323 if (dwo_entry
== NULL
)
7326 /* If the global table doesn't have an entry for this TU, add one. */
7327 if (sig_entry
== NULL
)
7328 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7330 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7331 sig_entry
->per_cu
.tu_read
= 1;
7335 /* Subroutine of lookup_signatured_type.
7336 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7337 then try the DWP file. If the TU stub (skeleton) has been removed then
7338 it won't be in .gdb_index. */
7340 static struct signatured_type
*
7341 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7343 struct dwarf2_per_objfile
*dwarf2_per_objfile
7344 = cu
->per_cu
->dwarf2_per_objfile
;
7345 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7346 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7347 struct dwo_unit
*dwo_entry
;
7348 struct signatured_type find_sig_entry
, *sig_entry
;
7351 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7352 gdb_assert (dwp_file
!= NULL
);
7354 /* If TU skeletons have been removed then we may not have read in any
7356 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7358 dwarf2_per_objfile
->signatured_types
7359 = allocate_signatured_type_table (objfile
);
7362 find_sig_entry
.signature
= sig
;
7363 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7364 &find_sig_entry
, INSERT
);
7365 sig_entry
= (struct signatured_type
*) *slot
;
7367 /* Have we already tried to read this TU?
7368 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7369 needn't exist in the global table yet). */
7370 if (sig_entry
!= NULL
)
7373 if (dwp_file
->tus
== NULL
)
7375 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7376 sig
, 1 /* is_debug_types */);
7377 if (dwo_entry
== NULL
)
7380 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7381 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7386 /* Lookup a signature based type for DW_FORM_ref_sig8.
7387 Returns NULL if signature SIG is not present in the table.
7388 It is up to the caller to complain about this. */
7390 static struct signatured_type
*
7391 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7393 struct dwarf2_per_objfile
*dwarf2_per_objfile
7394 = cu
->per_cu
->dwarf2_per_objfile
;
7397 && dwarf2_per_objfile
->using_index
)
7399 /* We're in a DWO/DWP file, and we're using .gdb_index.
7400 These cases require special processing. */
7401 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7402 return lookup_dwo_signatured_type (cu
, sig
);
7404 return lookup_dwp_signatured_type (cu
, sig
);
7408 struct signatured_type find_entry
, *entry
;
7410 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7412 find_entry
.signature
= sig
;
7413 entry
= ((struct signatured_type
*)
7414 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7419 /* Low level DIE reading support. */
7421 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7424 init_cu_die_reader (struct die_reader_specs
*reader
,
7425 struct dwarf2_cu
*cu
,
7426 struct dwarf2_section_info
*section
,
7427 struct dwo_file
*dwo_file
,
7428 struct abbrev_table
*abbrev_table
)
7430 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7431 reader
->abfd
= get_section_bfd_owner (section
);
7433 reader
->dwo_file
= dwo_file
;
7434 reader
->die_section
= section
;
7435 reader
->buffer
= section
->buffer
;
7436 reader
->buffer_end
= section
->buffer
+ section
->size
;
7437 reader
->comp_dir
= NULL
;
7438 reader
->abbrev_table
= abbrev_table
;
7441 /* Subroutine of init_cutu_and_read_dies to simplify it.
7442 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7443 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7446 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7447 from it to the DIE in the DWO. If NULL we are skipping the stub.
7448 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7449 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7450 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7451 STUB_COMP_DIR may be non-NULL.
7452 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7453 are filled in with the info of the DIE from the DWO file.
7454 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7455 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7456 kept around for at least as long as *RESULT_READER.
7458 The result is non-zero if a valid (non-dummy) DIE was found. */
7461 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7462 struct dwo_unit
*dwo_unit
,
7463 struct die_info
*stub_comp_unit_die
,
7464 const char *stub_comp_dir
,
7465 struct die_reader_specs
*result_reader
,
7466 const gdb_byte
**result_info_ptr
,
7467 struct die_info
**result_comp_unit_die
,
7468 int *result_has_children
,
7469 abbrev_table_up
*result_dwo_abbrev_table
)
7471 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7472 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7473 struct dwarf2_cu
*cu
= this_cu
->cu
;
7475 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7476 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7477 int i
,num_extra_attrs
;
7478 struct dwarf2_section_info
*dwo_abbrev_section
;
7479 struct attribute
*attr
;
7480 struct die_info
*comp_unit_die
;
7482 /* At most one of these may be provided. */
7483 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7485 /* These attributes aren't processed until later:
7486 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7487 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7488 referenced later. However, these attributes are found in the stub
7489 which we won't have later. In order to not impose this complication
7490 on the rest of the code, we read them here and copy them to the
7499 if (stub_comp_unit_die
!= NULL
)
7501 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7503 if (! this_cu
->is_debug_types
)
7504 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7505 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7506 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7507 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7508 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7510 /* There should be a DW_AT_addr_base attribute here (if needed).
7511 We need the value before we can process DW_FORM_GNU_addr_index. */
7513 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7515 cu
->addr_base
= DW_UNSND (attr
);
7517 /* There should be a DW_AT_ranges_base attribute here (if needed).
7518 We need the value before we can process DW_AT_ranges. */
7519 cu
->ranges_base
= 0;
7520 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7522 cu
->ranges_base
= DW_UNSND (attr
);
7524 else if (stub_comp_dir
!= NULL
)
7526 /* Reconstruct the comp_dir attribute to simplify the code below. */
7527 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7528 comp_dir
->name
= DW_AT_comp_dir
;
7529 comp_dir
->form
= DW_FORM_string
;
7530 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7531 DW_STRING (comp_dir
) = stub_comp_dir
;
7534 /* Set up for reading the DWO CU/TU. */
7535 cu
->dwo_unit
= dwo_unit
;
7536 dwarf2_section_info
*section
= dwo_unit
->section
;
7537 dwarf2_read_section (objfile
, section
);
7538 abfd
= get_section_bfd_owner (section
);
7539 begin_info_ptr
= info_ptr
= (section
->buffer
7540 + to_underlying (dwo_unit
->sect_off
));
7541 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7543 if (this_cu
->is_debug_types
)
7545 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7547 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7548 &cu
->header
, section
,
7550 info_ptr
, rcuh_kind::TYPE
);
7551 /* This is not an assert because it can be caused by bad debug info. */
7552 if (sig_type
->signature
!= cu
->header
.signature
)
7554 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7555 " TU at offset 0x%x [in module %s]"),
7556 hex_string (sig_type
->signature
),
7557 hex_string (cu
->header
.signature
),
7558 to_underlying (dwo_unit
->sect_off
),
7559 bfd_get_filename (abfd
));
7561 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7562 /* For DWOs coming from DWP files, we don't know the CU length
7563 nor the type's offset in the TU until now. */
7564 dwo_unit
->length
= get_cu_length (&cu
->header
);
7565 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7567 /* Establish the type offset that can be used to lookup the type.
7568 For DWO files, we don't know it until now. */
7569 sig_type
->type_offset_in_section
7570 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7574 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7575 &cu
->header
, section
,
7577 info_ptr
, rcuh_kind::COMPILE
);
7578 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7579 /* For DWOs coming from DWP files, we don't know the CU length
7581 dwo_unit
->length
= get_cu_length (&cu
->header
);
7584 *result_dwo_abbrev_table
7585 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7586 cu
->header
.abbrev_sect_off
);
7587 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7588 result_dwo_abbrev_table
->get ());
7590 /* Read in the die, but leave space to copy over the attributes
7591 from the stub. This has the benefit of simplifying the rest of
7592 the code - all the work to maintain the illusion of a single
7593 DW_TAG_{compile,type}_unit DIE is done here. */
7594 num_extra_attrs
= ((stmt_list
!= NULL
)
7598 + (comp_dir
!= NULL
));
7599 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7600 result_has_children
, num_extra_attrs
);
7602 /* Copy over the attributes from the stub to the DIE we just read in. */
7603 comp_unit_die
= *result_comp_unit_die
;
7604 i
= comp_unit_die
->num_attrs
;
7605 if (stmt_list
!= NULL
)
7606 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7608 comp_unit_die
->attrs
[i
++] = *low_pc
;
7609 if (high_pc
!= NULL
)
7610 comp_unit_die
->attrs
[i
++] = *high_pc
;
7612 comp_unit_die
->attrs
[i
++] = *ranges
;
7613 if (comp_dir
!= NULL
)
7614 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7615 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7617 if (dwarf_die_debug
)
7619 fprintf_unfiltered (gdb_stdlog
,
7620 "Read die from %s@0x%x of %s:\n",
7621 get_section_name (section
),
7622 (unsigned) (begin_info_ptr
- section
->buffer
),
7623 bfd_get_filename (abfd
));
7624 dump_die (comp_unit_die
, dwarf_die_debug
);
7627 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7628 TUs by skipping the stub and going directly to the entry in the DWO file.
7629 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7630 to get it via circuitous means. Blech. */
7631 if (comp_dir
!= NULL
)
7632 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7634 /* Skip dummy compilation units. */
7635 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7636 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7639 *result_info_ptr
= info_ptr
;
7643 /* Subroutine of init_cutu_and_read_dies to simplify it.
7644 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7645 Returns NULL if the specified DWO unit cannot be found. */
7647 static struct dwo_unit
*
7648 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7649 struct die_info
*comp_unit_die
)
7651 struct dwarf2_cu
*cu
= this_cu
->cu
;
7653 struct dwo_unit
*dwo_unit
;
7654 const char *comp_dir
, *dwo_name
;
7656 gdb_assert (cu
!= NULL
);
7658 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7659 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7660 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7662 if (this_cu
->is_debug_types
)
7664 struct signatured_type
*sig_type
;
7666 /* Since this_cu is the first member of struct signatured_type,
7667 we can go from a pointer to one to a pointer to the other. */
7668 sig_type
= (struct signatured_type
*) this_cu
;
7669 signature
= sig_type
->signature
;
7670 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7674 struct attribute
*attr
;
7676 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7678 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7680 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7681 signature
= DW_UNSND (attr
);
7682 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7689 /* Subroutine of init_cutu_and_read_dies to simplify it.
7690 See it for a description of the parameters.
7691 Read a TU directly from a DWO file, bypassing the stub. */
7694 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7695 int use_existing_cu
, int keep
,
7696 die_reader_func_ftype
*die_reader_func
,
7699 std::unique_ptr
<dwarf2_cu
> new_cu
;
7700 struct signatured_type
*sig_type
;
7701 struct die_reader_specs reader
;
7702 const gdb_byte
*info_ptr
;
7703 struct die_info
*comp_unit_die
;
7705 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7707 /* Verify we can do the following downcast, and that we have the
7709 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7710 sig_type
= (struct signatured_type
*) this_cu
;
7711 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7713 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7715 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7716 /* There's no need to do the rereading_dwo_cu handling that
7717 init_cutu_and_read_dies does since we don't read the stub. */
7721 /* If !use_existing_cu, this_cu->cu must be NULL. */
7722 gdb_assert (this_cu
->cu
== NULL
);
7723 new_cu
.reset (new dwarf2_cu (this_cu
));
7726 /* A future optimization, if needed, would be to use an existing
7727 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7728 could share abbrev tables. */
7730 /* The abbreviation table used by READER, this must live at least as long as
7732 abbrev_table_up dwo_abbrev_table
;
7734 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7735 NULL
/* stub_comp_unit_die */,
7736 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7738 &comp_unit_die
, &has_children
,
7739 &dwo_abbrev_table
) == 0)
7745 /* All the "real" work is done here. */
7746 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7748 /* This duplicates the code in init_cutu_and_read_dies,
7749 but the alternative is making the latter more complex.
7750 This function is only for the special case of using DWO files directly:
7751 no point in overly complicating the general case just to handle this. */
7752 if (new_cu
!= NULL
&& keep
)
7754 /* Link this CU into read_in_chain. */
7755 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7756 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7757 /* The chain owns it now. */
7762 /* Initialize a CU (or TU) and read its DIEs.
7763 If the CU defers to a DWO file, read the DWO file as well.
7765 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7766 Otherwise the table specified in the comp unit header is read in and used.
7767 This is an optimization for when we already have the abbrev table.
7769 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7770 Otherwise, a new CU is allocated with xmalloc.
7772 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7773 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7775 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7776 linker) then DIE_READER_FUNC will not get called. */
7779 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7780 struct abbrev_table
*abbrev_table
,
7781 int use_existing_cu
, int keep
,
7782 die_reader_func_ftype
*die_reader_func
,
7785 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7786 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7787 struct dwarf2_section_info
*section
= this_cu
->section
;
7788 bfd
*abfd
= get_section_bfd_owner (section
);
7789 struct dwarf2_cu
*cu
;
7790 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7791 struct die_reader_specs reader
;
7792 struct die_info
*comp_unit_die
;
7794 struct attribute
*attr
;
7795 struct signatured_type
*sig_type
= NULL
;
7796 struct dwarf2_section_info
*abbrev_section
;
7797 /* Non-zero if CU currently points to a DWO file and we need to
7798 reread it. When this happens we need to reread the skeleton die
7799 before we can reread the DWO file (this only applies to CUs, not TUs). */
7800 int rereading_dwo_cu
= 0;
7802 if (dwarf_die_debug
)
7803 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
7804 this_cu
->is_debug_types
? "type" : "comp",
7805 to_underlying (this_cu
->sect_off
));
7807 if (use_existing_cu
)
7810 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7811 file (instead of going through the stub), short-circuit all of this. */
7812 if (this_cu
->reading_dwo_directly
)
7814 /* Narrow down the scope of possibilities to have to understand. */
7815 gdb_assert (this_cu
->is_debug_types
);
7816 gdb_assert (abbrev_table
== NULL
);
7817 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7818 die_reader_func
, data
);
7822 /* This is cheap if the section is already read in. */
7823 dwarf2_read_section (objfile
, section
);
7825 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7827 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7829 std::unique_ptr
<dwarf2_cu
> new_cu
;
7830 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7833 /* If this CU is from a DWO file we need to start over, we need to
7834 refetch the attributes from the skeleton CU.
7835 This could be optimized by retrieving those attributes from when we
7836 were here the first time: the previous comp_unit_die was stored in
7837 comp_unit_obstack. But there's no data yet that we need this
7839 if (cu
->dwo_unit
!= NULL
)
7840 rereading_dwo_cu
= 1;
7844 /* If !use_existing_cu, this_cu->cu must be NULL. */
7845 gdb_assert (this_cu
->cu
== NULL
);
7846 new_cu
.reset (new dwarf2_cu (this_cu
));
7850 /* Get the header. */
7851 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7853 /* We already have the header, there's no need to read it in again. */
7854 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7858 if (this_cu
->is_debug_types
)
7860 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7861 &cu
->header
, section
,
7862 abbrev_section
, info_ptr
,
7865 /* Since per_cu is the first member of struct signatured_type,
7866 we can go from a pointer to one to a pointer to the other. */
7867 sig_type
= (struct signatured_type
*) this_cu
;
7868 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7869 gdb_assert (sig_type
->type_offset_in_tu
7870 == cu
->header
.type_cu_offset_in_tu
);
7871 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7873 /* LENGTH has not been set yet for type units if we're
7874 using .gdb_index. */
7875 this_cu
->length
= get_cu_length (&cu
->header
);
7877 /* Establish the type offset that can be used to lookup the type. */
7878 sig_type
->type_offset_in_section
=
7879 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7881 this_cu
->dwarf_version
= cu
->header
.version
;
7885 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7886 &cu
->header
, section
,
7889 rcuh_kind::COMPILE
);
7891 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7892 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7893 this_cu
->dwarf_version
= cu
->header
.version
;
7897 /* Skip dummy compilation units. */
7898 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7899 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7902 /* If we don't have them yet, read the abbrevs for this compilation unit.
7903 And if we need to read them now, make sure they're freed when we're
7904 done (own the table through ABBREV_TABLE_HOLDER). */
7905 abbrev_table_up abbrev_table_holder
;
7906 if (abbrev_table
!= NULL
)
7907 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7911 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7912 cu
->header
.abbrev_sect_off
);
7913 abbrev_table
= abbrev_table_holder
.get ();
7916 /* Read the top level CU/TU die. */
7917 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7918 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7920 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7921 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7922 table from the DWO file and pass the ownership over to us. It will be
7923 referenced from READER, so we must make sure to free it after we're done
7926 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7927 DWO CU, that this test will fail (the attribute will not be present). */
7928 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7929 abbrev_table_up dwo_abbrev_table
;
7932 struct dwo_unit
*dwo_unit
;
7933 struct die_info
*dwo_comp_unit_die
;
7937 complaint (&symfile_complaints
,
7938 _("compilation unit with DW_AT_GNU_dwo_name"
7939 " has children (offset 0x%x) [in module %s]"),
7940 to_underlying (this_cu
->sect_off
), bfd_get_filename (abfd
));
7942 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7943 if (dwo_unit
!= NULL
)
7945 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7946 comp_unit_die
, NULL
,
7948 &dwo_comp_unit_die
, &has_children
,
7949 &dwo_abbrev_table
) == 0)
7954 comp_unit_die
= dwo_comp_unit_die
;
7958 /* Yikes, we couldn't find the rest of the DIE, we only have
7959 the stub. A complaint has already been logged. There's
7960 not much more we can do except pass on the stub DIE to
7961 die_reader_func. We don't want to throw an error on bad
7966 /* All of the above is setup for this call. Yikes. */
7967 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7969 /* Done, clean up. */
7970 if (new_cu
!= NULL
&& keep
)
7972 /* Link this CU into read_in_chain. */
7973 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7974 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7975 /* The chain owns it now. */
7980 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7981 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7982 to have already done the lookup to find the DWO file).
7984 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7985 THIS_CU->is_debug_types, but nothing else.
7987 We fill in THIS_CU->length.
7989 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7990 linker) then DIE_READER_FUNC will not get called.
7992 THIS_CU->cu is always freed when done.
7993 This is done in order to not leave THIS_CU->cu in a state where we have
7994 to care whether it refers to the "main" CU or the DWO CU. */
7997 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7998 struct dwo_file
*dwo_file
,
7999 die_reader_func_ftype
*die_reader_func
,
8002 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
8003 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8004 struct dwarf2_section_info
*section
= this_cu
->section
;
8005 bfd
*abfd
= get_section_bfd_owner (section
);
8006 struct dwarf2_section_info
*abbrev_section
;
8007 const gdb_byte
*begin_info_ptr
, *info_ptr
;
8008 struct die_reader_specs reader
;
8009 struct die_info
*comp_unit_die
;
8012 if (dwarf_die_debug
)
8013 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset 0x%x\n",
8014 this_cu
->is_debug_types
? "type" : "comp",
8015 to_underlying (this_cu
->sect_off
));
8017 gdb_assert (this_cu
->cu
== NULL
);
8019 abbrev_section
= (dwo_file
!= NULL
8020 ? &dwo_file
->sections
.abbrev
8021 : get_abbrev_section_for_cu (this_cu
));
8023 /* This is cheap if the section is already read in. */
8024 dwarf2_read_section (objfile
, section
);
8026 struct dwarf2_cu
cu (this_cu
);
8028 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
8029 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
8030 &cu
.header
, section
,
8031 abbrev_section
, info_ptr
,
8032 (this_cu
->is_debug_types
8034 : rcuh_kind::COMPILE
));
8036 this_cu
->length
= get_cu_length (&cu
.header
);
8038 /* Skip dummy compilation units. */
8039 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
8040 || peek_abbrev_code (abfd
, info_ptr
) == 0)
8043 abbrev_table_up abbrev_table
8044 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
8045 cu
.header
.abbrev_sect_off
);
8047 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
8048 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
8050 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8053 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
8054 does not lookup the specified DWO file.
8055 This cannot be used to read DWO files.
8057 THIS_CU->cu is always freed when done.
8058 This is done in order to not leave THIS_CU->cu in a state where we have
8059 to care whether it refers to the "main" CU or the DWO CU.
8060 We can revisit this if the data shows there's a performance issue. */
8063 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
8064 die_reader_func_ftype
*die_reader_func
,
8067 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
8070 /* Type Unit Groups.
8072 Type Unit Groups are a way to collapse the set of all TUs (type units) into
8073 a more manageable set. The grouping is done by DW_AT_stmt_list entry
8074 so that all types coming from the same compilation (.o file) are grouped
8075 together. A future step could be to put the types in the same symtab as
8076 the CU the types ultimately came from. */
8079 hash_type_unit_group (const void *item
)
8081 const struct type_unit_group
*tu_group
8082 = (const struct type_unit_group
*) item
;
8084 return hash_stmt_list_entry (&tu_group
->hash
);
8088 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
8090 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
8091 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
8093 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
8096 /* Allocate a hash table for type unit groups. */
8099 allocate_type_unit_groups_table (struct objfile
*objfile
)
8101 return htab_create_alloc_ex (3,
8102 hash_type_unit_group
,
8105 &objfile
->objfile_obstack
,
8106 hashtab_obstack_allocate
,
8107 dummy_obstack_deallocate
);
8110 /* Type units that don't have DW_AT_stmt_list are grouped into their own
8111 partial symtabs. We combine several TUs per psymtab to not let the size
8112 of any one psymtab grow too big. */
8113 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
8114 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
8116 /* Helper routine for get_type_unit_group.
8117 Create the type_unit_group object used to hold one or more TUs. */
8119 static struct type_unit_group
*
8120 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
8122 struct dwarf2_per_objfile
*dwarf2_per_objfile
8123 = cu
->per_cu
->dwarf2_per_objfile
;
8124 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8125 struct dwarf2_per_cu_data
*per_cu
;
8126 struct type_unit_group
*tu_group
;
8128 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8129 struct type_unit_group
);
8130 per_cu
= &tu_group
->per_cu
;
8131 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8133 if (dwarf2_per_objfile
->using_index
)
8135 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8136 struct dwarf2_per_cu_quick_data
);
8140 unsigned int line_offset
= to_underlying (line_offset_struct
);
8141 struct partial_symtab
*pst
;
8144 /* Give the symtab a useful name for debug purposes. */
8145 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
8146 name
= xstrprintf ("<type_units_%d>",
8147 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
8149 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
8151 pst
= create_partial_symtab (per_cu
, name
);
8157 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
8158 tu_group
->hash
.line_sect_off
= line_offset_struct
;
8163 /* Look up the type_unit_group for type unit CU, and create it if necessary.
8164 STMT_LIST is a DW_AT_stmt_list attribute. */
8166 static struct type_unit_group
*
8167 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
8169 struct dwarf2_per_objfile
*dwarf2_per_objfile
8170 = cu
->per_cu
->dwarf2_per_objfile
;
8171 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8172 struct type_unit_group
*tu_group
;
8174 unsigned int line_offset
;
8175 struct type_unit_group type_unit_group_for_lookup
;
8177 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
8179 dwarf2_per_objfile
->type_unit_groups
=
8180 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
8183 /* Do we need to create a new group, or can we use an existing one? */
8187 line_offset
= DW_UNSND (stmt_list
);
8188 ++tu_stats
->nr_symtab_sharers
;
8192 /* Ugh, no stmt_list. Rare, but we have to handle it.
8193 We can do various things here like create one group per TU or
8194 spread them over multiple groups to split up the expansion work.
8195 To avoid worst case scenarios (too many groups or too large groups)
8196 we, umm, group them in bunches. */
8197 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
8198 | (tu_stats
->nr_stmt_less_type_units
8199 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
8200 ++tu_stats
->nr_stmt_less_type_units
;
8203 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
8204 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
8205 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
8206 &type_unit_group_for_lookup
, INSERT
);
8209 tu_group
= (struct type_unit_group
*) *slot
;
8210 gdb_assert (tu_group
!= NULL
);
8214 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8215 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8217 ++tu_stats
->nr_symtabs
;
8223 /* Partial symbol tables. */
8225 /* Create a psymtab named NAME and assign it to PER_CU.
8227 The caller must fill in the following details:
8228 dirname, textlow, texthigh. */
8230 static struct partial_symtab
*
8231 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8233 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8234 struct partial_symtab
*pst
;
8236 pst
= start_psymtab_common (objfile
, name
, 0,
8237 objfile
->global_psymbols
,
8238 objfile
->static_psymbols
);
8240 pst
->psymtabs_addrmap_supported
= 1;
8242 /* This is the glue that links PST into GDB's symbol API. */
8243 pst
->read_symtab_private
= per_cu
;
8244 pst
->read_symtab
= dwarf2_read_symtab
;
8245 per_cu
->v
.psymtab
= pst
;
8250 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8253 struct process_psymtab_comp_unit_data
8255 /* True if we are reading a DW_TAG_partial_unit. */
8257 int want_partial_unit
;
8259 /* The "pretend" language that is used if the CU doesn't declare a
8262 enum language pretend_language
;
8265 /* die_reader_func for process_psymtab_comp_unit. */
8268 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8269 const gdb_byte
*info_ptr
,
8270 struct die_info
*comp_unit_die
,
8274 struct dwarf2_cu
*cu
= reader
->cu
;
8275 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8276 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8277 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8279 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8280 struct partial_symtab
*pst
;
8281 enum pc_bounds_kind cu_bounds_kind
;
8282 const char *filename
;
8283 struct process_psymtab_comp_unit_data
*info
8284 = (struct process_psymtab_comp_unit_data
*) data
;
8286 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8289 gdb_assert (! per_cu
->is_debug_types
);
8291 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8293 cu
->list_in_scope
= &file_symbols
;
8295 /* Allocate a new partial symbol table structure. */
8296 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8297 if (filename
== NULL
)
8300 pst
= create_partial_symtab (per_cu
, filename
);
8302 /* This must be done before calling dwarf2_build_include_psymtabs. */
8303 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8305 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8307 dwarf2_find_base_address (comp_unit_die
, cu
);
8309 /* Possibly set the default values of LOWPC and HIGHPC from
8311 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8312 &best_highpc
, cu
, pst
);
8313 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8314 /* Store the contiguous range if it is not empty; it can be empty for
8315 CUs with no code. */
8316 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8317 gdbarch_adjust_dwarf2_addr (gdbarch
,
8318 best_lowpc
+ baseaddr
),
8319 gdbarch_adjust_dwarf2_addr (gdbarch
,
8320 best_highpc
+ baseaddr
) - 1,
8323 /* Check if comp unit has_children.
8324 If so, read the rest of the partial symbols from this comp unit.
8325 If not, there's no more debug_info for this comp unit. */
8328 struct partial_die_info
*first_die
;
8329 CORE_ADDR lowpc
, highpc
;
8331 lowpc
= ((CORE_ADDR
) -1);
8332 highpc
= ((CORE_ADDR
) 0);
8334 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8336 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8337 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8339 /* If we didn't find a lowpc, set it to highpc to avoid
8340 complaints from `maint check'. */
8341 if (lowpc
== ((CORE_ADDR
) -1))
8344 /* If the compilation unit didn't have an explicit address range,
8345 then use the information extracted from its child dies. */
8346 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8349 best_highpc
= highpc
;
8352 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
8353 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
8355 end_psymtab_common (objfile
, pst
);
8357 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8360 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8361 struct dwarf2_per_cu_data
*iter
;
8363 /* Fill in 'dependencies' here; we fill in 'users' in a
8365 pst
->number_of_dependencies
= len
;
8367 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8369 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8372 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8374 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8377 /* Get the list of files included in the current compilation unit,
8378 and build a psymtab for each of them. */
8379 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8381 if (dwarf_read_debug
)
8383 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8385 fprintf_unfiltered (gdb_stdlog
,
8386 "Psymtab for %s unit @0x%x: %s - %s"
8387 ", %d global, %d static syms\n",
8388 per_cu
->is_debug_types
? "type" : "comp",
8389 to_underlying (per_cu
->sect_off
),
8390 paddress (gdbarch
, pst
->textlow
),
8391 paddress (gdbarch
, pst
->texthigh
),
8392 pst
->n_global_syms
, pst
->n_static_syms
);
8396 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8397 Process compilation unit THIS_CU for a psymtab. */
8400 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8401 int want_partial_unit
,
8402 enum language pretend_language
)
8404 /* If this compilation unit was already read in, free the
8405 cached copy in order to read it in again. This is
8406 necessary because we skipped some symbols when we first
8407 read in the compilation unit (see load_partial_dies).
8408 This problem could be avoided, but the benefit is unclear. */
8409 if (this_cu
->cu
!= NULL
)
8410 free_one_cached_comp_unit (this_cu
);
8412 if (this_cu
->is_debug_types
)
8413 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8417 process_psymtab_comp_unit_data info
;
8418 info
.want_partial_unit
= want_partial_unit
;
8419 info
.pretend_language
= pretend_language
;
8420 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8421 process_psymtab_comp_unit_reader
, &info
);
8424 /* Age out any secondary CUs. */
8425 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8428 /* Reader function for build_type_psymtabs. */
8431 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8432 const gdb_byte
*info_ptr
,
8433 struct die_info
*type_unit_die
,
8437 struct dwarf2_per_objfile
*dwarf2_per_objfile
8438 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8439 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8440 struct dwarf2_cu
*cu
= reader
->cu
;
8441 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8442 struct signatured_type
*sig_type
;
8443 struct type_unit_group
*tu_group
;
8444 struct attribute
*attr
;
8445 struct partial_die_info
*first_die
;
8446 CORE_ADDR lowpc
, highpc
;
8447 struct partial_symtab
*pst
;
8449 gdb_assert (data
== NULL
);
8450 gdb_assert (per_cu
->is_debug_types
);
8451 sig_type
= (struct signatured_type
*) per_cu
;
8456 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8457 tu_group
= get_type_unit_group (cu
, attr
);
8459 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8461 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8462 cu
->list_in_scope
= &file_symbols
;
8463 pst
= create_partial_symtab (per_cu
, "");
8466 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8468 lowpc
= (CORE_ADDR
) -1;
8469 highpc
= (CORE_ADDR
) 0;
8470 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8472 end_psymtab_common (objfile
, pst
);
8475 /* Struct used to sort TUs by their abbreviation table offset. */
8477 struct tu_abbrev_offset
8479 struct signatured_type
*sig_type
;
8480 sect_offset abbrev_offset
;
8483 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
8486 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
8488 const struct tu_abbrev_offset
* const *a
8489 = (const struct tu_abbrev_offset
* const*) ap
;
8490 const struct tu_abbrev_offset
* const *b
8491 = (const struct tu_abbrev_offset
* const*) bp
;
8492 sect_offset aoff
= (*a
)->abbrev_offset
;
8493 sect_offset boff
= (*b
)->abbrev_offset
;
8495 return (aoff
> boff
) - (aoff
< boff
);
8498 /* Efficiently read all the type units.
8499 This does the bulk of the work for build_type_psymtabs.
8501 The efficiency is because we sort TUs by the abbrev table they use and
8502 only read each abbrev table once. In one program there are 200K TUs
8503 sharing 8K abbrev tables.
8505 The main purpose of this function is to support building the
8506 dwarf2_per_objfile->type_unit_groups table.
8507 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8508 can collapse the search space by grouping them by stmt_list.
8509 The savings can be significant, in the same program from above the 200K TUs
8510 share 8K stmt_list tables.
8512 FUNC is expected to call get_type_unit_group, which will create the
8513 struct type_unit_group if necessary and add it to
8514 dwarf2_per_objfile->type_unit_groups. */
8517 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8519 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8520 struct cleanup
*cleanups
;
8521 abbrev_table_up abbrev_table
;
8522 sect_offset abbrev_offset
;
8523 struct tu_abbrev_offset
*sorted_by_abbrev
;
8526 /* It's up to the caller to not call us multiple times. */
8527 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8529 if (dwarf2_per_objfile
->n_type_units
== 0)
8532 /* TUs typically share abbrev tables, and there can be way more TUs than
8533 abbrev tables. Sort by abbrev table to reduce the number of times we
8534 read each abbrev table in.
8535 Alternatives are to punt or to maintain a cache of abbrev tables.
8536 This is simpler and efficient enough for now.
8538 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8539 symtab to use). Typically TUs with the same abbrev offset have the same
8540 stmt_list value too so in practice this should work well.
8542 The basic algorithm here is:
8544 sort TUs by abbrev table
8545 for each TU with same abbrev table:
8546 read abbrev table if first user
8547 read TU top level DIE
8548 [IWBN if DWO skeletons had DW_AT_stmt_list]
8551 if (dwarf_read_debug
)
8552 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8554 /* Sort in a separate table to maintain the order of all_type_units
8555 for .gdb_index: TU indices directly index all_type_units. */
8556 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
8557 dwarf2_per_objfile
->n_type_units
);
8558 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8560 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
8562 sorted_by_abbrev
[i
].sig_type
= sig_type
;
8563 sorted_by_abbrev
[i
].abbrev_offset
=
8564 read_abbrev_offset (dwarf2_per_objfile
,
8565 sig_type
->per_cu
.section
,
8566 sig_type
->per_cu
.sect_off
);
8568 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
8569 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
8570 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
8572 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8574 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8576 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
8578 /* Switch to the next abbrev table if necessary. */
8579 if (abbrev_table
== NULL
8580 || tu
->abbrev_offset
!= abbrev_offset
)
8582 abbrev_offset
= tu
->abbrev_offset
;
8584 abbrev_table_read_table (dwarf2_per_objfile
,
8585 &dwarf2_per_objfile
->abbrev
,
8587 ++tu_stats
->nr_uniq_abbrev_tables
;
8590 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
.get (),
8591 0, 0, build_type_psymtabs_reader
, NULL
);
8594 do_cleanups (cleanups
);
8597 /* Print collected type unit statistics. */
8600 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8602 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8604 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8605 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
8606 dwarf2_per_objfile
->n_type_units
);
8607 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8608 tu_stats
->nr_uniq_abbrev_tables
);
8609 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8610 tu_stats
->nr_symtabs
);
8611 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8612 tu_stats
->nr_symtab_sharers
);
8613 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8614 tu_stats
->nr_stmt_less_type_units
);
8615 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8616 tu_stats
->nr_all_type_units_reallocs
);
8619 /* Traversal function for build_type_psymtabs. */
8622 build_type_psymtab_dependencies (void **slot
, void *info
)
8624 struct dwarf2_per_objfile
*dwarf2_per_objfile
8625 = (struct dwarf2_per_objfile
*) info
;
8626 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8627 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8628 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8629 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8630 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8631 struct signatured_type
*iter
;
8634 gdb_assert (len
> 0);
8635 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8637 pst
->number_of_dependencies
= len
;
8639 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8641 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8644 gdb_assert (iter
->per_cu
.is_debug_types
);
8645 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8646 iter
->type_unit_group
= tu_group
;
8649 VEC_free (sig_type_ptr
, tu_group
->tus
);
8654 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8655 Build partial symbol tables for the .debug_types comp-units. */
8658 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8660 if (! create_all_type_units (dwarf2_per_objfile
))
8663 build_type_psymtabs_1 (dwarf2_per_objfile
);
8666 /* Traversal function for process_skeletonless_type_unit.
8667 Read a TU in a DWO file and build partial symbols for it. */
8670 process_skeletonless_type_unit (void **slot
, void *info
)
8672 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8673 struct dwarf2_per_objfile
*dwarf2_per_objfile
8674 = (struct dwarf2_per_objfile
*) info
;
8675 struct signatured_type find_entry
, *entry
;
8677 /* If this TU doesn't exist in the global table, add it and read it in. */
8679 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8681 dwarf2_per_objfile
->signatured_types
8682 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8685 find_entry
.signature
= dwo_unit
->signature
;
8686 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8688 /* If we've already seen this type there's nothing to do. What's happening
8689 is we're doing our own version of comdat-folding here. */
8693 /* This does the job that create_all_type_units would have done for
8695 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8696 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8699 /* This does the job that build_type_psymtabs_1 would have done. */
8700 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8701 build_type_psymtabs_reader
, NULL
);
8706 /* Traversal function for process_skeletonless_type_units. */
8709 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8711 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8713 if (dwo_file
->tus
!= NULL
)
8715 htab_traverse_noresize (dwo_file
->tus
,
8716 process_skeletonless_type_unit
, info
);
8722 /* Scan all TUs of DWO files, verifying we've processed them.
8723 This is needed in case a TU was emitted without its skeleton.
8724 Note: This can't be done until we know what all the DWO files are. */
8727 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8729 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8730 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8731 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8733 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8734 process_dwo_file_for_skeletonless_type_units
,
8735 dwarf2_per_objfile
);
8739 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8742 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8746 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8748 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8749 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8755 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8757 /* Set the 'user' field only if it is not already set. */
8758 if (pst
->dependencies
[j
]->user
== NULL
)
8759 pst
->dependencies
[j
]->user
= pst
;
8764 /* Build the partial symbol table by doing a quick pass through the
8765 .debug_info and .debug_abbrev sections. */
8768 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8770 struct cleanup
*back_to
;
8772 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8774 if (dwarf_read_debug
)
8776 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8777 objfile_name (objfile
));
8780 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8782 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8784 /* Any cached compilation units will be linked by the per-objfile
8785 read_in_chain. Make sure to free them when we're done. */
8786 back_to
= make_cleanup (free_cached_comp_units
, dwarf2_per_objfile
);
8788 build_type_psymtabs (dwarf2_per_objfile
);
8790 create_all_comp_units (dwarf2_per_objfile
);
8792 /* Create a temporary address map on a temporary obstack. We later
8793 copy this to the final obstack. */
8794 auto_obstack temp_obstack
;
8796 scoped_restore save_psymtabs_addrmap
8797 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8798 addrmap_create_mutable (&temp_obstack
));
8800 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8802 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8804 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8807 /* This has to wait until we read the CUs, we need the list of DWOs. */
8808 process_skeletonless_type_units (dwarf2_per_objfile
);
8810 /* Now that all TUs have been processed we can fill in the dependencies. */
8811 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8813 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8814 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8817 if (dwarf_read_debug
)
8818 print_tu_stats (dwarf2_per_objfile
);
8820 set_partial_user (dwarf2_per_objfile
);
8822 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8823 &objfile
->objfile_obstack
);
8824 /* At this point we want to keep the address map. */
8825 save_psymtabs_addrmap
.release ();
8827 do_cleanups (back_to
);
8829 if (dwarf_read_debug
)
8830 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8831 objfile_name (objfile
));
8834 /* die_reader_func for load_partial_comp_unit. */
8837 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8838 const gdb_byte
*info_ptr
,
8839 struct die_info
*comp_unit_die
,
8843 struct dwarf2_cu
*cu
= reader
->cu
;
8845 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8847 /* Check if comp unit has_children.
8848 If so, read the rest of the partial symbols from this comp unit.
8849 If not, there's no more debug_info for this comp unit. */
8851 load_partial_dies (reader
, info_ptr
, 0);
8854 /* Load the partial DIEs for a secondary CU into memory.
8855 This is also used when rereading a primary CU with load_all_dies. */
8858 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8860 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8861 load_partial_comp_unit_reader
, NULL
);
8865 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8866 struct dwarf2_section_info
*section
,
8867 struct dwarf2_section_info
*abbrev_section
,
8868 unsigned int is_dwz
,
8871 struct dwarf2_per_cu_data
***all_comp_units
)
8873 const gdb_byte
*info_ptr
;
8874 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8876 if (dwarf_read_debug
)
8877 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8878 get_section_name (section
),
8879 get_section_file_name (section
));
8881 dwarf2_read_section (objfile
, section
);
8883 info_ptr
= section
->buffer
;
8885 while (info_ptr
< section
->buffer
+ section
->size
)
8887 struct dwarf2_per_cu_data
*this_cu
;
8889 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8891 comp_unit_head cu_header
;
8892 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8893 abbrev_section
, info_ptr
,
8894 rcuh_kind::COMPILE
);
8896 /* Save the compilation unit for later lookup. */
8897 if (cu_header
.unit_type
!= DW_UT_type
)
8899 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8900 struct dwarf2_per_cu_data
);
8901 memset (this_cu
, 0, sizeof (*this_cu
));
8905 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8906 struct signatured_type
);
8907 memset (sig_type
, 0, sizeof (*sig_type
));
8908 sig_type
->signature
= cu_header
.signature
;
8909 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8910 this_cu
= &sig_type
->per_cu
;
8912 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8913 this_cu
->sect_off
= sect_off
;
8914 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8915 this_cu
->is_dwz
= is_dwz
;
8916 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8917 this_cu
->section
= section
;
8919 if (*n_comp_units
== *n_allocated
)
8922 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
8923 *all_comp_units
, *n_allocated
);
8925 (*all_comp_units
)[*n_comp_units
] = this_cu
;
8928 info_ptr
= info_ptr
+ this_cu
->length
;
8932 /* Create a list of all compilation units in OBJFILE.
8933 This is only done for -readnow and building partial symtabs. */
8936 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8940 struct dwarf2_per_cu_data
**all_comp_units
;
8941 struct dwz_file
*dwz
;
8942 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8946 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
8948 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8949 &dwarf2_per_objfile
->abbrev
, 0,
8950 &n_allocated
, &n_comp_units
, &all_comp_units
);
8952 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8954 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8955 1, &n_allocated
, &n_comp_units
,
8958 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
8959 struct dwarf2_per_cu_data
*,
8961 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
8962 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
8963 xfree (all_comp_units
);
8964 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
8967 /* Process all loaded DIEs for compilation unit CU, starting at
8968 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8969 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8970 DW_AT_ranges). See the comments of add_partial_subprogram on how
8971 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8974 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8975 CORE_ADDR
*highpc
, int set_addrmap
,
8976 struct dwarf2_cu
*cu
)
8978 struct partial_die_info
*pdi
;
8980 /* Now, march along the PDI's, descending into ones which have
8981 interesting children but skipping the children of the other ones,
8982 until we reach the end of the compilation unit. */
8988 fixup_partial_die (pdi
, cu
);
8990 /* Anonymous namespaces or modules have no name but have interesting
8991 children, so we need to look at them. Ditto for anonymous
8994 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8995 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8996 || pdi
->tag
== DW_TAG_imported_unit
8997 || pdi
->tag
== DW_TAG_inlined_subroutine
)
9001 case DW_TAG_subprogram
:
9002 case DW_TAG_inlined_subroutine
:
9003 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9005 case DW_TAG_constant
:
9006 case DW_TAG_variable
:
9007 case DW_TAG_typedef
:
9008 case DW_TAG_union_type
:
9009 if (!pdi
->is_declaration
)
9011 add_partial_symbol (pdi
, cu
);
9014 case DW_TAG_class_type
:
9015 case DW_TAG_interface_type
:
9016 case DW_TAG_structure_type
:
9017 if (!pdi
->is_declaration
)
9019 add_partial_symbol (pdi
, cu
);
9021 if (cu
->language
== language_rust
&& pdi
->has_children
)
9022 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
9025 case DW_TAG_enumeration_type
:
9026 if (!pdi
->is_declaration
)
9027 add_partial_enumeration (pdi
, cu
);
9029 case DW_TAG_base_type
:
9030 case DW_TAG_subrange_type
:
9031 /* File scope base type definitions are added to the partial
9033 add_partial_symbol (pdi
, cu
);
9035 case DW_TAG_namespace
:
9036 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9039 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9041 case DW_TAG_imported_unit
:
9043 struct dwarf2_per_cu_data
*per_cu
;
9045 /* For now we don't handle imported units in type units. */
9046 if (cu
->per_cu
->is_debug_types
)
9048 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9049 " supported in type units [in module %s]"),
9050 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9053 per_cu
= dwarf2_find_containing_comp_unit
9054 (pdi
->d
.sect_off
, pdi
->is_dwz
,
9055 cu
->per_cu
->dwarf2_per_objfile
);
9057 /* Go read the partial unit, if needed. */
9058 if (per_cu
->v
.psymtab
== NULL
)
9059 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
9061 VEC_safe_push (dwarf2_per_cu_ptr
,
9062 cu
->per_cu
->imported_symtabs
, per_cu
);
9065 case DW_TAG_imported_declaration
:
9066 add_partial_symbol (pdi
, cu
);
9073 /* If the die has a sibling, skip to the sibling. */
9075 pdi
= pdi
->die_sibling
;
9079 /* Functions used to compute the fully scoped name of a partial DIE.
9081 Normally, this is simple. For C++, the parent DIE's fully scoped
9082 name is concatenated with "::" and the partial DIE's name.
9083 Enumerators are an exception; they use the scope of their parent
9084 enumeration type, i.e. the name of the enumeration type is not
9085 prepended to the enumerator.
9087 There are two complexities. One is DW_AT_specification; in this
9088 case "parent" means the parent of the target of the specification,
9089 instead of the direct parent of the DIE. The other is compilers
9090 which do not emit DW_TAG_namespace; in this case we try to guess
9091 the fully qualified name of structure types from their members'
9092 linkage names. This must be done using the DIE's children rather
9093 than the children of any DW_AT_specification target. We only need
9094 to do this for structures at the top level, i.e. if the target of
9095 any DW_AT_specification (if any; otherwise the DIE itself) does not
9098 /* Compute the scope prefix associated with PDI's parent, in
9099 compilation unit CU. The result will be allocated on CU's
9100 comp_unit_obstack, or a copy of the already allocated PDI->NAME
9101 field. NULL is returned if no prefix is necessary. */
9103 partial_die_parent_scope (struct partial_die_info
*pdi
,
9104 struct dwarf2_cu
*cu
)
9106 const char *grandparent_scope
;
9107 struct partial_die_info
*parent
, *real_pdi
;
9109 /* We need to look at our parent DIE; if we have a DW_AT_specification,
9110 then this means the parent of the specification DIE. */
9113 while (real_pdi
->has_specification
)
9114 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
9115 real_pdi
->spec_is_dwz
, cu
);
9117 parent
= real_pdi
->die_parent
;
9121 if (parent
->scope_set
)
9122 return parent
->scope
;
9124 fixup_partial_die (parent
, cu
);
9126 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
9128 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9129 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9130 Work around this problem here. */
9131 if (cu
->language
== language_cplus
9132 && parent
->tag
== DW_TAG_namespace
9133 && strcmp (parent
->name
, "::") == 0
9134 && grandparent_scope
== NULL
)
9136 parent
->scope
= NULL
;
9137 parent
->scope_set
= 1;
9141 if (pdi
->tag
== DW_TAG_enumerator
)
9142 /* Enumerators should not get the name of the enumeration as a prefix. */
9143 parent
->scope
= grandparent_scope
;
9144 else if (parent
->tag
== DW_TAG_namespace
9145 || parent
->tag
== DW_TAG_module
9146 || parent
->tag
== DW_TAG_structure_type
9147 || parent
->tag
== DW_TAG_class_type
9148 || parent
->tag
== DW_TAG_interface_type
9149 || parent
->tag
== DW_TAG_union_type
9150 || parent
->tag
== DW_TAG_enumeration_type
)
9152 if (grandparent_scope
== NULL
)
9153 parent
->scope
= parent
->name
;
9155 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
9157 parent
->name
, 0, cu
);
9161 /* FIXME drow/2004-04-01: What should we be doing with
9162 function-local names? For partial symbols, we should probably be
9164 complaint (&symfile_complaints
,
9165 _("unhandled containing DIE tag %d for DIE at %d"),
9166 parent
->tag
, to_underlying (pdi
->sect_off
));
9167 parent
->scope
= grandparent_scope
;
9170 parent
->scope_set
= 1;
9171 return parent
->scope
;
9174 /* Return the fully scoped name associated with PDI, from compilation unit
9175 CU. The result will be allocated with malloc. */
9178 partial_die_full_name (struct partial_die_info
*pdi
,
9179 struct dwarf2_cu
*cu
)
9181 const char *parent_scope
;
9183 /* If this is a template instantiation, we can not work out the
9184 template arguments from partial DIEs. So, unfortunately, we have
9185 to go through the full DIEs. At least any work we do building
9186 types here will be reused if full symbols are loaded later. */
9187 if (pdi
->has_template_arguments
)
9189 fixup_partial_die (pdi
, cu
);
9191 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
9193 struct die_info
*die
;
9194 struct attribute attr
;
9195 struct dwarf2_cu
*ref_cu
= cu
;
9197 /* DW_FORM_ref_addr is using section offset. */
9198 attr
.name
= (enum dwarf_attribute
) 0;
9199 attr
.form
= DW_FORM_ref_addr
;
9200 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
9201 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
9203 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
9207 parent_scope
= partial_die_parent_scope (pdi
, cu
);
9208 if (parent_scope
== NULL
)
9211 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
9215 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
9217 struct dwarf2_per_objfile
*dwarf2_per_objfile
9218 = cu
->per_cu
->dwarf2_per_objfile
;
9219 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9220 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9222 const char *actual_name
= NULL
;
9224 char *built_actual_name
;
9226 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9228 built_actual_name
= partial_die_full_name (pdi
, cu
);
9229 if (built_actual_name
!= NULL
)
9230 actual_name
= built_actual_name
;
9232 if (actual_name
== NULL
)
9233 actual_name
= pdi
->name
;
9237 case DW_TAG_inlined_subroutine
:
9238 case DW_TAG_subprogram
:
9239 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
9240 if (pdi
->is_external
|| cu
->language
== language_ada
)
9242 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
9243 of the global scope. But in Ada, we want to be able to access
9244 nested procedures globally. So all Ada subprograms are stored
9245 in the global scope. */
9246 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9247 built_actual_name
!= NULL
,
9248 VAR_DOMAIN
, LOC_BLOCK
,
9249 &objfile
->global_psymbols
,
9250 addr
, cu
->language
, objfile
);
9254 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9255 built_actual_name
!= NULL
,
9256 VAR_DOMAIN
, LOC_BLOCK
,
9257 &objfile
->static_psymbols
,
9258 addr
, cu
->language
, objfile
);
9261 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9262 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9264 case DW_TAG_constant
:
9266 std::vector
<partial_symbol
*> *list
;
9268 if (pdi
->is_external
)
9269 list
= &objfile
->global_psymbols
;
9271 list
= &objfile
->static_psymbols
;
9272 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9273 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9274 list
, 0, cu
->language
, objfile
);
9277 case DW_TAG_variable
:
9279 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9283 && !dwarf2_per_objfile
->has_section_at_zero
)
9285 /* A global or static variable may also have been stripped
9286 out by the linker if unused, in which case its address
9287 will be nullified; do not add such variables into partial
9288 symbol table then. */
9290 else if (pdi
->is_external
)
9293 Don't enter into the minimal symbol tables as there is
9294 a minimal symbol table entry from the ELF symbols already.
9295 Enter into partial symbol table if it has a location
9296 descriptor or a type.
9297 If the location descriptor is missing, new_symbol will create
9298 a LOC_UNRESOLVED symbol, the address of the variable will then
9299 be determined from the minimal symbol table whenever the variable
9301 The address for the partial symbol table entry is not
9302 used by GDB, but it comes in handy for debugging partial symbol
9305 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9306 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9307 built_actual_name
!= NULL
,
9308 VAR_DOMAIN
, LOC_STATIC
,
9309 &objfile
->global_psymbols
,
9311 cu
->language
, objfile
);
9315 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9317 /* Static Variable. Skip symbols whose value we cannot know (those
9318 without location descriptors or constant values). */
9319 if (!has_loc
&& !pdi
->has_const_value
)
9321 xfree (built_actual_name
);
9325 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9326 built_actual_name
!= NULL
,
9327 VAR_DOMAIN
, LOC_STATIC
,
9328 &objfile
->static_psymbols
,
9329 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
9330 cu
->language
, objfile
);
9333 case DW_TAG_typedef
:
9334 case DW_TAG_base_type
:
9335 case DW_TAG_subrange_type
:
9336 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9337 built_actual_name
!= NULL
,
9338 VAR_DOMAIN
, LOC_TYPEDEF
,
9339 &objfile
->static_psymbols
,
9340 0, cu
->language
, objfile
);
9342 case DW_TAG_imported_declaration
:
9343 case DW_TAG_namespace
:
9344 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9345 built_actual_name
!= NULL
,
9346 VAR_DOMAIN
, LOC_TYPEDEF
,
9347 &objfile
->global_psymbols
,
9348 0, cu
->language
, objfile
);
9351 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9352 built_actual_name
!= NULL
,
9353 MODULE_DOMAIN
, LOC_TYPEDEF
,
9354 &objfile
->global_psymbols
,
9355 0, cu
->language
, objfile
);
9357 case DW_TAG_class_type
:
9358 case DW_TAG_interface_type
:
9359 case DW_TAG_structure_type
:
9360 case DW_TAG_union_type
:
9361 case DW_TAG_enumeration_type
:
9362 /* Skip external references. The DWARF standard says in the section
9363 about "Structure, Union, and Class Type Entries": "An incomplete
9364 structure, union or class type is represented by a structure,
9365 union or class entry that does not have a byte size attribute
9366 and that has a DW_AT_declaration attribute." */
9367 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9369 xfree (built_actual_name
);
9373 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9374 static vs. global. */
9375 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9376 built_actual_name
!= NULL
,
9377 STRUCT_DOMAIN
, LOC_TYPEDEF
,
9378 cu
->language
== language_cplus
9379 ? &objfile
->global_psymbols
9380 : &objfile
->static_psymbols
,
9381 0, cu
->language
, objfile
);
9384 case DW_TAG_enumerator
:
9385 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9386 built_actual_name
!= NULL
,
9387 VAR_DOMAIN
, LOC_CONST
,
9388 cu
->language
== language_cplus
9389 ? &objfile
->global_psymbols
9390 : &objfile
->static_psymbols
,
9391 0, cu
->language
, objfile
);
9397 xfree (built_actual_name
);
9400 /* Read a partial die corresponding to a namespace; also, add a symbol
9401 corresponding to that namespace to the symbol table. NAMESPACE is
9402 the name of the enclosing namespace. */
9405 add_partial_namespace (struct partial_die_info
*pdi
,
9406 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9407 int set_addrmap
, struct dwarf2_cu
*cu
)
9409 /* Add a symbol for the namespace. */
9411 add_partial_symbol (pdi
, cu
);
9413 /* Now scan partial symbols in that namespace. */
9415 if (pdi
->has_children
)
9416 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9419 /* Read a partial die corresponding to a Fortran module. */
9422 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9423 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9425 /* Add a symbol for the namespace. */
9427 add_partial_symbol (pdi
, cu
);
9429 /* Now scan partial symbols in that module. */
9431 if (pdi
->has_children
)
9432 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9435 /* Read a partial die corresponding to a subprogram or an inlined
9436 subprogram and create a partial symbol for that subprogram.
9437 When the CU language allows it, this routine also defines a partial
9438 symbol for each nested subprogram that this subprogram contains.
9439 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9440 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9442 PDI may also be a lexical block, in which case we simply search
9443 recursively for subprograms defined inside that lexical block.
9444 Again, this is only performed when the CU language allows this
9445 type of definitions. */
9448 add_partial_subprogram (struct partial_die_info
*pdi
,
9449 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9450 int set_addrmap
, struct dwarf2_cu
*cu
)
9452 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9454 if (pdi
->has_pc_info
)
9456 if (pdi
->lowpc
< *lowpc
)
9457 *lowpc
= pdi
->lowpc
;
9458 if (pdi
->highpc
> *highpc
)
9459 *highpc
= pdi
->highpc
;
9462 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9463 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9468 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9469 SECT_OFF_TEXT (objfile
));
9470 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9471 pdi
->lowpc
+ baseaddr
);
9472 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9473 pdi
->highpc
+ baseaddr
);
9474 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9475 cu
->per_cu
->v
.psymtab
);
9479 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9481 if (!pdi
->is_declaration
)
9482 /* Ignore subprogram DIEs that do not have a name, they are
9483 illegal. Do not emit a complaint at this point, we will
9484 do so when we convert this psymtab into a symtab. */
9486 add_partial_symbol (pdi
, cu
);
9490 if (! pdi
->has_children
)
9493 if (cu
->language
== language_ada
)
9495 pdi
= pdi
->die_child
;
9498 fixup_partial_die (pdi
, cu
);
9499 if (pdi
->tag
== DW_TAG_subprogram
9500 || pdi
->tag
== DW_TAG_inlined_subroutine
9501 || pdi
->tag
== DW_TAG_lexical_block
)
9502 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9503 pdi
= pdi
->die_sibling
;
9508 /* Read a partial die corresponding to an enumeration type. */
9511 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9512 struct dwarf2_cu
*cu
)
9514 struct partial_die_info
*pdi
;
9516 if (enum_pdi
->name
!= NULL
)
9517 add_partial_symbol (enum_pdi
, cu
);
9519 pdi
= enum_pdi
->die_child
;
9522 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9523 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9525 add_partial_symbol (pdi
, cu
);
9526 pdi
= pdi
->die_sibling
;
9530 /* Return the initial uleb128 in the die at INFO_PTR. */
9533 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9535 unsigned int bytes_read
;
9537 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9540 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9541 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9543 Return the corresponding abbrev, or NULL if the number is zero (indicating
9544 an empty DIE). In either case *BYTES_READ will be set to the length of
9545 the initial number. */
9547 static struct abbrev_info
*
9548 peek_die_abbrev (const die_reader_specs
&reader
,
9549 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9551 dwarf2_cu
*cu
= reader
.cu
;
9552 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9553 unsigned int abbrev_number
9554 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9556 if (abbrev_number
== 0)
9559 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9562 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9563 " at offset 0x%x [in module %s]"),
9564 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9565 to_underlying (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9571 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9572 Returns a pointer to the end of a series of DIEs, terminated by an empty
9573 DIE. Any children of the skipped DIEs will also be skipped. */
9575 static const gdb_byte
*
9576 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9580 unsigned int bytes_read
;
9581 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9584 return info_ptr
+ bytes_read
;
9586 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9590 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9591 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9592 abbrev corresponding to that skipped uleb128 should be passed in
9593 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9596 static const gdb_byte
*
9597 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9598 struct abbrev_info
*abbrev
)
9600 unsigned int bytes_read
;
9601 struct attribute attr
;
9602 bfd
*abfd
= reader
->abfd
;
9603 struct dwarf2_cu
*cu
= reader
->cu
;
9604 const gdb_byte
*buffer
= reader
->buffer
;
9605 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9606 unsigned int form
, i
;
9608 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9610 /* The only abbrev we care about is DW_AT_sibling. */
9611 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9613 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9614 if (attr
.form
== DW_FORM_ref_addr
)
9615 complaint (&symfile_complaints
,
9616 _("ignoring absolute DW_AT_sibling"));
9619 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9620 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9622 if (sibling_ptr
< info_ptr
)
9623 complaint (&symfile_complaints
,
9624 _("DW_AT_sibling points backwards"));
9625 else if (sibling_ptr
> reader
->buffer_end
)
9626 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9632 /* If it isn't DW_AT_sibling, skip this attribute. */
9633 form
= abbrev
->attrs
[i
].form
;
9637 case DW_FORM_ref_addr
:
9638 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9639 and later it is offset sized. */
9640 if (cu
->header
.version
== 2)
9641 info_ptr
+= cu
->header
.addr_size
;
9643 info_ptr
+= cu
->header
.offset_size
;
9645 case DW_FORM_GNU_ref_alt
:
9646 info_ptr
+= cu
->header
.offset_size
;
9649 info_ptr
+= cu
->header
.addr_size
;
9656 case DW_FORM_flag_present
:
9657 case DW_FORM_implicit_const
:
9669 case DW_FORM_ref_sig8
:
9672 case DW_FORM_data16
:
9675 case DW_FORM_string
:
9676 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9677 info_ptr
+= bytes_read
;
9679 case DW_FORM_sec_offset
:
9681 case DW_FORM_GNU_strp_alt
:
9682 info_ptr
+= cu
->header
.offset_size
;
9684 case DW_FORM_exprloc
:
9686 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9687 info_ptr
+= bytes_read
;
9689 case DW_FORM_block1
:
9690 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9692 case DW_FORM_block2
:
9693 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9695 case DW_FORM_block4
:
9696 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9700 case DW_FORM_ref_udata
:
9701 case DW_FORM_GNU_addr_index
:
9702 case DW_FORM_GNU_str_index
:
9703 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9705 case DW_FORM_indirect
:
9706 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9707 info_ptr
+= bytes_read
;
9708 /* We need to continue parsing from here, so just go back to
9710 goto skip_attribute
;
9713 error (_("Dwarf Error: Cannot handle %s "
9714 "in DWARF reader [in module %s]"),
9715 dwarf_form_name (form
),
9716 bfd_get_filename (abfd
));
9720 if (abbrev
->has_children
)
9721 return skip_children (reader
, info_ptr
);
9726 /* Locate ORIG_PDI's sibling.
9727 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9729 static const gdb_byte
*
9730 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9731 struct partial_die_info
*orig_pdi
,
9732 const gdb_byte
*info_ptr
)
9734 /* Do we know the sibling already? */
9736 if (orig_pdi
->sibling
)
9737 return orig_pdi
->sibling
;
9739 /* Are there any children to deal with? */
9741 if (!orig_pdi
->has_children
)
9744 /* Skip the children the long way. */
9746 return skip_children (reader
, info_ptr
);
9749 /* Expand this partial symbol table into a full symbol table. SELF is
9753 dwarf2_read_symtab (struct partial_symtab
*self
,
9754 struct objfile
*objfile
)
9756 struct dwarf2_per_objfile
*dwarf2_per_objfile
9757 = get_dwarf2_per_objfile (objfile
);
9761 warning (_("bug: psymtab for %s is already read in."),
9768 printf_filtered (_("Reading in symbols for %s..."),
9770 gdb_flush (gdb_stdout
);
9773 /* If this psymtab is constructed from a debug-only objfile, the
9774 has_section_at_zero flag will not necessarily be correct. We
9775 can get the correct value for this flag by looking at the data
9776 associated with the (presumably stripped) associated objfile. */
9777 if (objfile
->separate_debug_objfile_backlink
)
9779 struct dwarf2_per_objfile
*dpo_backlink
9780 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9782 dwarf2_per_objfile
->has_section_at_zero
9783 = dpo_backlink
->has_section_at_zero
;
9786 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9788 psymtab_to_symtab_1 (self
);
9790 /* Finish up the debug error message. */
9792 printf_filtered (_("done.\n"));
9795 process_cu_includes (dwarf2_per_objfile
);
9798 /* Reading in full CUs. */
9800 /* Add PER_CU to the queue. */
9803 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9804 enum language pretend_language
)
9806 struct dwarf2_queue_item
*item
;
9809 item
= XNEW (struct dwarf2_queue_item
);
9810 item
->per_cu
= per_cu
;
9811 item
->pretend_language
= pretend_language
;
9814 if (dwarf2_queue
== NULL
)
9815 dwarf2_queue
= item
;
9817 dwarf2_queue_tail
->next
= item
;
9819 dwarf2_queue_tail
= item
;
9822 /* If PER_CU is not yet queued, add it to the queue.
9823 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9825 The result is non-zero if PER_CU was queued, otherwise the result is zero
9826 meaning either PER_CU is already queued or it is already loaded.
9828 N.B. There is an invariant here that if a CU is queued then it is loaded.
9829 The caller is required to load PER_CU if we return non-zero. */
9832 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9833 struct dwarf2_per_cu_data
*per_cu
,
9834 enum language pretend_language
)
9836 /* We may arrive here during partial symbol reading, if we need full
9837 DIEs to process an unusual case (e.g. template arguments). Do
9838 not queue PER_CU, just tell our caller to load its DIEs. */
9839 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9841 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9846 /* Mark the dependence relation so that we don't flush PER_CU
9848 if (dependent_cu
!= NULL
)
9849 dwarf2_add_dependence (dependent_cu
, per_cu
);
9851 /* If it's already on the queue, we have nothing to do. */
9855 /* If the compilation unit is already loaded, just mark it as
9857 if (per_cu
->cu
!= NULL
)
9859 per_cu
->cu
->last_used
= 0;
9863 /* Add it to the queue. */
9864 queue_comp_unit (per_cu
, pretend_language
);
9869 /* Process the queue. */
9872 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9874 struct dwarf2_queue_item
*item
, *next_item
;
9876 if (dwarf_read_debug
)
9878 fprintf_unfiltered (gdb_stdlog
,
9879 "Expanding one or more symtabs of objfile %s ...\n",
9880 objfile_name (dwarf2_per_objfile
->objfile
));
9883 /* The queue starts out with one item, but following a DIE reference
9884 may load a new CU, adding it to the end of the queue. */
9885 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9887 if ((dwarf2_per_objfile
->using_index
9888 ? !item
->per_cu
->v
.quick
->compunit_symtab
9889 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9890 /* Skip dummy CUs. */
9891 && item
->per_cu
->cu
!= NULL
)
9893 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9894 unsigned int debug_print_threshold
;
9897 if (per_cu
->is_debug_types
)
9899 struct signatured_type
*sig_type
=
9900 (struct signatured_type
*) per_cu
;
9902 sprintf (buf
, "TU %s at offset 0x%x",
9903 hex_string (sig_type
->signature
),
9904 to_underlying (per_cu
->sect_off
));
9905 /* There can be 100s of TUs.
9906 Only print them in verbose mode. */
9907 debug_print_threshold
= 2;
9911 sprintf (buf
, "CU at offset 0x%x",
9912 to_underlying (per_cu
->sect_off
));
9913 debug_print_threshold
= 1;
9916 if (dwarf_read_debug
>= debug_print_threshold
)
9917 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9919 if (per_cu
->is_debug_types
)
9920 process_full_type_unit (per_cu
, item
->pretend_language
);
9922 process_full_comp_unit (per_cu
, item
->pretend_language
);
9924 if (dwarf_read_debug
>= debug_print_threshold
)
9925 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9928 item
->per_cu
->queued
= 0;
9929 next_item
= item
->next
;
9933 dwarf2_queue_tail
= NULL
;
9935 if (dwarf_read_debug
)
9937 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9938 objfile_name (dwarf2_per_objfile
->objfile
));
9942 /* Free all allocated queue entries. This function only releases anything if
9943 an error was thrown; if the queue was processed then it would have been
9944 freed as we went along. */
9947 dwarf2_release_queue (void *dummy
)
9949 struct dwarf2_queue_item
*item
, *last
;
9951 item
= dwarf2_queue
;
9954 /* Anything still marked queued is likely to be in an
9955 inconsistent state, so discard it. */
9956 if (item
->per_cu
->queued
)
9958 if (item
->per_cu
->cu
!= NULL
)
9959 free_one_cached_comp_unit (item
->per_cu
);
9960 item
->per_cu
->queued
= 0;
9968 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
9971 /* Read in full symbols for PST, and anything it depends on. */
9974 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9976 struct dwarf2_per_cu_data
*per_cu
;
9982 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9983 if (!pst
->dependencies
[i
]->readin
9984 && pst
->dependencies
[i
]->user
== NULL
)
9986 /* Inform about additional files that need to be read in. */
9989 /* FIXME: i18n: Need to make this a single string. */
9990 fputs_filtered (" ", gdb_stdout
);
9992 fputs_filtered ("and ", gdb_stdout
);
9994 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9995 wrap_here (""); /* Flush output. */
9996 gdb_flush (gdb_stdout
);
9998 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
10001 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
10003 if (per_cu
== NULL
)
10005 /* It's an include file, no symbols to read for it.
10006 Everything is in the parent symtab. */
10011 dw2_do_instantiate_symtab (per_cu
);
10014 /* Trivial hash function for die_info: the hash value of a DIE
10015 is its offset in .debug_info for this objfile. */
10018 die_hash (const void *item
)
10020 const struct die_info
*die
= (const struct die_info
*) item
;
10022 return to_underlying (die
->sect_off
);
10025 /* Trivial comparison function for die_info structures: two DIEs
10026 are equal if they have the same offset. */
10029 die_eq (const void *item_lhs
, const void *item_rhs
)
10031 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
10032 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
10034 return die_lhs
->sect_off
== die_rhs
->sect_off
;
10037 /* die_reader_func for load_full_comp_unit.
10038 This is identical to read_signatured_type_reader,
10039 but is kept separate for now. */
10042 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
10043 const gdb_byte
*info_ptr
,
10044 struct die_info
*comp_unit_die
,
10048 struct dwarf2_cu
*cu
= reader
->cu
;
10049 enum language
*language_ptr
= (enum language
*) data
;
10051 gdb_assert (cu
->die_hash
== NULL
);
10053 htab_create_alloc_ex (cu
->header
.length
/ 12,
10057 &cu
->comp_unit_obstack
,
10058 hashtab_obstack_allocate
,
10059 dummy_obstack_deallocate
);
10062 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
10063 &info_ptr
, comp_unit_die
);
10064 cu
->dies
= comp_unit_die
;
10065 /* comp_unit_die is not stored in die_hash, no need. */
10067 /* We try not to read any attributes in this function, because not
10068 all CUs needed for references have been loaded yet, and symbol
10069 table processing isn't initialized. But we have to set the CU language,
10070 or we won't be able to build types correctly.
10071 Similarly, if we do not read the producer, we can not apply
10072 producer-specific interpretation. */
10073 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
10076 /* Load the DIEs associated with PER_CU into memory. */
10079 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
10080 enum language pretend_language
)
10082 gdb_assert (! this_cu
->is_debug_types
);
10084 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
10085 load_full_comp_unit_reader
, &pretend_language
);
10088 /* Add a DIE to the delayed physname list. */
10091 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
10092 const char *name
, struct die_info
*die
,
10093 struct dwarf2_cu
*cu
)
10095 struct delayed_method_info mi
;
10097 mi
.fnfield_index
= fnfield_index
;
10101 cu
->method_list
.push_back (mi
);
10104 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
10105 "const" / "volatile". If so, decrements LEN by the length of the
10106 modifier and return true. Otherwise return false. */
10110 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
10112 size_t mod_len
= sizeof (mod
) - 1;
10113 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
10121 /* Compute the physnames of any methods on the CU's method list.
10123 The computation of method physnames is delayed in order to avoid the
10124 (bad) condition that one of the method's formal parameters is of an as yet
10125 incomplete type. */
10128 compute_delayed_physnames (struct dwarf2_cu
*cu
)
10130 /* Only C++ delays computing physnames. */
10131 if (cu
->method_list
.empty ())
10133 gdb_assert (cu
->language
== language_cplus
);
10135 for (struct delayed_method_info
&mi
: cu
->method_list
)
10137 const char *physname
;
10138 struct fn_fieldlist
*fn_flp
10139 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
10140 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
10141 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
10142 = physname
? physname
: "";
10144 /* Since there's no tag to indicate whether a method is a
10145 const/volatile overload, extract that information out of the
10147 if (physname
!= NULL
)
10149 size_t len
= strlen (physname
);
10153 if (physname
[len
] == ')') /* shortcut */
10155 else if (check_modifier (physname
, len
, " const"))
10156 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
10157 else if (check_modifier (physname
, len
, " volatile"))
10158 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
10165 /* The list is no longer needed. */
10166 cu
->method_list
.clear ();
10169 /* Go objects should be embedded in a DW_TAG_module DIE,
10170 and it's not clear if/how imported objects will appear.
10171 To keep Go support simple until that's worked out,
10172 go back through what we've read and create something usable.
10173 We could do this while processing each DIE, and feels kinda cleaner,
10174 but that way is more invasive.
10175 This is to, for example, allow the user to type "p var" or "b main"
10176 without having to specify the package name, and allow lookups
10177 of module.object to work in contexts that use the expression
10181 fixup_go_packaging (struct dwarf2_cu
*cu
)
10183 char *package_name
= NULL
;
10184 struct pending
*list
;
10187 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
10189 for (i
= 0; i
< list
->nsyms
; ++i
)
10191 struct symbol
*sym
= list
->symbol
[i
];
10193 if (SYMBOL_LANGUAGE (sym
) == language_go
10194 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
10196 char *this_package_name
= go_symbol_package_name (sym
);
10198 if (this_package_name
== NULL
)
10200 if (package_name
== NULL
)
10201 package_name
= this_package_name
;
10204 struct objfile
*objfile
10205 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10206 if (strcmp (package_name
, this_package_name
) != 0)
10207 complaint (&symfile_complaints
,
10208 _("Symtab %s has objects from two different Go packages: %s and %s"),
10209 (symbol_symtab (sym
) != NULL
10210 ? symtab_to_filename_for_display
10211 (symbol_symtab (sym
))
10212 : objfile_name (objfile
)),
10213 this_package_name
, package_name
);
10214 xfree (this_package_name
);
10220 if (package_name
!= NULL
)
10222 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10223 const char *saved_package_name
10224 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10226 strlen (package_name
));
10227 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
10228 saved_package_name
);
10229 struct symbol
*sym
;
10231 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10233 sym
= allocate_symbol (objfile
);
10234 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
10235 SYMBOL_SET_NAMES (sym
, saved_package_name
,
10236 strlen (saved_package_name
), 0, objfile
);
10237 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
10238 e.g., "main" finds the "main" module and not C's main(). */
10239 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10240 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
10241 SYMBOL_TYPE (sym
) = type
;
10243 add_symbol_to_list (sym
, &global_symbols
);
10245 xfree (package_name
);
10249 /* Return the symtab for PER_CU. This works properly regardless of
10250 whether we're using the index or psymtabs. */
10252 static struct compunit_symtab
*
10253 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10255 return (per_cu
->dwarf2_per_objfile
->using_index
10256 ? per_cu
->v
.quick
->compunit_symtab
10257 : per_cu
->v
.psymtab
->compunit_symtab
);
10260 /* A helper function for computing the list of all symbol tables
10261 included by PER_CU. */
10264 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10265 htab_t all_children
, htab_t all_type_symtabs
,
10266 struct dwarf2_per_cu_data
*per_cu
,
10267 struct compunit_symtab
*immediate_parent
)
10271 struct compunit_symtab
*cust
;
10272 struct dwarf2_per_cu_data
*iter
;
10274 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10277 /* This inclusion and its children have been processed. */
10282 /* Only add a CU if it has a symbol table. */
10283 cust
= get_compunit_symtab (per_cu
);
10286 /* If this is a type unit only add its symbol table if we haven't
10287 seen it yet (type unit per_cu's can share symtabs). */
10288 if (per_cu
->is_debug_types
)
10290 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10294 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10295 if (cust
->user
== NULL
)
10296 cust
->user
= immediate_parent
;
10301 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10302 if (cust
->user
== NULL
)
10303 cust
->user
= immediate_parent
;
10308 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10311 recursively_compute_inclusions (result
, all_children
,
10312 all_type_symtabs
, iter
, cust
);
10316 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10320 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10322 gdb_assert (! per_cu
->is_debug_types
);
10324 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10327 struct dwarf2_per_cu_data
*per_cu_iter
;
10328 struct compunit_symtab
*compunit_symtab_iter
;
10329 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10330 htab_t all_children
, all_type_symtabs
;
10331 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10333 /* If we don't have a symtab, we can just skip this case. */
10337 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10338 NULL
, xcalloc
, xfree
);
10339 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10340 NULL
, xcalloc
, xfree
);
10343 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10347 recursively_compute_inclusions (&result_symtabs
, all_children
,
10348 all_type_symtabs
, per_cu_iter
,
10352 /* Now we have a transitive closure of all the included symtabs. */
10353 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10355 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10356 struct compunit_symtab
*, len
+ 1);
10358 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10359 compunit_symtab_iter
);
10361 cust
->includes
[ix
] = compunit_symtab_iter
;
10362 cust
->includes
[len
] = NULL
;
10364 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10365 htab_delete (all_children
);
10366 htab_delete (all_type_symtabs
);
10370 /* Compute the 'includes' field for the symtabs of all the CUs we just
10374 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10377 struct dwarf2_per_cu_data
*iter
;
10380 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10384 if (! iter
->is_debug_types
)
10385 compute_compunit_symtab_includes (iter
);
10388 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10391 /* Generate full symbol information for PER_CU, whose DIEs have
10392 already been loaded into memory. */
10395 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10396 enum language pretend_language
)
10398 struct dwarf2_cu
*cu
= per_cu
->cu
;
10399 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10400 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10401 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10402 CORE_ADDR lowpc
, highpc
;
10403 struct compunit_symtab
*cust
;
10404 CORE_ADDR baseaddr
;
10405 struct block
*static_block
;
10408 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10411 scoped_free_pendings free_pending
;
10413 /* Clear the list here in case something was left over. */
10414 cu
->method_list
.clear ();
10416 cu
->list_in_scope
= &file_symbols
;
10418 cu
->language
= pretend_language
;
10419 cu
->language_defn
= language_def (cu
->language
);
10421 /* Do line number decoding in read_file_scope () */
10422 process_die (cu
->dies
, cu
);
10424 /* For now fudge the Go package. */
10425 if (cu
->language
== language_go
)
10426 fixup_go_packaging (cu
);
10428 /* Now that we have processed all the DIEs in the CU, all the types
10429 should be complete, and it should now be safe to compute all of the
10431 compute_delayed_physnames (cu
);
10433 /* Some compilers don't define a DW_AT_high_pc attribute for the
10434 compilation unit. If the DW_AT_high_pc is missing, synthesize
10435 it, by scanning the DIE's below the compilation unit. */
10436 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10438 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10439 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10441 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10442 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10443 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10444 addrmap to help ensure it has an accurate map of pc values belonging to
10446 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10448 cust
= end_symtab_from_static_block (static_block
,
10449 SECT_OFF_TEXT (objfile
), 0);
10453 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10455 /* Set symtab language to language from DW_AT_language. If the
10456 compilation is from a C file generated by language preprocessors, do
10457 not set the language if it was already deduced by start_subfile. */
10458 if (!(cu
->language
== language_c
10459 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10460 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10462 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10463 produce DW_AT_location with location lists but it can be possibly
10464 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10465 there were bugs in prologue debug info, fixed later in GCC-4.5
10466 by "unwind info for epilogues" patch (which is not directly related).
10468 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10469 needed, it would be wrong due to missing DW_AT_producer there.
10471 Still one can confuse GDB by using non-standard GCC compilation
10472 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10474 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10475 cust
->locations_valid
= 1;
10477 if (gcc_4_minor
>= 5)
10478 cust
->epilogue_unwind_valid
= 1;
10480 cust
->call_site_htab
= cu
->call_site_htab
;
10483 if (dwarf2_per_objfile
->using_index
)
10484 per_cu
->v
.quick
->compunit_symtab
= cust
;
10487 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10488 pst
->compunit_symtab
= cust
;
10492 /* Push it for inclusion processing later. */
10493 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10496 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10497 already been loaded into memory. */
10500 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10501 enum language pretend_language
)
10503 struct dwarf2_cu
*cu
= per_cu
->cu
;
10504 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10505 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10506 struct compunit_symtab
*cust
;
10507 struct signatured_type
*sig_type
;
10509 gdb_assert (per_cu
->is_debug_types
);
10510 sig_type
= (struct signatured_type
*) per_cu
;
10513 scoped_free_pendings free_pending
;
10515 /* Clear the list here in case something was left over. */
10516 cu
->method_list
.clear ();
10518 cu
->list_in_scope
= &file_symbols
;
10520 cu
->language
= pretend_language
;
10521 cu
->language_defn
= language_def (cu
->language
);
10523 /* The symbol tables are set up in read_type_unit_scope. */
10524 process_die (cu
->dies
, cu
);
10526 /* For now fudge the Go package. */
10527 if (cu
->language
== language_go
)
10528 fixup_go_packaging (cu
);
10530 /* Now that we have processed all the DIEs in the CU, all the types
10531 should be complete, and it should now be safe to compute all of the
10533 compute_delayed_physnames (cu
);
10535 /* TUs share symbol tables.
10536 If this is the first TU to use this symtab, complete the construction
10537 of it with end_expandable_symtab. Otherwise, complete the addition of
10538 this TU's symbols to the existing symtab. */
10539 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10541 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10542 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10546 /* Set symtab language to language from DW_AT_language. If the
10547 compilation is from a C file generated by language preprocessors,
10548 do not set the language if it was already deduced by
10550 if (!(cu
->language
== language_c
10551 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10552 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10557 augment_type_symtab ();
10558 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10561 if (dwarf2_per_objfile
->using_index
)
10562 per_cu
->v
.quick
->compunit_symtab
= cust
;
10565 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10566 pst
->compunit_symtab
= cust
;
10571 /* Process an imported unit DIE. */
10574 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10576 struct attribute
*attr
;
10578 /* For now we don't handle imported units in type units. */
10579 if (cu
->per_cu
->is_debug_types
)
10581 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10582 " supported in type units [in module %s]"),
10583 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10586 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10589 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10590 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10591 dwarf2_per_cu_data
*per_cu
10592 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10593 cu
->per_cu
->dwarf2_per_objfile
);
10595 /* If necessary, add it to the queue and load its DIEs. */
10596 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10597 load_full_comp_unit (per_cu
, cu
->language
);
10599 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10604 /* RAII object that represents a process_die scope: i.e.,
10605 starts/finishes processing a DIE. */
10606 class process_die_scope
10609 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10610 : m_die (die
), m_cu (cu
)
10612 /* We should only be processing DIEs not already in process. */
10613 gdb_assert (!m_die
->in_process
);
10614 m_die
->in_process
= true;
10617 ~process_die_scope ()
10619 m_die
->in_process
= false;
10621 /* If we're done processing the DIE for the CU that owns the line
10622 header, we don't need the line header anymore. */
10623 if (m_cu
->line_header_die_owner
== m_die
)
10625 delete m_cu
->line_header
;
10626 m_cu
->line_header
= NULL
;
10627 m_cu
->line_header_die_owner
= NULL
;
10636 /* Process a die and its children. */
10639 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10641 process_die_scope
scope (die
, cu
);
10645 case DW_TAG_padding
:
10647 case DW_TAG_compile_unit
:
10648 case DW_TAG_partial_unit
:
10649 read_file_scope (die
, cu
);
10651 case DW_TAG_type_unit
:
10652 read_type_unit_scope (die
, cu
);
10654 case DW_TAG_subprogram
:
10655 case DW_TAG_inlined_subroutine
:
10656 read_func_scope (die
, cu
);
10658 case DW_TAG_lexical_block
:
10659 case DW_TAG_try_block
:
10660 case DW_TAG_catch_block
:
10661 read_lexical_block_scope (die
, cu
);
10663 case DW_TAG_call_site
:
10664 case DW_TAG_GNU_call_site
:
10665 read_call_site_scope (die
, cu
);
10667 case DW_TAG_class_type
:
10668 case DW_TAG_interface_type
:
10669 case DW_TAG_structure_type
:
10670 case DW_TAG_union_type
:
10671 process_structure_scope (die
, cu
);
10673 case DW_TAG_enumeration_type
:
10674 process_enumeration_scope (die
, cu
);
10677 /* These dies have a type, but processing them does not create
10678 a symbol or recurse to process the children. Therefore we can
10679 read them on-demand through read_type_die. */
10680 case DW_TAG_subroutine_type
:
10681 case DW_TAG_set_type
:
10682 case DW_TAG_array_type
:
10683 case DW_TAG_pointer_type
:
10684 case DW_TAG_ptr_to_member_type
:
10685 case DW_TAG_reference_type
:
10686 case DW_TAG_rvalue_reference_type
:
10687 case DW_TAG_string_type
:
10690 case DW_TAG_base_type
:
10691 case DW_TAG_subrange_type
:
10692 case DW_TAG_typedef
:
10693 /* Add a typedef symbol for the type definition, if it has a
10695 new_symbol (die
, read_type_die (die
, cu
), cu
);
10697 case DW_TAG_common_block
:
10698 read_common_block (die
, cu
);
10700 case DW_TAG_common_inclusion
:
10702 case DW_TAG_namespace
:
10703 cu
->processing_has_namespace_info
= 1;
10704 read_namespace (die
, cu
);
10706 case DW_TAG_module
:
10707 cu
->processing_has_namespace_info
= 1;
10708 read_module (die
, cu
);
10710 case DW_TAG_imported_declaration
:
10711 cu
->processing_has_namespace_info
= 1;
10712 if (read_namespace_alias (die
, cu
))
10714 /* The declaration is not a global namespace alias: fall through. */
10715 case DW_TAG_imported_module
:
10716 cu
->processing_has_namespace_info
= 1;
10717 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10718 || cu
->language
!= language_fortran
))
10719 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
10720 dwarf_tag_name (die
->tag
));
10721 read_import_statement (die
, cu
);
10724 case DW_TAG_imported_unit
:
10725 process_imported_unit_die (die
, cu
);
10728 case DW_TAG_variable
:
10729 read_variable (die
, cu
);
10733 new_symbol (die
, NULL
, cu
);
10738 /* DWARF name computation. */
10740 /* A helper function for dwarf2_compute_name which determines whether DIE
10741 needs to have the name of the scope prepended to the name listed in the
10745 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10747 struct attribute
*attr
;
10751 case DW_TAG_namespace
:
10752 case DW_TAG_typedef
:
10753 case DW_TAG_class_type
:
10754 case DW_TAG_interface_type
:
10755 case DW_TAG_structure_type
:
10756 case DW_TAG_union_type
:
10757 case DW_TAG_enumeration_type
:
10758 case DW_TAG_enumerator
:
10759 case DW_TAG_subprogram
:
10760 case DW_TAG_inlined_subroutine
:
10761 case DW_TAG_member
:
10762 case DW_TAG_imported_declaration
:
10765 case DW_TAG_variable
:
10766 case DW_TAG_constant
:
10767 /* We only need to prefix "globally" visible variables. These include
10768 any variable marked with DW_AT_external or any variable that
10769 lives in a namespace. [Variables in anonymous namespaces
10770 require prefixing, but they are not DW_AT_external.] */
10772 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10774 struct dwarf2_cu
*spec_cu
= cu
;
10776 return die_needs_namespace (die_specification (die
, &spec_cu
),
10780 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10781 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10782 && die
->parent
->tag
!= DW_TAG_module
)
10784 /* A variable in a lexical block of some kind does not need a
10785 namespace, even though in C++ such variables may be external
10786 and have a mangled name. */
10787 if (die
->parent
->tag
== DW_TAG_lexical_block
10788 || die
->parent
->tag
== DW_TAG_try_block
10789 || die
->parent
->tag
== DW_TAG_catch_block
10790 || die
->parent
->tag
== DW_TAG_subprogram
)
10799 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10800 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10801 defined for the given DIE. */
10803 static struct attribute
*
10804 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10806 struct attribute
*attr
;
10808 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10810 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10815 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10816 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10817 defined for the given DIE. */
10819 static const char *
10820 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10822 const char *linkage_name
;
10824 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10825 if (linkage_name
== NULL
)
10826 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10828 return linkage_name
;
10831 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10832 compute the physname for the object, which include a method's:
10833 - formal parameters (C++),
10834 - receiver type (Go),
10836 The term "physname" is a bit confusing.
10837 For C++, for example, it is the demangled name.
10838 For Go, for example, it's the mangled name.
10840 For Ada, return the DIE's linkage name rather than the fully qualified
10841 name. PHYSNAME is ignored..
10843 The result is allocated on the objfile_obstack and canonicalized. */
10845 static const char *
10846 dwarf2_compute_name (const char *name
,
10847 struct die_info
*die
, struct dwarf2_cu
*cu
,
10850 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10853 name
= dwarf2_name (die
, cu
);
10855 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10856 but otherwise compute it by typename_concat inside GDB.
10857 FIXME: Actually this is not really true, or at least not always true.
10858 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10859 Fortran names because there is no mangling standard. So new_symbol
10860 will set the demangled name to the result of dwarf2_full_name, and it is
10861 the demangled name that GDB uses if it exists. */
10862 if (cu
->language
== language_ada
10863 || (cu
->language
== language_fortran
&& physname
))
10865 /* For Ada unit, we prefer the linkage name over the name, as
10866 the former contains the exported name, which the user expects
10867 to be able to reference. Ideally, we want the user to be able
10868 to reference this entity using either natural or linkage name,
10869 but we haven't started looking at this enhancement yet. */
10870 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10872 if (linkage_name
!= NULL
)
10873 return linkage_name
;
10876 /* These are the only languages we know how to qualify names in. */
10878 && (cu
->language
== language_cplus
10879 || cu
->language
== language_fortran
|| cu
->language
== language_d
10880 || cu
->language
== language_rust
))
10882 if (die_needs_namespace (die
, cu
))
10884 const char *prefix
;
10885 const char *canonical_name
= NULL
;
10889 prefix
= determine_prefix (die
, cu
);
10890 if (*prefix
!= '\0')
10892 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10895 buf
.puts (prefixed_name
);
10896 xfree (prefixed_name
);
10901 /* Template parameters may be specified in the DIE's DW_AT_name, or
10902 as children with DW_TAG_template_type_param or
10903 DW_TAG_value_type_param. If the latter, add them to the name
10904 here. If the name already has template parameters, then
10905 skip this step; some versions of GCC emit both, and
10906 it is more efficient to use the pre-computed name.
10908 Something to keep in mind about this process: it is very
10909 unlikely, or in some cases downright impossible, to produce
10910 something that will match the mangled name of a function.
10911 If the definition of the function has the same debug info,
10912 we should be able to match up with it anyway. But fallbacks
10913 using the minimal symbol, for instance to find a method
10914 implemented in a stripped copy of libstdc++, will not work.
10915 If we do not have debug info for the definition, we will have to
10916 match them up some other way.
10918 When we do name matching there is a related problem with function
10919 templates; two instantiated function templates are allowed to
10920 differ only by their return types, which we do not add here. */
10922 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10924 struct attribute
*attr
;
10925 struct die_info
*child
;
10928 die
->building_fullname
= 1;
10930 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10934 const gdb_byte
*bytes
;
10935 struct dwarf2_locexpr_baton
*baton
;
10938 if (child
->tag
!= DW_TAG_template_type_param
10939 && child
->tag
!= DW_TAG_template_value_param
)
10950 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10953 complaint (&symfile_complaints
,
10954 _("template parameter missing DW_AT_type"));
10955 buf
.puts ("UNKNOWN_TYPE");
10958 type
= die_type (child
, cu
);
10960 if (child
->tag
== DW_TAG_template_type_param
)
10962 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
10966 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10969 complaint (&symfile_complaints
,
10970 _("template parameter missing "
10971 "DW_AT_const_value"));
10972 buf
.puts ("UNKNOWN_VALUE");
10976 dwarf2_const_value_attr (attr
, type
, name
,
10977 &cu
->comp_unit_obstack
, cu
,
10978 &value
, &bytes
, &baton
);
10980 if (TYPE_NOSIGN (type
))
10981 /* GDB prints characters as NUMBER 'CHAR'. If that's
10982 changed, this can use value_print instead. */
10983 c_printchar (value
, type
, &buf
);
10986 struct value_print_options opts
;
10989 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10993 else if (bytes
!= NULL
)
10995 v
= allocate_value (type
);
10996 memcpy (value_contents_writeable (v
), bytes
,
10997 TYPE_LENGTH (type
));
11000 v
= value_from_longest (type
, value
);
11002 /* Specify decimal so that we do not depend on
11004 get_formatted_print_options (&opts
, 'd');
11006 value_print (v
, &buf
, &opts
);
11012 die
->building_fullname
= 0;
11016 /* Close the argument list, with a space if necessary
11017 (nested templates). */
11018 if (!buf
.empty () && buf
.string ().back () == '>')
11025 /* For C++ methods, append formal parameter type
11026 information, if PHYSNAME. */
11028 if (physname
&& die
->tag
== DW_TAG_subprogram
11029 && cu
->language
== language_cplus
)
11031 struct type
*type
= read_type_die (die
, cu
);
11033 c_type_print_args (type
, &buf
, 1, cu
->language
,
11034 &type_print_raw_options
);
11036 if (cu
->language
== language_cplus
)
11038 /* Assume that an artificial first parameter is
11039 "this", but do not crash if it is not. RealView
11040 marks unnamed (and thus unused) parameters as
11041 artificial; there is no way to differentiate
11043 if (TYPE_NFIELDS (type
) > 0
11044 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11045 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11046 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11048 buf
.puts (" const");
11052 const std::string
&intermediate_name
= buf
.string ();
11054 if (cu
->language
== language_cplus
)
11056 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11057 &objfile
->per_bfd
->storage_obstack
);
11059 /* If we only computed INTERMEDIATE_NAME, or if
11060 INTERMEDIATE_NAME is already canonical, then we need to
11061 copy it to the appropriate obstack. */
11062 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11063 name
= ((const char *)
11064 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11065 intermediate_name
.c_str (),
11066 intermediate_name
.length ()));
11068 name
= canonical_name
;
11075 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11076 If scope qualifiers are appropriate they will be added. The result
11077 will be allocated on the storage_obstack, or NULL if the DIE does
11078 not have a name. NAME may either be from a previous call to
11079 dwarf2_name or NULL.
11081 The output string will be canonicalized (if C++). */
11083 static const char *
11084 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11086 return dwarf2_compute_name (name
, die
, cu
, 0);
11089 /* Construct a physname for the given DIE in CU. NAME may either be
11090 from a previous call to dwarf2_name or NULL. The result will be
11091 allocated on the objfile_objstack or NULL if the DIE does not have a
11094 The output string will be canonicalized (if C++). */
11096 static const char *
11097 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11099 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11100 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11103 /* In this case dwarf2_compute_name is just a shortcut not building anything
11105 if (!die_needs_namespace (die
, cu
))
11106 return dwarf2_compute_name (name
, die
, cu
, 1);
11108 mangled
= dw2_linkage_name (die
, cu
);
11110 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11111 See https://github.com/rust-lang/rust/issues/32925. */
11112 if (cu
->language
== language_rust
&& mangled
!= NULL
11113 && strchr (mangled
, '{') != NULL
)
11116 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11118 gdb::unique_xmalloc_ptr
<char> demangled
;
11119 if (mangled
!= NULL
)
11121 /* Use DMGL_RET_DROP for C++ template functions to suppress their return
11122 type. It is easier for GDB users to search for such functions as
11123 `name(params)' than `long name(params)'. In such case the minimal
11124 symbol names do not match the full symbol names but for template
11125 functions there is never a need to look up their definition from their
11126 declaration so the only disadvantage remains the minimal symbol
11127 variant `long name(params)' does not have the proper inferior type.
11130 if (cu
->language
== language_go
)
11132 /* This is a lie, but we already lie to the caller new_symbol.
11133 new_symbol assumes we return the mangled name.
11134 This just undoes that lie until things are cleaned up. */
11138 demangled
.reset (gdb_demangle (mangled
,
11139 (DMGL_PARAMS
| DMGL_ANSI
11140 | DMGL_RET_DROP
)));
11143 canon
= demangled
.get ();
11151 if (canon
== NULL
|| check_physname
)
11153 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11155 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11157 /* It may not mean a bug in GDB. The compiler could also
11158 compute DW_AT_linkage_name incorrectly. But in such case
11159 GDB would need to be bug-to-bug compatible. */
11161 complaint (&symfile_complaints
,
11162 _("Computed physname <%s> does not match demangled <%s> "
11163 "(from linkage <%s>) - DIE at 0x%x [in module %s]"),
11164 physname
, canon
, mangled
, to_underlying (die
->sect_off
),
11165 objfile_name (objfile
));
11167 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11168 is available here - over computed PHYSNAME. It is safer
11169 against both buggy GDB and buggy compilers. */
11183 retval
= ((const char *)
11184 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11185 retval
, strlen (retval
)));
11190 /* Inspect DIE in CU for a namespace alias. If one exists, record
11191 a new symbol for it.
11193 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11196 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11198 struct attribute
*attr
;
11200 /* If the die does not have a name, this is not a namespace
11202 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11206 struct die_info
*d
= die
;
11207 struct dwarf2_cu
*imported_cu
= cu
;
11209 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11210 keep inspecting DIEs until we hit the underlying import. */
11211 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11212 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11214 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11218 d
= follow_die_ref (d
, attr
, &imported_cu
);
11219 if (d
->tag
!= DW_TAG_imported_declaration
)
11223 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11225 complaint (&symfile_complaints
,
11226 _("DIE at 0x%x has too many recursively imported "
11227 "declarations"), to_underlying (d
->sect_off
));
11234 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11236 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11237 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11239 /* This declaration is a global namespace alias. Add
11240 a symbol for it whose type is the aliased namespace. */
11241 new_symbol (die
, type
, cu
);
11250 /* Return the using directives repository (global or local?) to use in the
11251 current context for LANGUAGE.
11253 For Ada, imported declarations can materialize renamings, which *may* be
11254 global. However it is impossible (for now?) in DWARF to distinguish
11255 "external" imported declarations and "static" ones. As all imported
11256 declarations seem to be static in all other languages, make them all CU-wide
11257 global only in Ada. */
11259 static struct using_direct
**
11260 using_directives (enum language language
)
11262 if (language
== language_ada
&& context_stack_depth
== 0)
11263 return &global_using_directives
;
11265 return &local_using_directives
;
11268 /* Read the import statement specified by the given die and record it. */
11271 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11273 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11274 struct attribute
*import_attr
;
11275 struct die_info
*imported_die
, *child_die
;
11276 struct dwarf2_cu
*imported_cu
;
11277 const char *imported_name
;
11278 const char *imported_name_prefix
;
11279 const char *canonical_name
;
11280 const char *import_alias
;
11281 const char *imported_declaration
= NULL
;
11282 const char *import_prefix
;
11283 std::vector
<const char *> excludes
;
11285 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11286 if (import_attr
== NULL
)
11288 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11289 dwarf_tag_name (die
->tag
));
11294 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11295 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11296 if (imported_name
== NULL
)
11298 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11300 The import in the following code:
11314 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11315 <52> DW_AT_decl_file : 1
11316 <53> DW_AT_decl_line : 6
11317 <54> DW_AT_import : <0x75>
11318 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11319 <59> DW_AT_name : B
11320 <5b> DW_AT_decl_file : 1
11321 <5c> DW_AT_decl_line : 2
11322 <5d> DW_AT_type : <0x6e>
11324 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11325 <76> DW_AT_byte_size : 4
11326 <77> DW_AT_encoding : 5 (signed)
11328 imports the wrong die ( 0x75 instead of 0x58 ).
11329 This case will be ignored until the gcc bug is fixed. */
11333 /* Figure out the local name after import. */
11334 import_alias
= dwarf2_name (die
, cu
);
11336 /* Figure out where the statement is being imported to. */
11337 import_prefix
= determine_prefix (die
, cu
);
11339 /* Figure out what the scope of the imported die is and prepend it
11340 to the name of the imported die. */
11341 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11343 if (imported_die
->tag
!= DW_TAG_namespace
11344 && imported_die
->tag
!= DW_TAG_module
)
11346 imported_declaration
= imported_name
;
11347 canonical_name
= imported_name_prefix
;
11349 else if (strlen (imported_name_prefix
) > 0)
11350 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11351 imported_name_prefix
,
11352 (cu
->language
== language_d
? "." : "::"),
11353 imported_name
, (char *) NULL
);
11355 canonical_name
= imported_name
;
11357 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11358 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11359 child_die
= sibling_die (child_die
))
11361 /* DWARF-4: A Fortran use statement with a “rename list” may be
11362 represented by an imported module entry with an import attribute
11363 referring to the module and owned entries corresponding to those
11364 entities that are renamed as part of being imported. */
11366 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11368 complaint (&symfile_complaints
,
11369 _("child DW_TAG_imported_declaration expected "
11370 "- DIE at 0x%x [in module %s]"),
11371 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
11375 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11376 if (import_attr
== NULL
)
11378 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11379 dwarf_tag_name (child_die
->tag
));
11384 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11386 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11387 if (imported_name
== NULL
)
11389 complaint (&symfile_complaints
,
11390 _("child DW_TAG_imported_declaration has unknown "
11391 "imported name - DIE at 0x%x [in module %s]"),
11392 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
11396 excludes
.push_back (imported_name
);
11398 process_die (child_die
, cu
);
11401 add_using_directive (using_directives (cu
->language
),
11405 imported_declaration
,
11408 &objfile
->objfile_obstack
);
11411 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11412 types, but gives them a size of zero. Starting with version 14,
11413 ICC is compatible with GCC. */
11416 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11418 if (!cu
->checked_producer
)
11419 check_producer (cu
);
11421 return cu
->producer_is_icc_lt_14
;
11424 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11425 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11426 this, it was first present in GCC release 4.3.0. */
11429 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11431 if (!cu
->checked_producer
)
11432 check_producer (cu
);
11434 return cu
->producer_is_gcc_lt_4_3
;
11437 static file_and_directory
11438 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11440 file_and_directory res
;
11442 /* Find the filename. Do not use dwarf2_name here, since the filename
11443 is not a source language identifier. */
11444 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11445 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11447 if (res
.comp_dir
== NULL
11448 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11449 && IS_ABSOLUTE_PATH (res
.name
))
11451 res
.comp_dir_storage
= ldirname (res
.name
);
11452 if (!res
.comp_dir_storage
.empty ())
11453 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11455 if (res
.comp_dir
!= NULL
)
11457 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11458 directory, get rid of it. */
11459 const char *cp
= strchr (res
.comp_dir
, ':');
11461 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11462 res
.comp_dir
= cp
+ 1;
11465 if (res
.name
== NULL
)
11466 res
.name
= "<unknown>";
11471 /* Handle DW_AT_stmt_list for a compilation unit.
11472 DIE is the DW_TAG_compile_unit die for CU.
11473 COMP_DIR is the compilation directory. LOWPC is passed to
11474 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11477 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11478 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11480 struct dwarf2_per_objfile
*dwarf2_per_objfile
11481 = cu
->per_cu
->dwarf2_per_objfile
;
11482 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11483 struct attribute
*attr
;
11484 struct line_header line_header_local
;
11485 hashval_t line_header_local_hash
;
11487 int decode_mapping
;
11489 gdb_assert (! cu
->per_cu
->is_debug_types
);
11491 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11495 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11497 /* The line header hash table is only created if needed (it exists to
11498 prevent redundant reading of the line table for partial_units).
11499 If we're given a partial_unit, we'll need it. If we're given a
11500 compile_unit, then use the line header hash table if it's already
11501 created, but don't create one just yet. */
11503 if (dwarf2_per_objfile
->line_header_hash
== NULL
11504 && die
->tag
== DW_TAG_partial_unit
)
11506 dwarf2_per_objfile
->line_header_hash
11507 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11508 line_header_eq_voidp
,
11509 free_line_header_voidp
,
11510 &objfile
->objfile_obstack
,
11511 hashtab_obstack_allocate
,
11512 dummy_obstack_deallocate
);
11515 line_header_local
.sect_off
= line_offset
;
11516 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11517 line_header_local_hash
= line_header_hash (&line_header_local
);
11518 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11520 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11521 &line_header_local
,
11522 line_header_local_hash
, NO_INSERT
);
11524 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11525 is not present in *SLOT (since if there is something in *SLOT then
11526 it will be for a partial_unit). */
11527 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11529 gdb_assert (*slot
!= NULL
);
11530 cu
->line_header
= (struct line_header
*) *slot
;
11535 /* dwarf_decode_line_header does not yet provide sufficient information.
11536 We always have to call also dwarf_decode_lines for it. */
11537 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11541 cu
->line_header
= lh
.release ();
11542 cu
->line_header_die_owner
= die
;
11544 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11548 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11549 &line_header_local
,
11550 line_header_local_hash
, INSERT
);
11551 gdb_assert (slot
!= NULL
);
11553 if (slot
!= NULL
&& *slot
== NULL
)
11555 /* This newly decoded line number information unit will be owned
11556 by line_header_hash hash table. */
11557 *slot
= cu
->line_header
;
11558 cu
->line_header_die_owner
= NULL
;
11562 /* We cannot free any current entry in (*slot) as that struct line_header
11563 may be already used by multiple CUs. Create only temporary decoded
11564 line_header for this CU - it may happen at most once for each line
11565 number information unit. And if we're not using line_header_hash
11566 then this is what we want as well. */
11567 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11569 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11570 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11575 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11578 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11580 struct dwarf2_per_objfile
*dwarf2_per_objfile
11581 = cu
->per_cu
->dwarf2_per_objfile
;
11582 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11583 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11584 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11585 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11586 struct attribute
*attr
;
11587 struct die_info
*child_die
;
11588 CORE_ADDR baseaddr
;
11590 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11592 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11594 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11595 from finish_block. */
11596 if (lowpc
== ((CORE_ADDR
) -1))
11598 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11600 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11602 prepare_one_comp_unit (cu
, die
, cu
->language
);
11604 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11605 standardised yet. As a workaround for the language detection we fall
11606 back to the DW_AT_producer string. */
11607 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11608 cu
->language
= language_opencl
;
11610 /* Similar hack for Go. */
11611 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11612 set_cu_language (DW_LANG_Go
, cu
);
11614 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11616 /* Decode line number information if present. We do this before
11617 processing child DIEs, so that the line header table is available
11618 for DW_AT_decl_file. */
11619 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11621 /* Process all dies in compilation unit. */
11622 if (die
->child
!= NULL
)
11624 child_die
= die
->child
;
11625 while (child_die
&& child_die
->tag
)
11627 process_die (child_die
, cu
);
11628 child_die
= sibling_die (child_die
);
11632 /* Decode macro information, if present. Dwarf 2 macro information
11633 refers to information in the line number info statement program
11634 header, so we can only read it if we've read the header
11636 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11638 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11639 if (attr
&& cu
->line_header
)
11641 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11642 complaint (&symfile_complaints
,
11643 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11645 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11649 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11650 if (attr
&& cu
->line_header
)
11652 unsigned int macro_offset
= DW_UNSND (attr
);
11654 dwarf_decode_macros (cu
, macro_offset
, 0);
11659 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
11660 Create the set of symtabs used by this TU, or if this TU is sharing
11661 symtabs with another TU and the symtabs have already been created
11662 then restore those symtabs in the line header.
11663 We don't need the pc/line-number mapping for type units. */
11666 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
11668 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
11669 struct type_unit_group
*tu_group
;
11671 struct attribute
*attr
;
11673 struct signatured_type
*sig_type
;
11675 gdb_assert (per_cu
->is_debug_types
);
11676 sig_type
= (struct signatured_type
*) per_cu
;
11678 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11680 /* If we're using .gdb_index (includes -readnow) then
11681 per_cu->type_unit_group may not have been set up yet. */
11682 if (sig_type
->type_unit_group
== NULL
)
11683 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
11684 tu_group
= sig_type
->type_unit_group
;
11686 /* If we've already processed this stmt_list there's no real need to
11687 do it again, we could fake it and just recreate the part we need
11688 (file name,index -> symtab mapping). If data shows this optimization
11689 is useful we can do it then. */
11690 first_time
= tu_group
->compunit_symtab
== NULL
;
11692 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11697 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11698 lh
= dwarf_decode_line_header (line_offset
, cu
);
11703 dwarf2_start_symtab (cu
, "", NULL
, 0);
11706 gdb_assert (tu_group
->symtabs
== NULL
);
11707 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11712 cu
->line_header
= lh
.release ();
11713 cu
->line_header_die_owner
= die
;
11717 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
11719 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11720 still initializing it, and our caller (a few levels up)
11721 process_full_type_unit still needs to know if this is the first
11724 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
11725 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11726 cu
->line_header
->file_names
.size ());
11728 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11730 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11732 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
11734 if (current_subfile
->symtab
== NULL
)
11736 /* NOTE: start_subfile will recognize when it's been
11737 passed a file it has already seen. So we can't
11738 assume there's a simple mapping from
11739 cu->line_header->file_names to subfiles, plus
11740 cu->line_header->file_names may contain dups. */
11741 current_subfile
->symtab
11742 = allocate_symtab (cust
, current_subfile
->name
);
11745 fe
.symtab
= current_subfile
->symtab
;
11746 tu_group
->symtabs
[i
] = fe
.symtab
;
11751 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11753 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11755 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11757 fe
.symtab
= tu_group
->symtabs
[i
];
11761 /* The main symtab is allocated last. Type units don't have DW_AT_name
11762 so they don't have a "real" (so to speak) symtab anyway.
11763 There is later code that will assign the main symtab to all symbols
11764 that don't have one. We need to handle the case of a symbol with a
11765 missing symtab (DW_AT_decl_file) anyway. */
11768 /* Process DW_TAG_type_unit.
11769 For TUs we want to skip the first top level sibling if it's not the
11770 actual type being defined by this TU. In this case the first top
11771 level sibling is there to provide context only. */
11774 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11776 struct die_info
*child_die
;
11778 prepare_one_comp_unit (cu
, die
, language_minimal
);
11780 /* Initialize (or reinitialize) the machinery for building symtabs.
11781 We do this before processing child DIEs, so that the line header table
11782 is available for DW_AT_decl_file. */
11783 setup_type_unit_groups (die
, cu
);
11785 if (die
->child
!= NULL
)
11787 child_die
= die
->child
;
11788 while (child_die
&& child_die
->tag
)
11790 process_die (child_die
, cu
);
11791 child_die
= sibling_die (child_die
);
11798 http://gcc.gnu.org/wiki/DebugFission
11799 http://gcc.gnu.org/wiki/DebugFissionDWP
11801 To simplify handling of both DWO files ("object" files with the DWARF info)
11802 and DWP files (a file with the DWOs packaged up into one file), we treat
11803 DWP files as having a collection of virtual DWO files. */
11806 hash_dwo_file (const void *item
)
11808 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11811 hash
= htab_hash_string (dwo_file
->dwo_name
);
11812 if (dwo_file
->comp_dir
!= NULL
)
11813 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11818 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11820 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11821 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11823 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11825 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11826 return lhs
->comp_dir
== rhs
->comp_dir
;
11827 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11830 /* Allocate a hash table for DWO files. */
11833 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11835 return htab_create_alloc_ex (41,
11839 &objfile
->objfile_obstack
,
11840 hashtab_obstack_allocate
,
11841 dummy_obstack_deallocate
);
11844 /* Lookup DWO file DWO_NAME. */
11847 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11848 const char *dwo_name
,
11849 const char *comp_dir
)
11851 struct dwo_file find_entry
;
11854 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11855 dwarf2_per_objfile
->dwo_files
11856 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11858 memset (&find_entry
, 0, sizeof (find_entry
));
11859 find_entry
.dwo_name
= dwo_name
;
11860 find_entry
.comp_dir
= comp_dir
;
11861 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11867 hash_dwo_unit (const void *item
)
11869 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11871 /* This drops the top 32 bits of the id, but is ok for a hash. */
11872 return dwo_unit
->signature
;
11876 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11878 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11879 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11881 /* The signature is assumed to be unique within the DWO file.
11882 So while object file CU dwo_id's always have the value zero,
11883 that's OK, assuming each object file DWO file has only one CU,
11884 and that's the rule for now. */
11885 return lhs
->signature
== rhs
->signature
;
11888 /* Allocate a hash table for DWO CUs,TUs.
11889 There is one of these tables for each of CUs,TUs for each DWO file. */
11892 allocate_dwo_unit_table (struct objfile
*objfile
)
11894 /* Start out with a pretty small number.
11895 Generally DWO files contain only one CU and maybe some TUs. */
11896 return htab_create_alloc_ex (3,
11900 &objfile
->objfile_obstack
,
11901 hashtab_obstack_allocate
,
11902 dummy_obstack_deallocate
);
11905 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11907 struct create_dwo_cu_data
11909 struct dwo_file
*dwo_file
;
11910 struct dwo_unit dwo_unit
;
11913 /* die_reader_func for create_dwo_cu. */
11916 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11917 const gdb_byte
*info_ptr
,
11918 struct die_info
*comp_unit_die
,
11922 struct dwarf2_cu
*cu
= reader
->cu
;
11923 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11924 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11925 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11926 struct dwo_file
*dwo_file
= data
->dwo_file
;
11927 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11928 struct attribute
*attr
;
11930 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11933 complaint (&symfile_complaints
,
11934 _("Dwarf Error: debug entry at offset 0x%x is missing"
11935 " its dwo_id [in module %s]"),
11936 to_underlying (sect_off
), dwo_file
->dwo_name
);
11940 dwo_unit
->dwo_file
= dwo_file
;
11941 dwo_unit
->signature
= DW_UNSND (attr
);
11942 dwo_unit
->section
= section
;
11943 dwo_unit
->sect_off
= sect_off
;
11944 dwo_unit
->length
= cu
->per_cu
->length
;
11946 if (dwarf_read_debug
)
11947 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, dwo_id %s\n",
11948 to_underlying (sect_off
),
11949 hex_string (dwo_unit
->signature
));
11952 /* Create the dwo_units for the CUs in a DWO_FILE.
11953 Note: This function processes DWO files only, not DWP files. */
11956 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11957 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11960 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11961 const gdb_byte
*info_ptr
, *end_ptr
;
11963 dwarf2_read_section (objfile
, §ion
);
11964 info_ptr
= section
.buffer
;
11966 if (info_ptr
== NULL
)
11969 if (dwarf_read_debug
)
11971 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11972 get_section_name (§ion
),
11973 get_section_file_name (§ion
));
11976 end_ptr
= info_ptr
+ section
.size
;
11977 while (info_ptr
< end_ptr
)
11979 struct dwarf2_per_cu_data per_cu
;
11980 struct create_dwo_cu_data create_dwo_cu_data
;
11981 struct dwo_unit
*dwo_unit
;
11983 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11985 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11986 sizeof (create_dwo_cu_data
.dwo_unit
));
11987 memset (&per_cu
, 0, sizeof (per_cu
));
11988 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11989 per_cu
.is_debug_types
= 0;
11990 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11991 per_cu
.section
= §ion
;
11992 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11994 init_cutu_and_read_dies_no_follow (
11995 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11996 info_ptr
+= per_cu
.length
;
11998 // If the unit could not be parsed, skip it.
11999 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12002 if (cus_htab
== NULL
)
12003 cus_htab
= allocate_dwo_unit_table (objfile
);
12005 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12006 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12007 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12008 gdb_assert (slot
!= NULL
);
12011 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12012 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12014 complaint (&symfile_complaints
,
12015 _("debug cu entry at offset 0x%x is duplicate to"
12016 " the entry at offset 0x%x, signature %s"),
12017 to_underlying (sect_off
), to_underlying (dup_sect_off
),
12018 hex_string (dwo_unit
->signature
));
12020 *slot
= (void *)dwo_unit
;
12024 /* DWP file .debug_{cu,tu}_index section format:
12025 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12029 Both index sections have the same format, and serve to map a 64-bit
12030 signature to a set of section numbers. Each section begins with a header,
12031 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12032 indexes, and a pool of 32-bit section numbers. The index sections will be
12033 aligned at 8-byte boundaries in the file.
12035 The index section header consists of:
12037 V, 32 bit version number
12039 N, 32 bit number of compilation units or type units in the index
12040 M, 32 bit number of slots in the hash table
12042 Numbers are recorded using the byte order of the application binary.
12044 The hash table begins at offset 16 in the section, and consists of an array
12045 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12046 order of the application binary). Unused slots in the hash table are 0.
12047 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12049 The parallel table begins immediately after the hash table
12050 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12051 array of 32-bit indexes (using the byte order of the application binary),
12052 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12053 table contains a 32-bit index into the pool of section numbers. For unused
12054 hash table slots, the corresponding entry in the parallel table will be 0.
12056 The pool of section numbers begins immediately following the hash table
12057 (at offset 16 + 12 * M from the beginning of the section). The pool of
12058 section numbers consists of an array of 32-bit words (using the byte order
12059 of the application binary). Each item in the array is indexed starting
12060 from 0. The hash table entry provides the index of the first section
12061 number in the set. Additional section numbers in the set follow, and the
12062 set is terminated by a 0 entry (section number 0 is not used in ELF).
12064 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12065 section must be the first entry in the set, and the .debug_abbrev.dwo must
12066 be the second entry. Other members of the set may follow in any order.
12072 DWP Version 2 combines all the .debug_info, etc. sections into one,
12073 and the entries in the index tables are now offsets into these sections.
12074 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12077 Index Section Contents:
12079 Hash Table of Signatures dwp_hash_table.hash_table
12080 Parallel Table of Indices dwp_hash_table.unit_table
12081 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12082 Table of Section Sizes dwp_hash_table.v2.sizes
12084 The index section header consists of:
12086 V, 32 bit version number
12087 L, 32 bit number of columns in the table of section offsets
12088 N, 32 bit number of compilation units or type units in the index
12089 M, 32 bit number of slots in the hash table
12091 Numbers are recorded using the byte order of the application binary.
12093 The hash table has the same format as version 1.
12094 The parallel table of indices has the same format as version 1,
12095 except that the entries are origin-1 indices into the table of sections
12096 offsets and the table of section sizes.
12098 The table of offsets begins immediately following the parallel table
12099 (at offset 16 + 12 * M from the beginning of the section). The table is
12100 a two-dimensional array of 32-bit words (using the byte order of the
12101 application binary), with L columns and N+1 rows, in row-major order.
12102 Each row in the array is indexed starting from 0. The first row provides
12103 a key to the remaining rows: each column in this row provides an identifier
12104 for a debug section, and the offsets in the same column of subsequent rows
12105 refer to that section. The section identifiers are:
12107 DW_SECT_INFO 1 .debug_info.dwo
12108 DW_SECT_TYPES 2 .debug_types.dwo
12109 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12110 DW_SECT_LINE 4 .debug_line.dwo
12111 DW_SECT_LOC 5 .debug_loc.dwo
12112 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12113 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12114 DW_SECT_MACRO 8 .debug_macro.dwo
12116 The offsets provided by the CU and TU index sections are the base offsets
12117 for the contributions made by each CU or TU to the corresponding section
12118 in the package file. Each CU and TU header contains an abbrev_offset
12119 field, used to find the abbreviations table for that CU or TU within the
12120 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12121 be interpreted as relative to the base offset given in the index section.
12122 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12123 should be interpreted as relative to the base offset for .debug_line.dwo,
12124 and offsets into other debug sections obtained from DWARF attributes should
12125 also be interpreted as relative to the corresponding base offset.
12127 The table of sizes begins immediately following the table of offsets.
12128 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12129 with L columns and N rows, in row-major order. Each row in the array is
12130 indexed starting from 1 (row 0 is shared by the two tables).
12134 Hash table lookup is handled the same in version 1 and 2:
12136 We assume that N and M will not exceed 2^32 - 1.
12137 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12139 Given a 64-bit compilation unit signature or a type signature S, an entry
12140 in the hash table is located as follows:
12142 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12143 the low-order k bits all set to 1.
12145 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12147 3) If the hash table entry at index H matches the signature, use that
12148 entry. If the hash table entry at index H is unused (all zeroes),
12149 terminate the search: the signature is not present in the table.
12151 4) Let H = (H + H') modulo M. Repeat at Step 3.
12153 Because M > N and H' and M are relatively prime, the search is guaranteed
12154 to stop at an unused slot or find the match. */
12156 /* Create a hash table to map DWO IDs to their CU/TU entry in
12157 .debug_{info,types}.dwo in DWP_FILE.
12158 Returns NULL if there isn't one.
12159 Note: This function processes DWP files only, not DWO files. */
12161 static struct dwp_hash_table
*
12162 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12163 struct dwp_file
*dwp_file
, int is_debug_types
)
12165 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12166 bfd
*dbfd
= dwp_file
->dbfd
;
12167 const gdb_byte
*index_ptr
, *index_end
;
12168 struct dwarf2_section_info
*index
;
12169 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12170 struct dwp_hash_table
*htab
;
12172 if (is_debug_types
)
12173 index
= &dwp_file
->sections
.tu_index
;
12175 index
= &dwp_file
->sections
.cu_index
;
12177 if (dwarf2_section_empty_p (index
))
12179 dwarf2_read_section (objfile
, index
);
12181 index_ptr
= index
->buffer
;
12182 index_end
= index_ptr
+ index
->size
;
12184 version
= read_4_bytes (dbfd
, index_ptr
);
12187 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12191 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12193 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12196 if (version
!= 1 && version
!= 2)
12198 error (_("Dwarf Error: unsupported DWP file version (%s)"
12199 " [in module %s]"),
12200 pulongest (version
), dwp_file
->name
);
12202 if (nr_slots
!= (nr_slots
& -nr_slots
))
12204 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12205 " is not power of 2 [in module %s]"),
12206 pulongest (nr_slots
), dwp_file
->name
);
12209 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12210 htab
->version
= version
;
12211 htab
->nr_columns
= nr_columns
;
12212 htab
->nr_units
= nr_units
;
12213 htab
->nr_slots
= nr_slots
;
12214 htab
->hash_table
= index_ptr
;
12215 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12217 /* Exit early if the table is empty. */
12218 if (nr_slots
== 0 || nr_units
== 0
12219 || (version
== 2 && nr_columns
== 0))
12221 /* All must be zero. */
12222 if (nr_slots
!= 0 || nr_units
!= 0
12223 || (version
== 2 && nr_columns
!= 0))
12225 complaint (&symfile_complaints
,
12226 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12227 " all zero [in modules %s]"),
12235 htab
->section_pool
.v1
.indices
=
12236 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12237 /* It's harder to decide whether the section is too small in v1.
12238 V1 is deprecated anyway so we punt. */
12242 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12243 int *ids
= htab
->section_pool
.v2
.section_ids
;
12244 /* Reverse map for error checking. */
12245 int ids_seen
[DW_SECT_MAX
+ 1];
12248 if (nr_columns
< 2)
12250 error (_("Dwarf Error: bad DWP hash table, too few columns"
12251 " in section table [in module %s]"),
12254 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12256 error (_("Dwarf Error: bad DWP hash table, too many columns"
12257 " in section table [in module %s]"),
12260 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12261 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12262 for (i
= 0; i
< nr_columns
; ++i
)
12264 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12266 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12268 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12269 " in section table [in module %s]"),
12270 id
, dwp_file
->name
);
12272 if (ids_seen
[id
] != -1)
12274 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12275 " id %d in section table [in module %s]"),
12276 id
, dwp_file
->name
);
12281 /* Must have exactly one info or types section. */
12282 if (((ids_seen
[DW_SECT_INFO
] != -1)
12283 + (ids_seen
[DW_SECT_TYPES
] != -1))
12286 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12287 " DWO info/types section [in module %s]"),
12290 /* Must have an abbrev section. */
12291 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12293 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12294 " section [in module %s]"),
12297 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12298 htab
->section_pool
.v2
.sizes
=
12299 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12300 * nr_units
* nr_columns
);
12301 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12302 * nr_units
* nr_columns
))
12305 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12306 " [in module %s]"),
12314 /* Update SECTIONS with the data from SECTP.
12316 This function is like the other "locate" section routines that are
12317 passed to bfd_map_over_sections, but in this context the sections to
12318 read comes from the DWP V1 hash table, not the full ELF section table.
12320 The result is non-zero for success, or zero if an error was found. */
12323 locate_v1_virtual_dwo_sections (asection
*sectp
,
12324 struct virtual_v1_dwo_sections
*sections
)
12326 const struct dwop_section_names
*names
= &dwop_section_names
;
12328 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12330 /* There can be only one. */
12331 if (sections
->abbrev
.s
.section
!= NULL
)
12333 sections
->abbrev
.s
.section
= sectp
;
12334 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12336 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12337 || section_is_p (sectp
->name
, &names
->types_dwo
))
12339 /* There can be only one. */
12340 if (sections
->info_or_types
.s
.section
!= NULL
)
12342 sections
->info_or_types
.s
.section
= sectp
;
12343 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12345 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12347 /* There can be only one. */
12348 if (sections
->line
.s
.section
!= NULL
)
12350 sections
->line
.s
.section
= sectp
;
12351 sections
->line
.size
= bfd_get_section_size (sectp
);
12353 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12355 /* There can be only one. */
12356 if (sections
->loc
.s
.section
!= NULL
)
12358 sections
->loc
.s
.section
= sectp
;
12359 sections
->loc
.size
= bfd_get_section_size (sectp
);
12361 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12363 /* There can be only one. */
12364 if (sections
->macinfo
.s
.section
!= NULL
)
12366 sections
->macinfo
.s
.section
= sectp
;
12367 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12369 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12371 /* There can be only one. */
12372 if (sections
->macro
.s
.section
!= NULL
)
12374 sections
->macro
.s
.section
= sectp
;
12375 sections
->macro
.size
= bfd_get_section_size (sectp
);
12377 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12379 /* There can be only one. */
12380 if (sections
->str_offsets
.s
.section
!= NULL
)
12382 sections
->str_offsets
.s
.section
= sectp
;
12383 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12387 /* No other kind of section is valid. */
12394 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12395 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12396 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12397 This is for DWP version 1 files. */
12399 static struct dwo_unit
*
12400 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12401 struct dwp_file
*dwp_file
,
12402 uint32_t unit_index
,
12403 const char *comp_dir
,
12404 ULONGEST signature
, int is_debug_types
)
12406 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12407 const struct dwp_hash_table
*dwp_htab
=
12408 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12409 bfd
*dbfd
= dwp_file
->dbfd
;
12410 const char *kind
= is_debug_types
? "TU" : "CU";
12411 struct dwo_file
*dwo_file
;
12412 struct dwo_unit
*dwo_unit
;
12413 struct virtual_v1_dwo_sections sections
;
12414 void **dwo_file_slot
;
12417 gdb_assert (dwp_file
->version
== 1);
12419 if (dwarf_read_debug
)
12421 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12423 pulongest (unit_index
), hex_string (signature
),
12427 /* Fetch the sections of this DWO unit.
12428 Put a limit on the number of sections we look for so that bad data
12429 doesn't cause us to loop forever. */
12431 #define MAX_NR_V1_DWO_SECTIONS \
12432 (1 /* .debug_info or .debug_types */ \
12433 + 1 /* .debug_abbrev */ \
12434 + 1 /* .debug_line */ \
12435 + 1 /* .debug_loc */ \
12436 + 1 /* .debug_str_offsets */ \
12437 + 1 /* .debug_macro or .debug_macinfo */ \
12438 + 1 /* trailing zero */)
12440 memset (§ions
, 0, sizeof (sections
));
12442 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12445 uint32_t section_nr
=
12446 read_4_bytes (dbfd
,
12447 dwp_htab
->section_pool
.v1
.indices
12448 + (unit_index
+ i
) * sizeof (uint32_t));
12450 if (section_nr
== 0)
12452 if (section_nr
>= dwp_file
->num_sections
)
12454 error (_("Dwarf Error: bad DWP hash table, section number too large"
12455 " [in module %s]"),
12459 sectp
= dwp_file
->elf_sections
[section_nr
];
12460 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12462 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12463 " [in module %s]"),
12469 || dwarf2_section_empty_p (§ions
.info_or_types
)
12470 || dwarf2_section_empty_p (§ions
.abbrev
))
12472 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12473 " [in module %s]"),
12476 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12478 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12479 " [in module %s]"),
12483 /* It's easier for the rest of the code if we fake a struct dwo_file and
12484 have dwo_unit "live" in that. At least for now.
12486 The DWP file can be made up of a random collection of CUs and TUs.
12487 However, for each CU + set of TUs that came from the same original DWO
12488 file, we can combine them back into a virtual DWO file to save space
12489 (fewer struct dwo_file objects to allocate). Remember that for really
12490 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12492 std::string virtual_dwo_name
=
12493 string_printf ("virtual-dwo/%d-%d-%d-%d",
12494 get_section_id (§ions
.abbrev
),
12495 get_section_id (§ions
.line
),
12496 get_section_id (§ions
.loc
),
12497 get_section_id (§ions
.str_offsets
));
12498 /* Can we use an existing virtual DWO file? */
12499 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12500 virtual_dwo_name
.c_str (),
12502 /* Create one if necessary. */
12503 if (*dwo_file_slot
== NULL
)
12505 if (dwarf_read_debug
)
12507 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12508 virtual_dwo_name
.c_str ());
12510 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12512 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12513 virtual_dwo_name
.c_str (),
12514 virtual_dwo_name
.size ());
12515 dwo_file
->comp_dir
= comp_dir
;
12516 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12517 dwo_file
->sections
.line
= sections
.line
;
12518 dwo_file
->sections
.loc
= sections
.loc
;
12519 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12520 dwo_file
->sections
.macro
= sections
.macro
;
12521 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12522 /* The "str" section is global to the entire DWP file. */
12523 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12524 /* The info or types section is assigned below to dwo_unit,
12525 there's no need to record it in dwo_file.
12526 Also, we can't simply record type sections in dwo_file because
12527 we record a pointer into the vector in dwo_unit. As we collect more
12528 types we'll grow the vector and eventually have to reallocate space
12529 for it, invalidating all copies of pointers into the previous
12531 *dwo_file_slot
= dwo_file
;
12535 if (dwarf_read_debug
)
12537 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12538 virtual_dwo_name
.c_str ());
12540 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12543 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12544 dwo_unit
->dwo_file
= dwo_file
;
12545 dwo_unit
->signature
= signature
;
12546 dwo_unit
->section
=
12547 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12548 *dwo_unit
->section
= sections
.info_or_types
;
12549 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12554 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12555 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12556 piece within that section used by a TU/CU, return a virtual section
12557 of just that piece. */
12559 static struct dwarf2_section_info
12560 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12561 struct dwarf2_section_info
*section
,
12562 bfd_size_type offset
, bfd_size_type size
)
12564 struct dwarf2_section_info result
;
12567 gdb_assert (section
!= NULL
);
12568 gdb_assert (!section
->is_virtual
);
12570 memset (&result
, 0, sizeof (result
));
12571 result
.s
.containing_section
= section
;
12572 result
.is_virtual
= 1;
12577 sectp
= get_section_bfd_section (section
);
12579 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12580 bounds of the real section. This is a pretty-rare event, so just
12581 flag an error (easier) instead of a warning and trying to cope. */
12583 || offset
+ size
> bfd_get_section_size (sectp
))
12585 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12586 " in section %s [in module %s]"),
12587 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12588 objfile_name (dwarf2_per_objfile
->objfile
));
12591 result
.virtual_offset
= offset
;
12592 result
.size
= size
;
12596 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12597 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12598 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12599 This is for DWP version 2 files. */
12601 static struct dwo_unit
*
12602 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12603 struct dwp_file
*dwp_file
,
12604 uint32_t unit_index
,
12605 const char *comp_dir
,
12606 ULONGEST signature
, int is_debug_types
)
12608 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12609 const struct dwp_hash_table
*dwp_htab
=
12610 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12611 bfd
*dbfd
= dwp_file
->dbfd
;
12612 const char *kind
= is_debug_types
? "TU" : "CU";
12613 struct dwo_file
*dwo_file
;
12614 struct dwo_unit
*dwo_unit
;
12615 struct virtual_v2_dwo_sections sections
;
12616 void **dwo_file_slot
;
12619 gdb_assert (dwp_file
->version
== 2);
12621 if (dwarf_read_debug
)
12623 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12625 pulongest (unit_index
), hex_string (signature
),
12629 /* Fetch the section offsets of this DWO unit. */
12631 memset (§ions
, 0, sizeof (sections
));
12633 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12635 uint32_t offset
= read_4_bytes (dbfd
,
12636 dwp_htab
->section_pool
.v2
.offsets
12637 + (((unit_index
- 1) * dwp_htab
->nr_columns
12639 * sizeof (uint32_t)));
12640 uint32_t size
= read_4_bytes (dbfd
,
12641 dwp_htab
->section_pool
.v2
.sizes
12642 + (((unit_index
- 1) * dwp_htab
->nr_columns
12644 * sizeof (uint32_t)));
12646 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12649 case DW_SECT_TYPES
:
12650 sections
.info_or_types_offset
= offset
;
12651 sections
.info_or_types_size
= size
;
12653 case DW_SECT_ABBREV
:
12654 sections
.abbrev_offset
= offset
;
12655 sections
.abbrev_size
= size
;
12658 sections
.line_offset
= offset
;
12659 sections
.line_size
= size
;
12662 sections
.loc_offset
= offset
;
12663 sections
.loc_size
= size
;
12665 case DW_SECT_STR_OFFSETS
:
12666 sections
.str_offsets_offset
= offset
;
12667 sections
.str_offsets_size
= size
;
12669 case DW_SECT_MACINFO
:
12670 sections
.macinfo_offset
= offset
;
12671 sections
.macinfo_size
= size
;
12673 case DW_SECT_MACRO
:
12674 sections
.macro_offset
= offset
;
12675 sections
.macro_size
= size
;
12680 /* It's easier for the rest of the code if we fake a struct dwo_file and
12681 have dwo_unit "live" in that. At least for now.
12683 The DWP file can be made up of a random collection of CUs and TUs.
12684 However, for each CU + set of TUs that came from the same original DWO
12685 file, we can combine them back into a virtual DWO file to save space
12686 (fewer struct dwo_file objects to allocate). Remember that for really
12687 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12689 std::string virtual_dwo_name
=
12690 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12691 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12692 (long) (sections
.line_size
? sections
.line_offset
: 0),
12693 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12694 (long) (sections
.str_offsets_size
12695 ? sections
.str_offsets_offset
: 0));
12696 /* Can we use an existing virtual DWO file? */
12697 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12698 virtual_dwo_name
.c_str (),
12700 /* Create one if necessary. */
12701 if (*dwo_file_slot
== NULL
)
12703 if (dwarf_read_debug
)
12705 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12706 virtual_dwo_name
.c_str ());
12708 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12710 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12711 virtual_dwo_name
.c_str (),
12712 virtual_dwo_name
.size ());
12713 dwo_file
->comp_dir
= comp_dir
;
12714 dwo_file
->sections
.abbrev
=
12715 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12716 sections
.abbrev_offset
, sections
.abbrev_size
);
12717 dwo_file
->sections
.line
=
12718 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12719 sections
.line_offset
, sections
.line_size
);
12720 dwo_file
->sections
.loc
=
12721 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12722 sections
.loc_offset
, sections
.loc_size
);
12723 dwo_file
->sections
.macinfo
=
12724 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12725 sections
.macinfo_offset
, sections
.macinfo_size
);
12726 dwo_file
->sections
.macro
=
12727 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12728 sections
.macro_offset
, sections
.macro_size
);
12729 dwo_file
->sections
.str_offsets
=
12730 create_dwp_v2_section (dwarf2_per_objfile
,
12731 &dwp_file
->sections
.str_offsets
,
12732 sections
.str_offsets_offset
,
12733 sections
.str_offsets_size
);
12734 /* The "str" section is global to the entire DWP file. */
12735 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12736 /* The info or types section is assigned below to dwo_unit,
12737 there's no need to record it in dwo_file.
12738 Also, we can't simply record type sections in dwo_file because
12739 we record a pointer into the vector in dwo_unit. As we collect more
12740 types we'll grow the vector and eventually have to reallocate space
12741 for it, invalidating all copies of pointers into the previous
12743 *dwo_file_slot
= dwo_file
;
12747 if (dwarf_read_debug
)
12749 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12750 virtual_dwo_name
.c_str ());
12752 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12755 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12756 dwo_unit
->dwo_file
= dwo_file
;
12757 dwo_unit
->signature
= signature
;
12758 dwo_unit
->section
=
12759 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12760 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12762 ? &dwp_file
->sections
.types
12763 : &dwp_file
->sections
.info
,
12764 sections
.info_or_types_offset
,
12765 sections
.info_or_types_size
);
12766 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12771 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12772 Returns NULL if the signature isn't found. */
12774 static struct dwo_unit
*
12775 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12776 struct dwp_file
*dwp_file
, const char *comp_dir
,
12777 ULONGEST signature
, int is_debug_types
)
12779 const struct dwp_hash_table
*dwp_htab
=
12780 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12781 bfd
*dbfd
= dwp_file
->dbfd
;
12782 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12783 uint32_t hash
= signature
& mask
;
12784 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12787 struct dwo_unit find_dwo_cu
;
12789 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12790 find_dwo_cu
.signature
= signature
;
12791 slot
= htab_find_slot (is_debug_types
12792 ? dwp_file
->loaded_tus
12793 : dwp_file
->loaded_cus
,
12794 &find_dwo_cu
, INSERT
);
12797 return (struct dwo_unit
*) *slot
;
12799 /* Use a for loop so that we don't loop forever on bad debug info. */
12800 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12802 ULONGEST signature_in_table
;
12804 signature_in_table
=
12805 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12806 if (signature_in_table
== signature
)
12808 uint32_t unit_index
=
12809 read_4_bytes (dbfd
,
12810 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12812 if (dwp_file
->version
== 1)
12814 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12815 dwp_file
, unit_index
,
12816 comp_dir
, signature
,
12821 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12822 dwp_file
, unit_index
,
12823 comp_dir
, signature
,
12826 return (struct dwo_unit
*) *slot
;
12828 if (signature_in_table
== 0)
12830 hash
= (hash
+ hash2
) & mask
;
12833 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12834 " [in module %s]"),
12838 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12839 Open the file specified by FILE_NAME and hand it off to BFD for
12840 preliminary analysis. Return a newly initialized bfd *, which
12841 includes a canonicalized copy of FILE_NAME.
12842 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12843 SEARCH_CWD is true if the current directory is to be searched.
12844 It will be searched before debug-file-directory.
12845 If successful, the file is added to the bfd include table of the
12846 objfile's bfd (see gdb_bfd_record_inclusion).
12847 If unable to find/open the file, return NULL.
12848 NOTE: This function is derived from symfile_bfd_open. */
12850 static gdb_bfd_ref_ptr
12851 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12852 const char *file_name
, int is_dwp
, int search_cwd
)
12855 char *absolute_name
;
12856 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12857 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12858 to debug_file_directory. */
12860 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12864 if (*debug_file_directory
!= '\0')
12865 search_path
= concat (".", dirname_separator_string
,
12866 debug_file_directory
, (char *) NULL
);
12868 search_path
= xstrdup (".");
12871 search_path
= xstrdup (debug_file_directory
);
12873 flags
= OPF_RETURN_REALPATH
;
12875 flags
|= OPF_SEARCH_IN_PATH
;
12876 desc
= openp (search_path
, flags
, file_name
,
12877 O_RDONLY
| O_BINARY
, &absolute_name
);
12878 xfree (search_path
);
12882 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
, gnutarget
, desc
));
12883 xfree (absolute_name
);
12884 if (sym_bfd
== NULL
)
12886 bfd_set_cacheable (sym_bfd
.get (), 1);
12888 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12891 /* Success. Record the bfd as having been included by the objfile's bfd.
12892 This is important because things like demangled_names_hash lives in the
12893 objfile's per_bfd space and may have references to things like symbol
12894 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12895 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12900 /* Try to open DWO file FILE_NAME.
12901 COMP_DIR is the DW_AT_comp_dir attribute.
12902 The result is the bfd handle of the file.
12903 If there is a problem finding or opening the file, return NULL.
12904 Upon success, the canonicalized path of the file is stored in the bfd,
12905 same as symfile_bfd_open. */
12907 static gdb_bfd_ref_ptr
12908 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12909 const char *file_name
, const char *comp_dir
)
12911 if (IS_ABSOLUTE_PATH (file_name
))
12912 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12913 0 /*is_dwp*/, 0 /*search_cwd*/);
12915 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12917 if (comp_dir
!= NULL
)
12919 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12920 file_name
, (char *) NULL
);
12922 /* NOTE: If comp_dir is a relative path, this will also try the
12923 search path, which seems useful. */
12924 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12927 1 /*search_cwd*/));
12928 xfree (path_to_try
);
12933 /* That didn't work, try debug-file-directory, which, despite its name,
12934 is a list of paths. */
12936 if (*debug_file_directory
== '\0')
12939 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12940 0 /*is_dwp*/, 1 /*search_cwd*/);
12943 /* This function is mapped across the sections and remembers the offset and
12944 size of each of the DWO debugging sections we are interested in. */
12947 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12949 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12950 const struct dwop_section_names
*names
= &dwop_section_names
;
12952 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12954 dwo_sections
->abbrev
.s
.section
= sectp
;
12955 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12957 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12959 dwo_sections
->info
.s
.section
= sectp
;
12960 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
12962 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12964 dwo_sections
->line
.s
.section
= sectp
;
12965 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
12967 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12969 dwo_sections
->loc
.s
.section
= sectp
;
12970 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
12972 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12974 dwo_sections
->macinfo
.s
.section
= sectp
;
12975 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12977 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12979 dwo_sections
->macro
.s
.section
= sectp
;
12980 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
12982 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12984 dwo_sections
->str
.s
.section
= sectp
;
12985 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
12987 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12989 dwo_sections
->str_offsets
.s
.section
= sectp
;
12990 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12992 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12994 struct dwarf2_section_info type_section
;
12996 memset (&type_section
, 0, sizeof (type_section
));
12997 type_section
.s
.section
= sectp
;
12998 type_section
.size
= bfd_get_section_size (sectp
);
12999 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
13004 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13005 by PER_CU. This is for the non-DWP case.
13006 The result is NULL if DWO_NAME can't be found. */
13008 static struct dwo_file
*
13009 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13010 const char *dwo_name
, const char *comp_dir
)
13012 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13013 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13014 struct dwo_file
*dwo_file
;
13015 struct cleanup
*cleanups
;
13017 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
13020 if (dwarf_read_debug
)
13021 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13024 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13025 dwo_file
->dwo_name
= dwo_name
;
13026 dwo_file
->comp_dir
= comp_dir
;
13027 dwo_file
->dbfd
= dbfd
.release ();
13029 free_dwo_file_cleanup_data
*cleanup_data
= XNEW (free_dwo_file_cleanup_data
);
13030 cleanup_data
->dwo_file
= dwo_file
;
13031 cleanup_data
->dwarf2_per_objfile
= dwarf2_per_objfile
;
13033 cleanups
= make_cleanup (free_dwo_file_cleanup
, cleanup_data
);
13035 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
13036 &dwo_file
->sections
);
13038 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13041 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
,
13042 dwo_file
->sections
.types
, dwo_file
->tus
);
13044 discard_cleanups (cleanups
);
13046 if (dwarf_read_debug
)
13047 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13052 /* This function is mapped across the sections and remembers the offset and
13053 size of each of the DWP debugging sections common to version 1 and 2 that
13054 we are interested in. */
13057 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13058 void *dwp_file_ptr
)
13060 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13061 const struct dwop_section_names
*names
= &dwop_section_names
;
13062 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13064 /* Record the ELF section number for later lookup: this is what the
13065 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13066 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13067 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13069 /* Look for specific sections that we need. */
13070 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13072 dwp_file
->sections
.str
.s
.section
= sectp
;
13073 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13075 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13077 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13078 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13080 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13082 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13083 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13087 /* This function is mapped across the sections and remembers the offset and
13088 size of each of the DWP version 2 debugging sections that we are interested
13089 in. This is split into a separate function because we don't know if we
13090 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13093 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13095 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13096 const struct dwop_section_names
*names
= &dwop_section_names
;
13097 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13099 /* Record the ELF section number for later lookup: this is what the
13100 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13101 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13102 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13104 /* Look for specific sections that we need. */
13105 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13107 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13108 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13110 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13112 dwp_file
->sections
.info
.s
.section
= sectp
;
13113 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13115 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13117 dwp_file
->sections
.line
.s
.section
= sectp
;
13118 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13120 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13122 dwp_file
->sections
.loc
.s
.section
= sectp
;
13123 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13125 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13127 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13128 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13130 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13132 dwp_file
->sections
.macro
.s
.section
= sectp
;
13133 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13135 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13137 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13138 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13140 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13142 dwp_file
->sections
.types
.s
.section
= sectp
;
13143 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13147 /* Hash function for dwp_file loaded CUs/TUs. */
13150 hash_dwp_loaded_cutus (const void *item
)
13152 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13154 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13155 return dwo_unit
->signature
;
13158 /* Equality function for dwp_file loaded CUs/TUs. */
13161 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13163 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13164 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13166 return dua
->signature
== dub
->signature
;
13169 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13172 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13174 return htab_create_alloc_ex (3,
13175 hash_dwp_loaded_cutus
,
13176 eq_dwp_loaded_cutus
,
13178 &objfile
->objfile_obstack
,
13179 hashtab_obstack_allocate
,
13180 dummy_obstack_deallocate
);
13183 /* Try to open DWP file FILE_NAME.
13184 The result is the bfd handle of the file.
13185 If there is a problem finding or opening the file, return NULL.
13186 Upon success, the canonicalized path of the file is stored in the bfd,
13187 same as symfile_bfd_open. */
13189 static gdb_bfd_ref_ptr
13190 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13191 const char *file_name
)
13193 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13195 1 /*search_cwd*/));
13199 /* Work around upstream bug 15652.
13200 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13201 [Whether that's a "bug" is debatable, but it is getting in our way.]
13202 We have no real idea where the dwp file is, because gdb's realpath-ing
13203 of the executable's path may have discarded the needed info.
13204 [IWBN if the dwp file name was recorded in the executable, akin to
13205 .gnu_debuglink, but that doesn't exist yet.]
13206 Strip the directory from FILE_NAME and search again. */
13207 if (*debug_file_directory
!= '\0')
13209 /* Don't implicitly search the current directory here.
13210 If the user wants to search "." to handle this case,
13211 it must be added to debug-file-directory. */
13212 return try_open_dwop_file (dwarf2_per_objfile
,
13213 lbasename (file_name
), 1 /*is_dwp*/,
13220 /* Initialize the use of the DWP file for the current objfile.
13221 By convention the name of the DWP file is ${objfile}.dwp.
13222 The result is NULL if it can't be found. */
13224 static struct dwp_file
*
13225 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13227 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13228 struct dwp_file
*dwp_file
;
13230 /* Try to find first .dwp for the binary file before any symbolic links
13233 /* If the objfile is a debug file, find the name of the real binary
13234 file and get the name of dwp file from there. */
13235 std::string dwp_name
;
13236 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13238 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13239 const char *backlink_basename
= lbasename (backlink
->original_name
);
13241 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13244 dwp_name
= objfile
->original_name
;
13246 dwp_name
+= ".dwp";
13248 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13250 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13252 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13253 dwp_name
= objfile_name (objfile
);
13254 dwp_name
+= ".dwp";
13255 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13260 if (dwarf_read_debug
)
13261 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13264 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13265 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13266 dwp_file
->dbfd
= dbfd
.release ();
13268 /* +1: section 0 is unused */
13269 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13270 dwp_file
->elf_sections
=
13271 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13272 dwp_file
->num_sections
, asection
*);
13274 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13277 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13279 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13281 /* The DWP file version is stored in the hash table. Oh well. */
13282 if (dwp_file
->cus
&& dwp_file
->tus
13283 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13285 /* Technically speaking, we should try to limp along, but this is
13286 pretty bizarre. We use pulongest here because that's the established
13287 portability solution (e.g, we cannot use %u for uint32_t). */
13288 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13289 " TU version %s [in DWP file %s]"),
13290 pulongest (dwp_file
->cus
->version
),
13291 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13295 dwp_file
->version
= dwp_file
->cus
->version
;
13296 else if (dwp_file
->tus
)
13297 dwp_file
->version
= dwp_file
->tus
->version
;
13299 dwp_file
->version
= 2;
13301 if (dwp_file
->version
== 2)
13302 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13305 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13306 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13308 if (dwarf_read_debug
)
13310 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13311 fprintf_unfiltered (gdb_stdlog
,
13312 " %s CUs, %s TUs\n",
13313 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13314 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13320 /* Wrapper around open_and_init_dwp_file, only open it once. */
13322 static struct dwp_file
*
13323 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13325 if (! dwarf2_per_objfile
->dwp_checked
)
13327 dwarf2_per_objfile
->dwp_file
13328 = open_and_init_dwp_file (dwarf2_per_objfile
);
13329 dwarf2_per_objfile
->dwp_checked
= 1;
13331 return dwarf2_per_objfile
->dwp_file
;
13334 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13335 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13336 or in the DWP file for the objfile, referenced by THIS_UNIT.
13337 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13338 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13340 This is called, for example, when wanting to read a variable with a
13341 complex location. Therefore we don't want to do file i/o for every call.
13342 Therefore we don't want to look for a DWO file on every call.
13343 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13344 then we check if we've already seen DWO_NAME, and only THEN do we check
13347 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13348 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13350 static struct dwo_unit
*
13351 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13352 const char *dwo_name
, const char *comp_dir
,
13353 ULONGEST signature
, int is_debug_types
)
13355 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13356 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13357 const char *kind
= is_debug_types
? "TU" : "CU";
13358 void **dwo_file_slot
;
13359 struct dwo_file
*dwo_file
;
13360 struct dwp_file
*dwp_file
;
13362 /* First see if there's a DWP file.
13363 If we have a DWP file but didn't find the DWO inside it, don't
13364 look for the original DWO file. It makes gdb behave differently
13365 depending on whether one is debugging in the build tree. */
13367 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13368 if (dwp_file
!= NULL
)
13370 const struct dwp_hash_table
*dwp_htab
=
13371 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13373 if (dwp_htab
!= NULL
)
13375 struct dwo_unit
*dwo_cutu
=
13376 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13377 signature
, is_debug_types
);
13379 if (dwo_cutu
!= NULL
)
13381 if (dwarf_read_debug
)
13383 fprintf_unfiltered (gdb_stdlog
,
13384 "Virtual DWO %s %s found: @%s\n",
13385 kind
, hex_string (signature
),
13386 host_address_to_string (dwo_cutu
));
13394 /* No DWP file, look for the DWO file. */
13396 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13397 dwo_name
, comp_dir
);
13398 if (*dwo_file_slot
== NULL
)
13400 /* Read in the file and build a table of the CUs/TUs it contains. */
13401 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13403 /* NOTE: This will be NULL if unable to open the file. */
13404 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13406 if (dwo_file
!= NULL
)
13408 struct dwo_unit
*dwo_cutu
= NULL
;
13410 if (is_debug_types
&& dwo_file
->tus
)
13412 struct dwo_unit find_dwo_cutu
;
13414 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13415 find_dwo_cutu
.signature
= signature
;
13417 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13419 else if (!is_debug_types
&& dwo_file
->cus
)
13421 struct dwo_unit find_dwo_cutu
;
13423 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13424 find_dwo_cutu
.signature
= signature
;
13425 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13429 if (dwo_cutu
!= NULL
)
13431 if (dwarf_read_debug
)
13433 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13434 kind
, dwo_name
, hex_string (signature
),
13435 host_address_to_string (dwo_cutu
));
13442 /* We didn't find it. This could mean a dwo_id mismatch, or
13443 someone deleted the DWO/DWP file, or the search path isn't set up
13444 correctly to find the file. */
13446 if (dwarf_read_debug
)
13448 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13449 kind
, dwo_name
, hex_string (signature
));
13452 /* This is a warning and not a complaint because it can be caused by
13453 pilot error (e.g., user accidentally deleting the DWO). */
13455 /* Print the name of the DWP file if we looked there, helps the user
13456 better diagnose the problem. */
13457 std::string dwp_text
;
13459 if (dwp_file
!= NULL
)
13460 dwp_text
= string_printf (" [in DWP file %s]",
13461 lbasename (dwp_file
->name
));
13463 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset 0x%x"
13464 " [in module %s]"),
13465 kind
, dwo_name
, hex_string (signature
),
13467 this_unit
->is_debug_types
? "TU" : "CU",
13468 to_underlying (this_unit
->sect_off
), objfile_name (objfile
));
13473 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13474 See lookup_dwo_cutu_unit for details. */
13476 static struct dwo_unit
*
13477 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13478 const char *dwo_name
, const char *comp_dir
,
13479 ULONGEST signature
)
13481 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13484 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13485 See lookup_dwo_cutu_unit for details. */
13487 static struct dwo_unit
*
13488 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13489 const char *dwo_name
, const char *comp_dir
)
13491 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13494 /* Traversal function for queue_and_load_all_dwo_tus. */
13497 queue_and_load_dwo_tu (void **slot
, void *info
)
13499 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13500 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13501 ULONGEST signature
= dwo_unit
->signature
;
13502 struct signatured_type
*sig_type
=
13503 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13505 if (sig_type
!= NULL
)
13507 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13509 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13510 a real dependency of PER_CU on SIG_TYPE. That is detected later
13511 while processing PER_CU. */
13512 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13513 load_full_type_unit (sig_cu
);
13514 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13520 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13521 The DWO may have the only definition of the type, though it may not be
13522 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13523 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13526 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13528 struct dwo_unit
*dwo_unit
;
13529 struct dwo_file
*dwo_file
;
13531 gdb_assert (!per_cu
->is_debug_types
);
13532 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13533 gdb_assert (per_cu
->cu
!= NULL
);
13535 dwo_unit
= per_cu
->cu
->dwo_unit
;
13536 gdb_assert (dwo_unit
!= NULL
);
13538 dwo_file
= dwo_unit
->dwo_file
;
13539 if (dwo_file
->tus
!= NULL
)
13540 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13543 /* Free all resources associated with DWO_FILE.
13544 Close the DWO file and munmap the sections.
13545 All memory should be on the objfile obstack. */
13548 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
13551 /* Note: dbfd is NULL for virtual DWO files. */
13552 gdb_bfd_unref (dwo_file
->dbfd
);
13554 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13557 /* Wrapper for free_dwo_file for use in cleanups. */
13560 free_dwo_file_cleanup (void *arg
)
13562 struct free_dwo_file_cleanup_data
*data
13563 = (struct free_dwo_file_cleanup_data
*) arg
;
13564 struct objfile
*objfile
= data
->dwarf2_per_objfile
->objfile
;
13566 free_dwo_file (data
->dwo_file
, objfile
);
13571 /* Traversal function for free_dwo_files. */
13574 free_dwo_file_from_slot (void **slot
, void *info
)
13576 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13577 struct objfile
*objfile
= (struct objfile
*) info
;
13579 free_dwo_file (dwo_file
, objfile
);
13584 /* Free all resources associated with DWO_FILES. */
13587 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13589 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13592 /* Read in various DIEs. */
13594 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13595 Inherit only the children of the DW_AT_abstract_origin DIE not being
13596 already referenced by DW_AT_abstract_origin from the children of the
13600 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13602 struct die_info
*child_die
;
13603 sect_offset
*offsetp
;
13604 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13605 struct die_info
*origin_die
;
13606 /* Iterator of the ORIGIN_DIE children. */
13607 struct die_info
*origin_child_die
;
13608 struct attribute
*attr
;
13609 struct dwarf2_cu
*origin_cu
;
13610 struct pending
**origin_previous_list_in_scope
;
13612 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13616 /* Note that following die references may follow to a die in a
13620 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13622 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13624 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13625 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13627 if (die
->tag
!= origin_die
->tag
13628 && !(die
->tag
== DW_TAG_inlined_subroutine
13629 && origin_die
->tag
== DW_TAG_subprogram
))
13630 complaint (&symfile_complaints
,
13631 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
13632 to_underlying (die
->sect_off
),
13633 to_underlying (origin_die
->sect_off
));
13635 std::vector
<sect_offset
> offsets
;
13637 for (child_die
= die
->child
;
13638 child_die
&& child_die
->tag
;
13639 child_die
= sibling_die (child_die
))
13641 struct die_info
*child_origin_die
;
13642 struct dwarf2_cu
*child_origin_cu
;
13644 /* We are trying to process concrete instance entries:
13645 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13646 it's not relevant to our analysis here. i.e. detecting DIEs that are
13647 present in the abstract instance but not referenced in the concrete
13649 if (child_die
->tag
== DW_TAG_call_site
13650 || child_die
->tag
== DW_TAG_GNU_call_site
)
13653 /* For each CHILD_DIE, find the corresponding child of
13654 ORIGIN_DIE. If there is more than one layer of
13655 DW_AT_abstract_origin, follow them all; there shouldn't be,
13656 but GCC versions at least through 4.4 generate this (GCC PR
13658 child_origin_die
= child_die
;
13659 child_origin_cu
= cu
;
13662 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13666 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13670 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13671 counterpart may exist. */
13672 if (child_origin_die
!= child_die
)
13674 if (child_die
->tag
!= child_origin_die
->tag
13675 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13676 && child_origin_die
->tag
== DW_TAG_subprogram
))
13677 complaint (&symfile_complaints
,
13678 _("Child DIE 0x%x and its abstract origin 0x%x have "
13680 to_underlying (child_die
->sect_off
),
13681 to_underlying (child_origin_die
->sect_off
));
13682 if (child_origin_die
->parent
!= origin_die
)
13683 complaint (&symfile_complaints
,
13684 _("Child DIE 0x%x and its abstract origin 0x%x have "
13685 "different parents"),
13686 to_underlying (child_die
->sect_off
),
13687 to_underlying (child_origin_die
->sect_off
));
13689 offsets
.push_back (child_origin_die
->sect_off
);
13692 std::sort (offsets
.begin (), offsets
.end ());
13693 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13694 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13695 if (offsetp
[-1] == *offsetp
)
13696 complaint (&symfile_complaints
,
13697 _("Multiple children of DIE 0x%x refer "
13698 "to DIE 0x%x as their abstract origin"),
13699 to_underlying (die
->sect_off
), to_underlying (*offsetp
));
13701 offsetp
= offsets
.data ();
13702 origin_child_die
= origin_die
->child
;
13703 while (origin_child_die
&& origin_child_die
->tag
)
13705 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13706 while (offsetp
< offsets_end
13707 && *offsetp
< origin_child_die
->sect_off
)
13709 if (offsetp
>= offsets_end
13710 || *offsetp
> origin_child_die
->sect_off
)
13712 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13713 Check whether we're already processing ORIGIN_CHILD_DIE.
13714 This can happen with mutually referenced abstract_origins.
13716 if (!origin_child_die
->in_process
)
13717 process_die (origin_child_die
, origin_cu
);
13719 origin_child_die
= sibling_die (origin_child_die
);
13721 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13725 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13727 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13728 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13729 struct context_stack
*newobj
;
13732 struct die_info
*child_die
;
13733 struct attribute
*attr
, *call_line
, *call_file
;
13735 CORE_ADDR baseaddr
;
13736 struct block
*block
;
13737 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13738 std::vector
<struct symbol
*> template_args
;
13739 struct template_symbol
*templ_func
= NULL
;
13743 /* If we do not have call site information, we can't show the
13744 caller of this inlined function. That's too confusing, so
13745 only use the scope for local variables. */
13746 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13747 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13748 if (call_line
== NULL
|| call_file
== NULL
)
13750 read_lexical_block_scope (die
, cu
);
13755 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13757 name
= dwarf2_name (die
, cu
);
13759 /* Ignore functions with missing or empty names. These are actually
13760 illegal according to the DWARF standard. */
13763 complaint (&symfile_complaints
,
13764 _("missing name for subprogram DIE at %d"),
13765 to_underlying (die
->sect_off
));
13769 /* Ignore functions with missing or invalid low and high pc attributes. */
13770 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13771 <= PC_BOUNDS_INVALID
)
13773 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13774 if (!attr
|| !DW_UNSND (attr
))
13775 complaint (&symfile_complaints
,
13776 _("cannot get low and high bounds "
13777 "for subprogram DIE at %d"),
13778 to_underlying (die
->sect_off
));
13782 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13783 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13785 /* If we have any template arguments, then we must allocate a
13786 different sort of symbol. */
13787 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13789 if (child_die
->tag
== DW_TAG_template_type_param
13790 || child_die
->tag
== DW_TAG_template_value_param
)
13792 templ_func
= allocate_template_symbol (objfile
);
13793 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13798 newobj
= push_context (0, lowpc
);
13799 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13800 (struct symbol
*) templ_func
);
13802 /* If there is a location expression for DW_AT_frame_base, record
13804 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13806 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13808 /* If there is a location for the static link, record it. */
13809 newobj
->static_link
= NULL
;
13810 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13813 newobj
->static_link
13814 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13815 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13818 cu
->list_in_scope
= &local_symbols
;
13820 if (die
->child
!= NULL
)
13822 child_die
= die
->child
;
13823 while (child_die
&& child_die
->tag
)
13825 if (child_die
->tag
== DW_TAG_template_type_param
13826 || child_die
->tag
== DW_TAG_template_value_param
)
13828 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13831 template_args
.push_back (arg
);
13834 process_die (child_die
, cu
);
13835 child_die
= sibling_die (child_die
);
13839 inherit_abstract_dies (die
, cu
);
13841 /* If we have a DW_AT_specification, we might need to import using
13842 directives from the context of the specification DIE. See the
13843 comment in determine_prefix. */
13844 if (cu
->language
== language_cplus
13845 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13847 struct dwarf2_cu
*spec_cu
= cu
;
13848 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13852 child_die
= spec_die
->child
;
13853 while (child_die
&& child_die
->tag
)
13855 if (child_die
->tag
== DW_TAG_imported_module
)
13856 process_die (child_die
, spec_cu
);
13857 child_die
= sibling_die (child_die
);
13860 /* In some cases, GCC generates specification DIEs that
13861 themselves contain DW_AT_specification attributes. */
13862 spec_die
= die_specification (spec_die
, &spec_cu
);
13866 newobj
= pop_context ();
13867 /* Make a block for the local symbols within. */
13868 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
13869 newobj
->static_link
, lowpc
, highpc
);
13871 /* For C++, set the block's scope. */
13872 if ((cu
->language
== language_cplus
13873 || cu
->language
== language_fortran
13874 || cu
->language
== language_d
13875 || cu
->language
== language_rust
)
13876 && cu
->processing_has_namespace_info
)
13877 block_set_scope (block
, determine_prefix (die
, cu
),
13878 &objfile
->objfile_obstack
);
13880 /* If we have address ranges, record them. */
13881 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13883 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
13885 /* Attach template arguments to function. */
13886 if (!template_args
.empty ())
13888 gdb_assert (templ_func
!= NULL
);
13890 templ_func
->n_template_arguments
= template_args
.size ();
13891 templ_func
->template_arguments
13892 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13893 templ_func
->n_template_arguments
);
13894 memcpy (templ_func
->template_arguments
,
13895 template_args
.data (),
13896 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13899 /* In C++, we can have functions nested inside functions (e.g., when
13900 a function declares a class that has methods). This means that
13901 when we finish processing a function scope, we may need to go
13902 back to building a containing block's symbol lists. */
13903 local_symbols
= newobj
->locals
;
13904 local_using_directives
= newobj
->local_using_directives
;
13906 /* If we've finished processing a top-level function, subsequent
13907 symbols go in the file symbol list. */
13908 if (outermost_context_p ())
13909 cu
->list_in_scope
= &file_symbols
;
13912 /* Process all the DIES contained within a lexical block scope. Start
13913 a new scope, process the dies, and then close the scope. */
13916 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13918 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13919 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13920 struct context_stack
*newobj
;
13921 CORE_ADDR lowpc
, highpc
;
13922 struct die_info
*child_die
;
13923 CORE_ADDR baseaddr
;
13925 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13927 /* Ignore blocks with missing or invalid low and high pc attributes. */
13928 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13929 as multiple lexical blocks? Handling children in a sane way would
13930 be nasty. Might be easier to properly extend generic blocks to
13931 describe ranges. */
13932 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13934 case PC_BOUNDS_NOT_PRESENT
:
13935 /* DW_TAG_lexical_block has no attributes, process its children as if
13936 there was no wrapping by that DW_TAG_lexical_block.
13937 GCC does no longer produces such DWARF since GCC r224161. */
13938 for (child_die
= die
->child
;
13939 child_die
!= NULL
&& child_die
->tag
;
13940 child_die
= sibling_die (child_die
))
13941 process_die (child_die
, cu
);
13943 case PC_BOUNDS_INVALID
:
13946 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13947 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13949 push_context (0, lowpc
);
13950 if (die
->child
!= NULL
)
13952 child_die
= die
->child
;
13953 while (child_die
&& child_die
->tag
)
13955 process_die (child_die
, cu
);
13956 child_die
= sibling_die (child_die
);
13959 inherit_abstract_dies (die
, cu
);
13960 newobj
= pop_context ();
13962 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
13964 struct block
*block
13965 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
13966 newobj
->start_addr
, highpc
);
13968 /* Note that recording ranges after traversing children, as we
13969 do here, means that recording a parent's ranges entails
13970 walking across all its children's ranges as they appear in
13971 the address map, which is quadratic behavior.
13973 It would be nicer to record the parent's ranges before
13974 traversing its children, simply overriding whatever you find
13975 there. But since we don't even decide whether to create a
13976 block until after we've traversed its children, that's hard
13978 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13980 local_symbols
= newobj
->locals
;
13981 local_using_directives
= newobj
->local_using_directives
;
13984 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13987 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13989 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13990 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13991 CORE_ADDR pc
, baseaddr
;
13992 struct attribute
*attr
;
13993 struct call_site
*call_site
, call_site_local
;
13996 struct die_info
*child_die
;
13998 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14000 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
14003 /* This was a pre-DWARF-5 GNU extension alias
14004 for DW_AT_call_return_pc. */
14005 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14009 complaint (&symfile_complaints
,
14010 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
14011 "DIE 0x%x [in module %s]"),
14012 to_underlying (die
->sect_off
), objfile_name (objfile
));
14015 pc
= attr_value_as_address (attr
) + baseaddr
;
14016 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
14018 if (cu
->call_site_htab
== NULL
)
14019 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
14020 NULL
, &objfile
->objfile_obstack
,
14021 hashtab_obstack_allocate
, NULL
);
14022 call_site_local
.pc
= pc
;
14023 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
14026 complaint (&symfile_complaints
,
14027 _("Duplicate PC %s for DW_TAG_call_site "
14028 "DIE 0x%x [in module %s]"),
14029 paddress (gdbarch
, pc
), to_underlying (die
->sect_off
),
14030 objfile_name (objfile
));
14034 /* Count parameters at the caller. */
14037 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14038 child_die
= sibling_die (child_die
))
14040 if (child_die
->tag
!= DW_TAG_call_site_parameter
14041 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14043 complaint (&symfile_complaints
,
14044 _("Tag %d is not DW_TAG_call_site_parameter in "
14045 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
14046 child_die
->tag
, to_underlying (child_die
->sect_off
),
14047 objfile_name (objfile
));
14055 = ((struct call_site
*)
14056 obstack_alloc (&objfile
->objfile_obstack
,
14057 sizeof (*call_site
)
14058 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14060 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14061 call_site
->pc
= pc
;
14063 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14064 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14066 struct die_info
*func_die
;
14068 /* Skip also over DW_TAG_inlined_subroutine. */
14069 for (func_die
= die
->parent
;
14070 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14071 && func_die
->tag
!= DW_TAG_subroutine_type
;
14072 func_die
= func_die
->parent
);
14074 /* DW_AT_call_all_calls is a superset
14075 of DW_AT_call_all_tail_calls. */
14077 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14078 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14079 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14080 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14082 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14083 not complete. But keep CALL_SITE for look ups via call_site_htab,
14084 both the initial caller containing the real return address PC and
14085 the final callee containing the current PC of a chain of tail
14086 calls do not need to have the tail call list complete. But any
14087 function candidate for a virtual tail call frame searched via
14088 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14089 determined unambiguously. */
14093 struct type
*func_type
= NULL
;
14096 func_type
= get_die_type (func_die
, cu
);
14097 if (func_type
!= NULL
)
14099 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14101 /* Enlist this call site to the function. */
14102 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14103 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14106 complaint (&symfile_complaints
,
14107 _("Cannot find function owning DW_TAG_call_site "
14108 "DIE 0x%x [in module %s]"),
14109 to_underlying (die
->sect_off
), objfile_name (objfile
));
14113 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14115 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14117 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14120 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14121 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14123 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14124 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14125 /* Keep NULL DWARF_BLOCK. */;
14126 else if (attr_form_is_block (attr
))
14128 struct dwarf2_locexpr_baton
*dlbaton
;
14130 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14131 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14132 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14133 dlbaton
->per_cu
= cu
->per_cu
;
14135 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14137 else if (attr_form_is_ref (attr
))
14139 struct dwarf2_cu
*target_cu
= cu
;
14140 struct die_info
*target_die
;
14142 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14143 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14144 if (die_is_declaration (target_die
, target_cu
))
14146 const char *target_physname
;
14148 /* Prefer the mangled name; otherwise compute the demangled one. */
14149 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14150 if (target_physname
== NULL
)
14151 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14152 if (target_physname
== NULL
)
14153 complaint (&symfile_complaints
,
14154 _("DW_AT_call_target target DIE has invalid "
14155 "physname, for referencing DIE 0x%x [in module %s]"),
14156 to_underlying (die
->sect_off
), objfile_name (objfile
));
14158 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14164 /* DW_AT_entry_pc should be preferred. */
14165 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14166 <= PC_BOUNDS_INVALID
)
14167 complaint (&symfile_complaints
,
14168 _("DW_AT_call_target target DIE has invalid "
14169 "low pc, for referencing DIE 0x%x [in module %s]"),
14170 to_underlying (die
->sect_off
), objfile_name (objfile
));
14173 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14174 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14179 complaint (&symfile_complaints
,
14180 _("DW_TAG_call_site DW_AT_call_target is neither "
14181 "block nor reference, for DIE 0x%x [in module %s]"),
14182 to_underlying (die
->sect_off
), objfile_name (objfile
));
14184 call_site
->per_cu
= cu
->per_cu
;
14186 for (child_die
= die
->child
;
14187 child_die
&& child_die
->tag
;
14188 child_die
= sibling_die (child_die
))
14190 struct call_site_parameter
*parameter
;
14191 struct attribute
*loc
, *origin
;
14193 if (child_die
->tag
!= DW_TAG_call_site_parameter
14194 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14196 /* Already printed the complaint above. */
14200 gdb_assert (call_site
->parameter_count
< nparams
);
14201 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14203 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14204 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14205 register is contained in DW_AT_call_value. */
14207 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14208 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14209 if (origin
== NULL
)
14211 /* This was a pre-DWARF-5 GNU extension alias
14212 for DW_AT_call_parameter. */
14213 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14215 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14217 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14219 sect_offset sect_off
14220 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14221 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14223 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14224 binding can be done only inside one CU. Such referenced DIE
14225 therefore cannot be even moved to DW_TAG_partial_unit. */
14226 complaint (&symfile_complaints
,
14227 _("DW_AT_call_parameter offset is not in CU for "
14228 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
14229 to_underlying (child_die
->sect_off
),
14230 objfile_name (objfile
));
14233 parameter
->u
.param_cu_off
14234 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14236 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14238 complaint (&symfile_complaints
,
14239 _("No DW_FORM_block* DW_AT_location for "
14240 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
14241 to_underlying (child_die
->sect_off
), objfile_name (objfile
));
14246 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14247 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14248 if (parameter
->u
.dwarf_reg
!= -1)
14249 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14250 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14251 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14252 ¶meter
->u
.fb_offset
))
14253 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14256 complaint (&symfile_complaints
,
14257 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14258 "for DW_FORM_block* DW_AT_location is supported for "
14259 "DW_TAG_call_site child DIE 0x%x "
14261 to_underlying (child_die
->sect_off
),
14262 objfile_name (objfile
));
14267 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14269 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14270 if (!attr_form_is_block (attr
))
14272 complaint (&symfile_complaints
,
14273 _("No DW_FORM_block* DW_AT_call_value for "
14274 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
14275 to_underlying (child_die
->sect_off
),
14276 objfile_name (objfile
));
14279 parameter
->value
= DW_BLOCK (attr
)->data
;
14280 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14282 /* Parameters are not pre-cleared by memset above. */
14283 parameter
->data_value
= NULL
;
14284 parameter
->data_value_size
= 0;
14285 call_site
->parameter_count
++;
14287 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14289 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14292 if (!attr_form_is_block (attr
))
14293 complaint (&symfile_complaints
,
14294 _("No DW_FORM_block* DW_AT_call_data_value for "
14295 "DW_TAG_call_site child DIE 0x%x [in module %s]"),
14296 to_underlying (child_die
->sect_off
),
14297 objfile_name (objfile
));
14300 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14301 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14307 /* Helper function for read_variable. If DIE represents a virtual
14308 table, then return the type of the concrete object that is
14309 associated with the virtual table. Otherwise, return NULL. */
14311 static struct type
*
14312 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14314 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14318 /* Find the type DIE. */
14319 struct die_info
*type_die
= NULL
;
14320 struct dwarf2_cu
*type_cu
= cu
;
14322 if (attr_form_is_ref (attr
))
14323 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14324 if (type_die
== NULL
)
14327 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14329 return die_containing_type (type_die
, type_cu
);
14332 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14335 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14337 struct rust_vtable_symbol
*storage
= NULL
;
14339 if (cu
->language
== language_rust
)
14341 struct type
*containing_type
= rust_containing_type (die
, cu
);
14343 if (containing_type
!= NULL
)
14345 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14347 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14348 struct rust_vtable_symbol
);
14349 initialize_objfile_symbol (storage
);
14350 storage
->concrete_type
= containing_type
;
14351 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14355 new_symbol (die
, NULL
, cu
, storage
);
14358 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14359 reading .debug_rnglists.
14360 Callback's type should be:
14361 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14362 Return true if the attributes are present and valid, otherwise,
14365 template <typename Callback
>
14367 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14368 Callback
&&callback
)
14370 struct dwarf2_per_objfile
*dwarf2_per_objfile
14371 = cu
->per_cu
->dwarf2_per_objfile
;
14372 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14373 bfd
*obfd
= objfile
->obfd
;
14374 /* Base address selection entry. */
14377 const gdb_byte
*buffer
;
14378 CORE_ADDR baseaddr
;
14379 bool overflow
= false;
14381 found_base
= cu
->base_known
;
14382 base
= cu
->base_address
;
14384 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14385 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14387 complaint (&symfile_complaints
,
14388 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14392 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14394 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14398 /* Initialize it due to a false compiler warning. */
14399 CORE_ADDR range_beginning
= 0, range_end
= 0;
14400 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14401 + dwarf2_per_objfile
->rnglists
.size
);
14402 unsigned int bytes_read
;
14404 if (buffer
== buf_end
)
14409 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14412 case DW_RLE_end_of_list
:
14414 case DW_RLE_base_address
:
14415 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14420 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14422 buffer
+= bytes_read
;
14424 case DW_RLE_start_length
:
14425 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14430 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14431 buffer
+= bytes_read
;
14432 range_end
= (range_beginning
14433 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14434 buffer
+= bytes_read
;
14435 if (buffer
> buf_end
)
14441 case DW_RLE_offset_pair
:
14442 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14443 buffer
+= bytes_read
;
14444 if (buffer
> buf_end
)
14449 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14450 buffer
+= bytes_read
;
14451 if (buffer
> buf_end
)
14457 case DW_RLE_start_end
:
14458 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14463 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14464 buffer
+= bytes_read
;
14465 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14466 buffer
+= bytes_read
;
14469 complaint (&symfile_complaints
,
14470 _("Invalid .debug_rnglists data (no base address)"));
14473 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14475 if (rlet
== DW_RLE_base_address
)
14480 /* We have no valid base address for the ranges
14482 complaint (&symfile_complaints
,
14483 _("Invalid .debug_rnglists data (no base address)"));
14487 if (range_beginning
> range_end
)
14489 /* Inverted range entries are invalid. */
14490 complaint (&symfile_complaints
,
14491 _("Invalid .debug_rnglists data (inverted range)"));
14495 /* Empty range entries have no effect. */
14496 if (range_beginning
== range_end
)
14499 range_beginning
+= base
;
14502 /* A not-uncommon case of bad debug info.
14503 Don't pollute the addrmap with bad data. */
14504 if (range_beginning
+ baseaddr
== 0
14505 && !dwarf2_per_objfile
->has_section_at_zero
)
14507 complaint (&symfile_complaints
,
14508 _(".debug_rnglists entry has start address of zero"
14509 " [in module %s]"), objfile_name (objfile
));
14513 callback (range_beginning
, range_end
);
14518 complaint (&symfile_complaints
,
14519 _("Offset %d is not terminated "
14520 "for DW_AT_ranges attribute"),
14528 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14529 Callback's type should be:
14530 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14531 Return 1 if the attributes are present and valid, otherwise, return 0. */
14533 template <typename Callback
>
14535 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14536 Callback
&&callback
)
14538 struct dwarf2_per_objfile
*dwarf2_per_objfile
14539 = cu
->per_cu
->dwarf2_per_objfile
;
14540 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14541 struct comp_unit_head
*cu_header
= &cu
->header
;
14542 bfd
*obfd
= objfile
->obfd
;
14543 unsigned int addr_size
= cu_header
->addr_size
;
14544 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14545 /* Base address selection entry. */
14548 unsigned int dummy
;
14549 const gdb_byte
*buffer
;
14550 CORE_ADDR baseaddr
;
14552 if (cu_header
->version
>= 5)
14553 return dwarf2_rnglists_process (offset
, cu
, callback
);
14555 found_base
= cu
->base_known
;
14556 base
= cu
->base_address
;
14558 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14559 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14561 complaint (&symfile_complaints
,
14562 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14566 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14568 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14572 CORE_ADDR range_beginning
, range_end
;
14574 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14575 buffer
+= addr_size
;
14576 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14577 buffer
+= addr_size
;
14578 offset
+= 2 * addr_size
;
14580 /* An end of list marker is a pair of zero addresses. */
14581 if (range_beginning
== 0 && range_end
== 0)
14582 /* Found the end of list entry. */
14585 /* Each base address selection entry is a pair of 2 values.
14586 The first is the largest possible address, the second is
14587 the base address. Check for a base address here. */
14588 if ((range_beginning
& mask
) == mask
)
14590 /* If we found the largest possible address, then we already
14591 have the base address in range_end. */
14599 /* We have no valid base address for the ranges
14601 complaint (&symfile_complaints
,
14602 _("Invalid .debug_ranges data (no base address)"));
14606 if (range_beginning
> range_end
)
14608 /* Inverted range entries are invalid. */
14609 complaint (&symfile_complaints
,
14610 _("Invalid .debug_ranges data (inverted range)"));
14614 /* Empty range entries have no effect. */
14615 if (range_beginning
== range_end
)
14618 range_beginning
+= base
;
14621 /* A not-uncommon case of bad debug info.
14622 Don't pollute the addrmap with bad data. */
14623 if (range_beginning
+ baseaddr
== 0
14624 && !dwarf2_per_objfile
->has_section_at_zero
)
14626 complaint (&symfile_complaints
,
14627 _(".debug_ranges entry has start address of zero"
14628 " [in module %s]"), objfile_name (objfile
));
14632 callback (range_beginning
, range_end
);
14638 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14639 Return 1 if the attributes are present and valid, otherwise, return 0.
14640 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14643 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14644 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14645 struct partial_symtab
*ranges_pst
)
14647 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14648 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14649 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14650 SECT_OFF_TEXT (objfile
));
14653 CORE_ADDR high
= 0;
14656 retval
= dwarf2_ranges_process (offset
, cu
,
14657 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14659 if (ranges_pst
!= NULL
)
14664 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14665 range_beginning
+ baseaddr
);
14666 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14667 range_end
+ baseaddr
);
14668 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
14672 /* FIXME: This is recording everything as a low-high
14673 segment of consecutive addresses. We should have a
14674 data structure for discontiguous block ranges
14678 low
= range_beginning
;
14684 if (range_beginning
< low
)
14685 low
= range_beginning
;
14686 if (range_end
> high
)
14694 /* If the first entry is an end-of-list marker, the range
14695 describes an empty scope, i.e. no instructions. */
14701 *high_return
= high
;
14705 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14706 definition for the return value. *LOWPC and *HIGHPC are set iff
14707 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14709 static enum pc_bounds_kind
14710 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14711 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14712 struct partial_symtab
*pst
)
14714 struct dwarf2_per_objfile
*dwarf2_per_objfile
14715 = cu
->per_cu
->dwarf2_per_objfile
;
14716 struct attribute
*attr
;
14717 struct attribute
*attr_high
;
14719 CORE_ADDR high
= 0;
14720 enum pc_bounds_kind ret
;
14722 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14725 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14728 low
= attr_value_as_address (attr
);
14729 high
= attr_value_as_address (attr_high
);
14730 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14734 /* Found high w/o low attribute. */
14735 return PC_BOUNDS_INVALID
;
14737 /* Found consecutive range of addresses. */
14738 ret
= PC_BOUNDS_HIGH_LOW
;
14742 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14745 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14746 We take advantage of the fact that DW_AT_ranges does not appear
14747 in DW_TAG_compile_unit of DWO files. */
14748 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14749 unsigned int ranges_offset
= (DW_UNSND (attr
)
14750 + (need_ranges_base
14754 /* Value of the DW_AT_ranges attribute is the offset in the
14755 .debug_ranges section. */
14756 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14757 return PC_BOUNDS_INVALID
;
14758 /* Found discontinuous range of addresses. */
14759 ret
= PC_BOUNDS_RANGES
;
14762 return PC_BOUNDS_NOT_PRESENT
;
14765 /* read_partial_die has also the strict LOW < HIGH requirement. */
14767 return PC_BOUNDS_INVALID
;
14769 /* When using the GNU linker, .gnu.linkonce. sections are used to
14770 eliminate duplicate copies of functions and vtables and such.
14771 The linker will arbitrarily choose one and discard the others.
14772 The AT_*_pc values for such functions refer to local labels in
14773 these sections. If the section from that file was discarded, the
14774 labels are not in the output, so the relocs get a value of 0.
14775 If this is a discarded function, mark the pc bounds as invalid,
14776 so that GDB will ignore it. */
14777 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14778 return PC_BOUNDS_INVALID
;
14786 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14787 its low and high PC addresses. Do nothing if these addresses could not
14788 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14789 and HIGHPC to the high address if greater than HIGHPC. */
14792 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14793 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14794 struct dwarf2_cu
*cu
)
14796 CORE_ADDR low
, high
;
14797 struct die_info
*child
= die
->child
;
14799 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14801 *lowpc
= std::min (*lowpc
, low
);
14802 *highpc
= std::max (*highpc
, high
);
14805 /* If the language does not allow nested subprograms (either inside
14806 subprograms or lexical blocks), we're done. */
14807 if (cu
->language
!= language_ada
)
14810 /* Check all the children of the given DIE. If it contains nested
14811 subprograms, then check their pc bounds. Likewise, we need to
14812 check lexical blocks as well, as they may also contain subprogram
14814 while (child
&& child
->tag
)
14816 if (child
->tag
== DW_TAG_subprogram
14817 || child
->tag
== DW_TAG_lexical_block
)
14818 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14819 child
= sibling_die (child
);
14823 /* Get the low and high pc's represented by the scope DIE, and store
14824 them in *LOWPC and *HIGHPC. If the correct values can't be
14825 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14828 get_scope_pc_bounds (struct die_info
*die
,
14829 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14830 struct dwarf2_cu
*cu
)
14832 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14833 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14834 CORE_ADDR current_low
, current_high
;
14836 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14837 >= PC_BOUNDS_RANGES
)
14839 best_low
= current_low
;
14840 best_high
= current_high
;
14844 struct die_info
*child
= die
->child
;
14846 while (child
&& child
->tag
)
14848 switch (child
->tag
) {
14849 case DW_TAG_subprogram
:
14850 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14852 case DW_TAG_namespace
:
14853 case DW_TAG_module
:
14854 /* FIXME: carlton/2004-01-16: Should we do this for
14855 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14856 that current GCC's always emit the DIEs corresponding
14857 to definitions of methods of classes as children of a
14858 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14859 the DIEs giving the declarations, which could be
14860 anywhere). But I don't see any reason why the
14861 standards says that they have to be there. */
14862 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14864 if (current_low
!= ((CORE_ADDR
) -1))
14866 best_low
= std::min (best_low
, current_low
);
14867 best_high
= std::max (best_high
, current_high
);
14875 child
= sibling_die (child
);
14880 *highpc
= best_high
;
14883 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14887 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14888 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14890 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14891 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14892 struct attribute
*attr
;
14893 struct attribute
*attr_high
;
14895 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14898 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14901 CORE_ADDR low
= attr_value_as_address (attr
);
14902 CORE_ADDR high
= attr_value_as_address (attr_high
);
14904 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14907 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14908 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14909 record_block_range (block
, low
, high
- 1);
14913 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14916 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14917 We take advantage of the fact that DW_AT_ranges does not appear
14918 in DW_TAG_compile_unit of DWO files. */
14919 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14921 /* The value of the DW_AT_ranges attribute is the offset of the
14922 address range list in the .debug_ranges section. */
14923 unsigned long offset
= (DW_UNSND (attr
)
14924 + (need_ranges_base
? cu
->ranges_base
: 0));
14925 const gdb_byte
*buffer
;
14927 /* For some target architectures, but not others, the
14928 read_address function sign-extends the addresses it returns.
14929 To recognize base address selection entries, we need a
14931 unsigned int addr_size
= cu
->header
.addr_size
;
14932 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14934 /* The base address, to which the next pair is relative. Note
14935 that this 'base' is a DWARF concept: most entries in a range
14936 list are relative, to reduce the number of relocs against the
14937 debugging information. This is separate from this function's
14938 'baseaddr' argument, which GDB uses to relocate debugging
14939 information from a shared library based on the address at
14940 which the library was loaded. */
14941 CORE_ADDR base
= cu
->base_address
;
14942 int base_known
= cu
->base_known
;
14944 dwarf2_ranges_process (offset
, cu
,
14945 [&] (CORE_ADDR start
, CORE_ADDR end
)
14949 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14950 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14951 record_block_range (block
, start
, end
- 1);
14956 /* Check whether the producer field indicates either of GCC < 4.6, or the
14957 Intel C/C++ compiler, and cache the result in CU. */
14960 check_producer (struct dwarf2_cu
*cu
)
14964 if (cu
->producer
== NULL
)
14966 /* For unknown compilers expect their behavior is DWARF version
14969 GCC started to support .debug_types sections by -gdwarf-4 since
14970 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14971 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14972 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14973 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14975 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14977 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14978 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14980 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14981 cu
->producer_is_icc_lt_14
= major
< 14;
14984 /* For other non-GCC compilers, expect their behavior is DWARF version
14988 cu
->checked_producer
= 1;
14991 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14992 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14993 during 4.6.0 experimental. */
14996 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14998 if (!cu
->checked_producer
)
14999 check_producer (cu
);
15001 return cu
->producer_is_gxx_lt_4_6
;
15004 /* Return the default accessibility type if it is not overriden by
15005 DW_AT_accessibility. */
15007 static enum dwarf_access_attribute
15008 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
15010 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15012 /* The default DWARF 2 accessibility for members is public, the default
15013 accessibility for inheritance is private. */
15015 if (die
->tag
!= DW_TAG_inheritance
)
15016 return DW_ACCESS_public
;
15018 return DW_ACCESS_private
;
15022 /* DWARF 3+ defines the default accessibility a different way. The same
15023 rules apply now for DW_TAG_inheritance as for the members and it only
15024 depends on the container kind. */
15026 if (die
->parent
->tag
== DW_TAG_class_type
)
15027 return DW_ACCESS_private
;
15029 return DW_ACCESS_public
;
15033 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15034 offset. If the attribute was not found return 0, otherwise return
15035 1. If it was found but could not properly be handled, set *OFFSET
15039 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15042 struct attribute
*attr
;
15044 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15049 /* Note that we do not check for a section offset first here.
15050 This is because DW_AT_data_member_location is new in DWARF 4,
15051 so if we see it, we can assume that a constant form is really
15052 a constant and not a section offset. */
15053 if (attr_form_is_constant (attr
))
15054 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15055 else if (attr_form_is_section_offset (attr
))
15056 dwarf2_complex_location_expr_complaint ();
15057 else if (attr_form_is_block (attr
))
15058 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15060 dwarf2_complex_location_expr_complaint ();
15068 /* Add an aggregate field to the field list. */
15071 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15072 struct dwarf2_cu
*cu
)
15074 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15075 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15076 struct nextfield
*new_field
;
15077 struct attribute
*attr
;
15079 const char *fieldname
= "";
15081 /* Allocate a new field list entry and link it in. */
15082 new_field
= XNEW (struct nextfield
);
15083 make_cleanup (xfree
, new_field
);
15084 memset (new_field
, 0, sizeof (struct nextfield
));
15086 if (die
->tag
== DW_TAG_inheritance
)
15088 new_field
->next
= fip
->baseclasses
;
15089 fip
->baseclasses
= new_field
;
15093 new_field
->next
= fip
->fields
;
15094 fip
->fields
= new_field
;
15098 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15100 new_field
->accessibility
= DW_UNSND (attr
);
15102 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15103 if (new_field
->accessibility
!= DW_ACCESS_public
)
15104 fip
->non_public_fields
= 1;
15106 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15108 new_field
->virtuality
= DW_UNSND (attr
);
15110 new_field
->virtuality
= DW_VIRTUALITY_none
;
15112 fp
= &new_field
->field
;
15114 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15118 /* Data member other than a C++ static data member. */
15120 /* Get type of field. */
15121 fp
->type
= die_type (die
, cu
);
15123 SET_FIELD_BITPOS (*fp
, 0);
15125 /* Get bit size of field (zero if none). */
15126 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15129 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15133 FIELD_BITSIZE (*fp
) = 0;
15136 /* Get bit offset of field. */
15137 if (handle_data_member_location (die
, cu
, &offset
))
15138 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15139 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15142 if (gdbarch_bits_big_endian (gdbarch
))
15144 /* For big endian bits, the DW_AT_bit_offset gives the
15145 additional bit offset from the MSB of the containing
15146 anonymous object to the MSB of the field. We don't
15147 have to do anything special since we don't need to
15148 know the size of the anonymous object. */
15149 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15153 /* For little endian bits, compute the bit offset to the
15154 MSB of the anonymous object, subtract off the number of
15155 bits from the MSB of the field to the MSB of the
15156 object, and then subtract off the number of bits of
15157 the field itself. The result is the bit offset of
15158 the LSB of the field. */
15159 int anonymous_size
;
15160 int bit_offset
= DW_UNSND (attr
);
15162 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15165 /* The size of the anonymous object containing
15166 the bit field is explicit, so use the
15167 indicated size (in bytes). */
15168 anonymous_size
= DW_UNSND (attr
);
15172 /* The size of the anonymous object containing
15173 the bit field must be inferred from the type
15174 attribute of the data member containing the
15176 anonymous_size
= TYPE_LENGTH (fp
->type
);
15178 SET_FIELD_BITPOS (*fp
,
15179 (FIELD_BITPOS (*fp
)
15180 + anonymous_size
* bits_per_byte
15181 - bit_offset
- FIELD_BITSIZE (*fp
)));
15184 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15186 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15187 + dwarf2_get_attr_constant_value (attr
, 0)));
15189 /* Get name of field. */
15190 fieldname
= dwarf2_name (die
, cu
);
15191 if (fieldname
== NULL
)
15194 /* The name is already allocated along with this objfile, so we don't
15195 need to duplicate it for the type. */
15196 fp
->name
= fieldname
;
15198 /* Change accessibility for artificial fields (e.g. virtual table
15199 pointer or virtual base class pointer) to private. */
15200 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15202 FIELD_ARTIFICIAL (*fp
) = 1;
15203 new_field
->accessibility
= DW_ACCESS_private
;
15204 fip
->non_public_fields
= 1;
15207 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15209 /* C++ static member. */
15211 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15212 is a declaration, but all versions of G++ as of this writing
15213 (so through at least 3.2.1) incorrectly generate
15214 DW_TAG_variable tags. */
15216 const char *physname
;
15218 /* Get name of field. */
15219 fieldname
= dwarf2_name (die
, cu
);
15220 if (fieldname
== NULL
)
15223 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15225 /* Only create a symbol if this is an external value.
15226 new_symbol checks this and puts the value in the global symbol
15227 table, which we want. If it is not external, new_symbol
15228 will try to put the value in cu->list_in_scope which is wrong. */
15229 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15231 /* A static const member, not much different than an enum as far as
15232 we're concerned, except that we can support more types. */
15233 new_symbol (die
, NULL
, cu
);
15236 /* Get physical name. */
15237 physname
= dwarf2_physname (fieldname
, die
, cu
);
15239 /* The name is already allocated along with this objfile, so we don't
15240 need to duplicate it for the type. */
15241 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15242 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15243 FIELD_NAME (*fp
) = fieldname
;
15245 else if (die
->tag
== DW_TAG_inheritance
)
15249 /* C++ base class field. */
15250 if (handle_data_member_location (die
, cu
, &offset
))
15251 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15252 FIELD_BITSIZE (*fp
) = 0;
15253 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15254 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15255 fip
->nbaseclasses
++;
15259 /* Can the type given by DIE define another type? */
15262 type_can_define_types (const struct die_info
*die
)
15266 case DW_TAG_typedef
:
15267 case DW_TAG_class_type
:
15268 case DW_TAG_structure_type
:
15269 case DW_TAG_union_type
:
15270 case DW_TAG_enumeration_type
:
15278 /* Add a type definition defined in the scope of the FIP's class. */
15281 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15282 struct dwarf2_cu
*cu
)
15284 struct decl_field_list
*new_field
;
15285 struct decl_field
*fp
;
15287 /* Allocate a new field list entry and link it in. */
15288 new_field
= XCNEW (struct decl_field_list
);
15289 make_cleanup (xfree
, new_field
);
15291 gdb_assert (type_can_define_types (die
));
15293 fp
= &new_field
->field
;
15295 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15296 fp
->name
= dwarf2_name (die
, cu
);
15297 fp
->type
= read_type_die (die
, cu
);
15299 /* Save accessibility. */
15300 enum dwarf_access_attribute accessibility
;
15301 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15303 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15305 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15306 switch (accessibility
)
15308 case DW_ACCESS_public
:
15309 /* The assumed value if neither private nor protected. */
15311 case DW_ACCESS_private
:
15312 fp
->is_private
= 1;
15314 case DW_ACCESS_protected
:
15315 fp
->is_protected
= 1;
15318 complaint (&symfile_complaints
,
15319 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15322 if (die
->tag
== DW_TAG_typedef
)
15324 new_field
->next
= fip
->typedef_field_list
;
15325 fip
->typedef_field_list
= new_field
;
15326 fip
->typedef_field_list_count
++;
15330 new_field
->next
= fip
->nested_types_list
;
15331 fip
->nested_types_list
= new_field
;
15332 fip
->nested_types_list_count
++;
15336 /* Create the vector of fields, and attach it to the type. */
15339 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15340 struct dwarf2_cu
*cu
)
15342 int nfields
= fip
->nfields
;
15344 /* Record the field count, allocate space for the array of fields,
15345 and create blank accessibility bitfields if necessary. */
15346 TYPE_NFIELDS (type
) = nfields
;
15347 TYPE_FIELDS (type
) = (struct field
*)
15348 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
15349 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
15351 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15353 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15355 TYPE_FIELD_PRIVATE_BITS (type
) =
15356 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15357 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15359 TYPE_FIELD_PROTECTED_BITS (type
) =
15360 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15361 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15363 TYPE_FIELD_IGNORE_BITS (type
) =
15364 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15365 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15368 /* If the type has baseclasses, allocate and clear a bit vector for
15369 TYPE_FIELD_VIRTUAL_BITS. */
15370 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
15372 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
15373 unsigned char *pointer
;
15375 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15376 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15377 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15378 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
15379 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
15382 /* Copy the saved-up fields into the field vector. Start from the head of
15383 the list, adding to the tail of the field array, so that they end up in
15384 the same order in the array in which they were added to the list. */
15385 while (nfields
-- > 0)
15387 struct nextfield
*fieldp
;
15391 fieldp
= fip
->fields
;
15392 fip
->fields
= fieldp
->next
;
15396 fieldp
= fip
->baseclasses
;
15397 fip
->baseclasses
= fieldp
->next
;
15400 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
15401 switch (fieldp
->accessibility
)
15403 case DW_ACCESS_private
:
15404 if (cu
->language
!= language_ada
)
15405 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
15408 case DW_ACCESS_protected
:
15409 if (cu
->language
!= language_ada
)
15410 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
15413 case DW_ACCESS_public
:
15417 /* Unknown accessibility. Complain and treat it as public. */
15419 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15420 fieldp
->accessibility
);
15424 if (nfields
< fip
->nbaseclasses
)
15426 switch (fieldp
->virtuality
)
15428 case DW_VIRTUALITY_virtual
:
15429 case DW_VIRTUALITY_pure_virtual
:
15430 if (cu
->language
== language_ada
)
15431 error (_("unexpected virtuality in component of Ada type"));
15432 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
15439 /* Return true if this member function is a constructor, false
15443 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15445 const char *fieldname
;
15446 const char *type_name
;
15449 if (die
->parent
== NULL
)
15452 if (die
->parent
->tag
!= DW_TAG_structure_type
15453 && die
->parent
->tag
!= DW_TAG_union_type
15454 && die
->parent
->tag
!= DW_TAG_class_type
)
15457 fieldname
= dwarf2_name (die
, cu
);
15458 type_name
= dwarf2_name (die
->parent
, cu
);
15459 if (fieldname
== NULL
|| type_name
== NULL
)
15462 len
= strlen (fieldname
);
15463 return (strncmp (fieldname
, type_name
, len
) == 0
15464 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15467 /* Add a member function to the proper fieldlist. */
15470 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15471 struct type
*type
, struct dwarf2_cu
*cu
)
15473 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15474 struct attribute
*attr
;
15475 struct fnfieldlist
*flp
;
15477 struct fn_field
*fnp
;
15478 const char *fieldname
;
15479 struct nextfnfield
*new_fnfield
;
15480 struct type
*this_type
;
15481 enum dwarf_access_attribute accessibility
;
15483 if (cu
->language
== language_ada
)
15484 error (_("unexpected member function in Ada type"));
15486 /* Get name of member function. */
15487 fieldname
= dwarf2_name (die
, cu
);
15488 if (fieldname
== NULL
)
15491 /* Look up member function name in fieldlist. */
15492 for (i
= 0; i
< fip
->nfnfields
; i
++)
15494 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15498 /* Create new list element if necessary. */
15499 if (i
< fip
->nfnfields
)
15500 flp
= &fip
->fnfieldlists
[i
];
15503 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
15505 fip
->fnfieldlists
= (struct fnfieldlist
*)
15506 xrealloc (fip
->fnfieldlists
,
15507 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
15508 * sizeof (struct fnfieldlist
));
15509 if (fip
->nfnfields
== 0)
15510 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
15512 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
15513 flp
->name
= fieldname
;
15516 i
= fip
->nfnfields
++;
15519 /* Create a new member function field and chain it to the field list
15521 new_fnfield
= XNEW (struct nextfnfield
);
15522 make_cleanup (xfree
, new_fnfield
);
15523 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
15524 new_fnfield
->next
= flp
->head
;
15525 flp
->head
= new_fnfield
;
15528 /* Fill in the member function field info. */
15529 fnp
= &new_fnfield
->fnfield
;
15531 /* Delay processing of the physname until later. */
15532 if (cu
->language
== language_cplus
)
15534 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
15539 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15540 fnp
->physname
= physname
? physname
: "";
15543 fnp
->type
= alloc_type (objfile
);
15544 this_type
= read_type_die (die
, cu
);
15545 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15547 int nparams
= TYPE_NFIELDS (this_type
);
15549 /* TYPE is the domain of this method, and THIS_TYPE is the type
15550 of the method itself (TYPE_CODE_METHOD). */
15551 smash_to_method_type (fnp
->type
, type
,
15552 TYPE_TARGET_TYPE (this_type
),
15553 TYPE_FIELDS (this_type
),
15554 TYPE_NFIELDS (this_type
),
15555 TYPE_VARARGS (this_type
));
15557 /* Handle static member functions.
15558 Dwarf2 has no clean way to discern C++ static and non-static
15559 member functions. G++ helps GDB by marking the first
15560 parameter for non-static member functions (which is the this
15561 pointer) as artificial. We obtain this information from
15562 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15563 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15564 fnp
->voffset
= VOFFSET_STATIC
;
15567 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15568 dwarf2_full_name (fieldname
, die
, cu
));
15570 /* Get fcontext from DW_AT_containing_type if present. */
15571 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15572 fnp
->fcontext
= die_containing_type (die
, cu
);
15574 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15575 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15577 /* Get accessibility. */
15578 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15580 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15582 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15583 switch (accessibility
)
15585 case DW_ACCESS_private
:
15586 fnp
->is_private
= 1;
15588 case DW_ACCESS_protected
:
15589 fnp
->is_protected
= 1;
15593 /* Check for artificial methods. */
15594 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15595 if (attr
&& DW_UNSND (attr
) != 0)
15596 fnp
->is_artificial
= 1;
15598 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15600 /* Get index in virtual function table if it is a virtual member
15601 function. For older versions of GCC, this is an offset in the
15602 appropriate virtual table, as specified by DW_AT_containing_type.
15603 For everyone else, it is an expression to be evaluated relative
15604 to the object address. */
15606 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15609 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15611 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15613 /* Old-style GCC. */
15614 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15616 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15617 || (DW_BLOCK (attr
)->size
> 1
15618 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15619 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15621 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15622 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15623 dwarf2_complex_location_expr_complaint ();
15625 fnp
->voffset
/= cu
->header
.addr_size
;
15629 dwarf2_complex_location_expr_complaint ();
15631 if (!fnp
->fcontext
)
15633 /* If there is no `this' field and no DW_AT_containing_type,
15634 we cannot actually find a base class context for the
15636 if (TYPE_NFIELDS (this_type
) == 0
15637 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15639 complaint (&symfile_complaints
,
15640 _("cannot determine context for virtual member "
15641 "function \"%s\" (offset %d)"),
15642 fieldname
, to_underlying (die
->sect_off
));
15647 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15651 else if (attr_form_is_section_offset (attr
))
15653 dwarf2_complex_location_expr_complaint ();
15657 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15663 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15664 if (attr
&& DW_UNSND (attr
))
15666 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15667 complaint (&symfile_complaints
,
15668 _("Member function \"%s\" (offset %d) is virtual "
15669 "but the vtable offset is not specified"),
15670 fieldname
, to_underlying (die
->sect_off
));
15671 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15672 TYPE_CPLUS_DYNAMIC (type
) = 1;
15677 /* Create the vector of member function fields, and attach it to the type. */
15680 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15681 struct dwarf2_cu
*cu
)
15683 struct fnfieldlist
*flp
;
15686 if (cu
->language
== language_ada
)
15687 error (_("unexpected member functions in Ada type"));
15689 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15690 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15691 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
15693 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
15695 struct nextfnfield
*nfp
= flp
->head
;
15696 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15699 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
15700 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
15701 fn_flp
->fn_fields
= (struct fn_field
*)
15702 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
15703 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
15704 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
15707 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
15710 /* Returns non-zero if NAME is the name of a vtable member in CU's
15711 language, zero otherwise. */
15713 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15715 static const char vptr
[] = "_vptr";
15717 /* Look for the C++ form of the vtable. */
15718 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15724 /* GCC outputs unnamed structures that are really pointers to member
15725 functions, with the ABI-specified layout. If TYPE describes
15726 such a structure, smash it into a member function type.
15728 GCC shouldn't do this; it should just output pointer to member DIEs.
15729 This is GCC PR debug/28767. */
15732 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15734 struct type
*pfn_type
, *self_type
, *new_type
;
15736 /* Check for a structure with no name and two children. */
15737 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15740 /* Check for __pfn and __delta members. */
15741 if (TYPE_FIELD_NAME (type
, 0) == NULL
15742 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15743 || TYPE_FIELD_NAME (type
, 1) == NULL
15744 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15747 /* Find the type of the method. */
15748 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15749 if (pfn_type
== NULL
15750 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15751 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15754 /* Look for the "this" argument. */
15755 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15756 if (TYPE_NFIELDS (pfn_type
) == 0
15757 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15758 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15761 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15762 new_type
= alloc_type (objfile
);
15763 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15764 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15765 TYPE_VARARGS (pfn_type
));
15766 smash_to_methodptr_type (type
, new_type
);
15770 /* Called when we find the DIE that starts a structure or union scope
15771 (definition) to create a type for the structure or union. Fill in
15772 the type's name and general properties; the members will not be
15773 processed until process_structure_scope. A symbol table entry for
15774 the type will also not be done until process_structure_scope (assuming
15775 the type has a name).
15777 NOTE: we need to call these functions regardless of whether or not the
15778 DIE has a DW_AT_name attribute, since it might be an anonymous
15779 structure or union. This gets the type entered into our set of
15780 user defined types. */
15782 static struct type
*
15783 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15785 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15787 struct attribute
*attr
;
15790 /* If the definition of this type lives in .debug_types, read that type.
15791 Don't follow DW_AT_specification though, that will take us back up
15792 the chain and we want to go down. */
15793 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15796 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15798 /* The type's CU may not be the same as CU.
15799 Ensure TYPE is recorded with CU in die_type_hash. */
15800 return set_die_type (die
, type
, cu
);
15803 type
= alloc_type (objfile
);
15804 INIT_CPLUS_SPECIFIC (type
);
15806 name
= dwarf2_name (die
, cu
);
15809 if (cu
->language
== language_cplus
15810 || cu
->language
== language_d
15811 || cu
->language
== language_rust
)
15813 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15815 /* dwarf2_full_name might have already finished building the DIE's
15816 type. If so, there is no need to continue. */
15817 if (get_die_type (die
, cu
) != NULL
)
15818 return get_die_type (die
, cu
);
15820 TYPE_TAG_NAME (type
) = full_name
;
15821 if (die
->tag
== DW_TAG_structure_type
15822 || die
->tag
== DW_TAG_class_type
)
15823 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15827 /* The name is already allocated along with this objfile, so
15828 we don't need to duplicate it for the type. */
15829 TYPE_TAG_NAME (type
) = name
;
15830 if (die
->tag
== DW_TAG_class_type
)
15831 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15835 if (die
->tag
== DW_TAG_structure_type
)
15837 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15839 else if (die
->tag
== DW_TAG_union_type
)
15841 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15845 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15848 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15849 TYPE_DECLARED_CLASS (type
) = 1;
15851 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15854 if (attr_form_is_constant (attr
))
15855 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15858 /* For the moment, dynamic type sizes are not supported
15859 by GDB's struct type. The actual size is determined
15860 on-demand when resolving the type of a given object,
15861 so set the type's length to zero for now. Otherwise,
15862 we record an expression as the length, and that expression
15863 could lead to a very large value, which could eventually
15864 lead to us trying to allocate that much memory when creating
15865 a value of that type. */
15866 TYPE_LENGTH (type
) = 0;
15871 TYPE_LENGTH (type
) = 0;
15874 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15876 /* ICC<14 does not output the required DW_AT_declaration on
15877 incomplete types, but gives them a size of zero. */
15878 TYPE_STUB (type
) = 1;
15881 TYPE_STUB_SUPPORTED (type
) = 1;
15883 if (die_is_declaration (die
, cu
))
15884 TYPE_STUB (type
) = 1;
15885 else if (attr
== NULL
&& die
->child
== NULL
15886 && producer_is_realview (cu
->producer
))
15887 /* RealView does not output the required DW_AT_declaration
15888 on incomplete types. */
15889 TYPE_STUB (type
) = 1;
15891 /* We need to add the type field to the die immediately so we don't
15892 infinitely recurse when dealing with pointers to the structure
15893 type within the structure itself. */
15894 set_die_type (die
, type
, cu
);
15896 /* set_die_type should be already done. */
15897 set_descriptive_type (type
, die
, cu
);
15902 /* Finish creating a structure or union type, including filling in
15903 its members and creating a symbol for it. */
15906 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15908 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15909 struct die_info
*child_die
;
15912 type
= get_die_type (die
, cu
);
15914 type
= read_structure_type (die
, cu
);
15916 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15918 struct field_info fi
;
15919 std::vector
<struct symbol
*> template_args
;
15920 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
15922 memset (&fi
, 0, sizeof (struct field_info
));
15924 child_die
= die
->child
;
15926 while (child_die
&& child_die
->tag
)
15928 if (child_die
->tag
== DW_TAG_member
15929 || child_die
->tag
== DW_TAG_variable
)
15931 /* NOTE: carlton/2002-11-05: A C++ static data member
15932 should be a DW_TAG_member that is a declaration, but
15933 all versions of G++ as of this writing (so through at
15934 least 3.2.1) incorrectly generate DW_TAG_variable
15935 tags for them instead. */
15936 dwarf2_add_field (&fi
, child_die
, cu
);
15938 else if (child_die
->tag
== DW_TAG_subprogram
)
15940 /* Rust doesn't have member functions in the C++ sense.
15941 However, it does emit ordinary functions as children
15942 of a struct DIE. */
15943 if (cu
->language
== language_rust
)
15944 read_func_scope (child_die
, cu
);
15947 /* C++ member function. */
15948 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
15951 else if (child_die
->tag
== DW_TAG_inheritance
)
15953 /* C++ base class field. */
15954 dwarf2_add_field (&fi
, child_die
, cu
);
15956 else if (type_can_define_types (child_die
))
15957 dwarf2_add_type_defn (&fi
, child_die
, cu
);
15958 else if (child_die
->tag
== DW_TAG_template_type_param
15959 || child_die
->tag
== DW_TAG_template_value_param
)
15961 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15964 template_args
.push_back (arg
);
15967 child_die
= sibling_die (child_die
);
15970 /* Attach template arguments to type. */
15971 if (!template_args
.empty ())
15973 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15974 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15975 TYPE_TEMPLATE_ARGUMENTS (type
)
15976 = XOBNEWVEC (&objfile
->objfile_obstack
,
15978 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15979 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15980 template_args
.data (),
15981 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15982 * sizeof (struct symbol
*)));
15985 /* Attach fields and member functions to the type. */
15987 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15990 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15992 /* Get the type which refers to the base class (possibly this
15993 class itself) which contains the vtable pointer for the current
15994 class from the DW_AT_containing_type attribute. This use of
15995 DW_AT_containing_type is a GNU extension. */
15997 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15999 struct type
*t
= die_containing_type (die
, cu
);
16001 set_type_vptr_basetype (type
, t
);
16006 /* Our own class provides vtbl ptr. */
16007 for (i
= TYPE_NFIELDS (t
) - 1;
16008 i
>= TYPE_N_BASECLASSES (t
);
16011 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16013 if (is_vtable_name (fieldname
, cu
))
16015 set_type_vptr_fieldno (type
, i
);
16020 /* Complain if virtual function table field not found. */
16021 if (i
< TYPE_N_BASECLASSES (t
))
16022 complaint (&symfile_complaints
,
16023 _("virtual function table pointer "
16024 "not found when defining class '%s'"),
16025 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16030 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16033 else if (cu
->producer
16034 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16036 /* The IBM XLC compiler does not provide direct indication
16037 of the containing type, but the vtable pointer is
16038 always named __vfp. */
16042 for (i
= TYPE_NFIELDS (type
) - 1;
16043 i
>= TYPE_N_BASECLASSES (type
);
16046 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16048 set_type_vptr_fieldno (type
, i
);
16049 set_type_vptr_basetype (type
, type
);
16056 /* Copy fi.typedef_field_list linked list elements content into the
16057 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16058 if (fi
.typedef_field_list
)
16060 int i
= fi
.typedef_field_list_count
;
16062 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16063 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16064 = ((struct decl_field
*)
16065 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
16066 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
16068 /* Reverse the list order to keep the debug info elements order. */
16071 struct decl_field
*dest
, *src
;
16073 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
16074 src
= &fi
.typedef_field_list
->field
;
16075 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
16080 /* Copy fi.nested_types_list linked list elements content into the
16081 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16082 if (fi
.nested_types_list
!= NULL
&& cu
->language
!= language_ada
)
16084 int i
= fi
.nested_types_list_count
;
16086 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16087 TYPE_NESTED_TYPES_ARRAY (type
)
16088 = ((struct decl_field
*)
16089 TYPE_ALLOC (type
, sizeof (struct decl_field
) * i
));
16090 TYPE_NESTED_TYPES_COUNT (type
) = i
;
16092 /* Reverse the list order to keep the debug info elements order. */
16095 struct decl_field
*dest
, *src
;
16097 dest
= &TYPE_NESTED_TYPES_FIELD (type
, i
);
16098 src
= &fi
.nested_types_list
->field
;
16099 fi
.nested_types_list
= fi
.nested_types_list
->next
;
16104 do_cleanups (back_to
);
16107 quirk_gcc_member_function_pointer (type
, objfile
);
16109 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16110 snapshots) has been known to create a die giving a declaration
16111 for a class that has, as a child, a die giving a definition for a
16112 nested class. So we have to process our children even if the
16113 current die is a declaration. Normally, of course, a declaration
16114 won't have any children at all. */
16116 child_die
= die
->child
;
16118 while (child_die
!= NULL
&& child_die
->tag
)
16120 if (child_die
->tag
== DW_TAG_member
16121 || child_die
->tag
== DW_TAG_variable
16122 || child_die
->tag
== DW_TAG_inheritance
16123 || child_die
->tag
== DW_TAG_template_value_param
16124 || child_die
->tag
== DW_TAG_template_type_param
)
16129 process_die (child_die
, cu
);
16131 child_die
= sibling_die (child_die
);
16134 /* Do not consider external references. According to the DWARF standard,
16135 these DIEs are identified by the fact that they have no byte_size
16136 attribute, and a declaration attribute. */
16137 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16138 || !die_is_declaration (die
, cu
))
16139 new_symbol (die
, type
, cu
);
16142 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16143 update TYPE using some information only available in DIE's children. */
16146 update_enumeration_type_from_children (struct die_info
*die
,
16148 struct dwarf2_cu
*cu
)
16150 struct die_info
*child_die
;
16151 int unsigned_enum
= 1;
16155 auto_obstack obstack
;
16157 for (child_die
= die
->child
;
16158 child_die
!= NULL
&& child_die
->tag
;
16159 child_die
= sibling_die (child_die
))
16161 struct attribute
*attr
;
16163 const gdb_byte
*bytes
;
16164 struct dwarf2_locexpr_baton
*baton
;
16167 if (child_die
->tag
!= DW_TAG_enumerator
)
16170 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16174 name
= dwarf2_name (child_die
, cu
);
16176 name
= "<anonymous enumerator>";
16178 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16179 &value
, &bytes
, &baton
);
16185 else if ((mask
& value
) != 0)
16190 /* If we already know that the enum type is neither unsigned, nor
16191 a flag type, no need to look at the rest of the enumerates. */
16192 if (!unsigned_enum
&& !flag_enum
)
16197 TYPE_UNSIGNED (type
) = 1;
16199 TYPE_FLAG_ENUM (type
) = 1;
16202 /* Given a DW_AT_enumeration_type die, set its type. We do not
16203 complete the type's fields yet, or create any symbols. */
16205 static struct type
*
16206 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16208 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16210 struct attribute
*attr
;
16213 /* If the definition of this type lives in .debug_types, read that type.
16214 Don't follow DW_AT_specification though, that will take us back up
16215 the chain and we want to go down. */
16216 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16219 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16221 /* The type's CU may not be the same as CU.
16222 Ensure TYPE is recorded with CU in die_type_hash. */
16223 return set_die_type (die
, type
, cu
);
16226 type
= alloc_type (objfile
);
16228 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16229 name
= dwarf2_full_name (NULL
, die
, cu
);
16231 TYPE_TAG_NAME (type
) = name
;
16233 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16236 struct type
*underlying_type
= die_type (die
, cu
);
16238 TYPE_TARGET_TYPE (type
) = underlying_type
;
16241 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16244 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16248 TYPE_LENGTH (type
) = 0;
16251 /* The enumeration DIE can be incomplete. In Ada, any type can be
16252 declared as private in the package spec, and then defined only
16253 inside the package body. Such types are known as Taft Amendment
16254 Types. When another package uses such a type, an incomplete DIE
16255 may be generated by the compiler. */
16256 if (die_is_declaration (die
, cu
))
16257 TYPE_STUB (type
) = 1;
16259 /* Finish the creation of this type by using the enum's children.
16260 We must call this even when the underlying type has been provided
16261 so that we can determine if we're looking at a "flag" enum. */
16262 update_enumeration_type_from_children (die
, type
, cu
);
16264 /* If this type has an underlying type that is not a stub, then we
16265 may use its attributes. We always use the "unsigned" attribute
16266 in this situation, because ordinarily we guess whether the type
16267 is unsigned -- but the guess can be wrong and the underlying type
16268 can tell us the reality. However, we defer to a local size
16269 attribute if one exists, because this lets the compiler override
16270 the underlying type if needed. */
16271 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16273 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16274 if (TYPE_LENGTH (type
) == 0)
16275 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16278 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16280 return set_die_type (die
, type
, cu
);
16283 /* Given a pointer to a die which begins an enumeration, process all
16284 the dies that define the members of the enumeration, and create the
16285 symbol for the enumeration type.
16287 NOTE: We reverse the order of the element list. */
16290 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16292 struct type
*this_type
;
16294 this_type
= get_die_type (die
, cu
);
16295 if (this_type
== NULL
)
16296 this_type
= read_enumeration_type (die
, cu
);
16298 if (die
->child
!= NULL
)
16300 struct die_info
*child_die
;
16301 struct symbol
*sym
;
16302 struct field
*fields
= NULL
;
16303 int num_fields
= 0;
16306 child_die
= die
->child
;
16307 while (child_die
&& child_die
->tag
)
16309 if (child_die
->tag
!= DW_TAG_enumerator
)
16311 process_die (child_die
, cu
);
16315 name
= dwarf2_name (child_die
, cu
);
16318 sym
= new_symbol (child_die
, this_type
, cu
);
16320 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16322 fields
= (struct field
*)
16324 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16325 * sizeof (struct field
));
16328 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16329 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16330 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16331 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16337 child_die
= sibling_die (child_die
);
16342 TYPE_NFIELDS (this_type
) = num_fields
;
16343 TYPE_FIELDS (this_type
) = (struct field
*)
16344 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16345 memcpy (TYPE_FIELDS (this_type
), fields
,
16346 sizeof (struct field
) * num_fields
);
16351 /* If we are reading an enum from a .debug_types unit, and the enum
16352 is a declaration, and the enum is not the signatured type in the
16353 unit, then we do not want to add a symbol for it. Adding a
16354 symbol would in some cases obscure the true definition of the
16355 enum, giving users an incomplete type when the definition is
16356 actually available. Note that we do not want to do this for all
16357 enums which are just declarations, because C++0x allows forward
16358 enum declarations. */
16359 if (cu
->per_cu
->is_debug_types
16360 && die_is_declaration (die
, cu
))
16362 struct signatured_type
*sig_type
;
16364 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16365 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16366 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16370 new_symbol (die
, this_type
, cu
);
16373 /* Extract all information from a DW_TAG_array_type DIE and put it in
16374 the DIE's type field. For now, this only handles one dimensional
16377 static struct type
*
16378 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16380 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16381 struct die_info
*child_die
;
16383 struct type
*element_type
, *range_type
, *index_type
;
16384 struct attribute
*attr
;
16386 struct dynamic_prop
*byte_stride_prop
= NULL
;
16387 unsigned int bit_stride
= 0;
16389 element_type
= die_type (die
, cu
);
16391 /* The die_type call above may have already set the type for this DIE. */
16392 type
= get_die_type (die
, cu
);
16396 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16402 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16403 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16406 complaint (&symfile_complaints
,
16407 _("unable to read array DW_AT_byte_stride "
16408 " - DIE at 0x%x [in module %s]"),
16409 to_underlying (die
->sect_off
),
16410 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16411 /* Ignore this attribute. We will likely not be able to print
16412 arrays of this type correctly, but there is little we can do
16413 to help if we cannot read the attribute's value. */
16414 byte_stride_prop
= NULL
;
16418 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16420 bit_stride
= DW_UNSND (attr
);
16422 /* Irix 6.2 native cc creates array types without children for
16423 arrays with unspecified length. */
16424 if (die
->child
== NULL
)
16426 index_type
= objfile_type (objfile
)->builtin_int
;
16427 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16428 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16429 byte_stride_prop
, bit_stride
);
16430 return set_die_type (die
, type
, cu
);
16433 std::vector
<struct type
*> range_types
;
16434 child_die
= die
->child
;
16435 while (child_die
&& child_die
->tag
)
16437 if (child_die
->tag
== DW_TAG_subrange_type
)
16439 struct type
*child_type
= read_type_die (child_die
, cu
);
16441 if (child_type
!= NULL
)
16443 /* The range type was succesfully read. Save it for the
16444 array type creation. */
16445 range_types
.push_back (child_type
);
16448 child_die
= sibling_die (child_die
);
16451 /* Dwarf2 dimensions are output from left to right, create the
16452 necessary array types in backwards order. */
16454 type
= element_type
;
16456 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16460 while (i
< range_types
.size ())
16461 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16462 byte_stride_prop
, bit_stride
);
16466 size_t ndim
= range_types
.size ();
16468 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16469 byte_stride_prop
, bit_stride
);
16472 /* Understand Dwarf2 support for vector types (like they occur on
16473 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16474 array type. This is not part of the Dwarf2/3 standard yet, but a
16475 custom vendor extension. The main difference between a regular
16476 array and the vector variant is that vectors are passed by value
16478 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16480 make_vector_type (type
);
16482 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16483 implementation may choose to implement triple vectors using this
16485 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16488 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16489 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16491 complaint (&symfile_complaints
,
16492 _("DW_AT_byte_size for array type smaller "
16493 "than the total size of elements"));
16496 name
= dwarf2_name (die
, cu
);
16498 TYPE_NAME (type
) = name
;
16500 /* Install the type in the die. */
16501 set_die_type (die
, type
, cu
);
16503 /* set_die_type should be already done. */
16504 set_descriptive_type (type
, die
, cu
);
16509 static enum dwarf_array_dim_ordering
16510 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16512 struct attribute
*attr
;
16514 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16517 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16519 /* GNU F77 is a special case, as at 08/2004 array type info is the
16520 opposite order to the dwarf2 specification, but data is still
16521 laid out as per normal fortran.
16523 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16524 version checking. */
16526 if (cu
->language
== language_fortran
16527 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16529 return DW_ORD_row_major
;
16532 switch (cu
->language_defn
->la_array_ordering
)
16534 case array_column_major
:
16535 return DW_ORD_col_major
;
16536 case array_row_major
:
16538 return DW_ORD_row_major
;
16542 /* Extract all information from a DW_TAG_set_type DIE and put it in
16543 the DIE's type field. */
16545 static struct type
*
16546 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16548 struct type
*domain_type
, *set_type
;
16549 struct attribute
*attr
;
16551 domain_type
= die_type (die
, cu
);
16553 /* The die_type call above may have already set the type for this DIE. */
16554 set_type
= get_die_type (die
, cu
);
16558 set_type
= create_set_type (NULL
, domain_type
);
16560 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16562 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16564 return set_die_type (die
, set_type
, cu
);
16567 /* A helper for read_common_block that creates a locexpr baton.
16568 SYM is the symbol which we are marking as computed.
16569 COMMON_DIE is the DIE for the common block.
16570 COMMON_LOC is the location expression attribute for the common
16572 MEMBER_LOC is the location expression attribute for the particular
16573 member of the common block that we are processing.
16574 CU is the CU from which the above come. */
16577 mark_common_block_symbol_computed (struct symbol
*sym
,
16578 struct die_info
*common_die
,
16579 struct attribute
*common_loc
,
16580 struct attribute
*member_loc
,
16581 struct dwarf2_cu
*cu
)
16583 struct dwarf2_per_objfile
*dwarf2_per_objfile
16584 = cu
->per_cu
->dwarf2_per_objfile
;
16585 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16586 struct dwarf2_locexpr_baton
*baton
;
16588 unsigned int cu_off
;
16589 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16590 LONGEST offset
= 0;
16592 gdb_assert (common_loc
&& member_loc
);
16593 gdb_assert (attr_form_is_block (common_loc
));
16594 gdb_assert (attr_form_is_block (member_loc
)
16595 || attr_form_is_constant (member_loc
));
16597 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16598 baton
->per_cu
= cu
->per_cu
;
16599 gdb_assert (baton
->per_cu
);
16601 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16603 if (attr_form_is_constant (member_loc
))
16605 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16606 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16609 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16611 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16614 *ptr
++ = DW_OP_call4
;
16615 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16616 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16619 if (attr_form_is_constant (member_loc
))
16621 *ptr
++ = DW_OP_addr
;
16622 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16623 ptr
+= cu
->header
.addr_size
;
16627 /* We have to copy the data here, because DW_OP_call4 will only
16628 use a DW_AT_location attribute. */
16629 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16630 ptr
+= DW_BLOCK (member_loc
)->size
;
16633 *ptr
++ = DW_OP_plus
;
16634 gdb_assert (ptr
- baton
->data
== baton
->size
);
16636 SYMBOL_LOCATION_BATON (sym
) = baton
;
16637 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16640 /* Create appropriate locally-scoped variables for all the
16641 DW_TAG_common_block entries. Also create a struct common_block
16642 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16643 is used to sepate the common blocks name namespace from regular
16647 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16649 struct attribute
*attr
;
16651 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16654 /* Support the .debug_loc offsets. */
16655 if (attr_form_is_block (attr
))
16659 else if (attr_form_is_section_offset (attr
))
16661 dwarf2_complex_location_expr_complaint ();
16666 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16667 "common block member");
16672 if (die
->child
!= NULL
)
16674 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16675 struct die_info
*child_die
;
16676 size_t n_entries
= 0, size
;
16677 struct common_block
*common_block
;
16678 struct symbol
*sym
;
16680 for (child_die
= die
->child
;
16681 child_die
&& child_die
->tag
;
16682 child_die
= sibling_die (child_die
))
16685 size
= (sizeof (struct common_block
)
16686 + (n_entries
- 1) * sizeof (struct symbol
*));
16688 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16690 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16691 common_block
->n_entries
= 0;
16693 for (child_die
= die
->child
;
16694 child_die
&& child_die
->tag
;
16695 child_die
= sibling_die (child_die
))
16697 /* Create the symbol in the DW_TAG_common_block block in the current
16699 sym
= new_symbol (child_die
, NULL
, cu
);
16702 struct attribute
*member_loc
;
16704 common_block
->contents
[common_block
->n_entries
++] = sym
;
16706 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16710 /* GDB has handled this for a long time, but it is
16711 not specified by DWARF. It seems to have been
16712 emitted by gfortran at least as recently as:
16713 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16714 complaint (&symfile_complaints
,
16715 _("Variable in common block has "
16716 "DW_AT_data_member_location "
16717 "- DIE at 0x%x [in module %s]"),
16718 to_underlying (child_die
->sect_off
),
16719 objfile_name (objfile
));
16721 if (attr_form_is_section_offset (member_loc
))
16722 dwarf2_complex_location_expr_complaint ();
16723 else if (attr_form_is_constant (member_loc
)
16724 || attr_form_is_block (member_loc
))
16727 mark_common_block_symbol_computed (sym
, die
, attr
,
16731 dwarf2_complex_location_expr_complaint ();
16736 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16737 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16741 /* Create a type for a C++ namespace. */
16743 static struct type
*
16744 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16746 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16747 const char *previous_prefix
, *name
;
16751 /* For extensions, reuse the type of the original namespace. */
16752 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16754 struct die_info
*ext_die
;
16755 struct dwarf2_cu
*ext_cu
= cu
;
16757 ext_die
= dwarf2_extension (die
, &ext_cu
);
16758 type
= read_type_die (ext_die
, ext_cu
);
16760 /* EXT_CU may not be the same as CU.
16761 Ensure TYPE is recorded with CU in die_type_hash. */
16762 return set_die_type (die
, type
, cu
);
16765 name
= namespace_name (die
, &is_anonymous
, cu
);
16767 /* Now build the name of the current namespace. */
16769 previous_prefix
= determine_prefix (die
, cu
);
16770 if (previous_prefix
[0] != '\0')
16771 name
= typename_concat (&objfile
->objfile_obstack
,
16772 previous_prefix
, name
, 0, cu
);
16774 /* Create the type. */
16775 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16776 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16778 return set_die_type (die
, type
, cu
);
16781 /* Read a namespace scope. */
16784 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16786 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16789 /* Add a symbol associated to this if we haven't seen the namespace
16790 before. Also, add a using directive if it's an anonymous
16793 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16797 type
= read_type_die (die
, cu
);
16798 new_symbol (die
, type
, cu
);
16800 namespace_name (die
, &is_anonymous
, cu
);
16803 const char *previous_prefix
= determine_prefix (die
, cu
);
16805 std::vector
<const char *> excludes
;
16806 add_using_directive (using_directives (cu
->language
),
16807 previous_prefix
, TYPE_NAME (type
), NULL
,
16808 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16812 if (die
->child
!= NULL
)
16814 struct die_info
*child_die
= die
->child
;
16816 while (child_die
&& child_die
->tag
)
16818 process_die (child_die
, cu
);
16819 child_die
= sibling_die (child_die
);
16824 /* Read a Fortran module as type. This DIE can be only a declaration used for
16825 imported module. Still we need that type as local Fortran "use ... only"
16826 declaration imports depend on the created type in determine_prefix. */
16828 static struct type
*
16829 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16831 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16832 const char *module_name
;
16835 module_name
= dwarf2_name (die
, cu
);
16837 complaint (&symfile_complaints
,
16838 _("DW_TAG_module has no name, offset 0x%x"),
16839 to_underlying (die
->sect_off
));
16840 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16842 /* determine_prefix uses TYPE_TAG_NAME. */
16843 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16845 return set_die_type (die
, type
, cu
);
16848 /* Read a Fortran module. */
16851 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16853 struct die_info
*child_die
= die
->child
;
16856 type
= read_type_die (die
, cu
);
16857 new_symbol (die
, type
, cu
);
16859 while (child_die
&& child_die
->tag
)
16861 process_die (child_die
, cu
);
16862 child_die
= sibling_die (child_die
);
16866 /* Return the name of the namespace represented by DIE. Set
16867 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16870 static const char *
16871 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16873 struct die_info
*current_die
;
16874 const char *name
= NULL
;
16876 /* Loop through the extensions until we find a name. */
16878 for (current_die
= die
;
16879 current_die
!= NULL
;
16880 current_die
= dwarf2_extension (die
, &cu
))
16882 /* We don't use dwarf2_name here so that we can detect the absence
16883 of a name -> anonymous namespace. */
16884 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16890 /* Is it an anonymous namespace? */
16892 *is_anonymous
= (name
== NULL
);
16894 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16899 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16900 the user defined type vector. */
16902 static struct type
*
16903 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16905 struct gdbarch
*gdbarch
16906 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16907 struct comp_unit_head
*cu_header
= &cu
->header
;
16909 struct attribute
*attr_byte_size
;
16910 struct attribute
*attr_address_class
;
16911 int byte_size
, addr_class
;
16912 struct type
*target_type
;
16914 target_type
= die_type (die
, cu
);
16916 /* The die_type call above may have already set the type for this DIE. */
16917 type
= get_die_type (die
, cu
);
16921 type
= lookup_pointer_type (target_type
);
16923 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16924 if (attr_byte_size
)
16925 byte_size
= DW_UNSND (attr_byte_size
);
16927 byte_size
= cu_header
->addr_size
;
16929 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16930 if (attr_address_class
)
16931 addr_class
= DW_UNSND (attr_address_class
);
16933 addr_class
= DW_ADDR_none
;
16935 /* If the pointer size or address class is different than the
16936 default, create a type variant marked as such and set the
16937 length accordingly. */
16938 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
16940 if (gdbarch_address_class_type_flags_p (gdbarch
))
16944 type_flags
= gdbarch_address_class_type_flags
16945 (gdbarch
, byte_size
, addr_class
);
16946 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16948 type
= make_type_with_address_space (type
, type_flags
);
16950 else if (TYPE_LENGTH (type
) != byte_size
)
16952 complaint (&symfile_complaints
,
16953 _("invalid pointer size %d"), byte_size
);
16957 /* Should we also complain about unhandled address classes? */
16961 TYPE_LENGTH (type
) = byte_size
;
16962 return set_die_type (die
, type
, cu
);
16965 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16966 the user defined type vector. */
16968 static struct type
*
16969 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16972 struct type
*to_type
;
16973 struct type
*domain
;
16975 to_type
= die_type (die
, cu
);
16976 domain
= die_containing_type (die
, cu
);
16978 /* The calls above may have already set the type for this DIE. */
16979 type
= get_die_type (die
, cu
);
16983 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16984 type
= lookup_methodptr_type (to_type
);
16985 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16987 struct type
*new_type
16988 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16990 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16991 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16992 TYPE_VARARGS (to_type
));
16993 type
= lookup_methodptr_type (new_type
);
16996 type
= lookup_memberptr_type (to_type
, domain
);
16998 return set_die_type (die
, type
, cu
);
17001 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17002 the user defined type vector. */
17004 static struct type
*
17005 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17006 enum type_code refcode
)
17008 struct comp_unit_head
*cu_header
= &cu
->header
;
17009 struct type
*type
, *target_type
;
17010 struct attribute
*attr
;
17012 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17014 target_type
= die_type (die
, cu
);
17016 /* The die_type call above may have already set the type for this DIE. */
17017 type
= get_die_type (die
, cu
);
17021 type
= lookup_reference_type (target_type
, refcode
);
17022 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17025 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17029 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17031 return set_die_type (die
, type
, cu
);
17034 /* Add the given cv-qualifiers to the element type of the array. GCC
17035 outputs DWARF type qualifiers that apply to an array, not the
17036 element type. But GDB relies on the array element type to carry
17037 the cv-qualifiers. This mimics section 6.7.3 of the C99
17040 static struct type
*
17041 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17042 struct type
*base_type
, int cnst
, int voltl
)
17044 struct type
*el_type
, *inner_array
;
17046 base_type
= copy_type (base_type
);
17047 inner_array
= base_type
;
17049 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17051 TYPE_TARGET_TYPE (inner_array
) =
17052 copy_type (TYPE_TARGET_TYPE (inner_array
));
17053 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17056 el_type
= TYPE_TARGET_TYPE (inner_array
);
17057 cnst
|= TYPE_CONST (el_type
);
17058 voltl
|= TYPE_VOLATILE (el_type
);
17059 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17061 return set_die_type (die
, base_type
, cu
);
17064 static struct type
*
17065 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17067 struct type
*base_type
, *cv_type
;
17069 base_type
= die_type (die
, cu
);
17071 /* The die_type call above may have already set the type for this DIE. */
17072 cv_type
= get_die_type (die
, cu
);
17076 /* In case the const qualifier is applied to an array type, the element type
17077 is so qualified, not the array type (section 6.7.3 of C99). */
17078 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17079 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17081 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17082 return set_die_type (die
, cv_type
, cu
);
17085 static struct type
*
17086 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17088 struct type
*base_type
, *cv_type
;
17090 base_type
= die_type (die
, cu
);
17092 /* The die_type call above may have already set the type for this DIE. */
17093 cv_type
= get_die_type (die
, cu
);
17097 /* In case the volatile qualifier is applied to an array type, the
17098 element type is so qualified, not the array type (section 6.7.3
17100 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17101 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17103 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17104 return set_die_type (die
, cv_type
, cu
);
17107 /* Handle DW_TAG_restrict_type. */
17109 static struct type
*
17110 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17112 struct type
*base_type
, *cv_type
;
17114 base_type
= die_type (die
, cu
);
17116 /* The die_type call above may have already set the type for this DIE. */
17117 cv_type
= get_die_type (die
, cu
);
17121 cv_type
= make_restrict_type (base_type
);
17122 return set_die_type (die
, cv_type
, cu
);
17125 /* Handle DW_TAG_atomic_type. */
17127 static struct type
*
17128 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17130 struct type
*base_type
, *cv_type
;
17132 base_type
= die_type (die
, cu
);
17134 /* The die_type call above may have already set the type for this DIE. */
17135 cv_type
= get_die_type (die
, cu
);
17139 cv_type
= make_atomic_type (base_type
);
17140 return set_die_type (die
, cv_type
, cu
);
17143 /* Extract all information from a DW_TAG_string_type DIE and add to
17144 the user defined type vector. It isn't really a user defined type,
17145 but it behaves like one, with other DIE's using an AT_user_def_type
17146 attribute to reference it. */
17148 static struct type
*
17149 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17151 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17152 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17153 struct type
*type
, *range_type
, *index_type
, *char_type
;
17154 struct attribute
*attr
;
17155 unsigned int length
;
17157 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17160 length
= DW_UNSND (attr
);
17164 /* Check for the DW_AT_byte_size attribute. */
17165 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17168 length
= DW_UNSND (attr
);
17176 index_type
= objfile_type (objfile
)->builtin_int
;
17177 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17178 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17179 type
= create_string_type (NULL
, char_type
, range_type
);
17181 return set_die_type (die
, type
, cu
);
17184 /* Assuming that DIE corresponds to a function, returns nonzero
17185 if the function is prototyped. */
17188 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17190 struct attribute
*attr
;
17192 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17193 if (attr
&& (DW_UNSND (attr
) != 0))
17196 /* The DWARF standard implies that the DW_AT_prototyped attribute
17197 is only meaninful for C, but the concept also extends to other
17198 languages that allow unprototyped functions (Eg: Objective C).
17199 For all other languages, assume that functions are always
17201 if (cu
->language
!= language_c
17202 && cu
->language
!= language_objc
17203 && cu
->language
!= language_opencl
)
17206 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17207 prototyped and unprototyped functions; default to prototyped,
17208 since that is more common in modern code (and RealView warns
17209 about unprototyped functions). */
17210 if (producer_is_realview (cu
->producer
))
17216 /* Handle DIES due to C code like:
17220 int (*funcp)(int a, long l);
17224 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17226 static struct type
*
17227 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17229 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17230 struct type
*type
; /* Type that this function returns. */
17231 struct type
*ftype
; /* Function that returns above type. */
17232 struct attribute
*attr
;
17234 type
= die_type (die
, cu
);
17236 /* The die_type call above may have already set the type for this DIE. */
17237 ftype
= get_die_type (die
, cu
);
17241 ftype
= lookup_function_type (type
);
17243 if (prototyped_function_p (die
, cu
))
17244 TYPE_PROTOTYPED (ftype
) = 1;
17246 /* Store the calling convention in the type if it's available in
17247 the subroutine die. Otherwise set the calling convention to
17248 the default value DW_CC_normal. */
17249 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17251 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17252 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17253 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17255 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17257 /* Record whether the function returns normally to its caller or not
17258 if the DWARF producer set that information. */
17259 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17260 if (attr
&& (DW_UNSND (attr
) != 0))
17261 TYPE_NO_RETURN (ftype
) = 1;
17263 /* We need to add the subroutine type to the die immediately so
17264 we don't infinitely recurse when dealing with parameters
17265 declared as the same subroutine type. */
17266 set_die_type (die
, ftype
, cu
);
17268 if (die
->child
!= NULL
)
17270 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17271 struct die_info
*child_die
;
17272 int nparams
, iparams
;
17274 /* Count the number of parameters.
17275 FIXME: GDB currently ignores vararg functions, but knows about
17276 vararg member functions. */
17278 child_die
= die
->child
;
17279 while (child_die
&& child_die
->tag
)
17281 if (child_die
->tag
== DW_TAG_formal_parameter
)
17283 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17284 TYPE_VARARGS (ftype
) = 1;
17285 child_die
= sibling_die (child_die
);
17288 /* Allocate storage for parameters and fill them in. */
17289 TYPE_NFIELDS (ftype
) = nparams
;
17290 TYPE_FIELDS (ftype
) = (struct field
*)
17291 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17293 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17294 even if we error out during the parameters reading below. */
17295 for (iparams
= 0; iparams
< nparams
; iparams
++)
17296 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17299 child_die
= die
->child
;
17300 while (child_die
&& child_die
->tag
)
17302 if (child_die
->tag
== DW_TAG_formal_parameter
)
17304 struct type
*arg_type
;
17306 /* DWARF version 2 has no clean way to discern C++
17307 static and non-static member functions. G++ helps
17308 GDB by marking the first parameter for non-static
17309 member functions (which is the this pointer) as
17310 artificial. We pass this information to
17311 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17313 DWARF version 3 added DW_AT_object_pointer, which GCC
17314 4.5 does not yet generate. */
17315 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17317 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17319 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17320 arg_type
= die_type (child_die
, cu
);
17322 /* RealView does not mark THIS as const, which the testsuite
17323 expects. GCC marks THIS as const in method definitions,
17324 but not in the class specifications (GCC PR 43053). */
17325 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17326 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17329 struct dwarf2_cu
*arg_cu
= cu
;
17330 const char *name
= dwarf2_name (child_die
, cu
);
17332 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17335 /* If the compiler emits this, use it. */
17336 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17339 else if (name
&& strcmp (name
, "this") == 0)
17340 /* Function definitions will have the argument names. */
17342 else if (name
== NULL
&& iparams
== 0)
17343 /* Declarations may not have the names, so like
17344 elsewhere in GDB, assume an artificial first
17345 argument is "this". */
17349 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17353 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17356 child_die
= sibling_die (child_die
);
17363 static struct type
*
17364 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17366 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17367 const char *name
= NULL
;
17368 struct type
*this_type
, *target_type
;
17370 name
= dwarf2_full_name (NULL
, die
, cu
);
17371 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17372 TYPE_TARGET_STUB (this_type
) = 1;
17373 set_die_type (die
, this_type
, cu
);
17374 target_type
= die_type (die
, cu
);
17375 if (target_type
!= this_type
)
17376 TYPE_TARGET_TYPE (this_type
) = target_type
;
17379 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17380 spec and cause infinite loops in GDB. */
17381 complaint (&symfile_complaints
,
17382 _("Self-referential DW_TAG_typedef "
17383 "- DIE at 0x%x [in module %s]"),
17384 to_underlying (die
->sect_off
), objfile_name (objfile
));
17385 TYPE_TARGET_TYPE (this_type
) = NULL
;
17390 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17391 (which may be different from NAME) to the architecture back-end to allow
17392 it to guess the correct format if necessary. */
17394 static struct type
*
17395 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17396 const char *name_hint
)
17398 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17399 const struct floatformat
**format
;
17402 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17404 type
= init_float_type (objfile
, bits
, name
, format
);
17406 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17411 /* Find a representation of a given base type and install
17412 it in the TYPE field of the die. */
17414 static struct type
*
17415 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17417 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17419 struct attribute
*attr
;
17420 int encoding
= 0, bits
= 0;
17423 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17426 encoding
= DW_UNSND (attr
);
17428 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17431 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17433 name
= dwarf2_name (die
, cu
);
17436 complaint (&symfile_complaints
,
17437 _("DW_AT_name missing from DW_TAG_base_type"));
17442 case DW_ATE_address
:
17443 /* Turn DW_ATE_address into a void * pointer. */
17444 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17445 type
= init_pointer_type (objfile
, bits
, name
, type
);
17447 case DW_ATE_boolean
:
17448 type
= init_boolean_type (objfile
, bits
, 1, name
);
17450 case DW_ATE_complex_float
:
17451 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17452 type
= init_complex_type (objfile
, name
, type
);
17454 case DW_ATE_decimal_float
:
17455 type
= init_decfloat_type (objfile
, bits
, name
);
17458 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17460 case DW_ATE_signed
:
17461 type
= init_integer_type (objfile
, bits
, 0, name
);
17463 case DW_ATE_unsigned
:
17464 if (cu
->language
== language_fortran
17466 && startswith (name
, "character("))
17467 type
= init_character_type (objfile
, bits
, 1, name
);
17469 type
= init_integer_type (objfile
, bits
, 1, name
);
17471 case DW_ATE_signed_char
:
17472 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17473 || cu
->language
== language_pascal
17474 || cu
->language
== language_fortran
)
17475 type
= init_character_type (objfile
, bits
, 0, name
);
17477 type
= init_integer_type (objfile
, bits
, 0, name
);
17479 case DW_ATE_unsigned_char
:
17480 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17481 || cu
->language
== language_pascal
17482 || cu
->language
== language_fortran
17483 || cu
->language
== language_rust
)
17484 type
= init_character_type (objfile
, bits
, 1, name
);
17486 type
= init_integer_type (objfile
, bits
, 1, name
);
17490 gdbarch
*arch
= get_objfile_arch (objfile
);
17493 type
= builtin_type (arch
)->builtin_char16
;
17494 else if (bits
== 32)
17495 type
= builtin_type (arch
)->builtin_char32
;
17498 complaint (&symfile_complaints
,
17499 _("unsupported DW_ATE_UTF bit size: '%d'"),
17501 type
= init_integer_type (objfile
, bits
, 1, name
);
17503 return set_die_type (die
, type
, cu
);
17508 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17509 dwarf_type_encoding_name (encoding
));
17510 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17514 if (name
&& strcmp (name
, "char") == 0)
17515 TYPE_NOSIGN (type
) = 1;
17517 return set_die_type (die
, type
, cu
);
17520 /* Parse dwarf attribute if it's a block, reference or constant and put the
17521 resulting value of the attribute into struct bound_prop.
17522 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17525 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17526 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17528 struct dwarf2_property_baton
*baton
;
17529 struct obstack
*obstack
17530 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17532 if (attr
== NULL
|| prop
== NULL
)
17535 if (attr_form_is_block (attr
))
17537 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17538 baton
->referenced_type
= NULL
;
17539 baton
->locexpr
.per_cu
= cu
->per_cu
;
17540 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17541 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17542 prop
->data
.baton
= baton
;
17543 prop
->kind
= PROP_LOCEXPR
;
17544 gdb_assert (prop
->data
.baton
!= NULL
);
17546 else if (attr_form_is_ref (attr
))
17548 struct dwarf2_cu
*target_cu
= cu
;
17549 struct die_info
*target_die
;
17550 struct attribute
*target_attr
;
17552 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17553 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17554 if (target_attr
== NULL
)
17555 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17557 if (target_attr
== NULL
)
17560 switch (target_attr
->name
)
17562 case DW_AT_location
:
17563 if (attr_form_is_section_offset (target_attr
))
17565 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17566 baton
->referenced_type
= die_type (target_die
, target_cu
);
17567 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17568 prop
->data
.baton
= baton
;
17569 prop
->kind
= PROP_LOCLIST
;
17570 gdb_assert (prop
->data
.baton
!= NULL
);
17572 else if (attr_form_is_block (target_attr
))
17574 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17575 baton
->referenced_type
= die_type (target_die
, target_cu
);
17576 baton
->locexpr
.per_cu
= cu
->per_cu
;
17577 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17578 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17579 prop
->data
.baton
= baton
;
17580 prop
->kind
= PROP_LOCEXPR
;
17581 gdb_assert (prop
->data
.baton
!= NULL
);
17585 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17586 "dynamic property");
17590 case DW_AT_data_member_location
:
17594 if (!handle_data_member_location (target_die
, target_cu
,
17598 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17599 baton
->referenced_type
= read_type_die (target_die
->parent
,
17601 baton
->offset_info
.offset
= offset
;
17602 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17603 prop
->data
.baton
= baton
;
17604 prop
->kind
= PROP_ADDR_OFFSET
;
17609 else if (attr_form_is_constant (attr
))
17611 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17612 prop
->kind
= PROP_CONST
;
17616 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17617 dwarf2_name (die
, cu
));
17624 /* Read the given DW_AT_subrange DIE. */
17626 static struct type
*
17627 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17629 struct type
*base_type
, *orig_base_type
;
17630 struct type
*range_type
;
17631 struct attribute
*attr
;
17632 struct dynamic_prop low
, high
;
17633 int low_default_is_valid
;
17634 int high_bound_is_count
= 0;
17636 LONGEST negative_mask
;
17638 orig_base_type
= die_type (die
, cu
);
17639 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17640 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17641 creating the range type, but we use the result of check_typedef
17642 when examining properties of the type. */
17643 base_type
= check_typedef (orig_base_type
);
17645 /* The die_type call above may have already set the type for this DIE. */
17646 range_type
= get_die_type (die
, cu
);
17650 low
.kind
= PROP_CONST
;
17651 high
.kind
= PROP_CONST
;
17652 high
.data
.const_val
= 0;
17654 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17655 omitting DW_AT_lower_bound. */
17656 switch (cu
->language
)
17659 case language_cplus
:
17660 low
.data
.const_val
= 0;
17661 low_default_is_valid
= 1;
17663 case language_fortran
:
17664 low
.data
.const_val
= 1;
17665 low_default_is_valid
= 1;
17668 case language_objc
:
17669 case language_rust
:
17670 low
.data
.const_val
= 0;
17671 low_default_is_valid
= (cu
->header
.version
>= 4);
17675 case language_pascal
:
17676 low
.data
.const_val
= 1;
17677 low_default_is_valid
= (cu
->header
.version
>= 4);
17680 low
.data
.const_val
= 0;
17681 low_default_is_valid
= 0;
17685 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17687 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17688 else if (!low_default_is_valid
)
17689 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
17690 "- DIE at 0x%x [in module %s]"),
17691 to_underlying (die
->sect_off
),
17692 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17694 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17695 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17697 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
17698 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17700 /* If bounds are constant do the final calculation here. */
17701 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17702 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17704 high_bound_is_count
= 1;
17708 /* Dwarf-2 specifications explicitly allows to create subrange types
17709 without specifying a base type.
17710 In that case, the base type must be set to the type of
17711 the lower bound, upper bound or count, in that order, if any of these
17712 three attributes references an object that has a type.
17713 If no base type is found, the Dwarf-2 specifications say that
17714 a signed integer type of size equal to the size of an address should
17716 For the following C code: `extern char gdb_int [];'
17717 GCC produces an empty range DIE.
17718 FIXME: muller/2010-05-28: Possible references to object for low bound,
17719 high bound or count are not yet handled by this code. */
17720 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17722 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17723 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17724 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17725 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17727 /* Test "int", "long int", and "long long int" objfile types,
17728 and select the first one having a size above or equal to the
17729 architecture address size. */
17730 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17731 base_type
= int_type
;
17734 int_type
= objfile_type (objfile
)->builtin_long
;
17735 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17736 base_type
= int_type
;
17739 int_type
= objfile_type (objfile
)->builtin_long_long
;
17740 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17741 base_type
= int_type
;
17746 /* Normally, the DWARF producers are expected to use a signed
17747 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17748 But this is unfortunately not always the case, as witnessed
17749 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17750 is used instead. To work around that ambiguity, we treat
17751 the bounds as signed, and thus sign-extend their values, when
17752 the base type is signed. */
17754 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17755 if (low
.kind
== PROP_CONST
17756 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17757 low
.data
.const_val
|= negative_mask
;
17758 if (high
.kind
== PROP_CONST
17759 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17760 high
.data
.const_val
|= negative_mask
;
17762 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17764 if (high_bound_is_count
)
17765 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17767 /* Ada expects an empty array on no boundary attributes. */
17768 if (attr
== NULL
&& cu
->language
!= language_ada
)
17769 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17771 name
= dwarf2_name (die
, cu
);
17773 TYPE_NAME (range_type
) = name
;
17775 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17777 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17779 set_die_type (die
, range_type
, cu
);
17781 /* set_die_type should be already done. */
17782 set_descriptive_type (range_type
, die
, cu
);
17787 static struct type
*
17788 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17792 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17794 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17796 /* In Ada, an unspecified type is typically used when the description
17797 of the type is defered to a different unit. When encountering
17798 such a type, we treat it as a stub, and try to resolve it later on,
17800 if (cu
->language
== language_ada
)
17801 TYPE_STUB (type
) = 1;
17803 return set_die_type (die
, type
, cu
);
17806 /* Read a single die and all its descendents. Set the die's sibling
17807 field to NULL; set other fields in the die correctly, and set all
17808 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17809 location of the info_ptr after reading all of those dies. PARENT
17810 is the parent of the die in question. */
17812 static struct die_info
*
17813 read_die_and_children (const struct die_reader_specs
*reader
,
17814 const gdb_byte
*info_ptr
,
17815 const gdb_byte
**new_info_ptr
,
17816 struct die_info
*parent
)
17818 struct die_info
*die
;
17819 const gdb_byte
*cur_ptr
;
17822 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17825 *new_info_ptr
= cur_ptr
;
17828 store_in_ref_table (die
, reader
->cu
);
17831 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17835 *new_info_ptr
= cur_ptr
;
17838 die
->sibling
= NULL
;
17839 die
->parent
= parent
;
17843 /* Read a die, all of its descendents, and all of its siblings; set
17844 all of the fields of all of the dies correctly. Arguments are as
17845 in read_die_and_children. */
17847 static struct die_info
*
17848 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17849 const gdb_byte
*info_ptr
,
17850 const gdb_byte
**new_info_ptr
,
17851 struct die_info
*parent
)
17853 struct die_info
*first_die
, *last_sibling
;
17854 const gdb_byte
*cur_ptr
;
17856 cur_ptr
= info_ptr
;
17857 first_die
= last_sibling
= NULL
;
17861 struct die_info
*die
17862 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17866 *new_info_ptr
= cur_ptr
;
17873 last_sibling
->sibling
= die
;
17875 last_sibling
= die
;
17879 /* Read a die, all of its descendents, and all of its siblings; set
17880 all of the fields of all of the dies correctly. Arguments are as
17881 in read_die_and_children.
17882 This the main entry point for reading a DIE and all its children. */
17884 static struct die_info
*
17885 read_die_and_siblings (const struct die_reader_specs
*reader
,
17886 const gdb_byte
*info_ptr
,
17887 const gdb_byte
**new_info_ptr
,
17888 struct die_info
*parent
)
17890 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17891 new_info_ptr
, parent
);
17893 if (dwarf_die_debug
)
17895 fprintf_unfiltered (gdb_stdlog
,
17896 "Read die from %s@0x%x of %s:\n",
17897 get_section_name (reader
->die_section
),
17898 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17899 bfd_get_filename (reader
->abfd
));
17900 dump_die (die
, dwarf_die_debug
);
17906 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17908 The caller is responsible for filling in the extra attributes
17909 and updating (*DIEP)->num_attrs.
17910 Set DIEP to point to a newly allocated die with its information,
17911 except for its child, sibling, and parent fields.
17912 Set HAS_CHILDREN to tell whether the die has children or not. */
17914 static const gdb_byte
*
17915 read_full_die_1 (const struct die_reader_specs
*reader
,
17916 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17917 int *has_children
, int num_extra_attrs
)
17919 unsigned int abbrev_number
, bytes_read
, i
;
17920 struct abbrev_info
*abbrev
;
17921 struct die_info
*die
;
17922 struct dwarf2_cu
*cu
= reader
->cu
;
17923 bfd
*abfd
= reader
->abfd
;
17925 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17926 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17927 info_ptr
+= bytes_read
;
17928 if (!abbrev_number
)
17935 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17937 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17939 bfd_get_filename (abfd
));
17941 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17942 die
->sect_off
= sect_off
;
17943 die
->tag
= abbrev
->tag
;
17944 die
->abbrev
= abbrev_number
;
17946 /* Make the result usable.
17947 The caller needs to update num_attrs after adding the extra
17949 die
->num_attrs
= abbrev
->num_attrs
;
17951 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17952 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17956 *has_children
= abbrev
->has_children
;
17960 /* Read a die and all its attributes.
17961 Set DIEP to point to a newly allocated die with its information,
17962 except for its child, sibling, and parent fields.
17963 Set HAS_CHILDREN to tell whether the die has children or not. */
17965 static const gdb_byte
*
17966 read_full_die (const struct die_reader_specs
*reader
,
17967 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17970 const gdb_byte
*result
;
17972 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
17974 if (dwarf_die_debug
)
17976 fprintf_unfiltered (gdb_stdlog
,
17977 "Read die from %s@0x%x of %s:\n",
17978 get_section_name (reader
->die_section
),
17979 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17980 bfd_get_filename (reader
->abfd
));
17981 dump_die (*diep
, dwarf_die_debug
);
17987 /* Abbreviation tables.
17989 In DWARF version 2, the description of the debugging information is
17990 stored in a separate .debug_abbrev section. Before we read any
17991 dies from a section we read in all abbreviations and install them
17992 in a hash table. */
17994 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
17996 struct abbrev_info
*
17997 abbrev_table::alloc_abbrev ()
17999 struct abbrev_info
*abbrev
;
18001 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18002 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18007 /* Add an abbreviation to the table. */
18010 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18011 struct abbrev_info
*abbrev
)
18013 unsigned int hash_number
;
18015 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18016 abbrev
->next
= m_abbrevs
[hash_number
];
18017 m_abbrevs
[hash_number
] = abbrev
;
18020 /* Look up an abbrev in the table.
18021 Returns NULL if the abbrev is not found. */
18023 struct abbrev_info
*
18024 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18026 unsigned int hash_number
;
18027 struct abbrev_info
*abbrev
;
18029 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18030 abbrev
= m_abbrevs
[hash_number
];
18034 if (abbrev
->number
== abbrev_number
)
18036 abbrev
= abbrev
->next
;
18041 /* Read in an abbrev table. */
18043 static abbrev_table_up
18044 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18045 struct dwarf2_section_info
*section
,
18046 sect_offset sect_off
)
18048 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18049 bfd
*abfd
= get_section_bfd_owner (section
);
18050 const gdb_byte
*abbrev_ptr
;
18051 struct abbrev_info
*cur_abbrev
;
18052 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18053 unsigned int abbrev_form
;
18054 struct attr_abbrev
*cur_attrs
;
18055 unsigned int allocated_attrs
;
18057 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18059 dwarf2_read_section (objfile
, section
);
18060 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18061 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18062 abbrev_ptr
+= bytes_read
;
18064 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18065 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18067 /* Loop until we reach an abbrev number of 0. */
18068 while (abbrev_number
)
18070 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18072 /* read in abbrev header */
18073 cur_abbrev
->number
= abbrev_number
;
18075 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18076 abbrev_ptr
+= bytes_read
;
18077 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18080 /* now read in declarations */
18083 LONGEST implicit_const
;
18085 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18086 abbrev_ptr
+= bytes_read
;
18087 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18088 abbrev_ptr
+= bytes_read
;
18089 if (abbrev_form
== DW_FORM_implicit_const
)
18091 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18093 abbrev_ptr
+= bytes_read
;
18097 /* Initialize it due to a false compiler warning. */
18098 implicit_const
= -1;
18101 if (abbrev_name
== 0)
18104 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18106 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18108 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18111 cur_attrs
[cur_abbrev
->num_attrs
].name
18112 = (enum dwarf_attribute
) abbrev_name
;
18113 cur_attrs
[cur_abbrev
->num_attrs
].form
18114 = (enum dwarf_form
) abbrev_form
;
18115 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18116 ++cur_abbrev
->num_attrs
;
18119 cur_abbrev
->attrs
=
18120 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18121 cur_abbrev
->num_attrs
);
18122 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18123 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18125 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18127 /* Get next abbreviation.
18128 Under Irix6 the abbreviations for a compilation unit are not
18129 always properly terminated with an abbrev number of 0.
18130 Exit loop if we encounter an abbreviation which we have
18131 already read (which means we are about to read the abbreviations
18132 for the next compile unit) or if the end of the abbreviation
18133 table is reached. */
18134 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18136 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18137 abbrev_ptr
+= bytes_read
;
18138 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18143 return abbrev_table
;
18146 /* Returns nonzero if TAG represents a type that we might generate a partial
18150 is_type_tag_for_partial (int tag
)
18155 /* Some types that would be reasonable to generate partial symbols for,
18156 that we don't at present. */
18157 case DW_TAG_array_type
:
18158 case DW_TAG_file_type
:
18159 case DW_TAG_ptr_to_member_type
:
18160 case DW_TAG_set_type
:
18161 case DW_TAG_string_type
:
18162 case DW_TAG_subroutine_type
:
18164 case DW_TAG_base_type
:
18165 case DW_TAG_class_type
:
18166 case DW_TAG_interface_type
:
18167 case DW_TAG_enumeration_type
:
18168 case DW_TAG_structure_type
:
18169 case DW_TAG_subrange_type
:
18170 case DW_TAG_typedef
:
18171 case DW_TAG_union_type
:
18178 /* Load all DIEs that are interesting for partial symbols into memory. */
18180 static struct partial_die_info
*
18181 load_partial_dies (const struct die_reader_specs
*reader
,
18182 const gdb_byte
*info_ptr
, int building_psymtab
)
18184 struct dwarf2_cu
*cu
= reader
->cu
;
18185 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18186 struct partial_die_info
*part_die
;
18187 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18188 unsigned int bytes_read
;
18189 unsigned int load_all
= 0;
18190 int nesting_level
= 1;
18195 gdb_assert (cu
->per_cu
!= NULL
);
18196 if (cu
->per_cu
->load_all_dies
)
18200 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18204 &cu
->comp_unit_obstack
,
18205 hashtab_obstack_allocate
,
18206 dummy_obstack_deallocate
);
18208 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
18212 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18214 /* A NULL abbrev means the end of a series of children. */
18215 if (abbrev
== NULL
)
18217 if (--nesting_level
== 0)
18219 /* PART_DIE was probably the last thing allocated on the
18220 comp_unit_obstack, so we could call obstack_free
18221 here. We don't do that because the waste is small,
18222 and will be cleaned up when we're done with this
18223 compilation unit. This way, we're also more robust
18224 against other users of the comp_unit_obstack. */
18227 info_ptr
+= bytes_read
;
18228 last_die
= parent_die
;
18229 parent_die
= parent_die
->die_parent
;
18233 /* Check for template arguments. We never save these; if
18234 they're seen, we just mark the parent, and go on our way. */
18235 if (parent_die
!= NULL
18236 && cu
->language
== language_cplus
18237 && (abbrev
->tag
== DW_TAG_template_type_param
18238 || abbrev
->tag
== DW_TAG_template_value_param
))
18240 parent_die
->has_template_arguments
= 1;
18244 /* We don't need a partial DIE for the template argument. */
18245 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18250 /* We only recurse into c++ subprograms looking for template arguments.
18251 Skip their other children. */
18253 && cu
->language
== language_cplus
18254 && parent_die
!= NULL
18255 && parent_die
->tag
== DW_TAG_subprogram
)
18257 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18261 /* Check whether this DIE is interesting enough to save. Normally
18262 we would not be interested in members here, but there may be
18263 later variables referencing them via DW_AT_specification (for
18264 static members). */
18266 && !is_type_tag_for_partial (abbrev
->tag
)
18267 && abbrev
->tag
!= DW_TAG_constant
18268 && abbrev
->tag
!= DW_TAG_enumerator
18269 && abbrev
->tag
!= DW_TAG_subprogram
18270 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18271 && abbrev
->tag
!= DW_TAG_lexical_block
18272 && abbrev
->tag
!= DW_TAG_variable
18273 && abbrev
->tag
!= DW_TAG_namespace
18274 && abbrev
->tag
!= DW_TAG_module
18275 && abbrev
->tag
!= DW_TAG_member
18276 && abbrev
->tag
!= DW_TAG_imported_unit
18277 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18279 /* Otherwise we skip to the next sibling, if any. */
18280 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18284 info_ptr
= read_partial_die (reader
, part_die
, abbrev
, bytes_read
,
18287 /* This two-pass algorithm for processing partial symbols has a
18288 high cost in cache pressure. Thus, handle some simple cases
18289 here which cover the majority of C partial symbols. DIEs
18290 which neither have specification tags in them, nor could have
18291 specification tags elsewhere pointing at them, can simply be
18292 processed and discarded.
18294 This segment is also optional; scan_partial_symbols and
18295 add_partial_symbol will handle these DIEs if we chain
18296 them in normally. When compilers which do not emit large
18297 quantities of duplicate debug information are more common,
18298 this code can probably be removed. */
18300 /* Any complete simple types at the top level (pretty much all
18301 of them, for a language without namespaces), can be processed
18303 if (parent_die
== NULL
18304 && part_die
->has_specification
== 0
18305 && part_die
->is_declaration
== 0
18306 && ((part_die
->tag
== DW_TAG_typedef
&& !part_die
->has_children
)
18307 || part_die
->tag
== DW_TAG_base_type
18308 || part_die
->tag
== DW_TAG_subrange_type
))
18310 if (building_psymtab
&& part_die
->name
!= NULL
)
18311 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
18312 VAR_DOMAIN
, LOC_TYPEDEF
,
18313 &objfile
->static_psymbols
,
18314 0, cu
->language
, objfile
);
18315 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
18319 /* The exception for DW_TAG_typedef with has_children above is
18320 a workaround of GCC PR debug/47510. In the case of this complaint
18321 type_name_no_tag_or_error will error on such types later.
18323 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18324 it could not find the child DIEs referenced later, this is checked
18325 above. In correct DWARF DW_TAG_typedef should have no children. */
18327 if (part_die
->tag
== DW_TAG_typedef
&& part_die
->has_children
)
18328 complaint (&symfile_complaints
,
18329 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18330 "- DIE at 0x%x [in module %s]"),
18331 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
18333 /* If we're at the second level, and we're an enumerator, and
18334 our parent has no specification (meaning possibly lives in a
18335 namespace elsewhere), then we can add the partial symbol now
18336 instead of queueing it. */
18337 if (part_die
->tag
== DW_TAG_enumerator
18338 && parent_die
!= NULL
18339 && parent_die
->die_parent
== NULL
18340 && parent_die
->tag
== DW_TAG_enumeration_type
18341 && parent_die
->has_specification
== 0)
18343 if (part_die
->name
== NULL
)
18344 complaint (&symfile_complaints
,
18345 _("malformed enumerator DIE ignored"));
18346 else if (building_psymtab
)
18347 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
18348 VAR_DOMAIN
, LOC_CONST
,
18349 cu
->language
== language_cplus
18350 ? &objfile
->global_psymbols
18351 : &objfile
->static_psymbols
,
18352 0, cu
->language
, objfile
);
18354 info_ptr
= locate_pdi_sibling (reader
, part_die
, info_ptr
);
18358 /* We'll save this DIE so link it in. */
18359 part_die
->die_parent
= parent_die
;
18360 part_die
->die_sibling
= NULL
;
18361 part_die
->die_child
= NULL
;
18363 if (last_die
&& last_die
== parent_die
)
18364 last_die
->die_child
= part_die
;
18366 last_die
->die_sibling
= part_die
;
18368 last_die
= part_die
;
18370 if (first_die
== NULL
)
18371 first_die
= part_die
;
18373 /* Maybe add the DIE to the hash table. Not all DIEs that we
18374 find interesting need to be in the hash table, because we
18375 also have the parent/sibling/child chains; only those that we
18376 might refer to by offset later during partial symbol reading.
18378 For now this means things that might have be the target of a
18379 DW_AT_specification, DW_AT_abstract_origin, or
18380 DW_AT_extension. DW_AT_extension will refer only to
18381 namespaces; DW_AT_abstract_origin refers to functions (and
18382 many things under the function DIE, but we do not recurse
18383 into function DIEs during partial symbol reading) and
18384 possibly variables as well; DW_AT_specification refers to
18385 declarations. Declarations ought to have the DW_AT_declaration
18386 flag. It happens that GCC forgets to put it in sometimes, but
18387 only for functions, not for types.
18389 Adding more things than necessary to the hash table is harmless
18390 except for the performance cost. Adding too few will result in
18391 wasted time in find_partial_die, when we reread the compilation
18392 unit with load_all_dies set. */
18395 || abbrev
->tag
== DW_TAG_constant
18396 || abbrev
->tag
== DW_TAG_subprogram
18397 || abbrev
->tag
== DW_TAG_variable
18398 || abbrev
->tag
== DW_TAG_namespace
18399 || part_die
->is_declaration
)
18403 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18404 to_underlying (part_die
->sect_off
),
18409 part_die
= XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
18411 /* For some DIEs we want to follow their children (if any). For C
18412 we have no reason to follow the children of structures; for other
18413 languages we have to, so that we can get at method physnames
18414 to infer fully qualified class names, for DW_AT_specification,
18415 and for C++ template arguments. For C++, we also look one level
18416 inside functions to find template arguments (if the name of the
18417 function does not already contain the template arguments).
18419 For Ada, we need to scan the children of subprograms and lexical
18420 blocks as well because Ada allows the definition of nested
18421 entities that could be interesting for the debugger, such as
18422 nested subprograms for instance. */
18423 if (last_die
->has_children
18425 || last_die
->tag
== DW_TAG_namespace
18426 || last_die
->tag
== DW_TAG_module
18427 || last_die
->tag
== DW_TAG_enumeration_type
18428 || (cu
->language
== language_cplus
18429 && last_die
->tag
== DW_TAG_subprogram
18430 && (last_die
->name
== NULL
18431 || strchr (last_die
->name
, '<') == NULL
))
18432 || (cu
->language
!= language_c
18433 && (last_die
->tag
== DW_TAG_class_type
18434 || last_die
->tag
== DW_TAG_interface_type
18435 || last_die
->tag
== DW_TAG_structure_type
18436 || last_die
->tag
== DW_TAG_union_type
))
18437 || (cu
->language
== language_ada
18438 && (last_die
->tag
== DW_TAG_subprogram
18439 || last_die
->tag
== DW_TAG_lexical_block
))))
18442 parent_die
= last_die
;
18446 /* Otherwise we skip to the next sibling, if any. */
18447 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18449 /* Back to the top, do it again. */
18453 /* Read a minimal amount of information into the minimal die structure. */
18455 static const gdb_byte
*
18456 read_partial_die (const struct die_reader_specs
*reader
,
18457 struct partial_die_info
*part_die
,
18458 struct abbrev_info
*abbrev
, unsigned int abbrev_len
,
18459 const gdb_byte
*info_ptr
)
18461 struct dwarf2_cu
*cu
= reader
->cu
;
18462 struct dwarf2_per_objfile
*dwarf2_per_objfile
18463 = cu
->per_cu
->dwarf2_per_objfile
;
18464 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18465 const gdb_byte
*buffer
= reader
->buffer
;
18467 struct attribute attr
;
18468 int has_low_pc_attr
= 0;
18469 int has_high_pc_attr
= 0;
18470 int high_pc_relative
= 0;
18472 memset (part_die
, 0, sizeof (struct partial_die_info
));
18474 part_die
->sect_off
= (sect_offset
) (info_ptr
- buffer
);
18476 info_ptr
+= abbrev_len
;
18478 if (abbrev
== NULL
)
18481 part_die
->tag
= abbrev
->tag
;
18482 part_die
->has_children
= abbrev
->has_children
;
18484 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18486 info_ptr
= read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
18488 /* Store the data if it is of an attribute we want to keep in a
18489 partial symbol table. */
18493 switch (part_die
->tag
)
18495 case DW_TAG_compile_unit
:
18496 case DW_TAG_partial_unit
:
18497 case DW_TAG_type_unit
:
18498 /* Compilation units have a DW_AT_name that is a filename, not
18499 a source language identifier. */
18500 case DW_TAG_enumeration_type
:
18501 case DW_TAG_enumerator
:
18502 /* These tags always have simple identifiers already; no need
18503 to canonicalize them. */
18504 part_die
->name
= DW_STRING (&attr
);
18508 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18509 &objfile
->per_bfd
->storage_obstack
);
18513 case DW_AT_linkage_name
:
18514 case DW_AT_MIPS_linkage_name
:
18515 /* Note that both forms of linkage name might appear. We
18516 assume they will be the same, and we only store the last
18518 if (cu
->language
== language_ada
)
18519 part_die
->name
= DW_STRING (&attr
);
18520 part_die
->linkage_name
= DW_STRING (&attr
);
18523 has_low_pc_attr
= 1;
18524 part_die
->lowpc
= attr_value_as_address (&attr
);
18526 case DW_AT_high_pc
:
18527 has_high_pc_attr
= 1;
18528 part_die
->highpc
= attr_value_as_address (&attr
);
18529 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18530 high_pc_relative
= 1;
18532 case DW_AT_location
:
18533 /* Support the .debug_loc offsets. */
18534 if (attr_form_is_block (&attr
))
18536 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
18538 else if (attr_form_is_section_offset (&attr
))
18540 dwarf2_complex_location_expr_complaint ();
18544 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18545 "partial symbol information");
18548 case DW_AT_external
:
18549 part_die
->is_external
= DW_UNSND (&attr
);
18551 case DW_AT_declaration
:
18552 part_die
->is_declaration
= DW_UNSND (&attr
);
18555 part_die
->has_type
= 1;
18557 case DW_AT_abstract_origin
:
18558 case DW_AT_specification
:
18559 case DW_AT_extension
:
18560 part_die
->has_specification
= 1;
18561 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18562 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18563 || cu
->per_cu
->is_dwz
);
18565 case DW_AT_sibling
:
18566 /* Ignore absolute siblings, they might point outside of
18567 the current compile unit. */
18568 if (attr
.form
== DW_FORM_ref_addr
)
18569 complaint (&symfile_complaints
,
18570 _("ignoring absolute DW_AT_sibling"));
18573 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18574 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18576 if (sibling_ptr
< info_ptr
)
18577 complaint (&symfile_complaints
,
18578 _("DW_AT_sibling points backwards"));
18579 else if (sibling_ptr
> reader
->buffer_end
)
18580 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18582 part_die
->sibling
= sibling_ptr
;
18585 case DW_AT_byte_size
:
18586 part_die
->has_byte_size
= 1;
18588 case DW_AT_const_value
:
18589 part_die
->has_const_value
= 1;
18591 case DW_AT_calling_convention
:
18592 /* DWARF doesn't provide a way to identify a program's source-level
18593 entry point. DW_AT_calling_convention attributes are only meant
18594 to describe functions' calling conventions.
18596 However, because it's a necessary piece of information in
18597 Fortran, and before DWARF 4 DW_CC_program was the only
18598 piece of debugging information whose definition refers to
18599 a 'main program' at all, several compilers marked Fortran
18600 main programs with DW_CC_program --- even when those
18601 functions use the standard calling conventions.
18603 Although DWARF now specifies a way to provide this
18604 information, we support this practice for backward
18606 if (DW_UNSND (&attr
) == DW_CC_program
18607 && cu
->language
== language_fortran
)
18608 part_die
->main_subprogram
= 1;
18611 if (DW_UNSND (&attr
) == DW_INL_inlined
18612 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18613 part_die
->may_be_inlined
= 1;
18617 if (part_die
->tag
== DW_TAG_imported_unit
)
18619 part_die
->d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18620 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18621 || cu
->per_cu
->is_dwz
);
18625 case DW_AT_main_subprogram
:
18626 part_die
->main_subprogram
= DW_UNSND (&attr
);
18634 if (high_pc_relative
)
18635 part_die
->highpc
+= part_die
->lowpc
;
18637 if (has_low_pc_attr
&& has_high_pc_attr
)
18639 /* When using the GNU linker, .gnu.linkonce. sections are used to
18640 eliminate duplicate copies of functions and vtables and such.
18641 The linker will arbitrarily choose one and discard the others.
18642 The AT_*_pc values for such functions refer to local labels in
18643 these sections. If the section from that file was discarded, the
18644 labels are not in the output, so the relocs get a value of 0.
18645 If this is a discarded function, mark the pc bounds as invalid,
18646 so that GDB will ignore it. */
18647 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18649 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18651 complaint (&symfile_complaints
,
18652 _("DW_AT_low_pc %s is zero "
18653 "for DIE at 0x%x [in module %s]"),
18654 paddress (gdbarch
, part_die
->lowpc
),
18655 to_underlying (part_die
->sect_off
), objfile_name (objfile
));
18657 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18658 else if (part_die
->lowpc
>= part_die
->highpc
)
18660 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18662 complaint (&symfile_complaints
,
18663 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18664 "for DIE at 0x%x [in module %s]"),
18665 paddress (gdbarch
, part_die
->lowpc
),
18666 paddress (gdbarch
, part_die
->highpc
),
18667 to_underlying (part_die
->sect_off
),
18668 objfile_name (objfile
));
18671 part_die
->has_pc_info
= 1;
18677 /* Find a cached partial DIE at OFFSET in CU. */
18679 static struct partial_die_info
*
18680 find_partial_die_in_comp_unit (sect_offset sect_off
, struct dwarf2_cu
*cu
)
18682 struct partial_die_info
*lookup_die
= NULL
;
18683 struct partial_die_info part_die
;
18685 part_die
.sect_off
= sect_off
;
18686 lookup_die
= ((struct partial_die_info
*)
18687 htab_find_with_hash (cu
->partial_dies
, &part_die
,
18688 to_underlying (sect_off
)));
18693 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18694 except in the case of .debug_types DIEs which do not reference
18695 outside their CU (they do however referencing other types via
18696 DW_FORM_ref_sig8). */
18698 static struct partial_die_info
*
18699 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18701 struct dwarf2_per_objfile
*dwarf2_per_objfile
18702 = cu
->per_cu
->dwarf2_per_objfile
;
18703 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18704 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18705 struct partial_die_info
*pd
= NULL
;
18707 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18708 && offset_in_cu_p (&cu
->header
, sect_off
))
18710 pd
= find_partial_die_in_comp_unit (sect_off
, cu
);
18713 /* We missed recording what we needed.
18714 Load all dies and try again. */
18715 per_cu
= cu
->per_cu
;
18719 /* TUs don't reference other CUs/TUs (except via type signatures). */
18720 if (cu
->per_cu
->is_debug_types
)
18722 error (_("Dwarf Error: Type Unit at offset 0x%x contains"
18723 " external reference to offset 0x%x [in module %s].\n"),
18724 to_underlying (cu
->header
.sect_off
), to_underlying (sect_off
),
18725 bfd_get_filename (objfile
->obfd
));
18727 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18728 dwarf2_per_objfile
);
18730 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18731 load_partial_comp_unit (per_cu
);
18733 per_cu
->cu
->last_used
= 0;
18734 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
18737 /* If we didn't find it, and not all dies have been loaded,
18738 load them all and try again. */
18740 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18742 per_cu
->load_all_dies
= 1;
18744 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18745 THIS_CU->cu may already be in use. So we can't just free it and
18746 replace its DIEs with the ones we read in. Instead, we leave those
18747 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18748 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18750 load_partial_comp_unit (per_cu
);
18752 pd
= find_partial_die_in_comp_unit (sect_off
, per_cu
->cu
);
18756 internal_error (__FILE__
, __LINE__
,
18757 _("could not find partial DIE 0x%x "
18758 "in cache [from module %s]\n"),
18759 to_underlying (sect_off
), bfd_get_filename (objfile
->obfd
));
18763 /* See if we can figure out if the class lives in a namespace. We do
18764 this by looking for a member function; its demangled name will
18765 contain namespace info, if there is any. */
18768 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18769 struct dwarf2_cu
*cu
)
18771 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18772 what template types look like, because the demangler
18773 frequently doesn't give the same name as the debug info. We
18774 could fix this by only using the demangled name to get the
18775 prefix (but see comment in read_structure_type). */
18777 struct partial_die_info
*real_pdi
;
18778 struct partial_die_info
*child_pdi
;
18780 /* If this DIE (this DIE's specification, if any) has a parent, then
18781 we should not do this. We'll prepend the parent's fully qualified
18782 name when we create the partial symbol. */
18784 real_pdi
= struct_pdi
;
18785 while (real_pdi
->has_specification
)
18786 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18787 real_pdi
->spec_is_dwz
, cu
);
18789 if (real_pdi
->die_parent
!= NULL
)
18792 for (child_pdi
= struct_pdi
->die_child
;
18794 child_pdi
= child_pdi
->die_sibling
)
18796 if (child_pdi
->tag
== DW_TAG_subprogram
18797 && child_pdi
->linkage_name
!= NULL
)
18799 char *actual_class_name
18800 = language_class_name_from_physname (cu
->language_defn
,
18801 child_pdi
->linkage_name
);
18802 if (actual_class_name
!= NULL
)
18804 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18807 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18809 strlen (actual_class_name
)));
18810 xfree (actual_class_name
);
18817 /* Adjust PART_DIE before generating a symbol for it. This function
18818 may set the is_external flag or change the DIE's name. */
18821 fixup_partial_die (struct partial_die_info
*part_die
,
18822 struct dwarf2_cu
*cu
)
18824 /* Once we've fixed up a die, there's no point in doing so again.
18825 This also avoids a memory leak if we were to call
18826 guess_partial_die_structure_name multiple times. */
18827 if (part_die
->fixup_called
)
18830 /* If we found a reference attribute and the DIE has no name, try
18831 to find a name in the referred to DIE. */
18833 if (part_die
->name
== NULL
&& part_die
->has_specification
)
18835 struct partial_die_info
*spec_die
;
18837 spec_die
= find_partial_die (part_die
->spec_offset
,
18838 part_die
->spec_is_dwz
, cu
);
18840 fixup_partial_die (spec_die
, cu
);
18842 if (spec_die
->name
)
18844 part_die
->name
= spec_die
->name
;
18846 /* Copy DW_AT_external attribute if it is set. */
18847 if (spec_die
->is_external
)
18848 part_die
->is_external
= spec_die
->is_external
;
18852 /* Set default names for some unnamed DIEs. */
18854 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
18855 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
18857 /* If there is no parent die to provide a namespace, and there are
18858 children, see if we can determine the namespace from their linkage
18860 if (cu
->language
== language_cplus
18861 && !VEC_empty (dwarf2_section_info_def
,
18862 cu
->per_cu
->dwarf2_per_objfile
->types
)
18863 && part_die
->die_parent
== NULL
18864 && part_die
->has_children
18865 && (part_die
->tag
== DW_TAG_class_type
18866 || part_die
->tag
== DW_TAG_structure_type
18867 || part_die
->tag
== DW_TAG_union_type
))
18868 guess_partial_die_structure_name (part_die
, cu
);
18870 /* GCC might emit a nameless struct or union that has a linkage
18871 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18872 if (part_die
->name
== NULL
18873 && (part_die
->tag
== DW_TAG_class_type
18874 || part_die
->tag
== DW_TAG_interface_type
18875 || part_die
->tag
== DW_TAG_structure_type
18876 || part_die
->tag
== DW_TAG_union_type
)
18877 && part_die
->linkage_name
!= NULL
)
18881 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
18886 /* Strip any leading namespaces/classes, keep only the base name.
18887 DW_AT_name for named DIEs does not contain the prefixes. */
18888 base
= strrchr (demangled
, ':');
18889 if (base
&& base
> demangled
&& base
[-1] == ':')
18894 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18897 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18898 base
, strlen (base
)));
18903 part_die
->fixup_called
= 1;
18906 /* Read an attribute value described by an attribute form. */
18908 static const gdb_byte
*
18909 read_attribute_value (const struct die_reader_specs
*reader
,
18910 struct attribute
*attr
, unsigned form
,
18911 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
18913 struct dwarf2_cu
*cu
= reader
->cu
;
18914 struct dwarf2_per_objfile
*dwarf2_per_objfile
18915 = cu
->per_cu
->dwarf2_per_objfile
;
18916 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18917 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18918 bfd
*abfd
= reader
->abfd
;
18919 struct comp_unit_head
*cu_header
= &cu
->header
;
18920 unsigned int bytes_read
;
18921 struct dwarf_block
*blk
;
18923 attr
->form
= (enum dwarf_form
) form
;
18926 case DW_FORM_ref_addr
:
18927 if (cu
->header
.version
== 2)
18928 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18930 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18931 &cu
->header
, &bytes_read
);
18932 info_ptr
+= bytes_read
;
18934 case DW_FORM_GNU_ref_alt
:
18935 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18936 info_ptr
+= bytes_read
;
18939 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18940 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18941 info_ptr
+= bytes_read
;
18943 case DW_FORM_block2
:
18944 blk
= dwarf_alloc_block (cu
);
18945 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18947 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18948 info_ptr
+= blk
->size
;
18949 DW_BLOCK (attr
) = blk
;
18951 case DW_FORM_block4
:
18952 blk
= dwarf_alloc_block (cu
);
18953 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18955 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18956 info_ptr
+= blk
->size
;
18957 DW_BLOCK (attr
) = blk
;
18959 case DW_FORM_data2
:
18960 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18963 case DW_FORM_data4
:
18964 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18967 case DW_FORM_data8
:
18968 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18971 case DW_FORM_data16
:
18972 blk
= dwarf_alloc_block (cu
);
18974 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18976 DW_BLOCK (attr
) = blk
;
18978 case DW_FORM_sec_offset
:
18979 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18980 info_ptr
+= bytes_read
;
18982 case DW_FORM_string
:
18983 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18984 DW_STRING_IS_CANONICAL (attr
) = 0;
18985 info_ptr
+= bytes_read
;
18988 if (!cu
->per_cu
->is_dwz
)
18990 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18991 abfd
, info_ptr
, cu_header
,
18993 DW_STRING_IS_CANONICAL (attr
) = 0;
18994 info_ptr
+= bytes_read
;
18998 case DW_FORM_line_strp
:
18999 if (!cu
->per_cu
->is_dwz
)
19001 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19003 cu_header
, &bytes_read
);
19004 DW_STRING_IS_CANONICAL (attr
) = 0;
19005 info_ptr
+= bytes_read
;
19009 case DW_FORM_GNU_strp_alt
:
19011 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19012 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19015 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19017 DW_STRING_IS_CANONICAL (attr
) = 0;
19018 info_ptr
+= bytes_read
;
19021 case DW_FORM_exprloc
:
19022 case DW_FORM_block
:
19023 blk
= dwarf_alloc_block (cu
);
19024 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19025 info_ptr
+= bytes_read
;
19026 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19027 info_ptr
+= blk
->size
;
19028 DW_BLOCK (attr
) = blk
;
19030 case DW_FORM_block1
:
19031 blk
= dwarf_alloc_block (cu
);
19032 blk
->size
= read_1_byte (abfd
, info_ptr
);
19034 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19035 info_ptr
+= blk
->size
;
19036 DW_BLOCK (attr
) = blk
;
19038 case DW_FORM_data1
:
19039 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19043 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19046 case DW_FORM_flag_present
:
19047 DW_UNSND (attr
) = 1;
19049 case DW_FORM_sdata
:
19050 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19051 info_ptr
+= bytes_read
;
19053 case DW_FORM_udata
:
19054 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19055 info_ptr
+= bytes_read
;
19058 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19059 + read_1_byte (abfd
, info_ptr
));
19063 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19064 + read_2_bytes (abfd
, info_ptr
));
19068 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19069 + read_4_bytes (abfd
, info_ptr
));
19073 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19074 + read_8_bytes (abfd
, info_ptr
));
19077 case DW_FORM_ref_sig8
:
19078 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19081 case DW_FORM_ref_udata
:
19082 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19083 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19084 info_ptr
+= bytes_read
;
19086 case DW_FORM_indirect
:
19087 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19088 info_ptr
+= bytes_read
;
19089 if (form
== DW_FORM_implicit_const
)
19091 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19092 info_ptr
+= bytes_read
;
19094 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19097 case DW_FORM_implicit_const
:
19098 DW_SND (attr
) = implicit_const
;
19100 case DW_FORM_GNU_addr_index
:
19101 if (reader
->dwo_file
== NULL
)
19103 /* For now flag a hard error.
19104 Later we can turn this into a complaint. */
19105 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19106 dwarf_form_name (form
),
19107 bfd_get_filename (abfd
));
19109 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19110 info_ptr
+= bytes_read
;
19112 case DW_FORM_GNU_str_index
:
19113 if (reader
->dwo_file
== NULL
)
19115 /* For now flag a hard error.
19116 Later we can turn this into a complaint if warranted. */
19117 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19118 dwarf_form_name (form
),
19119 bfd_get_filename (abfd
));
19122 ULONGEST str_index
=
19123 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19125 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19126 DW_STRING_IS_CANONICAL (attr
) = 0;
19127 info_ptr
+= bytes_read
;
19131 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19132 dwarf_form_name (form
),
19133 bfd_get_filename (abfd
));
19137 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19138 attr
->form
= DW_FORM_GNU_ref_alt
;
19140 /* We have seen instances where the compiler tried to emit a byte
19141 size attribute of -1 which ended up being encoded as an unsigned
19142 0xffffffff. Although 0xffffffff is technically a valid size value,
19143 an object of this size seems pretty unlikely so we can relatively
19144 safely treat these cases as if the size attribute was invalid and
19145 treat them as zero by default. */
19146 if (attr
->name
== DW_AT_byte_size
19147 && form
== DW_FORM_data4
19148 && DW_UNSND (attr
) >= 0xffffffff)
19151 (&symfile_complaints
,
19152 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19153 hex_string (DW_UNSND (attr
)));
19154 DW_UNSND (attr
) = 0;
19160 /* Read an attribute described by an abbreviated attribute. */
19162 static const gdb_byte
*
19163 read_attribute (const struct die_reader_specs
*reader
,
19164 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19165 const gdb_byte
*info_ptr
)
19167 attr
->name
= abbrev
->name
;
19168 return read_attribute_value (reader
, attr
, abbrev
->form
,
19169 abbrev
->implicit_const
, info_ptr
);
19172 /* Read dwarf information from a buffer. */
19174 static unsigned int
19175 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19177 return bfd_get_8 (abfd
, buf
);
19181 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19183 return bfd_get_signed_8 (abfd
, buf
);
19186 static unsigned int
19187 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19189 return bfd_get_16 (abfd
, buf
);
19193 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19195 return bfd_get_signed_16 (abfd
, buf
);
19198 static unsigned int
19199 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19201 return bfd_get_32 (abfd
, buf
);
19205 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19207 return bfd_get_signed_32 (abfd
, buf
);
19211 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19213 return bfd_get_64 (abfd
, buf
);
19217 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19218 unsigned int *bytes_read
)
19220 struct comp_unit_head
*cu_header
= &cu
->header
;
19221 CORE_ADDR retval
= 0;
19223 if (cu_header
->signed_addr_p
)
19225 switch (cu_header
->addr_size
)
19228 retval
= bfd_get_signed_16 (abfd
, buf
);
19231 retval
= bfd_get_signed_32 (abfd
, buf
);
19234 retval
= bfd_get_signed_64 (abfd
, buf
);
19237 internal_error (__FILE__
, __LINE__
,
19238 _("read_address: bad switch, signed [in module %s]"),
19239 bfd_get_filename (abfd
));
19244 switch (cu_header
->addr_size
)
19247 retval
= bfd_get_16 (abfd
, buf
);
19250 retval
= bfd_get_32 (abfd
, buf
);
19253 retval
= bfd_get_64 (abfd
, buf
);
19256 internal_error (__FILE__
, __LINE__
,
19257 _("read_address: bad switch, "
19258 "unsigned [in module %s]"),
19259 bfd_get_filename (abfd
));
19263 *bytes_read
= cu_header
->addr_size
;
19267 /* Read the initial length from a section. The (draft) DWARF 3
19268 specification allows the initial length to take up either 4 bytes
19269 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19270 bytes describe the length and all offsets will be 8 bytes in length
19273 An older, non-standard 64-bit format is also handled by this
19274 function. The older format in question stores the initial length
19275 as an 8-byte quantity without an escape value. Lengths greater
19276 than 2^32 aren't very common which means that the initial 4 bytes
19277 is almost always zero. Since a length value of zero doesn't make
19278 sense for the 32-bit format, this initial zero can be considered to
19279 be an escape value which indicates the presence of the older 64-bit
19280 format. As written, the code can't detect (old format) lengths
19281 greater than 4GB. If it becomes necessary to handle lengths
19282 somewhat larger than 4GB, we could allow other small values (such
19283 as the non-sensical values of 1, 2, and 3) to also be used as
19284 escape values indicating the presence of the old format.
19286 The value returned via bytes_read should be used to increment the
19287 relevant pointer after calling read_initial_length().
19289 [ Note: read_initial_length() and read_offset() are based on the
19290 document entitled "DWARF Debugging Information Format", revision
19291 3, draft 8, dated November 19, 2001. This document was obtained
19294 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19296 This document is only a draft and is subject to change. (So beware.)
19298 Details regarding the older, non-standard 64-bit format were
19299 determined empirically by examining 64-bit ELF files produced by
19300 the SGI toolchain on an IRIX 6.5 machine.
19302 - Kevin, July 16, 2002
19306 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19308 LONGEST length
= bfd_get_32 (abfd
, buf
);
19310 if (length
== 0xffffffff)
19312 length
= bfd_get_64 (abfd
, buf
+ 4);
19315 else if (length
== 0)
19317 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19318 length
= bfd_get_64 (abfd
, buf
);
19329 /* Cover function for read_initial_length.
19330 Returns the length of the object at BUF, and stores the size of the
19331 initial length in *BYTES_READ and stores the size that offsets will be in
19333 If the initial length size is not equivalent to that specified in
19334 CU_HEADER then issue a complaint.
19335 This is useful when reading non-comp-unit headers. */
19338 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19339 const struct comp_unit_head
*cu_header
,
19340 unsigned int *bytes_read
,
19341 unsigned int *offset_size
)
19343 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19345 gdb_assert (cu_header
->initial_length_size
== 4
19346 || cu_header
->initial_length_size
== 8
19347 || cu_header
->initial_length_size
== 12);
19349 if (cu_header
->initial_length_size
!= *bytes_read
)
19350 complaint (&symfile_complaints
,
19351 _("intermixed 32-bit and 64-bit DWARF sections"));
19353 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19357 /* Read an offset from the data stream. The size of the offset is
19358 given by cu_header->offset_size. */
19361 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19362 const struct comp_unit_head
*cu_header
,
19363 unsigned int *bytes_read
)
19365 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19367 *bytes_read
= cu_header
->offset_size
;
19371 /* Read an offset from the data stream. */
19374 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19376 LONGEST retval
= 0;
19378 switch (offset_size
)
19381 retval
= bfd_get_32 (abfd
, buf
);
19384 retval
= bfd_get_64 (abfd
, buf
);
19387 internal_error (__FILE__
, __LINE__
,
19388 _("read_offset_1: bad switch [in module %s]"),
19389 bfd_get_filename (abfd
));
19395 static const gdb_byte
*
19396 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19398 /* If the size of a host char is 8 bits, we can return a pointer
19399 to the buffer, otherwise we have to copy the data to a buffer
19400 allocated on the temporary obstack. */
19401 gdb_assert (HOST_CHAR_BIT
== 8);
19405 static const char *
19406 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19407 unsigned int *bytes_read_ptr
)
19409 /* If the size of a host char is 8 bits, we can return a pointer
19410 to the string, otherwise we have to copy the string to a buffer
19411 allocated on the temporary obstack. */
19412 gdb_assert (HOST_CHAR_BIT
== 8);
19415 *bytes_read_ptr
= 1;
19418 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19419 return (const char *) buf
;
19422 /* Return pointer to string at section SECT offset STR_OFFSET with error
19423 reporting strings FORM_NAME and SECT_NAME. */
19425 static const char *
19426 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19427 bfd
*abfd
, LONGEST str_offset
,
19428 struct dwarf2_section_info
*sect
,
19429 const char *form_name
,
19430 const char *sect_name
)
19432 dwarf2_read_section (objfile
, sect
);
19433 if (sect
->buffer
== NULL
)
19434 error (_("%s used without %s section [in module %s]"),
19435 form_name
, sect_name
, bfd_get_filename (abfd
));
19436 if (str_offset
>= sect
->size
)
19437 error (_("%s pointing outside of %s section [in module %s]"),
19438 form_name
, sect_name
, bfd_get_filename (abfd
));
19439 gdb_assert (HOST_CHAR_BIT
== 8);
19440 if (sect
->buffer
[str_offset
] == '\0')
19442 return (const char *) (sect
->buffer
+ str_offset
);
19445 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19447 static const char *
19448 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19449 bfd
*abfd
, LONGEST str_offset
)
19451 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19453 &dwarf2_per_objfile
->str
,
19454 "DW_FORM_strp", ".debug_str");
19457 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19459 static const char *
19460 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19461 bfd
*abfd
, LONGEST str_offset
)
19463 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19465 &dwarf2_per_objfile
->line_str
,
19466 "DW_FORM_line_strp",
19467 ".debug_line_str");
19470 /* Read a string at offset STR_OFFSET in the .debug_str section from
19471 the .dwz file DWZ. Throw an error if the offset is too large. If
19472 the string consists of a single NUL byte, return NULL; otherwise
19473 return a pointer to the string. */
19475 static const char *
19476 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19477 LONGEST str_offset
)
19479 dwarf2_read_section (objfile
, &dwz
->str
);
19481 if (dwz
->str
.buffer
== NULL
)
19482 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19483 "section [in module %s]"),
19484 bfd_get_filename (dwz
->dwz_bfd
));
19485 if (str_offset
>= dwz
->str
.size
)
19486 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19487 ".debug_str section [in module %s]"),
19488 bfd_get_filename (dwz
->dwz_bfd
));
19489 gdb_assert (HOST_CHAR_BIT
== 8);
19490 if (dwz
->str
.buffer
[str_offset
] == '\0')
19492 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19495 /* Return pointer to string at .debug_str offset as read from BUF.
19496 BUF is assumed to be in a compilation unit described by CU_HEADER.
19497 Return *BYTES_READ_PTR count of bytes read from BUF. */
19499 static const char *
19500 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19501 const gdb_byte
*buf
,
19502 const struct comp_unit_head
*cu_header
,
19503 unsigned int *bytes_read_ptr
)
19505 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19507 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19510 /* Return pointer to string at .debug_line_str offset as read from BUF.
19511 BUF is assumed to be in a compilation unit described by CU_HEADER.
19512 Return *BYTES_READ_PTR count of bytes read from BUF. */
19514 static const char *
19515 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19516 bfd
*abfd
, const gdb_byte
*buf
,
19517 const struct comp_unit_head
*cu_header
,
19518 unsigned int *bytes_read_ptr
)
19520 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19522 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19527 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19528 unsigned int *bytes_read_ptr
)
19531 unsigned int num_read
;
19533 unsigned char byte
;
19540 byte
= bfd_get_8 (abfd
, buf
);
19543 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19544 if ((byte
& 128) == 0)
19550 *bytes_read_ptr
= num_read
;
19555 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19556 unsigned int *bytes_read_ptr
)
19559 int shift
, num_read
;
19560 unsigned char byte
;
19567 byte
= bfd_get_8 (abfd
, buf
);
19570 result
|= ((LONGEST
) (byte
& 127) << shift
);
19572 if ((byte
& 128) == 0)
19577 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19578 result
|= -(((LONGEST
) 1) << shift
);
19579 *bytes_read_ptr
= num_read
;
19583 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19584 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19585 ADDR_SIZE is the size of addresses from the CU header. */
19588 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19589 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19591 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19592 bfd
*abfd
= objfile
->obfd
;
19593 const gdb_byte
*info_ptr
;
19595 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19596 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19597 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19598 objfile_name (objfile
));
19599 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19600 error (_("DW_FORM_addr_index pointing outside of "
19601 ".debug_addr section [in module %s]"),
19602 objfile_name (objfile
));
19603 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19604 + addr_base
+ addr_index
* addr_size
);
19605 if (addr_size
== 4)
19606 return bfd_get_32 (abfd
, info_ptr
);
19608 return bfd_get_64 (abfd
, info_ptr
);
19611 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19614 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19616 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19617 cu
->addr_base
, cu
->header
.addr_size
);
19620 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19623 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19624 unsigned int *bytes_read
)
19626 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19627 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19629 return read_addr_index (cu
, addr_index
);
19632 /* Data structure to pass results from dwarf2_read_addr_index_reader
19633 back to dwarf2_read_addr_index. */
19635 struct dwarf2_read_addr_index_data
19637 ULONGEST addr_base
;
19641 /* die_reader_func for dwarf2_read_addr_index. */
19644 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19645 const gdb_byte
*info_ptr
,
19646 struct die_info
*comp_unit_die
,
19650 struct dwarf2_cu
*cu
= reader
->cu
;
19651 struct dwarf2_read_addr_index_data
*aidata
=
19652 (struct dwarf2_read_addr_index_data
*) data
;
19654 aidata
->addr_base
= cu
->addr_base
;
19655 aidata
->addr_size
= cu
->header
.addr_size
;
19658 /* Given an index in .debug_addr, fetch the value.
19659 NOTE: This can be called during dwarf expression evaluation,
19660 long after the debug information has been read, and thus per_cu->cu
19661 may no longer exist. */
19664 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19665 unsigned int addr_index
)
19667 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19668 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19669 struct dwarf2_cu
*cu
= per_cu
->cu
;
19670 ULONGEST addr_base
;
19673 /* We need addr_base and addr_size.
19674 If we don't have PER_CU->cu, we have to get it.
19675 Nasty, but the alternative is storing the needed info in PER_CU,
19676 which at this point doesn't seem justified: it's not clear how frequently
19677 it would get used and it would increase the size of every PER_CU.
19678 Entry points like dwarf2_per_cu_addr_size do a similar thing
19679 so we're not in uncharted territory here.
19680 Alas we need to be a bit more complicated as addr_base is contained
19683 We don't need to read the entire CU(/TU).
19684 We just need the header and top level die.
19686 IWBN to use the aging mechanism to let us lazily later discard the CU.
19687 For now we skip this optimization. */
19691 addr_base
= cu
->addr_base
;
19692 addr_size
= cu
->header
.addr_size
;
19696 struct dwarf2_read_addr_index_data aidata
;
19698 /* Note: We can't use init_cutu_and_read_dies_simple here,
19699 we need addr_base. */
19700 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
19701 dwarf2_read_addr_index_reader
, &aidata
);
19702 addr_base
= aidata
.addr_base
;
19703 addr_size
= aidata
.addr_size
;
19706 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19710 /* Given a DW_FORM_GNU_str_index, fetch the string.
19711 This is only used by the Fission support. */
19713 static const char *
19714 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19716 struct dwarf2_cu
*cu
= reader
->cu
;
19717 struct dwarf2_per_objfile
*dwarf2_per_objfile
19718 = cu
->per_cu
->dwarf2_per_objfile
;
19719 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19720 const char *objf_name
= objfile_name (objfile
);
19721 bfd
*abfd
= objfile
->obfd
;
19722 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19723 struct dwarf2_section_info
*str_offsets_section
=
19724 &reader
->dwo_file
->sections
.str_offsets
;
19725 const gdb_byte
*info_ptr
;
19726 ULONGEST str_offset
;
19727 static const char form_name
[] = "DW_FORM_GNU_str_index";
19729 dwarf2_read_section (objfile
, str_section
);
19730 dwarf2_read_section (objfile
, str_offsets_section
);
19731 if (str_section
->buffer
== NULL
)
19732 error (_("%s used without .debug_str.dwo section"
19733 " in CU at offset 0x%x [in module %s]"),
19734 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
19735 if (str_offsets_section
->buffer
== NULL
)
19736 error (_("%s used without .debug_str_offsets.dwo section"
19737 " in CU at offset 0x%x [in module %s]"),
19738 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
19739 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19740 error (_("%s pointing outside of .debug_str_offsets.dwo"
19741 " section in CU at offset 0x%x [in module %s]"),
19742 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
19743 info_ptr
= (str_offsets_section
->buffer
19744 + str_index
* cu
->header
.offset_size
);
19745 if (cu
->header
.offset_size
== 4)
19746 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19748 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19749 if (str_offset
>= str_section
->size
)
19750 error (_("Offset from %s pointing outside of"
19751 " .debug_str.dwo section in CU at offset 0x%x [in module %s]"),
19752 form_name
, to_underlying (cu
->header
.sect_off
), objf_name
);
19753 return (const char *) (str_section
->buffer
+ str_offset
);
19756 /* Return the length of an LEB128 number in BUF. */
19759 leb128_size (const gdb_byte
*buf
)
19761 const gdb_byte
*begin
= buf
;
19767 if ((byte
& 128) == 0)
19768 return buf
- begin
;
19773 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19782 cu
->language
= language_c
;
19785 case DW_LANG_C_plus_plus
:
19786 case DW_LANG_C_plus_plus_11
:
19787 case DW_LANG_C_plus_plus_14
:
19788 cu
->language
= language_cplus
;
19791 cu
->language
= language_d
;
19793 case DW_LANG_Fortran77
:
19794 case DW_LANG_Fortran90
:
19795 case DW_LANG_Fortran95
:
19796 case DW_LANG_Fortran03
:
19797 case DW_LANG_Fortran08
:
19798 cu
->language
= language_fortran
;
19801 cu
->language
= language_go
;
19803 case DW_LANG_Mips_Assembler
:
19804 cu
->language
= language_asm
;
19806 case DW_LANG_Ada83
:
19807 case DW_LANG_Ada95
:
19808 cu
->language
= language_ada
;
19810 case DW_LANG_Modula2
:
19811 cu
->language
= language_m2
;
19813 case DW_LANG_Pascal83
:
19814 cu
->language
= language_pascal
;
19817 cu
->language
= language_objc
;
19820 case DW_LANG_Rust_old
:
19821 cu
->language
= language_rust
;
19823 case DW_LANG_Cobol74
:
19824 case DW_LANG_Cobol85
:
19826 cu
->language
= language_minimal
;
19829 cu
->language_defn
= language_def (cu
->language
);
19832 /* Return the named attribute or NULL if not there. */
19834 static struct attribute
*
19835 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19840 struct attribute
*spec
= NULL
;
19842 for (i
= 0; i
< die
->num_attrs
; ++i
)
19844 if (die
->attrs
[i
].name
== name
)
19845 return &die
->attrs
[i
];
19846 if (die
->attrs
[i
].name
== DW_AT_specification
19847 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19848 spec
= &die
->attrs
[i
];
19854 die
= follow_die_ref (die
, spec
, &cu
);
19860 /* Return the named attribute or NULL if not there,
19861 but do not follow DW_AT_specification, etc.
19862 This is for use in contexts where we're reading .debug_types dies.
19863 Following DW_AT_specification, DW_AT_abstract_origin will take us
19864 back up the chain, and we want to go down. */
19866 static struct attribute
*
19867 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19871 for (i
= 0; i
< die
->num_attrs
; ++i
)
19872 if (die
->attrs
[i
].name
== name
)
19873 return &die
->attrs
[i
];
19878 /* Return the string associated with a string-typed attribute, or NULL if it
19879 is either not found or is of an incorrect type. */
19881 static const char *
19882 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19884 struct attribute
*attr
;
19885 const char *str
= NULL
;
19887 attr
= dwarf2_attr (die
, name
, cu
);
19891 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19892 || attr
->form
== DW_FORM_string
19893 || attr
->form
== DW_FORM_GNU_str_index
19894 || attr
->form
== DW_FORM_GNU_strp_alt
)
19895 str
= DW_STRING (attr
);
19897 complaint (&symfile_complaints
,
19898 _("string type expected for attribute %s for "
19899 "DIE at 0x%x in module %s"),
19900 dwarf_attr_name (name
), to_underlying (die
->sect_off
),
19901 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19907 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19908 and holds a non-zero value. This function should only be used for
19909 DW_FORM_flag or DW_FORM_flag_present attributes. */
19912 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19914 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19916 return (attr
&& DW_UNSND (attr
));
19920 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19922 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19923 which value is non-zero. However, we have to be careful with
19924 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19925 (via dwarf2_flag_true_p) follows this attribute. So we may
19926 end up accidently finding a declaration attribute that belongs
19927 to a different DIE referenced by the specification attribute,
19928 even though the given DIE does not have a declaration attribute. */
19929 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19930 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19933 /* Return the die giving the specification for DIE, if there is
19934 one. *SPEC_CU is the CU containing DIE on input, and the CU
19935 containing the return value on output. If there is no
19936 specification, but there is an abstract origin, that is
19939 static struct die_info
*
19940 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19942 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19945 if (spec_attr
== NULL
)
19946 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19948 if (spec_attr
== NULL
)
19951 return follow_die_ref (die
, spec_attr
, spec_cu
);
19954 /* Stub for free_line_header to match void * callback types. */
19957 free_line_header_voidp (void *arg
)
19959 struct line_header
*lh
= (struct line_header
*) arg
;
19965 line_header::add_include_dir (const char *include_dir
)
19967 if (dwarf_line_debug
>= 2)
19968 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
19969 include_dirs
.size () + 1, include_dir
);
19971 include_dirs
.push_back (include_dir
);
19975 line_header::add_file_name (const char *name
,
19977 unsigned int mod_time
,
19978 unsigned int length
)
19980 if (dwarf_line_debug
>= 2)
19981 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
19982 (unsigned) file_names
.size () + 1, name
);
19984 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
19987 /* A convenience function to find the proper .debug_line section for a CU. */
19989 static struct dwarf2_section_info
*
19990 get_debug_line_section (struct dwarf2_cu
*cu
)
19992 struct dwarf2_section_info
*section
;
19993 struct dwarf2_per_objfile
*dwarf2_per_objfile
19994 = cu
->per_cu
->dwarf2_per_objfile
;
19996 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19998 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19999 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20000 else if (cu
->per_cu
->is_dwz
)
20002 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20004 section
= &dwz
->line
;
20007 section
= &dwarf2_per_objfile
->line
;
20012 /* Read directory or file name entry format, starting with byte of
20013 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20014 entries count and the entries themselves in the described entry
20018 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20019 bfd
*abfd
, const gdb_byte
**bufp
,
20020 struct line_header
*lh
,
20021 const struct comp_unit_head
*cu_header
,
20022 void (*callback
) (struct line_header
*lh
,
20025 unsigned int mod_time
,
20026 unsigned int length
))
20028 gdb_byte format_count
, formati
;
20029 ULONGEST data_count
, datai
;
20030 const gdb_byte
*buf
= *bufp
;
20031 const gdb_byte
*format_header_data
;
20032 unsigned int bytes_read
;
20034 format_count
= read_1_byte (abfd
, buf
);
20036 format_header_data
= buf
;
20037 for (formati
= 0; formati
< format_count
; formati
++)
20039 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20041 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20045 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20047 for (datai
= 0; datai
< data_count
; datai
++)
20049 const gdb_byte
*format
= format_header_data
;
20050 struct file_entry fe
;
20052 for (formati
= 0; formati
< format_count
; formati
++)
20054 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20055 format
+= bytes_read
;
20057 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20058 format
+= bytes_read
;
20060 gdb::optional
<const char *> string
;
20061 gdb::optional
<unsigned int> uint
;
20065 case DW_FORM_string
:
20066 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20070 case DW_FORM_line_strp
:
20071 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20078 case DW_FORM_data1
:
20079 uint
.emplace (read_1_byte (abfd
, buf
));
20083 case DW_FORM_data2
:
20084 uint
.emplace (read_2_bytes (abfd
, buf
));
20088 case DW_FORM_data4
:
20089 uint
.emplace (read_4_bytes (abfd
, buf
));
20093 case DW_FORM_data8
:
20094 uint
.emplace (read_8_bytes (abfd
, buf
));
20098 case DW_FORM_udata
:
20099 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20103 case DW_FORM_block
:
20104 /* It is valid only for DW_LNCT_timestamp which is ignored by
20109 switch (content_type
)
20112 if (string
.has_value ())
20115 case DW_LNCT_directory_index
:
20116 if (uint
.has_value ())
20117 fe
.d_index
= (dir_index
) *uint
;
20119 case DW_LNCT_timestamp
:
20120 if (uint
.has_value ())
20121 fe
.mod_time
= *uint
;
20124 if (uint
.has_value ())
20130 complaint (&symfile_complaints
,
20131 _("Unknown format content type %s"),
20132 pulongest (content_type
));
20136 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20142 /* Read the statement program header starting at OFFSET in
20143 .debug_line, or .debug_line.dwo. Return a pointer
20144 to a struct line_header, allocated using xmalloc.
20145 Returns NULL if there is a problem reading the header, e.g., if it
20146 has a version we don't understand.
20148 NOTE: the strings in the include directory and file name tables of
20149 the returned object point into the dwarf line section buffer,
20150 and must not be freed. */
20152 static line_header_up
20153 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20155 const gdb_byte
*line_ptr
;
20156 unsigned int bytes_read
, offset_size
;
20158 const char *cur_dir
, *cur_file
;
20159 struct dwarf2_section_info
*section
;
20161 struct dwarf2_per_objfile
*dwarf2_per_objfile
20162 = cu
->per_cu
->dwarf2_per_objfile
;
20164 section
= get_debug_line_section (cu
);
20165 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20166 if (section
->buffer
== NULL
)
20168 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20169 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20171 complaint (&symfile_complaints
, _("missing .debug_line section"));
20175 /* We can't do this until we know the section is non-empty.
20176 Only then do we know we have such a section. */
20177 abfd
= get_section_bfd_owner (section
);
20179 /* Make sure that at least there's room for the total_length field.
20180 That could be 12 bytes long, but we're just going to fudge that. */
20181 if (to_underlying (sect_off
) + 4 >= section
->size
)
20183 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20187 line_header_up
lh (new line_header ());
20189 lh
->sect_off
= sect_off
;
20190 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20192 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20194 /* Read in the header. */
20196 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20197 &bytes_read
, &offset_size
);
20198 line_ptr
+= bytes_read
;
20199 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20201 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20204 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20205 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20207 if (lh
->version
> 5)
20209 /* This is a version we don't understand. The format could have
20210 changed in ways we don't handle properly so just punt. */
20211 complaint (&symfile_complaints
,
20212 _("unsupported version in .debug_line section"));
20215 if (lh
->version
>= 5)
20217 gdb_byte segment_selector_size
;
20219 /* Skip address size. */
20220 read_1_byte (abfd
, line_ptr
);
20223 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20225 if (segment_selector_size
!= 0)
20227 complaint (&symfile_complaints
,
20228 _("unsupported segment selector size %u "
20229 "in .debug_line section"),
20230 segment_selector_size
);
20234 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20235 line_ptr
+= offset_size
;
20236 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20238 if (lh
->version
>= 4)
20240 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20244 lh
->maximum_ops_per_instruction
= 1;
20246 if (lh
->maximum_ops_per_instruction
== 0)
20248 lh
->maximum_ops_per_instruction
= 1;
20249 complaint (&symfile_complaints
,
20250 _("invalid maximum_ops_per_instruction "
20251 "in `.debug_line' section"));
20254 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20256 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20258 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20260 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20262 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20264 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20265 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20267 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20271 if (lh
->version
>= 5)
20273 /* Read directory table. */
20274 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20276 [] (struct line_header
*lh
, const char *name
,
20277 dir_index d_index
, unsigned int mod_time
,
20278 unsigned int length
)
20280 lh
->add_include_dir (name
);
20283 /* Read file name table. */
20284 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20286 [] (struct line_header
*lh
, const char *name
,
20287 dir_index d_index
, unsigned int mod_time
,
20288 unsigned int length
)
20290 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20295 /* Read directory table. */
20296 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20298 line_ptr
+= bytes_read
;
20299 lh
->add_include_dir (cur_dir
);
20301 line_ptr
+= bytes_read
;
20303 /* Read file name table. */
20304 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20306 unsigned int mod_time
, length
;
20309 line_ptr
+= bytes_read
;
20310 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20311 line_ptr
+= bytes_read
;
20312 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20313 line_ptr
+= bytes_read
;
20314 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20315 line_ptr
+= bytes_read
;
20317 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20319 line_ptr
+= bytes_read
;
20321 lh
->statement_program_start
= line_ptr
;
20323 if (line_ptr
> (section
->buffer
+ section
->size
))
20324 complaint (&symfile_complaints
,
20325 _("line number info header doesn't "
20326 "fit in `.debug_line' section"));
20331 /* Subroutine of dwarf_decode_lines to simplify it.
20332 Return the file name of the psymtab for included file FILE_INDEX
20333 in line header LH of PST.
20334 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20335 If space for the result is malloc'd, *NAME_HOLDER will be set.
20336 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20338 static const char *
20339 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20340 const struct partial_symtab
*pst
,
20341 const char *comp_dir
,
20342 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20344 const file_entry
&fe
= lh
->file_names
[file_index
];
20345 const char *include_name
= fe
.name
;
20346 const char *include_name_to_compare
= include_name
;
20347 const char *pst_filename
;
20350 const char *dir_name
= fe
.include_dir (lh
);
20352 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20353 if (!IS_ABSOLUTE_PATH (include_name
)
20354 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20356 /* Avoid creating a duplicate psymtab for PST.
20357 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20358 Before we do the comparison, however, we need to account
20359 for DIR_NAME and COMP_DIR.
20360 First prepend dir_name (if non-NULL). If we still don't
20361 have an absolute path prepend comp_dir (if non-NULL).
20362 However, the directory we record in the include-file's
20363 psymtab does not contain COMP_DIR (to match the
20364 corresponding symtab(s)).
20369 bash$ gcc -g ./hello.c
20370 include_name = "hello.c"
20372 DW_AT_comp_dir = comp_dir = "/tmp"
20373 DW_AT_name = "./hello.c"
20377 if (dir_name
!= NULL
)
20379 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20380 include_name
, (char *) NULL
));
20381 include_name
= name_holder
->get ();
20382 include_name_to_compare
= include_name
;
20384 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20386 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20387 include_name
, (char *) NULL
));
20388 include_name_to_compare
= hold_compare
.get ();
20392 pst_filename
= pst
->filename
;
20393 gdb::unique_xmalloc_ptr
<char> copied_name
;
20394 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20396 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20397 pst_filename
, (char *) NULL
));
20398 pst_filename
= copied_name
.get ();
20401 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20405 return include_name
;
20408 /* State machine to track the state of the line number program. */
20410 class lnp_state_machine
20413 /* Initialize a machine state for the start of a line number
20415 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20417 file_entry
*current_file ()
20419 /* lh->file_names is 0-based, but the file name numbers in the
20420 statement program are 1-based. */
20421 return m_line_header
->file_name_at (m_file
);
20424 /* Record the line in the state machine. END_SEQUENCE is true if
20425 we're processing the end of a sequence. */
20426 void record_line (bool end_sequence
);
20428 /* Check address and if invalid nop-out the rest of the lines in this
20430 void check_line_address (struct dwarf2_cu
*cu
,
20431 const gdb_byte
*line_ptr
,
20432 CORE_ADDR lowpc
, CORE_ADDR address
);
20434 void handle_set_discriminator (unsigned int discriminator
)
20436 m_discriminator
= discriminator
;
20437 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20440 /* Handle DW_LNE_set_address. */
20441 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20444 address
+= baseaddr
;
20445 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20448 /* Handle DW_LNS_advance_pc. */
20449 void handle_advance_pc (CORE_ADDR adjust
);
20451 /* Handle a special opcode. */
20452 void handle_special_opcode (unsigned char op_code
);
20454 /* Handle DW_LNS_advance_line. */
20455 void handle_advance_line (int line_delta
)
20457 advance_line (line_delta
);
20460 /* Handle DW_LNS_set_file. */
20461 void handle_set_file (file_name_index file
);
20463 /* Handle DW_LNS_negate_stmt. */
20464 void handle_negate_stmt ()
20466 m_is_stmt
= !m_is_stmt
;
20469 /* Handle DW_LNS_const_add_pc. */
20470 void handle_const_add_pc ();
20472 /* Handle DW_LNS_fixed_advance_pc. */
20473 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20475 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20479 /* Handle DW_LNS_copy. */
20480 void handle_copy ()
20482 record_line (false);
20483 m_discriminator
= 0;
20486 /* Handle DW_LNE_end_sequence. */
20487 void handle_end_sequence ()
20489 m_record_line_callback
= ::record_line
;
20493 /* Advance the line by LINE_DELTA. */
20494 void advance_line (int line_delta
)
20496 m_line
+= line_delta
;
20498 if (line_delta
!= 0)
20499 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20502 gdbarch
*m_gdbarch
;
20504 /* True if we're recording lines.
20505 Otherwise we're building partial symtabs and are just interested in
20506 finding include files mentioned by the line number program. */
20507 bool m_record_lines_p
;
20509 /* The line number header. */
20510 line_header
*m_line_header
;
20512 /* These are part of the standard DWARF line number state machine,
20513 and initialized according to the DWARF spec. */
20515 unsigned char m_op_index
= 0;
20516 /* The line table index (1-based) of the current file. */
20517 file_name_index m_file
= (file_name_index
) 1;
20518 unsigned int m_line
= 1;
20520 /* These are initialized in the constructor. */
20522 CORE_ADDR m_address
;
20524 unsigned int m_discriminator
;
20526 /* Additional bits of state we need to track. */
20528 /* The last file that we called dwarf2_start_subfile for.
20529 This is only used for TLLs. */
20530 unsigned int m_last_file
= 0;
20531 /* The last file a line number was recorded for. */
20532 struct subfile
*m_last_subfile
= NULL
;
20534 /* The function to call to record a line. */
20535 record_line_ftype
*m_record_line_callback
= NULL
;
20537 /* The last line number that was recorded, used to coalesce
20538 consecutive entries for the same line. This can happen, for
20539 example, when discriminators are present. PR 17276. */
20540 unsigned int m_last_line
= 0;
20541 bool m_line_has_non_zero_discriminator
= false;
20545 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20547 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20548 / m_line_header
->maximum_ops_per_instruction
)
20549 * m_line_header
->minimum_instruction_length
);
20550 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20551 m_op_index
= ((m_op_index
+ adjust
)
20552 % m_line_header
->maximum_ops_per_instruction
);
20556 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20558 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20559 CORE_ADDR addr_adj
= (((m_op_index
20560 + (adj_opcode
/ m_line_header
->line_range
))
20561 / m_line_header
->maximum_ops_per_instruction
)
20562 * m_line_header
->minimum_instruction_length
);
20563 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20564 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20565 % m_line_header
->maximum_ops_per_instruction
);
20567 int line_delta
= (m_line_header
->line_base
20568 + (adj_opcode
% m_line_header
->line_range
));
20569 advance_line (line_delta
);
20570 record_line (false);
20571 m_discriminator
= 0;
20575 lnp_state_machine::handle_set_file (file_name_index file
)
20579 const file_entry
*fe
= current_file ();
20581 dwarf2_debug_line_missing_file_complaint ();
20582 else if (m_record_lines_p
)
20584 const char *dir
= fe
->include_dir (m_line_header
);
20586 m_last_subfile
= current_subfile
;
20587 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20588 dwarf2_start_subfile (fe
->name
, dir
);
20593 lnp_state_machine::handle_const_add_pc ()
20596 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20599 = (((m_op_index
+ adjust
)
20600 / m_line_header
->maximum_ops_per_instruction
)
20601 * m_line_header
->minimum_instruction_length
);
20603 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20604 m_op_index
= ((m_op_index
+ adjust
)
20605 % m_line_header
->maximum_ops_per_instruction
);
20608 /* Ignore this record_line request. */
20611 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
20616 /* Return non-zero if we should add LINE to the line number table.
20617 LINE is the line to add, LAST_LINE is the last line that was added,
20618 LAST_SUBFILE is the subfile for LAST_LINE.
20619 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20620 had a non-zero discriminator.
20622 We have to be careful in the presence of discriminators.
20623 E.g., for this line:
20625 for (i = 0; i < 100000; i++);
20627 clang can emit four line number entries for that one line,
20628 each with a different discriminator.
20629 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20631 However, we want gdb to coalesce all four entries into one.
20632 Otherwise the user could stepi into the middle of the line and
20633 gdb would get confused about whether the pc really was in the
20634 middle of the line.
20636 Things are further complicated by the fact that two consecutive
20637 line number entries for the same line is a heuristic used by gcc
20638 to denote the end of the prologue. So we can't just discard duplicate
20639 entries, we have to be selective about it. The heuristic we use is
20640 that we only collapse consecutive entries for the same line if at least
20641 one of those entries has a non-zero discriminator. PR 17276.
20643 Note: Addresses in the line number state machine can never go backwards
20644 within one sequence, thus this coalescing is ok. */
20647 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
20648 int line_has_non_zero_discriminator
,
20649 struct subfile
*last_subfile
)
20651 if (current_subfile
!= last_subfile
)
20653 if (line
!= last_line
)
20655 /* Same line for the same file that we've seen already.
20656 As a last check, for pr 17276, only record the line if the line
20657 has never had a non-zero discriminator. */
20658 if (!line_has_non_zero_discriminator
)
20663 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
20664 in the line table of subfile SUBFILE. */
20667 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20668 unsigned int line
, CORE_ADDR address
,
20669 record_line_ftype p_record_line
)
20671 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20673 if (dwarf_line_debug
)
20675 fprintf_unfiltered (gdb_stdlog
,
20676 "Recording line %u, file %s, address %s\n",
20677 line
, lbasename (subfile
->name
),
20678 paddress (gdbarch
, address
));
20681 (*p_record_line
) (subfile
, line
, addr
);
20684 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20685 Mark the end of a set of line number records.
20686 The arguments are the same as for dwarf_record_line_1.
20687 If SUBFILE is NULL the request is ignored. */
20690 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20691 CORE_ADDR address
, record_line_ftype p_record_line
)
20693 if (subfile
== NULL
)
20696 if (dwarf_line_debug
)
20698 fprintf_unfiltered (gdb_stdlog
,
20699 "Finishing current line, file %s, address %s\n",
20700 lbasename (subfile
->name
),
20701 paddress (gdbarch
, address
));
20704 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
20708 lnp_state_machine::record_line (bool end_sequence
)
20710 if (dwarf_line_debug
)
20712 fprintf_unfiltered (gdb_stdlog
,
20713 "Processing actual line %u: file %u,"
20714 " address %s, is_stmt %u, discrim %u\n",
20715 m_line
, to_underlying (m_file
),
20716 paddress (m_gdbarch
, m_address
),
20717 m_is_stmt
, m_discriminator
);
20720 file_entry
*fe
= current_file ();
20723 dwarf2_debug_line_missing_file_complaint ();
20724 /* For now we ignore lines not starting on an instruction boundary.
20725 But not when processing end_sequence for compatibility with the
20726 previous version of the code. */
20727 else if (m_op_index
== 0 || end_sequence
)
20729 fe
->included_p
= 1;
20730 if (m_record_lines_p
&& m_is_stmt
)
20732 if (m_last_subfile
!= current_subfile
|| end_sequence
)
20734 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
20735 m_address
, m_record_line_callback
);
20740 if (dwarf_record_line_p (m_line
, m_last_line
,
20741 m_line_has_non_zero_discriminator
,
20744 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
20746 m_record_line_callback
);
20748 m_last_subfile
= current_subfile
;
20749 m_last_line
= m_line
;
20755 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
20756 bool record_lines_p
)
20759 m_record_lines_p
= record_lines_p
;
20760 m_line_header
= lh
;
20762 m_record_line_callback
= ::record_line
;
20764 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20765 was a line entry for it so that the backend has a chance to adjust it
20766 and also record it in case it needs it. This is currently used by MIPS
20767 code, cf. `mips_adjust_dwarf2_line'. */
20768 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20769 m_is_stmt
= lh
->default_is_stmt
;
20770 m_discriminator
= 0;
20774 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20775 const gdb_byte
*line_ptr
,
20776 CORE_ADDR lowpc
, CORE_ADDR address
)
20778 /* If address < lowpc then it's not a usable value, it's outside the
20779 pc range of the CU. However, we restrict the test to only address
20780 values of zero to preserve GDB's previous behaviour which is to
20781 handle the specific case of a function being GC'd by the linker. */
20783 if (address
== 0 && address
< lowpc
)
20785 /* This line table is for a function which has been
20786 GCd by the linker. Ignore it. PR gdb/12528 */
20788 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20789 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20791 complaint (&symfile_complaints
,
20792 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20793 line_offset
, objfile_name (objfile
));
20794 m_record_line_callback
= noop_record_line
;
20795 /* Note: record_line_callback is left as noop_record_line until
20796 we see DW_LNE_end_sequence. */
20800 /* Subroutine of dwarf_decode_lines to simplify it.
20801 Process the line number information in LH.
20802 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20803 program in order to set included_p for every referenced header. */
20806 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20807 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20809 const gdb_byte
*line_ptr
, *extended_end
;
20810 const gdb_byte
*line_end
;
20811 unsigned int bytes_read
, extended_len
;
20812 unsigned char op_code
, extended_op
;
20813 CORE_ADDR baseaddr
;
20814 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20815 bfd
*abfd
= objfile
->obfd
;
20816 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20817 /* True if we're recording line info (as opposed to building partial
20818 symtabs and just interested in finding include files mentioned by
20819 the line number program). */
20820 bool record_lines_p
= !decode_for_pst_p
;
20822 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20824 line_ptr
= lh
->statement_program_start
;
20825 line_end
= lh
->statement_program_end
;
20827 /* Read the statement sequences until there's nothing left. */
20828 while (line_ptr
< line_end
)
20830 /* The DWARF line number program state machine. Reset the state
20831 machine at the start of each sequence. */
20832 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
20833 bool end_sequence
= false;
20835 if (record_lines_p
)
20837 /* Start a subfile for the current file of the state
20839 const file_entry
*fe
= state_machine
.current_file ();
20842 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
20845 /* Decode the table. */
20846 while (line_ptr
< line_end
&& !end_sequence
)
20848 op_code
= read_1_byte (abfd
, line_ptr
);
20851 if (op_code
>= lh
->opcode_base
)
20853 /* Special opcode. */
20854 state_machine
.handle_special_opcode (op_code
);
20856 else switch (op_code
)
20858 case DW_LNS_extended_op
:
20859 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20861 line_ptr
+= bytes_read
;
20862 extended_end
= line_ptr
+ extended_len
;
20863 extended_op
= read_1_byte (abfd
, line_ptr
);
20865 switch (extended_op
)
20867 case DW_LNE_end_sequence
:
20868 state_machine
.handle_end_sequence ();
20869 end_sequence
= true;
20871 case DW_LNE_set_address
:
20874 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20875 line_ptr
+= bytes_read
;
20877 state_machine
.check_line_address (cu
, line_ptr
,
20879 state_machine
.handle_set_address (baseaddr
, address
);
20882 case DW_LNE_define_file
:
20884 const char *cur_file
;
20885 unsigned int mod_time
, length
;
20888 cur_file
= read_direct_string (abfd
, line_ptr
,
20890 line_ptr
+= bytes_read
;
20891 dindex
= (dir_index
)
20892 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20893 line_ptr
+= bytes_read
;
20895 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20896 line_ptr
+= bytes_read
;
20898 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20899 line_ptr
+= bytes_read
;
20900 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20903 case DW_LNE_set_discriminator
:
20905 /* The discriminator is not interesting to the
20906 debugger; just ignore it. We still need to
20907 check its value though:
20908 if there are consecutive entries for the same
20909 (non-prologue) line we want to coalesce them.
20912 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20913 line_ptr
+= bytes_read
;
20915 state_machine
.handle_set_discriminator (discr
);
20919 complaint (&symfile_complaints
,
20920 _("mangled .debug_line section"));
20923 /* Make sure that we parsed the extended op correctly. If e.g.
20924 we expected a different address size than the producer used,
20925 we may have read the wrong number of bytes. */
20926 if (line_ptr
!= extended_end
)
20928 complaint (&symfile_complaints
,
20929 _("mangled .debug_line section"));
20934 state_machine
.handle_copy ();
20936 case DW_LNS_advance_pc
:
20939 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20940 line_ptr
+= bytes_read
;
20942 state_machine
.handle_advance_pc (adjust
);
20945 case DW_LNS_advance_line
:
20948 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20949 line_ptr
+= bytes_read
;
20951 state_machine
.handle_advance_line (line_delta
);
20954 case DW_LNS_set_file
:
20956 file_name_index file
20957 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20959 line_ptr
+= bytes_read
;
20961 state_machine
.handle_set_file (file
);
20964 case DW_LNS_set_column
:
20965 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20966 line_ptr
+= bytes_read
;
20968 case DW_LNS_negate_stmt
:
20969 state_machine
.handle_negate_stmt ();
20971 case DW_LNS_set_basic_block
:
20973 /* Add to the address register of the state machine the
20974 address increment value corresponding to special opcode
20975 255. I.e., this value is scaled by the minimum
20976 instruction length since special opcode 255 would have
20977 scaled the increment. */
20978 case DW_LNS_const_add_pc
:
20979 state_machine
.handle_const_add_pc ();
20981 case DW_LNS_fixed_advance_pc
:
20983 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
20986 state_machine
.handle_fixed_advance_pc (addr_adj
);
20991 /* Unknown standard opcode, ignore it. */
20994 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
20996 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20997 line_ptr
+= bytes_read
;
21004 dwarf2_debug_line_missing_end_sequence_complaint ();
21006 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21007 in which case we still finish recording the last line). */
21008 state_machine
.record_line (true);
21012 /* Decode the Line Number Program (LNP) for the given line_header
21013 structure and CU. The actual information extracted and the type
21014 of structures created from the LNP depends on the value of PST.
21016 1. If PST is NULL, then this procedure uses the data from the program
21017 to create all necessary symbol tables, and their linetables.
21019 2. If PST is not NULL, this procedure reads the program to determine
21020 the list of files included by the unit represented by PST, and
21021 builds all the associated partial symbol tables.
21023 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21024 It is used for relative paths in the line table.
21025 NOTE: When processing partial symtabs (pst != NULL),
21026 comp_dir == pst->dirname.
21028 NOTE: It is important that psymtabs have the same file name (via strcmp)
21029 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21030 symtab we don't use it in the name of the psymtabs we create.
21031 E.g. expand_line_sal requires this when finding psymtabs to expand.
21032 A good testcase for this is mb-inline.exp.
21034 LOWPC is the lowest address in CU (or 0 if not known).
21036 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21037 for its PC<->lines mapping information. Otherwise only the filename
21038 table is read in. */
21041 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21042 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21043 CORE_ADDR lowpc
, int decode_mapping
)
21045 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21046 const int decode_for_pst_p
= (pst
!= NULL
);
21048 if (decode_mapping
)
21049 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21051 if (decode_for_pst_p
)
21055 /* Now that we're done scanning the Line Header Program, we can
21056 create the psymtab of each included file. */
21057 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21058 if (lh
->file_names
[file_index
].included_p
== 1)
21060 gdb::unique_xmalloc_ptr
<char> name_holder
;
21061 const char *include_name
=
21062 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21064 if (include_name
!= NULL
)
21065 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21070 /* Make sure a symtab is created for every file, even files
21071 which contain only variables (i.e. no code with associated
21073 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21076 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21078 file_entry
&fe
= lh
->file_names
[i
];
21080 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21082 if (current_subfile
->symtab
== NULL
)
21084 current_subfile
->symtab
21085 = allocate_symtab (cust
, current_subfile
->name
);
21087 fe
.symtab
= current_subfile
->symtab
;
21092 /* Start a subfile for DWARF. FILENAME is the name of the file and
21093 DIRNAME the name of the source directory which contains FILENAME
21094 or NULL if not known.
21095 This routine tries to keep line numbers from identical absolute and
21096 relative file names in a common subfile.
21098 Using the `list' example from the GDB testsuite, which resides in
21099 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21100 of /srcdir/list0.c yields the following debugging information for list0.c:
21102 DW_AT_name: /srcdir/list0.c
21103 DW_AT_comp_dir: /compdir
21104 files.files[0].name: list0.h
21105 files.files[0].dir: /srcdir
21106 files.files[1].name: list0.c
21107 files.files[1].dir: /srcdir
21109 The line number information for list0.c has to end up in a single
21110 subfile, so that `break /srcdir/list0.c:1' works as expected.
21111 start_subfile will ensure that this happens provided that we pass the
21112 concatenation of files.files[1].dir and files.files[1].name as the
21116 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21120 /* In order not to lose the line information directory,
21121 we concatenate it to the filename when it makes sense.
21122 Note that the Dwarf3 standard says (speaking of filenames in line
21123 information): ``The directory index is ignored for file names
21124 that represent full path names''. Thus ignoring dirname in the
21125 `else' branch below isn't an issue. */
21127 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21129 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21133 start_subfile (filename
);
21139 /* Start a symtab for DWARF.
21140 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21142 static struct compunit_symtab
*
21143 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21144 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21146 struct compunit_symtab
*cust
21147 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21148 low_pc
, cu
->language
);
21150 record_debugformat ("DWARF 2");
21151 record_producer (cu
->producer
);
21153 /* We assume that we're processing GCC output. */
21154 processing_gcc_compilation
= 2;
21156 cu
->processing_has_namespace_info
= 0;
21162 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21163 struct dwarf2_cu
*cu
)
21165 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21166 struct comp_unit_head
*cu_header
= &cu
->header
;
21168 /* NOTE drow/2003-01-30: There used to be a comment and some special
21169 code here to turn a symbol with DW_AT_external and a
21170 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21171 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21172 with some versions of binutils) where shared libraries could have
21173 relocations against symbols in their debug information - the
21174 minimal symbol would have the right address, but the debug info
21175 would not. It's no longer necessary, because we will explicitly
21176 apply relocations when we read in the debug information now. */
21178 /* A DW_AT_location attribute with no contents indicates that a
21179 variable has been optimized away. */
21180 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21182 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21186 /* Handle one degenerate form of location expression specially, to
21187 preserve GDB's previous behavior when section offsets are
21188 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21189 then mark this symbol as LOC_STATIC. */
21191 if (attr_form_is_block (attr
)
21192 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21193 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21194 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21195 && (DW_BLOCK (attr
)->size
21196 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21198 unsigned int dummy
;
21200 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21201 SYMBOL_VALUE_ADDRESS (sym
) =
21202 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21204 SYMBOL_VALUE_ADDRESS (sym
) =
21205 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21206 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21207 fixup_symbol_section (sym
, objfile
);
21208 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21209 SYMBOL_SECTION (sym
));
21213 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21214 expression evaluator, and use LOC_COMPUTED only when necessary
21215 (i.e. when the value of a register or memory location is
21216 referenced, or a thread-local block, etc.). Then again, it might
21217 not be worthwhile. I'm assuming that it isn't unless performance
21218 or memory numbers show me otherwise. */
21220 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21222 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21223 cu
->has_loclist
= 1;
21226 /* Given a pointer to a DWARF information entry, figure out if we need
21227 to make a symbol table entry for it, and if so, create a new entry
21228 and return a pointer to it.
21229 If TYPE is NULL, determine symbol type from the die, otherwise
21230 used the passed type.
21231 If SPACE is not NULL, use it to hold the new symbol. If it is
21232 NULL, allocate a new symbol on the objfile's obstack. */
21234 static struct symbol
*
21235 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21236 struct symbol
*space
)
21238 struct dwarf2_per_objfile
*dwarf2_per_objfile
21239 = cu
->per_cu
->dwarf2_per_objfile
;
21240 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21241 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21242 struct symbol
*sym
= NULL
;
21244 struct attribute
*attr
= NULL
;
21245 struct attribute
*attr2
= NULL
;
21246 CORE_ADDR baseaddr
;
21247 struct pending
**list_to_add
= NULL
;
21249 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21251 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21253 name
= dwarf2_name (die
, cu
);
21256 const char *linkagename
;
21257 int suppress_add
= 0;
21262 sym
= allocate_symbol (objfile
);
21263 OBJSTAT (objfile
, n_syms
++);
21265 /* Cache this symbol's name and the name's demangled form (if any). */
21266 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21267 linkagename
= dwarf2_physname (name
, die
, cu
);
21268 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21270 /* Fortran does not have mangling standard and the mangling does differ
21271 between gfortran, iFort etc. */
21272 if (cu
->language
== language_fortran
21273 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21274 symbol_set_demangled_name (&(sym
->ginfo
),
21275 dwarf2_full_name (name
, die
, cu
),
21278 /* Default assumptions.
21279 Use the passed type or decode it from the die. */
21280 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21281 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21283 SYMBOL_TYPE (sym
) = type
;
21285 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21286 attr
= dwarf2_attr (die
,
21287 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21291 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21294 attr
= dwarf2_attr (die
,
21295 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21299 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21300 struct file_entry
*fe
;
21302 if (cu
->line_header
!= NULL
)
21303 fe
= cu
->line_header
->file_name_at (file_index
);
21308 complaint (&symfile_complaints
,
21309 _("file index out of range"));
21311 symbol_set_symtab (sym
, fe
->symtab
);
21317 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21322 addr
= attr_value_as_address (attr
);
21323 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21324 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21326 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21327 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21328 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21329 add_symbol_to_list (sym
, cu
->list_in_scope
);
21331 case DW_TAG_subprogram
:
21332 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21334 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21335 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21336 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21337 || cu
->language
== language_ada
)
21339 /* Subprograms marked external are stored as a global symbol.
21340 Ada subprograms, whether marked external or not, are always
21341 stored as a global symbol, because we want to be able to
21342 access them globally. For instance, we want to be able
21343 to break on a nested subprogram without having to
21344 specify the context. */
21345 list_to_add
= &global_symbols
;
21349 list_to_add
= cu
->list_in_scope
;
21352 case DW_TAG_inlined_subroutine
:
21353 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21355 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21356 SYMBOL_INLINED (sym
) = 1;
21357 list_to_add
= cu
->list_in_scope
;
21359 case DW_TAG_template_value_param
:
21361 /* Fall through. */
21362 case DW_TAG_constant
:
21363 case DW_TAG_variable
:
21364 case DW_TAG_member
:
21365 /* Compilation with minimal debug info may result in
21366 variables with missing type entries. Change the
21367 misleading `void' type to something sensible. */
21368 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21369 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21371 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21372 /* In the case of DW_TAG_member, we should only be called for
21373 static const members. */
21374 if (die
->tag
== DW_TAG_member
)
21376 /* dwarf2_add_field uses die_is_declaration,
21377 so we do the same. */
21378 gdb_assert (die_is_declaration (die
, cu
));
21383 dwarf2_const_value (attr
, sym
, cu
);
21384 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21387 if (attr2
&& (DW_UNSND (attr2
) != 0))
21388 list_to_add
= &global_symbols
;
21390 list_to_add
= cu
->list_in_scope
;
21394 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21397 var_decode_location (attr
, sym
, cu
);
21398 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21400 /* Fortran explicitly imports any global symbols to the local
21401 scope by DW_TAG_common_block. */
21402 if (cu
->language
== language_fortran
&& die
->parent
21403 && die
->parent
->tag
== DW_TAG_common_block
)
21406 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21407 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21408 && !dwarf2_per_objfile
->has_section_at_zero
)
21410 /* When a static variable is eliminated by the linker,
21411 the corresponding debug information is not stripped
21412 out, but the variable address is set to null;
21413 do not add such variables into symbol table. */
21415 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21417 /* Workaround gfortran PR debug/40040 - it uses
21418 DW_AT_location for variables in -fPIC libraries which may
21419 get overriden by other libraries/executable and get
21420 a different address. Resolve it by the minimal symbol
21421 which may come from inferior's executable using copy
21422 relocation. Make this workaround only for gfortran as for
21423 other compilers GDB cannot guess the minimal symbol
21424 Fortran mangling kind. */
21425 if (cu
->language
== language_fortran
&& die
->parent
21426 && die
->parent
->tag
== DW_TAG_module
21428 && startswith (cu
->producer
, "GNU Fortran"))
21429 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21431 /* A variable with DW_AT_external is never static,
21432 but it may be block-scoped. */
21433 list_to_add
= (cu
->list_in_scope
== &file_symbols
21434 ? &global_symbols
: cu
->list_in_scope
);
21437 list_to_add
= cu
->list_in_scope
;
21441 /* We do not know the address of this symbol.
21442 If it is an external symbol and we have type information
21443 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21444 The address of the variable will then be determined from
21445 the minimal symbol table whenever the variable is
21447 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21449 /* Fortran explicitly imports any global symbols to the local
21450 scope by DW_TAG_common_block. */
21451 if (cu
->language
== language_fortran
&& die
->parent
21452 && die
->parent
->tag
== DW_TAG_common_block
)
21454 /* SYMBOL_CLASS doesn't matter here because
21455 read_common_block is going to reset it. */
21457 list_to_add
= cu
->list_in_scope
;
21459 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21460 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21462 /* A variable with DW_AT_external is never static, but it
21463 may be block-scoped. */
21464 list_to_add
= (cu
->list_in_scope
== &file_symbols
21465 ? &global_symbols
: cu
->list_in_scope
);
21467 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21469 else if (!die_is_declaration (die
, cu
))
21471 /* Use the default LOC_OPTIMIZED_OUT class. */
21472 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21474 list_to_add
= cu
->list_in_scope
;
21478 case DW_TAG_formal_parameter
:
21479 /* If we are inside a function, mark this as an argument. If
21480 not, we might be looking at an argument to an inlined function
21481 when we do not have enough information to show inlined frames;
21482 pretend it's a local variable in that case so that the user can
21484 if (context_stack_depth
> 0
21485 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21486 SYMBOL_IS_ARGUMENT (sym
) = 1;
21487 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21490 var_decode_location (attr
, sym
, cu
);
21492 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21495 dwarf2_const_value (attr
, sym
, cu
);
21498 list_to_add
= cu
->list_in_scope
;
21500 case DW_TAG_unspecified_parameters
:
21501 /* From varargs functions; gdb doesn't seem to have any
21502 interest in this information, so just ignore it for now.
21505 case DW_TAG_template_type_param
:
21507 /* Fall through. */
21508 case DW_TAG_class_type
:
21509 case DW_TAG_interface_type
:
21510 case DW_TAG_structure_type
:
21511 case DW_TAG_union_type
:
21512 case DW_TAG_set_type
:
21513 case DW_TAG_enumeration_type
:
21514 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21515 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21518 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21519 really ever be static objects: otherwise, if you try
21520 to, say, break of a class's method and you're in a file
21521 which doesn't mention that class, it won't work unless
21522 the check for all static symbols in lookup_symbol_aux
21523 saves you. See the OtherFileClass tests in
21524 gdb.c++/namespace.exp. */
21528 list_to_add
= (cu
->list_in_scope
== &file_symbols
21529 && cu
->language
== language_cplus
21530 ? &global_symbols
: cu
->list_in_scope
);
21532 /* The semantics of C++ state that "struct foo {
21533 ... }" also defines a typedef for "foo". */
21534 if (cu
->language
== language_cplus
21535 || cu
->language
== language_ada
21536 || cu
->language
== language_d
21537 || cu
->language
== language_rust
)
21539 /* The symbol's name is already allocated along
21540 with this objfile, so we don't need to
21541 duplicate it for the type. */
21542 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21543 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21548 case DW_TAG_typedef
:
21549 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21550 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21551 list_to_add
= cu
->list_in_scope
;
21553 case DW_TAG_base_type
:
21554 case DW_TAG_subrange_type
:
21555 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21556 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21557 list_to_add
= cu
->list_in_scope
;
21559 case DW_TAG_enumerator
:
21560 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21563 dwarf2_const_value (attr
, sym
, cu
);
21566 /* NOTE: carlton/2003-11-10: See comment above in the
21567 DW_TAG_class_type, etc. block. */
21569 list_to_add
= (cu
->list_in_scope
== &file_symbols
21570 && cu
->language
== language_cplus
21571 ? &global_symbols
: cu
->list_in_scope
);
21574 case DW_TAG_imported_declaration
:
21575 case DW_TAG_namespace
:
21576 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21577 list_to_add
= &global_symbols
;
21579 case DW_TAG_module
:
21580 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21581 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21582 list_to_add
= &global_symbols
;
21584 case DW_TAG_common_block
:
21585 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21586 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21587 add_symbol_to_list (sym
, cu
->list_in_scope
);
21590 /* Not a tag we recognize. Hopefully we aren't processing
21591 trash data, but since we must specifically ignore things
21592 we don't recognize, there is nothing else we should do at
21594 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
21595 dwarf_tag_name (die
->tag
));
21601 sym
->hash_next
= objfile
->template_symbols
;
21602 objfile
->template_symbols
= sym
;
21603 list_to_add
= NULL
;
21606 if (list_to_add
!= NULL
)
21607 add_symbol_to_list (sym
, list_to_add
);
21609 /* For the benefit of old versions of GCC, check for anonymous
21610 namespaces based on the demangled name. */
21611 if (!cu
->processing_has_namespace_info
21612 && cu
->language
== language_cplus
)
21613 cp_scan_for_anonymous_namespaces (sym
, objfile
);
21618 /* Given an attr with a DW_FORM_dataN value in host byte order,
21619 zero-extend it as appropriate for the symbol's type. The DWARF
21620 standard (v4) is not entirely clear about the meaning of using
21621 DW_FORM_dataN for a constant with a signed type, where the type is
21622 wider than the data. The conclusion of a discussion on the DWARF
21623 list was that this is unspecified. We choose to always zero-extend
21624 because that is the interpretation long in use by GCC. */
21627 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21628 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21630 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21631 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21632 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21633 LONGEST l
= DW_UNSND (attr
);
21635 if (bits
< sizeof (*value
) * 8)
21637 l
&= ((LONGEST
) 1 << bits
) - 1;
21640 else if (bits
== sizeof (*value
) * 8)
21644 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21645 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21652 /* Read a constant value from an attribute. Either set *VALUE, or if
21653 the value does not fit in *VALUE, set *BYTES - either already
21654 allocated on the objfile obstack, or newly allocated on OBSTACK,
21655 or, set *BATON, if we translated the constant to a location
21659 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21660 const char *name
, struct obstack
*obstack
,
21661 struct dwarf2_cu
*cu
,
21662 LONGEST
*value
, const gdb_byte
**bytes
,
21663 struct dwarf2_locexpr_baton
**baton
)
21665 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21666 struct comp_unit_head
*cu_header
= &cu
->header
;
21667 struct dwarf_block
*blk
;
21668 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21669 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21675 switch (attr
->form
)
21678 case DW_FORM_GNU_addr_index
:
21682 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21683 dwarf2_const_value_length_mismatch_complaint (name
,
21684 cu_header
->addr_size
,
21685 TYPE_LENGTH (type
));
21686 /* Symbols of this form are reasonably rare, so we just
21687 piggyback on the existing location code rather than writing
21688 a new implementation of symbol_computed_ops. */
21689 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21690 (*baton
)->per_cu
= cu
->per_cu
;
21691 gdb_assert ((*baton
)->per_cu
);
21693 (*baton
)->size
= 2 + cu_header
->addr_size
;
21694 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21695 (*baton
)->data
= data
;
21697 data
[0] = DW_OP_addr
;
21698 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21699 byte_order
, DW_ADDR (attr
));
21700 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21703 case DW_FORM_string
:
21705 case DW_FORM_GNU_str_index
:
21706 case DW_FORM_GNU_strp_alt
:
21707 /* DW_STRING is already allocated on the objfile obstack, point
21709 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21711 case DW_FORM_block1
:
21712 case DW_FORM_block2
:
21713 case DW_FORM_block4
:
21714 case DW_FORM_block
:
21715 case DW_FORM_exprloc
:
21716 case DW_FORM_data16
:
21717 blk
= DW_BLOCK (attr
);
21718 if (TYPE_LENGTH (type
) != blk
->size
)
21719 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21720 TYPE_LENGTH (type
));
21721 *bytes
= blk
->data
;
21724 /* The DW_AT_const_value attributes are supposed to carry the
21725 symbol's value "represented as it would be on the target
21726 architecture." By the time we get here, it's already been
21727 converted to host endianness, so we just need to sign- or
21728 zero-extend it as appropriate. */
21729 case DW_FORM_data1
:
21730 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21732 case DW_FORM_data2
:
21733 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21735 case DW_FORM_data4
:
21736 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21738 case DW_FORM_data8
:
21739 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21742 case DW_FORM_sdata
:
21743 case DW_FORM_implicit_const
:
21744 *value
= DW_SND (attr
);
21747 case DW_FORM_udata
:
21748 *value
= DW_UNSND (attr
);
21752 complaint (&symfile_complaints
,
21753 _("unsupported const value attribute form: '%s'"),
21754 dwarf_form_name (attr
->form
));
21761 /* Copy constant value from an attribute to a symbol. */
21764 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21765 struct dwarf2_cu
*cu
)
21767 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21769 const gdb_byte
*bytes
;
21770 struct dwarf2_locexpr_baton
*baton
;
21772 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21773 SYMBOL_PRINT_NAME (sym
),
21774 &objfile
->objfile_obstack
, cu
,
21775 &value
, &bytes
, &baton
);
21779 SYMBOL_LOCATION_BATON (sym
) = baton
;
21780 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21782 else if (bytes
!= NULL
)
21784 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21785 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21789 SYMBOL_VALUE (sym
) = value
;
21790 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21794 /* Return the type of the die in question using its DW_AT_type attribute. */
21796 static struct type
*
21797 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21799 struct attribute
*type_attr
;
21801 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21804 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21805 /* A missing DW_AT_type represents a void type. */
21806 return objfile_type (objfile
)->builtin_void
;
21809 return lookup_die_type (die
, type_attr
, cu
);
21812 /* True iff CU's producer generates GNAT Ada auxiliary information
21813 that allows to find parallel types through that information instead
21814 of having to do expensive parallel lookups by type name. */
21817 need_gnat_info (struct dwarf2_cu
*cu
)
21819 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
21820 of GNAT produces this auxiliary information, without any indication
21821 that it is produced. Part of enhancing the FSF version of GNAT
21822 to produce that information will be to put in place an indicator
21823 that we can use in order to determine whether the descriptive type
21824 info is available or not. One suggestion that has been made is
21825 to use a new attribute, attached to the CU die. For now, assume
21826 that the descriptive type info is not available. */
21830 /* Return the auxiliary type of the die in question using its
21831 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21832 attribute is not present. */
21834 static struct type
*
21835 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21837 struct attribute
*type_attr
;
21839 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21843 return lookup_die_type (die
, type_attr
, cu
);
21846 /* If DIE has a descriptive_type attribute, then set the TYPE's
21847 descriptive type accordingly. */
21850 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21851 struct dwarf2_cu
*cu
)
21853 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21855 if (descriptive_type
)
21857 ALLOCATE_GNAT_AUX_TYPE (type
);
21858 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21862 /* Return the containing type of the die in question using its
21863 DW_AT_containing_type attribute. */
21865 static struct type
*
21866 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21868 struct attribute
*type_attr
;
21869 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21871 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21873 error (_("Dwarf Error: Problem turning containing type into gdb type "
21874 "[in module %s]"), objfile_name (objfile
));
21876 return lookup_die_type (die
, type_attr
, cu
);
21879 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21881 static struct type
*
21882 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21884 struct dwarf2_per_objfile
*dwarf2_per_objfile
21885 = cu
->per_cu
->dwarf2_per_objfile
;
21886 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21887 char *message
, *saved
;
21889 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
21890 objfile_name (objfile
),
21891 to_underlying (cu
->header
.sect_off
),
21892 to_underlying (die
->sect_off
));
21893 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
21894 message
, strlen (message
));
21897 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21900 /* Look up the type of DIE in CU using its type attribute ATTR.
21901 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21902 DW_AT_containing_type.
21903 If there is no type substitute an error marker. */
21905 static struct type
*
21906 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21907 struct dwarf2_cu
*cu
)
21909 struct dwarf2_per_objfile
*dwarf2_per_objfile
21910 = cu
->per_cu
->dwarf2_per_objfile
;
21911 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21912 struct type
*this_type
;
21914 gdb_assert (attr
->name
== DW_AT_type
21915 || attr
->name
== DW_AT_GNAT_descriptive_type
21916 || attr
->name
== DW_AT_containing_type
);
21918 /* First see if we have it cached. */
21920 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21922 struct dwarf2_per_cu_data
*per_cu
;
21923 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21925 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21926 dwarf2_per_objfile
);
21927 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21929 else if (attr_form_is_ref (attr
))
21931 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21933 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21935 else if (attr
->form
== DW_FORM_ref_sig8
)
21937 ULONGEST signature
= DW_SIGNATURE (attr
);
21939 return get_signatured_type (die
, signature
, cu
);
21943 complaint (&symfile_complaints
,
21944 _("Dwarf Error: Bad type attribute %s in DIE"
21945 " at 0x%x [in module %s]"),
21946 dwarf_attr_name (attr
->name
), to_underlying (die
->sect_off
),
21947 objfile_name (objfile
));
21948 return build_error_marker_type (cu
, die
);
21951 /* If not cached we need to read it in. */
21953 if (this_type
== NULL
)
21955 struct die_info
*type_die
= NULL
;
21956 struct dwarf2_cu
*type_cu
= cu
;
21958 if (attr_form_is_ref (attr
))
21959 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21960 if (type_die
== NULL
)
21961 return build_error_marker_type (cu
, die
);
21962 /* If we find the type now, it's probably because the type came
21963 from an inter-CU reference and the type's CU got expanded before
21965 this_type
= read_type_die (type_die
, type_cu
);
21968 /* If we still don't have a type use an error marker. */
21970 if (this_type
== NULL
)
21971 return build_error_marker_type (cu
, die
);
21976 /* Return the type in DIE, CU.
21977 Returns NULL for invalid types.
21979 This first does a lookup in die_type_hash,
21980 and only reads the die in if necessary.
21982 NOTE: This can be called when reading in partial or full symbols. */
21984 static struct type
*
21985 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
21987 struct type
*this_type
;
21989 this_type
= get_die_type (die
, cu
);
21993 return read_type_die_1 (die
, cu
);
21996 /* Read the type in DIE, CU.
21997 Returns NULL for invalid types. */
21999 static struct type
*
22000 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22002 struct type
*this_type
= NULL
;
22006 case DW_TAG_class_type
:
22007 case DW_TAG_interface_type
:
22008 case DW_TAG_structure_type
:
22009 case DW_TAG_union_type
:
22010 this_type
= read_structure_type (die
, cu
);
22012 case DW_TAG_enumeration_type
:
22013 this_type
= read_enumeration_type (die
, cu
);
22015 case DW_TAG_subprogram
:
22016 case DW_TAG_subroutine_type
:
22017 case DW_TAG_inlined_subroutine
:
22018 this_type
= read_subroutine_type (die
, cu
);
22020 case DW_TAG_array_type
:
22021 this_type
= read_array_type (die
, cu
);
22023 case DW_TAG_set_type
:
22024 this_type
= read_set_type (die
, cu
);
22026 case DW_TAG_pointer_type
:
22027 this_type
= read_tag_pointer_type (die
, cu
);
22029 case DW_TAG_ptr_to_member_type
:
22030 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22032 case DW_TAG_reference_type
:
22033 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22035 case DW_TAG_rvalue_reference_type
:
22036 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22038 case DW_TAG_const_type
:
22039 this_type
= read_tag_const_type (die
, cu
);
22041 case DW_TAG_volatile_type
:
22042 this_type
= read_tag_volatile_type (die
, cu
);
22044 case DW_TAG_restrict_type
:
22045 this_type
= read_tag_restrict_type (die
, cu
);
22047 case DW_TAG_string_type
:
22048 this_type
= read_tag_string_type (die
, cu
);
22050 case DW_TAG_typedef
:
22051 this_type
= read_typedef (die
, cu
);
22053 case DW_TAG_subrange_type
:
22054 this_type
= read_subrange_type (die
, cu
);
22056 case DW_TAG_base_type
:
22057 this_type
= read_base_type (die
, cu
);
22059 case DW_TAG_unspecified_type
:
22060 this_type
= read_unspecified_type (die
, cu
);
22062 case DW_TAG_namespace
:
22063 this_type
= read_namespace_type (die
, cu
);
22065 case DW_TAG_module
:
22066 this_type
= read_module_type (die
, cu
);
22068 case DW_TAG_atomic_type
:
22069 this_type
= read_tag_atomic_type (die
, cu
);
22072 complaint (&symfile_complaints
,
22073 _("unexpected tag in read_type_die: '%s'"),
22074 dwarf_tag_name (die
->tag
));
22081 /* See if we can figure out if the class lives in a namespace. We do
22082 this by looking for a member function; its demangled name will
22083 contain namespace info, if there is any.
22084 Return the computed name or NULL.
22085 Space for the result is allocated on the objfile's obstack.
22086 This is the full-die version of guess_partial_die_structure_name.
22087 In this case we know DIE has no useful parent. */
22090 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22092 struct die_info
*spec_die
;
22093 struct dwarf2_cu
*spec_cu
;
22094 struct die_info
*child
;
22095 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22098 spec_die
= die_specification (die
, &spec_cu
);
22099 if (spec_die
!= NULL
)
22105 for (child
= die
->child
;
22107 child
= child
->sibling
)
22109 if (child
->tag
== DW_TAG_subprogram
)
22111 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22113 if (linkage_name
!= NULL
)
22116 = language_class_name_from_physname (cu
->language_defn
,
22120 if (actual_name
!= NULL
)
22122 const char *die_name
= dwarf2_name (die
, cu
);
22124 if (die_name
!= NULL
22125 && strcmp (die_name
, actual_name
) != 0)
22127 /* Strip off the class name from the full name.
22128 We want the prefix. */
22129 int die_name_len
= strlen (die_name
);
22130 int actual_name_len
= strlen (actual_name
);
22132 /* Test for '::' as a sanity check. */
22133 if (actual_name_len
> die_name_len
+ 2
22134 && actual_name
[actual_name_len
22135 - die_name_len
- 1] == ':')
22136 name
= (char *) obstack_copy0 (
22137 &objfile
->per_bfd
->storage_obstack
,
22138 actual_name
, actual_name_len
- die_name_len
- 2);
22141 xfree (actual_name
);
22150 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22151 prefix part in such case. See
22152 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22154 static const char *
22155 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22157 struct attribute
*attr
;
22160 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22161 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22164 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22167 attr
= dw2_linkage_name_attr (die
, cu
);
22168 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22171 /* dwarf2_name had to be already called. */
22172 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22174 /* Strip the base name, keep any leading namespaces/classes. */
22175 base
= strrchr (DW_STRING (attr
), ':');
22176 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22179 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22180 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22182 &base
[-1] - DW_STRING (attr
));
22185 /* Return the name of the namespace/class that DIE is defined within,
22186 or "" if we can't tell. The caller should not xfree the result.
22188 For example, if we're within the method foo() in the following
22198 then determine_prefix on foo's die will return "N::C". */
22200 static const char *
22201 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22203 struct dwarf2_per_objfile
*dwarf2_per_objfile
22204 = cu
->per_cu
->dwarf2_per_objfile
;
22205 struct die_info
*parent
, *spec_die
;
22206 struct dwarf2_cu
*spec_cu
;
22207 struct type
*parent_type
;
22208 const char *retval
;
22210 if (cu
->language
!= language_cplus
22211 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22212 && cu
->language
!= language_rust
)
22215 retval
= anonymous_struct_prefix (die
, cu
);
22219 /* We have to be careful in the presence of DW_AT_specification.
22220 For example, with GCC 3.4, given the code
22224 // Definition of N::foo.
22228 then we'll have a tree of DIEs like this:
22230 1: DW_TAG_compile_unit
22231 2: DW_TAG_namespace // N
22232 3: DW_TAG_subprogram // declaration of N::foo
22233 4: DW_TAG_subprogram // definition of N::foo
22234 DW_AT_specification // refers to die #3
22236 Thus, when processing die #4, we have to pretend that we're in
22237 the context of its DW_AT_specification, namely the contex of die
22240 spec_die
= die_specification (die
, &spec_cu
);
22241 if (spec_die
== NULL
)
22242 parent
= die
->parent
;
22245 parent
= spec_die
->parent
;
22249 if (parent
== NULL
)
22251 else if (parent
->building_fullname
)
22254 const char *parent_name
;
22256 /* It has been seen on RealView 2.2 built binaries,
22257 DW_TAG_template_type_param types actually _defined_ as
22258 children of the parent class:
22261 template class <class Enum> Class{};
22262 Class<enum E> class_e;
22264 1: DW_TAG_class_type (Class)
22265 2: DW_TAG_enumeration_type (E)
22266 3: DW_TAG_enumerator (enum1:0)
22267 3: DW_TAG_enumerator (enum2:1)
22269 2: DW_TAG_template_type_param
22270 DW_AT_type DW_FORM_ref_udata (E)
22272 Besides being broken debug info, it can put GDB into an
22273 infinite loop. Consider:
22275 When we're building the full name for Class<E>, we'll start
22276 at Class, and go look over its template type parameters,
22277 finding E. We'll then try to build the full name of E, and
22278 reach here. We're now trying to build the full name of E,
22279 and look over the parent DIE for containing scope. In the
22280 broken case, if we followed the parent DIE of E, we'd again
22281 find Class, and once again go look at its template type
22282 arguments, etc., etc. Simply don't consider such parent die
22283 as source-level parent of this die (it can't be, the language
22284 doesn't allow it), and break the loop here. */
22285 name
= dwarf2_name (die
, cu
);
22286 parent_name
= dwarf2_name (parent
, cu
);
22287 complaint (&symfile_complaints
,
22288 _("template param type '%s' defined within parent '%s'"),
22289 name
? name
: "<unknown>",
22290 parent_name
? parent_name
: "<unknown>");
22294 switch (parent
->tag
)
22296 case DW_TAG_namespace
:
22297 parent_type
= read_type_die (parent
, cu
);
22298 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22299 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22300 Work around this problem here. */
22301 if (cu
->language
== language_cplus
22302 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22304 /* We give a name to even anonymous namespaces. */
22305 return TYPE_TAG_NAME (parent_type
);
22306 case DW_TAG_class_type
:
22307 case DW_TAG_interface_type
:
22308 case DW_TAG_structure_type
:
22309 case DW_TAG_union_type
:
22310 case DW_TAG_module
:
22311 parent_type
= read_type_die (parent
, cu
);
22312 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22313 return TYPE_TAG_NAME (parent_type
);
22315 /* An anonymous structure is only allowed non-static data
22316 members; no typedefs, no member functions, et cetera.
22317 So it does not need a prefix. */
22319 case DW_TAG_compile_unit
:
22320 case DW_TAG_partial_unit
:
22321 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22322 if (cu
->language
== language_cplus
22323 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22324 && die
->child
!= NULL
22325 && (die
->tag
== DW_TAG_class_type
22326 || die
->tag
== DW_TAG_structure_type
22327 || die
->tag
== DW_TAG_union_type
))
22329 char *name
= guess_full_die_structure_name (die
, cu
);
22334 case DW_TAG_enumeration_type
:
22335 parent_type
= read_type_die (parent
, cu
);
22336 if (TYPE_DECLARED_CLASS (parent_type
))
22338 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22339 return TYPE_TAG_NAME (parent_type
);
22342 /* Fall through. */
22344 return determine_prefix (parent
, cu
);
22348 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22349 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22350 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22351 an obconcat, otherwise allocate storage for the result. The CU argument is
22352 used to determine the language and hence, the appropriate separator. */
22354 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22357 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22358 int physname
, struct dwarf2_cu
*cu
)
22360 const char *lead
= "";
22363 if (suffix
== NULL
|| suffix
[0] == '\0'
22364 || prefix
== NULL
|| prefix
[0] == '\0')
22366 else if (cu
->language
== language_d
)
22368 /* For D, the 'main' function could be defined in any module, but it
22369 should never be prefixed. */
22370 if (strcmp (suffix
, "D main") == 0)
22378 else if (cu
->language
== language_fortran
&& physname
)
22380 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22381 DW_AT_MIPS_linkage_name is preferred and used instead. */
22389 if (prefix
== NULL
)
22391 if (suffix
== NULL
)
22398 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22400 strcpy (retval
, lead
);
22401 strcat (retval
, prefix
);
22402 strcat (retval
, sep
);
22403 strcat (retval
, suffix
);
22408 /* We have an obstack. */
22409 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22413 /* Return sibling of die, NULL if no sibling. */
22415 static struct die_info
*
22416 sibling_die (struct die_info
*die
)
22418 return die
->sibling
;
22421 /* Get name of a die, return NULL if not found. */
22423 static const char *
22424 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22425 struct obstack
*obstack
)
22427 if (name
&& cu
->language
== language_cplus
)
22429 std::string canon_name
= cp_canonicalize_string (name
);
22431 if (!canon_name
.empty ())
22433 if (canon_name
!= name
)
22434 name
= (const char *) obstack_copy0 (obstack
,
22435 canon_name
.c_str (),
22436 canon_name
.length ());
22443 /* Get name of a die, return NULL if not found.
22444 Anonymous namespaces are converted to their magic string. */
22446 static const char *
22447 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22449 struct attribute
*attr
;
22450 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22452 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22453 if ((!attr
|| !DW_STRING (attr
))
22454 && die
->tag
!= DW_TAG_namespace
22455 && die
->tag
!= DW_TAG_class_type
22456 && die
->tag
!= DW_TAG_interface_type
22457 && die
->tag
!= DW_TAG_structure_type
22458 && die
->tag
!= DW_TAG_union_type
)
22463 case DW_TAG_compile_unit
:
22464 case DW_TAG_partial_unit
:
22465 /* Compilation units have a DW_AT_name that is a filename, not
22466 a source language identifier. */
22467 case DW_TAG_enumeration_type
:
22468 case DW_TAG_enumerator
:
22469 /* These tags always have simple identifiers already; no need
22470 to canonicalize them. */
22471 return DW_STRING (attr
);
22473 case DW_TAG_namespace
:
22474 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22475 return DW_STRING (attr
);
22476 return CP_ANONYMOUS_NAMESPACE_STR
;
22478 case DW_TAG_class_type
:
22479 case DW_TAG_interface_type
:
22480 case DW_TAG_structure_type
:
22481 case DW_TAG_union_type
:
22482 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22483 structures or unions. These were of the form "._%d" in GCC 4.1,
22484 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22485 and GCC 4.4. We work around this problem by ignoring these. */
22486 if (attr
&& DW_STRING (attr
)
22487 && (startswith (DW_STRING (attr
), "._")
22488 || startswith (DW_STRING (attr
), "<anonymous")))
22491 /* GCC might emit a nameless typedef that has a linkage name. See
22492 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22493 if (!attr
|| DW_STRING (attr
) == NULL
)
22495 char *demangled
= NULL
;
22497 attr
= dw2_linkage_name_attr (die
, cu
);
22498 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22501 /* Avoid demangling DW_STRING (attr) the second time on a second
22502 call for the same DIE. */
22503 if (!DW_STRING_IS_CANONICAL (attr
))
22504 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22510 /* FIXME: we already did this for the partial symbol... */
22513 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22514 demangled
, strlen (demangled
)));
22515 DW_STRING_IS_CANONICAL (attr
) = 1;
22518 /* Strip any leading namespaces/classes, keep only the base name.
22519 DW_AT_name for named DIEs does not contain the prefixes. */
22520 base
= strrchr (DW_STRING (attr
), ':');
22521 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22524 return DW_STRING (attr
);
22533 if (!DW_STRING_IS_CANONICAL (attr
))
22536 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22537 &objfile
->per_bfd
->storage_obstack
);
22538 DW_STRING_IS_CANONICAL (attr
) = 1;
22540 return DW_STRING (attr
);
22543 /* Return the die that this die in an extension of, or NULL if there
22544 is none. *EXT_CU is the CU containing DIE on input, and the CU
22545 containing the return value on output. */
22547 static struct die_info
*
22548 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22550 struct attribute
*attr
;
22552 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22556 return follow_die_ref (die
, attr
, ext_cu
);
22559 /* Convert a DIE tag into its string name. */
22561 static const char *
22562 dwarf_tag_name (unsigned tag
)
22564 const char *name
= get_DW_TAG_name (tag
);
22567 return "DW_TAG_<unknown>";
22572 /* Convert a DWARF attribute code into its string name. */
22574 static const char *
22575 dwarf_attr_name (unsigned attr
)
22579 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22580 if (attr
== DW_AT_MIPS_fde
)
22581 return "DW_AT_MIPS_fde";
22583 if (attr
== DW_AT_HP_block_index
)
22584 return "DW_AT_HP_block_index";
22587 name
= get_DW_AT_name (attr
);
22590 return "DW_AT_<unknown>";
22595 /* Convert a DWARF value form code into its string name. */
22597 static const char *
22598 dwarf_form_name (unsigned form
)
22600 const char *name
= get_DW_FORM_name (form
);
22603 return "DW_FORM_<unknown>";
22608 static const char *
22609 dwarf_bool_name (unsigned mybool
)
22617 /* Convert a DWARF type code into its string name. */
22619 static const char *
22620 dwarf_type_encoding_name (unsigned enc
)
22622 const char *name
= get_DW_ATE_name (enc
);
22625 return "DW_ATE_<unknown>";
22631 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22635 print_spaces (indent
, f
);
22636 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
22637 dwarf_tag_name (die
->tag
), die
->abbrev
,
22638 to_underlying (die
->sect_off
));
22640 if (die
->parent
!= NULL
)
22642 print_spaces (indent
, f
);
22643 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
22644 to_underlying (die
->parent
->sect_off
));
22647 print_spaces (indent
, f
);
22648 fprintf_unfiltered (f
, " has children: %s\n",
22649 dwarf_bool_name (die
->child
!= NULL
));
22651 print_spaces (indent
, f
);
22652 fprintf_unfiltered (f
, " attributes:\n");
22654 for (i
= 0; i
< die
->num_attrs
; ++i
)
22656 print_spaces (indent
, f
);
22657 fprintf_unfiltered (f
, " %s (%s) ",
22658 dwarf_attr_name (die
->attrs
[i
].name
),
22659 dwarf_form_name (die
->attrs
[i
].form
));
22661 switch (die
->attrs
[i
].form
)
22664 case DW_FORM_GNU_addr_index
:
22665 fprintf_unfiltered (f
, "address: ");
22666 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22668 case DW_FORM_block2
:
22669 case DW_FORM_block4
:
22670 case DW_FORM_block
:
22671 case DW_FORM_block1
:
22672 fprintf_unfiltered (f
, "block: size %s",
22673 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22675 case DW_FORM_exprloc
:
22676 fprintf_unfiltered (f
, "expression: size %s",
22677 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22679 case DW_FORM_data16
:
22680 fprintf_unfiltered (f
, "constant of 16 bytes");
22682 case DW_FORM_ref_addr
:
22683 fprintf_unfiltered (f
, "ref address: ");
22684 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22686 case DW_FORM_GNU_ref_alt
:
22687 fprintf_unfiltered (f
, "alt ref address: ");
22688 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22694 case DW_FORM_ref_udata
:
22695 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22696 (long) (DW_UNSND (&die
->attrs
[i
])));
22698 case DW_FORM_data1
:
22699 case DW_FORM_data2
:
22700 case DW_FORM_data4
:
22701 case DW_FORM_data8
:
22702 case DW_FORM_udata
:
22703 case DW_FORM_sdata
:
22704 fprintf_unfiltered (f
, "constant: %s",
22705 pulongest (DW_UNSND (&die
->attrs
[i
])));
22707 case DW_FORM_sec_offset
:
22708 fprintf_unfiltered (f
, "section offset: %s",
22709 pulongest (DW_UNSND (&die
->attrs
[i
])));
22711 case DW_FORM_ref_sig8
:
22712 fprintf_unfiltered (f
, "signature: %s",
22713 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22715 case DW_FORM_string
:
22717 case DW_FORM_line_strp
:
22718 case DW_FORM_GNU_str_index
:
22719 case DW_FORM_GNU_strp_alt
:
22720 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22721 DW_STRING (&die
->attrs
[i
])
22722 ? DW_STRING (&die
->attrs
[i
]) : "",
22723 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22726 if (DW_UNSND (&die
->attrs
[i
]))
22727 fprintf_unfiltered (f
, "flag: TRUE");
22729 fprintf_unfiltered (f
, "flag: FALSE");
22731 case DW_FORM_flag_present
:
22732 fprintf_unfiltered (f
, "flag: TRUE");
22734 case DW_FORM_indirect
:
22735 /* The reader will have reduced the indirect form to
22736 the "base form" so this form should not occur. */
22737 fprintf_unfiltered (f
,
22738 "unexpected attribute form: DW_FORM_indirect");
22740 case DW_FORM_implicit_const
:
22741 fprintf_unfiltered (f
, "constant: %s",
22742 plongest (DW_SND (&die
->attrs
[i
])));
22745 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22746 die
->attrs
[i
].form
);
22749 fprintf_unfiltered (f
, "\n");
22754 dump_die_for_error (struct die_info
*die
)
22756 dump_die_shallow (gdb_stderr
, 0, die
);
22760 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22762 int indent
= level
* 4;
22764 gdb_assert (die
!= NULL
);
22766 if (level
>= max_level
)
22769 dump_die_shallow (f
, indent
, die
);
22771 if (die
->child
!= NULL
)
22773 print_spaces (indent
, f
);
22774 fprintf_unfiltered (f
, " Children:");
22775 if (level
+ 1 < max_level
)
22777 fprintf_unfiltered (f
, "\n");
22778 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22782 fprintf_unfiltered (f
,
22783 " [not printed, max nesting level reached]\n");
22787 if (die
->sibling
!= NULL
&& level
> 0)
22789 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22793 /* This is called from the pdie macro in gdbinit.in.
22794 It's not static so gcc will keep a copy callable from gdb. */
22797 dump_die (struct die_info
*die
, int max_level
)
22799 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22803 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22807 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22808 to_underlying (die
->sect_off
),
22814 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22818 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22820 if (attr_form_is_ref (attr
))
22821 return (sect_offset
) DW_UNSND (attr
);
22823 complaint (&symfile_complaints
,
22824 _("unsupported die ref attribute form: '%s'"),
22825 dwarf_form_name (attr
->form
));
22829 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22830 * the value held by the attribute is not constant. */
22833 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22835 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22836 return DW_SND (attr
);
22837 else if (attr
->form
== DW_FORM_udata
22838 || attr
->form
== DW_FORM_data1
22839 || attr
->form
== DW_FORM_data2
22840 || attr
->form
== DW_FORM_data4
22841 || attr
->form
== DW_FORM_data8
)
22842 return DW_UNSND (attr
);
22845 /* For DW_FORM_data16 see attr_form_is_constant. */
22846 complaint (&symfile_complaints
,
22847 _("Attribute value is not a constant (%s)"),
22848 dwarf_form_name (attr
->form
));
22849 return default_value
;
22853 /* Follow reference or signature attribute ATTR of SRC_DIE.
22854 On entry *REF_CU is the CU of SRC_DIE.
22855 On exit *REF_CU is the CU of the result. */
22857 static struct die_info
*
22858 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22859 struct dwarf2_cu
**ref_cu
)
22861 struct die_info
*die
;
22863 if (attr_form_is_ref (attr
))
22864 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22865 else if (attr
->form
== DW_FORM_ref_sig8
)
22866 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22869 dump_die_for_error (src_die
);
22870 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22871 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22877 /* Follow reference OFFSET.
22878 On entry *REF_CU is the CU of the source die referencing OFFSET.
22879 On exit *REF_CU is the CU of the result.
22880 Returns NULL if OFFSET is invalid. */
22882 static struct die_info
*
22883 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22884 struct dwarf2_cu
**ref_cu
)
22886 struct die_info temp_die
;
22887 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22888 struct dwarf2_per_objfile
*dwarf2_per_objfile
22889 = cu
->per_cu
->dwarf2_per_objfile
;
22890 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22892 gdb_assert (cu
->per_cu
!= NULL
);
22896 if (cu
->per_cu
->is_debug_types
)
22898 /* .debug_types CUs cannot reference anything outside their CU.
22899 If they need to, they have to reference a signatured type via
22900 DW_FORM_ref_sig8. */
22901 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22904 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22905 || !offset_in_cu_p (&cu
->header
, sect_off
))
22907 struct dwarf2_per_cu_data
*per_cu
;
22909 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22910 dwarf2_per_objfile
);
22912 /* If necessary, add it to the queue and load its DIEs. */
22913 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22914 load_full_comp_unit (per_cu
, cu
->language
);
22916 target_cu
= per_cu
->cu
;
22918 else if (cu
->dies
== NULL
)
22920 /* We're loading full DIEs during partial symbol reading. */
22921 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22922 load_full_comp_unit (cu
->per_cu
, language_minimal
);
22925 *ref_cu
= target_cu
;
22926 temp_die
.sect_off
= sect_off
;
22927 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22929 to_underlying (sect_off
));
22932 /* Follow reference attribute ATTR of SRC_DIE.
22933 On entry *REF_CU is the CU of SRC_DIE.
22934 On exit *REF_CU is the CU of the result. */
22936 static struct die_info
*
22937 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22938 struct dwarf2_cu
**ref_cu
)
22940 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22941 struct dwarf2_cu
*cu
= *ref_cu
;
22942 struct die_info
*die
;
22944 die
= follow_die_offset (sect_off
,
22945 (attr
->form
== DW_FORM_GNU_ref_alt
22946 || cu
->per_cu
->is_dwz
),
22949 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
22950 "at 0x%x [in module %s]"),
22951 to_underlying (sect_off
), to_underlying (src_die
->sect_off
),
22952 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22957 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22958 Returned value is intended for DW_OP_call*. Returned
22959 dwarf2_locexpr_baton->data has lifetime of
22960 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22962 struct dwarf2_locexpr_baton
22963 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22964 struct dwarf2_per_cu_data
*per_cu
,
22965 CORE_ADDR (*get_frame_pc
) (void *baton
),
22968 struct dwarf2_cu
*cu
;
22969 struct die_info
*die
;
22970 struct attribute
*attr
;
22971 struct dwarf2_locexpr_baton retval
;
22972 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22973 struct dwarf2_per_objfile
*dwarf2_per_objfile
22974 = get_dwarf2_per_objfile (objfile
);
22976 if (per_cu
->cu
== NULL
)
22981 /* We shouldn't get here for a dummy CU, but don't crash on the user.
22982 Instead just throw an error, not much else we can do. */
22983 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
22984 to_underlying (sect_off
), objfile_name (objfile
));
22987 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
22989 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
22990 to_underlying (sect_off
), objfile_name (objfile
));
22992 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22995 /* DWARF: "If there is no such attribute, then there is no effect.".
22996 DATA is ignored if SIZE is 0. */
22998 retval
.data
= NULL
;
23001 else if (attr_form_is_section_offset (attr
))
23003 struct dwarf2_loclist_baton loclist_baton
;
23004 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23007 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23009 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23011 retval
.size
= size
;
23015 if (!attr_form_is_block (attr
))
23016 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
23017 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23018 to_underlying (sect_off
), objfile_name (objfile
));
23020 retval
.data
= DW_BLOCK (attr
)->data
;
23021 retval
.size
= DW_BLOCK (attr
)->size
;
23023 retval
.per_cu
= cu
->per_cu
;
23025 age_cached_comp_units (dwarf2_per_objfile
);
23030 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23033 struct dwarf2_locexpr_baton
23034 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23035 struct dwarf2_per_cu_data
*per_cu
,
23036 CORE_ADDR (*get_frame_pc
) (void *baton
),
23039 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23041 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23044 /* Write a constant of a given type as target-ordered bytes into
23047 static const gdb_byte
*
23048 write_constant_as_bytes (struct obstack
*obstack
,
23049 enum bfd_endian byte_order
,
23056 *len
= TYPE_LENGTH (type
);
23057 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23058 store_unsigned_integer (result
, *len
, byte_order
, value
);
23063 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23064 pointer to the constant bytes and set LEN to the length of the
23065 data. If memory is needed, allocate it on OBSTACK. If the DIE
23066 does not have a DW_AT_const_value, return NULL. */
23069 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23070 struct dwarf2_per_cu_data
*per_cu
,
23071 struct obstack
*obstack
,
23074 struct dwarf2_cu
*cu
;
23075 struct die_info
*die
;
23076 struct attribute
*attr
;
23077 const gdb_byte
*result
= NULL
;
23080 enum bfd_endian byte_order
;
23081 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23083 if (per_cu
->cu
== NULL
)
23088 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23089 Instead just throw an error, not much else we can do. */
23090 error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
23091 to_underlying (sect_off
), objfile_name (objfile
));
23094 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23096 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
23097 to_underlying (sect_off
), objfile_name (objfile
));
23100 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23104 byte_order
= (bfd_big_endian (objfile
->obfd
)
23105 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23107 switch (attr
->form
)
23110 case DW_FORM_GNU_addr_index
:
23114 *len
= cu
->header
.addr_size
;
23115 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23116 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23120 case DW_FORM_string
:
23122 case DW_FORM_GNU_str_index
:
23123 case DW_FORM_GNU_strp_alt
:
23124 /* DW_STRING is already allocated on the objfile obstack, point
23126 result
= (const gdb_byte
*) DW_STRING (attr
);
23127 *len
= strlen (DW_STRING (attr
));
23129 case DW_FORM_block1
:
23130 case DW_FORM_block2
:
23131 case DW_FORM_block4
:
23132 case DW_FORM_block
:
23133 case DW_FORM_exprloc
:
23134 case DW_FORM_data16
:
23135 result
= DW_BLOCK (attr
)->data
;
23136 *len
= DW_BLOCK (attr
)->size
;
23139 /* The DW_AT_const_value attributes are supposed to carry the
23140 symbol's value "represented as it would be on the target
23141 architecture." By the time we get here, it's already been
23142 converted to host endianness, so we just need to sign- or
23143 zero-extend it as appropriate. */
23144 case DW_FORM_data1
:
23145 type
= die_type (die
, cu
);
23146 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23147 if (result
== NULL
)
23148 result
= write_constant_as_bytes (obstack
, byte_order
,
23151 case DW_FORM_data2
:
23152 type
= die_type (die
, cu
);
23153 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23154 if (result
== NULL
)
23155 result
= write_constant_as_bytes (obstack
, byte_order
,
23158 case DW_FORM_data4
:
23159 type
= die_type (die
, cu
);
23160 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23161 if (result
== NULL
)
23162 result
= write_constant_as_bytes (obstack
, byte_order
,
23165 case DW_FORM_data8
:
23166 type
= die_type (die
, cu
);
23167 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23168 if (result
== NULL
)
23169 result
= write_constant_as_bytes (obstack
, byte_order
,
23173 case DW_FORM_sdata
:
23174 case DW_FORM_implicit_const
:
23175 type
= die_type (die
, cu
);
23176 result
= write_constant_as_bytes (obstack
, byte_order
,
23177 type
, DW_SND (attr
), len
);
23180 case DW_FORM_udata
:
23181 type
= die_type (die
, cu
);
23182 result
= write_constant_as_bytes (obstack
, byte_order
,
23183 type
, DW_UNSND (attr
), len
);
23187 complaint (&symfile_complaints
,
23188 _("unsupported const value attribute form: '%s'"),
23189 dwarf_form_name (attr
->form
));
23196 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23197 valid type for this die is found. */
23200 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23201 struct dwarf2_per_cu_data
*per_cu
)
23203 struct dwarf2_cu
*cu
;
23204 struct die_info
*die
;
23206 if (per_cu
->cu
== NULL
)
23212 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23216 return die_type (die
, cu
);
23219 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23223 dwarf2_get_die_type (cu_offset die_offset
,
23224 struct dwarf2_per_cu_data
*per_cu
)
23226 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23227 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23230 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23231 On entry *REF_CU is the CU of SRC_DIE.
23232 On exit *REF_CU is the CU of the result.
23233 Returns NULL if the referenced DIE isn't found. */
23235 static struct die_info
*
23236 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23237 struct dwarf2_cu
**ref_cu
)
23239 struct die_info temp_die
;
23240 struct dwarf2_cu
*sig_cu
;
23241 struct die_info
*die
;
23243 /* While it might be nice to assert sig_type->type == NULL here,
23244 we can get here for DW_AT_imported_declaration where we need
23245 the DIE not the type. */
23247 /* If necessary, add it to the queue and load its DIEs. */
23249 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23250 read_signatured_type (sig_type
);
23252 sig_cu
= sig_type
->per_cu
.cu
;
23253 gdb_assert (sig_cu
!= NULL
);
23254 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23255 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23256 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23257 to_underlying (temp_die
.sect_off
));
23260 struct dwarf2_per_objfile
*dwarf2_per_objfile
23261 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23263 /* For .gdb_index version 7 keep track of included TUs.
23264 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23265 if (dwarf2_per_objfile
->index_table
!= NULL
23266 && dwarf2_per_objfile
->index_table
->version
<= 7)
23268 VEC_safe_push (dwarf2_per_cu_ptr
,
23269 (*ref_cu
)->per_cu
->imported_symtabs
,
23280 /* Follow signatured type referenced by ATTR in SRC_DIE.
23281 On entry *REF_CU is the CU of SRC_DIE.
23282 On exit *REF_CU is the CU of the result.
23283 The result is the DIE of the type.
23284 If the referenced type cannot be found an error is thrown. */
23286 static struct die_info
*
23287 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23288 struct dwarf2_cu
**ref_cu
)
23290 ULONGEST signature
= DW_SIGNATURE (attr
);
23291 struct signatured_type
*sig_type
;
23292 struct die_info
*die
;
23294 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23296 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23297 /* sig_type will be NULL if the signatured type is missing from
23299 if (sig_type
== NULL
)
23301 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23302 " from DIE at 0x%x [in module %s]"),
23303 hex_string (signature
), to_underlying (src_die
->sect_off
),
23304 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23307 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23310 dump_die_for_error (src_die
);
23311 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23312 " from DIE at 0x%x [in module %s]"),
23313 hex_string (signature
), to_underlying (src_die
->sect_off
),
23314 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23320 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23321 reading in and processing the type unit if necessary. */
23323 static struct type
*
23324 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23325 struct dwarf2_cu
*cu
)
23327 struct dwarf2_per_objfile
*dwarf2_per_objfile
23328 = cu
->per_cu
->dwarf2_per_objfile
;
23329 struct signatured_type
*sig_type
;
23330 struct dwarf2_cu
*type_cu
;
23331 struct die_info
*type_die
;
23334 sig_type
= lookup_signatured_type (cu
, signature
);
23335 /* sig_type will be NULL if the signatured type is missing from
23337 if (sig_type
== NULL
)
23339 complaint (&symfile_complaints
,
23340 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23341 " from DIE at 0x%x [in module %s]"),
23342 hex_string (signature
), to_underlying (die
->sect_off
),
23343 objfile_name (dwarf2_per_objfile
->objfile
));
23344 return build_error_marker_type (cu
, die
);
23347 /* If we already know the type we're done. */
23348 if (sig_type
->type
!= NULL
)
23349 return sig_type
->type
;
23352 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23353 if (type_die
!= NULL
)
23355 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23356 is created. This is important, for example, because for c++ classes
23357 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23358 type
= read_type_die (type_die
, type_cu
);
23361 complaint (&symfile_complaints
,
23362 _("Dwarf Error: Cannot build signatured type %s"
23363 " referenced from DIE at 0x%x [in module %s]"),
23364 hex_string (signature
), to_underlying (die
->sect_off
),
23365 objfile_name (dwarf2_per_objfile
->objfile
));
23366 type
= build_error_marker_type (cu
, die
);
23371 complaint (&symfile_complaints
,
23372 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23373 " from DIE at 0x%x [in module %s]"),
23374 hex_string (signature
), to_underlying (die
->sect_off
),
23375 objfile_name (dwarf2_per_objfile
->objfile
));
23376 type
= build_error_marker_type (cu
, die
);
23378 sig_type
->type
= type
;
23383 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23384 reading in and processing the type unit if necessary. */
23386 static struct type
*
23387 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23388 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23390 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23391 if (attr_form_is_ref (attr
))
23393 struct dwarf2_cu
*type_cu
= cu
;
23394 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23396 return read_type_die (type_die
, type_cu
);
23398 else if (attr
->form
== DW_FORM_ref_sig8
)
23400 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23404 struct dwarf2_per_objfile
*dwarf2_per_objfile
23405 = cu
->per_cu
->dwarf2_per_objfile
;
23407 complaint (&symfile_complaints
,
23408 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23409 " at 0x%x [in module %s]"),
23410 dwarf_form_name (attr
->form
), to_underlying (die
->sect_off
),
23411 objfile_name (dwarf2_per_objfile
->objfile
));
23412 return build_error_marker_type (cu
, die
);
23416 /* Load the DIEs associated with type unit PER_CU into memory. */
23419 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23421 struct signatured_type
*sig_type
;
23423 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23424 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23426 /* We have the per_cu, but we need the signatured_type.
23427 Fortunately this is an easy translation. */
23428 gdb_assert (per_cu
->is_debug_types
);
23429 sig_type
= (struct signatured_type
*) per_cu
;
23431 gdb_assert (per_cu
->cu
== NULL
);
23433 read_signatured_type (sig_type
);
23435 gdb_assert (per_cu
->cu
!= NULL
);
23438 /* die_reader_func for read_signatured_type.
23439 This is identical to load_full_comp_unit_reader,
23440 but is kept separate for now. */
23443 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23444 const gdb_byte
*info_ptr
,
23445 struct die_info
*comp_unit_die
,
23449 struct dwarf2_cu
*cu
= reader
->cu
;
23451 gdb_assert (cu
->die_hash
== NULL
);
23453 htab_create_alloc_ex (cu
->header
.length
/ 12,
23457 &cu
->comp_unit_obstack
,
23458 hashtab_obstack_allocate
,
23459 dummy_obstack_deallocate
);
23462 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23463 &info_ptr
, comp_unit_die
);
23464 cu
->dies
= comp_unit_die
;
23465 /* comp_unit_die is not stored in die_hash, no need. */
23467 /* We try not to read any attributes in this function, because not
23468 all CUs needed for references have been loaded yet, and symbol
23469 table processing isn't initialized. But we have to set the CU language,
23470 or we won't be able to build types correctly.
23471 Similarly, if we do not read the producer, we can not apply
23472 producer-specific interpretation. */
23473 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23476 /* Read in a signatured type and build its CU and DIEs.
23477 If the type is a stub for the real type in a DWO file,
23478 read in the real type from the DWO file as well. */
23481 read_signatured_type (struct signatured_type
*sig_type
)
23483 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23485 gdb_assert (per_cu
->is_debug_types
);
23486 gdb_assert (per_cu
->cu
== NULL
);
23488 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23489 read_signatured_type_reader
, NULL
);
23490 sig_type
->per_cu
.tu_read
= 1;
23493 /* Decode simple location descriptions.
23494 Given a pointer to a dwarf block that defines a location, compute
23495 the location and return the value.
23497 NOTE drow/2003-11-18: This function is called in two situations
23498 now: for the address of static or global variables (partial symbols
23499 only) and for offsets into structures which are expected to be
23500 (more or less) constant. The partial symbol case should go away,
23501 and only the constant case should remain. That will let this
23502 function complain more accurately. A few special modes are allowed
23503 without complaint for global variables (for instance, global
23504 register values and thread-local values).
23506 A location description containing no operations indicates that the
23507 object is optimized out. The return value is 0 for that case.
23508 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23509 callers will only want a very basic result and this can become a
23512 Note that stack[0] is unused except as a default error return. */
23515 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23517 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23519 size_t size
= blk
->size
;
23520 const gdb_byte
*data
= blk
->data
;
23521 CORE_ADDR stack
[64];
23523 unsigned int bytes_read
, unsnd
;
23529 stack
[++stacki
] = 0;
23568 stack
[++stacki
] = op
- DW_OP_lit0
;
23603 stack
[++stacki
] = op
- DW_OP_reg0
;
23605 dwarf2_complex_location_expr_complaint ();
23609 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23611 stack
[++stacki
] = unsnd
;
23613 dwarf2_complex_location_expr_complaint ();
23617 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23622 case DW_OP_const1u
:
23623 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23627 case DW_OP_const1s
:
23628 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23632 case DW_OP_const2u
:
23633 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23637 case DW_OP_const2s
:
23638 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23642 case DW_OP_const4u
:
23643 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23647 case DW_OP_const4s
:
23648 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23652 case DW_OP_const8u
:
23653 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23658 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23664 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23669 stack
[stacki
+ 1] = stack
[stacki
];
23674 stack
[stacki
- 1] += stack
[stacki
];
23678 case DW_OP_plus_uconst
:
23679 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23685 stack
[stacki
- 1] -= stack
[stacki
];
23690 /* If we're not the last op, then we definitely can't encode
23691 this using GDB's address_class enum. This is valid for partial
23692 global symbols, although the variable's address will be bogus
23695 dwarf2_complex_location_expr_complaint ();
23698 case DW_OP_GNU_push_tls_address
:
23699 case DW_OP_form_tls_address
:
23700 /* The top of the stack has the offset from the beginning
23701 of the thread control block at which the variable is located. */
23702 /* Nothing should follow this operator, so the top of stack would
23704 /* This is valid for partial global symbols, but the variable's
23705 address will be bogus in the psymtab. Make it always at least
23706 non-zero to not look as a variable garbage collected by linker
23707 which have DW_OP_addr 0. */
23709 dwarf2_complex_location_expr_complaint ();
23713 case DW_OP_GNU_uninit
:
23716 case DW_OP_GNU_addr_index
:
23717 case DW_OP_GNU_const_index
:
23718 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23725 const char *name
= get_DW_OP_name (op
);
23728 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
23731 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
23735 return (stack
[stacki
]);
23738 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23739 outside of the allocated space. Also enforce minimum>0. */
23740 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23742 complaint (&symfile_complaints
,
23743 _("location description stack overflow"));
23749 complaint (&symfile_complaints
,
23750 _("location description stack underflow"));
23754 return (stack
[stacki
]);
23757 /* memory allocation interface */
23759 static struct dwarf_block
*
23760 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23762 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23765 static struct die_info
*
23766 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23768 struct die_info
*die
;
23769 size_t size
= sizeof (struct die_info
);
23772 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23774 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23775 memset (die
, 0, sizeof (struct die_info
));
23780 /* Macro support. */
23782 /* Return file name relative to the compilation directory of file number I in
23783 *LH's file name table. The result is allocated using xmalloc; the caller is
23784 responsible for freeing it. */
23787 file_file_name (int file
, struct line_header
*lh
)
23789 /* Is the file number a valid index into the line header's file name
23790 table? Remember that file numbers start with one, not zero. */
23791 if (1 <= file
&& file
<= lh
->file_names
.size ())
23793 const file_entry
&fe
= lh
->file_names
[file
- 1];
23795 if (!IS_ABSOLUTE_PATH (fe
.name
))
23797 const char *dir
= fe
.include_dir (lh
);
23799 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23801 return xstrdup (fe
.name
);
23805 /* The compiler produced a bogus file number. We can at least
23806 record the macro definitions made in the file, even if we
23807 won't be able to find the file by name. */
23808 char fake_name
[80];
23810 xsnprintf (fake_name
, sizeof (fake_name
),
23811 "<bad macro file number %d>", file
);
23813 complaint (&symfile_complaints
,
23814 _("bad file number in macro information (%d)"),
23817 return xstrdup (fake_name
);
23821 /* Return the full name of file number I in *LH's file name table.
23822 Use COMP_DIR as the name of the current directory of the
23823 compilation. The result is allocated using xmalloc; the caller is
23824 responsible for freeing it. */
23826 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23828 /* Is the file number a valid index into the line header's file name
23829 table? Remember that file numbers start with one, not zero. */
23830 if (1 <= file
&& file
<= lh
->file_names
.size ())
23832 char *relative
= file_file_name (file
, lh
);
23834 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23836 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23837 relative
, (char *) NULL
);
23840 return file_file_name (file
, lh
);
23844 static struct macro_source_file
*
23845 macro_start_file (int file
, int line
,
23846 struct macro_source_file
*current_file
,
23847 struct line_header
*lh
)
23849 /* File name relative to the compilation directory of this source file. */
23850 char *file_name
= file_file_name (file
, lh
);
23852 if (! current_file
)
23854 /* Note: We don't create a macro table for this compilation unit
23855 at all until we actually get a filename. */
23856 struct macro_table
*macro_table
= get_macro_table ();
23858 /* If we have no current file, then this must be the start_file
23859 directive for the compilation unit's main source file. */
23860 current_file
= macro_set_main (macro_table
, file_name
);
23861 macro_define_special (macro_table
);
23864 current_file
= macro_include (current_file
, line
, file_name
);
23868 return current_file
;
23871 static const char *
23872 consume_improper_spaces (const char *p
, const char *body
)
23876 complaint (&symfile_complaints
,
23877 _("macro definition contains spaces "
23878 "in formal argument list:\n`%s'"),
23890 parse_macro_definition (struct macro_source_file
*file
, int line
,
23895 /* The body string takes one of two forms. For object-like macro
23896 definitions, it should be:
23898 <macro name> " " <definition>
23900 For function-like macro definitions, it should be:
23902 <macro name> "() " <definition>
23904 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23906 Spaces may appear only where explicitly indicated, and in the
23909 The Dwarf 2 spec says that an object-like macro's name is always
23910 followed by a space, but versions of GCC around March 2002 omit
23911 the space when the macro's definition is the empty string.
23913 The Dwarf 2 spec says that there should be no spaces between the
23914 formal arguments in a function-like macro's formal argument list,
23915 but versions of GCC around March 2002 include spaces after the
23919 /* Find the extent of the macro name. The macro name is terminated
23920 by either a space or null character (for an object-like macro) or
23921 an opening paren (for a function-like macro). */
23922 for (p
= body
; *p
; p
++)
23923 if (*p
== ' ' || *p
== '(')
23926 if (*p
== ' ' || *p
== '\0')
23928 /* It's an object-like macro. */
23929 int name_len
= p
- body
;
23930 char *name
= savestring (body
, name_len
);
23931 const char *replacement
;
23934 replacement
= body
+ name_len
+ 1;
23937 dwarf2_macro_malformed_definition_complaint (body
);
23938 replacement
= body
+ name_len
;
23941 macro_define_object (file
, line
, name
, replacement
);
23945 else if (*p
== '(')
23947 /* It's a function-like macro. */
23948 char *name
= savestring (body
, p
- body
);
23951 char **argv
= XNEWVEC (char *, argv_size
);
23955 p
= consume_improper_spaces (p
, body
);
23957 /* Parse the formal argument list. */
23958 while (*p
&& *p
!= ')')
23960 /* Find the extent of the current argument name. */
23961 const char *arg_start
= p
;
23963 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23966 if (! *p
|| p
== arg_start
)
23967 dwarf2_macro_malformed_definition_complaint (body
);
23970 /* Make sure argv has room for the new argument. */
23971 if (argc
>= argv_size
)
23974 argv
= XRESIZEVEC (char *, argv
, argv_size
);
23977 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
23980 p
= consume_improper_spaces (p
, body
);
23982 /* Consume the comma, if present. */
23987 p
= consume_improper_spaces (p
, body
);
23996 /* Perfectly formed definition, no complaints. */
23997 macro_define_function (file
, line
, name
,
23998 argc
, (const char **) argv
,
24000 else if (*p
== '\0')
24002 /* Complain, but do define it. */
24003 dwarf2_macro_malformed_definition_complaint (body
);
24004 macro_define_function (file
, line
, name
,
24005 argc
, (const char **) argv
,
24009 /* Just complain. */
24010 dwarf2_macro_malformed_definition_complaint (body
);
24013 /* Just complain. */
24014 dwarf2_macro_malformed_definition_complaint (body
);
24020 for (i
= 0; i
< argc
; i
++)
24026 dwarf2_macro_malformed_definition_complaint (body
);
24029 /* Skip some bytes from BYTES according to the form given in FORM.
24030 Returns the new pointer. */
24032 static const gdb_byte
*
24033 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24034 enum dwarf_form form
,
24035 unsigned int offset_size
,
24036 struct dwarf2_section_info
*section
)
24038 unsigned int bytes_read
;
24042 case DW_FORM_data1
:
24047 case DW_FORM_data2
:
24051 case DW_FORM_data4
:
24055 case DW_FORM_data8
:
24059 case DW_FORM_data16
:
24063 case DW_FORM_string
:
24064 read_direct_string (abfd
, bytes
, &bytes_read
);
24065 bytes
+= bytes_read
;
24068 case DW_FORM_sec_offset
:
24070 case DW_FORM_GNU_strp_alt
:
24071 bytes
+= offset_size
;
24074 case DW_FORM_block
:
24075 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24076 bytes
+= bytes_read
;
24079 case DW_FORM_block1
:
24080 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24082 case DW_FORM_block2
:
24083 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24085 case DW_FORM_block4
:
24086 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24089 case DW_FORM_sdata
:
24090 case DW_FORM_udata
:
24091 case DW_FORM_GNU_addr_index
:
24092 case DW_FORM_GNU_str_index
:
24093 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24096 dwarf2_section_buffer_overflow_complaint (section
);
24101 case DW_FORM_implicit_const
:
24106 complaint (&symfile_complaints
,
24107 _("invalid form 0x%x in `%s'"),
24108 form
, get_section_name (section
));
24116 /* A helper for dwarf_decode_macros that handles skipping an unknown
24117 opcode. Returns an updated pointer to the macro data buffer; or,
24118 on error, issues a complaint and returns NULL. */
24120 static const gdb_byte
*
24121 skip_unknown_opcode (unsigned int opcode
,
24122 const gdb_byte
**opcode_definitions
,
24123 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24125 unsigned int offset_size
,
24126 struct dwarf2_section_info
*section
)
24128 unsigned int bytes_read
, i
;
24130 const gdb_byte
*defn
;
24132 if (opcode_definitions
[opcode
] == NULL
)
24134 complaint (&symfile_complaints
,
24135 _("unrecognized DW_MACFINO opcode 0x%x"),
24140 defn
= opcode_definitions
[opcode
];
24141 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24142 defn
+= bytes_read
;
24144 for (i
= 0; i
< arg
; ++i
)
24146 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24147 (enum dwarf_form
) defn
[i
], offset_size
,
24149 if (mac_ptr
== NULL
)
24151 /* skip_form_bytes already issued the complaint. */
24159 /* A helper function which parses the header of a macro section.
24160 If the macro section is the extended (for now called "GNU") type,
24161 then this updates *OFFSET_SIZE. Returns a pointer to just after
24162 the header, or issues a complaint and returns NULL on error. */
24164 static const gdb_byte
*
24165 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24167 const gdb_byte
*mac_ptr
,
24168 unsigned int *offset_size
,
24169 int section_is_gnu
)
24171 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24173 if (section_is_gnu
)
24175 unsigned int version
, flags
;
24177 version
= read_2_bytes (abfd
, mac_ptr
);
24178 if (version
!= 4 && version
!= 5)
24180 complaint (&symfile_complaints
,
24181 _("unrecognized version `%d' in .debug_macro section"),
24187 flags
= read_1_byte (abfd
, mac_ptr
);
24189 *offset_size
= (flags
& 1) ? 8 : 4;
24191 if ((flags
& 2) != 0)
24192 /* We don't need the line table offset. */
24193 mac_ptr
+= *offset_size
;
24195 /* Vendor opcode descriptions. */
24196 if ((flags
& 4) != 0)
24198 unsigned int i
, count
;
24200 count
= read_1_byte (abfd
, mac_ptr
);
24202 for (i
= 0; i
< count
; ++i
)
24204 unsigned int opcode
, bytes_read
;
24207 opcode
= read_1_byte (abfd
, mac_ptr
);
24209 opcode_definitions
[opcode
] = mac_ptr
;
24210 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24211 mac_ptr
+= bytes_read
;
24220 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24221 including DW_MACRO_import. */
24224 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24226 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24227 struct macro_source_file
*current_file
,
24228 struct line_header
*lh
,
24229 struct dwarf2_section_info
*section
,
24230 int section_is_gnu
, int section_is_dwz
,
24231 unsigned int offset_size
,
24232 htab_t include_hash
)
24234 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24235 enum dwarf_macro_record_type macinfo_type
;
24236 int at_commandline
;
24237 const gdb_byte
*opcode_definitions
[256];
24239 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24240 &offset_size
, section_is_gnu
);
24241 if (mac_ptr
== NULL
)
24243 /* We already issued a complaint. */
24247 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24248 GDB is still reading the definitions from command line. First
24249 DW_MACINFO_start_file will need to be ignored as it was already executed
24250 to create CURRENT_FILE for the main source holding also the command line
24251 definitions. On first met DW_MACINFO_start_file this flag is reset to
24252 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24254 at_commandline
= 1;
24258 /* Do we at least have room for a macinfo type byte? */
24259 if (mac_ptr
>= mac_end
)
24261 dwarf2_section_buffer_overflow_complaint (section
);
24265 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24268 /* Note that we rely on the fact that the corresponding GNU and
24269 DWARF constants are the same. */
24271 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24272 switch (macinfo_type
)
24274 /* A zero macinfo type indicates the end of the macro
24279 case DW_MACRO_define
:
24280 case DW_MACRO_undef
:
24281 case DW_MACRO_define_strp
:
24282 case DW_MACRO_undef_strp
:
24283 case DW_MACRO_define_sup
:
24284 case DW_MACRO_undef_sup
:
24286 unsigned int bytes_read
;
24291 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24292 mac_ptr
+= bytes_read
;
24294 if (macinfo_type
== DW_MACRO_define
24295 || macinfo_type
== DW_MACRO_undef
)
24297 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24298 mac_ptr
+= bytes_read
;
24302 LONGEST str_offset
;
24304 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24305 mac_ptr
+= offset_size
;
24307 if (macinfo_type
== DW_MACRO_define_sup
24308 || macinfo_type
== DW_MACRO_undef_sup
24311 struct dwz_file
*dwz
24312 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24314 body
= read_indirect_string_from_dwz (objfile
,
24318 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24322 is_define
= (macinfo_type
== DW_MACRO_define
24323 || macinfo_type
== DW_MACRO_define_strp
24324 || macinfo_type
== DW_MACRO_define_sup
);
24325 if (! current_file
)
24327 /* DWARF violation as no main source is present. */
24328 complaint (&symfile_complaints
,
24329 _("debug info with no main source gives macro %s "
24331 is_define
? _("definition") : _("undefinition"),
24335 if ((line
== 0 && !at_commandline
)
24336 || (line
!= 0 && at_commandline
))
24337 complaint (&symfile_complaints
,
24338 _("debug info gives %s macro %s with %s line %d: %s"),
24339 at_commandline
? _("command-line") : _("in-file"),
24340 is_define
? _("definition") : _("undefinition"),
24341 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24344 parse_macro_definition (current_file
, line
, body
);
24347 gdb_assert (macinfo_type
== DW_MACRO_undef
24348 || macinfo_type
== DW_MACRO_undef_strp
24349 || macinfo_type
== DW_MACRO_undef_sup
);
24350 macro_undef (current_file
, line
, body
);
24355 case DW_MACRO_start_file
:
24357 unsigned int bytes_read
;
24360 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24361 mac_ptr
+= bytes_read
;
24362 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24363 mac_ptr
+= bytes_read
;
24365 if ((line
== 0 && !at_commandline
)
24366 || (line
!= 0 && at_commandline
))
24367 complaint (&symfile_complaints
,
24368 _("debug info gives source %d included "
24369 "from %s at %s line %d"),
24370 file
, at_commandline
? _("command-line") : _("file"),
24371 line
== 0 ? _("zero") : _("non-zero"), line
);
24373 if (at_commandline
)
24375 /* This DW_MACRO_start_file was executed in the
24377 at_commandline
= 0;
24380 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24384 case DW_MACRO_end_file
:
24385 if (! current_file
)
24386 complaint (&symfile_complaints
,
24387 _("macro debug info has an unmatched "
24388 "`close_file' directive"));
24391 current_file
= current_file
->included_by
;
24392 if (! current_file
)
24394 enum dwarf_macro_record_type next_type
;
24396 /* GCC circa March 2002 doesn't produce the zero
24397 type byte marking the end of the compilation
24398 unit. Complain if it's not there, but exit no
24401 /* Do we at least have room for a macinfo type byte? */
24402 if (mac_ptr
>= mac_end
)
24404 dwarf2_section_buffer_overflow_complaint (section
);
24408 /* We don't increment mac_ptr here, so this is just
24411 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24413 if (next_type
!= 0)
24414 complaint (&symfile_complaints
,
24415 _("no terminating 0-type entry for "
24416 "macros in `.debug_macinfo' section"));
24423 case DW_MACRO_import
:
24424 case DW_MACRO_import_sup
:
24428 bfd
*include_bfd
= abfd
;
24429 struct dwarf2_section_info
*include_section
= section
;
24430 const gdb_byte
*include_mac_end
= mac_end
;
24431 int is_dwz
= section_is_dwz
;
24432 const gdb_byte
*new_mac_ptr
;
24434 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24435 mac_ptr
+= offset_size
;
24437 if (macinfo_type
== DW_MACRO_import_sup
)
24439 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24441 dwarf2_read_section (objfile
, &dwz
->macro
);
24443 include_section
= &dwz
->macro
;
24444 include_bfd
= get_section_bfd_owner (include_section
);
24445 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24449 new_mac_ptr
= include_section
->buffer
+ offset
;
24450 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24454 /* This has actually happened; see
24455 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24456 complaint (&symfile_complaints
,
24457 _("recursive DW_MACRO_import in "
24458 ".debug_macro section"));
24462 *slot
= (void *) new_mac_ptr
;
24464 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24465 include_bfd
, new_mac_ptr
,
24466 include_mac_end
, current_file
, lh
,
24467 section
, section_is_gnu
, is_dwz
,
24468 offset_size
, include_hash
);
24470 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24475 case DW_MACINFO_vendor_ext
:
24476 if (!section_is_gnu
)
24478 unsigned int bytes_read
;
24480 /* This reads the constant, but since we don't recognize
24481 any vendor extensions, we ignore it. */
24482 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24483 mac_ptr
+= bytes_read
;
24484 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24485 mac_ptr
+= bytes_read
;
24487 /* We don't recognize any vendor extensions. */
24493 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24494 mac_ptr
, mac_end
, abfd
, offset_size
,
24496 if (mac_ptr
== NULL
)
24501 } while (macinfo_type
!= 0);
24505 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24506 int section_is_gnu
)
24508 struct dwarf2_per_objfile
*dwarf2_per_objfile
24509 = cu
->per_cu
->dwarf2_per_objfile
;
24510 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24511 struct line_header
*lh
= cu
->line_header
;
24513 const gdb_byte
*mac_ptr
, *mac_end
;
24514 struct macro_source_file
*current_file
= 0;
24515 enum dwarf_macro_record_type macinfo_type
;
24516 unsigned int offset_size
= cu
->header
.offset_size
;
24517 const gdb_byte
*opcode_definitions
[256];
24519 struct dwarf2_section_info
*section
;
24520 const char *section_name
;
24522 if (cu
->dwo_unit
!= NULL
)
24524 if (section_is_gnu
)
24526 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24527 section_name
= ".debug_macro.dwo";
24531 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24532 section_name
= ".debug_macinfo.dwo";
24537 if (section_is_gnu
)
24539 section
= &dwarf2_per_objfile
->macro
;
24540 section_name
= ".debug_macro";
24544 section
= &dwarf2_per_objfile
->macinfo
;
24545 section_name
= ".debug_macinfo";
24549 dwarf2_read_section (objfile
, section
);
24550 if (section
->buffer
== NULL
)
24552 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24555 abfd
= get_section_bfd_owner (section
);
24557 /* First pass: Find the name of the base filename.
24558 This filename is needed in order to process all macros whose definition
24559 (or undefinition) comes from the command line. These macros are defined
24560 before the first DW_MACINFO_start_file entry, and yet still need to be
24561 associated to the base file.
24563 To determine the base file name, we scan the macro definitions until we
24564 reach the first DW_MACINFO_start_file entry. We then initialize
24565 CURRENT_FILE accordingly so that any macro definition found before the
24566 first DW_MACINFO_start_file can still be associated to the base file. */
24568 mac_ptr
= section
->buffer
+ offset
;
24569 mac_end
= section
->buffer
+ section
->size
;
24571 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24572 &offset_size
, section_is_gnu
);
24573 if (mac_ptr
== NULL
)
24575 /* We already issued a complaint. */
24581 /* Do we at least have room for a macinfo type byte? */
24582 if (mac_ptr
>= mac_end
)
24584 /* Complaint is printed during the second pass as GDB will probably
24585 stop the first pass earlier upon finding
24586 DW_MACINFO_start_file. */
24590 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24593 /* Note that we rely on the fact that the corresponding GNU and
24594 DWARF constants are the same. */
24596 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24597 switch (macinfo_type
)
24599 /* A zero macinfo type indicates the end of the macro
24604 case DW_MACRO_define
:
24605 case DW_MACRO_undef
:
24606 /* Only skip the data by MAC_PTR. */
24608 unsigned int bytes_read
;
24610 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24611 mac_ptr
+= bytes_read
;
24612 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24613 mac_ptr
+= bytes_read
;
24617 case DW_MACRO_start_file
:
24619 unsigned int bytes_read
;
24622 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24623 mac_ptr
+= bytes_read
;
24624 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24625 mac_ptr
+= bytes_read
;
24627 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24631 case DW_MACRO_end_file
:
24632 /* No data to skip by MAC_PTR. */
24635 case DW_MACRO_define_strp
:
24636 case DW_MACRO_undef_strp
:
24637 case DW_MACRO_define_sup
:
24638 case DW_MACRO_undef_sup
:
24640 unsigned int bytes_read
;
24642 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24643 mac_ptr
+= bytes_read
;
24644 mac_ptr
+= offset_size
;
24648 case DW_MACRO_import
:
24649 case DW_MACRO_import_sup
:
24650 /* Note that, according to the spec, a transparent include
24651 chain cannot call DW_MACRO_start_file. So, we can just
24652 skip this opcode. */
24653 mac_ptr
+= offset_size
;
24656 case DW_MACINFO_vendor_ext
:
24657 /* Only skip the data by MAC_PTR. */
24658 if (!section_is_gnu
)
24660 unsigned int bytes_read
;
24662 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24663 mac_ptr
+= bytes_read
;
24664 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24665 mac_ptr
+= bytes_read
;
24670 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24671 mac_ptr
, mac_end
, abfd
, offset_size
,
24673 if (mac_ptr
== NULL
)
24678 } while (macinfo_type
!= 0 && current_file
== NULL
);
24680 /* Second pass: Process all entries.
24682 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24683 command-line macro definitions/undefinitions. This flag is unset when we
24684 reach the first DW_MACINFO_start_file entry. */
24686 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24688 NULL
, xcalloc
, xfree
));
24689 mac_ptr
= section
->buffer
+ offset
;
24690 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24691 *slot
= (void *) mac_ptr
;
24692 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24693 abfd
, mac_ptr
, mac_end
,
24694 current_file
, lh
, section
,
24695 section_is_gnu
, 0, offset_size
,
24696 include_hash
.get ());
24699 /* Check if the attribute's form is a DW_FORM_block*
24700 if so return true else false. */
24703 attr_form_is_block (const struct attribute
*attr
)
24705 return (attr
== NULL
? 0 :
24706 attr
->form
== DW_FORM_block1
24707 || attr
->form
== DW_FORM_block2
24708 || attr
->form
== DW_FORM_block4
24709 || attr
->form
== DW_FORM_block
24710 || attr
->form
== DW_FORM_exprloc
);
24713 /* Return non-zero if ATTR's value is a section offset --- classes
24714 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24715 You may use DW_UNSND (attr) to retrieve such offsets.
24717 Section 7.5.4, "Attribute Encodings", explains that no attribute
24718 may have a value that belongs to more than one of these classes; it
24719 would be ambiguous if we did, because we use the same forms for all
24723 attr_form_is_section_offset (const struct attribute
*attr
)
24725 return (attr
->form
== DW_FORM_data4
24726 || attr
->form
== DW_FORM_data8
24727 || attr
->form
== DW_FORM_sec_offset
);
24730 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24731 zero otherwise. When this function returns true, you can apply
24732 dwarf2_get_attr_constant_value to it.
24734 However, note that for some attributes you must check
24735 attr_form_is_section_offset before using this test. DW_FORM_data4
24736 and DW_FORM_data8 are members of both the constant class, and of
24737 the classes that contain offsets into other debug sections
24738 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24739 that, if an attribute's can be either a constant or one of the
24740 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24741 taken as section offsets, not constants.
24743 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24744 cannot handle that. */
24747 attr_form_is_constant (const struct attribute
*attr
)
24749 switch (attr
->form
)
24751 case DW_FORM_sdata
:
24752 case DW_FORM_udata
:
24753 case DW_FORM_data1
:
24754 case DW_FORM_data2
:
24755 case DW_FORM_data4
:
24756 case DW_FORM_data8
:
24757 case DW_FORM_implicit_const
:
24765 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24766 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24769 attr_form_is_ref (const struct attribute
*attr
)
24771 switch (attr
->form
)
24773 case DW_FORM_ref_addr
:
24778 case DW_FORM_ref_udata
:
24779 case DW_FORM_GNU_ref_alt
:
24786 /* Return the .debug_loc section to use for CU.
24787 For DWO files use .debug_loc.dwo. */
24789 static struct dwarf2_section_info
*
24790 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24792 struct dwarf2_per_objfile
*dwarf2_per_objfile
24793 = cu
->per_cu
->dwarf2_per_objfile
;
24797 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24799 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24801 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24802 : &dwarf2_per_objfile
->loc
);
24805 /* A helper function that fills in a dwarf2_loclist_baton. */
24808 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24809 struct dwarf2_loclist_baton
*baton
,
24810 const struct attribute
*attr
)
24812 struct dwarf2_per_objfile
*dwarf2_per_objfile
24813 = cu
->per_cu
->dwarf2_per_objfile
;
24814 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24816 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
24818 baton
->per_cu
= cu
->per_cu
;
24819 gdb_assert (baton
->per_cu
);
24820 /* We don't know how long the location list is, but make sure we
24821 don't run off the edge of the section. */
24822 baton
->size
= section
->size
- DW_UNSND (attr
);
24823 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24824 baton
->base_address
= cu
->base_address
;
24825 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24829 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24830 struct dwarf2_cu
*cu
, int is_block
)
24832 struct dwarf2_per_objfile
*dwarf2_per_objfile
24833 = cu
->per_cu
->dwarf2_per_objfile
;
24834 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24835 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24837 if (attr_form_is_section_offset (attr
)
24838 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24839 the section. If so, fall through to the complaint in the
24841 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24843 struct dwarf2_loclist_baton
*baton
;
24845 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24847 fill_in_loclist_baton (cu
, baton
, attr
);
24849 if (cu
->base_known
== 0)
24850 complaint (&symfile_complaints
,
24851 _("Location list used without "
24852 "specifying the CU base address."));
24854 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24855 ? dwarf2_loclist_block_index
24856 : dwarf2_loclist_index
);
24857 SYMBOL_LOCATION_BATON (sym
) = baton
;
24861 struct dwarf2_locexpr_baton
*baton
;
24863 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24864 baton
->per_cu
= cu
->per_cu
;
24865 gdb_assert (baton
->per_cu
);
24867 if (attr_form_is_block (attr
))
24869 /* Note that we're just copying the block's data pointer
24870 here, not the actual data. We're still pointing into the
24871 info_buffer for SYM's objfile; right now we never release
24872 that buffer, but when we do clean up properly this may
24874 baton
->size
= DW_BLOCK (attr
)->size
;
24875 baton
->data
= DW_BLOCK (attr
)->data
;
24879 dwarf2_invalid_attrib_class_complaint ("location description",
24880 SYMBOL_NATURAL_NAME (sym
));
24884 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24885 ? dwarf2_locexpr_block_index
24886 : dwarf2_locexpr_index
);
24887 SYMBOL_LOCATION_BATON (sym
) = baton
;
24891 /* Return the OBJFILE associated with the compilation unit CU. If CU
24892 came from a separate debuginfo file, then the master objfile is
24896 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24898 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24900 /* Return the master objfile, so that we can report and look up the
24901 correct file containing this variable. */
24902 if (objfile
->separate_debug_objfile_backlink
)
24903 objfile
= objfile
->separate_debug_objfile_backlink
;
24908 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24909 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24910 CU_HEADERP first. */
24912 static const struct comp_unit_head
*
24913 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24914 struct dwarf2_per_cu_data
*per_cu
)
24916 const gdb_byte
*info_ptr
;
24919 return &per_cu
->cu
->header
;
24921 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24923 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24924 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24925 rcuh_kind::COMPILE
);
24930 /* Return the address size given in the compilation unit header for CU. */
24933 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24935 struct comp_unit_head cu_header_local
;
24936 const struct comp_unit_head
*cu_headerp
;
24938 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24940 return cu_headerp
->addr_size
;
24943 /* Return the offset size given in the compilation unit header for CU. */
24946 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24948 struct comp_unit_head cu_header_local
;
24949 const struct comp_unit_head
*cu_headerp
;
24951 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24953 return cu_headerp
->offset_size
;
24956 /* See its dwarf2loc.h declaration. */
24959 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24961 struct comp_unit_head cu_header_local
;
24962 const struct comp_unit_head
*cu_headerp
;
24964 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24966 if (cu_headerp
->version
== 2)
24967 return cu_headerp
->addr_size
;
24969 return cu_headerp
->offset_size
;
24972 /* Return the text offset of the CU. The returned offset comes from
24973 this CU's objfile. If this objfile came from a separate debuginfo
24974 file, then the offset may be different from the corresponding
24975 offset in the parent objfile. */
24978 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
24980 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24982 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
24985 /* Return DWARF version number of PER_CU. */
24988 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
24990 return per_cu
->dwarf_version
;
24993 /* Locate the .debug_info compilation unit from CU's objfile which contains
24994 the DIE at OFFSET. Raises an error on failure. */
24996 static struct dwarf2_per_cu_data
*
24997 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24998 unsigned int offset_in_dwz
,
24999 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25001 struct dwarf2_per_cu_data
*this_cu
;
25003 const sect_offset
*cu_off
;
25006 high
= dwarf2_per_objfile
->n_comp_units
- 1;
25009 struct dwarf2_per_cu_data
*mid_cu
;
25010 int mid
= low
+ (high
- low
) / 2;
25012 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25013 cu_off
= &mid_cu
->sect_off
;
25014 if (mid_cu
->is_dwz
> offset_in_dwz
25015 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25020 gdb_assert (low
== high
);
25021 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25022 cu_off
= &this_cu
->sect_off
;
25023 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25025 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25026 error (_("Dwarf Error: could not find partial DIE containing "
25027 "offset 0x%x [in module %s]"),
25028 to_underlying (sect_off
),
25029 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25031 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25033 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25037 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25038 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
25039 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25040 error (_("invalid dwarf2 offset %u"), to_underlying (sect_off
));
25041 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25046 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25048 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25049 : per_cu (per_cu_
),
25052 checked_producer (0),
25053 producer_is_gxx_lt_4_6 (0),
25054 producer_is_gcc_lt_4_3 (0),
25055 producer_is_icc_lt_14 (0),
25056 processing_has_namespace_info (0)
25061 /* Destroy a dwarf2_cu. */
25063 dwarf2_cu::~dwarf2_cu ()
25068 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25071 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25072 enum language pretend_language
)
25074 struct attribute
*attr
;
25076 /* Set the language we're debugging. */
25077 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25079 set_cu_language (DW_UNSND (attr
), cu
);
25082 cu
->language
= pretend_language
;
25083 cu
->language_defn
= language_def (cu
->language
);
25086 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25089 /* Free all cached compilation units. */
25092 free_cached_comp_units (void *data
)
25094 struct dwarf2_per_objfile
*dwarf2_per_objfile
25095 = (struct dwarf2_per_objfile
*) data
;
25097 dwarf2_per_objfile
->free_cached_comp_units ();
25100 /* Increase the age counter on each cached compilation unit, and free
25101 any that are too old. */
25104 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25106 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25108 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25109 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25110 while (per_cu
!= NULL
)
25112 per_cu
->cu
->last_used
++;
25113 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25114 dwarf2_mark (per_cu
->cu
);
25115 per_cu
= per_cu
->cu
->read_in_chain
;
25118 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25119 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25120 while (per_cu
!= NULL
)
25122 struct dwarf2_per_cu_data
*next_cu
;
25124 next_cu
= per_cu
->cu
->read_in_chain
;
25126 if (!per_cu
->cu
->mark
)
25129 *last_chain
= next_cu
;
25132 last_chain
= &per_cu
->cu
->read_in_chain
;
25138 /* Remove a single compilation unit from the cache. */
25141 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25143 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25144 struct dwarf2_per_objfile
*dwarf2_per_objfile
25145 = target_per_cu
->dwarf2_per_objfile
;
25147 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25148 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25149 while (per_cu
!= NULL
)
25151 struct dwarf2_per_cu_data
*next_cu
;
25153 next_cu
= per_cu
->cu
->read_in_chain
;
25155 if (per_cu
== target_per_cu
)
25159 *last_chain
= next_cu
;
25163 last_chain
= &per_cu
->cu
->read_in_chain
;
25169 /* Release all extra memory associated with OBJFILE. */
25172 dwarf2_free_objfile (struct objfile
*objfile
)
25174 struct dwarf2_per_objfile
*dwarf2_per_objfile
25175 = get_dwarf2_per_objfile (objfile
);
25177 if (dwarf2_per_objfile
== NULL
)
25180 dwarf2_per_objfile
->~dwarf2_per_objfile ();
25183 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25184 We store these in a hash table separate from the DIEs, and preserve them
25185 when the DIEs are flushed out of cache.
25187 The CU "per_cu" pointer is needed because offset alone is not enough to
25188 uniquely identify the type. A file may have multiple .debug_types sections,
25189 or the type may come from a DWO file. Furthermore, while it's more logical
25190 to use per_cu->section+offset, with Fission the section with the data is in
25191 the DWO file but we don't know that section at the point we need it.
25192 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25193 because we can enter the lookup routine, get_die_type_at_offset, from
25194 outside this file, and thus won't necessarily have PER_CU->cu.
25195 Fortunately, PER_CU is stable for the life of the objfile. */
25197 struct dwarf2_per_cu_offset_and_type
25199 const struct dwarf2_per_cu_data
*per_cu
;
25200 sect_offset sect_off
;
25204 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25207 per_cu_offset_and_type_hash (const void *item
)
25209 const struct dwarf2_per_cu_offset_and_type
*ofs
25210 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25212 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25215 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25218 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25220 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25221 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25222 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25223 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25225 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25226 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25229 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25230 table if necessary. For convenience, return TYPE.
25232 The DIEs reading must have careful ordering to:
25233 * Not cause infite loops trying to read in DIEs as a prerequisite for
25234 reading current DIE.
25235 * Not trying to dereference contents of still incompletely read in types
25236 while reading in other DIEs.
25237 * Enable referencing still incompletely read in types just by a pointer to
25238 the type without accessing its fields.
25240 Therefore caller should follow these rules:
25241 * Try to fetch any prerequisite types we may need to build this DIE type
25242 before building the type and calling set_die_type.
25243 * After building type call set_die_type for current DIE as soon as
25244 possible before fetching more types to complete the current type.
25245 * Make the type as complete as possible before fetching more types. */
25247 static struct type
*
25248 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25250 struct dwarf2_per_objfile
*dwarf2_per_objfile
25251 = cu
->per_cu
->dwarf2_per_objfile
;
25252 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25253 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25254 struct attribute
*attr
;
25255 struct dynamic_prop prop
;
25257 /* For Ada types, make sure that the gnat-specific data is always
25258 initialized (if not already set). There are a few types where
25259 we should not be doing so, because the type-specific area is
25260 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25261 where the type-specific area is used to store the floatformat).
25262 But this is not a problem, because the gnat-specific information
25263 is actually not needed for these types. */
25264 if (need_gnat_info (cu
)
25265 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25266 && TYPE_CODE (type
) != TYPE_CODE_FLT
25267 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25268 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25269 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25270 && !HAVE_GNAT_AUX_INFO (type
))
25271 INIT_GNAT_SPECIFIC (type
);
25273 /* Read DW_AT_allocated and set in type. */
25274 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25275 if (attr_form_is_block (attr
))
25277 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25278 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25280 else if (attr
!= NULL
)
25282 complaint (&symfile_complaints
,
25283 _("DW_AT_allocated has the wrong form (%s) at DIE 0x%x"),
25284 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25285 to_underlying (die
->sect_off
));
25288 /* Read DW_AT_associated and set in type. */
25289 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25290 if (attr_form_is_block (attr
))
25292 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25293 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25295 else if (attr
!= NULL
)
25297 complaint (&symfile_complaints
,
25298 _("DW_AT_associated has the wrong form (%s) at DIE 0x%x"),
25299 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25300 to_underlying (die
->sect_off
));
25303 /* Read DW_AT_data_location and set in type. */
25304 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25305 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25306 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25308 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25310 dwarf2_per_objfile
->die_type_hash
=
25311 htab_create_alloc_ex (127,
25312 per_cu_offset_and_type_hash
,
25313 per_cu_offset_and_type_eq
,
25315 &objfile
->objfile_obstack
,
25316 hashtab_obstack_allocate
,
25317 dummy_obstack_deallocate
);
25320 ofs
.per_cu
= cu
->per_cu
;
25321 ofs
.sect_off
= die
->sect_off
;
25323 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25324 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25326 complaint (&symfile_complaints
,
25327 _("A problem internal to GDB: DIE 0x%x has type already set"),
25328 to_underlying (die
->sect_off
));
25329 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25330 struct dwarf2_per_cu_offset_and_type
);
25335 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25336 or return NULL if the die does not have a saved type. */
25338 static struct type
*
25339 get_die_type_at_offset (sect_offset sect_off
,
25340 struct dwarf2_per_cu_data
*per_cu
)
25342 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25343 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25345 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25348 ofs
.per_cu
= per_cu
;
25349 ofs
.sect_off
= sect_off
;
25350 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25351 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25358 /* Look up the type for DIE in CU in die_type_hash,
25359 or return NULL if DIE does not have a saved type. */
25361 static struct type
*
25362 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25364 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25367 /* Add a dependence relationship from CU to REF_PER_CU. */
25370 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25371 struct dwarf2_per_cu_data
*ref_per_cu
)
25375 if (cu
->dependencies
== NULL
)
25377 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25378 NULL
, &cu
->comp_unit_obstack
,
25379 hashtab_obstack_allocate
,
25380 dummy_obstack_deallocate
);
25382 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25384 *slot
= ref_per_cu
;
25387 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25388 Set the mark field in every compilation unit in the
25389 cache that we must keep because we are keeping CU. */
25392 dwarf2_mark_helper (void **slot
, void *data
)
25394 struct dwarf2_per_cu_data
*per_cu
;
25396 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25398 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25399 reading of the chain. As such dependencies remain valid it is not much
25400 useful to track and undo them during QUIT cleanups. */
25401 if (per_cu
->cu
== NULL
)
25404 if (per_cu
->cu
->mark
)
25406 per_cu
->cu
->mark
= 1;
25408 if (per_cu
->cu
->dependencies
!= NULL
)
25409 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25414 /* Set the mark field in CU and in every other compilation unit in the
25415 cache that we must keep because we are keeping CU. */
25418 dwarf2_mark (struct dwarf2_cu
*cu
)
25423 if (cu
->dependencies
!= NULL
)
25424 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25428 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25432 per_cu
->cu
->mark
= 0;
25433 per_cu
= per_cu
->cu
->read_in_chain
;
25437 /* Trivial hash function for partial_die_info: the hash value of a DIE
25438 is its offset in .debug_info for this objfile. */
25441 partial_die_hash (const void *item
)
25443 const struct partial_die_info
*part_die
25444 = (const struct partial_die_info
*) item
;
25446 return to_underlying (part_die
->sect_off
);
25449 /* Trivial comparison function for partial_die_info structures: two DIEs
25450 are equal if they have the same offset. */
25453 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25455 const struct partial_die_info
*part_die_lhs
25456 = (const struct partial_die_info
*) item_lhs
;
25457 const struct partial_die_info
*part_die_rhs
25458 = (const struct partial_die_info
*) item_rhs
;
25460 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25463 static struct cmd_list_element
*set_dwarf_cmdlist
;
25464 static struct cmd_list_element
*show_dwarf_cmdlist
;
25467 set_dwarf_cmd (const char *args
, int from_tty
)
25469 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25474 show_dwarf_cmd (const char *args
, int from_tty
)
25476 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25479 /* Free data associated with OBJFILE, if necessary. */
25482 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
25484 struct dwarf2_per_objfile
*data
= (struct dwarf2_per_objfile
*) d
;
25487 for (ix
= 0; ix
< data
->n_comp_units
; ++ix
)
25488 VEC_free (dwarf2_per_cu_ptr
, data
->all_comp_units
[ix
]->imported_symtabs
);
25490 for (ix
= 0; ix
< data
->n_type_units
; ++ix
)
25491 VEC_free (dwarf2_per_cu_ptr
,
25492 data
->all_type_units
[ix
]->per_cu
.imported_symtabs
);
25493 xfree (data
->all_type_units
);
25495 VEC_free (dwarf2_section_info_def
, data
->types
);
25497 if (data
->dwo_files
)
25498 free_dwo_files (data
->dwo_files
, objfile
);
25499 if (data
->dwp_file
)
25500 gdb_bfd_unref (data
->dwp_file
->dbfd
);
25502 if (data
->dwz_file
&& data
->dwz_file
->dwz_bfd
)
25503 gdb_bfd_unref (data
->dwz_file
->dwz_bfd
);
25505 if (data
->index_table
!= NULL
)
25506 data
->index_table
->~mapped_index ();
25510 /* The "save gdb-index" command. */
25512 /* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
25516 file_write (FILE *file
, const void *data
, size_t size
)
25518 if (fwrite (data
, 1, size
, file
) != size
)
25519 error (_("couldn't data write to file"));
25522 /* Write the contents of VEC to FILE, with error checking. */
25524 template<typename Elem
, typename Alloc
>
25526 file_write (FILE *file
, const std::vector
<Elem
, Alloc
> &vec
)
25528 file_write (file
, vec
.data (), vec
.size () * sizeof (vec
[0]));
25531 /* In-memory buffer to prepare data to be written later to a file. */
25535 /* Copy DATA to the end of the buffer. */
25536 template<typename T
>
25537 void append_data (const T
&data
)
25539 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
25540 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
25541 grow (sizeof (data
)));
25544 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
25545 terminating zero is appended too. */
25546 void append_cstr0 (const char *cstr
)
25548 const size_t size
= strlen (cstr
) + 1;
25549 std::copy (cstr
, cstr
+ size
, grow (size
));
25552 /* Store INPUT as ULEB128 to the end of buffer. */
25553 void append_unsigned_leb128 (ULONGEST input
)
25557 gdb_byte output
= input
& 0x7f;
25561 append_data (output
);
25567 /* Accept a host-format integer in VAL and append it to the buffer
25568 as a target-format integer which is LEN bytes long. */
25569 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
25571 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
25574 /* Return the size of the buffer. */
25575 size_t size () const
25577 return m_vec
.size ();
25580 /* Return true iff the buffer is empty. */
25581 bool empty () const
25583 return m_vec
.empty ();
25586 /* Write the buffer to FILE. */
25587 void file_write (FILE *file
) const
25589 ::file_write (file
, m_vec
);
25593 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
25594 the start of the new block. */
25595 gdb_byte
*grow (size_t size
)
25597 m_vec
.resize (m_vec
.size () + size
);
25598 return &*m_vec
.end () - size
;
25601 gdb::byte_vector m_vec
;
25604 /* An entry in the symbol table. */
25605 struct symtab_index_entry
25607 /* The name of the symbol. */
25609 /* The offset of the name in the constant pool. */
25610 offset_type index_offset
;
25611 /* A sorted vector of the indices of all the CUs that hold an object
25613 std::vector
<offset_type
> cu_indices
;
25616 /* The symbol table. This is a power-of-2-sized hash table. */
25617 struct mapped_symtab
25621 data
.resize (1024);
25624 offset_type n_elements
= 0;
25625 std::vector
<symtab_index_entry
> data
;
25628 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
25631 Function is used only during write_hash_table so no index format backward
25632 compatibility is needed. */
25634 static symtab_index_entry
&
25635 find_slot (struct mapped_symtab
*symtab
, const char *name
)
25637 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
25639 index
= hash
& (symtab
->data
.size () - 1);
25640 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
25644 if (symtab
->data
[index
].name
== NULL
25645 || strcmp (name
, symtab
->data
[index
].name
) == 0)
25646 return symtab
->data
[index
];
25647 index
= (index
+ step
) & (symtab
->data
.size () - 1);
25651 /* Expand SYMTAB's hash table. */
25654 hash_expand (struct mapped_symtab
*symtab
)
25656 auto old_entries
= std::move (symtab
->data
);
25658 symtab
->data
.clear ();
25659 symtab
->data
.resize (old_entries
.size () * 2);
25661 for (auto &it
: old_entries
)
25662 if (it
.name
!= NULL
)
25664 auto &ref
= find_slot (symtab
, it
.name
);
25665 ref
= std::move (it
);
25669 /* Add an entry to SYMTAB. NAME is the name of the symbol.
25670 CU_INDEX is the index of the CU in which the symbol appears.
25671 IS_STATIC is one if the symbol is static, otherwise zero (global). */
25674 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
25675 int is_static
, gdb_index_symbol_kind kind
,
25676 offset_type cu_index
)
25678 offset_type cu_index_and_attrs
;
25680 ++symtab
->n_elements
;
25681 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
25682 hash_expand (symtab
);
25684 symtab_index_entry
&slot
= find_slot (symtab
, name
);
25685 if (slot
.name
== NULL
)
25688 /* index_offset is set later. */
25691 cu_index_and_attrs
= 0;
25692 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
25693 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
25694 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
25696 /* We don't want to record an index value twice as we want to avoid the
25698 We process all global symbols and then all static symbols
25699 (which would allow us to avoid the duplication by only having to check
25700 the last entry pushed), but a symbol could have multiple kinds in one CU.
25701 To keep things simple we don't worry about the duplication here and
25702 sort and uniqufy the list after we've processed all symbols. */
25703 slot
.cu_indices
.push_back (cu_index_and_attrs
);
25706 /* Sort and remove duplicates of all symbols' cu_indices lists. */
25709 uniquify_cu_indices (struct mapped_symtab
*symtab
)
25711 for (auto &entry
: symtab
->data
)
25713 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
25715 auto &cu_indices
= entry
.cu_indices
;
25716 std::sort (cu_indices
.begin (), cu_indices
.end ());
25717 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
25718 cu_indices
.erase (from
, cu_indices
.end ());
25723 /* A form of 'const char *' suitable for container keys. Only the
25724 pointer is stored. The strings themselves are compared, not the
25729 c_str_view (const char *cstr
)
25733 bool operator== (const c_str_view
&other
) const
25735 return strcmp (m_cstr
, other
.m_cstr
) == 0;
25738 /* Return the underlying C string. Note, the returned string is
25739 only a reference with lifetime of this object. */
25740 const char *c_str () const
25746 friend class c_str_view_hasher
;
25747 const char *const m_cstr
;
25750 /* A std::unordered_map::hasher for c_str_view that uses the right
25751 hash function for strings in a mapped index. */
25752 class c_str_view_hasher
25755 size_t operator () (const c_str_view
&x
) const
25757 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
25761 /* A std::unordered_map::hasher for std::vector<>. */
25762 template<typename T
>
25763 class vector_hasher
25766 size_t operator () (const std::vector
<T
> &key
) const
25768 return iterative_hash (key
.data (),
25769 sizeof (key
.front ()) * key
.size (), 0);
25773 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
25774 constant pool entries going into the data buffer CPOOL. */
25777 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
25780 /* Elements are sorted vectors of the indices of all the CUs that
25781 hold an object of this name. */
25782 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
25783 vector_hasher
<offset_type
>>
25786 /* We add all the index vectors to the constant pool first, to
25787 ensure alignment is ok. */
25788 for (symtab_index_entry
&entry
: symtab
->data
)
25790 if (entry
.name
== NULL
)
25792 gdb_assert (entry
.index_offset
== 0);
25794 /* Finding before inserting is faster than always trying to
25795 insert, because inserting always allocates a node, does the
25796 lookup, and then destroys the new node if another node
25797 already had the same key. C++17 try_emplace will avoid
25800 = symbol_hash_table
.find (entry
.cu_indices
);
25801 if (found
!= symbol_hash_table
.end ())
25803 entry
.index_offset
= found
->second
;
25807 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
25808 entry
.index_offset
= cpool
.size ();
25809 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
25810 for (const auto index
: entry
.cu_indices
)
25811 cpool
.append_data (MAYBE_SWAP (index
));
25815 /* Now write out the hash table. */
25816 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
25817 for (const auto &entry
: symtab
->data
)
25819 offset_type str_off
, vec_off
;
25821 if (entry
.name
!= NULL
)
25823 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
25824 if (insertpair
.second
)
25825 cpool
.append_cstr0 (entry
.name
);
25826 str_off
= insertpair
.first
->second
;
25827 vec_off
= entry
.index_offset
;
25831 /* While 0 is a valid constant pool index, it is not valid
25832 to have 0 for both offsets. */
25837 output
.append_data (MAYBE_SWAP (str_off
));
25838 output
.append_data (MAYBE_SWAP (vec_off
));
25842 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
25844 /* Helper struct for building the address table. */
25845 struct addrmap_index_data
25847 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
25848 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
25851 struct objfile
*objfile
;
25852 data_buf
&addr_vec
;
25853 psym_index_map
&cu_index_htab
;
25855 /* Non-zero if the previous_* fields are valid.
25856 We can't write an entry until we see the next entry (since it is only then
25857 that we know the end of the entry). */
25858 int previous_valid
;
25859 /* Index of the CU in the table of all CUs in the index file. */
25860 unsigned int previous_cu_index
;
25861 /* Start address of the CU. */
25862 CORE_ADDR previous_cu_start
;
25865 /* Write an address entry to ADDR_VEC. */
25868 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
25869 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
25871 CORE_ADDR baseaddr
;
25873 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25875 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
25876 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
25877 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
25880 /* Worker function for traversing an addrmap to build the address table. */
25883 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
25885 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
25886 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
25888 if (data
->previous_valid
)
25889 add_address_entry (data
->objfile
, data
->addr_vec
,
25890 data
->previous_cu_start
, start_addr
,
25891 data
->previous_cu_index
);
25893 data
->previous_cu_start
= start_addr
;
25896 const auto it
= data
->cu_index_htab
.find (pst
);
25897 gdb_assert (it
!= data
->cu_index_htab
.cend ());
25898 data
->previous_cu_index
= it
->second
;
25899 data
->previous_valid
= 1;
25902 data
->previous_valid
= 0;
25907 /* Write OBJFILE's address map to ADDR_VEC.
25908 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
25909 in the index file. */
25912 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
25913 psym_index_map
&cu_index_htab
)
25915 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
25917 /* When writing the address table, we have to cope with the fact that
25918 the addrmap iterator only provides the start of a region; we have to
25919 wait until the next invocation to get the start of the next region. */
25921 addrmap_index_data
.objfile
= objfile
;
25922 addrmap_index_data
.previous_valid
= 0;
25924 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
25925 &addrmap_index_data
);
25927 /* It's highly unlikely the last entry (end address = 0xff...ff)
25928 is valid, but we should still handle it.
25929 The end address is recorded as the start of the next region, but that
25930 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
25932 if (addrmap_index_data
.previous_valid
)
25933 add_address_entry (objfile
, addr_vec
,
25934 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
25935 addrmap_index_data
.previous_cu_index
);
25938 /* Return the symbol kind of PSYM. */
25940 static gdb_index_symbol_kind
25941 symbol_kind (struct partial_symbol
*psym
)
25943 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
25944 enum address_class aclass
= PSYMBOL_CLASS (psym
);
25952 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
25954 return GDB_INDEX_SYMBOL_KIND_TYPE
;
25956 case LOC_CONST_BYTES
:
25957 case LOC_OPTIMIZED_OUT
:
25959 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
25961 /* Note: It's currently impossible to recognize psyms as enum values
25962 short of reading the type info. For now punt. */
25963 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
25965 /* There are other LOC_FOO values that one might want to classify
25966 as variables, but dwarf2read.c doesn't currently use them. */
25967 return GDB_INDEX_SYMBOL_KIND_OTHER
;
25969 case STRUCT_DOMAIN
:
25970 return GDB_INDEX_SYMBOL_KIND_TYPE
;
25972 return GDB_INDEX_SYMBOL_KIND_OTHER
;
25976 /* Add a list of partial symbols to SYMTAB. */
25979 write_psymbols (struct mapped_symtab
*symtab
,
25980 std::unordered_set
<partial_symbol
*> &psyms_seen
,
25981 struct partial_symbol
**psymp
,
25983 offset_type cu_index
,
25986 for (; count
-- > 0; ++psymp
)
25988 struct partial_symbol
*psym
= *psymp
;
25990 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
25991 error (_("Ada is not currently supported by the index"));
25993 /* Only add a given psymbol once. */
25994 if (psyms_seen
.insert (psym
).second
)
25996 gdb_index_symbol_kind kind
= symbol_kind (psym
);
25998 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
25999 is_static
, kind
, cu_index
);
26004 /* A helper struct used when iterating over debug_types. */
26005 struct signatured_type_index_data
26007 signatured_type_index_data (data_buf
&types_list_
,
26008 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
26009 : types_list (types_list_
), psyms_seen (psyms_seen_
)
26012 struct objfile
*objfile
;
26013 struct mapped_symtab
*symtab
;
26014 data_buf
&types_list
;
26015 std::unordered_set
<partial_symbol
*> &psyms_seen
;
26019 /* A helper function that writes a single signatured_type to an
26023 write_one_signatured_type (void **slot
, void *d
)
26025 struct signatured_type_index_data
*info
26026 = (struct signatured_type_index_data
*) d
;
26027 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26028 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
26030 write_psymbols (info
->symtab
,
26032 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
26033 psymtab
->n_global_syms
, info
->cu_index
,
26035 write_psymbols (info
->symtab
,
26037 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
26038 psymtab
->n_static_syms
, info
->cu_index
,
26041 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26042 to_underlying (entry
->per_cu
.sect_off
));
26043 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26044 to_underlying (entry
->type_offset_in_tu
));
26045 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
26052 /* Recurse into all "included" dependencies and count their symbols as
26053 if they appeared in this psymtab. */
26056 recursively_count_psymbols (struct partial_symtab
*psymtab
,
26057 size_t &psyms_seen
)
26059 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26060 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26061 recursively_count_psymbols (psymtab
->dependencies
[i
],
26064 psyms_seen
+= psymtab
->n_global_syms
;
26065 psyms_seen
+= psymtab
->n_static_syms
;
26068 /* Recurse into all "included" dependencies and write their symbols as
26069 if they appeared in this psymtab. */
26072 recursively_write_psymbols (struct objfile
*objfile
,
26073 struct partial_symtab
*psymtab
,
26074 struct mapped_symtab
*symtab
,
26075 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26076 offset_type cu_index
)
26080 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26081 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26082 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26083 symtab
, psyms_seen
, cu_index
);
26085 write_psymbols (symtab
,
26087 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26088 psymtab
->n_global_syms
, cu_index
,
26090 write_psymbols (symtab
,
26092 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26093 psymtab
->n_static_syms
, cu_index
,
26097 /* DWARF-5 .debug_names builder. */
26101 debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bool is_dwarf64
,
26102 bfd_endian dwarf5_byte_order
)
26103 : m_dwarf5_byte_order (dwarf5_byte_order
),
26104 m_dwarf32 (dwarf5_byte_order
),
26105 m_dwarf64 (dwarf5_byte_order
),
26106 m_dwarf (is_dwarf64
26107 ? static_cast<dwarf
&> (m_dwarf64
)
26108 : static_cast<dwarf
&> (m_dwarf32
)),
26109 m_name_table_string_offs (m_dwarf
.name_table_string_offs
),
26110 m_name_table_entry_offs (m_dwarf
.name_table_entry_offs
),
26111 m_debugstrlookup (dwarf2_per_objfile
)
26114 int dwarf5_offset_size () const
26116 const bool dwarf5_is_dwarf64
= &m_dwarf
== &m_dwarf64
;
26117 return dwarf5_is_dwarf64
? 8 : 4;
26120 /* Is this symbol from DW_TAG_compile_unit or DW_TAG_type_unit? */
26121 enum class unit_kind
{ cu
, tu
};
26123 /* Insert one symbol. */
26124 void insert (const partial_symbol
*psym
, int cu_index
, bool is_static
,
26127 const int dwarf_tag
= psymbol_tag (psym
);
26128 if (dwarf_tag
== 0)
26130 const char *const name
= SYMBOL_SEARCH_NAME (psym
);
26131 const auto insertpair
26132 = m_name_to_value_set
.emplace (c_str_view (name
),
26133 std::set
<symbol_value
> ());
26134 std::set
<symbol_value
> &value_set
= insertpair
.first
->second
;
26135 value_set
.emplace (symbol_value (dwarf_tag
, cu_index
, is_static
, kind
));
26138 /* Build all the tables. All symbols must be already inserted.
26139 This function does not call file_write, caller has to do it
26143 /* Verify the build method has not be called twice. */
26144 gdb_assert (m_abbrev_table
.empty ());
26145 const size_t name_count
= m_name_to_value_set
.size ();
26146 m_bucket_table
.resize
26147 (std::pow (2, std::ceil (std::log2 (name_count
* 4 / 3))));
26148 m_hash_table
.reserve (name_count
);
26149 m_name_table_string_offs
.reserve (name_count
);
26150 m_name_table_entry_offs
.reserve (name_count
);
26152 /* Map each hash of symbol to its name and value. */
26153 struct hash_it_pair
26156 decltype (m_name_to_value_set
)::const_iterator it
;
26158 std::vector
<std::forward_list
<hash_it_pair
>> bucket_hash
;
26159 bucket_hash
.resize (m_bucket_table
.size ());
26160 for (decltype (m_name_to_value_set
)::const_iterator it
26161 = m_name_to_value_set
.cbegin ();
26162 it
!= m_name_to_value_set
.cend ();
26165 const char *const name
= it
->first
.c_str ();
26166 const uint32_t hash
= dwarf5_djb_hash (name
);
26167 hash_it_pair hashitpair
;
26168 hashitpair
.hash
= hash
;
26169 hashitpair
.it
= it
;
26170 auto &slot
= bucket_hash
[hash
% bucket_hash
.size()];
26171 slot
.push_front (std::move (hashitpair
));
26173 for (size_t bucket_ix
= 0; bucket_ix
< bucket_hash
.size (); ++bucket_ix
)
26175 const std::forward_list
<hash_it_pair
> &hashitlist
26176 = bucket_hash
[bucket_ix
];
26177 if (hashitlist
.empty ())
26179 uint32_t &bucket_slot
= m_bucket_table
[bucket_ix
];
26180 /* The hashes array is indexed starting at 1. */
26181 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&bucket_slot
),
26182 sizeof (bucket_slot
), m_dwarf5_byte_order
,
26183 m_hash_table
.size () + 1);
26184 for (const hash_it_pair
&hashitpair
: hashitlist
)
26186 m_hash_table
.push_back (0);
26187 store_unsigned_integer (reinterpret_cast<gdb_byte
*>
26188 (&m_hash_table
.back ()),
26189 sizeof (m_hash_table
.back ()),
26190 m_dwarf5_byte_order
, hashitpair
.hash
);
26191 const c_str_view
&name
= hashitpair
.it
->first
;
26192 const std::set
<symbol_value
> &value_set
= hashitpair
.it
->second
;
26193 m_name_table_string_offs
.push_back_reorder
26194 (m_debugstrlookup
.lookup (name
.c_str ()));
26195 m_name_table_entry_offs
.push_back_reorder (m_entry_pool
.size ());
26196 gdb_assert (!value_set
.empty ());
26197 for (const symbol_value
&value
: value_set
)
26199 int &idx
= m_indexkey_to_idx
[index_key (value
.dwarf_tag
,
26204 idx
= m_idx_next
++;
26205 m_abbrev_table
.append_unsigned_leb128 (idx
);
26206 m_abbrev_table
.append_unsigned_leb128 (value
.dwarf_tag
);
26207 m_abbrev_table
.append_unsigned_leb128
26208 (value
.kind
== unit_kind::cu
? DW_IDX_compile_unit
26209 : DW_IDX_type_unit
);
26210 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_udata
);
26211 m_abbrev_table
.append_unsigned_leb128 (value
.is_static
26212 ? DW_IDX_GNU_internal
26213 : DW_IDX_GNU_external
);
26214 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_flag_present
);
26216 /* Terminate attributes list. */
26217 m_abbrev_table
.append_unsigned_leb128 (0);
26218 m_abbrev_table
.append_unsigned_leb128 (0);
26221 m_entry_pool
.append_unsigned_leb128 (idx
);
26222 m_entry_pool
.append_unsigned_leb128 (value
.cu_index
);
26225 /* Terminate the list of CUs. */
26226 m_entry_pool
.append_unsigned_leb128 (0);
26229 gdb_assert (m_hash_table
.size () == name_count
);
26231 /* Terminate tags list. */
26232 m_abbrev_table
.append_unsigned_leb128 (0);
26235 /* Return .debug_names bucket count. This must be called only after
26236 calling the build method. */
26237 uint32_t bucket_count () const
26239 /* Verify the build method has been already called. */
26240 gdb_assert (!m_abbrev_table
.empty ());
26241 const uint32_t retval
= m_bucket_table
.size ();
26243 /* Check for overflow. */
26244 gdb_assert (retval
== m_bucket_table
.size ());
26248 /* Return .debug_names names count. This must be called only after
26249 calling the build method. */
26250 uint32_t name_count () const
26252 /* Verify the build method has been already called. */
26253 gdb_assert (!m_abbrev_table
.empty ());
26254 const uint32_t retval
= m_hash_table
.size ();
26256 /* Check for overflow. */
26257 gdb_assert (retval
== m_hash_table
.size ());
26261 /* Return number of bytes of .debug_names abbreviation table. This
26262 must be called only after calling the build method. */
26263 uint32_t abbrev_table_bytes () const
26265 gdb_assert (!m_abbrev_table
.empty ());
26266 return m_abbrev_table
.size ();
26269 /* Recurse into all "included" dependencies and store their symbols
26270 as if they appeared in this psymtab. */
26271 void recursively_write_psymbols
26272 (struct objfile
*objfile
,
26273 struct partial_symtab
*psymtab
,
26274 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26277 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26278 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26279 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26280 psyms_seen
, cu_index
);
26282 write_psymbols (psyms_seen
,
26283 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26284 psymtab
->n_global_syms
, cu_index
, false, unit_kind::cu
);
26285 write_psymbols (psyms_seen
,
26286 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26287 psymtab
->n_static_syms
, cu_index
, true, unit_kind::cu
);
26290 /* Return number of bytes the .debug_names section will have. This
26291 must be called only after calling the build method. */
26292 size_t bytes () const
26294 /* Verify the build method has been already called. */
26295 gdb_assert (!m_abbrev_table
.empty ());
26296 size_t expected_bytes
= 0;
26297 expected_bytes
+= m_bucket_table
.size () * sizeof (m_bucket_table
[0]);
26298 expected_bytes
+= m_hash_table
.size () * sizeof (m_hash_table
[0]);
26299 expected_bytes
+= m_name_table_string_offs
.bytes ();
26300 expected_bytes
+= m_name_table_entry_offs
.bytes ();
26301 expected_bytes
+= m_abbrev_table
.size ();
26302 expected_bytes
+= m_entry_pool
.size ();
26303 return expected_bytes
;
26306 /* Write .debug_names to FILE_NAMES and .debug_str addition to
26307 FILE_STR. This must be called only after calling the build
26309 void file_write (FILE *file_names
, FILE *file_str
) const
26311 /* Verify the build method has been already called. */
26312 gdb_assert (!m_abbrev_table
.empty ());
26313 ::file_write (file_names
, m_bucket_table
);
26314 ::file_write (file_names
, m_hash_table
);
26315 m_name_table_string_offs
.file_write (file_names
);
26316 m_name_table_entry_offs
.file_write (file_names
);
26317 m_abbrev_table
.file_write (file_names
);
26318 m_entry_pool
.file_write (file_names
);
26319 m_debugstrlookup
.file_write (file_str
);
26322 /* A helper user data for write_one_signatured_type. */
26323 class write_one_signatured_type_data
26326 write_one_signatured_type_data (debug_names
&nametable_
,
26327 signatured_type_index_data
&&info_
)
26328 : nametable (nametable_
), info (std::move (info_
))
26330 debug_names
&nametable
;
26331 struct signatured_type_index_data info
;
26334 /* A helper function to pass write_one_signatured_type to
26335 htab_traverse_noresize. */
26337 write_one_signatured_type (void **slot
, void *d
)
26339 write_one_signatured_type_data
*data
= (write_one_signatured_type_data
*) d
;
26340 struct signatured_type_index_data
*info
= &data
->info
;
26341 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26343 data
->nametable
.write_one_signatured_type (entry
, info
);
26350 /* Storage for symbol names mapping them to their .debug_str section
26352 class debug_str_lookup
26356 /* Object costructor to be called for current DWARF2_PER_OBJFILE.
26357 All .debug_str section strings are automatically stored. */
26358 debug_str_lookup (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26359 : m_abfd (dwarf2_per_objfile
->objfile
->obfd
),
26360 m_dwarf2_per_objfile (dwarf2_per_objfile
)
26362 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
26363 &dwarf2_per_objfile
->str
);
26364 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
26366 for (const gdb_byte
*data
= dwarf2_per_objfile
->str
.buffer
;
26367 data
< (dwarf2_per_objfile
->str
.buffer
26368 + dwarf2_per_objfile
->str
.size
);)
26370 const char *const s
= reinterpret_cast<const char *> (data
);
26371 const auto insertpair
26372 = m_str_table
.emplace (c_str_view (s
),
26373 data
- dwarf2_per_objfile
->str
.buffer
);
26374 if (!insertpair
.second
)
26375 complaint (&symfile_complaints
,
26376 _("Duplicate string \"%s\" in "
26377 ".debug_str section [in module %s]"),
26378 s
, bfd_get_filename (m_abfd
));
26379 data
+= strlen (s
) + 1;
26383 /* Return offset of symbol name S in the .debug_str section. Add
26384 such symbol to the section's end if it does not exist there
26386 size_t lookup (const char *s
)
26388 const auto it
= m_str_table
.find (c_str_view (s
));
26389 if (it
!= m_str_table
.end ())
26391 const size_t offset
= (m_dwarf2_per_objfile
->str
.size
26392 + m_str_add_buf
.size ());
26393 m_str_table
.emplace (c_str_view (s
), offset
);
26394 m_str_add_buf
.append_cstr0 (s
);
26398 /* Append the end of the .debug_str section to FILE. */
26399 void file_write (FILE *file
) const
26401 m_str_add_buf
.file_write (file
);
26405 std::unordered_map
<c_str_view
, size_t, c_str_view_hasher
> m_str_table
;
26407 struct dwarf2_per_objfile
*m_dwarf2_per_objfile
;
26409 /* Data to add at the end of .debug_str for new needed symbol names. */
26410 data_buf m_str_add_buf
;
26413 /* Container to map used DWARF tags to their .debug_names abbreviation
26418 index_key (int dwarf_tag_
, bool is_static_
, unit_kind kind_
)
26419 : dwarf_tag (dwarf_tag_
), is_static (is_static_
), kind (kind_
)
26424 operator== (const index_key
&other
) const
26426 return (dwarf_tag
== other
.dwarf_tag
&& is_static
== other
.is_static
26427 && kind
== other
.kind
);
26430 const int dwarf_tag
;
26431 const bool is_static
;
26432 const unit_kind kind
;
26435 /* Provide std::unordered_map::hasher for index_key. */
26436 class index_key_hasher
26440 operator () (const index_key
&key
) const
26442 return (std::hash
<int>() (key
.dwarf_tag
) << 1) | key
.is_static
;
26446 /* Parameters of one symbol entry. */
26450 const int dwarf_tag
, cu_index
;
26451 const bool is_static
;
26452 const unit_kind kind
;
26454 symbol_value (int dwarf_tag_
, int cu_index_
, bool is_static_
,
26456 : dwarf_tag (dwarf_tag_
), cu_index (cu_index_
), is_static (is_static_
),
26461 operator< (const symbol_value
&other
) const
26481 /* Abstract base class to unify DWARF-32 and DWARF-64 name table
26486 const bfd_endian dwarf5_byte_order
;
26488 explicit offset_vec (bfd_endian dwarf5_byte_order_
)
26489 : dwarf5_byte_order (dwarf5_byte_order_
)
26492 /* Call std::vector::reserve for NELEM elements. */
26493 virtual void reserve (size_t nelem
) = 0;
26495 /* Call std::vector::push_back with store_unsigned_integer byte
26496 reordering for ELEM. */
26497 virtual void push_back_reorder (size_t elem
) = 0;
26499 /* Return expected output size in bytes. */
26500 virtual size_t bytes () const = 0;
26502 /* Write name table to FILE. */
26503 virtual void file_write (FILE *file
) const = 0;
26506 /* Template to unify DWARF-32 and DWARF-64 output. */
26507 template<typename OffsetSize
>
26508 class offset_vec_tmpl
: public offset_vec
26511 explicit offset_vec_tmpl (bfd_endian dwarf5_byte_order_
)
26512 : offset_vec (dwarf5_byte_order_
)
26515 /* Implement offset_vec::reserve. */
26516 void reserve (size_t nelem
) override
26518 m_vec
.reserve (nelem
);
26521 /* Implement offset_vec::push_back_reorder. */
26522 void push_back_reorder (size_t elem
) override
26524 m_vec
.push_back (elem
);
26525 /* Check for overflow. */
26526 gdb_assert (m_vec
.back () == elem
);
26527 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&m_vec
.back ()),
26528 sizeof (m_vec
.back ()), dwarf5_byte_order
, elem
);
26531 /* Implement offset_vec::bytes. */
26532 size_t bytes () const override
26534 return m_vec
.size () * sizeof (m_vec
[0]);
26537 /* Implement offset_vec::file_write. */
26538 void file_write (FILE *file
) const override
26540 ::file_write (file
, m_vec
);
26544 std::vector
<OffsetSize
> m_vec
;
26547 /* Base class to unify DWARF-32 and DWARF-64 .debug_names output
26548 respecting name table width. */
26552 offset_vec
&name_table_string_offs
, &name_table_entry_offs
;
26554 dwarf (offset_vec
&name_table_string_offs_
,
26555 offset_vec
&name_table_entry_offs_
)
26556 : name_table_string_offs (name_table_string_offs_
),
26557 name_table_entry_offs (name_table_entry_offs_
)
26562 /* Template to unify DWARF-32 and DWARF-64 .debug_names output
26563 respecting name table width. */
26564 template<typename OffsetSize
>
26565 class dwarf_tmpl
: public dwarf
26568 explicit dwarf_tmpl (bfd_endian dwarf5_byte_order_
)
26569 : dwarf (m_name_table_string_offs
, m_name_table_entry_offs
),
26570 m_name_table_string_offs (dwarf5_byte_order_
),
26571 m_name_table_entry_offs (dwarf5_byte_order_
)
26575 offset_vec_tmpl
<OffsetSize
> m_name_table_string_offs
;
26576 offset_vec_tmpl
<OffsetSize
> m_name_table_entry_offs
;
26579 /* Try to reconstruct original DWARF tag for given partial_symbol.
26580 This function is not DWARF-5 compliant but it is sufficient for
26581 GDB as a DWARF-5 index consumer. */
26582 static int psymbol_tag (const struct partial_symbol
*psym
)
26584 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26585 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26593 return DW_TAG_subprogram
;
26595 return DW_TAG_typedef
;
26597 case LOC_CONST_BYTES
:
26598 case LOC_OPTIMIZED_OUT
:
26600 return DW_TAG_variable
;
26602 /* Note: It's currently impossible to recognize psyms as enum values
26603 short of reading the type info. For now punt. */
26604 return DW_TAG_variable
;
26606 /* There are other LOC_FOO values that one might want to classify
26607 as variables, but dwarf2read.c doesn't currently use them. */
26608 return DW_TAG_variable
;
26610 case STRUCT_DOMAIN
:
26611 return DW_TAG_structure_type
;
26617 /* Call insert for all partial symbols and mark them in PSYMS_SEEN. */
26618 void write_psymbols (std::unordered_set
<partial_symbol
*> &psyms_seen
,
26619 struct partial_symbol
**psymp
, int count
, int cu_index
,
26620 bool is_static
, unit_kind kind
)
26622 for (; count
-- > 0; ++psymp
)
26624 struct partial_symbol
*psym
= *psymp
;
26626 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
26627 error (_("Ada is not currently supported by the index"));
26629 /* Only add a given psymbol once. */
26630 if (psyms_seen
.insert (psym
).second
)
26631 insert (psym
, cu_index
, is_static
, kind
);
26635 /* A helper function that writes a single signatured_type
26636 to a debug_names. */
26638 write_one_signatured_type (struct signatured_type
*entry
,
26639 struct signatured_type_index_data
*info
)
26641 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
26643 write_psymbols (info
->psyms_seen
,
26644 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
26645 psymtab
->n_global_syms
, info
->cu_index
, false,
26647 write_psymbols (info
->psyms_seen
,
26648 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
26649 psymtab
->n_static_syms
, info
->cu_index
, true,
26652 info
->types_list
.append_uint (dwarf5_offset_size (), m_dwarf5_byte_order
,
26653 to_underlying (entry
->per_cu
.sect_off
));
26658 /* Store value of each symbol. */
26659 std::unordered_map
<c_str_view
, std::set
<symbol_value
>, c_str_view_hasher
>
26660 m_name_to_value_set
;
26662 /* Tables of DWARF-5 .debug_names. They are in object file byte
26664 std::vector
<uint32_t> m_bucket_table
;
26665 std::vector
<uint32_t> m_hash_table
;
26667 const bfd_endian m_dwarf5_byte_order
;
26668 dwarf_tmpl
<uint32_t> m_dwarf32
;
26669 dwarf_tmpl
<uint64_t> m_dwarf64
;
26671 offset_vec
&m_name_table_string_offs
, &m_name_table_entry_offs
;
26672 debug_str_lookup m_debugstrlookup
;
26674 /* Map each used .debug_names abbreviation tag parameter to its
26676 std::unordered_map
<index_key
, int, index_key_hasher
> m_indexkey_to_idx
;
26678 /* Next unused .debug_names abbreviation tag for
26679 m_indexkey_to_idx. */
26680 int m_idx_next
= 1;
26682 /* .debug_names abbreviation table. */
26683 data_buf m_abbrev_table
;
26685 /* .debug_names entry pool. */
26686 data_buf m_entry_pool
;
26689 /* Return iff any of the needed offsets does not fit into 32-bit
26690 .debug_names section. */
26693 check_dwarf64_offsets (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26695 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26697 const dwarf2_per_cu_data
&per_cu
= *dwarf2_per_objfile
->all_comp_units
[i
];
26699 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
26702 for (int i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
26704 const signatured_type
&sigtype
= *dwarf2_per_objfile
->all_type_units
[i
];
26705 const dwarf2_per_cu_data
&per_cu
= sigtype
.per_cu
;
26707 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
26713 /* The psyms_seen set is potentially going to be largish (~40k
26714 elements when indexing a -g3 build of GDB itself). Estimate the
26715 number of elements in order to avoid too many rehashes, which
26716 require rebuilding buckets and thus many trips to
26720 psyms_seen_size (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26722 size_t psyms_count
= 0;
26723 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26725 struct dwarf2_per_cu_data
*per_cu
26726 = dwarf2_per_objfile
->all_comp_units
[i
];
26727 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
26729 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
26730 recursively_count_psymbols (psymtab
, psyms_count
);
26732 /* Generating an index for gdb itself shows a ratio of
26733 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
26734 return psyms_count
/ 4;
26737 /* Write new .gdb_index section for OBJFILE into OUT_FILE.
26738 Return how many bytes were expected to be written into OUT_FILE. */
26741 write_gdbindex (struct dwarf2_per_objfile
*dwarf2_per_objfile
, FILE *out_file
)
26743 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
26744 mapped_symtab symtab
;
26747 /* While we're scanning CU's create a table that maps a psymtab pointer
26748 (which is what addrmap records) to its index (which is what is recorded
26749 in the index file). This will later be needed to write the address
26751 psym_index_map cu_index_htab
;
26752 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
26754 /* The CU list is already sorted, so we don't need to do additional
26755 work here. Also, the debug_types entries do not appear in
26756 all_comp_units, but only in their own hash table. */
26758 std::unordered_set
<partial_symbol
*> psyms_seen
26759 (psyms_seen_size (dwarf2_per_objfile
));
26760 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26762 struct dwarf2_per_cu_data
*per_cu
26763 = dwarf2_per_objfile
->all_comp_units
[i
];
26764 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
26766 /* CU of a shared file from 'dwz -m' may be unused by this main file.
26767 It may be referenced from a local scope but in such case it does not
26768 need to be present in .gdb_index. */
26769 if (psymtab
== NULL
)
26772 if (psymtab
->user
== NULL
)
26773 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
26776 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
26777 gdb_assert (insertpair
.second
);
26779 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26780 to_underlying (per_cu
->sect_off
));
26781 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
26784 /* Dump the address map. */
26786 write_address_map (objfile
, addr_vec
, cu_index_htab
);
26788 /* Write out the .debug_type entries, if any. */
26789 data_buf types_cu_list
;
26790 if (dwarf2_per_objfile
->signatured_types
)
26792 signatured_type_index_data
sig_data (types_cu_list
,
26795 sig_data
.objfile
= objfile
;
26796 sig_data
.symtab
= &symtab
;
26797 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
26798 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
26799 write_one_signatured_type
, &sig_data
);
26802 /* Now that we've processed all symbols we can shrink their cu_indices
26804 uniquify_cu_indices (&symtab
);
26806 data_buf symtab_vec
, constant_pool
;
26807 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
26810 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
26811 offset_type total_len
= size_of_contents
;
26813 /* The version number. */
26814 contents
.append_data (MAYBE_SWAP (8));
26816 /* The offset of the CU list from the start of the file. */
26817 contents
.append_data (MAYBE_SWAP (total_len
));
26818 total_len
+= cu_list
.size ();
26820 /* The offset of the types CU list from the start of the file. */
26821 contents
.append_data (MAYBE_SWAP (total_len
));
26822 total_len
+= types_cu_list
.size ();
26824 /* The offset of the address table from the start of the file. */
26825 contents
.append_data (MAYBE_SWAP (total_len
));
26826 total_len
+= addr_vec
.size ();
26828 /* The offset of the symbol table from the start of the file. */
26829 contents
.append_data (MAYBE_SWAP (total_len
));
26830 total_len
+= symtab_vec
.size ();
26832 /* The offset of the constant pool from the start of the file. */
26833 contents
.append_data (MAYBE_SWAP (total_len
));
26834 total_len
+= constant_pool
.size ();
26836 gdb_assert (contents
.size () == size_of_contents
);
26838 contents
.file_write (out_file
);
26839 cu_list
.file_write (out_file
);
26840 types_cu_list
.file_write (out_file
);
26841 addr_vec
.file_write (out_file
);
26842 symtab_vec
.file_write (out_file
);
26843 constant_pool
.file_write (out_file
);
26848 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
26849 static const gdb_byte dwarf5_gdb_augmentation
[] = { 'G', 'D', 'B', 0 };
26851 /* Write a new .debug_names section for OBJFILE into OUT_FILE, write
26852 needed addition to .debug_str section to OUT_FILE_STR. Return how
26853 many bytes were expected to be written into OUT_FILE. */
26856 write_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
26857 FILE *out_file
, FILE *out_file_str
)
26859 const bool dwarf5_is_dwarf64
= check_dwarf64_offsets (dwarf2_per_objfile
);
26860 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
26861 const enum bfd_endian dwarf5_byte_order
26862 = gdbarch_byte_order (get_objfile_arch (objfile
));
26864 /* The CU list is already sorted, so we don't need to do additional
26865 work here. Also, the debug_types entries do not appear in
26866 all_comp_units, but only in their own hash table. */
26868 debug_names
nametable (dwarf2_per_objfile
, dwarf5_is_dwarf64
,
26869 dwarf5_byte_order
);
26870 std::unordered_set
<partial_symbol
*>
26871 psyms_seen (psyms_seen_size (dwarf2_per_objfile
));
26872 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26874 const dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
26875 partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
26877 /* CU of a shared file from 'dwz -m' may be unused by this main
26878 file. It may be referenced from a local scope but in such
26879 case it does not need to be present in .debug_names. */
26880 if (psymtab
== NULL
)
26883 if (psymtab
->user
== NULL
)
26884 nametable
.recursively_write_psymbols (objfile
, psymtab
, psyms_seen
, i
);
26886 cu_list
.append_uint (nametable
.dwarf5_offset_size (), dwarf5_byte_order
,
26887 to_underlying (per_cu
->sect_off
));
26890 /* Write out the .debug_type entries, if any. */
26891 data_buf types_cu_list
;
26892 if (dwarf2_per_objfile
->signatured_types
)
26894 debug_names::write_one_signatured_type_data
sig_data (nametable
,
26895 signatured_type_index_data (types_cu_list
, psyms_seen
));
26897 sig_data
.info
.objfile
= objfile
;
26898 /* It is used only for gdb_index. */
26899 sig_data
.info
.symtab
= nullptr;
26900 sig_data
.info
.cu_index
= 0;
26901 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
26902 debug_names::write_one_signatured_type
,
26906 nametable
.build ();
26908 /* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */
26910 const offset_type bytes_of_header
26911 = ((dwarf5_is_dwarf64
? 12 : 4)
26913 + sizeof (dwarf5_gdb_augmentation
));
26914 size_t expected_bytes
= 0;
26915 expected_bytes
+= bytes_of_header
;
26916 expected_bytes
+= cu_list
.size ();
26917 expected_bytes
+= types_cu_list
.size ();
26918 expected_bytes
+= nametable
.bytes ();
26921 if (!dwarf5_is_dwarf64
)
26923 const uint64_t size64
= expected_bytes
- 4;
26924 gdb_assert (size64
< 0xfffffff0);
26925 header
.append_uint (4, dwarf5_byte_order
, size64
);
26929 header
.append_uint (4, dwarf5_byte_order
, 0xffffffff);
26930 header
.append_uint (8, dwarf5_byte_order
, expected_bytes
- 12);
26933 /* The version number. */
26934 header
.append_uint (2, dwarf5_byte_order
, 5);
26937 header
.append_uint (2, dwarf5_byte_order
, 0);
26939 /* comp_unit_count - The number of CUs in the CU list. */
26940 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_comp_units
);
26942 /* local_type_unit_count - The number of TUs in the local TU
26944 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_type_units
);
26946 /* foreign_type_unit_count - The number of TUs in the foreign TU
26948 header
.append_uint (4, dwarf5_byte_order
, 0);
26950 /* bucket_count - The number of hash buckets in the hash lookup
26952 header
.append_uint (4, dwarf5_byte_order
, nametable
.bucket_count ());
26954 /* name_count - The number of unique names in the index. */
26955 header
.append_uint (4, dwarf5_byte_order
, nametable
.name_count ());
26957 /* abbrev_table_size - The size in bytes of the abbreviations
26959 header
.append_uint (4, dwarf5_byte_order
, nametable
.abbrev_table_bytes ());
26961 /* augmentation_string_size - The size in bytes of the augmentation
26962 string. This value is rounded up to a multiple of 4. */
26963 static_assert (sizeof (dwarf5_gdb_augmentation
) % 4 == 0, "");
26964 header
.append_uint (4, dwarf5_byte_order
, sizeof (dwarf5_gdb_augmentation
));
26965 header
.append_data (dwarf5_gdb_augmentation
);
26967 gdb_assert (header
.size () == bytes_of_header
);
26969 header
.file_write (out_file
);
26970 cu_list
.file_write (out_file
);
26971 types_cu_list
.file_write (out_file
);
26972 nametable
.file_write (out_file
, out_file_str
);
26974 return expected_bytes
;
26977 /* Assert that FILE's size is EXPECTED_SIZE. Assumes file's seek
26978 position is at the end of the file. */
26981 assert_file_size (FILE *file
, const char *filename
, size_t expected_size
)
26983 const auto file_size
= ftell (file
);
26984 if (file_size
== -1)
26985 error (_("Can't get `%s' size"), filename
);
26986 gdb_assert (file_size
== expected_size
);
26989 /* Create an index file for OBJFILE in the directory DIR. */
26992 write_psymtabs_to_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
26994 dw_index_kind index_kind
)
26996 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
26998 if (dwarf2_per_objfile
->using_index
)
26999 error (_("Cannot use an index to create the index"));
27001 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
27002 error (_("Cannot make an index when the file has multiple .debug_types sections"));
27004 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
27008 if (stat (objfile_name (objfile
), &st
) < 0)
27009 perror_with_name (objfile_name (objfile
));
27011 std::string
filename (std::string (dir
) + SLASH_STRING
27012 + lbasename (objfile_name (objfile
))
27013 + (index_kind
== dw_index_kind::DEBUG_NAMES
27014 ? INDEX5_SUFFIX
: INDEX4_SUFFIX
));
27016 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
27018 error (_("Can't open `%s' for writing"), filename
.c_str ());
27020 /* Order matters here; we want FILE to be closed before FILENAME is
27021 unlinked, because on MS-Windows one cannot delete a file that is
27022 still open. (Don't call anything here that might throw until
27023 file_closer is created.) */
27024 gdb::unlinker
unlink_file (filename
.c_str ());
27025 gdb_file_up
close_out_file (out_file
);
27027 if (index_kind
== dw_index_kind::DEBUG_NAMES
)
27029 std::string
filename_str (std::string (dir
) + SLASH_STRING
27030 + lbasename (objfile_name (objfile
))
27031 + DEBUG_STR_SUFFIX
);
27033 = gdb_fopen_cloexec (filename_str
.c_str (), "wb").release ();
27035 error (_("Can't open `%s' for writing"), filename_str
.c_str ());
27036 gdb::unlinker
unlink_file_str (filename_str
.c_str ());
27037 gdb_file_up
close_out_file_str (out_file_str
);
27039 const size_t total_len
27040 = write_debug_names (dwarf2_per_objfile
, out_file
, out_file_str
);
27041 assert_file_size (out_file
, filename
.c_str (), total_len
);
27043 /* We want to keep the file .debug_str file too. */
27044 unlink_file_str
.keep ();
27048 const size_t total_len
27049 = write_gdbindex (dwarf2_per_objfile
, out_file
);
27050 assert_file_size (out_file
, filename
.c_str (), total_len
);
27053 /* We want to keep the file. */
27054 unlink_file
.keep ();
27057 /* Implementation of the `save gdb-index' command.
27059 Note that the .gdb_index file format used by this command is
27060 documented in the GDB manual. Any changes here must be documented
27064 save_gdb_index_command (const char *arg
, int from_tty
)
27066 struct objfile
*objfile
;
27067 const char dwarf5space
[] = "-dwarf-5 ";
27068 dw_index_kind index_kind
= dw_index_kind::GDB_INDEX
;
27073 arg
= skip_spaces (arg
);
27074 if (strncmp (arg
, dwarf5space
, strlen (dwarf5space
)) == 0)
27076 index_kind
= dw_index_kind::DEBUG_NAMES
;
27077 arg
+= strlen (dwarf5space
);
27078 arg
= skip_spaces (arg
);
27082 error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
27084 ALL_OBJFILES (objfile
)
27088 /* If the objfile does not correspond to an actual file, skip it. */
27089 if (stat (objfile_name (objfile
), &st
) < 0)
27092 struct dwarf2_per_objfile
*dwarf2_per_objfile
27093 = get_dwarf2_per_objfile (objfile
);
27095 if (dwarf2_per_objfile
!= NULL
)
27099 write_psymtabs_to_index (dwarf2_per_objfile
, arg
, index_kind
);
27101 CATCH (except
, RETURN_MASK_ERROR
)
27103 exception_fprintf (gdb_stderr
, except
,
27104 _("Error while writing index for `%s': "),
27105 objfile_name (objfile
));
27115 int dwarf_always_disassemble
;
27118 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
27119 struct cmd_list_element
*c
, const char *value
)
27121 fprintf_filtered (file
,
27122 _("Whether to always disassemble "
27123 "DWARF expressions is %s.\n"),
27128 show_check_physname (struct ui_file
*file
, int from_tty
,
27129 struct cmd_list_element
*c
, const char *value
)
27131 fprintf_filtered (file
,
27132 _("Whether to check \"physname\" is %s.\n"),
27137 _initialize_dwarf2_read (void)
27139 struct cmd_list_element
*c
;
27141 dwarf2_objfile_data_key
27142 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
27144 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
27145 Set DWARF specific variables.\n\
27146 Configure DWARF variables such as the cache size"),
27147 &set_dwarf_cmdlist
, "maintenance set dwarf ",
27148 0/*allow-unknown*/, &maintenance_set_cmdlist
);
27150 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
27151 Show DWARF specific variables\n\
27152 Show DWARF variables such as the cache size"),
27153 &show_dwarf_cmdlist
, "maintenance show dwarf ",
27154 0/*allow-unknown*/, &maintenance_show_cmdlist
);
27156 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
27157 &dwarf_max_cache_age
, _("\
27158 Set the upper bound on the age of cached DWARF compilation units."), _("\
27159 Show the upper bound on the age of cached DWARF compilation units."), _("\
27160 A higher limit means that cached compilation units will be stored\n\
27161 in memory longer, and more total memory will be used. Zero disables\n\
27162 caching, which can slow down startup."),
27164 show_dwarf_max_cache_age
,
27165 &set_dwarf_cmdlist
,
27166 &show_dwarf_cmdlist
);
27168 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
27169 &dwarf_always_disassemble
, _("\
27170 Set whether `info address' always disassembles DWARF expressions."), _("\
27171 Show whether `info address' always disassembles DWARF expressions."), _("\
27172 When enabled, DWARF expressions are always printed in an assembly-like\n\
27173 syntax. When disabled, expressions will be printed in a more\n\
27174 conversational style, when possible."),
27176 show_dwarf_always_disassemble
,
27177 &set_dwarf_cmdlist
,
27178 &show_dwarf_cmdlist
);
27180 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
27181 Set debugging of the DWARF reader."), _("\
27182 Show debugging of the DWARF reader."), _("\
27183 When enabled (non-zero), debugging messages are printed during DWARF\n\
27184 reading and symtab expansion. A value of 1 (one) provides basic\n\
27185 information. A value greater than 1 provides more verbose information."),
27188 &setdebuglist
, &showdebuglist
);
27190 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
27191 Set debugging of the DWARF DIE reader."), _("\
27192 Show debugging of the DWARF DIE reader."), _("\
27193 When enabled (non-zero), DIEs are dumped after they are read in.\n\
27194 The value is the maximum depth to print."),
27197 &setdebuglist
, &showdebuglist
);
27199 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
27200 Set debugging of the dwarf line reader."), _("\
27201 Show debugging of the dwarf line reader."), _("\
27202 When enabled (non-zero), line number entries are dumped as they are read in.\n\
27203 A value of 1 (one) provides basic information.\n\
27204 A value greater than 1 provides more verbose information."),
27207 &setdebuglist
, &showdebuglist
);
27209 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
27210 Set cross-checking of \"physname\" code against demangler."), _("\
27211 Show cross-checking of \"physname\" code against demangler."), _("\
27212 When enabled, GDB's internal \"physname\" code is checked against\n\
27214 NULL
, show_check_physname
,
27215 &setdebuglist
, &showdebuglist
);
27217 add_setshow_boolean_cmd ("use-deprecated-index-sections",
27218 no_class
, &use_deprecated_index_sections
, _("\
27219 Set whether to use deprecated gdb_index sections."), _("\
27220 Show whether to use deprecated gdb_index sections."), _("\
27221 When enabled, deprecated .gdb_index sections are used anyway.\n\
27222 Normally they are ignored either because of a missing feature or\n\
27223 performance issue.\n\
27224 Warning: This option must be enabled before gdb reads the file."),
27227 &setlist
, &showlist
);
27229 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
27231 Save a gdb-index file.\n\
27232 Usage: save gdb-index [-dwarf-5] DIRECTORY\n\
27234 No options create one file with .gdb-index extension for pre-DWARF-5\n\
27235 compatible .gdb_index section. With -dwarf-5 creates two files with\n\
27236 extension .debug_names and .debug_str for DWARF-5 .debug_names section."),
27238 set_cmd_completer (c
, filename_completer
);
27240 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27241 &dwarf2_locexpr_funcs
);
27242 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27243 &dwarf2_loclist_funcs
);
27245 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27246 &dwarf2_block_frame_base_locexpr_funcs
);
27247 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27248 &dwarf2_block_frame_base_loclist_funcs
);
27251 selftests::register_test ("dw2_expand_symtabs_matching",
27252 selftests::dw2_expand_symtabs_matching::run_test
);